parsecommand

decompiled_code:
__int64 __fastcall parsecommand(char *a1, __int64 a2)
{
const char *v3; // rax
__int64 result; // rax
int v5; // eax
char *v6; // rbx
__int64 v7; // rax
int v8; // eax
char v9; // al
int v10; // er12
char *v11; // r13
int v12; // er12
char *v13; // [rsp+0h] [rbp-38h] BYREF
__int64 v14[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = (const char *)&unk_750;
do
{
*((_QWORD *)v3 - 1) = v3;
v3 += 16;
}
while ( v3 != "_-.,/~+" );
qword_878 = 0LL;
cmds = (__int64)&cmdbuf;
cp = (__int64)&cbuf;
pp = (__int64)&pbuf;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 24) = 0LL;
*(_DWORD *)(a2 + 32) = 0;
*(_QWORD *)a2 = 0LL;
while ( 2 )
{
v5 = acmd(a1, v14);
if ( v5 <= 0 )
return 0xFFFFFFFFLL;
v6 = &a1[v5];
v7 = v14[0];
*(_QWORD *)(v14[0] + 8) = *(_QWORD *)a2;
*(_QWORD *)a2 = v7;
while ( 1 )
{
while ( 1 )
{
v8 = nexttoken(v6, &v13);
if ( !v8 )
return 1LL;
a1 = &v6[v8];
v9 = *v13;
if ( *v13 != 62 )
break;
if ( *(_QWORD *)(a2 + 16) )
{
fwrite("duplicate redirection of stdout\n", 1uLL, 0x20uLL, stderr);
return 0xFFFFFFFFLL;
}
v12 = nexttoken(a1, (_QWORD *)(a2 + 16));
if ( v12 < 0 )
return 0xFFFFFFFFLL;
v11 = *(char **)(a2 + 16);
if ( !(unsigned int)isidentifier(v11) )
{
LABEL_22:
fprintf(stderr, "Illegal filename: \"%s\"\n", v11);
return 0xFFFFFFFFLL;
}
v6 = &a1[v12];
}
if ( v9 > 62 )
break;
if ( v9 == 38 )
{
if ( (unsigned int)nexttoken(a1, &v13) )
{
fwrite("illegal backgrounding\n", 1uLL, 0x16uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)(a2 + 32) = 1;
result = 1LL;
}
return result;
}
if ( v9 != 60 )
return 0xFFFFFFFFLL;
if ( *(_QWORD *)(a2 + 8) )
{
fwrite("duplicate redirection of stdin\n", 1uLL, 0x1FuLL, stderr);
return 0xFFFFFFFFLL;
}
v10 = nexttoken(a1, (_QWORD *)(a2 + 8));
if ( v10 < 0 )
return 0xFFFFFFFFLL;
v11 = *(char **)(a2 + 8);
if ( !(unsigned int)isidentifier(v11) )
goto LABEL_22;
v6 = &a1[v10];
}
if ( v9 == 124 )
continue;
return 0xFFFFFFFFLL;
}
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, __int64 a2)
{
const char *v3; // rax
__int64 result; // rax
int v5; // eax
char *v6; // rbx
__int64 v7; // rax
int v8; // eax
char v9; // al
int v10; // er12
char *v11; // r13
int v12; // er12
char *v13; // [rsp+0h] [rbp-38h] BYREF
__int64 v14[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = (const char *)&unk_750;
do
{
*((_QWORD *)v3 - 1) = v3;
v3 += 16;
}
while ( v3 != "_-.,/~+" );
qword_878 = 0LL;
cmds = (__int64)&cmdbuf;
cp = (__int64)&cbuf;
pp = (__int64)&pbuf;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 24) = 0LL;
*(_DWORD *)(a2 + 32) = 0;
*(_QWORD *)a2 = 0LL;
while ( 2 )
{
v5 = func1(a1, v14);
if ( v5 <= 0 )
return 0xFFFFFFFFLL;
v6 = &a1[v5];
v7 = v14[0];
*(_QWORD *)(v14[0] + 8) = *(_QWORD *)a2;
*(_QWORD *)a2 = v7;
while ( 1 )
{
while ( 1 )
{
v8 = func0(v6, &v13);
if ( !v8 )
return 1LL;
a1 = &v6[v8];
v9 = *v13;
if ( *v13 != 62 )
break;
if ( *(_QWORD *)(a2 + 16) )
{
fwrite("duplicate redirection of stdout\n", 1uLL, 0x20uLL, stderr);
return 0xFFFFFFFFLL;
}
v12 = func0(a1, (_QWORD *)(a2 + 16));
if ( v12 < 0 )
return 0xFFFFFFFFLL;
v11 = *(char **)(a2 + 16);
if ( !(unsigned int)func2(v11) )
{
LABEL_22:
fprintf(stderr, "Illegal filename: \"%s\"\n", v11);
return 0xFFFFFFFFLL;
}
v6 = &a1[v12];
}
if ( v9 > 62 )
break;
if ( v9 == 38 )
{
if ( (unsigned int)func0(a1, &v13) )
{
fwrite("illegal backgrounding\n", 1uLL, 0x16uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)(a2 + 32) = 1;
result = 1LL;
}
return result;
}
if ( v9 != 60 )
return 0xFFFFFFFFLL;
if ( *(_QWORD *)(a2 + 8) )
{
fwrite("duplicate redirection of stdin\n", 1uLL, 0x1FuLL, stderr);
return 0xFFFFFFFFLL;
}
v10 = func0(a1, (_QWORD *)(a2 + 8));
if ( v10 < 0 )
return 0xFFFFFFFFLL;
v11 = *(char **)(a2 + 8);
if ( !(unsigned int)func2(v11) )
goto LABEL_22;
v6 = &a1[v10];
}
if ( v9 == 124 )
continue;
return 0xFFFFFFFFLL;
}
}

original_code:
int parsecommand(char *cmdline, Shellcmd *shellcmd)
{
  int i, n;
  Cmd *cmd0;
  char *t = cmdline;
  char *tok;
  for (i = 0; i < 20 -1; i++) cmdbuf[i].next = &cmdbuf[i+1];
  cmdbuf[20 -1].next = ((void *)0);
  cmds = cmdbuf;
  cp = cbuf;
  pp = pbuf;
  shellcmd->rd_stdin = ((void *)0);
  shellcmd->rd_stdout = ((void *)0);
  shellcmd->rd_stderr = ((void *)0);
  shellcmd->background = 0;
  shellcmd->the_cmds = ((void *)0);
  do {
    if ((n = acmd(t, &cmd0)) <= 0)
      return -1;
    t += n;
    cmd0->next = shellcmd->the_cmds;
    shellcmd->the_cmds = cmd0;
    int newtoken = 1;
    while (newtoken) {
      n = nexttoken(t, &tok);
      if (n == 0)
 {
   return 1;
 }
      t += n;
      switch(*tok) {
      case ('|'):
 newtoken = 0;
 break;
      case ('&'):
 n = nexttoken(t, &tok);
 if (n == 0)
   {
     shellcmd->background = 1;
     return 1;
   }
 else
   {
     fprintf(stderr, "illegal backgrounding\n");
     return -1;
   }
 newtoken = 0;
 break;
      case ('<'):
 if (shellcmd->rd_stdin != ((void *)0))
   {
     fprintf(stderr, "duplicate redirection of stdin\n");
     return -1;
   }
 if ((n = nexttoken(t, &(shellcmd->rd_stdin))) < 0)
   return -1;
 if (!isidentifier(shellcmd->rd_stdin))
   {
     fprintf(stderr, "Illegal filename: \"%s\"\n", shellcmd->rd_stdin);
     return -1;
   }
 t += n;
 break;
      case ('>'):
 if (shellcmd->rd_stdout != ((void *)0))
   {
     fprintf(stderr, "duplicate redirection of stdout\n");
     return -1;
   }
 if ((n = nexttoken(t, &(shellcmd->rd_stdout))) < 0)
   return -1;
 if (!isidentifier(shellcmd->rd_stdout))
   {
     fprintf(stderr, "Illegal filename: \"%s\"\n", shellcmd->rd_stdout);
     return -1;
   }
 t += n;
 break;
      default:
 return -1;
      }
    }
  } while (1);
  return 0;
}

canonical_original_code:
int parsecommand(char *cmdline, struct _shellcmd *shellcmd)
{
  int i; int n;
  struct _cmd *cmd0;
  char *t = cmdline;
  char *tok;
  for (i = 0; i < 20 -1; i++) cmdbuf[i].next = &cmdbuf[i+1];
  cmdbuf[20 -1].next = ((void *)0);
  cmds = cmdbuf;
  cp = cbuf;
  pp = pbuf;
  shellcmd->rd_stdin = ((void *)0);
  shellcmd->rd_stdout = ((void *)0);
  shellcmd->rd_stderr = ((void *)0);
  shellcmd->background = 0;
  shellcmd->the_cmds = ((void *)0);
  do {
    if ((n = acmd(t, &cmd0)) <= 0)
      return -1;
    t += n;
    cmd0->next = shellcmd->the_cmds;
    shellcmd->the_cmds = cmd0;
    int newtoken = 1;
    while (newtoken) {
      n = nexttoken(t, &tok);
      if (n == 0)
 {
   return 1;
 }
      t += n;
      switch(*tok) {
      case ('|'):
 newtoken = 0;
 break;
      case ('&'):
 n = nexttoken(t, &tok);
 if (n == 0)
   {
     shellcmd->background = 1;
     return 1;
   }
 else
   {
     fprintf(stderr, "illegal backgrounding\n");
     return -1;
   }
 newtoken = 0;
 break;
      case ('<'):
 if (shellcmd->rd_stdin != ((void *)0))
   {
     fprintf(stderr, "duplicate redirection of stdin\n");
     return -1;
   }
 if ((n = nexttoken(t, &(shellcmd->rd_stdin))) < 0)
   return -1;
 if (!isidentifier(shellcmd->rd_stdin))
   {
     fprintf(stderr, "Illegal filename: \"%s\"\n", shellcmd->rd_stdin);
     return -1;
   }
 t += n;
 break;
      case ('>'):
 if (shellcmd->rd_stdout != ((void *)0))
   {
     fprintf(stderr, "duplicate redirection of stdout\n");
     return -1;
   }
 if ((n = nexttoken(t, &(shellcmd->rd_stdout))) < 0)
   return -1;
 if (!isidentifier(shellcmd->rd_stdout))
   {
     fprintf(stderr, "Illegal filename: \"%s\"\n", shellcmd->rd_stdout);
     return -1;
   }
 t += n;
 break;
      default:
 return -1;
      }
    }
  } while (1);
  return 0;
}

variable_types:
cmdline
char *

variable_types: struct _shellcmd { struct _cmd { char **cmd; struct _cmd *next; } *the_cmds; char *rd_stdin; char *rd_stdout; char *rd_stderr; int background; } *

variable_types: i int

variable_types:
t
char *

variable_types: newtoken int

user_defined_types: struct _shellcmd { struct _cmd *the_cmds; char *rd_stdin; char *rd_stdout; char *rd_stderr; int background; }


pipecmd

decompiled_code:
__int64 __fastcall pipecmd(char *file, char **argv, char *a3, char **a4)
{
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

pipe(pipedes);
if ( !fork() )
{
close(1);
dup2(pipedes[1], 1);
close(pipedes[0]);
execvp(file, argv);
}
close(0);
dup2(pipedes[0], 0);
close(pipedes[1]);
execvp(a3, a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *file, char **argv, char *a3, char **a4)
{
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

pipe(pipedes);
if ( !fork() )
{
close(1);
dup2(pipedes[1], 1);
close(pipedes[0]);
execvp(file, argv);
}
close(0);
dup2(pipedes[0], 0);
close(pipedes[1]);
execvp(a3, a4);
return 0LL;
}

original_code:
int pipecmd(char *filename1, char *argv1[], char *filename2, char *argv2[])
{
  int pfds[2];
  pipe(pfds);
  pid_t p1 = fork();
  if(p1 == 0){
    close(1);
    dup2(pfds[1], 1);
    close(pfds[0]);
    execvp(filename1, argv1);
  }
  close(0);
  dup2(pfds[0], 0);
  close(pfds[1]);
  execvp(filename2, argv2);
  return 0;
}

canonical_original_code:
int pipecmd(char *filename1, char *argv1[], char *filename2, char *argv2[])
{
  int pfds[2];
  pipe(pfds);
  int p1 = fork();
  if(p1 == 0){
    close(1);
    dup2(pfds[1], 1);
    close(pfds[0]);
    execvp(filename1, argv1);
  }
  close(0);
  dup2(pfds[0], 0);
  close(pfds[1]);
  execvp(filename2, argv2);
  return 0;
}

variable_types:
pfds
int [2]

return_type: int


asyncRunner

decompiled_code:
void __fastcall __noreturn asyncRunner(void *a1)
{
int v1; // ebx
__int64 v2; // rax

v1 = 500;
do
{
v2 = node_new(a1);
a1 = (void *)fifo;
list_add(fifo, v2);
--v1;
}
while ( v1 );
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
int v1; // ebx
__int64 v2; // rax

v1 = 500;
do
{
v2 = node_new(a1);
a1 = (void *)fifo;
list_add(fifo, v2);
--v1;
}
while ( v1 );
pthread_exit(0LL);
}

original_code:
void *asyncRunner(void* peh){
 int i;
 for(i=0; i<elmsPerThread; i++){
  list_add(fifo, node_new());
 }
 pthread_exit(((void *)0));
}

canonical_original_code:
void *asyncRunner(void *peh){
 int i;
 for(i=0; i<elmsPerThread; i++){
  list_add(fifo, node_new());
 }
 pthread_exit(((void *)0));
}

variable_types:
peh
void *

return_type: void *


asyncListTest

decompiled_code:
__int64 asyncListTest()
{
pthread_t **v0; // rbx
char *v1; // rbp
pthread_t *v2; // rax
int v3; // er12
__int64 v4; // rax
int v5; // ebx
int v6; // ebp
__int64 result; // rax
_BYTE v8[24]; // [rsp+0h] [rbp-38h] BYREF
char v9[32]; // [rsp+18h] [rbp-20h] BYREF

fifo = list_new();
v0 = (pthread_t **)v8;
v1 = v8;
do
{
v2 = (pthread_t *)malloc(8uLL);
*(_QWORD *)v1 = v2;
pthread_create(v2, 0LL, (void *(*)(void *))asyncRunner, 0LL);
v1 += 8;
}
while ( v1 != v9 );
do
pthread_join(**v0++, 0LL);
while ( v0 != (pthread_t **)v9 );
v3 = *(_DWORD *)fifo;
v4 = *(_QWORD *)(*(_QWORD *)(fifo + 8) + 8LL);
if ( v4 )
{
v5 = 0;
do
{
++v5;
v4 = *(_QWORD *)(v4 + 8);
}
while ( v4 );
}
else
{
v5 = 0;
}
if ( ((__int64 (*)(void))list_remove)() )
{
v6 = 0;
do
++v6;
while ( list_remove(fifo) );
}
else
{
v6 = 0;
}
if ( v3 != v5 )
_assert_fail("assertedN == actualN", "main.c", 0x35u, "asyncListTest");
if ( v6 != v5 )
_assert_fail("removeN == actualN", "main.c", 0x36u, "asyncListTest");
if ( v5 != 1500 )
_assert_fail("elmsPerThread*numberOfThreads == actualN", "main.c", 0x37u, "asyncListTest");
result = fifo;
if ( *(_DWORD *)fifo )
_assert_fail("fifo->len == 0", "main.c", 0x38u, "asyncListTest");
return result;
}

canonical_decompiled_code:
__int64 func1()
{
pthread_t **v0; // rbx
char *v1; // rbp
pthread_t *v2; // rax
int v3; // er12
__int64 v4; // rax
int v5; // ebx
int v6; // ebp
__int64 result; // rax
_BYTE v8[24]; // [rsp+0h] [rbp-38h] BYREF
char v9[32]; // [rsp+18h] [rbp-20h] BYREF

fifo = list_new();
v0 = (pthread_t **)v8;
v1 = v8;
do
{
v2 = (pthread_t *)malloc(8uLL);
*(_QWORD *)v1 = v2;
pthread_create(v2, 0LL, (void *(*)(void *))asyncRunner, 0LL);
v1 += 8;
}
while ( v1 != v9 );
do
pthread_join(**v0++, 0LL);
while ( v0 != (pthread_t **)v9 );
v3 = *(_DWORD *)fifo;
v4 = *(_QWORD *)(*(_QWORD *)(fifo + 8) + 8LL);
if ( v4 )
{
v5 = 0;
do
{
++v5;
v4 = *(_QWORD *)(v4 + 8);
}
while ( v4 );
}
else
{
v5 = 0;
}
if ( ((__int64 (*)(void))list_remove)() )
{
v6 = 0;
do
++v6;
while ( list_remove(fifo) );
}
else
{
v6 = 0;
}
if ( v3 != v5 )
_assert_fail("assertedN == actualN", "main.c", 0x35u, "asyncListTest");
if ( v6 != v5 )
_assert_fail("removeN == actualN", "main.c", 0x36u, "asyncListTest");
if ( v5 != 1500 )
_assert_fail("elmsPerThread*numberOfThreads == actualN", "main.c", 0x37u, "asyncListTest");
result = fifo;
if ( *(_DWORD *)fifo )
_assert_fail("fifo->len == 0", "main.c", 0x38u, "asyncListTest");
return result;
}

original_code:
void asyncListTest(){
 fifo = list_new();
 pthread_t *ids[numberOfThreads];
 int i;
 for(i=0; i<numberOfThreads; i++){
  pthread_t* tid = (pthread_t *) malloc(sizeof(pthread_t));
  ids[i] = tid;
  pthread_create(tid, ((void *)0), asyncRunner, ((void *)0));
 }
 for(i=0; i<numberOfThreads; i++){
  pthread_join(*ids[i], ((void *)0));
 }
 int removeN=0;
 int actualN=0;
 int assertedN = fifo->len;
 Node *n = fifo->first->next;
 while(n != ((void *)0)) {
  actualN++;
  n = n->next;
 }
 n = list_remove(fifo);
 while(n != ((void *)0)){
  removeN++;
  n = list_remove(fifo);
 }
 ((void) sizeof ((assertedN == actualN) ? 1 : 0), __extension__ ({ if (assertedN == actualN) ; else __assert_fail ("assertedN == actualN", "main.c", 53, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((removeN == actualN) ? 1 : 0), __extension__ ({ if (removeN == actualN) ; else __assert_fail ("removeN == actualN", "main.c", 54, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((elmsPerThread*numberOfThreads == actualN) ? 1 : 0), __extension__ ({ if (elmsPerThread*numberOfThreads == actualN) ; else __assert_fail ("elmsPerThread*numberOfThreads == actualN", "main.c", 55, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((fifo->len == 0) ? 1 : 0), __extension__ ({ if (fifo->len == 0) ; else __assert_fail ("fifo->len == 0", "main.c", 56, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void asyncListTest(){
 fifo = list_new();
 unsigned long *ids[-1];
 int i;
 for(i=0; i<numberOfThreads; i++){
  unsigned long *tid = (pthread_t *) malloc(sizeof(pthread_t));
  ids[i] = tid;
  pthread_create(tid, ((void *)0), asyncRunner, ((void *)0));
 }
 for(i=0; i<numberOfThreads; i++){
  pthread_join(*ids[i], ((void *)0));
 }
 int removeN = 0;
 int actualN = 0;
 int assertedN = fifo->len;
 struct node *n = fifo->first->next;
 while(n != ((void *)0)) {
  actualN++;
  n = n->next;
 }
 n = list_remove(fifo);
 while(n != ((void *)0)){
  removeN++;
  n = list_remove(fifo);
 }
 ((void) sizeof ((assertedN == actualN) ? 1 : 0), __extension__ ({ if (assertedN == actualN) ; else __assert_fail ("assertedN == actualN", "main.c", 53, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((removeN == actualN) ? 1 : 0), __extension__ ({ if (removeN == actualN) ; else __assert_fail ("removeN == actualN", "main.c", 54, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((elmsPerThread*numberOfThreads == actualN) ? 1 : 0), __extension__ ({ if (elmsPerThread*numberOfThreads == actualN) ; else __assert_fail ("elmsPerThread*numberOfThreads == actualN", "main.c", 55, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((fifo->len == 0) ? 1 : 0), __extension__ ({ if (fifo->len == 0) ; else __assert_fail ("fifo->len == 0", "main.c", 56, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
ids
unsigned long *[-1]

variable_types:
tid
unsigned long *

variable_types: removeN int

variable_types: actualN int

variable_types: assertedN int

variable_types: struct node { void *elm; struct node *next; } *

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
asyncListTest(argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func1(argc, argv, envp);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 asyncListTest();
 return 0;
 fifo = list_new();
 list_add(fifo, node_new_str("s1"));
 list_add(fifo, node_new_str("s2"));
 Node *n1 = list_remove(fifo);
 if (n1 == ((void *)0)) { printf("Error no elements in list\n"); exit(-1);}
 Node *n2 = list_remove(fifo);
 if (n2 == ((void *)0)) { printf("Error no elements in list\n"); exit(-1);}
 printf("%s\n%s\n", n1->elm, n2->elm);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 asyncListTest();
 return 0;
 fifo = list_new();
 list_add(fifo, node_new_str("s1"));
 list_add(fifo, node_new_str("s2"));
 struct node *n1 = list_remove(fifo);
 if (n1 == ((void *)0)) { printf("Error no elements in list\n"); exit(-1);}
 struct node *n2 = list_remove(fifo);
 if (n2 == ((void *)0)) { printf("Error no elements in list\n"); exit(-1);}
 printf("%s\n%s\n", n1->elm, n2->elm);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

user_defined_types: struct node { void *elm; struct node *next; }


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

pthread_mutex_init(&mutex, 0LL);
v0 = malloc(0x18uLL);
*(_DWORD *)v0 = 0;
v1 = malloc(0x10uLL);
v0[2] = v1;
v0[1] = v1;
*v1 = 0LL;
v1[1] = 0LL;
return v0;
}

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

pthread_mutex_init(&mutex, 0LL);
v0 = malloc(0x18uLL);
*(_DWORD *)v0 = 0;
v1 = malloc(0x10uLL);
v0[2] = v1;
v0[1] = v1;
*v1 = 0LL;
v1[1] = 0LL;
return v0;
}

original_code:
List *list_new(void)
{
 pthread_mutex_init(&mutex, ((void *)0));
 List *l;
 l = (List *) malloc(sizeof(List));
 l->len = 0;
 l->first = l->last = (Node *) malloc(sizeof(Node));
 l->first->elm = ((void *)0);
 l->first->next = ((void *)0);
 return l;
}

canonical_original_code:
struct list *list_new()
{
 pthread_mutex_init(&mutex, ((void *)0));
 struct list *l;
 l = (struct list *) malloc(sizeof(List));
 l->len = 0;
 l->first = l->last = (struct node *) malloc(sizeof(Node));
 l->first->elm = ((void *)0);
 l->first->next = ((void *)0);
 return l;
}

variable_types: struct list { int len; struct node { void *elm; struct node *next; } *first; struct node *last; } *

user_defined_types: struct list { int len; struct node *first; struct node *last; }


decompiled_code:
int __fastcall list_add(__int64 a1, __int64 a2)
{
__int64 v2; // rax

pthread_mutex_lock(&mutex);
if ( *(_DWORD *)a1 )
v2 = *(_QWORD *)(a1 + 16);
else
v2 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(v2 + 8) = a2;
*(_QWORD *)(a1 + 16) = a2;
++*(_DWORD *)a1;
return pthread_mutex_unlock(&mutex);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rax

pthread_mutex_lock(&mutex);
if ( *(_DWORD *)a1 )
v2 = *(_QWORD *)(a1 + 16);
else
v2 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(v2 + 8) = a2;
*(_QWORD *)(a1 + 16) = a2;
++*(_DWORD *)a1;
return pthread_mutex_unlock(&mutex);
}

original_code:
void list_add(List *l, Node *n)
{
 pthread_mutex_lock(&mutex);
 if(l->len == 0){
  l->first->next = n;
  l->last = n;
  l->len++;
 }else{
  l->last->next = n;
  l->last = n;
  l->len++;
 }
 pthread_mutex_unlock(&mutex);
}

canonical_original_code:
void list_add(struct list *l, struct node *n)
{
 pthread_mutex_lock(&mutex);
 if(l->len == 0){
  l->first->next = n;
  l->last = n;
  l->len++;
 }else{
  l->last->next = n;
  l->last = n;
  l->len++;
 }
 pthread_mutex_unlock(&mutex);
}

variable_types:
n
struct node *


decompiled_code:
__int64 __fastcall list_remove(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp

pthread_mutex_lock(&mutex);
if ( *(_DWORD *)a1 )
{
v1 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(v1 + 8);
*(_QWORD *)(v1 + 8) = *(_QWORD *)(v2 + 8);
--*(_DWORD *)a1;
pthread_mutex_unlock(&mutex);
}
else
{
pthread_mutex_unlock(&mutex);
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp

pthread_mutex_lock(&mutex);
if ( *(_DWORD *)a1 )
{
v1 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(v1 + 8);
*(_QWORD *)(v1 + 8) = *(_QWORD *)(v2 + 8);
--*(_DWORD *)a1;
pthread_mutex_unlock(&mutex);
}
else
{
pthread_mutex_unlock(&mutex);
v2 = 0LL;
}
return v2;
}

original_code:
Node *list_remove(List *l)
{
 pthread_mutex_lock(&mutex);
 if(l->len == 0){
  pthread_mutex_unlock(&mutex);
  return ((void *)0);
 }
 Node *n = l->first->next;
 l->first->next = n->next;
 l->len--;
 pthread_mutex_unlock(&mutex);
 return n;
}

canonical_original_code:
struct node *list_remove(struct list *l)
{
 pthread_mutex_lock(&mutex);
 if(l->len == 0){
  pthread_mutex_unlock(&mutex);
  return ((void *)0);
 }
 struct node *n = l->first->next;
 l->first->next = n->next;
 l->len--;
 pthread_mutex_unlock(&mutex);
 return n;
}

variable_types: struct list { int len; struct node *first; struct node *last; } *

return_type: struct node { void *elm; struct node *next; } *


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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
Node *node_new(void)
{
 Node *n;
 n = (Node *) malloc(sizeof(Node));
 n->elm = ((void *)0);
 n->next = ((void *)0);
 return n;
}

canonical_original_code:
struct node *node_new()
{
 struct node *n;
 n = (struct node *) malloc(sizeof(Node));
 n->elm = ((void *)0);
 n->next = ((void *)0);
 return n;
}


siginttrap

decompiled_code:
void __fastcall __noreturn siginttrap(unsigned int a1)
{
printf("\nI gots sigint %d\n", a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(unsigned int a1)
{
printf("\nI gots sigint %d\n", a1);
exit(0);
}

original_code:
void siginttrap(int signal){
  printf("\nI gots sigint %d\n", signal);
  exit (0);
}

variable_types: signal int


executecmd

decompiled_code:
__int64 __fastcall executecmd(const char ***a1, unsigned int a2, int a3, int a4)
{
__pid_t v6; // er12
size_t v8; // rbp
int *v9; // rax
int *v10; // rbx
__int64 v11; // rsi
_BYTE v12[8200]; // [rsp+0h] [rbp-2038h] BYREF
int pipedes[2]; // [rsp+2008h] [rbp-30h] BYREF

if ( a1 )
{
pipe(pipedes);
executecmd(a1[1], a2, (unsigned int)pipedes[1], 0LL);
v6 = fork();
if ( !v6 )
{
dup2(pipedes[0], 0);
dup2(a3, 1);
close(pipedes[1]);
signal(2, (__sighandler_t)siginttrap);
if ( execvp(**a1, (char *const *)*a1) )
{
printf("Error in: %s\n", **a1);
v10 = _errno_location();
v11 = (unsigned int)*v10;
if ( (_DWORD)v11 == 2 )
printf("%s not found\n", **a1);
else
printf("errno set to: %d", v11);
exit(*v10);
}
}
if ( a3 == 1 && !a4 )
{
waitpid(v6, 0LL, 0);
}
else if ( a3 != 1 )
{
close(a3);
}
}
else
{
if ( a2 )
{
puts("copying");
do
{
v8 = (unsigned int)read(a2, v12, 0x400uLL);
write(a3, v12, v8);
v9 = _errno_location();
printf("did %d bytes, errno is: %d\n", (unsigned int)v8, (unsigned int)*v9);
}
while ( (int)v8 > 0 );
close(a2);
}
close(a3);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char ***a1, unsigned int a2, int a3, int a4)
{
__pid_t v6; // er12
size_t v8; // rbp
int *v9; // rax
int *v10; // rbx
__int64 v11; // rsi
_BYTE v12[8200]; // [rsp+0h] [rbp-2038h] BYREF
int pipedes[2]; // [rsp+2008h] [rbp-30h] BYREF

if ( a1 )
{
pipe(pipedes);
func2(a1[1], a2, (unsigned int)pipedes[1], 0LL);
v6 = fork();
if ( !v6 )
{
dup2(pipedes[0], 0);
dup2(a3, 1);
close(pipedes[1]);
signal(2, (__sighandler_t)siginttrap);
if ( execvp(**a1, (char *const *)*a1) )
{
printf("Error in: %s\n", **a1);
v10 = _errno_location();
v11 = (unsigned int)*v10;
if ( (_DWORD)v11 == 2 )
printf("%s not found\n", **a1);
else
printf("errno set to: %d", v11);
exit(*v10);
}
}
if ( a3 == 1 && !a4 )
{
waitpid(v6, 0LL, 0);
}
else if ( a3 != 1 )
{
close(a3);
}
}
else
{
if ( a2 )
{
puts("copying");
do
{
v8 = (unsigned int)read(a2, v12, 0x400uLL);
write(a3, v12, v8);
v9 = _errno_location();
printf("did %d bytes, errno is: %d\n", (unsigned int)v8, (unsigned int)*v9);
}
while ( (int)v8 > 0 );
close(a2);
}
close(a3);
}
return 0LL;
}

original_code:
int executecmd (Cmd* cmd, int std_in, int std_out, int bg){
  if(cmd == ((void *)0)){
    if(std_in != 0){
      puts("copying");
      void* buf[1024];
      int size=0;
      do {
        size = read(std_in, buf, 1024);
        write(std_out, buf, size);
        printf("did %d bytes, errno is: %d\n", size, (*__errno_location ()));
      } while (size > 0);
      close (std_in);
    }
    close (std_out);
    return 0;
  }
  int pfds[2];
  pipe(pfds);
  executecmd(cmd->next, std_in, pfds[1], 0);
  pid_t child = fork();
  if(child==0){
    dup2(pfds[0], 0);
    dup2(std_out, 1);
    close(pfds[1]);
    signal(2, siginttrap);
    if(execvp(cmd->cmd[0], cmd->cmd)){
      printf("Error in: %s\n", cmd->cmd[0]);
      if((*__errno_location ()) == 2){
        printf("%s not found\n", cmd->cmd[0]);
      }else {
        printf("errno set to: %d", (*__errno_location ()));
      }
      exit ((*__errno_location ()));
    }
  }
  if(std_out == 1 && !bg){
    waitpid(child, ((void *)0), ((void *)0));
  }
  else if (std_out != 1){
     close(std_out);
  }
  return 0;
}

canonical_original_code:
int executecmd(struct _cmd *cmd, int std_in, int std_out, int bg){
  if(cmd == ((void *)0)){
    if(std_in != 0){
      puts("copying");
      void *buf[1024];
      int size = 0;
      do {
        size = read(std_in, buf, 1024);
        write(std_out, buf, size);
        printf("did %d bytes, errno is: %d\n", size, (*__errno_location ()));
      } while (size > 0);
      close (std_in);
    }
    close (std_out);
    return 0;
  }
  int pfds[2];
  pipe(pfds);
  executecmd(cmd->next, std_in, pfds[1], 0);
  int child = fork();
  if(child==0){
    dup2(pfds[0], 0);
    dup2(std_out, 1);
    close(pfds[1]);
    signal(2, siginttrap);
    if(execvp(cmd->cmd[0], cmd->cmd)){
      printf("Error in: %s\n", cmd->cmd[0]);
      if((*__errno_location ()) == 2){
        printf("%s not found\n", cmd->cmd[0]);
      }else {
        printf("errno set to: %d", (*__errno_location ()));
      }
      exit ((*__errno_location ()));
    }
  }
  if(std_out == 1 && !bg){
    waitpid(child, ((void *)0), ((void *)0));
  }
  else if (std_out != 1){
     close(std_out);
  }
  return 0;
}

variable_types: struct _cmd { char **cmd; struct _cmd *next; } *

variable_types: bg int

variable_types:
buf
void *[1024]

variable_types: size int

variable_types: child int


executeshellcmd

decompiled_code:
__int64 __fastcall executeshellcmd(__int64 a1)
{
const char *v2; // rdi
int v3; // ebp
const char *v4; // rdi
int v5; // edx

v2 = *(const char **)(a1 + 8);
v3 = 0;
if ( v2 )
v3 = open(v2, 0);
v4 = *(const char **)(a1 + 16);
v5 = 1;
if ( v4 )
v5 = open(v4, 65, 1LL);
executecmd(*(const char ****)a1, v3, v5, *(_DWORD *)(a1 + 32));
printshellcmd(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
const char *v2; // rdi
int v3; // ebp
const char *v4; // rdi
int v5; // edx

v2 = *(const char **)(a1 + 8);
v3 = 0;
if ( v2 )
v3 = open(v2, 0);
v4 = *(const char **)(a1 + 16);
v5 = 1;
if ( v4 )
v5 = open(v4, 65, 1LL);
func2(*(const char ****)a1, v3, v5, *(_DWORD *)(a1 + 32));
printshellcmd(a1);
return 0LL;
}

original_code:
int executeshellcmd (Shellcmd *shellcmd){
  int std_in = 0;
  if(shellcmd->rd_stdin != ((void *)0)){
    std_in = open(shellcmd->rd_stdin, 00);
  }
  int std_out = 1;
  if(shellcmd->rd_stdout != ((void *)0)){
    std_out = open(shellcmd->rd_stdout, 01|0100);
  }
  executecmd(shellcmd->the_cmds, std_in, std_out, shellcmd->background);
  printshellcmd(shellcmd);
  return 0;
}

canonical_original_code:
int executeshellcmd(struct _shellcmd *shellcmd){
  int std_in = 0;
  if(shellcmd->rd_stdin != ((void *)0)){
    std_in = open(shellcmd->rd_stdin, 00);
  }
  int std_out = 1;
  if(shellcmd->rd_stdout != ((void *)0)){
    std_out = open(shellcmd->rd_stdout, 01|0100);
  }
  executecmd(shellcmd->the_cmds, std_in, std_out, shellcmd->background);
  printshellcmd(shellcmd);
  return 0;
}

variable_types: struct _shellcmd { struct _cmd { char **cmd; struct _cmd *next; } *the_cmds; char *rd_stdin; char *rd_stdout; char *rd_stderr; int background; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE *v3; // rax
void *v4; // rbx
int v6; // ebp
_BYTE v7[48]; // [rsp+0h] [rbp-B8h] BYREF
char s[136]; // [rsp+30h] [rbp-88h] BYREF

signal(2, (__sighandler_t)((char *)siginttrap + 1));
if ( gethostname(s) )
{
while ( 1 )
{
printf("%s", s);
v3 = (_BYTE *)readline("$-> ");
v4 = v3;
if ( !v3 )
break;
if ( !*v3 )
goto LABEL_4;
add_history(v3);
if ( !strcmp((const char *)v4, "exit") )
{
free(v4);
break;
}
if ( (unsigned int)parsecommand(v4, v7) )
{
v6 = executeshellcmd((__int64)v7);
free(v4);
if ( v6 )
break;
}
else
{
LABEL_4:
free(v4);
}
}
puts("Exiting bosh.");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE *v3; // rax
void *v4; // rbx
int v6; // ebp
_BYTE v7[48]; // [rsp+0h] [rbp-B8h] BYREF
char s[136]; // [rsp+30h] [rbp-88h] BYREF

signal(2, (__sighandler_t)((char *)siginttrap + 1));
if ( func1(s) )
{
while ( 1 )
{
printf("%s", s);
v3 = (_BYTE *)readline("$-> ");
v4 = v3;
if ( !v3 )
break;
if ( !*v3 )
goto LABEL_4;
add_history(v3);
if ( !strcmp((const char *)v4, "exit") )
{
free(v4);
break;
}
if ( (unsigned int)parsecommand(v4, v7) )
{
v6 = func3((__int64)v7);
free(v4);
if ( v6 )
break;
}
else
{
LABEL_4:
free(v4);
}
}
puts("Exiting bosh.");
}
return 0;
}

original_code:
int main(int argc, char* argv[]) {
  char *cmdline;
  char hostname[100];
  int terminate = 0;
  Shellcmd shellcmd;
  signal(2, ((__sighandler_t) 1));
  if (gethostname(hostname)) {
    while (!terminate) {
      printf("%s", hostname);
      if (cmdline = readline("$-> ")) {
        if(*cmdline) {
          add_history(cmdline);
          if (!strcmp(cmdline, "exit")){
            terminate=1;
          } else if (parsecommand(cmdline, &shellcmd)) {
            terminate = executeshellcmd(&shellcmd);
          }
        }
        free(cmdline);
      } else terminate = 1;
    }
    printf("Exiting bosh.\n");
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  char *cmdline;
  char hostname[100];
  int terminate = 0;
  struct _shellcmd shellcmd;
  signal(2, ((void (*)(int)) 1));
  if (gethostname(hostname)) {
    while (!terminate) {
      printf("%s", hostname);
      if (cmdline = readline("$-> ")) {
        if(*cmdline) {
          add_history(cmdline);
          if (!strcmp(cmdline, "exit")){
            terminate=1;
          } else if (parsecommand(cmdline, &shellcmd)) {
            terminate = executeshellcmd(&shellcmd);
          }
        }
        free(cmdline);
      } else terminate = 1;
    }
    printf("Exiting bosh.\n");
  }
  return 0;
}

variable_types:
cmdline
char *

variable_types:
hostname
char [100]

variable_types: terminate int

variable_types: struct _shellcmd { struct _cmd { char **cmd; struct _cmd *next; } *the_cmds; char *rd_stdin; char *rd_stdout; char *rd_stderr; int background; }


printshellcmd

decompiled_code:
int __fastcall printshellcmd(__int64 *a1)
{
const char *v1; // rsi
const char *v2; // rsi
const char *v3; // rsi
int result; // eax
__int64 i; // rbp
const char **v6; // rbx
const char *j; // rsi

puts("Shellcommand:");
v1 = (const char *)a1[1];
if ( !v1 )
v1 = "<none>";
printf(" stdin : %s\n", v1);
v2 = (const char *)a1[2];
if ( !v2 )
v2 = "<none>";
printf(" stdout: %s\n", v2);
v3 = "yes";
if ( !*((_DWORD *)a1 + 8) )
v3 = "no";
result = printf(" bg : %s\n", v3);
for ( i = *a1; i; result = puts("]") )
{
v6 = *(const char ***)i;
i = *(_QWORD *)(i + 8);
printf(" [");
for ( j = *v6; *v6; j = *v6 )
{
++v6;
printf("%s ", j);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1)
{
const char *v1; // rsi
const char *v2; // rsi
const char *v3; // rsi
int result; // eax
__int64 i; // rbp
const char **v6; // rbx
const char *j; // rsi

puts("Shellcommand:");
v1 = (const char *)a1[1];
if ( !v1 )
v1 = "<none>";
printf(" stdin : %s\n", v1);
v2 = (const char *)a1[2];
if ( !v2 )
v2 = "<none>";
printf(" stdout: %s\n", v2);
v3 = "yes";
if ( !*((_DWORD *)a1 + 8) )
v3 = "no";
result = printf(" bg : %s\n", v3);
for ( i = *a1; i; result = puts("]") )
{
v6 = *(const char ***)i;
i = *(_QWORD *)(i + 8);
printf(" [");
for ( j = *v6; *v6; j = *v6 )
{
++v6;
printf("%s ", j);
}
}
return result;
}

original_code:
void printshellcmd(Shellcmd *shellcmd)
{
  printf("Shellcommand:\n");
  printf("   stdin : %s\n", shellcmd->rd_stdin ? shellcmd->rd_stdin : "<none>" );
  printf("   stdout: %s\n", shellcmd->rd_stdout ? shellcmd->rd_stdout : "<none>" );
  printf("   bg    : %s\n", shellcmd->background ? "yes" : "no");
  Cmd *cmdlist = shellcmd->the_cmds;
  while (cmdlist != ((void *)0)) {
    char **cmd = cmdlist->cmd;
    cmdlist = cmdlist->next;
    char **printcmd = cmd;
    printf("    [");
    while (*printcmd != ((void *)0)) {
      printf("%s ", *printcmd++);
    }
    printf("]\n");
  }
}

canonical_original_code:
void printshellcmd(struct _shellcmd *shellcmd)
{
  printf("Shellcommand:\n");
  printf("   stdin : %s\n", shellcmd->rd_stdin ? shellcmd->rd_stdin : "<none>" );
  printf("   stdout: %s\n", shellcmd->rd_stdout ? shellcmd->rd_stdout : "<none>" );
  printf("   bg    : %s\n", shellcmd->background ? "yes" : "no");
  struct _cmd *cmdlist = shellcmd->the_cmds;
  while (cmdlist != ((void *)0)) {
    char **cmd = cmdlist->cmd;
    cmdlist = cmdlist->next;
    char **printcmd = cmd;
    printf("    [");
    while (*printcmd != ((void *)0)) {
      printf("%s ", *printcmd++);
    }
    printf("]\n");
  }
}

variable_types:
cmd
char **

variable_types:
printcmd
char **

user_defined_types: struct _cmd { char **cmd; struct _cmd *next; }


getVariableType

repo: BleuLlama/BLBasic

decompiled_code:
__int64 __fastcall getVariableType(const char *a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = 0LL;
if ( *a1 )
result = (unsigned int)(a1[strlen(a1) - 1] != 36) + 1;
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *a1 )
result = (unsigned int)(a1[strlen(a1) - 1] != 36) + 1;
return result;
}

original_code:
int getVariableType( char * name )
{
 if( !name ) return 0;
 if( strlen(name) == 0 ) return 0;
 if( name[strlen(name)-1] == '$' ) return 1;
 return 2;
}

canonical_original_code:
int getVariableType(char *name)
{
 if( !name ) return 0;
 if( strlen(name) == 0 ) return 0;
 if( name[strlen(name)-1] == '$' ) return 1;
 return 2;
}

variable_types:
name
char *


clearVariableAux

decompiled_code:
void __fastcall clearVariableAux(__int64 a1)
{
for ( ; a1; a1 = *(_QWORD *)(a1 + 32) )
*(_QWORD *)(a1 + 40) = 0LL;
}

original_code:
void clearVariableAux( basic_variable * list )
{
 while( list )
 {
  list->forStartLine = 0;
  list = list->next;
 }
}

canonical_original_code:
void clearVariableAux(struct basic_variable *list)
{
 while( list )
 {
  list->forStartLine = 0;
  list = list->next;
 }
}

variable_types: struct basic_variable { char *name; int protect; int type; long l_data; char *c_data; struct basic_variable *next; long forStartLine; } *


dumpVariables

decompiled_code:
int __fastcall dumpVariables(__int64 a1)
{
__int64 v1; // rbx
int result; // eax
const char *v3; // rcx
const char *v4; // rdx
const char *v5; // rsi
const char *v6; // rcx
const char *v7; // rsi

v1 = a1;
for ( result = puts("Variable List:"); v1; v1 = *(_QWORD *)(v1 + 32) )
{
result = *(_DWORD *)(v1 + 12);
if ( result == 1 )
{
v3 = (const char *)&unk_429;
if ( *(_DWORD *)(v1 + 8) )
v3 = "(protected)";
v4 = *(const char **)(v1 + 24);
if ( !v4 )
v4 = "ERR";
v5 = *(const char **)v1;
if ( !*(_QWORD *)v1 )
v5 = "ERR";
result = printf("%16s : \"%s\" %s\n", v5, v4, v3);
}
else if ( result == 2 )
{
v6 = (const char *)&unk_429;
if ( *(_DWORD *)(v1 + 8) )
v6 = "(protected)";
v7 = *(const char **)v1;
if ( !*(_QWORD *)v1 )
v7 = "ERR";
result = printf("%16s : %ld %s\n", v7, *(_QWORD *)(v1 + 16), v6);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
int result; // eax
const char *v3; // rcx
const char *v4; // rdx
const char *v5; // rsi
const char *v6; // rcx
const char *v7; // rsi

v1 = a1;
for ( result = puts("Variable List:"); v1; v1 = *(_QWORD *)(v1 + 32) )
{
result = *(_DWORD *)(v1 + 12);
if ( result == 1 )
{
v3 = (const char *)&unk_429;
if ( *(_DWORD *)(v1 + 8) )
v3 = "(protected)";
v4 = *(const char **)(v1 + 24);
if ( !v4 )
v4 = "ERR";
v5 = *(const char **)v1;
if ( !*(_QWORD *)v1 )
v5 = "ERR";
result = printf("%16s : \"%s\" %s\n", v5, v4, v3);
}
else if ( result == 2 )
{
v6 = (const char *)&unk_429;
if ( *(_DWORD *)(v1 + 8) )
v6 = "(protected)";
v7 = *(const char **)v1;
if ( !*(_QWORD *)v1 )
v7 = "ERR";
result = printf("%16s : %ld %s\n", v7, *(_QWORD *)(v1 + 16), v6);
}
}
return result;
}

original_code:
void dumpVariables( basic_variable * list )
{
 printf( "Variable List:\n" );
 while( list ) {
  switch( list->type ) {
  case( 1 ):
   printf( "%16s : \"%s\" %s\n",
    list->name?list->name:"ERR",
    list->c_data?list->c_data:"ERR",
    list->protect?"(protected)":""
    );
   break;
  case( 2 ):
   printf( "%16s : %ld %s\n",
    list->name?list->name:"ERR",
    list->l_data,
    list->protect?"(protected)":""
    );
   break;
  }
  list = list->next;
 }
}

canonical_original_code:
void dumpVariables(struct basic_variable *list)
{
 printf( "Variable List:\n" );
 while( list ) {
  switch( list->type ) {
  case( 1 ):
   printf( "%16s : \"%s\" %s\n",
    list->name?list->name:"ERR",
    list->c_data?list->c_data:"ERR",
    list->protect?"(protected)":""
    );
   break;
  case( 2 ):
   printf( "%16s : %ld %s\n",
    list->name?list->name:"ERR",
    list->l_data,
    list->protect?"(protected)":""
    );
   break;
  }
  list = list->next;
 }
}

user_defined_types: struct basic_variable { char *name; int protect; int type; long l_data; char *c_data; struct basic_variable *next; long forStartLine; }


findVariable

decompiled_code:
__int64 __fastcall findVariable(__int64 a1, const char *a2)
{
__int64 v2; // rbx

v2 = a1;
if ( !a1 )
return 0LL;
while ( strcmp(a2, *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 32);
if ( !v2 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
__int64 v2; // rbx

v2 = a1;
if ( !a1 )
return 0LL;
while ( strcmp(a2, *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 32);
if ( !v2 )
return 0LL;
}
return v2;
}

original_code:
basic_variable * findVariable( basic_variable * list, char * name )
{
 basic_variable * el = list;
 while( el ) {
  if( !strcmp( name, el->name )) return el;
  el = el->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct basic_variable *findVariable(struct basic_variable *list, char *name)
{
 struct basic_variable *el = list;
 while( el ) {
  if( !strcmp( name, el->name )) return el;
  el = el->next;
 }
 return ((void *)0);
}

variable_types:
list
struct basic_variable *

return_type: struct basic_variable { char *name; int protect; int type; long l_data; char *c_data; struct basic_variable *next; long forStartLine; } *


isProtectedVariable

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

if ( !a2 || !a1 )
return 0LL;
v2 = findVariable(a1, a2);
result = 0LL;
if ( v2 )
result = *(unsigned int *)(v2 + 8);
return result;
}

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

if ( !a2 || !a1 )
return 0LL;
v2 = func4(a1, a2);
result = 0LL;
if ( v2 )
result = *(unsigned int *)(v2 + 8);
return result;
}

original_code:
int isProtectedVariable( basic_variable * list, char * name )
{
 basic_variable * v;
 if( !name || !list ) return 0;
 v = findVariable( list, name );
 if( v ) {
  return v->protect;
 }
 return 0;
}

canonical_original_code:
int isProtectedVariable(struct basic_variable *list, char *name)
{
 struct basic_variable *v;
 if( !name || !list ) return 0;
 v = findVariable( list, name );
 if( v ) {
  return v->protect;
 }
 return 0;
}


getVariableNumber

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

if ( !a1 || !a2 )
return 0LL;
v2 = findVariable(a1, a2);
result = 0LL;
if ( v2 )
result = *(_QWORD *)(v2 + 16);
return result;
}

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

if ( !a1 || !a2 )
return 0LL;
v2 = func4(a1, a2);
result = 0LL;
if ( v2 )
result = *(_QWORD *)(v2 + 16);
return result;
}

original_code:
long getVariableNumber( basic_variable * list, char * name )
{
 basic_variable * tn;
 if( !list || !name ) return 0;
 tn = findVariable( list, name );
 if( tn ) {
  return( tn->l_data );
 }
 return 0;
}

canonical_original_code:
long getVariableNumber(struct basic_variable *list, char *name)
{
 struct basic_variable *tn;
 if( !list || !name ) return 0;
 tn = findVariable( list, name );
 if( tn ) {
  return( tn->l_data );
 }
 return 0;
}

return_type: long


getVariableString

decompiled_code:
void *__fastcall getVariableString(__int64 a1, const char *a2)
{
__int64 v2; // rdx
void *result; // rax

if ( !a1 || !a2 )
return &unk_429;
v2 = findVariable(a1, a2);
result = &unk_429;
if ( v2 )
result = *(void **)(v2 + 24);
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, const char *a2)
{
__int64 v2; // rdx
void *result; // rax

if ( !a1 || !a2 )
return &unk_429;
v2 = func4(a1, a2);
result = &unk_429;
if ( v2 )
result = *(void **)(v2 + 24);
return result;
}

original_code:
char * getVariableString( basic_variable * list, char * name )
{
 basic_variable * tn;
 if( !list || !name ) return "";
 tn = findVariable( list, name );
 if( tn ) {
  return( tn->c_data );
 }
 return "";
}

canonical_original_code:
char *getVariableString(struct basic_variable *list, char *name)
{
 struct basic_variable *tn;
 if( !list || !name ) return "";
 tn = findVariable( list, name );
 if( tn ) {
  return( tn->c_data );
 }
 return "";
}

return_type: char *


signalBreak

decompiled_code:
void __fastcall signalBreak(int a1)
{
if ( (unsigned int)(a1 - 1) <= 1 )
{
printf("BREAK %d/5!\n", (unsigned int)(breakCount + 1));
if ( ++breakCount > 4 )
exit(0);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( (unsigned int)(a1 - 1) <= 1 )
{
printf("BREAK %d/5!\n", (unsigned int)(breakCount + 1));
if ( ++breakCount > 4 )
exit(0);
}
}

original_code:
void signalBreak( int sig )
{
 if( sig == 1 || sig == 2 ) {
  printf( "BREAK %d/5!\n", breakCount+1 );
  breakCount++;
  if( breakCount >= 5 ) {
   exit( 0 );
  }
 }
}

canonical_original_code:
void signalBreak(int sig)
{
 if( sig == 1 || sig == 2 ) {
  printf( "BREAK %d/5!\n", breakCount+1 );
  breakCount++;
  if( breakCount >= 5 ) {
   exit( 0 );
  }
 }
}

variable_types: sig int


startInfo

decompiled_code:
int __fastcall startInfo(__int64 a1)
{
cmd_info(a1, 0LL);
return puts("Ready.");
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
cmd_info(a1, 0LL);
return puts("Ready.");
}

original_code:
void startInfo( basic_program * bp )
{
 cmd_info( bp, ((void *)0) );
 printf( "Ready.\n" );
}

canonical_original_code:
void startInfo(struct basic_program *bp)
{
 cmd_info( bp, ((void *)0) );
 printf( "Ready.\n" );
}

variable_types: struct basic_program { int exitNow; struct basic_line { long lineNumber; int temp; struct basic_token { int token_id; long l_data; char *c_data; struct basic_token *next; struct basic_token *shunt; struct basic_token *nextData; } *tokens; struct basic_line *next; struct basic_line *prev; struct basic_line *continuation; struct basic_line *continuationParent; struct basic_token *nextData; } *listing; int traceOn; struct basic_line *runningLine; long nextLineNumberToExecute; struct basic_line *gosubList[256]; int nGosubLevels; struct basic_variable { char *name; int protect; int type; long l_data; char *c_data; struct basic_variable *next; long forStartLine; } *variables; struct basic_token *firstData; struct basic_token *currentData; } *

user_defined_types: struct basic_program { int exitNow; struct basic_line *listing; int traceOn; struct basic_line *runningLine; long nextLineNumberToExecute; struct basic_line *gosubList[256]; int nGosubLevels; struct basic_variable *variables; struct basic_token *firstData; struct basic_token *currentData; }

user_defined_types: struct basic_line { long lineNumber; int temp; struct basic_token *tokens; struct basic_line *next; struct basic_line *prev; struct basic_line *continuation; struct basic_line *continuationParent; struct basic_token *nextData; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
_QWORD *i; // r12
_QWORD *v7; // rbp
_QWORD *v8; // rax
char v9[1048]; // [rsp+0h] [rbp-418h] BYREF

signal(2, signalBreak);
signal(1, signalBreak);
mkdir("./programs", 0x1EDu);
v3 = newProgram();
if ( v3 )
{
v4 = v3;
startInfo(v3);
do
{
fwrite(">: ", 1uLL, 3uLL, stdout);
fflush(stdout);
fgets(v9, 1024, stdin);
v8 = (_QWORD *)consumeString(v4, v9);
v7 = v8;
if ( v8 )
{
if ( *v8 == -1LL )
{
evaluateLine(v4, v8);
for ( i = (_QWORD *)v7[5]; i; i = (_QWORD *)i[5] )
{
evaluateLine(v4, i);
v7 = i;
}
deleteLines(v7);
}
else if ( *(_DWORD *)(v4 + 16) )
{
stringizeLine(v8, v9, 1024LL);
puts(v9);
}
}
breakCount = 0;
while ( (unsigned int)run_poll(v4) && !breakCount )
{
run_poll(v4);
if ( *(_DWORD *)(v4 + 16) )
dumpVariables(*(_QWORD *)(v4 + 2096));
usleep(0x3E8u);
}
if ( *(_DWORD *)(v4 + 16) )
dumpVariables(*(_QWORD *)(v4 + 2096));
*(_QWORD *)(v4 + 24) = 0LL;
*(_QWORD *)(v4 + 32) = -1LL;
}
while ( !*(_DWORD *)v4 );
}
else
{
errorReport(0xFFFFFFFFLL, 1LL);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
_QWORD *i; // r12
_QWORD *v7; // rbp
_QWORD *v8; // rax
char v9[1048]; // [rsp+0h] [rbp-418h] BYREF

signal(2, signalBreak);
signal(1, signalBreak);
mkdir("./programs", 0x1EDu);
v3 = newProgram();
if ( v3 )
{
v4 = v3;
func1(v3);
do
{
fwrite(">: ", 1uLL, 3uLL, stdout);
fflush(stdout);
fgets(v9, 1024, stdin);
v8 = (_QWORD *)consumeString(v4, v9);
v7 = v8;
if ( v8 )
{
if ( *v8 == -1LL )
{
evaluateLine(v4, v8);
for ( i = (_QWORD *)v7[5]; i; i = (_QWORD *)i[5] )
{
evaluateLine(v4, i);
v7 = i;
}
deleteLines(v7);
}
else if ( *(_DWORD *)(v4 + 16) )
{
stringizeLine(v8, v9, 1024LL);
puts(v9);
}
}
breakCount = 0;
while ( (unsigned int)run_poll(v4) && !breakCount )
{
run_poll(v4);
if ( *(_DWORD *)(v4 + 16) )
dumpVariables(*(_QWORD *)(v4 + 2096));
usleep(0x3E8u);
}
if ( *(_DWORD *)(v4 + 16) )
dumpVariables(*(_QWORD *)(v4 + 2096));
*(_QWORD *)(v4 + 24) = 0LL;
*(_QWORD *)(v4 + 32) = -1LL;
}
while ( !*(_DWORD *)v4 );
}
else
{
errorReport(0xFFFFFFFFLL, 1LL);
}
return 0;
}

original_code:
int main( int argc, char ** argv )
{
 basic_program * bp;
 basic_line * bl;
 char lnbuf[1024];
 (void) signal( 2, signalBreak );
 (void) signal( 1, signalBreak );
 mkdir( "./programs", 0755 );
 bp = newProgram();
 if( !bp ) {
  errorReport( -1, 1 );
  return 0;
 }
 startInfo( bp );
 do {
  fprintf( stdout, ">: " ); fflush( stdout );
  fgets( lnbuf, 1024, stdin);
  bl = consumeString( bp, lnbuf );
  if( bl ) {
   if( bl->lineNumber == -1 ) {
    evaluateLine( bp, bl );
    while( bl->continuation ) {
     bl = bl->continuation;
     evaluateLine( bp, bl );
    }
    deleteLines( bl );
   } else {
    if( bp->traceOn ) {
     stringizeLine( bl, lnbuf, 1024 );
     printf( "%s\n", lnbuf );
    }
   }
  }
  breakCount = 0;
  while( run_poll( bp ) && !breakCount )
  {
   run_poll( bp );
   if( bp->traceOn ) {
    dumpVariables( bp->variables );
   }
   usleep( 1 * 1000 );
  }
  if( bp->traceOn ) {
   dumpVariables( bp->variables );
  }
  bp->runningLine = ((void *)0);
  bp->nextLineNumberToExecute = -1;
 } while( !bp->exitNow );
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct basic_program *bp;
 struct basic_line *bl;
 char lnbuf[1024];
 (void) signal( 2, signalBreak );
 (void) signal( 1, signalBreak );
 mkdir( "./programs", 0755 );
 bp = newProgram();
 if( !bp ) {
  errorReport( -1, 1 );
  return 0;
 }
 startInfo( bp );
 do {
  fprintf( stdout, ">: " ); fflush( stdout );
  fgets( lnbuf, 1024, stdin);
  bl = consumeString( bp, lnbuf );
  if( bl ) {
   if( bl->lineNumber == -1 ) {
    evaluateLine( bp, bl );
    while( bl->continuation ) {
     bl = bl->continuation;
     evaluateLine( bp, bl );
    }
    deleteLines( bl );
   } else {
    if( bp->traceOn ) {
     stringizeLine( bl, lnbuf, 1024 );
     printf( "%s\n", lnbuf );
    }
   }
  }
  breakCount = 0;
  while( run_poll( bp ) && !breakCount )
  {
   run_poll( bp );
   if( bp->traceOn ) {
    dumpVariables( bp->variables );
   }
   usleep( 1 * 1000 );
  }
  if( bp->traceOn ) {
   dumpVariables( bp->variables );
  }
  bp->runningLine = ((void *)0);
  bp->nextLineNumberToExecute = -1;
 } while( !bp->exitNow );
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct basic_line { long lineNumber; int temp; struct basic_token { int token_id; long l_data; char *c_data; struct basic_token *next; struct basic_token *shunt; struct basic_token *nextData; } *tokens; struct basic_line *next; struct basic_line *prev; struct basic_line *continuation; struct basic_line *continuationParent; struct basic_token *nextData; } *

variable_types:
lnbuf
char [1024]


errorReportAdditional

decompiled_code:
int __fastcall errorReportAdditional(int a1, unsigned int a2, const char *a3)
{
const char *v4; // r8

switch ( a1 )
{
case -17:
v4 = "Divide by zero error.";
break;
case -16:
v4 = "Out of DATA error.";
break;
case -15:
v4 = "For-Next error.";
break;
case -14:
v4 = "ON target address not found.";
break;
case -13:
v4 = "Not a runnable command.";
break;
case -12:
v4 = "Directory is unreadable.";
break;
case -11:
v4 = "RETURN to nowhere.";
break;
case -10:
v4 = "GOSUB max depth reached.";
break;
case -9:
v4 = "Nonsense in BASIC.";
break;
case -8:
v4 = "Unavailable line number.";
break;
case -7:
v4 = "No program data.";
break;
case -6:
v4 = "Data stream error.";
break;
case -5:
v4 = "File IO error.";
break;
case -4:
v4 = "File not found.";
break;
case -3:
v4 = "A parameter type is incorrect.";
break;
case -2:
v4 = "Parameter list incorrect.";
break;
case -1:
v4 = "Could not allocate memory.";
break;
case 0:
v4 = "No error.";
break;
default:
v4 = "Unknown.";
break;
}
fprintf(stderr, "ERROR %d-%d: %s", (unsigned int)-a1, a2, v4);
if ( a3 )
fprintf(stderr, "(%s)", a3);
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func0(int a1, unsigned int a2, const char *a3)
{
const char *v4; // r8

switch ( a1 )
{
case -17:
v4 = "Divide by zero error.";
break;
case -16:
v4 = "Out of DATA error.";
break;
case -15:
v4 = "For-Next error.";
break;
case -14:
v4 = "ON target address not found.";
break;
case -13:
v4 = "Not a runnable command.";
break;
case -12:
v4 = "Directory is unreadable.";
break;
case -11:
v4 = "RETURN to nowhere.";
break;
case -10:
v4 = "GOSUB max depth reached.";
break;
case -9:
v4 = "Nonsense in BASIC.";
break;
case -8:
v4 = "Unavailable line number.";
break;
case -7:
v4 = "No program data.";
break;
case -6:
v4 = "Data stream error.";
break;
case -5:
v4 = "File IO error.";
break;
case -4:
v4 = "File not found.";
break;
case -3:
v4 = "A parameter type is incorrect.";
break;
case -2:
v4 = "Parameter list incorrect.";
break;
case -1:
v4 = "Could not allocate memory.";
break;
case 0:
v4 = "No error.";
break;
default:
v4 = "Unknown.";
break;
}
fprintf(stderr, "ERROR %d-%d: %s", (unsigned int)-a1, a2, v4);
if ( a3 )
fprintf(stderr, "(%s)", a3);
return fputc(10, stderr);
}

original_code:
void errorReportAdditional( int code, int codeMinor, char * additional )
{
 char * msg = "Unknown.";
 switch( code )
 {
 case( 0 ): msg = "No error."; break;
 case( -1 ): msg = "Could not allocate memory."; break;
 case( -2 ): msg = "Parameter list incorrect."; break;
 case( -3 ): msg = "A parameter type is incorrect."; break;
 case( -4 ): msg = "File not found."; break;
 case( -5 ): msg = "File IO error."; break;
 case( -6 ): msg = "Data stream error."; break;
 case( -7 ): msg = "No program data."; break;
 case( -8 ): msg = "Unavailable line number."; break;
 case( -9 ): msg = "Nonsense in BASIC."; break;
 case( -10 ): msg = "GOSUB max depth reached."; break;
 case( -11 ): msg = "RETURN to nowhere."; break;
 case( -12 ): msg = "Directory is unreadable."; break;
 case( -13 ): msg = "Not a runnable command."; break;
 case( -14 ): msg = "ON target address not found."; break;
 case( -15 ): msg = "For-Next error."; break;
 case( -16 ): msg = "Out of DATA error."; break;
 case( -17 ): msg = "Divide by zero error."; break;
 default:
  break;
 }
 fprintf( stderr, "ERROR %d-%d: %s", -code, codeMinor, msg );
 if( additional )
 {
  fprintf( stderr, "(%s)", additional );
 }
 fprintf( stderr, "\n" );
}

canonical_original_code:
void errorReportAdditional(int code, int codeMinor, char *additional)
{
 char *msg = "Unknown.";
 switch( code )
 {
 case( 0 ): msg = "No error."; break;
 case( -1 ): msg = "Could not allocate memory."; break;
 case( -2 ): msg = "Parameter list incorrect."; break;
 case( -3 ): msg = "A parameter type is incorrect."; break;
 case( -4 ): msg = "File not found."; break;
 case( -5 ): msg = "File IO error."; break;
 case( -6 ): msg = "Data stream error."; break;
 case( -7 ): msg = "No program data."; break;
 case( -8 ): msg = "Unavailable line number."; break;
 case( -9 ): msg = "Nonsense in BASIC."; break;
 case( -10 ): msg = "GOSUB max depth reached."; break;
 case( -11 ): msg = "RETURN to nowhere."; break;
 case( -12 ): msg = "Directory is unreadable."; break;
 case( -13 ): msg = "Not a runnable command."; break;
 case( -14 ): msg = "ON target address not found."; break;
 case( -15 ): msg = "For-Next error."; break;
 case( -16 ): msg = "Out of DATA error."; break;
 case( -17 ): msg = "Divide by zero error."; break;
 default:
  break;
 }
 fprintf( stderr, "ERROR %d-%d: %s", -code, codeMinor, msg );
 if( additional )
 {
  fprintf( stderr, "(%s)", additional );
 }
 fprintf( stderr, "\n" );
}

variable_types: code int

variable_types: codeMinor int

variable_types:
additional
char *

variable_types:
msg
char *


errorReport

decompiled_code:
int __fastcall errorReport(int a1, unsigned int a2)
{
return errorReportAdditional(a1, a2, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(int a1, unsigned int a2)
{
return func0(a1, a2, 0LL);
}

original_code:
void errorReport( int code, int codeMinor )
{
 errorReportAdditional( code, codeMinor, ((void *)0) );
}

canonical_original_code:
void errorReport(int code, int codeMinor)
{
 errorReportAdditional( code, codeMinor, ((void *)0) );
}


newString

decompiled_code:
char *__fastcall newString(const char *a1)
{
if ( !a1 )
a1 = &s;
return strdup(a1);
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
if ( !a1 )
a1 = &s;
return strdup(a1);
}

original_code:
char * newString( char * content )
{
 char * ret;
 if( !content ) content = "";
 ret = strdup( content );
 return ret;
}

canonical_original_code:
char *newString(char *content)
{
 char *ret;
 if( !content ) content = "";
 ret = strdup( content );
 return ret;
}

variable_types:
content
char *

variable_types:
ret
char *


appendString

decompiled_code:
char *__fastcall appendString(void *ptr, char *src)
{
char *v2; // rbx
size_t v3; // rbp
size_t v4; // rax

v2 = (char *)ptr;
if ( src )
{
if ( !ptr )
v2 = newString(&s);
v3 = strlen(src);
v4 = strlen(v2);
v2 = (char *)realloc(v2, v3 + v4 + 2);
strcat(v2, src);
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(void *ptr, char *src)
{
char *v2; // rbx
size_t v3; // rbp
size_t v4; // rax

v2 = (char *)ptr;
if ( src )
{
if ( !ptr )
v2 = func0(&s);
v3 = strlen(src);
v4 = strlen(v2);
v2 = (char *)realloc(v2, v3 + v4 + 2);
strcat(v2, src);
}
return v2;
}

original_code:
char * appendString( char * start, char * newBit )
{
 char * ret;
 if( newBit == ((void *)0) ) return start;
 if( !start ) start = newString( "" );
 ret = realloc( start, strlen( newBit ) + strlen( start ) + 2 );
 strcat( ret, newBit );
 return ret;
}

canonical_original_code:
char *appendString(char *start, char *newBit)
{
 char *ret;
 if( newBit == ((void *)0) ) return start;
 if( !start ) start = newString( "" );
 ret = realloc( start, strlen( newBit ) + strlen( start ) + 2 );
 strcat( ret, newBit );
 return ret;
}

variable_types:
start
char *

variable_types:
newBit
char *


appendNumber

decompiled_code:
char *__fastcall appendNumber(void *ptr, __int64 a2)
{
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

snprintf(v3, 0x20uLL, "%ld", a2);
return appendString(ptr, v3);
}

canonical_decompiled_code:
char *__fastcall func2(void *ptr, __int64 a2)
{
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

snprintf(v3, 0x20uLL, "%ld", a2);
return func1(ptr, v3);
}

original_code:
char * appendNumber( char * start, long newBit )
{
 char buf[32];
 snprintf( buf, 32, "%ld", newBit );
 return appendString( start, buf );
}

canonical_original_code:
char *appendNumber(char *start, long newBit)
{
 char buf[32];
 snprintf( buf, 32, "%ld", newBit );
 return appendString( start, buf );
}

variable_types: newBit long

variable_types:
buf
char [32]


stringChomp

decompiled_code:
const char *__fastcall stringChomp(const char *a1)
{
int v1; // eax
const char *v2; // rax

if ( a1 )
{
v1 = strlen(a1);
if ( v1 > 0 )
{
v2 = &a1[v1 - 1];
if ( *v2 == 10 )
{
*v2 = 0;
}
else if ( *v2 == 13 )
{
*v2 = 0;
}
}
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func3(const char *a1)
{
int v1; // eax
const char *v2; // rax

if ( a1 )
{
v1 = strlen(a1);
if ( v1 > 0 )
{
v2 = &a1[v1 - 1];
if ( *v2 == 10 )
{
*v2 = 0;
}
else if ( *v2 == 13 )
{
*v2 = 0;
}
}
}
return a1;
}

original_code:
char * stringChomp( char * str )
{
 int len;
 if( !str ) return ((void *)0);
 len = strlen( str );
 if( len < 1 ) return str;
 if( str[len-1] == '\n' )
     str[len-1] = '\0';
 if( str[len-1] == '\r' )
     str[len-1] = '\0';
 return str;
}

canonical_original_code:
char *stringChomp(char *str)
{
 int len;
 if( !str ) return ((void *)0);
 len = strlen( str );
 if( len < 1 ) return str;
 if( str[len-1] == '\n' )
     str[len-1] = '\0';
 if( str[len-1] == '\r' )
     str[len-1] = '\0';
 return str;
}

variable_types:
str
char *

variable_types: len int


getLineFromUser

decompiled_code:
char *getLineFromUser()
{
char v1[1032]; // [rsp+0h] [rbp-408h] BYREF

fgets(v1, 1024, stdin);
return strdup(v1);
}

canonical_decompiled_code:
char *func4()
{
char v1[1032]; // [rsp+0h] [rbp-408h] BYREF

fgets(v1, 1024, stdin);
return strdup(v1);
}

original_code:
char * getLineFromUser( void )
{
 char lnbuf[1024];
 fgets( lnbuf, 1024, stdin );
 return( strdup( lnbuf ));
}

canonical_original_code:
char *getLineFromUser()
{
 char lnbuf[1024];
 fgets( lnbuf, 1024, stdin );
 return( strdup( lnbuf ));
}


repo: BleuLlama/model-t-shell

decompiled_code:
unsigned __int64 __fastcall items_Init(int a1, int a2)
{
unsigned __int64 result; // rax
__int64 v3; // rbx
void *v4; // rdi

gridwide = a1 / 14;
gridtall = a2 - 4;
result = (unsigned int)((a2 - 4) * (a1 / 14));
if ( maxItems != (_DWORD)result )
{
if ( itemList )
{
if ( maxItems > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)*((_QWORD *)itemList + 4 * v3 + 2);
if ( v4 )
free(v4);
++v3;
}
while ( maxItems > (int)v3 );
}
free(itemList);
}
maxItems = gridtall * gridwide;
result = (unsigned __int64)calloc(gridtall * gridwide, 0x20uLL);
itemList = (void *)result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int a1, int a2)
{
unsigned __int64 result; // rax
__int64 v3; // rbx
void *v4; // rdi

gridwide = a1 / 14;
gridtall = a2 - 4;
result = (unsigned int)((a2 - 4) * (a1 / 14));
if ( maxItems != (_DWORD)result )
{
if ( itemList )
{
if ( maxItems > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)*((_QWORD *)itemList + 4 * v3 + 2);
if ( v4 )
free(v4);
++v3;
}
while ( maxItems > (int)v3 );
}
free(itemList);
}
maxItems = gridtall * gridwide;
result = (unsigned __int64)calloc(gridtall * gridwide, 0x20uLL);
itemList = (void *)result;
}
return result;
}

original_code:
void items_Init( int mx, int my )
{
 int pad = 1;
 int nmi = 0;
 gridwide = (int) floor( mx/14 );
 gridtall = my -2 - (pad * 2);
 nmi = gridwide * gridtall;
 if( nmi == maxItems ) return;
 if( itemList ) {
  int idx;
  for( idx=0; idx<maxItems ; idx++ ) {
   if( itemList[idx].full ) free( itemList[idx].full );
  }
  free( itemList );
 }
 maxItems = gridwide * gridtall;
 itemList = (anItem *)calloc( maxItems, sizeof( anItem ) );
}

canonical_original_code:
void items_Init(int mx, int my)
{
 int pad = 1;
 int nmi = 0;
 gridwide = (int) floor( mx/14 );
 gridtall = my -2 - (pad * 2);
 nmi = gridwide * gridtall;
 if( nmi == maxItems ) return;
 if( itemList ) {
  int idx;
  for( idx=0; idx<maxItems ; idx++ ) {
   if( itemList[idx].full ) free( itemList[idx].full );
  }
  free( itemList );
 }
 maxItems = gridwide * gridtall;
 itemList = (struct anItem *)calloc( maxItems, sizeof( anItem ) );
}

variable_types: mx int

variable_types: my int

variable_types: pad int

variable_types: nmi int

variable_types: idx int

user_defined_types: struct anItem { char display[14]; char *full; int flags; }


decompiled_code:
__int64 __fastcall items_Add(char *src, char *s, int a3)
{
char *v4; // r12
int v5; // edx
__int64 result; // rax

strncpy((char *)itemList + 32 * nItems, src, 0x100uLL);
if ( s )
{
v4 = (char *)itemList + 32 * nItems;
*((_QWORD *)v4 + 2) = strdup(s);
}
v5 = nItems;
result = (__int64)itemList + 32 * nItems;
*(_DWORD *)(result + 24) = a3;
nItems = v5 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, char *s, int a3)
{
char *v4; // r12
int v5; // edx
__int64 result; // rax

strncpy((char *)itemList + 32 * nItems, src, 0x100uLL);
if ( s )
{
v4 = (char *)itemList + 32 * nItems;
*((_QWORD *)v4 + 2) = strdup(s);
}
v5 = nItems;
result = (__int64)itemList + 32 * nItems;
*(_DWORD *)(result + 24) = a3;
nItems = v5 + 1;
return result;
}

original_code:
void items_Add( char * display, char * full, int flags )
{
 strncpy( itemList[ nItems ].display, display, (256) );
 if( full ) itemList[ nItems ].full = strdup( full );
 itemList[ nItems ].flags = flags;
 nItems++;
}

canonical_original_code:
void items_Add(char *display, char *full, int flags)
{
 strncpy( itemList[ nItems ].display, display, (256) );
 if( full ) itemList[ nItems ].full = strdup( full );
 itemList[ nItems ].flags = flags;
 nItems++;
}

variable_types:
display
char *

variable_types:
full
char *

variable_types: flags int


decompiled_code:
__int64 __fastcall items_SelectDelta(int a1, int a2)
{
__int64 result; // rax
int v3; // edx
int v4; // edi

result = (unsigned int)gridwide;
v3 = gridtall * gridwide;
if ( a1 )
{
v4 = selection + a1;
if ( v4 < 0 )
v4 = 0;
if ( v3 - 1 <= v4 )
v4 = v3 - 1;
selection = v4;
}
if ( a2 < 0 )
{
if ( gridwide <= selection )
selection -= gridwide;
}
else if ( a2 > 0 )
{
result = (unsigned int)(selection + gridwide);
if ( (int)result < v3 )
selection += gridwide;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
__int64 result; // rax
int v3; // edx
int v4; // edi

result = (unsigned int)gridwide;
v3 = gridtall * gridwide;
if ( a1 )
{
v4 = selection + a1;
if ( v4 < 0 )
v4 = 0;
if ( v3 - 1 <= v4 )
v4 = v3 - 1;
selection = v4;
}
if ( a2 < 0 )
{
if ( gridwide <= selection )
selection -= gridwide;
}
else if ( a2 > 0 )
{
result = (unsigned int)(selection + gridwide);
if ( (int)result < v3 )
selection += gridwide;
}
return result;
}

original_code:
void items_SelectDelta( int dx, int dy )
{
 int maxitems = (gridtall * gridwide);
 if( dx ) {
  selection += dx;
  if( selection < 0 ) selection = 0;
  if( selection >= maxitems-1 ) selection = maxitems -1;
 }
 if( dy < 0 ) {
  if( selection >= gridwide ) selection -= gridwide;
 }
 if( dy > 0 ) {
  if( (selection + gridwide) <= maxitems-1) selection += gridwide;
 }
}

canonical_original_code:
void items_SelectDelta(int dx, int dy)
{
 int maxitems = (gridtall * gridwide);
 if( dx ) {
  selection += dx;
  if( selection < 0 ) selection = 0;
  if( selection >= maxitems-1 ) selection = maxitems -1;
 }
 if( dy < 0 ) {
  if( selection >= gridwide ) selection -= gridwide;
 }
 if( dy > 0 ) {
  if( (selection + gridwide) <= maxitems-1) selection += gridwide;
 }
}

variable_types: dx int

variable_types: dy int

variable_types: maxitems int


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

result = 0LL;
if ( a1 >= 0x2710 )
a1 = 0;
selection = a1;
return result;
}

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

result = 0LL;
if ( a1 >= 0x2710 )
a1 = 0;
selection = a1;
return result;
}

original_code:
void items_Select( int idx )
{
 if( idx < 0 ) idx = 0;
 if( idx > 9999 ) idx = 0;
 selection = idx;
}

canonical_original_code:
void items_Select(int idx)
{
 if( idx < 0 ) idx = 0;
 if( idx > 9999 ) idx = 0;
 selection = idx;
}


decompiled_code:
__int64 items_SelectNextSection()
{
int v0; // edx
__int64 result; // rax
int v2; // ecx
char v3; // r8

v0 = *((_DWORD *)itemList + 8 * selection + 6);
result = (unsigned int)(selection + 1);
selection = result;
v2 = result;
v3 = 0;
if ( gridwide * gridtall >= (int)result )
{
while ( (v0 & 2) == 0 || (*((_BYTE *)itemList + 32 * (int)result + 24) & 2) != 0 )
{
v0 = *((_DWORD *)itemList + 8 * (int)result + 6);
result = (unsigned int)(v2 + 1);
v3 = 1;
if ( (int)result > gridwide * gridtall )
goto LABEL_2;
++v2;
}
if ( v3 )
selection = result;
}
else
{
LABEL_2:
selection = 0;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // edx
__int64 result; // rax
int v2; // ecx
char v3; // r8

v0 = *((_DWORD *)itemList + 8 * selection + 6);
result = (unsigned int)(selection + 1);
selection = result;
v2 = result;
v3 = 0;
if ( gridwide * gridtall >= (int)result )
{
while ( (v0 & 2) == 0 || (*((_BYTE *)itemList + 32 * (int)result + 24) & 2) != 0 )
{
v0 = *((_DWORD *)itemList + 8 * (int)result + 6);
result = (unsigned int)(v2 + 1);
v3 = 1;
if ( (int)result > gridwide * gridtall )
goto LABEL_2;
++v2;
}
if ( v3 )
selection = result;
}
else
{
LABEL_2:
selection = 0;
}
return result;
}

original_code:
void items_SelectNextSection( void )
{
 int maxitems = (gridtall * gridwide);
 int lastFlags = itemList[selection].flags;
 do {
  selection++;
  if( selection > maxitems ) {
   selection = 0;
   return;
  }
  if( (lastFlags & 0x02) == 0x02 ) {
   if( (itemList[selection].flags & 0x02) != 0x02 ) {
    return;
   }
  }
  lastFlags = itemList[selection].flags;
 } while( 1 );
}

canonical_original_code:
void items_SelectNextSection()
{
 int maxitems = (gridtall * gridwide);
 int lastFlags = itemList[selection].flags;
 do {
  selection++;
  if( selection > maxitems ) {
   selection = 0;
   return;
  }
  if( (lastFlags & 0x02) == 0x02 ) {
   if( (itemList[selection].flags & 0x02) != 0x02 ) {
    return;
   }
  }
  lastFlags = itemList[selection].flags;
 } while( 1 );
}

variable_types: lastFlags int


decompiled_code:
const char *__fastcall items_GetDisplay(int a1)
{
const char *result; // rax
const char *v2; // rdi

result = "--";
if ( a1 >= 0 && maxItems > a1 )
{
v2 = (char *)itemList + 32 * a1;
result = "--.--";
if ( *((_DWORD *)v2 + 6) )
result = v2;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func6(int a1)
{
const char *result; // rax
const char *v2; // rdi

result = "--";
if ( a1 >= 0 && maxItems > a1 )
{
v2 = (char *)itemList + 32 * a1;
result = "--.--";
if ( *((_DWORD *)v2 + 6) )
result = v2;
}
return result;
}

original_code:
char * items_GetDisplay( int idx )
{
 if( idx < 0 || idx >= maxItems ) {
  return "--";
 }
 if( itemList[idx].flags != 0x00 ) {
  return itemList[ idx ].display;
 }
 return "--.--";
}

canonical_original_code:
char *items_GetDisplay(int idx)
{
 if( idx < 0 || idx >= maxItems ) {
  return "--";
 }
 if( itemList[idx].flags != 0x00 ) {
  return itemList[ idx ].display;
 }
 return "--.--";
}


initScreen

decompiled_code:
int initScreen()
{
initscr();
cbreak();
noecho();
wtimeout(stdscr, 0);
curs_set(0);
nonl();
intrflush(stdscr, 0);
keypad(stdscr, 1);
mousemask(0xFFFFFFFuLL, 0LL);
start_color();
init_pair(1, 0, 2);
init_pair(2, 7, 4);
init_pair(3, 0, 6);
init_pair(4, 7, 0);
init_pair(6, 0, 3);
init_pair(7, 3, 1);
init_pair(8, 0, 6);
return init_pair(5, 3, 0);
}

canonical_decompiled_code:
int func0()
{
initscr();
cbreak();
noecho();
wtimeout(stdscr, 0);
curs_set(0);
nonl();
intrflush(stdscr, 0);
keypad(stdscr, 1);
mousemask(0xFFFFFFFuLL, 0LL);
start_color();
init_pair(1, 0, 2);
init_pair(2, 7, 4);
init_pair(3, 0, 6);
init_pair(4, 7, 0);
init_pair(6, 0, 3);
init_pair(7, 3, 1);
init_pair(8, 0, 6);
return init_pair(5, 3, 0);
}

original_code:
void initScreen( void )
{
 initscr();
 cbreak();
 noecho();
 wtimeout(stdscr,(0));
 curs_set( 0 );
 nonl();
 intrflush( stdscr, 0 );
 keypad( stdscr, 1 );
 mousemask( (((0010L) << (((6) - 1) * 5)) - 1), ((void *)0) );
 start_color();
 init_pair( (1), 0, 2 );
 init_pair( (2), 7, 4 );
 init_pair( (3), 0, 6 );
 init_pair( (4), 7, 0 );
 init_pair( (6), 0, 3 );
 init_pair( (7), 3, 1 );
 init_pair( (8), 0, 6 );
 init_pair( (5), 3, 0 );
}

canonical_original_code:
void initScreen()
{
 initscr();
 cbreak();
 noecho();
 wtimeout(stdscr,(0));
 curs_set( 0 );
 nonl();
 intrflush( stdscr, 0 );
 keypad( stdscr, 1 );
 mousemask( (((0010L) << (((6) - 1) * 5)) - 1), ((void *)0) );
 start_color();
 init_pair( (1), 0, 2 );
 init_pair( (2), 7, 4 );
 init_pair( (3), 0, 6 );
 init_pair( (4), 7, 0 );
 init_pair( (6), 0, 3 );
 init_pair( (7), 3, 1 );
 init_pair( (8), 0, 6 );
 init_pair( (5), 3, 0 );
}


deinitScreen

decompiled_code:
int deinitScreen()
{
curs_set(1);
return endwin();
}

canonical_decompiled_code:
int func1()
{
curs_set(1);
return endwin();
}

original_code:
void deinitScreen( void )
{
 curs_set( 1 );
 endwin();
}

canonical_original_code:
void deinitScreen()
{
 curs_set( 1 );
 endwin();
}


showTopBar

decompiled_code:
int showTopBar()
{
const char *v0; // rax
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-110h] BYREF
char s[264]; // [rsp+10h] [rbp-108h] BYREF

wattr_on(win, 0x100uLL, 0LL);
string_Prep(lineString, (unsigned int)winw);
v0 = (const char *)utils_whoami();
snprintf(s, 0x100uLL, "%s - Model T Shell v%s", v0, "0.05");
string_Right(lineString, s);
time(&timer);
v1 = localtime(&timer);
strftime(s, 0x100uLL, "%b %d,%Y %a %I:%M:%S %p", v1);
string_Left(lineString, s);
wmove(win, 0, 0);
wprintw(win, lineString);
return wattr_off(win, 0x100uLL, 0LL);
}

canonical_decompiled_code:
int func2()
{
const char *v0; // rax
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-110h] BYREF
char s[264]; // [rsp+10h] [rbp-108h] BYREF

wattr_on(win, 0x100uLL, 0LL);
string_Prep(lineString, (unsigned int)winw);
v0 = (const char *)utils_whoami();
snprintf(s, 0x100uLL, "%s - Model T Shell v%s", v0, "0.05");
string_Right(lineString, s);
time(&timer);
v1 = localtime(&timer);
strftime(s, 0x100uLL, "%b %d,%Y %a %I:%M:%S %p", v1);
string_Left(lineString, s);
wmove(win, 0, 0);
wprintw(win, lineString);
return wattr_off(win, 0x100uLL, 0LL);
}

original_code:
void showTopBar( int mx, int my )
{
 char tbuf[ (256) ];
 time_t rawtime;
 struct tm *timeinfo;
 wattr_on(win, (attr_t)((((chtype)((((1)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 string_Prep( lineString, winw );
 snprintf( tbuf, (256), "%s - Model T Shell v%s", utils_whoami(), "0.05" );
 string_Right( lineString, tbuf );
 time( &rawtime );
 timeinfo = localtime( &rawtime );
 strftime( tbuf, (256), "%b %d,%Y %a %I:%M:%S %p", timeinfo );
 string_Left( lineString, tbuf );
 wmove( win, 0, 0 );
 wprintw( win, lineString );
 wattr_off(win, (attr_t)((((chtype)((((1)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
}

canonical_original_code:
void showTopBar(int mx, int my)
{
 char tbuf[-1];
 long rawtime;
 struct tm *timeinfo;
 wattr_on(win, (attr_t)((((chtype)((((1)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 string_Prep( lineString, winw );
 snprintf( tbuf, (256), "%s - Model T Shell v%s", utils_whoami(), "0.05" );
 string_Right( lineString, tbuf );
 time( &rawtime );
 timeinfo = localtime( &rawtime );
 strftime( tbuf, (256), "%b %d,%Y %a %I:%M:%S %p", timeinfo );
 string_Left( lineString, tbuf );
 wmove( win, 0, 0 );
 wprintw( win, lineString );
 wattr_off(win, (attr_t)((((chtype)((((1)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
}

variable_types:
tbuf
char [-1]

variable_types: rawtime 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; } *


showPathBar

decompiled_code:
int showPathBar()
{
wmove(win, 1, 0);
string_Prep(lineString, (unsigned int)winw);
string_Center(lineString, cwd);
wattr_on(win, 0x500uLL, 0LL);
wprintw(win, lineString);
return wattr_off(win, 0x500uLL, 0LL);
}

canonical_decompiled_code:
int func3()
{
wmove(win, 1, 0);
string_Prep(lineString, (unsigned int)winw);
string_Center(lineString, cwd);
wattr_on(win, 0x500uLL, 0LL);
wprintw(win, lineString);
return wattr_off(win, 0x500uLL, 0LL);
}

original_code:
void showPathBar( int mx, int my )
{
 wmove( win, 1, 0 );
 string_Prep( lineString, winw );
 string_Center( lineString, cwd );
 wattr_on(win, (attr_t)((((chtype)((((5)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 wprintw( win, lineString );
 wattr_off(win, (attr_t)((((chtype)((((5)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
}

canonical_original_code:
void showPathBar(int mx, int my)
{
 wmove( win, 1, 0 );
 string_Prep( lineString, winw );
 string_Center( lineString, cwd );
 wattr_on(win, (attr_t)((((chtype)((((5)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 wprintw( win, lineString );
 wattr_off(win, (attr_t)((((chtype)((((5)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
}


showErrorBar

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

wmove(win, a2 - 2, 0);
string_Prep(lineString, (unsigned int)winw);
v2 = 1024;
if ( errCode )
{
v2 = 1792;
if ( errCode > 0 )
v2 = 2048;
v3 = Error_Get();
string_Center(lineString, v3);
}
wattr_on(win, v2, 0LL);
wprintw(win, lineString);
return wattr_off(win, v2, 0LL);
}

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

wmove(win, a2 - 2, 0);
string_Prep(lineString, (unsigned int)winw);
v2 = 1024;
if ( errCode )
{
v2 = 1792;
if ( errCode > 0 )
v2 = 2048;
v3 = Error_Get();
string_Center(lineString, v3);
}
wattr_on(win, v2, 0LL);
wprintw(win, lineString);
return wattr_off(win, v2, 0LL);
}

variable_types: col int


showBottomBar

decompiled_code:
int showBottomBar()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

wattr_on(win, 0x200uLL, 0LL);
v1[0] = 0;
snprintf(v1, 0x100uLL, "Select: %s", userInput);
string_Prep(lineString, (unsigned int)winw);
string_Left(lineString, v1);
wmove(win, winh - 1, 0);
wprintw(win, lineString);
return wattr_off(win, 0x200uLL, 0LL);
}

canonical_decompiled_code:
int func5()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

wattr_on(win, 0x200uLL, 0LL);
v1[0] = 0;
snprintf(v1, 0x100uLL, "Select: %s", userInput);
string_Prep(lineString, (unsigned int)winw);
string_Left(lineString, v1);
wmove(win, winh - 1, 0);
wprintw(win, lineString);
return wattr_off(win, 0x200uLL, 0LL);
}

original_code:
void showBottomBar( int mx, int my )
{
 char tbuf[ (256) ];
 wattr_on(win, (attr_t)((((chtype)((((2)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 tbuf[0] = '\0';
 snprintf( tbuf, (256), "Select: %s", userInput );
 string_Prep( lineString, winw );
 string_Left( lineString, tbuf );
 wmove( win, winh-1, 0 );
 wprintw( win, lineString );
 wattr_off(win, (attr_t)((((chtype)((((2)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
}

canonical_original_code:
void showBottomBar(int mx, int my)
{
 char tbuf[-1];
 wattr_on(win, (attr_t)((((chtype)((((2)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 tbuf[0] = '\0';
 snprintf( tbuf, (256), "Select: %s", userInput );
 string_Prep( lineString, winw );
 string_Left( lineString, tbuf );
 wmove( win, winh-1, 0 );
 wprintw( win, lineString );
 wattr_off(win, (attr_t)((((chtype)((((2)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
}


clearInput

decompiled_code:
void clearInput()
{
userInput[0] = 95;
userInput[1] = 0;
}

canonical_decompiled_code:
void func6()
{
userInput[0] = 95;
userInput[1] = 0;
}

original_code:
void clearInput( void )
{
 userInput[0] = '_';
 userInput[1] = '\0';
}

canonical_original_code:
void clearInput()
{
 userInput[0] = '_';
 userInput[1] = '\0';
}


copyItemToUserInput

decompiled_code:
size_t copyItemToUserInput()
{
__int64 v0; // rax
const char *v1; // rsi
size_t result; // rax

v0 = itemList + 32LL * selection;
if ( (*(_BYTE *)(v0 + 24) & 1) != 0 )
{
v1 = *(const char **)(v0 + 16);
if ( !v1 )
v1 = &src;
strcpy(userInput, v1);
}
else
{
userInput[0] = 0;
}
result = strlen(userInput);
*(_WORD *)&userInput[result] = 95;
return result;
}

canonical_decompiled_code:
size_t func7()
{
__int64 v0; // rax
const char *v1; // rsi
size_t result; // rax

v0 = itemList + 32LL * selection;
if ( (*(_BYTE *)(v0 + 24) & 1) != 0 )
{
v1 = *(const char **)(v0 + 16);
if ( !v1 )
v1 = &src;
strcpy(userInput, v1);
}
else
{
userInput[0] = 0;
}
result = strlen(userInput);
*(_WORD *)&userInput[result] = 95;
return result;
}

original_code:
void copyItemToUserInput( void )
{
 if( itemList[ selection ].flags & 0x01 ) {
  strcpy( userInput, itemList[ selection ].full?itemList[ selection ].full:"" );
 } else {
  strcpy( userInput, "" );
 }
 strcat( userInput, "_" );
}

canonical_original_code:
void copyItemToUserInput()
{
 if( itemList[ selection ].flags & 0x01 ) {
  strcpy( userInput, itemList[ selection ].full?itemList[ selection ].full:"" );
 } else {
  strcpy( userInput, "" );
 }
 strcat( userInput, "_" );
}


pressAnyKey

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

fwrite("Press ENTER to continue...\n", 1uLL, 0x1BuLL, stdout);
fflush(stdout);
do
result = getchar();
while ( result != -1 && result != 10 );
return result;
}

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

fwrite("Press ENTER to continue...\n", 1uLL, 0x1BuLL, stdout);
fflush(stdout);
do
result = getchar();
while ( result != -1 && result != 10 );
return result;
}

original_code:
void pressAnyKey( void )
{
 int ch;
 fprintf( stdout, "Press ENTER to continue...\n" );
 fflush( stdout );
 while((ch = getchar()) != '\n' && ch != (-1));
}

canonical_original_code:
void pressAnyKey()
{
 int ch;
 fprintf( stdout, "Press ENTER to continue...\n" );
 fflush( stdout );
 while((ch = getchar()) != '\n' && ch != (-1));
}

variable_types: ch int


noticeText

decompiled_code:
int __fastcall noticeText(const char *a1)
{
deinitScreen();
printf("Notice: %s\n", a1);
pressAnyKey();
return initScreen();
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
func1();
printf("Notice: %s\n", a1);
func8();
return func0();
}

original_code:
void noticeText( char * txt )
{
 deinitScreen();
 printf( "Notice: %s\n", txt );
 pressAnyKey();
 initScreen();
}

canonical_original_code:
void noticeText(char *txt)
{
 deinitScreen();
 printf( "Notice: %s\n", txt );
 pressAnyKey();
 initScreen();
}

variable_types:
txt
char *


runCommand

decompiled_code:
int __fastcall runCommand(char *arg, __int64 a2)
{
__pid_t v2; // ebx
int result; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = fork();
result = deinitScreen();
if ( !v2 )
{
execl(arg, arg, a2, 0LL);
exit(-9999);
}
if ( v2 >= 0 )
{
wait((__WAIT_STATUS)&stat_loc);
fputc(10, stdout);
if ( LODWORD(stat_loc.__uptr) )
fprintf(stdout, "Process completed with reutncode %d\n", LODWORD(stat_loc.__uptr));
else
fwrite("Process completed.\n", 1uLL, 0x13uLL, stdout);
pressAnyKey();
result = initScreen();
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(char *arg, __int64 a2)
{
__pid_t v2; // ebx
int result; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = fork();
result = func1();
if ( !v2 )
{
execl(arg, arg, a2, 0LL);
exit(-9999);
}
if ( v2 >= 0 )
{
wait((__WAIT_STATUS)&stat_loc);
fputc(10, stdout);
if ( LODWORD(stat_loc.__uptr) )
fprintf(stdout, "Process completed with reutncode %d\n", LODWORD(stat_loc.__uptr));
else
fwrite("Process completed.\n", 1uLL, 0x13uLL, stdout);
func8();
result = func0();
}
return result;
}

original_code:
void runCommand( char * command, char * parameter )
{
 pid_t pID = fork();
 deinitScreen();
 if( pID == 0 ) {
  execl( command, command, parameter, ((void *)0) );
  exit( -9999 );
 } else if ( pID < 0 ) {
  return;
 } else {
  int s;
  pID = wait( &s );
  fprintf( stdout, "\n" );
  if( s != 0 ) {
   fprintf( stdout, "Process completed with reutncode %d\n", s );
  } else {
   fprintf( stdout, "Process completed.\n" );
  }
 }
 pressAnyKey();
 initScreen();
}

canonical_original_code:
void runCommand(char *command, char *parameter)
{
 int pID = fork();
 deinitScreen();
 if( pID == 0 ) {
  execl( command, command, parameter, ((void *)0) );
  exit( -9999 );
 } else if ( pID < 0 ) {
  return;
 } else {
  int s;
  pID = wait( &s );
  fprintf( stdout, "\n" );
  if( s != 0 ) {
   fprintf( stdout, "Process completed with reutncode %d\n", s );
  } else {
   fprintf( stdout, "Process completed.\n" );
  }
 }
 pressAnyKey();
 initScreen();
}

variable_types:
command
char *

variable_types:
parameter
char *

variable_types: pID int

variable_types: s int


launchItem

decompiled_code:
int launchItem()
{
const char *v0; // r12
const char *v1; // rbx
__int64 v2; // rax
char *v3; // rbp
const char *v4; // rax
int result; // eax
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

v0 = *(const char **)(itemList + 32LL * selection + 16);
v1 = (const char *)string_fileExtension(v0);
if ( !v1 )
v1 = ".txt";
v2 = conf_Get(v1);
if ( v2 )
{
v3 = (char *)v2;
v4 = (const char *)conf_Get("Places.Cwd");
snprintf(v6, 0x100uLL, "%s/%s", v4, v0);
result = runCommand(v3, (__int64)v6);
}
else
{
snprintf(v6, 0x100uLL, "No handler installed for this type of file: %s", v1);
result = noticeText(v6);
}
return result;
}

canonical_decompiled_code:
int func11()
{
const char *v0; // r12
const char *v1; // rbx
__int64 v2; // rax
char *v3; // rbp
const char *v4; // rax
int result; // eax
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

v0 = *(const char **)(itemList + 32LL * selection + 16);
v1 = (const char *)string_fileExtension(v0);
if ( !v1 )
v1 = ".txt";
v2 = conf_Get(v1);
if ( v2 )
{
v3 = (char *)v2;
v4 = (const char *)conf_Get("Places.Cwd");
snprintf(v6, 0x100uLL, "%s/%s", v4, v0);
result = func10(v3, (__int64)v6);
}
else
{
snprintf(v6, 0x100uLL, "No handler installed for this type of file: %s", v1);
result = func9(v6);
}
return result;
}

original_code:
void launchItem( void )
{
 char * full = itemList[ selection ].full;
 char * ext = string_fileExtension( full );
 char * cmd;
 char fullPath[ (256) ];
 if( !ext ) { ext = ".txt"; }
 cmd = conf_Get( ext );
 if( !cmd ) {
  snprintf( fullPath, (256),"No handler installed for this type of file: %s", ext );
  noticeText( fullPath );
  return;
 }
 snprintf( fullPath, (256), "%s/%s", conf_Get( "Places.Cwd" ), full );
 runCommand( cmd, fullPath );
}

canonical_original_code:
void launchItem()
{
 char *full = itemList[ selection ].full;
 char *ext = string_fileExtension( full );
 char *cmd;
 char fullPath[-1];
 if( !ext ) { ext = ".txt"; }
 cmd = conf_Get( ext );
 if( !cmd ) {
  snprintf( fullPath, (256),"No handler installed for this type of file: %s", ext );
  noticeText( fullPath );
  return;
 }
 snprintf( fullPath, (256), "%s/%s", conf_Get( "Places.Cwd" ), full );
 runCommand( cmd, fullPath );
}

variable_types:
ext
char *

variable_types:
cmd
char *

variable_types:
fullPath
char [-1]


executeSelection

decompiled_code:
void executeSelection()
{
__int64 v0; // rax
int v1; // esi
__int64 v2; // rax
__int64 v3; // rax
char *v4; // rax

userInput[strlen(userInput) - 1] = 0;
v0 = itemList + 32LL * selection;
v1 = *(_DWORD *)(v0 + 24);
if ( (v1 & 0x40) != 0 )
{
utils_changeDirectory(*(_QWORD *)(v0 + 16), v1 & 0x80);
conf_Set("Places.Cwd", cwd);
items_Populate();
}
if ( (unsigned int)string_sameCI("EXIT", userInput)
|| (v2 = items_GetDisplay(selection), (unsigned int)string_sameCI("EXIT", v2)) )
{
exitNow = 1;
}
else if ( (unsigned int)string_sameCI("TEXT", userInput)
|| (v3 = items_GetDisplay(selection), (unsigned int)string_sameCI("TEXT", v3)) )
{
v4 = (char *)conf_Get(".txt");
runCommand(v4, (__int64)"Untitled.txt");
}
else
{
if ( (*(_BYTE *)(itemList + 32LL * selection + 24) & 1) != 0 )
launchItem();
clearInput();
}
}

canonical_decompiled_code:
void func12()
{
__int64 v0; // rax
int v1; // esi
__int64 v2; // rax
__int64 v3; // rax
char *v4; // rax

userInput[strlen(userInput) - 1] = 0;
v0 = itemList + 32LL * selection;
v1 = *(_DWORD *)(v0 + 24);
if ( (v1 & 0x40) != 0 )
{
utils_changeDirectory(*(_QWORD *)(v0 + 16), v1 & 0x80);
conf_Set("Places.Cwd", cwd);
items_Populate();
}
if ( (unsigned int)string_sameCI("EXIT", userInput)
|| (v2 = items_GetDisplay(selection), (unsigned int)string_sameCI("EXIT", v2)) )
{
exitNow = 1;
}
else if ( (unsigned int)string_sameCI("TEXT", userInput)
|| (v3 = items_GetDisplay(selection), (unsigned int)string_sameCI("TEXT", v3)) )
{
v4 = (char *)conf_Get(".txt");
func10(v4, (__int64)"Untitled.txt");
}
else
{
if ( (*(_BYTE *)(itemList + 32LL * selection + 24) & 1) != 0 )
func11();
func6();
}
}

original_code:
void executeSelection( void )
{
 userInput[ strlen( userInput )-1 ] = '\0';
 if( itemList[ selection ].flags & 0x40 )
 {
  utils_changeDirectory( itemList[ selection ].full, itemList[ selection ].flags & 0x80 );
         conf_Set( "Places.Cwd", cwd );
  items_Populate();
 }
 if( string_sameCI( "EXIT", userInput )
            || string_sameCI( "EXIT", items_GetDisplay( selection ))) {
  exitNow = 1;
  return;
 }
 if( string_sameCI( "TEXT", userInput )
            || string_sameCI( "TEXT", items_GetDisplay( selection ))) {
  runCommand( conf_Get( ".txt" ), "Untitled.txt" );
  return;
 }
 if( itemList[ selection ].flags & 0x01 )
 {
  launchItem();
 }
 clearInput();
}

canonical_original_code:
void executeSelection()
{
 userInput[ strlen( userInput )-1 ] = '\0';
 if( itemList[ selection ].flags & 0x40 )
 {
  utils_changeDirectory( itemList[ selection ].full, itemList[ selection ].flags & 0x80 );
         conf_Set( "Places.Cwd", cwd );
  items_Populate();
 }
 if( string_sameCI( "EXIT", userInput )
            || string_sameCI( "EXIT", items_GetDisplay( selection ))) {
  exitNow = 1;
  return;
 }
 if( string_sameCI( "TEXT", userInput )
            || string_sameCI( "TEXT", items_GetDisplay( selection ))) {
  runCommand( conf_Get( ".txt" ), "Untitled.txt" );
  return;
 }
 if( itemList[ selection ].flags & 0x01 )
 {
  launchItem();
 }
 clearInput();
}


showMiddleBlob

decompiled_code:
__int64 showMiddleBlob()
{
__int64 result; // rax
int v1; // er14
unsigned int v2; // ebp
unsigned int v3; // ebx
const char *v4; // rax
int i; // er12
int v6; // er13

result = items_Init();
v1 = 3;
v2 = 0;
if ( gridtall > 0 )
{
while ( 1 )
{
v6 = 0;
for ( i = 0; gridwide > i; v6 += 14 )
{
v3 = 1024;
if ( selection == v2 )
v3 = 1536;
wattr_on(win, v3, 0LL);
wmove(win, v1, v6);
v4 = (const char *)items_GetDisplay(v2);
wprintw(win, " %-12s ", v4);
wattr_off(win, v3, 0LL);
++v2;
++i;
}
result = (unsigned int)(v1 + 1);
if ( gridtall <= v1 - 2 )
break;
++v1;
}
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
int v1; // er14
unsigned int v2; // ebp
unsigned int v3; // ebx
const char *v4; // rax
int i; // er12
int v6; // er13

result = items_Init();
v1 = 3;
v2 = 0;
if ( gridtall > 0 )
{
while ( 1 )
{
v6 = 0;
for ( i = 0; gridwide > i; v6 += 14 )
{
v3 = 1024;
if ( selection == v2 )
v3 = 1536;
wattr_on(win, v3, 0LL);
wmove(win, v1, v6);
v4 = (const char *)items_GetDisplay(v2);
wprintw(win, " %-12s ", v4);
wattr_off(win, v3, 0LL);
++v2;
++i;
}
result = (unsigned int)(v1 + 1);
if ( gridtall <= v1 - 2 )
break;
++v1;
}
}
return result;
}

original_code:
void showMiddleBlob( int mx, int my )
{
 int pad = 1;
 int col;
 int cidx;
 int x,y;
 items_Init( mx, my );
 cidx = 0;
 for( y=0 ; y<gridtall ; y++ )
 {
  for( x=0 ; x<gridwide ; x++ )
  {
   if( cidx == selection ) {
    col = (((chtype)((((6)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)));
   } else {
    col = (((chtype)((((4)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)));
   }
   wattr_on(win, (attr_t)(col), ((void *)0));
   wmove( win, y+2 + pad,
        x*14 );
   wprintw( win, " %-12s ", items_GetDisplay( cidx ));
   wattr_off(win, (attr_t)(col), ((void *)0));
   cidx++;
  }
 }
}

canonical_original_code:
void showMiddleBlob(int mx, int my)
{
 int pad = 1;
 int col;
 int cidx;
 int x; int y;
 items_Init( mx, my );
 cidx = 0;
 for( y=0 ; y<gridtall ; y++ )
 {
  for( x=0 ; x<gridwide ; x++ )
  {
   if( cidx == selection ) {
    col = (((chtype)((((6)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)));
   } else {
    col = (((chtype)((((4)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)));
   }
   wattr_on(win, (attr_t)(col), ((void *)0));
   wmove( win, y+2 + pad,
        x*14 );
   wprintw( win, " %-12s ", items_GetDisplay( cidx ));
   wattr_off(win, (attr_t)(col), ((void *)0));
   cidx++;
  }
 }
}

variable_types: mx int

variable_types: my int

variable_types: pad int

variable_types: cidx int

variable_types: x int

variable_types: y int


showHelp

decompiled_code:
void __fastcall showHelp(int a1, int a2)
{
int v2; // ebx
const char *v3; // [rsp+0h] [rbp-88h] BYREF
const char *v4; // [rsp+8h] [rbp-80h] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

if ( showHelpWindow )
{
if ( !helpwin )
{
helpwinw = a1;
helpwinh = a2;
helpwin = newwin(a2, a1, a2 - winh, 0);
}
wclear(helpwin);
wattr_on(helpwin, 0x300uLL, 0LL);
wborder(helpwin, 0x20uLL, 0x20uLL, 0x20uLL, 0x20uLL, 0x20uLL, 0x20uLL, 0x20uLL, 0x20uLL);
string_Prep(lineString, (unsigned int)(helpwinw - 2));
string_Center(lineString, "Help (Debug info for now)");
wmove(helpwin, 0, 1);
wprintw(helpwin, lineString);
wattr_off(helpwin, 0x300uLL, 0LL);
string_Center(lineString, cwd);
wmove(helpwin, 1, 1);
wattr_on(helpwin, 0x500uLL, 0LL);
wprintw(helpwin, lineString);
wattr_off(helpwin, 0x500uLL, 0LL);
if ( helpwinh > 4 )
{
v2 = 0;
do
{
if ( !(unsigned int)conf_GetKV((unsigned int)v2, &v3, &v4) )
{
snprintf(s, 0x64uLL, "%20s = %s", v3, v4);
wmove(helpwin, v2 + 3, 3);
wprintw(helpwin, "%s", s);
}
++v2;
}
while ( helpwinh - 4 > v2 );
}
wnoutrefresh(helpwin);
usleep(0xC350u);
}
}

canonical_decompiled_code:
void __fastcall func14(int a1, int a2)
{
int v2; // ebx
const char *v3; // [rsp+0h] [rbp-88h] BYREF
const char *v4; // [rsp+8h] [rbp-80h] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

if ( showHelpWindow )
{
if ( !helpwin )
{
helpwinw = a1;
helpwinh = a2;
helpwin = newwin(a2, a1, a2 - winh, 0);
}
wclear(helpwin);
wattr_on(helpwin, 0x300uLL, 0LL);
wborder(helpwin, 0x20uLL, 0x20uLL, 0x20uLL, 0x20uLL, 0x20uLL, 0x20uLL, 0x20uLL, 0x20uLL);
string_Prep(lineString, (unsigned int)(helpwinw - 2));
string_Center(lineString, "Help (Debug info for now)");
wmove(helpwin, 0, 1);
wprintw(helpwin, lineString);
wattr_off(helpwin, 0x300uLL, 0LL);
string_Center(lineString, cwd);
wmove(helpwin, 1, 1);
wattr_on(helpwin, 0x500uLL, 0LL);
wprintw(helpwin, lineString);
wattr_off(helpwin, 0x500uLL, 0LL);
if ( helpwinh > 4 )
{
v2 = 0;
do
{
if ( !(unsigned int)conf_GetKV((unsigned int)v2, &v3, &v4) )
{
snprintf(s, 0x64uLL, "%20s = %s", v3, v4);
wmove(helpwin, v2 + 3, 3);
wprintw(helpwin, "%s", s);
}
++v2;
}
while ( helpwinh - 4 > v2 );
}
wnoutrefresh(helpwin);
usleep(0xC350u);
}
}

original_code:
void showHelp( int mx, int my )
{
 int i=0;
 if( !showHelpWindow ) return;
 if( !helpwin ) {
  helpwinw = mx;
  helpwinh = my;
  helpwin = newwin( helpwinh, helpwinw, my-winh, 0 );
 }
 wclear( helpwin );
 wattr_on(helpwin, (attr_t)((((chtype)((((3)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 wborder( helpwin, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
 string_Prep( lineString, helpwinw-2 );
 string_Center( lineString, "Help (Debug info for now)" );
 wmove( helpwin, 0, 1 );
 wprintw( helpwin, lineString );
 wattr_off(helpwin, (attr_t)((((chtype)((((3)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 string_Center( lineString, cwd );
 wmove( helpwin, 1, 1 );
 wattr_on(helpwin, (attr_t)((((chtype)((((5)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 wprintw( helpwin, lineString );
 wattr_off(helpwin, (attr_t)((((chtype)((((5)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 for( i=0 ; i<helpwinh-4 ; i++ ) {
  char buf[100];
  char * k;
  char * v;
  if( !conf_GetKV( i, &k, &v )) {
   snprintf( buf, 100, "%20s = %s", k, v );
   wmove( helpwin, 3+i, 3 );
   wprintw( helpwin, "%s", buf );
  }
 }
 wnoutrefresh( helpwin );
 usleep( 1000 * 50 );
}

canonical_original_code:
void showHelp(int mx, int my)
{
 int i = 0;
 if( !showHelpWindow ) return;
 if( !helpwin ) {
  helpwinw = mx;
  helpwinh = my;
  helpwin = newwin( helpwinh, helpwinw, my-winh, 0 );
 }
 wclear( helpwin );
 wattr_on(helpwin, (attr_t)((((chtype)((((3)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 wborder( helpwin, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
 string_Prep( lineString, helpwinw-2 );
 string_Center( lineString, "Help (Debug info for now)" );
 wmove( helpwin, 0, 1 );
 wprintw( helpwin, lineString );
 wattr_off(helpwin, (attr_t)((((chtype)((((3)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 string_Center( lineString, cwd );
 wmove( helpwin, 1, 1 );
 wattr_on(helpwin, (attr_t)((((chtype)((((5)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 wprintw( helpwin, lineString );
 wattr_off(helpwin, (attr_t)((((chtype)((((5)))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
 for( i=0 ; i<helpwinh-4 ; i++ ) {
  char buf[100];
  char *k;
  char *v;
  if( !conf_GetKV( i, &k, &v )) {
   snprintf( buf, 100, "%20s = %s", k, v );
   wmove( helpwin, 3+i, 3 );
   wprintw( helpwin, "%s", buf );
  }
 }
 wnoutrefresh( helpwin );
 usleep( 1000 * 50 );
}

variable_types: i int

variable_types:
buf
char [100]

variable_types:
k
char *

variable_types:
v
char *


showDisplay

decompiled_code:
int __fastcall showDisplay(unsigned int a1, unsigned int a2)
{
if ( !win )
{
winw = a1;
winh = a2;
win = newwin(a2, a1, 0, 0);
}
if ( fullRedraw )
{
fullRedraw = 0;
wclear(win);
}
showTopBar();
showErrorBar(a1, a2);
showBottomBar();
showMiddleBlob(a1, a2);
showPathBar();
wnoutrefresh(win);
return usleep(0xC350u);
}

canonical_decompiled_code:
int __fastcall func15(unsigned int a1, unsigned int a2)
{
if ( !win )
{
winw = a1;
winh = a2;
win = newwin(a2, a1, 0, 0);
}
if ( fullRedraw )
{
fullRedraw = 0;
wclear(win);
}
func2();
func4(a1, a2);
func5();
func13(a1, a2);
func3();
wnoutrefresh(win);
return usleep(0xC350u);
}

original_code:
void showDisplay( int mx, int my )
{
 if( !win ) {
  winw = mx;
  winh = my;
  win = newwin( winh, winw, my-winh, 0 );
 }
 if( fullRedraw ) {
  fullRedraw = 0;
  wclear( win );
 }
 showTopBar( mx, my );
 showErrorBar( mx, my );
 showBottomBar( mx, my );
 showMiddleBlob( mx, my );
 showPathBar( mx, my );
 wnoutrefresh( win );
 usleep( 1000 * 50 );
}

canonical_original_code:
void showDisplay(int mx, int my)
{
 if( !win ) {
  winw = mx;
  winh = my;
  win = newwin( winh, winw, my-winh, 0 );
 }
 if( fullRedraw ) {
  fullRedraw = 0;
  wclear( win );
 }
 showTopBar( mx, my );
 showErrorBar( mx, my );
 showBottomBar( mx, my );
 showMiddleBlob( mx, my );
 showPathBar( mx, my );
 wnoutrefresh( win );
 usleep( 1000 * 50 );
}


isValidInput

decompiled_code:
__int64 __fastcall isValidInput(int a1)
{
return ((*_ctype_b_loc())[a1] >> 14) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
return ((*_ctype_b_loc())[a1] >> 14) & 1;
}

original_code:
int isValidInput( int ch )
{
 if( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISprint)) return 1;
 return 0;
}

canonical_original_code:
int isValidInput(int ch)
{
 if( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISprint)) return 1;
 return 0;
}

variable_types: ch int