decompiled_code:
char **__fastcall find_command(char *s1)
{
const char *v1; // rsi
__int64 v2; // rbx
unsigned int v3; // ebp

v1 = commands;
if ( !commands )
return (char **)commands;
v2 = (unsigned int)((_DWORD)&commands + 24);
v3 = 0;
while ( strcmp(s1, v1) )
{
++v3;
v2 += 24LL;
v1 = *(const char **)(v2 - 24);
if ( !v1 )
return (char **)v1;
}
return &(&commands)[3 * v3];
}

canonical_decompiled_code:
char **__fastcall func5(char *s1)
{
const char *v1; // rsi
__int64 v2; // rbx
unsigned int v3; // ebp

v1 = commands;
if ( !commands )
return (char **)commands;
v2 = (unsigned int)((_DWORD)&commands + 24);
v3 = 0;
while ( strcmp(s1, v1) )
{
++v3;
v2 += 24LL;
v1 = *(const char **)(v2 - 24);
if ( !v1 )
return (char **)v1;
}
return &(&commands)[3 * v3];
}

original_code:
COMMAND *find_command (char *name) {
  unsigned int i;
  for (i = 0; commands[i].name; i++)
    if (strcmp (name, commands[i].name) == 0)
      return (&commands[i]);
  return ((COMMAND *)((void *)0));
}

canonical_original_code:
struct COMMAND *find_command(char *name) {
  unsigned int i;
  for (i = 0; commands[i].name; i++)
    if (strcmp (name, commands[i].name) == 0)
      return (&commands[i]);
  return ((struct COMMAND *)((void *)0));
}

variable_types:
i
unsigned int

return_type: struct COMMAND { char *name; int (*func)(char **); char *doc; } *


repo: ismell/rxh

decompiled_code:
void initialize_readline()
{
rl_basic_word_break_characters = " \t\n\"\\'`@><=;|&{(";
rl_attempted_completion_function = command_completion;
}

canonical_decompiled_code:
void func6()
{
rl_basic_word_break_characters = " \t\n\"\\'`@><=;|&{(";
rl_attempted_completion_function = command_completion;
}

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
void *v4; // rbx
const char *v5; // rax
const char *v6; // rbp
_QWORD *v7; // rax
_QWORD *v8; // r14
__int64 v9; // r13
_QWORD *v10; // r12
char **v11; // rax
bool v12; // cf
bool v13; // zf
const char *v14; // rdi
__int64 v15; // rcx
const char *v16; // rsi
__int64 v17; // r13
__int64 v18; // r12
int v19; // eax
int v20; // eax
int v21; // [rsp+8h] [rbp-40h]
int v22; // [rsp+Ch] [rbp-3Ch]

initialize_readline();
jobs = rxJobs_Initialize(argc, argv);
v22 = setenv("PS1", "\x1B[01;31m$USER \x1B[01;34m$PWD $EMO\x1B[01;34m#\x1B[22;37m ", 1);
if ( !v22 )
{
while ( 1 )
{
v3 = getenv("PS1");
v4 = (void *)rxExpandVars(v3);
rxJobs_Wait(jobs, 0LL);
v5 = (const char *)rl_gets((__int64)v4);
v6 = v5;
if ( !v5 )
break;
if ( *v5 )
{
v7 = (_QWORD *)rxParse(v5);
v8 = v7;
lastrtn = -1;
if ( !v7 )
goto LABEL_8;
v9 = *v7;
if ( !*v7 )
goto LABEL_23;
v21 = v22;
v10 = v7;
do
{
v11 = find_command(**(char ***)(v9 + 8));
v12 = 0;
v13 = v11 == 0LL;
if ( v11 )
*(_QWORD *)(v9 + 32) = v11[1];
v14 = "&";
v15 = 2LL;
v16 = *(const char **)(*v10 + 40LL);
do
{
if ( !v15 )
break;
v12 = *v16 < (unsigned int)*v14;
v13 = *v16++ == *v14++;
--v15;
}
while ( v13 );
if ( (!v12 && !v13) == v12 )
{
free(*(void **)(*v10 + 40LL));
v17 = *v10;
*(_QWORD *)(v17 + 40) = strdup(&byte_905);
v21 = 1;
}
v9 = *++v10;
}
while ( *v10 );
if ( v21 )
{
v18 = xmalloc(24LL);
*(_DWORD *)(v18 + 8) = 1;
*(_QWORD *)(v18 + 16) = strdup(v6);
v19 = xfork(v6, v16);
*(_DWORD *)(v18 + 4) = v19;
if ( !v19 )
{
v20 = rxCmd_Execute(v8);
exit(v20);
}
rxJobs_Add(jobs, v18);
lastrtn = 0;
}
else
{
LABEL_23:
lastrtn = rxCmd_Execute(v8);
}
loopArray(v8, &rxCmd_Free);
if ( lastrtn )
LABEL_8:
setenv("EMO", "\x1B[22;31m:( ", 1);
else
setenv("EMO", "\x1B[22;32m:) ", 1);
}
if ( v4 )
free(v4);
}
exit(0);
}
perror("setenv");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
void *v4; // rbx
const char *v5; // rax
const char *v6; // rbp
_QWORD *v7; // rax
_QWORD *v8; // r14
__int64 v9; // r13
_QWORD *v10; // r12
char **v11; // rax
bool v12; // cf
bool v13; // zf
const char *v14; // rdi
__int64 v15; // rcx
const char *v16; // rsi
__int64 v17; // r13
__int64 v18; // r12
int v19; // eax
int v20; // eax
int v21; // [rsp+8h] [rbp-40h]
int v22; // [rsp+Ch] [rbp-3Ch]

func6();
jobs = rxJobs_Initialize(argc, argv);
v22 = setenv("PS1", "\x1B[01;31m$USER \x1B[01;34m$PWD $EMO\x1B[01;34m#\x1B[22;37m ", 1);
if ( !v22 )
{
while ( 1 )
{
v3 = getenv("PS1");
v4 = (void *)rxExpandVars(v3);
rxJobs_Wait(jobs, 0LL);
v5 = (const char *)func4((__int64)v4);
v6 = v5;
if ( !v5 )
break;
if ( *v5 )
{
v7 = (_QWORD *)rxParse(v5);
v8 = v7;
lastrtn = -1;
if ( !v7 )
goto LABEL_8;
v9 = *v7;
if ( !*v7 )
goto LABEL_23;
v21 = v22;
v10 = v7;
do
{
v11 = func5(**(char ***)(v9 + 8));
v12 = 0;
v13 = v11 == 0LL;
if ( v11 )
*(_QWORD *)(v9 + 32) = v11[1];
v14 = "&";
v15 = 2LL;
v16 = *(const char **)(*v10 + 40LL);
do
{
if ( !v15 )
break;
v12 = *v16 < (unsigned int)*v14;
v13 = *v16++ == *v14++;
--v15;
}
while ( v13 );
if ( (!v12 && !v13) == v12 )
{
free(*(void **)(*v10 + 40LL));
v17 = *v10;
*(_QWORD *)(v17 + 40) = strdup(&byte_905);
v21 = 1;
}
v9 = *++v10;
}
while ( *v10 );
if ( v21 )
{
v18 = xmalloc(24LL);
*(_DWORD *)(v18 + 8) = 1;
*(_QWORD *)(v18 + 16) = strdup(v6);
v19 = xfork(v6, v16);
*(_DWORD *)(v18 + 4) = v19;
if ( !v19 )
{
v20 = rxCmd_Execute(v8);
exit(v20);
}
rxJobs_Add(jobs, v18);
lastrtn = 0;
}
else
{
LABEL_23:
lastrtn = rxCmd_Execute(v8);
}
loopArray(v8, &rxCmd_Free);
if ( lastrtn )
LABEL_8:
setenv("EMO", "\x1B[22;31m:( ", 1);
else
setenv("EMO", "\x1B[22;32m:) ", 1);
}
if ( v4 )
free(v4);
}
exit(0);
}
perror("setenv");
exit(1);
}

original_code:
int main() {
 initialize_readline();
 char *line;
 rxCommand **cmds;
 COMMAND *icmd;
 int i, background;
 jobs = rxJobs_Initialize();
 rxJob *job;
 if (setenv("PS1", "\033[01;31m$USER \033[01;34m$PWD $EMO\033[01;34m#\033[22;37m ", 1)) {
  perror("setenv"); exit(1);
 }
 char *prompt = ((void *)0);
 for (;;) {
  if (prompt)
   free(prompt);
  prompt = rxExpandVars(getenv("PS1"));
  rxJobs_Wait(jobs, 0);
  line = rl_gets(prompt);
  if (!line)
   break;
  if (*line) {
   cmds = rxParse(line);
   lastrtn = -1;
   background = 0;
   if (cmds) {
    if (0) loopArray((void**)cmds, (void*)&rxCmd_Print);
    for (i = 0; cmds[i]; i++) {
     if(icmd = find_command(cmds[i]->args[0])) {
      cmds[i]->fn = icmd->func;
     }
     if (strcmp(cmds[i]->op,"&") == 0) {
      background = 1;
      free(cmds[i]->op);
      cmds[i]->op = strdup("");
     }
    }
    if (background) {
     job = xmalloc(sizeof(rxJob));
     job->status = 1;
     job->cmd = strdup(line);
     job->pid = xfork();
     if (job->pid == 0) {
      exit(rxCmd_Execute(cmds));
     } else {
      rxJobs_Add(jobs, job);
      lastrtn = 0;
     }
    } else {
     lastrtn = rxCmd_Execute(cmds);
    }
    loopArray((void**)cmds, (void*)&rxCmd_Free);
   }
   if (lastrtn)
    setenv("EMO", "\033[22;31m:( ", 1);
   else
    setenv("EMO", "\033[22;32m:) ", 1);
  }
 }
    exit(0);
}

canonical_original_code:
int main() {
 initialize_readline();
 char *line;
 struct rxCommand **cmds;
 struct COMMAND *icmd;
 int i; int background;
 jobs = rxJobs_Initialize();
 struct rxJob *job;
 if (setenv("PS1", "\033[01;31m$USER \033[01;34m$PWD $EMO\033[01;34m#\033[22;37m ", 1)) {
  perror("setenv"); exit(1);
 }
 char *prompt = ((void *)0);
 for (;;) {
  if (prompt)
   free(prompt);
  prompt = rxExpandVars(getenv("PS1"));
  rxJobs_Wait(jobs, 0);
  line = rl_gets(prompt);
  if (!line)
   break;
  if (*line) {
   cmds = rxParse(line);
   lastrtn = -1;
   background = 0;
   if (cmds) {
    if (0) loopArray((void **)cmds, (void *)&rxCmd_Print);
    for (i = 0; cmds[i]; i++) {
     if(icmd = find_command(cmds[i]->args[0])) {
      cmds[i]->fn = icmd->func;
     }
     if (strcmp(cmds[i]->op,"&") == 0) {
      background = 1;
      free(cmds[i]->op);
      cmds[i]->op = strdup("");
     }
    }
    if (background) {
     job = xmalloc(sizeof(rxJob));
     job->status = 1;
     job->cmd = strdup(line);
     job->pid = xfork();
     if (job->pid == 0) {
      exit(rxCmd_Execute(cmds));
     } else {
      rxJobs_Add(jobs, job);
      lastrtn = 0;
     }
    } else {
     lastrtn = rxCmd_Execute(cmds);
    }
    loopArray((void **)cmds, (void *)&rxCmd_Free);
   }
   if (lastrtn)
    setenv("EMO", "\033[22;31m:( ", 1);
   else
    setenv("EMO", "\033[22;32m:) ", 1);
  }
 }
    exit(0);
}

variable_types:
line
char *

variable_types: struct rxCommand { int id; int pid; char **args; int fd[2]; int status; int (*fn)(char **); char *op; } **

variable_types: struct COMMAND { char *name; int (*func)(char **); char *doc; } *

variable_types: i int

variable_types: background int

variable_types: struct rxJob { int id; int pid; int status; int rtn; char *cmd; } *

variable_types:
prompt
char *

return_type: int


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax
int *v2; // rax

result = malloc(a1);
if ( !result )
{
perror("malloc");
v2 = _errno_location();
exit(*v2);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax
int *v2; // rax

result = malloc(a1);
if ( !result )
{
perror("malloc");
v2 = _errno_location();
exit(*v2);
}
return result;
}

original_code:
void *xmalloc (size_t size) {
 void *value = malloc (size);
 if (value == 0) {
  perror("malloc"); exit((*__errno_location ()));
 }
 return value;
}

canonical_original_code:
void *xmalloc(unsigned long size) {
 void *value = malloc (size);
 if (value == 0) {
  perror("malloc"); exit((*__errno_location ()));
 }
 return value;
}

variable_types:
size
unsigned long

variable_types:
value
void *

return_type: void *


xcalloc

decompiled_code:
void *__fastcall xcalloc(size_t a1, size_t a2)
{
void *result; // rax
int *v3; // rax

result = calloc(a1, a2);
if ( !result )
{
perror("cmalloc");
v3 = _errno_location();
exit(*v3);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1, size_t a2)
{
void *result; // rax
int *v3; // rax

result = calloc(a1, a2);
if ( !result )
{
perror("cmalloc");
v3 = _errno_location();
exit(*v3);
}
return result;
}

original_code:
void *xcalloc (size_t nmemb, size_t size) {
 void *value = calloc (nmemb, size);
 if (value == 0) {
  perror("cmalloc"); exit((*__errno_location ()));
 }
 return value;
}

canonical_original_code:
void *xcalloc(unsigned long nmemb, unsigned long size) {
 void *value = calloc (nmemb, size);
 if (value == 0) {
  perror("cmalloc"); exit((*__errno_location ()));
 }
 return value;
}

variable_types:
nmemb
unsigned long


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, size_t a2)
{
void *result; // rax
int *v3; // rax

result = realloc(a1, a2);
if ( !result )
{
perror("realloc");
v3 = _errno_location();
exit(*v3);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *result; // rax
int *v3; // rax

result = realloc(a1, a2);
if ( !result )
{
perror("realloc");
v3 = _errno_location();
exit(*v3);
}
return result;
}

original_code:
void *xrealloc(void *ptr, size_t size) {
 void *value = realloc (ptr, size);
 if (value == 0) {
  perror("realloc"); exit((*__errno_location ()));
 }
 return value;
}

canonical_original_code:
void *xrealloc(void *ptr, unsigned long size) {
 void *value = realloc (ptr, size);
 if (value == 0) {
  perror("realloc"); exit((*__errno_location ()));
 }
 return value;
}

variable_types:
ptr
void *


xfork

decompiled_code:
__pid_t xfork()
{
__pid_t result; // eax
int *v1; // rax

result = fork();
if ( result == -1 )
{
perror("fork");
v1 = _errno_location();
exit(*v1);
}
return result;
}

canonical_decompiled_code:
__pid_t func3()
{
__pid_t result; // eax
int *v1; // rax

result = fork();
if ( result == -1 )
{
perror("fork");
v1 = _errno_location();
exit(*v1);
}
return result;
}

original_code:
pid_t xfork(void) {
 pid_t value;
 if ((value = fork()) == -1) {
  perror("fork"); exit((*__errno_location ()));
 }
 return value;
}

canonical_original_code:
int xfork() {
 int value;
 if ((value = fork()) == -1) {
  perror("fork"); exit((*__errno_location ()));
 }
 return value;
}

variable_types: value int


xclose

decompiled_code:
__int64 __fastcall xclose(int a1)
{
int *v2; // rax

if ( close(a1) == -1 )
{
perror("close");
v2 = _errno_location();
exit(*v2);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
int *v2; // rax

if ( close(a1) == -1 )
{
perror("close");
v2 = _errno_location();
exit(*v2);
}
return 0LL;
}

original_code:
int xclose(int fd) {
 if (close(fd) == -1) {
  perror("close"); exit((*__errno_location ()));
 }
 return 0;
}

variable_types: fd int


decompiled_code:
int __fastcall xdup2(int a1, int a2)
{
int result; // eax
int *v3; // rax

result = dup2(a1, a2);
if ( result == -1 )
{
perror("dup2");
v3 = _errno_location();
exit(*v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1, int a2)
{
int result; // eax
int *v3; // rax

result = dup2(a1, a2);
if ( result == -1 )
{
perror("dup2");
v3 = _errno_location();
exit(*v3);
}
return result;
}

original_code:
int xdup2(int oldfd, int newfd) {
 int rtn;
 if ((rtn = dup2(oldfd, newfd)) == -1) {
  perror("dup2"); exit((*__errno_location ()));
 }
 return rtn;
}

variable_types: oldfd int

variable_types: newfd int

variable_types: rtn int


loopArray

decompiled_code:
__int64 __fastcall loopArray(_QWORD *a1, void (*a2)(void))
{
int v2; // ebx
__int64 result; // rax

if ( a1 && *a1 )
{
v2 = 0;
do
{
a2();
result = (unsigned int)++v2;
}
while ( a1[v2] );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, void (*a2)(void))
{
int v2; // ebx
__int64 result; // rax

if ( a1 && *a1 )
{
v2 = 0;
do
{
a2();
result = (unsigned int)++v2;
}
while ( a1[v2] );
}
return result;
}

original_code:
void loopArray(void **arr, void (*fn)(void *)) {
 unsigned int i;
 if (arr != ((void *)0)) {
  for (i = 0; arr[i] != ((void *)0); i++) {
   fn(arr[i]);
  }
 }
}

variable_types:
arr
void **

variable_types:
fn
void (*)(void *)

variable_types:
i
unsigned int


xgetcwd

decompiled_code:
char *xgetcwd()
{
char *v0; // rbx

v0 = getcwd(0LL, 0LL);
if ( !v0 )
perror("getcwd");
return v0;
}

canonical_decompiled_code:
char *func7()
{
char *v0; // rbx

v0 = getcwd(0LL, 0LL);
if ( !v0 )
perror("getcwd");
return v0;
}

original_code:
char *xgetcwd() {
 char *buf = ((void *)0);
 size_t size;
 buf = getcwd(buf,0);
 if (!buf) {
  perror("getcwd");
 }
 return buf;
}

canonical_original_code:
char *xgetcwd() {
 char *buf = ((void *)0);
 unsigned long size;
 buf = getcwd(buf,0);
 if (!buf) {
  perror("getcwd");
 }
 return buf;
}

variable_types:
buf
char *

return_type: char *


printString

decompiled_code:
int __fastcall printString(const char *a1)
{
return puts(a1);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
return puts(a1);
}

original_code:
void printString(char * str) {
 printf("%s\n", str);
}

canonical_original_code:
void printString(char *str) {
 printf("%s\n", str);
}

variable_types:
str
char *


decompiled_code:
_BOOL8 __fastcall ls_file_select(const struct dirent *a1)
{
bool v1; // zf
_BOOL8 result; // rax

v1 = strcmp(a1->d_name, ".") == 0;
result = !v1;
if ( !v1 )
result = strcmp(a1->d_name, "..") != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const struct dirent *a1)
{
bool v1; // zf
_BOOL8 result; // rax

v1 = strcmp(a1->d_name, ".") == 0;
result = !v1;
if ( !v1 )
result = strcmp(a1->d_name, "..") != 0;
return result;
}

original_code:
int ls_file_select(const struct dirent *entry) {
 if ((strcmp(entry->d_name, ".")== 0) || (strcmp(entry->d_name, "..") == 0))
  return 0;
 return 1;
}

canonical_original_code:
int ls_file_select(struct dirent *entry) {
 if ((strcmp(entry->d_name, ".")== 0) || (strcmp(entry->d_name, "..") == 0))
  return 0;
 return 1;
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *


decompiled_code:
__int64 __fastcall rxf_cd(_QWORD *a1)
{
const char *v1; // rdi
char *v2; // rbx
__int64 result; // rax
char *v4; // rax

if ( a1 && *a1 )
{
v1 = (const char *)a1[1];
if ( v1 )
{
if ( chdir(v1) != -1 )
{
LABEL_5:
v2 = (char *)xgetcwd();
setenv("PWD", v2, 1);
free(v2);
return 0LL;
}
}
else
{
v4 = getenv("HOME");
if ( !v4 || chdir(v4) != -1 )
goto LABEL_5;
}
perror("chdir");
result = (unsigned int)*_errno_location();
}
else
{
fwrite("cd: Invalid args\n", 1uLL, 0x11uLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
const char *v1; // rdi
char *v2; // rbx
__int64 result; // rax
char *v4; // rax

if ( a1 && *a1 )
{
v1 = (const char *)a1[1];
if ( v1 )
{
if ( chdir(v1) != -1 )
{
LABEL_5:
v2 = (char *)xgetcwd();
setenv("PWD", v2, 1);
free(v2);
return 0LL;
}
}
else
{
v4 = getenv("HOME");
if ( !v4 || chdir(v4) != -1 )
goto LABEL_5;
}
perror("chdir");
result = (unsigned int)*_errno_location();
}
else
{
fwrite("cd: Invalid args\n", 1uLL, 0x11uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int rxf_cd (char ** args) {
 char *ncwd;
 if (!args || args[0] == ((void *)0)) {
  fprintf(stderr, "cd: Invalid args\n");
  return 1;
 } else if (args[1] == ((void *)0)) {
  ncwd = getenv("HOME");
  if (ncwd) {
   if (chdir (ncwd) == -1) {
        perror ("chdir");
        return (*__errno_location ());
      }
  }
 }
 else {
  if (chdir (args[1]) == -1) {
       perror ("chdir");
       return (*__errno_location ());
     }
 }
 ncwd = (char*)xgetcwd();
 setenv("PWD", ncwd, 1);
 free (ncwd);
 return 0;
}

canonical_original_code:
int rxf_cd(char **args) {
 char *ncwd;
 if (!args || args[0] == ((void *)0)) {
  fprintf(stderr, "cd: Invalid args\n");
  return 1;
 } else if (args[1] == ((void *)0)) {
  ncwd = getenv("HOME");
  if (ncwd) {
   if (chdir (ncwd) == -1) {
        perror ("chdir");
        return (*__errno_location ());
      }
  }
 }
 else {
  if (chdir (args[1]) == -1) {
       perror ("chdir");
       return (*__errno_location ());
     }
 }
 ncwd = (char *)xgetcwd();
 setenv("PWD", ncwd, 1);
 free (ncwd);
 return 0;
}

variable_types:
args
char **

variable_types:
ncwd
char *


decompiled_code:
__int64 __fastcall rxf_ls(char *a1)
{
char *v1; // rbx
const char **v2; // r12
const char *v3; // rdi
unsigned int v4; // er14
int v5; // er13
__int64 v6; // rbp
__int64 v7; // rbx
int v8; // ebp
__int64 v10; // [rsp+0h] [rbp-58h] BYREF
void *ptr; // [rsp+8h] [rbp-50h] BYREF
char v12; // [rsp+10h] [rbp-48h] BYREF

if ( !a1 )
return (unsigned int)-1;
v1 = a1;
if ( !*(_QWORD *)a1 )
return (unsigned int)-1;
if ( !*((_QWORD *)a1 + 1) )
v1 = &v12;
ptr = 0LL;
ioctl(1, 0x5413uLL, &v10);
v2 = (const char **)(v1 + 8);
v3 = (const char *)*((_QWORD *)v1 + 1);
if ( !v3 )
return 0;
v4 = 0;
v5 = 1;
do
{
v8 = scandir(
v3,
(struct dirent ***)&ptr,
(int (*)(const struct dirent *))ls_file_select,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
if ( v8 == -1 )
{
perror("scandir");
v4 = -1;
}
else
{
if ( v5 > 1 )
putchar(10);
printf("%s:\n", *v2);
if ( v8 > 0 )
{
v6 = 8LL * (unsigned int)v8;
v7 = 0LL;
do
{
puts((const char *)(*(_QWORD *)((char *)ptr + v7) + 19LL));
free(*(void **)((char *)ptr + v7));
v7 += 8LL;
}
while ( v7 != v6 );
}
free(ptr);
}
++v5;
v3 = *++v2;
}
while ( *v2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char *v1; // rbx
const char **v2; // r12
const char *v3; // rdi
unsigned int v4; // er14
int v5; // er13
__int64 v6; // rbp
__int64 v7; // rbx
int v8; // ebp
__int64 v10; // [rsp+0h] [rbp-58h] BYREF
void *ptr; // [rsp+8h] [rbp-50h] BYREF
char v12; // [rsp+10h] [rbp-48h] BYREF

if ( !a1 )
return (unsigned int)-1;
v1 = a1;
if ( !*(_QWORD *)a1 )
return (unsigned int)-1;
if ( !*((_QWORD *)a1 + 1) )
v1 = &v12;
ptr = 0LL;
ioctl(1, 0x5413uLL, &v10);
v2 = (const char **)(v1 + 8);
v3 = (const char *)*((_QWORD *)v1 + 1);
if ( !v3 )
return 0;
v4 = 0;
v5 = 1;
do
{
v8 = scandir(
v3,
(struct dirent ***)&ptr,
(int (*)(const struct dirent *))ls_file_select,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
if ( v8 == -1 )
{
perror("scandir");
v4 = -1;
}
else
{
if ( v5 > 1 )
putchar(10);
printf("%s:\n", *v2);
if ( v8 > 0 )
{
v6 = 8LL * (unsigned int)v8;
v7 = 0LL;
do
{
puts((const char *)(*(_QWORD *)((char *)ptr + v7) + 19LL));
free(*(void **)((char *)ptr + v7));
v7 += 8LL;
}
while ( v7 != v6 );
}
free(ptr);
}
++v5;
v3 = *++v2;
}
while ( *v2 );
return v4;
}

original_code:
int rxf_ls (char ** args) {
 if (!args || !args[0])
  return -1;
 if (!args[1])
  args = (char*[]){args[0],".",((void *)0)};
 register int i, j;
 int rtn = 0, count, width = 80, n = 0, len;
 struct dirent **files = ((void *)0);
 struct winsize win;
 if (ioctl(1, 0x5413, &win) == 0 && win.ws_col > 0)
   width = win.ws_col;
 for (i = 1; args[i] != ((void *)0); i++) {
  count = scandir(args[i], &files, ls_file_select, alphasort);
  if (count == -1) {
   perror("scandir");
   rtn = -1;
  } else {
   if (i > 1) printf("\n");
   printf("%s:\n",args[i]);
   for (j = 0; j < count; j++) {
    printf("%s\n", files[j]->d_name);
    free(files[j]);
   }
   free(files);
  }
 }
 return rtn;
}

canonical_original_code:
int rxf_ls(char **args) {
 if (!args || !args[0])
  return -1;
 if (!args[1])
  args = (char *[]){args[0],".",((void *)0)};
 register int i; register int j;
 int rtn = 0; int count; int width = 80; int n = 0; int len;
 struct dirent **files = ((void *)0);
 struct winsize win;
 if (ioctl(1, 0x5413, &win) == 0 && win.ws_col > 0)
   width = win.ws_col;
 for (i = 1; args[i] != ((void *)0); i++) {
  count = scandir(args[i], &files, ls_file_select, alphasort);
  if (count == -1) {
   perror("scandir");
   rtn = -1;
  } else {
   if (i > 1) printf("\n");
   printf("%s:\n",args[i]);
   for (j = 0; j < count; j++) {
    printf("%s\n", files[j]->d_name);
    free(files[j]);
   }
   free(files);
  }
 }
 return rtn;
}

variable_types: i int

variable_types: j int

variable_types: count int

variable_types: width int

variable_types: n int

variable_types: len int

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } **

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


decompiled_code:
__int64 rxf_enviorn()
{
char *v0; // rdi
__int64 v1; // rbx

v0 = *environ;
if ( !*environ )
return 0LL;
v1 = 1LL;
do
{
puts(v0);
v0 = environ[v1++];
}
while ( v0 );
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
char *v0; // rdi
__int64 v1; // rbx

v0 = *environ;
if ( !*environ )
return 0LL;
v1 = 1LL;
do
{
puts(v0);
v0 = environ[v1++];
}
while ( v0 );
return 0LL;
}

original_code:
int rxf_enviorn (char ** args) {
 register int i;
 for(i = 0; environ[i]; i++)
  printf("%s\n", environ[i]);
 return 0;
}

canonical_original_code:
int rxf_enviorn(char **args) {
 register int i;
 for(i = 0; environ[i]; i++)
  printf("%s\n", environ[i]);
 return 0;
}


decompiled_code:
__int64 __fastcall rxf_echo(_QWORD *a1)
{
const char *v1; // rdx
_QWORD *v2; // rbx
unsigned int v3; // ebp

if ( !a1 )
return 1;
if ( !*a1 )
return 1;
v1 = (const char *)a1[1];
if ( !v1 )
goto LABEL_11;
v2 = a1 + 2;
v3 = 1;
do
{
if ( !strcmp(v1, "-n") )
v3 = 0;
else
printf("%s ", v1);
v1 = (const char *)*v2++;
}
while ( v1 );
if ( v3 )
{
LABEL_11:
putchar(10);
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
const char *v1; // rdx
_QWORD *v2; // rbx
unsigned int v3; // ebp

if ( !a1 )
return 1;
if ( !*a1 )
return 1;
v1 = (const char *)a1[1];
if ( !v1 )
goto LABEL_11;
v2 = a1 + 2;
v3 = 1;
do
{
if ( !strcmp(v1, "-n") )
v3 = 0;
else
printf("%s ", v1);
v1 = (const char *)*v2++;
}
while ( v1 );
if ( v3 )
{
LABEL_11:
putchar(10);
v3 = 0;
}
return v3;
}

original_code:
int rxf_echo (char ** args) {
 int i, nl = 1;
 if (!args || !args[0])
  return 1;
 for (i = 1; args[i]; i++) {
  if (strcmp(args[i], "-n") == 0)
   nl = 0;
  else
   printf("%s ", args[i]);
 }
 if (nl)
  printf("\n");
 return 0;
}

canonical_original_code:
int rxf_echo(char **args) {
 int i; int nl = 1;
 if (!args || !args[0])
  return 1;
 for (i = 1; args[i]; i++) {
  if (strcmp(args[i], "-n") == 0)
   nl = 0;
  else
   printf("%s ", args[i]);
 }
 if (nl)
  printf("\n");
 return 0;
}

variable_types: nl int


decompiled_code:
__int64 __fastcall rxf_export(const char **a1)
{
const char *v1; // rbp
const char *v2; // rbx
char *v3; // rax
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v2 = a1[1];
if ( v2 && (v3 = index(a1[1], 61)) != 0LL )
{
*v3 = 0;
setenv(v2, v3 + 1, 1);
result = 0LL;
}
else
{
fprintf(stderr, "Usage: %s NAME=value\n", v1);
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char **a1)
{
const char *v1; // rbp
const char *v2; // rbx
char *v3; // rax
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v2 = a1[1];
if ( v2 && (v3 = index(a1[1], 61)) != 0LL )
{
*v3 = 0;
setenv(v2, v3 + 1, 1);
result = 0LL;
}
else
{
fprintf(stderr, "Usage: %s NAME=value\n", v1);
result = 4294967294LL;
}
return result;
}

original_code:
int rxf_export (char ** args) {
 if (!args || !args[0])
  return -1;
 if (!args[1]) {
  usage: fprintf(stderr, "Usage: %s NAME=value\n", args[0]);
  return -2;
 }
 char *eq, *str;
 str = args[1];
 if (eq = index(str, '=')) {
  *eq = '\0';
  setenv(str, eq+1, 1);
 } else {
  goto usage;
 }
 return 0;
}

canonical_original_code:
int rxf_export(char **args) {
 if (!args || !args[0])
  return -1;
 if (!args[1]) {
  usage: fprintf(stderr, "Usage: %s NAME=value\n", args[0]);
  return -2;
 }
 char *eq; char *str;
 str = args[1];
 if (eq = index(str, '=')) {
  *eq = '\0';
  setenv(str, eq+1, 1);
 } else {
  goto usage;
 }
 return 0;
}

variable_types:
eq
char *


decompiled_code:
__int64 rxf_jobs()
{
rxJobs_Print(jobs, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
rxJobs_Print(jobs, 0LL);
return 0LL;
}

original_code:
int rxf_jobs (char ** args) {
 rxJobs_Print(jobs, 0);
 return 0;
}

canonical_original_code:
int rxf_jobs(char **args) {
 rxJobs_Print(jobs, 0);
 return 0;
}


decompiled_code:
void __noreturn rxf_exit()
{
rxJobs_Wait(jobs, 1LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
rxJobs_Wait(jobs, 1LL);
exit(0);
}

original_code:
int rxf_exit (char ** args) {
 rxJobs_Wait(jobs, 1);
 exit(0);
}

canonical_original_code:
int rxf_exit(char **args) {
 rxJobs_Wait(jobs, 1);
 exit(0);
}


charrpos

decompiled_code:
const char *__fastcall charrpos(const char *a1, char *a2, int a3)
{
int v5; // edx
char v6; // di
const char *v7; // rsi
__int64 v8; // r8
const char *v9; // r9
char *v10; // rdx
char v11; // al

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v5 = strlen(a1) + ~a3;
if ( v5 < 0 )
return 0LL;
v6 = *a2;
v7 = &a1[v5];
v8 = (__int64)&v7[-v5 - 1];
while ( !v6 )
{
LABEL_9:
if ( *v7 != 32 )
return 0LL;
if ( --v7 == (const char *)v8 )
return 0LL;
}
v9 = v7;
v10 = a2 + 1;
v11 = v6;
while ( *v7 != v11 )
{
v11 = *v10++;
if ( !v11 )
goto LABEL_9;
}
return v9;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1, char *a2, int a3)
{
int v5; // edx
char v6; // di
const char *v7; // rsi
__int64 v8; // r8
const char *v9; // r9
char *v10; // rdx
char v11; // al

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v5 = strlen(a1) + ~a3;
if ( v5 < 0 )
return 0LL;
v6 = *a2;
v7 = &a1[v5];
v8 = (__int64)&v7[-v5 - 1];
while ( !v6 )
{
LABEL_9:
if ( *v7 != 32 )
return 0LL;
if ( --v7 == (const char *)v8 )
return 0LL;
}
v9 = v7;
v10 = a2 + 1;
v11 = v6;
while ( *v7 != v11 )
{
v11 = *v10++;
if ( !v11 )
goto LABEL_9;
}
return v9;
}

original_code:
char *charrpos(char const *haystack, char const *needles, int offset) {
 if (haystack == ((void *)0) || needles == ((void *)0))
  return ((void *)0);
 int i, j;
 for (i = strlen(haystack) - 1 - offset; i >= 0; i--) {
  for (j = 0; needles[j] != 0; j++) {
   if (haystack[i] == needles[j]) {
    return (char*)haystack+i;
   }
  }
  if (haystack[i] != ' ')
   break;
 }
 return ((void *)0);
}

canonical_original_code:
char *charrpos(char *haystack, char *needles, int offset) {
 if (haystack == ((void *)0) || needles == ((void *)0))
  return ((void *)0);
 int i; int j;
 for (i = strlen(haystack) - 1 - offset; i >= 0; i--) {
  for (j = 0; needles[j] != 0; j++) {
   if (haystack[i] == needles[j]) {
    return (char *)haystack+i;
   }
  }
  if (haystack[i] != ' ')
   break;
 }
 return ((void *)0);
}

variable_types:
haystack
char *

variable_types:
needles
char *

variable_types: offset int


quickSorti

original_code:
_Bool quickSorti(int *arr, int elements) {
 int piv, beg[1000], end[1000], i=0, L, R ;
 beg[0]=0; end[0]=elements;
 while (i>=0) {
  L=beg[i]; R=end[i]-1;
  if (L<R) {
   piv=arr[L];
   if (i==1000 -1)
    return 0;
   while (L<R) {
    while (arr[R]>=piv && L<R) R--;
    if (L<R) arr[L++]=arr[R];
    while (arr[L]<=piv && L<R) L++;
    if (L<R) arr[R--]=arr[L];
   }
   arr[L]=piv;
   beg[i+1]=L+1;
   end[i+1]=end[i];
   end[i++]=L;
  }
  else {
   i--;
  }
 }
 return 1;
}

canonical_original_code:
_Bool quickSorti(int *arr, int elements) {
 int piv; int beg[1000]; int end[1000]; int i = 0; int L; int R;
 beg[0]=0; end[0]=elements;
 while (i>=0) {
  L=beg[i]; R=end[i]-1;
  if (L<R) {
   piv=arr[L];
   if (i==1000 -1)
    return 0;
   while (L<R) {
    while (arr[R]>=piv && L<R) R--;
    if (L<R) arr[L++]=arr[R];
    while (arr[L]<=piv && L<R) L++;
    if (L<R) arr[R--]=arr[L];
   }
   arr[L]=piv;
   beg[i+1]=L+1;
   end[i+1]=end[i];
   end[i++]=L;
  }
  else {
   i--;
  }
 }
 return 1;
}

variable_types:
arr
int *

variable_types: elements int

variable_types: piv int

variable_types:
beg
int [1000]

variable_types:
end
int [1000]

variable_types: L int

variable_types: R int


quickSortc

original_code:
_Bool quickSortc(char **arr, int elements) {
 int beg[1000], end[1000], i=0, L, R;
 char *piv;
 beg[0]=0; end[0]=elements;
 while (i>=0) {
  L=beg[i]; R=end[i]-1;
  if (L<R) {
   piv=arr[L];
   if (i==1000 -1)
    return 0;
   while (L<R) {
    while (strcmp(arr[R],piv) >= 0 && L<R) R--;
    if (L<R) arr[L++]=arr[R];
    while (strcmp(arr[L],piv) <= 0 && L<R) L++;
    if (L<R) arr[R--]=arr[L];
   }
   arr[L]=piv;
   beg[i+1]=L+1;
   end[i+1]=end[i];
   end[i++]=L;
  }
  else {
   i--;
  }
 }
 return 1;
}

canonical_original_code:
_Bool quickSortc(char **arr, int elements) {
 int beg[1000]; int end[1000]; int i = 0; int L; int R;
 char *piv;
 beg[0]=0; end[0]=elements;
 while (i>=0) {
  L=beg[i]; R=end[i]-1;
  if (L<R) {
   piv=arr[L];
   if (i==1000 -1)
    return 0;
   while (L<R) {
    while (strcmp(arr[R],piv) >= 0 && L<R) R--;
    if (L<R) arr[L++]=arr[R];
    while (strcmp(arr[L],piv) <= 0 && L<R) L++;
    if (L<R) arr[R--]=arr[L];
   }
   arr[L]=piv;
   beg[i+1]=L+1;
   end[i+1]=end[i];
   end[i++]=L;
  }
  else {
   i--;
  }
 }
 return 1;
}

variable_types:
arr
char **

variable_types: i int

variable_types:
piv
char *


main

repo: isomer/contain

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax

v3 = fork();
if ( v3 == -1 )
err(1, "Failed to fork()");
if ( !v3 )
{
execvp(argv[1], (char *const *)argv + 1);
err(1, "Failed to execve(%s)", argv[1]);
}
while ( wait(0LL) == -1 && *__errno_location() != 10 )
;
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    (void)argc;
    switch(fork()) {
        case 0:
            execvp(argv[1], &argv[1]);
            err(1, "Failed to execve(%s)", argv[1]);
        case -1:
            err(1, "Failed to fork()");
        default:
            break;
    }
    while (wait(((void *)0)) == -1 && (*__errno_location ()) != 10)
        ;
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: itgrufti/laughing-octo-robot

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
const char *v4; // rbp

v3 = (char *)argv[1];
if ( v3 == "--help" || v3 == "-h" )
{
puts(aHilfeAusgef);
puts("-h, --help\tHilfe zeigen.");
printf("-t, --test Testfunktion");
}
else if ( v3 == "--test" || v3 == "-t" )
{
puts("Test Erfolgreich");
}
else
{
v4 = *argv;
puts("Normaler Start");
printf("%d\n", (unsigned int)(char)v4);
printf("%d\n", (unsigned int)(char)v3);
}
return 0;
}

original_code:
int main ( int argc, char *argv[] )
 {
  if( argv[1] == "-h" || argv[1] == "--help" ){
   printf(" Hilfe ausgeführt!\n");
   printf("-h, --help	Hilfe zeigen.\n");
   printf("-t, --test  Testfunktion");
   return 0;
  }
  else if( argv[1] == "-t" || argv[1] == "--test" ){
   printf("Test Erfolgreich\n");
   return 0;
  }
  else{
   char eins, zwei;
   eins = argv[0];
   zwei = argv[1];
   printf("Normaler Start\n");
   printf("%d\n", eins);
   printf("%d\n", zwei);
   return 0;
  }
}

canonical_original_code:
int main(int argc, char *argv[])
 {
  if( argv[1] == "-h" || argv[1] == "--help" ){
   printf(" Hilfe ausgeführt!\n");
   printf("-h, --help	Hilfe zeigen.\n");
   printf("-t, --test  Testfunktion");
   return 0;
  }
  else if( argv[1] == "-t" || argv[1] == "--test" ){
   printf("Test Erfolgreich\n");
   return 0;
  }
  else{
   char eins; char zwei;
   eins = argv[0];
   zwei = argv[1];
   printf("Normaler Start\n");
   printf("%d\n", eins);
   printf("%d\n", zwei);
   return 0;
  }
}

variable_types: eins char

variable_types: zwei char


decompiled_code:
int init_keyboard()
{
return tcgetattr(0, &init_tio);
}

canonical_decompiled_code:
int func0()
{
return tcgetattr(0, &init_tio);
}

original_code: void init_keyboard() { tcgetattr(0,&init_tio); }


decompiled_code:
int close_keyboard()
{
return tcsetattr(0, 0, &init_tio);
}

canonical_decompiled_code:
int func1()
{
return tcsetattr(0, 0, &init_tio);
}

original_code: void close_keyboard() { tcsetattr(0,0,&init_tio); }


kbhit

decompiled_code:
__int64 kbhit()
{
fd_set v1; // [rsp+0h] [rbp-D8h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-58h] BYREF
struct termios termios_p; // [rsp+90h] [rbp-48h] BYREF

*(__m128i *)&termios_p.c_iflag = _mm_load_si128((const __m128i *)&init_tio);
*(__m128i *)&termios_p.c_line = _mm_load_si128((const __m128i *)&init_tio.c_line);
*(__m128i *)&termios_p.c_cc[15] = _mm_load_si128((const __m128i *)&init_tio.c_cc[15]);
*(_QWORD *)&termios_p.c_cc[31] = *(_QWORD *)&init_tio.c_cc[31];
termios_p.c_ospeed = init_tio.c_ospeed;
termios_p.c_lflag &= 0xFFFFFFFD;
tcsetattr(0, 0, &termios_p);
memset(&v1, 0, sizeof(v1));
v1.fds_bits[0] |= 1uLL;
timeout.tv_usec = 0LL;
timeout.tv_sec = 0LL;
select(1, &v1, 0LL, 0LL, &timeout);
tcsetattr(0, 0, &init_tio);
return v1.fds_bits[0] & 1;
}

canonical_decompiled_code:
__int64 func2()
{
fd_set v1; // [rsp+0h] [rbp-D8h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-58h] BYREF
struct termios termios_p; // [rsp+90h] [rbp-48h] BYREF

*(__m128i *)&termios_p.c_iflag = _mm_load_si128((const __m128i *)&init_tio);
*(__m128i *)&termios_p.c_line = _mm_load_si128((const __m128i *)&init_tio.c_line);
*(__m128i *)&termios_p.c_cc[15] = _mm_load_si128((const __m128i *)&init_tio.c_cc[15]);
*(_QWORD *)&termios_p.c_cc[31] = *(_QWORD *)&init_tio.c_cc[31];
termios_p.c_ospeed = init_tio.c_ospeed;
termios_p.c_lflag &= 0xFFFFFFFD;
tcsetattr(0, 0, &termios_p);
memset(&v1, 0, sizeof(v1));
v1.fds_bits[0] |= 1uLL;
timeout.tv_usec = 0LL;
timeout.tv_sec = 0LL;
select(1, &v1, 0LL, 0LL, &timeout);
tcsetattr(0, 0, &init_tio);
return v1.fds_bits[0] & 1;
}

original_code:
int kbhit()
{
    struct termios tio;
    struct timeval tv;
    fd_set rfds;
    memcpy(&tio,&init_tio,sizeof(struct termios));
    tio.c_lflag &= ~(0000002);
    tcsetattr(0,0,&tio);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&rfds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
    tv.tv_usec = 0;
    tv.tv_sec = 0;
    select(1,&rfds,((void *)0),((void *)0),&tv);
    tcsetattr(0,0,&init_tio);
    return (((((&rfds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0)?1:0);
}

canonical_original_code:
int kbhit()
{
    struct termios tio;
    struct timeval tv;
    struct fd_set rfds;
    memcpy(&tio,&init_tio,sizeof(struct termios));
    tio.c_lflag &= ~(0000002);
    tcsetattr(0,0,&tio);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&rfds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
    tv.tv_usec = 0;
    tv.tv_sec = 0;
    select(1,&rfds,((void *)0),((void *)0),&tv);
    tcsetattr(0,0,&init_tio);
    return (((((&rfds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0)?1:0);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
rfds
struct fd_set { long __fds_bits[-1]; }


readkey

decompiled_code:
__int64 readkey()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF
unsigned int buf[3]; // [rsp+3Ch] [rbp-Ch] BYREF

*(__m128i *)&v1.c_iflag = _mm_load_si128((const __m128i *)&init_tio);
*(__m128i *)&v1.c_line = _mm_load_si128((const __m128i *)&init_tio.c_line);
*(__m128i *)&v1.c_cc[15] = _mm_load_si128((const __m128i *)&init_tio.c_cc[15]);
*(_QWORD *)&v1.c_cc[31] = *(_QWORD *)&init_tio.c_cc[31];
v1.c_ospeed = init_tio.c_ospeed;
v1.c_lflag &= 0xFFFFFFF5;
tcsetattr(0, 0, &v1);
read(0, buf, 1uLL);
tcsetattr(0, 0, &init_tio);
return buf[0];
}

canonical_decompiled_code:
__int64 func3()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF
unsigned int buf[3]; // [rsp+3Ch] [rbp-Ch] BYREF

*(__m128i *)&v1.c_iflag = _mm_load_si128((const __m128i *)&init_tio);
*(__m128i *)&v1.c_line = _mm_load_si128((const __m128i *)&init_tio.c_line);
*(__m128i *)&v1.c_cc[15] = _mm_load_si128((const __m128i *)&init_tio.c_cc[15]);
*(_QWORD *)&v1.c_cc[31] = *(_QWORD *)&init_tio.c_cc[31];
v1.c_ospeed = init_tio.c_ospeed;
v1.c_lflag &= 0xFFFFFFF5;
tcsetattr(0, 0, &v1);
read(0, buf, 1uLL);
tcsetattr(0, 0, &init_tio);
return buf[0];
}

original_code:
int readkey()
{
    int ch;
    struct termios tio;
    memcpy(&tio,&init_tio,sizeof(struct termios));
    tio.c_lflag &= ~(0000002 | 0000010);
    tcsetattr(0,0,&tio);
    read(0,&ch,1);
    tcsetattr(0,0,&init_tio);
    return ch;
}

variable_types: ch int

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


map

repo: ius/radeonvolt

decompiled_code:
__int64 __fastcall map(__int64 a1, __int64 a2)
{
int v2; // eax
void *v3; // rax
unsigned int v4; // edx

v2 = open("/dev/mem", 2);
*(_DWORD *)a1 = v2;
if ( v2 == -1 )
{
perror("Failed to open /dev/mem");
v4 = 1;
}
else
{
v3 = mmap(0LL, 0x20000uLL, 3, 1, v2, a2 & 0xFFFFFFFFFFFE0000LL);
*(_QWORD *)(a1 + 8) = v3;
v4 = 0;
if ( v3 == (void *)-1LL )
{
perror("Failed to map memory");
v4 = 1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
int v2; // eax
void *v3; // rax
unsigned int v4; // edx

v2 = open("/dev/mem", 2);
*(_DWORD *)a1 = v2;
if ( v2 == -1 )
{
perror("Failed to open /dev/mem");
v4 = 1;
}
else
{
v3 = mmap(0LL, 0x20000uLL, 3, 1, v2, a2 & 0xFFFFFFFFFFFE0000LL);
*(_QWORD *)(a1 + 8) = v3;
v4 = 0;
if ( v3 == (void *)-1LL )
{
perror("Failed to map memory");
v4 = 1;
}
}
return v4;
}

original_code:
int map(struct mem_ctx *mem, pciaddr_t base)
{
 mem->fd = open("/dev/mem", 02);
 if(mem->fd == -1) {
  perror("Failed to open /dev/mem");
  return 1;
 }
 mem->base = mmap(0, 131072, 0x1 | 0x2,
   0x01, mem->fd, base & ~(131072 -1));
 if(mem->base == ((void *) -1)) {
  perror("Failed to map memory");
  return 1;
 }
 return 0;
}

canonical_original_code:
int map(struct mem_ctx *mem, unsigned long base)
{
 mem->fd = open("/dev/mem", 02);
 if(mem->fd == -1) {
  perror("Failed to open /dev/mem");
  return 1;
 }
 mem->base = mmap(0, 131072, 0x1 | 0x2,
   0x01, mem->fd, base & ~(131072 -1));
 if(mem->base == ((void *) -1)) {
  perror("Failed to map memory");
  return 1;
 }
 return 0;
}

variable_types: struct mem_ctx { int fd; void *base; } *

variable_types:
base
unsigned long


unmap

decompiled_code:
int __fastcall unmap(__int64 a1)
{
int result; // eax

munmap(*(void **)(a1 + 8), 0x20000uLL);
*(_QWORD *)(a1 + 8) = 0LL;
result = close(*(_DWORD *)a1);
*(_DWORD *)a1 = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
int result; // eax

munmap(*(void **)(a1 + 8), 0x20000uLL);
*(_QWORD *)(a1 + 8) = 0LL;
result = close(*(_DWORD *)a1);
*(_DWORD *)a1 = 0;
return result;
}

original_code:
void unmap(struct mem_ctx *mem)
{
 munmap(mem->base, 131072);
 mem->base = 0;
 close(mem->fd);
 mem->fd = 0;
}


decompiled_code:
__int64 __fastcall radeon_init(__int64 *a1, __int64 a2, __int64 a3)
{
unsigned int v4; // ebx

v4 = 1;
if ( !(unsigned int)map(a2, *a1) )
{
v4 = 0;
*(_QWORD *)a3 = *(_QWORD *)(a2 + 8);
*(_BYTE *)(a3 + 8) = 112;
i2c_setup();
i2c_select_bus(*(_QWORD *)a3, 0LL);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, __int64 a2, __int64 a3)
{
unsigned int v4; // ebx

v4 = 1;
if ( !(unsigned int)func0(a2, *a1) )
{
v4 = 0;
*(_QWORD *)a3 = *(_QWORD *)(a2 + 8);
*(_BYTE *)(a3 + 8) = 112;
i2c_setup();
i2c_select_bus(*(_QWORD *)a3, 0LL);
}
return v4;
}

original_code:
int radeon_init(struct card *card, struct mem_ctx *mem, struct rv8xx_i2c *i2c)
{
 if(map(mem, card->base)) {
  return 1;
 }
 i2c->base = mem->base;
 i2c->address = 0x70;
 i2c_setup(i2c->base);
 i2c_select_bus(i2c->base, 0);
 return 0;
}

variable_types: struct card { unsigned long base; int bus; char name[256]; } *

variable_types: struct rv8xx_i2c { void *base; unsigned char address; } *


decompiled_code:
int __fastcall radeon_release(__int64 a1)
{
return unmap(a1);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
return func1(a1);
}

original_code:
void radeon_release(struct mem_ctx *mem)
{
 unmap(mem);
}


decompiled_code:
int __fastcall show_info(__int64 a1, __int64 a2)
{
unsigned __int8 v2; // al
float v4; // xmm0_4
unsigned __int8 v5; // r12
unsigned __int8 v6; // bp
unsigned __int8 v7; // al
float v8; // [rsp+Ch] [rbp-2Ch]
float v9; // [rsp+10h] [rbp-28h]
float v10; // [rsp+14h] [rbp-24h]
float v11; // [rsp+18h] [rbp-20h]
float v12; // [rsp+1Ch] [rbp-1Ch]

printf("Device [%d]: %s\n", *(unsigned int *)(a1 + 8), (const char *)(a1 + 12));
v2 = vt1165_device_id(a2);
if ( v2 != 10 )
return fprintf(stderr, "Unsupported i2c device (%02x)\n", v2);
if ( (unsigned __int8)vt1165_vid_mode(a2) != 3 )
return fwrite("Unsupported VID mode\n", 1uLL, 0x15uLL, stderr);
v8 = vt1165_get_voltage(a2, 2LL);
v12 = vt1165_avg_current(a2);
printf("\tCurrent core voltage: %.4f V\n", v8);
v9 = vt1165_get_voltage(a2, 3LL);
v10 = vt1165_get_voltage(a2, 2LL);
v11 = vt1165_get_voltage(a2, 1LL);
v4 = vt1165_get_voltage(a2, 0LL);
printf("\tPresets: %.4f / %.4f / %.4f / %.4f V\n", v4, v11, v10, v9);
printf("\tCore power draw: %.2f A (%.02f W)\n", v12, (float)(v8 * v12));
v5 = vt1165_temp(a2, 2LL);
v6 = vt1165_temp(a2, 1LL);
v7 = vt1165_temp(a2, 0LL);
return printf("\tVRM temperatures: %d / %d / %d C\n", v7, v6, v5);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2)
{
unsigned __int8 v2; // al
float v4; // xmm0_4
unsigned __int8 v5; // r12
unsigned __int8 v6; // bp
unsigned __int8 v7; // al
float v8; // [rsp+Ch] [rbp-2Ch]
float v9; // [rsp+10h] [rbp-28h]
float v10; // [rsp+14h] [rbp-24h]
float v11; // [rsp+18h] [rbp-20h]
float v12; // [rsp+1Ch] [rbp-1Ch]

printf("Device [%d]: %s\n", *(unsigned int *)(a1 + 8), (const char *)(a1 + 12));
v2 = vt1165_device_id(a2);
if ( v2 != 10 )
return fprintf(stderr, "Unsupported i2c device (%02x)\n", v2);
if ( (unsigned __int8)vt1165_vid_mode(a2) != 3 )
return fwrite("Unsupported VID mode\n", 1uLL, 0x15uLL, stderr);
v8 = vt1165_get_voltage(a2, 2LL);
v12 = vt1165_avg_current(a2);
printf("\tCurrent core voltage: %.4f V\n", v8);
v9 = vt1165_get_voltage(a2, 3LL);
v10 = vt1165_get_voltage(a2, 2LL);
v11 = vt1165_get_voltage(a2, 1LL);
v4 = vt1165_get_voltage(a2, 0LL);
printf("\tPresets: %.4f / %.4f / %.4f / %.4f V\n", v4, v11, v10, v9);
printf("\tCore power draw: %.2f A (%.02f W)\n", v12, (float)(v8 * v12));
v5 = vt1165_temp(a2, 2LL);
v6 = vt1165_temp(a2, 1LL);
v7 = vt1165_temp(a2, 0LL);
return printf("\tVRM temperatures: %d / %d / %d C\n", v7, v6, v5);
}

original_code:
void show_info(struct card *card, struct rv8xx_i2c *i2c)
{
 unsigned char data;
 printf("Device [%d]: %s\n", card->bus, card->name);
 data = vt1165_device_id(i2c);
 if(data != 0x0a) {
  fprintf(stderr, "Unsupported i2c device (%02x)\n", data);
  return;
 }
 if(vt1165_vid_mode(i2c) == 3) {
  float voltage = vt1165_get_voltage(i2c, 2);
  float current = vt1165_avg_current(i2c);
  printf("\tCurrent core voltage: %.4f V\n", voltage);
  printf("\tPresets: %.4f / %.4f / %.4f / %.4f V\n",
   vt1165_get_voltage(i2c, 0),
   vt1165_get_voltage(i2c, 1),
   vt1165_get_voltage(i2c, 2),
   vt1165_get_voltage(i2c, 3));
  printf("\tCore power draw: %.2f A (%.02f W)\n",
   current, (voltage * current));
  printf("\tVRM temperatures: %d / %d / %d C\n",
   vt1165_temp(i2c, 0),
   vt1165_temp(i2c, 1),
   vt1165_temp(i2c, 2));
 } else {
  fprintf(stderr, "Unsupported VID mode\n");
 }
}

variable_types:
data
unsigned char

variable_types: voltage float

variable_types: current float

user_defined_types: struct card { unsigned long base; int bus; char name[256]; }

user_defined_types: struct rv8xx_i2c { void *base; unsigned char address; }


decompiled_code:
int show_usage()
{
puts("Usage: radeonvolt [options]\n");
puts("Optional arguments:");
puts(" --device device to query/modify");
puts(" --vcore set core voltage (in V)");
return puts("\nExample: radeonvolt --device 0 --vcore 1.0875");
}

canonical_decompiled_code:
int func6()
{
puts("Usage: radeonvolt [options]\n");
puts("Optional arguments:");
puts(" --device device to query/modify");
puts(" --vcore set core voltage (in V)");
return puts("\nExample: radeonvolt --device 0 --vcore 1.0875");
}

original_code:
void show_usage()
{
 printf("Usage: radeonvolt [options]\n\n");
 printf("Optional arguments:\n");
 printf("  --device  device to query/modify\n");
 printf("  --vcore    set core voltage (in V)\n");
 printf("\nExample: radeonvolt --device 0 --vcore 1.0875\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
__int64 v4; // rbx
int v5; // ebp
unsigned int v6; // eax
unsigned int v7; // er13
__int64 v8; // r12
__int64 v9; // rbx
float v11; // xmm1_4
__int64 v12; // rsi
float v13; // [rsp+Ch] [rbp-5Ch]
char v14[16]; // [rsp+10h] [rbp-58h] BYREF
char v15[72]; // [rsp+20h] [rbp-48h] BYREF

if ( argc % 2 == 1 )
{
v3 = 1;
v4 = 1LL;
v5 = -1;
v13 = *(float *)&LC15;
if ( argc - 1 <= 1 )
{
LABEL_3:
cards = malloc(0x2200uLL);
v6 = enum_cards();
v7 = v6;
if ( !v6 )
{
LABEL_25:
free(cards);
return 0;
}
v8 = 272LL * v6;
v9 = 0LL;
while ( 1 )
{
if ( *(_DWORD *)((char *)cards + v9 + 8) == v5 || v5 == -1 )
{
if ( (unsigned int)radeon_init((__int64 *)((char *)cards + v9), (__int64)v15, (__int64)v14) )
{
free(cards);
return v3;
}
v12 = *(unsigned int *)((char *)cards + v9 + 8);
if ( (v7 == 1 || (_DWORD)v12 == v5) && v13 > 0.0 )
{
if ( v13 >= 2.0 )
{
fprintf(stderr, "Specified vddc (%.4f V) doesn't seem sane. Not setting..\n", v13);
}
else
{
printf(
"Setting vddc of device %d to %.4f V (%#02x)\n",
v12,
v13,
(unsigned __int8)(int)(float)((float)(v13 - 0.44999999) / 0.0125));
vt1165_set_voltage(v14, 2LL, (unsigned __int8)(int)(float)((float)(v13 - 0.44999999) / 0.0125));
}
}
putchar(10);
show_info((__int64)cards + v9, (__int64)v14);
putchar(10);
radeon_release((__int64)v15);
}
v9 += 272LL;
if ( v9 == v8 )
goto LABEL_25;
}
}
while ( 1 )
{
if ( !strcmp(argv[v4], "--device") )
{
v5 = atoi(argv[(int)v4 + 1]);
}
else
{
if ( strcmp(argv[v4], "--vcore") )
{
show_usage();
return v3;
}
v11 = atof(argv[(int)v4 + 1]);
v13 = v11;
}
v4 += 2LL;
if ( argc - 1 <= (int)v4 )
goto LABEL_3;
}
}
show_usage();
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
__int64 v4; // rbx
int v5; // ebp
unsigned int v6; // eax
unsigned int v7; // er13
__int64 v8; // r12
__int64 v9; // rbx
float v11; // xmm1_4
__int64 v12; // rsi
float v13; // [rsp+Ch] [rbp-5Ch]
char v14[16]; // [rsp+10h] [rbp-58h] BYREF
char v15[72]; // [rsp+20h] [rbp-48h] BYREF

if ( argc % 2 == 1 )
{
v3 = 1;
v4 = 1LL;
v5 = -1;
v13 = *(float *)&LC15;
if ( argc - 1 <= 1 )
{
LABEL_3:
cards = malloc(0x2200uLL);
v6 = func2();
v7 = v6;
if ( !v6 )
{
LABEL_25:
free(cards);
return 0;
}
v8 = 272LL * v6;
v9 = 0LL;
while ( 1 )
{
if ( *(_DWORD *)((char *)cards + v9 + 8) == v5 || v5 == -1 )
{
if ( (unsigned int)func3((__int64 *)((char *)cards + v9), (__int64)v15, (__int64)v14) )
{
free(cards);
return v3;
}
v12 = *(unsigned int *)((char *)cards + v9 + 8);
if ( (v7 == 1 || (_DWORD)v12 == v5) && v13 > 0.0 )
{
if ( v13 >= 2.0 )
{
fprintf(stderr, "Specified vddc (%.4f V) doesn't seem sane. Not setting..\n", v13);
}
else
{
printf(
"Setting vddc of device %d to %.4f V (%#02x)\n",
v12,
v13,
(unsigned __int8)(int)(float)((float)(v13 - 0.44999999) / 0.0125));
vt1165_set_voltage(v14, 2LL, (unsigned __int8)(int)(float)((float)(v13 - 0.44999999) / 0.0125));
}
}
putchar(10);
func5((__int64)cards + v9, (__int64)v14);
putchar(10);
func4((__int64)v15);
}
v9 += 272LL;
if ( v9 == v8 )
goto LABEL_25;
}
}
while ( 1 )
{
if ( !strcmp(argv[v4], "--device") )
{
v5 = atoi(argv[(int)v4 + 1]);
}
else
{
if ( strcmp(argv[v4], "--vcore") )
{
func6();
return v3;
}
v11 = atof(argv[(int)v4 + 1]);
v13 = v11;
}
v4 += 2LL;
if ( argc - 1 <= (int)v4 )
goto LABEL_3;
}
}
func6();
return 1;
}

original_code:
int main(int argc, char *argv[])
{
 unsigned int num_cards;
 struct mem_ctx mem;
 struct rv8xx_i2c i2c;
 float vddc = -1;
 int device = -1;
 int i;
 if(argc % 2 != 1) {
  show_usage();
  return 1;
 }
 for(i = 1; i < (argc-1); i++) {
  if(!strcmp(argv[i], "--device")) {
   device = atoi(argv[++i]);
  } else if(!strcmp(argv[i], "--vcore")) {
   vddc = atof(argv[++i]);
  } else {
   show_usage();
   return 1;
  }
 }
 cards = malloc(sizeof(struct card) * 32);
 num_cards = enum_cards();
 for(i = 0; i < num_cards; i++) {
  if(device == cards[i].bus || device == -1) {
   if(radeon_init(&cards[i], &mem, &i2c)) {
    free(cards);
    return 1;
   }
   if(device == cards[i].bus || num_cards == 1) {
    if(vddc > 0) {
     if(vddc < 2.00f) {
      u8 value = (u8)((vddc - 0.450f) / 0.0125f);
      printf("Setting vddc of device %d to %.4f V (%#02x)\n", cards[i].bus, vddc, value);
      vt1165_set_voltage(&i2c, 2, value);
     } else {
      fprintf(stderr, "Specified vddc (%.4f V) doesn't seem sane. Not setting..\n", vddc);
     }
    }
   }
   printf("\n");
   show_info(&cards[i], &i2c);
   printf("\n");
   radeon_release(&mem);
  }
 }
 free(cards);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned int num_cards;
 struct mem_ctx mem;
 struct rv8xx_i2c i2c;
 float vddc = -1;
 int device = -1;
 int i;
 if(argc % 2 != 1) {
  show_usage();
  return 1;
 }
 for(i = 1; i < (argc-1); i++) {
  if(!strcmp(argv[i], "--device")) {
   device = atoi(argv[++i]);
  } else if(!strcmp(argv[i], "--vcore")) {
   vddc = atof(argv[++i]);
  } else {
   show_usage();
   return 1;
  }
 }
 cards = malloc(sizeof(struct card) * 32);
 num_cards = enum_cards();
 for(i = 0; i < num_cards; i++) {
  if(device == cards[i].bus || device == -1) {
   if(radeon_init(&cards[i], &mem, &i2c)) {
    free(cards);
    return 1;
   }
   if(device == cards[i].bus || num_cards == 1) {
    if(vddc > 0) {
     if(vddc < 2.00f) {
      unsigned char value = (u8)((vddc - 0.450f) / 0.0125f);
      printf("Setting vddc of device %d to %.4f V (%#02x)\n", cards[i].bus, vddc, value);
      vt1165_set_voltage(&i2c, 2, value);
     } else {
      fprintf(stderr, "Specified vddc (%.4f V) doesn't seem sane. Not setting..\n", vddc);
     }
    }
   }
   printf("\n");
   show_info(&cards[i], &i2c);
   printf("\n");
   radeon_release(&mem);
  }
 }
 free(cards);
 return 0;
}

variable_types:
mem
struct mem_ctx { int fd; void *base; }

variable_types: struct rv8xx_i2c { void *base; unsigned char address; }

variable_types: vddc float

variable_types: device int

variable_types: i int

variable_types:
value
unsigned char


decompiled_code:
int __fastcall i2c_print_status(__int16 a1)
{
printf("i2c status: ");
switch ( a1 & 0xF )
{
case 0:
printf("idle");
break;
case 1:
printf("sending start");
break;
case 2:
printf("sending address");
break;
case 3:
printf("sending/receiving data");
break;
case 4:
printf("sending/receiving ack");
break;
case 5:
printf("sending stop");
break;
case 7:
printf("byte delay");
break;
case 8:
printf("waiting for GO");
break;
default:
printf("unknown");
break;
}
if ( (a1 & 0x10) != 0 )
printf(" (done)");
if ( (a1 & 0x20) != 0 )
printf(" (aborted)");
if ( (a1 & 0x40) != 0 )
printf(" (timeout)");
if ( (a1 & 0x80u) != 0 )
printf(" (stopped on nack)");
if ( (a1 & 0x100) != 0 )
printf(" (nack)");
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(__int16 a1)
{
printf("i2c status: ");
switch ( a1 & 0xF )
{
case 0:
printf("idle");
break;
case 1:
printf("sending start");
break;
case 2:
printf("sending address");
break;
case 3:
printf("sending/receiving data");
break;
case 4:
printf("sending/receiving ack");
break;
case 5:
printf("sending stop");
break;
case 7:
printf("byte delay");
break;
case 8:
printf("waiting for GO");
break;
default:
printf("unknown");
break;
}
if ( (a1 & 0x10) != 0 )
printf(" (done)");
if ( (a1 & 0x20) != 0 )
printf(" (aborted)");
if ( (a1 & 0x40) != 0 )
printf(" (timeout)");
if ( (a1 & 0x80u) != 0 )
printf(" (stopped on nack)");
if ( (a1 & 0x100) != 0 )
printf(" (nack)");
return putchar(10);
}

original_code:
void i2c_print_status(u32 status)
{
 printf("i2c status: ");
 switch(status & 0x0f) {
  case 0: printf("idle");
   break;
  case 1:
   printf("sending start");
   break;
  case 2:
   printf("sending address");
   break;
  case 3:
   printf("sending/receiving data");
   break;
  case 4:
   printf("sending/receiving ack");
   break;
  case 5:
   printf("sending stop");
   break;
  case 7:
   printf("byte delay");
   break;
  case 8:
   printf("waiting for GO");
   break;
  default:
   printf("unknown");
   break;
 }
 if(status & (1 << 4)) {
  printf(" (done)");
 }
 if(status & (1 << 5)) {
  printf(" (aborted)");
 }
 if(status & (1 << 6)) {
  printf(" (timeout)");
 }
 if(status & (1 << 7)) {
  printf(" (stopped on nack)");
 }
 if(status & (1 << 8)) {
  printf(" (nack)");
 }
 printf("\n");
}

canonical_original_code:
void i2c_print_status(unsigned int status)
{
 printf("i2c status: ");
 switch(status & 0x0f) {
  case 0: printf("idle");
   break;
  case 1:
   printf("sending start");
   break;
  case 2:
   printf("sending address");
   break;
  case 3:
   printf("sending/receiving data");
   break;
  case 4:
   printf("sending/receiving ack");
   break;
  case 5:
   printf("sending stop");
   break;
  case 7:
   printf("byte delay");
   break;
  case 8:
   printf("waiting for GO");
   break;
  default:
   printf("unknown");
   break;
 }
 if(status & (1 << 4)) {
  printf(" (done)");
 }
 if(status & (1 << 5)) {
  printf(" (aborted)");
 }
 if(status & (1 << 6)) {
  printf(" (timeout)");
 }
 if(status & (1 << 7)) {
  printf(" (stopped on nack)");
 }
 if(status & (1 << 8)) {
  printf(" (nack)");
 }
 printf("\n");
}

variable_types:
status
unsigned int


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

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

original_code:
u32 mmio_read(void *base, u32 offset)
{
 u32 value;
 value = *(u32*)(base+offset);
 return value;
}

canonical_original_code:
unsigned int mmio_read(void *base, unsigned int offset)
{
 unsigned int value;
 value = *(unsigned int *)(base+offset);
 return value;
}

variable_types:
base
void *

variable_types:
offset
unsigned int

variable_types:
value
unsigned int

return_type: unsigned int


decompiled_code:
int __fastcall mmio_write(__int64 a1, unsigned int a2, int a3)
{
*(_DWORD *)(a1 + a2) = a3;
return usleep(1u);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, unsigned int a2, int a3)
{
*(_DWORD *)(a1 + a2) = a3;
return usleep(1u);
}

original_code:
void mmio_write(void *base, u32 offset, u32 value)
{
 *(u32*)(base+offset) = value;
 usleep(1);
}

canonical_original_code:
void mmio_write(void *base, unsigned int offset, unsigned int value)
{
 *(unsigned int *)(base+offset) = value;
 usleep(1);
}


decompiled_code:
int __fastcall i2c_show_status(__int64 a1)
{
__int16 v1; // ax

v1 = mmio_read(a1, 0x60D8u);
return i2c_print_status(v1);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int16 v1; // ax

v1 = func1(a1, 0x60D8u);
return func0(v1);
}

original_code:
void i2c_show_status(void *base)
{
 i2c_print_status(mmio_read(base, 0x60d8));
}


decompiled_code:
int __fastcall i2c_do_tx(__int64 a1)
{
mmio_write(a1, 0x60D0u, 1);
return usleep(0x3E8u);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
func2(a1, 0x60D0u, 1);
return usleep(0x3E8u);
}

original_code:
void i2c_do_tx(void *base)
{
 mmio_write(base, 0x60d0, 1);
 usleep(1000);
}


decompiled_code:
int __fastcall i2c_setup(__int64 a1)
{
int v1; // eax

v1 = mmio_read(a1, 0x60D4u);
mmio_write(a1, 0x60D4u, v1 | 4);
mmio_write(a1, 0x60DCu, 35389442);
return mmio_write(a1, 0x60E0u, 671154183);
}

original_code:
void i2c_setup(void *base)
{
 u32 reg;
 reg = mmio_read(base, 0x60d4);
 mmio_write(base, 0x60d4, reg | (0x01 << 2));
 mmio_write(base, 0x60dc, ((0x021c << 16) | 0x02));
 reg = mmio_read(base, 0x60e0);
 mmio_write(base, 0x60e0, 0x28010007);
}

canonical_original_code:
void i2c_setup(void *base)
{
 unsigned int reg;
 reg = mmio_read(base, 0x60d4);
 mmio_write(base, 0x60d4, reg | (0x01 << 2));
 mmio_write(base, 0x60dc, ((0x021c << 16) | 0x02));
 reg = mmio_read(base, 0x60e0);
 mmio_write(base, 0x60e0, 0x28010007);
}

variable_types:
reg
unsigned int


decompiled_code:
int __fastcall i2c_select_bus(__int64 a1)
{
int v1; // eax

v1 = mmio_read(a1, 0x6430u);
mmio_write(a1, 0x6430u, v1 & 0xFF000000);
return mmio_write(a1, 0x60ECu, 10281);
}

original_code:
void i2c_select_bus(void *base, unsigned int bus)
{
 u32 reg;
 reg = mmio_read(base, 0x6430);
 mmio_write(base, 0x6430, reg & 0xff000000);
 mmio_write(base, 0x60ec, (0x28 << 8) | 0x29);
}

canonical_original_code:
void i2c_select_bus(void *base, unsigned int bus)
{
 unsigned int reg;
 reg = mmio_read(base, 0x6430);
 mmio_write(base, 0x6430, reg & 0xff000000);
 mmio_write(base, 0x60ec, (0x28 << 8) | 0x29);
}

variable_types:
bus
unsigned int


decompiled_code:
int __fastcall i2c_write(__int64 a1, unsigned __int8 a2, unsigned __int8 *a3, unsigned __int8 a4)
{
int v5; // er14
int v6; // edx
unsigned __int8 *v7; // rbx
int result; // eax

if ( a4 <= 0xCu )
{
v5 = a4;
v6 = a4 << 16;
BYTE1(v6) = 48;
mmio_write(a1, 0x60E4u, v6);
mmio_write(a1, 0x60E8u, (a2 << 9) | 0x80000000);
if ( v5 > 0 )
{
v7 = a3;
do
mmio_write(a1, 0x60E8u, *v7++ << 8);
while ( v7 != &a3[v5 - 1 + 1] );
}
result = i2c_do_tx(a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, unsigned __int8 a2, unsigned __int8 *a3, unsigned __int8 a4)
{
int v5; // er14
int v6; // edx
unsigned __int8 *v7; // rbx
int result; // eax

if ( a4 <= 0xCu )
{
v5 = a4;
v6 = a4 << 16;
BYTE1(v6) = 48;
func2(a1, 0x60E4u, v6);
func2(a1, 0x60E8u, (a2 << 9) | 0x80000000);
if ( v5 > 0 )
{
v7 = a3;
do
func2(a1, 0x60E8u, *v7++ << 8);
while ( v7 != &a3[v5 - 1 + 1] );
}
result = func4(a1);
}
return result;
}

original_code:
void i2c_write(void *base, u8 address, u8 *data, u8 length)
{
 int i;
 if(length > 12)
  return;
 mmio_write(base, 0x60e4, (length << 16) | (1 << 12) | (1 << 13));
 mmio_write(base, 0x60e8, (1 << 31) | ((address << 1) << 8));
 for(i = 0; i < length; i++) {
  mmio_write(base, 0x60e8, (data[i] << 8));
 }
 i2c_do_tx(base);
}

canonical_original_code:
void i2c_write(void *base, unsigned char address, unsigned char *data, unsigned char length)
{
 int i;
 if(length > 12)
  return;
 mmio_write(base, 0x60e4, (length << 16) | (1 << 12) | (1 << 13));
 mmio_write(base, 0x60e8, (1 << 31) | ((address << 1) << 8));
 for(i = 0; i < length; i++) {
  mmio_write(base, 0x60e8, (data[i] << 8));
 }
 i2c_do_tx(base);
}

variable_types:
address
unsigned char

variable_types:
data
unsigned char *

variable_types:
length
unsigned char


decompiled_code:
int __fastcall i2c_write_byte(__int64 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
unsigned __int8 v5[10]; // [rsp+Eh] [rbp-Ah] BYREF

v5[0] = a3;
v5[1] = a4;
return i2c_write(a1, a2, v5, 2u);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
unsigned __int8 v5[10]; // [rsp+Eh] [rbp-Ah] BYREF

v5[0] = a3;
v5[1] = a4;
return func7(a1, a2, v5, 2u);
}

original_code:
void i2c_write_byte(void *base, u8 address, u8 offset, u8 value)
{
 u8 buf[2];
 buf[0] = offset;
 buf[1] = value;
 i2c_write(base, address, buf, sizeof(buf));
}

canonical_original_code:
void i2c_write_byte(void *base, unsigned char address, unsigned char offset, unsigned char value)
{
 unsigned char buf[2];
 buf[0] = offset;
 buf[1] = value;
 i2c_write(base, address, buf, sizeof(buf));
}

variable_types:
offset
unsigned char

variable_types:
buf
unsigned char [2]


decompiled_code:
__int64 __fastcall i2c_read_byte(__int64 a1, unsigned __int8 a2, unsigned __int8 a3)
{
int v4; // ebp

mmio_write(a1, 0x60E4u, 69632);
v4 = a2 << 9;
mmio_write(a1, 0x60E8u, v4 | 0x80000000);
mmio_write(a1, 0x60E8u, a3 << 8);
i2c_do_tx(a1);
mmio_write(a1, 0x60E4u, 77825);
mmio_write(a1, 0x60E8u, v4 | 0x80000100);
i2c_do_tx(a1);
mmio_write(a1, 0x60E8u, -2147418111);
return (unsigned int)mmio_read(a1, 0x60E8u) >> 8;
}

canonical_original_code:
unsigned char i2c_read_byte(void *base, unsigned char address, unsigned char offset)
{
 unsigned int reg;
 mmio_write(base, 0x60e4, (1 << 16) | (1 << 12));
 mmio_write(base, 0x60e8, (1 << 31) | ((address << 1) << 8));
 mmio_write(base, 0x60e8, (offset << 8));
 i2c_do_tx(base);
 mmio_write(base, 0x60e4, (1 << 16) | (1 << 12) | (1 << 13) | 1);
 mmio_write(base, 0x60e8, (1 << 31) | (((address << 1) | 0x01 ) << 8));
 i2c_do_tx(base);
 mmio_write(base, 0x60e8, (1 << 31) | (0x01 << 16) | 1);
 reg = mmio_read(base, 0x60e8);
 return (reg >> 8);
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall vt1165_device_id(__int64 a1)
{
return i2c_read_byte(*(_QWORD *)a1, *(unsigned __int8 *)(a1 + 8), 26LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return i2c_read_byte(*(_QWORD *)a1, *(unsigned __int8 *)(a1 + 8), 26LL);
}

original_code:
u8 vt1165_device_id(struct rv8xx_i2c *i2c)
{
 return i2c_read_byte(i2c->base, i2c->address, 0x1a);
}

canonical_original_code:
unsigned char vt1165_device_id(struct rv8xx_i2c *i2c)
{
 return i2c_read_byte(i2c->base, i2c->address, 0x1a);
}

variable_types: struct rv8xx_i2c { void *base; unsigned char address; } *


decompiled_code:
__int64 __fastcall vt1165_radc(_QWORD *a1, int a2)
{
__int64 result; // rax
unsigned __int8 v3; // bp
unsigned __int8 v4; // bp
unsigned __int8 v5; // bp
unsigned __int8 v6; // bp

switch ( a2 )
{
case 0:
result = i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 2LL) & 0x1F;
break;
case 1:
v3 = i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 2LL);
result = ((v3 >> 5) | (unsigned __int8)(8 * i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 3LL))) & 0x1F;
break;
case 2:
result = ((unsigned int)i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 3LL) >> 2) & 0x1F;
break;
case 3:
v4 = i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 3LL);
result = ((v4 >> 7) | (unsigned __int8)(2 * i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 4LL))) & 0x1F;
break;
case 4:
v5 = i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 4LL);
result = ((v5 >> 4) | (unsigned __int8)(16 * i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 5LL))) & 0x1F;
break;
case 5:
result = ((unsigned int)i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 5LL) >> 1) & 0x1F;
break;
case 6:
v6 = i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 5LL);
result = ((v6 >> 6) | (unsigned __int8)(4 * i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 6LL))) & 0x1F;
break;
case 7:
result = (unsigned __int8)i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 6LL) >> 3;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, int a2)
{
__int64 result; // rax
unsigned __int8 v3; // bp
unsigned __int8 v4; // bp
unsigned __int8 v5; // bp
unsigned __int8 v6; // bp

switch ( a2 )
{
case 0:
result = i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 2LL) & 0x1F;
break;
case 1:
v3 = i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 2LL);
result = ((v3 >> 5) | (unsigned __int8)(8 * i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 3LL))) & 0x1F;
break;
case 2:
result = ((unsigned int)i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 3LL) >> 2) & 0x1F;
break;
case 3:
v4 = i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 3LL);
result = ((v4 >> 7) | (unsigned __int8)(2 * i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 4LL))) & 0x1F;
break;
case 4:
v5 = i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 4LL);
result = ((v5 >> 4) | (unsigned __int8)(16 * i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 5LL))) & 0x1F;
break;
case 5:
result = ((unsigned int)i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 5LL) >> 1) & 0x1F;
break;
case 6:
v6 = i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 5LL);
result = ((v6 >> 6) | (unsigned __int8)(4 * i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 6LL))) & 0x1F;
break;
case 7:
result = (unsigned __int8)i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 6LL) >> 3;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
u8 vt1165_radc(struct rv8xx_i2c *i2c, unsigned int index)
{
 unsigned int reg, value = 0;
 switch(index) {
  case 0:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x02);
   value = reg & 0x1f;
   break;
  case 1:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x02);
   value = (reg >> 5);
   reg = i2c_read_byte(i2c->base, i2c->address, 0x03);
   value = ((reg << 3) | value) & 0x1f;
   break;
  case 2:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x03);
   value = (reg >> 2) & 0x1f;
   break;
  case 3:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x03);
   value = (reg >> 7);
   reg = i2c_read_byte(i2c->base, i2c->address, 0x04);
   value = ((reg << 1) | value) & 0x1f;
   break;
  case 4:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x04);
   value = (reg >> 4);
   reg = i2c_read_byte(i2c->base, i2c->address, 0x05);
   value = ((reg << 4) | value) & 0x1f;
   break;
  case 5:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x05);
   value = (reg >> 1) & 0x1f;
   break;
  case 6:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x05);
   value = (reg >> 6);
   reg = i2c_read_byte(i2c->base, i2c->address, 0x06);
   value = ((reg << 2) | value) & 0x1f;
   break;
  case 7:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x06);
   value = (reg >> 3) & 0x1f;
   break;
 }
 return value;
}

canonical_original_code:
unsigned char vt1165_radc(struct rv8xx_i2c *i2c, unsigned int index)
{
 unsigned int reg; unsigned int value = 0;
 switch(index) {
  case 0:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x02);
   value = reg & 0x1f;
   break;
  case 1:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x02);
   value = (reg >> 5);
   reg = i2c_read_byte(i2c->base, i2c->address, 0x03);
   value = ((reg << 3) | value) & 0x1f;
   break;
  case 2:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x03);
   value = (reg >> 2) & 0x1f;
   break;
  case 3:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x03);
   value = (reg >> 7);
   reg = i2c_read_byte(i2c->base, i2c->address, 0x04);
   value = ((reg << 1) | value) & 0x1f;
   break;
  case 4:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x04);
   value = (reg >> 4);
   reg = i2c_read_byte(i2c->base, i2c->address, 0x05);
   value = ((reg << 4) | value) & 0x1f;
   break;
  case 5:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x05);
   value = (reg >> 1) & 0x1f;
   break;
  case 6:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x05);
   value = (reg >> 6);
   reg = i2c_read_byte(i2c->base, i2c->address, 0x06);
   value = ((reg << 2) | value) & 0x1f;
   break;
  case 7:
   reg = i2c_read_byte(i2c->base, i2c->address, 0x06);
   value = (reg >> 3) & 0x1f;
   break;
 }
 return value;
}

variable_types:
index
unsigned int


decompiled_code:
char __fastcall vt1165_vid_mode(_QWORD *a1)
{
return (unsigned __int8)vt1165_radc(a1, 3) >> 2;
}

canonical_decompiled_code:
char __fastcall func2(_QWORD *a1)
{
return (unsigned __int8)func1(a1, 3) >> 2;
}

original_code:
u8 vt1165_vid_mode(struct rv8xx_i2c *i2c)
{
 u8 data = vt1165_radc(i2c, 3);
 return (data >> 2);
}

canonical_original_code:
unsigned char vt1165_vid_mode(struct rv8xx_i2c *i2c)
{
 unsigned char data = vt1165_radc(i2c, 3);
 return (data >> 2);
}

variable_types:
data
unsigned char


decompiled_code:
__int64 __fastcall vt1165_active_slaves(__int64 a1)
{
return i2c_read_byte(*(_QWORD *)a1, *(unsigned __int8 *)(a1 + 8), 14LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return i2c_read_byte(*(_QWORD *)a1, *(unsigned __int8 *)(a1 + 8), 14LL);
}

original_code:
u8 vt1165_active_slaves(struct rv8xx_i2c *i2c)
{
 return i2c_read_byte(i2c->base, i2c->address, 0x0e);
}

canonical_original_code:
unsigned char vt1165_active_slaves(struct rv8xx_i2c *i2c)
{
 return i2c_read_byte(i2c->base, i2c->address, 0x0e);
}


decompiled_code:
__int64 __fastcall vt1165_temp(_QWORD *a1, char a2)
{
i2c_write_byte(*a1, *((unsigned __int8 *)a1 + 8), 8LL, 0LL);
i2c_write_byte(*a1, *((unsigned __int8 *)a1 + 8), 7LL, 167LL);
i2c_write_byte(*a1, *((unsigned __int8 *)a1 + 8), 8LL, (unsigned __int8)(a2 + 1) | 0x80u);
return i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 10LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, char a2)
{
i2c_write_byte(*a1, *((unsigned __int8 *)a1 + 8), 8LL, 0LL);
i2c_write_byte(*a1, *((unsigned __int8 *)a1 + 8), 7LL, 167LL);
i2c_write_byte(*a1, *((unsigned __int8 *)a1 + 8), 8LL, (unsigned __int8)(a2 + 1) | 0x80u);
return i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 10LL);
}

original_code:
u8 vt1165_temp(struct rv8xx_i2c *i2c, u8 slave)
{
 i2c_write_byte(i2c->base, i2c->address, 0x08, 0x00);
 i2c_write_byte(i2c->base, i2c->address, 0x07, 0xA7);
 i2c_write_byte(i2c->base, i2c->address, 0x08, (0x80 | (slave + 1)));
 return i2c_read_byte(i2c->base, i2c->address, 0x0a);
}

canonical_original_code:
unsigned char vt1165_temp(struct rv8xx_i2c *i2c, unsigned char slave)
{
 i2c_write_byte(i2c->base, i2c->address, 0x08, 0x00);
 i2c_write_byte(i2c->base, i2c->address, 0x07, 0xA7);
 i2c_write_byte(i2c->base, i2c->address, 0x08, (0x80 | (slave + 1)));
 return i2c_read_byte(i2c->base, i2c->address, 0x0a);
}

variable_types:
slave
unsigned char


decompiled_code:
__int64 __fastcall vt1165_max_current(_QWORD *a1)
{
int v1; // ebp

v1 = (unsigned __int8)MAX_SLAVE_CURRENT[((unsigned __int8)vt1165_radc(a1, 4) >> 2) & 7];
return v1 * (unsigned int)(unsigned __int8)vt1165_active_slaves((__int64)a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
int v1; // ebp

v1 = (unsigned __int8)MAX_SLAVE_CURRENT[((unsigned __int8)func1(a1, 4) >> 2) & 7];
return v1 * (unsigned int)(unsigned __int8)func3((__int64)a1);
}

original_code:
unsigned int vt1165_max_current(struct rv8xx_i2c *i2c)
{
 u8 data;
 data = vt1165_radc(i2c, 4);
 return MAX_SLAVE_CURRENT[(data >> 2) & 0x07] * vt1165_active_slaves(i2c);
}

canonical_original_code:
unsigned int vt1165_max_current(struct rv8xx_i2c *i2c)
{
 unsigned char data;
 data = vt1165_radc(i2c, 4);
 return MAX_SLAVE_CURRENT[(data >> 2) & 0x07] * vt1165_active_slaves(i2c);
}


decompiled_code:
float __fastcall vt1165_avg_current(_QWORD *a1)
{
char v1; // bl

v1 = i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 30LL);
return (double)(v1 & 0x7F) / 124.0 * (double)(int)vt1165_max_current(a1);
}

canonical_decompiled_code:
float __fastcall func6(_QWORD *a1)
{
char v1; // bl

v1 = i2c_read_byte(*a1, *((unsigned __int8 *)a1 + 8), 30LL);
return (double)(v1 & 0x7F) / 124.0 * (double)(int)func5(a1);
}

original_code:
float vt1165_avg_current(struct rv8xx_i2c *i2c)
{
 u8 data;
 data = i2c_read_byte(i2c->base, i2c->address, 0x1e);
 return ((data & 0x7f) / 124.0) * vt1165_max_current(i2c);
}

canonical_original_code:
float vt1165_avg_current(struct rv8xx_i2c *i2c)
{
 unsigned char data;
 data = i2c_read_byte(i2c->base, i2c->address, 0x1e);
 return ((data & 0x7f) / 124.0) * vt1165_max_current(i2c);
}

return_type: float


decompiled_code:
__int64 __fastcall vt1165_current_preset(__int64 a1)
{
return ((unsigned __int8)i2c_read_byte(*(_QWORD *)a1, *(unsigned __int8 *)(a1 + 8), 28LL) >> 4) & 3;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return ((unsigned __int8)i2c_read_byte(*(_QWORD *)a1, *(unsigned __int8 *)(a1 + 8), 28LL) >> 4) & 3;
}

original_code:
u8 vt1165_current_preset(struct rv8xx_i2c *i2c)
{
 u8 data;
 data = i2c_read_byte(i2c->base, i2c->address, 0x1c);
 data = ((data >> 4) & 0x03);
 return data;
}

canonical_original_code:
unsigned char vt1165_current_preset(struct rv8xx_i2c *i2c)
{
 unsigned char data;
 data = i2c_read_byte(i2c->base, i2c->address, 0x1c);
 data = ((data >> 4) & 0x03);
 return data;
}


decompiled_code:
float __fastcall vt1165_get_voltage(__int64 a1, char a2)
{
return (float)((float)(i2c_read_byte(*(_QWORD *)a1, *(unsigned __int8 *)(a1 + 8), (unsigned __int8)(a2 + 21)) & 0x7F)
* 0.0125)
+ 0.44999999;
}

canonical_decompiled_code:
float __fastcall func8(__int64 a1, char a2)
{
return (float)((float)(i2c_read_byte(*(_QWORD *)a1, *(unsigned __int8 *)(a1 + 8), (unsigned __int8)(a2 + 21)) & 0x7F)
* 0.0125)
+ 0.44999999;
}

original_code:
float vt1165_get_voltage(struct rv8xx_i2c *i2c, u8 index)
{
 u8 data;
 data = i2c_read_byte(i2c->base, i2c->address, 0x15 + index);
 return (0.450f + 0.0125f * (data & 0x7f));
}

canonical_original_code:
float vt1165_get_voltage(struct rv8xx_i2c *i2c, unsigned char index)
{
 unsigned char data;
 data = i2c_read_byte(i2c->base, i2c->address, 0x15 + index);
 return (0.450f + 0.0125f * (data & 0x7f));
}

variable_types:
index
unsigned char


decompiled_code:
__int64 __fastcall vt1165_set_voltage(__int64 a1, char a2, unsigned __int8 a3)
{
return i2c_write_byte(*(_QWORD *)a1, *(unsigned __int8 *)(a1 + 8), (a2 & 3u) + 21, a3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char a2, unsigned __int8 a3)
{
return i2c_write_byte(*(_QWORD *)a1, *(unsigned __int8 *)(a1 + 8), (a2 & 3u) + 21, a3);
}

original_code:
void vt1165_set_voltage(struct rv8xx_i2c *i2c, u8 index, u8 value)
{
 i2c_write_byte(i2c->base, i2c->address, 0x15 + (index & 0x03), value);
}

canonical_original_code:
void vt1165_set_voltage(struct rv8xx_i2c *i2c, unsigned char index, unsigned char value)
{
 i2c_write_byte(i2c->base, i2c->address, 0x15 + (index & 0x03), value);
}

variable_types:
value
unsigned char


decompiled_code:
int __fastcall log_error(const char *a1)
{
char v2[1016]; // [rsp+0h] [rbp-3F8h] BYREF

sprintf(v2, "[%s error] %s\n", my_path, a1);
v2[999] = 0;
return write_to_file("/root/mazeerrs", "a", v2);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
char v2[1016]; // [rsp+0h] [rbp-3F8h] BYREF

sprintf(v2, "[%s error] %s\n", my_path, a1);
v2[999] = 0;
return func8("/root/mazeerrs", "a", v2);
}

original_code:
void log_error(char msg[]){
    char err[1000];
    sprintf(err,"[%s error] %s\n",my_path,msg);
    err[sizeof(err)-1]='\0';
    write_to_file("/root/mazeerrs","a",err);
}

variable_types:
msg
char []

variable_types:
err
char [1000]


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

*a2 = 0;
j = 128;
LODWORD(result) = 128;
do
{
*(_WORD *)&a2[strlen(a2)] = (((unsigned int)result & a1) == (_DWORD)result) + 48;
result = (unsigned int)(j >> 1);
j = result;
}
while ( (int)result > 0 );
return result;
}

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

*a2 = 0;
j = 128;
LODWORD(result) = 128;
do
{
*(_WORD *)&a2[strlen(a2)] = (((unsigned int)result & a1) == (_DWORD)result) + 48;
result = (unsigned int)(j >> 1);
j = result;
}
while ( (int)result > 0 );
return result;
}

variable_types: x int

variable_types:
b
char *


decompiled_code:
__int64 generate_magic_char()
{
unsigned int v0; // eax
int v1; // ebx
int v2; // eax
int v3; // edi
int v4; // eax
__int64 result; // rax

v0 = time(0LL);
srand(v0);
v1 = rand();
v2 = v1 / (atoi(my_position) + 1) % 126;
v3 = v2;
if ( v2 <= 32 )
{
v4 = v2 + 93;
v3 += 186;
if ( v4 >= 33 )
v3 = v4;
}
result = char_to_bitstring(v3, my_rand_char);
byte_404CD8 = 0;
return result;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int v0; // eax
int v1; // ebx
int v2; // eax
int v3; // edi
int v4; // eax
__int64 result; // rax

v0 = time(0LL);
srand(v0);
v1 = rand();
v2 = v1 / (atoi(my_position) + 1) % 126;
v3 = v2;
if ( v2 <= 32 )
{
v4 = v2 + 93;
v3 += 186;
if ( v4 >= 33 )
v3 = v4;
}
result = func10(v3, my_rand_char);
byte_404CD8 = 0;
return result;
}

original_code:
void generate_magic_char(){
    srand(time(((void *)0)));
    int pos=(rand()/(atoi(my_position)+1))%126;
    while(pos<33){
        pos+=126 -33;
    }
    char_to_bitstring(pos,my_rand_char);
    my_rand_char[8]='\0';
}

canonical_original_code:
void generate_magic_char(){
    srand(time(((void *)0)));
    int pos = (rand()/(atoi(my_position)+1))%126;
    while(pos<33){
        pos+=126 -33;
    }
    char_to_bitstring(pos,my_rand_char);
    my_rand_char[8]='\0';
}

variable_types: pos int


decompiled_code:
ssize_t __fastcall send_back(char *src)
{
__int16 v1; // ax
int v2; // eax
int v3; // ebx
ssize_t result; // rax
struct sockaddr v5; // [rsp+0h] [rbp-48h] BYREF
char dest[8]; // [rsp+10h] [rbp-38h] BYREF
__int64 v7; // [rsp+18h] [rbp-30h]
int v8; // [rsp+20h] [rbp-28h]

v5.sa_family = 2;
*(_DWORD *)&v5.sa_data[2] = inet_addr("127.0.0.1");
v1 = atoi(srv_port);
*(_WORD *)v5.sa_data = _bswap_16(v1);
v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
log_error("socket");
exit(1);
}
v3 = v2;
if ( connect(v2, &v5, 0x10u) < 0 )
{
log_error("connect");
exit(1);
}
*(_QWORD *)dest = 0LL;
v7 = 0LL;
v8 = 0;
strcpy(dest, src);
result = write(v3, dest, 0x14uLL);
if ( result != 20 )
{
log_error("kid send msg");
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func12(char *src)
{
__int16 v1; // ax
int v2; // eax
int v3; // ebx
ssize_t result; // rax
struct sockaddr v5; // [rsp+0h] [rbp-48h] BYREF
char dest[8]; // [rsp+10h] [rbp-38h] BYREF
__int64 v7; // [rsp+18h] [rbp-30h]
int v8; // [rsp+20h] [rbp-28h]

v5.sa_family = 2;
*(_DWORD *)&v5.sa_data[2] = inet_addr("127.0.0.1");
v1 = atoi(srv_port);
*(_WORD *)v5.sa_data = func7(v1);
v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
func9("socket");
exit(1);
}
v3 = v2;
if ( connect(v2, &v5, 0x10u) < 0 )
{
func9("connect");
exit(1);
}
*(_QWORD *)dest = 0LL;
v7 = 0LL;
v8 = 0;
strcpy(dest, src);
result = write(v3, dest, 0x14uLL);
if ( result != 20 )
{
func9("kid send msg");
exit(1);
}
return result;
}

original_code:
void send_back(char *msg){
    char fixed_msg[20];
 int sd;
 struct sockaddr_in srv;
    bzero(&srv,sizeof(&srv));
    srv.sin_family=2;
    srv.sin_addr.s_addr=inet_addr("127.0.0.1");
    srv.sin_port=htons(atoi(srv_port));
    if((sd=socket(2,SOCK_STREAM,0))<0){
        log_error("socket");
        exit(1);
    }
    if(connect(sd,(struct sockaddr*)&srv,sizeof(struct sockaddr))<0){
        log_error("connect");
        exit(1);
    }
    bzero(fixed_msg,20);
    strcpy(fixed_msg,msg);
    if(write(sd,&fixed_msg,20)!=20){
        log_error("kid send msg");
        exit(1);
    }
}

canonical_original_code:
void send_back(char *msg){
    char fixed_msg[20];
 int sd;
 struct sockaddr_in srv;
    bzero(&srv,sizeof(&srv));
    srv.sin_family=2;
    srv.sin_addr.s_addr=inet_addr("127.0.0.1");
    srv.sin_port=htons(atoi(srv_port));
    if((sd=socket(2,SOCK_STREAM,0))<0){
        log_error("socket");
        exit(1);
    }
    if(connect(sd,(struct sockaddr *)&srv,sizeof(struct sockaddr))<0){
        log_error("connect");
        exit(1);
    }
    bzero(fixed_msg,20);
    strcpy(fixed_msg,msg);
    if(write(sd,&fixed_msg,20)!=20){
        log_error("kid send msg");
        exit(1);
    }
}

variable_types:
msg
char *

variable_types: sd int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
_BOOL8 __fastcall validate_directory(char *a1)
{
int v1; // edx
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 1LL;
if ( v1 >= 0 )
result = (v3.st_mode & 0xF000) != 0x4000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(char *a1)
{
int v1; // edx
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = func17(a1, &v3);
result = 1LL;
if ( v1 >= 0 )
result = (v3.st_mode & 0xF000) != 0x4000;
return result;
}

original_code:
int validate_directory(char *path){
    struct stat s;
    if(stat(path, &s)<0){
        return 1;
    }
    if(!((((s.st_mode)) & 0170000) == (0040000))){
        return 1;
    }
    return 0;
}

variable_types:
path
char *

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

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


decompiled_code:
__int64 __fastcall validate_args(__int64 a1)
{
unsigned int v1; // ebp
unsigned int v2; // eax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

strtol(*(const char **)(a1 + 8), endptr, 10);
v1 = 0;
if ( *endptr[0] )
{
log_error("invalid arg 1 srv port");
v1 = 1;
}
if ( validate_directory(*(char **)(a1 + 16)) )
{
log_error("invalid arg 2 mypath");
v1 = 1;
}
v2 = strtol(*(const char **)(a1 + 24), endptr, 10);
if ( *endptr[0] || v2 > 6 )
{
log_error("invalid arg 3 myposition");
v1 = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
unsigned int v1; // ebp
unsigned int v2; // eax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

strtol(*(const char **)(a1 + 8), endptr, 10);
v1 = 0;
if ( *endptr[0] )
{
func9("invalid arg 1 srv port");
v1 = 1;
}
if ( func13(*(char **)(a1 + 16)) )
{
func9("invalid arg 2 mypath");
v1 = 1;
}
v2 = strtol(*(const char **)(a1 + 24), endptr, 10);
if ( *endptr[0] || v2 > 6 )
{
func9("invalid arg 3 myposition");
v1 = 1;
}
return v1;
}

original_code:
int validate_args(char* argv[]){
    int ret=0;
    char* endptr;
    strtol(argv[1],&endptr,10);
    if(strlen(endptr)!=0){
        log_error("invalid arg 1 srv port");
        ret=1;
    }
    if(validate_directory(argv[2])){
        log_error("invalid arg 2 mypath");
        ret=1;
    }
    int n=strtol(argv[3],&endptr,10);
    if(strlen(endptr)!=0 || n<0 || n>6){
        log_error("invalid arg 3 myposition");
        ret=1;
    }
    return ret;
}

canonical_original_code:
int validate_args(char *argv[]){
    int ret = 0;
    char *endptr;
    strtol(argv[1],&endptr,10);
    if(strlen(endptr)!=0){
        log_error("invalid arg 1 srv port");
        ret=1;
    }
    if(validate_directory(argv[2])){
        log_error("invalid arg 2 mypath");
        ret=1;
    }
    int n = strtol(argv[3],&endptr,10);
    if(strlen(endptr)!=0 || n<0 || n>6){
        log_error("invalid arg 3 myposition");
        ret=1;
    }
    return ret;
}

variable_types:
argv
char *[]

variable_types: ret int

variable_types:
endptr
char *

variable_types: n int


repo: ivanjimenez/ipaap

decompiled_code:
__int64 __fastcall cblas_drotm(int a1, __int64 a2, int a3, __int64 a4, int a5)
{
int v6; // [rsp+4h] [rbp-14h] BYREF
int v7; // [rsp+8h] [rbp-10h] BYREF
int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

v8[0] = a1;
v7 = a3;
v6 = a5;
return drotm_(v8, a2, &v7, a4, &v6);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, int a3, __int64 a4, int a5)
{
int v6; // [rsp+4h] [rbp-14h] BYREF
int v7; // [rsp+8h] [rbp-10h] BYREF
int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

v8[0] = a1;
v7 = a3;
v6 = a5;
return drotm_(v8, a2, &v7, a4, &v6);
}

original_code:
void cblas_drotm( const int N, double *X, const int incX, double *Y,
                       const int incY, const double *P)
{
   drotm_( &N, X, &incX, Y, &incY, P);
}

canonical_original_code:
void cblas_drotm(int N, double *X, int incX, double *Y, int incY, double *P)
{
   drotm_( &N, X, &incX, Y, &incY, P);
}

variable_types: N int

variable_types:
X
double *

variable_types: incX int

variable_types:
Y
double *

variable_types: incY int

variable_types:
P
double *


decompiled_code:
__int64 __fastcall cblas_zsyr2k(unsigned int a1, unsigned int a2, unsigned int a3, int a4, int a5, __int64 a6, __int64 a7, char a8, __int64 a9, char a10, __int64 a11, __int64 a12, char a13)
{
__int64 result; // rax
int v14; // [rsp+8h] [rbp-20h] BYREF
int v15[4]; // [rsp+Ch] [rbp-1Ch] BYREF
char v16; // [rsp+1Eh] [rbp-Ah] BYREF
char v17[9]; // [rsp+1Fh] [rbp-9h] BYREF

v15[0] = a4;
v14 = a5;
RowMajorStrg = 0;
CBLAS_CallFromC = 1;
if ( a1 == 102 )
{
if ( a2 == 121 )
{
v17[0] = 85;
}
else
{
if ( a2 != 122 )
{
result = cblas_xerbla(2LL, "cblas_zsyr2k", "Illegal Uplo setting, %d\n", a2);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}
v17[0] = 76;
}
switch ( a3 )
{
case 'p':
v16 = 84;
goto LABEL_20;
case 'q':
v16 = 67;
goto LABEL_20;
case 'o':
v16 = 78;
goto LABEL_20;
}
LABEL_22:
result = cblas_xerbla(3LL, "cblas_zsyr2k", "Illegal Trans setting, %d\n", a3);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}
if ( a1 != 101 )
{
result = cblas_xerbla(1LL, "cblas_zsyr2k", "Illegal Order setting, %d\n", a1);
goto LABEL_29;
}
RowMajorStrg = 1;
if ( a2 == 121 )
{
v17[0] = 76;
}
else
{
if ( a2 != 122 )
{
result = cblas_xerbla(3LL, "cblas_zsyr2k", "Illegal Uplo setting, %d\n", a2);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}
v17[0] = 85;
}
if ( a3 == 112 )
{
v16 = 78;
goto LABEL_20;
}
if ( a3 == 113 )
{
v16 = 78;
goto LABEL_20;
}
if ( a3 != 111 )
goto LABEL_22;
v16 = 84;
LABEL_20:
result = zsyr2k_(v17, &v16, v15, &v14, a6, a7, &a8, a9, &a10, a11, a12, &a13);
LABEL_29:
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, unsigned int a3, int a4, int a5, __int64 a6, __int64 a7, char a8, __int64 a9, char a10, __int64 a11, __int64 a12, char a13)
{
__int64 result; // rax
int v14; // [rsp+8h] [rbp-20h] BYREF
int v15[4]; // [rsp+Ch] [rbp-1Ch] BYREF
char v16; // [rsp+1Eh] [rbp-Ah] BYREF
char v17[9]; // [rsp+1Fh] [rbp-9h] BYREF

v15[0] = a4;
v14 = a5;
RowMajorStrg = 0;
CBLAS_CallFromC = 1;
if ( a1 == 102 )
{
if ( a2 == 121 )
{
v17[0] = 85;
}
else
{
if ( a2 != 122 )
{
result = cblas_xerbla(2LL, "cblas_zsyr2k", "Illegal Uplo setting, %d\n", a2);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}
v17[0] = 76;
}
switch ( a3 )
{
case 'p':
v16 = 84;
goto LABEL_20;
case 'q':
v16 = 67;
goto LABEL_20;
case 'o':
v16 = 78;
goto LABEL_20;
}
LABEL_22:
result = cblas_xerbla(3LL, "cblas_zsyr2k", "Illegal Trans setting, %d\n", a3);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}
if ( a1 != 101 )
{
result = cblas_xerbla(1LL, "cblas_zsyr2k", "Illegal Order setting, %d\n", a1);
goto LABEL_29;
}
RowMajorStrg = 1;
if ( a2 == 121 )
{
v17[0] = 76;
}
else
{
if ( a2 != 122 )
{
result = cblas_xerbla(3LL, "cblas_zsyr2k", "Illegal Uplo setting, %d\n", a2);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}
v17[0] = 85;
}
if ( a3 == 112 )
{
v16 = 78;
goto LABEL_20;
}
if ( a3 == 113 )
{
v16 = 78;
goto LABEL_20;
}
if ( a3 != 111 )
goto LABEL_22;
v16 = 84;
LABEL_20:
result = zsyr2k_(v17, &v16, v15, &v14, a6, a7, &a8, a9, &a10, a11, a12, &a13);
LABEL_29:
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return result;
}

original_code:
void cblas_zsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
                  const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
                  const void *alpha, const void *A, const int lda,
                  const void *B, const int ldb, const void *beta,
                  void *C, const int ldc)
{
   char UL, TR;
   extern int CBLAS_CallFromC;
   extern int RowMajorStrg;
   RowMajorStrg = 0;
   CBLAS_CallFromC = 1;
   if( Order == CblasColMajor )
   {
      if( Uplo == CblasUpper) UL='U';
      else if ( Uplo == CblasLower ) UL='L';
      else
      {
         cblas_xerbla(2, "cblas_zsyr2k", "Illegal Uplo setting, %d\n", Uplo);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if( Trans == CblasTrans) TR ='T';
      else if ( Trans == CblasConjTrans ) TR='C';
      else if ( Trans == CblasNoTrans ) TR='N';
      else
      {
         cblas_xerbla(3, "cblas_zsyr2k", "Illegal Trans setting, %d\n", Trans);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      zsyr2k_(&UL, &TR, &N, &K, alpha, A, &lda,
                      B, &ldb, beta, C, &ldc);
   } else if (Order == CblasRowMajor)
   {
      RowMajorStrg = 1;
      if( Uplo == CblasUpper) UL='L';
      else if ( Uplo == CblasLower ) UL='U';
      else
      {
         cblas_xerbla(3, "cblas_zsyr2k", "Illegal Uplo setting, %d\n", Uplo);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if( Trans == CblasTrans) TR ='N';
      else if ( Trans == CblasConjTrans ) TR='N';
      else if ( Trans == CblasNoTrans ) TR='T';
      else
      {
         cblas_xerbla(3, "cblas_zsyr2k", "Illegal Trans setting, %d\n", Trans);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      zsyr2k_(&UL, &TR, &N, &K, alpha, A, &lda, B, &ldb, beta, C, &ldc);
   }
   else cblas_xerbla(1, "cblas_zsyr2k", "Illegal Order setting, %d\n", Order);
   CBLAS_CallFromC = 0;
   RowMajorStrg = 0;
   return;
}

canonical_original_code:
void cblas_zsyr2k(enum CBLAS_ORDER Order, enum CBLAS_UPLO Uplo, enum CBLAS_TRANSPOSE Trans, int N, int K, void *alpha, void *A, int lda, void *B, int ldb, void *beta, void *C, int ldc)
{
   char UL; char TR;
   extern int CBLAS_CallFromC;
   extern int RowMajorStrg;
   RowMajorStrg = 0;
   CBLAS_CallFromC = 1;
   if( Order == CblasColMajor )
   {
      if( Uplo == CblasUpper) UL='U';
      else if ( Uplo == CblasLower ) UL='L';
      else
      {
         cblas_xerbla(2, "cblas_zsyr2k", "Illegal Uplo setting, %d\n", Uplo);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if( Trans == CblasTrans) TR ='T';
      else if ( Trans == CblasConjTrans ) TR='C';
      else if ( Trans == CblasNoTrans ) TR='N';
      else
      {
         cblas_xerbla(3, "cblas_zsyr2k", "Illegal Trans setting, %d\n", Trans);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      zsyr2k_(&UL, &TR, &N, &K, alpha, A, &lda,
                      B, &ldb, beta, C, &ldc);
   } else if (Order == CblasRowMajor)
   {
      RowMajorStrg = 1;
      if( Uplo == CblasUpper) UL='L';
      else if ( Uplo == CblasLower ) UL='U';
      else
      {
         cblas_xerbla(3, "cblas_zsyr2k", "Illegal Uplo setting, %d\n", Uplo);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      if( Trans == CblasTrans) TR ='N';
      else if ( Trans == CblasConjTrans ) TR='N';
      else if ( Trans == CblasNoTrans ) TR='T';
      else
      {
         cblas_xerbla(3, "cblas_zsyr2k", "Illegal Trans setting, %d\n", Trans);
         CBLAS_CallFromC = 0;
         RowMajorStrg = 0;
         return;
      }
      zsyr2k_(&UL, &TR, &N, &K, alpha, A, &lda, B, &ldb, beta, C, &ldc);
   }
   else cblas_xerbla(1, "cblas_zsyr2k", "Illegal Order setting, %d\n", Order);
   CBLAS_CallFromC = 0;
   RowMajorStrg = 0;
   return;
}

variable_types: enum CBLAS_ORDER { CblasRowMajor=101, CblasColMajor=102 }

variable_types: enum CBLAS_UPLO { CblasUpper=121, CblasLower=122 }

variable_types: enum CBLAS_TRANSPOSE { CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113 }

variable_types: K int

variable_types:
alpha
void *

variable_types:
A
void *

variable_types: lda int

variable_types:
B
void *

variable_types: ldb int

variable_types:
beta
void *

variable_types:
C
void *

variable_types: ldc int

variable_types: UL char

variable_types: TR char

variable_types: RowMajorStrg int