decompiled_code:
void __fastcall array_div(int a1, double *a2, int a3)
{
__int64 v3; // rax
double v4; // xmm0_8

if ( a3 > 0 )
{
v3 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
do
{
v4 = *a2++;
*(a2 - 1) = v4 / (double)a1;
}
while ( a2 != (double *)v3 );
}
}

canonical_decompiled_code:
void __fastcall func13(int a1, double *a2, int a3)
{
__int64 v3; // rax
double v4; // xmm0_8

if ( a3 > 0 )
{
v3 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
do
{
v4 = *a2++;
*(a2 - 1) = v4 / (double)a1;
}
while ( a2 != (double *)v3 );
}
}

original_code:
void array_div(int n, double *array, int size){
  for(int i = 0; i < size; i++)
    array[i] /= n;
}

variable_types: n int

variable_types: size int


repo: ramfjord/audiomark

original_code:
void array_add(double *array, double *addition, int size){
  for(int i = 0; i < size; i++)
    array[i] += addition[i];
}

variable_types:
array
double *

variable_types:
addition
double *

variable_types: i int

return_type: void


original_code:
void dub_x_dub_e_dub(double *a, double *b, double *c, int len){
 for(int i = 0; i < len; i++)
  c[i] = a[i] * b[i];
}

variable_types:
a
double *

variable_types:
b
double *

variable_types:
c
double *

variable_types: len int


decompiled_code:
__int64 __fastcall seed_rand(__int64 seedval)
{
srand(seedval);
srand48((unsigned int)seedval);
return (unsigned int)seedval;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 seedval)
{
srand(seedval);
srand48((unsigned int)seedval);
return (unsigned int)seedval;
}

original_code:
unsigned seed_rand(unsigned seed){
  srand(seed);
 srand48((long)seed);
  return seed;
}

canonical_original_code:
unsigned int seed_rand(unsigned int seed){
  srand(seed);
 srand48((long)seed);
  return seed;
}

variable_types:
seed
unsigned int

return_type: unsigned int


decompiled_code:
void free_rand()
{
free(my_random);
}

canonical_decompiled_code:
void func1()
{
free(my_random);
}

original_code:
void free_rand(){
  free(my_random);
}

canonical_original_code:
void free_rand(){
  free(my_random);
}


decompiled_code:
char *__fastcall set_rand(int a1)
{
char *result; // rax
char *v2; // rdx

if ( my_random )
free_rand();
random_size = a1;
result = (char *)malloc(4LL * a1);
my_random = result;
v2 = result;
if ( a1 > 0 )
{
result = 0LL;
do
{
*(_DWORD *)&v2[4 * (_QWORD)result] = (_DWORD)result;
++result;
}
while ( result != (char *)a1 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(int a1)
{
char *result; // rax
char *v2; // rdx

if ( my_random )
func1();
random_size = a1;
result = (char *)malloc(4LL * a1);
my_random = result;
v2 = result;
if ( a1 > 0 )
{
result = 0LL;
do
{
*(_DWORD *)&v2[4 * (_QWORD)result] = (_DWORD)result;
++result;
}
while ( result != (char *)a1 );
}
return result;
}

original_code:
void set_rand(int size){
  if(my_random)
    free_rand();
  random_size = size;
  my_random = (int *)malloc(sizeof(int) * random_size);
  for(int i = 0; i < random_size; i++)
    my_random[i] = i;
}


decompiled_code:
__int64 __fastcall next_rand(unsigned int a1)
{
int v1; // eax
_DWORD *v2; // rsi
unsigned int *v3; // rax
unsigned int v4; // er8

if ( (int)(random_size - a1) <= 0 )
{
fprintf(stderr, "n_chosen (%d) is greater than random_size (%d)!!\n", a1, (unsigned int)random_size);
v4 = -1;
}
else
{
v1 = rand();
v2 = my_random;
v3 = (unsigned int *)((char *)my_random + 4 * (v1 % (int)(random_size - a1)));
v4 = *v3;
*v3 = *((_DWORD *)my_random + (int)(random_size - a1) - 1);
v2[random_size - a1 - 1] = v4;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
int v1; // eax
_DWORD *v2; // rsi
unsigned int *v3; // rax
unsigned int v4; // er8

if ( (int)(random_size - a1) <= 0 )
{
fprintf(stderr, "n_chosen (%d) is greater than random_size (%d)!!\n", a1, (unsigned int)random_size);
v4 = -1;
}
else
{
v1 = rand();
v2 = my_random;
v3 = (unsigned int *)((char *)my_random + 4 * (v1 % (int)(random_size - a1)));
v4 = *v3;
*v3 = *((_DWORD *)my_random + (int)(random_size - a1) - 1);
v2[random_size - a1 - 1] = v4;
}
return v4;
}

original_code:
int next_rand(int n_chosen){
  if(random_size - n_chosen <= 0){
    fprintf(stderr,"n_chosen (%d) is greater than random_size (%d)!!\n",n_chosen, random_size);
    return -1;
  }
  int i = rand() % (random_size - n_chosen);
  int temp = my_random[i];
  my_random[i] = my_random[random_size - n_chosen - 1];
  my_random[random_size - n_chosen - 1] = temp;
  return temp;
}

variable_types: temp int

return_type: int


decompiled_code:
// attributes: thunk
double rand_double(void)
{
return drand48();
}

canonical_decompiled_code:
double func4(void)
{
return drand48();
}

original_code:
double rand_double(){
  return drand48();
}

return_type: double


decompiled_code:
double norm_double()
{
double v1; // xmm0_8
double v2; // xmm2_8
double v3; // xmm2_8
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm3_8
double v7; // xmm1_8
double v8; // xmm0_8
double v9; // xmm0_8
double x; // [rsp+0h] [rbp-38h]
double xa; // [rsp+0h] [rbp-38h]
double v12; // [rsp+8h] [rbp-30h]
double v13; // [rsp+8h] [rbp-30h]
double v14; // [rsp+18h] [rbp-20h]
double cosx; // [rsp+20h] [rbp-18h] BYREF
double sinx[2]; // [rsp+28h] [rbp-10h] BYREF

if ( Z2_def_1 )
{
Z2_def_1 = 0;
return *(double *)&Z2_0;
}
x = rand_double();
v1 = rand_double();
v2 = v1;
if ( x != 0.0 )
{
if ( v1 == 0.0 )
v2 = LC1;
v12 = x;
Z2_def_1 = 1;
v6 = x;
v5 = log(x) * -2.0;
xa = *(double *)&LC5;
if ( v5 < 0.0 )
{
v14 = v12;
v13 = sqrt(v5);
sincos(v2 * 6.283185307179586, sinx, &cosx);
v4 = sinx[0];
v3 = cosx;
v6 = v14;
v7 = v13;
goto LABEL_11;
}
goto LABEL_9;
}
Z2_def_1 = 1;
if ( v1 != 0.0 )
{
v6 = LC1;
v5 = *(double *)&LC2;
xa = *(double *)&LC5;
LABEL_9:
sincos(v2 * 6.283185307179586, sinx, &cosx);
v4 = sinx[0];
v3 = cosx;
goto LABEL_10;
}
v3 = LC1;
v4 = *(double *)&LC3;
v5 = *(double *)&LC2;
v6 = LC1;
xa = *(double *)&LC5;
LABEL_10:
v7 = sqrt(v5);
LABEL_11:
*(double *)&Z2_0 = v7 * v4;
v8 = log(v6) * xa;
if ( v8 < 0.0 )
v9 = sqrt(v8);
else
v9 = sqrt(v8);
return v9 * v3;
}

canonical_decompiled_code:
double func5()
{
double v1; // xmm0_8
double v2; // xmm2_8
double v3; // xmm2_8
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm3_8
double v7; // xmm1_8
double v8; // xmm0_8
double v9; // xmm0_8
double x; // [rsp+0h] [rbp-38h]
double xa; // [rsp+0h] [rbp-38h]
double v12; // [rsp+8h] [rbp-30h]
double v13; // [rsp+8h] [rbp-30h]
double v14; // [rsp+18h] [rbp-20h]
double cosx; // [rsp+20h] [rbp-18h] BYREF
double sinx[2]; // [rsp+28h] [rbp-10h] BYREF

if ( Z2_def_1 )
{
Z2_def_1 = 0;
return *(double *)&Z2_0;
}
x = func4();
v1 = func4();
v2 = v1;
if ( x != 0.0 )
{
if ( v1 == 0.0 )
v2 = LC1;
v12 = x;
Z2_def_1 = 1;
v6 = x;
v5 = log(x) * -2.0;
xa = *(double *)&LC5;
if ( v5 < 0.0 )
{
v14 = v12;
v13 = sqrt(v5);
sincos(v2 * 6.283185307179586, sinx, &cosx);
v4 = sinx[0];
v3 = cosx;
v6 = v14;
v7 = v13;
goto LABEL_11;
}
goto LABEL_9;
}
Z2_def_1 = 1;
if ( v1 != 0.0 )
{
v6 = LC1;
v5 = *(double *)&LC2;
xa = *(double *)&LC5;
LABEL_9:
sincos(v2 * 6.283185307179586, sinx, &cosx);
v4 = sinx[0];
v3 = cosx;
goto LABEL_10;
}
v3 = LC1;
v4 = *(double *)&LC3;
v5 = *(double *)&LC2;
v6 = LC1;
xa = *(double *)&LC5;
LABEL_10:
v7 = sqrt(v5);
LABEL_11:
*(double *)&Z2_0 = v7 * v4;
v8 = log(v6) * xa;
if ( v8 < 0.0 )
v9 = sqrt(v8);
else
v9 = sqrt(v8);
return v9 * v3;
}


original_code:
int shuffle_d_arr(double *buffer, int n){
 for(int i = n-1; i >= 0; i--){
  int j = rand() % i;
  double tmp = buffer[i];
  buffer[i] = buffer[j];
  buffer[j] = tmp;
 }
}

variable_types:
buffer
double *

variable_types: j int

variable_types: tmp double


main

canonical_name: main

repo: ramfjord/ctrie

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
const char *v6; // rax
const char *v7; // rax
int v9; // [rsp+4h] [rbp-24h] BYREF
int v10; // [rsp+8h] [rbp-20h] BYREF
__int64 v11; // [rsp+Fh] [rbp-19h] BYREF
char v12[17]; // [rsp+17h] [rbp-11h] BYREF

v9 = 17;
v3 = init_trymap(int_indexer, 10LL, envp);
v11 = 0x21216F6C6C6568LL;
iput_try(v3, &v9, &v11);
v4 = size_try(v3);
printf("num elts in mytry: %d\n", v4);
v10 = 23;
strcpy(v12, "goodbye!");
iput_try(v3, &v10, v12);
v5 = size_try(v3);
printf("added another, now we have %d elts\n", v5);
v9 = 17;
v6 = (const char *)iget_try(v3, &v9);
printf("found: %s\n", v6);
v10 = 23;
v7 = (const char *)iget_try(v3, &v10);
printf("also found: %s\n", v7);
free_try(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
const char *v6; // rax
const char *v7; // rax
int v9; // [rsp+4h] [rbp-24h] BYREF
int v10; // [rsp+8h] [rbp-20h] BYREF
__int64 v11; // [rsp+Fh] [rbp-19h] BYREF
char v12[17]; // [rsp+17h] [rbp-11h] BYREF

v9 = 17;
v3 = init_trymap(int_indexer, 10LL, envp);
v11 = 0x21216F6C6C6568LL;
func12(v3, &v9, &v11);
v4 = func16(v3);
printf("num elts in mytry: %d\n", v4);
v10 = 23;
strcpy(v12, "goodbye!");
func12(v3, &v10, v12);
v5 = func16(v3);
printf("added another, now we have %d elts\n", v5);
v9 = 17;
v6 = (const char *)func15(v3, &v9);
printf("found: %s\n", v6);
v10 = 23;
v7 = (const char *)func15(v3, &v10);
printf("also found: %s\n", v7);
func9(v3);
return 0;
}

original_code:
int main(){
  trynode *mytry = init_trymap(&int_indexer, 10);
  char hello[] = "hello!!";
  int blah = 17;
  iput_try(mytry,&blah,(void *)hello);
  printf("num elts in mytry: %d\n", size_try(mytry));
  int blah2 = 23;
  char hello2[] = "goodbye!";
  iput_try(mytry,&blah2,(void *)hello2);
  printf("added another, now we have %d elts\n", size_try(mytry));
  blah = 17;
  char *ret = (char *)iget_try(mytry, &blah);
  printf("found: %s\n", ret);
  blah2 = 23;
  ret = (char *)iget_try(mytry, &blah2);
  printf("also found: %s\n", ret);
  free_try(mytry);
}

canonical_original_code:
int main(){
  struct trynode *mytry = init_trymap(&int_indexer, 10);
  char hello[] = "hello!!";
  int blah = 17;
  iput_try(mytry,&blah,(void *)hello);
  printf("num elts in mytry: %d\n", size_try(mytry));
  int blah2 = 23;
  char hello2[] = "goodbye!";
  iput_try(mytry,&blah2,(void *)hello2);
  printf("added another, now we have %d elts\n", size_try(mytry));
  blah = 17;
  char *ret = (char *)iget_try(mytry, &blah);
  printf("found: %s\n", ret);
  blah2 = 23;
  ret = (char *)iget_try(mytry, &blah2);
  printf("also found: %s\n", ret);
  free_try(mytry);
}

variable_types: struct trynode { void *payload; int nchildren; struct trynode **children; int nbelow; int (*get_index)(void *); int cur_i; } *

variable_types:
hello
char []

variable_types: blah int

variable_types:
ret
char *


decompiled_code:
__int64 __fastcall int_indexer(int *a1)
{
int v1; // edx

v1 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
*a1 = v1 / 10;
return (unsigned int)(v1 % 10);
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1)
{
int v1; // edx

v1 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
*a1 = v1 / 10;
return (unsigned int)(v1 % 10);
}

original_code:
int int_indexer(void *my_int){
  int *my_real_int = (int *)my_int;
  if(*my_real_int == 0)
    return -1;
  int ret = *my_real_int % 10;
  *my_real_int /= 10;
  return ret;
}

variable_types: ret int


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

if ( a2 )
result = memset(a1, 0, a2);
return result;
}

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

if ( a2 )
result = memset(a1, 0, a2);
return result;
}

original_code:
void my_bzero(void *array, size_t size)
{
  char *cur = (char *)array;
  for(int i = 0; i < size; i++)
    *(cur++) = (char)0;
}

canonical_original_code:
void my_bzero(void *array, unsigned long size)
{
  char *cur = (char *)array;
  for(int i = 0; i < size; i++)
    *(cur++) = (char)0;
}

variable_types:
array
void *

variable_types:
size
unsigned long

variable_types:
cur
char *


original_code:
int free_try(trynode *root)
{
  if(root == ((void *)0))
    return 0;
  for(int i = 0; i < root->nchildren; i++){
    free_try(root->children[i]);
  }
  free(root->children);
  free(root);
  return 0;
}

canonical_original_code:
int free_try(struct trynode *root)
{
  if(root == ((void *)0))
    return 0;
  for(int i = 0; i < root->nchildren; i++){
    free_try(root->children[i]);
  }
  free(root->children);
  free(root);
  return 0;
}

variable_types: i int

user_defined_types: struct trynode { void *payload; int nchildren; struct trynode **children; int nbelow; int (*get_index)(void *); int cur_i; }


original_code:
int put_try(trynode *root, void *key, void *val)
{
  int next_index = root->get_index(key);
  if(next_index == -1){
    int nadded = (root->payload) ? 0 : 1;
    root->nbelow += nadded;
    root->payload = val;
    return nadded;
  }
  if(root->children[next_index] == ((void *)0))
    newchild_try(root,next_index);
  int nadded = put_try(root->children[next_index], key, val);
  root->nbelow += nadded;
  return nadded;
}

canonical_original_code:
int put_try(struct trynode *root, void *key, void *val)
{
  int next_index = root->get_index(key);
  if(next_index == -1){
    int nadded = (root->payload) ? 0 : 1;
    root->nbelow += nadded;
    root->payload = val;
    return nadded;
  }
  if(root->children[next_index] == ((void *)0))
    newchild_try(root,next_index);
  int nadded = put_try(root->children[next_index], key, val);
  root->nbelow += nadded;
  return nadded;
}

variable_types:
key
void *

variable_types:
val
void *

variable_types: nadded int


decompiled_code:
// attributes: thunk
__int64 __fastcall sput_try(__int64 a1, __int64 a2, __int64 a3)
{
return put_try(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, __int64 a3)
{
return func10(a1, a2, a3);
}

original_code:
int sput_try(trynode *root, char *key, void *val)
{
  return put_try(root, (void *)key, val);
}

canonical_original_code:
int sput_try(struct trynode *root, char *key, void *val)
{
  return put_try(root, (void *)key, val);
}

variable_types:
key
char *


decompiled_code:
// attributes: thunk
__int64 __fastcall iput_try(__int64 a1, __int64 a2, __int64 a3)
{
return sput_try(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3)
{
return func11(a1, a2, a3);
}

original_code:
int iput_try(trynode *root, int *key, void *val)
{
  return put_try(root, (void *)key, val);
}

canonical_original_code:
int iput_try(struct trynode *root, int *key, void *val)
{
  return put_try(root, (void *)key, val);
}

variable_types:
key
int *


original_code:
void *get_try(trynode *root, void *key)
{
  int next_index = root->get_index(key);
  if(next_index == -1)
    return root->payload;
  if(root->children[next_index])
    return get_try(root->children[next_index], key);
  return ((void *)0);
}

canonical_original_code:
void *get_try(struct trynode *root, void *key)
{
  int next_index = root->get_index(key);
  if(next_index == -1)
    return root->payload;
  if(root->children[next_index])
    return get_try(root->children[next_index], key);
  return ((void *)0);
}

return_type: void *


decompiled_code:
// attributes: thunk
__int64 __fastcall sget_try(__int64 a1, __int64 a2)
{
return get_try(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
return func13(a1, a2);
}

original_code:
void *sget_try(trynode *root, char *key)
{
  return get_try(root, (void *)key);
}

canonical_original_code:
void *sget_try(struct trynode *root, char *key)
{
  return get_try(root, (void *)key);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall iget_try(__int64 a1, __int64 a2)
{
return sget_try(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
return func14(a1, a2);
}

original_code:
void *iget_try(trynode *root, int *key)
{
  return get_try(root, (void *)key);
}

canonical_original_code:
void *iget_try(struct trynode *root, int *key)
{
  return get_try(root, (void *)key);
}


decompiled_code:
__int64 __fastcall size_try(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

original_code:
int size_try(trynode *root)
{
  return root->nbelow;
}

canonical_original_code:
int size_try(struct trynode *root)
{
  return root->nbelow;
}


decompiled_code:
__int64 traverse_from_0()
{
fwrite("traverse_from_0 UNIMPLEMENTED\n", 1uLL, 0x1EuLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 func17()
{
fwrite("traverse_from_0 UNIMPLEMENTED\n", 1uLL, 0x1EuLL, stderr);
return 0LL;
}

original_code:
int traverse_from_0(trynode *root)
{
  fprintf(stderr, "traverse_from_0 UNIMPLEMENTED\n");
  return 0;
}

canonical_original_code:
int traverse_from_0(struct trynode *root)
{
  fprintf(stderr, "traverse_from_0 UNIMPLEMENTED\n");
  return 0;
}


decompiled_code:
__int64 __fastcall hex_to_u16(char *src)
{
size_t v1; // rax
__int64 result; // rax
size_t v3; // r13
unsigned __int64 v4; // rbx
char v5[8]; // [rsp+0h] [rbp-58h]
__int64 v6; // [rsp+8h] [rbp-50h] BYREF
char dest[72]; // [rsp+10h] [rbp-48h] BYREF

v1 = strlen(src);
if ( v1 > 0x10 )
{
v3 = v1 - 16;
v4 = v1;
strncpy(dest, &src[v1 - 16], 0x10uLL);
_isoc99_sscanf(dest, "%llx", &v6);
if ( v4 <= 0x20 )
{
strncpy(dest, src, v3);
v5[v4] = 0;
}
else
{
strncpy(dest, &src[v4 - 32], 0x10uLL);
}
_isoc99_sscanf(dest, "%llx", &v6);
result = v6;
}
else
{
_isoc99_sscanf(src, "%llx", &v6);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src)
{
size_t v1; // rax
__int64 result; // rax
size_t v3; // r13
unsigned __int64 v4; // rbx
char v5[8]; // [rsp+0h] [rbp-58h]
__int64 v6; // [rsp+8h] [rbp-50h] BYREF
char dest[72]; // [rsp+10h] [rbp-48h] BYREF

v1 = strlen(src);
if ( v1 > 0x10 )
{
v3 = v1 - 16;
v4 = v1;
strncpy(dest, &src[v1 - 16], 0x10uLL);
_isoc99_sscanf(dest, "%llx", &v6);
if ( v4 <= 0x20 )
{
strncpy(dest, src, v3);
v5[v4] = 0;
}
else
{
strncpy(dest, &src[v4 - 32], 0x10uLL);
}
_isoc99_sscanf(dest, "%llx", &v6);
result = v6;
}
else
{
_isoc99_sscanf(src, "%llx", &v6);
result = 0LL;
}
return result;
}

original_code:
u16 hex_to_u16(const char *s)
{
    u16 result;
    size_t len;
    char sub[16 + 1];
    u8 temp;
    result.hi8 = 0;
    result.lo8 = 0;
    len = strlen(s);
    if (len <= 16)
    {
        sscanf(s, "%llx", &temp);
        result.lo8 = temp;
    }
    else
    {
        strncpy(sub, s + len - 16, 16);
        sscanf(sub, "%llx", &temp);
        result.lo8 = temp;
        if (len <= 32)
        {
            strncpy(sub, s, len - 16);
            sub[len - 16] = '\0';
            sscanf(sub, "%llx", &temp);
            result.hi8 = temp;
        }
        else
        {
            strncpy(sub, s + len - 32, 16);
            sscanf(sub, "%llx", &temp);
            result.hi8 = temp;
        }
    }
    return (result);
}

canonical_original_code:
struct u16 hex_to_u16(char *s)
{
    struct u16 result;
    unsigned long len;
    char sub[-1];
    unsigned long long temp;
    result.hi8 = 0;
    result.lo8 = 0;
    len = strlen(s);
    if (len <= 16)
    {
        sscanf(s, "%llx", &temp);
        result.lo8 = temp;
    }
    else
    {
        strncpy(sub, s + len - 16, 16);
        sscanf(sub, "%llx", &temp);
        result.lo8 = temp;
        if (len <= 32)
        {
            strncpy(sub, s, len - 16);
            sub[len - 16] = '\0';
            sscanf(sub, "%llx", &temp);
            result.hi8 = temp;
        }
        else
        {
            strncpy(sub, s + len - 32, 16);
            sscanf(sub, "%llx", &temp);
            result.hi8 = temp;
        }
    }
    return (result);
}

variable_types:
s
char *

variable_types: struct u16 { unsigned long long hi8; unsigned long long lo8; }

variable_types:
len
unsigned long

variable_types:
sub
char [-1]

variable_types:
temp
unsigned long long


decompiled_code:
char *__fastcall u16_to_hex(__int64 a1, __int64 a2, char *a3)
{
size_t v5; // rax

if ( a1 )
{
sprintf(a3, "%llx", a1);
v5 = strlen(a3);
sprintf(&a3[v5], "%016llx", a2);
}
else
{
sprintf(a3, "%llx", a2);
}
return a3;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, __int64 a2, char *a3)
{
size_t v5; // rax

if ( a1 )
{
sprintf(a3, "%llx", a1);
v5 = strlen(a3);
sprintf(&a3[v5], "%016llx", a2);
}
else
{
sprintf(a3, "%llx", a2);
}
return a3;
}

original_code:
char *u16_to_hex(u16 k, char *buf)
{
    char *p;
    if (k.hi8 == 0)
        sprintf(buf, "%llx", k.lo8);
    else
    {
        sprintf(buf, "%llx", k.hi8);
        p = buf + strlen(buf);
        sprintf(p, "%016llx", k.lo8);
    }
    return (buf);
}

canonical_original_code:
char *u16_to_hex(struct u16 k, char *buf)
{
    char *p;
    if (k.hi8 == 0)
        sprintf(buf, "%llx", k.lo8);
    else
    {
        sprintf(buf, "%llx", k.hi8);
        p = buf + strlen(buf);
        sprintf(p, "%016llx", k.lo8);
    }
    return (buf);
}

variable_types:
buf
char *

variable_types:
p
char *

return_type: char *

user_defined_types: struct u16 { unsigned long long hi8; unsigned long long lo8; }


original_code:
char *u16_to_dec(u16 k, char *buf)
{
    u8 hi8 = k.hi8;
    u8 lo8 = k.lo8;
    int himod;
    int lomod;
    char temp[(39 + 1)];
    char *digit = temp;
    char *tail;
    while (hi8)
    {
        himod = (int)(hi8 % 10);
        hi8 /= 10;
        lomod = (int)(lo8 % 10);
        lo8 /= 10;
        lo8 += hi2loQuot[himod] ;
        lomod += (int)hi2loMod[himod];
        if (lomod >= 10)
        {
            lomod -= 10;
            lo8 += 1;
        }
        *digit++ = '0' + lomod;
    }
    sprintf(buf, "%llu", lo8);
    tail = buf + strlen(buf);
    while (digit > temp)
        *tail++ = *--digit;
    *tail = '\0';
    return (buf);
}

canonical_original_code:
char *u16_to_dec(struct u16 k, char *buf)
{
    unsigned long long hi8 = k.hi8;
    unsigned long long lo8 = k.lo8;
    int himod;
    int lomod;
    char temp[-1];
    char *digit = temp;
    char *tail;
    while (hi8)
    {
        himod = (int)(hi8 % 10);
        hi8 /= 10;
        lomod = (int)(lo8 % 10);
        lo8 /= 10;
        lo8 += hi2loQuot[himod] ;
        lomod += (int)hi2loMod[himod];
        if (lomod >= 10)
        {
            lomod -= 10;
            lo8 += 1;
        }
        *digit++ = '0' + lomod;
    }
    sprintf(buf, "%llu", lo8);
    tail = buf + strlen(buf);
    while (digit > temp)
        *tail++ = *--digit;
    *tail = '\0';
    return (buf);
}

variable_types: himod int

variable_types: lomod int

variable_types:
temp
char [-1]

variable_types:
digit
char *

variable_types:
tail
char *


original_code:
u16 mult16(u16 a, u16 b)
{
    u16 prod;
    u8 ahi4, alow4, bhi4, blow4, temp;
    u8 reshibit, hibit0, hibit1;
    prod.hi8 = 0;
    ahi4 = a.lo8 >> 32;
    alow4 = (a.lo8 & 0xFFFFFFFFLL);
    bhi4 = b.lo8 >> 32;
    blow4 = (b.lo8 & 0xFFFFFFFFLL);
    prod.lo8 = alow4 * blow4;
    temp = ahi4 * blow4;
    prod.hi8 += temp >> 32;
    temp <<= 32;
    hibit0 = (temp & 0x8000000000000000LL);
    hibit1 = (prod.lo8 & 0x8000000000000000LL);
    prod.lo8 += temp;
    reshibit = (prod.lo8 & 0x8000000000000000LL);
    if ((hibit0 & hibit1) || ((hibit0 ^ hibit1) && reshibit == 0LL))
        prod.hi8++;
    temp = alow4 * bhi4;
    prod.hi8 += temp >> 32;
    temp <<= 32;
    hibit0 = (temp & 0x8000000000000000LL);
    hibit1 = (prod.lo8 & 0x8000000000000000LL);
    prod.lo8 += temp;
    reshibit = (prod.lo8 & 0x8000000000000000LL);
    if ((hibit0 & hibit1) || ((hibit0 ^ hibit1) && reshibit == 0LL))
        prod.hi8++;
    prod.hi8 += ahi4 * bhi4;
    prod.hi8 += a.lo8 * b.hi8;
    prod.hi8 += a.hi8 * b.lo8;
    return (prod);
}

canonical_original_code:
struct u16 mult16(struct u16 a, struct u16 b)
{
    struct u16 prod;
    unsigned long long ahi4; unsigned long long alow4; unsigned long long bhi4; unsigned long long blow4; unsigned long long temp;
    unsigned long long reshibit; unsigned long long hibit0; unsigned long long hibit1;
    prod.hi8 = 0;
    ahi4 = a.lo8 >> 32;
    alow4 = (a.lo8 & 0xFFFFFFFFLL);
    bhi4 = b.lo8 >> 32;
    blow4 = (b.lo8 & 0xFFFFFFFFLL);
    prod.lo8 = alow4 * blow4;
    temp = ahi4 * blow4;
    prod.hi8 += temp >> 32;
    temp <<= 32;
    hibit0 = (temp & 0x8000000000000000LL);
    hibit1 = (prod.lo8 & 0x8000000000000000LL);
    prod.lo8 += temp;
    reshibit = (prod.lo8 & 0x8000000000000000LL);
    if ((hibit0 & hibit1) || ((hibit0 ^ hibit1) && reshibit == 0LL))
        prod.hi8++;
    temp = alow4 * bhi4;
    prod.hi8 += temp >> 32;
    temp <<= 32;
    hibit0 = (temp & 0x8000000000000000LL);
    hibit1 = (prod.lo8 & 0x8000000000000000LL);
    prod.lo8 += temp;
    reshibit = (prod.lo8 & 0x8000000000000000LL);
    if ((hibit0 & hibit1) || ((hibit0 ^ hibit1) && reshibit == 0LL))
        prod.hi8++;
    prod.hi8 += ahi4 * bhi4;
    prod.hi8 += a.lo8 * b.hi8;
    prod.hi8 += a.hi8 * b.lo8;
    return (prod);
}

variable_types:
a
struct u16

variable_types:
b
struct u16

variable_types:
reshibit
unsigned long long

return_type: struct u16 { unsigned long long hi8; unsigned long long lo8; }


canonical_original_code:
struct u16 add16(struct u16 a, struct u16 b)
{
    struct u16 sum;
    unsigned long long reshibit; unsigned long long hibit0; unsigned long long hibit1;
    sum.hi8 = a.hi8 + b.hi8;
    hibit0 = (a.lo8 & 0x8000000000000000LL);
    hibit1 = (b.lo8 & 0x8000000000000000LL);
    sum.lo8 = a.lo8 + b.lo8;
    reshibit = (sum.lo8 & 0x8000000000000000LL);
    if ((hibit0 & hibit1) || ((hibit0 ^ hibit1) && reshibit == 0LL))
        sum.hi8++;
    return (sum);
}


decompiled_code:
__int64 __fastcall dec_to_u16(_BYTE *a1)
{
unsigned __int64 v1; // rdx
__int64 result; // rax
__int64 v3; // rax
char v4; // r9
__int64 v5; // rdx
_BYTE *v6; // r10

v1 = 0LL;
result = 0LL;
if ( (unsigned __int8)(*a1 - 48) <= 9u )
{
do
{
v3 = add16((v1 >> 61) + 8 * result, 8 * v1, (v1 >> 63) + 2 * result, 2 * v1);
result = add16(v3, v5, 0LL, (char)(v4 - 48));
}
while ( (unsigned __int8)(*v6 - 48) <= 9u );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
unsigned __int64 v1; // rdx
__int64 result; // rax
__int64 v3; // rax
char v4; // r9
__int64 v5; // rdx
_BYTE *v6; // r10

v1 = 0LL;
result = 0LL;
if ( (unsigned __int8)(*a1 - 48) <= 9u )
{
do
{
v3 = func4((v1 >> 61) + 8 * result, 8 * v1, (v1 >> 63) + 2 * result, 2 * v1);
result = func4(v3, v5, 0LL, (char)(v4 - 48));
}
while ( (unsigned __int8)(*v6 - 48) <= 9u );
}
return result;
}

original_code:
u16 dec_to_u16(const char *s)
{
    u16 result;
    u16 temp;
    const char *p;
    result.hi8 = 0;
    result.lo8 = 0;
    for (p = s; *p >= '0' && *p <= '9'; p++)
    {
        temp = result;
        result.hi8 <<= 3;
        result.hi8 += (result.lo8 & 0xE000000000000000ULL) >> 61;
        result.lo8 <<= 3;
        temp.hi8 <<= 1;
        temp.hi8 += (temp.lo8 & 0x8000000000000000ULL) >> 63;
        temp.lo8 <<= 1;
        result = add16(result, temp);
        temp.hi8 = 0;
        temp.lo8 = *p - '0';
        result = add16(result, temp);
    }
    return (result);
}

canonical_original_code:
struct u16 dec_to_u16(char *s)
{
    struct u16 result;
    struct u16 temp;
    char *p;
    result.hi8 = 0;
    result.lo8 = 0;
    for (p = s; *p >= '0' && *p <= '9'; p++)
    {
        temp = result;
        result.hi8 <<= 3;
        result.hi8 += (result.lo8 & 0xE000000000000000ULL) >> 61;
        result.lo8 <<= 3;
        temp.hi8 <<= 1;
        temp.hi8 += (temp.lo8 & 0x8000000000000000ULL) >> 63;
        temp.lo8 <<= 1;
        result = add16(result, temp);
        temp.hi8 = 0;
        temp.lo8 = *p - '0';
        result = add16(result, temp);
    }
    return (result);
}


original_code:
u16 skip_ahead_rand(u16 advance)
{
    int i;
    u16 new;
    u8 bit_map;
    new.hi8 = 0;
    new.lo8 = 0;
    bit_map = advance.lo8;
    for (i = 0; bit_map && i < 64; i++)
    {
        if (bit_map & ((u8)1 << i))
        {
            new = add16(mult16(new, Gen[i].a), Gen[i].c);
            bit_map &= ~((u8)1 << i);
        }
    }
    bit_map = advance.hi8;
    for (i = 0; bit_map && i < 64; i++)
    {
        if (bit_map & ((u8)1 << i))
        {
            new = add16(mult16(new, Gen[i + 64].a), Gen[i + 64].c);
            bit_map &= ~((u8)1 << i);
        }
    }
    return (new);
}

canonical_original_code:
struct u16 skip_ahead_rand(struct u16 advance)
{
    int i;
    struct u16 new;
    unsigned long long bit_map;
    new.hi8 = 0;
    new.lo8 = 0;
    bit_map = advance.lo8;
    for (i = 0; bit_map && i < 64; i++)
    {
        if (bit_map & ((unsigned long long)1 << i))
        {
            new = add16(mult16(new, Gen[i].a), Gen[i].c);
            bit_map &= ~((unsigned long long)1 << i);
        }
    }
    bit_map = advance.hi8;
    for (i = 0; bit_map && i < 64; i++)
    {
        if (bit_map & ((unsigned long long)1 << i))
        {
            new = add16(mult16(new, Gen[i + 64].a), Gen[i + 64].c);
            bit_map &= ~((unsigned long long)1 << i);
        }
    }
    return (new);
}

variable_types:
advance
struct u16

variable_types: i int


original_code:
u16 next_rand(u16 rand)
{
    rand = add16(mult16(rand, Gen[0].a), Gen[0].c);
    return (rand);
}

canonical_original_code:
struct u16 next_rand(struct u16 rand)
{
    rand = add16(mult16(rand, Gen[0].a), Gen[0].c);
    return (rand);
}

variable_types:
rand
struct u16


repo: ramrunner/nbeng

decompiled_code:
struct addrinfo *__fastcall prepare_socket(int *a1, const char *a2, const char *a3, char a4)
{
int v6; // eax
int v7; // eax
struct addrinfo *v8; // rbx
int v9; // eax
int v10; // ebp
struct addrinfo *v11; // rbx
struct addrinfo *result; // rax
const char *v13; // rax
int optval; // [rsp+Ch] [rbp-9Ch] BYREF
struct addrinfo *pai; // [rsp+10h] [rbp-98h] BYREF
struct addrinfo *v16; // [rsp+18h] [rbp-90h] BYREF
struct addrinfo req; // [rsp+20h] [rbp-88h] BYREF
struct addrinfo v18; // [rsp+50h] [rbp-58h] BYREF

optval = 1;
if ( a3 == 0LL || a2 == 0LL || !a1 )
errx(1, "prepare_socket was passed a null arg");
*(_OWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&v18.ai_flags = 0x200000001LL;
v6 = *a1;
*(_OWORD *)&v18.ai_socktype = 0LL;
req.ai_family = 2;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
*(_OWORD *)&v18.ai_addr = 0LL;
v18.ai_next = 0LL;
v18.ai_socktype = ((unsigned int)(v6 - 2) > 1) + 1;
req.ai_socktype = v18.ai_socktype;
v7 = getaddrinfo(a2, a3, &req, &pai);
if ( v7 || (v7 = getaddrinfo(0LL, a3, &v18, &v16)) != 0 )
{
v13 = gai_strerror(v7);
errx(1, "getaddrinfo: %s", v13);
}
v8 = pai;
if ( !pai )
LABEL_16:
err(1, "socket");
while ( 1 )
{
v9 = socket(v8->ai_family, v8->ai_socktype, v8->ai_protocol);
v10 = v9;
if ( v9 >= 0 )
break;
LABEL_15:
v8 = v8->ai_next;
if ( !v8 )
goto LABEL_16;
}
if ( setsockopt(v9, 1, 2, &optval, 4u) < 0 )
{
close(v10);
warn("setsockopt");
goto LABEL_15;
}
v11 = v16;
if ( !v16 )
LABEL_18:
err(1, "bind");
while ( bind(v10, v11->ai_addr, v11->ai_addrlen) < 0 )
{
close(v10);
warn("bind");
v11 = v11->ai_next;
if ( !v11 )
goto LABEL_18;
}
if ( *a1 != 1 && (a4 & 1) != 0 )
listen(v10, 5);
result = pai;
a1[1] = v10;
*((_QWORD *)a1 + 530) = result;
return result;
}

canonical_decompiled_code:
struct addrinfo *__fastcall func0(int *a1, const char *a2, const char *a3, char a4)
{
int v6; // eax
int v7; // eax
struct addrinfo *v8; // rbx
int v9; // eax
int v10; // ebp
struct addrinfo *v11; // rbx
struct addrinfo *result; // rax
const char *v13; // rax
int optval; // [rsp+Ch] [rbp-9Ch] BYREF
struct addrinfo *pai; // [rsp+10h] [rbp-98h] BYREF
struct addrinfo *v16; // [rsp+18h] [rbp-90h] BYREF
struct addrinfo req; // [rsp+20h] [rbp-88h] BYREF
struct addrinfo v18; // [rsp+50h] [rbp-58h] BYREF

optval = 1;
if ( a3 == 0LL || a2 == 0LL || !a1 )
errx(1, "prepare_socket was passed a null arg");
*(_OWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&v18.ai_flags = 0x200000001LL;
v6 = *a1;
*(_OWORD *)&v18.ai_socktype = 0LL;
req.ai_family = 2;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
*(_OWORD *)&v18.ai_addr = 0LL;
v18.ai_next = 0LL;
v18.ai_socktype = ((unsigned int)(v6 - 2) > 1) + 1;
req.ai_socktype = v18.ai_socktype;
v7 = getaddrinfo(a2, a3, &req, &pai);
if ( v7 || (v7 = getaddrinfo(0LL, a3, &v18, &v16)) != 0 )
{
v13 = gai_strerror(v7);
errx(1, "getaddrinfo: %s", v13);
}
v8 = pai;
if ( !pai )
LABEL_16:
err(1, "socket");
while ( 1 )
{
v9 = socket(v8->ai_family, v8->ai_socktype, v8->ai_protocol);
v10 = v9;
if ( v9 >= 0 )
break;
LABEL_15:
v8 = v8->ai_next;
if ( !v8 )
goto LABEL_16;
}
if ( setsockopt(v9, 1, 2, &optval, 4u) < 0 )
{
close(v10);
warn("setsockopt");
goto LABEL_15;
}
v11 = v16;
if ( !v16 )
LABEL_18:
err(1, "bind");
while ( bind(v10, v11->ai_addr, v11->ai_addrlen) < 0 )
{
close(v10);
warn("bind");
v11 = v11->ai_next;
if ( !v11 )
goto LABEL_18;
}
if ( *a1 != 1 && (a4 & 1) != 0 )
listen(v10, 5);
result = pai;
a1[1] = v10;
*((_QWORD *)a1 + 530) = result;
return result;
}

original_code:
static void
prepare_socket(concontxt *con, char *host, char *port, int lflag)
{
 struct addrinfo cli_hints, *cli_servinfo, srv_hints, *srv_servinfo, *p0;
 int rv, cli_sockfd, optval = 1;
 if ((con == ((void *)0)) || (host == ((void *)0)) || (port == ((void *)0)))
  errx(1, "prepare_socket was passed a null arg");
 memset(&cli_hints, 0, sizeof (cli_hints));
 memset(&srv_hints, 0, sizeof (srv_hints));
 cli_hints.ai_family = srv_hints.ai_family = 2;
 srv_hints.ai_flags = 0x0001;
 cli_hints.ai_socktype = srv_hints.ai_socktype =
  ((con->contype == 2) || (con->contype == 3))
  ? SOCK_STREAM : SOCK_DGRAM;
 rv = getaddrinfo(host, port, &cli_hints, &cli_servinfo);
 if (rv)
  errx(1, "getaddrinfo: %s", gai_strerror(rv));
 rv = getaddrinfo(((void *)0), port, &srv_hints, &srv_servinfo);
 if (rv)
  errx(1, "getaddrinfo: %s", gai_strerror(rv));
 for (p0 = cli_servinfo; p0; p0 = p0->ai_next) {
  cli_sockfd = socket(p0->ai_family, p0->ai_socktype,
        p0->ai_protocol);
  if (cli_sockfd < 0)
   continue;
  rv = setsockopt(cli_sockfd, 1,
    2, &optval, sizeof (optval));
  if (rv < 0) {
   close(cli_sockfd);
   warn("setsockopt");
   continue;
  }
  break;
 }
 if (!p0)
  err(1, "socket");
 for (p0 = srv_servinfo; p0; p0 = p0->ai_next) {
  if (bind(cli_sockfd, p0->ai_addr, p0->ai_addrlen) < 0) {
   close(cli_sockfd);
   warn("bind");
   continue;
  }
  break;
 }
 if (!p0)
  err(1, "bind");
 if (con->contype != 1 && lflag)
  listen(cli_sockfd, 5);
 con->confd = cli_sockfd;
 con->clinfo = cli_servinfo;
}

canonical_original_code:
static void prepare_socket(struct concontxt_t *con, char *host, char *port, int lflag)
{
 struct addrinfo cli_hints; struct addrinfo *cli_servinfo; struct addrinfo srv_hints; struct addrinfo *srv_servinfo; struct addrinfo *p0;
 int rv; int cli_sockfd; int optval = 1;
 if ((con == ((void *)0)) || (host == ((void *)0)) || (port == ((void *)0)))
  errx(1, "prepare_socket was passed a null arg");
 memset(&cli_hints, 0, sizeof (cli_hints));
 memset(&srv_hints, 0, sizeof (srv_hints));
 cli_hints.ai_family = srv_hints.ai_family = 2;
 srv_hints.ai_flags = 0x0001;
 cli_hints.ai_socktype = srv_hints.ai_socktype =
  ((con->contype == 2) || (con->contype == 3))
  ? SOCK_STREAM : SOCK_DGRAM;
 rv = getaddrinfo(host, port, &cli_hints, &cli_servinfo);
 if (rv)
  errx(1, "getaddrinfo: %s", gai_strerror(rv));
 rv = getaddrinfo(((void *)0), port, &srv_hints, &srv_servinfo);
 if (rv)
  errx(1, "getaddrinfo: %s", gai_strerror(rv));
 for (p0 = cli_servinfo; p0; p0 = p0->ai_next) {
  cli_sockfd = socket(p0->ai_family, p0->ai_socktype,
        p0->ai_protocol);
  if (cli_sockfd < 0)
   continue;
  rv = setsockopt(cli_sockfd, 1,
    2, &optval, sizeof (optval));
  if (rv < 0) {
   close(cli_sockfd);
   warn("setsockopt");
   continue;
  }
  break;
 }
 if (!p0)
  err(1, "socket");
 for (p0 = srv_servinfo; p0; p0 = p0->ai_next) {
  if (bind(cli_sockfd, p0->ai_addr, p0->ai_addrlen) < 0) {
   close(cli_sockfd);
   warn("bind");
   continue;
  }
  break;
 }
 if (!p0)
  err(1, "bind");
 if (con->contype != 1 && lflag)
  listen(cli_sockfd, 5);
 con->confd = cli_sockfd;
 con->clinfo = cli_servinfo;
}

variable_types: struct concontxt_t { unsigned int contype; int confd; int clifd; int clifds[1024]; struct fd_set { long __fds_bits[-1]; } lset; struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *clinfo; struct addrinfo *srvinfo; char *buf; unsigned int buflen; int wfd; } *

variable_types:
host
char *

variable_types:
port
char *

variable_types: lflag int

variable_types: rv int

variable_types: optval int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

user_defined_types: struct concontxt_t { unsigned int contype; int confd; int clifd; int clifds[1024]; struct fd_set lset; struct addrinfo *clinfo; struct addrinfo *srvinfo; char *buf; unsigned int buflen; int wfd; }


myconnect

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

if ( connect(
*(_DWORD *)(a1 + 4),
*(const struct sockaddr **)(*(_QWORD *)(a1 + 4240) + 24LL),
*(_DWORD *)(*(_QWORD *)(a1 + 4240) + 16LL)) < 0 )
warn("connect");
result = *(unsigned int *)(a1 + 4);
*(_DWORD *)(a1 + 4) = -1;
*(_DWORD *)(a1 + 8) = result;
return result;
}

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

if ( connect(
*(_DWORD *)(a1 + 4),
*(const struct sockaddr **)(*(_QWORD *)(a1 + 4240) + 24LL),
*(_DWORD *)(*(_QWORD *)(a1 + 4240) + 16LL)) < 0 )
warn("connect");
result = *(unsigned int *)(a1 + 4);
*(_DWORD *)(a1 + 4) = -1;
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
static void
myconnect(concontxt *con)
{
 int r;
 r = connect(con->confd,
      con->clinfo->ai_addr,
      con->clinfo->ai_addrlen);
 if (r < 0)
  warn("connect");
 con->clifd = con->confd;
 con->confd = -1;
}

canonical_original_code:
static void myconnect(struct concontxt_t *con)
{
 int r;
 r = connect(con->confd,
      con->clinfo->ai_addr,
      con->clinfo->ai_addrlen);
 if (r < 0)
  warn("connect");
 con->clifd = con->confd;
 con->confd = -1;
}

variable_types: r int

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


readstdin

original_code:
static void
readstdin(concontxt *con)
{
 char buf[512];
 ssize_t n;
 do {
  n = read(con->wfd, buf, 512);
  if (n < 0) {
   if ((*__errno_location ()) != 11)
    err(1, "read");
   continue;
  }
  break;
 } while (1);
 buf[n] = '\0';
 if (n == 0 || strncmp(buf, "Q\n", 3) == 0) {
  qflag = 1;
  return;
 }
        printf("n=%zd buf=%s", n, buf);
 if ((con->buf = malloc(n)) == ((void *)0)) {
  warn("malloc");
  goto freex;
 }
 memcpy(con->buf, buf, n);
 con->buflen = n;
 return;
freex:
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}

canonical_original_code:
static void readstdin(struct concontxt_t *con)
{
 char buf[512];
 long n;
 do {
  n = read(con->wfd, buf, 512);
  if (n < 0) {
   if ((*__errno_location ()) != 11)
    err(1, "read");
   continue;
  }
  break;
 } while (1);
 buf[n] = '\0';
 if (n == 0 || strncmp(buf, "Q\n", 3) == 0) {
  qflag = 1;
  return;
 }
        printf("n=%zd buf=%s", n, buf);
 if ((con->buf = malloc(n)) == ((void *)0)) {
  warn("malloc");
  goto freex;
 }
 memcpy(con->buf, buf, n);
 con->buflen = n;
 return;
freex:
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}

variable_types:
buf
char [512]

variable_types: n long


writesock

original_code:
static void
writesock(concontxt *con)
{
 ssize_t n;
 if (con->buf == ((void *)0))
  return;
 if (con->contype == 1) {
         n = sendto(con->confd, con->buf, con->buflen, 0,
      con->clinfo->ai_addr,
      con->clinfo->ai_addrlen);
  if (n < 0)
   warn("sendto");
 } else {
  n = write(con->clifd, con->buf, con->buflen);
  if (n < 0) {
   warn("write");
   close(con->clifd);
   con->clifd = -1;
   goto freex;
  }
 }
freex:
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}

canonical_original_code:
static void writesock(struct concontxt_t *con)
{
 long n;
 if (con->buf == ((void *)0))
  return;
 if (con->contype == 1) {
         n = sendto(con->confd, con->buf, con->buflen, 0,
      con->clinfo->ai_addr,
      con->clinfo->ai_addrlen);
  if (n < 0)
   warn("sendto");
 } else {
  n = write(con->clifd, con->buf, con->buflen);
  if (n < 0) {
   warn("write");
   close(con->clifd);
   con->clifd = -1;
   goto freex;
  }
 }
freex:
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}


writestdout

original_code:
static void
writestdout(concontxt *con)
{
 write(con->lfd, con->buf, con->buflen);
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}

canonical_original_code:
static void writestdout(struct concontxt_t *con)
{
 write(con->lfd, con->buf, con->buflen);
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}


myaccept

decompiled_code:
int __fastcall myaccept(__int64 a1)
{
int v2; // edi
__int64 v3; // rbx
__int64 v4; // rsi
__int64 v6; // [rsp-10h] [rbp-4C8h]
socklen_t addr_len; // [rsp+Ch] [rbp-4ACh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-4A8h] BYREF
char host[8]; // [rsp+90h] [rbp-428h] BYREF

v2 = *(_DWORD *)(a1 + 4);
addr_len = 128;
v3 = (unsigned int)accept(v2, &addr, &addr_len);
printf("newfd=%d\n", v3);
if ( (int)v3 < 0 )
err(1, "accept");
*(_DWORD *)(a1 + 8) = v3;
v4 = addr_len;
if ( getnameinfo(&addr, addr_len, host, 0x401u, 0LL, 0, 0) < 0 )
{
warn("getnameinfo", v4, v6);
strcpy(host, "unknown");
}
return printf("host=%s\n", host);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
int v2; // edi
__int64 v3; // rbx
__int64 v4; // rsi
__int64 v6; // [rsp-10h] [rbp-4C8h]
socklen_t addr_len; // [rsp+Ch] [rbp-4ACh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-4A8h] BYREF
char host[8]; // [rsp+90h] [rbp-428h] BYREF

v2 = *(_DWORD *)(a1 + 4);
addr_len = 128;
v3 = (unsigned int)accept(v2, &addr, &addr_len);
printf("newfd=%d\n", v3);
if ( (int)v3 < 0 )
err(1, "accept");
*(_DWORD *)(a1 + 8) = v3;
v4 = addr_len;
if ( getnameinfo(&addr, addr_len, host, 0x401u, 0LL, 0, 0) < 0 )
{
warn("getnameinfo", v4, v6);
strcpy(host, "unknown");
}
return printf("host=%s\n", host);
}

original_code:
static void
myaccept(concontxt *con)
{
 int r;
 char host[1025];
 int newfd;
 struct sockaddr_storage sa;
 socklen_t salen = sizeof (sa);
 newfd = accept(con->confd, (struct sockaddr *)&sa, &salen);
 printf("newfd=%d\n", newfd);
 if (newfd < 0)
  err(1, "accept");
 con->clifd = newfd;
 r = getnameinfo((struct sockaddr *)&sa, salen,
   host, sizeof (host), ((void *)0), 0, 0);
 if (r < 0) {
  warn("getnameinfo");
  snprintf(host, sizeof (host), "unknown");
 }
 printf("host=%s\n", host);
}

canonical_original_code:
static void myaccept(struct concontxt_t *con)
{
 int r;
 char host[1025];
 int newfd;
 struct sockaddr_storage sa;
 unsigned int salen = sizeof (sa);
 newfd = accept(con->confd, (struct sockaddr *)&sa, &salen);
 printf("newfd=%d\n", newfd);
 if (newfd < 0)
  err(1, "accept");
 con->clifd = newfd;
 r = getnameinfo((struct sockaddr *)&sa, salen,
   host, sizeof (host), ((void *)0), 0, 0);
 if (r < 0) {
  warn("getnameinfo");
  snprintf(host, sizeof (host), "unknown");
 }
 printf("host=%s\n", host);
}

variable_types:
host
char [1025]

variable_types: newfd int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
salen
unsigned int


readsock

decompiled_code:
void __fastcall readsock(__int64 a1)
{
bool v2; // zf
ssize_t v3; // rax
size_t v4; // rbp
void *v5; // rax
ssize_t v6; // rax
__int64 v7; // rsi
void *v8; // rdi
__int64 v9; // [rsp-10h] [rbp-6C8h]
socklen_t addr_len; // [rsp+Ch] [rbp-6ACh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-6A8h] BYREF
char buf[512]; // [rsp+90h] [rbp-628h] BYREF
char host[8]; // [rsp+290h] [rbp-428h] BYREF

v2 = *(_DWORD *)a1 == 1;
addr_len = 128;
if ( v2 )
{
v6 = recvfrom(*(_DWORD *)(a1 + 4), buf, 0x200uLL, 64, &addr, &addr_len);
v4 = v6;
if ( v6 < 0 )
{
warn("recvfrom");
goto LABEL_13;
}
v7 = addr_len;
if ( getnameinfo(&addr, addr_len, host, 0x401u, 0LL, 0, 0) < 0 )
{
warn("getnameinfo", v7, v9);
strcpy(host, "unknown");
}
printf("host=%s\n", host);
}
else
{
while ( 1 )
{
v3 = read(*(_DWORD *)(a1 + 8), buf, 0x200uLL);
v4 = v3;
if ( v3 >= 0 )
break;
if ( *_errno_location() != 11 )
err(1, "read");
}
if ( !v3 )
{
qflag = 1;
close(*(_DWORD *)(a1 + 8));
*(_DWORD *)(a1 + 8) = -1;
goto LABEL_13;
}
}
buf[v4] = 0;
v5 = malloc(v4);
*(_QWORD *)(a1 + 4256) = v5;
if ( v5 )
{
memcpy(v5, buf, v4);
*(_DWORD *)(a1 + 4264) = v4;
printf("n=%zd buf=%s", v4, buf);
return;
}
warn("malloc");
LABEL_13:
v8 = *(void **)(a1 + 4256);
if ( v8 )
free(v8);
*(_QWORD *)(a1 + 4256) = 0LL;
*(_DWORD *)(a1 + 4264) = 0;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
bool v2; // zf
ssize_t v3; // rax
size_t v4; // rbp
void *v5; // rax
ssize_t v6; // rax
__int64 v7; // rsi
void *v8; // rdi
__int64 v9; // [rsp-10h] [rbp-6C8h]
socklen_t addr_len; // [rsp+Ch] [rbp-6ACh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-6A8h] BYREF
char buf[512]; // [rsp+90h] [rbp-628h] BYREF
char host[8]; // [rsp+290h] [rbp-428h] BYREF

v2 = *(_DWORD *)a1 == 1;
addr_len = 128;
if ( v2 )
{
v6 = recvfrom(*(_DWORD *)(a1 + 4), buf, 0x200uLL, 64, &addr, &addr_len);
v4 = v6;
if ( v6 < 0 )
{
warn("recvfrom");
goto LABEL_13;
}
v7 = addr_len;
if ( getnameinfo(&addr, addr_len, host, 0x401u, 0LL, 0, 0) < 0 )
{
warn("getnameinfo", v7, v9);
strcpy(host, "unknown");
}
printf("host=%s\n", host);
}
else
{
while ( 1 )
{
v3 = read(*(_DWORD *)(a1 + 8), buf, 0x200uLL);
v4 = v3;
if ( v3 >= 0 )
break;
if ( *_errno_location() != 11 )
err(1, "read");
}
if ( !v3 )
{
qflag = 1;
close(*(_DWORD *)(a1 + 8));
*(_DWORD *)(a1 + 8) = -1;
goto LABEL_13;
}
}
buf[v4] = 0;
v5 = malloc(v4);
*(_QWORD *)(a1 + 4256) = v5;
if ( v5 )
{
memcpy(v5, buf, v4);
*(_DWORD *)(a1 + 4264) = v4;
printf("n=%zd buf=%s", v4, buf);
return;
}
warn("malloc");
LABEL_13:
v8 = *(void **)(a1 + 4256);
if ( v8 )
free(v8);
*(_QWORD *)(a1 + 4256) = 0LL;
*(_DWORD *)(a1 + 4264) = 0;
}

original_code:
static void
readsock(concontxt *con)
{
 char buf[512];
 ssize_t n;
 int r;
 char host[1025];
 socklen_t addr_len;
 struct sockaddr_storage their_addr;
 addr_len = sizeof (their_addr);
 if (con->contype == 1) {
  n = recvfrom(con->confd, buf, sizeof (buf), MSG_DONTWAIT,
        (struct sockaddr *)&their_addr, &addr_len);
  if (n < 0) {
   warn("recvfrom");
   goto freex;
  }
  r = getnameinfo((struct sockaddr *)&their_addr, addr_len,
    host, sizeof (host), ((void *)0), 0, 0);
  if (r < 0) {
   warn("getnameinfo");
   snprintf(host, sizeof (host), "unknown");
  }
  printf("host=%s\n", host);
 } else {
  do {
   n = read(con->clifd, buf, sizeof (buf));
   if (n < 0) {
    if ((*__errno_location ()) != 11)
     err(1, "read");
    continue;
   }
   if (n == 0) {
    qflag = 1;
    close(con->clifd);
    con->clifd = -1;
    goto freex;
   }
   break;
  } while (1);
 }
 buf[n] = '\0';
 if ((con->buf = malloc(n)) == ((void *)0)) {
  warn("malloc");
  goto freex;
 }
 memcpy(con->buf, buf, n);
 con->buflen = n;
 printf("n=%zd buf=%s", n, buf);
 return;
freex:
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}

canonical_original_code:
static void readsock(struct concontxt_t *con)
{
 char buf[512];
 long n;
 int r;
 char host[1025];
 unsigned int addr_len;
 struct sockaddr_storage their_addr;
 addr_len = sizeof (their_addr);
 if (con->contype == 1) {
  n = recvfrom(con->confd, buf, sizeof (buf), MSG_DONTWAIT,
        (struct sockaddr *)&their_addr, &addr_len);
  if (n < 0) {
   warn("recvfrom");
   goto freex;
  }
  r = getnameinfo((struct sockaddr *)&their_addr, addr_len,
    host, sizeof (host), ((void *)0), 0, 0);
  if (r < 0) {
   warn("getnameinfo");
   snprintf(host, sizeof (host), "unknown");
  }
  printf("host=%s\n", host);
 } else {
  do {
   n = read(con->clifd, buf, sizeof (buf));
   if (n < 0) {
    if ((*__errno_location ()) != 11)
     err(1, "read");
    continue;
   }
   if (n == 0) {
    qflag = 1;
    close(con->clifd);
    con->clifd = -1;
    goto freex;
   }
   break;
  } while (1);
 }
 buf[n] = '\0';
 if ((con->buf = malloc(n)) == ((void *)0)) {
  warn("malloc");
  goto freex;
 }
 memcpy(con->buf, buf, n);
 con->buflen = n;
 printf("n=%zd buf=%s", n, buf);
 return;
freex:
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }


usage

decompiled_code:
size_t __fastcall usage(int a1)
{
size_t result; // rax

result = fwrite(
"usage: nbeng [-ht] rhost rport\n\t-t\tUse TCP for transport\n\t-h\tThis help screen\n",
1uLL,
0x4EuLL,
stderr);
if ( a1 )
exit(1);
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(int a1)
{
size_t result; // rax

result = fwrite(
"usage: nbeng [-ht] rhost rport\n\t-t\tUse TCP for transport\n\t-h\tThis help screen\n",
1uLL,
0x4EuLL,
stderr);
if ( a1 )
exit(1);
return result;
}

original_code:
void
usage(int ret)
{
        fprintf(stderr, "usage: nbeng [-ht] rhost rport\n"
  "\t-t	Use TCP for transport\n"
  "\t-h	This help screen\n");
 if (ret)
  exit(1);
}

variable_types: ret int


main

original_code:
int
main(int argc, char *argv[])
{
 int c;
 int highsock, readsocks;
 struct timeval timeout;
 char *host, *port;
 concontxt *con;
 while ((c = getopt(argc, argv, "ht")) != -1) {
  switch (c) {
  case 'h':
   usage(1);
   break;
  case 't':
   tflag = 1;
   break;
  default:
   usage(1);
  }
 }
 argc -= optind;
 argv += optind;
 if (argc != 2)
  usage(1);
 host = argv[0];
 port = argv[1];
 con = malloc(sizeof (concontxt));
 if (con == ((void *)0))
  err(1, "malloc");
 con->wfd = 0;
 con->lfd = 1;
 con->contype = (tflag || sflag) ? 2 : 1;
 con->clifd = -1;
 prepare_socket(con, host, port, 1);
 while (1) {
  timeout.tv_sec = 1;
  timeout.tv_usec = 0;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&(con->lset))->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&con->lset)->__fds_bits)[((con->wfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->wfd) % (8 * (int) sizeof (__fd_mask)))))));
  highsock = con->wfd;
  if (con->confd != -1) {
   ((void) (((&con->lset)->__fds_bits)[((con->confd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->confd) % (8 * (int) sizeof (__fd_mask)))))));
   highsock = con->confd;
  }
  if (con->clifd != -1) {
   ((void) (((&con->lset)->__fds_bits)[((con->clifd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->clifd) % (8 * (int) sizeof (__fd_mask)))))));
   highsock = con->clifd;
  }
  if (qflag)
   goto freex;
  readsocks = select(highsock + 1, &con->lset, ((void *)0),
       ((void *)0), &timeout);
  if (readsocks < 0) {
   warn("select");
   goto freex;
  }
  if (readsocks != 0) {
   if (((((&con->lset)->__fds_bits)[((con->wfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->wfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    if (con->clifd == -1
        && con->contype != 1) {
     close(con->confd);
     prepare_socket(con, host, port, 0);
     myconnect(con);
    }
    readstdin(con);
    writesock(con);
   }
   if (con->confd != -1 &&
       ((((&con->lset)->__fds_bits)[((con->confd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->confd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    if (con->contype == 1) {
     readsock(con);
     writestdout(con);
    } else {
     myaccept(con);
    }
   }
   if (con->clifd != -1 &&
       ((((&con->lset)->__fds_bits)[((con->clifd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->clifd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    readsock(con);
    writestdout(con);
   }
  }
 }
freex:
 printf("exiting\n");
 if (con != ((void *)0)) {
  close(con->confd);
  close(con->clifd);
  free(con);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int c;
 int highsock; int readsocks;
 struct timeval timeout;
 char *host; char *port;
 struct concontxt_t *con;
 while ((c = getopt(argc, argv, "ht")) != -1) {
  switch (c) {
  case 'h':
   usage(1);
   break;
  case 't':
   tflag = 1;
   break;
  default:
   usage(1);
  }
 }
 argc -= optind;
 argv += optind;
 if (argc != 2)
  usage(1);
 host = argv[0];
 port = argv[1];
 con = malloc(sizeof (concontxt));
 if (con == ((void *)0))
  err(1, "malloc");
 con->wfd = 0;
 con->lfd = 1;
 con->contype = (tflag || sflag) ? 2 : 1;
 con->clifd = -1;
 prepare_socket(con, host, port, 1);
 while (1) {
  timeout.tv_sec = 1;
  timeout.tv_usec = 0;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&(con->lset))->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&con->lset)->__fds_bits)[((con->wfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->wfd) % (8 * (int) sizeof (__fd_mask)))))));
  highsock = con->wfd;
  if (con->confd != -1) {
   ((void) (((&con->lset)->__fds_bits)[((con->confd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->confd) % (8 * (int) sizeof (__fd_mask)))))));
   highsock = con->confd;
  }
  if (con->clifd != -1) {
   ((void) (((&con->lset)->__fds_bits)[((con->clifd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->clifd) % (8 * (int) sizeof (__fd_mask)))))));
   highsock = con->clifd;
  }
  if (qflag)
   goto freex;
  readsocks = select(highsock + 1, &con->lset, ((void *)0),
       ((void *)0), &timeout);
  if (readsocks < 0) {
   warn("select");
   goto freex;
  }
  if (readsocks != 0) {
   if (((((&con->lset)->__fds_bits)[((con->wfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->wfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    if (con->clifd == -1
        && con->contype != 1) {
     close(con->confd);
     prepare_socket(con, host, port, 0);
     myconnect(con);
    }
    readstdin(con);
    writesock(con);
   }
   if (con->confd != -1 &&
       ((((&con->lset)->__fds_bits)[((con->confd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->confd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    if (con->contype == 1) {
     readsock(con);
     writestdout(con);
    } else {
     myaccept(con);
    }
   }
   if (con->clifd != -1 &&
       ((((&con->lset)->__fds_bits)[((con->clifd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->clifd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    readsock(con);
    writestdout(con);
   }
  }
 }
freex:
 printf("exiting\n");
 if (con != ((void *)0)) {
  close(con->confd);
  close(con->clifd);
  free(con);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: highsock int

variable_types: readsocks int

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


decompiled_code:
unsigned __int64 x86_bpred_init()
{
unsigned __int64 result; // rax
__int64 v1; // r13
int i; // er14
__int64 v3; // rbp
unsigned int v4; // ebx
__int64 v5; // r8
__int64 v6; // r12
__int64 v7; // r12
bool v8; // cc
char v9[248]; // [rsp+0h] [rbp-F8h] BYREF

x86_bpred_twolevel_l2height = 1 << x86_bpred_twolevel_hist_size;
if ( (x86_bpred_bimod_size & (x86_bpred_bimod_size - 1)) != 0 )
{
fatal("number of entries in bimodal precitor must be a power of 2");
if ( (x86_bpred_choice_size & (x86_bpred_choice_size - 1)) == 0 )
{
LABEL_3:
if ( (x86_bpred_btb_sets & (x86_bpred_btb_sets - 1)) == 0 )
goto LABEL_4;
goto LABEL_15;
}
}
else if ( (x86_bpred_choice_size & (x86_bpred_choice_size - 1)) == 0 )
{
goto LABEL_3;
}
fatal("number of entries in choice predictor must be power of 2");
if ( (x86_bpred_btb_sets & (x86_bpred_btb_sets - 1)) == 0 )
{
LABEL_4:
if ( (x86_bpred_btb_assoc & (x86_bpred_btb_assoc - 1)) == 0 )
goto LABEL_5;
goto LABEL_16;
}
LABEL_15:
fatal("number of BTB sets must be a power of 2");
if ( (x86_bpred_btb_assoc & (x86_bpred_btb_assoc - 1)) == 0 )
{
LABEL_5:
if ( (unsigned int)(x86_bpred_twolevel_hist_size - 1) <= 0x1D )
goto LABEL_6;
goto LABEL_17;
}
LABEL_16:
fatal("BTB associativity must be a power of 2");
if ( (unsigned int)(x86_bpred_twolevel_hist_size - 1) <= 0x1D )
{
LABEL_6:
if ( (x86_bpred_twolevel_l1size & (x86_bpred_twolevel_l1size - 1)) == 0 )
goto LABEL_7;
LABEL_18:
fatal("two-level predictor sizes must be power of 2");
result = (unsigned int)x86_bpred_twolevel_l2size;
if ( (x86_bpred_twolevel_l2size & (x86_bpred_twolevel_l2size - 1)) == 0 )
goto LABEL_8;
goto LABEL_19;
}
LABEL_17:
fatal("predictor history size must be >=1 and <=30");
if ( (x86_bpred_twolevel_l1size & (x86_bpred_twolevel_l1size - 1)) != 0 )
goto LABEL_18;
LABEL_7:
result = (unsigned int)x86_bpred_twolevel_l2size;
if ( (x86_bpred_twolevel_l2size & (x86_bpred_twolevel_l2size - 1)) == 0 )
goto LABEL_8;
LABEL_19:
result = fatal("two-level predictor sizes must be power of 2");
LABEL_8:
v1 = 0LL;
for ( i = 0; x86_cpu_num_cores > i; v1 += 1824LL )
{
result = x86_cpu_num_threads;
v3 = 0LL;
v4 = 0;
if ( x86_cpu_num_threads > 0 )
{
do
{
v5 = v4++;
snprintf(v9, 0xC8uLL, "c%dt%d.bpred", (unsigned int)i, v5);
v6 = *(_QWORD *)(*x86_cpu + v1);
result = (unsigned __int64)x86_bpred_create((__int64)v9);
v7 = v3 + v6;
v3 += 1904LL;
v8 = x86_cpu_num_threads <= (int)v4;
*(_QWORD *)(v7 + 96) = result;
}
while ( !v8 );
}
++i;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 func0()
{
unsigned __int64 result; // rax
__int64 v1; // r13
int i; // er14
__int64 v3; // rbp
unsigned int v4; // ebx
__int64 v5; // r8
__int64 v6; // r12
__int64 v7; // r12
bool v8; // cc
char v9[248]; // [rsp+0h] [rbp-F8h] BYREF

x86_bpred_twolevel_l2height = 1 << x86_bpred_twolevel_hist_size;
if ( (x86_bpred_bimod_size & (x86_bpred_bimod_size - 1)) != 0 )
{
fatal("number of entries in bimodal precitor must be a power of 2");
if ( (x86_bpred_choice_size & (x86_bpred_choice_size - 1)) == 0 )
{
LABEL_3:
if ( (x86_bpred_btb_sets & (x86_bpred_btb_sets - 1)) == 0 )
goto LABEL_4;
goto LABEL_15;
}
}
else if ( (x86_bpred_choice_size & (x86_bpred_choice_size - 1)) == 0 )
{
goto LABEL_3;
}
fatal("number of entries in choice predictor must be power of 2");
if ( (x86_bpred_btb_sets & (x86_bpred_btb_sets - 1)) == 0 )
{
LABEL_4:
if ( (x86_bpred_btb_assoc & (x86_bpred_btb_assoc - 1)) == 0 )
goto LABEL_5;
goto LABEL_16;
}
LABEL_15:
fatal("number of BTB sets must be a power of 2");
if ( (x86_bpred_btb_assoc & (x86_bpred_btb_assoc - 1)) == 0 )
{
LABEL_5:
if ( (unsigned int)(x86_bpred_twolevel_hist_size - 1) <= 0x1D )
goto LABEL_6;
goto LABEL_17;
}
LABEL_16:
fatal("BTB associativity must be a power of 2");
if ( (unsigned int)(x86_bpred_twolevel_hist_size - 1) <= 0x1D )
{
LABEL_6:
if ( (x86_bpred_twolevel_l1size & (x86_bpred_twolevel_l1size - 1)) == 0 )
goto LABEL_7;
LABEL_18:
fatal("two-level predictor sizes must be power of 2");
result = (unsigned int)x86_bpred_twolevel_l2size;
if ( (x86_bpred_twolevel_l2size & (x86_bpred_twolevel_l2size - 1)) == 0 )
goto LABEL_8;
goto LABEL_19;
}
LABEL_17:
fatal("predictor history size must be >=1 and <=30");
if ( (x86_bpred_twolevel_l1size & (x86_bpred_twolevel_l1size - 1)) != 0 )
goto LABEL_18;
LABEL_7:
result = (unsigned int)x86_bpred_twolevel_l2size;
if ( (x86_bpred_twolevel_l2size & (x86_bpred_twolevel_l2size - 1)) == 0 )
goto LABEL_8;
LABEL_19:
result = fatal("two-level predictor sizes must be power of 2");
LABEL_8:
v1 = 0LL;
for ( i = 0; x86_cpu_num_cores > i; v1 += 1824LL )
{
result = x86_cpu_num_threads;
v3 = 0LL;
v4 = 0;
if ( x86_cpu_num_threads > 0 )
{
do
{
v5 = v4++;
snprintf(v9, 0xC8uLL, "c%dt%d.bpred", (unsigned int)i, v5);
v6 = *(_QWORD *)(*x86_cpu + v1);
result = (unsigned __int64)x86_bpred_create((__int64)v9);
v7 = v3 + v6;
v3 += 1904LL;
v8 = x86_cpu_num_threads <= (int)v4;
*(_QWORD *)(v7 + 96) = result;
}
while ( !v8 );
}
++i;
}
return result;
}

original_code:
void x86_bpred_init()
{
 char name[200];
 int core;
 int thread;
 x86_bpred_twolevel_l2height = 1 << x86_bpred_twolevel_hist_size;
 if (x86_bpred_bimod_size & (x86_bpred_bimod_size - 1))
  fatal("number of entries in bimodal precitor must be a power of 2");
 if (x86_bpred_choice_size & (x86_bpred_choice_size - 1))
  fatal("number of entries in choice predictor must be power of 2");
 if (x86_bpred_btb_sets & (x86_bpred_btb_sets - 1))
  fatal("number of BTB sets must be a power of 2");
 if (x86_bpred_btb_assoc & (x86_bpred_btb_assoc - 1))
  fatal("BTB associativity must be a power of 2");
 if (x86_bpred_twolevel_hist_size < 1 || x86_bpred_twolevel_hist_size > 30)
  fatal("predictor history size must be >=1 and <=30");
 if (x86_bpred_twolevel_l1size & (x86_bpred_twolevel_l1size - 1))
  fatal("two-level predictor sizes must be power of 2");
 if (x86_bpred_twolevel_l2size & (x86_bpred_twolevel_l2size - 1))
  fatal("two-level predictor sizes must be power of 2");
 for (core = 0; core < x86_cpu_num_cores; core++) for (thread = 0; thread < x86_cpu_num_threads; thread++)
 {
  snprintf(name, sizeof name, "c%dt%d.bpred", core, thread);
  (x86_cpu->core[core].thread[thread]).bpred = x86_bpred_create(name);
 }
}

variable_types:
name
char [200]

variable_types: core int

variable_types: thread int


decompiled_code:
__int64 __fastcall x86_bpred_free(_QWORD *a1)
{
if ( ((x86_bpred_kind - 3) & 0xFFFFFFFD) != 0 )
{
if ( (unsigned int)(x86_bpred_kind - 4) > 1 )
goto LABEL_3;
}
else
{
mhandle_free(a1[4], "bpred.c:198");
if ( (unsigned int)(x86_bpred_kind - 4) > 1 )
goto LABEL_3;
}
mhandle_free(a1[5], "bpred.c:202");
mhandle_free(a1[6], "bpred.c:203");
if ( x86_bpred_kind == 5 )
mhandle_free(a1[7], "bpred.c:208");
LABEL_3:
mhandle_free(*a1, "bpred.c:211");
mhandle_free(a1[3], "bpred.c:212");
mhandle_free(a1[1], "bpred.c:213");
return mhandle_free(a1, "bpred.c:214");
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
if ( ((x86_bpred_kind - 3) & 0xFFFFFFFD) != 0 )
{
if ( (unsigned int)(x86_bpred_kind - 4) > 1 )
goto LABEL_3;
}
else
{
mhandle_free(a1[4], "bpred.c:198");
if ( (unsigned int)(x86_bpred_kind - 4) > 1 )
goto LABEL_3;
}
mhandle_free(a1[5], "bpred.c:202");
mhandle_free(a1[6], "bpred.c:203");
if ( x86_bpred_kind == 5 )
mhandle_free(a1[7], "bpred.c:208");
LABEL_3:
mhandle_free(*a1, "bpred.c:211");
mhandle_free(a1[3], "bpred.c:212");
mhandle_free(a1[1], "bpred.c:213");
return mhandle_free(a1, "bpred.c:214");
}

original_code:
void x86_bpred_free(struct x86_bpred_t *bpred)
{
 if (x86_bpred_kind == x86_bpred_kind_bimod || x86_bpred_kind == x86_bpred_kind_comb)
  (mhandle_free(bpred->bimod, "bpred.c" ":" "198"));
 if (x86_bpred_kind == x86_bpred_kind_twolevel || x86_bpred_kind == x86_bpred_kind_comb) {
  (mhandle_free(bpred->twolevel_bht, "bpred.c" ":" "202"));
  (mhandle_free(bpred->twolevel_pht, "bpred.c" ":" "203"));
 }
 if (x86_bpred_kind == x86_bpred_kind_comb)
  (mhandle_free(bpred->choice, "bpred.c" ":" "208"));
 (mhandle_free(bpred->name, "bpred.c" ":" "211"));
 (mhandle_free(bpred->btb, "bpred.c" ":" "212"));
 (mhandle_free(bpred->ras, "bpred.c" ":" "213"));
 (mhandle_free(bpred, "bpred.c" ":" "214"));
}

variable_types: struct x86_bpred_t { char *name; unsigned int *ras; int ras_index; struct btb_entry_t { unsigned int source; unsigned int target; int counter; } *btb; char *bimod; unsigned int *twolevel_bht; char *twolevel_pht; char *choice; long long accesses; long long hits; } *

user_defined_types: struct x86_bpred_t { char *name; unsigned int *ras; int ras_index; struct btb_entry_t *btb; char *bimod; unsigned int *twolevel_bht; char *twolevel_pht; char *choice; long long accesses; long long hits; }


decompiled_code:
__int64 x86_bpred_done()
{
int v0; // er12
__int64 v1; // rbp
__int64 result; // rax
__int64 i; // rbx
__int64 v4; // rax

if ( x86_cpu_num_cores > 0 )
{
v0 = 0;
v1 = 0LL;
do
{
result = x86_cpu_num_threads;
for ( i = 0LL;
x86_cpu_num_threads > (int)i;
result = x86_bpred_free(*(_QWORD **)(*(_QWORD *)(*x86_cpu + v1) + v4 + 96)) )
{
v4 = 1904 * i++;
}
++v0;
v1 += 1824LL;
}
while ( x86_cpu_num_cores > v0 );
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // er12
__int64 v1; // rbp
__int64 result; // rax
__int64 i; // rbx
__int64 v4; // rax

if ( x86_cpu_num_cores > 0 )
{
v0 = 0;
v1 = 0LL;
do
{
result = x86_cpu_num_threads;
for ( i = 0LL;
x86_cpu_num_threads > (int)i;
result = func1(*(_QWORD **)(*(_QWORD *)(*x86_cpu + v1) + v4 + 96)) )
{
v4 = 1904 * i++;
}
++v0;
v1 += 1824LL;
}
while ( x86_cpu_num_cores > v0 );
}
return result;
}

original_code:
void x86_bpred_done()
{
 int core;
 int thread;
 for (core = 0; core < x86_cpu_num_cores; core++) for (thread = 0; thread < x86_cpu_num_threads; thread++)
  x86_bpred_free((x86_cpu->core[core].thread[thread]).bpred);
}


decompiled_code:
__int64 __fastcall x86_bpred_lookup_multiple(__int64 a1, int a2, int a3)
{
unsigned int v4; // eax
__int64 v5; // rbx
int v6; // edi
int v7; // edx
unsigned int v8; // er8
int v9; // ecx
int v10; // esi

if ( x86_bpred_kind != 4 )
_assert_fail("x86_bpred_kind == x86_bpred_kind_twolevel", "bpred.c", 0x12Au, "x86_bpred_lookup_multiple");
v4 = *(_DWORD *)(*(_QWORD *)(a1 + 40) + 4LL * (a2 & (unsigned int)(x86_bpred_twolevel_l1size - 1)));
if ( x86_bpred_twolevel_l2height <= v4 )
_assert_fail("bhr < x86_bpred_twolevel_l2height", "bpred.c", 0x12Du, "x86_bpred_lookup_multiple");
v5 = *(_QWORD *)(a1 + 48);
v6 = a2 & (x86_bpred_twolevel_l2size - 1);
v7 = *(_BYTE *)(v5 + v6 + v4 * x86_bpred_twolevel_l2size) > 1;
if ( a3 <= 1 )
return *(_BYTE *)(v5 + v6 + v4 * x86_bpred_twolevel_l2size) > 1;
v8 = *(_BYTE *)(v5 + v6 + v4 * x86_bpred_twolevel_l2size) > 1;
v9 = 1;
do
{
v4 = (x86_bpred_twolevel_l2height - 1) & (v7 | (2 * v4));
v7 = *(_BYTE *)(v5 + v6 + v4 * x86_bpred_twolevel_l2size) > 1;
v10 = v7 << v9++;
v8 |= v10;
}
while ( a3 != v9 );
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, int a3)
{
unsigned int v4; // eax
__int64 v5; // rbx
int v6; // edi
int v7; // edx
unsigned int v8; // er8
int v9; // ecx
int v10; // esi

if ( x86_bpred_kind != 4 )
_assert_fail("x86_bpred_kind == x86_bpred_kind_twolevel", "bpred.c", 0x12Au, "x86_bpred_lookup_multiple");
v4 = *(_DWORD *)(*(_QWORD *)(a1 + 40) + 4LL * (a2 & (unsigned int)(x86_bpred_twolevel_l1size - 1)));
if ( x86_bpred_twolevel_l2height <= v4 )
_assert_fail("bhr < x86_bpred_twolevel_l2height", "bpred.c", 0x12Du, "x86_bpred_lookup_multiple");
v5 = *(_QWORD *)(a1 + 48);
v6 = a2 & (x86_bpred_twolevel_l2size - 1);
v7 = *(_BYTE *)(v5 + v6 + v4 * x86_bpred_twolevel_l2size) > 1;
if ( a3 <= 1 )
return *(_BYTE *)(v5 + v6 + v4 * x86_bpred_twolevel_l2size) > 1;
v8 = *(_BYTE *)(v5 + v6 + v4 * x86_bpred_twolevel_l2size) > 1;
v9 = 1;
do
{
v4 = (x86_bpred_twolevel_l2height - 1) & (v7 | (2 * v4));
v7 = *(_BYTE *)(v5 + v6 + v4 * x86_bpred_twolevel_l2size) > 1;
v10 = v7 << v9++;
v8 |= v10;
}
while ( a3 != v9 );
return v8;
}

original_code:
int x86_bpred_lookup_multiple(struct x86_bpred_t *bpred, uint32_t eip, int count)
{
 int i, pred, temp_pred;
 uint32_t bht_index, pht_col;
 uint32_t bhr;
 ((void) sizeof ((x86_bpred_kind == x86_bpred_kind_twolevel) ? 1 : 0), __extension__ ({ if (x86_bpred_kind == x86_bpred_kind_twolevel) ; else __assert_fail ("x86_bpred_kind == x86_bpred_kind_twolevel", "bpred.c", 298, __extension__ __PRETTY_FUNCTION__); }));
 bht_index = eip & (x86_bpred_twolevel_l1size - 1);
 bhr = bpred->twolevel_bht[bht_index];
 ((void) sizeof ((bhr < x86_bpred_twolevel_l2height) ? 1 : 0), __extension__ ({ if (bhr < x86_bpred_twolevel_l2height) ; else __assert_fail ("bhr < x86_bpred_twolevel_l2height", "bpred.c", 301, __extension__ __PRETTY_FUNCTION__); }));
 pht_col = eip & (x86_bpred_twolevel_l2size - 1);
 pred = temp_pred = bpred->twolevel_pht[bhr * x86_bpred_twolevel_l2size + pht_col] > 1;
 for (i = 1; i < count; i++)
 {
  bhr = ((bhr << 1) | temp_pred) & (x86_bpred_twolevel_l2height - 1);
  temp_pred = bpred->twolevel_pht[bhr * x86_bpred_twolevel_l2size + pht_col] > 1;
  ((void) sizeof ((!temp_pred || temp_pred == 1) ? 1 : 0), __extension__ ({ if (!temp_pred || temp_pred == 1) ; else __assert_fail ("!temp_pred || temp_pred == 1", "bpred.c", 310, __extension__ __PRETTY_FUNCTION__); }));
  pred |= temp_pred << i;
 }
 return pred;
}

canonical_original_code:
int x86_bpred_lookup_multiple(struct x86_bpred_t *bpred, unsigned int eip, int count)
{
 int i; int pred; int temp_pred;
 unsigned int bht_index; unsigned int pht_col;
 unsigned int bhr;
 ((void) sizeof ((x86_bpred_kind == x86_bpred_kind_twolevel) ? 1 : 0), __extension__ ({ if (x86_bpred_kind == x86_bpred_kind_twolevel) ; else __assert_fail ("x86_bpred_kind == x86_bpred_kind_twolevel", "bpred.c", 298, __extension__ __PRETTY_FUNCTION__); }));
 bht_index = eip & (x86_bpred_twolevel_l1size - 1);
 bhr = bpred->twolevel_bht[bht_index];
 ((void) sizeof ((bhr < x86_bpred_twolevel_l2height) ? 1 : 0), __extension__ ({ if (bhr < x86_bpred_twolevel_l2height) ; else __assert_fail ("bhr < x86_bpred_twolevel_l2height", "bpred.c", 301, __extension__ __PRETTY_FUNCTION__); }));
 pht_col = eip & (x86_bpred_twolevel_l2size - 1);
 pred = temp_pred = bpred->twolevel_pht[bhr * x86_bpred_twolevel_l2size + pht_col] > 1;
 for (i = 1; i < count; i++)
 {
  bhr = ((bhr << 1) | temp_pred) & (x86_bpred_twolevel_l2height - 1);
  temp_pred = bpred->twolevel_pht[bhr * x86_bpred_twolevel_l2size + pht_col] > 1;
  ((void) sizeof ((!temp_pred || temp_pred == 1) ? 1 : 0), __extension__ ({ if (!temp_pred || temp_pred == 1) ; else __assert_fail ("!temp_pred || temp_pred == 1", "bpred.c", 310, __extension__ __PRETTY_FUNCTION__); }));
  pred |= temp_pred << i;
 }
 return pred;
}

variable_types:
eip
unsigned int

variable_types: count int

variable_types: i int

variable_types: pred int

variable_types:
bhr
unsigned int

user_defined_types: struct btb_entry_t { unsigned int source; unsigned int target; int counter; }


decompiled_code:
__int64 __fastcall x86_bpred_btb_next_branch(__int64 a1, unsigned int a2, int a3)
{
unsigned int v3; // er8
unsigned int v4; // er9
__int64 v5; // rsi
__int64 v6; // rdx
_DWORD *v7; // rax
__int64 v8; // rdx

if ( (a3 & (a3 - 1)) != 0 )
_assert_fail("!(bsize & (bsize - 1))", "bpred.c", 0x1E8u, "x86_bpred_btb_next_branch");
v3 = a2;
v4 = -a3 & (a3 + a2);
if ( a2 >= v4 )
return 0LL;
while ( x86_bpred_btb_assoc <= 0 )
{
LABEL_8:
if ( v4 == ++v3 )
return 0LL;
}
v5 = *(_QWORD *)(a1 + 24);
v6 = (int)(x86_bpred_btb_assoc * (v3 & (x86_bpred_btb_sets - 1)));
v7 = (_DWORD *)(v5 + 12 * v6);
v8 = v5 + 12 * ((unsigned int)(x86_bpred_btb_assoc - 1) + v6) + 12;
while ( *v7 != v3 )
{
v7 += 3;
if ( (_DWORD *)v8 == v7 )
goto LABEL_8;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2, int a3)
{
unsigned int v3; // er8
unsigned int v4; // er9
__int64 v5; // rsi
__int64 v6; // rdx
_DWORD *v7; // rax
__int64 v8; // rdx

if ( (a3 & (a3 - 1)) != 0 )
_assert_fail("!(bsize & (bsize - 1))", "bpred.c", 0x1E8u, "x86_bpred_btb_next_branch");
v3 = a2;
v4 = -a3 & (a3 + a2);
if ( a2 >= v4 )
return 0LL;
while ( x86_bpred_btb_assoc <= 0 )
{
LABEL_8:
if ( v4 == ++v3 )
return 0LL;
}
v5 = *(_QWORD *)(a1 + 24);
v6 = (int)(x86_bpred_btb_assoc * (v3 & (x86_bpred_btb_sets - 1)));
v7 = (_DWORD *)(v5 + 12 * v6);
v8 = v5 + 12 * ((unsigned int)(x86_bpred_btb_assoc - 1) + v6) + 12;
while ( *v7 != v3 )
{
v7 += 3;
if ( (_DWORD *)v8 == v7 )
goto LABEL_8;
}
return v3;
}

original_code:
unsigned int x86_bpred_btb_next_branch(struct x86_bpred_t *bpred, uint32_t eip, uint32_t bsize)
{
 struct btb_entry_t *entry;
 uint32_t limit;
 int set, way;
 ((void) sizeof ((!(bsize & (bsize - 1))) ? 1 : 0), __extension__ ({ if (!(bsize & (bsize - 1))) ; else __assert_fail ("!(bsize & (bsize - 1))", "bpred.c", 488, __extension__ __PRETTY_FUNCTION__); }));
 limit = (eip + bsize) & ~(bsize - 1);
 while (eip < limit) {
  set = eip & (x86_bpred_btb_sets - 1);
  for (way = 0; way < x86_bpred_btb_assoc; way++)
  {
   entry = (&bpred->btb[(set) * x86_bpred_btb_assoc + (way)]);
   if (entry->source == eip)
    return eip;
  }
  eip++;
 }
 return 0;
}

canonical_original_code:
unsigned int x86_bpred_btb_next_branch(struct x86_bpred_t *bpred, unsigned int eip, unsigned int bsize)
{
 struct btb_entry_t *entry;
 unsigned int limit;
 int set; int way;
 ((void) sizeof ((!(bsize & (bsize - 1))) ? 1 : 0), __extension__ ({ if (!(bsize & (bsize - 1))) ; else __assert_fail ("!(bsize & (bsize - 1))", "bpred.c", 488, __extension__ __PRETTY_FUNCTION__); }));
 limit = (eip + bsize) & ~(bsize - 1);
 while (eip < limit) {
  set = eip & (x86_bpred_btb_sets - 1);
  for (way = 0; way < x86_bpred_btb_assoc; way++)
  {
   entry = (&bpred->btb[(set) * x86_bpred_btb_assoc + (way)]);
   if (entry->source == eip)
    return eip;
  }
  eip++;
 }
 return 0;
}

variable_types:
bsize
unsigned int

variable_types: struct btb_entry_t { unsigned int source; unsigned int target; int counter; } *

variable_types:
limit
unsigned int

variable_types: set int

variable_types: way int


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

result = (_QWORD *)mhandle_calloc(70LL, 8LL, "isa.c:40");
frm_isa_inst_func = (__int64)result;
if ( !result )
{
fatal("%s: out of memory", "frm_isa_init");
result = (_QWORD *)frm_isa_inst_func;
}
result[1] = &frm_isa_FFMA_impl;
result[2] = &frm_isa_FADD_impl;
result[3] = &frm_isa_FADD32I_impl;
result[4] = &frm_isa_FCMP_impl;
result[5] = &frm_isa_FMUL_impl;
result[6] = &frm_isa_FMUL32I_impl;
result[7] = &frm_isa_FSETP_impl;
result[8] = &frm_isa_MUFU_impl;
result[9] = &frm_isa_DFMA_impl;
result[10] = &frm_isa_DADD_impl;
result[11] = &frm_isa_DMUL_impl;
result[12] = &frm_isa_DSETP_impl;
result[13] = &frm_isa_IMAD_impl;
result[14] = &frm_isa_IMUL_impl;
result[15] = &frm_isa_IADD_impl;
result[16] = &frm_isa_IADD32I_impl;
result[17] = &frm_isa_ISCADD_impl;
result[18] = &frm_isa_BFE_impl;
result[19] = &frm_isa_BFI_impl;
result[20] = &frm_isa_SHR_impl;
result[21] = &frm_isa_SHL_impl;
result[22] = &frm_isa_LOP_impl;
result[23] = &frm_isa_LOP32I_impl;
result[24] = &frm_isa_ISETP_impl;
result[25] = &frm_isa_ICMP_impl;
result[26] = &frm_isa_F2F_impl;
result[27] = &frm_isa_F2I_impl;
result[28] = &frm_isa_I2F_impl;
result[29] = &frm_isa_I2I_impl;
result[30] = &frm_isa_MOV_impl;
result[31] = &frm_isa_MOV32I_impl;
result[32] = &frm_isa_SEL_impl;
result[33] = &frm_isa_LDC_impl;
result[34] = &frm_isa_LD_impl;
result[35] = &frm_isa_LDU_impl;
result[36] = &frm_isa_LDL_impl;
result[37] = &frm_isa_LDS_impl;
result[38] = &frm_isa_LDLK_impl;
result[39] = &frm_isa_LDSLK_impl;
result[40] = &frm_isa_ST_impl;
result[41] = &frm_isa_STL_impl;
result[42] = &frm_isa_STUL_impl;
result[43] = &frm_isa_STS_impl;
result[44] = &frm_isa_STSUL_impl;
result[45] = &frm_isa_ATOM_impl;
result[46] = &frm_isa_RED_impl;
result[47] = &frm_isa_CCTL_impl;
result[48] = &frm_isa_CCTLL_impl;
result[49] = &frm_isa_MEMBAR_impl;
result[50] = &frm_isa_BRA_impl;
result[51] = &frm_isa_JMP_impl;
result[52] = &frm_isa_CAL_impl;
result[53] = &frm_isa_JCAL_impl;
result[54] = &frm_isa_RET_impl;
result[55] = &frm_isa_BRK_impl;
result[56] = &frm_isa_CONT_impl;
result[57] = &frm_isa_LONGJMP_impl;
result[58] = &frm_isa_SSY_impl;
result[59] = &frm_isa_PBK_impl;
result[60] = &frm_isa_PCNT_impl;
result[61] = &frm_isa_PRET_impl;
result[62] = &frm_isa_PLONGJMP_impl;
result[63] = &frm_isa_EXIT_impl;
result[64] = &frm_isa_NOP_impl;
result[65] = &frm_isa_S2R_impl;
result[66] = &frm_isa_B2R_impl;
result[67] = &frm_isa_LEPC_impl;
result[68] = &frm_isa_BAR_impl;
result[69] = &frm_isa_VOTE_impl;
return result;
}

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

result = (_QWORD *)mhandle_calloc(70LL, 8LL, "isa.c:40");
frm_isa_inst_func = (__int64)result;
if ( !result )
{
fatal("%s: out of memory", "frm_isa_init");
result = (_QWORD *)frm_isa_inst_func;
}
result[1] = &frm_isa_FFMA_impl;
result[2] = &frm_isa_FADD_impl;
result[3] = &frm_isa_FADD32I_impl;
result[4] = &frm_isa_FCMP_impl;
result[5] = &frm_isa_FMUL_impl;
result[6] = &frm_isa_FMUL32I_impl;
result[7] = &frm_isa_FSETP_impl;
result[8] = &frm_isa_MUFU_impl;
result[9] = &frm_isa_DFMA_impl;
result[10] = &frm_isa_DADD_impl;
result[11] = &frm_isa_DMUL_impl;
result[12] = &frm_isa_DSETP_impl;
result[13] = &frm_isa_IMAD_impl;
result[14] = &frm_isa_IMUL_impl;
result[15] = &frm_isa_IADD_impl;
result[16] = &frm_isa_IADD32I_impl;
result[17] = &frm_isa_ISCADD_impl;
result[18] = &frm_isa_BFE_impl;
result[19] = &frm_isa_BFI_impl;
result[20] = &frm_isa_SHR_impl;
result[21] = &frm_isa_SHL_impl;
result[22] = &frm_isa_LOP_impl;
result[23] = &frm_isa_LOP32I_impl;
result[24] = &frm_isa_ISETP_impl;
result[25] = &frm_isa_ICMP_impl;
result[26] = &frm_isa_F2F_impl;
result[27] = &frm_isa_F2I_impl;
result[28] = &frm_isa_I2F_impl;
result[29] = &frm_isa_I2I_impl;
result[30] = &frm_isa_MOV_impl;
result[31] = &frm_isa_MOV32I_impl;
result[32] = &frm_isa_SEL_impl;
result[33] = &frm_isa_LDC_impl;
result[34] = &frm_isa_LD_impl;
result[35] = &frm_isa_LDU_impl;
result[36] = &frm_isa_LDL_impl;
result[37] = &frm_isa_LDS_impl;
result[38] = &frm_isa_LDLK_impl;
result[39] = &frm_isa_LDSLK_impl;
result[40] = &frm_isa_ST_impl;
result[41] = &frm_isa_STL_impl;
result[42] = &frm_isa_STUL_impl;
result[43] = &frm_isa_STS_impl;
result[44] = &frm_isa_STSUL_impl;
result[45] = &frm_isa_ATOM_impl;
result[46] = &frm_isa_RED_impl;
result[47] = &frm_isa_CCTL_impl;
result[48] = &frm_isa_CCTLL_impl;
result[49] = &frm_isa_MEMBAR_impl;
result[50] = &frm_isa_BRA_impl;
result[51] = &frm_isa_JMP_impl;
result[52] = &frm_isa_CAL_impl;
result[53] = &frm_isa_JCAL_impl;
result[54] = &frm_isa_RET_impl;
result[55] = &frm_isa_BRK_impl;
result[56] = &frm_isa_CONT_impl;
result[57] = &frm_isa_LONGJMP_impl;
result[58] = &frm_isa_SSY_impl;
result[59] = &frm_isa_PBK_impl;
result[60] = &frm_isa_PCNT_impl;
result[61] = &frm_isa_PRET_impl;
result[62] = &frm_isa_PLONGJMP_impl;
result[63] = &frm_isa_EXIT_impl;
result[64] = &frm_isa_NOP_impl;
result[65] = &frm_isa_S2R_impl;
result[66] = &frm_isa_B2R_impl;
result[67] = &frm_isa_LEPC_impl;
result[68] = &frm_isa_BAR_impl;
result[69] = &frm_isa_VOTE_impl;
return result;
}

original_code:
void frm_isa_init()
{
 frm_isa_inst_func = (mhandle_calloc(FRM_INST_COUNT, sizeof(frm_isa_inst_func_t), "isa.c" ":" "40"));
 if (!frm_isa_inst_func)
  fatal("%s: out of memory", __FUNCTION__);
frm_isa_inst_func[FRM_INST_FFMA] = frm_isa_FFMA_impl;
frm_isa_inst_func[FRM_INST_FADD] = frm_isa_FADD_impl;
frm_isa_inst_func[FRM_INST_FADD32I] = frm_isa_FADD32I_impl;
frm_isa_inst_func[FRM_INST_FCMP] = frm_isa_FCMP_impl;
frm_isa_inst_func[FRM_INST_FMUL] = frm_isa_FMUL_impl;
frm_isa_inst_func[FRM_INST_FMUL32I] = frm_isa_FMUL32I_impl;
frm_isa_inst_func[FRM_INST_FSETP] = frm_isa_FSETP_impl;
frm_isa_inst_func[FRM_INST_MUFU] = frm_isa_MUFU_impl;
frm_isa_inst_func[FRM_INST_DFMA] = frm_isa_DFMA_impl;
frm_isa_inst_func[FRM_INST_DADD] = frm_isa_DADD_impl;
frm_isa_inst_func[FRM_INST_DMUL] = frm_isa_DMUL_impl;
frm_isa_inst_func[FRM_INST_DSETP] = frm_isa_DSETP_impl;
frm_isa_inst_func[FRM_INST_IMAD] = frm_isa_IMAD_impl;
frm_isa_inst_func[FRM_INST_IMUL] = frm_isa_IMUL_impl;
frm_isa_inst_func[FRM_INST_IADD] = frm_isa_IADD_impl;
frm_isa_inst_func[FRM_INST_IADD32I] = frm_isa_IADD32I_impl;
frm_isa_inst_func[FRM_INST_ISCADD] = frm_isa_ISCADD_impl;
frm_isa_inst_func[FRM_INST_BFE] = frm_isa_BFE_impl;
frm_isa_inst_func[FRM_INST_BFI] = frm_isa_BFI_impl;
frm_isa_inst_func[FRM_INST_SHR] = frm_isa_SHR_impl;
frm_isa_inst_func[FRM_INST_SHL] = frm_isa_SHL_impl;
frm_isa_inst_func[FRM_INST_LOP] = frm_isa_LOP_impl;
frm_isa_inst_func[FRM_INST_LOP32I] = frm_isa_LOP32I_impl;
frm_isa_inst_func[FRM_INST_ISETP] = frm_isa_ISETP_impl;
frm_isa_inst_func[FRM_INST_ICMP] = frm_isa_ICMP_impl;
frm_isa_inst_func[FRM_INST_F2F] = frm_isa_F2F_impl;
frm_isa_inst_func[FRM_INST_F2I] = frm_isa_F2I_impl;
frm_isa_inst_func[FRM_INST_I2F] = frm_isa_I2F_impl;
frm_isa_inst_func[FRM_INST_I2I] = frm_isa_I2I_impl;
frm_isa_inst_func[FRM_INST_MOV] = frm_isa_MOV_impl;
frm_isa_inst_func[FRM_INST_MOV32I] = frm_isa_MOV32I_impl;
frm_isa_inst_func[FRM_INST_SEL] = frm_isa_SEL_impl;
frm_isa_inst_func[FRM_INST_LDC] = frm_isa_LDC_impl;
frm_isa_inst_func[FRM_INST_LD] = frm_isa_LD_impl;
frm_isa_inst_func[FRM_INST_LDU] = frm_isa_LDU_impl;
frm_isa_inst_func[FRM_INST_LDL] = frm_isa_LDL_impl;
frm_isa_inst_func[FRM_INST_LDS] = frm_isa_LDS_impl;
frm_isa_inst_func[FRM_INST_LDLK] = frm_isa_LDLK_impl;
frm_isa_inst_func[FRM_INST_LDSLK] = frm_isa_LDSLK_impl;
frm_isa_inst_func[FRM_INST_ST] = frm_isa_ST_impl;
frm_isa_inst_func[FRM_INST_STL] = frm_isa_STL_impl;
frm_isa_inst_func[FRM_INST_STUL] = frm_isa_STUL_impl;
frm_isa_inst_func[FRM_INST_STS] = frm_isa_STS_impl;
frm_isa_inst_func[FRM_INST_STSUL] = frm_isa_STSUL_impl;
frm_isa_inst_func[FRM_INST_ATOM] = frm_isa_ATOM_impl;
frm_isa_inst_func[FRM_INST_RED] = frm_isa_RED_impl;
frm_isa_inst_func[FRM_INST_CCTL] = frm_isa_CCTL_impl;
frm_isa_inst_func[FRM_INST_CCTLL] = frm_isa_CCTLL_impl;
frm_isa_inst_func[FRM_INST_MEMBAR] = frm_isa_MEMBAR_impl;
frm_isa_inst_func[FRM_INST_BRA] = frm_isa_BRA_impl;
frm_isa_inst_func[FRM_INST_JMP] = frm_isa_JMP_impl;
frm_isa_inst_func[FRM_INST_CAL] = frm_isa_CAL_impl;
frm_isa_inst_func[FRM_INST_JCAL] = frm_isa_JCAL_impl;
frm_isa_inst_func[FRM_INST_RET] = frm_isa_RET_impl;
frm_isa_inst_func[FRM_INST_BRK] = frm_isa_BRK_impl;
frm_isa_inst_func[FRM_INST_CONT] = frm_isa_CONT_impl;
frm_isa_inst_func[FRM_INST_LONGJMP] = frm_isa_LONGJMP_impl;
frm_isa_inst_func[FRM_INST_SSY] = frm_isa_SSY_impl;
frm_isa_inst_func[FRM_INST_PBK] = frm_isa_PBK_impl;
frm_isa_inst_func[FRM_INST_PCNT] = frm_isa_PCNT_impl;
frm_isa_inst_func[FRM_INST_PRET] = frm_isa_PRET_impl;
frm_isa_inst_func[FRM_INST_PLONGJMP] = frm_isa_PLONGJMP_impl;
frm_isa_inst_func[FRM_INST_EXIT] = frm_isa_EXIT_impl;
frm_isa_inst_func[FRM_INST_NOP] = frm_isa_NOP_impl;
frm_isa_inst_func[FRM_INST_S2R] = frm_isa_S2R_impl;
frm_isa_inst_func[FRM_INST_B2R] = frm_isa_B2R_impl;
frm_isa_inst_func[FRM_INST_LEPC] = frm_isa_LEPC_impl;
frm_isa_inst_func[FRM_INST_BAR] = frm_isa_BAR_impl;
frm_isa_inst_func[FRM_INST_VOTE] = frm_isa_VOTE_impl;
}


decompiled_code:
__int64 frm_isa_done()
{
return mhandle_free(frm_isa_inst_func, "isa.c:55");
}

canonical_decompiled_code:
__int64 func1()
{
return mhandle_free(frm_isa_inst_func, "isa.c:55");
}

original_code:
void frm_isa_done()
{
 (mhandle_free(frm_isa_inst_func, "isa.c" ":" "55"));
}


decompiled_code:
__int64 __fastcall frm_isa_global_mem_write(unsigned int a1, __int64 a2)
{
return mem_write(*(_QWORD *)(frm_emu + 232LL), a1, 4LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
return mem_write(*(_QWORD *)(frm_emu + 232LL), a1, 4LL, a2);
}

original_code:
void frm_isa_global_mem_write(unsigned int addr, void *pvalue)
{
 mem_write(frm_emu->global_mem, addr, sizeof(unsigned int), pvalue);
}

variable_types:
addr
unsigned int

variable_types:
pvalue
void *


decompiled_code:
__int64 __fastcall frm_isa_global_mem_read(unsigned int a1, __int64 a2)
{
return mem_read(*(_QWORD *)(frm_emu + 232LL), a1, 4LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2)
{
return mem_read(*(_QWORD *)(frm_emu + 232LL), a1, 4LL, a2);
}

original_code:
void frm_isa_global_mem_read(unsigned int addr, void *pvalue)
{
 mem_read(frm_emu->global_mem, addr, sizeof(unsigned int), pvalue);
}


decompiled_code:
__int64 __fastcall frm_isa_const_mem_write(unsigned int a1, __int64 a2)
{
__int64 v2; // rax

v2 = frm_emu;
if ( a1 <= 0x1F )
*(_DWORD *)(frm_emu + 4LL * a1 + 104) = 1;
return mem_write(*(_QWORD *)(v2 + 96), a1, 4LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2)
{
__int64 v2; // rax

v2 = frm_emu;
if ( a1 <= 0x1F )
*(_DWORD *)(frm_emu + 4LL * a1 + 104) = 1;
return mem_write(*(_QWORD *)(v2 + 96), a1, 4LL, a2);
}

original_code:
void frm_isa_const_mem_write(unsigned int addr, void *pvalue)
{
 if (addr < 0x20)
  frm_emu->const_mem_init[addr] = 1;
 mem_write(frm_emu->const_mem, addr, sizeof(unsigned int), pvalue);
}


decompiled_code:
__int64 __fastcall frm_isa_const_mem_read(unsigned int a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rax

v2 = a2;
v3 = frm_emu;
if ( a1 <= 0x1F && !*(_DWORD *)(frm_emu + 4LL * a1 + 104) )
{
warning("c [0] [0x%x] is used uninitialized", a1);
v3 = frm_emu;
v2 = a2;
}
return mem_read(*(_QWORD *)(v3 + 96), a1, 4LL, v2);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rax

v2 = a2;
v3 = frm_emu;
if ( a1 <= 0x1F && !*(_DWORD *)(frm_emu + 4LL * a1 + 104) )
{
warning("c [0] [0x%x] is used uninitialized", a1);
v3 = frm_emu;
v2 = a2;
}
return mem_read(*(_QWORD *)(v3 + 96), a1, 4LL, v2);
}

original_code:
void frm_isa_const_mem_read(unsigned int addr, void *pvalue)
{
 if (addr < 0x20 && !frm_emu->const_mem_init[addr])
  warning("c [0] [0x%x] is used uninitialized", addr);
 mem_read(frm_emu->const_mem, addr, sizeof(unsigned int), pvalue);
}


decompiled_code:
__int64 __fastcall frm_cuda_object_add(__int64 a1)
{
linked_list_find(frm_cuda_object_list, a1);
if ( !*(_DWORD *)(frm_cuda_object_list + 4) )
_assert_fail("frm_cuda_object_list->error_code", "cuda-obj.c", 0x2Au, "frm_cuda_object_add");
return linked_list_add(frm_cuda_object_list, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
linked_list_find(frm_cuda_object_list, a1);
if ( !*(_DWORD *)(frm_cuda_object_list + 4) )
_assert_fail("frm_cuda_object_list->error_code", "cuda-obj.c", 0x2Au, "frm_cuda_object_add");
return linked_list_add(frm_cuda_object_list, a1);
}

original_code:
void frm_cuda_object_add(void *object)
{
 linked_list_find(frm_cuda_object_list, object);
 ((void) sizeof ((frm_cuda_object_list->error_code) ? 1 : 0), __extension__ ({ if (frm_cuda_object_list->error_code) ; else __assert_fail ("frm_cuda_object_list->error_code", "cuda-obj.c", 42, __extension__ __PRETTY_FUNCTION__); }));
 linked_list_add(frm_cuda_object_list, object);
}

variable_types:
object
void *


decompiled_code:
__int64 __fastcall frm_cuda_object_remove(__int64 a1)
{
linked_list_find(frm_cuda_object_list, a1);
if ( *(_DWORD *)(frm_cuda_object_list + 4) )
_assert_fail("!frm_cuda_object_list->error_code", "cuda-obj.c", 0x34u, "frm_cuda_object_remove");
return linked_list_remove();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
linked_list_find(frm_cuda_object_list, a1);
if ( *(_DWORD *)(frm_cuda_object_list + 4) )
_assert_fail("!frm_cuda_object_list->error_code", "cuda-obj.c", 0x34u, "frm_cuda_object_remove");
return linked_list_remove();
}

original_code:
void frm_cuda_object_remove(void *object)
{
 linked_list_find(frm_cuda_object_list, object);
 ((void) sizeof ((!frm_cuda_object_list->error_code) ? 1 : 0), __extension__ ({ if (!frm_cuda_object_list->error_code) ; else __assert_fail ("!frm_cuda_object_list->error_code", "cuda-obj.c", 52, __extension__ __PRETTY_FUNCTION__); }));
 linked_list_remove(frm_cuda_object_list);
}


decompiled_code:
__int64 __fastcall frm_cuda_object_new_id(int a1)
{
unsigned int v1; // er12

v1 = cuda_current_object_id_7++ | (a1 << 16);
if ( (unsigned int)cuda_current_object_id_7 > 0xFFFF )
fatal("cuda_object_new_id: too many CUDA objects");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
unsigned int v1; // er12

v1 = cuda_current_object_id_7++ | (a1 << 16);
if ( (unsigned int)cuda_current_object_id_7 > 0xFFFF )
fatal("cuda_object_new_id: too many CUDA objects");
return v1;
}

original_code:
unsigned int frm_cuda_object_new_id(enum frm_cuda_obj_t type)
{
 static unsigned int cuda_current_object_id;
 unsigned int id;
 id = (type << 16) | cuda_current_object_id;
 cuda_current_object_id++;
 if (cuda_current_object_id > 0xffff)
  fatal("cuda_object_new_id: too many CUDA objects");
 return id;
}

variable_types: enum frm_cuda_obj_t { FRM_CUDA_OBJ_DEVICE=1, FRM_CUDA_OBJ_CONTEXT=2, FRM_CUDA_OBJ_MODULE=3, FRM_CUDA_OBJ_FUNCTION=4, FRM_CUDA_OBJ_MEMORY=5, FRM_CUDA_OBJ_STREAM=6 }

variable_types:
id
unsigned int


decompiled_code:
_DWORD *frm_cuda_device_create()
{
_DWORD *v0; // r12

v0 = (_DWORD *)mhandle_calloc(1LL, 4LL, "cuda-obj.c:170");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_device_create");
*v0 = frm_cuda_object_new_id(1);
frm_cuda_object_add((__int64)v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func3()
{
_DWORD *v0; // r12

v0 = (_DWORD *)mhandle_calloc(1LL, 4LL, "cuda-obj.c:170");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_device_create");
*v0 = func2(1);
func0((__int64)v0);
return v0;
}

original_code:
struct frm_cuda_device_t *frm_cuda_device_create()
{
 struct frm_cuda_device_t *device;
 device = (mhandle_calloc(1, sizeof(struct frm_cuda_device_t), "cuda-obj.c" ":" "170"));
 if (!device)
  fatal("%s: out of memory", __FUNCTION__);
 device->id = frm_cuda_object_new_id(FRM_CUDA_OBJ_DEVICE);
 frm_cuda_object_add(device);
 return device;
}

variable_types: struct frm_cuda_device_t { unsigned int id; } *


decompiled_code:
__int64 __fastcall frm_cuda_device_free(__int64 a1)
{
frm_cuda_object_remove(a1);
return mhandle_free(a1, "cuda-obj.c:188");
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
func1(a1);
return mhandle_free(a1, "cuda-obj.c:188");
}

original_code:
void frm_cuda_device_free(struct frm_cuda_device_t *device)
{
 frm_cuda_object_remove(device);
 (mhandle_free(device, "cuda-obj.c" ":" "188"));
}

user_defined_types: struct frm_cuda_device_t { unsigned int id; }


decompiled_code:
_DWORD *frm_cuda_context_create()
{
_DWORD *v0; // r12
int v1; // eax

v0 = (_DWORD *)mhandle_calloc(1LL, 12LL, "cuda-obj.c:205");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_context_create");
v1 = frm_cuda_object_new_id(2);
v0[1] = 1;
*v0 = v1;
frm_cuda_object_add((__int64)v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func5()
{
_DWORD *v0; // r12
int v1; // eax

v0 = (_DWORD *)mhandle_calloc(1LL, 12LL, "cuda-obj.c:205");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_context_create");
v1 = func2(2);
v0[1] = 1;
*v0 = v1;
func0((__int64)v0);
return v0;
}

original_code:
struct frm_cuda_context_t *frm_cuda_context_create()
{
 struct frm_cuda_context_t *context;
 context = (mhandle_calloc(1, sizeof(struct frm_cuda_context_t), "cuda-obj.c" ":" "205"));
 if (!context)
  fatal("%s: out of memory", __FUNCTION__);
 context->id = frm_cuda_object_new_id(FRM_CUDA_OBJ_CONTEXT);
 context->ref_count = 1;
 frm_cuda_object_add(context);
 return context;
}

variable_types: struct frm_cuda_context_t { unsigned int id; int ref_count; unsigned int device_id; } *


decompiled_code:
__int64 __fastcall frm_cuda_context_free(__int64 a1)
{
frm_cuda_object_remove(a1);
return mhandle_free(a1, "cuda-obj.c:224");
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
func1(a1);
return mhandle_free(a1, "cuda-obj.c:224");
}

original_code:
void frm_cuda_context_free(struct frm_cuda_context_t *context)
{
 frm_cuda_object_remove(context);
 (mhandle_free(context, "cuda-obj.c" ":" "224"));
}

user_defined_types: struct frm_cuda_context_t { unsigned int id; int ref_count; unsigned int device_id; }


decompiled_code:
_DWORD *frm_cuda_module_create()
{
_DWORD *v0; // r12
int v1; // eax

v0 = (_DWORD *)mhandle_calloc(1LL, 24LL, "cuda-obj.c:241");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_module_create");
v1 = frm_cuda_object_new_id(3);
v0[1] = 1;
*v0 = v1;
frm_cuda_object_add((__int64)v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func7()
{
_DWORD *v0; // r12
int v1; // eax

v0 = (_DWORD *)mhandle_calloc(1LL, 24LL, "cuda-obj.c:241");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_module_create");
v1 = func2(3);
v0[1] = 1;
*v0 = v1;
func0((__int64)v0);
return v0;
}

original_code:
struct frm_cuda_module_t *frm_cuda_module_create()
{
 struct frm_cuda_module_t *module;
 module = (mhandle_calloc(1, sizeof(struct frm_cuda_module_t), "cuda-obj.c" ":" "241"));
 if (!module)
  fatal("%s: out of memory", __FUNCTION__);
 module->id = frm_cuda_object_new_id(FRM_CUDA_OBJ_MODULE);
 module->ref_count = 1;
 frm_cuda_object_add(module);
 return module;
}

variable_types: struct frm_cuda_module_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; struct elf_file_t { char *path; struct elf_buffer_t { void *ptr; int size; int pos; } buffer; struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *header; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *section_list; struct elf_section_t { char *name; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *header; struct elf_buffer_t buffer; } *string_table; struct list_t *program_header_list; struct list_t *symbol_table; } *elf_file; } *

user_defined_types: struct frm_cuda_module_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; struct elf_file_t *elf_file; }

user_defined_types: struct elf_file_t { char *path; struct elf_buffer_t buffer; struct Elf32_Ehdr *header; struct list_t *section_list; struct elf_section_t *string_table; struct list_t *program_header_list; struct list_t *symbol_table; }

user_defined_types: struct elf_section_t { char *name; struct Elf32_Shdr *header; struct elf_buffer_t buffer; }


decompiled_code:
__int64 __fastcall frm_cuda_module_free(__int64 a1)
{
if ( *(_QWORD *)(a1 + 16) )
elf_file_free();
frm_cuda_object_remove(a1);
return mhandle_free(a1, "cuda-obj.c:262");
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
if ( *(_QWORD *)(a1 + 16) )
elf_file_free();
func1(a1);
return mhandle_free(a1, "cuda-obj.c:262");
}

original_code:
void frm_cuda_module_free(struct frm_cuda_module_t *module)
{
 if (module->elf_file)
  elf_file_free(module->elf_file);
 frm_cuda_object_remove(module);
 (mhandle_free(module, "cuda-obj.c" ":" "262"));
}

user_defined_types: struct elf_buffer_t { void *ptr; int size; int pos; }

user_defined_types: struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }

user_defined_types: struct list_t { int count; int error_code; int size; int head; int tail; void **elem; }

user_defined_types: struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; }


decompiled_code:
__int64 __fastcall frm_cuda_function_arg_create(char *src)
{
size_t v1; // rax
__int64 v2; // r12

v1 = strlen(src);
v2 = mhandle_calloc(1LL, v1 + 221, "cuda-obj.c:277");
if ( !v2 )
fatal("%s: out of memory", "frm_cuda_function_arg_create");
strncpy((char *)(v2 + 4), src, 0xC8uLL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *src)
{
size_t v1; // rax
__int64 v2; // r12

v1 = strlen(src);
v2 = mhandle_calloc(1LL, v1 + 221, "cuda-obj.c:277");
if ( !v2 )
fatal("%s: out of memory", "frm_cuda_function_arg_create");
strncpy((char *)(v2 + 4), src, 0xC8uLL);
return v2;
}

original_code:
struct frm_cuda_function_arg_t *frm_cuda_function_arg_create(char *name)
{
 struct frm_cuda_function_arg_t *arg;
 arg = (mhandle_calloc(1, sizeof(struct frm_cuda_function_arg_t) + strlen(name) + 1, "cuda-obj.c" ":" "277"));
 if (!arg)
  fatal("%s: out of memory", __FUNCTION__);
 strncpy(arg->name, name, 200);
 return arg;
}

variable_types:
name
char *

variable_types: struct frm_cuda_function_arg_t { int id; char name[200]; enum frm_cuda_function_arg_kind_t { FRM_CUDA_FUNCTION_ARG_KIND_VALUE=1, FRM_CUDA_FUNCTION_ARG_KIND_POINTER=2 } kind; enum frm_cuda_mem_scope_t { FRM_CUDA_MEM_SCOPE_NONE=0, FRM_CUDA_MEM_SCOPE_GLOBAL=1, FRM_CUDA_MEM_SCOPE_LOCAL=2, FRM_CUDA_MEM_SCOPE_PRIVATE=3, FRM_CUDA_MEM_SCOPE_CONSTANT=4 } mem_scope; enum frm_cuda_function_arg_access_type_t { FRM_CUDA_FUNCTION_ARG_READ_ONLY=1, FRM_CUDA_FUNCTION_ARG_WRITE_ONLY=2, FRM_CUDA_FUNCTION_ARG_READ_WRITE=3 } access_type; unsigned int value; } *

user_defined_types: struct frm_cuda_function_arg_t { int id; char name[200]; enum frm_cuda_function_arg_kind_t kind; enum frm_cuda_mem_scope_t mem_scope; enum frm_cuda_function_arg_access_type_t access_type; unsigned int value; }


decompiled_code:
__int64 __fastcall frm_cuda_function_arg_free(__int64 a1)
{
return mhandle_free(a1, "cuda-obj.c:291");
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return mhandle_free(a1, "cuda-obj.c:291");
}

original_code:
void frm_cuda_function_arg_free(struct frm_cuda_function_arg_t *arg)
{
 (mhandle_free(arg, "cuda-obj.c" ":" "291"));
}

user_defined_types: enum frm_cuda_function_arg_kind_t { FRM_CUDA_FUNCTION_ARG_KIND_VALUE=1, FRM_CUDA_FUNCTION_ARG_KIND_POINTER=2 }

user_defined_types: enum frm_cuda_mem_scope_t { FRM_CUDA_MEM_SCOPE_NONE=0, FRM_CUDA_MEM_SCOPE_GLOBAL=1, FRM_CUDA_MEM_SCOPE_LOCAL=2, FRM_CUDA_MEM_SCOPE_PRIVATE=3, FRM_CUDA_MEM_SCOPE_CONSTANT=4 }

user_defined_types: enum frm_cuda_function_arg_access_type_t { FRM_CUDA_FUNCTION_ARG_READ_ONLY=1, FRM_CUDA_FUNCTION_ARG_WRITE_ONLY=2, FRM_CUDA_FUNCTION_ARG_READ_WRITE=3 }


decompiled_code:
_DWORD *frm_cuda_memory_create()
{
_DWORD *v0; // r12
int v1; // eax

v0 = (_DWORD *)mhandle_calloc(1LL, 20LL, "cuda-obj.c:349");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_memory_create");
v1 = frm_cuda_object_new_id(5);
v0[1] = 1;
*v0 = v1;
frm_cuda_object_add((__int64)v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func13()
{
_DWORD *v0; // r12
int v1; // eax

v0 = (_DWORD *)mhandle_calloc(1LL, 20LL, "cuda-obj.c:349");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_memory_create");
v1 = func2(5);
v0[1] = 1;
*v0 = v1;
func0((__int64)v0);
return v0;
}

original_code:
struct frm_cuda_memory_t *frm_cuda_memory_create()
{
        struct frm_cuda_memory_t *mem;
        mem = (mhandle_calloc(1, sizeof(struct frm_cuda_memory_t), "cuda-obj.c" ":" "349"));
        if (!mem)
                fatal("%s: out of memory", __FUNCTION__);
        mem->id = frm_cuda_object_new_id(FRM_CUDA_OBJ_MEMORY);
        mem->ref_count = 1;
        frm_cuda_object_add(mem);
        return mem;
}

variable_types: struct frm_cuda_memory_t { unsigned int id; int ref_count; unsigned int size; unsigned int host_ptr; unsigned int device_ptr; } *


decompiled_code:
__int64 __fastcall frm_cuda_memory_free(__int64 a1)
{
frm_cuda_object_remove(a1);
return mhandle_free(a1, "cuda-obj.c:366");
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
func1(a1);
return mhandle_free(a1, "cuda-obj.c:366");
}

original_code:
void frm_cuda_memory_free(struct frm_cuda_memory_t *mem)
{
        frm_cuda_object_remove(mem);
        (mhandle_free(mem, "cuda-obj.c" ":" "366"));
}

user_defined_types: struct frm_cuda_memory_t { unsigned int id; int ref_count; unsigned int size; unsigned int host_ptr; unsigned int device_ptr; }