input

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

if ( a1 == 110 )
return 1LL;
if ( a1 > 110 )
return 2 * (unsigned int)(a1 != 121);
result = 1LL;
if ( a1 != 78 )
result = 2 * (unsigned int)(a1 != 89);
return result;
}

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

if ( a1 == 110 )
return 1LL;
if ( a1 > 110 )
return 2 * (unsigned int)(a1 != 121);
result = 1LL;
if ( a1 != 78 )
result = 2 * (unsigned int)(a1 != 89);
return result;
}

original_code:
int input(char ch)
{
    switch(ch) {
    case 'y':
    case 'Y':
        return 0;
    case 'n':
    case 'N':
        return 1;
    default:
        return 2;
    }
}

variable_types: ch char


repo: Zuckonit/callmewash

decompiled_code:
__int64 plus_day()
{
char *v0; // rbx
int v1; // ebp
char *v2; // rax
char *v3; // r12
unsigned int v4; // eax
int v5; // ebx
int v6; // ebp

v0 = read_file(f_date);
v1 = atoi(v0);
v2 = (char *)malloc(0xAuLL);
if ( !v1 )
{
printf("Error data (integer instead) have been existed in %s", f_record);
exit(1);
}
v3 = v2;
v4 = get_current_time();
v5 = diff_day(v0, v4);
v6 = v1 + 1;
if ( v5 < 2 )
v5 = v6;
sprintf(v3, "%d", (unsigned int)v5);
write_file(f_record, v3);
free(v3);
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 func12()
{
char *v0; // rbx
int v1; // ebp
char *v2; // rax
char *v3; // r12
unsigned int v4; // eax
int v5; // ebx
int v6; // ebp

v0 = func7(f_date);
v1 = atoi(v0);
v2 = (char *)malloc(0xAuLL);
if ( !v1 )
{
printf("Error data (integer instead) have been existed in %s", f_record);
exit(1);
}
v3 = v2;
v4 = func15();
v5 = func17(v0, v4);
v6 = v1 + 1;
if ( v5 < 2 )
v5 = v6;
sprintf(v3, "%d", (unsigned int)v5);
func8(f_record, v3);
free(v3);
return (unsigned int)v5;
}

original_code:
int plus_day()
{
    char *buf = read_file(f_date);
    int day = atoi(buf);
    char *str = (char*)malloc(sizeof(char)*10);
    int _day;
    if (day == 0) {
        printf("Error data (integer instead) have been existed in %s", f_record);
        exit(1);
    }
    _day = diff_day(buf, get_current_time());
    if (_day > 1)
        day = _day;
    else
        day++;
    sprintf(str, "%d", day);
    write_file(f_record, str);
    free(str);
    return day;
}

variable_types:
buf
char *

variable_types: day int

variable_types:
str
char *

return_type: int


decompiled_code:
__int64 update_date()
{
char *v0; // rbx
char *v1; // rax
unsigned int v2; // ebp

v0 = (char *)(int)get_current_time();
if ( !file_exist(f_date) || (v1 = read_file(f_date), (v2 = strcmp(v0, v1)) != 0) )
{
write_file(f_date, v0);
v2 = 1;
}
else
{
free(v0);
}
return v2;
}

canonical_decompiled_code:
__int64 func13()
{
char *v0; // rbx
char *v1; // rax
unsigned int v2; // ebp

v0 = (char *)(int)func15();
if ( !func9(f_date) || (v1 = func7(f_date), (v2 = strcmp(v0, v1)) != 0) )
{
func8(f_date, v0);
v2 = 1;
}
else
{
free(v0);
}
return v2;
}

original_code:
int update_date()
{
    char *c_date = get_current_time();
    if (!file_exist(f_date)) {
        write_file(f_date, c_date);
        return 1;
    }
    char *r_date = read_file(f_date);
    if(strcmp(c_date, r_date) != 0) {
        write_file(f_date, c_date);
        return 1;
    }
    free(c_date);
    return 0;
}


init

decompiled_code:
int init()
{
int result; // eax

result = file_exist(f_record);
if ( !result )
result = write_file(f_record, "1");
return result;
}

canonical_decompiled_code:
int func14()
{
int result; // eax

result = func9(f_record);
if ( !result )
result = func8(f_record, "1");
return result;
}

original_code:
void init()
{
    if(!file_exist(f_record)) {
        write_file(f_record, "1");
    }
}

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char v4; // bl
int v5; // eax

welcome();
init();
v3 = read_file(f_record);
printf("%s days after your last washing!\n", v3);
if ( !(unsigned int)update_date() )
{
printf("You have checked today!");
exit(1);
}
printf("Have you washed your clothes? (Y/N)/(y/n): ");
v4 = getchar();
getchar();
v5 = input(v4);
if ( v5 )
{
if ( v5 == 1 )
{
puts(&byte_402146);
plus_day();
update_date();
}
else
{
puts("Error input, only (Y/N)/(y/n) admitted!");
}
}
else
{
puts("=3");
write_file(f_record, "1");
update_date();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char v4; // bl
int v5; // eax

func11();
func14();
v3 = func7(f_record);
printf("%s days after your last washing!\n", v3);
if ( !(unsigned int)func13() )
{
printf("You have checked today!");
exit(1);
}
printf("Have you washed your clothes? (Y/N)/(y/n): ");
v4 = getchar();
getchar();
v5 = func10(v4);
if ( v5 )
{
if ( v5 == 1 )
{
puts(&byte_402146);
func12();
func13();
}
else
{
puts("Error input, only (Y/N)/(y/n) admitted!");
}
}
else
{
puts("=3");
func8(f_record, "1");
func13();
}
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
    char ch;
    int res;
    welcome();
    init();
    printf("%s days after your last washing!\n",read_file(f_record));
    if(!update_date()) {
        printf("You have checked today!");
        exit(1);
    }
    printf("Have you washed your clothes? (Y/N)/(y/n): ");
    ch = getchar();
    getchar();
    res = input(ch);
    if(res == 0) {
        printf("=3\n");
        write_file(f_record, "1");
        update_date();
    }
    else if(res == 1) {
        printf("╭(╯^╰)╮\n");
        plus_day();
        update_date();
    }
    else
        printf("Error input, only (Y/N)/(y/n) admitted!\n");
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char ch;
    int res;
    welcome();
    init();
    printf("%s days after your last washing!\n",read_file(f_record));
    if(!update_date()) {
        printf("You have checked today!");
        exit(1);
    }
    printf("Have you washed your clothes? (Y/N)/(y/n): ");
    ch = getchar();
    getchar();
    res = input(ch);
    if(res == 0) {
        printf("=3\n");
        write_file(f_record, "1");
        update_date();
    }
    else if(res == 1) {
        printf("╭(╯^╰)╮\n");
        plus_day();
        update_date();
    }
    else
        printf("Error input, only (Y/N)/(y/n) admitted!\n");
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: res int


decompiled_code:
char *get_current_time()
{
struct tm *v0; // rbx
char *v1; // rbp
__int64 v2; // rdx
__int64 v3; // rdx
char s[3]; // [rsp+2h] [rbp-26h] BYREF
char dest[3]; // [rsp+5h] [rbp-23h] BYREF
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v1 = (char *)malloc(0xAuLL);
v2 = (unsigned int)v0->tm_mday;
if ( (int)v2 > 9 )
sprintf(dest, "%d", v2);
else
strcpy(dest, (&CONVERT_DAY_OR_MONTH)[(int)v2]);
v3 = (unsigned int)v0->tm_mon;
if ( (int)v3 > 8 )
sprintf(s, "%d", v3);
else
strcpy(s, (&CONVERT_DAY_OR_MONTH)[(int)v3 + 1]);
sprintf(v1, "%d%s%s", (unsigned int)(v0->tm_year + 1900), s, dest);
return v1;
}

canonical_decompiled_code:
char *func15()
{
struct tm *v0; // rbx
char *v1; // rbp
__int64 v2; // rdx
__int64 v3; // rdx
char s[3]; // [rsp+2h] [rbp-26h] BYREF
char dest[3]; // [rsp+5h] [rbp-23h] BYREF
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v1 = (char *)malloc(0xAuLL);
v2 = (unsigned int)v0->tm_mday;
if ( (int)v2 > 9 )
sprintf(dest, "%d", v2);
else
strcpy(dest, (&CONVERT_DAY_OR_MONTH)[(int)v2]);
v3 = (unsigned int)v0->tm_mon;
if ( (int)v3 > 8 )
sprintf(s, "%d", v3);
else
strcpy(s, (&CONVERT_DAY_OR_MONTH)[(int)v3 + 1]);
sprintf(v1, "%d%s%s", (unsigned int)(v0->tm_year + 1900), s, dest);
return v1;
}

original_code:
char *get_current_time()
{
    time_t t = time(((void *)0));
    struct tm *n_time = localtime(&t);
    char *tstr = (char *)malloc(sizeof(char) * 10);
    char day[3];
    char month[3];
    if(n_time->tm_mday < 10)
        strcpy(day, CONVERT_DAY_OR_MONTH[n_time->tm_mday]);
    else
        sprintf(day,"%d",n_time->tm_mday);
    if(n_time->tm_mon+1 < 10)
        strcpy(month, CONVERT_DAY_OR_MONTH[n_time->tm_mon+1]);
    else
        sprintf(month,"%d",n_time->tm_mon);
    sprintf(tstr,"%d%s%s",n_time->tm_year+1900,month,day);
    return tstr;
}

canonical_original_code:
char *get_current_time()
{
    long t = time(((void *)0));
    struct tm *n_time = localtime(&t);
    char *tstr = (char *)malloc(sizeof(char) * 10);
    char day[3];
    char month[3];
    if(n_time->tm_mday < 10)
        strcpy(day, CONVERT_DAY_OR_MONTH[n_time->tm_mday]);
    else
        sprintf(day,"%d",n_time->tm_mday);
    if(n_time->tm_mon+1 < 10)
        strcpy(month, CONVERT_DAY_OR_MONTH[n_time->tm_mon+1]);
    else
        sprintf(month,"%d",n_time->tm_mon);
    sprintf(tstr,"%d%s%s",n_time->tm_year+1900,month,day);
    return tstr;
}

variable_types: t long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; } *

variable_types:
tstr
char *

variable_types:
day
char [3]

variable_types:
month
char [3]

return_type: char *


decompiled_code:
__int64 __fastcall diff_day(__int64 a1, __int64 a2)
{
time_t v2; // rbx
time_t v3; // rax
__m128i v5; // [rsp+0h] [rbp-C8h] BYREF
__m128i v6; // [rsp+10h] [rbp-B8h] BYREF
__m128i v7; // [rsp+20h] [rbp-A8h] BYREF
const char *v8; // [rsp+30h] [rbp-98h]
struct tm tp; // [rsp+40h] [rbp-88h] BYREF
struct tm v10; // [rsp+80h] [rbp-48h] BYREF

pack_date((__int64)&v5, a1);
*(__m128i *)&v10.tm_sec = _mm_loadu_si128(&v5);
*(__m128i *)&v10.tm_mon = _mm_loadu_si128(&v6);
*(__m128i *)&v10.tm_isdst = _mm_loadu_si128(&v7);
v10.tm_zone = v8;
pack_date((__int64)&v5, a2);
*(__m128i *)&tp.tm_sec = _mm_loadu_si128(&v5);
*(__m128i *)&tp.tm_mon = _mm_loadu_si128(&v6);
*(__m128i *)&tp.tm_isdst = _mm_loadu_si128(&v7);
tp.tm_zone = v8;
v2 = mktime(&tp);
v3 = mktime(&v10);
return abs32((unsigned int)(int)difftime(v3, v2) / 86400LL);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2)
{
time_t v2; // rbx
time_t v3; // rax
__m128i v5; // [rsp+0h] [rbp-C8h] BYREF
__m128i v6; // [rsp+10h] [rbp-B8h] BYREF
__m128i v7; // [rsp+20h] [rbp-A8h] BYREF
const char *v8; // [rsp+30h] [rbp-98h]
struct tm tp; // [rsp+40h] [rbp-88h] BYREF
struct tm v10; // [rsp+80h] [rbp-48h] BYREF

func16((__int64)&v5, a1);
*(__m128i *)&v10.tm_sec = _mm_loadu_si128(&v5);
*(__m128i *)&v10.tm_mon = _mm_loadu_si128(&v6);
*(__m128i *)&v10.tm_isdst = _mm_loadu_si128(&v7);
v10.tm_zone = v8;
func16((__int64)&v5, a2);
*(__m128i *)&tp.tm_sec = _mm_loadu_si128(&v5);
*(__m128i *)&tp.tm_mon = _mm_loadu_si128(&v6);
*(__m128i *)&tp.tm_isdst = _mm_loadu_si128(&v7);
tp.tm_zone = v8;
v2 = mktime(&tp);
v3 = mktime(&v10);
return abs32((unsigned int)(int)difftime(v3, v2) / 86400LL);
}

original_code:
int diff_day(const char *day1, const char *day2)
{
    long t;
    Date tm1,tm2;
    tm1 = pack_date(day1);
    tm2 = pack_date(day2);
    t=(long)difftime(mktime(&tm1), mktime(&tm2));
    return(abs(t/24/3600));
}

canonical_original_code:
int diff_day(char *day1, char *day2)
{
    long t;
    struct tm tm1; struct tm tm2;
    tm1 = pack_date(day1);
    tm2 = pack_date(day2);
    t=(long)difftime(mktime(&tm1), mktime(&tm2));
    return(abs(t/24/3600));
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; }


repo: Zwitty/FileSystem

decompiled_code:
__int64 __fastcall sfs_gettype(char *s)
{
_BYTE *v1; // r13
void *v2; // r12
size_t i; // rbx
int v4; // eax
__int64 result; // rax
void *v6; // r13
void *v7; // r12
size_t j; // rbx
__int64 v9; // rdi

v1 = malloc(0x80uLL);
v2 = malloc(0x80uLL);
append(v2, 49LL);
for ( i = 0LL; strlen(s) > i; ++i )
append(v2, (unsigned int)s[i]);
v4 = inodeSearch(v2);
if ( v4 > 0 )
get_block((unsigned int)v4, v1);
result = 1LL;
if ( *v1 != 49 )
{
v6 = malloc(0x80uLL);
v7 = malloc(0x80uLL);
append(v7, 48LL);
for ( j = 0LL; strlen(s) > j; ++j )
append(v7, (unsigned int)s[j]);
v9 = (unsigned int)inodeSearch(v7);
result = 0xFFFFFFFFLL;
if ( (int)v9 > 0 )
{
get_block(v9, v6);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s)
{
_BYTE *v1; // r13
void *v2; // r12
size_t i; // rbx
int v4; // eax
__int64 result; // rax
void *v6; // r13
void *v7; // r12
size_t j; // rbx
__int64 v9; // rdi

v1 = malloc(0x80uLL);
v2 = malloc(0x80uLL);
append(v2, 49LL);
for ( i = 0LL; strlen(s) > i; ++i )
append(v2, (unsigned int)s[i]);
v4 = inodeSearch(v2);
if ( v4 > 0 )
get_block((unsigned int)v4, v1);
result = 1LL;
if ( *v1 != 49 )
{
v6 = malloc(0x80uLL);
v7 = malloc(0x80uLL);
append(v7, 48LL);
for ( j = 0LL; strlen(s) > j; ++j )
append(v7, (unsigned int)s[j]);
v9 = (unsigned int)inodeSearch(v7);
result = 0xFFFFFFFFLL;
if ( (int)v9 > 0 )
{
get_block(v9, v6);
result = 0LL;
}
}
return result;
}

original_code:
int
sfs_gettype(char *pathname){
 char* buf2;
 buf2 = malloc(128);
 char* path3;
 path3 = malloc(128);
 append(path3, '1');
 int w;
 for(w =0; w <strlen(pathname); w++){
  append(path3, pathname[w]);
 }
 int index2 = inodeSearch(path3);
 if(index2 > 0){
  get_block(index2, buf2);
 }
 if(buf2[0] == '1'){
  return 1;
 }
 char* buf1;
 buf1 = malloc(128);
 char* path2;
 path2 = malloc(128);
 append(path2, '0');
 int q;
 for(q =0; q <strlen(pathname); q++){
  append(path2, pathname[q]);
 }
 int index = inodeSearch(path2);
 if(index > 0){
  get_block(index, buf1);
  if(buf1[0] == '0'){
   return 0;
  }
 }else{
  return -1;
 }
}

canonical_original_code:
int sfs_gettype(char *pathname){
 char *buf2;
 buf2 = malloc(128);
 char *path3;
 path3 = malloc(128);
 append(path3, '1');
 int w;
 for(w =0; w <strlen(pathname); w++){
  append(path3, pathname[w]);
 }
 int index2 = inodeSearch(path3);
 if(index2 > 0){
  get_block(index2, buf2);
 }
 if(buf2[0] == '1'){
  return 1;
 }
 char *buf1;
 buf1 = malloc(128);
 char *path2;
 path2 = malloc(128);
 append(path2, '0');
 int q;
 for(q =0; q <strlen(pathname); q++){
  append(path2, pathname[q]);
 }
 int index = inodeSearch(path2);
 if(index > 0){
  get_block(index, buf1);
  if(buf1[0] == '0'){
   return 0;
  }
 }else{
  return -1;
 }
}

variable_types:
pathname
char *

variable_types: w int

variable_types: q int

variable_types: index int


decompiled_code:
__int64 __fastcall sfs_readdir(int a1, char *a2)
{
const char *v2; // r13
const char *v3; // r12
__int64 i; // rbx
const char *v5; // rbp
const char *v6; // r15
unsigned int v7; // ebx
int v8; // er13
__int64 j; // rbx
size_t v11; // rax

v2 = (const char *)(int)getDirSuperBlock();
v3 = (const char *)malloc(0x80uLL);
append(v3, 48LL);
for ( i = 0LL; strlen(v2) > ++i; append(v3, (unsigned int)v2[i]) )
;
v5 = (const char *)malloc(0x80uLL);
v6 = (const char *)malloc(0x80uLL);
v7 = 11;
v8 = 0;
while ( 1 )
{
get_block(v7, v5);
v11 = strlen(v3);
if ( !strncmp(v5, v3, v11) && ++v8 == a1 )
break;
if ( ++v7 == 512 )
return 0LL;
}
for ( j = 0LL; strlen(v5) > ++j; append(v6, (unsigned int)v5[j]) )
;
strcpy(a2, v6);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, char *a2)
{
const char *v2; // r13
const char *v3; // r12
__int64 i; // rbx
const char *v5; // rbp
const char *v6; // r15
unsigned int v7; // ebx
int v8; // er13
__int64 j; // rbx
size_t v11; // rax

v2 = (const char *)(int)getDirSuperBlock();
v3 = (const char *)malloc(0x80uLL);
append(v3, 48LL);
for ( i = 0LL; strlen(v2) > ++i; append(v3, (unsigned int)v2[i]) )
;
v5 = (const char *)malloc(0x80uLL);
v6 = (const char *)malloc(0x80uLL);
v7 = 11;
v8 = 0;
while ( 1 )
{
get_block(v7, v5);
v11 = strlen(v3);
if ( !strncmp(v5, v3, v11) && ++v8 == a1 )
break;
if ( ++v7 == 512 )
return 0LL;
}
for ( j = 0LL; strlen(v5) > ++j; append(v6, (unsigned int)v5[j]) )
;
strcpy(a2, v6);
return 1LL;
}

original_code:
int
sfs_readdir(int fd, char *mem_pointer){
 char* openDir;
 openDir = malloc(128);
 openDir = getDirSuperBlock();
 char* buf;
 buf = malloc(128);
 append(buf, '0');
 int i;
 for(i = 1; i < strlen(openDir); i++){
  append(buf, openDir[i]);
 }
 char* temp;
 temp = malloc(128);
 char* temp2;
 temp2 = malloc(128);
 int check = 0;
 int j;
 for (j = 11; j < 512; j++){
  get_block(j,temp);
  if(strncmp(temp, buf, strlen(buf)) == 0){
   check = check + 1;
   if(check == fd){
    int k;
    for(k =1; k <strlen(temp); k++){
     append(temp2, temp[k]);
    }
    strcpy(mem_pointer, temp2);
    return 1;
   }
  }
 }
 return 0;
}

canonical_original_code:
int sfs_readdir(int fd, char *mem_pointer){
 char *openDir;
 openDir = malloc(128);
 openDir = getDirSuperBlock();
 char *buf;
 buf = malloc(128);
 append(buf, '0');
 int i;
 for(i = 1; i < strlen(openDir); i++){
  append(buf, openDir[i]);
 }
 char *temp;
 temp = malloc(128);
 char *temp2;
 temp2 = malloc(128);
 int check = 0;
 int j;
 for (j = 11; j < 512; j++){
  get_block(j,temp);
  if(strncmp(temp, buf, strlen(buf)) == 0){
   check = check + 1;
   if(check == fd){
    int k;
    for(k =1; k <strlen(temp); k++){
     append(temp2, temp[k]);
    }
    strcpy(mem_pointer, temp2);
    return 1;
   }
  }
 }
 return 0;
}

variable_types: fd int

variable_types:
openDir
char *

variable_types: i int

variable_types:
temp
char *

variable_types: check int

variable_types: j int

variable_types: k int


decompiled_code:
__int64 init_disk()
{
int v0; // eax
int v1; // ebx
__int64 result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = open("simdisk.data", 66, 440LL);
diskfd = v0;
if ( v0 < 0 )
{
perror("opening disk data file");
result = 0xFFFFFFFFLL;
}
else
{
v1 = v0;
if ( lseek(v0, 0x10000LL, 0) < 0 )
{
perror("disk data file seek");
result = 0xFFFFFFFFLL;
}
else if ( write(v1, buf, 1uLL) < 0 )
{
perror("disk data file write");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
int v1; // ebx
__int64 result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = open("simdisk.data", 66, 440LL);
diskfd = v0;
if ( v0 < 0 )
{
perror("opening disk data file");
result = 0xFFFFFFFFLL;
}
else
{
v1 = v0;
if ( lseek(v0, 0x10000LL, 0) < 0 )
{
perror("disk data file seek");
result = 0xFFFFFFFFLL;
}
else if ( write(v1, buf, 1uLL) < 0 )
{
perror("disk data file write");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
static int
init_disk()
{
  char garbage;
  if ((diskfd = open("simdisk.data",02|0100,0400|0200|((0400|0200|0100) >> 3))) < 0) {
    perror("opening disk data file");
    return(-1);
  }
  if (lseek(diskfd,128*512,0) < 0) {
    perror("disk data file seek");
    return(-1);
  }
  if (write(diskfd,&garbage,1) < 0) {
    perror("disk data file write");
    return(-1);
  }
  return(0);
}

variable_types: garbage char


decompiled_code:
__int64 __fastcall get_block(unsigned int a1, void *a2)
{
int v2; // ebp
__int64 result; // rax

if ( a1 > 0x1FF )
{
fprintf(stderr, "get_block: invalid block number: %d\n", a1);
result = 0xFFFFFFFFLL;
}
else if ( diskfd < 0 && (unsigned int)init_disk() )
{
result = 0xFFFFFFFFLL;
}
else
{
v2 = diskfd;
if ( lseek(diskfd, (int)(a1 << 7), 0) < 0 || read(v2, a2, 0x80uLL) < 0 )
{
perror("get_block");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, void *a2)
{
int v2; // ebp
__int64 result; // rax

if ( a1 > 0x1FF )
{
fprintf(stderr, "get_block: invalid block number: %d\n", a1);
result = 0xFFFFFFFFLL;
}
else if ( diskfd < 0 && (unsigned int)func0() )
{
result = 0xFFFFFFFFLL;
}
else
{
v2 = diskfd;
if ( lseek(diskfd, (int)(a1 << 7), 0) < 0 || read(v2, a2, 0x80uLL) < 0 )
{
perror("get_block");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int
get_block(int blknum,
   char *buf)
{
  if (blknum >= 512 || blknum < 0) {
    fprintf(stderr,"get_block: invalid block number: %d\n",blknum);
    return(-1);
  }
  if (diskfd < 0) {
    if (init_disk() != 0) return(-1);
  }
  if (lseek(diskfd,blknum*128,0) < 0) {
    perror("get_block");
    return(-1);
  }
  if (read(diskfd,buf,128) < 0) {
    perror("get_block");
    return(-1);
  }
  return(0);
}

variable_types: blknum int

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall put_block(unsigned int a1, const void *a2)
{
int v2; // ebp
__int64 result; // rax

if ( a1 > 0x1FF )
{
fprintf(stderr, "put_block: invalid block number: %d\n", a1);
result = 0xFFFFFFFFLL;
}
else if ( diskfd < 0 && (unsigned int)init_disk() )
{
result = 0xFFFFFFFFLL;
}
else
{
v2 = diskfd;
if ( lseek(diskfd, (int)(a1 << 7), 0) < 0 || write(v2, a2, 0x80uLL) < 0 )
{
perror("put_block");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, const void *a2)
{
int v2; // ebp
__int64 result; // rax

if ( a1 > 0x1FF )
{
fprintf(stderr, "put_block: invalid block number: %d\n", a1);
result = 0xFFFFFFFFLL;
}
else if ( diskfd < 0 && (unsigned int)func0() )
{
result = 0xFFFFFFFFLL;
}
else
{
v2 = diskfd;
if ( lseek(diskfd, (int)(a1 << 7), 0) < 0 || write(v2, a2, 0x80uLL) < 0 )
{
perror("put_block");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int
put_block(int blknum,
   char *buf)
{
  if (blknum >= 512 || blknum < 0) {
    fprintf(stderr,"put_block: invalid block number: %d\n",blknum);
    return(-1);
  }
  if (diskfd < 0) {
    if (init_disk() != 0) return(-1);
  }
  if (lseek(diskfd,blknum*128,0) < 0) {
    perror("put_block");
    return(-1);
  }
  if (write(diskfd,buf,128) < 0) {
    perror("put_block");
    return(-1);
  }
  return(0);
}


decompiled_code:
__int64 __fastcall sfs_close(int a1)
{
__int64 result; // rax
_WORD *v2; // rax

result = 0xFFFFFFFFLL;
if ( a1 <= 4 )
{
v2 = malloc(0x80uLL);
*v2 = 48;
put_block((unsigned int)(a1 - 1), v2);
result = 1LL;
}
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a1 <= 4 )
{
v2 = malloc(0x80uLL);
*v2 = 48;
put_block((unsigned int)(a1 - 1), v2);
result = 1LL;
}
return result;
}

original_code:
int sfs_close(int fd){
 if (fd <= 4){
  char* buf;
  buf = malloc(128);
  strcpy(buf, "0");
  put_block(fd-1,buf);
  return 1;
 }else{
  return -1;
 }
}

canonical_original_code:
int sfs_close(int fd){
 if (fd <= 4){
  char *buf;
  buf = malloc(128);
  strcpy(buf, "0");
  put_block(fd-1,buf);
  return 1;
 }else{
  return -1;
 }
}


inodeSearch

decompiled_code:
__int64 __fastcall inodeSearch(char *s2)
{
const char *v1; // rbp
unsigned int v2; // ebx
size_t v3; // rax

v1 = (const char *)malloc(0x80uLL);
v2 = 11;
while ( 1 )
{
get_block(v2, v1);
if ( *v1 )
{
v3 = strlen(s2);
if ( !strncmp(v1, s2, v3) )
break;
}
if ( ++v2 == 512 )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2)
{
const char *v1; // rbp
unsigned int v2; // ebx
size_t v3; // rax

v1 = (const char *)malloc(0x80uLL);
v2 = 11;
while ( 1 )
{
get_block(v2, v1);
if ( *v1 )
{
v3 = strlen(s2);
if ( !strncmp(v1, s2, v3) )
break;
}
if ( ++v2 == 512 )
return (unsigned int)-1;
}
return v2;
}

original_code:
int inodeSearch(char* path){
 int i, j;
 int index = -1;
 char* temp, temp2;
 char* A;
 temp = malloc(128);
 for (i=11; i<512; i++){
  get_block(i, temp);
  if (temp[0] != '\0'){
   if(strncmp(temp, path, strlen(path)) == 0){
     index = i;
     break;
    }else{
     continue;
    }
  }
 }
 return index;
}

canonical_original_code:
int inodeSearch(char *path){
 int i; int j;
 int index = -1;
 char *temp; char temp2;
 char *A;
 temp = malloc(128);
 for (i=11; i<512; i++){
  get_block(i, temp);
  if (temp[0] != '\0'){
   if(strncmp(temp, path, strlen(path)) == 0){
     index = i;
     break;
    }else{
     continue;
    }
  }
 }
 return index;
}

variable_types:
path
char *

variable_types:
A
char *


inodeReadTable

decompiled_code:
__int64 inodeReadTable()
{
void *v0; // rbx
void *v1; // r13
__int64 *v2; // rbx
__int64 *v3; // rbp
int v4; // er12
__int64 i; // rbx
char v6; // si

v0 = malloc(0x80uLL);
inodeBlocks = (__int64)v0;
*(&inodeBlocks + 1) = (__int64)malloc(0x80uLL);
*(&inodeBlocks + 2) = (__int64)malloc(0x80uLL);
*(&inodeBlocks + 3) = (__int64)malloc(0x80uLL);
*(&inodeBlocks + 4) = (__int64)malloc(0x80uLL);
*(&inodeBlocks + 5) = (__int64)malloc(0x80uLL);
*(&inodeBlocks + 6) = (__int64)malloc(0x80uLL);
*(&inodeBlocks + 7) = (__int64)malloc(0x80uLL);
get_block(2LL, v0);
get_block(3LL, *(&inodeBlocks + 1));
get_block(4LL, *(&inodeBlocks + 2));
get_block(5LL, *(&inodeBlocks + 3));
get_block(6LL, *(&inodeBlocks + 4));
get_block(7LL, *(&inodeBlocks + 5));
get_block(8LL, *(&inodeBlocks + 6));
get_block(9LL, *(&inodeBlocks + 7));
v1 = malloc(0x80uLL);
v2 = inode;
do
*v2++ = (__int64)malloc(0x14uLL);
while ( v2 != (__int64 *)(unsigned int)((_DWORD)inode + 4096) );
v3 = &inodeBlocks;
v4 = 0;
do
{
for ( i = 0LL; i != 128; ++i )
{
v6 = *(_BYTE *)(*v3 + i);
if ( v6 == 33 )
{
if ( v4 <= 511 )
inode[v4++] = (__int64)v1;
}
else if ( v6 )
{
append(v1, (unsigned int)v6);
}
}
++v3;
}
while ( (__int64 *)(unsigned int)((_DWORD)&inodeBlocks + 64) != v3 );
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
void *v0; // rbx
void *v1; // r13
__int64 *v2; // rbx
__int64 *v3; // rbp
int v4; // er12
__int64 i; // rbx
char v6; // si

v0 = malloc(0x80uLL);
inodeBlocks = (__int64)v0;
*(&inodeBlocks + 1) = (__int64)malloc(0x80uLL);
*(&inodeBlocks + 2) = (__int64)malloc(0x80uLL);
*(&inodeBlocks + 3) = (__int64)malloc(0x80uLL);
*(&inodeBlocks + 4) = (__int64)malloc(0x80uLL);
*(&inodeBlocks + 5) = (__int64)malloc(0x80uLL);
*(&inodeBlocks + 6) = (__int64)malloc(0x80uLL);
*(&inodeBlocks + 7) = (__int64)malloc(0x80uLL);
get_block(2LL, v0);
get_block(3LL, *(&inodeBlocks + 1));
get_block(4LL, *(&inodeBlocks + 2));
get_block(5LL, *(&inodeBlocks + 3));
get_block(6LL, *(&inodeBlocks + 4));
get_block(7LL, *(&inodeBlocks + 5));
get_block(8LL, *(&inodeBlocks + 6));
get_block(9LL, *(&inodeBlocks + 7));
v1 = malloc(0x80uLL);
v2 = inode;
do
*v2++ = (__int64)malloc(0x14uLL);
while ( v2 != (__int64 *)(unsigned int)((_DWORD)inode + 4096) );
v3 = &inodeBlocks;
v4 = 0;
do
{
for ( i = 0LL; i != 128; ++i )
{
v6 = *(_BYTE *)(*v3 + i);
if ( v6 == 33 )
{
if ( v4 <= 511 )
inode[v4++] = (__int64)v1;
}
else if ( v6 )
{
append(v1, (unsigned int)v6);
}
}
++v3;
}
while ( (__int64 *)(unsigned int)((_DWORD)&inodeBlocks + 64) != v3 );
return 0LL;
}

original_code:
int inodeReadTable(){
 inodeBlocks[0] = malloc(128);
 inodeBlocks[1] = malloc(128);
 inodeBlocks[2] = malloc(128);
 inodeBlocks[3] = malloc(128);
 inodeBlocks[4] = malloc(128);
 inodeBlocks[5] = malloc(128);
 inodeBlocks[6] = malloc(128);
 inodeBlocks[7] = malloc(128);
 get_block(2, inodeBlocks[0]);
 get_block(3, inodeBlocks[1]);
 get_block(4, inodeBlocks[2]);
 get_block(5, inodeBlocks[3]);
 get_block(6, inodeBlocks[4]);
 get_block(7, inodeBlocks[5]);
 get_block(8, inodeBlocks[6]);
 get_block(9, inodeBlocks[7]);
 int j, k;
 int i = 0;
 char* temp;
 temp = malloc(128);
 int g;
 for(g=0; g<512; g++){
  inode[g] = malloc(20);
 }
 for (j = 0; j < 8; j++) {
  for (k =0; k < 128; k++){
   if(inodeBlocks[j][k] == '!'){
    if(i < 512){
     inode[i] = temp;
     i = i + 1;
    }
   }else if(inodeBlocks[j][k] != '\0') {
    append(temp, inodeBlocks[j][k]);
   }else{
    continue;
   }
  }
 }
 return 0;
}

canonical_original_code:
int inodeReadTable(){
 inodeBlocks[0] = malloc(128);
 inodeBlocks[1] = malloc(128);
 inodeBlocks[2] = malloc(128);
 inodeBlocks[3] = malloc(128);
 inodeBlocks[4] = malloc(128);
 inodeBlocks[5] = malloc(128);
 inodeBlocks[6] = malloc(128);
 inodeBlocks[7] = malloc(128);
 get_block(2, inodeBlocks[0]);
 get_block(3, inodeBlocks[1]);
 get_block(4, inodeBlocks[2]);
 get_block(5, inodeBlocks[3]);
 get_block(6, inodeBlocks[4]);
 get_block(7, inodeBlocks[5]);
 get_block(8, inodeBlocks[6]);
 get_block(9, inodeBlocks[7]);
 int j; int k;
 int i = 0;
 char *temp;
 temp = malloc(128);
 int g;
 for(g=0; g<512; g++){
  inode[g] = malloc(20);
 }
 for (j = 0; j < 8; j++) {
  for (k =0; k < 128; k++){
   if(inodeBlocks[j][k] == '!'){
    if(i < 512){
     inode[i] = temp;
     i = i + 1;
    }
   }else if(inodeBlocks[j][k] != '\0') {
    append(temp, inodeBlocks[j][k]);
   }else{
    continue;
   }
  }
 }
 return 0;
}

variable_types: g int


inodeAdd

decompiled_code:
__int64 inodeAdd()
{
_BYTE *v0; // rbp
unsigned int v1; // ebx

inodeReadTable();
v0 = malloc(0x80uLL);
v1 = 11;
while ( 1 )
{
get_block(v1, v0);
if ( !*v0 )
break;
if ( ++v1 == 512 )
return (unsigned int)-1;
}
inode[v1] = (char)v1;
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
_BYTE *v0; // rbp
unsigned int v1; // ebx

func1();
v0 = malloc(0x80uLL);
v1 = 11;
while ( 1 )
{
get_block(v1, v0);
if ( !*v0 )
break;
if ( ++v1 == 512 )
return (unsigned int)-1;
}
inode[v1] = (char)v1;
return v1;
}

original_code:
int inodeAdd(int type, char* path){
 inodeReadTable();
 int i;
 int index = -1;
 char* chartype = (char)type;
 char* temp, temp2;
 temp = malloc(128);
 for (i=11; i<512; i++){
  get_block(i, temp);
  if (temp[0] == '\0'){
   index = i;
   temp2 = (char)index;
   inode[i] = temp2;
   break;
  }
 }
 return index;
}

canonical_original_code:
int inodeAdd(int type, char *path){
 inodeReadTable();
 int i;
 int index = -1;
 char *chartype = (char)type;
 char *temp; char temp2;
 temp = malloc(128);
 for (i=11; i<512; i++){
  get_block(i, temp);
  if (temp[0] == '\0'){
   index = i;
   temp2 = (char)index;
   inode[i] = temp2;
   break;
  }
 }
 return index;
}

variable_types: type int

variable_types:
chartype
char *


append

decompiled_code:
__int64 __fastcall append(const char *a1, char a2)
{
__int64 result; // rax

result = (int)strlen(a1);
a1[(int)result] = a2;
a1[(int)result + 1] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, char a2)
{
__int64 result; // rax

result = (int)strlen(a1);
a1[(int)result] = a2;
a1[(int)result + 1] = 0;
return result;
}

original_code:
void append(char* s, char c)
{
        int len = strlen(s);
        s[len] = c;
        s[len+1] = '\0';
}

canonical_original_code:
void append(char *s, char c)
{
        int len = strlen(s);
        s[len] = c;
        s[len+1] = '\0';
}

variable_types:
s
char *

variable_types: c char

variable_types: len int


decompiled_code:
__int64 __fastcall sfs_write(unsigned int a1, int a2, int a3, __int64 a4)
{
_BYTE *v6; // rbp
__int64 result; // rax
unsigned int v8; // er13
int v9; // ebx
__int64 v10; // rax
__int64 v11; // r12

v6 = malloc(0x80uLL);
result = getSuperBlock(a1);
if ( (_DWORD)result != -1 )
{
v8 = result + 1;
get_block((unsigned int)(result + 1), v6);
v9 = a2 + a3;
if ( a2 < v9 )
{
v10 = a2;
v11 = a4 - a2;
do
{
v6[v10] = *(_BYTE *)(v11 + v10);
++v10;
}
while ( v9 > (int)v10 );
}
put_block(v8, v6);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2, int a3, __int64 a4)
{
_BYTE *v6; // rbp
__int64 result; // rax
unsigned int v8; // er13
int v9; // ebx
__int64 v10; // rax
__int64 v11; // r12

v6 = malloc(0x80uLL);
result = getSuperBlock(a1);
if ( (_DWORD)result != -1 )
{
v8 = result + 1;
get_block((unsigned int)(result + 1), v6);
v9 = a2 + a3;
if ( a2 < v9 )
{
v10 = a2;
v11 = a4 - a2;
do
{
v6[v10] = *(_BYTE *)(v11 + v10);
++v10;
}
while ( v9 > (int)v10 );
}
put_block(v8, v6);
result = 1LL;
}
return result;
}

original_code:
int sfs_write(int fd, int start, int length, char *mem_pointer){
 char* buf;
 buf = malloc(128);
 int index;
 index = getSuperBlock(fd);
 if(index == -1){
  return -1;
 }
 get_block(index+1, buf);
 int i;
 int space = start+length;
 for(i = start; i < space; i++){
  buf[i] = mem_pointer[i-start];
 }
 put_block(index+1, buf);
 return 1;
}

canonical_original_code:
int sfs_write(int fd, int start, int length, char *mem_pointer){
 char *buf;
 buf = malloc(128);
 int index;
 index = getSuperBlock(fd);
 if(index == -1){
  return -1;
 }
 get_block(index+1, buf);
 int i;
 int space = start+length;
 for(i = start; i < space; i++){
  buf[i] = mem_pointer[i-start];
 }
 put_block(index+1, buf);
 return 1;
}

variable_types: fd int

variable_types: start int

variable_types: length int

variable_types: index int

variable_types: space int


putSuperBlock

decompiled_code:
__int64 __fastcall putSuperBlock(unsigned int a1)
{
char *v1; // r12
_BYTE *v2; // rbp
unsigned int v3; // ebx

v1 = (char *)malloc(0x80uLL);
snprintf(v1, 0x7FuLL, "%d", a1);
v2 = malloc(0x80uLL);
v3 = 0;
while ( 1 )
{
get_block(v3, v2);
if ( *v2 == 48 )
break;
if ( ++v3 == 4 )
return (unsigned int)-1;
}
put_block(v3, v1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
char *v1; // r12
_BYTE *v2; // rbp
unsigned int v3; // ebx

v1 = (char *)malloc(0x80uLL);
snprintf(v1, 0x7FuLL, "%d", a1);
v2 = malloc(0x80uLL);
v3 = 0;
while ( 1 )
{
get_block(v3, v2);
if ( *v2 == 48 )
break;
if ( ++v3 == 4 )
return (unsigned int)-1;
}
put_block(v3, v1);
return v3;
}

original_code:
int putSuperBlock(int FileLoc){
 char* buf;
 buf = malloc(128);
 char* fileChar;
 fileChar = malloc(128);
 snprintf(fileChar, 127, "%d",FileLoc);
 int i;
 char* temp;
 temp = malloc(128);
 for(i = 0; i< 4; i++){
  get_block(i,temp);
  if(temp[0] == '0'){
   put_block(i, fileChar);
   return i;
  }
 }
 return -1;
}

canonical_original_code:
int putSuperBlock(int FileLoc){
 char *buf;
 buf = malloc(128);
 char *fileChar;
 fileChar = malloc(128);
 snprintf(fileChar, 127, "%d",FileLoc);
 int i;
 char *temp;
 temp = malloc(128);
 for(i = 0; i< 4; i++){
  get_block(i,temp);
  if(temp[0] == '0'){
   put_block(i, fileChar);
   return i;
  }
 }
 return -1;
}

variable_types: FileLoc int

variable_types:
fileChar
char *

variable_types: i int

variable_types:
temp
char *


getSuperBlock

decompiled_code:
int __fastcall getSuperBlock(int a1)
{
const char *v1; // rbp

v1 = (const char *)malloc(0x80uLL);
get_block((unsigned int)(a1 - 1), v1);
return atoi(v1);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
const char *v1; // rbp

v1 = (const char *)malloc(0x80uLL);
get_block((unsigned int)(a1 - 1), v1);
return atoi(v1);
}

original_code:
int getSuperBlock(int fd){
 char* buf;
 buf = malloc(128);
 get_block(fd-1, buf);
 int openFile =atoi(buf);
 return openFile;
}

canonical_original_code:
int getSuperBlock(int fd){
 char *buf;
 buf = malloc(128);
 get_block(fd-1, buf);
 int openFile = atoi(buf);
 return openFile;
}

variable_types:
buf
char *

variable_types: openFile int


putDirSuperBlock

decompiled_code:
__int64 __fastcall putDirSuperBlock(char *s)
{
void *v1; // r12
size_t i; // rbx

v1 = malloc(0x80uLL);
for ( i = 0LL; strlen(s) > i; ++i )
append(v1, (unsigned int)s[i]);
put_block(4LL, v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s)
{
void *v1; // r12
size_t i; // rbx

v1 = malloc(0x80uLL);
for ( i = 0LL; strlen(s) > i; ++i )
append(v1, (unsigned int)s[i]);
put_block(4LL, v1);
return 0LL;
}

original_code:
int putDirSuperBlock(char* openDir){
 char* buf;
 buf = malloc(128);
 int i;
 for(i=0; i< strlen(openDir); i++){
  append(buf, openDir[i]);
 }
 put_block(4, buf);
 return 0;
}

canonical_original_code:
int putDirSuperBlock(char *openDir){
 char *buf;
 buf = malloc(128);
 int i;
 for(i=0; i< strlen(openDir); i++){
  append(buf, openDir[i]);
 }
 put_block(4, buf);
 return 0;
}

variable_types:
openDir
char *


getDirSuperBlock

decompiled_code:
void *getDirSuperBlock()
{
void *v0; // rbx

v0 = malloc(0x80uLL);
get_block(4LL, v0);
return v0;
}

canonical_decompiled_code:
void *func3()
{
void *v0; // rbx

v0 = malloc(0x80uLL);
get_block(4LL, v0);
return v0;
}

original_code:
char* getDirSuperBlock(){
 char* dir;
 dir = malloc(128);
 int i;
 get_block(4, dir);
 return dir;
}

canonical_original_code:
char *getDirSuperBlock(){
 char *dir;
 dir = malloc(128);
 int i;
 get_block(4, dir);
 return dir;
}

variable_types:
dir
char *


decompiled_code:
__int64 __fastcall sfs_create(char *s, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // er13
size_t v4; // rcx
unsigned __int64 v5; // rax
int v6; // edx
__int64 result; // rax
void *v8; // r14
size_t i; // rbp
void *v10; // rbx

v2 = inodeAdd(a2, s);
if ( *s != 47 )
return 0xFFFFFFFFLL;
v3 = v2;
if ( v2 == -1 )
return 0xFFFFFFFFLL;
v4 = strlen(s);
v5 = 1LL;
v6 = 0;
while ( v4 > v5 )
{
if ( s[v5] == 47 )
{
v6 = 0;
}
else if ( ++v6 > 6 )
{
return 0xFFFFFFFFLL;
}
++v5;
}
v8 = malloc(0x80uLL);
append(v8, (char)(a2 + 48));
for ( i = 0LL; strlen(s) > i; ++i )
append(v8, (unsigned int)s[i]);
put_block(v3, v8);
result = 1LL;
if ( !a2 )
{
v10 = malloc(0x80uLL);
append(v10, 33LL);
put_block(v3 + 1, v10);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // er13
size_t v4; // rcx
unsigned __int64 v5; // rax
int v6; // edx
__int64 result; // rax
void *v8; // r14
size_t i; // rbp
void *v10; // rbx

v2 = inodeAdd(a2, s);
if ( *s != 47 )
return 0xFFFFFFFFLL;
v3 = v2;
if ( v2 == -1 )
return 0xFFFFFFFFLL;
v4 = strlen(s);
v5 = 1LL;
v6 = 0;
while ( v4 > v5 )
{
if ( s[v5] == 47 )
{
v6 = 0;
}
else if ( ++v6 > 6 )
{
return 0xFFFFFFFFLL;
}
++v5;
}
v8 = malloc(0x80uLL);
append(v8, (char)(a2 + 48));
for ( i = 0LL; strlen(s) > i; ++i )
append(v8, (unsigned int)s[i]);
put_block(v3, v8);
result = 1LL;
if ( !a2 )
{
v10 = malloc(0x80uLL);
append(v10, 33LL);
put_block(v3 + 1, v10);
result = 1LL;
}
return result;
}

original_code:
int sfs_create(char *pathname, int type){
 int index;
 index = inodeAdd(type, pathname);
 if(pathname[0] != '/')
 {
  return -1;
 }
 if(index == -1){
  return -1;
 }
 int p;
 int count = 0;
 for(p=1; p<strlen(pathname);p++){
  if(pathname[p] != '/'){
   count = count + 1;
  }
  if(pathname[p] == '/'){
   count = 0;
  }
  if(count > 6){
   return -1;
  }
 }
 char* addToBlock;
 addToBlock = malloc(128);
 char* chartype = (char)(((int)'0')+type);
 append(addToBlock, chartype);
 int i;
 for(i=0; i<strlen(pathname); i++){
  append(addToBlock, pathname[i]);
 }
 put_block(index, addToBlock);
 if(type == 0){
  char* dataBuf;
  dataBuf = malloc(128);
  append(dataBuf, '!');
  put_block(index+1, dataBuf);
 }
 return 1;
}

canonical_original_code:
int sfs_create(char *pathname, int type){
 int index;
 index = inodeAdd(type, pathname);
 if(pathname[0] != '/')
 {
  return -1;
 }
 if(index == -1){
  return -1;
 }
 int p;
 int count = 0;
 for(p=1; p<strlen(pathname);p++){
  if(pathname[p] != '/'){
   count = count + 1;
  }
  if(pathname[p] == '/'){
   count = 0;
  }
  if(count > 6){
   return -1;
  }
 }
 char *addToBlock;
 addToBlock = malloc(128);
 char *chartype = (char)(((int)'0')+type);
 append(addToBlock, chartype);
 int i;
 for(i=0; i<strlen(pathname); i++){
  append(addToBlock, pathname[i]);
 }
 put_block(index, addToBlock);
 if(type == 0){
  char *dataBuf;
  dataBuf = malloc(128);
  append(dataBuf, '!');
  put_block(index+1, dataBuf);
 }
 return 1;
}

variable_types:
pathname
char *

variable_types: type int

variable_types: p int

variable_types: count int

variable_types:
addToBlock
char *

variable_types:
chartype
char *

variable_types:
dataBuf
char *


decompiled_code:
__int64 __fastcall sfs_read(unsigned int a1, int a2, int a3, __int64 a4)
{
_BYTE *v6; // r12
__int64 result; // rax
__int64 v8; // rax
__int64 v9; // rbp

v6 = malloc(0x80uLL);
result = getSuperBlock(a1);
if ( (_DWORD)result != -1 )
{
get_block((unsigned int)(result + 1), v6);
if ( a2 >= a2 + a3 )
{
result = 1LL;
}
else
{
v8 = a2;
v9 = a4 - a2;
do
{
*(_BYTE *)(v9 + v8) = v6[v8];
++v8;
}
while ( a2 + a3 > (int)v8 );
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2, int a3, __int64 a4)
{
_BYTE *v6; // r12
__int64 result; // rax
__int64 v8; // rax
__int64 v9; // rbp

v6 = malloc(0x80uLL);
result = getSuperBlock(a1);
if ( (_DWORD)result != -1 )
{
get_block((unsigned int)(result + 1), v6);
if ( a2 >= a2 + a3 )
{
result = 1LL;
}
else
{
v8 = a2;
v9 = a4 - a2;
do
{
*(_BYTE *)(v9 + v8) = v6[v8];
++v8;
}
while ( a2 + a3 > (int)v8 );
result = 1LL;
}
}
return result;
}

original_code:
int sfs_read(int fd, int start, int length, char *mem_pointer){
 char* buf;
 buf = malloc(128);
 int index = getSuperBlock(fd);
 if(index == -1){
  return -1;
 }else
  get_block(index+1, buf);
  int i;
  int space = start+length;
  for(i = start; i < space; i++){
   mem_pointer[i-start] = buf[i];
  }
 return 1;
}

canonical_original_code:
int sfs_read(int fd, int start, int length, char *mem_pointer){
 char *buf;
 buf = malloc(128);
 int index = getSuperBlock(fd);
 if(index == -1){
  return -1;
 }else
  get_block(index+1, buf);
  int i;
  int space = start+length;
  for(i = start; i < space; i++){
   mem_pointer[i-start] = buf[i];
  }
 return 1;
}

variable_types: fd int

variable_types: start int

variable_types: length int

variable_types: index int


decompiled_code:
__int64 __fastcall sfs_delete(char *s)
{
void *v1; // r12
size_t i; // rbx
int v3; // ebx
__int64 result; // rax
void *v5; // rax

v1 = malloc(0x80uLL);
append(v1, 48LL);
for ( i = 0LL; strlen(s) > i; ++i )
append(v1, (unsigned int)s[i]);
v3 = inodeSearch(v1);
result = 0LL;
if ( v3 >= 0 )
{
v5 = malloc(0x80uLL);
put_block((unsigned int)v3, v5);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s)
{
void *v1; // r12
size_t i; // rbx
int v3; // ebx
__int64 result; // rax
void *v5; // rax

v1 = malloc(0x80uLL);
append(v1, 48LL);
for ( i = 0LL; strlen(s) > i; ++i )
append(v1, (unsigned int)s[i]);
v3 = inodeSearch(v1);
result = 0LL;
if ( v3 >= 0 )
{
v5 = malloc(0x80uLL);
put_block((unsigned int)v3, v5);
result = 1LL;
}
return result;
}

original_code:
int sfs_delete(char *pathname){
 char* path2;
 path2 = malloc(128);
 append(path2, '0');
 int q;
 for(q =0; q <strlen(pathname); q++){
  append(path2, pathname[q]);
 }
 int index = inodeSearch(path2);
 if(index < 0){
  return 0;
 }
 char* buf = malloc(128);
 put_block(index, buf);
 return 1;
}

canonical_original_code:
int sfs_delete(char *pathname){
 char *path2;
 path2 = malloc(128);
 append(path2, '0');
 int q;
 for(q =0; q <strlen(pathname); q++){
  append(path2, pathname[q]);
 }
 int index = inodeSearch(path2);
 if(index < 0){
  return 0;
 }
 char *buf = malloc(128);
 put_block(index, buf);
 return 1;
}

variable_types: q int


decompiled_code:
__int64 __fastcall sfs_open(char *s)
{
unsigned int v1; // er13
void *v2; // r12
size_t i; // rbx
int v4; // eax

v1 = sfs_gettype();
v2 = malloc(0x80uLL);
append(v2, (unsigned int)(char)(v1 + 48));
for ( i = 0LL; strlen(s) > i; ++i )
append(v2, (unsigned int)s[i]);
v4 = inodeSearch(v2);
if ( v4 < 0 )
return (unsigned int)v4;
if ( !v1 )
return (unsigned int)(putSuperBlock((unsigned int)v4) + 1);
if ( v1 == 1 )
putDirSuperBlock(v2);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s)
{
unsigned int v1; // er13
void *v2; // r12
size_t i; // rbx
int v4; // eax

v1 = sfs_gettype();
v2 = malloc(0x80uLL);
append(v2, (unsigned int)(char)(v1 + 48));
for ( i = 0LL; strlen(s) > i; ++i )
append(v2, (unsigned int)s[i]);
v4 = inodeSearch(v2);
if ( v4 < 0 )
return (unsigned int)v4;
if ( !v1 )
return (unsigned int)(putSuperBlock((unsigned int)v4) + 1);
if ( v1 == 1 )
putDirSuperBlock(v2);
return v1;
}

original_code:
int sfs_open(char *pathname){
 int type = sfs_gettype(pathname);
 char chartype = (char)(((int)'0')+type);
 char* path2;
 path2 = malloc(128);
 append(path2, chartype);
 int q;
 for(q =0; q <strlen(pathname); q++){
  append(path2, pathname[q]);
 }
 int index = inodeSearch(path2);
 if(index < 0){
  return index;
 }
 if(type == 0){
  return putSuperBlock(index) + 1;
 }
 if(type == 1){
  putDirSuperBlock(path2);
 }
 return type;
}

canonical_original_code:
int sfs_open(char *pathname){
 int type = sfs_gettype(pathname);
 char chartype = (char)(((int)'0')+type);
 char *path2;
 path2 = malloc(128);
 append(path2, chartype);
 int q;
 for(q =0; q <strlen(pathname); q++){
  append(path2, pathname[q]);
 }
 int index = inodeSearch(path2);
 if(index < 0){
  return index;
 }
 if(type == 0){
  return putSuperBlock(index) + 1;
 }
 if(type == 1){
  putDirSuperBlock(path2);
 }
 return type;
}

variable_types: chartype char


decompiled_code:
__int64 __fastcall sfs_initialize(int a1)
{
_WORD *v1; // r15
_WORD *v2; // r14
_WORD *v3; // r13
char *v4; // r12
char *v5; // rbp
char *v6; // rax
char *v7; // rbx
__int64 result; // rax
void *v9; // rbp
unsigned int i; // ebx
void *v11; // [rsp+8h] [rbp-60h]
void *v12; // [rsp+10h] [rbp-58h]
void *v13; // [rsp+18h] [rbp-50h]
void *v14; // [rsp+20h] [rbp-48h]
_WORD *v15; // [rsp+28h] [rbp-40h]

v1 = malloc(0x80uLL);
*v1 = 48;
v2 = malloc(0x80uLL);
*v2 = 48;
v3 = malloc(0x80uLL);
*v3 = 48;
v15 = malloc(0x80uLL);
*v15 = 48;
v4 = (char *)malloc(0x80uLL);
strcpy(v4, "1/");
v5 = (char *)malloc(0x80uLL);
strcpy(v5, "101/!");
v11 = malloc(0x80uLL);
v12 = malloc(0x80uLL);
v13 = malloc(0x80uLL);
v14 = malloc(0x80uLL);
v6 = (char *)malloc(0x80uLL);
strcpy(v6, "1/");
if ( a1 > 0 )
{
v9 = malloc(0x80uLL);
for ( i = 0; i != 512; ++i )
put_block(i, v9);
result = 2LL;
}
else
{
v7 = v6;
put_block(0LL, v1);
put_block(1LL, v2);
put_block(2LL, v3);
put_block(3LL, v15);
put_block(4LL, v4);
put_block(5LL, v5);
put_block(6LL, v11);
put_block(7LL, v12);
put_block(8LL, v13);
put_block(9LL, v14);
put_block(10LL, v7);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
_WORD *v1; // r15
_WORD *v2; // r14
_WORD *v3; // r13
char *v4; // r12
char *v5; // rbp
char *v6; // rax
char *v7; // rbx
__int64 result; // rax
void *v9; // rbp
unsigned int i; // ebx
void *v11; // [rsp+8h] [rbp-60h]
void *v12; // [rsp+10h] [rbp-58h]
void *v13; // [rsp+18h] [rbp-50h]
void *v14; // [rsp+20h] [rbp-48h]
_WORD *v15; // [rsp+28h] [rbp-40h]

v1 = malloc(0x80uLL);
*v1 = 48;
v2 = malloc(0x80uLL);
*v2 = 48;
v3 = malloc(0x80uLL);
*v3 = 48;
v15 = malloc(0x80uLL);
*v15 = 48;
v4 = (char *)malloc(0x80uLL);
strcpy(v4, "1/");
v5 = (char *)malloc(0x80uLL);
strcpy(v5, "101/!");
v11 = malloc(0x80uLL);
v12 = malloc(0x80uLL);
v13 = malloc(0x80uLL);
v14 = malloc(0x80uLL);
v6 = (char *)malloc(0x80uLL);
strcpy(v6, "1/");
if ( a1 > 0 )
{
v9 = malloc(0x80uLL);
for ( i = 0; i != 512; ++i )
put_block(i, v9);
result = 2LL;
}
else
{
v7 = v6;
put_block(0LL, v1);
put_block(1LL, v2);
put_block(2LL, v3);
put_block(3LL, v15);
put_block(4LL, v4);
put_block(5LL, v5);
put_block(6LL, v11);
put_block(7LL, v12);
put_block(8LL, v13);
put_block(9LL, v14);
put_block(10LL, v7);
result = 1LL;
}
return result;
}

original_code:
int sfs_initialize(int erase){
 char * superblock_0 = ((void *)0);
 char * superblock_1 = ((void *)0);
 char * superblock_2 = ((void *)0);
 char * superblock_3 = ((void *)0);
 char * superblock_4 = ((void *)0);
 char* inodein[512];
 superblock_0 = malloc(128);
 strcpy(superblock_0, "0");
 superblock_1 = malloc(128);
 strcpy(superblock_1, "0");
 superblock_2 = malloc(128);
 strcpy(superblock_2, "0");
 superblock_3 = malloc(128);
 strcpy(superblock_3, "0");
 superblock_4 = malloc(128);
 strcpy(superblock_4, "1/");
 inodein[0] = malloc(128);
 inodein[0] = ((void *)0);
 inodein[1] = malloc(128);
 inodein[1] = ((void *)0);
 inodein[2] = malloc(128);
 inodein[3] = malloc(128);
 inodein[4] = malloc(128);
 inodein[5] = malloc(128);
 strcpy(inodein[5], "101/!");
 inodein[6] = malloc(128);
 inodein[7] = malloc(128);
 inodein[8] = malloc(128);
 inodein[9] = malloc(128);
 inodein[10] = malloc(128);
 strcpy(inodein[10], "1/");
 if(erase >= 1){
  char* buf;
  buf = malloc(128);
  int i;
  for(i=0; i<512; i++){
   put_block(i, buf);
  }
  return 2;
 }else{
  put_block(0, superblock_0);
  put_block(1, superblock_1);
  put_block(2, superblock_2);
  put_block(3, superblock_3);
  put_block(4, superblock_4);
  put_block(5, inodein[5]);
  put_block(6, inodein[6]);
  put_block(7, inodein[7]);
  put_block(8, inodein[8]);
  put_block(9, inodein[9]);
  put_block(10, inodein[10]);
  return 1;
 }
}

canonical_original_code:
int sfs_initialize(int erase){
 char *superblock_0 = ((void *)0);
 char *superblock_1 = ((void *)0);
 char *superblock_2 = ((void *)0);
 char *superblock_3 = ((void *)0);
 char *superblock_4 = ((void *)0);
 char *inodein[512];
 superblock_0 = malloc(128);
 strcpy(superblock_0, "0");
 superblock_1 = malloc(128);
 strcpy(superblock_1, "0");
 superblock_2 = malloc(128);
 strcpy(superblock_2, "0");
 superblock_3 = malloc(128);
 strcpy(superblock_3, "0");
 superblock_4 = malloc(128);
 strcpy(superblock_4, "1/");
 inodein[0] = malloc(128);
 inodein[0] = ((void *)0);
 inodein[1] = malloc(128);
 inodein[1] = ((void *)0);
 inodein[2] = malloc(128);
 inodein[3] = malloc(128);
 inodein[4] = malloc(128);
 inodein[5] = malloc(128);
 strcpy(inodein[5], "101/!");
 inodein[6] = malloc(128);
 inodein[7] = malloc(128);
 inodein[8] = malloc(128);
 inodein[9] = malloc(128);
 inodein[10] = malloc(128);
 strcpy(inodein[10], "1/");
 if(erase >= 1){
  char *buf;
  buf = malloc(128);
  int i;
  for(i=0; i<512; i++){
   put_block(i, buf);
  }
  return 2;
 }else{
  put_block(0, superblock_0);
  put_block(1, superblock_1);
  put_block(2, superblock_2);
  put_block(3, superblock_3);
  put_block(4, superblock_4);
  put_block(5, inodein[5]);
  put_block(6, inodein[6]);
  put_block(7, inodein[7]);
  put_block(8, inodein[8]);
  put_block(9, inodein[9]);
  put_block(10, inodein[10]);
  return 1;
 }
}

variable_types: erase int

variable_types:
inodein
char *[512]

variable_types:
buf
char *

variable_types: i int


repo: a-darwish/cuteOS

decompiled_code:
__int64 __fastcall bit_is_set(unsigned __int8 a1, char a2)
{
return (a1 >> a2) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, char a2)
{
return (a1 >> a2) & 1;
}

original_code:
static _Bool bit_is_set(uint8_t val, int bit)
{
 if ((val & (1U << bit)) == 0)
  return ((_Bool)0);
 return ((_Bool)1);
}

canonical_original_code:
static _Bool bit_is_set(unsigned char val, int bit)
{
 if ((val & (1U << bit)) == 0)
  return ((_Bool)0);
 return ((_Bool)1);
}

variable_types:
val
unsigned char

variable_types: bit int


decompiled_code:
__int64 __fastcall set_offsets(unsigned int a1, _DWORD *a2, unsigned int *a3, int a4)
{
__int64 result; // rax

if ( 8 * a4 <= a1 )
{
panic("%s:%d - !(bit < len * 8)\n", "lib/bitmap.c", 59LL);
result = bitmap_first_set_bit();
}
else
{
result = a1 >> 3;
*a2 = result;
*a3 = a1 & 7;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, _DWORD *a2, unsigned int *a3, int a4)
{
__int64 result; // rax

if ( 8 * a4 <= a1 )
{
panic("%s:%d - !(bit < len * 8)\n", "lib/bitmap.c", 59LL);
result = func2();
}
else
{
result = a1 >> 3;
*a2 = result;
*a3 = a1 & 7;
}
return result;
}

original_code:
static void set_offsets(uint bit, uint *byte_offset, uint *bit_offset, uint len)
{
 do { if (__builtin_expect((!(bit < len * 8)), 0)) panic("%s:%d - !(" "bit < len * 8" ")\n", "lib/bitmap.c", 59); } while (0);;
 *byte_offset = bit / 8;
 *bit_offset = bit % 8;
}

canonical_original_code:
static void set_offsets(unsigned int bit, unsigned int *byte_offset, unsigned int *bit_offset, unsigned int len)
{
 do { if (__builtin_expect((!(bit < len * 8)), 0)) panic("%s:%d - !(" "bit < len * 8" ")\n", "lib/bitmap.c", 59); } while (0);;
 *byte_offset = bit / 8;
 *bit_offset = bit % 8;
}

variable_types:
bit
unsigned int

variable_types:
len
unsigned int


decompiled_code:
__int64 __fastcall bitmap_first_set_bit(__int64 a1, int a2)
{
__int64 i; // r12
unsigned __int8 v4; // bp
int j; // ebx

if ( !a2 )
return -1LL;
for ( i = 0LL; i != a2; ++i )
{
v4 = *(_BYTE *)(a1 + i);
for ( j = 0; j != 8; ++j )
{
if ( (unsigned __int8)bit_is_set(v4, j) )
return (unsigned int)(j + 8 * i);
}
}
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 i; // r12
unsigned __int8 v4; // bp
int j; // ebx

if ( !a2 )
return -1LL;
for ( i = 0LL; i != a2; ++i )
{
v4 = *(_BYTE *)(a1 + i);
for ( j = 0; j != 8; ++j )
{
if ( (unsigned __int8)func0(v4, j) )
return (unsigned int)(j + 8 * i);
}
}
return -1LL;
}

original_code: int64_t bitmap_first_set_bit(char *buf, uint len) { uint bits_per_byte = 8; for (uint i = 0; i < len; i++) for (uint j = 0; j < bits_per_byte; j++) if (bit_is_set(buf[i], j)) return (i * 8) + j; return -1; }

canonical_original_code: long bitmap_first_set_bit(char *buf, unsigned int len) { unsigned int bits_per_byte = 8; for (unsigned int i = 0; i < len; i++) for (unsigned int j = 0; j < bits_per_byte; j++) if (bit_is_set(buf[i], j)) return (i * 8) + j; return -1; }

variable_types:
i
unsigned int

variable_types:
j
unsigned int

return_type: long


decompiled_code:
__int64 __fastcall bitmap_first_zero_bit(__int64 a1, int a2)
{
__int64 i; // r12
unsigned __int8 v4; // bp
int j; // ebx

if ( !a2 )
return -1LL;
for ( i = 0LL; i != a2; ++i )
{
v4 = *(_BYTE *)(a1 + i);
for ( j = 0; j != 8; ++j )
{
if ( !(unsigned __int8)bit_is_set(v4, j) )
return (unsigned int)(j + 8 * i);
}
}
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
__int64 i; // r12
unsigned __int8 v4; // bp
int j; // ebx

if ( !a2 )
return -1LL;
for ( i = 0LL; i != a2; ++i )
{
v4 = *(_BYTE *)(a1 + i);
for ( j = 0; j != 8; ++j )
{
if ( !(unsigned __int8)func0(v4, j) )
return (unsigned int)(j + 8 * i);
}
}
return -1LL;
}

original_code: int64_t bitmap_first_zero_bit(char *buf, uint len) { uint bits_per_byte = 8; for (uint i = 0; i < len; i++) for (uint j = 0; j < bits_per_byte; j++) if (!bit_is_set(buf[i], j)) return (i * 8) + j; return -1; }

canonical_original_code: long bitmap_first_zero_bit(char *buf, unsigned int len) { unsigned int bits_per_byte = 8; for (unsigned int i = 0; i < len; i++) for (unsigned int j = 0; j < bits_per_byte; j++) if (!bit_is_set(buf[i], j)) return (i * 8) + j; return -1; }


decompiled_code:
__int64 __fastcall bitmap_bit_is_set(__int64 a1, unsigned int a2, int a3)
{
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

set_offsets(a2, v5, &v4, a3);
return bit_is_set(*(_BYTE *)(a1 + v5[0]), v4);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, int a3)
{
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

func1(a2, v5, &v4, a3);
return func0(*(_BYTE *)(a1 + v5[0]), v4);
}

original_code:
_Bool bitmap_bit_is_set(char *buf, uint bit, uint len)
{
 uint byte_offset, bit_offset;
 set_offsets(bit, &byte_offset, &bit_offset, len);
 buf += byte_offset;
 return bit_is_set(*buf, bit_offset);
}

canonical_original_code:
_Bool bitmap_bit_is_set(char *buf, unsigned int bit, unsigned int len)
{
 unsigned int byte_offset; unsigned int bit_offset;
 set_offsets(bit, &byte_offset, &bit_offset, len);
 buf += byte_offset;
 return bit_is_set(*buf, bit_offset);
}


decompiled_code:
__int64 __fastcall bitmap_bit_is_clear(__int64 a1, unsigned int a2, int a3)
{
return (unsigned int)bitmap_bit_is_set(a1, a2, a3) ^ 1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2, int a3)
{
return (unsigned int)func6(a1, a2, a3) ^ 1;
}

original_code:
_Bool bitmap_bit_is_clear(char *buf, uint bit, uint len)
{
 return !bitmap_bit_is_set(buf, bit, len);
}

canonical_original_code:
_Bool bitmap_bit_is_clear(char *buf, unsigned int bit, unsigned int len)
{
 return !bitmap_bit_is_set(buf, bit, len);
}


decompiled_code:
char *__fastcall memcpy_forward(char *a1, char *a2, unsigned __int64 a3)
{
char *v4; // rcx
char *v5; // rdx

if ( a1 + 8 > a2 && &a2[a3] > a1 )
{
v4 = a1;
v5 = a2;
a2 = "memcpy_forward";
a1 = "%s: badly-overlapped regions, src=0x%lx, dst=0x%lx, len=0x%lx";
panic("%s: badly-overlapped regions, src=0x%lx, dst=0x%lx, len=0x%lx", "memcpy_forward", v5, v4, a3);
}
return _memcpy_forward(a1, a2, a3);
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, char *a2, unsigned __int64 a3)
{
char *v4; // rcx
char *v5; // rdx

if ( a1 + 8 > a2 && &a2[a3] > a1 )
{
v4 = a1;
v5 = a2;
a2 = "memcpy_forward";
a1 = "%s: badly-overlapped regions, src=0x%lx, dst=0x%lx, len=0x%lx";
panic("%s: badly-overlapped regions, src=0x%lx, dst=0x%lx, len=0x%lx", "memcpy_forward", v5, v4, a3);
}
return func0(a1, a2, a3);
}

original_code:
void *memcpy_forward(void *dst, const void *src, size_t len)
{
 uintptr_t udst, usrc;
 _Bool bad_overlap;
 udst = (uintptr_t)dst;
 usrc = (uintptr_t)src;
 bad_overlap = (udst + 8 > usrc) && (usrc + len > udst);
 if (__builtin_expect((bad_overlap), 0))
  panic("%s: badly-overlapped regions, src=0x%lx, dst"
        "=0x%lx, len=0x%lx", __func__, src, dst, len);
 return __memcpy_forward(dst, src, len);
}

canonical_original_code:
void *memcpy_forward(void *dst, void *src, unsigned long len)
{
 unsigned long udst; unsigned long usrc;
 _Bool bad_overlap;
 udst = (unsigned long)dst;
 usrc = (unsigned long)src;
 bad_overlap = (udst + 8 > usrc) && (usrc + len > udst);
 if (__builtin_expect((bad_overlap), 0))
  panic("%s: badly-overlapped regions, src=0x%lx, dst"
        "=0x%lx, len=0x%lx", __func__, src, dst, len);
 return __memcpy_forward(dst, src, len);
}

variable_types:
dst
void *

variable_types:
src
void *

variable_types:
len
unsigned long

variable_types:
udst
unsigned long

variable_types:
usrc
unsigned long

return_type: void *


memcpy

decompiled_code:
char *__fastcall memcpy(char *a1, char *a2, unsigned __int64 a3)
{
char *v4; // rcx
char *v5; // rdx

if ( &a1[a3] > a2 && &a2[a3] > a1 )
{
v4 = a1;
v5 = a2;
a2 = "memcpy";
a1 = "%s: overlapped regions, src=0x%lx, dst=0x%lx, len=0x%lx";
panic("%s: overlapped regions, src=0x%lx, dst=0x%lx, len=0x%lx", "memcpy", v5, v4, a3);
}
return _memcpy_forward(a1, a2, a3);
}

canonical_decompiled_code:
char *__fastcall func2(char *a1, char *a2, unsigned __int64 a3)
{
char *v4; // rcx
char *v5; // rdx

if ( &a1[a3] > a2 && &a2[a3] > a1 )
{
v4 = a1;
v5 = a2;
a2 = "memcpy";
a1 = "%s: overlapped regions, src=0x%lx, dst=0x%lx, len=0x%lx";
panic("%s: overlapped regions, src=0x%lx, dst=0x%lx, len=0x%lx", "memcpy", v5, v4, a3);
}
return func0(a1, a2, a3);
}

original_code:
void *memcpy(void * restrict dst, const void * restrict src, size_t len)
{
 uintptr_t udst, usrc;
 _Bool overlap;
 udst = (uintptr_t)dst;
 usrc = (uintptr_t)src;
 overlap = (udst + len > usrc) && (usrc + len > udst);
 if (__builtin_expect((overlap), 0))
  panic("%s: overlapped regions, src=0x%lx, dst=0x"
        "%lx, len=0x%lx", __func__, src, dst, len);
 return __memcpy_forward(dst, src, len);
}

canonical_original_code:
void *memcpy(void *dst, void *src, unsigned long len)
{
 unsigned long udst; unsigned long usrc;
 _Bool overlap;
 udst = (unsigned long)dst;
 usrc = (unsigned long)src;
 overlap = (udst + len > usrc) && (usrc + len > udst);
 if (__builtin_expect((overlap), 0))
  panic("%s: overlapped regions, src=0x%lx, dst=0x"
        "%lx, len=0x%lx", __func__, src, dst, len);
 return __memcpy_forward(dst, src, len);
}


decompiled_code:
// attributes: thunk
char *__fastcall memcpy_forward_nocheck(char *a1, char *a2, unsigned __int64 a3)
{
return _memcpy_forward(a1, a2, a3);
}

canonical_decompiled_code:
char *__fastcall func3(char *a1, char *a2, unsigned __int64 a3)
{
return func0(a1, a2, a3);
}

original_code:
void *memcpy_forward_nocheck(void *dst, const void *src, size_t len)
{
 return __memcpy_forward(dst, src, len);
}

canonical_original_code:
void *memcpy_forward_nocheck(void *dst, void *src, unsigned long len)
{
 return __memcpy_forward(dst, src, len);
}


decompiled_code:
// attributes: thunk
char *__fastcall memcpy_nocheck(char *a1, char *a2, unsigned __int64 a3)
{
return _memcpy_forward(a1, a2, a3);
}

canonical_decompiled_code:
char *__fastcall func4(char *a1, char *a2, unsigned __int64 a3)
{
return func0(a1, a2, a3);
}

original_code:
void *memcpy_nocheck(void * restrict dst, const void * restrict src, size_t len)
{
 return __memcpy_forward(dst, src, len);
}

canonical_original_code:
void *memcpy_nocheck(void *dst, void *src, unsigned long len)
{
 return __memcpy_forward(dst, src, len);
}


memset

decompiled_code:
char *__fastcall memset(char *a1, unsigned __int8 a2, unsigned __int64 a3)
{
__int64 v3; // rax
unsigned __int64 v4; // rsi

v3 = 0x101010101010101LL * a2;
v4 = a3 & 7;
memset(a1, v3, v4);
memset64(&a1[v4], v3, a3 >> 3);
return a1;
}

canonical_decompiled_code:
char *__fastcall func5(char *a1, unsigned __int8 a2, unsigned __int64 a3)
{
__int64 v3; // rax
unsigned __int64 v4; // rsi

v3 = 0x101010101010101LL * a2;
v4 = a3 & 7;
func5(a1, v3, v4);
func7(&a1[v4], v3, a3 >> 3);
return a1;
}

original_code:
void *memset(void *dst, uint8_t ch, size_t len)
{
 uint64_t uch;
 uintptr_t d0;
 uch = ch;
 asm volatile (
  "mov  %3, %%rcx;"
  "rep  stosb;"
  "mov  %4, %%rcx;"
  "rep  stosq;"
  :"=&D" (d0)
  :"0" (dst), "a" (uch * 0x0101010101010101),
   "ir" (len & 7), "ir" (len >> 3)
  :"rcx", "memory");
 return dst;
}

canonical_original_code:
void *memset(void *dst, unsigned char ch, unsigned long len)
{
 unsigned long uch;
 unsigned long d0;
 uch = ch;
 asm volatile (
  "mov  %3, %%rcx;"
  "rep  stosb;"
  "mov  %4, %%rcx;"
  "rep  stosq;"
  :"=&D" (d0)
  :"0" (dst), "a" (uch * 0x0101010101010101),
   "ir" (len & 7), "ir" (len >> 3)
  :"rcx", "memory");
 return dst;
}

variable_types:
ch
unsigned char

variable_types:
uch
unsigned long


decompiled_code:
__int64 __fastcall memset32(void *a1, __int64 a2, unsigned __int64 a3)
{
__int64 result; // rax

if ( (a3 & 7) != 0 )
{
panic("%s:%d - !((len % 8) == 0)\n", "lib/string.c", 152LL);
result = memset64();
}
else
{
memset64(a1, (a2 << 32) + (unsigned int)a2, a3 >> 3);
result = (__int64)a1;
}
return result;
}

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

if ( (a3 & 7) != 0 )
{
panic("%s:%d - !((len % 8) == 0)\n", "lib/string.c", 152LL);
result = func7();
}
else
{
func7(a1, (a2 << 32) + (unsigned int)a2, a3 >> 3);
result = (__int64)a1;
}
return result;
}

original_code:
void *memset32(void *dst, uint32_t val, uint64_t len)
{
 uint64_t uval;
 uintptr_t d0;
 do { if (__builtin_expect((!((len % 8) == 0)), 0)) panic("%s:%d - !(" "(len % 8) == 0" ")\n", "lib/string.c", 152); } while (0);;
 len = len / 8;
 uval = ((uint64_t)val << 32) + val;
 asm volatile (
  "rep stosq"
  :"=&D" (d0), "+&c" (len)
  :"0" (dst), "a" (uval)
  :"memory");
 return dst;
}

canonical_original_code:
void *memset32(void *dst, unsigned int val, unsigned long len)
{
 unsigned long uval;
 unsigned long d0;
 do { if (__builtin_expect((!((len % 8) == 0)), 0)) panic("%s:%d - !(" "(len % 8) == 0" ")\n", "lib/string.c", 152); } while (0);;
 len = len / 8;
 uval = ((unsigned long)val << 32) + val;
 asm volatile (
  "rep stosq"
  :"=&D" (d0), "+&c" (len)
  :"0" (dst), "a" (uval)
  :"memory");
 return dst;
}

variable_types:
val
unsigned int

variable_types:
uval
unsigned long


decompiled_code:
__int64 __fastcall memset64(void *a1, unsigned __int64 a2, unsigned __int64 a3)
{
__int64 result; // rax

if ( (a3 & 7) != 0 )
{
panic("%s:%d - !((len % 8) == 0)\n", "lib/string.c", 173LL);
result = strlen();
}
else
{
memset64(a1, a2, a3 >> 3);
result = (__int64)a1;
}
return result;
}

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

if ( (a3 & 7) != 0 )
{
panic("%s:%d - !((len % 8) == 0)\n", "lib/string.c", 173LL);
result = func8();
}
else
{
func7(a1, a2, a3 >> 3);
result = (__int64)a1;
}
return result;
}

original_code:
void *memset64(void *dst, uint64_t val, uint64_t len)
{
 uintptr_t d0;
 do { if (__builtin_expect((!((len % 8) == 0)), 0)) panic("%s:%d - !(" "(len % 8) == 0" ")\n", "lib/string.c", 173); } while (0);;
 len = len / 8;
 asm volatile (
  "rep stosq"
  :"=&D" (d0), "+&c" (len)
  :"0" (dst), "a" (val)
  :"memory");
 return dst;
}

canonical_original_code:
void *memset64(void *dst, unsigned long val, unsigned long len)
{
 unsigned long d0;
 do { if (__builtin_expect((!((len % 8) == 0)), 0)) panic("%s:%d - !(" "(len % 8) == 0" ")\n", "lib/string.c", 173); } while (0);;
 len = len / 8;
 asm volatile (
  "rep stosq"
  :"=&D" (d0), "+&c" (len)
  :"0" (dst), "a" (val)
  :"memory");
 return dst;
}

variable_types:
val
unsigned long


strncmp

decompiled_code:
__int64 __fastcall strncmp(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax
unsigned __int8 v5; // di

if ( !a3 )
return 0;
v4 = 0LL;
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v4) - *(_BYTE *)(a2 + v4);
if ( v5 || !*(_BYTE *)(a1 + v4) )
break;
if ( ++v4 == a3 )
return 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax
unsigned __int8 v5; // di

if ( !a3 )
return 0;
v4 = 0LL;
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v4) - *(_BYTE *)(a2 + v4);
if ( v5 || !*(_BYTE *)(a1 + v4) )
break;
if ( ++v4 == a3 )
return 0;
}
return v5;
}

original_code:
int strncmp(const char *c1, const char *c2, int n)
{
 uint8_t s1, s2, res;
 res = 0;
 while (n) {
  s1 = *c1++;
  s2 = *c2++;
  res = s1 - s2;
  if (res != 0 || s1 == 0)
   break;
  n--;
 }
 return res;
}

canonical_original_code:
int strncmp(char *c1, char *c2, int n)
{
 unsigned char s1; unsigned char s2; unsigned char res;
 res = 0;
 while (n) {
  s1 = *c1++;
  s2 = *c2++;
  res = s1 - s2;
  if (res != 0 || s1 == 0)
   break;
  n--;
 }
 return res;
}

variable_types: n int

variable_types:
res
unsigned char


memcmp

decompiled_code:
__int64 __fastcall memcmp(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rcx
__int64 i; // rax
unsigned __int8 v5; // dl

v3 = a3;
for ( i = 0LL; i != v3; ++i )
{
v5 = *(_BYTE *)(a1 + i) - *(_BYTE *)(a2 + i);
if ( v5 )
return v5;
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rcx
__int64 i; // rax
unsigned __int8 v5; // dl

v3 = a3;
for ( i = 0LL; i != v3; ++i )
{
v5 = *(_BYTE *)(a1 + i) - *(_BYTE *)(a2 + i);
if ( v5 )
return v5;
}
return 0;
}

original_code:
int memcmp(const void *s1, const void *s2, uint32_t n)
{
 const uint8_t *v1, *v2;
 uint8_t res;
 v1 = s1;
 v2 = s2;
 res = 0;
 while (n--) {
  res = *v1++ - *v2++;
  if (res != 0)
   break;
 }
 return res;
}

canonical_original_code:
int memcmp(void *s1, void *s2, unsigned int n)
{
 unsigned char *v1; unsigned char *v2;
 unsigned char res;
 v1 = s1;
 v2 = s2;
 res = 0;
 while (n--) {
  res = *v1++ - *v2++;
  if (res != 0)
   break;
 }
 return res;
}

variable_types:
n
unsigned int


decompiled_code:
void local_irq_enable()
{
_enable();
}

canonical_decompiled_code:
void func2()
{
_enable();
}

original_code:
static inline void local_irq_enable(void)
{
 asm volatile ("sti"
        ::
        :"cc", "memory");
}

canonical_original_code:
static inline void local_irq_enable()
{
 asm volatile ("sti"
        ::
        :"cc", "memory");
}


decompiled_code:
void *clear_bss()
{
return memset(&_bss_start, 0, &_bss_end - &_bss_start);
}

canonical_decompiled_code:
void *func3()
{
return memset(&_bss_start, 0, &_bss_end - &_bss_start);
}

original_code:
static void clear_bss(void)
{
 memset(__bss_start , 0, __bss_end - __bss_start);
}

canonical_original_code:
static void clear_bss()
{
 memset(__bss_start , 0, __bss_end - __bss_start);
}


decompiled_code:
__int64 __fastcall set_intr_gate(unsigned int a1, unsigned __int64 a2)
{
_QWORD v3[3]; // [rsp+0h] [rbp-18h] BYREF

pack_idt_gate((__int64)v3, 14, a2);
return write_idt_gate(v3, (__int64)&idt, a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, unsigned __int64 a2)
{
_QWORD v3[3]; // [rsp+0h] [rbp-18h] BYREF

func0((__int64)v3, 14, a2);
return func4(v3, (__int64)&idt, a1);
}

original_code:
static inline void set_intr_gate(unsigned int n, void *addr)
{
 struct idt_gate gate;
 pack_idt_gate(&gate, 0xe, addr);
 write_idt_gate(&gate, idt, n);
}

variable_types:
addr
void *

variable_types: struct idt_gate { unsigned short offset_low; unsigned short selector; unsigned short ist; unsigned short offset_middle; unsigned int offset_high; unsigned int reserved0_2; }


decompiled_code:
void setup_idt()
{
char *v0; // rbp
unsigned int i; // ebx

v0 = (char *)&idt_exception_stubs;
for ( i = 0; i != 32; ++i )
{
set_intr_gate(i, (unsigned __int64)v0);
v0 += 12;
}
set_intr_gate(0xF1u, (unsigned __int64)&halt_cpu_ipi_handler);
load_idt(&idtdesc);
}

canonical_decompiled_code:
void func6()
{
char *v0; // rbp
unsigned int i; // ebx

v0 = (char *)&idt_exception_stubs;
for ( i = 0; i != 32; ++i )
{
func5(i, (unsigned __int64)v0);
v0 += 12;
}
func5(0xF1u, (unsigned __int64)&halt_cpu_ipi_handler);
func1(&idtdesc);
}

original_code:
static void setup_idt(void)
{
 for (int i = 0; i < (0x1F + 1); i ++)
  set_intr_gate(i, &idt_exception_stubs[i]);
 set_intr_gate(0xf1, halt_cpu_ipi_handler);
 load_idt(&idtdesc);
}

canonical_original_code:
static void setup_idt()
{
 for (int i = 0; i < (0x1F + 1); i ++)
  set_intr_gate(i, &idt_exception_stubs[i]);
 set_intr_gate(0xf1, halt_cpu_ipi_handler);
 load_idt(&idtdesc);
}

variable_types: i int


decompiled_code:
__int64 print_info()
{
printk("Cute 0.0\n\n");
printk("Text start = 0x%lx\n", &_text_start);
printk("Text end = 0x%lx\n", &_text_end);
printk("Text size = %d bytes\n\n", &_text_end - &_text_start);
printk("Data start = 0x%lx\n", &_data_start);
printk("Data end = 0x%lx\n", &_data_end);
printk("Data size = %d bytes\n\n", &_data_end - &_data_start);
printk("BSS start = 0x%lx\n", &_bss_start);
printk("BSS end = 0x%lx\n", &_bss_end);
return printk("BSS size = %d bytes\n\n", &_bss_end - &_bss_start);
}

canonical_decompiled_code:
__int64 func7()
{
printk("Cute 0.0\n\n");
printk("Text start = 0x%lx\n", &_text_start);
printk("Text end = 0x%lx\n", &_text_end);
printk("Text size = %d bytes\n\n", &_text_end - &_text_start);
printk("Data start = 0x%lx\n", &_data_start);
printk("Data end = 0x%lx\n", &_data_end);
printk("Data size = %d bytes\n\n", &_data_end - &_data_start);
printk("BSS start = 0x%lx\n", &_bss_start);
printk("BSS end = 0x%lx\n", &_bss_end);
return printk("BSS size = %d bytes\n\n", &_bss_end - &_bss_start);
}

original_code:
static void print_info(void)
{
 printk("Cute 0.0\n\n");
 printk("Text start = 0x%lx\n", __text_start);
 printk("Text end   = 0x%lx\n", __text_end);
 printk("Text size  = %d bytes\n\n", __text_end - __text_start);
 printk("Data start = 0x%lx\n", __data_start);
 printk("Data end   = 0x%lx\n", __data_end);
 printk("Data size  = %d bytes\n\n", __data_end - __data_start);
 printk("BSS start  = 0x%lx\n", __bss_start);
 printk("BSS end    = 0x%lx\n", __bss_end);
 printk("BSS size   = %d bytes\n\n", __bss_end - __bss_start);
}

canonical_original_code:
static void print_info()
{
 printk("Cute 0.0\n\n");
 printk("Text start = 0x%lx\n", __text_start);
 printk("Text end   = 0x%lx\n", __text_end);
 printk("Text size  = %d bytes\n\n", __text_end - __text_start);
 printk("Data start = 0x%lx\n", __data_start);
 printk("Data end   = 0x%lx\n", __data_end);
 printk("Data size  = %d bytes\n\n", __data_end - __data_start);
 printk("BSS start  = 0x%lx\n", __bss_start);
 printk("BSS end    = 0x%lx\n", __bss_end);
 printk("BSS size   = %d bytes\n\n", __bss_end - __bss_start);
}


decompiled_code:
void __noreturn kernel_start()
{
clear_bss();
setup_idt();
schedulify_this_code_path(0LL);
print_info();
ramdisk_init();
e820_init();
pagealloc_init();
vm_init();
kmalloc_init();
mptables_init();
serial_init();
pic_init();
apic_init();
ioapic_init();
smpboot_init();
keyboard_init();
sched_init();
local_irq_enable();
ext2_init();
smpboot_trigger_secondary_cores_testcases();
__halt();
}

canonical_decompiled_code:
void __noreturn func8()
{
func3();
func6();
schedulify_this_code_path(0LL);
func7();
ramdisk_init();
e820_init();
pagealloc_init();
vm_init();
kmalloc_init();
mptables_init();
serial_init();
pic_init();
apic_init();
ioapic_init();
smpboot_init();
keyboard_init();
sched_init();
func2();
ext2_init();
smpboot_trigger_secondary_cores_testcases();
__halt();
}

original_code:
void __attribute__((noreturn)) kernel_start(void)
{
 clear_bss();
 setup_idt();
 schedulify_this_code_path(BOOTSTRAP);
 print_info();
 ramdisk_init();
 e820_init();
 pagealloc_init();
 vm_init();
 kmalloc_init();
 mptables_init();
 serial_init();
 pic_init();
 apic_init();
 ioapic_init();
 smpboot_init();
 keyboard_init();
 sched_init();
 local_irq_enable();
 ext2_init();
 smpboot_trigger_secondary_cores_testcases();
 run_test_cases();
 do { while (((_Bool)1)) asm volatile ("hlt":::"memory"); } while (0);;
}

canonical_original_code:
void kernel_start()
{
 clear_bss();
 setup_idt();
 schedulify_this_code_path(BOOTSTRAP);
 print_info();
 ramdisk_init();
 e820_init();
 pagealloc_init();
 vm_init();
 kmalloc_init();
 mptables_init();
 serial_init();
 pic_init();
 apic_init();
 ioapic_init();
 smpboot_init();
 keyboard_init();
 sched_init();
 local_irq_enable();
 ext2_init();
 smpboot_trigger_secondary_cores_testcases();
 run_test_cases();
 do { while (((_Bool)1)) asm volatile ("hlt":::"memory"); } while (0);;
}


decompiled_code:
void null_printer()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void null_printer(__attribute__((__unused__)) const char *fmt, ...)
{
}

canonical_original_code:
void null_printer(char *fmt, ...)
{
}

variable_types:
fmt
char *


original_code:
void buf_hex_dump(struct buffer_dumper *dumper, void *given_buf, uint len)
{
 unsigned int bytes_perline = 16, n = 0;
 uint8_t *buf = given_buf;
 for (uint i = 0; i < len; i++) {
  dumper->pr(" ");
  if (buf[i] < 0x10)
   dumper->pr("0");
  dumper->pr("%x", buf[i]);
  n++;
  if (n == bytes_perline || i == len - 1) {
   dumper->pr("\n");
   n = 0;
  }
 }
}

canonical_original_code:
void buf_hex_dump(struct buffer_dumper *dumper, void *given_buf, unsigned int len)
{
 unsigned int bytes_perline = 16; unsigned int n = 0;
 unsigned char *buf = given_buf;
 for (unsigned int i = 0; i < len; i++) {
  dumper->pr(" ");
  if (buf[i] < 0x10)
   dumper->pr("0");
  dumper->pr("%x", buf[i]);
  n++;
  if (n == bytes_perline || i == len - 1) {
   dumper->pr("\n");
   n = 0;
  }
 }
}

variable_types: struct buffer_dumper { void (*pr)(char *fmt, ...); void (*formatter)(struct buffer_dumper *dumper, void *buf, unsigned int len); } *

variable_types:
len
unsigned int

variable_types:
buf
unsigned char *

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall buf_char_dump(__int64 (__fastcall **a1)(void *, _QWORD), char *a2, int a3)
{
char *v3; // rbx
char *v4; // rbp
__int64 result; // rax

if ( a3 )
{
v3 = a2;
v4 = &a2[a3];
do
result = (*a1)(&unk_11B, (unsigned int)*v3++);
while ( v3 != v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 (__fastcall **a1)(void *, _QWORD), char *a2, int a3)
{
char *v3; // rbx
char *v4; // rbp
__int64 result; // rax

if ( a3 )
{
v3 = a2;
v4 = &a2[a3];
do
result = (*a1)(&unk_11B, (unsigned int)*v3++);
while ( v3 != v4 );
}
return result;
}

original_code:
void buf_char_dump(struct buffer_dumper *dumper, void *given_buf, uint len)
{
 char *buf = given_buf;
 for (uint i = 0; i < len; i++)
  dumper->pr("%c", buf[i]);
}

canonical_original_code:
void buf_char_dump(struct buffer_dumper *dumper, void *given_buf, unsigned int len)
{
 char *buf = given_buf;
 for (unsigned int i = 0; i < len; i++)
  dumper->pr("%c", buf[i]);
}

variable_types:
buf
char *

user_defined_types: struct buffer_dumper { void (*pr)(char *fmt, ...); void (*formatter)(struct buffer_dumper *dumper, void *buf, unsigned int len); }


decompiled_code:
void buf_null_dump()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void buf_null_dump(__attribute__((__unused__)) struct buffer_dumper *dumper,
     __attribute__((__unused__)) void __attribute__((__unused__)) *given_buf, __attribute__((__unused__)) uint len)
{
}

canonical_original_code:
void buf_null_dump(struct buffer_dumper *dumper, void *given_buf, unsigned int len)
{
}


printbuf

decompiled_code:
__int64 __fastcall printbuf(__int64 a1)
{
if ( !a1 )
{
panic("%s:%d - !(dumper != NULL)\n", "lib/buffer_dumper.c", 80LL);
JUMPOUT(0x110LL);
}
return (*(__int64 (**)(void))(a1 + 8))();
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
if ( !a1 )
{
panic("%s:%d - !(dumper != NULL)\n", "lib/buffer_dumper.c", 80LL);
JUMPOUT(0x110LL);
}
return (*(__int64 (**)(void))(a1 + 8))();
}

original_code:
void printbuf(struct buffer_dumper* dumper, void *buf, uint len)
{
 do { if (__builtin_expect((!(dumper != ((void *)0))), 0)) panic("%s:%d - !(" "dumper != NULL" ")\n", "lib/buffer_dumper.c", 80); } while (0);;
 dumper->formatter(dumper, buf, len);
}

canonical_original_code:
void printbuf(struct buffer_dumper *dumper, void *buf, unsigned int len)
{
 do { if (__builtin_expect((!(dumper != ((void *)0))), 0)) panic("%s:%d - !(" "dumper != NULL" ")\n", "lib/buffer_dumper.c", 80); } while (0);;
 dumper->formatter(dumper, buf, len);
}

variable_types:
buf
void *


decompiled_code:
__int64 default_rflags()
{
return 514LL;
}

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

original_code:
static inline union x86_rflags default_rflags(void)
{
 union x86_rflags flags;
 flags.raw = 0;
 flags.__reserved1_0 = 1;
 flags.irqs_enabled = 1;
 return flags;
}

canonical_original_code:
static inline union x86_rflags default_rflags()
{
 union x86_rflags flags;
 flags.raw = 0;
 flags.__reserved1_0 = 1;
 flags.irqs_enabled = 1;
 return flags;
}

variable_types: union x86_rflags { unsigned long raw; struct { unsigned int carry_flag; unsigned int __reserved0_4; }; }


decompiled_code:
__int64 __fastcall pcb_init(__int64 a1)
{
return memset64(a1, 0xDEADFEEDDEADFEEDLL, 56LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return memset64(a1, 0xDEADFEEDDEADFEEDLL, 56LL);
}

original_code:
static inline void pcb_init(struct pcb *pcb)
{
 memset64(pcb, 0xdeadfeeddeadfeed, sizeof(*pcb));
}

variable_types: struct pcb { unsigned long rbp; unsigned long rbx; unsigned long r12; unsigned long r13; unsigned long r14; unsigned long r15; unsigned long rsp; } *


decompiled_code:
__int64 __fastcall irq_ctx_init(__int64 a1)
{
return memset64(a1, 0xDEADFEEDDEADFEEDLL, 112LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return memset64(a1, 0xDEADFEEDDEADFEEDLL, 112LL);
}

original_code:
static inline void irq_ctx_init(struct irq_ctx *ctx)
{
 memset64(ctx, 0xdeadfeeddeadfeed, sizeof(*ctx));
}

variable_types: struct irq_ctx { unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long rsi; unsigned long rdi; unsigned long rdx; unsigned long rcx; unsigned long rax; unsigned long rip; unsigned long cs; unsigned long rflags; unsigned long rsp; unsigned long ss; } *


decompiled_code:
__int64 kthread_alloc_pid()
{
return atomic_inc(&pids_0);
}

canonical_decompiled_code:
__int64 func5()
{
return atomic_inc(&pids_0);
}

original_code:
uint64_t kthread_alloc_pid(void)
{
 static uint64_t pids;
 return atomic_inc(&pids);
}

canonical_original_code:
unsigned long kthread_alloc_pid()
{
 static unsigned long pids;
 return atomic_inc(&pids);
}

variable_types:
pids
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall proc_init(__int64 *a1)
{
memset(a1, 0, 0x140uLL);
*a1 = kthread_alloc_pid();
pcb_init((__int64)(a1 + 1));
*((_DWORD *)a1 + 16) = 2;
list_init(a1 + 9);
a1[13] = 2LL;
return unrolled_init(a1 + 14, 32LL);
}

original_code:
static inline void proc_init(struct proc *proc)
{
 memset(proc, 0, sizeof(struct proc));
 proc->pid = kthread_alloc_pid();
 pcb_init(&proc->pcb);
 proc->state = TD_INVALID;
 list_init(&proc->pnode);
 proc->working_dir = EXT2_ROOT_INODE;
 unrolled_init(&proc->fdtable, 32);
}

variable_types: struct proc { unsigned long pid; struct pcb { unsigned long rbp; unsigned long rbx; unsigned long r12; unsigned long r13; unsigned long r14; unsigned long r15; unsigned long rsp; } pcb; int state; struct list_node { struct list_node *next; struct list_node *prev; } pnode; unsigned long runtime; unsigned long enter_runqueue_ts; unsigned long working_dir; struct unrolled_head { struct __node { void **array; unsigned int array_len; unsigned int array_nrfree; unsigned int num; struct __node *next; } *node; unsigned int array_len; } fdtable; struct { unsigned long runtime_overall; unsigned int dispatch_count; unsigned long rqwait_overall; unsigned long prio_map[-1]; unsigned int preempt_high_prio; unsigned int preempt_slice_end; } stats; } *

user_defined_types: struct proc { unsigned long pid; struct pcb pcb; int state; struct list_node pnode; unsigned long runtime; unsigned long enter_runqueue_ts; unsigned long working_dir; struct unrolled_head fdtable; struct { unsigned long runtime_overall; unsigned int dispatch_count; unsigned long rqwait_overall; unsigned long prio_map[-1]; unsigned int preempt_high_prio; unsigned int preempt_slice_end; } stats; }

user_defined_types: struct unrolled_head { struct __node *node; unsigned int array_len; }


original_code:
void kthread_create(void (* func)(void))
{
 struct proc *proc;
 struct irq_ctx *irq_ctx;
 char *stack;
 proc = kmalloc(sizeof(*proc));
 proc_init(proc);
 stack = kmalloc((1 << 12));
 stack = stack + (1 << 12);
 irq_ctx = (struct irq_ctx *)(stack - sizeof(*irq_ctx));
 irq_ctx_init(irq_ctx);
 irq_ctx->cs = 0x08;
 irq_ctx->rip = (uintptr_t)func;
 irq_ctx->ss = 0;
 irq_ctx->rsp = (uintptr_t)stack;
 irq_ctx->rflags = default_rflags().raw;
 proc->pcb.rsp = (uintptr_t)irq_ctx;
 sched_enqueue(proc);
}

canonical_original_code:
void kthread_create(void (*func)())
{
 struct proc *proc;
 struct irq_ctx *irq_ctx;
 char *stack;
 proc = kmalloc(sizeof(*proc));
 proc_init(proc);
 stack = kmalloc((1 << 12));
 stack = stack + (1 << 12);
 irq_ctx = (struct irq_ctx *)(stack - sizeof(*irq_ctx));
 irq_ctx_init(irq_ctx);
 irq_ctx->cs = 0x08;
 irq_ctx->rip = (unsigned long)func;
 irq_ctx->ss = 0;
 irq_ctx->rsp = (unsigned long)stack;
 irq_ctx->rflags = default_rflags().raw;
 proc->pcb.rsp = (unsigned long)irq_ctx;
 sched_enqueue(proc);
}

variable_types:
func
void (*)()

variable_types:
stack
char *

user_defined_types: struct irq_ctx { unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long rsi; unsigned long rdi; unsigned long rdx; unsigned long rcx; unsigned long rax; unsigned long rip; unsigned long cs; unsigned long rflags; unsigned long rsp; unsigned long ss; }

user_defined_types: struct pcb { unsigned long rbp; unsigned long rbx; unsigned long r12; unsigned long r13; unsigned long r14; unsigned long r15; unsigned long rsp; }

user_defined_types: struct list_node { struct list_node *next; struct list_node *prev; }

user_defined_types: struct __node { void **array; unsigned int array_len; unsigned int array_nrfree; unsigned int num; struct __node *next; }


decompiled_code:
__int64 __fastcall vga_scrollup(__int16 a1)
{
int *v1; // rax
__int64 result; // rax

memcpy_forward_nocheck(&vga_buffer, &unk_10A0, 3840LL);
v1 = (int *)&unk_1F00;
do
{
v1 = (int *)((char *)v1 + 2);
*((_WORD *)v1 - 1) = (a1 << 8) + 32;
}
while ( v1 != &vga_ypos );
result = memcpy_nocheck(0xFFFF8000000B8000LL, &vga_buffer, 4000LL);
vga_xpos = 0;
--vga_ypos;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1)
{
int *v1; // rax
__int64 result; // rax

memcpy_forward_nocheck(&vga_buffer, &unk_10A0, 3840LL);
v1 = (int *)&unk_1F00;
do
{
v1 = (int *)((char *)v1 + 2);
*((_WORD *)v1 - 1) = (a1 << 8) + 32;
}
while ( v1 != &vga_ypos );
result = memcpy_nocheck(0xFFFF8000000B8000LL, &vga_buffer, 4000LL);
vga_xpos = 0;
--vga_ypos;
return result;
}

original_code:
static void vga_scrollup(int color) {
 char *src, *dst;
 int rows_24;
 uint16_t *vgap;
 src = vga_buffer + 2 * 80;
 dst = vga_buffer;
 rows_24 = 2 * ((25 - 1) * 80);
 memcpy_forward_nocheck(dst, src, rows_24);
 vgap = (uint16_t *)(vga_buffer + rows_24);
 for (int i = 0; i < 80; i++)
  *vgap++ = (color << 8) + ' ';
 memcpy_nocheck(((char *)({ do { if (__builtin_expect((!((uintptr_t)(0xb8000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0xb8000) >= KERN_PHYS_OFFSET" ")\n", "lib/printf.c", 331); } while (0);; do { if (__builtin_expect((!((uintptr_t)(0xb8000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0xb8000) < KERN_PHYS_END_MAX" ")\n", "lib/printf.c", 331); } while (0);; (void *)((char *)(0xb8000) + 0xffff800000000000ULL); })), vga_buffer, (25 * 80 * 2));
 vga_xpos = 0;
 vga_ypos--;
}

canonical_original_code:
static void vga_scrollup(int color) {
 char *src; char *dst;
 int rows_24;
 unsigned short *vgap;
 src = vga_buffer + 2 * 80;
 dst = vga_buffer;
 rows_24 = 2 * ((25 - 1) * 80);
 memcpy_forward_nocheck(dst, src, rows_24);
 vgap = (unsigned short *)(vga_buffer + rows_24);
 for (int i = 0; i < 80; i++)
  *vgap++ = (color << 8) + ' ';
 memcpy_nocheck(((char *)({ do { if (__builtin_expect((!((unsigned long)(0xb8000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0xb8000) >= KERN_PHYS_OFFSET" ")\n", "lib/printf.c", 331); } while (0);; do { if (__builtin_expect((!((unsigned long)(0xb8000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0xb8000) < KERN_PHYS_END_MAX" ")\n", "lib/printf.c", 331); } while (0);; (void *)((char *)(0xb8000) + 0xffff800000000000ULL); })), vga_buffer, (25 * 80 * 2));
 vga_xpos = 0;
 vga_ypos--;
}

variable_types: color int

variable_types:
src
char *

variable_types:
dst
char *

variable_types:
vgap
unsigned short *


decompiled_code:
__int64 __fastcall putc_colored(char a1, __int16 a2)
{
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a1;
return vga_write(v3, 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, __int16 a2)
{
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a1;
return func2(v3, 1, a2);
}

original_code:
void putc_colored(char c, int color)
{
 vga_write(&c, 1, color);
}

variable_types: c char


putc

decompiled_code:
__int64 __fastcall putc(char a1)
{
return putc_colored(a1, 15);
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
return func3(a1, 15);
}

original_code:
void putc(char c)
{
 putc_colored(c, (((0x0) << 4) | (0xf)));
}


decompiled_code:
void __fastcall __noreturn printk_panic(char *a1)
{
char v2; // di
char *v3; // rbp
char i; // di

v2 = panic_prefix;
if ( panic_prefix )
{
v3 = &panic_prefix;
do
{
++v3;
putc(v2);
v2 = *v3;
}
while ( *v3 );
}
for ( i = *a1; *a1; i = *a1 )
{
++a1;
putc(i);
}
__halt();
}

canonical_decompiled_code:
void __fastcall __noreturn func5(char *a1)
{
char v2; // di
char *v3; // rbp
char i; // di

v2 = panic_prefix;
if ( panic_prefix )
{
v3 = &panic_prefix;
do
{
++v3;
func4(v2);
v2 = *v3;
}
while ( *v3 );
}
for ( i = *a1; *a1; i = *a1 )
{
++a1;
func4(i);
}
__halt();
}

original_code:
static __attribute__((noreturn)) void printk_panic(const char *str)
{
 const char *prefix;
 prefix = panic_prefix;
 while (*prefix != 0)
  putc(*prefix++);
 while (*str != 0)
  putc(*str++);
 do { while (((_Bool)1)) asm volatile ("hlt":::"memory"); } while (0);;
}

canonical_original_code:
static void printk_panic(char *str)
{
 char *prefix;
 prefix = panic_prefix;
 while (*prefix != 0)
  putc(*prefix++);
 while (*str != 0)
  putc(*str++);
 do { while (((_Bool)1)) asm volatile ("hlt":::"memory"); } while (0);;
}

variable_types:
str
char *

variable_types:
prefix
char *


ltoa

decompiled_code:
__int64 __fastcall ltoa(signed __int64 a1, _BYTE *a2, int a3, unsigned int a4)
{
if ( a4 - 3 > 0xD )
printk_panic("!(radix > 2 && radix <= PRINTK_MAX_RADIX)");
if ( a1 >= 0 )
return ultoa(a1, (__int64)a2, a3, a4);
if ( a3 <= 1 )
printk_panic("!(size >= 2)");
*a2 = 45;
return (unsigned int)ultoa(-a1, (__int64)(a2 + 1), a3 - 1, a4) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func7(signed __int64 a1, _BYTE *a2, int a3, unsigned int a4)
{
if ( a4 - 3 > 0xD )
func5("!(radix > 2 && radix <= PRINTK_MAX_RADIX)");
if ( a1 >= 0 )
return func6(a1, (__int64)a2, a3, a4);
if ( a3 <= 1 )
func5("!(size >= 2)");
*a2 = 45;
return (unsigned int)func6(-a1, (__int64)(a2 + 1), a3 - 1, a4) + 1;
}

original_code:
static int ltoa(signed long num, char *buf, int size, int radix)
{
 do { if (__builtin_expect((!(radix > 2 && radix <= 16)), 0)) printk_panic("!(" "radix > 2 && radix <= PRINTK_MAX_RADIX" ")"); } while (0);;
 if (num < 0) {
  do { if (__builtin_expect((!(size >= 2)), 0)) printk_panic("!(" "size >= 2" ")"); } while (0);;
  num *= -1;
  buf[0] = '-';
  return ultoa(num, buf+1, size-1, radix) + 1;
 }
 return ultoa(num, buf, size, radix);
}

canonical_original_code:
static int ltoa(long num, char *buf, int size, int radix)
{
 do { if (__builtin_expect((!(radix > 2 && radix <= 16)), 0)) printk_panic("!(" "radix > 2 && radix <= PRINTK_MAX_RADIX" ")"); } while (0);;
 if (num < 0) {
  do { if (__builtin_expect((!(size >= 2)), 0)) printk_panic("!(" "size >= 2" ")"); } while (0);;
  num *= -1;
  buf[0] = '-';
  return ultoa(num, buf+1, size-1, radix) + 1;
 }
 return ultoa(num, buf, size, radix);
}

variable_types: num long

variable_types: size int

variable_types: radix int


vsnprintf

decompiled_code:
__int64 __fastcall vsnprintf(char *dest, int a2, char *a3, int *a4)
{
int v4; // ebp
char *v5; // rbx
char *v7; // r12
int v8; // eax
char i; // al
__int64 v11; // [rsp+4h] [rbp-34h] BYREF
int v12; // [rsp+Ch] [rbp-2Ch]

v11 = 0LL;
v12 = 0;
if ( a2 <= 0 )
return 0LL;
v4 = a2;
v5 = a3;
v7 = dest;
if ( *a3 )
{
do
{
for ( i = *v5; i != 37 && i != 0 && v4; i = *v5 )
{
++v5;
*v7++ = i;
--v4;
}
if ( !v4 || !i )
break;
if ( i != 37 )
printk_panic("!(*fmt == '%')");
v5 = parse_arg(v5, &v11);
v8 = print_arg(v7, v4, (unsigned int *)&v11, a4);
v7 += v8;
v4 -= v8;
}
while ( *v5 );
if ( v7 < dest )
printk_panic("!(str >= buf)");
}
return (unsigned int)((_DWORD)v7 - (_DWORD)dest);
}

canonical_decompiled_code:
__int64 __fastcall func9(char *dest, int a2, char *a3, int *a4)
{
int v4; // ebp
char *v5; // rbx
char *v7; // r12
int v8; // eax
char i; // al
__int64 v11; // [rsp+4h] [rbp-34h] BYREF
int v12; // [rsp+Ch] [rbp-2Ch]

v11 = 0LL;
v12 = 0;
if ( a2 <= 0 )
return 0LL;
v4 = a2;
v5 = a3;
v7 = dest;
if ( *a3 )
{
do
{
for ( i = *v5; i != 37 && i != 0 && v4; i = *v5 )
{
++v5;
*v7++ = i;
--v4;
}
if ( !v4 || !i )
break;
if ( i != 37 )
func5("!(*fmt == '%')");
v5 = parse_arg(v5, &v11);
v8 = func8(v7, v4, (unsigned int *)&v11, a4);
v7 += v8;
v4 -= v8;
}
while ( *v5 );
if ( v7 < dest )
func5("!(str >= buf)");
}
return (unsigned int)((_DWORD)v7 - (_DWORD)dest);
}

original_code:
int vsnprintf(char *buf, int size, const char *fmt, va_list args)
{
 struct printf_argdesc desc = { 0 };
 char *str;
 int len;
 if (size < 1)
  return 0;
 str = buf;
 while (*fmt) {
  while (*fmt != 0 && *fmt != '%' && size != 0) {
   *str++ = *fmt++;
   --size;
  }
  if (*fmt == 0 || size == 0)
   break;
  do { if (__builtin_expect((!(*fmt == '%')), 0)) printk_panic("!(" "*fmt == '%'" ")"); } while (0);;
  fmt = parse_arg(fmt, &desc);
  len = print_arg(str, size, &desc, args);
  str += len;
  size -= len;
 }
 do { if (__builtin_expect((!(str >= buf)), 0)) printk_panic("!(" "str >= buf" ")"); } while (0);;
 return str - buf;
}

canonical_original_code:
int vsnprintf(char *buf, int size, char *fmt, __builtin_va_list args)
{
 struct printf_argdesc desc = { 0 };
 char *str;
 int len;
 if (size < 1)
  return 0;
 str = buf;
 while (*fmt) {
  while (*fmt != 0 && *fmt != '%' && size != 0) {
   *str++ = *fmt++;
   --size;
  }
  if (*fmt == 0 || size == 0)
   break;
  do { if (__builtin_expect((!(*fmt == '%')), 0)) printk_panic("!(" "*fmt == '%'" ")"); } while (0);;
  fmt = parse_arg(fmt, &desc);
  len = print_arg(str, size, &desc, args);
  str += len;
  size -= len;
 }
 do { if (__builtin_expect((!(str >= buf)), 0)) printk_panic("!(" "str >= buf" ")"); } while (0);;
 return str - buf;
}

variable_types:
buf
char *

variable_types:
fmt
char *

variable_types: struct printf_argdesc { int radix; enum printf_arglen { INT=0, LONG=1 } len; enum printf_argtype { NONE=0, SIGNED=1, UNSIGNED=2, STRING=3, CHAR=4, PERCENT=5 } type; }

variable_types: len int

user_defined_types: struct printf_argdesc { int radix; enum printf_arglen len; enum printf_argtype type; }


printk

decompiled_code:
__int64 printk(char *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
int v9; // eax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
spin_lock(&kbuf_lock);
v9 = vsnprintf(kbuf, 1024, a1, (int *)va);
vga_write(kbuf, v9, 15);
return spin_unlock(&kbuf_lock);
}

canonical_decompiled_code:
__int64 func10(char *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
int v9; // eax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
spin_lock(&kbuf_lock);
v9 = func9(kbuf, 1024, a1, (int *)va);
func2(kbuf, v9, 15);
return spin_unlock(&kbuf_lock);
}

original_code:
void printk(const char *fmt, ...)
{
 va_list args;
 int n;
 spin_lock(&kbuf_lock);
 __builtin_va_start(args,fmt);
 n = vsnprintf(kbuf, sizeof(kbuf), fmt, args);
 __builtin_va_end(args);
 vga_write(kbuf, n, (((0x0) << 4) | (0xf)));
 spin_unlock(&kbuf_lock);
}

canonical_original_code:
void printk(char *fmt, ...)
{
 __builtin_va_list args;
 int n;
 spin_lock(&kbuf_lock);
 __builtin_va_start(args,fmt);
 n = vsnprintf(kbuf, sizeof(kbuf), fmt, args);
 __builtin_va_end(args);
 vga_write(kbuf, n, (((0x0) << 4) | (0xf)));
 spin_unlock(&kbuf_lock);
}

variable_types: n int


prints

decompiled_code:
__int64 prints(char *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
unsigned int v9; // eax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
spin_lock(&sbuf_lock);
v9 = vsnprintf(sbuf, 1024, a1, (int *)va);
serial_write(sbuf, v9);
return spin_unlock(&sbuf_lock);
}

canonical_decompiled_code:
__int64 func11(char *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
unsigned int v9; // eax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
spin_lock(&sbuf_lock);
v9 = func9(sbuf, 1024, a1, (int *)va);
serial_write(sbuf, v9);
return spin_unlock(&sbuf_lock);
}

original_code:
void prints(const char *fmt, ...)
{
 va_list args;
 int n;
 spin_lock(&sbuf_lock);
 __builtin_va_start(args,fmt);
 n = vsnprintf(sbuf, sizeof(sbuf), fmt, args);
 __builtin_va_end(args);
 serial_write(sbuf, n);
 spin_unlock(&sbuf_lock);
}

canonical_original_code:
void prints(char *fmt, ...)
{
 __builtin_va_list args;
 int n;
 spin_lock(&sbuf_lock);
 __builtin_va_start(args,fmt);
 n = vsnprintf(sbuf, sizeof(sbuf), fmt, args);
 __builtin_va_end(args);
 serial_write(sbuf, n);
 spin_unlock(&sbuf_lock);
}


decompiled_code:
__int64 printk_bust_all_locks()
{
spin_lock(&vga_lock);
return spin_lock(&kbuf_lock);
}

canonical_decompiled_code:
__int64 func12()
{
spin_lock(&vga_lock);
return spin_lock(&kbuf_lock);
}

original_code:
void printk_bust_all_locks(void)
{
 spin_lock(&vga_lock);
 spin_lock(&kbuf_lock);
}

canonical_original_code:
void printk_bust_all_locks()
{
 spin_lock(&vga_lock);
 spin_lock(&kbuf_lock);
}


readl

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

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

original_code:
static inline uint32_t readl(const volatile void *addr) {
 return ({ uint32_t val; asm volatile ("mov %[addr], %[val];" : [val] "=r"(val) : [addr] "m"(*(const volatile uint32_t *)addr) : "memory"); val; });
}

canonical_original_code:
static inline unsigned int readl(void *addr) {
 return ({ unsigned int val; asm volatile ("mov %[addr], %[val];" : [val] "=r"(val) : [addr] "m"(*(unsigned int *)addr) : "memory"); val; });
}

variable_types:
addr
void *

variable_types:
val
unsigned int

return_type: unsigned int


decompiled_code:
unsigned __int64 __fastcall ioapic_isa_pin(int a1, int a2)
{
const char *v3; // rsi
int v5; // er10
const char *v6; // rdi
__int64 v7; // rax
int v9; // ecx
char v10; // di
int *v11; // rdx
unsigned int v12; // eax

LODWORD(v3) = mp_isa_busid;
if ( mp_isa_busid == -1 )
{
v3 = "dev/ioapic.c";
v6 = "%s:%d - !(mp_isa_busid != -1)\n";
v7 = panic("%s:%d - !(mp_isa_busid != -1)\n", "dev/ioapic.c", 71LL);
goto LABEL_5;
}
v5 = nr_mpcirqs;
v6 = (const char *)nr_mpcirqs;
v7 = 0LL;
if ( nr_mpcirqs <= 0 )
return -1LL;
while ( 1 )
{
v9 = v7;
if ( (_DWORD)v3 == *((unsigned __int8 *)&mp_irqs + 8 * v7 + 4)
&& *((unsigned __int8 *)&mp_irqs + 8 * v7 + 5) == a1
&& *((unsigned __int8 *)&mp_irqs + 8 * v7 + 1) == a2 )
{
break;
}
LABEL_5:
if ( (const char *)++v7 == v6 )
return -1LL;
}
if ( v5 <= (int)v7 )
return -1LL;
if ( nr_ioapics <= 0 )
return -1LL;
v10 = *((_BYTE *)&mp_irqs + 8 * (int)v7 + 6);
v11 = &ioapic_descs;
v12 = 0;
while ( v10 != *(_BYTE *)v11 )
{
++v12;
v11 += 3;
if ( nr_ioapics == v12 )
return -1LL;
}
return ((unsigned __int64)*((unsigned __int8 *)&mp_irqs + 8 * v9 + 7) << 32) | v12;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(int a1, int a2)
{
const char *v3; // rsi
int v5; // er10
const char *v6; // rdi
__int64 v7; // rax
int v9; // ecx
char v10; // di
int *v11; // rdx
unsigned int v12; // eax

LODWORD(v3) = mp_isa_busid;
if ( mp_isa_busid == -1 )
{
v3 = "dev/ioapic.c";
v6 = "%s:%d - !(mp_isa_busid != -1)\n";
v7 = panic("%s:%d - !(mp_isa_busid != -1)\n", "dev/ioapic.c", 71LL);
goto LABEL_5;
}
v5 = nr_mpcirqs;
v6 = (const char *)nr_mpcirqs;
v7 = 0LL;
if ( nr_mpcirqs <= 0 )
return -1LL;
while ( 1 )
{
v9 = v7;
if ( (_DWORD)v3 == *((unsigned __int8 *)&mp_irqs + 8 * v7 + 4)
&& *((unsigned __int8 *)&mp_irqs + 8 * v7 + 5) == a1
&& *((unsigned __int8 *)&mp_irqs + 8 * v7 + 1) == a2 )
{
break;
}
LABEL_5:
if ( (const char *)++v7 == v6 )
return -1LL;
}
if ( v5 <= (int)v7 )
return -1LL;
if ( nr_ioapics <= 0 )
return -1LL;
v10 = *((_BYTE *)&mp_irqs + 8 * (int)v7 + 6);
v11 = &ioapic_descs;
v12 = 0;
while ( v10 != *(_BYTE *)v11 )
{
++v12;
v11 += 3;
if ( nr_ioapics == v12 )
return -1LL;
}
return ((unsigned __int64)*((unsigned __int8 *)&mp_irqs + 8 * v9 + 7) << 32) | v12;
}

original_code:
static struct ioapic_pin ioapic_isa_pin(int isa_irq, enum mp_irqtype type)
{
 struct ioapic_pin pin = { .apic = -1, .pin = -1 };
 int irq;
 do { if (__builtin_expect((!(mp_isa_busid != -1)), 0)) panic("%s:%d - !(" "mp_isa_busid != -1" ")\n", "dev/ioapic.c", 71); } while (0);;
 for (irq = 0; irq < nr_mpcirqs; irq++) {
  if ((mp_irqs[irq].src_busid == mp_isa_busid) &&
      (mp_irqs[irq].src_busirq == isa_irq) &&
      (mp_irqs[irq].type == type))
   break;
 }
 if (irq >= nr_mpcirqs)
  return pin;
 for (int apic = 0; apic < nr_ioapics; apic++) {
  if(mp_irqs[irq].dst_ioapicid == ioapic_descs[apic].id) {
   pin.apic = apic;
   pin.pin = mp_irqs[irq].dst_ioapicpin;
   return pin;
  }
 }
 return pin;
}

variable_types: enum mp_irqtype { MP_INT=0, MP_NMI=1, MP_SMI=2, MP_ExtINT=3 }

variable_types: struct ioapic_pin { int apic; int pin; }

variable_types: irq int

variable_types: apic int


decompiled_code:
__int64 __fastcall ioapic_base(int a1)
{
if ( nr_ioapics > a1 )
return vm_kmap((unsigned int)ioapic_descs[3 * a1 + 1], 32LL);
panic("%s:%d - !(apic < nr_ioapics)\n", "include/ioapic.h", 83LL);
return ioapic_write();
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
if ( nr_ioapics > a1 )
return vm_kmap((unsigned int)ioapic_descs[3 * a1 + 1], 32LL);
panic("%s:%d - !(apic < nr_ioapics)\n", "include/ioapic.h", 83LL);
return func4();
}

original_code:
static inline uintptr_t ioapic_base(int apic)
{
 void *vbase;
 do { if (__builtin_expect((!(apic < nr_ioapics)), 0)) panic("%s:%d - !(" "apic < nr_ioapics" ")\n", "include/ioapic.h", 83); } while (0);;
 vbase = vm_kmap(ioapic_descs[apic].base, 0x20);
 return (uintptr_t)vbase;
}

canonical_original_code:
static inline unsigned long ioapic_base(int apic)
{
 void *vbase;
 do { if (__builtin_expect((!(apic < nr_ioapics)), 0)) panic("%s:%d - !(" "apic < nr_ioapics" ")\n", "include/ioapic.h", 83); } while (0);;
 vbase = vm_kmap(ioapic_descs[apic].base, 0x20);
 return (unsigned long)vbase;
}

variable_types:
vbase
void *