decompiled_code:
int __fastcall xltek_printHeader(__int64 a1)
{
const char *v1; // rsi
char *v2; // rax
const char *v4; // rsi
time_t timer; // [rsp+8h] [rbp-40h] BYREF
char v6[56]; // [rsp+10h] [rbp-38h] BYREF

timer = *(unsigned int *)(a1 + 20);
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_EEG) )
{
v1 = "Patient Information (.eeg)";
goto LABEL_4;
}
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_ERD) )
{
v1 = "Raw Data (.erd)";
LABEL_4:
printf("File type: %s\n", v1);
printf("file schema: %d\n", *(unsigned __int16 *)(a1 + 16));
printf("base schema: %d\n", *(unsigned __int16 *)(a1 + 18));
v2 = ctime(&timer);
printf("creation time: %s", v2);
printf("patient ID: %d\n", *(unsigned int *)(a1 + 24));
printf("study ID: %d\n", *(unsigned int *)(a1 + 28));
printf("last name: %s\n", (const char *)(a1 + 32));
printf("first name: %s\n", (const char *)(a1 + 112));
printf("middle name: %s\n", (const char *)(a1 + 192));
return printf("id: %s\n", (const char *)(a1 + 272));
}
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_ETC) )
{
v1 = "Table of Contents (.etc)";
goto LABEL_4;
}
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_ENT) )
{
v1 = "Notes (.ent)";
goto LABEL_4;
}
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_SNC) )
{
v1 = "Synchronization File (.snc)";
goto LABEL_4;
}
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_STC) )
{
v1 = "Segments Table of Contents (.stc)";
goto LABEL_4;
}
v4 = "Video Table of Contents (MPEG-1) (.vtc)";
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_VTC_MPEG1) )
goto LABEL_12;
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_VTC_MPEG4) )
{
v4 = "Video Table of Contents (MPEG-4) (.vtc)";
LABEL_12:
printf("File type: %s\n", v4);
return puts(
"This file type does not follow the standard used by other xltek\n"
"files, so the rest of the header that's been read in won't make\n"
"sense.");
}
puts("Unknown file type.");
xltek_uuidToString((unsigned __int8 *)a1, v6);
printf("GUID: %s\n", v6);
return puts("Note: byte order is network byte order (big-endian)");
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
const char *v1; // rsi
char *v2; // rax
const char *v4; // rsi
time_t timer; // [rsp+8h] [rbp-40h] BYREF
char v6[56]; // [rsp+10h] [rbp-38h] BYREF

timer = *(unsigned int *)(a1 + 20);
if ( (unsigned int)func1(a1, (__int64)&UUID_EEG) )
{
v1 = "Patient Information (.eeg)";
goto LABEL_4;
}
if ( (unsigned int)func1(a1, (__int64)&UUID_ERD) )
{
v1 = "Raw Data (.erd)";
LABEL_4:
printf("File type: %s\n", v1);
printf("file schema: %d\n", *(unsigned __int16 *)(a1 + 16));
printf("base schema: %d\n", *(unsigned __int16 *)(a1 + 18));
v2 = ctime(&timer);
printf("creation time: %s", v2);
printf("patient ID: %d\n", *(unsigned int *)(a1 + 24));
printf("study ID: %d\n", *(unsigned int *)(a1 + 28));
printf("last name: %s\n", (const char *)(a1 + 32));
printf("first name: %s\n", (const char *)(a1 + 112));
printf("middle name: %s\n", (const char *)(a1 + 192));
return printf("id: %s\n", (const char *)(a1 + 272));
}
if ( (unsigned int)func1(a1, (__int64)&UUID_ETC) )
{
v1 = "Table of Contents (.etc)";
goto LABEL_4;
}
if ( (unsigned int)func1(a1, (__int64)&UUID_ENT) )
{
v1 = "Notes (.ent)";
goto LABEL_4;
}
if ( (unsigned int)func1(a1, (__int64)&UUID_SNC) )
{
v1 = "Synchronization File (.snc)";
goto LABEL_4;
}
if ( (unsigned int)func1(a1, (__int64)&UUID_STC) )
{
v1 = "Segments Table of Contents (.stc)";
goto LABEL_4;
}
v4 = "Video Table of Contents (MPEG-1) (.vtc)";
if ( (unsigned int)func1(a1, (__int64)&UUID_VTC_MPEG1) )
goto LABEL_12;
if ( (unsigned int)func1(a1, (__int64)&UUID_VTC_MPEG4) )
{
v4 = "Video Table of Contents (MPEG-4) (.vtc)";
LABEL_12:
printf("File type: %s\n", v4);
return puts(
"This file type does not follow the standard used by other xltek\n"
"files, so the rest of the header that's been read in won't make\n"
"sense.");
}
puts("Unknown file type.");
func0((unsigned __int8 *)a1, v6);
printf("GUID: %s\n", v6);
return puts("Note: byte order is network byte order (big-endian)");
}

original_code:
void xltek_printHeader( const xltek_head_t *head )
{
  const char *file_type;
  char uuid_str[37];
  time_t create_time = (time_t) head->m_creation_time;
  if (xltek_uuidEqual( head->m_file_guid, UUID_EEG )) {
    file_type = "Patient Information (.eeg)";
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_ERD )) {
    file_type = "Raw Data (.erd)";
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_ETC )) {
    file_type = "Table of Contents (.etc)";
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_ENT )) {
    file_type = "Notes (.ent)";
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_SNC )) {
    file_type = "Synchronization File (.snc)";
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_STC )) {
    file_type = "Segments Table of Contents (.stc)";
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_VTC_MPEG1 )) {
    file_type = "Video Table of Contents (MPEG-1) (.vtc)";
    printf( "File type: %s\n", file_type );
    printf( "This file type does not follow the standard used by other xltek\n"
            "files, so the rest of the header that's been read in won't make\n"
            "sense.\n" );
    return;
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_VTC_MPEG4 )) {
    file_type = "Video Table of Contents (MPEG-4) (.vtc)";
    printf( "File type: %s\n", file_type );
    printf( "This file type does not follow the standard used by other xltek\n"
            "files, so the rest of the header that's been read in won't make\n"
            "sense.\n" );
    return;
  } else {
    printf( "Unknown file type.\n" );
    xltek_uuidToString( head->m_file_guid, uuid_str );
    printf( "GUID: %s\n", uuid_str );
    printf( "Note: byte order is network byte order (big-endian)\n" );
    return;
  }
  printf("File type:      %s\n", file_type);
  printf("file schema:    %d\n", head->m_file_schema);
  printf("base schema:    %d\n", head->m_base_schema);
  printf("creation time:  %s", ctime(&(create_time)));
  printf("patient ID:     %d\n", head->m_patient_id);
  printf("study ID:       %d\n", head->m_study_id);
  printf("last name:      %s\n", head->m_pat_last_name);
  printf("first name:     %s\n", head->m_pat_first_name);
  printf("middle name:    %s\n", head->m_pat_middle_name);
  printf("id:             %s\n", head->m_pat_id);
}

canonical_original_code:
void xltek_printHeader(struct xltek_head_t *head)
{
  char *file_type;
  char uuid_str[37];
  long create_time = (time_t) head->m_creation_time;
  if (xltek_uuidEqual( head->m_file_guid, UUID_EEG )) {
    file_type = "Patient Information (.eeg)";
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_ERD )) {
    file_type = "Raw Data (.erd)";
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_ETC )) {
    file_type = "Table of Contents (.etc)";
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_ENT )) {
    file_type = "Notes (.ent)";
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_SNC )) {
    file_type = "Synchronization File (.snc)";
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_STC )) {
    file_type = "Segments Table of Contents (.stc)";
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_VTC_MPEG1 )) {
    file_type = "Video Table of Contents (MPEG-1) (.vtc)";
    printf( "File type: %s\n", file_type );
    printf( "This file type does not follow the standard used by other xltek\n"
            "files, so the rest of the header that's been read in won't make\n"
            "sense.\n" );
    return;
  } else if (xltek_uuidEqual( head->m_file_guid, UUID_VTC_MPEG4 )) {
    file_type = "Video Table of Contents (MPEG-4) (.vtc)";
    printf( "File type: %s\n", file_type );
    printf( "This file type does not follow the standard used by other xltek\n"
            "files, so the rest of the header that's been read in won't make\n"
            "sense.\n" );
    return;
  } else {
    printf( "Unknown file type.\n" );
    xltek_uuidToString( head->m_file_guid, uuid_str );
    printf( "GUID: %s\n", uuid_str );
    printf( "Note: byte order is network byte order (big-endian)\n" );
    return;
  }
  printf("File type:      %s\n", file_type);
  printf("file schema:    %d\n", head->m_file_schema);
  printf("base schema:    %d\n", head->m_base_schema);
  printf("creation time:  %s", ctime(&(create_time)));
  printf("patient ID:     %d\n", head->m_patient_id);
  printf("study ID:       %d\n", head->m_study_id);
  printf("last name:      %s\n", head->m_pat_last_name);
  printf("first name:     %s\n", head->m_pat_first_name);
  printf("middle name:    %s\n", head->m_pat_middle_name);
  printf("id:             %s\n", head->m_pat_id);
}

variable_types: struct xltek_head_t { unsigned char m_file_guid[16]; unsigned short m_file_schema; unsigned short m_base_schema; unsigned int m_creation_time; unsigned int m_patient_id; unsigned int m_study_id; char m_pat_last_name[80]; char m_pat_first_name[80]; char m_pat_middle_name[80]; char m_pat_id[80]; } *


repo: brandtd/eyeblink

decompiled_code:
__int64 __fastcall jade_init(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebx
double v3; // xmm0_8
size_t v4; // r12
double v5; // xmm0_8
int v6; // xmm1_4
void *v7; // r14
void *v8; // rax
__int64 v9; // rbp
int v10; // er13
size_t v11; // rbp
void *v12; // rax
size_t v13; // rdi
__int64 *v14; // rbp
void *v15; // rax
void *v16; // rax

v1 = *(_DWORD *)(a1 + 20);
num_var = *(_DWORD *)(a1 + 16);
v2 = num_var;
v3 = (float)v1;
num_elem = num_var * num_var;
v4 = 4LL * (unsigned int)(num_var * num_var);
mat_size = v4;
num_cm = (v2 * (v2 + 1)) >> 1;
*(float *)&scale = 1.0 / (float)v1;
if ( v3 < 0.0 )
v5 = sqrt(v3);
else
v5 = sqrt(v3);
*(float *)&v6 = 1.0 / v5 / 100.0;
threshold = v6;
v7 = malloc(v4 * ((v2 * (v2 + 1)) >> 1));
cm_mat = v7;
v8 = malloc(4LL * v2);
v9 = *(unsigned int *)(a1 + 20);
t = (__int64)v7;
mu_X = v8;
v10 = v9;
dword_CB4 = v2;
dword_CB0 = v2;
dword_CAC = v2;
v11 = 4 * v2 * v9;
dword_CA8 = v2;
v12 = malloc(v11);
v13 = v11;
dword_CC8 = v2;
v14 = &t;
qword_CB8 = (__int64)v12;
dword_CC0 = v2;
dword_CCC = v10;
dword_CC4 = v10;
v15 = malloc(v13);
dword_CE0 = v2;
qword_CD0 = (__int64)v15;
dword_CD8 = v2;
dword_CE4 = v10;
dword_CDC = v10;
do
{
v14 += 3;
v16 = malloc(v4);
*((_DWORD *)v14 + 17) = v2;
v14[6] = (__int64)v16;
*((_DWORD *)v14 + 16) = v2;
*((_DWORD *)v14 + 15) = v2;
*((_DWORD *)v14 + 14) = v2;
}
while ( v14 != &qword_CE8 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebx
double v3; // xmm0_8
size_t v4; // r12
double v5; // xmm0_8
int v6; // xmm1_4
void *v7; // r14
void *v8; // rax
__int64 v9; // rbp
int v10; // er13
size_t v11; // rbp
void *v12; // rax
size_t v13; // rdi
__int64 *v14; // rbp
void *v15; // rax
void *v16; // rax

v1 = *(_DWORD *)(a1 + 20);
num_var = *(_DWORD *)(a1 + 16);
v2 = num_var;
v3 = (float)v1;
num_elem = num_var * num_var;
v4 = 4LL * (unsigned int)(num_var * num_var);
mat_size = v4;
num_cm = (v2 * (v2 + 1)) >> 1;
*(float *)&scale = 1.0 / (float)v1;
if ( v3 < 0.0 )
v5 = sqrt(v3);
else
v5 = sqrt(v3);
*(float *)&v6 = 1.0 / v5 / 100.0;
threshold = v6;
v7 = malloc(v4 * ((v2 * (v2 + 1)) >> 1));
cm_mat = v7;
v8 = malloc(4LL * v2);
v9 = *(unsigned int *)(a1 + 20);
t = (__int64)v7;
mu_X = v8;
v10 = v9;
dword_CB4 = v2;
dword_CB0 = v2;
dword_CAC = v2;
v11 = 4 * v2 * v9;
dword_CA8 = v2;
v12 = malloc(v11);
v13 = v11;
dword_CC8 = v2;
v14 = &t;
qword_CB8 = (__int64)v12;
dword_CC0 = v2;
dword_CCC = v10;
dword_CC4 = v10;
v15 = malloc(v13);
dword_CE0 = v2;
qword_CD0 = (__int64)v15;
dword_CD8 = v2;
dword_CE4 = v10;
dword_CDC = v10;
do
{
v14 += 3;
v16 = malloc(v4);
*((_DWORD *)v14 + 17) = v2;
v14[6] = (__int64)v16;
*((_DWORD *)v14 + 16) = v2;
*((_DWORD *)v14 + 15) = v2;
*((_DWORD *)v14 + 14) = v2;
}
while ( v14 != &qword_CE8 );
return 1LL;
}

original_code:
int jade_init( ICAParams *params )
{
  int i;
  _num_var = params->num_var;
  _num_cm = (_num_var * (_num_var + 1)) / 2;
  _num_elem = _num_var * _num_var;
  _mat_size = sizeof(float) * _num_elem;
  _scale = 1.0 / (float) params->num_obs;
  _threshold = (1.0 / sqrt((float) params->num_obs)) / 100.0;
  _cm_mat = (float*) malloc( _mat_size * _num_cm );
  _mu_X = (float*) malloc( sizeof(float) * _num_var );
  _t[0].elem = _cm_mat;
  _t[0].rows = _t[0].cols = _t[0].ld = _t[0].lag = _num_var;
  for (i = 1; i <= 2; i++) {
    _t[i].elem = (float*) malloc( sizeof(float) *
                                    _num_var * params->num_obs );
    _t[i].rows = _t[i].ld = _num_var;
    _t[i].cols = _t[i].lag = params->num_obs;
  }
  for (i = 3; i <= 5; i++) {
    _t[i].elem = (float*) malloc( _mat_size );
    _t[i].rows = _t[i].cols = _t[i].ld = _t[i].lag = _num_var;
  }
  return 1;
}

canonical_original_code:
int jade_init(struct ICAParams *params)
{
  int i;
  _num_var = params->num_var;
  _num_cm = (_num_var * (_num_var + 1)) / 2;
  _num_elem = _num_var * _num_var;
  _mat_size = sizeof(float) * _num_elem;
  _scale = 1.0 / (float) params->num_obs;
  _threshold = (1.0 / sqrt((float) params->num_obs)) / 100.0;
  _cm_mat = (float *) malloc( _mat_size * _num_cm );
  _mu_X = (float *) malloc( sizeof(float) * _num_var );
  _t[0].elem = _cm_mat;
  _t[0].rows = _t[0].cols = _t[0].ld = _t[0].lag = _num_var;
  for (i = 1; i <= 2; i++) {
    _t[i].elem = (float *) malloc( sizeof(float) *
                                    _num_var * params->num_obs );
    _t[i].rows = _t[i].ld = _num_var;
    _t[i].cols = _t[i].lag = params->num_obs;
  }
  for (i = 3; i <= 5; i++) {
    _t[i].elem = (float *) malloc( _mat_size );
    _t[i].rows = _t[i].cols = _t[i].ld = _t[i].lag = _num_var;
  }
  return 1;
}

variable_types: struct ICAParams { enum ICA_TYPE { ICA_FASTICA=0, ICA_JADE=1 } implem; float epsilon; enum ContrastType { NONLIN_TANH=0, NONLIN_CUBE=1, NONLIN_GAUSS=2 } contrast; unsigned int max_iter; unsigned int num_var; unsigned int num_obs; int gpu_device; int use_gpu; } *

variable_types: i int

return_type: int

user_defined_types: struct ICAParams { enum ICA_TYPE implem; float epsilon; enum ContrastType contrast; unsigned int max_iter; unsigned int num_var; unsigned int num_obs; int gpu_device; int use_gpu; }


decompiled_code:
void jade_shutdown()
{
unsigned __int64 v0; // rbx
void *v1; // rdi

v0 = 0LL;
free(cm_mat);
cm_mat = 0LL;
free(mu_X);
mu_X = 0LL;
do
{
v1 = (void *)qword_CB8[v0 / 2];
v0 += 6LL;
free(v1);
t[v0 / 2] = 0LL;
dword_CAC[v0] = 0;
dword_CA8[v0] = 0;
dword_CB4[v0] = 0;
dword_CB0[v0] = 0;
}
while ( v0 != 30 );
mat_size = 0LL;
num_elem = 0;
num_cm = 0;
num_var = 0;
threshold = 0;
scale = 0;
}

canonical_decompiled_code:
void func1()
{
unsigned __int64 v0; // rbx
void *v1; // rdi

v0 = 0LL;
free(cm_mat);
cm_mat = 0LL;
free(mu_X);
mu_X = 0LL;
do
{
v1 = (void *)qword_CB8[v0 / 2];
v0 += 6LL;
free(v1);
t[v0 / 2] = 0LL;
dword_CAC[v0] = 0;
dword_CA8[v0] = 0;
dword_CB4[v0] = 0;
dword_CB0[v0] = 0;
}
while ( v0 != 30 );
mat_size = 0LL;
num_elem = 0;
num_cm = 0;
num_var = 0;
threshold = 0;
scale = 0;
}

original_code:
void jade_shutdown()
{
  int i;
  free( _cm_mat ); _cm_mat = ((void *)0);
  free( _mu_X ); _mu_X = ((void *)0);
  for (i = 1; i < 6; i++) {
    free( _t[i].elem );
    _t[i].elem = ((void *)0);
    _t[i].ld = _t[i].lag = _t[i].rows = _t[i].cols = 0;
  }
  _num_var = _num_cm = _num_elem = _mat_size = 0;
  _scale = _threshold = 0.0;
}

return_type: void


jade

decompiled_code:
__int64 __fastcall jade(_QWORD *a1, _QWORD *a2, _QWORD *a3, __int64 a4, __int64 a5)
{
int v5; // ecx
_DWORD *v6; // rdi
unsigned int v7; // edx
int v8; // eax
__int64 v9; // r8
unsigned int v10; // ebx
void *v11; // r12
int v12; // er9
__int64 v13; // rsi
__int64 v14; // r8
int v15; // er13
int v16; // ebp
float v17; // xmm1_4
unsigned int v18; // er10
int v19; // er11
int v20; // ecx
unsigned int v21; // eax
float v22; // xmm0_4
__int64 v23; // rdx
unsigned int v24; // er12
__int64 v25; // rsi
int v26; // edi
unsigned int v27; // edx
int v28; // eax
float *v29; // rcx
float v30; // xmm0_4
__int64 v31; // r15
unsigned int v32; // ebp
__int64 v33; // rsi
__int64 v34; // r9
int v35; // er13
int v36; // er14
float v37; // xmm1_4
unsigned int v38; // er10
int v39; // er11
int v40; // ecx
unsigned int v41; // eax
__int64 v42; // rdx
__int64 v43; // rax
float *v44; // rdx
unsigned int v45; // ebx
unsigned int v46; // eax
unsigned int v47; // ebp
unsigned int v48; // er13
int v49; // er12
int v50; // er15
int v51; // er14
float v52; // xmm3_4
int v53; // edx
unsigned int v54; // eax
float v55; // xmm4_4
float v56; // xmm2_4
float v57; // xmm1_4
__int64 v58; // rsi
float v59; // xmm0_4
float v60; // xmm3_4
float v61; // xmm2_4
double v62; // xmm1_8
double v63; // xmm2_8
double v64; // xmm0_8
float v65; // xmm0_4
float v67; // xmm0_4
float v68; // xmm3_4
float v69; // xmm6_4
float v70; // xmm5_4
unsigned int v71; // er8
unsigned int v72; // esi
unsigned int v73; // edi
int v74; // er10
int v75; // er9
char *v76; // rax
float v77; // xmm4_4
float *v78; // rcx
float *v79; // r14
float v80; // xmm10_4
float *v81; // rdx
float v82; // xmm2_4
int v83; // edx
float *v84; // r14
__int64 v85; // rcx
float v86; // xmm1_4
float *v87; // rcx
unsigned int v88; // er14
unsigned int v89; // edx
__int64 v90; // rcx
float *v91; // r15
__int64 v92; // rcx
float v93; // xmm1_4
float *v94; // rcx
unsigned int v95; // edx
unsigned int v96; // er14
float *v97; // r15
__int64 v98; // rcx
float v99; // xmm1_4
float *v100; // rcx
char *v101; // rsi
unsigned int v102; // eax
__int64 v103; // rdx
__int64 v104; // rcx
float *v105; // rdx
float *v106; // rcx
float v107; // xmm1_4
unsigned int v109; // [rsp+0h] [rbp-C8h]
int v110; // [rsp+Ch] [rbp-BCh]
int v111; // [rsp+10h] [rbp-B8h]
unsigned int v112; // [rsp+14h] [rbp-B4h]
int v113; // [rsp+18h] [rbp-B0h]
int v114; // [rsp+1Ch] [rbp-ACh]
unsigned int v115; // [rsp+20h] [rbp-A8h]
int v116; // [rsp+24h] [rbp-A4h]
unsigned int v117; // [rsp+28h] [rbp-A0h]
int v118; // [rsp+2Ch] [rbp-9Ch]
float v119; // [rsp+30h] [rbp-98h]
int v120; // [rsp+34h] [rbp-94h]
int v121; // [rsp+40h] [rbp-88h]
int v122; // [rsp+44h] [rbp-84h]
int v123; // [rsp+48h] [rbp-80h]
int v124; // [rsp+50h] [rbp-78h]
int v125; // [rsp+54h] [rbp-74h]
int v126; // [rsp+58h] [rbp-70h]
unsigned int v127; // [rsp+5Ch] [rbp-6Ch]
double cosx; // [rsp+80h] [rbp-48h] BYREF
double sinx[8]; // [rsp+88h] [rbp-40h] BYREF

memset(s, 0, mat_size);
v5 = num_var;
if ( num_var )
{
v6 = s;
v7 = 0;
v8 = 0;
do
{
v9 = v7;
++v8;
v7 += v5 + 1;
v6[v9] = LC0;
}
while ( v8 != v5 );
}
remmean(mu_X, a3, a5);
v10 = 0;
whiten(qword_CB8, &qword_CE8, &qword_D00, a3, 0LL);
v11 = cm_mat;
v12 = num_var;
t[0] = (__int64)cm_mat;
if ( !num_var )
{
LABEL_28:
v125 = -1;
goto LABEL_30;
}
while ( 1 )
{
v13 = qword_CB8[0];
v14 = qword_CD0;
v15 = *(_DWORD *)(a5 + 12);
if ( v15 )
{
v16 = *(_DWORD *)(a5 + 8);
v17 = *(float *)&scale;
v18 = 0;
v19 = 0;
v20 = v16;
do
{
if ( v16 )
{
v21 = v18;
do
{
v22 = *(float *)(v13 + 4LL * (v10 + v18));
v23 = v21++;
*(float *)(v14 + 4 * v23) = (float)((float)(v22 * v22) * v17) * *(float *)(v13 + 4 * v23);
}
while ( v20 != v21 );
}
++v19;
v18 += v12;
v20 += v12;
}
while ( v19 != v15 );
}
sgemm_(
&not_transpose,
&transpose,
&dword_CD8,
&dword_CC0,
&dword_CDC,
&alpha,
v14,
&dword_CE0,
v13,
&dword_CC8,
&beta,
v11,
dword_CB0);
v12 = num_var;
v24 = num_var;
if ( !num_var )
{
v31 = t[0] + 4LL * (unsigned int)num_elem;
t[0] = v31;
if ( !v10 )
goto LABEL_28;
LABEL_17:
v32 = 0;
do
{
v33 = qword_CB8[0];
v34 = qword_CD0;
v35 = *(_DWORD *)(a5 + 12);
if ( v35 )
{
v36 = *(_DWORD *)(a5 + 8);
v37 = *(float *)&scale;
v38 = 0;
v39 = 0;
v40 = v36;
do
{
if ( v36 )
{
v41 = v38;
do
{
v42 = v41++;
*(float *)(v34 + 4 * v42) = (float)((float)(*(float *)(v33 + 4LL * (v10 + v38))
* *(float *)(v33 + 4LL * (v32 + v38)))
* v37)
* *(float *)(v33 + 4 * v42);
}
while ( v40 != v41 );
}
++v39;
v38 += v24;
v40 += v24;
}
while ( v39 != v35 );
}
sgemm_(
&not_transpose,
&transpose,
&dword_CD8,
&dword_CC0,
&dword_CDC,
&alpha,
v34,
&dword_CE0,
v33,
&dword_CC8,
&beta,
v31,
dword_CB0);
v24 = num_var;
v43 = t[0];
v12 = num_var;
v44 = (float *)(t[0] + 4LL * (v32 + v10 * num_var));
*v44 = *v44 - 1.0;
LODWORD(v44) = v32 * v24;
++v32;
*(float *)(v43 + 4LL * (v10 + (unsigned int)v44)) = *(float *)(v43 + 4LL * (v10 + (unsigned int)v44)) - 1.0;
v31 = v43 + 4LL * (unsigned int)num_elem;
t[0] = v31;
}
while ( v32 < v10 );
goto LABEL_25;
}
v25 = t[0];
v26 = num_var + 1;
v27 = 0;
v28 = 0;
do
{
while ( 1 )
{
v29 = (float *)(v25 + 4LL * v27);
v30 = *v29;
if ( v28 == v10 )
break;
++v28;
v27 += v26;
*v29 = v30 - 1.0;
if ( v28 == v24 )
goto LABEL_16;
}
++v28;
v27 += v26;
*v29 = v30 - 3.0;
}
while ( v28 != v24 );
LABEL_16:
v31 = v25 + 4LL * (unsigned int)num_elem;
t[0] = v31;
if ( v10 )
goto LABEL_17;
LABEL_25:
if ( ++v10 >= v24 )
break;
v11 = (void *)t[0];
}
v125 = v24 - 1;
LABEL_30:
v127 = 0;
while ( 2 )
{
++v127;
if ( !v125 )
break;
v120 = v12;
v45 = v12;
v121 = v12;
v126 = ~v12;
v114 = 0;
v124 = -v12;
v118 = v12 + 1;
v112 = 0;
v113 = 0;
while ( 2 )
{
v115 = v112;
v46 = v112 + 1;
v112 = v46;
if ( v46 >= v45 )
goto LABEL_43;
v109 = v46;
v47 = v45;
v48 = v45;
v111 = 1;
v49 = 1;
v50 = num_cm;
v51 = v118;
v119 = *(float *)&threshold;
v117 = v120 - v45;
v116 = v124;
while ( 2 )
{
if ( v50 )
{
v52 = 0.0;
v53 = 0;
v54 = v120 - v45;
v55 = 0.0;
v56 = 0.0;
do
{
++v53;
v57 = *((float *)cm_mat + v54) - *((float *)cm_mat + v51 + v54);
v58 = v47 + v54;
v54 += num_elem;
v59 = *((float *)cm_mat + v58) + *((float *)cm_mat + v58);
v56 = v56 + (float)(v57 * v57);
v52 = v52 + (float)(v57 * v59);
v55 = v55 + (float)(v59 * v59);
}
while ( v53 != v50 );
v60 = v52 + v52;
v61 = v56 - v55;
v62 = v61;
v63 = (float)((float)(v61 * v61) + (float)(v60 * v60));
if ( v63 >= 0.0 )
{
v110 = v50;
v64 = v60;
goto LABEL_40;
}
sqrt(v63);
v110 = v50;
v64 = v60;
}
else
{
v64 = 0.0;
v110 = 0;
v63 = 0.0;
v62 = 0.0;
LABEL_40:
v63 = sqrt(v63);
}
v65 = atan2(v64, v62 + v63) * 0.5;
if ( COERCE_FLOAT(LODWORD(v65) & LC7) <= v119 )
{
LABEL_42:
++v109;
v48 += v45;
++v49;
v116 -= v45;
v51 += v118;
v47 += v45;
++v111;
if ( v109 >= v45 )
goto LABEL_43;
continue;
}
break;
}
sincos(v65, sinx, &cosx);
v67 = cosx;
v68 = sinx[0];
if ( v110 )
{
v69 = v67 * v67;
v70 = v68 * v68;
v71 = v117 + v47;
v72 = v120 - v45;
v73 = v117 + v51;
v74 = 0;
v122 = v51;
v75 = num_elem;
v123 = v50;
v76 = (char *)cm_mat;
LODWORD(v77) = LODWORD(v68) ^ LC8;
do
{
v78 = (float *)&v76[4 * v71 + 4 * v116 + 4 * v117];
v79 = (float *)&v76[4 * v71];
v80 = *v78;
v81 = (float *)&v76[4 * v71 + 4 * v111];
v82 = *v79 * ((v67 + v67) * v68);
*v79 = (float)((float)(*v81 - *v78) * (float)(v67 * v68))
+ (float)(*v79 * (float)((float)(v67 * v67) - (float)(v68 * v68)));
*v78 = (float)((float)(*v81 * v70) + (float)(v69 * v80)) + v82;
*v81 = (float)((float)(*v81 * v69) + (float)(v80 * v70)) - v82;
v83 = v72 + v114;
if ( v115 )
{
do
{
v84 = (float *)&v76[4 * v83];
v85 = v48 + v83++;
v86 = *v84;
v87 = (float *)&v76[4 * v85];
*v84 = (float)(*v87 * v68) + (float)(*v84 * v67);
*v87 = (float)(v86 * v77) + (float)(*v87 * v67);
}
while ( v72 != v83 );
}
v88 = v116 + v120 + v71;
v89 = v71 + 1;
if ( v112 < v109 )
{
do
{
v90 = v88;
v88 += v45;
v91 = (float *)&v76[4 * v90];
v92 = v89++;
v93 = *v91;
v94 = (float *)&v76[4 * v92];
*v91 = (float)(*v94 * v68) + (float)(*v91 * v67);
*v94 = (float)(v93 * v77) + (float)(*v94 * v67);
}
while ( v73 != v89 );
}
v95 = v45 + v71;
v96 = v109 + 1;
if ( v45 > v109 + 1 )
{
do
{
++v96;
v97 = (float *)&v76[4 * v95];
v98 = v49 + v95;
v95 += v45;
v99 = *v97;
v100 = (float *)&v76[4 * v98];
*v97 = (float)(*v100 * v68) + (float)(*v97 * v67);
*v100 = (float)(v99 * v77) + (float)(*v100 * v67);
}
while ( v96 != v45 );
}
++v74;
v71 += v75;
v73 += v75;
v72 += v75;
}
while ( v74 != v110 );
v51 = v122;
v50 = v123;
}
if ( v45 )
{
v101 = (char *)s;
v102 = v121 - v45;
do
{
v103 = v102;
v104 = v48 + v102++;
v105 = (float *)&v101[4 * v103];
v106 = (float *)&v101[4 * v104];
v107 = (float)(*v105 * v67) + (float)(*v106 * v68);
*v106 = (float)(*v106 * v67) - (float)(*v105 * v68);
*v105 = v107;
}
while ( v121 != v102 );
v113 = 1;
goto LABEL_42;
}
v113 = 1;
LABEL_43:
v121 += v45;
v124 += v126;
--v114;
v120 += v118;
if ( v112 != v125 )
continue;
break;
}
v12 = v45;
if ( v127 <= 0x63 && v113 )
continue;
break;
}
sgemm_(
&transpose,
&not_transpose,
&unk_D24,
&dword_CC4,
&unk_D20,
&alpha,
s,
&unk_D28,
qword_CB8[0],
&dword_CC8,
&beta,
*a3,
a3 + 2);
sgemm_(
&transpose,
&not_transpose,
&unk_D24,
&unk_CF4,
&unk_D20,
&alpha,
s,
&unk_D28,
qword_CE8,
&unk_CF8,
&beta,
*a1,
a1 + 2);
sgemm_(
&not_transpose,
&not_transpose,
&unk_D08,
&unk_D24,
&unk_D0C,
&alpha,
qword_D00,
&unk_D10,
s,
&unk_D28,
&beta,
*a2,
a2 + 2);
sgemv_(&not_transpose, a1 + 1, (char *)a1 + 12, &alpha, *a1, a1 + 2, mu_X, &one, &beta, a4, &one);
return v127;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, _QWORD *a2, _QWORD *a3, __int64 a4, __int64 a5)
{
int v5; // ecx
_DWORD *v6; // rdi
unsigned int v7; // edx
int v8; // eax
__int64 v9; // r8
unsigned int v10; // ebx
void *v11; // r12
int v12; // er9
__int64 v13; // rsi
__int64 v14; // r8
int v15; // er13
int v16; // ebp
float v17; // xmm1_4
unsigned int v18; // er10
int v19; // er11
int v20; // ecx
unsigned int v21; // eax
float v22; // xmm0_4
__int64 v23; // rdx
unsigned int v24; // er12
__int64 v25; // rsi
int v26; // edi
unsigned int v27; // edx
int v28; // eax
float *v29; // rcx
float v30; // xmm0_4
__int64 v31; // r15
unsigned int v32; // ebp
__int64 v33; // rsi
__int64 v34; // r9
int v35; // er13
int v36; // er14
float v37; // xmm1_4
unsigned int v38; // er10
int v39; // er11
int v40; // ecx
unsigned int v41; // eax
__int64 v42; // rdx
__int64 v43; // rax
float *v44; // rdx
unsigned int v45; // ebx
unsigned int v46; // eax
unsigned int v47; // ebp
unsigned int v48; // er13
int v49; // er12
int v50; // er15
int v51; // er14
float v52; // xmm3_4
int v53; // edx
unsigned int v54; // eax
float v55; // xmm4_4
float v56; // xmm2_4
float v57; // xmm1_4
__int64 v58; // rsi
float v59; // xmm0_4
float v60; // xmm3_4
float v61; // xmm2_4
double v62; // xmm1_8
double v63; // xmm2_8
double v64; // xmm0_8
float v65; // xmm0_4
float v67; // xmm0_4
float v68; // xmm3_4
float v69; // xmm6_4
float v70; // xmm5_4
unsigned int v71; // er8
unsigned int v72; // esi
unsigned int v73; // edi
int v74; // er10
int v75; // er9
char *v76; // rax
float v77; // xmm4_4
float *v78; // rcx
float *v79; // r14
float v80; // xmm10_4
float *v81; // rdx
float v82; // xmm2_4
int v83; // edx
float *v84; // r14
__int64 v85; // rcx
float v86; // xmm1_4
float *v87; // rcx
unsigned int v88; // er14
unsigned int v89; // edx
__int64 v90; // rcx
float *v91; // r15
__int64 v92; // rcx
float v93; // xmm1_4
float *v94; // rcx
unsigned int v95; // edx
unsigned int v96; // er14
float *v97; // r15
__int64 v98; // rcx
float v99; // xmm1_4
float *v100; // rcx
char *v101; // rsi
unsigned int v102; // eax
__int64 v103; // rdx
__int64 v104; // rcx
float *v105; // rdx
float *v106; // rcx
float v107; // xmm1_4
unsigned int v109; // [rsp+0h] [rbp-C8h]
int v110; // [rsp+Ch] [rbp-BCh]
int v111; // [rsp+10h] [rbp-B8h]
unsigned int v112; // [rsp+14h] [rbp-B4h]
int v113; // [rsp+18h] [rbp-B0h]
int v114; // [rsp+1Ch] [rbp-ACh]
unsigned int v115; // [rsp+20h] [rbp-A8h]
int v116; // [rsp+24h] [rbp-A4h]
unsigned int v117; // [rsp+28h] [rbp-A0h]
int v118; // [rsp+2Ch] [rbp-9Ch]
float v119; // [rsp+30h] [rbp-98h]
int v120; // [rsp+34h] [rbp-94h]
int v121; // [rsp+40h] [rbp-88h]
int v122; // [rsp+44h] [rbp-84h]
int v123; // [rsp+48h] [rbp-80h]
int v124; // [rsp+50h] [rbp-78h]
int v125; // [rsp+54h] [rbp-74h]
int v126; // [rsp+58h] [rbp-70h]
unsigned int v127; // [rsp+5Ch] [rbp-6Ch]
double cosx; // [rsp+80h] [rbp-48h] BYREF
double sinx[8]; // [rsp+88h] [rbp-40h] BYREF

memset(s, 0, mat_size);
v5 = num_var;
if ( num_var )
{
v6 = s;
v7 = 0;
v8 = 0;
do
{
v9 = v7;
++v8;
v7 += v5 + 1;
v6[v9] = LC0;
}
while ( v8 != v5 );
}
remmean(mu_X, a3, a5);
v10 = 0;
whiten(qword_CB8, &qword_CE8, &qword_D00, a3, 0LL);
v11 = cm_mat;
v12 = num_var;
t[0] = (__int64)cm_mat;
if ( !num_var )
{
LABEL_28:
v125 = -1;
goto LABEL_30;
}
while ( 1 )
{
v13 = qword_CB8[0];
v14 = qword_CD0;
v15 = *(_DWORD *)(a5 + 12);
if ( v15 )
{
v16 = *(_DWORD *)(a5 + 8);
v17 = *(float *)&scale;
v18 = 0;
v19 = 0;
v20 = v16;
do
{
if ( v16 )
{
v21 = v18;
do
{
v22 = *(float *)(v13 + 4LL * (v10 + v18));
v23 = v21++;
*(float *)(v14 + 4 * v23) = (float)((float)(v22 * v22) * v17) * *(float *)(v13 + 4 * v23);
}
while ( v20 != v21 );
}
++v19;
v18 += v12;
v20 += v12;
}
while ( v19 != v15 );
}
sgemm_(
&not_transpose,
&transpose,
&dword_CD8,
&dword_CC0,
&dword_CDC,
&alpha,
v14,
&dword_CE0,
v13,
&dword_CC8,
&beta,
v11,
dword_CB0);
v12 = num_var;
v24 = num_var;
if ( !num_var )
{
v31 = t[0] + 4LL * (unsigned int)num_elem;
t[0] = v31;
if ( !v10 )
goto LABEL_28;
LABEL_17:
v32 = 0;
do
{
v33 = qword_CB8[0];
v34 = qword_CD0;
v35 = *(_DWORD *)(a5 + 12);
if ( v35 )
{
v36 = *(_DWORD *)(a5 + 8);
v37 = *(float *)&scale;
v38 = 0;
v39 = 0;
v40 = v36;
do
{
if ( v36 )
{
v41 = v38;
do
{
v42 = v41++;
*(float *)(v34 + 4 * v42) = (float)((float)(*(float *)(v33 + 4LL * (v10 + v38))
* *(float *)(v33 + 4LL * (v32 + v38)))
* v37)
* *(float *)(v33 + 4 * v42);
}
while ( v40 != v41 );
}
++v39;
v38 += v24;
v40 += v24;
}
while ( v39 != v35 );
}
sgemm_(
&not_transpose,
&transpose,
&dword_CD8,
&dword_CC0,
&dword_CDC,
&alpha,
v34,
&dword_CE0,
v33,
&dword_CC8,
&beta,
v31,
dword_CB0);
v24 = num_var;
v43 = t[0];
v12 = num_var;
v44 = (float *)(t[0] + 4LL * (v32 + v10 * num_var));
*v44 = *v44 - 1.0;
LODWORD(v44) = v32 * v24;
++v32;
*(float *)(v43 + 4LL * (v10 + (unsigned int)v44)) = *(float *)(v43 + 4LL * (v10 + (unsigned int)v44)) - 1.0;
v31 = v43 + 4LL * (unsigned int)num_elem;
t[0] = v31;
}
while ( v32 < v10 );
goto LABEL_25;
}
v25 = t[0];
v26 = num_var + 1;
v27 = 0;
v28 = 0;
do
{
while ( 1 )
{
v29 = (float *)(v25 + 4LL * v27);
v30 = *v29;
if ( v28 == v10 )
break;
++v28;
v27 += v26;
*v29 = v30 - 1.0;
if ( v28 == v24 )
goto LABEL_16;
}
++v28;
v27 += v26;
*v29 = v30 - 3.0;
}
while ( v28 != v24 );
LABEL_16:
v31 = v25 + 4LL * (unsigned int)num_elem;
t[0] = v31;
if ( v10 )
goto LABEL_17;
LABEL_25:
if ( ++v10 >= v24 )
break;
v11 = (void *)t[0];
}
v125 = v24 - 1;
LABEL_30:
v127 = 0;
while ( 2 )
{
++v127;
if ( !v125 )
break;
v120 = v12;
v45 = v12;
v121 = v12;
v126 = ~v12;
v114 = 0;
v124 = -v12;
v118 = v12 + 1;
v112 = 0;
v113 = 0;
while ( 2 )
{
v115 = v112;
v46 = v112 + 1;
v112 = v46;
if ( v46 >= v45 )
goto LABEL_43;
v109 = v46;
v47 = v45;
v48 = v45;
v111 = 1;
v49 = 1;
v50 = num_cm;
v51 = v118;
v119 = *(float *)&threshold;
v117 = v120 - v45;
v116 = v124;
while ( 2 )
{
if ( v50 )
{
v52 = 0.0;
v53 = 0;
v54 = v120 - v45;
v55 = 0.0;
v56 = 0.0;
do
{
++v53;
v57 = *((float *)cm_mat + v54) - *((float *)cm_mat + v51 + v54);
v58 = v47 + v54;
v54 += num_elem;
v59 = *((float *)cm_mat + v58) + *((float *)cm_mat + v58);
v56 = v56 + (float)(v57 * v57);
v52 = v52 + (float)(v57 * v59);
v55 = v55 + (float)(v59 * v59);
}
while ( v53 != v50 );
v60 = v52 + v52;
v61 = v56 - v55;
v62 = v61;
v63 = (float)((float)(v61 * v61) + (float)(v60 * v60));
if ( v63 >= 0.0 )
{
v110 = v50;
v64 = v60;
goto LABEL_40;
}
sqrt(v63);
v110 = v50;
v64 = v60;
}
else
{
v64 = 0.0;
v110 = 0;
v63 = 0.0;
v62 = 0.0;
LABEL_40:
v63 = sqrt(v63);
}
v65 = atan2(v64, v62 + v63) * 0.5;
if ( COERCE_FLOAT(LODWORD(v65) & LC7) <= v119 )
{
LABEL_42:
++v109;
v48 += v45;
++v49;
v116 -= v45;
v51 += v118;
v47 += v45;
++v111;
if ( v109 >= v45 )
goto LABEL_43;
continue;
}
break;
}
sincos(v65, sinx, &cosx);
v67 = cosx;
v68 = sinx[0];
if ( v110 )
{
v69 = v67 * v67;
v70 = v68 * v68;
v71 = v117 + v47;
v72 = v120 - v45;
v73 = v117 + v51;
v74 = 0;
v122 = v51;
v75 = num_elem;
v123 = v50;
v76 = (char *)cm_mat;
LODWORD(v77) = LODWORD(v68) ^ LC8;
do
{
v78 = (float *)&v76[4 * v71 + 4 * v116 + 4 * v117];
v79 = (float *)&v76[4 * v71];
v80 = *v78;
v81 = (float *)&v76[4 * v71 + 4 * v111];
v82 = *v79 * ((v67 + v67) * v68);
*v79 = (float)((float)(*v81 - *v78) * (float)(v67 * v68))
+ (float)(*v79 * (float)((float)(v67 * v67) - (float)(v68 * v68)));
*v78 = (float)((float)(*v81 * v70) + (float)(v69 * v80)) + v82;
*v81 = (float)((float)(*v81 * v69) + (float)(v80 * v70)) - v82;
v83 = v72 + v114;
if ( v115 )
{
do
{
v84 = (float *)&v76[4 * v83];
v85 = v48 + v83++;
v86 = *v84;
v87 = (float *)&v76[4 * v85];
*v84 = (float)(*v87 * v68) + (float)(*v84 * v67);
*v87 = (float)(v86 * v77) + (float)(*v87 * v67);
}
while ( v72 != v83 );
}
v88 = v116 + v120 + v71;
v89 = v71 + 1;
if ( v112 < v109 )
{
do
{
v90 = v88;
v88 += v45;
v91 = (float *)&v76[4 * v90];
v92 = v89++;
v93 = *v91;
v94 = (float *)&v76[4 * v92];
*v91 = (float)(*v94 * v68) + (float)(*v91 * v67);
*v94 = (float)(v93 * v77) + (float)(*v94 * v67);
}
while ( v73 != v89 );
}
v95 = v45 + v71;
v96 = v109 + 1;
if ( v45 > v109 + 1 )
{
do
{
++v96;
v97 = (float *)&v76[4 * v95];
v98 = v49 + v95;
v95 += v45;
v99 = *v97;
v100 = (float *)&v76[4 * v98];
*v97 = (float)(*v100 * v68) + (float)(*v97 * v67);
*v100 = (float)(v99 * v77) + (float)(*v100 * v67);
}
while ( v96 != v45 );
}
++v74;
v71 += v75;
v73 += v75;
v72 += v75;
}
while ( v74 != v110 );
v51 = v122;
v50 = v123;
}
if ( v45 )
{
v101 = (char *)s;
v102 = v121 - v45;
do
{
v103 = v102;
v104 = v48 + v102++;
v105 = (float *)&v101[4 * v103];
v106 = (float *)&v101[4 * v104];
v107 = (float)(*v105 * v67) + (float)(*v106 * v68);
*v106 = (float)(*v106 * v67) - (float)(*v105 * v68);
*v105 = v107;
}
while ( v121 != v102 );
v113 = 1;
goto LABEL_42;
}
v113 = 1;
LABEL_43:
v121 += v45;
v124 += v126;
--v114;
v120 += v118;
if ( v112 != v125 )
continue;
break;
}
v12 = v45;
if ( v127 <= 0x63 && v113 )
continue;
break;
}
sgemm_(
&transpose,
&not_transpose,
&unk_D24,
&dword_CC4,
&unk_D20,
&alpha,
s,
&unk_D28,
qword_CB8[0],
&dword_CC8,
&beta,
*a3,
a3 + 2);
sgemm_(
&transpose,
&not_transpose,
&unk_D24,
&unk_CF4,
&unk_D20,
&alpha,
s,
&unk_D28,
qword_CE8,
&unk_CF8,
&beta,
*a1,
a1 + 2);
sgemm_(
&not_transpose,
&not_transpose,
&unk_D08,
&unk_D24,
&unk_D0C,
&alpha,
qword_D00,
&unk_D10,
s,
&unk_D28,
&beta,
*a2,
a2 + 2);
sgemv_(&not_transpose, a1 + 1, (char *)a1 + 12, &alpha, *a1, a1 + 2, mu_X, &one, &beta, a4, &one);
return v127;
}

original_code:
unsigned int jade( Matrix *W, Matrix *A, Matrix *S, float *mu_S,
                   Matrix const *X )
{
  unsigned int i, var_i, var_j, var, var2, row, col, sweeps, modified;
  unsigned int p_i, q_i, pp_i, qq_i, pq_i, p, q, cm;
  float on_diag, off_diag, GG_x, GG_z, GG_y, theta, cosine, sine, tmp1, tmp2;
  float cos_sqr, sin_sqr;
  memset( _t[5].elem, 0, _mat_size );
  for (i = 0; i < _num_var; i++) {
    _t[5].elem[i * _num_var + i] = 1.0;
  }
  remmean( _mu_X, S, X );
  whiten( &(_t[1]), &(_t[3]), &(_t[4]), S, 0 );
  _t[0].elem = _cm_mat;
  for (var = 0; var < _num_var; var++) {
    for (col = 0; col < X->cols; col++) {
      for (row = 0; row < X->rows; row++) {
        i = col * _num_var + row;
        var_i = col * _num_var + var;
        _t[2].elem[i] = (_scale *
                            (_t[1].elem[var_i] *
                             _t[1].elem[var_i])) *
                           _t[1].elem[i];
      }
    }
    sgemm_( &_not_transpose, &_transpose, &((_t[2]).rows), &((_t[1]).rows), &((_t[2]).cols), &_alpha, (_t[2]).elem, &((_t[2]).ld), (_t[1]).elem, &((_t[1]).ld), &_beta, (_t[0]).elem, &((_t[0]).ld) );
    for (i = 0; i < _num_var; i++) {
      var_i = i * _num_var + i;
      if (i == var) {
        _t[0].elem[var_i] -= 3.0;
      } else {
        _t[0].elem[var_i] -= 1.0;
      }
    }
    _t[0].elem += _num_elem;
    for (var2 = 0; var2 < var; var2++) {
      for (col = 0; col < X->cols; col++) {
        for (row = 0; row < X->rows; row++) {
          i = col * _num_var + row;
          var_i = col * _num_var + var;
          var_j = col * _num_var + var2;
          _t[2].elem[i] = (_scale *
                              (_t[1].elem[var_i] *
                               _t[1].elem[var_j])) *
                             _t[1].elem[i];
        }
      }
      sgemm_( &_not_transpose, &_transpose, &((_t[2]).rows), &((_t[1]).rows), &((_t[2]).cols), &_alpha, (_t[2]).elem, &((_t[2]).ld), (_t[1]).elem, &((_t[1]).ld), &_beta, (_t[0]).elem, &((_t[0]).ld) );
      _t[0].elem[ var * _num_var + var2 ] -= 1.0;
      _t[0].elem[ var2 * _num_var + var ] -= 1.0;
      _t[0].elem += _num_elem;
    }
  }
  sweeps = 0;
  modified = 1;
  while (sweeps < 100 && modified) {
    modified = 0;
    sweeps++;
    for (p = 0; p < _num_var - 1; p++) {
      for (q = p + 1; q < _num_var; q++) {
        GG_x = 0.0f;
        GG_y = 0.0f;
        GG_z = 0.0f;
        for (cm = 0; cm < _num_cm; cm++) {
          pp_i = cm * _num_elem + p * _num_var + p;
          qq_i = cm * _num_elem + q * _num_var + q;
          pq_i = cm * _num_elem + q * _num_var + p;
          on_diag = _cm_mat[pp_i] - _cm_mat[qq_i];
          off_diag = _cm_mat[pq_i] * 2.0;
          GG_x += on_diag * on_diag;
          GG_y += on_diag * off_diag;
          GG_z += off_diag * off_diag;
        }
        on_diag = GG_x - GG_z;
        off_diag = GG_y * 2.0;
        theta = 0.5 * atan2( off_diag, on_diag +
                             sqrt(on_diag * on_diag + off_diag * off_diag));
        if (fabs( theta ) > _threshold) {
          modified = 1;
          cosine = cos( theta );
          sine = sin( theta );
          for (i = 0; i < _num_cm; i++) {
            pp_i = p * _num_var + p + _num_elem * i;
            qq_i = q * _num_var + q + _num_elem * i;
            pq_i = q * _num_var + p + _num_elem * i;
            cos_sqr = cosine * cosine;
            sin_sqr = sine * sine;
            tmp1 = _cm_mat[pp_i];
            tmp2 = 2.0 * cosine * sine * _cm_mat[pq_i];
            _cm_mat[pq_i] = (cos_sqr - sin_sqr) * _cm_mat[pq_i] +
                           cosine * sine * (_cm_mat[qq_i] - _cm_mat[pp_i]);
            _cm_mat[pp_i] = cos_sqr * tmp1 + sin_sqr * _cm_mat[qq_i] + tmp2;
            _cm_mat[qq_i] = sin_sqr * tmp1 + cos_sqr * _cm_mat[qq_i] - tmp2;
            for (row = 0; row < p; row++) {
              p_i = p * _num_var + row + _num_elem * i;
              q_i = q * _num_var + row + _num_elem * i;
              tmp1 = cosine * _cm_mat[p_i];
              tmp2 = -sine * _cm_mat[p_i];
              _cm_mat[p_i] = tmp1 + sine * _cm_mat[q_i];
              _cm_mat[q_i] = tmp2 + cosine * _cm_mat[q_i];
            }
            for (col = p + 1; col < q; col++) {
              p_i = col * _num_var + p + _num_elem * i;
              q_i = q * _num_var + col + _num_elem * i;
              tmp1 = cosine * _cm_mat[p_i];
              tmp2 = -sine * _cm_mat[p_i];
              _cm_mat[p_i] = tmp1 + sine * _cm_mat[q_i];
              _cm_mat[q_i] = tmp2 + cosine * _cm_mat[q_i];
            }
            for (col = q + 1; col < _num_var; col++) {
              p_i = col * _num_var + p + _num_elem * i;
              q_i = col * _num_var + q + _num_elem * i;
              tmp1 = cosine * _cm_mat[p_i];
              tmp2 = -sine * _cm_mat[p_i];
              _cm_mat[p_i] = tmp1 + sine * _cm_mat[q_i];
              _cm_mat[q_i] = tmp2 + cosine * _cm_mat[q_i];
            }
          }
          for (row = 0; row < _num_var; row++) {
            p_i = p * _num_var + row;
            q_i = q * _num_var + row;
            tmp1 = cosine * _t[5].elem[p_i] + sine * _t[5].elem[q_i];
            _t[5].elem[q_i] = cosine * _t[5].elem[q_i] - sine * _t[5].elem[p_i];
            _t[5].elem[p_i] = tmp1;
          }
        }
      }
    }
  }
  sgemm_( &_transpose, &_not_transpose, &((_t[5]).cols), &((_t[1]).cols), &((_t[5]).rows), &_alpha, (_t[5]).elem, &((_t[5]).ld), (_t[1]).elem, &((_t[1]).ld), &_beta, (*S).elem, &((*S).ld) );
  sgemm_( &_transpose, &_not_transpose, &((_t[5]).cols), &((_t[3]).cols), &((_t[5]).rows), &_alpha, (_t[5]).elem, &((_t[5]).ld), (_t[3]).elem, &((_t[3]).ld), &_beta, (*W).elem, &((*W).ld) );
  sgemm_( &_not_transpose, &_not_transpose, &((_t[4]).rows), &((_t[5]).cols), &((_t[4]).cols), &_alpha, (_t[4]).elem, &((_t[4]).ld), (_t[5]).elem, &((_t[5]).ld), &_beta, (*A).elem, &((*A).ld) );
  sgemv_( &_not_transpose, &((*W).rows), &((*W).cols), &_alpha, (*W).elem, &((*W).ld), _mu_X, &_one, &_beta, mu_S, &_one );
  return sweeps;
}

canonical_original_code:
unsigned int jade(struct Matrix *W, struct Matrix *A, struct Matrix *S, float *mu_S, struct Matrix *X)
{
  unsigned int i; unsigned int var_i; unsigned int var_j; unsigned int var; unsigned int var2; unsigned int row; unsigned int col; unsigned int sweeps; unsigned int modified;
  unsigned int p_i; unsigned int q_i; unsigned int pp_i; unsigned int qq_i; unsigned int pq_i; unsigned int p; unsigned int q; unsigned int cm;
  float on_diag; float off_diag; float GG_x; float GG_z; float GG_y; float theta; float cosine; float sine; float tmp1; float tmp2;
  float cos_sqr; float sin_sqr;
  memset( _t[5].elem, 0, _mat_size );
  for (i = 0; i < _num_var; i++) {
    _t[5].elem[i * _num_var + i] = 1.0;
  }
  remmean( _mu_X, S, X );
  whiten( &(_t[1]), &(_t[3]), &(_t[4]), S, 0 );
  _t[0].elem = _cm_mat;
  for (var = 0; var < _num_var; var++) {
    for (col = 0; col < X->cols; col++) {
      for (row = 0; row < X->rows; row++) {
        i = col * _num_var + row;
        var_i = col * _num_var + var;
        _t[2].elem[i] = (_scale *
                            (_t[1].elem[var_i] *
                             _t[1].elem[var_i])) *
                           _t[1].elem[i];
      }
    }
    sgemm_( &_not_transpose, &_transpose, &((_t[2]).rows), &((_t[1]).rows), &((_t[2]).cols), &_alpha, (_t[2]).elem, &((_t[2]).ld), (_t[1]).elem, &((_t[1]).ld), &_beta, (_t[0]).elem, &((_t[0]).ld) );
    for (i = 0; i < _num_var; i++) {
      var_i = i * _num_var + i;
      if (i == var) {
        _t[0].elem[var_i] -= 3.0;
      } else {
        _t[0].elem[var_i] -= 1.0;
      }
    }
    _t[0].elem += _num_elem;
    for (var2 = 0; var2 < var; var2++) {
      for (col = 0; col < X->cols; col++) {
        for (row = 0; row < X->rows; row++) {
          i = col * _num_var + row;
          var_i = col * _num_var + var;
          var_j = col * _num_var + var2;
          _t[2].elem[i] = (_scale *
                              (_t[1].elem[var_i] *
                               _t[1].elem[var_j])) *
                             _t[1].elem[i];
        }
      }
      sgemm_( &_not_transpose, &_transpose, &((_t[2]).rows), &((_t[1]).rows), &((_t[2]).cols), &_alpha, (_t[2]).elem, &((_t[2]).ld), (_t[1]).elem, &((_t[1]).ld), &_beta, (_t[0]).elem, &((_t[0]).ld) );
      _t[0].elem[ var * _num_var + var2 ] -= 1.0;
      _t[0].elem[ var2 * _num_var + var ] -= 1.0;
      _t[0].elem += _num_elem;
    }
  }
  sweeps = 0;
  modified = 1;
  while (sweeps < 100 && modified) {
    modified = 0;
    sweeps++;
    for (p = 0; p < _num_var - 1; p++) {
      for (q = p + 1; q < _num_var; q++) {
        GG_x = 0.0f;
        GG_y = 0.0f;
        GG_z = 0.0f;
        for (cm = 0; cm < _num_cm; cm++) {
          pp_i = cm * _num_elem + p * _num_var + p;
          qq_i = cm * _num_elem + q * _num_var + q;
          pq_i = cm * _num_elem + q * _num_var + p;
          on_diag = _cm_mat[pp_i] - _cm_mat[qq_i];
          off_diag = _cm_mat[pq_i] * 2.0;
          GG_x += on_diag * on_diag;
          GG_y += on_diag * off_diag;
          GG_z += off_diag * off_diag;
        }
        on_diag = GG_x - GG_z;
        off_diag = GG_y * 2.0;
        theta = 0.5 * atan2( off_diag, on_diag +
                             sqrt(on_diag * on_diag + off_diag * off_diag));
        if (fabs( theta ) > _threshold) {
          modified = 1;
          cosine = cos( theta );
          sine = sin( theta );
          for (i = 0; i < _num_cm; i++) {
            pp_i = p * _num_var + p + _num_elem * i;
            qq_i = q * _num_var + q + _num_elem * i;
            pq_i = q * _num_var + p + _num_elem * i;
            cos_sqr = cosine * cosine;
            sin_sqr = sine * sine;
            tmp1 = _cm_mat[pp_i];
            tmp2 = 2.0 * cosine * sine * _cm_mat[pq_i];
            _cm_mat[pq_i] = (cos_sqr - sin_sqr) * _cm_mat[pq_i] +
                           cosine * sine * (_cm_mat[qq_i] - _cm_mat[pp_i]);
            _cm_mat[pp_i] = cos_sqr * tmp1 + sin_sqr * _cm_mat[qq_i] + tmp2;
            _cm_mat[qq_i] = sin_sqr * tmp1 + cos_sqr * _cm_mat[qq_i] - tmp2;
            for (row = 0; row < p; row++) {
              p_i = p * _num_var + row + _num_elem * i;
              q_i = q * _num_var + row + _num_elem * i;
              tmp1 = cosine * _cm_mat[p_i];
              tmp2 = -sine * _cm_mat[p_i];
              _cm_mat[p_i] = tmp1 + sine * _cm_mat[q_i];
              _cm_mat[q_i] = tmp2 + cosine * _cm_mat[q_i];
            }
            for (col = p + 1; col < q; col++) {
              p_i = col * _num_var + p + _num_elem * i;
              q_i = q * _num_var + col + _num_elem * i;
              tmp1 = cosine * _cm_mat[p_i];
              tmp2 = -sine * _cm_mat[p_i];
              _cm_mat[p_i] = tmp1 + sine * _cm_mat[q_i];
              _cm_mat[q_i] = tmp2 + cosine * _cm_mat[q_i];
            }
            for (col = q + 1; col < _num_var; col++) {
              p_i = col * _num_var + p + _num_elem * i;
              q_i = col * _num_var + q + _num_elem * i;
              tmp1 = cosine * _cm_mat[p_i];
              tmp2 = -sine * _cm_mat[p_i];
              _cm_mat[p_i] = tmp1 + sine * _cm_mat[q_i];
              _cm_mat[q_i] = tmp2 + cosine * _cm_mat[q_i];
            }
          }
          for (row = 0; row < _num_var; row++) {
            p_i = p * _num_var + row;
            q_i = q * _num_var + row;
            tmp1 = cosine * _t[5].elem[p_i] + sine * _t[5].elem[q_i];
            _t[5].elem[q_i] = cosine * _t[5].elem[q_i] - sine * _t[5].elem[p_i];
            _t[5].elem[p_i] = tmp1;
          }
        }
      }
    }
  }
  sgemm_( &_transpose, &_not_transpose, &((_t[5]).cols), &((_t[1]).cols), &((_t[5]).rows), &_alpha, (_t[5]).elem, &((_t[5]).ld), (_t[1]).elem, &((_t[1]).ld), &_beta, (*S).elem, &((*S).ld) );
  sgemm_( &_transpose, &_not_transpose, &((_t[5]).cols), &((_t[3]).cols), &((_t[5]).rows), &_alpha, (_t[5]).elem, &((_t[5]).ld), (_t[3]).elem, &((_t[3]).ld), &_beta, (*W).elem, &((*W).ld) );
  sgemm_( &_not_transpose, &_not_transpose, &((_t[4]).rows), &((_t[5]).cols), &((_t[4]).cols), &_alpha, (_t[4]).elem, &((_t[4]).ld), (_t[5]).elem, &((_t[5]).ld), &_beta, (*A).elem, &((*A).ld) );
  sgemv_( &_not_transpose, &((*W).rows), &((*W).cols), &_alpha, (*W).elem, &((*W).ld), _mu_X, &_one, &_beta, mu_S, &_one );
  return sweeps;
}

variable_types: struct Matrix { float *elem; int rows; int cols; int ld; int lag; } *

variable_types:
A
struct Matrix *

variable_types:
S
struct Matrix *

variable_types:
X
struct Matrix *

variable_types:
i
unsigned int

variable_types:
var
unsigned int

variable_types:
row
unsigned int

variable_types:
col
unsigned int

variable_types:
sweeps
unsigned int

variable_types:
modified
unsigned int

variable_types:
p
unsigned int

variable_types:
q
unsigned int

variable_types:
cm
unsigned int

variable_types: theta float

variable_types: cosine float

variable_types: sine float

return_type: unsigned int


decompiled_code:
__int64 __fastcall fastica_init(_DWORD *a1)
{
int v1; // xmm0_4
int v2; // eax
bool v3; // zf
void *v4; // rax
__int64 v5; // r12
int v6; // ebp
void *v7; // rax
__int64 v8; // rdi
void *v9; // rax
size_t v10; // r12
__int64 i; // rbx
void *v12; // rax

v1 = a1[1];
max_iter = a1[3];
v2 = a1[2];
epsilon = v1;
if ( v2 == 1 )
{
contrast = (__int64)&negent_cube;
}
else
{
v3 = v2 == 2;
v4 = &negent_gauss;
if ( !v3 )
v4 = &negent_tanh;
contrast = (__int64)v4;
}
v5 = (unsigned int)a1[4];
v6 = a1[4];
v7 = malloc(4 * v5);
v8 = (unsigned int)a1[5];
eig_vals = v7;
v9 = malloc(4 * v5 * v8);
LODWORD(qword_920) = v5;
LODWORD(qword_918) = v5;
white_Z = v9;
HIDWORD(qword_920) = v8;
HIDWORD(qword_918) = v8;
v10 = 4 * v5 * v5;
for ( i = 0LL; i != 15; *(_DWORD *)((char *)&tW + i * 8 + 8) = v6 )
{
i += 3LL;
v12 = malloc(v10);
HIDWORD(qword_890[i]) = v6;
*(void **)((char *)&tW + i * 8) = v12;
LODWORD(qword_890[i]) = v6;
*(_DWORD *)((char *)&tW + i * 8 + 12) = v6;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
int v1; // xmm0_4
int v2; // eax
bool v3; // zf
void *v4; // rax
__int64 v5; // r12
int v6; // ebp
void *v7; // rax
__int64 v8; // rdi
void *v9; // rax
size_t v10; // r12
__int64 i; // rbx
void *v12; // rax

v1 = a1[1];
max_iter = a1[3];
v2 = a1[2];
epsilon = v1;
if ( v2 == 1 )
{
contrast = (__int64)&negent_cube;
}
else
{
v3 = v2 == 2;
v4 = &negent_gauss;
if ( !v3 )
v4 = &negent_tanh;
contrast = (__int64)v4;
}
v5 = (unsigned int)a1[4];
v6 = a1[4];
v7 = malloc(4 * v5);
v8 = (unsigned int)a1[5];
eig_vals = v7;
v9 = malloc(4 * v5 * v8);
LODWORD(qword_920) = v5;
LODWORD(qword_918) = v5;
white_Z = v9;
HIDWORD(qword_920) = v8;
HIDWORD(qword_918) = v8;
v10 = 4 * v5 * v5;
for ( i = 0LL; i != 15; *(_DWORD *)((char *)&tW + i * 8 + 8) = v6 )
{
i += 3LL;
v12 = malloc(v10);
HIDWORD(qword_890[i]) = v6;
*(void **)((char *)&tW + i * 8) = v12;
LODWORD(qword_890[i]) = v6;
*(_DWORD *)((char *)&tW + i * 8 + 12) = v6;
}
return 1LL;
}

original_code:
int fastica_init( ICAParams *params )
{
  int i;
  _epsilon = params->epsilon;
  _max_iter = params->max_iter;
  switch (params->contrast) {
    case NONLIN_CUBE:
      _contrast = negent_cube;
      break;
    case NONLIN_GAUSS:
      _contrast = negent_gauss;
      break;
    case NONLIN_TANH:
    default:
      _contrast = negent_tanh;
      break;
  }
  _eig_vals = (float*) malloc( sizeof(float) * params->num_var );
  _white_Z.elem = (float*) malloc( sizeof(float) * params->num_var *
                                     params->num_obs );
  _white_Z.cols = _white_Z.lag = params->num_obs;
  _white_Z.rows = _white_Z.ld = params->num_var;
  for (i = 1; i < sizeof(_tW) / sizeof(Matrix); i++) {
    _tW[i].elem = (float*) malloc( sizeof(float) *
                                     params->num_var * params->num_var );
    _tW[i].rows = _tW[i].cols = _tW[i].ld = _tW[i].lag = params->num_var;
  }
  return 1;
}

canonical_original_code:
int fastica_init(struct ICAParams *params)
{
  int i;
  _epsilon = params->epsilon;
  _max_iter = params->max_iter;
  switch (params->contrast) {
    case NONLIN_CUBE:
      _contrast = negent_cube;
      break;
    case NONLIN_GAUSS:
      _contrast = negent_gauss;
      break;
    case NONLIN_TANH:
    default:
      _contrast = negent_tanh;
      break;
  }
  _eig_vals = (float *) malloc( sizeof(float) * params->num_var );
  _white_Z.elem = (float *) malloc( sizeof(float) * params->num_var *
                                     params->num_obs );
  _white_Z.cols = _white_Z.lag = params->num_obs;
  _white_Z.rows = _white_Z.ld = params->num_var;
  for (i = 1; i < sizeof(_tW) / sizeof(Matrix); i++) {
    _tW[i].elem = (float *) malloc( sizeof(float) *
                                     params->num_var * params->num_var );
    _tW[i].rows = _tW[i].cols = _tW[i].ld = _tW[i].lag = params->num_var;
  }
  return 1;
}

variable_types: struct ICAParams { enum ICA_TYPE { ICA_FASTICA=0, ICA_JADE=1 } implem; float epsilon; enum ContrastType { NONLIN_TANH=0, NONLIN_CUBE=1, NONLIN_GAUSS=2 } contrast; unsigned int max_iter; unsigned int num_var; unsigned int num_obs; int gpu_device; int use_gpu; } *

variable_types: i int


decompiled_code:
void fastica_shutdown()
{
__int64 v0; // rbx
void *v1; // rdi

v0 = 0LL;
free(eig_vals);
eig_vals = 0LL;
free(white_Z);
white_Z = 0LL;
qword_918 = 0LL;
qword_920 = 0LL;
do
{
v1 = *(void **)((char *)&dest + v0 * 8);
v0 += 3LL;
free(v1);
*(void **)((char *)&tW + v0 * 8) = 0LL;
HIDWORD(qword_890[v0]) = 0;
LODWORD(qword_890[v0]) = 0;
*(_DWORD *)((char *)&tW + v0 * 8 + 12) = 0;
*(_DWORD *)((char *)&tW + v0 * 8 + 8) = 0;
}
while ( v0 != 15 );
contrast = 0LL;
epsilon = 0;
max_iter = 0;
}

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

v0 = 0LL;
free(eig_vals);
eig_vals = 0LL;
free(white_Z);
white_Z = 0LL;
qword_918 = 0LL;
qword_920 = 0LL;
do
{
v1 = *(void **)((char *)&dest + v0 * 8);
v0 += 3LL;
free(v1);
*(void **)((char *)&tW + v0 * 8) = 0LL;
HIDWORD(qword_890[v0]) = 0;
LODWORD(qword_890[v0]) = 0;
*(_DWORD *)((char *)&tW + v0 * 8 + 12) = 0;
*(_DWORD *)((char *)&tW + v0 * 8 + 8) = 0;
}
while ( v0 != 15 );
contrast = 0LL;
epsilon = 0;
max_iter = 0;
}

original_code:
void fastica_shutdown()
{
  int i;
  free( _eig_vals );
  _eig_vals = ((void *)0);
  free( _white_Z.elem );
  _white_Z.elem = ((void *)0);
  _white_Z.cols = _white_Z.lag = _white_Z.rows = _white_Z.ld = 0;
  for (i = 1; i < sizeof(_tW) / sizeof(Matrix); i++) {
    free( _tW[i].elem );
    _tW[i].elem = ((void *)0);
    _tW[i].rows = _tW[i].cols = _tW[i].ld = _tW[i].lag = 0;
  }
  _contrast = ((void *)0);
  _epsilon = 0.0;
  _max_iter = 0;
}


fastica

original_code:
unsigned int fastica( Matrix *W, Matrix *A, Matrix *S, float *mu_S,
                      Matrix const *X )
{
  int num_iter, prev_i, new_i, row, col, i;
  float min;
  _tW[0] = *W;
  remmean( mu_S, S, X );
  whiten( &_white_Z, &_tW[2], &_tW[3], S, 0 );
  for (i = 0; i < _tW[0].rows * _tW[0].cols; i++) {
    _tW[0].elem[i] = 0.0;
  }
  for (i = 0; i < _tW[0].rows; i++) {
    _tW[0].elem[i + i*_tW[0].rows] = 1.0;
  }
  num_iter = 0;
  do {
    new_i = (num_iter + 1) & 0x01;
    prev_i = (num_iter ) & 0x01;
    num_iter++;
    _contrast( &_tW[4], &_tW[prev_i], &_white_Z );
    sgemm_( &_not_transpose, &_transpose, &((_tW[4]).rows), &((_tW[4]).rows), &((_tW[4]).cols), &_alpha, (_tW[4]).elem, &((_tW[4]).ld), (_tW[4]).elem, &((_tW[4]).ld), &_beta, (_tW[new_i]).elem, &((_tW[new_i]).ld) );
    if (_work == ((void *)0)) { _work = (float*) malloc(sizeof(float)); _lwork = 1; } ssyev_( &_jobz,&_uplo,&((_tW[new_i]).rows),(_tW[new_i]).elem,&((_tW[new_i]).ld), (_eig_vals), _work, &_n1, &_info ); if ((int) _work[0] > _lwork) { _lwork = (int) _work[0]; if (_work) { free( _work ); } _work = (float*) malloc( sizeof(float) * _lwork ); } ssyev_( &_jobz,&_uplo,&((_tW[new_i]).rows),(_tW[new_i]).elem,&((_tW[new_i]).ld), (_eig_vals), _work, &_lwork, &_info );
    for (i = 0; i < W->rows; i++) {
      _eig_vals[i] = 1.0 / sqrt( fabs( _eig_vals[i]) );
    }
    for (col = 0; col < W->cols; col++) {
      for (row = 0; row < W->rows; row++) {
        i = col * W->rows + row;
        A->elem[i] = _eig_vals[row] * _tW[new_i].elem[row*W->rows + col];
      }
    }
    sgemm_( &_not_transpose, &_not_transpose, &((_tW[new_i]).rows), &((*A).cols), &((_tW[new_i]).cols), &_alpha, (_tW[new_i]).elem, &((_tW[new_i]).ld), (*A).elem, &((*A).ld), &_beta, (_tW[5]).elem, &((_tW[5]).ld) );
    sgemm_( &_not_transpose, &_not_transpose, &((_tW[5]).rows), &((_tW[4]).cols), &((_tW[5]).cols), &_alpha, (_tW[5]).elem, &((_tW[5]).ld), (_tW[4]).elem, &((_tW[4]).ld), &_beta, (_tW[new_i]).elem, &((_tW[new_i]).ld) );
    sgemm_( &_not_transpose, &_transpose, &((_tW[new_i]).rows), &((_tW[prev_i]).rows), &((_tW[new_i]).cols), &_alpha, (_tW[new_i]).elem, &((_tW[new_i]).ld), (_tW[prev_i]).elem, &((_tW[prev_i]).ld), &_beta, (_tW[4]).elem, &((_tW[4]).ld) );
    min = 1.0;
    for (i = 0; i < W->rows; i++) {
      if (min > fabs(_tW[4].elem[i*W->rows + i])) {
        min = fabs(_tW[4].elem[i*W->rows + i]);
      }
    }
  } while ((1.0 - min) > _epsilon && num_iter < _max_iter);
  if (new_i == 0) {
    memcpy( _tW[1].elem, _tW[0].elem, sizeof(float) * W->rows * W->cols );
    new_i = 1;
  }
  sgemm_( &_not_transpose, &_transpose, &((_tW[3]).rows), &((_tW[1]).rows), &((_tW[3]).cols), &_alpha, (_tW[3]).elem, &((_tW[3]).ld), (_tW[1]).elem, &((_tW[1]).ld), &_beta, (*A).elem, &((*A).ld) );
  sgemm_( &_not_transpose, &_not_transpose, &((_tW[1]).rows), &((_tW[2]).cols), &((_tW[1]).cols), &_alpha, (_tW[1]).elem, &((_tW[1]).ld), (_tW[2]).elem, &((_tW[2]).ld), &_beta, (*W).elem, &((*W).ld) );
  sgemm_( &_not_transpose, &_not_transpose, &((_tW[1]).rows), &((_white_Z).cols), &((_tW[1]).cols), &_alpha, (_tW[1]).elem, &((_tW[1]).ld), (_white_Z).elem, &((_white_Z).ld), &_beta, (*S).elem, &((*S).ld) );
  sgemv_( &_not_transpose, &((*W).rows), &((*W).cols), &_alpha, (*W).elem, &((*W).ld), mu_S, &_one, &_beta, _eig_vals, &_one );
  memcpy( mu_S, _eig_vals, sizeof(float) * S->rows );
  return num_iter;
}

canonical_original_code:
unsigned int fastica(struct Matrix *W, struct Matrix *A, struct Matrix *S, float *mu_S, struct Matrix *X)
{
  int num_iter; int prev_i; int new_i; int row; int col; int i;
  float min;
  _tW[0] = *W;
  remmean( mu_S, S, X );
  whiten( &_white_Z, &_tW[2], &_tW[3], S, 0 );
  for (i = 0; i < _tW[0].rows * _tW[0].cols; i++) {
    _tW[0].elem[i] = 0.0;
  }
  for (i = 0; i < _tW[0].rows; i++) {
    _tW[0].elem[i + i*_tW[0].rows] = 1.0;
  }
  num_iter = 0;
  do {
    new_i = (num_iter + 1) & 0x01;
    prev_i = (num_iter ) & 0x01;
    num_iter++;
    _contrast( &_tW[4], &_tW[prev_i], &_white_Z );
    sgemm_( &_not_transpose, &_transpose, &((_tW[4]).rows), &((_tW[4]).rows), &((_tW[4]).cols), &_alpha, (_tW[4]).elem, &((_tW[4]).ld), (_tW[4]).elem, &((_tW[4]).ld), &_beta, (_tW[new_i]).elem, &((_tW[new_i]).ld) );
    if (_work == ((void *)0)) { _work = (float *) malloc(sizeof(float)); _lwork = 1; } ssyev_( &_jobz,&_uplo,&((_tW[new_i]).rows),(_tW[new_i]).elem,&((_tW[new_i]).ld), (_eig_vals), _work, &_n1, &_info ); if ((int) _work[0] > _lwork) { _lwork = (int) _work[0]; if (_work) { free( _work ); } _work = (float *) malloc( sizeof(float) * _lwork ); } ssyev_( &_jobz,&_uplo,&((_tW[new_i]).rows),(_tW[new_i]).elem,&((_tW[new_i]).ld), (_eig_vals), _work, &_lwork, &_info );
    for (i = 0; i < W->rows; i++) {
      _eig_vals[i] = 1.0 / sqrt( fabs( _eig_vals[i]) );
    }
    for (col = 0; col < W->cols; col++) {
      for (row = 0; row < W->rows; row++) {
        i = col * W->rows + row;
        A->elem[i] = _eig_vals[row] * _tW[new_i].elem[row*W->rows + col];
      }
    }
    sgemm_( &_not_transpose, &_not_transpose, &((_tW[new_i]).rows), &((*A).cols), &((_tW[new_i]).cols), &_alpha, (_tW[new_i]).elem, &((_tW[new_i]).ld), (*A).elem, &((*A).ld), &_beta, (_tW[5]).elem, &((_tW[5]).ld) );
    sgemm_( &_not_transpose, &_not_transpose, &((_tW[5]).rows), &((_tW[4]).cols), &((_tW[5]).cols), &_alpha, (_tW[5]).elem, &((_tW[5]).ld), (_tW[4]).elem, &((_tW[4]).ld), &_beta, (_tW[new_i]).elem, &((_tW[new_i]).ld) );
    sgemm_( &_not_transpose, &_transpose, &((_tW[new_i]).rows), &((_tW[prev_i]).rows), &((_tW[new_i]).cols), &_alpha, (_tW[new_i]).elem, &((_tW[new_i]).ld), (_tW[prev_i]).elem, &((_tW[prev_i]).ld), &_beta, (_tW[4]).elem, &((_tW[4]).ld) );
    min = 1.0;
    for (i = 0; i < W->rows; i++) {
      if (min > fabs(_tW[4].elem[i*W->rows + i])) {
        min = fabs(_tW[4].elem[i*W->rows + i]);
      }
    }
  } while ((1.0 - min) > _epsilon && num_iter < _max_iter);
  if (new_i == 0) {
    memcpy( _tW[1].elem, _tW[0].elem, sizeof(float) * W->rows * W->cols );
    new_i = 1;
  }
  sgemm_( &_not_transpose, &_transpose, &((_tW[3]).rows), &((_tW[1]).rows), &((_tW[3]).cols), &_alpha, (_tW[3]).elem, &((_tW[3]).ld), (_tW[1]).elem, &((_tW[1]).ld), &_beta, (*A).elem, &((*A).ld) );
  sgemm_( &_not_transpose, &_not_transpose, &((_tW[1]).rows), &((_tW[2]).cols), &((_tW[1]).cols), &_alpha, (_tW[1]).elem, &((_tW[1]).ld), (_tW[2]).elem, &((_tW[2]).ld), &_beta, (*W).elem, &((*W).ld) );
  sgemm_( &_not_transpose, &_not_transpose, &((_tW[1]).rows), &((_white_Z).cols), &((_tW[1]).cols), &_alpha, (_tW[1]).elem, &((_tW[1]).ld), (_white_Z).elem, &((_white_Z).ld), &_beta, (*S).elem, &((*S).ld) );
  sgemv_( &_not_transpose, &((*W).rows), &((*W).cols), &_alpha, (*W).elem, &((*W).ld), mu_S, &_one, &_beta, _eig_vals, &_one );
  memcpy( mu_S, _eig_vals, sizeof(float) * S->rows );
  return num_iter;
}

variable_types: struct Matrix { float *elem; int rows; int cols; int ld; int lag; } *

variable_types:
A
struct Matrix *

variable_types: row int

variable_types: col int

variable_types: min float


original_code:
void conv_mirrorDown( float *output,
                      float const *input, unsigned int len_input,
                      float const *filter, unsigned int len_filter )
{
  unsigned int i, j, k;
  float sum;
  for (i = 1; i < len_filter - 1; i += 2) {
    sum = 0.0;
    for (j = 0; j <= i; j++) {
      sum += input[j] * filter[i-j];
    }
    for (j = i+1; j < len_filter; j++) {
      sum += input[j-i] * filter[j];
    }
    *(output++) = sum;
  }
  for (; i < len_input; i += 2) {
    sum = 0.0;
    for (j = 0; j < len_filter; j++) {
      sum += input[i-j] * filter[j];
    }
    *(output++) = sum;
  }
  for (; i < len_input + len_filter - 1; i += 2) {
    k = 2 * len_input - 2 - i;
    sum = 0.0;
    for (j = k; j < len_input; j++) {
      sum += input[j] * filter[j-k];
    }
    for (j = 1 - len_filter + i; j < len_input - 1; j++) {
      sum += input[j] * filter[i-j];
    }
    *(output++) = sum;
  }
}

canonical_original_code:
void conv_mirrorDown(float *output, float *input, unsigned int len_input, float *filter, unsigned int len_filter)
{
  unsigned int i; unsigned int j; unsigned int k;
  float sum;
  for (i = 1; i < len_filter - 1; i += 2) {
    sum = 0.0;
    for (j = 0; j <= i; j++) {
      sum += input[j] * filter[i-j];
    }
    for (j = i+1; j < len_filter; j++) {
      sum += input[j-i] * filter[j];
    }
    *(output++) = sum;
  }
  for (; i < len_input; i += 2) {
    sum = 0.0;
    for (j = 0; j < len_filter; j++) {
      sum += input[i-j] * filter[j];
    }
    *(output++) = sum;
  }
  for (; i < len_input + len_filter - 1; i += 2) {
    k = 2 * len_input - 2 - i;
    sum = 0.0;
    for (j = k; j < len_input; j++) {
      sum += input[j] * filter[j-k];
    }
    for (j = 1 - len_filter + i; j < len_input - 1; j++) {
      sum += input[j] * filter[i-j];
    }
    *(output++) = sum;
  }
}

variable_types:
output
float *

variable_types:
input
float *

variable_types:
filter
float *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
k
unsigned int

variable_types: sum float


decompiled_code:
__int64 __fastcall conv_mirrorUp(float *a1, float *a2, unsigned int a3, float *a4, unsigned int a5)
{
unsigned int v5; // er15
float v6; // xmm3_4
__int64 v7; // rdx
float v8; // xmm1_4
float v9; // xmm0_4
float *v10; // rbx
int v11; // er12
unsigned int v12; // er8
unsigned int v13; // er9
int v14; // er11
unsigned int v15; // er15
unsigned int v16; // er14
unsigned int v17; // er13
int v18; // ebp
unsigned int v19; // eax
float v20; // xmm1_4
float v21; // xmm2_4
float *v22; // rdx
float v23; // xmm0_4
float v24; // xmm4_4
__int64 v25; // rdi
unsigned int v26; // edx
float *v27; // rax
__int64 v28; // rdi
float v29; // xmm0_4
float v30; // xmm4_4
float v31; // xmm0_4
int v32; // eax
float *v33; // r9
unsigned int v34; // edi
float v35; // xmm2_4
float v36; // xmm1_4
unsigned int v37; // eax
float *v38; // rdx
unsigned int v39; // eax
__int64 v40; // r10
float v41; // xmm4_4
float v42; // xmm0_4
unsigned int v43; // ebx
__int64 v44; // rax
float *v45; // r11
float *v46; // r13
unsigned int v47; // er10
unsigned int v48; // er9
float v49; // xmm2_4
float v50; // xmm1_4
float *v51; // rdx
int v52; // eax
float v53; // xmm0_4
float v54; // xmm4_4
__int64 v55; // rdi
float *v56; // rdx
unsigned int v57; // eax
float v58; // xmm0_4
float v59; // xmm4_4
__int64 v60; // rdi
__int64 result; // rax
__int64 v62; // rdi
float *v63; // rax
unsigned int v64; // edx
__int64 v65; // rdi
__int64 v66; // rsi
float *v67; // [rsp+0h] [rbp-50h]
unsigned int v68; // [rsp+8h] [rbp-48h]
unsigned int v69; // [rsp+Ch] [rbp-44h]
unsigned int v71; // [rsp+1Ch] [rbp-34h]

v5 = a5;
if ( a5 <= 1 )
{
v6 = 0.0;
v8 = 0.0;
}
else
{
v6 = 0.0;
v7 = 1LL;
v8 = 0.0;
do
{
v9 = a2[(unsigned int)(v7 - 1) >> 1] * a4[v7];
v7 += 2LL;
v8 = v8 + v9;
}
while ( a5 > (unsigned int)v7 );
}
*a1 = v8;
v10 = a1 + 1;
v11 = a5 & 1;
v12 = a5 >> 1;
v67 = a1 + 1;
v69 = (v5 - 1) >> 1;
if ( v69 )
{
v68 = v5;
v13 = v12 - 1;
v14 = 0;
v15 = (v5 - 1) >> 1;
v16 = 2;
v17 = 3;
v18 = -1;
do
{
v19 = 2 * v14;
v20 = 0.0;
v21 = 0.0;
v22 = a2;
do
{
v23 = *v22++;
v24 = a4[v19];
v25 = v19 + 1;
v19 -= 2;
v20 = v20 + (float)(v24 * v23);
v21 = v21 + (float)(v23 * a4[v25]);
}
while ( v19 != -2 );
if ( ++v14 >= v12 )
{
v32 = v14;
}
else
{
v26 = v18 + v14;
v27 = &a4[v16];
do
{
v28 = v26++;
v29 = a2[v28];
v30 = *v27 * v29;
v31 = v29 * v27[v17 - (unsigned __int64)v16];
v27 += 2;
v20 = v20 + v30;
v21 = v21 + v31;
}
while ( v13 != v26 );
v32 = v13 + v14;
}
if ( v11 )
v20 = v20 + (float)(a2[v18 + v32] * a4[2 * v32]);
*v10 = v20;
--v18;
v10 += 2;
v17 += 2;
v16 += 2;
--v13;
*(v10 - 1) = v21;
}
while ( v14 != v15 );
v5 = v68;
v67 += 2 * v69;
}
if ( a3 <= v69 )
{
v43 = a3 - 1;
}
else
{
v33 = v67;
v34 = v69 - v12;
do
{
v35 = 0.0;
v36 = 0.0;
v37 = 0;
if ( v12 )
{
v38 = a4;
v35 = 0.0;
v36 = 0.0;
v39 = v34 + v12;
do
{
v40 = v39;
v41 = *v38;
--v39;
v38 += 2;
v42 = a2[v40];
v36 = v36 + (float)(v41 * v42);
v35 = v35 + (float)(v42 * *(v38 - 1));
}
while ( v34 != v39 );
v37 = v12;
}
if ( v11 )
v36 = v36 + (float)(a2[v34 + v12 - v37] * a4[2 * v37]);
*v33 = v36;
++v34;
v33 += 2;
*(v33 - 1) = v35;
}
while ( a3 - v12 != v34 );
v43 = a3 - 1;
v44 = a3 - 1 - v69;
v69 = a3;
v67 += 2 * v44 + 2;
}
v71 = v43 + v12;
if ( v43 + v12 <= v69 )
{
result = v69;
v71 = v69;
}
else
{
v45 = v67;
v46 = a2 + 1;
v47 = 2 * a3 - 2 - v69;
v48 = v69 - v12 + 1;
do
{
if ( a3 <= v47 )
{
v49 = 0.0;
v50 = 0.0;
}
else
{
v49 = 0.0;
v50 = 0.0;
v51 = &a2[v47];
v52 = 0;
do
{
v53 = *v51++;
v54 = a4[v52];
v55 = (unsigned int)(v52 + 1);
v52 += 2;
v50 = v50 + (float)(v54 * v53);
v49 = v49 + (float)(v53 * a4[v55]);
}
while ( &v46[v47 + (unsigned __int64)(v43 - v47)] != v51 );
}
if ( v43 > v48 )
{
v56 = &a2[v48];
v57 = 2 * (v12 - 1);
do
{
v58 = *v56++;
v59 = a4[v57];
v60 = v57 + 1;
v57 -= 2;
v50 = v50 + (float)(v59 * v58);
v49 = v49 + (float)(v58 * a4[v60]);
}
while ( &v46[v48 + (unsigned __int64)(a3 - 2 - v48)] != v56 );
}
if ( v11 )
v50 = v50 + (float)(a2[v48 - 1] * a4[v5 & 0xFFFFFFFE]);
*v45 = v50;
++v48;
v45 += 2;
--v47;
*(v45 - 1) = v49;
}
while ( a3 != v48 );
result = (__int64)&v67[2 * (v71 - 1 - v69) + 2];
v67 = (float *)result;
}
if ( v11 )
{
v62 = 2 * a3 - 2 - v71;
if ( a3 > (unsigned int)v62 )
{
v63 = &a2[v62];
v64 = 0;
v65 = (__int64)&a2[v43 + 1 + v71 - (2 * a3 - 2) + v62];
do
{
v66 = v64;
++v63;
v64 += 2;
v6 = v6 + (float)(a4[v66] * *(v63 - 1));
}
while ( (float *)v65 != v63 );
}
result = (__int64)v67;
*v67 = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(float *a1, float *a2, unsigned int a3, float *a4, unsigned int a5)
{
unsigned int v5; // er15
float v6; // xmm3_4
__int64 v7; // rdx
float v8; // xmm1_4
float v9; // xmm0_4
float *v10; // rbx
int v11; // er12
unsigned int v12; // er8
unsigned int v13; // er9
int v14; // er11
unsigned int v15; // er15
unsigned int v16; // er14
unsigned int v17; // er13
int v18; // ebp
unsigned int v19; // eax
float v20; // xmm1_4
float v21; // xmm2_4
float *v22; // rdx
float v23; // xmm0_4
float v24; // xmm4_4
__int64 v25; // rdi
unsigned int v26; // edx
float *v27; // rax
__int64 v28; // rdi
float v29; // xmm0_4
float v30; // xmm4_4
float v31; // xmm0_4
int v32; // eax
float *v33; // r9
unsigned int v34; // edi
float v35; // xmm2_4
float v36; // xmm1_4
unsigned int v37; // eax
float *v38; // rdx
unsigned int v39; // eax
__int64 v40; // r10
float v41; // xmm4_4
float v42; // xmm0_4
unsigned int v43; // ebx
__int64 v44; // rax
float *v45; // r11
float *v46; // r13
unsigned int v47; // er10
unsigned int v48; // er9
float v49; // xmm2_4
float v50; // xmm1_4
float *v51; // rdx
int v52; // eax
float v53; // xmm0_4
float v54; // xmm4_4
__int64 v55; // rdi
float *v56; // rdx
unsigned int v57; // eax
float v58; // xmm0_4
float v59; // xmm4_4
__int64 v60; // rdi
__int64 result; // rax
__int64 v62; // rdi
float *v63; // rax
unsigned int v64; // edx
__int64 v65; // rdi
__int64 v66; // rsi
float *v67; // [rsp+0h] [rbp-50h]
unsigned int v68; // [rsp+8h] [rbp-48h]
unsigned int v69; // [rsp+Ch] [rbp-44h]
unsigned int v71; // [rsp+1Ch] [rbp-34h]

v5 = a5;
if ( a5 <= 1 )
{
v6 = 0.0;
v8 = 0.0;
}
else
{
v6 = 0.0;
v7 = 1LL;
v8 = 0.0;
do
{
v9 = a2[(unsigned int)(v7 - 1) >> 1] * a4[v7];
v7 += 2LL;
v8 = v8 + v9;
}
while ( a5 > (unsigned int)v7 );
}
*a1 = v8;
v10 = a1 + 1;
v11 = a5 & 1;
v12 = a5 >> 1;
v67 = a1 + 1;
v69 = (v5 - 1) >> 1;
if ( v69 )
{
v68 = v5;
v13 = v12 - 1;
v14 = 0;
v15 = (v5 - 1) >> 1;
v16 = 2;
v17 = 3;
v18 = -1;
do
{
v19 = 2 * v14;
v20 = 0.0;
v21 = 0.0;
v22 = a2;
do
{
v23 = *v22++;
v24 = a4[v19];
v25 = v19 + 1;
v19 -= 2;
v20 = v20 + (float)(v24 * v23);
v21 = v21 + (float)(v23 * a4[v25]);
}
while ( v19 != -2 );
if ( ++v14 >= v12 )
{
v32 = v14;
}
else
{
v26 = v18 + v14;
v27 = &a4[v16];
do
{
v28 = v26++;
v29 = a2[v28];
v30 = *v27 * v29;
v31 = v29 * v27[v17 - (unsigned __int64)v16];
v27 += 2;
v20 = v20 + v30;
v21 = v21 + v31;
}
while ( v13 != v26 );
v32 = v13 + v14;
}
if ( v11 )
v20 = v20 + (float)(a2[v18 + v32] * a4[2 * v32]);
*v10 = v20;
--v18;
v10 += 2;
v17 += 2;
v16 += 2;
--v13;
*(v10 - 1) = v21;
}
while ( v14 != v15 );
v5 = v68;
v67 += 2 * v69;
}
if ( a3 <= v69 )
{
v43 = a3 - 1;
}
else
{
v33 = v67;
v34 = v69 - v12;
do
{
v35 = 0.0;
v36 = 0.0;
v37 = 0;
if ( v12 )
{
v38 = a4;
v35 = 0.0;
v36 = 0.0;
v39 = v34 + v12;
do
{
v40 = v39;
v41 = *v38;
--v39;
v38 += 2;
v42 = a2[v40];
v36 = v36 + (float)(v41 * v42);
v35 = v35 + (float)(v42 * *(v38 - 1));
}
while ( v34 != v39 );
v37 = v12;
}
if ( v11 )
v36 = v36 + (float)(a2[v34 + v12 - v37] * a4[2 * v37]);
*v33 = v36;
++v34;
v33 += 2;
*(v33 - 1) = v35;
}
while ( a3 - v12 != v34 );
v43 = a3 - 1;
v44 = a3 - 1 - v69;
v69 = a3;
v67 += 2 * v44 + 2;
}
v71 = v43 + v12;
if ( v43 + v12 <= v69 )
{
result = v69;
v71 = v69;
}
else
{
v45 = v67;
v46 = a2 + 1;
v47 = 2 * a3 - 2 - v69;
v48 = v69 - v12 + 1;
do
{
if ( a3 <= v47 )
{
v49 = 0.0;
v50 = 0.0;
}
else
{
v49 = 0.0;
v50 = 0.0;
v51 = &a2[v47];
v52 = 0;
do
{
v53 = *v51++;
v54 = a4[v52];
v55 = (unsigned int)(v52 + 1);
v52 += 2;
v50 = v50 + (float)(v54 * v53);
v49 = v49 + (float)(v53 * a4[v55]);
}
while ( &v46[v47 + (unsigned __int64)(v43 - v47)] != v51 );
}
if ( v43 > v48 )
{
v56 = &a2[v48];
v57 = 2 * (v12 - 1);
do
{
v58 = *v56++;
v59 = a4[v57];
v60 = v57 + 1;
v57 -= 2;
v50 = v50 + (float)(v59 * v58);
v49 = v49 + (float)(v58 * a4[v60]);
}
while ( &v46[v48 + (unsigned __int64)(a3 - 2 - v48)] != v56 );
}
if ( v11 )
v50 = v50 + (float)(a2[v48 - 1] * a4[v5 & 0xFFFFFFFE]);
*v45 = v50;
++v48;
v45 += 2;
--v47;
*(v45 - 1) = v49;
}
while ( a3 != v48 );
result = (__int64)&v67[2 * (v71 - 1 - v69) + 2];
v67 = (float *)result;
}
if ( v11 )
{
v62 = 2 * a3 - 2 - v71;
if ( a3 > (unsigned int)v62 )
{
v63 = &a2[v62];
v64 = 0;
v65 = (__int64)&a2[v43 + 1 + v71 - (2 * a3 - 2) + v62];
do
{
v66 = v64;
++v63;
v64 += 2;
v6 = v6 + (float)(a4[v66] * *(v63 - 1));
}
while ( (float *)v65 != v63 );
}
result = (__int64)v67;
*v67 = v6;
}
return result;
}

original_code:
void conv_mirrorUp( float *output,
                    float const *input, unsigned int len_input,
                    float const *filter, unsigned int len_filter )
{
  unsigned int i, j, k;
  float sum[2];
  sum[0] = 0.0;
  for (i = 1; i < len_filter; i += 2) {
    sum[0] += input[(i - 1) / 2] * filter[i];
  }
  *(output++) = sum[0];
  for (i = 0; i < (len_filter - 1) / 2; i++) {
    sum[0] = 0.0;
    sum[1] = 0.0;
    for (j = 0; j <= i; j++) {
      sum[0] += input[j] * filter[2*(i-j)];
      sum[1] += input[j] * filter[2*(i-j) + 1];
    }
    for (j = i+1; j < len_filter/2; j++) {
      sum[0] += input[j-i-1] * filter[2*j];
      sum[1] += input[j-i-1] * filter[2*j + 1];
    }
    if (len_filter & 1) {
      sum[0] += input[j-i-1] * filter[2*j];
    }
    *(output++) = sum[0];
    *(output++) = sum[1];
  }
  for (; i < len_input; i++) {
    sum[0] = 0.0;
    sum[1] = 0.0;
    for (j = 0; j < len_filter / 2; j++) {
      sum[0] += input[i-j] * filter[2*j];
      sum[1] += input[i-j] * filter[2*j + 1];
    }
    if (len_filter & 1) {
      sum[0] += input[i-j] * filter[2*j];
    }
    *(output++) = sum[0];
    *(output++) = sum[1];
  }
  for (; i < len_input + (len_filter / 2) - 1; i++) {
    k = 2 * len_input - 2 - i;
    sum[0] = 0.0;
    sum[1] = 0.0;
    for (j = k; j < len_input; j++) {
      sum[0] += input[j] * filter[2*(j-k)];
      sum[1] += input[j] * filter[2*(j-k) + 1];
    }
    for (j = 1 - (len_filter/2) + i; j < len_input - 1; j++) {
      sum[0] += input[j] * filter[2*(i-j)];
      sum[1] += input[j] * filter[2*(i-j) + 1];
    }
    if (len_filter & 1) {
      j = 1 - (len_filter/2) + i - 1;
      sum[0] += input[j] * filter[2*(i-j)];
    }
    *(output++) = sum[0];
    *(output++) = sum[1];
  }
  if (len_filter & 1) {
    k = 2 * len_input - 2 - i;
    sum[0] = 0.0;
    for (j = k; j < len_input; j++) {
      sum[0] += input[j] * filter[2*(j-k)];
    }
    *(output++) = sum[0];
  }
}

canonical_original_code:
void conv_mirrorUp(float *output, float *input, unsigned int len_input, float *filter, unsigned int len_filter)
{
  unsigned int i; unsigned int j; unsigned int k;
  float sum[2];
  sum[0] = 0.0;
  for (i = 1; i < len_filter; i += 2) {
    sum[0] += input[(i - 1) / 2] * filter[i];
  }
  *(output++) = sum[0];
  for (i = 0; i < (len_filter - 1) / 2; i++) {
    sum[0] = 0.0;
    sum[1] = 0.0;
    for (j = 0; j <= i; j++) {
      sum[0] += input[j] * filter[2*(i-j)];
      sum[1] += input[j] * filter[2*(i-j) + 1];
    }
    for (j = i+1; j < len_filter/2; j++) {
      sum[0] += input[j-i-1] * filter[2*j];
      sum[1] += input[j-i-1] * filter[2*j + 1];
    }
    if (len_filter & 1) {
      sum[0] += input[j-i-1] * filter[2*j];
    }
    *(output++) = sum[0];
    *(output++) = sum[1];
  }
  for (; i < len_input; i++) {
    sum[0] = 0.0;
    sum[1] = 0.0;
    for (j = 0; j < len_filter / 2; j++) {
      sum[0] += input[i-j] * filter[2*j];
      sum[1] += input[i-j] * filter[2*j + 1];
    }
    if (len_filter & 1) {
      sum[0] += input[i-j] * filter[2*j];
    }
    *(output++) = sum[0];
    *(output++) = sum[1];
  }
  for (; i < len_input + (len_filter / 2) - 1; i++) {
    k = 2 * len_input - 2 - i;
    sum[0] = 0.0;
    sum[1] = 0.0;
    for (j = k; j < len_input; j++) {
      sum[0] += input[j] * filter[2*(j-k)];
      sum[1] += input[j] * filter[2*(j-k) + 1];
    }
    for (j = 1 - (len_filter/2) + i; j < len_input - 1; j++) {
      sum[0] += input[j] * filter[2*(i-j)];
      sum[1] += input[j] * filter[2*(i-j) + 1];
    }
    if (len_filter & 1) {
      j = 1 - (len_filter/2) + i - 1;
      sum[0] += input[j] * filter[2*(i-j)];
    }
    *(output++) = sum[0];
    *(output++) = sum[1];
  }
  if (len_filter & 1) {
    k = 2 * len_input - 2 - i;
    sum[0] = 0.0;
    for (j = k; j < len_input; j++) {
      sum[0] += input[j] * filter[2*(j-k)];
    }
    *(output++) = sum[0];
  }
}

variable_types:
sum
float [2]


decompiled_code:
int __fastcall xltek_printErdHeaderS9(__int64 a1)
{
unsigned int v1; // er10
__int64 v2; // r8
__int64 v3; // r9
__int64 v4; // r11
char *v5; // rax
unsigned int v6; // esi
unsigned int v8; // [rsp+0h] [rbp-18h] BYREF
unsigned int v9; // [rsp+4h] [rbp-14h]
unsigned int v10; // [rsp+8h] [rbp-10h]
unsigned int v11; // [rsp+Ch] [rbp-Ch]
char v12; // [rsp+10h] [rbp-8h] BYREF

v2 = *(unsigned int *)(a1 + 4116);
v3 = *(unsigned int *)(a1 + 4120);
v4 = *(unsigned int *)(a1 + 4124);
v5 = (char *)&v8;
v6 = num_headbox_types;
v8 = *(_DWORD *)(a1 + 4112);
v1 = v8;
v9 = v2;
v10 = v3;
v11 = v4;
if ( num_headbox_types > v8 )
goto LABEL_3;
while ( 1 )
{
*(_DWORD *)v5 = 0;
LABEL_3:
v5 += 4;
if ( &v12 == v5 )
break;
while ( v6 > *(_DWORD *)v5 )
{
v5 += 4;
if ( &v12 == v5 )
return printf(
"ERD schema 9.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 4128),
(const char *)(a1 + 4144),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 4132),
(const char *)(a1 + 4154),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 4136),
(const char *)(a1 + 4164),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 4140),
(const char *)(a1 + 4174),
(const char *)(a1 + 4184),
(const char *)(a1 + 4194),
*(unsigned int *)(a1 + 4204));
}
}
return printf(
"ERD schema 9.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 4128),
(const char *)(a1 + 4144),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 4132),
(const char *)(a1 + 4154),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 4136),
(const char *)(a1 + 4164),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 4140),
(const char *)(a1 + 4174),
(const char *)(a1 + 4184),
(const char *)(a1 + 4194),
*(unsigned int *)(a1 + 4204));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
unsigned int v1; // er10
__int64 v2; // r8
__int64 v3; // r9
__int64 v4; // r11
char *v5; // rax
unsigned int v6; // esi
unsigned int v8; // [rsp+0h] [rbp-18h] BYREF
unsigned int v9; // [rsp+4h] [rbp-14h]
unsigned int v10; // [rsp+8h] [rbp-10h]
unsigned int v11; // [rsp+Ch] [rbp-Ch]
char v12; // [rsp+10h] [rbp-8h] BYREF

v2 = *(unsigned int *)(a1 + 4116);
v3 = *(unsigned int *)(a1 + 4120);
v4 = *(unsigned int *)(a1 + 4124);
v5 = (char *)&v8;
v6 = num_headbox_types;
v8 = *(_DWORD *)(a1 + 4112);
v1 = v8;
v9 = v2;
v10 = v3;
v11 = v4;
if ( num_headbox_types > v8 )
goto LABEL_3;
while ( 1 )
{
*(_DWORD *)v5 = 0;
LABEL_3:
v5 += 4;
if ( &v12 == v5 )
break;
while ( v6 > *(_DWORD *)v5 )
{
v5 += 4;
if ( &v12 == v5 )
return printf(
"ERD schema 9.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 4128),
(const char *)(a1 + 4144),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 4132),
(const char *)(a1 + 4154),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 4136),
(const char *)(a1 + 4164),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 4140),
(const char *)(a1 + 4174),
(const char *)(a1 + 4184),
(const char *)(a1 + 4194),
*(unsigned int *)(a1 + 4204));
}
}
return printf(
"ERD schema 9.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 4128),
(const char *)(a1 + 4144),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 4132),
(const char *)(a1 + 4154),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 4136),
(const char *)(a1 + 4164),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 4140),
(const char *)(a1 + 4174),
(const char *)(a1 + 4184),
(const char *)(a1 + 4194),
*(unsigned int *)(a1 + 4204));
}

original_code:
void xltek_printErdHeaderS9( const xltek_erd_s9_t *head )
{
  unsigned int i, boxtype[4] = { head->m_headbox_type[0],
                                 head->m_headbox_type[1],
                                 head->m_headbox_type[2],
                                 head->m_headbox_type[3] };
  for (i = 0; i < 4; i++) {
    if (boxtype[i] >= _num_headbox_types) {
      boxtype[i] = 0;
    }
  }
  printf("ERD schema 9.\n"
         "Sample frequency:           %g\n"
         "Number of channels:         %d\n"
         "Bits of delta per channel:  %d\n"
         "Storage order:              --skipped--\n"
         "\n"
         "Headbox:  type        |  serial  | software version\n"
         "          ------------+----------+-----------------\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "\n"
         "DSP hardware version:       %s\n"
         "DSP software version:       %s\n"
         "Discarded least sig. bits:  %d\n",
         head->m_sample_freq,
         head->m_num_channels,
         head->m_deltabits,
         head->m_headbox_type[0], _headbox_types[boxtype[0]],
            head->m_headbox_sn[0], head->m_headbox_sw_version[0],
         head->m_headbox_type[1], _headbox_types[boxtype[1]],
            head->m_headbox_sn[1], head->m_headbox_sw_version[1],
         head->m_headbox_type[2], _headbox_types[boxtype[2]],
            head->m_headbox_sn[2], head->m_headbox_sw_version[2],
         head->m_headbox_type[3], _headbox_types[boxtype[3]],
            head->m_headbox_sn[3], head->m_headbox_sw_version[3],
         head->m_dsp_hw_version,
         head->m_dsp_sw_version,
         head->m_discardbits );
}

canonical_original_code:
void xltek_printErdHeaderS9(struct xltek_erd_s9_t *head)
{
  unsigned int i; unsigned int boxtype[4] = { head->m_headbox_type[0],
                                 head->m_headbox_type[1],
                                 head->m_headbox_type[2],
                                 head->m_headbox_type[3] };
  for (i = 0; i < 4; i++) {
    if (boxtype[i] >= _num_headbox_types) {
      boxtype[i] = 0;
    }
  }
  printf("ERD schema 9.\n"
         "Sample frequency:           %g\n"
         "Number of channels:         %d\n"
         "Bits of delta per channel:  %d\n"
         "Storage order:              --skipped--\n"
         "\n"
         "Headbox:  type        |  serial  | software version\n"
         "          ------------+----------+-----------------\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "\n"
         "DSP hardware version:       %s\n"
         "DSP software version:       %s\n"
         "Discarded least sig. bits:  %d\n",
         head->m_sample_freq,
         head->m_num_channels,
         head->m_deltabits,
         head->m_headbox_type[0], _headbox_types[boxtype[0]],
            head->m_headbox_sn[0], head->m_headbox_sw_version[0],
         head->m_headbox_type[1], _headbox_types[boxtype[1]],
            head->m_headbox_sn[1], head->m_headbox_sw_version[1],
         head->m_headbox_type[2], _headbox_types[boxtype[2]],
            head->m_headbox_sn[2], head->m_headbox_sw_version[2],
         head->m_headbox_type[3], _headbox_types[boxtype[3]],
            head->m_headbox_sn[3], head->m_headbox_sw_version[3],
         head->m_dsp_hw_version,
         head->m_dsp_sw_version,
         head->m_discardbits );
}

variable_types: struct xltek_erd_s9_t { double m_sample_freq; unsigned int m_num_channels; unsigned int m_deltabits; unsigned int m_phys_chan[1024]; unsigned int m_headbox_type[4]; unsigned int m_headbox_sn[4]; char m_headbox_sw_version[4][10]; char m_dsp_hw_version[10]; char m_dsp_sw_version[10]; unsigned int m_discardbits; unsigned short m_shorted[1024]; unsigned short m_frequency_factor[1024]; } *

variable_types:
boxtype
unsigned int [4]


decompiled_code:
int __fastcall xltek_printErdHeaderS7(__int64 a1)
{
unsigned int v1; // er10
__int64 v2; // r8
__int64 v3; // r9
__int64 v4; // r11
char *v5; // rax
unsigned int v6; // esi
unsigned int v8; // [rsp+0h] [rbp-18h] BYREF
unsigned int v9; // [rsp+4h] [rbp-14h]
unsigned int v10; // [rsp+8h] [rbp-10h]
unsigned int v11; // [rsp+Ch] [rbp-Ch]
char v12; // [rsp+10h] [rbp-8h] BYREF

v2 = *(unsigned int *)(a1 + 4116);
v3 = *(unsigned int *)(a1 + 4120);
v4 = *(unsigned int *)(a1 + 4124);
v5 = (char *)&v8;
v6 = num_headbox_types;
v8 = *(_DWORD *)(a1 + 4112);
v1 = v8;
v9 = v2;
v10 = v3;
v11 = v4;
if ( num_headbox_types > v8 )
goto LABEL_3;
while ( 1 )
{
*(_DWORD *)v5 = 0;
LABEL_3:
v5 += 4;
if ( &v12 == v5 )
break;
while ( v6 > *(_DWORD *)v5 )
{
v5 += 4;
if ( &v12 == v5 )
return printf(
"ERD schema 7.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 4128),
(const char *)(a1 + 4144),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 4132),
(const char *)(a1 + 4154),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 4136),
(const char *)(a1 + 4164),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 4140),
(const char *)(a1 + 4174),
(const char *)(a1 + 4184),
(const char *)(a1 + 4194),
*(unsigned int *)(a1 + 4204));
}
}
return printf(
"ERD schema 7.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 4128),
(const char *)(a1 + 4144),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 4132),
(const char *)(a1 + 4154),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 4136),
(const char *)(a1 + 4164),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 4140),
(const char *)(a1 + 4174),
(const char *)(a1 + 4184),
(const char *)(a1 + 4194),
*(unsigned int *)(a1 + 4204));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
unsigned int v1; // er10
__int64 v2; // r8
__int64 v3; // r9
__int64 v4; // r11
char *v5; // rax
unsigned int v6; // esi
unsigned int v8; // [rsp+0h] [rbp-18h] BYREF
unsigned int v9; // [rsp+4h] [rbp-14h]
unsigned int v10; // [rsp+8h] [rbp-10h]
unsigned int v11; // [rsp+Ch] [rbp-Ch]
char v12; // [rsp+10h] [rbp-8h] BYREF

v2 = *(unsigned int *)(a1 + 4116);
v3 = *(unsigned int *)(a1 + 4120);
v4 = *(unsigned int *)(a1 + 4124);
v5 = (char *)&v8;
v6 = num_headbox_types;
v8 = *(_DWORD *)(a1 + 4112);
v1 = v8;
v9 = v2;
v10 = v3;
v11 = v4;
if ( num_headbox_types > v8 )
goto LABEL_3;
while ( 1 )
{
*(_DWORD *)v5 = 0;
LABEL_3:
v5 += 4;
if ( &v12 == v5 )
break;
while ( v6 > *(_DWORD *)v5 )
{
v5 += 4;
if ( &v12 == v5 )
return printf(
"ERD schema 7.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 4128),
(const char *)(a1 + 4144),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 4132),
(const char *)(a1 + 4154),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 4136),
(const char *)(a1 + 4164),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 4140),
(const char *)(a1 + 4174),
(const char *)(a1 + 4184),
(const char *)(a1 + 4194),
*(unsigned int *)(a1 + 4204));
}
}
return printf(
"ERD schema 7.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 4128),
(const char *)(a1 + 4144),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 4132),
(const char *)(a1 + 4154),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 4136),
(const char *)(a1 + 4164),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 4140),
(const char *)(a1 + 4174),
(const char *)(a1 + 4184),
(const char *)(a1 + 4194),
*(unsigned int *)(a1 + 4204));
}

original_code:
void xltek_printErdHeaderS7( const xltek_erd_s7_t *head )
{
  unsigned int i, boxtype[4] = { head->m_headbox_type[0],
                                 head->m_headbox_type[1],
                                 head->m_headbox_type[2],
                                 head->m_headbox_type[3] };
  for (i = 0; i < 4; i++) {
    if (boxtype[i] >= _num_headbox_types) {
      boxtype[i] = 0;
    }
  }
  printf("ERD schema 7.\n"
         "Sample frequency:           %g\n"
         "Number of channels:         %d\n"
         "Bits of delta per channel:  %d\n"
         "Storage order:              --skipped--\n"
         "\n"
         "Headbox:  type        |  serial  | software version\n"
         "          ------------+----------+-----------------\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "\n"
         "DSP hardware version:       %s\n"
         "DSP software version:       %s\n"
         "Discarded least sig. bits:  %d\n",
         head->m_sample_freq,
         head->m_num_channels,
         head->m_deltabits,
         head->m_headbox_type[0], _headbox_types[boxtype[0]],
            head->m_headbox_sn[0], head->m_headbox_sw_version[0],
         head->m_headbox_type[1], _headbox_types[boxtype[1]],
            head->m_headbox_sn[1], head->m_headbox_sw_version[1],
         head->m_headbox_type[2], _headbox_types[boxtype[2]],
            head->m_headbox_sn[2], head->m_headbox_sw_version[2],
         head->m_headbox_type[3], _headbox_types[boxtype[3]],
            head->m_headbox_sn[3], head->m_headbox_sw_version[3],
         head->m_dsp_hw_version,
         head->m_dsp_sw_version,
         head->m_discardbits );
}

canonical_original_code:
void xltek_printErdHeaderS7(struct xltek_erd_s7_t *head)
{
  unsigned int i; unsigned int boxtype[4] = { head->m_headbox_type[0],
                                 head->m_headbox_type[1],
                                 head->m_headbox_type[2],
                                 head->m_headbox_type[3] };
  for (i = 0; i < 4; i++) {
    if (boxtype[i] >= _num_headbox_types) {
      boxtype[i] = 0;
    }
  }
  printf("ERD schema 7.\n"
         "Sample frequency:           %g\n"
         "Number of channels:         %d\n"
         "Bits of delta per channel:  %d\n"
         "Storage order:              --skipped--\n"
         "\n"
         "Headbox:  type        |  serial  | software version\n"
         "          ------------+----------+-----------------\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "\n"
         "DSP hardware version:       %s\n"
         "DSP software version:       %s\n"
         "Discarded least sig. bits:  %d\n",
         head->m_sample_freq,
         head->m_num_channels,
         head->m_deltabits,
         head->m_headbox_type[0], _headbox_types[boxtype[0]],
            head->m_headbox_sn[0], head->m_headbox_sw_version[0],
         head->m_headbox_type[1], _headbox_types[boxtype[1]],
            head->m_headbox_sn[1], head->m_headbox_sw_version[1],
         head->m_headbox_type[2], _headbox_types[boxtype[2]],
            head->m_headbox_sn[2], head->m_headbox_sw_version[2],
         head->m_headbox_type[3], _headbox_types[boxtype[3]],
            head->m_headbox_sn[3], head->m_headbox_sw_version[3],
         head->m_dsp_hw_version,
         head->m_dsp_sw_version,
         head->m_discardbits );
}

variable_types: struct xltek_erd_s7_t { double m_sample_freq; unsigned int m_num_channels; unsigned int m_deltabits; unsigned int m_phys_chan[1024]; unsigned int m_headbox_type[4]; unsigned int m_headbox_sn[4]; char m_headbox_sw_version[4][10]; char m_dsp_hw_version[10]; char m_dsp_sw_version[10]; unsigned int m_discardbits; } *


decompiled_code:
int __fastcall xltek_printErdHeader(__int64 a1, __int64 a2)
{
int result; // eax

switch ( (int)a2 )
{
case 5:
result = xltek_printErdHeaderS5();
break;
case 6:
result = xltek_printErdHeaderS6();
break;
case 7:
result = xltek_printErdHeaderS7();
break;
case 8:
result = xltek_printErdHeaderS8();
break;
case 9:
result = xltek_printErdHeaderS9();
break;
default:
result = printf("Unknown ERD schema (%d).\n", a2);
break;
}
return result;
}

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

switch ( (int)a2 )
{
case 5:
result = xltek_printErdHeaderS5();
break;
case 6:
result = xltek_printErdHeaderS6();
break;
case 7:
result = xltek_printErdHeaderS7();
break;
case 8:
result = xltek_printErdHeaderS8();
break;
case 9:
result = xltek_printErdHeaderS9();
break;
default:
result = printf("Unknown ERD schema (%d).\n", a2);
break;
}
return result;
}

original_code:
void xltek_printErdHeader( const xltek_erd_head_t *head, int schema )
{
  switch (schema) {
    case 5: xltek_printErdHeaderS5( &(head->s5) ); break;
    case 6: xltek_printErdHeaderS6( &(head->s6) ); break;
    case 7: xltek_printErdHeaderS7( &(head->s7) ); break;
    case 8: xltek_printErdHeaderS8( &(head->s8) ); break;
    case 9: xltek_printErdHeaderS9( &(head->s9) ); break;
    default:
      printf( "Unknown ERD schema (%d).\n", schema );
      return;
  }
}

canonical_original_code:
void xltek_printErdHeader(union xltek_erd_head_t *head, int schema)
{
  switch (schema) {
    case 5: xltek_printErdHeaderS5( &(head->s5) ); break;
    case 6: xltek_printErdHeaderS6( &(head->s6) ); break;
    case 7: xltek_printErdHeaderS7( &(head->s7) ); break;
    case 8: xltek_printErdHeaderS8( &(head->s8) ); break;
    case 9: xltek_printErdHeaderS9( &(head->s9) ); break;
    default:
      printf( "Unknown ERD schema (%d).\n", schema );
      return;
  }
}

variable_types: union xltek_erd_head_t { struct xltek_erd_s5_t { double m_sample_freq; unsigned int m_num_channels; unsigned int m_deltabits; unsigned int m_phys_chan[32]; unsigned int m_headbox_type[4]; unsigned int m_headbox_sn[4]; char m_headbox_sw_version[4][10]; char m_dsp_hw_version[10]; char m_dsp_sw_version[10]; unsigned int m_discardbits; } s5; struct xltek_erd_s6_t { double m_sample_freq; unsigned int m_num_channels; unsigned int m_deltabits; unsigned int m_phys_chan[128]; unsigned int m_headbox_type[4]; unsigned int m_headbox_sn[4]; char m_headbox_sw_version[4][10]; char m_dsp_hw_version[10]; char m_dsp_sw_version[10]; unsigned int m_discardbits; } s6; struct xltek_erd_s7_t { double m_sample_freq; unsigned int m_num_channels; unsigned int m_deltabits; unsigned int m_phys_chan[1024]; unsigned int m_headbox_type[4]; unsigned int m_headbox_sn[4]; char m_headbox_sw_version[4][10]; char m_dsp_hw_version[10]; char m_dsp_sw_version[10]; unsigned int m_discardbits; } s7; struct xltek_erd_s8_t { double m_sample_freq; unsigned int m_num_channels; unsigned int m_deltabits; unsigned int m_phys_chan[1024]; unsigned int m_headbox_type[4]; unsigned int m_headbox_sn[4]; char m_headbox_sw_version[4][10]; char m_dsp_hw_version[10]; char m_dsp_sw_version[10]; unsigned int m_discardbits; unsigned short m_shorted[1024]; unsigned short m_frequency_factor[1024]; } s8; struct xltek_erd_s9_t { double m_sample_freq; unsigned int m_num_channels; unsigned int m_deltabits; unsigned int m_phys_chan[1024]; unsigned int m_headbox_type[4]; unsigned int m_headbox_sn[4]; char m_headbox_sw_version[4][10]; char m_dsp_hw_version[10]; char m_dsp_sw_version[10]; unsigned int m_discardbits; unsigned short m_shorted[1024]; unsigned short m_frequency_factor[1024]; } s9; } *

variable_types: schema int

user_defined_types: union xltek_erd_head_t { struct xltek_erd_s5_t s5; struct xltek_erd_s6_t s6; struct xltek_erd_s7_t s7; struct xltek_erd_s8_t s8; struct xltek_erd_s9_t s9; }