dictExpand

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

v2 = dictNextPower(a2);
result = 1LL;
if ( a1[3] <= a2 )
{
a1[1] = v2;
a1[2] = v2 - 1;
if ( *a1 )
*a1 = wrealloc(*a1, 8 * v2);
else
*a1 = wmalloc(8 * v2);
memset((void *)*a1, 0, 8 * v2);
result = 0LL;
}
return result;
}

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

v2 = func0(a2);
result = 1LL;
if ( a1[3] <= a2 )
{
a1[1] = v2;
a1[2] = v2 - 1;
if ( *a1 )
*a1 = wrealloc(*a1, 8 * v2);
else
*a1 = wmalloc(8 * v2);
memset((void *)*a1, 0, 8 * v2);
result = 0LL;
}
return result;
}

original_code:
int dictExpand(struct dict *d, unsigned long size)
{
    unsigned long realsize = _dictNextPower(size);
    if (d->used > size)
        return 1;
    d->size = realsize;
    d->sizemask = realsize-1;
    if (d->table)
        d->table = wrealloc(d->table, realsize*sizeof(struct dictEntry*));
    else
        d->table = wmalloc(realsize*sizeof(struct dictEntry*));
    memset(d->table, 0, realsize*sizeof(struct dictEntry*));
    return 0;
}

canonical_original_code:
int dictExpand(struct dict *d, unsigned long size)
{
    unsigned long realsize = _dictNextPower(size);
    if (d->used > size)
        return 1;
    d->size = realsize;
    d->sizemask = realsize-1;
    if (d->table)
        d->table = wrealloc(d->table, realsize*sizeof(struct dictEntry *));
    else
        d->table = wmalloc(realsize*sizeof(struct dictEntry *));
    memset(d->table, 0, realsize*sizeof(struct dictEntry *));
    return 0;
}

variable_types:
size
unsigned long

variable_types:
realsize
unsigned long

user_defined_types: struct dictEntry { void *key; union { void *val; unsigned long u64; long s64; } v; struct dictEntry *next; }

user_defined_types: struct dictType { unsigned int (*hashFunction)(void *key); void *(*keyDup)(void *key); void *(*valDup)(void *obj); int (*keyCompare)(void *key1, void *key2); void (*keyDestructor)(void *key); void (*valDestructor)(void *obj); }


dictAdd

original_code:
int dictAdd(struct dict *d, void *key, void *val)
{
    struct dictEntry *entry = dictAddRaw(d,key);
    if (!entry) return 1;
    do { if ((d)->type->valDup) entry->v.val = (d)->type->valDup(val); else entry->v.val = (val); } while(0);
    return 0;
}

variable_types: struct dict { struct dictEntry { void *key; union { void *val; unsigned long u64; long s64; } v; struct dictEntry *next; } **table; unsigned long size; unsigned long sizemask; unsigned long used; struct dictType { unsigned int (*hashFunction)(void *key); void *(*keyDup)(void *key); void *(*valDup)(void *obj); int (*keyCompare)(void *key1, void *key2); void (*keyDestructor)(void *key); void (*valDestructor)(void *obj); } *type; } *

variable_types:
key
void *

variable_types:
val
void *

return_type: int

user_defined_types: struct dict { struct dictEntry **table; unsigned long size; unsigned long sizemask; unsigned long used; struct dictType *type; }


dictReplace

original_code:
int dictReplace(struct dict *d, void *key, void *val, int *replace)
{
    struct dictEntry *entry, auxentry;
    if (dictAdd(d, key, val) == 0) {
        if (replace)
            *replace = 0;
        return 0;
    }
    entry = dictFind(d, key);
    if (entry == ((void *)0)) {
        return 1;
    }
    auxentry = *entry;
    do { if ((d)->type->valDup) entry->v.val = (d)->type->valDup(val); else entry->v.val = (val); } while(0);
    if ((d)->type->valDestructor && (&auxentry)->v.val) (d)->type->valDestructor((&auxentry)->v.val);
    if (replace)
        *replace = 1;
    return 0;
}

canonical_original_code:
int dictReplace(struct dict *d, void *key, void *val, int *replace)
{
    struct dictEntry *entry; struct dictEntry auxentry;
    if (dictAdd(d, key, val) == 0) {
        if (replace)
            *replace = 0;
        return 0;
    }
    entry = dictFind(d, key);
    if (entry == ((void *)0)) {
        return 1;
    }
    auxentry = *entry;
    do { if ((d)->type->valDup) entry->v.val = (d)->type->valDup(val); else entry->v.val = (val); } while(0);
    if ((d)->type->valDestructor && (&auxentry)->v.val) (d)->type->valDestructor((&auxentry)->v.val);
    if (replace)
        *replace = 1;
    return 0;
}

variable_types:
replace
int *

variable_types: struct dictEntry { void *key; union { void *val; unsigned long u64; long s64; } v; struct dictEntry *next; } *


dictDelete

decompiled_code:
__int64 __fastcall dictDelete(__int64 a1, __int64 a2)
{
return dictGenericDelete(a1, a2, 0);
}

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

original_code:
int dictDelete(struct dict *ht, const void *key) {
    return dictGenericDelete(ht, key, 0);
}

canonical_original_code:
int dictDelete(struct dict *ht, void *key) {
    return dictGenericDelete(ht, key, 0);
}


dictDeleteNoFree

decompiled_code:
__int64 __fastcall dictDeleteNoFree(__int64 a1, __int64 a2)
{
return dictGenericDelete(a1, a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
return func1(a1, a2, 1);
}

original_code:
int dictDeleteNoFree(struct dict *ht, const void *key) {
    return dictGenericDelete(ht, key, 1);
}

canonical_original_code:
int dictDeleteNoFree(struct dict *ht, void *key) {
    return dictGenericDelete(ht, key, 1);
}


dictRelease

decompiled_code:
__int64 __fastcall dictRelease(_QWORD *a1)
{
dictClear(a1);
return wfree(a1);
}

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

original_code:
void dictRelease(struct dict *d)
{
    dictClear(d);
    wfree(d);
}

return_type: void


dictNext

decompiled_code:
__int64 __fastcall dictNext(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rcx
int v3; // edx

do
{
result = a1[2];
if ( result )
{
a1[2] = a1[3];
}
else
{
v2 = *a1;
v3 = *((_DWORD *)a1 + 3) + 1;
*((_DWORD *)a1 + 3) = v3;
if ( v3 >= *(_DWORD *)(v2 + 8) )
return result;
a1[2] = *(_QWORD *)(*(_QWORD *)v2 + 8LL * v3);
}
result = a1[2];
}
while ( !result );
a1[3] = *(_QWORD *)(result + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rcx
int v3; // edx

do
{
result = a1[2];
if ( result )
{
a1[2] = a1[3];
}
else
{
v2 = *a1;
v3 = *((_DWORD *)a1 + 3) + 1;
*((_DWORD *)a1 + 3) = v3;
if ( v3 >= *(_DWORD *)(v2 + 8) )
return result;
a1[2] = *(_QWORD *)(*(_QWORD *)v2 + 8LL * v3);
}
result = a1[2];
}
while ( !result );
a1[3] = *(_QWORD *)(result + 16);
return result;
}

original_code:
struct dictEntry *dictNext(struct dictIterator *iter)
{
    while (1) {
        if (iter->entry == ((void *)0)) {
            struct dict *d = iter->d;
            iter->index++;
            if (iter->index >= (signed) d->size) {
                break;
            }
            iter->entry = d->table[iter->index];
        } else {
            iter->entry = iter->nextEntry;
        }
        if (iter->entry) {
            iter->nextEntry = iter->entry->next;
            return iter->entry;
        }
    }
    return ((void *)0);
}

canonical_original_code:
struct dictEntry *dictNext(struct dictIterator *iter)
{
    while (1) {
        if (iter->entry == ((void *)0)) {
            struct dict *d = iter->d;
            iter->index++;
            if (iter->index >= (int) d->size) {
                break;
            }
            iter->entry = d->table[iter->index];
        } else {
            iter->entry = iter->nextEntry;
        }
        if (iter->entry) {
            iter->nextEntry = iter->entry->next;
            return iter->entry;
        }
    }
    return ((void *)0);
}

variable_types: struct dictIterator { struct dict { struct dictEntry **table; unsigned long size; unsigned long sizemask; unsigned long used; struct dictType { unsigned int (*hashFunction)(void *key); void *(*keyDup)(void *key); void *(*valDup)(void *obj); int (*keyCompare)(void *key1, void *key2); void (*keyDestructor)(void *key); void (*valDestructor)(void *obj); } *type; } *d; int table; struct dictEntry *entry; } *

return_type: struct dictEntry { void *key; union { void *val; unsigned long u64; long s64; } v; struct dictEntry *next; } *

user_defined_types: struct dictIterator { struct dict *d; int table; struct dictEntry *entry; }


dictReleaseIterator

decompiled_code:
__int64 __fastcall dictReleaseIterator(__int64 a1)
{
return wfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return wfree(a1);
}

original_code:
void dictReleaseIterator(struct dictIterator *iter)
{
    wfree(iter);
}

variable_types: struct dictIterator { struct dict { struct dictEntry { void *key; union { void *val; unsigned long u64; long s64; } v; struct dictEntry *next; } **table; unsigned long size; unsigned long sizemask; unsigned long used; struct dictType { unsigned int (*hashFunction)(void *key); void *(*keyDup)(void *key); void *(*valDup)(void *obj); int (*keyCompare)(void *key1, void *key2); void (*keyDestructor)(void *key); void (*valDestructor)(void *obj); } *type; } *d; int table; struct dictEntry *entry; } *


dictGenHashFunction

original_code:
unsigned int dictGenHashFunction(const void *key, int len) {
    uint32_t seed = dict_hash_function_seed;
    const uint32_t m = 0x5bd1e995;
    const int r = 24;
    uint32_t h = seed ^ len;
    const unsigned char *data = (const unsigned char *)key;
    while(len >= 4) {
        uint32_t k = *(uint32_t*)data;
        k *= m;
        k ^= k >> r;
        k *= m;
        h *= m;
        h ^= k;
        data += 4;
        len -= 4;
    }
    switch(len) {
    case 3: h ^= data[2] << 16;
    case 2: h ^= data[1] << 8;
    case 1: h ^= data[0]; h *= m;
    };
    h ^= h >> 13;
    h *= m;
    h ^= h >> 15;
    return (unsigned int)h;
}

canonical_original_code:
unsigned int dictGenHashFunction(void *key, int len) {
    unsigned int seed = dict_hash_function_seed;
    unsigned int m = 0x5bd1e995;
    int r = 24;
    unsigned int h = seed ^ len;
    unsigned char *data = (const unsigned char *)key;
    while(len >= 4) {
        unsigned int k = *(uint32_t*)data;
        k *= m;
        k ^= k >> r;
        k *= m;
        h *= m;
        h ^= k;
        data += 4;
        len -= 4;
    }
    switch(len) {
    case 3: h ^= data[2] << 16;
    case 2: h ^= data[1] << 8;
    case 1: h ^= data[0]; h *= m;
    };
    h ^= h >> 13;
    h *= m;
    h ^= h >> 15;
    return (unsigned int)h;
}

variable_types: len int

variable_types:
seed
unsigned int

variable_types:
m
unsigned int

variable_types: r int

variable_types:
h
unsigned int

variable_types:
data
unsigned char *

variable_types:
k
unsigned int

return_type: unsigned int


dictGenCaseHashFunction

decompiled_code:
__int64 __fastcall dictGenCaseHashFunction(unsigned __int8 *a1, int a2)
{
const __int32_t *v3; // rdi
unsigned __int8 *v4; // rsi
unsigned int v5; // edx

if ( !a2 )
return 2128LL;
v3 = *_ctype_tolower_loc();
v4 = &a1[a2];
v5 = 2128;
do
v5 += v3[*a1++] + 32 * v5;
while ( a1 != v4 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned __int8 *a1, int a2)
{
const __int32_t *v3; // rdi
unsigned __int8 *v4; // rsi
unsigned int v5; // edx

if ( !a2 )
return 2128LL;
v3 = *_ctype_tolower_loc();
v4 = &a1[a2];
v5 = 2128;
do
v5 += v3[*a1++] + 32 * v5;
while ( a1 != v4 );
return v5;
}

original_code:
unsigned int dictGenCaseHashFunction(const unsigned char *buf, int len) {
    unsigned int hash = (unsigned int)dict_hash_function_seed;
    while (len--)
        hash = ((hash << 5) + hash) + (tolower(*buf++));
    return hash;
}

canonical_original_code:
unsigned int dictGenCaseHashFunction(unsigned char *buf, int len) {
    unsigned int hash = (unsigned int)dict_hash_function_seed;
    while (len--)
        hash = ((hash << 5) + hash) + (tolower(*buf++));
    return hash;
}

variable_types:
buf
unsigned char *

variable_types:
hash
unsigned int


dictPrint

decompiled_code:
__int64 __fastcall dictPrint(__int64 a1)
{
__int64 *v1; // rbx
const char **v2; // rax

v1 = (__int64 *)dictGetIterator(a1);
while ( 1 )
{
v2 = (const char **)dictNext(v1);
if ( !v2 )
break;
printf("%s -> %s \n", *v2, v2[1]);
}
return dictReleaseIterator((__int64)v1);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
__int64 *v1; // rbx
const char **v2; // rax

v1 = (__int64 *)func11(a1);
while ( 1 )
{
v2 = (const char **)func12(v1);
if ( !v2 )
break;
printf("%s -> %s \n", *v2, v2[1]);
}
return func13((__int64)v1);
}

original_code:
void dictPrint(struct dict *d)
{
    struct dictIterator *iter = dictGetIterator(d);
    struct dictEntry *entry;
    while ((entry = dictNext(iter)) != ((void *)0)) {
        printf("%s -> %s \n", (char *)entry->key, (char *)entry->v.val);
    }
    dictReleaseIterator(iter);
}


dictPrintStats

decompiled_code:
int __fastcall dictPrintStats(__int64 a1)
{
char *v1; // rax
__int64 v2; // rbx
__int64 *v3; // rcx
__int64 v4; // rsi
__int64 v5; // r13
unsigned __int64 v6; // r12
int result; // eax
__int64 v8; // rax
__int64 v9; // rax
unsigned __int64 v10; // rdx
float v11; // xmm0_4
__int64 v12; // rax
float v13; // xmm0_4
__int64 i; // rbx
__int64 v15; // rdx
__int64 v16; // rax
float v17; // xmm0_4
__int64 v18; // rdx
float v19; // xmm1_4
__int64 v20; // rcx
__int64 v21; // rax
float v22; // [rsp+Ch] [rbp-1BCh]
__int64 v23[50]; // [rsp+10h] [rbp-1B8h] BYREF
char v24; // [rsp+1A0h] [rbp-28h] BYREF

v1 = (char *)v23;
if ( !*(_QWORD *)(a1 + 24) )
return puts("No stats available for empty dictionaries");
do
{
*(_QWORD *)v1 = 0LL;
v1 += 8;
}
while ( &v24 != v1 );
v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
{
v3 = *(__int64 **)a1;
v4 = *(_QWORD *)a1 + 8 * v2;
v5 = 0LL;
v6 = 0LL;
v2 = 0LL;
do
{
v9 = *v3;
if ( *v3 )
{
++v2;
v10 = 0LL;
do
{
++v10;
v9 = *(_QWORD *)(v9 + 16);
}
while ( v9 );
v8 = 49LL;
if ( v10 <= 0x31 )
v8 = v10;
++v23[v8];
if ( v6 < v10 )
v6 = v10;
v5 += v10;
}
else
{
++v23[0];
}
++v3;
}
while ( (__int64 *)v4 != v3 );
}
else
{
v5 = 0LL;
v6 = 0LL;
}
puts("Hash table stats:");
printf(" table size: %ld\n", *(_QWORD *)(a1 + 8));
printf(" number of elements: %ld\n", *(_QWORD *)(a1 + 24));
printf(" different slots: %ld\n", v2);
printf(" max chain length: %ld\n", v6);
if ( v2 < 0 )
v22 = (float)(v2 & 1 | (unsigned int)((unsigned __int64)v2 >> 1))
+ (float)(v2 & 1 | (unsigned int)((unsigned __int64)v2 >> 1));
else
v22 = (float)(int)v2;
if ( v5 < 0 )
v11 = (float)(v5 & 1 | (unsigned int)((unsigned __int64)v5 >> 1))
+ (float)(v5 & 1 | (unsigned int)((unsigned __int64)v5 >> 1));
else
v11 = (float)(int)v5;
printf(" avg chain length (counted): %.02f\n", (float)(v11 / v22));
v12 = *(_QWORD *)(a1 + 24);
if ( v12 < 0 )
{
v15 = *(_QWORD *)(a1 + 24) & 1LL | ((unsigned __int64)v12 >> 1);
v13 = (float)(int)v15 + (float)(int)v15;
}
else
{
v13 = (float)(int)v12;
}
printf(" avg chain length (computed): %.02f\n", (float)(v13 / v22));
result = puts(" Chain length distribution:");
for ( i = 0LL; i != 49; ++i )
{
v20 = v23[i];
if ( v20 )
{
if ( v20 < 0 )
{
v16 = v23[i] & 1 | ((unsigned __int64)v20 >> 1);
v17 = (float)(int)v16 + (float)(int)v16;
}
else
{
v17 = (float)(int)v20;
}
v21 = *(_QWORD *)(a1 + 8);
if ( v21 < 0 )
{
v18 = *(_QWORD *)(a1 + 8) & 1LL | ((unsigned __int64)v21 >> 1);
v19 = (float)(int)v18 + (float)(int)v18;
}
else
{
v19 = (float)(int)v21;
}
result = printf(" %s%ld: %ld (%.02f%%)\n", (const char *)&unk_A20, i, v20, (float)((float)(v17 / v19) * 100.0));
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(__int64 a1)
{
char *v1; // rax
__int64 v2; // rbx
__int64 *v3; // rcx
__int64 v4; // rsi
__int64 v5; // r13
unsigned __int64 v6; // r12
int result; // eax
__int64 v8; // rax
__int64 v9; // rax
unsigned __int64 v10; // rdx
float v11; // xmm0_4
__int64 v12; // rax
float v13; // xmm0_4
__int64 i; // rbx
__int64 v15; // rdx
__int64 v16; // rax
float v17; // xmm0_4
__int64 v18; // rdx
float v19; // xmm1_4
__int64 v20; // rcx
__int64 v21; // rax
float v22; // [rsp+Ch] [rbp-1BCh]
__int64 v23[50]; // [rsp+10h] [rbp-1B8h] BYREF
char v24; // [rsp+1A0h] [rbp-28h] BYREF

v1 = (char *)v23;
if ( !*(_QWORD *)(a1 + 24) )
return puts("No stats available for empty dictionaries");
do
{
*(_QWORD *)v1 = 0LL;
v1 += 8;
}
while ( &v24 != v1 );
v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
{
v3 = *(__int64 **)a1;
v4 = *(_QWORD *)a1 + 8 * v2;
v5 = 0LL;
v6 = 0LL;
v2 = 0LL;
do
{
v9 = *v3;
if ( *v3 )
{
++v2;
v10 = 0LL;
do
{
++v10;
v9 = *(_QWORD *)(v9 + 16);
}
while ( v9 );
v8 = 49LL;
if ( v10 <= 0x31 )
v8 = v10;
++v23[v8];
if ( v6 < v10 )
v6 = v10;
v5 += v10;
}
else
{
++v23[0];
}
++v3;
}
while ( (__int64 *)v4 != v3 );
}
else
{
v5 = 0LL;
v6 = 0LL;
}
puts("Hash table stats:");
printf(" table size: %ld\n", *(_QWORD *)(a1 + 8));
printf(" number of elements: %ld\n", *(_QWORD *)(a1 + 24));
printf(" different slots: %ld\n", v2);
printf(" max chain length: %ld\n", v6);
if ( v2 < 0 )
v22 = (float)(v2 & 1 | (unsigned int)((unsigned __int64)v2 >> 1))
+ (float)(v2 & 1 | (unsigned int)((unsigned __int64)v2 >> 1));
else
v22 = (float)(int)v2;
if ( v5 < 0 )
v11 = (float)(v5 & 1 | (unsigned int)((unsigned __int64)v5 >> 1))
+ (float)(v5 & 1 | (unsigned int)((unsigned __int64)v5 >> 1));
else
v11 = (float)(int)v5;
printf(" avg chain length (counted): %.02f\n", (float)(v11 / v22));
v12 = *(_QWORD *)(a1 + 24);
if ( v12 < 0 )
{
v15 = *(_QWORD *)(a1 + 24) & 1LL | ((unsigned __int64)v12 >> 1);
v13 = (float)(int)v15 + (float)(int)v15;
}
else
{
v13 = (float)(int)v12;
}
printf(" avg chain length (computed): %.02f\n", (float)(v13 / v22));
result = puts(" Chain length distribution:");
for ( i = 0LL; i != 49; ++i )
{
v20 = v23[i];
if ( v20 )
{
if ( v20 < 0 )
{
v16 = v23[i] & 1 | ((unsigned __int64)v20 >> 1);
v17 = (float)(int)v16 + (float)(int)v16;
}
else
{
v17 = (float)(int)v20;
}
v21 = *(_QWORD *)(a1 + 8);
if ( v21 < 0 )
{
v18 = *(_QWORD *)(a1 + 8) & 1LL | ((unsigned __int64)v21 >> 1);
v19 = (float)(int)v18 + (float)(int)v18;
}
else
{
v19 = (float)(int)v21;
}
result = printf(" %s%ld: %ld (%.02f%%)\n", (const char *)&unk_A20, i, v20, (float)((float)(v17 / v19) * 100.0));
}
}
return result;
}

original_code:
void dictPrintStats(struct dict *d) {
    unsigned long i, slots = 0, chainlen, maxchainlen = 0;
    unsigned long totchainlen = 0;
    unsigned long clvector[50];
    if (d->used == 0) {
        printf("No stats available for empty dictionaries\n");
        return;
    }
    for (i = 0; i < 50; i++) clvector[i] = 0;
    for (i = 0; i < d->size; i++) {
        struct dictEntry *he;
        if (d->table[i] == ((void *)0)) {
            clvector[0]++;
            continue;
        }
        slots++;
        chainlen = 0;
        he = d->table[i];
        while(he) {
            chainlen++;
            he = he->next;
        }
        clvector[(chainlen < 50) ? chainlen : (50 -1)]++;
        if (chainlen > maxchainlen) maxchainlen = chainlen;
        totchainlen += chainlen;
    }
    printf("Hash table stats:\n");
    printf(" table size: %ld\n", d->size);
    printf(" number of elements: %ld\n", d->used);
    printf(" different slots: %ld\n", slots);
    printf(" max chain length: %ld\n", maxchainlen);
    printf(" avg chain length (counted): %.02f\n", (float)totchainlen/slots);
    printf(" avg chain length (computed): %.02f\n", (float)d->used/slots);
    printf(" Chain length distribution:\n");
    for (i = 0; i < 50 -1; i++) {
        if (clvector[i] == 0) continue;
        printf("   %s%ld: %ld (%.02f%%)\n",(i == 50 -1)?">= ":"", i, clvector[i], ((float)clvector[i]/d->size)*100);
    }
}

canonical_original_code:
void dictPrintStats(struct dict *d) {
    unsigned long i; unsigned long slots = 0; unsigned long chainlen; unsigned long maxchainlen = 0;
    unsigned long totchainlen = 0;
    unsigned long clvector[50];
    if (d->used == 0) {
        printf("No stats available for empty dictionaries\n");
        return;
    }
    for (i = 0; i < 50; i++) clvector[i] = 0;
    for (i = 0; i < d->size; i++) {
        struct dictEntry *he;
        if (d->table[i] == ((void *)0)) {
            clvector[0]++;
            continue;
        }
        slots++;
        chainlen = 0;
        he = d->table[i];
        while(he) {
            chainlen++;
            he = he->next;
        }
        clvector[(chainlen < 50) ? chainlen : (50 -1)]++;
        if (chainlen > maxchainlen) maxchainlen = chainlen;
        totchainlen += chainlen;
    }
    printf("Hash table stats:\n");
    printf(" table size: %ld\n", d->size);
    printf(" number of elements: %ld\n", d->used);
    printf(" different slots: %ld\n", slots);
    printf(" max chain length: %ld\n", maxchainlen);
    printf(" avg chain length (counted): %.02f\n", (float)totchainlen/slots);
    printf(" avg chain length (computed): %.02f\n", (float)d->used/slots);
    printf(" Chain length distribution:\n");
    for (i = 0; i < 50 -1; i++) {
        if (clvector[i] == 0) continue;
        printf("   %s%ld: %ld (%.02f%%)\n",(i == 50 -1)?">= ":"", i, clvector[i], ((float)clvector[i]/d->size)*100);
    }
}

variable_types:
i
unsigned long

variable_types:
slots
unsigned long

variable_types:
chainlen
unsigned long

variable_types:
maxchainlen
unsigned long

variable_types:
totchainlen
unsigned long

variable_types:
clvector
unsigned long [50]


wstrlen

decompiled_code:
__int64 __fastcall wstrlen(__int64 a1)
{
return *(unsigned int *)(a1 - 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(unsigned int *)(a1 - 8);
}

original_code:
static inline int wstrlen(const wstr s)
{
    struct wstrhd *hd = (struct wstrhd *)(s - sizeof(struct wstrhd));
    return hd->len;
}

canonical_original_code:
static inline int wstrlen(char *s)
{
    struct wstrhd *hd = (struct wstrhd *)(s - sizeof(struct wstrhd));
    return hd->len;
}

variable_types:
s
char *

variable_types: struct wstrhd { int len; int free; char buf[]; } *


readBulkFrom

decompiled_code:
ssize_t __fastcall readBulkFrom(unsigned int a1, __int64 a2)
{
ssize_t result; // rax
int v4; // edi
char *v5; // rax

result = read(a1, *(void **)a2, *(_QWORD *)(a2 + 8));
if ( result == -1 )
{
v4 = *_errno_location();
if ( v4 == 11 )
{
result = 0LL;
}
else
{
v5 = strerror(v4);
wheatLog(2LL, "Reading from fd %d: %s", a1, v5);
result = 0xFFFFFFFFLL;
}
}
else if ( !result )
{
wheatLog(0LL, "Peer close file descriptor %d", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(unsigned int a1, __int64 a2)
{
ssize_t result; // rax
int v4; // edi
char *v5; // rax

result = read(a1, *(void **)a2, *(_QWORD *)(a2 + 8));
if ( result == -1 )
{
v4 = *_errno_location();
if ( v4 == 11 )
{
result = 0LL;
}
else
{
v5 = strerror(v4);
wheatLog(2LL, "Reading from fd %d: %s", a1, v5);
result = 0xFFFFFFFFLL;
}
}
else if ( !result )
{
wheatLog(0LL, "Peer close file descriptor %d", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int readBulkFrom(int fd, struct slice *slice)
{
    ssize_t nread;
    nread = read(fd, slice->data, slice->len);
    if (nread == -1) {
        if ((*__errno_location ()) == 11) {
            nread = 0;
        } else {
            wheatLog(2, "Reading from fd %d: %s", fd, strerror((*__errno_location ())));
            return -1;
        }
    } else if (nread == 0) {
        wheatLog(0, "Peer close file descriptor %d", fd);
        return -1;
    }
    return (int)nread;
}

canonical_original_code:
int readBulkFrom(int fd, struct slice *slice)
{
    long nread;
    nread = read(fd, slice->data, slice->len);
    if (nread == -1) {
        if ((*__errno_location ()) == 11) {
            nread = 0;
        } else {
            wheatLog(2, "Reading from fd %d: %s", fd, strerror((*__errno_location ())));
            return -1;
        }
    } else if (nread == 0) {
        wheatLog(0, "Peer close file descriptor %d", fd);
        return -1;
    }
    return (int)nread;
}

variable_types: fd int

variable_types: struct slice { unsigned char *data; unsigned long len; } *

variable_types: nread long


syncReadBulkFrom

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

do
result = readBulkFrom(a1, a2);
while ( !(_DWORD)result );
return result;
}

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

do
result = func1(a1, a2);
while ( !(_DWORD)result );
return result;
}

original_code:
int syncReadBulkFrom(int fd, struct slice *slice)
{
   int read = 0;
   do {
       read = readBulkFrom(fd, slice);
   } while(read == 0);
   return read;
}

variable_types: read int

user_defined_types: struct slice { unsigned char *data; unsigned long len; }


writeBulkTo

decompiled_code:
ssize_t __fastcall writeBulkTo(int a1, __int64 a2)
{
ssize_t result; // rax
int v3; // edi
char *v4; // rax
char *v5; // rax

result = write(a1, *(const void **)a2, *(_QWORD *)(a2 + 8));
if ( result == -1 )
{
v3 = *_errno_location();
result = 0LL;
if ( v3 != 11 )
{
if ( v3 == 32 )
{
v5 = strerror(32);
wheatLog(0LL, "Receive RST, peer closed", v5);
}
else
{
v4 = strerror(v3);
wheatLog(2LL, "Error writing to client: %s", v4);
}
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(int a1, __int64 a2)
{
ssize_t result; // rax
int v3; // edi
char *v4; // rax
char *v5; // rax

result = write(a1, *(const void **)a2, *(_QWORD *)(a2 + 8));
if ( result == -1 )
{
v3 = *_errno_location();
result = 0LL;
if ( v3 != 11 )
{
if ( v3 == 32 )
{
v5 = strerror(32);
wheatLog(0LL, "Receive RST, peer closed", v5);
}
else
{
v4 = strerror(v3);
wheatLog(2LL, "Error writing to client: %s", v4);
}
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int writeBulkTo(int fd, struct slice *slice)
{
    ssize_t nwritten;
    nwritten = write(fd, slice->data, slice->len);
    if (nwritten == -1) {
        if ((*__errno_location ()) == 11) {
            nwritten = 0;
        } else if ((*__errno_location ()) == 32) {
            wheatLog(0, "Receive RST, peer closed", strerror((*__errno_location ())));
            return -1;
        } else {
            wheatLog(2,
                "Error writing to client: %s", strerror((*__errno_location ())));
            return -1;
        }
    }
    return (int)nwritten;
}

canonical_original_code:
int writeBulkTo(int fd, struct slice *slice)
{
    long nwritten;
    nwritten = write(fd, slice->data, slice->len);
    if (nwritten == -1) {
        if ((*__errno_location ()) == 11) {
            nwritten = 0;
        } else if ((*__errno_location ()) == 32) {
            wheatLog(0, "Receive RST, peer closed", strerror((*__errno_location ())));
            return -1;
        } else {
            wheatLog(2,
                "Error writing to client: %s", strerror((*__errno_location ())));
            return -1;
        }
    }
    return (int)nwritten;
}

variable_types: nwritten long


sendReplyToClient

decompiled_code:
ssize_t __fastcall sendReplyToClient(__int64 a1, unsigned int a2, __int64 a3)
{
int v4; // eax
unsigned __int64 v5; // r12
unsigned __int64 v6; // rbx
__int64 v7; // r15
int v8; // eax
ssize_t result; // rax
_BYTE v10[72]; // [rsp+0h] [rbp-48h] BYREF

v4 = wstrlen(*(_QWORD *)(a3 + 16));
v5 = v4;
if ( !v4 )
return deleteEvent(a1, a2, 2LL);
v6 = 0LL;
while ( 1 )
{
v7 = *(_QWORD *)(a3 + 16);
v8 = wstrlen(v7);
sliceTo(v10, v7, v8);
result = writeBulkTo(*(_DWORD *)a3, (__int64)v10);
if ( (int)result <= 0 )
break;
v6 += (int)result;
if ( v5 <= v6 )
goto LABEL_5;
}
if ( (int)result == -1LL )
return freeMasterClient(a3);
LABEL_5:
if ( v5 == v6 )
return deleteEvent(a1, a2, 2LL);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func4(__int64 a1, unsigned int a2, __int64 a3)
{
int v4; // eax
unsigned __int64 v5; // r12
unsigned __int64 v6; // rbx
__int64 v7; // r15
int v8; // eax
ssize_t result; // rax
_BYTE v10[72]; // [rsp+0h] [rbp-48h] BYREF

v4 = func0(*(_QWORD *)(a3 + 16));
v5 = v4;
if ( !v4 )
return deleteEvent(a1, a2, 2LL);
v6 = 0LL;
while ( 1 )
{
v7 = *(_QWORD *)(a3 + 16);
v8 = func0(v7);
sliceTo(v10, v7, v8);
result = func3(*(_DWORD *)a3, (__int64)v10);
if ( (int)result <= 0 )
break;
v6 += (int)result;
if ( v5 <= v6 )
goto LABEL_5;
}
if ( (int)result == -1LL )
return freeMasterClient(a3);
LABEL_5:
if ( v5 == v6 )
return deleteEvent(a1, a2, 2LL);
return result;
}

original_code:
static void sendReplyToClient(struct evcenter *center, int fd, void *data, int mask)
{
    struct masterClient *client = data;
    size_t bufpos = 0, totallen = wstrlen(client->response_buf);
    ssize_t nwritten = 0;
    while (bufpos < totallen) {
        struct slice slice;
        sliceTo(&slice, (uint8_t *)client->response_buf,
                wstrlen(client->response_buf));
        nwritten = writeBulkTo(client->fd, &slice);
        if (nwritten <= 0)
            break;
        bufpos += nwritten;
    }
    if (nwritten == -1) {
        freeMasterClient(client);
        return ;
    }
    if (bufpos == totallen) {
        deleteEvent(center, fd, 2);
    }
}

canonical_original_code:
static void sendReplyToClient(struct evcenter *center, int fd, void *data, int mask)
{
    struct masterClient *client = data;
    unsigned long bufpos = 0; unsigned long totallen = wstrlen(client->response_buf);
    long nwritten = 0;
    while (bufpos < totallen) {
        struct slice slice;
        sliceTo(&slice, (unsigned char *)client->response_buf,
                wstrlen(client->response_buf));
        nwritten = writeBulkTo(client->fd, &slice);
        if (nwritten <= 0)
            break;
        bufpos += nwritten;
    }
    if (nwritten == -1) {
        freeMasterClient(client);
        return ;
    }
    if (bufpos == totallen) {
        deleteEvent(center, fd, 2);
    }
}

variable_types: struct evcenter { int nevent; struct event { int mask; void *client_data; void (*read_proc)(struct evcenter *center, int fd, void *client_data, int mask); void (*write_proc)(struct evcenter *center, int fd, void *client_data, int mask); } *events; struct fired_event { int mask; int fd; } *fired_events; void *apidata; } *

variable_types:
data
void *

variable_types: mask int

variable_types: struct masterClient { int fd; char *request_buf; char *response_buf; int argc; char **argv; } *

variable_types:
bufpos
unsigned long

variable_types:
totallen
unsigned long

variable_types: struct slice { unsigned char *data; unsigned long len; }

user_defined_types: struct evcenter { int nevent; struct event *events; struct fired_event *fired_events; void *apidata; }


syncWriteBulkTo

decompiled_code:
ssize_t __fastcall syncWriteBulkTo(int a1, __int64 a2)
{
unsigned int v2; // ebx
ssize_t result; // rax

if ( !*(_QWORD *)(a2 + 8) )
return 0LL;
v2 = 0;
while ( 1 )
{
result = writeBulkTo(a1, a2);
if ( (_DWORD)result == -1 )
break;
v2 += result;
if ( (unsigned __int64)(int)v2 >= *(_QWORD *)(a2 + 8) )
return v2;
}
return result;
}

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

if ( !*(_QWORD *)(a2 + 8) )
return 0LL;
v2 = 0;
while ( 1 )
{
result = func3(a1, a2);
if ( (_DWORD)result == -1 )
break;
v2 += result;
if ( (unsigned __int64)(int)v2 >= *(_QWORD *)(a2 + 8) )
return v2;
}
return result;
}

original_code:
int syncWriteBulkTo(int fd, struct slice *slice)
{
    int totallen, ret;
    totallen = 0;
    while (totallen < slice->len) {
        ret = writeBulkTo(fd, slice);
        if (ret == -1)
            return -1;
        totallen += ret;
    }
    return totallen;
}

canonical_original_code:
int syncWriteBulkTo(int fd, struct slice *slice)
{
    int totallen; int ret;
    totallen = 0;
    while (totallen < slice->len) {
        ret = writeBulkTo(fd, slice);
        if (ret == -1)
            return -1;
        totallen += ret;
    }
    return totallen;
}

variable_types: totallen int

variable_types: ret int


isClientPreparedWrite

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

if ( a1 <= 0 )
result = -1LL;
else
result = -(__int64)((unsigned int)createEvent(a2, (unsigned int)a1, 2LL, sendReplyToClient, a3) == -1);
return result;
}

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

if ( a1 <= 0 )
result = -1LL;
else
result = -(__int64)((unsigned int)createEvent(a2, (unsigned int)a1, 2LL, sendReplyToClient, a3) == -1);
return result;
}

original_code:
ssize_t isClientPreparedWrite(int fd, struct evcenter *center, void *c)
{
    if (fd <= 0 || createEvent(center, fd, 2, sendReplyToClient, c) == -1)
        return -1;
    return 0;
}

canonical_original_code:
long isClientPreparedWrite(int fd, struct evcenter *center, void *c)
{
    if (fd <= 0 || createEvent(center, fd, 2, sendReplyToClient, c) == -1)
        return -1;
    return 0;
}

variable_types:
c
void *

return_type: long

user_defined_types: struct event { int mask; void *client_data; void (*read_proc)(struct evcenter *center, int fd, void *client_data, int mask); void (*write_proc)(struct evcenter *center, int fd, void *client_data, int mask); }

user_defined_types: struct fired_event { int mask; int fd; }


replyMasterClient

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

result = isClientPreparedWrite(*(_DWORD *)a1, Server[10507], a1);
if ( result != -1 )
{
result = wstrCatLen(*(_QWORD *)(a1 + 16), a2, a3);
*(_QWORD *)(a1 + 16) = result;
}
return result;
}

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

result = func6(*(_DWORD *)a1, Server[10507], a1);
if ( result != -1 )
{
result = wstrCatLen(*(_QWORD *)(a1 + 16), a2, a3);
*(_QWORD *)(a1 + 16) = result;
}
return result;
}

original_code:
void replyMasterClient(struct masterClient *c, const char *buf, size_t len)
{
    if (isClientPreparedWrite(c->fd, Server.master_center, c) == -1)
        return ;
    c->response_buf = wstrCatLen(c->response_buf, buf, len);
}

canonical_original_code:
void replyMasterClient(struct masterClient *c, char *buf, unsigned long len)
{
    if (isClientPreparedWrite(c->fd, Server.master_center, c) == -1)
        return ;
    c->response_buf = wstrCatLen(c->response_buf, buf, len);
}

variable_types:
buf
char *

variable_types:
len
unsigned long

user_defined_types: struct masterClient { int fd; char *request_buf; char *response_buf; int argc; char **argv; }


matchInt

decompiled_code:
_BOOL8 __fastcall matchInt(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

original_code:
int matchInt(void *ptr, void *key)
{
    return (*(int *)ptr == *(int *)key);
}

variable_types:
ptr
void *

variable_types:
key
void *


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

result = WorkerProcess;
*(_QWORD *)(WorkerProcess + 64LL) = 0LL;
return result;
}

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

result = WorkerProcess;
*(_QWORD *)(WorkerProcess + 64LL) = 0LL;
return result;
}

original_code:
void handleWorkerUsr1(int sig)
{
    WorkerProcess->refresh_time = 0;
    return ;
}

variable_types: sig int


handleWorkerQuit

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

result = WorkerProcess;
*(_DWORD *)(WorkerProcess + 24LL) = 0;
return result;
}

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

result = WorkerProcess;
*(_DWORD *)(WorkerProcess + 24LL) = 0;
return result;
}

original_code:
void handleWorkerQuit(int sig)
{
    WorkerProcess->alive = 0;
}


freeInt

decompiled_code:
__int64 freeInt()
{
return wfree();
}

canonical_decompiled_code:
__int64 func3()
{
return wfree();
}

original_code:
void freeInt(void *ptr)
{
    wfree(ptr);
}

canonical_original_code:
void freeInt(void *ptr)
{
    wfree(ptr);
}


createIntList

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

result = (_QWORD *)createList();
result[2] = dupInt;
result[4] = freeInt;
result[3] = matchInt;
return result;
}

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

result = (_QWORD *)createList();
result[2] = dupInt;
result[4] = freeInt;
result[3] = matchInt;
return result;
}

original_code:
static struct list *createIntList()
{
    struct list *l = createList();
    ((l)->dup = (dupInt));
    ((l)->free = (freeInt));
    ((l)->match = (matchInt));
    return l;
}

variable_types: struct list { struct listNode { struct listNode *next; struct listNode *prev; void *value; } *first; void *(*dup)(void *ptr); int (*match)(void *ptr, void *key); void (*free)(void *ptr); unsigned long len; } *

user_defined_types: struct list { struct listNode *first; void *(*dup)(void *ptr); int (*match)(void *ptr, void *key); void (*free)(void *ptr); unsigned long len; }


signalProc

decompiled_code:
__int64 __fastcall signalProc(int a1)
{
__int64 v1; // rdi
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a1;
v1 = Server[10517];
if ( *(_QWORD *)(v1 + 40) <= 4uLL )
{
if ( v3[0] != 17 )
appendToListTail(v1, v3);
result = wakeUp();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
__int64 v1; // rdi
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a1;
v1 = Server[10517];
if ( *(_QWORD *)(v1 + 40) <= 4uLL )
{
if ( v3[0] != 17 )
appendToListTail(v1, v3);
result = wakeUp();
}
return result;
}

original_code:
void signalProc(int signal)
{
    if (((Server.signal_queue)->len) < 5) {
        if (signal != 17)
            appendToListTail(Server.signal_queue, &signal);
        wakeUp();
    }
}

variable_types: signal int


handleWorkerAbort

decompiled_code:
__int64 handleWorkerAbort()
{
*(_DWORD *)(WorkerProcess + 24LL) = 0;
return halt(1LL);
}

canonical_decompiled_code:
__int64 func6()
{
*(_DWORD *)(WorkerProcess + 24LL) = 0;
return halt(1LL);
}

original_code:
void handleWorkerAbort(int sig)
{
    WorkerProcess->alive = 0;
    halt(1);
}


handleSegv

decompiled_code:
int handleSegv()
{
wheat_stacktrace(1LL);
wheatLogRaw(2LL, "Signal SEGV received, core dump");
return raise(11);
}

canonical_decompiled_code:
int func7()
{
wheat_stacktrace(1LL);
wheatLogRaw(2LL, "Signal SEGV received, core dump");
return raise(11);
}

original_code:
void handleSegv()
{
    wheat_stacktrace(1);
    wheatLogRaw(2, "Signal SEGV received, core dump");
    raise(11);
}


initWorkerSignals

decompiled_code:
int initWorkerSignals()
{
unsigned int *v0; // rbp
int result; // eax
unsigned int v2; // ebx
int *v3; // rax
char *v4; // rax
struct sigaction v5; // [rsp+0h] [rbp-158h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-B8h] BYREF

v0 = (unsigned int *)&signals;
do
{
v6.sa_flags = 0;
v2 = *v0;
if ( *v0 == 3 )
{
v6.sa_handler = (__sighandler_t)handleWorkerQuit;
}
else
{
switch ( v2 )
{
case 0xFu:
case 2u:
v6.sa_handler = (__sighandler_t)handleWorkerAbort;
break;
case 0xAu:
v6.sa_handler = (__sighandler_t)handleWorkerUsr1;
break;
case 0xBu:
v6.sa_flags = 0x80000000;
v6.sa_handler = (__sighandler_t)handleSegv;
break;
default:
v6.sa_handler = 0LL;
break;
}
}
sigemptyset(&v6.sa_mask);
result = sigaction(v2, &v6, &v5);
if ( result )
{
v3 = _errno_location();
v4 = strerror(*v3);
result = wheatLog(2LL, "sigaction error on %d : %s", v2, v4);
}
++v0;
}
while ( v0 != (unsigned int *)1644 );
return result;
}

canonical_decompiled_code:
int func8()
{
unsigned int *v0; // rbp
int result; // eax
unsigned int v2; // ebx
int *v3; // rax
char *v4; // rax
struct sigaction v5; // [rsp+0h] [rbp-158h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-B8h] BYREF

v0 = (unsigned int *)&signals;
do
{
v6.sa_flags = 0;
v2 = *v0;
if ( *v0 == 3 )
{
v6.sa_handler = (__sighandler_t)handleWorkerQuit;
}
else
{
switch ( v2 )
{
case 0xFu:
case 2u:
v6.sa_handler = (__sighandler_t)handleWorkerAbort;
break;
case 0xAu:
v6.sa_handler = (__sighandler_t)handleWorkerUsr1;
break;
case 0xBu:
v6.sa_flags = 0x80000000;
v6.sa_handler = (__sighandler_t)handleSegv;
break;
default:
v6.sa_handler = 0LL;
break;
}
}
sigemptyset(&v6.sa_mask);
result = sigaction(v2, &v6, &v5);
if ( result )
{
v3 = _errno_location();
v4 = strerror(*v3);
result = wheatLog(2LL, "sigaction error on %d : %s", v2, v4);
}
++v0;
}
while ( v0 != (unsigned int *)1644 );
return result;
}

original_code:
void initWorkerSignals()
{
    struct sigaction act, oact;
    int i;
    for (i = 0; i < 11; i++) {
        act.sa_flags = 0;
        if (signals[i] == 3)
            act.__sigaction_handler.sa_handler = handleWorkerQuit;
        else if (signals[i] == 15 || signals[i] == 2)
            act.__sigaction_handler.sa_handler = handleWorkerAbort;
        else if (signals[i] == 10)
            act.__sigaction_handler.sa_handler = handleWorkerUsr1;
        else if (signals[i] == 11) {
            act.sa_flags = (int)0x80000000;
            act.__sigaction_handler.sa_handler = handleSegv;
        }
        else
            act.__sigaction_handler.sa_handler = ((__sighandler_t) 0);
        sigemptyset(&act.sa_mask);
        if (sigaction(signals[i], &act, &oact) != 0) {
            wheatLog(2, "sigaction error on %d : %s", signals[i], strerror((*__errno_location ())));
        }
    }
}

canonical_original_code:
void initWorkerSignals()
{
    struct sigaction act; struct sigaction oact;
    int i;
    for (i = 0; i < 11; i++) {
        act.sa_flags = 0;
        if (signals[i] == 3)
            act.__sigaction_handler.sa_handler = handleWorkerQuit;
        else if (signals[i] == 15 || signals[i] == 2)
            act.__sigaction_handler.sa_handler = handleWorkerAbort;
        else if (signals[i] == 10)
            act.__sigaction_handler.sa_handler = handleWorkerUsr1;
        else if (signals[i] == 11) {
            act.sa_flags = (int)0x80000000;
            act.__sigaction_handler.sa_handler = handleSegv;
        }
        else
            act.__sigaction_handler.sa_handler = ((void (*)(int)) 0);
        sigemptyset(&act.sa_mask);
        if (sigaction(signals[i], &act, &oact) != 0) {
            wheatLog(2, "sigaction error on %d : %s", signals[i], strerror((*__errno_location ())));
        }
    }
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: i int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


initMasterSignals

decompiled_code:
int initMasterSignals()
{
int *v0; // rbx
unsigned int v1; // ebp
int *v2; // rax
char *v3; // rax
int result; // eax
int *v5; // rax
char *v6; // rax
struct sigaction v7; // [rsp+0h] [rbp-158h] BYREF
struct sigaction v8; // [rsp+A0h] [rbp-B8h] BYREF

Server[10517] = createIntList();
v8.sa_handler = (__sighandler_t)signalProc;
sigemptyset(&v8.sa_mask);
v8.sa_flags = 0;
v0 = (int *)&signals;
do
{
v1 = *v0;
if ( sigaction(*v0, &v8, &v7) )
{
v2 = _errno_location();
v3 = strerror(*v2);
wheatLog(4LL, "sigaction error on %d : %s", v1, v3);
}
++v0;
}
while ( v0 != (int *)&unk_668 );
v8.sa_handler = (__sighandler_t)handleSegv;
sigemptyset(&v8.sa_mask);
v8.sa_flags = 0x80000000;
result = sigaction(11, &v8, &v7);
if ( result )
{
v5 = _errno_location();
v6 = strerror(*v5);
result = wheatLog(4LL, "sigaction error on %d : %s", 11LL, v6);
}
return result;
}

canonical_decompiled_code:
int func9()
{
int *v0; // rbx
unsigned int v1; // ebp
int *v2; // rax
char *v3; // rax
int result; // eax
int *v5; // rax
char *v6; // rax
struct sigaction v7; // [rsp+0h] [rbp-158h] BYREF
struct sigaction v8; // [rsp+A0h] [rbp-B8h] BYREF

Server[10517] = func4();
v8.sa_handler = (__sighandler_t)signalProc;
sigemptyset(&v8.sa_mask);
v8.sa_flags = 0;
v0 = (int *)&signals;
do
{
v1 = *v0;
if ( sigaction(*v0, &v8, &v7) )
{
v2 = _errno_location();
v3 = strerror(*v2);
wheatLog(4LL, "sigaction error on %d : %s", v1, v3);
}
++v0;
}
while ( v0 != (int *)&unk_668 );
v8.sa_handler = (__sighandler_t)handleSegv;
sigemptyset(&v8.sa_mask);
v8.sa_flags = 0x80000000;
result = sigaction(11, &v8, &v7);
if ( result )
{
v5 = _errno_location();
v6 = strerror(*v5);
result = wheatLog(4LL, "sigaction error on %d : %s", 11LL, v6);
}
return result;
}

original_code:
void initMasterSignals()
{
    Server.signal_queue = createIntList();
    struct sigaction act, oact;
    act.__sigaction_handler.sa_handler = signalProc;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    int i;
    for (i = 0; i < 10; i++) {
        if (sigaction(signals[i], &act, &oact) != 0) {
            wheatLog(4, "sigaction error on %d : %s", signals[i], strerror((*__errno_location ())));
        }
    }
    act.__sigaction_handler.sa_handler = handleSegv;
    sigemptyset(&act.sa_mask);
    act.sa_flags = (int)0x80000000;
    if (sigaction(signals[10], &act, &oact) != 0) {
            wheatLog(4, "sigaction error on %d : %s", signals[i], strerror((*__errno_location ())));
    }
}

canonical_original_code:
void initMasterSignals()
{
    Server.signal_queue = createIntList();
    struct sigaction act; struct sigaction oact;
    act.__sigaction_handler.sa_handler = signalProc;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    int i;
    for (i = 0; i < 10; i++) {
        if (sigaction(signals[i], &act, &oact) != 0) {
            wheatLog(4, "sigaction error on %d : %s", signals[i], strerror((*__errno_location ())));
        }
    }
    act.__sigaction_handler.sa_handler = handleSegv;
    sigemptyset(&act.sa_mask);
    act.sa_flags = (int)0x80000000;
    if (sigaction(signals[10], &act, &oact) != 0) {
            wheatLog(4, "sigaction error on %d : %s", signals[i], strerror((*__errno_location ())));
    }
}

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


handleChld

decompiled_code:
__int64 handleChld()
{
return wakeUp();
}

canonical_decompiled_code:
__int64 func10()
{
return wakeUp();
}

original_code:
void handleChld()
{
    wakeUp();
}

canonical_original_code:
void handleChld()
{
    wakeUp();
}


handleHup

decompiled_code:
__int64 handleHup()
{
wheatLog(2LL, "Hang up: %s", (const char *)(unsigned int)((_DWORD)Server + 1112));
return reload();
}

canonical_decompiled_code:
__int64 func11()
{
wheatLog(2LL, "Hang up: %s", (const char *)(unsigned int)((_DWORD)Server + 1112));
return reload();
}

original_code:
void handleHup()
{
    wheatLog(2, "Hang up: %s", Server.master_name);
    reload();
}


handleQuit

decompiled_code:
__int64 handleQuit()
{
wheatLog(4LL, "Signal sigquit");
return halt(1LL);
}

canonical_decompiled_code:
__int64 func12()
{
wheatLog(4LL, "Signal sigquit");
return halt(1LL);
}

original_code:
void handleQuit()
{
    wheatLog(4, "Signal sigquit");
    halt(1);
}


handleInt

decompiled_code:
__int64 handleInt()
{
wheatLog(4LL, "Signal int");
return halt(0LL);
}

canonical_decompiled_code:
__int64 func13()
{
wheatLog(4LL, "Signal int");
return halt(0LL);
}

original_code:
void handleInt()
{
    wheatLog(4, "Signal int");
    halt(0);
}


handleTerm

decompiled_code:
__int64 handleTerm()
{
wheatLog(4LL, "Signal term");
return halt(0LL);
}

canonical_decompiled_code:
__int64 func14()
{
wheatLog(4LL, "Signal term");
return halt(0LL);
}

original_code:
void handleTerm()
{
    wheatLog(4, "Signal term");
    halt(0);
}


handleTtin

decompiled_code:
__int64 handleTtin()
{
++LODWORD(Server[2]);
return adjustWorkerNumber();
}

canonical_decompiled_code:
__int64 func15()
{
++LODWORD(Server[2]);
return adjustWorkerNumber();
}

original_code:
void handleTtin()
{
    Server.worker_number++;
    adjustWorkerNumber();
}


handleTtou

decompiled_code:
__int64 handleTtou()
{
--LODWORD(Server[2]);
return adjustWorkerNumber();
}

canonical_decompiled_code:
__int64 func16()
{
--LODWORD(Server[2]);
return adjustWorkerNumber();
}

original_code:
void handleTtou()
{
    Server.worker_number--;
    adjustWorkerNumber();
}


decompiled_code:
__int64 handleUsr1()
{
wheatLog(2LL, "Signal usr1: %s", (const char *)(unsigned int)((_DWORD)Server + 1112));
killAllWorkers(10LL);
return logStat();
}

canonical_decompiled_code:
__int64 func17()
{
wheatLog(2LL, "Signal usr1: %s", (const char *)(unsigned int)((_DWORD)Server + 1112));
killAllWorkers(10LL);
return logStat();
}

original_code:
void handleUsr1()
{
    wheatLog(2, "Signal usr1: %s", Server.master_name);
    killAllWorkers(10);
    logStat();
}


decompiled_code:
__int64 handleUsr2()
{
wheatLog(2LL, "Signal usr2: %s reexec", (const char *)(unsigned int)((_DWORD)Server + 1112));
return reexec();
}

canonical_decompiled_code:
__int64 func18()
{
wheatLog(2LL, "Signal usr2: %s reexec", (const char *)(unsigned int)((_DWORD)Server + 1112));
return reexec();
}

original_code:
void handleUsr2()
{
    wheatLog(2, "Signal usr2: %s reexec", Server.master_name);
    reexec();
}


handleWinch

decompiled_code:
__int64 handleWinch()
{
__pid_t v0; // ebx

if ( getppid() != 1 )
{
v0 = getpgrp();
if ( v0 == getpid() )
return wheatLog(2LL, "Signal winch ignored, not daemonize");
}
wheatLog(2LL, "Signal winch: graceful stop of workers");
LODWORD(Server[2]) = 0;
return killAllWorkers(3LL);
}

canonical_decompiled_code:
__int64 func19()
{
__pid_t v0; // ebx

if ( getppid() != 1 )
{
v0 = getpgrp();
if ( v0 == getpid() )
return wheatLog(2LL, "Signal winch ignored, not daemonize");
}
wheatLog(2LL, "Signal winch: graceful stop of workers");
LODWORD(Server[2]) = 0;
return killAllWorkers(3LL);
}

original_code:
void handleWinch()
{
    if (getppid() == 1 || getpgrp() != getpid()) {
        wheatLog(2, "Signal winch: graceful stop of workers");
        Server.worker_number = 0;
        killAllWorkers(3);
    } else {
        wheatLog(2, "Signal winch ignored, not daemonize");
    }
}


signalGenericHandle

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

switch ( a1 )
{
case 17:
return handleChld();
case 1:
return handleHup();
case 3:
return handleQuit();
case 2:
return handleInt();
case 15:
return handleTerm();
case 21:
return handleTtin();
case 22:
return handleTtou();
case 10:
return handleUsr1();
case 12:
return handleUsr2();
case 28:
result = handleWinch();
break;
}
return result;
}

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

switch ( a1 )
{
case 17:
return func10();
case 1:
return func11();
case 3:
return func12();
case 2:
return func13();
case 15:
return func14();
case 21:
return func15();
case 22:
return func16();
case 10:
return func17();
case 12:
return func18();
case 28:
result = func19();
break;
}
return result;
}

original_code:
void signalGenericHandle(int sig)
{
    if (sig == 17)
        handleChld();
    else if (sig == 1)
        handleHup();
    else if (sig == 3)
        handleQuit();
    else if (sig == 2)
        handleInt();
    else if (sig == 15)
        handleTerm();
    else if (sig == 21)
        handleTtin();
    else if (sig == 22)
        handleTtou();
    else if (sig == 10)
        handleUsr1();
    else if (sig == 12)
        handleUsr2();
    else if (sig == 28)
        handleWinch();
}


wstrlen

decompiled_code:
__int64 __fastcall wstrlen(__int64 a1)
{
return *(unsigned int *)(a1 - 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(unsigned int *)(a1 - 8);
}

original_code:
static inline int wstrlen(const wstr s)
{
    struct wstrhd *hd = (struct wstrhd *)(s - sizeof(struct wstrhd));
    return hd->len;
}

variable_types:
s
char *

variable_types: struct wstrhd { int len; int free; char buf[]; } *


wstrupdatelen

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

result = (unsigned int)(*(_DWORD *)(a1 - 8) - a2);
*(_DWORD *)(a1 - 4) += result;
*(_DWORD *)(a1 - 8) = a2;
*(_BYTE *)(a1 + a2) = 0;
return result;
}

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

result = (unsigned int)(*(_DWORD *)(a1 - 8) - a2);
*(_DWORD *)(a1 - 4) += result;
*(_DWORD *)(a1 - 8) = a2;
*(_BYTE *)(a1 + a2) = 0;
return result;
}

original_code:
static inline void wstrupdatelen(wstr s, int len)
{
    struct wstrhd *hd = (struct wstrhd *)(s - sizeof(struct wstrhd));
    hd->free += (hd->len - len);
    hd->len = len;
    hd->buf[len] = '\0';
}

canonical_original_code:
static inline void wstrupdatelen(char *s, int len)
{
    struct wstrhd *hd = (struct wstrhd *)(s - sizeof(struct wstrhd));
    hd->free += (hd->len - len);
    hd->len = len;
    hd->buf[len] = '\0';
}

variable_types: len int

user_defined_types: struct wstrhd { int len; int free; char buf[]; }


wstrEmpty

decompiled_code:
int *wstrEmpty()
{
return wstrNewLen(0LL, 0);
}

canonical_decompiled_code:
int *func4()
{
return func2(0LL, 0);
}

original_code:
wstr wstrEmpty()
{
    return wstrNewLen(((void *)0), 0);
}

canonical_original_code:
char *wstrEmpty()
{
    return wstrNewLen(((void *)0), 0);
}

return_type: char *


wstrClear

decompiled_code:
__int64 __fastcall wstrClear(__int64 a1)
{
return wstrupdatelen(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return func1(a1, 0);
}

original_code:
void wstrClear(wstr s)
{
    wstrupdatelen(s, 0);
}

canonical_original_code:
void wstrClear(char *s)
{
    wstrupdatelen(s, 0);
}


wstrMakeRoom

original_code:
wstr wstrMakeRoom(wstr s, size_t add_size)
{
    struct wstrhd *sh = (void *)(s - sizeof(struct wstrhd));
    if (sh->free >= add_size)
        return s;
    int old_len = wstrlen(s);
    int new_len = (old_len + (int)add_size) * 2;
    struct wstrhd *new_sh = wrealloc(sh, sizeof(struct wstrhd)+new_len+1);
    if (new_sh == ((void *)0)) {
        return ((void *)0);
    }
    new_sh->free = new_len - old_len;
    return new_sh->buf;
}

canonical_original_code:
char *wstrMakeRoom(char *s, unsigned long add_size)
{
    struct wstrhd *sh = (void *)(s - sizeof(struct wstrhd));
    if (sh->free >= add_size)
        return s;
    int old_len = wstrlen(s);
    int new_len = (old_len + (int)add_size) * 2;
    struct wstrhd *new_sh = wrealloc(sh, sizeof(struct wstrhd)+new_len+1);
    if (new_sh == ((void *)0)) {
        return ((void *)0);
    }
    new_sh->free = new_len - old_len;
    return new_sh->buf;
}


wstrFree

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

if ( a1 )
result = wfree(a1 - 8);
return result;
}

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

if ( a1 )
result = wfree(a1 - 8);
return result;
}

original_code:
void wstrFree(wstr s)
{
    if (s == ((void *)0)) {
        return ;
    }
    wfree(s - sizeof(struct wstrhd));
}

canonical_original_code:
void wstrFree(char *s)
{
    if (s == ((void *)0)) {
        return ;
    }
    wfree(s - sizeof(struct wstrhd));
}


wstrFreeSplit

decompiled_code:
__int64 __fastcall wstrFreeSplit(__int64 *a1, int a2)
{
__int64 *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
wstrFree(*v2++);
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return wfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, int a2)
{
__int64 *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
func7(*v2++);
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return wfree(a1);
}

original_code:
void wstrFreeSplit(wstr *slots, int count)
{
    int i;
    for (i = 0; i < count; i++) {
        wstrFree(slots[i]);
    }
    wfree(slots);
}

canonical_original_code:
void wstrFreeSplit(char **slots, int count)
{
    int i;
    for (i = 0; i < count; i++) {
        wstrFree(slots[i]);
    }
    wfree(slots);
}

variable_types:
slots
char **

variable_types: count int


wstrCmpNocaseChars

decompiled_code:
int __fastcall wstrCmpNocaseChars(char *s1, char *s2, size_t n)
{
int v4; // ebx
int result; // eax
int v6; // ebx

v4 = wstrlen((__int64)s1);
result = strncasecmp(s1, s2, n);
v6 = v4 - n;
if ( !result )
result = v6;
return result;
}

canonical_decompiled_code:
int __fastcall func10(char *s1, char *s2, size_t n)
{
int v4; // ebx
int result; // eax
int v6; // ebx

v4 = func0((__int64)s1);
result = strncasecmp(s1, s2, n);
v6 = v4 - n;
if ( !result )
result = v6;
return result;
}

original_code:
int wstrCmpNocaseChars(const wstr s1, const char *s2, size_t l2)
{
    int l1, cmp;
    l1 = wstrlen(s1);
    cmp = strncasecmp(s1, s2, l2);
    if (cmp == 0)
        return (int)(l1 - l2);
    return cmp;
}

canonical_original_code:
int wstrCmpNocaseChars(char *s1, char *s2, unsigned long l2)
{
    int l1; int cmp;
    l1 = wstrlen(s1);
    cmp = strncasecmp(s1, s2, l2);
    if (cmp == 0)
        return (int)(l1 - l2);
    return cmp;
}

variable_types: cmp int


wstrCmpChars

decompiled_code:
int __fastcall wstrCmpChars(void *s1, void *s2, unsigned __int64 a3)
{
int v4; // ebx
int v5; // edx
int result; // eax
int v7; // ebx

v4 = wstrlen((__int64)s1);
v5 = v4;
if ( v4 > a3 )
v5 = a3;
result = memcmp(s1, s2, v5);
v7 = v4 - a3;
if ( !result )
result = v7;
return result;
}

canonical_decompiled_code:
int __fastcall func11(void *s1, void *s2, unsigned __int64 a3)
{
int v4; // ebx
int v5; // edx
int result; // eax
int v7; // ebx

v4 = func0((__int64)s1);
v5 = v4;
if ( v4 > a3 )
v5 = a3;
result = memcmp(s1, s2, v5);
v7 = v4 - a3;
if ( !result )
result = v7;
return result;
}

original_code:
int wstrCmpChars(const wstr s1, const char *s2, size_t l2)
{
    int minlen, cmp;
    size_t l1 = wstrlen(s1);
    minlen = l1 < l2 ? l1: l2;
    cmp = memcmp(s1, s2, minlen);
    if (cmp == 0)
        return (int)(l1 - l2);
    return cmp;
}

canonical_original_code:
int wstrCmpChars(char *s1, char *s2, unsigned long l2)
{
    int minlen; int cmp;
    unsigned long l1 = wstrlen(s1);
    minlen = l1 < l2 ? l1: l2;
    cmp = memcmp(s1, s2, minlen);
    if (cmp == 0)
        return (int)(l1 - l2);
    return cmp;
}

variable_types: minlen int


wstrCmp

decompiled_code:
int __fastcall wstrCmp(void *s1, void *s2)
{
int v2; // eax

v2 = wstrlen((__int64)s2);
return wstrCmpChars(s1, s2, v2);
}

canonical_decompiled_code:
int __fastcall func12(void *s1, void *s2)
{
int v2; // eax

v2 = func0((__int64)s2);
return func11(s1, s2, v2);
}

original_code:
int wstrCmp(const wstr s1, const wstr s2)
{
    return wstrCmpChars(s1, s2, wstrlen(s2));
}

canonical_original_code:
int wstrCmp(char *s1, char *s2)
{
    return wstrCmpChars(s1, s2, wstrlen(s2));
}


wstrCatLen

decompiled_code:
__int64 __fastcall wstrCatLen(__int64 a1, const void *a2, unsigned __int64 a3)
{
int v4; // er12
__int64 v5; // rax
__int64 v6; // rbx

if ( !a1 || !a2 )
return 0LL;
v4 = wstrlen(a1);
v5 = wstrMakeRoom(a1, a3);
v6 = v5;
if ( v5 )
{
memcpy((void *)(v5 + v4), a2, a3);
wstrupdatelen(v6, v4 + a3);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, const void *a2, unsigned __int64 a3)
{
int v4; // er12
__int64 v5; // rax
__int64 v6; // rbx

if ( !a1 || !a2 )
return 0LL;
v4 = func0(a1);
v5 = func6(a1, a3);
v6 = v5;
if ( v5 )
{
memcpy((void *)(v5 + v4), a2, a3);
func1(v6, v4 + a3);
}
return v6;
}

original_code:
wstr wstrCatLen(wstr s, const char *t, size_t tlen)
{
    if (s == ((void *)0) || t == ((void *)0))
        return ((void *)0);
    int slen;
    slen = wstrlen(s);
    wstr new_s;
    new_s = wstrMakeRoom(s, tlen);
    if (new_s == ((void *)0))
        return ((void *)0);
    memcpy(new_s+slen, t, tlen);
    wstrupdatelen(new_s, (int)tlen+slen);
    return new_s;
}

canonical_original_code:
char *wstrCatLen(char *s, char *t, unsigned long tlen)
{
    if (s == ((void *)0) || t == ((void *)0))
        return ((void *)0);
    int slen;
    slen = wstrlen(s);
    char *new_s;
    new_s = wstrMakeRoom(s, tlen);
    if (new_s == ((void *)0))
        return ((void *)0);
    memcpy(new_s+slen, t, tlen);
    wstrupdatelen(new_s, (int)tlen+slen);
    return new_s;
}

variable_types:
t
char *

variable_types:
tlen
unsigned long

variable_types: slen int


wstrCat

decompiled_code:
__int64 __fastcall wstrCat(__int64 a1, const char *a2)
{
unsigned __int64 v2; // rax

v2 = strlen(a2);
return wstrCatLen(a1, a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, const char *a2)
{
unsigned __int64 v2; // rax

v2 = strlen(a2);
return func13(a1, a2, v2);
}

original_code:
wstr wstrCat(wstr s, const char *t)
{
    return wstrCatLen(s, t, strlen(t));
}

canonical_original_code:
char *wstrCat(char *s, char *t)
{
    return wstrCatLen(s, t, strlen(t));
}


wstrStartWithChars

decompiled_code:
_BOOL8 __fastcall wstrStartWithChars(void *s1, void *s2, size_t a3)
{
size_t v4; // rdx
_BOOL8 result; // rax

v4 = (int)wstrlen((__int64)s1);
result = 0LL;
if ( v4 >= a3 )
result = memcmp(s1, s2, v4) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(void *s1, void *s2, size_t a3)
{
size_t v4; // rdx
_BOOL8 result; // rax

v4 = (int)func0((__int64)s1);
result = 0LL;
if ( v4 >= a3 )
result = memcmp(s1, s2, v4) == 0;
return result;
}

original_code:
int wstrStartWithChars(const wstr s, const char *s2, size_t s2_len)
{
    int s_len = wstrlen(s);
    if (s_len < s2_len)
        return 0;
    int r = memcmp(s, s2, s_len);
    if (r == 0) {
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
int wstrStartWithChars(char *s, char *s2, unsigned long s2_len)
{
    int s_len = wstrlen(s);
    if (s_len < s2_len)
        return 0;
    int r = memcmp(s, s2, s_len);
    if (r == 0) {
        return 1;
    } else {
        return 0;
    }
}

variable_types: r int


wstrStartWith

decompiled_code:
_BOOL8 __fastcall wstrStartWith(void *s1, void *s2)
{
int v2; // eax

v2 = wstrlen((__int64)s2);
return wstrStartWithChars(s1, s2, v2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(void *s1, void *s2)
{
int v2; // eax

v2 = func0((__int64)s2);
return func15(s1, s2, v2);
}

original_code:
int wstrStartWith(const wstr s, const wstr s2)
{
    return wstrStartWithChars(s, s2, wstrlen(s2));
}

canonical_original_code:
int wstrStartWith(char *s, char *s2)
{
    return wstrStartWithChars(s, s2, wstrlen(s2));
}


wstrRange

decompiled_code:
void *__fastcall wstrRange(void *dest, int a2, int a3)
{
int v3; // ebx
int v5; // eax
int v6; // ebp

if ( dest )
{
v3 = a2;
v5 = wstrlen((__int64)dest);
if ( a2 < 0 )
v3 = a2 + v5;
if ( a3 < 0 )
{
a3 += v5;
}
else if ( !a3 )
{
a3 = v5;
}
if ( v3 > v5 )
v3 = v5;
if ( a3 > v5 )
a3 = v5;
v6 = a3 - v3;
if ( v6 < 0 )
v6 = 0;
memmove(dest, (char *)dest + v3, v6);
wstrupdatelen((__int64)dest, v6);
}
return dest;
}

canonical_decompiled_code:
void *__fastcall func17(void *dest, int a2, int a3)
{
int v3; // ebx
int v5; // eax
int v6; // ebp

if ( dest )
{
v3 = a2;
v5 = func0((__int64)dest);
if ( a2 < 0 )
v3 = a2 + v5;
if ( a3 < 0 )
{
a3 += v5;
}
else if ( !a3 )
{
a3 = v5;
}
if ( v3 > v5 )
v3 = v5;
if ( a3 > v5 )
a3 = v5;
v6 = a3 - v3;
if ( v6 < 0 )
v6 = 0;
memmove(dest, (char *)dest + v3, v6);
func1((__int64)dest, v6);
}
return dest;
}

original_code:
wstr wstrRange(wstr str, int left, int right)
{
    if (str == ((void *)0))
        return ((void *)0);
    int len = wstrlen(str);
    if (left < 0) {
        left = len + left;
    }
    if (right < 0) {
        right = len + right;
    }
    else if (right == 0)
        right = len;
    if (left > len)
        left = len;
    if (right > len)
        right = len;
    int new_len = (right - left);
    if (new_len < 0)
        new_len = 0;
    memmove(str, str+left, new_len);
    wstrupdatelen(str, new_len);
    return str;
}

canonical_original_code:
char *wstrRange(char *str, int left, int right)
{
    if (str == ((void *)0))
        return ((void *)0);
    int len = wstrlen(str);
    if (left < 0) {
        left = len + left;
    }
    if (right < 0) {
        right = len + right;
    }
    else if (right == 0)
        right = len;
    if (left > len)
        left = len;
    if (right > len)
        right = len;
    int new_len = (right - left);
    if (new_len < 0)
        new_len = 0;
    memmove(str, str+left, new_len);
    wstrupdatelen(str, new_len);
    return str;
}

variable_types:
str
char *

variable_types: left int

variable_types: right int


wstrStrip

decompiled_code:
void *__fastcall wstrStrip(void *dest, char *s)
{
int v2; // eax
int v3; // ebp
int v4; // er15
char *v5; // r13
int i; // ebx
char *v7; // r13
int v8; // ebp

v2 = wstrlen((__int64)dest);
v3 = v2 - 1;
if ( v2 <= 0 )
{
i = 0;
}
else
{
v4 = v2;
v5 = (char *)dest;
for ( i = 0; i != v4; ++i )
{
if ( !strchr(s, *v5) )
break;
++v5;
}
}
if ( v3 > i )
{
v7 = (char *)dest + v3;
while ( strchr(s, *v7) )
{
--v3;
--v7;
if ( v3 == i )
{
v3 = i;
break;
}
}
}
v8 = v3 - i + 1;
memmove(dest, (char *)dest + i, v8);
wstrupdatelen((__int64)dest, v8);
return dest;
}

canonical_decompiled_code:
void *__fastcall func18(void *dest, char *s)
{
int v2; // eax
int v3; // ebp
int v4; // er15
char *v5; // r13
int i; // ebx
char *v7; // r13
int v8; // ebp

v2 = func0((__int64)dest);
v3 = v2 - 1;
if ( v2 <= 0 )
{
i = 0;
}
else
{
v4 = v2;
v5 = (char *)dest;
for ( i = 0; i != v4; ++i )
{
if ( !strchr(s, *v5) )
break;
++v5;
}
}
if ( v3 > i )
{
v7 = (char *)dest + v3;
while ( strchr(s, *v7) )
{
--v3;
--v7;
if ( v3 == i )
{
v3 = i;
break;
}
}
}
v8 = v3 - i + 1;
memmove(dest, (char *)dest + i, v8);
func1((__int64)dest, v8);
return dest;
}

original_code:
wstr wstrStrip(wstr str, const char *chars)
{
    int left, right, len = wstrlen(str);
    left = 0;
    right = len - 1;
    while(left < len && strchr(chars, str[left])) left++;
    while(right > left && strchr(chars, str[right])) right--;
    memmove(str, str+left, right-left+1);
    wstrupdatelen(str, right-left+1);
    return str;
}

canonical_original_code:
char *wstrStrip(char *str, char *chars)
{
    int left; int right; int len = wstrlen(str);
    left = 0;
    right = len - 1;
    while(left < len && strchr(chars, str[left])) left++;
    while(right > left && strchr(chars, str[right])) right--;
    memmove(str, str+left, right-left+1);
    wstrupdatelen(str, right-left+1);
    return str;
}

variable_types:
chars
char *


wstrIndex

decompiled_code:
__int64 __fastcall wstrIndex(__int64 a1, char a2)
{
unsigned int v3; // eax
unsigned int v4; // esi
__int64 v5; // rcx
__int64 v6; // rax
unsigned int v7; // edx

v3 = wstrlen(a1);
if ( !v3 )
return (unsigned int)-1;
v4 = v3;
v5 = v3;
v6 = 0LL;
while ( 1 )
{
v7 = v6;
if ( *(_BYTE *)(a1 + v6) == a2 )
break;
if ( ++v6 == v5 )
return (unsigned int)-1;
}
if ( v4 == (_DWORD)v6 )
v7 = -1;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, char a2)
{
unsigned int v3; // eax
unsigned int v4; // esi
__int64 v5; // rcx
__int64 v6; // rax
unsigned int v7; // edx

v3 = func0(a1);
if ( !v3 )
return (unsigned int)-1;
v4 = v3;
v5 = v3;
v6 = 0LL;
while ( 1 )
{
v7 = v6;
if ( *(_BYTE *)(a1 + v6) == a2 )
break;
if ( ++v6 == v5 )
return (unsigned int)-1;
}
if ( v4 == (_DWORD)v6 )
v7 = -1;
return v7;
}

original_code:
int wstrIndex(wstr s, const char t)
{
    int i = 0, len = wstrlen(s);
    while (i != len && s[i] != t)
        ++i;
    return (i != len) ? i : -1;
}

canonical_original_code:
int wstrIndex(char *s, char t)
{
    int i = 0; int len = wstrlen(s);
    while (i != len && s[i] != t)
        ++i;
    return (i != len) ? i : -1;
}

variable_types: t char


wstrRemoveFreeSpace

decompiled_code:
__int64 __fastcall wstrRemoveFreeSpace(__int64 a1)
{
__int64 v1; // rax

v1 = wrealloc(a1 - 8, *(int *)(a1 - 8) + 9LL);
*(_DWORD *)(v1 + 4) = 0;
return v1 + 8;
}

original_code:
wstr wstrRemoveFreeSpace(wstr s)
{
    struct wstrhd *sh = (void *)(s - sizeof(struct wstrhd));
    sh = wrealloc(sh, sizeof(struct wstrhd)+sh->len+1);
    sh->free = 0;
    return sh->buf;
}

canonical_original_code:
char *wstrRemoveFreeSpace(char *s)
{
    struct wstrhd *sh = (void *)(s - sizeof(struct wstrhd));
    sh = wrealloc(sh, sizeof(struct wstrhd)+sh->len+1);
    sh->free = 0;
    return sh->buf;
}


wstrlen

decompiled_code:
__int64 __fastcall wstrlen(__int64 a1)
{
return *(unsigned int *)(a1 - 8);
}

original_code:
static inline int wstrlen(const wstr s)
{
    struct wstrhd *hd = (struct wstrhd *)(s - sizeof(struct wstrhd));
    return hd->len;
}

canonical_original_code:
static inline int wstrlen(char *s)
{
    struct wstrhd *hd = (struct wstrhd *)(s - sizeof(struct wstrhd));
    return hd->len;
}


dictEncIntKeyCompare

decompiled_code:
_BOOL8 __fastcall dictEncIntKeyCompare(__int64 a1, __int64 a2)
{
return a2 == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2)
{
return a2 == a1;
}

original_code:
int dictEncIntKeyCompare(const void *key1, const void *key2)
{
    return key1 == key2;
}

canonical_original_code:
int dictEncIntKeyCompare(void *key1, void *key2)
{
    return key1 == key2;
}


dictWstrHash

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

v1 = wstrlen(a1);
return dictGenHashFunction(a1, v1);
}

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

v1 = func0(a1);
return dictGenHashFunction(a1, v1);
}

original_code:
unsigned int dictWstrHash(const void *key) {
    return dictGenHashFunction((unsigned char*)key, wstrlen((char*)key));
}

canonical_original_code:
unsigned int dictWstrHash(void *key) {
    return dictGenHashFunction((unsigned char *)key, wstrlen((char *)key));
}

variable_types:
key
void *


dictSliceHash

decompiled_code:
__int64 __fastcall dictSliceHash(__int64 a1)
{
return dictGenHashFunction(*(_QWORD *)a1, *(unsigned int *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return dictGenHashFunction(*(_QWORD *)a1, *(unsigned int *)(a1 + 8));
}

original_code:
unsigned int dictSliceHash(const void *key) {
    const struct slice *s = key;
    return dictGenHashFunction(s->data, (int)s->len);
}

canonical_original_code:
unsigned int dictSliceHash(void *key) {
    struct slice *s = key;
    return dictGenHashFunction(s->data, (int)s->len);
}

variable_types: struct slice { unsigned char *data; unsigned long len; } *


dictWstrKeyCompare

decompiled_code:
_BOOL8 __fastcall dictWstrKeyCompare(void *s1, void *s2)
{
int v2; // ebx
int v3; // edx
_BOOL8 result; // rax

v2 = wstrlen((__int64)s1);
v3 = wstrlen((__int64)s2);
result = 0LL;
if ( v2 == v3 )
result = memcmp(s1, s2, v2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(void *s1, void *s2)
{
int v2; // ebx
int v3; // edx
_BOOL8 result; // rax

v2 = func0((__int64)s1);
v3 = func0((__int64)s2);
result = 0LL;
if ( v2 == v3 )
result = memcmp(s1, s2, v2) == 0;
return result;
}

original_code:
int dictWstrKeyCompare(const void *key1, const void *key2)
{
    int l1,l2;
    l1 = wstrlen((wstr)key1);
    l2 = wstrlen((wstr)key2);
    if (l1 != l2) return 0;
    return memcmp(key1, key2, l1) == 0;
}

canonical_original_code:
int dictWstrKeyCompare(void *key1, void *key2)
{
    int l1; int l2;
    l1 = wstrlen((char *)key1);
    l2 = wstrlen((char *)key2);
    if (l1 != l2) return 0;
    return memcmp(key1, key2, l1) == 0;
}


dictSliceKeyCompare

decompiled_code:
_BOOL8 __fastcall dictSliceKeyCompare(__int64 a1, __int64 a2)
{
size_t v2; // rdx
_BOOL8 result; // rax

v2 = *(_QWORD *)(a1 + 8);
result = 0LL;
if ( v2 == *(_QWORD *)(a2 + 8) )
result = memcmp(*(const void **)a1, *(const void **)a2, v2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1, __int64 a2)
{
size_t v2; // rdx
_BOOL8 result; // rax

v2 = *(_QWORD *)(a1 + 8);
result = 0LL;
if ( v2 == *(_QWORD *)(a2 + 8) )
result = memcmp(*(const void **)a1, *(const void **)a2, v2) == 0;
return result;
}

original_code:
int dictSliceKeyCompare(const void *key1, const void *key2)
{
    const struct slice *s1 = key1, *s2 = key2;
    size_t l1,l2;
    l1 = s1->len;
    l2 = s2->len;
    if (l1 != l2) return 0;
    return memcmp(s1->data, s2->data, l1) == 0;
}

canonical_original_code:
int dictSliceKeyCompare(void *key1, void *key2)
{
    struct slice *s1 = key1; struct slice *s2 = key2;
    unsigned long l1; unsigned long l2;
    l1 = s1->len;
    l2 = s2->len;
    if (l1 != l2) return 0;
    return memcmp(s1->data, s2->data, l1) == 0;
}


dictWstrDestructor

decompiled_code:
__int64 dictWstrDestructor()
{
return wstrFree();
}

canonical_decompiled_code:
__int64 func6()
{
return wstrFree();
}

original_code:
void dictWstrDestructor(void *val)
{
    wstrFree(val);
}

variable_types:
val
void *


dictSliceDestructor

decompiled_code:
__int64 dictSliceDestructor()
{
return sliceFree();
}

canonical_decompiled_code:
__int64 func7()
{
return sliceFree();
}

original_code:
void dictSliceDestructor(void *val)
{
    sliceFree(val);
}


dictWstrCaseHash

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

v1 = wstrlen(a1);
return dictGenCaseHashFunction(a1, v1);
}

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

v1 = func0(a1);
return dictGenCaseHashFunction(a1, v1);
}

original_code:
unsigned int dictWstrCaseHash(const void *key) {
    return dictGenCaseHashFunction((unsigned char*)key, wstrlen((char*)key));
}

canonical_original_code:
unsigned int dictWstrCaseHash(void *key) {
    return dictGenCaseHashFunction((unsigned char *)key, wstrlen((char *)key));
}


dictSliceCaseHash

decompiled_code:
__int64 __fastcall dictSliceCaseHash(__int64 a1)
{
return dictGenCaseHashFunction(*(_QWORD *)a1, *(unsigned int *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return dictGenCaseHashFunction(*(_QWORD *)a1, *(unsigned int *)(a1 + 8));
}

original_code:
unsigned int dictSliceCaseHash(const void *key) {
    const struct slice *s = key;
    return dictGenCaseHashFunction(s->data, (int)s->len);
}

canonical_original_code:
unsigned int dictSliceCaseHash(void *key) {
    struct slice *s = key;
    return dictGenCaseHashFunction(s->data, (int)s->len);
}


daemonize

decompiled_code:
__int64 __fastcall daemonize(int a1)
{
__pid_t v1; // eax
unsigned int v2; // ebp
int *v3; // rax
char *v4; // rax
__pid_t v6; // eax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int v11; // eax
unsigned int v12; // ebx
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
int *v19; // rax
char *v20; // rax
int *v21; // rax
char *v22; // rax
int *v23; // rax
char *v24; // rax

v1 = fork();
if ( v1 == -1 )
{
v2 = -1;
v3 = _errno_location();
v4 = strerror(*v3);
wheatLog(4LL, "fork() failed: %s", v4);
}
else
{
if ( v1 )
exit(0);
if ( setsid() < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
wheatLog(4LL, "setsid() failed: %s", v8);
v2 = -1;
}
else
{
v6 = fork();
v2 = v6;
if ( v6 == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
wheatLog(4LL, "fork() failed: %s", v10);
}
else
{
if ( v6 )
exit(0);
if ( a1 || chdir("/") >= 0 )
{
umask(0);
v11 = open("/dev/null", 2);
v12 = v11;
if ( v11 < 0 )
{
v17 = _errno_location();
v18 = strerror(*v17);
wheatLog(4LL, "open(\"/dev/null\") failed: %s", v18);
v2 = -1;
}
else if ( dup2(v11, 0) < 0 )
{
v19 = _errno_location();
v20 = strerror(*v19);
wheatLog(4LL, "dup2(%d, STDIN) failed: %s", v12, v20);
close(v12);
v2 = -1;
}
else if ( dup2(v12, 1) < 0 )
{
v21 = _errno_location();
v22 = strerror(*v21);
wheatLog(4LL, "dup2(%d, STDOUT) failed: %s", v12, v22);
close(v12);
v2 = -1;
}
else if ( dup2(v12, 2) < 0 )
{
v23 = _errno_location();
v24 = strerror(*v23);
wheatLog(4LL, "dup2(%d, STDERR) failed: %s", v12, v24);
close(v12);
v2 = -1;
}
else if ( (int)v12 > 2 && close(v12) < 0 )
{
v13 = _errno_location();
v14 = strerror(*v13);
wheatLog(4LL, "close(%d) failed: %s", v12, v14);
v2 = -1;
}
}
else
{
v15 = _errno_location();
v16 = strerror(*v15);
wheatLog(4LL, "chdir(\"/\") failed: %s", v16);
v2 = -1;
}
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
__pid_t v1; // eax
unsigned int v2; // ebp
int *v3; // rax
char *v4; // rax
__pid_t v6; // eax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int v11; // eax
unsigned int v12; // ebx
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
int *v19; // rax
char *v20; // rax
int *v21; // rax
char *v22; // rax
int *v23; // rax
char *v24; // rax

v1 = fork();
if ( v1 == -1 )
{
v2 = -1;
v3 = _errno_location();
v4 = strerror(*v3);
wheatLog(4LL, "fork() failed: %s", v4);
}
else
{
if ( v1 )
exit(0);
if ( setsid() < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
wheatLog(4LL, "setsid() failed: %s", v8);
v2 = -1;
}
else
{
v6 = fork();
v2 = v6;
if ( v6 == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
wheatLog(4LL, "fork() failed: %s", v10);
}
else
{
if ( v6 )
exit(0);
if ( a1 || chdir("/") >= 0 )
{
umask(0);
v11 = open("/dev/null", 2);
v12 = v11;
if ( v11 < 0 )
{
v17 = _errno_location();
v18 = strerror(*v17);
wheatLog(4LL, "open(\"/dev/null\") failed: %s", v18);
v2 = -1;
}
else if ( dup2(v11, 0) < 0 )
{
v19 = _errno_location();
v20 = strerror(*v19);
wheatLog(4LL, "dup2(%d, STDIN) failed: %s", v12, v20);
close(v12);
v2 = -1;
}
else if ( dup2(v12, 1) < 0 )
{
v21 = _errno_location();
v22 = strerror(*v21);
wheatLog(4LL, "dup2(%d, STDOUT) failed: %s", v12, v22);
close(v12);
v2 = -1;
}
else if ( dup2(v12, 2) < 0 )
{
v23 = _errno_location();
v24 = strerror(*v23);
wheatLog(4LL, "dup2(%d, STDERR) failed: %s", v12, v24);
close(v12);
v2 = -1;
}
else if ( (int)v12 > 2 && close(v12) < 0 )
{
v13 = _errno_location();
v14 = strerror(*v13);
wheatLog(4LL, "close(%d) failed: %s", v12, v14);
v2 = -1;
}
}
else
{
v15 = _errno_location();
v16 = strerror(*v15);
wheatLog(4LL, "chdir(\"/\") failed: %s", v16);
v2 = -1;
}
}
}
}
return v2;
}

original_code:
int daemonize(int dump_core)
{
    int status;
    pid_t pid, sid;
    int fd;
    pid = fork();
    switch (pid) {
        case -1:
            wheatLog(4, "fork() failed: %s", strerror((*__errno_location ())));
            return -1;
        case 0:
            break;
        default:
            _exit(0);
    }
    sid = setsid();
    if (sid < 0) {
        wheatLog(4, "setsid() failed: %s", strerror((*__errno_location ())));
        return -1;
    }
    pid = fork();
    switch (pid) {
        case -1:
            wheatLog(4, "fork() failed: %s", strerror((*__errno_location ())));
            return -1;
        case 0:
            break;
        default:
            _exit(0);
    }
    if (dump_core == 0) {
        status = chdir("/");
        if (status < 0) {
            wheatLog(4, "chdir(\"/\") failed: %s", strerror((*__errno_location ())));
            return -1;
        }
    }
    umask(0);
    fd = open("/dev/null", 02);
    if (fd < 0) {
        wheatLog(4, "open(\"/dev/null\") failed: %s", strerror((*__errno_location ())));
        return -1;
    }
    status = dup2(fd, 0);
    if (status < 0) {
        wheatLog(4, "dup2(%d, STDIN) failed: %s", fd, strerror((*__errno_location ())));
        close(fd);
        return -1;
    }
    status = dup2(fd, 1);
    if (status < 0) {
        wheatLog(4, "dup2(%d, STDOUT) failed: %s", fd, strerror((*__errno_location ())));
        close(fd);
        return -1;
    }
    status = dup2(fd, 2);
    if (status < 0) {
        wheatLog(4, "dup2(%d, STDERR) failed: %s", fd, strerror((*__errno_location ())));
        close(fd);
        return -1;
    }
    if (fd > 2) {
        status = close(fd);
        if (status < 0) {
            wheatLog(4, "close(%d) failed: %s", fd, strerror((*__errno_location ())));
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int daemonize(int dump_core)
{
    int status;
    int pid; int sid;
    int fd;
    pid = fork();
    switch (pid) {
        case -1:
            wheatLog(4, "fork() failed: %s", strerror((*__errno_location ())));
            return -1;
        case 0:
            break;
        default:
            _exit(0);
    }
    sid = setsid();
    if (sid < 0) {
        wheatLog(4, "setsid() failed: %s", strerror((*__errno_location ())));
        return -1;
    }
    pid = fork();
    switch (pid) {
        case -1:
            wheatLog(4, "fork() failed: %s", strerror((*__errno_location ())));
            return -1;
        case 0:
            break;
        default:
            _exit(0);
    }
    if (dump_core == 0) {
        status = chdir("/");
        if (status < 0) {
            wheatLog(4, "chdir(\"/\") failed: %s", strerror((*__errno_location ())));
            return -1;
        }
    }
    umask(0);
    fd = open("/dev/null", 02);
    if (fd < 0) {
        wheatLog(4, "open(\"/dev/null\") failed: %s", strerror((*__errno_location ())));
        return -1;
    }
    status = dup2(fd, 0);
    if (status < 0) {
        wheatLog(4, "dup2(%d, STDIN) failed: %s", fd, strerror((*__errno_location ())));
        close(fd);
        return -1;
    }
    status = dup2(fd, 1);
    if (status < 0) {
        wheatLog(4, "dup2(%d, STDOUT) failed: %s", fd, strerror((*__errno_location ())));
        close(fd);
        return -1;
    }
    status = dup2(fd, 2);
    if (status < 0) {
        wheatLog(4, "dup2(%d, STDERR) failed: %s", fd, strerror((*__errno_location ())));
        close(fd);
        return -1;
    }
    if (fd > 2) {
        status = close(fd);
        if (status < 0) {
            wheatLog(4, "close(%d) failed: %s", fd, strerror((*__errno_location ())));
            return -1;
        }
    }
    return 0;
}

variable_types: status int

variable_types: pid int

variable_types: sid int

variable_types: fd int


setTimer

decompiled_code:
int __fastcall setTimer(int a1)
{
struct itimerval v2; // [rsp+0h] [rbp-28h] BYREF

v2.it_value.tv_sec = a1 / 1000;
v2.it_value.tv_usec = 1000 * (a1 % 1000);
v2.it_interval = v2.it_value;
return setitimer(ITIMER_REAL, &v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func13(int a1)
{
struct itimerval v2; // [rsp+0h] [rbp-28h] BYREF

v2.it_value.tv_sec = a1 / 1000;
v2.it_value.tv_usec = 1000 * (a1 % 1000);
v2.it_interval = v2.it_value;
return setitimer(ITIMER_REAL, &v2, 0LL);
}

original_code:
void setTimer(int milliseconds)
{
    struct itimerval it;
    it.it_value.tv_sec = milliseconds / 1000;
    it.it_value.tv_usec = (milliseconds % 1000) * 1000;
    it.it_interval.tv_sec = it.it_value.tv_sec;
    it.it_interval.tv_usec = it.it_value.tv_usec;
    setitimer(ITIMER_REAL, &it, ((void *)0));
}

variable_types: milliseconds int

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


getFileSizeAndMtime

decompiled_code:
int __fastcall getFileSizeAndMtime(int fd, __off_t *a2, __time_t *a3)
{
int result; // eax
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

if ( fd <= 0 )
wheat_assert("fd > 0", "util.c", 270LL, 1LL);
result = fstat(fd, &v5);
if ( result != -1 )
{
if ( a2 )
*a2 = v5.st_size;
result = 0;
if ( a3 )
{
*a3 = v5.st_mtim.tv_sec;
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(int fd, __off_t *a2, __time_t *a3)
{
int result; // eax
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

if ( fd <= 0 )
wheat_assert("fd > 0", "util.c", 270LL, 1LL);
result = fstat(fd, &v5);
if ( result != -1 )
{
if ( a2 )
*a2 = v5.st_size;
result = 0;
if ( a3 )
{
*a3 = v5.st_mtim.tv_sec;
result = 0;
}
}
return result;
}

original_code:
int getFileSizeAndMtime(int fd, off_t *len, time_t *m_time)
{
    do { if (!(fd > 0)) { wheat_assert("fd > 0", "util.c", 270, 1); } } while (0);
    struct stat stat;
    int ret = fstat(fd, &stat);
    if (ret == -1)
        return -1;
    if (len) *len = stat.st_size;
    if (m_time) *m_time = stat.st_mtim.tv_sec;
    return 0;
}

canonical_original_code:
int getFileSizeAndMtime(int fd, long *len, long *m_time)
{
    do { if (!(fd > 0)) { wheat_assert("fd > 0", "util.c", 270, 1); } } while (0);
    struct stat stat;
    int ret = fstat(fd, &stat);
    if (ret == -1)
        return -1;
    if (len) *len = stat.st_size;
    if (m_time) *m_time = stat.st_mtim.tv_sec;
    return 0;
}

variable_types:
len
long *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: ret int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


isRegFile

decompiled_code:
int __fastcall isRegFile(char *file)
{
int result; // eax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( !file )
wheat_assert("path", "util.c", 283LL, 1LL);
result = lstat(file, &v2);
if ( result != -1 )
result = -((v2.st_mode & 0xF000) != 0x8000);
return result;
}

canonical_decompiled_code:
int __fastcall func15(char *file)
{
int result; // eax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( !file )
wheat_assert("path", "util.c", 283LL, 1LL);
result = lstat(file, &v2);
if ( result != -1 )
result = -((v2.st_mode & 0xF000) != 0x8000);
return result;
}

original_code:
int isRegFile(const char *path)
{
    do { if (!(path)) { wheat_assert("path", "util.c", 283, 1); } } while (0);
    struct stat stat;
    int ret = lstat(path, &stat);
    if (ret == -1)
        return -1;
    return ((((stat.st_mode)) & 0170000) == (0100000)) == 0 ? -1 : 0;
}

canonical_original_code:
int isRegFile(char *path)
{
    do { if (!(path)) { wheat_assert("path", "util.c", 283, 1); } } while (0);
    struct stat stat;
    int ret = lstat(path, &stat);
    if (ret == -1)
        return -1;
    return ((((stat.st_mode)) & 0170000) == (0100000)) == 0 ? -1 : 0;
}

variable_types:
path
char *

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


fromSameParentDir

decompiled_code:
_BOOL8 __fastcall fromSameParentDir(void *s1, void *s2)
{
int v2; // ebx
int v3; // edx
_BOOL8 result; // rax

v2 = wstrlen((__int64)s1);
v3 = wstrlen((__int64)s2);
result = 0LL;
if ( v2 <= v3 )
result = memcmp(s1, s2, v2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(void *s1, void *s2)
{
int v2; // ebx
int v3; // edx
_BOOL8 result; // rax

v2 = func0((__int64)s1);
v3 = func0((__int64)s2);
result = 0LL;
if ( v2 <= v3 )
result = memcmp(s1, s2, v2) == 0;
return result;
}

original_code:
int fromSameParentDir(wstr parent, wstr child)
{
    if (wstrlen(parent) > wstrlen(child))
        return 0;
    return memcmp(parent, child, wstrlen(parent)) == 0;
}

canonical_original_code:
int fromSameParentDir(char *parent, char *child)
{
    if (wstrlen(parent) > wstrlen(child))
        return 0;
    return memcmp(parent, child, wstrlen(parent)) == 0;
}

variable_types:
parent
char *

variable_types:
child
char *


decompiled_code:
__int64 __fastcall ll2string(void *dest, unsigned __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned __int64 v5; // rcx
char *v6; // rsi
char *v7; // r9
unsigned __int64 v8; // rax
_BYTE *v9; // rsi
size_t v10; // rbp
_BYTE v11[31]; // [rsp-1Eh] [rbp-38h] BYREF
char v12; // [rsp+1h] [rbp-19h] BYREF

result = 0LL;
if ( a2 )
{
v5 = abs64(a3);
v6 = &v12;
do
{
v7 = v6--;
v6[1] = v5 % 0xA + 48;
v8 = v5;
v5 /= 0xAuLL;
}
while ( v8 > 9 );
if ( a3 < 0 )
{
*v6 = 45;
v6 = v7 - 2;
}
v9 = v6 + 1;
v10 = 32 - (v9 - v11);
if ( 33 - (v9 - v11) > a2 )
v10 = a2 - 1;
memcpy(dest, v9, v10);
*((_BYTE *)dest + v10) = 0;
result = (unsigned int)v10;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(void *dest, unsigned __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned __int64 v5; // rcx
char *v6; // rsi
char *v7; // r9
unsigned __int64 v8; // rax
_BYTE *v9; // rsi
size_t v10; // rbp
_BYTE v11[31]; // [rsp-1Eh] [rbp-38h] BYREF
char v12; // [rsp+1h] [rbp-19h] BYREF

result = 0LL;
if ( a2 )
{
v5 = abs64(a3);
v6 = &v12;
do
{
v7 = v6--;
v6[1] = v5 % 0xA + 48;
v8 = v5;
v5 /= 0xAuLL;
}
while ( v8 > 9 );
if ( a3 < 0 )
{
*v6 = 45;
v6 = v7 - 2;
}
v9 = v6 + 1;
v10 = 32 - (v9 - v11);
if ( 33 - (v9 - v11) > a2 )
v10 = a2 - 1;
memcpy(dest, v9, v10);
*((_BYTE *)dest + v10) = 0;
result = (unsigned int)v10;
}
return result;
}

original_code:
int ll2string(char *s, size_t len, long long value)
{
    char buf[32], *p;
    unsigned long long v;
    size_t l;
    if (len == 0) return 0;
    v = (value < 0) ? -value : value;
    p = buf+31;
    do {
        *p-- = '0'+(v%10);
        v /= 10;
    } while(v);
    if (value < 0) *p-- = '-';
    p++;
    l = 32-(p-buf);
    if (l+1 > len) l = len-1;
    memcpy(s,p,l);
    s[l] = '\0';
    return l;
}

canonical_original_code:
int ll2string(char *s, unsigned long len, long long value)
{
    char buf[32]; char *p;
    unsigned long long v;
    unsigned long l;
    if (len == 0) return 0;
    v = (value < 0) ? -value : value;
    p = buf+31;
    do {
        *p-- = '0'+(v%10);
        v /= 10;
    } while(v);
    if (value < 0) *p-- = '-';
    p++;
    l = 32-(p-buf);
    if (l+1 > len) l = len-1;
    memcpy(s,p,l);
    s[l] = '\0';
    return l;
}

variable_types:
s
char *

variable_types:
len
unsigned long

variable_types:
value
long long

variable_types:
buf
char [32]

variable_types:
p
char *

variable_types:
v
unsigned long long

variable_types:
l
unsigned long


dictEncIntHash

decompiled_code:
__int64 __fastcall dictEncIntHash(__int64 a1)
{
unsigned int v1; // eax
_BYTE v3[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = ll2string(v3, 0x20uLL, a1);
return dictGenHashFunction(v3, v1);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
unsigned int v1; // eax
_BYTE v3[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = func17(v3, 0x20uLL, a1);
return dictGenHashFunction(v3, v1);
}

original_code:
unsigned int dictEncIntHash(const void *key)
{
    char buf[32];
    int len;
    len = ll2string(buf, 32, (intptr_t)key);
    return dictGenHashFunction((unsigned char*)buf, len);
}

canonical_original_code:
unsigned int dictEncIntHash(void *key)
{
    char buf[32];
    int len;
    len = ll2string(buf, 32, (long)key);
    return dictGenHashFunction((unsigned char *)buf, len);
}

variable_types:
key
void *

variable_types: len int


original_code:
int string2ll(const char *s, size_t slen, long long *value)
{
    const char *p = s;
    size_t plen = 0;
    int negative = 0;
    unsigned long long v;
    if (plen == slen)
        return -1;
    if (slen == 1 && p[0] == '0') {
        if (value != ((void *)0)) *value = 0;
        return 0;
    }
    if (p[0] == '-') {
        negative = 1;
        p++; plen++;
        if (plen == slen)
            return -1;
    }
    if (p[0] >= '1' && p[0] <= '9') {
        v = p[0]-'0';
        p++; plen++;
    } else if (p[0] == '0' && slen == 1) {
        *value = 0;
        return 0;
    } else {
        return -1;
    }
    while (plen < slen && p[0] >= '0' && p[0] <= '9') {
        if (v > ((0x7fffffffffffffffLL * 2ULL + 1ULL) / 10))
            return -1;
        v *= 10;
        if (v > ((0x7fffffffffffffffLL * 2ULL + 1ULL) - (p[0]-'0')))
            return -1;
        v += p[0]-'0';
        p++; plen++;
    }
    if (plen < slen)
        return -1;
    if (negative) {
        if (v > ((unsigned long long)(-((-0x7fffffffffffffffLL - 1LL)+1))+1))
            return -1;
        if (value != ((void *)0)) *value = -v;
    } else {
        if (v > 0x7fffffffffffffffLL)
            return -1;
        if (value != ((void *)0)) *value = v;
    }
    return 0;
}

canonical_original_code:
int string2ll(char *s, unsigned long slen, long long *value)
{
    char *p = s;
    unsigned long plen = 0;
    int negative = 0;
    unsigned long long v;
    if (plen == slen)
        return -1;
    if (slen == 1 && p[0] == '0') {
        if (value != ((void *)0)) *value = 0;
        return 0;
    }
    if (p[0] == '-') {
        negative = 1;
        p++; plen++;
        if (plen == slen)
            return -1;
    }
    if (p[0] >= '1' && p[0] <= '9') {
        v = p[0]-'0';
        p++; plen++;
    } else if (p[0] == '0' && slen == 1) {
        *value = 0;
        return 0;
    } else {
        return -1;
    }
    while (plen < slen && p[0] >= '0' && p[0] <= '9') {
        if (v > ((0x7fffffffffffffffLL * 2ULL + 1ULL) / 10))
            return -1;
        v *= 10;
        if (v > ((0x7fffffffffffffffLL * 2ULL + 1ULL) - (p[0]-'0')))
            return -1;
        v += p[0]-'0';
        p++; plen++;
    }
    if (plen < slen)
        return -1;
    if (negative) {
        if (v > ((unsigned long long)(-((-0x7fffffffffffffffLL - 1LL)+1))+1))
            return -1;
        if (value != ((void *)0)) *value = -v;
    } else {
        if (v > 0x7fffffffffffffffLL)
            return -1;
        if (value != ((void *)0)) *value = v;
    }
    return 0;
}

variable_types:
slen
unsigned long

variable_types:
value
long long *

variable_types:
plen
unsigned long

variable_types: negative int


getIntLen

decompiled_code:
__int64 __fastcall getIntLen(unsigned __int64 a1)
{
unsigned __int64 v1; // rdx
__int64 v2; // rcx
unsigned __int64 v3; // rsi

v1 = a1 / 0xA;
if ( a1 <= 9 )
return 1LL;
v2 = 1LL;
do
{
++v2;
v3 = v1;
v1 /= 0xAuLL;
}
while ( v3 > 9 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned __int64 a1)
{
unsigned __int64 v1; // rdx
__int64 v2; // rcx
unsigned __int64 v3; // rsi

v1 = a1 / 0xA;
if ( a1 <= 9 )
return 1LL;
v2 = 1LL;
do
{
++v2;
v3 = v1;
v1 /= 0xAuLL;
}
while ( v3 > 9 );
return v2;
}

original_code:
size_t getIntLen(unsigned long i)
{
    size_t len = 1;
    while (i /= 10) {
        len++;
    }
    return len;
}

canonical_original_code:
unsigned long getIntLen(unsigned long i)
{
    unsigned long len = 1;
    while (i /= 10) {
        len++;
    }
    return len;
}

variable_types:
i
unsigned long

return_type: unsigned long


wheatLog

decompiled_code:
void wheatLog(unsigned __int8 a1, const char *a2, ...)
{
char v2[1032]; // [rsp+0h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-D0h] BYREF

if ( a1 >= Server[21046] )
{
va_start(arg, a2);
vsnprintf(v2, 0x400uLL, a2, arg);
wheatLogRaw(a1, v2);
}
}

canonical_decompiled_code:
void func1(unsigned __int8 a1, const char *a2, ...)
{
char v2[1032]; // [rsp+0h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-D0h] BYREF

if ( a1 >= Server[21046] )
{
va_start(arg, a2);
vsnprintf(v2, 0x400uLL, a2, arg);
func0(a1, v2);
}
}

original_code:
void wheatLog(int level, const char *fmt, ...)
{
    va_list ap;
    char msg[1024];
    int ret;
    if ((level&0xff) < Server.verbose) return;
    __builtin_va_start(ap,fmt);
    ret = vsnprintf(msg, sizeof(msg), fmt, ap);
    __builtin_va_end(ap);
    wheatLogRaw(level, msg);
}

canonical_original_code:
void wheatLog(int level, char *fmt, ...)
{
    __builtin_va_list ap;
    char msg[1024];
    int ret;
    if ((level&0xff) < Server.verbose) return;
    __builtin_va_start(ap,fmt);
    ret = vsnprintf(msg, sizeof(msg), fmt, ap);
    __builtin_va_end(ap);
    wheatLogRaw(level, msg);
}

variable_types: level int

variable_types:
fmt
char *

variable_types:
msg
char [1024]

variable_types: ret int


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

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

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

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

original_code:
static inline size_t spt_min(size_t a, size_t b) {
 return (((a) < (b))? (a) : (b));
}

canonical_original_code:
static inline unsigned long spt_min(unsigned long a, unsigned long b) {
 return (((a) < (b))? (a) : (b));
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long


decompiled_code:
__int64 __fastcall spt_copyargs(int a1, __int64 a2)
{
const char **v3; // rbx
int i; // ebp
_QWORD *v6; // r12
const char *v7; // rdi
char *v8; // rax

v3 = (const char **)(a2 + 8);
for ( i = 1; ; ++i )
{
if ( i < a1 )
{
v6 = v3;
v7 = *v3;
if ( !*v3 )
goto LABEL_6;
goto LABEL_4;
}
v6 = v3;
v7 = *v3;
if ( !*v3 )
break;
LABEL_4:
v8 = strdup(v7);
if ( !v8 )
return (unsigned int)*_errno_location();
*v6 = v8;
LABEL_6:
++v3;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2)
{
const char **v3; // rbx
int i; // ebp
_QWORD *v6; // r12
const char *v7; // rdi
char *v8; // rax

v3 = (const char **)(a2 + 8);
for ( i = 1; ; ++i )
{
if ( i < a1 )
{
v6 = v3;
v7 = *v3;
if ( !*v3 )
goto LABEL_6;
goto LABEL_4;
}
v6 = v3;
v7 = *v3;
if ( !*v3 )
break;
LABEL_4:
v8 = strdup(v7);
if ( !v8 )
return (unsigned int)*_errno_location();
*v6 = v8;
LABEL_6:
++v3;
}
return 0LL;
}

original_code:
static int spt_copyargs(int argc, char *argv[]) {
 char *tmp;
 int i;
 for (i = 1; i < argc || (i >= argc && argv[i]); i++) {
  if (!argv[i])
   continue;
  if (!(tmp = strdup(argv[i])))
   return (*__errno_location ());
  argv[i] = tmp;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
tmp
char *

variable_types: i int


decompiled_code:
__int64 spt_clearenv()
{
clearenv();
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
clearenv();
return 0LL;
}

original_code:
static int spt_clearenv(void) {
 clearenv();
 return 0;
}

canonical_original_code:
static int spt_clearenv() {
 clearenv();
 return 0;
}