uniq

original_code:
void uniq(char *str)
{
    char *p = str;
    char c;
    c = *p++;
    while (*str) {
 if (*str != c) {
     c = *str;
     *p++ = c;
 }
 str++;
    }
    *p=0;
}

variable_types:
str
char *

variable_types:
p
char *

variable_types: c char


repo: papazoga/randpass

decompiled_code:
int __fastcall construct_charclass(const char *a1)
{
int v1; // ebp
int v3; // er12
char *v4; // rax
__int64 v5; // rax
char v6; // dl
unsigned int v7; // edi
const char *v8; // rbp
int result; // eax

v1 = 0;
v3 = strlen(a1);
v4 = (char *)malloc(0x80uLL);
charlen = 0;
charclass = v4;
if ( v3 <= 0 )
{
LABEL_7:
*v4 = 0;
qsort(charclass, charlen, 1uLL, (__compar_fn_t)intcompar);
uniq(charclass);
v8 = charclass;
charlen = strlen(charclass);
result = verbose;
if ( verbose )
result = printf("Character class: '%s'\n", v8);
}
else
{
while ( 1 )
{
v5 = v1;
v6 = a1[v1];
v7 = a1[v1 - 1];
if ( !v6 )
break;
if ( v6 == 45 )
{
v1 += 2;
append_range(v7, a1[v5 + 1]);
}
else
{
++v1;
append_single(v7);
}
if ( v1 >= v3 )
{
v4 = &charclass[charlen];
goto LABEL_7;
}
}
result = append_single(v7);
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(const char *a1)
{
int v1; // ebp
int v3; // er12
char *v4; // rax
__int64 v5; // rax
char v6; // dl
unsigned int v7; // edi
const char *v8; // rbp
int result; // eax

v1 = 0;
v3 = strlen(a1);
v4 = (char *)malloc(0x80uLL);
charlen = 0;
charclass = v4;
if ( v3 <= 0 )
{
LABEL_7:
*v4 = 0;
qsort(charclass, charlen, 1uLL, (__compar_fn_t)intcompar);
func10(charclass);
v8 = charclass;
charlen = strlen(charclass);
result = verbose;
if ( verbose )
result = printf("Character class: '%s'\n", v8);
}
else
{
while ( 1 )
{
v5 = v1;
v6 = a1[v1];
v7 = a1[v1 - 1];
if ( !v6 )
break;
if ( v6 == 45 )
{
v1 += 2;
func9(v7, a1[v5 + 1]);
}
else
{
++v1;
func8(v7);
}
if ( v1 >= v3 )
{
v4 = &charclass[charlen];
goto LABEL_7;
}
}
result = func8(v7);
}
return result;
}

original_code:
void construct_charclass(char *cc)
{
    int i,j,k;
    int len = strlen(cc);
    charclass = malloc(128);
    charlen = 0;
    while (i<len) {
 switch(cc[i]) {
 case '-':
     append_range(cc[i-1], cc[i+1]);
     i+=2;
     break;
 case 0:
     append_single(cc[i-1]);
     return;
 default:
     append_single(cc[i++ - 1]);
 }
    }
    charclass[charlen] = 0;
    qsort(charclass, charlen, sizeof(char), intcompar);
    uniq(charclass);
    charlen = strlen(charclass);
    if (verbose)
 printf ("Character class: '%s'\n", charclass);
}

canonical_original_code:
void construct_charclass(char *cc)
{
    int i; int j; int k;
    int len = strlen(cc);
    charclass = malloc(128);
    charlen = 0;
    while (i<len) {
 switch(cc[i]) {
 case '-':
     append_range(cc[i-1], cc[i+1]);
     i+=2;
     break;
 case 0:
     append_single(cc[i-1]);
     return;
 default:
     append_single(cc[i++ - 1]);
 }
    }
    charclass[charlen] = 0;
    qsort(charclass, charlen, sizeof(char), intcompar);
    uniq(charclass);
    charlen = strlen(charclass);
    if (verbose)
 printf ("Character class: '%s'\n", charclass);
}

variable_types:
cc
char *

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: len int

return_type: void


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"usage: %s [-l length] [-c charclass]\n"
"where:\n"
" length is the length of desired password (0<length<256)\n"
" charclass is character class, e.g. acg-kz => acghijkz\n",
progname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func12()
{
fprintf(
stderr,
"usage: %s [-l length] [-c charclass]\n"
"where:\n"
" length is the length of desired password (0<length<256)\n"
" charclass is character class, e.g. acg-kz => acghijkz\n",
progname);
exit(1);
}

original_code:
void usage()
{
    fprintf (stderr, "usage: %s [-l length] [-c charclass]\n"
      "where:\n"
      "  length is the length of desired password (0<length<256)\n"
      "  charclass is character class, e.g. acg-kz => acghijkz\n", progname);
    exit(1);
}


calculateIndex

decompiled_code:
unsigned __int64 __fastcall calculateIndex(__int64 a1, int a2)
{
return a2 & (unsigned __int64)(a1 - 1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, int a2)
{
return a2 & (unsigned __int64)(a1 - 1);
}

original_code:
static inline size_t calculateIndex(size_t bucketCount, int hash) {
    return ((size_t) hash) & (bucketCount - 1);
}

canonical_original_code:
static inline unsigned long calculateIndex(unsigned long bucketCount, int hash) {
    return ((unsigned long) hash) & (bucketCount - 1);
}

variable_types:
bucketCount
unsigned long

variable_types: hash int

return_type: unsigned long


equalKeys

decompiled_code:
__int64 __fastcall equalKeys(__int64 a1, int a2, __int64 a3, int a4, __int64 (__fastcall *a5)(__int64, __int64))
{
if ( a1 == a3 )
return 1LL;
if ( a2 == a4 )
return a5(a1, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int64 a3, int a4, __int64 (__fastcall *a5)(__int64, __int64))
{
if ( a1 == a3 )
return 1LL;
if ( a2 == a4 )
return a5(a1, a3);
return 0LL;
}

original_code:
static inline _Bool equalKeys(void* keyA, int hashA, void* keyB, int hashB,
        _Bool (*equals)(void*, void*)) {
    if (keyA == keyB) {
        return 1;
    }
    if (hashA != hashB) {
        return 0;
    }
    return equals(keyA, keyB);
}

canonical_original_code:
static inline _Bool equalKeys(void *keyA, int hashA, void *keyB, int hashB, _Bool (*equals)(void *, void *)) {
    if (keyA == keyB) {
        return 1;
    }
    if (hashA != hashB) {
        return 0;
    }
    return equals(keyA, keyB);
}

variable_types:
keyA
void *

variable_types: hashA int

variable_types:
keyB
void *

variable_types: hashB int

variable_types:
equals
_Bool (*)(void *, void *)


expandIfNecessary

original_code:
static void expandIfNecessary(Hashmap* map) {
    if (map->size > (map->bucketCount * 3 / 4)) {
        size_t newBucketCount = map->bucketCount << 1;
        Entry** newBuckets = calloc(newBucketCount, sizeof(Entry*));
        if (newBuckets == ((void *)0)) {
            return;
        }
        size_t i;
        for (i = 0; i < map->bucketCount; i++) {
            Entry* entry = map->buckets[i];
            while (entry != ((void *)0)) {
                Entry* next = entry->next;
                size_t index = calculateIndex(newBucketCount, entry->hash);
                entry->next = newBuckets[index];
                newBuckets[index] = entry;
                entry = next;
            }
        }
        free(map->buckets);
        map->buckets = newBuckets;
        map->bucketCount = newBucketCount;
    }
}

canonical_original_code:
static void expandIfNecessary(struct _Hashmap *map) {
    if (map->size > (map->bucketCount * 3 / 4)) {
        unsigned long newBucketCount = map->bucketCount << 1;
        struct _Entry **newBuckets = calloc(newBucketCount, sizeof(Entry*));
        if (newBuckets == ((void *)0)) {
            return;
        }
        unsigned long i;
        for (i = 0; i < map->bucketCount; i++) {
            struct _Entry *entry = map->buckets[i];
            while (entry != ((void *)0)) {
                struct _Entry *next = entry->next;
                unsigned long index = calculateIndex(newBucketCount, entry->hash);
                entry->next = newBuckets[index];
                newBuckets[index] = entry;
                entry = next;
            }
        }
        free(map->buckets);
        map->buckets = newBuckets;
        map->bucketCount = newBucketCount;
    }
}

variable_types: struct _Hashmap { struct _Entry { void *key; int hash; void *value; struct _Entry *next; } **buckets; unsigned long bucketCount; int (*hash)(void *key); _Bool (*equals)(void *keyA, void *keyB); unsigned long size; } *

variable_types:
newBucketCount
unsigned long

variable_types:
i
unsigned long

variable_types:
index
unsigned long

user_defined_types: struct _Hashmap { struct _Entry **buckets; unsigned long bucketCount; int (*hash)(void *key); _Bool (*equals)(void *keyA, void *keyB); unsigned long size; }


hashmapSize

decompiled_code:
__int64 __fastcall hashmapSize(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

original_code:
size_t hashmapSize(Hashmap* map) {
    return map->size;
}

canonical_original_code:
unsigned long hashmapSize(struct _Hashmap *map) {
    return map->size;
}

user_defined_types: struct _Entry { void *key; int hash; void *value; struct _Entry *next; }


hashmapLock

decompiled_code:
void hashmapLock()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void hashmapLock(Hashmap* map) {
}

canonical_original_code:
void hashmapLock(struct _Hashmap *map) {
}


hashmapUnlock

decompiled_code:
void hashmapUnlock()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void hashmapUnlock(Hashmap* map) {
}

canonical_original_code:
void hashmapUnlock(struct _Hashmap *map) {
}


hashmapFree

decompiled_code:
void __fastcall hashmapFree(void *ptr)
{
bool v2; // zf
_QWORD *v3; // rdi
unsigned __int64 v4; // rbp
_QWORD *v5; // rbx
void *v6; // rdi

v2 = *((_QWORD *)ptr + 1) == 0LL;
v3 = *(_QWORD **)ptr;
if ( !v2 )
{
v4 = 0LL;
do
{
v5 = (_QWORD *)v3[v4];
if ( v5 )
{
do
{
v6 = v5;
v5 = (_QWORD *)v5[3];
free(v6);
}
while ( v5 );
v3 = *(_QWORD **)ptr;
}
++v4;
}
while ( *((_QWORD *)ptr + 1) > v4 );
}
free(v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
bool v2; // zf
_QWORD *v3; // rdi
unsigned __int64 v4; // rbp
_QWORD *v5; // rbx
void *v6; // rdi

v2 = *((_QWORD *)ptr + 1) == 0LL;
v3 = *(_QWORD **)ptr;
if ( !v2 )
{
v4 = 0LL;
do
{
v5 = (_QWORD *)v3[v4];
if ( v5 )
{
do
{
v6 = v5;
v5 = (_QWORD *)v5[3];
free(v6);
}
while ( v5 );
v3 = *(_QWORD **)ptr;
}
++v4;
}
while ( *((_QWORD *)ptr + 1) > v4 );
}
free(v3);
free(ptr);
}

original_code:
void hashmapFree(Hashmap* map) {
    size_t i;
    for (i = 0; i < map->bucketCount; i++) {
        Entry* entry = map->buckets[i];
        while (entry != ((void *)0)) {
            Entry* next = entry->next;
            free(entry);
            entry = next;
        }
    }
    free(map->buckets);
    free(map);
}

canonical_original_code:
void hashmapFree(struct _Hashmap *map) {
    unsigned long i;
    for (i = 0; i < map->bucketCount; i++) {
        struct _Entry *entry = map->buckets[i];
        while (entry != ((void *)0)) {
            struct _Entry *next = entry->next;
            free(entry);
            entry = next;
        }
    }
    free(map->buckets);
    free(map);
}

variable_types: struct _Entry { void *key; int hash; void *value; struct _Entry *next; } *


hashmapHash

decompiled_code:
__int64 __fastcall hashmapHash(char *a1, __int64 a2)
{
__int64 result; // rax
char *v3; // rsi

LODWORD(result) = a2;
if ( !a2 )
return 0LL;
v3 = &a1[a2];
do
result = (unsigned int)(31 * result + *a1++);
while ( a1 != v3 );
return result;
}

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

LODWORD(result) = a2;
if ( !a2 )
return 0LL;
v3 = &a1[a2];
do
result = (unsigned int)(31 * result + *a1++);
while ( a1 != v3 );
return result;
}

original_code:
int hashmapHash(void* key, size_t keySize) {
    int h = keySize;
    char* data = (char*) key;
    size_t i;
    for (i = 0; i < keySize; i++) {
        h = h * 31 + *data;
        data++;
    }
    return h;
}

canonical_original_code:
int hashmapHash(void *key, unsigned long keySize) {
    int h = keySize;
    char *data = (char*) key;
    unsigned long i;
    for (i = 0; i < keySize; i++) {
        h = h * 31 + *data;
        data++;
    }
    return h;
}

variable_types:
key
void *

variable_types:
keySize
unsigned long

variable_types: h int

variable_types:
data
char *

return_type: int


hashmapGet

original_code:
void* hashmapGet(Hashmap* map, void* key) {
    int hash = hashKey(map, key);
    size_t index = calculateIndex(map->bucketCount, hash);
    Entry* entry = map->buckets[index];
    while (entry != ((void *)0)) {
        if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) {
            return entry->value;
        }
        entry = entry->next;
    }
    return ((void *)0);
}

canonical_original_code:
void *hashmapGet(struct _Hashmap *map, void *key) {
    int hash = hashKey(map, key);
    unsigned long index = calculateIndex(map->bucketCount, hash);
    struct _Entry *entry = map->buckets[index];
    while (entry != ((void *)0)) {
        if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) {
            return entry->value;
        }
        entry = entry->next;
    }
    return ((void *)0);
}

return_type: void *


hashmapContainsKey

decompiled_code:
__int64 __fastcall hashmapContainsKey(__int64 a1, __int64 a2)
{
int v2; // er12
__int64 v3; // rbx
__int64 result; // rax

v2 = hashKey_isra_0(*(__int64 (__fastcall **)(__int64))(a1 + 16), a2);
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8 * calculateIndex(*(_QWORD *)(a1 + 8), v2));
if ( !v3 )
return 0LL;
while ( 1 )
{
result = equalKeys(
*(_QWORD *)v3,
*(_DWORD *)(v3 + 8),
a2,
v2,
*(__int64 (__fastcall **)(__int64, __int64))(a1 + 24));
if ( (_BYTE)result )
break;
v3 = *(_QWORD *)(v3 + 24);
if ( !v3 )
return 0LL;
}
return result;
}

original_code:
_Bool hashmapContainsKey(Hashmap* map, void* key) {
    int hash = hashKey(map, key);
    size_t index = calculateIndex(map->bucketCount, hash);
    Entry* entry = map->buckets[index];
    while (entry != ((void *)0)) {
        if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) {
            return 1;
        }
        entry = entry->next;
    }
    return 0;
}

canonical_original_code:
_Bool hashmapContainsKey(struct _Hashmap *map, void *key) {
    int hash = hashKey(map, key);
    unsigned long index = calculateIndex(map->bucketCount, hash);
    struct _Entry *entry = map->buckets[index];
    while (entry != ((void *)0)) {
        if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) {
            return 1;
        }
        entry = entry->next;
    }
    return 0;
}


hashmapRemove

original_code:
void* hashmapRemove(Hashmap* map, void* key) {
    int hash = hashKey(map, key);
    size_t index = calculateIndex(map->bucketCount, hash);
    Entry** p = &(map->buckets[index]);
    Entry* current;
    while ((current = *p) != ((void *)0)) {
        if (equalKeys(current->key, current->hash, key, hash, map->equals)) {
            void* value = current->value;
            *p = current->next;
            free(current);
            map->size--;
            return value;
        }
        p = &current->next;
    }
    return ((void *)0);
}

canonical_original_code:
void *hashmapRemove(struct _Hashmap *map, void *key) {
    int hash = hashKey(map, key);
    unsigned long index = calculateIndex(map->bucketCount, hash);
    struct _Entry **p = &(map->buckets[index]);
    struct _Entry *current;
    while ((current = *p) != ((void *)0)) {
        if (equalKeys(current->key, current->hash, key, hash, map->equals)) {
            void *value = current->value;
            *p = current->next;
            free(current);
            map->size--;
            return value;
        }
        p = &current->next;
    }
    return ((void *)0);
}

variable_types: struct _Entry { void *key; int hash; void *value; struct _Entry *next; } **

variable_types:
value
void *


hashmapForEach

decompiled_code:
void __fastcall hashmapForEach(_QWORD *a1, unsigned __int8 (__fastcall *a2)(_QWORD, _QWORD, __int64), __int64 a3)
{
__int64 v3; // r14
_QWORD *v5; // rbx

if ( a1[1] )
{
v3 = 0LL;
while ( 1 )
{
v5 = *(_QWORD **)(*a1 + 8 * v3);
if ( v5 )
break;
LABEL_8:
if ( a1[1] <= (unsigned __int64)++v3 )
return;
}
while ( a2(*v5, v5[2], a3) )
{
v5 = (_QWORD *)v5[3];
if ( !v5 )
goto LABEL_8;
}
}
}

canonical_decompiled_code:
void __fastcall func13(_QWORD *a1, unsigned __int8 (__fastcall *a2)(_QWORD, _QWORD, __int64), __int64 a3)
{
__int64 v3; // r14
_QWORD *v5; // rbx

if ( a1[1] )
{
v3 = 0LL;
while ( 1 )
{
v5 = *(_QWORD **)(*a1 + 8 * v3);
if ( v5 )
break;
LABEL_8:
if ( a1[1] <= (unsigned __int64)++v3 )
return;
}
while ( a2(*v5, v5[2], a3) )
{
v5 = (_QWORD *)v5[3];
if ( !v5 )
goto LABEL_8;
}
}
}

original_code:
void hashmapForEach(Hashmap* map,
        _Bool (*callback)(void* key, void* value, void* context),
        void* context) {
    size_t i;
    for (i = 0; i < map->bucketCount; i++) {
        Entry* entry = map->buckets[i];
        while (entry != ((void *)0)) {
            if (!callback(entry->key, entry->value, context)) {
                return;
            }
            entry = entry->next;
        }
    }
}

canonical_original_code:
void hashmapForEach(struct _Hashmap *map, _Bool (*callback)(void *key, void *value, void *context), void *context) {
    unsigned long i;
    for (i = 0; i < map->bucketCount; i++) {
        struct _Entry *entry = map->buckets[i];
        while (entry != ((void *)0)) {
            if (!callback(entry->key, entry->value, context)) {
                return;
            }
            entry = entry->next;
        }
    }
}

variable_types: _Bool (*)(void *key, void *value, void *context)

variable_types:
context
void *


hashmapCurrentCapacity

decompiled_code:
unsigned __int64 __fastcall hashmapCurrentCapacity(__int64 a1)
{
return (unsigned __int64)(3LL * *(_QWORD *)(a1 + 8)) >> 2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func14(__int64 a1)
{
return (unsigned __int64)(3LL * *(_QWORD *)(a1 + 8)) >> 2;
}

original_code:
size_t hashmapCurrentCapacity(Hashmap* map) {
    size_t bucketCount = map->bucketCount;
    return bucketCount * 3 / 4;
}

canonical_original_code:
unsigned long hashmapCurrentCapacity(struct _Hashmap *map) {
    unsigned long bucketCount = map->bucketCount;
    return bucketCount * 3 / 4;
}

variable_types:
bucketCount
unsigned long


hashmapCountCollisions

original_code:
size_t hashmapCountCollisions(Hashmap* map) {
    size_t collisions = 0;
    size_t i;
    for (i = 0; i < map->bucketCount; i++) {
        Entry* entry = map->buckets[i];
        while (entry != ((void *)0)) {
            if (entry->next != ((void *)0)) {
                collisions++;
            }
            entry = entry->next;
        }
    }
    return collisions;
}

canonical_original_code:
unsigned long hashmapCountCollisions(struct _Hashmap *map) {
    unsigned long collisions = 0;
    unsigned long i;
    for (i = 0; i < map->bucketCount; i++) {
        struct _Entry *entry = map->buckets[i];
        while (entry != ((void *)0)) {
            if (entry->next != ((void *)0)) {
                collisions++;
            }
            entry = entry->next;
        }
    }
    return collisions;
}

variable_types:
collisions
unsigned long


hashmapIntHash

decompiled_code:
__int64 __fastcall hashmapIntHash(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int *a1)
{
return *a1;
}

original_code:
int hashmapIntHash(void* key) {
    return *((int*) key);
}

canonical_original_code:
int hashmapIntHash(void *key) {
    return *((int *) key);
}


hashmapIntEquals

decompiled_code:
bool __fastcall hashmapIntEquals(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

canonical_decompiled_code:
bool __fastcall func17(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

original_code:
_Bool hashmapIntEquals(void* keyA, void* keyB) {
    int a = *((int*) keyA);
    int b = *((int*) keyB);
    return a == b;
}

canonical_original_code:
_Bool hashmapIntEquals(void *keyA, void *keyB) {
    int a = *((int*) keyA);
    int b = *((int*) keyB);
    return a == b;
}

variable_types:
keyA
void *

variable_types:
keyB
void *

variable_types: a int

variable_types: b int


push

decompiled_code:
__int64 __fastcall push(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r14
__int64 v5; // rax
__int64 v6; // rbx
_QWORD *v8; // rax

v5 = hash_lookup(a1 + 1);
if ( v5 )
{
v6 = v5;
v3 = compute_distance(*a1, a3);
rbtree_rm(a1, *(_QWORD *)(v6 + 8));
*(_QWORD *)(v6 + 8) = a3;
}
else
{
v8 = malloc(0x18uLL);
*v8 = a2;
v8[1] = a3;
hash_add(a1 + 1, v8);
}
rbtree_add(a1, a3);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r14
__int64 v5; // rax
__int64 v6; // rbx
_QWORD *v8; // rax

v5 = hash_lookup(a1 + 1);
if ( v5 )
{
v6 = v5;
v3 = compute_distance(*a1, a3);
rbtree_rm(a1, *(_QWORD *)(v6 + 8));
*(_QWORD *)(v6 + 8) = a3;
}
else
{
v8 = malloc(0x18uLL);
*v8 = a2;
v8[1] = a3;
hash_add(a1 + 1, v8);
}
rbtree_add(a1, a3);
return v3;
}

original_code:
ref_num_t push (lru_stack_t *stack, cbn_t cbn, ref_num_t ref_num) {
    ht_entry_t *res = hash_lookup(stack->ht, cbn);
    ref_num_t dist;
    if (res) {
        dist = compute_distance(stack->tree, ref_num);
        rbtree_rm(&stack->tree, res->ref_num);
        res->ref_num = ref_num;
    } else {
        ht_entry_t *entry = malloc(sizeof(ht_entry_t));
        entry->cbn = cbn;
        entry->ref_num = ref_num;
        hash_add(stack->ht, entry);
    }
    rbtree_add(&stack->tree, ref_num);
    return dist;
}

canonical_original_code:
unsigned long push(struct lru_stack_s *stack, unsigned long cbn, unsigned long ref_num) {
    struct ht_entry_s *res = hash_lookup(stack->ht, cbn);
    unsigned long dist;
    if (res) {
        dist = compute_distance(stack->tree, ref_num);
        rbtree_rm(&stack->tree, res->ref_num);
        res->ref_num = ref_num;
    } else {
        struct ht_entry_s *entry = malloc(sizeof(ht_entry_t));
        entry->cbn = cbn;
        entry->ref_num = ref_num;
        hash_add(stack->ht, entry);
    }
    rbtree_add(&stack->tree, ref_num);
    return dist;
}

variable_types: struct lru_stack_s { struct rbtree { unsigned long ref_num; char color_field; struct rbtree *left; struct rbtree *right; } *tree; struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *ht[512]; } *

variable_types:
cbn
unsigned long

variable_types:
dist
unsigned long

user_defined_types: struct lru_stack_s { struct rbtree *tree; struct ht_entry_s *ht[512]; }


decompiled_code:
__int64 __fastcall init_lru_stack(__int64 a1)
{
return init_ht(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return init_ht(a1 + 8);
}

original_code:
void init_lru_stack (lru_stack_t *stack) {
    init_ht(stack->ht);
}

canonical_original_code:
void init_lru_stack(struct lru_stack_s *stack) {
    init_ht(stack->ht);
}

user_defined_types: struct rbtree { unsigned long ref_num; char color_field; struct rbtree *left; struct rbtree *right; }

user_defined_types: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; }


decompiled_code:
__int64 __fastcall delete_lru_stack(_QWORD *a1)
{
delete_ht(a1 + 1);
return delete_rbtree(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
delete_ht(a1 + 1);
return delete_rbtree(*a1);
}

original_code:
void delete_lru_stack (lru_stack_t *stack) {
    delete_ht(stack->ht);
    delete_rbtree(stack->tree);
}

canonical_original_code:
void delete_lru_stack(struct lru_stack_s *stack) {
    delete_ht(stack->ht);
    delete_rbtree(stack->tree);
}


decompiled_code:
__int64 __fastcall ht_entry_hash_function(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
uint64_t ht_entry_hash_function(ht_entry_t *e) {
    return(e->cbn);
}

canonical_original_code:
unsigned long ht_entry_hash_function(struct ht_entry_s *e) {
    return(e->cbn);
}

variable_types: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *


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

for ( LOBYTE(result) = a1 != 0; a2 != a1; LOBYTE(result) = a1 != 0 )
{
if ( !(_BYTE)result )
break;
a1 = *(_QWORD *)(a1 + 16);
}
return (unsigned __int8)result;
}

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

for ( LOBYTE(result) = a1 != 0; a2 != a1; LOBYTE(result) = a1 != 0 )
{
if ( !(_BYTE)result )
break;
a1 = *(_QWORD *)(a1 + 16);
}
return (unsigned __int8)result;
}

original_code: int sglib_ht_entry_t_is_member(ht_entry_t *list, ht_entry_t *elem) { int result; { ht_entry_t *_p_; for(_p_ = (list); _p_!=((void *)0) && _p_ != (elem); _p_= _p_->next) ; (result) = (_p_!=((void *)0));}; return(result); }

canonical_original_code: int sglib_ht_entry_t_is_member(struct ht_entry_s *list, struct ht_entry_s *elem) { int result; { struct ht_entry_s *_p_; for(_p_ = (list); _p_!=((void *)0) && _p_ != (elem); _p_= _p_->next) ; (result) = (_p_!=((void *)0));}; return(result); }

variable_types:
elem
struct ht_entry_s *

variable_types: result int


decompiled_code:
_BOOL8 __fastcall sglib_ht_entry_t_add_if_not_member(_QWORD **a1, _QWORD *a2, _QWORD *a3)
{
_QWORD *v3; // rax
_BOOL8 result; // rax

v3 = *a1;
if ( *a1 )
{
while ( *v3 != *a2 )
{
v3 = (_QWORD *)v3[2];
if ( !v3 )
goto LABEL_6;
}
*a3 = v3;
result = v3 == 0LL;
}
else
{
LABEL_6:
*a3 = 0LL;
a2[2] = *a1;
*a1 = a2;
result = *a3 == 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD **a1, _QWORD *a2, _QWORD *a3)
{
_QWORD *v3; // rax
_BOOL8 result; // rax

v3 = *a1;
if ( *a1 )
{
while ( *v3 != *a2 )
{
v3 = (_QWORD *)v3[2];
if ( !v3 )
goto LABEL_6;
}
*a3 = v3;
result = v3 == 0LL;
}
else
{
LABEL_6:
*a3 = 0LL;
a2[2] = *a1;
*a1 = a2;
result = *a3 == 0LL;
}
return result;
}

original_code: int sglib_ht_entry_t_add_if_not_member(ht_entry_t **list, ht_entry_t *elem, ht_entry_t **member) { { ht_entry_t *_p_; for(_p_ = (*list); _p_!=((void *)0) && (_p_->cbn - (elem)->cbn) != 0; _p_= _p_->next) ; (*member) = _p_; if (_p_ == ((void *)0)) { { (elem)->next = (*list); (*list) = (elem);}; }}; return(*member==((void *)0)); }

canonical_original_code: int sglib_ht_entry_t_add_if_not_member(struct ht_entry_s **list, struct ht_entry_s *elem, struct ht_entry_s **member) { { struct ht_entry_s *_p_; for(_p_ = (*list); _p_!=((void *)0) && (_p_->cbn - (elem)->cbn) != 0; _p_= _p_->next) ; (*member) = _p_; if (_p_ == ((void *)0)) { { (elem)->next = (*list); (*list) = (elem);}; }}; return(*member==((void *)0)); }

variable_types: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } **

variable_types:
member
struct ht_entry_s **


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

result = *a1;
if ( !*a1 )
LABEL_6:
_assert_fail(
"*_p_!=NULL && \"element is not member of the container, use DELETE_IF_MEMBER instead\"!=NULL",
"hash_table.c",
0x16u,
"sglib_ht_entry_t_delete");
while ( 1 )
{
v3 = result;
result = *(_QWORD *)(result + 16);
if ( a2 == v3 )
break;
a1 = (__int64 *)(v3 + 16);
if ( !result )
goto LABEL_6;
}
*a1 = result;
return result;
}

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

result = *a1;
if ( !*a1 )
LABEL_6:
_assert_fail(
"*_p_!=NULL && \"element is not member of the container, use DELETE_IF_MEMBER instead\"!=NULL",
"hash_table.c",
0x16u,
"sglib_ht_entry_t_delete");
while ( 1 )
{
v3 = result;
result = *(_QWORD *)(result + 16);
if ( a2 == v3 )
break;
a1 = (__int64 *)(v3 + 16);
if ( !result )
goto LABEL_6;
}
*a1 = result;
return result;
}

original_code: void sglib_ht_entry_t_delete(ht_entry_t **list, ht_entry_t *elem) { { ht_entry_t **_p_; for(_p_ = &(*list); *_p_!=((void *)0) && *_p_!=(elem); _p_= &(*_p_)->next) ; ((void) sizeof ((*_p_!=((void *)0) && "element is not member of the container, use DELETE_IF_MEMBER instead"!=((void *)0)) ? 1 : 0), __extension__ ({ if (*_p_!=((void *)0) && "element is not member of the container, use DELETE_IF_MEMBER instead"!=((void *)0)) ; else __assert_fail ("*_p_!=NULL && \"element is not member of the container, use DELETE_IF_MEMBER instead\"!=NULL", "hash_table.c", 22, __extension__ __PRETTY_FUNCTION__); })); *_p_ = (*_p_)->next;}; }

canonical_original_code: void sglib_ht_entry_t_delete(struct ht_entry_s **list, struct ht_entry_s *elem) { { struct ht_entry_s **_p_; for(_p_ = &(*list); *_p_!=((void *)0) && *_p_!=(elem); _p_= &(*_p_)->next) ; ((void) sizeof ((*_p_!=((void *)0) && "element is not member of the container, use DELETE_IF_MEMBER instead"!=((void *)0)) ? 1 : 0), __extension__ ({ if (*_p_!=((void *)0) && "element is not member of the container, use DELETE_IF_MEMBER instead"!=((void *)0)) ; else __assert_fail ("*_p_!=NULL && \"element is not member of the container, use DELETE_IF_MEMBER instead\"!=NULL", "hash_table.c", 22, __extension__ __PRETTY_FUNCTION__); })); *_p_ = (*_p_)->next;}; }


decompiled_code:
_BOOL8 __fastcall sglib_ht_entry_t_delete_if_member(_QWORD **a1, _QWORD *a2, _QWORD *a3)
{
_QWORD *v3; // rax
_BOOL8 result; // rax

v3 = *a1;
if ( *a1 )
{
while ( *v3 != *a2 )
{
a1 = (_QWORD **)(v3 + 2);
v3 = (_QWORD *)v3[2];
if ( !v3 )
goto LABEL_6;
}
*a3 = v3;
*a1 = (_QWORD *)v3[2];
result = *a3 != 0LL;
}
else
{
LABEL_6:
*a3 = 0LL;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_QWORD **a1, _QWORD *a2, _QWORD *a3)
{
_QWORD *v3; // rax
_BOOL8 result; // rax

v3 = *a1;
if ( *a1 )
{
while ( *v3 != *a2 )
{
a1 = (_QWORD **)(v3 + 2);
v3 = (_QWORD *)v3[2];
if ( !v3 )
goto LABEL_6;
}
*a3 = v3;
*a1 = (_QWORD *)v3[2];
result = *a3 != 0LL;
}
else
{
LABEL_6:
*a3 = 0LL;
result = 0LL;
}
return result;
}

original_code: int sglib_ht_entry_t_delete_if_member(ht_entry_t **list, ht_entry_t *elem, ht_entry_t **member) { { ht_entry_t **_p_; for(_p_ = &(*list); *_p_!=((void *)0) && ((*_p_)->cbn - (elem)->cbn) != 0; _p_= &(*_p_)->next) ; (*member) = *_p_; if (*_p_ != ((void *)0)) { *_p_ = (*_p_)->next; }}; return(*member!=((void *)0)); }

canonical_original_code: int sglib_ht_entry_t_delete_if_member(struct ht_entry_s **list, struct ht_entry_s *elem, struct ht_entry_s **member) { { struct ht_entry_s **_p_; for(_p_ = &(*list); *_p_!=((void *)0) && ((*_p_)->cbn - (elem)->cbn) != 0; _p_= &(*_p_)->next) ; (*member) = *_p_; if (*_p_ != ((void *)0)) { *_p_ = (*_p_)->next; }}; return(*member!=((void *)0)); }


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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 16);
return result;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 16);
return result;
}

original_code: int sglib_ht_entry_t_len(ht_entry_t *list) { int res; { ht_entry_t *_ce_; (res) = 0; { ht_entry_t *_ne_; ht_entry_t *_ce_; (_ce_) = (list); while ((_ce_)!=((void *)0)) { _ne_ = (_ce_)->next; {(res)++;}; (_ce_) = _ne_; }};}; return(res); }

canonical_original_code: int sglib_ht_entry_t_len(struct ht_entry_s *list) { int res; { struct ht_entry_s *_ce_; (res) = 0; { struct ht_entry_s *_ne_; struct ht_entry_s *_ce_; (_ce_) = (list); while ((_ce_)!=((void *)0)) { _ne_ = (_ce_)->next; {(res)++;}; (_ce_) = _ne_; }};}; return(res); }

variable_types: res int


decompiled_code:
__int64 __fastcall sglib_ht_entry_t_it_current(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code: ht_entry_t *sglib_ht_entry_t_it_current(struct sglib_ht_entry_t_iterator *it) { return(it->currentelem); }

canonical_original_code: struct ht_entry_s *sglib_ht_entry_t_it_current(struct sglib_ht_entry_t_iterator *it) { return(it->currentelem); }

variable_types: struct sglib_ht_entry_t_iterator { struct ht_entry_s *currentelem; struct ht_entry_s *nextelem; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; } *

return_type: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *


decompiled_code:
__int64 __fastcall sglib_ht_entry_t_it_next(_QWORD *a1)
{
unsigned int (__fastcall *v1)(__int64, __int64); // rbp
__int64 v2; // r12
__int64 v3; // r13

v1 = (unsigned int (__fastcall *)(__int64, __int64))a1[2];
v2 = a1[1];
a1[1] = 0LL;
if ( !v1 )
{
*a1 = v2;
if ( !v2 )
return v2;
goto LABEL_7;
}
v3 = a1[3];
if ( v2 )
{
while ( v1(v2, v3) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_9;
}
*a1 = v2;
LABEL_7:
a1[1] = *(_QWORD *)(v2 + 16);
return v2;
}
LABEL_9:
*a1 = 0LL;
return 0LL;
}

original_code: ht_entry_t *sglib_ht_entry_t_it_next(struct sglib_ht_entry_t_iterator *it) { ht_entry_t *ce, *eq; int (*scp)(ht_entry_t *, ht_entry_t *); ce = it->nextelem; it->nextelem = ((void *)0); if (it->subcomparator != ((void *)0)) { eq = it->equalto; scp = it->subcomparator; while (ce!=((void *)0) && scp(ce, eq)!=0) ce = ce->next; } it->currentelem = ce; if (ce != ((void *)0)) it->nextelem = ce->next; return(ce); }

canonical_original_code: struct ht_entry_s *sglib_ht_entry_t_it_next(struct sglib_ht_entry_t_iterator *it) { struct ht_entry_s *ce; struct ht_entry_s *eq; int (*scp)(struct ht_entry_s *, struct ht_entry_s *); ce = it->nextelem; it->nextelem = ((void *)0); if (it->subcomparator != ((void *)0)) { eq = it->equalto; scp = it->subcomparator; while (ce!=((void *)0) && scp(ce, eq)!=0) ce = ce->next; } it->currentelem = ce; if (ce != ((void *)0)) it->nextelem = ce->next; return(ce); }

variable_types: int (*)(struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *, struct ht_entry_s *)

user_defined_types: struct sglib_ht_entry_t_iterator { struct ht_entry_s *currentelem; struct ht_entry_s *nextelem; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; }


decompiled_code:
__int64 __fastcall sglib_ht_entry_t_it_init_on_equal(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
a1[2] = a3;
a1[3] = a4;
a1[1] = a2;
return sglib_ht_entry_t_it_next(a1);
}

original_code: ht_entry_t *sglib_ht_entry_t_it_init_on_equal(struct sglib_ht_entry_t_iterator *it, ht_entry_t *list, int (*subcomparator)(ht_entry_t *, ht_entry_t *), ht_entry_t *equalto) { it->subcomparator = subcomparator; it->equalto = equalto; it->nextelem = list; return(sglib_ht_entry_t_it_next(it)); }

canonical_original_code: struct ht_entry_s *sglib_ht_entry_t_it_init_on_equal(struct sglib_ht_entry_t_iterator *it, struct ht_entry_s *list, int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *), struct ht_entry_s *equalto) { it->subcomparator = subcomparator; it->equalto = equalto; it->nextelem = list; return(sglib_ht_entry_t_it_next(it)); }

variable_types:
list
struct ht_entry_s *

variable_types: int (*)(struct ht_entry_s *, struct ht_entry_s *)

variable_types:
equalto
struct ht_entry_s *


decompiled_code:
__int64 __fastcall sglib_ht_entry_t_it_init(_QWORD *a1, __int64 a2)
{
return sglib_ht_entry_t_it_init_on_equal(a1, a2, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1, __int64 a2)
{
return func12(a1, a2, 0LL, 0LL);
}

original_code: ht_entry_t *sglib_ht_entry_t_it_init(struct sglib_ht_entry_t_iterator *it, ht_entry_t *list) { return(sglib_ht_entry_t_it_init_on_equal(it, list, ((void *)0), ((void *)0))); }

canonical_original_code: struct ht_entry_s *sglib_ht_entry_t_it_init(struct sglib_ht_entry_t_iterator *it, struct ht_entry_s *list) { return(sglib_ht_entry_t_it_init_on_equal(it, list, ((void *)0), ((void *)0))); }


decompiled_code:
_BOOL8 __fastcall sglib_hashed_ht_entry_t_add_if_not_member(__int64 a1, _QWORD *a2)
{
__int16 v2; // ax
__int64 v3; // rcx
_QWORD *v4; // rdx

v2 = ht_entry_hash_function((__int64)a2);
return sglib_ht_entry_t_add_if_not_member((_QWORD **)(v3 + 8LL * (v2 & 0x1FF)), a2, v4);
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(__int64 a1, _QWORD *a2)
{
__int16 v2; // ax
__int64 v3; // rcx
_QWORD *v4; // rdx

v2 = func0((__int64)a2);
return func2((_QWORD **)(v3 + 8LL * (v2 & 0x1FF)), a2, v4);
}

original_code: int sglib_hashed_ht_entry_t_add_if_not_member(ht_entry_t *table[512], ht_entry_t *elem, ht_entry_t **member) { unsigned i; i = ((unsigned)ht_entry_hash_function(elem)) % (512); return(sglib_ht_entry_t_add_if_not_member(&(table)[i], elem, member)); }

canonical_original_code: int sglib_hashed_ht_entry_t_add_if_not_member(struct ht_entry_s *table[512], struct ht_entry_s *elem, struct ht_entry_s **member) { unsigned int i; i = ((unsigned int)ht_entry_hash_function(elem)) % (512); return(sglib_ht_entry_t_add_if_not_member(&(table)[i], elem, member)); }

variable_types: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *[512]

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall sglib_hashed_ht_entry_t_delete(__int64 a1, __int64 a2)
{
__int16 v2; // ax
__int64 v3; // rdx

v2 = ht_entry_hash_function(a2);
return sglib_ht_entry_t_delete((__int64 *)(v3 + 8LL * (v2 & 0x1FF)), a2);
}

original_code: void sglib_hashed_ht_entry_t_delete(ht_entry_t *table[512], ht_entry_t *elem) { unsigned i; i = ((unsigned)ht_entry_hash_function(elem)) % (512); sglib_ht_entry_t_delete(&(table)[i], elem); }

canonical_original_code: void sglib_hashed_ht_entry_t_delete(struct ht_entry_s *table[512], struct ht_entry_s *elem) { unsigned int i; i = ((unsigned int)ht_entry_hash_function(elem)) % (512); sglib_ht_entry_t_delete(&(table)[i], elem); }


decompiled_code:
_BOOL8 __fastcall sglib_hashed_ht_entry_t_delete_if_member(__int64 a1, _QWORD *a2)
{
__int16 v2; // ax
__int64 v3; // rcx
_QWORD *v4; // rdx

v2 = ht_entry_hash_function((__int64)a2);
return sglib_ht_entry_t_delete_if_member((_QWORD **)(v3 + 8LL * (v2 & 0x1FF)), a2, v4);
}

canonical_decompiled_code:
_BOOL8 __fastcall func18(__int64 a1, _QWORD *a2)
{
__int16 v2; // ax
__int64 v3; // rcx
_QWORD *v4; // rdx

v2 = func0((__int64)a2);
return func6((_QWORD **)(v3 + 8LL * (v2 & 0x1FF)), a2, v4);
}

original_code: int sglib_hashed_ht_entry_t_delete_if_member(ht_entry_t *table[512], ht_entry_t *elem, ht_entry_t **memb) { unsigned i; i = ((unsigned)ht_entry_hash_function(elem)) % (512); return(sglib_ht_entry_t_delete_if_member(&(table)[i], elem, memb)); }

canonical_original_code: int sglib_hashed_ht_entry_t_delete_if_member(struct ht_entry_s *table[512], struct ht_entry_s *elem, struct ht_entry_s **memb) { unsigned int i; i = ((unsigned int)ht_entry_hash_function(elem)) % (512); return(sglib_ht_entry_t_delete_if_member(&(table)[i], elem, memb)); }

variable_types:
memb
struct ht_entry_s **


decompiled_code:
__int64 __fastcall sglib_hashed_ht_entry_t_is_member(__int64 a1, __int64 a2)
{
__int16 v2; // ax
__int64 v3; // rdx

v2 = ht_entry_hash_function(a2);
return sglib_ht_entry_t_is_member(*(_QWORD *)(v3 + 8LL * (v2 & 0x1FF)), a2);
}

original_code: int sglib_hashed_ht_entry_t_is_member(ht_entry_t *table[512], ht_entry_t *elem) { unsigned i; i = ((unsigned)ht_entry_hash_function(elem)) % (512); return(sglib_ht_entry_t_is_member((table)[i], elem)); }

canonical_original_code: int sglib_hashed_ht_entry_t_is_member(struct ht_entry_s *table[512], struct ht_entry_s *elem) { unsigned int i; i = ((unsigned int)ht_entry_hash_function(elem)) % (512); return(sglib_ht_entry_t_is_member((table)[i], elem)); }


decompiled_code:
// attributes: thunk
__int64 __fastcall sglib_hashed_ht_entry_t_it_current(__int64 a1)
{
return sglib_ht_entry_t_it_current(a1);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
return func10(a1);
}

original_code: ht_entry_t *sglib_hashed_ht_entry_t_it_current(struct sglib_hashed_ht_entry_t_iterator *it) { return(sglib_ht_entry_t_it_current(&it->containerIt)); }

canonical_original_code: struct ht_entry_s *sglib_hashed_ht_entry_t_it_current(struct sglib_hashed_ht_entry_t_iterator *it) { return(sglib_ht_entry_t_it_current(&it->containerIt)); }

variable_types: struct sglib_hashed_ht_entry_t_iterator { struct sglib_ht_entry_t_iterator { struct ht_entry_s *currentelem; struct ht_entry_s *nextelem; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; } containerIt; struct ht_entry_s **table; int currentIndex; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; } *

user_defined_types: struct sglib_hashed_ht_entry_t_iterator { struct sglib_ht_entry_t_iterator containerIt; struct ht_entry_s **table; int currentIndex; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; }


decompiled_code:
__int64 __fastcall sglib_hashed_ht_entry_t_it_next(__int64 a1)
{
__int64 v1; // r12
__int64 result; // rax
int v3; // eax

v1 = sglib_ht_entry_t_it_next((_QWORD *)a1);
if ( !v1 )
{
while ( 1 )
{
v3 = *(_DWORD *)(a1 + 40) + 1;
*(_DWORD *)(a1 + 40) = v3;
if ( v3 > 511 )
break;
result = sglib_ht_entry_t_it_init_on_equal(
(_QWORD *)a1,
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL * v3),
*(_QWORD *)(a1 + 48),
*(_QWORD *)(a1 + 56));
if ( result )
return result;
}
}
return v1;
}

original_code: ht_entry_t *sglib_hashed_ht_entry_t_it_next(struct sglib_hashed_ht_entry_t_iterator *it) { ht_entry_t *e; e = sglib_ht_entry_t_it_next(&it->containerIt); while (e==((void *)0) && (++(it->currentIndex))<(512)) { e = sglib_ht_entry_t_it_init_on_equal(&it->containerIt, it->table[it->currentIndex], it->subcomparator, it->equalto); } return(e); }

canonical_original_code: struct ht_entry_s *sglib_hashed_ht_entry_t_it_next(struct sglib_hashed_ht_entry_t_iterator *it) { struct ht_entry_s *e; e = sglib_ht_entry_t_it_next(&it->containerIt); while (e==((void *)0) && (++(it->currentIndex))<(512)) { e = sglib_ht_entry_t_it_init_on_equal(&it->containerIt, it->table[it->currentIndex], it->subcomparator, it->equalto); } return(e); }


decompiled_code:
__int64 __fastcall sglib_hashed_ht_entry_t_it_init_on_equal(__int64 a1, __int64 *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rsi
__int64 result; // rax

*(_QWORD *)(a1 + 32) = a2;
*(_QWORD *)(a1 + 56) = a4;
v4 = *a2;
*(_DWORD *)(a1 + 40) = 0;
*(_QWORD *)(a1 + 48) = a3;
result = sglib_ht_entry_t_it_init_on_equal((_QWORD *)a1, v4, a3, a4);
if ( !result )
result = sglib_hashed_ht_entry_t_it_next(a1);
return result;
}

original_code: ht_entry_t *sglib_hashed_ht_entry_t_it_init_on_equal(struct sglib_hashed_ht_entry_t_iterator *it, ht_entry_t *table[512], int (*subcomparator)(ht_entry_t *, ht_entry_t *), ht_entry_t *equalto) { ht_entry_t *e; it->table = table; it->currentIndex = 0; it->subcomparator = subcomparator; it->equalto = equalto; e = sglib_ht_entry_t_it_init_on_equal(&it->containerIt, table[it->currentIndex], it->subcomparator, it->equalto); if (e==((void *)0)) e = sglib_hashed_ht_entry_t_it_next(it); return(e); }

canonical_original_code: struct ht_entry_s *sglib_hashed_ht_entry_t_it_init_on_equal(struct sglib_hashed_ht_entry_t_iterator *it, struct ht_entry_s *table[512], int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *), struct ht_entry_s *equalto) { struct ht_entry_s *e; it->table = table; it->currentIndex = 0; it->subcomparator = subcomparator; it->equalto = equalto; e = sglib_ht_entry_t_it_init_on_equal(&it->containerIt, table[it->currentIndex], it->subcomparator, it->equalto); if (e==((void *)0)) e = sglib_hashed_ht_entry_t_it_next(it); return(e); }

variable_types:
table
struct ht_entry_s *[512]


decompiled_code:
__int64 __fastcall sglib_hashed_ht_entry_t_it_init(__int64 a1, __int64 *a2)
{
return sglib_hashed_ht_entry_t_it_init_on_equal(a1, a2, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, __int64 *a2)
{
return func22(a1, a2, 0LL, 0LL);
}

original_code: ht_entry_t *sglib_hashed_ht_entry_t_it_init(struct sglib_hashed_ht_entry_t_iterator *it, ht_entry_t *table[512]) { return(sglib_hashed_ht_entry_t_it_init_on_equal(it, table, ((void *)0), ((void *)0))); }

canonical_original_code: struct ht_entry_s *sglib_hashed_ht_entry_t_it_init(struct sglib_hashed_ht_entry_t_iterator *it, struct ht_entry_s *table[512]) { return(sglib_hashed_ht_entry_t_it_init_on_equal(it, table, ((void *)0), ((void *)0))); }


decompiled_code:
__int64 __fastcall delete_ht(__int64 *a1)
{
__int64 result; // rax
void *v2; // rdi
_BYTE v3[72]; // [rsp+0h] [rbp-48h] BYREF

result = sglib_hashed_ht_entry_t_it_init((__int64)v3, a1);
if ( result )
{
v2 = (void *)result;
do
{
free(v2);
result = sglib_hashed_ht_entry_t_it_next((__int64)v3);
v2 = (void *)result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 *a1)
{
__int64 result; // rax
void *v2; // rdi
_BYTE v3[72]; // [rsp+0h] [rbp-48h] BYREF

result = func23((__int64)v3, a1);
if ( result )
{
v2 = (void *)result;
do
{
free(v2);
result = func21((__int64)v3);
v2 = (void *)result;
}
while ( result );
}
return result;
}

original_code:
void delete_ht (ht_entry_t **ht) {
    ht_entry_t *i;
    struct sglib_hashed_ht_entry_t_iterator it;
    for (i = sglib_hashed_ht_entry_t_it_init(&it, ht); i != ((void *)0);
         i = sglib_hashed_ht_entry_t_it_next(&it)) {
        free(i);
    }
}

canonical_original_code:
void delete_ht(struct ht_entry_s **ht) {
    struct ht_entry_s *i;
    struct sglib_hashed_ht_entry_t_iterator it;
    for (i = sglib_hashed_ht_entry_t_it_init(&it, ht); i != ((void *)0);
         i = sglib_hashed_ht_entry_t_it_next(&it)) {
        free(i);
    }
}

variable_types: struct sglib_hashed_ht_entry_t_iterator { struct sglib_ht_entry_t_iterator { struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *currentelem; struct ht_entry_s *nextelem; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; } containerIt; struct ht_entry_s **table; int currentIndex; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; }


decompiled_code:
int __fastcall parse_options(int argc, char **argv)
{
int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "t:f:");
if ( result == -1 )
break;
if ( result == 102 )
{
*((_DWORD *)&env + 2) = 0;
}
else
{
if ( result != 116 )
{
fprintf(stderr, "Usage: %s [-t trace file] [-f trace format]\n", *argv);
exit(1);
}
env = optarg;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int argc, char **argv)
{
int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "t:f:");
if ( result == -1 )
break;
if ( result == 102 )
{
*((_DWORD *)&env + 2) = 0;
}
else
{
if ( result != 116 )
{
fprintf(stderr, "Usage: %s [-t trace file] [-f trace format]\n", *argv);
exit(1);
}
env = optarg;
}
}
return result;
}

original_code:
void parse_options (int argc, const char *argv[]) {
  int opt;
  while ((opt = getopt(argc, argv, "t:f:")) != -1) {
    switch (opt) {
      case 't':
        env.file_name = optarg;
        break;
      case 'f':
        env.trace_format = SEAGATE;
        break;
      default:
        fprintf (stderr, "Usage: %s [-t trace file] [-f trace format]\n",
                 argv[0]);
        exit(1);
    }
  }
}

canonical_original_code:
void parse_options(int argc, char *argv[]) {
  int opt;
  while ((opt = getopt(argc, argv, "t:f:")) != -1) {
    switch (opt) {
      case 't':
        env.file_name = optarg;
        break;
      case 'f':
        env.trace_format = SEAGATE;
        break;
      default:
        fprintf (stderr, "Usage: %s [-t trace file] [-f trace format]\n",
                 argv[0]);
        exit(1);
    }
  }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int


repo: parzio/crypto-secure-communication

original_code:
void MAJ5_init(MAJ5 *maj5){
 LFSR temp = { ((void *)0) , ((void *)0) , 0};
 maj5->reg[0] = temp;
 LFSR_init(&maj5->reg[0] , MAJ5_reg1 , MAJ5_poly1 , MAJ5_degree[0]);
 maj5->reg[1] = temp;
 LFSR_init(&maj5->reg[1] , MAJ5_reg2 , MAJ5_poly2 , MAJ5_degree[1]);
 maj5->reg[2] = temp;
 LFSR_init(&maj5->reg[2] , MAJ5_reg3 , MAJ5_poly3 , MAJ5_degree[2]);
 maj5->reg[3] = temp;
 LFSR_init(&maj5->reg[3] , MAJ5_reg4 , MAJ5_poly4 , MAJ5_degree[3]);
 maj5->reg[4] = temp;
 LFSR_init(&maj5->reg[4] , MAJ5_reg5 , MAJ5_poly5 , MAJ5_degree[4]);
}

canonical_original_code:
void MAJ5_init(struct MAJ5 *maj5){
 struct LFSR temp = { ((void *)0) , ((void *)0) , 0};
 maj5->reg[0] = temp;
 LFSR_init(&maj5->reg[0] , MAJ5_reg1 , MAJ5_poly1 , MAJ5_degree[0]);
 maj5->reg[1] = temp;
 LFSR_init(&maj5->reg[1] , MAJ5_reg2 , MAJ5_poly2 , MAJ5_degree[1]);
 maj5->reg[2] = temp;
 LFSR_init(&maj5->reg[2] , MAJ5_reg3 , MAJ5_poly3 , MAJ5_degree[2]);
 maj5->reg[3] = temp;
 LFSR_init(&maj5->reg[3] , MAJ5_reg4 , MAJ5_poly4 , MAJ5_degree[3]);
 maj5->reg[4] = temp;
 LFSR_init(&maj5->reg[4] , MAJ5_reg5 , MAJ5_poly5 , MAJ5_degree[4]);
}

variable_types: struct MAJ5 { struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } reg[5]; } *


decompiled_code:
__int64 __fastcall MAJ5_delete(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

v1 = a1 + 120;
v2 = a1;
do
{
v3 = v2;
v2 += 24LL;
result = LFSR_delete(v3);
}
while ( v2 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

v1 = a1 + 120;
v2 = a1;
do
{
v3 = v2;
v2 += 24LL;
result = LFSR_delete(v3);
}
while ( v2 != v1 );
return result;
}

original_code:
void MAJ5_delete(MAJ5 *maj5){
 int i;
 for(i = 0; i < 5; i++)
  LFSR_delete(&maj5->reg[i]);
}

canonical_original_code:
void MAJ5_delete(struct MAJ5 *maj5){
 int i;
 for(i = 0; i < 5; i++)
  LFSR_delete(&maj5->reg[i]);
}

variable_types: i int

user_defined_types: struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; }


decompiled_code:
__int64 __fastcall MAJ5_update(__int64 a1)
{
__int64 v1; // rsi
int v2; // er13
__int64 v3; // r12
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v6; // rbp
unsigned int v7; // er12
__int64 v8; // rdi
int v9; // eax
__int64 v10; // rdi

v1 = 8LL;
v2 = 0;
v3 = a1;
v4 = 0LL;
v5 = a1;
while ( 1 )
{
v2 += (unsigned __int8)LFSR_getBit(v3, v1) == 0;
++v4;
v3 += 24LL;
if ( v4 == 5 )
break;
v1 = (unsigned int)MAJ5_clock[v4];
}
v6 = 0LL;
v7 = 0;
if ( v2 <= 2 )
{
if ( (unsigned __int8)LFSR_getBit(a1, 8LL) == 1 )
goto LABEL_14;
LABEL_11:
for ( v7 ^= LFSR_getBit(v5, (unsigned int)(*(_DWORD *)(v5 + 16) - 1)); ; v7 ^= LFSR_update(v5) )
{
++v6;
v5 += 24LL;
if ( v6 == 5 )
break;
if ( (unsigned __int8)LFSR_getBit(v5, (unsigned int)MAJ5_clock[v6]) != 1 )
goto LABEL_11;
LABEL_14:
;
}
}
else
{
if ( (unsigned __int8)LFSR_getBit(a1, 8LL) )
goto LABEL_8;
while ( 1 )
{
v8 = v5;
++v6;
v5 += 24LL;
v7 ^= LFSR_update(v8);
if ( v6 == 5 )
break;
while ( (unsigned __int8)LFSR_getBit(v5, (unsigned int)MAJ5_clock[v6]) )
{
LABEL_8:
v9 = *(_DWORD *)(v5 + 16);
v10 = v5;
++v6;
v5 += 24LL;
v7 ^= LFSR_getBit(v10, (unsigned int)(v9 - 1));
if ( v6 == 5 )
return v7;
}
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rsi
int v2; // er13
__int64 v3; // r12
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v6; // rbp
unsigned int v7; // er12
__int64 v8; // rdi
int v9; // eax
__int64 v10; // rdi

v1 = 8LL;
v2 = 0;
v3 = a1;
v4 = 0LL;
v5 = a1;
while ( 1 )
{
v2 += (unsigned __int8)LFSR_getBit(v3, v1) == 0;
++v4;
v3 += 24LL;
if ( v4 == 5 )
break;
v1 = (unsigned int)MAJ5_clock[v4];
}
v6 = 0LL;
v7 = 0;
if ( v2 <= 2 )
{
if ( (unsigned __int8)LFSR_getBit(a1, 8LL) == 1 )
goto LABEL_14;
LABEL_11:
for ( v7 ^= LFSR_getBit(v5, (unsigned int)(*(_DWORD *)(v5 + 16) - 1)); ; v7 ^= LFSR_update(v5) )
{
++v6;
v5 += 24LL;
if ( v6 == 5 )
break;
if ( (unsigned __int8)LFSR_getBit(v5, (unsigned int)MAJ5_clock[v6]) != 1 )
goto LABEL_11;
LABEL_14:
;
}
}
else
{
if ( (unsigned __int8)LFSR_getBit(a1, 8LL) )
goto LABEL_8;
while ( 1 )
{
v8 = v5;
++v6;
v5 += 24LL;
v7 ^= LFSR_update(v8);
if ( v6 == 5 )
break;
while ( (unsigned __int8)LFSR_getBit(v5, (unsigned int)MAJ5_clock[v6]) )
{
LABEL_8:
v9 = *(_DWORD *)(v5 + 16);
v10 = v5;
++v6;
v5 += 24LL;
v7 ^= LFSR_getBit(v10, (unsigned int)(v9 - 1));
if ( v6 == 5 )
return v7;
}
}
}
return v7;
}

original_code:
bit MAJ5_update(MAJ5 *maj5){
 int count_zero = 0;
 int i;
 bit output = 0;
 bit temp = 0;
 for(i = 0; i < 5; i++)
 {
  temp = LFSR_getBit(&maj5->reg[i] , MAJ5_clock[i]);
  if(temp == 0)
   count_zero ++;
 }
 if(count_zero >= 3)
 {
  for(i = 0; i < 5; i++)
  {
   if(LFSR_getBit(&maj5->reg[i], MAJ5_clock[i]) == 0)
    output ^= LFSR_update(&maj5->reg[i]);
   else
    output ^= LFSR_getBit(&maj5->reg[i], (maj5->reg[i].degree-1));
  }
 }
 else
 {
  for(i = 0; i < 5; i++)
  {
   if(LFSR_getBit(&maj5->reg[i], MAJ5_clock[i]) == 1)
    output ^= LFSR_update(&maj5->reg[i]);
   else
    output ^= LFSR_getBit(&maj5->reg[i], (maj5->reg[i].degree-1));
  }
 }
 return output;
}

canonical_original_code:
unsigned int MAJ5_update(struct MAJ5 *maj5){
 int count_zero = 0;
 int i;
 unsigned int output = 0;
 unsigned int temp = 0;
 for(i = 0; i < 5; i++)
 {
  temp = LFSR_getBit(&maj5->reg[i] , MAJ5_clock[i]);
  if(temp == 0)
   count_zero ++;
 }
 if(count_zero >= 3)
 {
  for(i = 0; i < 5; i++)
  {
   if(LFSR_getBit(&maj5->reg[i], MAJ5_clock[i]) == 0)
    output ^= LFSR_update(&maj5->reg[i]);
   else
    output ^= LFSR_getBit(&maj5->reg[i], (maj5->reg[i].degree-1));
  }
 }
 else
 {
  for(i = 0; i < 5; i++)
  {
   if(LFSR_getBit(&maj5->reg[i], MAJ5_clock[i]) == 1)
    output ^= LFSR_update(&maj5->reg[i]);
   else
    output ^= LFSR_getBit(&maj5->reg[i], (maj5->reg[i].degree-1));
  }
 }
 return output;
}

variable_types:
output
unsigned int

variable_types:
temp
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall MAJ5_warmUpStream(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a2 )
{
for ( i = 0; i != a2; ++i )
result = MAJ5_update(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a2 )
{
for ( i = 0; i != a2; ++i )
result = func2(a1);
}
return result;
}

original_code:
void MAJ5_warmUpStream(MAJ5 *maj5, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  MAJ5_update(maj5);
}

canonical_original_code:
void MAJ5_warmUpStream(struct MAJ5 *maj5, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  MAJ5_update(maj5);
}

variable_types:
stream
unsigned int


decompiled_code:
void __fastcall MAJ5_getStream(__int64 a1, _BYTE *a2, int a3)
{
__int64 v3; // r12
_BYTE *v4; // rbx

if ( a3 )
{
v3 = (__int64)&a2[a3 - 1 + 1];
v4 = a2;
do
*v4++ = MAJ5_update(a1);
while ( v4 != (_BYTE *)v3 );
}
}

original_code:
void MAJ5_getStream(MAJ5 *maj5, bit *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = MAJ5_update(maj5);
}

canonical_original_code:
void MAJ5_getStream(struct MAJ5 *maj5, unsigned int *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = MAJ5_update(maj5);
}

variable_types:
result
unsigned int *


decompiled_code:
__int64 __fastcall MAJ5_encrypt(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
__int64 v6; // rbx
char v7; // dl
__int64 i; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v4 = 0LL;
v6 = a4;
do
{
MAJ5_getStream(a1, v10, 8);
v7 = *(_BYTE *)(a2 + v4);
for ( i = 0LL; i != 8; ++i )
{
result = (unsigned __int8)v10[i] << i;
v7 ^= result;
}
*(_BYTE *)(a3 + v4++) = v7;
}
while ( v4 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
__int64 v6; // rbx
char v7; // dl
__int64 i; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v4 = 0LL;
v6 = a4;
do
{
func4(a1, v10, 8);
v7 = *(_BYTE *)(a2 + v4);
for ( i = 0LL; i != 8; ++i )
{
result = (unsigned __int8)v10[i] << i;
v7 ^= result;
}
*(_BYTE *)(a3 + v4++) = v7;
}
while ( v4 != v6 );
}
return result;
}

original_code:
void MAJ5_encrypt(MAJ5 *maj5, byte *plaintext, byte *chipertext, unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  bit temp[8];
  MAJ5_getStream(maj5 , temp , 8);
  byte currentByte = plaintext[i];
  for(j = 0; j < 8; j++)
  {
  bit x = temp[j] << j;
  currentByte ^= x;
  }
  chipertext[i] = currentByte;
 }
}

canonical_original_code:
void MAJ5_encrypt(struct MAJ5 *maj5, unsigned int *plaintext, unsigned int *chipertext, unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  unsigned int temp[8];
  MAJ5_getStream(maj5 , temp , 8);
  unsigned int currentByte = plaintext[i];
  for(j = 0; j < 8; j++)
  {
  unsigned int x = temp[j] << j;
  currentByte ^= x;
  }
  chipertext[i] = currentByte;
 }
}

variable_types:
plaintext
unsigned int *

variable_types:
chipertext
unsigned int *

variable_types:
length
unsigned int

variable_types: j int

variable_types:
temp
unsigned int [8]

variable_types:
currentByte
unsigned int

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall MAJ5_decrypt(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
__int64 v6; // rbx
char v7; // dl
__int64 i; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v4 = 0LL;
v6 = a4;
do
{
MAJ5_getStream(a1, v10, 8);
v7 = *(_BYTE *)(a3 + v4);
for ( i = 0LL; i != 8; ++i )
{
result = (unsigned __int8)v10[i] << i;
v7 ^= result;
}
*(_BYTE *)(a2 + v4++) = v7;
}
while ( v4 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
__int64 v6; // rbx
char v7; // dl
__int64 i; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v4 = 0LL;
v6 = a4;
do
{
func4(a1, v10, 8);
v7 = *(_BYTE *)(a3 + v4);
for ( i = 0LL; i != 8; ++i )
{
result = (unsigned __int8)v10[i] << i;
v7 ^= result;
}
*(_BYTE *)(a2 + v4++) = v7;
}
while ( v4 != v6 );
}
return result;
}

original_code:
void MAJ5_decrypt(MAJ5 *maj5, byte *plaintext, byte *chipertext, unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  bit temp[8];
  MAJ5_getStream(maj5 , temp , 8);
  byte currentByte = chipertext[i];
  for(j = 0; j < 8; j++)
  {
  bit x = temp[j] << j;
  currentByte ^= x;
  }
  plaintext[i] = currentByte;
 }
}

canonical_original_code:
void MAJ5_decrypt(struct MAJ5 *maj5, unsigned int *plaintext, unsigned int *chipertext, unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  unsigned int temp[8];
  MAJ5_getStream(maj5 , temp , 8);
  unsigned int currentByte = chipertext[i];
  for(j = 0; j < 8; j++)
  {
  unsigned int x = temp[j] << j;
  currentByte ^= x;
  }
  plaintext[i] = currentByte;
 }
}


getChunk

decompiled_code:
__int64 __fastcall getChunk(__int64 a1, __int64 a2, int a3)
{
int v3; // ecx
__int64 result; // rax
__int64 v5; // rsi

v3 = 2 * (3 * a3 + 3);
result = (unsigned int)(v3 - 6);
if ( !__OFSUB__(v3, (_DWORD)result) && v3 != (_DWORD)result )
{
result = (int)result;
v5 = a2 - (int)result;
do
{
*(_BYTE *)(v5 + result) = *(_BYTE *)(a1 + result);
++result;
}
while ( v3 > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3)
{
int v3; // ecx
__int64 result; // rax
__int64 v5; // rsi

v3 = 2 * (3 * a3 + 3);
result = (unsigned int)(v3 - 6);
if ( !__OFSUB__(v3, (_DWORD)result) && v3 != (_DWORD)result )
{
result = (int)result;
v5 = a2 - (int)result;
do
{
*(_BYTE *)(v5 + result) = *(_BYTE *)(a1 + result);
++result;
}
while ( v3 > (int)result );
}
return result;
}

original_code:
void getChunk(bit block[24], bit chunk[6], unsigned int index){
 int j, z = 0 , end = (6 * index + 6) , start = index * 6;
 for(j = start; j < end ; j++)
 {
  chunk[z] = block[j];
  z++;
 }
}

canonical_original_code:
void getChunk(unsigned int block[24], unsigned int chunk[6], unsigned int index){
 int j; int z = 0; int end = (6 * index + 6); int start = index * 6;
 for(j = start; j < end ; j++)
 {
  chunk[z] = block[j];
  z++;
 }
}

variable_types:
block
unsigned int [24]

variable_types:
chunk
unsigned int [6]

variable_types:
index
unsigned int

variable_types: z int

variable_types: end int

variable_types: start int


setChunk

decompiled_code:
__int64 __fastcall setChunk(__int64 a1, __int64 a2, int a3)
{
int v3; // ecx
__int64 result; // rax
__int64 v5; // rsi

v3 = 2 * (3 * a3 + 3);
result = (unsigned int)(v3 - 6);
if ( !__OFSUB__(v3, (_DWORD)result) && v3 != (_DWORD)result )
{
result = (int)result;
v5 = a2 - (int)result;
do
{
*(_BYTE *)(a1 + result) = *(_BYTE *)(v5 + result);
++result;
}
while ( v3 > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3)
{
int v3; // ecx
__int64 result; // rax
__int64 v5; // rsi

v3 = 2 * (3 * a3 + 3);
result = (unsigned int)(v3 - 6);
if ( !__OFSUB__(v3, (_DWORD)result) && v3 != (_DWORD)result )
{
result = (int)result;
v5 = a2 - (int)result;
do
{
*(_BYTE *)(a1 + result) = *(_BYTE *)(v5 + result);
++result;
}
while ( v3 > (int)result );
}
return result;
}

original_code:
void setChunk(bit block[24], bit chunk[6], unsigned int index){
 int j, z = 0 , end = (6 * index + 6) , start = index * 6;
 for(j = start; j < end ; j++)
 {
  block[j] = chunk[z];
  z++;
 }
}

canonical_original_code:
void setChunk(unsigned int block[24], unsigned int chunk[6], unsigned int index){
 int j; int z = 0; int end = (6 * index + 6); int start = index * 6;
 for(j = start; j < end ; j++)
 {
  block[j] = chunk[z];
  z++;
 }
}


mixingLayer

decompiled_code:
__int64 __fastcall mixingLayer(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rax
unsigned int v3; // edx
__int64 j; // r8
__int64 result; // rax
_WORD v6[28]; // [rsp+0h] [rbp-38h] BYREF

for ( i = 0LL; i != 4; ++i )
{
v2 = 3 * i;
v3 = i;
mixingLayerMatrixMul(a1, (__int64)&v6[v2], v3);
}
for ( j = 0LL; j != 4; result = setChunk(a1, (__int64)&v6[3 * j], j) )
;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rax
unsigned int v3; // edx
__int64 j; // r8
__int64 result; // rax
_WORD v6[28]; // [rsp+0h] [rbp-38h] BYREF

for ( i = 0LL; i != 4; ++i )
{
v2 = 3 * i;
v3 = i;
func2(a1, (__int64)&v6[v2], v3);
}
for ( j = 0LL; j != 4; result = func3(a1, (__int64)&v6[3 * j], j) )
;
return result;
}

original_code:
void mixingLayer(bit block[24]){
 int i;
 bit chunk_buffer[4][6];
 for(i = 0; i < 4; i++)
  mixingLayerMatrixMul(block , chunk_buffer[i] , i);
 for(i = 0; i < 4; i++)
  setChunk(block , chunk_buffer[i] , i);
}

canonical_original_code:
void mixingLayer(unsigned int block[24]){
 int i;
 unsigned int chunk_buffer[4][6];
 for(i = 0; i < 4; i++)
  mixingLayerMatrixMul(block , chunk_buffer[i] , i);
 for(i = 0; i < 4; i++)
  setChunk(block , chunk_buffer[i] , i);
}

variable_types: i int


decompiled_code:
__int64 __fastcall inverse_mixingLayer(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rax
unsigned int v3; // edx
__int64 j; // r8
__int64 result; // rax
_WORD v6[28]; // [rsp+0h] [rbp-38h] BYREF

for ( i = 0LL; i != 4; ++i )
{
v2 = 3 * i;
v3 = i;
inverse_mixingLayerMatrixMul(a1, (__int64)&v6[v2], v3);
}
for ( j = 0LL; j != 4; result = setChunk(a1, (__int64)&v6[3 * j], j) )
;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rax
unsigned int v3; // edx
__int64 j; // r8
__int64 result; // rax
_WORD v6[28]; // [rsp+0h] [rbp-38h] BYREF

for ( i = 0LL; i != 4; ++i )
{
v2 = 3 * i;
v3 = i;
func1(a1, (__int64)&v6[v2], v3);
}
for ( j = 0LL; j != 4; result = func3(a1, (__int64)&v6[3 * j], j) )
;
return result;
}

original_code:
void inverse_mixingLayer(bit block[24]){
 int i;
 bit chunk_buffer[4][6];
 for(i = 0; i < 4; i++)
  inverse_mixingLayerMatrixMul(block , chunk_buffer[i] , i);
 for(i = 0; i < 4; i++)
  setChunk(block , chunk_buffer[i] , i);
}

canonical_original_code:
void inverse_mixingLayer(unsigned int block[24]){
 int i;
 unsigned int chunk_buffer[4][6];
 for(i = 0; i < 4; i++)
  inverse_mixingLayerMatrixMul(block , chunk_buffer[i] , i);
 for(i = 0; i < 4; i++)
  setChunk(block , chunk_buffer[i] , i);
}


blockInversion

decompiled_code:
__int64 __fastcall blockInversion(__int64 a1)
{
int i; // ebx
__int64 result; // rax
char v3[30]; // [rsp+Ah] [rbp-1Eh] BYREF

for ( i = 0; i != 4; ++i )
{
getChunk(a1, (__int64)v3, i);
inverteArray(v3, 6LL);
result = setChunk(a1, (__int64)v3, i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int i; // ebx
__int64 result; // rax
char v3[30]; // [rsp+Ah] [rbp-1Eh] BYREF

for ( i = 0; i != 4; ++i )
{
func0(a1, (__int64)v3, i);
inverteArray(v3, 6LL);
result = func3(a1, (__int64)v3, i);
}
return result;
}

original_code:
void blockInversion(bit block[24]){
 int i;
 bit chunk[6];
 for(i = 0; i < 4; i++)
 {
  getChunk(block , chunk , i);
  inverteArray(chunk , 6);
  setChunk(block , chunk , i);
 }
}

canonical_original_code:
void blockInversion(unsigned int block[24]){
 int i;
 unsigned int chunk[6];
 for(i = 0; i < 4; i++)
 {
  getChunk(block , chunk , i);
  inverteArray(chunk , 6);
  setChunk(block , chunk , i);
 }
}


sbox

decompiled_code:
__int64 __fastcall sbox(__int64 a1, int a2)
{
int v2; // er12
__int64 result; // rax
int v4; // er12
int v5; // er12
int v6; // er12
int v7; // [rsp+Ah] [rbp-1Eh] BYREF
unsigned __int16 v8; // [rsp+Eh] [rbp-1Ah]

v7 = *(_DWORD *)a1;
v8 = *(_WORD *)(a1 + 4);
if ( a2 == 2 )
{
v6 = 16;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v6;
}
while ( v6 );
}
else if ( a2 > 2 )
{
v4 = 61;
if ( a2 != 3 )
goto LABEL_14;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v4;
}
while ( v4 );
BYTE2(v7) ^= 1u;
}
else
{
if ( a2 )
{
if ( a2 == 1 )
{
v2 = 4;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v2;
}
while ( v2 );
goto LABEL_7;
}
LABEL_14:
puts("sbox index error ");
goto LABEL_7;
}
v5 = 61;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v5;
}
while ( v5 );
}
LABEL_7:
*(_DWORD *)a1 = v7;
result = v8;
*(_WORD *)(a1 + 4) = v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
int v2; // er12
__int64 result; // rax
int v4; // er12
int v5; // er12
int v6; // er12
int v7; // [rsp+Ah] [rbp-1Eh] BYREF
unsigned __int16 v8; // [rsp+Eh] [rbp-1Ah]

v7 = *(_DWORD *)a1;
v8 = *(_WORD *)(a1 + 4);
if ( a2 == 2 )
{
v6 = 16;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v6;
}
while ( v6 );
}
else if ( a2 > 2 )
{
v4 = 61;
if ( a2 != 3 )
goto LABEL_14;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v4;
}
while ( v4 );
BYTE2(v7) ^= 1u;
}
else
{
if ( a2 )
{
if ( a2 == 1 )
{
v2 = 4;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v2;
}
while ( v2 );
goto LABEL_7;
}
LABEL_14:
puts("sbox index error ");
goto LABEL_7;
}
v5 = 61;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v5;
}
while ( v5 );
}
LABEL_7:
*(_DWORD *)a1 = v7;
result = v8;
*(_WORD *)(a1 + 4) = v8;
return result;
}

original_code:
void sbox(bit chunk[6] , int index){
 int i;
 bit result[6];
 for(i = 0; i < 6; i++)
  result[i] = chunk[i];
 switch(index){
  case 0:
   for( i = 1; i < sbox1_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 1:
   for( i = 1; i < sbox2_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 2:
   for( i = 1; i < sbox3_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 3:
   for( i = 1; i < sbox4_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   result[2] ^= 1;
   break;
  default : printf("sbox index error \n"); break;
 }
 for(i = 0; i < 6; i++)
  chunk[i] = result[i];
}

canonical_original_code:
void sbox(unsigned int chunk[6], int index){
 int i;
 unsigned int result[6];
 for(i = 0; i < 6; i++)
  result[i] = chunk[i];
 switch(index){
  case 0:
   for( i = 1; i < sbox1_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 1:
   for( i = 1; i < sbox2_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 2:
   for( i = 1; i < sbox3_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 3:
   for( i = 1; i < sbox4_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   result[2] ^= 1;
   break;
  default : printf("sbox index error \n"); break;
 }
 for(i = 0; i < 6; i++)
  chunk[i] = result[i];
}

variable_types: index int

variable_types:
result
unsigned int [6]


keySchedule

original_code:
void keySchedule(bit key[24] , bit schedule[16][24]){
 bit word[88][6];
 int i , j , r;
 for(i = 0; i < 4; i++){
  getChunk(key, word[i], i);
  for(j = 0; j < 6; j++)
   word[i + 4][j] = word[i][j];
 }
 for(i = 4; i < 8; i++)
 {
  sbox(word[i], i - 4);
  if(i < 7)
   arraySum(word[i - 3] , word[i] , word[i] , 6);
  else
   arraySum(word[0] , word[i] , word[i] , 6);
 }
 for(j = 9; j <= 88; j++)
 {
  i = j-1;
  if((j % 8) == 1)
   {
   bit buffer[6];
   arrayCopy(word[i - 1] , buffer , 6);
   rotate(buffer, -1 , 6);
   sbox(buffer , 1);
   arraySum(buffer , word[i - 8], word[i], 6);
   arraySum(word[i], keyScheduleArray , word[i], 6);
   }
  else if((j % 8) == 5)
   {
   bit buffer[6];
   arrayCopy(word[i - 1] , buffer , 6);
   sbox(buffer , 2);
   arraySum(word[i - 8] , buffer , word[i] , 6);
   }
  else if((j % 4) != 1)
   arraySum(word[i - 8] , word[i - 1] , word[i] , 6);
 }
 for(r = 0; r < 3; r++)
 {
  for(j = 0; j < 5; j++)
  {
   int z = (8 + 20*r) + j;
   int index = (r*5)+j;
   for(i = 0; i < 4; i++)
   {
    setChunk(schedule[index] , word[z] , i);
    z += 5;
   }
  }
 }
 int z = 68;
 for(i = 0; i < 4; i++)
 {
  setChunk(schedule[15] , word[z] , i);
  z += 5;
 }
}

canonical_original_code:
void keySchedule(unsigned int key[24], unsigned int schedule[16][24]){
 unsigned int word[88][6];
 int i; int j; int r;
 for(i = 0; i < 4; i++){
  getChunk(key, word[i], i);
  for(j = 0; j < 6; j++)
   word[i + 4][j] = word[i][j];
 }
 for(i = 4; i < 8; i++)
 {
  sbox(word[i], i - 4);
  if(i < 7)
   arraySum(word[i - 3] , word[i] , word[i] , 6);
  else
   arraySum(word[0] , word[i] , word[i] , 6);
 }
 for(j = 9; j <= 88; j++)
 {
  i = j-1;
  if((j % 8) == 1)
   {
   unsigned int buffer[6];
   arrayCopy(word[i - 1] , buffer , 6);
   rotate(buffer, -1 , 6);
   sbox(buffer , 1);
   arraySum(buffer , word[i - 8], word[i], 6);
   arraySum(word[i], keyScheduleArray , word[i], 6);
   }
  else if((j % 8) == 5)
   {
   unsigned int buffer[6];
   arrayCopy(word[i - 1] , buffer , 6);
   sbox(buffer , 2);
   arraySum(word[i - 8] , buffer , word[i] , 6);
   }
  else if((j % 4) != 1)
   arraySum(word[i - 8] , word[i - 1] , word[i] , 6);
 }
 for(r = 0; r < 3; r++)
 {
  for(j = 0; j < 5; j++)
  {
   int z = (8 + 20*r) + j;
   int index = (r*5)+j;
   for(i = 0; i < 4; i++)
   {
    setChunk(schedule[index] , word[z] , i);
    z += 5;
   }
  }
 }
 int z = 68;
 for(i = 0; i < 4; i++)
 {
  setChunk(schedule[15] , word[z] , i);
  z += 5;
 }
}

variable_types:
key
unsigned int [24]

variable_types:
schedule
unsigned int [16][24]

variable_types:
word
unsigned int [88][6]

variable_types: r int

variable_types:
buffer
unsigned int [6]


sboxLayer

decompiled_code:
__int64 __fastcall sboxLayer(__int64 a1)
{
int i; // ebx
__int64 result; // rax
char v3[30]; // [rsp+Ah] [rbp-1Eh] BYREF

for ( i = 0; i != 4; ++i )
{
getChunk(a1, (__int64)v3, i);
sbox((__int64)v3, i);
result = setChunk(a1, (__int64)v3, i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int i; // ebx
__int64 result; // rax
char v3[30]; // [rsp+Ah] [rbp-1Eh] BYREF

for ( i = 0; i != 4; ++i )
{
func0(a1, (__int64)v3, i);
func7((__int64)v3, i);
result = func3(a1, (__int64)v3, i);
}
return result;
}

original_code:
void sboxLayer(bit block[24]){
 int i;
 for(i = 0; i < 4; i++)
 {
  bit chunk[6];
  getChunk(block , chunk , i);
  sbox(chunk , i);
  setChunk(block , chunk , i);
 }
}

canonical_original_code:
void sboxLayer(unsigned int block[24]){
 int i;
 for(i = 0; i < 4; i++)
 {
  unsigned int chunk[6];
  getChunk(block , chunk , i);
  sbox(chunk , i);
  setChunk(block , chunk , i);
 }
}


round

decompiled_code:
__int64 __fastcall round(__int64 a1, __int64 a2)
{
sboxLayer(a1);
mixingLayer(a1);
return arraySum(a1, a2, a1, 24LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
func9(a1);
func4(a1);
return arraySum(a1, a2, a1, 24LL);
}

original_code:
void round(bit block[24], bit key[24]){
 sboxLayer(block);
 mixingLayer(block);
 arraySum(block , key , block , 24);
}

canonical_original_code:
void round(unsigned int block[24], unsigned int key[24]){
 sboxLayer(block);
 mixingLayer(block);
 arraySum(block , key , block , 24);
}


decompiled_code:
__int64 __fastcall bunny24_encrypt(__int64 a1, __int64 a2)
{
_BYTE v3[24]; // [rsp+0h] [rbp-188h] BYREF
char v4[24]; // [rsp+18h] [rbp-170h] BYREF
char v5[24]; // [rsp+30h] [rbp-158h] BYREF
char v6[320]; // [rsp+48h] [rbp-140h] BYREF

keySchedule(a2, (__int64)v3);
arraySum(a1, v3, a1, 24LL);
round(a1, (__int64)v4);
round(a1, (__int64)v5);
return round(a1, (__int64)v6);
}

original_code:
void bunny24_encrypt(bit block[24] , bit key[24]){
 bit keys[16][24];
 keySchedule(key , keys);
 int i;
 arraySum(block , keys[0] , block , 24);
 for(i = 1; i <= 3; i++)
  round(block , keys[i]);
}

canonical_original_code:
void bunny24_encrypt(unsigned int block[24], unsigned int key[24]){
 unsigned int keys[16][24];
 keySchedule(key , keys);
 int i;
 arraySum(block , keys[0] , block , 24);
 for(i = 1; i <= 3; i++)
  round(block , keys[i]);
}

variable_types:
keys
unsigned int [16][24]


decompiled_code:
__int64 __fastcall inverse_sbox(__int64 a1, int a2)
{
int v2; // er12
__int64 result; // rax
int v4; // er12
int v5; // er12
int v6; // er12
int v7; // [rsp+Ah] [rbp-1Eh] BYREF
unsigned __int16 v8; // [rsp+Eh] [rbp-1Ah]

v7 = *(_DWORD *)a1;
v8 = *(_WORD *)(a1 + 4);
if ( a2 == 2 )
{
v6 = 25;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v6;
}
while ( v6 );
}
else if ( a2 > 2 )
{
if ( a2 != 3 )
goto LABEL_18;
BYTE2(v7) ^= 1u;
v4 = 61;
*(_BYTE *)(a1 + 2) ^= 1u;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v4;
}
while ( v4 );
}
else
{
if ( a2 )
{
if ( a2 == 1 )
{
v2 = 37;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v2;
}
while ( v2 );
goto LABEL_7;
}
LABEL_18:
puts("sbox index error ");
goto LABEL_7;
}
v5 = 61;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v5;
}
while ( v5 );
}
LABEL_7:
*(_DWORD *)a1 = v7;
result = v8;
*(_WORD *)(a1 + 4) = v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
int v2; // er12
__int64 result; // rax
int v4; // er12
int v5; // er12
int v6; // er12
int v7; // [rsp+Ah] [rbp-1Eh] BYREF
unsigned __int16 v8; // [rsp+Eh] [rbp-1Ah]

v7 = *(_DWORD *)a1;
v8 = *(_WORD *)(a1 + 4);
if ( a2 == 2 )
{
v6 = 25;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v6;
}
while ( v6 );
}
else if ( a2 > 2 )
{
if ( a2 != 3 )
goto LABEL_18;
BYTE2(v7) ^= 1u;
v4 = 61;
*(_BYTE *)(a1 + 2) ^= 1u;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v4;
}
while ( v4 );
}
else
{
if ( a2 )
{
if ( a2 == 1 )
{
v2 = 37;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v2;
}
while ( v2 );
goto LABEL_7;
}
LABEL_18:
puts("sbox index error ");
goto LABEL_7;
}
v5 = 61;
do
{
arrayMul(&v7, a1, &primitivePoly);
--v5;
}
while ( v5 );
}
LABEL_7:
*(_DWORD *)a1 = v7;
result = v8;
*(_WORD *)(a1 + 4) = v8;
return result;
}

original_code:
void inverse_sbox(bit chunk[6] , int index){
 int i;
 bit result[6];
 for(i = 0; i < 6; i++)
  result[i] = chunk[i];
 switch(index){
  case 0:
   for( i = 1; i < inverse_sbox1_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 1:
   for( i = 1; i < inverse_sbox2_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 2:
   for( i = 1; i < inverse_sbox3_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 3:
   result[2] ^= 1;
   chunk[2] ^= 1;
   for(i = 1; i < inverse_sbox4_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  default : printf("sbox index error \n"); break;
 }
 for(i = 0; i < 6; i++)
  chunk[i] = result[i];
}

canonical_original_code:
void inverse_sbox(unsigned int chunk[6], int index){
 int i;
 unsigned int result[6];
 for(i = 0; i < 6; i++)
  result[i] = chunk[i];
 switch(index){
  case 0:
   for( i = 1; i < inverse_sbox1_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 1:
   for( i = 1; i < inverse_sbox2_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 2:
   for( i = 1; i < inverse_sbox3_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  case 3:
   result[2] ^= 1;
   chunk[2] ^= 1;
   for(i = 1; i < inverse_sbox4_power; i++)
    arrayMul(result , chunk , primitivePoly , result , primitivePolyDegree);
   break;
  default : printf("sbox index error \n"); break;
 }
 for(i = 0; i < 6; i++)
  chunk[i] = result[i];
}


decompiled_code:
__int64 __fastcall inverse_sboxLayer(__int64 a1)
{
int i; // ebx
__int64 result; // rax
char v3[30]; // [rsp+Ah] [rbp-1Eh] BYREF

for ( i = 0; i != 4; ++i )
{
getChunk(a1, (__int64)v3, i);
inverse_sbox((__int64)v3, i);
result = setChunk(a1, (__int64)v3, i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
int i; // ebx
__int64 result; // rax
char v3[30]; // [rsp+Ah] [rbp-1Eh] BYREF

for ( i = 0; i != 4; ++i )
{
func0(a1, (__int64)v3, i);
func12((__int64)v3, i);
result = func3(a1, (__int64)v3, i);
}
return result;
}

original_code:
void inverse_sboxLayer(bit block[24]){
 int i;
 for(i = 0; i < 4; i++)
 {
  bit chunk[6];
  getChunk(block , chunk , i);
  inverse_sbox(chunk , i);
  setChunk(block , chunk , i);
 }
}

canonical_original_code:
void inverse_sboxLayer(unsigned int block[24]){
 int i;
 for(i = 0; i < 4; i++)
 {
  unsigned int chunk[6];
  getChunk(block , chunk , i);
  inverse_sbox(chunk , i);
  setChunk(block , chunk , i);
 }
}


decompiled_code:
__int64 __fastcall inverse_round(__int64 a1, __int64 a2)
{
arraySum(a1, a2, a1, 24LL);
inverse_mixingLayer(a1);
return inverse_sboxLayer(a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
arraySum(a1, a2, a1, 24LL);
func5(a1);
return func13(a1);
}

original_code:
void inverse_round(bit block[24], bit key[24]){
 arraySum(block , key , block , 24);
 inverse_mixingLayer(block);
 inverse_sboxLayer(block);
}

canonical_original_code:
void inverse_round(unsigned int block[24], unsigned int key[24]){
 arraySum(block , key , block , 24);
 inverse_mixingLayer(block);
 inverse_sboxLayer(block);
}


decompiled_code:
__int64 __fastcall bunny24_decrypt(__int64 a1, __int64 a2)
{
_BYTE v3[24]; // [rsp+0h] [rbp-188h] BYREF
char v4[24]; // [rsp+18h] [rbp-170h] BYREF
char v5[24]; // [rsp+30h] [rbp-158h] BYREF
char v6[320]; // [rsp+48h] [rbp-140h] BYREF

keySchedule(a2, (__int64)v3);
inverse_round(a1, (__int64)v6);
inverse_round(a1, (__int64)v5);
inverse_round(a1, (__int64)v4);
return arraySum(a1, v3, a1, 24LL);
}

original_code:
void bunny24_decrypt(bit block[24] , bit key[24]){
 bit keys[16][24];
 keySchedule(key , keys);
 int i;
 for(i = 3; i > 0; i--)
  inverse_round(block , keys[i]);
 arraySum(block , keys[0] , block , 24);
}

canonical_original_code:
void bunny24_decrypt(unsigned int block[24], unsigned int key[24]){
 unsigned int keys[16][24];
 keySchedule(key , keys);
 int i;
 for(i = 3; i > 0; i--)
  inverse_round(block , keys[i]);
 arraySum(block , keys[0] , block , 24);
}


decompiled_code:
__int64 __fastcall bunny24_bruteForce(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 i; // rcx
__int64 result; // rax
char v5[32]; // [rsp+0h] [rbp-68h] BYREF
char v6[72]; // [rsp+20h] [rbp-48h] BYREF

v2 = 0;
while ( 1 )
{
arrayCopy(a1, v6, 24LL);
for ( i = 0LL; i != 24; ++i )
v5[i] = (v2 & (1 << i)) != 0;
bunny24_encrypt((__int64)v6, (__int64)v5);
result = arrayEqual(v6, a2, 24LL);
if ( !(_DWORD)result )
break;
if ( ++v2 == 0x1000000 )
return result;
}
return printHex(v5, 24LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 i; // rcx
__int64 result; // rax
char v5[32]; // [rsp+0h] [rbp-68h] BYREF
char v6[72]; // [rsp+20h] [rbp-48h] BYREF

v2 = 0;
while ( 1 )
{
arrayCopy(a1, v6, 24LL);
for ( i = 0LL; i != 24; ++i )
v5[i] = (v2 & (1 << i)) != 0;
func11((__int64)v6, (__int64)v5);
result = arrayEqual(v6, a2, 24LL);
if ( !(_DWORD)result )
break;
if ( ++v2 == 0x1000000 )
return result;
}
return printHex(v5, 24LL);
}

original_code:
void bunny24_bruteForce(bit plain[24] , bit crypt[24]){
 unsigned int i, end = 1024 * 1024 * 16;
 bit test[24];
 bit testp[24];
 for(i = 0; i < end; i++)
 {
  arrayCopy(plain , testp , 24);
  int j;
  for(j = 0; j < 24; j++)
  {
   if(i & (1 << j))
    test[j] = 1;
   else
    test[j] = 0;
  }
  bunny24_encrypt(testp , test);
  if(arrayEqual(testp , crypt , 24) == 0)
  {
   printHex(test , 24);
   return;
  }
 }
}

canonical_original_code:
void bunny24_bruteForce(unsigned int plain[24], unsigned int crypt[24]){
 unsigned int i; unsigned int end = 1024 * 1024 * 16;
 unsigned int test[24];
 unsigned int testp[24];
 for(i = 0; i < end; i++)
 {
  arrayCopy(plain , testp , 24);
  int j;
  for(j = 0; j < 24; j++)
  {
   if(i & (1 << j))
    test[j] = 1;
   else
    test[j] = 0;
  }
  bunny24_encrypt(testp , test);
  if(arrayEqual(testp , crypt , 24) == 0)
  {
   printHex(test , 24);
   return;
  }
 }
}

variable_types:
plain
unsigned int [24]

variable_types:
crypt
unsigned int [24]

variable_types:
i
unsigned int

variable_types:
end
unsigned int

variable_types:
test
unsigned int [24]

variable_types:
testp
unsigned int [24]

variable_types: j int


isZero

original_code:
int isZero(bit * reg , int length){
 int x = 0;
 int j = 0;
 for(x = 0; x < length; x++)
  if(reg[x] == 0)
   j++;
 if(j == length)
  return 0;
 else
  return 1;
}

canonical_original_code:
int isZero(unsigned int *reg, int length){
 int x = 0;
 int j = 0;
 for(x = 0; x < length; x++)
  if(reg[x] == 0)
   j++;
 if(j == length)
  return 0;
 else
  return 1;
}

variable_types:
reg
unsigned int *

variable_types: length int

variable_types: x int


original_code:
void TOY_init(TOY *toy){
 LFSR temp = { ((void *)0) , ((void *)0) , 0};
 bit TOY_reg1[TOY_degree[0]];
 bit TOY_reg2[TOY_degree[1]];
 bit TOY_reg3[TOY_degree[2]];
 bit TOY_reg4[TOY_degree[3]];
 bit TOY_reg5[TOY_degree[4]];
 initFPRNG();
 int r1 = 0 , r2 = 0, r3 = 0 , r4 = 0, r5 = 0;
 do{
 SPRNG(TOY_reg1 , TOY_degree[0]);
 r1 = isZero(TOY_reg1 , TOY_degree[0]);
 SPRNG(TOY_reg2 , TOY_degree[1]);
 r2 = isZero(TOY_reg2 , TOY_degree[1]);
 SPRNG(TOY_reg3 , TOY_degree[2]);
 r3 = isZero(TOY_reg3 , TOY_degree[2]);
 SPRNG(TOY_reg4 , TOY_degree[3]);
 r4 = isZero(TOY_reg4 , TOY_degree[3]);
 SPRNG(TOY_reg5 , TOY_degree[4]);
 r5 = isZero(TOY_reg5 , TOY_degree[4]);
 }while(r1 == 0 || r2 == 0 || r3 == 0 || r4 == 0 || r5 == 0);
 toy->reg[0] = temp;
 LFSR_init(&toy->reg[0] , TOY_reg1 , TOY_poly1 , TOY_degree[0]);
 toy->reg[1] = temp;
 LFSR_init(&toy->reg[1] , TOY_reg2 , TOY_poly2 , TOY_degree[1]);
 toy->reg[2] = temp;
 LFSR_init(&toy->reg[2] , TOY_reg3 , TOY_poly3 , TOY_degree[2]);
 toy->reg[3] = temp;
 LFSR_init(&toy->reg[3] , TOY_reg4 , TOY_poly4 , TOY_degree[3]);
 toy->reg[4] = temp;
 LFSR_init(&toy->reg[4] , TOY_reg5 , TOY_poly5 , TOY_degree[4]);
}

canonical_original_code:
void TOY_init(struct TOY *toy){
 struct LFSR temp = { ((void *)0) , ((void *)0) , 0};
 unsigned int TOY_reg1[-1];
 unsigned int TOY_reg2[-1];
 unsigned int TOY_reg3[-1];
 unsigned int TOY_reg4[-1];
 unsigned int TOY_reg5[-1];
 initFPRNG();
 int r1 = 0; int r2 = 0; int r3 = 0; int r4 = 0; int r5 = 0;
 do{
 SPRNG(TOY_reg1 , TOY_degree[0]);
 r1 = isZero(TOY_reg1 , TOY_degree[0]);
 SPRNG(TOY_reg2 , TOY_degree[1]);
 r2 = isZero(TOY_reg2 , TOY_degree[1]);
 SPRNG(TOY_reg3 , TOY_degree[2]);
 r3 = isZero(TOY_reg3 , TOY_degree[2]);
 SPRNG(TOY_reg4 , TOY_degree[3]);
 r4 = isZero(TOY_reg4 , TOY_degree[3]);
 SPRNG(TOY_reg5 , TOY_degree[4]);
 r5 = isZero(TOY_reg5 , TOY_degree[4]);
 }while(r1 == 0 || r2 == 0 || r3 == 0 || r4 == 0 || r5 == 0);
 toy->reg[0] = temp;
 LFSR_init(&toy->reg[0] , TOY_reg1 , TOY_poly1 , TOY_degree[0]);
 toy->reg[1] = temp;
 LFSR_init(&toy->reg[1] , TOY_reg2 , TOY_poly2 , TOY_degree[1]);
 toy->reg[2] = temp;
 LFSR_init(&toy->reg[2] , TOY_reg3 , TOY_poly3 , TOY_degree[2]);
 toy->reg[3] = temp;
 LFSR_init(&toy->reg[3] , TOY_reg4 , TOY_poly4 , TOY_degree[3]);
 toy->reg[4] = temp;
 LFSR_init(&toy->reg[4] , TOY_reg5 , TOY_poly5 , TOY_degree[4]);
}

variable_types: struct TOY { struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } reg[5]; } *


original_code:
void TOY_init_with_reg(TOY * toy , bit r1[2] , bit r2[3] , bit r3[4] , bit r4[7] , bit r5[8]){
 LFSR temp = { ((void *)0) , ((void *)0) , 0};
 toy->reg[0] = temp;
 LFSR_init(&toy->reg[0] , r1 , TOY_poly1 , TOY_degree[0]);
 toy->reg[1] = temp;
 LFSR_init(&toy->reg[1] , r2 , TOY_poly2 , TOY_degree[1]);
 toy->reg[2] = temp;
 LFSR_init(&toy->reg[2] , r3 , TOY_poly3 , TOY_degree[2]);
 toy->reg[3] = temp;
 LFSR_init(&toy->reg[3] , r4 , TOY_poly4 , TOY_degree[3]);
 toy->reg[4] = temp;
 LFSR_init(&toy->reg[4] , r5 , TOY_poly5 , TOY_degree[4]);
}

canonical_original_code:
void TOY_init_with_reg(struct TOY *toy, unsigned int r1[2], unsigned int r2[3], unsigned int r3[4], unsigned int r4[7], unsigned int r5[8]){
 struct LFSR temp = { ((void *)0) , ((void *)0) , 0};
 toy->reg[0] = temp;
 LFSR_init(&toy->reg[0] , r1 , TOY_poly1 , TOY_degree[0]);
 toy->reg[1] = temp;
 LFSR_init(&toy->reg[1] , r2 , TOY_poly2 , TOY_degree[1]);
 toy->reg[2] = temp;
 LFSR_init(&toy->reg[2] , r3 , TOY_poly3 , TOY_degree[2]);
 toy->reg[3] = temp;
 LFSR_init(&toy->reg[3] , r4 , TOY_poly4 , TOY_degree[3]);
 toy->reg[4] = temp;
 LFSR_init(&toy->reg[4] , r5 , TOY_poly5 , TOY_degree[4]);
}

variable_types: struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; }


decompiled_code:
int __fastcall TOY_print_intial_state(_QWORD *a1)
{
puts("Reg initial state \n------------------------- ");
printArray(*a1, 2LL);
printArray(a1[3], 3LL);
printArray(a1[6], 4LL);
printArray(a1[9], 7LL);
printArray(a1[12], 8LL);
return puts("------------------------- ");
}

canonical_decompiled_code:
int __fastcall func3(_QWORD *a1)
{
puts("Reg initial state \n------------------------- ");
printArray(*a1, 2LL);
printArray(a1[3], 3LL);
printArray(a1[6], 4LL);
printArray(a1[9], 7LL);
printArray(a1[12], 8LL);
return puts("------------------------- ");
}

original_code:
void TOY_print_intial_state(TOY * toy){
 printf("Reg initial state \n------------------------- \n");
 LFSR * reg1 , *reg2 , *reg3 , *reg4 , *reg5;
 reg1 = &toy->reg[0];
 reg2 = &toy->reg[1];
 reg3 = &toy->reg[2];
 reg4 = &toy->reg[3];
 reg5 = &toy->reg[4];
 printArray(reg1->reg, TOY_degree[0]);
 printArray(reg2->reg , TOY_degree[1]);
 printArray(reg3->reg , TOY_degree[2]);
 printArray(reg4->reg , TOY_degree[3]);
 printArray(reg5->reg , TOY_degree[4]);
 printf("------------------------- \n");
}

canonical_original_code:
void TOY_print_intial_state(struct TOY *toy){
 printf("Reg initial state \n------------------------- \n");
 struct LFSR *reg1; struct LFSR *reg2; struct LFSR *reg3; struct LFSR *reg4; struct LFSR *reg5;
 reg1 = &toy->reg[0];
 reg2 = &toy->reg[1];
 reg3 = &toy->reg[2];
 reg4 = &toy->reg[3];
 reg5 = &toy->reg[4];
 printArray(reg1->reg, TOY_degree[0]);
 printArray(reg2->reg , TOY_degree[1]);
 printArray(reg3->reg , TOY_degree[2]);
 printArray(reg4->reg , TOY_degree[3]);
 printArray(reg5->reg , TOY_degree[4]);
 printf("------------------------- \n");
}

variable_types: struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } *


decompiled_code:
__int64 __fastcall TOY_delete(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

v1 = a1 + 120;
v2 = a1;
do
{
v3 = v2;
v2 += 24LL;
result = LFSR_delete(v3);
}
while ( v2 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

v1 = a1 + 120;
v2 = a1;
do
{
v3 = v2;
v2 += 24LL;
result = LFSR_delete(v3);
}
while ( v2 != v1 );
return result;
}

original_code:
void TOY_delete(TOY *toy){
 int i;
 for(i = 0; i < 5; i++)
  LFSR_delete(&toy->reg[i]);
}

canonical_original_code:
void TOY_delete(struct TOY *toy){
 int i;
 for(i = 0; i < 5; i++)
  LFSR_delete(&toy->reg[i]);
}

variable_types: i int


original_code:
bit TOY_update(TOY *toy){
 bit out[5];
 int i;
 for(i = 0; i < 5; i++)
  out[i] = LFSR_update(&toy->reg[i]);
 bit result = (out[0] & out[1] & out[2] & out[3] & out[4]) ^ (out[3] & out[4]) ^ out[4];
 return result;
}

canonical_original_code:
unsigned int TOY_update(struct TOY *toy){
 unsigned int out[5];
 int i;
 for(i = 0; i < 5; i++)
  out[i] = LFSR_update(&toy->reg[i]);
 unsigned int result = (out[0] & out[1] & out[2] & out[3] & out[4]) ^ (out[3] & out[4]) ^ out[4];
 return result;
}

variable_types:
out
unsigned int [5]

variable_types:
result
unsigned int


decompiled_code:
void __fastcall TOY_getStream(__int64 a1, char *a2, int a3)
{
__int64 v3; // r12
char *v4; // rbx

if ( a3 )
{
v3 = (__int64)&a2[a3 - 1 + 1];
v4 = a2;
do
*v4++ = TOY_update(a1);
while ( v4 != (char *)v3 );
}
}

original_code:
void TOY_getStream(TOY *toy, bit *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = TOY_update(toy);
}

canonical_original_code:
void TOY_getStream(struct TOY *toy, unsigned int *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = TOY_update(toy);
}

variable_types:
result
unsigned int *

variable_types:
stream
unsigned int


canonical_original_code:
void A51_init(struct A51 *a51){
 struct LFSR temp = { ((void *)0) , ((void *)0) , 0};
 a51->reg[0] = temp;
 LFSR_init(&a51->reg[0] , A51_reg1 , A51_poly1 , A51_degree[0]);
 a51->reg[1] = temp;
 LFSR_init(&a51->reg[1] , A51_reg2 , A51_poly2 , A51_degree[1]);
 a51->reg[2] = temp;
 LFSR_init(&a51->reg[2] , A51_reg3 , A51_poly3 , A51_degree[2]);
}

variable_types: struct A51 { struct LFSR { unsigned int *reg; unsigned int *poly; unsigned int degree; } reg[3]; } *


decompiled_code:
__int64 __fastcall A51_delete(__int64 a1)
{
((void (*)(void))LFSR_delete)();
LFSR_delete(a1 + 24);
return LFSR_delete(a1 + 48);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
((void (*)(void))LFSR_delete)();
LFSR_delete(a1 + 24);
return LFSR_delete(a1 + 48);
}

original_code:
void A51_delete(A51 *a51){
 int i;
 for(i = 0; i < 3; i++)
  LFSR_delete(&a51->reg[i]);
}

canonical_original_code:
void A51_delete(struct A51 *a51){
 int i;
 for(i = 0; i < 3; i++)
  LFSR_delete(&a51->reg[i]);
}


decompiled_code:
__int64 __fastcall A51_update(__int64 a1)
{
__int64 v1; // rsi
int v2; // er14
__int64 v3; // r13
unsigned int *v4; // r12
unsigned int *v5; // rbp
__int64 v6; // rbx
unsigned int v7; // er13

v1 = 8LL;
v2 = 0;
v3 = a1;
v4 = (unsigned int *)&A51_clock;
v5 = (unsigned int *)&A51_clock;
v6 = a1;
while ( 1 )
{
v2 += (unsigned __int8)LFSR_getBit(v3, v1) == 0;
++v5;
v3 += 24LL;
if ( v5 == (unsigned int *)1244 )
break;
v1 = *v5;
}
v7 = 0;
if ( v2 <= 1 )
{
if ( (unsigned __int8)LFSR_getBit(a1, 8LL) == 1 )
goto LABEL_14;
LABEL_11:
for ( v7 ^= LFSR_getBit(v6, (unsigned int)(*(_DWORD *)(v6 + 16) - 1)); ; v7 ^= LFSR_update(v6) )
{
++v4;
v6 += 24LL;
if ( v4 == (unsigned int *)1244 )
break;
if ( (unsigned __int8)LFSR_getBit(v6, *v4) != 1 )
goto LABEL_11;
LABEL_14:
;
}
}
else
{
if ( (unsigned __int8)LFSR_getBit(a1, 8LL) )
goto LABEL_9;
LABEL_6:
for ( v7 ^= LFSR_update(v6); ; v7 ^= LFSR_getBit(v6, (unsigned int)(*(_DWORD *)(v6 + 16) - 1)) )
{
++v4;
v6 += 24LL;
if ( v4 == (unsigned int *)1244 )
break;
if ( !(unsigned __int8)LFSR_getBit(v6, *v4) )
goto LABEL_6;
LABEL_9:
;
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rsi
int v2; // er14
__int64 v3; // r13
unsigned int *v4; // r12
unsigned int *v5; // rbp
__int64 v6; // rbx
unsigned int v7; // er13

v1 = 8LL;
v2 = 0;
v3 = a1;
v4 = (unsigned int *)&A51_clock;
v5 = (unsigned int *)&A51_clock;
v6 = a1;
while ( 1 )
{
v2 += (unsigned __int8)LFSR_getBit(v3, v1) == 0;
++v5;
v3 += 24LL;
if ( v5 == (unsigned int *)1244 )
break;
v1 = *v5;
}
v7 = 0;
if ( v2 <= 1 )
{
if ( (unsigned __int8)LFSR_getBit(a1, 8LL) == 1 )
goto LABEL_14;
LABEL_11:
for ( v7 ^= LFSR_getBit(v6, (unsigned int)(*(_DWORD *)(v6 + 16) - 1)); ; v7 ^= LFSR_update(v6) )
{
++v4;
v6 += 24LL;
if ( v4 == (unsigned int *)1244 )
break;
if ( (unsigned __int8)LFSR_getBit(v6, *v4) != 1 )
goto LABEL_11;
LABEL_14:
;
}
}
else
{
if ( (unsigned __int8)LFSR_getBit(a1, 8LL) )
goto LABEL_9;
LABEL_6:
for ( v7 ^= LFSR_update(v6); ; v7 ^= LFSR_getBit(v6, (unsigned int)(*(_DWORD *)(v6 + 16) - 1)) )
{
++v4;
v6 += 24LL;
if ( v4 == (unsigned int *)1244 )
break;
if ( !(unsigned __int8)LFSR_getBit(v6, *v4) )
goto LABEL_6;
LABEL_9:
;
}
}
return v7;
}

original_code:
bit A51_update(A51 *a51){
 int count_zero = 0;
 int i;
 bit output = 0;
 bit temp = 0;
 for(i = 0; i < 3; i++)
 {
  temp = LFSR_getBit(&a51->reg[i] , A51_clock[i]);
  if(temp == 0)
   count_zero ++;
 }
 if(count_zero >= 2)
 {
  for(i = 0; i < 3; i++)
  {
   if(LFSR_getBit(&a51->reg[i], A51_clock[i]) == 0)
    output ^= LFSR_update(&a51->reg[i]);
   else
    output ^= LFSR_getBit(&a51->reg[i], (a51->reg[i].degree-1));
  }
 }
 else
 {
  for(i = 0; i < 3; i++)
  {
   if(LFSR_getBit(&a51->reg[i], A51_clock[i]) == 1)
    output ^= LFSR_update(&a51->reg[i]);
   else
    output ^= LFSR_getBit(&a51->reg[i], (a51->reg[i].degree-1));
  }
 }
 return output;
}

canonical_original_code:
unsigned int A51_update(struct A51 *a51){
 int count_zero = 0;
 int i;
 unsigned int output = 0;
 unsigned int temp = 0;
 for(i = 0; i < 3; i++)
 {
  temp = LFSR_getBit(&a51->reg[i] , A51_clock[i]);
  if(temp == 0)
   count_zero ++;
 }
 if(count_zero >= 2)
 {
  for(i = 0; i < 3; i++)
  {
   if(LFSR_getBit(&a51->reg[i], A51_clock[i]) == 0)
    output ^= LFSR_update(&a51->reg[i]);
   else
    output ^= LFSR_getBit(&a51->reg[i], (a51->reg[i].degree-1));
  }
 }
 else
 {
  for(i = 0; i < 3; i++)
  {
   if(LFSR_getBit(&a51->reg[i], A51_clock[i]) == 1)
    output ^= LFSR_update(&a51->reg[i]);
   else
    output ^= LFSR_getBit(&a51->reg[i], (a51->reg[i].degree-1));
  }
 }
 return output;
}

variable_types:
output
unsigned int

variable_types:
temp
unsigned int


decompiled_code:
__int64 __fastcall A51_warmUpStream(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a2 )
{
for ( i = 0; i != a2; ++i )
result = A51_update(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a2 )
{
for ( i = 0; i != a2; ++i )
result = func2(a1);
}
return result;
}

original_code:
void A51_warmUpStream(A51 *a51, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  A51_update(a51);
}

canonical_original_code:
void A51_warmUpStream(struct A51 *a51, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  A51_update(a51);
}


original_code:
void A51_getStream(A51 *a51, bit *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = A51_update(a51);
}

canonical_original_code:
void A51_getStream(struct A51 *a51, unsigned int *result, unsigned int stream){
 int i;
 for(i = 0; i < stream; i++)
  result[i] = A51_update(a51);
}


decompiled_code:
__int64 __fastcall A51_encrypt(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
__int64 v6; // rbx
char v7; // dl
__int64 i; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v4 = 0LL;
v6 = a4;
do
{
A51_getStream(a1, v10, 8);
v7 = *(_BYTE *)(a2 + v4);
for ( i = 0LL; i != 8; ++i )
{
result = (unsigned __int8)v10[i] << i;
v7 ^= result;
}
*(_BYTE *)(a3 + v4++) = v7;
}
while ( v4 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
__int64 v6; // rbx
char v7; // dl
__int64 i; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v4 = 0LL;
v6 = a4;
do
{
func4(a1, v10, 8);
v7 = *(_BYTE *)(a2 + v4);
for ( i = 0LL; i != 8; ++i )
{
result = (unsigned __int8)v10[i] << i;
v7 ^= result;
}
*(_BYTE *)(a3 + v4++) = v7;
}
while ( v4 != v6 );
}
return result;
}

original_code:
void A51_encrypt(A51 *a51, byte *plaintext, byte *chipertext, unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  bit temp[8];
  A51_getStream(a51 , temp , 8);
  byte currentByte = plaintext[i];
  for(j = 0; j < 8; j++)
  {
  bit x = temp[j] << j;
  currentByte ^= x;
  }
  chipertext[i] = currentByte;
 }
}

canonical_original_code:
void A51_encrypt(struct A51 *a51, unsigned int *plaintext, unsigned int *chipertext, unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  unsigned int temp[8];
  A51_getStream(a51 , temp , 8);
  unsigned int currentByte = plaintext[i];
  for(j = 0; j < 8; j++)
  {
  unsigned int x = temp[j] << j;
  currentByte ^= x;
  }
  chipertext[i] = currentByte;
 }
}

variable_types:
plaintext
unsigned int *

variable_types:
chipertext
unsigned int *

variable_types:
length
unsigned int

variable_types:
temp
unsigned int [8]

variable_types:
currentByte
unsigned int

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall A51_decrypt(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
__int64 v6; // rbx
char v7; // dl
__int64 i; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v4 = 0LL;
v6 = a4;
do
{
A51_getStream(a1, v10, 8);
v7 = *(_BYTE *)(a3 + v4);
for ( i = 0LL; i != 8; ++i )
{
result = (unsigned __int8)v10[i] << i;
v7 ^= result;
}
*(_BYTE *)(a2 + v4++) = v7;
}
while ( v4 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
__int64 v6; // rbx
char v7; // dl
__int64 i; // rcx
__int64 result; // rax
char v10[48]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 )
{
v4 = 0LL;
v6 = a4;
do
{
func4(a1, v10, 8);
v7 = *(_BYTE *)(a3 + v4);
for ( i = 0LL; i != 8; ++i )
{
result = (unsigned __int8)v10[i] << i;
v7 ^= result;
}
*(_BYTE *)(a2 + v4++) = v7;
}
while ( v4 != v6 );
}
return result;
}

original_code:
void A51_decrypt(A51 *a51, byte *plaintext, byte *chipertext, unsigned int length){
 int i , j;
 for(i = 0; i < length; i++)
 {
  bit temp[8];
  A51_getStream(a51 , temp , 8);
  byte currentByte = chipertext[i];
  for(j = 0; j < 8; j++)
  {
  bit x = temp[j] << j;
  currentByte ^= x;
  }
  plaintext[i] = currentByte;
 }
}

canonical_original_code:
void A51_decrypt(struct A51 *a51, unsigned int *plaintext, unsigned int *chipertext, unsigned int length){
 int i; int j;
 for(i = 0; i < length; i++)
 {
  unsigned int temp[8];
  A51_getStream(a51 , temp , 8);
  unsigned int currentByte = chipertext[i];
  for(j = 0; j < 8; j++)
  {
  unsigned int x = temp[j] << j;
  currentByte ^= x;
  }
  plaintext[i] = currentByte;
 }
}

variable_types: j int


getCipherLength

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

result = a1;
if ( __ROR4__(-1431655765 * a1 + 715827880, 3) > 0xAAAAAAAu )
result = (unsigned int)(8 * (3 * ((int)a1 / 24) + 3));
return result;
}

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

result = a1;
if ( __ROR4__(-1431655765 * a1 + 715827880, 3) > 0xAAAAAAAu )
result = (unsigned int)(8 * (3 * ((int)a1 / 24) + 3));
return result;
}

original_code:
int getCipherLength(int length){
 if(length % 24 == 0)
  return length;
 return (length / 24 + 1) * 24;
}

variable_types: length int