decompiled_code:
__int64 __fastcall vector_sub_to(__int64 a1, int *a2, __int64 a3)
{
__int64 v4; // rdx
__int64 result; // rax
__int64 v6; // rdi
__int64 v7; // rsi
__int64 v8; // rcx

v4 = *a2;
result = a1;
if ( (int)v4 > 0 )
{
v6 = *((_QWORD *)a2 + 2);
v7 = *(_QWORD *)(a3 + 16);
v8 = *(_QWORD *)(result + 16);
for ( result = 0LL; result != v4; ++result )
*(double *)(v8 + 8 * result) = *(double *)(v6 + 8 * result) - *(double *)(v7 + 8 * result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int *a2, __int64 a3)
{
__int64 v4; // rdx
__int64 result; // rax
__int64 v6; // rdi
__int64 v7; // rsi
__int64 v8; // rcx

v4 = *a2;
result = a1;
if ( (int)v4 > 0 )
{
v6 = *((_QWORD *)a2 + 2);
v7 = *(_QWORD *)(a3 + 16);
v8 = *(_QWORD *)(result + 16);
for ( result = 0LL; result != v4; ++result )
*(double *)(v8 + 8 * result) = *(double *)(v6 + 8 * result) - *(double *)(v7 + 8 * result);
}
return result;
}

original_code:
void
vector_sub_to (vector_t *dest, const vector_t *v1, const vector_t *v2)
{
  int i, siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (v1->dimension != v1->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = v1->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = v1->coef[i] - v2->coef[i];
}

canonical_original_code:
void vector_sub_to(struct vector *dest, struct vector *v1, struct vector *v2)
{
  int i; int siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (v1->dimension != v1->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = v1->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = v1->coef[i] - v2->coef[i];
}


repo: BatchDrake/libsim

original_code:
void
vector_add_ponderated (vector_t *dest, const vector_t *orig, vectcoef_t f)
{
  int i, siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = orig->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] += f * orig->coef[i];
}

canonical_original_code:
void vector_add_ponderated(struct vector *dest, struct vector *orig, double f)
{
  int i; int siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = orig->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] += f * orig->coef[i];
}

variable_types: struct vector { int dimension; void *base; double *coef; } *

variable_types:
orig
struct vector *

variable_types: f double

variable_types: i int

variable_types: siz int

return_type: void


decompiled_code:
double *__fastcall vector_mul_by_const(unsigned int *a1, double a2)
{
double *result; // rax
double *v3; // rdx
__int64 v4; // rcx
__int64 v5; // rcx

result = (double *)*a1;
if ( (int)result > 0 )
{
v3 = (double *)*((_QWORD *)a1 + 2);
v4 = (unsigned int)((_DWORD)result - 1);
result = v3 + 1;
v5 = (__int64)&v3[v4 + 1];
while ( 1 )
{
*v3 = *v3 * a2;
v3 = result;
if ( result == (double *)v5 )
break;
++result;
}
}
return result;
}

canonical_decompiled_code:
double *__fastcall func6(unsigned int *a1, double a2)
{
double *result; // rax
double *v3; // rdx
__int64 v4; // rcx
__int64 v5; // rcx

result = (double *)*a1;
if ( (int)result > 0 )
{
v3 = (double *)*((_QWORD *)a1 + 2);
v4 = (unsigned int)((_DWORD)result - 1);
result = v3 + 1;
v5 = (__int64)&v3[v4 + 1];
while ( 1 )
{
*v3 = *v3 * a2;
v3 = result;
if ( result == (double *)v5 )
break;
++result;
}
}
return result;
}

original_code:
void
vector_mul_by_const (vector_t *dest, vectcoef_t f)
{
  int i, siz;
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] *= f;
}

canonical_original_code:
void vector_mul_by_const(struct vector *dest, double f)
{
  int i; int siz;
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] *= f;
}

user_defined_types: struct vector { int dimension; void *base; double *coef; }


original_code:
void
vector_mul_by_const_to (vector_t *dest, const vector_t *orig, vectcoef_t f)
{
  int i, siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = f * orig->coef[i];
}

canonical_original_code:
void vector_mul_by_const_to(struct vector *dest, struct vector *orig, double f)
{
  int i; int siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = f * orig->coef[i];
}


decompiled_code:
void *__fastcall vector_zero(void **a1)
{
__int64 v1; // rdx
void *result; // rax

v1 = *(int *)a1;
if ( (int)v1 > 0 )
result = memset(a1[2], 0, 8 * v1);
return result;
}

canonical_decompiled_code:
void *__fastcall func8(void **a1)
{
__int64 v1; // rdx
void *result; // rax

v1 = *(int *)a1;
if ( (int)v1 > 0 )
result = memset(a1[2], 0, 8 * v1);
return result;
}

original_code:
void
vector_zero (vector_t *dest)
{
  int i;
  int siz;
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = 0.0;
}

canonical_original_code:
void vector_zero(struct vector *dest)
{
  int i;
  int siz;
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = 0.0;
}


original_code:
void
vector_copy (vector_t *dest, const vector_t *orig)
{
  int i;
  int siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = orig->coef[i];
}

canonical_original_code:
void vector_copy(struct vector *dest, struct vector *orig)
{
  int i;
  int siz;
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = dest->dimension;
  for (i = 0; i < siz; i++)
    dest->coef[i] = orig->coef[i];
}


decompiled_code:
double *__fastcall vector_cross_product(__int64 a1, __int64 a2, __int64 a3)
{
double *v4; // rdx
double *v5; // rcx
double *result; // rax

if ( *(_DWORD *)a2 != 3 )
{
fprintf(stderr, "%s: vector is not tri-dimensional\n", "vector_cross_product");
abort();
}
v4 = *(double **)(a2 + 16);
v5 = *(double **)(a1 + 16);
result = *(double **)(a3 + 16);
*v5 = v4[1] * result[2] - v4[2] * result[1];
v5[1] = v4[2] * *result - *v4 * result[2];
v5[2] = *v4 * result[1] - v4[1] * *result;
return result;
}

canonical_decompiled_code:
double *__fastcall func11(__int64 a1, __int64 a2, __int64 a3)
{
double *v4; // rdx
double *v5; // rcx
double *result; // rax

if ( *(_DWORD *)a2 != 3 )
{
fprintf(stderr, "%s: vector is not tri-dimensional\n", "vector_cross_product");
abort();
}
v4 = *(double **)(a2 + 16);
v5 = *(double **)(a1 + 16);
result = *(double **)(a3 + 16);
*v5 = v4[1] * result[2] - v4[2] * result[1];
v5[1] = v4[2] * *result - *v4 * result[2];
v5[2] = *v4 * result[1] - v4[1] * *result;
return result;
}

original_code:
void
vector_cross_product (vector_t *dest, const vector_t *v1, const vector_t *v2)
{
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (v1->dimension != 3) { fprintf (stderr, "%s: vector is not tri-dimensional\n", __func__); abort (); };
  dest->coef[0] = v1->coef[1] * v2->coef[2] - v1->coef[2] * v2->coef[1];
  dest->coef[1] = v1->coef[2] * v2->coef[0] - v1->coef[0] * v2->coef[2];
  dest->coef[2] = v1->coef[0] * v2->coef[1] - v1->coef[1] * v2->coef[0];
}

canonical_original_code:
void vector_cross_product(struct vector *dest, struct vector *v1, struct vector *v2)
{
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (v1->dimension != 3) { fprintf (stderr, "%s: vector is not tri-dimensional\n", __func__); abort (); };
  dest->coef[0] = v1->coef[1] * v2->coef[2] - v1->coef[2] * v2->coef[1];
  dest->coef[1] = v1->coef[2] * v2->coef[0] - v1->coef[0] * v2->coef[2];
  dest->coef[2] = v1->coef[0] * v2->coef[1] - v1->coef[1] * v2->coef[0];
}


decompiled_code:
double *__fastcall vector_cross_product_ponderated(__int64 a1, __int64 a2, __int64 a3, double a4)
{
double *v5; // rdx
double *v6; // rcx
double *result; // rax

if ( *(_DWORD *)a2 != 3 )
{
fprintf(stderr, "%s: vector is not tri-dimensional\n", "vector_cross_product_ponderated");
abort();
}
v5 = *(double **)(a2 + 16);
v6 = *(double **)(a1 + 16);
result = *(double **)(a3 + 16);
*v6 = (v5[1] * result[2] - v5[2] * result[1]) * a4;
v6[1] = (v5[2] * *result - *v5 * result[2]) * a4;
v6[2] = (*v5 * result[1] - v5[1] * *result) * a4;
return result;
}

canonical_decompiled_code:
double *__fastcall func12(__int64 a1, __int64 a2, __int64 a3, double a4)
{
double *v5; // rdx
double *v6; // rcx
double *result; // rax

if ( *(_DWORD *)a2 != 3 )
{
fprintf(stderr, "%s: vector is not tri-dimensional\n", "vector_cross_product_ponderated");
abort();
}
v5 = *(double **)(a2 + 16);
v6 = *(double **)(a1 + 16);
result = *(double **)(a3 + 16);
*v6 = (v5[1] * result[2] - v5[2] * result[1]) * a4;
v6[1] = (v5[2] * *result - *v5 * result[2]) * a4;
v6[2] = (*v5 * result[1] - v5[1] * *result) * a4;
return result;
}

original_code:
void
vector_cross_product_ponderated (vector_t *dest,
                                 const vector_t *v1,
                                 const vector_t *v2,
                                 vectcoef_t f)
{
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (v1->dimension != 3) { fprintf (stderr, "%s: vector is not tri-dimensional\n", __func__); abort (); };
  dest->coef[0] = f * (v1->coef[1] * v2->coef[2] - v1->coef[2] * v2->coef[1]);
  dest->coef[1] = f * (v1->coef[2] * v2->coef[0] - v1->coef[0] * v2->coef[2]);
  dest->coef[2] = f * (v1->coef[0] * v2->coef[1] - v1->coef[1] * v2->coef[0]);
}

canonical_original_code:
void vector_cross_product_ponderated(struct vector *dest, struct vector *v1, struct vector *v2, double f)
{
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (dest->dimension != dest->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  if (v1->dimension != 3) { fprintf (stderr, "%s: vector is not tri-dimensional\n", __func__); abort (); };
  dest->coef[0] = f * (v1->coef[1] * v2->coef[2] - v1->coef[2] * v2->coef[1]);
  dest->coef[1] = f * (v1->coef[2] * v2->coef[0] - v1->coef[0] * v2->coef[2]);
  dest->coef[2] = f * (v1->coef[0] * v2->coef[1] - v1->coef[1] * v2->coef[0]);
}


original_code:
vectcoef_t
vector_norm (const vector_t *v1)
{
  int i, siz;
  vectcoef_t result = 0.0;
  siz = v1->dimension;
  for (i = 0; i < siz; i++)
    result += v1->coef[i] * v1->coef[i];
  return sqrt (result);
}

canonical_original_code:
double vector_norm(struct vector *v1)
{
  int i; int siz;
  double result = 0.0;
  siz = v1->dimension;
  for (i = 0; i < siz; i++)
    result += v1->coef[i] * v1->coef[i];
  return sqrt (result);
}

variable_types: result double

return_type: double


original_code:
vectcoef_t
vector_eucdist (const vector_t *v1, const vector_t *v2)
{
  int i, siz;
  vectcoef_t result = 0.0;
  if (v1->dimension != v1->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = v1->dimension;
  for (i = 0; i < siz; i++)
    result += (v1->coef[i] - v2->coef[i]) * (v1->coef[i] - v2->coef[i]);
  return sqrt (result);
}

canonical_original_code:
double vector_eucdist(struct vector *v1, struct vector *v2)
{
  int i; int siz;
  double result = 0.0;
  if (v1->dimension != v1->dimension) { fprintf (stderr, "%s: vector dimensions don't macht\n", __func__); abort (); };
  siz = v1->dimension;
  for (i = 0; i < siz; i++)
    result += (v1->coef[i] - v2->coef[i]) * (v1->coef[i] - v2->coef[i]);
  return sqrt (result);
}


decompiled_code:
int *__fastcall hook_bucket_new(int a1)
{
int *v1; // rax
int *v2; // r12
int *result; // rax

if ( a1 <= 0 )
{
errno_save();
fwrite(" * LibSIM error: hook.c:33: hooks < 1? wtf\n", 1uLL, 0x2BuLL, stderr);
errno_restore();
result = 0LL;
}
else
{
v1 = (int *)xmalloc(32LL * (a1 - 1) + 16);
v2 = v1;
if ( v1 )
{
*v1 = a1;
memset(v1 + 2, 0, 8LL * a1);
}
result = v2;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func0(int a1)
{
int *v1; // rax
int *v2; // r12
int *result; // rax

if ( a1 <= 0 )
{
errno_save();
fwrite(" * LibSIM error: hook.c:33: hooks < 1? wtf\n", 1uLL, 0x2BuLL, stderr);
errno_restore();
result = 0LL;
}
else
{
v1 = (int *)xmalloc(32LL * (a1 - 1) + 16);
v2 = v1;
if ( v1 )
{
*v1 = a1;
memset(v1 + 2, 0, 8LL * a1);
}
result = v2;
}
return result;
}

original_code:
struct hook_bucket *
hook_bucket_new (int hooks)
{
  struct hook_bucket *new;
  int i;
  if (hooks < 1)
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "hook.c" ":" "33" ": " "hooks < 1? wtf\n"); errno_restore (); } while (0);;
    return ((void *)0);
  }
  if ((new = xmalloc (sizeof (struct hook_bucket) +
                 sizeof (struct hook_func) * (hooks - 1))) == ((void *)0))
    return ((void *)0);
  new->hb_hook_count = hooks;
  for (i = 0; i < hooks; i++)
    new->hb_hooks[i] = ((void *)0);
  return new;
}

canonical_original_code:
struct hook_bucket *hook_bucket_new(int hooks)
{
  struct hook_bucket *new;
  int i;
  if (hooks < 1)
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "hook.c" ":" "33" ": " "hooks < 1? wtf\n"); errno_restore (); } while (0);;
    return ((void *)0);
  }
  if ((new = xmalloc (sizeof (struct hook_bucket) +
                 sizeof (struct hook_func) * (hooks - 1))) == ((void *)0))
    return ((void *)0);
  new->hb_hook_count = hooks;
  for (i = 0; i < hooks; i++)
    new->hb_hooks[i] = ((void *)0);
  return new;
}

variable_types: hooks int

variable_types: struct hook_bucket { int hb_hook_count; struct hook_func { int (*hf_func)(int, void *, void *); void *hf_data; struct hook_func *hf_next; struct hook_func *hf_prev; } *hb_hooks[1]; } *

user_defined_types: struct hook_bucket { int hb_hook_count; struct hook_func *hb_hooks[1]; }


decompiled_code:
__int64 __fastcall hook_register(int *a1, int a2, __int64 a3, __int64 a4)
{
_QWORD *v6; // rax
__int64 result; // rax

if ( a2 < 0 || *a1 <= a2 )
{
errno_save();
fprintf(stderr, " * LibSIM error: hook.c:74: code (%d) out of bounds!\n", (unsigned int)a2);
errno_restore();
result = 0xFFFFFFFFLL;
}
else
{
v6 = (_QWORD *)xmalloc(32LL);
if ( v6 )
{
*v6 = a3;
v6[1] = a4;
hook_add(a1, (unsigned int)a2, v6);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

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

if ( a2 < 0 || *a1 <= a2 )
{
errno_save();
fprintf(stderr, " * LibSIM error: hook.c:74: code (%d) out of bounds!\n", (unsigned int)a2);
errno_restore();
result = 0xFFFFFFFFLL;
}
else
{
v6 = (_QWORD *)xmalloc(32LL);
if ( v6 )
{
*v6 = a3;
v6[1] = a4;
hook_add(a1, (unsigned int)a2, v6);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int
hook_register (struct hook_bucket *bucket, int code,
               int (*func) (int, void *, void *),
               void *data)
{
  struct hook_func *cb;
  if (!(((code) >= 0) && ((code) < (bucket->hb_hook_count))))
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "hook.c" ":" "74" ": " "code (%d) out of bounds!\n", code); errno_restore (); } while (0);;
    return -1;
  }
  if ((cb = xmalloc (sizeof (struct hook_func))) == ((void *)0))
    return -1;
  cb->hf_func = func;
  cb->hf_data = data;
  hook_add (bucket, code, cb);
  return 0;
}

canonical_original_code:
int hook_register(struct hook_bucket *bucket, int code, int (*func)(int, void *, void *), void *data)
{
  struct hook_func *cb;
  if (!(((code) >= 0) && ((code) < (bucket->hb_hook_count))))
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "hook.c" ":" "74" ": " "code (%d) out of bounds!\n", code); errno_restore (); } while (0);;
    return -1;
  }
  if ((cb = xmalloc (sizeof (struct hook_func))) == ((void *)0))
    return -1;
  cb->hf_func = func;
  cb->hf_data = data;
  hook_add (bucket, code, cb);
  return 0;
}

variable_types: code int

variable_types:
func
int (*)(int, void *, void *)

variable_types:
data
void *

variable_types: struct hook_func { int (*hf_func)(int, void *, void *); void *hf_data; struct hook_func *hf_next; struct hook_func *hf_prev; } *

return_type: int


decompiled_code:
void __fastcall hook_bucket_free(void *ptr)
{
unsigned int v1; // ebx
__int64 v2; // rsi

if ( *(int *)ptr > 0 )
{
v1 = 0;
do
{
v2 = v1++;
hook_func_free(ptr, v2);
}
while ( *(_DWORD *)ptr > (signed int)v1 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
unsigned int v1; // ebx
__int64 v2; // rsi

if ( *(int *)ptr > 0 )
{
v1 = 0;
do
{
v2 = v1++;
hook_func_free(ptr, v2);
}
while ( *(_DWORD *)ptr > (signed int)v1 );
}
free(ptr);
}

original_code:
void
hook_bucket_free (struct hook_bucket *bucket)
{
  int i;
  for (i = 0; i < bucket->hb_hook_count; i++)
    hook_func_free (bucket, i);
  free (bucket);
}

canonical_original_code:
void hook_bucket_free(struct hook_bucket *bucket)
{
  int i;
  for (i = 0; i < bucket->hb_hook_count; i++)
    hook_func_free (bucket, i);
  free (bucket);
}

user_defined_types: struct hook_func { int (*hf_func)(int, void *, void *); void *hf_data; struct hook_func *hf_next; struct hook_func *hf_prev; }


decompiled_code:
__int64 __fastcall trigger_hook(int *a1, int a2, __int64 a3)
{
__int64 v3; // rbx
unsigned int v5; // er12

if ( a2 < 0 || *a1 <= a2 )
{
errno_save();
v5 = -1;
fprintf(stderr, " * LibSIM error: hook.c:131: code (%d) out of bounds!\n", (unsigned int)a2);
errno_restore();
}
else
{
v3 = *(_QWORD *)&a1[2 * a2 + 2];
if ( v3 )
{
v5 = 0;
do
{
++v5;
if ( (*(unsigned int (__fastcall **)(_QWORD, _QWORD, __int64))v3)((unsigned int)a2, *(_QWORD *)(v3 + 8), a3) == 1 )
break;
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
}
else
{
v5 = 0;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, int a2, __int64 a3)
{
__int64 v3; // rbx
unsigned int v5; // er12

if ( a2 < 0 || *a1 <= a2 )
{
errno_save();
v5 = -1;
fprintf(stderr, " * LibSIM error: hook.c:131: code (%d) out of bounds!\n", (unsigned int)a2);
errno_restore();
}
else
{
v3 = *(_QWORD *)&a1[2 * a2 + 2];
if ( v3 )
{
v5 = 0;
do
{
++v5;
if ( (*(unsigned int (__fastcall **)(_QWORD, _QWORD, __int64))v3)((unsigned int)a2, *(_QWORD *)(v3 + 8), a3) == 1 )
break;
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
}
else
{
v5 = 0;
}
}
return v5;
}

original_code:
int
trigger_hook (struct hook_bucket *bucket, int code, void *data)
{
  int acum;
  struct hook_func *func;
  if (!(((code) >= 0) && ((code) < (bucket->hb_hook_count))))
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "hook.c" ":" "131" ": " "code (%d) out of bounds!\n", code); errno_restore (); } while (0);;
    return -1;
  }
  acum = 0;
  func = bucket->hb_hooks[code];
  while (func != ((void *)0))
  {
    if ((func->hf_func) (code, func->hf_data, data) == 1)
    {
      acum++;
      break;
    }
    acum++;
    func = func->hf_next;
  }
  return acum;
}

canonical_original_code:
int trigger_hook(struct hook_bucket *bucket, int code, void *data)
{
  int acum;
  struct hook_func *func;
  if (!(((code) >= 0) && ((code) < (bucket->hb_hook_count))))
  {
    do { errno_save (); fprintf (stderr, " * LibSIM error: " "hook.c" ":" "131" ": " "code (%d) out of bounds!\n", code); errno_restore (); } while (0);;
    return -1;
  }
  acum = 0;
  func = bucket->hb_hooks[code];
  while (func != ((void *)0))
  {
    if ((func->hf_func) (code, func->hf_data, data) == 1)
    {
      acum++;
      break;
    }
    acum++;
    func = func->hf_next;
  }
  return acum;
}

variable_types: acum int


decompiled_code:
void __noreturn xalloc_die()
{
fwrite("Memoria insuficiente (interno)\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("Memoria insuficiente (interno)\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}

original_code:
static void
xalloc_die (void)
{
  fprintf (stderr, "Memoria insuficiente (interno)\n");
  exit (1);
}

canonical_original_code:
static void xalloc_die()
{
  fprintf (stderr, "Memoria insuficiente (interno)\n");
  exit (1);
}


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

result = (unsigned int)*_errno_location();
saved_errno = result;
return result;
}

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

result = (unsigned int)*_errno_location();
saved_errno = result;
return result;
}

original_code:
void errno_save ()
{
  saved_errno = (*__errno_location ());
}

canonical_original_code:
void errno_save()
{
  saved_errno = (*__errno_location ());
}


decompiled_code:
int *errno_restore()
{
int *result; // rax

result = _errno_location();
*result = saved_errno;
return result;
}

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

result = _errno_location();
*result = saved_errno;
return result;
}

original_code:
void errno_restore ()
{
  (*__errno_location ()) = saved_errno;
}

canonical_original_code:
void errno_restore()
{
  (*__errno_location ()) = saved_errno;
}


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

if ( (int)a2 >= a3 )
return 0LL;
a2 = (int)a2;
while ( 1 )
{
result = (unsigned int)a2;
if ( !*(_BYTE *)(a1 + a2) )
break;
if ( a3 <= (int)++a2 )
return 0LL;
}
return result;
}

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

if ( (int)a2 >= a3 )
return 0LL;
a2 = (int)a2;
while ( 1 )
{
result = (unsigned int)a2;
if ( !*(_BYTE *)(a1 + a2) )
break;
if ( a3 <= (int)++a2 )
return 0LL;
}
return result;
}

original_code:
int
is_asciiz(const char *buf, int lbound, int ubound)
{
  register int i;
  for (i = lbound; i < ubound; i++)
    if (!buf[i])
      return i;
  return 0;
}

canonical_original_code:
int is_asciiz(char *buf, int lbound, int ubound)
{
  register int i;
  for (i = lbound; i < ubound; i++)
    if (!buf[i])
      return i;
  return 0;
}

variable_types:
buf
char *

variable_types: lbound int

variable_types: ubound int


xmalloc

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

result = malloc(a1);
if ( !result )
xalloc_die();
return result;
}

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

result = malloc(a1);
if ( !result )
func0();
return result;
}

original_code:
void*
xmalloc (size_t size)
{
  void* m = malloc (size);
  if (m == ((void *)0))
    xalloc_die ();
  return m;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
  void *m = malloc (size);
  if (m == ((void *)0))
    xalloc_die ();
  return m;
}

variable_types:
size
unsigned long

variable_types:
m
void *

return_type: void *


xrealloc

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

result = realloc(a1, a2);
if ( !result )
xalloc_die();
return result;
}

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

result = realloc(a1, a2);
if ( !result )
func0();
return result;
}

original_code:
void*
xrealloc (void* ptr, size_t new_size)
{
  void* m = realloc (ptr, new_size);
  if (m == ((void *)0))
    xalloc_die ();
  return m;
}

canonical_original_code:
void *xrealloc(void *ptr, unsigned long new_size)
{
  void *m = realloc (ptr, new_size);
  if (m == ((void *)0))
    xalloc_die ();
  return m;
}

variable_types:
ptr
void *


vstrbuild

decompiled_code:
char *__fastcall vstrbuild(char *format, __gnuc_va_list arg)
{
int v3; // er14
char *v4; // rbp
size_t v5; // rbx
__int64 v6; // rsi
size_t v7; // rsi
int v8; // eax
int v9; // eax
_BYTE *v11; // rax

if ( !format )
return 0LL;
if ( !*format )
{
v11 = xmalloc(1uLL);
*v11 = 0;
return v11;
}
v3 = vsnprintf(0LL, 0LL, format, arg) + 1;
v4 = (char *)xmalloc(v3);
v5 = v3 + 16LL;
vsnprintf(v4, v3, format, arg);
v6 = 0LL;
while ( 1 )
{
v8 = is_asciiz((__int64)v4, v6, v3);
if ( v8 )
break;
v7 = v5;
v4 = (char *)xrealloc(v4, v5);
v5 += 16LL;
vsnprintf(v4, v7, format, arg);
v6 = (unsigned int)v3;
v3 += 16;
}
v9 = v8 + 1;
if ( v9 == v3 )
return v4;
return (char *)xrealloc(v4, v9);
}

canonical_decompiled_code:
char *__fastcall func6(char *format, __gnuc_va_list arg)
{
int v3; // er14
char *v4; // rbp
size_t v5; // rbx
__int64 v6; // rsi
size_t v7; // rsi
int v8; // eax
int v9; // eax
_BYTE *v11; // rax

if ( !format )
return 0LL;
if ( !*format )
{
v11 = func4(1uLL);
*v11 = 0;
return v11;
}
v3 = vsnprintf(0LL, 0LL, format, arg) + 1;
v4 = (char *)func4(v3);
v5 = v3 + 16LL;
vsnprintf(v4, v3, format, arg);
v6 = 0LL;
while ( 1 )
{
v8 = func3((__int64)v4, v6, v3);
if ( v8 )
break;
v7 = v5;
v4 = (char *)func5(v4, v5);
v5 += 16LL;
vsnprintf(v4, v7, format, arg);
v6 = (unsigned int)v3;
v3 += 16;
}
v9 = v8 + 1;
if ( v9 == v3 )
return v4;
return (char *)func5(v4, v9);
}

original_code:
char*
vstrbuild (const char *fmt, va_list ap)
{
  char *out;
  void *p;
  int size, zeroindex;
  int last;
  last = 0;
  if (fmt != ((void *)0))
  {
    if (!*fmt)
    {
      out = xmalloc (1);
      out[0] = '\0';
      return out;
    }
    size = vsnprintf (((void *)0), 0, fmt, ap) + 1;
    out = xmalloc (size);
    vsnprintf (out, size, fmt, ap);
    for(;;)
    {
      if ((zeroindex = is_asciiz (out, last, size)) != 0)
      {
        if (zeroindex + 1 == size)
          return out;
        p = xrealloc (out, zeroindex + 1);
        return (char *) p;
      }
      last = size;
      size += 16;
      p = xrealloc (out, size);
      out = (char *) p;
      vsnprintf (out, size, fmt, ap);
    }
  }
  else
    out = ((void *)0);
  return out;
}

canonical_original_code:
char *vstrbuild(char *fmt, __builtin_va_list ap)
{
  char *out;
  void *p;
  int size; int zeroindex;
  int last;
  last = 0;
  if (fmt != ((void *)0))
  {
    if (!*fmt)
    {
      out = xmalloc (1);
      out[0] = '\0';
      return out;
    }
    size = vsnprintf (((void *)0), 0, fmt, ap) + 1;
    out = xmalloc (size);
    vsnprintf (out, size, fmt, ap);
    for(;;)
    {
      if ((zeroindex = is_asciiz (out, last, size)) != 0)
      {
        if (zeroindex + 1 == size)
          return out;
        p = xrealloc (out, zeroindex + 1);
        return (char *) p;
      }
      last = size;
      size += 16;
      p = xrealloc (out, size);
      out = (char *) p;
      vsnprintf (out, size, fmt, ap);
    }
  }
  else
    out = ((void *)0);
  return out;
}

variable_types:
fmt
char *

variable_types:
out
char *

variable_types:
p
void *

variable_types: size int

variable_types: zeroindex int

variable_types: last int

return_type: char *


strbuild

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

va_start(arg, a1);
return vstrbuild(a1, arg);
}

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

va_start(arg, a1);
return func6(a1, arg);
}

original_code:
char*
strbuild (const char *fmt, ...)
{
  char *out;
  va_list ap;
  __builtin_va_start(ap,fmt);
  out = vstrbuild (fmt, ap);
  __builtin_va_end(ap);
  return out;
}

canonical_original_code:
char *strbuild(char *fmt, ...)
{
  char *out;
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  out = vstrbuild (fmt, ap);
  __builtin_va_end(ap);
  return out;
}


xstrdup

decompiled_code:
char *__fastcall xstrdup(char *src)
{
size_t v1; // rax
char *v2; // rax

if ( !src )
return 0LL;
v1 = strlen(src);
v2 = (char *)xmalloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func8(char *src)
{
size_t v1; // rax
char *v2; // rax

if ( !src )
return 0LL;
v1 = strlen(src);
v2 = (char *)func4(v1 + 1);
return strcpy(v2, src);
}

original_code:
char *
xstrdup (const char *str)
{
  char *ret;
  if (str != ((void *)0))
    {
      ret = xmalloc (strlen (str) + 1);
      strcpy (ret, str);
    }
  else
    ret = ((void *)0);
  return ret;
}

canonical_original_code:
char *xstrdup(char *str)
{
  char *ret;
  if (str != ((void *)0))
    {
      ret = xmalloc (strlen (str) + 1);
      strcpy (ret, str);
    }
  else
    ret = ((void *)0);
  return ret;
}

variable_types:
str
char *

variable_types:
ret
char *


original_code:
void
ptr_list_append (void ***list, int *count, void *new)
{
  int i;
  for (i = 0; i < *count; i++)
    if ((*list)[i] == ((void *)0))
      break;
  if (i == *count)
    *list = xrealloc (*list, ++*count * sizeof (void *));
  (*list)[i] = new;
}

canonical_original_code:
void ptr_list_append(void ***list, int *count, void *new)
{
  int i;
  for (i = 0; i < *count; i++)
    if ((*list)[i] == ((void *)0))
      break;
  if (i == *count)
    *list = xrealloc (*list, ++*count * sizeof (void *));
  (*list)[i] = new;
}

variable_types:
list
void ***

variable_types:
count
int *

variable_types:
new
void *

variable_types: i int


decompiled_code:
__int64 __fastcall ptr_list_remove_first(_QWORD **a1, int *a2, __int64 a3)
{
int v3; // esi
_QWORD *v4; // rax
__int64 v5; // rsi

v3 = *a2;
if ( v3 <= 0 )
return 0LL;
v4 = *a1;
v5 = (__int64)&(*a1)[(unsigned int)(v3 - 1) + 1];
while ( *v4 != a3 && a3 )
{
if ( ++v4 == (_QWORD *)v5 )
return 0LL;
}
*v4 = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD **a1, int *a2, __int64 a3)
{
int v3; // esi
_QWORD *v4; // rax
__int64 v5; // rsi

v3 = *a2;
if ( v3 <= 0 )
return 0LL;
v4 = *a1;
v5 = (__int64)&(*a1)[(unsigned int)(v3 - 1) + 1];
while ( *v4 != a3 && a3 )
{
if ( ++v4 == (_QWORD *)v5 )
return 0LL;
}
*v4 = 0LL;
return 1LL;
}

original_code:
int
ptr_list_remove_first (void ***list, int *count, void *ptr)
{
  int i;
  int found;
  found = 0;
  for (i = 0; i < *count; i++)
    if ((*list)[i] == ptr || ptr == ((void *)0))
    {
      (*list)[i] = ((void *)0);
      found++;
      break;
    }
  return found;
}

canonical_original_code:
int ptr_list_remove_first(void ***list, int *count, void *ptr)
{
  int i;
  int found;
  found = 0;
  for (i = 0; i < *count; i++)
    if ((*list)[i] == ptr || ptr == ((void *)0))
    {
      (*list)[i] = ((void *)0);
      found++;
      break;
    }
  return found;
}

variable_types: found int


decompiled_code:
__int64 __fastcall ptr_list_remove_all(_QWORD *a1, int *a2, __int64 a3)
{
__int64 v5; // rcx
bool v6; // r9
__int64 v7; // rcx
__int64 v8; // rax
unsigned int v9; // er8
_QWORD *v10; // rdx

v5 = *a2;
if ( (int)v5 <= 0 )
return 0LL;
v6 = a3 == 0;
v7 = 8 * v5;
v8 = 0LL;
v9 = 0;
do
{
while ( 1 )
{
v10 = (_QWORD *)(v8 + *a1);
if ( *v10 == a3 || v6 )
break;
v8 += 8LL;
if ( v7 == v8 )
return v9;
}
v8 += 8LL;
*v10 = 0LL;
++v9;
}
while ( v7 != v8 );
return v9;
}

original_code:
int
ptr_list_remove_all (void ***list, int *count, void *ptr)
{
  int i;
  int found;
  found = 0;
  for (i = 0; i < *count; i++)
    if ((*list)[i] == ptr || ptr == ((void *)0))
    {
      (*list)[i] = ((void *)0);
      found++;
    }
  return found;
}

canonical_original_code:
int ptr_list_remove_all(void ***list, int *count, void *ptr)
{
  int i;
  int found;
  found = 0;
  for (i = 0; i < *count; i++)
    if ((*list)[i] == ptr || ptr == ((void *)0))
    {
      (*list)[i] = ((void *)0);
      found++;
    }
  return found;
}


decompiled_code:
char *__fastcall read_line(int fd)
{
char *i; // r12
char *v2; // rax
char *v3; // rdi
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

for ( i = 0LL; ; i = v2 )
{
do
{
if ( read(fd, buf, 1uLL) <= 0 )
return i;
}
while ( buf[0] == 13 );
if ( buf[0] == 10 )
break;
v2 = str_append_char(i, buf[0]);
if ( !v2 )
{
v3 = i;
i = 0LL;
free(v3);
return i;
}
}
if ( i )
return i;
return strdup(&s);
}

canonical_decompiled_code:
char *__fastcall func12(int fd)
{
char *i; // r12
char *v2; // rax
char *v3; // rdi
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

for ( i = 0LL; ; i = v2 )
{
do
{
if ( read(fd, buf, 1uLL) <= 0 )
return i;
}
while ( buf[0] == 13 );
if ( buf[0] == 10 )
break;
v2 = str_append_char(i, buf[0]);
if ( !v2 )
{
v3 = i;
i = 0LL;
free(v3);
return i;
}
}
if ( i )
return i;
return strdup(&s);
}

original_code:
char *
read_line (int fd)
{
  char c;
  char *line;
  char *nptr;
  line = ((void *)0);
  for (;;)
  {
    if (read (fd, &c, 1) < 1)
      return line;
    if (c == '\r')
      continue;
    if (c == '\n')
    {
      if (line == ((void *)0))
        line = strdup ("");
      return line;
    }
    if ( (nptr = str_append_char (line, c)) == ((void *)0))
    {
      free (line);
      return ((void *)0);
    }
    line = nptr;
  }
  return ((void *)0);
}

canonical_original_code:
char *read_line(int fd)
{
  char c;
  char *line;
  char *nptr;
  line = ((void *)0);
  for (;;)
  {
    if (read (fd, &c, 1) < 1)
      return line;
    if (c == '\r')
      continue;
    if (c == '\n')
    {
      if (line == ((void *)0))
        line = strdup ("");
      return line;
    }
    if ( (nptr = str_append_char (line, c)) == ((void *)0))
    {
      free (line);
      return ((void *)0);
    }
    line = nptr;
  }
  return ((void *)0);
}

variable_types: fd int

variable_types: c char

variable_types:
line
char *

variable_types:
nptr
char *


decompiled_code:
__int64 __fastcall get_color(int a1, int a2, char a3)
{
unsigned int v4; // er8
int i; // edx
int v6; // eax
char v7; // cl

v4 = 0;
if ( a2 )
{
for ( i = 0; i != a2; ++i )
{
v6 = a1 >> (i + a3);
v7 = i;
v4 |= (v6 & 1) << v7;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, char a3)
{
unsigned int v4; // er8
int i; // edx
int v6; // eax
char v7; // cl

v4 = 0;
if ( a2 )
{
for ( i = 0; i != a2; ++i )
{
v6 = a1 >> (i + a3);
v7 = i;
v4 |= (v6 & 1) << v7;
}
}
return v4;
}

original_code:
static inline int get_color (int color, int bpp, int bit_off)
{
  int i;
  int result;
  for (result = 0, i = 0; i < bpp; i++)
    result |= (!!(color & (1 << (i + bit_off)))) << i;
  return result;
}

canonical_original_code:
static inline int get_color(int color, int bpp, int bit_off)
{
  int i;
  int result;
  for (result = 0, i = 0; i < bpp; i++)
    result |= (!!(color & (1 << (i + bit_off)))) << i;
  return result;
}

variable_types: color int

variable_types: bpp int

variable_types: result int


repo: BenjaminVanRyseghem/ASE

decompiled_code:
void __noreturn do_xit()
{
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
exit(0);
}

original_code:
static void
do_xit()
{
    exit(0);
}

canonical_original_code:
static void do_xit()
{
    exit(0);
}


xit

decompiled_code:
void __noreturn xit()
{
do_xit();
}

canonical_decompiled_code:
void __noreturn func1()
{
func0();
}

original_code:
static void
xit(struct _cmd *dummy)
{
    do_xit();
}

variable_types: struct _cmd { char *name; void (*fun)(struct _cmd *c); char *comment; } *


help

decompiled_code:
int help()
{
const char *v0; // rsi
char **v1; // rbx
const char *v2; // rdx
int result; // eax

v0 = commands;
if ( commands )
{
v1 = &commands;
do
{
v2 = v1[2];
v1 += 3;
result = printf("%s\t-- %s\n", v0, v2);
v0 = *v1;
}
while ( *v1 );
}
return result;
}

canonical_decompiled_code:
int func2()
{
const char *v0; // rsi
char **v1; // rbx
const char *v2; // rdx
int result; // eax

v0 = commands;
if ( commands )
{
v1 = &commands;
do
{
v2 = v1[2];
v1 += 3;
result = printf("%s\t-- %s\n", v0, v2);
v0 = *v1;
}
while ( *v1 );
}
return result;
}

original_code:
static void
help(struct _cmd *dummy)
{
    struct _cmd *c = commands;
    for (; c->name; c++)
 printf ("%s\t-- %s\n", c->name, c->comment);
}

user_defined_types: struct _cmd { char *name; void (*fun)(struct _cmd *c); char *comment; }


execute

decompiled_code:
__int64 __fastcall execute(char *s1)
{
char **v1; // rbp
const char *i; // rsi

v1 = &commands;
for ( i = commands; i; v1 += 3 )
{
if ( !strcmp(s1, i) )
break;
i = v1[3];
}
return ((__int64 (__fastcall *)(char **))v1[1])(v1);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s1)
{
char **v1; // rbp
const char *i; // rsi

v1 = &commands;
for ( i = commands; i; v1 += 3 )
{
if ( !strcmp(s1, i) )
break;
i = v1[3];
}
return ((__int64 (__fastcall *)(char **))v1[1])(v1);
}

original_code:
static void
execute(const char *name)
{
    struct _cmd *c = commands;
    while (c->name && strcmp (name, c->name))
 c++;
    (*c->fun)(c);
}

canonical_original_code:
static void execute(char *name)
{
    struct _cmd *c = commands;
    while (c->name && strcmp (name, c->name))
 c++;
    (*c->fun)(c);
}

variable_types:
name
char *


loop

decompiled_code:
__int64 loop()
{
__int64 result; // rax
char v1[72]; // [rsp+0h] [rbp-48h] BYREF

while ( 1 )
{
printf("> ");
result = _isoc99_scanf("%62s", v1);
if ( (_DWORD)result != 1 )
break;
execute(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
char v1[72]; // [rsp+0h] [rbp-48h] BYREF

while ( 1 )
{
printf("> ");
result = _isoc99_scanf("%62s", v1);
if ( (_DWORD)result != 1 )
break;
func3(v1);
}
return result;
}

original_code:
static void
loop(void)
{
    char name[64];
    while (printf("> "), scanf("%62s", name) == 1)
 execute(name) ;
}

canonical_original_code:
static void loop()
{
    char name[64];
    while (printf("> "), scanf("%62s", name) == 1)
 execute(name) ;
}

variable_types:
name
char [64]


decompiled_code:
int __fastcall none(__int64 a1)
{
return puts(*(const char **)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
return puts(*(const char **)(a1 + 16));
}

original_code:
static void
none(struct _cmd *c)
{
    printf ("%s\n", c->comment) ;
}


decompiled_code:
__int64 edit_volume()
{
save_super();
interactive_set_current_volume();
return load_super();
}

canonical_decompiled_code:
__int64 func6()
{
save_super();
interactive_set_current_volume();
return load_super();
}

original_code:
static void
edit_volume(struct _cmd *c)
{
 save_super();
 interactive_set_current_volume();
 load_super();
}


newbloc

decompiled_code:
__int64 newbloc()
{
return new_bloc();
}

canonical_decompiled_code:
__int64 func7()
{
return new_bloc();
}

original_code:
static void
newbloc(struct _cmd *c)
{
 new_bloc();
}


save

decompiled_code:
__int64 save()
{
return save_mbr();
}

canonical_decompiled_code:
__int64 func9()
{
return save_mbr();
}

original_code:
static void
save(struct _cmd *c)
{
 save_mbr();
}


quit

decompiled_code:
void __noreturn quit()
{
save();
exit(0);
}

canonical_decompiled_code:
void __noreturn func10()
{
func9();
exit(0);
}

original_code:
static void
quit(struct _cmd *c)
{
 save(c);
    exit(0);
}


del

decompiled_code:
__int64 del()
{
return interactive_delete_volume();
}

canonical_decompiled_code:
__int64 func11()
{
return interactive_delete_volume();
}

original_code:
static void
del(struct _cmd *c)
{
 interactive_delete_volume();
}


new

decompiled_code:
__int64 new()
{
return interactive_create_new_volume();
}

canonical_decompiled_code:
__int64 func12()
{
return interactive_create_new_volume();
}

original_code:
static void
new(struct _cmd *c)
{
 interactive_create_new_volume();
}


list

decompiled_code:
__int64 list()
{
return dfs();
}

canonical_decompiled_code:
__int64 func13()
{
return dfs();
}

original_code:
static void
list(struct _cmd *c)
{
 dfs();
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
init(argc, argv, envp);
loop();
do_xit();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
init(argc, argv, envp);
func4();
func0();
}

original_code:
int
main(int argc, char **argv)
{
 init();
    loop();
    do_xit();
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
void empty_it()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void empty_it(){
    return;
}

canonical_original_code:
static void empty_it(){
    return;
}


decompiled_code:
__int64 __fastcall retrieve_type_from_string(const char *a1)
{
unsigned int v1; // er8

v1 = 0;
if ( strcmp(a1, "VT_BASE") )
{
v1 = 1;
if ( strcmp(a1, "VT_ANX") )
v1 = strcmp(a1, "VT_OTH") == 0 ? 2 : -1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
unsigned int v1; // er8

v1 = 0;
if ( strcmp(a1, "VT_BASE") )
{
v1 = 1;
if ( strcmp(a1, "VT_ANX") )
v1 = strcmp(a1, "VT_OTH") == 0 ? 2 : -1;
}
return v1;
}

original_code:
enum vd_type_e retrieve_type_from_string(char *buffer){
 if (!strcmp(buffer, "VT_BASE")) return VT_BASE;
 if (!strcmp(buffer, "VT_ANX")) return VT_ANX;
 if (!strcmp(buffer, "VT_OTH")) return VT_OTH;
 return -1;
}

variable_types:
buffer
char *

return_type: enum vd_type_e { VT_BASE=0, VT_ANX=1, VT_OTH=2 }


decompiled_code:
__int64 __fastcall delete_volume(unsigned int a1)
{
int v1; // ebx
__int64 result; // rax

v1 = mbr[0];
if ( mbr[0] <= a1 )
{
fwrite("Can't delete this volume, the index is wrong\n", 1uLL, 0x2DuLL, stderr);
result = 1LL;
}
else
{
if ( mbr[0] > a1 + 1 )
memmove(&mbr[4 * (a1 + 1) - 3], &mbr[4 * (a1 + 1) + 1], 16 * (mbr[0] - 2 - a1 + 1LL));
result = 0LL;
mbr[0] = v1 - 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
int v1; // ebx
__int64 result; // rax

v1 = mbr[0];
if ( mbr[0] <= a1 )
{
fwrite("Can't delete this volume, the index is wrong\n", 1uLL, 0x2DuLL, stderr);
result = 1LL;
}
else
{
if ( mbr[0] > a1 + 1 )
memmove(&mbr[4 * (a1 + 1) - 3], &mbr[4 * (a1 + 1) + 1], 16 * (mbr[0] - 2 - a1 + 1LL));
result = 0LL;
mbr[0] = v1 - 1;
}
return result;
}

original_code:
int delete_volume(unsigned int vol){
 int i;
 if (vol<0 || vol >= mbr.mbr_nvol){
  fprintf(stderr, "Can't delete this volume, the index is wrong\n");
  return 1;
 }
 for ( i = vol+1 ; i < mbr.mbr_nvol; i ++){
  mbr.mbr_vols[i-1] = mbr.mbr_vols[i];
 }
 mbr.mbr_nvol--;
 return 0;
}

variable_types:
vol
unsigned int


decompiled_code:
__int64 interactive_delete_volume()
{
int v0; // er8
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

puts("Please enter the volume index to remove:");
v0 = _isoc99_scanf("%i", v2);
result = 1LL;
if ( v0 )
result = delete_volume(v2[0]);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // er8
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

puts("Please enter the volume index to remove:");
v0 = _isoc99_scanf("%i", v2);
result = 1LL;
if ( v0 )
result = func2(v2[0]);
return result;
}

original_code:
int interactive_delete_volume(){
 unsigned int vol;
 printf("Please enter the volume index to remove:\n");
 if(scanf("%i",&vol) == 0) return 1;
 return delete_volume(vol);
}


decompiled_code:
int __fastcall read_sector(unsigned int a1, unsigned int a2, __int64 a3)
{
return read_sector_n(a1, a2, a3, 0x200u);
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1, unsigned int a2, __int64 a3)
{
return func5(a1, a2, a3, 0x200u);
}

original_code:
void read_sector(unsigned int cyl, unsigned int sect, unsigned char *buffer){
 read_sector_n(cyl, sect, buffer, 512);
}

variable_types:
cyl
unsigned int

variable_types:
sect
unsigned int

variable_types:
buffer
unsigned char *


decompiled_code:
int __fastcall format_sector(unsigned int a1, unsigned int a2, int a3, unsigned __int8 a4)
{
unsigned __int64 v4; // rax
unsigned int v5; // ebp
unsigned int v6; // ebx
unsigned int v7; // esi
_QWORD v9[69]; // [rsp+0h] [rbp-228h] BYREF

v4 = 0x101010101010101LL * a4;
v5 = a2 + a3;
memset64(v9, v4, 0x40uLL);
if ( a2 < a2 + a3 )
{
v6 = a2;
do
{
v7 = v6++;
LODWORD(v4) = write_sector(a1, v7, (__int64)v9);
}
while ( v5 > v6 );
}
return v4;
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, unsigned int a2, int a3, unsigned __int8 a4)
{
unsigned __int64 v4; // rax
unsigned int v5; // ebp
unsigned int v6; // ebx
unsigned int v7; // esi
_QWORD v9[69]; // [rsp+0h] [rbp-228h] BYREF

v4 = 0x101010101010101LL * a4;
v5 = a2 + a3;
memset64(v9, v4, 0x40uLL);
if ( a2 < a2 + a3 )
{
v6 = a2;
do
{
v7 = v6++;
LODWORD(v4) = func7(a1, v7, (__int64)v9);
}
while ( v5 > v6 );
}
return v4;
}

original_code:
void format_sector(unsigned int cylinder, unsigned int sector, unsigned int nsector, unsigned int value){
 int i;
 unsigned char buffer[512];
 for (i = 0; i < 512 ; i ++){
  buffer[i] = value;
 }
 for(i = sector ; i < (sector + nsector) ; i++){
  write_sector(cylinder,i,buffer);
 }
}

variable_types:
cylinder
unsigned int

variable_types:
sector
unsigned int

variable_types:
nsector
unsigned int

variable_types:
value
unsigned int

variable_types: i int

variable_types:
buffer
unsigned char [512]


format

decompiled_code:
int format()
{
unsigned int i; // ebx
int result; // eax

for ( i = 0; i != 16; ++i )
result = format_sector(i, 0, 16, 0);
return result;
}

canonical_decompiled_code:
int func9()
{
unsigned int i; // ebx
int result; // eax

for ( i = 0; i != 16; ++i )
result = func8(i, 0, 16, 0);
return result;
}

original_code:
void format(){
 int i;
 for(i = 0 ; i < 16; i ++){
  format_sector(i, 0, 16, 0);
 }
}


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

read_sector_n(0, 0, (__int64)mbr, 0x88u);
result = 0LL;
if ( mbr[33] != 51966 )
{
mbr[0] = 0;
result = 1LL;
mbr[33] = 51966;
}
return result;
}

original_code:
int load_mbr(){
 read_sector_n(0,0, ((unsigned char*)(&mbr)), sizeof(struct mbr_s));
 if(mbr.mbr_magic == 0xCAFE){
  return 0;
 }
 mbr.mbr_nvol = 0;
 mbr.mbr_magic = 0xCAFE;
 return 1;
}

canonical_original_code:
int load_mbr(){
 read_sector_n(0,0, ((unsigned char *)(&mbr)), sizeof(struct mbr_s));
 if(mbr.mbr_magic == 0xCAFE){
  return 0;
 }
 mbr.mbr_nvol = 0;
 mbr.mbr_magic = 0xCAFE;
 return 1;
}

user_defined_types: struct mbr_s { unsigned int mbr_nvol; struct vd_descr_s mbr_vols[8]; unsigned int mbr_magic; }

user_defined_types: struct vd_descr_s { unsigned int vd_first_sector; unsigned int vd_first_cylinder; unsigned int vd_n_sector; enum vd_type_e vd_val_type; }

user_defined_types: enum vd_type_e { VT_BASE=0, VT_ANX=1, VT_OTH=2 }


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

if ( a1 < 0 || mbr[0] < (unsigned int)a1 )
{
fwrite("Wrong volume number\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
if ( a2 < 0 || (v2 = 4LL * a1, a1 > (unsigned int)mbr[v2 + 3]) )
{
fwrite("Wrong bloc number\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
return mbr[v2 + 2] + ((unsigned int)(a2 + mbr[v2 + 1]) >> 4);
}

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

if ( a1 < 0 || mbr[0] < (unsigned int)a1 )
{
fwrite("Wrong volume number\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
if ( a2 < 0 || (v2 = 4LL * a1, a1 > (unsigned int)mbr[v2 + 3]) )
{
fwrite("Wrong bloc number\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
return mbr[v2 + 2] + ((unsigned int)(a2 + mbr[v2 + 1]) >> 4);
}

original_code:
unsigned cylinder_of_bloc(int vol, int n_bloc){
 if (vol<0 || vol > mbr.mbr_nvol){
  fprintf(stderr, "Wrong volume number\n");
  exit(1);
 }
 if (n_bloc<0 || vol > mbr.mbr_vols[vol].vd_n_sector){
  fprintf(stderr, "Wrong bloc number\n");
  exit(1);
 }
 unsigned fc = mbr.mbr_vols[vol].vd_first_cylinder;
 unsigned fs = mbr.mbr_vols[vol].vd_first_sector;
 return (fc+(fs+n_bloc)/16);
}

canonical_original_code:
unsigned int cylinder_of_bloc(int vol, int n_bloc){
 if (vol<0 || vol > mbr.mbr_nvol){
  fprintf(stderr, "Wrong volume number\n");
  exit(1);
 }
 if (n_bloc<0 || vol > mbr.mbr_vols[vol].vd_n_sector){
  fprintf(stderr, "Wrong bloc number\n");
  exit(1);
 }
 unsigned int fc = mbr.mbr_vols[vol].vd_first_cylinder;
 unsigned int fs = mbr.mbr_vols[vol].vd_first_sector;
 return (fc+(fs+n_bloc)/16);
}

variable_types: vol int

variable_types:
fc
unsigned int

variable_types:
fs
unsigned int

return_type: unsigned int


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

if ( a1 < 0 || mbr[0] < (unsigned int)a1 )
{
fwrite("Wrong volume number\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
if ( a2 < 0 || (v2 = 4LL * a1, a1 > (unsigned int)mbr[v2 + 3]) )
{
fwrite("Wrong bloc number\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
return (LOBYTE(mbr[v2 + 1]) + (_BYTE)a2) & 0xF;
}

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

if ( a1 < 0 || mbr[0] < (unsigned int)a1 )
{
fwrite("Wrong volume number\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
if ( a2 < 0 || (v2 = 4LL * a1, a1 > (unsigned int)mbr[v2 + 3]) )
{
fwrite("Wrong bloc number\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
return (LOBYTE(mbr[v2 + 1]) + (_BYTE)a2) & 0xF;
}

original_code:
unsigned sector_of_bloc(int vol, int n_bloc){
 if (vol<0 || vol > mbr.mbr_nvol){
  fprintf(stderr, "Wrong volume number\n");
  exit(1);
 }
 if (n_bloc<0 || vol > mbr.mbr_vols[vol].vd_n_sector){
  fprintf(stderr, "Wrong bloc number\n");
  exit(1);
 }
 unsigned fs = mbr.mbr_vols[vol].vd_first_sector;
 return ((fs+n_bloc)%16);
}

canonical_original_code:
unsigned int sector_of_bloc(int vol, int n_bloc){
 if (vol<0 || vol > mbr.mbr_nvol){
  fprintf(stderr, "Wrong volume number\n");
  exit(1);
 }
 if (n_bloc<0 || vol > mbr.mbr_vols[vol].vd_n_sector){
  fprintf(stderr, "Wrong bloc number\n");
  exit(1);
 }
 unsigned int fs = mbr.mbr_vols[vol].vd_first_sector;
 return ((fs+n_bloc)%16);
}


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

v4 = cylinder_of_bloc(a1, a2);
v5 = sector_of_bloc(a1, a2);
return read_sector(v4, v5, a3);
}

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

v4 = func12(a1, a2);
v5 = func13(a1, a2);
return func6(v4, v5, a3);
}

original_code:
void read_bloc(int vol, int n_bloc, unsigned char* buffer){
 unsigned int cyl = cylinder_of_bloc(vol, n_bloc);
 unsigned int sec = sector_of_bloc(vol, n_bloc);
 read_sector(cyl, sec, buffer);
}

canonical_original_code:
void read_bloc(int vol, int n_bloc, unsigned char *buffer){
 unsigned int cyl = cylinder_of_bloc(vol, n_bloc);
 unsigned int sec = sector_of_bloc(vol, n_bloc);
 read_sector(cyl, sec, buffer);
}

variable_types:
sec
unsigned int


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

v4 = cylinder_of_bloc(a1, a2);
v5 = sector_of_bloc(a1, a2);
return write_sector(v4, v5, a3);
}

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

v4 = func12(a1, a2);
v5 = func13(a1, a2);
return func7(v4, v5, a3);
}

original_code:
void write_bloc(unsigned int vol, unsigned int n_bloc, const unsigned char *buffer){
 unsigned int cyl = cylinder_of_bloc(vol, n_bloc);
 unsigned int sec = sector_of_bloc(vol, n_bloc);
 write_sector(cyl, sec, buffer);
}

canonical_original_code:
void write_bloc(unsigned int vol, unsigned int n_bloc, unsigned char *buffer){
 unsigned int cyl = cylinder_of_bloc(vol, n_bloc);
 unsigned int sec = sector_of_bloc(vol, n_bloc);
 write_sector(cyl, sec, buffer);
}


decompiled_code:
int __fastcall format_vol(int a1)
{
return format_sector(mbr[4 * a1 + 2], mbr[4 * a1 + 1], mbr[4 * a1 + 3], 0);
}

canonical_decompiled_code:
int __fastcall func16(int a1)
{
return func8(mbr[4 * a1 + 2], mbr[4 * a1 + 1], mbr[4 * a1 + 3], 0);
}

original_code:
void format_vol(unsigned int vol){
 int n_bloc = mbr.mbr_vols[vol].vd_n_sector;
 unsigned int cyl = mbr.mbr_vols[vol].vd_first_cylinder;
 unsigned int sec = mbr.mbr_vols[vol].vd_first_sector;
 format_sector(cyl, sec, n_bloc, 0);
}


decompiled_code:
int __fastcall printf_vol(unsigned int a1)
{
__int64 v1; // rbx
char *v2; // rax
unsigned int v3; // er12
unsigned int v4; // eax

v1 = 4LL * a1;
printf("Volume %d:\n", a1);
printf("\tsize: %d\n", (unsigned int)mbr[v1 + 3]);
printf("\t(fc, fs):(%d,%d)\n", (unsigned int)mbr[v1 + 2], (unsigned int)mbr[v1 + 1]);
v2 = printType(mbr[v1 + 4]);
printf("\ttype: %s\n", v2);
v3 = sector_of_bloc(a1, mbr[v1 + 3] - 1);
v4 = cylinder_of_bloc(a1, mbr[v1 + 3]);
return printf("\t(lc,ls); (%d,%d)\n\n", v4, v3);
}

canonical_decompiled_code:
int __fastcall func18(unsigned int a1)
{
__int64 v1; // rbx
char *v2; // rax
unsigned int v3; // er12
unsigned int v4; // eax

v1 = 4LL * a1;
printf("Volume %d:\n", a1);
printf("\tsize: %d\n", (unsigned int)mbr[v1 + 3]);
printf("\t(fc, fs):(%d,%d)\n", (unsigned int)mbr[v1 + 2], (unsigned int)mbr[v1 + 1]);
v2 = func17(mbr[v1 + 4]);
printf("\ttype: %s\n", v2);
v3 = func13(a1, mbr[v1 + 3] - 1);
v4 = func12(a1, mbr[v1 + 3]);
return printf("\t(lc,ls); (%d,%d)\n\n", v4, v3);
}

original_code:
void printf_vol(unsigned int i){
 printf("Volume %d:\n",i);
  printf("\tsize: %d\n",mbr.mbr_vols[i].vd_n_sector);
  printf("\t(fc, fs):(%d,%d)\n",mbr.mbr_vols[i].vd_first_cylinder,mbr.mbr_vols[i].vd_first_sector);
  printf("\ttype: %s\n", printType(mbr.mbr_vols[i].vd_val_type));
  printf("\t(lc,ls); (%d,%d)\n\n",cylinder_of_bloc(i, mbr.mbr_vols[i].vd_n_sector), sector_of_bloc(i,mbr.mbr_vols[i].vd_n_sector-1));
}

variable_types:
i
unsigned int


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

if ( mbr[0] == 8 )
{
fwrite("Max number of volumes reached\n", 1uLL, 0x1EuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v4 = 4LL * (unsigned int)mbr[0];
mbr[v4 + 1] = a1;
mbr[v4 + 2] = a2;
mbr[v4 + 3] = a3;
mbr[v4 + 4] = a4;
printf("%d, %d, %d\n\n", a2, a1, a3);
printf_vol(mbr[0]);
result = (unsigned int)mbr[0]++;
}
return result;
}

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

if ( mbr[0] == 8 )
{
fwrite("Max number of volumes reached\n", 1uLL, 0x1EuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v4 = 4LL * (unsigned int)mbr[0];
mbr[v4 + 1] = a1;
mbr[v4 + 2] = a2;
mbr[v4 + 3] = a3;
mbr[v4 + 4] = a4;
printf("%d, %d, %d\n\n", a2, a1, a3);
func18(mbr[0]);
result = (unsigned int)mbr[0]++;
}
return result;
}

original_code:
int create_new_volume(unsigned f_s, unsigned f_c, unsigned n_s, enum vd_type_e type){
 if(mbr.mbr_nvol == 8){
  fprintf(stderr, "Max number of volumes reached\n");
  return -1;
 }
 struct vd_descr_s new_vol;
 new_vol.vd_first_sector = f_s;
 new_vol.vd_first_cylinder = f_c;
 new_vol.vd_n_sector = n_s;
 new_vol.vd_val_type = type;
 mbr.mbr_vols[mbr.mbr_nvol] = new_vol;
 printf("%d, %d,  %d\n\n",f_c,f_s,n_s);
 printf_vol(mbr.mbr_nvol);
 return mbr.mbr_nvol++;
}

canonical_original_code:
int create_new_volume(unsigned int f_s, unsigned int f_c, unsigned int n_s, enum vd_type_e type){
 if(mbr.mbr_nvol == 8){
  fprintf(stderr, "Max number of volumes reached\n");
  return -1;
 }
 struct vd_descr_s new_vol;
 new_vol.vd_first_sector = f_s;
 new_vol.vd_first_cylinder = f_c;
 new_vol.vd_n_sector = n_s;
 new_vol.vd_val_type = type;
 mbr.mbr_vols[mbr.mbr_nvol] = new_vol;
 printf("%d, %d,  %d\n\n",f_c,f_s,n_s);
 printf_vol(mbr.mbr_nvol);
 return mbr.mbr_nvol++;
}

variable_types: struct vd_descr_s { unsigned int vd_first_sector; unsigned int vd_first_cylinder; unsigned int vd_n_sector; enum vd_type_e { VT_BASE=0, VT_ANX=1, VT_OTH=2 } vd_val_type; }


decompiled_code:
__int64 interactive_create_new_volume()
{
int v0; // eax
unsigned int v2; // [rsp+4h] [rbp-414h] BYREF
unsigned int v3; // [rsp+8h] [rbp-410h] BYREF
unsigned int v4; // [rsp+Ch] [rbp-40Ch] BYREF
char v5[1032]; // [rsp+10h] [rbp-408h] BYREF

puts("Please enter the first cylinder:");
if ( !(unsigned int)_isoc99_scanf("%i", &v3) )
return 0xFFFFFFFFLL;
puts("Please enter the first sector:");
if ( !(unsigned int)_isoc99_scanf("%i", &v2) )
return 0xFFFFFFFFLL;
puts("Please enter the number of sectors:");
if ( !(unsigned int)_isoc99_scanf("%i", &v4) )
return 0xFFFFFFFFLL;
puts("Please enter the volume type (VT_BASE, VT_ANX, VT_OTH):");
if ( !(unsigned int)_isoc99_scanf("%s", v5) )
return 0xFFFFFFFFLL;
v0 = retrieve_type_from_string(v5);
return create_new_volume(v2, v3, v4, v0);
}

canonical_decompiled_code:
__int64 func20()
{
int v0; // eax
unsigned int v2; // [rsp+4h] [rbp-414h] BYREF
unsigned int v3; // [rsp+8h] [rbp-410h] BYREF
unsigned int v4; // [rsp+Ch] [rbp-40Ch] BYREF
char v5[1032]; // [rsp+10h] [rbp-408h] BYREF

puts("Please enter the first cylinder:");
if ( !(unsigned int)_isoc99_scanf("%i", &v3) )
return 0xFFFFFFFFLL;
puts("Please enter the first sector:");
if ( !(unsigned int)_isoc99_scanf("%i", &v2) )
return 0xFFFFFFFFLL;
puts("Please enter the number of sectors:");
if ( !(unsigned int)_isoc99_scanf("%i", &v4) )
return 0xFFFFFFFFLL;
puts("Please enter the volume type (VT_BASE, VT_ANX, VT_OTH):");
if ( !(unsigned int)_isoc99_scanf("%s", v5) )
return 0xFFFFFFFFLL;
v0 = func1(v5);
return func19(v2, v3, v4, v0);
}

original_code:
int interactive_create_new_volume(){
 unsigned f_s;
 unsigned f_c;
 unsigned n_s;
 enum vd_type_e type;
 char buffer[1024];
 printf("Please enter the first cylinder:\n");
 if(scanf("%i",&f_c) == 0) return -1;
 printf("Please enter the first sector:\n");
 if(scanf("%i",&f_s) == 0) return -1;
 printf("Please enter the number of sectors:\n");
 if(scanf("%i",&n_s) == 0) return -1;
 printf("Please enter the volume type (VT_BASE, VT_ANX, VT_OTH):\n");
 if(scanf("%s",buffer) == 0) return -1;
 type = retrieve_type_from_string(buffer);
 return create_new_volume(f_s, f_c, n_s, type);
}

canonical_original_code:
int interactive_create_new_volume(){
 unsigned int f_s;
 unsigned int f_c;
 unsigned int n_s;
 enum vd_type_e type;
 char buffer[1024];
 printf("Please enter the first cylinder:\n");
 if(scanf("%i",&f_c) == 0) return -1;
 printf("Please enter the first sector:\n");
 if(scanf("%i",&f_s) == 0) return -1;
 printf("Please enter the number of sectors:\n");
 if(scanf("%i",&n_s) == 0) return -1;
 printf("Please enter the volume type (VT_BASE, VT_ANX, VT_OTH):\n");
 if(scanf("%s",buffer) == 0) return -1;
 type = retrieve_type_from_string(buffer);
 return create_new_volume(f_s, f_c, n_s, type);
}

variable_types: enum vd_type_e { VT_BASE=0, VT_ANX=1, VT_OTH=2 }

variable_types:
buffer
char [1024]


listVolumes

decompiled_code:
int listVolumes()
{
int result; // eax
unsigned int v1; // ebx
unsigned int v2; // edi

result = mbr[0];
if ( mbr[0] )
{
v1 = 0;
do
{
v2 = v1++;
result = printf_vol(v2);
}
while ( mbr[0] > v1 );
}
return result;
}

canonical_decompiled_code:
int func21()
{
int result; // eax
unsigned int v1; // ebx
unsigned int v2; // edi

result = mbr[0];
if ( mbr[0] )
{
v1 = 0;
do
{
v2 = v1++;
result = func18(v2);
}
while ( mbr[0] > v1 );
}
return result;
}

original_code:
void listVolumes(){
 int i;
 for ( i = 0 ; i < mbr.mbr_nvol; i++){
  printf_vol(i);
 }
}


dump

original_code:
void
dump(unsigned char *buffer,
     unsigned int buffer_size,
     int ascii_dump,
     int octal_dump)
{
    int i,j;
    for (i=0; i<buffer_size; i+=16) {
 printf("%.8o",i);
 if (octal_dump) {
     for(j=0; j<8; j++)
  printf(" %.2x", buffer[i+j]);
     printf(" - ");
     for( ; j<16; j++)
  printf(" %.2x", buffer[i+j]);
     printf("\n");
 }
 if (ascii_dump) {
     printf("%8c", ' ');
     for(j=0; j<8; j++)
  printf(" %1c ", ((*__ctype_b_loc ())[(int) ((buffer[i+j]))] & (unsigned short int) _ISprint)?buffer[i+j]:' ');
     printf(" - ");
     for( ; j<16; j++)
  printf(" %1c ", ((*__ctype_b_loc ())[(int) ((buffer[i+j]))] & (unsigned short int) _ISprint)?buffer[i+j]:' ');
     printf("\n");
 }
    }
}

canonical_original_code:
void dump(unsigned char *buffer, unsigned int buffer_size, int ascii_dump, int octal_dump)
{
    int i; int j;
    for (i=0; i<buffer_size; i+=16) {
 printf("%.8o",i);
 if (octal_dump) {
     for(j=0; j<8; j++)
  printf(" %.2x", buffer[i+j]);
     printf(" - ");
     for( ; j<16; j++)
  printf(" %.2x", buffer[i+j]);
     printf("\n");
 }
 if (ascii_dump) {
     printf("%8c", ' ');
     for(j=0; j<8; j++)
  printf(" %1c ", ((*__ctype_b_loc ())[(int) ((buffer[i+j]))] & (unsigned short) _ISprint)?buffer[i+j]:' ');
     printf(" - ");
     for( ; j<16; j++)
  printf(" %1c ", ((*__ctype_b_loc ())[(int) ((buffer[i+j]))] & (unsigned short) _ISprint)?buffer[i+j]:' ');
     printf("\n");
 }
    }
}

variable_types: j int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char shortopts[37]; // [rsp+3h] [rbp-25h] BYREF

_bss_start = 1;
strcpy(shortopts, "hvctruxfzdsm");
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, shortopts);
if ( v3 == -1 )
return 0;
switch ( v3 )
{
case 'c':
puts(aParam_4);
puts(aNonImpl);
break;
case 'd':
puts(aParam_3);
puts(aNonImpl);
break;
case 'f':
puts(aParam_2);
break;
case 'h':
puts("Aide :");
puts("Lister : taar -t fichierTAR");
puts("Extraire : taar -x fichierTAR cheminDeSortie");
puts("Compresser : taar -z fichierTAR");
break;
case 'm':
puts(aParam_1);
puts(aNonImpl);
break;
case 'r':
puts(aParam_0);
puts(aNonImpl);
break;
case 's':
printf(format);
puts(aNonImpl);
break;
case 't':
lister((char *)argv[2]);
break;
case 'u':
puts(aParam);
puts(aNonImpl);
break;
case 'v':
puts(s);
break;
case 'x':
extraire((char *)argv[2]);
break;
case 'z':
compresser(argv[2]);
break;
default:
continue;
}
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char shortopts[37]; // [rsp+3h] [rbp-25h] BYREF

_bss_start = 1;
strcpy(shortopts, "hvctruxfzdsm");
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, shortopts);
if ( v3 == -1 )
return 0;
switch ( v3 )
{
case 'c':
puts(aParam_4);
puts(aNonImpl);
break;
case 'd':
puts(aParam_3);
puts(aNonImpl);
break;
case 'f':
puts(aParam_2);
break;
case 'h':
puts("Aide :");
puts("Lister : taar -t fichierTAR");
puts("Extraire : taar -x fichierTAR cheminDeSortie");
puts("Compresser : taar -z fichierTAR");
break;
case 'm':
puts(aParam_1);
puts(aNonImpl);
break;
case 'r':
puts(aParam_0);
puts(aNonImpl);
break;
case 's':
printf(format);
puts(aNonImpl);
break;
case 't':
func10((char *)argv[2]);
break;
case 'u':
puts(aParam);
puts(aNonImpl);
break;
case 'v':
puts(s);
break;
case 'x':
func11((char *)argv[2]);
break;
case 'z':
func12(argv[2]);
break;
default:
continue;
}
}
}

original_code:
int main(int argc, char *argv[])
{
  int optch;
  extern int opterr;
  char format[] = "hvctruxfzdsm";
  _Bool verbose = 0;
  opterr = 1;
  while ((optch = getopt(argc, argv, format)) != -1)
    switch (optch)
    {
      case 'h':
        printf ("Aide :\n");
        printf ("Lister  : taar -t fichierTAR\n");
        printf ("Extraire  : taar -x fichierTAR cheminDeSortie\n");
        printf ("Compresser  : taar -z fichierTAR\n");
        break;
      case 'v':
        printf ("Paramètre v recontré : mode verbose\n");
        verbose = 1;
        break;
      case 'c':
        printf ("Paramètre c recontré : creer une archive à partir d'une liste de fichiers (et de repertoires)\n");
        printf ("Non implémenté\n");
        break;
      case 't':
        lister(argv[2]);
        break;
      case 'r':
        printf ("Paramètre r recontré : ajouter de nouveaux fichiers (ou repertoires) à une archive existante\n");
        printf ("Non implémenté\n");
        break;
      case 'u':
        printf ("Paramètre u recontré : pour mettre à jour l'archive si les fichiers listes sont plus recents que ceux archives\n");
        printf ("Non implémenté\n");
        break;
      case 'x':
        extraire(argv[2], argv[3]);
        break;
      case 'f':
        printf ("Paramètre f recontré : pour indiquer le nom du fichier archive, sinon tar utilise l'entree et la sortie standard avec les options precedentes\n");
        break;
      case 'z':
        compresser(argv[2]);
        break;
      case 'd':
        printf ("Paramètre d recontré : pour supprimer un fichier d'une archive\n");
        printf ("Non implémenté\n");
        break;
      case 's':
        printf ("Paramètre s recontré\nAvec 'parse' : pour economiser de la place pour stocker les fichier contenant beaucoup de zeros consecutifs (sparse file)");
        printf ("Non implémenté\n");
        break;
      case 'm':
        printf ("Paramètre m recontré : pour afficher les differences entre les fichiers archives et les fichiers existants en utilisant la commande Unix 'diff'\n");
        printf ("Non implémenté\n");
        break;
    }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: optch int

variable_types: opterr int

variable_types:
format
char []


repo: BergerLab/CAST

decompiled_code:
void __fastcall cb_seq_free(void *ptr)
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void cb_seq_free(struct cb_seq *seq){
    free(seq->name);
    free(seq->residues);
    free(seq);
}

variable_types: struct cb_seq { int id; char *name; char *residues; int length; } *


decompiled_code:
void __fastcall cb_hit_expansion_free(void *ptr)
{
cb_seq_free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
func0(*(void **)ptr);
free(ptr);
}

original_code:
void cb_hit_expansion_free(struct cb_hit_expansion *expansion){
    cb_seq_free(expansion->seq);
    free(expansion);
}

variable_types: struct cb_hit_expansion { struct cb_seq { int id; char *name; char *residues; int length; } *seq; char strand; long offset; } *

user_defined_types: struct cb_hit_expansion { struct cb_seq *seq; char strand; long offset; }


decompiled_code:
unsigned __int64 __fastcall hash_string(char *a1)
{
__int64 v1; // rax
char *v2; // rsi
unsigned __int64 v3; // rcx

v1 = *a1;
v2 = a1 + 1;
if ( !(_BYTE)v1 )
return 5381LL;
v3 = 5381LL;
do
{
++v2;
v3 += 32 * v3 + v1;
v1 = *(v2 - 1);
}
while ( (_BYTE)v1 );
return v3 % 0xF4240;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(char *a1)
{
__int64 v1; // rax
char *v2; // rsi
unsigned __int64 v3; // rcx

v1 = *a1;
v2 = a1 + 1;
if ( !(_BYTE)v1 )
return 5381LL;
v3 = 5381LL;
do
{
++v2;
v3 += 32 * v3 + v1;
v1 = *(v2 - 1);
}
while ( (_BYTE)v1 );
return v3 % 0xF4240;
}

original_code:
static uint64_t
hash_string(char* str)
{
    uint64_t hash = 5381;
    char c;
    while ((c = *str++))
        hash = ((hash << 5) + hash) + c;
    return hash % DS_HASHMAP_BUCKETS;
}

canonical_original_code:
static unsigned long hash_string(char *str)
{
    unsigned long hash = 5381;
    char c;
    while ((c = *str++))
        hash = ((hash << 5) + hash) + c;
    return hash % DS_HASHMAP_BUCKETS;
}

variable_types:
str
char *

variable_types:
hash
unsigned long

variable_types: c char

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall hash_int(int a1)
{
return a1 % 0xF4240uLL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(int a1)
{
return a1 % 0xF4240uLL;
}

original_code:
static uint64_t
hash_int(int32_t integer)
{
    return (uint64_t) integer % DS_HASHMAP_BUCKETS;
}

canonical_original_code:
static unsigned long hash_int(int integer)
{
    return (unsigned long) integer % DS_HASHMAP_BUCKETS;
}

variable_types: integer int


decompiled_code:
unsigned __int64 __fastcall hash_value(char *a1, int a2, char a3)
{
if ( (a1 != 0LL) != (a3 == 2) )
_assert_fail(
"(skey == NULL && type != DS_HASHMAP_KEY_STRING) || (skey != NULL && type == DS_HASHMAP_KEY_STRING)",
"hashmap.c",
0x196u,
"hash_value");
if ( a3 == 1 )
return hash_int(a2);
if ( a3 != 2 )
_assert_fail("false", "hashmap.c", 0x1A2u, "hash_value");
return hash_string(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(char *a1, int a2, char a3)
{
if ( (a1 != 0LL) != (a3 == 2) )
_assert_fail(
"(skey == NULL && type != DS_HASHMAP_KEY_STRING) || (skey != NULL && type == DS_HASHMAP_KEY_STRING)",
"hashmap.c",
0x196u,
"hash_value");
if ( a3 == 1 )
return func1(a2);
if ( a3 != 2 )
_assert_fail("false", "hashmap.c", 0x1A2u, "hash_value");
return func0(a1);
}

original_code:
static uint64_t
hash_value(char *skey, int32_t ikey, int8_t type)
{
    (((skey == ((void *)0) && type != 2) || (skey != ((void *)0) && type == 2)) ? (void) (0) : __assert_fail ("(skey == NULL && type != DS_HASHMAP_KEY_STRING) || (skey != NULL && type == DS_HASHMAP_KEY_STRING)", "hashmap.c", 406, __extension__ __PRETTY_FUNCTION__));
    switch(type) {
    case 2:
        return hash_string(skey);
        break;
    case 1:
        return hash_int(ikey);
        break;
    }
    ((0) ? (void) (0) : __assert_fail ("false", "hashmap.c", 418, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
static unsigned long hash_value(char *skey, int ikey, char type)
{
    (((skey == ((void *)0) && type != 2) || (skey != ((void *)0) && type == 2)) ? (void) (0) : __assert_fail ("(skey == NULL && type != DS_HASHMAP_KEY_STRING) || (skey != NULL && type == DS_HASHMAP_KEY_STRING)", "hashmap.c", 406, __extension__ __PRETTY_FUNCTION__));
    switch(type) {
    case 2:
        return hash_string(skey);
        break;
    case 1:
        return hash_int(ikey);
        break;
    }
    ((0) ? (void) (0) : __assert_fail ("false", "hashmap.c", 418, __extension__ __PRETTY_FUNCTION__));
}

variable_types:
skey
char *

variable_types: ikey int

variable_types: type char


decompiled_code:
bool __fastcall is_key_match(__int64 a1, const char *a2, int a3, char a4)
{
bool result; // al

result = 0;
if ( a4 == 2 )
{
if ( *(_BYTE *)(a1 + 8) == 2 )
result = strcmp(a2, *(const char **)(a1 + 16)) == 0;
}
else if ( a4 == 1 && *(_BYTE *)(a1 + 8) == 1 )
{
result = *(_DWORD *)(a1 + 16) == a3;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func3(__int64 a1, const char *a2, int a3, char a4)
{
bool result; // al

result = 0;
if ( a4 == 2 )
{
if ( *(_BYTE *)(a1 + 8) == 2 )
result = strcmp(a2, *(const char **)(a1 + 16)) == 0;
}
else if ( a4 == 1 && *(_BYTE *)(a1 + 8) == 1 )
{
result = *(_DWORD *)(a1 + 16) == a3;
}
return result;
}

original_code:
static _Bool
is_key_match(struct DSHashKey *key, char *skey, int32_t ikey, int8_t type)
{
    return (type == 2 &&
            key->keytype == 2 &&
            strcmp(skey, key->key.s) == 0)
           ||
           (type == 1 &&
            key->keytype == 1 &&
            ikey == key->key.i);
}

canonical_original_code:
static _Bool is_key_match(struct DSHashKey *key, char *skey, int ikey, char type)
{
    return (type == 2 &&
            key->keytype == 2 &&
            strcmp(skey, key->key.s) == 0)
           ||
           (type == 1 &&
            key->keytype == 1 &&
            ikey == key->key.i);
}

variable_types: struct DSHashKey { struct DSHashMap { struct DSVector { int size; int capacity; void **data; } *keys; struct DSHashItem { struct DSHashKey *key; void *data; struct DSHashItem *next; } **buckets; } *hash; char keytype; union { int i; char *s; } key; } *

user_defined_types: struct DSHashKey { struct DSHashMap *hash; char keytype; union { int i; char *s; } key; }

user_defined_types: struct DSHashMap { struct DSVector *keys; struct DSHashItem **buckets; }


original_code:
static void
ds_hashmap_put(struct DSHashMap *hash, void *data, char* skey, int32_t ikey,
               int8_t type)
{
    struct DSHashItem *item, *last;
    uint64_t hashval;
    hashval = hash_value(skey, ikey, type);
    item = hash->buckets[hashval];
    last = ((void *)0);
    while (item != ((void *)0)) {
        if (is_key_match(item->key, skey, ikey, type)) {
            if (item->data != ((void *)0))
                free(item->data);
            item->data = data;
            return;
        }
        if (item->next == ((void *)0))
            last = item;
        item = item->next;
    }
    item = malloc(sizeof(*item));
    ((item) ? (void) (0) : __assert_fail ("item", "hashmap.c", 136, __extension__ __PRETTY_FUNCTION__));
    item->next = ((void *)0);
    item->data = data;
    item->key = malloc(sizeof(*item->key));
    ((item->key) ? (void) (0) : __assert_fail ("item->key", "hashmap.c", 141, __extension__ __PRETTY_FUNCTION__));
    item->key->hash = hash;
    item->key->keytype = type;
    switch(type) {
    case 2:
        item->key->key.s = skey;
        break;
    case 1:
        item->key->key.i = ikey;
        break;
    }
    if (last == ((void *)0))
        hash->buckets[hashval] = item;
    else
        last->next = item;
    ds_vector_append(hash->keys, item->key);
}

canonical_original_code:
static void ds_hashmap_put(struct DSHashMap *hash, void *data, char *skey, int ikey, char type)
{
    struct DSHashItem *item; struct DSHashItem *last;
    unsigned long hashval;
    hashval = hash_value(skey, ikey, type);
    item = hash->buckets[hashval];
    last = ((void *)0);
    while (item != ((void *)0)) {
        if (is_key_match(item->key, skey, ikey, type)) {
            if (item->data != ((void *)0))
                free(item->data);
            item->data = data;
            return;
        }
        if (item->next == ((void *)0))
            last = item;
        item = item->next;
    }
    item = malloc(sizeof(*item));
    ((item) ? (void) (0) : __assert_fail ("item", "hashmap.c", 136, __extension__ __PRETTY_FUNCTION__));
    item->next = ((void *)0);
    item->data = data;
    item->key = malloc(sizeof(*item->key));
    ((item->key) ? (void) (0) : __assert_fail ("item->key", "hashmap.c", 141, __extension__ __PRETTY_FUNCTION__));
    item->key->hash = hash;
    item->key->keytype = type;
    switch(type) {
    case 2:
        item->key->key.s = skey;
        break;
    case 1:
        item->key->key.i = ikey;
        break;
    }
    if (last == ((void *)0))
        hash->buckets[hashval] = item;
    else
        last->next = item;
    ds_vector_append(hash->keys, item->key);
}

variable_types: struct DSHashMap { struct DSVector { int size; int capacity; void **data; } *keys; struct DSHashItem { struct DSHashKey { struct DSHashMap *hash; char keytype; union { int i; char *s; } key; } *key; void *data; struct DSHashItem *next; } **buckets; } *

variable_types:
data
void *

variable_types: struct DSHashItem { struct DSHashKey { struct DSHashMap { struct DSVector { int size; int capacity; void **data; } *keys; struct DSHashItem **buckets; } *hash; char keytype; union { int i; char *s; } key; } *key; void *data; struct DSHashItem *next; } *

variable_types:
hashval
unsigned long

user_defined_types: struct DSHashItem { struct DSHashKey *key; void *data; struct DSHashItem *next; }


original_code:
static void
ds_hashmap_remove(struct DSHashMap *hash, char *skey, int32_t ikey, int8_t type,
                  _Bool free_data, _Bool free_string_keys)
{
    struct DSHashItem *item, *last;
    uint64_t hashval;
    hashval = hash_value(skey, ikey, type);
    item = hash->buckets[hashval];
    last = ((void *)0);
    while (item != ((void *)0)) {
        if (is_key_match(item->key, skey, ikey, type)) {
            int32_t i;
            if (last == ((void *)0))
                hash->buckets[hashval] = ((void *)0);
            else
                last->next = item->next;
            for (i = 0; i < hash->keys->size; ++i) {
                struct DSHashKey *k;
                k = (struct DSHashKey*) ds_vector_get(hash->keys, i);
                if (is_key_match(k, skey, ikey, type)) {
                    ds_vector_remove(hash->keys, i);
                    break;
                }
            }
            if (free_data && item->data != ((void *)0))
                free(item->data);
            if (free_string_keys && type == 2)
                free(item->key->key.s);
            free(item->key);
            free(item);
            return;
        }
        last = item;
        item = item->next;
    }
}

canonical_original_code:
static void ds_hashmap_remove(struct DSHashMap *hash, char *skey, int ikey, char type, _Bool free_data, _Bool free_string_keys)
{
    struct DSHashItem *item; struct DSHashItem *last;
    unsigned long hashval;
    hashval = hash_value(skey, ikey, type);
    item = hash->buckets[hashval];
    last = ((void *)0);
    while (item != ((void *)0)) {
        if (is_key_match(item->key, skey, ikey, type)) {
            int i;
            if (last == ((void *)0))
                hash->buckets[hashval] = ((void *)0);
            else
                last->next = item->next;
            for (i = 0; i < hash->keys->size; ++i) {
                struct DSHashKey *k;
                k = (struct DSHashKey *) ds_vector_get(hash->keys, i);
                if (is_key_match(k, skey, ikey, type)) {
                    ds_vector_remove(hash->keys, i);
                    break;
                }
            }
            if (free_data && item->data != ((void *)0))
                free(item->data);
            if (free_string_keys && type == 2)
                free(item->key->key.s);
            free(item->key);
            free(item);
            return;
        }
        last = item;
        item = item->next;
    }
}

variable_types: i int

user_defined_types: struct DSVector { int size; int capacity; void **data; }


decompiled_code:
int __fastcall ds_hashmap_compare_keys(__int64 a1, __int64 a2)
{
char v2; // al
const char *v3; // rbp
char v4; // al
char v5; // r12
bool v6; // r13
bool v7; // al
char *v8; // rsi
bool v10; // dl
char v11; // al
char s1[11]; // [rsp+Ah] [rbp-3Eh] BYREF
char s2[51]; // [rsp+15h] [rbp-33h] BYREF

v2 = *(_BYTE *)(a1 + 8);
if ( v2 != 1 )
{
if ( v2 != 2 )
{
v11 = *(_BYTE *)(a2 + 8);
if ( v11 != 1 )
{
if ( v11 != 2 )
{
v8 = 0LL;
v3 = 0LL;
v5 = 0;
v6 = 1;
LABEL_22:
v7 = v8 == 0LL;
v5 &= v8 == 0LL;
goto LABEL_7;
}
v8 = *(char **)(a2 + 16);
v10 = v8 != 0LL;
v5 = 0;
v3 = 0LL;
LABEL_24:
v6 = v3 == 0LL;
if ( !v3 && v10 )
return strcmp(s1, v8);
goto LABEL_22;
}
v6 = 1;
v5 = 0;
v3 = 0LL;
LABEL_16:
sprintf(s2, "%d", *(unsigned int *)(a2 + 16));
goto LABEL_6;
}
v3 = *(const char **)(a1 + 16);
v4 = *(_BYTE *)(a2 + 8);
v5 = v3 != 0LL;
if ( v4 != 1 )
goto LABEL_4;
LABEL_15:
v6 = v3 == 0LL;
goto LABEL_16;
}
v5 = 0;
v3 = 0LL;
sprintf(s1, "%d", *(unsigned int *)(a1 + 16));
v4 = *(_BYTE *)(a2 + 8);
if ( v4 == 1 )
goto LABEL_15;
LABEL_4:
if ( v4 == 2 )
{
v8 = *(char **)(a2 + 16);
v10 = v8 != 0LL;
if ( v5 && v8 )
return strcmp(v3, v8);
goto LABEL_24;
}
v6 = v3 == 0LL;
LABEL_6:
v7 = 1;
LABEL_7:
if ( !v5 )
{
if ( !v6 || !v7 )
_assert_fail("false", "hashmap.c", 0x184u, "ds_hashmap_compare_keys");
v8 = s2;
return strcmp(s1, v8);
}
v8 = s2;
return strcmp(v3, v8);
}

original_code:
static int32_t
ds_hashmap_compare_keys(void *vk1, void *vk2)
{
    struct DSHashKey *k1, *k2;
    char *s1 = ((void *)0), *s2 = ((void *)0);
    char i1[11], i2[11];
    k1 = (struct DSHashKey*) vk1;
    k2 = (struct DSHashKey*) vk2;
    switch(k1->keytype) {
    case 2:
        s1 = k1->key.s;
        break;
    case 1:
        sprintf(i1, "%d", k1->key.i);
        break;
    }
    switch(k2->keytype) {
    case 2:
        s2 = k2->key.s;
        break;
    case 1:
        sprintf(i2, "%d", k2->key.i);
        break;
    }
    if (s1 != ((void *)0) && s2 != ((void *)0))
        return strcmp(s1, s2);
    else if (s1 == ((void *)0) && s2 != ((void *)0))
        return strcmp(i1, s2);
    else if (s1 != ((void *)0) && s2 == ((void *)0))
        return strcmp(s1, i2);
    else if (s1 == ((void *)0) && s2 == ((void *)0))
        return strcmp(i1, i2);
    ((0) ? (void) (0) : __assert_fail ("false", "hashmap.c", 388, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
static int ds_hashmap_compare_keys(void *vk1, void *vk2)
{
    struct DSHashKey *k1; struct DSHashKey *k2;
    char *s1 = ((void *)0); char *s2 = ((void *)0);
    char i1[11]; char i2[11];
    k1 = (struct DSHashKey *) vk1;
    k2 = (struct DSHashKey *) vk2;
    switch(k1->keytype) {
    case 2:
        s1 = k1->key.s;
        break;
    case 1:
        sprintf(i1, "%d", k1->key.i);
        break;
    }
    switch(k2->keytype) {
    case 2:
        s2 = k2->key.s;
        break;
    case 1:
        sprintf(i2, "%d", k2->key.i);
        break;
    }
    if (s1 != ((void *)0) && s2 != ((void *)0))
        return strcmp(s1, s2);
    else if (s1 == ((void *)0) && s2 != ((void *)0))
        return strcmp(i1, s2);
    else if (s1 != ((void *)0) && s2 == ((void *)0))
        return strcmp(s1, i2);
    else if (s1 == ((void *)0) && s2 == ((void *)0))
        return strcmp(i1, i2);
    ((0) ? (void) (0) : __assert_fail ("false", "hashmap.c", 388, __extension__ __PRETTY_FUNCTION__));
}


decompiled_code:
_QWORD *ds_hashmap_create()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void *v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
_assert_fail("hash", "hashmap.c", 0x2Cu, "ds_hashmap_create");
v1 = v0;
*v0 = ds_vector_create();
v2 = calloc(0x7A1200uLL, 1uLL);
v1[1] = v2;
if ( !v2 )
_assert_fail("hash->buckets", "hashmap.c", 0x30u, "ds_hashmap_create");
return v1;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void *v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
_assert_fail("hash", "hashmap.c", 0x2Cu, "ds_hashmap_create");
v1 = v0;
*v0 = ds_vector_create();
v2 = calloc(0x7A1200uLL, 1uLL);
v1[1] = v2;
if ( !v2 )
_assert_fail("hash->buckets", "hashmap.c", 0x30u, "ds_hashmap_create");
return v1;
}

original_code:
struct DSHashMap *
ds_hashmap_create()
{
    struct DSHashMap *hash;
    int32_t i;
    hash = malloc(sizeof(*hash));
    ((hash) ? (void) (0) : __assert_fail ("hash", "hashmap.c", 44, __extension__ __PRETTY_FUNCTION__));
    hash->keys = ds_vector_create();
    hash->buckets = malloc(DS_HASHMAP_BUCKETS * sizeof(*hash->buckets));
    ((hash->buckets) ? (void) (0) : __assert_fail ("hash->buckets", "hashmap.c", 48, __extension__ __PRETTY_FUNCTION__));
    for (i = 0; i < DS_HASHMAP_BUCKETS; ++i)
        hash->buckets[i] = ((void *)0);
    return hash;
}

canonical_original_code:
struct DSHashMap *ds_hashmap_create()
{
    struct DSHashMap *hash;
    int i;
    hash = malloc(sizeof(*hash));
    ((hash) ? (void) (0) : __assert_fail ("hash", "hashmap.c", 44, __extension__ __PRETTY_FUNCTION__));
    hash->keys = ds_vector_create();
    hash->buckets = malloc(DS_HASHMAP_BUCKETS * sizeof(*hash->buckets));
    ((hash->buckets) ? (void) (0) : __assert_fail ("hash->buckets", "hashmap.c", 48, __extension__ __PRETTY_FUNCTION__));
    for (i = 0; i < DS_HASHMAP_BUCKETS; ++i)
        hash->buckets[i] = ((void *)0);
    return hash;
}

return_type: struct DSHashMap { struct DSVector { int size; int capacity; void **data; } *keys; struct DSHashItem { struct DSHashKey { struct DSHashMap *hash; char keytype; union { int i; char *s; } key; } *key; void *data; struct DSHashItem *next; } **buckets; } *


decompiled_code:
void __fastcall ds_hashmap_free(void *ptr, char a2, char a3)
{
__int64 i; // r14
__int64 v5; // rbx
void **v6; // rbp

for ( i = 0LL; i != 8000000; i += 8LL )
{
v5 = *(_QWORD *)(*((_QWORD *)ptr + 1) + i);
while ( v5 )
{
v6 = (void **)v5;
v5 = *(_QWORD *)(v5 + 16);
if ( a3 && *((_BYTE *)*v6 + 8) == 2 )
free(*((void **)*v6 + 2));
if ( a2 )
free(v6[1]);
free(*v6);
free(v6);
}
}
ds_vector_free_no_data(*(_QWORD *)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void
ds_hashmap_free(struct DSHashMap *hash, _Bool free_data, _Bool free_string_keys)
{
    struct DSHashItem *item, *item2;
    int32_t i;
    for (i = 0; i < DS_HASHMAP_BUCKETS; ++i) {
        item = hash->buckets[i];
        while(item) {
            item2 = item->next;
            if (free_string_keys && item->key->keytype == 2)
                free(item->key->key.s);
            if (free_data)
                free(item->data);
            free(item->key);
            free(item);
            item = item2;
        }
    }
    ds_vector_free_no_data(hash->keys);
    free(hash->buckets);
    free(hash);
}

canonical_original_code:
void ds_hashmap_free(struct DSHashMap *hash, _Bool free_data, _Bool free_string_keys)
{
    struct DSHashItem *item; struct DSHashItem *item2;
    int i;
    for (i = 0; i < DS_HASHMAP_BUCKETS; ++i) {
        item = hash->buckets[i];
        while(item) {
            item2 = item->next;
            if (free_string_keys && item->key->keytype == 2)
                free(item->key->key.s);
            if (free_data)
                free(item->data);
            free(item->key);
            free(item);
            item = item2;
        }
    }
    ds_vector_free_no_data(hash->keys);
    free(hash->buckets);
    free(hash);
}


decompiled_code:
__int64 __fastcall ds_hashmap_put_str(_QWORD *a1, char *a2, __int64 a3)
{
return ds_hashmap_put(a1, a3, a2, 0, 2);
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, char *a2, __int64 a3)
{
return func4(a1, a3, a2, 0, 2);
}

original_code:
void
ds_hashmap_put_str(struct DSHashMap *hash, char *key, void *data)
{
    ds_hashmap_put(hash, data, key, 0, 2);
}

variable_types:
key
char *


decompiled_code:
// attributes: thunk
__int64 __fastcall ds_puts(_QWORD *a1, char *a2, __int64 a3)
{
return ds_hashmap_put_str(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, char *a2, __int64 a3)
{
return func9(a1, a2, a3);
}

original_code:
void
ds_puts(struct DSHashMap *hash, char *key, void *data)
{
    ds_hashmap_put_str(hash, key, data);
}


decompiled_code:
__int64 __fastcall ds_hashmap_put_int(_QWORD *a1, int a2, __int64 a3)
{
return ds_hashmap_put(a1, a3, 0LL, a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1, int a2, __int64 a3)
{
return func4(a1, a3, 0LL, a2, 1);
}

original_code:
void
ds_hashmap_put_int(struct DSHashMap *hash, int32_t key, void *data)
{
    ds_hashmap_put(hash, data, ((void *)0), key, 1);
}

canonical_original_code:
void ds_hashmap_put_int(struct DSHashMap *hash, int key, void *data)
{
    ds_hashmap_put(hash, data, ((void *)0), key, 1);
}

variable_types: key int


decompiled_code:
// attributes: thunk
__int64 __fastcall ds_puti(_QWORD *a1, int a2, __int64 a3)
{
return ds_hashmap_put_int(a1, a2, a3);
}

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

original_code:
void
ds_puti(struct DSHashMap *hash, int32_t key, void *data)
{
    ds_hashmap_put_int(hash, key, data);
}

canonical_original_code:
void ds_puti(struct DSHashMap *hash, int key, void *data)
{
    ds_hashmap_put_int(hash, key, data);
}


decompiled_code:
void __fastcall ds_hashmap_remove_str(_QWORD *a1, char *a2, char a3, char a4)
{
ds_hashmap_remove(a1, a2, 0, 2, a3, a4);
}

canonical_decompiled_code:
void __fastcall func13(_QWORD *a1, char *a2, char a3, char a4)
{
func5(a1, a2, 0, 2, a3, a4);
}

original_code:
void
ds_hashmap_remove_str(struct DSHashMap *hash, char *key, _Bool free_data,
                      _Bool free_string_keys)
{
    ds_hashmap_remove(hash, key, 0, 2, free_data,
                      free_string_keys);
}


decompiled_code:
void __fastcall ds_hashmap_remove_int(_QWORD *a1, int a2, char a3)
{
ds_hashmap_remove(a1, 0LL, a2, 1, a3, 0);
}

canonical_decompiled_code:
void __fastcall func14(_QWORD *a1, int a2, char a3)
{
func5(a1, 0LL, a2, 1, a3, 0);
}

original_code:
void
ds_hashmap_remove_int(struct DSHashMap *hash, int32_t key, _Bool free_data)
{
    ds_hashmap_remove(hash, ((void *)0), key, 1, free_data, 0);
}

canonical_original_code:
void ds_hashmap_remove_int(struct DSHashMap *hash, int key, _Bool free_data)
{
    ds_hashmap_remove(hash, ((void *)0), key, 1, free_data, 0);
}


decompiled_code:
int __fastcall ds_hashmap_print_keys(signed int **a1)
{
signed int *v2; // rdi
__int64 v3; // rax
signed int v4; // ebx
char v5; // dl

v2 = *a1;
LODWORD(v3) = *v2;
if ( *v2 > 0 )
{
v4 = 0;
do
{
while ( 1 )
{
v3 = ds_vector_get(v2, (unsigned int)v4);
v5 = *(_BYTE *)(v3 + 8);
if ( v5 != 1 )
break;
++v4;
LODWORD(v3) = printf("%d\n", *(unsigned int *)(v3 + 16));
v2 = *a1;
if ( **a1 <= v4 )
return v3;
}
if ( v5 == 2 )
LODWORD(v3) = puts(*(const char **)(v3 + 16));
v2 = *a1;
++v4;
}
while ( **a1 > v4 );
}
return v3;
}

canonical_decompiled_code:
int __fastcall func15(signed int **a1)
{
signed int *v2; // rdi
__int64 v3; // rax
signed int v4; // ebx
char v5; // dl

v2 = *a1;
LODWORD(v3) = *v2;
if ( *v2 > 0 )
{
v4 = 0;
do
{
while ( 1 )
{
v3 = ds_vector_get(v2, (unsigned int)v4);
v5 = *(_BYTE *)(v3 + 8);
if ( v5 != 1 )
break;
++v4;
LODWORD(v3) = printf("%d\n", *(unsigned int *)(v3 + 16));
v2 = *a1;
if ( **a1 <= v4 )
return v3;
}
if ( v5 == 2 )
LODWORD(v3) = puts(*(const char **)(v3 + 16));
v2 = *a1;
++v4;
}
while ( **a1 > v4 );
}
return v3;
}

original_code:
void
ds_hashmap_print_keys(struct DSHashMap *hash)
{
    int32_t i;
    for (i = 0; i < hash->keys->size; ++i) {
        struct DSHashKey *key;
        key = ds_vector_get(hash->keys, i);
        switch(key->keytype) {
        case 2:
            printf("%s\n", key->key.s);
            break;
        case 1:
            printf("%d\n", key->key.i);
            break;
        }
    }
}

canonical_original_code:
void ds_hashmap_print_keys(struct DSHashMap *hash)
{
    int i;
    for (i = 0; i < hash->keys->size; ++i) {
        struct DSHashKey *key;
        key = ds_vector_get(hash->keys, i);
        switch(key->keytype) {
        case 2:
            printf("%s\n", key->key.s);
            break;
        case 1:
            printf("%d\n", key->key.i);
            break;
        }
    }
}


decompiled_code:
__int64 __fastcall ds_hashmap_sort_keys(_QWORD *a1)
{
return ds_hashmap_sort_by(a1);
}

canonical_decompiled_code:
__int64 __fastcall func18(_QWORD *a1)
{
return func17(a1);
}

original_code:
void
ds_hashmap_sort_keys(struct DSHashMap *hash)
{
    ds_hashmap_sort_by(hash, ds_hashmap_compare_keys);
}


decompiled_code:
void __fastcall cb_vector_array_free(void *ptr)
{
volatile signed __int32 *v1; // rdx
signed __int32 v3; // eax
int v4; // ecx
signed __int32 v5; // ett
__int64 i; // rbx
void *v7; // rdi

v1 = (volatile signed __int32 *)((char *)ptr + 8);
do
{
v3 = *v1;
do
{
v4 = v3;
v5 = v3;
v3 = _InterlockedCompareExchange(v1, v3, v3);
}
while ( v5 != v3 );
}
while ( v4 > 0 );
for ( i = 0LL; *(_DWORD *)ptr > (int)i; ++i )
{
v7 = *(void **)(*((_QWORD *)ptr + 2) + 8 * i);
free(v7);
}
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
volatile signed __int32 *v1; // rdx
signed __int32 v3; // eax
int v4; // ecx
signed __int32 v5; // ett
__int64 i; // rbx
void *v7; // rdi

v1 = (volatile signed __int32 *)((char *)ptr + 8);
do
{
v3 = *v1;
do
{
v4 = v3;
v5 = v3;
v3 = _InterlockedCompareExchange(v1, v3, v3);
}
while ( v5 != v3 );
}
while ( v4 > 0 );
for ( i = 0LL; *(_DWORD *)ptr > (int)i; ++i )
{
v7 = *(void **)(*((_QWORD *)ptr + 2) + 8 * i);
free(v7);
}
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void cb_vector_array_free(struct cb_vector_array *array){
    while (__sync_fetch_and_or(&(array->th), 0) > 0) {}
    for (int i = 0; i < array->size; i++)
        free(array->data[i]);
    free(array->data);
    free(array);
}

variable_types: struct cb_vector_array { int size; int capacity; int th; void **data; } *


decompiled_code:
void __fastcall cb_vector_array_free_no_data(void *ptr)
{
volatile signed __int32 *v1; // rdx
signed __int32 v2; // eax
int v3; // ecx
signed __int32 v4; // ett

v1 = (volatile signed __int32 *)((char *)ptr + 8);
do
{
v2 = *v1;
do
{
v3 = v2;
v4 = v2;
v2 = _InterlockedCompareExchange(v1, v2, v2);
}
while ( v4 != v2 );
}
while ( v3 > 0 );
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
volatile signed __int32 *v1; // rdx
signed __int32 v2; // eax
int v3; // ecx
signed __int32 v4; // ett

v1 = (volatile signed __int32 *)((char *)ptr + 8);
do
{
v2 = *v1;
do
{
v3 = v2;
v4 = v2;
v2 = _InterlockedCompareExchange(v1, v2, v2);
}
while ( v4 != v2 );
}
while ( v3 > 0 );
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void cb_vector_array_free_no_data(struct cb_vector_array *array){
    while (__sync_fetch_and_or(&(array->th), 0) > 0) {}
    free(array->data);
    free(array);
}

user_defined_types: struct cb_vector_array { int size; int capacity; int th; void **data; }


decompiled_code:
__int64 __fastcall cb_vector_array_get(__int64 a1, int a2)
{
__int64 v2; // r8

_InterlockedAdd((volatile signed __int32 *)(a1 + 8), 1u);
v2 = 0LL;
if ( *(_DWORD *)a1 > a2 )
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2);
_InterlockedSub((volatile signed __int32 *)(a1 + 8), 1u);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 v2; // r8

_InterlockedAdd((volatile signed __int32 *)(a1 + 8), 1u);
v2 = 0LL;
if ( *(_DWORD *)a1 > a2 )
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2);
_InterlockedSub((volatile signed __int32 *)(a1 + 8), 1u);
return v2;
}

original_code:
void *cb_vector_array_get(struct cb_vector_array *array, int index){
    void *el = ((void *)0);
    __sync_fetch_and_add(&(array->th), 1);
    el = index >= array->size ? ((void *)0) : array->data[index];
    __sync_fetch_and_sub(&(array->th), 1);
    return el;
}

variable_types: index int

variable_types:
el
void *


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

result = *a1;
v3 = *((_QWORD *)a1 + 2);
*a1 = result + 1;
*(_QWORD *)(v3 + 8 * result) = a2;
return result;
}

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

result = *a1;
v3 = *((_QWORD *)a1 + 2);
*a1 = result + 1;
*(_QWORD *)(v3 + 8 * result) = a2;
return result;
}

original_code:
void cb_vector_array_append(struct cb_vector_array *array, void *data){
    array->data[array->size++] = data;
}


decompiled_code:
void __fastcall cb_vector_free(__int64 a1)
{
unsigned int v1; // eax

v1 = pthread_rwlock_destroy((pthread_rwlock_t *)(a1 + 16));
if ( v1 )
{
fprintf(stderr, "Could not destroy rwlock. Errno: %d\n", v1);
exit(1);
}
cb_vector_array_free(*(void **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
unsigned int v1; // eax

v1 = pthread_rwlock_destroy((pthread_rwlock_t *)(a1 + 16));
if ( v1 )
{
fprintf(stderr, "Could not destroy rwlock. Errno: %d\n", v1);
exit(1);
}
func0(*(void **)(a1 + 8));
}

original_code:
void cb_vector_free(struct cb_vector *vector){
    int errno;
    if (0 != (errno = pthread_rwlock_destroy(&vector->lock_add))) {
        fprintf(stderr, "Could not destroy rwlock. Errno: %d\n", errno);
        exit(1);
    }
    cb_vector_array_free(vector->data);
}

variable_types: struct cb_vector { int capacity; struct cb_vector_array { int size; int capacity; int th; void **data; } *data; union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } lock_add; } *

variable_types: errno int

user_defined_types: struct cb_vector { int capacity; struct cb_vector_array *data; union pthread_rwlock_t lock_add; }

user_defined_types: union pthread_rwlock_t { struct __pthread_rwlock_arch_t __data; char __size[56]; long __align; }


decompiled_code:
void __fastcall cb_vector_free_no_data(__int64 a1)
{
unsigned int v1; // eax

v1 = pthread_rwlock_destroy((pthread_rwlock_t *)(a1 + 16));
if ( v1 )
{
fprintf(stderr, "Could not destroy rwlock. Errno: %d\n", v1);
exit(1);
}
cb_vector_array_free_no_data(*(void **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
unsigned int v1; // eax

v1 = pthread_rwlock_destroy((pthread_rwlock_t *)(a1 + 16));
if ( v1 )
{
fprintf(stderr, "Could not destroy rwlock. Errno: %d\n", v1);
exit(1);
}
func1(*(void **)(a1 + 8));
}

original_code:
void cb_vector_free_no_data(struct cb_vector *vector){
    int errno;
    if (0 != (errno = pthread_rwlock_destroy(&vector->lock_add))) {
        fprintf(stderr, "Could not destroy rwlock. Errno: %d\n", errno);
        exit(1);
    }
    cb_vector_array_free_no_data(vector->data);
}

user_defined_types: struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; }


decompiled_code:
__int64 __fastcall cb_vector_get(__int64 a1, int a2)
{
return cb_vector_array_get(*(_QWORD *)(a1 + 8), a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
return func2(*(_QWORD *)(a1 + 8), a2);
}

original_code:
void *cb_vector_get(struct cb_vector *vector, int index){
    return cb_vector_array_get(vector->data, index);
}


decompiled_code:
void __fastcall cb_vector_expand(__int64 a1)
{
int *v2; // rbp
_QWORD *v3; // rax
__int64 v4; // rcx
__int64 v5; // rsi
__int64 v6; // rdi
signed __int64 v7; // r8
__int64 i; // rax

v2 = *(int **)(a1 + 8);
v3 = cb_vector_array_init(2 * v2[1]);
v4 = *v2;
v5 = *((_QWORD *)v2 + 2);
v6 = v3[2];
v7 = (signed __int64)v3;
*(_DWORD *)v3 = v4;
if ( (int)v4 > 0 )
{
for ( i = 0LL; i != v4; ++i )
*(_QWORD *)(v6 + 8 * i) = *(_QWORD *)(v5 + 8 * i);
}
_InterlockedCompareExchange64((volatile signed __int64 *)(a1 + 8), v7, *(_QWORD *)(a1 + 8));
cb_vector_array_free_no_data(v2);
}

original_code:
void cb_vector_expand(struct cb_vector *vector){
    struct cb_vector_array
      *old_array = vector->data,
      *new_array = cb_vector_array_init(vector->data->capacity*2);
    void **old_data = old_array->data, **new_data = new_array->data;
    int size = old_array->size;
    new_array->size = size;
    for (int i = 0; i < size; i++)
        new_data[i] = old_data[i];
    __sync_val_compare_and_swap(&vector->data, vector->data, new_array);
    cb_vector_array_free_no_data(old_array);
}

canonical_original_code:
void cb_vector_expand(struct cb_vector *vector){
    struct cb_vector_array *old_array = vector->data; struct cb_vector_array *new_array = cb_vector_array_init(vector->data->capacity*2);
    void **old_data = old_array->data; void **new_data = new_array->data;
    int size = old_array->size;
    new_array->size = size;
    for (int i = 0; i < size; i++)
        new_data[i] = old_data[i];
    __sync_val_compare_and_swap(&vector->data, vector->data, new_array);
    cb_vector_array_free_no_data(old_array);
}

variable_types: size int


decompiled_code:
int __fastcall cb_vector_append(__int64 a1, __int64 a2)
{
pthread_rwlock_t *v2; // r12
int *v4; // rdi

v2 = (pthread_rwlock_t *)(a1 + 16);
pthread_rwlock_wrlock((pthread_rwlock_t *)(a1 + 16));
v4 = *(int **)(a1 + 8);
if ( *v4 == *(_DWORD *)a1 )
{
cb_vector_expand(a1);
v4 = *(int **)(a1 + 8);
}
cb_vector_array_append(v4, a2);
return pthread_rwlock_unlock(v2);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, __int64 a2)
{
pthread_rwlock_t *v2; // r12
int *v4; // rdi

v2 = (pthread_rwlock_t *)(a1 + 16);
pthread_rwlock_wrlock((pthread_rwlock_t *)(a1 + 16));
v4 = *(int **)(a1 + 8);
if ( *v4 == *(_DWORD *)a1 )
{
func7(a1);
v4 = *(int **)(a1 + 8);
}
func3(v4, a2);
return pthread_rwlock_unlock(v2);
}

original_code:
void cb_vector_append(struct cb_vector *vector, void *data){
    pthread_rwlock_wrlock(&vector->lock_add);
    if (vector->data->size == vector->capacity)
        cb_vector_expand(vector);
    cb_vector_array_append(vector->data, data);
    pthread_rwlock_unlock(&vector->lock_add);
}