main

canonical_name: main

repo: ircnet/irc

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
const char *v4; // r14
unsigned int v5; // er13
int v6; // ebx
unsigned int v7; // eax
char *v8; // rax
int result; // eax
unsigned int v10; // [rsp+Ch] [rbp-3Ch]

v3 = 0LL;
v4 = 0LL;
v5 = 0;
v6 = 0;
v10 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "mdber:h?l:s:p:");
if ( v7 == -1 )
break;
switch ( v7 )
{
case '?':
brief_usage();
return result;
case 'b':
v6 |= 0x20u;
v5 = 4;
break;
case 'd':
v6 |= 2u;
break;
case 'e':
LOBYTE(v6) = v6 | 0x80;
v5 = 25;
break;
case 'h':
full_usage();
return result;
case 'l':
v6 |= 0x10u;
v10 = atoi(optarg);
break;
case 'm':
v6 |= 1u;
break;
case 'p':
v3 = optarg;
v6 |= 8u;
break;
case 'r':
v6 |= 0x40u;
v5 = atoi(optarg);
break;
case 's':
v4 = optarg;
v6 |= 4u;
break;
default:
printf("Invalid Option: -%c\n", v7);
break;
}
}
if ( (v6 & 1) != 0 )
{
if ( !v10 )
v10 = 8;
if ( (v6 & 4) != 0 )
v4 = (const char *)make_md5_salt_para(v4, v7);
else
v4 = (const char *)make_md5_salt(v10, v7);
}
else if ( (v6 & 0x20) != 0 )
{
if ( !v10 )
v10 = 22;
if ( (v6 & 4) != 0 )
v4 = (const char *)make_bf_salt_para(v5, v4);
else
v4 = (const char *)make_bf_salt(v5, v10);
}
else if ( (v6 & 0x80u) == 0 )
{
if ( (v6 & 4) != 0 )
{
if ( strlen(v4) != 2 )
{
puts("Invalid salt, please enter 2 alphanumeric characters");
exit(1);
}
}
else
{
v4 = (const char *)make_des_salt((unsigned int)argc, v7);
}
}
else if ( (v6 & 4) != 0 )
{
if ( strlen(v4) != 4 )
{
puts("Invalid salt, please enter 4 alphanumeric characters");
exit(1);
}
v4 = (const char *)make_ext_salt_para(v5, v4);
}
else
{
v4 = (const char *)make_ext_salt(v5, v7);
}
if ( (v6 & 8) != 0 )
{
if ( !v3 )
puts("Please enter a valid password");
}
else
{
v3 = getpass("plaintext: ");
}
v8 = crypt(v3, v4);
puts(v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
const char *v4; // r14
unsigned int v5; // er13
int v6; // ebx
unsigned int v7; // eax
char *v8; // rax
int result; // eax
unsigned int v10; // [rsp+Ch] [rbp-3Ch]

v3 = 0LL;
v4 = 0LL;
v5 = 0;
v6 = 0;
v10 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "mdber:h?l:s:p:");
if ( v7 == -1 )
break;
switch ( v7 )
{
case '?':
func15();
return result;
case 'b':
v6 |= 0x20u;
v5 = 4;
break;
case 'd':
v6 |= 2u;
break;
case 'e':
LOBYTE(v6) = v6 | 0x80;
v5 = 25;
break;
case 'h':
func14();
return result;
case 'l':
v6 |= 0x10u;
v10 = atoi(optarg);
break;
case 'm':
v6 |= 1u;
break;
case 'p':
v3 = optarg;
v6 |= 8u;
break;
case 'r':
v6 |= 0x40u;
v5 = atoi(optarg);
break;
case 's':
v4 = optarg;
v6 |= 4u;
break;
default:
printf("Invalid Option: -%c\n", v7);
break;
}
}
if ( (v6 & 1) != 0 )
{
if ( !v10 )
v10 = 8;
if ( (v6 & 4) != 0 )
v4 = (const char *)func9(v4, v7);
else
v4 = (const char *)make_md5_salt(v10, v7);
}
else if ( (v6 & 0x20) != 0 )
{
if ( !v10 )
v10 = 22;
if ( (v6 & 4) != 0 )
v4 = (const char *)func10(v5, v4);
else
v4 = (const char *)func13(v5, v10);
}
else if ( (v6 & 0x80u) == 0 )
{
if ( (v6 & 4) != 0 )
{
if ( strlen(v4) != 2 )
{
puts("Invalid salt, please enter 2 alphanumeric characters");
exit(1);
}
}
else
{
v4 = (const char *)func11((unsigned int)argc, v7);
}
}
else if ( (v6 & 4) != 0 )
{
if ( strlen(v4) != 4 )
{
puts("Invalid salt, please enter 4 alphanumeric characters");
exit(1);
}
v4 = (const char *)func8(v5, v4);
}
else
{
v4 = (const char *)func12(v5, v7);
}
if ( (v6 & 8) != 0 )
{
if ( !v3 )
puts("Please enter a valid password");
}
else
{
v3 = getpass("plaintext: ");
}
v8 = crypt(v3, v4);
puts(v8);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  char *plaintext = ((void *)0);
  extern char *optarg;
  int c;
  char *saltpara = ((void *)0);
  char *salt;
  int flag = 0;
  int length = 0;
  int rounds = 0;
  while( (c=getopt(argc, argv, "mdber:h?l:s:p:")) != -1)
  {
    switch(c)
    {
      case 'm':
        flag |= 0x00000001;
        break;
      case 'd':
        flag |= 0x00000002;
        break;
      case 'b':
        flag |= 0x00000020;
        rounds = 4;
        break;
      case 'e':
        flag |= 0x00000080;
        rounds = 25;
        break;
      case 'l':
        flag |= 0x00000010;
        length = atoi(optarg);
        break;
      case 'r':
        flag |= 0x00000040;
        rounds = atoi(optarg);
        break;
      case 's':
        flag |= 0x00000004;
        saltpara = optarg;
        break;
      case 'p':
        flag |= 0x00000008;
        plaintext = optarg;
        break;
      case 'h':
        full_usage();
        break;
      case '?':
        brief_usage();
        break;
      default:
        printf("Invalid Option: -%c\n", c);
        break;
    }
  }
  if (flag & 0x00000001)
  {
    if (length == 0)
      length = 8;
    if (flag & 0x00000004)
      salt = make_md5_salt_para(saltpara);
    else
      salt = make_md5_salt(length);
  }
  else if (flag & 0x00000020)
  {
    if (length == 0)
      length = 22;
    if (flag & 0x00000004)
      salt = make_bf_salt_para(rounds, saltpara);
    else
      salt = make_bf_salt(rounds, length);
  }
  else if (flag & 0x00000080)
  {
    if (flag & 0x00000004)
    {
      if ((strlen(saltpara) == 4))
      {
        salt = make_ext_salt_para(rounds, saltpara);
      }
      else
      {
        printf("Invalid salt, please enter 4 alphanumeric characters\n");
        exit(1);
      }
    }
    else
    {
      salt = make_ext_salt(rounds);
    }
  }
  else
  {
    if (flag & 0x00000004)
    {
      if ((strlen(saltpara) == 2))
      {
        salt = saltpara;
      }
      else
      {
        printf("Invalid salt, please enter 2 alphanumeric characters\n");
        exit(1);
      }
    }
    else
    {
      salt = make_des_salt();
    }
  }
  if (flag & 0x00000008)
  {
    if (!plaintext)
      printf("Please enter a valid password\n");
  }
  else
  {
    plaintext = getpass("plaintext: ");
  }
  printf("%s\n", crypt(plaintext, salt));
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
plaintext
char *

variable_types:
optarg
char *

variable_types: c int

variable_types:
saltpara
char *

variable_types:
salt
char *

variable_types: flag int

variable_types: length int

variable_types: rounds int


decompiled_code:
void *__fastcall int_to_base64(int a1)
{
char *v1; // rax
char v2; // dl

v1 = (char *)&buf_6;
do
{
v2 = a1;
++v1;
a1 >>= 6;
*(v1 - 1) = saltChars[v2 & 0x3F];
}
while ( v1 != &byte_404156 );
byte_404156 = 0;
return &buf_6;
}

canonical_decompiled_code:
void *__fastcall func7(int a1)
{
char *v1; // rax
char v2; // dl

v1 = (char *)&buf_6;
do
{
v2 = a1;
++v1;
a1 >>= 6;
*(v1 - 1) = saltChars[v2 & 0x3F];
}
while ( v1 != &byte_404156 );
byte_404156 = 0;
return &buf_6;
}

original_code:
char *int_to_base64(int value)
{
  static char buf[5];
  int i;
  for (i = 0; i < 4; i++)
  {
    buf[i] = saltChars[value & 63];
    value >>= 6;
  }
  buf[i] = '\0';
  return buf;
}

variable_types: value int

variable_types:
buf
char [5]

variable_types: i int

return_type: char *


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

v1 = (const char *)int_to_base64(a1);
sprintf(salt_4, "_%s%s", v1, v2);
return salt_4;
}

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

v1 = (const char *)func7(a1);
sprintf(salt_4, "_%s%s", v1, v2);
return salt_4;
}

original_code:
char *make_ext_salt_para(int rounds, char *saltpara)
{
  static char salt[10];
  sprintf(salt, "_%s%s", int_to_base64(rounds), saltpara);
  return salt;
}

variable_types:
salt
char [10]


decompiled_code:
char *__fastcall make_md5_salt_para(const char *a1)
{
if ( !a1 || strlen(a1) > 0x10 )
{
puts("Invalid Salt, please use up to 16 random alphanumeric characters");
exit(1);
}
sprintf(salt_3, "$1$%s$", a1);
return salt_3;
}

canonical_decompiled_code:
char *__fastcall func9(const char *a1)
{
if ( !a1 || strlen(a1) > 0x10 )
{
puts("Invalid Salt, please use up to 16 random alphanumeric characters");
exit(1);
}
sprintf(salt_3, "$1$%s$", a1);
return salt_3;
}

original_code:
char *make_md5_salt_para(char *saltpara)
{
  static char salt[21];
  if (saltpara && (strlen(saltpara) <= 16))
  {
    sprintf(salt, "$1$%s$", saltpara);
    return salt;
  }
  printf("Invalid Salt, please use up to 16 random alphanumeric characters\n");
  exit(1);
  return ((void *)0);
}

variable_types:
salt
char [21]


decompiled_code:
char *__fastcall make_bf_salt_para(unsigned int a1, const char *a2)
{
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

if ( !a2 || strlen(a2) > 0x16 )
{
puts("Invalid Salt, please use up to 22 random alphanumeric characters");
exit(1);
}
sprintf(s, "%02d", a1);
sprintf(salt_1, "$2a$%s$%s$", s, a2);
return salt_1;
}

canonical_decompiled_code:
char *__fastcall func10(unsigned int a1, const char *a2)
{
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

if ( !a2 || strlen(a2) > 0x16 )
{
puts("Invalid Salt, please use up to 22 random alphanumeric characters");
exit(1);
}
sprintf(s, "%02d", a1);
sprintf(salt_1, "$2a$%s$%s$", s, a2);
return salt_1;
}

original_code:
char *make_bf_salt_para(int rounds, char *saltpara)
{
  static char salt[31];
  char tbuf[3];
  if (saltpara && (strlen(saltpara) <= 22))
  {
    sprintf(tbuf, "%02d", rounds);
    sprintf(salt, "$2a$%s$%s$", tbuf, saltpara);
    return salt;
  }
  printf("Invalid Salt, please use up to 22 random alphanumeric characters\n");
  exit(1);
  return ((void *)0);
}

variable_types:
salt
char [31]

variable_types:
tbuf
char [3]


decompiled_code:
_BYTE *make_des_salt()
{
generate_random_salt(salt_7, 2);
byte_404159 = 0;
return salt_7;
}

canonical_decompiled_code:
_BYTE *func11()
{
generate_random_salt(salt_7, 2);
byte_404159 = 0;
return salt_7;
}

original_code:
char *make_des_salt(void)
{
  static char salt[3];
  generate_random_salt(salt, 2);
  salt[2] = '\0';
  return salt;
}

canonical_original_code:
char *make_des_salt()
{
  static char salt[3];
  generate_random_salt(salt, 2);
  salt[2] = '\0';
  return salt;
}

variable_types:
salt
char [3]


decompiled_code:
char *__fastcall make_ext_salt(int a1)
{
const char *v1; // rax

v1 = (const char *)int_to_base64(a1);
sprintf(salt_5, "_%s", v1);
generate_random_salt(byte_40414D, 4);
byte_404151 = 0;
return salt_5;
}

canonical_decompiled_code:
char *__fastcall func12(int a1)
{
const char *v1; // rax

v1 = (const char *)func7(a1);
sprintf(salt_5, "_%s", v1);
generate_random_salt(byte_40414D, 4);
byte_404151 = 0;
return salt_5;
}

original_code:
char *make_ext_salt(int rounds)
{
  static char salt[10];
  sprintf(salt, "_%s", int_to_base64(rounds));
  generate_random_salt(&salt[5], 4);
  salt[9] = '\0';
  return salt;
}


decompiled_code:
char *__fastcall make_bf_salt(unsigned int a1, int a2)
{
char *result; // rax
char s[11]; // [rsp+Dh] [rbp-Bh] BYREF

if ( a2 > 22 )
{
puts("BlowFish salt length too long");
exit(0);
}
sprintf(s, "%02d", a1);
sprintf(&salt_0, "$2a$%s$", s);
generate_random_salt(byte_4040C7, a2);
*(&salt_0 + a2 + 7) = 36;
result = &salt_0;
*(&salt_0 + a2 + 8) = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func13(unsigned int a1, int a2)
{
char *result; // rax
char s[11]; // [rsp+Dh] [rbp-Bh] BYREF

if ( a2 > 22 )
{
puts("BlowFish salt length too long");
exit(0);
}
sprintf(s, "%02d", a1);
sprintf(&salt_0, "$2a$%s$", s);
generate_random_salt(byte_4040C7, a2);
*(&salt_0 + a2 + 7) = 36;
result = &salt_0;
*(&salt_0 + a2 + 8) = 0;
return result;
}

original_code:
char *make_bf_salt(int rounds, int length)
{
  static char salt[31];
  char tbuf[3];
  if (length > 22)
  {
    printf("BlowFish salt length too long\n");
    exit(0);
  }
  sprintf(tbuf, "%02d", rounds);
  sprintf(salt, "$2a$%s$", tbuf);
  generate_random_salt(&salt[7], length);
  salt[length+7] = '$';
  salt[length+8] = '\0';
  return salt;
}


decompiled_code:
void __noreturn full_usage()
{
puts("mkpasswd [-m|-d|-b|-e] [-l saltlength] [-r rounds] [-s salt] [-p plaintext]");
puts("-m Generate an MD5 password");
puts("-d Generate a DES password");
puts("-b Generate a BlowFish password");
puts("-e Generate an Extended DES password");
puts("-l Specify a length for a random MD5 or BlowFish salt");
puts("-r Specify a number of rounds for a BlowFish or Extended DES password");
puts(" BlowFish: default 4, no more than 6 recommended");
puts(" Extended DES: default 25");
puts("-s Specify a salt, 2 alphanumeric characters for DES, up to 16 for MD5,");
puts(" up to 22 for BlowFish, and 4 for Extended DES");
puts("-p Specify a plaintext password to use");
puts("Example: mkpasswd -m -s 3dr -p test");
exit(0);
}

canonical_decompiled_code:
void __noreturn func14()
{
puts("mkpasswd [-m|-d|-b|-e] [-l saltlength] [-r rounds] [-s salt] [-p plaintext]");
puts("-m Generate an MD5 password");
puts("-d Generate a DES password");
puts("-b Generate a BlowFish password");
puts("-e Generate an Extended DES password");
puts("-l Specify a length for a random MD5 or BlowFish salt");
puts("-r Specify a number of rounds for a BlowFish or Extended DES password");
puts(" BlowFish: default 4, no more than 6 recommended");
puts(" Extended DES: default 25");
puts("-s Specify a salt, 2 alphanumeric characters for DES, up to 16 for MD5,");
puts(" up to 22 for BlowFish, and 4 for Extended DES");
puts("-p Specify a plaintext password to use");
puts("Example: mkpasswd -m -s 3dr -p test");
exit(0);
}

original_code:
void full_usage(void)
{
  printf("mkpasswd [-m|-d|-b|-e] [-l saltlength] [-r rounds] [-s salt] [-p plaintext]\n");
  printf("-m Generate an MD5 password\n");
  printf("-d Generate a DES password\n");
  printf("-b Generate a BlowFish password\n");
  printf("-e Generate an Extended DES password\n");
  printf("-l Specify a length for a random MD5 or BlowFish salt\n");
  printf("-r Specify a number of rounds for a BlowFish or Extended DES password\n");
  printf("   BlowFish:  default 4, no more than 6 recommended\n");
  printf("   Extended DES:  default 25\n");
  printf("-s Specify a salt, 2 alphanumeric characters for DES, up to 16 for MD5,\n");
  printf("   up to 22 for BlowFish, and 4 for Extended DES\n");
  printf("-p Specify a plaintext password to use\n");
  printf("Example: mkpasswd -m -s 3dr -p test\n");
  exit(0);
}

canonical_original_code:
void full_usage()
{
  printf("mkpasswd [-m|-d|-b|-e] [-l saltlength] [-r rounds] [-s salt] [-p plaintext]\n");
  printf("-m Generate an MD5 password\n");
  printf("-d Generate a DES password\n");
  printf("-b Generate a BlowFish password\n");
  printf("-e Generate an Extended DES password\n");
  printf("-l Specify a length for a random MD5 or BlowFish salt\n");
  printf("-r Specify a number of rounds for a BlowFish or Extended DES password\n");
  printf("   BlowFish:  default 4, no more than 6 recommended\n");
  printf("   Extended DES:  default 25\n");
  printf("-s Specify a salt, 2 alphanumeric characters for DES, up to 16 for MD5,\n");
  printf("   up to 22 for BlowFish, and 4 for Extended DES\n");
  printf("-p Specify a plaintext password to use\n");
  printf("Example: mkpasswd -m -s 3dr -p test\n");
  exit(0);
}

return_type: void


decompiled_code:
void __noreturn brief_usage()
{
puts("mkpasswd - password hash generator");
puts("Standard DES: mkpasswd [-d] [-s salt] [-p plaintext]");
puts("Extended DES: mkpasswd -e [-r rounds] [-s salt] [-p plaintext]");
puts(" MD5: mkpasswd -m [-l saltlength] [-s salt] [-p plaintext]");
puts(" BlowFish: mkpasswd -b [-r rounds] [-l saltlength] [-s salt]");
puts(" [-p plaintext]");
puts("Use -h for full usage");
exit(0);
}

canonical_decompiled_code:
void __noreturn func15()
{
puts("mkpasswd - password hash generator");
puts("Standard DES: mkpasswd [-d] [-s salt] [-p plaintext]");
puts("Extended DES: mkpasswd -e [-r rounds] [-s salt] [-p plaintext]");
puts(" MD5: mkpasswd -m [-l saltlength] [-s salt] [-p plaintext]");
puts(" BlowFish: mkpasswd -b [-r rounds] [-l saltlength] [-s salt]");
puts(" [-p plaintext]");
puts("Use -h for full usage");
exit(0);
}

original_code:
void brief_usage(void)
{
  printf("mkpasswd - password hash generator\n");
  printf("Standard DES:  mkpasswd [-d] [-s salt] [-p plaintext]\n");
  printf("Extended DES:  mkpasswd -e [-r rounds] [-s salt] [-p plaintext]\n");
  printf("         MD5:  mkpasswd -m [-l saltlength] [-s salt] [-p plaintext]\n");
  printf("    BlowFish:  mkpasswd -b [-r rounds] [-l saltlength] [-s salt]\n");
  printf("                           [-p plaintext]\n");
  printf("Use -h for full usage\n");
  exit(0);
}

canonical_original_code:
void brief_usage()
{
  printf("mkpasswd - password hash generator\n");
  printf("Standard DES:  mkpasswd [-d] [-s salt] [-p plaintext]\n");
  printf("Extended DES:  mkpasswd -e [-r rounds] [-s salt] [-p plaintext]\n");
  printf("         MD5:  mkpasswd -m [-l saltlength] [-s salt] [-p plaintext]\n");
  printf("    BlowFish:  mkpasswd -b [-r rounds] [-l saltlength] [-s salt]\n");
  printf("                           [-p plaintext]\n");
  printf("Use -h for full usage\n");
  exit(0);
}


cas

repo: irinaburdova/OS

decompiled_code:
__int64 __fastcall cas(__int64 _RDI, unsigned int a2, int _EDX)
{
__int64 result; // rax

result = a2;
__asm { cmpxchg [rdi], edx }
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 _RDI, unsigned int a2, int _EDX)
{
__int64 result; // rax

result = a2;
__asm { cmpxchg [rdi], edx }
return result;
}

original_code:
void cas(int* value, int cmp, int new_value) {
    int result;
    asm volatile("cmpxchg %1, %2"
        :"=a"(result)
        :"r"(new_value), "m"(*value), "0"(cmp)
        :"memory"
        );
    return;
}

canonical_original_code:
void cas(int *value, int cmp, int new_value) {
    int result;
    asm volatile("cmpxchg %1, %2"
        :"=a"(result)
        :"r"(new_value), "m"(*value), "0"(cmp)
        :"memory"
        );
    return;
}

variable_types:
value
int *

variable_types: cmp int

variable_types: result int


lock

decompiled_code:
int __fastcall lock(_DWORD *a1, int a2)
{
int result; // eax
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v3.tv_sec = 0LL;
v3.tv_nsec = 10LL;
do
{
cas((__int64)a1, 0, a2);
result = nanosleep(&v3, 0LL);
}
while ( *a1 != a2 );
return result;
}

canonical_decompiled_code:
int __fastcall func8(_DWORD *a1, int a2)
{
int result; // eax
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v3.tv_sec = 0LL;
v3.tv_nsec = 10LL;
do
{
func7((__int64)a1, 0, a2);
result = nanosleep(&v3, 0LL);
}
while ( *a1 != a2 );
return result;
}

original_code:
void lock(int* lock, int who) {
    struct timespec t;
    t.tv_sec = 0;
    t.tv_nsec = 10;
    do {
        cas(lock, 0, who);
        nanosleep(&t, ((void *)0));
    } while (*lock != who);
    return;
}

canonical_original_code:
void lock(int *lock, int who) {
    struct timespec t;
    t.tv_sec = 0;
    t.tv_nsec = 10;
    do {
        cas(lock, 0, who);
        nanosleep(&t, ((void *)0));
    } while (*lock != who);
    return;
}

variable_types:
lock
int *

variable_types: who int

variable_types: struct timespec { long tv_sec; long tv_nsec; }


worker

decompiled_code:
void *__fastcall worker(void *a1)
{
int v1; // ebx
int v2; // ebp
struct timespec v4; // [rsp+0h] [rbp-28h] BYREF

v1 = 500;
v2 = *(_DWORD *)a1;
v4.tv_sec = 0LL;
v4.tv_nsec = 10LL;
do
{
lock(mutex, v2);
++sum;
nanosleep(&v4, 0LL);
unlock(mutex);
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1)
{
int v1; // ebx
int v2; // ebp
struct timespec v4; // [rsp+0h] [rbp-28h] BYREF

v1 = 500;
v2 = *(_DWORD *)a1;
v4.tv_sec = 0LL;
v4.tv_nsec = 10LL;
do
{
func8(mutex, v2);
++sum;
nanosleep(&v4, 0LL);
func9(mutex);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void* worker(void *number) {
    int i;
    int id = *((int *) number);
    struct timespec t;
    t.tv_sec = 0;
    t.tv_nsec = 10;
    for (i = 0; i != 500; ++i) {
        lock(&mutex, id);
        ++sum;
        nanosleep(&t, ((void *)0));
        unlock(&mutex);
    }
    return ((void *)0);
}

canonical_original_code:
void *worker(void *number) {
    int i;
    int id = *((int *) number);
    struct timespec t;
    t.tv_sec = 0;
    t.tv_nsec = 10;
    for (i = 0; i != 500; ++i) {
        lock(&mutex, id);
        ++sum;
        nanosleep(&t, ((void *)0));
        unlock(&mutex);
    }
    return ((void *)0);
}

variable_types:
number
void *

variable_types: id int

return_type: void *

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 *v4; // r14
pthread_t *v5; // r15
unsigned int v6; // eax
int v7; // er12
__int64 i; // rbx
unsigned int v10; // eax
__int64 v11; // [rsp+0h] [rbp-4E0h] BYREF
_QWORD v12[106]; // [rsp+190h] [rbp-350h] BYREF

v3 = 0;
v4 = &v11;
v5 = v12;
do
{
*(_DWORD *)v4 = ++v3;
v6 = pthread_create(v5, 0LL, worker, v4);
v7 = v6;
if ( v6 )
{
v7 = 13;
printf("Can't create thread: %d\n", v6);
return v7;
}
v4 = (__int64 *)((char *)v4 + 4);
++v5;
}
while ( v3 != 100 );
for ( i = 0LL; i != 100; ++i )
{
while ( 1 )
{
v10 = pthread_join(v12[i], 0LL);
if ( v10 )
break;
if ( ++i == 100 )
goto LABEL_10;
}
printf("Can't join thread %d: %d", (unsigned int)i, v10);
}
LABEL_10:
printf("%lu\n", sum);
return v7;
}

original_code:
int main() {
    int threads_count = 100;
    pthread_t threads[threads_count];
    int ids[threads_count];
    int error, i;
    for (i = 0; i != threads_count; ++i) {
        ids[i] = i + 1;
        error = pthread_create(&threads[i], ((void *)0), &worker, &ids[i]);
        if (error) {
            printf("Can't create thread: %d\n", error);
            return 13;
        }
    }
    for (i = 0; i != threads_count; ++i) {
        error = pthread_join(threads[i], ((void *)0));
        if (error) {
            printf("Can't join thread %d: %d", i, error);
        }
    }
    printf("%lu\n", sum);
    return 0;
}

canonical_original_code:
int main() {
    int threads_count = 100;
    unsigned long threads[-1];
    int ids[-1];
    int error; int i;
    for (i = 0; i != threads_count; ++i) {
        ids[i] = i + 1;
        error = pthread_create(&threads[i], ((void *)0), &worker, &ids[i]);
        if (error) {
            printf("Can't create thread: %d\n", error);
            return 13;
        }
    }
    for (i = 0; i != threads_count; ++i) {
        error = pthread_join(threads[i], ((void *)0));
        if (error) {
            printf("Can't join thread %d: %d", i, error);
        }
    }
    printf("%lu\n", sum);
    return 0;
}

variable_types:
threads
unsigned long [-1]

variable_types:
ids
int [-1]

variable_types: error int

return_type: int


repo: irtefa/algo

original_code:
int rabin_karp(char text[], char pattern[])
{
 int t_len = strlen(text);
 int p_len = strlen(pattern);
 int i, j;
 if(p_len > t_len)
 {
  return 0;
 }
 int h = 1;
 for (i = 0; i < p_len - 1; i++)
 {
             h = (h*256)%3571;
   }
 for(i = 0; i < p_len; i++)
 {
  if(pattern[i] != text[i])
  {
   break;
  }
 }
 if(i == p_len)
 {
  printf("found at %d\n", i - p_len);
  return 1;
 }
 int hp = 0;
 int ht = 0;
 for(i = 0; i < p_len; i++)
 {
  hp = (hp * 256 + pattern[i]) % 3571;
  ht = (ht * 256 + text[i]) % 3571;
 }
 for(i = 0; i < t_len; i++)
 {
  if(ht == hp)
  {
   for(j = 0; j < p_len; j++)
   {
    if(text[i + j] != pattern[j])
    {
     break;
    }
   }
   if(j == p_len)
   {
    printf("found at %d\n", i);
    return 1;
   }
  }
  ht = (256 * (ht - text[i] * h) + text[i + p_len]) % 3571;
  if(ht < 0)
  {
   ht = ht + 3571;
  }
 }
 return 0;
}

canonical_original_code:
int rabin_karp(char text[], char pattern[])
{
 int t_len = strlen(text);
 int p_len = strlen(pattern);
 int i; int j;
 if(p_len > t_len)
 {
  return 0;
 }
 int h = 1;
 for (i = 0; i < p_len - 1; i++)
 {
             h = (h*256)%3571;
   }
 for(i = 0; i < p_len; i++)
 {
  if(pattern[i] != text[i])
  {
   break;
  }
 }
 if(i == p_len)
 {
  printf("found at %d\n", i - p_len);
  return 1;
 }
 int hp = 0;
 int ht = 0;
 for(i = 0; i < p_len; i++)
 {
  hp = (hp * 256 + pattern[i]) % 3571;
  ht = (ht * 256 + text[i]) % 3571;
 }
 for(i = 0; i < t_len; i++)
 {
  if(ht == hp)
  {
   for(j = 0; j < p_len; j++)
   {
    if(text[i + j] != pattern[j])
    {
     break;
    }
   }
   if(j == p_len)
   {
    printf("found at %d\n", i);
    return 1;
   }
  }
  ht = (256 * (ht - text[i] * h) + text[i + p_len]) % 3571;
  if(ht < 0)
  {
   ht = ht + 3571;
  }
 }
 return 0;
}

variable_types:
text
char []

variable_types:
pattern
char []

variable_types: i int

variable_types: j int

variable_types: h int

variable_types: hp int

variable_types: ht int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)rabin_karp(argv[1], argv[2], envp) == 1 )
puts("Pattern mathes text");
else
puts("Patter does not match text");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func7(argv[1], argv[2], envp) == 1 )
puts("Pattern mathes text");
else
puts("Patter does not match text");
return 0;
}

original_code:
int main(int argc, char * argv[])
{
 if(rabin_karp(argv[1], argv[2]) == 1)
 {
  printf("Pattern mathes text\n");
  return 0;
 }
 printf("Patter does not match text\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(rabin_karp(argv[1], argv[2]) == 1)
 {
  printf("Pattern mathes text\n");
  return 0;
 }
 printf("Patter does not match text\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall brute_force(const char *a1, const char *a2)
{
int v3; // er13
int v4; // eax
int v5; // er10
int v6; // er8
__int64 v7; // rsi
__int64 v8; // rax
int v9; // ecx

v3 = strlen(a1);
v4 = strlen(a2);
if ( v3 <= 0 )
return 0LL;
v5 = v4;
v6 = 0;
v7 = (unsigned int)(v4 - 1) + 1LL;
while ( 1 )
{
if ( v5 > 0 )
{
v8 = 1LL;
if ( v3 > v6 )
{
do
{
if ( a1[v8 - 1] != a2[v8 - 1] )
break;
v9 = v8;
if ( v8 == v7 )
goto LABEL_12;
++v8;
}
while ( v8 != (unsigned int)(v3 - 1 - v6) + 2LL );
}
goto LABEL_9;
}
v9 = 0;
LABEL_12:
if ( v5 == v9 )
return 1LL;
LABEL_9:
++v6;
++a1;
if ( v3 == v6 )
return 0LL;
}
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, const char *a2)
{
int v3; // er13
int v4; // eax
int v5; // er10
int v6; // er8
__int64 v7; // rsi
__int64 v8; // rax
int v9; // ecx

v3 = strlen(a1);
v4 = strlen(a2);
if ( v3 <= 0 )
return 0LL;
v5 = v4;
v6 = 0;
v7 = (unsigned int)(v4 - 1) + 1LL;
while ( 1 )
{
if ( v5 > 0 )
{
v8 = 1LL;
if ( v3 > v6 )
{
do
{
if ( a1[v8 - 1] != a2[v8 - 1] )
break;
v9 = v8;
if ( v8 == v7 )
goto LABEL_12;
++v8;
}
while ( v8 != (unsigned int)(v3 - 1 - v6) + 2LL );
}
goto LABEL_9;
}
v9 = 0;
LABEL_12:
if ( v5 == v9 )
return 1LL;
LABEL_9:
++v6;
++a1;
if ( v3 == v6 )
return 0LL;
}
}

original_code:
int brute_force(char text[], char pattern[])
{
 int t_len = strlen(text);
 int p_len = strlen(pattern);
 int i,j;
 for(i=0; i < t_len; i++) {
  for(j=0; j < p_len && i + j < t_len; j++) {
   if(text[i + j] != pattern[j]) {
    break;
   }
  }
  if(j == p_len) {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int brute_force(char text[], char pattern[])
{
 int t_len = strlen(text);
 int p_len = strlen(pattern);
 int i; int j;
 for(i=0; i < t_len; i++) {
  for(j=0; j < p_len && i + j < t_len; j++) {
   if(text[i + j] != pattern[j]) {
    break;
   }
  }
  if(j == p_len) {
   return 1;
  }
 }
 return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)brute_force(argv[1], argv[2], envp) == 1 )
puts("There is a match");
else
puts("The pattern is not present");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func7(argv[1], argv[2], envp) == 1 )
puts("There is a match");
else
puts("The pattern is not present");
return 0;
}

original_code:
int main(int argc, char * argv[])
{
 if(brute_force(argv[1], argv[2]) == 1) {
  printf("There is a match\n");
  return 0;
 }
 printf("The pattern is not present\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(brute_force(argv[1], argv[2]) == 1) {
  printf("There is a match\n");
  return 0;
 }
 printf("The pattern is not present\n");
 return 0;
}


repo: ismell/rxh

decompiled_code:
__int64 rxJobs_Initialize()
{
__int64 v0; // r12

v0 = xmalloc(24LL);
*(_QWORD *)v0 = 0x3FFFFFFFFLL;
*(_DWORD *)(v0 + 16) = 0;
*(_QWORD *)(v0 + 8) = xmalloc(24LL);
return v0;
}

original_code:
rxJobs *rxJobs_Initialize() {
 rxJobs *jobs = (rxJobs*)xmalloc(sizeof(rxJobs));
 jobs->i = -1;
 jobs->n = 3;
 jobs->cnt = 0;
 jobs->jobs = (rxJob**)xmalloc(sizeof(rxJob*)*jobs->n);
 return jobs;
}

canonical_original_code:
struct rxJobs *rxJobs_Initialize() {
 struct rxJobs *jobs = (rxJobs*)xmalloc(sizeof(rxJobs));
 jobs->i = -1;
 jobs->n = 3;
 jobs->cnt = 0;
 jobs->jobs = (struct rxJob **)xmalloc(sizeof(struct rxJob *)*jobs->n);
 return jobs;
}

variable_types: struct rxJobs { int i; int n; struct rxJob { int id; int pid; int status; int rtn; char *cmd; } **jobs; int cnt; } *

user_defined_types: struct rxJobs { int i; int n; struct rxJob **jobs; int cnt; }


original_code:
int rxJobs_Add(rxJobs *jobs, rxJob *job){
 if (!jobs || !job)
  return -1;
 if (jobs->i >= jobs->n-1) {
  if (0) fprintf(stderr, "Making jobs buffer bigger\n");
  jobs->n += 2;
  jobs->jobs = (rxJob**)xrealloc(jobs->jobs, sizeof(rxJob*)*jobs->n);
 }
 job->id = ++jobs->cnt;
 job->status = 1;
 jobs->jobs[++(jobs->i)] = job;
 printf("[%d] %d\n",job->id, job->pid);
 return 0;
}

canonical_original_code:
int rxJobs_Add(struct rxJobs *jobs, struct rxJob *job){
 if (!jobs || !job)
  return -1;
 if (jobs->i >= jobs->n-1) {
  if (0) fprintf(stderr, "Making jobs buffer bigger\n");
  jobs->n += 2;
  jobs->jobs = (struct rxJob **)xrealloc(jobs->jobs, sizeof(struct rxJob *)*jobs->n);
 }
 job->id = ++jobs->cnt;
 job->status = 1;
 jobs->jobs[++(jobs->i)] = job;
 printf("[%d] %d\n",job->id, job->pid);
 return 0;
}

variable_types:
job
struct rxJob *

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


decompiled_code:
int __fastcall rxJob_Print(unsigned int *a1)
{
const char *v1; // rdx
int result; // eax

if ( a1 )
{
v1 = "running";
if ( !a1[2] )
v1 = "done";
result = printf("[%d] %-10s %-10d %s\n", *a1, v1, a1[1], *((_QWORD *)a1 + 2));
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned int *a1)
{
const char *v1; // rdx
int result; // eax

if ( a1 )
{
v1 = "running";
if ( !a1[2] )
v1 = "done";
result = printf("[%d] %-10s %-10d %s\n", *a1, v1, a1[1], *((_QWORD *)a1 + 2));
}
return result;
}

original_code:
void rxJob_Print(rxJob *job) {
 char *status;
 if (!job)
  return;
 printf("[%d] %-10s %-10d %s\n", job->id, (job->status ? "running" : "done"), job->pid, job->cmd);
 return;
}

canonical_original_code:
void rxJob_Print(struct rxJob *job) {
 char *status;
 if (!job)
  return;
 printf("[%d] %-10s %-10d %s\n", job->id, (job->status ? "running" : "done"), job->pid, job->cmd);
 return;
}

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

variable_types:
status
char *


decompiled_code:
int __fastcall rxJobs_Print(__int64 a1)
{
int result; // eax
__int64 v3; // rbx
unsigned int *v4; // rdi

if ( a1 )
{
result = *(_DWORD *)a1;
if ( *(int *)a1 >= 0 )
{
v3 = 0LL;
do
{
v4 = *(unsigned int **)(*(_QWORD *)(a1 + 8) + 8 * v3++);
result = rxJob_Print(v4);
}
while ( *(_DWORD *)a1 >= (int)v3 );
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int result; // eax
__int64 v3; // rbx
unsigned int *v4; // rdi

if ( a1 )
{
result = *(_DWORD *)a1;
if ( *(int *)a1 >= 0 )
{
v3 = 0LL;
do
{
v4 = *(unsigned int **)(*(_QWORD *)(a1 + 8) + 8 * v3++);
result = func2(v4);
}
while ( *(_DWORD *)a1 >= (int)v3 );
}
}
return result;
}

original_code:
void rxJobs_Print(rxJobs *jobs) {
 int i;
 if (!jobs || jobs->i < 0)
  return;
 if (0) fprintf(stderr, "n: %d, i: %d\n", jobs->n, jobs->i);
 for (i = 0; i <= jobs->i; i++)
  rxJob_Print(jobs->jobs[i]);
 return;
}

canonical_original_code:
void rxJobs_Print(struct rxJobs *jobs) {
 int i;
 if (!jobs || jobs->i < 0)
  return;
 if (0) fprintf(stderr, "n: %d, i: %d\n", jobs->n, jobs->i);
 for (i = 0; i <= jobs->i; i++)
  rxJob_Print(jobs->jobs[i]);
 return;
}


original_code:
void rxJobs_Wait(rxJobs *jobs, int hang) {
 int i = 0, j;
 rxJob *job;
 if (0) fprintf(stderr, "n: %d, I: %d\n", jobs->n, jobs->i);
 if (!jobs || jobs->i < 0)
  return;
 for (i = 0; i <= jobs->i; i++) {
  job = jobs->jobs[i];
  if (0) fprintf(stderr, "   i: %d, I: %d, pid: %d\n", i, jobs->i, job->pid);
  if (job && waitpid(job->pid, &job->rtn, (hang ? 0 : 1))) {
   job->status = 0;
   rxJob_Print(job);
   free(job);
   if (jobs->i-i > 0) {
    if (0) fprintf(stderr, "shifting %d\n", jobs->i-i);
    for (j = i; j < jobs->i; j++) {
     jobs->jobs[j] = jobs->jobs[j+1];
    }
    i--;
   }
   jobs->i--;
  }
 }
 if (0) fprintf(stderr, "final: i) %d, I) %d\n", i, jobs->i);
 return;
}

canonical_original_code:
void rxJobs_Wait(struct rxJobs *jobs, int hang) {
 int i = 0; int j;
 struct rxJob *job;
 if (0) fprintf(stderr, "n: %d, I: %d\n", jobs->n, jobs->i);
 if (!jobs || jobs->i < 0)
  return;
 for (i = 0; i <= jobs->i; i++) {
  job = jobs->jobs[i];
  if (0) fprintf(stderr, "   i: %d, I: %d, pid: %d\n", i, jobs->i, job->pid);
  if (job && waitpid(job->pid, &job->rtn, (hang ? 0 : 1))) {
   job->status = 0;
   rxJob_Print(job);
   free(job);
   if (jobs->i-i > 0) {
    if (0) fprintf(stderr, "shifting %d\n", jobs->i-i);
    for (j = i; j < jobs->i; j++) {
     jobs->jobs[j] = jobs->jobs[j+1];
    }
    i--;
   }
   jobs->i--;
  }
 }
 if (0) fprintf(stderr, "final: i) %d, I) %d\n", i, jobs->i);
 return;
}

variable_types: hang int


decompiled_code:
__int64 __fastcall file_select(const struct dirent *a1)
{
__int64 result; // rax

if ( a1->d_name[0] != 46 || (result = (unsigned __int8)a1->d_name[1], a1->d_name[1]) )
{
if ( a1->d_name[0] != 46 || a1->d_name[1] != 46 || (result = (unsigned __int8)a1->d_name[2], a1->d_name[2]) )
result = access(a1->d_name, 1) == 0;
}
return result;
}

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

if ( a1->d_name[0] != 46 || (result = (unsigned __int8)a1->d_name[1], a1->d_name[1]) )
{
if ( a1->d_name[0] != 46 || a1->d_name[1] != 46 || (result = (unsigned __int8)a1->d_name[2], a1->d_name[2]) )
result = access(a1->d_name, 1) == 0;
}
return result;
}

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

canonical_original_code:
int file_select(struct dirent *entry) {
 if ((strcmp(entry->d_name, ".")== 0) || (strcmp(entry->d_name, "..") == 0))
  return (0);
 return !access(entry->d_name, 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:
const char *__fastcall command_generator(char *src, int a2)
{
__int64 v3; // r12
char *v4; // rbp
void *v5; // rdi
void **v6; // rbx
char *v7; // rax
unsigned __int64 v8; // rbx
char *v9; // r15
int v10; // er12
__int64 v11; // r13
struct dirent *v12; // r12
const char *v13; // r13
size_t v14; // r12
__int64 v15; // rbx
const char *v16; // rdi
const char *v17; // r15
size_t v19; // rax
char *v20; // rax
__int64 v21; // rbp
char *v22; // rbx
const char *v23; // rsi
void *v24; // rax
const char *v25; // rdi
_QWORD *v26; // rbp
__int64 v27; // rbx
__int64 v28; // rbx
char *v29; // rax
char *v30; // rdi
int v31; // eax
__int64 v32; // rbx
int v33; // ebp
__int64 v34; // rbx
unsigned __int64 v35; // r15
char *v36; // r12
struct dirent *v37; // r13
__int64 v38; // [rsp+0h] [rbp-58h]
int v39; // [rsp+0h] [rbp-58h]
char *ptr; // [rsp+8h] [rbp-50h]
struct dirent **namelist[8]; // [rsp+18h] [rbp-40h] BYREF

v3 = a2;
v4 = (char *)cmds_3;
namelist[0] = 0LL;
if ( a2 )
{
v14 = len_2;
v38 = offset_4;
v13 = &src[offset_4];
}
else
{
list_index_5 = 0;
offset_4 = 0;
if ( cmds_3 )
{
v5 = *(void **)cmds_3;
v6 = (void **)((char *)cmds_3 + 8);
if ( *(_QWORD *)cmds_3 )
{
do
{
free(v5);
v5 = *v6++;
}
while ( v5 );
}
free(v4);
}
v7 = rindex(src, 47);
if ( v7 )
{
v8 = 0LL;
offset_4 = (_DWORD)v7 - (_DWORD)src + 1;
v9 = (char *)xcalloc(offset_4, 1LL);
strncpy(v9, src, offset_4 - 1);
v10 = scandir(
v9,
namelist,
(int (*)(const struct dirent *))file_select,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v11 = 8LL * v10;
cmds_3 = (void *)xcalloc(v10 + 1, 8LL);
v4 = (char *)cmds_3;
if ( v10 > 0 )
{
do
{
v12 = namelist[0][v8 / 8];
*(_QWORD *)&v4[v8] = strdup(v12->d_name);
v8 += 8LL;
free(v12);
}
while ( v11 != v8 );
}
free(namelist[0]);
free(v9);
}
else
{
v24 = (void *)xmalloc(12000LL);
v25 = commands;
cmds_3 = v24;
v26 = v24;
if ( commands )
{
v27 = 1LL;
do
{
v3 = (int)v27;
v26[v27++ - 1] = strdup(v25);
v25 = (&commands)[3 * v27 - 3];
}
while ( v25 );
v28 = 8LL * (int)v3;
}
else
{
v28 = 0LL;
}
v29 = getenv("PATH");
ptr = strdup(v29);
v30 = strtok(ptr, ":");
if ( v30 )
{
v39 = 1500;
do
{
v31 = scandir(v30, namelist, 0LL, (int (*)(const struct dirent **, const struct dirent **))&alphasort);
v32 = v31;
if ( v31 >= 0 )
{
v33 = v31 + v3;
if ( v31 + (int)v3 >= v39 )
{
v39 += 2 * v31;
cmds_3 = (void *)xrealloc(cmds_3, 8LL * v39);
}
if ( (_DWORD)v32 )
{
v34 = 8 * v32;
v35 = 0LL;
v36 = (char *)cmds_3 + 8 * v3;
do
{
v37 = namelist[0][v35 / 8];
*(_QWORD *)&v36[v35] = strdup(v37->d_name);
v35 += 8LL;
free(v37);
}
while ( v34 != v35 );
}
else
{
v33 = v3;
}
v3 = v33;
free(namelist[0]);
}
v30 = strtok(0LL, ":");
}
while ( v30 );
v26 = cmds_3;
v28 = 8LL * (int)v3;
}
free(ptr);
cmds_3 = (void *)xrealloc(v26, v28);
v4 = (char *)cmds_3;
*(_QWORD *)((char *)cmds_3 + v28 - 8) = 0LL;
}
v13 = &src[offset_4];
v38 = offset_4;
len_2 = strlen(v13);
v14 = len_2;
}
v15 = list_index_5 + 1;
while ( 1 )
{
v17 = *(const char **)&v4[8 * v15 - 8];
if ( !v17 )
break;
v16 = *(const char **)&v4[8 * v15 - 8];
list_index_5 = v15++;
if ( !strncmp(v16, v13, v14) )
{
v19 = strlen(v17);
v20 = (char *)xcalloc(v38 + v19 + 1, 1LL);
v21 = offset_4;
v22 = v20;
strncpy(v20, src, offset_4);
v23 = v17;
v17 = v22;
strcpy(&v22[v21], v23);
return v17;
}
}
return v17;
}

canonical_decompiled_code:
const char *__fastcall func1(char *src, int a2)
{
__int64 v3; // r12
char *v4; // rbp
void *v5; // rdi
void **v6; // rbx
char *v7; // rax
unsigned __int64 v8; // rbx
char *v9; // r15
int v10; // er12
__int64 v11; // r13
struct dirent *v12; // r12
const char *v13; // r13
size_t v14; // r12
__int64 v15; // rbx
const char *v16; // rdi
const char *v17; // r15
size_t v19; // rax
char *v20; // rax
__int64 v21; // rbp
char *v22; // rbx
const char *v23; // rsi
void *v24; // rax
const char *v25; // rdi
_QWORD *v26; // rbp
__int64 v27; // rbx
__int64 v28; // rbx
char *v29; // rax
char *v30; // rdi
int v31; // eax
__int64 v32; // rbx
int v33; // ebp
__int64 v34; // rbx
unsigned __int64 v35; // r15
char *v36; // r12
struct dirent *v37; // r13
__int64 v38; // [rsp+0h] [rbp-58h]
int v39; // [rsp+0h] [rbp-58h]
char *ptr; // [rsp+8h] [rbp-50h]
struct dirent **namelist[8]; // [rsp+18h] [rbp-40h] BYREF

v3 = a2;
v4 = (char *)cmds_3;
namelist[0] = 0LL;
if ( a2 )
{
v14 = len_2;
v38 = offset_4;
v13 = &src[offset_4];
}
else
{
list_index_5 = 0;
offset_4 = 0;
if ( cmds_3 )
{
v5 = *(void **)cmds_3;
v6 = (void **)((char *)cmds_3 + 8);
if ( *(_QWORD *)cmds_3 )
{
do
{
free(v5);
v5 = *v6++;
}
while ( v5 );
}
free(v4);
}
v7 = rindex(src, 47);
if ( v7 )
{
v8 = 0LL;
offset_4 = (_DWORD)v7 - (_DWORD)src + 1;
v9 = (char *)xcalloc(offset_4, 1LL);
strncpy(v9, src, offset_4 - 1);
v10 = scandir(
v9,
namelist,
(int (*)(const struct dirent *))file_select,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v11 = 8LL * v10;
cmds_3 = (void *)xcalloc(v10 + 1, 8LL);
v4 = (char *)cmds_3;
if ( v10 > 0 )
{
do
{
v12 = namelist[0][v8 / 8];
*(_QWORD *)&v4[v8] = strdup(v12->d_name);
v8 += 8LL;
free(v12);
}
while ( v11 != v8 );
}
free(namelist[0]);
free(v9);
}
else
{
v24 = (void *)xmalloc(12000LL);
v25 = commands;
cmds_3 = v24;
v26 = v24;
if ( commands )
{
v27 = 1LL;
do
{
v3 = (int)v27;
v26[v27++ - 1] = strdup(v25);
v25 = (&commands)[3 * v27 - 3];
}
while ( v25 );
v28 = 8LL * (int)v3;
}
else
{
v28 = 0LL;
}
v29 = getenv("PATH");
ptr = strdup(v29);
v30 = strtok(ptr, ":");
if ( v30 )
{
v39 = 1500;
do
{
v31 = scandir(v30, namelist, 0LL, (int (*)(const struct dirent **, const struct dirent **))&alphasort);
v32 = v31;
if ( v31 >= 0 )
{
v33 = v31 + v3;
if ( v31 + (int)v3 >= v39 )
{
v39 += 2 * v31;
cmds_3 = (void *)xrealloc(cmds_3, 8LL * v39);
}
if ( (_DWORD)v32 )
{
v34 = 8 * v32;
v35 = 0LL;
v36 = (char *)cmds_3 + 8 * v3;
do
{
v37 = namelist[0][v35 / 8];
*(_QWORD *)&v36[v35] = strdup(v37->d_name);
v35 += 8LL;
free(v37);
}
while ( v34 != v35 );
}
else
{
v33 = v3;
}
v3 = v33;
free(namelist[0]);
}
v30 = strtok(0LL, ":");
}
while ( v30 );
v26 = cmds_3;
v28 = 8LL * (int)v3;
}
free(ptr);
cmds_3 = (void *)xrealloc(v26, v28);
v4 = (char *)cmds_3;
*(_QWORD *)((char *)cmds_3 + v28 - 8) = 0LL;
}
v13 = &src[offset_4];
v38 = offset_4;
len_2 = strlen(v13);
v14 = len_2;
}
v15 = list_index_5 + 1;
while ( 1 )
{
v17 = *(const char **)&v4[8 * v15 - 8];
if ( !v17 )
break;
v16 = *(const char **)&v4[8 * v15 - 8];
list_index_5 = v15++;
if ( !strncmp(v16, v13, v14) )
{
v19 = strlen(v17);
v20 = (char *)xcalloc(v38 + v19 + 1, 1LL);
v21 = offset_4;
v22 = v20;
strncpy(v20, src, offset_4);
v23 = v17;
v17 = v22;
strcpy(&v22[v21], v23);
return v17;
}
}
return v17;
}

original_code:
char * command_generator (const char *text, int state) {
 static int list_index, len, offset;
 static char **cmds = ((void *)0);
 struct dirent **files = ((void *)0);
 char *name, *tmp, *cwd;
 int i, j, count, n;
 if (!state) {
  list_index = 0;
  offset = 0;
  if (cmds != ((void *)0)) {
   for (i = 0; cmds[i] != ((void *)0); i++)
    free(cmds[i]);
   free(cmds);
  }
  tmp = rindex(text,'/');
  if (tmp != ((void *)0)) {
   offset = tmp-text+1;
   cwd = xcalloc(offset, sizeof(char));
   strncpy(cwd, text, offset-1);
   count = scandir(cwd, &files, file_select, alphasort);
   cmds = (char**)xcalloc(count+1, sizeof(char*));
   for (i = 0; i < count; i++) {
    cmds[i] = strdup(files[i]->d_name);
    free(files[i]);
   }
   free(files);
   free(cwd);
  } else {
   n = 1500;
   cmds = (char**)xmalloc(sizeof(char*)*n);
   for (i = 0; commands[i].name != ((void *)0); i++) {
    cmds[i] = strdup(commands[i].name);
   }
   tmp = strdup(getenv("PATH"));
   cwd = strtok(tmp , ":");
   while( cwd != ((void *)0) ) {
    count = scandir(cwd, &files, 0, alphasort);
    if (count < 0) {
    } else {
     if (count + i >= n) {
      n = n + count*2;
      cmds = xrealloc(cmds, sizeof(char*)*n);
     }
     for (j = 0; j < count; j++) {
      cmds[i++] = strdup(files[j]->d_name);
      free(files[j]);
     }
     free(files);
    }
    cwd = strtok( ((void *)0), ":");
   }
   free(tmp);
   n = i;
   cmds = xrealloc(cmds, sizeof(char*)*n);
   cmds[n-1] = ((void *)0);
  }
  len = strlen (text+offset);
 }
 while (name = cmds[list_index]) {
  list_index++;
  if (strncmp (name, text+offset, len) == 0) {
   tmp = xcalloc(offset+strlen(name)+1, sizeof(char));
   strncpy(tmp, text, offset);
   strcpy(tmp+offset, name);
   return tmp;
  }
 }
 return ((char *)((void *)0));
}

canonical_original_code:
char *command_generator(char *text, int state) {
 static int list_index; static int len; static int offset;
 static char **cmds = ((void *)0);
 struct dirent **files = ((void *)0);
 char *name; char *tmp; char *cwd;
 int i; int j; int count; int n;
 if (!state) {
  list_index = 0;
  offset = 0;
  if (cmds != ((void *)0)) {
   for (i = 0; cmds[i] != ((void *)0); i++)
    free(cmds[i]);
   free(cmds);
  }
  tmp = rindex(text,'/');
  if (tmp != ((void *)0)) {
   offset = tmp-text+1;
   cwd = xcalloc(offset, sizeof(char));
   strncpy(cwd, text, offset-1);
   count = scandir(cwd, &files, file_select, alphasort);
   cmds = (char **)xcalloc(count+1, sizeof(char *));
   for (i = 0; i < count; i++) {
    cmds[i] = strdup(files[i]->d_name);
    free(files[i]);
   }
   free(files);
   free(cwd);
  } else {
   n = 1500;
   cmds = (char **)xmalloc(sizeof(char *)*n);
   for (i = 0; commands[i].name != ((void *)0); i++) {
    cmds[i] = strdup(commands[i].name);
   }
   tmp = strdup(getenv("PATH"));
   cwd = strtok(tmp , ":");
   while( cwd != ((void *)0) ) {
    count = scandir(cwd, &files, 0, alphasort);
    if (count < 0) {
    } else {
     if (count + i >= n) {
      n = n + count*2;
      cmds = xrealloc(cmds, sizeof(char *)*n);
     }
     for (j = 0; j < count; j++) {
      cmds[i++] = strdup(files[j]->d_name);
      free(files[j]);
     }
     free(files);
    }
    cwd = strtok( ((void *)0), ":");
   }
   free(tmp);
   n = i;
   cmds = xrealloc(cmds, sizeof(char *)*n);
   cmds[n-1] = ((void *)0);
  }
  len = strlen (text+offset);
 }
 while (name = cmds[list_index]) {
  list_index++;
  if (strncmp (name, text+offset, len) == 0) {
   tmp = xcalloc(offset+strlen(name)+1, sizeof(char));
   strncpy(tmp, text, offset);
   strcpy(tmp+offset, name);
   return tmp;
  }
 }
 return ((char *)((void *)0));
}

variable_types:
text
char *

variable_types: state int

variable_types: len int

variable_types: offset int

variable_types:
cmds
char **

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:
name
char *

variable_types:
tmp
char *

variable_types:
cwd
char *

variable_types: count int

variable_types: n int


decompiled_code:
char *__fastcall environment_generator(char *s2, int a2)
{
int v2; // ebx
__int64 v3; // rdx
char **v4; // rax
const char *v5; // rbx
char *v6; // r12
__int64 v7; // rax
__int64 v8; // r14
char *v9; // rbp
const char *v10; // rsi
int v12; // eax

if ( a2 )
{
v2 = list_index_1;
v3 = list_index_1;
}
else
{
list_index_1 = 0;
v2 = 0;
v12 = strlen(s2);
v3 = 0LL;
len_0 = v12;
}
v4 = environ;
if ( !environ[v3] )
return 0LL;
while ( 1 )
{
list_index_1 = v2 + 1;
v5 = v4[v2];
v6 = strchr(v5, 61);
v7 = xcalloc(v6 - v5 + 2, 1LL);
v8 = list_index_1;
v9 = (char *)v7;
v2 = list_index_1;
v10 = environ[list_index_1 - 1];
strncpy((char *)(v7 + 1), v10, v6 - v10);
*v9 = 36;
if ( !strncmp(v9, s2, len_0) )
break;
free(v9);
v4 = environ;
if ( !environ[v8] )
return 0LL;
}
return v9;
}

canonical_decompiled_code:
char *__fastcall func2(char *s2, int a2)
{
int v2; // ebx
__int64 v3; // rdx
char **v4; // rax
const char *v5; // rbx
char *v6; // r12
__int64 v7; // rax
__int64 v8; // r14
char *v9; // rbp
const char *v10; // rsi
int v12; // eax

if ( a2 )
{
v2 = list_index_1;
v3 = list_index_1;
}
else
{
list_index_1 = 0;
v2 = 0;
v12 = strlen(s2);
v3 = 0LL;
len_0 = v12;
}
v4 = environ;
if ( !environ[v3] )
return 0LL;
while ( 1 )
{
list_index_1 = v2 + 1;
v5 = v4[v2];
v6 = strchr(v5, 61);
v7 = xcalloc(v6 - v5 + 2, 1LL);
v8 = list_index_1;
v9 = (char *)v7;
v2 = list_index_1;
v10 = environ[list_index_1 - 1];
strncpy((char *)(v7 + 1), v10, v6 - v10);
*v9 = 36;
if ( !strncmp(v9, s2, len_0) )
break;
free(v9);
v4 = environ;
if ( !environ[v8] )
return 0LL;
}
return v9;
}

original_code:
char *environment_generator (const char *text, int state) {
 static int list_index, len, envlen;
 char *tmp, *env;
 if (!state) {
  list_index = 0;
  len = strlen (text);
 }
 while (environ[list_index] != ((void *)0)) {
  list_index++;
  tmp = strstr(environ[list_index-1],"=");
  env = xcalloc(tmp - environ[list_index-1] +2, sizeof(char));
  strncpy(env+1, environ[list_index-1], tmp - environ[list_index-1]);
  *env = '$';
  if (strncmp (env, text, len) == 0)
   return env;
  free(env);
 }
 return ((char *)((void *)0));
}

canonical_original_code:
char *environment_generator(char *text, int state) {
 static int list_index; static int len; static int envlen;
 char *tmp; char *env;
 if (!state) {
  list_index = 0;
  len = strlen (text);
 }
 while (environ[list_index] != ((void *)0)) {
  list_index++;
  tmp = strstr(environ[list_index-1],"=");
  env = xcalloc(tmp - environ[list_index-1] +2, sizeof(char));
  strncpy(env+1, environ[list_index-1], tmp - environ[list_index-1]);
  *env = '$';
  if (strncmp (env, text, len) == 0)
   return env;
  free(env);
 }
 return ((char *)((void *)0));
}

variable_types: envlen int

variable_types:
env
char *


decompiled_code:
__int64 __fastcall command_completion(_BYTE *a1, int a2, int a3)
{
__int64 v3; // rax
__int64 result; // rax

v3 = charrpos(rl_line_buffer, "|`", (unsigned int)(a3 - a2));
if ( !a2 || v3 )
{
rl_completion_append_character = 32;
result = rl_completion_matches(a1, command_generator);
}
else if ( *a1 == 36 )
{
rl_completion_append_character = 32;
result = rl_completion_matches(a1, environment_generator);
}
else
{
result = 0LL;
}
return result;
}

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

v3 = charrpos(rl_line_buffer, "|`", (unsigned int)(a3 - a2));
if ( !a2 || v3 )
{
rl_completion_append_character = 32;
result = rl_completion_matches(a1, command_generator);
}
else if ( *a1 == 36 )
{
rl_completion_append_character = 32;
result = rl_completion_matches(a1, environment_generator);
}
else
{
result = 0LL;
}
return result;
}

original_code:
char **command_completion(const char *text, int start, int stop) {
 char **matches = ((void *)0), *cmdSplit;
     cmdSplit = charrpos(rl_line_buffer, "|`", stop-start);
    if (start == 0 || cmdSplit) {
        rl_completion_append_character = ' ';
        matches = rl_completion_matches(text, command_generator);
    } else if (*text == '$') {
        rl_completion_append_character = ' ';
        matches = rl_completion_matches(text, environment_generator);
    }
    return (matches);
}

canonical_original_code:
char **command_completion(char *text, int start, int stop) {
 char **matches = ((void *)0); char *cmdSplit;
     cmdSplit = charrpos(rl_line_buffer, "|`", stop-start);
    if (start == 0 || cmdSplit) {
        rl_completion_append_character = ' ';
        matches = rl_completion_matches(text, command_generator);
    } else if (*text == '$') {
        rl_completion_append_character = ' ';
        matches = rl_completion_matches(text, environment_generator);
    }
    return (matches);
}

variable_types: start int

variable_types: stop int

variable_types:
matches
char **

variable_types:
cmdSplit
char *

return_type: char **


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

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

canonical_decompiled_code:
char **__fastcall func4(char *s1)
{
const char *v1; // rsi
__int64 v2; // rbp
const char **v3; // rbx

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

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


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

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


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
void *v4; // rbp
const char *v5; // rax
const char *v6; // r12
_QWORD *v7; // rax
_QWORD *v8; // r14
__int64 v9; // rbx
int v10; // er15
__int64 *v11; // r13
char **v12; // rax
_BYTE *v13; // rdi
__int64 v14; // rbx
__int64 v15; // rax
__int64 v16; // r13
int v17; // eax
int v18; // eax

initialize_readline();
jobs = rxJobs_Initialize(argc, argv);
if ( !setenv("PS1", "\x1B[01;31m$USER \x1B[01;34m$PWD $EMO\x1B[01;34m#\x1B[22;37m ", 1) )
{
while ( 1 )
{
v3 = getenv("PS1");
v4 = (void *)rxExpandVars(v3);
rxJobs_Wait(jobs, 0LL);
v5 = rl_gets((__int64)v4);
v6 = v5;
if ( !v5 )
break;
if ( *v5 )
{
v7 = (_QWORD *)rxParse(v5);
lastrtn = -1;
v8 = v7;
if ( !v7 )
goto LABEL_7;
v9 = *v7;
if ( !*v7 )
goto LABEL_21;
v10 = 0;
v11 = v7;
do
{
v12 = find_command(**(char ***)(v9 + 8));
if ( v12 )
*(_QWORD *)(v9 + 32) = v12[1];
v13 = *(_BYTE **)(v9 + 40);
if ( *v13 == 38 && !v13[1] )
{
free(v13);
v14 = *v11;
v10 = 1;
*(_QWORD *)(v14 + 40) = strdup(&s);
}
v9 = v11[1];
++v11;
}
while ( v9 );
if ( v10 )
{
v15 = xmalloc(24LL);
*(_DWORD *)(v15 + 8) = 1;
v16 = v15;
*(_QWORD *)(v15 + 16) = strdup(v6);
v17 = xfork();
*(_DWORD *)(v16 + 4) = v17;
if ( !v17 )
{
v18 = rxCmd_Execute(v8);
exit(v18);
}
rxJobs_Add(jobs, v16);
lastrtn = 0;
}
else
{
LABEL_21:
lastrtn = rxCmd_Execute(v8);
}
loopArray(v8, &rxCmd_Free);
if ( lastrtn )
LABEL_7:
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; // rbp
const char *v5; // rax
const char *v6; // r12
_QWORD *v7; // rax
_QWORD *v8; // r14
__int64 v9; // rbx
int v10; // er15
__int64 *v11; // r13
char **v12; // rax
_BYTE *v13; // rdi
__int64 v14; // rbx
__int64 v15; // rax
__int64 v16; // r13
int v17; // eax
int v18; // eax

func5();
jobs = rxJobs_Initialize(argc, argv);
if ( !setenv("PS1", "\x1B[01;31m$USER \x1B[01;34m$PWD $EMO\x1B[01;34m#\x1B[22;37m ", 1) )
{
while ( 1 )
{
v3 = getenv("PS1");
v4 = (void *)rxExpandVars(v3);
rxJobs_Wait(jobs, 0LL);
v5 = rl_gets((__int64)v4);
v6 = v5;
if ( !v5 )
break;
if ( *v5 )
{
v7 = (_QWORD *)rxParse(v5);
lastrtn = -1;
v8 = v7;
if ( !v7 )
goto LABEL_7;
v9 = *v7;
if ( !*v7 )
goto LABEL_21;
v10 = 0;
v11 = v7;
do
{
v12 = func4(**(char ***)(v9 + 8));
if ( v12 )
*(_QWORD *)(v9 + 32) = v12[1];
v13 = *(_BYTE **)(v9 + 40);
if ( *v13 == 38 && !v13[1] )
{
free(v13);
v14 = *v11;
v10 = 1;
*(_QWORD *)(v14 + 40) = strdup(&s);
}
v9 = v11[1];
++v11;
}
while ( v9 );
if ( v10 )
{
v15 = xmalloc(24LL);
*(_DWORD *)(v15 + 8) = 1;
v16 = v15;
*(_QWORD *)(v15 + 16) = strdup(v6);
v17 = xfork();
*(_DWORD *)(v16 + 4) = v17;
if ( !v17 )
{
v18 = rxCmd_Execute(v8);
exit(v18);
}
rxJobs_Add(jobs, v16);
lastrtn = 0;
}
else
{
LABEL_21:
lastrtn = rxCmd_Execute(v8);
}
loopArray(v8, &rxCmd_Free);
if ( lastrtn )
LABEL_7:
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 *


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 *


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 *result; // rax

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

canonical_decompiled_code:
char *func7()
{
char *result; // rax

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

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 *


printString

decompiled_code:
// attributes: thunk
int printString(const char *s)
{
return puts(s);
}

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

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:
__int64 __fastcall ls_file_select(const struct dirent *a1)
{
__int64 result; // rax
int v2; // eax

if ( a1->d_name[0] != 46 || (result = (unsigned __int8)a1->d_name[1], a1->d_name[1]) )
{
v2 = (unsigned __int8)a1->d_name[0] - 46;
if ( a1->d_name[0] == 46 && (v2 = (unsigned __int8)a1->d_name[1] - 46, a1->d_name[1] == 46) )
result = a1->d_name[2] != 0;
else
result = v2 != 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const struct dirent *a1)
{
__int64 result; // rax
int v2; // eax

if ( a1->d_name[0] != 46 || (result = (unsigned __int8)a1->d_name[1], a1->d_name[1]) )
{
v2 = (unsigned __int8)a1->d_name[0] - 46;
if ( a1->d_name[0] == 46 && (v2 = (unsigned __int8)a1->d_name[1] - 46, a1->d_name[1] == 46) )
result = a1->d_name[2] != 0;
else
result = v2 != 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)
{
char *v1; // rdi
char *v2; // rbp
__int64 result; // rax

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

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

if ( a1 && *a1 )
{
v1 = (char *)a1[1];
if ( (v1 || (v1 = getenv("HOME")) != 0LL) && chdir(v1) == -1 )
{
perror("chdir");
result = (unsigned int)*_errno_location();
}
else
{
v2 = (char *)xgetcwd();
setenv("PWD", v2, 1);
free(v2);
result = 0LL;
}
}
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
unsigned int v2; // er14
const char **v3; // r12
const char *v4; // rdi
int v5; // er13
int v6; // eax
__int64 v7; // rbp
__int64 v8; // rbp
__int64 v9; // rbx
void *v10; // rdi
void *ptr; // [rsp+0h] [rbp-58h] BYREF
char v13[8]; // [rsp+8h] [rbp-50h] BYREF
char v14; // [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 = &v14;
v2 = 0;
ptr = 0LL;
v3 = (const char **)(v1 + 8);
ioctl(1, 0x5413uLL, v13);
v4 = (const char *)*((_QWORD *)v1 + 1);
if ( v4 )
{
v5 = 1;
do
{
v6 = scandir(
v4,
(struct dirent ***)&ptr,
(int (*)(const struct dirent *))ls_file_select,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v7 = v6;
if ( v6 == -1 )
{
v2 = -1;
perror("scandir");
}
else
{
if ( v5 != 1 )
putchar(10);
printf("%s:\n", *v3);
if ( (int)v7 > 0 )
{
v8 = 8 * v7;
v9 = 0LL;
do
{
puts((const char *)(*(_QWORD *)((char *)ptr + v9) + 19LL));
v10 = *(void **)((char *)ptr + v9);
v9 += 8LL;
free(v10);
}
while ( v8 != v9 );
}
free(ptr);
}
v4 = v3[1];
++v3;
++v5;
}
while ( v4 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char *v1; // rbx
unsigned int v2; // er14
const char **v3; // r12
const char *v4; // rdi
int v5; // er13
int v6; // eax
__int64 v7; // rbp
__int64 v8; // rbp
__int64 v9; // rbx
void *v10; // rdi
void *ptr; // [rsp+0h] [rbp-58h] BYREF
char v13[8]; // [rsp+8h] [rbp-50h] BYREF
char v14; // [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 = &v14;
v2 = 0;
ptr = 0LL;
v3 = (const char **)(v1 + 8);
ioctl(1, 0x5413uLL, v13);
v4 = (const char *)*((_QWORD *)v1 + 1);
if ( v4 )
{
v5 = 1;
do
{
v6 = scandir(
v4,
(struct dirent ***)&ptr,
(int (*)(const struct dirent *))ls_file_select,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v7 = v6;
if ( v6 == -1 )
{
v2 = -1;
perror("scandir");
}
else
{
if ( v5 != 1 )
putchar(10);
printf("%s:\n", *v3);
if ( (int)v7 > 0 )
{
v8 = 8 * v7;
v9 = 0LL;
do
{
puts((const char *)(*(_QWORD *)((char *)ptr + v9) + 19LL));
v10 = *(void **)((char *)ptr + v9);
v9 += 8LL;
free(v10);
}
while ( v8 != v9 );
}
free(ptr);
}
v4 = v3[1];
++v3;
++v5;
}
while ( v4 );
}
return v2;
}

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


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; // r12
const char *v2; // rbp
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; // r12
const char *v2; // rbp
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
char v9; // cl
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 ( 1 )
{
v9 = *v7;
v10 = a2 + 1;
v11 = v6;
if ( v6 )
break;
LABEL_10:
if ( v9 == 32 && --v7 != (const char *)v8 )
continue;
return 0LL;
}
while ( v11 != v9 )
{
v11 = *v10++;
if ( !v11 )
goto LABEL_10;
}
return v7;
}

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
char v9; // cl
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 ( 1 )
{
v9 = *v7;
v10 = a2 + 1;
v11 = v6;
if ( v6 )
break;
LABEL_10:
if ( v9 == 32 && --v7 != (const char *)v8 )
continue;
return 0LL;
}
while ( v11 != v9 )
{
v11 = *v10++;
if ( !v11 )
goto LABEL_10;
}
return v7;
}

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 == (char *)&unk_402004 || v3 == "--help" )
{
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()
{
struct timeval v1; // [rsp+0h] [rbp-D8h] BYREF
struct termios termios_p; // [rsp+10h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+50h] [rbp-88h] BYREF

*(_QWORD *)&termios_p.c_cc[31] = *(_QWORD *)&init_tio.c_cc[31];
*(__m128i *)&termios_p.c_iflag = _mm_load_si128((const __m128i *)&init_tio);
termios_p.c_ospeed = init_tio.c_ospeed;
termios_p.c_lflag &= 0xFFFFFFFD;
*(__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]);
tcsetattr(0, 0, &termios_p);
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[0] |= 1uLL;
v1.tv_usec = 0LL;
v1.tv_sec = 0LL;
select(1, &readfds, 0LL, 0LL, &v1);
tcsetattr(0, 0, &init_tio);
return readfds.fds_bits[0] & 1;
}

canonical_decompiled_code:
__int64 func2()
{
struct timeval v1; // [rsp+0h] [rbp-D8h] BYREF
struct termios termios_p; // [rsp+10h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+50h] [rbp-88h] BYREF

*(_QWORD *)&termios_p.c_cc[31] = *(_QWORD *)&init_tio.c_cc[31];
*(__m128i *)&termios_p.c_iflag = _mm_load_si128((const __m128i *)&init_tio);
termios_p.c_ospeed = init_tio.c_ospeed;
termios_p.c_lflag &= 0xFFFFFFFD;
*(__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]);
tcsetattr(0, 0, &termios_p);
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[0] |= 1uLL;
v1.tv_usec = 0LL;
v1.tv_sec = 0LL;
select(1, &readfds, 0LL, 0LL, &v1);
tcsetattr(0, 0, &init_tio);
return readfds.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()
{
unsigned int buf; // [rsp+Ch] [rbp-4Ch] BYREF
struct termios termios_p; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&termios_p.c_cc[31] = *(_QWORD *)&init_tio.c_cc[31];
*(__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]);
termios_p.c_lflag &= 0xFFFFFFF5;
termios_p.c_ospeed = init_tio.c_ospeed;
tcsetattr(0, 0, &termios_p);
read(0, &buf, 1uLL);
tcsetattr(0, 0, &init_tio);
return buf;
}

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

*(_QWORD *)&termios_p.c_cc[31] = *(_QWORD *)&init_tio.c_cc[31];
*(__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]);
termios_p.c_lflag &= 0xFFFFFFF5;
termios_p.c_ospeed = init_tio.c_ospeed;
tcsetattr(0, 0, &termios_p);
read(0, &buf, 1uLL);
tcsetattr(0, 0, &init_tio);
return buf;
}

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; // er8
__int64 result; // rax

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

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

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

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 v3; // er12
__int64 v5; // rdi

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

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:
// attributes: thunk
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, __m128i a3)
{
unsigned __int8 v3; // al
float v5; // ebx
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm0_8
double v9; // xmm0_8
unsigned __int8 v10; // r12
unsigned __int8 v11; // al
float v12; // [rsp+0h] [rbp-28h]
float v13; // [rsp+4h] [rbp-24h]
float v14; // [rsp+8h] [rbp-20h]
float v15; // [rsp+Ch] [rbp-1Ch]

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

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2, __m128i a3)
{
unsigned __int8 v3; // al
float v5; // ebx
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm0_8
double v9; // xmm0_8
unsigned __int8 v10; // r12
unsigned __int8 v11; // al
float v12; // [rsp+0h] [rbp-28h]
float v13; // [rsp+4h] [rbp-24h]
float v14; // [rsp+8h] [rbp-20h]
float v15; // [rsp+Ch] [rbp-1Ch]

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

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