decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx
__int64 j; // rbx
void *v8; // [rsp+0h] [rbp-28h] BYREF
_DWORD *v9; // [rsp+8h] [rbp-20h] BYREF
_DWORD *v10; // [rsp+10h] [rbp-18h] BYREF
int v11; // [rsp+18h] [rbp-10h] BYREF
int v12[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v10 = malloc(0x10uLL);
mdi_init(&v10, argv);
v9 = malloc(0x10uLL);
mdi_init(&v9, argv);
v8 = malloc(0x10uLL);
mdi_init(&v8, argv);
puts(
"1. Compute Sum of n mdi data\n"
"2. Compute n!\n"
"3. Compute 2^n\n"
"Enter the serial number. Enter '4' to switch to another computation. Enter '-1' to exit:");
while ( (unsigned int)_isoc99_scanf("%d", v12) )
{
if ( v12[0] != 5 )
{
switch ( v12[0] )
{
case 1:
puts("Enter the number of mdi data to be added:");
_isoc99_scanf("%d", &v11);
mdi_set_int(&v8, 0LL);
puts("Enter the mdi numbers:");
while ( v11-- )
{
v10 = (_DWORD *)read_mdi(v10);
mdi_set(&v9, v8);
if ( v10[3] < v9[3] )
mdi_add(&v8, v9, v10);
else
mdi_add(&v8, v10, v9);
}
break;
case 2:
puts("Enter the number for which factorial is to be calculated:");
_isoc99_scanf("%d", &v11);
mdi_init(&v8, &v11);
mdi_set_int(&v8, 1LL);
if ( v11 > 0 )
{
for ( i = 1LL; i <= v11; ++i )
{
**(_DWORD **)v10 = i;
v10[3] = 1;
mdi_set(&v9, v8);
mdi_mul(&v8, v9, v10);
}
}
break;
case 3:
puts("Enter the power of 2:");
_isoc99_scanf("%d", &v11);
mdi_init(&v8, &v11);
mdi_set_int(&v8, 1LL);
**(_DWORD **)v10 = 2;
v10[3] = 1;
if ( v11 > 0 )
{
for ( j = 1LL; j <= v11; ++j )
{
mdi_set(&v9, v8);
mdi_mul(&v8, v9, v10);
}
}
break;
default:
return 0;
}
print_mdi(v8);
}
}
return 0;
}

original_code:
int main()
{
 int j, k, flag, n;
 long int num, i;
 mdi_ptr input1, input2, res;
 input1 = (mdi_ptr)malloc(sizeof(mdi));
 mdi_init(&input1);
 input2 = (mdi_ptr)malloc(sizeof(mdi));
 mdi_init(&input2);
 res = (mdi_ptr)malloc(sizeof(mdi));
 mdi_init(&res);
 printf("1. Compute Sum of n mdi data\n2. Compute n!\n3. Compute 2^n\nEnter the serial number. Enter '4' to switch to another computation. Enter '-1' to exit:\n");
 while(scanf("%d", &flag))
 {
  if(flag == 5)
   continue;
  else if(flag == 1)
  {
   printf("Enter the number of mdi data to be added:\n");
   scanf("%d", &n);
   mdi_set_int(&res, 0);
   printf("Enter the mdi numbers:\n");
   while(n--)
   {
    input1 = read_mdi(input1);
    mdi_set(&input2, res);
    if(input1->digits >= input2->digits)
     mdi_add(&res, input1, input2);
    else
     mdi_add(&res, input2, input1);
   }
   print_mdi(res);
  }
  else if(flag == 2)
  {
   printf("Enter the number for which factorial is to be calculated:\n");
   scanf("%d", &n);
   mdi_init(&res);
   mdi_set_int(&res, 1);
   for(i=1; i<=n; i++)
   {
    input1->dp[0] = i;
    input1->digits = 1;
    mdi_set(&input2, res);
    mdi_mul(&res, input2, input1);
   }
   print_mdi(res);
  }
  else if(flag == 3)
  {
   printf("Enter the power of 2:\n");
   scanf("%d", &n);
   mdi_init(&res);
   mdi_set_int(&res, 1);
   input1->dp[0] = 2;
   input1->digits = 1;
   for(i=1; i<=n; i++)
   {
    mdi_set(&input2, res);
    mdi_mul(&res, input2, input1);
   }
   print_mdi(res);
  }
  else
   break;
 }
 return 0;
}

canonical_original_code:
int main()
{
 int j; int k; int flag; int n;
 long num; long i;
 struct mdi *input1; struct mdi *input2; struct mdi *res;
 input1 = (struct mdi *)malloc(sizeof(mdi));
 mdi_init(&input1);
 input2 = (struct mdi *)malloc(sizeof(mdi));
 mdi_init(&input2);
 res = (struct mdi *)malloc(sizeof(mdi));
 mdi_init(&res);
 printf("1. Compute Sum of n mdi data\n2. Compute n!\n3. Compute 2^n\nEnter the serial number. Enter '4' to switch to another computation. Enter '-1' to exit:\n");
 while(scanf("%d", &flag))
 {
  if(flag == 5)
   continue;
  else if(flag == 1)
  {
   printf("Enter the number of mdi data to be added:\n");
   scanf("%d", &n);
   mdi_set_int(&res, 0);
   printf("Enter the mdi numbers:\n");
   while(n--)
   {
    input1 = read_mdi(input1);
    mdi_set(&input2, res);
    if(input1->digits >= input2->digits)
     mdi_add(&res, input1, input2);
    else
     mdi_add(&res, input2, input1);
   }
   print_mdi(res);
  }
  else if(flag == 2)
  {
   printf("Enter the number for which factorial is to be calculated:\n");
   scanf("%d", &n);
   mdi_init(&res);
   mdi_set_int(&res, 1);
   for(i=1; i<=n; i++)
   {
    input1->dp[0] = i;
    input1->digits = 1;
    mdi_set(&input2, res);
    mdi_mul(&res, input2, input1);
   }
   print_mdi(res);
  }
  else if(flag == 3)
  {
   printf("Enter the power of 2:\n");
   scanf("%d", &n);
   mdi_init(&res);
   mdi_set_int(&res, 1);
   input1->dp[0] = 2;
   input1->digits = 1;
   for(i=1; i<=n; i++)
   {
    mdi_set(&input2, res);
    mdi_mul(&res, input2, input1);
   }
   print_mdi(res);
  }
  else
   break;
 }
 return 0;
}

variable_types: j int

variable_types: k int

variable_types: flag int

variable_types: num long

variable_types: i long

variable_types: struct mdi { unsigned int *dp; int ss; unsigned int digits; } *


repo: raidenawkward/nn

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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 64) )
bp_layer_destory_nodes();
result = bp_node_destory(a1);
}
return result;
}

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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 64) )
func0();
result = bp_node_destory(a1);
}
return result;
}

original_code:
static void bp_layer_destory_nodes(struct BPNode* node) {
 if (!node)
  return;
 if (node->next)
  bp_layer_destory_nodes(node->next);
 bp_node_destory(node);
}

canonical_original_code:
static void bp_layer_destory_nodes(struct BPNode *node) {
 if (!node)
  return;
 if (node->next)
  bp_layer_destory_nodes(node->next);
 bp_node_destory(node);
}

variable_types: struct BPNode { float input_weights[10]; int input_count; float threshold; float output; float (*get_output)(struct BPNode); struct BPNode *next; } *

return_type: void


decompiled_code:
float *__fastcall bp_layer_make_random_array(int a1, int a2)
{
float *v2; // r13
unsigned int v3; // eax
float *v4; // rbx

v2 = (float *)malloc(4LL * a1);
if ( v2 )
{
v3 = time(0LL);
srand(v3);
if ( a1 > 0 )
{
v4 = v2;
do
*v4++ = (float)(rand() % a2) / (float)a2;
while ( v4 != &v2[a1] );
}
}
return v2;
}

canonical_decompiled_code:
float *__fastcall func1(int a1, int a2)
{
float *v2; // r13
unsigned int v3; // eax
float *v4; // rbx

v2 = (float *)malloc(4LL * a1);
if ( v2 )
{
v3 = time(0LL);
srand(v3);
if ( a1 > 0 )
{
v4 = v2;
do
*v4++ = (float)(rand() % a2) / (float)a2;
while ( v4 != &v2[a1] );
}
}
return v2;
}

original_code:
static float* bp_layer_make_random_array(int length, int accuracy) {
 float *array = (float*)malloc(sizeof(float) * length);
 if (!array)
  return array;
 int i;
 srand(time(((void *)0)));
 for (i = 0; i < length; ++i) {
  array[i] = ((float)(rand() % accuracy)) / accuracy;
 }
 return array;
}

canonical_original_code:
static float *bp_layer_make_random_array(int length, int accuracy) {
 float *array = (float*)malloc(sizeof(float) * length);
 if (!array)
  return array;
 int i;
 srand(time(((void *)0)));
 for (i = 0; i < length; ++i) {
  array[i] = ((float)(rand() % accuracy)) / accuracy;
 }
 return array;
}

variable_types: length int

variable_types: accuracy int

variable_types:
array
float *

variable_types: i int

return_type: float *


decompiled_code:
_DWORD *bp_layer_create()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

canonical_decompiled_code:
_DWORD *func2()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

original_code:
struct BPLayer* bp_layer_create() {
 struct BPLayer* layer = (struct BPLayer*)malloc(sizeof(struct BPLayer));
 if (!layer)
  return layer;
 layer->first = ((void *)0);
 layer->node_count = 0;
 return layer;
}

canonical_original_code:
struct BPLayer *bp_layer_create() {
 struct BPLayer *layer = (struct BPLayer*)malloc(sizeof(struct BPLayer));
 if (!layer)
  return layer;
 layer->first = ((void *)0);
 layer->node_count = 0;
 return layer;
}

variable_types: struct BPLayer { struct BPNode { float input_weights[10]; int input_count; float threshold; float output; float (*get_output)(struct BPNode); struct BPNode *next; } *first; int node_count; } *

user_defined_types: struct BPLayer { struct BPNode *first; int node_count; }


decompiled_code:
__int64 __fastcall bp_layer_indexed_node(__int64 *a1, int a2)
{
__int64 result; // rax
int v3; // edx

if ( !a1 )
return 0LL;
if ( *((_DWORD *)a1 + 2) <= a2 )
return 0LL;
result = *a1;
if ( *a1 && a2 )
{
v3 = 0;
do
{
result = *(_QWORD *)(result + 64);
++v3;
}
while ( result && a2 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, int a2)
{
__int64 result; // rax
int v3; // edx

if ( !a1 )
return 0LL;
if ( *((_DWORD *)a1 + 2) <= a2 )
return 0LL;
result = *a1;
if ( *a1 && a2 )
{
v3 = 0;
do
{
result = *(_QWORD *)(result + 64);
++v3;
}
while ( result && a2 != v3 );
}
return result;
}

original_code:
struct BPNode* bp_layer_indexed_node(struct BPLayer* layer, int index) {
 if (!layer)
  return ((void *)0);
 if (index >= layer->node_count)
  return ((void *)0);
 struct BPNode* node = layer->first;
 int current = 0;
 while(node) {
  if (current == index)
   return node;
  node = node->next;
  ++ current;
 }
 return ((void *)0);
}

canonical_original_code:
struct BPNode *bp_layer_indexed_node(struct BPLayer *layer, int index) {
 if (!layer)
  return ((void *)0);
 if (index >= layer->node_count)
  return ((void *)0);
 struct BPNode *node = layer->first;
 int current = 0;
 while(node) {
  if (current == index)
   return node;
  node = node->next;
  ++ current;
 }
 return ((void *)0);
}

variable_types: struct BPLayer { struct BPNode *first; int node_count; } *

variable_types: index int

variable_types: current int

return_type: struct BPNode { float input_weights[10]; int input_count; float threshold; float output; float (*get_output)(struct BPNode); struct BPNode *next; } *


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

if ( a1 )
result = bp_layer_destory_nodes(*a1);
return result;
}

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

if ( a1 )
result = func0(*a1);
return result;
}

original_code:
void bp_layer_destory(struct BPLayer* layer) {
 if (!layer)
  return;
 bp_layer_destory_nodes(layer->first);
}

canonical_original_code:
void bp_layer_destory(struct BPLayer *layer) {
 if (!layer)
  return;
 bp_layer_destory_nodes(layer->first);
}

user_defined_types: struct BPNode { float input_weights[10]; int input_count; float threshold; float output; float (*get_output)(struct BPNode); struct BPNode *next; }


original_code:
int bp_layer_append(struct BPLayer* layer, struct BPNode* node) {
 if (!layer || !node)
  return 0;
 if (layer->node_count < 0)
  return 0;
 if (layer->node_count == 0) {
  layer->first = node;
  node->next = ((void *)0);
 } else {
  struct BPNode* last = layer->first;
  while (last->next) {
   last = last->next;
  }
  last->next = node;
  node->next = ((void *)0);
 }
 ++ layer->node_count;
 return 1;
}

canonical_original_code:
int bp_layer_append(struct BPLayer *layer, struct BPNode *node) {
 if (!layer || !node)
  return 0;
 if (layer->node_count < 0)
  return 0;
 if (layer->node_count == 0) {
  layer->first = node;
  node->next = ((void *)0);
 } else {
  struct BPNode *last = layer->first;
  while (last->next) {
   last = last->next;
  }
  last->next = node;
  node->next = ((void *)0);
 }
 ++ layer->node_count;
 return 1;
}

variable_types:
node
struct BPNode *

return_type: int


original_code:
int bp_layer_connect(struct BPLayer* level0, struct BPLayer* level1) {
 if (!level1)
  return 0;
 if (!level0) {
  struct BPNode *node = level1->first;
  while (node) {
   memset(node->input_weights,0x00,10);
   node->input_weights[0] = (1.0);
   node->input_count = 1;
   node = node->next;
  }
  return 1;
 }
 struct BPNode* node = level1->first;
 while (node) {
  if (node->input_count >= 10)
   goto err;
  memset(node->input_weights,0x00,10);
  int i;
  for (i = 0; i < level0->node_count; ++i)
   node->input_weights[i] = (0.5);
  node->input_count = level0->node_count;
  node = node->next;
 }
 return 1;
err:
 return 0;
}

canonical_original_code:
int bp_layer_connect(struct BPLayer *level0, struct BPLayer *level1) {
 if (!level1)
  return 0;
 if (!level0) {
  struct BPNode *node = level1->first;
  while (node) {
   memset(node->input_weights,0x00,10);
   node->input_weights[0] = (1.0);
   node->input_count = 1;
   node = node->next;
  }
  return 1;
 }
 struct BPNode *node = level1->first;
 while (node) {
  if (node->input_count >= 10)
   goto err;
  memset(node->input_weights,0x00,10);
  int i;
  for (i = 0; i < level0->node_count; ++i)
   node->input_weights[i] = (0.5);
  node->input_count = level0->node_count;
  node = node->next;
 }
 return 1;
err:
 return 0;
}


decompiled_code:
void __fastcall bp_layer_weights_randomize(__int64 *a1, int a2)
{
__int64 i; // rbx
int v3; // edi
float *v4; // rdi
int v5; // edx
__int64 j; // rax

if ( a1 )
{
for ( i = *a1; i; i = *(_QWORD *)(i + 64) )
{
v3 = *(_DWORD *)(i + 40);
if ( v3 )
{
v4 = bp_layer_make_random_array(v3, a2);
if ( !v4 )
return;
v5 = *(_DWORD *)(i + 40);
if ( v5 > 0 )
{
for ( j = 0LL; j != v5; ++j )
*(float *)(i + 4 * j) = v4[j];
}
free(v4);
}
}
}
}

original_code:
void bp_layer_weights_randomize(struct BPLayer* layer, int accuracy) {
 if (!layer)
  return;
 struct BPNode *node = layer->first;
 while (node) {
  if (node->input_count) {
   float *rand_array = bp_layer_make_random_array(node->input_count,accuracy);
   if (!rand_array)
    return;
   int i;
   for (i = 0; i < node->input_count; ++i)
    node->input_weights[i] = rand_array[i];
   free(rand_array);
  }
  node = node->next;
 }
}

canonical_original_code:
void bp_layer_weights_randomize(struct BPLayer *layer, int accuracy) {
 if (!layer)
  return;
 struct BPNode *node = layer->first;
 while (node) {
  if (node->input_count) {
   float *rand_array = bp_layer_make_random_array(node->input_count,accuracy);
   if (!rand_array)
    return;
   int i;
   for (i = 0; i < node->input_count; ++i)
    node->input_weights[i] = rand_array[i];
   free(rand_array);
  }
  node = node->next;
 }
}


decompiled_code:
_WORD *bp_node_create()
{
_WORD *result; // rax

result = malloc(0x48uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[4] = 0;
*((_DWORD *)result + 10) = 0;
*((_DWORD *)result + 11) = 0;
*((_DWORD *)result + 12) = 0;
*((_QWORD *)result + 7) = 0LL;
*((_QWORD *)result + 8) = 0LL;
}
return result;
}

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

result = malloc(0x48uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[4] = 0;
*((_DWORD *)result + 10) = 0;
*((_DWORD *)result + 11) = 0;
*((_DWORD *)result + 12) = 0;
*((_QWORD *)result + 7) = 0LL;
*((_QWORD *)result + 8) = 0LL;
}
return result;
}

original_code:
struct BPNode* bp_node_create() {
 struct BPNode *node = (struct BPNode*)malloc(sizeof(struct BPNode));
 if (!node)
  return node;
 memset(node->input_weights,0x00,10);
 node->input_count = 0;
 node->threshold = 0;
 node->output = 0;
 node->get_output = ((void *)0);
 node->next = ((void *)0);
 return node;
}

canonical_original_code:
struct BPNode *bp_node_create() {
 struct BPNode *node = (struct BPNode*)malloc(sizeof(struct BPNode));
 if (!node)
  return node;
 memset(node->input_weights,0x00,10);
 node->input_count = 0;
 node->threshold = 0;
 node->output = 0;
 node->get_output = ((void *)0);
 node->next = ((void *)0);
 return node;
}


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

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

original_code:
void bp_node_destory(struct BPNode* node) {
 if (!node)
  return;
 free(node);
}

canonical_original_code:
void bp_node_destory(struct BPNode *node) {
 if (!node)
  return;
 free(node);
}


decompiled_code:
int __fastcall print_net_info(__int64 a1)
{
__int64 i; // r13
int result; // eax
__int64 v3; // rbx
__int64 v4; // rbp
unsigned int v5; // er12

if ( !a1 )
return puts("empty ptr!");
for ( i = 0LL; *(_DWORD *)(a1 + 8) > (int)i; ++i )
{
printf("level %d\t", (unsigned int)i);
v4 = *(_QWORD *)(*(_QWORD *)a1 + 16 * i);
if ( v4 )
{
v5 = 0;
do
{
printf("node %d (", v5);
if ( *(int *)(v4 + 40) > 0 )
{
v3 = 0LL;
do
{
printf("%0.3f", *(float *)(v4 + 4 * v3));
if ( *(_DWORD *)(v4 + 40) - 1 != (_DWORD)v3 )
putchar(44);
++v3;
}
while ( *(_DWORD *)(v4 + 40) > (int)v3 );
}
printf(")\t");
v4 = *(_QWORD *)(v4 + 64);
++v5;
}
while ( v4 );
}
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
__int64 i; // r13
int result; // eax
__int64 v3; // rbx
__int64 v4; // rbp
unsigned int v5; // er12

if ( !a1 )
return puts("empty ptr!");
for ( i = 0LL; *(_DWORD *)(a1 + 8) > (int)i; ++i )
{
printf("level %d\t", (unsigned int)i);
v4 = *(_QWORD *)(*(_QWORD *)a1 + 16 * i);
if ( v4 )
{
v5 = 0;
do
{
printf("node %d (", v5);
if ( *(int *)(v4 + 40) > 0 )
{
v3 = 0LL;
do
{
printf("%0.3f", *(float *)(v4 + 4 * v3));
if ( *(_DWORD *)(v4 + 40) - 1 != (_DWORD)v3 )
putchar(44);
++v3;
}
while ( *(_DWORD *)(v4 + 40) > (int)v3 );
}
printf(")\t");
v4 = *(_QWORD *)(v4 + 64);
++v5;
}
while ( v4 );
}
result = putchar(10);
}
return result;
}

original_code:
static void print_net_info(struct BPNet* net) {
 if (!net) {
  printf("empty ptr!\n");
  return;
 }
 int i;
 for (i = 0; i < net->layer_count; ++i) {
  printf("level %d\t",i);
  struct BPNode *node = net->layers[i].first;
  int j = 0;
  while(node) {
   printf("node %d (",j);
   int k;
   for (k = 0; k < node->input_count; ++k) {
    printf("%0.3f",node->input_weights[k]);
    if (k != node->input_count - 1)
     printf(",");
   }
   printf(")\t");
   node = node->next;
   ++j;
  }
  printf("\n");
 }
}

canonical_original_code:
static void print_net_info(struct BPNet *net) {
 if (!net) {
  printf("empty ptr!\n");
  return;
 }
 int i;
 for (i = 0; i < net->layer_count; ++i) {
  printf("level %d\t",i);
  struct BPNode *node = net->layers[i].first;
  int j = 0;
  while(node) {
   printf("node %d (",j);
   int k;
   for (k = 0; k < node->input_count; ++k) {
    printf("%0.3f",node->input_weights[k]);
    if (k != node->input_count - 1)
     printf(",");
   }
   printf(")\t");
   node = node->next;
   ++j;
  }
  printf("\n");
 }
}

variable_types: struct BPNet { struct BPLayer { struct BPNode { float input_weights[10]; int input_count; float threshold; float output; float (*get_output)(struct BPNode); struct BPNode *next; } *first; int node_count; } *layers; int layer_count; } *

user_defined_types: struct BPNet { struct BPLayer *layers; int layer_count; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = bp_net_init(5LL, 3LL, envp);
printf("net inited , count of layer : %d\n", *(unsigned int *)(v4[0] + 8));
print_net_info(v4[0]);
bp_record_save(v4[0], "./record");
sync();
bp_net_destory(v4);
if ( (int)bp_record_load("./record", v4) < 0 )
{
puts("failded when loading");
}
else
{
printf("\nnet reinited , count of layer : %d\n", *(unsigned int *)(v4[0] + 8));
print_net_info(v4[0]);
bp_net_destory(v4);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = bp_net_init(5LL, 3LL, envp);
printf("net inited , count of layer : %d\n", *(unsigned int *)(v4[0] + 8));
func0(v4[0]);
bp_record_save(v4[0], "./record");
sync();
bp_net_destory(v4);
if ( (int)bp_record_load("./record", v4) < 0 )
{
puts("failded when loading");
}
else
{
printf("\nnet reinited , count of layer : %d\n", *(unsigned int *)(v4[0] + 8));
func0(v4[0]);
bp_net_destory(v4);
}
return 0;
}

original_code:
int main() {
 struct BPNet* net = bp_net_init(5,3);
 printf("net inited , count of layer : %d\n",net->layer_count);
 print_net_info(net);
 bp_record_save(net,"./record");
 sync();
 bp_net_destory(&net);
 if (bp_record_load("./record",&net) < 0) {
  printf("failded when loading\n");
  return 0;
 }
 printf("\nnet reinited , count of layer : %d\n",net->layer_count);
 print_net_info(net);
 bp_net_destory(&net);
 return 0;
}

canonical_original_code:
int main() {
 struct BPNet *net = bp_net_init(5,3);
 printf("net inited , count of layer : %d\n",net->layer_count);
 print_net_info(net);
 bp_record_save(net,"./record");
 sync();
 bp_net_destory(&net);
 if (bp_record_load("./record",&net) < 0) {
  printf("failded when loading\n");
  return 0;
 }
 printf("\nnet reinited , count of layer : %d\n",net->layer_count);
 print_net_info(net);
 bp_net_destory(&net);
 return 0;
}


decompiled_code:
__int64 __fastcall bp_record_generate_files_path(char *s, char **a2, char **a3, char **a4)
{
__int64 result; // rax
size_t v7; // rax
size_t v8; // rax
size_t v9; // rax
char *v10; // rax

result = 0LL;
if ( s )
{
v7 = strlen(s);
*a2 = (char *)malloc(v7 + 12);
v8 = strlen(s);
*a3 = (char *)malloc(v8 + 14);
v9 = strlen(s);
v10 = (char *)malloc(v9 + 13);
*a4 = v10;
if ( *a2 )
{
if ( *a3 && v10 )
{
sprintf(*a2, "%s/%s", s, "record.net");
sprintf(*a3, "%s/%s", s, "record.layer");
sprintf(*a4, "%s/%s", s, "record.node");
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, char **a2, char **a3, char **a4)
{
__int64 result; // rax
size_t v7; // rax
size_t v8; // rax
size_t v9; // rax
char *v10; // rax

result = 0LL;
if ( s )
{
v7 = strlen(s);
*a2 = (char *)malloc(v7 + 12);
v8 = strlen(s);
*a3 = (char *)malloc(v8 + 14);
v9 = strlen(s);
v10 = (char *)malloc(v9 + 13);
*a4 = v10;
if ( *a2 )
{
if ( *a3 && v10 )
{
sprintf(*a2, "%s/%s", s, "record.net");
sprintf(*a3, "%s/%s", s, "record.layer");
sprintf(*a4, "%s/%s", s, "record.node");
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
static int bp_record_generate_files_path(const char* dir, char** net, char** layer, char** node) {
 if (!dir)
  return 0;
 *net = (char*)malloc(sizeof(char) * (strlen(dir) + strlen("record.net") + 2));
 *layer = (char*)malloc(sizeof(char) * (strlen(dir) + strlen("record.layer") + 2));
 *node = (char*)malloc(sizeof(char) * (strlen(dir) + strlen("record.node") + 2));
 if (!*net || !*layer || !*node)
  return 0;
 sprintf(*net,"%s/%s\0",dir,"record.net");
 sprintf(*layer,"%s/%s\0",dir,"record.layer");
 sprintf(*node,"%s/%s\0",dir,"record.node");
 return 1;
}

canonical_original_code:
static int bp_record_generate_files_path(char *dir, char **net, char **layer, char **node) {
 if (!dir)
  return 0;
 *net = (char *)malloc(sizeof(char) * (strlen(dir) + strlen("record.net") + 2));
 *layer = (char *)malloc(sizeof(char) * (strlen(dir) + strlen("record.layer") + 2));
 *node = (char *)malloc(sizeof(char) * (strlen(dir) + strlen("record.node") + 2));
 if (!*net || !*layer || !*node)
  return 0;
 sprintf(*net,"%s/%s\0",dir,"record.net");
 sprintf(*layer,"%s/%s\0",dir,"record.layer");
 sprintf(*node,"%s/%s\0",dir,"record.node");
 return 1;
}

variable_types:
dir
char *

variable_types:
net
char **

variable_types:
layer
char **

variable_types:
node
char **


decompiled_code:
_DWORD *bp_net_create()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

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

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

original_code:
struct BPNet* bp_net_create() {
 struct BPNet *net = (struct BPNet*)malloc(sizeof(struct BPNet));
 if (!net)
  return net;
 net->layers = ((void *)0);
 net->layer_count = 0;
 return net;
}

canonical_original_code:
struct BPNet *bp_net_create() {
 struct BPNet *net = (struct BPNet*)malloc(sizeof(struct BPNet));
 if (!net)
  return net;
 net->layers = ((void *)0);
 net->layer_count = 0;
 return net;
}

return_type: struct BPNet { struct BPLayer { struct BPNode { float input_weights[10]; int input_count; float threshold; float output; float (*get_output)(struct BPNode); struct BPNode *next; } *first; int node_count; } *layers; int layer_count; } *


decompiled_code:
_BOOL8 __fastcall bp_net_append_layer(__int64 a1, const __m128i *a2)
{
_BOOL8 result; // rax
__m128i *v3; // rax
__m128i *v4; // rdx
int v5; // eax
int v6; // edx
__int64 v7; // rax
__int64 v8; // rsi
__int64 v9; // rdi

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
*(_DWORD *)(a1 + 8) = 0;
v3 = (__m128i *)realloc(*(void **)a1, 0x10uLL);
v4 = v3;
if ( v3 )
{
*(_QWORD *)a1 = v3;
v5 = *(_DWORD *)(a1 + 8) + 1;
*(_DWORD *)(a1 + 8) = v5;
v4[v5 - 1] = _mm_loadu_si128(a2);
v6 = *(_DWORD *)(a1 + 8);
v7 = 16LL * v6;
v8 = *(_QWORD *)a1 + v7 - 16;
v9 = *(_QWORD *)a1 + v7 - 32;
if ( !v6 )
v9 = 0LL;
result = (unsigned int)bp_layer_connect(v9, v8) != 0;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int bp_net_append_layer(struct BPNet* net, struct BPLayer* layer) {
 if (!net || !layer)
  return 0;
 if (net->layer_count < 0)
  net->layer_count = 0;
 if (net->layer_count = 0) {
  net->layers = (struct BPLayer*)malloc(sizeof(struct BPLayer));
  if (!net->layers)
   return 0;
 } else {
  struct BPLayer* newLayers = (struct BPLayer*)realloc(net->layers,sizeof(struct BPLayer) * (net->layer_count + 1));
  if (!newLayers)
   return 0;
  net->layers = newLayers;
 }
 net->layers[++ net->layer_count - 1] = *layer;
 if (!bp_layer_connect(net->layer_count? &(net->layers[net->layer_count - 2]) : ((void *)0),
  &(net->layers[net->layer_count - 1])))
  return 0;
 return 1;
}

canonical_original_code:
int bp_net_append_layer(struct BPNet *net, struct BPLayer *layer) {
 if (!net || !layer)
  return 0;
 if (net->layer_count < 0)
  net->layer_count = 0;
 if (net->layer_count = 0) {
  net->layers = (struct BPLayer *)malloc(sizeof(struct BPLayer));
  if (!net->layers)
   return 0;
 } else {
  struct BPLayer *newLayers = (struct BPLayer*)realloc(net->layers,sizeof(struct BPLayer) * (net->layer_count + 1));
  if (!newLayers)
   return 0;
  net->layers = newLayers;
 }
 net->layers[++ net->layer_count - 1] = *layer;
 if (!bp_layer_connect(net->layer_count? &(net->layers[net->layer_count - 2]) : ((void *)0),
  &(net->layers[net->layer_count - 1])))
  return 0;
 return 1;
}

variable_types:
layer
struct BPLayer *


decompiled_code:
int __fastcall verify_line(const char *a1, const char *a2)
{
char *v2; // rbx
char *v3; // rax
const char *v4; // rbp
int result; // eax

v2 = strstr(a1, "[OUTPUT]");
v3 = strstr(a2, "[OUTPUT]");
if ( !v2 )
return 1;
v4 = v3;
if ( !v3 )
return 1;
result = strcmp(v2, v3);
if ( result )
{
printf("\x1B[32m%s %s\x1B[0m", "MASTER >>>>>", v2);
printf("\x1B[31m%s %s\n\x1B[0m", "STUDENT >>>>>", v4);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, const char *a2)
{
char *v2; // rbx
char *v3; // rax
const char *v4; // rbp
int result; // eax

v2 = strstr(a1, "[OUTPUT]");
v3 = strstr(a2, "[OUTPUT]");
if ( !v2 )
return 1;
v4 = v3;
if ( !v3 )
return 1;
result = strcmp(v2, v3);
if ( result )
{
printf("\x1B[32m%s %s\x1B[0m", "MASTER >>>>>", v2);
printf("\x1B[31m%s %s\n\x1B[0m", "STUDENT >>>>>", v4);
result = 1;
}
return result;
}

original_code:
int verify_line( char *master, char *student ) {
  char *master_out, *student_out;
  int cmp;
  master_out = strstr(master, "[OUTPUT]");
  student_out = strstr(student, "[OUTPUT]");
  if ( !master_out || !student_out ) {
    return ( 1 );
  }
  cmp = strcmp( master_out, student_out );
  if ( cmp ) {
    printf( "\x1b[32m" "%s %s" "\x1b[0m",
        "MASTER  >>>>>", master_out );
    printf( "\x1b[31m" "%s %s\n" "\x1b[0m",
        "STUDENT >>>>>", student_out );
    return ( 1 );
  }
  return ( 0 );
}

canonical_original_code:
int verify_line(char *master, char *student) {
  char *master_out; char *student_out;
  int cmp;
  master_out = strstr(master, "[OUTPUT]");
  student_out = strstr(student, "[OUTPUT]");
  if ( !master_out || !student_out ) {
    return ( 1 );
  }
  cmp = strcmp( master_out, student_out );
  if ( cmp ) {
    printf( "\x1b[32m" "%s %s" "\x1b[0m",
        "MASTER  >>>>>", master_out );
    printf( "\x1b[31m" "%s %s\n" "\x1b[0m",
        "STUDENT >>>>>", student_out );
    return ( 1 );
  }
  return ( 0 );
}

variable_types:
master
char *

variable_types:
student
char *

variable_types: cmp int


repo: rajamony/denali

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
double v5; // xmm0_8
struct timeval v7; // [rsp+0h] [rbp-28h] BYREF

v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
gettimeofday(&v7, 0LL);
v5 = (double)SLODWORD(v7.tv_usec) / 1000000.0 * (double)(v4 - v3) + (double)v3;
if ( v5 < 0.0 )
{
v5 = 0.0;
}
else if ( v5 > 60.0 )
{
v5 = 60.0;
}
printf("Sleeping for %u micro-seconds\n", (unsigned int)(int)(v5 * 1000000.0));
usleep((int)(v5 * 1000000.0));
return 0;
}

original_code:
int main (int argc, char *argv[]) {
    struct timeval tp;
    int min = atoi (argv[1]);
    int max = atoi (argv[2]);
    gettimeofday (&tp, ((void *)0));
    double fraction = ((double) tp.tv_usec)/1e6;
    double howlong = min + fraction * (double) (max - min);
    if (howlong < 0)
        howlong = 0;
    if (howlong > 60)
 howlong = 60;
    useconds_t us = (useconds_t) (howlong * 1e6);
    printf ("Sleeping for %u micro-seconds\n", us);
    usleep (us);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct timeval tp;
    int min = atoi (argv[1]);
    int max = atoi (argv[2]);
    gettimeofday (&tp, ((void *)0));
    double fraction = ((double) tp.tv_usec)/1e6;
    double howlong = min + fraction * (double) (max - min);
    if (howlong < 0)
        howlong = 0;
    if (howlong > 60)
 howlong = 60;
    unsigned int us = (useconds_t) (howlong * 1e6);
    printf ("Sleeping for %u micro-seconds\n", us);
    usleep (us);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types: min int

variable_types: max int

variable_types: fraction double

variable_types: howlong double

variable_types:
us
unsigned int


zeta

repo: rajatthomas/Mass-Function

original_code:
double zeta(double mass, double flux){
  double answer = 1+70*pow((1+redshift)/21, -5.) * pow(mass/1e6, -0.33333) * (flux/3e7);
  return pow(answer,-1.0/3.0);
}

variable_types: mass double

variable_types: flux double

variable_types: answer double

return_type: double


momentfunc

decompiled_code:
double __fastcall momentfunc(double a1)
{
double v1; // rbx
double v2; // r14
double v4; // [rsp+8h] [rbp-20h]

v1 = exp(a1);
v2 = zeta(v1, 30000000.0);
v4 = pow(v1, 0.6666) * v2;
return MassFunc(v1, redshift) * v1 * v4;
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
double v1; // rbx
double v2; // r14
double v4; // [rsp+8h] [rbp-20h]

v1 = exp(a1);
v2 = func0(v1, 30000000.0);
v4 = pow(v1, 0.6666) * v2;
return MassFunc(v1, redshift) * v1 * v4;
}

original_code:
double momentfunc(double mass, void * params){
  mass = exp(mass);
double integrand;
 integrand = zeta(mass,3e7) * pow(mass, .6666);
integrand *= MassFunc(mass,redshift) * mass;
return integrand;
}

canonical_original_code:
double momentfunc(double mass, void *params){
  mass = exp(mass);
double integrand;
 integrand = zeta(mass,3e7) * pow(mass, .6666);
integrand *= MassFunc(mass,redshift) * mass;
return integrand;
}

variable_types:
params
void *

variable_types: integrand double


crash

decompiled_code:
void __fastcall __noreturn crash(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

original_code:
void crash(char *s)
{
    fprintf(stderr,"%s\n", s); exit(1); return;
}

variable_types:
s
char *


warn

decompiled_code:
int __fastcall warn(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
void warn(char *s)
{
    fprintf(stderr,"%s\n", s); return;
}


checking

decompiled_code:
__int64 checking()
{
scale = LC1;
qtensors = 0;
quiet = 0;
qredshift = 0;
if ( Omega_Matter <= 0.0 )
crash("Omega must be positive.");
if ( h_z0 <= 0.0 )
crash("Hubble constant must be positive.");
if ( h_z0 > 10.0 )
warn("Did you get the Hubble units right?");
if ( degen_Neutrino < 0 )
{
warn("Negative number of degenerate species reset to 1.");
degen_Neutrino = 1;
}
if ( redshift <= -1.0 )
crash("Redshift must exceed -1.");
if ( Omega_Baryon < 0.0 )
Omega_Baryon = COERCE_DOUBLE(Omega_Baryon ^ LC9) * Omega_Matter;
if ( Omega_Neutrino < 0.0 )
Omega_Neutrino = COERCE_DOUBLE(Omega_Neutrino ^ LC9) * Omega_Matter;
if ( -2538.0 == Omega_Lambda )
Omega_Lambda = 1.0 - Omega_Matter;
if ( Omega_Baryon + Omega_Neutrino > Omega_Matter )
crash("Baryons + Neutrinos exceeds Omega_0.");
if ( Omega_Baryon + Omega_Neutrino > Omega_Matter * 0.6 )
warn("CDM fraction is below range of TF fitting formula.");
if ( tilt > 1.3 || tilt < 0.7 )
warn("Tilt out of range of Bunn and White fitting formula.");
if ( 1.0 == tilt
|| (Omega_Matter < 0.2 || Omega_Matter > 1.0)
&& (warn("Omega out of range of Bunn and White fitting formula."), 1.0 == tilt) )
{
if ( Omega_Matter >= 0.2 && Omega_Matter <= 1.6 && Omega_Lambda >= 0.0 && Omega_Lambda <= 0.8 )
{
if ( !qtensors )
goto LABEL_30;
goto LABEL_28;
}
warn("Omega or Lambda out of range of Bunn and White fitting formula.");
}
if ( !qtensors )
goto LABEL_30;
if ( tilt > 1.0 )
LABEL_49:
crash("Tensor formulae only hold for tilts < 1 and simple cosmologies.");
LABEL_28:
if ( COERCE_DOUBLE(*(_QWORD *)&Omega_Lambda & LC23) > 0.00001
&& COERCE_DOUBLE(COERCE_UNSIGNED_INT64(1.0 - Omega_Matter - Omega_Lambda) & LC23) > 0.00001 )
{
goto LABEL_49;
}
LABEL_30:
if ( Omega_Baryon / Omega_Matter > 0.4 )
warn("Baryon oscillations will be large. TF fitting form will be inaccurate.");
if ( Omega_Neutrino / Omega_Matter > 0.4 )
warn("Neutrino fraction outside of range of TF fitting form.");
if ( h_z0 * Omega_Matter * h_z0 > 0.4 )
warn("Omega_0 h^2 outside of range of TF fitting form.");
if ( h_z0 * Omega_Matter * h_z0 < 0.06 )
warn("Omega_0 h^2 outside of range of TF fitting form.");
if ( redshift > 29.0 )
warn("Redshift is higher than range of TF fitting form.");
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
scale = LC1;
qtensors = 0;
quiet = 0;
qredshift = 0;
if ( Omega_Matter <= 0.0 )
func0("Omega must be positive.");
if ( h_z0 <= 0.0 )
func0("Hubble constant must be positive.");
if ( h_z0 > 10.0 )
func1("Did you get the Hubble units right?");
if ( degen_Neutrino < 0 )
{
func1("Negative number of degenerate species reset to 1.");
degen_Neutrino = 1;
}
if ( redshift <= -1.0 )
func0("Redshift must exceed -1.");
if ( Omega_Baryon < 0.0 )
Omega_Baryon = COERCE_DOUBLE(Omega_Baryon ^ LC9) * Omega_Matter;
if ( Omega_Neutrino < 0.0 )
Omega_Neutrino = COERCE_DOUBLE(Omega_Neutrino ^ LC9) * Omega_Matter;
if ( -2538.0 == Omega_Lambda )
Omega_Lambda = 1.0 - Omega_Matter;
if ( Omega_Baryon + Omega_Neutrino > Omega_Matter )
func0("Baryons + Neutrinos exceeds Omega_0.");
if ( Omega_Baryon + Omega_Neutrino > Omega_Matter * 0.6 )
func1("CDM fraction is below range of TF fitting formula.");
if ( tilt > 1.3 || tilt < 0.7 )
func1("Tilt out of range of Bunn and White fitting formula.");
if ( 1.0 == tilt
|| (Omega_Matter < 0.2 || Omega_Matter > 1.0)
&& (func1("Omega out of range of Bunn and White fitting formula."), 1.0 == tilt) )
{
if ( Omega_Matter >= 0.2 && Omega_Matter <= 1.6 && Omega_Lambda >= 0.0 && Omega_Lambda <= 0.8 )
{
if ( !qtensors )
goto LABEL_30;
goto LABEL_28;
}
func1("Omega or Lambda out of range of Bunn and White fitting formula.");
}
if ( !qtensors )
goto LABEL_30;
if ( tilt > 1.0 )
LABEL_49:
func0("Tensor formulae only hold for tilts < 1 and simple cosmologies.");
LABEL_28:
if ( COERCE_DOUBLE(*(_QWORD *)&Omega_Lambda & LC23) > 0.00001
&& COERCE_DOUBLE(COERCE_UNSIGNED_INT64(1.0 - Omega_Matter - Omega_Lambda) & LC23) > 0.00001 )
{
goto LABEL_49;
}
LABEL_30:
if ( Omega_Baryon / Omega_Matter > 0.4 )
func1("Baryon oscillations will be large. TF fitting form will be inaccurate.");
if ( Omega_Neutrino / Omega_Matter > 0.4 )
func1("Neutrino fraction outside of range of TF fitting form.");
if ( h_z0 * Omega_Matter * h_z0 > 0.4 )
func1("Omega_0 h^2 outside of range of TF fitting form.");
if ( h_z0 * Omega_Matter * h_z0 < 0.06 )
func1("Omega_0 h^2 outside of range of TF fitting form.");
if ( redshift > 29.0 )
func1("Redshift is higher than range of TF fitting form.");
return 1LL;
}

original_code:
int checking()
{
    scale = -1.0;
    qtensors = 0;
    quiet = 0;
    qredshift = 0;
    if (Omega_Matter<=0.0) crash("Omega must be positive.");
    if (h_z0<=0.0) crash("Hubble constant must be positive.");
 else if (h_z0>10.0) warn("Did you get the Hubble units right?");
    if (degen_Neutrino<0) {
 warn("Negative number of degenerate species reset to 1.");
 degen_Neutrino = 1.0;
    }
    if (redshift<=-1.0) crash("Redshift must exceed -1.");
    if (Omega_Baryon<0.0) Omega_Baryon = Omega_Matter*(-Omega_Baryon);
    if (Omega_Neutrino<0.0) Omega_Neutrino = Omega_Matter*(-Omega_Neutrino);
    if (Omega_Lambda== -2538) Omega_Lambda = 1-Omega_Matter;
    if (Omega_Baryon+Omega_Neutrino>Omega_Matter) crash("Baryons + Neutrinos exceeds Omega_0.");
 else if (Omega_Baryon+Omega_Neutrino>0.6*Omega_Matter)
     warn("CDM fraction is below range of TF fitting formula.");
    if (tilt>1.3 || tilt < 0.7)
 warn("Tilt out of range of Bunn and White fitting formula.");
    if (tilt!=1 && (Omega_Matter<0.2 || Omega_Matter>1.0))
 warn("Omega out of range of Bunn and White fitting formula.");
    if (tilt==1 && (Omega_Matter<0.2 || Omega_Matter>1.6 || Omega_Lambda<0.0 || Omega_Lambda>0.8))
 warn("Omega or Lambda out of range of Bunn and White fitting formula.");
    if (qtensors!=0&&(tilt>1.0||
 (fabs(Omega_Lambda)>1e-5&&fabs(1.0-Omega_Matter-Omega_Lambda)>1e-5)))
 crash("Tensor formulae only hold for tilts < 1 and simple cosmologies.");
    if (Omega_Baryon/Omega_Matter>0.4) warn("Baryon oscillations will be large.  TF fitting form will be inaccurate.");
    if (Omega_Neutrino/Omega_Matter>0.4) warn("Neutrino fraction outside of range of TF fitting form.");
    if (Omega_Matter*h_z0*h_z0>0.4) warn("Omega_0 h^2 outside of range of TF fitting form.");
    if (Omega_Matter*h_z0*h_z0<0.06) warn("Omega_0 h^2 outside of range of TF fitting form.");
    if (redshift>29) warn("Redshift is higher than range of TF fitting form.");
    return 1;
}


decompiled_code:
double __fastcall W2tophat(double a1)
{
double v1; // xmm0_8
double cosx; // [rsp+10h] [rbp-18h] BYREF
double sinx[2]; // [rsp+18h] [rbp-10h] BYREF

if ( a1 >= 0.03 )
{
sincos(a1, sinx, &cosx);
v1 = (cosx - sinx[0] / a1) / a1 / a1;
}
else
{
v1 = 0.3333333333333333 - a1 * a1 / 30.0;
}
return v1 * (v1 * 9.0);
}

canonical_decompiled_code:
double __fastcall func3(double a1)
{
double v1; // xmm0_8
double cosx; // [rsp+10h] [rbp-18h] BYREF
double sinx[2]; // [rsp+18h] [rbp-10h] BYREF

if ( a1 >= 0.03 )
{
sincos(a1, sinx, &cosx);
v1 = (cosx - sinx[0] / a1) / a1 / a1;
}
else
{
v1 = 0.3333333333333333 - a1 * a1 / 30.0;
}
return v1 * (v1 * 9.0);
}

original_code:
double W2tophat(double x)
{
    double j1onx;
    if (x<0.03)
 j1onx = (1.0/3.0-x*x*1.0/30.0);
    else j1onx = (cos(x)-sin(x)/x)/x/x;
    return 9.0*j1onx*j1onx;
}

variable_types: x double


powerspcbnu

decompiled_code:
double __fastcall powerspcbnu(double a1)
{
double v2; // r14
double v3; // xmm0_8
double v5; // [rsp+8h] [rbp-20h]

v2 = pow(a1 * 2997.0, tilt + 3.0);
if ( TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0 == 0.0 )
{
v3 = 0.0;
}
else
{
v5 = TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0;
v3 = TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0 * v5;
}
return v3 * v2;
}

canonical_decompiled_code:
double __fastcall func4(double a1)
{
double v2; // r14
double v3; // xmm0_8
double v5; // [rsp+8h] [rbp-20h]

v2 = pow(a1 * 2997.0, tilt + 3.0);
if ( TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0 == 0.0 )
{
v3 = 0.0;
}
else
{
v5 = TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0;
v3 = TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0 * v5;
}
return v3 * v2;
}

original_code:
double powerspcbnu(double k)
{
    return pow(2997.0*k, tilt+3.0)*(((deltaH*TransferFuncCDM_EH(k)*growth_to_z0)) == 0.0 ? 0.0 : (deltaH*TransferFuncCDM_EH(k)*growth_to_z0)*(deltaH*TransferFuncCDM_EH(k)*growth_to_z0));
}

variable_types: k double


decompiled_code:
double __fastcall sig2tophatnu(double a1)
{
double v1; // rbx
double v2; // rbx
double v5; // [rsp+10h] [rbp-18h]

v1 = powerspcbnu(a1 / *(double *)&sig2_scale);
v5 = W2tophat(a1) * v1;
v2 = powerspcbnu(1.0 / a1 / *(double *)&sig2_scale);
return (W2tophat(1.0 / a1) * v2 + v5) / a1;
}

canonical_decompiled_code:
double __fastcall func5(double a1)
{
double v1; // rbx
double v2; // rbx
double v5; // [rsp+10h] [rbp-18h]

v1 = func4(a1 / *(double *)&sig2_scale);
v5 = func3(a1) * v1;
v2 = func4(1.0 / a1 / *(double *)&sig2_scale);
return (func3(1.0 / a1) * v2 + v5) / a1;
}

original_code:
double sig2tophatnu(double x, void * params)
{
    double powerspcbnu(double k);
    return (powerspcbnu(x/sig2_scale)*W2tophat(x)+
      powerspcbnu(1.0/x/sig2_scale)*W2tophat(1.0/x))/x;
}

canonical_original_code:
double sig2tophatnu(double x, void *params)
{
    double powerspcbnu(double k);
    return (powerspcbnu(x/sig2_scale)*W2tophat(x)+
      powerspcbnu(1.0/x/sig2_scale)*W2tophat(1.0/x))/x;
}

variable_types:
powerspcbnu
double (double k)


decompiled_code:
double __fastcall sig2gaussnu(double a1)
{
double v1; // rbx
double v2; // rbx
double v5; // [rsp+8h] [rbp-10h]

v1 = powerspcbnu(a1 / *(double *)&sig2_scale);
v5 = exp(COERCE_DOUBLE(*(_QWORD *)&a1 ^ LC9) * a1) * v1;
v2 = powerspcbnu(1.0 / a1 / *(double *)&sig2_scale);
return (exp(-1.0 / a1 / a1) * v2 + v5) / a1;
}

canonical_decompiled_code:
double __fastcall func6(double a1)
{
double v1; // rbx
double v2; // rbx
double v5; // [rsp+8h] [rbp-10h]

v1 = func4(a1 / *(double *)&sig2_scale);
v5 = exp(COERCE_DOUBLE(*(_QWORD *)&a1 ^ LC9) * a1) * v1;
v2 = func4(1.0 / a1 / *(double *)&sig2_scale);
return (exp(-1.0 / a1 / a1) * v2 + v5) / a1;
}

original_code:
double sig2gaussnu(double x, void * params)
{
    double powerspcbnu(double k);
    return (powerspcbnu(x/sig2_scale)*exp(-x*x)+
      powerspcbnu(1.0/x/sig2_scale)*exp(-1.0/x/x))/x;
}

canonical_original_code:
double sig2gaussnu(double x, void *params)
{
    double powerspcbnu(double k);
    return (powerspcbnu(x/sig2_scale)*exp(-x*x)+
      powerspcbnu(1.0/x/sig2_scale)*exp(-1.0/x/x))/x;
}


decompiled_code:
double __fastcall sig2sharpknu(double a1)
{
return powerspcbnu(a1 / *(double *)&sig2_scale) / a1;
}

canonical_decompiled_code:
double __fastcall func7(double a1)
{
return func4(a1 / *(double *)&sig2_scale) / a1;
}

original_code:
double sig2sharpknu(double x, void * params)
{
    double powerspcbnu(double k);
    return (powerspcbnu(x/sig2_scale))/x;
}

canonical_original_code:
double sig2sharpknu(double x, void *params)
{
    double powerspcbnu(double k);
    return (powerspcbnu(x/sig2_scale))/x;
}


powerspcb

decompiled_code:
double __fastcall powerspcb(double a1)
{
double v2; // r14
double v3; // xmm0_8
double v5; // [rsp+8h] [rbp-20h]

v2 = pow(a1 * 2997.0, tilt + 3.0);
if ( TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0 == 0.0 )
{
v3 = 0.0;
}
else
{
v5 = TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0;
v3 = TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0 * v5;
}
return v3 * v2;
}

canonical_decompiled_code:
double __fastcall func8(double a1)
{
double v2; // r14
double v3; // xmm0_8
double v5; // [rsp+8h] [rbp-20h]

v2 = pow(a1 * 2997.0, tilt + 3.0);
if ( TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0 == 0.0 )
{
v3 = 0.0;
}
else
{
v5 = TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0;
v3 = TransferFuncCDM_EH(a1) * *(double *)&deltaH * growth_to_z0 * v5;
}
return v3 * v2;
}

original_code:
double powerspcb(double k)
{
    return pow(2997.0*k, tilt+3.0)*(((deltaH*TransferFuncCDM_EH(k)*growth_to_z0)) == 0.0 ? 0.0 : (deltaH*TransferFuncCDM_EH(k)*growth_to_z0)*(deltaH*TransferFuncCDM_EH(k)*growth_to_z0));
}


decompiled_code:
double __fastcall sig2tophat(double a1)
{
double v1; // rbx
double v2; // rbx
double v5; // [rsp+10h] [rbp-18h]

v1 = powerspcb(a1 / *(double *)&sig2_scale);
v5 = W2tophat(a1) * v1;
v2 = powerspcb(1.0 / a1 / *(double *)&sig2_scale);
return (W2tophat(1.0 / a1) * v2 + v5) / a1;
}

canonical_decompiled_code:
double __fastcall func9(double a1)
{
double v1; // rbx
double v2; // rbx
double v5; // [rsp+10h] [rbp-18h]

v1 = func8(a1 / *(double *)&sig2_scale);
v5 = func3(a1) * v1;
v2 = func8(1.0 / a1 / *(double *)&sig2_scale);
return (func3(1.0 / a1) * v2 + v5) / a1;
}

original_code:
double sig2tophat(double x, void * params)
{
    double powerspcb(double k);
    return (powerspcb(x/sig2_scale)*W2tophat(x)+
      powerspcb(1.0/x/sig2_scale)*W2tophat(1.0/x))/x;
}

canonical_original_code:
double sig2tophat(double x, void *params)
{
    double powerspcb(double k);
    return (powerspcb(x/sig2_scale)*W2tophat(x)+
      powerspcb(1.0/x/sig2_scale)*W2tophat(1.0/x))/x;
}

variable_types:
powerspcb
double (double k)


decompiled_code:
double __fastcall sig2gauss(double a1)
{
double v1; // rbx
double v2; // rbx
double v5; // [rsp+8h] [rbp-10h]

v1 = powerspcb(a1 / *(double *)&sig2_scale);
v5 = exp(COERCE_DOUBLE(*(_QWORD *)&a1 ^ LC9) * a1) * v1;
v2 = powerspcb(1.0 / a1 / *(double *)&sig2_scale);
return (exp(-1.0 / a1 / a1) * v2 + v5) / a1;
}

canonical_decompiled_code:
double __fastcall func10(double a1)
{
double v1; // rbx
double v2; // rbx
double v5; // [rsp+8h] [rbp-10h]

v1 = func8(a1 / *(double *)&sig2_scale);
v5 = exp(COERCE_DOUBLE(*(_QWORD *)&a1 ^ LC9) * a1) * v1;
v2 = func8(1.0 / a1 / *(double *)&sig2_scale);
return (exp(-1.0 / a1 / a1) * v2 + v5) / a1;
}

original_code:
double sig2gauss(double x, void * params)
{
    double powerspcb(double k);
    return (powerspcb(x/sig2_scale)*exp(-x*x)+
      powerspcb(1.0/x/sig2_scale)*exp(-1.0/x/x))/x;
}

canonical_original_code:
double sig2gauss(double x, void *params)
{
    double powerspcb(double k);
    return (powerspcb(x/sig2_scale)*exp(-x*x)+
      powerspcb(1.0/x/sig2_scale)*exp(-1.0/x/x))/x;
}


decompiled_code:
double __fastcall sig2sharpk(double a1)
{
return powerspcb(a1 / *(double *)&sig2_scale) / a1;
}

canonical_decompiled_code:
double __fastcall func11(double a1)
{
return func8(a1 / *(double *)&sig2_scale) / a1;
}

original_code:
double sig2sharpk(double x, void * params)
{
    double powerspcb(double k);
    return (powerspcb(x/sig2_scale))/x;
}

canonical_original_code:
double sig2sharpk(double x, void *params)
{
    double powerspcb(double k);
    return (powerspcb(x/sig2_scale))/x;
}


cobenorm

decompiled_code:
double cobenorm()
{
double v0; // xmm0_8
double v1; // rbx
double v2; // xmm1_8
double result; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // rbx
double v7; // xmm1_8
double v8; // xmm0_8
double v9; // r12
double v10; // rbp
double v11; // rbx
double v12; // rbx
double v13; // rbp
double v14; // xmm3_8
double v15; // xmm1_8
double v16; // [rsp+8h] [rbp-20h]
double v17; // [rsp+8h] [rbp-20h]

v16 = tilt - 1.0;
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(Omega_Matter + Omega_Lambda - 1.0) & LC23) >= 0.00001 )
{
if ( COERCE_DOUBLE(*(_QWORD *)&Omega_Lambda & LC23) >= 0.00001 )
{
v9 = exp(Omega_Matter);
v10 = exp(Omega_Lambda);
v11 = Omega_Matter;
v17 = 2.422 - v9 * 1.166 + v10 * 0.8 + v11 * 3.78 - v11 * 2.267 * exp(Omega_Lambda);
v12 = *(double *)&LC2;
if ( Omega_Matter != 0.0 )
v12 = Omega_Matter * Omega_Matter;
v13 = Omega_Lambda;
v14 = exp(Omega_Matter);
if ( Omega_Lambda == 0.0 )
v15 = 0.0;
else
v15 = Omega_Lambda * Omega_Lambda;
result = (v12 * 0.487
+ v17
+ v13 * 0.5610000000000001
+ v13 * 3.329 * v14
- 8.568 * Omega_Matter * Omega_Lambda
+ v15 * 1.08)
* 0.00001;
}
else
{
if ( qtensors )
{
v5 = log(Omega_Matter);
v6 = pow(Omega_Matter, -0.35 - v5 * 0.19 - v16 * 0.15);
v7 = exp(v16 * 1.7 * v16 + v16 * 1.02);
}
else
{
v8 = log(Omega_Matter);
v6 = pow(Omega_Matter, -0.35 - v8 * 0.19 - v16 * 0.17);
v7 = exp(COERCE_DOUBLE(*(_QWORD *)&v16 ^ LC9) - v16 * 0.14 * v16);
}
result = v6 * 0.0000195 * v7;
}
}
else
{
if ( qtensors )
{
v0 = log(Omega_Matter);
v1 = pow(Omega_Matter, -0.785 - v0 * 0.05);
v2 = exp(v16 * 1.97 * v16 + v16);
}
else
{
v4 = log(Omega_Matter);
v1 = pow(Omega_Matter, -0.785 - v4 * 0.05);
v2 = exp(v16 * -0.95 - v16 * 0.169 * v16);
}
result = v1 * 0.0000194 * v2;
}
return result;
}

canonical_decompiled_code:
double func12()
{
double v0; // xmm0_8
double v1; // rbx
double v2; // xmm1_8
double result; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // rbx
double v7; // xmm1_8
double v8; // xmm0_8
double v9; // r12
double v10; // rbp
double v11; // rbx
double v12; // rbx
double v13; // rbp
double v14; // xmm3_8
double v15; // xmm1_8
double v16; // [rsp+8h] [rbp-20h]
double v17; // [rsp+8h] [rbp-20h]

v16 = tilt - 1.0;
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(Omega_Matter + Omega_Lambda - 1.0) & LC23) >= 0.00001 )
{
if ( COERCE_DOUBLE(*(_QWORD *)&Omega_Lambda & LC23) >= 0.00001 )
{
v9 = exp(Omega_Matter);
v10 = exp(Omega_Lambda);
v11 = Omega_Matter;
v17 = 2.422 - v9 * 1.166 + v10 * 0.8 + v11 * 3.78 - v11 * 2.267 * exp(Omega_Lambda);
v12 = *(double *)&LC2;
if ( Omega_Matter != 0.0 )
v12 = Omega_Matter * Omega_Matter;
v13 = Omega_Lambda;
v14 = exp(Omega_Matter);
if ( Omega_Lambda == 0.0 )
v15 = 0.0;
else
v15 = Omega_Lambda * Omega_Lambda;
result = (v12 * 0.487
+ v17
+ v13 * 0.5610000000000001
+ v13 * 3.329 * v14
- 8.568 * Omega_Matter * Omega_Lambda
+ v15 * 1.08)
* 0.00001;
}
else
{
if ( qtensors )
{
v5 = log(Omega_Matter);
v6 = pow(Omega_Matter, -0.35 - v5 * 0.19 - v16 * 0.15);
v7 = exp(v16 * 1.7 * v16 + v16 * 1.02);
}
else
{
v8 = log(Omega_Matter);
v6 = pow(Omega_Matter, -0.35 - v8 * 0.19 - v16 * 0.17);
v7 = exp(COERCE_DOUBLE(*(_QWORD *)&v16 ^ LC9) - v16 * 0.14 * v16);
}
result = v6 * 0.0000195 * v7;
}
}
else
{
if ( qtensors )
{
v0 = log(Omega_Matter);
v1 = pow(Omega_Matter, -0.785 - v0 * 0.05);
v2 = exp(v16 * 1.97 * v16 + v16);
}
else
{
v4 = log(Omega_Matter);
v1 = pow(Omega_Matter, -0.785 - v4 * 0.05);
v2 = exp(v16 * -0.95 - v16 * 0.169 * v16);
}
result = v1 * 0.0000194 * v2;
}
return result;
}

original_code:
double cobenorm()
{
    double n;
    n = tilt-1;
    if (fabs(Omega_Matter+Omega_Lambda-1.0)<1e-5) {
 if (qtensors)
     return 1.94e-5*pow(Omega_Matter, -0.785-0.05*log(Omega_Matter))*
  exp(n+1.97*n*n);
 else return 1.94e-5*pow(Omega_Matter, -0.785-0.05*log(Omega_Matter))*
  exp(-0.95*n-0.169*n*n);
    } else if (fabs(Omega_Lambda)<1e-5) {
 if (qtensors)
     return 1.95e-5*pow(Omega_Matter,-0.35-0.19*log(Omega_Matter)-0.15*n)*
  exp(+1.02*n+1.7*n*n);
 else return 1.95e-5*pow(Omega_Matter, -0.35-0.19*log(Omega_Matter)-0.17*n)*
  exp(-n-0.14*n*n);
    } else return 1e-5*(2.422-1.166*exp(Omega_Matter)+0.800*exp(Omega_Lambda)
 +3.780*Omega_Matter-2.267*Omega_Matter*exp(Omega_Lambda)+0.487*(((Omega_Matter)) == 0.0 ? 0.0 : (Omega_Matter)*(Omega_Matter))+
 0.561*Omega_Lambda+3.329*Omega_Lambda*exp(Omega_Matter)-8.568*Omega_Matter*Omega_Lambda+
 1.080*(((Omega_Lambda)) == 0.0 ? 0.0 : (Omega_Lambda)*(Omega_Lambda)));
}

variable_types: n double


Sigma

decompiled_code:
double __fastcall Sigma(double a1)
{
__int64 v2; // rbx
double v3; // rbp
double (__fastcall *v5[2])(double); // [rsp+0h] [rbp-38h] BYREF
double x; // [rsp+10h] [rbp-28h] BYREF
char v7[32]; // [rsp+18h] [rbp-20h] BYREF

v2 = gsl_integration_workspace_alloc(2000LL);
checking();
if ( (unsigned int)TransferFunc_Init(redshift) )
puts("Some warnings in Init");
deltaH = cobenorm();
quiet = 1;
if ( *(double *)&scale > 0.0 || a1 > 0.0 )
{
if ( a1 >= 0.0 && *(double *)&scale < 0.0 )
scale = pow(8.587496929418813e-13 / Omega_Matter * a1, 0.3333333333333333);
sig2_scale = scale;
if ( !strcmp((const char *)&SigmaFilter, "top-hat") )
v5[0] = sig2tophat;
if ( !strcmp((const char *)&SigmaFilter, "gaussian") )
v5[0] = sig2gauss;
if ( !strcmp((const char *)&SigmaFilter, "sharp-k") )
v5[0] = sig2sharpk;
gsl_integration_qags(v5, 2000LL, v2, &x, v7, 0.0, 1.0, 0.0, 0.00000001489999);
if ( x < 0.0 )
v3 = sqrt(x);
else
v3 = sqrt(x);
}
else
{
v3 = *(double *)&LC2;
}
gsl_integration_workspace_free(v2);
return v3;
}

canonical_decompiled_code:
double __fastcall func13(double a1)
{
__int64 v2; // rbx
double v3; // rbp
double (__fastcall *v5[2])(double); // [rsp+0h] [rbp-38h] BYREF
double x; // [rsp+10h] [rbp-28h] BYREF
char v7[32]; // [rsp+18h] [rbp-20h] BYREF

v2 = gsl_integration_workspace_alloc(2000LL);
func2();
if ( (unsigned int)TransferFunc_Init(redshift) )
puts("Some warnings in Init");
deltaH = func12();
quiet = 1;
if ( *(double *)&scale > 0.0 || a1 > 0.0 )
{
if ( a1 >= 0.0 && *(double *)&scale < 0.0 )
scale = pow(8.587496929418813e-13 / Omega_Matter * a1, 0.3333333333333333);
sig2_scale = scale;
if ( !strcmp((const char *)&SigmaFilter, "top-hat") )
v5[0] = sig2tophat;
if ( !strcmp((const char *)&SigmaFilter, "gaussian") )
v5[0] = sig2gauss;
if ( !strcmp((const char *)&SigmaFilter, "sharp-k") )
v5[0] = sig2sharpk;
gsl_integration_qags(v5, 2000LL, v2, &x, v7, 0.0, 1.0, 0.0, 0.00000001489999);
if ( x < 0.0 )
v3 = sqrt(x);
else
v3 = sqrt(x);
}
else
{
v3 = *(double *)&LC2;
}
gsl_integration_workspace_free(v2);
return v3;
}

original_code:
double Sigma(double mass)
{
    double sigma = 0.0;
    double cobenorm();
    double epsabs=0.0, abserr, epsrel=1.489999e-08,sig2;
    int nbins = 2000;
 gsl_integration_workspace *w = gsl_integration_workspace_alloc (nbins);
    gsl_function F;
    checking();
  if(TransferFunc_Init(redshift)) printf("Some warnings in Init\n");
  deltaH = cobenorm();
quiet=1;
    if (!quiet) {
 printf("Omega_0  = %5.3f, Omega_baryon = %5.3f, Omega_neutrino = %5.3f\n",
  Omega_Matter, Omega_Baryon, Omega_Neutrino);
 printf("Hubble   = %5.3f, Lambda       = %5.3f, N_neutrinos    = %d\n",
  h_z0, Omega_Lambda, (int) degen_Neutrino);
 printf("Redshift = %5.3f, Growth = %6.4f relative to z=0\n",
  redshift, growth_to_z0);
 printf("Tilt     = %5.3f, COBE normalization: deltaH = %8.3e",
  tilt, deltaH);
 if (tilt!=1.0)
     if (qtensors) printf(" with tensors.\n");
     else printf(" without tensors.\n");
 else printf("\n");
    }
   if (scale>0 || mass>0) {
 if (mass<0)
     mass = 4.0*3.14159265358979323846/3.0*Omega_Matter*2.78e11*scale*scale*scale;
 else if (scale<0)
     scale = pow(3.0/4.0/3.14159265358979323846/2.78e11/Omega_Matter*mass, 1.0/3.0);
 sig2_scale = scale;
        if(strcmp(SigmaFilter,"top-hat")==0)
         F.function = &sig2tophat;
 if(strcmp(SigmaFilter,"gaussian")==0)
  F.function = &sig2gauss;
        if(strcmp(SigmaFilter,"sharp-k")==0)
         F.function = &sig2sharpk;
  gsl_integration_qags(&F,0.0,1.0,epsabs,epsrel,nbins,w,&sig2,&abserr);
 sigma = sqrt(sig2);
    }
 gsl_integration_workspace_free (w);
  return sigma;
}

canonical_original_code:
double Sigma(double mass)
{
    double sigma = 0.0;
    double cobenorm();
    double epsabs = 0.0; double abserr; double epsrel = 1.489999e-08; double sig2;
    int nbins = 2000;
 struct gsl_integration_workspace *w = gsl_integration_workspace_alloc (nbins);
    struct gsl_function_struct F;
    checking();
  if(TransferFunc_Init(redshift)) printf("Some warnings in Init\n");
  deltaH = cobenorm();
quiet=1;
    if (!quiet) {
 printf("Omega_0  = %5.3f, Omega_baryon = %5.3f, Omega_neutrino = %5.3f\n",
  Omega_Matter, Omega_Baryon, Omega_Neutrino);
 printf("Hubble   = %5.3f, Lambda       = %5.3f, N_neutrinos    = %d\n",
  h_z0, Omega_Lambda, (int) degen_Neutrino);
 printf("Redshift = %5.3f, Growth = %6.4f relative to z=0\n",
  redshift, growth_to_z0);
 printf("Tilt     = %5.3f, COBE normalization: deltaH = %8.3e",
  tilt, deltaH);
 if (tilt!=1.0)
     if (qtensors) printf(" with tensors.\n");
     else printf(" without tensors.\n");
 else printf("\n");
    }
   if (scale>0 || mass>0) {
 if (mass<0)
     mass = 4.0*3.14159265358979323846/3.0*Omega_Matter*2.78e11*scale*scale*scale;
 else if (scale<0)
     scale = pow(3.0/4.0/3.14159265358979323846/2.78e11/Omega_Matter*mass, 1.0/3.0);
 sig2_scale = scale;
        if(strcmp(SigmaFilter,"top-hat")==0)
         F.function = &sig2tophat;
 if(strcmp(SigmaFilter,"gaussian")==0)
  F.function = &sig2gauss;
        if(strcmp(SigmaFilter,"sharp-k")==0)
         F.function = &sig2sharpk;
  gsl_integration_qags(&F,0.0,1.0,epsabs,epsrel,nbins,w,&sig2,&abserr);
 sigma = sqrt(sig2);
    }
 gsl_integration_workspace_free (w);
  return sigma;
}

variable_types: sigma double

variable_types:
cobenorm
double ()

variable_types: epsabs double

variable_types: abserr double

variable_types: epsrel double

variable_types: nbins int

variable_types: struct gsl_integration_workspace { unsigned long limit; unsigned long size; unsigned long nrmax; unsigned long i; unsigned long maximum_level; double *alist; double *blist; double *rlist; double *elist; unsigned long *order; unsigned long *level; } *

variable_types: struct gsl_function_struct { double (*function)(double x, void *params); void *params; }


repo: ralferoo/cpctools

decompiled_code:
__int64 __fastcall TZX_InsertBlockAfter(__int64 a1, _QWORD *a2, __int64 a3)
{
__int64 result; // rax

*a2 = a3;
result = *(_QWORD *)(a3 + 8);
a2[1] = result;
*(_QWORD *)(a3 + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2, __int64 a3)
{
__int64 result; // rax

*a2 = a3;
result = *(_QWORD *)(a3 + 8);
a2[1] = result;
*(_QWORD *)(a3 + 8) = a2;
return result;
}

original_code:
void TZX_InsertBlockAfter(TZX_FILE *pFile,TZX_BLOCK *pBlock, TZX_BLOCK *pPrev)
{
 pBlock->pPrev = pPrev;
 pBlock->pNext = pPrev->pNext;
 pPrev->pNext = pBlock;
}

canonical_original_code:
void TZX_InsertBlockAfter(struct TZX_FILE *pFile, struct TZX_BLOCK *pBlock, struct TZX_BLOCK *pPrev)
{
 pBlock->pPrev = pPrev;
 pBlock->pNext = pPrev->pNext;
 pPrev->pNext = pBlock;
}

variable_types: struct TZX_FILE { unsigned char VersionMajor; unsigned char VersionMinor; struct TZX_BLOCK { struct TZX_BLOCK *pPrev; struct TZX_BLOCK *pNext; unsigned char *pBlockHeader; unsigned long DataBlockSize; unsigned char *pBlockData; } *pFirstBlock; } *

variable_types:
pBlock
struct TZX_BLOCK *

variable_types:
pPrev
struct TZX_BLOCK *

user_defined_types: struct TZX_FILE { unsigned char VersionMajor; unsigned char VersionMinor; struct TZX_BLOCK *pFirstBlock; }


decompiled_code:
__int64 __fastcall TZX_AddBlockToEndOfFile(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a1 + 8);
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 8);
}
while ( result );
result = TZX_InsertBlockAfter(a1, a2, v3);
}
else
{
*(_QWORD *)(a1 + 8) = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a1 + 8);
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 8);
}
while ( result );
result = func0(a1, a2, v3);
}
else
{
*(_QWORD *)(a1 + 8) = a2;
}
return result;
}

original_code:
void TZX_AddBlockToEndOfFile(TZX_FILE *pFile, TZX_BLOCK *pBlock)
{
 if (pFile->pFirstBlock==((void *)0))
 {
  pFile->pFirstBlock = pBlock;
 }
 else
 {
  TZX_BLOCK *pCurrentBlock;
  pCurrentBlock = pFile->pFirstBlock;
  while (pCurrentBlock->pNext!=((void *)0))
   pCurrentBlock = pCurrentBlock->pNext;
  TZX_InsertBlockAfter(pFile,pBlock, pCurrentBlock);
 }
}

canonical_original_code:
void TZX_AddBlockToEndOfFile(struct TZX_FILE *pFile, struct TZX_BLOCK *pBlock)
{
 if (pFile->pFirstBlock==((void *)0))
 {
  pFile->pFirstBlock = pBlock;
 }
 else
 {
  struct TZX_BLOCK *pCurrentBlock;
  pCurrentBlock = pFile->pFirstBlock;
  while (pCurrentBlock->pNext!=((void *)0))
   pCurrentBlock = pCurrentBlock->pNext;
  TZX_InsertBlockAfter(pFile,pBlock, pCurrentBlock);
 }
}

variable_types: struct TZX_BLOCK { struct TZX_BLOCK *pPrev; struct TZX_BLOCK *pNext; unsigned char *pBlockHeader; unsigned long DataBlockSize; unsigned char *pBlockData; } *


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

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

original_code:
void TZX_FreeBlock(TZX_BLOCK *pBlock)
{
 free(pBlock);
}

canonical_original_code:
void TZX_FreeBlock(struct TZX_BLOCK *pBlock)
{
 free(pBlock);
}

user_defined_types: struct TZX_BLOCK { struct TZX_BLOCK *pPrev; struct TZX_BLOCK *pNext; unsigned char *pBlockHeader; unsigned long DataBlockSize; unsigned char *pBlockData; }


decompiled_code:
void __fastcall TZX_FreeFile(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1];
TZX_DetachBlock((__int64)ptr, v2);
TZX_FreeBlock(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1];
TZX_DetachBlock((__int64)ptr, v2);
func3(v2);
}
free(ptr);
}

original_code:
void TZX_FreeFile(TZX_FILE *pFile)
{
 TZX_BLOCK *pBlock;
 pBlock = pFile->pFirstBlock;
 while (pBlock!=((void *)0))
 {
  TZX_BLOCK *pNextBlock = pBlock->pNext;
  TZX_DetachBlock(pFile, pBlock);
  TZX_FreeBlock(pBlock);
  pBlock = pNextBlock;
 }
 free(pFile);
}

canonical_original_code:
void TZX_FreeFile(struct TZX_FILE *pFile)
{
 struct TZX_BLOCK *pBlock;
 pBlock = pFile->pFirstBlock;
 while (pBlock!=((void *)0))
 {
  struct TZX_BLOCK *pNextBlock = pBlock->pNext;
  TZX_DetachBlock(pFile, pBlock);
  TZX_FreeBlock(pBlock);
  pBlock = pNextBlock;
 }
 free(pFile);
}


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

switch ( a1 )
{
case 16:
result = 5LL;
break;
case 17:
result = 19LL;
break;
case 20:
result = 11LL;
break;
case 21:
result = 9LL;
break;
case 32:
result = 3LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 16:
result = 5LL;
break;
case 17:
result = 19LL;
break;
case 20:
result = 11LL;
break;
case 21:
result = 9LL;
break;
case 32:
result = 3LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int TZX_GetBlockHeaderSize(unsigned char ID)
{
 switch (ID)
 {
  case 0x010:
   return 4+1;
  case 0x011:
   return 18+1;
  case 0x020:
   return 2+1;
  case 0x014:
   return 0x0a + 1;
  case 0x015:
   return 0x08 + 1;
  default:
   break;
 }
 return 0;
}

variable_types:
ID
unsigned char


decompiled_code:
_BOOL8 __fastcall TZX_BlockHasData(unsigned __int8 a1)
{
_BOOL8 result; // rax

if ( a1 <= 0x11u )
result = a1 > 0xFu;
else
result = (unsigned __int8)(a1 - 20) <= 1u;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(unsigned __int8 a1)
{
_BOOL8 result; // rax

if ( a1 <= 0x11u )
result = a1 > 0xFu;
else
result = (unsigned __int8)(a1 - 20) <= 1u;
return result;
}

original_code:
BOOL TZX_BlockHasData(unsigned char ID)
{
 switch (ID)
 {
  case 0x010:
  case 0x011:
  case 0x014:
  case 0x015:
   return (1==1);
  case 0x020:
   return (1==0);
  default:
   break;
 }
 return (1==0);
}

canonical_original_code:
int TZX_BlockHasData(unsigned char ID)
{
 switch (ID)
 {
  case 0x010:
  case 0x011:
  case 0x014:
  case 0x015:
   return (1==1);
  case 0x020:
   return (1==0);
  default:
   break;
 }
 return (1==0);
}


decompiled_code:
__int64 __fastcall TZX_GetBlockDataPtr(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

original_code:
unsigned char *TZX_GetBlockDataPtr(TZX_BLOCK *pBlock)
{
 return pBlock->pBlockData;
}

canonical_original_code:
unsigned char *TZX_GetBlockDataPtr(struct TZX_BLOCK *pBlock)
{
 return pBlock->pBlockData;
}

return_type: unsigned char *


decompiled_code:
__int64 __fastcall TZX_GetBlockHeaderPtr(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
unsigned char *TZX_GetBlockHeaderPtr(TZX_BLOCK *pBlock)
{
 return pBlock->pBlockHeader;
}

canonical_original_code:
unsigned char *TZX_GetBlockHeaderPtr(struct TZX_BLOCK *pBlock)
{
 return pBlock->pBlockHeader;
}


decompiled_code:
__int64 __fastcall TZX_SetupPauseBlock(__int64 a1, __int16 a2)
{
__int64 result; // rax

result = TZX_GetBlockHeaderPtr(a1);
if ( result )
{
if ( *(_BYTE *)result == 32 )
*(_WORD *)(result + 1) = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int16 a2)
{
__int64 result; // rax

result = func13(a1);
if ( result )
{
if ( *(_BYTE *)result == 32 )
*(_WORD *)(result + 1) = a2;
}
return result;
}

original_code:
void TZX_SetupPauseBlock(TZX_BLOCK *pBlock,unsigned long PauseInMilliseconds)
{
 unsigned char *pHeader = TZX_GetBlockHeaderPtr(pBlock);
 if (pHeader!=((void *)0))
 {
  if (pHeader[0] == 0x020)
  {
   pHeader[1] = (unsigned char)PauseInMilliseconds;
   pHeader[2] = (unsigned char)(PauseInMilliseconds>>8);
  }
 }
}

canonical_original_code:
void TZX_SetupPauseBlock(struct TZX_BLOCK *pBlock, unsigned long PauseInMilliseconds)
{
 unsigned char *pHeader = TZX_GetBlockHeaderPtr(pBlock);
 if (pHeader!=((void *)0))
 {
  if (pHeader[0] == 0x020)
  {
   pHeader[1] = (unsigned char)PauseInMilliseconds;
   pHeader[2] = (unsigned char)(PauseInMilliseconds>>8);
  }
 }
}

variable_types:
PauseInMilliseconds
unsigned long

variable_types:
pHeader
unsigned char *


decompiled_code:
int __fastcall pws_mywrite(int fd, char *src)
{
int v2; // ebx
int *v4; // rax
char *v5; // rax
struct timespec v6; // [rsp+0h] [rbp-68h] BYREF
char dest[88]; // [rsp+10h] [rbp-58h] BYREF

v2 = strlen(src);
strcpy(dest, src);
if ( write(fd, dest, v2) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
die("power supply write error: %s", v5);
}
v6.tv_sec = 0LL;
v6.tv_nsec = 20000000LL;
return nanosleep(&v6, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(int fd, char *src)
{
int v2; // ebx
int *v4; // rax
char *v5; // rax
struct timespec v6; // [rsp+0h] [rbp-68h] BYREF
char dest[88]; // [rsp+10h] [rbp-58h] BYREF

v2 = strlen(src);
strcpy(dest, src);
if ( write(fd, dest, v2) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
die("power supply write error: %s", v5);
}
v6.tv_sec = 0LL;
v6.tv_nsec = 20000000LL;
return nanosleep(&v6, 0LL);
}

original_code:
void pws_mywrite(int file, char *cmd) {
 int size = strlen(cmd);
 char str[50];
 sprintf(str, "%s", cmd);
 if(write(file, str, size)==-1)
  die("power supply write error: %s", strerror((*__errno_location ())));
 long pause_ms = 20;
 long pause_seconds = pause_ms/1000;
 pause_ms -= pause_seconds*1000;
 struct timespec pausetime;
 pausetime.tv_sec = pause_seconds;
 pausetime.tv_nsec = pause_ms*1e6;
 nanosleep(&pausetime, ((void *)0));
}

variable_types: file int

variable_types:
cmd
char *

variable_types: size int

variable_types:
str
char [50]

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


decompiled_code:
int init_pws()
{
__int64 i; // rbx
int result; // eax
char v2[112]; // [rsp+0h] [rbp-E8h] BYREF
char s[120]; // [rsp+70h] [rbp-78h] BYREF

gettimeofday(&starttime, 0LL);
for ( i = 1LL; i != 3; ++i )
{
engaged[i - 1] = 0;
sprintf(s, "/dev/usbtmc%d", (unsigned int)i);
result = open(s, 2);
if ( result >= 0 )
{
files[i - 1] = result;
pws_mywrite(result, "*RST");
pws_mywrite(files[i - 1], "SYST:REM");
pws_mywrite(files[i - 1], "SOUR:VOLT 20V");
engaged[i - 1] = 1;
pws_i_control[i - 1] = LC5;
sprintf(v2, "SOUR:CURR %fA", *(double *)&LC5);
pws_mywrite(files[i - 1], v2);
result = pws_mywrite(files[i - 1], "OUTPUT 1");
}
else
{
files[i - 1] = -1;
}
}
return result;
}

canonical_decompiled_code:
int func2()
{
__int64 i; // rbx
int result; // eax
char v2[112]; // [rsp+0h] [rbp-E8h] BYREF
char s[120]; // [rsp+70h] [rbp-78h] BYREF

gettimeofday(&starttime, 0LL);
for ( i = 1LL; i != 3; ++i )
{
engaged[i - 1] = 0;
sprintf(s, "/dev/usbtmc%d", (unsigned int)i);
result = open(s, 2);
if ( result >= 0 )
{
files[i - 1] = result;
func0(result, "*RST");
func0(files[i - 1], "SYST:REM");
func0(files[i - 1], "SOUR:VOLT 20V");
engaged[i - 1] = 1;
pws_i_control[i - 1] = LC5;
sprintf(v2, "SOUR:CURR %fA", *(double *)&LC5);
func0(files[i - 1], v2);
result = func0(files[i - 1], "OUTPUT 1");
}
else
{
files[i - 1] = -1;
}
}
return result;
}

original_code:
void init_pws() {
 int i, h;
 char fname[100];
 gettimeofday(&starttime, 0);
 for (i = 0; i < 2; i++) {
  engaged[i] = 0;
  sprintf(fname, "/dev/usbtmc%d", i+1);
  if ((h = open(fname, 02)) >= 0) {
   files[i] = h;
   char buffer[100];
   pws_mywrite(files[i], "*RST");
   pws_mywrite(files[i], "SYST:REM");
   pws_mywrite(files[i], "SOUR:VOLT 20V");
   int control_enabled = 0;
    control_enabled = 1;
    engaged[i] = 1;
    pws_i_control[i] = 0.5;
   if((options_opt.pws_delay != 0 &&
    options_opt.pws_current[i] != 0) || control_enabled)
   {
    sprintf(buffer,"SOUR:CURR %fA",
     0.5);
    pws_mywrite(files[i], buffer);
    pws_mywrite(files[i], "OUTPUT 1");
   }
   else
   {
    pws_mywrite(files[i], "OUTPUT 0");
   }
  }
  else {
   files[i] = -1;
  }
 }
}

canonical_original_code:
void init_pws() {
 int i; int h;
 char fname[100];
 gettimeofday(&starttime, 0);
 for (i = 0; i < 2; i++) {
  engaged[i] = 0;
  sprintf(fname, "/dev/usbtmc%d", i+1);
  if ((h = open(fname, 02)) >= 0) {
   files[i] = h;
   char buffer[100];
   pws_mywrite(files[i], "*RST");
   pws_mywrite(files[i], "SYST:REM");
   pws_mywrite(files[i], "SOUR:VOLT 20V");
   int control_enabled = 0;
    control_enabled = 1;
    engaged[i] = 1;
    pws_i_control[i] = 0.5;
   if((options_opt.pws_delay != 0 &&
    options_opt.pws_current[i] != 0) || control_enabled)
   {
    sprintf(buffer,"SOUR:CURR %fA",
     0.5);
    pws_mywrite(files[i], buffer);
    pws_mywrite(files[i], "OUTPUT 1");
   }
   else
   {
    pws_mywrite(files[i], "OUTPUT 0");
   }
  }
  else {
   files[i] = -1;
  }
 }
}

variable_types: i int

variable_types: h int

variable_types:
fname
char [100]

variable_types:
buffer
char [100]


decompiled_code:
void __fastcall parse_pws(const char *a1, int a2, __int64 a3)
{
*(double *)(a3 + 8LL * a2) = atof(a1);
}

canonical_decompiled_code:
void __fastcall func3(const char *a1, int a2, __int64 a3)
{
*(double *)(a3 + 8LL * a2) = atof(a1);
}

original_code:
void parse_pws(char *buffer, int ch, double *dataArray) {
 dataArray[ch] = atof(buffer);
}

variable_types:
buffer
char *

variable_types: ch int

variable_types:
dataArray
double *


decompiled_code:
void *__fastcall rw_pws(void *a1)
{
int v1; // ebp
float v2; // eax
char v4[64]; // [rsp+0h] [rbp-D8h] BYREF
char s[152]; // [rsp+40h] [rbp-98h] BYREF

v1 = *(_DWORD *)a1;
while ( states[v1] != 2 )
{
if ( !engaged[v1] )
{
gettimeofday((struct timeval *)&now[2 * v1], 0LL);
v2 = options_opt[30];
if ( v2 == 0.0 || now[2 * v1] - starttime.tv_sec > SLODWORD(v2) )
{
sprintf(s, "SOUR:CURR %fA", options_opt[v1 + 28]);
pws_mywrite(files[v1], s);
pws_mywrite(files[v1], "OUTPUT 1");
engaged[v1] = 1;
}
}
pws_myread(files[v1], "MEAS:VOLT:DC?", s);
parse_pws(s, v1, (__int64)&curr_pws_v);
pws_myread(files[v1], "MEAS:CURR:DC?", s);
parse_pws(s, v1, (__int64)&curr_pws_i);
sprintf(v4, "SOUR:CURR %fA", *(double *)&pws_i_control[v1]);
pws_mywrite(files[v1], v4);
if ( !states[v1] )
states[v1] = 1;
}
states[v1] = 3;
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func4(void *a1)
{
int v1; // ebp
float v2; // eax
char v4[64]; // [rsp+0h] [rbp-D8h] BYREF
char s[152]; // [rsp+40h] [rbp-98h] BYREF

v1 = *(_DWORD *)a1;
while ( states[v1] != 2 )
{
if ( !engaged[v1] )
{
gettimeofday((struct timeval *)&now[2 * v1], 0LL);
v2 = options_opt[30];
if ( v2 == 0.0 || now[2 * v1] - starttime.tv_sec > SLODWORD(v2) )
{
sprintf(s, "SOUR:CURR %fA", options_opt[v1 + 28]);
func0(files[v1], s);
func0(files[v1], "OUTPUT 1");
engaged[v1] = 1;
}
}
func1(files[v1], "MEAS:VOLT:DC?", s);
func3(s, v1, (__int64)&curr_pws_v);
func1(files[v1], "MEAS:CURR:DC?", s);
func3(s, v1, (__int64)&curr_pws_i);
sprintf(v4, "SOUR:CURR %fA", *(double *)&pws_i_control[v1]);
func0(files[v1], v4);
if ( !states[v1] )
states[v1] = 1;
}
states[v1] = 3;
return 0LL;
}

original_code:
void *rw_pws(void *chan) {
 char buffer[100];
 int ch = *((int *)chan);
 while (states[ch] != HALTED) {
  if(!engaged[ch])
  {
   gettimeofday(&now[ch], 0);
   if(options_opt.pws_delay == 0 ||
    (now[ch].tv_sec-starttime.tv_sec > options_opt.pws_delay))
   {
    sprintf(buffer,"SOUR:CURR %fA",
     options_opt.pws_current[ch]);
    pws_mywrite(files[ch], buffer);
    pws_mywrite(files[ch], "OUTPUT 1");
    engaged[ch] = 1;
   }
  }
  pws_myread(files[ch], "MEAS:VOLT:DC?", buffer);
  parse_pws(buffer, ch, curr_pws_v);
  pws_myread(files[ch], "MEAS:CURR:DC?", buffer);
  parse_pws(buffer, ch, curr_pws_i);
   char iset_cmd[50];
   sprintf(iset_cmd, "SOUR:CURR %fA", pws_i_control[ch]);
   pws_mywrite(files[ch], iset_cmd);
  if (states[ch] == INIT) states[ch] = RUNNING;
 }
 states[ch] = TERMINATED;
 return 0;
}

variable_types:
chan
void *

return_type: void *


decompiled_code:
__int64 start_pws()
{
__int64 result; // rax
int v1; // ecx
int arg; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

init_pws();
if ( files[0] >= 0 )
{
arg = 0;
states[0] = 0;
pthread_create(&threads, 0LL, rw_pws, &arg);
}
if ( files[1] >= 0 )
{
v3[0] = 1;
states[1] = 0;
pthread_create((pthread_t *)(unsigned int)((_DWORD)&threads + 8), 0LL, rw_pws, v3);
}
result = (unsigned int)states[1];
do
{
while ( !states[0] && files[0] >= 0 )
{
if ( !(_DWORD)result )
{
v1 = 0;
goto LABEL_8;
}
}
if ( (_DWORD)result )
return result;
v1 = 1;
LABEL_8:
;
}
while ( files[1] >= 0 || !v1 );
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
int v1; // ecx
int arg; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

func2();
if ( files[0] >= 0 )
{
arg = 0;
states[0] = 0;
pthread_create(&threads, 0LL, rw_pws, &arg);
}
if ( files[1] >= 0 )
{
v3[0] = 1;
states[1] = 0;
pthread_create((pthread_t *)(unsigned int)((_DWORD)&threads + 8), 0LL, rw_pws, v3);
}
result = (unsigned int)states[1];
do
{
while ( !states[0] && files[0] >= 0 )
{
if ( !(_DWORD)result )
{
v1 = 0;
goto LABEL_8;
}
}
if ( (_DWORD)result )
return result;
v1 = 1;
LABEL_8:
;
}
while ( files[1] >= 0 || !v1 );
return result;
}

original_code:
void start_pws() {
 int i;
 int inds[2];
 init_pws();
 for (i = 0; i < 2; i++) {
  if (files[i] >= 0) {
   int exit;
   inds[i] = i;
   states[i] = INIT;
   exit = pthread_create(&threads[i], ((void *)0), rw_pws, (void *) &inds[i]);
  }
 }
 int running = 0;
 while (!running) {
  running = 1;
  for (i = 0; i < 2; i++) {
   if (states[i] == INIT && files[i] >= 0) running = 0;
  }
 }
}

variable_types:
inds
int [2]

variable_types: exit int

variable_types: running int


decompiled_code:
int pws_cleanup()
{
__int64 i; // rbx
int result; // eax

for ( i = 0LL; i != 2; ++i )
{
if ( files[i] >= 0 )
{
states[i] = 2;
do
sleep(1u);
while ( states[i] != 3 );
pws_mywrite(files[i], "OUTPUT 0");
result = close(files[i]);
}
}
return result;
}

canonical_decompiled_code:
int func6()
{
__int64 i; // rbx
int result; // eax

for ( i = 0LL; i != 2; ++i )
{
if ( files[i] >= 0 )
{
states[i] = 2;
do
sleep(1u);
while ( states[i] != 3 );
func0(files[i], "OUTPUT 0");
result = close(files[i]);
}
}
return result;
}

original_code:
void pws_cleanup() {
 int i;
 for (i = 0; i < 2; i++) {
  if (files[i] >= 0) {
   int exit;
   states[i] = HALTED;
   while(states[i] != TERMINATED)
   {
    sleep(1);
   }
   pws_mywrite(files[i], "OUTPUT 0");
   close(files[i]);
  }
 }
}


mywrite

decompiled_code:
int __fastcall mywrite(int fd, char *s)
{
int v2; // ebx
struct timespec v4; // [rsp+0h] [rbp-68h] BYREF
char sa[88]; // [rsp+10h] [rbp-58h] BYREF

v2 = strlen(s);
sprintf(sa, "%s\n", s);
write(fd, sa, v2 + 1);
v4.tv_sec = 0LL;
v4.tv_nsec = 100000000LL;
return nanosleep(&v4, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(int fd, char *s)
{
int v2; // ebx
struct timespec v4; // [rsp+0h] [rbp-68h] BYREF
char sa[88]; // [rsp+10h] [rbp-58h] BYREF

v2 = strlen(s);
sprintf(sa, "%s\n", s);
write(fd, sa, v2 + 1);
v4.tv_sec = 0LL;
v4.tv_nsec = 100000000LL;
return nanosleep(&v4, 0LL);
}

original_code:
void mywrite(int file, char *cmd) {
 int size = strlen(cmd);
 char str[50];
 sprintf(str, "%s\n", cmd);
 write(file, str, size + 1);
 struct timespec waittime;
 waittime.tv_sec = 0;
 waittime.tv_nsec = 100000000;
 nanosleep(&waittime, ((void *)0));
}

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


myread

decompiled_code:
__int64 __fastcall myread(int fd, char *s, void *buf)
{
int v4; // eax

debug_message("READ1\n");
mywrite(fd, s);
v4 = read(fd, buf, 0x186A0uLL);
if ( v4 < 0 )
*(_BYTE *)buf = 0;
else
*((_BYTE *)buf + v4) = 0;
debug_message("BUFFER: %s\n", (const char *)buf);
return debug_message("READ2\n");
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, char *s, void *buf)
{
int v4; // eax

debug_message("READ1\n");
func0(fd, s);
v4 = read(fd, buf, 0x186A0uLL);
if ( v4 < 0 )
*(_BYTE *)buf = 0;
else
*((_BYTE *)buf + v4) = 0;
debug_message("BUFFER: %s\n", (const char *)buf);
return debug_message("READ2\n");
}

original_code:
void myread(int file, char *cmd, char *buffer) {
 debug_message("READ1\n");
 int len;
 mywrite(file, cmd);
 len = read(file, buffer, 100000);
 if (len >= 0) buffer[len] = 0;
 else buffer[0] = 0;
 debug_message("BUFFER: %s\n", buffer);
 debug_message("READ2\n");
}

variable_types: len int


getcond

decompiled_code:
int __fastcall getcond(int a1, void *a2)
{
myread(a1, "STAT:OPER:COND?", a2);
return atoi((const char *)a2);
}

canonical_decompiled_code:
int __fastcall func2(int a1, void *a2)
{
func1(a1, "STAT:OPER:COND?", a2);
return atoi((const char *)a2);
}

original_code:
int getcond(int file, char *buffer) {
 myread(file, "STAT:OPER:COND?", buffer);
 return atoi(buffer);
}

variable_types: file int


decompiled_code:
__int64 init_power()
{
__int64 v0; // rbx
__int64 v1; // rsi
int v2; // ebp
char v4[256]; // [rsp+0h] [rbp-198h] BYREF
char s[152]; // [rsp+100h] [rbp-98h] BYREF

debug_message("INIT1\n");
gettimeofday(&st, 0LL);
if ( NUM_PWR_CHANNELS <= 0 )
{
v1 = 0LL;
}
else
{
v0 = 0LL;
do
{
sprintf(s, "/dev/usbtmc%d", (unsigned int)v0);
v2 = open(s, 2);
if ( v2 >= 0 )
{
fprintf(stderr, "- POWER: preparing meter %s\n", s);
myfile[v0] = v2;
mywrite(v2, "*RST");
if ( (_DWORD)v0 )
mywrite(myfile[v0], "CONF:VOLT:AC MIN");
else
mywrite(myfile[0], "CONF:VOLT:DC MIN,DEF");
mywrite(myfile[v0], "TRIG:SOUR IMM");
myread(myfile[v0], "SYST:ERR?", v4);
error_message("- POWER: meter %d initialized with error status %s", (unsigned int)v0, v4);
}
v1 = (unsigned int)++v0;
}
while ( NUM_PWR_CHANNELS > (int)v0 );
}
error_message("- detected %d power meters\n", v1);
return debug_message("INIT2\n");
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbx
__int64 v1; // rsi
int v2; // ebp
char v4[256]; // [rsp+0h] [rbp-198h] BYREF
char s[152]; // [rsp+100h] [rbp-98h] BYREF

debug_message("INIT1\n");
gettimeofday(&st, 0LL);
if ( NUM_PWR_CHANNELS <= 0 )
{
v1 = 0LL;
}
else
{
v0 = 0LL;
do
{
sprintf(s, "/dev/usbtmc%d", (unsigned int)v0);
v2 = open(s, 2);
if ( v2 >= 0 )
{
fprintf(stderr, "- POWER: preparing meter %s\n", s);
myfile[v0] = v2;
func0(v2, "*RST");
if ( (_DWORD)v0 )
func0(myfile[v0], "CONF:VOLT:AC MIN");
else
func0(myfile[0], "CONF:VOLT:DC MIN,DEF");
func0(myfile[v0], "TRIG:SOUR IMM");
func1(myfile[v0], "SYST:ERR?", v4);
error_message("- POWER: meter %d initialized with error status %s", (unsigned int)v0, v4);
}
v1 = (unsigned int)++v0;
}
while ( NUM_PWR_CHANNELS > (int)v0 );
}
error_message("- detected %d power meters\n", v1);
return debug_message("INIT2\n");
}

original_code:
void init_power() {
 debug_message("INIT1\n");
 int k;
 char fname[100];
 char err[256];
 int h;
 gettimeofday(&st, ((void *)0));
 for(k=0; k < NUM_PWR_CHANNELS; k++) {
  sprintf(fname, "/dev/usbtmc%d", k);
  if ((h = open(fname, 02)) >= 0) {
   fprintf(stderr, "- POWER: preparing meter %s\n", fname);
   myfile[k] = h;
   mywrite(myfile[k], "*RST");
   if (k == 0) mywrite(myfile[k], "CONF:VOLT:DC MIN,DEF");
   else mywrite(myfile[k], "CONF:VOLT:AC MIN");
   mywrite(myfile[k], "TRIG:SOUR IMM");
    myread(myfile[k], "SYST:ERR?", err);
    error_message("- POWER: meter %d initialized with error status %s",
     k, err);
  }
 }
 error_message("- detected %d power meters\n", k);
 debug_message("INIT2\n");
}

variable_types: k int

variable_types:
err
char [256]


decompiled_code:
char *__fastcall parse_power(char *a1, int a2)
{
char *result; // rax
const char *v3; // rdi

result = strtok(a1, ",*\\+");
if ( result )
{
v3 = result;
do
{
curr_pwr[a2] = atof(v3);
result = strtok(0LL, ",*\\+");
v3 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *a1, int a2)
{
char *result; // rax
const char *v3; // rdi

result = strtok(a1, ",*\\+");
if ( result )
{
v3 = result;
do
{
curr_pwr[a2] = atof(v3);
result = strtok(0LL, ",*\\+");
v3 = result;
}
while ( result );
}
return result;
}

original_code:
void parse_power(char *buffer, int ch) {
 char *val;
 val = strtok(buffer, ",*\\+");
 while (val != ((void *)0)) {
  curr_pwr[ch] = atof(val);
  val = strtok(((void *)0), ",*\\+");
 }
}

variable_types:
val
char *


decompiled_code:
void __fastcall __noreturn read_power(void *a1)
{
unsigned int v1; // ebp
struct timeval v2; // [rsp+0h] [rbp-186C8h] BYREF
char buf[100024]; // [rsp+10h] [rbp-186B8h] BYREF

debug_message("THREAD READ 1\n");
v1 = *(_DWORD *)a1;
states[v1] = 0;
error_message("- reading channel %d\n", v1);
while ( states[v1] != 2 )
{
gettimeofday(&v2, 0LL);
myread(myfile[v1], "READ?", buf);
parse_power(buf, v1);
if ( !states[v1] )
states[v1] = 1;
}
debug_message("THREAD READ 2\n");
states[v1] = 3;
pthread_exit(&loc_2);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(void *a1)
{
unsigned int v1; // ebp
struct timeval v2; // [rsp+0h] [rbp-186C8h] BYREF
char buf[100024]; // [rsp+10h] [rbp-186B8h] BYREF

debug_message("THREAD READ 1\n");
v1 = *(_DWORD *)a1;
states[v1] = 0;
error_message("- reading channel %d\n", v1);
while ( states[v1] != 2 )
{
gettimeofday(&v2, 0LL);
func1(myfile[v1], "READ?", buf);
func4(buf, v1);
if ( !states[v1] )
states[v1] = 1;
}
debug_message("THREAD READ 2\n");
states[v1] = 3;
pthread_exit(&loc_2);
}

original_code:
void *read_power(void *chan) {
 debug_message(("THREAD READ 1\n"));
 char buffer[100000];
 int ch = *((int *)chan);
 states[ch] = INIT;
 error_message("- reading channel %d\n", ch);
 while (states[ch] != HALTED) {
  int n;
  struct timeval curr;
      gettimeofday(&curr, ((void *)0));
  myread(myfile[ch], "READ?", buffer);
    parse_power(buffer, ch);
    if (states[ch] == INIT) states[ch] = RUNNING;
 }
 debug_message(("THREAD READ 2\n"));
 states[ch] = TERMINATED;
 pthread_exit((void *)2);
}

variable_types:
buffer
char [100000]

variable_types: n int

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


decompiled_code:
__int64 start_power()
{
void *v0; // rsp
__int64 result; // rax
__int64 *v2; // r12
__int64 v3; // rbx
unsigned int v4; // eax
int v5; // edx
__int64 v6; // [rsp+0h] [rbp-10h] BYREF

v0 = alloca(4LL * NUM_PWR_CHANNELS);
result = init_power();
if ( NUM_PWR_CHANNELS > 0 )
{
v2 = &v6;
v3 = 0LL;
do
{
*(_DWORD *)v2 = v3;
v4 = pthread_create((pthread_t *)&threads[v3], 0LL, (void *(*)(void *))read_power, v2);
result = error_message("- POWER: created power thread #%d with return code %d\n", (unsigned int)v3++, v4);
v2 = (__int64 *)((char *)v2 + 4);
}
while ( NUM_PWR_CHANNELS > (int)v3 );
do
{
if ( NUM_PWR_CHANNELS <= 0 )
break;
result = 0LL;
v5 = 1;
do
{
if ( !states[result] )
v5 = 0;
++result;
}
while ( result != NUM_PWR_CHANNELS );
}
while ( !v5 );
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
void *v0; // rsp
__int64 result; // rax
__int64 *v2; // r12
__int64 v3; // rbx
unsigned int v4; // eax
int v5; // edx
__int64 v6; // [rsp+0h] [rbp-10h] BYREF

v0 = alloca(4LL * NUM_PWR_CHANNELS);
result = func3();
if ( NUM_PWR_CHANNELS > 0 )
{
v2 = &v6;
v3 = 0LL;
do
{
*(_DWORD *)v2 = v3;
v4 = pthread_create((pthread_t *)&threads[v3], 0LL, (void *(*)(void *))read_power, v2);
result = error_message("- POWER: created power thread #%d with return code %d\n", (unsigned int)v3++, v4);
v2 = (__int64 *)((char *)v2 + 4);
}
while ( NUM_PWR_CHANNELS > (int)v3 );
do
{
if ( NUM_PWR_CHANNELS <= 0 )
break;
result = 0LL;
v5 = 1;
do
{
if ( !states[result] )
v5 = 0;
++result;
}
while ( result != NUM_PWR_CHANNELS );
}
while ( !v5 );
}
return result;
}

original_code:
void start_power() {
 int i;
 int inds[NUM_PWR_CHANNELS];
 init_power();
 for (i = 0; i < NUM_PWR_CHANNELS; i++) {
  int exit;
  inds[i] = i;
  exit = pthread_create(&threads[i], ((void *)0), read_power, (void *) &inds[i]);
  error_message("- POWER: created power thread #%d with return code %d\n",
   i, exit);
 }
 int running = 0;
 while(!running) {
  running = 1;
  for (i = 0; i < NUM_PWR_CHANNELS; i++) {
   if (states[i] == INIT) running = 0;
  }
 }
}

canonical_original_code:
void start_power() {
 int i;
 int inds[-1];
 init_power();
 for (i = 0; i < NUM_PWR_CHANNELS; i++) {
  int exit;
  inds[i] = i;
  exit = pthread_create(&threads[i], ((void *)0), read_power, (void *) &inds[i]);
  error_message("- POWER: created power thread #%d with return code %d\n",
   i, exit);
 }
 int running = 0;
 while(!running) {
  running = 1;
  for (i = 0; i < NUM_PWR_CHANNELS; i++) {
   if (states[i] == INIT) running = 0;
  }
 }
}

variable_types: i int

variable_types:
inds
int [-1]


decompiled_code:
__int64 power_cleanup()
{
__int64 v0; // rbx
__int64 v1; // rbx

debug_message("CLEAUP1\n");
if ( NUM_PWR_CHANNELS > 0 )
{
v0 = 0LL;
do
{
states[v0] = 2;
do
sleep(1u);
while ( states[v0] != 3 );
pthread_detach(threads[v0++]);
}
while ( NUM_PWR_CHANNELS > (int)v0 );
if ( NUM_PWR_CHANNELS > 0 )
{
v1 = 0LL;
do
close(myfile[v1++]);
while ( NUM_PWR_CHANNELS > (int)v1 );
}
}
return debug_message("CLEAUP2\n");
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rbx
__int64 v1; // rbx

debug_message("CLEAUP1\n");
if ( NUM_PWR_CHANNELS > 0 )
{
v0 = 0LL;
do
{
states[v0] = 2;
do
sleep(1u);
while ( states[v0] != 3 );
pthread_detach(threads[v0++]);
}
while ( NUM_PWR_CHANNELS > (int)v0 );
if ( NUM_PWR_CHANNELS > 0 )
{
v1 = 0LL;
do
close(myfile[v1++]);
while ( NUM_PWR_CHANNELS > (int)v1 );
}
}
return debug_message("CLEAUP2\n");
}

original_code:
void power_cleanup() {
 debug_message(("CLEAUP1\n"));
 int i;
 for(i = 0; i < NUM_PWR_CHANNELS; i++) {
  int exit;
  states[i] = HALTED;
  void *retval;
  while(states[i] != TERMINATED)
  {
   sleep(1);
  }
  pthread_detach(threads[i]);
 }
 for(i = 0; i < NUM_PWR_CHANNELS; i++) {
  close(myfile[i]);
 }
 debug_message(("CLEAUP2\n"));
}

variable_types:
retval
void *


decompiled_code:
void delete_options()
{
free(*((void **)&options_opt + 16));
}

canonical_decompiled_code:
void func0()
{
free(*((void **)&options_opt + 16));
}

original_code:
void delete_options()
{
 free(options_opt.affinities);
}