httpWaitForContent

decompiled_code:
void __fastcall httpWaitForContent(__int64 a1)
{
pthread_mutex_t *v1; // rbp

if ( Initialised )
{
if ( a1 )
{
v1 = *(pthread_mutex_t **)(a1 + 56);
pthread_mutex_lock(v1);
pthread_mutex_unlock(v1);
free(v1);
*(_QWORD *)(a1 + 56) = 0LL;
}
else
{
httpError = -11LL;
}
}
else
{
httpError = -2LL;
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
pthread_mutex_t *v1; // rbp

if ( Initialised )
{
if ( a1 )
{
v1 = *(pthread_mutex_t **)(a1 + 56);
pthread_mutex_lock(v1);
pthread_mutex_unlock(v1);
free(v1);
*(_QWORD *)(a1 + 56) = 0LL;
}
else
{
httpError = -11LL;
}
}
else
{
httpError = -2LL;
}
}

original_code:
void httpWaitForContent(Response *resp)
{
 ContentInternals *Intern;
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (resp == ((void *)0))
 {
  httpError = -11;
  return;
 }
 Intern = (ContentInternals *)resp->Private;
 pthread_mutex_lock(&Intern->mutex);
 pthread_mutex_unlock(&Intern->mutex);
 free(Intern);
 resp->Private = ((void *)0);
}

canonical_original_code:
void httpWaitForContent(struct _Response *resp)
{
 struct _ContentInternals *Intern;
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (resp == ((void *)0))
 {
  httpError = -11;
  return;
 }
 Intern = (struct _ContentInternals *)resp->Private;
 pthread_mutex_lock(&Intern->mutex);
 pthread_mutex_unlock(&Intern->mutex);
 free(Intern);
 resp->Private = ((void *)0);
}


httpGetError

repo: DX-MON/libHTTP

decompiled_code:
__int64 httpGetError()
{
return httpError;
}

canonical_decompiled_code:
__int64 func0()
{
return httpError;
}

original_code:
int httpGetError()
{
 int ret = httpError;
 return ret;
}

variable_types: ret int

return_type: int


httpResetError

decompiled_code:
void httpResetError()
{
httpError = 0LL;
}

canonical_decompiled_code:
void func1()
{
httpError = 0LL;
}

original_code:
void httpResetError()
{
 httpError = 0;
}

return_type: void


httpGetErrorText

decompiled_code:
char *httpGetErrorText()
{
unsigned int v0; // ebx
char *v1; // rbp
unsigned int *v3; // r12
char *v4; // r13
int v5; // eax

v0 = httpGetError();
httpResetError();
v1 = "0; No Error.";
if ( v0 )
{
v3 = (unsigned int *)_errno_location();
v4 = strerror(*v3);
v5 = snprintf(0LL, 0LL, "%i; Socket error: (%i) \"%s\"", v0, *v3, v4);
v1 = (char *)malloc(v5 + 1);
sprintf(v1, "%i; Socket error: (%i) \"%s\"", v0, *v3, v4);
*v3 = 0;
}
return v1;
}

canonical_decompiled_code:
char *func2()
{
unsigned int v0; // ebx
char *v1; // rbp
unsigned int *v3; // r12
char *v4; // r13
int v5; // eax

v0 = func0();
func1();
v1 = "0; No Error.";
if ( v0 )
{
v3 = (unsigned int *)_errno_location();
v4 = strerror(*v3);
v5 = snprintf(0LL, 0LL, "%i; Socket error: (%i) \"%s\"", v0, *v3, v4);
v1 = (char *)malloc(v5 + 1);
sprintf(v1, "%i; Socket error: (%i) \"%s\"", v0, *v3, v4);
*v3 = 0;
}
return v1;
}

original_code:
char *httpGetErrorText()
{
 const char *perr;
 int err = httpGetError(), retLen;
 char *ret;
 httpResetError();
 if (err == 0)
  return "0; No Error.";
 perr = strerror((*__errno_location ()));
 retLen = snprintf(((void *)0), 0, "%i; Socket error: (%i) \"%s\"", err, (*__errno_location ()), perr) + 1;
 ret = (char *)malloc(retLen);
 sprintf(ret, "%i; Socket error: (%i) \"%s\"", err, (*__errno_location ()), perr);
 (*__errno_location ()) = 0;
 return ret;
}

canonical_original_code:
char *httpGetErrorText()
{
 char *perr;
 int err = httpGetError(); int retLen;
 char *ret;
 httpResetError();
 if (err == 0)
  return "0; No Error.";
 perr = strerror((*__errno_location ()));
 retLen = snprintf(((void *)0), 0, "%i; Socket error: (%i) \"%s\"", err, (*__errno_location ()), perr) + 1;
 ret = (char *)malloc(retLen);
 sprintf(ret, "%i; Socket error: (%i) \"%s\"", err, (*__errno_location ()), perr);
 (*__errno_location ()) = 0;
 return ret;
}

variable_types:
perr
char *

variable_types: err int

variable_types: retLen int

variable_types:
ret
char *

return_type: char *


IsDigit

decompiled_code:
bool __fastcall IsDigit(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

canonical_decompiled_code:
bool __fastcall func0(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

original_code:
uint8_t IsDigit(char x)
{
 x -= '0';
 if (x >= 0 && x <= 9)
  return 1;
 return 0;
}

canonical_original_code:
unsigned char IsDigit(char x)
{
 x -= '0';
 if (x >= 0 && x <= 9)
  return 1;
 return 0;
}

variable_types: x char

return_type: unsigned char


GetNextDigit

decompiled_code:
char __fastcall GetNextDigit(int *a1, char *a2)
{
int v2; // eax
int v3; // eax

LOBYTE(v2) = IsDigit(*a2);
if ( (_BYTE)v2 == 1 )
{
v3 = 10 * *a1;
*a1 = v3;
v2 = v3 + *a2 - 48;
*a1 = v2;
}
return v2;
}

canonical_decompiled_code:
char __fastcall func1(int *a1, char *a2)
{
int v2; // eax
int v3; // eax

LOBYTE(v2) = func0(*a2);
if ( (_BYTE)v2 == 1 )
{
v3 = 10 * *a1;
*a1 = v3;
v2 = v3 + *a2 - 48;
*a1 = v2;
}
return v2;
}

original_code:
void GetNextDigit(int *dest, char *src)
{
 if (IsDigit(src[0]) == 1)
 {
  *dest *= 10;
  *dest += src[0] - '0';
 }
}

variable_types:
dest
int *

variable_types:
src
char *


ProtoError

decompiled_code:
__int64 ProtoError()
{
httpError = -9LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
httpError = -9LL;
return 0LL;
}

original_code:
uint8_t ProtoError()
{
 httpError = -9;
 return 0;
}

canonical_original_code:
unsigned char ProtoError()
{
 httpError = -9;
 return 0;
}


HeaderProtoError

decompiled_code:
__int64 HeaderProtoError()
{
httpError = -10LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
httpError = -10LL;
return 0LL;
}

original_code:
uint8_t HeaderProtoError()
{
 httpError = -10;
 return 0;
}

canonical_original_code:
unsigned char HeaderProtoError()
{
 httpError = -10;
 return 0;
}


NewlineCheck

decompiled_code:
__int64 __fastcall NewlineCheck(const void *a1)
{
int v1; // edx
__int64 result; // rax

v1 = memcmp(a1, &unk_7F4, 2uLL);
result = 1LL;
if ( v1 )
result = HeaderProtoError();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const void *a1)
{
int v1; // edx
__int64 result; // rax

v1 = memcmp(a1, &unk_7F4, 2uLL);
result = 1LL;
if ( v1 )
result = func3();
return result;
}

original_code:
uint8_t NewlineCheck(const char *buff)
{
 if (memcmp(buff , "\r\n", 2) != 0)
  return HeaderProtoError();
 return 1;
}

canonical_original_code:
unsigned char NewlineCheck(char *buff)
{
 if (memcmp(buff , "\r\n", 2) != 0)
  return HeaderProtoError();
 return 1;
}

variable_types:
buff
char *


tryReadHeaders

decompiled_code:
__int64 __fastcall tryReadHeaders(__int64 a1, __int64 a2)
{
__int64 result; // rax
bool v5; // cf
bool v6; // zf
char *v7; // rsi
unsigned __int64 v8; // rdi
__int64 v9; // rcx
int v10; // er12
char v11; // r13
char v12; // r13
__int64 v13; // r13
_BYTE *v14; // rax
int v15; // er14
_BYTE *v16; // r13
int v17; // er14
__int64 i; // r15
int v19; // er14
char v20; // r15
void *v21; // rdi
size_t v22; // r14
void *v23; // rax
char v24; // r14
_QWORD *v25; // rax
char v26; // r15
char v27; // [rsp+0h] [rbp-58h]
int v28[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 5LL, v28);
if ( (_BYTE)result )
{
result = 0LL;
v5 = v28[0] < 5u;
v6 = v28[0] == 5;
if ( v28[0] == 5 )
{
v7 = &buff_0;
v8 = (unsigned __int64)"HTTP/";
v9 = 5LL;
do
{
if ( !v9 )
break;
v5 = (unsigned __int8)*v7 < *(_BYTE *)v8;
v6 = *v7++ == *(_BYTE *)v8++;
--v9;
}
while ( v6 );
v10 = (char)((!v5 && !v6) - v5);
if ( (!v5 && !v6) == v5 )
{
do
{
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( !(_BYTE)result )
return result;
if ( v28[0] != 1 )
return 0LL;
v7 = &buff_0;
GetNextDigit((int *)a2, &buff_0);
v11 = buff_0;
v8 = (unsigned int)buff_0;
}
while ( IsDigit(buff_0) );
if ( v11 != 46 )
goto LABEL_15;
do
{
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( !(_BYTE)result )
return result;
if ( v28[0] != 1 )
return 0LL;
v7 = &buff_0;
GetNextDigit((int *)(a2 + 4), &buff_0);
v12 = buff_0;
v8 = (unsigned int)buff_0;
}
while ( IsDigit(buff_0) );
if ( v12 != 32 )
goto LABEL_15;
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 3LL, v28);
if ( (_BYTE)result )
{
result = 0LL;
if ( v28[0] == 3 )
{
byte_7F2 = 0;
*(_DWORD *)(a2 + 8) = atoi(&buff_0);
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( (_BYTE)result )
{
result = 0LL;
if ( v28[0] == 1 )
{
*(_QWORD *)(a2 + 16) = malloc(1uLL);
v13 = 0LL;
do
{
v15 = v13;
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( !(_BYTE)result )
return result;
if ( v28[0] != 1 )
return 0LL;
if ( buff_0 == 13 )
break;
if ( buff_0 == 10 )
break;
v14 = realloc(*(void **)(a2 + 16), v13 + 2);
*(_QWORD *)(a2 + 16) = v14;
v14[v13] = buff_0;
v15 = ++v13;
if ( buff_0 == 13 )
break;
}
while ( buff_0 != 10 );
*(_BYTE *)(*(_QWORD *)(a2 + 16) + v15) = 0;
result = tryRecv(*(unsigned int *)(a1 + 24), &unk_7F0, 1LL, v28);
if ( (_BYTE)result )
{
result = 0LL;
if ( v28[0] == 1 )
{
result = NewlineCheck(&buff_0);
if ( (_BYTE)result )
{
*(_QWORD *)(a2 + 24) = malloc(0LL);
LABEL_33:
v16 = malloc(1uLL);
*v16 = 0;
v17 = v10;
while ( 1 )
{
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( !(_BYTE)result )
return result;
if ( v28[0] != 1 )
return 0LL;
v26 = buff_0;
if ( (unsigned __int8)buff_0 > 0x3Au )
{
v27 = buff_0 != 13 && buff_0 != 10;
if ( !v27 )
continue;
}
else
{
v27 = ((0x400000000002400uLL >> buff_0) ^ 1) & 1;
if ( buff_0 == 10 || buff_0 == 13 )
goto LABEL_78;
}
v16 = realloc(v16, v17 + 2);
v16[v17++] = v26;
LABEL_78:
if ( !v27 )
{
v16[v17] = 0;
if ( v26 == 13 )
{
result = tryRecv(*(unsigned int *)(a1 + 24), &unk_7F0, 1LL, v28);
if ( (_BYTE)result )
{
result = 0LL;
if ( v28[0] == 1 )
{
result = NewlineCheck(&buff_0);
if ( (_BYTE)result )
{
httpGetContentAsync(a1, a2);
result = 1LL;
}
}
}
}
else if ( !v17 && v26 == 10 )
{
free(v16);
result = HeaderProtoError();
}
else if ( !strcasecmp(v16, "Content-Length:") )
{
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( (_BYTE)result )
{
if ( v28[0] == 1 )
{
v16 = realloc(v16, v17 + 2);
v16[v17] = buff_0;
v19 = v17 + 1;
while ( 1 )
{
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( !(_BYTE)result )
break;
if ( v28[0] != 1 )
return 0LL;
v20 = buff_0;
if ( IsDigit(buff_0) )
{
v16 = realloc(v16, v19 + 2);
v16[v19++] = v20;
}
GetNextDigit((int *)(a2 + 48), &buff_0);
if ( !IsDigit(buff_0) )
{
v16[v19] = 0;
v21 = *(void **)(a2 + 40);
if ( v21 )
free(v21);
v22 = *(_DWORD *)(a2 + 48) + 1;
v23 = malloc(v22);
*(_QWORD *)(a2 + 40) = v23;
memset(v23, 0, v22);
LABEL_63:
v25 = realloc(*(void **)(a2 + 24), 8LL * (*(_DWORD *)(a2 + 32) + 1));
*(_QWORD *)(a2 + 24) = v25;
v25[(*(_DWORD *)(a2 + 32))++] = v16;
result = tryRecv(*(unsigned int *)(a1 + 24), &unk_7F0, 1LL, v28);
if ( (_BYTE)result )
{
if ( v28[0] == 1 )
{
result = NewlineCheck(&buff_0);
if ( (_BYTE)result )
goto LABEL_33;
}
else
{
result = 0LL;
}
}
return result;
}
}
}
else
{
result = 0LL;
}
}
}
else
{
if ( !strcasecmp(v16, "Transfer-Encoding:") )
*(_BYTE *)(a2 + 64) = 1;
for ( i = v17; ; ++i )
{
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( !(_BYTE)result )
break;
if ( v28[0] != 1 )
return 0LL;
v24 = buff_0;
if ( buff_0 == 13 || buff_0 == 10 )
{
v16[(int)i] = 0;
goto LABEL_63;
}
v16 = realloc(v16, i + 2);
v16[i] = v24;
}
}
return result;
}
}
}
}
}
}
}
}
}
}
else
{
LABEL_15:
result = ProtoError(v8, v7);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 result; // rax
bool v5; // cf
bool v6; // zf
char *v7; // rsi
unsigned __int64 v8; // rdi
__int64 v9; // rcx
int v10; // er12
char v11; // r13
char v12; // r13
__int64 v13; // r13
_BYTE *v14; // rax
int v15; // er14
_BYTE *v16; // r13
int v17; // er14
__int64 i; // r15
int v19; // er14
char v20; // r15
void *v21; // rdi
size_t v22; // r14
void *v23; // rax
char v24; // r14
_QWORD *v25; // rax
char v26; // r15
char v27; // [rsp+0h] [rbp-58h]
int v28[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 5LL, v28);
if ( (_BYTE)result )
{
result = 0LL;
v5 = v28[0] < 5u;
v6 = v28[0] == 5;
if ( v28[0] == 5 )
{
v7 = &buff_0;
v8 = (unsigned __int64)"HTTP/";
v9 = 5LL;
do
{
if ( !v9 )
break;
v5 = (unsigned __int8)*v7 < *(_BYTE *)v8;
v6 = *v7++ == *(_BYTE *)v8++;
--v9;
}
while ( v6 );
v10 = (char)((!v5 && !v6) - v5);
if ( (!v5 && !v6) == v5 )
{
do
{
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( !(_BYTE)result )
return result;
if ( v28[0] != 1 )
return 0LL;
v7 = &buff_0;
func1((int *)a2, &buff_0);
v11 = buff_0;
v8 = (unsigned int)buff_0;
}
while ( func0(buff_0) );
if ( v11 != 46 )
goto LABEL_15;
do
{
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( !(_BYTE)result )
return result;
if ( v28[0] != 1 )
return 0LL;
v7 = &buff_0;
func1((int *)(a2 + 4), &buff_0);
v12 = buff_0;
v8 = (unsigned int)buff_0;
}
while ( func0(buff_0) );
if ( v12 != 32 )
goto LABEL_15;
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 3LL, v28);
if ( (_BYTE)result )
{
result = 0LL;
if ( v28[0] == 3 )
{
byte_7F2 = 0;
*(_DWORD *)(a2 + 8) = atoi(&buff_0);
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( (_BYTE)result )
{
result = 0LL;
if ( v28[0] == 1 )
{
*(_QWORD *)(a2 + 16) = malloc(1uLL);
v13 = 0LL;
do
{
v15 = v13;
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( !(_BYTE)result )
return result;
if ( v28[0] != 1 )
return 0LL;
if ( buff_0 == 13 )
break;
if ( buff_0 == 10 )
break;
v14 = realloc(*(void **)(a2 + 16), v13 + 2);
*(_QWORD *)(a2 + 16) = v14;
v14[v13] = buff_0;
v15 = ++v13;
if ( buff_0 == 13 )
break;
}
while ( buff_0 != 10 );
*(_BYTE *)(*(_QWORD *)(a2 + 16) + v15) = 0;
result = tryRecv(*(unsigned int *)(a1 + 24), &unk_7F0, 1LL, v28);
if ( (_BYTE)result )
{
result = 0LL;
if ( v28[0] == 1 )
{
result = func4(&buff_0);
if ( (_BYTE)result )
{
*(_QWORD *)(a2 + 24) = malloc(0LL);
LABEL_33:
v16 = malloc(1uLL);
*v16 = 0;
v17 = v10;
while ( 1 )
{
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( !(_BYTE)result )
return result;
if ( v28[0] != 1 )
return 0LL;
v26 = buff_0;
if ( (unsigned __int8)buff_0 > 0x3Au )
{
v27 = buff_0 != 13 && buff_0 != 10;
if ( !v27 )
continue;
}
else
{
v27 = ((0x400000000002400uLL >> buff_0) ^ 1) & 1;
if ( buff_0 == 10 || buff_0 == 13 )
goto LABEL_78;
}
v16 = realloc(v16, v17 + 2);
v16[v17++] = v26;
LABEL_78:
if ( !v27 )
{
v16[v17] = 0;
if ( v26 == 13 )
{
result = tryRecv(*(unsigned int *)(a1 + 24), &unk_7F0, 1LL, v28);
if ( (_BYTE)result )
{
result = 0LL;
if ( v28[0] == 1 )
{
result = func4(&buff_0);
if ( (_BYTE)result )
{
httpGetContentAsync(a1, a2);
result = 1LL;
}
}
}
}
else if ( !v17 && v26 == 10 )
{
free(v16);
result = func3();
}
else if ( !strcasecmp(v16, "Content-Length:") )
{
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( (_BYTE)result )
{
if ( v28[0] == 1 )
{
v16 = realloc(v16, v17 + 2);
v16[v17] = buff_0;
v19 = v17 + 1;
while ( 1 )
{
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( !(_BYTE)result )
break;
if ( v28[0] != 1 )
return 0LL;
v20 = buff_0;
if ( func0(buff_0) )
{
v16 = realloc(v16, v19 + 2);
v16[v19++] = v20;
}
func1((int *)(a2 + 48), &buff_0);
if ( !func0(buff_0) )
{
v16[v19] = 0;
v21 = *(void **)(a2 + 40);
if ( v21 )
free(v21);
v22 = *(_DWORD *)(a2 + 48) + 1;
v23 = malloc(v22);
*(_QWORD *)(a2 + 40) = v23;
memset(v23, 0, v22);
LABEL_63:
v25 = realloc(*(void **)(a2 + 24), 8LL * (*(_DWORD *)(a2 + 32) + 1));
*(_QWORD *)(a2 + 24) = v25;
v25[(*(_DWORD *)(a2 + 32))++] = v16;
result = tryRecv(*(unsigned int *)(a1 + 24), &unk_7F0, 1LL, v28);
if ( (_BYTE)result )
{
if ( v28[0] == 1 )
{
result = func4(&buff_0);
if ( (_BYTE)result )
goto LABEL_33;
}
else
{
result = 0LL;
}
}
return result;
}
}
}
else
{
result = 0LL;
}
}
}
else
{
if ( !strcasecmp(v16, "Transfer-Encoding:") )
*(_BYTE *)(a2 + 64) = 1;
for ( i = v17; ; ++i )
{
result = tryRecv(*(unsigned int *)(a1 + 24), &buff_0, 1LL, v28);
if ( !(_BYTE)result )
break;
if ( v28[0] != 1 )
return 0LL;
v24 = buff_0;
if ( buff_0 == 13 || buff_0 == 10 )
{
v16[(int)i] = 0;
goto LABEL_63;
}
v16 = realloc(v16, i + 2);
v16[i] = v24;
}
}
return result;
}
}
}
}
}
}
}
}
}
}
else
{
LABEL_15:
result = func2(v8, v7);
}
}
}
return result;
}

original_code:
uint8_t tryReadHeaders(Address *URL, Response *ret)
{
 uint32_t recved;
 int rtl;
 static char buff[5] = {0};
 if (!tryRecv(URL->Socket, buff, 5, &recved) || recved != 5)
  return 0;
 if (strncmp(buff, "HTTP/", 5) != 0)
  return ProtoError();
 do
 {
  if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
   return 0;
  GetNextDigit(&ret->HTTPMajorVer, buff);
 }
 while (IsDigit(buff[0]) == 1);
 if (buff[0] != '.')
  return ProtoError();
 do
 {
  if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
   return 0;
  GetNextDigit(&ret->HTTPMinorVer, buff);
 }
 while (IsDigit(buff[0]) == 1);
 if (buff[0] != ' ')
  return ProtoError();
 if (!tryRecv(URL->Socket, buff, 3, &recved) || recved != 3)
  return 0;
 buff[3] = 0;
 ret->ResponceCode = atoi(buff);
 if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
  return 0;
 ret->ResponceText = (char *)malloc(1);
 rtl = 0;
 do
 {
  if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
   return 0;
  if (buff[0] != '\r' && buff[0] != '\n')
  {
   ret->ResponceText = (char *)realloc(ret->ResponceText, rtl + 2);
   ret->ResponceText[rtl] = buff[0];
   rtl++;
  }
 }
 while (buff[0] != '\r' && buff[0] != '\n');
 ret->ResponceText[rtl] = 0;
 if (!tryRecv(URL->Socket, buff + 1, 1, &recved) || recved != 1)
  return 0;
 if (!NewlineCheck(buff))
  return 0;
 ret->Headers = malloc(0);
 while (1)
 {
  char *Header = malloc(1);
  int lenHeader = 0;
  Header[0] = 0;
  do
  {
   if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
    return 0;
   if (buff[0] != '\r' && buff[0] != '\n')
   {
    Header = realloc(Header, lenHeader + 2);
    Header[lenHeader] = buff[0];
    lenHeader++;
   }
  }
  while (buff[0] != ':' && buff[0] != '\r' && buff[0] != '\n');
  Header[lenHeader] = 0;
  if (buff[0] == '\r' || buff[0] == '\n' && lenHeader == 0)
  {
   if (buff[0] == '\n')
   {
    free(Header);
    return HeaderProtoError();
   }
   if (!tryRecv(URL->Socket, buff + 1, 1, &recved) || recved != 1)
    return 0;
   if (!NewlineCheck(buff))
    return 0;
   break;
  }
  else
  {
   if (strcasecmp(Header, "Content-Length:") == 0)
   {
    if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
     return 0;
    Header = realloc(Header, lenHeader + 2);
    Header[lenHeader] = buff[0];
    lenHeader++;
    do
    {
     if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
      return 0;
     if (IsDigit(buff[0]) == 1)
     {
      Header = (char *)realloc(Header, lenHeader + 2);
      Header[lenHeader] = buff[0];
      lenHeader++;
     }
     GetNextDigit(&ret->ContentLen, buff);
    }
    while (IsDigit(buff[0]) == 1);
    Header[lenHeader] = 0;
    if (ret->Content != ((void *)0))
     free(ret->Content);
    ret->Content = (char *)malloc(ret->ContentLen + 1);
    memset(ret->Content, 0x00, ret->ContentLen + 1);
   }
   else
   {
    if (strcasecmp(Header, "Transfer-Encoding:") == 0)
     ret->TransferEncodingFound = 1;
    do
    {
     if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
      return 0;
     if (buff[0] != '\r' && buff[0] != '\n')
     {
      Header = (char *)realloc(Header, lenHeader + 2);
      Header[lenHeader] = buff[0];
      lenHeader++;
     }
    }
    while (buff[0] != '\r' && buff[0] != '\n');
    Header[lenHeader] = 0;
   }
   ret->Headers = (char **)realloc(ret->Headers, sizeof(char *) * (ret->nHeaders + 1));
   ret->Headers[ret->nHeaders] = Header;
   ret->nHeaders++;
   if (!tryRecv(URL->Socket, buff + 1, 1, &recved) || recved != 1)
    return 0;
   if (!NewlineCheck(buff))
    return 0;
  }
 }
 httpGetContentAsync(URL, ret);
 return 1;
}

canonical_original_code:
unsigned char tryReadHeaders(struct _Address *URL, struct _Response *ret)
{
 unsigned int recved;
 int rtl;
 static char buff[5] = {0};
 if (!tryRecv(URL->Socket, buff, 5, &recved) || recved != 5)
  return 0;
 if (strncmp(buff, "HTTP/", 5) != 0)
  return ProtoError();
 do
 {
  if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
   return 0;
  GetNextDigit(&ret->HTTPMajorVer, buff);
 }
 while (IsDigit(buff[0]) == 1);
 if (buff[0] != '.')
  return ProtoError();
 do
 {
  if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
   return 0;
  GetNextDigit(&ret->HTTPMinorVer, buff);
 }
 while (IsDigit(buff[0]) == 1);
 if (buff[0] != ' ')
  return ProtoError();
 if (!tryRecv(URL->Socket, buff, 3, &recved) || recved != 3)
  return 0;
 buff[3] = 0;
 ret->ResponceCode = atoi(buff);
 if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
  return 0;
 ret->ResponceText = (char *)malloc(1);
 rtl = 0;
 do
 {
  if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
   return 0;
  if (buff[0] != '\r' && buff[0] != '\n')
  {
   ret->ResponceText = (char *)realloc(ret->ResponceText, rtl + 2);
   ret->ResponceText[rtl] = buff[0];
   rtl++;
  }
 }
 while (buff[0] != '\r' && buff[0] != '\n');
 ret->ResponceText[rtl] = 0;
 if (!tryRecv(URL->Socket, buff + 1, 1, &recved) || recved != 1)
  return 0;
 if (!NewlineCheck(buff))
  return 0;
 ret->Headers = malloc(0);
 while (1)
 {
  char *Header = malloc(1);
  int lenHeader = 0;
  Header[0] = 0;
  do
  {
   if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
    return 0;
   if (buff[0] != '\r' && buff[0] != '\n')
   {
    Header = realloc(Header, lenHeader + 2);
    Header[lenHeader] = buff[0];
    lenHeader++;
   }
  }
  while (buff[0] != ':' && buff[0] != '\r' && buff[0] != '\n');
  Header[lenHeader] = 0;
  if (buff[0] == '\r' || buff[0] == '\n' && lenHeader == 0)
  {
   if (buff[0] == '\n')
   {
    free(Header);
    return HeaderProtoError();
   }
   if (!tryRecv(URL->Socket, buff + 1, 1, &recved) || recved != 1)
    return 0;
   if (!NewlineCheck(buff))
    return 0;
   break;
  }
  else
  {
   if (strcasecmp(Header, "Content-Length:") == 0)
   {
    if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
     return 0;
    Header = realloc(Header, lenHeader + 2);
    Header[lenHeader] = buff[0];
    lenHeader++;
    do
    {
     if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
      return 0;
     if (IsDigit(buff[0]) == 1)
     {
      Header = (char *)realloc(Header, lenHeader + 2);
      Header[lenHeader] = buff[0];
      lenHeader++;
     }
     GetNextDigit(&ret->ContentLen, buff);
    }
    while (IsDigit(buff[0]) == 1);
    Header[lenHeader] = 0;
    if (ret->Content != ((void *)0))
     free(ret->Content);
    ret->Content = (char *)malloc(ret->ContentLen + 1);
    memset(ret->Content, 0x00, ret->ContentLen + 1);
   }
   else
   {
    if (strcasecmp(Header, "Transfer-Encoding:") == 0)
     ret->TransferEncodingFound = 1;
    do
    {
     if (!tryRecv(URL->Socket, buff, 1, &recved) || recved != 1)
      return 0;
     if (buff[0] != '\r' && buff[0] != '\n')
     {
      Header = (char *)realloc(Header, lenHeader + 2);
      Header[lenHeader] = buff[0];
      lenHeader++;
     }
    }
    while (buff[0] != '\r' && buff[0] != '\n');
    Header[lenHeader] = 0;
   }
   ret->Headers = (char **)realloc(ret->Headers, sizeof(char *) * (ret->nHeaders + 1));
   ret->Headers[ret->nHeaders] = Header;
   ret->nHeaders++;
   if (!tryRecv(URL->Socket, buff + 1, 1, &recved) || recved != 1)
    return 0;
   if (!NewlineCheck(buff))
    return 0;
  }
 }
 httpGetContentAsync(URL, ret);
 return 1;
}

variable_types: struct _Address { char *ServerName; int ServerIP; char *ItemLocation; int Socket; unsigned char Secure; char *Protocol; struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *Server; short Port; int method; } *

variable_types: struct _Response { int HTTPMajorVer; char *ResponceText; char **Headers; int nHeaders; char *Content; int ContentLen; void *Private; unsigned char TransferEncodingFound; } *

variable_types:
recved
unsigned int

variable_types: rtl int

variable_types:
buff
char [5]

variable_types:
Header
char *

variable_types: lenHeader int

user_defined_types: struct _Address { char *ServerName; int ServerIP; char *ItemLocation; int Socket; unsigned char Secure; char *Protocol; struct hostent *Server; short Port; int method; }


httpFreeResponse

original_code:
void httpFreeResponse(Response **resp)
{
 Response *r;
 int i;
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (resp == ((void *)0) || *resp == ((void *)0))
 {
  httpError = -11;
  return;
 }
 r = *resp;
 free(r->ResponceText);
 for (i = 0; i < r->nHeaders; i++)
  free(r->Headers[i]);
 free(r->Headers);
 free(r->Content);
 free(r);
 *resp = ((void *)0);
}

canonical_original_code:
void httpFreeResponse(struct _Response **resp)
{
 struct _Response *r;
 int i;
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (resp == ((void *)0) || *resp == ((void *)0))
 {
  httpError = -11;
  return;
 }
 r = *resp;
 free(r->ResponceText);
 for (i = 0; i < r->nHeaders; i++)
  free(r->Headers[i]);
 free(r->Headers);
 free(r->Content);
 free(r);
 *resp = ((void *)0);
}

variable_types: struct _Response { int HTTPMajorVer; char *ResponceText; char **Headers; int nHeaders; char *Content; int ContentLen; void *Private; unsigned char TransferEncodingFound; } **

variable_types: i int


httpResponse

decompiled_code:
__int64 __fastcall httpResponse(__int64 a1)
{
_QWORD *v1; // rax
char v2; // dl
__int64 result; // rax
_QWORD *v4; // [rsp+0h] [rbp-10h] BYREF

if ( Initialised )
{
if ( a1 )
{
v1 = malloc(0x48uLL);
v4 = v1;
*v1 = 0LL;
v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = 0LL;
v1[4] = 0LL;
v1[5] = 0LL;
v1[6] = 0LL;
v1[7] = 0LL;
v1[8] = 0LL;
v2 = tryReadHeaders(a1, (__int64)v1);
result = (__int64)v4;
if ( !v2 )
{
httpFreeResponse((__int64 *)&v4);
result = 0LL;
}
}
else
{
httpError = -6LL;
result = 0LL;
}
}
else
{
httpError = -2LL;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
_QWORD *v1; // rax
char v2; // dl
__int64 result; // rax
_QWORD *v4; // [rsp+0h] [rbp-10h] BYREF

if ( Initialised )
{
if ( a1 )
{
v1 = malloc(0x48uLL);
v4 = v1;
*v1 = 0LL;
v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = 0LL;
v1[4] = 0LL;
v1[5] = 0LL;
v1[6] = 0LL;
v1[7] = 0LL;
v1[8] = 0LL;
v2 = func5(a1, (__int64)v1);
result = (__int64)v4;
if ( !v2 )
{
func6((__int64 *)&v4);
result = 0LL;
}
}
else
{
httpError = -6LL;
result = 0LL;
}
}
else
{
httpError = -2LL;
result = 0LL;
}
return result;
}

original_code:
Response *httpResponse(Address *URL)
{
 Response *ret;
 if (Initialised == 0)
 {
  httpError = -2;
  return ((void *)0);
 }
 if (URL == ((void *)0))
 {
  httpError = -6;
  return ((void *)0);
 }
 ret = (Response *)malloc(sizeof(Response));
 memset(ret, 0x00, sizeof(Response));
 if (tryReadHeaders(URL, ret) == 0)
 {
  httpFreeResponse(&ret);
  return ((void *)0);
 }
 return ret;
}

canonical_original_code:
struct _Response *httpResponse(struct _Address *URL)
{
 struct _Response *ret;
 if (Initialised == 0)
 {
  httpError = -2;
  return ((void *)0);
 }
 if (URL == ((void *)0))
 {
  httpError = -6;
  return ((void *)0);
 }
 ret = (struct _Response *)malloc(sizeof(Response));
 memset(ret, 0x00, sizeof(Response));
 if (tryReadHeaders(URL, ret) == 0)
 {
  httpFreeResponse(&ret);
  return ((void *)0);
 }
 return ret;
}

return_type: struct _Response { int HTTPMajorVer; char *ResponceText; char **Headers; int nHeaders; char *Content; int ContentLen; void *Private; unsigned char TransferEncodingFound; } *

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }


httpInit

decompiled_code:
__int64 httpInit()
{
if ( Initialised == 1 )
return 0xFFFFFFFFLL;
Initialised = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
if ( Initialised == 1 )
return 0xFFFFFFFFLL;
Initialised = 1;
return 0LL;
}

original_code:
int httpInit()
{
 if (Initialised == 1)
  return -1;
 Initialised = 1;
 return 0;
}


httpDeinit

decompiled_code:
__int64 httpDeinit()
{
if ( !Initialised )
return 4294967294LL;
Initialised = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
if ( !Initialised )
return 4294967294LL;
Initialised = 0;
return 0LL;
}

original_code:
int httpDeinit()
{
 if (Initialised == 0)
  return -2;
 Initialised = 0;
 return 0;
}


poschr

decompiled_code:
__int64 __fastcall poschr(const char *a1, char a2)
{
size_t v2; // rax
char v3; // dl
size_t v4; // rcx
__int64 v5; // rax
__int64 result; // rax

v2 = strlen(a1);
v3 = *a1;
if ( !v2 || (v4 = v2, v3 == a2) )
{
LODWORD(v5) = 0;
}
else
{
v5 = 0LL;
do
v3 = a1[++v5];
while ( v4 != v5 && v3 != a2 );
}
result = (unsigned int)(v5 + 1);
if ( v3 != a2 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, char a2)
{
size_t v2; // rax
char v3; // dl
size_t v4; // rcx
__int64 v5; // rax
__int64 result; // rax

v2 = strlen(a1);
v3 = *a1;
if ( !v2 || (v4 = v2, v3 == a2) )
{
LODWORD(v5) = 0;
}
else
{
v5 = 0LL;
do
v3 = a1[++v5];
while ( v4 != v5 && v3 != a2 );
}
result = (unsigned int)(v5 + 1);
if ( v3 != a2 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int poschr(const char *haystack, const char needle)
{
 size_t i = 0, len = strlen(haystack);
 while (haystack[i] != needle && len != i)
  i++;
 if (haystack[i] == needle)
  return i + 1;
 else
  return -1;
}

canonical_original_code:
int poschr(char *haystack, char needle)
{
 unsigned long i = 0; unsigned long len = strlen(haystack);
 while (haystack[i] != needle && len != i)
  i++;
 if (haystack[i] == needle)
  return i + 1;
 else
  return -1;
}

variable_types:
haystack
char *

variable_types: needle char

variable_types:
i
unsigned long

variable_types:
len
unsigned long


URLError

decompiled_code:
__int64 URLError()
{
httpError = -3LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
httpError = -3LL;
return 0LL;
}

original_code:
uint8_t URLError()
{
 httpError = -3;
 return 0;
}

canonical_original_code:
unsigned char URLError()
{
 httpError = -3;
 return 0;
}


ConnProtoError

decompiled_code:
__int64 ConnProtoError()
{
httpError = -4LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
httpError = -4LL;
return 0LL;
}

original_code:
uint8_t ConnProtoError()
{
 httpError = -4;
 return 0;
}

canonical_original_code:
unsigned char ConnProtoError()
{
 httpError = -4;
 return 0;
}


DNSError

decompiled_code:
__int64 DNSError()
{
httpError = -5LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
httpError = -5LL;
return 0LL;
}

original_code:
uint8_t DNSError()
{
 httpError = -5;
 return 0;
}

canonical_original_code:
unsigned char DNSError()
{
 httpError = -5;
 return 0;
}


tryLocate

original_code:
uint8_t tryLocate(char *Addr, Address *ret, LocateInternal *parts)
{
 int i;
 i = poschr(Addr, ':');
 if (i <= 0)
  return URLError();
 parts->Proto = (char *)malloc(i);
 memset(parts->Proto, 0x00, i);
 memcpy(parts->Proto, Addr, i - 1);
 Addr += i;
 if (Addr[0] != '/')
  return URLError();
 Addr++;
 if (Addr[0] != '/')
  return URLError();
 Addr++;
 i = poschr(Addr, '/');
 if (i == -1)
  i = strlen(Addr) + 1;
 if (i <= 1)
  return URLError();
 parts->Server = (char *)malloc(i);
 memcpy(parts->Server, Addr, i - 1);
 parts->Server[i - 1] = 0;
 Addr += i - 1;
 i = strlen(Addr);
 if (i == 0)
 {
  parts->Item = (char *)malloc(2);
  memcpy(parts->Item, "/", 2);
 }
 else
 {
  parts->Item = (char *)malloc(strlen(Addr) + 1);
  strcpy(parts->Item, Addr);
 }
 ret->ItemLocation = parts->Item;
 parts->Item = ((void *)0);
 if (strncasecmp(parts->Proto, "http", 4) != 0)
  return ConnProtoError();
 else if (parts->Proto[4] == 's')
  ret->Secure = 1;
 else
  ret->Secure = 0;
 ret->Protocol = parts->Proto;
 parts->Proto = ((void *)0);
 i = poschr(parts->Server, ':');
 if (i == -1)
  ret->Port = (ret->Secure == 1 ? 443 : 80);
 else
 {
  char *tmp = (char *)malloc(i);
  if (parts->Server[i] == 0)
   ret->Port = (ret->Secure == 1 ? 443 : 80);
  else
   ret->Port = (short)atoi(parts->Server + i);
  memcpy(tmp, parts->Server, i);
  tmp[i - 1] = 0;
  free(parts->Server);
  parts->Server = tmp;
 }
 ret->ServerName = parts->Server;
 parts->Server = ((void *)0);
 ret->Server = (struct hostent *)malloc(sizeof(struct hostent));
 if (ret->Server == ((void *)0))
  return DNSError();
 {
  struct hostent *host = gethostbyname(ret->ServerName);
  if (host == ((void *)0))
   return DNSError();
  memcpy(ret->Server, host, sizeof(struct hostent));
 }
 httpError = 0;
 return 1;
}

canonical_original_code:
unsigned char tryLocate(char *Addr, struct _Address *ret, struct _LocateInternal *parts)
{
 int i;
 i = poschr(Addr, ':');
 if (i <= 0)
  return URLError();
 parts->Proto = (char *)malloc(i);
 memset(parts->Proto, 0x00, i);
 memcpy(parts->Proto, Addr, i - 1);
 Addr += i;
 if (Addr[0] != '/')
  return URLError();
 Addr++;
 if (Addr[0] != '/')
  return URLError();
 Addr++;
 i = poschr(Addr, '/');
 if (i == -1)
  i = strlen(Addr) + 1;
 if (i <= 1)
  return URLError();
 parts->Server = (char *)malloc(i);
 memcpy(parts->Server, Addr, i - 1);
 parts->Server[i - 1] = 0;
 Addr += i - 1;
 i = strlen(Addr);
 if (i == 0)
 {
  parts->Item = (char *)malloc(2);
  memcpy(parts->Item, "/", 2);
 }
 else
 {
  parts->Item = (char *)malloc(strlen(Addr) + 1);
  strcpy(parts->Item, Addr);
 }
 ret->ItemLocation = parts->Item;
 parts->Item = ((void *)0);
 if (strncasecmp(parts->Proto, "http", 4) != 0)
  return ConnProtoError();
 else if (parts->Proto[4] == 's')
  ret->Secure = 1;
 else
  ret->Secure = 0;
 ret->Protocol = parts->Proto;
 parts->Proto = ((void *)0);
 i = poschr(parts->Server, ':');
 if (i == -1)
  ret->Port = (ret->Secure == 1 ? 443 : 80);
 else
 {
  char *tmp = (char *)malloc(i);
  if (parts->Server[i] == 0)
   ret->Port = (ret->Secure == 1 ? 443 : 80);
  else
   ret->Port = (short)atoi(parts->Server + i);
  memcpy(tmp, parts->Server, i);
  tmp[i - 1] = 0;
  free(parts->Server);
  parts->Server = tmp;
 }
 ret->ServerName = parts->Server;
 parts->Server = ((void *)0);
 ret->Server = (struct hostent *)malloc(sizeof(struct hostent));
 if (ret->Server == ((void *)0))
  return DNSError();
 {
  struct hostent *host = gethostbyname(ret->ServerName);
  if (host == ((void *)0))
   return DNSError();
  memcpy(ret->Server, host, sizeof(struct hostent));
 }
 httpError = 0;
 return 1;
}

variable_types:
Addr
char *

variable_types: struct _LocateInternal { char *Proto; char *Server; char *Item; } *

variable_types:
tmp
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


httpLocate

decompiled_code:
void **__fastcall httpLocate(void *src)
{
void **v1; // rax
void **v2; // rbx
void *ptr; // [rsp+0h] [rbp-38h] BYREF
void *v5; // [rsp+8h] [rbp-30h]
void *v6; // [rsp+10h] [rbp-28h]

if ( src )
{
if ( Initialised )
{
v1 = (void **)malloc(0x38uLL);
v2 = v1;
if ( v1 )
{
*v1 = 0LL;
v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = 0LL;
v1[4] = 0LL;
v1[5] = 0LL;
v1[6] = 0LL;
ptr = 0LL;
v5 = 0LL;
v6 = 0LL;
if ( !(unsigned __int8)tryLocate(src, (__int64)v1, (__int64 *)&ptr) )
{
free(ptr);
free(v5);
free(v6);
free(v2[5]);
free(*v2);
free(v2[2]);
free(v2[4]);
free(v2);
v2 = 0LL;
}
}
else
{
httpError = -14LL;
}
}
else
{
httpError = -2LL;
v2 = 0LL;
}
}
else
{
httpError = -3LL;
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
void **__fastcall func5(void *src)
{
void **v1; // rax
void **v2; // rbx
void *ptr; // [rsp+0h] [rbp-38h] BYREF
void *v5; // [rsp+8h] [rbp-30h]
void *v6; // [rsp+10h] [rbp-28h]

if ( src )
{
if ( Initialised )
{
v1 = (void **)malloc(0x38uLL);
v2 = v1;
if ( v1 )
{
*v1 = 0LL;
v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = 0LL;
v1[4] = 0LL;
v1[5] = 0LL;
v1[6] = 0LL;
ptr = 0LL;
v5 = 0LL;
v6 = 0LL;
if ( !(unsigned __int8)func4(src, (__int64)v1, (__int64 *)&ptr) )
{
free(ptr);
free(v5);
free(v6);
free(v2[5]);
free(*v2);
free(v2[2]);
free(v2[4]);
free(v2);
v2 = 0LL;
}
}
else
{
httpError = -14LL;
}
}
else
{
httpError = -2LL;
v2 = 0LL;
}
}
else
{
httpError = -3LL;
v2 = 0LL;
}
return v2;
}

original_code:
Address *httpLocate(char *URL)
{
 Address *ret;
 LocateInternal parts;
 if (URL == ((void *)0))
 {
  httpError = -3;
  return ((void *)0);
 }
 if (Initialised == 0)
 {
  httpError = -2;
  return ((void *)0);
 }
 ret = (Address *)malloc(sizeof(Address));
 if (ret == ((void *)0))
 {
  httpError = -14;
  return ((void *)0);
 }
 memset(ret, 0, sizeof(Address));
 memset(&parts, 0, sizeof(LocateInternal));
 if (!tryLocate(URL, ret, &parts))
 {
  free(parts.Proto);
  free(parts.Server);
  free(parts.Item);
  free(ret->Server);
  free(ret->ServerName);
  free(ret->ItemLocation);
  free(ret->Protocol);
  free(ret);
  return ((void *)0);
 }
 return ret;
}

canonical_original_code:
struct _Address *httpLocate(char *URL)
{
 struct _Address *ret;
 struct _LocateInternal parts;
 if (URL == ((void *)0))
 {
  httpError = -3;
  return ((void *)0);
 }
 if (Initialised == 0)
 {
  httpError = -2;
  return ((void *)0);
 }
 ret = (struct _Address *)malloc(sizeof(Address));
 if (ret == ((void *)0))
 {
  httpError = -14;
  return ((void *)0);
 }
 memset(ret, 0, sizeof(Address));
 memset(&parts, 0, sizeof(LocateInternal));
 if (!tryLocate(URL, ret, &parts))
 {
  free(parts.Proto);
  free(parts.Server);
  free(parts.Item);
  free(ret->Server);
  free(ret->ServerName);
  free(ret->ItemLocation);
  free(ret->Protocol);
  free(ret);
  return ((void *)0);
 }
 return ret;
}

variable_types:
URL
char *

variable_types: struct _Address { char *ServerName; int ServerIP; char *ItemLocation; int Socket; unsigned char Secure; char *Protocol; struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *Server; short Port; int method; } *

variable_types: struct _LocateInternal { char *Proto; char *Server; char *Item; }


httpConnect

decompiled_code:
void __fastcall httpConnect(__int64 a1)
{
int v1; // eax
char *v2; // rax
in_addr_t v3; // eax
struct sockaddr v4; // [rsp+0h] [rbp-18h] BYREF

if ( Initialised )
{
if ( a1 )
{
if ( *(_QWORD *)(a1 + 40) )
{
v1 = socket(2, 1, 6);
*(_DWORD *)(a1 + 24) = v1;
if ( v1 == -1 )
{
httpError = -7LL;
}
else
{
v2 = inet_ntoa((struct in_addr)(**(struct in_addr ***)(*(_QWORD *)(a1 + 40) + 24LL))->s_addr);
v3 = inet_addr(v2);
*(_DWORD *)(a1 + 8) = v3;
*(_QWORD *)&v4.sa_data[6] = 0LL;
v4.sa_family = 2;
*(_DWORD *)&v4.sa_data[2] = v3;
*(_WORD *)v4.sa_data = _bswap_16(*(_WORD *)(a1 + 48));
if ( connect(*(_DWORD *)(a1 + 24), &v4, 0x10u) == -1 )
httpError = -8LL;
else
*(_BYTE *)(a1 + 29) = 1;
}
}
else
{
httpError = -5LL;
}
}
else
{
httpError = -6LL;
}
}
else
{
httpError = -2LL;
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
int v1; // eax
char *v2; // rax
in_addr_t v3; // eax
struct sockaddr v4; // [rsp+0h] [rbp-18h] BYREF

if ( Initialised )
{
if ( a1 )
{
if ( *(_QWORD *)(a1 + 40) )
{
v1 = socket(2, 1, 6);
*(_DWORD *)(a1 + 24) = v1;
if ( v1 == -1 )
{
httpError = -7LL;
}
else
{
v2 = inet_ntoa((struct in_addr)(**(struct in_addr ***)(*(_QWORD *)(a1 + 40) + 24LL))->s_addr);
v3 = inet_addr(v2);
*(_DWORD *)(a1 + 8) = v3;
*(_QWORD *)&v4.sa_data[6] = 0LL;
v4.sa_family = 2;
*(_DWORD *)&v4.sa_data[2] = v3;
*(_WORD *)v4.sa_data = func0(*(_WORD *)(a1 + 48));
if ( connect(*(_DWORD *)(a1 + 24), &v4, 0x10u) == -1 )
httpError = -8LL;
else
*(_BYTE *)(a1 + 29) = 1;
}
}
else
{
httpError = -5LL;
}
}
else
{
httpError = -6LL;
}
}
else
{
httpError = -2LL;
}
}

original_code:
void httpConnect(Address *URL)
{
 struct sockaddr_in service;
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (URL == ((void *)0))
 {
  httpError = -6;
  return;
 }
 if (URL->Server == ((void *)0))
 {
  httpError = -5;
  return;
 }
 URL->Socket = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (URL->Socket == -1)
 {
  httpError = -7;
  return;
 }
 URL->ServerIP = inet_addr(inet_ntoa(*(struct in_addr *) *(URL->Server->h_addr_list)));
 memset(&service, 0x00, sizeof(service));
 service.sin_family = 2;
 service.sin_addr.s_addr = URL->ServerIP;
 service.sin_port = htons(URL->Port);
 if (connect(URL->Socket, (struct sockaddr *)&service, sizeof(service)) == -1)
 {
  httpError = -8;
  return;
 }
 URL->Connected = 1;
 return;
}

canonical_original_code:
void httpConnect(struct _Address *URL)
{
 struct sockaddr_in service;
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (URL == ((void *)0))
 {
  httpError = -6;
  return;
 }
 if (URL->Server == ((void *)0))
 {
  httpError = -5;
  return;
 }
 URL->Socket = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (URL->Socket == -1)
 {
  httpError = -7;
  return;
 }
 URL->ServerIP = inet_addr(inet_ntoa(*(struct in_addr *) *(URL->Server->h_addr_list)));
 memset(&service, 0x00, sizeof(service));
 service.sin_family = 2;
 service.sin_addr.s_addr = URL->ServerIP;
 service.sin_port = htons(URL->Port);
 if (connect(URL->Socket, (struct sockaddr *)&service, sizeof(service)) == -1)
 {
  httpError = -8;
  return;
 }
 URL->Connected = 1;
 return;
}

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

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

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


httpDisconnect

decompiled_code:
int __fastcall httpDisconnect(__int64 a1)
{
int v2; // edi
int result; // eax

if ( Initialised )
{
if ( a1 )
{
v2 = *(_DWORD *)(a1 + 24);
if ( v2 != -1 )
{
if ( *(_BYTE *)(a1 + 29) == 1 )
shutdown(v2, 2);
result = close(*(_DWORD *)(a1 + 24));
}
}
else
{
httpError = -6LL;
}
}
else
{
httpError = -2LL;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
int v2; // edi
int result; // eax

if ( Initialised )
{
if ( a1 )
{
v2 = *(_DWORD *)(a1 + 24);
if ( v2 != -1 )
{
if ( *(_BYTE *)(a1 + 29) == 1 )
shutdown(v2, 2);
result = close(*(_DWORD *)(a1 + 24));
}
}
else
{
httpError = -6LL;
}
}
else
{
httpError = -2LL;
}
return result;
}

original_code:
void httpDisconnect(Address *URL)
{
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (URL == ((void *)0))
 {
  httpError = -6;
  return;
 }
 if (URL->Socket != -1)
 {
  if (URL->Connected == 1)
   shutdown(URL->Socket, SHUT_RDWR);
  close(URL->Socket);
 }
 return;
}

canonical_original_code:
void httpDisconnect(struct _Address *URL)
{
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (URL == ((void *)0))
 {
  httpError = -6;
  return;
 }
 if (URL->Socket != -1)
 {
  if (URL->Connected == 1)
   shutdown(URL->Socket, SHUT_RDWR);
  close(URL->Socket);
 }
 return;
}


httpFreeAddress

decompiled_code:
void __fastcall httpFreeAddress(void ***a1)
{
void **v1; // rbp

if ( Initialised )
{
if ( a1 && (v1 = *a1) != 0LL )
{
free(*v1);
free(v1[2]);
free(v1[4]);
free(v1[5]);
free(v1);
*a1 = 0LL;
}
else
{
httpError = -6LL;
}
}
else
{
httpError = -2LL;
}
}

canonical_decompiled_code:
void __fastcall func8(void ***a1)
{
void **v1; // rbp

if ( Initialised )
{
if ( a1 && (v1 = *a1) != 0LL )
{
free(*v1);
free(v1[2]);
free(v1[4]);
free(v1[5]);
free(v1);
*a1 = 0LL;
}
else
{
httpError = -6LL;
}
}
else
{
httpError = -2LL;
}
}

original_code:
void httpFreeAddress(Address **URL)
{
 Address *a;
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (URL == ((void *)0) || *URL == ((void *)0))
 {
  httpError = -6;
  return;
 }
 a = *URL;
 free(a->ServerName);
 free(a->ItemLocation);
 free(a->Protocol);
 free(a->Server);
 free(a);
 *URL = ((void *)0);
}

canonical_original_code:
void httpFreeAddress(struct _Address **URL)
{
 struct _Address *a;
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (URL == ((void *)0) || *URL == ((void *)0))
 {
  httpError = -6;
  return;
 }
 a = *URL;
 free(a->ServerName);
 free(a->ItemLocation);
 free(a->Protocol);
 free(a->Server);
 free(a);
 *URL = ((void *)0);
}

variable_types: struct _Address { char *ServerName; int ServerIP; char *ItemLocation; int Socket; unsigned char Secure; char *Protocol; struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *Server; short Port; int method; } **


httpSetMethod

decompiled_code:
void __fastcall httpSetMethod(__int64 a1, unsigned int a2)
{
if ( Initialised )
{
if ( a1 )
{
if ( a2 <= 7 )
*(_DWORD *)(a1 + 52) = a2;
}
else
{
httpError = -6LL;
}
}
else
{
httpError = -2LL;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, unsigned int a2)
{
if ( Initialised )
{
if ( a1 )
{
if ( a2 <= 7 )
*(_DWORD *)(a1 + 52) = a2;
}
else
{
httpError = -6LL;
}
}
else
{
httpError = -2LL;
}
}

original_code:
void httpSetMethod(Address *URL, httpMethod Method)
{
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (URL == ((void *)0))
 {
  httpError = -6;
  return;
 }
 if (Method > Connect)
  return;
 URL->method = (int)Method;
}

canonical_original_code:
void httpSetMethod(struct _Address *URL, enum _httpMethod Method)
{
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (URL == ((void *)0))
 {
  httpError = -6;
  return;
 }
 if (Method > Connect)
  return;
 URL->method = (int)Method;
}

variable_types: enum _httpMethod { Get=0, Head=1, Post=2, Options=3, Put=4, Delete=5, Trace=6, Connect=7 }


httpGetMethod

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

if ( Initialised )
{
if ( a1 )
{
result = (__int64)*(&Methods + *(int *)(a1 + 52));
}
else
{
httpError = -6LL;
result = 0LL;
}
}
else
{
httpError = -2LL;
result = 0LL;
}
return result;
}

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

if ( Initialised )
{
if ( a1 )
{
result = (__int64)*(&Methods + *(int *)(a1 + 52));
}
else
{
httpError = -6LL;
result = 0LL;
}
}
else
{
httpError = -2LL;
result = 0LL;
}
return result;
}

original_code:
const char *httpGetMethod(Address *URL)
{
 if (Initialised == 0)
 {
  httpError = -2;
  return ((void *)0);
 }
 if (URL == ((void *)0))
 {
  httpError = -6;
  return ((void *)0);
 }
 return Methods[URL->method];
}

canonical_original_code:
char *httpGetMethod(struct _Address *URL)
{
 if (Initialised == 0)
 {
  httpError = -2;
  return ((void *)0);
 }
 if (URL == ((void *)0))
 {
  httpError = -6;
  return ((void *)0);
 }
 return Methods[URL->method];
}


getch

decompiled_code:
__int64 getch()
{
unsigned int v0; // ebx
struct termios v2; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

tcgetattr(0, &termios_p);
*(__m128i *)&v2.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v2.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v2.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v2.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v2.c_ospeed = termios_p.c_ospeed;
v2.c_lflag &= 0xFFFFFFF5;
tcsetattr(0, 0, &v2);
v0 = getchar();
tcsetattr(0, 0, &termios_p);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
struct termios v2; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

tcgetattr(0, &termios_p);
*(__m128i *)&v2.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v2.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v2.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v2.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v2.c_ospeed = termios_p.c_ospeed;
v2.c_lflag &= 0xFFFFFFF5;
tcsetattr(0, 0, &v2);
v0 = getchar();
tcsetattr(0, 0, &termios_p);
return v0;
}

original_code:
int getch()
{
 struct termios oldt, newt;
 int ch;
 tcgetattr(0, &oldt);
 newt = oldt;
 newt.c_lflag &= ~(0000002 | 0000010);
 tcsetattr(0, 0, &newt);
 ch = getchar();
 tcsetattr(0, 0, &oldt);
 return ch;
}

canonical_original_code:
int getch()
{
 struct termios oldt; struct termios newt;
 int ch;
 tcgetattr(0, &oldt);
 newt = oldt;
 newt.c_lflag &= ~(0000002 | 0000010);
 tcsetattr(0, 0, &newt);
 ch = getchar();
 tcsetattr(0, 0, &oldt);
 return ch;
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types: ch int


tryRecv

decompiled_code:
__int64 __fastcall tryRecv(int a1, void *a2, unsigned int a3, int *a4)
{
int v6; // eax
__int64 result; // rax

v6 = recv(a1, a2, a3, 0);
if ( v6 < 0 )
{
httpError = -12LL;
result = 0LL;
}
else if ( v6 )
{
*a4 = v6;
result = 1LL;
}
else
{
result = 1LL;
if ( a3 )
{
httpError = -13LL;
result = 0LL;
}
}
return result;
}

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

v6 = recv(a1, a2, a3, 0);
if ( v6 < 0 )
{
httpError = -12LL;
result = 0LL;
}
else if ( v6 )
{
*a4 = v6;
result = 1LL;
}
else
{
result = 1LL;
if ( a3 )
{
httpError = -13LL;
result = 0LL;
}
}
return result;
}

original_code:
uint8_t tryRecv(SOCKET sock, char *buffer, uint32_t bufferLen, uint32_t *retLen)
{
 int ret = recv(sock, buffer, bufferLen, 0);
 if (ret < 0)
 {
  httpError = -12;
  return 0;
 }
 else if (ret == 0)
 {
  if (bufferLen == 0)
   return 1;
  else
  {
   httpError = -13;
   return 0;
  }
 }
 *retLen = (uint32_t)ret;
 return 1;
}

canonical_original_code:
unsigned char tryRecv(int sock, char *buffer, unsigned int bufferLen, unsigned int *retLen)
{
 int ret = recv(sock, buffer, bufferLen, 0);
 if (ret < 0)
 {
  httpError = -12;
  return 0;
 }
 else if (ret == 0)
 {
  if (bufferLen == 0)
   return 1;
  else
  {
   httpError = -13;
   return 0;
  }
 }
 *retLen = (unsigned int)ret;
 return 1;
}

variable_types: sock int

variable_types:
buffer
char *

variable_types:
bufferLen
unsigned int

variable_types:
retLen
unsigned int *

variable_types: ret int


httpRequest

decompiled_code:
void __fastcall httpRequest(__int64 a1)
{
const char *v1; // r13
int v2; // ebp
char *v3; // r12

if ( Initialised )
{
if ( a1 )
{
v1 = (const char *)httpGetMethod();
v2 = snprintf(
0LL,
0LL,
"%s %s HTTP/1.1\r\nUser-Agent: Future Consiousness/0.1 () Future Explorer 0.0.1\r\nHost: %s:%u\r\n\r\n",
v1,
*(const char **)(a1 + 16),
*(const char **)a1,
(unsigned int)*(__int16 *)(a1 + 48));
v3 = (char *)malloc(v2 + 1);
sprintf(
v3,
"%s %s HTTP/1.1\r\nUser-Agent: Future Consiousness/0.1 () Future Explorer 0.0.1\r\nHost: %s:%u\r\n\r\n",
v1,
*(const char **)(a1 + 16),
*(const char **)a1,
(unsigned int)*(__int16 *)(a1 + 48));
send(*(_DWORD *)(a1 + 24), v3, v2, 0);
free(v3);
}
else
{
httpError = -6LL;
}
}
else
{
httpError = -2LL;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
const char *v1; // r13
int v2; // ebp
char *v3; // r12

if ( Initialised )
{
if ( a1 )
{
v1 = (const char *)httpGetMethod();
v2 = snprintf(
0LL,
0LL,
"%s %s HTTP/1.1\r\nUser-Agent: Future Consiousness/0.1 () Future Explorer 0.0.1\r\nHost: %s:%u\r\n\r\n",
v1,
*(const char **)(a1 + 16),
*(const char **)a1,
(unsigned int)*(__int16 *)(a1 + 48));
v3 = (char *)malloc(v2 + 1);
sprintf(
v3,
"%s %s HTTP/1.1\r\nUser-Agent: Future Consiousness/0.1 () Future Explorer 0.0.1\r\nHost: %s:%u\r\n\r\n",
v1,
*(const char **)(a1 + 16),
*(const char **)a1,
(unsigned int)*(__int16 *)(a1 + 48));
send(*(_DWORD *)(a1 + 24), v3, v2, 0);
free(v3);
}
else
{
httpError = -6LL;
}
}
else
{
httpError = -2LL;
}
}

original_code:
void httpRequest(Address *URL)
{
 char *request;
 const char *method;
 int reqLen;
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (URL == ((void *)0))
 {
  httpError = -6;
  return;
 }
 method = httpGetMethod(URL);
 reqLen = snprintf(((void *)0), 0, "%s %s HTTP/1.1\r\nUser-Agent: Future Consiousness/0.1 () Future Explorer 0.0.1\r\nHost: %s:%u\r\n\r\n", method, URL->ItemLocation, URL->ServerName, URL->Port) + 1;
 request = malloc(reqLen);
 sprintf(request, "%s %s HTTP/1.1\r\nUser-Agent: Future Consiousness/0.1 () Future Explorer 0.0.1\r\nHost: %s:%u\r\n\r\n", method, URL->ItemLocation, URL->ServerName, URL->Port);
 send(URL->Socket, request, reqLen - 1, 0);
 free(request);
}

canonical_original_code:
void httpRequest(struct _Address *URL)
{
 char *request;
 char *method;
 int reqLen;
 if (Initialised == 0)
 {
  httpError = -2;
  return;
 }
 if (URL == ((void *)0))
 {
  httpError = -6;
  return;
 }
 method = httpGetMethod(URL);
 reqLen = snprintf(((void *)0), 0, "%s %s HTTP/1.1\r\nUser-Agent: Future Consiousness/0.1 () Future Explorer 0.0.1\r\nHost: %s:%u\r\n\r\n", method, URL->ItemLocation, URL->ServerName, URL->Port) + 1;
 request = malloc(reqLen);
 sprintf(request, "%s %s HTTP/1.1\r\nUser-Agent: Future Consiousness/0.1 () Future Explorer 0.0.1\r\nHost: %s:%u\r\n\r\n", method, URL->ItemLocation, URL->ServerName, URL->Port);
 send(URL->Socket, request, reqLen - 1, 0);
 free(request);
}

variable_types:
request
char *

variable_types:
method
char *

variable_types: reqLen int


rp

repo: Daeinar/piccolo

decompiled_code:
unsigned __int64 __fastcall rp(unsigned __int64 *a1)
{
unsigned __int64 v1; // rdx
unsigned __int64 v2; // rax
unsigned __int64 result; // rax

v1 = *a1;
v2 = a1[1];
*a1 = (((_DWORD)v2 << 16) & 0xFF0000 | (unsigned __int64)(unsigned __int8)BYTE2(*a1)) ^ (v2 >> 16) & 0xFF00 ^ ((unsigned int)*a1 << 16) & 0xFF000000;
result = ((_DWORD)v2 << 16) & 0xFF000000 ^ (unsigned __int64)BYTE2(v2);
a1[1] = result ^ ((v1 >> 16) & 0xFF00 | ((_DWORD)v1 << 16) & 0xFF0000);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(unsigned __int64 *a1)
{
unsigned __int64 v1; // rdx
unsigned __int64 v2; // rax
unsigned __int64 result; // rax

v1 = *a1;
v2 = a1[1];
*a1 = (((_DWORD)v2 << 16) & 0xFF0000 | (unsigned __int64)(unsigned __int8)BYTE2(*a1)) ^ (v2 >> 16) & 0xFF00 ^ ((unsigned int)*a1 << 16) & 0xFF000000;
result = ((_DWORD)v2 << 16) & 0xFF000000 ^ (unsigned __int64)BYTE2(v2);
a1[1] = result ^ ((v1 >> 16) & 0xFF00 | ((_DWORD)v1 << 16) & 0xFF0000);
return result;
}

variable_types:
s
struct STATE { unsigned long b[2]; } *

variable_types:
t
unsigned long [2]


gm

decompiled_code:
__int64 __fastcall gm(int a1, unsigned __int8 a2)
{
int v2; // edx
__int64 result; // rax
char v4; // r8

v2 = 4;
result = 0LL;
do
{
if ( (a2 & 1) != 0 )
result = a1 ^ (unsigned int)result;
v4 = a1 & 8;
a1 *= 2;
if ( v4 )
a1 ^= 0x13u;
a2 >>= 1;
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, unsigned __int8 a2)
{
int v2; // edx
__int64 result; // rax
char v4; // r8

v2 = 4;
result = 0LL;
do
{
if ( (a2 & 1) != 0 )
result = a1 ^ (unsigned int)result;
v4 = a1 & 8;
a1 *= 2;
if ( v4 )
a1 ^= 0x13u;
a2 >>= 1;
--v2;
}
while ( v2 );
return result;
}

canonical_original_code:
unsigned char gm(unsigned char a, unsigned char b) {
  unsigned char g = 0;
  int i;
  for (i = 0; i < 4; i++) {
    if ( (b & 0x1) == 1 ) { g ^= a; }
    unsigned char hbs = (a & 0x8);
    a <<= 0x1;
    if ( hbs == 0x8) { a ^= 0x13; }
    b >>= 0x1;
  }
  return g;
}

variable_types:
a
unsigned char

variable_types:
b
unsigned char

variable_types:
g
unsigned char

variable_types: i int

variable_types:
hbs
unsigned char


main

canonical_name: main

repo: Damienkatz/memhog

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
__int64 v4; // rbx
void *v5; // rdi
int v6; // ebx
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc == 2 )
{
v3 = argv[1];
if ( v3 == strstr(v3, "0x") )
v4 = strtol(v3, endptr, 16);
else
v4 = strtol(v3, endptr, 10);
if ( *endptr[0] )
{
printf("Failed: Invalid argument %s, make sure to pass a base 10 or 16 integer (ex: 255 or 0xFF)\n", argv[1]);
v6 = 1;
}
else
{
printf("Attempting to hog %li bytes of RAM.\n", v4);
v5 = malloc(v4);
if ( v5 )
{
v6 = mlock(v5, v4);
if ( v6 )
{
puts("Failed! Couldn't mlock.");
v6 = 1;
}
else
{
puts("Success! Press any key to kill me and get back the RAM.");
getchar();
}
}
else
{
puts("Failied! Couldn't malloc.");
v6 = 1;
}
}
}
else
{
puts("Failed: Missing argument, make sure to pass a base 10 or 16 integer (ex: 255 or 0xFF)");
v6 = 1;
}
return v6;
}

original_code:
int main(int argc, const char* argv[]) {
 char* lastchar;
 long bytes_to_hog;
 void* mem;
 if (argc != 2) {
  printf("Failed: Missing argument, make sure to pass a base 10 or 16 integer (ex: 255 or 0xFF)\n");
  return 1;
 }
 if (strstr(argv[1], "0x") == argv[1]) {
  bytes_to_hog = strtol(argv[1], &lastchar, 16);
 } else {
  bytes_to_hog = strtol(argv[1], &lastchar, 10);
 }
 if (*lastchar != '\0') {
  printf("Failed: Invalid argument %s, make sure to pass a base 10 or 16 integer (ex: 255 or 0xFF)\n", argv[1]);
  return 1;
 }
 printf("Attempting to hog %li bytes of RAM.\n", bytes_to_hog);
  mem = malloc(bytes_to_hog);
 if (!mem) {
  printf("Failied! Couldn't malloc.\n");
  return 1;
 }
 if (mlock(mem, bytes_to_hog)) {
  printf("Failed! Couldn't mlock.\n");
  return 1;
 }
 printf("Success! Press any key to kill me and get back the RAM.\n");
 getchar();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 char *lastchar;
 long bytes_to_hog;
 void *mem;
 if (argc != 2) {
  printf("Failed: Missing argument, make sure to pass a base 10 or 16 integer (ex: 255 or 0xFF)\n");
  return 1;
 }
 if (strstr(argv[1], "0x") == argv[1]) {
  bytes_to_hog = strtol(argv[1], &lastchar, 16);
 } else {
  bytes_to_hog = strtol(argv[1], &lastchar, 10);
 }
 if (*lastchar != '\0') {
  printf("Failed: Invalid argument %s, make sure to pass a base 10 or 16 integer (ex: 255 or 0xFF)\n", argv[1]);
  return 1;
 }
 printf("Attempting to hog %li bytes of RAM.\n", bytes_to_hog);
  mem = malloc(bytes_to_hog);
 if (!mem) {
  printf("Failied! Couldn't malloc.\n");
  return 1;
 }
 if (mlock(mem, bytes_to_hog)) {
  printf("Failed! Couldn't mlock.\n");
  return 1;
 }
 printf("Success! Press any key to kill me and get back the RAM.\n");
 getchar();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
lastchar
char *

variable_types:
mem
void *


tochar

repo: DanGrayson/coq-tex

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

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

original_code:
static unsigned char tochar(signed char x) {
     return (signed char)x;
     }

canonical_original_code:
static unsigned char tochar(char x) {
     return (char)x;
     }

variable_types: x char


translate

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

v1 = translateTable[a1];
v2 = 0;
if ( a1 != 10 )
v2 = column_0 + 1;
column_0 = v2;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 v1; // rdx
int v2; // eax

v1 = translateTable[a1];
v2 = 0;
if ( a1 != 10 )
v2 = column_0 + 1;
column_0 = v2;
return v1;
}

original_code:
static char *translate(int c) {
  static int column = 0;
  char *r = translateTable[(int)c];
  if (c == '\n') column = 0; else column++;
  return r;
}

variable_types: c int

variable_types: column int

variable_types:
r
char *


decompiled_code:
void delay_clear()
{
delay_n = 0;
}

canonical_decompiled_code:
void func9()
{
delay_n = 0;
}

original_code:
static void delay_clear() {
  delay_n = 0;
}


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
fprintf(stderr, "%s: %s\n", (const char *)progname, a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(const char *a1)
{
fprintf(stderr, "%s: %s\n", (const char *)progname, a1);
exit(1);
}

original_code:
static void error(char *s) {
     fprintf(stderr, "%s: %s\n",progname,s);
     exit(1);
     }

variable_types:
s
char *


setup

decompiled_code:
int setup()
{
__int64 i; // rbx
char *v1; // rbp
__int64 j; // rbx
char *v3; // rbp
const char *v4; // r12
char v5; // bl
char *v6; // rbp
const char *v7; // r12
char v8; // bl
char *v9; // rbp
int result; // eax

for ( i = 0LL; i != 256; ++i )
{
v1 = (char *)getmem(0xBuLL);
sprintf(v1, "{\\char%d}", (unsigned int)i);
translateTable[i] = (__int64)v1;
}
for ( j = 32LL; j != 127; ++j )
{
v3 = (char *)getmem(2uLL);
sprintf(v3, "%c", (unsigned int)j);
translateTable[j] = (__int64)v3;
}
v4 = "\\%";
v5 = 92;
do
{
v6 = (char *)getmem(0xBuLL);
sprintf(v6, "{\\char`\\%c}", (unsigned int)v5);
translateTable[v5] = (__int64)v6;
v5 = *++v4;
}
while ( *v4 );
v7 = " ${}";
v8 = 32;
do
{
v9 = (char *)getmem(3uLL);
result = sprintf(v9, "\\%c", (unsigned int)v8);
translateTable[v8] = (__int64)v9;
v8 = *++v7;
}
while ( *v7 );
qword_404150 = (__int64)"\\\\\n";
qword_404168 = (__int64)"\r";
qword_404148 = (__int64)"\t";
qword_404200 = (__int64)"\\ ";
qword_4043F8 = (__int64)"\\_";
qword_4043F0 = (__int64)"\\^";
return result;
}

canonical_decompiled_code:
int func13()
{
__int64 i; // rbx
char *v1; // rbp
__int64 j; // rbx
char *v3; // rbp
const char *v4; // r12
char v5; // bl
char *v6; // rbp
const char *v7; // r12
char v8; // bl
char *v9; // rbp
int result; // eax

for ( i = 0LL; i != 256; ++i )
{
v1 = (char *)func12(0xBuLL);
sprintf(v1, "{\\char%d}", (unsigned int)i);
translateTable[i] = (__int64)v1;
}
for ( j = 32LL; j != 127; ++j )
{
v3 = (char *)func12(2uLL);
sprintf(v3, "%c", (unsigned int)j);
translateTable[j] = (__int64)v3;
}
v4 = "\\%";
v5 = 92;
do
{
v6 = (char *)func12(0xBuLL);
sprintf(v6, "{\\char`\\%c}", (unsigned int)v5);
translateTable[v5] = (__int64)v6;
v5 = *++v4;
}
while ( *v4 );
v7 = " ${}";
v8 = 32;
do
{
v9 = (char *)func12(3uLL);
result = sprintf(v9, "\\%c", (unsigned int)v8);
translateTable[v8] = (__int64)v9;
v8 = *++v7;
}
while ( *v7 );
qword_404150 = (__int64)"\\\\\n";
qword_404168 = (__int64)"\r";
qword_404148 = (__int64)"\t";
qword_404200 = (__int64)"\\ ";
qword_4043F8 = (__int64)"\\_";
qword_4043F0 = (__int64)"\\^";
return result;
}

original_code:
static void setup() {
     int i;
     char *special = "\\%";
     char *special2 = " ${}";
     char *p;
     for (i = 0; i< 256; i++) {
   p = getmem(11);
   sprintf(p,"{\\char%d}", i);
   translateTable[i] = p;
   }
     for (i = 32; i < 127; i++) {
   p = getmem(2);
   sprintf(p,"%c", i);
   translateTable[i] = p;
   }
     for (; *special; special++) {
   p = getmem(11);
   sprintf(p,"{\\char`\\%c}", *special);
   translateTable[(int)*special] = p;
   }
     for (; *special2; special2++) {
   p = getmem(3);
   sprintf(p,"\\%c", *special2);
   translateTable[(int)*special2] = p;
   }
     translateTable['\n'] = "\\\\\n";
     translateTable['\r'] = "\r";
     translateTable['\t'] = "\t";
     translateTable[' '] = "\\ ";
     translateTable['_'] = "\\_";
     translateTable['^'] = "\\^";
     }

variable_types:
special
char *

variable_types:
p
char *


trap

decompiled_code:
void trap()
{
;
}

canonical_decompiled_code:
void func18()
{
;
}

original_code:
void trap(){
     }

canonical_original_code:
void trap(){
     }


historyGet

decompiled_code:
__int64 __fastcall historyGet(unsigned int a1, unsigned int a2)
{
return history[64 * (unsigned __int64)a1 + a2];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
return history[64 * (unsigned __int64)a1 + a2];
}

original_code:
History historyGet(Piece fromPiece, Sq toSq) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 return history[fromPiece][toSq];
}

canonical_original_code:
unsigned long historyGet(enum Piece fromPiece, enum Sq toSq) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 return history[fromPiece][toSq];
}

variable_types: enum Piece { PieceNone=expr, PieceWPawn=expr, PieceWKnight=expr, PieceWBishopL=expr, PieceWBishopD=expr, PieceWRook=expr, PieceWQueen=expr, PieceWKing=expr, PieceBPawn=expr, PieceBKnight=expr, PieceBBishopL=expr, PieceBBishopD=expr, PieceBRook=expr, PieceBQueen=expr, PieceBKing=expr, PieceNB=expr }

return_type: unsigned long


historyAge

decompiled_code:
_QWORD *historyAge()
{
unsigned __int64 v0; // rdx
_QWORD *result; // rax

v0 = (unsigned int)((_DWORD)history + 512);
do
{
result = (_QWORD *)(v0 - 512);
do
*result++ >>= 1;
while ( result != (_QWORD *)v0 );
v0 += 512LL;
}
while ( v0 != (_DWORD)history + 8704 );
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
unsigned __int64 v0; // rdx
_QWORD *result; // rax

v0 = (unsigned int)((_DWORD)history + 512);
do
{
result = (_QWORD *)(v0 - 512);
do
*result++ >>= 1;
while ( result != (_QWORD *)v0 );
v0 += 512LL;
}
while ( v0 != (_DWORD)history + 8704 );
return result;
}

original_code:
void historyAge(void) {
 unsigned int i, j;
 for(i=0;i<PieceNB;++i)
  for(j=0;j<SqNB;++j)
   history[i][j]/=2;
}

canonical_original_code:
void historyAge() {
 unsigned int i; unsigned int j;
 for(i=0;i<PieceNB;++i)
  for(j=0;j<SqNB;++j)
   history[i][j]/=2;
}

variable_types:
i
unsigned int

variable_types:
j
unsigned int


historyClear

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

result = 0LL;
memset(history, 0, sizeof(history));
return result;
}

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

result = 0LL;
memset(history, 0, sizeof(history));
return result;
}

original_code:
void historyClear(void) {
 memset(history, 0, sizeof(history));
}

canonical_original_code:
void historyClear() {
 memset(history, 0, sizeof(history));
}


sqIsValid

decompiled_code:
bool __fastcall sqIsValid(unsigned int a1)
{
return a1 <= 0x3F;
}

canonical_decompiled_code:
bool __fastcall func0(unsigned int a1)
{
return a1 <= 0x3F;
}

original_code:
_Bool sqIsValid(Sq sq) {
 return (sq>=SqA1 && sq<=SqH8);
}

canonical_original_code:
_Bool sqIsValid(enum Sq sq) {
 return (sq>=SqA1 && sq<=SqH8);
}


sqMake

decompiled_code:
__int64 __fastcall sqMake(int a1, int a2)
{
return (unsigned int)(a1 + 8 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
return (unsigned int)(a1 + 8 * a2);
}

original_code:
Sq sqMake(File file, Rank rank) {
 ((void) (0));
 ((void) (0));
 return (rank<<3)+file;
}

canonical_original_code:
enum Sq sqMake(enum File file, enum Rank rank) {
 ((void) (0));
 ((void) (0));
 return (rank<<3)+file;
}

variable_types: enum File { FileA=0, FileB=1, FileC=2, FileD=3, FileE=4, FileF=5, FileG=6, FileH=7, FileNB=8 }

variable_types: enum Rank { Rank1=0, Rank2=1, Rank3=2, Rank4=3, Rank5=4, Rank6=5, Rank7=6, Rank8=7, RankNB=8 }


sqFile

decompiled_code:
__int64 __fastcall sqFile(char a1)
{
return a1 & 7;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
return a1 & 7;
}

canonical_original_code:
enum File sqFile(enum Sq sq) {
 ((void) (0));
 return (sq&(((1u)<<3)-1));
}

return_type: enum File { FileA=0, FileB=1, FileC=2, FileD=3, FileE=4, FileF=5, FileG=6, FileH=7, FileNB=8 }


sqRank

decompiled_code:
__int64 __fastcall sqRank(unsigned int a1)
{
return a1 >> 3;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return a1 >> 3;
}

original_code:
Rank sqRank(Sq sq) {
 ((void) (0));
 return (sq>>3);
}

canonical_original_code:
enum Rank sqRank(enum Sq sq) {
 ((void) (0));
 return (sq>>3);
}

return_type: enum Rank { Rank1=0, Rank2=1, Rank3=2, Rank4=3, Rank5=4, Rank6=5, Rank7=6, Rank8=7, RankNB=8 }


sqMirror

decompiled_code:
__int64 __fastcall sqMirror(int a1)
{
return a1 ^ 7u;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return a1 ^ 7u;
}

canonical_original_code:
enum Sq sqMirror(enum Sq sq) {
 ((void) (0));
 return (sq^(((1u)<<3)-1));
}


sqFlip

decompiled_code:
__int64 __fastcall sqFlip(int a1)
{
return a1 ^ 0x38u;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
return a1 ^ 0x38u;
}

canonical_original_code:
enum Sq sqFlip(enum Sq sq) {
 ((void) (0));
 return (sq^((((1u)<<3)-1)<<3));
}


sqNormalise

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

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

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

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

original_code:
Sq sqNormalise(Sq sq, Colour colour) {
 return (colour==ColourWhite ? sq : sqFlip(sq));
}

canonical_original_code:
enum Sq sqNormalise(enum Sq sq, enum Colour colour) {
 return (colour==ColourWhite ? sq : sqFlip(sq));
}

variable_types: enum Colour { ColourWhite=0, ColourBlack=1, ColourNB=2 }


sqNorth

decompiled_code:
__int64 __fastcall sqNorth(int a1, int a2)
{
return (unsigned int)(a1 + 8 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return (unsigned int)(a1 + 8 * a2);
}

original_code:
Sq sqNorth(Sq sq, unsigned int n) {
 ((void) (0));
 ((void) (0));
 return sq+(8*n);
}

canonical_original_code:
enum Sq sqNorth(enum Sq sq, unsigned int n) {
 ((void) (0));
 ((void) (0));
 return sq+(8*n);
}

variable_types:
n
unsigned int


sqSouth

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

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

original_code:
Sq sqSouth(Sq sq, unsigned int n) {
 ((void) (0));
 ((void) (0));
 return sq-(8*n);
}

canonical_original_code:
enum Sq sqSouth(enum Sq sq, unsigned int n) {
 ((void) (0));
 ((void) (0));
 return sq-(8*n);
}


sqWestOne

decompiled_code:
__int64 __fastcall sqWestOne(int a1)
{
return (unsigned int)(a1 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
return (unsigned int)(a1 - 1);
}

original_code:
Sq sqWestOne(Sq sq) {
 ((void) (0));
 ((void) (0));
 return sq-1;
}

canonical_original_code:
enum Sq sqWestOne(enum Sq sq) {
 ((void) (0));
 ((void) (0));
 return sq-1;
}


sqEastOne

decompiled_code:
__int64 __fastcall sqEastOne(int a1)
{
return (unsigned int)(a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
return (unsigned int)(a1 + 1);
}

original_code:
Sq sqEastOne(Sq sq) {
 ((void) (0));
 ((void) (0));
 return sq+1;
}

canonical_original_code:
enum Sq sqEastOne(enum Sq sq) {
 ((void) (0));
 ((void) (0));
 return sq+1;
}


sqForwardOne

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

if ( a2 )
result = sqSouth(a1, 1);
else
result = sqNorth(a1, 1);
return result;
}

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

if ( a2 )
result = func8(a1, 1);
else
result = func7(a1, 1);
return result;
}

original_code:
Sq sqForwardOne(Sq sq, Colour colour) {
 ((void) (0));
 ((void) (0));
 return (colour==ColourWhite ? sqNorth(sq,1) : sqSouth(sq,1));
}

canonical_original_code:
enum Sq sqForwardOne(enum Sq sq, enum Colour colour) {
 ((void) (0));
 ((void) (0));
 return (colour==ColourWhite ? sqNorth(sq,1) : sqSouth(sq,1));
}

user_defined_types: enum Colour { ColourWhite=0, ColourBlack=1, ColourNB=2 }


sqBackwardOne

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

if ( a2 )
result = sqNorth(a1, 1);
else
result = sqSouth(a1, 1);
return result;
}

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

if ( a2 )
result = func7(a1, 1);
else
result = func8(a1, 1);
return result;
}

original_code:
Sq sqBackwardOne(Sq sq, Colour colour) {
 ((void) (0));
 ((void) (0));
 return (colour==ColourWhite ? sqSouth(sq,1) : sqNorth(sq,1));
}

canonical_original_code:
enum Sq sqBackwardOne(enum Sq sq, enum Colour colour) {
 ((void) (0));
 ((void) (0));
 return (colour==ColourWhite ? sqSouth(sq,1) : sqNorth(sq,1));
}


sqIsLight

decompiled_code:
__int64 __fastcall sqIsLight(unsigned int a1)
{
unsigned __int8 v1; // bl

v1 = sqFile(a1);
return (v1 ^ (unsigned __int8)sqRank(a1)) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1)
{
unsigned __int8 v1; // bl

v1 = func2(a1);
return (v1 ^ (unsigned __int8)func3(a1)) & 1;
}

original_code:
_Bool sqIsLight(Sq sq) {
 ((void) (0));
 return ((sqFile(sq)^sqRank(sq))&1);
}

canonical_original_code:
_Bool sqIsLight(enum Sq sq) {
 ((void) (0));
 return ((sqFile(sq)^sqRank(sq))&1);
}


bitbaseQuit

decompiled_code:
void bitbaseQuit()
{
free(bitbase);
bitbase = 0LL;
}

canonical_decompiled_code:
void func0()
{
free(bitbase);
bitbase = 0LL;
}

original_code:
void bitbaseQuit(void) {
 free(bitbase);
 bitbase=((void *)0);
}

canonical_original_code:
void bitbaseQuit() {
 free(bitbase);
 bitbase=((void *)0);
}


bitbaseComputeStaticResult

original_code:
BitBaseResultFull bitbaseComputeStaticResult(Sq pawnSq, Sq wKingSq, Colour stm, Sq bKingSq) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 ((void) (0));
 BB wKingAtks=attacksKing(wKingSq);
 BB bKingAtks=attacksKing(bKingSq);
 BB pawnAtks=attacksPawn(pawnSq, ColourWhite);
 BB wKingBB=bbSq(wKingSq);
 BB bKingBB=bbSq(bKingSq);
 BB pawnBB=bbSq(pawnSq);
 BB occ=(pawnBB | wKingBB | bKingBB);
 Rank pawnRank=sqRank(pawnSq);
 if (pawnSq==wKingSq || pawnSq==bKingSq || wKingSq==bKingSq ||
     pawnRank==Rank1 ||
     (wKingAtks & bKingBB) ||
     (stm==ColourWhite && (pawnAtks & bKingBB)))
  return BitBaseResultFullInvalid;
 if (pawnRank==Rank7 && stm==ColourWhite) {
  BB promoBB=bbNorthOne(pawnBB);
  if (!(promoBB & occ) &&
      (!(promoBB & bKingAtks) || (promoBB & wKingAtks)))
   return BitBaseResultFullWin;
 }
 if (stm==ColourBlack && (bKingAtks & pawnBB) && !(wKingAtks & pawnBB))
  return BitBaseResultFullDraw;
 if (pawnRank==Rank8)
  return BitBaseResultFullWin;
 if (stm==ColourWhite) {
  BB safe=~(bKingAtks | occ);
  if (!(wKingAtks & safe) &&
      (bbNorthOne(pawnBB) & occ))
   return BitBaseResultFullDraw;
 } else {
  BB safe=~(wKingAtks | pawnAtks | occ);
  if (!(bKingAtks & safe))
   return BitBaseResultFullDraw;
 }
 return BitBaseResultFullUnknown;
}

canonical_original_code:
enum BitBaseResultFull bitbaseComputeStaticResult(enum Sq pawnSq, enum Sq wKingSq, enum Colour stm, enum Sq bKingSq) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 ((void) (0));
 unsigned long wKingAtks = attacksKing(wKingSq);
 unsigned long bKingAtks = attacksKing(bKingSq);
 unsigned long pawnAtks = attacksPawn(pawnSq, ColourWhite);
 unsigned long wKingBB = bbSq(wKingSq);
 unsigned long bKingBB = bbSq(bKingSq);
 unsigned long pawnBB = bbSq(pawnSq);
 unsigned long occ = (pawnBB | wKingBB | bKingBB);
 enum Rank pawnRank = sqRank(pawnSq);
 if (pawnSq==wKingSq || pawnSq==bKingSq || wKingSq==bKingSq ||
     pawnRank==Rank1 ||
     (wKingAtks & bKingBB) ||
     (stm==ColourWhite && (pawnAtks & bKingBB)))
  return BitBaseResultFullInvalid;
 if (pawnRank==Rank7 && stm==ColourWhite) {
  unsigned long promoBB = bbNorthOne(pawnBB);
  if (!(promoBB & occ) &&
      (!(promoBB & bKingAtks) || (promoBB & wKingAtks)))
   return BitBaseResultFullWin;
 }
 if (stm==ColourBlack && (bKingAtks & pawnBB) && !(wKingAtks & pawnBB))
  return BitBaseResultFullDraw;
 if (pawnRank==Rank8)
  return BitBaseResultFullWin;
 if (stm==ColourWhite) {
  unsigned long safe = ~(bKingAtks | occ);
  if (!(wKingAtks & safe) &&
      (bbNorthOne(pawnBB) & occ))
   return BitBaseResultFullDraw;
 } else {
  unsigned long safe = ~(wKingAtks | pawnAtks | occ);
  if (!(bKingAtks & safe))
   return BitBaseResultFullDraw;
 }
 return BitBaseResultFullUnknown;
}

variable_types:
wKingAtks
unsigned long

variable_types:
bKingAtks
unsigned long

variable_types:
pawnAtks
unsigned long

variable_types:
wKingBB
unsigned long

variable_types:
bKingBB
unsigned long

variable_types:
pawnBB
unsigned long

variable_types:
occ
unsigned long

variable_types:
promoBB
unsigned long

variable_types:
safe
unsigned long

return_type: enum BitBaseResultFull { BitBaseResultFullInvalid=0, BitBaseResultFullUnknown=1, BitBaseResultFullDraw=2, BitBaseResultFullWin=3 }

user_defined_types: enum Rank { Rank1=0, Rank2=1, Rank3=2, Rank4=3, Rank5=4, Rank6=5, Rank7=6, Rank8=7, RankNB=8 }


bitbaseIndex

decompiled_code:
__int64 __fastcall bitbaseIndex(int a1, int a2, int a3, int a4)
{
return (unsigned int)(a4 + 2 * (a3 + ((a2 + 8 * a1) << 6)));
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int a3, int a4)
{
return (unsigned int)(a4 + 2 * (a3 + ((a2 + 8 * a1) << 6)));
}

original_code:
unsigned int bitbaseIndex(File pawnFile, Rank pawnRank, Sq wKingSq, Colour stm) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 ((void) (0));
 return ((pawnFile*RankNB+pawnRank)*SqNB+wKingSq)*ColourNB+stm;
}

canonical_original_code:
unsigned int bitbaseIndex(enum File pawnFile, enum Rank pawnRank, enum Sq wKingSq, enum Colour stm) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 ((void) (0));
 return ((pawnFile*RankNB+pawnRank)*SqNB+wKingSq)*ColourNB+stm;
}

return_type: unsigned int

user_defined_types: enum File { FileA=0, FileB=1, FileC=2, FileD=3, FileE=4, FileF=5, FileG=6, FileH=7, FileNB=8 }


bitbaseProbeRaw

decompiled_code:
__int64 __fastcall bitbaseProbeRaw(unsigned int a1, unsigned int a2, unsigned int a3, int a4)
{
int v4; // er12
unsigned int v7; // ebx
int v8; // er13

v4 = a2;
v7 = sqFile();
v8 = sqRank(a1);
if ( v7 > 3 )
{
v7 = fileMirror(v7);
v4 = sqMirror(a2);
LOBYTE(a3) = sqMirror(a3);
}
return (*((_QWORD *)bitbase + (unsigned int)bitbaseIndex(v7, v8, v4, a4)) >> a3) & 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2, unsigned int a3, int a4)
{
int v4; // er12
unsigned int v7; // ebx
int v8; // er13

v4 = a2;
v7 = sqFile();
v8 = sqRank(a1);
if ( v7 > 3 )
{
v7 = fileMirror(v7);
v4 = sqMirror(a2);
LOBYTE(a3) = sqMirror(a3);
}
return (*((_QWORD *)bitbase + (unsigned int)func2(v7, v8, v4, a4)) >> a3) & 1LL;
}

original_code:
BitBaseResult bitbaseProbeRaw(Sq pawnSq, Sq wKingSq, Sq bKingSq, Colour stm) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 ((void) (0));
 File pawnFile=sqFile(pawnSq);
 Rank pawnRank=sqRank(pawnSq);
 if (pawnFile>FileD) {
  pawnFile=fileMirror(pawnFile);
  wKingSq=sqMirror(wKingSq);
  bKingSq=sqMirror(bKingSq);
 }
 unsigned int index=bitbaseIndex(pawnFile, pawnRank, wKingSq, stm);
 return (bitbase[index]>>bKingSq)&1;
}

canonical_original_code:
enum BitBaseResult bitbaseProbeRaw(enum Sq pawnSq, enum Sq wKingSq, enum Sq bKingSq, enum Colour stm) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 ((void) (0));
 enum File pawnFile = sqFile(pawnSq);
 enum Rank pawnRank = sqRank(pawnSq);
 if (pawnFile>FileD) {
  pawnFile=fileMirror(pawnFile);
  wKingSq=sqMirror(wKingSq);
  bKingSq=sqMirror(bKingSq);
 }
 unsigned int index = bitbaseIndex(pawnFile, pawnRank, wKingSq, stm);
 return (bitbase[index]>>bKingSq)&1;
}

variable_types:
index
unsigned int

return_type: enum BitBaseResult { BitBaseResultDraw=0, BitBaseResultWin=1 }


bitbaseIndexFull

decompiled_code:
__int64 __fastcall bitbaseIndexFull(int a1, int a2, int a3, int a4, int a5)
{
return (unsigned int)(a5 + ((a4 + 2 * (a3 + ((a2 + 8 * a1) << 6))) << 6));
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2, int a3, int a4, int a5)
{
return (unsigned int)(a5 + ((a4 + 2 * (a3 + ((a2 + 8 * a1) << 6))) << 6));
}

original_code:
unsigned int bitbaseIndexFull(File pawnFile, Rank pawnRank, Sq wKingSq, Colour stm, Sq bKingSq) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 ((void) (0));
 ((void) (0));
 return (((pawnFile*RankNB+pawnRank)*SqNB+wKingSq)*ColourNB+stm)*SqNB+bKingSq;
}

canonical_original_code:
unsigned int bitbaseIndexFull(enum File pawnFile, enum Rank pawnRank, enum Sq wKingSq, enum Colour stm, enum Sq bKingSq) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 ((void) (0));
 ((void) (0));
 return (((pawnFile*RankNB+pawnRank)*SqNB+wKingSq)*ColourNB+stm)*SqNB+bKingSq;
}


bitbaseComputeDynamicResult

decompiled_code:
__int64 __fastcall bitbaseComputeDynamicResult(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
int v7; // ebx
int v8; // er13
int v9; // ebp
char v10; // r14
int v11; // eax
__int64 result; // rax
char v13; // r14
int v14; // eax
__int64 v16[8]; // [rsp+18h] [rbp-40h] BYREF

v7 = sqFile(a2);
v8 = sqRank(a2);
v9 = colourSwap(a4);
if ( a4 )
{
v16[0] = attacksKing(a5);
if ( v16[0] )
{
v13 = 1;
do
{
v14 = bbScanReset(v16);
result = *(unsigned int *)(a1 + 4LL * (unsigned int)bitbaseIndexFull(v7, v8, a3, v9, v14));
if ( (_DWORD)result == 1 )
{
v13 = 0;
}
else if ( (_DWORD)result == 2 )
{
return result;
}
}
while ( v16[0] );
result = v13 == 0 ? 1 : 3;
}
else
{
result = 3LL;
}
}
else
{
v16[0] = attacksKing(a3);
if ( v16[0] )
{
v10 = 1;
while ( 1 )
{
v11 = bbScanReset(v16);
result = *(unsigned int *)(a1 + 4LL * (unsigned int)bitbaseIndexFull(v7, v8, v11, v9, a5));
if ( (_DWORD)result == 1 )
{
v10 = 0;
}
else if ( (_DWORD)result == 3 )
{
return result;
}
if ( !v16[0] )
goto LABEL_10;
}
}
v10 = 1;
LABEL_10:
result = *(unsigned int *)(a1 + 4LL * (unsigned int)bitbaseIndexFull(v7, v8 + 1, a3, v9, a5));
if ( (_DWORD)result == 1 )
{
if ( v8 != 1 )
return result;
v10 = 0;
}
else
{
if ( (_DWORD)result == 3 )
return result;
if ( !(_DWORD)result || v8 != 1 )
return (v10 & 1u) + 1;
}
result = *(unsigned int *)(a1 + 4LL * (unsigned int)bitbaseIndexFull(v7, 3, a3, v9, a5));
if ( (_DWORD)result != 1 && (_DWORD)result != 3 )
return (v10 & 1u) + 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
int v7; // ebx
int v8; // er13
int v9; // ebp
char v10; // r14
int v11; // eax
__int64 result; // rax
char v13; // r14
int v14; // eax
__int64 v16[8]; // [rsp+18h] [rbp-40h] BYREF

v7 = sqFile(a2);
v8 = sqRank(a2);
v9 = colourSwap(a4);
if ( a4 )
{
v16[0] = attacksKing(a5);
if ( v16[0] )
{
v13 = 1;
do
{
v14 = bbScanReset(v16);
result = *(unsigned int *)(a1 + 4LL * (unsigned int)func5(v7, v8, a3, v9, v14));
if ( (_DWORD)result == 1 )
{
v13 = 0;
}
else if ( (_DWORD)result == 2 )
{
return result;
}
}
while ( v16[0] );
result = v13 == 0 ? 1 : 3;
}
else
{
result = 3LL;
}
}
else
{
v16[0] = attacksKing(a3);
if ( v16[0] )
{
v10 = 1;
while ( 1 )
{
v11 = bbScanReset(v16);
result = *(unsigned int *)(a1 + 4LL * (unsigned int)func5(v7, v8, v11, v9, a5));
if ( (_DWORD)result == 1 )
{
v10 = 0;
}
else if ( (_DWORD)result == 3 )
{
return result;
}
if ( !v16[0] )
goto LABEL_10;
}
}
v10 = 1;
LABEL_10:
result = *(unsigned int *)(a1 + 4LL * (unsigned int)func5(v7, v8 + 1, a3, v9, a5));
if ( (_DWORD)result == 1 )
{
if ( v8 != 1 )
return result;
v10 = 0;
}
else
{
if ( (_DWORD)result == 3 )
return result;
if ( !(_DWORD)result || v8 != 1 )
return (v10 & 1u) + 1;
}
result = *(unsigned int *)(a1 + 4LL * (unsigned int)func5(v7, 3, a3, v9, a5));
if ( (_DWORD)result != 1 && (_DWORD)result != 3 )
return (v10 & 1u) + 1;
}
return result;
}

original_code:
BitBaseResultFull bitbaseComputeDynamicResult(const BitBaseResultFull *array, Sq pawnSq, Sq wKingSq, Colour stm, Sq bKingSq) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 ((void) (0));
 File pawnFile=sqFile(pawnSq);
 Rank pawnRank=sqRank(pawnSq);
 Colour xstm=colourSwap(stm);
 if (stm==ColourWhite) {
  _Bool allDraws=1;
  BB set=attacksKing(wKingSq);
  while(set) {
   unsigned int newIndex=bitbaseIndexFull(pawnFile, pawnRank, bbScanReset(&set), xstm, bKingSq);
   switch(array[newIndex]) {
    case BitBaseResultFullInvalid: break;
    case BitBaseResultFullUnknown: allDraws=0; break;
    case BitBaseResultFullDraw: break;
    case BitBaseResultFullWin: return BitBaseResultFullWin; break;
   }
  }
  unsigned int newIndex=bitbaseIndexFull(pawnFile, pawnRank+1, wKingSq, xstm, bKingSq);
  _Bool singlePushOk=1;
  switch(array[newIndex]) {
   case BitBaseResultFullInvalid: singlePushOk=0; break;
   case BitBaseResultFullUnknown: allDraws=0; break;
   case BitBaseResultFullDraw: break;
   case BitBaseResultFullWin: return BitBaseResultFullWin; break;
  }
  if (pawnRank==Rank2 && singlePushOk) {
   unsigned int newIndex=bitbaseIndexFull(pawnFile, pawnRank+2, wKingSq, xstm, bKingSq);
   switch(array[newIndex]) {
    case BitBaseResultFullInvalid: break;
    case BitBaseResultFullUnknown: allDraws=0; break;
    case BitBaseResultFullDraw: break;
    case BitBaseResultFullWin: return BitBaseResultFullWin; break;
   }
  }
  return (allDraws ? BitBaseResultFullDraw : BitBaseResultFullUnknown);
 } else {
  _Bool allWins=1;
  BB set=attacksKing(bKingSq);
  while(set) {
   unsigned int newIndex=bitbaseIndexFull(pawnFile, pawnRank, wKingSq, xstm, bbScanReset(&set));
   switch(array[newIndex]) {
    case BitBaseResultFullInvalid: break;
    case BitBaseResultFullUnknown: allWins=0; break;
    case BitBaseResultFullDraw: return BitBaseResultFullDraw; break;
    case BitBaseResultFullWin: break;
   }
  }
  return (allWins ? BitBaseResultFullWin : BitBaseResultFullUnknown);
 }
 ((void) (0));
 return BitBaseResultFullInvalid;
}

canonical_original_code:
enum BitBaseResultFull bitbaseComputeDynamicResult(enum BitBaseResultFull *array, enum Sq pawnSq, enum Sq wKingSq, enum Colour stm, enum Sq bKingSq) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 ((void) (0));
 enum File pawnFile = sqFile(pawnSq);
 enum Rank pawnRank = sqRank(pawnSq);
 enum Colour xstm = colourSwap(stm);
 if (stm==ColourWhite) {
  _Bool allDraws = 1;
  unsigned long set = attacksKing(wKingSq);
  while(set) {
   unsigned int newIndex = bitbaseIndexFull(pawnFile, pawnRank, bbScanReset(&set), xstm, bKingSq);
   switch(array[newIndex]) {
    case BitBaseResultFullInvalid: break;
    case BitBaseResultFullUnknown: allDraws=0; break;
    case BitBaseResultFullDraw: break;
    case BitBaseResultFullWin: return BitBaseResultFullWin; break;
   }
  }
  unsigned int newIndex = bitbaseIndexFull(pawnFile, pawnRank+1, wKingSq, xstm, bKingSq);
  _Bool singlePushOk = 1;
  switch(array[newIndex]) {
   case BitBaseResultFullInvalid: singlePushOk=0; break;
   case BitBaseResultFullUnknown: allDraws=0; break;
   case BitBaseResultFullDraw: break;
   case BitBaseResultFullWin: return BitBaseResultFullWin; break;
  }
  if (pawnRank==Rank2 && singlePushOk) {
   unsigned int newIndex = bitbaseIndexFull(pawnFile, pawnRank+2, wKingSq, xstm, bKingSq);
   switch(array[newIndex]) {
    case BitBaseResultFullInvalid: break;
    case BitBaseResultFullUnknown: allDraws=0; break;
    case BitBaseResultFullDraw: break;
    case BitBaseResultFullWin: return BitBaseResultFullWin; break;
   }
  }
  return (allDraws ? BitBaseResultFullDraw : BitBaseResultFullUnknown);
 } else {
  _Bool allWins = 1;
  unsigned long set = attacksKing(bKingSq);
  while(set) {
   unsigned int newIndex = bitbaseIndexFull(pawnFile, pawnRank, wKingSq, xstm, bbScanReset(&set));
   switch(array[newIndex]) {
    case BitBaseResultFullInvalid: break;
    case BitBaseResultFullUnknown: allWins=0; break;
    case BitBaseResultFullDraw: return BitBaseResultFullDraw; break;
    case BitBaseResultFullWin: break;
   }
  }
  return (allWins ? BitBaseResultFullWin : BitBaseResultFullUnknown);
 }
 ((void) (0));
 return BitBaseResultFullInvalid;
}

variable_types: enum BitBaseResultFull { BitBaseResultFullInvalid=0, BitBaseResultFullUnknown=1, BitBaseResultFullDraw=2, BitBaseResultFullWin=3 } *

variable_types:
set
unsigned long

variable_types:
newIndex
unsigned int


bitbaseGen

decompiled_code:
void __fastcall bitbaseGen()
{
unsigned int j; // er12
_DWORD *v1; // r14
unsigned int i; // er15
_DWORD *v3; // rax
int k; // ebp
unsigned int l; // ebx
_DWORD *v6; // r13
unsigned int ii; // ebx
_DWORD *v8; // rbp
int v9; // eax
unsigned int n; // er15
unsigned int v11; // er12
unsigned int m; // er15
int jj; // ebp
int ll; // ebx
int kk; // er12
unsigned int v16; // er13
unsigned int v17; // [rsp+Ch] [rbp-4Ch]
unsigned int v18; // [rsp+10h] [rbp-48h]
__int64 v19; // [rsp+10h] [rbp-48h]
int v20; // [rsp+10h] [rbp-48h]
char v21; // [rsp+1Bh] [rbp-3Dh]
unsigned int v22; // [rsp+1Ch] [rbp-3Ch]

v3 = malloc(0x100000uLL);
if ( !v3 )
{
mainFatalError("Error: Could not allocate memory for generating KPvK bitbase.\n");
goto LABEL_4;
}
v1 = v3;
for ( i = 0; i != 4; ++i )
{
v17 = 7;
do
{
v18 = sqMake(i, v17);
for ( j = 0; j != 64; ++j )
{
for ( k = 0; k != 2; ++k )
{
for ( l = 0; l != 64; ++l )
{
v6 = &v1[(unsigned int)bitbaseIndexFull(i, v17, j, k, l)];
*v6 = bitbaseComputeStaticResult(v18, j, k, l);
}
}
LABEL_4:
;
}
--v17;
}
while ( v17 );
}
for ( m = 0; m != 4; ++m )
{
v16 = 6;
do
{
v22 = sqMake(m, v16);
v20 = m;
do
{
v11 = 0;
v21 = 0;
do
{
for ( n = 0; n != 2; ++n )
{
for ( ii = 0; ii != 64; ++ii )
{
v8 = &v1[(unsigned int)bitbaseIndexFull(v20, v16, v11, n, ii)];
if ( *v8 == 1 )
{
v9 = bitbaseComputeDynamicResult((__int64)v1, v22, v11, n, ii);
*v8 = v9;
v21 |= v9 != 1;
}
}
}
++v11;
}
while ( v11 != 64 );
}
while ( v21 );
m = v20;
for ( jj = 0; jj != 64; ++jj )
{
for ( kk = 0; kk != 2; ++kk )
{
v19 = 8LL * (unsigned int)bitbaseIndex(m, v16, jj, kk);
*(_QWORD *)((char *)bitbase + v19) = 0LL;
for ( ll = 0; ll != 64; ++ll )
{
if ( v1[(unsigned int)bitbaseIndexFull(m, v16, jj, kk, ll)] == 3 )
*(_QWORD *)((char *)bitbase + v19) |= 1LL << ll;
}
}
}
--v16;
}
while ( v16 );
}
free(v1);
}

canonical_decompiled_code:
void __fastcall func7()
{
unsigned int j; // er12
_DWORD *v1; // r14
unsigned int i; // er15
_DWORD *v3; // rax
int k; // ebp
unsigned int l; // ebx
_DWORD *v6; // r13
unsigned int ii; // ebx
_DWORD *v8; // rbp
int v9; // eax
unsigned int n; // er15
unsigned int v11; // er12
unsigned int m; // er15
int jj; // ebp
int ll; // ebx
int kk; // er12
unsigned int v16; // er13
unsigned int v17; // [rsp+Ch] [rbp-4Ch]
unsigned int v18; // [rsp+10h] [rbp-48h]
__int64 v19; // [rsp+10h] [rbp-48h]
int v20; // [rsp+10h] [rbp-48h]
char v21; // [rsp+1Bh] [rbp-3Dh]
unsigned int v22; // [rsp+1Ch] [rbp-3Ch]

v3 = malloc(0x100000uLL);
if ( !v3 )
{
mainFatalError("Error: Could not allocate memory for generating KPvK bitbase.\n");
goto LABEL_4;
}
v1 = v3;
for ( i = 0; i != 4; ++i )
{
v17 = 7;
do
{
v18 = sqMake(i, v17);
for ( j = 0; j != 64; ++j )
{
for ( k = 0; k != 2; ++k )
{
for ( l = 0; l != 64; ++l )
{
v6 = &v1[(unsigned int)func5(i, v17, j, k, l)];
*v6 = func1(v18, j, k, l);
}
}
LABEL_4:
;
}
--v17;
}
while ( v17 );
}
for ( m = 0; m != 4; ++m )
{
v16 = 6;
do
{
v22 = sqMake(m, v16);
v20 = m;
do
{
v11 = 0;
v21 = 0;
do
{
for ( n = 0; n != 2; ++n )
{
for ( ii = 0; ii != 64; ++ii )
{
v8 = &v1[(unsigned int)func5(v20, v16, v11, n, ii)];
if ( *v8 == 1 )
{
v9 = func6((__int64)v1, v22, v11, n, ii);
*v8 = v9;
v21 |= v9 != 1;
}
}
}
++v11;
}
while ( v11 != 64 );
}
while ( v21 );
m = v20;
for ( jj = 0; jj != 64; ++jj )
{
for ( kk = 0; kk != 2; ++kk )
{
v19 = 8LL * (unsigned int)func2(m, v16, jj, kk);
*(_QWORD *)((char *)bitbase + v19) = 0LL;
for ( ll = 0; ll != 64; ++ll )
{
if ( v1[(unsigned int)func5(m, v16, jj, kk, ll)] == 3 )
*(_QWORD *)((char *)bitbase + v19) |= 1LL << ll;
}
}
}
--v16;
}
while ( v16 );
}
free(v1);
}

original_code:
void bitbaseGen(void) {
 BitBaseResultFull *array=malloc((FileNB/2)*RankNB*SqNB*ColourNB*SqNB*sizeof(BitBaseResultFull));
 if (array==((void *)0))
  mainFatalError("Error: Could not allocate memory for generating KPvK bitbase.\n");
 Sq wKingSq, bKingSq;
 Colour stm;
 File pawnFile;
 Rank pawnRank;
 for(pawnFile=FileA;pawnFile<=FileD;++pawnFile)
  for(pawnRank=Rank8;pawnRank>=Rank2;--pawnRank) {
   Sq pawnSq=sqMake(pawnFile, pawnRank);
   for(wKingSq=0;wKingSq<SqNB;++wKingSq)
    for(stm=0;stm<ColourNB;++stm)
     for(bKingSq=0;bKingSq<SqNB;++bKingSq) {
      unsigned int index=bitbaseIndexFull(pawnFile, pawnRank, wKingSq, stm, bKingSq);
      array[index]=bitbaseComputeStaticResult(pawnSq, wKingSq, stm, bKingSq);
     }
  }
 for(pawnFile=FileA;pawnFile<=FileD;++pawnFile)
  for(pawnRank=Rank7;pawnRank>=Rank2;--pawnRank) {
   Sq pawnSq=sqMake(pawnFile, pawnRank);
   _Bool change;
   do {
    change=0;
    for(wKingSq=0;wKingSq<SqNB;++wKingSq)
     for(stm=0;stm<ColourNB;++stm)
      for(bKingSq=0;bKingSq<SqNB;++bKingSq) {
       unsigned int index=bitbaseIndexFull(pawnFile, pawnRank, wKingSq, stm, bKingSq);
       if (array[index]!=BitBaseResultFullUnknown)
        continue;
       BitBaseResultFull result=bitbaseComputeDynamicResult(array, pawnSq, wKingSq, stm, bKingSq);
       change|=((array[index]=result)!=BitBaseResultFullUnknown);
      }
   } while(change);
   for(wKingSq=0;wKingSq<SqNB;++wKingSq)
    for(stm=0;stm<ColourNB;++stm) {
     unsigned int index=bitbaseIndex(pawnFile, pawnRank, wKingSq, stm);
     bitbase[index]=0;
     for(bKingSq=0;bKingSq<SqNB;++bKingSq) {
      unsigned int fullIndex=bitbaseIndexFull(pawnFile, pawnRank, wKingSq, stm, bKingSq);
      typedef struct { int static_assertion_failed : !!(BitBaseResultWin==1); } static_assertion_failed_3;
      if (array[fullIndex]==BitBaseResultFullWin)
       bitbase[index]|=(1llu<<bKingSq);
     }
    }
  }
 free(array);
}

canonical_original_code:
void bitbaseGen() {
 enum BitBaseResultFull *array = malloc((FileNB/2)*RankNB*SqNB*ColourNB*SqNB*sizeof(BitBaseResultFull));
 if (array==((void *)0))
  mainFatalError("Error: Could not allocate memory for generating KPvK bitbase.\n");
 enum Sq wKingSq; enum Sq bKingSq;
 enum Colour stm;
 enum File pawnFile;
 enum Rank pawnRank;
 for(pawnFile=FileA;pawnFile<=FileD;++pawnFile)
  for(pawnRank=Rank8;pawnRank>=Rank2;--pawnRank) {
   enum Sq pawnSq = sqMake(pawnFile, pawnRank);
   for(wKingSq=0;wKingSq<SqNB;++wKingSq)
    for(stm=0;stm<ColourNB;++stm)
     for(bKingSq=0;bKingSq<SqNB;++bKingSq) {
      unsigned int index = bitbaseIndexFull(pawnFile, pawnRank, wKingSq, stm, bKingSq);
      array[index]=bitbaseComputeStaticResult(pawnSq, wKingSq, stm, bKingSq);
     }
  }
 for(pawnFile=FileA;pawnFile<=FileD;++pawnFile)
  for(pawnRank=Rank7;pawnRank>=Rank2;--pawnRank) {
   enum Sq pawnSq = sqMake(pawnFile, pawnRank);
   _Bool change;
   do {
    change=0;
    for(wKingSq=0;wKingSq<SqNB;++wKingSq)
     for(stm=0;stm<ColourNB;++stm)
      for(bKingSq=0;bKingSq<SqNB;++bKingSq) {
       unsigned int index = bitbaseIndexFull(pawnFile, pawnRank, wKingSq, stm, bKingSq);
       if (array[index]!=BitBaseResultFullUnknown)
        continue;
       enum BitBaseResultFull result = bitbaseComputeDynamicResult(array, pawnSq, wKingSq, stm, bKingSq);
       change|=((array[index]=result)!=BitBaseResultFullUnknown);
      }
   } while(change);
   for(wKingSq=0;wKingSq<SqNB;++wKingSq)
    for(stm=0;stm<ColourNB;++stm) {
     unsigned int index = bitbaseIndex(pawnFile, pawnRank, wKingSq, stm);
     bitbase[index]=0;
     for(bKingSq=0;bKingSq<SqNB;++bKingSq) {
      unsigned int fullIndex = bitbaseIndexFull(pawnFile, pawnRank, wKingSq, stm, bKingSq);
      typedef struct { int static_assertion_failed : !!(BitBaseResultWin==1); } static_assertion_failed_3;
      if (array[fullIndex]==BitBaseResultFullWin)
       bitbase[index]|=(1llu<<bKingSq);
     }
    }
  }
 free(array);
}

variable_types: enum File { FileA=0, FileB=1, FileC=2, FileD=3, FileE=4, FileF=5, FileG=6, FileH=7, FileNB=8 }

variable_types: enum BitBaseResultFull { BitBaseResultFullInvalid=0, BitBaseResultFullUnknown=1, BitBaseResultFullDraw=2, BitBaseResultFullWin=3 }

variable_types:
fullIndex
unsigned int


bitbaseInit

decompiled_code:
void bitbaseInit()
{
bitbase = malloc(0x8000uLL);
if ( !bitbase )
{
mainFatalError("Error: Could not allocate memory for KPvK bitbase.\n");
JUMPOUT(0x710LL);
}
bitbaseGen();
}

canonical_decompiled_code:
void func8()
{
bitbase = malloc(0x8000uLL);
if ( !bitbase )
{
mainFatalError("Error: Could not allocate memory for KPvK bitbase.\n");
JUMPOUT(0x710LL);
}
func7();
}

original_code:
void bitbaseInit(void) {
 bitbase=malloc((FileNB/2)*RankNB*SqNB*ColourNB*sizeof(uint64_t));
 if (bitbase==((void *)0))
  mainFatalError("Error: Could not allocate memory for KPvK bitbase.\n");
 bitbaseGen();
}

canonical_original_code:
void bitbaseInit() {
 bitbase=malloc((FileNB/2)*RankNB*SqNB*ColourNB*sizeof(unsigned long));
 if (bitbase==((void *)0))
  mainFatalError("Error: Could not allocate memory for KPvK bitbase.\n");
 bitbaseGen();
}


utilStrEqual

decompiled_code:
bool __fastcall utilStrEqual(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
bool __fastcall func0(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
_Bool utilStrEqual(const char *a, const char *b) {
 return (strcmp(a, b)==0);
}

canonical_original_code:
_Bool utilStrEqual(char *a, char *b) {
 return (strcmp(a, b)==0);
}

variable_types:
a
char *

variable_types:
b
char *


utilRandSeed

decompiled_code:
void __fastcall utilRandSeed(__int64 a1)
{
utilRandState = a1;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
utilRandState = a1;
}

original_code:
void utilRandSeed(uint64_t seed) {
 utilRandState=seed;
}

canonical_original_code:
void utilRandSeed(unsigned long seed) {
 utilRandState=seed;
}

variable_types:
seed
unsigned long


decompiled_code:
__int64 utilRand64()
{
utilRandState ^= ((utilRandState ^ ((unsigned __int64)utilRandState >> 12)) << 25) ^ ((unsigned __int64)utilRandState >> 12) ^ ((((utilRandState ^ ((unsigned __int64)utilRandState >> 12)) << 25) ^ utilRandState ^ ((unsigned __int64)utilRandState >> 12)) >> 27);
return 0x2545F4914F6CDD1DLL * utilRandState;
}

canonical_decompiled_code:
__int64 func2()
{
utilRandState ^= ((utilRandState ^ ((unsigned __int64)utilRandState >> 12)) << 25) ^ ((unsigned __int64)utilRandState >> 12) ^ ((((utilRandState ^ ((unsigned __int64)utilRandState >> 12)) << 25) ^ utilRandState ^ ((unsigned __int64)utilRandState >> 12)) >> 27);
return 0x2545F4914F6CDD1DLL * utilRandState;
}

original_code:
uint64_t utilRand64(void) {
 utilRandState^=utilRandState>>12;
 utilRandState^=utilRandState<<25;
 utilRandState^=utilRandState>>27;
 return utilRandState*2685821657736338717llu;
}

canonical_original_code:
unsigned long utilRand64() {
 utilRandState^=utilRandState>>12;
 utilRandState^=utilRandState<<25;
 utilRandState^=utilRandState>>27;
 return utilRandState*2685821657736338717llu;
}