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

timer = *(unsigned int *)(a1 + 20);
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_EEG) )
{
v2 = "Patient Information (.eeg)";
LABEL_14:
printf("File type: %s\n", v2);
printf("file schema: %d\n", *(unsigned __int16 *)(a1 + 16));
printf("base schema: %d\n", *(unsigned __int16 *)(a1 + 18));
v3 = ctime(&timer);
printf("creation time: %s", v3);
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_ERD) )
{
v2 = "Raw Data (.erd)";
goto LABEL_14;
}
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_ETC) )
{
v2 = "Table of Contents (.etc)";
goto LABEL_14;
}
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_ENT) )
{
v2 = "Notes (.ent)";
goto LABEL_14;
}
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_SNC) )
{
v2 = "Synchronization File (.snc)";
goto LABEL_14;
}
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_STC) )
{
v2 = "Segments Table of Contents (.stc)";
goto LABEL_14;
}
if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_VTC_MPEG1) )
{
printf("File type: %s\n", "Video Table of Contents (MPEG-1) (.vtc)");
result = 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.");
}
else if ( (unsigned int)xltek_uuidEqual(a1, (__int64)&UUID_VTC_MPEG4) )
{
printf("File type: %s\n", "Video Table of Contents (MPEG-4) (.vtc)");
result = 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.");
}
else
{
puts("Unknown file type.");
xltek_uuidToString((unsigned __int8 *)a1, v5);
printf("GUID: %s\n", v5);
result = puts("Note: byte order is network byte order (big-endian)");
}
return result;
}

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

timer = *(unsigned int *)(a1 + 20);
if ( (unsigned int)func1(a1, (__int64)&UUID_EEG) )
{
v2 = "Patient Information (.eeg)";
LABEL_14:
printf("File type: %s\n", v2);
printf("file schema: %d\n", *(unsigned __int16 *)(a1 + 16));
printf("base schema: %d\n", *(unsigned __int16 *)(a1 + 18));
v3 = ctime(&timer);
printf("creation time: %s", v3);
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_ERD) )
{
v2 = "Raw Data (.erd)";
goto LABEL_14;
}
if ( (unsigned int)func1(a1, (__int64)&UUID_ETC) )
{
v2 = "Table of Contents (.etc)";
goto LABEL_14;
}
if ( (unsigned int)func1(a1, (__int64)&UUID_ENT) )
{
v2 = "Notes (.ent)";
goto LABEL_14;
}
if ( (unsigned int)func1(a1, (__int64)&UUID_SNC) )
{
v2 = "Synchronization File (.snc)";
goto LABEL_14;
}
if ( (unsigned int)func1(a1, (__int64)&UUID_STC) )
{
v2 = "Segments Table of Contents (.stc)";
goto LABEL_14;
}
if ( (unsigned int)func1(a1, (__int64)&UUID_VTC_MPEG1) )
{
printf("File type: %s\n", "Video Table of Contents (MPEG-1) (.vtc)");
result = 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.");
}
else if ( (unsigned int)func1(a1, (__int64)&UUID_VTC_MPEG4) )
{
printf("File type: %s\n", "Video Table of Contents (MPEG-4) (.vtc)");
result = 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.");
}
else
{
puts("Unknown file type.");
func0((unsigned __int8 *)a1, v5);
printf("GUID: %s\n", v5);
result = puts("Note: byte order is network byte order (big-endian)");
}
return result;
}

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)
{
unsigned int v1; // ebx
int v2; // eax
double v3; // xmm0_8
double v4; // xmm0_8
int v5; // xmm0_4
void *v6; // r14
__int64 *v7; // rbp

v1 = *(_DWORD *)(a1 + 16);
num_var = v1;
num_cm = (v1 * (v1 + 1)) >> 1;
num_elem = v1 * v1;
mat_size = 4LL * v1 * v1;
v2 = *(_DWORD *)(a1 + 20);
*(float *)&scale = 1.0 / (float)v2;
v3 = (float)v2;
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
*(float *)&v5 = 1.0 / v4 / 100.0;
threshold = v5;
v6 = malloc(4LL * v1 * v1 * ((v1 * (v1 + 1)) >> 1));
cm_mat = v6;
mu_X = malloc(4LL * v1);
t = (__int64)v6;
dword_C94 = v1;
dword_C90 = v1;
dword_C8C = v1;
dword_C88 = v1;
qword_C98 = (__int64)malloc(4 * v1 * (unsigned __int64)*(unsigned int *)(a1 + 20));
dword_CA8 = v1;
dword_CA0 = v1;
dword_CAC = *(_DWORD *)(a1 + 20);
dword_CA4 = dword_CAC;
qword_CB0 = (__int64)malloc(4 * v1 * (unsigned __int64)*(unsigned int *)(a1 + 20));
dword_CC0 = v1;
dword_CB8 = v1;
dword_CC4 = *(_DWORD *)(a1 + 20);
dword_CBC = dword_CC4;
v7 = &t;
do
{
v7[9] = (__int64)malloc(4LL * v1 * v1);
*((_DWORD *)v7 + 23) = v1;
*((_DWORD *)v7 + 22) = v1;
*((_DWORD *)v7 + 21) = v1;
*((_DWORD *)v7 + 20) = v1;
v7 += 3;
}
while ( v7 != &qword_CC8 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // ebx
int v2; // eax
double v3; // xmm0_8
double v4; // xmm0_8
int v5; // xmm0_4
void *v6; // r14
__int64 *v7; // rbp

v1 = *(_DWORD *)(a1 + 16);
num_var = v1;
num_cm = (v1 * (v1 + 1)) >> 1;
num_elem = v1 * v1;
mat_size = 4LL * v1 * v1;
v2 = *(_DWORD *)(a1 + 20);
*(float *)&scale = 1.0 / (float)v2;
v3 = (float)v2;
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
*(float *)&v5 = 1.0 / v4 / 100.0;
threshold = v5;
v6 = malloc(4LL * v1 * v1 * ((v1 * (v1 + 1)) >> 1));
cm_mat = v6;
mu_X = malloc(4LL * v1);
t = (__int64)v6;
dword_C94 = v1;
dword_C90 = v1;
dword_C8C = v1;
dword_C88 = v1;
qword_C98 = (__int64)malloc(4 * v1 * (unsigned __int64)*(unsigned int *)(a1 + 20));
dword_CA8 = v1;
dword_CA0 = v1;
dword_CAC = *(_DWORD *)(a1 + 20);
dword_CA4 = dword_CAC;
qword_CB0 = (__int64)malloc(4 * v1 * (unsigned __int64)*(unsigned int *)(a1 + 20));
dword_CC0 = v1;
dword_CB8 = v1;
dword_CC4 = *(_DWORD *)(a1 + 20);
dword_CBC = dword_CC4;
v7 = &t;
do
{
v7[9] = (__int64)malloc(4LL * v1 * v1);
*((_DWORD *)v7 + 23) = v1;
*((_DWORD *)v7 + 22) = v1;
*((_DWORD *)v7 + 21) = v1;
*((_DWORD *)v7 + 20) = v1;
v7 += 3;
}
while ( v7 != &qword_CC8 );
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 i; // rbx

free(cm_mat);
cm_mat = 0LL;
free(mu_X);
mu_X = 0LL;
for ( i = 0LL; i != 30; i += 6LL )
{
free((void *)qword_C98[i / 2]);
qword_C98[i / 2] = 0LL;
dword_CA4[i] = 0;
dword_CA0[i] = 0;
dword_CAC[i] = 0;
dword_CA8[i] = 0;
}
mat_size = 0LL;
num_elem = 0;
num_cm = 0;
num_var = 0;
threshold = 0;
scale = 0;
}

canonical_decompiled_code:
void func1()
{
unsigned __int64 i; // rbx

free(cm_mat);
cm_mat = 0LL;
free(mu_X);
mu_X = 0LL;
for ( i = 0LL; i != 30; i += 6LL )
{
free((void *)qword_C98[i / 2]);
qword_C98[i / 2] = 0LL;
dword_CA4[i] = 0;
dword_CA0[i] = 0;
dword_CAC[i] = 0;
dword_CA8[i] = 0;
}
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 v6; // ecx
unsigned int v7; // edx
int v8; // eax
unsigned int v9; // er15
unsigned int v10; // ebp
unsigned int v11; // eax
unsigned int v12; // er8
int v13; // esi
int v14; // esi
int v15; // er8
unsigned int v16; // edx
int v17; // eax
float v18; // xmm0_4
float *v19; // rcx
unsigned int i; // er12
unsigned int v21; // eax
unsigned int v22; // er9
int v23; // esi
int v24; // eax
float *v25; // rax
int v26; // er10
float v27; // xmm1_4
float v28; // xmm1_4
int v29; // er12
int v30; // ebp
unsigned int v31; // er13
unsigned int v32; // er14
int v33; // ebx
unsigned int v34; // eax
float v35; // xmm3_4
float v36; // xmm4_4
float v37; // xmm2_4
int v38; // edx
float v39; // xmm1_4
float v40; // xmm0_4
float v41; // xmm2_4
double v42; // xmm1_8
float v43; // xmm0_4
float v44; // xmm0_4
float v45; // xmm3_4
float v46; // xmm6_4
float v47; // xmm5_4
char *v48; // rax
unsigned int v49; // er8
unsigned int v50; // edi
unsigned int v51; // esi
int v52; // er9
float v53; // xmm4_4
float *v54; // rcx
float v55; // xmm10_4
float *v56; // r13
float v57; // xmm2_4
float *v58; // rdx
int v59; // edx
float *v60; // r13
float v61; // xmm1_4
float *v62; // rcx
unsigned int v63; // er13
unsigned int v64; // edx
float *v65; // r14
float v66; // xmm1_4
float *v67; // rcx
unsigned int v68; // er13
unsigned int v69; // edx
float *v70; // r14
float v71; // xmm1_4
float *v72; // rcx
unsigned int v73; // eax
float v74; // xmm1_4
float *v75; // rcx
float v76; // xmm2_4
unsigned int v77; // eax
int v79; // [rsp+Ch] [rbp-BCh]
unsigned int v80; // [rsp+10h] [rbp-B8h]
unsigned int v81; // [rsp+14h] [rbp-B4h]
double v82; // [rsp+18h] [rbp-B0h]
int v83; // [rsp+18h] [rbp-B0h]
unsigned int v84; // [rsp+20h] [rbp-A8h]
float v85; // [rsp+24h] [rbp-A4h]
int v86; // [rsp+28h] [rbp-A0h]
int v87; // [rsp+2Ch] [rbp-9Ch]
int v88; // [rsp+30h] [rbp-98h]
unsigned int v89; // [rsp+34h] [rbp-94h]
unsigned int v90; // [rsp+38h] [rbp-90h]
int v91; // [rsp+3Ch] [rbp-8Ch]
unsigned int v92; // [rsp+40h] [rbp-88h]
unsigned int v93; // [rsp+44h] [rbp-84h]
unsigned int v94; // [rsp+48h] [rbp-80h]
unsigned int v95; // [rsp+4Ch] [rbp-7Ch]
int v96; // [rsp+50h] [rbp-78h]
unsigned int v97; // [rsp+5Ch] [rbp-6Ch]
double cosx; // [rsp+80h] [rbp-48h] BYREF
double sinx[8]; // [rsp+88h] [rbp-40h] BYREF

memset(s, 0, mat_size);
v6 = num_var;
if ( num_var )
{
v7 = 0;
v8 = 0;
do
{
*((_DWORD *)s + v7) = LC0;
++v8;
v7 += v6 + 1;
}
while ( v8 != v6 );
}
remmean(mu_X, a3, a5);
whiten(qword_C98, &qword_CC8, &qword_CE0, a3, 0LL);
t = (__int64)cm_mat;
v9 = num_var;
v10 = 0;
if ( num_var )
{
while ( 1 )
{
if ( *(_DWORD *)(a5 + 12) )
{
v28 = *(float *)&scale;
v13 = 0;
v12 = 0;
do
{
if ( *(_DWORD *)(a5 + 8) )
{
v11 = 0;
do
{
*(float *)(qword_CB0 + 4LL * (v11 + v13)) = (float)((float)(*(float *)(qword_C98[0] + 4LL * (v10 + v13))
* *(float *)(qword_C98[0] + 4LL * (v10 + v13)))
* v28)
* *(float *)(qword_C98[0] + 4LL * (v11 + v13));
++v11;
}
while ( *(_DWORD *)(a5 + 8) > v11 );
}
++v12;
v13 += v9;
}
while ( *(_DWORD *)(a5 + 12) > v12 );
}
sgemm_(
&not_transpose,
&transpose,
&dword_CB8,
dword_CA0,
&dword_CBC,
&alpha,
qword_CB0,
&dword_CC0,
qword_C98[0],
dword_CA8,
&beta,
t,
&dword_C90);
v14 = num_var;
if ( !num_var )
break;
v15 = num_var + 1;
v16 = 0;
v17 = 0;
do
{
v19 = (float *)(t + 4LL * v16);
if ( v17 == v10 )
v18 = *v19 - 3.0;
else
v18 = *v19 - 1.0;
*v19 = v18;
++v17;
v16 += v15;
}
while ( v17 != v14 );
t += 4LL * (unsigned int)num_elem;
if ( v10 )
goto LABEL_18;
LABEL_27:
++v10;
v9 = num_var;
if ( num_var <= v10 )
goto LABEL_5;
}
t += 4LL * (unsigned int)num_elem;
if ( !v10 )
{
v9 = 0;
goto LABEL_5;
}
LABEL_18:
for ( i = 0; i < v10; ++i )
{
if ( *(_DWORD *)(a5 + 12) )
{
v26 = num_var;
v27 = *(float *)&scale;
v23 = 0;
v22 = 0;
do
{
if ( *(_DWORD *)(a5 + 8) )
{
v21 = 0;
do
{
*(float *)(qword_CB0 + 4LL * (v21 + v23)) = (float)((float)(*(float *)(qword_C98[0] + 4LL * (v10 + v23))
* *(float *)(qword_C98[0] + 4LL * (i + v23)))
* v27)
* *(float *)(qword_C98[0] + 4LL * (v21 + v23));
++v21;
}
while ( *(_DWORD *)(a5 + 8) > v21 );
}
++v22;
v23 += v26;
}
while ( *(_DWORD *)(a5 + 12) > v22 );
}
sgemm_(
&not_transpose,
&transpose,
&dword_CB8,
dword_CA0,
&dword_CBC,
&alpha,
qword_CB0,
&dword_CC0,
qword_C98[0],
dword_CA8,
&beta,
t,
&dword_C90);
v24 = num_var;
*(float *)(t + 4LL * (v10 * num_var + i)) = *(float *)(t + 4LL * (v10 * num_var + i)) - 1.0;
v25 = (float *)(t + 4LL * (i * v24 + v10));
*v25 = *v25 - 1.0;
t += 4LL * (unsigned int)num_elem;
}
goto LABEL_27;
}
LABEL_5:
v97 = 0;
do
{
++v97;
if ( v9 == 1 )
break;
v90 = v9 + 1;
v96 = -v9;
v93 = v9;
v92 = v9;
v87 = 0;
v91 = 0;
v81 = 0;
v86 = 0;
do
{
v84 = v81;
v77 = v81 + 1;
v81 = v77;
if ( v77 < v9 )
{
v89 = v93 - v9;
v30 = v92 - v91;
v31 = v9 + 1;
v32 = v9;
v88 = v96;
v80 = v77;
v79 = 1;
v29 = 1;
do
{
v33 = num_cm;
if ( num_cm )
{
v34 = v93 - v9;
v35 = 0.0;
v36 = 0.0;
v37 = 0.0;
v38 = 0;
do
{
v39 = *((float *)cm_mat + v34) - *((float *)cm_mat + v34 + v31);
v40 = *((float *)cm_mat + v34 + v32) + *((float *)cm_mat + v34 + v32);
v37 = v37 + (float)(v39 * v39);
v35 = v35 + (float)(v39 * v40);
v36 = v36 + (float)(v40 * v40);
++v38;
v34 += num_elem;
}
while ( v38 != num_cm );
v41 = v37 - v36;
v85 = v35 + v35;
v82 = v41;
v42 = (float)((float)(v41 * v41) + (float)((float)(v35 + v35) * (float)(v35 + v35)));
if ( v42 < 0.0 )
{
sqrt(v42);
goto LABEL_37;
}
}
else
{
v85 = 0.0;
v42 = 0.0;
v82 = 0.0;
}
v42 = sqrt(v42);
LABEL_37:
v43 = atan2(v85, v42 + v82) * 0.5;
if ( COERCE_FLOAT(LODWORD(v43) & LC7) > *(float *)&threshold )
{
sincos(v43, sinx, &cosx);
v44 = cosx;
v45 = sinx[0];
if ( v33 )
{
v83 = num_elem;
v46 = v44 * v44;
v47 = v45 * v45;
v48 = (char *)cm_mat;
v49 = v89 + v32;
v50 = v89 + v31;
v51 = v93 - v9;
v52 = 0;
LODWORD(v53) = LODWORD(v45) ^ LC8;
v94 = v31;
v95 = v32;
do
{
v54 = (float *)&v48[4 * v88 + 4 * v89 + 4 * v49];
v55 = *v54;
v56 = (float *)&v48[4 * v49];
v57 = *v56 * ((v44 + v44) * v45);
v58 = (float *)&v48[4 * v49 + 4 * v79];
*v56 = (float)((float)(*v58 - *v54) * (float)(v44 * v45))
+ (float)(*v56 * (float)((float)(v44 * v44) - (float)(v45 * v45)));
*v54 = (float)((float)(v47 * *v58) + (float)(v46 * v55)) + v57;
*v58 = (float)((float)(v46 * *v58) + (float)(v55 * v47)) - v57;
if ( v84 )
{
v59 = v51 + v87;
do
{
v60 = (float *)&v48[4 * v59];
v61 = *v60;
v62 = (float *)&v48[4 * (v59 + v30)];
*v60 = (float)(v45 * *v62) + (float)(*v60 * v44);
*v62 = (float)(v61 * v53) + (float)(v44 * *v62);
++v59;
}
while ( v59 != v51 );
}
if ( v81 < v80 )
{
v63 = v93 + v88 + v49;
v64 = v49 + 1;
do
{
v65 = (float *)&v48[4 * v63];
v66 = *v65;
v67 = (float *)&v48[4 * v64];
*v65 = (float)(v45 * *v67) + (float)(*v65 * v44);
*v67 = (float)(v66 * v53) + (float)(v44 * *v67);
v63 += v9;
++v64;
}
while ( v50 != v64 );
}
v68 = v80 + 1;
if ( v80 + 1 < v9 )
{
v69 = v49 + v92 - v91;
do
{
v70 = (float *)&v48[4 * v69];
v71 = *v70;
v72 = (float *)&v48[4 * v69 + 4 * v29];
*v70 = (float)(v45 * *v72) + (float)(*v70 * v44);
*v72 = (float)(v71 * v53) + (float)(v44 * *v72);
++v68;
v69 += v9;
}
while ( v68 != v9 );
}
++v52;
v49 += v83;
v50 += v83;
v51 += v83;
}
while ( v52 != v33 );
v31 = v94;
v32 = v95;
}
if ( !v9 )
{
v86 = 1;
break;
}
v73 = v91;
do
{
v74 = *((float *)s + v73);
v75 = (float *)((char *)s + 4 * v73 + 4 * v30);
v76 = *v75;
*v75 = (float)(*v75 * v44) - (float)(v74 * v45);
*((float *)s + v73++) = (float)(v74 * v44) + (float)(v76 * v45);
}
while ( v73 != v92 );
v86 = 1;
}
++v80;
++v29;
v30 += v9;
v88 -= v9;
++v79;
v31 += v90;
v32 += v9;
}
while ( v80 < v9 );
}
v91 += v9;
v92 += v9;
v93 += v90;
--v87;
v96 += ~v9;
}
while ( v81 != v9 - 1 );
}
while ( v97 <= 0x63 && v86 );
sgemm_(
&transpose,
&not_transpose,
&unk_D04,
dword_CA4,
&unk_D00,
&alpha,
s,
&unk_D08,
qword_C98[0],
dword_CA8,
&beta,
*a3,
a3 + 2);
sgemm_(
&transpose,
&not_transpose,
&unk_D04,
&unk_CD4,
&unk_D00,
&alpha,
s,
&unk_D08,
qword_CC8,
&unk_CD8,
&beta,
*a1,
a1 + 2);
sgemm_(
&not_transpose,
&not_transpose,
&unk_CE8,
&unk_D04,
&unk_CEC,
&alpha,
qword_CE0,
&unk_CF0,
s,
&unk_D08,
&beta,
*a2,
a2 + 2);
sgemv_(&not_transpose, a1 + 1, (char *)a1 + 12, &alpha, *a1, a1 + 2, mu_X, &one, &beta, a4, &one);
return v97;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, _QWORD *a2, _QWORD *a3, __int64 a4, __int64 a5)
{
int v6; // ecx
unsigned int v7; // edx
int v8; // eax
unsigned int v9; // er15
unsigned int v10; // ebp
unsigned int v11; // eax
unsigned int v12; // er8
int v13; // esi
int v14; // esi
int v15; // er8
unsigned int v16; // edx
int v17; // eax
float v18; // xmm0_4
float *v19; // rcx
unsigned int i; // er12
unsigned int v21; // eax
unsigned int v22; // er9
int v23; // esi
int v24; // eax
float *v25; // rax
int v26; // er10
float v27; // xmm1_4
float v28; // xmm1_4
int v29; // er12
int v30; // ebp
unsigned int v31; // er13
unsigned int v32; // er14
int v33; // ebx
unsigned int v34; // eax
float v35; // xmm3_4
float v36; // xmm4_4
float v37; // xmm2_4
int v38; // edx
float v39; // xmm1_4
float v40; // xmm0_4
float v41; // xmm2_4
double v42; // xmm1_8
float v43; // xmm0_4
float v44; // xmm0_4
float v45; // xmm3_4
float v46; // xmm6_4
float v47; // xmm5_4
char *v48; // rax
unsigned int v49; // er8
unsigned int v50; // edi
unsigned int v51; // esi
int v52; // er9
float v53; // xmm4_4
float *v54; // rcx
float v55; // xmm10_4
float *v56; // r13
float v57; // xmm2_4
float *v58; // rdx
int v59; // edx
float *v60; // r13
float v61; // xmm1_4
float *v62; // rcx
unsigned int v63; // er13
unsigned int v64; // edx
float *v65; // r14
float v66; // xmm1_4
float *v67; // rcx
unsigned int v68; // er13
unsigned int v69; // edx
float *v70; // r14
float v71; // xmm1_4
float *v72; // rcx
unsigned int v73; // eax
float v74; // xmm1_4
float *v75; // rcx
float v76; // xmm2_4
unsigned int v77; // eax
int v79; // [rsp+Ch] [rbp-BCh]
unsigned int v80; // [rsp+10h] [rbp-B8h]
unsigned int v81; // [rsp+14h] [rbp-B4h]
double v82; // [rsp+18h] [rbp-B0h]
int v83; // [rsp+18h] [rbp-B0h]
unsigned int v84; // [rsp+20h] [rbp-A8h]
float v85; // [rsp+24h] [rbp-A4h]
int v86; // [rsp+28h] [rbp-A0h]
int v87; // [rsp+2Ch] [rbp-9Ch]
int v88; // [rsp+30h] [rbp-98h]
unsigned int v89; // [rsp+34h] [rbp-94h]
unsigned int v90; // [rsp+38h] [rbp-90h]
int v91; // [rsp+3Ch] [rbp-8Ch]
unsigned int v92; // [rsp+40h] [rbp-88h]
unsigned int v93; // [rsp+44h] [rbp-84h]
unsigned int v94; // [rsp+48h] [rbp-80h]
unsigned int v95; // [rsp+4Ch] [rbp-7Ch]
int v96; // [rsp+50h] [rbp-78h]
unsigned int v97; // [rsp+5Ch] [rbp-6Ch]
double cosx; // [rsp+80h] [rbp-48h] BYREF
double sinx[8]; // [rsp+88h] [rbp-40h] BYREF

memset(s, 0, mat_size);
v6 = num_var;
if ( num_var )
{
v7 = 0;
v8 = 0;
do
{
*((_DWORD *)s + v7) = LC0;
++v8;
v7 += v6 + 1;
}
while ( v8 != v6 );
}
remmean(mu_X, a3, a5);
whiten(qword_C98, &qword_CC8, &qword_CE0, a3, 0LL);
t = (__int64)cm_mat;
v9 = num_var;
v10 = 0;
if ( num_var )
{
while ( 1 )
{
if ( *(_DWORD *)(a5 + 12) )
{
v28 = *(float *)&scale;
v13 = 0;
v12 = 0;
do
{
if ( *(_DWORD *)(a5 + 8) )
{
v11 = 0;
do
{
*(float *)(qword_CB0 + 4LL * (v11 + v13)) = (float)((float)(*(float *)(qword_C98[0] + 4LL * (v10 + v13))
* *(float *)(qword_C98[0] + 4LL * (v10 + v13)))
* v28)
* *(float *)(qword_C98[0] + 4LL * (v11 + v13));
++v11;
}
while ( *(_DWORD *)(a5 + 8) > v11 );
}
++v12;
v13 += v9;
}
while ( *(_DWORD *)(a5 + 12) > v12 );
}
sgemm_(
&not_transpose,
&transpose,
&dword_CB8,
dword_CA0,
&dword_CBC,
&alpha,
qword_CB0,
&dword_CC0,
qword_C98[0],
dword_CA8,
&beta,
t,
&dword_C90);
v14 = num_var;
if ( !num_var )
break;
v15 = num_var + 1;
v16 = 0;
v17 = 0;
do
{
v19 = (float *)(t + 4LL * v16);
if ( v17 == v10 )
v18 = *v19 - 3.0;
else
v18 = *v19 - 1.0;
*v19 = v18;
++v17;
v16 += v15;
}
while ( v17 != v14 );
t += 4LL * (unsigned int)num_elem;
if ( v10 )
goto LABEL_18;
LABEL_27:
++v10;
v9 = num_var;
if ( num_var <= v10 )
goto LABEL_5;
}
t += 4LL * (unsigned int)num_elem;
if ( !v10 )
{
v9 = 0;
goto LABEL_5;
}
LABEL_18:
for ( i = 0; i < v10; ++i )
{
if ( *(_DWORD *)(a5 + 12) )
{
v26 = num_var;
v27 = *(float *)&scale;
v23 = 0;
v22 = 0;
do
{
if ( *(_DWORD *)(a5 + 8) )
{
v21 = 0;
do
{
*(float *)(qword_CB0 + 4LL * (v21 + v23)) = (float)((float)(*(float *)(qword_C98[0] + 4LL * (v10 + v23))
* *(float *)(qword_C98[0] + 4LL * (i + v23)))
* v27)
* *(float *)(qword_C98[0] + 4LL * (v21 + v23));
++v21;
}
while ( *(_DWORD *)(a5 + 8) > v21 );
}
++v22;
v23 += v26;
}
while ( *(_DWORD *)(a5 + 12) > v22 );
}
sgemm_(
&not_transpose,
&transpose,
&dword_CB8,
dword_CA0,
&dword_CBC,
&alpha,
qword_CB0,
&dword_CC0,
qword_C98[0],
dword_CA8,
&beta,
t,
&dword_C90);
v24 = num_var;
*(float *)(t + 4LL * (v10 * num_var + i)) = *(float *)(t + 4LL * (v10 * num_var + i)) - 1.0;
v25 = (float *)(t + 4LL * (i * v24 + v10));
*v25 = *v25 - 1.0;
t += 4LL * (unsigned int)num_elem;
}
goto LABEL_27;
}
LABEL_5:
v97 = 0;
do
{
++v97;
if ( v9 == 1 )
break;
v90 = v9 + 1;
v96 = -v9;
v93 = v9;
v92 = v9;
v87 = 0;
v91 = 0;
v81 = 0;
v86 = 0;
do
{
v84 = v81;
v77 = v81 + 1;
v81 = v77;
if ( v77 < v9 )
{
v89 = v93 - v9;
v30 = v92 - v91;
v31 = v9 + 1;
v32 = v9;
v88 = v96;
v80 = v77;
v79 = 1;
v29 = 1;
do
{
v33 = num_cm;
if ( num_cm )
{
v34 = v93 - v9;
v35 = 0.0;
v36 = 0.0;
v37 = 0.0;
v38 = 0;
do
{
v39 = *((float *)cm_mat + v34) - *((float *)cm_mat + v34 + v31);
v40 = *((float *)cm_mat + v34 + v32) + *((float *)cm_mat + v34 + v32);
v37 = v37 + (float)(v39 * v39);
v35 = v35 + (float)(v39 * v40);
v36 = v36 + (float)(v40 * v40);
++v38;
v34 += num_elem;
}
while ( v38 != num_cm );
v41 = v37 - v36;
v85 = v35 + v35;
v82 = v41;
v42 = (float)((float)(v41 * v41) + (float)((float)(v35 + v35) * (float)(v35 + v35)));
if ( v42 < 0.0 )
{
sqrt(v42);
goto LABEL_37;
}
}
else
{
v85 = 0.0;
v42 = 0.0;
v82 = 0.0;
}
v42 = sqrt(v42);
LABEL_37:
v43 = atan2(v85, v42 + v82) * 0.5;
if ( COERCE_FLOAT(LODWORD(v43) & LC7) > *(float *)&threshold )
{
sincos(v43, sinx, &cosx);
v44 = cosx;
v45 = sinx[0];
if ( v33 )
{
v83 = num_elem;
v46 = v44 * v44;
v47 = v45 * v45;
v48 = (char *)cm_mat;
v49 = v89 + v32;
v50 = v89 + v31;
v51 = v93 - v9;
v52 = 0;
LODWORD(v53) = LODWORD(v45) ^ LC8;
v94 = v31;
v95 = v32;
do
{
v54 = (float *)&v48[4 * v88 + 4 * v89 + 4 * v49];
v55 = *v54;
v56 = (float *)&v48[4 * v49];
v57 = *v56 * ((v44 + v44) * v45);
v58 = (float *)&v48[4 * v49 + 4 * v79];
*v56 = (float)((float)(*v58 - *v54) * (float)(v44 * v45))
+ (float)(*v56 * (float)((float)(v44 * v44) - (float)(v45 * v45)));
*v54 = (float)((float)(v47 * *v58) + (float)(v46 * v55)) + v57;
*v58 = (float)((float)(v46 * *v58) + (float)(v55 * v47)) - v57;
if ( v84 )
{
v59 = v51 + v87;
do
{
v60 = (float *)&v48[4 * v59];
v61 = *v60;
v62 = (float *)&v48[4 * (v59 + v30)];
*v60 = (float)(v45 * *v62) + (float)(*v60 * v44);
*v62 = (float)(v61 * v53) + (float)(v44 * *v62);
++v59;
}
while ( v59 != v51 );
}
if ( v81 < v80 )
{
v63 = v93 + v88 + v49;
v64 = v49 + 1;
do
{
v65 = (float *)&v48[4 * v63];
v66 = *v65;
v67 = (float *)&v48[4 * v64];
*v65 = (float)(v45 * *v67) + (float)(*v65 * v44);
*v67 = (float)(v66 * v53) + (float)(v44 * *v67);
v63 += v9;
++v64;
}
while ( v50 != v64 );
}
v68 = v80 + 1;
if ( v80 + 1 < v9 )
{
v69 = v49 + v92 - v91;
do
{
v70 = (float *)&v48[4 * v69];
v71 = *v70;
v72 = (float *)&v48[4 * v69 + 4 * v29];
*v70 = (float)(v45 * *v72) + (float)(*v70 * v44);
*v72 = (float)(v71 * v53) + (float)(v44 * *v72);
++v68;
v69 += v9;
}
while ( v68 != v9 );
}
++v52;
v49 += v83;
v50 += v83;
v51 += v83;
}
while ( v52 != v33 );
v31 = v94;
v32 = v95;
}
if ( !v9 )
{
v86 = 1;
break;
}
v73 = v91;
do
{
v74 = *((float *)s + v73);
v75 = (float *)((char *)s + 4 * v73 + 4 * v30);
v76 = *v75;
*v75 = (float)(*v75 * v44) - (float)(v74 * v45);
*((float *)s + v73++) = (float)(v74 * v44) + (float)(v76 * v45);
}
while ( v73 != v92 );
v86 = 1;
}
++v80;
++v29;
v30 += v9;
v88 -= v9;
++v79;
v31 += v90;
v32 += v9;
}
while ( v80 < v9 );
}
v91 += v9;
v92 += v9;
v93 += v90;
--v87;
v96 += ~v9;
}
while ( v81 != v9 - 1 );
}
while ( v97 <= 0x63 && v86 );
sgemm_(
&transpose,
&not_transpose,
&unk_D04,
dword_CA4,
&unk_D00,
&alpha,
s,
&unk_D08,
qword_C98[0],
dword_CA8,
&beta,
*a3,
a3 + 2);
sgemm_(
&transpose,
&not_transpose,
&unk_D04,
&unk_CD4,
&unk_D00,
&alpha,
s,
&unk_D08,
qword_CC8,
&unk_CD8,
&beta,
*a1,
a1 + 2);
sgemm_(
&not_transpose,
&not_transpose,
&unk_CE8,
&unk_D04,
&unk_CEC,
&alpha,
qword_CE0,
&unk_CF0,
s,
&unk_D08,
&beta,
*a2,
a2 + 2);
sgemv_(&not_transpose, a1 + 1, (char *)a1 + 12, &alpha, *a1, a1 + 2, mu_X, &one, &beta, a4, &one);
return v97;
}

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; // eax
bool v2; // zf
void *v3; // rax
__int64 v4; // r12
unsigned int v5; // ebx
__int64 i; // rbx
int v7; // eax

epsilon = a1[1];
max_iter = a1[3];
v1 = a1[2];
if ( v1 == 1 )
{
contrast = (__int64)&negent_cube;
}
else
{
v2 = v1 == 2;
v3 = &negent_gauss;
if ( !v2 )
v3 = &negent_tanh;
contrast = (__int64)v3;
}
v4 = (unsigned int)a1[4];
eig_vals = malloc(4 * v4);
v5 = a1[5];
white_Z = malloc(4 * v4 * v5);
dword_904 = v5;
dword_8FC = v5;
dword_900 = a1[4];
dword_8F8 = dword_900;
for ( i = 0LL; i != 30; i += 6LL )
{
*(void **)((char *)&dest + i * 4) = malloc(4 * (unsigned int)a1[4] * (unsigned __int64)(unsigned int)a1[4]);
v7 = a1[4];
dword_88C[i] = v7;
dword_888[i] = v7;
dword_884[i] = v7;
dword_880[i] = v7;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
int v1; // eax
bool v2; // zf
void *v3; // rax
__int64 v4; // r12
unsigned int v5; // ebx
__int64 i; // rbx
int v7; // eax

epsilon = a1[1];
max_iter = a1[3];
v1 = a1[2];
if ( v1 == 1 )
{
contrast = (__int64)&negent_cube;
}
else
{
v2 = v1 == 2;
v3 = &negent_gauss;
if ( !v2 )
v3 = &negent_tanh;
contrast = (__int64)v3;
}
v4 = (unsigned int)a1[4];
eig_vals = malloc(4 * v4);
v5 = a1[5];
white_Z = malloc(4 * v4 * v5);
dword_904 = v5;
dword_8FC = v5;
dword_900 = a1[4];
dword_8F8 = dword_900;
for ( i = 0LL; i != 30; i += 6LL )
{
*(void **)((char *)&dest + i * 4) = malloc(4 * (unsigned int)a1[4] * (unsigned __int64)(unsigned int)a1[4]);
v7 = a1[4];
dword_88C[i] = v7;
dword_888[i] = v7;
dword_884[i] = v7;
dword_880[i] = v7;
}
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 i; // rbx

free(eig_vals);
eig_vals = 0LL;
free(white_Z);
white_Z = 0LL;
dword_900 = 0;
dword_8F8 = 0;
dword_904 = 0;
dword_8FC = 0;
for ( i = 0LL; i != 30; i += 6LL )
{
free(*(void **)((char *)&dest + i * 4));
*(void **)((char *)&dest + i * 4) = 0LL;
dword_88C[i] = 0;
dword_888[i] = 0;
dword_884[i] = 0;
dword_880[i] = 0;
}
contrast = 0LL;
epsilon = 0;
max_iter = 0;
}

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

free(eig_vals);
eig_vals = 0LL;
free(white_Z);
white_Z = 0LL;
dword_900 = 0;
dword_8F8 = 0;
dword_904 = 0;
dword_8FC = 0;
for ( i = 0LL; i != 30; i += 6LL )
{
free(*(void **)((char *)&dest + i * 4));
*(void **)((char *)&dest + i * 4) = 0LL;
dword_88C[i] = 0;
dword_888[i] = 0;
dword_884[i] = 0;
dword_880[i] = 0;
}
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:
void __fastcall conv_mirrorUp(float *a1, __int64 a2, unsigned int a3, __int64 a4, unsigned int a5)
{
__int64 v6; // rdx
float v7; // xmm1_4
float *v8; // r11
unsigned int v9; // er14
unsigned int v10; // ebp
unsigned int i; // er9
unsigned int v12; // eax
unsigned int v13; // edi
unsigned int v14; // edx
float v15; // xmm1_4
float v16; // xmm2_4
unsigned int v17; // eax
unsigned int v18; // edx
unsigned int v19; // er11
__int64 v20; // rax
unsigned int v21; // edx
float *v22; // r9
unsigned int v23; // er12
__int64 v24; // rax
float v25; // xmm1_4
float v26; // xmm2_4
unsigned int v27; // eax
unsigned int v28; // er14
unsigned int v29; // ebx
int v30; // eax
unsigned int v31; // er11
unsigned int v32; // er10
float *v33; // rbx
__int64 v34; // r15
int v35; // ebp
float v36; // xmm2_4
float v37; // xmm1_4
unsigned int v38; // eax
float *v39; // rdx
float *v40; // r8
unsigned int v41; // eax
unsigned int v42; // er9
float *v43; // rdx
unsigned int v44; // eax
unsigned int v45; // edi
float *v46; // rax
unsigned __int64 v47; // rdi
unsigned int v48; // edx
float v49; // xmm1_4
unsigned int v50; // [rsp+0h] [rbp-54h]
float *v51; // [rsp+4h] [rbp-50h]
float *v52; // [rsp+Ch] [rbp-48h]
unsigned int v53; // [rsp+18h] [rbp-3Ch]
char v54; // [rsp+20h] [rbp-34h]

if ( a5 <= 1 )
{
v7 = 0.0;
}
else
{
v6 = 1LL;
v7 = 0.0;
do
{
v7 = v7 + (float)(*(float *)(a2 + 4LL * ((unsigned int)(v6 - 1) >> 1)) * *(float *)(a4 + 4 * v6));
v6 += 2LL;
}
while ( a5 > (unsigned int)v6 );
}
v8 = a1 + 1;
v51 = a1 + 1;
*a1 = v7;
v9 = a5 - 1;
v10 = (a5 - 1) >> 1;
if ( a5 - 1 <= 1 )
{
v19 = 0;
}
else
{
for ( i = 0; ; ++i )
{
v13 = 2 * i;
v14 = 0;
v15 = 0.0;
v16 = 0.0;
do
{
v15 = v15 + (float)(*(float *)(a2 + 4LL * v14) * *(float *)(a4 + 4LL * v13));
v16 = v16 + (float)(*(float *)(a2 + 4LL * v14++) * *(float *)(a4 + 4LL * (v13 + 1)));
v13 -= 2;
}
while ( v14 <= i );
if ( i + 1 >= a5 >> 1 )
{
v12 = i + 1;
}
else
{
v17 = 2 * i + 2;
v18 = 0;
do
{
v15 = v15 + (float)(*(float *)(a2 + 4LL * v18) * *(float *)(a4 + 4LL * v17));
v16 = v16 + (float)(*(float *)(a2 + 4LL * v18++) * *(float *)(a4 + 4LL * (v17 + 1)));
v17 += 2;
}
while ( v17 != (a5 & 0xFFFFFFFE) );
v12 = a5 >> 1;
}
if ( (a5 & 1) != 0 )
v15 = v15 + (float)(*(float *)(a2 + 4LL * (~i + v12)) * *(float *)(a4 + 8LL * v12));
*v8 = v15;
v8 += 2;
*(v8 - 1) = v16;
if ( i + 1 >= v10 )
break;
}
v19 = 1;
if ( v9 > 1 )
v19 = (a5 - 1) >> 1;
v20 = 8LL * (v10 - 1) + 8;
if ( v9 <= 1 )
v20 = 8LL;
v51 = (float *)((char *)v51 + v20);
}
if ( a3 <= v19 )
{
v23 = v19;
}
else
{
v21 = v19;
v22 = v51;
while ( 1 )
{
v24 = 0LL;
v25 = 0.0;
v26 = 0.0;
if ( a5 <= 1 )
{
v27 = 0;
}
else
{
do
{
v26 = v26 + (float)(*(float *)(a2 + 4LL * (v21 - (unsigned int)v24)) * *(float *)(a4 + 8 * v24));
v25 = v25 + (float)(*(float *)(a2 + 4LL * (v21 - (unsigned int)v24)) * *(float *)(a4 + 8 * v24 + 4));
++v24;
}
while ( a5 >> 1 > (unsigned int)v24 );
v27 = a5 >> 1;
}
if ( (a5 & 1) != 0 )
v26 = v26 + (float)(*(float *)(a2 + 4LL * (v21 - v27)) * *(float *)(a4 + 8LL * v27));
*v22 = v26;
v22 += 2;
*(v22 - 1) = v25;
v23 = v21 + 1;
if ( a3 == v21 + 1 )
break;
++v21;
}
v51 += 2 * (v21 - v19) + 2;
}
v28 = a3 - 1;
v29 = (a5 >> 1) + a3 - 1;
v53 = v29;
if ( v29 <= v23 )
{
v53 = v23;
}
else
{
v30 = 2 * a3 - 2;
v52 = (float *)(a4 + 4LL * (a5 & 0xFFFFFFFE));
v31 = v23 - (a5 >> 1) + 1;
v32 = v23 - v30;
v50 = v29 - v30;
v33 = v51;
v34 = a2 + 4;
v35 = a5 & 1;
v54 = a5;
do
{
v38 = -v32;
if ( a3 <= -v32 )
{
v36 = 0.0;
v37 = 0.0;
}
else
{
v39 = (float *)(a2 + 4LL * v38);
v40 = (float *)(v34 + 4 * (v28 + v32 + (unsigned __int64)v38));
v41 = 0;
v36 = 0.0;
v37 = 0.0;
do
{
v37 = v37 + (float)(*v39 * *(float *)(a4 + 4LL * v41));
v36 = v36 + (float)(*v39++ * *(float *)(a4 + 4LL * (v41 + 1)));
v41 += 2;
}
while ( v39 != v40 );
}
v42 = v31 - 1;
if ( v28 > v31 )
{
v43 = (float *)(a2 + 4LL * v31);
v44 = 2 * (v32 + 2 * a3 - 3 - v42);
do
{
v37 = v37 + (float)(*v43 * *(float *)(a4 + 4LL * v44));
v36 = v36 + (float)(*v43++ * *(float *)(a4 + 4LL * (v44 + 1)));
v44 -= 2;
}
while ( v43 != (float *)(v34 + 4 * (v31 + (unsigned __int64)(a3 - 2 - v31))) );
}
if ( v35 )
v37 = v37 + (float)(*(float *)(a2 + 4LL * v42) * *v52);
*v33 = v37;
v33 += 2;
*(v33 - 1) = v36;
++v31;
++v32;
}
while ( v32 != v50 );
LOBYTE(a5) = v54;
v51 += 2 * (v53 - 1 - v23) + 2;
}
if ( (a5 & 1) != 0 )
{
v45 = 2 * a3 - 2 - v53;
if ( a3 <= v45 )
{
v49 = 0.0;
}
else
{
v46 = (float *)(a2 + 4LL * v45);
v47 = a2 + 4 * (v28 + v53 - (2 * a3 - 2) + (unsigned __int64)v45) + 4;
v48 = 0;
v49 = 0.0;
do
{
v49 = v49 + (float)(*(float *)(a4 + 4LL * v48) * *v46++);
v48 += 2;
}
while ( (float *)v47 != v46 );
}
*v51 = v49;
}
}

canonical_decompiled_code:
void __fastcall func1(float *a1, __int64 a2, unsigned int a3, __int64 a4, unsigned int a5)
{
__int64 v6; // rdx
float v7; // xmm1_4
float *v8; // r11
unsigned int v9; // er14
unsigned int v10; // ebp
unsigned int i; // er9
unsigned int v12; // eax
unsigned int v13; // edi
unsigned int v14; // edx
float v15; // xmm1_4
float v16; // xmm2_4
unsigned int v17; // eax
unsigned int v18; // edx
unsigned int v19; // er11
__int64 v20; // rax
unsigned int v21; // edx
float *v22; // r9
unsigned int v23; // er12
__int64 v24; // rax
float v25; // xmm1_4
float v26; // xmm2_4
unsigned int v27; // eax
unsigned int v28; // er14
unsigned int v29; // ebx
int v30; // eax
unsigned int v31; // er11
unsigned int v32; // er10
float *v33; // rbx
__int64 v34; // r15
int v35; // ebp
float v36; // xmm2_4
float v37; // xmm1_4
unsigned int v38; // eax
float *v39; // rdx
float *v40; // r8
unsigned int v41; // eax
unsigned int v42; // er9
float *v43; // rdx
unsigned int v44; // eax
unsigned int v45; // edi
float *v46; // rax
unsigned __int64 v47; // rdi
unsigned int v48; // edx
float v49; // xmm1_4
unsigned int v50; // [rsp+0h] [rbp-54h]
float *v51; // [rsp+4h] [rbp-50h]
float *v52; // [rsp+Ch] [rbp-48h]
unsigned int v53; // [rsp+18h] [rbp-3Ch]
char v54; // [rsp+20h] [rbp-34h]

if ( a5 <= 1 )
{
v7 = 0.0;
}
else
{
v6 = 1LL;
v7 = 0.0;
do
{
v7 = v7 + (float)(*(float *)(a2 + 4LL * ((unsigned int)(v6 - 1) >> 1)) * *(float *)(a4 + 4 * v6));
v6 += 2LL;
}
while ( a5 > (unsigned int)v6 );
}
v8 = a1 + 1;
v51 = a1 + 1;
*a1 = v7;
v9 = a5 - 1;
v10 = (a5 - 1) >> 1;
if ( a5 - 1 <= 1 )
{
v19 = 0;
}
else
{
for ( i = 0; ; ++i )
{
v13 = 2 * i;
v14 = 0;
v15 = 0.0;
v16 = 0.0;
do
{
v15 = v15 + (float)(*(float *)(a2 + 4LL * v14) * *(float *)(a4 + 4LL * v13));
v16 = v16 + (float)(*(float *)(a2 + 4LL * v14++) * *(float *)(a4 + 4LL * (v13 + 1)));
v13 -= 2;
}
while ( v14 <= i );
if ( i + 1 >= a5 >> 1 )
{
v12 = i + 1;
}
else
{
v17 = 2 * i + 2;
v18 = 0;
do
{
v15 = v15 + (float)(*(float *)(a2 + 4LL * v18) * *(float *)(a4 + 4LL * v17));
v16 = v16 + (float)(*(float *)(a2 + 4LL * v18++) * *(float *)(a4 + 4LL * (v17 + 1)));
v17 += 2;
}
while ( v17 != (a5 & 0xFFFFFFFE) );
v12 = a5 >> 1;
}
if ( (a5 & 1) != 0 )
v15 = v15 + (float)(*(float *)(a2 + 4LL * (~i + v12)) * *(float *)(a4 + 8LL * v12));
*v8 = v15;
v8 += 2;
*(v8 - 1) = v16;
if ( i + 1 >= v10 )
break;
}
v19 = 1;
if ( v9 > 1 )
v19 = (a5 - 1) >> 1;
v20 = 8LL * (v10 - 1) + 8;
if ( v9 <= 1 )
v20 = 8LL;
v51 = (float *)((char *)v51 + v20);
}
if ( a3 <= v19 )
{
v23 = v19;
}
else
{
v21 = v19;
v22 = v51;
while ( 1 )
{
v24 = 0LL;
v25 = 0.0;
v26 = 0.0;
if ( a5 <= 1 )
{
v27 = 0;
}
else
{
do
{
v26 = v26 + (float)(*(float *)(a2 + 4LL * (v21 - (unsigned int)v24)) * *(float *)(a4 + 8 * v24));
v25 = v25 + (float)(*(float *)(a2 + 4LL * (v21 - (unsigned int)v24)) * *(float *)(a4 + 8 * v24 + 4));
++v24;
}
while ( a5 >> 1 > (unsigned int)v24 );
v27 = a5 >> 1;
}
if ( (a5 & 1) != 0 )
v26 = v26 + (float)(*(float *)(a2 + 4LL * (v21 - v27)) * *(float *)(a4 + 8LL * v27));
*v22 = v26;
v22 += 2;
*(v22 - 1) = v25;
v23 = v21 + 1;
if ( a3 == v21 + 1 )
break;
++v21;
}
v51 += 2 * (v21 - v19) + 2;
}
v28 = a3 - 1;
v29 = (a5 >> 1) + a3 - 1;
v53 = v29;
if ( v29 <= v23 )
{
v53 = v23;
}
else
{
v30 = 2 * a3 - 2;
v52 = (float *)(a4 + 4LL * (a5 & 0xFFFFFFFE));
v31 = v23 - (a5 >> 1) + 1;
v32 = v23 - v30;
v50 = v29 - v30;
v33 = v51;
v34 = a2 + 4;
v35 = a5 & 1;
v54 = a5;
do
{
v38 = -v32;
if ( a3 <= -v32 )
{
v36 = 0.0;
v37 = 0.0;
}
else
{
v39 = (float *)(a2 + 4LL * v38);
v40 = (float *)(v34 + 4 * (v28 + v32 + (unsigned __int64)v38));
v41 = 0;
v36 = 0.0;
v37 = 0.0;
do
{
v37 = v37 + (float)(*v39 * *(float *)(a4 + 4LL * v41));
v36 = v36 + (float)(*v39++ * *(float *)(a4 + 4LL * (v41 + 1)));
v41 += 2;
}
while ( v39 != v40 );
}
v42 = v31 - 1;
if ( v28 > v31 )
{
v43 = (float *)(a2 + 4LL * v31);
v44 = 2 * (v32 + 2 * a3 - 3 - v42);
do
{
v37 = v37 + (float)(*v43 * *(float *)(a4 + 4LL * v44));
v36 = v36 + (float)(*v43++ * *(float *)(a4 + 4LL * (v44 + 1)));
v44 -= 2;
}
while ( v43 != (float *)(v34 + 4 * (v31 + (unsigned __int64)(a3 - 2 - v31))) );
}
if ( v35 )
v37 = v37 + (float)(*(float *)(a2 + 4LL * v42) * *v52);
*v33 = v37;
v33 += 2;
*(v33 - 1) = v36;
++v31;
++v32;
}
while ( v32 != v50 );
LOBYTE(a5) = v54;
v51 += 2 * (v53 - 1 - v23) + 2;
}
if ( (a5 & 1) != 0 )
{
v45 = 2 * a3 - 2 - v53;
if ( a3 <= v45 )
{
v49 = 0.0;
}
else
{
v46 = (float *)(a2 + 4LL * v45);
v47 = a2 + 4 * (v28 + v53 - (2 * a3 - 2) + (unsigned __int64)v45) + 4;
v48 = 0;
v49 = 0.0;
do
{
v49 = v49 + (float)(*(float *)(a4 + 4LL * v48) * *v46++);
v48 += 2;
}
while ( (float *)v47 != v46 );
}
*v51 = v49;
}
}

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
unsigned int v5; // ecx
char *v6; // rax
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

v1 = *(_DWORD *)(a1 + 4112);
v8 = v1;
v2 = *(unsigned int *)(a1 + 4116);
v9 = *(_DWORD *)(a1 + 4116);
v3 = *(unsigned int *)(a1 + 4120);
v10 = *(_DWORD *)(a1 + 4120);
v4 = *(unsigned int *)(a1 + 4124);
v11 = *(_DWORD *)(a1 + 4124);
v5 = num_headbox_types;
v6 = (char *)&v8;
do
{
if ( *(_DWORD *)v6 >= v5 )
*(_DWORD *)v6 = 0;
v6 += 4;
}
while ( v6 != &v12 );
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
unsigned int v5; // ecx
char *v6; // rax
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

v1 = *(_DWORD *)(a1 + 4112);
v8 = v1;
v2 = *(unsigned int *)(a1 + 4116);
v9 = *(_DWORD *)(a1 + 4116);
v3 = *(unsigned int *)(a1 + 4120);
v10 = *(_DWORD *)(a1 + 4120);
v4 = *(unsigned int *)(a1 + 4124);
v11 = *(_DWORD *)(a1 + 4124);
v5 = num_headbox_types;
v6 = (char *)&v8;
do
{
if ( *(_DWORD *)v6 >= v5 )
*(_DWORD *)v6 = 0;
v6 += 4;
}
while ( v6 != &v12 );
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
unsigned int v5; // ecx
char *v6; // rax
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

v1 = *(_DWORD *)(a1 + 4112);
v8 = v1;
v2 = *(unsigned int *)(a1 + 4116);
v9 = *(_DWORD *)(a1 + 4116);
v3 = *(unsigned int *)(a1 + 4120);
v10 = *(_DWORD *)(a1 + 4120);
v4 = *(unsigned int *)(a1 + 4124);
v11 = *(_DWORD *)(a1 + 4124);
v5 = num_headbox_types;
v6 = (char *)&v8;
do
{
if ( *(_DWORD *)v6 >= v5 )
*(_DWORD *)v6 = 0;
v6 += 4;
}
while ( v6 != &v12 );
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
unsigned int v5; // ecx
char *v6; // rax
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

v1 = *(_DWORD *)(a1 + 4112);
v8 = v1;
v2 = *(unsigned int *)(a1 + 4116);
v9 = *(_DWORD *)(a1 + 4116);
v3 = *(unsigned int *)(a1 + 4120);
v10 = *(_DWORD *)(a1 + 4120);
v4 = *(unsigned int *)(a1 + 4124);
v11 = *(_DWORD *)(a1 + 4124);
v5 = num_headbox_types;
v6 = (char *)&v8;
do
{
if ( *(_DWORD *)v6 >= v5 )
*(_DWORD *)v6 = 0;
v6 += 4;
}
while ( v6 != &v12 );
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; }


original_code:
double xltek_convertSample( int sample, int headbox_type, int channel,
                            int discard_bits, const char *sw_version )
{
  static double const conv_8711 = 8711.0 / (2097152.0 - 0.5);
  static double const conv_5e7 = (5000000.0 / (1024.0 - 0.5)) / 64.0;
  static double const conv_2neg6 = 1.0 / 64.0;
  static double const conv_hyppo = (8711.0/(2097152.0-0.5))/(159.8/249.5);
  static double const conv_1e8 = (10000000.0 / (1024.0 - 0.5)) / 64.0;
  static double const conv_2e8 = (20000000.0 / 65536.0);
  static double const conv_108e6 = (10800000.0 / 65536.0) / 64.0;
  double as_doub;
  double two_power = pow(2.0, (double) discard_bits);
  switch (headbox_type) {
    case 1: as_doub = (double) sample * conv_8711 * two_power;
              break;
    case 3: as_doub = (double) sample * conv_8711 * two_power;
              break;
    case 4: if (channel <= 23) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_5e7 * two_power;
              }
              break;
    case 5: if (channel <= 25) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 31) {
                as_doub = (double) sample * conv_hyppo * two_power;
              } else if (channel <= 39 && atof(sw_version) < 3.4) {
                as_doub = (double) sample * conv_1e8 * two_power;
              } else if (channel <= 39 && atof(sw_version)) {
                as_doub = (double) sample * conv_2e8 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 6: if (channel <= 31) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_5e7 * two_power;
              }
              break;
    case 8: if (channel <= 24) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 9: if (channel <= 32) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 14: if (channel <= 37) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 47) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 15: if (channel <= 27) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 31) {
                as_doub = (double) sample * conv_1e8 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 17: if (channel <= 39) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 43) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 19: as_doub = (double) sample * conv_8711 * two_power;
              break;
    case 21: if (channel <= 127) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 22: if (channel <= 31) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 39) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else if (channel <= 41) {
                as_doub = (double) sample * conv_2neg6 * two_power;
              } else {
                as_doub = (double) sample * conv_108e6 * two_power;
              }
              break;
    case 23: if (channel <= 31) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 35) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else if (channel <= 37) {
                as_doub = (double) sample * conv_2neg6 * two_power;
              } else {
                as_doub = (double) sample * conv_108e6 * two_power;
              }
              break;
    default:
      fprintf( stderr, "Unknown headbox type (%d)!\n", headbox_type );
      as_doub = 0.0;
  }
  return as_doub;
}

canonical_original_code:
double xltek_convertSample(int sample, int headbox_type, int channel, int discard_bits, char *sw_version)
{
  static double conv_8711 = 8711.0 / (2097152.0 - 0.5);
  static double conv_5e7 = (5000000.0 / (1024.0 - 0.5)) / 64.0;
  static double conv_2neg6 = 1.0 / 64.0;
  static double conv_hyppo = (8711.0/(2097152.0-0.5))/(159.8/249.5);
  static double conv_1e8 = (10000000.0 / (1024.0 - 0.5)) / 64.0;
  static double conv_2e8 = (20000000.0 / 65536.0);
  static double conv_108e6 = (10800000.0 / 65536.0) / 64.0;
  double as_doub;
  double two_power = pow(2.0, (double) discard_bits);
  switch (headbox_type) {
    case 1: as_doub = (double) sample * conv_8711 * two_power;
              break;
    case 3: as_doub = (double) sample * conv_8711 * two_power;
              break;
    case 4: if (channel <= 23) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_5e7 * two_power;
              }
              break;
    case 5: if (channel <= 25) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 31) {
                as_doub = (double) sample * conv_hyppo * two_power;
              } else if (channel <= 39 && atof(sw_version) < 3.4) {
                as_doub = (double) sample * conv_1e8 * two_power;
              } else if (channel <= 39 && atof(sw_version)) {
                as_doub = (double) sample * conv_2e8 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 6: if (channel <= 31) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_5e7 * two_power;
              }
              break;
    case 8: if (channel <= 24) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 9: if (channel <= 32) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 14: if (channel <= 37) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 47) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 15: if (channel <= 27) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 31) {
                as_doub = (double) sample * conv_1e8 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 17: if (channel <= 39) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 43) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 19: as_doub = (double) sample * conv_8711 * two_power;
              break;
    case 21: if (channel <= 127) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 22: if (channel <= 31) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 39) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else if (channel <= 41) {
                as_doub = (double) sample * conv_2neg6 * two_power;
              } else {
                as_doub = (double) sample * conv_108e6 * two_power;
              }
              break;
    case 23: if (channel <= 31) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 35) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else if (channel <= 37) {
                as_doub = (double) sample * conv_2neg6 * two_power;
              } else {
                as_doub = (double) sample * conv_108e6 * two_power;
              }
              break;
    default:
      fprintf( stderr, "Unknown headbox type (%d)!\n", headbox_type );
      as_doub = 0.0;
  }
  return as_doub;
}

variable_types: sample int

variable_types: channel int

return_type: double