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

v1 = get_free_block(a1);
mark_block(v1, 1);
return v1;
}

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

v1 = func6(a1);
func3(v1, 1);
return v1;
}

original_code:
block_nr alloc_block(block_nr start)
{
        block_nr blk_nr;
        blk_nr = get_free_block(start);
        mark_block(blk_nr, 1);
        return blk_nr;
}

canonical_original_code:
unsigned int alloc_block(unsigned int start)
{
        unsigned int blk_nr;
        blk_nr = get_free_block(start);
        mark_block(blk_nr, 1);
        return blk_nr;
}

variable_types:
start
unsigned int


repo: dbader/potatoes

decompiled_code:
void test_reload()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void test_reload()
{
}

canonical_original_code:
void test_reload()
{
}

return_type: void


decompiled_code:
__int64 test_close()
{
__int64 v0; // rsi
__int16 v1; // bx
__int16 v2; // bp
_BYTE v4[184]; // [rsp+0h] [rbp-B8h] BYREF

init_proc_file_table(v4);
do_mkdir("/usr");
do_mkdir("/usr/mydir");
do_mkfile("/usr/mydir/mydoc");
v0 = (unsigned int)(__int16)do_open("/usr/mydir/mydoc");
v1 = insert_proc_file(v4, v0);
v2 = insert_proc_file(v4, v0);
dump_files();
dump_proc_files(v4);
do_close_pf(v4, (unsigned int)v2);
dump_files();
dump_proc_files(v4);
do_close_pf(v4, (unsigned int)v1);
dump_files();
return dump_proc_files(v4);
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v0; // rsi
__int16 v1; // bx
__int16 v2; // bp
_BYTE v4[184]; // [rsp+0h] [rbp-B8h] BYREF

init_proc_file_table(v4);
do_mkdir("/usr");
do_mkdir("/usr/mydir");
do_mkfile("/usr/mydir/mydoc");
v0 = (unsigned int)(__int16)do_open("/usr/mydir/mydoc");
v1 = insert_proc_file(v4, v0);
v2 = insert_proc_file(v4, v0);
dump_files();
dump_proc_files(v4);
do_close_pf(v4, (unsigned int)v2);
dump_files();
dump_proc_files(v4);
do_close_pf(v4, (unsigned int)v1);
dump_files();
return dump_proc_files(v4);
}

original_code:
void test_close()
{
        proc_file pft[20];
        init_proc_file_table(pft);
        do_mkdir("/usr");
        do_mkdir("/usr/mydir");
        do_mkfile("/usr/mydir/mydoc");
        file_nr fd = do_open("/usr/mydir/mydoc");
        file_nr pfd1 = insert_proc_file(pft, fd);
        file_nr pfd2 = insert_proc_file(pft, fd);
        dump_files();
        dump_proc_files(pft);
        do_close_pf(pft, pfd2);
        dump_files();
        dump_proc_files(pft);
        do_close_pf(pft, pfd1);
        dump_files();
        dump_proc_files(pft);
}

canonical_original_code:
void test_close()
{
        struct proc_file pft[20];
        init_proc_file_table(pft);
        do_mkdir("/usr");
        do_mkdir("/usr/mydir");
        do_mkfile("/usr/mydir/mydoc");
        short fd = do_open("/usr/mydir/mydoc");
        short pfd1 = insert_proc_file(pft, fd);
        short pfd2 = insert_proc_file(pft, fd);
        dump_files();
        dump_proc_files(pft);
        do_close_pf(pft, pfd2);
        dump_files();
        dump_proc_files(pft);
        do_close_pf(pft, pfd1);
        dump_files();
        dump_proc_files(pft);
}

variable_types: struct proc_file { short pf_desc; short pf_f_desc; unsigned int pf_pos; } [20]

variable_types: fd short


decompiled_code:
__int64 test_sync()
{
fs_shutdown();
dump_bmap();
dump_inode(root);
load_fs();
dump_bmap();
return dump_inode(root);
}

canonical_decompiled_code:
__int64 func12()
{
fs_shutdown();
dump_bmap();
dump_inode(root);
load_fs();
dump_bmap();
return dump_inode(root);
}

original_code:
void test_sync()
{
        fs_shutdown();
        dump_bmap();
        dump_inode(root);
        load_fs();
        dump_bmap();
        dump_inode(root);
}


decompiled_code:
__int64 run_FS_tests()
{
return test_open_close();
}

canonical_decompiled_code:
__int64 func15()
{
return func14();
}

original_code:
void run_FS_tests()
{
        test_open_close();
}


decompiled_code:
__int16 *init_inode_table()
{
__int16 *result; // rax

result = &inode_table;
do
{
result += 80;
*(result - 80) = -1;
}
while ( result != &inode_table + 800 );
return result;
}

canonical_decompiled_code:
__int16 *func0()
{
__int16 *result; // rax

result = &inode_table;
do
{
result += 80;
*(result - 80) = -1;
}
while ( result != &inode_table + 800 );
return result;
}

original_code:
void init_inode_table()
{
        ((void)0);
        for (int i = 0; i < 10; i++) {
                inode_table[i].i_num = -1;
        }
}

variable_types: i int


decompiled_code:
__int64 __fastcall read_dinode(__int64 a1, __int64 a2)
{
return rd_block(a1, a2, 150LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return rd_block(a1, a2, 150LL);
}

original_code:
void read_dinode(d_inode *inode, block_nr inode_blk)
{
        rd_block(inode, inode_blk, sizeof(d_inode));
}

canonical_original_code:
void read_dinode(struct d_inode *inode, unsigned int inode_blk)
{
        rd_block(inode, inode_blk, sizeof(d_inode));
}

variable_types: struct d_inode { unsigned short i_mode; unsigned int i_size; struct time { unsigned char sec; unsigned char min; unsigned char hour; unsigned char weekday; unsigned char day; unsigned char month; unsigned char year; unsigned char century; } i_create_ts; struct time i_modify_ts; unsigned int i_direct_pointer[30]; unsigned int i_single_indirect_pointer; unsigned int i_double_indirect_pointer; } *

user_defined_types: struct d_inode { unsigned short i_mode; unsigned int i_size; struct time i_create_ts; struct time i_modify_ts; unsigned int i_direct_pointer[30]; unsigned int i_single_indirect_pointer; unsigned int i_double_indirect_pointer; }


original_code:
void cpy_minode_to_dinode(d_inode *di, m_inode *mi)
{
        di->i_mode = mi->i_mode;
        di->i_size = mi->i_size;
        di->i_create_ts = mi->i_create_ts;
        di->i_modify_ts = mi->i_modify_ts;
        for (int i = 0; i < 30; i++) {
                di->i_direct_pointer[i] = mi->i_direct_pointer[i];
        }
        di->i_single_indirect_pointer = mi->i_single_indirect_pointer;
        di->i_double_indirect_pointer = mi->i_double_indirect_pointer;
}

canonical_original_code:
void cpy_minode_to_dinode(struct d_inode *di, struct m_inode *mi)
{
        di->i_mode = mi->i_mode;
        di->i_size = mi->i_size;
        di->i_create_ts = mi->i_create_ts;
        di->i_modify_ts = mi->i_modify_ts;
        for (int i = 0; i < 30; i++) {
                di->i_direct_pointer[i] = mi->i_direct_pointer[i];
        }
        di->i_single_indirect_pointer = mi->i_single_indirect_pointer;
        di->i_double_indirect_pointer = mi->i_double_indirect_pointer;
}

variable_types: struct m_inode { short i_num; unsigned int i_adr; unsigned short i_mode; unsigned int i_size; struct time i_create_ts; struct time i_modify_ts; unsigned int i_direct_pointer[30]; unsigned int i_single_indirect_pointer; unsigned int i_double_indirect_pointer; } *

user_defined_types: struct time { unsigned char sec; unsigned char min; unsigned char hour; unsigned char weekday; unsigned char day; unsigned char month; unsigned char year; unsigned char century; }


decompiled_code:
__int64 __fastcall write_inode(__int64 a1)
{
__int64 v1; // rcx

cpy_minode_to_dinode((__int64)&d_inode_cache, a1);
return wrt_block(*(unsigned int *)(v1 + 4), &d_inode_cache, 150LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rcx

func2((__int64)&d_inode_cache, a1);
return wrt_block(*(unsigned int *)(v1 + 4), &d_inode_cache, 150LL);
}

original_code:
void write_inode(m_inode *inode)
{
        cpy_minode_to_dinode(&d_inode_cache, inode);
        wrt_block(inode->i_adr, &d_inode_cache, sizeof(d_inode));
}

canonical_original_code:
void write_inode(struct m_inode *inode)
{
        cpy_minode_to_dinode(&d_inode_cache, inode);
        wrt_block(inode->i_adr, &d_inode_cache, sizeof(d_inode));
}

variable_types: struct m_inode { short i_num; unsigned int i_adr; unsigned short i_mode; unsigned int i_size; struct time { unsigned char sec; unsigned char min; unsigned char hour; unsigned char weekday; unsigned char day; unsigned char month; unsigned char year; unsigned char century; } i_create_ts; struct time i_modify_ts; unsigned int i_direct_pointer[30]; unsigned int i_single_indirect_pointer; unsigned int i_double_indirect_pointer; } *

user_defined_types: struct m_inode { short i_num; unsigned int i_adr; unsigned short i_mode; unsigned int i_size; struct time i_create_ts; struct time i_modify_ts; unsigned int i_direct_pointer[30]; unsigned int i_single_indirect_pointer; unsigned int i_double_indirect_pointer; }


decompiled_code:
__int64 write_inodes()
{
__int16 *v0; // rbx
__int64 v1; // rdi
__int64 result; // rax

v0 = inode_table;
do
{
v1 = (__int64)v0;
v0 += 80;
result = write_inode(v1);
}
while ( v0 != &inode_table[800] );
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int16 *v0; // rbx
__int64 v1; // rdi
__int64 result; // rax

v0 = inode_table;
do
{
v1 = (__int64)v0;
v0 += 80;
result = func3(v1);
}
while ( v0 != &inode_table[800] );
return result;
}

original_code:
void write_inodes()
{
        for (int i = 0; i < 10; i++) {
                write_inode(&inode_table[i]);
        }
}


original_code:
void cpy_dinode_to_minode(m_inode *mi, d_inode *di)
{
        mi->i_mode = di->i_mode;
        mi->i_size = di->i_size;
        mi->i_create_ts = di->i_create_ts;
        mi->i_modify_ts = di->i_modify_ts;
        for (int i = 0; i < 30; i++) {
                mi->i_direct_pointer[i] = di->i_direct_pointer[i];
        }
        mi->i_single_indirect_pointer = di->i_single_indirect_pointer;
        mi->i_double_indirect_pointer = di->i_double_indirect_pointer;
}

canonical_original_code:
void cpy_dinode_to_minode(struct m_inode *mi, struct d_inode *di)
{
        mi->i_mode = di->i_mode;
        mi->i_size = di->i_size;
        mi->i_create_ts = di->i_create_ts;
        mi->i_modify_ts = di->i_modify_ts;
        for (int i = 0; i < 30; i++) {
                mi->i_direct_pointer[i] = di->i_direct_pointer[i];
        }
        mi->i_single_indirect_pointer = di->i_single_indirect_pointer;
        mi->i_double_indirect_pointer = di->i_double_indirect_pointer;
}

variable_types: struct d_inode { unsigned short i_mode; unsigned int i_size; struct time i_create_ts; struct time i_modify_ts; unsigned int i_direct_pointer[30]; unsigned int i_single_indirect_pointer; unsigned int i_double_indirect_pointer; } *


decompiled_code:
__int16 *alloc_inode()
{
__int16 *v0; // rdx
int v1; // eax
__int64 v3; // rdx

v0 = inode_table;
v1 = 0;
while ( *v0 != -1 )
{
++v1;
v0 += 80;
if ( v1 == 10 )
return 0LL;
}
v3 = 80LL * v1;
inode_table[v3] = v1;
return &inode_table[v3];
}

canonical_decompiled_code:
__int16 *func9()
{
__int16 *v0; // rdx
int v1; // eax
__int64 v3; // rdx

v0 = inode_table;
v1 = 0;
while ( *v0 != -1 )
{
++v1;
v0 += 80;
if ( v1 == 10 )
return 0LL;
}
v3 = 80LL * v1;
inode_table[v3] = v1;
return &inode_table[v3];
}

original_code:
m_inode* alloc_inode(void)
{
        for (int i = 0; i < 10; i++) {
                if (inode_table[i].i_num == -1) {
                        inode_table[i].i_num = i;
                        return &inode_table[i];
                }
        }
        return 0;
}

canonical_original_code:
struct m_inode *alloc_inode()
{
        for (int i = 0; i < 10; i++) {
                if (inode_table[i].i_num == -1) {
                        inode_table[i].i_num = i;
                        return &inode_table[i];
                }
        }
        return 0;
}

return_type: struct m_inode { short i_num; unsigned int i_adr; unsigned short i_mode; unsigned int i_size; struct time { unsigned char sec; unsigned char min; unsigned char hour; unsigned char weekday; unsigned char day; unsigned char month; unsigned char year; unsigned char century; } i_create_ts; struct time i_modify_ts; unsigned int i_direct_pointer[30]; unsigned int i_single_indirect_pointer; unsigned int i_double_indirect_pointer; } *


decompiled_code:
void dump_inode()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
void dump_inode(m_inode *mi)
{
        ((void)0);
        for (int i = 0; i < 30; i++) {
                ((void)0);
        }
        ((void)0);
}

canonical_original_code:
void dump_inode(struct m_inode *mi)
{
        ((void)0);
        for (int i = 0; i < 30; i++) {
                ((void)0);
        }
        ((void)0);
}


decompiled_code:
void dump_dinode()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void dump_dinode(d_inode *di)
{
        ((void)0);
        for (int i = 0; i < 30; i++) {
                ((void)0);
        }
        ((void)0);
}

canonical_original_code:
void dump_dinode(struct d_inode *di)
{
        ((void)0);
        for (int i = 0; i < 30; i++) {
                ((void)0);
        }
        ((void)0);
}


decompiled_code:
void dump_inodes()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code:
void dump_inodes()
{
        for (int i = 0; i < 10; i++) {
                dump_inode(&inode_table[i]);
        }
}


decompiled_code:
__int64 __fastcall chips_rm(int a1, __int64 a2)
{
__int64 result; // rax
__int16 v3; // ax
unsigned int v4; // ebp
char v5; // r8
_WORD v6[44]; // [rsp+0h] [rbp-58h] BYREF

if ( a1 == 2 )
{
v3 = do_open(*(_QWORD *)(a2 + 8));
if ( v3 < 0 )
{
fprintf(stderr, "Failed to open %s\n", *(const char **)(a2 + 8));
result = 1LL;
}
else
{
v4 = v3;
get_file_info((unsigned int)v3, v6);
do_close(v4);
if ( v6[14] == 1 )
{
v5 = fs_delete(*(_QWORD *)(a2 + 8));
result = 0LL;
if ( !v5 )
{
fprintf(stderr, "Failed to delete %s\n", *(const char **)(a2 + 8));
result = 1LL;
}
}
else
{
fprintf(stderr, "Not a file: %s\n", *(const char **)(a2 + 8));
result = 1LL;
}
}
}
else
{
fprintf(stderr, "Usage: %s <path>\n", *(const char **)a2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
__int64 result; // rax
__int16 v3; // ax
unsigned int v4; // ebp
char v5; // r8
_WORD v6[44]; // [rsp+0h] [rbp-58h] BYREF

if ( a1 == 2 )
{
v3 = do_open(*(_QWORD *)(a2 + 8));
if ( v3 < 0 )
{
fprintf(stderr, "Failed to open %s\n", *(const char **)(a2 + 8));
result = 1LL;
}
else
{
v4 = v3;
get_file_info((unsigned int)v3, v6);
do_close(v4);
if ( v6[14] == 1 )
{
v5 = fs_delete(*(_QWORD *)(a2 + 8));
result = 0LL;
if ( !v5 )
{
fprintf(stderr, "Failed to delete %s\n", *(const char **)(a2 + 8));
result = 1LL;
}
}
else
{
fprintf(stderr, "Not a file: %s\n", *(const char **)(a2 + 8));
result = 1LL;
}
}
}
else
{
fprintf(stderr, "Usage: %s <path>\n", *(const char **)a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int chips_rm(int argc, char **argv)
{
 if(argc != 2)
 {
  fprintf(stderr, "Usage: %s <path>\n", argv[0]);
  return -1;
 }
 int fd = do_open(argv[1]);
 if(fd < 0)
 {
  fprintf(stderr, "Failed to open %s\n", argv[1]);
  return 1;
 }
 potatoes_file_info_t info;
 get_file_info(fd, &info);
 do_close(fd);
 if(info.mode != 1)
 {
  fprintf(stderr, "Not a file: %s\n", argv[1]);
  return 1;
 }
 if(!fs_delete(argv[1]))
 {
  fprintf(stderr, "Failed to delete %s\n", argv[1]);
  return 1;
 }
 return 0;
}

canonical_original_code:
static int chips_rm(int argc, char **argv)
{
 if(argc != 2)
 {
  fprintf(stderr, "Usage: %s <path>\n", argv[0]);
  return -1;
 }
 int fd = do_open(argv[1]);
 if(fd < 0)
 {
  fprintf(stderr, "Failed to open %s\n", argv[1]);
  return 1;
 }
 struct potatoes_file_info info;
 get_file_info(fd, &info);
 do_close(fd);
 if(info.mode != 1)
 {
  fprintf(stderr, "Not a file: %s\n", argv[1]);
  return 1;
 }
 if(!fs_delete(argv[1]))
 {
  fprintf(stderr, "Failed to delete %s\n", argv[1]);
  return 1;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: fd int

variable_types: struct potatoes_file_info { char name[28]; unsigned short mode; unsigned int size; struct potatoes_time { unsigned char sec; unsigned char min; unsigned char hour; unsigned char weekday; unsigned char day; unsigned char month; unsigned char year; unsigned char century; } create_ts; struct potatoes_time modify_ts; unsigned short num_links; }

return_type: int

user_defined_types: struct potatoes_file_info { char name[28]; unsigned short mode; unsigned int size; struct potatoes_time create_ts; struct potatoes_time modify_ts; unsigned short num_links; }


decompiled_code:
__int64 __fastcall chips_ls(int a1, __int64 a2)
{
const char *v2; // r12
__int16 v3; // ax
unsigned int v4; // er14
unsigned int v5; // er13
signed int v6; // eax
unsigned int v7; // er12
char *v8; // rbx
char *v9; // rbp
const char *v10; // rdi
const char *v12; // rdx
char v13[28]; // [rsp+0h] [rbp-268h] BYREF
__int16 v14; // [rsp+1Ch] [rbp-24Ch]
char v15[4]; // [rsp+40h] [rbp-228h] BYREF
char s[548]; // [rsp+44h] [rbp-224h] BYREF

v2 = "/";
if ( a1 > 1 )
v2 = *(const char **)(a2 + 8);
v3 = do_open(v2);
v4 = v3;
if ( v3 < 0 )
{
v12 = v2;
v7 = -1;
fprintf(stderr, "Failed to open %s\n", v12);
}
else
{
v5 = 0;
get_file_info((unsigned int)v3, v13);
if ( v14 == 2 )
{
while ( 1 )
{
v6 = do_read(v4, v15, 512LL, v5);
v7 = v6;
if ( !v6 )
break;
v8 = s;
v9 = &s[v6 & 0xFFFFFFFFFFFFFFE0LL];
if ( (unsigned __int64)v6 >> 5 )
{
do
{
if ( !*((_DWORD *)v8 - 1) )
break;
v10 = v8;
v8 += 32;
puts(v10);
}
while ( v8 != v9 );
}
v5 += v7;
}
do_close(v4);
}
else
{
v7 = 0;
puts(v13);
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
const char *v2; // r12
__int16 v3; // ax
unsigned int v4; // er14
unsigned int v5; // er13
signed int v6; // eax
unsigned int v7; // er12
char *v8; // rbx
char *v9; // rbp
const char *v10; // rdi
const char *v12; // rdx
char v13[28]; // [rsp+0h] [rbp-268h] BYREF
__int16 v14; // [rsp+1Ch] [rbp-24Ch]
char v15[4]; // [rsp+40h] [rbp-228h] BYREF
char s[548]; // [rsp+44h] [rbp-224h] BYREF

v2 = "/";
if ( a1 > 1 )
v2 = *(const char **)(a2 + 8);
v3 = do_open(v2);
v4 = v3;
if ( v3 < 0 )
{
v12 = v2;
v7 = -1;
fprintf(stderr, "Failed to open %s\n", v12);
}
else
{
v5 = 0;
get_file_info((unsigned int)v3, v13);
if ( v14 == 2 )
{
while ( 1 )
{
v6 = do_read(v4, v15, 512LL, v5);
v7 = v6;
if ( !v6 )
break;
v8 = s;
v9 = &s[v6 & 0xFFFFFFFFFFFFFFE0LL];
if ( (unsigned __int64)v6 >> 5 )
{
do
{
if ( !*((_DWORD *)v8 - 1) )
break;
v10 = v8;
v8 += 32;
puts(v10);
}
while ( v8 != v9 );
}
v5 += v7;
}
do_close(v4);
}
else
{
v7 = 0;
puts(v13);
}
}
return v7;
}

original_code:
static int chips_ls(int argc, char **argv)
{
 char const *path = "/";
 if(argc > 1)
  path = argv[1];
 int fd = do_open((char *)path);
 if(fd < 0)
 {
  fprintf(stderr, "Failed to open %s\n", path);
  return -1;
 }
 potatoes_file_info_t info;
 get_file_info(fd, &info);
 if(info.mode != 2)
 {
  printf("%s\n", info.name);
  return 0;
 }
 potatoes_dir_entry dir[((512)/(sizeof (struct potatoes_dir_entry)))];
 int count, pos = 0;
 int i;
 while((count = do_read(fd, dir, sizeof(dir), pos)) != 0)
 {
  for(i = 0; i < count/sizeof(dir[0]) && dir[i].inode != 0; ++i)
   printf("%s\n", dir[i].name);
  pos += count;
 }
 do_close(fd);
 return 0;
}

canonical_original_code:
static int chips_ls(int argc, char **argv)
{
 char *path = "/";
 if(argc > 1)
  path = argv[1];
 int fd = do_open((char *)path);
 if(fd < 0)
 {
  fprintf(stderr, "Failed to open %s\n", path);
  return -1;
 }
 struct potatoes_file_info info;
 get_file_info(fd, &info);
 if(info.mode != 2)
 {
  printf("%s\n", info.name);
  return 0;
 }
 struct potatoes_dir_entry dir[-1];
 int count; int pos = 0;
 int i;
 while((count = do_read(fd, dir, sizeof(dir), pos)) != 0)
 {
  for(i = 0; i < count/sizeof(dir[0]) && dir[i].inode != 0; ++i)
   printf("%s\n", dir[i].name);
  pos += count;
 }
 do_close(fd);
 return 0;
}

variable_types:
path
char *

variable_types: struct potatoes_dir_entry { unsigned int inode; char name[28]; } [-1]

variable_types: count int

variable_types: pos int

user_defined_types: struct potatoes_time { unsigned char sec; unsigned char min; unsigned char hour; unsigned char weekday; unsigned char day; unsigned char month; unsigned char year; unsigned char century; }


decompiled_code:
__int64 __fastcall chips_trunc(int a1, __int64 a2)
{
__int64 v3; // rsi
char v4; // r8
__int64 result; // rax
int v6; // eax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned int)(a1 - 2) > 1 )
{
fprintf(stderr, "Usage: %s <file> [size]\n", *(const char **)a2);
result = 0xFFFFFFFFLL;
}
else
{
v3 = 0LL;
if ( a1 == 3 && ((v6 = strtol(*(const char **)(a2 + 16), &endptr, 0), *endptr) || (v3 = (unsigned int)v6, v6 < 0)) )
{
fprintf(stderr, "Not a nonnegative integer: %s\n", *(const char **)(a2 + 16));
result = 0xFFFFFFFFLL;
}
else
{
v4 = fs_truncate(*(_QWORD *)(a2 + 8), v3);
result = 0LL;
if ( !v4 )
{
fprintf(stderr, "Truncating %s failed.\n", *(const char **)(a2 + 8));
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2)
{
__int64 v3; // rsi
char v4; // r8
__int64 result; // rax
int v6; // eax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned int)(a1 - 2) > 1 )
{
fprintf(stderr, "Usage: %s <file> [size]\n", *(const char **)a2);
result = 0xFFFFFFFFLL;
}
else
{
v3 = 0LL;
if ( a1 == 3 && ((v6 = strtol(*(const char **)(a2 + 16), &endptr, 0), *endptr) || (v3 = (unsigned int)v6, v6 < 0)) )
{
fprintf(stderr, "Not a nonnegative integer: %s\n", *(const char **)(a2 + 16));
result = 0xFFFFFFFFLL;
}
else
{
v4 = fs_truncate(*(_QWORD *)(a2 + 8), v3);
result = 0LL;
if ( !v4 )
{
fprintf(stderr, "Truncating %s failed.\n", *(const char **)(a2 + 8));
result = 1LL;
}
}
}
return result;
}

original_code:
static int chips_trunc(int argc, char **argv)
{
 if(argc < 2 || argc > 3)
 {
  fprintf(stderr, "Usage: %s <file> [size]\n", argv[0]);
  return -1;
 }
 int size = 0;
 if(argc == 3)
 {
  char *end;
  size = strtol(argv[2], &end, 0);
  if(*end != 0 || size < 0)
  {
   fprintf(stderr, "Not a nonnegative integer: %s\n", argv[2]);
   return -1;
  }
 }
 if(!fs_truncate(argv[1], size))
 {
  fprintf(stderr, "Truncating %s failed.\n", argv[1]);
  return 1;
 }
 return 0;
}

variable_types: size int

variable_types:
end
char *


decompiled_code:
__int64 __fastcall chips_append(int a1, __int64 a2)
{
__int64 result; // rax
int v3; // er12
unsigned int v4; // ebp
int v5; // eax
int v6; // ebx
_WORD v7[16]; // [rsp+0h] [rbp-258h] BYREF
unsigned int v8; // [rsp+20h] [rbp-238h]
char buf[536]; // [rsp+40h] [rbp-218h] BYREF

if ( a1 != 2 )
{
fprintf(stderr, "Usage: %s <file>\n", *(const char **)a2);
return 0xFFFFFFFFLL;
}
v3 = (__int16)do_open(*(_QWORD *)(a2 + 8));
if ( v3 < 0 )
{
if ( !(unsigned __int8)fs_create(*(_QWORD *)(a2 + 8), 1LL) )
{
fprintf(stderr, "Failed to create %s\n", *(const char **)(a2 + 8));
return 1LL;
}
v3 = (__int16)do_open(*(_QWORD *)(a2 + 8));
if ( v3 < 0 )
{
fprintf(stderr, "Failed to open %s\n", *(const char **)(a2 + 8));
return 1LL;
}
}
get_file_info((unsigned int)v3, v7);
v4 = v8;
if ( v7[14] == 1 )
{
while ( 1 )
{
v5 = read(0, buf, 0x200uLL);
v6 = v5;
if ( v5 <= 0 )
break;
do_write((unsigned int)v3, buf, (unsigned int)v5, v4);
v4 += v6;
}
result = 0LL;
}
else
{
fprintf(stderr, "Not a file: %s\n", *(const char **)(a2 + 8));
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, __int64 a2)
{
__int64 result; // rax
int v3; // er12
unsigned int v4; // ebp
int v5; // eax
int v6; // ebx
_WORD v7[16]; // [rsp+0h] [rbp-258h] BYREF
unsigned int v8; // [rsp+20h] [rbp-238h]
char buf[536]; // [rsp+40h] [rbp-218h] BYREF

if ( a1 != 2 )
{
fprintf(stderr, "Usage: %s <file>\n", *(const char **)a2);
return 0xFFFFFFFFLL;
}
v3 = (__int16)do_open(*(_QWORD *)(a2 + 8));
if ( v3 < 0 )
{
if ( !(unsigned __int8)fs_create(*(_QWORD *)(a2 + 8), 1LL) )
{
fprintf(stderr, "Failed to create %s\n", *(const char **)(a2 + 8));
return 1LL;
}
v3 = (__int16)do_open(*(_QWORD *)(a2 + 8));
if ( v3 < 0 )
{
fprintf(stderr, "Failed to open %s\n", *(const char **)(a2 + 8));
return 1LL;
}
}
get_file_info((unsigned int)v3, v7);
v4 = v8;
if ( v7[14] == 1 )
{
while ( 1 )
{
v5 = read(0, buf, 0x200uLL);
v6 = v5;
if ( v5 <= 0 )
break;
do_write((unsigned int)v3, buf, (unsigned int)v5, v4);
v4 += v6;
}
result = 0LL;
}
else
{
fprintf(stderr, "Not a file: %s\n", *(const char **)(a2 + 8));
result = 1LL;
}
return result;
}

original_code:
static int chips_append(int argc, char **argv)
{
 if(argc != 2)
 {
  fprintf(stderr, "Usage: %s <file>\n", argv[0]);
  return -1;
 }
 int fd = do_open(argv[1]);
 if(fd < 0)
 {
  if(!fs_create(argv[1], 1))
  {
   fprintf(stderr, "Failed to create %s\n", argv[1]);
   return 1;
  }
  if((fd = do_open(argv[1])) < 0)
  {
   fprintf(stderr, "Failed to open %s\n", argv[1]);
   return 1;
  }
 }
 potatoes_file_info_t info;
 get_file_info(fd, &info);
 if(info.mode != 1)
 {
  fprintf(stderr, "Not a file: %s\n", argv[1]);
  return 1;
 }
 char buf[512];
 int count;
 int off = info.size;
 while((count = read(0, buf, 512)) > 0)
 {
  do_write(fd, buf, count, off);
  off += count;
 }
 return 0;
}

canonical_original_code:
static int chips_append(int argc, char **argv)
{
 if(argc != 2)
 {
  fprintf(stderr, "Usage: %s <file>\n", argv[0]);
  return -1;
 }
 int fd = do_open(argv[1]);
 if(fd < 0)
 {
  if(!fs_create(argv[1], 1))
  {
   fprintf(stderr, "Failed to create %s\n", argv[1]);
   return 1;
  }
  if((fd = do_open(argv[1])) < 0)
  {
   fprintf(stderr, "Failed to open %s\n", argv[1]);
   return 1;
  }
 }
 struct potatoes_file_info info;
 get_file_info(fd, &info);
 if(info.mode != 1)
 {
  fprintf(stderr, "Not a file: %s\n", argv[1]);
  return 1;
 }
 char buf[512];
 int count;
 int off = info.size;
 while((count = read(0, buf, 512)) > 0)
 {
  do_write(fd, buf, count, off);
  off += count;
 }
 return 0;
}

variable_types:
buf
char [512]

variable_types: off int


decompiled_code:
__int64 __fastcall chips_cat(int a1, const char **a2)
{
const char **v2; // r12
__int16 v3; // ax
unsigned int v4; // ebp
unsigned int v5; // ebx
int v6; // eax
__int64 result; // rax
_WORD v8[32]; // [rsp+0h] [rbp-268h] BYREF
char buf[552]; // [rsp+40h] [rbp-228h] BYREF

if ( a1 <= 1 )
{
fprintf(stderr, "Usage: %s <file> [more files ...]\n", *a2);
result = 0xFFFFFFFFLL;
}
else
{
v2 = a2 + 1;
while ( 1 )
{
v3 = do_open(*v2);
v4 = v3;
if ( v3 < 0 )
{
fprintf(stderr, "Failed to open %s\n", *v2);
goto LABEL_11;
}
get_file_info((unsigned int)v3, v8);
if ( v8[14] != 1 )
break;
v5 = 0;
while ( 1 )
{
v6 = do_read(v4, buf, 512LL, v5);
if ( v6 <= 0 )
break;
v5 += v6;
write(1, buf, v6);
}
if ( ++v2 == &a2[(unsigned int)(a1 - 2) + 2] )
return 0LL;
}
fprintf(stderr, "Not a file: %s\n", *v2);
LABEL_11:
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, const char **a2)
{
const char **v2; // r12
__int16 v3; // ax
unsigned int v4; // ebp
unsigned int v5; // ebx
int v6; // eax
__int64 result; // rax
_WORD v8[32]; // [rsp+0h] [rbp-268h] BYREF
char buf[552]; // [rsp+40h] [rbp-228h] BYREF

if ( a1 <= 1 )
{
fprintf(stderr, "Usage: %s <file> [more files ...]\n", *a2);
result = 0xFFFFFFFFLL;
}
else
{
v2 = a2 + 1;
while ( 1 )
{
v3 = do_open(*v2);
v4 = v3;
if ( v3 < 0 )
{
fprintf(stderr, "Failed to open %s\n", *v2);
goto LABEL_11;
}
get_file_info((unsigned int)v3, v8);
if ( v8[14] != 1 )
break;
v5 = 0;
while ( 1 )
{
v6 = do_read(v4, buf, 512LL, v5);
if ( v6 <= 0 )
break;
v5 += v6;
write(1, buf, v6);
}
if ( ++v2 == &a2[(unsigned int)(a1 - 2) + 2] )
return 0LL;
}
fprintf(stderr, "Not a file: %s\n", *v2);
LABEL_11:
result = 1LL;
}
return result;
}

original_code:
static int chips_cat(int argc, char **argv)
{
 if(argc < 2)
 {
  fprintf(stderr, "Usage: %s <file> [more files ...]\n", argv[0]);
  return -1;
 }
 int i;
 for(i = 1; i < argc; ++i)
 {
  int fd = do_open(argv[i]);
  if(fd < 0)
  {
   fprintf(stderr, "Failed to open %s\n", argv[i]);
   return 1;
  }
  potatoes_file_info_t info;
  get_file_info(fd, &info);
  if(info.mode != 1)
  {
   fprintf(stderr, "Not a file: %s\n", argv[i]);
   return 1;
  }
  char buf[512];
  int count;
  int off = 0;
  while((count = do_read(fd, buf, 512, off)) > 0)
  {
   off += count;
   write(1, buf, count);
  }
 }
 return 0;
}

canonical_original_code:
static int chips_cat(int argc, char **argv)
{
 if(argc < 2)
 {
  fprintf(stderr, "Usage: %s <file> [more files ...]\n", argv[0]);
  return -1;
 }
 int i;
 for(i = 1; i < argc; ++i)
 {
  int fd = do_open(argv[i]);
  if(fd < 0)
  {
   fprintf(stderr, "Failed to open %s\n", argv[i]);
   return 1;
  }
  struct potatoes_file_info info;
  get_file_info(fd, &info);
  if(info.mode != 1)
  {
   fprintf(stderr, "Not a file: %s\n", argv[i]);
   return 1;
  }
  char buf[512];
  int count;
  int off = 0;
  while((count = do_read(fd, buf, 512, off)) > 0)
  {
   off += count;
   write(1, buf, count);
  }
 }
 return 0;
}

variable_types: i int


decompiled_code:
__int64 chips_consts()
{
dump_consts();
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
dump_consts();
return 0LL;
}

original_code:
static int chips_consts(int argc, char **argv)
{
 dump_consts();
 return 0;
}


decompiled_code:
__int64 __fastcall chips_usage(const char *a1)
{
char **v1; // rbx
const char *v2; // rdx
const char *v3; // rcx

v1 = off_980;
fprintf(stderr, "Usage: %s <disk image> <command> [args ...]\n\n", a1);
fwrite("Available commands:\n", 1uLL, 0x14uLL, stderr);
v2 = "consts";
v3 = "Dump a list of constants used by the file system.";
while ( 1 )
{
fprintf(stderr, "\t%-10s - %s\n", v2, v3);
if ( v1 == (char **)&unk_A10 )
break;
v3 = v1[1];
v2 = *v1;
v1 += 3;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
char **v1; // rbx
const char *v2; // rdx
const char *v3; // rcx

v1 = off_980;
fprintf(stderr, "Usage: %s <disk image> <command> [args ...]\n\n", a1);
fwrite("Available commands:\n", 1uLL, 0x14uLL, stderr);
v2 = "consts";
v3 = "Dump a list of constants used by the file system.";
while ( 1 )
{
fprintf(stderr, "\t%-10s - %s\n", v2, v3);
if ( v1 == (char **)&unk_A10 )
break;
v3 = v1[1];
v2 = *v1;
v1 += 3;
}
return 0xFFFFFFFFLL;
}

original_code:
int chips_usage(char const *progname)
{
 fprintf(stderr, "Usage: %s <disk image> <command> [args ...]\n\n", progname);
 fprintf(stderr, "Available commands:\n");
 int i;
 for(i = 0; i < chips_num_commands; ++i)
  fprintf(stderr, "\t%-10s - %s\n", chips_commands[i].name, chips_commands[i].desc);
 return -1;
}

canonical_original_code:
int chips_usage(char *progname)
{
 fprintf(stderr, "Usage: %s <disk image> <command> [args ...]\n\n", progname);
 fprintf(stderr, "Available commands:\n");
 int i;
 for(i = 0; i < chips_num_commands; ++i)
  fprintf(stderr, "\t%-10s - %s\n", chips_commands[i].name, chips_commands[i].desc);
 return -1;
}

variable_types:
progname
char *


decompiled_code:
__int64 __fastcall chips_mkdir(int a1, __int64 a2)
{
__int64 result; // rax
char v3; // r8

if ( a1 == 2 )
{
v3 = fs_create(*(_QWORD *)(a2 + 8), 2LL);
result = 0LL;
if ( !v3 )
{
fprintf(stderr, "Failed to create directory %s\n", *(const char **)(a2 + 8));
result = 1LL;
}
}
else
{
fprintf(stderr, "Usage: %s <path>\n", *(const char **)a2);
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 == 2 )
{
v3 = fs_create(*(_QWORD *)(a2 + 8), 2LL);
result = 0LL;
if ( !v3 )
{
fprintf(stderr, "Failed to create directory %s\n", *(const char **)(a2 + 8));
result = 1LL;
}
}
else
{
fprintf(stderr, "Usage: %s <path>\n", *(const char **)a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int chips_mkdir(int argc, char **argv)
{
 if(argc != 2)
 {
  fprintf(stderr, "Usage: %s <path>\n", argv[0]);
  return -1;
 }
 if(!fs_create(argv[1], 2))
 {
  fprintf(stderr, "Failed to create directory %s\n", argv[1]);
  return 1;
 }
 return 0;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r14
__int64 v5; // rbx
const char *v6; // r15
int v8; // er12

if ( argc <= 2 )
return chips_usage(*argv);
v3 = potatoes_disc_create(argv[1]);
v4 = v3;
if ( v3 )
{
v5 = 0LL;
potatoes_set_current_disk(v3);
fs_init();
v6 = argv[2];
while ( strcmp(v6, off_968[3 * v5]) )
{
if ( ++v5 == 7 )
return chips_usage(*argv);
}
v8 = ((__int64 (__fastcall *)(_QWORD, const char **))*(&chips_commands + 3 * (int)v5))(
(unsigned int)(argc - 2),
argv + 2);
potatoes_set_current_disk(0LL);
potatoes_disc_destroy(v4);
}
else
{
v8 = 1;
fprintf(stderr, "Failed to open disk image %s\n", argv[1]);
}
return v8;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r14
__int64 v5; // rbx
const char *v6; // r15
int v8; // er12

if ( argc <= 2 )
return func7(*argv);
v3 = potatoes_disc_create(argv[1]);
v4 = v3;
if ( v3 )
{
v5 = 0LL;
potatoes_set_current_disk(v3);
fs_init();
v6 = argv[2];
while ( strcmp(v6, off_968[3 * v5]) )
{
if ( ++v5 == 7 )
return func7(*argv);
}
v8 = ((__int64 (__fastcall *)(_QWORD, const char **))*(&chips_commands + 3 * (int)v5))(
(unsigned int)(argc - 2),
argv + 2);
potatoes_set_current_disk(0LL);
potatoes_disc_destroy(v4);
}
else
{
v8 = 1;
fprintf(stderr, "Failed to open disk image %s\n", argv[1]);
}
return v8;
}

original_code:
int main(int argc, char **argv)
{
 if(argc < 3)
  return chips_usage(argv[0]);
 PotatoesDisk *disk = potatoes_disc_create(argv[1]);
 if(disk == ((void *)0))
 {
  fprintf(stderr, "Failed to open disk image %s\n", argv[1]);
  return 1;
 }
 potatoes_set_current_disk(disk);
 fs_init();
 int ret = -1;
 int i;
 for(i = 0; i < chips_num_commands; ++i)
  if(strcmp(argv[2], chips_commands[i].name) == 0)
  {
   ret = chips_commands[i].exec(argc - 2, argv + 2);
   break;
  }
 if(i == chips_num_commands)
  return chips_usage(argv[0]);
 potatoes_set_current_disk(((void *)0));
 potatoes_disc_destroy(disk);
 return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
 if(argc < 3)
  return chips_usage(argv[0]);
 struct PotatoesDisk *disk = potatoes_disc_create(argv[1]);
 if(disk == ((void *)0))
 {
  fprintf(stderr, "Failed to open disk image %s\n", argv[1]);
  return 1;
 }
 potatoes_set_current_disk(disk);
 fs_init();
 int ret = -1;
 int i;
 for(i = 0; i < chips_num_commands; ++i)
  if(strcmp(argv[2], chips_commands[i].name) == 0)
  {
   ret = chips_commands[i].exec(argc - 2, argv + 2);
   break;
  }
 if(i == chips_num_commands)
  return chips_usage(argv[0]);
 potatoes_set_current_disk(((void *)0));
 potatoes_disc_destroy(disk);
 return ret;
}

variable_types: struct PotatoesDisk { unsigned char *data; unsigned int size; } *

variable_types: ret int


decompiled_code:
__int64 __fastcall shrink_file(_DWORD *a1, unsigned int a2)
{
char *v3; // rbx
char *v4; // r12
__int64 v5; // rdi
__int64 v6; // rdi
__int64 result; // rax
char v8[552]; // [rsp+0h] [rbp-228h] BYREF

if ( a2 <= 0x7F )
{
rd_block(v8, (unsigned int)*a1, 512LL);
v3 = &v8[4 * a2];
v4 = &v8[4 * a2 + 4 + 4 * (unsigned __int64)(127 - a2)];
do
{
while ( 1 )
{
v5 = *(unsigned int *)v3;
if ( (_DWORD)v5 )
break;
v3 += 4;
if ( v3 == v4 )
goto LABEL_6;
}
v3 += 4;
mark_block(v5, 0LL);
*((_DWORD *)v3 - 1) = 0;
}
while ( v3 != v4 );
LABEL_6:
v6 = (unsigned int)*a1;
if ( a2 )
{
result = wrt_block(v6, v8, 512LL);
}
else
{
result = mark_block(v6, 0LL);
*a1 = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, unsigned int a2)
{
char *v3; // rbx
char *v4; // r12
__int64 v5; // rdi
__int64 v6; // rdi
__int64 result; // rax
char v8[552]; // [rsp+0h] [rbp-228h] BYREF

if ( a2 <= 0x7F )
{
rd_block(v8, (unsigned int)*a1, 512LL);
v3 = &v8[4 * a2];
v4 = &v8[4 * a2 + 4 + 4 * (unsigned __int64)(127 - a2)];
do
{
while ( 1 )
{
v5 = *(unsigned int *)v3;
if ( (_DWORD)v5 )
break;
v3 += 4;
if ( v3 == v4 )
goto LABEL_6;
}
v3 += 4;
mark_block(v5, 0LL);
*((_DWORD *)v3 - 1) = 0;
}
while ( v3 != v4 );
LABEL_6:
v6 = (unsigned int)*a1;
if ( a2 )
{
result = wrt_block(v6, v8, 512LL);
}
else
{
result = mark_block(v6, 0LL);
*a1 = 0;
}
}
return result;
}

original_code:
static void shrink_file(block_nr *block, uint32 start)
{
        ((void)0);
        if(start >= ((512)/(4)))
        {
                ((void)0);
                return;
        }
        block_nr addr_cache2[((512)/(4))];
        rd_block(addr_cache2, *block, sizeof(addr_cache2));
        int i;
        for(i = start; i < ((512)/(4)); ++i)
        {
                if(addr_cache2[i] != 0)
                {
                        mark_block(addr_cache2[i], 0);
                        addr_cache2[i] = 0;
                }
        }
        if(start != 0)
        {
                wrt_block(*block, addr_cache2, sizeof(addr_cache2));
        }
        else
        {
                mark_block(*block, 0);
                *block = 0;
        }
}

canonical_original_code:
static void shrink_file(unsigned int *block, unsigned int start)
{
        ((void)0);
        if(start >= ((512)/(4)))
        {
                ((void)0);
                return;
        }
        unsigned int addr_cache2[-1];
        rd_block(addr_cache2, *block, sizeof(addr_cache2));
        int i;
        for(i = start; i < ((512)/(4)); ++i)
        {
                if(addr_cache2[i] != 0)
                {
                        mark_block(addr_cache2[i], 0);
                        addr_cache2[i] = 0;
                }
        }
        if(start != 0)
        {
                wrt_block(*block, addr_cache2, sizeof(addr_cache2));
        }
        else
        {
                mark_block(*block, 0);
                *block = 0;
        }
}

variable_types:
block
unsigned int *

variable_types:
start
unsigned int


original_code:
bool fs_truncate(char *abs_path, uint32 size)
{
        ((void)0);
        int fd = fs_open(abs_path);
        if(fd < 0)
            return 0;
        m_inode *inode = get_file(fd)->f_inode;
        if(size < inode->i_size)
        {
                int start = (size + 512 - 1) / 512;
                int i, blk;
                for(i = start; i < 30; ++i)
                {
                        blk = inode->i_direct_pointer[i];
                        if(blk != 0)
                        {
                            mark_block(blk, 0);
                            inode->i_direct_pointer[i] = 0;
                        }
                }
                if(inode->i_single_indirect_pointer != 0 && start < 30 + ((512)/(4)))
                        shrink_file(&inode->i_single_indirect_pointer, (0 > start - 30 ? 0 : start - 30));
                if(inode->i_double_indirect_pointer != 0)
                {
                        rd_block(addr_cache, inode->i_double_indirect_pointer, sizeof(addr_cache));
                        for(i = (0 > (start - 30 - ((512)/(4))) / ((512)/(4)) ? 0 : (start - 30 - ((512)/(4))) / ((512)/(4))); i < ((512)/(4)); ++i)
                        {
                                if(addr_cache[i] == 0)
                                        break;
                                shrink_file(&addr_cache[i], (0 > start - 30 - (i + 1) * ((512)/(4)) ? 0 : start - 30 - (i + 1) * ((512)/(4))));
                        }
                        if(start < 30 + ((512)/(4)))
                        {
                                mark_block(inode->i_double_indirect_pointer, 0);
                                inode->i_double_indirect_pointer = 0;
                        }
                        else
                        {
                                wrt_block(inode->i_double_indirect_pointer, addr_cache, sizeof(addr_cache));
                        }
                }
        }
        else if(size > inode->i_size)
                get_data_block(inode, size, 1);
        inode->i_size = size;
        write_inode(inode);
        fs_close(fd);
        return 1;
}

canonical_original_code:
unsigned char fs_truncate(char *abs_path, unsigned int size)
{
        ((void)0);
        int fd = fs_open(abs_path);
        if(fd < 0)
            return 0;
        struct m_inode *inode = get_file(fd)->f_inode;
        if(size < inode->i_size)
        {
                int start = (size + 512 - 1) / 512;
                int i; int blk;
                for(i = start; i < 30; ++i)
                {
                        blk = inode->i_direct_pointer[i];
                        if(blk != 0)
                        {
                            mark_block(blk, 0);
                            inode->i_direct_pointer[i] = 0;
                        }
                }
                if(inode->i_single_indirect_pointer != 0 && start < 30 + ((512)/(4)))
                        shrink_file(&inode->i_single_indirect_pointer, (0 > start - 30 ? 0 : start - 30));
                if(inode->i_double_indirect_pointer != 0)
                {
                        rd_block(addr_cache, inode->i_double_indirect_pointer, sizeof(addr_cache));
                        for(i = (0 > (start - 30 - ((512)/(4))) / ((512)/(4)) ? 0 : (start - 30 - ((512)/(4))) / ((512)/(4))); i < ((512)/(4)); ++i)
                        {
                                if(addr_cache[i] == 0)
                                        break;
                                shrink_file(&addr_cache[i], (0 > start - 30 - (i + 1) * ((512)/(4)) ? 0 : start - 30 - (i + 1) * ((512)/(4))));
                        }
                        if(start < 30 + ((512)/(4)))
                        {
                                mark_block(inode->i_double_indirect_pointer, 0);
                                inode->i_double_indirect_pointer = 0;
                        }
                        else
                        {
                                wrt_block(inode->i_double_indirect_pointer, addr_cache, sizeof(addr_cache));
                        }
                }
        }
        else if(size > inode->i_size)
                get_data_block(inode, size, 1);
        inode->i_size = size;
        write_inode(inode);
        fs_close(fd);
        return 1;
}

variable_types:
size
unsigned int

variable_types: struct m_inode { short i_num; unsigned int i_adr; unsigned short i_mode; unsigned int i_size; struct time { unsigned char sec; unsigned char min; unsigned char hour; unsigned char weekday; unsigned char day; unsigned char month; unsigned char year; unsigned char century; } i_create_ts; struct time i_modify_ts; unsigned int i_direct_pointer[30]; unsigned int i_single_indirect_pointer; unsigned int i_double_indirect_pointer; } *

variable_types: start int

variable_types: blk int

return_type: unsigned char


decompiled_code:
__int64 __fastcall fs_create(__int64 a1, unsigned int a2)
{
return fs_create_delete(a1, 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
return func2(a1, 1, a2);
}

original_code:
bool fs_create(char *abs_path, int data_type)
{
        return fs_create_delete(abs_path, 1, data_type);
}

canonical_original_code:
unsigned char fs_create(char *abs_path, int data_type)
{
        return fs_create_delete(abs_path, 1, data_type);
}


decompiled_code:
__int64 __fastcall fs_delete(__int64 a1)
{
return fs_create_delete(a1, 2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return func2(a1, 2, 0);
}

original_code:
bool fs_delete(char *abs_path)
{
        return fs_create_delete(abs_path, 2, 0);
}

canonical_original_code:
unsigned char fs_delete(char *abs_path)
{
        return fs_create_delete(abs_path, 2, 0);
}


decompiled_code:
bool __fastcall contains_filename(unsigned int *a1, __int64 a2)
{
return (unsigned int)find_filename(a1, a2) != -1;
}

canonical_decompiled_code:
bool __fastcall func3(unsigned int *a1, __int64 a2)
{
return (unsigned int)func0(a1, a2) != -1;
}

original_code:
bool contains_filename(dir_entry file_list[((512)/(sizeof (struct dir_entry)))], char *name)
{
        return (find_filename(file_list, name) != -1);
}

canonical_original_code:
unsigned char contains_filename(struct dir_entry file_list[-1], char *name)
{
        return (find_filename(file_list, name) != -1);
}

variable_types: struct dir_entry { unsigned int inode; char name[28]; } [-1]

variable_types:
name
char *


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

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

original_code:
static int chips_release(const char *path, struct fuse_file_info *fi)
{
 return 0;
}

canonical_original_code:
static int chips_release(char *path, struct fuse_file_info *fi)
{
 return 0;
}

variable_types:
path
char *

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *


decompiled_code:
__int64 chips_open()
{
__int16 v0; // ax
unsigned int v1; // ebp
__int64 result; // rax
_WORD v3[36]; // [rsp+0h] [rbp-48h] BYREF

v0 = do_open();
if ( v0 < 0 )
return 4294967294LL;
v1 = v0;
get_file_info((unsigned int)v0, v3);
if ( v3[14] == 1 )
{
do_close(v1);
result = 0LL;
}
else
{
do_close(v1);
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int16 v0; // ax
unsigned int v1; // ebp
__int64 result; // rax
_WORD v3[36]; // [rsp+0h] [rbp-48h] BYREF

v0 = do_open();
if ( v0 < 0 )
return 4294967294LL;
v1 = v0;
get_file_info((unsigned int)v0, v3);
if ( v3[14] == 1 )
{
do_close(v1);
result = 0LL;
}
else
{
do_close(v1);
result = 4294967294LL;
}
return result;
}

original_code:
static int chips_open(const char *path, struct fuse_file_info *fi)
{
 int fd = do_open((char *)path);
 if(fd < 0)
  return -2;
 potatoes_file_info_t info;
 get_file_info(fd, &info);
 if(info.mode != 1)
 {
  do_close(fd);
  return -2;
 }
 do_close(fd);
 return 0;
}

canonical_original_code:
static int chips_open(char *path, struct fuse_file_info *fi)
{
 int fd = do_open((char *)path);
 if(fd < 0)
  return -2;
 struct potatoes_file_info info;
 get_file_info(fd, &info);
 if(info.mode != 1)
 {
  do_close(fd);
  return -2;
 }
 do_close(fd);
 return 0;
}

variable_types: fd int

variable_types: struct potatoes_file_info { char name[28]; unsigned short mode; unsigned int size; struct potatoes_time { unsigned char sec; unsigned char min; unsigned char hour; unsigned char weekday; unsigned char day; unsigned char month; unsigned char year; unsigned char century; } create_ts; struct potatoes_time modify_ts; unsigned short num_links; }

user_defined_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; }


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

result = chips_open(a1, a3);
if ( (_DWORD)result )
{
if ( (unsigned __int8)fs_create(a1, 1LL) )
result = chips_open(a1, a3);
else
result = 4294967294LL;
}
return result;
}

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

result = func2(a1, a3);
if ( (_DWORD)result )
{
if ( (unsigned __int8)fs_create(a1, 1LL) )
result = func2(a1, a3);
else
result = 4294967294LL;
}
return result;
}

original_code:
int chips_create(const char *path, mode_t mode, struct fuse_file_info *fi)
{
 if(chips_open(path, fi) == 0)
  return 0;
 if(!fs_create((char *)path, 1))
  return -2;
 return chips_open(path, fi);
}

canonical_original_code:
int chips_create(char *path, unsigned int mode, struct fuse_file_info *fi)
{
 if(chips_open(path, fi) == 0)
  return 0;
 if(!fs_create((char *)path, 1))
  return -2;
 return chips_open(path, fi);
}

variable_types:
mode
unsigned int


decompiled_code:
__int64 __fastcall chips_unlink(__int64 a1)
{
__int16 v1; // ax
unsigned int v2; // er12
_WORD v4[44]; // [rsp+0h] [rbp-58h] BYREF

v1 = do_open();
if ( v1 < 0 )
return 4294967294LL;
v2 = v1;
get_file_info((unsigned int)v1, v4);
if ( v4[14] != 1 )
return 0xFFFFFFFFLL;
do_close(v2);
return (unsigned int)-((unsigned __int8)fs_delete(a1) == 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int16 v1; // ax
unsigned int v2; // er12
_WORD v4[44]; // [rsp+0h] [rbp-58h] BYREF

v1 = do_open();
if ( v1 < 0 )
return 4294967294LL;
v2 = v1;
get_file_info((unsigned int)v1, v4);
if ( v4[14] != 1 )
return 0xFFFFFFFFLL;
do_close(v2);
return (unsigned int)-((unsigned __int8)fs_delete(a1) == 0);
}

original_code:
int chips_unlink(const char *path)
{
 int fd = do_open((char *)path);
 if(fd < 0)
  return -2;
 potatoes_file_info_t info;
 get_file_info(fd, &info);
 if(info.mode != 1)
  return -1;
 do_close(fd);
 return fs_delete((char *)path) ? 0 : -1;
}

canonical_original_code:
int chips_unlink(char *path)
{
 int fd = do_open((char *)path);
 if(fd < 0)
  return -2;
 struct potatoes_file_info info;
 get_file_info(fd, &info);
 if(info.mode != 1)
  return -1;
 do_close(fd);
 return fs_delete((char *)path) ? 0 : -1;
}


decompiled_code:
__int64 __fastcall chips_readdir(__int64 a1, __int64 a2, void (__fastcall *a3)(__int64, char *, _QWORD, _QWORD))
{
__int16 v5; // ax
unsigned int i; // er14
signed int v7; // eax
unsigned int v8; // er13
char *v9; // r15
char *v10; // rbx
char *v11; // rsi
unsigned int v13; // [rsp+Ch] [rbp-27Ch]
char v14[28]; // [rsp+10h] [rbp-278h] BYREF
__int16 v15; // [rsp+2Ch] [rbp-25Ch]
char v16[4]; // [rsp+50h] [rbp-238h] BYREF
char s[564]; // [rsp+54h] [rbp-234h] BYREF

v5 = do_open();
v13 = v5;
if ( v5 < 0 )
return (unsigned int)-2;
get_file_info((unsigned int)v5, v14);
if ( v15 != 2 )
return (unsigned int)-2;
for ( i = 0; ; i += v8 )
{
v7 = do_read(v13, v16, 512LL, i);
v8 = v7;
if ( !v7 )
break;
v9 = s;
v10 = &s[v7 & 0xFFFFFFFFFFFFFFE0LL];
if ( (unsigned __int64)v7 >> 5 )
{
do
{
if ( !*((_DWORD *)v9 - 1) )
break;
puts(v9);
v11 = v9;
v9 += 32;
a3(a2, v11, 0LL, 0LL);
}
while ( v9 != v10 );
}
}
do_close(v13);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, void (__fastcall *a3)(__int64, char *, _QWORD, _QWORD))
{
__int16 v5; // ax
unsigned int i; // er14
signed int v7; // eax
unsigned int v8; // er13
char *v9; // r15
char *v10; // rbx
char *v11; // rsi
unsigned int v13; // [rsp+Ch] [rbp-27Ch]
char v14[28]; // [rsp+10h] [rbp-278h] BYREF
__int16 v15; // [rsp+2Ch] [rbp-25Ch]
char v16[4]; // [rsp+50h] [rbp-238h] BYREF
char s[564]; // [rsp+54h] [rbp-234h] BYREF

v5 = do_open();
v13 = v5;
if ( v5 < 0 )
return (unsigned int)-2;
get_file_info((unsigned int)v5, v14);
if ( v15 != 2 )
return (unsigned int)-2;
for ( i = 0; ; i += v8 )
{
v7 = do_read(v13, v16, 512LL, i);
v8 = v7;
if ( !v7 )
break;
v9 = s;
v10 = &s[v7 & 0xFFFFFFFFFFFFFFE0LL];
if ( (unsigned __int64)v7 >> 5 )
{
do
{
if ( !*((_DWORD *)v9 - 1) )
break;
puts(v9);
v11 = v9;
v9 += 32;
a3(a2, v11, 0LL, 0LL);
}
while ( v9 != v10 );
}
}
do_close(v13);
return v8;
}

original_code:
static int chips_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
{
 int fd = do_open((char *)path);
 if(fd < 0)
  return -2;
 potatoes_file_info_t info;
 get_file_info(fd, &info);
 if(info.mode != 2)
  return -2;
 potatoes_dir_entry dir[((512)/(sizeof (struct potatoes_dir_entry)))];
 int count, pos = 0;
 int i;
 while((count = do_read(fd, dir, sizeof(dir), pos)) != 0)
 {
  for(i = 0; i < count/sizeof(dir[0]) && dir[i].inode != 0; ++i)
  {
   printf("%s\n", dir[i].name);
   filler(buf, dir[i].name, ((void *)0), 0);
  }
  pos += count;
 }
 do_close(fd);
 return 0;
}

canonical_original_code:
static int chips_readdir(char *path, void *buf, int (*filler)(void *buf, char *name, struct stat *stbuf, long off), long offset, struct fuse_file_info *fi)
{
 int fd = do_open((char *)path);
 if(fd < 0)
  return -2;
 struct potatoes_file_info info;
 get_file_info(fd, &info);
 if(info.mode != 2)
  return -2;
 struct potatoes_dir_entry dir[-1];
 int count; int pos = 0;
 int i;
 while((count = do_read(fd, dir, sizeof(dir), pos)) != 0)
 {
  for(i = 0; i < count/sizeof(dir[0]) && dir[i].inode != 0; ++i)
  {
   printf("%s\n", dir[i].name);
   filler(buf, dir[i].name, ((void *)0), 0);
  }
  pos += count;
 }
 do_close(fd);
 return 0;
}

variable_types:
buf
void *

variable_types: int (*)(void *buf, char *name, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *stbuf, long off)

variable_types: offset long

variable_types: struct potatoes_dir_entry { unsigned int inode; char name[28]; } [-1]

variable_types: count int

variable_types: pos int

variable_types: i int

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


decompiled_code:
__int64 __fastcall chips_read(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
unsigned int v6; // ebp
unsigned int v7; // er12

v6 = (__int16)do_open();
v7 = do_read(v6, a2, a3, a4);
do_close(v6);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
unsigned int v6; // ebp
unsigned int v7; // er12

v6 = (__int16)do_open();
v7 = do_read(v6, a2, a3, a4);
do_close(v6);
return v7;
}

original_code:
static int chips_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
{
 int fd = do_open((char *)path);
 int ret = do_read(fd, buf, size, offset);
 do_close(fd);
 return ret;
}

canonical_original_code:
static int chips_read(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *fi)
{
 int fd = do_open((char *)path);
 int ret = do_read(fd, buf, size, offset);
 do_close(fd);
 return ret;
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types: ret int


decompiled_code:
__int64 __fastcall chips_write(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rbp
unsigned int v7; // er12

v6 = (unsigned int)(__int16)do_open();
v7 = do_write(v6, a2, a3, a4);
do_close((unsigned int)v6);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rbp
unsigned int v7; // er12

v6 = (unsigned int)(__int16)do_open();
v7 = do_write(v6, a2, a3, a4);
do_close((unsigned int)v6);
return v7;
}

original_code:
static int chips_write (const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
{
 int fd = do_open((char *)path);
 int ret = do_write(fd, (char *)buf, size, offset);
 do_close(fd);
 return ret;
}

canonical_original_code:
static int chips_write(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *fi)
{
 int fd = do_open((char *)path);
 int ret = do_write(fd, (char *)buf, size, offset);
 do_close(fd);
 return ret;
}


decompiled_code:
__int64 chips_truncate()
{
return (unsigned int)-((unsigned __int8)fs_truncate() == 0);
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned int)-((unsigned __int8)fs_truncate() == 0);
}

original_code:
static int chips_truncate(const char *path, off_t offset)
{
 return fs_truncate((char *)path, offset) ? 0 : -1;
}

canonical_original_code:
static int chips_truncate(char *path, long offset)
{
 return fs_truncate((char *)path, offset) ? 0 : -1;
}


original_code:
static int chips_getattr(const char *path, struct stat *stbuf)
{
 memset(stbuf, 0, sizeof(struct stat));
 int fd = do_open((char *)path);
 if(fd < 0)
  return -2;
 potatoes_file_info_t info;
 get_file_info(fd, &info);
 if(info.mode == 2)
 {
  stbuf->st_mode = 0040000 | 0777;
  stbuf->st_nlink = 2;
 }
 else
 {
  stbuf->st_mode = 0100000 | 0666;
  stbuf->st_nlink = 1;
  stbuf->st_size = info.size;
 }
 do_close(fd);
 return 0;
}

canonical_original_code:
static int chips_getattr(char *path, struct stat *stbuf)
{
 memset(stbuf, 0, sizeof(struct stat));
 int fd = do_open((char *)path);
 if(fd < 0)
  return -2;
 struct potatoes_file_info info;
 get_file_info(fd, &info);
 if(info.mode == 2)
 {
  stbuf->st_mode = 0040000 | 0777;
  stbuf->st_nlink = 2;
 }
 else
 {
  stbuf->st_mode = 0100000 | 0666;
  stbuf->st_nlink = 1;
  stbuf->st_size = info.size;
 }
 do_close(fd);
 return 0;
}

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


decompiled_code:
__int64 __fastcall chips_mkdir(__int64 a1)
{
return (unsigned __int8)fs_create(a1, 2LL) == 0 ? 0xFFFFFFFE : 0;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return (unsigned __int8)fs_create(a1, 2LL) == 0 ? 0xFFFFFFFE : 0;
}

original_code:
int chips_mkdir(const char *path, mode_t mode)
{
 if(!fs_create((char *)path, 2))
  return -2;
 return 0;
}

canonical_original_code:
int chips_mkdir(char *path, unsigned int mode)
{
 if(!fs_create((char *)path, 2))
  return -2;
 return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rdi

if ( argc <= 2 )
{
fprintf(stderr, "Usage: %s <disk image> <mountpoint>\n", *argv);
}
else
{
v4 = potatoes_disc_create(argv[1]);
if ( v4 )
{
potatoes_set_current_disk(v4);
fs_init();
return ((__int64 (__fastcall *)(_QWORD, const char **, __int64 (__fastcall **)(), __int64, _QWORD))fuse_main_real)(
(unsigned int)(argc - 1),
argv + 1,
&chips_oper,
360LL,
0LL);
}
fprintf(stderr, "Failed to open disk image %s\n", argv[1]);
}
return 1;
}

original_code:
int main(int argc, char **argv) {
 if(argc < 3)
 {
  fprintf(stderr, "Usage: %s <disk image> <mountpoint>\n", argv[0]);
  return 1;
 }
 PotatoesDisk *disk = potatoes_disc_create(argv[1]);
 if(disk == ((void *)0))
 {
  fprintf(stderr, "Failed to open disk image %s\n", argv[1]);
  return 1;
 }
 potatoes_set_current_disk(disk);
 fs_init();
 return fuse_main_real(argc - 1, argv + 1, &chips_oper, sizeof(*(&chips_oper)), ((void *)0));
}

canonical_original_code:
int main(int argc, char **argv) {
 if(argc < 3)
 {
  fprintf(stderr, "Usage: %s <disk image> <mountpoint>\n", argv[0]);
  return 1;
 }
 struct PotatoesDisk *disk = potatoes_disc_create(argv[1]);
 if(disk == ((void *)0))
 {
  fprintf(stderr, "Failed to open disk image %s\n", argv[1]);
  return 1;
 }
 potatoes_set_current_disk(disk);
 fs_init();
 return fuse_main_real(argc - 1, argv + 1, &chips_oper, sizeof(*(&chips_oper)), ((void *)0));
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct PotatoesDisk { unsigned char *data; unsigned int size; } *


decompiled_code:
__int64 __fastcall fs_close(__int16 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // er8

v2 = get_file((unsigned int)a1);
v5 = 0;
if ( v2 && *(_WORD *)v2 != 0xFFFF )
{
write_inode(*(_QWORD *)(v2 + 8), a2, v3, v4, 0LL);
free_file((unsigned int)a1);
dump_files();
v5 = 1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // er8

v2 = get_file((unsigned int)a1);
v5 = 0;
if ( v2 && *(_WORD *)v2 != 0xFFFF )
{
write_inode(*(_QWORD *)(v2 + 8), a2, v3, v4, 0LL);
free_file((unsigned int)a1);
dump_files();
v5 = 1;
}
return v5;
}

original_code:
bool fs_close(file_nr fd)
{
        file *f = get_file(fd);
        if (f == (file*) 0 || f->f_desc == -1) {
                return 0;
        }
        ((void)0);
        write_inode(f->f_inode);
        free_file(fd);
        dump_files();
        return 1;
}

canonical_original_code:
unsigned char fs_close(short fd)
{
        struct file *f = get_file(fd);
        if (f == (struct file *) 0 || f->f_desc == -1) {
                return 0;
        }
        ((void)0);
        write_inode(f->f_inode);
        free_file(fd);
        dump_files();
        return 1;
}

variable_types: fd short

variable_types: struct file { short f_desc; struct m_inode { short i_num; unsigned int i_adr; unsigned short i_mode; unsigned int i_size; struct time { unsigned char sec; unsigned char min; unsigned char hour; unsigned char weekday; unsigned char day; unsigned char month; unsigned char year; unsigned char century; } i_create_ts; struct time i_modify_ts; unsigned int i_direct_pointer[30]; unsigned int i_single_indirect_pointer; unsigned int i_double_indirect_pointer; } *f_inode; char *f_name; unsigned char f_mode; unsigned short f_count; } *

user_defined_types: struct file { short f_desc; struct m_inode *f_inode; char *f_name; unsigned char f_mode; unsigned short f_count; }


decompiled_code:
__int64 __fastcall do_read(__int16 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
unsigned int v5; // er12
__int64 v7; // rax
_WORD v9[16]; // [rsp+0h] [rbp-68h] BYREF
int v10; // [rsp+20h] [rbp-48h]

v5 = 512;
get_file_info((unsigned int)a1, v9);
if ( v9[14] != 2 )
{
v5 = v10 - a4;
if ( v10 - a4 > a3 )
v5 = a3;
}
v7 = get_file((unsigned int)a1);
return fs_read(a2, *(_QWORD *)(v7 + 8), v5, a4, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int16 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
unsigned int v5; // er12
__int64 v7; // rax
_WORD v9[16]; // [rsp+0h] [rbp-68h] BYREF
int v10; // [rsp+20h] [rbp-48h]

v5 = 512;
get_file_info((unsigned int)a1, v9);
if ( v9[14] != 2 )
{
v5 = v10 - a4;
if ( v10 - a4 > a3 )
v5 = a3;
}
v7 = get_file((unsigned int)a1);
return fs_read(a2, *(_QWORD *)(v7 + 8), v5, a4, 0LL);
}

original_code:
size_t do_read(file_nr fd, void *buf, size_t count, uint32 pos)
{
        file_info_t info;
        get_file_info(fd, &info);
        int to_read;
        if (info.mode == 2) {
                to_read = sizeof(dir_entry) * ((512)/(sizeof (struct dir_entry)));
        } else {
                to_read = (count > info.size - pos) ? info.size - pos : count;
        }
        ((void)0);
        return fs_read(buf, get_file(fd)->f_inode, to_read, pos, 0);
}

canonical_original_code:
unsigned int do_read(short fd, void *buf, unsigned int count, unsigned int pos)
{
        struct file_info info;
        get_file_info(fd, &info);
        int to_read;
        if (info.mode == 2) {
                to_read = sizeof(dir_entry) * ((512)/(sizeof (struct dir_entry)));
        } else {
                to_read = (count > info.size - pos) ? info.size - pos : count;
        }
        ((void)0);
        return fs_read(buf, get_file(fd)->f_inode, to_read, pos, 0);
}

variable_types:
count
unsigned int

variable_types:
pos
unsigned int

variable_types: struct file_info { char name[28]; unsigned short mode; unsigned int size; struct time { unsigned char sec; unsigned char min; unsigned char hour; unsigned char weekday; unsigned char day; unsigned char month; unsigned char year; unsigned char century; } create_ts; struct time modify_ts; unsigned short num_links; }

return_type: unsigned int

user_defined_types: struct file_info { char name[28]; unsigned short mode; unsigned int size; struct time create_ts; struct time modify_ts; unsigned short num_links; }

user_defined_types: struct dir_entry { unsigned int inode; char name[28]; }


decompiled_code:
__int64 __fastcall do_write(__int16 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax

v6 = get_file((unsigned int)a1);
return fs_write(*(_QWORD *)(v6 + 8), a2, a3, a4, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int16 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax

v6 = get_file((unsigned int)a1);
return fs_write(*(_QWORD *)(v6 + 8), a2, a3, a4, 1LL);
}

original_code:
size_t do_write(file_nr fd, void *buf, size_t count, uint32 pos)
{
        return fs_write(get_file(fd)->f_inode, buf, count, pos, 1);
}

canonical_original_code:
unsigned int do_write(short fd, void *buf, unsigned int count, unsigned int pos)
{
        return fs_write(get_file(fd)->f_inode, buf, count, pos, 1);
}

variable_types:
buf
void *


decompiled_code:
__int64 __fastcall do_create(__int64 a1, unsigned __int8 a2)
{
return fs_create(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int8 a2)
{
return fs_create(a1, a2);
}

original_code:
bool do_create(char *abs_path, uint8 mode)
{
        return (fs_create(abs_path, mode));
}

canonical_original_code:
unsigned char do_create(char *abs_path, unsigned char mode)
{
        return (fs_create(abs_path, mode));
}

variable_types:
mode
unsigned char


decompiled_code:
__int64 __fastcall do_mkdir(__int64 a1)
{
return fs_create(a1, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return fs_create(a1, 2LL);
}

original_code:
bool do_mkdir(char *abs_path)
{
        return (fs_create(abs_path, 2));
}

canonical_original_code:
unsigned char do_mkdir(char *abs_path)
{
        return (fs_create(abs_path, 2));
}


decompiled_code:
__int64 __fastcall do_mkfile(__int64 a1)
{
return do_create(a1, 1u);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return func6(a1, 1u);
}

original_code:
bool do_mkfile(char *abs_path)
{
        return (do_create(abs_path, 1));
}

canonical_original_code:
unsigned char do_mkfile(char *abs_path)
{
        return (do_create(abs_path, 1));
}


decompiled_code:
__int64 do_remove()
{
return (unsigned int)-((unsigned __int8)fs_delete() == 0);
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)-((unsigned __int8)fs_delete() == 0);
}

original_code:
int do_remove(char *abs_path)
{
        return (fs_delete(abs_path)) ? 0 : -1;
}


decompiled_code:
// attributes: thunk
__int64 do_open()
{
return fs_open();
}

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

original_code:
file_nr do_open(char *abs_path)
{
        return (fs_open(abs_path));
}

canonical_original_code:
short do_open(char *abs_path)
{
        return (fs_open(abs_path));
}

return_type: short


decompiled_code:
__int64 __fastcall do_close(__int16 a1)
{
return (unsigned int)-((unsigned __int8)fs_close((unsigned int)a1) == 0);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int16 a1)
{
return (unsigned int)-((unsigned __int8)fs_close((unsigned int)a1) == 0);
}

original_code:
int do_close(file_nr fd)
{
        return (fs_close(fd)) ? 0 : -1;
}

canonical_original_code:
int do_close(short fd)
{
        return (fs_close(fd)) ? 0 : -1;
}


decompiled_code:
__int64 __fastcall do_close_pf(__int64 a1, __int16 a2)
{
__int64 v2; // rax
unsigned int v3; // er12

v2 = get_proc_file(a1, (unsigned int)a2);
if ( (unsigned int)do_close(*(_WORD *)(v2 + 2)) )
return (unsigned int)-1;
v3 = 0;
free_proc_file(a1, (unsigned int)a2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int16 a2)
{
__int64 v2; // rax
unsigned int v3; // er12

v2 = get_proc_file(a1, (unsigned int)a2);
if ( (unsigned int)func11(*(_WORD *)(v2 + 2)) )
return (unsigned int)-1;
v3 = 0;
free_proc_file(a1, (unsigned int)a2);
return v3;
}

original_code:
int do_close_pf(proc_file pft[20], file_nr pfd)
{
        proc_file *pf = get_proc_file(pft, pfd);
        if (do_close(pf->pf_f_desc) == 0) {
                free_proc_file(pft, pfd);
                return 0;
        }
        return -1;
}

canonical_original_code:
int do_close_pf(struct proc_file pft[20], short pfd)
{
        struct proc_file *pf = get_proc_file(pft, pfd);
        if (do_close(pf->pf_f_desc) == 0) {
                free_proc_file(pft, pfd);
                return 0;
        }
        return -1;
}

variable_types: struct proc_file { short pf_desc; short pf_f_desc; unsigned int pf_pos; } [20]

variable_types: pfd short

variable_types: struct proc_file { short pf_desc; short pf_f_desc; unsigned int pf_pos; } *


decompiled_code:
__off_t __fastcall do_lseek(int a1, __int16 a2, int a3)
{
return lseek(a1, (unsigned int)a2, a3);
}

canonical_decompiled_code:
__off_t __fastcall func13(int a1, __int16 a2, int a3)
{
return lseek(a1, (unsigned int)a2, a3);
}

original_code:
size_t do_lseek(proc_file pft[20], file_nr fd, sint32 offset, uint32 origin){
        return lseek(pft, fd, offset, origin);
}

canonical_original_code:
unsigned int do_lseek(struct proc_file pft[20], short fd, int offset, unsigned int origin){
        return lseek(pft, fd, offset, origin);
}

variable_types: offset int

variable_types:
origin
unsigned int

user_defined_types: struct proc_file { short pf_desc; short pf_f_desc; unsigned int pf_pos; }


decompiled_code:
bool do_file_exists()
{
return (unsigned int)search_file() != -1;
}

canonical_decompiled_code:
bool func14()
{
return (unsigned int)search_file() != -1;
}

original_code:
bool do_file_exists(char *path)
{
        return (search_file(path) != -1);
}

canonical_original_code:
unsigned char do_file_exists(char *path)
{
        return (search_file(path) != -1);
}

variable_types:
path
char *


decompiled_code:
__int64 __fastcall wrt_cache(unsigned int *a1, unsigned int a2)
{
return wrt_block(*a1, (__int64)(a1 + 1), a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, unsigned int a2)
{
return func2(*a1, (__int64)(a1 + 1), a2);
}

original_code:
void wrt_cache(block_cache *cache, size_t num_bytes)
{
        wrt_block(cache->block_nr, cache->cache, num_bytes);
}

canonical_original_code:
void wrt_cache(struct block_buffer *cache, unsigned int num_bytes)
{
        wrt_block(cache->block_nr, cache->cache, num_bytes);
}

variable_types: struct block_buffer { unsigned int block_nr; unsigned char cache[512]; } *


decompiled_code:
__int64 __fastcall enlarge_file(unsigned int *a1, unsigned int a2)
{
unsigned int v2; // er12

v2 = alloc_block(a2);
clear_block(v2);
*a1 = v2;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1, unsigned int a2)
{
unsigned int v2; // er12

v2 = alloc_block(a2);
func4(v2);
*a1 = v2;
return v2;
}

original_code:
block_nr enlarge_file(block_nr *blk_ptr, block_nr alloc_start)
{
        block_nr data_blk = alloc_block(alloc_start);
        clear_block(data_blk);
        *blk_ptr = data_blk;
        return data_blk;
}

canonical_original_code:
unsigned int enlarge_file(unsigned int *blk_ptr, unsigned int alloc_start)
{
        unsigned int data_blk = alloc_block(alloc_start);
        clear_block(data_blk);
        *blk_ptr = data_blk;
        return data_blk;
}


decompiled_code:
__int64 __fastcall get_data_block(unsigned int *a1, unsigned int a2, char a3)
{
unsigned int v5; // er12
unsigned int v7; // esi
__int64 v8; // rbx
unsigned int v9; // er14
__int64 v10; // rbx
unsigned int v11; // er12
unsigned int v12; // er15
__int64 v13; // rax

if ( a2 > 0x3BFF )
{
if ( a2 <= 0x13BFF )
{
v7 = a1[38];
if ( v7 )
{
rd_block((__int64)addr_cache, v7, 0x200u);
v8 = (a2 - 15360) >> 9;
v5 = addr_cache[v8];
if ( v5 )
goto LABEL_3;
if ( !a3 )
return (unsigned int)-1;
}
else
{
if ( !a3 )
return (unsigned int)-1;
v8 = (a2 - 15360) >> 9;
enlarge_file(a1 + 38, a1[1]);
rd_block((__int64)addr_cache, a1[38], 0x200u);
v5 = addr_cache[(unsigned int)v8];
if ( v5 )
goto LABEL_3;
}
v5 = enlarge_file((unsigned int *)&addr_cache[v8], a1[38]);
wrt_block(a1[38], (__int64)addr_cache, 0x200u);
goto LABEL_3;
}
if ( a2 > 0x813BFF )
return (unsigned int)-1;
v9 = a1[39];
if ( v9 )
{
rd_block((__int64)addr_cache, v9, 0x200u);
v10 = (a2 - 80896) >> 16;
v12 = addr_cache[v10];
v11 = (a2 - 80896) >> 9;
if ( v12 )
{
rd_block((__int64)addr_cache, v12, 0x200u);
v13 = v11 & 0x7F;
v5 = addr_cache[v13];
if ( v5 )
goto LABEL_3;
if ( !a3 )
return (unsigned int)-1;
LABEL_18:
v5 = enlarge_file((unsigned int *)&addr_cache[v13], v9);
wrt_block(v12, (__int64)addr_cache, 0x200u);
goto LABEL_3;
}
if ( !a3 )
return (unsigned int)-1;
}
else
{
if ( !a3 )
return (unsigned int)-1;
v10 = (a2 - 80896) >> 16;
v11 = (a2 - 80896) >> 9;
v9 = enlarge_file(a1 + 39, a1[1]);
rd_block((__int64)addr_cache, v9, 0x200u);
v12 = addr_cache[v10];
if ( v12 )
{
rd_block((__int64)addr_cache, v12, 0x200u);
v13 = (unsigned __int8)((unsigned __int16)(a2 - 15360) >> 8) >> 1;
v5 = addr_cache[v13];
if ( v5 )
goto LABEL_3;
goto LABEL_18;
}
}
v12 = enlarge_file((unsigned int *)&addr_cache[v10], v9);
wrt_block(v9, (__int64)addr_cache, 0x200u);
rd_block((__int64)addr_cache, v12, 0x200u);
v13 = v11 & 0x7F;
v5 = addr_cache[v13];
if ( v5 )
goto LABEL_3;
goto LABEL_18;
}
v5 = a1[(a2 >> 9) + 8];
if ( !v5 )
{
if ( a3 )
{
v5 = enlarge_file(&a1[(a2 >> 9) + 8], a1[1]);
goto LABEL_3;
}
return (unsigned int)-1;
}
LABEL_3:
write_inode(a1);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1, unsigned int a2, char a3)
{
unsigned int v5; // er12
unsigned int v7; // esi
__int64 v8; // rbx
unsigned int v9; // er14
__int64 v10; // rbx
unsigned int v11; // er12
unsigned int v12; // er15
__int64 v13; // rax

if ( a2 > 0x3BFF )
{
if ( a2 <= 0x13BFF )
{
v7 = a1[38];
if ( v7 )
{
func1((__int64)addr_cache, v7, 0x200u);
v8 = (a2 - 15360) >> 9;
v5 = addr_cache[v8];
if ( v5 )
goto LABEL_3;
if ( !a3 )
return (unsigned int)-1;
}
else
{
if ( !a3 )
return (unsigned int)-1;
v8 = (a2 - 15360) >> 9;
func5(a1 + 38, a1[1]);
func1((__int64)addr_cache, a1[38], 0x200u);
v5 = addr_cache[(unsigned int)v8];
if ( v5 )
goto LABEL_3;
}
v5 = func5((unsigned int *)&addr_cache[v8], a1[38]);
func2(a1[38], (__int64)addr_cache, 0x200u);
goto LABEL_3;
}
if ( a2 > 0x813BFF )
return (unsigned int)-1;
v9 = a1[39];
if ( v9 )
{
func1((__int64)addr_cache, v9, 0x200u);
v10 = (a2 - 80896) >> 16;
v12 = addr_cache[v10];
v11 = (a2 - 80896) >> 9;
if ( v12 )
{
func1((__int64)addr_cache, v12, 0x200u);
v13 = v11 & 0x7F;
v5 = addr_cache[v13];
if ( v5 )
goto LABEL_3;
if ( !a3 )
return (unsigned int)-1;
LABEL_18:
v5 = func5((unsigned int *)&addr_cache[v13], v9);
func2(v12, (__int64)addr_cache, 0x200u);
goto LABEL_3;
}
if ( !a3 )
return (unsigned int)-1;
}
else
{
if ( !a3 )
return (unsigned int)-1;
v10 = (a2 - 80896) >> 16;
v11 = (a2 - 80896) >> 9;
v9 = func5(a1 + 39, a1[1]);
func1((__int64)addr_cache, v9, 0x200u);
v12 = addr_cache[v10];
if ( v12 )
{
func1((__int64)addr_cache, v12, 0x200u);
v13 = (unsigned __int8)((unsigned __int16)(a2 - 15360) >> 8) >> 1;
v5 = addr_cache[v13];
if ( v5 )
goto LABEL_3;
goto LABEL_18;
}
}
v12 = func5((unsigned int *)&addr_cache[v10], v9);
func2(v9, (__int64)addr_cache, 0x200u);
func1((__int64)addr_cache, v12, 0x200u);
v13 = v11 & 0x7F;
v5 = addr_cache[v13];
if ( v5 )
goto LABEL_3;
goto LABEL_18;
}
v5 = a1[(a2 >> 9) + 8];
if ( !v5 )
{
if ( a3 )
{
v5 = func5(&a1[(a2 >> 9) + 8], a1[1]);
goto LABEL_3;
}
return (unsigned int)-1;
}
LABEL_3:
write_inode(a1);
return v5;
}

original_code:
block_nr get_data_block(m_inode *inode, uint32 pos, bool allow_enlargement)
{
        ((void)0);
        uint32 blk_nr;
        block_nr data_blk;
        if (pos < ((30) * (512))) {
                blk_nr = pos / 512;
                data_blk = inode->i_direct_pointer[blk_nr];
                if (data_blk == 0) {
                        if (!allow_enlargement) {
                                return -1;
                        }
                        data_blk = enlarge_file(&(inode->i_direct_pointer[blk_nr]), inode->i_adr);
                        ((void)0);
                }
        } else if (pos < (((30) * (512)) + ((((512)/(4))) * (512)))) {
                block_nr sip = inode->i_single_indirect_pointer;
                if (sip == 0) {
                        if (!allow_enlargement) {
                                return -1;
                        }
                        sip = enlarge_file(&(inode->i_single_indirect_pointer), inode->i_adr);
                        ((void)0);
                }
                rd_block(addr_cache, inode->i_single_indirect_pointer, sizeof(addr_cache));
                blk_nr = (pos - ((30) * (512))) / 512;
                data_blk = addr_cache[blk_nr];
                if (data_blk == 0) {
                        if (!allow_enlargement) {
                                return -1;
                        }
                        data_blk = enlarge_file(&addr_cache[blk_nr], inode->i_single_indirect_pointer);
                        wrt_block(inode->i_single_indirect_pointer, addr_cache, sizeof(addr_cache));
                        ((void)0);
                }
        } else if (pos < (((30) * (512)) + ((((512)/(4))) * (512)) + ((((512)/(4))) * (((512)/(4))) * (512)))) {
                block_nr dip = inode->i_double_indirect_pointer;
                if (dip == 0) {
                        if (!allow_enlargement) {
                                return -1;
                        }
                        dip = enlarge_file(&(inode->i_double_indirect_pointer), inode->i_adr);
                        ((void)0);
                }
                rd_block(addr_cache, dip, sizeof(addr_cache));
                blk_nr = (pos - ((30) * (512)) - ((((512)/(4))) * (512))) / 512;
                block_nr addr_block = blk_nr / ((512)/(4));
                block_nr sip = addr_cache[addr_block];
                if (sip == 0) {
                        if (!allow_enlargement) {
                                return -1;
                        }
                        sip = enlarge_file(&addr_cache[addr_block], dip);
                        wrt_block(dip, addr_cache, sizeof(addr_cache));
                        ((void)0);
                }
                rd_block(addr_cache, sip, sizeof(addr_cache));
                data_blk = addr_cache[blk_nr % ((512)/(4))];
                if (data_blk == 0) {
                        if (!allow_enlargement) {
                                return -1;
                        }
                        data_blk = enlarge_file(&addr_cache[blk_nr % ((512)/(4))], dip);
                        wrt_block(sip, addr_cache, sizeof(addr_cache));
                        ((void)0);
                }
        } else {
                return -1;
        }
        write_inode(inode);
        return data_blk;
}

canonical_original_code:
unsigned int get_data_block(struct m_inode *inode, unsigned int pos, unsigned char allow_enlargement)
{
        ((void)0);
        unsigned int blk_nr;
        unsigned int data_blk;
        if (pos < ((30) * (512))) {
                blk_nr = pos / 512;
                data_blk = inode->i_direct_pointer[blk_nr];
                if (data_blk == 0) {
                        if (!allow_enlargement) {
                                return -1;
                        }
                        data_blk = enlarge_file(&(inode->i_direct_pointer[blk_nr]), inode->i_adr);
                        ((void)0);
                }
        } else if (pos < (((30) * (512)) + ((((512)/(4))) * (512)))) {
                unsigned int sip = inode->i_single_indirect_pointer;
                if (sip == 0) {
                        if (!allow_enlargement) {
                                return -1;
                        }
                        sip = enlarge_file(&(inode->i_single_indirect_pointer), inode->i_adr);
                        ((void)0);
                }
                rd_block(addr_cache, inode->i_single_indirect_pointer, sizeof(addr_cache));
                blk_nr = (pos - ((30) * (512))) / 512;
                data_blk = addr_cache[blk_nr];
                if (data_blk == 0) {
                        if (!allow_enlargement) {
                                return -1;
                        }
                        data_blk = enlarge_file(&addr_cache[blk_nr], inode->i_single_indirect_pointer);
                        wrt_block(inode->i_single_indirect_pointer, addr_cache, sizeof(addr_cache));
                        ((void)0);
                }
        } else if (pos < (((30) * (512)) + ((((512)/(4))) * (512)) + ((((512)/(4))) * (((512)/(4))) * (512)))) {
                unsigned int dip = inode->i_double_indirect_pointer;
                if (dip == 0) {
                        if (!allow_enlargement) {
                                return -1;
                        }
                        dip = enlarge_file(&(inode->i_double_indirect_pointer), inode->i_adr);
                        ((void)0);
                }
                rd_block(addr_cache, dip, sizeof(addr_cache));
                blk_nr = (pos - ((30) * (512)) - ((((512)/(4))) * (512))) / 512;
                unsigned int addr_block = blk_nr / ((512)/(4));
                unsigned int sip = addr_cache[addr_block];
                if (sip == 0) {
                        if (!allow_enlargement) {
                                return -1;
                        }
                        sip = enlarge_file(&addr_cache[addr_block], dip);
                        wrt_block(dip, addr_cache, sizeof(addr_cache));
                        ((void)0);
                }
                rd_block(addr_cache, sip, sizeof(addr_cache));
                data_blk = addr_cache[blk_nr % ((512)/(4))];
                if (data_blk == 0) {
                        if (!allow_enlargement) {
                                return -1;
                        }
                        data_blk = enlarge_file(&addr_cache[blk_nr % ((512)/(4))], dip);
                        wrt_block(sip, addr_cache, sizeof(addr_cache));
                        ((void)0);
                }
        } else {
                return -1;
        }
        write_inode(inode);
        return data_blk;
}

variable_types: struct m_inode { short i_num; unsigned int i_adr; unsigned short i_mode; unsigned int i_size; struct time { unsigned char sec; unsigned char min; unsigned char hour; unsigned char weekday; unsigned char day; unsigned char month; unsigned char year; unsigned char century; } i_create_ts; struct time i_modify_ts; unsigned int i_direct_pointer[30]; unsigned int i_single_indirect_pointer; unsigned int i_double_indirect_pointer; } *

variable_types:
sip
unsigned int

variable_types:
dip
unsigned int


decompiled_code:
__int64 write_super_block()
{
return wrt_block(1LL, super, 45LL);
}

canonical_decompiled_code:
__int64 func3()
{
return wrt_block(1LL, super, 45LL);
}

original_code:
void write_super_block()
{
        wrt_block(((block_nr) 1), super, sizeof(super_block));
}

canonical_original_code:
void write_super_block()
{
        wrt_block(((unsigned int) 1), super, sizeof(super_block));
}


help

decompiled_code:
void __noreturn help()
{
fwrite("Supply a command you wish to execute (and its arguments if needed).\n", 1uLL, 0x44uLL, _bss_start);
fwrite(
"If you need to wait for more than one window use -n <INT> as first two arguments.\n",
1uLL,
0x52uLL,
_bss_start);
fwrite("E.g. i3-exec-wait xterm -title \"Rc Shell\" -e rc\n", 1uLL, 0x30uLL, _bss_start);
fwrite(" i3-exec-wait -n 4 gimp\n", 1uLL, 0x1CuLL, _bss_start);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
fwrite("Supply a command you wish to execute (and its arguments if needed).\n", 1uLL, 0x44uLL, _bss_start);
fwrite(
"If you need to wait for more than one window use -n <INT> as first two arguments.\n",
1uLL,
0x52uLL,
_bss_start);
fwrite("E.g. i3-exec-wait xterm -title \"Rc Shell\" -e rc\n", 1uLL, 0x30uLL, _bss_start);
fwrite(" i3-exec-wait -n 4 gimp\n", 1uLL, 0x1CuLL, _bss_start);
exit(1);
}

original_code:
void help() {
  fprintf(stderr, "Supply a command you wish to execute (and its arguments if needed).\n");
  fprintf(stderr, "If you need to wait for more than one window use -n <INT> as first two arguments.\n");
  fprintf(stderr, "E.g. i3-exec-wait xterm -title \"Rc Shell\" -e rc\n");
  fprintf(stderr, "     i3-exec-wait -n 4 gimp\n");
  exit(1);
}


die

decompiled_code:
void __fastcall __noreturn die(char *s)
{
if ( *__errno_location() )
{
perror(s);
exit(2);
}
fprintf(_bss_start, "ERROR: %s!\n", s);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(char *s)
{
if ( *__errno_location() )
{
perror(s);
exit(2);
}
fprintf(_bss_start, "ERROR: %s!\n", s);
exit(1);
}

original_code:
void die(const char *msg) {
  if ((*__errno_location ())) {
    perror(msg);
    exit(2);
  } else {
    fprintf(stderr, "ERROR: %s!\n", msg);
    exit(1);
  }
}

canonical_original_code:
void die(char *msg) {
  if ((*__errno_location ())) {
    perror(msg);
    exit(2);
  } else {
    fprintf(stderr, "ERROR: %s!\n", msg);
    exit(1);
  }
}

variable_types:
msg
char *


decompiled_code:
__int64 get_window_id()
{
__int64 v0; // rax
__int64 v1; // r12

if ( !yajl_tree_parse() )
die("JSON response parse error");
v0 = yajl_tree_get();
if ( !v0 )
die("Window node not found in the JSON response");
v1 = *(_QWORD *)(v0 + 8);
yajl_tree_free();
return v1;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v0; // rax
__int64 v1; // r12

if ( !yajl_tree_parse() )
func8("JSON response parse error");
v0 = yajl_tree_get();
if ( !v0 )
func8("Window node not found in the JSON response");
v1 = *(_QWORD *)(v0 + 8);
yajl_tree_free();
return v1;
}

original_code:
long get_window_id(char *json) {
  const char *path[] = { "container", "window", (const char *) 0 };
  yajl_val node;
  char errbuf[1024];
  long window_id;
  if ((node = yajl_tree_parse((const char *) json, errbuf, sizeof(errbuf))) == ((void *)0)) {
    ;
    die("JSON response parse error");
  }
  yajl_val window = yajl_tree_get(node, path, yajl_t_number);
  if (window)
    window_id = (long) ((window)->u.number.i);
  else
    die("Window node not found in the JSON response");
  yajl_tree_free(node);
  return window_id;
}

canonical_original_code:
long get_window_id(char *json) {
  char *path[] = { "container", "window", (const char *) 0 };
  struct yajl_val_s *node;
  char errbuf[1024];
  long window_id;
  if ((node = yajl_tree_parse((char *) json, errbuf, sizeof(errbuf))) == ((void *)0)) {
    ;
    die("JSON response parse error");
  }
  struct yajl_val_s *window = yajl_tree_get(node, path, yajl_t_number);
  if (window)
    window_id = (long) ((window)->u.number.i);
  else
    die("Window node not found in the JSON response");
  yajl_tree_free(node);
  return window_id;
}

variable_types:
json
char *

variable_types:
path
char *[]

variable_types: struct yajl_val_s { enum yajl_type { yajl_t_string=1, yajl_t_number=2, yajl_t_object=3, yajl_t_array=4, yajl_t_true=5, yajl_t_false=6, yajl_t_null=7, yajl_t_any=8 } type; union { char *string; struct { long long i; double d; char *r; unsigned int flags; } number; struct { char **keys; struct yajl_val_s **values; unsigned long len; } object; struct { struct yajl_val_s **values; unsigned long len; } array; } u; } *

variable_types:
errbuf
char [1024]

return_type: long

user_defined_types: struct yajl_val_s { enum yajl_type type; union { char *string; struct { long long i; double d; char *r; unsigned int flags; } number; struct { char **keys; struct yajl_val_s **values; unsigned long len; } object; struct { struct yajl_val_s **values; unsigned long len; } array; } u; }


repo: dreamlayers/acidwarp

decompiled_code:
__int64 draw_continue()
{
SDL_mutexP(draw_mtx);
drawnext = 1;
drawdone = 0;
SDL_CondSignal(drawnext_cond);
return SDL_mutexV(draw_mtx);
}

canonical_decompiled_code:
__int64 func0()
{
SDL_mutexP(draw_mtx);
drawnext = 1;
drawdone = 0;
SDL_CondSignal(drawnext_cond);
return SDL_mutexV(draw_mtx);
}

original_code:
static void draw_continue(void) {
  SDL_mutexP(draw_mtx);
  drawnext = SDL_TRUE;
  drawdone = SDL_FALSE;
  SDL_CondSignal(drawnext_cond);
  SDL_mutexV(draw_mtx);
}

canonical_original_code:
static void draw_continue() {
  SDL_mutexP(draw_mtx);
  drawnext = SDL_TRUE;
  drawdone = SDL_FALSE;
  SDL_CondSignal(drawnext_cond);
  SDL_mutexV(draw_mtx);
}


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

flags &= 0xFFFFFFFE;
result = (unsigned int)(imageFuncListIndex + 1);
if ( (int)result > 39 )
{
imageFuncListIndex = 0;
result = makeShuffledList(&imageFuncList, 40LL);
}
else
{
++imageFuncListIndex;
}
return result;
}

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

flags &= 0xFFFFFFFE;
result = (unsigned int)(imageFuncListIndex + 1);
if ( (int)result > 39 )
{
imageFuncListIndex = 0;
result = makeShuffledList(&imageFuncList, 40LL);
}
else
{
++imageFuncListIndex;
}
return result;
}

original_code:
static void draw_advance(void)
{
  flags &= ~1;
  if (++imageFuncListIndex >= 40) {
    imageFuncListIndex = 0;
    makeShuffledList(imageFuncList, 40);
  }
}

canonical_original_code:
static void draw_advance()
{
  flags &= ~1;
  if (++imageFuncListIndex >= 40) {
    imageFuncListIndex = 0;
    makeShuffledList(imageFuncList, 40);
  }
}


draw

decompiled_code:
__int64 __fastcall draw(unsigned int a1)
{
__int64 v2; // rdi
__int64 v3; // rsi
__int64 v4; // rcx
__int64 v5; // rdx
__int64 result; // rax
unsigned int v7; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned int v8; // [rsp+10h] [rbp-18h] BYREF
unsigned int v9; // [rsp+14h] [rbp-14h] BYREF
__int64 v10; // [rsp+18h] [rbp-10h] BYREF

disp_beginUpdate(&v10, &v7, &v8, &v9);
if ( (a1 & 0x80000000) != 0 )
{
writeBitmapImageToArray(v10, 0LL, v8, v9, v7);
result = ((__int64 (*)(void))disp_finishUpdate)();
}
else
{
v2 = v7;
v3 = v10;
v4 = v9 >> 1;
v5 = v8 >> 1;
if ( (flags & 2) != 0 )
{
generate_image_float(a1, v10, v5, v4);
result = ((__int64 (*)(void))disp_finishUpdate)();
}
else
{
generate_image(a1, v10, v5, v4);
result = disp_finishUpdate(a1, v3, v2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 v2; // rdi
__int64 v3; // rsi
__int64 v4; // rcx
__int64 v5; // rdx
__int64 result; // rax
unsigned int v7; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned int v8; // [rsp+10h] [rbp-18h] BYREF
unsigned int v9; // [rsp+14h] [rbp-14h] BYREF
__int64 v10; // [rsp+18h] [rbp-10h] BYREF

disp_beginUpdate(&v10, &v7, &v8, &v9);
if ( (a1 & 0x80000000) != 0 )
{
writeBitmapImageToArray(v10, 0LL, v8, v9, v7);
result = ((__int64 (*)(void))disp_finishUpdate)();
}
else
{
v2 = v7;
v3 = v10;
v4 = v9 >> 1;
v5 = v8 >> 1;
if ( (flags & 2) != 0 )
{
generate_image_float(a1, v10, v5, v4);
result = ((__int64 (*)(void))disp_finishUpdate)();
}
else
{
generate_image(a1, v10, v5, v4);
result = disp_finishUpdate(a1, v3, v2);
}
}
return result;
}

original_code:
static void draw(int which) {
  UCHAR *buf_graf;
  unsigned int buf_graf_stride, width, height;
  disp_beginUpdate(&buf_graf, &buf_graf_stride, &width, &height);
  if (which < 0) {
    writeBitmapImageToArray(buf_graf, 0, width, height,
                            buf_graf_stride);
  } else {
    if (flags & 2) {
      generate_image_float(which,
                           buf_graf, width/2, height/2, width, height,
                           256, buf_graf_stride, flags & 4);
    } else {
      generate_image(which,
                     buf_graf, width/2, height/2, width, height,
                     256, buf_graf_stride);
    }
  }
  disp_finishUpdate();
}

canonical_original_code:
static void draw(int which) {
  unsigned char *buf_graf;
  unsigned int buf_graf_stride; unsigned int width; unsigned int height;
  disp_beginUpdate(&buf_graf, &buf_graf_stride, &width, &height);
  if (which < 0) {
    writeBitmapImageToArray(buf_graf, 0, width, height,
                            buf_graf_stride);
  } else {
    if (flags & 2) {
      generate_image_float(which,
                           buf_graf, width/2, height/2, width, height,
                           256, buf_graf_stride, flags & 4);
    } else {
      generate_image(which,
                     buf_graf, width/2, height/2, width, height,
                     256, buf_graf_stride);
    }
  }
  disp_finishUpdate();
}

variable_types: which int

variable_types:
width
unsigned int

variable_types:
height
unsigned int


decompiled_code:
__int64 drawing_main()
{
int v0; // ebp
unsigned int v1; // ebx

v0 = -1;
if ( (flags & 1) == 0 )
v0 = imageFuncList[imageFuncListIndex];
v1 = v0;
while ( 1 )
{
draw(v1);
SDL_mutexP(draw_mtx);
drawdone = 1;
SDL_CondSignal(drawdone_cond);
while ( !drawnext )
SDL_CondWait(drawnext_cond, draw_mtx);
drawnext = 0;
SDL_mutexV(draw_mtx);
if ( quit_draw )
break;
if ( redraw_same )
{
redraw_same = 0;
v1 = v0;
}
else
{
draw_advance();
v0 = v1;
v1 = imageFuncList[imageFuncListIndex];
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // ebp
unsigned int v1; // ebx

v0 = -1;
if ( (flags & 1) == 0 )
v0 = imageFuncList[imageFuncListIndex];
v1 = v0;
while ( 1 )
{
func2(v1);
SDL_mutexP(draw_mtx);
drawdone = 1;
SDL_CondSignal(drawdone_cond);
while ( !drawnext )
SDL_CondWait(drawnext_cond, draw_mtx);
drawnext = 0;
SDL_mutexV(draw_mtx);
if ( quit_draw )
break;
if ( redraw_same )
{
redraw_same = 0;
v1 = v0;
}
else
{
func1();
v0 = v1;
v1 = imageFuncList[imageFuncListIndex];
}
}
return 0LL;
}

original_code:
static int drawing_main(void *param) {
  int displayed_img;
  int draw_img = (flags & 1) ? -1 : imageFuncList[imageFuncListIndex];
  displayed_img = draw_img;
  while (1) {
    draw(draw_img);
    SDL_mutexP(draw_mtx);
    drawdone = SDL_TRUE;
    SDL_CondSignal(drawdone_cond);
    while (!drawnext) {
      SDL_CondWait(drawnext_cond, draw_mtx);
    }
    drawnext = SDL_FALSE;
    SDL_mutexV(draw_mtx);
    if (quit_draw) break;
    if (redraw_same) {
      draw_img = displayed_img;
      redraw_same = 0;
    } else {
      draw_advance();
      displayed_img = draw_img;
      draw_img = imageFuncList[imageFuncListIndex];
    }
  }
  return 0;
}

variable_types:
param
void *


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

if ( drawing_thread )
{
SDL_mutexP(draw_mtx);
for ( ; !drawdone; abort_draw = 0 )
{
abort_draw = 1;
SDL_CondWait(drawdone_cond, draw_mtx);
}
result = SDL_mutexV(draw_mtx);
}
return result;
}

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

if ( drawing_thread )
{
SDL_mutexP(draw_mtx);
for ( ; !drawdone; abort_draw = 0 )
{
abort_draw = 1;
SDL_CondWait(drawdone_cond, draw_mtx);
}
result = SDL_mutexV(draw_mtx);
}
return result;
}

original_code:
void draw_abort(void) {
  if (drawing_thread != ((void *)0)) {
    SDL_mutexP(draw_mtx);
    while (!drawdone) {
      abort_draw = 1;
      SDL_CondWait(drawdone_cond, draw_mtx);
      abort_draw = 0;
    }
    SDL_mutexV(draw_mtx);
  }
}

canonical_original_code:
void draw_abort() {
  if (drawing_thread != ((void *)0)) {
    SDL_mutexP(draw_mtx);
    while (!drawdone) {
      abort_draw = 1;
      SDL_CondWait(drawdone_cond, draw_mtx);
      abort_draw = 0;
    }
    SDL_mutexV(draw_mtx);
  }
}


decompiled_code:
__int64 draw_next()
{
SDL_mutexP(draw_mtx);
while ( !drawdone )
SDL_CondWait(drawdone_cond, draw_mtx);
disp_swapBuffers();
drawnext = 1;
drawdone = 0;
SDL_CondSignal(drawnext_cond);
return SDL_mutexV(draw_mtx);
}

canonical_decompiled_code:
__int64 func5()
{
SDL_mutexP(draw_mtx);
while ( !drawdone )
SDL_CondWait(drawdone_cond, draw_mtx);
disp_swapBuffers();
drawnext = 1;
drawdone = 0;
SDL_CondSignal(drawnext_cond);
return SDL_mutexV(draw_mtx);
}

original_code:
void draw_next(void) {
  SDL_mutexP(draw_mtx);
  while (!drawdone) {
    SDL_CondWait(drawdone_cond, draw_mtx);
  }
  disp_swapBuffers();
  drawnext = SDL_TRUE;
  drawdone = SDL_FALSE;
  SDL_CondSignal(drawnext_cond);
  SDL_mutexV(draw_mtx);
}

canonical_original_code:
void draw_next() {
  SDL_mutexP(draw_mtx);
  while (!drawdone) {
    SDL_CondWait(drawdone_cond, draw_mtx);
  }
  disp_swapBuffers();
  drawnext = SDL_TRUE;
  drawdone = SDL_FALSE;
  SDL_CondSignal(drawnext_cond);
  SDL_mutexV(draw_mtx);
}


decompiled_code:
__int64 draw_same()
{
redraw_same = 1;
draw_continue();
return draw_next();
}

canonical_decompiled_code:
__int64 func6()
{
redraw_same = 1;
func0();
return func5();
}

original_code:
void draw_same(void) {
  redraw_same = 1;
  draw_continue();
  draw_next();
}

canonical_original_code:
void draw_same() {
  redraw_same = 1;
  draw_continue();
  draw_next();
}


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

flags = a1;
makeShuffledList(imageFuncList, 40LL);
abort_draw = 0;
quit_draw = 0;
draw_mtx = SDL_CreateMutex();
if ( !draw_mtx || (drawdone_cond = SDL_CreateCond()) == 0 || (drawnext_cond = SDL_CreateCond()) == 0 )
fatalSDLError("creating drawing synchronization primitives");
result = SDL_CreateThread(drawing_main, 0LL);
drawing_thread = result;
if ( !result )
result = fatalSDLError("creating drawing thread");
return result;
}

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

flags = a1;
makeShuffledList(imageFuncList, 40LL);
abort_draw = 0;
quit_draw = 0;
draw_mtx = SDL_CreateMutex();
if ( !draw_mtx || (drawdone_cond = SDL_CreateCond()) == 0 || (drawnext_cond = SDL_CreateCond()) == 0 )
fatalSDLError("creating drawing synchronization primitives");
result = SDL_CreateThread(drawing_main, 0LL);
drawing_thread = result;
if ( !result )
result = fatalSDLError("creating drawing thread");
return result;
}

original_code:
void draw_init(int draw_flags) {
  flags = draw_flags;
  makeShuffledList(imageFuncList, 40);
  abort_draw = 0;
  quit_draw = 0;
  if (!(draw_mtx = SDL_CreateMutex()) ||
      !(drawdone_cond = SDL_CreateCond()) ||
      !(drawnext_cond = SDL_CreateCond()))
    fatalSDLError("creating drawing synchronization primitives");
  drawing_thread = SDL_CreateThread(drawing_main,
                                    ((void *)0));
  if (drawing_thread == ((void *)0))
    fatalSDLError("creating drawing thread");
}


decompiled_code:
__int64 draw_quit()
{
__int64 result; // rax
char v1[12]; // [rsp+Ch] [rbp-Ch] BYREF

if ( drawing_thread )
{
quit_draw = 1;
draw_abort();
draw_continue();
result = SDL_WaitThread(drawing_thread, v1);
drawing_thread = 0LL;
}
if ( drawdone_cond )
{
result = SDL_DestroyCond();
drawdone_cond = 0LL;
}
if ( drawnext_cond )
{
result = SDL_DestroyCond();
drawnext_cond = 0LL;
}
if ( draw_mtx )
{
result = SDL_DestroyMutex();
draw_mtx = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
char v1[12]; // [rsp+Ch] [rbp-Ch] BYREF

if ( drawing_thread )
{
quit_draw = 1;
func4();
func0();
result = SDL_WaitThread(drawing_thread, v1);
drawing_thread = 0LL;
}
if ( drawdone_cond )
{
result = SDL_DestroyCond();
drawdone_cond = 0LL;
}
if ( drawnext_cond )
{
result = SDL_DestroyCond();
drawnext_cond = 0LL;
}
if ( draw_mtx )
{
result = SDL_DestroyMutex();
draw_mtx = 0LL;
}
return result;
}

original_code:
void draw_quit(void) {
  if (drawing_thread != ((void *)0)) {
    int status;
    quit_draw = 1;
    draw_abort();
    draw_continue();
    SDL_WaitThread(drawing_thread, &status);
    drawing_thread = ((void *)0);
  }
  if (drawdone_cond != ((void *)0)) {
    SDL_DestroyCond(drawdone_cond);
    drawdone_cond = ((void *)0);
  }
  if (drawnext_cond != ((void *)0)) {
    SDL_DestroyCond(drawnext_cond);
    drawnext_cond = ((void *)0);
  }
  if (draw_mtx != ((void *)0)) {
    SDL_DestroyMutex(draw_mtx);
    draw_mtx = ((void *)0);
  }
}

canonical_original_code:
void draw_quit() {
  if (drawing_thread != ((void *)0)) {
    int status;
    quit_draw = 1;
    draw_abort();
    draw_continue();
    SDL_WaitThread(drawing_thread, &status);
    drawing_thread = ((void *)0);
  }
  if (drawdone_cond != ((void *)0)) {
    SDL_DestroyCond(drawdone_cond);
    drawdone_cond = ((void *)0);
  }
  if (drawnext_cond != ((void *)0)) {
    SDL_DestroyCond(drawnext_cond);
    drawnext_cond = ((void *)0);
  }
  if (draw_mtx != ((void *)0)) {
    SDL_DestroyMutex(draw_mtx);
    draw_mtx = ((void *)0);
  }
}

variable_types: status int