decompiled_code:
__time_t get_time_ms()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) )
{
perror("gettimeofday()");
exit(42);
}
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

canonical_decompiled_code:
__time_t func16()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) )
{
perror("gettimeofday()");
exit(42);
}
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

original_code:
time_ms get_time_ms()
{
    struct timeval timeval;
    if (gettimeofday(&timeval, ((void *)0))) {
        perror("gettimeofday()");
        exit(42);
    }
    return timeval.tv_sec * 1000 + timeval.tv_usec / 1000;
}

canonical_original_code:
long get_time_ms()
{
    struct timeval timeval;
    if (gettimeofday(&timeval, ((void *)0))) {
        perror("gettimeofday()");
        exit(42);
    }
    return timeval.tv_sec * 1000 + timeval.tv_usec / 1000;
}

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const void *v3; // r13
int *v4; // rax
const char *v5; // rdi
int *v6; // rbx
__int64 v7; // rbp
char *v8; // r12
int v9; // ebp
int v10; // ebx
int v11; // eax
int v12; // er15
int v14; // eax
__int64 v15; // r14
int v16; // eax
int v17; // er12
void *v18; // rax
char *s2; // [rsp+0h] [rbp-1068h] BYREF
char v20[8]; // [rsp+8h] [rbp-1060h] BYREF
char v21[32]; // [rsp+10h] [rbp-1058h] BYREF
char ptr[4152]; // [rsp+30h] [rbp-1038h] BYREF

if ( argc == 1 )
{
v7 = 10485760LL;
goto LABEL_7;
}
if ( argc != 2 )
{
fprintf(stderr, "Syntax: %s [cbufsize in kb]\n", *argv);
goto LABEL_34;
}
v4 = __errno_location();
v5 = argv[1];
*v4 = 0;
v6 = v4;
v7 = strtol(v5, &s2, 0);
if ( *v6 )
{
perror("Cannot parse cbufsize argument");
exit(1);
}
v8 = s2;
if ( *s2 != 107 || s2[1] )
{
if ( !strcmp("m", s2) )
{
v7 <<= 20;
goto LABEL_7;
}
if ( !*v8 )
goto LABEL_7;
fprintf(stderr, "cbufsize contains garbage: %s\n", v8);
LABEL_34:
exit(1);
}
v7 <<= 10;
LABEL_7:
v9 = cbuf_init(v21, v7);
if ( v9 )
{
fwrite("Out of memory", 1uLL, 0xDuLL, stderr);
exit(2);
}
v10 = 3;
naldetector_init(v20, 0LL);
LABEL_13:
while ( !feof(stdin) && !ferror(stdin) && v10 > 0 )
{
v11 = fread(&ptr[v9], 1uLL, 32 - v9, stdin);
v12 = v11;
if ( v11 && v11 > 0 )
{
v15 = v9 + 1;
while ( 1 )
{
--v12;
v9 = v15;
v16 = naldetector_eat(v20, (unsigned int)v21[v15 + 31]);
v17 = v16;
if ( v16 )
{
if ( !--v10 )
break;
}
++v15;
if ( v12 <= 0 || v10 <= 0 )
goto LABEL_13;
}
v9 = v15 - v16;
v18 = malloc((int)v15 - v16);
v3 = v18;
if ( !v18 )
{
perror("Cannot allocate headers buffer");
exit(2);
}
memcpy(v18, ptr, v9);
cbuf_write(v21, &ptr[v9], v12 + v17);
}
}
if ( !v10 )
{
while ( !feof(stdin) && !ferror(stdin) )
{
v14 = fread(ptr, 1uLL, 0x1000uLL, stdin);
if ( v14 )
cbuf_write(v21, ptr, v14);
}
fwrite(v3, 1uLL, v9, stdout);
cbuf_print_nals(v21, stdout);
}
cbuf_free(v21);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const void *v3; // r13
int *v4; // rax
const char *v5; // rdi
int *v6; // rbx
__int64 v7; // rbp
char *v8; // r12
int v9; // ebp
int v10; // ebx
int v11; // eax
int v12; // er15
int v14; // eax
__int64 v15; // r14
int v16; // eax
int v17; // er12
void *v18; // rax
char *s2; // [rsp+0h] [rbp-1068h] BYREF
char v20[8]; // [rsp+8h] [rbp-1060h] BYREF
char v21[32]; // [rsp+10h] [rbp-1058h] BYREF
char ptr[4152]; // [rsp+30h] [rbp-1038h] BYREF

if ( argc == 1 )
{
v7 = 10485760LL;
goto LABEL_7;
}
if ( argc != 2 )
{
fprintf(stderr, "Syntax: %s [cbufsize in kb]\n", *argv);
goto LABEL_34;
}
v4 = __errno_location();
v5 = argv[1];
*v4 = 0;
v6 = v4;
v7 = strtol(v5, &s2, 0);
if ( *v6 )
{
perror("Cannot parse cbufsize argument");
exit(1);
}
v8 = s2;
if ( *s2 != 107 || s2[1] )
{
if ( !strcmp("m", s2) )
{
v7 <<= 20;
goto LABEL_7;
}
if ( !*v8 )
goto LABEL_7;
fprintf(stderr, "cbufsize contains garbage: %s\n", v8);
LABEL_34:
exit(1);
}
v7 <<= 10;
LABEL_7:
v9 = func7(v21, v7);
if ( v9 )
{
fwrite("Out of memory", 1uLL, 0xDuLL, stderr);
exit(2);
}
v10 = 3;
func11(v20, 0LL);
LABEL_13:
while ( !feof(stdin) && !ferror(stdin) && v10 > 0 )
{
v11 = fread(&ptr[v9], 1uLL, 32 - v9, stdin);
v12 = v11;
if ( v11 && v11 > 0 )
{
v15 = v9 + 1;
while ( 1 )
{
--v12;
v9 = v15;
v16 = func12(v20, (unsigned int)v21[v15 + 31]);
v17 = v16;
if ( v16 )
{
if ( !--v10 )
break;
}
++v15;
if ( v12 <= 0 || v10 <= 0 )
goto LABEL_13;
}
v9 = v15 - v16;
v18 = malloc((int)v15 - v16);
v3 = v18;
if ( !v18 )
{
perror("Cannot allocate headers buffer");
exit(2);
}
memcpy(v18, ptr, v9);
func9(v21, &ptr[v9], v12 + v17);
}
}
if ( !v10 )
{
while ( !feof(stdin) && !ferror(stdin) )
{
v14 = fread(ptr, 1uLL, 0x1000uLL, stdin);
if ( v14 )
func9(v21, ptr, v14);
}
fwrite(v3, 1uLL, v9, stdout);
func10(v21, stdout);
}
func8(v21);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
  struct cbuf cbuf;
  char buf[4096];
  long cbufsize;
  int read;
  char *garbage;
  char *headers;
  int headers_size;
  struct naldetector detector;
  int detected_rewind;
  int remaining_start_prefixes;
  if (argc == 1) {
    cbufsize = 10 * 1024 * 1024;
  } else if (argc == 2) {
    (*__errno_location ()) = 0;
    cbufsize = strtol(argv[1], &garbage, 0);
    if ((*__errno_location ())) {
      perror("Cannot parse cbufsize argument");
      exit(1);
    }
    if (strcmp("k", garbage) == 0) {
      cbufsize *= 1024;
    } else if (strcmp("m", garbage) == 0) {
      cbufsize *= 1024 * 1024;
    } else if (garbage[0] != '\0') {
      fprintf(stderr, "cbufsize contains garbage: %s\n", garbage);
      exit(1);
    }
  } else {
    fprintf(stderr, "Syntax: %s [cbufsize in kb]\n", argv[0]);
    exit(1);
  }
  if (cbuf_init(&cbuf, cbufsize)) {
    fprintf(stderr, "Out of memory");
    exit(2);
  }
  naldetector_init(&detector, 0 );
  headers_size = 0;
  remaining_start_prefixes = 3;
  while (!feof(stdin) && !ferror(stdin) && remaining_start_prefixes > 0) {
    if ((read = fread(&buf[headers_size], 1, 32 - headers_size, stdin))) {
      while (read > 0 && remaining_start_prefixes > 0) {
        read--;
        headers_size++;
        if ((detected_rewind = naldetector_eat(&detector, buf[headers_size - 1]))) {
          if (--remaining_start_prefixes == 0) {
            headers_size -= detected_rewind;
            if (!(headers = malloc(headers_size))) {
              perror("Cannot allocate headers buffer");
              exit(2);
            }
            memcpy(headers, buf, headers_size);
            cbuf_write(&cbuf, &buf[headers_size], read + detected_rewind);
          }
        }
      }
    }
  }
  if (remaining_start_prefixes == 0) {
    while (!feof(stdin) && !ferror(stdin)) {
      if ((read = fread(buf, 1, 4096, stdin))) {
        cbuf_write(&cbuf, buf, read);
      }
    }
    fwrite(headers, 1, headers_size, stdout);
    cbuf_print_nals(&cbuf, stdout);
  }
  cbuf_free(&cbuf);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct cbuf { char *data; unsigned long capacity; int head; unsigned long length; }

variable_types:
buf
char [4096]

variable_types: cbufsize long

variable_types: read int

variable_types:
garbage
char *

variable_types:
headers
char *

variable_types: struct naldetector { int pattern_bytes_ok; int detect_idr_only; }

return_type: int


decompiled_code:
__int64 __fastcall cbuf_init(__int64 a1, size_t a2)
{
void *v2; // rax
__int64 result; // rax

v2 = malloc(a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 1LL;
*(_QWORD *)(a1 + 8) = a2;
result = 0LL;
*(_DWORD *)(a1 + 16) = 0;
*(_QWORD *)(a1 + 24) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, size_t a2)
{
void *v2; // rax
__int64 result; // rax

v2 = malloc(a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 1LL;
*(_QWORD *)(a1 + 8) = a2;
result = 0LL;
*(_DWORD *)(a1 + 16) = 0;
*(_QWORD *)(a1 + 24) = 0LL;
return result;
}

original_code:
int cbuf_init(struct cbuf *cbuf, size_t capacity) {
  cbuf->data = (char *) malloc(capacity);
  if (!cbuf->data) {
    return 1;
  }
  cbuf->capacity = capacity;
  cbuf->head = 0;
  cbuf->length = 0;
  return 0;
}

canonical_original_code:
int cbuf_init(struct cbuf *cbuf, unsigned long capacity) {
  cbuf->data = (char *) malloc(capacity);
  if (!cbuf->data) {
    return 1;
  }
  cbuf->capacity = capacity;
  cbuf->head = 0;
  cbuf->length = 0;
  return 0;
}

variable_types: struct cbuf { char *data; unsigned long capacity; int head; unsigned long length; } *

variable_types:
capacity
unsigned long


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

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

original_code:
void cbuf_free(struct cbuf *cbuf) {
  free(cbuf->data);
}

return_type: void

user_defined_types: struct cbuf { char *data; unsigned long capacity; int head; unsigned long length; }


original_code:
size_t cbuf_write(struct cbuf *cbuf, char *data, size_t length) {
  size_t chunk;
  if (length > cbuf->capacity) {
    memcpy(cbuf->data, &data[length - cbuf->capacity], cbuf->capacity);
    cbuf->head = 0;
    cbuf->length = cbuf->capacity;
    return length;
  }
  cbuf->length += length;
  if (cbuf->length > cbuf->capacity) {
    cbuf->length = cbuf->capacity;
  }
  if (cbuf->head + length > cbuf->capacity) {
    chunk = cbuf->capacity - cbuf->head;
    memcpy(&cbuf->data[cbuf->head], data, chunk);
    memcpy(cbuf->data, data, length - chunk);
    cbuf->head = length - chunk;
  } else {
    memcpy(&cbuf->data[cbuf->head], data, length);
    cbuf->head += length;
    if (cbuf->head == cbuf->capacity) {
      cbuf->head = 0;
    }
  }
  return length;
}

canonical_original_code:
unsigned long cbuf_write(struct cbuf *cbuf, char *data, unsigned long length) {
  unsigned long chunk;
  if (length > cbuf->capacity) {
    memcpy(cbuf->data, &data[length - cbuf->capacity], cbuf->capacity);
    cbuf->head = 0;
    cbuf->length = cbuf->capacity;
    return length;
  }
  cbuf->length += length;
  if (cbuf->length > cbuf->capacity) {
    cbuf->length = cbuf->capacity;
  }
  if (cbuf->head + length > cbuf->capacity) {
    chunk = cbuf->capacity - cbuf->head;
    memcpy(&cbuf->data[cbuf->head], data, chunk);
    memcpy(cbuf->data, data, length - chunk);
    cbuf->head = length - chunk;
  } else {
    memcpy(&cbuf->data[cbuf->head], data, length);
    cbuf->head += length;
    if (cbuf->head == cbuf->capacity) {
      cbuf->head = 0;
    }
  }
  return length;
}

variable_types:
data
char *

variable_types:
length
unsigned long

variable_types:
chunk
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall naldetector_eat(int *a1, char a2)
{
int v2; // eax
__int64 result; // rax

v2 = *a1;
if ( *a1 == 3 )
{
if ( a2 == 1 )
{
result = 4LL;
if ( a1[1] )
{
*a1 = 4;
result = 0LL;
}
}
else
{
result = 0LL;
if ( a2 )
{
*a1 = 0;
result = 0LL;
}
}
}
else
{
if ( v2 != 4 )
{
if ( !a2 )
{
*a1 = v2 + 1;
return 0LL;
}
LABEL_9:
*a1 = 0;
return 0LL;
}
if ( !a1[1] )
fwrite("Warning: this naldetector must be reinitialized before detecting again", 1uLL, 0x46uLL, stderr);
result = 5LL;
if ( (a2 & 0x1F) != 5 )
goto LABEL_9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int *a1, char a2)
{
int v2; // eax
__int64 result; // rax

v2 = *a1;
if ( *a1 == 3 )
{
if ( a2 == 1 )
{
result = 4LL;
if ( a1[1] )
{
*a1 = 4;
result = 0LL;
}
}
else
{
result = 0LL;
if ( a2 )
{
*a1 = 0;
result = 0LL;
}
}
}
else
{
if ( v2 != 4 )
{
if ( !a2 )
{
*a1 = v2 + 1;
return 0LL;
}
LABEL_9:
*a1 = 0;
return 0LL;
}
if ( !a1[1] )
fwrite("Warning: this naldetector must be reinitialized before detecting again", 1uLL, 0x46uLL, stderr);
result = 5LL;
if ( (a2 & 0x1F) != 5 )
goto LABEL_9;
}
return result;
}

original_code:
int naldetector_eat(struct naldetector *detector, char c) {
  if (detector->pattern_bytes_ok == 4 - 1) {
    if (c == 0x01) {
      if (detector->detect_idr_only) {
        detector->pattern_bytes_ok = 4;
        return 0;
      }
      return 4;
    }
    if (c != 0x00) {
      detector->pattern_bytes_ok = 0;
    }
  } else if (detector->pattern_bytes_ok == 4) {
    if (!detector->detect_idr_only) {
      fprintf(stderr, "Warning: this naldetector must be reinitialized before detecting again");
    }
    if ((c & 0x1f) == 5) {
      return 4 + 1;
    }
    detector->pattern_bytes_ok = 0;
    return 0;
  } else if (c == 0x00) {
    detector->pattern_bytes_ok++;
  } else {
    detector->pattern_bytes_ok = 0;
  }
  return 0;
}

variable_types: struct naldetector { int pattern_bytes_ok; int detect_idr_only; } *

variable_types: c char


usage

decompiled_code:
int usage()
{
puts("Usage: gameOfLife [options...]");
puts(" --size -s size of the squared grid (default: 30)");
puts(" --delay -d time between two iterations in ms (default: 100)");
puts(" --cell -c character used to draw a cell (default: '#')");
puts(" --nbiter -n number of iterations (default: 0 (infinite))");
puts(" --border -b border of the grid (0 = no border (default), 1 = fixed border)");
puts(" --pattern -p path to the pattern file");
return puts(" --help display this help");
}

canonical_decompiled_code:
int func0()
{
puts("Usage: gameOfLife [options...]");
puts(" --size -s size of the squared grid (default: 30)");
puts(" --delay -d time between two iterations in ms (default: 100)");
puts(" --cell -c character used to draw a cell (default: '#')");
puts(" --nbiter -n number of iterations (default: 0 (infinite))");
puts(" --border -b border of the grid (0 = no border (default), 1 = fixed border)");
puts(" --pattern -p path to the pattern file");
return puts(" --help display this help");
}

original_code:
void usage(void) {
    printf("Usage: gameOfLife [options...]\n");
    printf("   --size       -s size of the squared grid (default: 30)\n");
    printf("   --delay      -d time between two iterations in ms (default: 100)\n");
    printf("   --cell       -c character used to draw a cell (default: '#')\n");
    printf("   --nbiter     -n number of iterations (default: 0 (infinite))\n");
    printf("   --border     -b border of the grid (0 = no border (default), 1 = fixed border)\n");
    printf("   --pattern    -p path to the pattern file\n");
    printf("   --help          display this help\n");
}

canonical_original_code:
void usage() {
    printf("Usage: gameOfLife [options...]\n");
    printf("   --size       -s size of the squared grid (default: 30)\n");
    printf("   --delay      -d time between two iterations in ms (default: 100)\n");
    printf("   --cell       -c character used to draw a cell (default: '#')\n");
    printf("   --nbiter     -n number of iterations (default: 0 (infinite))\n");
    printf("   --border     -b border of the grid (0 = no border (default), 1 = fixed border)\n");
    printf("   --pattern    -p path to the pattern file\n");
    printf("   --help          display this help\n");
}


initParams

original_code:
void initParams(Params *params) {
    params->size = -1;
    params->sizex = -1;
    params->sizey = -1;
    params->delay = 0;
    params->cell = '#';
    params->nbiter = 0;
    params->filename[0] = '\0';
}

canonical_original_code:
void initParams(struct Params *params) {
    params->size = -1;
    params->sizex = -1;
    params->sizey = -1;
    params->delay = 0;
    params->cell = '#';
    params->nbiter = 0;
    params->filename[0] = '\0';
}

variable_types: struct Params { int size; int sizex; int sizey; int border; long delay; char cell; unsigned int nbiter; int graphmode; char filename[1024]; } *


parseOptions

decompiled_code:
int __fastcall parseOptions(int argc, char **argv, __int64 a3)
{
char *v3; // r13
int result; // eax
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = (char *)(a3 + 36);
while ( 1 )
{
longind[0] = 0;
result = getopt_long(argc, argv, "s:d:c:n:b:p:g:h:", &long_options_0, longind);
if ( result == -1 )
return result;
if ( !result )
{
usage();
exit(0);
}
switch ( result )
{
case 'b':
*(_DWORD *)(a3 + 12) = atoi(optarg);
break;
case 'c':
*(_BYTE *)(a3 + 24) = *optarg;
break;
case 'd':
*(_QWORD *)(a3 + 16) = atol(optarg);
break;
case 'n':
*(_DWORD *)(a3 + 28) = atoi(optarg);
break;
case 'p':
strcpy(v3, optarg);
break;
case 's':
*(_DWORD *)a3 = atoi(optarg);
break;
default:
continue;
}
}
}

canonical_decompiled_code:
int __fastcall func2(int argc, char **argv, __int64 a3)
{
char *v3; // r13
int result; // eax
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = (char *)(a3 + 36);
while ( 1 )
{
longind[0] = 0;
result = getopt_long(argc, argv, "s:d:c:n:b:p:g:h:", &long_options_0, longind);
if ( result == -1 )
return result;
if ( !result )
{
func0();
exit(0);
}
switch ( result )
{
case 'b':
*(_DWORD *)(a3 + 12) = atoi(optarg);
break;
case 'c':
*(_BYTE *)(a3 + 24) = *optarg;
break;
case 'd':
*(_QWORD *)(a3 + 16) = atol(optarg);
break;
case 'n':
*(_DWORD *)(a3 + 28) = atoi(optarg);
break;
case 'p':
strcpy(v3, optarg);
break;
case 's':
*(_DWORD *)a3 = atoi(optarg);
break;
default:
continue;
}
}
}

original_code:
void parseOptions(int argc, char **argv, Params *params) {
    int c;
    while(1) {
        static struct option long_options[] =
        {
            {"help", 0 , &help_tag, 0 },
            {"size", 1, 0, 's'},
            {"delay", 1, 0, 'd'},
            {"cell", 1, 0, 'c'},
            {"nbiter", 1, 0, 'n'},
            {"border", 1, 0, 'b'},
            {"pattern", 1, 0, 'p'},
            {0,0,0,0}
        };
        int option_index = 0;
        c = getopt_long(argc, argv, "s:d:c:n:b:p:g:h:", long_options, &option_index);
        if (c == -1)
            break;
        switch(c) {
          case 0:
            usage();
            exit(0);
          case 's':
            params->size = atoi(optarg);
            break;
          case 'p':
            strcpy(params->filename, optarg);
            break;
          case 'd':
            params->delay = atol(optarg);
            break;
          case 'c':
            params->cell = optarg[0];
            break;
          case 'b':
            params->border = atoi(optarg);
            break;
          case 'n':
            params->nbiter = atoi(optarg);
            break;
        }
    }
}

canonical_original_code:
void parseOptions(int argc, char **argv, struct Params *params) {
    int c;
    while(1) {
        static struct option long_options[] = {
            {"help", 0 , &help_tag, 0 },
            {"size", 1, 0, 's'},
            {"delay", 1, 0, 'd'},
            {"cell", 1, 0, 'c'},
            {"nbiter", 1, 0, 'n'},
            {"border", 1, 0, 'b'},
            {"pattern", 1, 0, 'p'},
            {0,0,0,0}
        };
        int option_index = 0;
        c = getopt_long(argc, argv, "s:d:c:n:b:p:g:h:", long_options, &option_index);
        if (c == -1)
            break;
        switch(c) {
          case 0:
            usage();
            exit(0);
          case 's':
            params->size = atoi(optarg);
            break;
          case 'p':
            strcpy(params->filename, optarg);
            break;
          case 'd':
            params->delay = atol(optarg);
            break;
          case 'c':
            params->cell = optarg[0];
            break;
          case 'b':
            params->border = atoi(optarg);
            break;
          case 'n':
            params->nbiter = atoi(optarg);
            break;
        }
    }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

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

user_defined_types: struct Params { int size; int sizex; int sizey; int border; long delay; char cell; unsigned int nbiter; int graphmode; char filename[1024]; }


checkRuleFixedBorder

canonical_original_code:
int checkRuleFixedBorder(struct Grid *grid, int x, int y){
    int **g = grid->g;
    int sizex = grid->sizex;
    int sizey = grid->sizey;
    if ( x > 0 && x < sizex-1 && y > 0 && y < sizey-1) {
 return g[x-1][y-1]
             + g[x-1][y]
             + g[x-1][y+1]
      + g[x][y-1]
             + g[x][y+1]
      + g[x+1][y-1]
             + g[x+1][y]
             + g [x+1][y+1];
    }
    else if (x == 0) {
       if (y == 0) {
                  return g[0][1]
                       + g[1][1]
                       + g[1][0];
              }
              else if (y == sizey-1) {
    return g[0][sizey-2]
                       + g[1][sizey-1]
                       + g[1][sizey-2];
              }
       else return g[0][y-1]
                        + g[1][y-1]
          + g[1][y] + g[1][y+1]
          + g[0][y+1];
    }
    else if (x == sizex-1) {
       if (y == sizey-1) {
    return g[sizex-1][sizey-2]
         + g[sizex-2][sizey-2]
         + g[sizex-2][sizey-1];
              }
              else if (y == 0) {
    return g[sizex-1][1]
         + g[sizex-2][0]
         + g[sizex-2][1];
              }
              else return g[sizex-1][y-1]
                        + g[sizex-1][y+1]
                        + g[sizex-2][y-1]
                        + g[sizex-2][y]
                        + g[sizex-2][y+1];
    }
    else if (y == sizey-1) {
 return g[x-1][sizey-1]
             + g[x-1][sizey-2]
      + g[x][sizey-2]
             + g[x+1][sizey-2]
      + g[x+1][sizey-1];
    }
    else return g[x-1][0]
              + g[x-1][1]
              + g[x][1]
              + g[x+1][1]
              + g[x+1][0];
}

variable_types: struct Grid { int **g; int sizex; int sizey; } *

variable_types: x int

variable_types: y int

variable_types:
g
int **

variable_types: sizex int

variable_types: sizey int


checkRuleNoBorder

original_code:
int checkRuleNoBorder(Grid *grid, int x, int y){
    int **g = grid->g;
    int sizex = grid->sizex;
    int sizey = grid->sizey;
    int xm1 = (x-1) > -1 ? x-1 : sizex-1;
    int ym1 = (y-1) > -1 ? y-1 : sizey-1;
    int xp1 = (x+1) > sizex-1 ? 0 : x+1;
    int yp1 = (y-1) > sizey-1 ? 0 : y+1;
    return g[xm1][ym1]
         + g[xm1][y]
         + g[xm1][yp1]
         + g[x][ym1]
         + g[x][yp1]
         + g[xp1][ym1]
         + g[xp1][y]
         + g[xp1][yp1];
}

canonical_original_code:
int checkRuleNoBorder(struct Grid *grid, int x, int y){
    int **g = grid->g;
    int sizex = grid->sizex;
    int sizey = grid->sizey;
    int xm1 = (x-1) > -1 ? x-1 : sizex-1;
    int ym1 = (y-1) > -1 ? y-1 : sizey-1;
    int xp1 = (x+1) > sizex-1 ? 0 : x+1;
    int yp1 = (y-1) > sizey-1 ? 0 : y+1;
    return g[xm1][ym1]
         + g[xm1][y]
         + g[xm1][yp1]
         + g[x][ym1]
         + g[x][yp1]
         + g[xp1][ym1]
         + g[xp1][y]
         + g[xp1][yp1];
}

user_defined_types: struct Grid { int **g; int sizex; int sizey; }


update

original_code:
void update(Grid *from, Grid *to, int (*checkRule)(Grid*, int, int)) {
    int i,j,res;
    int sizex = from->sizex;
    int sizey = from->sizey;
    for ( i = 0 ; i < sizex ; i++)
        for ( j = 0 ; j < sizey ; j++) {
     res = checkRule(from, i, j);
     switch(res){
  case 2 :
      if (from->g[i][j] == 0) to->g[i][j] = 0;
      else to->g[i][j] = 1;
      break;
  case 3 :
      to->g[i][j] = 1;
      break;
  default :
      to->g[i][j] = 0;
      break;
     }
 }
}

canonical_original_code:
void update(struct Grid *from, struct Grid *to, int (*checkRule)(struct Grid *, int, int)) {
    int i; int j; int res;
    int sizex = from->sizex;
    int sizey = from->sizey;
    for ( i = 0 ; i < sizex ; i++)
        for ( j = 0 ; j < sizey ; j++) {
     res = checkRule(from, i, j);
     switch(res){
  case 2 :
      if (from->g[i][j] == 0) to->g[i][j] = 0;
      else to->g[i][j] = 1;
      break;
  case 3 :
      to->g[i][j] = 1;
      break;
  default :
      to->g[i][j] = 0;
      break;
     }
 }
}

variable_types:
to
struct Grid *

variable_types:
checkRule
int (*)(struct Grid *, int, int)

variable_types: i int

variable_types: j int

variable_types: res int


initGrid

decompiled_code:
char *__fastcall initGrid(__int64 a1, int a2, int a3)
{
size_t v3; // rbp
char *result; // rax
char *v5; // rbx
char *v6; // r12

v3 = a3;
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
result = (char *)malloc(8LL * a2);
*(_QWORD *)a1 = result;
if ( a2 > 0 )
{
v5 = result;
v6 = &result[8 * a2];
do
{
v5 += 8;
result = (char *)calloc(v3, 4uLL);
*((_QWORD *)v5 - 1) = result;
}
while ( v5 != v6 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, int a2, int a3)
{
size_t v3; // rbp
char *result; // rax
char *v5; // rbx
char *v6; // r12

v3 = a3;
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
result = (char *)malloc(8LL * a2);
*(_QWORD *)a1 = result;
if ( a2 > 0 )
{
v5 = result;
v6 = &result[8 * a2];
do
{
v5 += 8;
result = (char *)calloc(v3, 4uLL);
*((_QWORD *)v5 - 1) = result;
}
while ( v5 != v6 );
}
return result;
}

original_code:
void initGrid(Grid *grid, int sizex, int sizey) {
    grid->sizex = sizex;
    grid->sizey = sizey;
    grid->g = (int**)malloc(sizex * sizeof(int*));
    for(int i = 0; i < sizex ; i++)
      grid->g[i] = (int*)calloc(sizey,sizeof(int));
}

canonical_original_code:
void initGrid(struct Grid *grid, int sizex, int sizey) {
    grid->sizex = sizex;
    grid->sizey = sizey;
    grid->g = (int **)malloc(sizex * sizeof(int *));
    for(int i = 0; i < sizex ; i++)
      grid->g[i] = (int *)calloc(sizey,sizeof(int));
}


loadPatternToGrid

decompiled_code:
__int64 __fastcall loadPatternToGrid(__int64 a1, __int64 a2, int a3, int a4)
{
int v5; // er8
int v6; // edx
__int64 result; // rax
int v9; // esi
__int64 v10; // r8
__int64 v11; // r9
__int64 v12; // rsi
__int64 v13; // rcx

v5 = *(_DWORD *)(a2 + 8);
v6 = *(_DWORD *)(a1 + 8);
if ( v6 > v5 || (result = *(unsigned int *)(a1 + 12), v9 = *(_DWORD *)(a2 + 12), (int)result > v9) )
{
fwrite("ERROR: the pattern size is larger than the grid size. \n", 1uLL, 0x47uLL, stderr);
exit(1);
}
if ( v9 <= (int)result + a4 || v5 <= v6 + a3 )
{
fwrite("ERROR: the offset is too large for the grid.\n", 1uLL, 0x2DuLL, stderr);
exit(1);
}
if ( a3 < 0 || a4 < 0 )
{
a3 = (v5 - v6) >> 1;
a4 = (v9 - (int)result) >> 1;
}
if ( v6 > 0 )
{
v10 = 0LL;
v11 = 4LL * a4;
while ( 1 )
{
if ( (int)result > 0 )
{
v12 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v10);
result = 0LL;
v13 = v11 + *(_QWORD *)(*(_QWORD *)a2 + 8LL * (a3 + (int)v10));
do
{
*(_DWORD *)(v13 + 4 * result) = *(_DWORD *)(v12 + 4 * result);
++result;
}
while ( *(_DWORD *)(a1 + 12) > (int)result );
}
if ( *(_DWORD *)(a1 + 8) <= (int)++v10 )
break;
result = *(unsigned int *)(a1 + 12);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int a3, int a4)
{
int v5; // er8
int v6; // edx
__int64 result; // rax
int v9; // esi
__int64 v10; // r8
__int64 v11; // r9
__int64 v12; // rsi
__int64 v13; // rcx

v5 = *(_DWORD *)(a2 + 8);
v6 = *(_DWORD *)(a1 + 8);
if ( v6 > v5 || (result = *(unsigned int *)(a1 + 12), v9 = *(_DWORD *)(a2 + 12), (int)result > v9) )
{
fwrite("ERROR: the pattern size is larger than the grid size. \n", 1uLL, 0x47uLL, stderr);
exit(1);
}
if ( v9 <= (int)result + a4 || v5 <= v6 + a3 )
{
fwrite("ERROR: the offset is too large for the grid.\n", 1uLL, 0x2DuLL, stderr);
exit(1);
}
if ( a3 < 0 || a4 < 0 )
{
a3 = (v5 - v6) >> 1;
a4 = (v9 - (int)result) >> 1;
}
if ( v6 > 0 )
{
v10 = 0LL;
v11 = 4LL * a4;
while ( 1 )
{
if ( (int)result > 0 )
{
v12 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v10);
result = 0LL;
v13 = v11 + *(_QWORD *)(*(_QWORD *)a2 + 8LL * (a3 + (int)v10));
do
{
*(_DWORD *)(v13 + 4 * result) = *(_DWORD *)(v12 + 4 * result);
++result;
}
while ( *(_DWORD *)(a1 + 12) > (int)result );
}
if ( *(_DWORD *)(a1 + 8) <= (int)++v10 )
break;
result = *(unsigned int *)(a1 + 12);
}
}
return result;
}

original_code:
void loadPatternToGrid(Grid *pattern, Grid *grid, int x, int y) {
    if (pattern->sizex > grid->sizex || pattern->sizey > grid->sizey) {
        fprintf(stderr, "ERROR: the pattern size is larger than the grid size.                 \n");
        exit(1);
    }
    if (y+pattern->sizey > grid->sizey-1 || x+pattern->sizex > grid->sizex-1) {
        fprintf(stderr, "ERROR: the offset is too large for the grid.\n");
        exit(1);
    }
    int x_offset = x, y_offset = y;
    if (x < 0 || y < 0) {
        x_offset = (grid->sizex - pattern->sizex) / 2;
        y_offset = (grid->sizey - pattern->sizey) / 2;
    }
    for(int i = 0; i < pattern->sizex; i++)
        for(int j = 0; j < pattern->sizey; j++)
            grid->g[x_offset+i][y_offset+j] = pattern->g[i][j];
}

canonical_original_code:
void loadPatternToGrid(struct Grid *pattern, struct Grid *grid, int x, int y) {
    if (pattern->sizex > grid->sizex || pattern->sizey > grid->sizey) {
        fprintf(stderr, "ERROR: the pattern size is larger than the grid size.                 \n");
        exit(1);
    }
    if (y+pattern->sizey > grid->sizey-1 || x+pattern->sizex > grid->sizex-1) {
        fprintf(stderr, "ERROR: the offset is too large for the grid.\n");
        exit(1);
    }
    int x_offset = x; int y_offset = y;
    if (x < 0 || y < 0) {
        x_offset = (grid->sizex - pattern->sizex) / 2;
        y_offset = (grid->sizey - pattern->sizey) / 2;
    }
    for(int i = 0; i < pattern->sizex; i++)
        for(int j = 0; j < pattern->sizey; j++)
            grid->g[x_offset+i][y_offset+j] = pattern->g[i][j];
}

variable_types:
grid
struct Grid *


generateRandomPatternOnGrid

original_code:
void generateRandomPatternOnGrid(Grid *grid, double live) {
    double l = live;
    srand(time(((void *)0)));
    if ( l <= 0 || l >=1 )
        l = 0.5;
    for (int w = 0; w < grid->sizex ; w++)
        for (int h = 0; h < grid->sizey ; h++) {
            if((double)rand()/(double)2147483647 <= l)
                grid->g[w][h] = 1;
            else grid->g[w][h] = 0;
        }
}

canonical_original_code:
void generateRandomPatternOnGrid(struct Grid *grid, double live) {
    double l = live;
    srand(time(((void *)0)));
    if ( l <= 0 || l >=1 )
        l = 0.5;
    for (int w = 0; w < grid->sizex ; w++)
        for (int h = 0; h < grid->sizey ; h++) {
            if((double)rand()/(double)2147483647 <= l)
                grid->g[w][h] = 1;
            else grid->g[w][h] = 0;
        }
}

variable_types: live double

variable_types: l double

variable_types: w int

variable_types: h int


freeGrid

original_code:
void freeGrid(Grid *pattern) {
    for (int i = 0; i < pattern->sizey; i++)
        free(pattern->g[i]);
    free(pattern->g);
}

canonical_original_code:
void freeGrid(struct Grid *pattern) {
    for (int i = 0; i < pattern->sizey; i++)
        free(pattern->g[i]);
    free(pattern->g);
}


donothing

repo: romiras/BlackBox-linux

decompiled_code:
void donothing()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
int donothing(char* fmt, ...)
{
}

canonical_original_code:
int donothing(char *fmt, ...)
{
}

variable_types:
fmt
char *


DumpMod

decompiled_code:
void DumpMod()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void DumpMod()
{
  donothing("\n\n---- Mod info:\n");
  donothing("        hs, ms, ds, cs, vs = %d, %d, %d, %d, %d\n",
  mod.hs, mod.ms, mod.ds, mod.cs, mod.vs);
  donothing("        mad, dad = %d, %d\n\n", mod.mad, mod.dad);
}


RegisterModule

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

result = *((int *)&mod + 73);
*(_QWORD *)result = modlist;
modlist = result;
return result;
}

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

result = *((int *)&mod + 73);
*(_QWORD *)result = modlist;
modlist = result;
return result;
}

original_code:
void RegisterModule()
{
  Module* m;
  m = (Module*)mod.dad;
  m->next = modlist;
  modlist = m;
  donothing("Registred module %s\n", mod.name);
}

canonical_original_code:
void RegisterModule()
{
  struct Module *m;
  m = (struct Module *)mod.dad;
  m->next = modlist;
  modlist = m;
  donothing("Registred module %s\n", mod.name);
}

variable_types: struct Module { struct Module *next; int opts; int refcnt; short compTime[6]; int ext; int term; int nofimps; int csize; int code; int procBase; char *names; int *ptrs; struct Module *imports; struct Directory { int num; struct Object { int fprint; int offs; int id; struct Type { int size; struct Module *mod; int id; int base[16]; int fields; int ptroffs[1000000]; } *ostruct; } obj[1000000]; } *export; char name[256]; } *

user_defined_types: struct Module { struct Module *next; int opts; int refcnt; short compTime[6]; int ext; int term; int nofimps; int csize; int code; int procBase; char *names; int *ptrs; struct Module *imports; struct Directory *export; char name[256]; }

user_defined_types: struct Directory { int num; struct Object obj[1000000]; }

user_defined_types: struct Object { int fprint; int offs; int id; struct Type *ostruct; }


PrintMods

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

result = (_QWORD *)modlist;
if ( modlist )
{
do
result = (_QWORD *)*result;
while ( result );
}
return result;
}

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

result = (_QWORD *)modlist;
if ( modlist )
{
do
result = (_QWORD *)*result;
while ( result );
}
return result;
}

original_code:
void PrintMods()
{
  Module* ml;
  ml = modlist;
  donothing("Loaded Modules\n");
  while (ml != ((void *)0)){
    donothing("mod name: %s\n", ml->name);
    ml = ml->next;
  }
  donothing("end of list\n");
}

canonical_original_code:
void PrintMods()
{
  struct Module *ml;
  ml = modlist;
  donothing("Loaded Modules\n");
  while (ml != ((void *)0)){
    donothing("mod name: %s\n", ml->name);
    ml = ml->next;
  }
  donothing("end of list\n");
}

user_defined_types: struct Type { int size; struct Module *mod; int id; int base[16]; int fields; int ptroffs[1000000]; }


ThisModule

decompiled_code:
__int64 __fastcall ThisModule(char *s2)
{
__int64 i; // r12

for ( i = modlist; i; i = *(_QWORD *)i )
{
if ( !strcmp((const char *)(i + 120), s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2)
{
__int64 i; // r12

for ( i = modlist; i; i = *(_QWORD *)i )
{
if ( !strcmp((const char *)(i + 120), s2) )
break;
}
return i;
}

original_code:
Module* ThisModule(char* name)
{
  Module* ml;
  ml = modlist;
  while ((ml != ((void *)0)) && (strcmp(ml->name, name) != 0)){
    ml = ml->next;
  }
  return ml;
}

canonical_original_code:
struct Module *ThisModule(char *name)
{
  struct Module *ml;
  ml = modlist;
  while ((ml != ((void *)0)) && (strcmp(ml->name, name) != 0)){
    ml = ml->next;
  }
  return ml;
}

variable_types:
name
char *

return_type: struct Module { struct Module *next; int opts; int refcnt; short compTime[6]; int ext; int term; int nofimps; int csize; int code; int procBase; char *names; int *ptrs; struct Module *imports; struct Directory { int num; struct Object { int fprint; int offs; int id; struct Type { int size; struct Module *mod; int id; int base[16]; int fields; int ptroffs[1000000]; } *ostruct; } obj[1000000]; } *export; char name[256]; } *


ThisObject

original_code:
Object* ThisObject(Module* mod, char* name)
{
  int l, r, m;
  char* p;
  l = 0; r = mod->export->num;
  while (l < r){
    m = (l + r) / 2;
    p = (char*) &(mod->names[mod->export->obj[m].id / 256]);
    if (strcmp(p, name) == 0)
      return (Object*)&(mod->export->obj[m]);
    if (strcmp(p, name) < 0)
      l = m + 1;
    else
      r = m;
  }
  return ((void *)0);
}

canonical_original_code:
struct Object *ThisObject(struct Module *mod, char *name)
{
  int l; int r; int m;
  char *p;
  l = 0; r = mod->export->num;
  while (l < r){
    m = (l + r) / 2;
    p = (char *) &(mod->names[mod->export->obj[m].id / 256]);
    if (strcmp(p, name) == 0)
      return (struct Object *)&(mod->export->obj[m]);
    if (strcmp(p, name) < 0)
      l = m + 1;
    else
      r = m;
  }
  return ((void *)0);
}

variable_types:
mod
struct Module *

variable_types: l int

variable_types: r int

variable_types: m int

variable_types:
p
char *

return_type: struct Object { int fprint; int offs; int id; struct Type { int size; struct Module { struct Module *next; int opts; int refcnt; short compTime[6]; int ext; int term; int nofimps; int csize; int code; int procBase; char *names; int *ptrs; struct Module *imports; struct Directory { int num; struct Object obj[1000000]; } *export; char name[256]; } *mod; int id; int base[16]; int fields; int ptroffs[1000000]; } *ostruct; } *


ThisDesc

original_code:
Object* ThisDesc(Module* mod, int fprint)
{
  int i, n;
  i = 0; n = mod->export->num;
  while ((i < n) && (mod->export->obj[i].id / 256 == 0))
    {
      if (mod->export->obj[i].offs == fprint)
 return (Object*)&(mod->export->obj[i]);
      i++;
    }
  return ((void *)0);
}

canonical_original_code:
struct Object *ThisDesc(struct Module *mod, int fprint)
{
  int i; int n;
  i = 0; n = mod->export->num;
  while ((i < n) && (mod->export->obj[i].id / 256 == 0))
    {
      if (mod->export->obj[i].offs == fprint)
 return (struct Object *)&(mod->export->obj[i]);
      i++;
    }
  return ((void *)0);
}

variable_types: fprint int

variable_types: n int


LoadDll

decompiled_code:
__int64 __fastcall LoadDll(const char *a1)
{
char *v2; // rax

if ( !dlopen(a1, 257) )
{
printf("LoadDll: failed to load lib %s\n", a1);
v2 = dlerror();
printf(" - dlerror: %s\n", v2);
exit(-1);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
char *v2; // rax

if ( !dlopen(a1, 257) )
{
printf("LoadDll: failed to load lib %s\n", a1);
v2 = dlerror();
printf(" - dlerror: %s\n", v2);
exit(-1);
}
return 1LL;
}

original_code:
int LoadDll (char* name)
{
  void *handle;
  donothing("loading: %s\n", name);
  if ((handle = dlopen(name, 0x00001 + 0x00100)) == ((void *)0)) {
    printf("LoadDll: failed to load lib %s\n", name);
    printf(" - dlerror: %s\n", dlerror());
    exit(-1);
  }
  return handle != ((void *)0);
}

canonical_original_code:
int LoadDll(char *name)
{
  void *handle;
  donothing("loading: %s\n", name);
  if ((handle = dlopen(name, 0x00001 + 0x00100)) == ((void *)0)) {
    printf("LoadDll: failed to load lib %s\n", name);
    printf(" - dlerror: %s\n", dlerror());
    exit(-1);
  }
  return handle != ((void *)0);
}

variable_types:
handle
void *


ThisDllObj

decompiled_code:
void *__fastcall ThisDllObj(int a1, __int64 a2, const char *a3, const char *a4)
{
void *result; // rax
void *v7; // rdi
char *v8; // rax

if ( (unsigned int)(a1 - 3) > 1 )
return 0LL;
v7 = dlopen(a3, 257);
if ( !v7 )
{
printf("ThisDllObj: lib %s not found\n", a3);
v8 = dlerror();
printf(" - dlerror: %s\n", v8);
exit(-1);
}
result = dlsym(v7, a4);
if ( !(_DWORD)result )
{
printf("ThisDllObj: symbol %s not found\n", a4);
exit(-1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(int a1, __int64 a2, const char *a3, const char *a4)
{
void *result; // rax
void *v7; // rdi
char *v8; // rax

if ( (unsigned int)(a1 - 3) > 1 )
return 0LL;
v7 = dlopen(a3, 257);
if ( !v7 )
{
printf("ThisDllObj: lib %s not found\n", a3);
v8 = dlerror();
printf(" - dlerror: %s\n", v8);
exit(-1);
}
result = dlsym(v7, a4);
if ( !(_DWORD)result )
{
printf("ThisDllObj: symbol %s not found\n", a4);
exit(-1);
}
return result;
}

original_code:
int ThisDllObj (int mode, int fprint, char* dll, char* name)
{
  void *handle;
  int ad = 0;
  if ((mode == 0x3) || (mode == 0x4)){
    if ((handle = dlopen(dll, 0x00001 + 0x00100)) == ((void *)0)) {
      printf("ThisDllObj: lib %s not found\n", dll);
      printf(" - dlerror: %s\n", dlerror());
      exit(-1);
    } else {
      ad = (int)dlsym((void *) handle, name);
      if (ad == 0) {
 printf("ThisDllObj: symbol %s not found\n", name); exit(-1);
      }
    }
  }
  return ad;
 }

canonical_original_code:
int ThisDllObj(int mode, int fprint, char *dll, char *name)
{
  void *handle;
  int ad = 0;
  if ((mode == 0x3) || (mode == 0x4)){
    if ((handle = dlopen(dll, 0x00001 + 0x00100)) == ((void *)0)) {
      printf("ThisDllObj: lib %s not found\n", dll);
      printf(" - dlerror: %s\n", dlerror());
      exit(-1);
    } else {
      ad = (int)dlsym((void *) handle, name);
      if (ad == 0) {
 printf("ThisDllObj: symbol %s not found\n", name); exit(-1);
      }
    }
  }
  return ad;
 }

variable_types: mode int

variable_types:
dll
char *

variable_types: ad int


decompiled_code:
__int64 Read4()
{
unsigned __int8 v0; // bp
int v1; // ebp
int v2; // ebx

v0 = fgetc(f);
v1 = ((unsigned __int8)fgetc(f) << 8) + v0;
v2 = (unsigned __int8)fgetc(f);
return (unsigned int)(v1 + (v2 << 16) + (fgetc(f) << 24));
}

canonical_decompiled_code:
__int64 func9()
{
unsigned __int8 v0; // bp
int v1; // ebp
int v2; // ebx

v0 = fgetc(f);
v1 = ((unsigned __int8)fgetc(f) << 8) + v0;
v2 = (unsigned __int8)fgetc(f);
return (unsigned int)(v1 + (v2 << 16) + (fgetc(f) << 24));
}

original_code:
int Read4 ()
{
  unsigned char b;
  int w;
  b = fgetc(f); w = b % 256;
  b = fgetc(f); w = w + 0x100 * (b % 256);
  b = fgetc(f); w = w + 0x10000 * (b % 256);
  b = fgetc(f); w = w + 0x1000000 * b;
  return w;
}

canonical_original_code:
int Read4()
{
  unsigned char b;
  int w;
  b = fgetc(f); w = b % 256;
  b = fgetc(f); w = w + 0x100 * (b % 256);
  b = fgetc(f); w = w + 0x10000 * (b % 256);
  b = fgetc(f); w = w + 0x1000000 * b;
  return w;
}

variable_types:
b
unsigned char


RNum

variable_types: b char

variable_types: s int

variable_types: y int


Fixup

decompiled_code:
int __fastcall Fixup(const char *a1)
{
int v1; // ebp
int result; // eax
int v3; // ebx
unsigned int v4; // eax
__int64 v5; // rdx
unsigned int v6; // er15
unsigned int *v7; // r9
int v8; // eax
__int64 v9; // rsi
__int64 v10; // rcx
unsigned int *v11; // r14
unsigned int v12; // er13
__int64 v13; // r8
int v14; // eax
unsigned int v15; // [rsp+4h] [rbp-44h]
unsigned int *v16; // [rsp+8h] [rbp-40h]

v1 = (int)a1;
result = ((__int64 (*)(void))RNum)();
if ( result )
{
v3 = result;
while ( 1 )
{
v4 = ((__int64 (*)(void))RNum)();
v5 = v1 + v4;
v6 = v4;
v7 = (unsigned int *)(int)v5;
while ( 2 )
{
v8 = *((_DWORD *)&mod + 68);
if ( v3 > 0 )
{
LABEL_5:
v9 = (unsigned int)v3;
v10 = (unsigned int)(*((_DWORD *)&mod + 72) + v8 + v3);
goto LABEL_6;
}
LABEL_10:
v9 = (unsigned int)-v3;
if ( (int)v9 >= v8 )
v10 = (unsigned int)(*((_DWORD *)&mod + 73) - v3 - v8);
else
v10 = (unsigned int)(*((_DWORD *)&mod + 72) - v3);
LABEL_6:
v11 = (unsigned int *)(int)v10;
v12 = *(_DWORD *)(int)v10;
v13 = (unsigned int)((int)v12 / 0x1000000);
v3 = (int)(v12 + 0x800000) % 0x1000000 - 0x800000;
switch ( (int)v13 )
{
case 'd':
v12 = v5;
goto LABEL_8;
case 'e':
v12 = v5 - v10 - 4;
goto LABEL_8;
case 'f':
v12 = *v7;
goto LABEL_8;
case 'g':
v14 = v1 + v3;
v3 = v9 + 4;
*(_DWORD *)(int)v10 = v14;
continue;
case 'h':
*(_DWORD *)(int)v10 = v1 + v3;
goto LABEL_13;
case 'i':
v12 = v6 + *(_DWORD *)(v1 + 2);
goto LABEL_8;
case 'j':
a1 = "fixup: halfword not implemented";
v16 = v7;
v15 = v5;
puts("fixup: halfword not implemented");
v5 = v15;
v7 = v16;
LABEL_8:
*v11 = v12;
if ( v3 )
{
v8 = *((_DWORD *)&mod + 68);
if ( v3 > 0 )
goto LABEL_5;
goto LABEL_10;
}
LABEL_13:
result = RNum(a1, v9, v5, v10, v13, v7);
v3 = result;
if ( !result )
return result;
break;
default:
return printf("fixup error(link=%d, offset=%d, linkadr=%d, t=%d, x=%d)\n", v9, v6, v10, v13, v12);
}
break;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(const char *a1)
{
int v1; // ebp
int result; // eax
int v3; // ebx
unsigned int v4; // eax
__int64 v5; // rdx
unsigned int v6; // er15
unsigned int *v7; // r9
int v8; // eax
__int64 v9; // rsi
__int64 v10; // rcx
unsigned int *v11; // r14
unsigned int v12; // er13
__int64 v13; // r8
int v14; // eax
unsigned int v15; // [rsp+4h] [rbp-44h]
unsigned int *v16; // [rsp+8h] [rbp-40h]

v1 = (int)a1;
result = ((__int64 (*)(void))RNum)();
if ( result )
{
v3 = result;
while ( 1 )
{
v4 = ((__int64 (*)(void))RNum)();
v5 = v1 + v4;
v6 = v4;
v7 = (unsigned int *)(int)v5;
while ( 2 )
{
v8 = *((_DWORD *)&mod + 68);
if ( v3 > 0 )
{
LABEL_5:
v9 = (unsigned int)v3;
v10 = (unsigned int)(*((_DWORD *)&mod + 72) + v8 + v3);
goto LABEL_6;
}
LABEL_10:
v9 = (unsigned int)-v3;
if ( (int)v9 >= v8 )
v10 = (unsigned int)(*((_DWORD *)&mod + 73) - v3 - v8);
else
v10 = (unsigned int)(*((_DWORD *)&mod + 72) - v3);
LABEL_6:
v11 = (unsigned int *)(int)v10;
v12 = *(_DWORD *)(int)v10;
v13 = (unsigned int)((int)v12 / 0x1000000);
v3 = (int)(v12 + 0x800000) % 0x1000000 - 0x800000;
switch ( (int)v13 )
{
case 'd':
v12 = v5;
goto LABEL_8;
case 'e':
v12 = v5 - v10 - 4;
goto LABEL_8;
case 'f':
v12 = *v7;
goto LABEL_8;
case 'g':
v14 = v1 + v3;
v3 = v9 + 4;
*(_DWORD *)(int)v10 = v14;
continue;
case 'h':
*(_DWORD *)(int)v10 = v1 + v3;
goto LABEL_13;
case 'i':
v12 = v6 + *(_DWORD *)(v1 + 2);
goto LABEL_8;
case 'j':
a1 = "fixup: halfword not implemented";
v16 = v7;
v15 = v5;
puts("fixup: halfword not implemented");
v5 = v15;
v7 = v16;
LABEL_8:
*v11 = v12;
if ( v3 )
{
v8 = *((_DWORD *)&mod + 68);
if ( v3 > 0 )
goto LABEL_5;
goto LABEL_10;
}
LABEL_13:
result = func10(a1, v9, v5, v10, v13, v7);
v3 = result;
if ( !result )
return result;
break;
default:
return printf("fixup error(link=%d, offset=%d, linkadr=%d, t=%d, x=%d)\n", v9, v6, v10, v13, v12);
}
break;
}
}
}
return result;
}

original_code:
void Fixup (int adr)
{
  int link, offset, linkadr, n, x, t;
  donothing("fixup: %X ", adr);
  link = RNum();
  while (link != 0)
    {
      offset = RNum();
      donothing("+%d: ", offset);
      while (link != 0)
 {
   if (link > 0)
     {
       donothing("c");
       linkadr = mod.mad + mod.ms + link;
     }
   else
     {
       donothing("d");
       link = -link;
       if (link < mod.ms)
  linkadr = mod.mad + link;
       else
  linkadr = mod.dad + link - mod.ms;
     }
   donothing("%X ", link);
   x = *(int*)linkadr;
   t = x / 0x1000000;
   n = (x + 0x800000) % 0x1000000 - 0x800000;
   switch (t) {
   case 100: x = adr + offset; break;
   case 101: x = adr + offset - linkadr -4; break;
   case 102: x = *(int*)(adr + offset); break;
   case 103: x = adr + n; n = link + 4; break;
   case 104: x = adr + n; n = 0; break;
   case 105: x = *(int*)(adr + 2); x = x + offset; break;
   case 106:
     printf("fixup: halfword not implemented\n");
     break;
   default:
     printf("fixup error(link=%d, offset=%d, linkadr=%d, t=%d, x=%d)\n",
     link, offset, linkadr, t, x);
     return;
   }
   *(int*)linkadr = x;
   link = n;
 }
      link = RNum();
    }
  donothing("\n");
}

canonical_original_code:
void Fixup(int adr)
{
  int link; int offset; int linkadr; int n; int x; int t;
  donothing("fixup: %X ", adr);
  link = RNum();
  while (link != 0)
    {
      offset = RNum();
      donothing("+%d: ", offset);
      while (link != 0)
 {
   if (link > 0)
     {
       donothing("c");
       linkadr = mod.mad + mod.ms + link;
     }
   else
     {
       donothing("d");
       link = -link;
       if (link < mod.ms)
  linkadr = mod.mad + link;
       else
  linkadr = mod.dad + link - mod.ms;
     }
   donothing("%X ", link);
   x = *(int *)linkadr;
   t = x / 0x1000000;
   n = (x + 0x800000) % 0x1000000 - 0x800000;
   switch (t) {
   case 100: x = adr + offset; break;
   case 101: x = adr + offset - linkadr -4; break;
   case 102: x = *(int *)(adr + offset); break;
   case 103: x = adr + n; n = link + 4; break;
   case 104: x = adr + n; n = 0; break;
   case 105: x = *(int *)(adr + 2); x = x + offset; break;
   case 106:
     printf("fixup: halfword not implemented\n");
     break;
   default:
     printf("fixup error(link=%d, offset=%d, linkadr=%d, t=%d, x=%d)\n",
     link, offset, linkadr, t, x);
     return;
   }
   *(int *)linkadr = x;
   link = n;
 }
      link = RNum();
    }
  donothing("\n");
}

variable_types: adr int

variable_types: link int

variable_types: offset int

variable_types: linkadr int

variable_types: x int

variable_types: t int


ReadBootHeader

decompiled_code:
__int64 ReadBootHeader()
{
int v0; // ebx
int v1; // eax
int v2; // eax
int v3; // eax

fseek(f, 21399LL, 0);
v0 = Read4();
v1 = Read4();
if ( v0 != 978017389 || v1 )
return 0LL;
nofMods = Read4();
ReadName(kernel);
ReadName(mainmod);
v2 = Read4();
newRecAdr = 0;
newRecFP = v2;
v3 = Read4();
newArrAdr = 0;
newArrFP = v3;
*((_DWORD *)&mod + 66) = ftell(f);
return 1LL;
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // ebx
int v1; // eax
int v2; // eax
int v3; // eax

fseek(f, 21399LL, 0);
v0 = func9();
v1 = func9();
if ( v0 != 978017389 || v1 )
return 0LL;
nofMods = func9();
func11(kernel);
func11(mainmod);
v2 = func9();
newRecAdr = 0;
newRecFP = v2;
v3 = func9();
newArrAdr = 0;
newArrFP = v3;
*((_DWORD *)&mod + 66) = ftell(f);
return 1LL;
}

original_code:
int ReadBootHeader()
{
  int tag, version;
  fseek(f, 21399, 0);
  tag = Read4();
  version = Read4();
  if ((tag != 0x3A4B5C6D) || (version != 0))
    {
      return 0;
    }
  nofMods = Read4();
  donothing("Linked modules: %d\n", nofMods);
  ReadName(kernel);
  donothing("kernel: %s\n", kernel);
  ReadName(mainmod);
  donothing("main: %s\n", mainmod);
  newRecFP = Read4(); newRecAdr = 0;
  newArrFP = Read4(); newArrAdr = 0;
  mod.start = ftell(f);
  return 1;
}

canonical_original_code:
int ReadBootHeader()
{
  int tag; int version;
  fseek(f, 21399, 0);
  tag = Read4();
  version = Read4();
  if ((tag != 0x3A4B5C6D) || (version != 0))
    {
      return 0;
    }
  nofMods = Read4();
  donothing("Linked modules: %d\n", nofMods);
  ReadName(kernel);
  donothing("kernel: %s\n", kernel);
  ReadName(mainmod);
  donothing("main: %s\n", mainmod);
  newRecFP = Read4(); newRecAdr = 0;
  newArrFP = Read4(); newArrAdr = 0;
  mod.start = ftell(f);
  return 1;
}

variable_types: tag int

variable_types: version int


ReadHeader

decompiled_code:
__int64 __fastcall ReadHeader(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9
int v9; // er14
int v10; // ebp
bool v11; // zf
_QWORD *v12; // r13
_BYTE *v13; // rax
char *v14; // r12

if ( (unsigned int)Read4() != 1867465542 )
{
v3 = 0;
puts("wrong object file version");
return v3;
}
Read4();
*((_DWORD *)&mod + 67) = Read4();
*((_DWORD *)&mod + 68) = Read4();
*((_DWORD *)&mod + 69) = Read4();
*((_DWORD *)&mod + 70) = Read4();
*((_DWORD *)&mod + 71) = Read4();
v9 = RNum(a1, a2, v5, v6, v7, v8);
ReadName((_BYTE *)(unsigned int)((_DWORD)&mod + 8));
mod = 0LL;
if ( v9 <= 0 )
{
LABEL_14:
ftell(f);
return 1LL;
}
v10 = 0;
while ( 1 )
{
v12 = (_QWORD *)v2;
v13 = calloc(1uLL, 0x108uLL);
v14 = v13 + 8;
v2 = (__int64)v13;
ReadName(v13 + 8);
if ( !mod )
break;
*v12 = v2;
v11 = *(_WORD *)(v2 + 8) == 9252;
*(_QWORD *)v2 = 0LL;
if ( v11 )
goto LABEL_11;
LABEL_7:
if ( *(_BYTE *)(v2 + 8) == 36 )
goto LABEL_12;
LABEL_8:
if ( v9 == ++v10 )
goto LABEL_14;
}
v11 = *(_WORD *)(v2 + 8) == 9252;
mod = v2;
*(_QWORD *)v2 = 0LL;
if ( !v11 )
goto LABEL_7;
LABEL_11:
*(_DWORD *)(v2 + 8) = 1852990795;
strcpy(v14 + 4, "el");
if ( *(_BYTE *)(v2 + 8) != 36 )
goto LABEL_8;
LABEL_12:
v3 = LoadDll((const char *)(v2 + 9));
if ( v3 )
goto LABEL_8;
printf("Could not load lib: %s\n", (const char *)(unsigned int)*(char *)(v2 + 9));
return v3;
}

original_code:
int ReadHeader ()
{
  int ofTag, i, nofImps, processor;
  char str[80];
  ImpList *imp, *last;
  char* n;
  ofTag = Read4();
  if (ofTag != 0x6F4F4346)
    {
      printf("wrong object file version\n");
      return 0;
    }
  processor = Read4();
  mod.hs = Read4();
  mod.ms = Read4();
  mod.ds = Read4();
  mod.cs = Read4();
  mod.vs = Read4();
  donothing("File tag: %d ", ofTag); donothing("Processor: %d\n", processor);
  donothing("Header size: %d ", mod.hs);
  donothing("Meta size: %d ", mod.ms);
  donothing("Desc size: %d ", mod.ds );
  donothing("Code size: %d ", mod.cs);
  donothing("Data size: %d\n", mod.vs);
  nofImps = RNum(); donothing("Nof imports: %d\n", nofImps);
  ReadName(mod.name); donothing("Module name: %s\n", mod.name);
  mod.imp = ((void *)0);
  for (i = 0; i < nofImps; i++)
    {
      imp = (ImpList*)calloc(1, sizeof(ImpList));
      ReadName(imp->name);
      if (mod.imp == ((void *)0))
 mod.imp = imp;
      else
 last->next = imp;
      last = imp;
      last->next = ((void *)0);
      donothing("Import %d: %s\n", i, imp->name);
      if ((imp->name[0] == '$') && (imp->name[1] == '$'))
 strcpy(imp->name, "Kernel");
      if (imp->name[0] == '$'){
 n = imp->name;
 n++;
 if (!LoadDll(n)){
   printf("Could not load lib: %s\n", imp->name[1]);
   return 0;
 }
      }
    }
  donothing("Pos: %d\n", ftell(f));
  return 1;
}

canonical_original_code:
int ReadHeader()
{
  int ofTag; int i; int nofImps; int processor;
  char str[80];
  struct ImpList *imp; struct ImpList *last;
  char *n;
  ofTag = Read4();
  if (ofTag != 0x6F4F4346)
    {
      printf("wrong object file version\n");
      return 0;
    }
  processor = Read4();
  mod.hs = Read4();
  mod.ms = Read4();
  mod.ds = Read4();
  mod.cs = Read4();
  mod.vs = Read4();
  donothing("File tag: %d ", ofTag); donothing("Processor: %d\n", processor);
  donothing("Header size: %d ", mod.hs);
  donothing("Meta size: %d ", mod.ms);
  donothing("Desc size: %d ", mod.ds );
  donothing("Code size: %d ", mod.cs);
  donothing("Data size: %d\n", mod.vs);
  nofImps = RNum(); donothing("Nof imports: %d\n", nofImps);
  ReadName(mod.name); donothing("Module name: %s\n", mod.name);
  mod.imp = ((void *)0);
  for (i = 0; i < nofImps; i++)
    {
      imp = (struct ImpList *)calloc(1, sizeof(ImpList));
      ReadName(imp->name);
      if (mod.imp == ((void *)0))
 mod.imp = imp;
      else
 last->next = imp;
      last = imp;
      last->next = ((void *)0);
      donothing("Import %d: %s\n", i, imp->name);
      if ((imp->name[0] == '$') && (imp->name[1] == '$'))
 strcpy(imp->name, "Kernel");
      if (imp->name[0] == '$'){
 n = imp->name;
 n++;
 if (!LoadDll(n)){
   printf("Could not load lib: %s\n", imp->name[1]);
   return 0;
 }
      }
    }
  donothing("Pos: %d\n", ftell(f));
  return 1;
}

variable_types: ofTag int

variable_types: i int

variable_types: nofImps int

variable_types: processor int

variable_types:
str
char [80]

variable_types: struct ImpList { struct ImpList *next; char name[256]; } *

variable_types:
n
char *


ReadModule

decompiled_code:
__int64 __fastcall ReadModule()
{
__int64 v0; // rbp
unsigned int v1; // eax
int v2; // esi
signed int v3; // ebx
unsigned int v4; // eax
signed int v5; // er12
const char *v6; // rsi
unsigned int v7; // er12
__int64 v8; // rdi
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
__int64 v13; // r13
unsigned int v14; // er15
unsigned int v15; // er12
_DWORD *v16; // rdx
__int64 v17; // r8
__int64 v18; // r9
__int64 v19; // rcx
int v20; // ebx
__int64 v21; // rdx
__int64 v22; // rcx
__int64 v23; // r8
__int64 v24; // r9
unsigned int v25; // eax
unsigned int v26; // er14
__int64 v27; // rdx
__int64 v28; // rcx
__int64 v29; // r8
__int64 v30; // r9
__int64 v31; // rax
__int64 v32; // rbx
__int64 v33; // rax
__int64 v34; // rax
unsigned int v35; // eax
__int64 v36; // rdx
__int64 v37; // rcx
__int64 v38; // r8
__int64 v39; // r9
int v40; // eax
_DWORD *v42; // [rsp+8h] [rbp-150h]
_DWORD *v43; // [rsp+18h] [rbp-140h]
char v44[312]; // [rsp+20h] [rbp-138h] BYREF

v1 = (unsigned int)calloc(1uLL, *((int *)&mod + 69));
v2 = *((_DWORD *)&mod + 71) + *((_DWORD *)&mod + 68) + *((_DWORD *)&mod + 70);
*((_DWORD *)&mod + 73) = v1;
v3 = v1;
v4 = (unsigned int)calloc(1uLL, v2);
*((_DWORD *)&mod + 72) = v4;
if ( !v4 || !v3 )
{
v15 = 0;
puts("BootLoader: Couldn't initalize heap");
free((void *)*((int *)&mod + 73));
free((void *)*((int *)&mod + 72));
return v15;
}
v5 = v4;
fseek(f, *((_DWORD *)&mod + 66) + *((_DWORD *)&mod + 67), 0);
ftell(f);
fread((void *)v5, 1uLL, *((int *)&mod + 68), f);
ftell(f);
fread((void *)v3, 1uLL, *((int *)&mod + 69), f);
ftell(f);
v6 = byte_1;
fread((void *)(*((_DWORD *)&mod + 72) + *((_DWORD *)&mod + 68)), 1uLL, *((int *)&mod + 70), f);
ftell(f);
ftell(f);
v7 = newRecAdr;
if ( !newRecAdr || !newArrAdr )
{
v31 = ThisModule(kernel);
v32 = v31;
if ( v31 )
{
v33 = ThisObject(v31, "NewRec");
if ( v33 )
{
v7 = *(_DWORD *)(v32 + 80) + *(_DWORD *)(v33 + 4);
newRecAdr = v7;
}
v6 = "NewArr";
v34 = ThisObject(v32, "NewArr");
if ( v34 )
newArrAdr = *(_DWORD *)(v32 + 80) + *(_DWORD *)(v34 + 4);
}
}
Fixup((const char *)v7);
Fixup((const char *)(unsigned int)newArrAdr);
Fixup((const char *)*((unsigned int *)&mod + 72));
Fixup((const char *)*((unsigned int *)&mod + 73));
Fixup((const char *)(unsigned int)(*((_DWORD *)&mod + 72) + *((_DWORD *)&mod + 68)));
Fixup((const char *)(unsigned int)(*((_DWORD *)&mod + 70) + *((_DWORD *)&mod + 72) + *((_DWORD *)&mod + 68)));
v8 = (__int64)f;
ftell(f);
v13 = mod;
if ( mod )
{
v43 = (_DWORD *)(int)*(_QWORD *)((char *)&loc_66 + *((int *)&mod + 73) + 2);
while ( 1 )
{
v14 = RNum(v8, v6, v9, v10, v11, v12);
if ( *(_WORD *)(v13 + 8) == 9252 )
{
v8 = (__int64)"should be Kerneln";
printf("should be Kerneln");
}
v15 = 1;
if ( *(_BYTE *)(v13 + 8) != 36 )
{
v8 = v13 + 8;
v0 = ThisModule((char *)(v13 + 8));
if ( !v0 )
{
v15 = 0;
puts("invalid import list");
return v15;
}
v15 = 0;
}
if ( v14 )
break;
LABEL_36:
v13 = *(_QWORD *)v13;
*v43++ = v0;
if ( !v13 )
goto LABEL_37;
}
while ( 1 )
{
while ( 1 )
{
v8 = (__int64)v44;
ReadName(v44);
v25 = RNum(v44, v6, v21, v22, v23, v24);
v26 = v25;
if ( v15 )
break;
if ( v44[0] )
{
v6 = v44;
v8 = v0;
v16 = (_DWORD *)ThisObject(v0, v44);
}
else
{
v6 = (const char *)v25;
v8 = v0;
v16 = (_DWORD *)ThisDesc(v0, v25);
}
if ( !v16 )
ReadModule_cold();
v19 = (unsigned int)((int)v16[2] >> 31) >> 28;
if ( v16[2] % 16 != v14 )
{
printf("descriptor not found (%s, x: %d, id: %d)\n", v44, v14, (unsigned int)v16[2]);
return v15;
}
v20 = *v16;
if ( v14 == 3 )
{
v8 = (unsigned int)(*(_DWORD *)(v0 + 84) + v16[1]);
Fixup((const char *)v8);
if ( v20 != v26 )
{
LABEL_39:
printf("illigal foot print (%s)\n", (const char *)(v13 + 8));
return v15;
}
}
else
{
if ( v14 == 4 )
{
v8 = (unsigned int)(*(_DWORD *)(v0 + 80) + v16[1]);
Fixup((const char *)v8);
}
else if ( v14 == 2 )
{
v42 = v16;
v40 = RNum(v8, v6, v16, v19, v17, v18);
v6 = (const char *)((unsigned int)v40 >> 31);
if ( v40 % 2 == 1 )
v20 = v42[1];
if ( v40 > 1 && ((v42[2] / 16) & 0x8000000F) != 4 )
{
printf("object not found (%s)\n", (const char *)(v13 + 8));
return v15;
}
v8 = *((_QWORD *)v42 + 2);
Fixup((const char *)v8);
}
if ( v20 != v26 )
goto LABEL_39;
}
LABEL_22:
v14 = RNum(v8, v6, v16, v19, v17, v18);
if ( !v14 )
goto LABEL_36;
}
if ( v14 - 3 > 1 )
{
if ( v14 == 2 )
{
RNum(v44, v6, v16, v19, v17, v18);
if ( (unsigned int)RNum(v44, v6, v27, v28, v29, v30) )
{
LABEL_27:
v15 = 0;
printf("ReadModule: Object not found: %s\n", v44);
return v15;
}
}
goto LABEL_22;
}
v6 = (const char *)v25;
v35 = (unsigned int)ThisDllObj(v14, v25, (const char *)(v13 + 9), v44);
v8 = v35;
if ( !v35 )
goto LABEL_27;
Fixup((const char *)v35);
v14 = RNum(v8, v26, v36, v37, v38, v39);
if ( !v14 )
goto LABEL_36;
}
}
LABEL_37:
v15 = 1;
*((_DWORD *)&mod + 66) = ftell(f);
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func15()
{
__int64 v0; // rbp
unsigned int v1; // eax
int v2; // esi
signed int v3; // ebx
unsigned int v4; // eax
signed int v5; // er12
const char *v6; // rsi
unsigned int v7; // er12
__int64 v8; // rdi
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
__int64 v13; // r13
unsigned int v14; // er15
unsigned int v15; // er12
_DWORD *v16; // rdx
__int64 v17; // r8
__int64 v18; // r9
__int64 v19; // rcx
int v20; // ebx
__int64 v21; // rdx
__int64 v22; // rcx
__int64 v23; // r8
__int64 v24; // r9
unsigned int v25; // eax
unsigned int v26; // er14
__int64 v27; // rdx
__int64 v28; // rcx
__int64 v29; // r8
__int64 v30; // r9
__int64 v31; // rax
__int64 v32; // rbx
__int64 v33; // rax
__int64 v34; // rax
unsigned int v35; // eax
__int64 v36; // rdx
__int64 v37; // rcx
__int64 v38; // r8
__int64 v39; // r9
int v40; // eax
_DWORD *v42; // [rsp+8h] [rbp-150h]
_DWORD *v43; // [rsp+18h] [rbp-140h]
char v44[312]; // [rsp+20h] [rbp-138h] BYREF

v1 = (unsigned int)calloc(1uLL, *((int *)&mod + 69));
v2 = *((_DWORD *)&mod + 71) + *((_DWORD *)&mod + 68) + *((_DWORD *)&mod + 70);
*((_DWORD *)&mod + 73) = v1;
v3 = v1;
v4 = (unsigned int)calloc(1uLL, v2);
*((_DWORD *)&mod + 72) = v4;
if ( !v4 || !v3 )
{
v15 = 0;
puts("BootLoader: Couldn't initalize heap");
free((void *)*((int *)&mod + 73));
free((void *)*((int *)&mod + 72));
return v15;
}
v5 = v4;
fseek(f, *((_DWORD *)&mod + 66) + *((_DWORD *)&mod + 67), 0);
ftell(f);
fread((void *)v5, 1uLL, *((int *)&mod + 68), f);
ftell(f);
fread((void *)v3, 1uLL, *((int *)&mod + 69), f);
ftell(f);
v6 = byte_1;
fread((void *)(*((_DWORD *)&mod + 72) + *((_DWORD *)&mod + 68)), 1uLL, *((int *)&mod + 70), f);
ftell(f);
ftell(f);
v7 = newRecAdr;
if ( !newRecAdr || !newArrAdr )
{
v31 = func4(kernel);
v32 = v31;
if ( v31 )
{
v33 = func5(v31, "NewRec");
if ( v33 )
{
v7 = *(_DWORD *)(v32 + 80) + *(_DWORD *)(v33 + 4);
newRecAdr = v7;
}
v6 = "NewArr";
v34 = func5(v32, "NewArr");
if ( v34 )
newArrAdr = *(_DWORD *)(v32 + 80) + *(_DWORD *)(v34 + 4);
}
}
func12((const char *)v7);
func12((const char *)(unsigned int)newArrAdr);
func12((const char *)*((unsigned int *)&mod + 72));
func12((const char *)*((unsigned int *)&mod + 73));
func12((const char *)(unsigned int)(*((_DWORD *)&mod + 72) + *((_DWORD *)&mod + 68)));
func12((const char *)(unsigned int)(*((_DWORD *)&mod + 70) + *((_DWORD *)&mod + 72) + *((_DWORD *)&mod + 68)));
v8 = (__int64)f;
ftell(f);
v13 = mod;
if ( mod )
{
v43 = (_DWORD *)(int)*(_QWORD *)((char *)&loc_66 + *((int *)&mod + 73) + 2);
while ( 1 )
{
v14 = func10(v8, v6, v9, v10, v11, v12);
if ( *(_WORD *)(v13 + 8) == 9252 )
{
v8 = (__int64)"should be Kerneln";
printf("should be Kerneln");
}
v15 = 1;
if ( *(_BYTE *)(v13 + 8) != 36 )
{
v8 = v13 + 8;
v0 = func4((char *)(v13 + 8));
if ( !v0 )
{
v15 = 0;
puts("invalid import list");
return v15;
}
v15 = 0;
}
if ( v14 )
break;
LABEL_36:
v13 = *(_QWORD *)v13;
*v43++ = v0;
if ( !v13 )
goto LABEL_37;
}
while ( 1 )
{
while ( 1 )
{
v8 = (__int64)v44;
func11(v44);
v25 = func10(v44, v6, v21, v22, v23, v24);
v26 = v25;
if ( v15 )
break;
if ( v44[0] )
{
v6 = v44;
v8 = v0;
v16 = (_DWORD *)func5(v0, v44);
}
else
{
v6 = (const char *)v25;
v8 = v0;
v16 = (_DWORD *)func6(v0, v25);
}
if ( !v16 )
func16();
v19 = (unsigned int)((int)v16[2] >> 31) >> 28;
if ( v16[2] % 16 != v14 )
{
printf("descriptor not found (%s, x: %d, id: %d)\n", v44, v14, (unsigned int)v16[2]);
return v15;
}
v20 = *v16;
if ( v14 == 3 )
{
v8 = (unsigned int)(*(_DWORD *)(v0 + 84) + v16[1]);
func12((const char *)v8);
if ( v20 != v26 )
{
LABEL_39:
printf("illigal foot print (%s)\n", (const char *)(v13 + 8));
return v15;
}
}
else
{
if ( v14 == 4 )
{
v8 = (unsigned int)(*(_DWORD *)(v0 + 80) + v16[1]);
func12((const char *)v8);
}
else if ( v14 == 2 )
{
v42 = v16;
v40 = func10(v8, v6, v16, v19, v17, v18);
v6 = (const char *)((unsigned int)v40 >> 31);
if ( v40 % 2 == 1 )
v20 = v42[1];
if ( v40 > 1 && ((v42[2] / 16) & 0x8000000F) != 4 )
{
printf("object not found (%s)\n", (const char *)(v13 + 8));
return v15;
}
v8 = *((_QWORD *)v42 + 2);
func12((const char *)v8);
}
if ( v20 != v26 )
goto LABEL_39;
}
LABEL_22:
v14 = func10(v8, v6, v16, v19, v17, v18);
if ( !v14 )
goto LABEL_36;
}
if ( v14 - 3 > 1 )
{
if ( v14 == 2 )
{
func10(v44, v6, v16, v19, v17, v18);
if ( (unsigned int)func10(v44, v6, v27, v28, v29, v30) )
{
LABEL_27:
v15 = 0;
printf("ReadModule: Object not found: %s\n", v44);
return v15;
}
}
goto LABEL_22;
}
v6 = (const char *)v25;
v35 = (unsigned int)func8(v14, v25, (const char *)(v13 + 9), v44);
v8 = v35;
if ( !v35 )
goto LABEL_27;
func12((const char *)v35);
v14 = func10(v8, v26, v36, v37, v38, v39);
if ( !v14 )
goto LABEL_36;
}
}
LABEL_37:
v15 = 1;
*((_DWORD *)&mod + 66) = ftell(f);
return v15;
}

original_code:
int ReadModule ()
{
  char *dp, *mp;
  unsigned int cnt;
  ImpList* imp;
  int x, fp, opt, link, ofp, imptab, a;
  Module *desc, *k;
  String name;
  Object* obj;
  int isLib;
  char* im;
  mod.dad = (int) calloc(1, mod.ds);
  mod.mad = (int) calloc(1, mod.ms + mod.cs + mod.vs);
  if ((mod.dad == 0) || (mod.mad == 0))
    {
      printf("BootLoader: Couldn't initalize heap\n");
      free((void*)mod.dad);
      free((void*)mod.mad);
      return 0;
    }
  dp = (char*) mod.dad;
  mp = (char*) mod.mad;
  fseek(f, mod.start + mod.hs, 0);
  donothing("ReadModule after fseek pos: %d\n", ftell(f));
  cnt = fread(mp, 1, mod.ms, f);
  donothing("Read meta bulk (%d bytes. New pos: %d)\n", cnt, ftell(f));
  cnt = fread(dp, 1, mod.ds, f);
  donothing("Read desc bulk (%d bytes. New pos: %d)\n", cnt, ftell(f));
  mp = (char*)(mod.mad + mod.ms);
  cnt = fread(mp, 1, mod.cs, f);
  donothing("Read code bulk (%d bytes. New pos: %d)\n", cnt, ftell(f));
  DumpMod();
  donothing("before fixup: pos = %d\n", ftell(f));
  if ((!newRecAdr) || (!newArrAdr)){
    k = ThisModule(kernel);
    if (k != ((void *)0)){
      obj = ThisObject(k, "NewRec");
      if (obj != ((void *)0))
 newRecAdr = k->procBase + obj->offs;
      obj = ThisObject(k, "NewArr");
      if (obj != ((void *)0))
 newArrAdr = k->procBase + obj->offs;
      donothing("newRecFP: %X  newArrFP: %X\n", newRecFP, newArrFP);
      donothing("newRecAdr: %X  newArrAdr: %X\n", newRecAdr, newArrAdr);
    } else {
      donothing("no kernel before %s.\n", mod.name);
    }
  }
  Fixup(newRecAdr);
  Fixup(newArrAdr);
  Fixup(mod.mad);
  Fixup(mod.dad);
  Fixup(mod.mad + mod.ms);
  Fixup(mod.mad + mod.ms + mod.cs);
  donothing("after fixup: pos = %d\n", ftell(f));
  imp = mod.imp; imptab = (int)((Module*)(mod.dad))->imports;
  while (imp != ((void *)0)){
    x = RNum();
    if ((imp->name[0] == '$') && (imp->name[1] == '$'))
      printf("should be Kerneln");
    if (imp->name[0] == '$')
      isLib = 1;
    else{
      isLib = 0;
      desc = ThisModule(imp->name);
      if (desc == ((void *)0)){
 printf("invalid import list\n");
 return 0;
      }
    }
    while (x != 0) {
      ReadName(name); fp = RNum(); opt = 0;
      if (!isLib) {
 if (name[0] == 0)
   obj = ThisDesc(desc, fp);
 else
   obj = ThisObject(desc, name);
 if ((obj != ((void *)0)) && (obj->id % 16 == x)){
   ofp = obj->fprint;
   switch (x){
   case 0x2:
     opt = RNum();
     if (opt % 2 == 1) ofp = obj->offs;
     if ((opt > 1) && ((obj->id / 16) % 16 != 4)){
       printf("object not found (%s)\n", imp->name);
       return 0;
  }
     Fixup((int)obj->ostruct);
     break;
   case 0x3:
     Fixup(desc->varBase + obj->offs);
     break;
   case 0x4:
     Fixup(desc->procBase + obj->offs);
   }
   if (ofp != fp){
     printf("illigal foot print (%s)\n", imp->name);
     return 0;
   }
 } else {
   if (obj == ((void *)0)) printf("obj == NULL\n");
   printf("descriptor not found (%s, x: %d, id: %d)\n", name, x, obj->id);
   return 0;
 }
      }else{
 if ((x == 0x3) || (x == 0x4)){
   im = imp->name;
   im++;
   a = ThisDllObj(x, fp, im, name);
   if (a != 0)
     Fixup(a);
   else{
     printf("ReadModule: Object not found: %s\n", name);
     return 0;
   }
 } else {
   if (x == 0x2) {
     opt = RNum();
     x = RNum();
     if (x != 0) {
       printf("ReadModule: Object not found: %s\n", name);
       return 0;
     }
   }
 }
      }
      x = RNum();
    }
    *(int*)imptab = (int)desc; imptab += 4;
    imp = imp->next;
  }
  mod.start = ftell(f);
  return 1;
}

canonical_original_code:
int ReadModule()
{
  char *dp; char *mp;
  unsigned int cnt;
  struct ImpList *imp;
  int x; int fp; int opt; int link; int ofp; int imptab; int a;
  struct Module *desc; struct Module *k;
  char name[256];
  struct Object *obj;
  int isLib;
  char *im;
  mod.dad = (int) calloc(1, mod.ds);
  mod.mad = (int) calloc(1, mod.ms + mod.cs + mod.vs);
  if ((mod.dad == 0) || (mod.mad == 0))
    {
      printf("BootLoader: Couldn't initalize heap\n");
      free((void *)mod.dad);
      free((void *)mod.mad);
      return 0;
    }
  dp = (char *) mod.dad;
  mp = (char *) mod.mad;
  fseek(f, mod.start + mod.hs, 0);
  donothing("ReadModule after fseek pos: %d\n", ftell(f));
  cnt = fread(mp, 1, mod.ms, f);
  donothing("Read meta bulk (%d bytes. New pos: %d)\n", cnt, ftell(f));
  cnt = fread(dp, 1, mod.ds, f);
  donothing("Read desc bulk (%d bytes. New pos: %d)\n", cnt, ftell(f));
  mp = (char *)(mod.mad + mod.ms);
  cnt = fread(mp, 1, mod.cs, f);
  donothing("Read code bulk (%d bytes. New pos: %d)\n", cnt, ftell(f));
  DumpMod();
  donothing("before fixup: pos = %d\n", ftell(f));
  if ((!newRecAdr) || (!newArrAdr)){
    k = ThisModule(kernel);
    if (k != ((void *)0)){
      obj = ThisObject(k, "NewRec");
      if (obj != ((void *)0))
 newRecAdr = k->procBase + obj->offs;
      obj = ThisObject(k, "NewArr");
      if (obj != ((void *)0))
 newArrAdr = k->procBase + obj->offs;
      donothing("newRecFP: %X  newArrFP: %X\n", newRecFP, newArrFP);
      donothing("newRecAdr: %X  newArrAdr: %X\n", newRecAdr, newArrAdr);
    } else {
      donothing("no kernel before %s.\n", mod.name);
    }
  }
  Fixup(newRecAdr);
  Fixup(newArrAdr);
  Fixup(mod.mad);
  Fixup(mod.dad);
  Fixup(mod.mad + mod.ms);
  Fixup(mod.mad + mod.ms + mod.cs);
  donothing("after fixup: pos = %d\n", ftell(f));
  imp = mod.imp; imptab = (int)((struct Module *)(mod.dad))->imports;
  while (imp != ((void *)0)){
    x = RNum();
    if ((imp->name[0] == '$') && (imp->name[1] == '$'))
      printf("should be Kerneln");
    if (imp->name[0] == '$')
      isLib = 1;
    else{
      isLib = 0;
      desc = ThisModule(imp->name);
      if (desc == ((void *)0)){
 printf("invalid import list\n");
 return 0;
      }
    }
    while (x != 0) {
      ReadName(name); fp = RNum(); opt = 0;
      if (!isLib) {
 if (name[0] == 0)
   obj = ThisDesc(desc, fp);
 else
   obj = ThisObject(desc, name);
 if ((obj != ((void *)0)) && (obj->id % 16 == x)){
   ofp = obj->fprint;
   switch (x){
   case 0x2:
     opt = RNum();
     if (opt % 2 == 1) ofp = obj->offs;
     if ((opt > 1) && ((obj->id / 16) % 16 != 4)){
       printf("object not found (%s)\n", imp->name);
       return 0;
  }
     Fixup((int)obj->ostruct);
     break;
   case 0x3:
     Fixup(desc->varBase + obj->offs);
     break;
   case 0x4:
     Fixup(desc->procBase + obj->offs);
   }
   if (ofp != fp){
     printf("illigal foot print (%s)\n", imp->name);
     return 0;
   }
 } else {
   if (obj == ((void *)0)) printf("obj == NULL\n");
   printf("descriptor not found (%s, x: %d, id: %d)\n", name, x, obj->id);
   return 0;
 }
      }else{
 if ((x == 0x3) || (x == 0x4)){
   im = imp->name;
   im++;
   a = ThisDllObj(x, fp, im, name);
   if (a != 0)
     Fixup(a);
   else{
     printf("ReadModule: Object not found: %s\n", name);
     return 0;
   }
 } else {
   if (x == 0x2) {
     opt = RNum();
     x = RNum();
     if (x != 0) {
       printf("ReadModule: Object not found: %s\n", name);
       return 0;
     }
   }
 }
      }
      x = RNum();
    }
    *(int *)imptab = (int)desc; imptab += 4;
    imp = imp->next;
  }
  mod.start = ftell(f);
  return 1;
}

variable_types:
dp
char *

variable_types:
mp
char *

variable_types:
cnt
unsigned int

variable_types: fp int

variable_types: opt int

variable_types: ofp int

variable_types: imptab int

variable_types: a int

variable_types: struct Module { struct Module *next; int opts; int refcnt; short compTime[6]; int ext; int term; int nofimps; int csize; int code; int procBase; char *names; int *ptrs; struct Module *imports; struct Directory { int num; struct Object { int fprint; int offs; int id; struct Type { int size; struct Module *mod; int id; int base[16]; int fields; int ptroffs[1000000]; } *ostruct; } obj[1000000]; } *export; char name[256]; } *

variable_types:
name
char [256]

variable_types: struct Object { int fprint; int offs; int id; struct Type { int size; struct Module { struct Module *next; int opts; int refcnt; short compTime[6]; int ext; int term; int nofimps; int csize; int code; int procBase; char *names; int *ptrs; struct Module *imports; struct Directory { int num; struct Object obj[1000000]; } *export; char name[256]; } *mod; int id; int base[16]; int fields; int ptroffs[1000000]; } *ostruct; } *

variable_types: isLib int

variable_types:
im
char *

user_defined_types: struct ImpList { struct ImpList *next; char name[256]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rdi
int v5; // er12
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // r13
_DWORD *v9; // rax
__int64 v10; // rdx
_DWORD *v11; // rdx
void (*v12)(void); // rdx

v4 = *argv;
modlist = 0LL;
f = fopen(v4, "r");
if ( f )
{
if ( (unsigned int)ReadBootHeader() )
{
v5 = 0;
if ( nofMods <= 0 )
{
LABEL_7:
fclose(f);
v6 = ThisModule(kernel);
v7 = ThisModule(mainmod);
v8 = v7;
if ( v6 )
{
if ( v7 )
{
v9 = calloc(1uLL, 0x18uLL);
v10 = modlist;
v9[2] = argc;
*(_QWORD *)v9 = v10;
v11 = (_DWORD *)*(int *)(v6 + 84);
*((_QWORD *)v9 + 2) = argv;
bootInfo = (__int64)v9;
*v11 = (_DWORD)v9;
v12 = (void (*)(void))*(int *)(v8 + 68);
*(_DWORD *)(v6 + 8) |= 0x10000u;
v12();
}
else
{
printf("no main module");
}
}
else
{
puts("no kernel");
}
PrintMods();
}
else
{
while ( 1 )
{
if ( !(unsigned int)ReadHeader((__int64)v4, (__int64)"r") )
{
printf("Incorrect header: %s\n", (const char *)(unsigned int)((_DWORD)&mod + 8));
goto LABEL_14;
}
if ( !(unsigned int)ReadModule() )
break;
++v5;
RegisterModule();
if ( nofMods <= v5 )
goto LABEL_7;
}
printf("Incorrect module: %s\n", (const char *)(unsigned int)((_DWORD)&mod + 8));
LABEL_14:
fclose(f);
}
}
else
{
puts("Invalid BlackBox executable, make sure that the constant exeSize is correctly set");
}
}
else
{
printf("Couldn't find file: %s\n", "./bb.boot");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rdi
int v5; // er12
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // r13
_DWORD *v9; // rax
__int64 v10; // rdx
_DWORD *v11; // rdx
void (*v12)(void); // rdx

v4 = *argv;
modlist = 0LL;
f = fopen(v4, "r");
if ( f )
{
if ( (unsigned int)func13() )
{
v5 = 0;
if ( nofMods <= 0 )
{
LABEL_7:
fclose(f);
v6 = func4(kernel);
v7 = func4(mainmod);
v8 = v7;
if ( v6 )
{
if ( v7 )
{
v9 = calloc(1uLL, 0x18uLL);
v10 = modlist;
v9[2] = argc;
*(_QWORD *)v9 = v10;
v11 = (_DWORD *)*(int *)(v6 + 84);
*((_QWORD *)v9 + 2) = argv;
bootInfo = (__int64)v9;
*v11 = (_DWORD)v9;
v12 = (void (*)(void))*(int *)(v8 + 68);
*(_DWORD *)(v6 + 8) |= 0x10000u;
v12();
}
else
{
printf("no main module");
}
}
else
{
puts("no kernel");
}
func3();
}
else
{
while ( 1 )
{
if ( !(unsigned int)func14((__int64)v4, (__int64)"r") )
{
printf("Incorrect header: %s\n", (const char *)(unsigned int)((_DWORD)&mod + 8));
goto LABEL_14;
}
if ( !(unsigned int)func15() )
break;
++v5;
func2();
if ( nofMods <= v5 )
goto LABEL_7;
}
printf("Incorrect module: %s\n", (const char *)(unsigned int)((_DWORD)&mod + 8));
LABEL_14:
fclose(f);
}
}
else
{
puts("Invalid BlackBox executable, make sure that the constant exeSize is correctly set");
}
}
else
{
printf("Couldn't find file: %s\n", "./bb.boot");
}
return 0;
}

original_code:
int main (int argc, char *argv[])
{
  int i, ok;
  BodyProc body;
  int callBackAdr;
  Module *k, *m;
  modlist = ((void *)0);
  donothing("initializing BlackBox for Linux...\n");
  f = fopen(argv[0], "r");
  if (f != ((void *)0))
    {
      if (ReadBootHeader())
 {
   i = 0; ok = 1;
   while ((i < nofMods) && (ok)){
     ok = ReadHeader();
     if (ok) {
       ok = ReadModule();
       if (ok)
  RegisterModule();
       else
  printf("Incorrect module: %s\n", mod.name);
     } else
       printf("Incorrect header: %s\n", mod.name);
     i++;
   }
   fclose(f);
   if (ok) {
     k = ThisModule(kernel);
     m = ThisModule(mainmod);
     if (k == ((void *)0))
       printf("no kernel\n");
     else
       {
  if (m == ((void *)0))
    printf("no main module");
  else
    {
      bootInfo = calloc(1, sizeof(BootInfo));
      bootInfo->modList = modlist;
      bootInfo->argc = argc;
      bootInfo->argv = argv;
      *((int*)(k->varBase)) = (int)bootInfo;
      donothing("before body\n");
      body = (BodyProc)(m->code);
      k->opts = k->opts | 0x10000;
      body();
      donothing("after body\n");
    }
       }
     PrintMods();
   }
 } else
   printf("Invalid BlackBox executable, make sure that the constant exeSize is correctly set\n");
    } else
      printf("Couldn't find file: %s\n", bbfile);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int i; int ok;
  void (*body)();
  int callBackAdr;
  struct Module *k; struct Module *m;
  modlist = ((void *)0);
  donothing("initializing BlackBox for Linux...\n");
  f = fopen(argv[0], "r");
  if (f != ((void *)0))
    {
      if (ReadBootHeader())
 {
   i = 0; ok = 1;
   while ((i < nofMods) && (ok)){
     ok = ReadHeader();
     if (ok) {
       ok = ReadModule();
       if (ok)
  RegisterModule();
       else
  printf("Incorrect module: %s\n", mod.name);
     } else
       printf("Incorrect header: %s\n", mod.name);
     i++;
   }
   fclose(f);
   if (ok) {
     k = ThisModule(kernel);
     m = ThisModule(mainmod);
     if (k == ((void *)0))
       printf("no kernel\n");
     else
       {
  if (m == ((void *)0))
    printf("no main module");
  else
    {
      bootInfo = calloc(1, sizeof(BootInfo));
      bootInfo->modList = modlist;
      bootInfo->argc = argc;
      bootInfo->argv = argv;
      *((int *)(k->varBase)) = (int)bootInfo;
      donothing("before body\n");
      body = (BodyProc)(m->code);
      k->opts = k->opts | 0x10000;
      body();
      donothing("after body\n");
    }
       }
     PrintMods();
   }
 } else
   printf("Invalid BlackBox executable, make sure that the constant exeSize is correctly set\n");
    } else
      printf("Couldn't find file: %s\n", bbfile);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: ok int

variable_types:
body
void (*)()

variable_types: callBackAdr int


printUsage

decompiled_code:
int __fastcall printUsage(const char *a1)
{
return printf("Usage: %s <iterm file to convert>\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return printf("Usage: %s <iterm file to convert>\n", a1);
}

original_code:
void printUsage(char * name) {
    printf("Usage: %s <iterm file to convert>\n", name);
}

canonical_original_code:
void printUsage(char *name) {
    printf("Usage: %s <iterm file to convert>\n", name);
}

variable_types:
name
char *


main

repo: ronas/GPCAZ

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return 0;
}

original_code:
int main(int argc, char** argv) {
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    return (0);
}

variable_types:
argv
char **


repo: ronyrus/timing-play

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v5; // [rsp+0h] [rbp-38h]
__int64 v6; // [rsp+8h] [rbp-30h]
__int16 v7; // [rsp+10h] [rbp-28h]

while ( 1 )
{
puts("what is the password?:");
fflush(_bss_start);
if ( (unsigned int)__isoc99_scanf() != 1 )
break;
if ( !(v5 ^ 0x7263657379726576LL | v6 ^ 0x6F77737361707465LL) && v7 == 25714 )
{
v3 = 0;
puts("the password is correct, congrads!");
fflush(_bss_start);
return v3;
}
puts("wrong password, try again!");
fflush(_bss_start);
}
v3 = 1;
puts("something wrong with the input, bye bye");
fflush(_bss_start);
return v3;
}

original_code:
int main(int argc, char *argv[])
{
    char buf[30 + 1];
    while (1)
    {
        do { printf("what is the password?:\n"); fflush(stdout); } while (0);
        if (scanf("%30s", buf) != 1)
        {
            do { printf("something wrong with the input, bye bye\n"); fflush(stdout); } while (0);
            return 1;
        }
        if (memcmp(buf, "verysecretpassword", strlen("verysecretpassword")))
            do { printf("wrong password, try again!\n"); fflush(stdout); } while (0);
        else
        {
            do { printf("the password is correct, congrads!\n"); fflush(stdout); } while (0);
            break;
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char buf[-1];
    while (1)
    {
        do { printf("what is the password?:\n"); fflush(stdout); } while (0);
        if (scanf("%30s", buf) != 1)
        {
            do { printf("something wrong with the input, bye bye\n"); fflush(stdout); } while (0);
            return 1;
        }
        if (memcmp(buf, "verysecretpassword", strlen("verysecretpassword")))
            do { printf("wrong password, try again!\n"); fflush(stdout); } while (0);
        else
        {
            do { printf("the password is correct, congrads!\n"); fflush(stdout); } while (0);
            break;
        }
    }
    return 0;
}

variable_types:
buf
char [-1]


planeBoxOverlap

repo: rools/voxl

original_code:
int planeBoxOverlap(float normal[3],float d, float maxbox[3])
{
 int q;
 float vmin[3],vmax[3];
 for(q=0;q<=2;q++)
 {
  if(normal[q]>0.0f)
  {
   vmin[q]=-maxbox[q];
   vmax[q]=maxbox[q];
  }
  else
  {
   vmin[q]=maxbox[q];
   vmax[q]=-maxbox[q];
  }
 }
 if((normal[0]*vmin[0]+normal[1]*vmin[1]+normal[2]*vmin[2])+d>0.0f) return 0;
 if((normal[0]*vmax[0]+normal[1]*vmax[1]+normal[2]*vmax[2])+d>=0.0f) return 1;
 return 0;
}

canonical_original_code:
int planeBoxOverlap(float normal[3], float d, float maxbox[3])
{
 int q;
 float vmin[3]; float vmax[3];
 for(q=0;q<=2;q++)
 {
  if(normal[q]>0.0f)
  {
   vmin[q]=-maxbox[q];
   vmax[q]=maxbox[q];
  }
  else
  {
   vmin[q]=maxbox[q];
   vmax[q]=-maxbox[q];
  }
 }
 if((normal[0]*vmin[0]+normal[1]*vmin[1]+normal[2]*vmin[2])+d>0.0f) return 0;
 if((normal[0]*vmax[0]+normal[1]*vmax[1]+normal[2]*vmax[2])+d>=0.0f) return 1;
 return 0;
}

variable_types:
normal
float [3]

variable_types: d float

variable_types:
maxbox
float [3]

variable_types: q int

variable_types:
vmin
float [3]

variable_types:
vmax
float [3]


triBoxOverlap

decompiled_code:
__int64 __fastcall triBoxOverlap(float *a1, float *a2, _QWORD *a3)
{
float *v3; // rcx
float v4; // xmm1_4
float v5; // xmm0_4
float v6; // xmm10_4
float *v7; // rax
float v8; // xmm4_4
float v9; // xmm3_4
float v10; // xmm8_4
float v11; // xmm9_4
float v12; // xmm7_4
float v13; // xmm6_4
float v14; // xmm12_4
float v15; // xmm5_4
float v16; // xmm0_4
float v17; // xmm2_4
float v18; // xmm14_4
float v19; // xmm13_4
unsigned int v20; // er9
float v21; // xmm1_4
float v22; // xmm1_4
float v23; // xmm0_4
float v24; // xmm5_4
float v25; // xmm1_4
float v26; // xmm0_4
float v27; // xmm12_4
float v28; // xmm12_4
float v29; // xmm5_4
float v30; // xmm1_4
float v31; // xmm2_4
float v32; // xmm0_4
float v33; // xmm2_4
float v34; // xmm1_4
float v35; // xmm0_4
float v36; // xmm5_4
float v37; // xmm2_4
float v38; // xmm0_4
float v39; // xmm2_4
float v40; // xmm5_4
float v41; // xmm0_4
float v42; // xmm2_4
float v43; // xmm15_4
float v44; // xmm5_4
float v45; // xmm2_4
float v46; // xmm5_4
float v47; // xmm0_4
float v48; // xmm0_4
float v49; // xmm2_4
float v50; // xmm5_4
float v51; // xmm0_4
float v52; // xmm2_4
float v53; // xmm5_4
float v54; // xmm9_4
float v55; // xmm2_4
float v56; // xmm6_4
float v58; // [rsp+4h] [rbp-3Ch]
float v59; // [rsp+8h] [rbp-38h]
float v60; // [rsp+Ch] [rbp-34h]
float v61; // [rsp+10h] [rbp-30h]
float v62; // [rsp+14h] [rbp-2Ch]
float v63; // [rsp+18h] [rbp-28h]
float v64; // [rsp+1Ch] [rbp-24h]
float v65; // [rsp+1Ch] [rbp-24h]
float v66; // [rsp+20h] [rbp-20h]
float v67; // [rsp+24h] [rbp-1Ch]
float v68; // [rsp+28h] [rbp-18h]
float v69; // [rsp+2Ch] [rbp-14h]
float v70; // [rsp+34h] [rbp-Ch] BYREF
float v71; // [rsp+38h] [rbp-8h]
float v72; // [rsp+3Ch] [rbp-4h]

v3 = (float *)a3[1];
v4 = a1[1];
v5 = a1[2];
v6 = v3[1] - v4;
v7 = (float *)a3[2];
v8 = *(float *)(*a3 + 4LL) - v4;
v9 = *(float *)(*a3 + 8LL) - v5;
v10 = v6 - v8;
v11 = v7[1] - v4;
v59 = v3[2] - v5;
v12 = v59 - v9;
v13 = v7[2] - v5;
LODWORD(v14) = COERCE_UNSIGNED_INT(v6 - v8) & LC2;
LODWORD(v15) = COERCE_UNSIGNED_INT(v59 - v9) & LC2;
v16 = (float)(v8 * (float)(v59 - v9)) - (float)(v9 * (float)(v6 - v8));
v17 = (float)(v11 * (float)(v59 - v9)) - (float)(v13 * (float)(v6 - v8));
if ( v17 <= v16 )
{
v16 = (float)(v11 * v12) - (float)(v13 * (float)(v6 - v8));
v17 = (float)(v8 * v12) - (float)(v9 * (float)(v6 - v8));
}
v18 = a2[1];
v19 = a2[2];
v20 = 0;
v21 = (float)(v18 * v15) + (float)(v19 * v14);
if ( v16 <= v21 && COERCE_FLOAT(LODWORD(v21) ^ LC0) <= v17 )
{
v63 = *(float *)*a3 - *a1;
v61 = *v3 - *a1;
v60 = v61 - v63;
v58 = *v7 - *a1;
v22 = (float)((float)(v61 - v63) * v9) + (float)(v63 * COERCE_FLOAT(LODWORD(v12) ^ LC0));
v23 = (float)(COERCE_FLOAT(LODWORD(v12) ^ LC0) * v58) + (float)((float)(v61 - v63) * v13);
if ( v23 <= v22 )
{
v22 = (float)(COERCE_FLOAT(LODWORD(v12) ^ LC0) * v58) + (float)((float)(v61 - v63) * v13);
v23 = (float)((float)(v61 - v63) * v9) + (float)(v63 * COERCE_FLOAT(LODWORD(v12) ^ LC0));
}
v20 = 0;
v62 = *a2;
v24 = (float)(v15 * *a2) + (float)(v19 * COERCE_FLOAT(LODWORD(v60) & LC2));
if ( v22 <= v24 && COERCE_FLOAT(LODWORD(v24) ^ LC0) <= v23 )
{
v25 = (float)(v61 * v10) - (float)(v60 * v6);
v26 = (float)(v58 * v10) - (float)(v60 * v11);
if ( v25 <= v26 )
{
v26 = (float)(v61 * v10) - (float)(v60 * v6);
v25 = (float)(v58 * v10) - (float)(v60 * v11);
}
v20 = 0;
v27 = (float)(v14 * v62) + (float)(COERCE_FLOAT(LODWORD(v60) & LC2) * v18);
if ( v26 <= v27 && COERCE_FLOAT(LODWORD(v27) ^ LC0) <= v25 )
{
v28 = v13 - v59;
v67 = v11 - v6;
LODWORD(v64) = COERCE_UNSIGNED_INT(v11 - v6) & LC2;
LODWORD(v29) = COERCE_UNSIGNED_INT(v13 - v59) & LC2;
v30 = (float)(v8 * (float)(v13 - v59)) - (float)((float)(v11 - v6) * v9);
v31 = (float)(v11 * (float)(v13 - v59)) - (float)((float)(v11 - v6) * v13);
if ( v31 <= v30 )
{
v30 = (float)(v11 * (float)(v13 - v59)) - (float)((float)(v11 - v6) * v13);
v31 = (float)(v8 * (float)(v13 - v59)) - (float)((float)(v11 - v6) * v9);
}
v20 = 0;
v32 = (float)(v18 * v29) + (float)(v64 * v19);
if ( v30 <= v32 && COERCE_FLOAT(LODWORD(v32) ^ LC0) <= v31 )
{
v66 = v58 - v61;
v33 = (float)(v63 * COERCE_FLOAT(LODWORD(v28) ^ LC0)) + (float)((float)(v58 - v61) * v9);
v34 = (float)(COERCE_FLOAT(LODWORD(v28) ^ LC0) * v58) + (float)((float)(v58 - v61) * v13);
if ( v34 <= v33 )
{
v33 = (float)(COERCE_FLOAT(LODWORD(v28) ^ LC0) * v58) + (float)((float)(v58 - v61) * v13);
v34 = (float)(v63 * COERCE_FLOAT(LODWORD(v28) ^ LC0)) + (float)((float)(v58 - v61) * v9);
}
v20 = 0;
v35 = (float)(v29 * v62) + (float)(COERCE_FLOAT(LODWORD(v66) & LC2) * v19);
if ( v33 <= v35 && COERCE_FLOAT(LODWORD(v35) ^ LC0) <= v34 )
{
v36 = (float)(v63 * v67) - (float)(v66 * v8);
v37 = (float)(v61 * v67) - (float)(v66 * v6);
if ( v37 <= v36 )
{
v36 = (float)(v61 * v67) - (float)(v66 * v6);
v37 = (float)(v63 * v67) - (float)(v66 * v8);
}
v20 = 0;
v38 = (float)(v64 * v62) + (float)(COERCE_FLOAT(LODWORD(v66) & LC2) * v18);
if ( v36 <= v38 && COERCE_FLOAT(LODWORD(v38) ^ LC0) <= v37 )
{
v69 = v8 - v11;
LODWORD(v68) = COERCE_UNSIGNED_INT(v8 - v11) & LC2;
LODWORD(v65) = COERCE_UNSIGNED_INT(v9 - v13) & LC2;
v39 = (float)(v8 * (float)(v9 - v13)) - (float)((float)(v8 - v11) * v9);
v40 = (float)(v6 * (float)(v9 - v13)) - (float)(v59 * (float)(v8 - v11));
if ( v40 <= v39 )
{
v39 = (float)(v6 * (float)(v9 - v13)) - (float)(v59 * (float)(v8 - v11));
v40 = (float)(v8 * (float)(v9 - v13)) - (float)((float)(v8 - v11) * v9);
}
v20 = 0;
v41 = (float)(v65 * v18) + (float)(v68 * v19);
if ( v39 <= v41 && COERCE_FLOAT(LODWORD(v41) ^ LC0) <= v40 )
{
LODWORD(v42) = COERCE_UNSIGNED_INT(v9 - v13) ^ LC0;
v43 = v63 - v58;
v44 = v63 * v42;
v45 = (float)(v42 * v61) + (float)(v59 * (float)(v63 - v58));
v46 = v44 + (float)((float)(v63 - v58) * v9);
if ( v45 <= v46 )
{
v47 = v46;
v46 = v45;
v45 = v47;
}
v20 = 0;
v48 = (float)(v65 * v62) + (float)(v19 * COERCE_FLOAT(LC2 & LODWORD(v43)));
if ( v46 <= v48 && COERCE_FLOAT(LODWORD(v48) ^ LC0) <= v45 )
{
v49 = (float)(v61 * v69) - (float)(v43 * v6);
v50 = (float)(v69 * v58) - (float)(v43 * v11);
if ( v49 <= v50 )
{
v50 = (float)(v61 * v69) - (float)(v43 * v6);
v49 = (float)(v69 * v58) - (float)(v43 * v11);
}
v20 = 0;
v51 = (float)(COERCE_FLOAT(LC2 & LODWORD(v43)) * v18) + (float)(v68 * v62);
if ( v50 <= v51 && COERCE_FLOAT(LODWORD(v51) ^ LC0) <= v49 )
{
v52 = fmaxf(v58, fmaxf(v61, v63));
if ( fminf(v58, fminf(v61, v63)) <= v62 && COERCE_FLOAT(LODWORD(v62) ^ LC0) <= v52 )
{
v53 = v11;
v54 = fmaxf(v11, fmaxf(v6, v8));
if ( fminf(v53, fminf(v6, v8)) <= v18 && COERCE_FLOAT(LODWORD(v18) ^ LC0) <= v54 )
{
v55 = v13;
v56 = fmaxf(v13, fmaxf(v59, v9));
if ( fminf(v55, fminf(v59, v9)) <= v19 && COERCE_FLOAT(LODWORD(v19) ^ LC0) <= v56 )
{
v70 = (float)(v10 * v28) - (float)(v67 * v12);
v71 = (float)(v12 * v66) - (float)(v28 * v60);
v72 = (float)(v60 * v67) - (float)(v10 * v66);
LOBYTE(v20) = planeBoxOverlap(
&v70,
(__int64)a2,
COERCE_FLOAT(COERCE_UNSIGNED_INT(
(float)((float)(v8 * v71) + (float)(v70 * v63))
+ (float)(v9 * v72)) ^ LC0));
}
}
}
}
}
}
}
}
}
}
}
}
return v20;
}

canonical_decompiled_code:
__int64 __fastcall func1(float *a1, float *a2, _QWORD *a3)
{
float *v3; // rcx
float v4; // xmm1_4
float v5; // xmm0_4
float v6; // xmm10_4
float *v7; // rax
float v8; // xmm4_4
float v9; // xmm3_4
float v10; // xmm8_4
float v11; // xmm9_4
float v12; // xmm7_4
float v13; // xmm6_4
float v14; // xmm12_4
float v15; // xmm5_4
float v16; // xmm0_4
float v17; // xmm2_4
float v18; // xmm14_4
float v19; // xmm13_4
unsigned int v20; // er9
float v21; // xmm1_4
float v22; // xmm1_4
float v23; // xmm0_4
float v24; // xmm5_4
float v25; // xmm1_4
float v26; // xmm0_4
float v27; // xmm12_4
float v28; // xmm12_4
float v29; // xmm5_4
float v30; // xmm1_4
float v31; // xmm2_4
float v32; // xmm0_4
float v33; // xmm2_4
float v34; // xmm1_4
float v35; // xmm0_4
float v36; // xmm5_4
float v37; // xmm2_4
float v38; // xmm0_4
float v39; // xmm2_4
float v40; // xmm5_4
float v41; // xmm0_4
float v42; // xmm2_4
float v43; // xmm15_4
float v44; // xmm5_4
float v45; // xmm2_4
float v46; // xmm5_4
float v47; // xmm0_4
float v48; // xmm0_4
float v49; // xmm2_4
float v50; // xmm5_4
float v51; // xmm0_4
float v52; // xmm2_4
float v53; // xmm5_4
float v54; // xmm9_4
float v55; // xmm2_4
float v56; // xmm6_4
float v58; // [rsp+4h] [rbp-3Ch]
float v59; // [rsp+8h] [rbp-38h]
float v60; // [rsp+Ch] [rbp-34h]
float v61; // [rsp+10h] [rbp-30h]
float v62; // [rsp+14h] [rbp-2Ch]
float v63; // [rsp+18h] [rbp-28h]
float v64; // [rsp+1Ch] [rbp-24h]
float v65; // [rsp+1Ch] [rbp-24h]
float v66; // [rsp+20h] [rbp-20h]
float v67; // [rsp+24h] [rbp-1Ch]
float v68; // [rsp+28h] [rbp-18h]
float v69; // [rsp+2Ch] [rbp-14h]
float v70; // [rsp+34h] [rbp-Ch] BYREF
float v71; // [rsp+38h] [rbp-8h]
float v72; // [rsp+3Ch] [rbp-4h]

v3 = (float *)a3[1];
v4 = a1[1];
v5 = a1[2];
v6 = v3[1] - v4;
v7 = (float *)a3[2];
v8 = *(float *)(*a3 + 4LL) - v4;
v9 = *(float *)(*a3 + 8LL) - v5;
v10 = v6 - v8;
v11 = v7[1] - v4;
v59 = v3[2] - v5;
v12 = v59 - v9;
v13 = v7[2] - v5;
LODWORD(v14) = COERCE_UNSIGNED_INT(v6 - v8) & LC2;
LODWORD(v15) = COERCE_UNSIGNED_INT(v59 - v9) & LC2;
v16 = (float)(v8 * (float)(v59 - v9)) - (float)(v9 * (float)(v6 - v8));
v17 = (float)(v11 * (float)(v59 - v9)) - (float)(v13 * (float)(v6 - v8));
if ( v17 <= v16 )
{
v16 = (float)(v11 * v12) - (float)(v13 * (float)(v6 - v8));
v17 = (float)(v8 * v12) - (float)(v9 * (float)(v6 - v8));
}
v18 = a2[1];
v19 = a2[2];
v20 = 0;
v21 = (float)(v18 * v15) + (float)(v19 * v14);
if ( v16 <= v21 && COERCE_FLOAT(LODWORD(v21) ^ LC0) <= v17 )
{
v63 = *(float *)*a3 - *a1;
v61 = *v3 - *a1;
v60 = v61 - v63;
v58 = *v7 - *a1;
v22 = (float)((float)(v61 - v63) * v9) + (float)(v63 * COERCE_FLOAT(LODWORD(v12) ^ LC0));
v23 = (float)(COERCE_FLOAT(LODWORD(v12) ^ LC0) * v58) + (float)((float)(v61 - v63) * v13);
if ( v23 <= v22 )
{
v22 = (float)(COERCE_FLOAT(LODWORD(v12) ^ LC0) * v58) + (float)((float)(v61 - v63) * v13);
v23 = (float)((float)(v61 - v63) * v9) + (float)(v63 * COERCE_FLOAT(LODWORD(v12) ^ LC0));
}
v20 = 0;
v62 = *a2;
v24 = (float)(v15 * *a2) + (float)(v19 * COERCE_FLOAT(LODWORD(v60) & LC2));
if ( v22 <= v24 && COERCE_FLOAT(LODWORD(v24) ^ LC0) <= v23 )
{
v25 = (float)(v61 * v10) - (float)(v60 * v6);
v26 = (float)(v58 * v10) - (float)(v60 * v11);
if ( v25 <= v26 )
{
v26 = (float)(v61 * v10) - (float)(v60 * v6);
v25 = (float)(v58 * v10) - (float)(v60 * v11);
}
v20 = 0;
v27 = (float)(v14 * v62) + (float)(COERCE_FLOAT(LODWORD(v60) & LC2) * v18);
if ( v26 <= v27 && COERCE_FLOAT(LODWORD(v27) ^ LC0) <= v25 )
{
v28 = v13 - v59;
v67 = v11 - v6;
LODWORD(v64) = COERCE_UNSIGNED_INT(v11 - v6) & LC2;
LODWORD(v29) = COERCE_UNSIGNED_INT(v13 - v59) & LC2;
v30 = (float)(v8 * (float)(v13 - v59)) - (float)((float)(v11 - v6) * v9);
v31 = (float)(v11 * (float)(v13 - v59)) - (float)((float)(v11 - v6) * v13);
if ( v31 <= v30 )
{
v30 = (float)(v11 * (float)(v13 - v59)) - (float)((float)(v11 - v6) * v13);
v31 = (float)(v8 * (float)(v13 - v59)) - (float)((float)(v11 - v6) * v9);
}
v20 = 0;
v32 = (float)(v18 * v29) + (float)(v64 * v19);
if ( v30 <= v32 && COERCE_FLOAT(LODWORD(v32) ^ LC0) <= v31 )
{
v66 = v58 - v61;
v33 = (float)(v63 * COERCE_FLOAT(LODWORD(v28) ^ LC0)) + (float)((float)(v58 - v61) * v9);
v34 = (float)(COERCE_FLOAT(LODWORD(v28) ^ LC0) * v58) + (float)((float)(v58 - v61) * v13);
if ( v34 <= v33 )
{
v33 = (float)(COERCE_FLOAT(LODWORD(v28) ^ LC0) * v58) + (float)((float)(v58 - v61) * v13);
v34 = (float)(v63 * COERCE_FLOAT(LODWORD(v28) ^ LC0)) + (float)((float)(v58 - v61) * v9);
}
v20 = 0;
v35 = (float)(v29 * v62) + (float)(COERCE_FLOAT(LODWORD(v66) & LC2) * v19);
if ( v33 <= v35 && COERCE_FLOAT(LODWORD(v35) ^ LC0) <= v34 )
{
v36 = (float)(v63 * v67) - (float)(v66 * v8);
v37 = (float)(v61 * v67) - (float)(v66 * v6);
if ( v37 <= v36 )
{
v36 = (float)(v61 * v67) - (float)(v66 * v6);
v37 = (float)(v63 * v67) - (float)(v66 * v8);
}
v20 = 0;
v38 = (float)(v64 * v62) + (float)(COERCE_FLOAT(LODWORD(v66) & LC2) * v18);
if ( v36 <= v38 && COERCE_FLOAT(LODWORD(v38) ^ LC0) <= v37 )
{
v69 = v8 - v11;
LODWORD(v68) = COERCE_UNSIGNED_INT(v8 - v11) & LC2;
LODWORD(v65) = COERCE_UNSIGNED_INT(v9 - v13) & LC2;
v39 = (float)(v8 * (float)(v9 - v13)) - (float)((float)(v8 - v11) * v9);
v40 = (float)(v6 * (float)(v9 - v13)) - (float)(v59 * (float)(v8 - v11));
if ( v40 <= v39 )
{
v39 = (float)(v6 * (float)(v9 - v13)) - (float)(v59 * (float)(v8 - v11));
v40 = (float)(v8 * (float)(v9 - v13)) - (float)((float)(v8 - v11) * v9);
}
v20 = 0;
v41 = (float)(v65 * v18) + (float)(v68 * v19);
if ( v39 <= v41 && COERCE_FLOAT(LODWORD(v41) ^ LC0) <= v40 )
{
LODWORD(v42) = COERCE_UNSIGNED_INT(v9 - v13) ^ LC0;
v43 = v63 - v58;
v44 = v63 * v42;
v45 = (float)(v42 * v61) + (float)(v59 * (float)(v63 - v58));
v46 = v44 + (float)((float)(v63 - v58) * v9);
if ( v45 <= v46 )
{
v47 = v46;
v46 = v45;
v45 = v47;
}
v20 = 0;
v48 = (float)(v65 * v62) + (float)(v19 * COERCE_FLOAT(LC2 & LODWORD(v43)));
if ( v46 <= v48 && COERCE_FLOAT(LODWORD(v48) ^ LC0) <= v45 )
{
v49 = (float)(v61 * v69) - (float)(v43 * v6);
v50 = (float)(v69 * v58) - (float)(v43 * v11);
if ( v49 <= v50 )
{
v50 = (float)(v61 * v69) - (float)(v43 * v6);
v49 = (float)(v69 * v58) - (float)(v43 * v11);
}
v20 = 0;
v51 = (float)(COERCE_FLOAT(LC2 & LODWORD(v43)) * v18) + (float)(v68 * v62);
if ( v50 <= v51 && COERCE_FLOAT(LODWORD(v51) ^ LC0) <= v49 )
{
v52 = fmaxf(v58, fmaxf(v61, v63));
if ( fminf(v58, fminf(v61, v63)) <= v62 && COERCE_FLOAT(LODWORD(v62) ^ LC0) <= v52 )
{
v53 = v11;
v54 = fmaxf(v11, fmaxf(v6, v8));
if ( fminf(v53, fminf(v6, v8)) <= v18 && COERCE_FLOAT(LODWORD(v18) ^ LC0) <= v54 )
{
v55 = v13;
v56 = fmaxf(v13, fmaxf(v59, v9));
if ( fminf(v55, fminf(v59, v9)) <= v19 && COERCE_FLOAT(LODWORD(v19) ^ LC0) <= v56 )
{
v70 = (float)(v10 * v28) - (float)(v67 * v12);
v71 = (float)(v12 * v66) - (float)(v28 * v60);
v72 = (float)(v60 * v67) - (float)(v10 * v66);
LOBYTE(v20) = func0(
&v70,
(__int64)a2,
COERCE_FLOAT(COERCE_UNSIGNED_INT(
(float)((float)(v8 * v71) + (float)(v70 * v63))
+ (float)(v9 * v72)) ^ LC0));
}
}
}
}
}
}
}
}
}
}
}
}
return v20;
}

variable_types:
boxcenter
float [3]

variable_types:
boxhalfsize
float [3]

variable_types:
triverts
float *[3]

variable_types: min float

variable_types: max float

variable_types: rad float

variable_types: fex float

variable_types: fey float

variable_types: fez float


original_code:
struct vx_voxel *vx_get_octree_voxel(struct vx_octree *octree, float x, float y, float z, int detail) {
 uint32_t node = 0;
 float mid_point[3] = {0.5f, 0.5f, 0.5f};
 float node_size = 0.5f;
 struct vx_voxel *voxel = ((void *)0);
 for (int i = detail - 1; i >= 0; --i) {
  int octant = x > mid_point[0] ? 1 : 0;
  octant |= y > mid_point[1] ? 2 : 0;
  octant |= z > mid_point[2] ? 4 : 0;
  node_size *= 0.5f;
  mid_point[0] += x > mid_point[0] ? node_size : - node_size;
  mid_point[1] += y > mid_point[1] ? node_size : - node_size;
  mid_point[2] += z > mid_point[2] ? node_size : - node_size;
  if (i == 0) {
   if (octree->root[node].valid_masks & (1 << octant) && octree->root[node].leaf_mask & (1 << octant)) {
    voxel = (struct vx_voxel *)&octree->root[octree->root[node].child_pointers[octant]];
   } else {
    struct vx_voxel new_voxel;
    int pointer = vx_append_to_octree(octree, &new_voxel, 1);
    octree->root[node].valid_masks |= (1 << octant);
    octree->root[node].leaf_mask |= (1 << octant);
    octree->root[node].child_pointers[octant] = pointer;
    voxel = (struct vx_voxel *)&octree->root[pointer];
   }
  } else {
   if (octree->root[node].valid_masks & (1 << octant)) {
    node = octree->root[node].child_pointers[octant];
   } else {
    struct vx_node new_node;
    new_node.leaf_mask = 0;
    new_node.valid_masks = 0;
    int pointer = vx_append_to_octree(octree, &new_node, 1);
    octree->root[node].child_pointers[octant] = pointer;
    octree->root[node].valid_masks |= (1 << octant);
    node = pointer;
   }
  }
 }
 return voxel;
}

canonical_original_code:
struct vx_voxel *vx_get_octree_voxel(struct vx_octree *octree, float x, float y, float z, int detail) {
 unsigned int node = 0;
 float mid_point[3] = {0.5f, 0.5f, 0.5f};
 float node_size = 0.5f;
 struct vx_voxel *voxel = ((void *)0);
 for (int i = detail - 1; i >= 0; --i) {
  int octant = x > mid_point[0] ? 1 : 0;
  octant |= y > mid_point[1] ? 2 : 0;
  octant |= z > mid_point[2] ? 4 : 0;
  node_size *= 0.5f;
  mid_point[0] += x > mid_point[0] ? node_size : - node_size;
  mid_point[1] += y > mid_point[1] ? node_size : - node_size;
  mid_point[2] += z > mid_point[2] ? node_size : - node_size;
  if (i == 0) {
   if (octree->root[node].valid_masks & (1 << octant) && octree->root[node].leaf_mask & (1 << octant)) {
    voxel = (struct vx_voxel *)&octree->root[octree->root[node].child_pointers[octant]];
   } else {
    struct vx_voxel new_voxel;
    int pointer = vx_append_to_octree(octree, &new_voxel, 1);
    octree->root[node].valid_masks |= (1 << octant);
    octree->root[node].leaf_mask |= (1 << octant);
    octree->root[node].child_pointers[octant] = pointer;
    voxel = (struct vx_voxel *)&octree->root[pointer];
   }
  } else {
   if (octree->root[node].valid_masks & (1 << octant)) {
    node = octree->root[node].child_pointers[octant];
   } else {
    struct vx_node new_node;
    new_node.leaf_mask = 0;
    new_node.valid_masks = 0;
    int pointer = vx_append_to_octree(octree, &new_node, 1);
    octree->root[node].child_pointers[octant] = pointer;
    octree->root[node].valid_masks |= (1 << octant);
    node = pointer;
   }
  }
 }
 return voxel;
}

variable_types: struct vx_octree { struct vx_node { unsigned int child_pointers[8]; unsigned char valid_masks; unsigned char leaf_mask; unsigned short padding; } *root; unsigned int size; unsigned int allocated_size; unsigned int models[16]; int model_count; } *

variable_types: x float

variable_types: y float

variable_types: z float

variable_types: detail int

variable_types:
node
unsigned int

variable_types: struct vx_voxel { char normals[3]; unsigned char colors[4]; char padding; unsigned int padding2[7]; } *

variable_types: i int

variable_types: octant int

variable_types: pointer int

user_defined_types: struct vx_octree { struct vx_node *root; unsigned int size; unsigned int allocated_size; unsigned int models[16]; int model_count; }