decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // xmm0_8
__int64 v4; // rbp
__int64 v5; // r12
__int64 v6; // r14
__int64 v7; // rbx
__int64 v8; // r15
__int64 v9; // r13
__int64 v10; // r14
__int64 v12; // [rsp+8h] [rbp-A0h]
__int64 v13; // [rsp+10h] [rbp-98h]
__int64 v14; // [rsp+18h] [rbp-90h]
__int64 v15; // [rsp+20h] [rbp-88h]
__int64 v16; // [rsp+28h] [rbp-80h]
__int64 v17[7]; // [rsp+30h] [rbp-78h] BYREF
int v18; // [rsp+68h] [rbp-40h]

v4 = ssm_options_new(argc, argv, envp);
ssm_options_load(v4, 32LL, (unsigned int)argc, argv);
v5 = ssm_load_json_stream(stdin);
v6 = ssm_load_data(v4);
v7 = ssm_nav_new(v5, v4);
v8 = ssm_data_new(v6, v7, v4);
v9 = ssm_fitness_new(v8, v4);
v12 = ssm_calc_new(v6, v7, v8, v9, v4, 0LL);
v14 = ssm_X_new(v7, v4);
json_decref(v6);
v10 = ssm_input_new(v5, v7);
v15 = ssm_par_new(v10, v12, v7);
v13 = ssm_theta_new(v10, v7);
v16 = ssm_var_new(v5, v7);
v17[0] = v8;
v17[1] = v7;
v17[2] = v12;
v17[3] = v10;
v17[4] = v15;
v17[5] = v14;
v17[6] = v9;
v18 = *(_DWORD *)(v4 + 28);
gsl_set_error_handler_off();
ssm_simplex(v13, v16, v17, f_ksimplex, v7, v4);
if ( (*(_BYTE *)(v7 + 8) & 0x10) == 0 )
{
if ( *(_DWORD *)(v4 + 28) )
{
*(_QWORD *)(v9 + 136) = v3;
}
else
{
*(_QWORD *)(v9 + 40) = v3;
ssm_aic(v9, v7);
}
ssm_pipe_theta(stdout, v5, v13, 0LL, v9, v7, v4);
}
json_decref(v5);
ssm_X_free(v14);
ssm_calc_free(v12, v7);
ssm_data_free(v8);
ssm_nav_free(v7);
ssm_fitness_free(v9);
ssm_input_free(v10);
ssm_par_free(v15);
ssm_theta_free(v13);
ssm_var_free(v16);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // xmm0_8
__int64 v4; // rbp
__int64 v5; // r12
__int64 v6; // r14
__int64 v7; // rbx
__int64 v8; // r15
__int64 v9; // r13
__int64 v10; // r14
__int64 v12; // [rsp+8h] [rbp-A0h]
__int64 v13; // [rsp+10h] [rbp-98h]
__int64 v14; // [rsp+18h] [rbp-90h]
__int64 v15; // [rsp+20h] [rbp-88h]
__int64 v16; // [rsp+28h] [rbp-80h]
__int64 v17[7]; // [rsp+30h] [rbp-78h] BYREF
int v18; // [rsp+68h] [rbp-40h]

v4 = ssm_options_new(argc, argv, envp);
ssm_options_load(v4, 32LL, (unsigned int)argc, argv);
v5 = ssm_load_json_stream(stdin);
v6 = ssm_load_data(v4);
v7 = ssm_nav_new(v5, v4);
v8 = ssm_data_new(v6, v7, v4);
v9 = ssm_fitness_new(v8, v4);
v12 = ssm_calc_new(v6, v7, v8, v9, v4, 0LL);
v14 = ssm_X_new(v7, v4);
func1(v6);
v10 = ssm_input_new(v5, v7);
v15 = ssm_par_new(v10, v12, v7);
v13 = ssm_theta_new(v10, v7);
v16 = ssm_var_new(v5, v7);
v17[0] = v8;
v17[1] = v7;
v17[2] = v12;
v17[3] = v10;
v17[4] = v15;
v17[5] = v14;
v17[6] = v9;
v18 = *(_DWORD *)(v4 + 28);
gsl_set_error_handler_off();
ssm_simplex(v13, v16, v17, f_ksimplex, v7, v4);
if ( (*(_BYTE *)(v7 + 8) & 0x10) == 0 )
{
if ( *(_DWORD *)(v4 + 28) )
{
*(_QWORD *)(v9 + 136) = v3;
}
else
{
*(_QWORD *)(v9 + 40) = v3;
ssm_aic(v9, v7);
}
ssm_pipe_theta(stdout, v5, v13, 0LL, v9, v7, v4);
}
func1(v5);
ssm_X_free(v14);
ssm_calc_free(v12, v7);
ssm_data_free(v8);
ssm_nav_free(v7);
ssm_fitness_free(v9);
ssm_input_free(v10);
ssm_par_free(v15);
ssm_theta_free(v13);
ssm_var_free(v16);
return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    return clar_test(argc, argv);
}


repo: sballesteros/ssm

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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

original_code:
static inline
void json_decref(json_t *json)
{
    if(json && json->refcount != (size_t)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

canonical_original_code:
static inline void json_decref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

variable_types: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *

return_type: void

user_defined_types: struct json_t { enum json_type type; unsigned long refcount; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbp
__int64 v4; // r12
__int64 v5; // r14
__int64 v6; // rbx
__int64 v7; // r15
double *v8; // r13
__int64 v9; // r14
__int64 v11; // [rsp+0h] [rbp-A8h]
__int64 v12; // [rsp+8h] [rbp-A0h]
__int64 v13; // [rsp+10h] [rbp-98h]
__int64 v14; // [rsp+18h] [rbp-90h]
__int64 v15; // [rsp+20h] [rbp-88h]
double v16; // [rsp+28h] [rbp-80h]
__int64 v17[7]; // [rsp+30h] [rbp-78h] BYREF
int v18; // [rsp+68h] [rbp-40h]
int v19; // [rsp+6Ch] [rbp-3Ch]

v3 = (_DWORD *)ssm_options_new(argc, argv, envp);
ssm_options_load(v3, 128LL, (unsigned int)argc, argv);
v4 = ssm_load_json_stream(stdin);
v5 = ssm_load_data(v3);
v6 = ssm_nav_new(v4, v3);
v7 = ssm_data_new(v5, v6, v3);
v8 = (double *)ssm_fitness_new(v7, v3);
v11 = ssm_calc_new(v5, v6, v7, v8, v3, 0LL);
v13 = ssm_X_new(v6, v3);
json_decref(v5);
v9 = ssm_input_new(v4, v6);
v14 = ssm_par_new(v9, v11, v6);
v12 = ssm_theta_new(v9, v6);
v15 = ssm_var_new(v4, v6);
v17[0] = v7;
v17[1] = v6;
v17[2] = v11;
v17[3] = v9;
v17[4] = v14;
v17[5] = v13;
v17[6] = (__int64)v8;
v18 = v3[7];
v19 = v3[48];
gsl_set_error_handler_off();
if ( !v3[28] && (*(_BYTE *)(v6 + 8) & 1) != 0 )
{
v16 = f_simplex(v12, v17);
ssm_print_trace(*(_QWORD *)(v6 + 40), v12, v6, 0LL);
}
else
{
v16 = ssm_simplex(v12, v15, v17, f_simplex, v6, v3);
}
if ( (*(_BYTE *)(v6 + 8) & 0x10) == 0 )
{
if ( v3[48] )
{
v8[18] = v16;
}
else if ( v3[7] )
{
v8[17] = v16;
}
else
{
v8[5] = v16;
ssm_aic(v8, v6, v16);
}
ssm_pipe_theta(stdout, v4, v12, 0LL, v8, v6, v3);
}
json_decref(v4);
ssm_X_free(v13);
ssm_calc_free(v11, v6);
ssm_data_free(v7);
ssm_nav_free(v6);
ssm_fitness_free(v8);
ssm_input_free(v9);
ssm_par_free(v14);
ssm_theta_free(v12);
ssm_var_free(v15);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbp
__int64 v4; // r12
__int64 v5; // r14
__int64 v6; // rbx
__int64 v7; // r15
double *v8; // r13
__int64 v9; // r14
__int64 v11; // [rsp+0h] [rbp-A8h]
__int64 v12; // [rsp+8h] [rbp-A0h]
__int64 v13; // [rsp+10h] [rbp-98h]
__int64 v14; // [rsp+18h] [rbp-90h]
__int64 v15; // [rsp+20h] [rbp-88h]
double v16; // [rsp+28h] [rbp-80h]
__int64 v17[7]; // [rsp+30h] [rbp-78h] BYREF
int v18; // [rsp+68h] [rbp-40h]
int v19; // [rsp+6Ch] [rbp-3Ch]

v3 = (_DWORD *)ssm_options_new(argc, argv, envp);
ssm_options_load(v3, 128LL, (unsigned int)argc, argv);
v4 = ssm_load_json_stream(stdin);
v5 = ssm_load_data(v3);
v6 = ssm_nav_new(v4, v3);
v7 = ssm_data_new(v5, v6, v3);
v8 = (double *)ssm_fitness_new(v7, v3);
v11 = ssm_calc_new(v5, v6, v7, v8, v3, 0LL);
v13 = ssm_X_new(v6, v3);
func1(v5);
v9 = ssm_input_new(v4, v6);
v14 = ssm_par_new(v9, v11, v6);
v12 = ssm_theta_new(v9, v6);
v15 = ssm_var_new(v4, v6);
v17[0] = v7;
v17[1] = v6;
v17[2] = v11;
v17[3] = v9;
v17[4] = v14;
v17[5] = v13;
v17[6] = (__int64)v8;
v18 = v3[7];
v19 = v3[48];
gsl_set_error_handler_off();
if ( !v3[28] && (*(_BYTE *)(v6 + 8) & 1) != 0 )
{
v16 = func0(v12, v17);
ssm_print_trace(*(_QWORD *)(v6 + 40), v12, v6, 0LL);
}
else
{
v16 = ssm_simplex(v12, v15, v17, f_simplex, v6, v3);
}
if ( (*(_BYTE *)(v6 + 8) & 0x10) == 0 )
{
if ( v3[48] )
{
v8[18] = v16;
}
else if ( v3[7] )
{
v8[17] = v16;
}
else
{
v8[5] = v16;
ssm_aic(v8, v6, v16);
}
ssm_pipe_theta(stdout, v4, v12, 0LL, v8, v6, v3);
}
func1(v4);
ssm_X_free(v13);
ssm_calc_free(v11, v6);
ssm_data_free(v7);
ssm_nav_free(v6);
ssm_fitness_free(v8);
ssm_input_free(v9);
ssm_par_free(v14);
ssm_theta_free(v12);
ssm_var_free(v15);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    return clar_test(argc, argv);
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


user_defined_types: enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 }


decompiled_code:
void *__fastcall thread_start(void *a1)
{
int v1; // eax
unsigned int v2; // ebx
char *v3; // rax
int v4; // eax
unsigned int v5; // ebx
char *v6; // rax
int v7; // eax
unsigned int v8; // ebx
char *v10; // rax

v1 = pthread_mutex_lock(&gBarrierMu);
if ( v1 )
{
v2 = v1;
v3 = strerror(v1);
printf("Mutex lock failed at thread %d, error %d (%s)\n", (unsigned int)a1, v2, v3);
exit(1);
}
while ( gThreadWait )
{
if ( gVerbosity > 1 )
printf("Thread %d: waiting\n", (unsigned int)a1);
v4 = pthread_cond_wait(&gBarrierCv, &gBarrierMu);
v5 = v4;
if ( v4 )
{
v6 = strerror(v4);
printf("Cond wait failed at thread %d, error %d (%s)\n", (unsigned int)a1, v5, v6);
exit(1);
}
}
v7 = pthread_mutex_unlock(&gBarrierMu);
v8 = v7;
if ( v7 )
{
v10 = strerror(v7);
printf("Mutex unlock failed at thread %d, error %d (%s)\n", (unsigned int)a1, v8, v10);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // eax
unsigned int v2; // ebx
char *v3; // rax
int v4; // eax
unsigned int v5; // ebx
char *v6; // rax
int v7; // eax
unsigned int v8; // ebx
char *v10; // rax

v1 = pthread_mutex_lock(&gBarrierMu);
if ( v1 )
{
v2 = v1;
v3 = strerror(v1);
printf("Mutex lock failed at thread %d, error %d (%s)\n", (unsigned int)a1, v2, v3);
exit(1);
}
while ( gThreadWait )
{
if ( gVerbosity > 1 )
printf("Thread %d: waiting\n", (unsigned int)a1);
v4 = pthread_cond_wait(&gBarrierCv, &gBarrierMu);
v5 = v4;
if ( v4 )
{
v6 = strerror(v4);
printf("Cond wait failed at thread %d, error %d (%s)\n", (unsigned int)a1, v5, v6);
exit(1);
}
}
v7 = pthread_mutex_unlock(&gBarrierMu);
v8 = v7;
if ( v7 )
{
v10 = strerror(v7);
printf("Mutex unlock failed at thread %d, error %d (%s)\n", (unsigned int)a1, v8, v10);
exit(1);
}
return 0LL;
}

original_code:
void *thread_start(void *state) {
  int tid = (int) (uintptr_t) state;
  int rv = 0;
  if (0 != (rv = pthread_mutex_lock(&gBarrierMu))) {
    printf("Mutex lock failed at thread %d, error %d (%s)\n",
           tid, rv, strerror(rv));
    exit(1);
  }
  while (gThreadWait) {
    if (gVerbosity > 1) {
      printf("Thread %d: waiting\n", tid);
    }
    if (0 != (rv = pthread_cond_wait(&gBarrierCv, &gBarrierMu))) {
      printf("Cond wait failed at thread %d, error %d (%s)\n",
             tid, rv, strerror(rv));
      exit(1);
    }
  }
  if (0 != (rv = pthread_mutex_unlock(&gBarrierMu))) {
    printf("Mutex unlock failed at thread %d, error %d (%s)\n",
           tid, rv, strerror(rv));
    exit(1);
  }
  return ((void *)0);
}

variable_types:
state
void *

variable_types: tid int

variable_types: rv int

return_type: void *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // r12
unsigned __int64 v4; // r13
int v5; // eax
const char *v6; // rdx
const char **v7; // rbx
int v9; // eax
unsigned int v10; // er15
int v11; // eax
int v12; // eax
char *v13; // r14
unsigned __int64 v14; // rbx
const char *v15; // rsi
char *v16; // rax
char *v17; // rax
char *v18; // rax
int v19; // eax
unsigned int v20; // ebp
int v21; // eax
unsigned int v22; // ebp
char *v23; // rax
char *v24; // rax
int v25; // eax
unsigned int v26; // ebx
int v27; // eax
unsigned int v28; // ebx
int v29; // eax
unsigned int v30; // ebx
char *v31; // rax
char *v32; // rax
char *v33; // rax
pthread_attr_t v34; // [rsp+0h] [rbp-78h] BYREF
pthread_t newthread[8]; // [rsp+38h] [rbp-40h] BYREF

v3 = 0x4000LL;
v4 = 4096LL;
while ( 2 )
{
v5 = getopt(argc, (char *const *)argv, "mfhn:s:v");
if ( v5 != -1 )
{
switch ( v5 )
{
case 'f':
gExpectThreadCreationFailure = 1;
continue;
case 'h':
fprintf(
stderr,
"%s%s\n",
"Usage: egytian_cotton [-fhv] [-n num_threads] [-s bytes]\n",
" -f expect thread creation to fail for given\n"
" thread creation parameters\n"
" -h longer help\n"
" -v increase verbosity\n"
" -m use manual allocation of stacks\n"
" -n number of additional threads to create\n"
" -s stack size for each new thread\n");
v6 = long_winded_explanation[0];
if ( !long_winded_explanation[0] )
return 0;
v7 = (const char **)long_winded_explanation;
do
{
fprintf(stderr, " %s\n", v6);
v6 = *++v7;
}
while ( *v7 );
return 0;
case 'm':
gAllocateStacksUsingMalloc = 1;
continue;
case 'n':
v4 = strtoul(optarg, 0LL, 0);
continue;
case 's':
v3 = strtoul(optarg, 0LL, 0);
continue;
case 'v':
++gVerbosity;
continue;
default:
fprintf(stderr, "%s\n", "Usage: egytian_cotton [-fhv] [-n num_threads] [-s bytes]\n");
return 1;
}
}
break;
}
if ( gVerbosity > 1 )
{
printf("Creating %zd threads with 0x%zx byte stacks\n", v4, v3);
v15 = " not";
if ( !gExpectThreadCreationFailure )
v15 = "";
printf("According to the command line parameters, this is%s expected to work.\n", v15);
}
v9 = pthread_attr_init(&v34);
v10 = v9;
if ( v9 )
{
v16 = strerror(v9);
printf("Pthread attr initializetion failed, error %d (%s)\n", v10, v16);
}
else if ( !gAllocateStacksUsingMalloc && (v11 = pthread_attr_setstacksize(&v34, v3), (v10 = v11) != 0) )
{
v17 = strerror(v11);
printf("Pthread stack size selection failed, error %d (%s)\n", v10, v17);
}
else
{
v12 = pthread_attr_setdetachstate(&v34, 1);
v10 = v12;
if ( v12 )
{
v18 = strerror(v12);
printf("Pthread detach state selection failed, error %d (%s)\n", v10, v18);
}
else
{
v13 = 0LL;
if ( !gAllocateStacksUsingMalloc || (v13 = (char *)malloc(v3 * v4)) != 0LL )
{
if ( v4 )
{
v14 = 0LL;
while ( 1 )
{
if ( gVerbosity > 0 )
{
printf("Creating thread %zd\n", v14);
fflush(stdout);
}
if ( gAllocateStacksUsingMalloc )
{
v21 = pthread_attr_setstack(&v34, v13, v3);
v22 = v21;
if ( v21 )
{
v23 = strerror(v21);
printf("Pthread stack size selection failed, error %d (%s)\n", v22, v23);
v10 = v22;
goto LABEL_44;
}
}
v19 = pthread_create(newthread, &v34, thread_start, (void *)v14);
v20 = v19;
if ( v19 )
break;
putchar(46);
if ( kCountMask == (v14 & kCountMask) )
printf("%zd", v14);
if ( kNewlineMask == (v14 & kNewlineMask) )
putchar(10);
++v14;
v13 += v3;
if ( v4 == v14 )
goto LABEL_56;
}
v24 = strerror(v19);
printf("Thread creation failed at thread %zd, error %d (%s)\n", v14, v20, v24);
if ( gExpectThreadCreationFailure && v20 == 11 )
puts("This is expected.");
else
v10 = v20;
}
else
{
LABEL_56:
v10 = gExpectThreadCreationFailure;
if ( gExpectThreadCreationFailure )
{
puts("Expected thread creation failure.");
v10 = 1;
}
}
}
else
{
printf("Can not allocate memory for stacks");
v10 = 12;
}
}
}
LABEL_44:
v25 = pthread_mutex_lock(&gBarrierMu);
v26 = v25;
if ( v25 )
{
v31 = strerror(v25);
printf("Mutex lock failed at main thread, error %d (%s)\n", v26, v31);
exit(1);
}
gThreadWait = 0;
v27 = pthread_cond_broadcast(&gBarrierCv);
v28 = v27;
if ( v27 )
{
v32 = strerror(v27);
printf("Cond wait failed at main thread, error %d (%s)\n", v28, v32);
exit(1);
}
v29 = pthread_mutex_unlock(&gBarrierMu);
v30 = v29;
if ( v29 )
{
v33 = strerror(v29);
printf("Mutex unlock failed at main thread, error %d (%s)\n", v30, v33);
exit(1);
}
if ( v10 )
puts("FAILED");
else
puts("PASSED");
return v10 != 0;
}

original_code:
int main(int ac,
         char **av) {
  int opt;
  size_t num_threads = ((size_t) 0x1000);
  size_t stack_size = ((size_t) 0x4000);
  char const **line;
  int rv = 0;
  int cleanup_rv;
  pthread_t thr_state;
  pthread_attr_t attr;
  size_t tid;
  char *stacks = 0;
  while ((-1) != (opt = getopt(ac, av, "mfhn:s:v"))) {
    switch (opt) {
      case 'm':
        gAllocateStacksUsingMalloc = 1;
        break;
      case 'f':
        gExpectThreadCreationFailure = 1;
        break;
      case 'n':
        num_threads = strtoul(optarg, (char **) ((void *)0), 0);
        break;
      case 's':
        stack_size = strtoul(optarg, (char **) ((void *)0), 0);
        break;
      case 'v':
        ++gVerbosity;
        break;
      case 'h':
        fprintf(stderr, "%s%s\n", short_usage, flags_usage);
        for (line = long_winded_explanation; ((void *)0) != *line; ++line) {
          fprintf(stderr, "       %s\n", *line);
        }
        return 0;
      default:
        fprintf(stderr, "%s\n", short_usage);
        return 1;
    }
  }
  if (gVerbosity > 1) {
    printf("Creating %""zd"" threads with 0x%""zx"" byte stacks\n",
           num_threads,
           stack_size);
    printf("According to the command line parameters,"
           " this is%s expected to work.\n",
           gExpectThreadCreationFailure ? " not" : "");
  }
  if (0 != (rv = pthread_attr_init(&attr))) {
    printf("Pthread attr initializetion failed, error %d (%s)\n",
           rv, strerror(rv));
    goto cleanup_exit;
  }
  if (!gAllocateStacksUsingMalloc) {
    if (0 != (rv = pthread_attr_setstacksize(&attr, stack_size))) {
      printf("Pthread stack size selection failed, error %d (%s)\n",
             rv, strerror(rv));
      goto cleanup_exit;
    }
  }
  if (0 != (rv = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))) {
    printf("Pthread detach state selection failed, error %d (%s)\n",
           rv, strerror(rv));
    goto cleanup_exit;
  }
  if (gAllocateStacksUsingMalloc) {
    stacks = malloc(stack_size * num_threads);
    if (((void *)0) == stacks) {
      printf("Can not allocate memory for stacks");
      rv = 12;
      goto cleanup_exit;
    }
  }
  for (tid = 0; tid < num_threads; ++tid) {
    if (gVerbosity > 0) {
      printf("Creating thread %""zd""\n", tid); fflush(stdout);
    }
    if (gAllocateStacksUsingMalloc) {
      if (0 != (rv = pthread_attr_setstack(&attr, stacks + stack_size * tid,
                                           stack_size))) {
        printf("Pthread stack size selection failed, error %d (%s)\n",
               rv, strerror(rv));
        goto cleanup_exit;
      }
    }
    if (0 != (rv = pthread_create(&thr_state,
                                  &attr,
                                  thread_start,
                                  (void *) tid))) {
      printf("Thread creation failed at thread %""zd"", error %d (%s)\n",
             tid, rv, strerror(rv));
      if (gExpectThreadCreationFailure) {
        if (11 == rv) {
          printf("This is expected.\n");
          rv = 0;
          goto cleanup_exit;
        }
      }
      break;
    }
    putchar('.');
    if (kCountMask == (tid & kCountMask)) {
      printf("%""zd", tid);
    }
    if (kNewlineMask == (tid & kNewlineMask)) {
      putchar('\n');
    }
  }
  if (0 == rv && gExpectThreadCreationFailure) {
    printf("Expected thread creation failure.\n");
    rv = 1;
  }
cleanup_exit:
  if (0 != (cleanup_rv = pthread_mutex_lock(&gBarrierMu))) {
    printf("Mutex lock failed at main thread, error %d (%s)\n",
           cleanup_rv, strerror(cleanup_rv));
    exit(1);
  }
  gThreadWait = 0;
  if (0 != (cleanup_rv = pthread_cond_broadcast(&gBarrierCv))) {
    printf("Cond wait failed at main thread, error %d (%s)\n",
           cleanup_rv, strerror(cleanup_rv));
    exit(1);
  }
  if (0 != (cleanup_rv = pthread_mutex_unlock(&gBarrierMu))) {
    printf("Mutex unlock failed at main thread, error %d (%s)\n",
           cleanup_rv, strerror(cleanup_rv));
    exit(1);
  }
  if (0 == rv) {
    printf("PASSED\n");
  } else {
    printf("FAILED\n");
  }
  return rv != 0;
}

canonical_original_code:
int main(int ac, char **av) {
  int opt;
  unsigned long num_threads = ((size_t) 0x1000);
  unsigned long stack_size = ((size_t) 0x4000);
  char **line;
  int rv = 0;
  int cleanup_rv;
  unsigned long thr_state;
  union pthread_attr_t attr;
  unsigned long tid;
  char *stacks = 0;
  while ((-1) != (opt = getopt(ac, av, "mfhn:s:v"))) {
    switch (opt) {
      case 'm':
        gAllocateStacksUsingMalloc = 1;
        break;
      case 'f':
        gExpectThreadCreationFailure = 1;
        break;
      case 'n':
        num_threads = strtoul(optarg, (char **) ((void *)0), 0);
        break;
      case 's':
        stack_size = strtoul(optarg, (char **) ((void *)0), 0);
        break;
      case 'v':
        ++gVerbosity;
        break;
      case 'h':
        fprintf(stderr, "%s%s\n", short_usage, flags_usage);
        for (line = long_winded_explanation; ((void *)0) != *line; ++line) {
          fprintf(stderr, "       %s\n", *line);
        }
        return 0;
      default:
        fprintf(stderr, "%s\n", short_usage);
        return 1;
    }
  }
  if (gVerbosity > 1) {
    printf("Creating %""zd"" threads with 0x%""zx"" byte stacks\n",
           num_threads,
           stack_size);
    printf("According to the command line parameters,"
           " this is%s expected to work.\n",
           gExpectThreadCreationFailure ? " not" : "");
  }
  if (0 != (rv = pthread_attr_init(&attr))) {
    printf("Pthread attr initializetion failed, error %d (%s)\n",
           rv, strerror(rv));
    goto cleanup_exit;
  }
  if (!gAllocateStacksUsingMalloc) {
    if (0 != (rv = pthread_attr_setstacksize(&attr, stack_size))) {
      printf("Pthread stack size selection failed, error %d (%s)\n",
             rv, strerror(rv));
      goto cleanup_exit;
    }
  }
  if (0 != (rv = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))) {
    printf("Pthread detach state selection failed, error %d (%s)\n",
           rv, strerror(rv));
    goto cleanup_exit;
  }
  if (gAllocateStacksUsingMalloc) {
    stacks = malloc(stack_size * num_threads);
    if (((void *)0) == stacks) {
      printf("Can not allocate memory for stacks");
      rv = 12;
      goto cleanup_exit;
    }
  }
  for (tid = 0; tid < num_threads; ++tid) {
    if (gVerbosity > 0) {
      printf("Creating thread %""zd""\n", tid); fflush(stdout);
    }
    if (gAllocateStacksUsingMalloc) {
      if (0 != (rv = pthread_attr_setstack(&attr, stacks + stack_size * tid,
                                           stack_size))) {
        printf("Pthread stack size selection failed, error %d (%s)\n",
               rv, strerror(rv));
        goto cleanup_exit;
      }
    }
    if (0 != (rv = pthread_create(&thr_state,
                                  &attr,
                                  thread_start,
                                  (void *) tid))) {
      printf("Thread creation failed at thread %""zd"", error %d (%s)\n",
             tid, rv, strerror(rv));
      if (gExpectThreadCreationFailure) {
        if (11 == rv) {
          printf("This is expected.\n");
          rv = 0;
          goto cleanup_exit;
        }
      }
      break;
    }
    putchar('.');
    if (kCountMask == (tid & kCountMask)) {
      printf("%""zd", tid);
    }
    if (kNewlineMask == (tid & kNewlineMask)) {
      putchar('\n');
    }
  }
  if (0 == rv && gExpectThreadCreationFailure) {
    printf("Expected thread creation failure.\n");
    rv = 1;
  }
cleanup_exit:
  if (0 != (cleanup_rv = pthread_mutex_lock(&gBarrierMu))) {
    printf("Mutex lock failed at main thread, error %d (%s)\n",
           cleanup_rv, strerror(cleanup_rv));
    exit(1);
  }
  gThreadWait = 0;
  if (0 != (cleanup_rv = pthread_cond_broadcast(&gBarrierCv))) {
    printf("Cond wait failed at main thread, error %d (%s)\n",
           cleanup_rv, strerror(cleanup_rv));
    exit(1);
  }
  if (0 != (cleanup_rv = pthread_mutex_unlock(&gBarrierMu))) {
    printf("Mutex unlock failed at main thread, error %d (%s)\n",
           cleanup_rv, strerror(cleanup_rv));
    exit(1);
  }
  if (0 == rv) {
    printf("PASSED\n");
  } else {
    printf("FAILED\n");
  }
  return rv != 0;
}

variable_types: ac int

variable_types:
av
char **

variable_types: opt int

variable_types:
line
char **

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types:
tid
unsigned long

variable_types:
stacks
char *


addbyte

original_code:
void addbyte(int temp1[],int temp2[],int u,int v)
{
 int carry=0;
 int i,j,t,f=0,t1[100000];
 if(u<v)
 {
  t=u;
  u=v;
  v=t;
  for(i=0;i<u;i++)
  {
   t1[i]=temp1[i];
  }
  for(i=0;i<v;i++)
  {
   temp1[i]=temp2[i];
  }
  for(i=0;i<u;i++)
  {
   temp2[i]=t1[i];
  }
 }
 if(f==0)
 {
  for(i=0,j=0;i<u;i++,j++)
     {
   if(j<v)
   {
    if((temp1[i]==0)&&(temp2[j]==0))
    {
     if(carry=0)
     addvalue[i]=0;
     else
     {
      addvalue[i]=1;
      carry=0;
     }
    }
    if((temp1[i]==0)&&(temp2[j]==1))
    {
     if(carry==0)
     addvalue[i]=1;
     else
     addvalue[i]=0;
    }
    if((temp1[i]==1)&&(temp2[j]==0))
    {
     if(carry==0)
     addvalue[i]=1;
     else
     addvalue[i]=0;
    }
    if((temp1[i]==1)&&(temp2[j]==1))
    {
     if(carry==0)
     {
      addvalue[i]=0;
      carry=1;
     }
     else
     addvalue[i]=1;
    }
   }
   if((carry!=0)&&(j>=u))
   {
    if(temp1[i]==0)
    {
     addvalue[i]=1;
     carry=0;
    }
    else
    addvalue[i]=0;
   }
   if((carry==0)&&(j>=u))
   addvalue[i]=temp1[i];
  }
 }
}

canonical_original_code:
void addbyte(int temp1[], int temp2[], int u, int v)
{
 int carry = 0;
 int i; int j; int t; int f = 0; int t1[100000];
 if(u<v)
 {
  t=u;
  u=v;
  v=t;
  for(i=0;i<u;i++)
  {
   t1[i]=temp1[i];
  }
  for(i=0;i<v;i++)
  {
   temp1[i]=temp2[i];
  }
  for(i=0;i<u;i++)
  {
   temp2[i]=t1[i];
  }
 }
 if(f==0)
 {
  for(i=0,j=0;i<u;i++,j++)
     {
   if(j<v)
   {
    if((temp1[i]==0)&&(temp2[j]==0))
    {
     if(carry=0)
     addvalue[i]=0;
     else
     {
      addvalue[i]=1;
      carry=0;
     }
    }
    if((temp1[i]==0)&&(temp2[j]==1))
    {
     if(carry==0)
     addvalue[i]=1;
     else
     addvalue[i]=0;
    }
    if((temp1[i]==1)&&(temp2[j]==0))
    {
     if(carry==0)
     addvalue[i]=1;
     else
     addvalue[i]=0;
    }
    if((temp1[i]==1)&&(temp2[j]==1))
    {
     if(carry==0)
     {
      addvalue[i]=0;
      carry=1;
     }
     else
     addvalue[i]=1;
    }
   }
   if((carry!=0)&&(j>=u))
   {
    if(temp1[i]==0)
    {
     addvalue[i]=1;
     carry=0;
    }
    else
    addvalue[i]=0;
   }
   if((carry==0)&&(j>=u))
   addvalue[i]=temp1[i];
  }
 }
}

variable_types: u int

variable_types: v int

variable_types: carry int

variable_types: i int

variable_types: j int

variable_types: t int

variable_types: f int


changebyte

decompiled_code:
void __fastcall changebyte(__int64 a1, int a2)
{
__int64 v3; // rdi
__int64 v4; // rax
int v5; // er9
int v6; // esi

if ( a2 > 0 )
{
v3 = (unsigned int)a2;
v4 = 1LL;
v5 = 0;
v6 = 0;
while ( 1 )
{
v6 = (int)((double)*(int *)(a1 + 4 * v4 - 4) + (double)v6);
if ( v4 == v3 )
break;
if ( (int)v4 % 8 == 7 )
{
tweakbyte[v5++] = v6;
v6 = 0;
}
++v4;
}
}
}

original_code:
void changebyte(int temp4[],int u)
{
 int i,s,w=0,v=0;
 s=0;
 for(i=0;i<u;i++)
 {
  if((i%8)==7)
  {
   tweakbyte[w]=s;
   s=0;
   v=0;
   w=w+1;
  }
  s=s+pow(2,v)*temp4[i];
 }
}

canonical_original_code:
void changebyte(int temp4[], int u)
{
 int i; int s; int w = 0; int v = 0;
 s=0;
 for(i=0;i<u;i++)
 {
  if((i%8)==7)
  {
   tweakbyte[w]=s;
   s=0;
   v=0;
   w=w+1;
  }
  s=s+pow(2,v)*temp4[i];
 }
}

variable_types: s int

variable_types: w int


ubiimplement

decompiled_code:
__int64 ubiimplement()
{
int v0; // ebx
__int64 v1; // rax
unsigned int v2; // ecx
__int64 result; // rax
int v5; // er13
int *v6; // rax
int *v7; // rax
__int64 v8; // rax
__int64 v9; // rcx
int v10; // edx
char v11; // si
int v12; // eax
int v13; // ecx
__int64 v14; // rsi
unsigned int v15; // er12
unsigned __int64 i; // rax
unsigned __int64 j; // rax
int v18[16]; // [rsp+0h] [rbp-620E8h] BYREF
char v19[508]; // [rsp+40h] [rbp-620A8h] BYREF
int v20; // [rsp+23Ch] [rbp-61EACh] BYREF
char v21[504]; // [rsp+240h] [rbp-61EA8h] BYREF
int v22; // [rsp+438h] [rbp-61CB0h] BYREF
int v23[128]; // [rsp+440h] [rbp-61CA8h] BYREF
char v24[400040]; // [rsp+640h] [rbp-61AA8h] BYREF

v0 = sizeofplaintext;
if ( (sizeofplaintext & 0x1F) != 0 )
{
v1 = sizeofplaintext + 1;
do
{
plaintext[v1 - 1] = 0;
v2 = v1;
}
while ( v1++ & 0x1F );
sizeofplaintext = v2;
}
else
{
v2 = sizeofplaintext;
}
result = bytestowords(plaintext, 0LL, v2);
if ( sizeofplaintext > 31 )
{
v5 = 1;
do
{
v12 = 1024;
if ( v0 > 1024 )
v12 = v0;
v13 = v12;
v14 = 1LL;
do
{
v23[v14 + 127] = v13 % 2;
v15 = v14;
v13 /= 2;
++v14;
}
while ( v13 );
for ( i = 0LL; i != -512LL; i -= 4LL )
v23[i / 0xFFFFFFFFFFFFFFFCLL] = tweak[i / 4 + 127];
addbyte(v23, v24, 128LL, v15);
if ( (int)v15 < 128 )
v15 = 128;
if ( v5 == 1 )
{
v6 = (int *)v21;
do
*v6++ = 0;
while ( v6 != &v22 );
v22 = 1;
addbyte(&addvalue, v21, v15, 127LL);
}
if ( sizeofplaintext - 1 == v5 )
{
v7 = (int *)v19;
do
*v7++ = 0;
while ( &v20 != v7 );
v20 = 1;
addbyte(&addvalue, v19, v15, 128LL);
}
changebyte(&addvalue, v15);
for ( j = 0LL; j != -64LL; j -= 4LL )
v18[j / 0xFFFFFFFFFFFFFFFCLL] = tweakbyte[j / 4 + 15];
bytestowords(blockcipherkey, 1LL, 32LL);
bytestowords(v18, 2LL, 16LL);
keyschedule();
rounds();
v10 = move1;
v8 = 0LL;
v11 = 0;
do
{
v9 = ciphertext[v8];
blockcipherkey[v8] = v9;
if ( v10 < v0 )
{
entireciphertext[v10++] = v9;
v11 = 1;
}
++v8;
}
while ( v8 != 32 );
if ( v11 )
move1 = v10;
++v5;
result = (unsigned int)(sizeofplaintext / 32);
}
while ( (int)result >= v5 );
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebx
__int64 v1; // rax
unsigned int v2; // ecx
__int64 result; // rax
int v5; // er13
int *v6; // rax
int *v7; // rax
__int64 v8; // rax
__int64 v9; // rcx
int v10; // edx
char v11; // si
int v12; // eax
int v13; // ecx
__int64 v14; // rsi
unsigned int v15; // er12
unsigned __int64 i; // rax
unsigned __int64 j; // rax
int v18[16]; // [rsp+0h] [rbp-620E8h] BYREF
char v19[508]; // [rsp+40h] [rbp-620A8h] BYREF
int v20; // [rsp+23Ch] [rbp-61EACh] BYREF
char v21[504]; // [rsp+240h] [rbp-61EA8h] BYREF
int v22; // [rsp+438h] [rbp-61CB0h] BYREF
int v23[128]; // [rsp+440h] [rbp-61CA8h] BYREF
char v24[400040]; // [rsp+640h] [rbp-61AA8h] BYREF

v0 = sizeofplaintext;
if ( (sizeofplaintext & 0x1F) != 0 )
{
v1 = sizeofplaintext + 1;
do
{
plaintext[v1 - 1] = 0;
v2 = v1;
}
while ( v1++ & 0x1F );
sizeofplaintext = v2;
}
else
{
v2 = sizeofplaintext;
}
result = bytestowords(plaintext, 0LL, v2);
if ( sizeofplaintext > 31 )
{
v5 = 1;
do
{
v12 = 1024;
if ( v0 > 1024 )
v12 = v0;
v13 = v12;
v14 = 1LL;
do
{
v23[v14 + 127] = v13 % 2;
v15 = v14;
v13 /= 2;
++v14;
}
while ( v13 );
for ( i = 0LL; i != -512LL; i -= 4LL )
v23[i / 0xFFFFFFFFFFFFFFFCLL] = tweak[i / 4 + 127];
addbyte(v23, v24, 128LL, v15);
if ( (int)v15 < 128 )
v15 = 128;
if ( v5 == 1 )
{
v6 = (int *)v21;
do
*v6++ = 0;
while ( v6 != &v22 );
v22 = 1;
addbyte(&addvalue, v21, v15, 127LL);
}
if ( sizeofplaintext - 1 == v5 )
{
v7 = (int *)v19;
do
*v7++ = 0;
while ( &v20 != v7 );
v20 = 1;
addbyte(&addvalue, v19, v15, 128LL);
}
changebyte(&addvalue, v15);
for ( j = 0LL; j != -64LL; j -= 4LL )
v18[j / 0xFFFFFFFFFFFFFFFCLL] = tweakbyte[j / 4 + 15];
bytestowords(blockcipherkey, 1LL, 32LL);
bytestowords(v18, 2LL, 16LL);
keyschedule();
rounds();
v10 = move1;
v8 = 0LL;
v11 = 0;
do
{
v9 = ciphertext[v8];
blockcipherkey[v8] = v9;
if ( v10 < v0 )
{
entireciphertext[v10++] = v9;
v11 = 1;
}
++v8;
}
while ( v8 != 32 );
if ( v11 )
move1 = v10;
++v5;
result = (unsigned int)(sizeofplaintext / 32);
}
while ( (int)result >= v5 );
}
return result;
}

original_code:
void ubiimplement(void)
{
 int originalsize,i1,mini,w,j,tempe[100000],tempe1[128],i,tempe2[127],maxaddvalue,tempe3[128],tweakbyte1[16];
 originalsize=sizeofplaintext;
 while((sizeofplaintext%32)!=0)
 {
  plaintext[sizeofplaintext]=0;
  sizeofplaintext=sizeofplaintext+1;
 }
 bytestowords(plaintext,0,sizeofplaintext);
 for(i1=1;i1<=(sizeofplaintext/32);i1++)
 {
  mini=originalsize;
  if(mini<(i*32))
  mini=(i*32);
  w=0;
  for(j=mini;j!=0;j=(j/2))
  {
   tempe[w]=(j%2);
   w=w+1;
  }
  for(i=0,j=127;i<128;i++,j--)
  {
   tempe1[i]=tweak[j];
  }
  addbyte(tempe1,tempe,128,w);
  if(w>128)
  maxaddvalue=w;
  else
  maxaddvalue=128;
  if((i1-1)==0)
  {
   for(i=0;i<126;i++)
   {
    tempe2[i]=0;
   }
   tempe2[i]=1;
   addbyte(addvalue,tempe2,maxaddvalue,127);
   if(maxaddvalue<127)
   maxaddvalue=127;
  }
  if(i1==(sizeofplaintext-1))
  {
   for(i=0;i<127;i++)
   {
    tempe3[i]=0;
   }
   tempe3[i]=1;
   addbyte(addvalue,tempe3,maxaddvalue,128);
   if(maxaddvalue<128)
   maxaddvalue=128;
  }
  changebyte(addvalue,maxaddvalue);
  for(i=0,j=15;i<16;i++,j--)
  {
   tweakbyte1[i]=tweakbyte[j];
  }
  bytestowords(blockcipherkey,1,32);
  bytestowords(tweakbyte1,2,16);
  keyschedule();
  rounds();
  for(i=0;i<32;i++)
  {
   blockcipherkey[i]=ciphertext[i];
   if(move1<originalsize)
   {
    entireciphertext[move1]=ciphertext[i];
    move1=move1+1;
   }
  }
 }
}

canonical_original_code:
void ubiimplement()
{
 int originalsize; int i1; int mini; int w; int j; int tempe[100000]; int tempe1[128]; int i; int tempe2[127]; int maxaddvalue; int tempe3[128]; int tweakbyte1[16];
 originalsize=sizeofplaintext;
 while((sizeofplaintext%32)!=0)
 {
  plaintext[sizeofplaintext]=0;
  sizeofplaintext=sizeofplaintext+1;
 }
 bytestowords(plaintext,0,sizeofplaintext);
 for(i1=1;i1<=(sizeofplaintext/32);i1++)
 {
  mini=originalsize;
  if(mini<(i*32))
  mini=(i*32);
  w=0;
  for(j=mini;j!=0;j=(j/2))
  {
   tempe[w]=(j%2);
   w=w+1;
  }
  for(i=0,j=127;i<128;i++,j--)
  {
   tempe1[i]=tweak[j];
  }
  addbyte(tempe1,tempe,128,w);
  if(w>128)
  maxaddvalue=w;
  else
  maxaddvalue=128;
  if((i1-1)==0)
  {
   for(i=0;i<126;i++)
   {
    tempe2[i]=0;
   }
   tempe2[i]=1;
   addbyte(addvalue,tempe2,maxaddvalue,127);
   if(maxaddvalue<127)
   maxaddvalue=127;
  }
  if(i1==(sizeofplaintext-1))
  {
   for(i=0;i<127;i++)
   {
    tempe3[i]=0;
   }
   tempe3[i]=1;
   addbyte(addvalue,tempe3,maxaddvalue,128);
   if(maxaddvalue<128)
   maxaddvalue=128;
  }
  changebyte(addvalue,maxaddvalue);
  for(i=0,j=15;i<16;i++,j--)
  {
   tweakbyte1[i]=tweakbyte[j];
  }
  bytestowords(blockcipherkey,1,32);
  bytestowords(tweakbyte1,2,16);
  keyschedule();
  rounds();
  for(i=0;i<32;i++)
  {
   blockcipherkey[i]=ciphertext[i];
   if(move1<originalsize)
   {
    entireciphertext[move1]=ciphertext[i];
    move1=move1+1;
   }
  }
 }
}

variable_types: originalsize int

variable_types: mini int

variable_types:
tempe
int [100000]

variable_types: maxaddvalue int


repo: sbksba/Delaunay

decompiled_code:
__int64 Graphique_ResetPerspectiveProjection()
{
glMatrixMode(5889LL);
glPopMatrix();
return glMatrixMode(5888LL);
}

canonical_decompiled_code:
__int64 func0()
{
glMatrixMode(5889LL);
glPopMatrix();
return glMatrixMode(5888LL);
}

original_code:
void Graphique_ResetPerspectiveProjection()
{
 glMatrixMode(0x1701);
 glPopMatrix();
 glMatrixMode(0x1700);
}


decompiled_code:
__int64 Graphique_SetOrthographicProjection()
{
glMatrixMode(5889LL);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
glScalef(1.0, -1.0);
glTranslatef(0.0, -480.0);
return glMatrixMode(5888LL);
}

canonical_decompiled_code:
__int64 func1()
{
glMatrixMode(5889LL);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
glScalef(1.0, -1.0);
glTranslatef(0.0, -480.0);
return glMatrixMode(5888LL);
}

original_code:
void Graphique_SetOrthographicProjection()
{
 glMatrixMode(0x1701);
 glPushMatrix();
 glLoadIdentity();
 gluOrtho2D(0,640, 0, 480);
 glScalef(1, -1, 1);
 glTranslatef(0, -480, 0);
 glMatrixMode(0x1700);
}


original_code:
void Graphique_Dessin3D()
{
 SLTriangle *tmp;
 STriangle *t;
 tmp = tab.triangles->first;
 glColor3f(0.0,1.0,0.0);
 while(tmp!=((void *)0))
  {
  glPolygonMode(0x0408, 0x1B01);
  t=tmp->t;
  if((t->p1>3)&&(t->p2>3)&&(t->p3>3))
   {
   glBegin(0x0004);
    glVertex3d(tab.p[t->p1].x,tab.p[t->p1].y,tab.p[t->p1].z);
    glVertex3d(tab.p[t->p2].x,tab.p[t->p2].y,tab.p[t->p2].z);
    glVertex3d(tab.p[t->p3].x,tab.p[t->p3].y,tab.p[t->p3].z);
   glEnd();
   }
  tmp = tmp->next;
  }
 tmp = tab.triangles->first;
 glColor3f(0.0,0.0,0.0);
 glPolygonMode(0x0408, 0x1B02);
 glEnable(0x8037);
 glPolygonOffset(1.0,1.0);
 glBegin(0x0004);
  while(tmp!=((void *)0))
   {
   t=tmp->t;
   if((t->p1>3)&&(t->p2>3)&&(t->p3>3))
    {
    glVertex3d(tab.p[t->p1].x,tab.p[t->p1].y,tab.p[t->p1].z);
    glVertex3d(tab.p[t->p2].x,tab.p[t->p2].y,tab.p[t->p2].z);
    glVertex3d(tab.p[t->p3].x,tab.p[t->p3].y,tab.p[t->p3].z);
    }
   tmp = tmp->next;
   }
 glEnd();
 glDisable(0x8037);
}

canonical_original_code:
void Graphique_Dessin3D()
{
 struct sLTriangle *tmp;
 struct sTriangle *t;
 tmp = tab.triangles->first;
 glColor3f(0.0,1.0,0.0);
 while(tmp!=((void *)0))
  {
  glPolygonMode(0x0408, 0x1B01);
  t=tmp->t;
  if((t->p1>3)&&(t->p2>3)&&(t->p3>3))
   {
   glBegin(0x0004);
    glVertex3d(tab.p[t->p1].x,tab.p[t->p1].y,tab.p[t->p1].z);
    glVertex3d(tab.p[t->p2].x,tab.p[t->p2].y,tab.p[t->p2].z);
    glVertex3d(tab.p[t->p3].x,tab.p[t->p3].y,tab.p[t->p3].z);
   glEnd();
   }
  tmp = tmp->next;
  }
 tmp = tab.triangles->first;
 glColor3f(0.0,0.0,0.0);
 glPolygonMode(0x0408, 0x1B02);
 glEnable(0x8037);
 glPolygonOffset(1.0,1.0);
 glBegin(0x0004);
  while(tmp!=((void *)0))
   {
   t=tmp->t;
   if((t->p1>3)&&(t->p2>3)&&(t->p3>3))
    {
    glVertex3d(tab.p[t->p1].x,tab.p[t->p1].y,tab.p[t->p1].z);
    glVertex3d(tab.p[t->p2].x,tab.p[t->p2].y,tab.p[t->p2].z);
    glVertex3d(tab.p[t->p3].x,tab.p[t->p3].y,tab.p[t->p3].z);
    }
   tmp = tmp->next;
   }
 glEnd();
 glDisable(0x8037);
}

variable_types: struct sLTriangle { struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint { double x; } centre; double rayon; double critere; } *t; struct sLTriangle *next; } *

user_defined_types: struct sLTriangle { struct sTriangle *t; struct sLTriangle *next; }

user_defined_types: struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint centre; double rayon; double critere; }


variable_types:
v
double *

variable_types: height double


original_code:
void Graphique_Dessin3DFull()
{
 SLTriangle *tmp;
 STriangle *t;
 SVecteur V1,V2,V;
 GLdouble col[3];
 tmp = tab.triangles->first;
 glEnable(0x0B57);
 glColorMaterial(0x0408,0x1602);
 glPolygonMode(0x0408, 0x1B02);
 glEnable(0x0B50);
 glEnable(0x4000);
 glEnable(0x0BA1);
 glBegin(0x0004);
 while(tmp!=((void *)0))
  {
  t=tmp->t;
  if((t->p1>3)&&(t->p2>3)&&(t->p3>3))
   {
   V1.x = tab.p[tmp->t->p2].x-tab.p[tmp->t->p1].x;
   V1.y = tab.p[tmp->t->p2].y-tab.p[tmp->t->p1].y;
   V1.z = tab.p[tmp->t->p2].z-tab.p[tmp->t->p1].z;
   V2.x = tab.p[tmp->t->p3].x-tab.p[tmp->t->p1].x;
   V2.y = tab.p[tmp->t->p3].y-tab.p[tmp->t->p1].y;
   V2.z = tab.p[tmp->t->p3].z-tab.p[tmp->t->p1].z;
   Vecteur_ProdVect(&V1,&V2,&V);
   glNormal3d(V.x, V.y, V.z) ;
   Graphique_GetColor(col,tab.p[t->p1].z);
   glColor3dv(col);
   glVertex3d(tab.p[t->p1].x,tab.p[t->p1].y,tab.p[t->p1].z);
   Graphique_GetColor(col,tab.p[t->p2].z);
   glColor3dv(col);
   glVertex3d(tab.p[t->p2].x,tab.p[t->p2].y,tab.p[t->p2].z);
   Graphique_GetColor(col,tab.p[t->p3].z);
   glColor3dv(col);
   glVertex3d(tab.p[t->p3].x,tab.p[t->p3].y,tab.p[t->p3].z);
   }
  tmp = tmp->next;
  }
 glEnd();
 glDisable(0x4000);
 glDisable(0x0B50);
 glDisable(0x0BA1);
}

canonical_original_code:
void Graphique_Dessin3DFull()
{
 struct sLTriangle *tmp;
 struct sTriangle *t;
 struct sVecteur V1; struct sVecteur V2; struct sVecteur V;
 double col[3];
 tmp = tab.triangles->first;
 glEnable(0x0B57);
 glColorMaterial(0x0408,0x1602);
 glPolygonMode(0x0408, 0x1B02);
 glEnable(0x0B50);
 glEnable(0x4000);
 glEnable(0x0BA1);
 glBegin(0x0004);
 while(tmp!=((void *)0))
  {
  t=tmp->t;
  if((t->p1>3)&&(t->p2>3)&&(t->p3>3))
   {
   V1.x = tab.p[tmp->t->p2].x-tab.p[tmp->t->p1].x;
   V1.y = tab.p[tmp->t->p2].y-tab.p[tmp->t->p1].y;
   V1.z = tab.p[tmp->t->p2].z-tab.p[tmp->t->p1].z;
   V2.x = tab.p[tmp->t->p3].x-tab.p[tmp->t->p1].x;
   V2.y = tab.p[tmp->t->p3].y-tab.p[tmp->t->p1].y;
   V2.z = tab.p[tmp->t->p3].z-tab.p[tmp->t->p1].z;
   Vecteur_ProdVect(&V1,&V2,&V);
   glNormal3d(V.x, V.y, V.z) ;
   Graphique_GetColor(col,tab.p[t->p1].z);
   glColor3dv(col);
   glVertex3d(tab.p[t->p1].x,tab.p[t->p1].y,tab.p[t->p1].z);
   Graphique_GetColor(col,tab.p[t->p2].z);
   glColor3dv(col);
   glVertex3d(tab.p[t->p2].x,tab.p[t->p2].y,tab.p[t->p2].z);
   Graphique_GetColor(col,tab.p[t->p3].z);
   glColor3dv(col);
   glVertex3d(tab.p[t->p3].x,tab.p[t->p3].y,tab.p[t->p3].z);
   }
  tmp = tmp->next;
  }
 glEnd();
 glDisable(0x4000);
 glDisable(0x0B50);
 glDisable(0x0BA1);
}

variable_types: struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint { double x; } centre; double rayon; double critere; } *

variable_types:
V
struct sVecteur { double x; }

variable_types:
col
double [3]


decompiled_code:
__int64 __fastcall Graphique_RenderBitmapString(__int64 a1, _BYTE *a2, float a3, float a4)
{
_BYTE *v4; // rbx
char v5; // si
__int64 result; // rax

if ( HIDWORD(param[0]) )
{
v4 = a2;
glPushMatrix();
glColor3f(0.0, 1.0);
Graphique_SetOrthographicProjection();
glLoadIdentity();
glRasterPos2f(a3, a4);
v5 = *a2;
if ( v5 )
{
do
{
glutBitmapCharacter(a1, (unsigned int)v5);
v5 = *++v4;
}
while ( *v4 );
}
Graphique_ResetPerspectiveProjection();
glPopMatrix();
result = glPopMatrix();
}
return result;
}

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

if ( HIDWORD(param[0]) )
{
v4 = a2;
glPushMatrix();
glColor3f(0.0, 1.0);
func1();
glLoadIdentity();
glRasterPos2f(a3, a4);
v5 = *a2;
if ( v5 )
{
do
{
glutBitmapCharacter(a1, (unsigned int)v5);
v5 = *++v4;
}
while ( *v4 );
}
func0();
glPopMatrix();
result = glPopMatrix();
}
return result;
}

original_code:
void Graphique_RenderBitmapString(float x, float y, void *font,char *string)
{
  char *c;
  if(param.texte)
 {
 glPushMatrix();
 glColor3f(0.0f,1.0f,1.0f);
 Graphique_SetOrthographicProjection();
 glLoadIdentity();
 glRasterPos2f(x, y);
 for (c=string; *c != '\0'; c++)
  {
      glutBitmapCharacter(font, *c);
  }
 Graphique_ResetPerspectiveProjection();
 glPopMatrix();
 glPopMatrix();
 }
}

canonical_original_code:
void Graphique_RenderBitmapString(float x, float y, void *font, char *string)
{
  char *c;
  if(param.texte)
 {
 glPushMatrix();
 glColor3f(0.0f,1.0f,1.0f);
 Graphique_SetOrthographicProjection();
 glLoadIdentity();
 glRasterPos2f(x, y);
 for (c=string; *c != '\0'; c++)
  {
      glutBitmapCharacter(font, *c);
  }
 Graphique_ResetPerspectiveProjection();
 glPopMatrix();
 glPopMatrix();
 }
}

variable_types: x float

variable_types: y float

variable_types:
font
void *

variable_types:
string
char *

variable_types:
c
char *


decompiled_code:
__int64 __fastcall Main_redimFenetre(int a1, int a2)
{
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
gluPerspective(40.0, (float)((float)a1 / (float)a2), 1.0, 25.0);
glMatrixMode(5888LL);
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
gluPerspective(40.0, (float)((float)a1 / (float)a2), 1.0, 25.0);
glMatrixMode(5888LL);
return glutPostRedisplay();
}

original_code:
void Main_redimFenetre(int largeur, int hauteur)
{
  GLfloat rapport = ((float)(largeur))/((float)(hauteur));
  glViewport(0,0,largeur,hauteur);
  glMatrixMode(0x1701);
  glLoadIdentity();
  gluPerspective(40,rapport,1.0,25.0);
  glMatrixMode(0x1700);
  glutPostRedisplay();
}

canonical_original_code:
void Main_redimFenetre(int largeur, int hauteur)
{
  float rapport = ((float)(largeur))/((float)(hauteur));
  glViewport(0,0,largeur,hauteur);
  glMatrixMode(0x1701);
  glLoadIdentity();
  gluPerspective(40,rapport,1.0,25.0);
  glMatrixMode(0x1700);
  glutPostRedisplay();
}

variable_types: largeur int

variable_types: hauteur int

variable_types: rapport float


decompiled_code:
void Main_inserePoint()
{
__int64 v0; // rbx

if ( param )
FlipAlgo_InserePoint();
else
DestCons_InserePoint();
if ( (*(_BYTE *)(&param + 16) & 4) != 0 )
{
v0 = LODWORD(tab[2]) - 1;
*(double *)&tab[3 * v0 + 5] = TerrainImpl_CalcHeight(
terrainimpl,
*(double *)&tab[3 * v0 + 3],
*(double *)&tab[3 * v0 + 4]);
}
if ( (*(_BYTE *)(&param + 16) & 2) != 0 && LODWORD(tab[0]) == 30 * (SLODWORD(tab[0]) / 30) )
Terran_VieilMont(0LL, **(_QWORD **)(*(_QWORD *)(*(_QWORD *)tab[1] + 8LL) + 8LL), 20LL, 20LL, 1.0);
if ( (*(_BYTE *)(&param + 16) & 1) != 0 && LODWORD(tab[0]) == 100 * (SLODWORD(tab[0]) / 100) )
Terran_JeuneMont(0LL, **(_QWORD **)tab[1], 7LL, 0.5);
}

canonical_decompiled_code:
void func1()
{
__int64 v0; // rbx

if ( param )
FlipAlgo_InserePoint();
else
DestCons_InserePoint();
if ( (*(_BYTE *)(&param + 16) & 4) != 0 )
{
v0 = LODWORD(tab[2]) - 1;
*(double *)&tab[3 * v0 + 5] = TerrainImpl_CalcHeight(
terrainimpl,
*(double *)&tab[3 * v0 + 3],
*(double *)&tab[3 * v0 + 4]);
}
if ( (*(_BYTE *)(&param + 16) & 2) != 0 && LODWORD(tab[0]) == 30 * (SLODWORD(tab[0]) / 30) )
Terran_VieilMont(0LL, **(_QWORD **)(*(_QWORD *)(*(_QWORD *)tab[1] + 8LL) + 8LL), 20LL, 20LL, 1.0);
if ( (*(_BYTE *)(&param + 16) & 1) != 0 && LODWORD(tab[0]) == 100 * (SLODWORD(tab[0]) / 100) )
Terran_JeuneMont(0LL, **(_QWORD **)tab[1], 7LL, 0.5);
}

original_code:
void Main_inserePoint()
{
  if(param.flip_algo)
    FlipAlgo_InserePoint();
  else
    DestCons_InserePoint();
  if(param.gentype&4)
    tab.p[tab.np-1].z = TerrainImpl_CalcHeight(terrainimpl,tab.p[tab.np-1].x,tab.p[tab.np-1].y);
  if(param.gentype&2)
    if (tab.nt%30==0) Terran_VieilMont(((void *)0),(tab.triangles->first->next->next->t),1.0,20,20);
  if(param.gentype&1)
    if(tab.nt%100==0) Terran_JeuneMont(((void *)0),(tab.triangles->first->t),0.5,7);
}


decompiled_code:
__int64 Main_timer()
{
if ( param[13] && !param[14] )
Main_inserePoint();
Main_affichage();
return glutTimerFunc((unsigned int)param[12], Main_timer, 0LL);
}

canonical_decompiled_code:
__int64 func3()
{
if ( param[13] && !param[14] )
func1();
func2();
return glutTimerFunc((unsigned int)param[12], Main_timer, 0LL);
}

original_code:
void Main_timer(int value)
{
  if((param.auto_insert)&&!param.stop_insert)
    Main_inserePoint();
  Main_affichage();
  glutTimerFunc(param.timer_wait,Main_timer, 0);
  (void) value;
}

variable_types: value int


decompiled_code:
__int64 Main_nextGeneration()
{
int v0; // eax
__int64 result; // rax

v0 = param[16] + 1;
if ( v0 > 7 )
v0 = 1;
param[16] = v0;
result = v0 & 4;
param[4] = result;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
__int64 result; // rax

v0 = param[16] + 1;
if ( v0 > 7 )
v0 = 1;
param[16] = v0;
result = v0 & 4;
param[4] = result;
return result;
}

original_code:
void Main_nextGeneration()
{
  param.gentype++;
  if(param.gentype>=8)
    param.gentype=1;
  param.show_impl = (param.gentype&4);
}


decompiled_code:
__int64 __fastcall Main_touchesSpeciales(int a1)
{
_DWORD *v3; // rdi
int v4; // er12
int v5; // ebp
int v6; // esi
__int64 v7; // rdi
unsigned int v8; // edx

if ( a1 > 105 )
return glutPostRedisplay();
if ( a1 > 99 )
{
switch ( a1 )
{
case 'd':
*(double *)&param[6] = *(double *)&param[6] + 2.0;
break;
case 'e':
*(double *)&param[10] = *(double *)&param[10] + 0.2;
break;
case 'f':
*(double *)&param[6] = *(double *)&param[6] - 2.0;
break;
case 'g':
*(double *)&param[10] = *(double *)&param[10] - 0.2;
break;
case 'h':
*(double *)&param[8] = *(double *)&param[8] + 2.0;
break;
case 'i':
*(double *)&param[8] = *(double *)&param[8] - 2.0;
break;
default:
return glutPostRedisplay();
}
return glutPostRedisplay();
}
if ( a1 <= 8 )
{
if ( a1 > 4 )
{
v3 = terrainimpl;
if ( !terrainimpl )
{
v4 = 4;
v5 = 4;
goto LABEL_35;
}
}
else
{
if ( a1 != 2 )
{
if ( a1 == 3 )
Main_nextGeneration();
return glutPostRedisplay();
}
v3 = terrainimpl;
v4 = 4;
v5 = 4;
if ( !terrainimpl )
goto LABEL_25;
}
v5 = v3[2202];
v4 = *v3 - v5;
free(v3);
LABEL_35:
if ( a1 == 5 )
{
--v5;
LABEL_37:
if ( a1 == 8 )
++v4;
goto LABEL_16;
}
if ( a1 == 6 )
{
++v5;
goto LABEL_16;
}
LABEL_25:
if ( a1 != 7 )
goto LABEL_37;
--v4;
LABEL_16:
v6 = 0;
v7 = (unsigned int)v5;
if ( v5 < 0 )
v7 = 0LL;
if ( v4 >= 0 )
v6 = v4;
if ( (int)v7 + v6 > 199 )
{
v8 = 199 - v6;
if ( (int)v7 <= v6 )
v8 = v7;
v7 = v8;
}
terrainimpl = (void *)TerrainImpl_Init(v7, -10.0, 10.0, -10.0, 10.0);
DestCons_ResetTab();
return glutPostRedisplay();
}
if ( a1 == 10 )
param[1] = param[1] == 0;
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
_DWORD *v3; // rdi
int v4; // er12
int v5; // ebp
int v6; // esi
__int64 v7; // rdi
unsigned int v8; // edx

if ( a1 > 105 )
return glutPostRedisplay();
if ( a1 > 99 )
{
switch ( a1 )
{
case 'd':
*(double *)&param[6] = *(double *)&param[6] + 2.0;
break;
case 'e':
*(double *)&param[10] = *(double *)&param[10] + 0.2;
break;
case 'f':
*(double *)&param[6] = *(double *)&param[6] - 2.0;
break;
case 'g':
*(double *)&param[10] = *(double *)&param[10] - 0.2;
break;
case 'h':
*(double *)&param[8] = *(double *)&param[8] + 2.0;
break;
case 'i':
*(double *)&param[8] = *(double *)&param[8] - 2.0;
break;
default:
return glutPostRedisplay();
}
return glutPostRedisplay();
}
if ( a1 <= 8 )
{
if ( a1 > 4 )
{
v3 = terrainimpl;
if ( !terrainimpl )
{
v4 = 4;
v5 = 4;
goto LABEL_35;
}
}
else
{
if ( a1 != 2 )
{
if ( a1 == 3 )
func4();
return glutPostRedisplay();
}
v3 = terrainimpl;
v4 = 4;
v5 = 4;
if ( !terrainimpl )
goto LABEL_25;
}
v5 = v3[2202];
v4 = *v3 - v5;
free(v3);
LABEL_35:
if ( a1 == 5 )
{
--v5;
LABEL_37:
if ( a1 == 8 )
++v4;
goto LABEL_16;
}
if ( a1 == 6 )
{
++v5;
goto LABEL_16;
}
LABEL_25:
if ( a1 != 7 )
goto LABEL_37;
--v4;
LABEL_16:
v6 = 0;
v7 = (unsigned int)v5;
if ( v5 < 0 )
v7 = 0LL;
if ( v4 >= 0 )
v6 = v4;
if ( (int)v7 + v6 > 199 )
{
v8 = 199 - v6;
if ( (int)v7 <= v6 )
v8 = v7;
v7 = v8;
}
terrainimpl = (void *)TerrainImpl_Init(v7, -10.0, 10.0, -10.0, 10.0);
DestCons_ResetTab();
return glutPostRedisplay();
}
if ( a1 == 10 )
param[1] = param[1] == 0;
return glutPostRedisplay();
}

original_code:
void Main_touchesSpeciales(int touche, int x, int y)
{
  int tmp1,tmp2,tmp3;
  switch(touche)
    {
    case 0x0003:
      Main_nextGeneration();
      break;
    case 0x0002:
    case 0x0005:
    case 0x0006:
    case 0x0007:
    case 0x0008:
      if(terrainimpl!=((void *)0))
 {
   tmp1=terrainimpl->nb_montagnes;
   tmp2=terrainimpl->nb_centre-tmp1;
   free(terrainimpl);
 }
      else
 {tmp1=4;tmp2=4;}
      if(touche==0x0005)
 tmp1--;
      if(touche==0x0006)
 tmp1++;
      if(touche==0x0007)
 tmp2--;
      if(touche==0x0008)
 tmp2++;
      if(tmp1<0)
 tmp1=0;
      if(tmp2<0)
 tmp2=0;
      if(tmp1+tmp2>=200)
 {
   tmp3 = tmp1;
   tmp1 = (tmp1>tmp2)?tmp1-(tmp1+tmp2-200 +1):tmp1;
   tmp2 = (tmp3<tmp2)?tmp2-(tmp3+tmp2-200 +1):tmp2;
 }
      terrainimpl = TerrainImpl_Init(tmp1,tmp2,-10,10,-10,10);
      DestCons_ResetTab();
      break;
    case 0x000A:
      param.texte = ! param.texte;
      break;
    case 0x0065 :
      param.trans+=0.2;
      break;
    case 0x0067 :
      param.trans-=0.2;
      break;
    case 0x0066 :
      param.angle-=2.0;
      break;
    case 0x0064 :
      param.angle+=2.0;
      break;
    case 0x0068:
      param.angle2+= 2.0;
      break;
    case 0x0069:
      param.angle2-= 2.0;
      break;
    }
  glutPostRedisplay();
  (void) x;
  (void) y;
}

canonical_original_code:
void Main_touchesSpeciales(int touche, int x, int y)
{
  int tmp1; int tmp2; int tmp3;
  switch(touche)
    {
    case 0x0003:
      Main_nextGeneration();
      break;
    case 0x0002:
    case 0x0005:
    case 0x0006:
    case 0x0007:
    case 0x0008:
      if(terrainimpl!=((void *)0))
 {
   tmp1=terrainimpl->nb_montagnes;
   tmp2=terrainimpl->nb_centre-tmp1;
   free(terrainimpl);
 }
      else
 {tmp1=4;tmp2=4;}
      if(touche==0x0005)
 tmp1--;
      if(touche==0x0006)
 tmp1++;
      if(touche==0x0007)
 tmp2--;
      if(touche==0x0008)
 tmp2++;
      if(tmp1<0)
 tmp1=0;
      if(tmp2<0)
 tmp2=0;
      if(tmp1+tmp2>=200)
 {
   tmp3 = tmp1;
   tmp1 = (tmp1>tmp2)?tmp1-(tmp1+tmp2-200 +1):tmp1;
   tmp2 = (tmp3<tmp2)?tmp2-(tmp3+tmp2-200 +1):tmp2;
 }
      terrainimpl = TerrainImpl_Init(tmp1,tmp2,-10,10,-10,10);
      DestCons_ResetTab();
      break;
    case 0x000A:
      param.texte = ! param.texte;
      break;
    case 0x0065 :
      param.trans+=0.2;
      break;
    case 0x0067 :
      param.trans-=0.2;
      break;
    case 0x0066 :
      param.angle-=2.0;
      break;
    case 0x0064 :
      param.angle+=2.0;
      break;
    case 0x0068:
      param.angle2+= 2.0;
      break;
    case 0x0069:
      param.angle2-= 2.0;
      break;
    }
  glutPostRedisplay();
  (void) x;
  (void) y;
}

variable_types: touche int

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall Main_clavier(char a1)
{
bool v1; // zf
int v3; // eax
int v4; // eax
__m128d v5; // xmm1
__m128d v6; // xmm0
__m128d v7; // xmm0

switch ( a1 )
{
case '+':
v5.m128d_f64[0] = *(double *)&param[34] + 0.05;
*(_QWORD *)&v6.m128d_f64[0] = LC1;
v6.m128d_f64[0] = _mm_cmplt_sd(v6, v5).m128d_f64[0];
*(_QWORD *)&param[34] = ~*(_QWORD *)&v6.m128d_f64[0] & *(_QWORD *)&v5.m128d_f64[0] | LC1 & *(_QWORD *)&v6.m128d_f64[0];
break;
case '-':
v7.m128d_f64[0] = *(double *)&param[34] - 0.05;
v7.m128d_f64[0] = _mm_cmplt_sd(v7, (__m128d)(unsigned __int64)LC41).m128d_f64[0];
*(_QWORD *)&param[34] = ~*(_QWORD *)&v7.m128d_f64[0] & COERCE_UNSIGNED_INT64(*(double *)&param[34] - 0.05) | LC41 & *(_QWORD *)&v7.m128d_f64[0];
break;
case 'a':
v1 = param[13] == 0;
param[13] = v1;
if ( v1 )
glutTimerFunc((unsigned int)param[12], Main_timer, 0LL);
break;
case 'b':
param[15] = param[15] == 0;
break;
case 'c':
param[3] = param[3] == 0;
break;
case 'd':
param[5] = (param[5] + 1) % 3;
break;
case 'f':
param[2] = param[2] == 0;
break;
case 'i':
if ( !param[13] )
Main_inserePoint();
break;
case 'j':
param[0] = param[0] == 0;
break;
case 'm':
if ( terrainimpl && param[17] )
param[22] = param[22] == 0;
break;
case 'n':
if ( terrainimpl )
{
param[17] = param[17] == 0;
Main_touchesSpeciales(2);
printf("Min: %f Max:%f\n", *(double *)&param[18], *(double *)&param[20]);
}
break;
case 'o':
v3 = param[12] + 10;
if ( v3 > 1000 )
v3 = 1000;
param[12] = v3;
break;
case 'p':
v4 = param[12] - 10;
if ( v4 < 10 )
v4 = 1;
param[12] = v4;
break;
case 'q':
exit(0);
case 't':
param[4] = param[4] == 0;
break;
case 'w':
param[24] = param[24] == 0;
*(_QWORD *)&param[28] = *(_QWORD *)&param[26];
break;
case 'x':
if ( param[24] )
{
*(double *)&param[26] = *(double *)&param[26] - 0.1;
*(double *)&param[28] = *(double *)&param[28] - 0.1;
}
break;
case 'z':
if ( param[24] )
{
*(double *)&param[26] = *(double *)&param[26] + 0.1;
*(double *)&param[28] = *(double *)&param[28] + 0.1;
}
break;
default:
return glutPostRedisplay();
}
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
bool v1; // zf
int v3; // eax
int v4; // eax
__m128d v5; // xmm1
__m128d v6; // xmm0
__m128d v7; // xmm0

switch ( a1 )
{
case '+':
v5.m128d_f64[0] = *(double *)&param[34] + 0.05;
*(_QWORD *)&v6.m128d_f64[0] = LC1;
v6.m128d_f64[0] = _mm_cmplt_sd(v6, v5).m128d_f64[0];
*(_QWORD *)&param[34] = ~*(_QWORD *)&v6.m128d_f64[0] & *(_QWORD *)&v5.m128d_f64[0] | LC1 & *(_QWORD *)&v6.m128d_f64[0];
break;
case '-':
v7.m128d_f64[0] = *(double *)&param[34] - 0.05;
v7.m128d_f64[0] = _mm_cmplt_sd(v7, (__m128d)(unsigned __int64)LC41).m128d_f64[0];
*(_QWORD *)&param[34] = ~*(_QWORD *)&v7.m128d_f64[0] & COERCE_UNSIGNED_INT64(*(double *)&param[34] - 0.05) | LC41 & *(_QWORD *)&v7.m128d_f64[0];
break;
case 'a':
v1 = param[13] == 0;
param[13] = v1;
if ( v1 )
glutTimerFunc((unsigned int)param[12], Main_timer, 0LL);
break;
case 'b':
param[15] = param[15] == 0;
break;
case 'c':
param[3] = param[3] == 0;
break;
case 'd':
param[5] = (param[5] + 1) % 3;
break;
case 'f':
param[2] = param[2] == 0;
break;
case 'i':
if ( !param[13] )
func1();
break;
case 'j':
param[0] = param[0] == 0;
break;
case 'm':
if ( terrainimpl && param[17] )
param[22] = param[22] == 0;
break;
case 'n':
if ( terrainimpl )
{
param[17] = param[17] == 0;
func5(2);
printf("Min: %f Max:%f\n", *(double *)&param[18], *(double *)&param[20]);
}
break;
case 'o':
v3 = param[12] + 10;
if ( v3 > 1000 )
v3 = 1000;
param[12] = v3;
break;
case 'p':
v4 = param[12] - 10;
if ( v4 < 10 )
v4 = 1;
param[12] = v4;
break;
case 'q':
exit(0);
case 't':
param[4] = param[4] == 0;
break;
case 'w':
param[24] = param[24] == 0;
*(_QWORD *)&param[28] = *(_QWORD *)&param[26];
break;
case 'x':
if ( param[24] )
{
*(double *)&param[26] = *(double *)&param[26] - 0.1;
*(double *)&param[28] = *(double *)&param[28] - 0.1;
}
break;
case 'z':
if ( param[24] )
{
*(double *)&param[26] = *(double *)&param[26] + 0.1;
*(double *)&param[28] = *(double *)&param[28] + 0.1;
}
break;
default:
return glutPostRedisplay();
}
return glutPostRedisplay();
}

original_code:
void Main_clavier(unsigned char touche, int x, int y)
{
  SLTriangle *tmp = ((void *)0);
  switch(touche)
    {
    case 'a':
      param.auto_insert = !param.auto_insert;
      if(param.auto_insert)
 glutTimerFunc(param.timer_wait,Main_timer, 0);
      break;
    case 'b':
      param.barycentre = !param.barycentre;
      break;
    case 'c':
      param.circle = !param.circle;
      break;
    case 'd':
      param.draw = (param.draw+1)%3;
      break;
    case 'f' :
      param.filaire = !param.filaire;
      break;
    case 'i':
      if(!param.auto_insert)
 {
   Main_inserePoint();
   if(0==1){
     printf("Triangles are\n");
     tmp = tab.triangles->first;
     while(tmp!=((void *)0))
       {
  printf("\t Points are: %d %d %d\n",tmp->t->p1,tmp->t->p2,tmp->t->p3);
  printf("\t(%f,%f) (%f,%f) (%f,%f)\n",tab.p[tmp->t->p1].x,tab.p[tmp->t->p1].y,
         tab.p[tmp->t->p2].x,tab.p[tmp->t->p2].y,tab.p[tmp->t->p3].x,tab.p[tmp->t->p3].y);
  printf("Critere is %f\n",tmp->t->critere);
  tmp = tmp -> next;
       }
   }
 }
      break;
    case 'j':
      param.flip_algo = !param.flip_algo;
      break;
    case 'm':
      if((terrainimpl!=((void *)0))&&(param.norm_v2))
 param.flat = !param.flat;
      break;
    case 'n':
      if(terrainimpl!=((void *)0))
 {
   param.norm_v2 = !param.norm_v2;
   Main_touchesSpeciales(0x0002,0,0);
   printf("Min: %f Max:%f\n",param.min,param.max);
 }
      break;
    case 'o':
      param.timer_wait += 10;
      if(param.timer_wait>1000)
 param.timer_wait = 1000;
      break;
    case 'p':
      param.timer_wait -= 10;
      if(param.timer_wait<10)
 param.timer_wait = 1;
      break;
    case 'q' :
      exit(0);
      break;
    case 't':
      param.show_impl = !param.show_impl;
      break;
    case 'w':
      param.water = !param.water;
      param.w_cur = param.w_lvl;
      break;
    case 'x':
      if(param.water)
 {
   param.w_lvl -= 0.1;
   param.w_cur -= 0.1;
 }
      break;
    case 'z':
      if(param.water)
 {
   param.w_lvl += 0.1;
   param.w_cur += 0.1;
 }
      break;
    case '+':
      param.light+=0.05;
      if(param.light>1.0)
 param.light=1.0;
      break;
    case '-':
      param.light-=0.05;
      if(param.light<-1.0)
 param.light=-1.0;
      break;
    }
  glutPostRedisplay();
  (void) x;
  (void) y;
}

canonical_original_code:
void Main_clavier(unsigned char touche, int x, int y)
{
  struct sLTriangle *tmp = ((void *)0);
  switch(touche)
    {
    case 'a':
      param.auto_insert = !param.auto_insert;
      if(param.auto_insert)
 glutTimerFunc(param.timer_wait,Main_timer, 0);
      break;
    case 'b':
      param.barycentre = !param.barycentre;
      break;
    case 'c':
      param.circle = !param.circle;
      break;
    case 'd':
      param.draw = (param.draw+1)%3;
      break;
    case 'f' :
      param.filaire = !param.filaire;
      break;
    case 'i':
      if(!param.auto_insert)
 {
   Main_inserePoint();
   if(0==1){
     printf("Triangles are\n");
     tmp = tab.triangles->first;
     while(tmp!=((void *)0))
       {
  printf("\t Points are: %d %d %d\n",tmp->t->p1,tmp->t->p2,tmp->t->p3);
  printf("\t(%f,%f) (%f,%f) (%f,%f)\n",tab.p[tmp->t->p1].x,tab.p[tmp->t->p1].y,
         tab.p[tmp->t->p2].x,tab.p[tmp->t->p2].y,tab.p[tmp->t->p3].x,tab.p[tmp->t->p3].y);
  printf("Critere is %f\n",tmp->t->critere);
  tmp = tmp -> next;
       }
   }
 }
      break;
    case 'j':
      param.flip_algo = !param.flip_algo;
      break;
    case 'm':
      if((terrainimpl!=((void *)0))&&(param.norm_v2))
 param.flat = !param.flat;
      break;
    case 'n':
      if(terrainimpl!=((void *)0))
 {
   param.norm_v2 = !param.norm_v2;
   Main_touchesSpeciales(0x0002,0,0);
   printf("Min: %f Max:%f\n",param.min,param.max);
 }
      break;
    case 'o':
      param.timer_wait += 10;
      if(param.timer_wait>1000)
 param.timer_wait = 1000;
      break;
    case 'p':
      param.timer_wait -= 10;
      if(param.timer_wait<10)
 param.timer_wait = 1;
      break;
    case 'q' :
      exit(0);
      break;
    case 't':
      param.show_impl = !param.show_impl;
      break;
    case 'w':
      param.water = !param.water;
      param.w_cur = param.w_lvl;
      break;
    case 'x':
      if(param.water)
 {
   param.w_lvl -= 0.1;
   param.w_cur -= 0.1;
 }
      break;
    case 'z':
      if(param.water)
 {
   param.w_lvl += 0.1;
   param.w_cur += 0.1;
 }
      break;
    case '+':
      param.light+=0.05;
      if(param.light>1.0)
 param.light=1.0;
      break;
    case '-':
      param.light-=0.05;
      if(param.light<-1.0)
 param.light=-1.0;
      break;
    }
  glutPostRedisplay();
  (void) x;
  (void) y;
}

variable_types:
touche
unsigned char

variable_types: struct sLTriangle { struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint { double x; } centre; double rayon; double critere; } *t; struct sLTriangle *next; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // edx
int v6; // [rsp+Ch] [rbp-2Ch] BYREF
int v7[4]; // [rsp+10h] [rbp-28h] BYREF
int v8[6]; // [rsp+20h] [rbp-18h] BYREF

v6 = argc;
glutInit(&v6, argv, envp);
v3 = time(0LL);
srand(v3);
DestCons_InitTab();
glutInitDisplayMode(18LL);
glutInitWindowSize(640LL, 480LL);
glutCreateWindow("Delaunay");
glClearColor(0.0, 0.0, 0.0);
glEnable(2929LL);
glViewport(0LL, 0LL, 640LL, 480LL);
glMatrixMode(5889LL);
glLoadIdentity();
gluPerspective(40.0, 1.333333373069763, 1.0, 25.0);
glMatrixMode(5888LL);
v8[0] = LC14;
v8[1] = LC14;
v8[2] = 0;
v8[3] = 0;
v7[0] = LC14;
v7[1] = LC14;
v7[2] = LC14;
v7[3] = LC14;
glLightfv(0x4000LL, 4611LL, v8);
glLightfv(0x4000LL, 4609LL, v7);
glLightfv(0x4000LL, 4610LL, v7);
glutReshapeFunc(Main_redimFenetre);
glutDisplayFunc(Main_affichage);
glutKeyboardFunc(Main_clavier);
glutSpecialFunc(Main_touchesSpeciales);
terrainimpl = (void *)TerrainImpl_Init(4LL, -10.0, 10.0, -10.0, 10.0);
v4 = 1;
if ( terrainimpl )
{
glutMainLoop(4LL, 4LL, 1LL);
v4 = 0;
}
return v4;
}

original_code:
int main( int argc, char *argv[])
{
  glutInit(&argc,argv);
  srand(time(((void *)0)));
  DestCons_InitTab();
  glutInitDisplayMode(0x0000
        | 0x0002
        | 0x0010);
  glutInitWindowSize(640,480);
  glutCreateWindow("Delaunay");
  glClearColor(0.0,0.0,0.0,0.0);
  glEnable(0x0B71);
  GLfloat rapport = ((float)(640))/((float)(480));
  glViewport(0,0,640,480);
  glMatrixMode(0x1701);
  glLoadIdentity();
  gluPerspective(40,rapport,1.0,25.0);
  glMatrixMode(0x1700);
  GLfloat positionLumiere[] = {1.0,1.0,0.0,0.0};
  GLfloat couleurLumiere[] = {1.0,1.0,1.0,1.0};
  glLightfv(0x4000, 0x1203, positionLumiere);
  glLightfv(0x4000, 0x1201, couleurLumiere);
  glLightfv(0x4000, 0x1202, couleurLumiere);
  glutReshapeFunc(Main_redimFenetre);
  glutDisplayFunc(Main_affichage);
  glutKeyboardFunc(Main_clavier);
  glutSpecialFunc(Main_touchesSpeciales);
  terrainimpl = TerrainImpl_Init(4,4,-10,10,-10,10);
  if(terrainimpl==((void *)0))
    return 1;
  glutMainLoop();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  glutInit(&argc,argv);
  srand(time(((void *)0)));
  DestCons_InitTab();
  glutInitDisplayMode(0x0000
        | 0x0002
        | 0x0010);
  glutInitWindowSize(640,480);
  glutCreateWindow("Delaunay");
  glClearColor(0.0,0.0,0.0,0.0);
  glEnable(0x0B71);
  float rapport = ((float)(640))/((float)(480));
  glViewport(0,0,640,480);
  glMatrixMode(0x1701);
  glLoadIdentity();
  gluPerspective(40,rapport,1.0,25.0);
  glMatrixMode(0x1700);
  float positionLumiere[] = {1.0,1.0,0.0,0.0};
  float couleurLumiere[] = {1.0,1.0,1.0,1.0};
  glLightfv(0x4000, 0x1203, positionLumiere);
  glLightfv(0x4000, 0x1201, couleurLumiere);
  glLightfv(0x4000, 0x1202, couleurLumiere);
  glutReshapeFunc(Main_redimFenetre);
  glutDisplayFunc(Main_affichage);
  glutKeyboardFunc(Main_clavier);
  glutSpecialFunc(Main_touchesSpeciales);
  terrainimpl = TerrainImpl_Init(4,4,-10,10,-10,10);
  if(terrainimpl==((void *)0))
    return 1;
  glutMainLoop();
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
positionLumiere
float []

variable_types:
couleurLumiere
float []


decompiled_code:
_BOOL8 __fastcall Liste_TriangleIsIn(__int64 a1, __int64 **a2)
{
__int64 *v2; // rax
__int64 v3; // rdx

v2 = *a2;
if ( !a1 || !v2 )
return 0LL;
do
{
v3 = *v2;
v2 = (__int64 *)v2[1];
}
while ( v3 != a1 && v2 );
return v3 == a1;
}

original_code:
int Liste_TriangleIsIn(STriangle *t1, SStartT *t2)
{
 int res=0;
 if((t2->first!=((void *)0))&&(t1!=((void *)0)))
 {
  SLTriangle *tmp=t2->first;
  while( (!res) && (tmp!=((void *)0)) )
  {
   res=( (res) || (tmp->t==t1)) ;
   tmp=tmp->next;
  }
 }
 return res;
}

canonical_original_code:
int Liste_TriangleIsIn(struct sTriangle *t1, struct sStartT *t2)
{
 int res = 0;
 if((t2->first!=((void *)0))&&(t1!=((void *)0)))
 {
  struct sLTriangle *tmp = t2->first;
  while( (!res) && (tmp!=((void *)0)) )
  {
   res=( (res) || (tmp->t==t1)) ;
   tmp=tmp->next;
  }
 }
 return res;
}

variable_types: struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint { double x; } centre; double rayon; double critere; } *

variable_types: struct sStartT { struct sLTriangle { struct sTriangle *t; struct sLTriangle *next; } *first; } *

variable_types: res int

user_defined_types: struct sStartT { struct sLTriangle *first; }


decompiled_code:
__int64 __fastcall Global_AddPoint(double a1, double a2, double a3)
{
unsigned int v3; // ecx
__int64 v4; // rsi

v3 = *((_DWORD *)&tab + 4);
v4 = 3LL * (int)v3;
*((double *)&tab + v4 + 3) = a1;
*((double *)&tab + v4 + 4) = a2;
*((double *)&tab + v4 + 5) = a3;
*((_DWORD *)&tab + 4) = v3 + 1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(double a1, double a2, double a3)
{
unsigned int v3; // ecx
__int64 v4; // rsi

v3 = *((_DWORD *)&tab + 4);
v4 = 3LL * (int)v3;
*((double *)&tab + v4 + 3) = a1;
*((double *)&tab + v4 + 4) = a2;
*((double *)&tab + v4 + 5) = a3;
*((_DWORD *)&tab + 4) = v3 + 1;
return v3;
}

original_code:
int Global_AddPoint(double x,double y,double z)
{
 tab.p[tab.np].x=x;
 tab.p[tab.np].y=y;
 tab.p[tab.np].z=z;
 return tab.np++;
}

canonical_original_code:
int Global_AddPoint(double x, double y, double z)
{
 tab.p[tab.np].x=x;
 tab.p[tab.np].y=y;
 tab.p[tab.np].z=z;
 return tab.np++;
}

variable_types: x double

variable_types: y double

variable_types: z double


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

--tab;
result = Liste_EffTriangle(a1, *((_QWORD *)&tab + 1));
if ( !tab )
**((_QWORD **)&tab + 1) = 0LL;
return result;
}

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

--tab;
result = func5(a1, *((_QWORD *)&tab + 1));
if ( !tab )
**((_QWORD **)&tab + 1) = 0LL;
return result;
}

original_code:
int Global_EffTriangleListe(STriangle *t)
{
 int res;
 tab.nt--;
 res = Liste_EffTriangle(t,tab.triangles);
 if(tab.nt==0)
  tab.triangles->first = ((void *)0);
 return res;
}

canonical_original_code:
int Global_EffTriangleListe(struct sTriangle *t)
{
 int res;
 tab.nt--;
 res = Liste_EffTriangle(t,tab.triangles);
 if(tab.nt==0)
  tab.triangles->first = ((void *)0);
 return res;
}


decompiled_code:
__int64 __fastcall Liste_EffTriangle(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rax

result = 1LL;
if ( a1 )
{
v3 = *a2;
if ( *a2 )
{
if ( *(_QWORD *)v3 == a1 )
{
*a2 = *(_QWORD *)(v3 + 8);
if ( !*(_DWORD *)(a1 + 4) || *((__int64 **)&tab + 1) == a2 )
free(*(void **)v3);
else
Global_EffTriangleListe(a1);
free((void *)v3);
result = 1LL;
}
else
{
do
{
v4 = v3;
v3 = *(_QWORD *)(v3 + 8);
if ( !v3 )
return 0LL;
}
while ( *(_QWORD *)v3 != a1 );
*(_QWORD *)(v4 + 8) = *(_QWORD *)(v3 + 8);
if ( !*(_DWORD *)(a1 + 4) || *((__int64 **)&tab + 1) == a2 )
free(*(void **)v3);
else
Global_EffTriangleListe(a1);
free((void *)v3);
result = 1LL;
}
}
}
return result;
}

original_code:
int Liste_EffTriangle(STriangle *t1, SStartT *t2)
{
 if (t1!=((void *)0))
 if(t2->first!=((void *)0))
 {
  int res=0;
  SLTriangle *tmp=t2->first, *tmp2=tmp;
  if (tmp->t==t1)
  {
   t2->first=tmp->next;
   if( (t1->flip_param)&&(t2!=tab.triangles))
     Global_EffTriangleListe(t1);
    else
     free(tmp->t);
   free(tmp);
  }
  else
  while(!res)
  {
   if (tmp==((void *)0))
    return 0;
   else
   if(tmp->t==t1)
   {
    tmp2->next=tmp->next;
    if( (t1->flip_param)&&(t2!=tab.triangles))
     Global_EffTriangleListe(t1);
    else
     free(tmp->t);
    free(tmp);
    res=1;
   }
   else
   {
    tmp2=tmp;
    tmp=tmp->next;
   }
  }
 }
 return 1;
}

canonical_original_code:
int Liste_EffTriangle(struct sTriangle *t1, struct sStartT *t2)
{
 if (t1!=((void *)0))
 if(t2->first!=((void *)0))
 {
  int res = 0;
  struct sLTriangle *tmp = t2->first; struct sLTriangle *tmp2 = tmp;
  if (tmp->t==t1)
  {
   t2->first=tmp->next;
   if( (t1->flip_param)&&(t2!=tab.triangles))
     Global_EffTriangleListe(t1);
    else
     free(tmp->t);
   free(tmp);
  }
  else
  while(!res)
  {
   if (tmp==((void *)0))
    return 0;
   else
   if(tmp->t==t1)
   {
    tmp2->next=tmp->next;
    if( (t1->flip_param)&&(t2!=tab.triangles))
     Global_EffTriangleListe(t1);
    else
     free(tmp->t);
    free(tmp);
    res=1;
   }
   else
   {
    tmp2=tmp;
    tmp=tmp->next;
   }
  }
 }
 return 1;
}


decompiled_code:
void __fastcall Global_DestructionListe(__int64 *a1)
{
__int64 v1; // rbx
__int64 v2; // rbp

v1 = *a1;
if ( *a1 )
{
while ( 1 )
{
if ( *(_QWORD *)v1 )
free(*(void **)v1);
v2 = *(_QWORD *)(v1 + 8);
free((void *)v1);
if ( !v2 )
break;
v1 = v2;
}
}
}

original_code:
void Global_DestructionListe(SStartT *t)
{
 SLTriangle *tmp=t->first,*tmp2=t->first;
 while(tmp!=((void *)0))
 {
  if(tmp->t!=((void *)0))
   free(tmp->t);
  tmp=tmp->next;
  free(tmp2);
  tmp2=tmp;
 }
}

canonical_original_code:
void Global_DestructionListe(struct sStartT *t)
{
 struct sLTriangle *tmp = t->first; struct sLTriangle *tmp2 = t->first;
 while(tmp!=((void *)0))
 {
  if(tmp->t!=((void *)0))
   free(tmp->t);
  tmp=tmp->next;
  free(tmp2);
  tmp2=tmp;
 }
}

variable_types: struct sStartT { struct sLTriangle { struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint { double x; } centre; double rayon; double critere; } *t; struct sLTriangle *next; } *first; } *


decompiled_code:
void __fastcall FlipAlgo_InserePoint()
{
_QWORD *v0; // rbp
__int64 v1; // r15
unsigned int v2; // er14
__int64 *v3; // rax
__int64 v4; // rbx
__int64 v5; // r12
__int64 v6; // r13
__int64 v7; // r14
int i; // eax
unsigned int v9; // er15
unsigned int v10; // er13
unsigned int v11; // ebx
unsigned int v12; // ebp
_QWORD *v13; // rbx
void *v14; // rdi
void *ptr[8]; // [rsp+8h] [rbp-40h] BYREF

ptr[0] = 0LL;
if ( param[14] )
return;
if ( *((int *)&tab + 4) > 9999 || tab > 9998 )
{
param[14] = 1;
return;
}
v2 = Delaunay_ChoisitPoint();
v3 = (__int64 *)**((_QWORD **)&tab + 1);
v4 = *v3;
v5 = Triangle_Cree(v2, *(unsigned int *)(*v3 + 8), *(unsigned int *)(*v3 + 12));
v6 = Triangle_Cree(v2, *(unsigned int *)(v4 + 12), *(unsigned int *)(v4 + 16));
v7 = Triangle_Cree(v2, *(unsigned int *)(v4 + 16), *(unsigned int *)(v4 + 8));
*(_QWORD *)(v5 + 24) = v7;
*(_QWORD *)(v5 + 32) = *(_QWORD *)(v4 + 24);
*(_QWORD *)(v5 + 40) = v6;
*(_QWORD *)(v6 + 24) = v5;
*(_QWORD *)(v6 + 32) = *(_QWORD *)(v4 + 32);
*(_QWORD *)(v6 + 40) = v7;
*(_QWORD *)(v7 + 24) = v6;
*(_QWORD *)(v7 + 32) = *(_QWORD *)(v4 + 40);
*(_QWORD *)(v7 + 40) = v5;
for ( i = 1; ; ++i )
{
if ( i == 2 )
{
v0 = *(_QWORD **)(v4 + 32);
v1 = v6;
LABEL_8:
if ( !v0 )
continue;
goto LABEL_9;
}
if ( i != 3 )
{
if ( i != 1 )
{
if ( !v0 )
goto LABEL_15;
goto LABEL_9;
}
v0 = *(_QWORD **)(v4 + 24);
v1 = v5;
goto LABEL_8;
}
v0 = *(_QWORD **)(v4 + 40);
if ( !v0 )
break;
v1 = v7;
LABEL_9:
if ( v0[3] == v4 )
v0[3] = v1;
if ( v0[4] == v4 )
v0[4] = v1;
if ( v0[5] == v4 )
v0[5] = v1;
LABEL_15:
if ( i > 2 )
break;
}
Global_EffTriangleListe(v4);
Liste_AddTriangle(v5, ptr);
Liste_AddTriangle(v6, ptr);
Liste_AddTriangle(v7, ptr);
Liste_AddTriangle(*(_QWORD *)(v5 + 32), ptr);
Liste_AddTriangle(*(_QWORD *)(v6 + 32), ptr);
Liste_AddTriangle(*(_QWORD *)(v7 + 32), ptr);
v9 = *(_DWORD *)(v6 + 12);
v10 = *(_DWORD *)(v6 + 16);
v11 = *(_DWORD *)(v7 + 12);
v12 = *(_DWORD *)(v7 + 16);
FlipAlgo_CoteIllegal(*(_DWORD *)(v5 + 12), *(_DWORD *)(v5 + 16), (_QWORD **)ptr);
FlipAlgo_CoteIllegal(v9, v10, (_QWORD **)ptr);
FlipAlgo_CoteIllegal(v11, v12, (_QWORD **)ptr);
v13 = ptr[0];
if ( ptr[0] )
{
do
{
Global_AddTriangleListe(*v13);
v14 = v13;
v13 = (_QWORD *)v13[1];
free(v14);
}
while ( v13 );
}
}

canonical_decompiled_code:
void __fastcall func1()
{
_QWORD *v0; // rbp
__int64 v1; // r15
unsigned int v2; // er14
__int64 *v3; // rax
__int64 v4; // rbx
__int64 v5; // r12
__int64 v6; // r13
__int64 v7; // r14
int i; // eax
unsigned int v9; // er15
unsigned int v10; // er13
unsigned int v11; // ebx
unsigned int v12; // ebp
_QWORD *v13; // rbx
void *v14; // rdi
void *ptr[8]; // [rsp+8h] [rbp-40h] BYREF

ptr[0] = 0LL;
if ( param[14] )
return;
if ( *((int *)&tab + 4) > 9999 || tab > 9998 )
{
param[14] = 1;
return;
}
v2 = Delaunay_ChoisitPoint();
v3 = (__int64 *)**((_QWORD **)&tab + 1);
v4 = *v3;
v5 = Triangle_Cree(v2, *(unsigned int *)(*v3 + 8), *(unsigned int *)(*v3 + 12));
v6 = Triangle_Cree(v2, *(unsigned int *)(v4 + 12), *(unsigned int *)(v4 + 16));
v7 = Triangle_Cree(v2, *(unsigned int *)(v4 + 16), *(unsigned int *)(v4 + 8));
*(_QWORD *)(v5 + 24) = v7;
*(_QWORD *)(v5 + 32) = *(_QWORD *)(v4 + 24);
*(_QWORD *)(v5 + 40) = v6;
*(_QWORD *)(v6 + 24) = v5;
*(_QWORD *)(v6 + 32) = *(_QWORD *)(v4 + 32);
*(_QWORD *)(v6 + 40) = v7;
*(_QWORD *)(v7 + 24) = v6;
*(_QWORD *)(v7 + 32) = *(_QWORD *)(v4 + 40);
*(_QWORD *)(v7 + 40) = v5;
for ( i = 1; ; ++i )
{
if ( i == 2 )
{
v0 = *(_QWORD **)(v4 + 32);
v1 = v6;
LABEL_8:
if ( !v0 )
continue;
goto LABEL_9;
}
if ( i != 3 )
{
if ( i != 1 )
{
if ( !v0 )
goto LABEL_15;
goto LABEL_9;
}
v0 = *(_QWORD **)(v4 + 24);
v1 = v5;
goto LABEL_8;
}
v0 = *(_QWORD **)(v4 + 40);
if ( !v0 )
break;
v1 = v7;
LABEL_9:
if ( v0[3] == v4 )
v0[3] = v1;
if ( v0[4] == v4 )
v0[4] = v1;
if ( v0[5] == v4 )
v0[5] = v1;
LABEL_15:
if ( i > 2 )
break;
}
Global_EffTriangleListe(v4);
Liste_AddTriangle(v5, ptr);
Liste_AddTriangle(v6, ptr);
Liste_AddTriangle(v7, ptr);
Liste_AddTriangle(*(_QWORD *)(v5 + 32), ptr);
Liste_AddTriangle(*(_QWORD *)(v6 + 32), ptr);
Liste_AddTriangle(*(_QWORD *)(v7 + 32), ptr);
v9 = *(_DWORD *)(v6 + 12);
v10 = *(_DWORD *)(v6 + 16);
v11 = *(_DWORD *)(v7 + 12);
v12 = *(_DWORD *)(v7 + 16);
func0(*(_DWORD *)(v5 + 12), *(_DWORD *)(v5 + 16), (_QWORD **)ptr);
func0(v9, v10, (_QWORD **)ptr);
func0(v11, v12, (_QWORD **)ptr);
v13 = ptr[0];
if ( ptr[0] )
{
do
{
Global_AddTriangleListe(*v13);
v14 = v13;
v13 = (_QWORD *)v13[1];
free(v14);
}
while ( v13 );
}
}

original_code:
void FlipAlgo_InserePoint()
{
 int i;
 int p;
 SStartT list;
 SLTriangle *l,*l2;
 STriangle *t1,*t2,*t3,*t,*tmp,*tmp2;
 list.first=((void *)0);
 if(param.stop_insert)
  return;
 if((tab.np>=10000)||(tab.nt>=9999))
 {
  param.stop_insert=1;
  return;
 }
 p = Delaunay_ChoisitPoint();
 t = tab.triangles->first->t;
 t1 = Triangle_Cree(p,t->p1,t->p2);
 t2 = Triangle_Cree(p,t->p2,t->p3);
 t3 = Triangle_Cree(p,t->p3,t->p1);
 t1->t1 = t3;
 t1->t2 = t->t1;
 t1->t3 = t2;
 t2->t1 = t1;
 t2->t2 = t->t2;
 t2->t3 = t3;
 t3->t1 = t2;
 t3->t2 = t->t3;
 t3->t3 = t1;
 for(i=0;i<3;i++)
 {
  switch(i)
  {
  case 0: tmp = t->t1;
   tmp2 = t1;
   break;
  case 1: tmp = t->t2;
   tmp2 = t2;
   break;
  case 2: tmp = t->t3;
   tmp2 = t3;
   break;
  }
  if(tmp!=((void *)0))
  {
   if(tmp->t1==t)
    tmp->t1=tmp2;
   if(tmp->t2==t)
    tmp->t2=tmp2;
   if(tmp->t3==t)
    tmp->t3=tmp2;
  }
 }
 Global_EffTriangleListe(t);
 Liste_AddTriangle(t1,&list);
 Liste_AddTriangle(t2,&list);
 Liste_AddTriangle(t3,&list);
 Liste_AddTriangle(t1->t2,&list);
 Liste_AddTriangle(t2->t2,&list);
 Liste_AddTriangle(t3->t2,&list);
 int p1 = t1->p2, p2 = t1->p3, p3 = t2->p2, p4 = t2->p3,
  p5 = t3->p2, p6 = t3->p3;
 FlipAlgo_CoteIllegal(p1,p2,&list);
 FlipAlgo_CoteIllegal(p3,p4,&list);
 FlipAlgo_CoteIllegal(p5,p6,&list);
 l = list.first;
 while(l!=((void *)0))
 {
  Global_AddTriangleListe(l->t);
  l2 = l->next;
  free(l);
  l = l2;
 }
}

canonical_original_code:
void FlipAlgo_InserePoint()
{
 int i;
 int p;
 struct sStartT list;
 struct sLTriangle *l; struct sLTriangle *l2;
 struct sTriangle *t1; struct sTriangle *t2; struct sTriangle *t3; struct sTriangle *t; struct sTriangle *tmp; struct sTriangle *tmp2;
 list.first=((void *)0);
 if(param.stop_insert)
  return;
 if((tab.np>=10000)||(tab.nt>=9999))
 {
  param.stop_insert=1;
  return;
 }
 p = Delaunay_ChoisitPoint();
 t = tab.triangles->first->t;
 t1 = Triangle_Cree(p,t->p1,t->p2);
 t2 = Triangle_Cree(p,t->p2,t->p3);
 t3 = Triangle_Cree(p,t->p3,t->p1);
 t1->t1 = t3;
 t1->t2 = t->t1;
 t1->t3 = t2;
 t2->t1 = t1;
 t2->t2 = t->t2;
 t2->t3 = t3;
 t3->t1 = t2;
 t3->t2 = t->t3;
 t3->t3 = t1;
 for(i=0;i<3;i++)
 {
  switch(i)
  {
  case 0: tmp = t->t1;
   tmp2 = t1;
   break;
  case 1: tmp = t->t2;
   tmp2 = t2;
   break;
  case 2: tmp = t->t3;
   tmp2 = t3;
   break;
  }
  if(tmp!=((void *)0))
  {
   if(tmp->t1==t)
    tmp->t1=tmp2;
   if(tmp->t2==t)
    tmp->t2=tmp2;
   if(tmp->t3==t)
    tmp->t3=tmp2;
  }
 }
 Global_EffTriangleListe(t);
 Liste_AddTriangle(t1,&list);
 Liste_AddTriangle(t2,&list);
 Liste_AddTriangle(t3,&list);
 Liste_AddTriangle(t1->t2,&list);
 Liste_AddTriangle(t2->t2,&list);
 Liste_AddTriangle(t3->t2,&list);
 int p1 = t1->p2; int p2 = t1->p3; int p3 = t2->p2; int p4 = t2->p3; int p5 = t3->p2; int p6 = t3->p3;
 FlipAlgo_CoteIllegal(p1,p2,&list);
 FlipAlgo_CoteIllegal(p3,p4,&list);
 FlipAlgo_CoteIllegal(p5,p6,&list);
 l = list.first;
 while(l!=((void *)0))
 {
  Global_AddTriangleListe(l->t);
  l2 = l->next;
  free(l);
  l = l2;
 }
}

variable_types: i int

variable_types: p int

variable_types: struct sStartT { struct sLTriangle { struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint { double x; } centre; double rayon; double critere; } *t; struct sLTriangle *next; } *first; }


decompiled_code:
__int64 __fastcall DestCons_DeterminerTAD(_QWORD *a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rbp
int i; // ebx
__int64 result; // rax

Liste_AddTriangle(a1, a2);
for ( i = 1; ; ++i )
{
result = (unsigned int)(i - 1);
if ( i == 2 )
{
v3 = a1[4];
goto LABEL_3;
}
if ( i != 3 )
{
if ( i != 1 )
{
if ( !v3 )
goto LABEL_5;
goto LABEL_4;
}
v3 = a1[3];
LABEL_3:
if ( !v3 )
continue;
LABEL_4:
result = Liste_TriangleIsIn(v3, a2);
if ( (_DWORD)result )
goto LABEL_5;
goto LABEL_16;
}
v3 = a1[5];
if ( !v3 )
break;
result = Liste_TriangleIsIn(a1[5], a2);
if ( (_DWORD)result )
break;
LABEL_16:
result = Delaunay_PointInCercle(a3, v3);
if ( (_DWORD)result )
result = DestCons_DeterminerTAD(v3, a2, a3);
LABEL_5:
if ( i > 2 )
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rbp
int i; // ebx
__int64 result; // rax

Liste_AddTriangle(a1, a2);
for ( i = 1; ; ++i )
{
result = (unsigned int)(i - 1);
if ( i == 2 )
{
v3 = a1[4];
goto LABEL_3;
}
if ( i != 3 )
{
if ( i != 1 )
{
if ( !v3 )
goto LABEL_5;
goto LABEL_4;
}
v3 = a1[3];
LABEL_3:
if ( !v3 )
continue;
LABEL_4:
result = Liste_TriangleIsIn(v3, a2);
if ( (_DWORD)result )
goto LABEL_5;
goto LABEL_16;
}
v3 = a1[5];
if ( !v3 )
break;
result = Liste_TriangleIsIn(a1[5], a2);
if ( (_DWORD)result )
break;
LABEL_16:
result = Delaunay_PointInCercle(a3, v3);
if ( (_DWORD)result )
result = func2(v3, a2, a3);
LABEL_5:
if ( i > 2 )
return result;
}
return result;
}

original_code:
void DestCons_DeterminerTAD(STriangle *t, SStartT *lt,int p)
{
 int i;
 STriangle* tmp;
 Liste_AddTriangle(t,lt);
 for(i=0;i<3;i++)
  {
  switch(i)
   {
   case 0:
    tmp = t->t1;
    break;
   case 1:
    tmp = t->t2;
    break;
   case 2:
    tmp = t->t3;
    break;
   default: break;
   }
  if(tmp!=((void *)0))
   {
   if(!Liste_TriangleIsIn(tmp, lt))
    {
    if(Delaunay_PointInCercle(p,tmp))
     {
     DestCons_DeterminerTAD(tmp,lt,p);
     }
    }
   }
  }
}

canonical_original_code:
void DestCons_DeterminerTAD(struct sTriangle *t, struct sStartT *lt, int p)
{
 int i;
 struct sTriangle *tmp;
 Liste_AddTriangle(t,lt);
 for(i=0;i<3;i++)
  {
  switch(i)
   {
   case 0:
    tmp = t->t1;
    break;
   case 1:
    tmp = t->t2;
    break;
   case 2:
    tmp = t->t3;
    break;
   default: break;
   }
  if(tmp!=((void *)0))
   {
   if(!Liste_TriangleIsIn(tmp, lt))
    {
    if(Delaunay_PointInCercle(p,tmp))
     {
     DestCons_DeterminerTAD(tmp,lt,p);
     }
    }
   }
  }
}


decompiled_code:
__int64 DestCons_InitTab()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
_QWORD *v2; // rax

v0 = malloc(8uLL);
*((_QWORD *)&tab + 1) = v0;
if ( !v0 )
{
puts("Erreur d'allocation de malloc dans DestCons_InitTab");
exit(1);
}
*((_DWORD *)&tab + 4) = 4;
*((_QWORD *)&tab + 3) = LC3;
*((_OWORD *)&tab + 2) = (unsigned __int64)LC4;
*((_QWORD *)&tab + 6) = LC4;
*(_OWORD *)((char *)&tab + 56) = (unsigned __int64)LC4;
*((_QWORD *)&tab + 9) = LC4;
*((_OWORD *)&tab + 5) = (unsigned __int64)LC3;
*((_QWORD *)&tab + 12) = LC3;
*(_OWORD *)((char *)&tab + 104) = (unsigned __int64)LC3;
*v0 = 0LL;
v1 = (_QWORD *)Triangle_Cree(2LL, 1LL, 0LL);
v2 = (_QWORD *)Triangle_Cree(2LL, 0LL, 3LL);
v1[3] = 0LL;
v1[4] = 0LL;
v1[5] = v2;
v2[3] = v1;
v2[4] = 0LL;
v2[5] = 0LL;
tab = 0;
Global_AddTriangleListe(v2);
return Global_AddTriangleListe(v1);
}

canonical_decompiled_code:
__int64 func3()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
_QWORD *v2; // rax

v0 = malloc(8uLL);
*((_QWORD *)&tab + 1) = v0;
if ( !v0 )
{
puts("Erreur d'allocation de malloc dans DestCons_InitTab");
exit(1);
}
*((_DWORD *)&tab + 4) = 4;
*((_QWORD *)&tab + 3) = LC3;
*((_OWORD *)&tab + 2) = (unsigned __int64)LC4;
*((_QWORD *)&tab + 6) = LC4;
*(_OWORD *)((char *)&tab + 56) = (unsigned __int64)LC4;
*((_QWORD *)&tab + 9) = LC4;
*((_OWORD *)&tab + 5) = (unsigned __int64)LC3;
*((_QWORD *)&tab + 12) = LC3;
*(_OWORD *)((char *)&tab + 104) = (unsigned __int64)LC3;
*v0 = 0LL;
v1 = (_QWORD *)Triangle_Cree(2LL, 1LL, 0LL);
v2 = (_QWORD *)Triangle_Cree(2LL, 0LL, 3LL);
v1[3] = 0LL;
v1[4] = 0LL;
v1[5] = v2;
v2[3] = v1;
v2[4] = 0LL;
v2[5] = 0LL;
tab = 0;
Global_AddTriangleListe(v2);
return Global_AddTriangleListe(v1);
}

original_code:
void DestCons_InitTab()
{
 STriangle *tmp,*tmp2;
 tab.triangles = malloc(sizeof(SStartT));
 if(tab.triangles==((void *)0))
  {
  printf("Erreur d'allocation de malloc dans DestCons_InitTab\n");
  exit(1);
  }
 tab.np=4;
 tab.p[0].x = -10.0f;
 tab.p[0].y = 10.0f;
 tab.p[0].z = 0.0f;
 tab.p[1].x = 10.0f;
 tab.p[1].y = 10.0f;
 tab.p[1].z = 0.0f;
 tab.p[2].x = 10.0f;
 tab.p[2].y = -10.0f;
 tab.p[2].z = 0.0f;
 tab.p[3].x = -10.0f;
 tab.p[3].y = -10.0f;
 tab.p[3].z = 0.0f;
 tab.triangles->first=((void *)0);
 tmp = Triangle_Cree(2,1,0);
 tmp2 = Triangle_Cree(2,0,3);
 tmp->t1 = ((void *)0);
 tmp->t2 = ((void *)0);
 tmp->t3 = tmp2;
 tmp2->t1 = tmp;
 tmp2->t2 = ((void *)0);
 tmp2->t3 = ((void *)0);
 tab.nt=0;
 Global_AddTriangleListe(tmp2);
 Global_AddTriangleListe(tmp);
}

canonical_original_code:
void DestCons_InitTab()
{
 struct sTriangle *tmp; struct sTriangle *tmp2;
 tab.triangles = malloc(sizeof(SStartT));
 if(tab.triangles==((void *)0))
  {
  printf("Erreur d'allocation de malloc dans DestCons_InitTab\n");
  exit(1);
  }
 tab.np=4;
 tab.p[0].x = -10.0f;
 tab.p[0].y = 10.0f;
 tab.p[0].z = 0.0f;
 tab.p[1].x = 10.0f;
 tab.p[1].y = 10.0f;
 tab.p[1].z = 0.0f;
 tab.p[2].x = 10.0f;
 tab.p[2].y = -10.0f;
 tab.p[2].z = 0.0f;
 tab.p[3].x = -10.0f;
 tab.p[3].y = -10.0f;
 tab.p[3].z = 0.0f;
 tab.triangles->first=((void *)0);
 tmp = Triangle_Cree(2,1,0);
 tmp2 = Triangle_Cree(2,0,3);
 tmp->t1 = ((void *)0);
 tmp->t2 = ((void *)0);
 tmp->t3 = tmp2;
 tmp2->t1 = tmp;
 tmp2->t2 = ((void *)0);
 tmp2->t3 = ((void *)0);
 tab.nt=0;
 Global_AddTriangleListe(tmp2);
 Global_AddTriangleListe(tmp);
}


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

Global_DestructionListe(tab[1]);
DestCons_InitTab();
param[14] = 0;
result = (param[16] >> 2) & 1;
param[4] = result;
return result;
}

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

Global_DestructionListe(tab[1]);
func3();
param[14] = 0;
result = (param[16] >> 2) & 1;
param[4] = result;
return result;
}

original_code:
void DestCons_ResetTab()
{
 Global_DestructionListe(tab.triangles);
 DestCons_InitTab();
 param.stop_insert = 0;
 if(param.gentype&4)
  param.show_impl = 1;
 else
  param.show_impl = 0;
}


decompiled_code:
void DestCons_InserePoint()
{
unsigned int v0; // ebx
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void *v3; // rdi
void *v4; // rdi
void *v5; // [rsp+0h] [rbp-28h] BYREF
void *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v5 = 0LL;
ptr[0] = 0LL;
if ( !param[14] )
{
if ( SLODWORD(tab[2]) <= 9999 && SLODWORD(tab[0]) <= 9998 )
{
v0 = Delaunay_ChoisitPoint();
DestCons_DeterminerTAD(**(_QWORD ***)tab[1], (__int64)ptr, v0);
DestCons_DeterminerTAC((__int64 **)ptr, (_QWORD **)&v5, v0);
v1 = v5;
if ( v5 )
{
v2 = ptr[0];
if ( !ptr[0] )
goto LABEL_15;
do
{
Global_EffTriangleListe(*v2);
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
v1 = v5;
if ( v5 )
{
LABEL_15:
do
{
Global_AddTriangleListe(*v1);
v4 = v1;
v1 = (_QWORD *)v1[1];
free(v4);
}
while ( v1 );
}
}
else
{
param[14] = 1;
}
}
else
{
param[14] = 1;
}
}
}

canonical_decompiled_code:
void func5()
{
unsigned int v0; // ebx
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void *v3; // rdi
void *v4; // rdi
void *v5; // [rsp+0h] [rbp-28h] BYREF
void *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v5 = 0LL;
ptr[0] = 0LL;
if ( !param[14] )
{
if ( SLODWORD(tab[2]) <= 9999 && SLODWORD(tab[0]) <= 9998 )
{
v0 = Delaunay_ChoisitPoint();
func2(**(_QWORD ***)tab[1], (__int64)ptr, v0);
func1((__int64 **)ptr, (_QWORD **)&v5, v0);
v1 = v5;
if ( v5 )
{
v2 = ptr[0];
if ( !ptr[0] )
goto LABEL_15;
do
{
Global_EffTriangleListe(*v2);
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
v1 = v5;
if ( v5 )
{
LABEL_15:
do
{
Global_AddTriangleListe(*v1);
v4 = v1;
v1 = (_QWORD *)v1[1];
free(v4);
}
while ( v1 );
}
}
else
{
param[14] = 1;
}
}
else
{
param[14] = 1;
}
}
}

original_code:
void DestCons_InserePoint()
{
 int p;
 SStartT Tad,Tac;
 SLTriangle* tmp,*tmp2;
 Tac.first = ((void *)0);
 Tad.first = ((void *)0);
 if(param.stop_insert)
  return;
 if((tab.np>=10000)||(tab.nt>=9999))
 {
  param.stop_insert=1;
  return;
 }
 p = Delaunay_ChoisitPoint();
 DestCons_DeterminerTAD(tab.triangles->first->t,&Tad,p);
 DestCons_DeterminerTAC(&Tad,&Tac,p);
 if(Tac.first==((void *)0))
 {
  param.stop_insert=1;
  return;
 }
 tmp = Tad.first;
 while(tmp!=((void *)0))
  {
  Global_EffTriangleListe(tmp->t);
  tmp2 = tmp;
  tmp = tmp -> next;
  free(tmp2);
  }
 tmp = Tac.first;
 while(tmp!=((void *)0))
  {
  Global_AddTriangleListe(tmp->t);
  tmp2 = tmp;
  tmp = tmp -> next;
  free(tmp2);
  }
}

canonical_original_code:
void DestCons_InserePoint()
{
 int p;
 struct sStartT Tad; struct sStartT Tac;
 struct sLTriangle *tmp; struct sLTriangle *tmp2;
 Tac.first = ((void *)0);
 Tad.first = ((void *)0);
 if(param.stop_insert)
  return;
 if((tab.np>=10000)||(tab.nt>=9999))
 {
  param.stop_insert=1;
  return;
 }
 p = Delaunay_ChoisitPoint();
 DestCons_DeterminerTAD(tab.triangles->first->t,&Tad,p);
 DestCons_DeterminerTAC(&Tad,&Tac,p);
 if(Tac.first==((void *)0))
 {
  param.stop_insert=1;
  return;
 }
 tmp = Tad.first;
 while(tmp!=((void *)0))
  {
  Global_EffTriangleListe(tmp->t);
  tmp2 = tmp;
  tmp = tmp -> next;
  free(tmp2);
  }
 tmp = Tac.first;
 while(tmp!=((void *)0))
  {
  Global_AddTriangleListe(tmp->t);
  tmp2 = tmp;
  tmp = tmp -> next;
  free(tmp2);
  }
}


decompiled_code:
double __fastcall TerrainImpl_SimpleCalcHeight(int *a1, double a2, double a3)
{
double *v3; // rbx
__int64 v4; // rbp
double v5; // r12
double v6; // xmm3_8
double v7; // xmm0_8
double v9; // [rsp+8h] [rbp-40h]

if ( *a1 <= 0 )
return 0.0;
v3 = (double *)(a1 + 2);
v4 = 0LL;
v9 = 0.0;
do
{
v5 = *(double *)&a1[2 * v4 + 1602];
v6 = v5
* exp(
COERCE_DOUBLE(COERCE_UNSIGNED_INT64(*v3 - a2) ^ LC1) * (*v3 - a2) / v3[400]
- (v3[1] - a3) * (v3[1] - a3) / v3[401]);
v7 = v6;
if ( !a1[v4 + 2002] )
*(_QWORD *)&v7 = *(_QWORD *)&v6 ^ LC1;
v9 = v7 + v9;
++v4;
v3 += 2;
}
while ( *a1 > (int)v4 );
return v9;
}

original_code:
double TerrainImpl_SimpleCalcHeight(STerrainImpl* t,double x, double y)
{
  int i=0;
  double res = 0.0,tmp;
  for(i=0;i<t->nb_centre;i++)
    {
      tmp = t->hauteur[i]*exp( -(t->centre[i][0]-x)*(t->centre[i][0]-x)/t->etal[i][0]-(t->centre[i][1]-y)*(t->centre[i][1]-y)/ t->etal[i][1]);
      res += (t->montagne[i])?tmp:-tmp;
    }
  return res;
}

canonical_original_code:
double TerrainImpl_SimpleCalcHeight(struct sTerrainImpl *t, double x, double y)
{
  int i = 0;
  double res = 0.0; double tmp;
  for(i=0;i<t->nb_centre;i++)
    {
      tmp = t->hauteur[i]*exp( -(t->centre[i][0]-x)*(t->centre[i][0]-x)/t->etal[i][0]-(t->centre[i][1]-y)*(t->centre[i][1]-y)/ t->etal[i][1]);
      res += (t->montagne[i])?tmp:-tmp;
    }
  return res;
}

variable_types: struct sTerrainImpl { int nb_centre; double centre[200][2]; double etal[200][2]; double hauteur[200]; int montagne[200]; int nb_montagnes; } *

variable_types: res double

variable_types: tmp double

return_type: double


decompiled_code:
double __fastcall TerrainImpl_CalcHeight(int *a1, double a2, double a3)
{
double result; // xmm0_8
double v4; // xmm0_8

result = TerrainImpl_SimpleCalcHeight(a1, a2, a3);
if ( *((_DWORD *)&param + 17) )
{
v4 = (result - *((double *)&param + 9)) / (*((double *)&param + 10) - *((double *)&param + 9));
if ( *((_DWORD *)&param + 22) )
v4 = pow(v4, (double)*((int *)&param + 23));
result = v4 * 10.0;
}
return result;
}

canonical_decompiled_code:
double __fastcall func2(int *a1, double a2, double a3)
{
double result; // xmm0_8
double v4; // xmm0_8

result = func0(a1, a2, a3);
if ( *((_DWORD *)&param + 17) )
{
v4 = (result - *((double *)&param + 9)) / (*((double *)&param + 10) - *((double *)&param + 9));
if ( *((_DWORD *)&param + 22) )
v4 = pow(v4, (double)*((int *)&param + 23));
result = v4 * 10.0;
}
return result;
}

original_code:
double TerrainImpl_CalcHeight(STerrainImpl* t,double x, double y)
{
  double res = TerrainImpl_SimpleCalcHeight(t,x,y);
  if(param.norm_v2)
    {
      res = (res-param.min)/(param.max-param.min);
      if(param.flat)
 res = pow(res,param.power);
      res *= 10.0;
      return res;
    }
  return res;
}

canonical_original_code:
double TerrainImpl_CalcHeight(struct sTerrainImpl *t, double x, double y)
{
  double res = TerrainImpl_SimpleCalcHeight(t,x,y);
  if(param.norm_v2)
    {
      res = (res-param.min)/(param.max-param.min);
      if(param.flat)
 res = pow(res,param.power);
      res *= 10.0;
      return res;
    }
  return res;
}

user_defined_types: struct sTerrainImpl { int nb_centre; double centre[200][2]; double etal[200][2]; double hauteur[200]; int montagne[200]; int nb_montagnes; }


canonical_original_code:
int Triangle_CalcCritere(struct sTriangle *t)
{
 double h; double l1; double l2; double l3;
 l1 = sqrt((tab.p[t->p1].x - tab.p[t->p2].x)*(tab.p[t->p1].x - tab.p[t->p2].x)+(tab.p[t->p1].y - tab.p[t->p2].y)*(tab.p[t->p1].y - tab.p[t->p2].y));
 l2 = sqrt((tab.p[t->p1].x - tab.p[t->p3].x)*(tab.p[t->p1].x - tab.p[t->p3].x)+(tab.p[t->p1].y - tab.p[t->p3].y)*(tab.p[t->p1].y - tab.p[t->p3].y));
 l3 = sqrt((tab.p[t->p2].x - tab.p[t->p3].x)*(tab.p[t->p2].x - tab.p[t->p3].x)+(tab.p[t->p2].y - tab.p[t->p3].y)*(tab.p[t->p2].y - tab.p[t->p3].y));
 h = l1/(2.0*t->rayon);
 h *= l2;
 t->critere = h*l3/2.0;
 return 1;
}

variable_types: h double


original_code:
STriangle* Triangle_Cree(int x, int y, int z)
{
 STriangle *t = malloc(sizeof(*t));
 SVecteur v1, v2;
 if(t==((void *)0))
  {
  printf("Malloc failed in cree_t\n");
  return ((void *)0);
  }
 t->p1 = x;
 t->p2 = y;
 t->p3 = z;
 v1.x = tab.p[x].x - tab.p[y].x;
 v1.y = tab.p[x].y - tab.p[y].y;
 v1.z = tab.p[x].z - tab.p[y].z;
 v2.x = tab.p[x].x - tab.p[z].x;
 v2.y = tab.p[x].y - tab.p[z].y;
 v2.z = tab.p[x].z - tab.p[z].z;
 if(!Vecteur_Zup(&v1,&v2))
  {t->p1 = y; t->p2 = x;}
 Triangle_CalcParam(t);
 t->flip_param = 0;
 t->t1 = ((void *)0);
 t->t2 = ((void *)0);
 t->t3 = ((void *)0);
 return t;
}

canonical_original_code:
struct sTriangle *Triangle_Cree(int x, int y, int z)
{
 struct sTriangle *t = malloc(sizeof(*t));
 struct sVecteur v1; struct sVecteur v2;
 if(t==((void *)0))
  {
  printf("Malloc failed in cree_t\n");
  return ((void *)0);
  }
 t->p1 = x;
 t->p2 = y;
 t->p3 = z;
 v1.x = tab.p[x].x - tab.p[y].x;
 v1.y = tab.p[x].y - tab.p[y].y;
 v1.z = tab.p[x].z - tab.p[y].z;
 v2.x = tab.p[x].x - tab.p[z].x;
 v2.y = tab.p[x].y - tab.p[z].y;
 v2.z = tab.p[x].z - tab.p[z].z;
 if(!Vecteur_Zup(&v1,&v2))
  {t->p1 = y; t->p2 = x;}
 Triangle_CalcParam(t);
 t->flip_param = 0;
 t->t1 = ((void *)0);
 t->t2 = ((void *)0);
 t->t3 = ((void *)0);
 return t;
}

variable_types: x int

variable_types: y int

variable_types: z int

return_type: struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint { double x; } centre; double rayon; double critere; } *


decompiled_code:
__int64 __fastcall Terran_AddHaut(int a1, double a2)
{
__int64 result; // rax

result = 2LL * a1;
tab[3 * a1 + 5] = a2 + tab[3 * a1 + 5];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, double a2)
{
__int64 result; // rax

result = 2LL * a1;
tab[3 * a1 + 5] = a2 + tab[3 * a1 + 5];
return result;
}

original_code:
void Terran_AddHaut(int indice,double hauteur)
{
 tab.p[indice].z+=hauteur;
}

canonical_original_code:
void Terran_AddHaut(int indice, double hauteur)
{
 tab.p[indice].z+=hauteur;
}

variable_types: indice int

variable_types: hauteur double


decompiled_code:
__int64 __fastcall Terran_JeuneMont(__int64 a1, __int64 a2, int a3, double a4)
{
__int64 v4; // rbp
double v5; // r13
__int64 v7; // r14
__int64 v8; // r15
__int64 result; // rax
int v10; // edi

if ( !a2 )
return result;
v4 = a1;
v5 = a4;
if ( !a1 )
{
Terran_AddHaut(*(_DWORD *)(a2 + 8), a4);
Terran_AddHaut(*(_DWORD *)(a2 + 12), a4);
result = Terran_AddHaut(*(_DWORD *)(a2 + 16), a4);
v7 = *(_QWORD *)(a2 + 24);
v4 = *(_QWORD *)(a2 + 32);
v8 = *(_QWORD *)(a2 + 40);
goto LABEL_6;
}
v7 = *(_QWORD *)(a2 + 24);
if ( v7 == a1 )
{
v10 = *(_DWORD *)(a2 + 16);
v7 = *(_QWORD *)(a2 + 32);
}
else
{
if ( *(_QWORD *)(a2 + 32) != a1 )
{
v8 = 0LL;
v4 = 0LL;
v7 = 0LL;
goto LABEL_6;
}
v10 = *(_DWORD *)(a2 + 8);
v4 = *(_QWORD *)(a2 + 40);
}
if ( v10 == -1 )
{
v8 = 0LL;
LABEL_6:
if ( a3 <= 1 )
return result;
goto LABEL_15;
}
if ( a3 <= 2 )
{
v5 = a4 * 0.5;
result = Terran_AddHaut(v10, a4 * 0.5);
v8 = 0LL;
goto LABEL_6;
}
result = Terran_AddHaut(v10, a4);
v8 = 0LL;
LABEL_15:
if ( v7 )
result = Terran_JeuneMont(a2, v7, (unsigned int)(a3 - 1), v5);
if ( v4 )
result = Terran_JeuneMont(a2, v4, (unsigned int)(a3 - 1), v5);
if ( v8 )
result = Terran_JeuneMont(a2, v8, (unsigned int)(a3 - 1), v5);
return result;
}

original_code:
void Terran_JeuneMont(STriangle* orig,STriangle* t,double h,int p)
{
 int point=-1;
 STriangle* t1=((void *)0),*t2=((void *)0),*t3=((void *)0);
 if(t!=((void *)0))
 {
  if(orig==((void *)0))
  {
   Terran_AddHaut(t->p1,h);
   Terran_AddHaut(t->p2,h);
   Terran_AddHaut(t->p3,h);
   t1=t->t1;
   t2=t->t2;
   t3=t->t3;
  }
  else if(orig==t->t1)
  {
   point =t->p3;
   t1=t->t2;
   t2=t->t1;
  }
  else if(orig==t->t2)
  {
   point =t->p1;
   t1=t->t1;
   t2=t->t3;
  }
  else if(orig==t->t1)
  {
   point =t->p2;
   t1=t->t3;
   t2=t->t2;
  }
  if (point!=-1)
  {
   if (p<3)
   {
    h/=2;
    Terran_AddHaut(point,h);
   }
   else
   {
    Terran_AddHaut(point,h);
   }
  }
  if (p>1)
  {
   if(t1!=((void *)0)) Terran_JeuneMont(t,t1,h,p-1);
   if(t2!=((void *)0)) Terran_JeuneMont(t,t2,h,p-1);
   if(t3!=((void *)0)) Terran_JeuneMont(t,t3,h,p-1);
  }
 }
}

canonical_original_code:
void Terran_JeuneMont(struct sTriangle *orig, struct sTriangle *t, double h, int p)
{
 int point = -1;
 struct sTriangle *t1 = ((void *)0); struct sTriangle *t2 = ((void *)0); struct sTriangle *t3 = ((void *)0);
 if(t!=((void *)0))
 {
  if(orig==((void *)0))
  {
   Terran_AddHaut(t->p1,h);
   Terran_AddHaut(t->p2,h);
   Terran_AddHaut(t->p3,h);
   t1=t->t1;
   t2=t->t2;
   t3=t->t3;
  }
  else if(orig==t->t1)
  {
   point =t->p3;
   t1=t->t2;
   t2=t->t1;
  }
  else if(orig==t->t2)
  {
   point =t->p1;
   t1=t->t1;
   t2=t->t3;
  }
  else if(orig==t->t1)
  {
   point =t->p2;
   t1=t->t3;
   t2=t->t2;
  }
  if (point!=-1)
  {
   if (p<3)
   {
    h/=2;
    Terran_AddHaut(point,h);
   }
   else
   {
    Terran_AddHaut(point,h);
   }
  }
  if (p>1)
  {
   if(t1!=((void *)0)) Terran_JeuneMont(t,t1,h,p-1);
   if(t2!=((void *)0)) Terran_JeuneMont(t,t2,h,p-1);
   if(t3!=((void *)0)) Terran_JeuneMont(t,t3,h,p-1);
  }
 }
}

variable_types: struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint { double x; } centre; double rayon; double critere; } *

variable_types:
t
struct sTriangle *

variable_types: point int