repo: loadletter/gtk-tox

decompiled_code:
char *get_user_config_dir()
{
__uid_t v0; // eax
char *v1; // r13
char *v2; // r12
char *v4; // rax
size_t v5; // rbp
char *v6; // rax
struct passwd *result; // [rsp+8h] [rbp-450h] BYREF
struct passwd resultbuf; // [rsp+10h] [rbp-448h] BYREF
char buffer[1048]; // [rsp+40h] [rbp-418h] BYREF

v0 = getuid();
if ( getpwuid_r(v0, &resultbuf, buffer, 0x400uLL, &result) )
{
v4 = getenv("HOME");
v2 = v4;
if ( !v4 )
return v2;
v1 = buffer;
snprintf(buffer, 0x400uLL, "%s", v4);
}
else
{
v1 = resultbuf.pw_dir;
}
v2 = getenv("XDG_CONFIG_HOME");
if ( v2 )
return v2;
v5 = strlen(v1) + 9;
v6 = (char *)malloc(v5);
v2 = v6;
if ( !v6 )
return v2;
snprintf(v6, v5, "%s/.config", v1);
return v2;
}

canonical_decompiled_code:
char *func0()
{
__uid_t v0; // eax
char *v1; // r13
char *v2; // r12
char *v4; // rax
size_t v5; // rbp
char *v6; // rax
struct passwd *result; // [rsp+8h] [rbp-450h] BYREF
struct passwd resultbuf; // [rsp+10h] [rbp-448h] BYREF
char buffer[1048]; // [rsp+40h] [rbp-418h] BYREF

v0 = getuid();
if ( getpwuid_r(v0, &resultbuf, buffer, 0x400uLL, &result) )
{
v4 = getenv("HOME");
v2 = v4;
if ( !v4 )
return v2;
v1 = buffer;
snprintf(buffer, 0x400uLL, "%s", v4);
}
else
{
v1 = resultbuf.pw_dir;
}
v2 = getenv("XDG_CONFIG_HOME");
if ( v2 )
return v2;
v5 = strlen(v1) + 9;
v6 = (char *)malloc(v5);
v2 = v6;
if ( !v6 )
return v2;
snprintf(v6, v5, "%s/.config", v1);
return v2;
}

original_code:
char *get_user_config_dir(void)
{
    char *user_config_dir;
    struct passwd pwd;
    struct passwd *pwdbuf;
    const char *home;
    char buf[1024];
    size_t len;
    int rc;
    rc = getpwuid_r(getuid(), &pwd, buf, 1024, &pwdbuf);
    if (rc == 0) {
        home = pwd.pw_dir;
    } else {
        home = getenv("HOME");
        if (home == ((void *)0)) {
            return ((void *)0);
        }
        snprintf(buf, sizeof(buf), "%s", home);
        home = buf;
    }
    if (!(user_config_dir = getenv("XDG_CONFIG_HOME"))) {
        len = strlen(home) + strlen("/.config") + 1;
        user_config_dir = malloc(len);
        if (user_config_dir == ((void *)0)) {
            return ((void *)0);
        }
        snprintf(user_config_dir, len, "%s/.config", home);
    }
    return user_config_dir;
}

canonical_original_code:
char *get_user_config_dir()
{
    char *user_config_dir;
    struct passwd pwd;
    struct passwd *pwdbuf;
    char *home;
    char buf[1024];
    unsigned long len;
    int rc;
    rc = getpwuid_r(getuid(), &pwd, buf, 1024, &pwdbuf);
    if (rc == 0) {
        home = pwd.pw_dir;
    } else {
        home = getenv("HOME");
        if (home == ((void *)0)) {
            return ((void *)0);
        }
        snprintf(buf, sizeof(buf), "%s", home);
        home = buf;
    }
    if (!(user_config_dir = getenv("XDG_CONFIG_HOME"))) {
        len = strlen(home) + strlen("/.config") + 1;
        user_config_dir = malloc(len);
        if (user_config_dir == ((void *)0)) {
            return ((void *)0);
        }
        snprintf(user_config_dir, len, "%s/.config", home);
    }
    return user_config_dir;
}

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types:
home
char *

variable_types:
buf
char [1024]

variable_types:
len
unsigned long

variable_types: rc int


decompiled_code:
__int64 __fastcall create_user_config_dir(void *src)
{
size_t v1; // rbx
void *v2; // rbp
struct stat v4; // [rsp+0h] [rbp-A8h] BYREF

if ( !mkdir((const char *)src, 0x1C0u)
|| *_errno_location() == 17 && !stat((const char *)src, &v4) && (v4.st_mode & 0xF000) == 0x4000 )
{
v1 = strlen((const char *)src);
v2 = malloc(v1 + 6);
memcpy(v2, src, v1);
strcpy((char *)v2 + v1, "/tox/");
if ( !mkdir((const char *)v2, 0x1C0u)
|| *_errno_location() == 17 && !stat((const char *)v2, &v4) && (v4.st_mode & 0xF000) == 0x4000 )
{
free(v2);
return 0LL;
}
free(v2);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *src)
{
size_t v1; // rbx
void *v2; // rbp
struct stat v4; // [rsp+0h] [rbp-A8h] BYREF

if ( !mkdir((const char *)src, 0x1C0u)
|| *_errno_location() == 17 && !stat((const char *)src, &v4) && (v4.st_mode & 0xF000) == 0x4000 )
{
v1 = strlen((const char *)src);
v2 = malloc(v1 + 6);
memcpy(v2, src, v1);
strcpy((char *)v2 + v1, "/tox/");
if ( !mkdir((const char *)v2, 0x1C0u)
|| *_errno_location() == 17 && !stat((const char *)v2, &v4) && (v4.st_mode & 0xF000) == 0x4000 )
{
free(v2);
return 0LL;
}
free(v2);
}
return 0xFFFFFFFFLL;
}

original_code:
int create_user_config_dir(char *path)
{
    int mkdir_err;
    mkdir_err = mkdir(path, 0700);
    struct stat buf;
    if (mkdir_err && ((*__errno_location ()) != 17 || stat(path, &buf) || !((((buf.st_mode)) & 0170000) == (0040000)))) {
        return -1;
    }
    char *fullpath = malloc(strlen(path) + strlen("/tox/") + 1);
    strcpy(fullpath, path);
    strcat(fullpath, "/tox/");
    mkdir_err = mkdir(fullpath, 0700);
    if (mkdir_err && ((*__errno_location ()) != 17 || stat(fullpath, &buf) || !((((buf.st_mode)) & 0170000) == (0040000)))) {
        free(fullpath);
        return -1;
    }
    free(fullpath);
    return 0;
}

variable_types:
path
char *

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

variable_types:
fullpath
char *

return_type: int

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


repo: locasto/libdisorder

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

if ( LIBDISORDER_INITIALIZED != 1 )
{
result = 0LL;
m_num_tokens = 0;
LIBDISORDER_INITIALIZED = 1;
memset(&m_token_freqs, 0, 0x400uLL);
}
return result;
}

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

if ( LIBDISORDER_INITIALIZED != 1 )
{
result = 0LL;
m_num_tokens = 0;
LIBDISORDER_INITIALIZED = 1;
memset(&m_token_freqs, 0, 0x400uLL);
}
return result;
}

original_code:
static void
initialize_lib()
{
  int i = 0;
  if(1==LIBDISORDER_INITIALIZED)
    return;
  m_num_tokens = 0;
  for(i=0;i<256;i++)
  {
    m_token_freqs[i]=0;
    m_token_probs[i]=0.0;
  }
  LIBDISORDER_INITIALIZED = 1;
}

variable_types: i int

return_type: void


decompiled_code:
__int128 *count_num_tokens()
{
__int128 *result; // rax
int v1; // edx

result = (__int128 *)&m_token_freqs;
v1 = 0;
do
{
v1 -= (*(_DWORD *)result == 0) - 1;
result = (__int128 *)((char *)result + 4);
}
while ( result != &LC1 );
m_num_tokens = v1;
return result;
}

canonical_decompiled_code:
__int128 *func1()
{
__int128 *result; // rax
int v1; // edx

result = (__int128 *)&m_token_freqs;
v1 = 0;
do
{
v1 -= (*(_DWORD *)result == 0) - 1;
result = (__int128 *)((char *)result + 4);
}
while ( result != &LC1 );
m_num_tokens = v1;
return result;
}

original_code:
static void
count_num_tokens()
{
  int i = 0;
  int counter = 0;
  for(i=0;i<256;i++)
  {
    if(0!=m_token_freqs[i])
    {
      counter++;
    }
  }
  m_num_tokens = counter;
  return;
}

variable_types: counter int


decompiled_code:
__int64 __fastcall get_token_frequencies(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rdx
__int64 result; // rax

v2 = a1;
result = 0LL;
m_num_tokens = 0;
memset(m_token_freqs, 0, sizeof(m_token_freqs));
if ( a2 > 0 )
{
do
{
result = *v2++;
++m_token_freqs[result];
}
while ( v2 != &a1[a2] );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rdx
__int64 result; // rax

v2 = a1;
result = 0LL;
m_num_tokens = 0;
memset(m_token_freqs, 0, sizeof(m_token_freqs));
if ( a2 > 0 )
{
do
{
result = *v2++;
++m_token_freqs[result];
}
while ( v2 != &a1[a2] );
}
return result;
}

original_code:
static void
get_token_frequencies(char* buf,
        long long length)
{
  int i=0;
  char* itr=((void *)0);
  unsigned char c=0;
  itr = buf;
  m_num_tokens = 0;
  for(i=0;i<256;i++)
  {
    m_token_freqs[i] = 0;
    m_token_probs[i] = 0.0;
  }
  for(i=0;i<length;i++)
  {
    c = (unsigned char)*itr;
    m_token_freqs[c]++;
    itr++;
  }
}

canonical_original_code:
static void get_token_frequencies(char *buf, long long length)
{
  int i = 0;
  char *itr = ((void *)0);
  unsigned char c = 0;
  itr = buf;
  m_num_tokens = 0;
  for(i=0;i<256;i++)
  {
    m_token_freqs[i] = 0;
    m_token_probs[i] = 0.0;
  }
  for(i=0;i<length;i++)
  {
    c = (unsigned char)*itr;
    m_token_freqs[c]++;
    itr++;
  }
}

variable_types:
buf
char *

variable_types:
length
long long

variable_types:
itr
char *

variable_types:
c
unsigned char


decompiled_code:
double __fastcall shannon_H(unsigned __int8 *a1, __int64 a2)
{
double v2; // xmm1_8
int v3; // er12
__int128 *v4; // rbx
float v5; // xmm2_4
int v6; // eax
int v7; // xmm0_4

if ( !a1 || !a2 )
return 0.0;
if ( !LIBDISORDER_INITIALIZED )
initialize_lib();
m_maxent = 0;
v2 = 0.0;
m_ratio = 0;
get_token_frequencies(a1, (int)a2);
count_num_tokens();
v3 = m_num_tokens;
if ( m_num_tokens <= 256 )
{
v4 = (__int128 *)m_token_freqs;
v5 = 0.0;
do
{
while ( 1 )
{
v6 = *(_DWORD *)v4;
if ( *(_DWORD *)v4 )
break;
v4 = (__int128 *)((char *)v4 + 4);
if ( &LC1 == v4 )
goto LABEL_10;
}
v4 = (__int128 *)((char *)v4 + 4);
v5 = v5 + (float)((float)v6 / (float)(int)a2) * log2((float)((float)v6 / (float)(int)a2));
}
while ( &LC1 != v4 );
LABEL_10:
*(_QWORD *)&v2 = LODWORD(v5) ^ (unsigned int)LC1;
*(float *)&v7 = log2((double)v3);
m_maxent = v7;
*(float *)&m_ratio = COERCE_FLOAT(LODWORD(v5) ^ LC1) / *(float *)&v7;
}
return v2;
}

canonical_decompiled_code:
double __fastcall func3(unsigned __int8 *a1, __int64 a2)
{
double v2; // xmm1_8
int v3; // er12
__int128 *v4; // rbx
float v5; // xmm2_4
int v6; // eax
int v7; // xmm0_4

if ( !a1 || !a2 )
return 0.0;
if ( !LIBDISORDER_INITIALIZED )
func0();
m_maxent = 0;
v2 = 0.0;
m_ratio = 0;
func2(a1, (int)a2);
func1();
v3 = m_num_tokens;
if ( m_num_tokens <= 256 )
{
v4 = (__int128 *)m_token_freqs;
v5 = 0.0;
do
{
while ( 1 )
{
v6 = *(_DWORD *)v4;
if ( *(_DWORD *)v4 )
break;
v4 = (__int128 *)((char *)v4 + 4);
if ( &LC1 == v4 )
goto LABEL_10;
}
v4 = (__int128 *)((char *)v4 + 4);
v5 = v5 + (float)((float)v6 / (float)(int)a2) * log2((float)((float)v6 / (float)(int)a2));
}
while ( &LC1 != v4 );
LABEL_10:
*(_QWORD *)&v2 = LODWORD(v5) ^ (unsigned int)LC1;
*(float *)&v7 = log2((double)v3);
m_maxent = v7;
*(float *)&m_ratio = COERCE_FLOAT(LODWORD(v5) ^ LC1) / *(float *)&v7;
}
return v2;
}

original_code:
float
shannon_H(char* buf,
   long long length)
{
  int i = 0;
  float bits = 0.0;
  char* itr=((void *)0);
  unsigned char token;
  int num_events = 0;
  float freq = 0.0;
  float entropy = 0.0;
  if(((void *)0)==buf || 0==length)
    return 0.0;
  if(0==LIBDISORDER_INITIALIZED)
    initialize_lib();
  itr = buf;
  m_maxent = 0.0;
  m_ratio = 0.0;
  num_events = length;
  get_token_frequencies(itr, num_events);
  count_num_tokens();
  if(m_num_tokens>256)
  {
    return 0.0;
  }
  for(i=0;i<256;i++)
  {
    if(0!=m_token_freqs[i])
    {
      token = i;
      freq = ((float)m_token_freqs[token]);
      m_token_probs[token] = (freq / ((float)num_events));
      entropy += m_token_probs[token] * log2(m_token_probs[token]);
    }
  }
  bits = -1.0 * entropy;
  m_maxent = log2(m_num_tokens);
  m_ratio = bits / m_maxent;
  return bits;
}

canonical_original_code:
float shannon_H(char *buf, long long length)
{
  int i = 0;
  float bits = 0.0;
  char *itr = ((void *)0);
  unsigned char token;
  int num_events = 0;
  float freq = 0.0;
  float entropy = 0.0;
  if(((void *)0)==buf || 0==length)
    return 0.0;
  if(0==LIBDISORDER_INITIALIZED)
    initialize_lib();
  itr = buf;
  m_maxent = 0.0;
  m_ratio = 0.0;
  num_events = length;
  get_token_frequencies(itr, num_events);
  count_num_tokens();
  if(m_num_tokens>256)
  {
    return 0.0;
  }
  for(i=0;i<256;i++)
  {
    if(0!=m_token_freqs[i])
    {
      token = i;
      freq = ((float)m_token_freqs[token]);
      m_token_probs[token] = (freq / ((float)num_events));
      entropy += m_token_probs[token] * log2(m_token_probs[token]);
    }
  }
  bits = -1.0 * entropy;
  m_maxent = log2(m_num_tokens);
  m_ratio = bits / m_maxent;
  return bits;
}

variable_types: bits float

variable_types:
token
unsigned char

variable_types: freq float

variable_types: entropy float

return_type: float


decompiled_code:
__int64 get_num_tokens()
{
return (unsigned int)m_num_tokens;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)m_num_tokens;
}

original_code:
int
get_num_tokens()
{
  return m_num_tokens;
}


decompiled_code:
float get_max_entropy()
{
return *(float *)&m_maxent;
}

canonical_decompiled_code:
float func5()
{
return *(float *)&m_maxent;
}

original_code:
float
get_max_entropy()
{
  return m_maxent;
}


decompiled_code:
float get_entropy_ratio()
{
return *(float *)&m_ratio;
}

canonical_decompiled_code:
float func6()
{
return *(float *)&m_ratio;
}

original_code:
float
get_entropy_ratio()
{
  return m_ratio;
}


repo: lockie/cellular

decompiled_code:
int __fastcall display_usage(const char *a1)
{
printf("USAGE: %s [options]\n", a1);
puts("Options:");
puts("\t-i, --infile=<file>\tInput file (cellular automaton in XML format)");
puts("\t-o, --outfile=<file>\tOutput file (video in mkv container/automaton in XML)");
puts("\t-c, --characters\tWrite final state of cellular automaton in XML format instead of video");
puts("\t-C, --cpu\t\tForce CPU (non-CUDA) implementation");
puts("\t-q, --quantity=<cell>\tDrop quantity of given cell to stdout each step");
puts("\t-t, --timings\t\tDo timings");
puts("\t-s, --steps=<number>\tNumber of simulation steps (defaults to 100)");
puts("\t-w, --watermark=<text>\tWatermark printed as a subtitle on each video frame");
puts("\t-v, --verbose\t\tBe verbose (show fancy progressbar)");
puts("\t-h, -?, --help\t\tShow handy user manual you're reading");
return puts(
"\n"
"Cellular Copyright (C) 2011-2012 Andrew Kravchuk\n"
"This is free software; see the source for copying conditions. There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
printf("USAGE: %s [options]\n", a1);
puts("Options:");
puts("\t-i, --infile=<file>\tInput file (cellular automaton in XML format)");
puts("\t-o, --outfile=<file>\tOutput file (video in mkv container/automaton in XML)");
puts("\t-c, --characters\tWrite final state of cellular automaton in XML format instead of video");
puts("\t-C, --cpu\t\tForce CPU (non-CUDA) implementation");
puts("\t-q, --quantity=<cell>\tDrop quantity of given cell to stdout each step");
puts("\t-t, --timings\t\tDo timings");
puts("\t-s, --steps=<number>\tNumber of simulation steps (defaults to 100)");
puts("\t-w, --watermark=<text>\tWatermark printed as a subtitle on each video frame");
puts("\t-v, --verbose\t\tBe verbose (show fancy progressbar)");
puts("\t-h, -?, --help\t\tShow handy user manual you're reading");
return puts(
"\n"
"Cellular Copyright (C) 2011-2012 Andrew Kravchuk\n"
"This is free software; see the source for copying conditions. There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
}

original_code:
void display_usage(const char* progname)
{
 printf("USAGE: %s [options]\n", progname);
 printf("Options:\n");
 printf("\t-i, --infile=<file>\tInput file (cellular automaton in XML format)\n");
 printf("\t-o, --outfile=<file>\tOutput file (video in mkv container/automaton in XML)\n");
 printf("\t-c, --characters\tWrite final state of cellular automaton in XML format instead of video\n");
 printf("\t-C, --cpu\t\tForce CPU (non-CUDA) implementation\n");
 printf("\t-q, --quantity=<cell>\tDrop quantity of given cell to stdout each step\n");
 printf("\t-t, --timings\t\tDo timings\n");
 printf("\t-s, --steps=<number>\tNumber of simulation steps (defaults to 100)\n");
 printf("\t-w, --watermark=<text>\tWatermark printed as a subtitle on each video frame\n");
 printf("\t-v, --verbose\t\tBe verbose (show fancy progressbar)\n");
 printf("\t-h, -?, --help\t\tShow handy user manual you're reading\n");
 printf("\nCellular Copyright (C) 2011-2012 Andrew Kravchuk\nThis is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
}

canonical_original_code:
void display_usage(char *progname)
{
 printf("USAGE: %s [options]\n", progname);
 printf("Options:\n");
 printf("\t-i, --infile=<file>\tInput file (cellular automaton in XML format)\n");
 printf("\t-o, --outfile=<file>\tOutput file (video in mkv container/automaton in XML)\n");
 printf("\t-c, --characters\tWrite final state of cellular automaton in XML format instead of video\n");
 printf("\t-C, --cpu\t\tForce CPU (non-CUDA) implementation\n");
 printf("\t-q, --quantity=<cell>\tDrop quantity of given cell to stdout each step\n");
 printf("\t-t, --timings\t\tDo timings\n");
 printf("\t-s, --steps=<number>\tNumber of simulation steps (defaults to 100)\n");
 printf("\t-w, --watermark=<text>\tWatermark printed as a subtitle on each video frame\n");
 printf("\t-v, --verbose\t\tBe verbose (show fancy progressbar)\n");
 printf("\t-h, -?, --help\t\tShow handy user manual you're reading\n");
 printf("\nCellular Copyright (C) 2011-2012 Andrew Kravchuk\nThis is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
}

variable_types:
progname
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int v4; // eax
int v5; // ebp
char v6; // r13
char *v7; // r15
int v8; // er12
__int64 v10; // r14
unsigned int v11; // eax
int i; // ebx
unsigned int v13; // eax
int v14; // [rsp+Ch] [rbp-8Ch]
char *v15; // [rsp+10h] [rbp-88h]
char *v16; // [rsp+18h] [rbp-80h]
int v17; // [rsp+20h] [rbp-78h]
int v18; // [rsp+24h] [rbp-74h]
int longind; // [rsp+34h] [rbp-64h] BYREF
__int64 v20; // [rsp+38h] [rbp-60h] BYREF
struct timespec tp; // [rsp+40h] [rbp-58h] BYREF
struct timespec v22; // [rsp+50h] [rbp-48h] BYREF

longind = 0;
v4 = getopt_long(argc, (char *const *)argv, "i:o:cCq:ts:w:vh?", &long_opts, &longind);
if ( v4 == -1 )
{
LABEL_49:
puts("No input files");
return 0;
}
v17 = 0;
v5 = 0;
v6 = 0;
v7 = 0LL;
v15 = 0LL;
v8 = 0;
v16 = 0LL;
v18 = 0;
v14 = 0;
while ( 2 )
{
switch ( v4 )
{
case '?':
case 'h':
display_usage(*argv);
return 0;
case 'C':
v18 = 1;
goto LABEL_5;
case 'c':
v14 = 1;
goto LABEL_5;
case 'i':
v7 = optarg;
goto LABEL_5;
case 'o':
v16 = optarg;
goto LABEL_5;
case 'q':
v6 = *optarg;
goto LABEL_5;
case 's':
v5 = atoi(optarg);
goto LABEL_5;
case 't':
v17 = 1;
goto LABEL_5;
case 'v':
++v8;
goto LABEL_5;
case 'w':
v15 = optarg;
goto LABEL_5;
default:
LABEL_5:
v4 = getopt_long(argc, (char *const *)argv, "i:o:cCq:ts:w:vh?", &long_opts, &longind);
if ( v4 != -1 )
continue;
if ( !v7 )
goto LABEL_49;
if ( !v16 )
{
puts("No output file");
return 0;
}
if ( !v5 )
v5 = 100;
if ( v15 && v14 )
{
puts("--watermark option is incompatible with --characters");
return 0;
}
v20 = load_automaton(v7);
if ( !v20 )
return 1;
if ( v14 )
{
v13 = time(0LL);
srand(v13);
clock_gettime(4, &tp);
if ( !v6 && !v18 )
{
v10 = 0LL;
tick_cuda(v20, (unsigned int)v5);
clock_gettime(4, &v22);
goto LABEL_48;
}
v10 = 0LL;
if ( v5 <= 0 )
{
clock_gettime(4, &v22);
goto LABEL_48;
}
LABEL_24:
for ( i = 0; i != v5; ++i )
{
if ( !v14 )
render(v10, v20, v15);
if ( v18 )
tick(v20);
else
tick_cuda(v20, 1LL);
if ( v6 )
{
count_cells(v20, (unsigned int)v6);
if ( v8 )
printf("%d %f\n", *(unsigned int *)(v20 + 120), v3);
else
printf("%f\n", v3);
}
else if ( v8 )
{
printf("Tick %4d/%d\r", *(unsigned int *)(v20 + 120), (unsigned int)v5);
}
}
clock_gettime(4, &v22);
if ( !v14 )
goto LABEL_41;
LABEL_48:
save_automaton(v20, v16);
goto LABEL_41;
}
v10 = open_renderer(v20, v16);
if ( !v10 )
return 1;
v11 = time(0LL);
srand(v11);
clock_gettime(4, &tp);
if ( v5 > 0 )
goto LABEL_24;
clock_gettime(4, &v22);
LABEL_41:
if ( v17 )
printf(
"Took %f s\n",
(double)(LODWORD(v22.tv_nsec) - LODWORD(tp.tv_nsec)) / 1000000000.0
+ (double)(LODWORD(v22.tv_sec) - LODWORD(tp.tv_sec)));
close_renderer(v10);
delete_automaton(&v20);
return 0;
}
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int v4; // eax
int v5; // ebp
char v6; // r13
char *v7; // r15
int v8; // er12
__int64 v10; // r14
unsigned int v11; // eax
int i; // ebx
unsigned int v13; // eax
int v14; // [rsp+Ch] [rbp-8Ch]
char *v15; // [rsp+10h] [rbp-88h]
char *v16; // [rsp+18h] [rbp-80h]
int v17; // [rsp+20h] [rbp-78h]
int v18; // [rsp+24h] [rbp-74h]
int longind; // [rsp+34h] [rbp-64h] BYREF
__int64 v20; // [rsp+38h] [rbp-60h] BYREF
struct timespec tp; // [rsp+40h] [rbp-58h] BYREF
struct timespec v22; // [rsp+50h] [rbp-48h] BYREF

longind = 0;
v4 = getopt_long(argc, (char *const *)argv, "i:o:cCq:ts:w:vh?", &long_opts, &longind);
if ( v4 == -1 )
{
LABEL_49:
puts("No input files");
return 0;
}
v17 = 0;
v5 = 0;
v6 = 0;
v7 = 0LL;
v15 = 0LL;
v8 = 0;
v16 = 0LL;
v18 = 0;
v14 = 0;
while ( 2 )
{
switch ( v4 )
{
case '?':
case 'h':
func0(*argv);
return 0;
case 'C':
v18 = 1;
goto LABEL_5;
case 'c':
v14 = 1;
goto LABEL_5;
case 'i':
v7 = optarg;
goto LABEL_5;
case 'o':
v16 = optarg;
goto LABEL_5;
case 'q':
v6 = *optarg;
goto LABEL_5;
case 's':
v5 = atoi(optarg);
goto LABEL_5;
case 't':
v17 = 1;
goto LABEL_5;
case 'v':
++v8;
goto LABEL_5;
case 'w':
v15 = optarg;
goto LABEL_5;
default:
LABEL_5:
v4 = getopt_long(argc, (char *const *)argv, "i:o:cCq:ts:w:vh?", &long_opts, &longind);
if ( v4 != -1 )
continue;
if ( !v7 )
goto LABEL_49;
if ( !v16 )
{
puts("No output file");
return 0;
}
if ( !v5 )
v5 = 100;
if ( v15 && v14 )
{
puts("--watermark option is incompatible with --characters");
return 0;
}
v20 = load_automaton(v7);
if ( !v20 )
return 1;
if ( v14 )
{
v13 = time(0LL);
srand(v13);
clock_gettime(4, &tp);
if ( !v6 && !v18 )
{
v10 = 0LL;
tick_cuda(v20, (unsigned int)v5);
clock_gettime(4, &v22);
goto LABEL_48;
}
v10 = 0LL;
if ( v5 <= 0 )
{
clock_gettime(4, &v22);
goto LABEL_48;
}
LABEL_24:
for ( i = 0; i != v5; ++i )
{
if ( !v14 )
render(v10, v20, v15);
if ( v18 )
tick(v20);
else
tick_cuda(v20, 1LL);
if ( v6 )
{
count_cells(v20, (unsigned int)v6);
if ( v8 )
printf("%d %f\n", *(unsigned int *)(v20 + 120), v3);
else
printf("%f\n", v3);
}
else if ( v8 )
{
printf("Tick %4d/%d\r", *(unsigned int *)(v20 + 120), (unsigned int)v5);
}
}
clock_gettime(4, &v22);
if ( !v14 )
goto LABEL_41;
LABEL_48:
save_automaton(v20, v16);
goto LABEL_41;
}
v10 = open_renderer(v20, v16);
if ( !v10 )
return 1;
v11 = time(0LL);
srand(v11);
clock_gettime(4, &tp);
if ( v5 > 0 )
goto LABEL_24;
clock_gettime(4, &v22);
LABEL_41:
if ( v17 )
printf(
"Took %f s\n",
(double)(LODWORD(v22.tv_nsec) - LODWORD(tp.tv_nsec)) / 1000000000.0
+ (double)(LODWORD(v22.tv_sec) - LODWORD(tp.tv_sec)));
close_renderer(v10);
delete_automaton(&v20);
return 0;
}
}
}

original_code:
int main(int argc, char** argv)
{
 struct Automaton* automaton;
 void* renderer = ((void *)0);
 int i, verbose = 0, idx = 0, characters = 0, CPU = 0, timings = 0;
 const char *infile = ((void *)0), *outfile = ((void *)0), *watermark = ((void *)0);
 char cell = 0;
 int steps = 0;
 struct timespec start, end;
 int r = getopt_long(argc, argv, opt_string, long_opts, &idx);
 while(r != -1)
 {
  switch(r)
  {
   case 'i':
    infile = optarg;
    break;
   case 'o':
    outfile = optarg;
    break;
   case 'c':
    characters = 1;
    break;
   case 'C':
    CPU = 1;
    break;
   case 'q':
    cell = optarg[0];
    break;
   case 't':
    timings = 1;
    break;
   case 's':
    steps = atoi(optarg);
    break;
   case 'w':
    watermark = optarg;
    break;
   case 'v':
    verbose++;
    break;
   case 'h':
   case '?':
    display_usage(argv[0]);
    return 0;
    break;
   default:
    break;
  }
  r = getopt_long(argc, argv, opt_string, long_opts, &idx);
 }
 if(!infile)
 {
  printf("No input files\n");
  return 0;
 }
 if(!outfile)
 {
  printf("No output file\n");
  return 0;
 }
 if(steps == 0)
  steps = 100;
 if(watermark && characters)
 {
  printf("--watermark option is incompatible with --characters\n");
  return 0;
 }
 automaton = load_automaton(infile);
 if(!automaton)
  return 1;
 if(!characters)
 {
  renderer = open_renderer(automaton, outfile);
  if(!renderer)
   return 1;
 }
 srand((unsigned int)time(((void *)0)));
 clock_gettime(4, &start);
 if(characters && !CPU && !cell)
  tick_cuda(automaton, steps);
 else
 {
  for(i = 0; i < steps; i++)
  {
   if(!characters)
    render(renderer, automaton, watermark);
   if(CPU)
    tick(automaton);
   else
    tick_cuda(automaton, 1);
   if(cell)
   {
    if(verbose)
     printf("%d %f\n", automaton->ticks,
      count_cells(automaton, cell));
    else
     printf("%f\n", count_cells(automaton, cell));
   } else
    if(verbose)
     printf("Tick %4d/%d\r", automaton->ticks, steps);
  }
 }
 clock_gettime(4, &end);
 if(characters)
  save_automaton(automaton, outfile);
 if(timings)
 {
  double elapsed = (end.tv_sec - start.tv_sec) +
   (double)(end.tv_nsec - start.tv_nsec) / 1.0e9;
  printf("Took %f s\n", elapsed);
 }
 close_renderer(renderer);
 delete_automaton(&automaton);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct Automaton *automaton;
 void *renderer = ((void *)0);
 int i; int verbose = 0; int idx = 0; int characters = 0; int CPU = 0; int timings = 0;
 char *infile = ((void *)0); char *outfile = ((void *)0); char *watermark = ((void *)0);
 char cell = 0;
 int steps = 0;
 struct timespec start; struct timespec end;
 int r = getopt_long(argc, argv, opt_string, long_opts, &idx);
 while(r != -1)
 {
  switch(r)
  {
   case 'i':
    infile = optarg;
    break;
   case 'o':
    outfile = optarg;
    break;
   case 'c':
    characters = 1;
    break;
   case 'C':
    CPU = 1;
    break;
   case 'q':
    cell = optarg[0];
    break;
   case 't':
    timings = 1;
    break;
   case 's':
    steps = atoi(optarg);
    break;
   case 'w':
    watermark = optarg;
    break;
   case 'v':
    verbose++;
    break;
   case 'h':
   case '?':
    display_usage(argv[0]);
    return 0;
    break;
   default:
    break;
  }
  r = getopt_long(argc, argv, opt_string, long_opts, &idx);
 }
 if(!infile)
 {
  printf("No input files\n");
  return 0;
 }
 if(!outfile)
 {
  printf("No output file\n");
  return 0;
 }
 if(steps == 0)
  steps = 100;
 if(watermark && characters)
 {
  printf("--watermark option is incompatible with --characters\n");
  return 0;
 }
 automaton = load_automaton(infile);
 if(!automaton)
  return 1;
 if(!characters)
 {
  renderer = open_renderer(automaton, outfile);
  if(!renderer)
   return 1;
 }
 srand((unsigned int)time(((void *)0)));
 clock_gettime(4, &start);
 if(characters && !CPU && !cell)
  tick_cuda(automaton, steps);
 else
 {
  for(i = 0; i < steps; i++)
  {
   if(!characters)
    render(renderer, automaton, watermark);
   if(CPU)
    tick(automaton);
   else
    tick_cuda(automaton, 1);
   if(cell)
   {
    if(verbose)
     printf("%d %f\n", automaton->ticks,
      count_cells(automaton, cell));
    else
     printf("%f\n", count_cells(automaton, cell));
   } else
    if(verbose)
     printf("Tick %4d/%d\r", automaton->ticks, steps);
  }
 }
 clock_gettime(4, &end);
 if(characters)
  save_automaton(automaton, outfile);
 if(timings)
 {
  double elapsed = (end.tv_sec - start.tv_sec) +
   (double)(end.tv_nsec - start.tv_nsec) / 1.0e9;
  printf("Took %f s\n", elapsed);
 }
 close_renderer(renderer);
 delete_automaton(&automaton);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct Automaton { int width; unsigned long size; int nstates; char zerostate; double omega; char states[62]; struct Rule { char *oldstate; double probability; struct Rule *next; } *rules; unsigned long maxlength; char *lattice; int ticks; } *

variable_types:
renderer
void *

variable_types: verbose int

variable_types: idx int

variable_types: characters int

variable_types: CPU int

variable_types: timings int

variable_types:
infile
char *

variable_types:
outfile
char *

variable_types:
watermark
char *

variable_types: cell char

variable_types: steps int

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

variable_types: r int

variable_types: elapsed double

user_defined_types: struct Automaton { int width; unsigned long size; int nstates; char zerostate; double omega; char states[62]; struct Rule *rules; unsigned long maxlength; char *lattice; int ticks; }


original_code:
int ff_ass_add_rect(AVSubtitle *sub, const char *dialog,
                    int ts_start, int ts_end, int raw)
{
    int len = 0, dlen, duration = ts_end - ts_start;
    char s_start[16], s_end[16], header[48] = {0};
    AVSubtitleRect **rects;
    if (!raw) {
        ts_to_string(s_start, sizeof(s_start), ts_start);
        ts_to_string(s_end, sizeof(s_end), ts_end );
        len = snprintf(header, sizeof(header), "Dialogue: 0,%s,%s,",
                       s_start, s_end);
    }
    dlen = strcspn(dialog, "\n");
    dlen += dialog[dlen] == '\n';
    rects = av_realloc(sub->rects, (sub->num_rects+1) * sizeof(*sub->rects));
    if (!rects)
        return (-(12));
    sub->rects = rects;
    sub->end_display_time = (((int)sub->end_display_time) > (10 * duration) ? ((int)sub->end_display_time) : (10 * duration));
    rects[sub->num_rects] = av_mallocz(sizeof(*rects[0]));
    rects[sub->num_rects]->type = SUBTITLE_ASS;
    rects[sub->num_rects]->ass = av_malloc(len + dlen + 1);
    strcpy (rects[sub->num_rects]->ass , header);
    av_strlcpy(rects[sub->num_rects]->ass + len, dialog, dlen + 1);
    sub->num_rects++;
    return dlen;
}

canonical_original_code:
int ff_ass_add_rect(struct AVSubtitle *sub, char *dialog, int ts_start, int ts_end, int raw)
{
    int len = 0; int dlen; int duration = ts_end - ts_start;
    char s_start[16]; char s_end[16]; char header[48] = {0};
    struct AVSubtitleRect **rects;
    if (!raw) {
        ts_to_string(s_start, sizeof(s_start), ts_start);
        ts_to_string(s_end, sizeof(s_end), ts_end );
        len = snprintf(header, sizeof(header), "Dialogue: 0,%s,%s,",
                       s_start, s_end);
    }
    dlen = strcspn(dialog, "\n");
    dlen += dialog[dlen] == '\n';
    rects = av_realloc(sub->rects, (sub->num_rects+1) * sizeof(*sub->rects));
    if (!rects)
        return (-(12));
    sub->rects = rects;
    sub->end_display_time = (((int)sub->end_display_time) > (10 * duration) ? ((int)sub->end_display_time) : (10 * duration));
    rects[sub->num_rects] = av_mallocz(sizeof(*rects[0]));
    rects[sub->num_rects]->type = SUBTITLE_ASS;
    rects[sub->num_rects]->ass = av_malloc(len + dlen + 1);
    strcpy (rects[sub->num_rects]->ass , header);
    av_strlcpy(rects[sub->num_rects]->ass + len, dialog, dlen + 1);
    sub->num_rects++;
    return dlen;
}

variable_types: struct AVSubtitle { unsigned short format; unsigned int start_display_time; unsigned int end_display_time; unsigned int num_rects; struct AVSubtitleRect { int x; int y; int w; int h; int nb_colors; struct AVPicture { unsigned char *data[8]; int linesize[8]; } pict; unsigned char *data[4]; int linesize[4]; enum AVSubtitleType { SUBTITLE_NONE=0, SUBTITLE_BITMAP=1, SUBTITLE_TEXT=2, SUBTITLE_ASS=3 } type; char *text; char *ass; int flags; } **rects; long pts; } *

variable_types:
dialog
char *

variable_types: raw int

variable_types: len int

variable_types: dlen int

variable_types: duration int

variable_types:
header
char [48]

user_defined_types: struct AVSubtitle { unsigned short format; unsigned int start_display_time; unsigned int end_display_time; unsigned int num_rects; struct AVSubtitleRect **rects; long pts; }

user_defined_types: struct AVSubtitleRect { int x; int y; int w; int h; int nb_colors; struct AVPicture pict; unsigned char *data[4]; int linesize[4]; enum AVSubtitleType type; char *text; char *ass; int flags; }


txctl

repo: loetlab-jena/xplorer

variable_types: state int

variable_types: strength int

variable_types: struct GPCTL { char SRC; char ENAB; char KILL; char; char BUSY; char FLIP; char MASH; unsigned int; char PASSWD; }


main

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

v3 = (const char *)(unsigned int)(argc - 2);
if ( (unsigned int)v3 > 2
|| ((v3 = argv[1], *(_WORD *)v3 != 28271) || (result = *((unsigned __int8 *)v3 + 2), v3[2]))
&& (argv = (const char **)"off", (result = strcmp(v3, "off")) != 0) )
{
usage(v3, argv, envp);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
int result; // eax

v3 = (const char *)(unsigned int)(argc - 2);
if ( (unsigned int)v3 > 2
|| ((v3 = argv[1], *(_WORD *)v3 != 28271) || (result = *((unsigned __int8 *)v3 + 2), v3[2]))
&& (argv = (const char **)"off", (result = strcmp(v3, "off")) != 0) )
{
func8(v3, argv, envp);
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    int state;
    double frequency;
    int strength;
    if ((argc > 4) || (argc < 2)) {
        usage();
        return 1;
    }
    if(strcmp(argv[1],"on") == 0) {
        state = 1;
    }
    else if(strcmp(argv[1],"off") == 0) {
        state = 0;
    }
    else {
        usage();
        return 1;
    }
    frequency = (argc > 2) ? atof(argv[2]) : 0.0;
    strength = (argc = 4) ? atof(argv[3]) : 8;
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: frequency double


usage

decompiled_code:
int usage()
{
return puts("Usage: lo_ctl on/off [frequency] [driver strength]");
}

canonical_decompiled_code:
int func8()
{
return puts("Usage: lo_ctl on/off [frequency] [driver strength]");
}

original_code:
void usage(void)
{
    printf("Usage: lo_ctl on/off [frequency] [driver strength]\n");
}

canonical_original_code:
void usage()
{
    printf("Usage: lo_ctl on/off [frequency] [driver strength]\n");
}


original_code:
void process_data(double *data, int count, int fs, double fc, double freqdev, double igain, double qgain, double phaseoffset)
{
    static double old_phase = 0.0;
    double cumsum[1024];
    double phase;
    int i;
    if (count == 0)
        return;
    cumsum[0] = data[0]/fs;
    for (i = 1; i < count; i++) {
        cumsum[i] = cumsum[i-1] + data[i]/fs;
    }
    for (i=0; i < count; i++) {
        phase = 2*3.14159265358979323846*fc/fs*(i+1) + 2*3.14159265358979323846*freqdev*cumsum[i] + old_phase;
        data[2*i] = igain * sin(phase + phaseoffset);
        data[2*i + 1] = - qgain * sin(phase);
    }
    old_phase = fmod(phase, 2*3.14159265358979323846);
    return;
}

variable_types:
data
double *

variable_types: count int

variable_types: fs int

variable_types: fc double

variable_types: freqdev double

variable_types: igain double

variable_types: qgain double

variable_types: phaseoffset double

variable_types:
cumsum
double [1024]

variable_types: phase double

variable_types: i int


decompiled_code:
int usage()
{
return puts(
"Usage: fmmod inputfile outputfile [carrier] [freqdev] [gain | igain qgain [phaseoffset]]\n"
" inputfile: path to input file(needs to be single channel)\n"
" outputfile: path to output file\n"
" carrier: carrier frequency in Hz(standard: 0.0)\n"
" freqdev: frequency deviation in Hz(standard: 3000)\n"
" gain: amplification of both modulated signals(0.0 < gain < 1.0)\n"
" igain: amplification of modulated inphase signal\n"
" qgain: amplification of modulated quadrature signal\n"
" phaseoffset: phase offset between inphase and quadrature signal in degrees(standard: 90°)");
}

canonical_decompiled_code:
int func7()
{
return puts(
"Usage: fmmod inputfile outputfile [carrier] [freqdev] [gain | igain qgain [phaseoffset]]\n"
" inputfile: path to input file(needs to be single channel)\n"
" outputfile: path to output file\n"
" carrier: carrier frequency in Hz(standard: 0.0)\n"
" freqdev: frequency deviation in Hz(standard: 3000)\n"
" gain: amplification of both modulated signals(0.0 < gain < 1.0)\n"
" igain: amplification of modulated inphase signal\n"
" qgain: amplification of modulated quadrature signal\n"
" phaseoffset: phase offset between inphase and quadrature signal in degrees(standard: 90°)");
}

original_code:
void usage(void)
{
    printf("Usage: fmmod inputfile outputfile [carrier] [freqdev] [gain | igain qgain [phaseoffset]]\n             inputfile: path to input file(needs to be single channel)\n             outputfile: path to output file\n             carrier: carrier frequency in Hz(standard: 0.0)\n             freqdev: frequency deviation in Hz(standard: 3000)\n             gain: amplification of both modulated signals(0.0 < gain < 1.0)\n             igain: amplification of modulated inphase signal\n             qgain: amplification of modulated quadrature signal\n             phaseoffset: phase offset between inphase and quadrature signal in degrees(standard: 90°)\n");
}

canonical_original_code:
void usage()
{
    printf("Usage: fmmod inputfile outputfile [carrier] [freqdev] [gain | igain qgain [phaseoffset]]\n             inputfile: path to input file(needs to be single channel)\n             outputfile: path to output file\n             carrier: carrier frequency in Hz(standard: 0.0)\n             freqdev: frequency deviation in Hz(standard: 3000)\n             gain: amplification of both modulated signals(0.0 < gain < 1.0)\n             igain: amplification of modulated inphase signal\n             qgain: amplification of modulated quadrature signal\n             phaseoffset: phase offset between inphase and quadrature signal in degrees(standard: 90°)\n");
}


getBitmapSize

repo: logbird/cCase

decompiled_code:
size_t getBitmapSize()
{
return 8 * bitmap_bytes;
}

canonical_decompiled_code:
size_t func7()
{
return 8 * bitmap_bytes;
}

original_code:
size_t getBitmapSize()
{
    return bitmap_bytes * 8;
}

canonical_original_code:
unsigned long getBitmapSize()
{
    return bitmap_bytes * 8;
}

return_type: unsigned long


getBitmapIdx

decompiled_code:
__int64 __fastcall getBitmapIdx(int a1)
{
return a1 & ((unsigned int)getBitmapSize() - 1);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return a1 & ((unsigned int)func7() - 1);
}

original_code:
unsigned int getBitmapIdx(unsigned int hash_value) {
    unsigned int idx = 0;
    idx = hash_value & (getBitmapSize() - 1);
    return idx;
}

variable_types:
idx
unsigned int

return_type: unsigned int


setFilter

decompiled_code:
__int64 __fastcall setFilter(__int64 a1, __int64 a2, unsigned int a3)
{
size_t *v4; // rbx
int v5; // eax
int v6; // eax
__int64 result; // rax

v4 = (size_t *)hash_funcs;
do
{
v5 = ((__int64 (__fastcall *)(__int64, _QWORD))*v4++)(a2, a3);
v6 = getBitmapIdx(v5);
result = bitmapSetBit(a1, v6);
}
while ( v4 != &bitmap_bytes );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, unsigned int a3)
{
size_t *v4; // rbx
int v5; // eax
int v6; // eax
__int64 result; // rax

v4 = (size_t *)hash_funcs;
do
{
v5 = ((__int64 (__fastcall *)(__int64, _QWORD))*v4++)(a2, a3);
v6 = func8(v5);
result = func9(a1, v6);
}
while ( v4 != &bitmap_bytes );
return result;
}

original_code:
void setFilter(char *bitmap, char *buf, int len) {
    unsigned int i;
    unsigned int hash_value, idx;
    for (i = 0; i < 3; i++) {
        hash_value = hash_funcs[i](buf, len);
        idx = getBitmapIdx(hash_value);
        bitmapSetBit(bitmap, idx);
    }
}

canonical_original_code:
void setFilter(char *bitmap, char *buf, int len) {
    unsigned int i;
    unsigned int hash_value; unsigned int idx;
    for (i = 0; i < 3; i++) {
        hash_value = hash_funcs[i](buf, len);
        idx = getBitmapIdx(hash_value);
        bitmapSetBit(bitmap, idx);
    }
}

variable_types:
bitmap
char *

variable_types:
buf
char *

variable_types: len int

variable_types:
i
unsigned int


bitmapTestBit

decompiled_code:
__int64 __fastcall bitmapTestBit(__int64 a1, int a2)
{
return ((int)*(unsigned __int8 *)(a1 + (unsigned int)(a2 / 8)) >> (a2 & 7)) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
return ((int)*(unsigned __int8 *)(a1 + (unsigned int)(a2 / 8)) >> (a2 & 7)) & 1;
}

original_code:
int bitmapTestBit(unsigned char *bitmap, int pos) {
    unsigned int byte = pos/8;
    int bit = pos&7;
    return (bitmap[byte] & (1<<bit)) != 0;
}

variable_types:
bitmap
unsigned char *

variable_types: pos int

variable_types:
byte
unsigned int

variable_types: bit int


check

decompiled_code:
__int64 __fastcall check(__int64 a1, __int64 a2, unsigned int a3)
{
size_t *v4; // rbx
int v5; // eax
int v6; // eax
__int64 result; // rax

v4 = (size_t *)hash_funcs;
do
{
v5 = ((__int64 (__fastcall *)(__int64, _QWORD))*v4)(a2, a3);
v6 = getBitmapIdx(v5);
result = bitmapTestBit(a1, v6) & 1;
if ( !(_DWORD)result )
break;
++v4;
}
while ( &bitmap_bytes != v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, unsigned int a3)
{
size_t *v4; // rbx
int v5; // eax
int v6; // eax
__int64 result; // rax

v4 = (size_t *)hash_funcs;
do
{
v5 = ((__int64 (__fastcall *)(__int64, _QWORD))*v4)(a2, a3);
v6 = func8(v5);
result = func12(a1, v6) & 1;
if ( !(_DWORD)result )
break;
++v4;
}
while ( &bitmap_bytes != v4 );
return result;
}

original_code:
unsigned int check(char *bitmap, char *buf, int len) {
    unsigned int i;
    unsigned int is = 1;
    unsigned int hash_value, idx;
    for (i = 0; i < 3; i++) {
        hash_value = hash_funcs[i](buf, len);
        idx = getBitmapIdx(hash_value);
        is &= bitmapTestBit(bitmap, idx);
        if (is == 0)
            break;
    }
    return is;
}

canonical_original_code:
unsigned int check(char *bitmap, char *buf, int len) {
    unsigned int i;
    unsigned int is = 1;
    unsigned int hash_value; unsigned int idx;
    for (i = 0; i < 3; i++) {
        hash_value = hash_funcs[i](buf, len);
        idx = getBitmapIdx(hash_value);
        is &= bitmapTestBit(bitmap, idx);
        if (is == 0)
            break;
    }
    return is;
}

variable_types:
is
unsigned int


debugBitMap

decompiled_code:
void __fastcall debugBitMap(__int64 a1)
{
int v1; // er14
unsigned int v2; // er13
int v3; // ebp
int v4; // ebx
int v5; // esi
unsigned int v6; // eax

if ( bitmap_bytes )
{
v1 = -1;
v2 = 1;
do
{
v3 = v1;
printf("%04d\t", v2);
v1 += 8;
v4 = v1;
do
{
v5 = v4--;
v6 = bitmapTestBit(a1, v5);
printf("%d", v6);
}
while ( v3 != v4 );
putchar(10);
++v2;
}
while ( v2 <= bitmap_bytes );
}
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1)
{
int v1; // er14
unsigned int v2; // er13
int v3; // ebp
int v4; // ebx
int v5; // esi
unsigned int v6; // eax

if ( bitmap_bytes )
{
v1 = -1;
v2 = 1;
do
{
v3 = v1;
printf("%04d\t", v2);
v1 += 8;
v4 = v1;
do
{
v5 = v4--;
v6 = func12(a1, v5);
printf("%d", v6);
}
while ( v3 != v4 );
putchar(10);
++v2;
}
while ( v2 <= bitmap_bytes );
}
}

original_code:
void debugBitMap(unsigned char *bitmap) {
    unsigned int i, j;
    for (i = 1; i <= bitmap_bytes; i++) {
        printf("%04d\t", i);
        for ( j = 8; j >= 1; j--) {
            printf("%d", bitmapTestBit(bitmap, (i-1)*8 + j - 1));
        }
        printf("\n");
    }
}

canonical_original_code:
void debugBitMap(unsigned char *bitmap) {
    unsigned int i; unsigned int j;
    for (i = 1; i <= bitmap_bytes; i++) {
        printf("%04d\t", i);
        for ( j = 8; j >= 1; j--) {
            printf("%d", bitmapTestBit(bitmap, (i-1)*8 + j - 1));
        }
        printf("\n");
    }
}

variable_types:
j
unsigned int


decompiled_code:
__int64 __fastcall djb_hash(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
unsigned int v3; // er12
unsigned __int8 *v4; // rbp
int v5; // edi

if ( !a2 )
return 5381LL;
v2 = a1;
v3 = 5381;
v4 = &a1[a2];
do
{
v5 = *v2++;
v3 += tolower(v5) + 32 * v3;
}
while ( v2 != v4 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
unsigned int v3; // er12
unsigned __int8 *v4; // rbp
int v5; // edi

if ( !a2 )
return 5381LL;
v2 = a1;
v3 = 5381;
v4 = &a1[a2];
do
{
v5 = *v2++;
v3 += tolower(v5) + 32 * v3;
}
while ( v2 != v4 );
return v3;
}

original_code:
unsigned int djb_hash(const unsigned char *buf, int len)
{
    unsigned int hash = (unsigned int)hash_seed;
    while (len--)
        hash = ((hash << 5) + hash) + (tolower(*buf++));
    return (unsigned int)hash;
}

canonical_original_code:
unsigned int djb_hash(unsigned char *buf, int len)
{
    unsigned int hash = (unsigned int)hash_seed;
    while (len--)
        hash = ((hash << 5) + hash) + (tolower(*buf++));
    return (unsigned int)hash;
}

variable_types:
buf
unsigned char *

variable_types:
hash
unsigned int


original_code:
unsigned int murmur_hash(const unsigned char *buf, int len) {
    uint32_t seed = hash_seed;
    const uint32_t m = 0x5bd1e995;
    const int r = 24;
    uint32_t h = seed ^ len;
    const unsigned char *data = (const unsigned char *)buf;
    while(len >= 4) {
        uint32_t k = *(uint32_t*)data;
        k *= m;
        k ^= k >> r;
        k *= m;
        h *= m;
        h ^= k;
        data += 4;
        len -= 4;
    }
    switch(len) {
    case 3: h ^= data[2] << 16;
    case 2: h ^= data[1] << 8;
    case 1: h ^= data[0]; h *= m;
    };
    h ^= h >> 13;
    h *= m;
    h ^= h >> 15;
    return (unsigned int)h;
}

canonical_original_code:
unsigned int murmur_hash(unsigned char *buf, int len) {
    unsigned int seed = hash_seed;
    unsigned int m = 0x5bd1e995;
    int r = 24;
    unsigned int h = seed ^ len;
    unsigned char *data = (const unsigned char *)buf;
    while(len >= 4) {
        unsigned int k = *(uint32_t*)data;
        k *= m;
        k ^= k >> r;
        k *= m;
        h *= m;
        h ^= k;
        data += 4;
        len -= 4;
    }
    switch(len) {
    case 3: h ^= data[2] << 16;
    case 2: h ^= data[1] << 8;
    case 1: h ^= data[0]; h *= m;
    };
    h ^= h >> 13;
    h *= m;
    h ^= h >> 15;
    return (unsigned int)h;
}

variable_types:
seed
unsigned int

variable_types:
m
unsigned int

variable_types: r int

variable_types:
h
unsigned int

variable_types:
data
unsigned char *

variable_types:
k
unsigned int


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

if ( a2 <= 0 )
return 0LL;
LODWORD(result) = 0;
v3 = &a1[a2];
do
result = (unsigned int)crc16tab[(unsigned __int8)(*a1++ ^ BYTE1(result))] ^ ((_DWORD)result << 8);
while ( a1 != v3 );
return result;
}

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

if ( a2 <= 0 )
return 0LL;
LODWORD(result) = 0;
v3 = &a1[a2];
do
result = (unsigned int)crc16tab[(unsigned __int8)(*a1++ ^ BYTE1(result))] ^ ((_DWORD)result << 8);
while ( a1 != v3 );
return result;
}

original_code:
unsigned int crc16(const unsigned char *buf, int len) {
    int counter;
    unsigned int crc = 0;
    for (counter = 0; counter < len; counter++)
            crc = (crc<<8) ^ crc16tab[((crc>>8) ^ *buf++)&0x00FF];
    return (unsigned int)crc;
}

canonical_original_code:
unsigned int crc16(unsigned char *buf, int len) {
    int counter;
    unsigned int crc = 0;
    for (counter = 0; counter < len; counter++)
            crc = (crc<<8) ^ crc16tab[((crc>>8) ^ *buf++)&0x00FF];
    return (unsigned int)crc;
}

variable_types: counter int

variable_types:
crc
unsigned int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
int result; // eax

v3 = calloc(bitmap_bytes, 1uLL);
setFilter(v3, "logbird", 7LL);
v4 = check(v3, "abcd", 4LL);
printf("test %d is %d\n", "abcd", v4);
v5 = check(v3, "logbird", 7LL);
printf("test %d is %d\n", "logbird", v5);
free(v3);
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
int result; // eax

v3 = calloc(bitmap_bytes, 1uLL);
func10(v3, "logbird", 7LL);
v4 = func13(v3, "abcd", 4LL);
printf("test %d is %d\n", "abcd", v4);
v5 = func13(v3, "logbird", 7LL);
printf("test %d is %d\n", "logbird", v5);
free(v3);
return result;
}

original_code:
void main(int argc, char* argv) {
    unsigned int offset;
    char *bucket;
    bucket = calloc(bitmap_bytes, sizeof(char));
    setFilter(bucket, "logbird", 7);
    printf("test %d is %d\n", "abcd", check(bucket, "abcd", 4));
    printf("test %d is %d\n", "logbird", check(bucket, "logbird", 7));
    free(bucket);
}

canonical_original_code:
void main(int argc, char *argv) {
    unsigned int offset;
    char *bucket;
    bucket = calloc(bitmap_bytes, sizeof(char));
    setFilter(bucket, "logbird", 7);
    printf("test %d is %d\n", "abcd", check(bucket, "abcd", 4));
    printf("test %d is %d\n", "logbird", check(bucket, "logbird", 7));
    free(bucket);
}

variable_types: argc int

variable_types:
argv
char *

variable_types:
offset
unsigned int

variable_types:
bucket
char *


decompiled_code:
__int64 __fastcall get_a_name(void *dest, char a2, unsigned int a3, const char *a4)
{
__int64 result; // rax
unsigned int v5; // ebx
const char *v6; // r15
unsigned int v7; // eax
const char *v8; // rsi
int v9; // er15
__int64 v10; // r14
unsigned int v11; // er13
int v12; // eax
__int64 v13; // rax
int v14; // ebp
char *v15; // r14

result = 0LL;
if ( a3 > 2 )
return result;
v5 = a3;
v6 = a4;
if ( !a3 )
{
v5 = rand() % 2 + 1;
if ( v6 )
goto LABEL_4;
LABEL_13:
v6 = (const char *)*(&fname + (unsigned __int16)(rand() % 100));
goto LABEL_4;
}
if ( !a4 )
goto LABEL_13;
LABEL_4:
v7 = strlen(v6);
v8 = v6;
v9 = 0;
v10 = v7;
v11 = v7;
memcpy(dest, v8, v7);
*((_BYTE *)dest + v10) = 0;
v12 = 0;
if ( v5 )
{
do
{
v14 = 3 * v12;
v15 = (char *)dest + 3 * v12 + v11;
if ( a2 == 1 )
v13 = (__int64)*(&bname + (unsigned __int16)(rand() % 151));
else
v13 = (__int64)*(&gname + (unsigned __int16)(rand() % 133));
*(_WORD *)v15 = *(_WORD *)v13;
v15[2] = *(_BYTE *)(v13 + 2);
++v9;
*((_BYTE *)dest + v11 + v14 + 3) = 0;
v12 = (unsigned __int16)v9;
}
while ( (unsigned __int16)v9 < v5 );
}
printf("%s|%d\n", (const char *)dest, v11);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *dest, char a2, unsigned int a3, const char *a4)
{
__int64 result; // rax
unsigned int v5; // ebx
const char *v6; // r15
unsigned int v7; // eax
const char *v8; // rsi
int v9; // er15
__int64 v10; // r14
unsigned int v11; // er13
int v12; // eax
__int64 v13; // rax
int v14; // ebp
char *v15; // r14

result = 0LL;
if ( a3 > 2 )
return result;
v5 = a3;
v6 = a4;
if ( !a3 )
{
v5 = rand() % 2 + 1;
if ( v6 )
goto LABEL_4;
LABEL_13:
v6 = (const char *)*(&fname + (unsigned __int16)(rand() % 100));
goto LABEL_4;
}
if ( !a4 )
goto LABEL_13;
LABEL_4:
v7 = strlen(v6);
v8 = v6;
v9 = 0;
v10 = v7;
v11 = v7;
memcpy(dest, v8, v7);
*((_BYTE *)dest + v10) = 0;
v12 = 0;
if ( v5 )
{
do
{
v14 = 3 * v12;
v15 = (char *)dest + 3 * v12 + v11;
if ( a2 == 1 )
v13 = (__int64)*(&bname + (unsigned __int16)(rand() % 151));
else
v13 = (__int64)*(&gname + (unsigned __int16)(rand() % 133));
*(_WORD *)v15 = *(_WORD *)v13;
v15[2] = *(_BYTE *)(v13 + 2);
++v9;
*((_BYTE *)dest + v11 + v14 + 3) = 0;
v12 = (unsigned __int16)v9;
}
while ( (unsigned __int16)v9 < v5 );
}
printf("%s|%d\n", (const char *)dest, v11);
return 1LL;
}

original_code:
int get_a_name(char *name, g_tiny sex, g_size len, char *firstname)
{
    g_sint r;
    g_sint i;
    g_size fnamelen;
    if(len < 0 || len > 2)
        return 0;
    if(len == 0)
    {
        len = rand() % 2 + 1;
    }
    if(firstname == ((void *)0))
    {
        r = rand()%100;
        fnamelen = strlen(fname[r]);
        memcpy(name, fname[r], fnamelen);
    }else
    {
        fnamelen = strlen(firstname);
        memcpy(name, firstname, fnamelen);
    }
    name[fnamelen] = '\0';
    for(i = 0; i < len; i++)
    {
        if(sex == 1)
        {
            r = rand()%151;
            memcpy(name + (i*3 +fnamelen), bname[r], 3);
        }else
        {
            r = rand()%133;
            memcpy(name + (i*3 +fnamelen), gname[r], 3);
        }
        name[(i+1)*3 + fnamelen] = '\0';
    }
    printf("%s|%d\n", name, fnamelen);
    return 1;
}

canonical_original_code:
int get_a_name(char *name, unsigned char sex, unsigned int len, char *firstname)
{
    unsigned short r;
    unsigned short i;
    unsigned int fnamelen;
    if(len < 0 || len > 2)
        return 0;
    if(len == 0)
    {
        len = rand() % 2 + 1;
    }
    if(firstname == ((void *)0))
    {
        r = rand()%100;
        fnamelen = strlen(fname[r]);
        memcpy(name, fname[r], fnamelen);
    }else
    {
        fnamelen = strlen(firstname);
        memcpy(name, firstname, fnamelen);
    }
    name[fnamelen] = '\0';
    for(i = 0; i < len; i++)
    {
        if(sex == 1)
        {
            r = rand()%151;
            memcpy(name + (i*3 +fnamelen), bname[r], 3);
        }else
        {
            r = rand()%133;
            memcpy(name + (i*3 +fnamelen), gname[r], 3);
        }
        name[(i+1)*3 + fnamelen] = '\0';
    }
    printf("%s|%d\n", name, fnamelen);
    return 1;
}

variable_types:
name
char *

variable_types:
sex
unsigned char

variable_types:
len
unsigned int

variable_types:
firstname
char *

variable_types:
r
unsigned short

variable_types:
i
unsigned short

variable_types:
fnamelen
unsigned int


repo: lojikil/small-llist

decompiled_code:
__int64 __fastcall list_get(__int64 a1, void *a2)
{
if ( !a1 || !a2 )
return 0LL;
memcpy(a2, *(const void **)(a1 + 16), *(_QWORD *)(a1 + 24));
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, void *a2)
{
if ( !a1 || !a2 )
return 0LL;
memcpy(a2, *(const void **)(a1 + 16), *(_QWORD *)(a1 + 24));
return *(_QWORD *)a1;
}

original_code:
llist_t *list_get(llist_t *list, void *data) {
 if ((list == ((void *)0)) || (data == ((void *)0)))
  return ((void *)0);
 memcpy(data, list->data, list->size);
 return list->next;
}

canonical_original_code:
struct llist_t *list_get(struct llist_t *list, void *data) {
 if ((list == ((void *)0)) || (data == ((void *)0)))
  return ((void *)0);
 memcpy(data, list->data, list->size);
 return list->next;
}

variable_types:
list
struct llist_t *

variable_types:
data
void *

return_type: struct llist_t { void *next; void *prev; void *data; unsigned long size; } *


decompiled_code:
__int64 __fastcall list_nget(__int64 *a1, void *a2, size_t a3)
{
size_t v3; // r8
__int64 result; // rax

if ( !a1 || !a2 )
return 0LL;
v3 = a1[3];
if ( a3 )
{
if ( v3 > a3 )
v3 = a3;
memcpy(a2, (const void *)a1[2], v3);
result = *a1;
}
else
{
memcpy(a2, (const void *)a1[2], a1[3]);
result = *a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, void *a2, size_t a3)
{
size_t v3; // r8
__int64 result; // rax

if ( !a1 || !a2 )
return 0LL;
v3 = a1[3];
if ( a3 )
{
if ( v3 > a3 )
v3 = a3;
memcpy(a2, (const void *)a1[2], v3);
result = *a1;
}
else
{
memcpy(a2, (const void *)a1[2], a1[3]);
result = *a1;
}
return result;
}

original_code:
llist_t *list_nget(llist_t *list, void *data, size_t max_size) {
 size_t size;
 if ((list == ((void *)0)) || (data == ((void *)0)))
  return ((void *)0);
 if (max_size == 0)
  size = list->size;
 else
  size = max_size > list->size ? list->size : max_size;
 memcpy(data, list->data, size);
 return list->next;
}

canonical_original_code:
struct llist_t *list_nget(struct llist_t *list, void *data, unsigned long max_size) {
 unsigned long size;
 if ((list == ((void *)0)) || (data == ((void *)0)))
  return ((void *)0);
 if (max_size == 0)
  size = list->size;
 else
  size = max_size > list->size ? list->size : max_size;
 memcpy(data, list->data, size);
 return list->next;
}

variable_types:
size
unsigned long

user_defined_types: struct llist_t { void *next; void *prev; void *data; unsigned long size; }


decompiled_code:
__int64 __fastcall list_get_data(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

original_code:
void *list_get_data(llist_t *list) {
 if (list == ((void *)0))
  return ((void *)0);
 return list->data;
}

canonical_original_code:
void *list_get_data(struct llist_t *list) {
 if (list == ((void *)0))
  return ((void *)0);
 return list->data;
}

variable_types: struct llist_t { void *next; void *prev; void *data; unsigned long size; } *

return_type: void *


decompiled_code:
__int64 __fastcall list_get_size(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = *(_QWORD *)(a1 + 24);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 24);
else
result = 0LL;
return result;
}

original_code:
size_t list_get_size(llist_t *list) {
 if (list == ((void *)0))
  return 0;
 return list->size;
}

canonical_original_code:
unsigned long list_get_size(struct llist_t *list) {
 if (list == ((void *)0))
  return 0;
 return list->size;
}


decompiled_code:
__int64 __fastcall list_to_index(__int64 a1)
{
__int64 v1; // rax
__int64 i; // r8

if ( !a1 )
return 0LL;
v1 = *(_QWORD *)(a1 + 8);
for ( i = 1LL; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

original_code:
unsigned long list_to_index(llist_t *list) {
 unsigned long count;
 llist_t *node;
 if (list == ((void *)0))
  return 0;
 count = 1;
 node = list;
 while (node->prev != ((void *)0)) {
  node = node->prev;
  count++;
 }
 return count;
}

canonical_original_code:
unsigned long list_to_index(struct llist_t *list) {
 unsigned long count;
 struct llist_t *node;
 if (list == ((void *)0))
  return 0;
 count = 1;
 node = list;
 while (node->prev != ((void *)0)) {
  node = node->prev;
  count++;
 }
 return count;
}

variable_types:
count
unsigned long


inscribe

repo: lollek/how-to-slay-your-balrog

decompiled_code:
char *__fastcall inscribe(__int64 a1, const char *a2)
{
return strcpy((char *)(a1 + 3), a2);
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, const char *a2)
{
return strcpy((char *)(a1 + 3), a2);
}

original_code:
void inscribe(inven_type *i_ptr, char *str)
{
  (void) strcpy(i_ptr->inscrip, str);
}

canonical_original_code:
void inscribe(struct inven_type *i_ptr, char *str)
{
  (void) strcpy(i_ptr->inscrip, str);
}

variable_types: struct inven_type { unsigned short index; unsigned char name2; char inscrip[13]; unsigned long flags; unsigned char tval; unsigned char tchar; short p1; long cost; unsigned char subval; unsigned char number; unsigned short weight; short tohit; short todam; short ac; short toac; unsigned char damage[2]; unsigned char level; unsigned char ident; } *

variable_types:
str
char *


decompiled_code:
char *scribe_object()
{
char *result; // rax
__int64 v1; // rdx
int v2; // er12
size_t v3; // rax
int v4; // [rsp+0h] [rbp-ACh] BYREF
char s[80]; // [rsp+4h] [rbp-A8h] BYREF
char v6[88]; // [rsp+54h] [rbp-58h] BYREF

if ( inven_ctr <= 0 && equip_ctr <= 0 )
return (char *)msg_print("You are not carrying anything to inscribe.");
result = (char *)get_item(&v4, "Which one? ", 0LL, 34LL, 0LL, 0LL);
if ( (_DWORD)result )
{
objdes(v6, &inventory[56 * v4], 1LL);
sprintf(s, "Inscribing %s", v6);
msg_print(s);
v1 = 56LL * v4;
if ( inventory[v1 + 3] )
sprintf(s, "Replace %s New inscription:", &inventory[v1 + 3]);
else
strcpy(s, "Inscription: ");
v2 = 78 - strlen(v6);
if ( v2 >= 25 )
v2 = 12;
prt(s, 0LL, 0LL);
v3 = strlen(s);
result = (char *)get_string(s, 0LL, v3, (unsigned int)v2);
if ( (_DWORD)result )
result = inscribe((__int64)&inventory[56 * v4], s);
}
return result;
}

canonical_decompiled_code:
char *func2()
{
char *result; // rax
__int64 v1; // rdx
int v2; // er12
size_t v3; // rax
int v4; // [rsp+0h] [rbp-ACh] BYREF
char s[80]; // [rsp+4h] [rbp-A8h] BYREF
char v6[88]; // [rsp+54h] [rbp-58h] BYREF

if ( inven_ctr <= 0 && equip_ctr <= 0 )
return (char *)msg_print("You are not carrying anything to inscribe.");
result = (char *)get_item(&v4, "Which one? ", 0LL, 34LL, 0LL, 0LL);
if ( (_DWORD)result )
{
objdes(v6, &inventory[56 * v4], 1LL);
sprintf(s, "Inscribing %s", v6);
msg_print(s);
v1 = 56LL * v4;
if ( inventory[v1 + 3] )
sprintf(s, "Replace %s New inscription:", &inventory[v1 + 3]);
else
strcpy(s, "Inscription: ");
v2 = 78 - strlen(v6);
if ( v2 >= 25 )
v2 = 12;
prt(s, 0LL, 0LL);
v3 = strlen(s);
result = (char *)get_string(s, 0LL, v3, (unsigned int)v2);
if ( (_DWORD)result )
result = func1((__int64)&inventory[56 * v4], s);
}
return result;
}

original_code:
void scribe_object()
{
  int item_val, j;
  vtype out_val, tmp_str;
  if (inven_ctr > 0 || equip_ctr > 0)
    {
      if (get_item(&item_val, "Which one? ", 0, 34, (char *)0, (char *)0))
 {
   objdes(tmp_str, &inventory[item_val], 1);
   (void) sprintf(out_val, "Inscribing %s", tmp_str);
   msg_print(out_val);
   if (inventory[item_val].inscrip[0] != '\0')
     (void) sprintf(out_val, "Replace %s New inscription:",
      inventory[item_val].inscrip);
   else
     (void) strcpy(out_val, "Inscription: ");
   j = 78 - strlen(tmp_str);
   if (j > 24)
     j = 12;
   prt(out_val, 0, 0);
   if (get_string(out_val, 0, (int)strlen(out_val), j))
     inscribe(&inventory[item_val], out_val);
 }
    }
  else
    msg_print("You are not carrying anything to inscribe.");
}

canonical_original_code:
void scribe_object()
{
  int item_val; int j;
  char out_val[80]; char tmp_str[80];
  if (inven_ctr > 0 || equip_ctr > 0)
    {
      if (get_item(&item_val, "Which one? ", 0, 34, (char *)0, (char *)0))
 {
   objdes(tmp_str, &inventory[item_val], 1);
   (void) sprintf(out_val, "Inscribing %s", tmp_str);
   msg_print(out_val);
   if (inventory[item_val].inscrip[0] != '\0')
     (void) sprintf(out_val, "Replace %s New inscription:",
      inventory[item_val].inscrip);
   else
     (void) strcpy(out_val, "Inscription: ");
   j = 78 - strlen(tmp_str);
   if (j > 24)
     j = 12;
   prt(out_val, 0, 0);
   if (get_string(out_val, 0, (int)strlen(out_val), j))
     inscribe(&inventory[item_val], out_val);
 }
    }
  else
    msg_print("You are not carrying anything to inscribe.");
}

variable_types: j int


decompiled_code:
__int64 check_view()
{
__int64 v0; // rbp
__int64 v1; // rbx
__int64 result; // rax
__int64 v3; // rbx
int v4; // er12
__int16 v5; // cx
int i; // ebx
int v7; // edx

v0 = char_col;
v1 = char_row;
if ( (unsigned int)get_panel((unsigned int)char_row, (unsigned int)char_col, 0LL) )
prt_map();
result = move_light((unsigned int)char_row, (unsigned int)char_col, (unsigned int)char_row, (unsigned int)char_col);
v3 = v0 + 198 * v1;
if ( *((_BYTE *)&cave + 4 * v3 + 2) == 2 )
{
if ( py[201] <= 0 && (*((_BYTE *)&cave + 4 * v3 + 3) & 4) == 0 )
result = light_room((unsigned int)char_row, (unsigned int)char_col);
return result;
}
if ( (*((_BYTE *)&cave + 4 * v3 + 3) & 1) == 0 || py[201] > 0 )
return result;
LODWORD(result) = char_col;
v4 = char_row - 1;
v5 = char_col;
while ( 2 )
{
for ( i = result - 1; (*((_WORD *)&cave + 396 * v4 + 2 * i + 1) & 0x4FF) != 2; i = v7 )
{
result = (unsigned int)v5;
v7 = i + 1;
if ( (int)result < i )
goto LABEL_16;
LABEL_13:
;
}
light_room((unsigned int)v4, (unsigned int)i);
v5 = char_col;
v7 = i + 1;
result = (unsigned int)char_col;
if ( (int)result >= i )
goto LABEL_13;
LABEL_16:
if ( char_row >= v4 )
{
++v4;
continue;
}
return result;
}
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbp
__int64 v1; // rbx
__int64 result; // rax
__int64 v3; // rbx
int v4; // er12
__int16 v5; // cx
int i; // ebx
int v7; // edx

v0 = char_col;
v1 = char_row;
if ( (unsigned int)get_panel((unsigned int)char_row, (unsigned int)char_col, 0LL) )
prt_map();
result = move_light((unsigned int)char_row, (unsigned int)char_col, (unsigned int)char_row, (unsigned int)char_col);
v3 = v0 + 198 * v1;
if ( *((_BYTE *)&cave + 4 * v3 + 2) == 2 )
{
if ( py[201] <= 0 && (*((_BYTE *)&cave + 4 * v3 + 3) & 4) == 0 )
result = light_room((unsigned int)char_row, (unsigned int)char_col);
return result;
}
if ( (*((_BYTE *)&cave + 4 * v3 + 3) & 1) == 0 || py[201] > 0 )
return result;
LODWORD(result) = char_col;
v4 = char_row - 1;
v5 = char_col;
while ( 2 )
{
for ( i = result - 1; (*((_WORD *)&cave + 396 * v4 + 2 * i + 1) & 0x4FF) != 2; i = v7 )
{
result = (unsigned int)v5;
v7 = i + 1;
if ( (int)result < i )
goto LABEL_16;
LABEL_13:
;
}
light_room((unsigned int)v4, (unsigned int)i);
v5 = char_col;
v7 = i + 1;
result = (unsigned int)char_col;
if ( (int)result >= i )
goto LABEL_13;
LABEL_16:
if ( char_row >= v4 )
{
++v4;
continue;
}
return result;
}
}

original_code:
void check_view()
{
  register int i, j;
  register cave_type *c_ptr, *d_ptr;
  c_ptr = &cave[char_row][char_col];
  if (get_panel(char_row, char_col, 0))
    prt_map();
  move_light(char_row, char_col, char_row, char_col);
  if (c_ptr->fval == 2)
    {
      if ((py.flags.blind < 1) && !c_ptr->pl)
 light_room(char_row, char_col);
    }
  else if (c_ptr->lr && (py.flags.blind < 1))
    {
      for (i = (char_row - 1); i <= (char_row + 1); i++)
 for (j = (char_col - 1); j <= (char_col + 1); j++)
   {
     d_ptr = &cave[i][j];
     if ((d_ptr->fval == 2) && !d_ptr->pl)
       light_room(i, j);
   }
    }
}

canonical_original_code:
void check_view()
{
  register int i; register int j;
  register struct cave_type *c_ptr; register struct cave_type *d_ptr;
  c_ptr = &cave[char_row][char_col];
  if (get_panel(char_row, char_col, 0))
    prt_map();
  move_light(char_row, char_col, char_row, char_col);
  if (c_ptr->fval == 2)
    {
      if ((py.flags.blind < 1) && !c_ptr->pl)
 light_room(char_row, char_col);
    }
  else if (c_ptr->lr && (py.flags.blind < 1))
    {
      for (i = (char_row - 1); i <= (char_row + 1); i++)
 for (j = (char_col - 1); j <= (char_col + 1); j++)
   {
     d_ptr = &cave[i][j];
     if ((d_ptr->fval == 2) && !d_ptr->pl)
       light_room(i, j);
   }
    }
}

variable_types: i int

variable_types: struct cave_type { unsigned char cptr; unsigned char tptr; unsigned char fval; unsigned int lr; unsigned int fm; unsigned int pl; unsigned int tl; } *


decompiled_code:
unsigned __int64 init_m_level()
{
unsigned __int64 v0; // rax
__int64 v1; // rdx
unsigned __int64 result; // rax

m_level = 0LL;
*(_QWORD *)((char *)&m_level + 74) = 0LL;
memset(
(void *)(((_DWORD)&m_level + 8) & 0xFFFFFFF8),
0,
8LL * (((unsigned int)&m_level - (((_DWORD)&m_level + 8) & 0xFFFFFFF8) + 82) >> 3));
v0 = (unsigned int)((_DWORD)&c_list + 39);
do
{
v1 = *(unsigned __int8 *)v0;
v0 += 40LL;
++*((_WORD *)&m_level + v1);
}
while ( (_DWORD)&c_list + 11119 != v0 );
result = (unsigned int)((_DWORD)&m_level + 2);
do
{
*(_WORD *)result += *(_WORD *)(result - 2);
result += 2LL;
}
while ( (_DWORD)&m_level + 82 != result );
return result;
}

canonical_decompiled_code:
unsigned __int64 func0()
{
unsigned __int64 v0; // rax
__int64 v1; // rdx
unsigned __int64 result; // rax

m_level = 0LL;
*(_QWORD *)((char *)&m_level + 74) = 0LL;
memset(
(void *)(((_DWORD)&m_level + 8) & 0xFFFFFFF8),
0,
8LL * (((unsigned int)&m_level - (((_DWORD)&m_level + 8) & 0xFFFFFFF8) + 82) >> 3));
v0 = (unsigned int)((_DWORD)&c_list + 39);
do
{
v1 = *(unsigned __int8 *)v0;
v0 += 40LL;
++*((_WORD *)&m_level + v1);
}
while ( (_DWORD)&c_list + 11119 != v0 );
result = (unsigned int)((_DWORD)&m_level + 2);
do
{
*(_WORD *)result += *(_WORD *)(result - 2);
result += 2LL;
}
while ( (_DWORD)&m_level + 82 != result );
return result;
}

original_code:
static void init_m_level()
{
  register int i, k;
  for (i = 0; i <= 40; i++)
    m_level[i] = 0;
  k = 279 - 2;
  for (i = 0; i < k; i++)
    m_level[c_list[i].level]++;
  for (i = 1; i <= 40; i++)
    m_level[i] += m_level[i-1];
}

canonical_original_code:
static void init_m_level()
{
  register int i; register int k;
  for (i = 0; i <= 40; i++)
    m_level[i] = 0;
  k = 279 - 2;
  for (i = 0; i < k; i++)
    m_level[c_list[i].level]++;
  for (i = 1; i <= 40; i++)
    m_level[i] += m_level[i-1];
}

variable_types: k int


decompiled_code:
__int64 init_t_level()
{
unsigned __int64 v0; // rdi
unsigned __int8 *v1; // rax
__int64 v2; // rdx
unsigned __int64 v3; // rax
char *v4; // rax
int i; // ecx
__int64 v6; // rsi
int v7; // edx
__int64 result; // rax
int v9[51]; // [rsp+0h] [rbp-D0h] BYREF
char v10; // [rsp+CCh] [rbp-4h] BYREF

t_level = 0LL;
*(_QWORD *)((char *)&t_level + 94) = 0LL;
memset(
(void *)(((_DWORD)&t_level + 8) & 0xFFFFFFF8),
0,
8LL * (((unsigned int)&t_level - (((_DWORD)&t_level + 8) & 0xFFFFFFF8) + 102) >> 3));
v0 = (unsigned int)((_DWORD)&object_list + 46);
v1 = (unsigned __int8 *)v0;
do
{
v2 = *v1;
v1 += 48;
++*((_WORD *)&t_level + v2);
}
while ( v1 != (unsigned __int8 *)((char *)&object_list + 16558) );
v3 = (unsigned int)((_DWORD)&t_level + 2);
do
{
*(_WORD *)v3 += *(_WORD *)(v3 - 2);
v3 += 2LL;
}
while ( (_DWORD)&t_level + 102 != v3 );
v4 = (char *)v9;
do
{
*(_DWORD *)v4 = 1;
v4 += 4;
}
while ( &v10 != v4 );
for ( i = 0; i != 344; ++i )
{
v6 = *(unsigned __int8 *)v0;
v0 += 48LL;
v7 = v9[v6];
result = *((__int16 *)&t_level + v6) - v7;
v9[v6] = v7 + 1;
*((_WORD *)&sorted_objects + (int)result) = i;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned __int64 v0; // rdi
unsigned __int8 *v1; // rax
__int64 v2; // rdx
unsigned __int64 v3; // rax
char *v4; // rax
int i; // ecx
__int64 v6; // rsi
int v7; // edx
__int64 result; // rax
int v9[51]; // [rsp+0h] [rbp-D0h] BYREF
char v10; // [rsp+CCh] [rbp-4h] BYREF

t_level = 0LL;
*(_QWORD *)((char *)&t_level + 94) = 0LL;
memset(
(void *)(((_DWORD)&t_level + 8) & 0xFFFFFFF8),
0,
8LL * (((unsigned int)&t_level - (((_DWORD)&t_level + 8) & 0xFFFFFFF8) + 102) >> 3));
v0 = (unsigned int)((_DWORD)&object_list + 46);
v1 = (unsigned __int8 *)v0;
do
{
v2 = *v1;
v1 += 48;
++*((_WORD *)&t_level + v2);
}
while ( v1 != (unsigned __int8 *)((char *)&object_list + 16558) );
v3 = (unsigned int)((_DWORD)&t_level + 2);
do
{
*(_WORD *)v3 += *(_WORD *)(v3 - 2);
v3 += 2LL;
}
while ( (_DWORD)&t_level + 102 != v3 );
v4 = (char *)v9;
do
{
*(_DWORD *)v4 = 1;
v4 += 4;
}
while ( &v10 != v4 );
for ( i = 0; i != 344; ++i )
{
v6 = *(unsigned __int8 *)v0;
v0 += 48LL;
v7 = v9[v6];
result = *((__int16 *)&t_level + v6) - v7;
v9[v6] = v7 + 1;
*((_WORD *)&sorted_objects + (int)result) = i;
}
return result;
}

original_code:
static void init_t_level()
{
  register int i, l;
  int tmp[50 +1];
  for (i = 0; i <= 50; i++)
    t_level[i] = 0;
  for (i = 0; i < 344; i++)
    t_level[object_list[i].level]++;
  for (i = 1; i <= 50; i++)
    t_level[i] += t_level[i-1];
  for (i = 0; i <= 50; i++)
    tmp[i] = 1;
  for (i = 0; i < 344; i++)
    {
      l = object_list[i].level;
      sorted_objects[t_level[l] - tmp[l]] = i;
      tmp[l]++;
    }
}

canonical_original_code:
static void init_t_level()
{
  register int i; register int l;
  int tmp[-1];
  for (i = 0; i <= 50; i++)
    t_level[i] = 0;
  for (i = 0; i < 344; i++)
    t_level[object_list[i].level]++;
  for (i = 1; i <= 50; i++)
    t_level[i] += t_level[i-1];
  for (i = 0; i <= 50; i++)
    tmp[i] = 1;
  for (i = 0; i < 344; i++)
    {
      l = object_list[i].level;
      sorted_objects[t_level[l] - tmp[l]] = i;
      tmp[l]++;
    }
}

variable_types: l int

variable_types:
tmp
int [-1]


decompiled_code:
unsigned __int64 price_adjust()
{
unsigned __int64 v0; // rsi
__int64 v1; // rax
__int64 v2; // rcx
unsigned __int64 result; // rax

v0 = (unsigned int)((_DWORD)&object_list + 24);
do
{
v1 = *(_QWORD *)v0;
v0 += 48LL;
v2 = 100 * v1 + 50;
result = 0xA3D70A3D70A3D70BLL * v2;
*(_QWORD *)(v0 - 48) = v2 / 100;
}
while ( (_UNKNOWN *)v0 != (_UNKNOWN *)((char *)&object_list + 20184) );
return result;
}

canonical_decompiled_code:
unsigned __int64 func2()
{
unsigned __int64 v0; // rsi
__int64 v1; // rax
__int64 v2; // rcx
unsigned __int64 result; // rax

v0 = (unsigned int)((_DWORD)&object_list + 24);
do
{
v1 = *(_QWORD *)v0;
v0 += 48LL;
v2 = 100 * v1 + 50;
result = 0xA3D70A3D70A3D70BLL * v2;
*(_QWORD *)(v0 - 48) = v2 / 100;
}
while ( (_UNKNOWN *)v0 != (_UNKNOWN *)((char *)&object_list + 20184) );
return result;
}

original_code:
static void price_adjust()
{
  register int i;
  for (i = 0; i < 420; i++)
    object_list[i].cost = ((object_list[i].cost * 100) + 50) / 100;
}


decompiled_code:
__int64 char_inven_init()
{
char *v0; // rbx
char *v1; // rdi
int i; // ebx
__int64 result; // rax
_BYTE v4[55]; // [rsp+0h] [rbp-58h] BYREF
char v5; // [rsp+37h] [rbp-21h]

v0 = (char *)&inventory;
do
{
v1 = v0;
v0 += 56;
invcopy(v1, 417LL);
}
while ( (char *)(unsigned int)((_DWORD)&inventory + 1904) != v0 );
for ( i = 0; i != 5; ++i )
{
invcopy(v4, player_init[5 * py[104] + i]);
store_bought(v4);
if ( v4[24] == 23 )
v5 |= 0x20u;
result = inven_carry(v4);
}
spell_order[0] = _mm_load_si128((const __m128i *)&LC0);
spell_order[1] = spell_order[0];
return result;
}

canonical_decompiled_code:
__int64 func3()
{
char *v0; // rbx
char *v1; // rdi
int i; // ebx
__int64 result; // rax
_BYTE v4[55]; // [rsp+0h] [rbp-58h] BYREF
char v5; // [rsp+37h] [rbp-21h]

v0 = (char *)&inventory;
do
{
v1 = v0;
v0 += 56;
invcopy(v1, 417LL);
}
while ( (char *)(unsigned int)((_DWORD)&inventory + 1904) != v0 );
for ( i = 0; i != 5; ++i )
{
invcopy(v4, player_init[5 * py[104] + i]);
store_bought(v4);
if ( v4[24] == 23 )
v5 |= 0x20u;
result = inven_carry(v4);
}
spell_order[0] = _mm_load_si128((const __m128i *)&LC0);
spell_order[1] = spell_order[0];
return result;
}

original_code:
static void char_inven_init()
{
  register int i, j;
  inven_type inven_init;
  for (i = 0; i < 34; i++)
    invcopy(&inventory[i], 417);
  for (i = 0; i < 5; i++)
    {
      j = player_init[py.misc.pclass][i];
      invcopy(&inven_init, j);
      store_bought(&inven_init);
      if (inven_init.tval == 23)
 inven_init.ident |= 0x20;
      (void) inven_carry(&inven_init);
    }
  for (i = 0; i < 32; i++)
    spell_order[i] = 99;
}

canonical_original_code:
static void char_inven_init()
{
  register int i; register int j;
  struct inven_type inven_init;
  for (i = 0; i < 34; i++)
    invcopy(&inventory[i], 417);
  for (i = 0; i < 5; i++)
    {
      j = player_init[py.misc.pclass][i];
      invcopy(&inven_init, j);
      store_bought(&inven_init);
      if (inven_init.tval == 23)
 inven_init.ident |= 0x20;
      (void) inven_carry(&inven_init);
    }
  for (i = 0; i < 32; i++)
    spell_order[i] = 99;
}

variable_types: struct inven_type { unsigned short index; unsigned char name2; char inscrip[13]; unsigned long flags; unsigned char tval; unsigned char tchar; short p1; long cost; unsigned char subval; unsigned char number; unsigned short weight; short tohit; short todam; short ac; short toac; unsigned char damage[2]; unsigned char level; unsigned char ident; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r15
int v4; // er13
__int64 v5; // rbp
const char *v6; // r14
const char *v7; // rsi
__int64 v8; // rax
char v9; // al
char *v11; // rdx
int v12; // [rsp+8h] [rbp-50h]
int v13; // [rsp+Ch] [rbp-4Ch]
int v14[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v3 = argv + 1;
rogue_like_commands = 1;
init_scorefile(argc, argv, envp);
init_curses();
if ( argc <= 1 )
{
v12 = 0;
v4 = 0;
v5 = 0LL;
v13 = 0;
}
else
{
v12 = 0;
v4 = 0;
v5 = 0LL;
v13 = 0;
do
{
v6 = *v3;
if ( **v3 != 45 )
break;
switch ( v6[1] )
{
case 'N':
case 'n':
v13 = 1;
break;
case 'O':
case 'o':
v12 = 0;
v4 = 1;
break;
case 'R':
case 'r':
v12 = 1;
v4 = 1;
break;
case 'S':
display_scores(1LL);
exit_game();
goto LABEL_23;
case 'W':
case 'w':
goto LABEL_24;
case 's':
LABEL_23:
display_scores(0LL);
exit_game();
v6 = *v3;
LABEL_24:
to_be_wizard = 1;
if ( ((*_ctype_b_loc())[v6[2]] & 0x800) != 0 )
v5 = atoi(v6 + 2);
break;
default:
puts("Usage: moria [-norsw] [savefile]");
exit_game();
break;
}
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
}
read_times();
price_adjust();
init_seeds(v5);
init_m_level();
init_t_level();
store_init();
v7 = *v3;
if ( *v3 || (v7 = getenv("MORIA_SAV")) != 0LL )
{
strcpy(&savefile, v7);
}
else
{
v11 = getenv("HOME");
if ( v11 )
sprintf(&savefile, "%s/%s", v11, "moria.save");
else
strcpy(&savefile, "moria.save");
}
if ( v13 || access(&savefile, 0) || !(unsigned int)get_char(v14) )
{
if ( to_be_wizard && !(unsigned int)enter_wiz_mode() )
exit_game();
create_character();
birth_date = time(0LL);
char_inven_init();
v8 = py[104];
*(_DWORD *)&py[408] = 138572;
v9 = class[32 * v8 + 28];
if ( v9 == 1 )
{
clear_screen();
calc_spells(1LL);
calc_mana(1LL);
}
else if ( v9 == 2 )
{
calc_spells(2LL);
clear_screen();
calc_mana(2LL);
}
character_generated = 1;
v14[0] = 1;
}
else
{
if ( to_be_wizard && !(unsigned int)enter_wiz_mode() )
exit_game();
change_name();
if ( *(__int16 *)&py[112] < 0 )
death = 1;
}
if ( v4 )
rogue_like_commands = v12;
magic_init();
clear_screen();
prt_stat_block();
if ( v14[0] )
goto LABEL_28;
while ( !death )
{
dungeon();
if ( eof_flag )
{
strcpy((char *)&died_from + 16, "aved)");
died_from = _mm_load_si128((const __m128i *)&LC6);
if ( !(unsigned int)save_char() )
{
strcpy((char *)&died_from + 8, "ed eof");
died_from = 0x7463657078656E75LL;
}
death = 1;
break;
}
if ( death )
break;
LABEL_28:
generate_cave();
}
exit_game();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r15
int v4; // er13
__int64 v5; // rbp
const char *v6; // r14
const char *v7; // rsi
__int64 v8; // rax
char v9; // al
char *v11; // rdx
int v12; // [rsp+8h] [rbp-50h]
int v13; // [rsp+Ch] [rbp-4Ch]
int v14[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v3 = argv + 1;
rogue_like_commands = 1;
init_scorefile(argc, argv, envp);
init_curses();
if ( argc <= 1 )
{
v12 = 0;
v4 = 0;
v5 = 0LL;
v13 = 0;
}
else
{
v12 = 0;
v4 = 0;
v5 = 0LL;
v13 = 0;
do
{
v6 = *v3;
if ( **v3 != 45 )
break;
switch ( v6[1] )
{
case 'N':
case 'n':
v13 = 1;
break;
case 'O':
case 'o':
v12 = 0;
v4 = 1;
break;
case 'R':
case 'r':
v12 = 1;
v4 = 1;
break;
case 'S':
display_scores(1LL);
exit_game();
goto LABEL_23;
case 'W':
case 'w':
goto LABEL_24;
case 's':
LABEL_23:
display_scores(0LL);
exit_game();
v6 = *v3;
LABEL_24:
to_be_wizard = 1;
if ( ((*_ctype_b_loc())[v6[2]] & 0x800) != 0 )
v5 = atoi(v6 + 2);
break;
default:
puts("Usage: moria [-norsw] [savefile]");
exit_game();
break;
}
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
}
read_times();
func2();
init_seeds(v5);
func0();
func1();
store_init();
v7 = *v3;
if ( *v3 || (v7 = getenv("MORIA_SAV")) != 0LL )
{
strcpy(&savefile, v7);
}
else
{
v11 = getenv("HOME");
if ( v11 )
sprintf(&savefile, "%s/%s", v11, "moria.save");
else
strcpy(&savefile, "moria.save");
}
if ( v13 || access(&savefile, 0) || !(unsigned int)get_char(v14) )
{
if ( to_be_wizard && !(unsigned int)enter_wiz_mode() )
exit_game();
create_character();
birth_date = time(0LL);
func3();
v8 = py[104];
*(_DWORD *)&py[408] = 138572;
v9 = class[32 * v8 + 28];
if ( v9 == 1 )
{
clear_screen();
calc_spells(1LL);
calc_mana(1LL);
}
else if ( v9 == 2 )
{
calc_spells(2LL);
clear_screen();
calc_mana(2LL);
}
character_generated = 1;
v14[0] = 1;
}
else
{
if ( to_be_wizard && !(unsigned int)enter_wiz_mode() )
exit_game();
change_name();
if ( *(__int16 *)&py[112] < 0 )
death = 1;
}
if ( v4 )
rogue_like_commands = v12;
magic_init();
clear_screen();
prt_stat_block();
if ( v14[0] )
goto LABEL_28;
while ( !death )
{
dungeon();
if ( eof_flag )
{
strcpy((char *)&died_from + 16, "aved)");
died_from = _mm_load_si128((const __m128i *)&LC6);
if ( !(unsigned int)save_char() )
{
strcpy((char *)&died_from + 8, "ed eof");
died_from = 0x7463657078656E75LL;
}
death = 1;
break;
}
if ( death )
break;
LABEL_28:
generate_cave();
}
exit_game();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int32u seed;
  int generate;
  int result;
  char *p;
  int new_game = 0;
  int force_rogue_like = 0;
  int force_keys_to = 0;
  rogue_like_commands = 1;
  init_scorefile();
  init_curses();
  seed = 0;
  for (--argc, ++argv; argc > 0 && argv[0][0] == '-'; --argc, ++argv)
    switch (argv[0][1])
      {
      case 'N':
      case 'n': new_game = 1; break;
      case 'O':
      case 'o':
 force_rogue_like = 1;
 force_keys_to = 0;
 break;
      case 'R':
      case 'r':
 force_rogue_like = 1;
 force_keys_to = 1;
 break;
      case 'S': display_scores(1); exit_game();
      case 's': display_scores(0); exit_game();
      case 'W':
      case 'w':
 to_be_wizard = 1;
 if (((*__ctype_b_loc ())[(int) (((int)argv[0][2]))] & (unsigned short int) _ISdigit))
   seed = atoi(&argv[0][2]);
 break;
      default: (void) printf("Usage: moria [-norsw] [savefile]\n");
 exit_game();
      }
  read_times();
  price_adjust();
  init_seeds(seed);
  init_m_level();
  init_t_level();
  store_init();
  if (argv[0] != (char *)0)
    (void) strcpy (savefile, argv[0]);
  else if ((p = getenv("MORIA_SAV")) != (char *)0)
    (void) strcpy(savefile, p);
  else if ((p = getenv("HOME")) != (char *)0)
    (void) sprintf(savefile, "%s/%s", p, "moria.save");
  else
    (void) strcpy(savefile, "moria.save");
  result = 0;
  if ((new_game == 0) && !access(savefile, 0) && get_char(&generate))
    result = 1;
  if (to_be_wizard)
    if (!enter_wiz_mode())
      exit_game();
  if (result)
    {
      change_name();
      if (py.misc.chp < 0)
 death = 1;
    }
  else
    {
      create_character();
      birth_date = time ((long *)0);
      char_inven_init();
      py.flags.food = 7500;
      py.flags.food_digested = 2;
      if (class[py.misc.pclass].spell == 1)
 {
   clear_screen();
   calc_spells(1);
   calc_mana(1);
 }
      else if (class[py.misc.pclass].spell == 2)
 {
   calc_spells(2);
   clear_screen();
   calc_mana(2);
 }
      character_generated = 1;
      generate = 1;
    }
  if (force_rogue_like)
    rogue_like_commands = force_keys_to;
  magic_init();
  clear_screen();
  prt_stat_block();
  if (generate)
    generate_cave();
  while(!death)
    {
      dungeon();
      if (eof_flag)
 {
   (void) strcpy(died_from, "(end of input: saved)");
   if (!save_char())
     {
       (void) strcpy(died_from, "unexpected eof");
     }
   death = 1;
 }
      if (!death) generate_cave();
    }
  exit_game();
  return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  unsigned long seed;
  int generate;
  int result;
  char *p;
  int new_game = 0;
  int force_rogue_like = 0;
  int force_keys_to = 0;
  rogue_like_commands = 1;
  init_scorefile();
  init_curses();
  seed = 0;
  for (--argc, ++argv; argc > 0 && argv[0][0] == '-'; --argc, ++argv)
    switch (argv[0][1])
      {
      case 'N':
      case 'n': new_game = 1; break;
      case 'O':
      case 'o':
 force_rogue_like = 1;
 force_keys_to = 0;
 break;
      case 'R':
      case 'r':
 force_rogue_like = 1;
 force_keys_to = 1;
 break;
      case 'S': display_scores(1); exit_game();
      case 's': display_scores(0); exit_game();
      case 'W':
      case 'w':
 to_be_wizard = 1;
 if (((*__ctype_b_loc ())[(int) (((int)argv[0][2]))] & (unsigned short) _ISdigit))
   seed = atoi(&argv[0][2]);
 break;
      default: (void) printf("Usage: moria [-norsw] [savefile]\n");
 exit_game();
      }
  read_times();
  price_adjust();
  init_seeds(seed);
  init_m_level();
  init_t_level();
  store_init();
  if (argv[0] != (char *)0)
    (void) strcpy (savefile, argv[0]);
  else if ((p = getenv("MORIA_SAV")) != (char *)0)
    (void) strcpy(savefile, p);
  else if ((p = getenv("HOME")) != (char *)0)
    (void) sprintf(savefile, "%s/%s", p, "moria.save");
  else
    (void) strcpy(savefile, "moria.save");
  result = 0;
  if ((new_game == 0) && !access(savefile, 0) && get_char(&generate))
    result = 1;
  if (to_be_wizard)
    if (!enter_wiz_mode())
      exit_game();
  if (result)
    {
      change_name();
      if (py.misc.chp < 0)
 death = 1;
    }
  else
    {
      create_character();
      birth_date = time ((long *)0);
      char_inven_init();
      py.flags.food = 7500;
      py.flags.food_digested = 2;
      if (class[py.misc.pclass].spell == 1)
 {
   clear_screen();
   calc_spells(1);
   calc_mana(1);
 }
      else if (class[py.misc.pclass].spell == 2)
 {
   calc_spells(2);
   clear_screen();
   calc_mana(2);
 }
      character_generated = 1;
      generate = 1;
    }
  if (force_rogue_like)
    rogue_like_commands = force_keys_to;
  magic_init();
  clear_screen();
  prt_stat_block();
  if (generate)
    generate_cave();
  while(!death)
    {
      dungeon();
      if (eof_flag)
 {
   (void) strcpy(died_from, "(end of input: saved)");
   if (!save_char())
     {
       (void) strcpy(died_from, "unexpected eof");
     }
   death = 1;
 }
      if (!death) generate_cave();
    }
  exit_game();
  return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
seed
unsigned long

variable_types: generate int

variable_types: result int

variable_types:
p
char *