decompiled_code:
int __fastcall print_time(void (__fastcall *a1)(time_t *, struct tm *))
{
size_t v1; // rbx
int result; // eax
struct tm v3; // [rsp+0h] [rbp-68h] BYREF
time_t timer; // [rsp+38h] [rbp-30h] BYREF
char s[40]; // [rsp+40h] [rbp-28h] BYREF

time(&timer);
a1(&timer, &v3);
v1 = strftime(s, 0x20uLL, format, &v3);
if ( fwrite(s, 1uLL, v1, stdout) != v1 )
io_error(stdout);
result = fputc(9, stdout);
if ( result == -1 )
io_error(stdout);
return result;
}

canonical_decompiled_code:
int __fastcall func11(void (__fastcall *a1)(time_t *, struct tm *))
{
size_t v1; // rbx
int result; // eax
struct tm v3; // [rsp+0h] [rbp-68h] BYREF
time_t timer; // [rsp+38h] [rbp-30h] BYREF
char s[40]; // [rsp+40h] [rbp-28h] BYREF

time(&timer);
a1(&timer, &v3);
v1 = strftime(s, 0x20uLL, format, &v3);
if ( fwrite(s, 1uLL, v1, stdout) != v1 )
func10(stdout);
result = fputc(9, stdout);
if ( result == -1 )
func10(stdout);
return result;
}

original_code:
static void print_time(time_format time_format) {
  enum { buffer_max = 32 };
  char buffer[buffer_max];
  time_t rawtime;
  time(&rawtime);
  struct tm timeinfo;
  time_format(&rawtime, &timeinfo);
  const size_t len = strftime(buffer, buffer_max, format, &timeinfo);
  if(len != fwrite(buffer, 1, len, stdout)){
    io_error(stdout);
  }
  if (fputc('\t', stdout) == (-1)) {
   io_error(stdout);
  }
}

canonical_original_code:
static void print_time(struct tm *(*time_format)(long *, struct tm *)) {
  enum { buffer_max = 32 };
  char buffer[-1];
  long rawtime;
  time(&rawtime);
  struct tm timeinfo;
  time_format(&rawtime, &timeinfo);
  unsigned long len = strftime(buffer, buffer_max, format, &timeinfo);
  if(len != fwrite(buffer, 1, len, stdout)){
    io_error(stdout);
  }
  if (fputc('\t', stdout) == (-1)) {
   io_error(stdout);
  }
}

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; } *(*)(long *, struct tm *)

variable_types:
buffer
char [-1]

variable_types: rawtime long

variable_types:
len
unsigned long


main

canonical_name: main

repo: marcomorain/tcat

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v4; // ebx
int v5; // er12
__int64 v7; // r15
char *v8; // rbp
int v9; // eax
int v10; // ebx
int v11; // edx
int v12; // eax
struct tm *(*v13)(const time_t *, struct tm *); // [rsp+0h] [rbp-48h]
int v14; // [rsp+Ch] [rbp-3Ch]

v3 = getenv("TCAT_FORMAT");
if ( v3 )
format = v3;
if ( argc <= 1 )
{
v13 = gmtime_r;
}
else
{
v4 = 1;
v13 = gmtime_r;
v14 = 0;
do
{
v7 = v4;
v8 = (char *)argv[v7];
v5 = match(v8, "-v", "--version");
if ( v5 )
{
version(stdout);
return 0;
}
if ( match(v8, "-h", "--help") )
{
usage(stdout);
return v5;
}
if ( match(v8, "-l", "--local") )
{
v13 = localtime_r;
}
else if ( match(v8, "-f", "--format") )
{
if ( argc <= ++v4 )
{
fprintf(stderr, "Error: no format string given provided for %s option\n", argv[v4 - 1]);
return 1;
}
format = (char *)argv[v7 + 1];
}
else
{
fprintf(stderr, "Invalid option:\t%s\n", v8);
v14 = 1;
}
++v4;
}
while ( argc > v4 );
v5 = v14;
if ( v14 )
{
usage(stderr);
return v5;
}
}
v9 = fileno(stdin);
if ( isatty(v9) )
fwrite("Warning: input is from TTY\n", 1uLL, 0x1BuLL, stderr);
v10 = fgetc(stdin);
if ( v10 != -1 )
{
v11 = 10;
while ( 1 )
{
if ( v11 == 10 )
print_time((void (__fastcall *)(time_t *, struct tm *))v13);
if ( fputc(v10, stdout) == -1 )
io_error(stdout);
v12 = fgetc(stdin);
v11 = v10;
if ( v12 == -1 )
break;
v10 = v12;
}
}
v5 = ferror(stdin);
if ( v5 )
{
perror("output error");
v5 = 1;
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v4; // ebx
int v5; // er12
__int64 v7; // r15
char *v8; // rbp
int v9; // eax
int v10; // ebx
int v11; // edx
int v12; // eax
struct tm *(*v13)(const time_t *, struct tm *); // [rsp+0h] [rbp-48h]
int v14; // [rsp+Ch] [rbp-3Ch]

v3 = getenv("TCAT_FORMAT");
if ( v3 )
format = v3;
if ( argc <= 1 )
{
v13 = gmtime_r;
}
else
{
v4 = 1;
v13 = gmtime_r;
v14 = 0;
do
{
v7 = v4;
v8 = (char *)argv[v7];
v5 = func9(v8, "-v", "--version");
if ( v5 )
{
func7(stdout);
return 0;
}
if ( func9(v8, "-h", "--help") )
{
func8(stdout);
return v5;
}
if ( func9(v8, "-l", "--local") )
{
v13 = localtime_r;
}
else if ( func9(v8, "-f", "--format") )
{
if ( argc <= ++v4 )
{
fprintf(stderr, "Error: no format string given provided for %s option\n", argv[v4 - 1]);
return 1;
}
format = (char *)argv[v7 + 1];
}
else
{
fprintf(stderr, "Invalid option:\t%s\n", v8);
v14 = 1;
}
++v4;
}
while ( argc > v4 );
v5 = v14;
if ( v14 )
{
func8(stderr);
return v5;
}
}
v9 = fileno(stdin);
if ( isatty(v9) )
fwrite("Warning: input is from TTY\n", 1uLL, 0x1BuLL, stderr);
v10 = fgetc(stdin);
if ( v10 != -1 )
{
v11 = 10;
while ( 1 )
{
if ( v11 == 10 )
func11((void (__fastcall *)(time_t *, struct tm *))v13);
if ( fputc(v10, stdout) == -1 )
func10(stdout);
v12 = fgetc(stdin);
v11 = v10;
if ( v12 == -1 )
break;
v10 = v12;
}
}
v5 = ferror(stdin);
if ( v5 )
{
perror("output error");
v5 = 1;
}
return v5;
}

original_code:
int main(int argc, char** argv) {
  int bad_usage = 0;
  char *format_env = getenv(env_flag);
  if (format_env) {
    format = format_env;
  }
  time_format time_format = gmtime_r;
  for (int i = 1; i < argc; i++) {
    if (match(argv[i], "-v", "--version")) {
      version(stdout);
      return 0;
    }
    if (match(argv[i], "-h", "--help")) {
      usage(stdout);
      return 0;
    }
    if (match(argv[i], "-l", "--local")) {
      time_format = localtime_r;
      continue;
    }
    if (match(argv[i], "-f", "--format")) {
      if (++i >= argc) {
        fprintf(stderr, "Error: no format string given provided for %s option\n", argv[i-1]);
        return 1;
      }
      format = argv[i];
      continue;
    }
    bad_usage = 1;
    fprintf(stderr, "Invalid option:\t%s\n", argv[i]);
  }
  if (bad_usage) {
    usage(stderr);
    return 1;
  }
  if (isatty(fileno(stdin))) {
    fprintf(stderr, "Warning: input is from TTY\n");
  }
  int last = '\n';
  for(int c = fgetc(stdin); c != (-1); c = fgetc(stdin)) {
    if (last == '\n') {
      print_time(time_format);
    }
    if ((-1) == fputc(c, stdout)) {
      io_error(stdout);
    }
    last = c;
  }
  if (ferror(stdin)) {
    perror("output error");
    return 1;
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int bad_usage = 0;
  char *format_env = getenv(env_flag);
  if (format_env) {
    format = format_env;
  }
  struct tm *(*time_format)(long *, struct tm *) = gmtime_r;
  for (int i = 1; i < argc; i++) {
    if (match(argv[i], "-v", "--version")) {
      version(stdout);
      return 0;
    }
    if (match(argv[i], "-h", "--help")) {
      usage(stdout);
      return 0;
    }
    if (match(argv[i], "-l", "--local")) {
      time_format = localtime_r;
      continue;
    }
    if (match(argv[i], "-f", "--format")) {
      if (++i >= argc) {
        fprintf(stderr, "Error: no format string given provided for %s option\n", argv[i-1]);
        return 1;
      }
      format = argv[i];
      continue;
    }
    bad_usage = 1;
    fprintf(stderr, "Invalid option:\t%s\n", argv[i]);
  }
  if (bad_usage) {
    usage(stderr);
    return 1;
  }
  if (isatty(fileno(stdin))) {
    fprintf(stderr, "Warning: input is from TTY\n");
  }
  int last = '\n';
  for(int c = fgetc(stdin); c != (-1); c = fgetc(stdin)) {
    if (last == '\n') {
      print_time(time_format);
    }
    if ((-1) == fputc(c, stdout)) {
      io_error(stdout);
    }
    last = c;
  }
  if (ferror(stdin)) {
    perror("output error");
    return 1;
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: last int

variable_types: c int

return_type: int

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


repo: mdcclv/libphilo

decompiled_code:
char *get_method_info_proxy()
{
char *result; // rax

result = (char *)malloc(0x100uLL);
strcpy(result, "This is a PHRASE search method.");
return result;
}

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

result = (char *)malloc(0x100uLL);
strcpy(result, "This is a PHRASE search method.");
return result;
}

original_code:
Z8 *get_method_info_proxy ()
{
  Z8 *ret;
  ret = (Z8 *) malloc ( 256 );
  sprintf ( (char *)ret, "This is a PHRASE search method." );
  return ret;
}

canonical_original_code:
char *get_method_info_proxy()
{
  char *ret;
  ret = (char *) malloc ( 256 );
  sprintf ( (char *)ret, "This is a PHRASE search method." );
  return ret;
}

variable_types:
ret
char *

return_type: char *


repo: megacoder/arglist

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
double v4; // xmm1_8
double v5; // xmm2_8
double v6; // xmm3_8
double v7; // xmm6_8
double v8; // xmm7_8
char *v9; // rax
double v10; // xmm4_8
double v11; // xmm5_8

me = (char *)*argv;
v9 = strrchr(me, 47);
if ( v9 )
me = v9 + 1;
process("/bin/echo", v3, v4, v5, v6, v10, v11, v7, v8, "echo", "this", "is", "a", "test.", 0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
double v4; // xmm1_8
double v5; // xmm2_8
double v6; // xmm3_8
double v7; // xmm6_8
double v8; // xmm7_8
char *v9; // rax
double v10; // xmm4_8
double v11; // xmm5_8

me = (char *)*argv;
v9 = strrchr(me, 47);
if ( v9 )
me = v9 + 1;
func7("/bin/echo", v3, v4, v5, v6, v10, v11, v7, v8, "echo", "this", "is", "a", "test.", 0LL);
return 0;
}

original_code:
int
main(
 int argc __attribute__((unused)),
 char * * argv __attribute__((unused))
)
{
 char * bp;
 me = argv[ 0 ];
 if( (bp = strrchr( me, '/' )) != ((void *)0) ) {
  me = bp + 1;
 }
 process(
  "/bin/echo",
  "echo",
  "this",
  "is",
  "a",
  "test.",
  ((void *)0)
 );
 return( 0 );
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *bp;
 me = argv[ 0 ];
 if( (bp = strrchr( me, '/' )) != ((void *)0) ) {
  me = bp + 1;
 }
 process(
  "/bin/echo",
  "echo",
  "this",
  "is",
  "a",
  "test.",
  ((void *)0)
 );
 return( 0 );
}

variable_types:
bp
char *


repo: michaeljclark/userblk

decompiled_code:
void __fastcall sig_handler(int a1)
{
if ( a1 == 2 || a1 == 15 )
{
running = 0;
fwrite("caught signal, exiting after current request\n", 1uLL, 0x2DuLL, stderr);
}
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
if ( a1 == 2 || a1 == 15 )
{
running = 0;
fwrite("caught signal, exiting after current request\n", 1uLL, 0x2DuLL, stderr);
}
}

original_code:
static void sig_handler(int sig)
{
  switch(sig) {
  case 15:
  case 2:
    running = 0;
    fprintf(stderr,"caught signal, exiting after current request\n");
    break;
  }
}

variable_types: sig int

return_type: void


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return fprintf(
stderr,
"Usage: %s [options] <ubc_dev> <ubb_dev> <image>\n"
"\n"
"-h|--help show usage info\n"
"-d|--debug switch on debug output\n"
"-n|--nice <n> nice level\n"
"-s|--size <n> size in kilobytes of the image\n",
a1);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
return fprintf(
stderr,
"Usage: %s [options] <ubc_dev> <ubb_dev> <image>\n"
"\n"
"-h|--help show usage info\n"
"-d|--debug switch on debug output\n"
"-n|--nice <n> nice level\n"
"-s|--size <n> size in kilobytes of the image\n",
a1);
}

original_code:
static void print_usage(char *prog)
{
  fprintf(stderr, "Usage: %s [options] <ubc_dev> <ubb_dev> <image>\n\n"
   "-h|--help          show usage info\n"
   "-d|--debug         switch on debug output\n"
   "-n|--nice <n>      nice level\n"
   "-s|--size <n>      size in kilobytes of the image\n", prog);
}

variable_types:
prog
char *


decompiled_code:
char *__fastcall parse_cmdline(int argc, char **argv)
{
int v2; // eax
__int64 v3; // rdx
char *result; // rax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

longind[0] = 0;
while ( 1 )
{
v2 = getopt_long(argc, argv, "hdn:s:", &long_options, longind);
if ( v2 == -1 )
break;
if ( v2 == 110 )
{
if ( sscanf(optarg, "%d", &opt_nice) != 1 )
{
fwrite("nice level must be an integer\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
}
else if ( v2 > 110 )
{
if ( v2 == 115 && (sscanf(optarg, "%d", &opt_size) != 1 || opt_size <= 0) )
{
fwrite("size must be a positive integer\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
}
else if ( v2 == 100 )
{
++opt_debug;
}
else if ( v2 == 104 || v2 == 63 )
{
print_usage(*argv);
exit(1);
}
}
if ( argc - optind != 3 )
{
print_usage(*argv);
exit(1);
}
v3 = optind;
opt_ubc_device = argv[v3];
opt_ubb_device = argv[v3 + 1];
result = argv[v3 + 2];
opt_image = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func9(int argc, char **argv)
{
int v2; // eax
__int64 v3; // rdx
char *result; // rax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

longind[0] = 0;
while ( 1 )
{
v2 = getopt_long(argc, argv, "hdn:s:", &long_options, longind);
if ( v2 == -1 )
break;
if ( v2 == 110 )
{
if ( sscanf(optarg, "%d", &opt_nice) != 1 )
{
fwrite("nice level must be an integer\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
}
else if ( v2 > 110 )
{
if ( v2 == 115 && (sscanf(optarg, "%d", &opt_size) != 1 || opt_size <= 0) )
{
fwrite("size must be a positive integer\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
}
else if ( v2 == 100 )
{
++opt_debug;
}
else if ( v2 == 104 || v2 == 63 )
{
func8(*argv);
exit(1);
}
}
if ( argc - optind != 3 )
{
func8(*argv);
exit(1);
}
v3 = optind;
opt_ubc_device = argv[v3];
opt_ubb_device = argv[v3 + 1];
result = argv[v3 + 2];
opt_image = result;
return result;
}

original_code:
static void parse_cmdline(int argc, char **argv)
{
  int c, option_index = 0;
  while ((c = getopt_long(argc, argv, "hdn:s:",
    long_options, &option_index)) != -1) switch(c) {
    case 's':
      if (sscanf(optarg, "%d", &opt_size) != 1 || opt_size <= 0) {
 fprintf(stderr, "size must be a positive integer\n");
 exit(1);
      }
      break;
    case 'n':
      if (sscanf(optarg, "%d", &opt_nice) != 1) {
 fprintf(stderr, "nice level must be an integer\n");
 exit(1);
      }
      break;
    case 'd':
      opt_debug++;
      break;
    case 'h':
    case '?':
      print_usage(argv[0]);
      exit(1);
  }
  if (argc - optind != 3) {
    print_usage(argv[0]);
    exit(1);
  }
  opt_ubc_device = argv[optind];
  opt_ubb_device = argv[optind+1];
  opt_image = argv[optind+2];
}

canonical_original_code:
static void parse_cmdline(int argc, char **argv)
{
  int c; int option_index = 0;
  while ((c = getopt_long(argc, argv, "hdn:s:",
    long_options, &option_index)) != -1) switch(c) {
    case 's':
      if (sscanf(optarg, "%d", &opt_size) != 1 || opt_size <= 0) {
 fprintf(stderr, "size must be a positive integer\n");
 exit(1);
      }
      break;
    case 'n':
      if (sscanf(optarg, "%d", &opt_nice) != 1) {
 fprintf(stderr, "nice level must be an integer\n");
 exit(1);
      }
      break;
    case 'd':
      opt_debug++;
      break;
    case 'h':
    case '?':
      print_usage(argv[0]);
      exit(1);
  }
  if (argc - optind != 3) {
    print_usage(argv[0]);
    exit(1);
  }
  opt_ubc_device = argv[optind];
  opt_ubb_device = argv[optind+1];
  opt_image = argv[optind+2];
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er14
int v5; // eax
int v6; // ebp
char *v7; // rbx
__pid_t v8; // er15
__off_t v9; // rax
int v10; // eax
int v11; // ebx
int v12; // eax
size_t v13; // r12
size_t v14; // r13
int v15; // eax
int v16; // eax
size_t v17; // r12
size_t v18; // r13
int v19; // eax
int stat_loc; // [rsp+4h] [rbp-64h] BYREF
struct pollfd fds; // [rsp+8h] [rbp-60h] BYREF
unsigned int buf; // [rsp+10h] [rbp-58h] BYREF
_BOOL4 v24; // [rsp+14h] [rbp-54h]
__int64 v25; // [rsp+18h] [rbp-50h]
size_t v26; // [rsp+20h] [rbp-48h]
__int64 v27; // [rsp+28h] [rbp-40h]

parse_cmdline(argc, (char **)argv);
signal(2, sig_handler);
signal(15, sig_handler);
v3 = open(opt_ubc_device, 2);
if ( v3 < 0 )
{
perror("ubd: opening ubc device");
exit(1);
}
v4 = v3;
v5 = open64(opt_image, 16450, 420LL);
v6 = v5;
if ( v5 < 0 )
{
perror("ubd: opening image");
exit(1);
}
if ( !opt_size )
{
if ( ioctl(v5, 0x1260uLL, &opt_size) )
{
v9 = lseek(v6, 0LL, 2);
if ( v9 <= 0 )
{
fwrite("ubd: can't detect size of block image\n", 1uLL, 0x26uLL, stderr);
exit(1);
}
opt_size = v9 / 1024;
}
else
{
opt_size /= 2;
}
}
if ( ioctl(v4, 0x40047501uLL, &opt_size) < 0 )
{
perror("ubb: ioctl(UBC_IOCSSIZE)");
exit(1);
}
v7 = (char *)mmap(0LL, 0x20000uLL, 3, 1, v4, 0LL);
if ( v7 == (char *)-1LL )
{
perror("ubd: mmap");
exit(1);
}
if ( mlockall(3) < 0 )
{
perror("mlockall");
exit(1);
}
if ( nice(opt_nice) < 0 )
{
perror("ubd: nice");
exit(1);
}
printf("image : %s\n", opt_image);
printf("size : %dK\n", (unsigned int)opt_size);
printf("vm : %p\n", v7);
v8 = fork();
if ( !v8 )
{
v10 = open(opt_ubb_device, 2);
v11 = v10;
if ( v10 >= 0 )
{
if ( ioctl(v10, 0x125FuLL) < 0 )
puts("error reading partition table");
close(v11);
exit(0);
}
puts("couldn't open block device");
exit(0);
}
fds.fd = v4;
fds.events = 1;
running = 1;
while ( 2 )
{
if ( v8 && waitpid(v8, &stat_loc, 1) == v8 )
v8 = 0;
while ( 1 )
{
if ( poll(&fds, 1uLL, -1) >= 0 )
{
if ( !running )
return 0;
if ( (fds.events & 1) != 0 )
{
while ( 1 )
{
v12 = read(v4, &buf, 0x20uLL);
if ( v12 >= 0 )
break;
if ( *__errno_location() != 4 )
{
perror("ubd: ubc read");
goto LABEL_73;
}
if ( opt_debug )
puts("ubd: ubc read was interuppted, retrying.");
}
if ( v12 == 32 )
{
if ( !v24 )
{
if ( opt_debug )
printf("request[%d]: READ offset=%ld size=%zd\n", buf, v25, v26);
v13 = v26;
if ( v26 )
{
v14 = 0LL;
v13 = 0LL;
while ( 1 )
{
while ( 1 )
{
v16 = pread64(v6, &v7[v27 + v13], v26 - v13, v25 + v14);
if ( v16 < 0 )
break;
v14 += v16;
v13 = v14;
if ( v26 == v14 )
goto LABEL_45;
}
if ( *__errno_location() != 4 )
break;
if ( opt_debug )
puts("ubd: img read was interuppted, retrying.");
}
perror("ubd: image read");
}
LABEL_45:
v24 = v26 == v13;
goto LABEL_46;
}
if ( !v24 )
{
printf("request[%d]: cmd=%d unknown\n", buf, v24);
goto LABEL_46;
}
if ( opt_debug )
printf("request[%d]: WRITE offset=%ld size=%zd\n", buf, v25, v26);
v17 = v26;
if ( v26 )
{
v18 = 0LL;
v17 = 0LL;
while ( 1 )
{
while ( 1 )
{
v19 = pwrite64(v6, &v7[v27 + v17], v26 - v17, v25 + v18);
if ( v19 < 0 )
break;
v18 += v19;
v17 = v18;
if ( v26 == v18 )
goto LABEL_60;
}
if ( *__errno_location() != 4 )
break;
if ( opt_debug )
puts("ubd: img write was interuppted, retrying.");
}
perror("ubd: image write");
}
LABEL_60:
v24 = v26 == v17;
LABEL_46:
while ( 1 )
{
v15 = write(v4, &buf, 8uLL);
if ( v15 >= 0 )
break;
if ( *__errno_location() != 4 )
{
perror("ubd: ubc write");
goto LABEL_73;
}
if ( opt_debug )
puts("ubd: ubc write was interuppted, retrying.");
}
if ( v15 != 8 )
fwrite("ubd: write response was to short\n", 1uLL, 0x21uLL, stderr);
}
else
{
fwrite("ubd: read request was to short\n", 1uLL, 0x1FuLL, stderr);
}
}
goto LABEL_73;
}
if ( *__errno_location() != 4 )
break;
if ( !running )
return 0;
if ( opt_debug )
puts("ubd: ubc poll was interuppted, retrying.");
}
if ( running )
{
perror("ubd: ubc poll");
LABEL_73:
if ( !running )
exit(0);
continue;
}
return 0;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er14
int v5; // eax
int v6; // ebp
char *v7; // rbx
__pid_t v8; // er15
__off_t v9; // rax
int v10; // eax
int v11; // ebx
int v12; // eax
size_t v13; // r12
size_t v14; // r13
int v15; // eax
int v16; // eax
size_t v17; // r12
size_t v18; // r13
int v19; // eax
int stat_loc; // [rsp+4h] [rbp-64h] BYREF
struct pollfd fds; // [rsp+8h] [rbp-60h] BYREF
unsigned int buf; // [rsp+10h] [rbp-58h] BYREF
_BOOL4 v24; // [rsp+14h] [rbp-54h]
__int64 v25; // [rsp+18h] [rbp-50h]
size_t v26; // [rsp+20h] [rbp-48h]
__int64 v27; // [rsp+28h] [rbp-40h]

func9(argc, (char **)argv);
signal(2, sig_handler);
signal(15, sig_handler);
v3 = open(opt_ubc_device, 2);
if ( v3 < 0 )
{
perror("ubd: opening ubc device");
exit(1);
}
v4 = v3;
v5 = open64(opt_image, 16450, 420LL);
v6 = v5;
if ( v5 < 0 )
{
perror("ubd: opening image");
exit(1);
}
if ( !opt_size )
{
if ( ioctl(v5, 0x1260uLL, &opt_size) )
{
v9 = lseek(v6, 0LL, 2);
if ( v9 <= 0 )
{
fwrite("ubd: can't detect size of block image\n", 1uLL, 0x26uLL, stderr);
exit(1);
}
opt_size = v9 / 1024;
}
else
{
opt_size /= 2;
}
}
if ( ioctl(v4, 0x40047501uLL, &opt_size) < 0 )
{
perror("ubb: ioctl(UBC_IOCSSIZE)");
exit(1);
}
v7 = (char *)mmap(0LL, 0x20000uLL, 3, 1, v4, 0LL);
if ( v7 == (char *)-1LL )
{
perror("ubd: mmap");
exit(1);
}
if ( mlockall(3) < 0 )
{
perror("mlockall");
exit(1);
}
if ( nice(opt_nice) < 0 )
{
perror("ubd: nice");
exit(1);
}
printf("image : %s\n", opt_image);
printf("size : %dK\n", (unsigned int)opt_size);
printf("vm : %p\n", v7);
v8 = fork();
if ( !v8 )
{
v10 = open(opt_ubb_device, 2);
v11 = v10;
if ( v10 >= 0 )
{
if ( ioctl(v10, 0x125FuLL) < 0 )
puts("error reading partition table");
close(v11);
exit(0);
}
puts("couldn't open block device");
exit(0);
}
fds.fd = v4;
fds.events = 1;
running = 1;
while ( 2 )
{
if ( v8 && waitpid(v8, &stat_loc, 1) == v8 )
v8 = 0;
while ( 1 )
{
if ( poll(&fds, 1uLL, -1) >= 0 )
{
if ( !running )
return 0;
if ( (fds.events & 1) != 0 )
{
while ( 1 )
{
v12 = read(v4, &buf, 0x20uLL);
if ( v12 >= 0 )
break;
if ( *__errno_location() != 4 )
{
perror("ubd: ubc read");
goto LABEL_73;
}
if ( opt_debug )
puts("ubd: ubc read was interuppted, retrying.");
}
if ( v12 == 32 )
{
if ( !v24 )
{
if ( opt_debug )
printf("request[%d]: READ offset=%ld size=%zd\n", buf, v25, v26);
v13 = v26;
if ( v26 )
{
v14 = 0LL;
v13 = 0LL;
while ( 1 )
{
while ( 1 )
{
v16 = pread64(v6, &v7[v27 + v13], v26 - v13, v25 + v14);
if ( v16 < 0 )
break;
v14 += v16;
v13 = v14;
if ( v26 == v14 )
goto LABEL_45;
}
if ( *__errno_location() != 4 )
break;
if ( opt_debug )
puts("ubd: img read was interuppted, retrying.");
}
perror("ubd: image read");
}
LABEL_45:
v24 = v26 == v13;
goto LABEL_46;
}
if ( !v24 )
{
printf("request[%d]: cmd=%d unknown\n", buf, v24);
goto LABEL_46;
}
if ( opt_debug )
printf("request[%d]: WRITE offset=%ld size=%zd\n", buf, v25, v26);
v17 = v26;
if ( v26 )
{
v18 = 0LL;
v17 = 0LL;
while ( 1 )
{
while ( 1 )
{
v19 = pwrite64(v6, &v7[v27 + v17], v26 - v17, v25 + v18);
if ( v19 < 0 )
break;
v18 += v19;
v17 = v18;
if ( v26 == v18 )
goto LABEL_60;
}
if ( *__errno_location() != 4 )
break;
if ( opt_debug )
puts("ubd: img write was interuppted, retrying.");
}
perror("ubd: image write");
}
LABEL_60:
v24 = v26 == v17;
LABEL_46:
while ( 1 )
{
v15 = write(v4, &buf, 8uLL);
if ( v15 >= 0 )
break;
if ( *__errno_location() != 4 )
{
perror("ubd: ubc write");
goto LABEL_73;
}
if ( opt_debug )
puts("ubd: ubc write was interuppted, retrying.");
}
if ( v15 != 8 )
fwrite("ubd: write response was to short\n", 1uLL, 0x21uLL, stderr);
}
else
{
fwrite("ubd: read request was to short\n", 1uLL, 0x1FuLL, stderr);
}
}
goto LABEL_73;
}
if ( *__errno_location() != 4 )
break;
if ( !running )
return 0;
if ( opt_debug )
puts("ubd: ubc poll was interuppted, retrying.");
}
if ( running )
{
perror("ubd: ubc poll");
LABEL_73:
if ( !running )
exit(0);
continue;
}
return 0;
}
}

original_code:
int main(int argc, char **argv)
{
  int ub_fd, bi_fd, ret;
  off_t b;
  char *buf;
  ubc_req req;
  struct pollfd pevent[1];
  int rr_pid;
  parse_cmdline(argc, argv);
  signal(2, sig_handler);
  signal(15, sig_handler);
  if ((ub_fd = open(opt_ubc_device, 02)) < 0) {
    perror("ubd: opening ubc device");
    exit(1);
  }
  if ((bi_fd = open64(opt_image, 02 | 0100 | 0 | 040000,
                     0644)) < 0) {
    perror("ubd: opening image");
    exit(1);
  }
  if (!opt_size) {
    if (ioctl(bi_fd, (((0U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8)) | (((96)) << 0) | ((0) << ((0 +8)+8))), &opt_size) == 0) {
      opt_size /= 2;
    } else if ((b = lseek(bi_fd, 0, 2)) > 0) {
      opt_size = b / 1024;
    } else {
      fprintf(stderr, "ubd: can't detect size of block image\n");
      exit(1);
    }
  }
  if (ioctl(ub_fd, (((1U) << (((0 +8)+8)+14)) | ((('u')) << (0 +8)) | (((1)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &opt_size) < 0) {
    perror("ubb: ioctl(UBC_IOCSSIZE)");
    exit(1);
  }
  if ((buf = mmap(((void *)0), 32 * (1UL << 12), 0x1 | 0x2,
   0x01, ub_fd, 0)) == (void*)-1) {
    perror("ubd: mmap");
    exit(1);
  }
  if (mlockall(1|2)<0) {
    perror("mlockall");
    exit(1);
  }
  if (nice(opt_nice) < 0) {
    perror("ubd: nice");
    exit(1);
  }
  printf("image : %s\n", opt_image);
  printf("size  : %dK\n", opt_size);
  printf("vm    : %p\n", buf);
  if ((rr_pid = fork()) == 0) {
    int bd;
    if ((bd = open(opt_ubb_device, 02)) < 0) {
      printf("couldn't open block device\n");
      exit(0);
    }
    if (ioctl(bd, (((0U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8)) | (((95)) << 0) | ((0) << ((0 +8)+8)))) < 0) {
      printf("error reading partition table\n");
    }
    close(bd);
    exit(0);
  }
  pevent[0].fd = ub_fd;
  pevent[0].events = 0x001;
  running = 1;
  while (1) {
    if (!running) {
      exit(0);
    }
    if (rr_pid) {
      int status;
     if (waitpid(rr_pid, &status, 1) == rr_pid)
       rr_pid = 0;
    }
    while ((ret = poll(pevent, 1, -1)) < 0 && (*__errno_location ()) == 4) {
      if (!running)
 break;
      if (opt_debug)
 printf("ubd: ubc poll was interuppted, retrying.\n");
    }
    if (!running) break;
    if (ret < 0 && (*__errno_location ()) != 4) {
      perror("ubd: ubc poll");
      continue;
    } else if (!(pevent[0].events & 0x001)) continue;
    while ((ret = read(ub_fd, &req, sizeof(req.in))) < 0 && (*__errno_location ()) == 4) {
      if (opt_debug)
 printf("ubd: ubc read was interuppted, retrying.\n");
    }
    if (ret < 0 && (*__errno_location ()) != 4) {
      perror("ubd: ubc read");
      continue;
    } else if (ret != sizeof(req.in)) {
      fprintf(stderr, "ubd: read request was to short\n");
      continue;
    }
    switch(req.in.cmd) {
    case 0:
      if (opt_debug)
 printf("request[%d]: READ offset=%" "l" "d" " size=%zd\n",
        req.in.seq, req.in.offset, req.in.size);
      b = 0;
      while (b != req.in.size) {
 while ((ret = pread64(bi_fd,
        buf + req.in.mmap_offset + b,
        req.in.size - b,
        req.in.offset + b)) < 0 && (*__errno_location ()) == 4) {
   if (opt_debug)
     printf("ubd: img read was interuppted, retrying.\n");
 }
 if (ret < 0 && (*__errno_location ()) != 4) {
   perror("ubd: image read");
   break;
 }
 b += ret;
      }
      req.out.result = (b == req.in.size);
      break;
    case 1:
      if (opt_debug)
 printf("request[%d]: WRITE offset=%" "l" "d" " size=%zd\n",
        req.in.seq, req.in.offset, req.in.size);
      b = 0;
      while (b != req.in.size) {
 while ((ret = pwrite64(bi_fd,
         buf + req.in.mmap_offset + b,
         req.in.size - b,
         req.in.offset + b)) < 0 && (*__errno_location ()) == 4) {
   if (opt_debug)
     printf("ubd: img write was interuppted, retrying.\n");
 }
 if (ret < 0 && (*__errno_location ()) != 4) {
   perror("ubd: image write");
   break;
 }
 b += ret;
      }
      req.out.result = (b == req.in.size);
      break;
    default:
      printf("request[%d]: cmd=%d unknown\n",
      req.in.seq, req.in.cmd);
      break;
    }
    while ((ret = write(ub_fd, &req, sizeof(req.out))) < 0 && (*__errno_location ()) == 4) {
      if (opt_debug)
 printf("ubd: ubc write was interuppted, retrying.\n");
    }
    if (ret < 0 && (*__errno_location ()) != 4) {
      perror("ubd: ubc write");
      continue;
    } else if (ret != sizeof(req.out)) {
      fprintf(stderr, "ubd: write response was to short\n");
      continue;
    }
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int ub_fd; int bi_fd; int ret;
  long b;
  char *buf;
  union ubc_req req;
  struct pollfd pevent[1];
  int rr_pid;
  parse_cmdline(argc, argv);
  signal(2, sig_handler);
  signal(15, sig_handler);
  if ((ub_fd = open(opt_ubc_device, 02)) < 0) {
    perror("ubd: opening ubc device");
    exit(1);
  }
  if ((bi_fd = open64(opt_image, 02 | 0100 | 0 | 040000,
                     0644)) < 0) {
    perror("ubd: opening image");
    exit(1);
  }
  if (!opt_size) {
    if (ioctl(bi_fd, (((0U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8)) | (((96)) << 0) | ((0) << ((0 +8)+8))), &opt_size) == 0) {
      opt_size /= 2;
    } else if ((b = lseek(bi_fd, 0, 2)) > 0) {
      opt_size = b / 1024;
    } else {
      fprintf(stderr, "ubd: can't detect size of block image\n");
      exit(1);
    }
  }
  if (ioctl(ub_fd, (((1U) << (((0 +8)+8)+14)) | ((('u')) << (0 +8)) | (((1)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &opt_size) < 0) {
    perror("ubb: ioctl(UBC_IOCSSIZE)");
    exit(1);
  }
  if ((buf = mmap(((void *)0), 32 * (1UL << 12), 0x1 | 0x2,
   0x01, ub_fd, 0)) == (void *)-1) {
    perror("ubd: mmap");
    exit(1);
  }
  if (mlockall(1|2)<0) {
    perror("mlockall");
    exit(1);
  }
  if (nice(opt_nice) < 0) {
    perror("ubd: nice");
    exit(1);
  }
  printf("image : %s\n", opt_image);
  printf("size  : %dK\n", opt_size);
  printf("vm    : %p\n", buf);
  if ((rr_pid = fork()) == 0) {
    int bd;
    if ((bd = open(opt_ubb_device, 02)) < 0) {
      printf("couldn't open block device\n");
      exit(0);
    }
    if (ioctl(bd, (((0U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8)) | (((95)) << 0) | ((0) << ((0 +8)+8)))) < 0) {
      printf("error reading partition table\n");
    }
    close(bd);
    exit(0);
  }
  pevent[0].fd = ub_fd;
  pevent[0].events = 0x001;
  running = 1;
  while (1) {
    if (!running) {
      exit(0);
    }
    if (rr_pid) {
      int status;
     if (waitpid(rr_pid, &status, 1) == rr_pid)
       rr_pid = 0;
    }
    while ((ret = poll(pevent, 1, -1)) < 0 && (*__errno_location ()) == 4) {
      if (!running)
 break;
      if (opt_debug)
 printf("ubd: ubc poll was interuppted, retrying.\n");
    }
    if (!running) break;
    if (ret < 0 && (*__errno_location ()) != 4) {
      perror("ubd: ubc poll");
      continue;
    } else if (!(pevent[0].events & 0x001)) continue;
    while ((ret = read(ub_fd, &req, sizeof(req.in))) < 0 && (*__errno_location ()) == 4) {
      if (opt_debug)
 printf("ubd: ubc read was interuppted, retrying.\n");
    }
    if (ret < 0 && (*__errno_location ()) != 4) {
      perror("ubd: ubc read");
      continue;
    } else if (ret != sizeof(req.in)) {
      fprintf(stderr, "ubd: read request was to short\n");
      continue;
    }
    switch(req.in.cmd) {
    case 0:
      if (opt_debug)
 printf("request[%d]: READ offset=%" "l" "d" " size=%zd\n",
        req.in.seq, req.in.offset, req.in.size);
      b = 0;
      while (b != req.in.size) {
 while ((ret = pread64(bi_fd,
        buf + req.in.mmap_offset + b,
        req.in.size - b,
        req.in.offset + b)) < 0 && (*__errno_location ()) == 4) {
   if (opt_debug)
     printf("ubd: img read was interuppted, retrying.\n");
 }
 if (ret < 0 && (*__errno_location ()) != 4) {
   perror("ubd: image read");
   break;
 }
 b += ret;
      }
      req.out.result = (b == req.in.size);
      break;
    case 1:
      if (opt_debug)
 printf("request[%d]: WRITE offset=%" "l" "d" " size=%zd\n",
        req.in.seq, req.in.offset, req.in.size);
      b = 0;
      while (b != req.in.size) {
 while ((ret = pwrite64(bi_fd,
         buf + req.in.mmap_offset + b,
         req.in.size - b,
         req.in.offset + b)) < 0 && (*__errno_location ()) == 4) {
   if (opt_debug)
     printf("ubd: img write was interuppted, retrying.\n");
 }
 if (ret < 0 && (*__errno_location ()) != 4) {
   perror("ubd: image write");
   break;
 }
 b += ret;
      }
      req.out.result = (b == req.in.size);
      break;
    default:
      printf("request[%d]: cmd=%d unknown\n",
      req.in.seq, req.in.cmd);
      break;
    }
    while ((ret = write(ub_fd, &req, sizeof(req.out))) < 0 && (*__errno_location ()) == 4) {
      if (opt_debug)
 printf("ubd: ubc write was interuppted, retrying.\n");
    }
    if (ret < 0 && (*__errno_location ()) != 4) {
      perror("ubd: ubc write");
      continue;
    } else if (ret != sizeof(req.out)) {
      fprintf(stderr, "ubd: write response was to short\n");
      continue;
    }
  }
  return 0;
}

variable_types: ret int

variable_types: b long

variable_types:
buf
char *

variable_types: union ubc_req { struct ub_in { int seq; int cmd; long offset; unsigned long size; unsigned long mmap_offset; } in; struct ub_out { int seq; int result; } out; }

variable_types: struct pollfd { int fd; short events; short revents; } [1]

variable_types: bd int

variable_types: status int

user_defined_types: union ubc_req { struct ub_in in; struct ub_out out; }


newTimer

repo: mosinski/Projekty-C

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

result = malloc(0x28uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
return result;
}

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

result = malloc(0x28uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
return result;
}

original_code:
pTimer newTimer() {
 pTimer pT = (pTimer) malloc(sizeof(Timer));
 memset(pT, 0, sizeof(Timer));
 return pT;
}

canonical_original_code:
struct Timer *newTimer() {
 struct Timer *pT = (pTimer) malloc(sizeof(Timer));
 memset(pT, 0, sizeof(Timer));
 return pT;
}

variable_types: struct Timer { struct timespec { long tv_sec; long tv_nsec; } start; struct timespec end; long time; } *

user_defined_types: struct Timer { struct timespec start; struct timespec end; long time; }


freeTimer

decompiled_code:
void __fastcall freeTimer(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func8(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void freeTimer(pTimer pT) {
 if (pT) free(pT);
}

canonical_original_code:
void freeTimer(struct Timer *pT) {
 if (pT) free(pT);
}

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


startTimer

decompiled_code:
int __fastcall startTimer(struct timespec *tp)
{
int result; // eax

if ( tp )
result = clock_gettime(1, tp);
return result;
}

canonical_decompiled_code:
int __fastcall func9(struct timespec *tp)
{
int result; // eax

if ( tp )
result = clock_gettime(1, tp);
return result;
}

original_code:
void startTimer(pTimer pT) {
 if (pT) clock_gettime(1, &(pT->start));
}

canonical_original_code:
void startTimer(struct Timer *pT) {
 if (pT) clock_gettime(1, &(pT->start));
}


resetTimer

original_code:
void resetTimer(pTimer pT) {
 if (pT) memset(pT, 0, sizeof(Timer));
}

canonical_original_code:
void resetTimer(struct Timer *pT) {
 if (pT) memset(pT, 0, sizeof(Timer));
}


timespecDiff

original_code:
long int timespecDiff(pTimeSpec A, pTimeSpec B) {
 return ((A->tv_sec * 1000000000) + A->tv_nsec) - ((B->tv_sec * 1000000000) + B->tv_nsec);
}

canonical_original_code:
long timespecDiff(struct timespec *A, struct timespec *B) {
 return ((A->tv_sec * 1000000000) + A->tv_nsec) - ((B->tv_sec * 1000000000) + B->tv_nsec);
}

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

variable_types:
B
struct timespec *

return_type: long


stopTimer

decompiled_code:
void __fastcall stopTimer(struct timespec *a1)
{
if ( a1 )
{
clock_gettime(1, a1 + 1);
a1[2].tv_sec += timespecDiff(&a1[1].tv_sec, a1);
}
}

canonical_decompiled_code:
void __fastcall func12(struct timespec *a1)
{
if ( a1 )
{
clock_gettime(1, a1 + 1);
a1[2].tv_sec += func11(&a1[1].tv_sec, a1);
}
}

original_code:
void stopTimer(pTimer pT) {
 if (pT) {
  clock_gettime(1, &(pT->end));
  pT->time += timespecDiff(&(pT->end), &(pT->start));
 }
}

canonical_original_code:
void stopTimer(struct Timer *pT) {
 if (pT) {
  clock_gettime(1, &(pT->end));
  pT->time += timespecDiff(&(pT->end), &(pT->start));
 }
}


getTime

decompiled_code:
double __fastcall getTime(__int64 a1)
{
double result; // xmm0_8

result = -1.0;
if ( a1 )
result = (double)(int)*(_QWORD *)(a1 + 32) / 1000000000.0;
return result;
}

canonical_decompiled_code:
double __fastcall func13(__int64 a1)
{
double result; // xmm0_8

result = -1.0;
if ( a1 )
result = (double)(int)*(_QWORD *)(a1 + 32) / 1000000000.0;
return result;
}

original_code:
double getTime(pTimer pT){
 if(pT){
  return (double) pT->time / (double) 1000000000;
 }
 else{
  return -1.0;
 }
}

canonical_original_code:
double getTime(struct Timer *pT){
 if(pT){
  return (double) pT->time / (double) 1000000000;
 }
 else{
  return -1.0;
 }
}

return_type: double


printTimer

decompiled_code:
int __fastcall printTimer(__int64 a1)
{
double v1; // xmm0_8

if ( !a1 )
return printf("NULL");
v1 = getTime(a1);
return printf("%e", v1);
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
double v1; // xmm0_8

if ( !a1 )
return printf("NULL");
v1 = func13(a1);
return printf("%e", v1);
}

original_code:
void printTimer(pTimer pT) {
 if (pT) printf("%e", getTime(pT));
 else printf("NULL");
}

canonical_original_code:
void printTimer(struct Timer *pT) {
 if (pT) printf("%e", getTime(pT));
 else printf("NULL");
}


printTimerFmt

decompiled_code:
int __fastcall printTimerFmt(char *format, __int64 a2)
{
double v2; // xmm0_8

if ( !a2 )
return printf("NULL");
v2 = getTime(a2);
return printf(format, v2);
}

canonical_decompiled_code:
int __fastcall func15(char *format, __int64 a2)
{
double v2; // xmm0_8

if ( !a2 )
return printf("NULL");
v2 = func13(a2);
return printf(format, v2);
}

original_code:
void printTimerFmt(const char* fmt, pTimer pT) {
 if (pT) printf(fmt, getTime(pT));
 else printf("NULL");
}

canonical_original_code:
void printTimerFmt(char *fmt, struct Timer *pT) {
 if (pT) printf(fmt, getTime(pT));
 else printf("NULL");
}

variable_types:
fmt
char *


repo: mpatraw/MOAG

decompiled_code:
int __fastcall rng_seed(int *a1, unsigned int a2)
{
int *v2; // rbx
int result; // eax

srand(a2);
v2 = a1;
do
{
result = rand();
*v2++ = result;
}
while ( v2 != a1 + 4 );
return result;
}

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

srand(a2);
v2 = a1;
do
{
result = rand();
*v2++ = result;
}
while ( v2 != a1 + 4 );
return result;
}

original_code:
void rng_seed(struct rng_state *st, uint32_t seed)
{
 int i;
 srand(seed);
 for (i = 0; i < XOR128_K; ++i)
  st->q[i] = rand();
}

canonical_original_code:
void rng_seed(struct rng_state *st, unsigned int seed)
{
 int i;
 srand(seed);
 for (i = 0; i < XOR128_K; ++i)
  st->q[i] = rand();
}

variable_types: struct rng_state { unsigned int q[-1]; } *

variable_types:
seed
unsigned int

variable_types: i int


canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
unsigned int v1; // edx
unsigned int v2; // ecx
__int64 result; // rax

v1 = *a1 ^ (*a1 << 11);
*a1 = a1[1];
a1[1] = a1[2];
v2 = a1[3];
a1[2] = v2;
result = (v1 >> 8) ^ v1 ^ v2 ^ (v2 >> 19);
a1[3] = result;
return result;
}

variable_types:
t
unsigned int

return_type: unsigned int

user_defined_types: struct rng_state { unsigned int q[-1]; }


decompiled_code:
double __fastcall rng_unit(_DWORD *a1)
{
return (double)(int)rng_u32(a1) * 2.328306436538696e-10;
}

canonical_decompiled_code:
double __fastcall func2(_DWORD *a1)
{
return (double)(int)func1(a1) * 2.328306436538696e-10;
}

original_code:
double rng_unit(struct rng_state *st)
{
 return rng_u32(st) * 2.3283064365386963e-10;
}


decompiled_code:
double __fastcall rng_under(_DWORD *a1, int a2)
{
return (double)a2 * rng_unit(a1);
}

canonical_decompiled_code:
double __fastcall func3(_DWORD *a1, int a2)
{
return (double)a2 * func2(a1);
}

original_code:
double rng_under(struct rng_state *st, int32_t max)
{
 return rng_unit(st) * max;
}

canonical_original_code:
double rng_under(struct rng_state *st, int max)
{
 return rng_unit(st) * max;
}

variable_types: max int


decompiled_code:
double __fastcall rng_between(_DWORD *a1, int a2, int a3)
{
return (double)a2 + rng_under(a1, a3 - a2);
}

canonical_decompiled_code:
double __fastcall func4(_DWORD *a1, int a2, int a3)
{
return (double)a2 + func3(a1, a3 - a2);
}

original_code:
double rng_between(struct rng_state *st, int32_t min, int32_t max)
{
 return rng_under(st, max - min) + min;
}

canonical_original_code:
double rng_between(struct rng_state *st, int min, int max)
{
 return rng_under(st, max - min) + min;
}

variable_types: min int


original_code:
int32_t rng_range(struct rng_state *st, int32_t min, int32_t max)
{
 return floor(rng_between(st, min, max + 1));
}

canonical_original_code:
int rng_range(struct rng_state *st, int min, int max)
{
 return floor(rng_between(st, min, max + 1));
}


pdeath

repo: mumble-voip/sbcelt

decompiled_code:
int pdeath()
{
int result; // eax
__pid_t v1; // edx

result = prctl(1, 9LL);
if ( result != -1 )
{
v1 = getppid();
result = 0;
if ( v1 <= 1 )
exit(0);
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax
__pid_t v1; // edx

result = prctl(1, 9LL);
if ( result != -1 )
{
v1 = getppid();
result = 0;
if ( v1 <= 1 )
exit(0);
}
return result;
}

original_code:
int pdeath() {
 if (prctl(1, 9) == -1)
  return -1;
 if (getppid() <= 1)
  _exit(0);
 return 0;
}


checkBlock

decompiled_code:
void __fastcall checkBlock(_BYTE *a1, char a2, int a3)
{
int i; // eax

if ( a3 > 0 )
{
for ( i = 0; i != a3; ++i )
{
if ( *a1 != a2 )
_assert_fail("block[0] == value", "tests.c", 0xCu, "checkBlock");
}
}
}

canonical_decompiled_code:
void __fastcall func0(_BYTE *a1, char a2, int a3)
{
int i; // eax

if ( a3 > 0 )
{
for ( i = 0; i != a3; ++i )
{
if ( *a1 != a2 )
_assert_fail("block[0] == value", "tests.c", 0xCu, "checkBlock");
}
}
}

original_code:
void checkBlock(unsigned char* block, unsigned char value, size_t size) {
    for (int i = 0; i < (int)size; i++) {
        ((void) sizeof ((block[0] == value) ? 1 : 0), __extension__ ({ if (block[0] == value) ; else __assert_fail ("block[0] == value", "tests.c", 12, __extension__ __PRETTY_FUNCTION__); }));
    }
}

canonical_original_code:
void checkBlock(unsigned char *block, unsigned char value, unsigned long size) {
    for (int i = 0; i < (int)size; i++) {
        ((void) sizeof ((block[0] == value) ? 1 : 0), __extension__ ({ if (block[0] == value) ; else __assert_fail ("block[0] == value", "tests.c", 12, __extension__ __PRETTY_FUNCTION__); }));
    }
}

variable_types:
block
unsigned char *

variable_types:
value
unsigned char

variable_types:
size
unsigned long


testLarge

decompiled_code:
__int64 testLarge()
{
__int64 v0; // rdi
size_t v1; // rbx
__int64 v2; // rbp
void *v3; // rdi
__int64 v4; // rbp
__int64 v5; // rbx
__int64 result; // rax
unsigned __int8 *v7; // rax
__int64 v8; // rcx
__int64 v9[69]; // [rsp+0h] [rbp-228h]

puts("Testing large allocations");
if ( allocatedSpace )
_assert_fail("allocatedSpace == 0", "tests.c", 0x13u, "testLarge");
if ( allocatedChunkCount )
_assert_fail("allocatedChunkCount == 0", "tests.c", 0x14u, "testLarge");
if ( freeChunkCount )
_assert_fail("freeChunkCount == 0", "tests.c", 0x15u, "testLarge");
if ( regionsUsed )
_assert_fail("regionsUsed == 0", "tests.c", 0x16u, "testLarge");
v0 = vmemalloc(70LL);
v9[0] = v0;
if ( !v0 )
_assert_fail("allocd[0] != NULL", "tests.c", 0x1Cu, "testLarge");
*(_QWORD *)v0 = 0x101010101010101LL;
*(_QWORD *)(v0 + 8) = 0x101010101010101LL;
*(_QWORD *)(v0 + 16) = 0x101010101010101LL;
*(_QWORD *)(v0 + 24) = 0x101010101010101LL;
*(_QWORD *)(v0 + 32) = 0x101010101010101LL;
*(_QWORD *)(v0 + 40) = 0x101010101010101LL;
*(_QWORD *)(v0 + 48) = 0x101010101010101LL;
*(_QWORD *)(v0 + 56) = 0x101010101010101LL;
*(_DWORD *)(v0 + 64) = 16843009;
*(_WORD *)(v0 + 68) = 257;
if ( allocatedSpace <= 69 )
_assert_fail("allocatedSpace >= 70", "tests.c", 0x1Fu, "testLarge");
if ( allocatedChunkCount != 1 )
_assert_fail("allocatedChunkCount == 1", "tests.c", 0x20u, "testLarge");
if ( freeChunkCount > 1 )
_assert_fail("freeChunkCount <= 1", "tests.c", 0x21u, "testLarge");
if ( regionsUsed != 1 )
_assert_fail("regionsUsed == 1", "tests.c", 0x22u, "testLarge");
vmemfree(v0);
if ( allocatedSpace )
_assert_fail("allocatedSpace == 0", "tests.c", 0x26u, "testLarge");
if ( allocatedChunkCount )
_assert_fail("allocatedChunkCount == 0", "tests.c", 0x27u, "testLarge");
if ( freeChunkCount )
_assert_fail("freeChunkCount == 0", "tests.c", 0x28u, "testLarge");
if ( regionsUsed )
_assert_fail("regionsUsed == 0", "tests.c", 0x29u, "testLarge");
v1 = 70LL;
v2 = 0LL;
do
{
v3 = (void *)vmemalloc((unsigned int)v1);
v9[v2] = (__int64)v3;
if ( !v3 )
_assert_fail("allocd[i] != NULL", "tests.c", 0x2Eu, "testLarge");
memset(v3, v2++, v1);
v1 += 70LL;
}
while ( v1 != 4620 );
v4 = 69LL;
v5 = 0LL;
do
{
if ( (int)v4 + 1 > 0 )
{
v7 = (unsigned __int8 *)v9[v5];
v8 = (__int64)&v7[v4 + 1];
do
{
if ( *v7 != (_DWORD)v5 )
_assert_fail("allocd[i][j] == i", "tests.c", 0x37u, "testLarge");
++v7;
}
while ( v7 != (unsigned __int8 *)v8 );
}
result = vmemfree(v9[v5++]);
v4 += 70LL;
}
while ( v4 != 4619 );
if ( allocatedSpace )
_assert_fail("allocatedSpace == 0", "tests.c", 0x3Cu, "testLarge");
if ( allocatedChunkCount )
_assert_fail("allocatedChunkCount == 0", "tests.c", 0x3Du, "testLarge");
if ( freeChunkCount )
_assert_fail("freeChunkCount == 0", "tests.c", 0x3Eu, "testLarge");
if ( regionsUsed )
_assert_fail("regionsUsed == 0", "tests.c", 0x3Fu, "testLarge");
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rdi
size_t v1; // rbx
__int64 v2; // rbp
void *v3; // rdi
__int64 v4; // rbp
__int64 v5; // rbx
__int64 result; // rax
unsigned __int8 *v7; // rax
__int64 v8; // rcx
__int64 v9[69]; // [rsp+0h] [rbp-228h]

puts("Testing large allocations");
if ( allocatedSpace )
_assert_fail("allocatedSpace == 0", "tests.c", 0x13u, "testLarge");
if ( allocatedChunkCount )
_assert_fail("allocatedChunkCount == 0", "tests.c", 0x14u, "testLarge");
if ( freeChunkCount )
_assert_fail("freeChunkCount == 0", "tests.c", 0x15u, "testLarge");
if ( regionsUsed )
_assert_fail("regionsUsed == 0", "tests.c", 0x16u, "testLarge");
v0 = vmemalloc(70LL);
v9[0] = v0;
if ( !v0 )
_assert_fail("allocd[0] != NULL", "tests.c", 0x1Cu, "testLarge");
*(_QWORD *)v0 = 0x101010101010101LL;
*(_QWORD *)(v0 + 8) = 0x101010101010101LL;
*(_QWORD *)(v0 + 16) = 0x101010101010101LL;
*(_QWORD *)(v0 + 24) = 0x101010101010101LL;
*(_QWORD *)(v0 + 32) = 0x101010101010101LL;
*(_QWORD *)(v0 + 40) = 0x101010101010101LL;
*(_QWORD *)(v0 + 48) = 0x101010101010101LL;
*(_QWORD *)(v0 + 56) = 0x101010101010101LL;
*(_DWORD *)(v0 + 64) = 16843009;
*(_WORD *)(v0 + 68) = 257;
if ( allocatedSpace <= 69 )
_assert_fail("allocatedSpace >= 70", "tests.c", 0x1Fu, "testLarge");
if ( allocatedChunkCount != 1 )
_assert_fail("allocatedChunkCount == 1", "tests.c", 0x20u, "testLarge");
if ( freeChunkCount > 1 )
_assert_fail("freeChunkCount <= 1", "tests.c", 0x21u, "testLarge");
if ( regionsUsed != 1 )
_assert_fail("regionsUsed == 1", "tests.c", 0x22u, "testLarge");
vmemfree(v0);
if ( allocatedSpace )
_assert_fail("allocatedSpace == 0", "tests.c", 0x26u, "testLarge");
if ( allocatedChunkCount )
_assert_fail("allocatedChunkCount == 0", "tests.c", 0x27u, "testLarge");
if ( freeChunkCount )
_assert_fail("freeChunkCount == 0", "tests.c", 0x28u, "testLarge");
if ( regionsUsed )
_assert_fail("regionsUsed == 0", "tests.c", 0x29u, "testLarge");
v1 = 70LL;
v2 = 0LL;
do
{
v3 = (void *)vmemalloc((unsigned int)v1);
v9[v2] = (__int64)v3;
if ( !v3 )
_assert_fail("allocd[i] != NULL", "tests.c", 0x2Eu, "testLarge");
memset(v3, v2++, v1);
v1 += 70LL;
}
while ( v1 != 4620 );
v4 = 69LL;
v5 = 0LL;
do
{
if ( (int)v4 + 1 > 0 )
{
v7 = (unsigned __int8 *)v9[v5];
v8 = (__int64)&v7[v4 + 1];
do
{
if ( *v7 != (_DWORD)v5 )
_assert_fail("allocd[i][j] == i", "tests.c", 0x37u, "testLarge");
++v7;
}
while ( v7 != (unsigned __int8 *)v8 );
}
result = vmemfree(v9[v5++]);
v4 += 70LL;
}
while ( v4 != 4619 );
if ( allocatedSpace )
_assert_fail("allocatedSpace == 0", "tests.c", 0x3Cu, "testLarge");
if ( allocatedChunkCount )
_assert_fail("allocatedChunkCount == 0", "tests.c", 0x3Du, "testLarge");
if ( freeChunkCount )
_assert_fail("freeChunkCount == 0", "tests.c", 0x3Eu, "testLarge");
if ( regionsUsed )
_assert_fail("regionsUsed == 0", "tests.c", 0x3Fu, "testLarge");
return result;
}

original_code:
void testLarge() {
    printf("Testing large allocations\n");
    ((void) sizeof ((allocatedSpace == 0) ? 1 : 0), __extension__ ({ if (allocatedSpace == 0) ; else __assert_fail ("allocatedSpace == 0", "tests.c", 19, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((allocatedChunkCount == 0) ? 1 : 0), __extension__ ({ if (allocatedChunkCount == 0) ; else __assert_fail ("allocatedChunkCount == 0", "tests.c", 20, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((freeChunkCount == 0) ? 1 : 0), __extension__ ({ if (freeChunkCount == 0) ; else __assert_fail ("freeChunkCount == 0", "tests.c", 21, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((regionsUsed == 0) ? 1 : 0), __extension__ ({ if (regionsUsed == 0) ; else __assert_fail ("regionsUsed == 0", "tests.c", 22, __extension__ __PRETTY_FUNCTION__); }));
    unsigned char* allocd[65];
    allocd[0] = vmemalloc(70);
    ((void) sizeof ((allocd[0] != ((void *)0)) ? 1 : 0), __extension__ ({ if (allocd[0] != ((void *)0)) ; else __assert_fail ("allocd[0] != NULL", "tests.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    memset(allocd[0], 1, 70);
    ((void) sizeof ((allocatedSpace >= 70) ? 1 : 0), __extension__ ({ if (allocatedSpace >= 70) ; else __assert_fail ("allocatedSpace >= 70", "tests.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((allocatedChunkCount == 1) ? 1 : 0), __extension__ ({ if (allocatedChunkCount == 1) ; else __assert_fail ("allocatedChunkCount == 1", "tests.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((freeChunkCount <= 1) ? 1 : 0), __extension__ ({ if (freeChunkCount <= 1) ; else __assert_fail ("freeChunkCount <= 1", "tests.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((regionsUsed == 1) ? 1 : 0), __extension__ ({ if (regionsUsed == 1) ; else __assert_fail ("regionsUsed == 1", "tests.c", 34, __extension__ __PRETTY_FUNCTION__); }));
    vmemfree(allocd[0]);
    ((void) sizeof ((allocatedSpace == 0) ? 1 : 0), __extension__ ({ if (allocatedSpace == 0) ; else __assert_fail ("allocatedSpace == 0", "tests.c", 38, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((allocatedChunkCount == 0) ? 1 : 0), __extension__ ({ if (allocatedChunkCount == 0) ; else __assert_fail ("allocatedChunkCount == 0", "tests.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((freeChunkCount == 0) ? 1 : 0), __extension__ ({ if (freeChunkCount == 0) ; else __assert_fail ("freeChunkCount == 0", "tests.c", 40, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((regionsUsed == 0) ? 1 : 0), __extension__ ({ if (regionsUsed == 0) ; else __assert_fail ("regionsUsed == 0", "tests.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    int sizeToAlloc = 70;
    for (int i = 0; i < 65; i++) {
        allocd[i] = vmemalloc(sizeToAlloc);
        ((void) sizeof ((allocd[i] != ((void *)0)) ? 1 : 0), __extension__ ({ if (allocd[i] != ((void *)0)) ; else __assert_fail ("allocd[i] != NULL", "tests.c", 46, __extension__ __PRETTY_FUNCTION__); }));
        memset(allocd[i], i, sizeToAlloc);
        sizeToAlloc += 70;
    }
    sizeToAlloc = 70;
    for (int i = 0; i < 65; i++) {
        for (int j = 0; j < sizeToAlloc; j++) {
            ((void) sizeof ((allocd[i][j] == i) ? 1 : 0), __extension__ ({ if (allocd[i][j] == i) ; else __assert_fail ("allocd[i][j] == i", "tests.c", 55, __extension__ __PRETTY_FUNCTION__); }));
        }
        vmemfree(allocd[i]);
        sizeToAlloc += 70;
    }
    ((void) sizeof ((allocatedSpace == 0) ? 1 : 0), __extension__ ({ if (allocatedSpace == 0) ; else __assert_fail ("allocatedSpace == 0", "tests.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((allocatedChunkCount == 0) ? 1 : 0), __extension__ ({ if (allocatedChunkCount == 0) ; else __assert_fail ("allocatedChunkCount == 0", "tests.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((freeChunkCount == 0) ? 1 : 0), __extension__ ({ if (freeChunkCount == 0) ; else __assert_fail ("freeChunkCount == 0", "tests.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((regionsUsed == 0) ? 1 : 0), __extension__ ({ if (regionsUsed == 0) ; else __assert_fail ("regionsUsed == 0", "tests.c", 63, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void testLarge() {
    printf("Testing large allocations\n");
    ((void) sizeof ((allocatedSpace == 0) ? 1 : 0), __extension__ ({ if (allocatedSpace == 0) ; else __assert_fail ("allocatedSpace == 0", "tests.c", 19, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((allocatedChunkCount == 0) ? 1 : 0), __extension__ ({ if (allocatedChunkCount == 0) ; else __assert_fail ("allocatedChunkCount == 0", "tests.c", 20, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((freeChunkCount == 0) ? 1 : 0), __extension__ ({ if (freeChunkCount == 0) ; else __assert_fail ("freeChunkCount == 0", "tests.c", 21, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((regionsUsed == 0) ? 1 : 0), __extension__ ({ if (regionsUsed == 0) ; else __assert_fail ("regionsUsed == 0", "tests.c", 22, __extension__ __PRETTY_FUNCTION__); }));
    unsigned char *allocd[65];
    allocd[0] = vmemalloc(70);
    ((void) sizeof ((allocd[0] != ((void *)0)) ? 1 : 0), __extension__ ({ if (allocd[0] != ((void *)0)) ; else __assert_fail ("allocd[0] != NULL", "tests.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    memset(allocd[0], 1, 70);
    ((void) sizeof ((allocatedSpace >= 70) ? 1 : 0), __extension__ ({ if (allocatedSpace >= 70) ; else __assert_fail ("allocatedSpace >= 70", "tests.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((allocatedChunkCount == 1) ? 1 : 0), __extension__ ({ if (allocatedChunkCount == 1) ; else __assert_fail ("allocatedChunkCount == 1", "tests.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((freeChunkCount <= 1) ? 1 : 0), __extension__ ({ if (freeChunkCount <= 1) ; else __assert_fail ("freeChunkCount <= 1", "tests.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((regionsUsed == 1) ? 1 : 0), __extension__ ({ if (regionsUsed == 1) ; else __assert_fail ("regionsUsed == 1", "tests.c", 34, __extension__ __PRETTY_FUNCTION__); }));
    vmemfree(allocd[0]);
    ((void) sizeof ((allocatedSpace == 0) ? 1 : 0), __extension__ ({ if (allocatedSpace == 0) ; else __assert_fail ("allocatedSpace == 0", "tests.c", 38, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((allocatedChunkCount == 0) ? 1 : 0), __extension__ ({ if (allocatedChunkCount == 0) ; else __assert_fail ("allocatedChunkCount == 0", "tests.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((freeChunkCount == 0) ? 1 : 0), __extension__ ({ if (freeChunkCount == 0) ; else __assert_fail ("freeChunkCount == 0", "tests.c", 40, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((regionsUsed == 0) ? 1 : 0), __extension__ ({ if (regionsUsed == 0) ; else __assert_fail ("regionsUsed == 0", "tests.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    int sizeToAlloc = 70;
    for (int i = 0; i < 65; i++) {
        allocd[i] = vmemalloc(sizeToAlloc);
        ((void) sizeof ((allocd[i] != ((void *)0)) ? 1 : 0), __extension__ ({ if (allocd[i] != ((void *)0)) ; else __assert_fail ("allocd[i] != NULL", "tests.c", 46, __extension__ __PRETTY_FUNCTION__); }));
        memset(allocd[i], i, sizeToAlloc);
        sizeToAlloc += 70;
    }
    sizeToAlloc = 70;
    for (int i = 0; i < 65; i++) {
        for (int j = 0; j < sizeToAlloc; j++) {
            ((void) sizeof ((allocd[i][j] == i) ? 1 : 0), __extension__ ({ if (allocd[i][j] == i) ; else __assert_fail ("allocd[i][j] == i", "tests.c", 55, __extension__ __PRETTY_FUNCTION__); }));
        }
        vmemfree(allocd[i]);
        sizeToAlloc += 70;
    }
    ((void) sizeof ((allocatedSpace == 0) ? 1 : 0), __extension__ ({ if (allocatedSpace == 0) ; else __assert_fail ("allocatedSpace == 0", "tests.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((allocatedChunkCount == 0) ? 1 : 0), __extension__ ({ if (allocatedChunkCount == 0) ; else __assert_fail ("allocatedChunkCount == 0", "tests.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((freeChunkCount == 0) ? 1 : 0), __extension__ ({ if (freeChunkCount == 0) ; else __assert_fail ("freeChunkCount == 0", "tests.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((regionsUsed == 0) ? 1 : 0), __extension__ ({ if (regionsUsed == 0) ; else __assert_fail ("regionsUsed == 0", "tests.c", 63, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
allocd
unsigned char *[65]

variable_types: sizeToAlloc int

variable_types: j int


testSmall

decompiled_code:
__int64 testSmall()
{
_BYTE *v0; // rax
__int64 i; // rbx
_BYTE *v2; // rax
_QWORD *v3; // rax
__int64 j; // rbx
_BYTE *v5; // rdi
_QWORD *v6; // rdi
__int64 k; // rbx
_BYTE *v8; // rdi
_QWORD *v9; // rdi
__int64 result; // rax
__int64 v11[66]; // [rsp+0h] [rbp-428h]
__int64 v12[67]; // [rsp+210h] [rbp-218h]

puts("Testing small allocations");
v0 = (_BYTE *)vmemalloc(1LL);
v12[0] = (__int64)v0;
if ( !v0 )
_assert_fail("chars[0] != NULL", "tests.c", 0x4Bu, "testSmall");
*v0 = -1;
if ( allocatedSpace <= 0 )
_assert_fail("allocatedSpace >= (int)sizeof(char)", "tests.c", 0x4Du, "testSmall");
if ( allocatedChunkCount != 1 )
_assert_fail("allocatedChunkCount == 1", "tests.c", 0x4Eu, "testSmall");
if ( freeChunkCount > 1 )
_assert_fail("freeChunkCount <= 1", "tests.c", 0x4Fu, "testSmall");
if ( regionsUsed != 1 )
_assert_fail("regionsUsed == 1", "tests.c", 0x50u, "testSmall");
vmemfree(v0);
if ( allocatedSpace )
_assert_fail("allocatedSpace == 0", "tests.c", 0x54u, "testSmall");
if ( allocatedChunkCount )
_assert_fail("allocatedChunkCount == 0", "tests.c", 0x55u, "testSmall");
if ( regionsUsed )
_assert_fail("regionsUsed == 0", "tests.c", 0x56u, "testSmall");
if ( freeChunkCount )
_assert_fail("freeChunkCount == 0", "tests.c", 0x57u, "testSmall");
for ( i = 0LL; i != 65; ++i )
{
v2 = (_BYTE *)vmemalloc(1LL);
v12[i] = (__int64)v2;
*v2 = i;
v3 = (_QWORD *)vmemalloc(8LL);
v11[i] = (__int64)v3;
*v3 = i;
}
if ( allocatedSpace <= 584 )
_assert_fail("allocatedSpace >= NUM_TO_ALLOC * (int)(sizeof(char) + sizeof(long))", "tests.c", 0x60u, "testSmall");
if ( allocatedChunkCount <= 0 )
_assert_fail("allocatedChunkCount > 0", "tests.c", 0x61u, "testSmall");
if ( regionsUsed <= 0 )
_assert_fail("regionsUsed > 0", "tests.c", 0x62u, "testSmall");
for ( j = 32LL; j != 65; ++j )
{
v5 = (_BYTE *)v12[j];
if ( *v5 != (_BYTE)j )
_assert_fail("*chars[i] == (char)i", "tests.c", 0x67u, "testSmall");
vmemfree(v5);
v6 = (_QWORD *)v11[j];
if ( *v6 != j )
_assert_fail("*longs[i] == (long)i", "tests.c", 0x69u, "testSmall");
vmemfree(v6);
}
for ( k = 31LL; k != -1; --k )
{
v8 = (_BYTE *)v12[k];
if ( *v8 != (_BYTE)k )
_assert_fail("*chars[i] == (char)i", "tests.c", 0x6Eu, "testSmall");
vmemfree(v8);
v9 = (_QWORD *)v11[k];
if ( *v9 != k )
_assert_fail("*longs[i] == (long)i", "tests.c", 0x70u, "testSmall");
result = vmemfree(v9);
}
if ( allocatedSpace )
_assert_fail("allocatedSpace == 0", "tests.c", 0x74u, "testSmall");
if ( allocatedChunkCount )
_assert_fail("allocatedChunkCount == 0", "tests.c", 0x75u, "testSmall");
if ( regionsUsed )
_assert_fail("regionsUsed == 0", "tests.c", 0x76u, "testSmall");
if ( freeChunkCount )
_assert_fail("freeChunkCount == 0", "tests.c", 0x77u, "testSmall");
return result;
}

canonical_decompiled_code:
__int64 func2()
{
_BYTE *v0; // rax
__int64 i; // rbx
_BYTE *v2; // rax
_QWORD *v3; // rax
__int64 j; // rbx
_BYTE *v5; // rdi
_QWORD *v6; // rdi
__int64 k; // rbx
_BYTE *v8; // rdi
_QWORD *v9; // rdi
__int64 result; // rax
__int64 v11[66]; // [rsp+0h] [rbp-428h]
__int64 v12[67]; // [rsp+210h] [rbp-218h]

puts("Testing small allocations");
v0 = (_BYTE *)vmemalloc(1LL);
v12[0] = (__int64)v0;
if ( !v0 )
_assert_fail("chars[0] != NULL", "tests.c", 0x4Bu, "testSmall");
*v0 = -1;
if ( allocatedSpace <= 0 )
_assert_fail("allocatedSpace >= (int)sizeof(char)", "tests.c", 0x4Du, "testSmall");
if ( allocatedChunkCount != 1 )
_assert_fail("allocatedChunkCount == 1", "tests.c", 0x4Eu, "testSmall");
if ( freeChunkCount > 1 )
_assert_fail("freeChunkCount <= 1", "tests.c", 0x4Fu, "testSmall");
if ( regionsUsed != 1 )
_assert_fail("regionsUsed == 1", "tests.c", 0x50u, "testSmall");
vmemfree(v0);
if ( allocatedSpace )
_assert_fail("allocatedSpace == 0", "tests.c", 0x54u, "testSmall");
if ( allocatedChunkCount )
_assert_fail("allocatedChunkCount == 0", "tests.c", 0x55u, "testSmall");
if ( regionsUsed )
_assert_fail("regionsUsed == 0", "tests.c", 0x56u, "testSmall");
if ( freeChunkCount )
_assert_fail("freeChunkCount == 0", "tests.c", 0x57u, "testSmall");
for ( i = 0LL; i != 65; ++i )
{
v2 = (_BYTE *)vmemalloc(1LL);
v12[i] = (__int64)v2;
*v2 = i;
v3 = (_QWORD *)vmemalloc(8LL);
v11[i] = (__int64)v3;
*v3 = i;
}
if ( allocatedSpace <= 584 )
_assert_fail("allocatedSpace >= NUM_TO_ALLOC * (int)(sizeof(char) + sizeof(long))", "tests.c", 0x60u, "testSmall");
if ( allocatedChunkCount <= 0 )
_assert_fail("allocatedChunkCount > 0", "tests.c", 0x61u, "testSmall");
if ( regionsUsed <= 0 )
_assert_fail("regionsUsed > 0", "tests.c", 0x62u, "testSmall");
for ( j = 32LL; j != 65; ++j )
{
v5 = (_BYTE *)v12[j];
if ( *v5 != (_BYTE)j )
_assert_fail("*chars[i] == (char)i", "tests.c", 0x67u, "testSmall");
vmemfree(v5);
v6 = (_QWORD *)v11[j];
if ( *v6 != j )
_assert_fail("*longs[i] == (long)i", "tests.c", 0x69u, "testSmall");
vmemfree(v6);
}
for ( k = 31LL; k != -1; --k )
{
v8 = (_BYTE *)v12[k];
if ( *v8 != (_BYTE)k )
_assert_fail("*chars[i] == (char)i", "tests.c", 0x6Eu, "testSmall");
vmemfree(v8);
v9 = (_QWORD *)v11[k];
if ( *v9 != k )
_assert_fail("*longs[i] == (long)i", "tests.c", 0x70u, "testSmall");
result = vmemfree(v9);
}
if ( allocatedSpace )
_assert_fail("allocatedSpace == 0", "tests.c", 0x74u, "testSmall");
if ( allocatedChunkCount )
_assert_fail("allocatedChunkCount == 0", "tests.c", 0x75u, "testSmall");
if ( regionsUsed )
_assert_fail("regionsUsed == 0", "tests.c", 0x76u, "testSmall");
if ( freeChunkCount )
_assert_fail("freeChunkCount == 0", "tests.c", 0x77u, "testSmall");
return result;
}

original_code:
void testSmall() {
    printf("Testing small allocations\n");
    char *chars[65];
    long *longs[65];
    chars[0] = vmemalloc(sizeof(char));
    ((void) sizeof ((chars[0] != ((void *)0)) ? 1 : 0), __extension__ ({ if (chars[0] != ((void *)0)) ; else __assert_fail ("chars[0] != NULL", "tests.c", 75, __extension__ __PRETTY_FUNCTION__); }));
    *chars[0] = (char)~0;
    ((void) sizeof ((allocatedSpace >= (int)sizeof(char)) ? 1 : 0), __extension__ ({ if (allocatedSpace >= (int)sizeof(char)) ; else __assert_fail ("allocatedSpace >= (int)sizeof(char)", "tests.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((allocatedChunkCount == 1) ? 1 : 0), __extension__ ({ if (allocatedChunkCount == 1) ; else __assert_fail ("allocatedChunkCount == 1", "tests.c", 78, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((freeChunkCount <= 1) ? 1 : 0), __extension__ ({ if (freeChunkCount <= 1) ; else __assert_fail ("freeChunkCount <= 1", "tests.c", 79, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((regionsUsed == 1) ? 1 : 0), __extension__ ({ if (regionsUsed == 1) ; else __assert_fail ("regionsUsed == 1", "tests.c", 80, __extension__ __PRETTY_FUNCTION__); }));
    vmemfree(chars[0]);
    ((void) sizeof ((allocatedSpace == 0) ? 1 : 0), __extension__ ({ if (allocatedSpace == 0) ; else __assert_fail ("allocatedSpace == 0", "tests.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((allocatedChunkCount == 0) ? 1 : 0), __extension__ ({ if (allocatedChunkCount == 0) ; else __assert_fail ("allocatedChunkCount == 0", "tests.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((regionsUsed == 0) ? 1 : 0), __extension__ ({ if (regionsUsed == 0) ; else __assert_fail ("regionsUsed == 0", "tests.c", 86, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((freeChunkCount == 0) ? 1 : 0), __extension__ ({ if (freeChunkCount == 0) ; else __assert_fail ("freeChunkCount == 0", "tests.c", 87, __extension__ __PRETTY_FUNCTION__); }));
    for (int i = 0; i < 65; i++) {
        chars[i] = vmemalloc(sizeof(char));
        *chars[i] = (char)i;
        longs[i] = vmemalloc(sizeof(long));
        *longs[i] = (long)i;
    }
    ((void) sizeof ((allocatedSpace >= 65 * (int)(sizeof(char) + sizeof(long))) ? 1 : 0), __extension__ ({ if (allocatedSpace >= 65 * (int)(sizeof(char) + sizeof(long))) ; else __assert_fail ("allocatedSpace >= NUM_TO_ALLOC * (int)(sizeof(char) + sizeof(long))", "tests.c", 96, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((allocatedChunkCount > 0) ? 1 : 0), __extension__ ({ if (allocatedChunkCount > 0) ; else __assert_fail ("allocatedChunkCount > 0", "tests.c", 97, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((regionsUsed > 0) ? 1 : 0), __extension__ ({ if (regionsUsed > 0) ; else __assert_fail ("regionsUsed > 0", "tests.c", 98, __extension__ __PRETTY_FUNCTION__); }));
    int middle = 65 / 2;
    for (int i = middle; i < 65; i++) {
        ((void) sizeof ((*chars[i] == (char)i) ? 1 : 0), __extension__ ({ if (*chars[i] == (char)i) ; else __assert_fail ("*chars[i] == (char)i", "tests.c", 103, __extension__ __PRETTY_FUNCTION__); }));
        vmemfree(chars[i]);
        ((void) sizeof ((*longs[i] == (long)i) ? 1 : 0), __extension__ ({ if (*longs[i] == (long)i) ; else __assert_fail ("*longs[i] == (long)i", "tests.c", 105, __extension__ __PRETTY_FUNCTION__); }));
        vmemfree(longs[i]);
    }
    for (int i = middle - 1; i >= 0; i--) {
        ((void) sizeof ((*chars[i] == (char)i) ? 1 : 0), __extension__ ({ if (*chars[i] == (char)i) ; else __assert_fail ("*chars[i] == (char)i", "tests.c", 110, __extension__ __PRETTY_FUNCTION__); }));
        vmemfree(chars[i]);
        ((void) sizeof ((*longs[i] == (long)i) ? 1 : 0), __extension__ ({ if (*longs[i] == (long)i) ; else __assert_fail ("*longs[i] == (long)i", "tests.c", 112, __extension__ __PRETTY_FUNCTION__); }));
        vmemfree(longs[i]);
    }
    ((void) sizeof ((allocatedSpace == 0) ? 1 : 0), __extension__ ({ if (allocatedSpace == 0) ; else __assert_fail ("allocatedSpace == 0", "tests.c", 116, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((allocatedChunkCount == 0) ? 1 : 0), __extension__ ({ if (allocatedChunkCount == 0) ; else __assert_fail ("allocatedChunkCount == 0", "tests.c", 117, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((regionsUsed == 0) ? 1 : 0), __extension__ ({ if (regionsUsed == 0) ; else __assert_fail ("regionsUsed == 0", "tests.c", 118, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((freeChunkCount == 0) ? 1 : 0), __extension__ ({ if (freeChunkCount == 0) ; else __assert_fail ("freeChunkCount == 0", "tests.c", 119, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
chars
char *[65]

variable_types:
longs
long *[65]

variable_types: middle int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
setupTimer(argc, argv, envp);
setTraceFile("experiment2.csv");
testLarge();
testSmall();
closeTraceFile();
puts("Test succeeded.");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
setupTimer(argc, argv, envp);
setTraceFile("experiment2.csv");
func1();
func2();
closeTraceFile();
puts("Test succeeded.");
return 0;
}

original_code:
int main(){
    setupTimer();
    setTraceFile("experiment2.csv");
    testLarge();
    testSmall();
    closeTraceFile();
    printf("Test succeeded.\n");
    return 0;
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // rax

get_pgpg_stats();
v4 = v3;
while ( 1 )
{
get_pgpg_stats();
if ( v6 == v4 )
{
usleep(0x30D40u);
}
else
{
get_pgpg_stats();
v4 = v5;
set_led(1);
usleep(0x9C40u);
set_led(0);
usleep(0x2710u);
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // rax

func8();
v4 = v3;
while ( 1 )
{
func8();
if ( v6 == v4 )
{
usleep(0x30D40u);
}
else
{
func8();
v4 = v5;
func7(1);
usleep(0x9C40u);
func7(0);
usleep(0x2710u);
}
}
}

original_code:
int main() {
    long last_stat = get_pgpg_stats();
    for (;;) {
        while (get_pgpg_stats() != last_stat) {
            last_stat = get_pgpg_stats();
            set_led(1);
            usleep(flash_off_interval);
            set_led(0);
            usleep(flash_on_interval);
        }
        usleep(check_interval);
    }
}


yyparse

repo: norman-ipn/Partituras

original_code:
int
yyparse (void)
{
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    YYSTYPE yyvsa[200];
    YYSTYPE *yyvs;
    YYSTYPE *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (yytype_int16) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      long unsigned int yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 5)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-5))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 262 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 5 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 3:
    {}
    break;
  case 4:
    {
     escribir(fichero, (yyvsp[-2].sval));
   }
    break;
  case 6:
    {
       escribir(fichero, (yyvsp[0].sval));
   }
    break;
  case 8:
    {
       escribirTiempo(fichero, (yyvsp[0].ival));
   }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 8;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 5 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 262 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-5))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 5 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned) (yychar) <= 262 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

canonical_original_code:
int yyparse()
{
    int yystate;
    int yyerrstatus;
    short yyssa[200];
    short *yyss;
    short *yyssp;
    union YYSTYPE yyvsa[200];
    union YYSTYPE *yyvs;
    union YYSTYPE *yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  union YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (short) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      unsigned long yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        short *yyss1 = yyss;
        union yyalloc *yyptr = (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 5)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-5))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 262 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 5 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 3:
    {}
    break;
  case 4:
    {
     escribir(fichero, (yyvsp[-2].sval));
   }
    break;
  case 6:
    {
       escribir(fichero, (yyvsp[0].sval));
   }
    break;
  case 8:
    {
       escribirTiempo(fichero, (yyvsp[0].ival));
   }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 8;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 5 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 262 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-5))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 5 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned int) (yychar) <= 262 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyssp
short *

variable_types: union YYSTYPE { char *sval; int ival; } [200]

variable_types: union YYSTYPE { char *sval; int ival; } *

variable_types:
yystacksize
unsigned long

variable_types: yyn int

variable_types: yyresult int

variable_types: yytoken int

variable_types:
yyval
union YYSTYPE { char *sval; int ival; }

variable_types: yylen int

variable_types:
yysize
unsigned long

variable_types: union yyalloc { short yyss_alloc; union YYSTYPE { char *sval; int ival; } yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: yylhs int

variable_types: yyi int

user_defined_types: union yyalloc { short yyss_alloc; union YYSTYPE yyvs_alloc; }


yyerror

decompiled_code:
int __fastcall yyerror(const char *a1)
{
return printf("Error: %s \n", a1);
}

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

original_code:
int yyerror(char *s){
 printf("Error: %s \n", s);
}

variable_types:
s
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
fichero = fopen("Partitura.l", "w");
escribir_encabezado(fichero);
yyparse();
escribir_piePagina(fichero);
fclose(fichero);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
fichero = fopen("Partitura.l", "w");
escribir_encabezado(fichero);
func1();
escribir_piePagina(fichero);
fclose(fichero);
return 0;
}

original_code:
int main( int argc, char **argv){
 fichero = fopen("Partitura.l", "w");
 escribir_encabezado(fichero);
 yyparse();
 escribir_piePagina(fichero);
 fclose(fichero);
}

canonical_original_code:
int main(int argc, char **argv){
 fichero = fopen("Partitura.l", "w");
 escribir_encabezado(fichero);
 yyparse();
 escribir_piePagina(fichero);
 fclose(fichero);
}

variable_types: argc int

variable_types:
argv
char **


repo: odkq/simplebf

original_code:
static int pop_loop(struct loops *loops, unsigned int end_position)
{
 loops->current_in_stack->end = end_position;
 loops->current_in_stack = loops->current_in_stack->previous_in_stack;
 return 0;
}

variable_types: struct loops { struct loop { unsigned int start; unsigned int end; struct loop *next_in_list; struct loop *previous_in_stack; } *first; struct loop *current_in_list; struct loop *current_in_stack; } *

user_defined_types: struct loops { struct loop *first; struct loop *current_in_list; struct loop *current_in_stack; }


decompiled_code:
void __fastcall free_memory_blocks(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 3750);
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 3750);
free(v2);
}
}

original_code:
static void free_memory_blocks(struct memory_block *first_block)
{
 struct memory_block *current, *previous;
 current = previous = first_block;
 while (current) {
  previous = current;
  current = current->next;
  free(previous);
 }
}

canonical_original_code:
static void free_memory_blocks(struct memory_block *first_block)
{
 struct memory_block *current; struct memory_block *previous;
 current = previous = first_block;
 while (current) {
  previous = current;
  current = current->next;
  free(previous);
 }
}

variable_types: struct memory_block { unsigned char m[30000]; struct memory_block *next; struct memory_block *previous; } *


decompiled_code:
void __fastcall free_loops(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
static void free_loops(struct loops *loops)
{
 struct loop *l, *n;
 l = loops->first;
 while (l != ((void *)0)) {
  n = l->next_in_list;
  free(l);
  l = n;
 }
 free(loops);
}

canonical_original_code:
static void free_loops(struct loops *loops)
{
 struct loop *l; struct loop *n;
 l = loops->first;
 while (l != ((void *)0)) {
  n = l->next_in_list;
  free(l);
  l = n;
 }
 free(loops);
}

variable_types: struct loop { unsigned int start; unsigned int end; struct loop *next_in_list; struct loop *previous_in_stack; } *


original_code:
static int push_loop(struct loops *loops, unsigned int start_position)
{
 struct loop *l;
 if ((l = (struct loop *)malloc(sizeof(struct loop))) == ((void *)0))
  return 1;
 l->start = start_position;
 l->end = 0;
 l->previous_in_stack = loops->current_in_stack;
 l->next_in_list = ((void *)0);
 if (loops->current_in_list != ((void *)0))
  loops->current_in_list->next_in_list = l;
 else
  loops->first = l;
 loops->current_in_list = l;
 loops->current_in_stack = l;
 return 0;
}

user_defined_types: struct loop { unsigned int start; unsigned int end; struct loop *next_in_list; struct loop *previous_in_stack; }


original_code:
static int walk_fd(unsigned char *array, int fd)
{
 int c, i, j;
 ssize_t sread;
 unsigned char *p;
 char id[8] = "><+-.,[]";
 char buf[1024];
 p = array;
 do {
  sread = read(fd, buf, 1024);
  if (sread == (ssize_t)-1) {
   fprintf(stderr, "read(): %s", strerror((*__errno_location ())));
   return -1;
  }
  for (j = 0; j < (int)sread; j++) {
   c = buf[j];
   for (i = 0; i < 8; i++) {
    if (id[i] == c) {
     *p++ = c;
     break;
    }
   }
  }
 } while (sread == ((ssize_t)1024));
 return 0;
}

canonical_original_code:
static int walk_fd(unsigned char *array, int fd)
{
 int c; int i; int j;
 long sread;
 unsigned char *p;
 char id[8] = "><+-.,[]";
 char buf[1024];
 p = array;
 do {
  sread = read(fd, buf, 1024);
  if (sread == (long)-1) {
   fprintf(stderr, "read(): %s", strerror((*__errno_location ())));
   return -1;
  }
  for (j = 0; j < (int)sread; j++) {
   c = buf[j];
   for (i = 0; i < 8; i++) {
    if (id[i] == c) {
     *p++ = c;
     break;
    }
   }
  }
 } while (sread == ((long)1024));
 return 0;
}

variable_types:
array
unsigned char *

variable_types: fd int

variable_types: c int

variable_types: i int

variable_types: j int

variable_types: sread long

variable_types:
p
unsigned char *

variable_types:
id
char [8]

variable_types:
buf
char [1024]


simplebf

decompiled_code:
__int64 __fastcall simplebf(char *a1, __int64 *a2)
{
_QWORD *v2; // rax
void *v3; // r14
unsigned __int8 *v4; // r13
char v5; // al
__int64 v6; // r15
int v7; // ebp
int v8; // ebx
unsigned __int8 *v9; // rax
__int64 v11; // rax
int *v12; // rax

v2 = new_memory_block(0LL, 0LL);
if ( !v2 )
return 1LL;
v3 = v2;
v4 = (unsigned __int8 *)v2;
v5 = *a1;
if ( !*a1 )
{
LABEL_26:
fputc(10, stderr);
free(v4);
return 0LL;
}
v6 = (__int64)v3;
v7 = 0;
v8 = 0;
while ( 2 )
{
switch ( v5 )
{
case '+':
++v4[v7];
goto LABEL_14;
case ',':
v4[v7] = getchar();
goto LABEL_14;
case '-':
--v4[v7];
goto LABEL_14;
case '.':
putchar(v4[v7]);
goto LABEL_14;
case '<':
if ( --v7 != -1 )
goto LABEL_14;
v6 = *(_QWORD *)(v6 + 30008);
if ( !v6 )
{
fwrite("Program attempted to shift left of 0\n", 1uLL, 0x25uLL, stderr);
free_memory_blocks(v3);
return 1LL;
}
v4 = (unsigned __int8 *)v6;
v7 = 29999;
goto LABEL_14;
case '>':
if ( ++v7 != 30000 )
goto LABEL_14;
v9 = *(unsigned __int8 **)(v6 + 30000);
if ( !v9 )
{
v9 = (unsigned __int8 *)new_memory_block(v6, 0LL);
if ( !v9 )
{
free_memory_blocks(v3);
return 1LL;
}
}
v4 = v9;
v6 = (__int64)v9;
v7 = 0;
goto LABEL_14;
case '[':
if ( v4[v7] )
goto LABEL_14;
v11 = find_loop_by_start(a2, v8);
if ( !v11 )
return 2LL;
v8 = *(_DWORD *)(v11 + 4);
goto LABEL_14;
case ']':
if ( !v4[v7] )
goto LABEL_14;
v12 = (int *)find_loop_by_end(a2, v8);
if ( v12 )
{
v8 = *v12;
LABEL_14:
v5 = a1[++v8];
if ( !v5 )
goto LABEL_26;
continue;
}
return 3LL;
default:
free(v4);
return 4LL;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func15(char *a1, __int64 *a2)
{
_QWORD *v2; // rax
void *v3; // r14
unsigned __int8 *v4; // r13
char v5; // al
__int64 v6; // r15
int v7; // ebp
int v8; // ebx
unsigned __int8 *v9; // rax
__int64 v11; // rax
int *v12; // rax

v2 = new_memory_block(0LL, 0LL);
if ( !v2 )
return 1LL;
v3 = v2;
v4 = (unsigned __int8 *)v2;
v5 = *a1;
if ( !*a1 )
{
LABEL_26:
fputc(10, stderr);
free(v4);
return 0LL;
}
v6 = (__int64)v3;
v7 = 0;
v8 = 0;
while ( 2 )
{
switch ( v5 )
{
case '+':
++v4[v7];
goto LABEL_14;
case ',':
v4[v7] = getchar();
goto LABEL_14;
case '-':
--v4[v7];
goto LABEL_14;
case '.':
putchar(v4[v7]);
goto LABEL_14;
case '<':
if ( --v7 != -1 )
goto LABEL_14;
v6 = *(_QWORD *)(v6 + 30008);
if ( !v6 )
{
fwrite("Program attempted to shift left of 0\n", 1uLL, 0x25uLL, stderr);
func10(v3);
return 1LL;
}
v4 = (unsigned __int8 *)v6;
v7 = 29999;
goto LABEL_14;
case '>':
if ( ++v7 != 30000 )
goto LABEL_14;
v9 = *(unsigned __int8 **)(v6 + 30000);
if ( !v9 )
{
v9 = (unsigned __int8 *)new_memory_block(v6, 0LL);
if ( !v9 )
{
func10(v3);
return 1LL;
}
}
v4 = v9;
v6 = (__int64)v9;
v7 = 0;
goto LABEL_14;
case '[':
if ( v4[v7] )
goto LABEL_14;
v11 = func8(a2, v8);
if ( !v11 )
return 2LL;
v8 = *(_DWORD *)(v11 + 4);
goto LABEL_14;
case ']':
if ( !v4[v7] )
goto LABEL_14;
v12 = (int *)func9(a2, v8);
if ( v12 )
{
v8 = *v12;
LABEL_14:
v5 = a1[++v8];
if ( !v5 )
goto LABEL_26;
continue;
}
return 3LL;
default:
free(v4);
return 4LL;
}
}
}

original_code:
static int simplebf(const unsigned char *code, struct loops *loops)
{
 struct memory_block *first_block, *current_block;
 unsigned char *mem;
 struct loop *l;
 int pc, mc;
 if ((first_block = new_memory_block(((void *)0), ((void *)0))) == ((void *)0))
  return 1;
 current_block = first_block;
 mem = current_block->m;
 for (pc = 0, mc = 0; code[pc] != '\0'; pc++) {
  switch(code[pc]) {
  case '>':
   mc++;
   if (mc == 30000) {
    if (current_block->next) {
     current_block = current_block->next;
    } else {
     current_block = new_memory_block(current_block, ((void *)0));
     if (current_block == ((void *)0)) {
      free_memory_blocks(first_block);
      return 1;
     }
    }
    mc = 0;
    mem = current_block->m;
   }
   break;
  case '<':
   mc--;
   if (mc == -1) {
    current_block = current_block->previous;
    if (current_block == ((void *)0)) {
     fprintf(stderr, "Program attempted to shift left of 0\n");
     free_memory_blocks(first_block);
     return 1;
    }
    mc = 30000 - 1;
    mem = current_block->m;
   }
   break;
  case '+':
   mem[mc] = mem[mc] + 1;
   break;
  case '-':
   mem[mc] = mem[mc] - 1;
   break;
  case '.':
   putchar(mem[mc]);
   break;
  case ',':
   mem[mc] = getchar();
   break;
  case '[':
   if (mem[mc] == 0) {
    if ((l = find_loop_by_start(loops, pc))
        == ((void *)0))
     return 2;
    pc = l->end;
   }
   break;
  case ']':
   if (mem[mc] != 0) {
    if ((l = find_loop_by_end(loops, pc))
        == ((void *)0))
     return 3;
    pc = l->start;
   }
   break;
  default:
   free(mem);
   return 4;
  }
 }
 fprintf(stderr, "\n");
 free(mem);
 return 0;
}

canonical_original_code:
static int simplebf(unsigned char *code, struct loops *loops)
{
 struct memory_block *first_block; struct memory_block *current_block;
 unsigned char *mem;
 struct loop *l;
 int pc; int mc;
 if ((first_block = new_memory_block(((void *)0), ((void *)0))) == ((void *)0))
  return 1;
 current_block = first_block;
 mem = current_block->m;
 for (pc = 0, mc = 0; code[pc] != '\0'; pc++) {
  switch(code[pc]) {
  case '>':
   mc++;
   if (mc == 30000) {
    if (current_block->next) {
     current_block = current_block->next;
    } else {
     current_block = new_memory_block(current_block, ((void *)0));
     if (current_block == ((void *)0)) {
      free_memory_blocks(first_block);
      return 1;
     }
    }
    mc = 0;
    mem = current_block->m;
   }
   break;
  case '<':
   mc--;
   if (mc == -1) {
    current_block = current_block->previous;
    if (current_block == ((void *)0)) {
     fprintf(stderr, "Program attempted to shift left of 0\n");
     free_memory_blocks(first_block);
     return 1;
    }
    mc = 30000 - 1;
    mem = current_block->m;
   }
   break;
  case '+':
   mem[mc] = mem[mc] + 1;
   break;
  case '-':
   mem[mc] = mem[mc] - 1;
   break;
  case '.':
   putchar(mem[mc]);
   break;
  case ',':
   mem[mc] = getchar();
   break;
  case '[':
   if (mem[mc] == 0) {
    if ((l = find_loop_by_start(loops, pc))
        == ((void *)0))
     return 2;
    pc = l->end;
   }
   break;
  case ']':
   if (mem[mc] != 0) {
    if ((l = find_loop_by_end(loops, pc))
        == ((void *)0))
     return 3;
    pc = l->start;
   }
   break;
  default:
   free(mem);
   return 4;
  }
 }
 fprintf(stderr, "\n");
 free(mem);
 return 0;
}

variable_types:
code
unsigned char *

variable_types:
mem
unsigned char *

variable_types: pc int

variable_types: mc int

user_defined_types: struct memory_block { unsigned char m[30000]; struct memory_block *next; struct memory_block *previous; }


usage

decompiled_code:
int usage()
{
putchar(10);
puts("Usage: simplebf programfile");
return putchar(10);
}

canonical_decompiled_code:
int func16()
{
putchar(10);
puts("Usage: simplebf programfile");
return putchar(10);
}

original_code:
void usage(void)
{
 printf("\n");
 printf("Usage: simplebf programfile\n");
 printf("\n");
}

canonical_original_code:
void usage()
{
 printf("\n");
 printf("Usage: simplebf programfile\n");
 printf("\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v5; // rax
char *v6; // rbp
__int64 *v7; // rax
__int64 *v8; // r12
unsigned int v9; // eax

if ( argc == 2 )
{
v5 = (char *)fill_program_array(argv[1]);
v6 = v5;
if ( v5 )
{
v7 = register_loops(v5);
v8 = v7;
if ( v7 )
{
v9 = simplebf(v6, v7);
v3 = v9;
if ( v9 )
{
fprintf(stderr, "Error %d\n", v9);
v3 = 1;
}
else
{
free(v6);
free_loops(v8);
}
}
else
{
fwrite("Error in loops\n", 1uLL, 0xFuLL, stderr);
v3 = 1;
}
}
else
{
printf("Error reading %s\n", argv[1]);
v3 = 1;
}
}
else
{
usage();
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v5; // rax
char *v6; // rbp
__int64 *v7; // rax
__int64 *v8; // r12
unsigned int v9; // eax

if ( argc == 2 )
{
v5 = (char *)func14(argv[1]);
v6 = v5;
if ( v5 )
{
v7 = register_loops(v5);
v8 = v7;
if ( v7 )
{
v9 = func15(v6, v7);
v3 = v9;
if ( v9 )
{
fprintf(stderr, "Error %d\n", v9);
v3 = 1;
}
else
{
free(v6);
func11(v8);
}
}
else
{
fwrite("Error in loops\n", 1uLL, 0xFuLL, stderr);
v3 = 1;
}
}
else
{
printf("Error reading %s\n", argv[1]);
v3 = 1;
}
}
else
{
func16();
v3 = 1;
}
return v3;
}

original_code:
int main(int argc, char **argv)
{
 struct loops *loops;
 unsigned char *code;
 int e;
 if (argc != 2) {
  usage();
  return 1;
 }
 if ((code = fill_program_array(argv[1])) == ((void *)0)) {
  printf("Error reading %s\n", argv[1]);
  return 1;
 }
 if ((loops = register_loops(code)) == ((void *)0)) {
  fprintf(stderr, "Error in loops\n");
  return 1;
 }
 e = simplebf(code, loops);
 if (e) {
  fprintf(stderr, "Error %d\n", e);
  return 1;
 }
 free(code);
 free_loops(loops);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: e int


KeyItem

repo: pconrad/giffer

decompiled_code:
__int64 __fastcall KeyItem(unsigned int a1)
{
return ((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 12)) & 0x1FFF;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return ((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 12)) & 0x1FFF;
}

original_code:
static int KeyItem(uint32_t Item)
{
    return ((Item >> 12) ^ Item) & 0x1FFF;
}

canonical_original_code:
static int KeyItem(unsigned int Item)
{
    return ((Item >> 12) ^ Item) & 0x1FFF;
}

variable_types:
Item
unsigned int