decompiled_code:
float __fastcall dot_product(double a1, double a2)
{
return (float)(*((float *)&a1 + 1) * *((float *)&a2 + 1)) + (float)(*(float *)&a1 * *(float *)&a2);
}

canonical_decompiled_code:
float __fastcall func3(double a1, double a2)
{
return (float)(*((float *)&a1 + 1) * *((float *)&a2 + 1)) + (float)(*(float *)&a1 * *(float *)&a2);
}

original_code:
float dot_product(Point A, Point B) {
    return A.x * B.x + A.y * B.y;
}

canonical_original_code:
float dot_product(struct Point A, struct Point B) {
    return A.x * B.x + A.y * B.y;
}

variable_types:
A
struct Point { float x; float y; }


repo: onesuper/blasteroid

decompiled_code:
float __fastcall max_in2(float a1, float a2)
{
return fmaxf(a1, a2);
}

canonical_decompiled_code:
float __fastcall func4(float a1, float a2)
{
return fmaxf(a1, a2);
}

original_code:
float max_in2(float a, float b) {
    return (a > b) ? a : b;
}

variable_types: a float

variable_types: b float

return_type: float


decompiled_code:
float __fastcall min_in2(float a1, float a2)
{
return fminf(a1, a2);
}

canonical_decompiled_code:
float __fastcall func5(float a1, float a2)
{
return fminf(a1, a2);
}

original_code:
float min_in2(float a, float b) {
    return (a < b) ? a : b;
}


decompiled_code:
float __fastcall max_in4(float a1, float a2, float a3, float a4)
{
float v4; // xmm1_4
float v6; // [rsp+4h] [rbp-Ch]

v6 = max_in2(a1, a2);
v4 = max_in2(a3, a4);
return max_in2(v6, v4);
}

canonical_decompiled_code:
float __fastcall func6(float a1, float a2, float a3, float a4)
{
float v4; // xmm1_4
float v6; // [rsp+4h] [rbp-Ch]

v6 = func4(a1, a2);
v4 = func4(a3, a4);
return func4(v6, v4);
}

original_code:
float max_in4(float a, float b, float c, float d) {
    float ab = max_in2(a, b);
    float cd = max_in2(c, d);
    return max_in2(ab, cd);
}

variable_types: c float

variable_types: d float

variable_types: ab float

variable_types: cd float


decompiled_code:
float __fastcall min_in4(float a1, float a2, float a3, float a4)
{
float v4; // xmm1_4
float v6; // [rsp+4h] [rbp-Ch]

v6 = min_in2(a1, a2);
v4 = min_in2(a3, a4);
return min_in2(v6, v4);
}

canonical_decompiled_code:
float __fastcall func7(float a1, float a2, float a3, float a4)
{
float v4; // xmm1_4
float v6; // [rsp+4h] [rbp-Ch]

v6 = func5(a1, a2);
v4 = func5(a3, a4);
return func5(v6, v4);
}

original_code:
float min_in4(float a, float b, float c, float d) {
    float ab = min_in2(a, b);
    float cd = min_in2(c, d);
    return min_in2(ab, cd);
}


ls

repo: onesuper/myvfs

decompiled_code:
int ls()
{
__int64 v0; // rbx
int result; // eax
const char *v2; // rbp
int v3; // ebx
unsigned __int16 v4; // [rsp+0h] [rbp-418h] BYREF
char v5[28]; // [rsp+8h] [rbp-410h] BYREF
char v6; // [rsp+24h] [rbp-3F4h] BYREF

v0 = iget(cur_dir_dinode_no);
fseek(fd, (unsigned int)(*(_DWORD *)(v0 + 32) << 10), 0);
fread(&v4, 1uLL, 0x3F4uLL, fd);
result = iput(v0);
if ( v4 )
{
printf("%s\t", v5);
v2 = &v6;
v3 = 1;
while ( 1 )
{
result = v4;
if ( v4 <= v3 )
break;
printf("%s\t", v2);
++v3;
if ( v3 == 5 * (v3 / 5) )
putchar(10);
v2 += 28;
}
if ( v4 != 5 * (v4 / 5u) )
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // rbx
int result; // eax
const char *v2; // rbp
int v3; // ebx
unsigned __int16 v4; // [rsp+0h] [rbp-418h] BYREF
char v5[28]; // [rsp+8h] [rbp-410h] BYREF
char v6; // [rsp+24h] [rbp-3F4h] BYREF

v0 = iget(cur_dir_dinode_no);
fseek(fd, (unsigned int)(*(_DWORD *)(v0 + 32) << 10), 0);
fread(&v4, 1uLL, 0x3F4uLL, fd);
result = iput(v0);
if ( v4 )
{
printf("%s\t", v5);
v2 = &v6;
v3 = 1;
while ( 1 )
{
result = v4;
if ( v4 <= v3 )
break;
printf("%s\t", v2);
++v3;
if ( v3 == 5 * (v3 / 5) )
putchar(10);
v2 += 28;
}
if ( v4 != 5 * (v4 / 5u) )
result = putchar(10);
}
return result;
}

original_code:
void ls(void) {
 struct directory_t dir;
 struct inode_t* pinode= iget(cur_dir_dinode_no);
 fseek(fd, pinode->addr[0] * 1024, 0);
 fread(&dir, 1, sizeof(dir), fd);
 iput(pinode);
 int i;
 for (i=0; i<dir.size; i++) {
  printf("%s\t", dir.files[i].name);
  if (((i + 1) % 5) == 0)
   printf("\n");
 }
 if ((dir.size % 5) != 0)
  printf("\n");
 return;
}

canonical_original_code:
void ls() {
 struct directory_t dir;
 struct inode_t *pinode = iget(cur_dir_dinode_no);
 fseek(fd, pinode->addr[0] * 1024, 0);
 fread(&dir, 1, sizeof(dir), fd);
 iput(pinode);
 int i;
 for (i=0; i<dir.size; i++) {
  printf("%s\t", dir.files[i].name);
  if (((i + 1) % 5) == 0)
   printf("\n");
 }
 if ((dir.size % 5) != 0)
  printf("\n");
 return;
}

variable_types: struct directory_t { unsigned short size; struct file_t { unsigned int dino; char name[24]; } files[36]; }

variable_types: struct inode_t { struct inode_t *forward; struct inode_t *backward; unsigned int count; unsigned short flag; char type; unsigned int dino; unsigned int size; unsigned int addr[50]; } *

variable_types: i int

return_type: void

user_defined_types: struct directory_t { unsigned short size; struct file_t files[36]; }


cd

decompiled_code:
int cd()
{
unsigned int v0; // eax
unsigned int v1; // ebx
__int64 v2; // rax
_DWORD *v3; // rax

v0 = namei();
if ( v0 && (v1 = v0, (v2 = iget(v0)) != 0) )
{
if ( *(_BYTE *)(v2 + 22) == 100 )
{
v3 = &cur_dir_dinode_no;
cur_dir_dinode_no = v1;
}
else
{
LODWORD(v3) = puts("Not a directory");
}
}
else
{
LODWORD(v3) = puts("No such file or directory");
}
return (int)v3;
}

canonical_decompiled_code:
int func1()
{
unsigned int v0; // eax
unsigned int v1; // ebx
__int64 v2; // rax
_DWORD *v3; // rax

v0 = namei();
if ( v0 && (v1 = v0, (v2 = iget(v0)) != 0) )
{
if ( *(_BYTE *)(v2 + 22) == 100 )
{
v3 = &cur_dir_dinode_no;
cur_dir_dinode_no = v1;
}
else
{
LODWORD(v3) = puts("Not a directory");
}
}
else
{
LODWORD(v3) = puts("No such file or directory");
}
return (int)v3;
}

original_code:
void cd(const char* pathname) {
 int dinode_no = namei(pathname);
 if (dinode_no == 0) {
  printf("No such file or directory\n");
  return;
 }
 struct inode_t* pinode = iget(dinode_no);
 if (pinode == ((void *)0)) {
  printf("No such file or directory\n");
  return;
 }
 if (pinode->type != 'd') {
  printf("Not a directory\n");
  return;
 }
 cur_dir_dinode_no = dinode_no;
 return;
}

canonical_original_code:
void cd(char *pathname) {
 int dinode_no = namei(pathname);
 if (dinode_no == 0) {
  printf("No such file or directory\n");
  return;
 }
 struct inode_t *pinode = iget(dinode_no);
 if (pinode == ((void *)0)) {
  printf("No such file or directory\n");
  return;
 }
 if (pinode->type != 'd') {
  printf("Not a directory\n");
  return;
 }
 cur_dir_dinode_no = dinode_no;
 return;
}

variable_types:
pathname
char *

user_defined_types: struct inode_t { struct inode_t *forward; struct inode_t *backward; unsigned int count; unsigned short flag; char type; unsigned int dino; unsigned int size; unsigned int addr[50]; }


mkdir

decompiled_code:
int __fastcall mkdir(char *src)
{
int result; // eax
unsigned int v2; // ebp
__int64 v3; // r12
int v4; // ebp
__int64 v5; // rbx
unsigned __int16 v6; // ax
unsigned __int16 *v7; // rdx
unsigned __int16 v8[512]; // [rsp+0h] [rbp-848h] BYREF
char dest[16]; // [rsp+400h] [rbp-448h] BYREF
__int64 v10; // [rsp+410h] [rbp-438h]
int v11; // [rsp+418h] [rbp-430h]
__int16 ptr[2]; // [rsp+420h] [rbp-428h] BYREF
int v13; // [rsp+424h] [rbp-424h]
char v14[8]; // [rsp+428h] [rbp-420h] BYREF

if ( (unsigned int)namei() )
return puts("File or directory exists");
ptr[0] = 1;
strcpy(v14, "..");
v13 = cur_dir_dinode_no;
result = balloc();
v2 = result;
if ( result )
{
v3 = ialloc();
if ( v3 )
{
fseek(fd, v2 << 10, 0);
fwrite(ptr, 1uLL, 0x3F4uLL, fd);
*(_DWORD *)(v3 + 28) = 1;
*(_DWORD *)(v3 + 32) = v2;
*(_BYTE *)(v3 + 22) = 100;
v4 = *(_DWORD *)(v3 + 24);
iput(v3);
strcpy(&dest[4], src);
*(_DWORD *)dest = v4;
v5 = iget((unsigned int)cur_dir_dinode_no);
fseek(fd, (unsigned int)(*(_DWORD *)(v5 + 32) << 10), 0);
fread(v8, 1uLL, 0x3F4uLL, fd);
v6 = v8[0];
v7 = &v8[14 * v8[0]];
*(__m128i *)(v7 + 2) = _mm_loadu_si128((const __m128i *)dest);
*(_QWORD *)(v7 + 10) = v10;
*((_DWORD *)v7 + 7) = v11;
v8[0] = v6 + 1;
fseek(fd, (unsigned int)(*(_DWORD *)(v5 + 32) << 10), 0);
fwrite(v8, 1uLL, 0x3F4uLL, fd);
result = iput(v5);
}
else
{
result = bfree(v2);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *src)
{
int result; // eax
unsigned int v2; // ebp
__int64 v3; // r12
int v4; // ebp
__int64 v5; // rbx
unsigned __int16 v6; // ax
unsigned __int16 *v7; // rdx
unsigned __int16 v8[512]; // [rsp+0h] [rbp-848h] BYREF
char dest[16]; // [rsp+400h] [rbp-448h] BYREF
__int64 v10; // [rsp+410h] [rbp-438h]
int v11; // [rsp+418h] [rbp-430h]
__int16 ptr[2]; // [rsp+420h] [rbp-428h] BYREF
int v13; // [rsp+424h] [rbp-424h]
char v14[8]; // [rsp+428h] [rbp-420h] BYREF

if ( (unsigned int)namei() )
return puts("File or directory exists");
ptr[0] = 1;
strcpy(v14, "..");
v13 = cur_dir_dinode_no;
result = balloc();
v2 = result;
if ( result )
{
v3 = ialloc();
if ( v3 )
{
fseek(fd, v2 << 10, 0);
fwrite(ptr, 1uLL, 0x3F4uLL, fd);
*(_DWORD *)(v3 + 28) = 1;
*(_DWORD *)(v3 + 32) = v2;
*(_BYTE *)(v3 + 22) = 100;
v4 = *(_DWORD *)(v3 + 24);
iput(v3);
strcpy(&dest[4], src);
*(_DWORD *)dest = v4;
v5 = iget((unsigned int)cur_dir_dinode_no);
fseek(fd, (unsigned int)(*(_DWORD *)(v5 + 32) << 10), 0);
fread(v8, 1uLL, 0x3F4uLL, fd);
v6 = v8[0];
v7 = &v8[14 * v8[0]];
*(__m128i *)(v7 + 2) = _mm_loadu_si128((const __m128i *)dest);
*(_QWORD *)(v7 + 10) = v10;
*((_DWORD *)v7 + 7) = v11;
v8[0] = v6 + 1;
fseek(fd, (unsigned int)(*(_DWORD *)(v5 + 32) << 10), 0);
fwrite(v8, 1uLL, 0x3F4uLL, fd);
result = iput(v5);
}
else
{
result = bfree(v2);
}
}
return result;
}

original_code:
void mkdir(const char* pathname) {
 unsigned int dinode_no = namei(pathname);
 if (dinode_no != 0) {
  printf("File or directory exists\n");
  return;
 }
 struct directory_t dir;
 dir.size = 1;
 strcpy(dir.files[0].name, "..");
 dir.files[0].dino = cur_dir_dinode_no;
 unsigned int block_no = balloc();
 if (block_no == 0)
  return;
 struct inode_t* pinode = ialloc();
 if (pinode == ((void *)0)) {
  bfree(block_no);
  return;
 }
 unsigned int new_dinode_no;
 fseek(fd, block_no * 1024, 0);
 fwrite(&dir, 1, sizeof(dir), fd);
 pinode->size = 1;
 pinode->addr[0] = block_no;
 pinode->type = 'd';
 new_dinode_no = pinode->dino;
 iput(pinode);
 struct file_t file;
 strcpy(file.name, pathname);
 file.dino = new_dinode_no;
 struct directory_t dir_cur;
 struct inode_t *pinode_cur = iget(cur_dir_dinode_no);
 fseek(fd, pinode_cur->addr[0] * 1024, 0);
 fread(&dir_cur, 1, sizeof(dir_cur), fd);
 dir_cur.files[dir_cur.size] = file;
 dir_cur.size ++;
 fseek(fd, pinode_cur->addr[0] * 1024, 0);
 fwrite(&dir_cur, 1, sizeof(dir_cur), fd);
 iput(pinode_cur);
 return;
}

canonical_original_code:
void mkdir(char *pathname) {
 unsigned int dinode_no = namei(pathname);
 if (dinode_no != 0) {
  printf("File or directory exists\n");
  return;
 }
 struct directory_t dir;
 dir.size = 1;
 strcpy(dir.files[0].name, "..");
 dir.files[0].dino = cur_dir_dinode_no;
 unsigned int block_no = balloc();
 if (block_no == 0)
  return;
 struct inode_t *pinode = ialloc();
 if (pinode == ((void *)0)) {
  bfree(block_no);
  return;
 }
 unsigned int new_dinode_no;
 fseek(fd, block_no * 1024, 0);
 fwrite(&dir, 1, sizeof(dir), fd);
 pinode->size = 1;
 pinode->addr[0] = block_no;
 pinode->type = 'd';
 new_dinode_no = pinode->dino;
 iput(pinode);
 struct file_t file;
 strcpy(file.name, pathname);
 file.dino = new_dinode_no;
 struct directory_t dir_cur;
 struct inode_t *pinode_cur = iget(cur_dir_dinode_no);
 fseek(fd, pinode_cur->addr[0] * 1024, 0);
 fread(&dir_cur, 1, sizeof(dir_cur), fd);
 dir_cur.files[dir_cur.size] = file;
 dir_cur.size ++;
 fseek(fd, pinode_cur->addr[0] * 1024, 0);
 fwrite(&dir_cur, 1, sizeof(dir_cur), fd);
 iput(pinode_cur);
 return;
}

variable_types: struct file_t { unsigned int dino; char name[24]; }


touch

decompiled_code:
int __fastcall touch(char *src)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rbx
unsigned __int16 v4; // ax
unsigned __int16 *v5; // rdx
unsigned __int16 v7[512]; // [rsp+0h] [rbp-438h] BYREF
char dest[16]; // [rsp+400h] [rbp-38h] BYREF
__int64 v9; // [rsp+410h] [rbp-28h]
int v10; // [rsp+418h] [rbp-20h]

if ( (unsigned int)namei() )
{
LODWORD(v1) = puts("File or directory exists");
}
else
{
v1 = ialloc();
v2 = v1;
if ( v1 )
{
*(_DWORD *)(v1 + 28) = 0;
*(_BYTE *)(v1 + 22) = 102;
strcpy(&dest[4], src);
*(_DWORD *)dest = *(_DWORD *)(v2 + 24);
iput(v2);
v3 = iget((unsigned int)cur_dir_dinode_no);
fseek(fd, (unsigned int)(*(_DWORD *)(v3 + 32) << 10), 0);
fread(v7, 1uLL, 0x3F4uLL, fd);
v4 = v7[0];
v5 = &v7[14 * v7[0]];
*(__m128i *)(v5 + 2) = _mm_loadu_si128((const __m128i *)dest);
*(_QWORD *)(v5 + 10) = v9;
*((_DWORD *)v5 + 7) = v10;
v7[0] = v4 + 1;
fseek(fd, (unsigned int)(*(_DWORD *)(v3 + 32) << 10), 0);
fwrite(v7, 1uLL, 0x3F4uLL, fd);
LODWORD(v1) = iput(v3);
}
}
return v1;
}

canonical_decompiled_code:
int __fastcall func3(char *src)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rbx
unsigned __int16 v4; // ax
unsigned __int16 *v5; // rdx
unsigned __int16 v7[512]; // [rsp+0h] [rbp-438h] BYREF
char dest[16]; // [rsp+400h] [rbp-38h] BYREF
__int64 v9; // [rsp+410h] [rbp-28h]
int v10; // [rsp+418h] [rbp-20h]

if ( (unsigned int)namei() )
{
LODWORD(v1) = puts("File or directory exists");
}
else
{
v1 = ialloc();
v2 = v1;
if ( v1 )
{
*(_DWORD *)(v1 + 28) = 0;
*(_BYTE *)(v1 + 22) = 102;
strcpy(&dest[4], src);
*(_DWORD *)dest = *(_DWORD *)(v2 + 24);
iput(v2);
v3 = iget((unsigned int)cur_dir_dinode_no);
fseek(fd, (unsigned int)(*(_DWORD *)(v3 + 32) << 10), 0);
fread(v7, 1uLL, 0x3F4uLL, fd);
v4 = v7[0];
v5 = &v7[14 * v7[0]];
*(__m128i *)(v5 + 2) = _mm_loadu_si128((const __m128i *)dest);
*(_QWORD *)(v5 + 10) = v9;
*((_DWORD *)v5 + 7) = v10;
v7[0] = v4 + 1;
fseek(fd, (unsigned int)(*(_DWORD *)(v3 + 32) << 10), 0);
fwrite(v7, 1uLL, 0x3F4uLL, fd);
LODWORD(v1) = iput(v3);
}
}
return v1;
}

original_code:
void touch(const char* pathname) {
 unsigned int dinode_no = namei(pathname);
 if (dinode_no != 0) {
  printf("File or directory exists\n");
  return;
 }
 struct inode_t *pinode = ialloc();
 if (pinode == ((void *)0))
  return;
 pinode->size = 0;
 pinode->type = 'f';
 struct file_t file;
 strcpy(file.name, pathname);
 file.dino = pinode->dino;
 iput(pinode);
 pinode = iget(cur_dir_dinode_no);
 struct directory_t dir;
 fseek(fd, pinode->addr[0] * 1024, 0);
 fread(&dir, 1, sizeof(dir), fd);
 dir.files[dir.size] = file;
 dir.size ++;
 fseek(fd, pinode->addr[0] * 1024, 0);
 fwrite(&dir, 1, sizeof(dir), fd);
 iput(pinode);
 return;
}

canonical_original_code:
void touch(char *pathname) {
 unsigned int dinode_no = namei(pathname);
 if (dinode_no != 0) {
  printf("File or directory exists\n");
  return;
 }
 struct inode_t *pinode = ialloc();
 if (pinode == ((void *)0))
  return;
 pinode->size = 0;
 pinode->type = 'f';
 struct file_t file;
 strcpy(file.name, pathname);
 file.dino = pinode->dino;
 iput(pinode);
 pinode = iget(cur_dir_dinode_no);
 struct directory_t dir;
 fseek(fd, pinode->addr[0] * 1024, 0);
 fread(&dir, 1, sizeof(dir), fd);
 dir.files[dir.size] = file;
 dir.size ++;
 fseek(fd, pinode->addr[0] * 1024, 0);
 fwrite(&dir, 1, sizeof(dir), fd);
 iput(pinode);
 return;
}

user_defined_types: struct file_t { unsigned int dino; char name[24]; }


rm

decompiled_code:
int rm()
{
unsigned int v0; // eax
unsigned int v1; // ebx
__int64 v2; // rax
__int64 v3; // rbp
int result; // eax
char *v5; // rax
__int64 v6; // rbp
__int16 v7; // si
_DWORD *v8; // rdx
int v9; // eax
__int16 *v10; // rdx
__int16 *v11; // rax
__int64 v12; // r12
__int64 v13; // rbp
__int16 v14[2]; // [rsp+0h] [rbp-418h] BYREF
_DWORD v15[261]; // [rsp+4h] [rbp-414h] BYREF

v0 = namei();
if ( !v0 )
return puts("No such file or directory");
v1 = v0;
v2 = iget(v0);
v3 = v2;
if ( *(_BYTE *)(v2 + 22) == 102 )
{
iput(v2);
v5 = (char *)&open_file + 4;
do
{
if ( *(_DWORD *)v5 && *(_DWORD *)(*(_QWORD *)(v5 + 4) + 24LL) == v1 )
return puts("the file is already opened");
v5 += 24;
}
while ( v5 != (char *)&open_file + 2404 );
v6 = iget((unsigned int)cur_dir_dinode_no);
fseek(fd, (unsigned int)(*(_DWORD *)(v6 + 32) << 10), 0);
fread(v14, 1uLL, 0x3F4uLL, fd);
v7 = v14[0];
if ( v14[0] )
{
v8 = v15;
v9 = 0;
while ( *v8 != v1 )
{
++v9;
v8 += 7;
if ( v9 == (unsigned __int16)v14[0] )
goto LABEL_16;
}
--v14[0];
v10 = &v14[14 * v9];
v11 = &v14[14 * (unsigned __int16)(v7 - 1)];
*(__m128i *)(v10 + 2) = _mm_loadu_si128((const __m128i *)&v15[7 * (unsigned __int16)(v7 - 1)]);
*(_QWORD *)(v10 + 10) = *(_QWORD *)(v11 + 10);
*((_DWORD *)v10 + 7) = *((_DWORD *)v11 + 7);
}
LABEL_16:
fseek(fd, (unsigned int)(*(_DWORD *)(v6 + 32) << 10), 0);
fwrite(v14, 1uLL, 0x3F4uLL, fd);
iput(v6);
v12 = iget(v1);
if ( *(_DWORD *)(v12 + 28) )
{
v13 = 0LL;
do
bfree(*(unsigned int *)(v12 + 4 * v13++ + 32));
while ( *(_DWORD *)(v12 + 28) > (unsigned int)v13 );
}
iput(v12);
result = ifree(v1);
}
else
{
puts("Is a directory");
result = iput(v3);
}
return result;
}

canonical_decompiled_code:
int func4()
{
unsigned int v0; // eax
unsigned int v1; // ebx
__int64 v2; // rax
__int64 v3; // rbp
int result; // eax
char *v5; // rax
__int64 v6; // rbp
__int16 v7; // si
_DWORD *v8; // rdx
int v9; // eax
__int16 *v10; // rdx
__int16 *v11; // rax
__int64 v12; // r12
__int64 v13; // rbp
__int16 v14[2]; // [rsp+0h] [rbp-418h] BYREF
_DWORD v15[261]; // [rsp+4h] [rbp-414h] BYREF

v0 = namei();
if ( !v0 )
return puts("No such file or directory");
v1 = v0;
v2 = iget(v0);
v3 = v2;
if ( *(_BYTE *)(v2 + 22) == 102 )
{
iput(v2);
v5 = (char *)&open_file + 4;
do
{
if ( *(_DWORD *)v5 && *(_DWORD *)(*(_QWORD *)(v5 + 4) + 24LL) == v1 )
return puts("the file is already opened");
v5 += 24;
}
while ( v5 != (char *)&open_file + 2404 );
v6 = iget((unsigned int)cur_dir_dinode_no);
fseek(fd, (unsigned int)(*(_DWORD *)(v6 + 32) << 10), 0);
fread(v14, 1uLL, 0x3F4uLL, fd);
v7 = v14[0];
if ( v14[0] )
{
v8 = v15;
v9 = 0;
while ( *v8 != v1 )
{
++v9;
v8 += 7;
if ( v9 == (unsigned __int16)v14[0] )
goto LABEL_16;
}
--v14[0];
v10 = &v14[14 * v9];
v11 = &v14[14 * (unsigned __int16)(v7 - 1)];
*(__m128i *)(v10 + 2) = _mm_loadu_si128((const __m128i *)&v15[7 * (unsigned __int16)(v7 - 1)]);
*(_QWORD *)(v10 + 10) = *(_QWORD *)(v11 + 10);
*((_DWORD *)v10 + 7) = *((_DWORD *)v11 + 7);
}
LABEL_16:
fseek(fd, (unsigned int)(*(_DWORD *)(v6 + 32) << 10), 0);
fwrite(v14, 1uLL, 0x3F4uLL, fd);
iput(v6);
v12 = iget(v1);
if ( *(_DWORD *)(v12 + 28) )
{
v13 = 0LL;
do
bfree(*(unsigned int *)(v12 + 4 * v13++ + 32));
while ( *(_DWORD *)(v12 + 28) > (unsigned int)v13 );
}
iput(v12);
result = ifree(v1);
}
else
{
puts("Is a directory");
result = iput(v3);
}
return result;
}

original_code:
void rm(const char* pathname) {
 unsigned int dinode_no = namei(pathname);
 if (dinode_no == 0) {
  printf("No such file or directory\n");
  return;
 }
 struct inode_t* pinode = iget(dinode_no);
 if (pinode->type != 'f') {
  printf("Is a directory\n");
  iput(pinode);
  return;
 }
 iput(pinode);
 int i;
 for (i=0; i<100; i++) {
  if (open_file[i].count > 0 && open_file[i].pinode->dino == dinode_no) {
   printf("the file is already opened\n");
   return;
  }
 }
 pinode = iget(cur_dir_dinode_no);
 struct directory_t dir;
 fseek(fd, pinode->addr[0] * 1024, 0);
 fread(&dir, 1, sizeof(dir), fd);
 for (i=0; i<dir.size; i++) {
  if (dir.files[i].dino == dinode_no) {
   dir.size--;
   dir.files[i] = dir.files[dir.size];
   break;
  }
 }
 fseek(fd, pinode->addr[0] * 1024, 0);
 fwrite(&dir, 1, sizeof(dir), fd);
 iput(pinode);
 pinode = iget(dinode_no);
 for (i=0; i<pinode->size; i++) {
  bfree(pinode->addr[i]);
 }
 iput(pinode);
 ifree(dinode_no);
 return;
}

canonical_original_code:
void rm(char *pathname) {
 unsigned int dinode_no = namei(pathname);
 if (dinode_no == 0) {
  printf("No such file or directory\n");
  return;
 }
 struct inode_t *pinode = iget(dinode_no);
 if (pinode->type != 'f') {
  printf("Is a directory\n");
  iput(pinode);
  return;
 }
 iput(pinode);
 int i;
 for (i=0; i<100; i++) {
  if (open_file[i].count > 0 && open_file[i].pinode->dino == dinode_no) {
   printf("the file is already opened\n");
   return;
  }
 }
 pinode = iget(cur_dir_dinode_no);
 struct directory_t dir;
 fseek(fd, pinode->addr[0] * 1024, 0);
 fread(&dir, 1, sizeof(dir), fd);
 for (i=0; i<dir.size; i++) {
  if (dir.files[i].dino == dinode_no) {
   dir.size--;
   dir.files[i] = dir.files[dir.size];
   break;
  }
 }
 fseek(fd, pinode->addr[0] * 1024, 0);
 fwrite(&dir, 1, sizeof(dir), fd);
 iput(pinode);
 pinode = iget(dinode_no);
 for (i=0; i<pinode->size; i++) {
  bfree(pinode->addr[i]);
 }
 iput(pinode);
 ifree(dinode_no);
 return;
}


rmdir

original_code:
void rmdir(const char* pathname) {
 if (strcmp("/", pathname) == 0)
  return;
 if (strcmp("..", pathname) == 0)
  return;
 unsigned int dinode_no = namei(pathname);
 if (dinode_no == 0) {
  printf("No such file or directory\n");
  return;
 }
 struct inode_t* pinode = iget(dinode_no);
 if (pinode->type != 'd') {
  printf("Is a file\n");
  iput(pinode);
  return;
 }
 struct directory_t dir;
 fseek(fd, pinode->addr[0] * 1024, 0);
 fread(&dir, 1, sizeof(dir), fd);
 if (dir.size > 1) {
  printf("Directory not empty\n");
  iput(pinode);
  return;
 }
 iput(pinode);
 pinode = iget(cur_dir_dinode_no);
 fseek(fd, pinode->addr[0] * 1024, 0);
 fread(&dir, 1, sizeof(dir), fd);
 int i;
 for (i=0; i<dir.size; i++) {
  if (dir.files[i].dino == dinode_no) {
   dir.size--;
   dir.files[i] = dir.files[dir.size];
   break;
  }
 }
 fseek(fd, pinode->addr[0] * 1024, 0);
 fwrite(&dir, 1, sizeof(dir), fd);
 iput(pinode);
 pinode = iget(dinode_no);
 bfree(pinode->addr[0]);
 iput(pinode);
 ifree(dinode_no);
 return;
}

canonical_original_code:
void rmdir(char *pathname) {
 if (strcmp("/", pathname) == 0)
  return;
 if (strcmp("..", pathname) == 0)
  return;
 unsigned int dinode_no = namei(pathname);
 if (dinode_no == 0) {
  printf("No such file or directory\n");
  return;
 }
 struct inode_t *pinode = iget(dinode_no);
 if (pinode->type != 'd') {
  printf("Is a file\n");
  iput(pinode);
  return;
 }
 struct directory_t dir;
 fseek(fd, pinode->addr[0] * 1024, 0);
 fread(&dir, 1, sizeof(dir), fd);
 if (dir.size > 1) {
  printf("Directory not empty\n");
  iput(pinode);
  return;
 }
 iput(pinode);
 pinode = iget(cur_dir_dinode_no);
 fseek(fd, pinode->addr[0] * 1024, 0);
 fread(&dir, 1, sizeof(dir), fd);
 int i;
 for (i=0; i<dir.size; i++) {
  if (dir.files[i].dino == dinode_no) {
   dir.size--;
   dir.files[i] = dir.files[dir.size];
   break;
  }
 }
 fseek(fd, pinode->addr[0] * 1024, 0);
 fwrite(&dir, 1, sizeof(dir), fd);
 iput(pinode);
 pinode = iget(dinode_no);
 bfree(pinode->addr[0]);
 iput(pinode);
 ifree(dinode_no);
 return;
}


mopen

decompiled_code:
__int64 mopen()
{
unsigned int v0; // eax
__int64 v1; // rbx
_DWORD *v2; // rdx
__int64 result; // rax
__int64 v4; // rdi

v0 = namei();
if ( v0 )
{
v1 = iget(v0);
if ( *(_BYTE *)(v1 + 22) == 102 )
{
v2 = (_DWORD *)((char *)&open_file + 4);
result = 0LL;
while ( *v2 )
{
result = (unsigned int)(result + 1);
v2 += 6;
if ( (_DWORD)result == 100 )
{
puts("Cannot open any more files");
return 0xFFFFFFFFLL;
}
}
v4 = 3LL * (int)result;
*((_QWORD *)&open_file + v4 + 1) = v1;
*((_DWORD *)&open_file + 2 * v4 + 1) = 1;
}
else
{
puts("Is a directory");
iput(v1);
result = 0xFFFFFFFFLL;
}
}
else
{
puts("No such file or directory");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax
__int64 v1; // rbx
_DWORD *v2; // rdx
__int64 result; // rax
__int64 v4; // rdi

v0 = namei();
if ( v0 )
{
v1 = iget(v0);
if ( *(_BYTE *)(v1 + 22) == 102 )
{
v2 = (_DWORD *)((char *)&open_file + 4);
result = 0LL;
while ( *v2 )
{
result = (unsigned int)(result + 1);
v2 += 6;
if ( (_DWORD)result == 100 )
{
puts("Cannot open any more files");
return 0xFFFFFFFFLL;
}
}
v4 = 3LL * (int)result;
*((_QWORD *)&open_file + v4 + 1) = v1;
*((_DWORD *)&open_file + 2 * v4 + 1) = 1;
}
else
{
puts("Is a directory");
iput(v1);
result = 0xFFFFFFFFLL;
}
}
else
{
puts("No such file or directory");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mopen(const char* pathname) {
 unsigned int dinode_no = namei(pathname);
 if (dinode_no == 0) {
  printf("No such file or directory\n");
  return -1;
 }
 struct inode_t* pinode = iget(dinode_no);
 if (pinode->type != 'f') {
  printf("Is a directory\n");
  iput(pinode);
  return -1;
 }
 int i;
 for (i=0; i<100; i++) {
  if (open_file[i].count == 0)
   break;
 }
 if (i == 100) {
  printf("Cannot open any more files\n");
  return -1;
 }
 open_file[i].pinode = pinode;
 open_file[i].count = 1;
 return i;
}

canonical_original_code:
int mopen(char *pathname) {
 unsigned int dinode_no = namei(pathname);
 if (dinode_no == 0) {
  printf("No such file or directory\n");
  return -1;
 }
 struct inode_t *pinode = iget(dinode_no);
 if (pinode->type != 'f') {
  printf("Is a directory\n");
  iput(pinode);
  return -1;
 }
 int i;
 for (i=0; i<100; i++) {
  if (open_file[i].count == 0)
   break;
 }
 if (i == 100) {
  printf("Cannot open any more files\n");
  return -1;
 }
 open_file[i].pinode = pinode;
 open_file[i].count = 1;
 return i;
}

return_type: int


mclose

decompiled_code:
__int64 __fastcall mclose(int a1)
{
*((_DWORD *)&open_file + 6 * a1 + 1) = 0;
return iput(*((_QWORD *)&open_file + 3 * a1 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
*((_DWORD *)&open_file + 6 * a1 + 1) = 0;
return iput(*((_QWORD *)&open_file + 3 * a1 + 1));
}

original_code:
void mclose(int file_no) {
 open_file[file_no].count = 0;
 iput(open_file[file_no].pinode);
 return;
}


mread

decompiled_code:
char *__fastcall mread(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // rbp
int v3; // edi
char *v4; // r14
char *v6; // r12
__int64 v7; // rbx

if ( a1 <= 0x63 && *((_DWORD *)&open_file + 6 * (int)a1 + 1) )
{
v1 = iget(*(unsigned int *)(*((_QWORD *)&open_file + 3 * (int)a1 + 1) + 24LL));
v2 = v1;
v3 = *(_DWORD *)(v1 + 28);
if ( v3 )
{
v4 = (char *)malloc((unsigned int)(v3 << 10));
v6 = v4;
v7 = 0LL;
do
{
fseek(fd, (unsigned int)(*(_DWORD *)(v2 + 4 * v7 + 32) << 10), 0);
fread(v6, 1uLL, 0x400uLL, fd);
++v7;
v6 += 1024;
}
while ( *(_DWORD *)(v2 + 28) > (unsigned int)v7 );
iput(v2);
}
else
{
iput(v1);
v4 = (char *)&LC3;
}
}
else
{
puts("File has not been opened");
v4 = (char *)&LC3;
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // rbp
int v3; // edi
char *v4; // r14
char *v6; // r12
__int64 v7; // rbx

if ( a1 <= 0x63 && *((_DWORD *)&open_file + 6 * (int)a1 + 1) )
{
v1 = iget(*(unsigned int *)(*((_QWORD *)&open_file + 3 * (int)a1 + 1) + 24LL));
v2 = v1;
v3 = *(_DWORD *)(v1 + 28);
if ( v3 )
{
v4 = (char *)malloc((unsigned int)(v3 << 10));
v6 = v4;
v7 = 0LL;
do
{
fseek(fd, (unsigned int)(*(_DWORD *)(v2 + 4 * v7 + 32) << 10), 0);
fread(v6, 1uLL, 0x400uLL, fd);
++v7;
v6 += 1024;
}
while ( *(_DWORD *)(v2 + 28) > (unsigned int)v7 );
iput(v2);
}
else
{
iput(v1);
v4 = (char *)&LC3;
}
}
else
{
puts("File has not been opened");
v4 = (char *)&LC3;
}
return v4;
}

original_code:
char* mread(int file_no) {
 if (file_no < 0 || file_no > 99) {
  printf("File has not been opened\n");
  return "";
 }
 if (open_file[file_no].count < 1) {
  printf("File has not been opened\n");
  return "";
 }
 struct inode_t* pinode = open_file[file_no].pinode;
 pinode = iget(pinode->dino);
 if (pinode->size < 1) {
  iput(pinode);
  return "";
 } else {
  char *buf = (char*)malloc(pinode->size * 1024);
  int i;
  for (i=0; i<pinode->size; i++) {
   fseek(fd, pinode->addr[i] * 1024, 0);
   fread(buf + i * 1024, 1, 1024, fd);
  }
  iput(pinode);
  return buf;
 }
}

canonical_original_code:
char *mread(int file_no) {
 if (file_no < 0 || file_no > 99) {
  printf("File has not been opened\n");
  return "";
 }
 if (open_file[file_no].count < 1) {
  printf("File has not been opened\n");
  return "";
 }
 struct inode_t *pinode = open_file[file_no].pinode;
 pinode = iget(pinode->dino);
 if (pinode->size < 1) {
  iput(pinode);
  return "";
 } else {
  char *buf = (char*)malloc(pinode->size * 1024);
  int i;
  for (i=0; i<pinode->size; i++) {
   fseek(fd, pinode->addr[i] * 1024, 0);
   fread(buf + i * 1024, 1, 1024, fd);
  }
  iput(pinode);
  return buf;
 }
}

variable_types:
buf
char *

return_type: char *


mwrite

decompiled_code:
int __fastcall mwrite(unsigned int a1, char *a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rax
unsigned __int64 v5; // rdx
int v6; // er14
__int64 v7; // rbp
int *v8; // r12
char *v9; // rbp
int result; // eax

if ( a1 > 0x63 )
return puts("File has not been opened");
if ( !*((_DWORD *)&open_file + 6 * (int)a1 + 1) )
return puts("File has not been opened");
v2 = iget(*(unsigned int *)(*((_QWORD *)&open_file + 3 * (int)a1 + 1) + 24LL));
v3 = v2;
if ( !*a2 )
{
v6 = 0;
if ( !*(_DWORD *)(v2 + 28) )
return iput(v3);
goto LABEL_7;
}
v4 = 1LL;
do
v5 = v4++;
while ( a2[v4 - 1] );
v6 = (v5 >> 10) - (((v5 & 0x3FF) == 0) - 1);
if ( *(_DWORD *)(v3 + 28) )
{
LABEL_7:
v7 = 0LL;
do
bfree(*(unsigned int *)(v3 + 4 * v7++ + 32));
while ( *(_DWORD *)(v3 + 28) > (unsigned int)v7 );
}
if ( !v6 )
return iput(v3);
v8 = (int *)(v3 + 32);
v9 = a2;
while ( 1 )
{
result = balloc();
if ( !result )
break;
*v8 = result;
++*(_DWORD *)(v3 + 28);
fseek(fd, (unsigned int)(result << 10), 0);
fwrite(v9, 1uLL, 0x400uLL, fd);
++v8;
v9 += 1024;
if ( &a2[1024 * (unsigned __int64)(unsigned int)(v6 - 1) + 1024] == v9 )
return iput(v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, char *a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rax
unsigned __int64 v5; // rdx
int v6; // er14
__int64 v7; // rbp
int *v8; // r12
char *v9; // rbp
int result; // eax

if ( a1 > 0x63 )
return puts("File has not been opened");
if ( !*((_DWORD *)&open_file + 6 * (int)a1 + 1) )
return puts("File has not been opened");
v2 = iget(*(unsigned int *)(*((_QWORD *)&open_file + 3 * (int)a1 + 1) + 24LL));
v3 = v2;
if ( !*a2 )
{
v6 = 0;
if ( !*(_DWORD *)(v2 + 28) )
return iput(v3);
goto LABEL_7;
}
v4 = 1LL;
do
v5 = v4++;
while ( a2[v4 - 1] );
v6 = (v5 >> 10) - (((v5 & 0x3FF) == 0) - 1);
if ( *(_DWORD *)(v3 + 28) )
{
LABEL_7:
v7 = 0LL;
do
bfree(*(unsigned int *)(v3 + 4 * v7++ + 32));
while ( *(_DWORD *)(v3 + 28) > (unsigned int)v7 );
}
if ( !v6 )
return iput(v3);
v8 = (int *)(v3 + 32);
v9 = a2;
while ( 1 )
{
result = balloc();
if ( !result )
break;
*v8 = result;
++*(_DWORD *)(v3 + 28);
fseek(fd, (unsigned int)(result << 10), 0);
fwrite(v9, 1uLL, 0x400uLL, fd);
++v8;
v9 += 1024;
if ( &a2[1024 * (unsigned __int64)(unsigned int)(v6 - 1) + 1024] == v9 )
return iput(v3);
}
return result;
}

original_code:
void mwrite(int file_no, const char* content) {
 if (file_no < 0 || file_no > 99) {
  printf("File has not been opened\n");
  return;
 }
 if (open_file[file_no].count < 1) {
  printf("File has not been opened\n");
  return;
 }
 struct inode_t* pinode = open_file[file_no].pinode;
 pinode = iget(pinode->dino);
 int length;
 for (length=0; *(content + length) != '\0'; length++)
  ;
 unsigned int block_num = length * sizeof(char) / 1024;
 unsigned int offset = length * sizeof(char) % 1024;
 if (offset != 0)
  block_num++;
 int i;
 for (i=0; i<pinode->size; i++) {
  bfree(pinode->addr[i]);
 }
 for (i=0; i < block_num; i++) {
  unsigned int block_no = balloc();
  if (block_no == 0)
   return;
  pinode->addr[i]= block_no;
  pinode->size++;
  fseek(fd, block_no * 1024, 0);
  fwrite(content + i * 1024, 1, 1024, fd);
 }
 iput(pinode);
 return;
}

canonical_original_code:
void mwrite(int file_no, char *content) {
 if (file_no < 0 || file_no > 99) {
  printf("File has not been opened\n");
  return;
 }
 if (open_file[file_no].count < 1) {
  printf("File has not been opened\n");
  return;
 }
 struct inode_t *pinode = open_file[file_no].pinode;
 pinode = iget(pinode->dino);
 int length;
 for (length=0; *(content + length) != '\0'; length++)
  ;
 unsigned int block_num = length * sizeof(char) / 1024;
 unsigned int offset = length * sizeof(char) % 1024;
 if (offset != 0)
  block_num++;
 int i;
 for (i=0; i<pinode->size; i++) {
  bfree(pinode->addr[i]);
 }
 for (i=0; i < block_num; i++) {
  unsigned int block_no = balloc();
  if (block_no == 0)
   return;
  pinode->addr[i]= block_no;
  pinode->size++;
  fseek(fd, block_no * 1024, 0);
  fwrite(content + i * 1024, 1, 1024, fd);
 }
 iput(pinode);
 return;
}

variable_types:
content
char *

variable_types: length int

variable_types:
offset
unsigned int


decompiled_code:
size_t save_super_block()
{
fseek(fd, 1024LL, 0);
return fwrite(&sb, 1uLL, 0x338uLL, fd);
}

canonical_decompiled_code:
size_t func0()
{
fseek(fd, 1024LL, 0);
return fwrite(&sb, 1uLL, 0x338uLL, fd);
}

original_code:
void save_super_block() {
 fseek(fd, 1024 * 1, 0);
 fwrite(&sb, 1, sizeof(sb), fd);
 return;
}


verify

decompiled_code:
bool __fastcall verify(const char *a1)
{
return strcmp(a1, &usr[12]) == 0;
}

canonical_decompiled_code:
bool __fastcall func2(const char *a1)
{
return strcmp(a1, &usr[12]) == 0;
}

original_code:
char verify(char* password) {
 if (strcmp(password, usr.password) == 0)
  return 1;
 else
  return 0;
}

canonical_original_code:
char verify(char *password) {
 if (strcmp(password, usr.password) == 0)
  return 1;
 else
  return 0;
}

variable_types:
password
char *

return_type: char


decompiled_code:
__int64 __fastcall d_to_inode(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 result; // rax
char v4[4]; // [rsp+0h] [rbp-F8h] BYREF
int v5; // [rsp+4h] [rbp-F4h]
int v6; // [rsp+8h] [rbp-F0h]
char v7[236]; // [rsp+Ch] [rbp-ECh]

v2 = map_addr(a2);
fseek(fd, v2, 0);
fread(v4, 1uLL, 0xD4uLL, fd);
*(_BYTE *)(a1 + 22) = v4[0];
*(_DWORD *)(a1 + 28) = v6;
*(_DWORD *)(a1 + 24) = v5;
for ( result = 0LL; result != 200; result += 4LL )
*(_DWORD *)(a1 + result + 32) = *(_DWORD *)&v7[result];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 result; // rax
char v4[4]; // [rsp+0h] [rbp-F8h] BYREF
int v5; // [rsp+4h] [rbp-F4h]
int v6; // [rsp+8h] [rbp-F0h]
char v7[236]; // [rsp+Ch] [rbp-ECh]

v2 = func1(a2);
fseek(fd, v2, 0);
fread(v4, 1uLL, 0xD4uLL, fd);
*(_BYTE *)(a1 + 22) = v4[0];
*(_DWORD *)(a1 + 28) = v6;
*(_DWORD *)(a1 + 24) = v5;
for ( result = 0LL; result != 200; result += 4LL )
*(_DWORD *)(a1 + result + 32) = *(_DWORD *)&v7[result];
return result;
}

original_code:
void d_to_inode(struct inode_t *pinode, unsigned int dino) {
 struct d_inode_t dinode;
 fseek(fd, map_addr(dino), 0);
 fread(&dinode, 1, sizeof(dinode), fd);
 pinode->type = dinode.type;
 pinode->size = dinode.size;
 pinode->dino = dinode.dino;
 int i;
 for (i=0; i<50; i++) {
  pinode->addr[i] = dinode.addr[i];
 }
 return;
}

variable_types:
dino
unsigned int

variable_types: struct d_inode_t { char type; unsigned int dino; unsigned int size; unsigned int addr[50]; }


original_code:
void i_to_dinode(struct inode_t *pinode) {
 unsigned int dino = pinode->dino;
 struct d_inode_t dinode;
 dinode.type = pinode->type;
 dinode.size = pinode->size;
 dinode.dino = dino;
 int i;
 for(i=0; i<50; i++) {
  dinode.addr[i] = pinode->addr[i];
 }
 fseek(fd, map_addr(dino), 0);
 fwrite(&dinode, 1, sizeof(dinode), fd);
 return;
}

user_defined_types: struct d_inode_t { char type; unsigned int dino; unsigned int size; unsigned int addr[50]; }


decompiled_code:
__int64 __fastcall map_addr(int a1)
{
return 212LL * (unsigned int)(a1 - 1) + 2048;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return 212LL * (unsigned int)(a1 - 1) + 2048;
}

original_code:
unsigned long map_addr(unsigned int dino) {
 unsigned long addr = 2 * 1024 + sizeof(struct d_inode_t) * (dino - 1);
 return addr;
}

variable_types:
addr
unsigned long

return_type: unsigned long


namei

decompiled_code:
__int64 __fastcall namei(char *s2)
{
bool v2; // al
bool v3; // cf
bool v4; // zf
__int64 v5; // rcx
_BYTE *v6; // rdi
char *v7; // rsi
__int64 v9; // rbx
int v10; // er13
char *v11; // rbp
int v12; // ebx
__int16 v13[4]; // [rsp+0h] [rbp-428h] BYREF
char s1; // [rsp+8h] [rbp-420h] BYREF

v2 = strcmp(s2, "/") != 0;
v3 = 0;
v4 = !v2;
if ( !v2 )
return usr[6];
v5 = 2LL;
v6 = &LC1;
v7 = s2;
do
{
if ( !v5 )
break;
v3 = (unsigned __int8)*v7 < *v6;
v4 = *v7++ == *v6++;
--v5;
}
while ( v4 );
if ( (!v3 && !v4) == v3 )
return cur_dir_dinode_no;
v9 = iget(cur_dir_dinode_no, v7);
fseek(fd, (unsigned int)(*(_DWORD *)(v9 + 32) << 10), 0);
fread(v13, 1uLL, 0x3F4uLL, fd);
iput(v9);
v10 = (unsigned __int16)v13[0];
if ( !v13[0] )
return 0LL;
v11 = &s1;
v12 = 0;
while ( strcmp(v11, s2) )
{
++v12;
v11 += 28;
if ( v12 == v10 )
return 0LL;
}
return *(unsigned int *)&v13[14 * v12 + 2];
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2)
{
bool v2; // al
bool v3; // cf
bool v4; // zf
__int64 v5; // rcx
_BYTE *v6; // rdi
char *v7; // rsi
__int64 v9; // rbx
int v10; // er13
char *v11; // rbp
int v12; // ebx
__int16 v13[4]; // [rsp+0h] [rbp-428h] BYREF
char s1; // [rsp+8h] [rbp-420h] BYREF

v2 = strcmp(s2, "/") != 0;
v3 = 0;
v4 = !v2;
if ( !v2 )
return usr[6];
v5 = 2LL;
v6 = &LC1;
v7 = s2;
do
{
if ( !v5 )
break;
v3 = (unsigned __int8)*v7 < *v6;
v4 = *v7++ == *v6++;
--v5;
}
while ( v4 );
if ( (!v3 && !v4) == v3 )
return cur_dir_dinode_no;
v9 = iget(cur_dir_dinode_no, v7);
fseek(fd, (unsigned int)(*(_DWORD *)(v9 + 32) << 10), 0);
fread(v13, 1uLL, 0x3F4uLL, fd);
iput(v9);
v10 = (unsigned __int16)v13[0];
if ( !v13[0] )
return 0LL;
v11 = &s1;
v12 = 0;
while ( strcmp(v11, s2) )
{
++v12;
v11 += 28;
if ( v12 == v10 )
return 0LL;
}
return *(unsigned int *)&v13[14 * v12 + 2];
}

original_code:
unsigned int namei(const char *pathname) {
 if (strcmp(pathname, "/") == 0) {
  return usr.dino;
 } else if (strcmp(pathname, ".") == 0) {
  return cur_dir_dinode_no;
 } else {
  struct inode_t* pinode = iget(cur_dir_dinode_no);
  struct directory_t dir;
  fseek(fd, pinode->addr[0] * 1024, 0);
  fread(&dir, 1, sizeof(dir), fd);
  iput(pinode);
  int i;
  for (i=0; i<dir.size; i++) {
   if (strcmp(dir.files[i].name, pathname) == 0) {
    return dir.files[i].dino;
   }
  }
  return 0;
 }
}

canonical_original_code:
unsigned int namei(char *pathname) {
 if (strcmp(pathname, "/") == 0) {
  return usr.dino;
 } else if (strcmp(pathname, ".") == 0) {
  return cur_dir_dinode_no;
 } else {
  struct inode_t *pinode = iget(cur_dir_dinode_no);
  struct directory_t dir;
  fseek(fd, pinode->addr[0] * 1024, 0);
  fread(&dir, 1, sizeof(dir), fd);
  iput(pinode);
  int i;
  for (i=0; i<dir.size; i++) {
   if (strcmp(dir.files[i].name, pathname) == 0) {
    return dir.files[i].dino;
   }
  }
  return 0;
 }
}

return_type: unsigned int


balloc

original_code:
unsigned int balloc(void) {
 if (sb.free_block_num == 0) {
  printf("running out of free blocks");
  return 0;
 }
 if (sb.free_block_sp == 0) {
  int i, j;
  int count = 0;
  char flag = 0;
  for (i=0; i<600 / 50 ; i++) {
   struct bmap_t bmap;
   fseek(fd, 1024 * (2 + 400 + 50 * i), 0);
   fread(&bmap, 1, sizeof(bmap), fd);
   for (j=1; j<50; j++) {
    if (bmap.use[j] == 0) {
     bmap.use[j] = 1;
     bmap.free_block_num --;
     sb.free_block_stack[sb.free_block_sp] = bmap.addr[j];
     sb.free_block_sp ++;
     sb.free_block_num --;
     count++;
     if (count == 50) {
      flag = 1;
      break;
     }
    }
   }
   fseek(fd, 1024 * (2 + 400 + 50 * i), 0);
   fwrite(&bmap, 1, sizeof(bmap), fd);
   if (flag == 1)
    break;
  }
 }
 unsigned int alloc_block_no = sb.free_block_stack[sb.free_block_sp - 1];
 sb.modified = 0;
 sb.free_block_num--;
 sb.free_block_sp--;
 save_super_block();
 return alloc_block_no;
}

canonical_original_code:
unsigned int balloc() {
 if (sb.free_block_num == 0) {
  printf("running out of free blocks");
  return 0;
 }
 if (sb.free_block_sp == 0) {
  int i; int j;
  int count = 0;
  char flag = 0;
  for (i=0; i<600 / 50 ; i++) {
   struct bmap_t bmap;
   fseek(fd, 1024 * (2 + 400 + 50 * i), 0);
   fread(&bmap, 1, sizeof(bmap), fd);
   for (j=1; j<50; j++) {
    if (bmap.use[j] == 0) {
     bmap.use[j] = 1;
     bmap.free_block_num --;
     sb.free_block_stack[sb.free_block_sp] = bmap.addr[j];
     sb.free_block_sp ++;
     sb.free_block_num --;
     count++;
     if (count == 50) {
      flag = 1;
      break;
     }
    }
   }
   fseek(fd, 1024 * (2 + 400 + 50 * i), 0);
   fwrite(&bmap, 1, sizeof(bmap), fd);
   if (flag == 1)
    break;
  }
 }
 unsigned int alloc_block_no = sb.free_block_stack[sb.free_block_sp - 1];
 sb.modified = 0;
 sb.free_block_num--;
 sb.free_block_sp--;
 save_super_block();
 return alloc_block_no;
}

variable_types: j int

variable_types: count int

variable_types: flag char

variable_types: struct bmap_t { char use[50]; unsigned int addr[50]; unsigned short free_block_num; }


bfree

original_code:
void bfree(unsigned int block_no) {
 if (sb.free_block_sp == 100) {
  struct bmap_t bmap;
  unsigned int block_no_temp;
  int i, offset;
  for(i=0; i<50; i++) {
   block_no_temp = sb.free_block_stack[sb.free_block_sp - 1];
   sb.free_block_sp--;
   offset = (block_no_temp - 2) % 50;
   fseek(fd, 1024 * block_no_temp, 0);
   fread(&bmap, 1, sizeof(bmap), fd);
   bmap.free_block_num ++;
   bmap.use[offset] = 0;
   fwrite(&bmap, 1, sizeof(bmap), fd);
  }
 }
 sb.free_block_stack[sb.free_block_sp] = block_no;
 sb.free_block_sp ++;
 sb.free_block_num++;
 sb.modified = 0;
 save_super_block();
 return;
}

canonical_original_code:
void bfree(unsigned int block_no) {
 if (sb.free_block_sp == 100) {
  struct bmap_t bmap;
  unsigned int block_no_temp;
  int i; int offset;
  for(i=0; i<50; i++) {
   block_no_temp = sb.free_block_stack[sb.free_block_sp - 1];
   sb.free_block_sp--;
   offset = (block_no_temp - 2) % 50;
   fseek(fd, 1024 * block_no_temp, 0);
   fread(&bmap, 1, sizeof(bmap), fd);
   bmap.free_block_num ++;
   bmap.use[offset] = 0;
   fwrite(&bmap, 1, sizeof(bmap), fd);
  }
 }
 sb.free_block_stack[sb.free_block_sp] = block_no;
 sb.free_block_sp ++;
 sb.free_block_num++;
 sb.modified = 0;
 save_super_block();
 return;
}

variable_types: offset int

user_defined_types: struct bmap_t { char use[50]; unsigned int addr[50]; unsigned short free_block_num; }


ialloc

decompiled_code:
__int64 ialloc()
{
int v0; // er13
unsigned int v1; // ebx
__int64 v2; // rbx
__int64 v3; // rax
unsigned __int16 v4; // ax
__int64 v5; // rax
unsigned __int16 v6; // cx
unsigned int v7; // ebx
char v9[4]; // [rsp+0h] [rbp-108h] BYREF
int v10; // [rsp+4h] [rbp-104h]

if ( *((_DWORD *)&sb + 104) )
{
if ( !*((_WORD *)&sb + 410) )
{
v0 = 0;
v1 = 1;
while ( 1 )
{
v3 = map_addr(v1);
fseek(fd, v3, 0);
fread(v9, 1uLL, 0xD4uLL, fd);
if ( v9[0] == 101 )
{
v4 = *((_WORD *)&sb + 410);
*((_DWORD *)&sb + v4 + 105) = v10;
*((_WORD *)&sb + 410) = v4 + 1;
v9[0] = 117;
v5 = map_addr(v1);
fseek(fd, v5, 0);
fwrite(v9, 1uLL, 0xD4uLL, fd);
if ( ++v0 == 50 )
break;
}
if ( ++v1 == 1932 )
{
printf("running out of on-disk inodes");
return 0LL;
}
}
}
v6 = *((_WORD *)&sb + 410);
v7 = *((_DWORD *)&sb + v6 + 104);
*((_WORD *)&sb + 410) = v6 - 1;
--*((_DWORD *)&sb + 104);
save_super_block();
v2 = iget(v7);
i_to_dinode(v2);
}
else
{
printf("running out of inode");
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // er13
unsigned int v1; // ebx
__int64 v2; // rbx
__int64 v3; // rax
unsigned __int16 v4; // ax
__int64 v5; // rax
unsigned __int16 v6; // cx
unsigned int v7; // ebx
char v9[4]; // [rsp+0h] [rbp-108h] BYREF
int v10; // [rsp+4h] [rbp-104h]

if ( *((_DWORD *)&sb + 104) )
{
if ( !*((_WORD *)&sb + 410) )
{
v0 = 0;
v1 = 1;
while ( 1 )
{
v3 = map_addr(v1);
fseek(fd, v3, 0);
fread(v9, 1uLL, 0xD4uLL, fd);
if ( v9[0] == 101 )
{
v4 = *((_WORD *)&sb + 410);
*((_DWORD *)&sb + v4 + 105) = v10;
*((_WORD *)&sb + 410) = v4 + 1;
v9[0] = 117;
v5 = map_addr(v1);
fseek(fd, v5, 0);
fwrite(v9, 1uLL, 0xD4uLL, fd);
if ( ++v0 == 50 )
break;
}
if ( ++v1 == 1932 )
{
printf("running out of on-disk inodes");
return 0LL;
}
}
}
v6 = *((_WORD *)&sb + 410);
v7 = *((_DWORD *)&sb + v6 + 104);
*((_WORD *)&sb + 410) = v6 - 1;
--*((_DWORD *)&sb + 104);
save_super_block();
v2 = iget(v7);
i_to_dinode(v2);
}
else
{
printf("running out of inode");
v2 = 0LL;
}
return v2;
}

original_code:
struct inode_t *ialloc(void) {
 if (sb.free_inode_num == 0) {
  printf("running out of inode");
  return ((void *)0);
 }
 int i;
 int count = 0;
 char find50 = 0;
 struct d_inode_t dinode;
 if (sb.free_inode_sp == 0) {
  for (i=1; i<1024 * 400 / sizeof(dinode); i++) {
   fseek(fd, map_addr(i), 0);
   fread(&dinode, 1, sizeof(dinode), fd);
   if (dinode.type == 'e') {
    sb.free_inode_stack[sb.free_inode_sp] = dinode.dino;
    sb.free_inode_sp++;
    dinode.type = 'u';
    fseek(fd, map_addr(i), 0);
    fwrite(&dinode, 1, sizeof(dinode), fd);
    count ++;
    if (count == 50) {
     find50 = 1;
     break;
    }
   }
  }
  if (find50 == 0) {
   printf("running out of on-disk inodes");
   return ((void *)0);
  }
 }
 unsigned int dinode_no = sb.free_inode_stack[sb.free_inode_sp - 1];
 sb.free_inode_sp--;
 sb.free_inode_num--;
 save_super_block();
 struct inode_t* pinode = iget(dinode_no);
 i_to_dinode(pinode);
 return pinode;
}

canonical_original_code:
struct inode_t *ialloc() {
 if (sb.free_inode_num == 0) {
  printf("running out of inode");
  return ((void *)0);
 }
 int i;
 int count = 0;
 char find50 = 0;
 struct d_inode_t dinode;
 if (sb.free_inode_sp == 0) {
  for (i=1; i<1024 * 400 / sizeof(dinode); i++) {
   fseek(fd, map_addr(i), 0);
   fread(&dinode, 1, sizeof(dinode), fd);
   if (dinode.type == 'e') {
    sb.free_inode_stack[sb.free_inode_sp] = dinode.dino;
    sb.free_inode_sp++;
    dinode.type = 'u';
    fseek(fd, map_addr(i), 0);
    fwrite(&dinode, 1, sizeof(dinode), fd);
    count ++;
    if (count == 50) {
     find50 = 1;
     break;
    }
   }
  }
  if (find50 == 0) {
   printf("running out of on-disk inodes");
   return ((void *)0);
  }
 }
 unsigned int dinode_no = sb.free_inode_stack[sb.free_inode_sp - 1];
 sb.free_inode_sp--;
 sb.free_inode_num--;
 save_super_block();
 struct inode_t *pinode = iget(dinode_no);
 i_to_dinode(pinode);
 return pinode;
}

variable_types: struct inode_t { struct inode_t *forward; struct inode_t *backward; unsigned int count; unsigned short flag; char type; unsigned int dino; unsigned int size; unsigned int addr[50]; } *


ifree

decompiled_code:
void *__fastcall ifree(int a1)
{
void *result; // rax
unsigned __int16 v2; // dx
int v3; // ebx
unsigned int v4; // er15
__int64 v5; // rax
__int64 v6; // rax
char v7[280]; // [rsp+0h] [rbp-118h] BYREF

if ( *((_WORD *)&sb + 410) == 100 )
{
v3 = 50;
do
{
v4 = *((_DWORD *)&sb + *((unsigned __int16 *)&sb + 410) + 104);
v5 = map_addr(v4);
fseek(fd, v5, 0);
fread(v7, 1uLL, 0xD4uLL, fd);
v7[0] = 115;
v6 = map_addr(v4);
fseek(fd, v6, 0);
fwrite(v7, 1uLL, 0xD4uLL, fd);
--v3;
}
while ( v3 );
}
result = &sb;
v2 = *((_WORD *)&sb + 410);
*((_DWORD *)&sb + v2 + 105) = a1;
*((_WORD *)&sb + 410) = v2 + 1;
++*((_DWORD *)&sb + 104);
return result;
}

original_code:
void ifree(unsigned int dinode_no) {
 if (sb.free_inode_sp == 100) {
  int i;
  unsigned int no;
  struct d_inode_t dinode;
  for (i=0; i<50; i++) {
   no = sb.free_inode_stack[sb.free_inode_sp - 1];
   fseek(fd, map_addr(no), 0);
   fread(&dinode, 1, sizeof(dinode), fd);
   dinode.type = 's';
   fseek(fd, map_addr(no), 0);
   fwrite(&dinode, 1, sizeof(dinode), fd);
  }
 }
 sb.free_inode_stack[sb.free_inode_sp] = dinode_no;
 sb.free_inode_sp ++;
 sb.free_inode_num ++;
 return;
}

variable_types: i int

variable_types:
no
unsigned int


iput

decompiled_code:
void __fastcall iput(void *ptr)
{
unsigned int v1; // eax
_QWORD *v2; // rdx

v1 = *((_DWORD *)ptr + 4);
if ( v1 <= 1 )
{
i_to_dinode();
if ( *(_QWORD *)ptr )
{
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = v2;
*v2 = *(_QWORD *)ptr;
}
else
{
**((_QWORD **)ptr + 1) = 0LL;
}
free(ptr);
}
else
{
*((_DWORD *)ptr + 4) = v1 - 1;
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
unsigned int v1; // eax
_QWORD *v2; // rdx

v1 = *((_DWORD *)ptr + 4);
if ( v1 <= 1 )
{
i_to_dinode();
if ( *(_QWORD *)ptr )
{
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = v2;
*v2 = *(_QWORD *)ptr;
}
else
{
**((_QWORD **)ptr + 1) = 0LL;
}
free(ptr);
}
else
{
*((_DWORD *)ptr + 4) = v1 - 1;
}
}

original_code:
void iput(struct inode_t *pinode) {
 if (pinode->count > 1) {
  pinode->count--;
  return;
 }
 i_to_dinode(pinode);
 if (pinode->forward == ((void *)0)) {
  pinode->backward->forward = ((void *)0);
  free(pinode);
  return;
 } else {
  pinode->forward->backward = pinode->backward;
  pinode->backward->forward = pinode->forward;
  free(pinode);
  return;
 }
}


original_code:
void format_fs(char* path, char* pwd) {
 fd = fopen(path, "r+w+b");
 if (fd == ((void *)0))
 {
  printf("vfs does not exist\n");
  exit(0);
 }
 struct bmap_t bmap;
 int i, j;
 for (i=400 + 2; i<400 + 600 + 2; i+=50) {
  for(j=1; j<50; j++) {
   bmap.use[j] = 0;
   bmap.addr[j] = i + j;
   bmap.free_block_num = 49;
  }
  fseek(fd, i * 1024, 0);
  fwrite(&bmap, 1, sizeof(bmap), fd);
 }
 struct d_inode_t dinode;
 dinode.dino = 1;
 dinode.size = 0;
 dinode.type = 'e';
 for (i=1; i<1024 * 400 / sizeof(dinode); i++) {
  fseek(fd, map_addr(i), 0);
  fwrite(&dinode, 1, sizeof(dinode), fd);
  dinode.dino++;
 }
 dinode.size = 1;
 dinode.type = 'd';
 dinode.addr[0] = 400 + 2 + 1;
 dinode.dino = 1;
 fseek(fd, map_addr(dinode.dino), 0);
 fwrite(&dinode, 1, sizeof(dinode), fd);
 struct directory_t dir;
 dir.size = 0;
 fseek(fd, 1024 * (400 + 2 + 1), 0);
 fwrite(&dir, 1, sizeof(dir), fd);
 fseek(fd, 402 * 1024, 0);
 fread(&bmap, 1, sizeof(bmap), fd);
 bmap.use[1] = 1;
 bmap.free_block_num--;
 fseek(fd, 402 * 1024, 0);
 fwrite(&bmap, 1, sizeof(bmap), fd);
 struct user_t usr;
 strcpy(usr.name, "root");
 strcpy(usr.password, pwd);
 usr.dino = 1;
 fseek(fd, 0, 0);
 fwrite(&usr, 1, sizeof(usr), fd);
 struct super_block_t sb;
 sb.data_block_num = 600 - ( 600 / 50 );
 sb.inode_block_num = 400;
 sb.free_block_num = 600 - ( 600 / 50 ) - 1;
 sb.free_block_sp = 0;
 sb.free_inode_num = 400 * 1024 / sizeof(dinode) - 1;
 sb.free_inode_sp = 0;
 sb.modified = 0;
 fseek(fd, 1024 * 1, 0);
 fwrite(&sb, 1, sizeof(sb), fd);
 fclose(fd);
 return;
}

canonical_original_code:
void format_fs(char *path, char *pwd) {
 fd = fopen(path, "r+w+b");
 if (fd == ((void *)0))
 {
  printf("vfs does not exist\n");
  exit(0);
 }
 struct bmap_t bmap;
 int i; int j;
 for (i=400 + 2; i<400 + 600 + 2; i+=50) {
  for(j=1; j<50; j++) {
   bmap.use[j] = 0;
   bmap.addr[j] = i + j;
   bmap.free_block_num = 49;
  }
  fseek(fd, i * 1024, 0);
  fwrite(&bmap, 1, sizeof(bmap), fd);
 }
 struct d_inode_t dinode;
 dinode.dino = 1;
 dinode.size = 0;
 dinode.type = 'e';
 for (i=1; i<1024 * 400 / sizeof(dinode); i++) {
  fseek(fd, map_addr(i), 0);
  fwrite(&dinode, 1, sizeof(dinode), fd);
  dinode.dino++;
 }
 dinode.size = 1;
 dinode.type = 'd';
 dinode.addr[0] = 400 + 2 + 1;
 dinode.dino = 1;
 fseek(fd, map_addr(dinode.dino), 0);
 fwrite(&dinode, 1, sizeof(dinode), fd);
 struct directory_t dir;
 dir.size = 0;
 fseek(fd, 1024 * (400 + 2 + 1), 0);
 fwrite(&dir, 1, sizeof(dir), fd);
 fseek(fd, 402 * 1024, 0);
 fread(&bmap, 1, sizeof(bmap), fd);
 bmap.use[1] = 1;
 bmap.free_block_num--;
 fseek(fd, 402 * 1024, 0);
 fwrite(&bmap, 1, sizeof(bmap), fd);
 struct user_t usr;
 strcpy(usr.name, "root");
 strcpy(usr.password, pwd);
 usr.dino = 1;
 fseek(fd, 0, 0);
 fwrite(&usr, 1, sizeof(usr), fd);
 struct super_block_t sb;
 sb.data_block_num = 600 - ( 600 / 50 );
 sb.inode_block_num = 400;
 sb.free_block_num = 600 - ( 600 / 50 ) - 1;
 sb.free_block_sp = 0;
 sb.free_inode_num = 400 * 1024 / sizeof(dinode) - 1;
 sb.free_inode_sp = 0;
 sb.modified = 0;
 fseek(fd, 1024 * 1, 0);
 fwrite(&sb, 1, sizeof(sb), fd);
 fclose(fd);
 return;
}

variable_types:
path
char *

variable_types:
pwd
char *

variable_types: struct directory_t { unsigned short size; struct file_t { unsigned int dino; char name[24]; } files[36]; }

variable_types: struct user_t { char name[12]; char password[12]; unsigned int dino; }

variable_types: struct super_block_t { unsigned int inode_block_num; unsigned int data_block_num; unsigned int free_block_num; unsigned int free_block_stack[100]; unsigned short free_block_sp; unsigned int free_inode_num; unsigned int free_inode_stack[100]; unsigned short free_inode_sp; char modified; }


canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
return 212LL * (unsigned int)(a1 - 1) + 2048;
}

original_code:
unsigned long map_addr(unsigned int dino) {
 struct d_inode_t dinode;
 unsigned long addr = 2 * 1024 + sizeof(dinode) * (dino - 1);
 return addr;
}


decompiled_code:
char __fastcall init_param(const char *a1, const char *a2)
{
char *v2; // rax
bool v3; // zf

if ( !strcmp(a1, "time_limit") )
{
LODWORD(v2) = atoi(a2);
time_limit = (int)v2;
}
else if ( !strcmp(a1, "memory_limit") )
{
v2 = (char *)atol(a2);
memory_limit = (__int64)v2;
}
else if ( !strcmp(a1, "output_limit") )
{
v2 = (char *)atol(a2);
output_limit = (__int64)v2;
}
else if ( !strcmp(a1, "process_limit") )
{
LODWORD(v2) = atoi(a2);
process_limit = (int)v2;
}
else if ( !strcmp(a1, "command") )
{
v2 = strdup(a2);
command = v2;
}
else if ( !strcmp(a1, "input_file") )
{
v2 = strdup(a2);
input_file = (__int64)v2;
}
else if ( !strcmp(a1, "output_file") )
{
v2 = strdup(a2);
output_file = (__int64)v2;
}
else if ( !strcmp(a1, "error_file") )
{
v2 = strdup(a2);
error_file = (__int64)v2;
}
else if ( !strcmp(a1, "root") )
{
v2 = strdup(a2);
root = (__int64)v2;
}
else
{
v3 = strcmp(a1, "cwd") == 0;
LOBYTE(v2) = !v3;
if ( v3 )
{
v2 = strdup(a2);
cwd = (__int64)v2;
}
}
return (char)v2;
}

canonical_decompiled_code:
char __fastcall func0(const char *a1, const char *a2)
{
char *v2; // rax
bool v3; // zf

if ( !strcmp(a1, "time_limit") )
{
LODWORD(v2) = atoi(a2);
time_limit = (int)v2;
}
else if ( !strcmp(a1, "memory_limit") )
{
v2 = (char *)atol(a2);
memory_limit = (__int64)v2;
}
else if ( !strcmp(a1, "output_limit") )
{
v2 = (char *)atol(a2);
output_limit = (__int64)v2;
}
else if ( !strcmp(a1, "process_limit") )
{
LODWORD(v2) = atoi(a2);
process_limit = (int)v2;
}
else if ( !strcmp(a1, "command") )
{
v2 = strdup(a2);
command = v2;
}
else if ( !strcmp(a1, "input_file") )
{
v2 = strdup(a2);
input_file = (__int64)v2;
}
else if ( !strcmp(a1, "output_file") )
{
v2 = strdup(a2);
output_file = (__int64)v2;
}
else if ( !strcmp(a1, "error_file") )
{
v2 = strdup(a2);
error_file = (__int64)v2;
}
else if ( !strcmp(a1, "root") )
{
v2 = strdup(a2);
root = (__int64)v2;
}
else
{
v3 = strcmp(a1, "cwd") == 0;
LOBYTE(v2) = !v3;
if ( v3 )
{
v2 = strdup(a2);
cwd = (__int64)v2;
}
}
return (char)v2;
}

original_code:
void init_param(const char *key, const char *value)
{
 if (!strcmp(key, "time_limit"))
  time_limit = atoi(value);
 else if (!strcmp(key, "memory_limit"))
  memory_limit = atol(value);
 else if (!strcmp(key, "output_limit"))
  output_limit = atol(value);
 else if (!strcmp(key, "process_limit"))
  process_limit = atoi(value);
 else if (!strcmp(key, "command"))
  command = strdup(value);
 else if (!strcmp(key, "input_file"))
  input_file = strdup(value);
 else if (!strcmp(key, "output_file"))
  output_file = strdup(value);
 else if (!strcmp(key, "error_file"))
  error_file = strdup(value);
 else if (!strcmp(key, "root"))
  root = strdup(value);
 else if (!strcmp(key, "cwd"))
  cwd = strdup(value);
}

canonical_original_code:
void init_param(char *key, char *value)
{
 if (!strcmp(key, "time_limit"))
  time_limit = atoi(value);
 else if (!strcmp(key, "memory_limit"))
  memory_limit = atol(value);
 else if (!strcmp(key, "output_limit"))
  output_limit = atol(value);
 else if (!strcmp(key, "process_limit"))
  process_limit = atoi(value);
 else if (!strcmp(key, "command"))
  command = strdup(value);
 else if (!strcmp(key, "input_file"))
  input_file = strdup(value);
 else if (!strcmp(key, "output_file"))
  output_file = strdup(value);
 else if (!strcmp(key, "error_file"))
  error_file = strdup(value);
 else if (!strcmp(key, "root"))
  root = strdup(value);
 else if (!strcmp(key, "cwd"))
  cwd = strdup(value);
}

variable_types:
key
char *

variable_types:
value
char *


decompiled_code:
_QWORD *vector_init()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx

v0 = malloc(0x18uLL);
if ( !v0 )
_assert_fail("new != NULL", "vector.c", 0xEu, "vector_init");
v1 = v0;
*v0 = malloc(0LL);
v1[2] = 0LL;
v1[1] = 0LL;
return v1;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx

v0 = malloc(0x18uLL);
if ( !v0 )
_assert_fail("new != NULL", "vector.c", 0xEu, "vector_init");
v1 = v0;
*v0 = malloc(0LL);
v1[2] = 0LL;
v1[1] = 0LL;
return v1;
}

original_code:
struct vector *vector_init()
{
 struct vector *new = malloc(sizeof(struct vector));
 ((void) sizeof ((new != ((void *)0)) ? 1 : 0), __extension__ ({ if (new != ((void *)0)) ; else __assert_fail ("new != NULL", "vector.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 new->arr = malloc(0);
 new->size = 0;
 new->alloc = 0;
 return new;
}

variable_types: struct vector { void **arr; unsigned long alloc; unsigned long size; } *


decompiled_code:
__int64 __fastcall vector_push(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // rsi
_QWORD *v4; // rdx
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 16) + 1LL;
if ( v3 > *(_QWORD *)(a1 + 8) )
{
if ( !realloc(*(void **)a1, 8 * v3) )
_assert_fail("realloc(v->arr, sizeof(void *) * (v->size + 1)) != NULL", "vector.c", 0x18u, "vector_push");
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a1 + 16) + 1LL;
}
v4 = *(_QWORD **)a1;
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 16) = result + 1;
v4[result] = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // rsi
_QWORD *v4; // rdx
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 16) + 1LL;
if ( v3 > *(_QWORD *)(a1 + 8) )
{
if ( !realloc(*(void **)a1, 8 * v3) )
_assert_fail("realloc(v->arr, sizeof(void *) * (v->size + 1)) != NULL", "vector.c", 0x18u, "vector_push");
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a1 + 16) + 1LL;
}
v4 = *(_QWORD **)a1;
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 16) = result + 1;
v4[result] = a2;
return result;
}

original_code:
void vector_push(struct vector *v, const void *data)
{
 if (v->size + 1 > v->alloc) {
  ((void) sizeof ((realloc(v->arr, sizeof(void *) * (v->size + 1)) != ((void *)0)) ? 1 : 0), __extension__ ({ if (realloc(v->arr, sizeof(void *) * (v->size + 1)) != ((void *)0)) ; else __assert_fail ("realloc(v->arr, sizeof(void *) * (v->size + 1)) != NULL", "vector.c", 24, __extension__ __PRETTY_FUNCTION__); }));
  v->alloc = v->size + 1;
 }
 v->arr[v->size++] = data;
}

canonical_original_code:
void vector_push(struct vector *v, void *data)
{
 if (v->size + 1 > v->alloc) {
  ((void) sizeof ((realloc(v->arr, sizeof(void *) * (v->size + 1)) != ((void *)0)) ? 1 : 0), __extension__ ({ if (realloc(v->arr, sizeof(void *) * (v->size + 1)) != ((void *)0)) ; else __assert_fail ("realloc(v->arr, sizeof(void *) * (v->size + 1)) != NULL", "vector.c", 24, __extension__ __PRETTY_FUNCTION__); }));
  v->alloc = v->size + 1;
 }
 v->arr[v->size++] = data;
}

variable_types:
data
void *

user_defined_types: struct vector { void **arr; unsigned long alloc; unsigned long size; }


decompiled_code:
__int64 __fastcall vector_getdata(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
const void **vector_getdata(struct vector *v)
{
 return v->arr;
}

return_type: void **


decompiled_code:
char *log_prefix()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
sprintf(
prefixBuffer,
"%d-%02d-%02d %02d:%02d:%02d",
(unsigned int)(v0->tm_year + 1900),
(unsigned int)v0->tm_mon,
(unsigned int)v0->tm_mday,
(unsigned int)v0->tm_hour,
(unsigned int)v0->tm_min,
(unsigned int)v0->tm_sec);
return prefixBuffer;
}

canonical_decompiled_code:
char *func0()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
sprintf(
prefixBuffer,
"%d-%02d-%02d %02d:%02d:%02d",
(unsigned int)(v0->tm_year + 1900),
(unsigned int)v0->tm_mon,
(unsigned int)v0->tm_mday,
(unsigned int)v0->tm_hour,
(unsigned int)v0->tm_min,
(unsigned int)v0->tm_sec);
return prefixBuffer;
}

original_code:
const char *log_prefix()
{
 time_t now = time(((void *)0));
 struct tm *tmNow = localtime(&now);
 sprintf(prefixBuffer, "%d-%02d-%02d %02d:%02d:%02d",
  tmNow->tm_year + 1900, tmNow->tm_mon, tmNow->tm_mday,
  tmNow->tm_hour, tmNow->tm_min, tmNow->tm_sec);
 return prefixBuffer;
}

canonical_original_code:
char *log_prefix()
{
 long now = time(((void *)0));
 struct tm *tmNow = localtime(&now);
 sprintf(prefixBuffer, "%d-%02d-%02d %02d:%02d:%02d",
  tmNow->tm_year + 1900, tmNow->tm_mon, tmNow->tm_mday,
  tmNow->tm_hour, tmNow->tm_min, tmNow->tm_sec);
 return prefixBuffer;
}

variable_types: now long

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


decompiled_code:
void cc3k_global_irq_enable()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code: void cc3k_global_irq_enable(char dummy) {dummy=dummy; }

variable_types: dummy char


decompiled_code:
__int64 cc3k_hardware_init()
{
cc3k_set_enable(0LL);
cc3k_set_cs(1LL);
cc3k_set_clk(0LL);
return cc3k_set_dout(0LL);
}

canonical_decompiled_code:
__int64 func1()
{
cc3k_set_enable(0LL);
cc3k_set_cs(1LL);
cc3k_set_clk(0LL);
return cc3k_set_dout(0LL);
}

original_code:
void cc3k_hardware_init(void) {
    cc3k_set_enable(0);
    cc3k_set_cs(1);
    cc3k_set_clk(0);
    cc3k_set_dout(0);
}

canonical_original_code:
void cc3k_hardware_init() {
    cc3k_set_enable(0);
    cc3k_set_cs(1);
    cc3k_set_clk(0);
    cc3k_set_dout(0);
}


WlanReadInterruptPin

decompiled_code:
__int64 WlanReadInterruptPin()
{
return (char)cc3k_get_irq();
}

canonical_decompiled_code:
__int64 func2()
{
return (char)cc3k_get_irq();
}

original_code: long WlanReadInterruptPin(void) { return cc3k_get_irq(); }

canonical_original_code: long WlanReadInterruptPin() { return cc3k_get_irq(); }

return_type: long


WlanInterruptEnable

decompiled_code:
void WlanInterruptEnable()
{
cc3k_pseudo_irq_en = 1;
}

canonical_decompiled_code:
void func3()
{
cc3k_pseudo_irq_en = 1;
}

original_code: void WlanInterruptEnable(void) { cc3k_pseudo_irq_en=1; }

canonical_original_code: void WlanInterruptEnable() { cc3k_pseudo_irq_en=1; }


WlanInterruptDisable

decompiled_code:
void WlanInterruptDisable()
{
cc3k_pseudo_irq_en = 0;
}

canonical_decompiled_code:
void func4()
{
cc3k_pseudo_irq_en = 0;
}

original_code: void WlanInterruptDisable(void) { cc3k_pseudo_irq_en=0; }

canonical_original_code: void WlanInterruptDisable() { cc3k_pseudo_irq_en=0; }


WriteWlanPin

decompiled_code:
__int64 __fastcall WriteWlanPin(char a1)
{
return cc3k_set_enable((unsigned int)a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
return cc3k_set_enable((unsigned int)a1);
}

original_code: void WriteWlanPin(unsigned char val) { cc3k_set_enable(val); }

variable_types:
val
unsigned char


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

++cc3k_regular_cnt;
if ( cc3k_pseudo_irq_en && !(unsigned __int8)cc3k_get_irq() )
CC3000InterruptHandler();
result = (unsigned int)cc3k_regular_cnt;
if ( (cc3k_regular_cnt & 0x3F) == 0 )
result = hci_unsolicited_event_handler();
return result;
}

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

++cc3k_regular_cnt;
if ( cc3k_pseudo_irq_en && !(unsigned __int8)cc3k_get_irq() )
CC3000InterruptHandler();
result = (unsigned int)cc3k_regular_cnt;
if ( (cc3k_regular_cnt & 0x3F) == 0 )
result = hci_unsolicited_event_handler();
return result;
}

original_code:
void cc3k_regular() {
    cc3k_regular_cnt++;
    if (cc3k_pseudo_irq_en && !cc3k_get_irq())
        CC3000InterruptHandler();
    if ((cc3k_regular_cnt & 0x3f)==0)
        hci_unsolicited_event_handler();
}


decompiled_code:
__int64 __fastcall nvmem_read(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rax
char v10[41]; // [rsp+Fh] [rbp-29h] BYREF

v10[0] = -1;
v6 = tSLInformation[2];
v7 = UINT32_TO_STREAM_f(v6 + 9, a1);
v8 = UINT32_TO_STREAM_f(v7, a2);
UINT32_TO_STREAM_f(v8, a3);
hci_command_send(513LL, v6, 12LL);
SimpleLinkWaitEvent(513LL, v10);
SimpleLinkWaitData(a4, 0LL, 0LL);
return (unsigned __int8)v10[0];
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rax
char v10[41]; // [rsp+Fh] [rbp-29h] BYREF

v10[0] = -1;
v6 = tSLInformation[2];
v7 = UINT32_TO_STREAM_f(v6 + 9, a1);
v8 = UINT32_TO_STREAM_f(v7, a2);
UINT32_TO_STREAM_f(v8, a3);
hci_command_send(513LL, v6, 12LL);
SimpleLinkWaitEvent(513LL, v10);
SimpleLinkWaitData(a4, 0LL, 0LL);
return (unsigned __int8)v10[0];
}

original_code:
signed long
nvmem_read(unsigned long ulFileId, unsigned long ulLength, unsigned long ulOffset, unsigned char *buff)
{
 unsigned char ucStatus = 0xFF;
 unsigned char *ptr;
 unsigned char *args;
 ptr = tSLInformation.pucTxCommandBuffer;
 args = (ptr + ((5) + (4)));
 args = (UINT32_TO_STREAM_f(args, ulFileId));
 args = (UINT32_TO_STREAM_f(args, ulLength));
 args = (UINT32_TO_STREAM_f(args, ulOffset));
 hci_command_send((0x0201), ptr, (12));
 SimpleLinkWaitEvent((0x0201), &ucStatus);
 SimpleLinkWaitData(buff, 0, 0);
 return(ucStatus);
}

variable_types:
ulFileId
unsigned long

variable_types:
ulLength
unsigned long

variable_types:
ulOffset
unsigned long

variable_types:
buff
unsigned char *

variable_types:
ucStatus
unsigned char

variable_types:
ptr
unsigned char *

variable_types:
args
unsigned char *


decompiled_code:
__int64 __fastcall nvmem_write(__int64 a1, size_t a2, __int64 a3, const void *a4)
{
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v11[6]; // [rsp+8h] [rbp-30h] BYREF

v11[0] = -1LL;
v6 = tSLInformation[2];
v7 = UINT32_TO_STREAM_f(v6 + 10, a1);
v8 = UINT32_TO_STREAM_f(v7, 12LL);
v9 = UINT32_TO_STREAM_f(v8, a2);
UINT32_TO_STREAM_f(v9, a3);
memcpy((void *)(v6 + 26), a4, a2);
hci_data_command_send(144LL, v6, 16LL, (unsigned __int16)a2);
SimpleLinkWaitEvent(514LL, v11);
return v11[0];
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, size_t a2, __int64 a3, const void *a4)
{
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v11[6]; // [rsp+8h] [rbp-30h] BYREF

v11[0] = -1LL;
v6 = tSLInformation[2];
v7 = UINT32_TO_STREAM_f(v6 + 10, a1);
v8 = UINT32_TO_STREAM_f(v7, 12LL);
v9 = UINT32_TO_STREAM_f(v8, a2);
UINT32_TO_STREAM_f(v9, a3);
memcpy((void *)(v6 + 26), a4, a2);
hci_data_command_send(144LL, v6, 16LL, (unsigned __int16)a2);
SimpleLinkWaitEvent(514LL, v11);
return v11[0];
}

original_code:
signed long
nvmem_write(unsigned long ulFileId, unsigned long ulLength, unsigned long
      ulEntryOffset, unsigned char *buff)
{
 long iRes;
 unsigned char *ptr;
 unsigned char *args;
 iRes = -1;
 ptr = tSLInformation.pucTxCommandBuffer;
 args = (ptr + (5) + (5));
 args = (UINT32_TO_STREAM_f(args, ulFileId));
 args = (UINT32_TO_STREAM_f(args, 12));
 args = (UINT32_TO_STREAM_f(args, ulLength));
 args = (UINT32_TO_STREAM_f(args, ulEntryOffset));
 memcpy((ptr + (5) + (5) +
     (16)),buff,ulLength);
 hci_data_command_send((0x0090), ptr, (16),
            ulLength);
 SimpleLinkWaitEvent((0x0202), &iRes);
 return(iRes);
}

variable_types:
ulEntryOffset
unsigned long

variable_types: iRes long


decompiled_code:
__int64 __fastcall nvmem_set_mac_address(const void *a1)
{
return nvmem_write(6LL, 6uLL, 0LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(const void *a1)
{
return func1(6LL, 6uLL, 0LL, a1);
}

original_code:
unsigned char nvmem_set_mac_address(unsigned char *mac)
{
 return nvmem_write((6), (6), 0, mac);
}

variable_types:
mac
unsigned char *

return_type: unsigned char


decompiled_code:
__int64 __fastcall nvmem_get_mac_address(__int64 a1)
{
return nvmem_read(6LL, 6LL, 0LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return func0(6LL, 6LL, 0LL, a1);
}

original_code:
unsigned char nvmem_get_mac_address(unsigned char *mac)
{
 return nvmem_read((6), (6), 0, mac);
}


decompiled_code:
__int64 __fastcall nvmem_write_patch(__int64 a1, unsigned __int64 a2, char *a3)
{
size_t v3; // rbx
unsigned __int16 v5; // r12
unsigned int v6; // edx

v3 = a2;
if ( a2 <= 0x1F )
{
v5 = 0;
v6 = 0;
}
else
{
v5 = 0;
do
{
v6 = nvmem_write(a1, 0x20uLL, v5, a3);
v5 += 32;
v3 -= 32LL;
a3 += 32;
}
while ( !(_BYTE)v6 && v3 > 0x1F );
}
if ( v3 && !(_BYTE)v6 )
v6 = nvmem_write(a1, v3, v5, a3);
return v6;
}

original_code:
unsigned char nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, const unsigned char *spData)
{
 unsigned char status = 0;
 unsigned short offset = 0;
 unsigned char* spDataPtr = (unsigned char*)spData;
 while ((status == 0) && (spLength >= (32)))
 {
  status = nvmem_write(ulFileId, (32), offset, spDataPtr);
  offset += (32);
  spLength -= (32);
  spDataPtr += (32);
 }
 if (status !=0)
 {
  return status;
 }
 if (spLength != 0)
 {
  status = nvmem_write(ulFileId, spLength, offset, spDataPtr);
 }
 return status;
}

canonical_original_code:
unsigned char nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, unsigned char *spData)
{
 unsigned char status = 0;
 unsigned short offset = 0;
 unsigned char *spDataPtr = (unsigned char*)spData;
 while ((status == 0) && (spLength >= (32)))
 {
  status = nvmem_write(ulFileId, (32), offset, spDataPtr);
  offset += (32);
  spLength -= (32);
  spDataPtr += (32);
 }
 if (status !=0)
 {
  return status;
 }
 if (spLength != 0)
 {
  status = nvmem_write(ulFileId, spLength, offset, spDataPtr);
 }
 return status;
}

variable_types:
spLength
unsigned long

variable_types:
spData
unsigned char *

variable_types:
status
unsigned char

variable_types:
offset
unsigned short

variable_types:
spDataPtr
unsigned char *


decompiled_code:
__int64 __fastcall nvmem_read_sp_version(_BYTE *a1)
{
char v2[13]; // [rsp+Bh] [rbp-Dh] BYREF

hci_command_send(519LL, tSLInformation[2], 0LL);
SimpleLinkWaitEvent(519LL, v2);
*a1 = v2[3];
a1[1] = v2[4];
return (unsigned __int8)v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
char v2[13]; // [rsp+Bh] [rbp-Dh] BYREF

hci_command_send(519LL, tSLInformation[2], 0LL);
SimpleLinkWaitEvent(519LL, v2);
*a1 = v2[3];
a1[1] = v2[4];
return (unsigned __int8)v2[0];
}

original_code:
unsigned char nvmem_read_sp_version(unsigned char* patchVer)
{
 unsigned char *ptr;
 unsigned char retBuf[5];
 ptr = tSLInformation.pucTxCommandBuffer;
 hci_command_send((0x0207), ptr, 0);
 SimpleLinkWaitEvent((0x0207), retBuf);
 *patchVer = retBuf[3];
 *(patchVer+1) = retBuf[4];
 return(retBuf[0]);
}

canonical_original_code:
unsigned char nvmem_read_sp_version(unsigned char *patchVer)
{
 unsigned char *ptr;
 unsigned char retBuf[5];
 ptr = tSLInformation.pucTxCommandBuffer;
 hci_command_send((0x0207), ptr, 0);
 SimpleLinkWaitEvent((0x0207), retBuf);
 *patchVer = retBuf[3];
 *(patchVer+1) = retBuf[4];
 return(retBuf[0]);
}

variable_types:
patchVer
unsigned char *

variable_types:
retBuf
unsigned char [5]


decompiled_code:
__int64 __fastcall nvmem_create_entry(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax
unsigned __int16 v5[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v2 = tSLInformation[2];
v3 = UINT32_TO_STREAM_f(v2 + 9, a1);
UINT32_TO_STREAM_f(v3, a2);
hci_command_send(515LL, v2, 8LL);
SimpleLinkWaitEvent(515LL, v5);
return v5[0];
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax
unsigned __int16 v5[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v2 = tSLInformation[2];
v3 = UINT32_TO_STREAM_f(v2 + 9, a1);
UINT32_TO_STREAM_f(v3, a2);
hci_command_send(515LL, v2, 8LL);
SimpleLinkWaitEvent(515LL, v5);
return v5[0];
}

original_code:
signed long
nvmem_create_entry(unsigned long ulFileId, unsigned long ulNewLen)
{
 unsigned char *ptr;
 unsigned char *args;
 unsigned short retval;
 ptr = tSLInformation.pucTxCommandBuffer;
 args = (ptr + ((5) + (4)));
 args = (UINT32_TO_STREAM_f(args, ulFileId));
 args = (UINT32_TO_STREAM_f(args, ulNewLen));
 hci_command_send((0x0203),ptr, (8));
 SimpleLinkWaitEvent((0x0203), &retval);
 return(retval);
}

variable_types:
ulFileId
unsigned long

variable_types:
ulNewLen
unsigned long

variable_types:
retval
unsigned short


SPIPump

decompiled_code:
__int64 __fastcall SPIPump(unsigned __int8 a1)
{
unsigned int v1; // ebp
unsigned int v2; // ebx
int v3; // er12
int v4; // eax
int v5; // ebx

cc3k_global_irq_enable(0LL);
v1 = 7;
v2 = 0;
v3 = a1;
do
{
v5 = 2 * v2;
if ( _bittest(&v3, v1) )
cc3k_set_dout(1LL);
else
cc3k_set_dout(0LL);
cc3k_set_clk(1LL);
cc3k_set_clk(0LL);
v4 = cc3k_get_din();
LOBYTE(v4) = (_BYTE)v4 != 0;
v2 = v4 | v5;
--v1;
}
while ( v1 != -1 );
cc3k_set_dout(0LL);
cc3k_global_irq_enable(1LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
unsigned int v1; // ebp
unsigned int v2; // ebx
int v3; // er12
int v4; // eax
int v5; // ebx

cc3k_global_irq_enable(0LL);
v1 = 7;
v2 = 0;
v3 = a1;
do
{
v5 = 2 * v2;
if ( _bittest(&v3, v1) )
cc3k_set_dout(1LL);
else
cc3k_set_dout(0LL);
cc3k_set_clk(1LL);
cc3k_set_clk(0LL);
v4 = cc3k_get_din();
LOBYTE(v4) = (_BYTE)v4 != 0;
v2 = v4 | v5;
--v1;
}
while ( v1 != -1 );
cc3k_set_dout(0LL);
cc3k_global_irq_enable(1LL);
return v2;
}

original_code:
uint8_t SPIPump(uint8_t data) {
 uint8_t receivedData=0;
    int i;
    cc3k_global_irq_enable(0);
 for (i=7; i>=0; i--) {
  receivedData <<= 1;
  if (data & (1<<i))
            cc3k_set_dout(1);
        else
            cc3k_set_dout(0);
  cc3k_set_clk(1);
        cc3k_set_clk(0);
        receivedData |= cc3k_get_din() ? 1 : 0;
 }
    cc3k_set_dout(0);
    cc3k_global_irq_enable(1);
    return receivedData;
}

canonical_original_code:
unsigned char SPIPump(unsigned char data) {
 unsigned char receivedData = 0;
    int i;
    cc3k_global_irq_enable(0);
 for (i=7; i>=0; i--) {
  receivedData <<= 1;
  if (data & (1<<i))
            cc3k_set_dout(1);
        else
            cc3k_set_dout(0);
  cc3k_set_clk(1);
        cc3k_set_clk(0);
        receivedData |= cc3k_get_din() ? 1 : 0;
 }
    cc3k_set_dout(0);
    cc3k_global_irq_enable(1);
    return receivedData;
}

variable_types:
data
unsigned char

variable_types:
receivedData
unsigned char

variable_types: i int


SpiPauseSpi

decompiled_code:
void SpiPauseSpi()
{
SPIInterruptsEnabled = 0;
}

canonical_decompiled_code:
void func1()
{
SPIInterruptsEnabled = 0;
}

original_code:
void SpiPauseSpi(void) {
 SPIInterruptsEnabled = 0;
 }


SpiResumeSpi

decompiled_code:
void SpiResumeSpi()
{
SPIInterruptsEnabled = 1;
}

canonical_decompiled_code:
void func2()
{
SPIInterruptsEnabled = 1;
}

original_code:
void SpiResumeSpi(void) {
 SPIInterruptsEnabled = 1;
 }


SpiTriggerRxProcessing

decompiled_code:
__int64 SpiTriggerRxProcessing()
{
__int64 (__fastcall *v0)(_QWORD); // rax

SpiPauseSpi();
deassert_cs();
v0 = sSpiInformation[4];
if ( *((_BYTE *)v0 + 130) != 0xDE )
{
while ( 1 )
;
}
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))&loc_2;
return ((__int64 (__fastcall **)(char *))sSpiInformation)[0]((char *)v0 + 5);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 (__fastcall *v0)(_QWORD); // rax

func1();
deassert_cs();
v0 = sSpiInformation[4];
if ( *((_BYTE *)v0 + 130) != 0xDE )
{
while ( 1 )
;
}
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))&loc_2;
return ((__int64 (__fastcall **)(char *))sSpiInformation)[0]((char *)v0 + 5);
}

original_code:
void
SpiTriggerRxProcessing(void)
{
    SpiPauseSpi();
    deassert_cs();
 if (sSpiInformation.pRxPacket[((130 + 1)) - 1] != (0xDE))
 {
  while (1)
   ;
 }
 sSpiInformation.ulSpiState = (2);
 sSpiInformation.SPIRxHandler(sSpiInformation.pRxPacket + (5));
}

canonical_original_code:
void SpiTriggerRxProcessing()
{
    SpiPauseSpi();
    deassert_cs();
 if (sSpiInformation.pRxPacket[((130 + 1)) - 1] != (0xDE))
 {
  while (1)
   ;
 }
 sSpiInformation.ulSpiState = (2);
 sSpiInformation.SPIRxHandler(sSpiInformation.pRxPacket + (5));
}


SpiReadDataSynchronous

decompiled_code:
void __fastcall SpiReadDataSynchronous(__int64 a1, unsigned __int16 a2)
{
__int64 i; // rbx
unsigned __int8 v4; // di

if ( a2 )
{
for ( i = 0LL; i != a2; *(_BYTE *)(a1 + i++) = SPIPump(v4) )
{
v4 = 0;
if ( i <= 4 )
v4 = tSpiReadHeader[i];
}
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, unsigned __int16 a2)
{
__int64 i; // rbx
unsigned __int8 v4; // di

if ( a2 )
{
for ( i = 0LL; i != a2; *(_BYTE *)(a1 + i++) = func0(v4) )
{
v4 = 0;
if ( i <= 4 )
v4 = tSpiReadHeader[i];
}
}
}

original_code:
void SpiReadDataSynchronous(unsigned char *data, unsigned short size) {
 long i = 0;
    unsigned char *data_to_send = tSpiReadHeader;
    for (i = 0; i < size; i ++) {
        uint8_t j;
        if (i<5)
            j=data_to_send[i];
        else j=0;
        data[i] = SPIPump(j);
    }
}

canonical_original_code:
void SpiReadDataSynchronous(unsigned char *data, unsigned short size) {
 long i = 0;
    unsigned char *data_to_send = tSpiReadHeader;
    for (i = 0; i < size; i ++) {
        unsigned char j;
        if (i<5)
            j=data_to_send[i];
        else j=0;
        data[i] = SPIPump(j);
    }
}

variable_types:
data
unsigned char *

variable_types:
size
unsigned short

variable_types: i long

variable_types:
j
unsigned char


SpiWriteDataSynchronous

decompiled_code:
__int64 __fastcall SpiWriteDataSynchronous(unsigned __int8 *a1, unsigned __int16 a2)
{
unsigned __int8 *v2; // rbx
__int64 result; // rax

if ( a2 )
{
v2 = a1;
do
result = SPIPump(*v2++);
while ( v2 != &a1[a2] );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1, unsigned __int16 a2)
{
unsigned __int8 *v2; // rbx
__int64 result; // rax

if ( a2 )
{
v2 = a1;
do
result = func0(*v2++);
while ( v2 != &a1[a2] );
}
return result;
}

original_code:
void SpiWriteDataSynchronous(unsigned char *data, unsigned short size) {
 while (size)
    {
  SPIPump(*data);
  size --;
        data++;
    }
}


SpiFirstWrite

decompiled_code:
__int64 __fastcall SpiFirstWrite(unsigned __int8 *a1, __int16 a2)
{
assert_cs_and_wait();
SpiWriteDataSynchronous(a1, 4u);
cc3k_delay_us(50LL);
SpiWriteDataSynchronous(a1 + 4, a2 - 4);
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))&loc_2;
deassert_cs();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 *a1, __int16 a2)
{
assert_cs_and_wait();
func5(a1, 4u);
cc3k_delay_us(50LL);
func5(a1 + 4, a2 - 4);
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))&loc_2;
deassert_cs();
return 0LL;
}

original_code:
long
SpiFirstWrite(unsigned char *ucBuf, unsigned short usLength)
{
    assert_cs_and_wait();
    SpiWriteDataSynchronous(ucBuf, 4);
    cc3k_delay_us(50);
    SpiWriteDataSynchronous(ucBuf + 4, usLength - 4);
    sSpiInformation.ulSpiState = (2);
    deassert_cs();
    return(0);
}

variable_types:
ucBuf
unsigned char *

variable_types:
usLength
unsigned short


SpiWrite

decompiled_code:
__int64 __fastcall SpiWrite(__int64 a1, __int16 a2)
{
unsigned __int8 v2; // dl
__int64 (__fastcall *v3)(_QWORD); // rax
__int16 v4; // bp

cc3k_delay_ms(2LL);
v2 = (a2 ^ 1) & 1;
*(_BYTE *)a1 = 1;
*(_BYTE *)(a1 + 1) = (unsigned __int16)(a2 + v2) >> 8;
*(_WORD *)(a1 + 2) = (unsigned __int8)(v2 + a2);
*(_BYTE *)(a1 + 4) = 0;
if ( wlan_tx_buffer[130] != 0xDE )
{
while ( 1 )
;
}
v3 = sSpiInformation[2];
if ( !v3 )
{
while ( 1 )
;
}
v4 = v2 + a2 + 5;
if ( v3 == (__int64 (__fastcall *)(_QWORD))((char *)SPIPump + 1) )
{
SpiFirstWrite((unsigned __int8 *)a1, v4);
}
else
{
tSLInformation[9]();
while ( sSpiInformation[2] != (__int64 (__fastcall *)(_QWORD))&loc_2 )
;
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))&loc_3;
sSpiInformation[3] = (__int64 (__fastcall *)(_QWORD))a1;
LOWORD(sSpiInformation[1]) = v4;
assert_cs_and_wait();
tSLInformation[8]();
if ( !tSLInformation[7]() )
{
cc3k_delay_ms(2LL);
SpiWriteDataSynchronous((unsigned __int8 *)sSpiInformation[3], (unsigned __int16)sSpiInformation[1]);
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))&loc_2;
deassert_cs();
}
}
while ( sSpiInformation[2] != (__int64 (__fastcall *)(_QWORD))&loc_2 )
;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int16 a2)
{
unsigned __int8 v2; // dl
__int64 (__fastcall *v3)(_QWORD); // rax
__int16 v4; // bp

cc3k_delay_ms(2LL);
v2 = (a2 ^ 1) & 1;
*(_BYTE *)a1 = 1;
*(_BYTE *)(a1 + 1) = (unsigned __int16)(a2 + v2) >> 8;
*(_WORD *)(a1 + 2) = (unsigned __int8)(v2 + a2);
*(_BYTE *)(a1 + 4) = 0;
if ( wlan_tx_buffer[130] != 0xDE )
{
while ( 1 )
;
}
v3 = sSpiInformation[2];
if ( !v3 )
{
while ( 1 )
;
}
v4 = v2 + a2 + 5;
if ( v3 == (__int64 (__fastcall *)(_QWORD))((char *)SPIPump + 1) )
{
func6((unsigned __int8 *)a1, v4);
}
else
{
tSLInformation[9]();
while ( sSpiInformation[2] != (__int64 (__fastcall *)(_QWORD))&loc_2 )
;
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))&loc_3;
sSpiInformation[3] = (__int64 (__fastcall *)(_QWORD))a1;
LOWORD(sSpiInformation[1]) = v4;
assert_cs_and_wait();
tSLInformation[8]();
if ( !tSLInformation[7]() )
{
cc3k_delay_ms(2LL);
func5((unsigned __int8 *)sSpiInformation[3], (unsigned __int16)sSpiInformation[1]);
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))&loc_2;
deassert_cs();
}
}
while ( sSpiInformation[2] != (__int64 (__fastcall *)(_QWORD))&loc_2 )
;
return 0LL;
}

original_code:
long
SpiWrite(unsigned char *pUserBuffer, unsigned short usLength)
{
    unsigned char ucPad = 0;
    cc3k_delay_ms(2);
    if(!(usLength & 0x0001))
    {
        ucPad++;
    }
    pUserBuffer[0] = 1;
    pUserBuffer[1] = (((usLength + ucPad) & 0xFF00) >> 8);
    pUserBuffer[2] = ((usLength + ucPad) & 0x00FF);
    pUserBuffer[3] = 0;
    pUserBuffer[4] = 0;
    usLength += ((5) + ucPad);
 if (wlan_tx_buffer[((130 + 1)) - 1] != (0xDE))
 {
  while (1)
   ;
 }
 if (sSpiInformation.ulSpiState == (0))
 {
  while (sSpiInformation.ulSpiState != (1)) {
   }
   ;
 }
 if (sSpiInformation.ulSpiState == (1))
 {
  SpiFirstWrite(pUserBuffer, usLength);
 }
 else
 {
  tSLInformation.WlanInterruptDisable();
  while (sSpiInformation.ulSpiState != (2))
  {
   ;
  }
  sSpiInformation.ulSpiState = (3);
  sSpiInformation.pTxPacket = pUserBuffer;
  sSpiInformation.usTxPacketLength = usLength;
  assert_cs_and_wait();
  tSLInformation.WlanInterruptEnable();
  if (tSLInformation.ReadWlanInterruptPin() == 0)
  {
            cc3k_delay_ms(2);
            SpiWriteDataSynchronous(sSpiInformation.pTxPacket, sSpiInformation.usTxPacketLength);
   sSpiInformation.ulSpiState = (2);
   deassert_cs();
  }
 }
 while ((2) != sSpiInformation.ulSpiState)
  ;
    return(0);
}

variable_types:
pUserBuffer
unsigned char *

variable_types:
ucPad
unsigned char


SpiReadDataCont

decompiled_code:
__int64 SpiReadDataCont()
{
__int64 (__fastcall *v0)(_QWORD); // rbx
char v1; // al
unsigned __int16 v3; // ax
unsigned __int16 v4; // si
__int64 v5; // rax
__int64 v6; // rsi

v0 = sSpiInformation[4];
v1 = *((_BYTE *)v0 + 5);
if ( v1 == 2 )
{
v3 = STREAM_TO_UINT16_f((char *)v0 + 5, 3LL);
v4 = v3;
if ( (v3 & 1) != 0 )
{
if ( !v3 )
return 0LL;
}
else
{
v4 = v3 + 1;
}
SpiReadDataSynchronous((__int64)v0 + 10, v4);
}
else if ( v1 == 4 )
{
v5 = *((unsigned __int8 *)v0 + 8);
v6 = v5 - 1;
if ( (v5 & 1) == 0 )
v6 = *((unsigned __int8 *)v0 + 8);
if ( v6 )
SpiReadDataSynchronous((__int64)v0 + 10, v6);
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))(&loc_7 + 1);
}
return 0LL;
}

original_code:
long
SpiReadDataCont(void)
{
    long data_to_recv;
 unsigned char *evnt_buff, type;
    evnt_buff = sSpiInformation.pRxPacket;
    data_to_recv = 0;
 {type = (unsigned char)(*((char *)(evnt_buff + (5)) + (0)));};
    switch(type)
    {
        case 0x2:
        {
   {data_to_recv = STREAM_TO_UINT16_f((char *)(evnt_buff + (5)), (3));};
   if (!((((5) + 5) + data_to_recv) & 1))
   {
             data_to_recv++;
   }
   if (data_to_recv)
   {
             SpiReadDataSynchronous(evnt_buff + 10, data_to_recv);
   }
            break;
        }
        case 0x4:
        {
            {data_to_recv = (unsigned char)(*((char *)(evnt_buff + (5)) + (3)));};
   data_to_recv -= 1;
   if ((((5) + 5) + data_to_recv) & 1)
   {
             data_to_recv++;
   }
   if (data_to_recv)
   {
             SpiReadDataSynchronous(evnt_buff + 10, data_to_recv);
   }
   sSpiInformation.ulSpiState = (8);
            break;
        }
    }
    return (0);
}

canonical_original_code:
long SpiReadDataCont()
{
    long data_to_recv;
 unsigned char *evnt_buff; unsigned char type;
    evnt_buff = sSpiInformation.pRxPacket;
    data_to_recv = 0;
 {type = (unsigned char)(*((char *)(evnt_buff + (5)) + (0)));};
    switch(type)
    {
        case 0x2:
        {
   {data_to_recv = STREAM_TO_UINT16_f((char *)(evnt_buff + (5)), (3));};
   if (!((((5) + 5) + data_to_recv) & 1))
   {
             data_to_recv++;
   }
   if (data_to_recv)
   {
             SpiReadDataSynchronous(evnt_buff + 10, data_to_recv);
   }
            break;
        }
        case 0x4:
        {
            {data_to_recv = (unsigned char)(*((char *)(evnt_buff + (5)) + (3)));};
   data_to_recv -= 1;
   if ((((5) + 5) + data_to_recv) & 1)
   {
             data_to_recv++;
   }
   if (data_to_recv)
   {
             SpiReadDataSynchronous(evnt_buff + 10, data_to_recv);
   }
   sSpiInformation.ulSpiState = (8);
            break;
        }
    }
    return (0);
}

variable_types:
type
unsigned char


SSIContReadOperation

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

result = SpiReadDataCont();
if ( !result )
result = SpiTriggerRxProcessing();
return result;
}

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

result = func8();
if ( !result )
result = func3();
return result;
}

original_code:
void
SSIContReadOperation(void)
{
 if (!SpiReadDataCont())
 {
  SpiTriggerRxProcessing();
 }
}

canonical_original_code:
void SSIContReadOperation()
{
 if (!SpiReadDataCont())
 {
  SpiTriggerRxProcessing();
 }
}


SpiReadHeader

decompiled_code:
void SpiReadHeader()
{
SpiReadDataSynchronous((__int64)sSpiInformation[4], 0xAu);
}

canonical_decompiled_code:
void func10()
{
func4((__int64)sSpiInformation[4], 0xAu);
}

original_code:
void
SpiReadHeader(void)
{
 SpiReadDataSynchronous(sSpiInformation.pRxPacket, 10);
}

canonical_original_code:
void SpiReadHeader()
{
 SpiReadDataSynchronous(sSpiInformation.pRxPacket, 10);
}


decompiled_code:
void CC3000InterruptHandler()
{
__int64 (__fastcall *v0)(_QWORD); // rax

if ( SPIInterruptsEnabled )
{
v0 = sSpiInformation[2];
if ( v0 )
{
if ( v0 == (__int64 (__fastcall *)(_QWORD))&loc_2 )
{
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))(&loc_4 + 2);
assert_cs_and_wait();
SpiReadHeader();
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))(&loc_7 + 1);
SSIContReadOperation();
}
else if ( v0 == (__int64 (__fastcall *)(_QWORD))&loc_3 )
{
SpiWriteDataSynchronous((unsigned __int8 *)sSpiInformation[3], (unsigned __int16)sSpiInformation[1]);
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))&loc_2;
deassert_cs();
}
}
else
{
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))(SPIPump + 1);
}
}
}

canonical_decompiled_code:
void func11()
{
__int64 (__fastcall *v0)(_QWORD); // rax

if ( SPIInterruptsEnabled )
{
v0 = sSpiInformation[2];
if ( v0 )
{
if ( v0 == (__int64 (__fastcall *)(_QWORD))&loc_2 )
{
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))(&loc_4 + 2);
assert_cs_and_wait();
func10();
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))(&loc_7 + 1);
func9();
}
else if ( v0 == (__int64 (__fastcall *)(_QWORD))&loc_3 )
{
func5((unsigned __int8 *)sSpiInformation[3], (unsigned __int16)sSpiInformation[1]);
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))&loc_2;
deassert_cs();
}
}
else
{
sSpiInformation[2] = (__int64 (__fastcall *)(_QWORD))(SPIPump + 1);
}
}
}

original_code:
void CC3000InterruptHandler(void)
{
 if (!SPIInterruptsEnabled) {
  return;
  }
  if (sSpiInformation.ulSpiState == (0))
  {
    sSpiInformation.ulSpiState = (1);
  }
  else if (sSpiInformation.ulSpiState == (2))
  {
   sSpiInformation.ulSpiState = (6);
   assert_cs_and_wait();
          SpiReadHeader();
   sSpiInformation.ulSpiState = (8);
   SSIContReadOperation();
  }
  else if (sSpiInformation.ulSpiState == (3))
  {
   SpiWriteDataSynchronous(sSpiInformation.pTxPacket, sSpiInformation.usTxPacketLength);
   sSpiInformation.ulSpiState = (2);
   deassert_cs();
  }
  else {
   }
 }

canonical_original_code:
void CC3000InterruptHandler()
{
 if (!SPIInterruptsEnabled) {
  return;
  }
  if (sSpiInformation.ulSpiState == (0))
  {
    sSpiInformation.ulSpiState = (1);
  }
  else if (sSpiInformation.ulSpiState == (2))
  {
   sSpiInformation.ulSpiState = (6);
   assert_cs_and_wait();
          SpiReadHeader();
   sSpiInformation.ulSpiState = (8);
   SSIContReadOperation();
  }
  else if (sSpiInformation.ulSpiState == (3))
  {
   SpiWriteDataSynchronous(sSpiInformation.pTxPacket, sSpiInformation.usTxPacketLength);
   sSpiInformation.ulSpiState = (2);
   deassert_cs();
  }
  else {
   }
 }


SpiOpen

decompiled_code:
__int64 __fastcall SpiOpen(__int64 (__fastcall *a1)(_QWORD))
{
sSpiInformation[2] = 0LL;
memset(&spi_buffer, 0, 0x80uLL);
*((_WORD *)&spi_buffer + 64) = 0;
memset(wlan_tx_buffer, 0, 0x80uLL);
*(_WORD *)&wlan_tx_buffer[128] = 0;
sSpiInformation[0] = a1;
LOWORD(sSpiInformation[1]) = 0;
sSpiInformation[3] = 0LL;
sSpiInformation[4] = (__int64 (__fastcall *)(_QWORD))&spi_buffer;
WORD1(sSpiInformation[1]) = 0;
*((_BYTE *)&spi_buffer + 130) = -34;
wlan_tx_buffer[130] = -34;
return ((__int64 (__fastcall *)(_BYTE *, __int64 (__fastcall *)(_QWORD), _BYTE *))tSLInformation[8])(
&wlan_tx_buffer[128],
a1,
wlan_tx_buffer);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 (__fastcall *a1)(_QWORD))
{
sSpiInformation[2] = 0LL;
memset(&spi_buffer, 0, 0x80uLL);
*((_WORD *)&spi_buffer + 64) = 0;
memset(wlan_tx_buffer, 0, 0x80uLL);
*(_WORD *)&wlan_tx_buffer[128] = 0;
sSpiInformation[0] = a1;
LOWORD(sSpiInformation[1]) = 0;
sSpiInformation[3] = 0LL;
sSpiInformation[4] = (__int64 (__fastcall *)(_QWORD))&spi_buffer;
WORD1(sSpiInformation[1]) = 0;
*((_BYTE *)&spi_buffer + 130) = -34;
wlan_tx_buffer[130] = -34;
return ((__int64 (__fastcall *)(_BYTE *, __int64 (__fastcall *)(_QWORD), _BYTE *))tSLInformation[8])(
&wlan_tx_buffer[128],
a1,
wlan_tx_buffer);
}

original_code:
void
SpiOpen(gcSpiHandleRx pfRxHandler)
{
 sSpiInformation.ulSpiState = (0);
        memset(spi_buffer, 0, sizeof(spi_buffer));
        memset(wlan_tx_buffer, 0, sizeof(spi_buffer));
 sSpiInformation.SPIRxHandler = pfRxHandler;
 sSpiInformation.usTxPacketLength = 0;
 sSpiInformation.pTxPacket = ((void *)0);
 sSpiInformation.pRxPacket = (unsigned char *)spi_buffer;
 sSpiInformation.usRxPacketLength = 0;
 spi_buffer[((130 + 1)) - 1] = (0xDE);
 wlan_tx_buffer[((130 + 1)) - 1] = (0xDE);
 tSLInformation.WlanInterruptEnable();
}

canonical_original_code:
void SpiOpen(void (*pfRxHandler)(void *p))
{
 sSpiInformation.ulSpiState = (0);
        memset(spi_buffer, 0, sizeof(spi_buffer));
        memset(wlan_tx_buffer, 0, sizeof(spi_buffer));
 sSpiInformation.SPIRxHandler = pfRxHandler;
 sSpiInformation.usTxPacketLength = 0;
 sSpiInformation.pTxPacket = ((void *)0);
 sSpiInformation.pRxPacket = (unsigned char *)spi_buffer;
 sSpiInformation.usRxPacketLength = 0;
 spi_buffer[((130 + 1)) - 1] = (0xDE);
 wlan_tx_buffer[((130 + 1)) - 1] = (0xDE);
 tSLInformation.WlanInterruptEnable();
}

variable_types:
pfRxHandler
void (*)(void *p)


SpiClose

decompiled_code:
__int64 SpiClose()
{
if ( sSpiInformation[4] )
sSpiInformation[4] = 0LL;
return tSLInformation[9]();
}

canonical_decompiled_code:
__int64 func13()
{
if ( sSpiInformation[4] )
sSpiInformation[4] = 0LL;
return tSLInformation[9]();
}

original_code:
void
SpiClose(void)
{
 if (sSpiInformation.pRxPacket)
 {
  sSpiInformation.pRxPacket = 0;
 }
    tSLInformation.WlanInterruptDisable();
}

canonical_original_code:
void SpiClose()
{
 if (sSpiInformation.pRxPacket)
 {
  sSpiInformation.pRxPacket = 0;
 }
    tSLInformation.WlanInterruptDisable();
}


decompiled_code:
__int64 netapp_config_mac_adrress()
{
return (unsigned __int8)nvmem_set_mac_address();
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned __int8)nvmem_set_mac_address();
}

original_code:
long netapp_config_mac_adrress(unsigned char * mac)
{
 return nvmem_set_mac_address(mac);
}

canonical_original_code:
long netapp_config_mac_adrress(unsigned char *mac)
{
 return nvmem_set_mac_address(mac);
}

variable_types:
mac
unsigned char *


original_code:
long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask,unsigned long *aucDefaultGateway, unsigned long *aucDNSServer)
{
 signed char scRet;
 unsigned char *ptr;
 unsigned char *args;
 scRet = -1;
 ptr = tSLInformation.pucTxCommandBuffer;
 args = (ptr + ((5) + (4)));
 {register unsigned short _i; for (_i = 0; _i < 4; _i++) *(args)++ = ((unsigned char *) aucIP)[_i];};
 {register unsigned short _i; for (_i = 0; _i < 4; _i++) *(args)++ = ((unsigned char *) aucSubnetMask)[_i];};
 {register unsigned short _i; for (_i = 0; _i < 4; _i++) *(args)++ = ((unsigned char *) aucDefaultGateway)[_i];};
 args = (UINT32_TO_STREAM_f(args, 0));
 {register unsigned short _i; for (_i = 0; _i < 4; _i++) *(args)++ = ((unsigned char *) aucDNSServer)[_i];};
 hci_command_send((0x0001 + 0x2000), ptr, (20));
 SimpleLinkWaitEvent((0x0001 + 0x2000), &scRet);
 return(scRet);
}

canonical_original_code:
long netapp_dhcp(unsigned long *aucIP, unsigned long *aucSubnetMask, unsigned long *aucDefaultGateway, unsigned long *aucDNSServer)
{
 char scRet;
 unsigned char *ptr;
 unsigned char *args;
 scRet = -1;
 ptr = tSLInformation.pucTxCommandBuffer;
 args = (ptr + ((5) + (4)));
 {register unsigned short _i; for (_i = 0; _i < 4; _i++) *(args)++ = ((unsigned char *) aucIP)[_i];};
 {register unsigned short _i; for (_i = 0; _i < 4; _i++) *(args)++ = ((unsigned char *) aucSubnetMask)[_i];};
 {register unsigned short _i; for (_i = 0; _i < 4; _i++) *(args)++ = ((unsigned char *) aucDefaultGateway)[_i];};
 args = (UINT32_TO_STREAM_f(args, 0));
 {register unsigned short _i; for (_i = 0; _i < 4; _i++) *(args)++ = ((unsigned char *) aucDNSServer)[_i];};
 hci_command_send((0x0001 + 0x2000), ptr, (20));
 SimpleLinkWaitEvent((0x0001 + 0x2000), &scRet);
 return(scRet);
}

variable_types:
aucIP
unsigned long *

variable_types:
aucSubnetMask
unsigned long *

variable_types:
aucDefaultGateway
unsigned long *

variable_types:
aucDNSServer
unsigned long *

variable_types: scRet char

variable_types:
ptr
unsigned char *

variable_types:
args
unsigned char *


decompiled_code:
__int64 __fastcall netapp_timeout_values(_QWORD *a1, _QWORD *a2, _QWORD *a3, _QWORD *a4)
{
__int64 v6; // r13
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
char v11[41]; // [rsp+Fh] [rbp-29h] BYREF

v11[0] = -1;
v6 = tSLInformation[2];
if ( (unsigned __int64)(*a1 - 1LL) <= 0x12 )
*a1 = 20LL;
if ( (unsigned __int64)(*a2 - 1LL) <= 0x12 )
*a2 = 20LL;
if ( (unsigned __int64)(*a3 - 1LL) <= 0x12 )
*a3 = 20LL;
if ( (unsigned __int64)(*a4 - 1LL) <= 0x12 )
*a4 = 20LL;
v7 = UINT32_TO_STREAM_f(v6 + 9, *a1);
v8 = UINT32_TO_STREAM_f(v7, *a2);
v9 = UINT32_TO_STREAM_f(v8, *a3);
UINT32_TO_STREAM_f(v9, *a4);
hci_command_send(8201LL, v6, 20LL);
SimpleLinkWaitEvent(8201LL, v11);
return v11[0];
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, _QWORD *a2, _QWORD *a3, _QWORD *a4)
{
__int64 v6; // r13
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
char v11[41]; // [rsp+Fh] [rbp-29h] BYREF

v11[0] = -1;
v6 = tSLInformation[2];
if ( (unsigned __int64)(*a1 - 1LL) <= 0x12 )
*a1 = 20LL;
if ( (unsigned __int64)(*a2 - 1LL) <= 0x12 )
*a2 = 20LL;
if ( (unsigned __int64)(*a3 - 1LL) <= 0x12 )
*a3 = 20LL;
if ( (unsigned __int64)(*a4 - 1LL) <= 0x12 )
*a4 = 20LL;
v7 = UINT32_TO_STREAM_f(v6 + 9, *a1);
v8 = UINT32_TO_STREAM_f(v7, *a2);
v9 = UINT32_TO_STREAM_f(v8, *a3);
UINT32_TO_STREAM_f(v9, *a4);
hci_command_send(8201LL, v6, 20LL);
SimpleLinkWaitEvent(8201LL, v11);
return v11[0];
}

original_code:
long
netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP,unsigned long *aucKeepalive, unsigned long *aucInactivity)
{
 signed char scRet;
 unsigned char *ptr;
 unsigned char *args;
 scRet = -1;
 ptr = tSLInformation.pucTxCommandBuffer;
 args = (ptr + ((5) + (4)));
 if ((0 != *aucDHCP) && (*aucDHCP < 20)) { *aucDHCP = 20; }
    if ((0 != *aucARP) && (*aucARP < 20)) { *aucARP = 20; }
 if ((0 != *aucKeepalive) && (*aucKeepalive < 20)) { *aucKeepalive = 20; }
 if ((0 != *aucInactivity) && (*aucInactivity < 20)) { *aucInactivity = 20; }
 args = (UINT32_TO_STREAM_f(args, *aucDHCP));
 args = (UINT32_TO_STREAM_f(args, *aucARP));
 args = (UINT32_TO_STREAM_f(args, *aucKeepalive));
 args = (UINT32_TO_STREAM_f(args, *aucInactivity));
 hci_command_send((0x0009 + 0x2000), ptr, (20));
 SimpleLinkWaitEvent((0x0009 + 0x2000), &scRet);
 return(scRet);
}

canonical_original_code:
long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP, unsigned long *aucKeepalive, unsigned long *aucInactivity)
{
 char scRet;
 unsigned char *ptr;
 unsigned char *args;
 scRet = -1;
 ptr = tSLInformation.pucTxCommandBuffer;
 args = (ptr + ((5) + (4)));
 if ((0 != *aucDHCP) && (*aucDHCP < 20)) { *aucDHCP = 20; }
    if ((0 != *aucARP) && (*aucARP < 20)) { *aucARP = 20; }
 if ((0 != *aucKeepalive) && (*aucKeepalive < 20)) { *aucKeepalive = 20; }
 if ((0 != *aucInactivity) && (*aucInactivity < 20)) { *aucInactivity = 20; }
 args = (UINT32_TO_STREAM_f(args, *aucDHCP));
 args = (UINT32_TO_STREAM_f(args, *aucARP));
 args = (UINT32_TO_STREAM_f(args, *aucKeepalive));
 args = (UINT32_TO_STREAM_f(args, *aucInactivity));
 hci_command_send((0x0009 + 0x2000), ptr, (20));
 SimpleLinkWaitEvent((0x0009 + 0x2000), &scRet);
 return(scRet);
}

variable_types:
aucDHCP
unsigned long *

variable_types:
aucARP
unsigned long *

variable_types:
aucKeepalive
unsigned long *

variable_types:
aucInactivity
unsigned long *