decompiled_code:
void update_values()
{
unsigned __int64 i; // rbx
long double v1; // fst7
long double v2; // fst6
long double v3; // fst6
long double v4; // fst7
__int64 j; // rax

for ( i = 0LL; i != 320; vmid[i / 0x10 - 1] = sigmoid(v3) )
{
v1 = *(long double *)((char *)wmid + i);
i += 32LL;
v2 = v1 * vin[0]
+ mid_offset[i / 0x10 - 2]
+ *(long double *)((char *)&wmid[28] + i + 8) * vin[1]
+ *(long double *)((char *)&wmid[60] + i + 8) * vin[2]
+ *(long double *)((char *)&wmid[92] + i + 8) * vin[3]
+ *(long double *)((char *)&wmid[124] + i + 8) * vin[4];
vmid[i / 0x10 - 2] = v2;
vmid[i / 0x10 - 2] = sigmoid(v2);
v3 = *(long double *)((char *)&wmid[-2] + i + 4) * vin[0]
+ mid_offset[i / 0x10 - 1]
+ *(long double *)((char *)&wmid[30] + i + 4) * vin[1]
+ *(long double *)((char *)&wmid[62] + i + 4) * vin[2]
+ *(long double *)((char *)&wmid[94] + i + 4) * vin[3]
+ *(long double *)((char *)&wmid[126] + i + 4) * vin[4];
vmid[i / 0x10 - 1] = v3;
}
v4 = *(long double *)&out_offset;
for ( j = 0LL;
j != 20;
v4 = v4
+ vmid[j - 10] * wout[j - 10]
+ vmid[j - 9] * wout[j - 9]
+ vmid[j - 8] * wout[j - 8]
+ vmid[j - 7] * wout[j - 7]
+ vmid[j - 6] * wout[j - 6]
+ vmid[j - 5] * wout[j - 5]
+ vmid[j - 4] * wout[j - 4]
+ vmid[j - 3] * wout[j - 3]
+ vmid[j - 2] * wout[j - 2]
+ vmid[j - 1] * wout[j - 1] )
{
j += 10LL;
}
*(long double *)&vout = v4;
*(long double *)&vout = sigmoid(v4);
}

canonical_decompiled_code:
void func4()
{
unsigned __int64 i; // rbx
long double v1; // fst7
long double v2; // fst6
long double v3; // fst6
long double v4; // fst7
__int64 j; // rax

for ( i = 0LL; i != 320; vmid[i / 0x10 - 1] = func3(v3) )
{
v1 = *(long double *)((char *)wmid + i);
i += 32LL;
v2 = v1 * vin[0]
+ mid_offset[i / 0x10 - 2]
+ *(long double *)((char *)&wmid[28] + i + 8) * vin[1]
+ *(long double *)((char *)&wmid[60] + i + 8) * vin[2]
+ *(long double *)((char *)&wmid[92] + i + 8) * vin[3]
+ *(long double *)((char *)&wmid[124] + i + 8) * vin[4];
vmid[i / 0x10 - 2] = v2;
vmid[i / 0x10 - 2] = func3(v2);
v3 = *(long double *)((char *)&wmid[-2] + i + 4) * vin[0]
+ mid_offset[i / 0x10 - 1]
+ *(long double *)((char *)&wmid[30] + i + 4) * vin[1]
+ *(long double *)((char *)&wmid[62] + i + 4) * vin[2]
+ *(long double *)((char *)&wmid[94] + i + 4) * vin[3]
+ *(long double *)((char *)&wmid[126] + i + 4) * vin[4];
vmid[i / 0x10 - 1] = v3;
}
v4 = *(long double *)&out_offset;
for ( j = 0LL;
j != 20;
v4 = v4
+ vmid[j - 10] * wout[j - 10]
+ vmid[j - 9] * wout[j - 9]
+ vmid[j - 8] * wout[j - 8]
+ vmid[j - 7] * wout[j - 7]
+ vmid[j - 6] * wout[j - 6]
+ vmid[j - 5] * wout[j - 5]
+ vmid[j - 4] * wout[j - 4]
+ vmid[j - 3] * wout[j - 3]
+ vmid[j - 2] * wout[j - 2]
+ vmid[j - 1] * wout[j - 1] )
{
j += 10LL;
}
*(long double *)&vout = v4;
*(long double *)&vout = func3(v4);
}

original_code:
static void update_values(void)
{
 int j;
 for(j = 0; j < 20; j++) {
  int i;
  for(i = 0, vmid[j] = mid_offset[j]; i < 5; i++) {
   vmid[j] += vin[i] * wmid[i][j];
  }
  vmid[j] = sigmoid(vmid[j]);
 }
 for(j = 0; j < 1; j++) {
  int i;
  for(i = 0, vout[j] = out_offset[j]; i < 20; i++) {
   vout[j] += vmid[i] * wout[i][j];
  }
  vout[j] = sigmoid(vout[j]);
 }
}

canonical_original_code:
static void update_values()
{
 int j;
 for(j = 0; j < 20; j++) {
  int i;
  for(i = 0, vmid[j] = mid_offset[j]; i < 5; i++) {
   vmid[j] += vin[i] * wmid[i][j];
  }
  vmid[j] = sigmoid(vmid[j]);
 }
 for(j = 0; j < 1; j++) {
  int i;
  for(i = 0, vout[j] = out_offset[j]; i < 20; i++) {
   vout[j] += vmid[i] * wout[i][j];
  }
  vout[j] = sigmoid(vout[j]);
 }
}


cputf

decompiled_code:
int __fastcall cputf(unsigned int a1, long double a2)
{
return printf("\x1B[%dm%LE\x1B[0m ", a1, a2);
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1, long double a2)
{
return printf("\x1B[%dm%LE\x1B[0m ", a1, a2);
}

original_code:
void cputf(long double f, int bg)
{
 printf("\033[%dm%LE\033[0m ", bg, f);
}

variable_types:
f
long double

variable_types: bg int

return_type: void


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

result = (__int64)vin[0];
if ( ((__int64)vin[0] & 1) != 0 )
*(long double *)&expected = 0.0;
else
*(long double *)&expected = 1.0;
return result;
}

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

result = (__int64)vin[0];
if ( ((__int64)vin[0] & 1) != 0 )
*(long double *)&expected = 0.0;
else
*(long double *)&expected = 1.0;
return result;
}

original_code:
void gen_expected_not(void)
{
 unsigned int v1 = vin[0];
 expected[0] = (~v1) & 1;
}

canonical_original_code:
void gen_expected_not()
{
 unsigned int v1 = vin[0];
 expected[0] = (~v1) & 1;
}


decompiled_code:
__int16 gen_expected_xor()
{
__int16 result; // ax
char v1; // [rsp+16h] [rbp-Ah]
char v2; // [rsp+17h] [rbp-9h]

LOBYTE(result) = v1;
HIBYTE(result) = v2 | 0xC;
*(long double *)&expected = (long double)(((unsigned int)(__int64)vin[0] ^ (unsigned int)(__int64)vin[1]) & 1);
return result;
}

canonical_decompiled_code:
__int16 func7()
{
__int16 result; // ax
char v1; // [rsp+16h] [rbp-Ah]
char v2; // [rsp+17h] [rbp-9h]

LOBYTE(result) = v1;
HIBYTE(result) = v2 | 0xC;
*(long double *)&expected = (long double)(((unsigned int)(__int64)vin[0] ^ (unsigned int)(__int64)vin[1]) & 1);
return result;
}

original_code:
void gen_expected_xor(void)
{
 unsigned int v1 = vin[0], v2 = vin[1];
 expected[0] = (v1&1) ^ (v2&1);
}

canonical_original_code:
void gen_expected_xor()
{
 unsigned int v1 = vin[0]; unsigned int v2 = vin[1];
 expected[0] = (v1&1) ^ (v2&1);
}


repo: mpoul/cfed

original_code:
static void cfed_cleanup_idps (cfed_s_context_t *p_ctx)
{
        if (p_ctx == ((void *)0))
                return;
        int i=0;
        int j=0;
        if (p_ctx->conf && p_ctx->conf->idps)
        { while (p_ctx->conf->idps[i] != ((void *)0) )
           {
                if (p_ctx->conf->idps[i]->attrs != ((void *)0))
                { while (p_ctx->conf->idps[i]->attrs[j] != ((void *)0))
                  {
                        cfed_free(p_ctx, p_ctx->conf->idps[i]->attrs[j]->value);
                        cfed_free(p_ctx, p_ctx->conf->idps[i]->attrs[j]);
                        j++;
                  }
                  cfed_free(p_ctx, p_ctx->conf->idps[i]->entity_id);
                  cfed_free(p_ctx, p_ctx->conf->idps[i]->url);
                  cfed_free(p_ctx, p_ctx->conf->idps[i]->attrs);
                  cfed_free(p_ctx, p_ctx->conf->idps[i]);
                }
                  j=0;
                  i++;
           }
           cfed_free(p_ctx, p_ctx->conf->idps);
           p_ctx->conf->idps=((void *)0);
        }
}

canonical_original_code:
static void cfed_cleanup_idps(struct cfed_s_context *p_ctx)
{
        if (p_ctx == ((void *)0))
                return;
        int i = 0;
        int j = 0;
        if (p_ctx->conf && p_ctx->conf->idps)
        { while (p_ctx->conf->idps[i] != ((void *)0) )
           {
                if (p_ctx->conf->idps[i]->attrs != ((void *)0))
                { while (p_ctx->conf->idps[i]->attrs[j] != ((void *)0))
                  {
                        cfed_free(p_ctx, p_ctx->conf->idps[i]->attrs[j]->value);
                        cfed_free(p_ctx, p_ctx->conf->idps[i]->attrs[j]);
                        j++;
                  }
                  cfed_free(p_ctx, p_ctx->conf->idps[i]->entity_id);
                  cfed_free(p_ctx, p_ctx->conf->idps[i]->url);
                  cfed_free(p_ctx, p_ctx->conf->idps[i]->attrs);
                  cfed_free(p_ctx, p_ctx->conf->idps[i]);
                }
                  j=0;
                  i++;
           }
           cfed_free(p_ctx, p_ctx->conf->idps);
           p_ctx->conf->idps=((void *)0);
        }
}

variable_types: struct cfed_s_context { struct cfed_s_idpspconf_t { struct cfed_s_spconf { char *entity_id; char *url; struct cfed_s_idp_attr { enum cfed_e_authn_attrs { CFED_AUTHN_ATTR_START=0, CFED_AUTHN_ATTR_UNAME=1, CFED_AUTHN_ATTR_PASSWORD=2, CFED_AUTHN_ATTR_END=3 } authn_attr; char *value; } **attrs; } **sps; struct cfed_s_idpconf { char *entity_id; char *url; enum cfed_e_authn_type { CFED_AUTHN_TYPE_START=0, CFED_AUTHN_TYPE_BASIC=1, CFED_AUTHN_TYPE_X509=2, CFED_AUTHN_TYPE_FORMPASS=3, CFED_AUTHN_TYPE_END=4 } *authn_type; enum cfed_e_idp_type { CFED_IDP_TYPE_START=0, CFED_IDP_TYPE_STANDARD=1, CFED_IDP_TYPE_EXTENDED=2, CFED_IDP_TYPE_END=3 } idp_type; struct cfed_s_idp_attr **attrs; } **idps; } *conf; char *error; void *curl_handle; struct cfed_s_result { char *raw; char *assertions; int authn_status; } *result; } *

variable_types: i int

variable_types: j int

user_defined_types: struct cfed_s_context { struct cfed_s_idpspconf_t *conf; char *error; void *curl_handle; struct cfed_s_result *result; }

user_defined_types: struct cfed_s_idpspconf_t { struct cfed_s_spconf **sps; struct cfed_s_idpconf **idps; }

user_defined_types: struct cfed_s_spconf { char *entity_id; char *url; struct cfed_s_idp_attr **attrs; }

user_defined_types: struct cfed_s_idpconf { char *entity_id; char *url; enum cfed_e_authn_type *authn_type; enum cfed_e_idp_type idp_type; struct cfed_s_idp_attr **attrs; }

user_defined_types: struct cfed_s_idp_attr { enum cfed_e_authn_attrs authn_attr; char *value; }


decompiled_code:
__int64 __fastcall cfed_cleanup(__int64 a1)
{
__int64 **v2; // rdi
void *v3; // rdi
__int64 result; // rax

if ( a1 )
{
cfed_cleanup_idps(a1);
cfed_cleanup_sps((__int64 ***)a1);
v2 = *(__int64 ***)a1;
if ( v2 )
free(v2);
v3 = *(void **)(a1 + 8);
if ( v3 )
free(v3);
result = curl_easy_cleanup(*(_QWORD *)(a1 + 16));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 **v2; // rdi
void *v3; // rdi
__int64 result; // rax

if ( a1 )
{
func0(a1);
func1((__int64 ***)a1);
v2 = *(__int64 ***)a1;
if ( v2 )
free(v2);
v3 = *(void **)(a1 + 8);
if ( v3 )
free(v3);
result = curl_easy_cleanup(*(_QWORD *)(a1 + 16));
}
return result;
}

original_code:
void cfed_cleanup(cfed_s_context_t *p_ctx)
{
        if (p_ctx == ((void *)0))
                return;
        cfed_cleanup_idps (p_ctx);
        cfed_cleanup_sps (p_ctx);
        if (p_ctx->conf != ((void *)0))
          free (p_ctx->conf);
        if (p_ctx->error != ((void *)0))
            free (p_ctx->error);
 curl_easy_cleanup(p_ctx->curl_handle);
}

canonical_original_code:
void cfed_cleanup(struct cfed_s_context *p_ctx)
{
        if (p_ctx == ((void *)0))
                return;
        cfed_cleanup_idps (p_ctx);
        cfed_cleanup_sps (p_ctx);
        if (p_ctx->conf != ((void *)0))
          free (p_ctx->conf);
        if (p_ctx->error != ((void *)0))
            free (p_ctx->error);
 curl_easy_cleanup(p_ctx->curl_handle);
}

user_defined_types: struct cfed_s_result { char *raw; char *assertions; int authn_status; }

user_defined_types: enum cfed_e_idp_type { CFED_IDP_TYPE_START=0, CFED_IDP_TYPE_STANDARD=1, CFED_IDP_TYPE_EXTENDED=2, CFED_IDP_TYPE_END=3 }

user_defined_types: enum cfed_e_authn_type { CFED_AUTHN_TYPE_START=0, CFED_AUTHN_TYPE_BASIC=1, CFED_AUTHN_TYPE_X509=2, CFED_AUTHN_TYPE_FORMPASS=3, CFED_AUTHN_TYPE_END=4 }

user_defined_types: enum cfed_e_authn_attrs { CFED_AUTHN_ATTR_START=0, CFED_AUTHN_ATTR_UNAME=1, CFED_AUTHN_ATTR_PASSWORD=2, CFED_AUTHN_ATTR_END=3 }


repo: mqudsi/hancock

decompiled_code:
__int64 __fastcall hash_function(const char *a1)
{
size_t v2; // rax
unsigned int v3; // ecx
unsigned __int64 v4; // rdi
unsigned int i; // eax
__int64 v6; // rsi

v2 = strlen(a1);
v3 = 0;
v4 = v2;
for ( i = 0; ; i = 7 * i + a1[v6] )
{
v6 = v3;
if ( v3 >= v4 )
break;
++v3;
}
return i % 0x186A1;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
size_t v2; // rax
unsigned int v3; // ecx
unsigned __int64 v4; // rdi
unsigned int i; // eax
__int64 v6; // rsi

v2 = strlen(a1);
v3 = 0;
v4 = v2;
for ( i = 0; ; i = 7 * i + a1[v6] )
{
v6 = v3;
if ( v3 >= v4 )
break;
++v3;
}
return i % 0x186A1;
}

original_code:
unsigned int hash_function(char * s) {
  unsigned int i = 0;
  unsigned int j;
  for (j=0; j<strlen(s); j++){
    i = 7*i + s[j];
  };
  return i % 100001;
}

canonical_original_code:
unsigned int hash_function(char *s) {
  unsigned int i = 0;
  unsigned int j;
  for (j=0; j<strlen(s); j++){
    i = 7*i + s[j];
  };
  return i % 100001;
}

variable_types:
s
char *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

return_type: unsigned int


decompiled_code:
void *hash_empty()
{
void *result; // rax

result = calloc(0xC3508uLL, 1uLL);
if ( !result )
_assert_fail("s!=NULL", "hash.c", 0x15u, "hash_empty");
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax

result = calloc(0xC3508uLL, 1uLL);
if ( !result )
_assert_fail("s!=NULL", "hash.c", 0x15u, "hash_empty");
return result;
}

original_code:
hash_table * hash_empty() {
  hash_table *s = (hash_table *)malloc(sizeof(hash_table));
  int i;
  ((void) sizeof ((s!=((void *)0)) ? 1 : 0), __extension__ ({ if (s!=((void *)0)) ; else __assert_fail ("s!=NULL", "hash.c", 21, __extension__ __PRETTY_FUNCTION__); }));
  for(i=0;i<100001;i++)
    s->data[i]=0;
  return s;
}

canonical_original_code:
struct hash_table *hash_empty() {
  struct hash_table *s = (hash_table *)malloc(sizeof(hash_table));
  int i;
  ((void) sizeof ((s!=((void *)0)) ? 1 : 0), __extension__ ({ if (s!=((void *)0)) ; else __assert_fail ("s!=NULL", "hash.c", 21, __extension__ __PRETTY_FUNCTION__); }));
  for(i=0;i<100001;i++)
    s->data[i]=0;
  return s;
}

variable_types: struct hash_table { char *data[100001]; } *


decompiled_code:
// attributes: thunk
void hash_close(void *ptr)
{
free(ptr);
}

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

original_code:
void hash_close(hash_table *s){
  free(s);
}

canonical_original_code:
void hash_close(struct hash_table *s){
  free(s);
}

user_defined_types: struct hash_table { char *data[100001]; }


decompiled_code:
int __fastcall hash_insert(__int64 a1, const char *a2, signed int *a3)
{
unsigned int v4; // er14
int v5; // er12
int result; // eax
signed int v7; // ebx
const char *v8; // rdi
size_t v9; // rax
char *v10; // rax

v4 = hash_function(a2);
v5 = v4 + 100001;
do
{
v7 = v4 % 0x186A1;
v8 = *(const char **)(a1 + 8LL * (v4 % 0x186A1));
if ( !v8 )
{
v9 = strlen(a2);
v10 = (char *)malloc(v9 + 1);
*(_QWORD *)(a1 + 8LL * v7) = v10;
strcpy(v10, a2);
*a3 = v7;
return 0;
}
result = strcmp(v8, a2);
if ( !result )
{
*a3 = v7;
return result;
}
++v4;
}
while ( v4 != v5 );
*a3 = -1;
return -1;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, const char *a2, signed int *a3)
{
unsigned int v4; // er14
int v5; // er12
int result; // eax
signed int v7; // ebx
const char *v8; // rdi
size_t v9; // rax
char *v10; // rax

v4 = func0(a2);
v5 = v4 + 100001;
do
{
v7 = v4 % 0x186A1;
v8 = *(const char **)(a1 + 8LL * (v4 % 0x186A1));
if ( !v8 )
{
v9 = strlen(a2);
v10 = (char *)malloc(v9 + 1);
*(_QWORD *)(a1 + 8LL * v7) = v10;
strcpy(v10, a2);
*a3 = v7;
return 0;
}
result = strcmp(v8, a2);
if ( !result )
{
*a3 = v7;
return result;
}
++v4;
}
while ( v4 != v5 );
*a3 = -1;
return -1;
}

original_code:
int hash_insert(hash_table *s, hash_value v, unsigned int *hash) {
  unsigned int index=hash_function(v);
  int offset;
  for(offset=0;offset<100001;offset++) {
    int real_index = (offset+index) % 100001;
    if (0 == s->data[real_index] ) {
      s->data[real_index] = (char *)malloc(strlen(v) + 1);
      strcpy(s->data[real_index], v);
      *hash = real_index;
      return 0;
    }
    if (0 == strcmp(s->data[real_index],v)) {
      *hash = real_index;
      return 0;
    }
  }
  *hash = -1;
  return -1;
}

canonical_original_code:
int hash_insert(struct hash_table *s, char *v, unsigned int *hash) {
  unsigned int index = hash_function(v);
  int offset;
  for(offset=0;offset<100001;offset++) {
    int real_index = (offset+index) % 100001;
    if (0 == s->data[real_index] ) {
      s->data[real_index] = (char *)malloc(strlen(v) + 1);
      strcpy(s->data[real_index], v);
      *hash = real_index;
      return 0;
    }
    if (0 == strcmp(s->data[real_index],v)) {
      *hash = real_index;
      return 0;
    }
  }
  *hash = -1;
  return -1;
}

variable_types:
v
char *

variable_types:
hash
unsigned int *

variable_types:
index
unsigned int

variable_types: offset int

return_type: int


decompiled_code:
__int64 __fastcall hash_insert_pair(__int64 a1, const char *a2, unsigned int a3)
{
__int64 v3; // rbp
const char *v5; // rdi
size_t v7; // rax
char *v8; // rax

v3 = a3;
v5 = *(const char **)(a1 + 8LL * a3);
if ( v5 )
return (unsigned int)-(strcmp(v5, a2) != 0);
v7 = strlen(a2);
v8 = (char *)malloc(v7 + 1);
*(_QWORD *)(a1 + 8 * v3) = v8;
strcpy(v8, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, unsigned int a3)
{
__int64 v3; // rbp
const char *v5; // rdi
size_t v7; // rax
char *v8; // rax

v3 = a3;
v5 = *(const char **)(a1 + 8LL * a3);
if ( v5 )
return (unsigned int)-(strcmp(v5, a2) != 0);
v7 = strlen(a2);
v8 = (char *)malloc(v7 + 1);
*(_QWORD *)(a1 + 8 * v3) = v8;
strcpy(v8, a2);
return 0LL;
}

original_code:
int hash_insert_pair(hash_table *s, hash_value v, unsigned int hash){
   if (0 == s->data[hash] ) {
      s->data[hash] = (char *)malloc(strlen(v) + 1);
      strcpy(s->data[hash], v);
      return 0;
    }
    if (0 == strcmp(s->data[hash],v)) {
      return 0;
    }
    return -1;
}

canonical_original_code:
int hash_insert_pair(struct hash_table *s, char *v, unsigned int hash){
   if (0 == s->data[hash] ) {
      s->data[hash] = (char *)malloc(strlen(v) + 1);
      strcpy(s->data[hash], v);
      return 0;
    }
    if (0 == strcmp(s->data[hash],v)) {
      return 0;
    }
    return -1;
}

variable_types:
hash
unsigned int


decompiled_code:
__int64 __fastcall hash_lookup(__int64 a1, unsigned int a2)
{
return *(_QWORD *)(a1 + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
return *(_QWORD *)(a1 + 8LL * a2);
}

original_code:
hash_value hash_lookup(hash_table *s, unsigned int hash){
  return s->data[hash];
}

canonical_original_code:
char *hash_lookup(struct hash_table *s, unsigned int hash){
  return s->data[hash];
}

return_type: char *


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

result = malloc(8uLL);
*result = 0;
return result;
}

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

result = malloc(8uLL);
*result = 0;
return result;
}

original_code:
hash_iter hash_init_iter(hash_table *s){
  int *val=(int*)malloc(sizeof(int *));
  *val = 0;
  return val;
}

canonical_original_code:
int *hash_init_iter(struct hash_table *s){
  int *val = (int*)malloc(sizeof(int *));
  *val = 0;
  return val;
}

variable_types:
val
int *

return_type: int *


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

v4 = *a2;
if ( (int)v4 > 100000 )
return 0LL;
while ( 1 )
{
v6 = *(_QWORD *)(a1 + 8 * v4);
if ( v6 )
break;
*a2 = ++v4;
if ( (int)v4 > 100000 )
return 0LL;
}
*a3 = v6;
*a4 = v4;
result = 1LL;
++*a2;
return result;
}

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

v4 = *a2;
if ( (int)v4 > 100000 )
return 0LL;
while ( 1 )
{
v6 = *(_QWORD *)(a1 + 8 * v4);
if ( v6 )
break;
*a2 = ++v4;
if ( (int)v4 > 100000 )
return 0LL;
}
*a3 = v6;
*a4 = v4;
result = 1LL;
++*a2;
return result;
}

original_code:
int hash_next(hash_table *s, hash_iter i, hash_value *v, unsigned int *hash){
  while ((*i < 100001) && (0 == s->data[*i])) (*i)++;
  if (*i < 100001) {
    *v = s->data[*i];
    *hash = *i;
    (*i)++;
    return 1;
  } else {
    return 0;
  }
}

canonical_original_code:
int hash_next(struct hash_table *s, int *i, char **v, unsigned int *hash){
  while ((*i < 100001) && (0 == s->data[*i])) (*i)++;
  if (*i < 100001) {
    *v = s->data[*i];
    *hash = *i;
    (*i)++;
    return 1;
  } else {
    return 0;
  }
}

variable_types:
i
int *

variable_types:
v
char **


decompiled_code:
void __fastcall hash_close_iter(__int64 a1, void *a2)
{
free(a2);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, void *a2)
{
free(a2);
}

original_code:
void hash_close_iter(hash_table *s, hash_iter i) {
  free(i);
}

canonical_original_code:
void hash_close_iter(struct hash_table *s, int *i) {
  free(i);
}


freeExerciseDescriptor

repo: mquinson/CLE

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

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

original_code:
void freeExerciseDescriptor(exercise_desc *ex)
{
  free(ex->exerciseName);
  free(ex->exerciseConstructor);
  free(ex);
}

canonical_original_code:
void freeExerciseDescriptor(struct exercise_desc *ex)
{
  free(ex->exerciseName);
  free(ex->exerciseConstructor);
  free(ex);
}

variable_types: struct exercise_desc { char *exerciseName; char *exerciseConstructor; } *


newEntity

decompiled_code:
double *__fastcall newEntity(int a1, int a2, double a3)
{
double *result; // rax

result = (double *)malloc(0x10uLL);
*(_DWORD *)result = a1;
*((_DWORD *)result + 1) = a2;
result[1] = a3;
return result;
}

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

result = (double *)malloc(0x10uLL);
*(_DWORD *)result = a1;
*((_DWORD *)result + 1) = a2;
result[1] = a3;
return result;
}

original_code:
entity* newEntity(int x, int y, double ang)
{
  entity* result = malloc(sizeof(entity));
  result->x =x;
  result->y=y;
  result->ang=ang;
  return result;
}

canonical_original_code:
struct entity *newEntity(int x, int y, double ang)
{
  struct entity *result = malloc(sizeof(entity));
  result->x =x;
  result->y=y;
  result->ang=ang;
  return result;
}

variable_types: x int

variable_types: y int

variable_types: ang double

variable_types: struct entity { int x; int y; double ang; } *


freeEntity

decompiled_code:
// attributes: thunk
void freeEntity(void *ptr)
{
free(ptr);
}

original_code:
void freeEntity(entity* en)
{
  free(en);
}

canonical_original_code:
void freeEntity(struct entity *en)
{
  free(en);
}

user_defined_types: struct entity { int x; int y; double ang; }


freeWorld

decompiled_code:
// attributes: thunk
void __fastcall freeWorld(void *ptr)
{
freeEntity(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
func2(ptr);
}

original_code:
void freeWorld(world* w)
{
  free(w);
}

canonical_original_code:
void freeWorld(struct world *w)
{
  free(w);
}

variable_types:
w
struct world { double x; double y; } *


newVoidLessonContent

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

result = malloc(0x28uLL);
result[6] = 0;
*((_QWORD *)result + 4) = 0LL;
*((_QWORD *)result + 2) = 0LL;
*((_QWORD *)result + 1) = 0LL;
*(_QWORD *)result = 0LL;
return result;
}

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

result = malloc(0x28uLL);
result[6] = 0;
*((_QWORD *)result + 4) = 0LL;
*((_QWORD *)result + 2) = 0LL;
*((_QWORD *)result + 1) = 0LL;
*(_QWORD *)result = 0LL;
return result;
}

original_code:
lesson_content* newVoidLessonContent()
{
  lesson_content* result = malloc(sizeof(lesson_content));
  result->amount =0;
  result->exercises = ((void *)0);
  result->filename=((void *)0);
  result->lesson_name_file = ((void *)0);
  result->lesson_name=((void *)0);
  return result;
}

canonical_original_code:
struct lesson_content *newVoidLessonContent()
{
  struct lesson_content *result = malloc(sizeof(lesson_content));
  result->amount =0;
  result->exercises = ((void *)0);
  result->filename=((void *)0);
  result->lesson_name_file = ((void *)0);
  result->lesson_name=((void *)0);
  return result;
}

variable_types: struct lesson_content { char *lesson_name; char *lesson_name_file; char *filename; int amount; struct exercise_desc { char *exerciseName; char *exerciseConstructor; } **exercises; } *

user_defined_types: struct lesson_content { char *lesson_name; char *lesson_name_file; char *filename; int amount; struct exercise_desc **exercises; }


generateLessonFromName

decompiled_code:
void __fastcall generateLessonFromName(__int64 a1, const char *a2)
{
void *v3; // rdi
void *v4; // rdi
size_t v5; // rbx
char *v6; // rax
const char *v7; // r12
size_t v8; // rbp
const unsigned __int16 **v9; // rax
__int64 v10; // r14
char *v11; // rax

if ( a1 )
{
v3 = *(void **)(a1 + 8);
if ( v3 )
free(v3);
if ( *(_QWORD *)a1 )
free(*(void **)a1);
v4 = *(void **)(a1 + 16);
if ( v4 )
free(v4);
v5 = 0LL;
*(_QWORD *)a1 = strdup(a2);
v6 = strdup(a2);
*(_QWORD *)(a1 + 8) = v6;
v7 = v6;
v8 = strlen(v6);
while ( v5 < v8 )
{
v9 = _ctype_b_loc();
v10 = v7[v5];
if ( ((*v9)[v10] & 0x400) != 0 )
{
v7[v5] = (*_ctype_tolower_loc())[v10];
v7 = *(const char **)(a1 + 8);
v8 = strlen(v7);
}
++v5;
}
v11 = (char *)malloc(2 * v8 + 4);
*(_QWORD *)(a1 + 16) = v11;
sprintf(v11, "%s/%s.c", v7, v7);
}
}

original_code:
void generateLessonFromName(lesson_content* lesson, char* name)
{
    if(lesson==((void *)0))
      return;
    if(lesson->lesson_name_file)
      free(lesson->lesson_name_file);
    if(lesson->lesson_name)
      free(lesson->lesson_name);
    if(lesson->filename)
      free(lesson->filename);
    lesson->lesson_name = strdup(name);
    lesson->lesson_name_file = strdup(name);
    int i=0;
    for(; i<strlen(lesson->lesson_name_file); ++i)
    {
      if(((*__ctype_b_loc ())[(int) ((lesson->lesson_name_file[i]))] & (unsigned short int) _ISalpha))
      {
 lesson->lesson_name_file[i] = tolower(lesson->lesson_name_file[i]);
      }
    }
    lesson->filename= malloc(sizeof(char)*(strlen(lesson->lesson_name_file)*2+4));
    sprintf(lesson->filename, "%s/%s.c", lesson->lesson_name_file, lesson->lesson_name_file);
}

canonical_original_code:
void generateLessonFromName(struct lesson_content *lesson, char *name)
{
    if(lesson==((void *)0))
      return;
    if(lesson->lesson_name_file)
      free(lesson->lesson_name_file);
    if(lesson->lesson_name)
      free(lesson->lesson_name);
    if(lesson->filename)
      free(lesson->filename);
    lesson->lesson_name = strdup(name);
    lesson->lesson_name_file = strdup(name);
    int i = 0;
    for(; i<strlen(lesson->lesson_name_file); ++i)
    {
      if(((*__ctype_b_loc ())[(int) ((lesson->lesson_name_file[i]))] & (unsigned short) _ISalpha))
      {
 lesson->lesson_name_file[i] = tolower(lesson->lesson_name_file[i]);
      }
    }
    lesson->filename= malloc(sizeof(char)*(strlen(lesson->lesson_name_file)*2+4));
    sprintf(lesson->filename, "%s/%s.c", lesson->lesson_name_file, lesson->lesson_name_file);
}

variable_types:
name
char *

variable_types: i int

user_defined_types: struct exercise_desc { char *exerciseName; char *exerciseConstructor; }


freeLessonContent

decompiled_code:
void __fastcall freeLessonContent(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
__int64 v4; // rbx
void *v5; // rdi
void *v6; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
if ( *((int *)ptr + 6) > 0 )
{
v4 = 0LL;
do
{
v5 = *(void **)(*((_QWORD *)ptr + 4) + 8 * v4++);
freeExerciseDescriptor(v5);
}
while ( *((_DWORD *)ptr + 6) > (int)v4 );
}
v6 = (void *)*((_QWORD *)ptr + 4);
if ( v6 )
free(v6);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
__int64 v4; // rbx
void *v5; // rdi
void *v6; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
if ( *((int *)ptr + 6) > 0 )
{
v4 = 0LL;
do
{
v5 = *(void **)(*((_QWORD *)ptr + 4) + 8 * v4++);
func0(v5);
}
while ( *((_DWORD *)ptr + 6) > (int)v4 );
}
v6 = (void *)*((_QWORD *)ptr + 4);
if ( v6 )
free(v6);
free(ptr);
}
}

original_code:
void freeLessonContent(lesson_content* lesson)
{
  if(lesson==((void *)0))
      return;
  if(lesson->lesson_name_file)
    free(lesson->lesson_name_file);
  if(lesson->lesson_name)
    free(lesson->lesson_name);
  if(lesson->filename)
    free(lesson->filename);
  int i=0;
  for(;i<lesson->amount; ++i)
    freeExerciseDescriptor(lesson->exercises[i]);
  if(lesson->exercises)
    free(lesson->exercises);
  free(lesson);
}

canonical_original_code:
void freeLessonContent(struct lesson_content *lesson)
{
  if(lesson==((void *)0))
      return;
  if(lesson->lesson_name_file)
    free(lesson->lesson_name_file);
  if(lesson->lesson_name)
    free(lesson->lesson_name);
  if(lesson->filename)
    free(lesson->filename);
  int i = 0;
  for(;i<lesson->amount; ++i)
    freeExerciseDescriptor(lesson->exercises[i]);
  if(lesson->exercises)
    free(lesson->exercises);
  free(lesson);
}


addExerciseToLesson

original_code:
int addExerciseToLesson(lesson_content* lesson, exercise_desc* desc)
{
  int i;
  for(i=0; i< lesson->amount; ++i)
  {
    if(!strcmp(lesson->exercises[i]->exerciseConstructor, desc->exerciseConstructor))
      return 0;
  }
  exercise_desc** temp = malloc(sizeof(exercise_desc* )*(lesson->amount+1));
  for(i=0;i<lesson->amount; ++i)
  {
    temp[i] = lesson->exercises[i];
  }
  if(lesson->exercises)
    free(lesson->exercises);
  temp[lesson->amount] = desc;
  lesson->exercises = temp;
  ++(lesson->amount);
  return 1;
}

canonical_original_code:
int addExerciseToLesson(struct lesson_content *lesson, struct exercise_desc *desc)
{
  int i;
  for(i=0; i< lesson->amount; ++i)
  {
    if(!strcmp(lesson->exercises[i]->exerciseConstructor, desc->exerciseConstructor))
      return 0;
  }
  struct exercise_desc **temp = malloc(sizeof(exercise_desc* )*(lesson->amount+1));
  for(i=0;i<lesson->amount; ++i)
  {
    temp[i] = lesson->exercises[i];
  }
  if(lesson->exercises)
    free(lesson->exercises);
  temp[lesson->amount] = desc;
  lesson->exercises = temp;
  ++(lesson->amount);
  return 1;
}

variable_types:
desc
struct exercise_desc *

variable_types: struct exercise_desc { char *exerciseName; char *exerciseConstructor; } **


newVoidExoContent

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

result = malloc(0x58uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
*((_DWORD *)result + 10) = 0;
result[6] = 0LL;
*((_DWORD *)result + 14) = 0;
result[8] = 0LL;
*((_DWORD *)result + 18) = 0;
result[10] = 0LL;
return result;
}

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

result = malloc(0x58uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
*((_DWORD *)result + 10) = 0;
result[6] = 0LL;
*((_DWORD *)result + 14) = 0;
result[8] = 0LL;
*((_DWORD *)result + 18) = 0;
result[10] = 0LL;
return result;
}

original_code:
exo_content* newVoidExoContent()
{
  exo_content *result = malloc(sizeof(exo_content));
  result->w=((void *)0);
  result->e=((void *)0);
  result->lesson_name=((void *)0);
  result->exercise_name=((void *)0);
  result->exercise_file_name = ((void *)0);
  result->descriptionSize=0;
  result->description=((void *)0);
  result->codeEleveSize=0;
  result->codeEleve=((void *)0);
  result->codeProfSize=0;
  result->codeProf=((void *)0);
  return result;
}

canonical_original_code:
struct exo_content *newVoidExoContent()
{
  struct exo_content *result = malloc(sizeof(exo_content));
  result->w=((void *)0);
  result->e=((void *)0);
  result->lesson_name=((void *)0);
  result->exercise_name=((void *)0);
  result->exercise_file_name = ((void *)0);
  result->descriptionSize=0;
  result->description=((void *)0);
  result->codeEleveSize=0;
  result->codeEleve=((void *)0);
  result->codeProfSize=0;
  result->codeProf=((void *)0);
  return result;
}

variable_types: struct exo_content { struct world { double x; double y; } *w; struct entity { int x; int y; double ang; } *e; char *lesson_name; char *exercise_name; char *exercise_file_name; int descriptionSize; char **description; int codeEleveSize; char **codeEleve; int codeProfSize; char **codeProf; } *

user_defined_types: struct exo_content { struct world *w; struct entity *e; char *lesson_name; char *exercise_name; char *exercise_file_name; int descriptionSize; char **description; int codeEleveSize; char **codeEleve; int codeProfSize; char **codeProf; }


addWorldToExoContent

decompiled_code:
void __fastcall addWorldToExoContent(void **a1, void *a2)
{
void *v3; // rdi

v3 = *a1;
if ( v3 )
free(v3);
*a1 = a2;
}

canonical_decompiled_code:
void __fastcall func10(void **a1, void *a2)
{
void *v3; // rdi

v3 = *a1;
if ( v3 )
free(v3);
*a1 = a2;
}

original_code:
void addWorldToExoContent(exo_content* ex, world* w)
{
  if(ex->w)
    free(ex->w);
  ex->w=w;
}

canonical_original_code:
void addWorldToExoContent(struct exo_content *ex, struct world *w)
{
  if(ex->w)
    free(ex->w);
  ex->w=w;
}

variable_types:
w
struct world *


addEntityToExoContent

decompiled_code:
void __fastcall addEntityToExoContent(__int64 a1, __int64 a2)
{
void *v3; // rdi

v3 = *(void **)(a1 + 8);
if ( v3 )
free(v3);
*(_QWORD *)(a1 + 8) = a2;
}

original_code:
void addEntityToExoContent(exo_content* ex, entity* e)
{
  if(ex->e)
    free(ex->e);
  ex->e=e;
}

canonical_original_code:
void addEntityToExoContent(struct exo_content *ex, struct entity *e)
{
  if(ex->e)
    free(ex->e);
  ex->e=e;
}

variable_types:
e
struct entity *


addDescription

original_code:
void addDescription(exo_content* ex, char* description)
{
  char** temp = malloc(sizeof(char*)*(ex->descriptionSize+1));
  int i = 0;
  for(; i< ex->descriptionSize; ++i)
    temp[i] = ex->description[i];
  free(ex->description);
  temp[ex->descriptionSize] = strdup(description);
  ex->description = temp;
  ++(ex->descriptionSize);
}

canonical_original_code:
void addDescription(struct exo_content *ex, char *description)
{
  char **temp = malloc(sizeof(char*)*(ex->descriptionSize+1));
  int i = 0;
  for(; i< ex->descriptionSize; ++i)
    temp[i] = ex->description[i];
  free(ex->description);
  temp[ex->descriptionSize] = strdup(description);
  ex->description = temp;
  ++(ex->descriptionSize);
}

variable_types:
description
char *

variable_types:
temp
char **


addCodeEleve

original_code:
void addCodeEleve(exo_content* ex, char* codeEleve)
{
  char** temp = malloc(sizeof(char*)*(ex->codeEleveSize+1));
  int i = 0;
  for(; i< ex->codeEleveSize; ++i)
    temp[i] = ex->codeEleve[i];
  free(ex->codeEleve);
  temp[ex->codeEleveSize] = strdup(codeEleve);
  ex->codeEleve = temp;
  ++(ex->codeEleveSize);
}

canonical_original_code:
void addCodeEleve(struct exo_content *ex, char *codeEleve)
{
  char **temp = malloc(sizeof(char*)*(ex->codeEleveSize+1));
  int i = 0;
  for(; i< ex->codeEleveSize; ++i)
    temp[i] = ex->codeEleve[i];
  free(ex->codeEleve);
  temp[ex->codeEleveSize] = strdup(codeEleve);
  ex->codeEleve = temp;
  ++(ex->codeEleveSize);
}

variable_types:
codeEleve
char *


addCodeProf

original_code:
void addCodeProf(exo_content* ex, char* codeProf)
{
  char** temp = malloc(sizeof(char*)*(ex->codeProfSize+1));
  int i = 0;
  for(; i< ex->codeProfSize; ++i)
    temp[i] = ex->codeProf[i];
  free(ex->codeProf);
  temp[ex->codeProfSize] = strdup(codeProf);
  ex->codeProf = temp;
  ++(ex->codeProfSize);
}

canonical_original_code:
void addCodeProf(struct exo_content *ex, char *codeProf)
{
  char **temp = malloc(sizeof(char*)*(ex->codeProfSize+1));
  int i = 0;
  for(; i< ex->codeProfSize; ++i)
    temp[i] = ex->codeProf[i];
  free(ex->codeProf);
  temp[ex->codeProfSize] = strdup(codeProf);
  ex->codeProf = temp;
  ++(ex->codeProfSize);
}

variable_types:
codeProf
char *


setLessonName

decompiled_code:
size_t __fastcall setLessonName(__int64 a1, const char *a2)
{
void *v3; // rdi
size_t v4; // rbx
char *v5; // rax
const char *v6; // r12
size_t result; // rax
size_t v8; // rbp
const unsigned __int16 **v9; // rax
__int64 v10; // r14

v3 = *(void **)(a1 + 16);
if ( v3 )
free(v3);
v4 = 0LL;
v5 = strdup(a2);
*(_QWORD *)(a1 + 16) = v5;
v6 = v5;
result = strlen(v5);
v8 = result;
while ( v4 < v8 )
{
v9 = _ctype_b_loc();
v10 = v6[v4];
result = (size_t)*v9;
if ( (*(_BYTE *)(result + 2 * v10 + 1) & 4) != 0 )
{
v6[v4] = (*_ctype_tolower_loc())[v10];
v6 = *(const char **)(a1 + 16);
result = strlen(v6);
v8 = result;
}
++v4;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func15(__int64 a1, const char *a2)
{
void *v3; // rdi
size_t v4; // rbx
char *v5; // rax
const char *v6; // r12
size_t result; // rax
size_t v8; // rbp
const unsigned __int16 **v9; // rax
__int64 v10; // r14

v3 = *(void **)(a1 + 16);
if ( v3 )
free(v3);
v4 = 0LL;
v5 = strdup(a2);
*(_QWORD *)(a1 + 16) = v5;
v6 = v5;
result = strlen(v5);
v8 = result;
while ( v4 < v8 )
{
v9 = _ctype_b_loc();
v10 = v6[v4];
result = (size_t)*v9;
if ( (*(_BYTE *)(result + 2 * v10 + 1) & 4) != 0 )
{
v6[v4] = (*_ctype_tolower_loc())[v10];
v6 = *(const char **)(a1 + 16);
result = strlen(v6);
v8 = result;
}
++v4;
}
return result;
}

original_code:
void setLessonName(exo_content* ex, char* lesson_name)
{
  if(ex->lesson_name)
    free(ex->lesson_name);
  ex->lesson_name = strdup(lesson_name);
  int i=0;
  for(; i<strlen(ex->lesson_name) ; ++i)
  {
    if(((*__ctype_b_loc ())[(int) ((ex->lesson_name[i]))] & (unsigned short int) _ISalpha))
      ex->lesson_name[i] = tolower(ex->lesson_name[i]);
  }
}

canonical_original_code:
void setLessonName(struct exo_content *ex, char *lesson_name)
{
  if(ex->lesson_name)
    free(ex->lesson_name);
  ex->lesson_name = strdup(lesson_name);
  int i = 0;
  for(; i<strlen(ex->lesson_name) ; ++i)
  {
    if(((*__ctype_b_loc ())[(int) ((ex->lesson_name[i]))] & (unsigned short) _ISalpha))
      ex->lesson_name[i] = tolower(ex->lesson_name[i]);
  }
}


isLessonDefined

decompiled_code:
_BOOL8 __fastcall isLessonDefined(__int64 a1)
{
return *(_QWORD *)(a1 + 16) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(__int64 a1)
{
return *(_QWORD *)(a1 + 16) != 0LL;
}

original_code:
int isLessonDefined(exo_content* ex)
{
  if(ex->lesson_name)
    return 1;
  return 0;
}

canonical_original_code:
int isLessonDefined(struct exo_content *ex)
{
  if(ex->lesson_name)
    return 1;
  return 0;
}


setExerciseName

decompiled_code:
size_t __fastcall setExerciseName(__int64 a1, const char *a2)
{
void *v3; // rdi
void *v4; // rdi
size_t v5; // rbx
char *v6; // rax
const char *v7; // r12
const unsigned __int16 **v8; // rax
char *v9; // r14
__int64 v10; // r15
const unsigned __int16 **v11; // rbp
unsigned __int16 v12; // ax
size_t result; // rax

v3 = *(void **)(a1 + 24);
if ( v3 )
free(v3);
v4 = *(void **)(a1 + 32);
if ( v4 )
free(v4);
v5 = 0LL;
*(_QWORD *)(a1 + 24) = strdup(a2);
v6 = strdup(a2);
*(_QWORD *)(a1 + 32) = v6;
v7 = v6;
while ( 1 )
{
result = strlen(v7);
if ( result <= v5 )
break;
v8 = _ctype_b_loc();
v9 = (char *)&v7[v5];
v10 = v7[v5];
v11 = v8;
v12 = (*v8)[v10];
if ( (v12 & 0x400) != 0 )
{
*v9 = (*_ctype_tolower_loc())[v10];
v7 = *(const char **)(a1 + 32);
v9 = (char *)&v7[v5];
v12 = (*v11)[v7[v5]];
}
if ( (v12 & 8) == 0 )
{
*v9 = 95;
v7 = *(const char **)(a1 + 32);
}
++v5;
}
return result;
}

original_code:
void setExerciseName(exo_content* ex, char* exercise_name)
{
  if(ex->exercise_name)
    free(ex->exercise_name);
  if(ex->exercise_file_name)
    free(ex->exercise_file_name);
  ex->exercise_name = strdup(exercise_name);
  ex->exercise_file_name = strdup(exercise_name);
  int i=0;
  for(; i<strlen(ex->exercise_file_name) ; ++i)
  {
    if(((*__ctype_b_loc ())[(int) ((ex->exercise_file_name[i]))] & (unsigned short int) _ISalpha))
      ex->exercise_file_name[i] = tolower(ex->exercise_file_name[i]);
    if(!((*__ctype_b_loc ())[(int) ((ex->exercise_file_name[i]))] & (unsigned short int) _ISalnum))
      ex->exercise_file_name[i]='_';
  }
}

canonical_original_code:
void setExerciseName(struct exo_content *ex, char *exercise_name)
{
  if(ex->exercise_name)
    free(ex->exercise_name);
  if(ex->exercise_file_name)
    free(ex->exercise_file_name);
  ex->exercise_name = strdup(exercise_name);
  ex->exercise_file_name = strdup(exercise_name);
  int i = 0;
  for(; i<strlen(ex->exercise_file_name) ; ++i)
  {
    if(((*__ctype_b_loc ())[(int) ((ex->exercise_file_name[i]))] & (unsigned short) _ISalpha))
      ex->exercise_file_name[i] = tolower(ex->exercise_file_name[i]);
    if(!((*__ctype_b_loc ())[(int) ((ex->exercise_file_name[i]))] & (unsigned short) _ISalnum))
      ex->exercise_file_name[i]='_';
  }
}


isExerciseNameDefined

decompiled_code:
_BOOL8 __fastcall isExerciseNameDefined(__int64 a1)
{
return *(_QWORD *)(a1 + 24) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func18(__int64 a1)
{
return *(_QWORD *)(a1 + 24) != 0LL;
}

original_code:
int isExerciseNameDefined(exo_content* ex)
{
  if(ex->exercise_name)
    return 1;
  return 0;
}

canonical_original_code:
int isExerciseNameDefined(struct exo_content *ex)
{
  if(ex->exercise_name)
    return 1;
  return 0;
}


freeExerciseContent

original_code:
void freeExerciseContent(exo_content* ex)
{
  if(ex->w)
    free(ex->w);
  if(ex->e)
    free(ex->e);
  if(ex->lesson_name)
    free(ex->lesson_name);
  if(ex->exercise_file_name)
    free(ex->exercise_file_name);
  if(ex->exercise_name)
    free(ex->exercise_name);
  int i;
  for(i=0; i< ex->descriptionSize; ++i)
    free(ex->description[i]);
  if(ex->description)
    free(ex->description);
  for(i=0; i< ex->codeEleveSize; ++i)
    free(ex->codeEleve[i]);
  if(ex->codeEleve)
    free(ex->codeEleve);
  for(i=0; i< ex->codeProfSize; ++i)
    free(ex->codeProf[i]);
  if(ex->codeProf)
    free(ex->codeProf);
  free(ex);
}

canonical_original_code:
void freeExerciseContent(struct exo_content *ex)
{
  if(ex->w)
    free(ex->w);
  if(ex->e)
    free(ex->e);
  if(ex->lesson_name)
    free(ex->lesson_name);
  if(ex->exercise_file_name)
    free(ex->exercise_file_name);
  if(ex->exercise_name)
    free(ex->exercise_name);
  int i;
  for(i=0; i< ex->descriptionSize; ++i)
    free(ex->description[i]);
  if(ex->description)
    free(ex->description);
  for(i=0; i< ex->codeEleveSize; ++i)
    free(ex->codeEleve[i]);
  if(ex->codeEleve)
    free(ex->codeEleve);
  for(i=0; i< ex->codeProfSize; ++i)
    free(ex->codeProf[i]);
  if(ex->codeProf)
    free(ex->codeProf);
  free(ex);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // rbp
__int64 v5; // r13

v3 = newVoidExoContent(argc, argv, envp);
v4 = newVoidLessonContent();
if ( argc <= 1 )
puts("Erreur dans l'entree du parametre aucun parametre donne");
parseFile(v3, argv[1]);
v5 = generateExerciseDescriptor(v3);
parseLessonFile(v4, v3);
generateExerciseFile(v3, v4);
if ( !(unsigned int)addExerciseToLesson(v4, v5) )
freeExerciseDescriptor(v5);
generateLessonFile(v4);
generateExerciseHeader(v4);
freeLessonContent(v4);
freeExerciseContent(v3);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  exo_content *exercise = newVoidExoContent();
  lesson_content* lesson = newVoidLessonContent();
  if(argc < 2)
  {
    printf("Erreur dans l'entree du parametre aucun parametre donne\n");
  }
  parseFile(exercise, argv[1]);
  exercise_desc* descrip = generateExerciseDescriptor(exercise);
  parseLessonFile(lesson, exercise);
  generateExerciseFile(exercise, lesson);
  if(!addExerciseToLesson(lesson, descrip))
    freeExerciseDescriptor(descrip);
  generateLessonFile(lesson);
  generateExerciseHeader(lesson);
  freeLessonContent(lesson);
  freeExerciseContent(exercise);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct exo_content *exercise = newVoidExoContent();
  struct lesson_content *lesson = newVoidLessonContent();
  if(argc < 2)
  {
    printf("Erreur dans l'entree du parametre aucun parametre donne\n");
  }
  parseFile(exercise, argv[1]);
  struct exercise_desc *descrip = generateExerciseDescriptor(exercise);
  parseLessonFile(lesson, exercise);
  generateExerciseFile(exercise, lesson);
  if(!addExerciseToLesson(lesson, descrip))
    freeExerciseDescriptor(descrip);
  generateLessonFile(lesson);
  generateExerciseHeader(lesson);
  freeLessonContent(lesson);
  freeExerciseContent(exercise);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct exercise_desc { char *exerciseName; char *exerciseConstructor; } *


processWorldBalise

decompiled_code:
int __fastcall processWorldBalise(char *a1, __int64 a2)
{
char v2; // dl
char *v3; // rax
__int64 v4; // rax
double v6; // [rsp+0h] [rbp-18h] BYREF
double v7; // [rsp+8h] [rbp-10h] BYREF

v2 = *a1;
if ( *a1 == 9 || v2 == 32 )
{
v3 = a1 + 1;
while ( v2 != 10 )
{
v2 = *v3;
a1 = v3++;
if ( v2 != 9 && v2 != 32 )
goto LABEL_7;
}
}
else
{
LABEL_7:
if ( v2 != 10 )
{
_isoc99_sscanf(a1, "%lf %lf", &v6, &v7);
v4 = newWorld(v6, v7);
return addWorldToExoContent(a2, v4);
}
}
return puts(aErreurLorsDuD);
}

canonical_decompiled_code:
int __fastcall func0(char *a1, __int64 a2)
{
char v2; // dl
char *v3; // rax
__int64 v4; // rax
double v6; // [rsp+0h] [rbp-18h] BYREF
double v7; // [rsp+8h] [rbp-10h] BYREF

v2 = *a1;
if ( *a1 == 9 || v2 == 32 )
{
v3 = a1 + 1;
while ( v2 != 10 )
{
v2 = *v3;
a1 = v3++;
if ( v2 != 9 && v2 != 32 )
goto LABEL_7;
}
}
else
{
LABEL_7:
if ( v2 != 10 )
{
_isoc99_sscanf(a1, "%lf %lf", &v6, &v7);
v4 = newWorld(v6, v7);
return addWorldToExoContent(a2, v4);
}
}
return puts(aErreurLorsDuD);
}

original_code:
void processWorldBalise(char* line, exo_content* ex)
{
  int decalage=0;
     while((line[decalage] == '\t' || line[decalage] == ' ') && line[decalage]!='\n')
 ++decalage;
     if(line[decalage]=='\n')
   {
     printf("Erreur lors du décriptage de la balise world\n");
     return;
   }
   double x, y;
    sscanf(line+decalage, "%lf %lf", &x, &y);
    addWorldToExoContent(ex, newWorld(x,y));
}

canonical_original_code:
void processWorldBalise(char *line, struct exo_content *ex)
{
  int decalage = 0;
     while((line[decalage] == '\t' || line[decalage] == ' ') && line[decalage]!='\n')
 ++decalage;
     if(line[decalage]=='\n')
   {
     printf("Erreur lors du décriptage de la balise world\n");
     return;
   }
   double x; double y;
    sscanf(line+decalage, "%lf %lf", &x, &y);
    addWorldToExoContent(ex, newWorld(x,y));
}

variable_types:
line
char *

variable_types: decalage int

variable_types: x double

variable_types: y double


processEntityBalise

decompiled_code:
int __fastcall processEntityBalise(char *a1, __int64 a2)
{
char v2; // dl
char *v3; // rax
__int64 v4; // rax
unsigned int v6; // [rsp+0h] [rbp-18h] BYREF
unsigned int v7; // [rsp+4h] [rbp-14h] BYREF
double v8; // [rsp+8h] [rbp-10h] BYREF

v2 = *a1;
if ( *a1 == 9 || v2 == 32 )
{
v3 = a1 + 1;
while ( v2 != 10 )
{
v2 = *v3;
a1 = v3++;
if ( v2 != 9 && v2 != 32 )
goto LABEL_7;
}
}
else
{
LABEL_7:
if ( v2 != 10 )
{
_isoc99_sscanf(a1, "%d %d %lf", &v6, &v7, &v8);
v4 = newEntity(v6, v7, v8);
return addEntityToExoContent(a2, v4);
}
}
return puts(aErreurLorsDuD_0);
}

canonical_decompiled_code:
int __fastcall func1(char *a1, __int64 a2)
{
char v2; // dl
char *v3; // rax
__int64 v4; // rax
unsigned int v6; // [rsp+0h] [rbp-18h] BYREF
unsigned int v7; // [rsp+4h] [rbp-14h] BYREF
double v8; // [rsp+8h] [rbp-10h] BYREF

v2 = *a1;
if ( *a1 == 9 || v2 == 32 )
{
v3 = a1 + 1;
while ( v2 != 10 )
{
v2 = *v3;
a1 = v3++;
if ( v2 != 9 && v2 != 32 )
goto LABEL_7;
}
}
else
{
LABEL_7:
if ( v2 != 10 )
{
_isoc99_sscanf(a1, "%d %d %lf", &v6, &v7, &v8);
v4 = newEntity(v6, v7, v8);
return addEntityToExoContent(a2, v4);
}
}
return puts(aErreurLorsDuD_0);
}

original_code:
void processEntityBalise(char* line, exo_content* ex)
{
   int decalage=0;
     while((line[decalage] == '\t' || line[decalage] == ' ') && line[decalage]!='\n')
 ++decalage;
     if(line[decalage]=='\n')
   {
     printf("Erreur lors du décriptage de la balise entity\n");
     return;
   }
   int x, y;
   double ang;
   sscanf(line+decalage,"%d %d %lf", &x, &y, &ang);
   addEntityToExoContent(ex, newEntity(x,y,ang));
}

canonical_original_code:
void processEntityBalise(char *line, struct exo_content *ex)
{
   int decalage = 0;
     while((line[decalage] == '\t' || line[decalage] == ' ') && line[decalage]!='\n')
 ++decalage;
     if(line[decalage]=='\n')
   {
     printf("Erreur lors du décriptage de la balise entity\n");
     return;
   }
   int x; int y;
   double ang;
   sscanf(line+decalage,"%d %d %lf", &x, &y, &ang);
   addEntityToExoContent(ex, newEntity(x,y,ang));
}

variable_types: x int

variable_types: y int

variable_types: ang double


processLessonBalise

decompiled_code:
int __fastcall processLessonBalise(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbp
char v3; // al
_BYTE *i; // rax

v2 = a1;
if ( (unsigned int)isLessonDefined(a2) )
{
printf(format);
exit(1);
}
v3 = *a1;
if ( *a1 == 32 || v3 == 9 )
{
while ( v3 != 10 )
{
v3 = *++v2;
if ( v3 != 9 && v3 != 32 )
goto LABEL_7;
}
return puts(aErreurLorsDuD_0);
}
LABEL_7:
if ( v3 == 10 )
return puts(aErreurLorsDuD_0);
for ( i = v2; *i != 10; ++i )
;
*i = 0;
return setLessonName(a2, v2);
}

canonical_decompiled_code:
int __fastcall func2(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbp
char v3; // al
_BYTE *i; // rax

v2 = a1;
if ( (unsigned int)isLessonDefined(a2) )
{
printf(format);
exit(1);
}
v3 = *a1;
if ( *a1 == 32 || v3 == 9 )
{
while ( v3 != 10 )
{
v3 = *++v2;
if ( v3 != 9 && v3 != 32 )
goto LABEL_7;
}
return puts(aErreurLorsDuD_0);
}
LABEL_7:
if ( v3 == 10 )
return puts(aErreurLorsDuD_0);
for ( i = v2; *i != 10; ++i )
;
*i = 0;
return setLessonName(a2, v2);
}

original_code:
void processLessonBalise(char* line, exo_content* ex)
{
  if(isLessonDefined(ex))
  {
    printf("Erreur lors du parsing du fichier, la leçon est défini deux fois");
    exit(1);
  }
  char* firstChar=line;
     while((*firstChar == '\t' || *firstChar == ' ') && *firstChar!='\n')
 ++firstChar;
     if(*firstChar=='\n')
   {
     printf("Erreur lors du décriptage de la balise entity\n");
     return;
   }
   char* end = firstChar;
   while(*end != '\n')
     ++end;
   *end='\0';
   setLessonName(ex, firstChar);
}

canonical_original_code:
void processLessonBalise(char *line, struct exo_content *ex)
{
  if(isLessonDefined(ex))
  {
    printf("Erreur lors du parsing du fichier, la leçon est défini deux fois");
    exit(1);
  }
  char *firstChar = line;
     while((*firstChar == '\t' || *firstChar == ' ') && *firstChar!='\n')
 ++firstChar;
     if(*firstChar=='\n')
   {
     printf("Erreur lors du décriptage de la balise entity\n");
     return;
   }
   char *end = firstChar;
   while(*end != '\n')
     ++end;
   *end='\0';
   setLessonName(ex, firstChar);
}

variable_types: struct exo_content { struct world { double x; double y; } *w; struct entity { int x; int y; double ang; } *e; char *lesson_name; char *exercise_name; char *exercise_file_name; int descriptionSize; char **description; int codeEleveSize; char **codeEleve; int codeProfSize; char **codeProf; } *

variable_types:
firstChar
char *

variable_types:
end
char *


processExerciseBalise

decompiled_code:
int __fastcall processExerciseBalise(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbp
char v3; // al
_BYTE *i; // rax

v2 = a1;
if ( (unsigned int)isExerciseNameDefined(a2) )
{
puts(s);
exit(1);
}
v3 = *a1;
if ( *a1 == 32 || v3 == 9 )
{
while ( v3 != 10 )
{
v3 = *++v2;
if ( v3 != 9 && v3 != 32 )
goto LABEL_7;
}
return puts(aErreurLorsDuD_0);
}
LABEL_7:
if ( v3 == 10 )
return puts(aErreurLorsDuD_0);
for ( i = v2; *i != 10; ++i )
;
*i = 0;
return setExerciseName(a2, v2);
}

canonical_decompiled_code:
int __fastcall func3(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbp
char v3; // al
_BYTE *i; // rax

v2 = a1;
if ( (unsigned int)isExerciseNameDefined(a2) )
{
puts(s);
exit(1);
}
v3 = *a1;
if ( *a1 == 32 || v3 == 9 )
{
while ( v3 != 10 )
{
v3 = *++v2;
if ( v3 != 9 && v3 != 32 )
goto LABEL_7;
}
return puts(aErreurLorsDuD_0);
}
LABEL_7:
if ( v3 == 10 )
return puts(aErreurLorsDuD_0);
for ( i = v2; *i != 10; ++i )
;
*i = 0;
return setExerciseName(a2, v2);
}

original_code:
void processExerciseBalise(char* line, exo_content* ex)
{
  if(isExerciseNameDefined(ex))
  {
   printf("Erreur lors du parsing du fichier, le nom de 'exercise est défini deux fois\n");
   exit(1);
  }
  char* firstChar=line;
     while((*firstChar == '\t' || *firstChar == ' ') && *firstChar!='\n')
 ++firstChar;
     if(*firstChar=='\n')
   {
     printf("Erreur lors du décriptage de la balise entity\n");
     return;
   }
   char* end = firstChar;
   while(*end != '\n')
     ++end;
   *end='\0';
   setExerciseName(ex, firstChar);
}

canonical_original_code:
void processExerciseBalise(char *line, struct exo_content *ex)
{
  if(isExerciseNameDefined(ex))
  {
   printf("Erreur lors du parsing du fichier, le nom de 'exercise est défini deux fois\n");
   exit(1);
  }
  char *firstChar = line;
     while((*firstChar == '\t' || *firstChar == ' ') && *firstChar!='\n')
 ++firstChar;
     if(*firstChar=='\n')
   {
     printf("Erreur lors du décriptage de la balise entity\n");
     return;
   }
   char *end = firstChar;
   while(*end != '\n')
     ++end;
   *end='\0';
   setExerciseName(ex, firstChar);
}


parseBalise

decompiled_code:
__int64 __fastcall parseBalise(const void *a1)
{
bool v2; // zf
__int64 result; // rax

if ( !memcmp("/*BEGIN TEMPLATE*/", a1, 0x12uLL) )
{
template = 1;
result = 1LL;
}
else if ( !memcmp("/*END TEMPLATE*/", a1, 0x10uLL) )
{
template = 0;
result = 1LL;
}
else if ( !memcmp("/*BEGIN SOLUTION*/", a1, 0x12uLL) )
{
solution = 1;
result = 1LL;
}
else
{
v2 = memcmp("/*END SOLUTION*/", a1, 0x10uLL) == 0;
result = 0LL;
if ( v2 )
{
solution = 0;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1)
{
bool v2; // zf
__int64 result; // rax

if ( !memcmp("/*BEGIN TEMPLATE*/", a1, 0x12uLL) )
{
template = 1;
result = 1LL;
}
else if ( !memcmp("/*END TEMPLATE*/", a1, 0x10uLL) )
{
template = 0;
result = 1LL;
}
else if ( !memcmp("/*BEGIN SOLUTION*/", a1, 0x12uLL) )
{
solution = 1;
result = 1LL;
}
else
{
v2 = memcmp("/*END SOLUTION*/", a1, 0x10uLL) == 0;
result = 0LL;
if ( v2 )
{
solution = 0;
result = 1LL;
}
}
return result;
}

original_code:
int parseBalise(char* line)
{
    if(!strncmp(begin_template_balise, line, strlen(begin_template_balise)))
    {
      template=1;
      return 1;
    }
    else if(!strncmp(end_template_balise, line, strlen(end_template_balise)))
    {
      template=0;
      return 1;
    }
    else if(!strncmp(begin_solution_balise, line, strlen(begin_solution_balise)))
    {
      solution=1;
      return 1;
    }
    else if(!strncmp(end_solution_balise, line, strlen(end_solution_balise)))
    {
      solution=0;
      return 1;
    }
    return 0;
}

canonical_original_code:
int parseBalise(char *line)
{
    if(!strncmp(begin_template_balise, line, strlen(begin_template_balise)))
    {
      template=1;
      return 1;
    }
    else if(!strncmp(end_template_balise, line, strlen(end_template_balise)))
    {
      template=0;
      return 1;
    }
    else if(!strncmp(begin_solution_balise, line, strlen(begin_solution_balise)))
    {
      solution=1;
      return 1;
    }
    else if(!strncmp(end_solution_balise, line, strlen(end_solution_balise)))
    {
      solution=0;
      return 1;
    }
    return 0;
}


parseBaliseDescription

decompiled_code:
__int64 __fastcall parseBaliseDescription(const void *a1)
{
unsigned int v2; // er8

v2 = 1;
if ( memcmp("@world", a1, 6uLL) )
{
v2 = 2;
if ( memcmp("@entity", a1, 7uLL) )
{
v2 = 3;
if ( memcmp("@lesson", a1, 7uLL) )
{
v2 = 4;
if ( memcmp("@exercise", a1, 9uLL) )
v2 = memcmp("@description", a1, 0xCuLL) == 0 ? 5 : 0;
}
}
}
return v2;
}

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

v2 = 1;
if ( memcmp("@world", a1, 6uLL) )
{
v2 = 2;
if ( memcmp("@entity", a1, 7uLL) )
{
v2 = 3;
if ( memcmp("@lesson", a1, 7uLL) )
{
v2 = 4;
if ( memcmp("@exercise", a1, 9uLL) )
v2 = memcmp("@description", a1, 0xCuLL) == 0 ? 5 : 0;
}
}
}
return v2;
}

original_code:
int parseBaliseDescription(char* line)
{
    if(!strncmp(world_balise, line, strlen(world_balise)))
      return 1;
    else if(!strncmp(entity_balise, line, strlen(entity_balise)))
      return 2;
    else if(!strncmp(lesson_balise, line, strlen(lesson_balise)))
      return 3;
    else if(!strncmp(exercise_balise, line, strlen(exercise_balise)))
      return 4;
    else if(!strncmp(description_balise, line, strlen(description_balise)))
      return 5;
    else
      return 0;
}

canonical_original_code:
int parseBaliseDescription(char *line)
{
    if(!strncmp(world_balise, line, strlen(world_balise)))
      return 1;
    else if(!strncmp(entity_balise, line, strlen(entity_balise)))
      return 2;
    else if(!strncmp(lesson_balise, line, strlen(lesson_balise)))
      return 3;
    else if(!strncmp(exercise_balise, line, strlen(exercise_balise)))
      return 4;
    else if(!strncmp(description_balise, line, strlen(description_balise)))
      return 5;
    else
      return 0;
}


parseDescription

decompiled_code:
void __fastcall parseDescription(__int64 a1, const char *a2)
{
const char *v2; // r10
__int64 v3; // r11
char v4; // r9
__int64 v5; // r11
const char *v6; // rbp
char v7; // al

v2 = a2;
v3 = 0LL;
v4 = *a2;
if ( *a2 != 9 )
goto LABEL_3;
do
{
do
{
v4 = *++v2;
++v3;
}
while ( v4 == 9 );
LABEL_3:
;
}
while ( v4 == 32 );
if ( exercise_description )
{
if ( !(unsigned int)parseBaliseDescription(v2) )
{
a2[strlen(a2) - 1] = 0;
addDescription(a1, a2);
return;
}
exercise_description = 0;
}
if ( v4 != 10 )
{
switch ( (unsigned int)parseBaliseDescription(v2) )
{
case 0u:
puts("Erreur dans la description");
break;
case 1u:
processWorldBalise(&a2[v5 + 6], a1);
break;
case 2u:
processEntityBalise(&a2[v5 + 7], a1);
break;
case 3u:
processLessonBalise(&a2[v5 + 7], a1);
break;
case 4u:
processExerciseBalise(&a2[v5 + 9], a1);
break;
case 5u:
v6 = &a2[v5 + 12];
v7 = *v6;
if ( *v6 == 32 )
{
v7 = a2[v5 + 13];
v6 = &a2[v5 + 13];
}
if ( v7 )
{
v6[strlen(v6) - 1] = 0;
addDescription(a1, v6);
exercise_description = 1;
}
break;
default:
return;
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, const char *a2)
{
const char *v2; // r10
__int64 v3; // r11
char v4; // r9
__int64 v5; // r11
const char *v6; // rbp
char v7; // al

v2 = a2;
v3 = 0LL;
v4 = *a2;
if ( *a2 != 9 )
goto LABEL_3;
do
{
do
{
v4 = *++v2;
++v3;
}
while ( v4 == 9 );
LABEL_3:
;
}
while ( v4 == 32 );
if ( exercise_description )
{
if ( !(unsigned int)func1(v2) )
{
a2[strlen(a2) - 1] = 0;
addDescription(a1, a2);
return;
}
exercise_description = 0;
}
if ( v4 != 10 )
{
switch ( (unsigned int)func1(v2) )
{
case 0u:
puts("Erreur dans la description");
break;
case 1u:
processWorldBalise(&a2[v5 + 6], a1);
break;
case 2u:
processEntityBalise(&a2[v5 + 7], a1);
break;
case 3u:
processLessonBalise(&a2[v5 + 7], a1);
break;
case 4u:
processExerciseBalise(&a2[v5 + 9], a1);
break;
case 5u:
v6 = &a2[v5 + 12];
v7 = *v6;
if ( *v6 == 32 )
{
v7 = a2[v5 + 13];
v6 = &a2[v5 + 13];
}
if ( v7 )
{
v6[strlen(v6) - 1] = 0;
addDescription(a1, v6);
exercise_description = 1;
}
break;
default:
return;
}
}
}

original_code:
void parseDescription(exo_content *exoText, char* line)
{
   int decalage=0;
   while((line[decalage] == '\t' || line[decalage] == ' ') && line[decalage]!='\n')
    ++decalage;
  if(exercise_description)
  {
    if(parseBaliseDescription(line+decalage) != 0)
      exercise_description=0;
    else
    {
      line[strlen(line)-1]='\0';
      addDescription(exoText, line);
      return;
    }
  }
   if(line[decalage]=='\n')
   {
     return;
   }
   else
   switch(parseBaliseDescription(line+decalage))
   {
     case 1:
       processWorldBalise(line+decalage+strlen(world_balise), exoText);
       break;
     case 2:
       processEntityBalise(line+decalage+strlen(entity_balise), exoText);
       break;
     case 3:
       processLessonBalise(line+decalage+strlen(lesson_balise), exoText);
       break;
     case 4:
       processExerciseBalise(line+decalage+strlen(exercise_balise), exoText);
       break;
     case 5:
       line+=decalage+strlen(description_balise);
       if(*line == ' ')
  ++line;
       if(strlen(line)==0)
   break;
       line[strlen(line)-1]='\0';
       addDescription(exoText, line);
       exercise_description=1;
       break;
     case 0:
       printf("Erreur dans la description\n");
       break;
   };
}

canonical_original_code:
void parseDescription(struct exo_content *exoText, char *line)
{
   int decalage = 0;
   while((line[decalage] == '\t' || line[decalage] == ' ') && line[decalage]!='\n')
    ++decalage;
  if(exercise_description)
  {
    if(parseBaliseDescription(line+decalage) != 0)
      exercise_description=0;
    else
    {
      line[strlen(line)-1]='\0';
      addDescription(exoText, line);
      return;
    }
  }
   if(line[decalage]=='\n')
   {
     return;
   }
   else
   switch(parseBaliseDescription(line+decalage))
   {
     case 1:
       processWorldBalise(line+decalage+strlen(world_balise), exoText);
       break;
     case 2:
       processEntityBalise(line+decalage+strlen(entity_balise), exoText);
       break;
     case 3:
       processLessonBalise(line+decalage+strlen(lesson_balise), exoText);
       break;
     case 4:
       processExerciseBalise(line+decalage+strlen(exercise_balise), exoText);
       break;
     case 5:
       line+=decalage+strlen(description_balise);
       if(*line == ' ')
  ++line;
       if(strlen(line)==0)
   break;
       line[strlen(line)-1]='\0';
       addDescription(exoText, line);
       exercise_description=1;
       break;
     case 0:
       printf("Erreur dans la description\n");
       break;
   };
}


parseLine

decompiled_code:
void __fastcall parseLine(__int64 a1, const char *a2)
{
char v2; // al

v2 = *a2;
if ( *a2 == 32 || v2 == 9 )
{
do
{
do
v2 = *++a2;
while ( v2 == 9 );
}
while ( v2 == 32 );
}
if ( description )
{
if ( v2 == 42 )
{
if ( a2[1] == 47 )
{
*a2 = 0;
description = 0;
}
else
{
parseDescription(a1, a2 + 1);
}
}
}
else if ( v2 == 47 && a2[1] == 42 )
{
if ( a2[2] == 42 )
{
description = 1;
}
else if ( (unsigned int)parseBalise(a2) )
{
*a2 = 0;
}
}
}

original_code:
void parseLine(exo_content *exoText, char* line)
{
  while(*line == '\t' || *line == ' ')
    ++line;
  if(!description)
  {
    if(line[0]=='/')
    {
     if(line[1]=='*')
     {
       if(line[2]=='*')
  description=1;
       else
       {
  if(parseBalise(line))
   line[0]='\0';
       }
     }
    }
  }
  else
  {
    if(line[0]=='*')
    {
      if(line[1]=='/')
      {
 line[0]='\0';
 description=0;
      }
      else
 parseDescription(exoText, ++line);
    }
  }
}

canonical_original_code:
void parseLine(struct exo_content *exoText, char *line)
{
  while(*line == '\t' || *line == ' ')
    ++line;
  if(!description)
  {
    if(line[0]=='/')
    {
     if(line[1]=='*')
     {
       if(line[2]=='*')
  description=1;
       else
       {
  if(parseBalise(line))
   line[0]='\0';
       }
     }
    }
  }
  else
  {
    if(line[0]=='*')
    {
      if(line[1]=='/')
      {
 line[0]='\0';
 description=0;
      }
      else
 parseDescription(exoText, ++line);
    }
  }
}


constructLesson

decompiled_code:
void __fastcall constructLesson(__int64 a1, _QWORD *a2)
{
int v4; // ebp
__int64 *v5; // rbx
__int64 v6; // r14
__int64 v7; // rsi
__int64 v8; // rdi
__int64 v9; // rbp

generateLessonFromName(a1, *a2);
free((void *)*a2);
v4 = strtol((const char *)a2[1], 0LL, 10);
free((void *)a2[1]);
if ( v4 > 0 )
{
v5 = a2 + 2;
v6 = (__int64)&a2[2 * (unsigned int)(v4 - 1) + 4];
do
{
v7 = v5[1];
v8 = *v5;
v5 += 2;
v9 = newExerciseDescriptor(v8, v7);
free((void *)*(v5 - 2));
free((void *)*(v5 - 1));
addExerciseToLesson(a1, v9);
}
while ( v5 != (__int64 *)v6 );
}
free(a2);
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, _QWORD *a2)
{
int v4; // ebp
__int64 *v5; // rbx
__int64 v6; // r14
__int64 v7; // rsi
__int64 v8; // rdi
__int64 v9; // rbp

generateLessonFromName(a1, *a2);
free((void *)*a2);
v4 = strtol((const char *)a2[1], 0LL, 10);
free((void *)a2[1]);
if ( v4 > 0 )
{
v5 = a2 + 2;
v6 = (__int64)&a2[2 * (unsigned int)(v4 - 1) + 4];
do
{
v7 = v5[1];
v8 = *v5;
v5 += 2;
v9 = newExerciseDescriptor(v8, v7);
free((void *)*(v5 - 2));
free((void *)*(v5 - 1));
addExerciseToLesson(a1, v9);
}
while ( v5 != (__int64 *)v6 );
}
free(a2);
}

original_code:
void constructLesson(lesson_content* lesson, char** args)
{
  generateLessonFromName(lesson, args[0]);
  free(args[0]);
  int amount = strtol(args[1], ((void *)0), 10);
  free(args[1]);
  int i;
  for(i=0; i< amount; ++i)
  {
    exercise_desc *temp = newExerciseDescriptor(args[2+ i*2],args[3+2*i]);
    free(args[2+i*2]);
    free(args[3+i*2]);
    addExerciseToLesson(lesson, temp);
  }
  free(args);
}

canonical_original_code:
void constructLesson(struct lesson_content *lesson, char **args)
{
  generateLessonFromName(lesson, args[0]);
  free(args[0]);
  int amount = strtol(args[1], ((void *)0), 10);
  free(args[1]);
  int i;
  for(i=0; i< amount; ++i)
  {
    struct exercise_desc *temp = newExerciseDescriptor(args[2+ i*2],args[3+2*i]);
    free(args[2+i*2]);
    free(args[3+i*2]);
    addExerciseToLesson(lesson, temp);
  }
  free(args);
}

variable_types: struct lesson_content { char *lesson_name; char *lesson_name_file; char *filename; int amount; struct exercise_desc { char *exerciseName; char *exerciseConstructor; } **exercises; } *

variable_types:
args
char **

variable_types: amount int

variable_types: i int


goToNextWorld

decompiled_code:
char *__fastcall goToNextWorld(char **a1)
{
char *result; // rax
char v2; // cl
char *v3; // rdx
char v4; // dl

result = *a1;
v2 = **a1;
if ( (v2 & 0xDF) != 0 && v2 != 9 )
{
v3 = result + 1;
do
{
*a1 = v3;
v2 = *v3;
result = v3++;
}
while ( (v2 & 0xDF) != 0 && v2 != 9 );
}
if ( v2 == 9 || v2 == 32 )
{
++result;
if ( v2 )
{
do
{
*a1 = result;
v4 = *result++;
}
while ( (v4 == 9 || v4 == 32) && v4 );
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func6(char **a1)
{
char *result; // rax
char v2; // cl
char *v3; // rdx
char v4; // dl

result = *a1;
v2 = **a1;
if ( (v2 & 0xDF) != 0 && v2 != 9 )
{
v3 = result + 1;
do
{
*a1 = v3;
v2 = *v3;
result = v3++;
}
while ( (v2 & 0xDF) != 0 && v2 != 9 );
}
if ( v2 == 9 || v2 == 32 )
{
++result;
if ( v2 )
{
do
{
*a1 = result;
v4 = *result++;
}
while ( (v4 == 9 || v4 == 32) && v4 );
}
}
return result;
}

variable_types:
ptr
char **


extractLessonMain

original_code:
char* extractLessonMain(int fd)
{
  char* pattern = "lesson_new";
  long size = lseek(fd, 0, 2);
  lseek(fd, 0, 0);
  char* result = malloc(sizeof(char)*(size+1));
  int i=0;
  char buff;
  for(i=0; i<size; ++i)
  {
     read(fd, &buff, 1);
     if(buff == '\n')
       buff=' ';
     result[i] = buff;
  }
  result[size]='\0';
  char* temp = result;
  i = 2;
  while(1)
  {
    goToNextWorld(&temp);
    if(*temp == '\0')
    {
      printf("Lesson_new n'a pu être trouver\n");
      return ((void *)0);
    }
    if(!strncmp(temp, pattern , strlen(pattern)))
    {
      break;
    }
  }
  while(*temp != '(')
    ++temp;
  ++temp;
  char* first_bound = temp;
  while(*temp != ')')
    ++temp;
  *temp='\0';
  temp = malloc(sizeof(char)* (strlen(first_bound)+1));
  for(i=0; i<strlen(first_bound)+1; ++i)
    temp[i]='\0';
  int indice =0;
  while(*first_bound != '\0')
  {
    if(*first_bound == '"')
    {
      temp[indice] = *first_bound;
      ++indice;
      ++first_bound;
      while(*first_bound != '"' && *first_bound != '\0')
      {
 temp[indice] = *first_bound;
 ++indice;
 ++first_bound;
      }
      temp[indice] = *first_bound;
      ++indice;
    }
    else if(*first_bound != ' ' && *first_bound !='\t')
    {
       temp[indice] = *first_bound;
       ++indice;
    }
    ++first_bound;
  }
  temp[indice]='\0';
  free(result);
  return temp;
}

canonical_original_code:
char *extractLessonMain(int fd)
{
  char *pattern = "lesson_new";
  long size = lseek(fd, 0, 2);
  lseek(fd, 0, 0);
  char *result = malloc(sizeof(char)*(size+1));
  int i = 0;
  char buff;
  for(i=0; i<size; ++i)
  {
     read(fd, &buff, 1);
     if(buff == '\n')
       buff=' ';
     result[i] = buff;
  }
  result[size]='\0';
  char *temp = result;
  i = 2;
  while(1)
  {
    goToNextWorld(&temp);
    if(*temp == '\0')
    {
      printf("Lesson_new n'a pu être trouver\n");
      return ((void *)0);
    }
    if(!strncmp(temp, pattern , strlen(pattern)))
    {
      break;
    }
  }
  while(*temp != '(')
    ++temp;
  ++temp;
  char *first_bound = temp;
  while(*temp != ')')
    ++temp;
  *temp='\0';
  temp = malloc(sizeof(char)* (strlen(first_bound)+1));
  for(i=0; i<strlen(first_bound)+1; ++i)
    temp[i]='\0';
  int indice = 0;
  while(*first_bound != '\0')
  {
    if(*first_bound == '"')
    {
      temp[indice] = *first_bound;
      ++indice;
      ++first_bound;
      while(*first_bound != '"' && *first_bound != '\0')
      {
 temp[indice] = *first_bound;
 ++indice;
 ++first_bound;
      }
      temp[indice] = *first_bound;
      ++indice;
    }
    else if(*first_bound != ' ' && *first_bound !='\t')
    {
       temp[indice] = *first_bound;
       ++indice;
    }
    ++first_bound;
  }
  temp[indice]='\0';
  free(result);
  return temp;
}

variable_types: fd int

variable_types:
pattern
char *

variable_types: size long

variable_types:
result
char *

variable_types: buff char

variable_types:
temp
char *

variable_types: indice int


toNextComma

decompiled_code:
char *__fastcall toNextComma(char **a1)
{
char *result; // rax
char i; // dl
char *v3; // rdx
char v4; // cl
char *v5; // rax
char v6; // cl

result = *a1;
for ( i = **a1; i != 44; i = v3[1] )
{
LABEL_5:
if ( !i )
break;
if ( i == 34 )
{
v3 = result + 1;
*a1 = result + 1;
v4 = result[1];
if ( v4 != 34 && v4 )
{
v5 = result + 2;
while ( 1 )
{
*a1 = v5;
v6 = *v5;
v3 = v5++;
if ( v6 == 34 )
break;
if ( !v6 )
{
result = v3 + 1;
*a1 = v3 + 1;
i = v3[1];
if ( i != 44 )
goto LABEL_5;
return result;
}
}
}
}
else
{
v3 = *a1;
}
result = v3 + 1;
*a1 = v3 + 1;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(char **a1)
{
char *result; // rax
char i; // dl
char *v3; // rdx
char v4; // cl
char *v5; // rax
char v6; // cl

result = *a1;
for ( i = **a1; i != 44; i = v3[1] )
{
LABEL_5:
if ( !i )
break;
if ( i == 34 )
{
v3 = result + 1;
*a1 = result + 1;
v4 = result[1];
if ( v4 != 34 && v4 )
{
v5 = result + 2;
while ( 1 )
{
*a1 = v5;
v6 = *v5;
v3 = v5++;
if ( v6 == 34 )
break;
if ( !v6 )
{
result = v3 + 1;
*a1 = v3 + 1;
i = v3[1];
if ( i != 44 )
goto LABEL_5;
return result;
}
}
}
}
else
{
v3 = *a1;
}
result = v3 + 1;
*a1 = v3 + 1;
}
return result;
}


parseLessonFile

decompiled_code:
void __fastcall parseLessonFile(__int64 a1, __int64 a2)
{
const char *v2; // r12
size_t v3; // rax
char *v4; // rbp
int v5; // eax
int v6; // er12
char *v7; // r13
_QWORD *v8; // r15

v2 = *(const char **)(a2 + 16);
v3 = strlen(v2);
v4 = (char *)malloc(2 * v3 + 4);
sprintf(v4, "%s/%s.c", v2, v2);
printf("Fichier lesson : %s\n", v4);
v5 = open(v4, 0);
if ( !v5 )
{
puts(aImpossibleDeCh);
exit(1);
}
v6 = v5;
v7 = extractLessonMain(v5);
v8 = parseToArglist((__int64)v7);
free(v7);
close(v6);
constructLesson(a1, v8);
free(v4);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, __int64 a2)
{
const char *v2; // r12
size_t v3; // rax
char *v4; // rbp
int v5; // eax
int v6; // er12
char *v7; // r13
_QWORD *v8; // r15

v2 = *(const char **)(a2 + 16);
v3 = strlen(v2);
v4 = (char *)malloc(2 * v3 + 4);
sprintf(v4, "%s/%s.c", v2, v2);
printf("Fichier lesson : %s\n", v4);
v5 = open(v4, 0);
if ( !v5 )
{
puts(aImpossibleDeCh);
exit(1);
}
v6 = v5;
v7 = func7(v5);
v8 = parseToArglist((__int64)v7);
free(v7);
close(v6);
func5(a1, v8);
free(v4);
}

original_code:
void parseLessonFile(lesson_content *lesson, exo_content *exo)
{
  char* filename= malloc(sizeof(char)*(strlen(exo->lesson_name)*2+4));
  sprintf(filename, "%s/%s.c", exo->lesson_name, exo->lesson_name);
  printf("Fichier lesson : %s\n", filename);
  int fd = open(filename, 00);
  if(fd==0)
  {
      printf("Impossible de charger le fichier de leçon. Abandon.\n");
      exit(1);
  }
  char *content = extractLessonMain(fd);
  char** args = parseToArglist(content);
  free(content);
  close(fd);
  constructLesson(lesson, args);
  free(filename);
}

canonical_original_code:
void parseLessonFile(struct lesson_content *lesson, struct exo_content *exo)
{
  char *filename = malloc(sizeof(char)*(strlen(exo->lesson_name)*2+4));
  sprintf(filename, "%s/%s.c", exo->lesson_name, exo->lesson_name);
  printf("Fichier lesson : %s\n", filename);
  int fd = open(filename, 00);
  if(fd==0)
  {
      printf("Impossible de charger le fichier de leçon. Abandon.\n");
      exit(1);
  }
  char *content = extractLessonMain(fd);
  char **args = parseToArglist(content);
  free(content);
  close(fd);
  constructLesson(lesson, args);
  free(filename);
}

variable_types:
filename
char *

variable_types:
content
char *


generateExerciseDescriptor

decompiled_code:
__int64 __fastcall generateExerciseDescriptor(__int64 a1)
{
const char *v1; // r12
size_t v2; // rax
const char *v3; // r13
size_t v4; // rbp
size_t v5; // rax
char *v6; // rbp
__int64 v7; // r12

v1 = *(const char **)(a1 + 16);
v2 = strlen(v1);
v3 = *(const char **)(a1 + 24);
v4 = v2;
v5 = strlen(v3);
v6 = (char *)malloc(v4 + v5 + 10);
sprintf(v6, "%s_%s_create", v1, v3);
v7 = newExerciseDescriptor(*(_QWORD *)(a1 + 24), v6);
free(v6);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
const char *v1; // r12
size_t v2; // rax
const char *v3; // r13
size_t v4; // rbp
size_t v5; // rax
char *v6; // rbp
__int64 v7; // r12

v1 = *(const char **)(a1 + 16);
v2 = strlen(v1);
v3 = *(const char **)(a1 + 24);
v4 = v2;
v5 = strlen(v3);
v6 = (char *)malloc(v4 + v5 + 10);
sprintf(v6, "%s_%s_create", v1, v3);
v7 = newExerciseDescriptor(*(_QWORD *)(a1 + 24), v6);
free(v6);
return v7;
}

original_code:
exercise_desc *generateExerciseDescriptor(exo_content *ex)
{
  char* constructor = malloc(sizeof(char)*(strlen(ex->lesson_name) + strlen(ex->exercise_name) + sizeof("create")+3));
  sprintf(constructor, "%s_%s_create", ex->lesson_name, ex->exercise_name);
  exercise_desc *result = newExerciseDescriptor(ex->exercise_name, constructor);
  free(constructor);
  return result;
}

canonical_original_code:
struct exercise_desc *generateExerciseDescriptor(struct exo_content *ex)
{
  char *constructor = malloc(sizeof(char)*(strlen(ex->lesson_name) + strlen(ex->exercise_name) + sizeof("create")+3));
  sprintf(constructor, "%s_%s_create", ex->lesson_name, ex->exercise_name);
  struct exercise_desc *result = newExerciseDescriptor(ex->exercise_name, constructor);
  free(constructor);
  return result;
}

variable_types: struct exo_content { struct world { double x; double y; } *w; struct entity { int x; int y; double ang; } *e; char *lesson_name; char *exercise_name; char *exercise_file_name; int descriptionSize; char **description; int codeEleveSize; char **codeEleve; int codeProfSize; char **codeProf; } *

variable_types:
constructor
char *

variable_types: struct exercise_desc { char *exerciseName; char *exerciseConstructor; } *


repo: mrLite/C-Project

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

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

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

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

original_code:
double average_temp(Temp** t1, int w, int h){
 double sum = 0;
 for(int i=0; i < h; i++){
  for(int j=0; j < w; j++){
   sum += t1[i][j].t;
  }
 }
 return sum/ (w*h);
}

canonical_original_code:
double average_temp(struct Temp **t1, int w, int h){
 double sum = 0;
 for(int i = 0; i < h; i++){
  for(int j = 0; j < w; j++){
   sum += t1[i][j].t;
  }
 }
 return sum/ (w*h);
}

variable_types: w int

variable_types: h int

variable_types: sum double

variable_types: j int

return_type: double


variable_types: i int


decompiled_code:
__int64 __fastcall compare_temp(__int64 a1, __int64 a2, int a3, int a4, double a5)
{
__int64 v7; // rdi
__int64 v8; // rdx
__int64 v9; // rax

if ( a4 <= 2 )
return 0LL;
v7 = 1LL;
v8 = (unsigned int)(a3 - 3) + 2LL;
while ( a3 <= 2 )
{
LABEL_8:
if ( (unsigned int)(a4 - 3) + 2LL == ++v7 )
return 0LL;
}
v9 = 1LL;
while ( fabs(*(double *)(*(_QWORD *)(a2 + 8 * v7) + 8 * v9) - *(double *)(*(_QWORD *)(a1 + 8 * v7) + 8 * v9)) < a5 )
{
if ( v8 == ++v9 )
goto LABEL_8;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, int a3, int a4, double a5)
{
__int64 v7; // rdi
__int64 v8; // rdx
__int64 v9; // rax

if ( a4 <= 2 )
return 0LL;
v7 = 1LL;
v8 = (unsigned int)(a3 - 3) + 2LL;
while ( a3 <= 2 )
{
LABEL_8:
if ( (unsigned int)(a4 - 3) + 2LL == ++v7 )
return 0LL;
}
v9 = 1LL;
while ( fabs(*(double *)(*(_QWORD *)(a2 + 8 * v7) + 8 * v9) - *(double *)(*(_QWORD *)(a1 + 8 * v7) + 8 * v9)) < a5 )
{
if ( v8 == ++v9 )
goto LABEL_8;
}
return 1LL;
}

original_code:
int compare_temp(Temp** t1, Temp** t2, int w, int h, double e){
 for(int i=1; i < h-1; i++){
  for(int j=1; j < w-1; j++){
   double dif=fabs(t2[i][j].t-t1[i][j].t);
   if(dif >= e) return 1;
  }
 }
 return 0;
}

canonical_original_code:
int compare_temp(struct Temp **t1, struct Temp **t2, int w, int h, double e){
 for(int i = 1; i < h-1; i++){
  for(int j = 1; j < w-1; j++){
   double dif = fabs(t2[i][j].t-t1[i][j].t);
   if(dif >= e) return 1;
  }
 }
 return 0;
}

variable_types: e double

variable_types: dif double


decompiled_code:
__int64 __fastcall parse_id(__int64 a1, int a2, __int64 a3)
{
__int64 v3; // rax
unsigned int v4; // er8

if ( a2 <= 0 )
return 1LL;
v3 = 0LL;
v4 = 1;
do
{
if ( *(_BYTE *)(a1 + v3) != *(_BYTE *)(a3 + v3) )
v4 = 0;
++v3;
}
while ( v3 != a2 );
return v4;
}

original_code:
int parse_id(char* string, int len, char* comp){
 int ret = 1;
 for(int i = 0; i < len; i++){
  if(string[i] != comp[i])
   ret = 0;
 }
 return ret;
}

canonical_original_code:
int parse_id(char *string, int len, char *comp){
 int ret = 1;
 for(int i = 0; i < len; i++){
  if(string[i] != comp[i])
   ret = 0;
 }
 return ret;
}

variable_types:
string
char *

variable_types: len int

variable_types:
comp
char *

variable_types: ret int


repo: mradugin/dmcryptfile

decompiled_code:
__int64 __fastcall crypt_cipher_crypt(__int64 a1, __int64 a2, __int64 a3, size_t a4, const void *a5, size_t a6, int a7)
{
size_t v10; // r12
size_t v11; // rdx
void *v12; // rsp
struct cmsghdr *v13; // rax
__int64 result; // rax
struct cmsghdr v15; // [rsp+0h] [rbp-90h] BYREF
__int64 v16[2]; // [rsp+10h] [rbp-80h] BYREF
struct msghdr mhdr; // [rsp+20h] [rbp-70h] BYREF

*(_QWORD *)&v15.cmsg_level = a3;
v16[0] = a2;
v16[1] = a4;
if ( a5 )
{
v10 = (int)(((a6 + 11) & 0xFFFFFFF8) + 16);
v11 = v10 + 24;
}
else
{
v11 = 24LL;
v10 = 0LL;
}
mhdr.msg_controllen = v11;
*(_QWORD *)&mhdr.msg_flags = 0LL;
v12 = alloca(v11);
*(_OWORD *)&mhdr.msg_name = 0LL;
mhdr.msg_iov = (iovec *)v16;
mhdr.msg_iovlen = 1LL;
mhdr.msg_control = &v15;
if ( *(_QWORD *)&v15.cmsg_level == 0LL || a2 == 0 || !a4 || (a5 == 0LL) != (a6 == 0) )
return 4294967274LL;
v15.cmsg_len = v11;
memset(&v15, 0, v11);
if ( v15.cmsg_len <= 0xF )
crypt_cipher_crypt_cold(0.0);
v15.cmsg_len = 20LL;
*(_QWORD *)&v15.cmsg_level = 0x300000117LL;
LODWORD(v16[0]) = a7;
if ( a5 )
{
v13 = _cmsg_nxthdr(&mhdr, &v15);
*(_QWORD *)&v13->cmsg_level = 0x200000117LL;
v13->cmsg_len = v10;
*(_DWORD *)v13->__cmsg_data = a6;
memcpy(&v13->__cmsg_data[4], a5, a6);
}
if ( a4 == sendmsg(*(_DWORD *)(a1 + 4), &mhdr, 0) && a4 == read(*(_DWORD *)(a1 + 4), *(void **)&v15.cmsg_level, a4) )
result = 0LL;
else
result = 4294967291LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, size_t a4, const void *a5, size_t a6, int a7)
{
size_t v10; // r12
size_t v11; // rdx
void *v12; // rsp
struct cmsghdr *v13; // rax
__int64 result; // rax
struct cmsghdr v15; // [rsp+0h] [rbp-90h] BYREF
__int64 v16[2]; // [rsp+10h] [rbp-80h] BYREF
struct msghdr mhdr; // [rsp+20h] [rbp-70h] BYREF

*(_QWORD *)&v15.cmsg_level = a3;
v16[0] = a2;
v16[1] = a4;
if ( a5 )
{
v10 = (int)(((a6 + 11) & 0xFFFFFFF8) + 16);
v11 = v10 + 24;
}
else
{
v11 = 24LL;
v10 = 0LL;
}
mhdr.msg_controllen = v11;
*(_QWORD *)&mhdr.msg_flags = 0LL;
v12 = alloca(v11);
*(_OWORD *)&mhdr.msg_name = 0LL;
mhdr.msg_iov = (iovec *)v16;
mhdr.msg_iovlen = 1LL;
mhdr.msg_control = &v15;
if ( *(_QWORD *)&v15.cmsg_level == 0LL || a2 == 0 || !a4 || (a5 == 0LL) != (a6 == 0) )
return 4294967274LL;
v15.cmsg_len = v11;
memset(&v15, 0, v11);
if ( v15.cmsg_len <= 0xF )
func6(0.0);
v15.cmsg_len = 20LL;
*(_QWORD *)&v15.cmsg_level = 0x300000117LL;
LODWORD(v16[0]) = a7;
if ( a5 )
{
v13 = _cmsg_nxthdr(&mhdr, &v15);
*(_QWORD *)&v13->cmsg_level = 0x200000117LL;
v13->cmsg_len = v10;
*(_DWORD *)v13->__cmsg_data = a6;
memcpy(&v13->__cmsg_data[4], a5, a6);
}
if ( a4 == sendmsg(*(_DWORD *)(a1 + 4), &mhdr, 0) && a4 == read(*(_DWORD *)(a1 + 4), *(void **)&v15.cmsg_level, a4) )
result = 0LL;
else
result = 4294967291LL;
return result;
}

original_code:
static int crypt_cipher_crypt(struct crypt_cipher *ctx,
    const char *in, char *out, size_t length,
    const char *iv, size_t iv_length,
    uint32_t direction)
{
 int r = 0;
 ssize_t len;
 struct af_alg_iv *alg_iv;
 struct cmsghdr *header;
 uint32_t *type;
 struct iovec iov = {
  .iov_base = (void*)(uintptr_t)in,
  .iov_len = length,
 };
 int iv_msg_size = iv ? ((((sizeof(*alg_iv) + iv_length) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))) : 0;
 char buffer[((((sizeof(*type)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))) + iv_msg_size];
 struct msghdr msg = {
  .msg_control = buffer,
  .msg_controllen = sizeof(buffer),
  .msg_iov = &iov,
  .msg_iovlen = 1,
 };
 if (!in || !out || !length)
  return -22;
 if ((!iv && iv_length) || (iv && !iv_length))
  return -22;
 memset(buffer, 0, sizeof(buffer));
 header = ((size_t) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);
 header->cmsg_level = 279;
 header->cmsg_type = 3;
 header->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (sizeof(*type)));
 type = (void*)((header)->__cmsg_data);
 *type = direction;
 if (iv) {
  header = __cmsg_nxthdr (&msg, header);
  header->cmsg_level = 279;
  header->cmsg_type = 2;
  header->cmsg_len = iv_msg_size;
  alg_iv = (void*)((header)->__cmsg_data);
  alg_iv->ivlen = iv_length;
  memcpy(alg_iv->iv, iv, iv_length);
 }
 len = sendmsg(ctx->opfd, &msg, 0);
 if (len != (ssize_t)length) {
  r = -5;
  goto bad;
 }
 len = read(ctx->opfd, out, length);
 if (len != (ssize_t)length)
  r = -5;
bad:
 memset(buffer, 0, sizeof(buffer));
 return r;
}

canonical_original_code:
static int crypt_cipher_crypt(struct crypt_cipher *ctx, char *in, char *out, unsigned long length, char *iv, unsigned long iv_length, unsigned int direction)
{
 int r = 0;
 long len;
 struct af_alg_iv *alg_iv;
 struct cmsghdr *header;
 unsigned int *type;
 struct iovec iov = {
  .iov_base = (void*)(uintptr_t)in,
  .iov_len = length,
 };
 int iv_msg_size = iv ? ((((sizeof(*alg_iv) + iv_length) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))) : 0;
 char buffer[-1];
 struct msghdr msg = {
  .msg_control = buffer,
  .msg_controllen = sizeof(buffer),
  .msg_iov = &iov,
  .msg_iovlen = 1,
 };
 if (!in || !out || !length)
  return -22;
 if ((!iv && iv_length) || (iv && !iv_length))
  return -22;
 memset(buffer, 0, sizeof(buffer));
 header = ((unsigned long) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);
 header->cmsg_level = 279;
 header->cmsg_type = 3;
 header->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (unsigned long) - 1) & (unsigned long) ~(sizeof (unsigned long) - 1)) + (sizeof(*type)));
 type = (void *)((header)->__cmsg_data);
 *type = direction;
 if (iv) {
  header = __cmsg_nxthdr (&msg, header);
  header->cmsg_level = 279;
  header->cmsg_type = 2;
  header->cmsg_len = iv_msg_size;
  alg_iv = (void *)((header)->__cmsg_data);
  alg_iv->ivlen = iv_length;
  memcpy(alg_iv->iv, iv, iv_length);
 }
 len = sendmsg(ctx->opfd, &msg, 0);
 if (len != (long)length) {
  r = -5;
  goto bad;
 }
 len = read(ctx->opfd, out, length);
 if (len != (long)length)
  r = -5;
bad:
 memset(buffer, 0, sizeof(buffer));
 return r;
}

variable_types: struct crypt_cipher { int tfmfd; int opfd; } *

variable_types:
in
char *

variable_types:
out
char *

variable_types:
length
unsigned long

variable_types:
iv
char *

variable_types:
direction
unsigned int

variable_types: r int

variable_types: len long

variable_types: struct af_alg_iv { unsigned int ivlen; unsigned char iv[]; } *

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

variable_types:
type
unsigned int *

variable_types:
buffer
char [-1]

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


decompiled_code:
__int64 __fastcall crypt_kernel_socket_init(struct sockaddr *addr, int *a2, int *a3)
{
int v4; // eax
int v5; // eax
__int64 result; // rax

v4 = socket(38, 5, 0);
*a2 = v4;
if ( v4 == -1 )
return 4294967201LL;
if ( bind(v4, addr, 0x58u) == -1 )
{
close(*a2);
*a2 = -1;
result = 4294967294LL;
}
else
{
v5 = accept(*a2, 0LL, 0LL);
*a3 = v5;
if ( v5 == -1 )
{
close(*a2);
*a2 = -1;
result = 4294967274LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(struct sockaddr *addr, int *a2, int *a3)
{
int v4; // eax
int v5; // eax
__int64 result; // rax

v4 = socket(38, 5, 0);
*a2 = v4;
if ( v4 == -1 )
return 4294967201LL;
if ( bind(v4, addr, 0x58u) == -1 )
{
close(*a2);
*a2 = -1;
result = 4294967294LL;
}
else
{
v5 = accept(*a2, 0LL, 0LL);
*a3 = v5;
if ( v5 == -1 )
{
close(*a2);
*a2 = -1;
result = 4294967274LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int crypt_kernel_socket_init(struct sockaddr_alg *sa, int *tfmfd, int *opfd)
{
 *tfmfd = socket(38, SOCK_SEQPACKET, 0);
 if (*tfmfd == -1)
  return -95;
 if (bind(*tfmfd, (struct sockaddr *)sa, sizeof(*sa)) == -1) {
  close(*tfmfd);
  *tfmfd = -1;
  return -2;
 }
 *opfd = accept(*tfmfd, ((void *)0), 0);
 if (*opfd == -1) {
  close(*tfmfd);
  *tfmfd = -1;
  return -22;
 }
 return 0;
}

variable_types: struct sockaddr_alg { unsigned short salg_family; unsigned char salg_type[14]; unsigned int salg_feat; unsigned int salg_mask; unsigned char salg_name[64]; } *

variable_types:
tfmfd
int *

variable_types:
opfd
int *

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


decompiled_code:
__int64 __fastcall crypt_cipher_encrypt(__int64 a1, __int64 a2, __int64 a3, size_t a4, const void *a5, size_t a6)
{
return crypt_cipher_crypt(a1, a2, a3, a4, a5, a6, 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, size_t a4, const void *a5, size_t a6)
{
return func0(a1, a2, a3, a4, a5, a6, 1);
}

original_code:
int crypt_cipher_encrypt(struct crypt_cipher *ctx,
    const char *in, char *out, size_t length,
    const char *iv, size_t iv_length)
{
 return crypt_cipher_crypt(ctx, in, out, length,
      iv, iv_length, 1);
}

canonical_original_code:
int crypt_cipher_encrypt(struct crypt_cipher *ctx, char *in, char *out, unsigned long length, char *iv, unsigned long iv_length)
{
 return crypt_cipher_crypt(ctx, in, out, length,
      iv, iv_length, 1);
}

user_defined_types: struct crypt_cipher { int tfmfd; int opfd; }


decompiled_code:
__int64 __fastcall crypt_cipher_decrypt(__int64 a1, __int64 a2, __int64 a3, size_t a4, const void *a5, size_t a6)
{
return crypt_cipher_crypt(a1, a2, a3, a4, a5, a6, 0);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, size_t a4, const void *a5, size_t a6)
{
return func0(a1, a2, a3, a4, a5, a6, 0);
}

original_code:
int crypt_cipher_decrypt(struct crypt_cipher *ctx,
    const char *in, char *out, size_t length,
    const char *iv, size_t iv_length)
{
 return crypt_cipher_crypt(ctx, in, out, length,
      iv, iv_length, 0);
}

canonical_original_code:
int crypt_cipher_decrypt(struct crypt_cipher *ctx, char *in, char *out, unsigned long length, char *iv, unsigned long iv_length)
{
 return crypt_cipher_crypt(ctx, in, out, length,
      iv, iv_length, 0);
}


decompiled_code:
__int64 __fastcall crypt_cipher_destroy(void *ptr)
{
int v2; // edi
int v3; // edi

v2 = *(_DWORD *)ptr;
if ( v2 != -1 )
close(v2);
v3 = *((_DWORD *)ptr + 1);
if ( v3 != -1 )
close(v3);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
int v2; // edi
int v3; // edi

v2 = *(_DWORD *)ptr;
if ( v2 != -1 )
close(v2);
v3 = *((_DWORD *)ptr + 1);
if ( v3 != -1 )
close(v3);
free(ptr);
return 0LL;
}

original_code:
int crypt_cipher_destroy(struct crypt_cipher *ctx)
{
 if (ctx->tfmfd != -1)
  close(ctx->tfmfd);
 if (ctx->opfd != -1)
  close(ctx->opfd);
 memset(ctx, 0, sizeof(*ctx));
 free(ctx);
 return 0;
}


decompiled_code:
__int64 __fastcall crypt_cipher_init(int **a1, const char *a2, const char *a3, const void *a4, socklen_t a5)
{
int *v8; // rax
int *v9; // rbp
int v10; // eax
__int64 result; // rax
unsigned int v12; // [rsp+0h] [rbp-9Ch]
struct sockaddr addr; // [rsp+4h] [rbp-98h] BYREF
char s[16]; // [rsp+14h] [rbp-88h] BYREF
__int128 v15; // [rsp+24h] [rbp-78h]
__int128 v16; // [rsp+34h] [rbp-68h]
__int128 v17; // [rsp+44h] [rbp-58h]
__int64 v18; // [rsp+54h] [rbp-48h]

addr.sa_family = 38;
v18 = 0LL;
strcpy(addr.sa_data, "skcipher");
*(_WORD *)&addr.sa_data[12] = 0;
*(_OWORD *)s = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v8 = (int *)malloc(8uLL);
if ( !v8 )
return 4294967284LL;
v9 = v8;
snprintf(&s[8], 0x40uLL, "%s(%s)", a3, a2);
v10 = crypt_kernel_socket_init(&addr, v9, v9 + 1);
if ( v10 < 0 )
{
v12 = v10;
free(v9);
result = v12;
}
else if ( setsockopt(*v9, 279, 1, a4, a5) == -1 )
{
crypt_cipher_destroy(v9);
result = 4294967274LL;
}
else
{
*a1 = v9;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int **a1, const char *a2, const char *a3, const void *a4, socklen_t a5)
{
int *v8; // rax
int *v9; // rbp
int v10; // eax
__int64 result; // rax
unsigned int v12; // [rsp+0h] [rbp-9Ch]
struct sockaddr addr; // [rsp+4h] [rbp-98h] BYREF
char s[16]; // [rsp+14h] [rbp-88h] BYREF
__int128 v15; // [rsp+24h] [rbp-78h]
__int128 v16; // [rsp+34h] [rbp-68h]
__int128 v17; // [rsp+44h] [rbp-58h]
__int64 v18; // [rsp+54h] [rbp-48h]

addr.sa_family = 38;
v18 = 0LL;
strcpy(addr.sa_data, "skcipher");
*(_WORD *)&addr.sa_data[12] = 0;
*(_OWORD *)s = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v8 = (int *)malloc(8uLL);
if ( !v8 )
return 4294967284LL;
v9 = v8;
snprintf(&s[8], 0x40uLL, "%s(%s)", a3, a2);
v10 = func1(&addr, v9, v9 + 1);
if ( v10 < 0 )
{
v12 = v10;
free(v9);
result = v12;
}
else if ( setsockopt(*v9, 279, 1, a4, a5) == -1 )
{
func4(v9);
result = 4294967274LL;
}
else
{
*a1 = v9;
result = 0LL;
}
return result;
}

original_code:
int crypt_cipher_init(struct crypt_cipher **ctx, const char *name,
      const char *mode, const void *buffer, size_t length)
{
 struct crypt_cipher *h;
 struct sockaddr_alg sa = {
  .salg_family = 38,
  .salg_type = "skcipher",
 };
 int r;
 h = malloc(sizeof(*h));
 if (!h)
  return -12;
 snprintf((char *)sa.salg_name, sizeof(sa.salg_name),
   "%s(%s)", mode, name);
 r = crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd);
 if (r < 0) {
  free(h);
  return r;
 }
 if (setsockopt(h->tfmfd, 279, 1, buffer, length) == -1) {
  crypt_cipher_destroy(h);
  return -22;
 }
 *ctx = h;
 return 0;
}

canonical_original_code:
int crypt_cipher_init(struct crypt_cipher **ctx, char *name, char *mode, void *buffer, unsigned long length)
{
 struct crypt_cipher *h;
 struct sockaddr_alg sa = {
  .salg_family = 38,
  .salg_type = "skcipher",
 };
 int r;
 h = malloc(sizeof(*h));
 if (!h)
  return -12;
 snprintf((char *)sa.salg_name, sizeof(sa.salg_name),
   "%s(%s)", mode, name);
 r = crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd);
 if (r < 0) {
  free(h);
  return r;
 }
 if (setsockopt(h->tfmfd, 279, 1, buffer, length) == -1) {
  crypt_cipher_destroy(h);
  return -22;
 }
 *ctx = h;
 return 0;
}

variable_types: struct crypt_cipher { int tfmfd; int opfd; } **

variable_types:
name
char *

variable_types:
mode
char *

variable_types:
buffer
void *

variable_types: struct sockaddr_alg { unsigned short salg_family; unsigned char salg_type[14]; unsigned int salg_feat; unsigned int salg_mask; unsigned char salg_name[64]; }


decompiled_code:
__int64 crypt_backend_flags()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 1LL;
}

original_code:
uint32_t crypt_backend_flags(void)
{
 return (1 << 0);
}

canonical_original_code:
unsigned int crypt_backend_flags()
{
 return (1 << 0);
}


decompiled_code:
char *crypt_backend_version()
{
char *result; // rax

result = version;
if ( !crypto_backend_initialised )
result = (char *)&unk_5E1;
return result;
}

canonical_decompiled_code:
char *func3()
{
char *result; // rax

result = version;
if ( !crypto_backend_initialised )
result = (char *)&unk_5E1;
return result;
}

original_code:
const char *crypt_backend_version(void)
{
 return crypto_backend_initialised ? version : "";
}

canonical_original_code:
char *crypt_backend_version()
{
 return crypto_backend_initialised ? version : "";
}


decompiled_code:
__int64 __fastcall crypt_hash_size(char *a1)
{
char **v1; // rax
__int64 result; // rax

v1 = get_alg(a1);
if ( v1 )
result = *((unsigned int *)v1 + 4);
else
result = 4294967274LL;
return result;
}

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

v1 = func0(a1);
if ( v1 )
result = *((unsigned int *)v1 + 4);
else
result = 4294967274LL;
return result;
}

original_code:
int crypt_hash_size(const char *name)
{
 struct hash_alg *ha = _get_alg(name);
 return ha ? ha->length : -22;
}

canonical_original_code:
int crypt_hash_size(char *name)
{
 struct hash_alg *ha = _get_alg(name);
 return ha ? ha->length : -22;
}

variable_types: struct hash_alg { char *name; char *kernel_name; int length; } *


original_code:
int crypt_hash_init(struct crypt_hash **ctx, const char *name)
{
 struct crypt_hash *h;
 struct hash_alg *ha;
 struct sockaddr_alg sa = {
  .salg_family = 38,
  .salg_type = "hash",
 };
 h = malloc(sizeof(*h));
 if (!h)
  return -12;
 ha = _get_alg(name);
 if (!ha) {
  free(h);
  return -22;
 }
 h->hash_len = ha->length;
 strncpy((char *)sa.salg_name, ha->kernel_name, sizeof(sa.salg_name));
 if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd) < 0) {
  free(h);
  return -22;
 }
 *ctx = h;
 return 0;
}

canonical_original_code:
int crypt_hash_init(struct crypt_hash **ctx, char *name)
{
 struct crypt_hash *h;
 struct hash_alg *ha;
 struct sockaddr_alg sa = {
  .salg_family = 38,
  .salg_type = "hash",
 };
 h = malloc(sizeof(*h));
 if (!h)
  return -12;
 ha = _get_alg(name);
 if (!ha) {
  free(h);
  return -22;
 }
 h->hash_len = ha->length;
 strncpy((char *)sa.salg_name, ha->kernel_name, sizeof(sa.salg_name));
 if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd) < 0) {
  free(h);
  return -22;
 }
 *ctx = h;
 return 0;
}

variable_types: struct crypt_hash { int tfmfd; int opfd; int hash_len; } **

user_defined_types: struct sockaddr_alg { unsigned short salg_family; unsigned char salg_type[14]; unsigned int salg_feat; unsigned int salg_mask; unsigned char salg_name[64]; }

user_defined_types: struct hash_alg { char *name; char *kernel_name; int length; }


decompiled_code:
__int64 __fastcall crypt_hash_write(__int64 a1, const void *a2, size_t a3)
{
ssize_t v4; // rax
__int64 result; // rax

v4 = send(*(_DWORD *)(a1 + 4), a2, a3, 0x8000);
if ( v4 < 0 || v4 < a3 )
result = 4294967291LL;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const void *a2, size_t a3)
{
ssize_t v4; // rax
__int64 result; // rax

v4 = send(*(_DWORD *)(a1 + 4), a2, a3, 0x8000);
if ( v4 < 0 || v4 < a3 )
result = 4294967291LL;
else
result = 0LL;
return result;
}

original_code:
int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length)
{
 ssize_t r;
 r = send(ctx->opfd, buffer, length, MSG_MORE);
 if (r < 0 || (size_t)r < length)
  return -5;
 return 0;
}

canonical_original_code:
int crypt_hash_write(struct crypt_hash *ctx, char *buffer, unsigned long length)
{
 long r;
 r = send(ctx->opfd, buffer, length, MSG_MORE);
 if (r < 0 || (unsigned long)r < length)
  return -5;
 return 0;
}

variable_types: struct crypt_hash { int tfmfd; int opfd; int hash_len; } *

variable_types:
buffer
char *

variable_types:
length
unsigned long

variable_types: r long


decompiled_code:
ssize_t __fastcall crypt_hash_final(__int64 a1, void *a2, size_t a3)
{
ssize_t result; // rax

if ( *(int *)(a1 + 8) < a3 )
result = 4294967274LL;
else
result = (read(*(_DWORD *)(a1 + 4), a2, a3) >> 63) & 0xFFFFFFFBLL;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func7(__int64 a1, void *a2, size_t a3)
{
ssize_t result; // rax

if ( *(int *)(a1 + 8) < a3 )
result = 4294967274LL;
else
result = (read(*(_DWORD *)(a1 + 4), a2, a3) >> 63) & 0xFFFFFFFBLL;
return result;
}

original_code:
int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length)
{
 ssize_t r;
 if (length > (size_t)ctx->hash_len)
  return -22;
 r = read(ctx->opfd, buffer, length);
 if (r < 0)
  return -5;
 return 0;
}

canonical_original_code:
int crypt_hash_final(struct crypt_hash *ctx, char *buffer, unsigned long length)
{
 long r;
 if (length > (unsigned long)ctx->hash_len)
  return -22;
 r = read(ctx->opfd, buffer, length);
 if (r < 0)
  return -5;
 return 0;
}

user_defined_types: struct crypt_hash { int tfmfd; int opfd; int hash_len; }


decompiled_code:
__int64 __fastcall crypt_hash_destroy(void *ptr)
{
int v2; // edi
int v3; // edi

v2 = *(_DWORD *)ptr;
if ( v2 != -1 )
close(v2);
v3 = *((_DWORD *)ptr + 1);
if ( v3 != -1 )
close(v3);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *ptr)
{
int v2; // edi
int v3; // edi

v2 = *(_DWORD *)ptr;
if ( v2 != -1 )
close(v2);
v3 = *((_DWORD *)ptr + 1);
if ( v3 != -1 )
close(v3);
free(ptr);
return 0LL;
}

original_code:
int crypt_hash_destroy(struct crypt_hash *ctx)
{
 if (ctx->tfmfd != -1)
  close(ctx->tfmfd);
 if (ctx->opfd != -1)
  close(ctx->opfd);
 memset(ctx, 0, sizeof(*ctx));
 free(ctx);
 return 0;
}