decompiled_code:
int display_files()
{
unsigned int v0; // ebx

v0 = 0;
puts(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ");
do
{
printf("%d -> testdata/file%d.txt\n", v0, v0);
++v0;
}
while ( v0 != 20 );
return puts(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ");
}

canonical_decompiled_code:
int func2()
{
unsigned int v0; // ebx

v0 = 0;
puts(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ");
do
{
printf("%d -> testdata/file%d.txt\n", v0, v0);
++v0;
}
while ( v0 != 20 );
return puts(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ");
}

original_code:
void display_files() {
 int i;
 printf(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \n");
 for(i = 0; i < 20; i++) {
  printf("%d -> testdata/file%d.txt\n", i, i);
 }
 printf(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \n");
}


decompiled_code:
int __fastcall read_file(__int64 a1, __int64 a2)
{
int v2; // ebx
int v3; // eax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

display_files();
printf("Select file :");
_isoc99_scanf("%d", v5);
v2 = clock();
LRU_read(v5[0], a1, a2);
v3 = clock();
return printf("Read time : %.3f cpu sec\n", ((double)v3 - (double)v2) * 0.000001);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2)
{
int v2; // ebx
int v3; // eax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

func2();
printf("Select file :");
_isoc99_scanf("%d", v5);
v2 = clock();
LRU_read(v5[0], a1, a2);
v3 = clock();
return printf("Read time : %.3f cpu sec\n", ((double)v3 - (double)v2) * 0.000001);
}

original_code:
void
read_file(dlq_hdl_t *q_hdl, hash_hdl_t *h_hdl) {
 int i;
 int file_ch;
 clock_t cstart, cend;
 LRU_queue_data_t *q_data = ((void *)0);
 display_files();
 printf("Select file :");
 scanf("%d", &file_ch);
 if(file_ch < 0 && file_ch > 20) {
  printf("Invalid file choice\n");
  return;
 }
 cstart = clock();
 q_data = LRU_read(file_ch, q_hdl, h_hdl);
 cend = clock();
 printf("Read time : %.3f cpu sec\n",
   ((double)cend -(double)cstart)*1.0e-6);
}

canonical_original_code:
void read_file(struct dlq_hdl *q_hdl, struct hash_hdl *h_hdl) {
 int i;
 int file_ch;
 long cstart; long cend;
 struct LRU_queue_data *q_data = ((void *)0);
 display_files();
 printf("Select file :");
 scanf("%d", &file_ch);
 if(file_ch < 0 && file_ch > 20) {
  printf("Invalid file choice\n");
  return;
 }
 cstart = clock();
 q_data = LRU_read(file_ch, q_hdl, h_hdl);
 cend = clock();
 printf("Read time : %.3f cpu sec\n",
   ((double)cend -(double)cstart)*1.0e-6);
}

variable_types: struct dlq_hdl { struct dlq_node { struct dlq_node *next; struct dlq_node *prev; void *data; } *first; struct dlq_node *last; int capacity; int size; } *

variable_types: struct hash_hdl { int M; int size; struct hash_node { struct hash_node *next; void *key; void *data; } **array; int (*comparefn)(void *key1, void *key2); int (*hashfn)(struct hash_hdl *, void *key); } *

variable_types: i int

variable_types: cstart long

variable_types: cend long

variable_types: struct LRU_queue_data { char *filedata; int filedatalen; struct LRU_hash_key { char *hash_key_filename; int hash_key_filename_len; } *filekey; } *

return_type: void

user_defined_types: struct dlq_hdl { struct dlq_node *first; struct dlq_node *last; int capacity; int size; }

user_defined_types: struct hash_hdl { int M; int size; struct hash_node **array; int (*comparefn)(void *key1, void *key2); int (*hashfn)(struct hash_hdl *, void *key); }

user_defined_types: struct LRU_queue_data { char *filedata; int filedatalen; struct LRU_hash_key *filekey; }


decompiled_code:
// attributes: thunk
__int64 print_hashtable()
{
return hash_printstring();
}

canonical_decompiled_code:
__int64 func4()
{
return hash_printstring();
}

original_code:
void
print_hashtable(hash_hdl_t *hdl) {
 hash_printstring(hdl);
}

canonical_original_code:
void print_hashtable(struct hash_hdl *hdl) {
 hash_printstring(hdl);
}

user_defined_types: struct hash_node { struct hash_node *next; void *key; void *data; }


decompiled_code:
// attributes: thunk
__int64 print_LRUcache()
{
return dlq_printstring();
}

canonical_decompiled_code:
__int64 func5()
{
return dlq_printstring();
}

original_code:
void
print_LRUcache(dlq_hdl_t *hdl) {
 dlq_printstring(hdl);
}

canonical_original_code:
void print_LRUcache(struct dlq_hdl *hdl) {
 dlq_printstring(hdl);
}

user_defined_types: struct dlq_node { struct dlq_node *next; struct dlq_node *prev; void *data; }


decompiled_code:
__int64 __fastcall tst_hash(_DWORD *a1, char **a2)
{
int v2; // eax
char *v4; // rsi
__int64 v5; // rdi
int v6; // eax
char *v7; // rcx
char *v8; // rdi
int v9; // edx
int v10; // eax

v2 = *((_DWORD *)a2 + 2);
if ( v2 <= 0 )
return (unsigned int)(17 % *a1);
v4 = *a2;
v5 = (unsigned int)(v2 - 1);
v6 = 17;
v7 = v4 + 1;
v8 = &v4[v5 + 1];
while ( 1 )
{
v9 = 31 * v6;
v10 = *v4;
v4 = v7;
v6 = v9 + v10;
if ( v8 == v7 )
break;
++v7;
}
return (unsigned int)((v6 & 0x7FFFFFF) % *a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, char **a2)
{
int v2; // eax
char *v4; // rsi
__int64 v5; // rdi
int v6; // eax
char *v7; // rcx
char *v8; // rdi
int v9; // edx
int v10; // eax

v2 = *((_DWORD *)a2 + 2);
if ( v2 <= 0 )
return (unsigned int)(17 % *a1);
v4 = *a2;
v5 = (unsigned int)(v2 - 1);
v6 = 17;
v7 = v4 + 1;
v8 = &v4[v5 + 1];
while ( 1 )
{
v9 = 31 * v6;
v10 = *v4;
v4 = v7;
v6 = v9 + v10;
if ( v8 == v7 )
break;
++v7;
}
return (unsigned int)((v6 & 0x7FFFFFF) % *a1);
}

original_code:
static int
tst_hash(hash_hdl_t *hdl, void *key) {
 LRU_hash_key_t *k1;
 int i = 0;
 int hash = 17;
 k1 = (LRU_hash_key_t *)key;
 for(i = 0; i < k1->hash_key_filename_len; i++) {
  hash = hash*31 + (int)k1->hash_key_filename[i];
 }
 return (hash & 0x7ffffff) % (hdl->M);
}

canonical_original_code:
static int tst_hash(struct hash_hdl *hdl, void *key) {
 struct LRU_hash_key *k1;
 int i = 0;
 int hash = 17;
 k1 = (struct LRU_hash_key *)key;
 for(i = 0; i < k1->hash_key_filename_len; i++) {
  hash = hash*31 + (int)k1->hash_key_filename[i];
 }
 return (hash & 0x7ffffff) % (hdl->M);
}

variable_types:
key
void *

variable_types: struct LRU_hash_key { char *hash_key_filename; int hash_key_filename_len; } *

variable_types: hash int

return_type: int


decompiled_code:
int __fastcall tst_hash_compare(__int64 a1, __int64 a2)
{
size_t v2; // rdx
int result; // eax

v2 = *(int *)(a1 + 8);
if ( (_DWORD)v2 == *(_DWORD *)(a2 + 8) )
result = strncmp(*(const char **)a1, *(const char **)a2, v2);
else
result = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
size_t v2; // rdx
int result; // eax

v2 = *(int *)(a1 + 8);
if ( (_DWORD)v2 == *(_DWORD *)(a2 + 8) )
result = strncmp(*(const char **)a1, *(const char **)a2, v2);
else
result = -1;
return result;
}

original_code:
static int
tst_hash_compare(void *key1, void *key2) {
 LRU_hash_key_t *k1, *k2;
 k1 = (LRU_hash_key_t *)key1;
 k2 = (LRU_hash_key_t *)key2;
 if(k1->hash_key_filename_len != k2->hash_key_filename_len) {
  return -1;
 }
 return strncmp(k1->hash_key_filename, k2->hash_key_filename,
  k1->hash_key_filename_len);
}

canonical_original_code:
static int tst_hash_compare(void *key1, void *key2) {
 struct LRU_hash_key *k1; struct LRU_hash_key *k2;
 k1 = (struct LRU_hash_key *)key1;
 k2 = (struct LRU_hash_key *)key2;
 if(k1->hash_key_filename_len != k2->hash_key_filename_len) {
  return -1;
 }
 return strncmp(k1->hash_key_filename, k2->hash_key_filename,
  k1->hash_key_filename_len);
}

user_defined_types: struct LRU_hash_key { char *hash_key_filename; int hash_key_filename_len; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // r13
void **v6; // rax
void ***v7; // rbp
int v9; // [rsp+8h] [rbp-20h] BYREF
int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

printf("Enter LRU capacity:");
_isoc99_scanf("%d", v10);
v3 = dlq_create((unsigned int)v10[0]);
if ( !v3 )
return 1;
v4 = v3;
printf("Enter hash buckets:");
_isoc99_scanf("%d", v10);
v5 = hash_create((unsigned int)v10[0], tst_hash_compare, tst_hash);
if ( !v5 )
return 1;
while ( 1 )
{
puts("1 - Read file.");
puts("2 - Print hashtable ");
puts("3 - Print LRU Cache ");
_isoc99_scanf("%d", &v9);
if ( v9 == 2 )
{
print_hashtable(v5);
goto LABEL_10;
}
if ( v9 == 3 )
{
print_LRUcache(v4);
goto LABEL_10;
}
if ( v9 != 1 )
break;
read_file(v4, v5);
LABEL_10:
if ( (unsigned int)(v9 - 1) > 2 )
return 1;
}
while ( 1 )
{
v6 = (void **)dlq_dequeue(v4);
v7 = (void ***)v6;
if ( !v6 )
break;
free(*v6);
free(*v7[2]);
free(v7[2]);
free(v7);
}
dlq_destroy(v4);
hash_destroy(v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // r13
void **v6; // rax
void ***v7; // rbp
int v9; // [rsp+8h] [rbp-20h] BYREF
int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

printf("Enter LRU capacity:");
_isoc99_scanf("%d", v10);
v3 = dlq_create((unsigned int)v10[0]);
if ( !v3 )
return 1;
v4 = v3;
printf("Enter hash buckets:");
_isoc99_scanf("%d", v10);
v5 = hash_create((unsigned int)v10[0], tst_hash_compare, tst_hash);
if ( !v5 )
return 1;
while ( 1 )
{
puts("1 - Read file.");
puts("2 - Print hashtable ");
puts("3 - Print LRU Cache ");
_isoc99_scanf("%d", &v9);
if ( v9 == 2 )
{
func4(v5);
goto LABEL_10;
}
if ( v9 == 3 )
{
func5(v4);
goto LABEL_10;
}
if ( v9 != 1 )
break;
func3(v4, v5);
LABEL_10:
if ( (unsigned int)(v9 - 1) > 2 )
return 1;
}
while ( 1 )
{
v6 = (void **)dlq_dequeue(v4);
v7 = (void ***)v6;
if ( !v6 )
break;
free(*v6);
free(*v7[2]);
free(v7[2]);
free(v7);
}
dlq_destroy(v4);
hash_destroy(v5);
return 0;
}

original_code:
int main() {
 int ch;
 int capacity;
 LRU_queue_data_t *free_q_data;
 dlq_hdl_t *q_hdl;
 printf("Enter LRU capacity:");
 scanf("%d", &capacity);
 q_hdl = dlq_create(capacity);
 if(q_hdl == ((void *)0)) {
  return 1;
 }
 hash_hdl_t *h_hdl;
 printf("Enter hash buckets:");
 scanf("%d", &capacity);
 h_hdl = hash_create(capacity, tst_hash_compare, tst_hash);
 if(h_hdl == ((void *)0)) {
  return 1;
 }
 do {
  printf("1 - Read file.\n");
  printf("2 - Print hashtable \n");
  printf("3 - Print LRU Cache \n");
  scanf("%d", &ch);
  switch(ch) {
  case 1:
   read_file(q_hdl, h_hdl);
   break;
  case 2:
   print_hashtable(h_hdl);
   break;
  case 3:
   print_LRUcache(q_hdl);
   break;
  default:
   free_q_data = ((void *)0);
   while((free_q_data =
   (LRU_queue_data_t *)dlq_dequeue(q_hdl)) != ((void *)0)) {
    free(free_q_data->filedata);
    free_q_data->filedata = ((void *)0);
    free(free_q_data->filekey->hash_key_filename);
    free_q_data->filekey->hash_key_filename = ((void *)0);
    free(free_q_data->filekey);
    free_q_data->filekey = ((void *)0);
    free(free_q_data);
    free_q_data = ((void *)0);
   }
   dlq_destroy(q_hdl);
   q_hdl = ((void *)0);
   hash_destroy(h_hdl);
   h_hdl = ((void *)0);
   return 0;
  }
 }while (ch > 0 && ch < 4);
 return 1;
}

canonical_original_code:
int main() {
 int ch;
 int capacity;
 struct LRU_queue_data *free_q_data;
 struct dlq_hdl *q_hdl;
 printf("Enter LRU capacity:");
 scanf("%d", &capacity);
 q_hdl = dlq_create(capacity);
 if(q_hdl == ((void *)0)) {
  return 1;
 }
 struct hash_hdl *h_hdl;
 printf("Enter hash buckets:");
 scanf("%d", &capacity);
 h_hdl = hash_create(capacity, tst_hash_compare, tst_hash);
 if(h_hdl == ((void *)0)) {
  return 1;
 }
 do {
  printf("1 - Read file.\n");
  printf("2 - Print hashtable \n");
  printf("3 - Print LRU Cache \n");
  scanf("%d", &ch);
  switch(ch) {
  case 1:
   read_file(q_hdl, h_hdl);
   break;
  case 2:
   print_hashtable(h_hdl);
   break;
  case 3:
   print_LRUcache(q_hdl);
   break;
  default:
   free_q_data = ((void *)0);
   while((free_q_data =
   (struct LRU_queue_data *)dlq_dequeue(q_hdl)) != ((void *)0)) {
    free(free_q_data->filedata);
    free_q_data->filedata = ((void *)0);
    free(free_q_data->filekey->hash_key_filename);
    free_q_data->filekey->hash_key_filename = ((void *)0);
    free(free_q_data->filekey);
    free_q_data->filekey = ((void *)0);
    free(free_q_data);
    free_q_data = ((void *)0);
   }
   dlq_destroy(q_hdl);
   q_hdl = ((void *)0);
   hash_destroy(h_hdl);
   h_hdl = ((void *)0);
   return 0;
  }
 }while (ch > 0 && ch < 4);
 return 1;
}

variable_types: ch int

variable_types: capacity int


decompiled_code:
_QWORD *queue_create()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

canonical_decompiled_code:
_QWORD *func11()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

original_code:
queue_hdl_t *
queue_create() {
 queue_hdl_t *hdl;
 hdl = (queue_hdl_t *)malloc(sizeof(queue_hdl_t));
 if(hdl == ((void *)0)) {
  return ((void *)0);
 }
 hdl->first = ((void *)0);
 hdl->last = ((void *)0);
 hdl->size = 0;
 return hdl;
}

canonical_original_code:
struct queue_hdl *queue_create() {
 struct queue_hdl *hdl;
 hdl = (struct queue_hdl *)malloc(sizeof(queue_hdl_t));
 if(hdl == ((void *)0)) {
  return ((void *)0);
 }
 hdl->first = ((void *)0);
 hdl->last = ((void *)0);
 hdl->size = 0;
 return hdl;
}

variable_types: struct queue_hdl { struct queue_node { struct queue_node *next; void *data; } *first; struct queue_node *last; int size; } *

user_defined_types: struct queue_hdl { struct queue_node *first; struct queue_node *last; int size; }


decompiled_code:
// attributes: thunk
void queue_destroy(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func12(void *ptr)
{
free(ptr);
}

original_code:
void
queue_destroy(queue_hdl_t *hdl) {
 free(hdl);
 hdl = ((void *)0);
}

canonical_original_code:
void queue_destroy(struct queue_hdl *hdl) {
 free(hdl);
 hdl = ((void *)0);
}

user_defined_types: struct queue_node { struct queue_node *next; void *data; }


original_code:
void
queue_enqueue(queue_hdl_t *hdl, void *data) {
 queue_node_t *newnode;
 if(hdl == ((void *)0)) {
  return;
 }
 newnode = (queue_node_t *)malloc(sizeof(queue_node_t));
 if(newnode == ((void *)0)) {
  return;
 }
 hdl->size++;
 newnode->data = data;
 newnode->next = ((void *)0);
 if(hdl->last == ((void *)0)) {
  hdl->last = newnode;
  hdl->first = newnode;
  return;
 }
 hdl->last->next = newnode;
 hdl->last = newnode;
 return;
}

canonical_original_code:
void queue_enqueue(struct queue_hdl *hdl, void *data) {
 struct queue_node *newnode;
 if(hdl == ((void *)0)) {
  return;
 }
 newnode = (struct queue_node *)malloc(sizeof(queue_node_t));
 if(newnode == ((void *)0)) {
  return;
 }
 hdl->size++;
 newnode->data = data;
 newnode->next = ((void *)0);
 if(hdl->last == ((void *)0)) {
  hdl->last = newnode;
  hdl->first = newnode;
  return;
 }
 hdl->last->next = newnode;
 hdl->last = newnode;
 return;
}

variable_types:
data
void *

variable_types: struct queue_node { struct queue_node *next; void *data; } *


original_code:
void *
queue_dequeue(queue_hdl_t *hdl) {
 queue_node_t *qnodep;
 void *data;
 if(hdl == ((void *)0)) {
  return ((void *)0);
 }
 qnodep = hdl->first;
 if(qnodep == ((void *)0)) {
  return ((void *)0);
 }
 if(qnodep == hdl->last) {
  hdl->last = ((void *)0);
 }
 hdl->first = qnodep->next;
 hdl->size--;
 data = qnodep->data;
 free(qnodep);
 qnodep = ((void *)0);
 return data;
}

canonical_original_code:
void *queue_dequeue(struct queue_hdl *hdl) {
 struct queue_node *qnodep;
 void *data;
 if(hdl == ((void *)0)) {
  return ((void *)0);
 }
 qnodep = hdl->first;
 if(qnodep == ((void *)0)) {
  return ((void *)0);
 }
 if(qnodep == hdl->last) {
  hdl->last = ((void *)0);
 }
 hdl->first = qnodep->next;
 hdl->size--;
 data = qnodep->data;
 free(qnodep);
 qnodep = ((void *)0);
 return data;
}

return_type: void *


decompiled_code:
__int64 __fastcall queue_size(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int
queue_size(queue_hdl_t *hdl) {
 return hdl->size;
}

canonical_original_code:
int queue_size(struct queue_hdl *hdl) {
 return hdl->size;
}


decompiled_code:
int __fastcall queue_printstring(_QWORD **a1)
{
_QWORD *i; // rax

for ( i = *a1; i; i = (_QWORD *)*i )
;
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func16(_QWORD **a1)
{
_QWORD *i; // rax

for ( i = *a1; i; i = (_QWORD *)*i )
;
return putchar(10);
}

original_code:
void
queue_printstring(queue_hdl_t *hdl) {
 queue_node_t *s;
 s = hdl->first;
 while(s != ((void *)0)) {
  s = s->next;
 }
 printf("\n");
}

canonical_original_code:
void queue_printstring(struct queue_hdl *hdl) {
 struct queue_node *s;
 s = hdl->first;
 while(s != ((void *)0)) {
  s = s->next;
 }
 printf("\n");
}


repo: onesuper/blasteroid

decompiled_code:
float __fastcall random_float(float a1)
{
return (float)rand() / (float)(2147483600.0 / a1);
}

canonical_decompiled_code:
float __fastcall func0(float a1)
{
return (float)rand() / (float)(2147483600.0 / a1);
}

original_code:
float random_float(float range) {
    return (float)rand() / ((float)2147483647 / range);
}

variable_types: range float

return_type: float


decompiled_code:
void __fastcall point_rotate(float *a1, __m128i a2, float a3)
{
double v3; // xmm0_8
float v4; // xmm2_4
float v5; // xmm0_4
double v6; // [rsp+0h] [rbp-38h]
float v7; // [rsp+8h] [rbp-30h]
double v8; // [rsp+8h] [rbp-30h]
double v9; // [rsp+10h] [rbp-28h]
float v10; // [rsp+18h] [rbp-20h]
double cosx; // [rsp+20h] [rbp-18h] BYREF
double sinx[2]; // [rsp+28h] [rbp-10h] BYREF

v7 = COERCE_FLOAT(_mm_cvtsi128_si32(a2));
v10 = *(float *)&a2.m128i_i32[1];
v6 = (float)(*a1 - v7);
sincos(COERCE_FLOAT(LODWORD(a3) ^ LC1), sinx, &cosx);
v3 = v7;
v9 = cosx;
v8 = (float)(a1[1] - v10);
v4 = v6 * cosx + v3 + v8 * sinx[0];
*a1 = v4;
v5 = sin(a3) * v6 + v10 + v8 * v9;
a1[1] = v5;
}

canonical_decompiled_code:
void __fastcall func1(float *a1, __m128i a2, float a3)
{
double v3; // xmm0_8
float v4; // xmm2_4
float v5; // xmm0_4
double v6; // [rsp+0h] [rbp-38h]
float v7; // [rsp+8h] [rbp-30h]
double v8; // [rsp+8h] [rbp-30h]
double v9; // [rsp+10h] [rbp-28h]
float v10; // [rsp+18h] [rbp-20h]
double cosx; // [rsp+20h] [rbp-18h] BYREF
double sinx[2]; // [rsp+28h] [rbp-10h] BYREF

v7 = COERCE_FLOAT(_mm_cvtsi128_si32(a2));
v10 = *(float *)&a2.m128i_i32[1];
v6 = (float)(*a1 - v7);
sincos(COERCE_FLOAT(LODWORD(a3) ^ LC1), sinx, &cosx);
v3 = v7;
v9 = cosx;
v8 = (float)(a1[1] - v10);
v4 = v6 * cosx + v3 + v8 * sinx[0];
*a1 = v4;
v5 = sin(a3) * v6 + v10 + v8 * v9;
a1[1] = v5;
}

original_code:
void point_rotate(Point *p, Point center, float theta) {
    float x = p->x;
    float y = p->y;
    p->x = center.x + (x - center.x) * cos(-theta) + (y - center.y) * sin(-theta);
    p->y = center.y - (x - center.x) * sin(-theta) + (y - center.y) * cos(-theta);
}

canonical_original_code:
void point_rotate(struct Point *p, struct Point center, float theta) {
    float x = p->x;
    float y = p->y;
    p->x = center.x + (x - center.x) * cos(-theta) + (y - center.y) * sin(-theta);
    p->y = center.y - (x - center.x) * sin(-theta) + (y - center.y) * cos(-theta);
}

variable_types:
p
struct Point { float x; float y; } *

variable_types:
center
struct Point

variable_types: theta float

variable_types: x float

variable_types: y float


project

decompiled_code:
double __fastcall project(double a1, __m128i a2)
{
__m128i v2; // xmm3
unsigned __int64 v3; // rax
float v4; // xmm1_4
__int64 v5; // xmm0_8
double result; // xmm0_8

v2 = a2;
v3 = HIDWORD(a2.m128i_i64[0]);
v4 = *(float *)&a1;
v5 = HIDWORD(*(_QWORD *)&a1);
*(float *)&v5 = (float)((float)(*(float *)&v5 * *(float *)&v3) + (float)(v4 * *(float *)v2.m128i_i32))
/ (float)((float)(*(float *)v2.m128i_i32 * *(float *)v2.m128i_i32)
+ (float)(*(float *)&v3 * *(float *)&v3));
*(float *)v2.m128i_i32 = *(float *)v2.m128i_i32 * *(float *)&v5;
*(float *)&v5 = *(float *)&v5 * *(float *)&v3;
*(_QWORD *)&result = (v5 << 32) | (unsigned int)_mm_cvtsi128_si32(v2);
return result;
}

canonical_decompiled_code:
double __fastcall func2(double a1, __m128i a2)
{
__m128i v2; // xmm3
unsigned __int64 v3; // rax
float v4; // xmm1_4
__int64 v5; // xmm0_8
double result; // xmm0_8

v2 = a2;
v3 = HIDWORD(a2.m128i_i64[0]);
v4 = *(float *)&a1;
v5 = HIDWORD(*(_QWORD *)&a1);
*(float *)&v5 = (float)((float)(*(float *)&v5 * *(float *)&v3) + (float)(v4 * *(float *)v2.m128i_i32))
/ (float)((float)(*(float *)v2.m128i_i32 * *(float *)v2.m128i_i32)
+ (float)(*(float *)&v3 * *(float *)&v3));
*(float *)v2.m128i_i32 = *(float *)v2.m128i_i32 * *(float *)&v5;
*(float *)&v5 = *(float *)&v5 * *(float *)&v3;
*(_QWORD *)&result = (v5 << 32) | (unsigned int)_mm_cvtsi128_si32(v2);
return result;
}

original_code:
Point project(Point A, Point B) {
    Point p;
    float scalar = A.x * B.x + A.y * B.y;
    scalar /= B.x * B.x + B.y * B.y;
    p.x = scalar * B.x;
    p.y = scalar * B.y;
    return p;
}

canonical_original_code:
struct Point project(struct Point A, struct Point B) {
    struct Point p;
    float scalar = A.x * B.x + A.y * B.y;
    scalar /= B.x * B.x + B.y * B.y;
    p.x = scalar * B.x;
    p.y = scalar * B.y;
    return p;
}

variable_types:
A
struct Point

variable_types:
B
struct Point

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

variable_types: scalar float

return_type: struct Point { float x; float y; }


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; }


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


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 v5; // xmm4_4

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

canonical_decompiled_code:
float __fastcall func6(float a1, float a2, float a3, float a4)
{
float v4; // xmm1_4
float v5; // xmm4_4

func4(a1, a2);
v4 = func4(a3, a4);
return func4(v5, 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 v5; // xmm4_4

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

canonical_decompiled_code:
float __fastcall func7(float a1, float a2, float a3, float a4)
{
float v4; // xmm1_4
float v5; // xmm4_4

func5(a1, a2);
v4 = func5(a3, a4);
return func5(v5, 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:
__int16 ls()
{
__int64 v0; // rbp
__int16 result; // ax
int v2; // ebx
const char *v3; // rbp
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 )
{
v2 = 1;
printf("%s\t", v5);
v3 = &v6;
while ( v4 > v2 )
{
++v2;
printf("%s\t", v3);
if ( (unsigned int)(-858993459 * v2) <= 0x33333333 )
putchar(10);
v3 += 28;
}
result = -13107 * v4;
if ( (unsigned __int16)(-13107 * v4) > 0x3333u )
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
__int16 func0()
{
__int64 v0; // rbp
__int16 result; // ax
int v2; // ebx
const char *v3; // rbp
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 )
{
v2 = 1;
printf("%s\t", v5);
v3 = &v6;
while ( v4 > v2 )
{
++v2;
printf("%s\t", v3);
if ( (unsigned int)(-858993459 * v2) <= 0x33333333 )
putchar(10);
v3 += 28;
}
result = -13107 * v4;
if ( (unsigned __int16)(-13107 * v4) > 0x3333u )
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

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; // er12
__int64 v3; // r13
int v4; // er12
__int64 v5; // rbp
__m128i v6; // xmm0
FILE *v7; // rdi
__int64 v8; // rsi
unsigned __int16 *v9; // rdx
int v10; // ecx
char dest[16]; // [rsp+0h] [rbp-858h] BYREF
__int64 v12; // [rsp+10h] [rbp-848h]
int v13; // [rsp+18h] [rbp-840h]
__int16 ptr[2]; // [rsp+20h] [rbp-838h] BYREF
int v15; // [rsp+24h] [rbp-834h]
char v16[8]; // [rsp+28h] [rbp-830h] BYREF
unsigned __int16 v17[540]; // [rsp+420h] [rbp-438h] BYREF

if ( (unsigned int)namei() )
return puts("File or directory exists");
ptr[0] = 1;
strcpy(v16, "..");
v15 = 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 + 32) = v2;
v4 = *(_DWORD *)(v3 + 24);
*(_DWORD *)(v3 + 28) = 1;
*(_BYTE *)(v3 + 22) = 100;
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(v17, 1uLL, 0x3F4uLL, fd);
v6 = _mm_loadu_si128((const __m128i *)dest);
v7 = fd;
v8 = (unsigned int)(*(_DWORD *)(v5 + 32) << 10);
v9 = &v17[14 * v17[0]++];
*(_QWORD *)(v9 + 10) = v12;
v10 = v13;
*(__m128i *)(v9 + 2) = v6;
*((_DWORD *)v9 + 7) = v10;
fseek(v7, v8, 0);
fwrite(v17, 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; // er12
__int64 v3; // r13
int v4; // er12
__int64 v5; // rbp
__m128i v6; // xmm0
FILE *v7; // rdi
__int64 v8; // rsi
unsigned __int16 *v9; // rdx
int v10; // ecx
char dest[16]; // [rsp+0h] [rbp-858h] BYREF
__int64 v12; // [rsp+10h] [rbp-848h]
int v13; // [rsp+18h] [rbp-840h]
__int16 ptr[2]; // [rsp+20h] [rbp-838h] BYREF
int v15; // [rsp+24h] [rbp-834h]
char v16[8]; // [rsp+28h] [rbp-830h] BYREF
unsigned __int16 v17[540]; // [rsp+420h] [rbp-438h] BYREF

if ( (unsigned int)namei() )
return puts("File or directory exists");
ptr[0] = 1;
strcpy(v16, "..");
v15 = 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 + 32) = v2;
v4 = *(_DWORD *)(v3 + 24);
*(_DWORD *)(v3 + 28) = 1;
*(_BYTE *)(v3 + 22) = 100;
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(v17, 1uLL, 0x3F4uLL, fd);
v6 = _mm_loadu_si128((const __m128i *)dest);
v7 = fd;
v8 = (unsigned int)(*(_DWORD *)(v5 + 32) << 10);
v9 = &v17[14 * v17[0]++];
*(_QWORD *)(v9 + 10) = v12;
v10 = v13;
*(__m128i *)(v9 + 2) = v6;
*((_DWORD *)v9 + 7) = v10;
fseek(v7, v8, 0);
fwrite(v17, 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; // rbp
__int64 v3; // rbp
__m128i v4; // xmm0
FILE *v5; // rdi
__int64 v6; // rsi
unsigned __int16 *v7; // rdx
int v8; // ecx
char dest[16]; // [rsp+0h] [rbp-438h] BYREF
__int64 v11; // [rsp+10h] [rbp-428h]
int v12; // [rsp+18h] [rbp-420h]
unsigned __int16 ptr[524]; // [rsp+20h] [rbp-418h] BYREF

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(ptr, 1uLL, 0x3F4uLL, fd);
v4 = _mm_loadu_si128((const __m128i *)dest);
v5 = fd;
v6 = (unsigned int)(*(_DWORD *)(v3 + 32) << 10);
v7 = &ptr[14 * ptr[0]++];
*(_QWORD *)(v7 + 10) = v11;
v8 = v12;
*(__m128i *)(v7 + 2) = v4;
*((_DWORD *)v7 + 7) = v8;
fseek(v5, v6, 0);
fwrite(ptr, 1uLL, 0x3F4uLL, fd);
LODWORD(v1) = iput(v3);
}
}
return v1;
}

canonical_decompiled_code:
int __fastcall func3(char *src)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rbp
__m128i v4; // xmm0
FILE *v5; // rdi
__int64 v6; // rsi
unsigned __int16 *v7; // rdx
int v8; // ecx
char dest[16]; // [rsp+0h] [rbp-438h] BYREF
__int64 v11; // [rsp+10h] [rbp-428h]
int v12; // [rsp+18h] [rbp-420h]
unsigned __int16 ptr[524]; // [rsp+20h] [rbp-418h] BYREF

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(ptr, 1uLL, 0x3F4uLL, fd);
v4 = _mm_loadu_si128((const __m128i *)dest);
v5 = fd;
v6 = (unsigned int)(*(_DWORD *)(v3 + 32) << 10);
v7 = &ptr[14 * ptr[0]++];
*(_QWORD *)(v7 + 10) = v11;
v8 = v12;
*(__m128i *)(v7 + 2) = v4;
*((_DWORD *)v7 + 7) = v8;
fseek(v5, v6, 0);
fwrite(ptr, 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

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; // rbp
__int64 result; // rax
_DWORD *v3; // rdx
char *v4; // rdx

v0 = namei();
if ( v0 )
{
v1 = iget(v0);
if ( *(_BYTE *)(v1 + 22) == 102 )
{
result = 0LL;
v3 = (_DWORD *)((char *)&open_file + 4);
do
{
if ( !*v3 )
{
v4 = (char *)&open_file + 24 * (int)result;
*((_QWORD *)v4 + 1) = v1;
*((_DWORD *)v4 + 1) = 1;
return result;
}
result = (unsigned int)(result + 1);
v3 += 6;
}
while ( (_DWORD)result != 100 );
puts("Cannot open any more files");
result = 0xFFFFFFFFLL;
}
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; // rbp
__int64 result; // rax
_DWORD *v3; // rdx
char *v4; // rdx

v0 = namei();
if ( v0 )
{
v1 = iget(v0);
if ( *(_BYTE *)(v1 + 22) == 102 )
{
result = 0LL;
v3 = (_DWORD *)((char *)&open_file + 4);
do
{
if ( !*v3 )
{
v4 = (char *)&open_file + 24 * (int)result;
*((_QWORD *)v4 + 1) = v1;
*((_DWORD *)v4 + 1) = 1;
return result;
}
result = (unsigned int)(result + 1);
v3 += 6;
}
while ( (_DWORD)result != 100 );
puts("Cannot open any more files");
result = 0xFFFFFFFFLL;
}
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;
}


mclose

decompiled_code:
__int64 __fastcall mclose(int a1)
{
char *v1; // rax

v1 = (char *)&open_file + 24 * a1;
*((_DWORD *)v1 + 1) = 0;
return iput(*((_QWORD *)v1 + 1));
}

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

v1 = (char *)&open_file + 24 * a1;
*((_DWORD *)v1 + 1) = 0;
return iput(*((_QWORD *)v1 + 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)
{
char *v1; // rax
__int64 v2; // rax
int v3; // edi
__int64 v4; // r14
char *result; // rax
__int64 v6; // rbx
char *v7; // r13
char *v8; // rbp
int v9; // esi
void *v10; // rdi

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

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
char *v1; // rax
__int64 v2; // rax
int v3; // edi
__int64 v4; // r14
char *result; // rax
__int64 v6; // rbx
char *v7; // r13
char *v8; // rbp
int v9; // esi
void *v10; // rdi

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

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, _BYTE *a2)
{
char *v2; // rax
_BYTE *v3; // rbx
__int64 v4; // rax
__int64 v5; // r13
__int64 v6; // rax
__int16 v7; // cx
unsigned __int64 v8; // rdx
unsigned __int64 v9; // rdx
unsigned int v10; // er12
__int64 v11; // rbp
__int64 v12; // rdi
__int64 v13; // rbp
const void *v14; // rdi
int result; // eax

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

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, _BYTE *a2)
{
char *v2; // rax
_BYTE *v3; // rbx
__int64 v4; // rax
__int64 v5; // r13
__int64 v6; // rax
__int16 v7; // cx
unsigned __int64 v8; // rdx
unsigned __int64 v9; // rdx
unsigned int v10; // er12
__int64 v11; // rbp
__int64 v12; // rdi
__int64 v13; // rbp
const void *v14; // rdi
int result; // eax

if ( a1 > 0x63 )
return puts("File has not been opened");
v2 = (char *)&open_file + 24 * (int)a1;
if ( !*((_DWORD *)v2 + 1) )
return puts("File has not been opened");
v3 = a2;
v4 = iget(*(unsigned int *)(*((_QWORD *)v2 + 1) + 24LL));
v5 = v4;
if ( *a2 )
{
v6 = 1LL;
do
{
v7 = v6;
v8 = v6++;
}
while ( a2[v6 - 1] );
v9 = v8 >> 10;
v10 = v9;
if ( (v7 & 0x3FF) != 0 )
{
v10 = v9 + 1;
if ( !*(_DWORD *)(v5 + 28) )
goto LABEL_11;
}
else if ( !*(_DWORD *)(v5 + 28) )
{
goto LABEL_10;
}
}
else
{
v10 = 0;
if ( !*(_DWORD *)(v4 + 28) )
return iput(v5);
}
v11 = 0LL;
do
{
v12 = *(unsigned int *)(v5 + 4 * v11++ + 32);
bfree(v12);
}
while ( *(_DWORD *)(v5 + 28) > (unsigned int)v11 );
LABEL_10:
if ( !v10 )
return iput(v5);
LABEL_11:
v13 = 0LL;
while ( 1 )
{
result = balloc();
if ( !result )
break;
*(_DWORD *)(v5 + 4 * v13++ + 32) = result;
++*(_DWORD *)(v5 + 28);
fseek(fd, (unsigned int)(result << 10), 0);
v14 = v3;
v3 += 1024;
fwrite(v14, 1uLL, 0x400uLL, fd);
if ( v10 <= (unsigned int)v13 )
return iput(v5);
}
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


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]; }


decompiled_code:
size_t __fastcall i_to_dinode(const __m128i *a1)
{
int v1; // er8
int v2; // eax
__int64 v3; // rax
char vars0; // [rsp+0h] [rbp+0h] BYREF
int vars4; // [rsp+4h] [rbp+4h]
int vars8; // [rsp+8h] [rbp+8h]
__m128i varsC; // [rsp+Ch] [rbp+Ch]
__m128i vars1C; // [rsp+1Ch] [rbp+1Ch]
__m128i vars2C; // [rsp+2Ch] [rbp+2Ch]
__m128i vars3C; // [rsp+3Ch] [rbp+3Ch]
__m128i vars4C; // [rsp+4Ch] [rbp+4Ch]
__m128i vars5C; // [rsp+5Ch] [rbp+5Ch]
__m128i vars6C; // [rsp+6Ch] [rbp+6Ch]
__m128i vars7C; // [rsp+7Ch] [rbp+7Ch]
__m128i vars8C; // [rsp+8Ch] [rbp+8Ch]
__m128i vars9C; // [rsp+9Ch] [rbp+9Ch]
__m128i varsAC; // [rsp+ACh] [rbp+ACh]
__m128i varsBC; // [rsp+BCh] [rbp+BCh]
__int64 varsCC; // [rsp+CCh] [rbp+CCh]

v1 = a1[1].m128i_i32[2];
vars0 = a1[1].m128i_i8[6];
v2 = a1[1].m128i_i32[3];
vars4 = v1;
vars8 = v2;
varsC = _mm_loadu_si128(a1 + 2);
vars1C = _mm_loadu_si128(a1 + 3);
vars2C = _mm_loadu_si128(a1 + 4);
vars3C = _mm_loadu_si128(a1 + 5);
vars4C = _mm_loadu_si128(a1 + 6);
vars5C = _mm_loadu_si128(a1 + 7);
vars6C = _mm_loadu_si128(a1 + 8);
vars7C = _mm_loadu_si128(a1 + 9);
vars8C = _mm_loadu_si128(a1 + 10);
vars9C = _mm_loadu_si128(a1 + 11);
varsAC = _mm_loadu_si128(a1 + 12);
varsBC = _mm_loadu_si128(a1 + 13);
varsCC = a1[14].m128i_i64[0];
v3 = map_addr(v1);
fseek(fd, v3, 0);
return fwrite(&vars0, 1uLL, 0xD4uLL, fd);
}

canonical_decompiled_code:
size_t __fastcall func4(const __m128i *a1)
{
int v1; // er8
int v2; // eax
__int64 v3; // rax
char vars0; // [rsp+0h] [rbp+0h] BYREF
int vars4; // [rsp+4h] [rbp+4h]
int vars8; // [rsp+8h] [rbp+8h]
__m128i varsC; // [rsp+Ch] [rbp+Ch]
__m128i vars1C; // [rsp+1Ch] [rbp+1Ch]
__m128i vars2C; // [rsp+2Ch] [rbp+2Ch]
__m128i vars3C; // [rsp+3Ch] [rbp+3Ch]
__m128i vars4C; // [rsp+4Ch] [rbp+4Ch]
__m128i vars5C; // [rsp+5Ch] [rbp+5Ch]
__m128i vars6C; // [rsp+6Ch] [rbp+6Ch]
__m128i vars7C; // [rsp+7Ch] [rbp+7Ch]
__m128i vars8C; // [rsp+8Ch] [rbp+8Ch]
__m128i vars9C; // [rsp+9Ch] [rbp+9Ch]
__m128i varsAC; // [rsp+ACh] [rbp+ACh]
__m128i varsBC; // [rsp+BCh] [rbp+BCh]
__int64 varsCC; // [rsp+CCh] [rbp+CCh]

v1 = a1[1].m128i_i32[2];
vars0 = a1[1].m128i_i8[6];
v2 = a1[1].m128i_i32[3];
vars4 = v1;
vars8 = v2;
varsC = _mm_loadu_si128(a1 + 2);
vars1C = _mm_loadu_si128(a1 + 3);
vars2C = _mm_loadu_si128(a1 + 4);
vars3C = _mm_loadu_si128(a1 + 5);
vars4C = _mm_loadu_si128(a1 + 6);
vars5C = _mm_loadu_si128(a1 + 7);
vars6C = _mm_loadu_si128(a1 + 8);
vars7C = _mm_loadu_si128(a1 + 9);
vars8C = _mm_loadu_si128(a1 + 10);
vars9C = _mm_loadu_si128(a1 + 11);
varsAC = _mm_loadu_si128(a1 + 12);
varsBC = _mm_loadu_si128(a1 + 13);
varsCC = a1[14].m128i_i64[0];
v3 = func1(v1);
fseek(fd, v3, 0);
return fwrite(&vars0, 1uLL, 0xD4uLL, fd);
}

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)
{
int v1; // eax
unsigned int v2; // er8
__int64 v4; // rbp
int v5; // er13
char *v6; // rbp
int v7; // ebx
__int16 v8[4]; // [rsp+0h] [rbp-428h] BYREF
char s1; // [rsp+8h] [rbp-420h] BYREF

v1 = (unsigned __int8)*s2;
if ( v1 == 47 && !s2[1] )
return (unsigned int)usr[6];
if ( v1 == 46 )
{
v2 = cur_dir_dinode_no;
if ( !s2[1] )
return v2;
}
else
{
v2 = cur_dir_dinode_no;
}
v4 = iget(v2);
fseek(fd, (unsigned int)(*(_DWORD *)(v4 + 32) << 10), 0);
fread(v8, 1uLL, 0x3F4uLL, fd);
iput(v4);
v5 = (unsigned __int16)v8[0];
if ( !v8[0] )
return 0;
v6 = &s1;
v7 = 0;
while ( strcmp(v6, s2) )
{
++v7;
v6 += 28;
if ( v7 == v5 )
return 0;
}
return *(unsigned int *)&v8[14 * v7 + 2];
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2)
{
int v1; // eax
unsigned int v2; // er8
__int64 v4; // rbp
int v5; // er13
char *v6; // rbp
int v7; // ebx
__int16 v8[4]; // [rsp+0h] [rbp-428h] BYREF
char s1; // [rsp+8h] [rbp-420h] BYREF

v1 = (unsigned __int8)*s2;
if ( v1 == 47 && !s2[1] )
return (unsigned int)usr[6];
if ( v1 == 46 )
{
v2 = cur_dir_dinode_no;
if ( !s2[1] )
return v2;
}
else
{
v2 = cur_dir_dinode_no;
}
v4 = iget(v2);
fseek(fd, (unsigned int)(*(_DWORD *)(v4 + 32) << 10), 0);
fread(v8, 1uLL, 0x3F4uLL, fd);
iput(v4);
v5 = (unsigned __int16)v8[0];
if ( !v8[0] )
return 0;
v6 = &s1;
v7 = 0;
while ( strcmp(v6, s2) )
{
++v7;
v6 += 28;
if ( v7 == v5 )
return 0;
}
return *(unsigned int *)&v8[14 * v7 + 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

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:
__int64 __fastcall ifree(int a1)
{
int v1; // eax
__int64 v2; // rdx
__int64 result; // rax
int v4; // ebp
unsigned int v5; // er15
__int64 v6; // rax
__int64 v7; // rax
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // eax
__int64 v2; // rdx
__int64 result; // rax
int v4; // ebp
unsigned int v5; // er15
__int64 v6; // rax
__int64 v7; // rax
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = *((unsigned __int16 *)&sb + 410);
if ( (_WORD)v1 == 100 )
{
v4 = 50;
while ( 1 )
{
v5 = *((_DWORD *)&sb + v1 + 104);
v6 = map_addr(v5);
fseek(fd, v6, 0);
fread(v8, 1uLL, 0xD4uLL, fd);
v8[0] = 115;
v7 = map_addr(v5);
fseek(fd, v7, 0);
fwrite(v8, 1uLL, 0xD4uLL, fd);
if ( !--v4 )
break;
v1 = *((unsigned __int16 *)&sb + 410);
}
v1 = *((unsigned __int16 *)&sb + 410);
}
v2 = (unsigned __int16)v1;
result = (unsigned int)(v1 + 1);
++*((_DWORD *)&sb + 104);
*((_DWORD *)&sb + v2 + 105) = a1;
*((_WORD *)&sb + 410) = result;
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
__int64 v2; // rax
_QWORD *v3; // rdx

v1 = *((_DWORD *)ptr + 4);
if ( v1 <= 1 )
{
i_to_dinode();
v2 = *(_QWORD *)ptr;
if ( *(_QWORD *)ptr )
{
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
*(_QWORD *)(v2 + 8) = v3;
*v3 = v2;
}
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
__int64 v2; // rax
_QWORD *v3; // rdx

v1 = *((_DWORD *)ptr + 4);
if ( v1 <= 1 )
{
i_to_dinode();
v2 = *(_QWORD *)ptr;
if ( *(_QWORD *)ptr )
{
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
*(_QWORD *)(v2 + 8) = v3;
*v3 = v2;
}
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; // r12
void *v2; // rax
_QWORD *result; // rax

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

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void *v2; // rax
_QWORD *result; // rax

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

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)
{
__int64 result; // rax
__int64 v4; // rsi
_QWORD *v5; // rdx

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

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

result = *(_QWORD *)(a1 + 16);
v4 = result + 1;
if ( (unsigned __int64)(result + 1) > *(_QWORD *)(a1 + 8) )
{
if ( !realloc(*(void **)a1, 8 * v4) )
_assert_fail("realloc(v->arr, sizeof(void *) * (v->size + 1)) != NULL", "vector.c", 0x18u, "vector_push");
result = *(_QWORD *)(a1 + 16);
v4 = result + 1;
*(_QWORD *)(a1 + 8) = result + 1;
}
v5 = *(_QWORD **)a1;
*(_QWORD *)(a1 + 16) = v4;
v5[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 )
{
result = (unsigned int)cc3k_regular_cnt;
if ( (cc3k_regular_cnt & 0x3F) != 0 )
return result;
return hci_unsolicited_event_handler();
}
if ( (unsigned __int8)cc3k_get_irq() )
{
result = (unsigned int)cc3k_regular_cnt;
if ( (cc3k_regular_cnt & 0x3F) != 0 )
return result;
return hci_unsolicited_event_handler();
}
CC3000InterruptHandler();
result = (unsigned int)cc3k_regular_cnt;
if ( (cc3k_regular_cnt & 0x3F) == 0 )
return hci_unsolicited_event_handler();
return result;
}

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

++cc3k_regular_cnt;
if ( !cc3k_pseudo_irq_en )
{
result = (unsigned int)cc3k_regular_cnt;
if ( (cc3k_regular_cnt & 0x3F) != 0 )
return result;
return hci_unsolicited_event_handler();
}
if ( (unsigned __int8)cc3k_get_irq() )
{
result = (unsigned int)cc3k_regular_cnt;
if ( (cc3k_regular_cnt & 0x3F) != 0 )
return result;
return hci_unsolicited_event_handler();
}
CC3000InterruptHandler();
result = (unsigned int)cc3k_regular_cnt;
if ( (cc3k_regular_cnt & 0x3F) == 0 )
return 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; // r14
__int64 v7; // rax
__int64 v8; // rax
char v10[41]; // [rsp+Fh] [rbp-29h] BYREF

v6 = tSLInformation[2];
v10[0] = -1;
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; // r14
__int64 v7; // rax
__int64 v8; // rax
char v10[41]; // [rsp+Fh] [rbp-29h] BYREF

v6 = tSLInformation[2];
v10[0] = -1;
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

v6 = tSLInformation[2];
v11[0] = -1LL;
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

v6 = tSLInformation[2];
v11[0] = -1LL;
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, size_t a2, char *a3)
{
size_t v4; // rbp
unsigned __int16 v5; // bx
unsigned int v6; // eax
unsigned int v7; // er8

v4 = a2;
v5 = 0;
while ( v4 > 0x1F )
{
v6 = nvmem_write(a1, 0x20uLL, v5, a3);
v5 += 32;
v4 -= 32LL;
a3 += 32;
v7 = v6;
if ( (_BYTE)v6 )
return v7;
}
v7 = 0;
if ( !v4 )
return v7;
return (unsigned int)nvmem_write(a1, v4, v5, a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, size_t a2, char *a3)
{
size_t v4; // rbp
unsigned __int16 v5; // bx
unsigned int v6; // eax
unsigned int v7; // er8

v4 = a2;
v5 = 0;
while ( v4 > 0x1F )
{
v6 = func1(a1, 0x20uLL, v5, a3);
v5 += 32;
v4 -= 32LL;
a3 += 32;
v7 = v6;
if ( (_BYTE)v6 )
return v7;
}
v7 = 0;
if ( !v4 )
return v7;
return (unsigned int)func1(a1, v4, v5, a3);
}

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(_WORD *a1)
{
char v2[3]; // [rsp+Bh] [rbp-Dh] BYREF
__int16 v3; // [rsp+Eh] [rbp-Ah]

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

canonical_decompiled_code:
__int64 __fastcall func5(_WORD *a1)
{
char v2[3]; // [rsp+Bh] [rbp-Dh] BYREF
__int16 v3; // [rsp+Eh] [rbp-Ah]

hci_command_send(519LL, tSLInformation[2], 0LL);
SimpleLinkWaitEvent(519LL, v2);
*a1 = v3;
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; // r12
__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; // r12
__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; // er12
int v2; // er13
unsigned int v3; // ebp
unsigned int v4; // eax
int v6; // ebx

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

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

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

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:
__int64 SpiPauseSpi()
{
__int64 result; // rax

result = 0LL;
SPIInterruptsEnabled = 0;
return result;
}

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

result = 0LL;
SPIInterruptsEnabled = 0;
return result;
}

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

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


SpiResumeSpi

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

result = 1LL;
SPIInterruptsEnabled = 1;
return result;
}

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

result = 1LL;
SPIInterruptsEnabled = 1;
return result;
}

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

canonical_original_code:
void SpiResumeSpi() {
 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; // rbp
unsigned __int8 *v3; // rbx
unsigned __int8 v4; // di
__int64 result; // rax

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

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

if ( a2 )
{
v2 = &a1[a2];
v3 = a1;
do
{
v4 = *v3++;
result = func0(v4);
}
while ( v3 != v2 );
}
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