repo: okirch/testbus

decompiled_code:
void __fastcall ni_testbus_env_init(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
}

original_code:
void
ni_testbus_env_init(ni_testbus_env_t *env)
{
 memset(env, 0, sizeof(*env));
}

canonical_original_code:
void ni_testbus_env_init(struct ni_testbus_env *env)
{
 memset(env, 0, sizeof(*env));
}

variable_types: struct ni_testbus_env { struct ni_var_array { unsigned int count; struct ni_variable { char *name; char *value; } *data; } vars; unsigned char sorted; } *

user_defined_types: struct ni_testbus_env { struct ni_var_array vars; unsigned char sorted; }

user_defined_types: struct ni_var_array { unsigned int count; struct ni_variable *data; }


decompiled_code:
_QWORD *ni_testbus_global_env()
{
if ( !initialized_1 )
{
ni_testbus_env_init(_ni_testbus_global_env);
initialized_1 = 1;
}
return _ni_testbus_global_env;
}

canonical_decompiled_code:
_QWORD *func4()
{
if ( !initialized_1 )
{
func3(_ni_testbus_global_env);
initialized_1 = 1;
}
return _ni_testbus_global_env;
}

original_code:
ni_testbus_env_t *
ni_testbus_global_env(void)
{
 static int initialized = 0;
 if (!initialized) {
  ni_testbus_env_init(&__ni_testbus_global_env);
  initialized = 1;
 }
 return &__ni_testbus_global_env;
}

canonical_original_code:
struct ni_testbus_env *ni_testbus_global_env()
{
 static int initialized = 0;
 if (!initialized) {
  ni_testbus_env_init(&__ni_testbus_global_env);
  initialized = 1;
 }
 return &__ni_testbus_global_env;
}

variable_types: initialized int

return_type: struct ni_testbus_env { struct ni_var_array { unsigned int count; struct ni_variable { char *name; char *value; } *data; } vars; unsigned char sorted; } *


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

result = ni_var_array_destroy();
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
return result;
}

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

result = ni_var_array_destroy();
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
return result;
}

original_code:
void
ni_testbus_env_destroy(ni_testbus_env_t *env)
{
 ni_var_array_destroy(&env->vars);
 memset(env, 0, sizeof(*env));
}

canonical_original_code:
void ni_testbus_env_destroy(struct ni_testbus_env *env)
{
 ni_var_array_destroy(&env->vars);
 memset(env, 0, sizeof(*env));
}

return_type: void

user_defined_types: struct ni_variable { char *name; char *value; }


decompiled_code:
__int64 __fastcall ni_testbus_env_name_valid(char *a1)
{
char v1; // bp
const unsigned __int16 *v2; // rdx
__int64 result; // rax
_BYTE *v4; // rbp
char v5; // bl

v1 = *a1;
if ( *a1 == 95 || (v2 = *_ctype_b_loc(), result = 0LL, (v2[v1] & 0x400) != 0) )
{
v4 = a1 + 1;
v5 = a1[1];
if ( v5 )
{
do
{
if ( v5 != 95 && ((*_ctype_b_loc())[v5] & 8) == 0 )
return 0LL;
v5 = *++v4;
}
while ( *v4 );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1)
{
char v1; // bp
const unsigned __int16 *v2; // rdx
__int64 result; // rax
_BYTE *v4; // rbp
char v5; // bl

v1 = *a1;
if ( *a1 == 95 || (v2 = *_ctype_b_loc(), result = 0LL, (v2[v1] & 0x400) != 0) )
{
v4 = a1 + 1;
v5 = a1[1];
if ( v5 )
{
do
{
if ( v5 != 95 && ((*_ctype_b_loc())[v5] & 8) == 0 )
return 0LL;
v5 = *++v4;
}
while ( *v4 );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
ni_bool_t
ni_testbus_env_name_valid(const char *name)
{
 if (*name != '_' && !((*__ctype_b_loc ())[(int) ((*name))] & (unsigned short int) _ISalpha))
  return 0;
 while (*++name) {
  if (*name != '_' && !((*__ctype_b_loc ())[(int) ((*name))] & (unsigned short int) _ISalnum))
   return 0;
 }
 return 1;
}

canonical_original_code:
unsigned char ni_testbus_env_name_valid(char *name)
{
 if (*name != '_' && !((*__ctype_b_loc ())[(int) ((*name))] & (unsigned short) _ISalpha))
  return 0;
 while (*++name) {
  if (*name != '_' && !((*__ctype_b_loc ())[(int) ((*name))] & (unsigned short) _ISalnum))
   return 0;
 }
 return 1;
}

variable_types:
name
char *

return_type: unsigned char


decompiled_code:
bool __fastcall ni_testbus_env_name_reserved(const char *a1)
{
return strncmp(a1, "testbus_", 8uLL) == 0;
}

canonical_decompiled_code:
bool __fastcall func7(const char *a1)
{
return strncmp(a1, "testbus_", 8uLL) == 0;
}

original_code:
ni_bool_t
ni_testbus_env_name_reserved(const char *name)
{
 static const char reserved_prefix[] = "testbus_";
 if (!strncmp(name, reserved_prefix, sizeof(reserved_prefix)-1))
  return 1;
 return 0;
}

canonical_original_code:
unsigned char ni_testbus_env_name_reserved(char *name)
{
 static char reserved_prefix[] = "testbus_";
 if (!strncmp(name, reserved_prefix, sizeof(reserved_prefix)-1))
  return 1;
 return 0;
}


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

result = ni_var_array_set();
*(_BYTE *)(a1 + 16) = 0;
return result;
}

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

result = ni_var_array_set();
*(_BYTE *)(a1 + 16) = 0;
return result;
}

original_code:
void
ni_testbus_setenv(ni_testbus_env_t *env, const char *name, const char *value)
{
 ni_var_array_set(&env->vars, name, value);
 env->sorted = 0;
}

canonical_original_code:
void ni_testbus_setenv(struct ni_testbus_env *env, char *name, char *value)
{
 ni_var_array_set(&env->vars, name, value);
 env->sorted = 0;
}

variable_types:
value
char *


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

result = ni_var_array_set(a1, a2, 0LL);
*(_BYTE *)(a1 + 16) = 0;
return result;
}

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

result = ni_var_array_set(a1, a2, 0LL);
*(_BYTE *)(a1 + 16) = 0;
return result;
}

original_code:
void
ni_testbus_unsetenv(ni_testbus_env_t *env, const char *name)
{
 ni_var_array_set(&env->vars, name, ((void *)0));
 env->sorted = 0;
}

canonical_original_code:
void ni_testbus_unsetenv(struct ni_testbus_env *env, char *name)
{
 ni_var_array_set(&env->vars, name, ((void *)0));
 env->sorted = 0;
}


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

result = ni_var_array_get();
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

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

result = ni_var_array_get();
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

original_code:
const char *
ni_testbus_getenv(ni_testbus_env_t *env, const char *name)
{
 ni_var_t *var;
 if ((var = ni_var_array_get(&env->vars, name)) && var->value != ((void *)0))
  return var->value;
 return ((void *)0);
}

canonical_original_code:
char *ni_testbus_getenv(struct ni_testbus_env *env, char *name)
{
 struct ni_variable *var;
 if ((var = ni_var_array_get(&env->vars, name)) && var->value != ((void *)0))
  return var->value;
 return ((void *)0);
}

variable_types: struct ni_variable { char *name; char *value; } *

return_type: char *


decompiled_code:
void __fastcall ni_testbus_env_array_init(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func11(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

original_code:
void
ni_testbus_env_array_init(ni_testbus_env_array_t *array)
{
 memset(array, 0, sizeof(*array));
}

canonical_original_code:
void ni_testbus_env_array_init(struct ni_testbus_env_array *array)
{
 memset(array, 0, sizeof(*array));
}

variable_types: struct ni_testbus_env_array { unsigned int count; struct ni_testbus_env { struct ni_var_array { unsigned int count; struct ni_variable { char *name; char *value; } *data; } vars; unsigned char sorted; } **data; } *

user_defined_types: struct ni_testbus_env_array { unsigned int count; struct ni_testbus_env **data; }


decompiled_code:
void __fastcall ni_testbus_env_array_destroy(__int64 a1)
{
free(*(void **)(a1 + 8));
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void
ni_testbus_env_array_destroy(ni_testbus_env_array_t *array)
{
 free(array->data);
 memset(array, 0, sizeof(*array));
}

canonical_original_code:
void ni_testbus_env_array_destroy(struct ni_testbus_env_array *array)
{
 free(array->data);
 memset(array, 0, sizeof(*array));
}


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

result = ni_realloc(*(_QWORD *)(a1 + 8), 8LL * (unsigned int)(*(_DWORD *)a1 + 1));
*(_QWORD *)(a1 + 8) = result;
v3 = (*(_DWORD *)a1)++;
*(_QWORD *)(result + 8LL * v3) = a2;
return result;
}

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

result = ni_realloc(*(_QWORD *)(a1 + 8), 8LL * (unsigned int)(*(_DWORD *)a1 + 1));
*(_QWORD *)(a1 + 8) = result;
v3 = (*(_DWORD *)a1)++;
*(_QWORD *)(result + 8LL * v3) = a2;
return result;
}

original_code:
void
ni_testbus_env_array_append(ni_testbus_env_array_t *array, ni_testbus_env_t *env)
{
 array->data = ni_realloc(array->data, (array->count + 1) * sizeof(array->data[0]));
 array->data[array->count++] = env;
}

canonical_original_code:
void ni_testbus_env_array_append(struct ni_testbus_env_array *array, struct ni_testbus_env *env)
{
 array->data = ni_realloc(array->data, (array->count + 1) * sizeof(array->data[0]));
 array->data[array->count++] = env;
}

variable_types:
env
struct ni_testbus_env *


decompiled_code:
__int64 __fastcall ni_testbus_env_merge(__int64 a1, unsigned int *a2)
{
_QWORD *v2; // r15
unsigned int v3; // ebx
const char **i; // r14
__int64 v5; // rbp
unsigned int v6; // er13
const char **v7; // rbx
__int64 v8; // rax

v2 = (_QWORD *)ni_calloc(*a2, 16LL);
if ( *a2 )
{
v3 = 0;
do
{
_ni_testbus_env_sort(*(_QWORD *)(*((_QWORD *)a2 + 1) + 8LL * v3));
v2[2 * v3] = *(_QWORD *)(*((_QWORD *)a2 + 1) + 8LL * v3);
++v3;
}
while ( *a2 > v3 );
}
for ( i = 0LL; *a2; i = v7 )
{
v5 = (__int64)v2;
v6 = 0;
v7 = 0LL;
do
{
if ( i )
_ni_testbus_env_merge_skip_dups(v5, *i);
v8 = _ni_testbus_env_merge_next(v5, v7);
v7 = (const char **)v8;
++v6;
v5 += 16LL;
}
while ( *a2 > v6 );
if ( !v8 )
break;
ni_testbus_setenv(a1);
}
free(v2);
*(_BYTE *)(a1 + 16) = 1;
return 1LL;
}

original_code:
ni_bool_t
ni_testbus_env_merge(ni_testbus_env_t *result, ni_testbus_env_array_t *env_array)
{
 struct env_merge_input *merge;
 ni_var_t *last = ((void *)0);
 unsigned int n;
 merge = ni_calloc(env_array->count, sizeof(*merge));
 for (n = 0; n < env_array->count; ++n) {
  __ni_testbus_env_sort(env_array->data[n]);
  merge[n].array = &env_array->data[n]->vars;
 }
 while (1) {
  ni_var_t *var = ((void *)0);
  struct env_merge_input *m;
  unsigned int n;
  for (n = 0, m = merge; n < env_array->count; ++n, ++m) {
   if (last)
    __ni_testbus_env_merge_skip_dups(m, last->name);
   var = __ni_testbus_env_merge_next(m, var);
  }
  if (var == ((void *)0))
   break;
  ni_testbus_setenv(result, var->name, var->value);
  last = var;
 }
 free(merge);
 result->sorted = 1;
 return 1;
}

canonical_original_code:
unsigned char ni_testbus_env_merge(struct ni_testbus_env *result, struct ni_testbus_env_array *env_array)
{
 struct env_merge_input *merge;
 struct ni_variable *last = ((void *)0);
 unsigned int n;
 merge = ni_calloc(env_array->count, sizeof(*merge));
 for (n = 0; n < env_array->count; ++n) {
  __ni_testbus_env_sort(env_array->data[n]);
  merge[n].array = &env_array->data[n]->vars;
 }
 while (1) {
  struct ni_variable *var = ((void *)0);
  struct env_merge_input *m;
  unsigned int n;
  for (n = 0, m = merge; n < env_array->count; ++n, ++m) {
   if (last)
    __ni_testbus_env_merge_skip_dups(m, last->name);
   var = __ni_testbus_env_merge_next(m, var);
  }
  if (var == ((void *)0))
   break;
  ni_testbus_setenv(result, var->name, var->value);
  last = var;
 }
 free(merge);
 result->sorted = 1;
 return 1;
}

variable_types: struct ni_testbus_env_array { unsigned int count; struct ni_testbus_env **data; } *

variable_types: struct env_merge_input { struct ni_var_array { unsigned int count; struct ni_variable { char *name; char *value; } *data; } *array; unsigned int next; } *

variable_types:
n
unsigned int

user_defined_types: struct env_merge_input { struct ni_var_array *array; unsigned int next; }


decompiled_code:
__int64 __fastcall xml_escape_quote(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1;
}

original_code:
const char *
xml_escape_quote(const char *string)
{
 return string;
}

canonical_original_code:
char *xml_escape_quote(char *string)
{
 return string;
}

variable_types:
string
char *


decompiled_code:
char *__fastcall xml_escape_entities(char *s, char **a2)
{
char *v2; // rbp
char v4; // al
char *v5; // rbx
unsigned int v6; // er12
const char *v7; // rdi
size_t v8; // rax
char *v9; // rbx
char i; // al
const char *v12; // rsi

v2 = s;
if ( s )
{
v4 = *s;
if ( *s )
{
v5 = s;
v6 = 0;
do
{
v7 = (const char *)escmap_2[v4];
if ( v7 )
v6 += strlen(v7);
v4 = *++v5;
}
while ( *v5 );
if ( v6 )
{
v8 = strlen(v2);
v9 = (char *)xmalloc(v6 + v8 + 1);
*a2 = v9;
for ( i = *v2; *v2; i = *v2 )
{
v12 = (const char *)escmap_2[i];
if ( v12 )
{
strcpy(v9, v12);
v9 += strlen(v9);
}
else
{
*v9++ = i;
}
++v2;
}
*v9 = 0;
v2 = *a2;
}
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func4(char *s, char **a2)
{
char *v2; // rbp
char v4; // al
char *v5; // rbx
unsigned int v6; // er12
const char *v7; // rdi
size_t v8; // rax
char *v9; // rbx
char i; // al
const char *v12; // rsi

v2 = s;
if ( s )
{
v4 = *s;
if ( *s )
{
v5 = s;
v6 = 0;
do
{
v7 = (const char *)escmap_2[v4];
if ( v7 )
v6 += strlen(v7);
v4 = *++v5;
}
while ( *v5 );
if ( v6 )
{
v8 = strlen(v2);
v9 = (char *)xmalloc(v6 + v8 + 1);
*a2 = v9;
for ( i = *v2; *v2; i = *v2 )
{
v12 = (const char *)escmap_2[i];
if ( v12 )
{
strcpy(v9, v12);
v9 += strlen(v9);
}
else
{
*v9++ = i;
}
++v2;
}
*v9 = 0;
v2 = *a2;
}
}
}
return v2;
}

original_code:
const char *
xml_escape_entities(const char *cdata, char **temp)
{
 static const char *escmap[256] = {
  ['<'] = "<",
  ['>'] = ">",
  ['&'] = "&",
 };
 const char *pos;
 unsigned int expand = 0;
 char *copy = ((void *)0);
 if (!cdata)
  return ((void *)0);
 for (pos = cdata; *pos; ++pos) {
  const char *replace;
  if ((replace = escmap[(unsigned int) *pos]) != ((void *)0))
   expand += strlen(replace);
 }
 if (expand == 0)
  return cdata;
 copy = *temp = xmalloc(expand + strlen(cdata) + 1);
 for (pos = cdata; *pos; ++pos) {
  const char *replace;
  if ((replace = escmap[(unsigned int) *pos]) != ((void *)0)) {
   strcpy(copy, replace);
   copy += strlen(copy);
  } else {
   *copy++ = *pos;
  }
 }
 *copy = '\0';
 return *temp;
}

canonical_original_code:
char *xml_escape_entities(char *cdata, char **temp)
{
 static char *escmap[256] = {
  ['<'] = "<",
  ['>'] = ">",
  ['&'] = "&",
 };
 char *pos;
 unsigned int expand = 0;
 char *copy = ((void *)0);
 if (!cdata)
  return ((void *)0);
 for (pos = cdata; *pos; ++pos) {
  char *replace;
  if ((replace = escmap[(unsigned int) *pos]) != ((void *)0))
   expand += strlen(replace);
 }
 if (expand == 0)
  return cdata;
 copy = *temp = xmalloc(expand + strlen(cdata) + 1);
 for (pos = cdata; *pos; ++pos) {
  char *replace;
  if ((replace = escmap[(unsigned int) *pos]) != ((void *)0)) {
   strcpy(copy, replace);
   copy += strlen(copy);
  } else {
   *copy++ = *pos;
  }
 }
 *copy = '\0';
 return *temp;
}

variable_types:
cdata
char *

variable_types:
temp
char **

variable_types:
escmap
char *[256]

variable_types:
pos
char *

variable_types:
expand
unsigned int

variable_types:
copy
char *

variable_types:
replace
char *


decompiled_code:
__int64 __fastcall xml_node_trace_printer(const char *a1, _DWORD *a2)
{
__int64 result; // rax

if ( !a2 || (result = (unsigned int)(ni_debug & *a2), (ni_debug & *a2) != 0) )
result = ni_trace("%s", a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, _DWORD *a2)
{
__int64 result; // rax

if ( !a2 || (result = (unsigned int)(ni_debug & *a2), (ni_debug & *a2) != 0) )
result = ni_trace("%s", a1);
return result;
}

original_code:
static void
xml_node_trace_printer(const char *line, void *user_data)
{
 if (user_data == ((void *)0)
  || (ni_debug & *(unsigned int *) user_data) != 0)
  ni_trace("%s", line);
}

canonical_original_code:
static void xml_node_trace_printer(char *line, void *user_data)
{
 if (user_data == ((void *)0)
  || (ni_debug & *(unsigned int *) user_data) != 0)
  ni_trace("%s", line);
}

variable_types:
line
char *


decompiled_code:
__int64 __fastcall xml_node_print_debug(__int64 a1, int a2)
{
int *v2; // rdx
int v4; // [rsp+Ch] [rbp-Ch] BYREF

v4 = a2;
v2 = &v4;
if ( !a2 )
v2 = 0LL;
return xml_node_print_fn(a1, (void (__fastcall *)(char *, __int64))xml_node_trace_printer, (__int64)v2);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, int a2)
{
int *v2; // rdx
int v4; // [rsp+Ch] [rbp-Ch] BYREF

v4 = a2;
v2 = &v4;
if ( !a2 )
v2 = 0LL;
return func19(a1, (void (__fastcall *)(char *, __int64))xml_node_trace_printer, (__int64)v2);
}

original_code:
int
xml_node_print_debug(const xml_node_t *node, unsigned int facility)
{
 return xml_node_print_fn(node, xml_node_trace_printer, facility? &facility : ((void *)0));
}

canonical_original_code:
int xml_node_print_debug(struct xml_node *node, unsigned int facility)
{
 return xml_node_print_fn(node, xml_node_trace_printer, facility? &facility : ((void *)0));
}

variable_types: struct xml_node { struct xml_node *next; unsigned short refcount; unsigned short final; char *name; struct xml_node *parent; char *cdata; struct ni_var_array { unsigned int count; struct ni_variable { char *name; char *value; } *data; } attrs; struct xml_node *children; struct xml_location { struct xml_location_shared { unsigned int refcount; char *filename; } *shared; unsigned int line; } *location; } *

variable_types:
facility
unsigned int

return_type: int

user_defined_types: struct xml_node { struct xml_node *next; unsigned short refcount; unsigned short final; char *name; struct xml_node *parent; char *cdata; struct ni_var_array attrs; struct xml_node *children; struct xml_location *location; }

user_defined_types: struct xml_location { struct xml_location_shared *shared; unsigned int line; }


decompiled_code:
__int64 ni_init()
{
unsigned int v0; // ebx
__int64 v1; // rdi
__int64 v2; // rax

v0 = ni_global;
if ( ni_global )
{
ni_error("ni_init called twice");
return (unsigned int)-1;
}
v1 = *((_QWORD *)&ni_global + 1);
if ( v1 )
{
if ( !(unsigned __int8)ni_file_exists(v1) )
{
ni_error("Configuration file %s does not exist", *((const char **)&ni_global + 1));
return (unsigned int)-1;
}
}
else
{
ni_string_dup((unsigned int)((_DWORD)&ni_global + 8), "/etc/testbus/config.xml");
if ( !(unsigned __int8)ni_file_exists(*((_QWORD *)&ni_global + 1)) )
{
*((_QWORD *)&ni_global + 2) = ni_config_new();
goto LABEL_9;
}
}
v2 = ni_config_parse(*((_QWORD *)&ni_global + 1), 0LL, 0LL);
*((_QWORD *)&ni_global + 2) = v2;
if ( v2 )
{
LABEL_9:
signal(13, handler);
ni_global = 1;
return v0;
}
ni_error("Unable to parse netinfo configuration file");
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
__int64 v1; // rdi
__int64 v2; // rax

v0 = ni_global;
if ( ni_global )
{
ni_error("ni_init called twice");
return (unsigned int)-1;
}
v1 = *((_QWORD *)&ni_global + 1);
if ( v1 )
{
if ( !(unsigned __int8)ni_file_exists(v1) )
{
ni_error("Configuration file %s does not exist", *((const char **)&ni_global + 1));
return (unsigned int)-1;
}
}
else
{
ni_string_dup((unsigned int)((_DWORD)&ni_global + 8), "/etc/testbus/config.xml");
if ( !(unsigned __int8)ni_file_exists(*((_QWORD *)&ni_global + 1)) )
{
*((_QWORD *)&ni_global + 2) = ni_config_new();
goto LABEL_9;
}
}
v2 = ni_config_parse(*((_QWORD *)&ni_global + 1), 0LL, 0LL);
*((_QWORD *)&ni_global + 2) = v2;
if ( v2 )
{
LABEL_9:
signal(13, handler);
ni_global = 1;
return v0;
}
ni_error("Unable to parse netinfo configuration file");
return (unsigned int)-1;
}

original_code:
int
ni_init(const char *appname)
{
 int explicit_config = 1;
 if (ni_global.initialized) {
  ni_error("ni_init called twice");
  return -1;
 }
 if (ni_global.config_path == ((void *)0)) {
  ni_string_dup(&ni_global.config_path, "/etc/testbus" "/config.xml");
  explicit_config = 0;
 }
 if (ni_file_exists(ni_global.config_path)) {
  ni_global.config = ni_config_parse(ni_global.config_path, ((void *)0), ((void *)0));
  if (!ni_global.config) {
   ni_error("Unable to parse netinfo configuration file");
   return -1;
  }
 } else {
  if (explicit_config) {
   ni_error("Configuration file %s does not exist",
     ni_global.config_path);
   return -1;
  }
  ni_global.config = ni_config_new();
 }
 signal(13, ((__sighandler_t) 1));
 ni_global.initialized = 1;
 return 0;
}

canonical_original_code:
int ni_init(char *appname)
{
 int explicit_config = 1;
 if (ni_global.initialized) {
  ni_error("ni_init called twice");
  return -1;
 }
 if (ni_global.config_path == ((void *)0)) {
  ni_string_dup(&ni_global.config_path, "/etc/testbus" "/config.xml");
  explicit_config = 0;
 }
 if (ni_file_exists(ni_global.config_path)) {
  ni_global.config = ni_config_parse(ni_global.config_path, ((void *)0), ((void *)0));
  if (!ni_global.config) {
   ni_error("Unable to parse netinfo configuration file");
   return -1;
  }
 } else {
  if (explicit_config) {
   ni_error("Configuration file %s does not exist",
     ni_global.config_path);
   return -1;
  }
  ni_global.config = ni_config_new();
 }
 signal(13, ((void (*)(int)) 1));
 ni_global.initialized = 1;
 return 0;
}

variable_types:
appname
char *


decompiled_code:
__int64 __fastcall ni_set_global_config_path(__int64 a1)
{
return ni_string_dup((unsigned int)((_DWORD)&ni_global + 8), a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return ni_string_dup((unsigned int)((_DWORD)&ni_global + 8), a1);
}

original_code:
void
ni_set_global_config_path(const char *pathname)
{
 ni_string_dup(&ni_global.config_path, pathname);
}

canonical_original_code:
void ni_set_global_config_path(char *pathname)
{
 ni_string_dup(&ni_global.config_path, pathname);
}

variable_types:
pathname
char *


decompiled_code:
__int64 ni_config_piddir()
{
unsigned int *v0; // rbx

v0 = (unsigned int *)*((_QWORD *)&ni_global + 2);
if ( !firsttime_1 )
return *(_QWORD *)v0;
if ( (int)ni_mkdir_maybe(*(_QWORD *)v0, v0[2]) >= 0 )
{
firsttime_1 = 0;
return *(_QWORD *)v0;
}
ni_fatal("Cannot create pid file directory \"%s\": %m", *(_QWORD *)v0);
return _ni_server_pidfile();
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int *v0; // rbx

v0 = (unsigned int *)*((_QWORD *)&ni_global + 2);
if ( !firsttime_1 )
return *(_QWORD *)v0;
if ( (int)ni_mkdir_maybe(*(_QWORD *)v0, v0[2]) >= 0 )
{
firsttime_1 = 0;
return *(_QWORD *)v0;
}
ni_fatal("Cannot create pid file directory \"%s\": %m", *(_QWORD *)v0);
return func3();
}

original_code:
const char *
ni_config_piddir(void)
{
 ni_config_fslocation_t *fsloc = &ni_global.config->piddir;
 static ni_bool_t firsttime = 1;
 if (firsttime) {
  if (ni_mkdir_maybe(fsloc->path, fsloc->mode) < 0)
   ni_fatal("Cannot create pid file directory \"%s\": %m", fsloc->path);
  firsttime = 0;
 }
 return fsloc->path;
}

canonical_original_code:
char *ni_config_piddir()
{
 struct ni_config_fslocation *fsloc = &ni_global.config->piddir;
 static unsigned char firsttime = 1;
 if (firsttime) {
  if (ni_mkdir_maybe(fsloc->path, fsloc->mode) < 0)
   ni_fatal("Cannot create pid file directory \"%s\": %m", fsloc->path);
  firsttime = 0;
 }
 return fsloc->path;
}

variable_types: struct ni_config_fslocation { char *path; unsigned int mode; } *

variable_types:
firsttime
unsigned char


decompiled_code:
__int64 ni_config_statedir()
{
__int64 v0; // rbx

v0 = *((_QWORD *)&ni_global + 2);
if ( !firsttime_0 )
return *(_QWORD *)(v0 + 16);
if ( (int)ni_mkdir_maybe(*(_QWORD *)(v0 + 16), *(unsigned int *)(v0 + 24)) >= 0 )
{
firsttime_0 = 0;
return *(_QWORD *)(v0 + 16);
}
ni_fatal("Cannot create state directory \"%s\": %m", *(_QWORD *)(v0 + 16));
return ni_server_listen_other_events();
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx

v0 = *((_QWORD *)&ni_global + 2);
if ( !firsttime_0 )
return *(_QWORD *)(v0 + 16);
if ( (int)ni_mkdir_maybe(*(_QWORD *)(v0 + 16), *(unsigned int *)(v0 + 24)) >= 0 )
{
firsttime_0 = 0;
return *(_QWORD *)(v0 + 16);
}
ni_fatal("Cannot create state directory \"%s\": %m", *(_QWORD *)(v0 + 16));
return func5();
}

original_code:
const char *
ni_config_statedir(void)
{
 ni_config_fslocation_t *fsloc = &ni_global.config->statedir;
 static ni_bool_t firsttime = 1;
 if (firsttime) {
  if (ni_mkdir_maybe(fsloc->path, fsloc->mode) < 0)
   ni_fatal("Cannot create state directory \"%s\": %m", fsloc->path);
  firsttime = 0;
 }
 return fsloc->path;
}

canonical_original_code:
char *ni_config_statedir()
{
 struct ni_config_fslocation *fsloc = &ni_global.config->statedir;
 static unsigned char firsttime = 1;
 if (firsttime) {
  if (ni_mkdir_maybe(fsloc->path, fsloc->mode) < 0)
   ni_fatal("Cannot create state directory \"%s\": %m", fsloc->path);
  firsttime = 0;
 }
 return fsloc->path;
}

user_defined_types: struct ni_config_fslocation { char *path; unsigned int mode; }


decompiled_code:
void __fastcall ni_server_listen_other_events(__int64 a1)
{
*((_QWORD *)&ni_global + 3) = a1;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
*((_QWORD *)&ni_global + 3) = a1;
}

original_code:
void
ni_server_listen_other_events(void (*event_handler)(unsigned int))
{
 ni_global.other_event = event_handler;
}


decompiled_code:
bool __fastcall ni_server_is_running(const char *a1)
{
void *v1; // rbx
int v2; // ebp

v1 = (void *)_ni_server_pidfile(a1);
v2 = ni_pidfile_check(v1);
free(v1);
return v2 > 0;
}

canonical_decompiled_code:
bool __fastcall func6(const char *a1)
{
void *v1; // rbx
int v2; // ebp

v1 = (void *)func3(a1);
v2 = ni_pidfile_check(v1);
free(v1);
return v2 > 0;
}

original_code:
ni_bool_t
ni_server_is_running(const char *appname)
{
 char *pidfilepath = __ni_server_pidfile(appname);
 int rv;
 rv = ni_pidfile_check(pidfilepath);
 free(pidfilepath);
 return rv > 0;
}

canonical_original_code:
unsigned char ni_server_is_running(char *appname)
{
 char *pidfilepath = __ni_server_pidfile(appname);
 int rv;
 rv = ni_pidfile_check(pidfilepath);
 free(pidfilepath);
 return rv > 0;
}

variable_types:
pidfilepath
char *

variable_types: rv int


decompiled_code:
__int64 __fastcall ni_server_background(const char *a1)
{
void *v1; // rbx
unsigned int v2; // ebp

v1 = (void *)_ni_server_pidfile(a1);
v2 = ni_daemonize(v1, 420LL);
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
void *v1; // rbx
unsigned int v2; // ebp

v1 = (void *)func3(a1);
v2 = ni_daemonize(v1, 420LL);
free(v1);
return v2;
}

original_code:
int
ni_server_background(const char *appname)
{
 char *pidfilepath = __ni_server_pidfile(appname);
 int rv;
 rv = ni_daemonize(pidfilepath, 0644);
 free(pidfilepath);
 return rv;
}

canonical_original_code:
int ni_server_background(char *appname)
{
 char *pidfilepath = __ni_server_pidfile(appname);
 int rv;
 rv = ni_daemonize(pidfilepath, 0644);
 free(pidfilepath);
 return rv;
}


decompiled_code:
__int64 __fastcall ni_server_terminate(const char *a1)
{
void *v1; // rbx
unsigned int v2; // ebp

v1 = (void *)_ni_server_pidfile(a1);
v2 = ni_pidfile_kill(v1, 15LL);
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
void *v1; // rbx
unsigned int v2; // ebp

v1 = (void *)func3(a1);
v2 = ni_pidfile_kill(v1, 15LL);
free(v1);
return v2;
}

original_code:
int
ni_server_terminate(const char *appname)
{
 char *pidfilepath = __ni_server_pidfile(appname);
 int rv;
 rv = ni_pidfile_kill(pidfilepath, 15);
 free(pidfilepath);
 return rv;
}

canonical_original_code:
int ni_server_terminate(char *appname)
{
 char *pidfilepath = __ni_server_pidfile(appname);
 int rv;
 rv = ni_pidfile_kill(pidfilepath, 15);
 free(pidfilepath);
 return rv;
}


decompiled_code:
void **__fastcall ni_timer_cancel(void **a1)
{
void **v1; // rax
void **v2; // rbx

v1 = _ni_timer_disarm(a1);
v2 = v1;
if ( v1 )
{
v2 = (void **)v1[5];
free(v1);
}
return v2;
}

canonical_decompiled_code:
void **__fastcall func2(void **a1)
{
void **v1; // rax
void **v2; // rbx

v1 = func1(a1);
v2 = v1;
if ( v1 )
{
v2 = (void **)v1[5];
free(v1);
}
return v2;
}

original_code:
void *
ni_timer_cancel(const ni_timer_t *handle)
{
 void *user_data = ((void *)0);
 ni_timer_t *timer;
 if ((timer = __ni_timer_disarm(handle)) != ((void *)0)) {
  user_data = timer->user_data;
  free(timer);
 }
 return user_data;
}

canonical_original_code:
void *ni_timer_cancel(struct ni_timer *handle)
{
 void *user_data = ((void *)0);
 struct ni_timer *timer;
 if ((timer = __ni_timer_disarm(handle)) != ((void *)0)) {
  user_data = timer->user_data;
  free(timer);
 }
 return user_data;
}

variable_types: struct ni_timer { struct ni_timer *next; unsigned int ident; struct timeval { long tv_sec; long tv_usec; } expires; void (*callback)(void *, struct ni_timer *); void *user_data; } *

return_type: void *

user_defined_types: struct ni_timer { struct ni_timer *next; unsigned int ident; struct timeval expires; void (*callback)(void *, struct ni_timer *); void *user_data; }


decompiled_code:
int __fastcall ni_timer_get_time(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func3(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
int
ni_timer_get_time(struct timeval *tv)
{
 return gettimeofday(tv, ((void *)0));
}

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


decompiled_code:
__int64 __fastcall ni_timer_register(unsigned __int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
int v5; // eax

v4 = xcalloc(1LL, 48LL);
*(_QWORD *)(v4 + 32) = a2;
*(_QWORD *)(v4 + 40) = a3;
v5 = id_counter_0++;
*(_DWORD *)(v4 + 8) = v5;
_ni_timer_arm((struct timeval *)v4, a1);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
int v5; // eax

v4 = xcalloc(1LL, 48LL);
*(_QWORD *)(v4 + 32) = a2;
*(_QWORD *)(v4 + 40) = a3;
v5 = id_counter_0++;
*(_DWORD *)(v4 + 8) = v5;
func4((struct timeval *)v4, a1);
return v4;
}

original_code:
const ni_timer_t *
ni_timer_register(unsigned long timeout, ni_timeout_callback_t *callback, void *data)
{
 static unsigned int id_counter;
 ni_timer_t *timer;
 timer = xcalloc(1, sizeof(*timer));
 timer->callback = callback;
 timer->user_data = data;
 timer->ident = id_counter++;
 __ni_timer_arm(timer, timeout);
 return timer;
}

canonical_original_code:
struct ni_timer *ni_timer_register(unsigned long timeout, void (*callback)(void *, struct ni_timer *), void *data)
{
 static unsigned int id_counter;
 struct ni_timer *timer;
 timer = xcalloc(1, sizeof(*timer));
 timer->callback = callback;
 timer->user_data = data;
 timer->ident = id_counter++;
 __ni_timer_arm(timer, timeout);
 return timer;
}

variable_types:
timeout
unsigned long

variable_types:
callback
void (*)(void *, struct ni_timer *)

variable_types:
data
void *

return_type: struct ni_timer { struct ni_timer *next; unsigned int ident; struct timeval { long tv_sec; long tv_usec; } expires; void (*callback)(void *, struct ni_timer *); void *user_data; } *


decompiled_code:
__int64 __fastcall ni_timer_create_alarm(unsigned __int64 a1, _BYTE *a2)
{
*a2 = 0;
return ni_timer_register(a1, (__int64)_ni_timer_alarm_handler, (__int64)a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int64 a1, _BYTE *a2)
{
*a2 = 0;
return func5(a1, (__int64)_ni_timer_alarm_handler, (__int64)a2);
}

original_code:
const ni_timer_t *
ni_timer_create_alarm(unsigned long timeout_ms, ni_bool_t *flag_p)
{
 *flag_p = 0;
 return ni_timer_register(timeout_ms, __ni_timer_alarm_handler, flag_p);
}

canonical_original_code:
struct ni_timer *ni_timer_create_alarm(unsigned long timeout_ms, unsigned char *flag_p)
{
 *flag_p = 0;
 return ni_timer_register(timeout_ms, __ni_timer_alarm_handler, flag_p);
}

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


decompiled_code:
void **__fastcall ni_timer_rearm(void **a1, unsigned __int64 a2)
{
void **v2; // rax
void **v3; // rbx

v2 = _ni_timer_disarm(a1);
v3 = v2;
if ( v2 )
_ni_timer_arm((struct timeval *)v2, a2);
return v3;
}

canonical_decompiled_code:
void **__fastcall func7(void **a1, unsigned __int64 a2)
{
void **v2; // rax
void **v3; // rbx

v2 = func1(a1);
v3 = v2;
if ( v2 )
func4((struct timeval *)v2, a2);
return v3;
}

original_code:
const ni_timer_t *
ni_timer_rearm(const ni_timer_t *handle, unsigned long timeout)
{
  ni_timer_t *timer;
  if ((timer = __ni_timer_disarm(handle)) != ((void *)0))
   __ni_timer_arm(timer, timeout);
  return timer;
}

canonical_original_code:
struct ni_timer *ni_timer_rearm(struct ni_timer *handle, unsigned long timeout)
{
  struct ni_timer *timer;
  if ((timer = __ni_timer_disarm(handle)) != ((void *)0))
   __ni_timer_arm(timer, timeout);
  return timer;
}

variable_types:
handle
struct ni_timer *


decompiled_code:
__int64 ni_timer_next_timeout()
{
void **v0; // rbx
__int64 result; // rax
__time_t v2; // rax
__time_t v3; // rax
__suseconds_t v4; // rsi
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

ni_timer_get_time(&v5);
v0 = (void **)ni_timer_list;
if ( !ni_timer_list )
return -1LL;
do
{
v2 = (__time_t)v0[2];
if ( v2 == v5.tv_sec )
{
if ( (__int64)v0[3] < v5.tv_usec )
goto LABEL_6;
}
else if ( v2 < v5.tv_sec )
{
goto LABEL_6;
}
v3 = v2 - v5.tv_sec;
v4 = (__suseconds_t)v0[3] - v5.tv_usec;
if ( v4 < 0 )
{
--v3;
v4 += 1000000LL;
}
result = 1000 * v3 + v4 / 1000;
if ( result > 0 )
return result;
LABEL_6:
ni_timer_list = *v0;
((void (__fastcall *)(void *, void **))v0[4])(v0[5], v0);
free(v0);
v0 = (void **)ni_timer_list;
}
while ( ni_timer_list );
return -1LL;
}

canonical_decompiled_code:
__int64 func8()
{
void **v0; // rbx
__int64 result; // rax
__time_t v2; // rax
__time_t v3; // rax
__suseconds_t v4; // rsi
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

func3(&v5);
v0 = (void **)ni_timer_list;
if ( !ni_timer_list )
return -1LL;
do
{
v2 = (__time_t)v0[2];
if ( v2 == v5.tv_sec )
{
if ( (__int64)v0[3] < v5.tv_usec )
goto LABEL_6;
}
else if ( v2 < v5.tv_sec )
{
goto LABEL_6;
}
v3 = v2 - v5.tv_sec;
v4 = (__suseconds_t)v0[3] - v5.tv_usec;
if ( v4 < 0 )
{
--v3;
v4 += 1000000LL;
}
result = 1000 * v3 + v4 / 1000;
if ( result > 0 )
return result;
LABEL_6:
ni_timer_list = *v0;
((void (__fastcall *)(void *, void **))v0[4])(v0[5], v0);
free(v0);
v0 = (void **)ni_timer_list;
}
while ( ni_timer_list );
return -1LL;
}

original_code:
long
ni_timer_next_timeout(void)
{
 struct timeval now, delta;
 ni_timer_t *timer;
 long timeout;
 ni_timer_get_time(&now);
 while ((timer = ni_timer_list) != ((void *)0)) {
  if (!(((&timer->expires)->tv_sec == (&now)->tv_sec) ? ((&timer->expires)->tv_usec < (&now)->tv_usec) : ((&timer->expires)->tv_sec < (&now)->tv_sec))) {
   do { (&delta)->tv_sec = (&timer->expires)->tv_sec - (&now)->tv_sec; (&delta)->tv_usec = (&timer->expires)->tv_usec - (&now)->tv_usec; if ((&delta)->tv_usec < 0) { --(&delta)->tv_sec; (&delta)->tv_usec += 1000000; } } while (0);
   timeout = delta.tv_sec * 1000 + delta.tv_usec / 1000;
   if (timeout > 0)
    return timeout;
  }
  ni_timer_list = timer->next;
  timer->callback(timer->user_data, timer);
  free(timer);
 }
 return -1;
}

canonical_original_code:
long ni_timer_next_timeout()
{
 struct timeval now; struct timeval delta;
 struct ni_timer *timer;
 long timeout;
 ni_timer_get_time(&now);
 while ((timer = ni_timer_list) != ((void *)0)) {
  if (!(((&timer->expires)->tv_sec == (&now)->tv_sec) ? ((&timer->expires)->tv_usec < (&now)->tv_usec) : ((&timer->expires)->tv_sec < (&now)->tv_sec))) {
   do { (&delta)->tv_sec = (&timer->expires)->tv_sec - (&now)->tv_sec; (&delta)->tv_usec = (&timer->expires)->tv_usec - (&now)->tv_usec; if ((&delta)->tv_usec < 0) { --(&delta)->tv_sec; (&delta)->tv_usec += 1000000; } } while (0);
   timeout = delta.tv_sec * 1000 + delta.tv_usec / 1000;
   if (timeout > 0)
    return timeout;
  }
  ni_timer_list = timer->next;
  timer->callback(timer->user_data, timer);
  free(timer);
 }
 return -1;
}

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

variable_types: timeout long

return_type: long


decompiled_code:
__int64 __fastcall ni_timeout_recompute(__int64 a1)
{
__int64 result; // rax
int v2; // eax
unsigned int v3; // eax
__int64 (*v4)(void); // rdx

result = 0LL;
if ( *(_DWORD *)a1 )
{
v2 = *(_DWORD *)(a1 + 8);
if ( v2 < 0 )
v3 = 2 * *(_DWORD *)(a1 + 4);
else
v3 = *(_DWORD *)(a1 + 4) + v2;
if ( *(_DWORD *)(a1 + 20) < v3 )
v3 = *(_DWORD *)(a1 + 20);
*(_DWORD *)(a1 + 4) = v3;
v4 = *(__int64 (**)(void))(a1 + 24);
result = 1LL;
if ( v4 )
result = v4();
}
return result;
}

original_code:
ni_bool_t
ni_timeout_recompute(ni_timeout_param_t *tmo)
{
 if (tmo->nretries == 0)
  return 0;
 if (tmo->increment >= 0)
  tmo->timeout += tmo->increment;
 else
  tmo->timeout <<= 1;
 if (tmo->timeout > tmo->max_timeout)
  tmo->timeout = tmo->max_timeout;
 if (tmo->backoff_callback)
  return tmo->backoff_callback(tmo);
 return 1;
}

canonical_original_code:
unsigned char ni_timeout_recompute(struct ni_timeout_param *tmo)
{
 if (tmo->nretries == 0)
  return 0;
 if (tmo->increment >= 0)
  tmo->timeout += tmo->increment;
 else
  tmo->timeout <<= 1;
 if (tmo->timeout > tmo->max_timeout)
  tmo->timeout = tmo->max_timeout;
 if (tmo->backoff_callback)
  return tmo->backoff_callback(tmo);
 return 1;
}

variable_types: struct ni_timeout_param { int nretries; unsigned int timeout; int increment; struct ni_int_range { int min; } jitter; unsigned int max_timeout; unsigned char (*backoff_callback)(struct ni_timeout_param *); } *

user_defined_types: struct ni_timeout_param { int nretries; unsigned int timeout; int increment; struct ni_int_range jitter; unsigned int max_timeout; unsigned char (*backoff_callback)(struct ni_timeout_param *); }


decompiled_code:
__int64 __fastcall ni_timeout_randomize(__int64 a1, int *a2)
{
__int64 v2; // r12
int v3; // er13
int v4; // ebp

v2 = a1;
if ( a2 )
{
v4 = a2[1];
if ( *a2 < v4 )
{
v3 = *a2;
v2 = *a2 + random() % (unsigned int)(v4 - v3) + a1;
}
}
return v2;
}

original_code:
unsigned long
ni_timeout_randomize(unsigned long timeout, const ni_int_range_t *jitter)
{
 if (jitter && jitter->min < jitter->max) {
  unsigned int jitter_range = (jitter->max - jitter->min);
  timeout += ((long) random() % jitter_range) + jitter->min;
 }
 return timeout;
}

canonical_original_code:
unsigned long ni_timeout_randomize(unsigned long timeout, struct ni_int_range *jitter)
{
 if (jitter && jitter->min < jitter->max) {
  unsigned int jitter_range = (jitter->max - jitter->min);
  timeout += ((long) random() % jitter_range) + jitter->min;
 }
 return timeout;
}

variable_types:
jitter
struct ni_int_range { int min; } *

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall ni_timeout_arm_msec(struct timeval *a1, __int64 a2)
{
return _ni_timeout_arm_msec(a1, *(unsigned int *)(a2 + 4), (int *)(a2 + 12));
}

canonical_decompiled_code:
unsigned __int64 __fastcall func12(struct timeval *a1, __int64 a2)
{
return func11(a1, *(unsigned int *)(a2 + 4), (int *)(a2 + 12));
}

original_code:
unsigned long
ni_timeout_arm_msec(struct timeval *deadline, const ni_timeout_param_t *tp)
{
 return __ni_timeout_arm_msec(deadline, tp->timeout, &tp->jitter);
}

canonical_original_code:
unsigned long ni_timeout_arm_msec(struct timeval *deadline, struct ni_timeout_param *tp)
{
 return __ni_timeout_arm_msec(deadline, tp->timeout, &tp->jitter);
}


decompiled_code:
unsigned __int64 __fastcall ni_timeout_arm(struct timeval *a1, __int64 a2)
{
__int64 v2; // rcx
int v4[4]; // [rsp+8h] [rbp-10h] BYREF

v2 = HIDWORD(*(_QWORD *)(a2 + 12));
v4[0] = 1000 * *(_QWORD *)(a2 + 12);
v4[1] = 1000 * v2;
return _ni_timeout_arm_msec(a1, (unsigned int)(1000 * *(_DWORD *)(a2 + 4)), v4);
}

original_code:
unsigned long
ni_timeout_arm(struct timeval *deadline, const ni_timeout_param_t *tp)
{
 ni_int_range_t jitter = tp->jitter;
 jitter.min *= 1000;
 jitter.max *= 1000;
 return __ni_timeout_arm_msec(deadline, tp->timeout * 1000, &jitter);
}

canonical_original_code:
unsigned long ni_timeout_arm(struct timeval *deadline, struct ni_timeout_param *tp)
{
 struct ni_int_range jitter = tp->jitter;
 jitter.min *= 1000;
 jitter.max *= 1000;
 return __ni_timeout_arm_msec(deadline, tp->timeout * 1000, &jitter);
}

variable_types:
jitter
struct ni_int_range { int min; }


decompiled_code:
void __fastcall ni_shellcmd_release(int *a1)
{
int v1; // eax

if ( a1 )
{
if ( !*a1 )
{
ni_error("Assertion failed: %s, line %u: %s", "include/dborb/process.h", 129LL, "proc->refcount");
abort();
}
v1 = *a1 - 1;
*a1 = v1;
if ( !v1 )
ni_shellcmd_free();
}
}

canonical_decompiled_code:
void __fastcall func1(int *a1)
{
int v1; // eax

if ( a1 )
{
if ( !*a1 )
{
ni_error("Assertion failed: %s, line %u: %s", "include/dborb/process.h", 129LL, "proc->refcount");
abort();
}
v1 = *a1 - 1;
*a1 = v1;
if ( !v1 )
ni_shellcmd_free();
}
}

original_code:
static inline void
ni_shellcmd_release(ni_shellcmd_t *proc)
{
 if (!proc)
  return;
 do { if (!(proc->refcount)) { ni_error("Assertion failed: %s, line %u: %s", "include/dborb/process.h", 129, "proc->refcount"); abort(); } } while(0);
 if (--(proc->refcount) == 0)
  ni_shellcmd_free(proc);
}

canonical_original_code:
static inline void ni_shellcmd_release(struct ni_shellcmd *proc)
{
 if (!proc)
  return;
 do { if (!(proc->refcount)) { ni_error("Assertion failed: %s, line %u: %s", "include/dborb/process.h", 129, "proc->refcount"); abort(); } } while(0);
 if (--(proc->refcount) == 0)
  ni_shellcmd_free(proc);
}

variable_types: struct ni_shellcmd { unsigned int refcount; char *command; struct ni_string_array { unsigned int count; char **data; } argv; struct ni_string_array environ; unsigned int timeout; } *

user_defined_types: struct ni_shellcmd { unsigned int refcount; char *command; struct ni_string_array argv; struct ni_string_array environ; unsigned int timeout; }


decompiled_code:
char *__fastcall ni_extension_new(_QWORD **a1, __int64 a2)
{
_QWORD *v2; // rbx
char *v3; // rbp
_QWORD *v4; // rax
_QWORD *v5; // rdi

v2 = a1;
v3 = (char *)calloc(1uLL, 0x38uLL);
ni_string_dup(v3 + 8, a2);
ni_string_dup(v3 + 16, a2);
v4 = *a1;
if ( *a1 )
{
do
{
v5 = v4;
v4 = (_QWORD *)*v4;
}
while ( v4 );
v2 = v5;
}
*v2 = v3;
return v3;
}

canonical_decompiled_code:
char *__fastcall func3(_QWORD **a1, __int64 a2)
{
_QWORD *v2; // rbx
char *v3; // rbp
_QWORD *v4; // rax
_QWORD *v5; // rdi

v2 = a1;
v3 = (char *)calloc(1uLL, 0x38uLL);
ni_string_dup(v3 + 8, a2);
ni_string_dup(v3 + 16, a2);
v4 = *a1;
if ( *a1 )
{
do
{
v5 = v4;
v4 = (_QWORD *)*v4;
}
while ( v4 );
v2 = v5;
}
*v2 = v3;
return v3;
}

original_code:
ni_extension_t *
ni_extension_new(ni_extension_t **list, const char *interface)
{
 ni_extension_t *ex;
 ex = calloc(1, sizeof(*ex));
 ni_string_dup(&ex->name, interface);
 ni_string_dup(&ex->interface, interface);
 while (*list)
  list = &(*list)->next;
 *list = ex;
 return ex;
}

canonical_original_code:
struct ni_extension *ni_extension_new(struct ni_extension **list, char *interface)
{
 struct ni_extension *ex;
 ex = calloc(1, sizeof(*ex));
 ni_string_dup(&ex->name, interface);
 ni_string_dup(&ex->interface, interface);
 while (*list)
  list = &(*list)->next;
 *list = ex;
 return ex;
}

variable_types:
list
struct ni_extension **

variable_types:
interface
char *

variable_types: struct ni_extension { struct ni_extension *next; char *name; char *interface; struct ni_script_action { struct ni_script_action *next; char *name; struct ni_shellcmd { unsigned int refcount; char *command; struct ni_string_array { unsigned int count; char **data; } argv; struct ni_string_array environ; unsigned int timeout; } *process; } *actions; struct ni_c_binding { struct ni_c_binding *next; char *name; char *library; char *symbol; } *c_bindings; struct ni_var_array { unsigned int count; struct ni_variable { char *name; char *value; } *data; } environment; } *

user_defined_types: struct ni_extension { struct ni_extension *next; char *name; char *interface; struct ni_script_action *actions; struct ni_c_binding *c_bindings; struct ni_var_array environment; }

user_defined_types: struct ni_script_action { struct ni_script_action *next; char *name; struct ni_shellcmd *process; }


decompiled_code:
__int64 __fastcall ni_extension_free(__int64 a1)
{
_QWORD *i; // rdi
_QWORD *j; // rdi

ni_string_free(a1 + 8);
ni_string_free(a1 + 16);
for ( i = *(_QWORD **)(a1 + 24); i; i = *(_QWORD **)(a1 + 24) )
{
*(_QWORD *)(a1 + 24) = *i;
_ni_script_action_free(i);
}
for ( j = *(_QWORD **)(a1 + 32); j; j = *(_QWORD **)(a1 + 32) )
{
*(_QWORD *)(a1 + 32) = *j;
ni_c_binding_free();
}
return ni_var_array_destroy(a1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
_QWORD *i; // rdi
_QWORD *j; // rdi

ni_string_free(a1 + 8);
ni_string_free(a1 + 16);
for ( i = *(_QWORD **)(a1 + 24); i; i = *(_QWORD **)(a1 + 24) )
{
*(_QWORD *)(a1 + 24) = *i;
func2(i);
}
for ( j = *(_QWORD **)(a1 + 32); j; j = *(_QWORD **)(a1 + 32) )
{
*(_QWORD *)(a1 + 32) = *j;
ni_c_binding_free();
}
return ni_var_array_destroy(a1 + 40);
}

original_code:
void
ni_extension_free(ni_extension_t *ex)
{
 ni_script_action_t *act;
 ni_c_binding_t *binding;
 ni_string_free(&ex->name);
 ni_string_free(&ex->interface);
 while ((act = ex->actions) != ((void *)0)) {
  ex->actions = act->next;
  __ni_script_action_free(act);
 }
 while ((binding = ex->c_bindings) != ((void *)0)) {
  ex->c_bindings = binding->next;
  ni_c_binding_free(binding);
 }
 ni_var_array_destroy(&ex->environment);
}

canonical_original_code:
void ni_extension_free(struct ni_extension *ex)
{
 struct ni_script_action *act;
 struct ni_c_binding *binding;
 ni_string_free(&ex->name);
 ni_string_free(&ex->interface);
 while ((act = ex->actions) != ((void *)0)) {
  ex->actions = act->next;
  __ni_script_action_free(act);
 }
 while ((binding = ex->c_bindings) != ((void *)0)) {
  ex->c_bindings = binding->next;
  ni_c_binding_free(binding);
 }
 ni_var_array_destroy(&ex->environment);
}

variable_types: struct ni_script_action { struct ni_script_action *next; char *name; struct ni_shellcmd { unsigned int refcount; char *command; struct ni_string_array { unsigned int count; char **data; } argv; struct ni_string_array environ; unsigned int timeout; } *process; } *

variable_types: struct ni_c_binding { struct ni_c_binding *next; char *name; char *library; char *symbol; } *


decompiled_code:
__int64 __fastcall ni_extension_script_new(__int64 a1, __int64 a2, __int64 a3)
{
char *v4; // rbx
__int64 result; // rax

v4 = _ni_script_action_new(a2, (_QWORD **)(a1 + 24));
result = ni_shellcmd_parse(a3);
*((_QWORD *)v4 + 2) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
char *v4; // rbx
__int64 result; // rax

v4 = func0(a2, (_QWORD **)(a1 + 24));
result = ni_shellcmd_parse(a3);
*((_QWORD *)v4 + 2) = result;
return result;
}

original_code:
ni_shellcmd_t *
ni_extension_script_new(ni_extension_t *extension, const char *name, const char *command)
{
 ni_script_action_t *script;
 script = __ni_script_action_new(name, &extension->actions);
 script->process = ni_shellcmd_parse(command);
 return script->process;
}

canonical_original_code:
struct ni_shellcmd *ni_extension_script_new(struct ni_extension *extension, char *name, char *command)
{
 struct ni_script_action *script;
 script = __ni_script_action_new(name, &extension->actions);
 script->process = ni_shellcmd_parse(command);
 return script->process;
}

variable_types: struct ni_extension { struct ni_extension *next; char *name; char *interface; struct ni_script_action { struct ni_script_action *next; char *name; struct ni_shellcmd *process; } *actions; struct ni_c_binding { struct ni_c_binding *next; char *name; char *library; char *symbol; } *c_bindings; struct ni_var_array { unsigned int count; struct ni_variable { char *name; char *value; } *data; } environment; } *

variable_types:
name
char *

variable_types:
command
char *

return_type: struct ni_shellcmd { unsigned int refcount; char *command; struct ni_string_array { unsigned int count; char **data; } argv; struct ni_string_array environ; unsigned int timeout; } *


original_code:
static inline void
ni_buffer_destroy(ni_buffer_t *bp)
{
 if (bp->allocated)
  free(bp->base);
 memset(bp, 0, sizeof(*bp));
}

canonical_original_code:
static inline void ni_buffer_destroy(struct ni_buffer *bp)
{
 if (bp->allocated)
  free(bp->base);
 memset(bp, 0, sizeof(*bp));
}

variable_types: struct ni_buffer { unsigned char *base; unsigned long head; unsigned long tail; unsigned long size; unsigned int overflow; } *


decompiled_code:
void __fastcall ni_buffer_free(void *ptr)
{
ni_buffer_destroy((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
func2((__int64)ptr);
free(ptr);
}

original_code:
static inline void
ni_buffer_free(ni_buffer_t *bp)
{
 ni_buffer_destroy(bp);
 free(bp);
}

canonical_original_code:
static inline void ni_buffer_free(struct ni_buffer *bp)
{
 ni_buffer_destroy(bp);
 free(bp);
}

user_defined_types: struct ni_buffer { unsigned char *base; unsigned long head; unsigned long tail; unsigned long size; unsigned int overflow; }


decompiled_code:
__int64 __fastcall ni_buffer_ensure_tailroom(_QWORD *a1, unsigned int a2)
{
__int64 v2; // rbp
void *v4; // r12

if ( (unsigned int)ni_buffer_tailroom((__int64)a1) < a2 )
{
v2 = a1[3] + a2;
if ( (a1[4] & 4) != 0 )
{
*a1 = xrealloc(*a1, v2);
}
else
{
v4 = (void *)xmalloc(v2);
memcpy(v4, (const void *)*a1, a1[3]);
*a1 = v4;
*((_BYTE *)a1 + 32) |= 4u;
}
a1[3] = v2;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, unsigned int a2)
{
__int64 v2; // rbp
void *v4; // r12

if ( (unsigned int)func1((__int64)a1) < a2 )
{
v2 = a1[3] + a2;
if ( (a1[4] & 4) != 0 )
{
*a1 = xrealloc(*a1, v2);
}
else
{
v4 = (void *)xmalloc(v2);
memcpy(v4, (const void *)*a1, a1[3]);
*a1 = v4;
*((_BYTE *)a1 + 32) |= 4u;
}
a1[3] = v2;
}
return 1LL;
}

original_code:
ni_bool_t
ni_buffer_ensure_tailroom(ni_buffer_t *bp, unsigned int min_room)
{
 size_t new_size;
 if (ni_buffer_tailroom(bp) >= min_room)
  return 1;
 new_size = bp->size + min_room;
 if (bp->allocated) {
  bp->base = xrealloc(bp->base, new_size);
 } else {
  unsigned char *new_base;
  new_base = xmalloc(new_size);
  memcpy(new_base, bp->base, bp->size);
  bp->base = new_base;
  bp->allocated = 1;
 }
 bp->size = new_size;
 return 1;
}

canonical_original_code:
unsigned char ni_buffer_ensure_tailroom(struct ni_buffer *bp, unsigned int min_room)
{
 unsigned long new_size;
 if (ni_buffer_tailroom(bp) >= min_room)
  return 1;
 new_size = bp->size + min_room;
 if (bp->allocated) {
  bp->base = xrealloc(bp->base, new_size);
 } else {
  unsigned char *new_base;
  new_base = xmalloc(new_size);
  memcpy(new_base, bp->base, bp->size);
  bp->base = new_base;
  bp->allocated = 1;
 }
 bp->size = new_size;
 return 1;
}


decompiled_code:
__int64 __fastcall ni_buffer_chain_count(_QWORD *a1)
{
_QWORD *v1; // rbx
unsigned int v2; // ebp

if ( !a1 )
return 0;
v1 = a1;
v2 = 0;
do
{
v2 += ni_buffer_count(v1[1]);
v1 = (_QWORD *)*v1;
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
_QWORD *v1; // rbx
unsigned int v2; // ebp

if ( !a1 )
return 0;
v1 = a1;
v2 = 0;
do
{
v2 += func0(v1[1]);
v1 = (_QWORD *)*v1;
}
while ( v1 );
return v2;
}

original_code:
unsigned int
ni_buffer_chain_count(const ni_buffer_chain_t *chain)
{
 unsigned int count = 0;
 for (; chain; chain = chain->next)
  count += ni_buffer_count(chain->data);
 return count;
}

canonical_original_code:
unsigned int ni_buffer_chain_count(struct ni_buffer_chain *chain)
{
 unsigned int count = 0;
 for (; chain; chain = chain->next)
  count += ni_buffer_count(chain->data);
 return count;
}

variable_types: struct ni_buffer_chain { struct ni_buffer_chain *next; struct ni_buffer { unsigned char *base; unsigned long head; unsigned long tail; unsigned long size; unsigned int overflow; } *data; } *

variable_types:
count
unsigned int

return_type: unsigned int

user_defined_types: struct ni_buffer_chain { struct ni_buffer_chain *next; struct ni_buffer *data; }


decompiled_code:
bool __fastcall ni_string_eq(const char *a1, const char *a2)
{
bool result; // al

if ( a1 && a2 )
result = strcmp(a1, a2) == 0;
else
result = a1 == a2;
return result;
}

canonical_decompiled_code:
bool __fastcall func0(const char *a1, const char *a2)
{
bool result; // al

if ( a1 && a2 )
result = strcmp(a1, a2) == 0;
else
result = a1 == a2;
return result;
}

original_code:
static inline ni_bool_t
ni_string_eq(const char *a, const char *b)
{
 if (a == ((void *)0) || b == ((void *)0))
  return a == b;
 return strcmp(a, b) == 0;
}

canonical_original_code:
static inline unsigned char ni_string_eq(char *a, char *b)
{
 if (a == ((void *)0) || b == ((void *)0))
  return a == b;
 return strcmp(a, b) == 0;
}

variable_types:
a
char *

variable_types:
b
char *


repo: olalonde/dashell

decompiled_code:
char *__fastcall parse_arguments(char *a1, int *a2, __int64 a3)
{
char *result; // rax
char *stringp; // [rsp+8h] [rbp-20h] BYREF

stringp = a1;
for ( *a2 = 0; ; ++*a2 )
{
result = strsep(&stringp, " \r\n");
if ( !result )
break;
*(_QWORD *)(a3 + 8LL * *a2) = result;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func7(char *a1, int *a2, __int64 a3)
{
char *result; // rax
char *stringp; // [rsp+8h] [rbp-20h] BYREF

stringp = a1;
for ( *a2 = 0; ; ++*a2 )
{
result = strsep(&stringp, " \r\n");
if ( !result )
break;
*(_QWORD *)(a3 + 8LL * *a2) = result;
}
return result;
}

original_code:
void parse_arguments(char buffer[], int *args_count, char *args[]) {
  char *delimiters = " \r\n";
  char *token;
  *args_count = 0;
  while(token = strsep(&buffer, delimiters)) {
    args[*args_count] = token;
    (*args_count)++;
  }
}

variable_types:
buffer
char []

variable_types:
args
char *[]

variable_types:
delimiters
char *

variable_types:
token
char *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
size_t v3; // rax
char *v4; // rsi
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
char *file[1025]; // [rsp+0h] [rbp-2468h] BYREF
int v10; // [rsp+200Ch] [rbp-45Ch] BYREF
char buf[1040]; // [rsp+2010h] [rbp-458h] BYREF
char format[32]; // [rsp+2420h] [rbp-48h] BYREF
char s[40]; // [rsp+2440h] [rbp-28h] BYREF

strcpy(s, "\x1B[1mdashell\x1B[2m>\x1B[0m ");
strcpy(format, "Cannot execute program %s.\n");
while ( 1 )
{
do
{
do
{
v3 = strlen(s);
write(1, s, v3 + 1);
buf[(int)read(0, buf, 0x400uLL)] = 0;
parse_arguments(buf, &v10, (__int64)file);
}
while ( !v10 );
v4 = file[0];
v5 = 0;
v6 = *file[0] == 0;
}
while ( !*file[0] );
v7 = "exit";
v8 = 5LL;
do
{
if ( !v8 )
break;
v5 = (unsigned __int8)*v4 < (unsigned int)*v7;
v6 = *v4++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
exit(0);
if ( fork() )
{
wait((__WAIT_STATUS)v7);
}
else if ( execvp(file[0], file) < 0 )
{
fprintf(stderr, format, file[0]);
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
size_t v3; // rax
char *v4; // rsi
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
char *file[1025]; // [rsp+0h] [rbp-2468h] BYREF
int v10; // [rsp+200Ch] [rbp-45Ch] BYREF
char buf[1040]; // [rsp+2010h] [rbp-458h] BYREF
char format[32]; // [rsp+2420h] [rbp-48h] BYREF
char s[40]; // [rsp+2440h] [rbp-28h] BYREF

strcpy(s, "\x1B[1mdashell\x1B[2m>\x1B[0m ");
strcpy(format, "Cannot execute program %s.\n");
while ( 1 )
{
do
{
do
{
v3 = strlen(s);
write(1, s, v3 + 1);
buf[(int)read(0, buf, 0x400uLL)] = 0;
func7(buf, &v10, (__int64)file);
}
while ( !v10 );
v4 = file[0];
v5 = 0;
v6 = *file[0] == 0;
}
while ( !*file[0] );
v7 = "exit";
v8 = 5LL;
do
{
if ( !v8 )
break;
v5 = (unsigned __int8)*v4 < (unsigned int)*v7;
v6 = *v4++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
exit(0);
if ( fork() )
{
wait((__WAIT_STATUS)v7);
}
else if ( execvp(file[0], file) < 0 )
{
fprintf(stderr, format, file[0]);
}
}
}

original_code:
int main(int argc, const char* argv[]) {
  char prompt[] = "\033[1mdashell\033[2m>\033[0m ";
  char exec_error[] = "Cannot execute program %s.\n";
  char buffer[1024 + 1];
  int args_count;
  char *args[1024];
  int n;
  while(1) {
    write(1, prompt, strlen(prompt) + 1);
    n = read(0, buffer, 1024);
    buffer[n] = '\0';
    parse_arguments(buffer, &args_count, args);
    if(args_count == 0 || strcmp(args[0], "") == 0) continue;
    if(strcmp(args[0], "exit") == 0) exit(0);
    pid_t child_pid = fork();
    if(child_pid == 0) {
      if(execvp(args[0], args) < 0) {
        fprintf(stderr, exec_error, args[0]);
      }
    }
    else {
      wait();
    }
  }
}

canonical_original_code:
int main(int argc, char *argv[]) {
  char prompt[] = "\033[1mdashell\033[2m>\033[0m ";
  char exec_error[] = "Cannot execute program %s.\n";
  char buffer[-1];
  int args_count;
  char *args[1024];
  int n;
  while(1) {
    write(1, prompt, strlen(prompt) + 1);
    n = read(0, buffer, 1024);
    buffer[n] = '\0';
    parse_arguments(buffer, &args_count, args);
    if(args_count == 0 || strcmp(args[0], "") == 0) continue;
    if(strcmp(args[0], "exit") == 0) exit(0);
    int child_pid = fork();
    if(child_pid == 0) {
      if(execvp(args[0], args) < 0) {
        fprintf(stderr, exec_error, args[0]);
      }
    }
    else {
      wait();
    }
  }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
prompt
char []

variable_types:
buffer
char [-1]

variable_types:
args
char *[1024]

variable_types: n int


repo: olcf/Serial-to-Parallel--Monte-Carlo-Pi

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
int v5; // ebp
double v6; // xmm1_8
double v8; // [rsp+8h] [rbp-30h]
time_t timer; // [rsp+18h] [rbp-20h] BYREF

v3 = time(&timer);
srand48(v3);
v4 = 100001;
v5 = 0;
do
{
v8 = drand48();
v6 = drand48();
v5 -= (v8 * v8 + v6 * v6 > 1.0) - 1;
--v4;
}
while ( v4 );
return printf("Pi: %f\n", (double)v5 / 100000.0 * 4.0);
}

original_code:
void main(int argc, char* argv[])
{
 double niter = 100000;
 double x,y;
 int i;
        int count=0;
 double z;
 double pi;
 time_t t;
 srand48(((unsigned)time(&t)));
 for (i=0; i<=niter; ++i)
 {
  x = (double)drand48();
  y = (double)drand48();
  z = ((x*x)+(y*y));
  if (z<=1)
  {
   ++count;
  }
 }
 pi = ((double)count/(double)niter)*4.0;
 printf("Pi: %f\n", pi);
}

canonical_original_code:
void main(int argc, char *argv[])
{
 double niter = 100000;
 double x; double y;
 int i;
        int count = 0;
 double z;
 double pi;
 long t;
 srand48(((unsigned int)time(&t)));
 for (i=0; i<=niter; ++i)
 {
  x = (double)drand48();
  y = (double)drand48();
  z = ((x*x)+(y*y));
  if (z<=1)
  {
   ++count;
  }
 }
 pi = ((double)count/(double)niter)*4.0;
 printf("Pi: %f\n", pi);
}

variable_types: niter double

variable_types: x double

variable_types: y double

variable_types: i int

variable_types: count int

variable_types: z double

variable_types: pi double

variable_types: t long


repo: ollef/paws

decompiled_code:
int run_pause_command()
{
int result; // eax

if ( verbose )
result = puts("Running pause command");
if ( pause_command )
result = system(pause_command);
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax

if ( verbose )
result = puts("Running pause command");
if ( pause_command )
result = system(pause_command);
return result;
}

original_code:
void run_pause_command() {
  if(verbose) {printf("Running pause command\n");};
  if(pause_command) {
    system(pause_command);
  }
}


decompiled_code:
int run_resume_command()
{
int result; // eax

if ( verbose )
result = puts("Running resume command");
if ( resume_command )
result = system(resume_command);
return result;
}

canonical_decompiled_code:
int func11()
{
int result; // eax

if ( verbose )
result = puts("Running resume command");
if ( resume_command )
result = system(resume_command);
return result;
}

original_code:
void run_resume_command() {
  if(verbose) {printf("Running resume command\n");};
  if(resume_command) {
    system(resume_command);
  }
}


decompiled_code:
__int64 __fastcall is_ignore_client(char *s1)
{
int v1; // ebp
__int64 v2; // rbx

v1 = num_ignore_clients;
if ( num_ignore_clients <= 0 )
return 0LL;
v2 = 0LL;
while ( strcmp(s1, (&ignore_clients)[v2]) )
{
if ( ++v2 == v1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *s1)
{
int v1; // ebp
__int64 v2; // rbx

v1 = num_ignore_clients;
if ( num_ignore_clients <= 0 )
return 0LL;
v2 = 0LL;
while ( strcmp(s1, (&ignore_clients)[v2]) )
{
if ( ++v2 == v1 )
return 0LL;
}
return 1LL;
}

original_code:
int is_ignore_client(const char* name) {
  for(int i = 0; i < num_ignore_clients; ++i) {
    if(strcmp(name, ignore_clients[i]) == 0) {
      return 1;
    }
  }
  return 0;
}

canonical_original_code:
int is_ignore_client(char *name) {
  for(int i = 0; i < num_ignore_clients; ++i) {
    if(strcmp(name, ignore_clients[i]) == 0) {
      return 1;
    }
  }
  return 0;
}

variable_types:
name
char *


decompiled_code:
int __fastcall rem_client(unsigned int a1)
{
__int64 v1; // rax
int v2; // ebp
bool v3; // zf

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( clients[2 * v1] == a1 )
break;
if ( ++v1 == 64 )
return v1;
}
if ( dword_404104[2 * (int)v1] )
{
v3 = active_clients == 1;
LODWORD(v1) = --active_clients;
if ( v3 )
LODWORD(v1) = run_resume_command();
}
clients[2 * v2] = -1;
if ( verbose )
LODWORD(v1) = printf("Removed client %u (# active clients = %u)\n", a1, (unsigned int)active_clients);
return v1;
}

canonical_decompiled_code:
int __fastcall func13(unsigned int a1)
{
__int64 v1; // rax
int v2; // ebp
bool v3; // zf

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( clients[2 * v1] == a1 )
break;
if ( ++v1 == 64 )
return v1;
}
if ( dword_404104[2 * (int)v1] )
{
v3 = active_clients == 1;
LODWORD(v1) = --active_clients;
if ( v3 )
LODWORD(v1) = func11();
}
clients[2 * v2] = -1;
if ( verbose )
LODWORD(v1) = printf("Removed client %u (# active clients = %u)\n", a1, (unsigned int)active_clients);
return v1;
}

original_code:
void rem_client(uint32_t idx) {
  for(int i = 0; i < 64; ++i) {
    if(clients[i].idx == idx) {
      if(clients[i].input_sinks > 0) {
        --active_clients;
        if(active_clients == 0) {
          run_resume_command();
        }
      }
      clients[i].idx = ((uint32_t) -1);
      if(verbose) {printf("Removed client %u (# active clients = %u)\n", idx, active_clients);};
      return;
    }
  }
}

canonical_original_code:
void rem_client(unsigned int idx) {
  for(int i = 0; i < 64; ++i) {
    if(clients[i].idx == idx) {
      if(clients[i].input_sinks > 0) {
        --active_clients;
        if(active_clients == 0) {
          run_resume_command();
        }
      }
      clients[i].idx = ((unsigned int) -1);
      if(verbose) {printf("Removed client %u (# active clients = %u)\n", idx, active_clients);};
      return;
    }
  }
}

variable_types:
idx
unsigned int


decompiled_code:
int __fastcall add_input_sink(unsigned int a1, char *a2)
{
__int64 i; // rax

LODWORD(i) = is_ignore_client(a2);
if ( !(_DWORD)i )
{
for ( i = 0LL; i != 64; ++i )
{
if ( clients[2 * i] == a1 )
{
++dword_404104[2 * (int)i];
if ( verbose )
LODWORD(i) = printf(
"Client %u (%s) added an input sink (# active clients = %u)\n",
a1,
a2,
(unsigned int)active_clients);
return i;
}
}
i = 0LL;
while ( clients[2 * i] != -1 )
{
if ( ++i == 64 )
return i;
}
clients[2 * (int)i] = a1;
dword_404104[2 * (int)i] = 1;
LODWORD(i) = active_clients + 1;
active_clients = i;
if ( (_DWORD)i == 1 )
LODWORD(i) = run_pause_command();
if ( verbose )
LODWORD(i) = printf(
"Client %u (%s) added its first input sink (# active clients = %u)\n",
a1,
a2,
(unsigned int)active_clients);
}
return i;
}

canonical_decompiled_code:
int __fastcall func15(unsigned int a1, char *a2)
{
__int64 i; // rax

LODWORD(i) = func12(a2);
if ( !(_DWORD)i )
{
for ( i = 0LL; i != 64; ++i )
{
if ( clients[2 * i] == a1 )
{
++dword_404104[2 * (int)i];
if ( verbose )
LODWORD(i) = printf(
"Client %u (%s) added an input sink (# active clients = %u)\n",
a1,
a2,
(unsigned int)active_clients);
return i;
}
}
i = 0LL;
while ( clients[2 * i] != -1 )
{
if ( ++i == 64 )
return i;
}
clients[2 * (int)i] = a1;
dword_404104[2 * (int)i] = 1;
LODWORD(i) = active_clients + 1;
active_clients = i;
if ( (_DWORD)i == 1 )
LODWORD(i) = func10();
if ( verbose )
LODWORD(i) = printf(
"Client %u (%s) added its first input sink (# active clients = %u)\n",
a1,
a2,
(unsigned int)active_clients);
}
return i;
}

original_code:
void add_input_sink(uint32_t idx, const char* name) {
  if(is_ignore_client(name))
    return;
  for(int i = 0; i < 64; ++i) {
    if(clients[i].idx == idx) {
      ++clients[i].input_sinks;
      if(verbose) {printf("Client %u (%s) added an input sink (# active clients = %u)\n", idx, name, active_clients);};
      return;
    }
  }
  for(int i = 0; i < 64; ++i) {
    if(clients[i].idx == ((uint32_t) -1)) {
      clients[i].idx = idx;
      clients[i].input_sinks = 1;
      ++active_clients;
      if(active_clients == 1) {
        run_pause_command();
      }
      if(verbose) {printf("Client %u (%s) added its first input sink (# active clients = %u)\n", idx, name, active_clients);};
      return;
    }
  }
}

canonical_original_code:
void add_input_sink(unsigned int idx, char *name) {
  if(is_ignore_client(name))
    return;
  for(int i = 0; i < 64; ++i) {
    if(clients[i].idx == idx) {
      ++clients[i].input_sinks;
      if(verbose) {printf("Client %u (%s) added an input sink (# active clients = %u)\n", idx, name, active_clients);};
      return;
    }
  }
  for(int i = 0; i < 64; ++i) {
    if(clients[i].idx == ((unsigned int) -1)) {
      clients[i].idx = idx;
      clients[i].input_sinks = 1;
      ++active_clients;
      if(active_clients == 1) {
        run_pause_command();
      }
      if(verbose) {printf("Client %u (%s) added its first input sink (# active clients = %u)\n", idx, name, active_clients);};
      return;
    }
  }
}


decompiled_code:
int __fastcall rem_input_sink(unsigned int a1, const char *a2)
{
__int64 v2; // rax
__int64 v3; // rcx
bool v4; // zf

v2 = 0LL;
while ( clients[2 * v2] != a1 )
{
if ( ++v2 == 64 )
return v2;
}
v3 = (int)v2;
LODWORD(v2) = dword_404104[2 * (int)v2] - 1;
dword_404104[2 * v3] = v2;
if ( (_DWORD)v2 )
{
if ( verbose )
LODWORD(v2) = printf(
"Client %u (%s) removed an input sink (# active clients = %u)\n",
a1,
a2,
(unsigned int)active_clients);
}
else
{
clients[2 * v3] = -1;
v4 = active_clients == 1;
LODWORD(v2) = --active_clients;
if ( v4 )
LODWORD(v2) = run_resume_command();
if ( verbose )
LODWORD(v2) = printf(
"Client %u (%s) removed its last input sink (# active clients = %u)\n",
a1,
a2,
(unsigned int)active_clients);
}
return v2;
}

canonical_decompiled_code:
int __fastcall func16(unsigned int a1, const char *a2)
{
__int64 v2; // rax
__int64 v3; // rcx
bool v4; // zf

v2 = 0LL;
while ( clients[2 * v2] != a1 )
{
if ( ++v2 == 64 )
return v2;
}
v3 = (int)v2;
LODWORD(v2) = dword_404104[2 * (int)v2] - 1;
dword_404104[2 * v3] = v2;
if ( (_DWORD)v2 )
{
if ( verbose )
LODWORD(v2) = printf(
"Client %u (%s) removed an input sink (# active clients = %u)\n",
a1,
a2,
(unsigned int)active_clients);
}
else
{
clients[2 * v3] = -1;
v4 = active_clients == 1;
LODWORD(v2) = --active_clients;
if ( v4 )
LODWORD(v2) = func11();
if ( verbose )
LODWORD(v2) = printf(
"Client %u (%s) removed its last input sink (# active clients = %u)\n",
a1,
a2,
(unsigned int)active_clients);
}
return v2;
}

original_code:
void rem_input_sink(uint32_t idx, const char* name) {
  for(int i = 0; i < 64; ++i) {
    if(clients[i].idx == idx) {
      --clients[i].input_sinks;
      if(clients[i].input_sinks == 0) {
        clients[i].idx = ((uint32_t) -1);
        --active_clients;
        if(active_clients == 0) {
          run_resume_command();
        }
        if(verbose) {printf("Client %u (%s) removed its last input sink (# active clients = %u)\n", idx, name, active_clients);};
      } else {
        if(verbose) {printf("Client %u (%s) removed an input sink (# active clients = %u)\n", idx, name, active_clients);};
      }
      return;
    }
  }
}

canonical_original_code:
void rem_input_sink(unsigned int idx, char *name) {
  for(int i = 0; i < 64; ++i) {
    if(clients[i].idx == idx) {
      --clients[i].input_sinks;
      if(clients[i].input_sinks == 0) {
        clients[i].idx = ((unsigned int) -1);
        --active_clients;
        if(active_clients == 0) {
          run_resume_command();
        }
        if(verbose) {printf("Client %u (%s) removed its last input sink (# active clients = %u)\n", idx, name, active_clients);};
      } else {
        if(verbose) {printf("Client %u (%s) removed an input sink (# active clients = %u)\n", idx, name, active_clients);};
      }
      return;
    }
  }
}


repo: olmo/PL

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
yyin = abrir_entrada(argc, (__int64)argv);
return yyparse();
}

original_code:
int main( int argc, char *argv[] )
{
  yyin= abrir_entrada(argc,argv) ;
  return yyparse() ;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  yyin= abrir_entrada(argc,argv) ;
  return yyparse() ;
}


decompiled_code:
void log_to_null()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code: void log_to_null(const char *fmt, ...){}

canonical_original_code: void log_to_null(char *fmt, ...){}

variable_types:
fmt
char *


decompiled_code:
int record_with_location(const char *a1, const char *a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a3);
fprintf(stderr, "%s %s: ", a1, a2);
return vfprintf(stderr, a3, arg);
}

canonical_decompiled_code:
int func1(const char *a1, const char *a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a3);
fprintf(stderr, "%s %s: ", a1, a2);
return vfprintf(stderr, a3, arg);
}

original_code:
void record_with_location(const char *location, const char *func, const char *fmt, ...){
    va_list ap;
    __builtin_va_start(ap,fmt);
    fprintf(stderr, "%s %s: ", location, func);
    vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void record_with_location(char *location, char *func, char *fmt, ...){
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    fprintf(stderr, "%s %s: ", location, func);
    vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
}

variable_types:
location
char *

variable_types:
func
char *


usage

decompiled_code:
int usage()
{
return puts(
"Usage: \n"
"\t-d ad_name\t domain name\n"
"\t-u ad_manager\t domain's manager account\n"
"\t-p ad_passwd\t domain's manager account password\n"
"\t\t\t if ad_passwd is '-' cmd will read stdin to get password\n"
"\t-f conf_file\t specify config file's path. it will instead the\n"
"\t\t\t the default /tmp/domain.conf. if any option above are specified \n"
"\t\t\t will override the corresponding field in conf_file");
}

canonical_decompiled_code:
int func2()
{
return puts(
"Usage: \n"
"\t-d ad_name\t domain name\n"
"\t-u ad_manager\t domain's manager account\n"
"\t-p ad_passwd\t domain's manager account password\n"
"\t\t\t if ad_passwd is '-' cmd will read stdin to get password\n"
"\t-f conf_file\t specify config file's path. it will instead the\n"
"\t\t\t the default /tmp/domain.conf. if any option above are specified \n"
"\t\t\t will override the corresponding field in conf_file");
}

original_code:
void usage(void){
    printf("Usage: \n"
           "\t-d ad_name\t domain name\n"
           "\t-u ad_manager\t domain's manager account\n"
           "\t-p ad_passwd\t domain's manager account password\n"
           "\t\t\t if ad_passwd is '-' cmd will read stdin to get password\n"
           "\t-f conf_file\t specify config file's path. it will instead the\n"
           "\t\t\t the default /tmp/domain.conf. if any option above are specified \n"
           "\t\t\t will override the corresponding field in conf_file\n");
}

canonical_original_code:
void usage(){
    printf("Usage: \n"
           "\t-d ad_name\t domain name\n"
           "\t-u ad_manager\t domain's manager account\n"
           "\t-p ad_passwd\t domain's manager account password\n"
           "\t\t\t if ad_passwd is '-' cmd will read stdin to get password\n"
           "\t-f conf_file\t specify config file's path. it will instead the\n"
           "\t\t\t the default /tmp/domain.conf. if any option above are specified \n"
           "\t\t\t will override the corresponding field in conf_file\n");
}


decompiled_code:
void free_ad_cond()
{
void *v0; // rdi
void *v1; // rdi
void *v2; // rdi
void *v3; // rdi
unsigned __int64 v4; // rbx

v0 = (void *)*((_QWORD *)&ad + 1);
if ( v0 )
free(v0);
v1 = (void *)*((_QWORD *)&ad + 2);
if ( v1 )
free(v1);
v2 = (void *)*((_QWORD *)&ad + 3);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)&ad + 4);
if ( v3 )
{
v4 = (unsigned int)((_DWORD)&ad + 32);
do
{
free(v3);
v4 += 8LL;
v3 = *(void **)v4;
}
while ( *(_QWORD *)v4 );
}
}

canonical_decompiled_code:
void func3()
{
void *v0; // rdi
void *v1; // rdi
void *v2; // rdi
void *v3; // rdi
unsigned __int64 v4; // rbx

v0 = (void *)*((_QWORD *)&ad + 1);
if ( v0 )
free(v0);
v1 = (void *)*((_QWORD *)&ad + 2);
if ( v1 )
free(v1);
v2 = (void *)*((_QWORD *)&ad + 3);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)&ad + 4);
if ( v3 )
{
v4 = (unsigned int)((_DWORD)&ad + 32);
do
{
free(v3);
v4 += 8LL;
v3 = *(void **)v4;
}
while ( *(_QWORD *)v4 );
}
}

original_code:
void free_ad_cond(void){
    char **p;
    if(ad.ad_uri)
        free(ad.ad_uri);
    if(ad.ad_manager)
        free(ad.ad_manager);
    if(ad.ad_passwd)
        free(ad.ad_passwd);
    p = ad.ad_org_unitS;
    while(*p){
        free(*p);
        p++;
    }
}

canonical_original_code:
void free_ad_cond(){
    char **p;
    if(ad.ad_uri)
        free(ad.ad_uri);
    if(ad.ad_manager)
        free(ad.ad_manager);
    if(ad.ad_passwd)
        free(ad.ad_passwd);
    p = ad.ad_org_unitS;
    while(*p){
        free(*p);
        p++;
    }
}

variable_types:
p
char **


decompiled_code:
_BOOL8 isvalid_ad_cond()
{
_BOOL8 result; // rax

if ( (ad & 2) != 0 || (result = 0LL, *((_QWORD *)&ad + 4)) )
{
result = 0LL;
if ( *((_QWORD *)&ad + 1) )
{
if ( *((_QWORD *)&ad + 2) )
result = *((_QWORD *)&ad + 3) != 0LL;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 func4()
{
_BOOL8 result; // rax

if ( (ad & 2) != 0 || (result = 0LL, *((_QWORD *)&ad + 4)) )
{
result = 0LL;
if ( *((_QWORD *)&ad + 1) )
{
if ( *((_QWORD *)&ad + 2) )
result = *((_QWORD *)&ad + 3) != 0LL;
}
}
return result;
}

original_code:
int isvalid_ad_cond(void){
    if(ad.ad_get_udir || ad.ad_org_unitS[0])
        return (ad.ad_uri && ad.ad_manager && ad.ad_passwd);
    return 0;
}

canonical_original_code:
int isvalid_ad_cond(){
    if(ad.ad_get_udir || ad.ad_org_unitS[0])
        return (ad.ad_uri && ad.ad_manager && ad.ad_passwd);
    return 0;
}


decompiled_code:
void dump_ad_cond()
{
unsigned __int64 v0; // rax

if ( *((_QWORD *)&ad + 4) )
{
v0 = (unsigned int)((_DWORD)&ad + 32);
do
v0 += 8LL;
while ( *(_QWORD *)v0 );
}
}

canonical_decompiled_code:
void func5()
{
unsigned __int64 v0; // rax

if ( *((_QWORD *)&ad + 4) )
{
v0 = (unsigned int)((_DWORD)&ad + 32);
do
v0 += 8LL;
while ( *(_QWORD *)v0 );
}
}

original_code:
void dump_ad_cond(void){
    char **p;
    if(ad.ad_uri && ad.ad_manager && ad.ad_passwd)
        log_to_null("\n\tad_uri ## %s ##\n" "\tad_manager ## %s ##\n" "\tad_passwd ## %s ##\n", ad.ad_uri, ad.ad_manager, ad.ad_passwd);
    p = ad.ad_org_unitS;
    while(*p){
        log_to_null("\n\tad_ou ## %s ##\n", *p);
        p++;
    }
    log_to_null("\n\tad.ad_gflag ## %s ##\n", ad.ad_gflag ? "Yes" : "No");
    log_to_null("\n\tad.ad_get_udir ## %s ##\n", ad.ad_get_udir ? "Yes" : "No");
    log_to_null("\n\tad.ad_encrypt ## %s ##\n", ad.ad_encrypt ? "Yes" : "No");
}

canonical_original_code:
void dump_ad_cond(){
    char **p;
    if(ad.ad_uri && ad.ad_manager && ad.ad_passwd)
        log_to_null("\n\tad_uri ## %s ##\n" "\tad_manager ## %s ##\n" "\tad_passwd ## %s ##\n", ad.ad_uri, ad.ad_manager, ad.ad_passwd);
    p = ad.ad_org_unitS;
    while(*p){
        log_to_null("\n\tad_ou ## %s ##\n", *p);
        p++;
    }
    log_to_null("\n\tad.ad_gflag ## %s ##\n", ad.ad_gflag ? "Yes" : "No");
    log_to_null("\n\tad.ad_get_udir ## %s ##\n", ad.ad_get_udir ? "Yes" : "No");
    log_to_null("\n\tad.ad_encrypt ## %s ##\n", ad.ad_encrypt ? "Yes" : "No");
}


decompiled_code:
__int64 __fastcall opt_parse(int argc, char **argv, char *shortopts)
{
char v4; // al
__int64 result; // rax

opterr = 0;
while ( 2 )
{
v4 = getopt(argc, argv, shortopts);
if ( v4 == -1 )
return 0LL;
switch ( v4 )
{
case 'c':
init_ad_cond("ad_get_udir", 24LL);
continue;
case 'd':
if ( !(unsigned int)init_ad_cond("ad_uri", optarg) )
continue;
goto LABEL_5;
case 'f':
conf_filepath = strdup(optarg);
if ( conf_filepath )
continue;
goto LABEL_5;
case 'g':
init_ad_cond("ad_gflag", 24LL);
continue;
case 'o':
if ( !(unsigned int)init_ad_cond("ad_org_unitS", optarg) )
continue;
goto LABEL_5;
case 'p':
if ( !strcmp(optarg, "-") )
{
get_stdin_passwd = 1;
continue;
}
if ( !(unsigned int)init_ad_cond("ad_passwd", optarg) )
continue;
LABEL_5:
usage();
free_ad_cond();
result = 0xFFFFFFFFLL;
if ( conf_filepath )
{
free(conf_filepath);
result = 0xFFFFFFFFLL;
}
return result;
case 's':
init_ad_cond("ad_encrypt", 24LL);
continue;
case 'u':
if ( !(unsigned int)init_ad_cond("ad_manager", optarg) )
continue;
goto LABEL_5;
default:
goto LABEL_5;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func6(int argc, char **argv, char *shortopts)
{
char v4; // al
__int64 result; // rax

opterr = 0;
while ( 2 )
{
v4 = getopt(argc, argv, shortopts);
if ( v4 == -1 )
return 0LL;
switch ( v4 )
{
case 'c':
init_ad_cond("ad_get_udir", 24LL);
continue;
case 'd':
if ( !(unsigned int)init_ad_cond("ad_uri", optarg) )
continue;
goto LABEL_5;
case 'f':
conf_filepath = strdup(optarg);
if ( conf_filepath )
continue;
goto LABEL_5;
case 'g':
init_ad_cond("ad_gflag", 24LL);
continue;
case 'o':
if ( !(unsigned int)init_ad_cond("ad_org_unitS", optarg) )
continue;
goto LABEL_5;
case 'p':
if ( !strcmp(optarg, "-") )
{
get_stdin_passwd = 1;
continue;
}
if ( !(unsigned int)init_ad_cond("ad_passwd", optarg) )
continue;
LABEL_5:
func2();
func3();
result = 0xFFFFFFFFLL;
if ( conf_filepath )
{
free(conf_filepath);
result = 0xFFFFFFFFLL;
}
return result;
case 's':
init_ad_cond("ad_encrypt", 24LL);
continue;
case 'u':
if ( !(unsigned int)init_ad_cond("ad_manager", optarg) )
continue;
goto LABEL_5;
default:
goto LABEL_5;
}
}
}

original_code:
int opt_parse(int argc, char **argv, char *optstr){
    char c;
    opterr = 0;
    while((c = getopt(argc, argv, optstr)) != -1){
        switch(c){
            case 'd':
                if(init_ad_cond("ad_uri", optarg))
                    goto ERR_ARGS;
                break;
            case 'u':
                if(init_ad_cond("ad_manager", optarg))
                    goto ERR_ARGS;
                break;
            case 'p':
                if(!strcmp(optarg, "-"))
                    get_stdin_passwd = 1;
                else
                    if(init_ad_cond("ad_passwd", optarg))
                        goto ERR_ARGS;
                break;
            case 'f':
                if((conf_filepath = strdup(optarg)) == ((void *)0))
                    goto ERR_ARGS;
                break;
            case 'o':
                if(init_ad_cond("ad_org_unitS", optarg))
                    goto ERR_ARGS;
                break;
            case 'c':
                init_ad_cond("ad_get_udir", (char *)24);
                break;
            case 'g':
                init_ad_cond("ad_gflag", (char *)24);
                break;
            case 's':
                init_ad_cond("ad_encrypt", (char *)24);
                break;
            default :
                goto ERR_ARGS;
        }
    }
    return 0;
ERR_ARGS:
    usage();
    free_ad_cond();
    if(conf_filepath)
        free(conf_filepath);
    return -1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
optstr
char *

variable_types: c char


decompiled_code:
__int64 get_real_passwd()
{
int v0; // eax
char *v1; // rbx
void *v2; // rdi
struct termios v4; // [rsp+0h] [rbp-448h] BYREF
char buf[1032]; // [rsp+40h] [rbp-408h] BYREF

tcgetattr(0, &v4);
v4.c_lflag &= 0xFFFFFFF7;
tcsetattr(0, 2, &v4);
write(1, "Password :", 0xAuLL);
v0 = read(0, buf, 0x400uLL);
if ( v0 <= 0 )
return 0xFFFFFFFFLL;
buf[v0 - 1] = 0;
v1 = strdup(buf);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = (void *)*((_QWORD *)&ad + 3);
if ( v2 )
free(v2);
*((_QWORD *)&ad + 3) = v1;
v4.c_lflag |= 8u;
tcsetattr(0, 0, &v4);
write(1, "\n", 1uLL);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
char *v1; // rbx
void *v2; // rdi
struct termios v4; // [rsp+0h] [rbp-448h] BYREF
char buf[1032]; // [rsp+40h] [rbp-408h] BYREF

tcgetattr(0, &v4);
v4.c_lflag &= 0xFFFFFFF7;
tcsetattr(0, 2, &v4);
write(1, "Password :", 0xAuLL);
v0 = read(0, buf, 0x400uLL);
if ( v0 <= 0 )
return 0xFFFFFFFFLL;
buf[v0 - 1] = 0;
v1 = strdup(buf);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = (void *)*((_QWORD *)&ad + 3);
if ( v2 )
free(v2);
*((_QWORD *)&ad + 3) = v1;
v4.c_lflag |= 8u;
tcsetattr(0, 0, &v4);
write(1, "\n", 1uLL);
return 0LL;
}

original_code:
int get_real_passwd(){
    int n;
    char buf[1024];
    char *passwd;
    struct termios term_attrs;
    tcgetattr(0, &term_attrs);
    term_attrs.c_lflag &= ~0000010;
    tcsetattr(0, 2, &term_attrs);
    write(1, "Password :", 10);
    if((n = read(0, buf, 1024)) < 1)
        return -1;
    buf[n - 1] = 0;
    if((passwd = strdup(buf)) == ((void *)0))
        return -1;
    if(ad.ad_passwd)
        free(ad.ad_passwd);
    ad.ad_passwd = passwd;
    term_attrs.c_lflag |= 0000010;
    tcsetattr(0, 0, &term_attrs);
    write(1, "\n", 1);
    return 0;
}

variable_types: n int

variable_types:
buf
char [1024]

variable_types:
passwd
char *

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)opt_parse(argc, (char **)argv, "d:f:u:p:n:o:csg") )
{
fwrite("bad cmdline arguments. please retry!\n", 1uLL, 0x25uLL, stderr);
exit(2);
}
if ( get_stdin_passwd )
get_real_passwd();
if ( !conf_filepath )
conf_filepath = "/var/automap.conf";
if ( (unsigned int)get_cond_from_file(conf_filepath) )
{
if ( !isvalid_ad_cond() )
{
fwrite("initialize from file failed. please retry!\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
}
else if ( !isvalid_ad_cond() )
{
fwrite(
"can't get fully informations to connect WIN_AD.\nplease specify it again on cmdline or conf_file and retry!\n",
1uLL,
0x6BuLL,
stderr);
exit(2);
}
get_domain_info(&ad);
dump_ad_cond();
free_ad_cond();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func6(argc, (char **)argv, "d:f:u:p:n:o:csg") )
{
fwrite("bad cmdline arguments. please retry!\n", 1uLL, 0x25uLL, stderr);
exit(2);
}
if ( get_stdin_passwd )
func7();
if ( !conf_filepath )
conf_filepath = "/var/automap.conf";
if ( (unsigned int)get_cond_from_file(conf_filepath) )
{
if ( !func4() )
{
fwrite("initialize from file failed. please retry!\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
}
else if ( !func4() )
{
fwrite(
"can't get fully informations to connect WIN_AD.\nplease specify it again on cmdline or conf_file and retry!\n",
1uLL,
0x6BuLL,
stderr);
exit(2);
}
get_domain_info(&ad);
func5();
func3();
return 0;
}

original_code:
int main(int argc, char *argv[]){
    int i = 0;
    if(opt_parse(argc, argv, "d:f:u:p:n:o:csg")){
        fprintf(stderr, "bad cmdline arguments. please retry!\n");
        exit(2);
    }
    if(get_stdin_passwd)
        get_real_passwd();
    if(!conf_filepath)
        conf_filepath = "/var/automap.conf";
    if(get_cond_from_file(conf_filepath) && !isvalid_ad_cond()){
        fprintf(stderr, "initialize from file failed. please retry!\n");
        exit(1);
    }
    if(!isvalid_ad_cond()){
        fprintf(stderr, "can't get fully informations to connect WIN_AD.\n"
                        "please specify it again on cmdline or conf_file and retry!\n");
        exit(2);
    }
    get_domain_info(&ad);
    dump_ad_cond();
    free_ad_cond();
    return 0;
}

variable_types:
argv
char *[]

variable_types: i int


decompiled_code:
__int64 __fastcall get_dn_with_ad_cond(__int64 a1, int *a2, char *a3, const char *a4)
{
const char *v4; // r8

v4 = *(const char **)(a1 + 8LL * *a2 + 32);
if ( !v4 )
return 0LL;
++*a2;
sprintf(a3, "ou=%s,%s", v4, a4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int *a2, char *a3, const char *a4)
{
const char *v4; // r8

v4 = *(const char **)(a1 + 8LL * *a2 + 32);
if ( !v4 )
return 0LL;
++*a2;
sprintf(a3, "ou=%s,%s", v4, a4);
return 1LL;
}

original_code:
static int get_dn_with_ad_cond(win_ad_cond *cond, int *offset, char *dn, const char *dc_s){
    char *p = cond->ad_org_unitS[*offset];
    if(!p)
        return 0;
    (*offset)++;
    sprintf(dn, "ou=%s,%s", p, dc_s);
    return 1;
}

canonical_original_code:
static int get_dn_with_ad_cond(struct _ldap_cond *cond, int *offset, char *dn, char *dc_s){
    char *p = cond->ad_org_unitS[*offset];
    if(!p)
        return 0;
    (*offset)++;
    sprintf(dn, "ou=%s,%s", p, dc_s);
    return 1;
}

variable_types: struct _ldap_cond { int ad_gflag; int ad_get_udir; int ad_encrypt; char *ad_uri; char *ad_manager; char *ad_passwd; char *ad_org_unitS[1024]; } *

variable_types:
offset
int *

variable_types:
dn
char *

variable_types:
p
char *


decompiled_code:
__int64 __fastcall is_ascii_str(char *a1)
{
char v1; // al
char *v2; // rbx

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1 + 1;
while ( 1 )
{
if ( v1 < 0 )
return 0LL;
if ( isspace(v1) )
break;
v1 = *v2++;
if ( !v1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
char v1; // al
char *v2; // rbx

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1 + 1;
while ( 1 )
{
if ( v1 < 0 )
return 0LL;
if ( isspace(v1) )
break;
v1 = *v2++;
if ( !v1 )
return 1LL;
}
return 0LL;
}

original_code:
static int is_ascii_str(const char *buf){
    int i;
    for(i = 0; buf[i]; i++){
        if(!isascii(buf[i]) || isspace(buf[i]))
            return 0;
    }
    return 1;
}

canonical_original_code:
static int is_ascii_str(char *buf){
    int i;
    for(i = 0; buf[i]; i++){
        if(!isascii(buf[i]) || isspace(buf[i]))
            return 0;
    }
    return 1;
}

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall init_ad_cond(const char *a1, const char *a2)
{
char **v2; // rbx
char *v3; // rax
unsigned int v4; // edx
char *v6; // rax
char *v7; // rax
char *v8; // rax
bool v9; // zf
__int64 v10[129]; // [rsp+0h] [rbp-408h] BYREF

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
if ( !strcmp(a1, "ad_uri") && !*((_QWORD *)&ad + 1) )
{
v10[0] = 0x2F2F3A7061646CLL;
strcat((char *)v10, a2);
v6 = strdup((const char *)v10);
*((_QWORD *)&ad + 1) = v6;
v4 = -(v6 == 0LL);
}
else if ( !strcmp(a1, "ad_manager") && !*((_QWORD *)&ad + 2) )
{
v7 = strdup(a2);
*((_QWORD *)&ad + 2) = v7;
v4 = -(v7 == 0LL);
}
else if ( !strcmp(a1, "ad_passwd") && !*((_QWORD *)&ad + 3) )
{
v8 = strdup(a2);
*((_QWORD *)&ad + 3) = v8;
v4 = -(v8 == 0LL);
}
else if ( !strcmp(a1, "ad_org_unitS") )
{
if ( *((_QWORD *)&ad + 4) )
{
v2 = (char **)(unsigned int)((_DWORD)&ad + 32);
do
++v2;
while ( *v2 );
}
else
{
v2 = (char **)(unsigned int)((_DWORD)&ad + 32);
}
v3 = strdup(a2);
*v2 = v3;
v4 = -(v3 == 0LL);
}
else
{
v9 = strcmp(a1, "ad_gflag") == 0;
v4 = !v9;
if ( v9 )
{
if ( (ad & 1) == 0 )
ad |= 1u;
}
else
{
v9 = strcmp(a1, "ad_get_udir") == 0;
v4 = !v9;
if ( v9 )
{
if ( (ad & 2) == 0 )
ad |= 2u;
}
else
{
v9 = strcmp(a1, "ad_encrypt") == 0;
v4 = !v9;
if ( v9 )
ad |= 4u;
else
v4 = 0;
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
char **v2; // rbx
char *v3; // rax
unsigned int v4; // edx
char *v6; // rax
char *v7; // rax
char *v8; // rax
bool v9; // zf
__int64 v10[129]; // [rsp+0h] [rbp-408h] BYREF

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
if ( !strcmp(a1, "ad_uri") && !*((_QWORD *)&ad + 1) )
{
v10[0] = 0x2F2F3A7061646CLL;
strcat((char *)v10, a2);
v6 = strdup((const char *)v10);
*((_QWORD *)&ad + 1) = v6;
v4 = -(v6 == 0LL);
}
else if ( !strcmp(a1, "ad_manager") && !*((_QWORD *)&ad + 2) )
{
v7 = strdup(a2);
*((_QWORD *)&ad + 2) = v7;
v4 = -(v7 == 0LL);
}
else if ( !strcmp(a1, "ad_passwd") && !*((_QWORD *)&ad + 3) )
{
v8 = strdup(a2);
*((_QWORD *)&ad + 3) = v8;
v4 = -(v8 == 0LL);
}
else if ( !strcmp(a1, "ad_org_unitS") )
{
if ( *((_QWORD *)&ad + 4) )
{
v2 = (char **)(unsigned int)((_DWORD)&ad + 32);
do
++v2;
while ( *v2 );
}
else
{
v2 = (char **)(unsigned int)((_DWORD)&ad + 32);
}
v3 = strdup(a2);
*v2 = v3;
v4 = -(v3 == 0LL);
}
else
{
v9 = strcmp(a1, "ad_gflag") == 0;
v4 = !v9;
if ( v9 )
{
if ( (ad & 1) == 0 )
ad |= 1u;
}
else
{
v9 = strcmp(a1, "ad_get_udir") == 0;
v4 = !v9;
if ( v9 )
{
if ( (ad & 2) == 0 )
ad |= 2u;
}
else
{
v9 = strcmp(a1, "ad_encrypt") == 0;
v4 = !v9;
if ( v9 )
ad |= 4u;
else
v4 = 0;
}
}
}
return v4;
}

original_code:
int init_ad_cond(const char *key, const char *value){
    char buf[1024];
    char **p;
    if(!key || !value)
        return -1;
    if(!strcmp(key, "ad_uri") && !ad.ad_uri){
        strcpy(buf, "ldap://");
        strcat(buf, value);
        if((ad.ad_uri = strdup(buf)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_manager") && !ad.ad_manager){
        if((ad.ad_manager = strdup(value)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_passwd") && !ad.ad_passwd){
        if((ad.ad_passwd = strdup(value)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_org_unitS")){
        p = ad.ad_org_unitS;
        while(*p) p++;
        if((*p = strdup(value)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_gflag")){
        if(!ad.ad_gflag)
            ad.ad_gflag = 1;
    }else if(!strcmp(key, "ad_get_udir")){
        if(!ad.ad_get_udir)
            ad.ad_get_udir = 1;
    }else if(!strcmp(key, "ad_encrypt")){
        ad.ad_encrypt = 1;
    }
    return 0;
}

canonical_original_code:
int init_ad_cond(char *key, char *value){
    char buf[1024];
    char **p;
    if(!key || !value)
        return -1;
    if(!strcmp(key, "ad_uri") && !ad.ad_uri){
        strcpy(buf, "ldap://");
        strcat(buf, value);
        if((ad.ad_uri = strdup(buf)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_manager") && !ad.ad_manager){
        if((ad.ad_manager = strdup(value)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_passwd") && !ad.ad_passwd){
        if((ad.ad_passwd = strdup(value)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_org_unitS")){
        p = ad.ad_org_unitS;
        while(*p) p++;
        if((*p = strdup(value)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_gflag")){
        if(!ad.ad_gflag)
            ad.ad_gflag = 1;
    }else if(!strcmp(key, "ad_get_udir")){
        if(!ad.ad_get_udir)
            ad.ad_get_udir = 1;
    }else if(!strcmp(key, "ad_encrypt")){
        ad.ad_encrypt = 1;
    }
    return 0;
}

variable_types:
key
char *

variable_types:
value
char *


getnext

repo: omnister/piglet

decompiled_code:
__int64 __fastcall getnext(int a1)
{
__int64 i; // rax
int v2; // ecx
unsigned int v3; // edx

for ( i = offset + 1; ; ++i )
{
v2 = i;
v3 = *(char *)(pc + i - 1);
if ( v3 != 32 )
break;
if ( !a1 )
{
offset = v2;
return v3;
}
}
offset = i;
if ( !v3 )
v3 = -1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 i; // rax
int v2; // ecx
unsigned int v3; // edx

for ( i = offset + 1; ; ++i )
{
v2 = i;
v3 = *(char *)(pc + i - 1);
if ( v3 != 32 )
break;
if ( !a1 )
{
offset = v2;
return v3;
}
}
offset = i;
if ( !v3 )
v3 = -1;
return v3;
}

original_code:
int getnext(int eatblanks) {
    int c;
 while ((((c = pc[offset++]) == ' ') && eatblanks ) && c!= '\0') {
  ;
 }
    if (c !='\0') {
        return(c);
    } else {
        return((-1));
    }
}

variable_types: eatblanks int

variable_types: c int


ungetnext

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

result = (unsigned int)offset;
if ( offset > 0 )
return (unsigned int)--offset;
++errflag;
return result;
}

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

result = (unsigned int)offset;
if ( offset > 0 )
return (unsigned int)--offset;
++errflag;
return result;
}

original_code:
void ungetnext() {
    if (offset > 0) {
        offset--;
    } else {
  errflag++;
 }
}


getval

decompiled_code:
double getval()
{
int v0; // eax
double v1; // rbp
double v2; // rbx
int v3; // er12

v0 = getnext(0);
if ( (unsigned int)(v0 - 48) <= 9 || (v1 = *(double *)&LC1, v2 = *(double *)&LC0, v0 == 46) )
{
v3 = 0;
v2 = *(double *)&LC0;
v1 = *(double *)&LC1;
while ( 1 )
{
if ( v0 == 46 )
{
++v3;
v1 = *(double *)&LC1;
}
else
{
v2 = (double)(v0 - 48) + v2 * 10.0;
}
v0 = getnext(0);
if ( (unsigned int)(v0 - 48) > 9 && v0 != 46 )
break;
if ( v3 )
v1 = v1 * 10.0;
}
}
if ( v0 )
ungetnext();
return v2 / v1;
}

original_code:
double getval()
{
    double val = 0.0;
    double power = 1.0;
    int c;
    int sawpoint = 0;
    c = getnext(0);
    for (val = 0; (c >= '0' && c <= '9') || c == '.'; c = getnext(0)) {
        if (sawpoint) {
            power *= 10.0;
        }
        if (c == '.') {
            power = 1.0;
            sawpoint++;
        } else {
            val = 10 * val + (double) (c - '0');
        }
    }
    if (c != '\0') { ungetnext(); }
    return (val / power);
}

variable_types: val double

variable_types: power double

variable_types: sawpoint int

return_type: double


primary

decompiled_code:
double primary()
{
int v0; // eax
double v1; // rbx

v0 = getnext(1);
if ( (unsigned int)(v0 - 48) <= 9 || v0 == 46 )
{
ungetnext();
v1 = getval();
}
else if ( v0 == 40 )
{
v1 = expr();
if ( (unsigned int)getnext(1) != 41 )
++errflag;
}
else
{
ungetnext();
++errflag;
v1 = *(double *)&LC0;
}
return v1;
}

canonical_decompiled_code:
double func3()
{
int v0; // eax
double v1; // rbx

v0 = func0(1);
if ( (unsigned int)(v0 - 48) <= 9 || v0 == 46 )
{
func1();
v1 = func2();
}
else if ( v0 == 40 )
{
v1 = func6();
if ( (unsigned int)func0(1) != 41 )
++errflag;
}
else
{
func1();
++errflag;
v1 = *(double *)&LC0;
}
return v1;
}

original_code:
double primary(void)
{
    double val=0.0;
    int c;
 int debug=0;
    c = getnext(1);
    if ((c >= '0' && c <= '9') || c == '.') {
        ungetnext();
        val = getval();
    } else if (c == '(') {
        val = expr();
        if ((c=getnext(1)) != ')') {
   errflag++;
  }
    } else {
  ungetnext();
     if (debug) printf("error: primary read <%c> = %d\n", c, c);
  errflag++;
 }
    return (val);
}

canonical_original_code:
double primary()
{
    double val = 0.0;
    int c;
 int debug = 0;
    c = getnext(1);
    if ((c >= '0' && c <= '9') || c == '.') {
        ungetnext();
        val = getval();
    } else if (c == '(') {
        val = expr();
        if ((c=getnext(1)) != ')') {
   errflag++;
  }
    } else {
  ungetnext();
     if (debug) printf("error: primary read <%c> = %d\n", c, c);
  errflag++;
 }
    return (val);
}

variable_types: debug int


unary

decompiled_code:
__m128d __fastcall unary(__m128d result)
{
int v1; // eax

v1 = getnext(1);
if ( v1 == 43 )
{
unary();
}
else if ( v1 == 45 )
{
result.m128d_f64[0] = unary();
result = _mm_xor_pd(result, (__m128d)LC3);
}
else
{
ungetnext();
result.m128d_f64[0] = primary();
}
return result;
}

canonical_decompiled_code:
__m128d __fastcall func4(__m128d result)
{
int v1; // eax

v1 = func0(1);
if ( v1 == 43 )
{
func4();
}
else if ( v1 == 45 )
{
result.m128d_f64[0] = func4();
result = _mm_xor_pd(result, (__m128d)LC3);
}
else
{
func1();
result.m128d_f64[0] = func3();
}
return result;
}

original_code:
double unary(void)
{
    double val;
    int c;
    switch (c = getnext(1)) {
    case '+':
        val = unary();
        break;
    case '-':
        val = -unary();
        break;
    default:
        ungetnext();
        val = primary();
        break;
    }
    return (val);
}

canonical_original_code:
double unary()
{
    double val;
    int c;
    switch (c = getnext(1)) {
    case '+':
        val = unary();
        break;
    case '-':
        val = -unary();
        break;
    default:
        ungetnext();
        val = primary();
        break;
    }
    return (val);
}


mulexp

original_code:
double mulexp(void)
{
    double val;
    int c;
    val = unary();
    for (;;) {
        switch (c = getnext(1)) {
        case '*':
            val *= unary();
            break;
        case '/':
            val /= unary();
            break;
        default:
            ungetnext();
            return (val);
            break;
        }
    }
}

canonical_original_code:
double mulexp()
{
    double val;
    int c;
    val = unary();
    for (;;) {
        switch (c = getnext(1)) {
        case '*':
            val *= unary();
            break;
        case '/':
            val /= unary();
            break;
        default:
            ungetnext();
            return (val);
            break;
        }
    }
}


expr

original_code:
double expr(void)
{
    double val;
    int c;
    val = mulexp();
    for (;;) {
        switch (c = getnext(1)) {
        case '+':
            val += mulexp();
            break;
        case '-':
            val -= mulexp();
            break;
        default:
            ungetnext();
            return (val);
            break;
        }
    }
}

canonical_original_code:
double expr()
{
    double val;
    int c;
    val = mulexp();
    for (;;) {
        switch (c = getnext(1)) {
        case '+':
            val += mulexp();
            break;
        case '-':
            val -= mulexp();
            break;
        default:
            ungetnext();
            return (val);
            break;
        }
    }
}


decompiled_code:
__int64 __fastcall parse_exp(double *a1, const char *a2, __m128d a3)
{
double v3; // rbx
__int64 result; // rax

pc = (__int64)a2;
errflag = 0;
offset = 0;
v3 = expr(a3);
*a1 = v3;
if ( strlen(a2) != offset )
++errflag;
result = (unsigned int)errflag;
if ( errflag )
v3 = *(double *)&LC0;
*a1 = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(double *a1, const char *a2, __m128d a3)
{
double v3; // rbx
__int64 result; // rax

pc = (__int64)a2;
errflag = 0;
offset = 0;
v3 = func6(a3);
*a1 = v3;
if ( strlen(a2) != offset )
++errflag;
result = (unsigned int)errflag;
if ( errflag )
v3 = *(double *)&LC0;
*a1 = v3;
return result;
}

original_code:
int parse_exp(double *val, char * expression) {
        pc = expression;
 errflag=0;
 offset=0;
 *val = expr();
 if (strlen(pc)-offset) errflag++;
 if (errflag) {
  *val = 0.0;
 }
 return(errflag);
}

canonical_original_code:
int parse_exp(double *val, char *expression) {
        pc = expression;
 errflag=0;
 offset=0;
 *val = expr();
 if (strlen(pc)-offset) errflag++;
 if (errflag) {
  *val = 0.0;
 }
 return(errflag);
}

variable_types:
val
double *

variable_types:
expression
char *