main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r13
int v4; // eax
int v5; // ebx
__int64 v7; // rbp
int v8; // er13
__int64 v9; // rax
__int64 v10; // r12
__int64 v11; // rbp
int v12; // er13
__int64 v13; // rax
__int64 v14; // r12
void *v15; // rdi
char *v16; // rax
int longind; // [rsp+Ch] [rbp-3Ch] BYREF
void *ptr; // [rsp+10h] [rbp-38h] BYREF
char *v19; // [rsp+18h] [rbp-30h] BYREF

v19 = 0LL;
ptr = 0LL;
verbose_flag = 0;
v3 = 0;
while ( 1 )
{
longind = 0;
v4 = getopt_long(argc, (char *const *)argv, "c:x:vhV", &long_options_0, &longind);
v5 = v4;
if ( v4 == -1 )
break;
if ( v4 == 99 )
{
ptr = optarg;
v3 = 99;
}
else if ( v4 <= 99 )
{
if ( v4 )
{
if ( v4 == 86 )
version();
else
LABEL_15:
usage();
return 0;
}
}
else if ( v4 == 118 )
{
verbose_flag = 1;
}
else
{
if ( v4 != 120 )
goto LABEL_15;
v19 = optarg;
v3 = 120;
}
}
if ( verbose_flag )
fwrite("Verbose flag is set\n", 1uLL, 0x14uLL, stdout);
if ( v3 != 99 )
{
if ( v3 != 120 )
{
fwrite("Error: no mode has been specified!\n", 1uLL, 0x23uLL, stderr);
usage();
return v5;
}
if ( optind < argc )
{
ptr = (void *)argv[optind];
print_verbose("File path: %s\nArchive path: %s\n", (const char *)ptr, v19);
print_verbose("Deompression mode\n");
v7 = bitio_open(v19, 0LL);
if ( !v7 )
{
fprintf(stderr, "Error: cannot open %s!\n", v19);
return v5;
}
v8 = 0;
LABEL_23:
v9 = bitio_open(ptr, 1LL);
v10 = v9;
if ( v9 )
{
decompress(v7, v9);
bitio_close(v7);
bitio_close(v10);
v5 = v8;
if ( v8 )
{
free(ptr);
v5 = 0;
}
}
else
{
fprintf(stderr, "Error: cannot open %s!\n", (const char *)ptr);
if ( v8 )
free(ptr);
}
return v5;
}
if ( asprintf((char **)&ptr, "%s.out", v19) != -1 )
{
v16 = strstr((const char *)ptr, ".ylz");
if ( v16 )
*v16 = 0;
print_verbose("File path: %s\nArchive path: %s\n", (const char *)ptr, v19);
print_verbose("Deompression mode\n");
v7 = bitio_open(v19, 0LL);
if ( !v7 )
{
fprintf(stderr, "Error: cannot open %s!\n", v19);
free(ptr);
return v5;
}
v8 = 1;
goto LABEL_23;
}
fwrite("Error: unable to allocate memory!\n", 1uLL, 0x22uLL, stderr);
v15 = ptr;
v5 = -1;
if ( !ptr )
return v5;
LABEL_36:
free(v15);
return v5;
}
if ( optind >= argc )
{
if ( asprintf(&v19, "%s.ylz", (const char *)ptr) == -1 )
{
fwrite("Error: unable to allocate memory!\n", 1uLL, 0x22uLL, stderr);
v15 = v19;
v5 = -1;
if ( !v19 )
return v5;
goto LABEL_36;
}
print_verbose("File path: %s\nArchive path: %s\n", (const char *)ptr, v19);
print_verbose("Compression mode\n");
v11 = bitio_open(ptr, 0LL);
if ( !v11 )
{
fprintf(stderr, "Error: cannot open %s!\n", (const char *)ptr);
free(v19);
return v5;
}
v12 = 1;
}
else
{
v19 = (char *)argv[optind];
print_verbose("File path: %s\nArchive path: %s\n", (const char *)ptr, v19);
print_verbose("Compression mode\n");
v11 = bitio_open(ptr, 0LL);
if ( !v11 )
{
fprintf(stderr, "Error: cannot open %s!\n", (const char *)ptr);
return v5;
}
v12 = 0;
}
v13 = bitio_open(v19, 1LL);
v14 = v13;
if ( v13 )
{
compress(v11, v13);
bitio_close(v11);
bitio_close(v14);
v5 = v12;
if ( v12 )
{
free(v19);
v5 = 0;
}
}
else
{
fprintf(stderr, "Error: cannot open %s!\n", v19);
if ( v12 )
free(v19);
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r13
int v4; // eax
int v5; // ebx
__int64 v7; // rbp
int v8; // er13
__int64 v9; // rax
__int64 v10; // r12
__int64 v11; // rbp
int v12; // er13
__int64 v13; // rax
__int64 v14; // r12
void *v15; // rdi
char *v16; // rax
int longind; // [rsp+Ch] [rbp-3Ch] BYREF
void *ptr; // [rsp+10h] [rbp-38h] BYREF
char *v19; // [rsp+18h] [rbp-30h] BYREF

v19 = 0LL;
ptr = 0LL;
verbose_flag = 0;
v3 = 0;
while ( 1 )
{
longind = 0;
v4 = getopt_long(argc, (char *const *)argv, "c:x:vhV", &long_options_0, &longind);
v5 = v4;
if ( v4 == -1 )
break;
if ( v4 == 99 )
{
ptr = optarg;
v3 = 99;
}
else if ( v4 <= 99 )
{
if ( v4 )
{
if ( v4 == 86 )
func0();
else
LABEL_15:
func1();
return 0;
}
}
else if ( v4 == 118 )
{
verbose_flag = 1;
}
else
{
if ( v4 != 120 )
goto LABEL_15;
v19 = optarg;
v3 = 120;
}
}
if ( verbose_flag )
fwrite("Verbose flag is set\n", 1uLL, 0x14uLL, stdout);
if ( v3 != 99 )
{
if ( v3 != 120 )
{
fwrite("Error: no mode has been specified!\n", 1uLL, 0x23uLL, stderr);
func1();
return v5;
}
if ( optind < argc )
{
ptr = (void *)argv[optind];
print_verbose("File path: %s\nArchive path: %s\n", (const char *)ptr, v19);
print_verbose("Deompression mode\n");
v7 = bitio_open(v19, 0LL);
if ( !v7 )
{
fprintf(stderr, "Error: cannot open %s!\n", v19);
return v5;
}
v8 = 0;
LABEL_23:
v9 = bitio_open(ptr, 1LL);
v10 = v9;
if ( v9 )
{
decompress(v7, v9);
bitio_close(v7);
bitio_close(v10);
v5 = v8;
if ( v8 )
{
free(ptr);
v5 = 0;
}
}
else
{
fprintf(stderr, "Error: cannot open %s!\n", (const char *)ptr);
if ( v8 )
free(ptr);
}
return v5;
}
if ( asprintf((char **)&ptr, "%s.out", v19) != -1 )
{
v16 = strstr((const char *)ptr, ".ylz");
if ( v16 )
*v16 = 0;
print_verbose("File path: %s\nArchive path: %s\n", (const char *)ptr, v19);
print_verbose("Deompression mode\n");
v7 = bitio_open(v19, 0LL);
if ( !v7 )
{
fprintf(stderr, "Error: cannot open %s!\n", v19);
free(ptr);
return v5;
}
v8 = 1;
goto LABEL_23;
}
fwrite("Error: unable to allocate memory!\n", 1uLL, 0x22uLL, stderr);
v15 = ptr;
v5 = -1;
if ( !ptr )
return v5;
LABEL_36:
free(v15);
return v5;
}
if ( optind >= argc )
{
if ( asprintf(&v19, "%s.ylz", (const char *)ptr) == -1 )
{
fwrite("Error: unable to allocate memory!\n", 1uLL, 0x22uLL, stderr);
v15 = v19;
v5 = -1;
if ( !v19 )
return v5;
goto LABEL_36;
}
print_verbose("File path: %s\nArchive path: %s\n", (const char *)ptr, v19);
print_verbose("Compression mode\n");
v11 = bitio_open(ptr, 0LL);
if ( !v11 )
{
fprintf(stderr, "Error: cannot open %s!\n", (const char *)ptr);
free(v19);
return v5;
}
v12 = 1;
}
else
{
v19 = (char *)argv[optind];
print_verbose("File path: %s\nArchive path: %s\n", (const char *)ptr, v19);
print_verbose("Compression mode\n");
v11 = bitio_open(ptr, 0LL);
if ( !v11 )
{
fprintf(stderr, "Error: cannot open %s!\n", (const char *)ptr);
return v5;
}
v12 = 0;
}
v13 = bitio_open(v19, 1LL);
v14 = v13;
if ( v13 )
{
compress(v11, v13);
bitio_close(v11);
bitio_close(v14);
v5 = v12;
if ( v12 )
{
free(v19);
v5 = 0;
}
}
else
{
fprintf(stderr, "Error: cannot open %s!\n", v19);
if ( v12 )
free(v19);
}
return v5;
}

original_code:
int main(int argc, char *argv[])
{
  char *archive_path = ((void *)0), *file_path = ((void *)0);
  char mode = 0;
  BITIO* in_file = ((void *)0), *out_file = ((void *)0);
  int i;
  int cst_alloc_fp, cst_alloc_ap;
  verbose_flag = 0;
  cst_alloc_fp = 0;
  cst_alloc_ap = 0;
  while (1) {
    static struct option long_options[] = {
      {"compress", 1, 0, 'c'},
      {"extract", 1, 0, 'x'},
      {"help", 0, 0, 'h'},
      {"version", 0, 0, 'V'},
      {"verbose", 0, &verbose_flag, 1},
      {0, 0, 0, 0}
    };
    int option_index = 0;
    i = getopt_long(argc, argv, "c:x:vhV",
                    long_options, &option_index);
    if (i == -1)
      break;
    switch (i) {
    case 0:
      break;
    case 'v':
      verbose_flag = 1;
      break;
    case 'c':
      mode = i;
      file_path = optarg;
      break;
    case 'x':
      mode = i;
      archive_path = optarg;
      break;
    case 'V':
      version();
      return 0;
    case 'h':
    case '?':
    default:
      usage();
      return 0;
    }
  }
  if (verbose_flag)
    fprintf(stdout, "Verbose flag is set\n");
  if (mode == 'c') {
    if (optind < argc)
      archive_path = argv[optind];
    else{
      cst_alloc_ap = 1;
      if (asprintf(&archive_path, "%s.ylz", file_path) == -1) {
        fprintf(stderr, "Error: unable to allocate memory!\n");
        if (archive_path != ((void *)0))
          free(archive_path);
        return -1;
      }
    }
  }
  else if (mode == 'x') {
    if (optind < argc) {
      file_path = argv[optind];
    }
    else {
      cst_alloc_fp = 1;
      if (asprintf(&file_path, "%s.out", archive_path) == -1) {
        fprintf(stderr, "Error: unable to allocate memory!\n");
        if (file_path != ((void *)0))
          free(file_path);
        return -1;
      }
      char* extension = strstr(file_path, ".ylz");
      if (extension)
        *extension = '\0';
    }
  }
  else {
    fprintf(stderr, "Error: no mode has been specified!\n");
    usage();
    return -1;
  }
  print_verbose("File path: %s\nArchive path: %s\n", file_path, archive_path);
  if (mode == 'c') {
    print_verbose("Compression mode\n");
    if ((in_file = bitio_open(file_path, 00)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", file_path);
      if (cst_alloc_ap)
        free(archive_path);
      return -1;
    }
    if ((out_file = bitio_open(archive_path, 01)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", archive_path);
      if (cst_alloc_ap)
        free(archive_path);
      return -1;
    }
    compress(in_file, out_file);
    bitio_close(in_file);
    bitio_close(out_file);
    if (cst_alloc_ap)
      free(archive_path);
  }
  else if (mode == 'x') {
    print_verbose("Deompression mode\n");
    if ((in_file = bitio_open(archive_path, 00)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", archive_path);
      if (cst_alloc_fp)
        free(file_path);
      return -1;
    }
    if ((out_file = bitio_open(file_path, 01)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", file_path);
      if (cst_alloc_fp)
        free(file_path);
      return -1;
    }
    decompress(in_file, out_file);
    bitio_close(in_file);
    bitio_close(out_file);
    if (cst_alloc_fp)
      free(file_path);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *archive_path = ((void *)0); char *file_path = ((void *)0);
  char mode = 0;
  struct BITIO *in_file = ((void *)0); struct BITIO *out_file = ((void *)0);
  int i;
  int cst_alloc_fp; int cst_alloc_ap;
  verbose_flag = 0;
  cst_alloc_fp = 0;
  cst_alloc_ap = 0;
  while (1) {
    static struct option long_options[] = {
      {"compress", 1, 0, 'c'},
      {"extract", 1, 0, 'x'},
      {"help", 0, 0, 'h'},
      {"version", 0, 0, 'V'},
      {"verbose", 0, &verbose_flag, 1},
      {0, 0, 0, 0}
    };
    int option_index = 0;
    i = getopt_long(argc, argv, "c:x:vhV",
                    long_options, &option_index);
    if (i == -1)
      break;
    switch (i) {
    case 0:
      break;
    case 'v':
      verbose_flag = 1;
      break;
    case 'c':
      mode = i;
      file_path = optarg;
      break;
    case 'x':
      mode = i;
      archive_path = optarg;
      break;
    case 'V':
      version();
      return 0;
    case 'h':
    case '?':
    default:
      usage();
      return 0;
    }
  }
  if (verbose_flag)
    fprintf(stdout, "Verbose flag is set\n");
  if (mode == 'c') {
    if (optind < argc)
      archive_path = argv[optind];
    else{
      cst_alloc_ap = 1;
      if (asprintf(&archive_path, "%s.ylz", file_path) == -1) {
        fprintf(stderr, "Error: unable to allocate memory!\n");
        if (archive_path != ((void *)0))
          free(archive_path);
        return -1;
      }
    }
  }
  else if (mode == 'x') {
    if (optind < argc) {
      file_path = argv[optind];
    }
    else {
      cst_alloc_fp = 1;
      if (asprintf(&file_path, "%s.out", archive_path) == -1) {
        fprintf(stderr, "Error: unable to allocate memory!\n");
        if (file_path != ((void *)0))
          free(file_path);
        return -1;
      }
      char *extension = strstr(file_path, ".ylz");
      if (extension)
        *extension = '\0';
    }
  }
  else {
    fprintf(stderr, "Error: no mode has been specified!\n");
    usage();
    return -1;
  }
  print_verbose("File path: %s\nArchive path: %s\n", file_path, archive_path);
  if (mode == 'c') {
    print_verbose("Compression mode\n");
    if ((in_file = bitio_open(file_path, 00)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", file_path);
      if (cst_alloc_ap)
        free(archive_path);
      return -1;
    }
    if ((out_file = bitio_open(archive_path, 01)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", archive_path);
      if (cst_alloc_ap)
        free(archive_path);
      return -1;
    }
    compress(in_file, out_file);
    bitio_close(in_file);
    bitio_close(out_file);
    if (cst_alloc_ap)
      free(archive_path);
  }
  else if (mode == 'x') {
    print_verbose("Deompression mode\n");
    if ((in_file = bitio_open(archive_path, 00)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", archive_path);
      if (cst_alloc_fp)
        free(file_path);
      return -1;
    }
    if ((out_file = bitio_open(file_path, 01)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", file_path);
      if (cst_alloc_fp)
        free(file_path);
      return -1;
    }
    decompress(in_file, out_file);
    bitio_close(in_file);
    bitio_close(out_file);
    if (cst_alloc_fp)
      free(file_path);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: mode char

variable_types: struct BITIO { int fd; unsigned int first; unsigned int empty; int mode; unsigned long buf[-1]; } *

variable_types: i int

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

variable_types:
extension
char *


min

repo: badnack/Yalzi

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

original_code:
inline static int
min(int x1, int x2)
{
  return (x1 <= x2) ? x1 : x2;
}

return_type: int


decompiled_code:
__int64 __fastcall fix_write(int *a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r14
__int64 result; // rax
__int64 v5; // rsi
__int64 v6; // rax
__int64 v7; // rdx
unsigned int v8; // ebp
unsigned int v9; // ebp
unsigned int v10; // er12
char v11; // r15
int v12; // ebx

if ( a3 > 0x40 )
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
else
{
v3 = a3;
result = 0LL;
if ( a3 )
{
do
{
v9 = a1[2];
v10 = v9 >> 6;
v11 = v9 & 0x3F;
v12 = min(64 - (v9 & 0x3F), v3);
if ( v12 == 64 )
{
v5 = *(_QWORD *)&a1[2 * v10 + 4];
v6 = -1LL;
v7 = 0LL;
}
else
{
v6 = (1LL << v12) - 1;
v5 = *(_QWORD *)&a1[2 * v10 + 4];
v7 = (1LL << v11) - 1;
}
*(_QWORD *)&a1[2 * v10 + 4] = v5 & v7 | ((a2 & v6) << v11);
v3 -= v12;
v8 = v12 + v9;
a1[2] = v8;
if ( v8 > 0x7FFF )
{
result = store_buffer(a1, 0x1000uLL);
if ( (_DWORD)result == -1 )
return result;
a1[2] = 0;
}
a2 >>= v12;
}
while ( v3 );
result = 0LL;
}
}
return result;
}

original_code:
static int
fix_write(BITIO* bip, env_var src, size_t src_len)
{
  int index;
  int offset;
  int bits_to_write;
  env_var mask;
  if (src_len > (sizeof(env_var) * 8)) {
      (*__errno_location ()) = 22;
      return -1;
  }
  while (src_len > 0) {
    index = (bip->empty) / (sizeof(env_var) * 8);
    offset = (bip->empty) % (sizeof(env_var) * 8);
    bits_to_write = min((sizeof(env_var) * 8) - offset, src_len);
    mask = (bits_to_write == (sizeof(env_var) * 8)) ? 0xFFFFFFFFFFFFFFFF : ((((env_var)1) << bits_to_write) - 1);
    bip->buf[index] &= (bits_to_write == (sizeof(env_var) * 8)) ? 0 : (((env_var)1) << offset) - 1;
    bip->buf[index] |= (src & mask) << offset;
    src_len -= bits_to_write;
    bip->empty += bits_to_write;
    if (bip->empty >= (4096 / (sizeof(env_var))) * (sizeof(env_var) * 8)) {
      if (store_buffer(bip, ((4096 / (sizeof(env_var))) * sizeof(env_var))) == -1)
        return -1;
      bip->empty = 0;
    }
    src >>= bits_to_write;
  }
  return 0;
}

canonical_original_code:
static int fix_write(struct BITIO *bip, unsigned long src, unsigned long src_len)
{
  int index;
  int offset;
  int bits_to_write;
  unsigned long mask;
  if (src_len > (sizeof(env_var) * 8)) {
      (*__errno_location ()) = 22;
      return -1;
  }
  while (src_len > 0) {
    index = (bip->empty) / (sizeof(env_var) * 8);
    offset = (bip->empty) % (sizeof(env_var) * 8);
    bits_to_write = min((sizeof(env_var) * 8) - offset, src_len);
    mask = (bits_to_write == (sizeof(env_var) * 8)) ? 0xFFFFFFFFFFFFFFFF : ((((unsigned long)1) << bits_to_write) - 1);
    bip->buf[index] &= (bits_to_write == (sizeof(env_var) * 8)) ? 0 : (((unsigned long)1) << offset) - 1;
    bip->buf[index] |= (src & mask) << offset;
    src_len -= bits_to_write;
    bip->empty += bits_to_write;
    if (bip->empty >= (4096 / (sizeof(env_var))) * (sizeof(env_var) * 8)) {
      if (store_buffer(bip, ((4096 / (sizeof(env_var))) * sizeof(env_var))) == -1)
        return -1;
      bip->empty = 0;
    }
    src >>= bits_to_write;
  }
  return 0;
}

variable_types:
src
unsigned long

variable_types: index int

variable_types: offset int

variable_types:
mask
unsigned long

user_defined_types: struct BITIO { int fd; unsigned int first; unsigned int empty; int mode; unsigned long buf[-1]; }


original_code:
static int
fix_read(BITIO* bip, env_var* dst, size_t dst_len)
{
  int err;
  int bits_to_read;
  int read_bits = 0;
  int index;
  int offset;
  env_var mask;
  if (dst_len > (sizeof(env_var) * 8)) {
    (*__errno_location ()) = 22;
    return -1;
  }
  while (dst_len > 0) {
    if (bip->first >= (4096 / (sizeof(env_var))) * (sizeof(env_var) * 8) || bip->empty <= bip->first) {
      if ((err = load_buffer(bip, ((4096 / (sizeof(env_var))) * sizeof(env_var)))) == -1)
        return -1;
      bip->first = 0;
      bip->empty = err * 8;
      if (bip->empty == 0)
        return read_bits;
    }
    index = (bip->first) / (sizeof(env_var) * 8);
    offset = (bip->first) % (sizeof(env_var) * 8);
    bits_to_read = min((sizeof(env_var) * 8) - offset, min(dst_len, bip->empty - bip->first));
    mask = (bits_to_read == (sizeof(env_var) * 8)) ? 0xFFFFFFFFFFFFFFFF : (((((env_var)1) << bits_to_read) - 1) << offset);
    *dst &= (bits_to_read == (sizeof(env_var) * 8)) ? 0 : ~((((env_var)1 << bits_to_read) - 1) << read_bits);
    *dst |= (offset - read_bits > 0) ? ((env_var)(bip->buf[index] & mask) >> (offset - read_bits)) : ((env_var)(bip->buf[index] & mask) << (read_bits - offset));
    dst_len -= bits_to_read;
    bip->first += bits_to_read;
    read_bits += bits_to_read;
  }
  return read_bits;
}

canonical_original_code:
static int fix_read(struct BITIO *bip, unsigned long *dst, unsigned long dst_len)
{
  int err;
  int bits_to_read;
  int read_bits = 0;
  int index;
  int offset;
  unsigned long mask;
  if (dst_len > (sizeof(env_var) * 8)) {
    (*__errno_location ()) = 22;
    return -1;
  }
  while (dst_len > 0) {
    if (bip->first >= (4096 / (sizeof(env_var))) * (sizeof(env_var) * 8) || bip->empty <= bip->first) {
      if ((err = load_buffer(bip, ((4096 / (sizeof(env_var))) * sizeof(env_var)))) == -1)
        return -1;
      bip->first = 0;
      bip->empty = err * 8;
      if (bip->empty == 0)
        return read_bits;
    }
    index = (bip->first) / (sizeof(env_var) * 8);
    offset = (bip->first) % (sizeof(env_var) * 8);
    bits_to_read = min((sizeof(env_var) * 8) - offset, min(dst_len, bip->empty - bip->first));
    mask = (bits_to_read == (sizeof(env_var) * 8)) ? 0xFFFFFFFFFFFFFFFF : (((((unsigned long)1) << bits_to_read) - 1) << offset);
    *dst &= (bits_to_read == (sizeof(env_var) * 8)) ? 0 : ~((((unsigned long)1 << bits_to_read) - 1) << read_bits);
    *dst |= (offset - read_bits > 0) ? ((env_var)(bip->buf[index] & mask) >> (offset - read_bits)) : ((env_var)(bip->buf[index] & mask) << (read_bits - offset));
    dst_len -= bits_to_read;
    bip->first += bits_to_read;
    read_bits += bits_to_read;
  }
  return read_bits;
}

variable_types:
dst
unsigned long *

variable_types: err int


decompiled_code:
__int64 __fastcall bitio_write(int *a1, unsigned __int64 *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rbp
int v4; // eax
unsigned __int64 *v5; // r12
__int64 v6; // r15
int v7; // ebx
__int64 result; // rax

v3 = a3;
v4 = (a3 >> 6) + ((a3 & 0x3F) != 0);
if ( a2 == 0LL || a1 == 0LL || !a3 )
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
else if ( a1[3] == 1 )
{
if ( v4 <= 0 )
{
result = 0LL;
}
else
{
v5 = a2;
v6 = (__int64)&a2[(unsigned int)(v4 - 1) + 1];
while ( 1 )
{
v7 = 64;
if ( v3 <= 0x40 )
v7 = v3;
result = fix_write(a1, *v5, v7);
if ( (_DWORD)result == -1 )
break;
v3 -= v7;
if ( ++v5 == (unsigned __int64 *)v6 )
return 0LL;
}
}
}
else
{
*_errno_location() = 9;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int *a1, unsigned __int64 *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rbp
int v4; // eax
unsigned __int64 *v5; // r12
__int64 v6; // r15
int v7; // ebx
__int64 result; // rax

v3 = a3;
v4 = (a3 >> 6) + ((a3 & 0x3F) != 0);
if ( a2 == 0LL || a1 == 0LL || !a3 )
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
else if ( a1[3] == 1 )
{
if ( v4 <= 0 )
{
result = 0LL;
}
else
{
v5 = a2;
v6 = (__int64)&a2[(unsigned int)(v4 - 1) + 1];
while ( 1 )
{
v7 = 64;
if ( v3 <= 0x40 )
v7 = v3;
result = func3(a1, *v5, v7);
if ( (_DWORD)result == -1 )
break;
v3 -= v7;
if ( ++v5 == (unsigned __int64 *)v6 )
return 0LL;
}
}
}
else
{
*_errno_location() = 9;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
bitio_write(BITIO* bip, env_var* data, size_t src_len)
{
  int b_steps = src_len / (sizeof(env_var) * 8) + ((src_len % (sizeof(env_var) * 8)) > 0);
  int i,size;
  if (bip == ((void *)0) || data == ((void *)0) || src_len <= 0) {
    (*__errno_location ()) = 22;
    return -1;
  }
  if (bip->mode != 01) {
    (*__errno_location ()) = 9;
    return -1;
  }
  for (i = 0; i < b_steps; i++) {
    size = (src_len > (sizeof(env_var) * 8)) ? ((sizeof(env_var) * 8)) : src_len;
    if (fix_write(bip, data[i], size) == -1)
      return -1;
    src_len -= size;
  }
  return 0;
}

canonical_original_code:
int bitio_write(struct BITIO *bip, unsigned long *data, unsigned long src_len)
{
  int b_steps = src_len / (sizeof(env_var) * 8) + ((src_len % (sizeof(env_var) * 8)) > 0);
  int i; int size;
  if (bip == ((void *)0) || data == ((void *)0) || src_len <= 0) {
    (*__errno_location ()) = 22;
    return -1;
  }
  if (bip->mode != 01) {
    (*__errno_location ()) = 9;
    return -1;
  }
  for (i = 0; i < b_steps; i++) {
    size = (src_len > (sizeof(env_var) * 8)) ? ((sizeof(env_var) * 8)) : src_len;
    if (fix_write(bip, data[i], size) == -1)
      return -1;
    src_len -= size;
  }
  return 0;
}

variable_types:
data
unsigned long *

variable_types: size int


original_code:
int
bitio_read(BITIO* bip, env_var* data, size_t dst_len)
{
  int read_bits = 0;
  int b_steps = dst_len / (sizeof(env_var) * 8) + ((dst_len % (sizeof(env_var) * 8)) > 0);
  int i,size;
  if (data == ((void *)0) || bip == ((void *)0) || dst_len <= 0) {
    (*__errno_location ()) = 22;
    return -1;
  }
  if (bip->mode != 00) {
    (*__errno_location ()) = 9;
    return -1;
  }
  for (i = 0; i < b_steps; i++) {
    size = (dst_len > (sizeof(env_var) * 8)) ? (sizeof(env_var) * 8) : dst_len;
    if ((read_bits += fix_read(bip, &data[i], size)) <= 0)
      return -1;
    dst_len -= size;
  }
  return read_bits;
}

canonical_original_code:
int bitio_read(struct BITIO *bip, unsigned long *data, unsigned long dst_len)
{
  int read_bits = 0;
  int b_steps = dst_len / (sizeof(env_var) * 8) + ((dst_len % (sizeof(env_var) * 8)) > 0);
  int i; int size;
  if (data == ((void *)0) || bip == ((void *)0) || dst_len <= 0) {
    (*__errno_location ()) = 22;
    return -1;
  }
  if (bip->mode != 00) {
    (*__errno_location ()) = 9;
    return -1;
  }
  for (i = 0; i < b_steps; i++) {
    size = (dst_len > (sizeof(env_var) * 8)) ? (sizeof(env_var) * 8) : dst_len;
    if ((read_bits += fix_read(bip, &data[i], size)) <= 0)
      return -1;
    dst_len -= size;
  }
  return read_bits;
}


decompiled_code:
__int64 __fastcall bitio_close(void *ptr)
{
unsigned int v1; // ebp
unsigned int v3; // eax
unsigned int v4; // edx
unsigned int v5; // ecx

if ( ptr )
{
if ( *((_DWORD *)ptr + 3) == 1 )
{
v3 = *((_DWORD *)ptr + 2);
if ( v3 )
{
v4 = v3 >> 6;
v5 = *((_DWORD *)ptr + 2) & 0x3F;
if ( (v3 & 0x3F) != 0 )
*((_QWORD *)ptr + (int)v4 + 2) &= ~(-1LL << v5);
store_buffer((int *)ptr, (v5 >> 3) + 8LL * (int)v4 - (((v3 & 7) == 0) - 1LL));
}
}
v1 = close(*(_DWORD *)ptr);
free(ptr);
}
else
{
*_errno_location() = 22;
v1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *ptr)
{
unsigned int v1; // ebp
unsigned int v3; // eax
unsigned int v4; // edx
unsigned int v5; // ecx

if ( ptr )
{
if ( *((_DWORD *)ptr + 3) == 1 )
{
v3 = *((_DWORD *)ptr + 2);
if ( v3 )
{
v4 = v3 >> 6;
v5 = *((_DWORD *)ptr + 2) & 0x3F;
if ( (v3 & 0x3F) != 0 )
*((_QWORD *)ptr + (int)v4 + 2) &= ~(-1LL << v5);
func2((int *)ptr, (v5 >> 3) + 8LL * (int)v4 - (((v3 & 7) == 0) - 1LL));
}
}
v1 = close(*(_DWORD *)ptr);
free(ptr);
}
else
{
*_errno_location() = 22;
v1 = -1;
}
return v1;
}

original_code:
int
bitio_close(BITIO* bip)
{
  int err, index, offset;
  if (bip == ((void *)0)){
    (*__errno_location ()) = 22;
    return -1;
  }
  err = 0;
  if (bip->mode == 01 && bip->empty > 0) {
    index = bip->empty / (sizeof(env_var) * 8);
    if ((offset = (bip->empty % (sizeof(env_var) * 8))))
      bip->buf[index] &= ((env_var)1 << offset) - 1;
    store_buffer(bip, index * sizeof(env_var) + (offset / 8) + ((offset % 8) > 0));
  }
  err = close(bip->fd);
  memset(bip, 0, sizeof(BITIO));
  free(bip);
  return err;
}

canonical_original_code:
int bitio_close(struct BITIO *bip)
{
  int err; int index; int offset;
  if (bip == ((void *)0)){
    (*__errno_location ()) = 22;
    return -1;
  }
  err = 0;
  if (bip->mode == 01 && bip->empty > 0) {
    index = bip->empty / (sizeof(env_var) * 8);
    if ((offset = (bip->empty % (sizeof(env_var) * 8))))
      bip->buf[index] &= ((unsigned long)1 << offset) - 1;
    store_buffer(bip, index * sizeof(env_var) + (offset / 8) + ((offset % 8) > 0));
  }
  err = close(bip->fd);
  memset(bip, 0, sizeof(BITIO));
  free(bip);
  return err;
}


original_code:
void
bitio_flush(BITIO* bip)
{
  int index, offset;
  if (bip == ((void *)0))
    return;
  if (bip->mode == 01 && bip->empty > 0) {
    index = bip->empty / (sizeof(env_var) * 8);
    if ((offset = (bip->empty % (sizeof(env_var) * 8))))
      bip->buf[index] &= ((env_var)1 << offset) - 1;
    store_buffer(bip, index*sizeof(env_var) + (offset / 8) + ((offset % 8) > 0));
    bip->empty = 0;
    bip->first = 0;
  }
  memset(bip->buf, 0, ((4096 / (sizeof(env_var))) * sizeof(env_var)));
}

canonical_original_code:
void bitio_flush(struct BITIO *bip)
{
  int index; int offset;
  if (bip == ((void *)0))
    return;
  if (bip->mode == 01 && bip->empty > 0) {
    index = bip->empty / (sizeof(env_var) * 8);
    if ((offset = (bip->empty % (sizeof(env_var) * 8))))
      bip->buf[index] &= ((unsigned long)1 << offset) - 1;
    store_buffer(bip, index*sizeof(env_var) + (offset / 8) + ((offset % 8) > 0));
    bip->empty = 0;
    bip->first = 0;
  }
  memset(bip->buf, 0, ((4096 / (sizeof(env_var))) * sizeof(env_var)));
}

return_type: void


decompiled_code:
__int64 __fastcall hashtable_insert(__int64 a1, __int64 a2, unsigned __int64 a3, __int64 a4)
{
int v4; // er13
int v5; // ebp
unsigned int v6; // eax
_DWORD *i; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = a3;
v5 = a4;
if ( a3 > 0x3FFFFF )
return 0xFFFFFFFFLL;
v6 = get_hash(a2, a4);
for ( i = (_DWORD *)(a1 + 12LL * v6); i[2]; i = (_DWORD *)(a1 + 12LL * v6) )
v6 = (v6 + 1) & 0x7FFFFF;
i[2] = v4;
*i = a2;
i[1] = v5;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned __int64 a3, __int64 a4)
{
int v4; // er13
int v5; // ebp
unsigned int v6; // eax
_DWORD *i; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = a3;
v5 = a4;
if ( a3 > 0x3FFFFF )
return 0xFFFFFFFFLL;
v6 = get_hash(a2, a4);
for ( i = (_DWORD *)(a1 + 12LL * v6); i[2]; i = (_DWORD *)(a1 + 12LL * v6) )
v6 = (v6 + 1) & 0x7FFFFF;
i[2] = v4;
*i = a2;
i[1] = v5;
return 0LL;
}

original_code:
int
hashtable_insert(hashtable* ht, env_var f_label, env_var c_label, env_var c_value)
{
  uint32_t index;
  if (ht == ((void *)0) || c_label > 4194303)
    return -1;
  index = get_hash(f_label, c_value);
  while (ht[index].c_label)
    index = (index + 1) % 8388608;
  ht[index].c_label = c_label;
  ht[index].f_label = f_label;
  ht[index].c_value = c_value;
  return 0;
}

canonical_original_code:
int hashtable_insert(struct hashtable_entry *ht, unsigned long f_label, unsigned long c_label, unsigned long c_value)
{
  unsigned int index;
  if (ht == ((void *)0) || c_label > 4194303)
    return -1;
  index = get_hash(f_label, c_value);
  while (ht[index].c_label)
    index = (index + 1) % 8388608;
  ht[index].c_label = c_label;
  ht[index].f_label = f_label;
  ht[index].c_value = c_value;
  return 0;
}

variable_types: struct hashtable_entry { unsigned int f_label; unsigned int c_value; unsigned int c_label; } *

variable_types:
index
unsigned int


decompiled_code:
__int64 __fastcall hashtable_get_index(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax
_DWORD *v5; // rdx
unsigned int i; // ecx

if ( !a1 )
return -1LL;
v4 = get_hash(a2, a3);
v5 = (_DWORD *)(a1 + 12LL * v4);
for ( i = v5[2]; i; i = v5[2] )
{
if ( v5[1] == a3 && *v5 == a2 )
break;
v4 = (v4 + 1) & 0x7FFFFF;
v5 = (_DWORD *)(a1 + 12LL * v4);
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax
_DWORD *v5; // rdx
unsigned int i; // ecx

if ( !a1 )
return -1LL;
v4 = get_hash(a2, a3);
v5 = (_DWORD *)(a1 + 12LL * v4);
for ( i = v5[2]; i; i = v5[2] )
{
if ( v5[1] == a3 && *v5 == a2 )
break;
v4 = (v4 + 1) & 0x7FFFFF;
v5 = (_DWORD *)(a1 + 12LL * v4);
}
return i;
}

original_code:
env_var
hashtable_get_index(hashtable* ht, env_var f_label, env_var c_value)
{
  uint32_t h_index;
  if (ht == ((void *)0))
    return -1;
  h_index = get_hash(f_label, c_value);
  while (ht[h_index].c_label && (ht[h_index].c_value != c_value || ht[h_index].f_label != f_label))
    h_index = (h_index + 1) % 8388608;
  return ht[h_index].c_label;
}

canonical_original_code:
unsigned long hashtable_get_index(struct hashtable_entry *ht, unsigned long f_label, unsigned long c_value)
{
  unsigned int h_index;
  if (ht == ((void *)0))
    return -1;
  h_index = get_hash(f_label, c_value);
  while (ht[h_index].c_label && (ht[h_index].c_value != c_value || ht[h_index].f_label != f_label))
    h_index = (h_index + 1) % 8388608;
  return ht[h_index].c_label;
}

return_type: unsigned long

user_defined_types: struct hashtable_entry { unsigned int f_label; unsigned int c_value; unsigned int c_label; }


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

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

original_code:
void
hashtable_destroy(hashtable* ht)
{
  memset(ht, 0, 8388608* sizeof(hashtable));
  free(ht);
}

canonical_original_code:
void hashtable_destroy(struct hashtable_entry *ht)
{
  memset(ht, 0, 8388608* sizeof(hashtable));
  free(ht);
}


decompiled_code:
__int64 __fastcall init_dictionary(void *a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // rcx
unsigned int v3; // ebp

if ( !a1 )
return (unsigned int)-1;
memset(a1, 0, 0x6000000uLL);
v1 = 0LL;
while ( 1 )
{
v2 = v1++;
v3 = hashtable_insert((__int64)a1, 0LL, v1, v2);
if ( v3 == -1 )
break;
if ( v1 == 256 )
return 0;
}
hashtable_destroy(a1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // rcx
unsigned int v3; // ebp

if ( !a1 )
return (unsigned int)-1;
memset(a1, 0, 0x6000000uLL);
v1 = 0LL;
while ( 1 )
{
v2 = v1++;
v3 = func0((__int64)a1, 0LL, v1, v2);
if ( v3 == -1 )
break;
if ( v1 == 256 )
return 0;
}
func2(a1);
return v3;
}

original_code:
static int
init_dictionary(hashtable* ht)
{
  int i;
  if (ht == ((void *)0))
    return -1;
  memset(ht, 0, 8388608 * sizeof(hashtable));
  for (i = 0; i < 257 - 1; i++) {
    if (hashtable_insert(ht, 0, (env_var)i+1, (env_var)i) == -1) {
      hashtable_destroy(ht);
      return -1;
    }
  }
  return 0;
}

canonical_original_code:
static int init_dictionary(struct hashtable_entry *ht)
{
  int i;
  if (ht == ((void *)0))
    return -1;
  memset(ht, 0, 8388608 * sizeof(hashtable));
  for (i = 0; i < 257 - 1; i++) {
    if (hashtable_insert(ht, 0, (unsigned long)i+1, (unsigned long)i) == -1) {
      hashtable_destroy(ht);
      return -1;
    }
  }
  return 0;
}


decompiled_code:
void *hashtable_create()
{
void *v0; // rax
void *v1; // rbx

v0 = calloc(0x800000uLL, 0xCuLL);
v1 = v0;
if ( v0 && (unsigned int)init_dictionary(v0) == -1 )
v1 = 0LL;
return v1;
}

canonical_decompiled_code:
void *func4()
{
void *v0; // rax
void *v1; // rbx

v0 = calloc(0x800000uLL, 0xCuLL);
v1 = v0;
if ( v0 && (unsigned int)func3(v0) == -1 )
v1 = 0LL;
return v1;
}

original_code:
hashtable*
hashtable_create()
{
  hashtable* ht;
  if ((ht = (hashtable_entry*)calloc(8388608, sizeof(hashtable_entry))) == ((void *)0) )
    return ((void *)0);
  if (init_dictionary(ht) == -1)
    return ((void *)0);
  return ht;
}

canonical_original_code:
struct hashtable_entry *hashtable_create()
{
  struct hashtable_entry *ht;
  if ((ht = (struct hashtable_entry *)calloc(8388608, sizeof(hashtable_entry))) == ((void *)0) )
    return ((void *)0);
  if (init_dictionary(ht) == -1)
    return ((void *)0);
  return ht;
}

return_type: struct hashtable_entry { unsigned int f_label; unsigned int c_value; unsigned int c_label; } *


decompiled_code:
__int64 __fastcall hashtable_reset(void *a1)
{
return init_dictionary(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(void *a1)
{
return func3(a1);
}

original_code:
int
hashtable_reset(hashtable* ht)
{
  return init_dictionary(ht);
}

canonical_original_code:
int hashtable_reset(struct hashtable_entry *ht)
{
  return init_dictionary(ht);
}


decompiled_code:
__int64 __fastcall pre_append(__int64 a1, __int64 a2)
{
unsigned int v3; // esi
unsigned int v4; // edx
__int64 result; // rax

v3 = *(_DWORD *)(a1 + 16) + *(_DWORD *)(a2 + 16);
if ( *(_DWORD *)(a1 + 20) < v3 )
{
*(_DWORD *)(a1 + 20) = v3;
*(_QWORD *)(a1 + 8) = realloc(*(void **)(a1 + 8), v3);
}
v4 = *(_DWORD *)(a1 + 16);
if ( v4 )
memmove((void *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a2 + 16)), *(const void **)(a1 + 8), v4);
memcpy(*(void **)(a1 + 8), *(const void **)(a2 + 8), *(unsigned int *)(a2 + 16));
result = *(unsigned int *)(a2 + 16);
*(_DWORD *)(a1 + 16) += result;
return result;
}

original_code:
static void
pre_append(dec_table* current, dec_table* parent)
{
    if (current->word_size < (current->word_length + parent->word_length)) {
      current->word_size = current->word_length + parent->word_length;
      current->word = realloc(current->word, current->word_size);
    }
    if (current->word_length > 0) {
      memmove(current->word + parent->word_length, current->word, current->word_length);
    }
    memcpy(current->word, parent->word, parent->word_length);
    current->word_length += parent->word_length;
}

canonical_original_code:
static void pre_append(struct dec_table_entry *current, struct dec_table_entry *parent)
{
    if (current->word_size < (current->word_length + parent->word_length)) {
      current->word_size = current->word_length + parent->word_length;
      current->word = realloc(current->word, current->word_size);
    }
    if (current->word_length > 0) {
      memmove(current->word + parent->word_length, current->word, current->word_length);
    }
    memcpy(current->word, parent->word, parent->word_length);
    current->word_length += parent->word_length;
}

variable_types: struct dec_table_entry { unsigned int f_label; unsigned char *word; unsigned int word_length; unsigned int word_size; } *

variable_types:
parent
struct dec_table_entry *


decompiled_code:
void __fastcall dec_table_destroy(void *ptr)
{
void **v1; // rbx

if ( ptr )
{
v1 = (void **)((char *)ptr + 100663256);
do
{
if ( *v1 )
free(*v1);
v1 -= 3;
}
while ( v1 != (void **)((char *)ptr - 16) );
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void **v1; // rbx

if ( ptr )
{
v1 = (void **)((char *)ptr + 100663256);
do
{
if ( *v1 )
free(*v1);
v1 -= 3;
}
while ( v1 != (void **)((char *)ptr - 16) );
free(ptr);
}
}

original_code:
void
dec_table_destroy(dec_table* dt)
{
  int n = 4194303;
  if (dt == ((void *)0))
    return;
  for (; n--;)
    if(dt[n].word != 0)
      free(dt[n].word);
  memset(dt, 0, sizeof(dec_table) * 4194303);
  free(dt);
}

canonical_original_code:
void dec_table_destroy(struct dec_table_entry *dt)
{
  int n = 4194303;
  if (dt == ((void *)0))
    return;
  for (; n--;)
    if(dt[n].word != 0)
      free(dt[n].word);
  memset(dt, 0, sizeof(dec_table) * 4194303);
  free(dt);
}

variable_types: n int

user_defined_types: struct dec_table_entry { unsigned int f_label; unsigned char *word; unsigned int word_length; unsigned int word_size; }


decompiled_code:
char *dec_table_create()
{
char *v0; // rax
char *v1; // r13
char *v2; // rbp
int v3; // er12
_BYTE *v4; // rax

v0 = (char *)calloc(0x3FFFFFuLL, 0x18uLL);
v1 = v0;
if ( v0 )
{
v2 = v0 + 24;
v3 = 0;
while ( 1 )
{
*((_DWORD *)v2 + 4) = 1;
*(_DWORD *)v2 = 0;
v4 = malloc(1uLL);
*((_QWORD *)v2 + 1) = v4;
if ( !v4 )
break;
*v4 = v3++;
v2 += 24;
if ( v3 == 256 )
return v1;
}
dec_table_destroy(v1);
free(v1);
v1 = 0LL;
}
return v1;
}

original_code:
dec_table*
dec_table_create()
{
  dec_table* dt;
  int i;
  if ((dt = (dec_table*) calloc(4194303, sizeof(dec_table))) == ((void *)0))
    return ((void *)0);
  for (i = 1; i < 257; i++) {
    dt[i].word_length = 1;
    dt[i].f_label = 0;
    if ((dt[i].word = malloc(1 * sizeof(uint8_t))) == ((void *)0)) {
      dec_table_destroy(dt);
      free(dt);
      return ((void *)0);
    }
    dt[i].word[0] = (uint8_t)i - 1;
  }
  return dt;
}

canonical_original_code:
struct dec_table_entry *dec_table_create()
{
  struct dec_table_entry *dt;
  int i;
  if ((dt = (struct dec_table_entry *) calloc(4194303, sizeof(dec_table))) == ((void *)0))
    return ((void *)0);
  for (i = 1; i < 257; i++) {
    dt[i].word_length = 1;
    dt[i].f_label = 0;
    if ((dt[i].word = malloc(1 * sizeof(unsigned char))) == ((void *)0)) {
      dec_table_destroy(dt);
      free(dt);
      return ((void *)0);
    }
    dt[i].word[0] = (unsigned char)i - 1;
  }
  return dt;
}

return_type: struct dec_table_entry { unsigned int f_label; unsigned char *word; unsigned int word_length; unsigned int word_size; } *


repo: baezilisK/micecraft

decompiled_code:
void rng_init()
{
struct timeval v0; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v0, 0LL);
srand(LODWORD(v0.tv_sec) * LODWORD(v0.tv_usec));
}

canonical_decompiled_code:
void func0()
{
struct timeval v0; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v0, 0LL);
srand(LODWORD(v0.tv_sec) * LODWORD(v0.tv_usec));
}

original_code:
void rng_init (void) {
  struct timeval tv;
  gettimeofday (&tv, ((void *)0));
  srand (tv.tv_sec * tv.tv_usec);
}

canonical_original_code:
void rng_init() {
  struct timeval tv;
  gettimeofday (&tv, ((void *)0));
  srand (tv.tv_sec * tv.tv_usec);
}

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


decompiled_code:
__int64 __fastcall rng_i(int a1)
{
return (unsigned int)(rand() / (0x7FFFFFFF / a1 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)(rand() / (0x7FFFFFFF / a1 + 1));
}


decompiled_code:
float rng_f()
{
return (float)rand() * 4.6566129e-10;
}

canonical_decompiled_code:
float func2()
{
return (float)rand() * 4.6566129e-10;
}

original_code:
float rng_f (void) {
  return (float) rand () / 2147483647;
}

canonical_original_code:
float rng_f() {
  return (float) rand () / 2147483647;
}

return_type: float


decompiled_code:
void rng_free()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void rng_free (void) {
}

canonical_original_code:
void rng_free() {
}


getdx

decompiled_code:
void __fastcall getdx(float *a1)
{
double v1; // rbx
float v2; // xmm0_4
double v3; // rbx
float v4; // xmm0_4
float v5; // xmm0_4
double v6; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = cos(*(float *)&cam_ti);
v2 = v1 * cos(*(float *)&cam_tj);
*a1 = v2;
v3 = sin(*(float *)&cam_ti);
sincos(*(float *)&cam_tj, sinx, &v6);
v4 = v3 * v6;
a1[1] = v4;
v5 = sinx[0];
a1[2] = v5;
}

canonical_decompiled_code:
void __fastcall func0(float *a1)
{
double v1; // rbx
float v2; // xmm0_4
double v3; // rbx
float v4; // xmm0_4
float v5; // xmm0_4
double v6; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = cos(*(float *)&cam_ti);
v2 = v1 * cos(*(float *)&cam_tj);
*a1 = v2;
v3 = sin(*(float *)&cam_ti);
sincos(*(float *)&cam_tj, sinx, &v6);
v4 = v3 * v6;
a1[1] = v4;
v5 = sinx[0];
a1[2] = v5;
}

original_code:
static void getdx (float *dx) {
  dx[0] = cos (cam_ti) * cos (cam_tj);
  dx[1] = sin (cam_ti) * cos (cam_tj);
  dx[2] = sin (cam_tj);
}

canonical_original_code:
static void getdx(float *dx) {
  dx[0] = cos (cam_ti) * cos (cam_tj);
  dx[1] = sin (cam_ti) * cos (cam_tj);
  dx[2] = sin (cam_tj);
}

variable_types:
dx
float *


decompiled_code:
__int64 __fastcall cam_mv(float a1, float a2, float a3)
{
double v3; // r14
double v4; // rbp
double v5; // rbx
__m128i v6; // xmm4
float v7; // ebp
__int64 result; // rax
float v9; // [rsp+10h] [rbp-38h]
double cosx; // [rsp+20h] [rbp-28h] BYREF
double sinx[4]; // [rsp+28h] [rbp-20h] BYREF

v3 = *(float *)&cam_ti;
sincos(*(float *)&cam_ti, sinx, &cosx);
v4 = cosx;
v5 = sinx[0];
sincos(v3 - 1.570796326795, sinx, &cosx);
v6 = 0LL;
*(float *)v6.m128i_i32 = v4 * a1 + a2 * cosx;
v7 = COERCE_FLOAT(_mm_cvtsi128_si32(v6));
*(float *)v6.m128i_i32 = a2 * sinx[0] + v5 * a1;
v9 = *(float *)v6.m128i_i32;
result = map_get(
(unsigned int)(int)(float)(v7 + *(float *)&cam_x),
(unsigned int)(int)(float)(*(float *)v6.m128i_i32 + *(float *)&cam_y),
(unsigned int)(int)(float)(a3 + *(float *)&cam_z));
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(float *)&cam_x = v7 + *(float *)&cam_x;
*(float *)&cam_y = v9 + *(float *)&cam_y;
*(float *)&cam_z = a3 + *(float *)&cam_z;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(float a1, float a2, float a3)
{
double v3; // r14
double v4; // rbp
double v5; // rbx
__m128i v6; // xmm4
float v7; // ebp
__int64 result; // rax
float v9; // [rsp+10h] [rbp-38h]
double cosx; // [rsp+20h] [rbp-28h] BYREF
double sinx[4]; // [rsp+28h] [rbp-20h] BYREF

v3 = *(float *)&cam_ti;
sincos(*(float *)&cam_ti, sinx, &cosx);
v4 = cosx;
v5 = sinx[0];
sincos(v3 - 1.570796326795, sinx, &cosx);
v6 = 0LL;
*(float *)v6.m128i_i32 = v4 * a1 + a2 * cosx;
v7 = COERCE_FLOAT(_mm_cvtsi128_si32(v6));
*(float *)v6.m128i_i32 = a2 * sinx[0] + v5 * a1;
v9 = *(float *)v6.m128i_i32;
result = map_get(
(unsigned int)(int)(float)(v7 + *(float *)&cam_x),
(unsigned int)(int)(float)(*(float *)v6.m128i_i32 + *(float *)&cam_y),
(unsigned int)(int)(float)(a3 + *(float *)&cam_z));
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(float *)&cam_x = v7 + *(float *)&cam_x;
*(float *)&cam_y = v9 + *(float *)&cam_y;
*(float *)&cam_z = a3 + *(float *)&cam_z;
return result;
}

original_code:
int cam_mv (float x, float y, float z) {
  int ret = -1;
  float
    dx = x * cos (cam_ti) + y * cos (cam_ti - 3.14159265359/2),
    dy = x * sin (cam_ti) + y * sin (cam_ti - 3.14159265359/2),
    dz = z;
  int i = cam_x + dx, j = cam_y + dy, k = cam_z + dz;
  if (!map_get (i, j, k)) {
    cam_x += dx; cam_y += dy; cam_z += dz;
    ret = 0;
  }
  return ret;
}

canonical_original_code:
int cam_mv(float x, float y, float z) {
  int ret = -1;
  float dx = x * cos (cam_ti) + y * cos (cam_ti - 3.14159265359/2); float dy = x * sin (cam_ti) + y * sin (cam_ti - 3.14159265359/2); float dz = z;
  int i = cam_x + dx; int j = cam_y + dy; int k = cam_z + dz;
  if (!map_get (i, j, k)) {
    cam_x += dx; cam_y += dy; cam_z += dz;
    ret = 0;
  }
  return ret;
}

variable_types: x float

variable_types: y float

variable_types: z float

variable_types: ret int

variable_types: dx float

variable_types: dy float

variable_types: dz float

variable_types: i int

variable_types: j int

variable_types: k int


decompiled_code:
__int64 cam_sync()
{
int v1[5]; // [rsp+10h] [rbp-14h] BYREF

getdx((float *)v1);
glMatrixMode(5888LL);
glLoadIdentity();
return gluLookAt(
*(float *)&cam_x,
*(float *)&cam_y,
*(float *)&cam_z,
(float)(*(float *)&cam_x + *(float *)v1),
(float)(*(float *)&cam_y + *(float *)&v1[1]),
(float)(*(float *)&cam_z + *(float *)&v1[2]),
0.0);
}

canonical_decompiled_code:
__int64 func3()
{
int v1[5]; // [rsp+10h] [rbp-14h] BYREF

func0((float *)v1);
glMatrixMode(5888LL);
glLoadIdentity();
return gluLookAt(
*(float *)&cam_x,
*(float *)&cam_y,
*(float *)&cam_z,
(float)(*(float *)&cam_x + *(float *)v1),
(float)(*(float *)&cam_y + *(float *)&v1[1]),
(float)(*(float *)&cam_z + *(float *)&v1[2]),
0.0);
}

original_code:
void cam_sync (void) {
  float dx[3];
  getdx (dx);
  glMatrixMode (0x1700);
  glLoadIdentity ();
  gluLookAt (
    cam_x, cam_y, cam_z,
    cam_x + dx[0], cam_y + dx[1], cam_z + dx[2],
    0, 0, 1
  );
}

canonical_original_code:
void cam_sync() {
  float dx[3];
  getdx (dx);
  glMatrixMode (0x1700);
  glLoadIdentity ();
  gluLookAt (
    cam_x, cam_y, cam_z,
    cam_x + dx[0], cam_y + dx[1], cam_z + dx[2],
    0, 0, 1
  );
}

variable_types:
dx
float [3]


decompiled_code:
void terrain_init()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void terrain_init (void) {
}

canonical_original_code:
void terrain_init() {
}


decompiled_code:
float __fastcall terrain_h(float a1)
{
return sin((float)(a1 / 3.0)) * 4.0;
}

canonical_decompiled_code:
float __fastcall func1(float a1)
{
return sin((float)(a1 / 3.0)) * 4.0;
}

original_code:
float terrain_h (float x, float y) {
  (void) y;
  return 4 * sin (x / 3);
}

canonical_original_code:
float terrain_h(float x, float y) {
  (void) y;
  return 4 * sin (x / 3);
}


decompiled_code:
void terrain_del()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void terrain_del (void) {
}

canonical_original_code:
void terrain_del() {
}


original_code:
void map_gen (void) {
  int i, j, k, l;
  terrain_init ();
  for (l = 0; l < (sizeof(chunks) / sizeof *(chunks)); ++l)
    for (i = 0; i < 8; ++i)
      for (j = 0; j < 8; ++j)
        for (k = 0; k < 128; ++k)
          chunks[l][i][j][k] = rng_f () < 0.05;
  terrain_del ();
}

canonical_original_code:
void map_gen() {
  int i; int j; int k; int l;
  terrain_init ();
  for (l = 0; l < (sizeof(chunks) / sizeof *(chunks)); ++l)
    for (i = 0; i < 8; ++i)
      for (j = 0; j < 8; ++j)
        for (k = 0; k < 128; ++k)
          chunks[l][i][j][k] = rng_f () < 0.05;
  terrain_del ();
}

variable_types: l int


decompiled_code:
__int64 __fastcall map_set(int a1, int a2, int a3, int a4)
{
__int64 result; // rax

result = a3;
chunks[128 * (a2 + 8LL * a1) + a3] = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, int a4)
{
__int64 result; // rax

result = a3;
chunks[128 * (a2 + 8LL * a1) + a3] = a4;
return result;
}

original_code:
void map_set (int i, int j, int k, int val) {
  chunks[0][i][j][k] = val;
}

canonical_original_code:
void map_set(int i, int j, int k, int val) {
  chunks[0][i][j][k] = val;
}

variable_types: val int


decompiled_code:
__int64 __fastcall map_get(unsigned int a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax

if ( a3 > 8 || a2 > 8 || a1 > 0x20 )
result = 0LL;
else
result = (unsigned int)chunks[128 * ((int)a2 + 8LL * (int)a1) + (int)a3];
return result;
}

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

if ( a3 > 8 || a2 > 8 || a1 > 0x20 )
result = 0LL;
else
result = (unsigned int)chunks[128 * ((int)a2 + 8LL * (int)a1) + (int)a3];
return result;
}

original_code:
int map_get (int i, int j, int k) {
  if (i < 0 || j < 0 || k < 0) return 0;
  if (i > 32 || j > 8 || k > 8) return 0;
  return chunks[0][i][j][k];
}

canonical_original_code:
int map_get(int i, int j, int k) {
  if (i < 0 || j < 0 || k < 0) return 0;
  if (i > 32 || j > 8 || k > 8) return 0;
  return chunks[0][i][j][k];
}


decompiled_code:
float __fastcall map_height(float a1, float a2, float a3)
{
signed int v3; // ebx

v3 = (int)a3;
if ( a1 >= 1000.0 || a2 >= 1000.0 || a3 >= 1000.0 )
_assert_fail("x < a && y < a && z < a", "src/map.c", 0x25u, "map_height");
if ( v3 >= 0 )
{
do
{
if ( (unsigned int)map_get((int)a1, (int)a2, v3) )
break;
--v3;
}
while ( v3 != -1 );
}
return a3 - (float)(v3 + 1);
}

canonical_decompiled_code:
float __fastcall func3(float a1, float a2, float a3)
{
signed int v3; // ebx

v3 = (int)a3;
if ( a1 >= 1000.0 || a2 >= 1000.0 || a3 >= 1000.0 )
_assert_fail("x < a && y < a && z < a", "src/map.c", 0x25u, "map_height");
if ( v3 >= 0 )
{
do
{
if ( (unsigned int)func2((int)a1, (int)a2, v3) )
break;
--v3;
}
while ( v3 != -1 );
}
return a3 - (float)(v3 + 1);
}

original_code:
float map_height (float x, float y, float z) {
  float a = 1000;
  int i = x, j = y, k = z;
  ((x < a && y < a && z < a) ? (void) (0) : __assert_fail ("x < a && y < a && z < a", "src/map.c", 37, __extension__ __PRETTY_FUNCTION__));
  for (; k >= 0 && !map_get (i, j, k); --k);
  return z - (k + 1);
}

canonical_original_code:
float map_height(float x, float y, float z) {
  float a = 1000;
  int i = x; int j = y; int k = z;
  ((x < a && y < a && z < a) ? (void) (0) : __assert_fail ("x < a && y < a && z < a", "src/map.c", 37, __extension__ __PRETTY_FUNCTION__));
  for (; k >= 0 && !map_get (i, j, k); --k);
  return z - (k + 1);
}

variable_types: a float


decompiled_code:
__int64 map_display()
{
const char *v0; // rbx
int v1; // ebp
__m128i v2; // xmm6
__int64 result; // rax

v0 = (const char *)chunks;
v1 = 0;
do
{
glColor3f(0.0, 0.0, 1.0);
v2 = 0LL;
*(float *)v2.m128i_i32 = (float)v1;
ugl_rprism(*(double *)v2.m128i_i64, 0.0, 0.0, 8.0, 8.0, 128.0);
result = chunk_display(v0, *(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v2)).m128i_i64);
v1 += 8;
v0 += 0x8000;
}
while ( v0 != "src/map.c" );
return result;
}

original_code:
void map_display (void) {
  int i;
  for (i = 0; i < (sizeof(chunks) / sizeof *(chunks)); ++i) {
    glColor3f (0, 0, 1);
    ugl_rprism (8*i, 0, 0, 8, 8, 128);
    chunk_display (chunks[i], i * 8);
  }
}

canonical_original_code:
void map_display() {
  int i;
  for (i = 0; i < (sizeof(chunks) / sizeof *(chunks)); ++i) {
    glColor3f (0, 0, 1);
    ugl_rprism (8*i, 0, 0, 8, 8, 128);
    chunk_display (chunks[i], i * 8);
  }
}


decompiled_code:
void map_del()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void map_del (void) {
}

canonical_original_code:
void map_del() {
}


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
if ( a1 )
{
fwrite("out of memory\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
if ( a1 )
{
fwrite("out of memory\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
}
return result;
}

original_code:
void *xmalloc (size_t n) {
  void *ret = malloc (n);
  if (!ret && n) {
    fprintf (stderr, "out of memory\n");
    exit (1);
  }
  return ret;
}

canonical_original_code:
void *xmalloc(unsigned long n) {
  void *ret = malloc (n);
  if (!ret && n) {
    fprintf (stderr, "out of memory\n");
    exit (1);
  }
  return ret;
}

variable_types:
n
unsigned long

variable_types:
ret
void *

return_type: void *


decompiled_code:
__int64 __fastcall kbd_glutkeydown(unsigned __int8 a1)
{
__int64 result; // rax

result = (unsigned __int8)kbd_map[a1];
kbd_state[result] = 1;
kbd_toggle[result] ^= 1u;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
__int64 result; // rax

result = (unsigned __int8)kbd_map[a1];
kbd_state[result] = 1;
kbd_toggle[result] ^= 1u;
return result;
}

original_code:
void kbd_glutkeydown (unsigned char key, int x, int y) {
  (void) x; (void) y;
  kbd_state[kbd_map[key]] = 1;
  kbd_toggle[kbd_map[key]] ^= 1;
}

canonical_original_code:
void kbd_glutkeydown(unsigned char key, int x, int y) {
  (void) x; (void) y;
  kbd_state[kbd_map[key]] = 1;
  kbd_toggle[kbd_map[key]] ^= 1;
}

variable_types:
key
unsigned char

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall kbd_glutkeyup(unsigned __int8 a1)
{
__int64 result; // rax

result = (unsigned __int8)kbd_map[a1];
kbd_state[result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
__int64 result; // rax

result = (unsigned __int8)kbd_map[a1];
kbd_state[result] = 0;
return result;
}

original_code:
void kbd_glutkeyup (unsigned char key, int x, int y) {
  (void) x; (void) y;
  kbd_state[kbd_map[key]] = 0;
}

canonical_original_code:
void kbd_glutkeyup(unsigned char key, int x, int y) {
  (void) x; (void) y;
  kbd_state[kbd_map[key]] = 0;
}


display

repo: baezilisK/paint

decompiled_code:
__int64 display()
{
if ( draw )
glBegin();
glColor3f();
glVertex2f();
glVertex2f();
glEnd();
printf("displayed %d %d\n", (unsigned int)mousex, (unsigned int)mousey);
return glFlush();
}

canonical_decompiled_code:
__int64 func7()
{
if ( draw )
glBegin();
glColor3f();
glVertex2f();
glVertex2f();
glEnd();
printf("displayed %d %d\n", (unsigned int)mousex, (unsigned int)mousey);
return glFlush();
}

original_code:
void display (void) {
  if (draw) glBegin (0x0003);
    glColor3f (r, g, b);
    glVertex2f (mousexx, mouseyy); glVertex2f (mousex, mousey);
  glEnd ();
  printf ("displayed %d %d\n", mousex, mousey);
  glFlush ();
}

canonical_original_code:
void display() {
  if (draw) glBegin (0x0003);
    glColor3f (r, g, b);
    glVertex2f (mousexx, mouseyy); glVertex2f (mousex, mousey);
  glEnd ();
  printf ("displayed %d %d\n", mousex, mousey);
  glFlush ();
}


reshape

decompiled_code:
__int64 reshape()
{
glViewport();
glLoadIdentity();
return glOrtho();
}

canonical_decompiled_code:
__int64 func8()
{
glViewport();
glLoadIdentity();
return glOrtho();
}

original_code:
void reshape (int w, int h) {
  glViewport (0, 0, w, h);
  glLoadIdentity ();
  glOrtho (0, w, 0, h, -1, 1);
}

canonical_original_code:
void reshape(int w, int h) {
  glViewport (0, 0, w, h);
  glLoadIdentity ();
  glOrtho (0, w, 0, h, -1, 1);
}

variable_types: w int

variable_types: h int


mouse

decompiled_code:
_BOOL8 __fastcall mouse(unsigned int a1, unsigned int a2, unsigned int a3, int a4)
{
_BOOL8 result; // rax
int v7; // [rsp+Ch] [rbp-2Ch]

glGetIntegerv();
printf("mouse %d %d %d %d\n", a1, a2, a3, (unsigned int)(v7 - a4));
result = a2 == 0;
draw = a2 == 0;
if ( !a2 )
{
mousex = a3;
mousexx = a3;
mousey = v7 - a4;
mouseyy = v7 - a4;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(unsigned int a1, unsigned int a2, unsigned int a3, int a4)
{
_BOOL8 result; // rax
int v7; // [rsp+Ch] [rbp-2Ch]

glGetIntegerv();
printf("mouse %d %d %d %d\n", a1, a2, a3, (unsigned int)(v7 - a4));
result = a2 == 0;
draw = a2 == 0;
if ( !a2 )
{
mousex = a3;
mousexx = a3;
mousey = v7 - a4;
mouseyy = v7 - a4;
}
return result;
}

original_code:
void mouse (int button, int state, int x, int y) {
  int vp[4]; glGetIntegerv (0x0BA2, vp); y = vp[3] - y;
  printf ("mouse %d %d %d %d\n", button, state, x, y);
  if (draw = state == 0x0000, draw) {
    mousexx = mousex = x;
    mouseyy = mousey = y;
  }
}

canonical_original_code:
void mouse(int button, int state, int x, int y) {
  int vp[4]; glGetIntegerv (0x0BA2, vp); y = vp[3] - y;
  printf ("mouse %d %d %d %d\n", button, state, x, y);
  if (draw = state == 0x0000, draw) {
    mousexx = mousex = x;
    mouseyy = mousey = y;
  }
}

variable_types: button int

variable_types: state int

variable_types:
vp
int [4]


trackmouse

decompiled_code:
__int64 __fastcall trackmouse(int a1, int a2)
{
int v3; // [rsp+Ch] [rbp-1Ch]

glGetIntegerv();
mousexx = mousex;
mouseyy = mousey;
mousex = a1;
mousey = v3 - a2;
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
int v3; // [rsp+Ch] [rbp-1Ch]

glGetIntegerv();
mousexx = mousex;
mouseyy = mousey;
mousex = a1;
mousey = v3 - a2;
return glutPostRedisplay();
}

original_code:
void trackmouse (int x, int y) {
  int vp[4]; glGetIntegerv (0x0BA2, vp);
  mousexx = mousex, mouseyy = mousey;
  mousex = x; mousey = vp[3] -y;
  glutPostRedisplay ();
}

canonical_original_code:
void trackmouse(int x, int y) {
  int vp[4]; glGetIntegerv (0x0BA2, vp);
  mousexx = mousex, mouseyy = mousey;
  mousex = x; mousey = vp[3] -y;
  glutPostRedisplay ();
}


keyboard

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

if ( a1 == 27 )
exit(0);
if ( a1 == 36 )
{
glClear();
result = glutPostRedisplay();
LABEL_9:
if ( a1 == 40 )
{
b ^= 1u;
return result;
}
goto LABEL_12;
}
if ( a1 != 123 )
{
if ( a1 == 125 )
{
g ^= 1u;
return result;
}
goto LABEL_9;
}
r ^= 1u;
LABEL_12:
if ( a1 == 61 )
{
b = 0;
g = 0;
r = 0;
}
return result;
}

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

if ( a1 == 27 )
exit(0);
if ( a1 == 36 )
{
glClear();
result = glutPostRedisplay();
LABEL_9:
if ( a1 == 40 )
{
b ^= 1u;
return result;
}
goto LABEL_12;
}
if ( a1 != 123 )
{
if ( a1 == 125 )
{
g ^= 1u;
return result;
}
goto LABEL_9;
}
r ^= 1u;
LABEL_12:
if ( a1 == 61 )
{
b = 0;
g = 0;
r = 0;
}
return result;
}

original_code:
void keyboard (unsigned char key, int x, int y) {
  (void) x; (void) y;
  if (key == 0x1B) exit (0);
  if (key == '$') glClear (0x00004000), glutPostRedisplay ();
  if (key == '{') r ^= 1;
  if (key == '}') g ^= 1;
  if (key == '(') b ^= 1;
  if (key == '=') r = g = b = 0;
}

canonical_original_code:
void keyboard(unsigned char key, int x, int y) {
  (void) x; (void) y;
  if (key == 0x1B) exit (0);
  if (key == '$') glClear (0x00004000), glutPostRedisplay ();
  if (key == '{') r ^= 1;
  if (key == '}') g ^= 1;
  if (key == '(') b ^= 1;
  if (key == '=') r = g = b = 0;
}


init

decompiled_code:
__int64 init()
{
glClearColor();
return glClear();
}

canonical_decompiled_code:
__int64 func12()
{
glClearColor();
return glClear();
}

original_code:
void init (void) {
  glClearColor (0, 0, 0, 0);
  glClear (0x00004000);
}

canonical_original_code:
void init() {
  glClearColor (0, 0, 0, 0);
  glClear (0x00004000);
}


main

canonical_name: main

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

glutInit();
glutInitDisplayMode();
glutInitWindowSize();
v3 = *argv;
glutCreateWindow();
init(v3, 300LL);
glutDisplayFunc();
glutReshapeFunc();
glutMouseFunc();
glutKeyboardFunc();
glutMotionFunc();
glutMainLoop();
exit(1);
}

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

glutInit();
glutInitDisplayMode();
glutInitWindowSize();
v3 = *argv;
glutCreateWindow();
func12(v3, 300LL);
glutDisplayFunc();
glutReshapeFunc();
glutMouseFunc();
glutKeyboardFunc();
glutMotionFunc();
glutMainLoop();
exit(1);
}

original_code:
int main (int argc, char **argv) {
  glutInit (&argc, argv);
  glutInitDisplayMode (0x0000 | 0x0000);
  glutInitWindowSize (300, 300);
  glutCreateWindow (argv[0]);
  init ();
  glutDisplayFunc (display);
  glutReshapeFunc (reshape);
  glutMouseFunc (mouse);
  glutKeyboardFunc (keyboard);
  glutMotionFunc (trackmouse);
  glutMainLoop ();
  exit (1);
}

canonical_original_code:
int main(int argc, char **argv) {
  glutInit (&argc, argv);
  glutInitDisplayMode (0x0000 | 0x0000);
  glutInitWindowSize (300, 300);
  glutCreateWindow (argv[0]);
  init ();
  glutDisplayFunc (display);
  glutReshapeFunc (reshape);
  glutMouseFunc (mouse);
  glutKeyboardFunc (keyboard);
  glutMotionFunc (trackmouse);
  glutMainLoop ();
  exit (1);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall find_max_func(_DWORD *a1, unsigned int *a2)
{
__int64 result; // rax

result = *a2;
if ( (int)result > *a1 )
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, unsigned int *a2)
{
__int64 result; // rax

result = *a2;
if ( (int)result > *a1 )
*a1 = result;
return result;
}

original_code:
static void find_max_func(void *max_val, void *data)
{
    if ( *((int*)data) > *((int*)max_val) )
    {
        *((int*)max_val) = *((int*)data);
    }
}

canonical_original_code:
static void find_max_func(void *max_val, void *data)
{
    if ( *((int *)data) > *((int *)max_val) )
    {
        *((int *)max_val) = *((int *)data);
    }
}

variable_types:
data
void *


decompiled_code:
int __fastcall print_data_func(int *a1, unsigned int *a2)
{
bool v2; // zf
int result; // eax

printf("%d", *a2);
v2 = *a1 == 1;
result = *a1 - 1;
*a1 = result;
if ( !v2 )
result = printf(", ");
return result;
}

canonical_decompiled_code:
int __fastcall func9(int *a1, unsigned int *a2)
{
bool v2; // zf
int result; // eax

printf("%d", *a2);
v2 = *a1 == 1;
result = *a1 - 1;
*a1 = result;
if ( !v2 )
result = printf(", ");
return result;
}

original_code:
static void print_data_func(void *remaining_size, void *data)
{
    printf("%d", *(int*)data);
    (*((int*)remaining_size))--;
    if (*((int*)remaining_size) != 0)
    {
        printf(", ");
    }
}

canonical_original_code:
static void print_data_func(void *remaining_size, void *data)
{
    printf("%d", *(int *)data);
    (*((int *)remaining_size))--;
    if (*((int *)remaining_size) != 0)
    {
        printf(", ");
    }
}


decompiled_code:
char *__fastcall get_cmd_args(char *dest, char *a2, char *a3)
{
char *result; // rax
__int64 v6; // rbx
int v7; // ebp
int v8; // esi
int v9; // edx
int v10; // edx
char v11; // [rsp+1h] [rbp-59h]
char v12[88]; // [rsp+2h] [rbp-58h] BYREF

if ( !fgets(v12, 39, _bss_start) )
{
perror("fgets");
exit(1);
}
*(_QWORD *)dest = 0LL;
*((_DWORD *)dest + 2) = 0;
dest[12] = 0;
*(_QWORD *)a2 = 0LL;
*((_DWORD *)a2 + 2) = 0;
a2[12] = 0;
*(_QWORD *)a3 = 0LL;
*((_DWORD *)a3 + 2) = 0;
a3[12] = 0;
LOBYTE(result) = v12[0];
if ( v12[0] == 10 )
{
v9 = 0;
v8 = 0;
return strncpy(dest, &v12[v8], v9 - v8);
}
v6 = 1LL;
v7 = 0;
v8 = 0;
do
{
v10 = v6 - 1;
if ( (_BYTE)result == 32 )
{
if ( v7 )
{
if ( v7 == 1 )
strncpy(a2, &v12[v8], v10 - v8);
}
else
{
strncpy(dest, &v12[v8], v10 - v8);
}
++v7;
v8 = v6;
}
v9 = v6++;
result = (char *)(unsigned __int8)*(&v11 + v6);
}
while ( (_BYTE)result != 10 );
switch ( v7 )
{
case 0:
return strncpy(dest, &v12[v8], v9 - v8);
case 1:
return strncpy(a2, &v12[v8], v9 - v8);
case 2:
result = strncpy(a3, &v12[v8], v9 - v8);
break;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func11(char *dest, char *a2, char *a3)
{
char *result; // rax
__int64 v6; // rbx
int v7; // ebp
int v8; // esi
int v9; // edx
int v10; // edx
char v11; // [rsp+1h] [rbp-59h]
char v12[88]; // [rsp+2h] [rbp-58h] BYREF

if ( !fgets(v12, 39, _bss_start) )
{
perror("fgets");
exit(1);
}
*(_QWORD *)dest = 0LL;
*((_DWORD *)dest + 2) = 0;
dest[12] = 0;
*(_QWORD *)a2 = 0LL;
*((_DWORD *)a2 + 2) = 0;
a2[12] = 0;
*(_QWORD *)a3 = 0LL;
*((_DWORD *)a3 + 2) = 0;
a3[12] = 0;
LOBYTE(result) = v12[0];
if ( v12[0] == 10 )
{
v9 = 0;
v8 = 0;
return strncpy(dest, &v12[v8], v9 - v8);
}
v6 = 1LL;
v7 = 0;
v8 = 0;
do
{
v10 = v6 - 1;
if ( (_BYTE)result == 32 )
{
if ( v7 )
{
if ( v7 == 1 )
strncpy(a2, &v12[v8], v10 - v8);
}
else
{
strncpy(dest, &v12[v8], v10 - v8);
}
++v7;
v8 = v6;
}
v9 = v6++;
result = (char *)(unsigned __int8)*(&v11 + v6);
}
while ( (_BYTE)result != 10 );
switch ( v7 )
{
case 0:
return strncpy(dest, &v12[v8], v9 - v8);
case 1:
return strncpy(a2, &v12[v8], v9 - v8);
case 2:
result = strncpy(a3, &v12[v8], v9 - v8);
break;
}
return result;
}

original_code:
static void get_cmd_args(char cmd[], char arg1[], char arg2[])
{
    char buf[(13 + 13 + 13)];
    int start_idx, end_idx, word_cnt;
    if (((void *)0) == fgets(buf, (13 + 13 + 13), stdin))
    {
        perror("fgets");
        exit(1);
    }
    memset(cmd, '\0', 13);
    memset(arg1, '\0', 13);
    memset(arg2, '\0', 13);
    start_idx = 0;
    end_idx = 0;
    word_cnt = 0;
    while (buf[end_idx] != '\n')
    {
        if (buf[end_idx] == ' ')
        {
            if (word_cnt == 0)
            {
                strncpy(cmd, &buf[start_idx], end_idx - start_idx);
            }
            else if (word_cnt == 1)
            {
                strncpy(arg1, &buf[start_idx], end_idx - start_idx);
            }
            word_cnt++;
            start_idx = end_idx + 1;
        }
        end_idx++;
    }
    if (word_cnt == 0)
    {
        strncpy(cmd, &buf[start_idx], end_idx - start_idx);
    }
    else if (word_cnt == 1)
    {
        strncpy(arg1, &buf[start_idx], end_idx - start_idx);
    }
    else if (word_cnt == 2)
    {
        strncpy(arg2, &buf[start_idx], end_idx - start_idx);
    }
}

canonical_original_code:
static void get_cmd_args(char cmd[], char arg1[], char arg2[])
{
    char buf[-1];
    int start_idx; int end_idx; int word_cnt;
    if (((void *)0) == fgets(buf, (13 + 13 + 13), stdin))
    {
        perror("fgets");
        exit(1);
    }
    memset(cmd, '\0', 13);
    memset(arg1, '\0', 13);
    memset(arg2, '\0', 13);
    start_idx = 0;
    end_idx = 0;
    word_cnt = 0;
    while (buf[end_idx] != '\n')
    {
        if (buf[end_idx] == ' ')
        {
            if (word_cnt == 0)
            {
                strncpy(cmd, &buf[start_idx], end_idx - start_idx);
            }
            else if (word_cnt == 1)
            {
                strncpy(arg1, &buf[start_idx], end_idx - start_idx);
            }
            word_cnt++;
            start_idx = end_idx + 1;
        }
        end_idx++;
    }
    if (word_cnt == 0)
    {
        strncpy(cmd, &buf[start_idx], end_idx - start_idx);
    }
    else if (word_cnt == 1)
    {
        strncpy(arg1, &buf[start_idx], end_idx - start_idx);
    }
    else if (word_cnt == 2)
    {
        strncpy(arg2, &buf[start_idx], end_idx - start_idx);
    }
}

variable_types:
cmd
char []

variable_types:
buf
char [-1]


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

result = malloc(0x10uLL);
if ( !result )
{
perror("dlist_create malloc() failed");
exit(1);
}
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
if ( !result )
{
perror("dlist_create malloc() failed");
exit(1);
}
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
DList *dlist_create(void)
{
    DList *thiz = (DList *)malloc(sizeof(DList));
    if (thiz == ((void *)0))
    {
        perror("dlist_create malloc() failed");
        exit(1);
    }
    thiz->head = ((void *)0);
    thiz->size = 0;
    return thiz;
}

canonical_original_code:
struct _DList *dlist_create()
{
    struct _DList *thiz = (DList *)malloc(sizeof(DList));
    if (thiz == ((void *)0))
    {
        perror("dlist_create malloc() failed");
        exit(1);
    }
    thiz->head = ((void *)0);
    thiz->size = 0;
    return thiz;
}

variable_types: struct _DList { struct _DListNode { void *pdata; struct _DListNode *prev; struct _DListNode *next; } *head; unsigned long size; } *

user_defined_types: struct _DList { struct _DListNode *head; unsigned long size; }


decompiled_code:
__int64 __fastcall dlist_size(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
size_t dlist_size(DList *thiz)
{
    return thiz->size;
}

canonical_original_code:
unsigned long dlist_size(struct _DList *thiz)
{
    return thiz->size;
}

user_defined_types: struct _DListNode { void *pdata; struct _DListNode *prev; struct _DListNode *next; }


decompiled_code:
__int64 __fastcall dlist_foreach(_QWORD *a1, void (__fastcall *a2)(__int64, _QWORD), __int64 a3)
{
_QWORD *v3; // rbx
unsigned int v5; // ebp
__int64 result; // rax

v3 = (_QWORD *)*a1;
if ( a1[1] )
{
v5 = 0;
do
{
a2(a3, *v3);
v3 = (_QWORD *)v3[2];
result = ++v5;
}
while ( (unsigned __int64)v5 < a1[1] );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(_QWORD *a1, void (__fastcall *a2)(__int64, _QWORD), __int64 a3)
{
_QWORD *v3; // rbx
unsigned int v5; // ebp
__int64 result; // rax

v3 = (_QWORD *)*a1;
if ( a1[1] )
{
v5 = 0;
do
{
a2(a3, *v3);
v3 = (_QWORD *)v3[2];
result = ++v5;
}
while ( (unsigned __int64)v5 < a1[1] );
}
return result;
}

original_code:
void dlist_foreach(DList *thiz, DListVisitFunc data_func, void *ctx)
{
    struct _DListNode *iter;
    unsigned int idx;
    iter = thiz->head;
    idx = 0;
    while (idx < thiz->size)
    {
        data_func(ctx, iter->pdata);
        iter = iter->next;
        idx++;
    }
}

canonical_original_code:
void dlist_foreach(struct _DList *thiz, void (*data_func)(void *ctx, void *data), void *ctx)
{
    struct _DListNode *iter;
    unsigned int idx;
    iter = thiz->head;
    idx = 0;
    while (idx < thiz->size)
    {
        data_func(ctx, iter->pdata);
        iter = iter->next;
        idx++;
    }
}

variable_types:
ctx
void *

variable_types: struct _DListNode { void *pdata; struct _DListNode *prev; struct _DListNode *next; } *

variable_types:
idx
unsigned int


decompiled_code:
int __fastcall dlist_insert(_QWORD *a1, unsigned __int64 a2, __int64 a3)
{
unsigned __int64 v3; // r13
_QWORD *v5; // rax
_QWORD *v6; // rdx
_QWORD *v7; // rcx
__int64 i; // rax

v3 = a1[1];
if ( v3 < a2 )
{
LODWORD(v5) = printf("idx %zu is out of range[0..%zu]\n", a2, a1[1]);
}
else
{
v5 = malloc(0x18uLL);
v6 = v5;
if ( !v5 )
{
perror("new_node_p malloc");
exit(1);
}
*v5 = a3;
v5[2] = 0LL;
v5[1] = 0LL;
if ( v3 )
{
v7 = (_QWORD *)*a1;
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
v7 = (_QWORD *)v7[2];
}
v5 = (_QWORD *)v7[1];
}
else
{
v7 = v5;
}
v6[2] = v7;
v6[1] = v5;
v7[1] = v6;
v5[2] = v6;
if ( !a2 )
*a1 = v6;
++a1[1];
}
return (int)v5;
}

original_code:
void dlist_insert(DList *thiz, size_t idx, void *pdata)
{
    size_t i;
    struct _DListNode *new_node_p = ((void *)0);
    struct _DListNode *node_of_idx_p = ((void *)0);
    struct _DListNode *prev_node_of_idx_p = ((void *)0);
    if (idx > thiz->size)
    {
        printf("idx %zu is out of range[0..%zu]\n", idx, thiz->size);
        return;
    }
    new_node_p = (struct _DListNode *)malloc(sizeof(struct _DListNode));
    if (new_node_p == ((void *)0))
    {
        perror("new_node_p malloc");
        exit(1);
    }
    new_node_p->pdata = pdata;
    new_node_p->next = ((void *)0);
    new_node_p->prev = ((void *)0);
    if (thiz->size == 0)
    {
        node_of_idx_p = prev_node_of_idx_p = new_node_p;
    }
    else
    {
        node_of_idx_p = thiz->head;
        for (i = 0; i < idx; i++)
            node_of_idx_p = node_of_idx_p->next;
        prev_node_of_idx_p = node_of_idx_p->prev;
    }
    new_node_p->next = node_of_idx_p;
    new_node_p->prev = prev_node_of_idx_p;
    node_of_idx_p->prev = new_node_p;
    prev_node_of_idx_p->next = new_node_p;
    if (idx == 0)
    {
        thiz->head = new_node_p;
    }
    thiz->size++;
}

canonical_original_code:
void dlist_insert(struct _DList *thiz, unsigned long idx, void *pdata)
{
    unsigned long i;
    struct _DListNode *new_node_p = ((void *)0);
    struct _DListNode *node_of_idx_p = ((void *)0);
    struct _DListNode *prev_node_of_idx_p = ((void *)0);
    if (idx > thiz->size)
    {
        printf("idx %zu is out of range[0..%zu]\n", idx, thiz->size);
        return;
    }
    new_node_p = (struct _DListNode *)malloc(sizeof(struct _DListNode));
    if (new_node_p == ((void *)0))
    {
        perror("new_node_p malloc");
        exit(1);
    }
    new_node_p->pdata = pdata;
    new_node_p->next = ((void *)0);
    new_node_p->prev = ((void *)0);
    if (thiz->size == 0)
    {
        node_of_idx_p = prev_node_of_idx_p = new_node_p;
    }
    else
    {
        node_of_idx_p = thiz->head;
        for (i = 0; i < idx; i++)
            node_of_idx_p = node_of_idx_p->next;
        prev_node_of_idx_p = node_of_idx_p->prev;
    }
    new_node_p->next = node_of_idx_p;
    new_node_p->prev = prev_node_of_idx_p;
    node_of_idx_p->prev = new_node_p;
    prev_node_of_idx_p->next = new_node_p;
    if (idx == 0)
    {
        thiz->head = new_node_p;
    }
    thiz->size++;
}

variable_types:
idx
unsigned long

variable_types:
pdata
void *

variable_types:
i
unsigned long


original_code:
void dlist_delete(DList *thiz, size_t idx)
{
    size_t i;
    struct _DListNode *node_of_idx_p = ((void *)0);
    struct _DListNode *next_node_of_idx_p = ((void *)0);
    struct _DListNode *prev_node_of_idx_p = ((void *)0);
    if (thiz->size == 0)
    {
        printf("dlist is empty.\n");
        return;
    }
    if (idx >= thiz->size)
    {
        printf("idx %zu is out of range[0..%zu]\n", idx, (thiz->size - 1));
        return;
    }
    node_of_idx_p = thiz->head;
    for (i = 0; i < idx; i++)
    {
        node_of_idx_p = node_of_idx_p->next;
    }
    next_node_of_idx_p = node_of_idx_p->next;
    prev_node_of_idx_p = node_of_idx_p->prev;
    if (idx == 0)
    {
        thiz->head = next_node_of_idx_p;
    }
    next_node_of_idx_p->prev = prev_node_of_idx_p;
    prev_node_of_idx_p->next = next_node_of_idx_p;
    thiz->size--;
    if (thiz->size == 0)
    {
        thiz->head = ((void *)0);
    }
    free(node_of_idx_p->pdata);
    free(node_of_idx_p);
}

canonical_original_code:
void dlist_delete(struct _DList *thiz, unsigned long idx)
{
    unsigned long i;
    struct _DListNode *node_of_idx_p = ((void *)0);
    struct _DListNode *next_node_of_idx_p = ((void *)0);
    struct _DListNode *prev_node_of_idx_p = ((void *)0);
    if (thiz->size == 0)
    {
        printf("dlist is empty.\n");
        return;
    }
    if (idx >= thiz->size)
    {
        printf("idx %zu is out of range[0..%zu]\n", idx, (thiz->size - 1));
        return;
    }
    node_of_idx_p = thiz->head;
    for (i = 0; i < idx; i++)
    {
        node_of_idx_p = node_of_idx_p->next;
    }
    next_node_of_idx_p = node_of_idx_p->next;
    prev_node_of_idx_p = node_of_idx_p->prev;
    if (idx == 0)
    {
        thiz->head = next_node_of_idx_p;
    }
    next_node_of_idx_p->prev = prev_node_of_idx_p;
    prev_node_of_idx_p->next = next_node_of_idx_p;
    thiz->size--;
    if (thiz->size == 0)
    {
        thiz->head = ((void *)0);
    }
    free(node_of_idx_p->pdata);
    free(node_of_idx_p);
}


decompiled_code:
void __fastcall dlist_destroy(void *ptr)
{
while ( *((_QWORD *)ptr + 1) )
dlist_delete((__int64 *)ptr, 0LL);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func24(void *ptr)
{
while ( *((_QWORD *)ptr + 1) )
func23((__int64 *)ptr, 0LL);
free(ptr);
}

original_code:
void dlist_destroy(DList *thiz)
{
    while (thiz->size != 0)
    {
        dlist_delete(thiz, 0);
    }
    free(thiz);
}

canonical_original_code:
void dlist_destroy(struct _DList *thiz)
{
    while (thiz->size != 0)
    {
        dlist_delete(thiz, 0);
    }
    free(thiz);
}


GamaSort

repo: baifanmvp/sort

original_code:
static void GamaSort(KEY_T array[], int lo, int up, int bit)
{
    register KEY_T temp;
    register long b, u, l;
    if (up - lo > 15) {
 b = (1 << bit);
 u = up; l = lo;
 while (((b & array[u]) == b) && (u > lo))
     u--;
 if (!((u == lo) && ((b & array[u]) == b))) {
     while (((b & array[l]) == 0) && (l < up))
  l++;
 }
 if ((u == lo && (b & array[u]) == b) ||
     (l == up && (b & array[l]) == 0)) {
     u = up + 1;
 } else {
     while (l < u) {
  if (((b & array[l]) == b) && ((b & array[u]) == 0)) {
      temp = (array[u]); (array[u]) = (array[l]); (array[l]) = temp;
      while (((b & array[u]) == b) && (u > lo))
   u--;
  }
  l++;
     }
 }
 if (l >= u)
     u++;
 if (bit > 0) {
     if (u - 1 > lo)
  GamaSort(array, lo, u-1, bit-1);
     if (up > u)
  GamaSort(array, u, up, bit-1);
 }
    }
}

canonical_original_code:
static void GamaSort(long array[], int lo, int up, int bit)
{
    register long temp;
    register long b; register long u; register long l;
    if (up - lo > 15) {
 b = (1 << bit);
 u = up; l = lo;
 while (((b & array[u]) == b) && (u > lo))
     u--;
 if (!((u == lo) && ((b & array[u]) == b))) {
     while (((b & array[l]) == 0) && (l < up))
  l++;
 }
 if ((u == lo && (b & array[u]) == b) ||
     (l == up && (b & array[l]) == 0)) {
     u = up + 1;
 } else {
     while (l < u) {
  if (((b & array[l]) == b) && ((b & array[u]) == 0)) {
      temp = (array[u]); (array[u]) = (array[l]); (array[l]) = temp;
      while (((b & array[u]) == b) && (u > lo))
   u--;
  }
  l++;
     }
 }
 if (l >= u)
     u++;
 if (bit > 0) {
     if (u - 1 > lo)
  GamaSort(array, lo, u-1, bit-1);
     if (up > u)
  GamaSort(array, u, up, bit-1);
 }
    }
}

variable_types:
array
long []

variable_types: lo int

variable_types: up int

variable_types: bit int

variable_types: temp long

variable_types: b long

variable_types: u long

variable_types: l long


lg

decompiled_code:
__int64 __fastcall lg(int a1)
{
return (unsigned int)(int)(log10((double)a1) / 0.3010299956639812);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)(int)(log10((double)a1) / 0.3010299956639812);
}

original_code:
static int lg (int x)
{
    return (int) (log10(x) / log10(2));
}

canonical_original_code:
static int lg(int x)
{
    return (int) (log10(x) / log10(2));
}

variable_types: x int


gamasort

original_code:
void gamasort(KEY_T array[], int lo, int up)
{
    KEY_T ubits, i, temp, max = (-0x7fffffff - 1), maxidx;
    for (i = 0; i <= up; i++) {
 if (array[i] >= max) {
     max = array[i];
     maxidx = i;
 }
    }
    temp = (array[up]); (array[up]) = (array[maxidx]); (array[maxidx]) = temp;
    ubits = lg(array[maxidx]);
    GamaSort(array, lo, up, ubits);
    insort(array, up);
}

canonical_original_code:
void gamasort(long array[], int lo, int up)
{
    long ubits; long i; long temp; long max = (-0x7fffffff - 1); long maxidx;
    for (i = 0; i <= up; i++) {
 if (array[i] >= max) {
     max = array[i];
     maxidx = i;
 }
    }
    temp = (array[up]); (array[up]) = (array[maxidx]); (array[maxidx]) = temp;
    ubits = lg(array[maxidx]);
    GamaSort(array, lo, up, ubits);
    insort(array, up);
}

variable_types: ubits long

variable_types: i long

variable_types: max long

variable_types: maxidx long


heapsort

original_code:
void heapsort (KEY_T array[], int len)
{
    register int i;
    register KEY_T temp, *sa = array - 1;
    for (i = len / 2; i >= 1; i--)
 siftdown (sa, i, len);
    for (i = len; i >= 2; i--) {
 temp = (sa[1]); (sa[1]) = (sa[i]); (sa[i]) = temp;
 siftdown (sa, 1, i - 1);
    }
}

canonical_original_code:
void heapsort(long array[], int len)
{
    register int i;
    register long temp; register long *sa = array - 1;
    for (i = len / 2; i >= 1; i--)
 siftdown (sa, i, len);
    for (i = len; i >= 2; i--) {
 temp = (sa[1]); (sa[1]) = (sa[i]); (sa[i]) = temp;
 siftdown (sa, 1, i - 1);
    }
}

variable_types: len int

variable_types: i int

variable_types:
sa
long *


increment

decompiled_code:
void __fastcall increment(__int64 a1)
{
++*(_DWORD *)(a1 + 64);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
++*(_DWORD *)(a1 + 64);
}

original_code:
static void
increment(test_t *test) {
    test->counter++;
}

canonical_original_code:
static void increment(struct test *test) {
    test->counter++;
}

variable_types: struct test { struct e3_timer { struct e3_timer *next; unsigned long ticks; void (*function)(void *cookie); void *cookie; } timer_1; struct e3_timer timer_2; unsigned int counter; } *

user_defined_types: struct test { struct e3_timer timer_1; struct e3_timer timer_2; unsigned int counter; }


triple

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

result = (unsigned int)(3 * *(_DWORD *)(a1 + 64));
*(_DWORD *)(a1 + 64) = result;
return result;
}

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

result = (unsigned int)(3 * *(_DWORD *)(a1 + 64));
*(_DWORD *)(a1 + 64) = result;
return result;
}

original_code:
static void
triple(test_t *test) {
    test->counter *= 3;
}

canonical_original_code:
static void triple(struct test *test) {
    test->counter *= 3;
}

user_defined_types: struct e3_timer { struct e3_timer *next; unsigned long ticks; void (*function)(void *cookie); void *cookie; }


reschedule

decompiled_code:
__int64 __fastcall reschedule(__int64 a1)
{
++*(_DWORD *)(a1 + 64);
return e3_timer_create(a1, 0LL, reschedule, a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
++*(_DWORD *)(a1 + 64);
return e3_timer_create(a1, 0LL, reschedule, a1);
}

original_code:
static void
reschedule(test_t *test) {
    test->counter++;
    e3_timer_create(&test->timer_1, 0,
        (e3_timer_function_t) reschedule, test);
}

canonical_original_code:
static void reschedule(struct test *test) {
    test->counter++;
    e3_timer_create(&test->timer_1, 0,
        (void (*)(void *cookie)) reschedule, test);
}