wstrStartWithChars

decompiled_code:
_BOOL8 __fastcall wstrStartWithChars(const void *a1, const void *a2)
{
size_t v2; // rdx
_BOOL8 result; // rax
size_t v4; // rcx

v2 = (int)wstrlen((__int64)a1);
result = 0LL;
if ( v2 >= v4 )
result = memcmp(a1, a2, v2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(const void *a1, const void *a2)
{
size_t v2; // rdx
_BOOL8 result; // rax
size_t v4; // rcx

v2 = (int)func0((__int64)a1);
result = 0LL;
if ( v2 >= v4 )
result = memcmp(a1, a2, v2) == 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(__int64 a1, const void *a2)
{
const void *v2; // r8

wstrlen((__int64)a2);
return wstrStartWithChars(v2, a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(__int64 a1, const void *a2)
{
const void *v2; // r8

func0((__int64)a2);
return func14(v2, a2);
}

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

variable_types:
s
char *

return_type: int


wstrRange

decompiled_code:
void *__fastcall wstrRange(void *dest, int a2)
{
int v2; // eax
int v3; // edx
int v4; // ecx
int v5; // edx
int v6; // ebp
int v7; // edx

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

canonical_decompiled_code:
void *__fastcall func16(void *dest, int a2)
{
int v2; // eax
int v3; // edx
int v4; // ecx
int v5; // edx
int v6; // ebp
int v7; // edx

if ( dest )
{
v2 = func0((__int64)dest);
v4 = v3;
if ( a2 < 0 )
a2 += v2;
if ( v3 < 0 )
{
v5 = v2 + v3;
if ( v2 + v4 > v2 )
v5 = v2;
}
else
{
v5 = v2;
if ( v4 )
{
if ( v2 <= v4 )
v4 = v2;
v5 = v4;
}
}
v6 = 0;
if ( a2 > v2 )
a2 = v2;
v7 = v5 - a2;
if ( v7 >= 0 )
v6 = v7;
memmove(dest, (char *)dest + a2, 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

variable_types: len int

return_type: char *


wstrStrip

decompiled_code:
void *__fastcall wstrStrip(void *src, char *s)
{
char *v2; // rbp
int v3; // ebx
int v4; // eax
int v5; // er12
int v6; // er14
char *v7; // r14
int v8; // er12

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

canonical_decompiled_code:
void *__fastcall func17(void *src, char *s)
{
char *v2; // rbp
int v3; // ebx
int v4; // eax
int v5; // er12
int v6; // er14
char *v7; // r14
int v8; // er12

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

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 v2; // eax
__int64 v3; // rdx
__int64 result; // rax

v2 = wstrlen(a1);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
result = 0LL;
while ( *(_BYTE *)(a1 + result) != a2 )
{
if ( ++result == v3 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, char a2)
{
unsigned int v2; // eax
__int64 v3; // rdx
__int64 result; // rax

v2 = func0(a1);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
result = 0LL;
while ( *(_BYTE *)(a1 + result) != a2 )
{
if ( ++result == v3 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

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

variable_types: i int


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

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


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

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


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 *

return_type: unsigned int


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(__int64 a1, const void *a2)
{
size_t v2; // rdx
const void *v3; // r8
int v4; // er9
_BOOL8 result; // rax

wstrlen(a1);
v4 = wstrlen((__int64)a2);
result = 0LL;
if ( (_DWORD)v2 == v4 )
result = memcmp(v3, a2, v2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, const void *a2)
{
size_t v2; // rdx
const void *v3; // r8
int v4; // er9
_BOOL8 result; // rax

func0(a1);
v4 = func0((__int64)a2);
result = 0LL;
if ( (_DWORD)v2 == v4 )
result = memcmp(v3, a2, 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);
if ( v2 == *(_QWORD *)(a2 + 8) )
result = memcmp(*(const void **)a1, *(const void **)a2, v2) == 0;
else
result = 0LL;
return result;
}

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

v2 = *(_QWORD *)(a1 + 8);
if ( v2 == *(_QWORD *)(a2 + 8) )
result = memcmp(*(const void **)a1, *(const void **)a2, v2) == 0;
else
result = 0LL;
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;
}

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


dictWstrDestructor

decompiled_code:
// attributes: thunk
__int64 dictWstrDestructor()
{
return wstrFree();
}

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

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

variable_types:
val
void *

return_type: void


dictSliceDestructor

decompiled_code:
// attributes: thunk
__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; // er12
__pid_t v3; // eax
int v4; // eax
unsigned int v5; // ebp
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
__int64 v15; // rdx
const char *v16; // rsi
char *v17; // rcx
int *v18; // rax
char *v19; // rax
int *v20; // rax
char *v21; // rax
int *v22; // rax
char *v23; // rax
int *v24; // rax
char *v25; // rax

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

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

v1 = fork();
v2 = v1;
if ( v1 == -1 )
goto LABEL_16;
if ( v1 )
goto LABEL_15;
if ( setsid() < 0 )
{
v11 = _errno_location();
v2 = -1;
v12 = strerror(*v11);
wheatLog(4LL, "setsid() failed: %s", v12);
return v2;
}
v3 = fork();
v2 = v3;
if ( v3 == -1 )
{
LABEL_16:
v8 = _errno_location();
v9 = strerror(*v8);
wheatLog(4LL, "fork() failed: %s", v9);
return v2;
}
if ( v3 )
LABEL_15:
exit(0);
if ( !a1 && chdir("/") < 0 )
{
v24 = _errno_location();
v2 = -1;
v25 = strerror(*v24);
wheatLog(4LL, "chdir(\"/\") failed: %s", v25);
return v2;
}
umask(0);
v4 = open("/dev/null", 2);
v5 = v4;
if ( v4 < 0 )
{
v20 = _errno_location();
v2 = -1;
v21 = strerror(*v20);
wheatLog(4LL, "open(\"/dev/null\") failed: %s", v21);
return v2;
}
if ( dup2(v4, 0) < 0 )
{
v18 = _errno_location();
v19 = strerror(*v18);
v15 = v5;
v16 = "dup2(%d, STDIN) failed: %s";
v17 = v19;
goto LABEL_20;
}
if ( dup2(v5, 1) < 0 )
{
v13 = _errno_location();
v14 = strerror(*v13);
v15 = v5;
v16 = "dup2(%d, STDOUT) failed: %s";
v17 = v14;
LABEL_20:
v2 = -1;
wheatLog(4LL, v16, v15, v17);
close(v5);
return v2;
}
if ( dup2(v5, 2) < 0 )
{
v22 = _errno_location();
v23 = strerror(*v22);
v15 = v5;
v16 = "dup2(%d, STDERR) failed: %s";
v17 = v23;
goto LABEL_20;
}
if ( (int)v5 > 2 && close(v5) < 0 )
{
v6 = _errno_location();
v2 = -1;
v7 = strerror(*v6);
wheatLog(4LL, "close(%d) failed: %s", v5, v7);
}
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;
}
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;
}
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(__int64 a1, const void *a2)
{
size_t v2; // rdx
const void *v3; // r8
int v4; // er9
_BOOL8 result; // rax

wstrlen(a1);
v4 = wstrlen((__int64)a2);
result = 0LL;
if ( (int)v2 <= v4 )
result = memcmp(v3, a2, v2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(__int64 a1, const void *a2)
{
size_t v2; // rdx
const void *v3; // r8
int v4; // er9
_BOOL8 result; // rax

func0(a1);
v4 = func0((__int64)a2);
result = 0LL;
if ( (int)v2 <= v4 )
result = memcmp(v3, a2, 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)
{
unsigned __int64 v4; // rcx
char *v5; // rdi
char *v6; // r8
unsigned __int64 v7; // rax
size_t v8; // rbx
_BYTE v10[31]; // [rsp-1Eh] [rbp-28h] BYREF
char src; // [rsp+1h] [rbp-9h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func17(void *dest, unsigned __int64 a2, __int64 a3)
{
unsigned __int64 v4; // rcx
char *v5; // rdi
char *v6; // r8
unsigned __int64 v7; // rax
size_t v8; // rbx
_BYTE v10[31]; // [rsp-1Eh] [rbp-28h] BYREF
char src; // [rsp+1h] [rbp-9h] BYREF

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

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


decompiled_code:
__int64 __fastcall string2ll(_BYTE *a1, unsigned __int64 a2, __int64 *a3)
{
char v4; // al
unsigned int v5; // er8
_BYTE *v7; // r8
unsigned __int64 v8; // rcx
int v9; // er10
__int64 v10; // rax
_BYTE *v11; // r8
unsigned __int64 v12; // rax
unsigned __int8 v13; // dl

if ( !a2 )
return 0xFFFFFFFFLL;
v4 = *a1;
if ( a2 != 1 )
{
if ( v4 == 45 )
{
v4 = a1[1];
v7 = a1 + 1;
v8 = 2LL;
v9 = 1;
if ( (unsigned __int8)(v4 - 49) > 8u )
return 0xFFFFFFFFLL;
}
else
{
v5 = -1;
if ( (unsigned __int8)(v4 - 49) > 8u )
return v5;
v7 = a1;
v8 = 1LL;
v9 = 0;
}
v10 = (char)(v4 - 48);
if ( a2 <= v8 )
goto LABEL_14;
v11 = &v7[-v8];
while ( 1 )
{
v13 = v11[v8 + 1] - 48;
if ( v13 > 9u )
break;
if ( (unsigned __int64)v10 > 0x1999999999999999LL )
return 0xFFFFFFFFLL;
v12 = 10 * v10;
if ( ~(__int64)(char)v13 < v12 )
return 0xFFFFFFFFLL;
++v8;
v10 = (char)v13 + v12;
if ( a2 <= v8 )
goto LABEL_14;
}
if ( a2 <= v8 )
{
LABEL_14:
if ( v9 )
{
if ( (unsigned __int64)v10 <= 0x8000000000000000LL )
{
v5 = 0;
if ( a3 )
*a3 = -v10;
return v5;
}
return 0xFFFFFFFFLL;
}
goto LABEL_24;
}
return 0xFFFFFFFFLL;
}
if ( v4 != 48 )
{
if ( v4 != 45 && (unsigned __int8)(v4 - 49) <= 8u )
{
v10 = (char)(v4 - 48);
LABEL_24:
if ( v10 >= 0 )
{
v5 = 0;
if ( a3 )
*a3 = v10;
return v5;
}
return 0xFFFFFFFFLL;
}
return 0xFFFFFFFFLL;
}
v5 = 0;
if ( !a3 )
return v5;
*a3 = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(_BYTE *a1, unsigned __int64 a2, __int64 *a3)
{
char v4; // al
unsigned int v5; // er8
_BYTE *v7; // r8
unsigned __int64 v8; // rcx
int v9; // er10
__int64 v10; // rax
_BYTE *v11; // r8
unsigned __int64 v12; // rax
unsigned __int8 v13; // dl

if ( !a2 )
return 0xFFFFFFFFLL;
v4 = *a1;
if ( a2 != 1 )
{
if ( v4 == 45 )
{
v4 = a1[1];
v7 = a1 + 1;
v8 = 2LL;
v9 = 1;
if ( (unsigned __int8)(v4 - 49) > 8u )
return 0xFFFFFFFFLL;
}
else
{
v5 = -1;
if ( (unsigned __int8)(v4 - 49) > 8u )
return v5;
v7 = a1;
v8 = 1LL;
v9 = 0;
}
v10 = (char)(v4 - 48);
if ( a2 <= v8 )
goto LABEL_14;
v11 = &v7[-v8];
while ( 1 )
{
v13 = v11[v8 + 1] - 48;
if ( v13 > 9u )
break;
if ( (unsigned __int64)v10 > 0x1999999999999999LL )
return 0xFFFFFFFFLL;
v12 = 10 * v10;
if ( ~(__int64)(char)v13 < v12 )
return 0xFFFFFFFFLL;
++v8;
v10 = (char)v13 + v12;
if ( a2 <= v8 )
goto LABEL_14;
}
if ( a2 <= v8 )
{
LABEL_14:
if ( v9 )
{
if ( (unsigned __int64)v10 <= 0x8000000000000000LL )
{
v5 = 0;
if ( a3 )
*a3 = -v10;
return v5;
}
return 0xFFFFFFFFLL;
}
goto LABEL_24;
}
return 0xFFFFFFFFLL;
}
if ( v4 != 48 )
{
if ( v4 != 45 && (unsigned __int8)(v4 - 49) <= 8u )
{
v10 = (char)(v4 - 48);
LABEL_24:
if ( v10 >= 0 )
{
v5 = 0;
if ( a3 )
*a3 = v10;
return v5;
}
return 0xFFFFFFFFLL;
}
return 0xFFFFFFFFLL;
}
v5 = 0;
if ( !a3 )
return v5;
*a3 = 0LL;
return 0LL;
}

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)
{
__int64 v1; // r8
unsigned __int64 v2; // rdx
unsigned __int64 v3; // rcx

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

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

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

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, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

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

canonical_decompiled_code:
void func1(unsigned __int8 a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

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

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


setproctitle

decompiled_code:
void setproctitle(char *format, ...)
{
int v1; // ebx
unsigned __int64 v2; // r14
void *v3; // rbp
unsigned __int64 v4; // rax
size_t v5; // rdx
unsigned __int64 v6; // r12
int v7; // eax
void *v8; // rdi
unsigned __int64 v9; // rbp
__int64 v10; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1F0h] BYREF
char s[256]; // [rsp+20h] [rbp-1D8h] BYREF
__int64 v13; // [rsp+128h] [rbp-D0h]
__int64 v14; // [rsp+130h] [rbp-C8h]

va_start(arg, format);
v13 = va_arg(arg, _QWORD);
v14 = va_arg(arg, _QWORD);
va_end(arg);
if ( !dest )
return;
if ( !format )
{
v1 = snprintf(s, 0x100uLL, "%s", (const char *)SPT);
if ( v1 > 0 )
goto LABEL_4;
LABEL_14:
dword_224 = *_errno_location();
return;
}
va_start(arg, format);
v1 = vsnprintf(s, 0x100uLL, format, arg);
if ( v1 <= 0 )
goto LABEL_14;
LABEL_4:
v2 = qword_210;
v3 = dest;
v4 = spt_min(0x100uLL, qword_210 - (_QWORD)dest);
v6 = v4;
if ( byte_220 )
{
memset(v3, 0, v4);
}
else
{
memset(v3, 0, v5);
byte_220 = 1;
}
v7 = spt_min(v1, v6 - 1);
v8 = v3;
v9 = (unsigned __int64)v3 + v7;
memcpy(v8, s, v7);
v10 = qword_218;
if ( qword_218 <= v9 )
{
if ( qword_218 == v9 && v2 > qword_218 + 1 )
{
*(_BYTE *)qword_218 = 32;
*(_BYTE *)(v10 + 1) = 0;
}
}
else
{
*(_BYTE *)qword_218 = 46;
}
}

canonical_decompiled_code:
void func1(char *format, ...)
{
int v1; // ebx
unsigned __int64 v2; // r14
void *v3; // rbp
unsigned __int64 v4; // rax
size_t v5; // rdx
unsigned __int64 v6; // r12
int v7; // eax
void *v8; // rdi
unsigned __int64 v9; // rbp
__int64 v10; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1F0h] BYREF
char s[256]; // [rsp+20h] [rbp-1D8h] BYREF
__int64 v13; // [rsp+128h] [rbp-D0h]
__int64 v14; // [rsp+130h] [rbp-C8h]

va_start(arg, format);
v13 = va_arg(arg, _QWORD);
v14 = va_arg(arg, _QWORD);
va_end(arg);
if ( !dest )
return;
if ( !format )
{
v1 = snprintf(s, 0x100uLL, "%s", (const char *)SPT);
if ( v1 > 0 )
goto LABEL_4;
LABEL_14:
dword_224 = *_errno_location();
return;
}
va_start(arg, format);
v1 = vsnprintf(s, 0x100uLL, format, arg);
if ( v1 <= 0 )
goto LABEL_14;
LABEL_4:
v2 = qword_210;
v3 = dest;
v4 = func0(0x100uLL, qword_210 - (_QWORD)dest);
v6 = v4;
if ( byte_220 )
{
memset(v3, 0, v4);
}
else
{
memset(v3, 0, v5);
byte_220 = 1;
}
v7 = func0(v1, v6 - 1);
v8 = v3;
v9 = (unsigned __int64)v3 + v7;
memcpy(v8, s, v7);
v10 = qword_218;
if ( qword_218 <= v9 )
{
if ( qword_218 == v9 && v2 > qword_218 + 1 )
{
*(_BYTE *)qword_218 = 32;
*(_BYTE *)(v10 + 1) = 0;
}
}
else
{
*(_BYTE *)qword_218 = 46;
}
}

original_code:
void setproctitle(const char *fmt, ...) {
 char buf[255 + 1];
 va_list ap;
 char *nul;
 int len, error;
 if (!SPT.base)
  return;
 if (fmt) {
  __builtin_va_start(ap,fmt);
  len = vsnprintf(buf, sizeof buf, fmt, ap);
  __builtin_va_end(ap);
 } else {
  len = snprintf(buf, sizeof buf, "%s", SPT.arg0);
 }
 if (len <= 0)
  { error = (*__errno_location ()); goto error; }
 if (!SPT.reset) {
  memset(SPT.base, 0, SPT.end - SPT.base);
  SPT.reset = 1;
 } else {
  memset(SPT.base, 0, spt_min(sizeof buf, SPT.end - SPT.base));
 }
 len = spt_min(len, spt_min(sizeof buf, SPT.end - SPT.base) - 1);
 memcpy(SPT.base, buf, len);
 nul = &SPT.base[len];
 if (nul < SPT.nul) {
  *SPT.nul = '.';
 } else if (nul == SPT.nul && &nul[1] < SPT.end) {
  *SPT.nul = ' ';
  *++nul = '\0';
 }
 return;
error:
 SPT.error = error;
}

canonical_original_code:
void setproctitle(char *fmt, ...) {
 char buf[-1];
 __builtin_va_list ap;
 char *nul;
 int len; int error;
 if (!SPT.base)
  return;
 if (fmt) {
  __builtin_va_start(ap,fmt);
  len = vsnprintf(buf, sizeof buf, fmt, ap);
  __builtin_va_end(ap);
 } else {
  len = snprintf(buf, sizeof buf, "%s", SPT.arg0);
 }
 if (len <= 0)
  { error = (*__errno_location ()); goto error; }
 if (!SPT.reset) {
  memset(SPT.base, 0, SPT.end - SPT.base);
  SPT.reset = 1;
 } else {
  memset(SPT.base, 0, spt_min(sizeof buf, SPT.end - SPT.base));
 }
 len = spt_min(len, spt_min(sizeof buf, SPT.end - SPT.base) - 1);
 memcpy(SPT.base, buf, len);
 nul = &SPT.base[len];
 if (nul < SPT.nul) {
  *SPT.nul = '.';
 } else if (nul == SPT.nul && &nul[1] < SPT.end) {
  *SPT.nul = ' ';
  *++nul = '\0';
 }
 return;
error:
 SPT.error = error;
}

variable_types:
buf
char [-1]

variable_types:
nul
char *

variable_types: error int


decompiled_code:
__int64 __fastcall spt_copyargs(int a1, __int64 a2)
{
__int64 i; // rbx
char *v4; // rax
const char *v5; // rdi

for ( i = 1LL; ; ++i )
{
v5 = *(const char **)(a2 + 8 * i);
if ( a1 > (int)i )
{
if ( !v5 )
continue;
}
else if ( !v5 )
{
return 0LL;
}
v4 = strdup(v5);
if ( !v4 )
break;
*(_QWORD *)(a2 + 8 * i) = v4;
}
return (unsigned int)*_errno_location();
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
__int64 i; // rbx
char *v4; // rax
const char *v5; // rdi

for ( i = 1LL; ; ++i )
{
v5 = *(const char **)(a2 + 8 * i);
if ( a1 > (int)i )
{
if ( !v5 )
continue;
}
else if ( !v5 )
{
return 0LL;
}
v4 = strdup(v5);
if ( !v4 )
break;
*(_QWORD *)(a2 + 8 * i) = v4;
}
return (unsigned int)*_errno_location();
}

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 func3()
{
clearenv();
return 0LL;
}

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

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


decompiled_code:
__int64 __fastcall spt_copyenv(char **a1)
{
__int64 result; // rax
const char *v3; // rdi
const char **v4; // rbp
char *v5; // rax
char *v6; // rbx

if ( environ != a1 )
return 0LL;
result = spt_clearenv();
if ( (_DWORD)result )
{
LABEL_11:
environ = a1;
}
else
{
v3 = *a1;
if ( *a1 )
{
v4 = (const char **)a1;
do
{
v5 = strchr(v3, 61);
v6 = v5;
if ( v5 )
{
*v5 = 0;
if ( setenv(*v4, v5 + 1, 1) )
{
result = (unsigned int)*_errno_location();
*v6 = 61;
if ( (_DWORD)result )
goto LABEL_11;
}
else
{
*v6 = 61;
}
}
v3 = v4[1];
++v4;
}
while ( v3 );
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char **a1)
{
__int64 result; // rax
const char *v3; // rdi
const char **v4; // rbp
char *v5; // rax
char *v6; // rbx

if ( environ != a1 )
return 0LL;
result = func3();
if ( (_DWORD)result )
{
LABEL_11:
environ = a1;
}
else
{
v3 = *a1;
if ( *a1 )
{
v4 = (const char **)a1;
do
{
v5 = strchr(v3, 61);
v6 = v5;
if ( v5 )
{
*v5 = 0;
if ( setenv(*v4, v5 + 1, 1) )
{
result = (unsigned int)*_errno_location();
*v6 = 61;
if ( (_DWORD)result )
goto LABEL_11;
}
else
{
*v6 = 61;
}
}
v3 = v4[1];
++v4;
}
while ( v3 );
}
result = 0LL;
}
return result;
}

original_code:
static int spt_copyenv(char *oldenv[]) {
 extern char **environ;
 char *eq;
 int i, error;
 if (environ != oldenv)
  return 0;
 if ((error = spt_clearenv()))
  goto error;
 for (i = 0; oldenv[i]; i++) {
  if (!(eq = strchr(oldenv[i], '=')))
   continue;
  *eq = '\0';
  error = (0 != setenv(oldenv[i], eq + 1, 1))? (*__errno_location ()) : 0;
  *eq = '=';
  if (error)
   goto error;
 }
 return 0;
error:
 environ = oldenv;
 return error;
}

canonical_original_code:
static int spt_copyenv(char *oldenv[]) {
 extern char **environ;
 char *eq;
 int i; int error;
 if (environ != oldenv)
  return 0;
 if ((error = spt_clearenv()))
  goto error;
 for (i = 0; oldenv[i]; i++) {
  if (!(eq = strchr(oldenv[i], '=')))
   continue;
  *eq = '\0';
  error = (0 != setenv(oldenv[i], eq + 1, 1))? (*__errno_location ()) : 0;
  *eq = '=';
  if (error)
   goto error;
 }
 return 0;
error:
 environ = oldenv;
 return error;
}

variable_types:
oldenv
char *[]

variable_types:
environ
char **

variable_types:
eq
char *


decompiled_code:
void __fastcall spt_init(int a1, const char **a2, char **a3)
{
const char *v3; // r13
const char *v4; // rbx
__int64 v5; // r14
size_t v6; // r15
const char *v7; // rbx
const char **v8; // r14
char *v9; // rax
char *v10; // rax
int v11; // eax
__int64 v13; // [rsp+8h] [rbp-40h]

v3 = *a2;
if ( *a2 )
{
v4 = *a2;
v5 = 0LL;
v13 = (__int64)&v3[strlen(v3)];
v6 = v13 + 1;
while ( a1 > (int)v5 || v4 )
{
if ( v6 <= (unsigned __int64)v4 && v4 )
v6 = (size_t)&v4[strlen(v4) + 1];
v4 = a2[++v5];
}
v7 = *a3;
if ( *a3 )
{
v8 = (const char **)(a3 + 1);
do
{
if ( v6 <= (unsigned __int64)v7 )
v6 = (size_t)&v7[strlen(v7) + 1];
v7 = *v8++;
}
while ( v7 );
}
SPT = (__int64)strdup(v3);
if ( SPT
&& (v9 = strdup(program_invocation_name)) != 0LL
&& (program_invocation_name = v9, (v10 = strdup(program_invocation_short_name)) != 0LL) )
{
program_invocation_short_name = v10;
v11 = spt_copyenv(a3);
if ( !v11 )
{
v11 = spt_copyargs(a1, (__int64)a2);
if ( !v11 )
{
dest = (void *)v3;
qword_210 = v6;
qword_218 = v13;
return;
}
}
}
else
{
v11 = *_errno_location();
}
dword_224 = v11;
}
}

canonical_decompiled_code:
void __fastcall func5(int a1, const char **a2, char **a3)
{
const char *v3; // r13
const char *v4; // rbx
__int64 v5; // r14
size_t v6; // r15
const char *v7; // rbx
const char **v8; // r14
char *v9; // rax
char *v10; // rax
int v11; // eax
__int64 v13; // [rsp+8h] [rbp-40h]

v3 = *a2;
if ( *a2 )
{
v4 = *a2;
v5 = 0LL;
v13 = (__int64)&v3[strlen(v3)];
v6 = v13 + 1;
while ( a1 > (int)v5 || v4 )
{
if ( v6 <= (unsigned __int64)v4 && v4 )
v6 = (size_t)&v4[strlen(v4) + 1];
v4 = a2[++v5];
}
v7 = *a3;
if ( *a3 )
{
v8 = (const char **)(a3 + 1);
do
{
if ( v6 <= (unsigned __int64)v7 )
v6 = (size_t)&v7[strlen(v7) + 1];
v7 = *v8++;
}
while ( v7 );
}
SPT = (__int64)strdup(v3);
if ( SPT
&& (v9 = strdup(program_invocation_name)) != 0LL
&& (program_invocation_name = v9, (v10 = strdup(program_invocation_short_name)) != 0LL) )
{
program_invocation_short_name = v10;
v11 = func4(a3);
if ( !v11 )
{
v11 = func2(a1, (__int64)a2);
if ( !v11 )
{
dest = (void *)v3;
qword_210 = v6;
qword_218 = v13;
return;
}
}
}
else
{
v11 = *_errno_location();
}
dword_224 = v11;
}
}

original_code:
void spt_init(int argc, char *argv[], char *envp[]) {
 char *base, *end, *nul, *tmp;
 int i, error;
 if (!(base = argv[0]))
  return;
 nul = &base[strlen(base)];
 end = nul + 1;
 for (i = 0; i < argc || (i >= argc && argv[i]); i++) {
  if (!argv[i] || argv[i] < end)
   continue;
  end = argv[i] + strlen(argv[i]) + 1;
 }
 for (i = 0; envp[i]; i++) {
  if (envp[i] < end)
   continue;
  end = envp[i] + strlen(envp[i]) + 1;
 }
 if (!(SPT.arg0 = strdup(argv[0])))
  goto syerr;
 if (!(tmp = strdup(program_invocation_name)))
  goto syerr;
 program_invocation_name = tmp;
 if (!(tmp = strdup(program_invocation_short_name)))
  goto syerr;
 program_invocation_short_name = tmp;
 if ((error = spt_copyenv(envp)))
  goto error;
 if ((error = spt_copyargs(argc, argv)))
  goto error;
 SPT.nul = nul;
 SPT.base = base;
 SPT.end = end;
 return;
syerr:
 error = (*__errno_location ());
error:
 SPT.error = error;
}

canonical_original_code:
void spt_init(int argc, char *argv[], char *envp[]) {
 char *base; char *end; char *nul; char *tmp;
 int i; int error;
 if (!(base = argv[0]))
  return;
 nul = &base[strlen(base)];
 end = nul + 1;
 for (i = 0; i < argc || (i >= argc && argv[i]); i++) {
  if (!argv[i] || argv[i] < end)
   continue;
  end = argv[i] + strlen(argv[i]) + 1;
 }
 for (i = 0; envp[i]; i++) {
  if (envp[i] < end)
   continue;
  end = envp[i] + strlen(envp[i]) + 1;
 }
 if (!(SPT.arg0 = strdup(argv[0])))
  goto syerr;
 if (!(tmp = strdup(program_invocation_name)))
  goto syerr;
 program_invocation_name = tmp;
 if (!(tmp = strdup(program_invocation_short_name)))
  goto syerr;
 program_invocation_short_name = tmp;
 if ((error = spt_copyenv(envp)))
  goto error;
 if ((error = spt_copyargs(argc, argv)))
  goto error;
 SPT.nul = nul;
 SPT.base = base;
 SPT.end = end;
 return;
syerr:
 error = (*__errno_location ());
error:
 SPT.error = error;
}

variable_types:
envp
char *[]

variable_types:
base
char *

variable_types:
end
char *


decompiled_code:
int __fastcall report_metro_type_stats(__int64 *a1)
{
__int64 v1; // r8
__int64 v2; // rsi
__int64 v3; // rdx
bool v4; // zf
__int64 v5; // rdx

v1 = *a1;
v2 = a1[1];
v3 = *a1 + v2;
v4 = a1[2] + v3 == 0;
v5 = a1[2] + v3;
a1[3] = v5;
if ( v4 )
return puts("# None.");
if ( v1 )
{
printf("# Metropolis selves: %9lld / %9lld (%7.3lf%%)\n", v1, v5, (double)(int)v1 * 100.0 / (double)(int)v5);
v2 = a1[1];
v5 = a1[3];
}
printf("# Metropolis keeps: %9lld / %9lld (%7.3lf%%)\n", v2, v5, (double)(int)v2 * 100.0 / (double)(int)v5);
return printf(
"# Metropolis changes: %9lld / %9lld (%7.3lf%%)\n",
a1[2],
a1[3],
(double)(int)a1[2] * 100.0 / (double)(int)a1[3]);
}

original_code:
void report_metro_type_stats(metro_type_stats_t* pstats)
{
 pstats->num_total = pstats->num_self
  + pstats->num_keep + pstats->num_change;
 if (pstats->num_total == 0) {
  printf("#   None.\n");
  return;
 }
 if (pstats->num_self != 0) {
  printf("#   Metropolis selves:  %9lld / %9lld (%7.3lf%%)\n",
   pstats->num_self, pstats->num_total,
   (double)pstats->num_self*100.0/(double)pstats->num_total);
 }
 printf("#   Metropolis keeps:   %9lld / %9lld (%7.3lf%%)\n",
  pstats->num_keep, pstats->num_total,
  (double)pstats->num_keep*100.0/(double)pstats->num_total);
 printf("#   Metropolis changes: %9lld / %9lld (%7.3lf%%)\n",
  pstats->num_change, pstats->num_total,
  (double)pstats->num_change*100.0/(double)pstats->num_total);
}

canonical_original_code:
void report_metro_type_stats(struct _metro_type_stats_t *pstats)
{
 pstats->num_total = pstats->num_self
  + pstats->num_keep + pstats->num_change;
 if (pstats->num_total == 0) {
  printf("#   None.\n");
  return;
 }
 if (pstats->num_self != 0) {
  printf("#   Metropolis selves:  %9lld / %9lld (%7.3lf%%)\n",
   pstats->num_self, pstats->num_total,
   (double)pstats->num_self*100.0/(double)pstats->num_total);
 }
 printf("#   Metropolis keeps:   %9lld / %9lld (%7.3lf%%)\n",
  pstats->num_keep, pstats->num_total,
  (double)pstats->num_keep*100.0/(double)pstats->num_total);
 printf("#   Metropolis changes: %9lld / %9lld (%7.3lf%%)\n",
  pstats->num_change, pstats->num_total,
  (double)pstats->num_change*100.0/(double)pstats->num_total);
}

variable_types: struct _metro_type_stats_t { long long num_self; long long num_keep; long long num_change; long long num_total; } *


decompiled_code:
int __fastcall report_metro_stats(__int64 *a1)
{
puts("# OPENS:");
report_metro_type_stats(a1);
puts("# CLOSES:");
report_metro_type_stats(a1 + 4);
puts("# HS:");
report_metro_type_stats(a1 + 8);
puts("# TS:");
report_metro_type_stats(a1 + 12);
puts("# SO:");
return report_metro_type_stats(a1 + 16);
}

canonical_decompiled_code:
int __fastcall func3(__int64 *a1)
{
puts("# OPENS:");
func1(a1);
puts("# CLOSES:");
func1(a1 + 4);
puts("# HS:");
func1(a1 + 8);
puts("# TS:");
func1(a1 + 12);
puts("# SO:");
return func1(a1 + 16);
}

original_code:
void report_metro_stats(metro_stats_t* pmetro_stats)
{
 printf("# OPENS:\n"); report_metro_type_stats(&pmetro_stats->open_stats);
 printf("# CLOSES:\n"); report_metro_type_stats(&pmetro_stats->close_stats);
 printf("# HS:\n"); report_metro_type_stats(&pmetro_stats->HS_stats);
 printf("# TS:\n"); report_metro_type_stats(&pmetro_stats->TS_stats);
 printf("# SO:\n"); report_metro_type_stats(&pmetro_stats->SO_stats);
}

canonical_original_code:
void report_metro_stats(struct _metro_stats_t *pmetro_stats)
{
 printf("# OPENS:\n"); report_metro_type_stats(&pmetro_stats->open_stats);
 printf("# CLOSES:\n"); report_metro_type_stats(&pmetro_stats->close_stats);
 printf("# HS:\n"); report_metro_type_stats(&pmetro_stats->HS_stats);
 printf("# TS:\n"); report_metro_type_stats(&pmetro_stats->TS_stats);
 printf("# SO:\n"); report_metro_type_stats(&pmetro_stats->SO_stats);
}

variable_types: struct _metro_stats_t { struct _metro_type_stats_t { long long num_self; long long num_keep; long long num_change; long long num_total; } open_stats; struct _metro_type_stats_t close_stats; struct _metro_type_stats_t HS_stats; struct _metro_type_stats_t TS_stats; struct _metro_type_stats_t SO_stats; } *

user_defined_types: struct _metro_stats_t { struct _metro_type_stats_t open_stats; struct _metro_type_stats_t close_stats; struct _metro_type_stats_t HS_stats; struct _metro_type_stats_t TS_stats; struct _metro_type_stats_t SO_stats; }


decompiled_code:
void __fastcall check_magic_number(unsigned int a1, const char *a2, const char *a3)
{
if ( a1 != 558711634 )
{
fprintf(stderr, "%s: expected %s 0x%08x; got 0x%08x.\n", a3, a2, 558711634LL, a1);
fwrite("Incorrect file format, or file format has changed?\n", 1uLL, 0x33uLL, stderr);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1, const char *a2, const char *a3)
{
if ( a1 != 558711634 )
{
fprintf(stderr, "%s: expected %s 0x%08x; got 0x%08x.\n", a3, a2, 558711634LL, a1);
fwrite("Incorrect file format, or file format has changed?\n", 1uLL, 0x33uLL, stderr);
exit(1);
}
}

original_code:
static void check_magic_number(unsigned file_value,
 char* var_name, char* func_name)
{
 if (file_value != 0x214d4352) {
  fprintf(stderr,
  "%s:  expected %s 0x%08x; got 0x%08x.\n",
   func_name, var_name,
   0x214d4352, file_value);
  fprintf(stderr, "Incorrect file format, or file format has changed?\n");
  exit(1);
 }
}

canonical_original_code:
static void check_magic_number(unsigned int file_value, char *var_name, char *func_name)
{
 if (file_value != 0x214d4352) {
  fprintf(stderr,
  "%s:  expected %s 0x%08x; got 0x%08x.\n",
   func_name, var_name,
   0x214d4352, file_value);
  fprintf(stderr, "Incorrect file format, or file format has changed?\n");
  exit(1);
 }
}


decompiled_code:
int __fastcall print_mcmc_params(__int64 a1)
{
const char *v1; // rax
unsigned int v2; // eax
const char *v3; // rax
const char *v4; // rsi
const char *v5; // rsi
__int64 v6; // rsi
__int64 v7; // rsi
const char *v8; // rdx
__int64 v9; // rsi
const char *v10; // rcx
const char *v11; // rdx
__int64 v12; // rsi
const char *v13; // rdx

v1 = (const char *)get_rng_type_desc(*(unsigned int *)(a1 + 4));
printf("# RNG = %s\n", v1);
if ( *(_DWORD *)(a1 + 12) )
printf("# RNG seed = 0x%08x\n", *(unsigned int *)(a1 + 8));
v2 = ipow(*(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20));
printf("# L = %d d = %d N = %d\n", *(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20), v2);
puts("# Boundary conditions: periodic.");
printf(
"# T = %11.7lf beta = %11.7lf alpha0 = %11.7lf\n",
1.0 / *(double *)(a1 + 24),
*(double *)(a1 + 24),
*(double *)(a1 + 32));
printf("# gamma = %11.7lf\n", *(double *)(a1 + 48));
v3 = (const char *)get_interaction_type_desc(*(unsigned int *)(a1 + 40));
printf("# Interactions: %s.\n", v3);
v4 = "uniform random";
if ( !*(_DWORD *)(a1 + 72) )
{
v4 = "Wx=1";
if ( !*(_DWORD *)(a1 + 76) )
{
v4 = "Wy=1";
if ( !*(_DWORD *)(a1 + 80) )
{
v4 = "Wz=1";
if ( !*(_DWORD *)(a1 + 84) )
v4 = "identity";
}
}
}
printf("# Initial permutation: %s.\n", v4);
v5 = "random";
if ( !*(_DWORD *)(a1 + 88) )
v5 = "sequential";
printf("# Site selection for Metropolis sweeps: %s.\n", v5);
v6 = *(unsigned int *)(a1 + 108);
if ( (_DWORD)v6 == -1 )
{
printf("# Thermalization is detected by %d turning points of system energy\n", *(unsigned int *)(a1 + 116));
printf("# smoothed over a %d-point window.\n", *(unsigned int *)(a1 + 112));
}
else
{
printf("# %d pre-accumulation sweeps having occurred.\n", v6);
}
v7 = *(unsigned int *)(a1 + 104);
v8 = "s";
if ( (_DWORD)v7 == 1 )
v8 = (const char *)&unk_762;
printf("# Terminate after %d accumulation%s:\n", v7, v8);
v9 = *(unsigned int *)(a1 + 96);
v10 = "s";
v11 = "SAR";
if ( (_DWORD)v9 == 1 )
v10 = (const char *)&unk_762;
if ( !*(_DWORD *)(a1 + 92) )
v11 = "SO";
printf("# * %d %s sweep%s per accumulation.\n", v9, v11, v10);
v12 = *(unsigned int *)(a1 + 100);
v13 = "s";
if ( (_DWORD)v12 == 1 )
v13 = (const char *)&unk_762;
return printf("# * %d worm sweep%s per accumulation.\n", v12, v13);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
const char *v1; // rax
unsigned int v2; // eax
const char *v3; // rax
const char *v4; // rsi
const char *v5; // rsi
__int64 v6; // rsi
__int64 v7; // rsi
const char *v8; // rdx
__int64 v9; // rsi
const char *v10; // rcx
const char *v11; // rdx
__int64 v12; // rsi
const char *v13; // rdx

v1 = (const char *)get_rng_type_desc(*(unsigned int *)(a1 + 4));
printf("# RNG = %s\n", v1);
if ( *(_DWORD *)(a1 + 12) )
printf("# RNG seed = 0x%08x\n", *(unsigned int *)(a1 + 8));
v2 = ipow(*(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20));
printf("# L = %d d = %d N = %d\n", *(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20), v2);
puts("# Boundary conditions: periodic.");
printf(
"# T = %11.7lf beta = %11.7lf alpha0 = %11.7lf\n",
1.0 / *(double *)(a1 + 24),
*(double *)(a1 + 24),
*(double *)(a1 + 32));
printf("# gamma = %11.7lf\n", *(double *)(a1 + 48));
v3 = (const char *)get_interaction_type_desc(*(unsigned int *)(a1 + 40));
printf("# Interactions: %s.\n", v3);
v4 = "uniform random";
if ( !*(_DWORD *)(a1 + 72) )
{
v4 = "Wx=1";
if ( !*(_DWORD *)(a1 + 76) )
{
v4 = "Wy=1";
if ( !*(_DWORD *)(a1 + 80) )
{
v4 = "Wz=1";
if ( !*(_DWORD *)(a1 + 84) )
v4 = "identity";
}
}
}
printf("# Initial permutation: %s.\n", v4);
v5 = "random";
if ( !*(_DWORD *)(a1 + 88) )
v5 = "sequential";
printf("# Site selection for Metropolis sweeps: %s.\n", v5);
v6 = *(unsigned int *)(a1 + 108);
if ( (_DWORD)v6 == -1 )
{
printf("# Thermalization is detected by %d turning points of system energy\n", *(unsigned int *)(a1 + 116));
printf("# smoothed over a %d-point window.\n", *(unsigned int *)(a1 + 112));
}
else
{
printf("# %d pre-accumulation sweeps having occurred.\n", v6);
}
v7 = *(unsigned int *)(a1 + 104);
v8 = "s";
if ( (_DWORD)v7 == 1 )
v8 = (const char *)&unk_762;
printf("# Terminate after %d accumulation%s:\n", v7, v8);
v9 = *(unsigned int *)(a1 + 96);
v10 = "s";
v11 = "SAR";
if ( (_DWORD)v9 == 1 )
v10 = (const char *)&unk_762;
if ( !*(_DWORD *)(a1 + 92) )
v11 = "SO";
printf("# * %d %s sweep%s per accumulation.\n", v9, v11, v10);
v12 = *(unsigned int *)(a1 + 100);
v13 = "s";
if ( (_DWORD)v12 == 1 )
v13 = (const char *)&unk_762;
return printf("# * %d worm sweep%s per accumulation.\n", v12, v13);
}

original_code:
void print_mcmc_params(mcmc_params_t* p)
{
 printf("# RNG = %s\n", get_rng_type_desc(p->rng_type));
 if (p->do_seed)
  printf("# RNG seed = 0x%08x\n", p->seed);
 printf("# L = %d d = %d N = %d\n", p->L, p->d, ipow(p->L, p->d));
 printf("# Boundary conditions: periodic.\n");
 printf("# T = %11.7lf beta = %11.7lf alpha0 = %11.7lf\n",
  1.0 / p->beta, p->beta, p->alpha0);
 printf("# gamma = %11.7lf\n", p->gamma);
 printf("# Interactions:  %s.\n",
  get_interaction_type_desc(p->interaction_type));
 printf("# Initial permutation: %s.\n",
  p->rand_init_pi ? "uniform random" :
  p->wx1_init_pi ? "Wx=1" :
  p->wy1_init_pi ? "Wy=1" :
  p->wz1_init_pi ? "Wz=1" :
  "identity");
 printf("# Site selection for Metropolis sweeps: %s.\n",
  p->do_random_sweep ? "random" : "sequential");
 if (p->force_therm == -1) {
  printf("# Thermalization is detected by %d turning points of system "
   "energy\n", p->therm_ntp);
  printf("# smoothed over a %d-point window.\n",
   p->smoothing_window_size);
 }
 else {
  printf("# %d pre-accumulation sweeps having occurred.\n",
   p->force_therm);
 }
 printf("# Terminate after %d accumulation%s:\n",
  p->termination_num_acc,
  p->termination_num_acc == 1 ? "" : "s");
 printf("# * %d %s  sweep%s per accumulation.\n",
  p->gsweeps_per_acc,
  p->allow_cycle_reversals ? "SAR" : "SO",
  p->gsweeps_per_acc == 1 ? "" : "s");
 printf("# * %d worm sweep%s per accumulation.\n",
  p->wsweeps_per_acc, p->wsweeps_per_acc == 1 ? "" : "s");
}

canonical_original_code:
void print_mcmc_params(struct _mcmc_params_t *p)
{
 printf("# RNG = %s\n", get_rng_type_desc(p->rng_type));
 if (p->do_seed)
  printf("# RNG seed = 0x%08x\n", p->seed);
 printf("# L = %d d = %d N = %d\n", p->L, p->d, ipow(p->L, p->d));
 printf("# Boundary conditions: periodic.\n");
 printf("# T = %11.7lf beta = %11.7lf alpha0 = %11.7lf\n",
  1.0 / p->beta, p->beta, p->alpha0);
 printf("# gamma = %11.7lf\n", p->gamma);
 printf("# Interactions:  %s.\n",
  get_interaction_type_desc(p->interaction_type));
 printf("# Initial permutation: %s.\n",
  p->rand_init_pi ? "uniform random" :
  p->wx1_init_pi ? "Wx=1" :
  p->wy1_init_pi ? "Wy=1" :
  p->wz1_init_pi ? "Wz=1" :
  "identity");
 printf("# Site selection for Metropolis sweeps: %s.\n",
  p->do_random_sweep ? "random" : "sequential");
 if (p->force_therm == -1) {
  printf("# Thermalization is detected by %d turning points of system "
   "energy\n", p->therm_ntp);
  printf("# smoothed over a %d-point window.\n",
   p->smoothing_window_size);
 }
 else {
  printf("# %d pre-accumulation sweeps having occurred.\n",
   p->force_therm);
 }
 printf("# Terminate after %d accumulation%s:\n",
  p->termination_num_acc,
  p->termination_num_acc == 1 ? "" : "s");
 printf("# * %d %s  sweep%s per accumulation.\n",
  p->gsweeps_per_acc,
  p->allow_cycle_reversals ? "SAR" : "SO",
  p->gsweeps_per_acc == 1 ? "" : "s");
 printf("# * %d worm sweep%s per accumulation.\n",
  p->wsweeps_per_acc, p->wsweeps_per_acc == 1 ? "" : "s");
}

variable_types: struct _mcmc_params_t { unsigned int magic_number; int rng_type; unsigned int seed; int do_seed; int L; int d; double beta; double alpha0; int interaction_type; int pad; double gamma; int tbd1; int tbd2; int tbd3; int tbd4; int rand_init_pi; int wx1_init_pi; int wy1_init_pi; int wz1_init_pi; int do_random_sweep; int allow_cycle_reversals; int gsweeps_per_acc; int wsweeps_per_acc; int termination_num_acc; int force_therm; int smoothing_window_size; int therm_ntp; unsigned int magic_number2; } *


decompiled_code:
int __fastcall display_footer(double *a1)
{
report_metro_stats(a1 + 4);
printf("# Elapsed thermalization seconds: %.6lf\n", a1[2] - a1[1]);
printf("# Elapsed accumulation seconds: %.6lf\n", a1[3] - a1[2]);
return printf("# Elapsed total seconds: %.6lf\n", a1[3] - a1[1]);
}

canonical_decompiled_code:
int __fastcall func7(double *a1)
{
report_metro_stats(a1 + 4);
printf("# Elapsed thermalization seconds: %.6lf\n", a1[2] - a1[1]);
printf("# Elapsed accumulation seconds: %.6lf\n", a1[3] - a1[2]);
return printf("# Elapsed total seconds: %.6lf\n", a1[3] - a1[1]);
}

original_code:
void display_footer(mcmc_footer_t* pfooter)
{
 report_metro_stats(&pfooter->metro_stats);
 printf("# Elapsed thermalization seconds: %.6lf\n",
  pfooter->therm_time - pfooter->start_time);
 printf("# Elapsed accumulation   seconds: %.6lf\n",
  pfooter->end_time - pfooter->therm_time);
 printf("# Elapsed total seconds:          %.6lf\n",
  pfooter->end_time - pfooter->start_time);
}

canonical_original_code:
void display_footer(struct _mcmc_footer_t *pfooter)
{
 report_metro_stats(&pfooter->metro_stats);
 printf("# Elapsed thermalization seconds: %.6lf\n",
  pfooter->therm_time - pfooter->start_time);
 printf("# Elapsed accumulation   seconds: %.6lf\n",
  pfooter->end_time - pfooter->therm_time);
 printf("# Elapsed total seconds:          %.6lf\n",
  pfooter->end_time - pfooter->start_time);
}

variable_types: struct _mcmc_footer_t { unsigned int magic_number; int pad; double start_time; double therm_time; double end_time; struct _metro_stats_t { struct _metro_type_stats_t { long long num_self; long long num_keep; long long num_change; long long num_total; } open_stats; struct _metro_type_stats_t close_stats; struct _metro_type_stats_t HS_stats; struct _metro_type_stats_t TS_stats; struct _metro_type_stats_t SO_stats; } metro_stats; int tbd[4]; unsigned int magic_number2; } *

user_defined_types: struct _mcmc_footer_t { unsigned int magic_number; int pad; double start_time; double therm_time; double end_time; struct _metro_stats_t metro_stats; int tbd[4]; unsigned int magic_number2; }


decompiled_code:
const char *__fastcall get_interaction_type_desc(int a1)
{
const char *result; // rax

if ( a1 == 33 )
return "constant r_ell";
if ( a1 <= 33 )
{
result = "none";
if ( a1 != 11 )
{
result = "(undefined interaction type)";
if ( a1 == 22 )
result = "r2";
}
}
else
{
result = "Vzw lower";
if ( a1 != 44 )
{
result = "(undefined interaction type)";
if ( a1 == 55 )
result = "Vzw upper";
}
}
return result;
}

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

if ( a1 == 33 )
return "constant r_ell";
if ( a1 <= 33 )
{
result = "none";
if ( a1 != 11 )
{
result = "(undefined interaction type)";
if ( a1 == 22 )
result = "r2";
}
}
else
{
result = "Vzw lower";
if ( a1 != 44 )
{
result = "(undefined interaction type)";
if ( a1 == 55 )
result = "Vzw upper";
}
}
return result;
}

original_code:
char* get_interaction_type_desc(int interaction_type)
{
 switch (interaction_type) {
 case 11: return "none"; break;
 case 22: return "r2"; break;
 case 33: return "constant r_ell"; break;
 case 44: return "Vzw lower"; break;
 case 55: return "Vzw upper"; break;
 default:
  return "(undefined interaction type)";
  break;
 }
}

canonical_original_code:
char *get_interaction_type_desc(int interaction_type)
{
 switch (interaction_type) {
 case 11: return "none"; break;
 case 22: return "r2"; break;
 case 33: return "constant r_ell"; break;
 case 44: return "Vzw lower"; break;
 case 55: return "Vzw upper"; break;
 default:
  return "(undefined interaction type)";
  break;
 }
}


decompiled_code:
double *__fastcall get_alphas(int a1, int a2, double a3)
{
double *v3; // r8
double *result; // rax
double *v5; // rax

v3 = (double *)double_malloc_or_die((unsigned int)(a2 + 1));
if ( a2 >= 0 )
v3 = (double *)memset(v3, 0, 8LL * a2 + 8);
if ( a1 == 33 )
{
if ( a2 <= 0 )
return v3;
v5 = v3 + 1;
do
*v5++ = a3;
while ( v5 != &v3[(unsigned int)(a2 - 1) + 2] );
result = v3;
}
else
{
if ( a1 <= 33 )
{
if ( a1 == 11 )
return v3;
if ( a1 == 22 )
{
v3[2] = a3;
return v3;
}
LABEL_17:
fprintf(stderr, "get_alphas: undefined interaction type %d.\n", (unsigned int)a1);
exit(1);
}
if ( a1 == 44 )
{
v3[2] = a3;
result = v3;
}
else
{
if ( a1 != 55 )
goto LABEL_17;
v3[2] = a3;
result = v3;
}
}
return result;
}

canonical_decompiled_code:
double *__fastcall func1(int a1, int a2, double a3)
{
double *v3; // r8
double *result; // rax
double *v5; // rax

v3 = (double *)double_malloc_or_die((unsigned int)(a2 + 1));
if ( a2 >= 0 )
v3 = (double *)memset(v3, 0, 8LL * a2 + 8);
if ( a1 == 33 )
{
if ( a2 <= 0 )
return v3;
v5 = v3 + 1;
do
*v5++ = a3;
while ( v5 != &v3[(unsigned int)(a2 - 1) + 2] );
result = v3;
}
else
{
if ( a1 <= 33 )
{
if ( a1 == 11 )
return v3;
if ( a1 == 22 )
{
v3[2] = a3;
return v3;
}
LABEL_17:
fprintf(stderr, "get_alphas: undefined interaction type %d.\n", (unsigned int)a1);
exit(1);
}
if ( a1 == 44 )
{
v3[2] = a3;
result = v3;
}
else
{
if ( a1 != 55 )
goto LABEL_17;
v3[2] = a3;
result = v3;
}
}
return result;
}

original_code:
double* get_alphas(int interaction_type, int N, double alpha0)
{
 double* alphas = double_malloc_or_die(N+1);
 int k;
 for (k = 0; k <= N; k++)
  alphas[k] = 0.0;
 switch (interaction_type) {
 case 11:
  break;
 case 22:
  alphas[2] = alpha0;
  break;
 case 33:
  for (k = 1; k <= N; k++)
   alphas[k] = alpha0;
  break;
 case 44:
  alphas[2] = alpha0;
  break;
 case 55:
  alphas[2] = alpha0;
  break;
 default:
  fprintf(stderr, "get_alphas: undefined interaction type %d.\n",
   interaction_type);
  exit(1);
  break;
 }
 return alphas;
}

canonical_original_code:
double *get_alphas(int interaction_type, int N, double alpha0)
{
 double *alphas = double_malloc_or_die(N+1);
 int k;
 for (k = 0; k <= N; k++)
  alphas[k] = 0.0;
 switch (interaction_type) {
 case 11:
  break;
 case 22:
  alphas[2] = alpha0;
  break;
 case 33:
  for (k = 1; k <= N; k++)
   alphas[k] = alpha0;
  break;
 case 44:
  alphas[2] = alpha0;
  break;
 case 55:
  alphas[2] = alpha0;
  break;
 default:
  fprintf(stderr, "get_alphas: undefined interaction type %d.\n",
   interaction_type);
  exit(1);
  break;
 }
 return alphas;
}

variable_types: N int

variable_types:
alphas
double *

variable_types: k int

return_type: double *


decompiled_code:
__int64 __fastcall mtrand_init(int a1)
{
unsigned int v1; // edx
__int64 result; // rax

mt[0] = a1;
v1 = a1;
for ( result = 1LL; ; ++result )
{
v1 = 1812433253 * (v1 ^ (v1 >> 30)) + result;
mt[result] = v1;
if ( result == 623 )
break;
}
mti = 624;
return result;
}

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

mt[0] = a1;
v1 = a1;
for ( result = 1LL; ; ++result )
{
v1 = 1812433253 * (v1 ^ (v1 >> 30)) + result;
mt[result] = v1;
if ( result == 623 )
break;
}
mti = 624;
return result;
}

original_code:
void mtrand_init(unsigned s)
{
    mt[0]= s & 0xffffffff;
    for (mti=1; mti<624; mti++) {
        mt[mti] =
     (1812433253 * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
        mt[mti] &= 0xffffffff;
    }
}

canonical_original_code:
void mtrand_init(unsigned int s)
{
    mt[0]= s & 0xffffffff;
    for (mti=1; mti<624; mti++) {
        mt[mti] =
     (1812433253 * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
        mt[mti] &= 0xffffffff;
    }
}

variable_types:
s
unsigned int


decompiled_code:
__int64 get_mtrand_int31()
{
return (unsigned int)get_mtrand_int32() >> 1;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)func2() >> 1;
}

original_code:
int get_mtrand_int31(void)
{
    return (int)(get_mtrand_int32()>>1);
}

canonical_original_code:
int get_mtrand_int31()
{
    return (int)(get_mtrand_int32()>>1);
}


decompiled_code:
double get_mtrand_float()
{
return (double)(int)get_mtrand_int32() * 2.328306436538696e-10;
}

original_code:
double get_mtrand_float(void)
{
    return get_mtrand_int32()*(1.0/4294967296.0);
}

canonical_original_code:
double get_mtrand_float()
{
    return get_mtrand_int32()*(1.0/4294967296.0);
}

return_type: double


decompiled_code:
double __fastcall get_mtrand_double(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // eax
unsigned int v6; // er8

v2 = ((__int64 (*)(void))get_mtrand_int32)();
v5 = get_mtrand_int32(a1, a2, v3, v4, v2, 0.0, 0.0);
return ((double)(v6 >> 5) * 67108864.0 + (double)(v5 >> 6)) * 1.110223024625157e-16;
}

original_code:
double get_mtrand_double(void)
{
    unsigned a = get_mtrand_int32() >> 5;
 unsigned b = get_mtrand_int32() >> 6;
    return (a*67108864.0+b) * (1.0/9007199254740992.0);
}

canonical_original_code:
double get_mtrand_double()
{
    unsigned int a = get_mtrand_int32() >> 5;
 unsigned int b = get_mtrand_int32() >> 6;
    return (a*67108864.0+b) * (1.0/9007199254740992.0);
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int


decompiled_code:
void *__fastcall therm_ctl_init(unsigned int *a1, unsigned int a2, int a3, int a4)
{
void *result; // rax
__int64 v5; // rdx

a1[1] = a3;
*a1 = a2;
a1[2] = a4;
*(_QWORD *)(a1 + 3) = 0LL;
*(_QWORD *)(a1 + 5) = 0LL;
*(_QWORD *)(a1 + 7) = 0LL;
*(_QWORD *)(a1 + 9) = 0LL;
*(_QWORD *)(a1 + 11) = 0LL;
*(_QWORD *)(a1 + 13) = 0LL;
*(_QWORD *)(a1 + 15) = 0LL;
*(_QWORD *)(a1 + 17) = 0LL;
result = (void *)double_malloc_or_die(a2);
v5 = (int)*a1;
*((_QWORD *)a1 + 10) = result;
if ( (int)v5 > 0 )
result = memset(result, 0, 8 * v5);
*((_QWORD *)a1 + 11) = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(unsigned int *a1, unsigned int a2, int a3, int a4)
{
void *result; // rax
__int64 v5; // rdx

a1[1] = a3;
*a1 = a2;
a1[2] = a4;
*(_QWORD *)(a1 + 3) = 0LL;
*(_QWORD *)(a1 + 5) = 0LL;
*(_QWORD *)(a1 + 7) = 0LL;
*(_QWORD *)(a1 + 9) = 0LL;
*(_QWORD *)(a1 + 11) = 0LL;
*(_QWORD *)(a1 + 13) = 0LL;
*(_QWORD *)(a1 + 15) = 0LL;
*(_QWORD *)(a1 + 17) = 0LL;
result = (void *)double_malloc_or_die(a2);
v5 = (int)*a1;
*((_QWORD *)a1 + 10) = result;
if ( (int)v5 > 0 )
result = memset(result, 0, 8 * v5);
*((_QWORD *)a1 + 11) = 0LL;
return result;
}

original_code:
void therm_ctl_init(therm_ctl_t* ptherm, int smoothing_window_size,
 int therm_ntp, int force_therm)
{
 int k;
 ptherm->smoothing_window_size = smoothing_window_size;
 ptherm->therm_ntp = therm_ntp;
 ptherm->force_therm = force_therm;
 ptherm->sweepi = 0;
 ptherm->H_lagger = 0.0;
 ptherm->ssH = 0.0;
 ptherm->smoothed_H = 0.0;
 ptherm->smoothed_Hm1 = 0.0;
 ptherm->smoothed_Hm2 = 0.0;
 ptherm->smoothed_H_diff1 = 0.0;
 ptherm->smoothed_H_diff2 = 0.0;
 ptherm->smoothing_scale = 0;
 ptherm->H_window = double_malloc_or_die(ptherm->smoothing_window_size);
 for (k = 0; k < ptherm->smoothing_window_size; k++)
  ptherm->H_window[k] = 0.0;
 ptherm->ntp = 0;
 ptherm->thermalized = 0;
}

canonical_original_code:
void therm_ctl_init(struct _therm_ctl_t *ptherm, int smoothing_window_size, int therm_ntp, int force_therm)
{
 int k;
 ptherm->smoothing_window_size = smoothing_window_size;
 ptherm->therm_ntp = therm_ntp;
 ptherm->force_therm = force_therm;
 ptherm->sweepi = 0;
 ptherm->H_lagger = 0.0;
 ptherm->ssH = 0.0;
 ptherm->smoothed_H = 0.0;
 ptherm->smoothed_Hm1 = 0.0;
 ptherm->smoothed_Hm2 = 0.0;
 ptherm->smoothed_H_diff1 = 0.0;
 ptherm->smoothed_H_diff2 = 0.0;
 ptherm->smoothing_scale = 0;
 ptherm->H_window = double_malloc_or_die(ptherm->smoothing_window_size);
 for (k = 0; k < ptherm->smoothing_window_size; k++)
  ptherm->H_window[k] = 0.0;
 ptherm->ntp = 0;
 ptherm->thermalized = 0;
}

variable_types: struct _therm_ctl_t { int smoothing_window_size; int therm_ntp; int force_therm; int sweepi; double H_lagger; double ssH; double smoothed_H; double smoothed_Hm1; double smoothed_Hm2; double smoothed_H_diff1; double smoothed_H_diff2; int smoothing_scale; double *H_window; int ntp; int thermalized; } *


original_code:
void therm_ctl_update(therm_ctl_t* ptherm, double H)
{
 int idx = ptherm->sweepi % ptherm->smoothing_window_size;
 if (ptherm->thermalized)
  return;
 ptherm->sweepi++;
 ptherm->H_lagger = ptherm->H_window[idx];
 ptherm->H_window[idx] = H;
 ptherm->smoothed_H_diff1 = ptherm->smoothed_H - ptherm->smoothed_Hm1;
 ptherm->smoothed_H_diff2 = ptherm->smoothed_Hm1 - ptherm->smoothed_Hm2;
 ptherm->smoothed_Hm2 = ptherm->smoothed_Hm1;
 ptherm->smoothed_Hm1 = ptherm->smoothed_H;
 if (ptherm->sweepi < ptherm->smoothing_window_size) {
  ptherm->smoothed_H += H;
  ptherm->smoothing_scale++;
 }
 else {
  ptherm->smoothed_H -= ptherm->H_lagger;
  ptherm->smoothed_H += H;
 }
 ptherm->ssH = ptherm->smoothed_H / ptherm->smoothing_scale;
 if (ptherm->sweepi >= ptherm->smoothing_window_size) {
  if (ptherm->smoothed_H_diff1 * ptherm->smoothed_H_diff2 < 0.0) {
   ptherm->ntp++;
   if (ptherm->ntp >= ptherm->therm_ntp)
    ptherm->thermalized = 1;
  }
 }
 if (ptherm->sweepi == ptherm->force_therm)
  ptherm->thermalized = 1;
}

canonical_original_code:
void therm_ctl_update(struct _therm_ctl_t *ptherm, double H)
{
 int idx = ptherm->sweepi % ptherm->smoothing_window_size;
 if (ptherm->thermalized)
  return;
 ptherm->sweepi++;
 ptherm->H_lagger = ptherm->H_window[idx];
 ptherm->H_window[idx] = H;
 ptherm->smoothed_H_diff1 = ptherm->smoothed_H - ptherm->smoothed_Hm1;
 ptherm->smoothed_H_diff2 = ptherm->smoothed_Hm1 - ptherm->smoothed_Hm2;
 ptherm->smoothed_Hm2 = ptherm->smoothed_Hm1;
 ptherm->smoothed_Hm1 = ptherm->smoothed_H;
 if (ptherm->sweepi < ptherm->smoothing_window_size) {
  ptherm->smoothed_H += H;
  ptherm->smoothing_scale++;
 }
 else {
  ptherm->smoothed_H -= ptherm->H_lagger;
  ptherm->smoothed_H += H;
 }
 ptherm->ssH = ptherm->smoothed_H / ptherm->smoothing_scale;
 if (ptherm->sweepi >= ptherm->smoothing_window_size) {
  if (ptherm->smoothed_H_diff1 * ptherm->smoothed_H_diff2 < 0.0) {
   ptherm->ntp++;
   if (ptherm->ntp >= ptherm->therm_ntp)
    ptherm->thermalized = 1;
  }
 }
 if (ptherm->sweepi == ptherm->force_therm)
  ptherm->thermalized = 1;
}

variable_types: H double

variable_types: idx int

user_defined_types: struct _therm_ctl_t { int smoothing_window_size; int therm_ntp; int force_therm; int sweepi; double H_lagger; double ssH; double smoothed_H; double smoothed_Hm1; double smoothed_Hm2; double smoothed_H_diff1; double smoothed_H_diff2; int smoothing_scale; double *H_window; int ntp; int thermalized; }


decompiled_code:
void __fastcall therm_ctl_free(__int64 a1)
{
free(*(void **)(a1 + 80));
*(_QWORD *)(a1 + 80) = 0LL;
}

original_code:
void therm_ctl_free(therm_ctl_t* ptherm)
{
 free(ptherm->H_window);
 ptherm->H_window = 0;
}

canonical_original_code:
void therm_ctl_free(struct _therm_ctl_t *ptherm)
{
 free(ptherm->H_window);
 ptherm->H_window = 0;
}


decompiled_code:
int __fastcall print_points_and_cycles(int *a1)
{
return print_points_and_cycles_aux(a1, 0, -1, a1[3] + 1);
}

canonical_decompiled_code:
int __fastcall func1(int *a1)
{
return func0(a1, 0, -1, a1[3] + 1);
}

original_code:
void print_points_and_cycles(points_t* ppoints)
{
 print_points_and_cycles_aux(ppoints, 0, -1, ppoints->N+1);
}

canonical_original_code:
void print_points_and_cycles(struct _points_t *ppoints)
{
 print_points_and_cycles_aux(ppoints, 0, -1, ppoints->N+1);
}

variable_types: struct _points_t { struct _dims_t { int nx; int ny; int nz; } dims; int N; struct _point_t { struct _coord_t { int selfi; int selfj; int selfk; } c; struct _point_t *pfwd; struct _point_t *pbwd; int fwd_dsq; double fwd_d; struct _cycinfo_t { struct _cycinfo_t *pprev; struct _cycinfo_t *pnext; struct _point_t *psite; int cyclen; } *pcycinfo; int mark; } ***lattice; struct _point_t wormhole; struct _cycinfo_t *pcycinfo_list_head; struct _cycinfo_t *pcycinfo_list_tail; } *

user_defined_types: struct _points_t { struct _dims_t dims; int N; struct _point_t ***lattice; struct _point_t wormhole; struct _cycinfo_t *pcycinfo_list_head; struct _cycinfo_t *pcycinfo_list_tail; }

user_defined_types: struct _point_t { struct _coord_t c; struct _point_t *pfwd; struct _point_t *pbwd; int fwd_dsq; double fwd_d; struct _cycinfo_t *pcycinfo; int mark; }


decompiled_code:
int __fastcall print_points_and_cycles_min_max(int *a1, int a2, int a3)
{
return print_points_and_cycles_aux(a1, 1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func2(int *a1, int a2, int a3)
{
return func0(a1, 1, a2, a3);
}

original_code:
void print_points_and_cycles_min_max(points_t* ppoints,
 int min_ell, int max_ell)
{
 print_points_and_cycles_aux(ppoints, 1, min_ell, max_ell);
}

canonical_original_code:
void print_points_and_cycles_min_max(struct _points_t *ppoints, int min_ell, int max_ell)
{
 print_points_and_cycles_aux(ppoints, 1, min_ell, max_ell);
}

user_defined_types: struct _dims_t { int nx; int ny; int nz; }

user_defined_types: struct _coord_t { int selfi; int selfj; int selfk; }

user_defined_types: struct _cycinfo_t { struct _cycinfo_t *pprev; struct _cycinfo_t *pnext; struct _point_t *psite; int cyclen; }


decompiled_code:
__int64 get_urandom()
{
int v0; // eax
__int64 v1; // rdx
int v2; // eax
unsigned int v3; // er8
unsigned int v5; // ebx

if ( fd_3 == -1 )
{
fd_3 = open("/dev/urandom", 0);
if ( fd_3 < 0 )
{
perror("open");
fprintf(stderr, "Couldn't open %s.\n", "/dev/urandom");
exit(1);
}
}
v0 = bufpos_1;
if ( !bufpos_1 )
{
v5 = read(fd_3, buf_0, 0x2000uLL);
if ( v5 != 0x2000 )
{
perror("read");
fprintf(stderr, "Couldn't read %s.\n", "/dev/urandom");
fprintf(stderr, "Expected %d byte(s); got %d.\n", 0x2000LL, v5);
exit(1);
}
v0 = bufpos_1;
}
v1 = v0;
v2 = v0 + 1;
v3 = buf_0[v1];
if ( v2 > 2047 )
v2 = 0;
bufpos_1 = v2;
return v3;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
__int64 v1; // rdx
int v2; // eax
unsigned int v3; // er8
unsigned int v5; // ebx

if ( fd_3 == -1 )
{
fd_3 = open("/dev/urandom", 0);
if ( fd_3 < 0 )
{
perror("open");
fprintf(stderr, "Couldn't open %s.\n", "/dev/urandom");
exit(1);
}
}
v0 = bufpos_1;
if ( !bufpos_1 )
{
v5 = read(fd_3, buf_0, 0x2000uLL);
if ( v5 != 0x2000 )
{
perror("read");
fprintf(stderr, "Couldn't read %s.\n", "/dev/urandom");
fprintf(stderr, "Expected %d byte(s); got %d.\n", 0x2000LL, v5);
exit(1);
}
v0 = bufpos_1;
}
v1 = v0;
v2 = v0 + 1;
v3 = buf_0[v1];
if ( v2 > 2047 )
v2 = 0;
bufpos_1 = v2;
return v3;
}

original_code:
int get_urandom(void)
{
 static int fd = -1;
 static int buf[2048];
 static int bufpos = 0;
 static char * dev_name = "/dev/urandom";
 int bytes_wanted;
 int bytes_read;
 int rv;
 if (fd == -1) {
  fd = open(dev_name, 00);
  if (fd < 0) {
   perror("open");
   fprintf(stderr, "Couldn't open %s.\n", dev_name);
   exit(1);
  }
 }
 if (bufpos == 0) {
  bytes_wanted = 2048 * sizeof(int);
  bytes_read = read(fd, buf, 2048 * sizeof(int));
  if (bytes_read != bytes_wanted) {
   perror("read");
   fprintf(stderr, "Couldn't read %s.\n", dev_name);
   fprintf(stderr, "Expected %d byte(s); got %d.\n",
    bytes_wanted, bytes_read);
   exit(1);
  }
 }
 rv = buf[bufpos];
 bufpos++;
 if (bufpos >= 2048)
  bufpos = 0;
 return rv;
}

canonical_original_code:
int get_urandom()
{
 static int fd = -1;
 static int buf[2048];
 static int bufpos = 0;
 static char *dev_name = "/dev/urandom";
 int bytes_wanted;
 int bytes_read;
 int rv;
 if (fd == -1) {
  fd = open(dev_name, 00);
  if (fd < 0) {
   perror("open");
   fprintf(stderr, "Couldn't open %s.\n", dev_name);
   exit(1);
  }
 }
 if (bufpos == 0) {
  bytes_wanted = 2048 * sizeof(int);
  bytes_read = read(fd, buf, 2048 * sizeof(int));
  if (bytes_read != bytes_wanted) {
   perror("read");
   fprintf(stderr, "Couldn't read %s.\n", dev_name);
   fprintf(stderr, "Expected %d byte(s); got %d.\n",
    bytes_wanted, bytes_read);
   exit(1);
  }
 }
 rv = buf[bufpos];
 bufpos++;
 if (bufpos >= 2048)
  bufpos = 0;
 return rv;
}

variable_types: fd int

variable_types:
buf
int [2048]

variable_types: bufpos int

variable_types: rv int


decompiled_code:
double get_urandomu()
{
return (double)(int)get_urandom() * 2.328306436538696e-10;
}

original_code:
double get_urandomu(void)
{
 unsigned u = get_urandom();
 double numer = (double)u;
 double denom = 4294967296.0;
 return (double)(numer/denom);
}

canonical_original_code:
double get_urandomu()
{
 unsigned int u = get_urandom();
 double numer = (double)u;
 double denom = 4294967296.0;
 return (double)(numer/denom);
}

variable_types:
u
unsigned int

variable_types: numer double

variable_types: denom double


gasdev

decompiled_code:
double gasdev()
{
double v0; // xmm0_8
double v1; // xmm0_8
double v2; // xmm1_8
double v3; // xmm3_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm2_8
double result; // xmm0_8
double v8; // [rsp+0h] [rbp-20h]

if ( iset_1 )
{
iset_1 = 0;
result = *(double *)&gset_0;
}
else
{
do
{
do
{
v0 = get_mtrand_double();
v8 = v0 + v0 - 1.0;
v1 = get_mtrand_double();
v2 = v1 + v1 - 1.0;
v3 = v8 * v8 + v2 * v2;
}
while ( v3 >= 1.0 );
}
while ( v3 == 0.0 );
v4 = log(v3) * -2.0 / (v8 * v8 + v2 * v2);
if ( v4 < 0.0 )
v5 = sqrt(v4);
else
v5 = sqrt(v4);
iset_1 = 1;
v6 = v8 * v5;
result = v5 * v2;
gset_0 = *(_QWORD *)&v6;
}
return result;
}

canonical_decompiled_code:
double func0()
{
double v0; // xmm0_8
double v1; // xmm0_8
double v2; // xmm1_8
double v3; // xmm3_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm2_8
double result; // xmm0_8
double v8; // [rsp+0h] [rbp-20h]

if ( iset_1 )
{
iset_1 = 0;
result = *(double *)&gset_0;
}
else
{
do
{
do
{
v0 = get_mtrand_double();
v8 = v0 + v0 - 1.0;
v1 = get_mtrand_double();
v2 = v1 + v1 - 1.0;
v3 = v8 * v8 + v2 * v2;
}
while ( v3 >= 1.0 );
}
while ( v3 == 0.0 );
v4 = log(v3) * -2.0 / (v8 * v8 + v2 * v2);
if ( v4 < 0.0 )
v5 = sqrt(v4);
else
v5 = sqrt(v4);
iset_1 = 1;
v6 = v8 * v5;
result = v5 * v2;
gset_0 = *(_QWORD *)&v6;
}
return result;
}

original_code:
double gasdev(void)
{
 static int iset = 0;
 static double gset;
 double fac, rsq, v1, v2;
 if (iset == 0) {
  do {
   v1 = 2.0 * get_mtrand_double() - 1.0;
   v2 = 2.0 * get_mtrand_double() - 1.0;
   rsq = v1*v1 + v2*v2;
  } while (rsq >= 1.0 || rsq == 0.0);
  fac = sqrt(-2.0 * log(rsq) / rsq);
  gset = v1 * fac;
  iset = 1;
  return v2 * fac;
 }
 else {
  iset = 0;
  return gset;
 }
}

canonical_original_code:
double gasdev()
{
 static int iset = 0;
 static double gset;
 double fac; double rsq; double v1; double v2;
 if (iset == 0) {
  do {
   v1 = 2.0 * get_mtrand_double() - 1.0;
   v2 = 2.0 * get_mtrand_double() - 1.0;
   rsq = v1*v1 + v2*v2;
  } while (rsq >= 1.0 || rsq == 0.0);
  fac = sqrt(-2.0 * log(rsq) / rsq);
  gset = v1 * fac;
  iset = 1;
  return v2 * fac;
 }
 else {
  iset = 0;
  return gset;
 }
}

variable_types: iset int

variable_types: gset double

variable_types: fac double

variable_types: rsq double


decompiled_code:
double __fastcall gasdev_ms(double a1, double a2)
{
return gasdev() * a2 + a1;
}

canonical_decompiled_code:
double __fastcall func1(double a1, double a2)
{
return func0() * a2 + a1;
}

original_code:
double gasdev_ms(double mean, double stddev)
{
 return mean + stddev * gasdev();
}

variable_types: mean double

variable_types: stddev double


decompiled_code:
const char *__fastcall get_rng_type_desc(int a1)
{
__int64 v1; // rdi
const char *result; // rax

v1 = (unsigned int)(a1 - 1);
result = "Unrecognized RNG type";
if ( (unsigned int)v1 <= 3 )
result = CSWTCH_1[v1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
__int64 v1; // rdi
const char *result; // rax

v1 = (unsigned int)(a1 - 1);
result = "Unrecognized RNG type";
if ( (unsigned int)v1 <= 3 )
result = CSWTCH_1[v1];
return result;
}

original_code:
char* get_rng_type_desc(int rng_type)
{
 char* rv = "Unrecognized RNG type";
 switch (rng_type) {
 case 1: rv = "psdes"; break;
 case 2: rv = "/dev/urandom"; break;
 case 3: rv = "rand48"; break;
 case 4: rv = "Mersenne twister"; break;
 }
 return rv;
}

canonical_original_code:
char *get_rng_type_desc(int rng_type)
{
 char *rv = "Unrecognized RNG type";
 switch (rng_type) {
 case 1: rv = "psdes"; break;
 case 2: rv = "/dev/urandom"; break;
 case 3: rv = "rand48"; break;
 case 4: rv = "Mersenne twister"; break;
 }
 return rv;
}

variable_types:
rv
char *


decompiled_code:
__int64 __fastcall get_rho_L_pi(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v5; // ebx
__int64 result; // rax
double v7; // xmm0_8
__int64 v8; // rdx

v5 = *(_DWORD *)(a1 + 12);
result = pmt_get_cycle_counts_and_lmax(a1, a3, a4);
if ( v5 >= 0 )
{
result = 0LL;
v7 = 0.0;
do
{
v8 = result;
v7 = v7 + (double)((int)result * *(_DWORD *)(a3 + 4 * result));
*(double *)(a2 + 8 * result++) = 1.0 / (double)v5 * v7;
}
while ( v5 != v8 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v5; // ebx
__int64 result; // rax
double v7; // xmm0_8
__int64 v8; // rdx

v5 = *(_DWORD *)(a1 + 12);
result = pmt_get_cycle_counts_and_lmax(a1, a3, a4);
if ( v5 >= 0 )
{
result = 0LL;
v7 = 0.0;
do
{
v8 = result;
v7 = v7 + (double)((int)result * *(_DWORD *)(a3 + 4 * result));
*(double *)(a2 + 8 * result++) = 1.0 / (double)v5 * v7;
}
while ( v5 != v8 );
}
return result;
}

original_code:
void get_rho_L_pi(points_t* ppoints, double* rho, int* counts, int *plmax)
{
 int N = ppoints->N;
 double recip_N = 1.0 / N;
 int j;
 double rhoval;
 pmt_get_cycle_counts_and_lmax(ppoints, counts, plmax);
 rhoval = 0.0;
 for (j = 0; j <= N; j++) {
  rhoval += j * counts[j];
  rho[j] = rhoval * recip_N;
 }
}

canonical_original_code:
void get_rho_L_pi(struct _points_t *ppoints, double *rho, int *counts, int *plmax)
{
 int N = ppoints->N;
 double recip_N = 1.0 / N;
 int j;
 double rhoval;
 pmt_get_cycle_counts_and_lmax(ppoints, counts, plmax);
 rhoval = 0.0;
 for (j = 0; j <= N; j++) {
  rhoval += j * counts[j];
  rho[j] = rhoval * recip_N;
 }
}

variable_types:
rho
double *

variable_types:
counts
int *

variable_types:
plmax
int *

variable_types: N int

variable_types: j int

variable_types: rhoval double


decompiled_code:
int __fastcall compute_rho_infty(__int64 a1, double *a2, __int64 a3, int a4)
{
double v5; // xmm3_8
__int64 v7; // rcx
__int64 v8; // rax
double v9; // xmm2_8
__int64 v10; // rsi
double v11; // xmm0_8
bool v12; // cc
double v13; // xmm0_8
double v14; // xmm1_8
double v15; // xmm4_8
__int64 v16; // rax
double v18; // [rsp+8h] [rbp-30h]
double v19; // [rsp+8h] [rbp-30h]
double v20; // [rsp+18h] [rbp-20h]

v5 = (double)a4;
if ( a4 <= 0 )
{
v20 = (double)a4;
v19 = *a2 - 0.0 / v5;
LODWORD(v16) = printf("# rho_infty max dev = %11.7lf at k = %d\n", 0.0, 0LL);
v14 = v19;
v15 = *(double *)&LC1;
v5 = v20;
if ( a4 )
return v16;
}
else
{
v7 = (unsigned int)(a4 + 1);
v8 = 1LL;
v9 = 0.0;
v10 = 0LL;
do
{
v11 = a2[v8] - (double)(int)v8 / v5;
v12 = v11 <= v9;
v13 = fmax(v11, v9);
if ( !v12 )
v10 = (unsigned int)v8;
++v8;
v9 = v13;
}
while ( v7 != v8 );
v18 = a2[(int)v10] - (double)(int)v10 / v5;
printf("# rho_infty max dev = %11.7lf at k = %d\n", v13, v10);
v14 = v18;
v15 = *(double *)&LC1;
}
v16 = 0LL;
do
{
*(double *)(a1 + 8 * v16) = fmin(v15, (double)(int)v16 / v5 + v14);
++v16;
}
while ( a4 >= (int)v16 );
return v16;
}

original_code:
double compute_rho_infty(double* rho_fit, double* rho_avg, double* rho,
 int N, int verbose)
{
 int k;
 int maxk = 0;
 double dev;
 double maxdev = 0.0;
 double rho_finite_T;
 double rho_infty_T;
 for (k = 1; k <= N; k++) {
  dev = rho_avg[k] - (double)k/(double)N;
  if (dev > maxdev) {
   maxdev = dev;
   maxk = k;
  }
 }
 rho_finite_T = rho_avg[maxk] - (double)maxk/(double)N;
 rho_infty_T = 1.0 - rho_finite_T;
 printf("# rho_infty max dev = %11.7lf at k = %d\n", maxdev, maxk);
 for (k = 0; k <= N; k++) {
  rho_fit[k] = (double)k/(double)N + rho_finite_T;
  if (rho_fit[k] > 1.0)
   rho_fit[k] = 1.0;
 }
 return rho_infty_T;
}

canonical_original_code:
double compute_rho_infty(double *rho_fit, double *rho_avg, double *rho, int N, int verbose)
{
 int k;
 int maxk = 0;
 double dev;
 double maxdev = 0.0;
 double rho_finite_T;
 double rho_infty_T;
 for (k = 1; k <= N; k++) {
  dev = rho_avg[k] - (double)k/(double)N;
  if (dev > maxdev) {
   maxdev = dev;
   maxk = k;
  }
 }
 rho_finite_T = rho_avg[maxk] - (double)maxk/(double)N;
 rho_infty_T = 1.0 - rho_finite_T;
 printf("# rho_infty max dev = %11.7lf at k = %d\n", maxdev, maxk);
 for (k = 0; k <= N; k++) {
  rho_fit[k] = (double)k/(double)N + rho_finite_T;
  if (rho_fit[k] > 1.0)
   rho_fit[k] = 1.0;
 }
 return rho_infty_T;
}

variable_types: verbose int

variable_types: k int

variable_types: maxk int

variable_types: dev double

variable_types: maxdev double


decompiled_code:
const char *__fastcall worm_move_to_desc(int a1)
{
const char *result; // rax

if ( a1 == 444 )
return "head swap";
if ( a1 > 444 )
{
result = (const char *)&unk_50;
if ( a1 == 555 )
result = "tail swap";
}
else
{
result = "open";
if ( a1 != 222 )
{
result = (const char *)&unk_50;
if ( a1 == 333 )
result = "close";
}
}
return result;
}

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

if ( a1 == 444 )
return "head swap";
if ( a1 > 444 )
{
result = (const char *)&unk_50;
if ( a1 == 555 )
result = "tail swap";
}
else
{
result = "open";
if ( a1 != 222 )
{
result = (const char *)&unk_50;
if ( a1 == 333 )
result = "close";
}
}
return result;
}

original_code:
char* worm_move_to_desc(int worm_move)
{
 switch (worm_move) {
 case 222: return "open"; break;
 case 333: return "close"; break;
 case 444: return "head swap"; break;
 case 555: return "tail swap"; break;
 default: return "???"; break;
 }
}

canonical_original_code:
char *worm_move_to_desc(int worm_move)
{
 switch (worm_move) {
 case 222: return "open"; break;
 case 333: return "close"; break;
 case 444: return "head swap"; break;
 case 555: return "tail swap"; break;
 default: return "???"; break;
 }
}


repo: johnkerl/percolation

decompiled_code:
__int64 __fastcall allocate_rgb_matrix(int a1, int a2, char a3, char a4, char a5)
{
__int64 v8; // r14
__int64 v9; // rax
__int64 v10; // rdi
__int64 v11; // rax
int v12; // edx
_BYTE *v13; // rax
__int64 v15; // [rsp+0h] [rbp-48h]

if ( a1 <= 0 || a2 <= 0 )
{
fprintf(
stderr,
"allocate_rgb_matrix: dimensions must be positive; got (%d,%d).\n",
(unsigned int)a1,
(unsigned int)a2);
exit(1);
}
v8 = 0LL;
v15 = malloc_or_die(16LL);
*(_DWORD *)(v15 + 4) = a2;
*(_DWORD *)v15 = a1;
v9 = malloc_or_die((unsigned int)(8 * a1));
*(_QWORD *)(v15 + 8) = v9;
v10 = v9;
do
{
v11 = malloc_or_die((unsigned int)(3 * a2));
v12 = 0;
*(_QWORD *)(v10 + 8 * v8) = v11;
v10 = *(_QWORD *)(v15 + 8);
v13 = *(_BYTE **)(v10 + 8 * v8);
do
{
++v12;
*v13 = a3;
v13 += 3;
*(v13 - 2) = a4;
*(v13 - 1) = a5;
}
while ( a2 > v12 );
++v8;
}
while ( a1 > (int)v8 );
return v15;
}

original_code:
rgb_matrix_t* allocate_rgb_matrix(int height, int width,
 int r_fill, int g_fill, int b_fill)
{
 rgb_matrix_t* pmatrix;
 int i, j;
 if ((height < 1) || (width < 1)) {
  fprintf(stderr,
  "allocate_rgb_matrix:  dimensions must be positive; got (%d,%d).\n",
   height, width);
  exit(1);
 }
 pmatrix = (rgb_matrix_t *)malloc_or_die(sizeof(rgb_matrix_t));
 pmatrix->height = height;
 pmatrix->width = width;
 pmatrix->data = (rgb_pixel_t **)malloc_or_die(
  height * sizeof(rgb_pixel_t *));
 for (i = 0; i < height; i++) {
  pmatrix->data[i] = (rgb_pixel_t*)malloc_or_die(
   width * sizeof(rgb_pixel_t));
  for (j = 0; j < width; j++) {
   pmatrix->data[i][j].r = r_fill;
   pmatrix->data[i][j].g = g_fill;
   pmatrix->data[i][j].b = b_fill;
  }
 }
 return pmatrix;
}

canonical_original_code:
struct _rgb_matrix_t *allocate_rgb_matrix(int height, int width, int r_fill, int g_fill, int b_fill)
{
 struct _rgb_matrix_t *pmatrix;
 int i; int j;
 if ((height < 1) || (width < 1)) {
  fprintf(stderr,
  "allocate_rgb_matrix:  dimensions must be positive; got (%d,%d).\n",
   height, width);
  exit(1);
 }
 pmatrix = (struct _rgb_matrix_t *)malloc_or_die(sizeof(rgb_matrix_t));
 pmatrix->height = height;
 pmatrix->width = width;
 pmatrix->data = (struct _rgb_pixel_t **)malloc_or_die(
  height * sizeof(struct _rgb_pixel_t *));
 for (i = 0; i < height; i++) {
  pmatrix->data[i] = (struct _rgb_pixel_t *)malloc_or_die(
   width * sizeof(rgb_pixel_t));
  for (j = 0; j < width; j++) {
   pmatrix->data[i][j].r = r_fill;
   pmatrix->data[i][j].g = g_fill;
   pmatrix->data[i][j].b = b_fill;
  }
 }
 return pmatrix;
}

variable_types: height int

variable_types: width int

variable_types: struct _rgb_matrix_t { int height; int width; struct _rgb_pixel_t { unsigned char r; unsigned char g; unsigned char b; } **data; } *

variable_types: i int

user_defined_types: struct _rgb_matrix_t { int height; int width; struct _rgb_pixel_t **data; }


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

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

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

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

original_code:
void free_rgb_matrix(rgb_matrix_t* prgb_matrix)
{
 int i;
 for (i = 0; i < prgb_matrix->height; i++)
  free(prgb_matrix->data[i]);
 free(prgb_matrix->data);
 free(prgb_matrix);
}

canonical_original_code:
void free_rgb_matrix(struct _rgb_matrix_t *prgb_matrix)
{
 int i;
 for (i = 0; i < prgb_matrix->height; i++)
  free(prgb_matrix->data[i]);
 free(prgb_matrix->data);
 free(prgb_matrix);
}

user_defined_types: struct _rgb_pixel_t { unsigned char r; unsigned char g; unsigned char b; }


decompiled_code:
__int64 __fastcall psdes_hash_64(int *a1, int *a2)
{
int v3; // er11
__int64 v4; // rdi
int v5; // eax
int v6; // ecx
int v7; // er8
unsigned int v8; // ecx
__int64 result; // rax

v3 = *a1;
v4 = 0LL;
v5 = 1259289432;
v6 = -1163302777;
while ( 1 )
{
v7 = *a2;
++v4;
v8 = *a2 ^ v6;
result = v3 ^ ((v5 ^ __ROL4__((unsigned __int16)v8 * (unsigned __int16)v8 - 1 - HIWORD(v8) * HIWORD(v8), 16))
+ (unsigned __int16)v8 * HIWORD(v8));
*a2 = result;
*a1 = v7;
if ( v4 == 4 )
break;
v6 = c1_1[v4];
v5 = c2_0[v4];
v3 = v7;
}
return result;
}

original_code:
void psdes_hash_64(
 unsigned * pword0,
 unsigned * pword1)
{
 unsigned i;
 unsigned iswap, ia, iah, ial, ib, ic;
 static unsigned c1[4] = {
  0xbaa96887, 0x1e17d32c, 0x03bcdc3c, 0x0f33d1b2 };
 static unsigned c2[4] = {
  0x4b0f3b58, 0xe874f0c3, 0x6955c5a6, 0x55a7ca46 };
 for (i = 0; i < 4; i++) {
  iswap = *pword1;
  ia = iswap ^ c1[i];
  ial = ia & 0xffff;
  iah = ia >> 16;
  ib = ial * ial + ~(iah * iah);
  ic = (ib >> 16) | ((ib & 0xffff) << 16);
  *pword1 = (*pword0) ^ ((ic ^ c2[i]) + ial * iah);
  *pword0 = iswap;
 }
}

canonical_original_code:
void psdes_hash_64(unsigned int *pword0, unsigned int *pword1)
{
 unsigned int i;
 unsigned int iswap; unsigned int ia; unsigned int iah; unsigned int ial; unsigned int ib; unsigned int ic;
 static unsigned int c1[4] = {
  0xbaa96887, 0x1e17d32c, 0x03bcdc3c, 0x0f33d1b2 };
 static unsigned int c2[4] = {
  0x4b0f3b58, 0xe874f0c3, 0x6955c5a6, 0x55a7ca46 };
 for (i = 0; i < 4; i++) {
  iswap = *pword1;
  ia = iswap ^ c1[i];
  ial = ia & 0xffff;
  iah = ia >> 16;
  ib = ial * ial + ~(iah * iah);
  ic = (ib >> 16) | ((ib & 0xffff) << 16);
  *pword1 = (*pword0) ^ ((ic ^ c2[i]) + ial * iah);
  *pword0 = iswap;
 }
}

variable_types:
i
unsigned int

variable_types:
iswap
unsigned int

variable_types:
ia
unsigned int

variable_types:
iah
unsigned int

variable_types:
ial
unsigned int

variable_types:
ib
unsigned int

variable_types:
ic
unsigned int