StringCompare

decompiled_code:
int __fastcall StringCompare(char *s1, const char *a2)
{
if ( s1 && a2 )
return strcmp(s1, a2);
Error("NULL string passed to StringCompare");
return strcmp(s1, a2);
}

canonical_decompiled_code:
int __fastcall func7(char *s1, const char *a2)
{
if ( s1 && a2 )
return strcmp(s1, a2);
Error("NULL string passed to StringCompare");
return strcmp(s1, a2);
}

original_code:
int StringCompare(string s1, string s2)
{
    if (s1 == ((void *)0) || s2 == ((void *)0)) {
        Error("NULL string passed to StringCompare");
    }
    return (strcmp(s1, s2));
}

canonical_original_code:
int StringCompare(char *s1, char *s2)
{
    if (s1 == ((void *)0) || s2 == ((void *)0)) {
        Error("NULL string passed to StringCompare");
    }
    return (strcmp(s1, s2));
}


FindChar

decompiled_code:
__int64 __fastcall FindChar(char a1, const char *a2, int a3)
{
size_t v3; // rbx
char *v4; // rax
__int64 result; // rax

v3 = a3;
if ( !a2 )
Error("NULL string passed to FindChar");
if ( (v3 & 0x80000000) != 0LL )
v3 = 0LL;
if ( v3 <= strlen(a2) && (v4 = strchr(&a2[v3], a1)) != 0LL )
result = (unsigned int)((_DWORD)v4 - (_DWORD)a2);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1, const char *a2, int a3)
{
size_t v3; // rbx
char *v4; // rax
__int64 result; // rax

v3 = a3;
if ( !a2 )
Error("NULL string passed to FindChar");
if ( (v3 & 0x80000000) != 0LL )
v3 = 0LL;
if ( v3 <= strlen(a2) && (v4 = strchr(&a2[v3], a1)) != 0LL )
result = (unsigned int)((_DWORD)v4 - (_DWORD)a2);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int FindChar(char ch, string text, int start)
{
    char *cptr;
    if (text == ((void *)0)) Error("NULL string passed to FindChar");
    if (start < 0) start = 0;
    if (start > strlen(text)) return (-1);
    cptr = strchr(text + start, ch);
    if (cptr == ((void *)0)) return (-1);
    return ((int) (cptr - text));
}

canonical_original_code:
int FindChar(char ch, char *text, int start)
{
    char *cptr;
    if (text == ((void *)0)) Error("NULL string passed to FindChar");
    if (start < 0) start = 0;
    if (start > strlen(text)) return (-1);
    cptr = strchr(text + start, ch);
    if (cptr == ((void *)0)) return (-1);
    return ((int) (cptr - text));
}

variable_types: ch char

variable_types:
text
char *

variable_types: start int

variable_types:
cptr
char *

return_type: int


FindString

decompiled_code:
__int64 __fastcall FindString(char *needle, char *s, int a3)
{
size_t v3; // rbx
char *v4; // rax
__int64 result; // rax

v3 = a3;
if ( needle )
{
if ( s )
goto LABEL_3;
}
else
{
Error("NULL pattern string in FindString");
if ( s )
goto LABEL_3;
}
Error("NULL text string in FindString");
LABEL_3:
if ( (v3 & 0x80000000) != 0LL )
v3 = 0LL;
if ( v3 <= strlen(s) && (v4 = strstr(&s[v3], needle)) != 0LL )
result = (unsigned int)((_DWORD)v4 - (_DWORD)s);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *needle, char *s, int a3)
{
size_t v3; // rbx
char *v4; // rax
__int64 result; // rax

v3 = a3;
if ( needle )
{
if ( s )
goto LABEL_3;
}
else
{
Error("NULL pattern string in FindString");
if ( s )
goto LABEL_3;
}
Error("NULL text string in FindString");
LABEL_3:
if ( (v3 & 0x80000000) != 0LL )
v3 = 0LL;
if ( v3 <= strlen(s) && (v4 = strstr(&s[v3], needle)) != 0LL )
result = (unsigned int)((_DWORD)v4 - (_DWORD)s);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int FindString(string str, string text, int start)
{
    char *cptr;
    if (str == ((void *)0)) Error("NULL pattern string in FindString");
    if (text == ((void *)0)) Error("NULL text string in FindString");
    if (start < 0) start = 0;
    if (start > strlen(text)) return (-1);
    cptr = strstr(text + start, str);
    if (cptr == ((void *)0)) return (-1);
    return ((int) (cptr - text));
}

canonical_original_code:
int FindString(char *str, char *text, int start)
{
    char *cptr;
    if (str == ((void *)0)) Error("NULL pattern string in FindString");
    if (text == ((void *)0)) Error("NULL text string in FindString");
    if (start < 0) start = 0;
    if (start > strlen(text)) return (-1);
    cptr = strstr(text + start, str);
    if (cptr == ((void *)0)) return (-1);
    return ((int) (cptr - text));
}

variable_types:
str
char *


IntegerToString

decompiled_code:
char *__fastcall IntegerToString(unsigned int a1)
{
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

sprintf(v2, "%d", a1);
return CopyString(v2);
}

canonical_decompiled_code:
char *__fastcall func10(unsigned int a1)
{
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

sprintf(v2, "%d", a1);
return func5(v2);
}

original_code:
string IntegerToString(int n)
{
    char buffer[30];
    sprintf(buffer, "%d", n);
    return (CopyString(buffer));
}

canonical_original_code:
char *IntegerToString(int n)
{
    char buffer[30];
    sprintf(buffer, "%d", n);
    return (CopyString(buffer));
}

variable_types: n int

variable_types:
buffer
char [30]

return_type: char *


StringToInteger

decompiled_code:
__int64 __fastcall StringToInteger(const char *a1)
{
char v2; // [rsp+Bh] [rbp-Dh] BYREF
unsigned int v3; // [rsp+Ch] [rbp-Ch] BYREF

if ( !a1 )
Error("NULL string passed to StringToInteger");
if ( (unsigned int)_isoc99_sscanf(a1, " %d %c", &v3, &v2) != 1 )
Error("StringToInteger called on illegal number %s", a1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
char v2; // [rsp+Bh] [rbp-Dh] BYREF
unsigned int v3; // [rsp+Ch] [rbp-Ch] BYREF

if ( !a1 )
Error("NULL string passed to StringToInteger");
if ( (unsigned int)_isoc99_sscanf(a1, " %d %c", &v3, &v2) != 1 )
Error("StringToInteger called on illegal number %s", a1);
return v3;
}

original_code:
int StringToInteger(string s)
{
    int result;
    char dummy;
    if (s == ((void *)0)) {
        Error("NULL string passed to StringToInteger");
    }
    if (sscanf(s, " %d %c", &result, &dummy) != 1) {
        Error("StringToInteger called on illegal number %s", s);
    }
    return (result);
}

canonical_original_code:
int StringToInteger(char *s)
{
    int result;
    char dummy;
    if (s == ((void *)0)) {
        Error("NULL string passed to StringToInteger");
    }
    if (sscanf(s, " %d %c", &result, &dummy) != 1) {
        Error("StringToInteger called on illegal number %s", s);
    }
    return (result);
}

variable_types:
s
char *

variable_types: result int

variable_types: dummy char


RealToString

decompiled_code:
char *__fastcall RealToString(double a1)
{
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

sprintf(v2, "%G", a1);
return CopyString(v2);
}

canonical_decompiled_code:
char *__fastcall func12(double a1)
{
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

sprintf(v2, "%G", a1);
return func5(v2);
}

original_code:
string RealToString(double d)
{
    char buffer[30];
    sprintf(buffer, "%G", d);
    return (CopyString(buffer));
}

canonical_original_code:
char *RealToString(double d)
{
    char buffer[30];
    sprintf(buffer, "%G", d);
    return (CopyString(buffer));
}

variable_types: d double


StringToReal

decompiled_code:
double __fastcall StringToReal(const char *a1)
{
char v2; // [rsp+7h] [rbp-11h] BYREF
double v3; // [rsp+8h] [rbp-10h] BYREF

if ( !a1 )
Error("NULL string passed to StringToReal");
if ( (unsigned int)_isoc99_sscanf(a1, " %lg %c", &v3, &v2) != 1 )
Error("StringToReal called on illegal number %s", a1);
return v3;
}

canonical_decompiled_code:
double __fastcall func13(const char *a1)
{
char v2; // [rsp+7h] [rbp-11h] BYREF
double v3; // [rsp+8h] [rbp-10h] BYREF

if ( !a1 )
Error("NULL string passed to StringToReal");
if ( (unsigned int)_isoc99_sscanf(a1, " %lg %c", &v3, &v2) != 1 )
Error("StringToReal called on illegal number %s", a1);
return v3;
}

original_code:
double StringToReal(string s)
{
    double result;
    char dummy;
    if (s == ((void *)0)) Error("NULL string passed to StringToReal");
    if (sscanf(s, " %lg %c", &result, &dummy) != 1) {
        Error("StringToReal called on illegal number %s", s);
    }
    return (result);
}

canonical_original_code:
double StringToReal(char *s)
{
    double result;
    char dummy;
    if (s == ((void *)0)) Error("NULL string passed to StringToReal");
    if (sscanf(s, " %lg %c", &result, &dummy) != 1) {
        Error("StringToReal called on illegal number %s", s);
    }
    return (result);
}

variable_types: result double

return_type: double


ProtectBlock

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

result = acb;
if ( acb )
result = (*(__int64 (**)(void))(acb + 16))();
return result;
}

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

result = acb;
if ( acb )
result = (*(__int64 (**)(void))(acb + 16))();
return result;
}

original_code:
void ProtectBlock(void *ptr, size_t nbytes)
{
    if (_acb != ((void *)0)) _acb->protectMethod(ptr, nbytes);
}

canonical_original_code:
void ProtectBlock(void *ptr, unsigned long nbytes)
{
    if (_acb != ((void *)0)) _acb->protectMethod(ptr, nbytes);
}

variable_types:
ptr
void *

variable_types:
nbytes
unsigned long

return_type: void


FreeBlock

decompiled_code:
void __fastcall FreeBlock(void *ptr)
{
if ( acb )
(*(void (__fastcall **)(void *))(acb + 8))(ptr);
else
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( acb )
(*(void (__fastcall **)(void *))(acb + 8))(ptr);
else
free(ptr);
}

original_code:
void FreeBlock(void *ptr)
{
    if (_acb == ((void *)0)) {
        free(ptr);
    } else {
        _acb->freeMethod(ptr);
    }
}


Error

decompiled_code:
__int64 Error(char *format, ...)
{
size_t v1; // rdi
char *v2; // r12
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
v1 = (int)(strlen(s) + 1);
if ( acb )
v2 = (char *)(*(__int64 (__fastcall **)(size_t))acb)(v1);
else
v2 = (char *)malloc(v1);
if ( v2 )
strcpy(v2, s);
else
v2 = "No memory available";
if ( !(unsigned int)HandlerExists(&ErrorException) )
{
fprintf(stderr, "Error: %s\n", v2);
exit(1);
}
return RaiseException(&ErrorException, "ErrorException", v2);
}

canonical_decompiled_code:
__int64 func2(char *format, ...)
{
size_t v1; // rdi
char *v2; // r12
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
v1 = (int)(strlen(s) + 1);
if ( acb )
v2 = (char *)(*(__int64 (__fastcall **)(size_t))acb)(v1);
else
v2 = (char *)malloc(v1);
if ( v2 )
strcpy(v2, s);
else
v2 = "No memory available";
if ( !(unsigned int)HandlerExists(&ErrorException) )
{
fprintf(stderr, "Error: %s\n", v2);
exit(1);
}
return RaiseException(&ErrorException, "ErrorException", v2);
}

original_code:
void Error(string msg, ...)
{
    va_list args;
    char errbuf[500 + 1];
    string errmsg;
    int errlen;
    __builtin_va_start(args,msg);
    vsprintf(errbuf, msg, args);
    __builtin_va_end(args);
    errlen = strlen(errbuf);
    if (errlen > 500) {
        fprintf(stderr, "Error: Error Message too long\n");
        exit(1);
    }
    if (_acb == ((void *)0)) {
        errmsg = malloc(errlen + 1);
    } else {
        errmsg = _acb->allocMethod(errlen + 1);
    }
    if (errmsg == ((void *)0)) {
        errmsg = "No memory available";
    } else {
        strcpy(errmsg, errbuf);
    }
    if (HandlerExists(&ErrorException)) {
        RaiseException(&ErrorException, "ErrorException", errmsg);
    } else {
        fprintf(stderr, "Error: %s\n", errmsg);
        exit(1);
    }
}

canonical_original_code:
void Error(char *msg, ...)
{
    __builtin_va_list args;
    char errbuf[-1];
    char *errmsg;
    int errlen;
    __builtin_va_start(args,msg);
    vsprintf(errbuf, msg, args);
    __builtin_va_end(args);
    errlen = strlen(errbuf);
    if (errlen > 500) {
        fprintf(stderr, "Error: Error Message too long\n");
        exit(1);
    }
    if (_acb == ((void *)0)) {
        errmsg = malloc(errlen + 1);
    } else {
        errmsg = _acb->allocMethod(errlen + 1);
    }
    if (errmsg == ((void *)0)) {
        errmsg = "No memory available";
    } else {
        strcpy(errmsg, errbuf);
    }
    if (HandlerExists(&ErrorException)) {
        RaiseException(&ErrorException, "ErrorException", errmsg);
    } else {
        fprintf(stderr, "Error: %s\n", errmsg);
        exit(1);
    }
}

variable_types:
msg
char *

variable_types:
errbuf
char [-1]

variable_types:
errmsg
char *

variable_types: errlen int


GetBlock

decompiled_code:
void *__fastcall GetBlock(size_t a1)
{
void *v1; // r12

if ( acb )
{
v1 = (void *)(*(__int64 (**)(void))acb)();
if ( v1 )
return v1;
}
else
{
v1 = malloc(a1);
if ( v1 )
return v1;
}
Error("No memory available");
return v1;
}

canonical_decompiled_code:
void *__fastcall func3(size_t a1)
{
void *v1; // r12

if ( acb )
{
v1 = (void *)(*(__int64 (**)(void))acb)();
if ( v1 )
return v1;
}
else
{
v1 = malloc(a1);
if ( v1 )
return v1;
}
func2("No memory available");
return v1;
}

original_code:
void *GetBlock(size_t nbytes)
{
    void *result;
    if (_acb == ((void *)0)) {
        result = malloc(nbytes);
    } else {
        result = _acb->allocMethod(nbytes);
    }
    if (result == ((void *)0)) Error("No memory available");
    return (result);
}

canonical_original_code:
void *GetBlock(unsigned long nbytes)
{
    void *result;
    if (_acb == ((void *)0)) {
        result = malloc(nbytes);
    } else {
        result = _acb->allocMethod(nbytes);
    }
    if (result == ((void *)0)) Error("No memory available");
    return (result);
}

variable_types:
result
void *

return_type: void *


GLRadians

decompiled_code:
double __fastcall GLRadians(double a1)
{
return a1 * 3.1415926535 / 180.0;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
return a1 * 3.1415926535 / 180.0;
}

original_code:
double GLRadians(double degrees)
{
    return (degrees * 3.1415926535 / 180);
}

variable_types: degrees double


GLDegrees

decompiled_code:
double __fastcall GLDegrees(double a1)
{
return a1 * 180.0 / 3.1415926535;
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
return a1 * 180.0 / 3.1415926535;
}

original_code:
double GLDegrees(double radians)
{
    return (radians * 180 / 3.1415926535);
}

variable_types: radians double


GLRound

original_code:
int GLRound(double x)
{
    return ((int) floor(x + 0.5));
}

variable_types: x double


GLMin

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

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

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

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

original_code:
int GLMin(int x, int y)
{
    return ((x < y) ? x : y);
}

variable_types: x int

variable_types: y int


GLMax

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

original_code:
int GLMax(int x, int y)
{
    return ((x > y) ? x : y);
}


GLMinF

decompiled_code:
double __fastcall GLMinF(double a1, double a2)
{
return fmin(a1, a2);
}

canonical_decompiled_code:
double __fastcall func5(double a1, double a2)
{
return fmin(a1, a2);
}

original_code:
double GLMinF(double x, double y)
{
    return ((x < y) ? x : y);
}

variable_types: y double


GLMaxF

decompiled_code:
double __fastcall GLMaxF(double a1, double a2)
{
return fmax(a1, a2);
}

canonical_decompiled_code:
double __fastcall func6(double a1, double a2)
{
return fmax(a1, a2);
}

original_code:
double GLMaxF(double x, double y)
{
    return ((x > y) ? x : y);
}


Randomize

decompiled_code:
void Randomize()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

canonical_decompiled_code:
void func0()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

original_code:
void Randomize(void)
{
    srand((int) time(((void *)0)));
}

canonical_original_code:
void Randomize()
{
    srand((int) time(((void *)0)));
}


RandomInteger

decompiled_code:
__int64 __fastcall RandomInteger(int a1, int a2)
{
return (unsigned int)(a1 + (int)((double)(a2 - a1 + 1) * ((double)rand() * 4.656612873077393e-10)));
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
return (unsigned int)(a1 + (int)((double)(a2 - a1 + 1) * ((double)rand() * 4.656612873077393e-10)));
}

original_code:
int RandomInteger(int low, int high)
{
    int k;
    double d;
    d = (double) rand() / ((double) 2147483647 + 1);
    k = (int) (d * (high - low + 1));
    return (low + k);
}

variable_types: low int

variable_types: high int

variable_types: k int


RandomReal

decompiled_code:
double __fastcall RandomReal(double a1, double a2)
{
return (a2 - a1) * ((double)rand() * 4.656612873077393e-10) + a1;
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2)
{
return (a2 - a1) * ((double)rand() * 4.656612873077393e-10) + a1;
}

original_code:
double RandomReal(double low, double high)
{
    double d;
    d = (double) rand() / ((double) 2147483647 + 1);
    return (low + d * (high - low));
}

variable_types: low double

variable_types: high double

variable_types: d double


Pts

decompiled_code:
double __fastcall Pts(double a1)
{
return a1 * 72.0;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
return a1 * 72.0;
}

original_code:
static double Pts(double inches)
{
    return (72 * inches);
}

variable_types: inches double


Radians

decompiled_code:
double __fastcall Radians(double a1)
{
return a1 / 180.0 * 3.1415926535;
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
return a1 / 180.0 * 3.1415926535;
}

original_code:
static double Radians(double degrees)
{
    return (degrees / 180 * 3.1415926535);
}


WritePostScriptHeader

decompiled_code:
int WritePostScriptHeader()
{
fprintf(psfile, "%%!PS-Adobe-1.0\n");
fprintf(psfile, "%%%%Title: graphics window\n");
fprintf(psfile, "%%%%Pages: 1\n");
return fprintf(psfile, "%%%%EndComments\n");
}

canonical_decompiled_code:
int func2()
{
fprintf(psfile, "%%!PS-Adobe-1.0\n");
fprintf(psfile, "%%%%Title: graphics window\n");
fprintf(psfile, "%%%%Pages: 1\n");
return fprintf(psfile, "%%%%EndComments\n");
}

original_code:
static void WritePostScriptHeader(void)
{
    fprintf(psfile, "%%!PS-Adobe-1.0\n");
    fprintf(psfile, "%%%%Title: graphics window\n");
    fprintf(psfile, "%%%%Pages: 1\n");
    fprintf(psfile, "%%%%EndComments\n");
}

canonical_original_code:
static void WritePostScriptHeader()
{
    fprintf(psfile, "%%!PS-Adobe-1.0\n");
    fprintf(psfile, "%%%%Title: graphics window\n");
    fprintf(psfile, "%%%%Pages: 1\n");
    fprintf(psfile, "%%%%EndComments\n");
}


WritePostScriptTrailer

decompiled_code:
size_t WritePostScriptTrailer()
{
nextWrite = ftell(psfile);
return fwrite("showpage\n", 1uLL, 9uLL, psfile);
}

canonical_decompiled_code:
size_t func3()
{
nextWrite = ftell(psfile);
return fwrite("showpage\n", 1uLL, 9uLL, psfile);
}

original_code:
static void WritePostScriptTrailer(void)
{
    nextWrite = ftell(psfile);
    fprintf(psfile, "showpage\n");
}

canonical_original_code:
static void WritePostScriptTrailer()
{
    nextWrite = ftell(psfile);
    fprintf(psfile, "showpage\n");
}


InitCheck

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

result = (unsigned int)initialized;
if ( !initialized )
result = Error("InitGraphics has not been called");
return result;
}

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

result = (unsigned int)initialized;
if ( !initialized )
result = Error("InitGraphics has not been called");
return result;
}

original_code:
static void InitCheck(void)
{
    if (!initialized) Error("InitGraphics has not been called");
}

canonical_original_code:
static void InitCheck()
{
    if (!initialized) Error("InitGraphics has not been called");
}


ResetFilePointer

decompiled_code:
int ResetFilePointer()
{
return fseek(psfile, nextWrite, 0);
}

canonical_decompiled_code:
int func5()
{
return fseek(psfile, nextWrite, 0);
}

original_code:
static void ResetFilePointer(void)
{
    fseek(psfile, nextWrite, 0);
}

canonical_original_code:
static void ResetFilePointer()
{
    fseek(psfile, nextWrite, 0);
}


GetCurrentX

decompiled_code:
double GetCurrentX()
{
InitCheck();
return *((double *)&cy + 1);
}

canonical_decompiled_code:
double func12()
{
func4();
return *((double *)&cy + 1);
}

original_code:
double GetCurrentX(void)
{
    InitCheck();
    return (cx);
}

canonical_original_code:
double GetCurrentX()
{
    InitCheck();
    return (cx);
}


GetCurrentY

decompiled_code:
double GetCurrentY()
{
InitCheck();
return *(double *)&cy;
}

canonical_decompiled_code:
double func13()
{
func4();
return *(double *)&cy;
}

original_code:
double GetCurrentY(void)
{
    InitCheck();
    return (cy);
}

canonical_original_code:
double GetCurrentY()
{
    InitCheck();
    return (cy);
}


GetLine

decompiled_code:
char *GetLine()
{
return ReadLine(stdin);
}

canonical_decompiled_code:
char *func1()
{
return func0(stdin);
}

original_code:
string GetLine(void)
{
    return (ReadLine(stdin));
}

canonical_original_code:
char *GetLine()
{
    return (ReadLine(stdin));
}


FindHandler

decompiled_code:
__int64 __fastcall FindHandler(char **a1)
{
__int64 v1; // r8
int v2; // edx
char ***v3; // rax

v1 = exceptionStack;
if ( exceptionStack )
{
while ( 1 )
{
v2 = *(_DWORD *)(v1 + 200);
if ( v2 > 0 )
break;
LABEL_8:
v1 = *(_QWORD *)(v1 + 312);
if ( !v1 )
return v1;
}
v3 = (char ***)(v1 + 208);
while ( *v3 != &ANY && *v3 != a1 )
{
if ( ++v3 == (char ***)(v1 + 8LL * (unsigned int)(v2 - 1) + 216) )
goto LABEL_8;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1)
{
__int64 v1; // r8
int v2; // edx
char ***v3; // rax

v1 = exceptionStack;
if ( exceptionStack )
{
while ( 1 )
{
v2 = *(_DWORD *)(v1 + 200);
if ( v2 > 0 )
break;
LABEL_8:
v1 = *(_QWORD *)(v1 + 312);
if ( !v1 )
return v1;
}
v3 = (char ***)(v1 + 208);
while ( *v3 != &ANY && *v3 != a1 )
{
if ( ++v3 == (char ***)(v1 + 8LL * (unsigned int)(v2 - 1) + 216) )
goto LABEL_8;
}
}
return v1;
}

original_code:
static context_block *FindHandler(exception *e)
{
    context_block *cb;
    exception *t;
    int i;
    for (cb = exceptionStack; cb != ((void *)0); cb = cb->link) {
        for (i = 0; i < cb->nx; i++) {
            t = cb->array[i];
            if (t == e || t == &ANY) return (cb);
        }
    }
    return (((void *)0));
}

canonical_original_code:
static struct ctx_block *FindHandler(struct exception *e)
{
    struct ctx_block *cb;
    struct exception *t;
    int i;
    for (cb = exceptionStack; cb != ((void *)0); cb = cb->link) {
        for (i = 0; i < cb->nx; i++) {
            t = cb->array[i];
            if (t == e || t == &ANY) return (cb);
        }
    }
    return (((void *)0));
}

variable_types:
e
struct exception *

variable_types: struct ctx_block { struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } jmp[1]; int nx; struct exception { char *name; } *array[10]; struct exception *id; void *value; char *name; struct ctx_block *link; } *

variable_types:
t
struct exception { char *name; } *

variable_types: i int

user_defined_types: struct ctx_block { struct __jmp_buf_tag jmp[1]; int nx; struct exception *array[10]; struct exception *id; void *value; char *name; struct ctx_block *link; }

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


RaiseException

decompiled_code:
void __fastcall __noreturn RaiseException(char **a1, const char *a2, unsigned __int64 a3)
{
struct __jmp_buf_tag *v5; // rbp
size_t v6; // rdi
char *v7; // rdi
char *v8; // rdi
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

v5 = (struct __jmp_buf_tag *)FindHandler(a1);
if ( !v5 )
{
sprintf(v9, "Unhandled exception (%.30s)", a2);
v6 = (int)(strlen(v9) + 1);
if ( acb )
v7 = (char *)((__int64 (__fastcall *)(size_t))*acb)(v6);
else
v7 = (char *)malloc(v6);
if ( v7 )
v8 = strcpy(v7, v9);
else
v8 = "Unhandled exception: unknown";
Error(v8);
}
v5[1].__saved_mask.__val[2] = (unsigned __int64)a1;
v5[1].__saved_mask.__val[3] = a3;
v5[1].__saved_mask.__val[4] = (unsigned __int64)a2;
exceptionStack = (__int64)v5;
longjmp(v5, 2);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(char **a1, const char *a2, unsigned __int64 a3)
{
struct __jmp_buf_tag *v5; // rbp
size_t v6; // rdi
char *v7; // rdi
char *v8; // rdi
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

v5 = (struct __jmp_buf_tag *)func0(a1);
if ( !v5 )
{
sprintf(v9, "Unhandled exception (%.30s)", a2);
v6 = (int)(strlen(v9) + 1);
if ( acb )
v7 = (char *)((__int64 (__fastcall *)(size_t))*acb)(v6);
else
v7 = (char *)malloc(v6);
if ( v7 )
v8 = strcpy(v7, v9);
else
v8 = "Unhandled exception: unknown";
Error(v8);
}
v5[1].__saved_mask.__val[2] = (unsigned __int64)a1;
v5[1].__saved_mask.__val[3] = a3;
v5[1].__saved_mask.__val[4] = (unsigned __int64)a2;
exceptionStack = (__int64)v5;
longjmp(v5, 2);
}

original_code:
void RaiseException(exception *e, string name, void *value)
{
    context_block *cb;
    char errbuf[100 + 1];
    string errmsg;
    int errlen;
    cb = FindHandler(e);
    if (cb == ((void *)0)) {
        sprintf(errbuf, "Unhandled exception (%.30s)", name);
        errlen = strlen(errbuf);
        if (_acb == ((void *)0)) {
            errmsg = malloc(errlen + 1);
        } else {
            errmsg = _acb->allocMethod(errlen + 1);
        }
        if (errmsg == ((void *)0)) {
            errmsg = "Unhandled exception: unknown";
        } else {
            strcpy(errmsg, errbuf);
        }
        Error(errmsg);
    }
    exceptionStack = cb;
    cb->id = e;
    cb->value = value;
    cb->name = name;
    longjmp(cb->jmp, 2);
}

canonical_original_code:
void RaiseException(struct exception *e, char *name, void *value)
{
    struct ctx_block *cb;
    char errbuf[-1];
    char *errmsg;
    int errlen;
    cb = FindHandler(e);
    if (cb == ((void *)0)) {
        sprintf(errbuf, "Unhandled exception (%.30s)", name);
        errlen = strlen(errbuf);
        if (_acb == ((void *)0)) {
            errmsg = malloc(errlen + 1);
        } else {
            errmsg = _acb->allocMethod(errlen + 1);
        }
        if (errmsg == ((void *)0)) {
            errmsg = "Unhandled exception: unknown";
        } else {
            strcpy(errmsg, errbuf);
        }
        Error(errmsg);
    }
    exceptionStack = cb;
    cb->id = e;
    cb->value = value;
    cb->name = name;
    longjmp(cb->jmp, 2);
}

variable_types:
e
struct exception { char *name; } *

variable_types:
name
char *

variable_types:
value
void *

variable_types:
errbuf
char [-1]

variable_types:
errmsg
char *

variable_types: errlen int

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


main

canonical_name: main

repo: gurugio/caos

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("\nStart Build Utility Programs in utils directory\n");
puts("/* *** */ ");
return 0;
}

original_code:
int main(void)
{
 printf("\nStart Build Utility Programs in utils directory\n\n");
 printf("/* *** */ \n");
 return 0;
}

canonical_original_code:
int main()
{
 printf("\nStart Build Utility Programs in utils directory\n\n");
 printf("/* *** */ \n");
 return 0;
}


repo: gurugio/gurugio

decompiled_code:
__int64 __fastcall do_divide_error(unsigned int a1)
{
caos_printf("DEVIDE ERROR ");
return caos_printf("ERROR=%d\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
caos_printf("DEVIDE ERROR ");
return caos_printf("ERROR=%d\n", a1);
}

original_code:
void do_divide_error(int err)
{
 caos_printf("DEVIDE ERROR  ");
 caos_printf("ERROR=%d\n", err);
}

variable_types: err int


decompiled_code:
void do_debug()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void do_debug(int err)
{
}

canonical_original_code:
void do_debug(int err)
{
}


decompiled_code:
void do_nmi()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void do_nmi(int err)
{
}

canonical_original_code:
void do_nmi(int err)
{
}


decompiled_code:
void do_int3()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void do_int3(int err)
{
}

canonical_original_code:
void do_int3(int err)
{
}


decompiled_code:
void do_overflow()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void do_overflow(int err)
{
}

canonical_original_code:
void do_overflow(int err)
{
}


decompiled_code:
void do_bounds()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void do_bounds(int err)
{
}

canonical_original_code:
void do_bounds(int err)
{
}


decompiled_code:
void do_invalid_op()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void do_invalid_op(int err)
{
}

canonical_original_code:
void do_invalid_op(int err)
{
}


decompiled_code:
void do_device_not_available()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void do_device_not_available(int err)
{
}


decompiled_code:
__int64 __fastcall do_doublefault_fn(unsigned int a1)
{
return caos_printf("DOUBLE FAULT, ERROR=%d\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
return caos_printf("DOUBLE FAULT, ERROR=%d\n", a1);
}

original_code:
void do_doublefault_fn(int err)
{
 caos_printf("DOUBLE FAULT, ERROR=%d\n", err);
}


decompiled_code:
void do_coprocessor_segment_overrun()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void do_coprocessor_segment_overrun(int err)
{
}


decompiled_code:
void do_invalid_TSS()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
void do_invalid_TSS(int err)
{
}

canonical_original_code:
void do_invalid_TSS(int err)
{
}


decompiled_code:
void do_segment_not_present()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void do_segment_not_present(int err)
{
}


decompiled_code:
void do_stack_segment()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code:
void do_stack_segment(int err)
{
}

canonical_original_code:
void do_stack_segment(int err)
{
}


decompiled_code:
__int64 __fastcall do_general_protection(unsigned int a1)
{
return caos_printf("ERROR=%x", a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1)
{
return caos_printf("ERROR=%x", a1);
}

original_code:
void do_general_protection(int err)
{
 caos_printf("ERROR=%x", err);
}


decompiled_code:
void do_page_fault()
{
;
}

canonical_decompiled_code:
void func15()
{
;
}

original_code:
void do_page_fault(int err)
{
}

canonical_original_code:
void do_page_fault(int err)
{
}


decompiled_code:
void do_coprocessor_error()
{
;
}

canonical_decompiled_code:
void func16()
{
;
}

original_code:
void do_coprocessor_error(int err)
{
}

canonical_original_code:
void do_coprocessor_error(int err)
{
}


decompiled_code:
void do_alignment_check()
{
;
}

canonical_decompiled_code:
void func17()
{
;
}

original_code:
void do_alignment_check(int err)
{
}

canonical_original_code:
void do_alignment_check(int err)
{
}


decompiled_code:
__int64 do_machine_check()
{
return oops(18LL);
}

canonical_decompiled_code:
__int64 func18()
{
return oops(18LL);
}

original_code:
void do_machine_check(int err)
{
 oops(18);
}


decompiled_code:
__int64 do_simd_coprocessor_error()
{
return oops(19LL);
}

canonical_decompiled_code:
__int64 func19()
{
return oops(19LL);
}

original_code:
void do_simd_coprocessor_error(int err)
{
 oops(19);
}


decompiled_code:
__int64 __fastcall scroll_screen(int a1)
{
int v1; // ebp
__int64 i; // rbx
__int64 v3; // rsi
__int64 v4; // rdi
__int64 result; // rax

if ( a1 > 0 )
{
v1 = a1;
do
{
for ( i = 160LL; i != 4160; i += 160LL )
{
v3 = video_mem + i;
v4 = video_mem + i - 160;
result = caos_memcpy(v4, v3, 160LL);
}
--v1;
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // ebp
__int64 i; // rbx
__int64 v3; // rsi
__int64 v4; // rdi
__int64 result; // rax

if ( a1 > 0 )
{
v1 = a1;
do
{
for ( i = 160LL; i != 4160; i += 160LL )
{
v3 = video_mem + i;
v4 = video_mem + i - 160;
result = caos_memcpy(v4, v3, 160LL);
}
--v1;
}
while ( v1 );
}
return result;
}

original_code:
void scroll_screen(int line)
{
 int i;
 for (; line > 0; line--) {
  for (i=0; i < 25; i++)
   caos_memcpy(video_mem + i*(80 * 2) , video_mem + (i+1)*(80 * 2) , (80 * 2) );
 }
}

variable_types: line int


decompiled_code:
__int64 __fastcall write_screen(__int64 a1, int a2, int a3)
{
__int64 v3; // rax
__int64 v4; // rcx

if ( a3 <= 0 )
return 0LL;
v3 = 0LL;
v4 = 2 * a2 + video_mem;
do
{
*(_BYTE *)(v4 + 2 * v3) = *(_BYTE *)(a1 + v3);
++v3;
}
while ( v3 != a3 );
return (unsigned int)a3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, int a3)
{
__int64 v3; // rax
__int64 v4; // rcx

if ( a3 <= 0 )
return 0LL;
v3 = 0LL;
v4 = 2 * a2 + video_mem;
do
{
*(_BYTE *)(v4 + 2 * v3) = *(_BYTE *)(a1 + v3);
++v3;
}
while ( v3 != a3 );
return (unsigned int)a3;
}

original_code:
int write_screen(const char *msg, int offset, int size)
{
 int l;
 char *vp = video_mem + offset*2;
 for (l=0; l<size; l++) {
  *(vp + 2*l) = msg[l];
 }
 return l;
}

canonical_original_code:
int write_screen(char *msg, int offset, int size)
{
 int l;
 char *vp = video_mem + offset*2;
 for (l=0; l<size; l++) {
  *(vp + 2*l) = msg[l];
 }
 return l;
}

variable_types:
msg
char *

variable_types: offset int

variable_types: size int

variable_types: l int

variable_types:
vp
char *


decompiled_code:
__int64 __fastcall clear_screen(int a1, int a2)
{
__int64 v2; // rdi
_BYTE *v3; // rax
__int64 v4; // rdx

v2 = 2 * a1;
if ( a2 <= 0 )
return 0LL;
v3 = (_BYTE *)(video_mem + v2);
v4 = video_mem + v2 + 2 + 2LL * (unsigned int)(a2 - 1);
do
{
*v3 = 0;
v3 += 2;
}
while ( v3 != (_BYTE *)v4 );
return (unsigned int)a2;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
__int64 v2; // rdi
_BYTE *v3; // rax
__int64 v4; // rdx

v2 = 2 * a1;
if ( a2 <= 0 )
return 0LL;
v3 = (_BYTE *)(video_mem + v2);
v4 = video_mem + v2 + 2 + 2LL * (unsigned int)(a2 - 1);
do
{
*v3 = 0;
v3 += 2;
}
while ( v3 != (_BYTE *)v4 );
return (unsigned int)a2;
}

original_code:
int clear_screen(int offset, int size)
{
 int l;
 char *vp = video_mem + offset*2;
 for (l=0; l<size; l++)
  *(vp + 2*l) = 0;
 return l;
}


decompiled_code:
void __fastcall set_cursor(int a1)
{
__int16 v1; // bx
unsigned __int16 v2; // bp

HIBYTE(v1) = BYTE1(a1);
cursor_offset = a1;
if ( (unsigned int)(a1 - 2000) <= 0x4F )
{
scroll_screen(1);
v1 = cursor_offset - 80;
cursor_offset -= 80;
}
outb(0xD4u, 0xEu);
outb(0xD5u, HIBYTE(v1));
v2 = (unsigned __int8)cursor_offset;
outb(0xD4u, 0xFu);
outb(0xD5u, v2);
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
__int16 v1; // bx
unsigned __int16 v2; // bp

HIBYTE(v1) = BYTE1(a1);
cursor_offset = a1;
if ( (unsigned int)(a1 - 2000) <= 0x4F )
{
func1(1);
v1 = cursor_offset - 80;
cursor_offset -= 80;
}
outb(0xD4u, 0xEu);
outb(0xD5u, HIBYTE(v1));
v2 = (unsigned __int8)cursor_offset;
outb(0xD4u, 0xFu);
outb(0xD5u, v2);
}

original_code:
void set_cursor(int A_dwNewCursorOffset)
{
  unsigned int dwTemp;
  cursor_offset = A_dwNewCursorOffset;
  if ( (cursor_offset/80) == 25) {
   scroll_screen(1);
   cursor_offset -= 80;
  }
  dwTemp = (unsigned int)(cursor_offset >> 8);
  outb((WORD)0x3d4, 0x0e);
  outb((WORD)0x3d5, dwTemp);
  dwTemp = (unsigned int)(cursor_offset & (unsigned int)0xff);
  outb((WORD)0x3d4, 0x0f);
  outb((WORD)0x3d5, dwTemp);
}

canonical_original_code:
void set_cursor(int A_dwNewCursorOffset)
{
  unsigned int dwTemp;
  cursor_offset = A_dwNewCursorOffset;
  if ( (cursor_offset/80) == 25) {
   scroll_screen(1);
   cursor_offset -= 80;
  }
  dwTemp = (unsigned int)(cursor_offset >> 8);
  outb((unsigned short)0x3d4, 0x0e);
  outb((unsigned short)0x3d5, dwTemp);
  dwTemp = (unsigned int)(cursor_offset & (unsigned int)0xff);
  outb((unsigned short)0x3d4, 0x0f);
  outb((unsigned short)0x3d5, dwTemp);
}

variable_types:
dwTemp
unsigned int


decompiled_code:
void init_screen()
{
cursor_offset = 0;
video_mem = 3221979136LL;
set_cursor(0);
}

canonical_decompiled_code:
void func5()
{
cursor_offset = 0;
video_mem = 3221979136LL;
func4(0);
}

original_code:
void init_screen(void)
{
  video_mem = (char *)0xc00b8000;
  cursor_offset = 0;
  set_cursor(cursor_offset);
}

canonical_original_code:
void init_screen()
{
  video_mem = (char *)0xc00b8000;
  cursor_offset = 0;
  set_cursor(cursor_offset);
}


decompiled_code:
void __fastcall caos_putchar(char a1)
{
*(_BYTE *)(video_mem + (unsigned int)(2 * cursor_offset++)) = a1;
set_cursor(cursor_offset);
}

canonical_decompiled_code:
void __fastcall func6(char a1)
{
*(_BYTE *)(video_mem + (unsigned int)(2 * cursor_offset++)) = a1;
func4(cursor_offset);
}

original_code:
void caos_putchar(char A_byteChar)
{
  *(video_mem + (cursor_offset*2) ) = A_byteChar;
  cursor_offset++;
  set_cursor(cursor_offset);
}


original_code:
int print_hex(char *buf, int a, char flag)
{
 unsigned char *p;
 unsigned char v[10];
 int i=0, j=0;
 int count=0;
 if (a == 0) {
  *buf = 0x30;
  return 1;
 }
 p = (unsigned char *)&a;
 for (i = sizeof(int); i > 0; i--) {
  if ( (p[i-1] >> 4) <= 9)
   v[count] = (p[i-1] >> 4) + 0x30;
  else
   v[count] = (p[i-1] >> 4) + 0x37;
  count++;
  if ( (p[i-1] & 0x0f) <= 9)
   v[count] = (p[i-1] & 0x0f) + 0x30;
  else
   v[count] = (p[i-1] & 0x0f) + 0x37;
  count++;
 }
 i=0;
 while (v[i] == '0')
  i++;
 count = 8 - i;
 for (j=0; j<count; j++)
  buf[j] = v[i++];
 return count;
}

canonical_original_code:
int print_hex(char *buf, int a, char flag)
{
 unsigned char *p;
 unsigned char v[10];
 int i = 0; int j = 0;
 int count = 0;
 if (a == 0) {
  *buf = 0x30;
  return 1;
 }
 p = (unsigned char *)&a;
 for (i = sizeof(int); i > 0; i--) {
  if ( (p[i-1] >> 4) <= 9)
   v[count] = (p[i-1] >> 4) + 0x30;
  else
   v[count] = (p[i-1] >> 4) + 0x37;
  count++;
  if ( (p[i-1] & 0x0f) <= 9)
   v[count] = (p[i-1] & 0x0f) + 0x30;
  else
   v[count] = (p[i-1] & 0x0f) + 0x37;
  count++;
 }
 i=0;
 while (v[i] == '0')
  i++;
 count = 8 - i;
 for (j=0; j<count; j++)
  buf[j] = v[i++];
 return count;
}

variable_types:
buf
char *

variable_types: a int

variable_types: flag char

variable_types:
p
unsigned char *

variable_types:
v
unsigned char [10]

variable_types: j int

variable_types: count int


decompiled_code:
__int64 __fastcall print_decimal(_BYTE *a1, int a2)
{
int v2; // er9
__int64 v3; // rcx
int v4; // er8
unsigned int v5; // eax
unsigned int v6; // esi
char v7; // dl
char *v8; // rax
_BYTE *v9; // rcx
__int64 result; // rax
char v11[10]; // [rsp+0h] [rbp-Ah] BYREF

if ( a2 )
{
v2 = 0;
if ( a2 < 0 )
{
*a1 = 45;
a2 = -a2;
v2 = 1;
}
v3 = 0LL;
do
{
v4 = v3;
v5 = a2 / 0xAu;
v6 = a2 % 0xAu;
v11[v3] = v6;
v7 = v6;
++v3;
a2 = v5;
}
while ( v5 );
v8 = &v11[v4];
v9 = &a1[v4 + 1];
while ( 1 )
{
++a1;
--v8;
*(a1 - 1) = v7 + 48;
if ( v9 == a1 )
break;
v7 = *v8;
}
result = (unsigned int)(v2 + v4 + 1);
}
else
{
*a1 = 48;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1, int a2)
{
int v2; // er9
__int64 v3; // rcx
int v4; // er8
unsigned int v5; // eax
unsigned int v6; // esi
char v7; // dl
char *v8; // rax
_BYTE *v9; // rcx
__int64 result; // rax
char v11[10]; // [rsp+0h] [rbp-Ah] BYREF

if ( a2 )
{
v2 = 0;
if ( a2 < 0 )
{
*a1 = 45;
a2 = -a2;
v2 = 1;
}
v3 = 0LL;
do
{
v4 = v3;
v5 = a2 / 0xAu;
v6 = a2 % 0xAu;
v11[v3] = v6;
v7 = v6;
++v3;
a2 = v5;
}
while ( v5 );
v8 = &v11[v4];
v9 = &a1[v4 + 1];
while ( 1 )
{
++a1;
--v8;
*(a1 - 1) = v7 + 48;
if ( v9 == a1 )
break;
v7 = *v8;
}
result = (unsigned int)(v2 + v4 + 1);
}
else
{
*a1 = 48;
result = 1LL;
}
return result;
}

original_code:
int print_decimal(char *A_szBuffer, int a, char flag)
{
 unsigned char v[10];
 int i = 0;
 int count = 0;
 if (a == 0) {
  *A_szBuffer = 0x30;
  return 1;
 }
 if (a & 0x80000000) {
  *A_szBuffer = '-';
  count++;
  a = -a;
 }
 while (a > 0) {
  v[i++] = a % 10;
  a /= 10;
 }
 for (--i; i >= 0; i--) {
  *A_szBuffer++ = v[i]+0x30;
  count++;
 }
 return count;
}

variable_types: i int


decompiled_code:
__int64 __fastcall caos_printf(unsigned __int8 *a1)
{
char v1; // di
__int64 v2; // rbx
unsigned int v3; // er12
int v5[6]; // [rsp+10h] [rbp-18h] BYREF

caos_vsprintf(sz, a1, v5);
v1 = sz[0];
if ( sz[0] )
{
v2 = 1LL;
while ( 1 )
{
v3 = v2;
if ( v1 == 10 )
break;
if ( v1 == 8 )
{
++v2;
caos_delchar(1);
v1 = sz[v2 - 1];
if ( !v1 )
return v3;
}
else
{
caos_putchar(v1);
LABEL_4:
v1 = sz[v2++];
if ( !v1 )
return v3;
}
}
set_cursor(16 * (5 * (cursor_offset / 0x50u) + 5));
goto LABEL_4;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 *a1)
{
char v1; // di
__int64 v2; // rbx
unsigned int v3; // er12
int v5[6]; // [rsp+10h] [rbp-18h] BYREF

func10(sz, a1, v5);
v1 = sz[0];
if ( sz[0] )
{
v2 = 1LL;
while ( 1 )
{
v3 = v2;
if ( v1 == 10 )
break;
if ( v1 == 8 )
{
++v2;
func7(1);
v1 = sz[v2 - 1];
if ( !v1 )
return v3;
}
else
{
func6(v1);
LABEL_4:
v1 = sz[v2++];
if ( !v1 )
return v3;
}
}
func4(16 * (5 * (cursor_offset / 0x50u) + 5));
goto LABEL_4;
}
return 0LL;
}

original_code:
int caos_printf(const char *format, ...)
{
  va_list ap;
  int i = 0;
  (void)((ap)=(va_list)&(format)+sizeof(format));
  caos_vsprintf(sz, format, ap);
  (void)((ap)=(void *)0);
  while (sz[i] != '\0') {
   if (sz[i] == '\n') {
    set_cursor( ((int)(cursor_offset/80) + 1)*80 );
    i++;
    continue;
   } else if (sz[i] == '\b') {
    caos_delchar(1);
    i++;
    continue;
   }
   caos_putchar(sz[i++]);
  }
  return i;
}

canonical_original_code:
int caos_printf(char *format, ...)
{
  char *ap;
  int i = 0;
  (void)((ap)=(char *)&(format)+sizeof(format));
  caos_vsprintf(sz, format, ap);
  (void)((ap)=(void *)0);
  while (sz[i] != '\0') {
   if (sz[i] == '\n') {
    set_cursor( ((int)(cursor_offset/80) + 1)*80 );
    i++;
    continue;
   } else if (sz[i] == '\b') {
    caos_delchar(1);
    i++;
    continue;
   }
   caos_putchar(sz[i++]);
  }
  return i;
}

variable_types:
format
char *

variable_types:
ap
char *


decompiled_code:
// attributes: thunk
__int64 set_idtr()
{
return lidt();
}

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

original_code:
void set_idtr(void)
{
 _lidt();
}

canonical_original_code:
void set_idtr()
{
 _lidt();
}


decompiled_code:
__int64 init_exception()
{
set_trap_gate(0, (int)&divide_error);
set_trap_gate(1, (int)&debug);
set_intr_gate(2, (int)&nmi);
set_system_gate(3, (int)&int3);
set_system_gate(4, (int)&overflow);
set_system_gate(5, (int)&bounds);
set_trap_gate(6, (int)&invalid_op);
set_trap_gate(7, (int)&device_not_available);
set_trap_gate(8, (int)&doublefault_fn);
set_trap_gate(9, (int)&coprocessor_segment_overrun);
set_trap_gate(10, (int)&invalid_TSS);
set_trap_gate(11, (int)&segment_not_present);
set_trap_gate(12, (int)&stack_segment);
set_trap_gate(13, (int)&general_protection);
set_intr_gate(14, (int)&page_fault);
set_trap_gate(16, (int)&coprocessor_error);
set_trap_gate(17, (int)&alignment_check);
set_trap_gate(18, (int)&machine_check);
set_trap_gate(19, (int)&simd_coprocessor_error);
return set_system_gate(128, (int)&system_call);
}

canonical_decompiled_code:
__int64 func4()
{
func2(0, (int)&divide_error);
func2(1, (int)&debug);
func0(2, (int)&nmi);
func1(3, (int)&int3);
func1(4, (int)&overflow);
func1(5, (int)&bounds);
func2(6, (int)&invalid_op);
func2(7, (int)&device_not_available);
func2(8, (int)&doublefault_fn);
func2(9, (int)&coprocessor_segment_overrun);
func2(10, (int)&invalid_TSS);
func2(11, (int)&segment_not_present);
func2(12, (int)&stack_segment);
func2(13, (int)&general_protection);
func0(14, (int)&page_fault);
func2(16, (int)&coprocessor_error);
func2(17, (int)&alignment_check);
func2(18, (int)&machine_check);
func2(19, (int)&simd_coprocessor_error);
return func1(128, (int)&system_call);
}

original_code:
void init_exception(void)
{
 set_trap_gate(0, _divide_error);
 set_trap_gate(1, _debug);
 set_intr_gate(2, _nmi);
 set_system_gate(3, _int3);
 set_system_gate(4, _overflow);
 set_system_gate(5, _bounds);
 set_trap_gate(6, _invalid_op);
 set_trap_gate(7, _device_not_available);
 set_trap_gate(8, _doublefault_fn);
 set_trap_gate(9, _coprocessor_segment_overrun);
 set_trap_gate(10, _invalid_TSS);
 set_trap_gate(11, _segment_not_present);
 set_trap_gate(12, _stack_segment);
 set_trap_gate(13, _general_protection);
 set_intr_gate(14, _page_fault);
 set_trap_gate(16, _coprocessor_error);
 set_trap_gate(17, _alignment_check);
 set_trap_gate(18, _machine_check);
 set_trap_gate(19, _simd_coprocessor_error);
 set_system_gate(128, _system_call);
}

canonical_original_code:
void init_exception()
{
 set_trap_gate(0, _divide_error);
 set_trap_gate(1, _debug);
 set_intr_gate(2, _nmi);
 set_system_gate(3, _int3);
 set_system_gate(4, _overflow);
 set_system_gate(5, _bounds);
 set_trap_gate(6, _invalid_op);
 set_trap_gate(7, _device_not_available);
 set_trap_gate(8, _doublefault_fn);
 set_trap_gate(9, _coprocessor_segment_overrun);
 set_trap_gate(10, _invalid_TSS);
 set_trap_gate(11, _segment_not_present);
 set_trap_gate(12, _stack_segment);
 set_trap_gate(13, _general_protection);
 set_intr_gate(14, _page_fault);
 set_trap_gate(16, _coprocessor_error);
 set_trap_gate(17, _alignment_check);
 set_trap_gate(18, _machine_check);
 set_trap_gate(19, _simd_coprocessor_error);
 set_system_gate(128, _system_call);
}


decompiled_code:
__int64 init_idt()
{
int v0; // ecx

caos_printf("Init IDT..\n");
v0 = 0;
idt = 3221225472LL;
do
set_trap_gate(v0, (int)&ignore_isr);
while ( v0 != 256 );
init_exception();
return init_irq();
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // ecx

caos_printf("Init IDT..\n");
v0 = 0;
idt = 3221225472LL;
do
func2(v0, (int)&ignore_isr);
while ( v0 != 256 );
func4();
return init_irq();
}

original_code:
void init_idt(void)
{
 int nIndex = 0;
 caos_printf("Init IDT..\n");
 idt = (idt_t *)0xC0000000;
 for (nIndex = 0; nIndex < 256; nIndex++) {
  set_trap_gate(nIndex, _ignore_isr);
 }
 init_exception();
 init_irq();
}

canonical_original_code:
void init_idt()
{
 int nIndex = 0;
 caos_printf("Init IDT..\n");
 idt = (struct _IDT *)0xC0000000;
 for (nIndex = 0; nIndex < 256; nIndex++) {
  set_trap_gate(nIndex, _ignore_isr);
 }
 init_exception();
 init_irq();
}

variable_types: nIndex int

user_defined_types: struct _IDT { unsigned short OffsetLow; unsigned short SegSelector; unsigned short Type; unsigned short OffsetHigh; }


decompiled_code:
void init_pic()
{
outb(0x20u, 0x11u);
outb(0xA0u, 0x11u);
outb(0x21u, 0x20u);
outb(0xA1u, 0x28u);
outb(0x21u, 4u);
outb(0xA1u, 2u);
outb(0x21u, 1u);
outb(0xA1u, 1u);
outb(0x21u, (unsigned __int8)irq_mask);
outb(0xA1u, HIBYTE(irq_mask));
}

canonical_decompiled_code:
void func0()
{
outb(0x20u, 0x11u);
outb(0xA0u, 0x11u);
outb(0x21u, 0x20u);
outb(0xA1u, 0x28u);
outb(0x21u, 4u);
outb(0xA1u, 2u);
outb(0x21u, 1u);
outb(0xA1u, 1u);
outb(0x21u, (unsigned __int8)irq_mask);
outb(0xA1u, HIBYTE(irq_mask));
}

original_code:
void init_pic(void)
{
 outb( 0x20, 0x11 );
 outb( 0xa0, 0x11 );
 outb( 0x21, 0x20 );
 outb( 0xa1, 0x20 +8 );
 outb( 0x21, 0x04 );
 outb( 0xa1, 0x02 );
 outb( 0x21, 0x01 );
 outb( 0xa1, 0x01 );
 outb( 0x21, (unsigned char)(irq_mask&0xff) );
 outb( 0xa1, (unsigned char)((irq_mask>>8)&0xff) );
}

canonical_original_code:
void init_pic()
{
 outb( 0x20, 0x11 );
 outb( 0xa0, 0x11 );
 outb( 0x21, 0x20 );
 outb( 0xa1, 0x20 +8 );
 outb( 0x21, 0x04 );
 outb( 0xa1, 0x02 );
 outb( 0x21, 0x01 );
 outb( 0xa1, 0x01 );
 outb( 0x21, (unsigned char)(irq_mask&0xff) );
 outb( 0xa1, (unsigned char)((irq_mask>>8)&0xff) );
}


decompiled_code:
__int64 init_irq()
{
__int64 *v0; // rax

init_pic();
v0 = &irqhandler;
do
*v0++ = (__int64)&ignore_irq;
while ( v0 != &irqhandler + 16 );
set_intr_gate(32LL, &irq_0);
return set_intr_gate(33LL, &irq_1);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 *v0; // rax

func0();
v0 = &irqhandler;
do
*v0++ = (__int64)&ignore_irq;
while ( v0 != &irqhandler + 16 );
set_intr_gate(32LL, &irq_0);
return set_intr_gate(33LL, &irq_1);
}

original_code:
void init_irq(void)
{
 int i;
 init_pic();
 for( i = 0; i < 16; i++ )
  irqhandler[i] = _ignore_irq;
 set_intr_gate(0x20 +0, _irq_0);
 set_intr_gate(0x20 +1, _irq_1);
}

canonical_original_code:
void init_irq()
{
 int i;
 init_pic();
 for( i = 0; i < 16; i++ )
  irqhandler[i] = _ignore_irq;
 set_intr_gate(0x20 +0, _irq_0);
 set_intr_gate(0x20 +1, _irq_1);
}


decompiled_code:
void __fastcall enable_irq(int a1)
{
__int16 v1; // ax

v1 = irq_mask & __ROL4__(-2, a1);
irq_mask = v1;
if ( a1 <= 7 )
outb(0x21u, (unsigned __int8)v1);
else
outb(0xA1u, HIBYTE(v1));
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
__int16 v1; // ax

v1 = irq_mask & __ROL4__(-2, a1);
irq_mask = v1;
if ( a1 <= 7 )
outb(0x21u, (unsigned __int8)v1);
else
outb(0xA1u, HIBYTE(v1));
}

original_code:
void enable_irq(int irq)
{
 irq_mask = irq_mask & ~(1<<irq);
 if( irq >= 8 )
  outb( 0xa1, (unsigned char)((irq_mask>>8)&0xff) );
 else
  outb( 0x21, (unsigned char)(irq_mask&0xff) );
}

variable_types: irq int


decompiled_code:
void __fastcall disable_irq(int a1)
{
__int16 v1; // ax

v1 = irq_mask | (1 << a1);
irq_mask = v1;
if ( a1 <= 7 )
outb(0x21u, (unsigned __int8)v1);
else
outb(0xA1u, HIBYTE(v1));
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
__int16 v1; // ax

v1 = irq_mask | (1 << a1);
irq_mask = v1;
if ( a1 <= 7 )
outb(0x21u, (unsigned __int8)v1);
else
outb(0xA1u, HIBYTE(v1));
}

original_code:
void disable_irq(int irq)
{
 irq_mask = irq_mask | (1<<irq);
 if( irq >= 8 )
  outb( 0xa1, (unsigned char)((irq_mask>>8)&0xff) );
 else
  outb( 0x21, (unsigned char)(irq_mask&0xff) );
}


decompiled_code:
void __fastcall register_irq(int a1, __int64 a2)
{
irqhandler[a1] = a2;
}

canonical_decompiled_code:
void __fastcall func4(int a1, __int64 a2)
{
irqhandler[a1] = a2;
}

original_code:
void register_irq(int irq, irqhandler_t handler)
{
 irqhandler[irq] = handler;
}

canonical_original_code:
void register_irq(int irq, void (*handler)())
{
 irqhandler[irq] = handler;
}

variable_types:
handler
void (*)()


decompiled_code:
void __fastcall unregister_irq(int a1)
{
irqhandler[a1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func5(int a1)
{
irqhandler[a1] = 0LL;
}

original_code:
void unregister_irq(int irq)
{
 irqhandler[irq] = (void *)0;
}


decompiled_code:
void __fastcall do_irq(int a1)
{
disable_irq(a1);
outb(0x20u, 0x20u);
_enable();
}

canonical_decompiled_code:
void __fastcall func6(int a1)
{
func3(a1);
outb(0x20u, 0x20u);
_enable();
}

original_code:
void do_irq(int irq)
{
 disable_irq(irq);
 outb(0x20, 0x20);
 __asm__ __volatile__("sti":::"memory");
}


decompiled_code:
// attributes: thunk
void __fastcall end_irq(int a1)
{
enable_irq(a1);
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
func2(a1);
}

original_code:
void end_irq(int irq)
{
 enable_irq(irq);
}


decompiled_code:
void __fastcall handle_irq(int a1)
{
do_irq(a1);
((void (*)(void))irqhandler[a1])();
end_irq(a1);
}

canonical_decompiled_code:
void __fastcall func8(int a1)
{
func6(a1);
((void (*)(void))irqhandler[a1])();
func7(a1);
}

original_code:
void handle_irq(int irq)
{
 do_irq(irq);
 irqhandler[irq]();
 end_irq(irq);
}


decompiled_code:
__int64 init_node()
{
__int64 result; // rax
__int64 v1; // rdx

result = (unsigned int)phy_mem_size;
*(&contig_page_data + 1) = (__int64)&contig_page_data;
*(&contig_page_data + 2) = 0LL;
*(&contig_page_data + 4) = result;
*(&contig_page_data + 3) = (__int64)"NORMAL";
contig_page_data = result << 8;
*(&contig_page_data + 5) = result << 8;
v1 = mem_map;
*((_DWORD *)&contig_page_data + 12) = 1;
*(&contig_page_data + 7) = v1;
*(&contig_page_data + 8) = 0LL;
*(&contig_page_data + 9) = result;
*((_DWORD *)&contig_page_data + 20) = 0;
*(&contig_page_data + 11) = 0LL;
return result;
}

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

result = (unsigned int)phy_mem_size;
*(&contig_page_data + 1) = (__int64)&contig_page_data;
*(&contig_page_data + 2) = 0LL;
*(&contig_page_data + 4) = result;
*(&contig_page_data + 3) = (__int64)"NORMAL";
contig_page_data = result << 8;
*(&contig_page_data + 5) = result << 8;
v1 = mem_map;
*((_DWORD *)&contig_page_data + 12) = 1;
*(&contig_page_data + 7) = v1;
*(&contig_page_data + 8) = 0LL;
*(&contig_page_data + 9) = result;
*((_DWORD *)&contig_page_data + 20) = 0;
*(&contig_page_data + 11) = 0LL;
return result;
}

original_code:
void init_node(void)
{
 contig_page_data.node_zones.free_pages = phy_mem_size*(1UL<<20)/(1UL<<12);
 contig_page_data.node_zones.size = phy_mem_size;
 contig_page_data.node_zones.zone_pgdat = &contig_page_data;
 contig_page_data.node_zones.zone_start_paddr = 0x0;
 contig_page_data.node_zones.name = "NORMAL";
 contig_page_data.node_zones.pages = (phy_mem_size * (1UL<<20))/(1UL<<12);
 contig_page_data.nr_zones = 1;
 contig_page_data.node_mem_map = mem_map;
 contig_page_data.node_start_paddr = 0;
 contig_page_data.node_size = phy_mem_size;
 contig_page_data.node_id = 0;
 contig_page_data.node_next = (void *)0;
}

canonical_original_code:
void init_node()
{
 contig_page_data.node_zones.free_pages = phy_mem_size*(1UL<<20)/(1UL<<12);
 contig_page_data.node_zones.size = phy_mem_size;
 contig_page_data.node_zones.zone_pgdat = &contig_page_data;
 contig_page_data.node_zones.zone_start_paddr = 0x0;
 contig_page_data.node_zones.name = "NORMAL";
 contig_page_data.node_zones.pages = (phy_mem_size * (1UL<<20))/(1UL<<12);
 contig_page_data.nr_zones = 1;
 contig_page_data.node_mem_map = mem_map;
 contig_page_data.node_start_paddr = 0;
 contig_page_data.node_size = phy_mem_size;
 contig_page_data.node_id = 0;
 contig_page_data.node_next = (void *)0;
}


decompiled_code:
__int64 init_mem_map()
{
int v0; // ebx
unsigned int v1; // ebp
__int64 v2; // rdx
unsigned __int64 v3; // r13
__int64 v4; // rsi
__int64 v5; // rdi
__int64 v6; // rcx
__int64 v7; // rdx
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rdx
unsigned int v11; // eax
__int64 v12; // rdx
_DWORD *v13; // rax
__int64 v14; // rdx
__int64 result; // rax
__int64 v16; // rdx
__int64 v17; // rdx

v0 = 0;
v1 = phy_mem_size << 8;
v2 = (unsigned int)(10240 * phy_mem_size);
v3 = (unsigned __int64)(int)v2 >> 12;
caos_printf(
"page count = %d, mem_map_size = %d, mem_map_page = %d\n",
(unsigned int)(phy_mem_size << 8),
v2,
(unsigned int)v3);
mem_map = ((__int64 (*)(void))alloc_bootmem)();
v4 = mem_map;
caos_printf("mem_map -> %x ", mem_map);
if ( (int)v3 > 1 )
{
do
{
++v0;
v4 = ((__int64 (*)(void))alloc_bootmem)();
caos_printf("%x ", v4);
}
while ( v0 != (_DWORD)v3 - 1 );
}
caos_printf("\n");
v5 = mem_map;
v6 = v1;
v7 = 0LL;
if ( v1 )
{
do
{
INIT_LIST_HEAD((_QWORD *)(40 * v7 + v5));
v5 = mem_map;
v9 = mem_map + v8;
*(_QWORD *)(v9 + 16) = v10;
v7 = v10 + 1;
*(_DWORD *)(v9 + 24) = 0;
*(_QWORD *)(v9 + 32) = 0LL;
}
while ( v7 != v6 );
}
v11 = (unsigned int)alloc_bootmem(v5, v4, v7, v6) >> 12;
v12 = v11;
if ( v11 )
{
v13 = (_DWORD *)(mem_map + 24);
v14 = mem_map + 24 + 40 * v12;
do
{
*v13 = 1;
v13 += 10;
}
while ( v13 != (_DWORD *)v14 );
}
result = (unsigned int)kernel_size >> 12;
v16 = (unsigned int)(result + 1);
if ( (unsigned int)v16 > 0x100 )
{
result = mem_map + 10264;
v17 = mem_map + 40 * v16 + 24;
do
{
*(_DWORD *)result = 1;
result += 40LL;
}
while ( v17 != result );
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // ebx
unsigned int v1; // ebp
__int64 v2; // rdx
unsigned __int64 v3; // r13
__int64 v4; // rsi
__int64 v5; // rdi
__int64 v6; // rcx
__int64 v7; // rdx
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rdx
unsigned int v11; // eax
__int64 v12; // rdx
_DWORD *v13; // rax
__int64 v14; // rdx
__int64 result; // rax
__int64 v16; // rdx
__int64 v17; // rdx

v0 = 0;
v1 = phy_mem_size << 8;
v2 = (unsigned int)(10240 * phy_mem_size);
v3 = (unsigned __int64)(int)v2 >> 12;
caos_printf(
"page count = %d, mem_map_size = %d, mem_map_page = %d\n",
(unsigned int)(phy_mem_size << 8),
v2,
(unsigned int)v3);
mem_map = ((__int64 (*)(void))alloc_bootmem)();
v4 = mem_map;
caos_printf("mem_map -> %x ", mem_map);
if ( (int)v3 > 1 )
{
do
{
++v0;
v4 = ((__int64 (*)(void))alloc_bootmem)();
caos_printf("%x ", v4);
}
while ( v0 != (_DWORD)v3 - 1 );
}
caos_printf("\n");
v5 = mem_map;
v6 = v1;
v7 = 0LL;
if ( v1 )
{
do
{
func0((_QWORD *)(40 * v7 + v5));
v5 = mem_map;
v9 = mem_map + v8;
*(_QWORD *)(v9 + 16) = v10;
v7 = v10 + 1;
*(_DWORD *)(v9 + 24) = 0;
*(_QWORD *)(v9 + 32) = 0LL;
}
while ( v7 != v6 );
}
v11 = (unsigned int)alloc_bootmem(v5, v4, v7, v6) >> 12;
v12 = v11;
if ( v11 )
{
v13 = (_DWORD *)(mem_map + 24);
v14 = mem_map + 24 + 40 * v12;
do
{
*v13 = 1;
v13 += 10;
}
while ( v13 != (_DWORD *)v14 );
}
result = (unsigned int)kernel_size >> 12;
v16 = (unsigned int)(result + 1);
if ( (unsigned int)v16 > 0x100 )
{
result = mem_map + 10264;
v17 = mem_map + 40 * v16 + 24;
do
{
*(_DWORD *)result = 1;
result += 40LL;
}
while ( v17 != result );
}
return result;
}

original_code:
void init_mem_map(void)
{
 unsigned int page_count;
 int mem_map_size;
 int mem_map_page;
 int l;
 unsigned int tmp;
 page_count = (phy_mem_size * (1UL<<20))/(1UL<<12);
 mem_map_size = page_count * sizeof(mem_map_t);
 mem_map_page = mem_map_size / (1UL<<12);
 caos_printf("page count = %d, mem_map_size = %d, mem_map_page = %d\n", page_count, mem_map_size, mem_map_page);
 mem_map = (mem_map_t *)alloc_bootmem();
 caos_printf("mem_map -> %x ", (unsigned long)mem_map);
 for (l=0; l<mem_map_page-1; l++) {
  caos_printf("%x ", (unsigned long)alloc_bootmem());
 }
 caos_printf("\n");
 for (l=0; l<page_count; l++) {
  INIT_LIST_HEAD(&mem_map[l].list);
  mem_map[l].index = l;
  mem_map[l].count = 0;
  mem_map[l].flags = 0;
 }
 tmp = (unsigned int)alloc_bootmem();
 for (l=0; l<tmp/(1UL<<12); l++)
  mem_map[l].count = 1;
 for (l=0x100; l<(kernel_size/(1UL<<12))+1; l++)
  mem_map[l].count = 1;
}

canonical_original_code:
void init_mem_map()
{
 unsigned int page_count;
 int mem_map_size;
 int mem_map_page;
 int l;
 unsigned int tmp;
 page_count = (phy_mem_size * (1UL<<20))/(1UL<<12);
 mem_map_size = page_count * sizeof(mem_map_t);
 mem_map_page = mem_map_size / (1UL<<12);
 caos_printf("page count = %d, mem_map_size = %d, mem_map_page = %d\n", page_count, mem_map_size, mem_map_page);
 mem_map = (struct page *)alloc_bootmem();
 caos_printf("mem_map -> %x ", (unsigned long)mem_map);
 for (l=0; l<mem_map_page-1; l++) {
  caos_printf("%x ", (unsigned long)alloc_bootmem());
 }
 caos_printf("\n");
 for (l=0; l<page_count; l++) {
  INIT_LIST_HEAD(&mem_map[l].list);
  mem_map[l].index = l;
  mem_map[l].count = 0;
  mem_map[l].flags = 0;
 }
 tmp = (unsigned int)alloc_bootmem();
 for (l=0; l<tmp/(1UL<<12); l++)
  mem_map[l].count = 1;
 for (l=0x100; l<(kernel_size/(1UL<<12))+1; l++)
  mem_map[l].count = 1;
}

variable_types:
tmp
unsigned int

user_defined_types: struct page { struct list_head list; unsigned long index; int count; unsigned long flags; }

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
__int64 setup_memory()
{
caos_printf("memory size = %dMB, kernel size = %dbytes\n", (unsigned int)phy_mem_size, (unsigned int)kernel_size);
bootmem_init((unsigned int)kernel_size);
paging_init((unsigned int)phy_mem_size);
init_mem_map();
return init_node();
}

canonical_decompiled_code:
__int64 func3()
{
caos_printf("memory size = %dMB, kernel size = %dbytes\n", (unsigned int)phy_mem_size, (unsigned int)kernel_size);
bootmem_init((unsigned int)kernel_size);
paging_init((unsigned int)phy_mem_size);
func2();
return func1();
}

original_code:
void setup_memory(void)
{
 caos_printf("memory size = %dMB, kernel size = %dbytes\n", phy_mem_size, kernel_size);
 bootmem_init(kernel_size);
 paging_init(phy_mem_size);
 init_mem_map();
 init_node();
}

canonical_original_code:
void setup_memory()
{
 caos_printf("memory size = %dMB, kernel size = %dbytes\n", phy_mem_size, kernel_size);
 bootmem_init(kernel_size);
 paging_init(phy_mem_size);
 init_mem_map();
 init_node();
}


decompiled_code:
__int64 print_busy_pages()
{
int v0; // ebx
__int64 v1; // rbp
__int64 i; // rbx
__int64 v3; // rax

v0 = phy_mem_size << 8;
caos_printf("Busy Pages : ");
if ( v0 > 0 )
{
v1 = (unsigned int)(v0 - 1);
for ( i = 0LL; ; i = v3 )
{
if ( *(int *)(mem_map + 40 * i + 24) > 0 )
{
caos_printf("%x ", (unsigned int)i);
v3 = i + 1;
if ( v1 == i )
return caos_printf("\n");
}
else
{
caos_printf("[%x] ", (unsigned int)i);
v3 = i + 1;
if ( v1 == i )
return caos_printf("\n");
}
}
}
return caos_printf("\n");
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx
__int64 v1; // rbp
__int64 i; // rbx
__int64 v3; // rax

v0 = phy_mem_size << 8;
caos_printf("Busy Pages : ");
if ( v0 > 0 )
{
v1 = (unsigned int)(v0 - 1);
for ( i = 0LL; ; i = v3 )
{
if ( *(int *)(mem_map + 40 * i + 24) > 0 )
{
caos_printf("%x ", (unsigned int)i);
v3 = i + 1;
if ( v1 == i )
return caos_printf("\n");
}
else
{
caos_printf("[%x] ", (unsigned int)i);
v3 = i + 1;
if ( v1 == i )
return caos_printf("\n");
}
}
}
return caos_printf("\n");
}

original_code:
void print_busy_pages(void)
{
 int l;
 int page_count = (phy_mem_size * (1UL<<20))/(1UL<<12);
 caos_printf("Busy Pages : ");
 for (l=0; l<page_count; l++) {
  if (mem_map[l].count > 0)
   caos_printf("%x ", l);
  else
   caos_printf("[%x] ", l);
 }
 caos_printf("\n");
}

canonical_original_code:
void print_busy_pages()
{
 int l;
 int page_count = (phy_mem_size * (1UL<<20))/(1UL<<12);
 caos_printf("Busy Pages : ");
 for (l=0; l<page_count; l++) {
  if (mem_map[l].count > 0)
   caos_printf("%x ", l);
  else
   caos_printf("[%x] ", l);
 }
 caos_printf("\n");
}

variable_types: l int


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

if ( a2 > 3 )
result = 0LL;
else
result = _alloc_pages(&contig_page_data, a1, a2);
return result;
}

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

if ( a2 > 3 )
result = 0LL;
else
result = _alloc_pages(&contig_page_data, a1, a2);
return result;
}

original_code:
page_t *alloc_pages(unsigned int gfp_mask, unsigned int order)
{
 if (order > 0x3)
  return (void *)0;
 return __alloc_pages(&contig_page_data, gfp_mask, order);
}

canonical_original_code:
struct page *alloc_pages(unsigned int gfp_mask, unsigned int order)
{
 if (order > 0x3)
  return (void *)0;
 return __alloc_pages(&contig_page_data, gfp_mask, order);
}

variable_types:
order
unsigned int

return_type: struct page { struct list_head { struct list_head *next; } list; unsigned long index; int count; unsigned long flags; } *


decompiled_code:
__int64 __fastcall get_free_pages(unsigned int a1, unsigned int a2)
{
__int64 v3; // rax

if ( a2 > 3 )
return 0LL;
v3 = _alloc_pages(&contig_page_data, a1, a2);
return page_to_virt(v3);
}

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

if ( a2 > 3 )
return 0LL;
v3 = _alloc_pages(&contig_page_data, a1, a2);
return page_to_virt(v3);
}

original_code:
unsigned long get_free_pages(unsigned int gfp_mask, unsigned int order)
{
 page_t *pg;
 if (order > 0x3)
  return (unsigned long)(void *)0;
 pg = __alloc_pages(&contig_page_data, gfp_mask, order);
 return page_to_virt(pg);
}

canonical_original_code:
unsigned long get_free_pages(unsigned int gfp_mask, unsigned int order)
{
 struct page *pg;
 if (order > 0x3)
  return (unsigned long)(void *)0;
 pg = __alloc_pages(&contig_page_data, gfp_mask, order);
 return page_to_virt(pg);
}

variable_types: struct page { struct list_head { struct list_head *next; } list; unsigned long index; int count; unsigned long flags; } *

return_type: unsigned long


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

if ( a2 <= 3 )
result = _free_pages();
return result;
}

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

if ( a2 <= 3 )
result = _free_pages();
return result;
}

original_code:
void free_pages(unsigned long addr, unsigned int order)
{
 if (order > 0x3)
  return;
 __free_pages(addr, order);
}

variable_types:
addr
unsigned long


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

result = caos_printf("INIT CHAR DEVICE TABLE..\n");
cdev_table[0] = 0LL;
cdev_table[1] = 0LL;
cdev_table[2] = 0LL;
cdev_table[3] = 0LL;
return result;
}

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

result = caos_printf("INIT CHAR DEVICE TABLE..\n");
cdev_table[0] = 0LL;
cdev_table[1] = 0LL;
cdev_table[2] = 0LL;
cdev_table[3] = 0LL;
return result;
}

original_code:
void init_char_dev(void)
{
 int i;
 caos_printf("INIT CHAR DEVICE TABLE..\n");
 for (i=0; i<8; i++) {
  cdev_table[i] = (void *)0;
 }
}

canonical_original_code:
void init_char_dev()
{
 int i;
 caos_printf("INIT CHAR DEVICE TABLE..\n");
 for (i=0; i<8; i++) {
  cdev_table[i] = (void *)0;
 }
}


decompiled_code:
__int64 __fastcall register_chrdev(const char *a1, __int64 a2)
{
__int64 v3; // rsi

caos_printf("Register [%s] device..", a1);
v3 = 0LL;
while ( cdev_table[v3] )
{
if ( ++v3 == 8 )
{
caos_printf("FAIL\n");
return 0xFFFFFFFFLL;
}
}
cdev_table[(int)v3] = a2;
caos_printf("OK\n");
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int64 a2)
{
__int64 v3; // rsi

caos_printf("Register [%s] device..", a1);
v3 = 0LL;
while ( cdev_table[v3] )
{
if ( ++v3 == 8 )
{
caos_printf("FAIL\n");
return 0xFFFFFFFFLL;
}
}
cdev_table[(int)v3] = a2;
caos_printf("OK\n");
return (unsigned int)v3;
}

original_code:
int register_chrdev(char *name, char_device_struct_t *cdev)
{
 int i;
 caos_printf("Register [%s] device..", name);
 for (i=0; i<8; i++) {
  if (cdev_table[i] == (void *)0) {
   cdev_table[i] = cdev;
   caos_printf("OK\n", i);
   return i;
  }
 }
 caos_printf("FAIL\n");
 return -1;
}

canonical_original_code:
int register_chrdev(char *name, struct char_device_struct *cdev)
{
 int i;
 caos_printf("Register [%s] device..", name);
 for (i=0; i<8; i++) {
  if (cdev_table[i] == (void *)0) {
   cdev_table[i] = cdev;
   caos_printf("OK\n", i);
   return i;
  }
 }
 caos_printf("FAIL\n");
 return -1;
}

variable_types:
name
char *

variable_types: struct char_device_struct { unsigned int major; char *name; struct file_operations { int (*read)(char *buf, int size, int offset); int (*write)(char *buf, int size, int offset); int (*open)(char *name); int (*close)(char *name); int (*ioctl)(unsigned int cmd); } *fops; } *

user_defined_types: struct char_device_struct { unsigned int major; char *name; struct file_operations *fops; }


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

caos_printf("Unregister device number [%d]..", a2);
if ( a1 > 7 )
{
caos_printf("FAIL\n");
result = 0xFFFFFFFFLL;
}
else
{
cdev_table[a1] = 0LL;
caos_printf("OK\n");
result = 1LL;
}
return result;
}

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

caos_printf("Unregister device number [%d]..", a2);
if ( a1 > 7 )
{
caos_printf("FAIL\n");
result = 0xFFFFFFFFLL;
}
else
{
cdev_table[a1] = 0LL;
caos_printf("OK\n");
result = 1LL;
}
return result;
}

original_code:
int unregister_chrdev(int major_num, char *name)
{
 caos_printf("Unregister device number [%d]..");
 if (major_num >= 8 || major_num < 0) {
  caos_printf("FAIL\n");
  return -1;
 }
 cdev_table[major_num] = (void *)0;
 caos_printf("OK\n");
 return 1;
}


decompiled_code:
__int64 __fastcall keyboard_read(__int64 a1, int a2)
{
__int64 v2; // rdx
_BYTE *v3; // rdi
__int64 result; // rax

v2 = fore_task;
if ( *(int *)(fore_task + 56LL) <= 0 )
{
result = 0LL;
LABEL_6:
*(_DWORD *)(v2 + 56) = 0;
return result;
}
v3 = (_BYTE *)(a1 + 1);
*(v3 - 1) = *(_BYTE *)(fore_task + 24LL);
for ( result = 0LL; a2 >= (int)result; *v3++ = *(_BYTE *)(fore_task + (int)result + 24LL) )
{
v2 = fore_task;
result = (unsigned int)(result + 1);
if ( *(_DWORD *)(fore_task + 56LL) <= (int)result )
goto LABEL_6;
}
*(_DWORD *)(fore_task + 56LL) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // rdx
_BYTE *v3; // rdi
__int64 result; // rax

v2 = fore_task;
if ( *(int *)(fore_task + 56LL) <= 0 )
{
result = 0LL;
LABEL_6:
*(_DWORD *)(v2 + 56) = 0;
return result;
}
v3 = (_BYTE *)(a1 + 1);
*(v3 - 1) = *(_BYTE *)(fore_task + 24LL);
for ( result = 0LL; a2 >= (int)result; *v3++ = *(_BYTE *)(fore_task + (int)result + 24LL) )
{
v2 = fore_task;
result = (unsigned int)(result + 1);
if ( *(_DWORD *)(fore_task + 56LL) <= (int)result )
goto LABEL_6;
}
*(_DWORD *)(fore_task + 56LL) = 0;
return result;
}

original_code:
int keyboard_read(char *buf, int size, int offset)
{
 int l;
 for (l=0; l<fore_task->key_offset; l++) {
  buf[l] = fore_task->key_input[l];
  if (l > size)
   break;
 }
 fore_task->key_offset = 0;
 return l;
}

variable_types:
buf
char *

variable_types: size int

variable_types: offset int


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

if ( (unsigned int)caos_strcmp(a1, qword_4C8) )
return 0xFFFFFFFFLL;
register_irq(1LL, keyboard_isr);
enable_irq(1LL);
*((_BYTE *)&key + 4) = 0;
result = (unsigned int)keyboard_device;
key = 0;
return result;
}

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

if ( (unsigned int)caos_strcmp(a1, qword_4C8) )
return 0xFFFFFFFFLL;
register_irq(1LL, keyboard_isr);
enable_irq(1LL);
*((_BYTE *)&key + 4) = 0;
result = (unsigned int)keyboard_device;
key = 0;
return result;
}

original_code:
int keyboard_open(const char *name)
{
 if (caos_strcmp(name, keyboard_device.name) != 0)
  return -1;
 register_irq(0x1, keyboard_isr);
 enable_irq(0x1);
 key.status = 0;
 key.code = 0;
 return keyboard_device.major;
}

canonical_original_code:
int keyboard_open(char *name)
{
 if (caos_strcmp(name, keyboard_device.name) != 0)
  return -1;
 register_irq(0x1, keyboard_isr);
 enable_irq(0x1);
 key.status = 0;
 key.code = 0;
 return keyboard_device.major;
}


decompiled_code:
__int64 __fastcall keyboard_close(__int64 a1)
{
unsigned int v1; // er12

if ( (unsigned int)caos_strcmp(a1, qword_4C8) )
return (unsigned int)-1;
v1 = 0;
unregister_irq(1LL);
disable_irq(1LL);
return v1;
}

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

if ( (unsigned int)caos_strcmp(a1, qword_4C8) )
return (unsigned int)-1;
v1 = 0;
unregister_irq(1LL);
disable_irq(1LL);
return v1;
}

original_code:
int keyboard_close(const char *name)
{
 if (caos_strcmp(name, keyboard_device.name) != 0)
  return -1;
 unregister_irq(0x1);
 disable_irq(0x1);
 return 0;
}

canonical_original_code:
int keyboard_close(char *name)
{
 if (caos_strcmp(name, keyboard_device.name) != 0)
  return -1;
 unregister_irq(0x1);
 disable_irq(0x1);
 return 0;
}


decompiled_code:
__int64 keyboard_init()
{
caos_printf("Initialize keyboard..");
qword_4D0 = (__int64)keyboard_ops;
qword_4C8 = (__int64)keyboard_name;
keyboard_device = register_chrdev(keyboard_name, &keyboard_device);
caos_printf("OK\n");
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
caos_printf("Initialize keyboard..");
qword_4D0 = (__int64)keyboard_ops;
qword_4C8 = (__int64)keyboard_name;
keyboard_device = register_chrdev(keyboard_name, &keyboard_device);
caos_printf("OK\n");
return 0LL;
}

original_code:
int keyboard_init(void)
{
 caos_printf("Initialize keyboard..");
 keyboard_device.fops = &keyboard_ops;
 keyboard_device.name = keyboard_name;
 keyboard_device.major = register_chrdev(keyboard_name, &keyboard_device);
 if (keyboard_device.major < 0) {
  caos_printf("FAIL\n");
  return -1;
 }
 caos_printf("OK\n");
 return 0;
}

canonical_original_code:
int keyboard_init()
{
 caos_printf("Initialize keyboard..");
 keyboard_device.fops = &keyboard_ops;
 keyboard_device.name = keyboard_name;
 keyboard_device.major = register_chrdev(keyboard_name, &keyboard_device);
 if (keyboard_device.major < 0) {
  caos_printf("FAIL\n");
  return -1;
 }
 caos_printf("OK\n");
 return 0;
}


decompiled_code:
__int64 device_exit()
{
if ( (int)unregister_chrdev((unsigned int)keyboard_device, qword_4C8) >= 0 )
return 0LL;
caos_printf("Release keyboard fail..\n");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func4()
{
if ( (int)unregister_chrdev((unsigned int)keyboard_device, qword_4C8) >= 0 )
return 0LL;
caos_printf("Release keyboard fail..\n");
return 0xFFFFFFFFLL;
}

original_code:
int device_exit(void)
{
 if (unregister_chrdev(keyboard_device.major, keyboard_device.name) < 0) {
  caos_printf("Release keyboard fail..\n");
  return -1;
 }
 return 0;
}

canonical_original_code:
int device_exit()
{
 if (unregister_chrdev(keyboard_device.major, keyboard_device.name) < 0) {
  caos_printf("Release keyboard fail..\n");
  return -1;
 }
 return 0;
}


decompiled_code:
void __fastcall key_buffer_insert(char a1)
{
__int64 v1; // rax
int v2; // edx

if ( a1 )
{
v1 = fore_task;
if ( fore_task )
{
v2 = *(_DWORD *)(fore_task + 56LL);
if ( v2 <= 31 )
{
*(_BYTE *)(fore_task + v2 + 24LL) = a1;
*(_DWORD *)(v1 + 56) = v2 + 1;
}
}
}
}

canonical_decompiled_code:
void __fastcall func5(char a1)
{
__int64 v1; // rax
int v2; // edx

if ( a1 )
{
v1 = fore_task;
if ( fore_task )
{
v2 = *(_DWORD *)(fore_task + 56LL);
if ( v2 <= 31 )
{
*(_BYTE *)(fore_task + v2 + 24LL) = a1;
*(_DWORD *)(v1 + 56) = v2 + 1;
}
}
}
}

original_code:
void key_buffer_insert(char k)
{
 if (k != 0x0) {
  if (fore_task != (void *)0 && fore_task->key_offset < 32) {
   fore_task->key_input[fore_task->key_offset] = k;
   fore_task->key_offset++;
  }
 }
}

variable_types: k char


decompiled_code:
void keyboard_isr()
{
unsigned __int8 v0; // al

v0 = inb(0x60u);
if ( (unsigned __int8)(v0 - 1) <= 0xFDu && (unsigned __int8)(v0 + 32) > 1u )
{
switch ( v0 )
{
case 0x45u:
key ^= 0x20u;
break;
case 0x1Du:
key ^= 8u;
break;
case 0x46u:
key ^= 0x10u;
break;
case 0x2Au:
key |= 1u;
break;
case 0xAA:
key &= 0xFFFFFFFE;
break;
case 0x3Au:
key |= 2u;
break;
case 0xBA:
key &= 0xFFFFFFFD;
break;
case 0x38u:
key |= 4u;
break;
case 0xB8:
key &= 0xFFFFFFFB;
break;
default:
if ( (v0 & 0x80u) == 0 )
{
if ( (key & 9) == 9 )
{
*((_BYTE *)&key + 4) = byte_6A0[v0];
}
else if ( key )
{
if ( (key & 8) != 0 )
{
*((_BYTE *)&key + 4) = byte_5A0[v0];
}
else if ( (key & 1) != 0 )
{
*((_BYTE *)&key + 4) = byte_620[v0];
}
else if ( (key & 2) != 0 )
{
*((_BYTE *)&key + 4) = byte_720[v0];
}
else
{
*((_BYTE *)&key + 4) = -1;
}
}
else
{
*((_BYTE *)&key + 4) = scan_to_ascii[v0];
}
if ( v0 == 28 )
{
key_buffer_insert(10);
}
else if ( v0 == 14 )
{
key_buffer_insert(8);
}
else
{
key_buffer_insert(*((_BYTE *)&key + 4));
}
}
break;
}
}
}

canonical_decompiled_code:
void func6()
{
unsigned __int8 v0; // al

v0 = inb(0x60u);
if ( (unsigned __int8)(v0 - 1) <= 0xFDu && (unsigned __int8)(v0 + 32) > 1u )
{
switch ( v0 )
{
case 0x45u:
key ^= 0x20u;
break;
case 0x1Du:
key ^= 8u;
break;
case 0x46u:
key ^= 0x10u;
break;
case 0x2Au:
key |= 1u;
break;
case 0xAA:
key &= 0xFFFFFFFE;
break;
case 0x3Au:
key |= 2u;
break;
case 0xBA:
key &= 0xFFFFFFFD;
break;
case 0x38u:
key |= 4u;
break;
case 0xB8:
key &= 0xFFFFFFFB;
break;
default:
if ( (v0 & 0x80u) == 0 )
{
if ( (key & 9) == 9 )
{
*((_BYTE *)&key + 4) = byte_6A0[v0];
}
else if ( key )
{
if ( (key & 8) != 0 )
{
*((_BYTE *)&key + 4) = byte_5A0[v0];
}
else if ( (key & 1) != 0 )
{
*((_BYTE *)&key + 4) = byte_620[v0];
}
else if ( (key & 2) != 0 )
{
*((_BYTE *)&key + 4) = byte_720[v0];
}
else
{
*((_BYTE *)&key + 4) = -1;
}
}
else
{
*((_BYTE *)&key + 4) = scan_to_ascii[v0];
}
if ( v0 == 28 )
{
func5(10);
}
else if ( v0 == 14 )
{
func5(8);
}
else
{
func5(*((_BYTE *)&key + 4));
}
}
break;
}
}
}

original_code:
void keyboard_isr(void)
{
 unsigned char scan=0;
 static int prefix=0;
 int tmp;
 int change_flag = 0;
 scan = inb(0x60);
 if ( (scan == 0) || (scan == 0xff) )
  return;
 if (scan == 0xe0 || scan == 0xe1) {
  prefix = 1;
  return;
 }
 if (scan == 0x45) {
  tmp = (1<<5);
  key.status ^= tmp;
  change_flag = 1;
 } else if (scan == 0x1d) {
  tmp = (1<<3);
  key.status ^= tmp;
  change_flag = 1;
 } else if (scan == 0x46) {
  tmp = (1<<4);
  key.status ^= tmp;
  change_flag = 1;
 } else if (scan == 0x2a) {
  tmp = (1<<0);
  key.status |= tmp;
  change_flag = 1;
 } else if (scan == (0x2a|0x80)) {
  tmp = (1<<0);
  key.status &= ~tmp;
  change_flag = 1;
 } else if (scan == 0x3a) {
  tmp = (1<<1);
  key.status |= tmp;
  change_flag = 1;
 } else if (scan == (0x3a|0x80)) {
  tmp = (1<<1);
  key.status &= ~tmp;
  change_flag = 1;
 } else if (scan == 0x38) {
  tmp = (1<<2);
  key.status |= tmp;
  change_flag = 1;
 } else if (scan == (0x38|0x80)) {
  tmp = (1<<2);
  key.status &= ~tmp;
  change_flag = 1;
 }
 if (change_flag != 0) {
  return;
 }
 if (scan & 0x80)
  return;
 if ( (key.status & (1<<3)) && (key.status & (1<<0)) )
  key.code = scan_to_ascii[3][scan];
 else if (key.status == 0)
  key.code = scan_to_ascii[0][scan];
 else if (key.status & (1<<3))
  key.code = scan_to_ascii[1][scan];
 else if (key.status & (1<<0))
  key.code = scan_to_ascii[2][scan];
 else if (key.status & (1<<1))
  key.code = scan_to_ascii[4][scan];
 else
  key.code = 0xff;
 if (scan == 0x1c) {
  key_buffer_insert('\n');
  return;
 } else if (scan == 0x0e) {
  key_buffer_insert('\b');
  return;
 }
 key_buffer_insert(key.code);
 prefix = 0;
}

canonical_original_code:
void keyboard_isr()
{
 unsigned char scan = 0;
 static int prefix = 0;
 int tmp;
 int change_flag = 0;
 scan = inb(0x60);
 if ( (scan == 0) || (scan == 0xff) )
  return;
 if (scan == 0xe0 || scan == 0xe1) {
  prefix = 1;
  return;
 }
 if (scan == 0x45) {
  tmp = (1<<5);
  key.status ^= tmp;
  change_flag = 1;
 } else if (scan == 0x1d) {
  tmp = (1<<3);
  key.status ^= tmp;
  change_flag = 1;
 } else if (scan == 0x46) {
  tmp = (1<<4);
  key.status ^= tmp;
  change_flag = 1;
 } else if (scan == 0x2a) {
  tmp = (1<<0);
  key.status |= tmp;
  change_flag = 1;
 } else if (scan == (0x2a|0x80)) {
  tmp = (1<<0);
  key.status &= ~tmp;
  change_flag = 1;
 } else if (scan == 0x3a) {
  tmp = (1<<1);
  key.status |= tmp;
  change_flag = 1;
 } else if (scan == (0x3a|0x80)) {
  tmp = (1<<1);
  key.status &= ~tmp;
  change_flag = 1;
 } else if (scan == 0x38) {
  tmp = (1<<2);
  key.status |= tmp;
  change_flag = 1;
 } else if (scan == (0x38|0x80)) {
  tmp = (1<<2);
  key.status &= ~tmp;
  change_flag = 1;
 }
 if (change_flag != 0) {
  return;
 }
 if (scan & 0x80)
  return;
 if ( (key.status & (1<<3)) && (key.status & (1<<0)) )
  key.code = scan_to_ascii[3][scan];
 else if (key.status == 0)
  key.code = scan_to_ascii[0][scan];
 else if (key.status & (1<<3))
  key.code = scan_to_ascii[1][scan];
 else if (key.status & (1<<0))
  key.code = scan_to_ascii[2][scan];
 else if (key.status & (1<<1))
  key.code = scan_to_ascii[4][scan];
 else
  key.code = 0xff;
 if (scan == 0x1c) {
  key_buffer_insert('\n');
  return;
 } else if (scan == 0x0e) {
  key_buffer_insert('\b');
  return;
 }
 key_buffer_insert(key.code);
 prefix = 0;
}

variable_types:
scan
unsigned char

variable_types: prefix int

variable_types: tmp int


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

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

original_code:
int timer_open(const char *name)
{
 return 0;
}

canonical_original_code:
int timer_open(char *name)
{
 return 0;
}


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

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

original_code:
int timer_ioctl(unsigned int cmd)
{
 return 0;
}

variable_types:
cmd
unsigned int


decompiled_code:
__int64 timer_isr()
{
timer_msg[11] = flow[++timer_count & 3];
return write_screen(timer_msg, 22LL, 12LL);
}

canonical_decompiled_code:
__int64 func2()
{
timer_msg[11] = flow[++timer_count & 3];
return write_screen(timer_msg, 22LL, 12LL);
}

original_code:
void timer_isr(void)
{
 timer_count++;
 timer_msg[11] = flow[timer_count%4];
 write_screen(timer_msg, 22, 12);
}

canonical_original_code:
void timer_isr()
{
 timer_count++;
 timer_msg[11] = flow[timer_count%4];
 write_screen(timer_msg, 22, 12);
}


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

*((_QWORD *)&timer_dev + 1) = timer_device_name;
*((_QWORD *)&timer_dev + 2) = timer_ops;
result = register_chrdev(timer_device_name, &timer_dev);
if ( (int)result >= 0 )
{
timer_dev = result;
timer_ops[0] = 0LL;
timer_ops[1] = 0LL;
timer_ops[2] = (__int64)timer_open;
timer_ops[3] = 0LL;
timer_ops[4] = (__int64)timer_ioctl;
caos_printf("Initialize timer..");
timer_interval = -1;
outb(0x43u, 0x34u);
outb(0x40u, (unsigned __int8)timer_interval);
outb(0x40u, HIBYTE(timer_interval));
register_irq(0LL, timer_isr);
enable_irq(0LL);
timer_count = 0LL;
clear_screen(0LL, 80LL);
result = caos_printf("OK\n");
}
return result;
}

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

*((_QWORD *)&timer_dev + 1) = timer_device_name;
*((_QWORD *)&timer_dev + 2) = timer_ops;
result = register_chrdev(timer_device_name, &timer_dev);
if ( (int)result >= 0 )
{
timer_dev = result;
timer_ops[0] = 0LL;
timer_ops[1] = 0LL;
timer_ops[2] = (__int64)timer_open;
timer_ops[3] = 0LL;
timer_ops[4] = (__int64)timer_ioctl;
caos_printf("Initialize timer..");
timer_interval = -1;
outb(0x43u, 0x34u);
outb(0x40u, (unsigned __int8)timer_interval);
outb(0x40u, HIBYTE(timer_interval));
register_irq(0LL, timer_isr);
enable_irq(0LL);
timer_count = 0LL;
clear_screen(0LL, 80LL);
result = caos_printf("OK\n");
}
return result;
}

original_code:
void init_timer(void)
{
 int major;
 timer_dev.name = timer_device_name;
 timer_dev.fops = &timer_ops;
 major = register_chrdev(timer_device_name, &timer_dev);
 if (major < 0)
  return;
 timer_dev.major = major;
 timer_ops.read = (void *)0;
 timer_ops.write = (void *)0;
 timer_ops.open = timer_open;
 timer_ops.close = (void *)0;
 timer_ops.ioctl = timer_ioctl;
 caos_printf("Initialize timer..");
 timer_interval = 0xffff;
 outb(0x43, 0x34);
 outb(0x40, (unsigned char)(timer_interval & 0xff));
 outb(0x40, (unsigned char)((timer_interval>>8) & 0xff));
 register_irq(0, timer_isr);
 enable_irq(0);
 timer_count = 0;
 clear_screen(0, 80);
 caos_printf("OK\n");
}

canonical_original_code:
void init_timer()
{
 int major;
 timer_dev.name = timer_device_name;
 timer_dev.fops = &timer_ops;
 major = register_chrdev(timer_device_name, &timer_dev);
 if (major < 0)
  return;
 timer_dev.major = major;
 timer_ops.read = (void *)0;
 timer_ops.write = (void *)0;
 timer_ops.open = timer_open;
 timer_ops.close = (void *)0;
 timer_ops.ioctl = timer_ioctl;
 caos_printf("Initialize timer..");
 timer_interval = 0xffff;
 outb(0x43, 0x34);
 outb(0x40, (unsigned char)(timer_interval & 0xff));
 outb(0x40, (unsigned char)((timer_interval>>8) & 0xff));
 register_irq(0, timer_isr);
 enable_irq(0);
 timer_count = 0;
 clear_screen(0, 80);
 caos_printf("OK\n");
}

variable_types: major int


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

result = a1 / 8;
*((_BYTE *)&boot_bitmap + result) |= 128 >> (a1 % 8);
return result;
}

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

result = a1 / 8;
*((_BYTE *)&boot_bitmap + result) |= 128 >> (a1 % 8);
return result;
}

original_code:
void set_boot_bitmap(int index)
{
 int byte, bit;
 unsigned char mask = 0x80;
 byte = index/8;
 bit = index%8;
 boot_bitmap[byte] |= (mask>>bit);
}

canonical_original_code:
void set_boot_bitmap(int index)
{
 int byte; int bit;
 unsigned char mask = 0x80;
 byte = index/8;
 bit = index%8;
 boot_bitmap[byte] |= (mask>>bit);
}

variable_types: index int

variable_types: byte int

variable_types: bit int

variable_types:
mask
unsigned char


decompiled_code:
__int64 bootmem_init()
{
int v0; // esi
int v1; // edi
__int64 result; // rax

v0 = 0;
*((_DWORD *)&boot_bitmap + 4) = 0;
boot_bitmap = 0LL;
do
{
v1 = v0++;
result = set_boot_bitmap(v1);
}
while ( v0 != 8 );
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // esi
int v1; // edi
__int64 result; // rax

v0 = 0;
*((_DWORD *)&boot_bitmap + 4) = 0;
boot_bitmap = 0LL;
do
{
v1 = v0++;
result = func0(v1);
}
while ( v0 != 8 );
return result;
}

original_code:
void bootmem_init(unsigned int kernel_size)
{
 int l;
 for (l=0; l<20; l++)
  boot_bitmap[l] = 0;
 for (l=0; l<= 0x7; l++)
  set_boot_bitmap(l);
}

variable_types: l int


decompiled_code:
__int64 alloc_bootmem()
{
char v0; // dl
__int64 v1; // rax
int v2; // ecx
__int64 result; // rax
int v4; // esi
int v5; // esi
int v6; // esi
int v7; // esi
int v8; // esi
int v9; // esi
int v10; // esi
int v11; // esi

v0 = boot_bitmap;
if ( (_BYTE)boot_bitmap == 0xFF )
{
v1 = 1LL;
do
{
v2 = v1;
v0 = *((_BYTE *)&boot_bitmap + v1++);
}
while ( v0 == -1 );
}
else
{
v2 = 0;
}
if ( v0 )
{
switch ( v0 )
{
case -128:
v7 = 8 * v2 + 1;
set_boot_bitmap(v7);
result = (__int64)v7 << 12;
break;
case -64:
v8 = 8 * v2 + 2;
set_boot_bitmap(v8);
result = (__int64)v8 << 12;
break;
case -32:
v9 = 8 * v2 + 3;
set_boot_bitmap(v9);
result = (__int64)v9 << 12;
break;
case -16:
v6 = 8 * v2 + 4;
set_boot_bitmap(v6);
result = (__int64)v6 << 12;
break;
case -8:
v10 = 8 * v2 + 5;
set_boot_bitmap(v10);
result = (__int64)v10 << 12;
break;
case -4:
v11 = 8 * v2 + 6;
set_boot_bitmap(v11);
result = (__int64)v11 << 12;
break;
default:
result = 0LL;
if ( v0 == -2 )
{
v5 = 8 * v2 + 7;
set_boot_bitmap(v5);
result = (__int64)v5 << 12;
}
break;
}
}
else
{
v4 = 8 * v2;
set_boot_bitmap(8 * v2);
result = (__int64)v4 << 12;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
char v0; // dl
__int64 v1; // rax
int v2; // ecx
__int64 result; // rax
int v4; // esi
int v5; // esi
int v6; // esi
int v7; // esi
int v8; // esi
int v9; // esi
int v10; // esi
int v11; // esi

v0 = boot_bitmap;
if ( (_BYTE)boot_bitmap == 0xFF )
{
v1 = 1LL;
do
{
v2 = v1;
v0 = *((_BYTE *)&boot_bitmap + v1++);
}
while ( v0 == -1 );
}
else
{
v2 = 0;
}
if ( v0 )
{
switch ( v0 )
{
case -128:
v7 = 8 * v2 + 1;
func0(v7);
result = (__int64)v7 << 12;
break;
case -64:
v8 = 8 * v2 + 2;
func0(v8);
result = (__int64)v8 << 12;
break;
case -32:
v9 = 8 * v2 + 3;
func0(v9);
result = (__int64)v9 << 12;
break;
case -16:
v6 = 8 * v2 + 4;
func0(v6);
result = (__int64)v6 << 12;
break;
case -8:
v10 = 8 * v2 + 5;
func0(v10);
result = (__int64)v10 << 12;
break;
case -4:
v11 = 8 * v2 + 6;
func0(v11);
result = (__int64)v11 << 12;
break;
default:
result = 0LL;
if ( v0 == -2 )
{
v5 = 8 * v2 + 7;
func0(v5);
result = (__int64)v5 << 12;
}
break;
}
}
else
{
v4 = 8 * v2;
func0(8 * v2);
result = (__int64)v4 << 12;
}
return result;
}

original_code:
void *alloc_bootmem(void)
{
 int l=0;
 while (boot_bitmap[l] == 0xff)
  l++;
 if (l >= 0xa0)
  return (void *)0;
 if (boot_bitmap[l] == 0x0) {
  set_boot_bitmap(l*8);
  return (void *)((l*8)*(1UL<<12));
 } else if (boot_bitmap[l] == 0x80) {
  set_boot_bitmap(l*8+1);
  return (void *)((l*8+1)*(1UL<<12));
 } else if (boot_bitmap[l] == 0xc0) {
  set_boot_bitmap(l*8+2);
  return (void *)((l*8+2)*(1UL<<12));
 } else if (boot_bitmap[l] == 0xe0) {
  set_boot_bitmap(l*8+3);
  return (void *)((l*8+3)*(1UL<<12));
 } else if (boot_bitmap[l] == 0xf0) {
  set_boot_bitmap(l*8+4);
  return (void *)((l*8+4)*(1UL<<12));
 } else if (boot_bitmap[l] == 0xf8) {
  set_boot_bitmap(l*8+5);
  return (void *)((l*8+5)*(1UL<<12));
 } else if (boot_bitmap[l] == 0xfc) {
  set_boot_bitmap(l*8+6);
  return (void *)((l*8+6)*(1UL<<12));
 } else if (boot_bitmap[l] == 0xfe) {
  set_boot_bitmap(l*8+7);
  return (void *)((l*8+7)*(1UL<<12));
 }
 return (void *)0;
}

canonical_original_code:
void *alloc_bootmem()
{
 int l = 0;
 while (boot_bitmap[l] == 0xff)
  l++;
 if (l >= 0xa0)
  return (void *)0;
 if (boot_bitmap[l] == 0x0) {
  set_boot_bitmap(l*8);
  return (void *)((l*8)*(1UL<<12));
 } else if (boot_bitmap[l] == 0x80) {
  set_boot_bitmap(l*8+1);
  return (void *)((l*8+1)*(1UL<<12));
 } else if (boot_bitmap[l] == 0xc0) {
  set_boot_bitmap(l*8+2);
  return (void *)((l*8+2)*(1UL<<12));
 } else if (boot_bitmap[l] == 0xe0) {
  set_boot_bitmap(l*8+3);
  return (void *)((l*8+3)*(1UL<<12));
 } else if (boot_bitmap[l] == 0xf0) {
  set_boot_bitmap(l*8+4);
  return (void *)((l*8+4)*(1UL<<12));
 } else if (boot_bitmap[l] == 0xf8) {
  set_boot_bitmap(l*8+5);
  return (void *)((l*8+5)*(1UL<<12));
 } else if (boot_bitmap[l] == 0xfc) {
  set_boot_bitmap(l*8+6);
  return (void *)((l*8+6)*(1UL<<12));
 } else if (boot_bitmap[l] == 0xfe) {
  set_boot_bitmap(l*8+7);
  return (void *)((l*8+7)*(1UL<<12));
 }
 return (void *)0;
}


decompiled_code:
__int64 __fastcall paging_init(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // er10
__int64 v6; // rdi
_QWORD *v7; // r9
__int64 result; // rax
int v9; // er11
__int64 v10; // r8
__int64 v11; // r10
__int64 v12; // rdx

swapper_pg_dir = 3221237760LL;
v2 = ((__int64 (*)(void))alloc_bootmem)();
v6 = v5 >> 2;
v7 = (_QWORD *)v2;
result = v2 + 3;
v9 = v5 >> 2 << 10;
if ( (unsigned int)v6 <= 1 )
{
if ( v9 <= 1024 )
return result;
}
else
{
v10 = 3221243912LL;
do
{
*(_QWORD *)v10 = result;
result = alloc_bootmem(v6, a2, v3, v4, v10 + 8, v7) + 3;
}
while ( v11 != v10 );
}
v12 = 4194307LL;
LODWORD(result) = 1024;
do
{
result = (unsigned int)(result + 1);
*v7 = v12;
v12 += 4096LL;
++v7;
}
while ( v9 > (int)result );
return result;
}

original_code:
void paging_init(unsigned int phy_mem_size)
{
 int l;
 pte_t *pte;
 pgd_t *pgd;
 unsigned long addr;
 unsigned long pte_start;
 int pgd_count;
 swapper_pg_dir = (pgd_t *)0xc0003000;
 pgd = swapper_pg_dir+0x301;
 pte_start = (unsigned long)alloc_bootmem();
 addr = pte_start + (0x002 | 0x001);
 pgd_count = phy_mem_size/4;
 for (l=1; l<pgd_count; l++) {
  do { ((*(pgd)) = (((pgd_t) { (addr) } ))); } while(0);
  addr = (unsigned long)alloc_bootmem() + (0x002|0x001);
  pgd++;
 }
 pte = (pte_t *)pte_start;
 addr = (4*0x100000) + (0x002 | 0x001);
 pgd_count = phy_mem_size/4;
 for (l=1024; l<1024*pgd_count; l++) {
  do { ((*(pte)) = (((pte_t) { (addr) } ))); } while(0);
  addr += (1UL<<12);
  pte++;
 }
}

canonical_original_code:
void paging_init(unsigned int phy_mem_size)
{
 int l;
 struct pte_t *pte;
 struct pgd_t *pgd;
 unsigned long addr;
 unsigned long pte_start;
 int pgd_count;
 swapper_pg_dir = (struct pgd_t *)0xc0003000;
 pgd = swapper_pg_dir+0x301;
 pte_start = (unsigned long)alloc_bootmem();
 addr = pte_start + (0x002 | 0x001);
 pgd_count = phy_mem_size/4;
 for (l=1; l<pgd_count; l++) {
  do { ((*(pgd)) = (((struct pgd_t) { (addr) } ))); } while(0);
  addr = (unsigned long)alloc_bootmem() + (0x002|0x001);
  pgd++;
 }
 pte = (struct pte_t *)pte_start;
 addr = (4*0x100000) + (0x002 | 0x001);
 pgd_count = phy_mem_size/4;
 for (l=1024; l<1024*pgd_count; l++) {
  do { ((*(pte)) = (((struct pte_t) { (addr) } ))); } while(0);
  addr += (1UL<<12);
  pte++;
 }
}

variable_types: struct pte_t { unsigned long pte_low; } *

variable_types:
pgd
struct pgd_t { unsigned long pgd; } *

variable_types:
addr
unsigned long

user_defined_types:
struct pgd_t { unsigned long pgd; }
struct pte_t { unsigned long pte_low; }


decompiled_code:
__int64 __fastcall virt_to_page(__int64 a1)
{
return mem_map + 40LL * (unsigned int)((unsigned __int64)(a1 - 3221225472LL) >> 12);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return mem_map + 40LL * (unsigned int)((unsigned __int64)(a1 - 3221225472LL) >> 12);
}

original_code:
page_t *virt_to_page(unsigned long vaddr)
{
 unsigned int pfn = ((unsigned long)(vaddr)-(0xC0000000UL)) >> 12;
 return mem_map+pfn;
}

canonical_original_code:
struct page *virt_to_page(unsigned long vaddr)
{
 unsigned int pfn = ((unsigned long)(vaddr)-(0xC0000000UL)) >> 12;
 return mem_map+pfn;
}

variable_types:
vaddr
unsigned long

variable_types:
pfn
unsigned int


original_code:
unsigned long page_to_virt(page_t *pg)
{
 unsigned int pfn = pg - mem_map;
 return (unsigned long)((void *)((unsigned long)(pfn << 12)+(0xC0000000UL)));
}

canonical_original_code:
unsigned long page_to_virt(struct page *pg)
{
 unsigned int pfn = pg - mem_map;
 return (unsigned long)((void *)((unsigned long)(pfn << 12)+(0xC0000000UL)));
}

variable_types: struct page { struct list_head { struct list_head *next; } list; unsigned long index; int count; unsigned long flags; } *


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

result = 0LL;
__asm { int 80h; LINUX - old_setup_syscall }
return result;
}

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

result = 0LL;
__asm { int 80h; LINUX - old_setup_syscall }
return result;
}

original_code: inline int sys_syscall_test(void){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(0) ); return __res;}

canonical_original_code: inline int sys_syscall_test(){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(0) ); return __res;}


decompiled_code:
void __fastcall __noreturn sys_cputstr(int status)
{
__asm { int 80h; LINUX - sys_exit }
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int status)
{
__asm { int 80h; LINUX - sys_exit }
}

original_code: inline int sys_cputstr(const char * str){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(1), "b"((long)str) ); return __res;}

canonical_original_code: inline int sys_cputstr(char *str){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(1), "b"((long)str) ); return __res;}

variable_types:
str
char *


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

result = 2LL;
__asm { int 80h; LINUX - sys_fork }
return result;
}

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

result = 2LL;
__asm { int 80h; LINUX - sys_fork }
return result;
}

original_code: inline int sys_cgetstr(const char * str, long arg){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(2), "b"((long)str), "c"((long)arg) ); return __res;}

canonical_original_code: inline int sys_cgetstr(char *str, long arg){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(2), "b"((long)str), "c"((long)arg) ); return __res;}

variable_types: arg long


decompiled_code:
__int64 __fastcall sys_cprintf(int fd, void *addr)
{
__int64 result; // rax

result = 3LL;
__asm { int 80h; LINUX - sys_read }
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, void *addr)
{
__int64 result; // rax

result = 3LL;
__asm { int 80h; LINUX - sys_read }
return result;
}

original_code: inline int sys_cprintf(const char * fmt, long arg){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(3), "b"((long)fmt), "c"((long)arg) ); return __res;}

canonical_original_code: inline int sys_cprintf(char *fmt, long arg){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(3), "b"((long)fmt), "c"((long)arg) ); return __res;}

variable_types:
fmt
char *


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

result = 4LL;
__asm { int 80h; LINUX - sys_write }
return result;
}

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

result = 4LL;
__asm { int 80h; LINUX - sys_write }
return result;
}

original_code: inline int sys_system_info(void){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(4) ); return __res;}

canonical_original_code: inline int sys_system_info(){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(4) ); return __res;}


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

result = 5LL;
__asm { int 80h; LINUX - sys_open }
return result;
}

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

result = 5LL;
__asm { int 80h; LINUX - sys_open }
return result;
}

original_code: inline int sys_turnoff(void){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(5) ); return __res;}

canonical_original_code: inline int sys_turnoff(){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(5) ); return __res;}


decompiled_code:
__int64 __fastcall sys_open(int fd)
{
__int64 result; // rax

result = 6LL;
__asm { int 80h; LINUX - sys_close }
return result;
}

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

result = 6LL;
__asm { int 80h; LINUX - sys_close }
return result;
}

original_code: inline int sys_open(const char * name, int flag){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(6), "b"((long)name), "c"((long)flag) ); return __res;}

canonical_original_code: inline int sys_open(char *name, int flag){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(6), "b"((long)name), "c"((long)flag) ); return __res;}

variable_types:
name
char *

variable_types: flag int


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

result = 7LL;
__asm { int 80h; LINUX - sys_waitpid }
return result;
}

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

result = 7LL;
__asm { int 80h; LINUX - sys_waitpid }
return result;
}

original_code: inline int sys_close(int fd){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(7), "b"((long)fd) ); return __res;}

variable_types: fd int


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

result = 8LL;
__asm { int 80h; LINUX - sys_creat }
return result;
}

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

result = 8LL;
__asm { int 80h; LINUX - sys_creat }
return result;
}

original_code: inline int sys_read(int fd, char * buf, int count){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(8), "b"((long)fd), "c"((long)buf), "d"((long)count) ); return __res;}

canonical_original_code: inline int sys_read(int fd, char *buf, int count){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(8), "b"((long)fd), "c"((long)buf), "d"((long)count) ); return __res;}

variable_types:
buf
char *

variable_types: count int


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

result = 9LL;
__asm { int 80h; LINUX - sys_link }
return result;
}

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

result = 9LL;
__asm { int 80h; LINUX - sys_link }
return result;
}

original_code: inline int sys_write(int fd, char * buf, int count){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(9), "b"((long)fd), "c"((long)buf), "d"((long)count) ); return __res;}

canonical_original_code: inline int sys_write(int fd, char *buf, int count){ long __res; asm volatile ( "int $0x80\n\t" :"=a"(__res) :"a"(9), "b"((long)fd), "c"((long)buf), "d"((long)count) ); return __res;}


decompiled_code:
__int64 do_syscall_test()
{
caos_printf("system-call test\n");
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
caos_printf("system-call test\n");
return 1LL;
}

original_code:
int do_syscall_test(void)
{
 caos_printf("system-call test\n");
 return 1;
}

canonical_original_code:
int do_syscall_test()
{
 caos_printf("system-call test\n");
 return 1;
}


decompiled_code:
__int64 __fastcall do_cputstr(__int64 a1)
{
caos_printf(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
caos_printf(a1);
return 1LL;
}

original_code:
int do_cputstr(const char *str)
{
 caos_printf(str);
 return 1;
}

canonical_original_code:
int do_cputstr(char *str)
{
 caos_printf(str);
 return 1;
}


decompiled_code:
__int64 __fastcall do_cprintf(__int64 a1)
{
caos_printf(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
caos_printf(a1);
return 1LL;
}

original_code:
int do_cprintf(const char *format, unsigned long arg)
{
 caos_printf(format, arg);
 return 1;
}

canonical_original_code:
int do_cprintf(char *format, unsigned long arg)
{
 caos_printf(format, arg);
 return 1;
}

variable_types:
format
char *

variable_types:
arg
unsigned long