decompiled_code:
char *__fastcall options_name_thumb(char *src)
{
size_t v1; // rax
char *v2; // r12
char *v3; // rax
const char *v4; // r13
char *v5; // rdx

v1 = strlen(src);
v2 = (char *)malloc(v1 + 7);
v3 = strrchr(src, 46);
if ( v3 )
{
v4 = v3;
strncpy(v2, src, v3 - src);
v5 = &v2[strlen(v2)];
*(_DWORD *)v5 = 1969779757;
*((_WORD *)v5 + 2) = 25197;
strcpy(v5 + 6, v4);
}
else
{
sprintf(v2, "%s-thumb", src);
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
size_t v1; // rax
char *v2; // r12
char *v3; // rax
const char *v4; // r13
char *v5; // rdx

v1 = strlen(src);
v2 = (char *)malloc(v1 + 7);
v3 = strrchr(src, 46);
if ( v3 )
{
v4 = v3;
strncpy(v2, src, v3 - src);
v5 = &v2[strlen(v2)];
*(_DWORD *)v5 = 1969779757;
*((_WORD *)v5 + 2) = 25197;
strcpy(v5 + 6, v4);
}
else
{
sprintf(v2, "%s-thumb", src);
}
return v2;
}

original_code:
static char *options_name_thumb(const char *name)
{
 char *thumb = malloc(strlen(name) + sizeof("-thumb"));
 char *dot = strrchr(name, '.');
 if (dot != ((void *)0)) {
  strncpy(thumb, name, (size_t)(dot - name));
  strcat(thumb, "-thumb");
  strcat(thumb, dot);
 } else {
  sprintf(thumb, "%s-thumb", name);
 }
 return thumb;
}

canonical_original_code:
static char *options_name_thumb(char *name)
{
 char *thumb = malloc(strlen(name) + sizeof("-thumb"));
 char *dot = strrchr(name, '.');
 if (dot != ((void *)0)) {
  strncpy(thumb, name, (unsigned long)(dot - name));
  strcat(thumb, "-thumb");
  strcat(thumb, dot);
 } else {
  sprintf(thumb, "%s-thumb", name);
 }
 return thumb;
}

variable_types:
name
char *

variable_types:
thumb
char *

variable_types:
dot
char *


repo: mahkoh/scrot

decompiled_code:
__int64 __fastcall options_init(int argc, char **argv)
{
_DWORD *v3; // rax
__int64 v4; // rbx
int v5; // eax
char *v6; // r15
size_t v7; // r14
void *v8; // rax
__int64 result; // rax
char *v10; // rdx
char *v11; // rdi
int v12; // ecx
int v13; // edx
const char *v14; // rdx
int longind; // [rsp+Ch] [rbp-1DCh] BYREF
struct option longopts[14]; // [rsp+10h] [rbp-1D8h] BYREF

v3 = calloc(1uLL, 0x38uLL);
v3[8] = 75;
v4 = (__int64)v3;
qmemcpy(longopts, &off_480, 0x1A0uLL);
longind = 0;
while ( 1 )
{
v5 = getopt_long(argc, argv, "bcd:e:hmq:swt:v+:", longopts, &longind);
if ( v5 == -1 )
break;
switch ( v5 )
{
case '+':
*(_DWORD *)(v4 + 24) = atoi(optarg);
break;
case 'b':
*(_BYTE *)(v4 + 51) = 1;
break;
case 'c':
*(_BYTE *)(v4 + 48) = 1;
break;
case 'd':
*(_DWORD *)(v4 + 28) = atoi(optarg);
break;
case 'e':
v6 = optarg;
v7 = strlen(optarg) + 1;
v8 = malloc(v7);
*(_QWORD *)(v4 + 16) = memcpy(v8, v6, v7);
break;
case 'h':
help_show_usage();
break;
case 'm':
*(_BYTE *)(v4 + 52) = 1;
break;
case 'q':
*(_DWORD *)(v4 + 32) = atoi(optarg);
break;
case 's':
*(_BYTE *)(v4 + 49) = 1;
break;
case 't':
options_init_thumbnail((_DWORD *)v4, optarg);
break;
case 'v':
help_show_version();
break;
case 'w':
*(_BYTE *)(v4 + 50) = 1;
break;
default:
continue;
}
}
result = optind;
if ( optind < argc )
{
LABEL_21:
v10 = *(char **)v4;
while ( argc > (int)result )
{
v11 = argv[result];
v12 = result + 1;
if ( v10 )
{
v14 = argv[result];
optind = result + 1;
fprintf(stderr, "unrecognised option %s\n", v14);
exit(1);
}
v13 = *(_DWORD *)(v4 + 36);
*(_QWORD *)v4 = v11;
++result;
if ( v13 )
{
optind = v12;
*(_QWORD *)(v4 + 8) = options_name_thumb(v11);
result = optind;
goto LABEL_21;
}
v10 = v11;
}
}
else
{
v10 = *(char **)v4;
}
optind = 1;
if ( !v10 )
{
*(_QWORD *)v4 = "%Y-%m-%d-%H%M%S_$wx$h_scrot.png";
*(_QWORD *)(v4 + 8) = "%Y-%m-%d-%H%M%S_$wx$h_scrot-thumb.png";
}
opt = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int argc, char **argv)
{
_DWORD *v3; // rax
__int64 v4; // rbx
int v5; // eax
char *v6; // r15
size_t v7; // r14
void *v8; // rax
__int64 result; // rax
char *v10; // rdx
char *v11; // rdi
int v12; // ecx
int v13; // edx
const char *v14; // rdx
int longind; // [rsp+Ch] [rbp-1DCh] BYREF
struct option longopts[14]; // [rsp+10h] [rbp-1D8h] BYREF

v3 = calloc(1uLL, 0x38uLL);
v3[8] = 75;
v4 = (__int64)v3;
qmemcpy(longopts, &off_480, 0x1A0uLL);
longind = 0;
while ( 1 )
{
v5 = getopt_long(argc, argv, "bcd:e:hmq:swt:v+:", longopts, &longind);
if ( v5 == -1 )
break;
switch ( v5 )
{
case '+':
*(_DWORD *)(v4 + 24) = atoi(optarg);
break;
case 'b':
*(_BYTE *)(v4 + 51) = 1;
break;
case 'c':
*(_BYTE *)(v4 + 48) = 1;
break;
case 'd':
*(_DWORD *)(v4 + 28) = atoi(optarg);
break;
case 'e':
v6 = optarg;
v7 = strlen(optarg) + 1;
v8 = malloc(v7);
*(_QWORD *)(v4 + 16) = memcpy(v8, v6, v7);
break;
case 'h':
help_show_usage();
break;
case 'm':
*(_BYTE *)(v4 + 52) = 1;
break;
case 'q':
*(_DWORD *)(v4 + 32) = atoi(optarg);
break;
case 's':
*(_BYTE *)(v4 + 49) = 1;
break;
case 't':
func0((_DWORD *)v4, optarg);
break;
case 'v':
help_show_version();
break;
case 'w':
*(_BYTE *)(v4 + 50) = 1;
break;
default:
continue;
}
}
result = optind;
if ( optind < argc )
{
LABEL_21:
v10 = *(char **)v4;
while ( argc > (int)result )
{
v11 = argv[result];
v12 = result + 1;
if ( v10 )
{
v14 = argv[result];
optind = result + 1;
fprintf(stderr, "unrecognised option %s\n", v14);
exit(1);
}
v13 = *(_DWORD *)(v4 + 36);
*(_QWORD *)v4 = v11;
++result;
if ( v13 )
{
optind = v12;
*(_QWORD *)(v4 + 8) = func1(v11);
result = optind;
goto LABEL_21;
}
v10 = v11;
}
}
else
{
v10 = *(char **)v4;
}
optind = 1;
if ( !v10 )
{
*(_QWORD *)v4 = "%Y-%m-%d-%H%M%S_$wx$h_scrot.png";
*(_QWORD *)(v4 + 8) = "%Y-%m-%d-%H%M%S_$wx$h_scrot-thumb.png";
}
opt = v4;
return result;
}

original_code:
void options_init(int argc, char **argv)
{
 struct Options *tmp_opt = calloc(1, sizeof(*tmp_opt));
 tmp_opt->quality = 75;
 const char *stropts = "bcd:e:hmq:swt:v+:";
 struct option lopts[] = {
  {"help", 0, 0, 'h'},
  {"version", 0, 0, 'v'},
  {"count", 0, 0, 'c'},
  {"select", 0, 0, 's'},
  {"window", 0, 0, 'w'},
  {"border", 0, 0, 'b'},
  {"multidisp", 0, 0, 'm'},
  {"thumb", 1, 0, 't'},
  {"delay", 1, 0, 'd'},
  {"quality", 1, 0, 'q'},
  {"exec", 1, 0, 'e'},
  {"debug-level", 1, 0, '+'},
  {0, 0, 0, 0}
 };
 int optch = 0;
 int cmdx = 0;
 while ((optch = getopt_long(argc, argv, stropts, lopts, &cmdx)) != (-1)) {
  switch (optch) {
  case 0:
   break;
  case 'h':
   help_show_usage();
   break;
  case 'v':
   help_show_version();
   break;
  case 'b':
   tmp_opt->border = 1;
   break;
  case 'd':
   tmp_opt->delay = atoi(optarg);
   break;
  case 'e':
   tmp_opt->exec = strcpy(malloc(strlen(optarg) + 1), optarg);
   break;
  case 'm':
   tmp_opt->multidisp = 1;
   break;
  case 'q':
   tmp_opt->quality = atoi(optarg);
   break;
  case 's':
   tmp_opt->select = 1;
   break;
  case 'w':
   tmp_opt->window = 1;
   break;
  case '+':
   tmp_opt->debug_level = atoi(optarg);
   break;
  case 'c':
   tmp_opt->countdown = 1;
   break;
  case 't':
   options_init_thumbnail(tmp_opt, optarg);
   break;
  default:
   break;
  }
 }
 if (optind < argc) {
  while (optind < argc) {
   if (tmp_opt->output_file == ((void *)0)) {
    tmp_opt->output_file = argv[optind++];
    if (tmp_opt->thumb) {
     tmp_opt->thumb_file = options_name_thumb(tmp_opt->output_file);
    }
   } else {
    fprintf(stderr, "unrecognised option %s\n", argv[optind++]);
    exit(1);
   }
  }
 }
 optind = 1;
 if (tmp_opt->output_file == ((void *)0)) {
  tmp_opt->output_file = "%Y-%m-%d-%H%M%S_$wx$h_scrot.png";
  tmp_opt->thumb_file = "%Y-%m-%d-%H%M%S_$wx$h_scrot-thumb.png";
 }
 opt = tmp_opt;
}

canonical_original_code:
void options_init(int argc, char **argv)
{
 struct Options *tmp_opt = calloc(1, sizeof(*tmp_opt));
 tmp_opt->quality = 75;
 char *stropts = "bcd:e:hmq:swt:v+:";
 struct option lopts[] = {
  {"help", 0, 0, 'h'},
  {"version", 0, 0, 'v'},
  {"count", 0, 0, 'c'},
  {"select", 0, 0, 's'},
  {"window", 0, 0, 'w'},
  {"border", 0, 0, 'b'},
  {"multidisp", 0, 0, 'm'},
  {"thumb", 1, 0, 't'},
  {"delay", 1, 0, 'd'},
  {"quality", 1, 0, 'q'},
  {"exec", 1, 0, 'e'},
  {"debug-level", 1, 0, '+'},
  {0, 0, 0, 0}
 };
 int optch = 0;
 int cmdx = 0;
 while ((optch = getopt_long(argc, argv, stropts, lopts, &cmdx)) != (-1)) {
  switch (optch) {
  case 0:
   break;
  case 'h':
   help_show_usage();
   break;
  case 'v':
   help_show_version();
   break;
  case 'b':
   tmp_opt->border = 1;
   break;
  case 'd':
   tmp_opt->delay = atoi(optarg);
   break;
  case 'e':
   tmp_opt->exec = strcpy(malloc(strlen(optarg) + 1), optarg);
   break;
  case 'm':
   tmp_opt->multidisp = 1;
   break;
  case 'q':
   tmp_opt->quality = atoi(optarg);
   break;
  case 's':
   tmp_opt->select = 1;
   break;
  case 'w':
   tmp_opt->window = 1;
   break;
  case '+':
   tmp_opt->debug_level = atoi(optarg);
   break;
  case 'c':
   tmp_opt->countdown = 1;
   break;
  case 't':
   options_init_thumbnail(tmp_opt, optarg);
   break;
  default:
   break;
  }
 }
 if (optind < argc) {
  while (optind < argc) {
   if (tmp_opt->output_file == ((void *)0)) {
    tmp_opt->output_file = argv[optind++];
    if (tmp_opt->thumb) {
     tmp_opt->thumb_file = options_name_thumb(tmp_opt->output_file);
    }
   } else {
    fprintf(stderr, "unrecognised option %s\n", argv[optind++]);
    exit(1);
   }
  }
 }
 optind = 1;
 if (tmp_opt->output_file == ((void *)0)) {
  tmp_opt->output_file = "%Y-%m-%d-%H%M%S_$wx$h_scrot.png";
  tmp_opt->thumb_file = "%Y-%m-%d-%H%M%S_$wx$h_scrot-thumb.png";
 }
 opt = tmp_opt;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct Options { char *output_file; char *thumb_file; char *exec; int debug_level; int delay; int quality; int thumb; int thumb_width; int thumb_height; _Bool countdown; _Bool select; _Bool window; _Bool border; _Bool multidisp; } *

variable_types:
stropts
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: optch int

variable_types: cmdx int

return_type: void


decompiled_code:
char *__fastcall util_fmt_int(char *format, unsigned int a2)
{
sprintf(tmp_0, format, a2);
return tmp_0;
}

canonical_decompiled_code:
char *__fastcall func0(char *format, unsigned int a2)
{
sprintf(tmp_0, format, a2);
return tmp_0;
}

original_code:
static char *util_fmt_int(char *fmt, int n)
{
 static char tmp[32];
 sprintf(tmp, fmt, n);
 return tmp;
}

variable_types:
fmt
char *

variable_types: n int

variable_types:
tmp
char [32]

return_type: char *


decompiled_code:
char *__fastcall util_fmt_char(char a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rbp
__int64 v5; // r12
unsigned int v7; // eax
unsigned int v8; // esi
char *result; // rax
int v10; // ebp
int v11; // er8
struct stat v12; // [rsp-30h] [rbp-A8h] BYREF
__int64 v13; // [rsp+68h] [rbp-10h]
__int64 v14; // [rsp+70h] [rbp-8h]

if ( a1 == 36 )
return "$";
v14 = v5;
v13 = v4;
switch ( a1 )
{
case 'f':
return (char *)a2;
case 'h':
v7 = image_height(a4);
goto LABEL_4;
case 'm':
return (char *)a3;
case 'n':
result = 0LL;
if ( a2 )
{
result = strrchr(a2, 47);
if ( !result )
result = (char *)a2;
}
return result;
case 'p':
v10 = image_width(a4);
v8 = image_height(a4) * v10;
goto LABEL_5;
case 's':
result = 0LL;
if ( a2 )
{
v11 = stat(a2, &v12);
result = "[err]";
if ( !v11 )
result = util_fmt_int("%d", v12.st_size);
}
return result;
case 't':
return (char *)image_format(a4);
case 'w':
v7 = image_width(a4);
LABEL_4:
v8 = v7;
LABEL_5:
result = util_fmt_int("%d", v8);
break;
default:
result = util_fmt_int("%c", a1);
break;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rbp
__int64 v5; // r12
unsigned int v7; // eax
unsigned int v8; // esi
char *result; // rax
int v10; // ebp
int v11; // er8
struct stat v12; // [rsp-30h] [rbp-A8h] BYREF
__int64 v13; // [rsp+68h] [rbp-10h]
__int64 v14; // [rsp+70h] [rbp-8h]

if ( a1 == 36 )
return "$";
v14 = v5;
v13 = v4;
switch ( a1 )
{
case 'f':
return (char *)a2;
case 'h':
v7 = image_height(a4);
goto LABEL_4;
case 'm':
return (char *)a3;
case 'n':
result = 0LL;
if ( a2 )
{
result = strrchr(a2, 47);
if ( !result )
result = (char *)a2;
}
return result;
case 'p':
v10 = image_width(a4);
v8 = image_height(a4) * v10;
goto LABEL_5;
case 's':
result = 0LL;
if ( a2 )
{
v11 = stat(a2, &v12);
result = "[err]";
if ( !v11 )
result = func0("%d", v12.st_size);
}
return result;
case 't':
return (char *)image_format(a4);
case 'w':
v7 = image_width(a4);
LABEL_4:
v8 = v7;
LABEL_5:
result = func0("%d", v8);
break;
default:
result = func0("%c", a1);
break;
}
return result;
}

original_code:
static char *util_fmt_char(char c, char *path_im, char *path_thumb, Image im)
{
 switch (c) {
 case 'f':
  return path_im;
 case 'm':
  return path_thumb;
 case 'n':
  if (path_im) {
   char *tmp = strrchr(path_im, '/');
   if (tmp)
    return tmp;
  }
  return path_im;
 case 'w':
  return util_fmt_int("%d", image_width(im));
 case 'h':
  return util_fmt_int("%d", image_height(im));
 case 's':
  if (path_im) {
   struct stat st;
   if (!stat(path_im, &st))
    return util_fmt_int("%d", st.st_size);
   else
    return "[err]";
  }
  return ((void *)0);
 case 'p':
  return util_fmt_int("%d", image_width(im) * image_height(im));
 case 't':
  return image_format(im);
 case '$':
  return "$";
 default:
  return util_fmt_int("%c", c);
 }
}

canonical_original_code:
static char *util_fmt_char(char c, char *path_im, char *path_thumb, void *im)
{
 switch (c) {
 case 'f':
  return path_im;
 case 'm':
  return path_thumb;
 case 'n':
  if (path_im) {
   char *tmp = strrchr(path_im, '/');
   if (tmp)
    return tmp;
  }
  return path_im;
 case 'w':
  return util_fmt_int("%d", image_width(im));
 case 'h':
  return util_fmt_int("%d", image_height(im));
 case 's':
  if (path_im) {
   struct stat st;
   if (!stat(path_im, &st))
    return util_fmt_int("%d", st.st_size);
   else
    return "[err]";
  }
  return ((void *)0);
 case 'p':
  return util_fmt_int("%d", image_width(im) * image_height(im));
 case 't':
  return image_format(im);
 case '$':
  return "$";
 default:
  return util_fmt_int("%c", c);
 }
}

variable_types: c char

variable_types:
im
void *

variable_types:
tmp
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; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


original_code:
char *util_fmt_str(const char *str, struct tm *tm, char *path_im, char *path_thumb, Image im)
{
 size_t buff_len = 4092;
 char buf[buff_len];
 strftime(buf, buff_len-1, str, tm);
 int left = buff_len;
 char *ret = malloc(buff_len);
 ret[0] = '\0';
 for (char *c = buf; *c != '\0'; c++) {
  if (*c != '$' && *c != '\\') {
   if (left == 1) {
    left += buff_len;
    buff_len *= 2;
    ret = realloc(ret, buff_len);
   }
   ret[buff_len-left] = *c;
   left--;
   ret[buff_len-left] = '\0';
   continue;
  }
  char *tmp = ((void *)0);
  if (*c == '$') {
   c++;
   tmp = util_fmt_char(*c, path_im, path_thumb, im);
  } else if (*c == '\\') {
   c++;
   if (*c == 'n') {
    if (path_im != ((void *)0))
     tmp = "\n";
   } else {
    tmp = util_fmt_int("%c", *c);
   }
  }
  if (tmp != ((void *)0)) {
   int len = strlen(tmp);
   while (left < len + 1) {
    left += buff_len;
    buff_len *= 2;
    ret = realloc(ret, buff_len);
   }
   left -= len;
   strcat(ret, tmp);
  }
 }
 return ret;
}

canonical_original_code:
char *util_fmt_str(char *str, struct tm *tm, char *path_im, char *path_thumb, void *im)
{
 unsigned long buff_len = 4092;
 char buf[-1];
 strftime(buf, buff_len-1, str, tm);
 int left = buff_len;
 char *ret = malloc(buff_len);
 ret[0] = '\0';
 for (char *c = buf; *c != '\0'; c++) {
  if (*c != '$' && *c != '\\') {
   if (left == 1) {
    left += buff_len;
    buff_len *= 2;
    ret = realloc(ret, buff_len);
   }
   ret[buff_len-left] = *c;
   left--;
   ret[buff_len-left] = '\0';
   continue;
  }
  char *tmp = ((void *)0);
  if (*c == '$') {
   c++;
   tmp = util_fmt_char(*c, path_im, path_thumb, im);
  } else if (*c == '\\') {
   c++;
   if (*c == 'n') {
    if (path_im != ((void *)0))
     tmp = "\n";
   } else {
    tmp = util_fmt_int("%c", *c);
   }
  }
  if (tmp != ((void *)0)) {
   int len = strlen(tmp);
   while (left < len + 1) {
    left += buff_len;
    buff_len *= 2;
    ret = realloc(ret, buff_len);
   }
   left -= len;
   strcat(ret, tmp);
  }
 }
 return ret;
}

variable_types:
str
char *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; } *

variable_types:
buf
char [-1]

variable_types: left int

variable_types:
ret
char *

variable_types:
c
char *

variable_types: len int


decompiled_code:
void __noreturn util_error(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

original_code:
void util_error(char *fmt, ...)
{
 va_list args;
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 exit(1);
}

canonical_original_code:
void util_error(char *fmt, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 exit(1);
}


decompiled_code:
__int64 image_X11_init()
{
__int64 v0; // rbp
__int64 v1; // r12
__int64 v2; // rbp
__int64 v3; // rbp

v0 = *(_QWORD *)(disp + 232LL);
v1 = *(_QWORD *)(v0 + ((__int64)XScreenNumberOfScreen(scr) << 7) + 64);
v2 = *(_QWORD *)(disp + 232LL);
v3 = *(_QWORD *)(v2 + ((__int64)XScreenNumberOfScreen(scr) << 7) + 80);
imlib_context_set_display(disp);
imlib_context_set_visual(v1);
imlib_context_set_colormap(v3);
imlib_context_set_color_modifier(0LL);
return imlib_context_set_operation(0LL);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbp
__int64 v1; // r12
__int64 v2; // rbp
__int64 v3; // rbp

v0 = *(_QWORD *)(disp + 232LL);
v1 = *(_QWORD *)(v0 + ((__int64)XScreenNumberOfScreen(scr) << 7) + 64);
v2 = *(_QWORD *)(disp + 232LL);
v3 = *(_QWORD *)(v2 + ((__int64)XScreenNumberOfScreen(scr) << 7) + 80);
imlib_context_set_display(disp);
imlib_context_set_visual(v1);
imlib_context_set_colormap(v3);
imlib_context_set_color_modifier(0LL);
return imlib_context_set_operation(0LL);
}

original_code:
void image_X11_init(void)
{
 Visual *vis = ((&((_XPrivDisplay)(disp))->screens[XScreenNumberOfScreen(scr)])->root_visual);
 Colormap cm = ((&((_XPrivDisplay)(disp))->screens[XScreenNumberOfScreen(scr)])->cmap);
 imlib_context_set_display(disp);
 imlib_context_set_visual(vis);
 imlib_context_set_colormap(cm);
 imlib_context_set_color_modifier(((void *)0));
 imlib_context_set_operation(IMLIB_OP_COPY);
}

canonical_original_code:
void image_X11_init()
{
 struct Visual *vis = ((&((_XPrivDisplay)(disp))->screens[XScreenNumberOfScreen(scr)])->root_visual);
 unsigned long cm = ((&((_XPrivDisplay)(disp))->screens[XScreenNumberOfScreen(scr)])->cmap);
 imlib_context_set_display(disp);
 imlib_context_set_visual(vis);
 imlib_context_set_colormap(cm);
 imlib_context_set_color_modifier(((void *)0));
 imlib_context_set_operation(IMLIB_OP_COPY);
}

variable_types: struct Visual { struct _XExtData { int number; struct _XExtData *next; int (*free_private)(struct _XExtData *extension); char *private_data; } *ext_data; unsigned long visualid; int class; unsigned long red_mask; int bits_per_rgb; int map_entries; } *

variable_types:
cm
unsigned long

user_defined_types: struct Visual { struct _XExtData *ext_data; unsigned long visualid; int class; unsigned long red_mask; int bits_per_rgb; int map_entries; }


decompiled_code:
__int64 image_X11_from_screen()
{
imlib_context_set_drawable(scr->root);
return imlib_create_image_from_drawable(0LL, 0LL, 0LL, (unsigned int)scr->width, (unsigned int)scr->height, 1LL);
}

canonical_decompiled_code:
__int64 func1()
{
imlib_context_set_drawable(scr->root);
return imlib_create_image_from_drawable(0LL, 0LL, 0LL, (unsigned int)scr->width, (unsigned int)scr->height, 1LL);
}

original_code:
Image image_X11_from_screen(void)
{
 imlib_context_set_drawable(scr->root);
 return imlib_create_image_from_drawable(0, 0, 0, scr->width, scr->height, 1);
}

canonical_original_code:
void *image_X11_from_screen()
{
 imlib_context_set_drawable(scr->root);
 return imlib_create_image_from_drawable(0, 0, 0, scr->width, scr->height, 1);
}

return_type: void *


decompiled_code:
__int64 __fastcall image_X11_from_area(unsigned int *a1)
{
imlib_context_set_drawable(scr->root);
return imlib_create_image_from_drawable(0LL, *a1, a1[1], a1[2], a1[3], 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
imlib_context_set_drawable(scr->root);
return imlib_create_image_from_drawable(0LL, *a1, a1[1], a1[2], a1[3], 1LL);
}

original_code:
Image image_X11_from_area(struct Area *area)
{
 imlib_context_set_drawable(scr->root);
 return imlib_create_image_from_drawable(0, area->x, area->y, area->width, area->height, 1);
}

canonical_original_code:
void *image_X11_from_area(struct Area *area)
{
 imlib_context_set_drawable(scr->root);
 return imlib_create_image_from_drawable(0, area->x, area->y, area->width, area->height, 1);
}

variable_types: struct Area { int x; int y; int width; int height; } *


decompiled_code:
// attributes: thunk
__int64 display_init()
{
return display_X11_init();
}

canonical_decompiled_code:
__int64 func0()
{
return display_X11_init();
}

original_code:
_Bool display_init(void)
{
 return display_X11_init();
}

canonical_original_code:
_Bool display_init()
{
 return display_X11_init();
}


decompiled_code:
// attributes: thunk
__int64 display_num_screens()
{
return display_X11_num_screens();
}

canonical_decompiled_code:
__int64 func1()
{
return display_X11_num_screens();
}

original_code:
int display_num_screens(void)
{
 return display_X11_num_screens();
}

canonical_original_code:
int display_num_screens()
{
 return display_X11_num_screens();
}

return_type: int


decompiled_code:
// attributes: thunk
__int64 display_open_screen()
{
return display_X11_open_screen();
}

canonical_decompiled_code:
__int64 func2()
{
return display_X11_open_screen();
}

original_code:
void display_open_screen(int num)
{
 display_X11_open_screen(num);
}

variable_types: num int


decompiled_code:
// attributes: thunk
__int64 display_select_area()
{
return display_X11_select_area();
}

canonical_decompiled_code:
__int64 func3()
{
return display_X11_select_area();
}

original_code:
struct Area *display_select_area(void)
{
 return display_X11_select_area();
}

canonical_original_code:
struct Area *display_select_area()
{
 return display_X11_select_area();
}

return_type: struct Area { int x; int y; int width; int height; } *


decompiled_code:
// attributes: thunk
__int64 display_select_window()
{
return display_X11_select_window();
}

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

original_code:
struct Area *display_select_window(void)
{
 return display_X11_select_window();
}

canonical_original_code:
struct Area *display_select_window()
{
 return display_X11_select_window();
}

user_defined_types: struct Area { int x; int y; int width; int height; }


decompiled_code:
void __noreturn help_show_version()
{
puts("scrot version 0.9.0");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("scrot version 0.9.0");
exit(0);
}

original_code:
void help_show_version(void)
{
 printf("scrot" " version " "0.9.0" "\n");
 exit(0);
}

canonical_original_code:
void help_show_version()
{
 printf("scrot" " version " "0.9.0" "\n");
 exit(0);
}


decompiled_code:
void __noreturn help_show_mini_usage()
{
puts("Usage : scrot [OPTIONS]... FILE\nUse scrot --help for detailed usage information");
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
puts("Usage : scrot [OPTIONS]... FILE\nUse scrot --help for detailed usage information");
exit(0);
}

original_code:
void help_show_mini_usage(void)
{
 printf("Usage : " "scrot" " [OPTIONS]... FILE\n"
        "Use " "scrot" " --help for detailed usage information\n");
 exit(0);
}

canonical_original_code:
void help_show_mini_usage()
{
 printf("Usage : " "scrot" " [OPTIONS]... FILE\n"
        "Use " "scrot" " --help for detailed usage information\n");
 exit(0);
}


decompiled_code:
void __noreturn help_show_usage()
{
fprintf(
stdout,
"Usage : scrot [OPTIONS]... [FILE]\n"
" Where FILE is the target file for the screenshot.\n"
" If FILE is not specified, a date-stamped file will be dropped in the\n"
" current directory.\n"
" See man scrot for more details\n"
" -h, --help display this help and exit\n"
" -v, --version output version information and exit\n"
" -b, --border When selecting a window, grab wm border too\n"
" -c, --count show a countdown before taking the shot\n"
" -d, --delay NUM wait NUM seconds before taking a shot\n"
" -e, --exec APP run APP on the resulting screenshot\n"
" -q, --quality NUM Image quality (1-100) high value means\n"
" high size, low compression. Default: 75.\n"
" For lossless compression formats, like png,\n"
" low quality means high compression.\n"
" -m, --multidisp For multiple heads, grab shot from each\n"
" and join them together.\n"
" -s, --select interactively choose a rectnagle with the mouse\n"
" -w, --window interactively choose a window with the mouse\n"
" -t, --thumb NUM generate thumbnail too. NUM is the percentage\n"
" of the original size for the thumbnail to be,\n"
" or the geometry in percent, e.g. 50x60 or 80x20.\n"
"\n"
" SPECIAL STRINGS\n"
" Both the --exec and filename parameters can take format specifiers\n"
" that are expanded by scrot when encountered.\n"
" There are two types of format specifier. Characters preceded by a '%%'\n"
" are interpretted by strftime(2). See man strftime for examples.\n"
" These options may be used to refer to the current date and time.\n"
" The second kind are internal to scrot and are prefixed by '$'\n"
" The following specifiers are recognised:\n"
" $f image path/filename (ignored when used in the filename)\n"
" $m thumbnail path/filename\n"
" $n image name (ignored when used in the filename)\n"
" $s image size (bytes) (ignored when used in the filename)\n"
" $p image pixel size\n"
" $w image width\n"
" $h image height\n"
" $t image format\n"
" $$ prints a literal '$'\n"
" \\n prints a newline (ignored when used in the filename)\n"
" Example:\n"
" scrot '%%Y-%%m-%%d_$wx$h_scrot.png' -e 'mv $f ~/images/shots/'\n"
" Creates a file called something like 2013-10-12_1024x768_scrot.png\n"
" and moves it to your images directory.\n"
"\n"
"This program is free software. See the file COPYING for licensing info.\n"
"Copyright Tom Gilbert 2000\n"
"Copyright mahkoh 2013\n"
"Report bugs at https://github.com/mahkoh/scrot/issues\n");
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
fprintf(
stdout,
"Usage : scrot [OPTIONS]... [FILE]\n"
" Where FILE is the target file for the screenshot.\n"
" If FILE is not specified, a date-stamped file will be dropped in the\n"
" current directory.\n"
" See man scrot for more details\n"
" -h, --help display this help and exit\n"
" -v, --version output version information and exit\n"
" -b, --border When selecting a window, grab wm border too\n"
" -c, --count show a countdown before taking the shot\n"
" -d, --delay NUM wait NUM seconds before taking a shot\n"
" -e, --exec APP run APP on the resulting screenshot\n"
" -q, --quality NUM Image quality (1-100) high value means\n"
" high size, low compression. Default: 75.\n"
" For lossless compression formats, like png,\n"
" low quality means high compression.\n"
" -m, --multidisp For multiple heads, grab shot from each\n"
" and join them together.\n"
" -s, --select interactively choose a rectnagle with the mouse\n"
" -w, --window interactively choose a window with the mouse\n"
" -t, --thumb NUM generate thumbnail too. NUM is the percentage\n"
" of the original size for the thumbnail to be,\n"
" or the geometry in percent, e.g. 50x60 or 80x20.\n"
"\n"
" SPECIAL STRINGS\n"
" Both the --exec and filename parameters can take format specifiers\n"
" that are expanded by scrot when encountered.\n"
" There are two types of format specifier. Characters preceded by a '%%'\n"
" are interpretted by strftime(2). See man strftime for examples.\n"
" These options may be used to refer to the current date and time.\n"
" The second kind are internal to scrot and are prefixed by '$'\n"
" The following specifiers are recognised:\n"
" $f image path/filename (ignored when used in the filename)\n"
" $m thumbnail path/filename\n"
" $n image name (ignored when used in the filename)\n"
" $s image size (bytes) (ignored when used in the filename)\n"
" $p image pixel size\n"
" $w image width\n"
" $h image height\n"
" $t image format\n"
" $$ prints a literal '$'\n"
" \\n prints a newline (ignored when used in the filename)\n"
" Example:\n"
" scrot '%%Y-%%m-%%d_$wx$h_scrot.png' -e 'mv $f ~/images/shots/'\n"
" Creates a file called something like 2013-10-12_1024x768_scrot.png\n"
" and moves it to your images directory.\n"
"\n"
"This program is free software. See the file COPYING for licensing info.\n"
"Copyright Tom Gilbert 2000\n"
"Copyright mahkoh 2013\n"
"Report bugs at https://github.com/mahkoh/scrot/issues\n");
exit(0);
}

original_code:
void help_show_usage(void)
{
 fprintf(stdout,
   "Usage : " "scrot" " [OPTIONS]... [FILE]\n"
   "  Where FILE is the target file for the screenshot.\n"
   "  If FILE is not specified, a date-stamped file will be dropped in the\n"
   "  current directory.\n" "  See man " "scrot" " for more details\n"
   "  -h, --help                display this help and exit\n"
   "  -v, --version             output version information and exit\n"
   "  -b, --border              When selecting a window, grab wm border too\n"
   "  -c, --count               show a countdown before taking the shot\n"
   "  -d, --delay NUM           wait NUM seconds before taking a shot\n"
   "  -e, --exec APP            run APP on the resulting screenshot\n"
   "  -q, --quality NUM         Image quality (1-100) high value means\n"
   "                            high size, low compression. Default: 75.\n"
   "                            For lossless compression formats, like png,\n"
   "                            low quality means high compression.\n"
   "  -m, --multidisp           For multiple heads, grab shot from each\n"
   "                            and join them together.\n"
   "  -s, --select              interactively choose a rectnagle with the mouse\n"
   "  -w, --window              interactively choose a window with the mouse\n"
   "  -t, --thumb NUM           generate thumbnail too. NUM is the percentage\n"
   "                            of the original size for the thumbnail to be,\n"
   "                            or the geometry in percent, e.g. 50x60 or 80x20.\n"
   "\n" "  SPECIAL STRINGS\n"
   "  Both the --exec and filename parameters can take format specifiers\n"
   "  that are expanded by " "scrot" " when encountered.\n"
   "  There are two types of format specifier. Characters preceded by a '%%'\n"
   "  are interpretted by strftime(2). See man strftime for examples.\n"
   "  These options may be used to refer to the current date and time.\n"
   "  The second kind are internal to " "scrot"
   "  and are prefixed by '$'\n"
   "  The following specifiers are recognised:\n"
   "                  $f image path/filename (ignored when used in the filename)\n"
   "                  $m thumbnail path/filename\n"
   "                  $n image name (ignored when used in the filename)\n"
   "                  $s image size (bytes) (ignored when used in the filename)\n"
   "                  $p image pixel size\n"
   "                  $w image width\n"
   "                  $h image height\n"
   "                  $t image format\n"
   "                  $$  prints a literal '$'\n"
   "                  \\n prints a newline (ignored when used in the filename)\n"
   "  Example:\n" "          " "scrot"
   " '%%Y-%%m-%%d_$wx$h_scrot.png' -e 'mv $f ~/images/shots/'\n"
   "          Creates a file called something like 2013-10-12_1024x768_scrot.png\n"
   "          and moves it to your images directory.\n" "\n"
   "This program is free software. See the file COPYING for licensing info.\n"
   "Copyright Tom Gilbert 2000\n"
   "Copyright mahkoh 2013\n"
   "Report bugs at https://github.com/mahkoh/scrot/issues\n");
 exit(0);
}

canonical_original_code:
void help_show_usage()
{
 fprintf(stdout,
   "Usage : " "scrot" " [OPTIONS]... [FILE]\n"
   "  Where FILE is the target file for the screenshot.\n"
   "  If FILE is not specified, a date-stamped file will be dropped in the\n"
   "  current directory.\n" "  See man " "scrot" " for more details\n"
   "  -h, --help                display this help and exit\n"
   "  -v, --version             output version information and exit\n"
   "  -b, --border              When selecting a window, grab wm border too\n"
   "  -c, --count               show a countdown before taking the shot\n"
   "  -d, --delay NUM           wait NUM seconds before taking a shot\n"
   "  -e, --exec APP            run APP on the resulting screenshot\n"
   "  -q, --quality NUM         Image quality (1-100) high value means\n"
   "                            high size, low compression. Default: 75.\n"
   "                            For lossless compression formats, like png,\n"
   "                            low quality means high compression.\n"
   "  -m, --multidisp           For multiple heads, grab shot from each\n"
   "                            and join them together.\n"
   "  -s, --select              interactively choose a rectnagle with the mouse\n"
   "  -w, --window              interactively choose a window with the mouse\n"
   "  -t, --thumb NUM           generate thumbnail too. NUM is the percentage\n"
   "                            of the original size for the thumbnail to be,\n"
   "                            or the geometry in percent, e.g. 50x60 or 80x20.\n"
   "\n" "  SPECIAL STRINGS\n"
   "  Both the --exec and filename parameters can take format specifiers\n"
   "  that are expanded by " "scrot" " when encountered.\n"
   "  There are two types of format specifier. Characters preceded by a '%%'\n"
   "  are interpretted by strftime(2). See man strftime for examples.\n"
   "  These options may be used to refer to the current date and time.\n"
   "  The second kind are internal to " "scrot"
   "  and are prefixed by '$'\n"
   "  The following specifiers are recognised:\n"
   "                  $f image path/filename (ignored when used in the filename)\n"
   "                  $m thumbnail path/filename\n"
   "                  $n image name (ignored when used in the filename)\n"
   "                  $s image size (bytes) (ignored when used in the filename)\n"
   "                  $p image pixel size\n"
   "                  $w image width\n"
   "                  $h image height\n"
   "                  $t image format\n"
   "                  $$  prints a literal '$'\n"
   "                  \\n prints a newline (ignored when used in the filename)\n"
   "  Example:\n" "          " "scrot"
   " '%%Y-%%m-%%d_$wx$h_scrot.png' -e 'mv $f ~/images/shots/'\n"
   "          Creates a file called something like 2013-10-12_1024x768_scrot.png\n"
   "          and moves it to your images directory.\n" "\n"
   "This program is free software. See the file COPYING for licensing info.\n"
   "Copyright Tom Gilbert 2000\n"
   "Copyright mahkoh 2013\n"
   "Report bugs at https://github.com/mahkoh/scrot/issues\n");
 exit(0);
}


decompiled_code:
int close_server()
{
int result; // eax
char v1; // [rsp-108h] [rbp-108h] BYREF

if ( ser_wr_fp )
{
if ( ser_rd_fp )
{
put_server("QUIT");
get_server(&v1, 256);
fclose(ser_wr_fp);
result = fclose(ser_rd_fp);
}
}
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax
char v1; // [rsp-108h] [rbp-108h] BYREF

if ( ser_wr_fp )
{
if ( ser_rd_fp )
{
func3("QUIT");
func4(&v1, 256);
fclose(ser_wr_fp);
result = fclose(ser_rd_fp);
}
}
return result;
}

original_code:
void
close_server()
{
 char ser_line[256];
 if (ser_wr_fp == ((void *)0) || ser_rd_fp == ((void *)0))
  return;
 put_server("QUIT");
 (void) get_server(ser_line, sizeof(ser_line));
 (void) fclose(ser_wr_fp);
 (void) fclose(ser_rd_fp);
}


main

canonical_name: main

repo: majuscule/rotomatic

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

if ( argc == 1 )
v3 = find_powermate(0LL, argv, envp);
else
v3 = open_powermate(argv[1], 0LL, envp);
if ( v3 < 0 )
{
fwrite("Unable to locate powermate\n", 1uLL, 0x1BuLL, _bss_start);
fprintf(_bss_start, "Try: %s [device]\n", *argv);
result = 1;
}
else
{
notify_init();
watch_powermate(v3);
close(v3);
result = 0;
}
return result;
}

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

if ( argc == 1 )
v3 = func8(0LL, argv, envp);
else
v3 = func7(argv[1], 0LL, envp);
if ( v3 < 0 )
{
fwrite("Unable to locate powermate\n", 1uLL, 0x1BuLL, _bss_start);
fprintf(_bss_start, "Try: %s [device]\n", *argv);
result = 1;
}
else
{
notify_init();
func10(v3);
close(v3);
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
  int powermate = -1;
  if(argc == 1)
    powermate = find_powermate(00);
  else
    powermate = open_powermate(argv[1], 00);
  if(powermate < 0){
    fprintf(stderr, "Unable to locate powermate\n");
    fprintf(stderr, "Try: %s [device]\n", argv[0]);
    return 1;
  }
  notify_init("powermate");
  watch_powermate(powermate);
  close(powermate);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: powermate int


decompiled_code:
__int64 __fastcall open_powermate(const char *a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
int v4; // edi
int *v6; // rax
char *v7; // rax
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = open(a1, a2);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
if ( ioctl(v2, 0x80FF4506uLL, v8) < 0 )
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(_bss_start, "\"%s\": EVIOCGNAME failed: %s\n", a1, v7);
LABEL_5:
v4 = v3;
v3 = -1;
close(v4);
return v3;
}
if ( strncasecmp(v8, "Griffin PowerMate", 0x11uLL) && strncasecmp(v8, "Griffin SoundKnob", 0x11uLL) )
goto LABEL_5;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
int v4; // edi
int *v6; // rax
char *v7; // rax
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = open(a1, a2);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
if ( ioctl(v2, 0x80FF4506uLL, v8) < 0 )
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(_bss_start, "\"%s\": EVIOCGNAME failed: %s\n", a1, v7);
LABEL_5:
v4 = v3;
v3 = -1;
close(v4);
return v3;
}
if ( strncasecmp(v8, "Griffin PowerMate", 0x11uLL) && strncasecmp(v8, "Griffin SoundKnob", 0x11uLL) )
goto LABEL_5;
return v3;
}

original_code:
int open_powermate(const char *dev, int mode)
{
  int fd = open(dev, mode);
  int i;
  char name[255];
  if(fd < 0){
    return -1;
  }
  if(ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (('E') << (0 +8)) | ((0x06) << 0) | ((sizeof(name)) << ((0 +8)+8))), name) < 0){
    fprintf(stderr, "\"%s\": EVIOCGNAME failed: %s\n", dev, strerror((*__errno_location ())));
    close(fd);
    return -1;
  }
  for(i=0; i<2; i++)
    if(!strncasecmp(name, valid_prefix[i], strlen(valid_prefix[i])))
      return fd;
  close(fd);
  return -1;
}

canonical_original_code:
int open_powermate(char *dev, int mode)
{
  int fd = open(dev, mode);
  int i;
  char name[255];
  if(fd < 0){
    return -1;
  }
  if(ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (('E') << (0 +8)) | ((0x06) << 0) | ((sizeof(name)) << ((0 +8)+8))), name) < 0){
    fprintf(stderr, "\"%s\": EVIOCGNAME failed: %s\n", dev, strerror((*__errno_location ())));
    close(fd);
    return -1;
  }
  for(i=0; i<2; i++)
    if(!strncasecmp(name, valid_prefix[i], strlen(valid_prefix[i])))
      return fd;
  close(fd);
  return -1;
}

variable_types:
dev
char *

variable_types: mode int

variable_types: fd int

variable_types: i int

variable_types:
name
char [255]


decompiled_code:
__int64 __fastcall find_powermate(int a1)
{
unsigned int v1; // ebx
__int64 result; // rax
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = 0;
while ( 1 )
{
sprintf(v3, "/dev/input/event%d", v1);
result = open_powermate(v3, a1);
if ( (int)result >= 0 )
break;
if ( ++v1 == 16 )
{
fwrite("Unable to locate or open a PowerMate", 1uLL, 0x24uLL, _bss_start);
return 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned int v1; // ebx
__int64 result; // rax
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = 0;
while ( 1 )
{
sprintf(v3, "/dev/input/event%d", v1);
result = func7(v3, a1);
if ( (int)result >= 0 )
break;
if ( ++v1 == 16 )
{
fwrite("Unable to locate or open a PowerMate", 1uLL, 0x24uLL, _bss_start);
return 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int find_powermate(int mode)
{
  char devname[256];
  int i, r;
  for(i=0; i<16; i++){
    sprintf(devname, "/dev/input/event%d", i);
    r = open_powermate(devname, mode);
    if(r >= 0)
      return r;
  }
  fprintf(stderr, "Unable to locate or open a PowerMate");
  return -1;
}

canonical_original_code:
int find_powermate(int mode)
{
  char devname[256];
  int i; int r;
  for(i=0; i<16; i++){
    sprintf(devname, "/dev/input/event%d", i);
    r = open_powermate(devname, mode);
    if(r >= 0)
      return r;
  }
  fprintf(stderr, "Unable to locate or open a PowerMate");
  return -1;
}

variable_types:
devname
char [256]

variable_types: r int


decompiled_code:
__int64 __fastcall handle_error(const char *a1)
{
fprintf(stderr, "Error: %s\n", a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
fprintf(stderr, "Error: %s\n", a1);
return 0xFFFFFFFFLL;
}

original_code:
int handle_error(char *txt)
{
 fprintf(stderr, "Error: %s\n", txt);
 return -1;
}

variable_types:
txt
char *


decompiled_code:
__int64 __fastcall check_known_device(__int64 a1)
{
char **v1; // rax
const char *v2; // rdx

v1 = &g_known_devices;
v2 = g_known_devices;
if ( !g_known_devices )
return 0LL;
while ( *(_DWORD *)(a1 + 4136) != *((_DWORD *)v1 + 2) )
{
v2 = v1[2];
v1 += 2;
if ( !v2 )
return 0LL;
}
fprintf(stderr, "Found %s\n", v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
char **v1; // rax
const char *v2; // rdx

v1 = &g_known_devices;
v2 = g_known_devices;
if ( !g_known_devices )
return 0LL;
while ( *(_DWORD *)(a1 + 4136) != *((_DWORD *)v1 + 2) )
{
v2 = v1[2];
v1 += 2;
if ( !v2 )
return 0LL;
}
fprintf(stderr, "Found %s\n", v2);
return 1LL;
}

original_code:
int check_known_device(struct usb_device *d)
{
 struct known_device *dev = g_known_devices;
 while (dev->desc) {
  if ((d->descriptor.idVendor == dev->vid) &&
   (d->descriptor.idProduct == dev->pid)) {
    fprintf(stderr, "Found %s\n", dev->desc);
    return 1;
  }
  dev++;
 }
 return 0;
}

variable_types: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device *devices; unsigned int location; struct usb_device *root_dev; } *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *

variable_types: struct known_device { char *desc; unsigned short vid; unsigned short pid; } *

user_defined_types: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus *bus; struct usb_device_descriptor descriptor; struct usb_config_descriptor *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; }

user_defined_types: struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface *interface; unsigned char *extra; int extralen; }

user_defined_types: struct usb_interface { struct usb_interface_descriptor *altsetting; int num_altsetting; }

user_defined_types: struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor *endpoint; unsigned char *extra; int extralen; }


decompiled_code:
int __fastcall memory_dump(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
int v3; // ebp
int result; // eax

if ( a2 )
{
v2 = a1;
v3 = 1;
result = printf("%02x ", *a1);
while ( v2 != &a1[a2 - 1] )
{
++v3;
result = printf("%02x ", v2[1]);
if ( v3 == 16 )
{
v3 = 0;
result = putchar(10);
}
++v2;
}
if ( v3 )
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
int v3; // ebp
int result; // eax

if ( a2 )
{
v2 = a1;
v3 = 1;
result = printf("%02x ", *a1);
while ( v2 != &a1[a2 - 1] )
{
++v3;
result = printf("%02x ", v2[1]);
if ( v3 == 16 )
{
v3 = 0;
result = putchar(10);
}
++v2;
}
if ( v3 )
result = putchar(10);
}
return result;
}

original_code:
void memory_dump(unsigned char *buf, unsigned int n)
{
 int i = 0;
 int c = 0;
 while (i < n) {
  printf("%02x ", buf[i]);
  c++;
  if (c == 16) { c = 0; printf("\n"); }
   i++;
 }
 if (c)
  printf("\n");
}

variable_types:
buf
unsigned char *

variable_types:
n
unsigned int

variable_types: c int


decompiled_code:
__int64 __fastcall get_rand(int a1, int a2)
{
unsigned int v3; // eax

if ( !init_0 )
{
v3 = getpid();
srand(v3);
init_0 = 1;
}
return (unsigned int)(rand() % (a2 - a1 + 1) + a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
unsigned int v3; // eax

if ( !init_0 )
{
v3 = getpid();
srand(v3);
init_0 = 1;
}
return (unsigned int)(rand() % (a2 - a1 + 1) + a1);
}

original_code:
int get_rand(int min, int max) {
 static int init = 0;
 int roll;
 if (init == 0) {
  srand(getpid());
  init = 1;
 }
 roll = (rand() % (max - min + 1) + min );
    return roll;
}

variable_types: min int

variable_types: max int

variable_types: init int

variable_types: roll int


decompiled_code:
__int64 roll_2d6()
{
int v0; // ebx

v0 = get_rand(1, 6);
return v0 + (unsigned int)get_rand(1, 6);
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx

v0 = func0(1, 6);
return v0 + (unsigned int)func0(1, 6);
}

original_code:
int roll_2d6() {
    return get_rand(1,6) + get_rand(1,6);
}


decompiled_code:
__int64 roll_1d6()
{
return get_rand(1, 6);
}

canonical_decompiled_code:
__int64 func2()
{
return func0(1, 6);
}

original_code:
int roll_1d6() {
    int roll;
    roll = get_rand(1,6);
    return roll;
}


decompiled_code:
_BOOL8 __fastcall roll_2d6_vs(int a1)
{
return (int)roll_2d6() >= a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
return (int)func1() >= a1;
}

original_code:
int roll_2d6_vs(int target) {
    int roll;
    int success = 0;
    roll = roll_2d6();
    if (roll >= target) {
        success = 1;
    }
    return success;
}

variable_types: target int

variable_types: success int


decompiled_code:
__int64 roll_average_traveller_stat()
{
int v0; // ebx

v0 = get_rand(2, 5);
return v0 + (unsigned int)get_rand(2, 5);
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx

v0 = func0(2, 5);
return v0 + (unsigned int)func0(2, 5);
}

original_code:
int roll_average_traveller_stat() {
    int roll;
    roll = get_rand(2,5) + get_rand(2,5);
    return roll;
}


decompiled_code:
__int64 __fastcall roll_strong_traveller_stat(int a1)
{
int v1; // ebx

v1 = get_rand(2, 6);
return a1 + v1 + (unsigned int)get_rand(2, 6);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // ebx

v1 = func0(2, 6);
return a1 + v1 + (unsigned int)func0(2, 6);
}

original_code:
int roll_strong_traveller_stat(int add) {
    return get_rand(2,6) + get_rand(2,6) + add;
}

variable_types: add int


usage

repo: makiftasova/little-utils

decompiled_code:
int __fastcall usage(const char *a1)
{
puts("Usage:\n------");
printf("%s [NAME]\n", a1);
puts("\nWARNING: This program requires root privileges to do its job\n");
puts("Exit Codes:\n-----------");
puts("\t0 - Exit Success");
puts("\t1 - Failed to run because of lack of root privileges");
return puts("\t2 - Failed to run because of illegal arguments given");
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
puts("Usage:\n------");
printf("%s [NAME]\n", a1);
puts("\nWARNING: This program requires root privileges to do its job\n");
puts("Exit Codes:\n-----------");
puts("\t0 - Exit Success");
puts("\t1 - Failed to run because of lack of root privileges");
return puts("\t2 - Failed to run because of illegal arguments given");
}

original_code:
void usage(const char* execName) {
    printf("Usage:\n------\n");
    printf("%s [NAME]\n", execName);
    printf("\nWARNING: This program requires root privileges to do its job\n\n");
    printf("Exit Codes:\n-----------\n");
    printf("\t0 - Exit Success\n");
    printf("\t1 - Failed to run because of lack of root privileges\n");
    printf("\t2 - Failed to run because of illegal arguments given\n");
    return;
}

canonical_original_code:
void usage(char *execName) {
    printf("Usage:\n------\n");
    printf("%s [NAME]\n", execName);
    printf("\nWARNING: This program requires root privileges to do its job\n\n");
    printf("Exit Codes:\n-----------\n");
    printf("\t0 - Exit Success\n");
    printf("\t1 - Failed to run because of lack of root privileges\n");
    printf("\t2 - Failed to run because of illegal arguments given\n");
    return;
}

variable_types:
execName
char *


main

repo: makobi/High-Performance-Computing

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
double v4; // r12
int v5; // eax
double *v6; // rbp
__int64 i; // r13
double *v8; // rax
double v9; // xmm0_8
double v11; // [rsp+0h] [rbp-38h]
double v12; // [rsp+0h] [rbp-38h]
double v13; // [rsp+8h] [rbp-30h]

v3 = 10;
v4 = 10.0;
v11 = 0.0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "n:l:r:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'n':
v3 = atoi(optarg);
break;
case 'r':
v4 = atof(optarg);
break;
case 'l':
v11 = atof(optarg);
break;
default:
fprintf(stderr, "Usage: %s [-n NUMBER_OF_RECTANGLES] [-l X_LEFT] [-r X_RIGHT]\n", *argv);
exit(-1);
}
}
v6 = (double *)malloc(8LL * v3);
v13 = v11 + 0.0;
v12 = (v4 - v11) / (double)v3;
if ( v3 <= 0 )
{
v9 = 0.0;
}
else
{
for ( i = 0LL; i != v3; ++i )
v6[i] = FUNC((double)(int)i * v12 + v13) * v12;
v8 = v6;
v9 = 0.0;
do
v9 = v9 + *v8++;
while ( v8 != &v6[(unsigned int)(v3 - 1) + 1] );
}
printf("%f\n", v9);
free(v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
double v4; // r12
int v5; // eax
double *v6; // rbp
__int64 i; // r13
double *v8; // rax
double v9; // xmm0_8
double v11; // [rsp+0h] [rbp-38h]
double v12; // [rsp+0h] [rbp-38h]
double v13; // [rsp+8h] [rbp-30h]

v3 = 10;
v4 = 10.0;
v11 = 0.0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "n:l:r:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'n':
v3 = atoi(optarg);
break;
case 'r':
v4 = atof(optarg);
break;
case 'l':
v11 = atof(optarg);
break;
default:
fprintf(stderr, "Usage: %s [-n NUMBER_OF_RECTANGLES] [-l X_LEFT] [-r X_RIGHT]\n", *argv);
exit(-1);
}
}
v6 = (double *)malloc(8LL * v3);
v13 = v11 + 0.0;
v12 = (v4 - v11) / (double)v3;
if ( v3 <= 0 )
{
v9 = 0.0;
}
else
{
for ( i = 0LL; i != v3; ++i )
v6[i] = func7((double)(int)i * v12 + v13) * v12;
v8 = v6;
v9 = 0.0;
do
v9 = v9 + *v8++;
while ( v8 != &v6[(unsigned int)(v3 - 1) + 1] );
}
printf("%f\n", v9);
free(v6);
return 0;
}

original_code:
int main(int argc, char** argv)
{
    int OUR_RANK = 0, OUR_NUMBER_OF_THREADS = 1, OUR_NUMBER_OF_RECTANGLES = 10,
        NUMBER_OF_RECTANGLES = 10, NUMBER_OF_PROCESSES = 1, MY_THREAD_NUM = 0,
        my_current_rectangle_id = 0;
    double OUR_X_LEFT = 0.0, X_LEFT = 0.0, X_RIGHT = 10.0, WIDTH = 0.0,
           RECTANGLE_WIDTH = 0.0, our_total_sum = 0.0, the_total_sum = 0.0,
           my_current_rectangle_left = 0.0, my_current_rectangle_height = 0.0;
    double * our_areas;
    int our_cardinality = 0;
    int c;
    while((c = getopt(argc, argv, "n:l:r:")) != -1)
    {
        switch(c)
        {
            case 'n':
                NUMBER_OF_RECTANGLES = atoi(optarg);
                break;
            case 'l':
                X_LEFT = atof(optarg);
                break;
            case 'r':
                X_RIGHT = atof(optarg);
                break;
            case '?':
            default:
                    fprintf(stderr, "Usage: %s [-n NUMBER_OF_RECTANGLES] [-l X_LEFT] [-r X_RIGHT]\n", argv[0]);
                exit(-1);
        }
    }
    argc -= optind;
    argv += optind;
    our_areas = (double*)malloc(NUMBER_OF_RECTANGLES * sizeof(double));
        if(MY_THREAD_NUM == 0)
        {
            WIDTH = X_RIGHT - X_LEFT;
            RECTANGLE_WIDTH = WIDTH / NUMBER_OF_RECTANGLES;
        }
        if(MY_THREAD_NUM == 1 % OUR_NUMBER_OF_THREADS)
        {
            OUR_NUMBER_OF_RECTANGLES = NUMBER_OF_RECTANGLES /
                NUMBER_OF_PROCESSES;
            if(OUR_RANK == NUMBER_OF_PROCESSES - 1)
                OUR_NUMBER_OF_RECTANGLES += NUMBER_OF_RECTANGLES %
                    NUMBER_OF_PROCESSES;
        }
        if(MY_THREAD_NUM == 2 % OUR_NUMBER_OF_THREADS)
        {
            OUR_X_LEFT = (OUR_RANK * (NUMBER_OF_RECTANGLES /
                    NUMBER_OF_PROCESSES)) + X_LEFT;
        }
    for(my_current_rectangle_id = 0; my_current_rectangle_id <
            OUR_NUMBER_OF_RECTANGLES; my_current_rectangle_id++)
    {
        my_current_rectangle_left = OUR_X_LEFT + my_current_rectangle_id
            * RECTANGLE_WIDTH;
        my_current_rectangle_height = FUNC(my_current_rectangle_left);
        our_areas[my_current_rectangle_id] = RECTANGLE_WIDTH *
                    my_current_rectangle_height;
    }
    for(my_current_rectangle_id = 0; my_current_rectangle_id <
            OUR_NUMBER_OF_RECTANGLES; my_current_rectangle_id++)
    {
        our_total_sum += our_areas[my_current_rectangle_id];
    }
        the_total_sum = our_total_sum;
 if (OUR_RANK == 0)
  printf("%f\n", the_total_sum);
    free(our_areas);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int OUR_RANK = 0; int OUR_NUMBER_OF_THREADS = 1; int OUR_NUMBER_OF_RECTANGLES = 10; int NUMBER_OF_RECTANGLES = 10; int NUMBER_OF_PROCESSES = 1; int MY_THREAD_NUM = 0; int my_current_rectangle_id = 0;
    double OUR_X_LEFT = 0.0; double X_LEFT = 0.0; double X_RIGHT = 10.0; double WIDTH = 0.0; double RECTANGLE_WIDTH = 0.0; double our_total_sum = 0.0; double the_total_sum = 0.0; double my_current_rectangle_left = 0.0; double my_current_rectangle_height = 0.0;
    double *our_areas;
    int our_cardinality = 0;
    int c;
    while((c = getopt(argc, argv, "n:l:r:")) != -1)
    {
        switch(c)
        {
            case 'n':
                NUMBER_OF_RECTANGLES = atoi(optarg);
                break;
            case 'l':
                X_LEFT = atof(optarg);
                break;
            case 'r':
                X_RIGHT = atof(optarg);
                break;
            case '?':
            default:
                    fprintf(stderr, "Usage: %s [-n NUMBER_OF_RECTANGLES] [-l X_LEFT] [-r X_RIGHT]\n", argv[0]);
                exit(-1);
        }
    }
    argc -= optind;
    argv += optind;
    our_areas = (double *)malloc(NUMBER_OF_RECTANGLES * sizeof(double));
        if(MY_THREAD_NUM == 0)
        {
            WIDTH = X_RIGHT - X_LEFT;
            RECTANGLE_WIDTH = WIDTH / NUMBER_OF_RECTANGLES;
        }
        if(MY_THREAD_NUM == 1 % OUR_NUMBER_OF_THREADS)
        {
            OUR_NUMBER_OF_RECTANGLES = NUMBER_OF_RECTANGLES /
                NUMBER_OF_PROCESSES;
            if(OUR_RANK == NUMBER_OF_PROCESSES - 1)
                OUR_NUMBER_OF_RECTANGLES += NUMBER_OF_RECTANGLES %
                    NUMBER_OF_PROCESSES;
        }
        if(MY_THREAD_NUM == 2 % OUR_NUMBER_OF_THREADS)
        {
            OUR_X_LEFT = (OUR_RANK * (NUMBER_OF_RECTANGLES /
                    NUMBER_OF_PROCESSES)) + X_LEFT;
        }
    for(my_current_rectangle_id = 0; my_current_rectangle_id <
            OUR_NUMBER_OF_RECTANGLES; my_current_rectangle_id++)
    {
        my_current_rectangle_left = OUR_X_LEFT + my_current_rectangle_id
            * RECTANGLE_WIDTH;
        my_current_rectangle_height = FUNC(my_current_rectangle_left);
        our_areas[my_current_rectangle_id] = RECTANGLE_WIDTH *
                    my_current_rectangle_height;
    }
    for(my_current_rectangle_id = 0; my_current_rectangle_id <
            OUR_NUMBER_OF_RECTANGLES; my_current_rectangle_id++)
    {
        our_total_sum += our_areas[my_current_rectangle_id];
    }
        the_total_sum = our_total_sum;
 if (OUR_RANK == 0)
  printf("%f\n", the_total_sum);
    free(our_areas);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: WIDTH double


FUNC

decompiled_code:
void __fastcall FUNC(double a1)
{
exp(-a1);
}

canonical_decompiled_code:
void __fastcall func7(double a1)
{
exp(-a1);
}

original_code:
double FUNC(double x)
{
    return exp(-x);
}

variable_types: x double

return_type: double


cleanup

repo: malensek/terminibbles

decompiled_code:
void __noreturn cleanup()
{
endwin();
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
endwin();
exit(0);
}

original_code:
void cleanup()
{
    endwin();
    exit(0);
}

canonical_original_code:
void cleanup()
{
    endwin();
    exit(0);
}


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

result = wgetch(stdscr);
if ( paused )
{
if ( (unsigned int)(result - 112) > 1 )
{
result = usleep(0x1F4u);
}
else if ( result == 113 )
{
paused = 0;
LABEL_5:
game_over = 1;
}
else
{
LABEL_20:
paused ^= 1u;
}
}
else if ( result > 119 )
{
if ( result == 260 )
{
LABEL_19:
result = change_direction(&board, 0xFFFFFFFFLL);
}
else if ( result <= 260 )
{
if ( result == 258 )
{
LABEL_17:
result = change_direction(&board, 39LL);
}
else if ( result == 259 )
{
LABEL_16:
result = change_direction(&board, 4294967257LL);
}
}
else if ( result == 261 )
{
LABEL_13:
result = change_direction(&board, 1LL);
}
}
else if ( result > 96 )
{
result -= 97;
switch ( result )
{
case 0:
case 7:
goto LABEL_19;
case 3:
case 11:
goto LABEL_13;
case 9:
case 18:
goto LABEL_17;
case 10:
case 22:
goto LABEL_16;
case 15:
goto LABEL_20;
case 16:
goto LABEL_5;
default:
return result;
}
}
return result;
}

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

result = wgetch(stdscr);
if ( paused )
{
if ( (unsigned int)(result - 112) > 1 )
{
result = usleep(0x1F4u);
}
else if ( result == 113 )
{
paused = 0;
LABEL_5:
game_over = 1;
}
else
{
LABEL_20:
paused ^= 1u;
}
}
else if ( result > 119 )
{
if ( result == 260 )
{
LABEL_19:
result = change_direction(&board, 0xFFFFFFFFLL);
}
else if ( result <= 260 )
{
if ( result == 258 )
{
LABEL_17:
result = change_direction(&board, 39LL);
}
else if ( result == 259 )
{
LABEL_16:
result = change_direction(&board, 4294967257LL);
}
}
else if ( result == 261 )
{
LABEL_13:
result = change_direction(&board, 1LL);
}
}
else if ( result > 96 )
{
result -= 97;
switch ( result )
{
case 0:
case 7:
goto LABEL_19;
case 3:
case 11:
goto LABEL_13;
case 9:
case 18:
goto LABEL_17;
case 10:
case 22:
goto LABEL_16;
case 15:
goto LABEL_20;
case 16:
goto LABEL_5;
default:
return result;
}
}
return result;
}

original_code:
void kbd_events()
{
    int key = wgetch(stdscr);
    if (paused) {
        if (key != 'p' && key != 'q') {
            usleep(500);
            return;
        }
    }
    switch (key) {
    case 'k':
    case 'w':
    case 0403:
        change_direction(&board, -39);
        break;
    case 'j':
    case 's':
    case 0402:
        change_direction(&board, 39);
        break;
    case 'h':
    case 'a':
    case 0404:
        change_direction(&board, -1);
        break;
    case 'l':
    case 'd':
    case 0405:
        change_direction(&board, 1);
        break;
    case 'p':
        paused = !paused;
        break;
    case 'q':
        if (paused) {
            paused = 0;
        }
        game_over = 1;
        break;
    }
}

variable_types: key int


decompiled_code:
int __fastcall draw_tile(int a1, int a2, int a3)
{
unsigned int v4; // er12
int v5; // esi

switch ( a3 )
{
case -7:
v4 = 58;
v5 = 1792;
break;
case -6:
v4 = 2097231;
v5 = 1536;
break;
case -5:
v4 = 32;
v5 = 1280;
break;
default:
v4 = 124;
v5 = 2048;
if ( a3 == -9 )
v4 = 88;
if ( a3 == -9 )
v5 = 2304;
break;
}
wattrset(game_win, v5);
if ( wmove(game_win, a1 + 1, 2 * a2 + 1) != -1 )
waddch(game_win, v4);
waddch(game_win, v4);
return wattrset(game_win, 1280);
}

canonical_decompiled_code:
int __fastcall func2(int a1, int a2, int a3)
{
unsigned int v4; // er12
int v5; // esi

switch ( a3 )
{
case -7:
v4 = 58;
v5 = 1792;
break;
case -6:
v4 = 2097231;
v5 = 1536;
break;
case -5:
v4 = 32;
v5 = 1280;
break;
default:
v4 = 124;
v5 = 2048;
if ( a3 == -9 )
v4 = 88;
if ( a3 == -9 )
v5 = 2304;
break;
}
wattrset(game_win, v5);
if ( wmove(game_win, a1 + 1, 2 * a2 + 1) != -1 )
waddch(game_win, v4);
waddch(game_win, v4);
return wattrset(game_win, 1280);
}

variable_types: y int

variable_types: x int

variable_types: tile int

variable_types:
display
unsigned long


decompiled_code:
int draw_board()
{
unsigned int i; // ebp
unsigned int j; // ebx
int v2; // eax
int v3; // esi

for ( i = 0; i != 22; ++i )
{
for ( j = 0; j != 39; ++j )
{
v2 = board_idx(i, j);
v3 = j;
draw_tile(i, v3, board[v2]);
}
}
return wattrset(game_win, 1280);
}

canonical_decompiled_code:
int func3()
{
unsigned int i; // ebp
unsigned int j; // ebx
int v2; // eax
int v3; // esi

for ( i = 0; i != 22; ++i )
{
for ( j = 0; j != 39; ++j )
{
v2 = board_idx(i, j);
v3 = j;
func2(i, v3, board[v2]);
}
}
return wattrset(game_win, 1280);
}

canonical_original_code:
void draw_board()
{
    int y; int x; int tile;
    for (y = 0; y < 22; ++y) {
        for (x = 0; x < 39; ++x) {
            tile = board.tile[board_idx(y, x)];
            draw_tile(y, x, tile);
        }
    }
    (void) wattrset(game_win, (((chtype)(((- -5))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
}


decompiled_code:
int draw_score()
{
return mvwprintw(game_win, 0, 58, "| Score: %4d |", (unsigned int)score);
}

canonical_decompiled_code:
int func4()
{
return mvwprintw(game_win, 0, 58, "| Score: %4d |", (unsigned int)score);
}

original_code:
void draw_score()
{
    mvwprintw(game_win, 0, 39 * 2 - 20, "| Score: %4d |", score);
}


splash

variable_types:
splash
unsigned char []

variable_types: offset int

variable_types: i int


winy

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

result = 4294967284LL;
if ( stdscr )
result = (unsigned int)((stdscr->_maxy - 21) / 2 - 1);
return result;
}

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

result = 4294967284LL;
if ( stdscr )
result = (unsigned int)((stdscr->_maxy - 21) / 2 - 1);
return result;
}

original_code:
int winy()
{
    int max_row = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1));
    return (max_row - 22) / 2 - 1;
}


winx

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

result = 4294967256LL;
if ( stdscr )
result = (unsigned int)((stdscr->_maxx - 77) / 2 - 1);
return result;
}

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

result = 4294967256LL;
if ( stdscr )
result = (unsigned int)((stdscr->_maxx - 77) / 2 - 1);
return result;
}

original_code:
int winx()
{
    int max_col = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1));
    return (max_col - 39 * 2) / 2 - 1;
}


checksize

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

if ( (int)winy() < 0 || (result = winx(), (int)result < 0) )
{
endwin();
puts("Terminal size not supported.");
exit(1);
}
return result;
}

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

if ( (int)func6() < 0 || (result = func7(), (int)result < 0) )
{
endwin();
puts("Terminal size not supported.");
exit(1);
}
return result;
}

original_code:
void checksize()
{
    if (winy() < 0 || winx() < 0) {
        endwin();
        printf("Terminal size not supported.\n");
        exit(1);
    }
}


refreshwin

decompiled_code:
void __fastcall refreshwin(int a1, __int64 a2)
{
WINDOW *v2; // rdi
unsigned int v3; // eax
__int64 v4; // rdx
__int64 v5; // rcx
int v6; // eax
int v7; // er8

wclear(stdscr);
endwin();
v2 = stdscr;
wrefresh(stdscr);
checksize();
v3 = winx();
v6 = winy(v2, a2, v4, v5, v3);
mvwin(game_win, v6, v7);
wborder(game_win, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
draw_board();
draw_score();
wrefresh(stdscr);
wrefresh(game_win);
}

canonical_decompiled_code:
void __fastcall func9(int a1, __int64 a2)
{
WINDOW *v2; // rdi
unsigned int v3; // eax
__int64 v4; // rdx
__int64 v5; // rcx
int v6; // eax
int v7; // er8

wclear(stdscr);
endwin();
v2 = stdscr;
wrefresh(stdscr);
func8();
v3 = func7();
v6 = func6(v2, a2, v4, v5, v3);
mvwin(game_win, v6, v7);
wborder(game_win, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
func3();
func4();
wrefresh(stdscr);
wrefresh(game_win);
}

original_code:
void refreshwin()
{
    wclear(stdscr);
    endwin();
    wrefresh(stdscr);
    checksize();
    mvwin(game_win, winy(), winx());
    wborder(game_win, 0, 0, 0, 0, 0, 0, 0, 0);
    draw_board();
    draw_score();
    wrefresh(stdscr);
    wrefresh(game_win);
}


decompiled_code:
char *__fastcall conf_dir(char *s)
{
const char *v1; // r12
char *v2; // rbp
size_t v3; // rax
char *v4; // rax

v1 = "/terminibbles/";
v2 = getenv("XDG_CONFIG_HOME");
if ( !v2 )
{
v1 = "/.config/terminibbles/";
v2 = getenv("HOME");
if ( !v2 )
{
v1 = "/";
v2 = "./scores/";
}
}
v3 = strlen(s);
v4 = stpcpy(&s[v3], v2);
return strcpy(v4, v1);
}

canonical_decompiled_code:
char *__fastcall func10(char *s)
{
const char *v1; // r12
char *v2; // rbp
size_t v3; // rax
char *v4; // rax

v1 = "/terminibbles/";
v2 = getenv("XDG_CONFIG_HOME");
if ( !v2 )
{
v1 = "/.config/terminibbles/";
v2 = getenv("HOME");
if ( !v2 )
{
v1 = "/";
v2 = "./scores/";
}
}
v3 = strlen(s);
v4 = stpcpy(&s[v3], v2);
return strcpy(v4, v1);
}

original_code:
void conf_dir(char *buffer)
{
    char *dir;
    char *subdir = "/";
    dir = getenv("XDG_CONFIG_HOME");
    if (dir != ((void *)0)) {
        subdir = "/terminibbles/";
    } else {
        dir = getenv("HOME");
        if (dir != ((void *)0)) {
            subdir = "/.config/terminibbles/";
        } else {
            dir = "./scores/";
        }
    }
    strcat(buffer, dir);
    strcat(buffer, subdir);
}

variable_types:
buffer
char *

variable_types:
dir
char *

variable_types:
subdir
char *


mkpath

decompiled_code:
void __fastcall mkpath(const char *a1)
{
char *v1; // r12
size_t v2; // rbp
__mode_t v3; // ebx
__mode_t v4; // er13
char *v5; // rbx
char *v6; // rbp

v1 = strdup(a1);
v2 = strlen(v1);
v3 = umask(0);
umask(v3);
v4 = 511 - v3;
if ( v2 > 1 )
{
v5 = v1 + 1;
v6 = &v1[v2];
do
{
while ( *v5 != 47 )
{
if ( ++v5 == v6 )
goto LABEL_6;
}
*v5++ = 0;
mkdir(v1, v4);
*(v5 - 1) = 47;
}
while ( v5 != v6 );
}
LABEL_6:
free(v1);
}

canonical_decompiled_code:
void __fastcall func11(const char *a1)
{
char *v1; // r12
size_t v2; // rbp
__mode_t v3; // ebx
__mode_t v4; // er13
char *v5; // rbx
char *v6; // rbp

v1 = strdup(a1);
v2 = strlen(v1);
v3 = umask(0);
umask(v3);
v4 = 511 - v3;
if ( v2 > 1 )
{
v5 = v1 + 1;
v6 = &v1[v2];
do
{
while ( *v5 != 47 )
{
if ( ++v5 == v6 )
goto LABEL_6;
}
*v5++ = 0;
mkdir(v1, v4);
*(v5 - 1) = 47;
}
while ( v5 != v6 );
}
LABEL_6:
free(v1);
}

original_code:
void mkpath(const char *path)
{
    char *pathcp = strdup(path);
    size_t len = strlen(pathcp);
    mode_t mask = umask(0);
    umask(mask);
    mask = 0777 - mask;
    int i;
    for (i = 1; i < len; ++i) {
        if (pathcp[i] == '/') {
            pathcp[i] = 0;
            mkdir(pathcp, mask);
            pathcp[i] = '/';
        }
    }
    free(pathcp);
}

canonical_original_code:
void mkpath(char *path)
{
    char *pathcp = strdup(path);
    unsigned long len = strlen(pathcp);
    unsigned int mask = umask(0);
    umask(mask);
    mask = 0777 - mask;
    int i;
    for (i = 1; i < len; ++i) {
        if (pathcp[i] == '/') {
            pathcp[i] = 0;
            mkdir(pathcp, mask);
            pathcp[i] = '/';
        }
    }
    free(pathcp);
}

variable_types:
path
char *

variable_types:
pathcp
char *

variable_types:
len
unsigned long

variable_types:
mask
unsigned int


decompiled_code:
int print_highscores()
{
__int64 v0; // rbx
const char *v1; // rbp
int result; // eax

v0 = 0LL;
puts("Highscores:");
do
{
v1 = (&difficulties)[v0];
result = read_highscore(v0);
if ( result > 0 )
result = printf("%s: %d\n", v1, (unsigned int)result);
++v0;
}
while ( v0 != 4 );
return result;
}

canonical_decompiled_code:
int func15()
{
__int64 v0; // rbx
const char *v1; // rbp
int result; // eax

v0 = 0LL;
puts("Highscores:");
do
{
v1 = (&difficulties)[v0];
result = func12(v0);
if ( result > 0 )
result = printf("%s: %d\n", v1, (unsigned int)result);
++v0;
}
while ( v0 != 4 );
return result;
}

original_code:
void print_highscores()
{
    printf("Highscores:\n");
    int difficulty;
    for (difficulty = 0; difficulty < 4; difficulty++) {
        char *name = difficulties[difficulty];
        int score = read_highscore(difficulty);
        if (score > 0) {
            printf("%s: %d\n", name, score);
        }
    }
}

variable_types: difficulty int

variable_types:
name
char *

variable_types: score int


decompiled_code:
int __fastcall print_usage(const char *a1)
{
printf("Usage: %s [-pqshHV] [-d 123] [-l level-file]\n", a1);
return puts(
"\n"
"-h: show the help message (this message)\n"
"\n"
"-d: set difficulty:\n"
" 1 easy\n"
" 2 medium\n"
" 3 hard\n"
"\n"
"-p: enable progressive difficulty\n"
" (increases difficulty every 25 points)\n"
"\n"
"-l: load level-file. Leave blank to list levels.\n"
"\n"
"-q: disable 3, 2, 1 countdown\n"
"\n"
"-s: enable sound (terminal bell)\n"
"\n"
"-H: list your highscores.\n"
"\n"
"-V: print the version info and exit.\n"
"\n"
"Controls:\n"
" Movement: WASD, HJKL, Arrow Keys\n"
" Pause: p\n"
" Quit: q\n");
}

canonical_decompiled_code:
int __fastcall func16(const char *a1)
{
printf("Usage: %s [-pqshHV] [-d 123] [-l level-file]\n", a1);
return puts(
"\n"
"-h: show the help message (this message)\n"
"\n"
"-d: set difficulty:\n"
" 1 easy\n"
" 2 medium\n"
" 3 hard\n"
"\n"
"-p: enable progressive difficulty\n"
" (increases difficulty every 25 points)\n"
"\n"
"-l: load level-file. Leave blank to list levels.\n"
"\n"
"-q: disable 3, 2, 1 countdown\n"
"\n"
"-s: enable sound (terminal bell)\n"
"\n"
"-H: list your highscores.\n"
"\n"
"-V: print the version info and exit.\n"
"\n"
"Controls:\n"
" Movement: WASD, HJKL, Arrow Keys\n"
" Pause: p\n"
" Quit: q\n");
}

original_code:
void print_usage(char *binary)
{
    printf("Usage: %s [-pqshHV] [-d 123] [-l level-file]\n", binary);
    printf("\n" "-h: show the help message (this message)\n\n" "-d: set difficulty:\n" "    1 easy\n" "    2 medium\n" "    3 hard\n\n" "-p: enable progressive difficulty\n" "    (increases difficulty every 25 points)\n\n" "-l: load level-file.  Leave blank to list levels.\n\n"
           "-q: disable 3, 2, 1 countdown\n\n" "-s: enable sound (terminal bell)\n\n" "-H: list your highscores.\n\n" "-V: print the version info and exit.\n\n" "Controls:\n" "    Movement: WASD, HJKL, Arrow Keys\n"
           "    Pause:    p\n"
           "    Quit:     q\n\n"
           "");
}

variable_types:
binary
char *


original_code:
int update_board(struct game_board *board) {
    int new_head = board->head + board->direction;
    int old_size = board->size;
    if (new_head < 0 || new_head >= 39 * 22 ||
            board->tile[new_head] >= 0 || board->tile[new_head] == -9 ||
            abs(board->head % 39 - new_head % 39) > 1) {
        return -1;
    }
    if (board->tile[new_head] == -7) {
        board->size++;
        int tile_idx[39 * 22];
        int i, num_empty;
        for (i = 0, num_empty = 0; i < 39 * 22; ++i) {
            if (board->tile[i] == -5) {
                tile_idx[num_empty++] = i;
            }
        }
        int rand = (random() % num_empty) + 1;
        int new_idx = tile_idx[rand];
        board->tile[new_idx] = -7;
    } else {
        int new_tail = board->tile[board->tail];
        board->tile[board->tail] = -5;
        board->tail = new_tail;
    }
    board->tile[new_head] = -6;
    board->tile[board->head] = new_head;
    board->head = new_head;
    return board->size - old_size;
}

canonical_original_code:
int update_board(struct game_board *board) {
    int new_head = board->head + board->direction;
    int old_size = board->size;
    if (new_head < 0 || new_head >= 39 * 22 ||
            board->tile[new_head] >= 0 || board->tile[new_head] == -9 ||
            abs(board->head % 39 - new_head % 39) > 1) {
        return -1;
    }
    if (board->tile[new_head] == -7) {
        board->size++;
        int tile_idx[-1];
        int i; int num_empty;
        for (i = 0, num_empty = 0; i < 39 * 22; ++i) {
            if (board->tile[i] == -5) {
                tile_idx[num_empty++] = i;
            }
        }
        int rand = (random() % num_empty) + 1;
        int new_idx = tile_idx[rand];
        board->tile[new_idx] = -7;
    } else {
        int new_tail = board->tile[board->tail];
        board->tile[board->tail] = -5;
        board->tail = new_tail;
    }
    board->tile[new_head] = -6;
    board->tile[board->head] = new_head;
    board->head = new_head;
    return board->size - old_size;
}

variable_types: struct game_board { int tile[-1]; int head; int tail; int size; int direction; } *

variable_types: rand int


decompiled_code:
__int64 __fastcall change_direction(__int64 a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(*(_DWORD *)(a1 + 3444) + a2);
if ( *(_DWORD *)(a1 + 3444) + a2 )
*(_DWORD *)(a1 + 3444) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(*(_DWORD *)(a1 + 3444) + a2);
if ( *(_DWORD *)(a1 + 3444) + a2 )
*(_DWORD *)(a1 + 3444) = a2;
return result;
}

original_code:
void change_direction(struct game_board *board, int new_dir)
{
    if (board->direction + new_dir != 0) {
        board->direction = new_dir;
    }
}

user_defined_types: struct game_board { int tile[-1]; int head; int tail; int size; int direction; }


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

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

original_code:
int board_idx(int y, int x)
{
    return y * 39 + x;
}

variable_types: y int

variable_types: x int


main

repo: malfaux/librandwalk

canonical_original_code:
int main(int argc, char **argv)
{
    int i;
    int out[31];
    int x[31] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};
    int dimlen = 31;
    unsigned long c1; unsigned long c2;
    unsigned long seed = randl();
    unsigned int rounds = 2;
    randwalk_init(dimlen, &c1, &c2);
    for (i = 0; i < dimlen; i++) {
        printf("%d ", x[i]);
    }
    printf("\n");
    for(i = 0; i < dimlen; i++) {
        out[i] = randwalk_shuffle(c1, c2, i, seed, rounds, dimlen);
        printf("%d ", out[i]);
    }
    printf("\n");
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
out
int [31]

variable_types:
x
int [31]

variable_types: dimlen int

variable_types:
seed
unsigned long

variable_types:
rounds
unsigned int


F

canonical_original_code:
static inline unsigned long F(unsigned long j, unsigned long R, unsigned long seed)
{
    static unsigned long primes[] = {
        961752031, 982324657, 15485843, 961752031, };
    R = ((R << (R&0x4)) + R + seed);
    R ^= sbox[R&0xF];
    return (((primes[j] * R + 25ULL) ^ R) + j);
}

variable_types:
j
unsigned long

variable_types:
R
unsigned long

variable_types:
primes
unsigned long []

return_type: unsigned long


fe

original_code:
static inline uint64_t
fe(unsigned r, uint64_t a, uint64_t b, uint64_t m, uint64_t seed)
{
    uint64_t L, R;
    unsigned j;
    uint64_t tmp;
    L = m % a;
    R = m / a;
    for (j=1; j<=r; j++) {
        if (j & 1) {
            tmp = (L + F(j, R, seed)) % a;
        } else {
            tmp = (L + F(j, R, seed)) % b;
        }
        L = R;
        R = tmp;
    }
    if (r & 1) {
        return a * L + R;
    } else {
        return a * R + L;
    }
}

canonical_original_code:
static inline unsigned long fe(unsigned int r, unsigned long a, unsigned long b, unsigned long m, unsigned long seed)
{
    unsigned long L; unsigned long R;
    unsigned int j;
    unsigned long tmp;
    L = m % a;
    R = m / a;
    for (j=1; j<=r; j++) {
        if (j & 1) {
            tmp = (L + F(j, R, seed)) % a;
        } else {
            tmp = (L + F(j, R, seed)) % b;
        }
        L = R;
        R = tmp;
    }
    if (r & 1) {
        return a * L + R;
    } else {
        return a * R + L;
    }
}

variable_types:
r
unsigned int

variable_types:
a
unsigned long

variable_types:
b
unsigned long

variable_types:
m
unsigned long

variable_types:
L
unsigned long

variable_types:
j
unsigned int

variable_types:
tmp
unsigned long


randl

decompiled_code:
__int64 randl()
{
int v0; // eax
int v1; // ebp
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

v0 = open("/dev/urandom", 0);
if ( v0 == -1 )
exit(1);
v1 = v0;
read(v0, &buf, 8uLL);
close(v1);
return buf;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // eax
int v1; // ebp
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

v0 = open("/dev/urandom", 0);
if ( v0 == -1 )
exit(1);
v1 = v0;
read(v0, &buf, 8uLL);
close(v1);
return buf;
}

original_code:
uint64_t randl(void)
{
    int fd = open("/dev/urandom", 00);
    uint64_t v;
    if (fd == -1) exit(1);
    read(fd, &v, sizeof(uint64_t));
    close(fd);
    return v;
}

canonical_original_code:
unsigned long randl()
{
    int fd = open("/dev/urandom", 00);
    unsigned long v;
    if (fd == -1) exit(1);
    read(fd, &v, sizeof(unsigned long));
    close(fd);
    return v;
}

variable_types: fd int

variable_types:
v
unsigned long


decompiled_code:
unsigned __int64 __fastcall randwalk_init(unsigned __int64 a1, _QWORD *a2, unsigned __int64 *a3)
{
unsigned __int64 result; // rax
unsigned __int64 v5; // rdx
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm2_8
double v9; // xmm0_8

switch ( a1 )
{
case 0uLL:
*a2 = 0LL;
result = a1;
goto LABEL_4;
case 1uLL:
*a2 = 1LL;
result = a1;
*a3 = 1LL;
break;
case 2uLL:
*a2 = 1LL;
result = a1;
*a3 = 2LL;
break;
case 3uLL:
*a2 = 2LL;
result = 2LL;
*a3 = 2LL;
break;
case 4uLL:
case 5uLL:
case 6uLL:
*a2 = 2LL;
result = 3LL;
*a3 = 3LL;
break;
case 7uLL:
case 8uLL:
*a2 = 3LL;
result = 3LL;
*a3 = 3LL;
break;
default:
if ( (a1 & 0x8000000000000000LL) != 0LL )
v6 = (double)(int)(a1 & 1 | (a1 >> 1)) + (double)(int)(a1 & 1 | (a1 >> 1));
else
v6 = (double)(int)a1;
if ( v6 < 0.0 )
v7 = sqrt(v6);
else
v7 = sqrt(v6);
v8 = v7 - 1.0;
if ( v7 - 1.0 >= 9.223372036854776e18 )
{
*a2 = (unsigned int)(int)(v8 - 9.223372036854776e18);
*a2 ^= 0x8000000000000000LL;
}
else
{
*a2 = (unsigned int)(int)v8;
}
v9 = v7 + 1.0;
if ( v9 >= 9.223372036854776e18 )
result = (unsigned int)(int)(v9 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
result = (unsigned int)(int)v9;
*a3 = result;
break;
}
if ( a1 >= result * *a2 )
{
LABEL_4:
++result;
do
{
*a3 = result;
v5 = result * *a2;
++result;
}
while ( v5 <= a1 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(unsigned __int64 a1, _QWORD *a2, unsigned __int64 *a3)
{
unsigned __int64 result; // rax
unsigned __int64 v5; // rdx
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm2_8
double v9; // xmm0_8

switch ( a1 )
{
case 0uLL:
*a2 = 0LL;
result = a1;
goto LABEL_4;
case 1uLL:
*a2 = 1LL;
result = a1;
*a3 = 1LL;
break;
case 2uLL:
*a2 = 1LL;
result = a1;
*a3 = 2LL;
break;
case 3uLL:
*a2 = 2LL;
result = 2LL;
*a3 = 2LL;
break;
case 4uLL:
case 5uLL:
case 6uLL:
*a2 = 2LL;
result = 3LL;
*a3 = 3LL;
break;
case 7uLL:
case 8uLL:
*a2 = 3LL;
result = 3LL;
*a3 = 3LL;
break;
default:
if ( (a1 & 0x8000000000000000LL) != 0LL )
v6 = (double)(int)(a1 & 1 | (a1 >> 1)) + (double)(int)(a1 & 1 | (a1 >> 1));
else
v6 = (double)(int)a1;
if ( v6 < 0.0 )
v7 = sqrt(v6);
else
v7 = sqrt(v6);
v8 = v7 - 1.0;
if ( v7 - 1.0 >= 9.223372036854776e18 )
{
*a2 = (unsigned int)(int)(v8 - 9.223372036854776e18);
*a2 ^= 0x8000000000000000LL;
}
else
{
*a2 = (unsigned int)(int)v8;
}
v9 = v7 + 1.0;
if ( v9 >= 9.223372036854776e18 )
result = (unsigned int)(int)(v9 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
result = (unsigned int)(int)v9;
*a3 = result;
break;
}
if ( a1 >= result * *a2 )
{
LABEL_4:
++result;
do
{
*a3 = result;
v5 = result * *a2;
++result;
}
while ( v5 <= a1 );
}
return result;
}

original_code:
void randwalk_init(uint64_t range, uint64_t *c1, uint64_t *c2)
{
    double root;
    switch (range) {
        case 0:
            *c1 = 0;
            *c2 = 0;
            break;
        case 1:
            *c1 = 1;
            *c2 = 1;
            break;
        case 2:
            *c1 = 1;
            *c2 = 2;
            break;
        case 3:
            *c1 = 2;
            *c2 = 2;
            break;
        case 4:
        case 5:
        case 6:
            *c1 = 2;
            *c2 = 3;
            break;
        case 7:
        case 8:
            *c1 = 3;
            *c2 = 3;
            break;
        default:
            root = sqrt(range * 1.0);
            *c1 = (uint64_t)(root-1);
            *c2 = (uint64_t)(root+1);
            break;
    }
    while ((*c1) * (*c2) <= range) (*c2)++;
}

canonical_original_code:
void randwalk_init(unsigned long range, unsigned long *c1, unsigned long *c2)
{
    double root;
    switch (range) {
        case 0:
            *c1 = 0;
            *c2 = 0;
            break;
        case 1:
            *c1 = 1;
            *c2 = 1;
            break;
        case 2:
            *c1 = 1;
            *c2 = 2;
            break;
        case 3:
            *c1 = 2;
            *c2 = 2;
            break;
        case 4:
        case 5:
        case 6:
            *c1 = 2;
            *c2 = 3;
            break;
        case 7:
        case 8:
            *c1 = 3;
            *c2 = 3;
            break;
        default:
            root = sqrt(range * 1.0);
            *c1 = (unsigned long)(root-1);
            *c2 = (unsigned long)(root+1);
            break;
    }
    while ((*c1) * (*c2) <= range) (*c2)++;
}

variable_types:
range
unsigned long

variable_types: root double


decompiled_code:
unsigned __int64 __fastcall randwalk_shuffle(unsigned __int64 a1, unsigned __int64 a2, unsigned __int64 a3, __int64 a4, unsigned int a5, unsigned __int64 a6)
{
unsigned __int64 i; // rcx

for ( i = fe(a5, a1, a2, a3, a4); a6 <= i; i = fe(a5, a1, a2, i, a4) )
;
return i;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(unsigned __int64 a1, unsigned __int64 a2, unsigned __int64 a3, __int64 a4, unsigned int a5, unsigned __int64 a6)
{
unsigned __int64 i; // rcx

for ( i = func8(a5, a1, a2, a3, a4); a6 <= i; i = func8(a5, a1, a2, i, a4) )
;
return i;
}

original_code:
uint64_t randwalk_shuffle(uint64_t c1, uint64_t c2, uint64_t m, uint64_t seed, uint32_t rounds, uint64_t range)
{
    uint64_t c;
    c = fe(rounds, c1, c2, m, seed);
    while(c >= range) {
        c = fe(rounds, c1, c2, c, seed);
    }
    return c;
}

canonical_original_code:
unsigned long randwalk_shuffle(unsigned long c1, unsigned long c2, unsigned long m, unsigned long seed, unsigned int rounds, unsigned long range)
{
    unsigned long c;
    c = fe(rounds, c1, c2, m, seed);
    while(c >= range) {
        c = fe(rounds, c1, c2, c, seed);
    }
    return c;
}

variable_types:
c
unsigned long


F

variable_types:
seed
unsigned long


randl

canonical_decompiled_code:
__int64 func8()
{
int v0; // eax
int v1; // ebp
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

v0 = open("/dev/urandom", 0);
if ( v0 == -1 )
exit(1);
v1 = v0;
read(v0, &buf, 8uLL);
close(v1);
return buf;
}


canonical_decompiled_code:
unsigned __int64 __fastcall func9(unsigned __int64 a1, _QWORD *a2, unsigned __int64 *a3)
{
unsigned __int64 result; // rax
unsigned __int64 v5; // rdx
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm2_8
double v9; // xmm0_8

switch ( a1 )
{
case 0uLL:
*a2 = 0LL;
result = a1;
goto LABEL_4;
case 1uLL:
*a2 = 1LL;
result = a1;
*a3 = 1LL;
break;
case 2uLL:
*a2 = 1LL;
result = a1;
*a3 = 2LL;
break;
case 3uLL:
*a2 = 2LL;
result = 2LL;
*a3 = 2LL;
break;
case 4uLL:
case 5uLL:
case 6uLL:
*a2 = 2LL;
result = 3LL;
*a3 = 3LL;
break;
case 7uLL:
case 8uLL:
*a2 = 3LL;
result = 3LL;
*a3 = 3LL;
break;
default:
if ( (a1 & 0x8000000000000000LL) != 0LL )
v6 = (double)(int)(a1 & 1 | (a1 >> 1)) + (double)(int)(a1 & 1 | (a1 >> 1));
else
v6 = (double)(int)a1;
if ( v6 < 0.0 )
v7 = sqrt(v6);
else
v7 = sqrt(v6);
v8 = v7 - 1.0;
if ( v7 - 1.0 >= 9.223372036854776e18 )
{
*a2 = (unsigned int)(int)(v8 - 9.223372036854776e18);
*a2 ^= 0x8000000000000000LL;
}
else
{
*a2 = (unsigned int)(int)v8;
}
v9 = v7 + 1.0;
if ( v9 >= 9.223372036854776e18 )
result = (unsigned int)(int)(v9 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
result = (unsigned int)(int)v9;
*a3 = result;
break;
}
if ( a1 >= result * *a2 )
{
LABEL_4:
++result;
do
{
*a3 = result;
v5 = result * *a2;
++result;
}
while ( v5 <= a1 );
}
return result;
}


canonical_decompiled_code:
unsigned __int64 __fastcall func10(unsigned __int64 a1, unsigned __int64 a2, unsigned __int64 a3, __int64 a4, unsigned int a5, unsigned __int64 a6)
{
unsigned __int64 i; // rcx

for ( i = func7(a5, a1, a2, a3, a4); a6 <= i; i = func7(a5, a1, a2, i, a4) )
;
return i;
}

variable_types:
rounds
unsigned int


variable_types:
x
struct f3 { float e[3]; }

variable_types:
y
struct f3

variable_types:
z
struct f3

variable_types:
m
struct f3x3 { float e[9]; }

return_type: struct f3x3 { float e[9]; }

user_defined_types:
struct f3 { float e[3]; }
struct f3x3 { float e[9]; }


decompiled_code:
__m128i __fastcall f3_make(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

canonical_decompiled_code:
__m128i __fastcall func0(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

original_code:
f3 f3_make(float e0, float e1, float e2) {
    f3 f;
    f.e[0] = e0;
    f.e[1] = e1;
    f.e[2] = e2;
    return f;
}

canonical_original_code:
struct f3 f3_make(float e0, float e1, float e2) {
    struct f3 f;
    f.e[0] = e0;
    f.e[1] = e1;
    f.e[2] = e2;
    return f;
}

variable_types:
f
struct f3 { float e[3]; }

return_type: struct f3 { float e[3]; }


decompiled_code:
float __fastcall f3_length_squared(double a1, __m128i a2)
{
float v3; // [rsp+8h] [rbp-8h]

v3 = COERCE_FLOAT(_mm_cvtsi128_si32(a2));
return (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(v3 * v3);
}

canonical_decompiled_code:
float __fastcall func1(double a1, __m128i a2)
{
float v3; // [rsp+8h] [rbp-8h]

v3 = COERCE_FLOAT(_mm_cvtsi128_si32(a2));
return (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(v3 * v3);
}

original_code:
float f3_length_squared(f3 v) {
    return v.e[0]*v.e[0] + v.e[1]*v.e[1] + v.e[2]*v.e[2];
}

canonical_original_code:
float f3_length_squared(struct f3 v) {
    return v.e[0]*v.e[0] + v.e[1]*v.e[1] + v.e[2]*v.e[2];
}

variable_types:
v
struct f3 { float e[3]; }

return_type: float


decompiled_code:
void __fastcall f3_length(double a1, float a2)
{
float v2; // xmm0_4

v2 = f3_length_squared(a1, _mm_cvtsi32_si128(LODWORD(a2)));
if ( v2 < 0.0 )
sqrtf(v2);
}

canonical_decompiled_code:
void __fastcall func2(double a1, float a2)
{
float v2; // xmm0_4

v2 = func1(a1, _mm_cvtsi32_si128(LODWORD(a2)));
if ( v2 < 0.0 )
sqrtf(v2);
}

original_code:
float f3_length(f3 v) {
    return sqrt( f3_length_squared(v) );
}

canonical_original_code:
float f3_length(struct f3 v) {
    return sqrt( f3_length_squared(v) );
}


decompiled_code:
void __fastcall f3_normalized(double a1, float a2)
{
f3_length(a1, a2);
}

canonical_decompiled_code:
void __fastcall func3(double a1, float a2)
{
func2(a1, a2);
}

original_code:
f3 f3_normalized(f3 v) {
    float l = f3_length(v);
    v.e[0] = v.e[0] / l;
    v.e[1] = v.e[1] / l;
    v.e[2] = v.e[2] / l;
    return v;
}

canonical_original_code:
struct f3 f3_normalized(struct f3 v) {
    float l = f3_length(v);
    v.e[0] = v.e[0] / l;
    v.e[1] = v.e[1] / l;
    v.e[2] = v.e[2] / l;
    return v;
}

variable_types:
v
struct f3

variable_types: l float


variable_types:
l
struct f3

variable_types:
r
struct f3


canonical_original_code:
struct f3 f3_sub(struct f3 l, struct f3 r) {
    struct f3 v;
    v.e[0] = l.e[0] - r.e[0];
    v.e[1] = l.e[1] - r.e[1];
    v.e[2] = l.e[2] - r.e[2];
    return v;
}


canonical_original_code:
struct f3 f3_minus(struct f3 v) {
    struct f3 r;
    r.e[0] = -v.e[0];
    r.e[1] = -v.e[1];
    r.e[2] = -v.e[2];
    return r;
}

variable_types:
r
struct f3 { float e[3]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
unsigned int v5; // [rsp+8h] [rbp-40h] BYREF
unsigned int v6; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
__int64 v8; // [rsp+18h] [rbp-30h] BYREF
__int64 v9; // [rsp+20h] [rbp-28h] BYREF
__int64 v10[4]; // [rsp+28h] [rbp-20h] BYREF

v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10[0] = 0LL;
if ( (unsigned int)(argc - 2) > 1 )
{
fwrite("\n====================================================================\n", 1uLL, 0x46uLL, stderr);
fwrite("This is updated package (Oct 08, 2004) for Ratio-Contour algorithm.\n", 1uLL, 0x44uLL, stderr);
fwrite(" (1) In this version, solid edge weight and length can be nonzero.\n", 1uLL, 0x43uLL, stderr);
fwrite(" (2) Zero will be returned when no alternate cycle is in the graph.\n", 1uLL, 0x44uLL, stderr);
fwrite(" (3) Fix a bug in previous release on May 06, 2004, to produce ONLY ONE cycle.\n", 1uLL, 0x4FuLL, stderr);
fwrite(" ---Song Wang, 10/08/2004.\n", 1uLL, 0x2EuLL, stderr);
fwrite("------------------------------------------------------------------\n", 1uLL, 0x43uLL, stderr);
fwrite("Usage: RatioContour4 image [NumIter(1)]\n\n", 1uLL, 0x29uLL, stderr);
fwrite(" Note: image is a image.w file with the format:\n", 1uLL, 0x36uLL, stderr);
fwrite(" Head line: #v(even) #e \n", 1uLL, 0x20uLL, stderr);
fwrite(" Each line: v1 v2 weight length solid(1)/dashed(0)\n", 1uLL, 0x39uLL, stderr);
fwrite("\n====================================================================\n", 1uLL, 0x46uLL, stderr);
}
else
{
v3 = 1LL;
sprintf(edgefilename, "%s.w", argv[1]);
strcpy(match_file, argv[1]);
if ( argc == 3 )
v3 = (unsigned int)atoi(argv[2]);
v5 = 0;
if ( (unsigned int)CCutil_getedgelist_n2(&v5, edgefilename, &v6, &v7, &v8, &v9, v10) )
{
fwrite("getedgelist_n2 failed\n", 1uLL, 0x16uLL, stderr);
}
else if ( (unsigned int)min_ratio_cycle(v5, v6, &v7, &v8, &v9, v10, match_file, v3) )
{
fwrite("ratio-cycle finding failed\n", 1uLL, 0x1BuLL, stderr);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
unsigned int v5; // [rsp+8h] [rbp-40h] BYREF
unsigned int v6; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
__int64 v8; // [rsp+18h] [rbp-30h] BYREF
__int64 v9; // [rsp+20h] [rbp-28h] BYREF
__int64 v10[4]; // [rsp+28h] [rbp-20h] BYREF

v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10[0] = 0LL;
if ( (unsigned int)(argc - 2) > 1 )
{
fwrite("\n====================================================================\n", 1uLL, 0x46uLL, stderr);
fwrite("This is updated package (Oct 08, 2004) for Ratio-Contour algorithm.\n", 1uLL, 0x44uLL, stderr);
fwrite(" (1) In this version, solid edge weight and length can be nonzero.\n", 1uLL, 0x43uLL, stderr);
fwrite(" (2) Zero will be returned when no alternate cycle is in the graph.\n", 1uLL, 0x44uLL, stderr);
fwrite(" (3) Fix a bug in previous release on May 06, 2004, to produce ONLY ONE cycle.\n", 1uLL, 0x4FuLL, stderr);
fwrite(" ---Song Wang, 10/08/2004.\n", 1uLL, 0x2EuLL, stderr);
fwrite("------------------------------------------------------------------\n", 1uLL, 0x43uLL, stderr);
fwrite("Usage: RatioContour4 image [NumIter(1)]\n\n", 1uLL, 0x29uLL, stderr);
fwrite(" Note: image is a image.w file with the format:\n", 1uLL, 0x36uLL, stderr);
fwrite(" Head line: #v(even) #e \n", 1uLL, 0x20uLL, stderr);
fwrite(" Each line: v1 v2 weight length solid(1)/dashed(0)\n", 1uLL, 0x39uLL, stderr);
fwrite("\n====================================================================\n", 1uLL, 0x46uLL, stderr);
}
else
{
v3 = 1LL;
sprintf(edgefilename, "%s.w", argv[1]);
strcpy(match_file, argv[1]);
if ( argc == 3 )
v3 = (unsigned int)atoi(argv[2]);
v5 = 0;
if ( (unsigned int)func0(&v5, edgefilename, &v6, &v7, &v8, &v9, v10) )
{
fwrite("getedgelist_n2 failed\n", 1uLL, 0x16uLL, stderr);
}
else if ( (unsigned int)min_ratio_cycle(v5, v6, &v7, &v8, &v9, v10, match_file, v3) )
{
fwrite("ratio-cycle finding failed\n", 1uLL, 0x1BuLL, stderr);
}
}
return 0;
}

original_code:
int main (int ac, char **av)
{
    int ncount, ecount;
    int *elist = (int *) ((void *)0);
    int *elen = (int *) ((void *)0);
    int *elen2 = (int *) ((void *)0);
    int *esolid = (int *) ((void *)0);
    int NumIteration;
    if ((ac != 2) && (ac !=3)){
       fprintf (stderr, "\n====================================================================\n");
       fprintf (stderr, "This is updated package (Oct 08, 2004) for Ratio-Contour algorithm.\n");
       fprintf (stderr, " (1) In this version, solid edge weight and length can be nonzero.\n");
       fprintf (stderr, " (2) Zero will be returned when no alternate cycle is in the graph.\n");
       fprintf (stderr, " (3) Fix a bug in previous release on May 06, 2004, to produce ONLY ONE cycle.\n");
       fprintf (stderr, "                    ---Song Wang, 10/08/2004.\n");
       fprintf (stderr, "------------------------------------------------------------------\n");
       fprintf (stderr, "Usage: RatioContour4 image [NumIter(1)]\n\n");
       fprintf (stderr, "       Note: image is a image.w file with the format:\n");
       fprintf (stderr, "       Head line: #v(even)  #e \n");
       fprintf (stderr, "       Each line: v1 v2 weight length solid(1)/dashed(0)\n");
       fprintf (stderr, "\n====================================================================\n");
       goto CLEANUP;
     }
    sprintf(edgefilename, "%s.w", av[1]);
    sprintf(match_file, "%s", av[1]);
    if (ac == 3)
       NumIteration = atoi(av[2]);
    else
       NumIteration = 1;
    ncount = 0;
    if (CCutil_getedgelist_n2 (&ncount, edgefilename,
                               &ecount, &elist, &elen, &elen2, &esolid)) {
       fprintf (stderr, "getedgelist_n2 failed\n");
       goto CLEANUP;
     }
    if (min_ratio_cycle (ncount, ecount, &elist,
                         &elen, &elen2, &esolid, match_file, NumIteration)){
        fprintf (stderr, "ratio-cycle finding failed\n");
        goto CLEANUP;
    }
CLEANUP:
   return 0;
}

canonical_original_code:
int main(int ac, char **av)
{
    int ncount; int ecount;
    int *elist = (int *) ((void *)0);
    int *elen = (int *) ((void *)0);
    int *elen2 = (int *) ((void *)0);
    int *esolid = (int *) ((void *)0);
    int NumIteration;
    if ((ac != 2) && (ac !=3)){
       fprintf (stderr, "\n====================================================================\n");
       fprintf (stderr, "This is updated package (Oct 08, 2004) for Ratio-Contour algorithm.\n");
       fprintf (stderr, " (1) In this version, solid edge weight and length can be nonzero.\n");
       fprintf (stderr, " (2) Zero will be returned when no alternate cycle is in the graph.\n");
       fprintf (stderr, " (3) Fix a bug in previous release on May 06, 2004, to produce ONLY ONE cycle.\n");
       fprintf (stderr, "                    ---Song Wang, 10/08/2004.\n");
       fprintf (stderr, "------------------------------------------------------------------\n");
       fprintf (stderr, "Usage: RatioContour4 image [NumIter(1)]\n\n");
       fprintf (stderr, "       Note: image is a image.w file with the format:\n");
       fprintf (stderr, "       Head line: #v(even)  #e \n");
       fprintf (stderr, "       Each line: v1 v2 weight length solid(1)/dashed(0)\n");
       fprintf (stderr, "\n====================================================================\n");
       goto CLEANUP;
     }
    sprintf(edgefilename, "%s.w", av[1]);
    sprintf(match_file, "%s", av[1]);
    if (ac == 3)
       NumIteration = atoi(av[2]);
    else
       NumIteration = 1;
    ncount = 0;
    if (CCutil_getedgelist_n2 (&ncount, edgefilename,
                               &ecount, &elist, &elen, &elen2, &esolid)) {
       fprintf (stderr, "getedgelist_n2 failed\n");
       goto CLEANUP;
     }
    if (min_ratio_cycle (ncount, ecount, &elist,
                         &elen, &elen2, &esolid, match_file, NumIteration)){
        fprintf (stderr, "ratio-cycle finding failed\n");
        goto CLEANUP;
    }
CLEANUP:
   return 0;
}

variable_types: ac int

variable_types:
av
char **

variable_types: ncount int

variable_types: ecount int

variable_types:
elist
int *

variable_types:
elen
int *

variable_types:
esolid
int *

variable_types: NumIteration int