readArguments

decompiled_code:
__int64 __fastcall readArguments(int a1, __int64 a2)
{
int i; // ebx
__int64 v3; // rdx
_BYTE *v4; // rax
const char *v5; // rdx
int v6; // eax
int v7; // eax
__int64 result; // rax

if ( a1 > 1 )
{
for ( i = 1; i < a1; ++i )
{
v3 = 8LL * i;
v4 = *(_BYTE **)(a2 + v3);
if ( *v4 == 45 )
{
switch ( v4[1] )
{
case 'c':
++i;
*((_DWORD *)&gConfig + 9) = atoi(*(const char **)(a2 + v3 + 8));
break;
case 'f':
++i;
*(&gConfig + 2) = *(_QWORD *)(a2 + v3 + 8);
break;
case 'i':
++i;
gConfig = *(_QWORD *)(a2 + v3 + 8);
break;
case 'l':
++i;
*((_DWORD *)&gConfig + 15) = atoi(*(const char **)(a2 + v3 + 8));
break;
case 'n':
++i;
*((_DWORD *)&gConfig + 11) = atoi(*(const char **)(a2 + v3 + 8));
break;
case 'o':
++i;
*(&gConfig + 1) = *(_QWORD *)(a2 + v3 + 8);
break;
case 'p':
++i;
*((_DWORD *)&gConfig + 14) = atoi(*(const char **)(a2 + v3 + 8));
break;
case 'r':
++i;
*((_DWORD *)&gConfig + 8) = atoi(*(const char **)(a2 + v3 + 8));
break;
case 's':
++i;
*(&gConfig + 6) = atol(*(const char **)(a2 + v3 + 8));
break;
case 't':
++i;
*(&gConfig + 3) = *(_QWORD *)(a2 + v3 + 8);
break;
case 'w':
++i;
*((_DWORD *)&gConfig + 10) = atoi(*(const char **)(a2 + v3 + 8));
break;
default:
continue;
}
}
}
}
if ( gConfig )
{
v5 = (const char *)*(&gConfig + 1);
if ( v5 )
{
v6 = *((_DWORD *)&gConfig + 9);
if ( v6 != 2 )
v6 = 1;
*((_DWORD *)&gConfig + 9) = v6;
v7 = *((_DWORD *)&gConfig + 8);
if ( v7 != 48000 )
v7 = 44100;
*((_DWORD *)&gConfig + 8) = v7;
*(float *)&peakCoEfficient = (float)*((int *)&gConfig + 14) / (float)v7;
debug(6, "output path: %s", v5);
debug(6, "input file: %s", (const char *)gConfig);
debug(6, "base file name: %s", (const char *)*(&gConfig + 2));
debug(6, "file offset: %d", *(&gConfig + 6));
debug(6, "sample rate: %d", *((unsigned int *)&gConfig + 8));
debug(6, "peaks per second: %d", *((unsigned int *)&gConfig + 14));
debug(6, "channels: %d", *((unsigned int *)&gConfig + 9));
debug(6, "wait time: %d", *((unsigned int *)&gConfig + 10));
debug(6, "start time: %s", (const char *)*(&gConfig + 3));
debug(6, "seconds per file: %d", *((unsigned int *)&gConfig + 15));
result = 0LL;
}
else
{
debug(1, "You must pass an output file. Use -o <output file>");
result = 1LL;
}
}
else
{
debug(1, "You must pass an input file. Use -i <input file>");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, __int64 a2)
{
int i; // ebx
__int64 v3; // rdx
_BYTE *v4; // rax
const char *v5; // rdx
int v6; // eax
int v7; // eax
__int64 result; // rax

if ( a1 > 1 )
{
for ( i = 1; i < a1; ++i )
{
v3 = 8LL * i;
v4 = *(_BYTE **)(a2 + v3);
if ( *v4 == 45 )
{
switch ( v4[1] )
{
case 'c':
++i;
*((_DWORD *)&gConfig + 9) = atoi(*(const char **)(a2 + v3 + 8));
break;
case 'f':
++i;
*(&gConfig + 2) = *(_QWORD *)(a2 + v3 + 8);
break;
case 'i':
++i;
gConfig = *(_QWORD *)(a2 + v3 + 8);
break;
case 'l':
++i;
*((_DWORD *)&gConfig + 15) = atoi(*(const char **)(a2 + v3 + 8));
break;
case 'n':
++i;
*((_DWORD *)&gConfig + 11) = atoi(*(const char **)(a2 + v3 + 8));
break;
case 'o':
++i;
*(&gConfig + 1) = *(_QWORD *)(a2 + v3 + 8);
break;
case 'p':
++i;
*((_DWORD *)&gConfig + 14) = atoi(*(const char **)(a2 + v3 + 8));
break;
case 'r':
++i;
*((_DWORD *)&gConfig + 8) = atoi(*(const char **)(a2 + v3 + 8));
break;
case 's':
++i;
*(&gConfig + 6) = atol(*(const char **)(a2 + v3 + 8));
break;
case 't':
++i;
*(&gConfig + 3) = *(_QWORD *)(a2 + v3 + 8);
break;
case 'w':
++i;
*((_DWORD *)&gConfig + 10) = atoi(*(const char **)(a2 + v3 + 8));
break;
default:
continue;
}
}
}
}
if ( gConfig )
{
v5 = (const char *)*(&gConfig + 1);
if ( v5 )
{
v6 = *((_DWORD *)&gConfig + 9);
if ( v6 != 2 )
v6 = 1;
*((_DWORD *)&gConfig + 9) = v6;
v7 = *((_DWORD *)&gConfig + 8);
if ( v7 != 48000 )
v7 = 44100;
*((_DWORD *)&gConfig + 8) = v7;
*(float *)&peakCoEfficient = (float)*((int *)&gConfig + 14) / (float)v7;
func3(6, "output path: %s", v5);
func3(6, "input file: %s", (const char *)gConfig);
func3(6, "base file name: %s", (const char *)*(&gConfig + 2));
func3(6, "file offset: %d", *(&gConfig + 6));
func3(6, "sample rate: %d", *((unsigned int *)&gConfig + 8));
func3(6, "peaks per second: %d", *((unsigned int *)&gConfig + 14));
func3(6, "channels: %d", *((unsigned int *)&gConfig + 9));
func3(6, "wait time: %d", *((unsigned int *)&gConfig + 10));
func3(6, "start time: %s", (const char *)*(&gConfig + 3));
func3(6, "seconds per file: %d", *((unsigned int *)&gConfig + 15));
result = 0LL;
}
else
{
func3(1, "You must pass an output file. Use -o <output file>");
result = 1LL;
}
}
else
{
func3(1, "You must pass an input file. Use -i <input file>");
result = 1LL;
}
return result;
}

original_code:
static int readArguments(int argc, char** argv)
{
 int opts;
 for (opts = 1; opts < argc; opts++) {
  if (argv[opts][0] == '-') {
   switch (argv[opts][1]) {
   case 'i':
    gConfig.inputFile = argv[++opts];
    break;
   case 'o':
    gConfig.outputPath = argv[++opts];
    break;
   case 'f':
    gConfig.baseFileName = argv[++opts];
    break;
   case 'r':
    gConfig.sampleRate = atoi(argv[++opts]);
    break;
   case 'p':
    gConfig.peaksPerSecond = atoi(argv[++opts]);
    break;
   case 's':
    gConfig.fileStartOffset = atol(argv[++opts]);
    break;
   case 'c':
    gConfig.channels = atoi(argv[++opts]);
    break;
   case 'w':
    gConfig.waitTime = atoi(argv[++opts]);
    break;
   case 'n':
    gConfig.timesToCheck = atoi(argv[++opts]);
    break;
   case 't':
    gConfig.startTime = argv[++opts];
    break;
   case 'l':
    gConfig.secondsPerFile = atoi(argv[++opts]);
    break;
   }
  }
 }
 if (gConfig.inputFile == ((void *)0))
 {
  debug(1, "You must pass an input file. Use -i <input file>");
  return 1;
 }
 if (gConfig.outputPath == ((void *)0))
 {
  debug(1, "You must pass an output file. Use -o <output file>");
  return 1;
 }
 switch (gConfig.channels)
 {
  case 2:
   gConfig.channels = 2;
   break;
  default:
   gConfig.channels = 1;
   break;
 }
 switch (gConfig.sampleRate)
 {
  case 48000:
   gConfig.sampleRate = 48000;
   break;
  default:
   gConfig.sampleRate = 44100;
   break;
 }
 peakCoEfficient = (float) gConfig.peaksPerSecond / (float) gConfig.sampleRate;
 debug(6, "output path: %s", gConfig.outputPath);
 debug(6, "input file: %s", gConfig.inputFile);
 debug(6, "base file name: %s", gConfig.baseFileName);
 debug(6, "file offset: %d", gConfig.fileStartOffset);
 debug(6, "sample rate: %d", gConfig.sampleRate);
 debug(6, "peaks per second: %d", gConfig.peaksPerSecond);
 debug(6, "channels: %d", gConfig.channels);
 debug(6, "wait time: %d", gConfig.waitTime);
 debug(6, "start time: %s", gConfig.startTime);
 debug(6, "seconds per file: %d", gConfig.secondsPerFile);
 return 0;
}

canonical_original_code:
static int readArguments(int argc, char **argv)
{
 int opts;
 for (opts = 1; opts < argc; opts++) {
  if (argv[opts][0] == '-') {
   switch (argv[opts][1]) {
   case 'i':
    gConfig.inputFile = argv[++opts];
    break;
   case 'o':
    gConfig.outputPath = argv[++opts];
    break;
   case 'f':
    gConfig.baseFileName = argv[++opts];
    break;
   case 'r':
    gConfig.sampleRate = atoi(argv[++opts]);
    break;
   case 'p':
    gConfig.peaksPerSecond = atoi(argv[++opts]);
    break;
   case 's':
    gConfig.fileStartOffset = atol(argv[++opts]);
    break;
   case 'c':
    gConfig.channels = atoi(argv[++opts]);
    break;
   case 'w':
    gConfig.waitTime = atoi(argv[++opts]);
    break;
   case 'n':
    gConfig.timesToCheck = atoi(argv[++opts]);
    break;
   case 't':
    gConfig.startTime = argv[++opts];
    break;
   case 'l':
    gConfig.secondsPerFile = atoi(argv[++opts]);
    break;
   }
  }
 }
 if (gConfig.inputFile == ((void *)0))
 {
  debug(1, "You must pass an input file. Use -i <input file>");
  return 1;
 }
 if (gConfig.outputPath == ((void *)0))
 {
  debug(1, "You must pass an output file. Use -o <output file>");
  return 1;
 }
 switch (gConfig.channels)
 {
  case 2:
   gConfig.channels = 2;
   break;
  default:
   gConfig.channels = 1;
   break;
 }
 switch (gConfig.sampleRate)
 {
  case 48000:
   gConfig.sampleRate = 48000;
   break;
  default:
   gConfig.sampleRate = 44100;
   break;
 }
 peakCoEfficient = (float) gConfig.peaksPerSecond / (float) gConfig.sampleRate;
 debug(6, "output path: %s", gConfig.outputPath);
 debug(6, "input file: %s", gConfig.inputFile);
 debug(6, "base file name: %s", gConfig.baseFileName);
 debug(6, "file offset: %d", gConfig.fileStartOffset);
 debug(6, "sample rate: %d", gConfig.sampleRate);
 debug(6, "peaks per second: %d", gConfig.peaksPerSecond);
 debug(6, "channels: %d", gConfig.channels);
 debug(6, "wait time: %d", gConfig.waitTime);
 debug(6, "start time: %s", gConfig.startTime);
 debug(6, "seconds per file: %d", gConfig.secondsPerFile);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opts int


main

canonical_name: main

repo: matthewshafer/crossing

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char v4; // al
__int64 v6[7]; // [rsp+0h] [rbp-38h] BYREF

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "u:p:f:m:");
if ( v4 == -1 )
break;
if ( v4 == 112 )
{
v6[1] = (__int64)optarg;
v3 += 100;
}
else if ( v4 > 112 )
{
if ( v4 == 117 )
{
v6[0] = (__int64)optarg;
v3 += 1000;
}
}
else if ( v4 == 102 )
{
v6[2] = (__int64)optarg;
v3 += 10;
}
else if ( v4 == 109 )
{
v6[3] = (__int64)optarg;
++v3;
}
}
if ( v3 == 1111 )
crossing_send_notification(v6);
else
puts("not enough args");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 crossing_data userdata;
 char c;
 int flags = 0;
 while((c = getopt(argc, argv, "u:p:f:m:")) != -1)
 {
  switch(c)
  {
   case 'u':
    userdata.username = optarg;
    flags += 1000;
    break;
   case 'p':
    userdata.password = optarg;
    flags += 100;
    break;
   case 'f':
    userdata.from = optarg;
    flags += 10;
    break;
   case 'm':
    userdata.message = optarg;
    flags += 1;
    break;
  }
 }
 if(flags == 1111)
 {
  crossing_send_notification(&userdata);
 }
 else
 {
  printf("not enough args\n");
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct crossing_data userdata;
 char c;
 int flags = 0;
 while((c = getopt(argc, argv, "u:p:f:m:")) != -1)
 {
  switch(c)
  {
   case 'u':
    userdata.username = optarg;
    flags += 1000;
    break;
   case 'p':
    userdata.password = optarg;
    flags += 100;
    break;
   case 'f':
    userdata.from = optarg;
    flags += 10;
    break;
   case 'm':
    userdata.message = optarg;
    flags += 1;
    break;
  }
 }
 if(flags == 1111)
 {
  crossing_send_notification(&userdata);
 }
 else
 {
  printf("not enough args\n");
 }
 return 0;
}

variable_types:
argv
char *[]

variable_types: struct crossing_data { char *username; char *password; char *from; char *message; }

variable_types: c char

variable_types: flags int

return_type: int


repo: matthiaskramm/cagekeeper

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

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

original_code:
static int add2(void*context, int x, int y)
{
    return x+y;
}

canonical_original_code:
static int add2(void *context, int x, int y)
{
    return x+y;
}

variable_types:
context
void *

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall add3(__int64 a1, int a2, int a3, int a4)
{
return (unsigned int)(a3 + a2 + a4);
}

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

original_code:
static int add3(void*context, int x, int y, int z)
{
    return x+y+z;
}

canonical_original_code:
static int add3(void *context, int x, int y, int z)
{
    return x+y+z;
}

variable_types: z int


decompiled_code:
float __fastcall fadd2(float a1, float a2)
{
return a1 + a2;
}

canonical_decompiled_code:
float __fastcall func2(float a1, float a2)
{
return a1 + a2;
}

original_code:
static float fadd2(void*context, float x, float y)
{
    return x+y;
}

canonical_original_code:
static float fadd2(void *context, float x, float y)
{
    return x+y;
}

variable_types: x float

variable_types: y float

return_type: float


decompiled_code:
float __fastcall fadd3(float a1, float a2, float a3)
{
return (float)(a1 + a2) + a3;
}

canonical_decompiled_code:
float __fastcall func3(float a1, float a2, float a3)
{
return (float)(a1 + a2) + a3;
}

original_code:
static float fadd3(void*context, float x, float y, float z)
{
    return x+y+z;
}

canonical_original_code:
static float fadd3(void *context, float x, float y, float z)
{
    return x+y+z;
}

variable_types: z float


negate

decompiled_code:
__int64 __fastcall negate(__int64 a1, int a2)
{
return a2 ^ 1u;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
return a2 ^ 1u;
}

original_code:
static _Bool negate(void*context, _Bool b)
{
    return !b;
}

canonical_original_code:
static _Bool negate(void *context, _Bool b)
{
    return !b;
}


decompiled_code:
__int64 __fastcall get_array(__int64 a1, int a2, int a3)
{
__int64 v4; // r14
int v5; // er12
__int64 v6; // rbp
unsigned int v7; // ebx

v4 = array_new();
if ( a2 > 0 )
{
v5 = a3;
do
{
v6 = array_new();
if ( a3 > 0 )
{
v7 = v5 - a3;
do
array_append_int32(v6, v7++);
while ( v7 != v5 );
}
array_append(v4, v6);
v5 += 10;
}
while ( v5 != a3 + 10 * a2 );
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, int a3)
{
__int64 v4; // r14
int v5; // er12
__int64 v6; // rbp
unsigned int v7; // ebx

v4 = array_new();
if ( a2 > 0 )
{
v5 = a3;
do
{
v6 = array_new();
if ( a3 > 0 )
{
v7 = v5 - a3;
do
array_append_int32(v6, v7++);
while ( v7 != v5 );
}
array_append(v4, v6);
v5 += 10;
}
while ( v5 != a3 + 10 * a2 );
}
return v4;
}

original_code:
static value_t* get_array(void*context, int width, int height)
{
    value_t*columns = array_new();
    int x;
    for(x=0;x<width;x++) {
        int y;
        value_t*column = array_new();
        for(y=0;y<height;y++) {
            array_append_int32(column, x*10+y);
        }
        array_append(columns, column);
    }
    return columns;
}

canonical_original_code:
static struct _value *get_array(void *context, int width, int height)
{
    struct _value *columns = array_new();
    int x;
    for(x=0;x<width;x++) {
        int y;
        struct _value *column = array_new();
        for(y=0;y<height;y++) {
            array_append_int32(column, x*10+y);
        }
        array_append(columns, column);
    }
    return columns;
}

variable_types: width int

variable_types: height int

variable_types: struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *

user_defined_types: struct _value { enum _type type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); }


original_code:
static value_t* concat_arrays(void*context, value_t*array1, value_t*array2)
{
    int i;
    value_t*a = array_new();
    for(i=0;i<array1->length;i++) {
        array_append(a, value_clone(array1->data[i]));
    }
    for(i=0;i<array2->length;i++) {
        array_append(a, value_clone(array2->data[i]));
    }
    return a;
}

canonical_original_code:
static struct _value *concat_arrays(void *context, struct _value *array1, struct _value *array2)
{
    int i;
    struct _value *a = array_new();
    for(i=0;i<array1->length;i++) {
        array_append(a, value_clone(array1->data[i]));
    }
    for(i=0;i<array2->length;i++) {
        array_append(a, value_clone(array2->data[i]));
    }
    return a;
}

variable_types: i int

return_type: struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *


decompiled_code:
char *__fastcall concat_strings(__int64 a1, const char *a2, const char *a3)
{
int v4; // ebx
int v5; // er12
char *v6; // rbp

v4 = strlen(a2);
v5 = strlen(a3);
v6 = (char *)malloc(v5 + v4 + 1);
memcpy(v6, a2, v4);
memcpy(&v6[v4], a3, v5);
v6[v5 + v4] = 0;
return v6;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1, const char *a2, const char *a3)
{
int v4; // ebx
int v5; // er12
char *v6; // rbp

v4 = strlen(a2);
v5 = strlen(a3);
v6 = (char *)malloc(v5 + v4 + 1);
memcpy(v6, a2, v4);
memcpy(&v6[v4], a3, v5);
v6[v5 + v4] = 0;
return v6;
}

original_code:
static char* concat_strings(void*context, char*s1, char*s2)
{
    int l1 = strlen(s1);
    int l2 = strlen(s2);
    char*tmp = malloc(l1+l2+1);
    memcpy(tmp, s1, l1);
    memcpy(tmp+l1, s2, l2);
    tmp[l1+l2] = 0;
    return tmp;
}

canonical_original_code:
static char *concat_strings(void *context, char *s1, char *s2)
{
    int l1 = strlen(s1);
    int l2 = strlen(s2);
    char *tmp = malloc(l1+l2+1);
    memcpy(tmp, s1, l1);
    memcpy(tmp+l1, s2, l2);
    tmp[l1+l2] = 0;
    return tmp;
}

variable_types:
tmp
char *

return_type: char *


trace

decompiled_code:
int __fastcall trace(__int64 a1, const char *a2)
{
return puts(a2);
}

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

original_code:
static void trace(void*context, char*s)
{
    printf("%s\n", s);
}

canonical_original_code:
static void trace(void *context, char *s)
{
    printf("%s\n", s);
}

variable_types:
s
char *

return_type: void


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r11
const char **v4; // rax
int v5; // ecx
char v6; // r9
const char *v7; // rdx
const char *v8; // rbp
__int64 v9; // rbx
void (__fastcall *v10)(__int64, const char *, __int64); // r12
__int64 v11; // rax
void (__fastcall *v12)(__int64, const char *, __int64); // r12
__int64 v13; // rax
void (__fastcall *v14)(__int64, const char *, __int64); // r12
__int64 v15; // rax
void (__fastcall *v16)(__int64, const char *, __int64); // r12
__int64 v17; // rax
void (__fastcall *v18)(__int64, const char *, __int64); // r12
__int64 v19; // rax
__int64 v20; // rsi
__int64 v21; // rbp
int result; // eax
__int64 v23; // r12
__int64 v24; // r12
__int64 v25; // r12
__int64 v26; // r12
__int64 v27; // r12
__int64 v28; // r12
__int64 v29; // rbp
__int64 v30; // rax
__int64 v31; // rsi
__int64 v32; // rax
__int64 v33; // r12
__int64 v34; // rax
__int64 v35; // rsi
__int64 v36; // rax
__int64 v37; // r12
__int64 v38; // rsi
__int64 v39; // rax

v3 = *argv;
if ( argc <= 1 )
goto LABEL_35;
v4 = argv + 1;
v5 = 0;
v6 = 1;
do
{
v7 = *v4;
if ( **v4 == 45 )
{
if ( v7[1] == 117 )
v6 = 0;
}
else
{
argv[v5++] = v7;
}
++v4;
}
while ( v4 != &argv[(unsigned int)(argc - 2) + 2] );
if ( v5 <= 0 )
{
LABEL_35:
printf("Usage:\n\t%s <program>\n", v3);
exit(1);
}
v8 = *argv;
if ( v6 )
v9 = interpreter_by_extension(*argv);
else
v9 = unsafe_interpreter_by_extension(*argv);
if ( v9 )
{
define_function(v9, "trace", trace, 0LL, "s", &LC1);
define_function(v9, "get_array", get_array, 0LL, "ii", "[");
define_function(v9, "add2", add2, 0LL, "ii", "i");
define_function(v9, "add3", add3, 0LL, "iii", "i");
define_function(v9, "fadd2", fadd2, 0LL, "ff", "f");
define_function(v9, "fadd3", fadd3, 0LL, "fff", "f");
define_function(v9, "concat_strings", concat_strings, 0LL, "ss", "s");
define_function(v9, "concat_arrays", concat_arrays, 0LL, "[[", "[");
define_function(v9, "negate", negate, 0LL, "b", "b");
v10 = *(void (__fastcall **)(__int64, const char *, __int64))(v9 + 32);
v11 = value_new_int32(3LL);
v10(v9, "global_int", v11);
v12 = *(void (__fastcall **)(__int64, const char *, __int64))(v9 + 32);
v13 = value_new_array();
v12(v9, "global_array", v13);
v14 = *(void (__fastcall **)(__int64, const char *, __int64))(v9 + 32);
v15 = value_new_boolean(1LL);
v14(v9, "global_boolean", v15);
v16 = *(void (__fastcall **)(__int64, const char *, __int64))(v9 + 32);
v17 = value_new_float32(3.0);
v16(v9, "global_float", v17);
v18 = *(void (__fastcall **)(__int64, const char *, __int64))(v9 + 32);
v19 = value_new_string("foobar");
v18(v9, "global_string", v19);
v20 = read_file(v8);
if ( v20 )
{
if ( (*(unsigned __int8 (__fastcall **)(__int64, __int64))(v9 + 48))(v9, v20) )
{
v21 = 0LL;
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v9 + 56))(v9, "call_noargs") )
{
v23 = value_new_array();
v21 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v9 + 64))(v9, "call_noargs", v23);
value_destroy(v23);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v9 + 56))(v9, "call_int") )
{
v24 = value_new_array();
array_append_int32(v24, 0LL);
v21 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v9 + 64))(v9, "call_int", v24);
value_destroy(v24);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v9 + 56))(v9, "call_float") )
{
v25 = value_new_array();
array_append_float32(v25, 0.0);
v21 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v9 + 64))(v9, "call_float", v25);
value_destroy(v25);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v9 + 56))(v9, "call_string") )
{
v26 = value_new_array();
array_append_string(v26, "foobar");
v21 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v9 + 64))(v9, "call_string", v26);
value_destroy(v26);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v9 + 56))(v9, "call_boolean") )
{
v27 = value_new_array();
array_append_boolean(v27, 0LL);
v21 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v9 + 64))(v9, "call_boolean", v27);
value_destroy(v27);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v9 + 56))(v9, "call_array") )
{
v28 = value_new_array();
v29 = value_new_array();
v30 = value_new_int32(1LL);
array_append(v29, v30);
v31 = value_new_int32(2LL);
array_append(v29, v31);
v32 = value_new_int32(3LL);
array_append(v29, v32);
array_append(v28, v29);
v21 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v9 + 64))(v9, "call_array", v28);
value_destroy(v28);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v9 + 56))(v9, "call_int_and_float_and_string") )
{
v33 = value_new_array();
v34 = value_new_int32(1LL);
array_append(v33, v34);
v35 = value_new_float32(2.0);
array_append(v33, v35);
v36 = value_new_string("foobar");
array_append(v33, v36);
v21 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v9 + 64))(
v9,
"call_int_and_float_and_string",
v33);
value_destroy(v33);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v9 + 56))(v9, "call_boolean_and_array") )
{
v37 = value_new_array();
v38 = value_new_boolean(1LL);
array_append(v37, v38);
v39 = value_new_array();
array_append(v37, v39);
v21 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v9 + 64))(v9, "call_boolean_and_array", v37);
value_destroy(v37);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v9 + 56))(v9, "test") )
v21 = (*(__int64 (__fastcall **)(__int64, const char *, void *))(v9 + 64))(v9, "test", &empty_array);
(*(void (__fastcall **)(__int64))(v9 + 72))(v9);
if ( v21 && *(_DWORD *)v21 == 4 )
{
fputs(*(const char **)(v21 + 16), stdout);
fputc(10, stdout);
result = strcmp(*(const char **)(v21 + 16), "ok") != 0;
}
else
{
value_dump(v21);
fputc(10, stdout);
result = 1;
}
}
else
{
fwrite("Error compiling script\n", 1uLL, 0x17uLL, stderr);
(*(void (__fastcall **)(__int64))(v9 + 72))(v9);
result = 1;
}
}
else
{
fprintf(stderr, "Error reading script %s\n", v8);
result = 1;
}
}
else
{
fprintf(stderr, "Couldn't initialize %sinterpreter for %s\n", (const char *)&LC1, v8);
result = 1;
}
return result;
}

original_code:
int main(int argn, char*argv[])
{
    char*program = argv[0];
    _Bool sandbox = 1;
    int i,j=0;
    for(i=1;i<argn;i++) {
        if(argv[i][0]=='-') {
            switch(argv[i][1]) {
                case 'u':
                    sandbox = 0;
                break;
            }
        } else {
            argv[j++] = argv[i];
        }
    }
    argn = j;
    if(argn < 1) {
        printf("Usage:\n\t%s <program>\n", program);
        exit(1);
    }
    char*filename = argv[0];
    language_t*l;
    if(sandbox) {
        l = interpreter_by_extension(filename);
    } else {
        l = unsafe_interpreter_by_extension(filename);
    }
    if(!l) {
        fprintf(stderr, "Couldn't initialize %sinterpreter for %s\n", l?"sandboxed":"", filename);
        return 1;
    }
    define_function(l, "trace", trace, ((void *)0), "s",""),
    define_function(l, "get_array", get_array, ((void *)0), "ii","["),
    define_function(l, "add2", add2, ((void *)0), "ii", "i"),
    define_function(l, "add3", add3, ((void *)0), "iii", "i"),
    define_function(l, "fadd2", fadd2, ((void *)0), "ff", "f"),
    define_function(l, "fadd3", fadd3, ((void *)0), "fff", "f"),
    define_function(l, "concat_strings", concat_strings, ((void *)0), "ss", "s"),
    define_function(l, "concat_arrays", concat_arrays, ((void *)0), "[[", "["),
    define_function(l, "negate", negate, ((void *)0), "b", "b"),
    l->define_constant(l, "global_int", value_new_int32(3));
    l->define_constant(l, "global_array", value_new_array());
    l->define_constant(l, "global_boolean", value_new_boolean(1));
    l->define_constant(l, "global_float", value_new_float32(3.0));
    l->define_constant(l, "global_string", value_new_string("foobar"));
    char* script = read_file(filename);
    if(!script) {
        fprintf(stderr, "Error reading script %s\n", filename);
        return 1;
    }
    _Bool compiled = l->compile_script(l, script);
    if(!compiled) {
        fprintf(stderr, "Error compiling script\n");
        l->destroy(l);
        return 1;
    }
    value_t*ret = ((void *)0);
    if(l->is_function(l, "call_noargs")) {
        value_t*args = value_new_array();
        ret = l->call_function(l, "call_noargs", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_int")) {
        value_t*args = value_new_array();
        array_append_int32(args, 0);
        ret = l->call_function(l, "call_int", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_float")) {
        value_t*args = value_new_array();
        array_append_float32(args, 0);
        ret = l->call_function(l, "call_float", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_string")) {
        value_t*args = value_new_array();
        array_append_string(args, "foobar");
        ret = l->call_function(l, "call_string", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_boolean")) {
        value_t*args = value_new_array();
        array_append_boolean(args, 0);
        ret = l->call_function(l, "call_boolean", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_array")) {
        value_t*args = value_new_array();
        value_t*a = value_new_array();
        array_append(a, value_new_int32(1));
        array_append(a, value_new_int32(2));
        array_append(a, value_new_int32(3));
        array_append(args, a);
        ret = l->call_function(l, "call_array", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_int_and_float_and_string")) {
        value_t*args = value_new_array();
        array_append(args, value_new_int32(1));
        array_append(args, value_new_float32(2));
        array_append(args, value_new_string("foobar"));
        ret = l->call_function(l, "call_int_and_float_and_string", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_boolean_and_array")) {
        value_t*args = value_new_array();
        array_append(args, value_new_boolean(1));
        array_append(args, value_new_array());
        ret = l->call_function(l, "call_boolean_and_array", args);
        value_destroy(args);
    }
    if(l->is_function(l, "test")) {
        ret = l->call_function(l, "test", (&empty_array));
    }
    l->destroy(l);
    if(ret && ret->type == TYPE_STRING) {
        fputs(ret->str, stdout);
        fputc('\n', stdout);
        if(!strcmp(ret->str, "ok"))
            return 0;
        else
            return 1;
    } else {
        value_dump(ret);
        fputc('\n', stdout);
        return 1;
    }
}

canonical_original_code:
int main(int argn, char *argv[])
{
    char *program = argv[0];
    _Bool sandbox = 1;
    int i; int j = 0;
    for(i=1;i<argn;i++) {
        if(argv[i][0]=='-') {
            switch(argv[i][1]) {
                case 'u':
                    sandbox = 0;
                break;
            }
        } else {
            argv[j++] = argv[i];
        }
    }
    argn = j;
    if(argn < 1) {
        printf("Usage:\n\t%s <program>\n", program);
        exit(1);
    }
    char *filename = argv[0];
    struct _language *l;
    if(sandbox) {
        l = interpreter_by_extension(filename);
    } else {
        l = unsafe_interpreter_by_extension(filename);
    }
    if(!l) {
        fprintf(stderr, "Couldn't initialize %sinterpreter for %s\n", l?"sandboxed":"", filename);
        return 1;
    }
    define_function(l, "trace", trace, ((void *)0), "s",""),
    define_function(l, "get_array", get_array, ((void *)0), "ii","["),
    define_function(l, "add2", add2, ((void *)0), "ii", "i"),
    define_function(l, "add3", add3, ((void *)0), "iii", "i"),
    define_function(l, "fadd2", fadd2, ((void *)0), "ff", "f"),
    define_function(l, "fadd3", fadd3, ((void *)0), "fff", "f"),
    define_function(l, "concat_strings", concat_strings, ((void *)0), "ss", "s"),
    define_function(l, "concat_arrays", concat_arrays, ((void *)0), "[[", "["),
    define_function(l, "negate", negate, ((void *)0), "b", "b"),
    l->define_constant(l, "global_int", value_new_int32(3));
    l->define_constant(l, "global_array", value_new_array());
    l->define_constant(l, "global_boolean", value_new_boolean(1));
    l->define_constant(l, "global_float", value_new_float32(3.0));
    l->define_constant(l, "global_string", value_new_string("foobar"));
    char *script = read_file(filename);
    if(!script) {
        fprintf(stderr, "Error reading script %s\n", filename);
        return 1;
    }
    _Bool compiled = l->compile_script(l, script);
    if(!compiled) {
        fprintf(stderr, "Error compiling script\n");
        l->destroy(l);
        return 1;
    }
    struct _value *ret = ((void *)0);
    if(l->is_function(l, "call_noargs")) {
        struct _value *args = value_new_array();
        ret = l->call_function(l, "call_noargs", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_int")) {
        struct _value *args = value_new_array();
        array_append_int32(args, 0);
        ret = l->call_function(l, "call_int", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_float")) {
        struct _value *args = value_new_array();
        array_append_float32(args, 0);
        ret = l->call_function(l, "call_float", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_string")) {
        struct _value *args = value_new_array();
        array_append_string(args, "foobar");
        ret = l->call_function(l, "call_string", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_boolean")) {
        struct _value *args = value_new_array();
        array_append_boolean(args, 0);
        ret = l->call_function(l, "call_boolean", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_array")) {
        struct _value *args = value_new_array();
        struct _value *a = value_new_array();
        array_append(a, value_new_int32(1));
        array_append(a, value_new_int32(2));
        array_append(a, value_new_int32(3));
        array_append(args, a);
        ret = l->call_function(l, "call_array", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_int_and_float_and_string")) {
        struct _value *args = value_new_array();
        array_append(args, value_new_int32(1));
        array_append(args, value_new_float32(2));
        array_append(args, value_new_string("foobar"));
        ret = l->call_function(l, "call_int_and_float_and_string", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_boolean_and_array")) {
        struct _value *args = value_new_array();
        array_append(args, value_new_boolean(1));
        array_append(args, value_new_array());
        ret = l->call_function(l, "call_boolean_and_array", args);
        value_destroy(args);
    }
    if(l->is_function(l, "test")) {
        ret = l->call_function(l, "test", (&empty_array));
    }
    l->destroy(l);
    if(ret && ret->type == TYPE_STRING) {
        fputs(ret->str, stdout);
        fputc('\n', stdout);
        if(!strcmp(ret->str, "ok"))
            return 0;
        else
            return 1;
    } else {
        value_dump(ret);
        fputc('\n', stdout);
        return 1;
    }
}

variable_types: argn int

variable_types:
argv
char *[]

variable_types:
program
char *

variable_types: j int

variable_types:
filename
char *

variable_types: struct _language { void *internal; char *name; _Bool timeout; _Bool (*initialize)(struct _language *li, unsigned long maxmem); void (*define_constant)(struct _language *li, char *name, struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *value); void (*define_function)(struct _language *li, char *name, struct _value *f); _Bool (*compile_script)(struct _language *li, char *script); _Bool (*is_function)(struct _language *li, char *name); struct _value *(*call_function)(struct _language *li, char *name, struct _value *args); void (*destroy)(struct _language *li); void *user; void (*log)(void *user, char *line); } *

variable_types:
script
char *

user_defined_types: struct _language { void *internal; char *name; _Bool timeout; _Bool (*initialize)(struct _language *li, unsigned long maxmem); void (*define_constant)(struct _language *li, char *name, struct _value *value); void (*define_function)(struct _language *li, char *name, struct _value *f); _Bool (*compile_script)(struct _language *li, char *script); _Bool (*is_function)(struct _language *li, char *name); struct _value *(*call_function)(struct _language *li, char *name, struct _value *args); void (*destroy)(struct _language *li); void *user; void (*log)(void *user, char *line); }


sigalarm

decompiled_code:
void __noreturn sigalarm()
{
longjmp(timeout_jmp, 1);
}

canonical_decompiled_code:
void __noreturn func0()
{
longjmp(timeout_jmp, 1);
}

original_code:
static void sigalarm(int signal)
{
    longjmp(timeout_jmp, 1);
}

variable_types: signal int


decompiled_code:
__int64 __fastcall raw_interpreter_by_extension(const char *a1)
{
const char *v1; // rbx
char *v2; // rax
bool v3; // cf
bool v4; // zf
__int64 v5; // rcx
const char *v6; // rdi
const char *v7; // rsi
char v8; // al
bool v9; // cf
bool v10; // zf
__int64 v11; // rcx
const char *v12; // rdi
const char *v13; // rsi
char v14; // al
bool v15; // cf
bool v16; // zf
__int64 v17; // rcx
const char *v18; // rdi
const char *v19; // rsi
__int64 result; // rax

v1 = a1;
v2 = strrchr(a1, 46);
v3 = 0;
v4 = v2 == 0LL;
if ( v2 )
v1 = v2 + 1;
v5 = 4LL;
v6 = (const char *)&LC0;
v7 = v1;
do
{
if ( !v5 )
break;
v3 = *v7 < (unsigned int)*v6;
v4 = *v7++ == *v6++;
--v5;
}
while ( v4 );
v8 = (!v3 && !v4) - v3;
v9 = 0;
v10 = v8 == 0;
if ( !v8 )
return lua_interpreter_new(v6, v7);
v11 = 3LL;
v12 = (const char *)&LC1;
v13 = v1;
do
{
if ( !v11 )
break;
v9 = *v13 < (unsigned int)*v12;
v10 = *v13++ == *v12++;
--v11;
}
while ( v10 );
v14 = (!v9 && !v10) - v9;
v15 = 0;
v16 = v14 == 0;
if ( !v14 )
return python_interpreter_new(v12, v13);
v17 = 3LL;
v18 = (const char *)&LC2;
v19 = v1;
do
{
if ( !v17 )
break;
v15 = *v19 < (unsigned int)*v18;
v16 = *v19++ == *v18++;
--v17;
}
while ( v16 );
if ( (!v15 && !v16) == v15 )
result = ruby_interpreter_new(v18, v19);
else
result = javascript_interpreter_new(v18, v19);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
const char *v1; // rbx
char *v2; // rax
bool v3; // cf
bool v4; // zf
__int64 v5; // rcx
const char *v6; // rdi
const char *v7; // rsi
char v8; // al
bool v9; // cf
bool v10; // zf
__int64 v11; // rcx
const char *v12; // rdi
const char *v13; // rsi
char v14; // al
bool v15; // cf
bool v16; // zf
__int64 v17; // rcx
const char *v18; // rdi
const char *v19; // rsi
__int64 result; // rax

v1 = a1;
v2 = strrchr(a1, 46);
v3 = 0;
v4 = v2 == 0LL;
if ( v2 )
v1 = v2 + 1;
v5 = 4LL;
v6 = (const char *)&LC0;
v7 = v1;
do
{
if ( !v5 )
break;
v3 = *v7 < (unsigned int)*v6;
v4 = *v7++ == *v6++;
--v5;
}
while ( v4 );
v8 = (!v3 && !v4) - v3;
v9 = 0;
v10 = v8 == 0;
if ( !v8 )
return lua_interpreter_new(v6, v7);
v11 = 3LL;
v12 = (const char *)&LC1;
v13 = v1;
do
{
if ( !v11 )
break;
v9 = *v13 < (unsigned int)*v12;
v10 = *v13++ == *v12++;
--v11;
}
while ( v10 );
v14 = (!v9 && !v10) - v9;
v15 = 0;
v16 = v14 == 0;
if ( !v14 )
return python_interpreter_new(v12, v13);
v17 = 3LL;
v18 = (const char *)&LC2;
v19 = v1;
do
{
if ( !v17 )
break;
v15 = *v19 < (unsigned int)*v18;
v16 = *v19++ == *v18++;
--v17;
}
while ( v16 );
if ( (!v15 && !v16) == v15 )
result = ruby_interpreter_new(v18, v19);
else
result = javascript_interpreter_new(v18, v19);
return result;
}

original_code:
static language_t* raw_interpreter_by_extension(const char*filename)
{
    const char*dot = strrchr(filename, '.');
    const char*extension = dot ? dot+1 : filename;
    language_t*core = ((void *)0);
    if(!strcmp(extension, "lua"))
        return lua_interpreter_new();
    else if(!strcmp(extension, "py"))
        return python_interpreter_new();
    else if(!strcmp(extension, "rb"))
        return ruby_interpreter_new();
    else
        return javascript_interpreter_new();
}

canonical_original_code:
static struct _language *raw_interpreter_by_extension(char *filename)
{
    char *dot = strrchr(filename, '.');
    char *extension = dot ? dot+1 : filename;
    struct _language *core = ((void *)0);
    if(!strcmp(extension, "lua"))
        return lua_interpreter_new();
    else if(!strcmp(extension, "py"))
        return python_interpreter_new();
    else if(!strcmp(extension, "rb"))
        return ruby_interpreter_new();
    else
        return javascript_interpreter_new();
}

variable_types:
dot
char *

variable_types:
extension
char *

return_type: struct _language { void *internal; char *name; _Bool timeout; _Bool (*initialize)(struct _language *li, unsigned long maxmem); void (*define_constant)(struct _language *li, char *name, struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *value); void (*define_function)(struct _language *li, char *name, struct _value *f); _Bool (*compile_script)(struct _language *li, char *script); _Bool (*is_function)(struct _language *li, char *name); struct _value *(*call_function)(struct _language *li, char *name, struct _value *args); void (*destroy)(struct _language *li); void *user; void (*log)(void *user, char *line); } *


decompiled_code:
__int64 __fastcall call_function_with_timeout(__int64 a1, const char *a2, __int64 a3, unsigned int a4, _BYTE *a5)
{
return with_timeout(a1, 0LL, a2, a3, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, __int64 a3, unsigned int a4, _BYTE *a5)
{
return func2(a1, 0LL, a2, a3, a4, a5);
}

original_code:
value_t* call_function_with_timeout(language_t*l, const char*function, value_t*args, int max_seconds, _Bool*timeout)
{
    return with_timeout(l, ((void *)0), function, args, max_seconds, timeout);
}

canonical_original_code:
struct _value *call_function_with_timeout(struct _language *l, char *function, struct _value *args, int max_seconds, _Bool *timeout)
{
    return with_timeout(l, ((void *)0), function, args, max_seconds, timeout);
}

variable_types: struct _language { void *internal; char *name; _Bool timeout; _Bool (*initialize)(struct _language *li, unsigned long maxmem); void (*define_constant)(struct _language *li, char *name, struct _value *value); void (*define_function)(struct _language *li, char *name, struct _value *f); _Bool (*compile_script)(struct _language *li, char *script); _Bool (*is_function)(struct _language *li, char *name); struct _value *(*call_function)(struct _language *li, char *name, struct _value *args); void (*destroy)(struct _language *li); void *user; void (*log)(void *user, char *line); } *

variable_types:
function
char *

variable_types:
args
struct _value *

variable_types:
timeout
_Bool *

user_defined_types: enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 }


decompiled_code:
__int64 __fastcall compile_and_run_function_with_timeout(__int64 a1, __int64 a2, const char *a3, __int64 a4, unsigned int a5, _BYTE *a6)
{
return with_timeout(a1, a2, a3, a4, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, const char *a3, __int64 a4, unsigned int a5, _BYTE *a6)
{
return func2(a1, a2, a3, a4, a5, a6);
}

original_code:
value_t* compile_and_run_function_with_timeout(language_t*l, const char*script, const char*function, value_t*args, int max_seconds, _Bool*timeout)
{
    return with_timeout(l, script, function, args, max_seconds, timeout);
}

canonical_original_code:
struct _value *compile_and_run_function_with_timeout(struct _language *l, char *script, char *function, struct _value *args, int max_seconds, _Bool *timeout)
{
    return with_timeout(l, script, function, args, max_seconds, timeout);
}


decompiled_code:
__int64 __fastcall wrap_sandbox(_QWORD *a1)
{
if ( !*a1 )
return proxy_new();
fwrite("Can't wrap sandbox, language already initialized\n", 1uLL, 0x31uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
if ( !*a1 )
return proxy_new();
fwrite("Can't wrap sandbox, language already initialized\n", 1uLL, 0x31uLL, stderr);
return 0LL;
}

original_code:
language_t* wrap_sandbox(language_t*language)
{
    if(language->internal) {
        fprintf(stderr, "Can't wrap sandbox, language already initialized\n");
        return ((void *)0);
    }
    return proxy_new(language);
}

canonical_original_code:
struct _language *wrap_sandbox(struct _language *language)
{
    if(language->internal) {
        fprintf(stderr, "Can't wrap sandbox, language already initialized\n");
        return ((void *)0);
    }
    return proxy_new(language);
}

variable_types:
language
struct _language *


decompiled_code:
__int64 __fastcall interpreter_by_extension(const char *a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)raw_interpreter_by_extension(a1);
return wrap_sandbox(v1);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)func1(a1);
return func5(v1);
}

original_code:
language_t* interpreter_by_extension(const char*filename)
{
    return wrap_sandbox(raw_interpreter_by_extension(filename));
}

canonical_original_code:
struct _language *interpreter_by_extension(char *filename)
{
    return wrap_sandbox(raw_interpreter_by_extension(filename));
}


decompiled_code:
__int64 __fastcall unsafe_interpreter_by_extension(const char *a1)
{
__int64 v1; // rbx

v1 = raw_interpreter_by_extension(a1);
if ( !(*(unsigned __int8 (__fastcall **)(__int64, _QWORD))(v1 + 24))(v1, config_maxmem) )
{
(*(void (__fastcall **)(__int64))(v1 + 72))(v1);
v1 = 0LL;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
__int64 v1; // rbx

v1 = func1(a1);
if ( !(*(unsigned __int8 (__fastcall **)(__int64, _QWORD))(v1 + 24))(v1, config_maxmem) )
{
(*(void (__fastcall **)(__int64))(v1 + 72))(v1);
v1 = 0LL;
}
return v1;
}

original_code:
language_t* unsafe_interpreter_by_extension(const char*filename)
{
    language_t*li = raw_interpreter_by_extension(filename);
    _Bool ret = li->initialize(li, config_maxmem);
    if(!ret) {
        li->destroy(li);
        return ((void *)0);
    }
    return li;
}

canonical_original_code:
struct _language *unsafe_interpreter_by_extension(char *filename)
{
    struct _language *li = raw_interpreter_by_extension(filename);
    _Bool ret = li->initialize(li, config_maxmem);
    if(!ret) {
        li->destroy(li);
        return ((void *)0);
    }
    return li;
}


decompiled_code:
__int64 __fastcall define_int_constant(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rbx

v3 = value_new_int32(a3);
(*(void (__fastcall **)(__int64, __int64, __int64))(a1 + 32))(a1, a2, v3);
return value_destroy(v3);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rbx

v3 = value_new_int32(a3);
(*(void (__fastcall **)(__int64, __int64, __int64))(a1 + 32))(a1, a2, v3);
return value_destroy(v3);
}

original_code:
void define_int_constant(language_t*li, const char*name, int i)
{
    value_t* v = value_new_int32(i);
    li->define_constant(li, name, v);
    value_destroy(v);
}

canonical_original_code:
void define_int_constant(struct _language *li, char *name, int i)
{
    struct _value *v = value_new_int32(i);
    li->define_constant(li, name, v);
    value_destroy(v);
}

variable_types:
name
char *

variable_types: i int

variable_types: struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *


decompiled_code:
__int64 __fastcall define_string_constant(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbx

v3 = value_new_string(a3);
(*(void (__fastcall **)(__int64, __int64, __int64))(a1 + 32))(a1, a2, v3);
return value_destroy(v3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbx

v3 = value_new_string(a3);
(*(void (__fastcall **)(__int64, __int64, __int64))(a1 + 32))(a1, a2, v3);
return value_destroy(v3);
}

original_code:
void define_string_constant(language_t*li, const char*name, const char*s)
{
    value_t* v = value_new_string(s);
    li->define_constant(li, name, v);
    value_destroy(v);
}

canonical_original_code:
void define_string_constant(struct _language *li, char *name, char *s)
{
    struct _value *v = value_new_string(s);
    li->define_constant(li, name, v);
    value_destroy(v);
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall define_function(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = value_new_cfunction();
return (*(__int64 (__fastcall **)(__int64, __int64, __int64))(a1 + 40))(a1, a2, v2);
}

original_code:
void define_function(language_t*li, const char*name, void*call, void*context, const char*params, const char*ret)
{
    value_t* v = value_new_cfunction(li, name, call, context, params, ret);
    li->define_function(li, name, v);
}

canonical_original_code:
void define_function(struct _language *li, char *name, void *call, void *context, char *params, char *ret)
{
    struct _value *v = value_new_cfunction(li, name, call, context, params, ret);
    li->define_function(li, name, v);
}

variable_types:
call
void *

variable_types:
context
void *

variable_types:
params
char *

variable_types:
ret
char *


decompiled_code:
__int64 __fastcall call_int_function(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_DWORD *v3; // rbx
unsigned int v4; // ebp

v2 = array_new();
v3 = (_DWORD *)(*(__int64 (__fastcall **)(__int64, __int64, __int64))(a1 + 64))(a1, a2, v2);
value_destroy(v2);
if ( *v3 == 2 )
{
v4 = v3[4];
}
else
{
language_error(a1, "expected return value to be an integer");
v4 = -1;
}
value_destroy(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_DWORD *v3; // rbx
unsigned int v4; // ebp

v2 = array_new();
v3 = (_DWORD *)(*(__int64 (__fastcall **)(__int64, __int64, __int64))(a1 + 64))(a1, a2, v2);
value_destroy(v2);
if ( *v3 == 2 )
{
v4 = v3[4];
}
else
{
language_error(a1, "expected return value to be an integer");
v4 = -1;
}
value_destroy(v3);
return v4;
}

original_code:
int call_int_function(language_t*li, const char*name)
{
    value_t*args = array_new();
    value_t*ret = li->call_function(li, name, args);
    value_destroy(args);
    int r;
    if(ret->type != TYPE_INT32) {
        language_error(li, "expected return value to be an integer");
        r = -1;
    } else {
        r = ret->i32;
    }
    value_destroy(ret);
    return r;
}

canonical_original_code:
int call_int_function(struct _language *li, char *name)
{
    struct _value *args = array_new();
    struct _value *ret = li->call_function(li, name, args);
    value_destroy(args);
    int r;
    if(ret->type != TYPE_INT32) {
        language_error(li, "expected return value to be an integer");
        r = -1;
    } else {
        r = ret->i32;
    }
    value_destroy(ret);
    return r;
}

variable_types: struct _language { void *internal; char *name; _Bool timeout; _Bool (*initialize)(struct _language *li, unsigned long maxmem); void (*define_constant)(struct _language *li, char *name, struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *value); void (*define_function)(struct _language *li, char *name, struct _value *f); _Bool (*compile_script)(struct _language *li, char *script); _Bool (*is_function)(struct _language *li, char *name); struct _value *(*call_function)(struct _language *li, char *name, struct _value *args); void (*destroy)(struct _language *li); void *user; void (*log)(void *user, char *line); } *

variable_types: r int


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

va_start(arg, format);
vfprintf(stdout, format, arg);
putchar(10);
return fflush(stdout);
}

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

va_start(arg, format);
vfprintf(stdout, format, arg);
putchar(10);
return fflush(stdout);
}

original_code:
char* dbg_printf(const char*format, ...)
{
    va_list arglist;
    __builtin_va_start(arglist,format);
    vfprintf(stdout, format, arglist);
    printf("\n");
    __builtin_va_end(arglist);
    fflush(stdout);
}

canonical_original_code:
char *dbg_printf(char *format, ...)
{
    __builtin_va_list arglist;
    __builtin_va_start(arglist,format);
    vfprintf(stdout, format, arglist);
    printf("\n");
    __builtin_va_end(arglist);
    fflush(stdout);
}

variable_types:
format
char *


memdup

decompiled_code:
void *__fastcall memdup(void *src, size_t n)
{
void *v2; // rax
void *v3; // rbx

v2 = malloc(n);
v3 = v2;
if ( v2 )
memcpy(v2, src, n);
return v3;
}

canonical_decompiled_code:
void *__fastcall func1(void *src, size_t n)
{
void *v2; // rax
void *v3; // rbx

v2 = malloc(n);
v3 = v2;
if ( v2 )
memcpy(v2, src, n);
return v3;
}

original_code:
void*memdup(const void*ptr, size_t size)
{
    void*new_ptr = malloc(size);
    if(!new_ptr)
        return ((void *)0);
    memcpy(new_ptr, ptr, size);
    return new_ptr;
}

canonical_original_code:
void *memdup(void *ptr, unsigned long size)
{
    void *new_ptr = malloc(size);
    if(!new_ptr)
        return ((void *)0);
    memcpy(new_ptr, ptr, size);
    return new_ptr;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

return_type: void *


allocprintf

decompiled_code:
char *allocprintf(char *format, ...)
{
size_t v1; // rbx
char *v2; // rbp
gcc_va_list va; // [rsp+8h] [rbp-100h] BYREF
char s; // [rsp+27h] [rbp-E1h] BYREF
gcc_va_list arg; // [rsp+28h] [rbp-E0h] BYREF

va_start(va, format);
va_start(arg, format);
v1 = vsnprintf(&s, 1uLL, format, arg) + 1;
v2 = (char *)malloc(v1);
vsnprintf(v2, v1, format, va);
return v2;
}

canonical_decompiled_code:
char *func2(char *format, ...)
{
size_t v1; // rbx
char *v2; // rbp
gcc_va_list va; // [rsp+8h] [rbp-100h] BYREF
char s; // [rsp+27h] [rbp-E1h] BYREF
gcc_va_list arg; // [rsp+28h] [rbp-E0h] BYREF

va_start(va, format);
va_start(arg, format);
v1 = vsnprintf(&s, 1uLL, format, arg) + 1;
v2 = (char *)malloc(v1);
vsnprintf(v2, v1, format, va);
return v2;
}

original_code:
char* allocprintf(const char*format, ...)
{
    va_list arglist1;
    __builtin_va_start(arglist1,format);
    char dummy;
    int l = vsnprintf(&dummy, 1, format, arglist1);
    __builtin_va_end(arglist1);
    va_list arglist2;
    __builtin_va_start(arglist2,format);
    char*buf = malloc(l+1);
    vsnprintf(buf, l+1, format, arglist2);
    __builtin_va_end(arglist2);
    return buf;
}

canonical_original_code:
char *allocprintf(char *format, ...)
{
    __builtin_va_list arglist1;
    __builtin_va_start(arglist1,format);
    char dummy;
    int l = vsnprintf(&dummy, 1, format, arglist1);
    __builtin_va_end(arglist1);
    __builtin_va_list arglist2;
    __builtin_va_start(arglist2,format);
    char *buf = malloc(l+1);
    vsnprintf(buf, l+1, format, arglist2);
    __builtin_va_end(arglist2);
    return buf;
}

variable_types: dummy char

variable_types: l int

variable_types:
buf
char *


decompiled_code:
void *__fastcall concat_paths(void *src, char *s)
{
int v2; // ebx
int v3; // ebp
int v4; // ecx
__int64 v5; // rax
char *v6; // rax
int i; // ebx
void *v8; // r14

v2 = strlen((const char *)src);
v3 = v2;
v4 = strlen(s);
if ( v2 )
{
v5 = v2;
do
{
v3 = v5;
if ( *((char *)src + v5 - 1) != 47 )
break;
v3 = --v5;
}
while ( (_DWORD)v5 );
}
if ( v4 <= 0 )
{
i = 0;
}
else
{
v6 = s;
for ( i = 0; i != v4; ++i )
{
if ( *v6 != 47 )
break;
++v6;
}
}
v8 = malloc(v3 + v4 - i + 2);
memcpy(v8, src, v3);
*((_BYTE *)v8 + v3) = 47;
strcpy((char *)v8 + v3 + 1, &s[i]);
return v8;
}

canonical_decompiled_code:
void *__fastcall func3(void *src, char *s)
{
int v2; // ebx
int v3; // ebp
int v4; // ecx
__int64 v5; // rax
char *v6; // rax
int i; // ebx
void *v8; // r14

v2 = strlen((const char *)src);
v3 = v2;
v4 = strlen(s);
if ( v2 )
{
v5 = v2;
do
{
v3 = v5;
if ( *((char *)src + v5 - 1) != 47 )
break;
v3 = --v5;
}
while ( (_DWORD)v5 );
}
if ( v4 <= 0 )
{
i = 0;
}
else
{
v6 = s;
for ( i = 0; i != v4; ++i )
{
if ( *v6 != 47 )
break;
++v6;
}
}
v8 = malloc(v3 + v4 - i + 2);
memcpy(v8, src, v3);
*((_BYTE *)v8 + v3) = 47;
strcpy((char *)v8 + v3 + 1, &s[i]);
return v8;
}

original_code:
char* concat_paths(const char*base, const char*add)
{
    int l1 = strlen(base);
    int l2 = strlen(add);
    int pos = 0;
    char*n = 0;
    while(l1 && base[l1-1] == path_seperator)
 l1--;
    while(pos < l2 && add[pos] == path_seperator)
 pos++;
    n = (char*)malloc(l1 + (l2-pos) + 2);
    memcpy(n,base,l1);
    n[l1]=path_seperator;
    strcpy(&n[l1+1],&add[pos]);
    return n;
}

canonical_original_code:
char *concat_paths(char *base, char *add)
{
    int l1 = strlen(base);
    int l2 = strlen(add);
    int pos = 0;
    char *n = 0;
    while(l1 && base[l1-1] == path_seperator)
 l1--;
    while(pos < l2 && add[pos] == path_seperator)
 pos++;
    n = (char *)malloc(l1 + (l2-pos) + 2);
    memcpy(n,base,l1);
    n[l1]=path_seperator;
    strcpy(&n[l1+1],&add[pos]);
    return n;
}

variable_types:
base
char *

variable_types:
add
char *

variable_types: pos int

variable_types:
n
char *


decompiled_code:
int __fastcall mkdir_p(const char *a1)
{
char *v1; // rax
const char *v2; // rbp
char *v3; // rbx
char i; // al

v1 = strdup(a1);
v2 = v1;
if ( *v1 == 47 )
{
v3 = v1;
do
++v3;
while ( *v3 == 47 );
}
else
{
v3 = v1;
}
if ( *v3 )
{
while ( 1 )
{
for ( i = *v3; *v3 != 47 && i; i = *v3 )
++v3;
if ( !i )
break;
*v3 = 0;
mkdir(v2, 0x1C0u);
*v3 = 47;
if ( !v3[1] )
break;
++v3;
}
}
return mkdir(v2, 0x1C0u);
}

canonical_decompiled_code:
int __fastcall func4(const char *a1)
{
char *v1; // rax
const char *v2; // rbp
char *v3; // rbx
char i; // al

v1 = strdup(a1);
v2 = v1;
if ( *v1 == 47 )
{
v3 = v1;
do
++v3;
while ( *v3 == 47 );
}
else
{
v3 = v1;
}
if ( *v3 )
{
while ( 1 )
{
for ( i = *v3; *v3 != 47 && i; i = *v3 )
++v3;
if ( !i )
break;
*v3 = 0;
mkdir(v2, 0x1C0u);
*v3 = 47;
if ( !v3[1] )
break;
++v3;
}
}
return mkdir(v2, 0x1C0u);
}

original_code:
void mkdir_p(const char*_path)
{
    char*path = strdup(_path);
    char*p = path;
    while(*p == path_seperator) {
        p++;
    }
    while(*p) {
        while(*p && *p != path_seperator) {
            p++;
        }
        if(!*p)
            break;
        *p = 0;
        mkdir(path, 0700);
        *p = path_seperator;
        p++;
    }
    mkdir(path, 0700);
}

canonical_original_code:
void mkdir_p(char *_path)
{
    char *path = strdup(_path);
    char *p = path;
    while(*p == path_seperator) {
        p++;
    }
    while(*p) {
        while(*p && *p != path_seperator) {
            p++;
        }
        if(!*p)
            break;
        *p = 0;
        mkdir(path, 0700);
        *p = path_seperator;
        p++;
    }
    mkdir(path, 0700);
}

variable_types:
path
char *

variable_types:
p
char *


decompiled_code:
bool __fastcall read_with_retry(int fd, __int64 a2, int a3)
{
int v4; // ebx
int *v5; // rax
bool result; // al
int v7; // eax

if ( a3 <= 0 )
return 1;
v4 = 0;
while ( 1 )
{
v7 = read(fd, (void *)(a2 + v4), (unsigned int)(a3 - v4));
if ( v7 < 0 )
{
v5 = _errno_location();
result = *v5 == 11 || *v5 == 4;
if ( !result )
return result;
goto LABEL_4;
}
if ( !v7 )
return 0;
v4 += v7;
LABEL_4:
if ( v4 >= a3 )
return 1;
}
}

canonical_decompiled_code:
bool __fastcall func6(int fd, __int64 a2, int a3)
{
int v4; // ebx
int *v5; // rax
bool result; // al
int v7; // eax

if ( a3 <= 0 )
return 1;
v4 = 0;
while ( 1 )
{
v7 = read(fd, (void *)(a2 + v4), (unsigned int)(a3 - v4));
if ( v7 < 0 )
{
v5 = _errno_location();
result = *v5 == 11 || *v5 == 4;
if ( !result )
return result;
goto LABEL_4;
}
if ( !v7 )
return 0;
v4 += v7;
LABEL_4:
if ( v4 >= a3 )
return 1;
}
}

original_code:
_Bool read_with_retry(int fd, void* data, int len)
{
    int pos = 0;
    while(pos<len) {
        int ret = read(fd, data+pos, len-pos);
        if(ret<0) {
            if((*__errno_location ()) == 4 || (*__errno_location ()) == 11)
                continue;
            return 0;
        }
        if(ret==0) {
            return 0;
        }
        pos += ret;
    }
    return 1;
}

canonical_original_code:
_Bool read_with_retry(int fd, void *data, int len)
{
    int pos = 0;
    while(pos<len) {
        int ret = read(fd, data+pos, len-pos);
        if(ret<0) {
            if((*__errno_location ()) == 4 || (*__errno_location ()) == 11)
                continue;
            return 0;
        }
        if(ret==0) {
            return 0;
        }
        pos += ret;
    }
    return 1;
}

variable_types: fd int

variable_types:
data
void *

variable_types: len int

variable_types: ret int


decompiled_code:
bool __fastcall read_with_timeout(int fd, __int64 a2, int a3, struct timeval *a4)
{
__int64 v6; // r15
int v7; // eax
bool result; // al
int *v9; // rax
int *v10; // rax
int v11; // [rsp+Ch] [rbp-BCh]
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF

if ( !a4 )
return read_with_retry(fd, a2, a3);
memset(&readfds, 0, sizeof(readfds));
v6 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v6;
if ( a3 <= 0 )
return 1;
v11 = 0;
while ( 1 )
{
while ( select(fd + 1, &readfds, 0LL, 0LL, a4) < 0 )
{
v9 = _errno_location();
result = *v9 == 11 || *v9 == 4;
if ( !result )
return result;
}
if ( (readfds.fds_bits[fd / 64] & v6) == 0 )
return 0;
v7 = read(fd, (void *)(a2 + v11), (unsigned int)(a3 - v11));
if ( v7 < 0 )
{
v10 = _errno_location();
result = *v10 == 11 || *v10 == 4;
if ( !result )
return result;
goto LABEL_9;
}
if ( !v7 )
return 0;
v11 += v7;
LABEL_9:
if ( v11 >= a3 )
return 1;
}
}

canonical_decompiled_code:
bool __fastcall func7(int fd, __int64 a2, int a3, struct timeval *a4)
{
__int64 v6; // r15
int v7; // eax
bool result; // al
int *v9; // rax
int *v10; // rax
int v11; // [rsp+Ch] [rbp-BCh]
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF

if ( !a4 )
return func6(fd, a2, a3);
memset(&readfds, 0, sizeof(readfds));
v6 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v6;
if ( a3 <= 0 )
return 1;
v11 = 0;
while ( 1 )
{
while ( select(fd + 1, &readfds, 0LL, 0LL, a4) < 0 )
{
v9 = _errno_location();
result = *v9 == 11 || *v9 == 4;
if ( !result )
return result;
}
if ( (readfds.fds_bits[fd / 64] & v6) == 0 )
return 0;
v7 = read(fd, (void *)(a2 + v11), (unsigned int)(a3 - v11));
if ( v7 < 0 )
{
v10 = _errno_location();
result = *v10 == 11 || *v10 == 4;
if ( !result )
return result;
goto LABEL_9;
}
if ( !v7 )
return 0;
v11 += v7;
LABEL_9:
if ( v11 >= a3 )
return 1;
}
}

original_code:
_Bool read_with_timeout(int fd, void* data, int len, struct timeval* timeout)
{
    if(!timeout) {
        return read_with_retry(fd, data, len);
    }
    fd_set readfds;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&readfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    int pos = 0;
    while(pos<len) {
        int ret;
        while(1) {
            ret = select(fd+1, &readfds, ((void *)0), ((void *)0), timeout);
            if(ret<0) {
                if((*__errno_location ()) == 4 || (*__errno_location ()) == 11)
                    continue;
                return 0;
            }
            if(ret>=0)
                break;
        }
        if(!((((&readfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            return 0;
        }
        ret = read(fd, data+pos, len-pos);
        if(ret<0) {
            if((*__errno_location ()) == 4 || (*__errno_location ()) == 11)
                continue;
            return 0;
        }
        if(ret==0) {
            return 0;
        }
        pos += ret;
    }
    return 1;
}

canonical_original_code:
_Bool read_with_timeout(int fd, void *data, int len, struct timeval *timeout)
{
    if(!timeout) {
        return read_with_retry(fd, data, len);
    }
    struct fd_set readfds;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&readfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    int pos = 0;
    while(pos<len) {
        int ret;
        while(1) {
            ret = select(fd+1, &readfds, ((void *)0), ((void *)0), timeout);
            if(ret<0) {
                if((*__errno_location ()) == 4 || (*__errno_location ()) == 11)
                    continue;
                return 0;
            }
            if(ret>=0)
                break;
        }
        if(!((((&readfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            return 0;
        }
        ret = read(fd, data+pos, len-pos);
        if(ret<0) {
            if((*__errno_location ()) == 4 || (*__errno_location ()) == 11)
                continue;
            return 0;
        }
        if(ret==0) {
            return 0;
        }
        pos += ret;
    }
    return 1;
}

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

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


decompiled_code:
void __fastcall __noreturn handle_signal(int status)
{
puts("signal");
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int status)
{
puts("signal");
exit(status);
}

original_code:
static void handle_signal(int signal, siginfo_t*siginfo, void*ucontext)
{
    void*here;
    printf("signal\n");
    Dl_info info;
    void**stack_top = &here;
    int i = 0;
    _exit(signal);
}

canonical_original_code:
static void handle_signal(int signal, struct siginfo_t *siginfo, void *ucontext)
{
    void *here;
    printf("signal\n");
    struct Dl_info info;
    void **stack_top = &here;
    int i = 0;
    _exit(signal);
}

variable_types: signal int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
ucontext
void *

variable_types:
here
void *

variable_types: struct Dl_info { char *dli_fname; void *dli_fbase; char *dli_sname; void *dli_saddr; }

variable_types: i int

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
int seccomp_lockdown()
{
int result; // eax
__int16 v1; // [rsp+0h] [rbp-168h] BYREF
char *v2; // [rsp+8h] [rbp-160h]
char v3[320]; // [rsp+10h] [rbp-158h] BYREF
struct rlimit64 rlimits; // [rsp+150h] [rbp-18h] BYREF

setenv("MALLOC_CHECK_", "0", 1);
sig.sa_handler = (__sighandler_t)handle_signal;
dword_1E8 = 4;
sigaction(11, &sig, 0LL);
sigaction(6, &sig, 0LL);
rlimits.rlim_max = config_maxmem + 0x10000;
rlimits.rlim_cur = rlimits.rlim_max;
setrlimit64(RLIMIT_DATA, &rlimits);
qmemcpy(v3, &unk_260, sizeof(v3));
v1 = 40;
v2 = v3;
if ( prctl(38, 1LL, 0LL, 0LL, 0LL) || (result = prctl(22, 2LL, &v1, 0LL, 0LL)) != 0 )
{
fwrite("could not enter secure computation mode\n", 1uLL, 0x28uLL, stderr);
perror("prctl");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
__int16 v1; // [rsp+0h] [rbp-168h] BYREF
char *v2; // [rsp+8h] [rbp-160h]
char v3[320]; // [rsp+10h] [rbp-158h] BYREF
struct rlimit64 rlimits; // [rsp+150h] [rbp-18h] BYREF

setenv("MALLOC_CHECK_", "0", 1);
sig.sa_handler = (__sighandler_t)handle_signal;
dword_1E8 = 4;
sigaction(11, &sig, 0LL);
sigaction(6, &sig, 0LL);
rlimits.rlim_max = config_maxmem + 0x10000;
rlimits.rlim_cur = rlimits.rlim_max;
setrlimit64(RLIMIT_DATA, &rlimits);
qmemcpy(v3, &unk_260, sizeof(v3));
v1 = 40;
v2 = v3;
if ( prctl(38, 1LL, 0LL, 0LL, 0LL) || (result = prctl(22, 2LL, &v1, 0LL, 0LL)) != 0 )
{
fwrite("could not enter secure computation mode\n", 1uLL, 0x28uLL, stderr);
perror("prctl");
exit(1);
}
return result;
}

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }

variable_types: struct sock_filter { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; } []

variable_types: struct sock_fprog { unsigned short len; struct sock_filter { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; } *filter; }

user_defined_types: struct sock_fprog { unsigned short len; struct sock_filter *filter; }


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

result = calloc(1uLL, 0x60uLL);
result[1] = "lua";
result[3] = initialize_lua;
result[6] = compile_script_lua;
result[7] = is_function_lua;
result[8] = call_function_lua;
result[5] = define_function_lua;
result[4] = define_constant_lua;
result[9] = destroy_lua;
return result;
}

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

result = calloc(1uLL, 0x60uLL);
result[1] = "lua";
result[3] = initialize_lua;
result[6] = compile_script_lua;
result[7] = is_function_lua;
result[8] = call_function_lua;
result[5] = define_function_lua;
result[4] = define_constant_lua;
result[9] = destroy_lua;
return result;
}

original_code:
language_t* lua_interpreter_new()
{
    language_t * li = calloc(1, sizeof(language_t));
    li->name = "lua";
    li->initialize = initialize_lua;
    li->compile_script = compile_script_lua;
    li->is_function = is_function_lua;
    li->call_function = call_function_lua;
    li->define_function = define_function_lua;
    li->define_constant = define_constant_lua;
    li->destroy = destroy_lua;
    return li;
}

canonical_original_code:
struct _language *lua_interpreter_new()
{
    struct _language *li = calloc(1, sizeof(language_t));
    li->name = "lua";
    li->initialize = initialize_lua;
    li->compile_script = compile_script_lua;
    li->is_function = is_function_lua;
    li->call_function = call_function_lua;
    li->define_function = define_function_lua;
    li->define_constant = define_constant_lua;
    li->destroy = destroy_lua;
    return li;
}

variable_types: struct _language { void *internal; char *name; _Bool timeout; _Bool (*initialize)(struct _language *li, unsigned long maxmem); void (*define_constant)(struct _language *li, char *name, struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *value); void (*define_function)(struct _language *li, char *name, struct _value *f); _Bool (*compile_script)(struct _language *li, char *script); _Bool (*is_function)(struct _language *li, char *name); struct _value *(*call_function)(struct _language *li, char *name, struct _value *args); void (*destroy)(struct _language *li); void *user; void (*log)(void *user, char *line); } *


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

result = calloc(1uLL, 0x60uLL);
result[1] = "py";
result[3] = initialize_py;
result[6] = compile_script_py;
result[7] = is_function_py;
result[8] = call_function_py;
result[4] = define_constant_py;
result[5] = define_function_py;
result[9] = destroy_py;
return result;
}

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

result = calloc(1uLL, 0x60uLL);
result[1] = "py";
result[3] = initialize_py;
result[6] = compile_script_py;
result[7] = is_function_py;
result[8] = call_function_py;
result[4] = define_constant_py;
result[5] = define_function_py;
result[9] = destroy_py;
return result;
}

original_code:
language_t* python_interpreter_new()
{
    language_t * li = calloc(1, sizeof(language_t));
    li->name = "py";
    li->initialize = initialize_py;
    li->compile_script = compile_script_py;
    li->is_function = is_function_py;
    li->call_function = call_function_py;
    li->define_constant = define_constant_py;
    li->define_function = define_function_py;
    li->destroy = destroy_py;
    return li;
}

canonical_original_code:
struct _language *python_interpreter_new()
{
    struct _language *li = calloc(1, sizeof(language_t));
    li->name = "py";
    li->initialize = initialize_py;
    li->compile_script = compile_script_py;
    li->is_function = is_function_py;
    li->call_function = call_function_py;
    li->define_constant = define_constant_py;
    li->define_function = define_function_py;
    li->destroy = destroy_py;
    return li;
}


setComplement

repo: matthiasr/revcomp

decompiled_code:
__int64 __fastcall setComplement(char a1, char a2)
{
__int64 result; // rax

complement[a1] = a2;
complement[a2] = a1;
result = a1 | 0x20;
complement[result] = a2;
complement[a2 | 0x20] = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1, char a2)
{
__int64 result; // rax

complement[a1] = a2;
complement[a2] = a1;
result = a1 | 0x20;
complement[result] = a2;
complement[a2 | 0x20] = a1;
return result;
}

original_code:
void
setComplement(char c1, char c2)
{
 complement[c1] = c2;
 complement[c2] = c1;
 complement[c1 | 0x20] = c2;
 complement[c2 | 0x20] = c1;
}


reverseComplementBlock

decompiled_code:
int *__fastcall reverseComplementBlock(int *a1)
{
int *v1; // rdx
int *result; // rax
char v3; // cl

v1 = a1 + 1;
result = (int *)((char *)a1 + *a1 + 3);
if ( a1 + 1 <= result )
{
do
{
v3 = complement[*(char *)v1];
*(_BYTE *)v1 = complement[*(char *)result];
*(_BYTE *)result = v3;
v1 = (int *)((char *)v1 + 1);
result = (int *)((char *)result - 1);
}
while ( v1 <= result );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func10(int *a1)
{
int *v1; // rdx
int *result; // rax
char v3; // cl

v1 = a1 + 1;
result = (int *)((char *)a1 + *a1 + 3);
if ( a1 + 1 <= result )
{
do
{
v3 = complement[*(char *)v1];
*(_BYTE *)v1 = complement[*(char *)result];
*(_BYTE *)result = v3;
v1 = (int *)((char *)v1 + 1);
result = (int *)((char *)result - 1);
}
while ( v1 <= result );
}
return result;
}

original_code:
void
reverseComplementBlock(Block * block)
{
 char *ptr1;
 char *ptr2;
 char c;
 ptr1 = &(block->text[0]);
 ptr2 = &(block->text[block->len - 1]);
 while (ptr1 <= ptr2) {
  c = complement[*ptr1];
  *ptr1 = complement[*ptr2];
  *ptr2 = c;
  ptr1++;
  ptr2--;
 }
}

canonical_original_code:
void reverseComplementBlock(struct block_struct *block)
{
 char *ptr1;
 char *ptr2;
 char c;
 ptr1 = &(block->text[0]);
 ptr2 = &(block->text[block->len - 1]);
 while (ptr1 <= ptr2) {
  c = complement[*ptr1];
  *ptr1 = complement[*ptr2];
  *ptr2 = c;
  ptr1++;
  ptr2--;
 }
}

variable_types: struct block_struct { int len; char text[1024]; struct block_struct *next; } *

variable_types: c char


readBlocks

original_code:
Block *
readBlocks()
{
 char c;
 int i;
 Block *result;
 Block *old;
 old = ((void *)0);
 result = ((void *)0);
 c = ' ';
 while (c != '>' && !feof(stdin)) {
  result = malloc(sizeof(Block));
  i = 0;
  while (i < 1024 && !feof(stdin)) {
   c = (char)my_getc(stdin);
   if (c == '>') {
    ungetc(c, stdin);
    break;
   }
   if (c >= ' ') {
     result->text[i++] = c;
   }
  }
  result->len = i;
  result->next = old;
  old = result;
 }
 return result;
}

canonical_original_code:
struct block_struct *readBlocks()
{
 char c;
 int i;
 struct block_struct *result;
 struct block_struct *old;
 old = ((void *)0);
 result = ((void *)0);
 c = ' ';
 while (c != '>' && !feof(stdin)) {
  result = malloc(sizeof(Block));
  i = 0;
  while (i < 1024 && !feof(stdin)) {
   c = (char)my_getc(stdin);
   if (c == '>') {
    ungetc(c, stdin);
    break;
   }
   if (c >= ' ') {
     result->text[i++] = c;
   }
  }
  result->len = i;
  result->next = old;
  old = result;
 }
 return result;
}

return_type: struct block_struct { int len; char text[1024]; struct block_struct *next; } *


decompiled_code:
__int64 process_sequence()
{
int v0; // ebp
__int64 result; // rax
int *v2; // r12
__int64 v3; // rbx
int *v4; // rbx
char v5[184]; // [rsp+0h] [rbp-B8h] BYREF

v0 = feof(stdin);
result = 0LL;
if ( !v0 )
{
fgets(v5, 132, stdin);
if ( !index(v5, 10) )
{
while ( my_getc(stdin) != 10 )
;
}
v2 = (int *)readBlocks();
printf("%s", v5);
if ( v2 )
{
while ( 1 )
{
reverseComplementBlock(v2);
if ( *v2 > 0 )
{
v3 = 0LL;
do
{
if ( v0 == 60 )
{
my_putc(10, (FILE *)stdout);
v0 = 1;
}
else
{
++v0;
}
my_putc(*((char *)v2 + v3++ + 4), (FILE *)stdout);
}
while ( *v2 > (int)v3 );
}
v4 = (int *)*((_QWORD *)v2 + 129);
free(v2);
if ( !v4 )
break;
v2 = v4;
}
}
my_putc(10, (FILE *)stdout);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // ebp
__int64 result; // rax
int *v2; // r12
__int64 v3; // rbx
int *v4; // rbx
char v5[184]; // [rsp+0h] [rbp-B8h] BYREF

v0 = feof(stdin);
result = 0LL;
if ( !v0 )
{
fgets(v5, 132, stdin);
if ( !index(v5, 10) )
{
while ( func7(stdin) != 10 )
;
}
v2 = (int *)func11();
printf("%s", v5);
if ( v2 )
{
while ( 1 )
{
func10(v2);
if ( *v2 > 0 )
{
v3 = 0LL;
do
{
if ( v0 == 60 )
{
func8(10, (FILE *)stdout);
v0 = 1;
}
else
{
++v0;
}
func8(*((char *)v2 + v3++ + 4), (FILE *)stdout);
}
while ( *v2 > (int)v3 );
}
v4 = (int *)*((_QWORD *)v2 + 129);
free(v2);
if ( !v4 )
break;
v2 = v4;
}
}
func8(10, (FILE *)stdout);
result = 1LL;
}
return result;
}

original_code:
int
process_sequence()
{
 char title [132];
 Block *ptr;
 Block *old_ptr;
 int i;
 int cpos;
 if (!feof(stdin)) {
  fgets(title, 132, stdin);
 } else {
  return 0;
 }
 if (index(title, '\n') == ((void *)0)) {
  while (my_getc(stdin) != '\n') {
  }
 }
 ptr = readBlocks();
 printf("%s", title);
 cpos = 0;
 while (ptr != ((void *)0)) {
  reverseComplementBlock(ptr);
  for (i = 0; i < ptr->len; i++) {
   if (cpos++ == 60) {
    my_putc('\n', stdout);
    cpos = 1;
   }
   my_putc(ptr->text[i], stdout);
  }
  old_ptr = ptr;
  ptr = ptr->next;
  free(old_ptr);
 }
 my_putc('\n', stdout);
 return 1;
}

canonical_original_code:
int process_sequence()
{
 char title[132];
 struct block_struct *ptr;
 struct block_struct *old_ptr;
 int i;
 int cpos;
 if (!feof(stdin)) {
  fgets(title, 132, stdin);
 } else {
  return 0;
 }
 if (index(title, '\n') == ((void *)0)) {
  while (my_getc(stdin) != '\n') {
  }
 }
 ptr = readBlocks();
 printf("%s", title);
 cpos = 0;
 while (ptr != ((void *)0)) {
  reverseComplementBlock(ptr);
  for (i = 0; i < ptr->len; i++) {
   if (cpos++ == 60) {
    my_putc('\n', stdout);
    cpos = 1;
   }
   my_putc(ptr->text[i], stdout);
  }
  old_ptr = ptr;
  ptr = ptr->next;
  free(old_ptr);
 }
 my_putc('\n', stdout);
 return 1;
}

variable_types:
title
char [132]

variable_types: cpos int

user_defined_types: struct block_struct { int len; char text[1024]; struct block_struct *next; }


main

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

v3 = complement;
do
*v3++ = 0;
while ( v3 != (char *)&end );
setComplement(65, 84);
setComplement(67, 71);
setComplement(77, 75);
setComplement(82, 89);
setComplement(87, 87);
setComplement(83, 83);
setComplement(86, 66);
setComplement(72, 68);
setComplement(78, 78);
do
result = process_sequence();
while ( result );
return result;
}

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

v3 = complement;
do
*v3++ = 0;
while ( v3 != (char *)&end );
func9(65, 84);
func9(67, 71);
func9(77, 75);
func9(82, 89);
func9(87, 87);
func9(83, 83);
func9(86, 66);
func9(72, 68);
func9(78, 78);
do
result = func12();
while ( result );
return result;
}

original_code:
int
main(int argc, char** argv)
{
 int i;
 char title [132];
 for (i = 0; i < 256; i++) {
  complement[i] = 0;
 }
 setComplement('A', 'T');
 setComplement('C', 'G');
 setComplement('M', 'K');
 setComplement('R', 'Y');
 setComplement('W', 'W');
 setComplement('S', 'S');
 setComplement('V', 'B');
 setComplement('H', 'D');
 setComplement('N', 'N');
 while (process_sequence()) {
 }
        return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i;
 char title[132];
 for (i = 0; i < 256; i++) {
  complement[i] = 0;
 }
 setComplement('A', 'T');
 setComplement('C', 'G');
 setComplement('M', 'K');
 setComplement('R', 'Y');
 setComplement('W', 'W');
 setComplement('S', 'S');
 setComplement('V', 'B');
 setComplement('H', 'D');
 setComplement('N', 'N');
 while (process_sequence()) {
 }
        return 0;
}

variable_types: argc int

variable_types:
argv
char **


original_code:
void setup_complement(void) {
    unsigned char c;
    for(c=0; c < 255; c++) complement[c] = c;
        { complement['G'] = 'C'; complement['C'] = 'G'; complement['G'+32]='C'; complement['C'+32]='G'; };
        { complement['A'] = 'T'; complement['T'] = 'A'; complement['A'+32]='T'; complement['T'+32]='A'; };
        { complement['M'] = 'K'; complement['K'] = 'M'; complement['M'+32]='K'; complement['K'+32]='M'; };
        { complement['R'] = 'Y'; complement['Y'] = 'R'; complement['R'+32]='Y'; complement['Y'+32]='R'; };
        { complement['V'] = 'B'; complement['B'] = 'V'; complement['V'+32]='B'; complement['B'+32]='V'; };
        { complement['H'] = 'D'; complement['D'] = 'H'; complement['H'+32]='D'; complement['D'+32]='H'; };
}

canonical_original_code:
void setup_complement() {
    unsigned char c;
    for(c=0; c < 255; c++) complement[c] = c;
        { complement['G'] = 'C'; complement['C'] = 'G'; complement['G'+32]='C'; complement['C'+32]='G'; };
        { complement['A'] = 'T'; complement['T'] = 'A'; complement['A'+32]='T'; complement['T'+32]='A'; };
        { complement['M'] = 'K'; complement['K'] = 'M'; complement['M'+32]='K'; complement['K'+32]='M'; };
        { complement['R'] = 'Y'; complement['Y'] = 'R'; complement['R'+32]='Y'; complement['Y'+32]='R'; };
        { complement['V'] = 'B'; complement['B'] = 'V'; complement['V'+32]='B'; complement['B'+32]='V'; };
        { complement['H'] = 'D'; complement['D'] = 'H'; complement['H'+32]='D'; complement['D'+32]='H'; };
}

variable_types:
c
unsigned char


complementAll

decompiled_code:
void __fastcall complementAll(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rax
_BYTE *v3; // rsi

if ( a2 )
{
v2 = a1;
v3 = &a1[a2];
do
{
*v2 = complement[(char)*v2];
++v2;
}
while ( v2 != v3 );
}
}

canonical_decompiled_code:
void __fastcall func8(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rax
_BYTE *v3; // rsi

if ( a2 )
{
v2 = a1;
v3 = &a1[a2];
do
{
*v2 = complement[(char)*v2];
++v2;
}
while ( v2 != v3 );
}
}

original_code:
void complementAll(char* array, size_t len) {
    int i;
    for(i=0; i<len; i++)
        array[i] = complement[array[i]];
}

canonical_original_code:
void complementAll(char *array, unsigned long len) {
    int i;
    for(i=0; i<len; i++)
        array[i] = complement[array[i]];
}

variable_types:
array
char *

variable_types:
len
unsigned long


reverse

decompiled_code:
unsigned __int64 __fastcall reverse(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
_BYTE *v3; // r8
char i; // dl
_BYTE *v5; // r9
char j; // cl

for ( result = 0LL; result < a2; --a2 )
{
v3 = (_BYTE *)(a1 + result);
for ( i = *(_BYTE *)(a1 + result); i == 10; i = *(_BYTE *)(a1 + result) )
{
++result;
v3 = (_BYTE *)(a1 + result);
}
v5 = (_BYTE *)(a1 + a2);
for ( j = *(_BYTE *)(a1 + a2); j == 10; j = *(_BYTE *)(a1 + a2) )
{
--a2;
v5 = (_BYTE *)(a1 + a2);
}
*v3 = j;
*v5 = i;
++result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
_BYTE *v3; // r8
char i; // dl
_BYTE *v5; // r9
char j; // cl

for ( result = 0LL; result < a2; --a2 )
{
v3 = (_BYTE *)(a1 + result);
for ( i = *(_BYTE *)(a1 + result); i == 10; i = *(_BYTE *)(a1 + result) )
{
++result;
v3 = (_BYTE *)(a1 + result);
}
v5 = (_BYTE *)(a1 + a2);
for ( j = *(_BYTE *)(a1 + a2); j == 10; j = *(_BYTE *)(a1 + a2) )
{
--a2;
v5 = (_BYTE *)(a1 + a2);
}
*v3 = j;
*v5 = i;
++result;
}
return result;
}

original_code:
void reverse(char* array, size_t len) {
    char temp;
    size_t a = 0, b = len;
    while(a<b) {
        while(array[a] == '\n') a++;
        while(array[b] == '\n') b--;
        temp = array[a];
        array[a] = array[b];
        array[b] = temp;
        a++; b--;
    }
}

canonical_original_code:
void reverse(char *array, unsigned long len) {
    char temp;
    unsigned long a = 0; unsigned long b = len;
    while(a<b) {
        while(array[a] == '\n') a++;
        while(array[b] == '\n') b--;
        temp = array[a];
        array[a] = array[b];
        array[b] = temp;
        a++; b--;
    }
}

variable_types: temp char

variable_types:
a
unsigned long

variable_types:
b
unsigned long


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
size_t v4; // r13
size_t v5; // rbx
size_t v6; // rax
size_t v7; // rbp
unsigned __int64 v8; // rbx
char *i; // r14
unsigned __int64 v10; // rbp

setup_complement(argc, argv, envp);
v3 = (char *)malloc(0x400uLL);
v4 = 0LL;
v5 = 1024LL;
while ( !feof(stdin) )
{
v4 += fread(&v3[v4], 1uLL, v5 - v4, stdin);
if ( v5 == v4 )
{
v5 *= 2LL;
v3 = (char *)realloc(v3, v5);
}
}
v6 = 0LL;
if ( v4 )
{
while ( 1 )
{
for ( i = &v3[v6]; v3[v6] != 10; i = &v3[v6] )
++v6;
if ( v4 <= v6 )
break;
v7 = v6;
while ( v3[v7] != 62 )
{
if ( v4 == ++v7 )
goto LABEL_16;
}
v8 = ~v6 + v7;
complementAll(i, v8);
reverse((__int64)i, v8);
if ( v4 <= v7 )
goto LABEL_17;
v6 = v7;
}
v7 = v6;
LABEL_16:
v10 = ~v6 + v7;
complementAll(i, v10);
reverse((__int64)i, v10);
}
LABEL_17:
fwrite(v3, 1uLL, v4, stdout);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
size_t v4; // r13
size_t v5; // rbx
size_t v6; // rax
size_t v7; // rbp
unsigned __int64 v8; // rbx
char *i; // r14
unsigned __int64 v10; // rbp

func7(argc, argv, envp);
v3 = (char *)malloc(0x400uLL);
v4 = 0LL;
v5 = 1024LL;
while ( !feof(stdin) )
{
v4 += fread(&v3[v4], 1uLL, v5 - v4, stdin);
if ( v5 == v4 )
{
v5 *= 2LL;
v3 = (char *)realloc(v3, v5);
}
}
v6 = 0LL;
if ( v4 )
{
while ( 1 )
{
for ( i = &v3[v6]; v3[v6] != 10; i = &v3[v6] )
++v6;
if ( v4 <= v6 )
break;
v7 = v6;
while ( v3[v7] != 62 )
{
if ( v4 == ++v7 )
goto LABEL_16;
}
v8 = ~v6 + v7;
func8(i, v8);
func9((__int64)i, v8);
if ( v4 <= v7 )
goto LABEL_17;
v6 = v7;
}
v7 = v6;
LABEL_16:
v10 = ~v6 + v7;
func8(i, v10);
func9((__int64)i, v10);
}
LABEL_17:
fwrite(v3, 1uLL, v4, stdout);
exit(0);
}

original_code:
int main(int argc, char** argv) {
    setup_complement();
    size_t bufsize = 1024;
    size_t nread = 0;
    size_t blockstart=0, blockend=0;
    char* buf;
    buf = malloc(sizeof(char)*bufsize);
    while(!feof(stdin)) {
        nread += fread(buf+nread, sizeof(char), bufsize-nread, stdin);
        if(nread == bufsize) {
            bufsize *= 2;
            buf = realloc(buf, bufsize);
        }
    }
    while(blockstart < nread) {
        while(buf[blockstart] != '\n')
            blockstart++;
        blockend = blockstart;
        while(blockend < nread && buf[blockend] != '>')
            blockend++;
        blockend--;
        complementAll(buf+blockstart, blockend-blockstart);
        reverse(buf+blockstart, blockend-blockstart);
        blockstart = blockend+1;
    }
    fwrite(buf, sizeof(char), nread, stdout);
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv) {
    setup_complement();
    unsigned long bufsize = 1024;
    unsigned long nread = 0;
    unsigned long blockstart = 0; unsigned long blockend = 0;
    char *buf;
    buf = malloc(sizeof(char)*bufsize);
    while(!feof(stdin)) {
        nread += fread(buf+nread, sizeof(char), bufsize-nread, stdin);
        if(nread == bufsize) {
            bufsize *= 2;
            buf = realloc(buf, bufsize);
        }
    }
    while(blockstart < nread) {
        while(buf[blockstart] != '\n')
            blockstart++;
        blockend = blockstart;
        while(blockend < nread && buf[blockend] != '>')
            blockend++;
        blockend--;
        complementAll(buf+blockstart, blockend-blockstart);
        reverse(buf+blockstart, blockend-blockstart);
        blockstart = blockend+1;
    }
    fwrite(buf, sizeof(char), nread, stdout);
    exit(0);
}

variable_types:
bufsize
unsigned long

variable_types:
nread
unsigned long

variable_types:
blockstart
unsigned long

variable_types:
blockend
unsigned long

variable_types:
buf
char *


repo: matthiasr/teco

decompiled_code:
__int64 find_lasteol()
{
unsigned int v0; // ebx
char v1; // al

t_qp[1] = mstack[1];
t_qp[2] = mstack[2];
v0 = 0;
while ( (unsigned int)backc(t_qp) )
{
v1 = *(_BYTE *)(t_qp[1] + t_qp[2] + 16LL);
if ( v1 == 13 || v1 == 10 )
{
fwdc(t_qp);
break;
}
++v0;
}
char_count = 0;
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
char v1; // al

t_qp[1] = mstack[1];
t_qp[2] = mstack[2];
v0 = 0;
while ( (unsigned int)backc(t_qp) )
{
v1 = *(_BYTE *)(t_qp[1] + t_qp[2] + 16LL);
if ( v1 == 13 || v1 == 10 )
{
fwdc(t_qp);
break;
}
++v0;
}
char_count = 0;
return v0;
}

original_code:
int find_lasteol()
    {
    int i;
    for (i = 0, t_qp.p = mstack[0].p, t_qp.c = mstack[0].c; (backc(&t_qp)) ; i++)
 {
 if ((t_qp.p->ch[t_qp.c] == 015) || (t_qp.p->ch[t_qp.c] == 012))
     {
     fwdc(&t_qp);
     break;
     }
 }
    char_count = 0;
    return(i);
    }

variable_types: i int