decompiled_code:
__int64 __fastcall qdpack_floquet_dissipation_rates(__int64 a1, __int64 a2, void (__fastcall *a3)(__int64, __int64, _QWORD, double), void (__fastcall *a4)(_QWORD, double))
{
__int64 v6; // rax
char *v7; // rax
char *v8; // r12
__int64 i; // rbp
__int64 v10; // r13
__int64 v11; // r12
_QWORD *v12; // r13
__int64 v13; // rax
bool v14; // zf
double v15; // xmm7_8
int v16; // ebp
__int64 v17; // r12
double v18; // xmm0_8
__int64 v19; // r15
double v20; // xmm0_8
double v21; // xmm0_8
__int64 v22; // r15
double v23; // xmm0_8
double v24; // xmm1_8
double v25; // xmm1_8
double v26; // xmm0_8
__int64 v27; // rdi
bool v28; // cf
int v29; // eax
__int64 j; // r12
__int64 v31; // rbp
double v32; // xmm0_8
__int64 v33; // rdx
__int64 k; // r13
__int64 v35; // r14
int v36; // eax
double v37; // xmm4_8
int v38; // er15
__int64 v39; // rbp
__int64 v40; // r12
double v41; // rbp
double v42; // xmm0_8
__int64 v43; // rdx
double v44; // xmm0_8
double v45; // xmm0_8
double v46; // xmm0_8
double v47; // rbp
double v48; // xmm0_8
double v49; // rbp
double v50; // xmm1_8
double v51; // xmm0_8
__int64 v52; // rbp
int v53; // er12
__int64 v54; // rdi
__int64 result; // rax
__int64 v56; // [rsp+0h] [rbp-A8h]
double v57; // [rsp+0h] [rbp-A8h]
double v58; // [rsp+0h] [rbp-A8h]
double v59; // [rsp+0h] [rbp-A8h]
double v60; // [rsp+0h] [rbp-A8h]
double v61; // [rsp+0h] [rbp-A8h]
double v62; // [rsp+0h] [rbp-A8h]
double v63; // [rsp+0h] [rbp-A8h]
double v64; // [rsp+0h] [rbp-A8h]
double v65; // [rsp+8h] [rbp-A0h]
double v66; // [rsp+8h] [rbp-A0h]
double v67; // [rsp+10h] [rbp-98h]
double v68; // [rsp+18h] [rbp-90h]
double v69; // [rsp+20h] [rbp-88h]
int v70; // [rsp+20h] [rbp-88h]
__int64 v71; // [rsp+28h] [rbp-80h]
double v72; // [rsp+30h] [rbp-78h]
int v73; // [rsp+3Ch] [rbp-6Ch]
__int64 v75; // [rsp+58h] [rbp-50h]
__int64 v76; // [rsp+60h] [rbp-48h]
void (__fastcall *v77)(_QWORD, double); // [rsp+68h] [rbp-40h]

v73 = qdpack_hilbert_space_nstates(a2);
v75 = qdpack_operator_alloc(a2);
v6 = qdpack_operator_alloc(a2);
*(_DWORD *)(a1 + 3232) = 1;
v76 = v6;
*(_QWORD *)(a1 + 3184) = malloc(0x18uLL);
*(_QWORD *)(a1 + 3192) = malloc(0x18uLL);
v7 = (char *)malloc(0x18uLL);
*(_QWORD *)(a1 + 3176) = v7;
if ( v7 )
{
v8 = v7;
for ( i = 0LL; ; ++i )
{
v10 = 8 * i;
*(_QWORD *)&v8[v10] = qdpack_operator_alloc(a2);
qdpack_operator_set_zero(*(_QWORD *)(*(_QWORD *)(a1 + 3176) + 8 * i));
v11 = *(_QWORD *)(a1 + 3192);
*(_QWORD *)(v10 + v11) = qdpack_operator_alloc(a2);
qdpack_operator_set_zero(*(_QWORD *)(*(_QWORD *)(a1 + 3192) + 8 * i));
v12 = (_QWORD *)(*(_QWORD *)(a1 + 3184) + 8 * i);
*v12 = qdpack_operator_alloc(a2);
qdpack_operator_set_zero(*(_QWORD *)(*(_QWORD *)(a1 + 3184) + 8 * i));
if ( *(_DWORD *)(a1 + 3232) < (int)i )
break;
v8 = *(char **)(a1 + 3176);
}
*(_QWORD *)(a1 + 3160) = qdpack_operator_alloc(a2);
*(_QWORD *)(a1 + 3144) = qdpack_operator_alloc(a2);
v13 = qdpack_operator_alloc(a2);
v14 = *(_QWORD *)(a1 + 3216) == 0LL;
*(_QWORD *)(a1 + 3200) = v13;
if ( v14 )
*(_QWORD *)(a1 + 3216) = qdpack_matrix_alloc(v73, v73);
a3(a1, a2, *(_QWORD *)(a1 + 3152), 0.0);
v15 = 6.283185307179586 / *(double *)(a1 + 3096);
v72 = v15 / 100.0;
v69 = v15 / 100.0;
if ( 0.5 * (v15 / 100.0) + v15 >= v15 / 100.0 )
{
v77 = a4;
do
{
qdpack_floquet_modes_t(a1, a2, v69);
a3(a1, a2, *(_QWORD *)(a1 + 3160), v69);
v16 = -*(_DWORD *)(a1 + 3232);
if ( ((*(_DWORD *)(a1 + 3232) & 0x40000000) != 0) == __OFSUB__(*(_DWORD *)(a1 + 3232), v16) )
{
v17 = 0LL;
do
{
v18 = gsl_complex_rect(0.0, 0.0);
v19 = *(_QWORD *)(a1 + 3160);
v68 = v18;
v56 = *(_QWORD *)(a1 + 3208);
v20 = gsl_complex_rect(1.0, 0.0);
qdpack_operator_blas_zgemm(113LL, 111LL, v19, v56, v75, v20, 0.0, v68, 0.0);
v21 = gsl_complex_rect(0.0, 0.0);
v22 = *(_QWORD *)(a1 + 3160);
v65 = v21;
v23 = gsl_complex_rect(1.0, 0.0);
qdpack_operator_blas_zgemm(111LL, 111LL, v75, v22, v76, v23, 0.0, v65, 0.0);
v24 = (double)v16++ * -6.283185307179586;
v25 = v24 * v69 / v15;
v26 = gsl_complex_polar(1.0, v25);
gsl_complex_mul_real(v26, v25, v72 / v15);
qdpack_operator_scale(v76);
v27 = *(_QWORD *)(*(_QWORD *)(a1 + 3176) + v17);
v17 += 8LL;
qdpack_operator_add(v27, v76);
}
while ( *(_DWORD *)(a1 + 3232) >= v16 );
}
v28 = 0.5 * (v15 / 100.0) + v15 < v69 + v72;
v69 = v69 + v72;
}
while ( !v28 );
a4 = v77;
}
v29 = *(_DWORD *)(a1 + 3232);
v71 = 0LL;
v70 = -v29;
if ( ((v29 & 0x40000000) != 0) == __OFSUB__(v29, -v29) )
{
do
{
printf("%s: floquet_X[%d]\n", "qdpack_floquet_dissipation_rates", (unsigned int)v71);
qdpack_operator_print_real(*(_QWORD *)(*(_QWORD *)(a1 + 3176) + 8 * v71));
qdpack_operator_print_imag(*(_QWORD *)(*(_QWORD *)(a1 + 3176) + 8 * v71));
if ( v73 > 0 )
{
for ( j = 0LL; j != v73; ++j )
{
v31 = 0LL;
do
{
v57 = qdpack_matrix_get(*(_QWORD *)(a1 + 3168), j, 0LL);
v58 = v57 - qdpack_matrix_get(*(_QWORD *)(a1 + 3168), v31, 0LL) + 6.283185307179586 * (double)v70 / v15;
qdpack_operator_set(*(_QWORD *)(*(_QWORD *)(a1 + 3192) + 8 * v71), j, v31);
heaviside_function(v58, 0.0);
a4(a1, v58);
v32 = qdpack_operator_get(*(_QWORD *)(*(_QWORD *)(a1 + 3176) + 8 * v71), j, v31);
gsl_complex_abs2(v32);
v33 = v31++;
qdpack_operator_set(*(_QWORD *)(*(_QWORD *)(a1 + 3184) + 8 * v71), j, v33);
}
while ( v73 != v31 );
}
}
printf("%s: floquet_delta[%d]\n", "qdpack_floquet_dissipation_rates", (unsigned int)v71);
qdpack_operator_print_real(*(_QWORD *)(*(_QWORD *)(a1 + 3192) + 8 * v71));
printf("%s: floquet_gamma[%d]\n", "qdpack_floquet_dissipation_rates", (unsigned int)v71);
qdpack_operator_print_real(*(_QWORD *)(*(_QWORD *)(a1 + 3184) + 8 * v71));
++v70;
++v71;
}
while ( *(_DWORD *)(a1 + 3232) >= v70 );
}
if ( v73 > 0 )
{
for ( k = 0LL; k != v73; ++k )
{
v35 = 0LL;
do
{
v36 = *(_DWORD *)(a1 + 3232);
v37 = 0.0;
v38 = -v36;
if ( ((v36 & 0x40000000) != 0) == __OFSUB__(v36, -v36) )
{
do
{
v39 = v38 + v36;
v67 = v37;
v40 = v36 - v38++;
*(_QWORD *)&v66 = COERCE_UNSIGNED_INT64(qdpack_operator_get(*(_QWORD *)(*(_QWORD *)(a1 + 3192) + 8 * v39), k, v35)) & LC14;
v59 = qdpack_operator_get(*(_QWORD *)(*(_QWORD *)(a1 + 3184) + 8 * v39), k, v35);
v41 = qdpack_operator_get(*(_QWORD *)(*(_QWORD *)(a1 + 3184) + 8 * v40), v35, k);
v42 = boltzmann_factor(v66, *(double *)(a1 + 1056));
v36 = *(_DWORD *)(a1 + 3232);
v37 = v67 + (v41 + v59) * v42 + v59;
}
while ( v36 >= v38 );
}
v43 = v35++;
qdpack_operator_set(*(_QWORD *)(a1 + 3200), k, v43);
}
while ( v73 != v35 );
}
}
printf("%s: floquet_A\n", "qdpack_floquet_dissipation_rates");
qdpack_operator_print_real(*(_QWORD *)(a1 + 3200));
v44 = qdpack_operator_get(*(_QWORD *)(a1 + 3200), 0LL, 1LL);
gsl_complex_rect(v44, 0.0);
qdpack_matrix_set(*(_QWORD *)(a1 + 3216), 0LL, 1LL);
v45 = qdpack_operator_get(*(_QWORD *)(a1 + 3200), 1LL, 0LL);
gsl_complex_rect(v45, 0.0);
qdpack_matrix_set(*(_QWORD *)(a1 + 3216), 1LL, 0LL);
v60 = qdpack_operator_get(*(_QWORD *)(a1 + 3200), 0LL, 0LL);
v61 = v60 + qdpack_operator_get(*(_QWORD *)(a1 + 3200), 0LL, 1LL);
v62 = qdpack_operator_get(*(_QWORD *)(a1 + 3200), 1LL, 0LL) + v61;
v46 = qdpack_operator_get(*(_QWORD *)(a1 + 3200), 1LL, 1LL);
gsl_complex_rect((v46 + v62) * 0.5, 0.0);
qdpack_matrix_set(*(_QWORD *)(a1 + 3216), 0LL, 0LL);
qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 0LL, 0LL);
qdpack_matrix_set(*(_QWORD *)(a1 + 3216), 1LL, 1LL);
if ( !*(_QWORD *)(a1 + 3224) )
*(_QWORD *)(a1 + 3224) = qdpack_matrix_alloc(v73, 0LL);
v47 = qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 1LL, 0LL);
v63 = qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 0LL, 1LL);
v48 = qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 1LL, 0LL);
gsl_complex_rect(v47 / (v63 + v48), 0.0);
qdpack_matrix_set(*(_QWORD *)(a1 + 3224), 0LL, 0LL);
v49 = qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 0LL, 1LL);
v64 = qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 0LL, 1LL);
v50 = v64 + qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 1LL, 0LL);
v51 = v49;
v52 = 0LL;
gsl_complex_rect(v51 / v50, 0.0);
qdpack_matrix_set(*(_QWORD *)(a1 + 3224), 1LL, 0LL);
v53 = -*(_DWORD *)(a1 + 3232);
if ( !(((*(_DWORD *)(a1 + 3232) & 0x40000000) != 0) ^ __OFSUB__(*(_DWORD *)(a1 + 3232), v53) | (*(_DWORD *)(a1 + 3232) == v53)) )
{
do
{
++v53;
qdpack_operator_free(*(_QWORD *)(*(_QWORD *)(a1 + 3176) + v52));
qdpack_operator_free(*(_QWORD *)(*(_QWORD *)(a1 + 3192) + v52));
v54 = *(_QWORD *)(*(_QWORD *)(a1 + 3184) + v52);
v52 += 8LL;
qdpack_operator_free(v54);
}
while ( *(_DWORD *)(a1 + 3232) > v53 );
}
qdpack_operator_free(v75);
qdpack_operator_free(v76);
qdpack_operator_free(*(_QWORD *)(a1 + 3200));
free(*(void **)(a1 + 3176));
free(*(void **)(a1 + 3192));
free(*(void **)(a1 + 3184));
result = 0LL;
}
else
{
fprintf(stderr, "%s: Failed to allocate floquet dissipation matrices.\n", "qdpack_floquet_dissipation_rates");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, void (__fastcall *a3)(__int64, __int64, _QWORD, double), void (__fastcall *a4)(_QWORD, double))
{
__int64 v6; // rax
char *v7; // rax
char *v8; // r12
__int64 i; // rbp
__int64 v10; // r13
__int64 v11; // r12
_QWORD *v12; // r13
__int64 v13; // rax
bool v14; // zf
double v15; // xmm7_8
int v16; // ebp
__int64 v17; // r12
double v18; // xmm0_8
__int64 v19; // r15
double v20; // xmm0_8
double v21; // xmm0_8
__int64 v22; // r15
double v23; // xmm0_8
double v24; // xmm1_8
double v25; // xmm1_8
double v26; // xmm0_8
__int64 v27; // rdi
bool v28; // cf
int v29; // eax
__int64 j; // r12
__int64 v31; // rbp
double v32; // xmm0_8
__int64 v33; // rdx
__int64 k; // r13
__int64 v35; // r14
int v36; // eax
double v37; // xmm4_8
int v38; // er15
__int64 v39; // rbp
__int64 v40; // r12
double v41; // rbp
double v42; // xmm0_8
__int64 v43; // rdx
double v44; // xmm0_8
double v45; // xmm0_8
double v46; // xmm0_8
double v47; // rbp
double v48; // xmm0_8
double v49; // rbp
double v50; // xmm1_8
double v51; // xmm0_8
__int64 v52; // rbp
int v53; // er12
__int64 v54; // rdi
__int64 result; // rax
__int64 v56; // [rsp+0h] [rbp-A8h]
double v57; // [rsp+0h] [rbp-A8h]
double v58; // [rsp+0h] [rbp-A8h]
double v59; // [rsp+0h] [rbp-A8h]
double v60; // [rsp+0h] [rbp-A8h]
double v61; // [rsp+0h] [rbp-A8h]
double v62; // [rsp+0h] [rbp-A8h]
double v63; // [rsp+0h] [rbp-A8h]
double v64; // [rsp+0h] [rbp-A8h]
double v65; // [rsp+8h] [rbp-A0h]
double v66; // [rsp+8h] [rbp-A0h]
double v67; // [rsp+10h] [rbp-98h]
double v68; // [rsp+18h] [rbp-90h]
double v69; // [rsp+20h] [rbp-88h]
int v70; // [rsp+20h] [rbp-88h]
__int64 v71; // [rsp+28h] [rbp-80h]
double v72; // [rsp+30h] [rbp-78h]
int v73; // [rsp+3Ch] [rbp-6Ch]
__int64 v75; // [rsp+58h] [rbp-50h]
__int64 v76; // [rsp+60h] [rbp-48h]
void (__fastcall *v77)(_QWORD, double); // [rsp+68h] [rbp-40h]

v73 = qdpack_hilbert_space_nstates(a2);
v75 = qdpack_operator_alloc(a2);
v6 = qdpack_operator_alloc(a2);
*(_DWORD *)(a1 + 3232) = 1;
v76 = v6;
*(_QWORD *)(a1 + 3184) = malloc(0x18uLL);
*(_QWORD *)(a1 + 3192) = malloc(0x18uLL);
v7 = (char *)malloc(0x18uLL);
*(_QWORD *)(a1 + 3176) = v7;
if ( v7 )
{
v8 = v7;
for ( i = 0LL; ; ++i )
{
v10 = 8 * i;
*(_QWORD *)&v8[v10] = qdpack_operator_alloc(a2);
qdpack_operator_set_zero(*(_QWORD *)(*(_QWORD *)(a1 + 3176) + 8 * i));
v11 = *(_QWORD *)(a1 + 3192);
*(_QWORD *)(v10 + v11) = qdpack_operator_alloc(a2);
qdpack_operator_set_zero(*(_QWORD *)(*(_QWORD *)(a1 + 3192) + 8 * i));
v12 = (_QWORD *)(*(_QWORD *)(a1 + 3184) + 8 * i);
*v12 = qdpack_operator_alloc(a2);
qdpack_operator_set_zero(*(_QWORD *)(*(_QWORD *)(a1 + 3184) + 8 * i));
if ( *(_DWORD *)(a1 + 3232) < (int)i )
break;
v8 = *(char **)(a1 + 3176);
}
*(_QWORD *)(a1 + 3160) = qdpack_operator_alloc(a2);
*(_QWORD *)(a1 + 3144) = qdpack_operator_alloc(a2);
v13 = qdpack_operator_alloc(a2);
v14 = *(_QWORD *)(a1 + 3216) == 0LL;
*(_QWORD *)(a1 + 3200) = v13;
if ( v14 )
*(_QWORD *)(a1 + 3216) = qdpack_matrix_alloc(v73, v73);
a3(a1, a2, *(_QWORD *)(a1 + 3152), 0.0);
v15 = 6.283185307179586 / *(double *)(a1 + 3096);
v72 = v15 / 100.0;
v69 = v15 / 100.0;
if ( 0.5 * (v15 / 100.0) + v15 >= v15 / 100.0 )
{
v77 = a4;
do
{
func1(a1, a2, v69);
a3(a1, a2, *(_QWORD *)(a1 + 3160), v69);
v16 = -*(_DWORD *)(a1 + 3232);
if ( ((*(_DWORD *)(a1 + 3232) & 0x40000000) != 0) == __OFSUB__(*(_DWORD *)(a1 + 3232), v16) )
{
v17 = 0LL;
do
{
v18 = gsl_complex_rect(0.0, 0.0);
v19 = *(_QWORD *)(a1 + 3160);
v68 = v18;
v56 = *(_QWORD *)(a1 + 3208);
v20 = gsl_complex_rect(1.0, 0.0);
qdpack_operator_blas_zgemm(113LL, 111LL, v19, v56, v75, v20, 0.0, v68, 0.0);
v21 = gsl_complex_rect(0.0, 0.0);
v22 = *(_QWORD *)(a1 + 3160);
v65 = v21;
v23 = gsl_complex_rect(1.0, 0.0);
qdpack_operator_blas_zgemm(111LL, 111LL, v75, v22, v76, v23, 0.0, v65, 0.0);
v24 = (double)v16++ * -6.283185307179586;
v25 = v24 * v69 / v15;
v26 = gsl_complex_polar(1.0, v25);
gsl_complex_mul_real(v26, v25, v72 / v15);
qdpack_operator_scale(v76);
v27 = *(_QWORD *)(*(_QWORD *)(a1 + 3176) + v17);
v17 += 8LL;
qdpack_operator_add(v27, v76);
}
while ( *(_DWORD *)(a1 + 3232) >= v16 );
}
v28 = 0.5 * (v15 / 100.0) + v15 < v69 + v72;
v69 = v69 + v72;
}
while ( !v28 );
a4 = v77;
}
v29 = *(_DWORD *)(a1 + 3232);
v71 = 0LL;
v70 = -v29;
if ( ((v29 & 0x40000000) != 0) == __OFSUB__(v29, -v29) )
{
do
{
printf("%s: floquet_X[%d]\n", "qdpack_floquet_dissipation_rates", (unsigned int)v71);
qdpack_operator_print_real(*(_QWORD *)(*(_QWORD *)(a1 + 3176) + 8 * v71));
qdpack_operator_print_imag(*(_QWORD *)(*(_QWORD *)(a1 + 3176) + 8 * v71));
if ( v73 > 0 )
{
for ( j = 0LL; j != v73; ++j )
{
v31 = 0LL;
do
{
v57 = qdpack_matrix_get(*(_QWORD *)(a1 + 3168), j, 0LL);
v58 = v57 - qdpack_matrix_get(*(_QWORD *)(a1 + 3168), v31, 0LL) + 6.283185307179586 * (double)v70 / v15;
qdpack_operator_set(*(_QWORD *)(*(_QWORD *)(a1 + 3192) + 8 * v71), j, v31);
heaviside_function(v58, 0.0);
a4(a1, v58);
v32 = qdpack_operator_get(*(_QWORD *)(*(_QWORD *)(a1 + 3176) + 8 * v71), j, v31);
gsl_complex_abs2(v32);
v33 = v31++;
qdpack_operator_set(*(_QWORD *)(*(_QWORD *)(a1 + 3184) + 8 * v71), j, v33);
}
while ( v73 != v31 );
}
}
printf("%s: floquet_delta[%d]\n", "qdpack_floquet_dissipation_rates", (unsigned int)v71);
qdpack_operator_print_real(*(_QWORD *)(*(_QWORD *)(a1 + 3192) + 8 * v71));
printf("%s: floquet_gamma[%d]\n", "qdpack_floquet_dissipation_rates", (unsigned int)v71);
qdpack_operator_print_real(*(_QWORD *)(*(_QWORD *)(a1 + 3184) + 8 * v71));
++v70;
++v71;
}
while ( *(_DWORD *)(a1 + 3232) >= v70 );
}
if ( v73 > 0 )
{
for ( k = 0LL; k != v73; ++k )
{
v35 = 0LL;
do
{
v36 = *(_DWORD *)(a1 + 3232);
v37 = 0.0;
v38 = -v36;
if ( ((v36 & 0x40000000) != 0) == __OFSUB__(v36, -v36) )
{
do
{
v39 = v38 + v36;
v67 = v37;
v40 = v36 - v38++;
*(_QWORD *)&v66 = COERCE_UNSIGNED_INT64(qdpack_operator_get(*(_QWORD *)(*(_QWORD *)(a1 + 3192) + 8 * v39), k, v35)) & LC14;
v59 = qdpack_operator_get(*(_QWORD *)(*(_QWORD *)(a1 + 3184) + 8 * v39), k, v35);
v41 = qdpack_operator_get(*(_QWORD *)(*(_QWORD *)(a1 + 3184) + 8 * v40), v35, k);
v42 = boltzmann_factor(v66, *(double *)(a1 + 1056));
v36 = *(_DWORD *)(a1 + 3232);
v37 = v67 + (v41 + v59) * v42 + v59;
}
while ( v36 >= v38 );
}
v43 = v35++;
qdpack_operator_set(*(_QWORD *)(a1 + 3200), k, v43);
}
while ( v73 != v35 );
}
}
printf("%s: floquet_A\n", "qdpack_floquet_dissipation_rates");
qdpack_operator_print_real(*(_QWORD *)(a1 + 3200));
v44 = qdpack_operator_get(*(_QWORD *)(a1 + 3200), 0LL, 1LL);
gsl_complex_rect(v44, 0.0);
qdpack_matrix_set(*(_QWORD *)(a1 + 3216), 0LL, 1LL);
v45 = qdpack_operator_get(*(_QWORD *)(a1 + 3200), 1LL, 0LL);
gsl_complex_rect(v45, 0.0);
qdpack_matrix_set(*(_QWORD *)(a1 + 3216), 1LL, 0LL);
v60 = qdpack_operator_get(*(_QWORD *)(a1 + 3200), 0LL, 0LL);
v61 = v60 + qdpack_operator_get(*(_QWORD *)(a1 + 3200), 0LL, 1LL);
v62 = qdpack_operator_get(*(_QWORD *)(a1 + 3200), 1LL, 0LL) + v61;
v46 = qdpack_operator_get(*(_QWORD *)(a1 + 3200), 1LL, 1LL);
gsl_complex_rect((v46 + v62) * 0.5, 0.0);
qdpack_matrix_set(*(_QWORD *)(a1 + 3216), 0LL, 0LL);
qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 0LL, 0LL);
qdpack_matrix_set(*(_QWORD *)(a1 + 3216), 1LL, 1LL);
if ( !*(_QWORD *)(a1 + 3224) )
*(_QWORD *)(a1 + 3224) = qdpack_matrix_alloc(v73, 0LL);
v47 = qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 1LL, 0LL);
v63 = qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 0LL, 1LL);
v48 = qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 1LL, 0LL);
gsl_complex_rect(v47 / (v63 + v48), 0.0);
qdpack_matrix_set(*(_QWORD *)(a1 + 3224), 0LL, 0LL);
v49 = qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 0LL, 1LL);
v64 = qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 0LL, 1LL);
v50 = v64 + qdpack_matrix_get(*(_QWORD *)(a1 + 3216), 1LL, 0LL);
v51 = v49;
v52 = 0LL;
gsl_complex_rect(v51 / v50, 0.0);
qdpack_matrix_set(*(_QWORD *)(a1 + 3224), 1LL, 0LL);
v53 = -*(_DWORD *)(a1 + 3232);
if ( !(((*(_DWORD *)(a1 + 3232) & 0x40000000) != 0) ^ __OFSUB__(*(_DWORD *)(a1 + 3232), v53) | (*(_DWORD *)(a1 + 3232) == v53)) )
{
do
{
++v53;
qdpack_operator_free(*(_QWORD *)(*(_QWORD *)(a1 + 3176) + v52));
qdpack_operator_free(*(_QWORD *)(*(_QWORD *)(a1 + 3192) + v52));
v54 = *(_QWORD *)(*(_QWORD *)(a1 + 3184) + v52);
v52 += 8LL;
qdpack_operator_free(v54);
}
while ( *(_DWORD *)(a1 + 3232) > v53 );
}
qdpack_operator_free(v75);
qdpack_operator_free(v76);
qdpack_operator_free(*(_QWORD *)(a1 + 3200));
free(*(void **)(a1 + 3176));
free(*(void **)(a1 + 3192));
free(*(void **)(a1 + 3184));
result = 0LL;
}
else
{
fprintf(stderr, "%s: Failed to allocate floquet dissipation matrices.\n", "qdpack_floquet_dissipation_rates");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
qdpack_floquet_dissipation_rates(qdpack_simulation_t *sim,
                                       qdpack_hilbert_space_t *qs,
                                       operator_cb_func_t floquet_modes_store_cb,
                                       spectral_density_cb_t s_func_cb)
{
    gsl_complex z;
    double t, delta_t, T;
    int i, i_limit = 100, j, qsn = qdpack_hilbert_space_nstates(qs);
    qdpack_operator_t *w1, *w2;
    int k, k_idx;
    w1 = qdpack_operator_alloc(qs);
    w2 = qdpack_operator_alloc(qs);
    sim->floquet_k_max = 1;
    sim->floquet_gamma = malloc(sizeof(qdpack_operator_t *) * (2 * sim->floquet_k_max + 1));
    sim->floquet_delta = malloc(sizeof(qdpack_operator_t *) * (2 * sim->floquet_k_max + 1));
    sim->floquet_X = malloc(sizeof(qdpack_operator_t *) * (2 * sim->floquet_k_max + 1));
    if (sim->floquet_X == ((void *)0))
    {
        fprintf(stderr, "%s: Failed to allocate floquet dissipation matrices.\n", __PRETTY_FUNCTION__);
        return -1;
    }
    for (k_idx = 0, k = - sim->floquet_k_max; k <= sim->floquet_k_max; k++, k_idx++)
    {
        sim->floquet_X[k_idx] = qdpack_operator_alloc(qs);
        qdpack_operator_set_zero(sim->floquet_X[k_idx]);
        sim->floquet_delta[k_idx] = qdpack_operator_alloc(qs);
        qdpack_operator_set_zero(sim->floquet_delta[k_idx]);
        sim->floquet_gamma[k_idx] = qdpack_operator_alloc(qs);
        qdpack_operator_set_zero(sim->floquet_gamma[k_idx]);
    }
    sim->floquet_modes_t = qdpack_operator_alloc(qs);
    sim->floquet_states_t = qdpack_operator_alloc(qs);
    sim->floquet_A = qdpack_operator_alloc(qs);
    if (sim->floquet_Gamma == ((void *)0))
    {
        sim->floquet_Gamma = qdpack_matrix_alloc(qsn, qsn);
    }
    floquet_modes_store_cb(sim, qs, sim->floquet_modes, 0.0);
    T = 2*3.14159265358979323846/sim->h_td_w;
    delta_t = T / i_limit;
    for (t = delta_t; t <= T+delta_t/2.0; t += delta_t)
    {
        qdpack_floquet_modes_t(sim, qs, t);
        floquet_modes_store_cb(sim, qs, sim->floquet_modes_t, t);
        for (k_idx = 0, k = - sim->floquet_k_max; k <= sim->floquet_k_max; k++, k_idx++)
        {
            qdpack_operator_blas_zgemm(CblasConjTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), sim->floquet_modes_t, sim->floquet_operator, (gsl_complex_rect(0.0,0.0)), w1);
            qdpack_operator_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), w1 , sim->floquet_modes_t, (gsl_complex_rect(0.0,0.0)), w2);
            z = gsl_complex_mul_real(gsl_complex_polar(1.0, - 2 * 3.14159265358979323846 * k * t / T), delta_t / T);
            qdpack_operator_scale(w2, z);
            qdpack_operator_add(sim->floquet_X[k_idx], w2);
        }
    }
    for (k_idx = 0, k = - sim->floquet_k_max; k <= sim->floquet_k_max; k++, k_idx++)
    {
        printf("%s: floquet_X[%d]\n", __PRETTY_FUNCTION__, k_idx);
        qdpack_operator_print_real(sim->floquet_X[k_idx]);
        qdpack_operator_print_imag(sim->floquet_X[k_idx]);
        for (i = 0; i < qsn; i++)
        {
            for (j = 0; j < qsn; j++)
            {
                gsl_complex z;
                double delta, gamma;
                delta = ((qdpack_matrix_get(sim->floquet_quasienergies, i, 0)).dat[0])
                      - ((qdpack_matrix_get(sim->floquet_quasienergies, j, 0)).dat[0])
                      + 2 * 3.14159265358979323846 * k / T;
                do {(&z)->dat[0]=(delta); (&z)->dat[1]=(0);} while(0);
                qdpack_operator_set(sim->floquet_delta[k_idx], i, j, z);
                gamma = 2 * 3.14159265358979323846 * heaviside_function(delta) * s_func_cb(sim, delta)
                                 * gsl_complex_abs2(qdpack_operator_get(sim->floquet_X[k_idx], i, j));
                do {(&z)->dat[0]=(gamma); (&z)->dat[1]=(0);} while(0);
                qdpack_operator_set(sim->floquet_gamma[k_idx], i, j, z);
            }
        }
        printf("%s: floquet_delta[%d]\n", __PRETTY_FUNCTION__, k_idx);
        qdpack_operator_print_real(sim->floquet_delta[k_idx]);
        printf("%s: floquet_gamma[%d]\n", __PRETTY_FUNCTION__, k_idx);
        qdpack_operator_print_real(sim->floquet_gamma[k_idx]);
    }
    for (i = 0; i < qsn; i++)
    {
        for (j = 0; j < qsn; j++)
        {
            double a_ij_sum = 0.0;
            for (k = - sim->floquet_k_max; k <= sim->floquet_k_max; k++)
            {
                double g1, g2, d;
                int k1_idx, k2_idx;
                k1_idx = k + sim->floquet_k_max;
                k2_idx = - k + sim->floquet_k_max;
                d = fabs(((qdpack_operator_get(sim->floquet_delta[k1_idx], i, j)).dat[0]));
                g1 = ((qdpack_operator_get(sim->floquet_gamma[k1_idx], i, j)).dat[0]);
                g2 = ((qdpack_operator_get(sim->floquet_gamma[k2_idx], j, i)).dat[0]);
                a_ij_sum += g1 + boltzmann_factor(d, sim->T_w) * (g1 + g2);
            }
            do {(&z)->dat[0]=(a_ij_sum); (&z)->dat[1]=(0);} while(0);
            qdpack_operator_set(sim->floquet_A, i, j, z);
        }
    }
    printf("%s: floquet_A\n", __PRETTY_FUNCTION__);
    qdpack_operator_print_real(sim->floquet_A);
    qdpack_matrix_set(sim->floquet_Gamma, 0, 1,
                      gsl_complex_rect(((qdpack_operator_get(sim->floquet_A, 0, 1)).dat[0]), 0.0));
    qdpack_matrix_set(sim->floquet_Gamma, 1, 0,
                      gsl_complex_rect(((qdpack_operator_get(sim->floquet_A, 1, 0)).dat[0]), 0.0));
    qdpack_matrix_set(sim->floquet_Gamma, 0, 0,
                      gsl_complex_rect(
                        (((qdpack_operator_get(sim->floquet_A, 0, 0)).dat[0]) +
                         ((qdpack_operator_get(sim->floquet_A, 0, 1)).dat[0]) +
                         ((qdpack_operator_get(sim->floquet_A, 1, 0)).dat[0]) +
                         ((qdpack_operator_get(sim->floquet_A, 1, 1)).dat[0])) / 2.0, 0.0));
    qdpack_matrix_set(sim->floquet_Gamma, 1, 1, qdpack_matrix_get(sim->floquet_Gamma, 0, 0));
    if (sim->floquet_ss_prob == ((void *)0))
    {
        sim->floquet_ss_prob = qdpack_matrix_alloc(qsn, 0);
    }
    qdpack_matrix_set(sim->floquet_ss_prob, 0, 0,
                      gsl_complex_rect(
                          ((qdpack_matrix_get(sim->floquet_Gamma, 1, 0)).dat[0]) /
                          (((qdpack_matrix_get(sim->floquet_Gamma, 0, 1)).dat[0]) +
                           ((qdpack_matrix_get(sim->floquet_Gamma, 1, 0)).dat[0])), 0.0));
    qdpack_matrix_set(sim->floquet_ss_prob, 1, 0,
                      gsl_complex_rect(
                          ((qdpack_matrix_get(sim->floquet_Gamma, 0, 1)).dat[0]) /
                          (((qdpack_matrix_get(sim->floquet_Gamma, 0, 1)).dat[0]) +
                           ((qdpack_matrix_get(sim->floquet_Gamma, 1, 0)).dat[0])), 0.0));
    for (k_idx = 0, k = - sim->floquet_k_max; k < sim->floquet_k_max; k++, k_idx++)
    {
        qdpack_operator_free(sim->floquet_X[k_idx]);
        qdpack_operator_free(sim->floquet_delta[k_idx]);
        qdpack_operator_free(sim->floquet_gamma[k_idx]);
    }
    qdpack_operator_free(w1);
    qdpack_operator_free(w2);
    qdpack_operator_free(sim->floquet_A);
    free(sim->floquet_X);
    free(sim->floquet_delta);
    free(sim->floquet_gamma);
    return 0;
}

canonical_original_code:
int qdpack_floquet_dissipation_rates(struct _qdpack_simulation *sim, struct qdpack_hilbert_space_t *qs, int (*floquet_modes_store_cb)(struct _qdpack_simulation *sp, struct qdpack_hilbert_space_t *qs, struct _qdpack_operator_t *rho_t, double t), double (*s_func_cb)(struct _qdpack_simulation *sp, double f))
{
    struct gsl_complex z;
    double t; double delta_t; double T;
    int i; int i_limit = 100; int j; int qsn = qdpack_hilbert_space_nstates(qs);
    struct _qdpack_operator_t *w1; struct _qdpack_operator_t *w2;
    int k; int k_idx;
    w1 = qdpack_operator_alloc(qs);
    w2 = qdpack_operator_alloc(qs);
    sim->floquet_k_max = 1;
    sim->floquet_gamma = malloc(sizeof(struct _qdpack_operator_t *) * (2 * sim->floquet_k_max + 1));
    sim->floquet_delta = malloc(sizeof(struct _qdpack_operator_t *) * (2 * sim->floquet_k_max + 1));
    sim->floquet_X = malloc(sizeof(struct _qdpack_operator_t *) * (2 * sim->floquet_k_max + 1));
    if (sim->floquet_X == ((void *)0))
    {
        fprintf(stderr, "%s: Failed to allocate floquet dissipation matrices.\n", __PRETTY_FUNCTION__);
        return -1;
    }
    for (k_idx = 0, k = - sim->floquet_k_max; k <= sim->floquet_k_max; k++, k_idx++)
    {
        sim->floquet_X[k_idx] = qdpack_operator_alloc(qs);
        qdpack_operator_set_zero(sim->floquet_X[k_idx]);
        sim->floquet_delta[k_idx] = qdpack_operator_alloc(qs);
        qdpack_operator_set_zero(sim->floquet_delta[k_idx]);
        sim->floquet_gamma[k_idx] = qdpack_operator_alloc(qs);
        qdpack_operator_set_zero(sim->floquet_gamma[k_idx]);
    }
    sim->floquet_modes_t = qdpack_operator_alloc(qs);
    sim->floquet_states_t = qdpack_operator_alloc(qs);
    sim->floquet_A = qdpack_operator_alloc(qs);
    if (sim->floquet_Gamma == ((void *)0))
    {
        sim->floquet_Gamma = qdpack_matrix_alloc(qsn, qsn);
    }
    floquet_modes_store_cb(sim, qs, sim->floquet_modes, 0.0);
    T = 2*3.14159265358979323846/sim->h_td_w;
    delta_t = T / i_limit;
    for (t = delta_t; t <= T+delta_t/2.0; t += delta_t)
    {
        qdpack_floquet_modes_t(sim, qs, t);
        floquet_modes_store_cb(sim, qs, sim->floquet_modes_t, t);
        for (k_idx = 0, k = - sim->floquet_k_max; k <= sim->floquet_k_max; k++, k_idx++)
        {
            qdpack_operator_blas_zgemm(CblasConjTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), sim->floquet_modes_t, sim->floquet_operator, (gsl_complex_rect(0.0,0.0)), w1);
            qdpack_operator_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), w1 , sim->floquet_modes_t, (gsl_complex_rect(0.0,0.0)), w2);
            z = gsl_complex_mul_real(gsl_complex_polar(1.0, - 2 * 3.14159265358979323846 * k * t / T), delta_t / T);
            qdpack_operator_scale(w2, z);
            qdpack_operator_add(sim->floquet_X[k_idx], w2);
        }
    }
    for (k_idx = 0, k = - sim->floquet_k_max; k <= sim->floquet_k_max; k++, k_idx++)
    {
        printf("%s: floquet_X[%d]\n", __PRETTY_FUNCTION__, k_idx);
        qdpack_operator_print_real(sim->floquet_X[k_idx]);
        qdpack_operator_print_imag(sim->floquet_X[k_idx]);
        for (i = 0; i < qsn; i++)
        {
            for (j = 0; j < qsn; j++)
            {
                struct gsl_complex z;
                double delta; double gamma;
                delta = ((qdpack_matrix_get(sim->floquet_quasienergies, i, 0)).dat[0])
                      - ((qdpack_matrix_get(sim->floquet_quasienergies, j, 0)).dat[0])
                      + 2 * 3.14159265358979323846 * k / T;
                do {(&z)->dat[0]=(delta); (&z)->dat[1]=(0);} while(0);
                qdpack_operator_set(sim->floquet_delta[k_idx], i, j, z);
                gamma = 2 * 3.14159265358979323846 * heaviside_function(delta) * s_func_cb(sim, delta)
                                 * gsl_complex_abs2(qdpack_operator_get(sim->floquet_X[k_idx], i, j));
                do {(&z)->dat[0]=(gamma); (&z)->dat[1]=(0);} while(0);
                qdpack_operator_set(sim->floquet_gamma[k_idx], i, j, z);
            }
        }
        printf("%s: floquet_delta[%d]\n", __PRETTY_FUNCTION__, k_idx);
        qdpack_operator_print_real(sim->floquet_delta[k_idx]);
        printf("%s: floquet_gamma[%d]\n", __PRETTY_FUNCTION__, k_idx);
        qdpack_operator_print_real(sim->floquet_gamma[k_idx]);
    }
    for (i = 0; i < qsn; i++)
    {
        for (j = 0; j < qsn; j++)
        {
            double a_ij_sum = 0.0;
            for (k = - sim->floquet_k_max; k <= sim->floquet_k_max; k++)
            {
                double g1; double g2; double d;
                int k1_idx; int k2_idx;
                k1_idx = k + sim->floquet_k_max;
                k2_idx = - k + sim->floquet_k_max;
                d = fabs(((qdpack_operator_get(sim->floquet_delta[k1_idx], i, j)).dat[0]));
                g1 = ((qdpack_operator_get(sim->floquet_gamma[k1_idx], i, j)).dat[0]);
                g2 = ((qdpack_operator_get(sim->floquet_gamma[k2_idx], j, i)).dat[0]);
                a_ij_sum += g1 + boltzmann_factor(d, sim->T_w) * (g1 + g2);
            }
            do {(&z)->dat[0]=(a_ij_sum); (&z)->dat[1]=(0);} while(0);
            qdpack_operator_set(sim->floquet_A, i, j, z);
        }
    }
    printf("%s: floquet_A\n", __PRETTY_FUNCTION__);
    qdpack_operator_print_real(sim->floquet_A);
    qdpack_matrix_set(sim->floquet_Gamma, 0, 1,
                      gsl_complex_rect(((qdpack_operator_get(sim->floquet_A, 0, 1)).dat[0]), 0.0));
    qdpack_matrix_set(sim->floquet_Gamma, 1, 0,
                      gsl_complex_rect(((qdpack_operator_get(sim->floquet_A, 1, 0)).dat[0]), 0.0));
    qdpack_matrix_set(sim->floquet_Gamma, 0, 0,
                      gsl_complex_rect(
                        (((qdpack_operator_get(sim->floquet_A, 0, 0)).dat[0]) +
                         ((qdpack_operator_get(sim->floquet_A, 0, 1)).dat[0]) +
                         ((qdpack_operator_get(sim->floquet_A, 1, 0)).dat[0]) +
                         ((qdpack_operator_get(sim->floquet_A, 1, 1)).dat[0])) / 2.0, 0.0));
    qdpack_matrix_set(sim->floquet_Gamma, 1, 1, qdpack_matrix_get(sim->floquet_Gamma, 0, 0));
    if (sim->floquet_ss_prob == ((void *)0))
    {
        sim->floquet_ss_prob = qdpack_matrix_alloc(qsn, 0);
    }
    qdpack_matrix_set(sim->floquet_ss_prob, 0, 0,
                      gsl_complex_rect(
                          ((qdpack_matrix_get(sim->floquet_Gamma, 1, 0)).dat[0]) /
                          (((qdpack_matrix_get(sim->floquet_Gamma, 0, 1)).dat[0]) +
                           ((qdpack_matrix_get(sim->floquet_Gamma, 1, 0)).dat[0])), 0.0));
    qdpack_matrix_set(sim->floquet_ss_prob, 1, 0,
                      gsl_complex_rect(
                          ((qdpack_matrix_get(sim->floquet_Gamma, 0, 1)).dat[0]) /
                          (((qdpack_matrix_get(sim->floquet_Gamma, 0, 1)).dat[0]) +
                           ((qdpack_matrix_get(sim->floquet_Gamma, 1, 0)).dat[0])), 0.0));
    for (k_idx = 0, k = - sim->floquet_k_max; k < sim->floquet_k_max; k++, k_idx++)
    {
        qdpack_operator_free(sim->floquet_X[k_idx]);
        qdpack_operator_free(sim->floquet_delta[k_idx]);
        qdpack_operator_free(sim->floquet_gamma[k_idx]);
    }
    qdpack_operator_free(w1);
    qdpack_operator_free(w2);
    qdpack_operator_free(sim->floquet_A);
    free(sim->floquet_X);
    free(sim->floquet_delta);
    free(sim->floquet_gamma);
    return 0;
}

variable_types: int (*)(struct _qdpack_simulation *sp, struct qdpack_hilbert_space_t *qs, struct _qdpack_operator_t *rho_t, double t)

variable_types: double (*)(struct _qdpack_simulation *sp, double f)

variable_types:
z
struct gsl_complex { double dat[2]; }

variable_types: T double

variable_types: k int

variable_types: delta double

variable_types: gamma double

variable_types: d double


repo: jrjohansson/qdpack

original_code:
qdpack_operator_t *
basis_transform(qdpack_simulation_t *sim, qdpack_hilbert_space_t *qs, int n, ho_w_func_t ho_w_cb, double t)
{
    gsl_complex z;
    qdpack_operator_t *S;
    int i, j, ns, mm, ll;
    double r, w0, wt, sij;
    qdpack_operator_list_t op_list;
    ns = qs->nstates[n];
    if ((S = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "basis_transform_ho: Failed to allocate basis tranformation matrix (Out of memory?).\n");
    }
    qdpack_operator_set_zero(S);
    w0 = ho_w_cb(0.0, sim);
    wt = ho_w_cb(t, sim);
    r = 2 * sqrt(w0 * wt) / (wt + w0);
    if (r > 1.0)
        r = 1.0;
    else if (r < -1.0)
        r = -1.0;
    for (j = 0; j < ns; j++)
    {
        for (i = j; i < ns; i++)
        {
            if ((i == j) || ((i+j)%2 == 0))
            {
                ll = (i+j)/2;
                mm = abs(i-j)/2;
                sij = fact_sqrt(((i<j)?i:j)) / fact_sqrt(((i<j)?j:i)) * sqrt(r) * gsl_sf_legendre_Plm(ll, mm, r);
                do {(&z)->dat[0]=(sij); (&z)->dat[1]=(0.0);} while(0);
                qdpack_operator_set(S, i, j, z);
                if (i != j)
                {
                    sij = pow(-1.0, (j-i)/2.0) * sij;
                    do {(&z)->dat[0]=(sij); (&z)->dat[1]=(0.0);} while(0);
                    qdpack_operator_set(S, j, i, z);
                }
            }
        }
    }
    if (qs->nsubsys > 1)
    {
        qdpack_operator_list_init(&op_list);
        for (i = 0; i < qs->nsubsys; i++)
        {
            qdpack_operator_t *M;
            qdpack_hilbert_space_t *qs_sub = qdpack_hilbert_space_new();
            qdpack_hilbert_space_add(qs_sub, qs->nstates[i]);
            M = qdpack_operator_alloc(qs_sub);
            if (i != n)
            {
                operator_unit(M, qs, i);
            }
            else
            {
                M = S;
            }
            qdpack_operator_list_append(&op_list, M);
        }
        qdpack_operator_tensor(S, qs, &op_list);
        qdpack_operator_list_free_entries(&op_list);
    }
    return S;
}

canonical_original_code:
struct _qdpack_operator_t *basis_transform(struct _qdpack_simulation *sim, struct qdpack_hilbert_space_t *qs, int n, double (*ho_w_cb)(double, void *), double t)
{
    struct gsl_complex z;
    struct _qdpack_operator_t *S;
    int i; int j; int ns; int mm; int ll;
    double r; double w0; double wt; double sij;
    struct qdpack_operator_list_t op_list;
    ns = qs->nstates[n];
    if ((S = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "basis_transform_ho: Failed to allocate basis tranformation matrix (Out of memory?).\n");
    }
    qdpack_operator_set_zero(S);
    w0 = ho_w_cb(0.0, sim);
    wt = ho_w_cb(t, sim);
    r = 2 * sqrt(w0 * wt) / (wt + w0);
    if (r > 1.0)
        r = 1.0;
    else if (r < -1.0)
        r = -1.0;
    for (j = 0; j < ns; j++)
    {
        for (i = j; i < ns; i++)
        {
            if ((i == j) || ((i+j)%2 == 0))
            {
                ll = (i+j)/2;
                mm = abs(i-j)/2;
                sij = fact_sqrt(((i<j)?i:j)) / fact_sqrt(((i<j)?j:i)) * sqrt(r) * gsl_sf_legendre_Plm(ll, mm, r);
                do {(&z)->dat[0]=(sij); (&z)->dat[1]=(0.0);} while(0);
                qdpack_operator_set(S, i, j, z);
                if (i != j)
                {
                    sij = pow(-1.0, (j-i)/2.0) * sij;
                    do {(&z)->dat[0]=(sij); (&z)->dat[1]=(0.0);} while(0);
                    qdpack_operator_set(S, j, i, z);
                }
            }
        }
    }
    if (qs->nsubsys > 1)
    {
        qdpack_operator_list_init(&op_list);
        for (i = 0; i < qs->nsubsys; i++)
        {
            struct _qdpack_operator_t *M;
            struct qdpack_hilbert_space_t *qs_sub = qdpack_hilbert_space_new();
            qdpack_hilbert_space_add(qs_sub, qs->nstates[i]);
            M = qdpack_operator_alloc(qs_sub);
            if (i != n)
            {
                operator_unit(M, qs, i);
            }
            else
            {
                M = S;
            }
            qdpack_operator_list_append(&op_list, M);
        }
        qdpack_operator_tensor(S, qs, &op_list);
        qdpack_operator_list_free_entries(&op_list);
    }
    return S;
}

variable_types: struct _qdpack_simulation { struct qdpack_hilbert_space_t *qs; double Ti; double Tf; double dT; char simsig[1024]; double T_w; struct _qdpack_operator_t *H0; struct _qdpack_operator_t *H1; struct _qdpack_operator_t *H_t; struct _qdpack_operator_t *H_a; struct _qdpack_operator_t *H_b; struct _qdpack_operator_t *do_a[20]; struct _qdpack_operator_t *do_ad[20]; struct _qdpack_operator_t *do_aad[20]; struct _qdpack_operator_t *do_ada[20]; struct _qdpack_operator_t *do_a_eb[20]; struct _qdpack_operator_t *do_ad_eb[20]; struct _qdpack_operator_t *do_aad_eb[20]; struct _qdpack_operator_t *do_ada_eb[20]; struct _qdpack_operator_t *ws1; struct _qdpack_operator_t *ws2; struct _qdpack_operator_t *op_tmp; double do_g1[20]; double do_g2[20]; int do_n; void *parameters; struct _qdpack_operator_t *dSSt; double (*ho_w_func)(double, void *); int cont_basis_transform; int option_me_eb; int option_adaptive; double g0; struct _qdpack_operator_t *N_op[10]; struct _qdpack_operator_t *a; struct _qdpack_operator_t *n_op; struct _qdpack_state { int n; struct qdpack_hilbert_space_t *qs; struct _qdpack_matrix *data; } *psi_f; double h_td_A; double h_td_w; int (*H0_func)(struct _qdpack_simulation *, struct qdpack_hilbert_space_t *, struct _qdpack_operator_t *); int (*H1_func)(struct _qdpack_simulation *, struct qdpack_hilbert_space_t *, struct _qdpack_operator_t *); int (*Ht_func)(struct _qdpack_simulation *, struct _qdpack_operator_t *, struct _qdpack_operator_t *, struct _qdpack_operator_t *, double); struct _qdpack_operator_t *evec; struct _qdpack_matrix *eval; struct _qdpack_operator_t *floquet_states_t; struct _qdpack_operator_t *floquet_modes; struct _qdpack_matrix *floquet_quasienergies; struct _qdpack_operator_t **floquet_X; struct _qdpack_matrix *floquet_Gamma; struct _qdpack_matrix *floquet_ss_prob; int floquet_k_max; } *

variable_types:
qs
struct qdpack_hilbert_space_t *

variable_types: n int

variable_types: t double

variable_types: i int

variable_types: j int

variable_types: ns int

variable_types: mm int

variable_types: ll int

variable_types: r double

variable_types: wt double

variable_types: sij double

variable_types: struct qdpack_operator_list_t { struct _qdpack_operator_t { int n; struct qdpack_hilbert_space_t { int nsubsys; int *nstates; } *qs; struct _qdpack_matrix { int n; struct gsl_matrix_complex { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_complex_struct { unsigned long size; double *data; } *block; int owner; } *data; } *data; } *dm[20]; int len; }

user_defined_types: struct qdpack_operator_list_t { struct _qdpack_operator_t *dm[20]; int len; }

user_defined_types: struct _qdpack_simulation { struct qdpack_hilbert_space_t *qs; double Ti; double Tf; double dT; char simsig[1024]; double T_w; struct _qdpack_operator_t *H0; struct _qdpack_operator_t *H1; struct _qdpack_operator_t *H_t; struct _qdpack_operator_t *H_a; struct _qdpack_operator_t *H_b; struct _qdpack_operator_t *do_a[20]; struct _qdpack_operator_t *do_ad[20]; struct _qdpack_operator_t *do_aad[20]; struct _qdpack_operator_t *do_ada[20]; struct _qdpack_operator_t *do_a_eb[20]; struct _qdpack_operator_t *do_ad_eb[20]; struct _qdpack_operator_t *do_aad_eb[20]; struct _qdpack_operator_t *do_ada_eb[20]; struct _qdpack_operator_t *ws1; struct _qdpack_operator_t *ws2; struct _qdpack_operator_t *op_tmp; double do_g1[20]; double do_g2[20]; int do_n; void *parameters; struct _qdpack_operator_t *dSSt; double (*ho_w_func)(double, void *); int cont_basis_transform; int option_me_eb; int option_adaptive; double g0; struct _qdpack_operator_t *N_op[10]; struct _qdpack_operator_t *a; struct _qdpack_operator_t *n_op; struct _qdpack_state *psi_f; double h_td_A; double h_td_w; int (*H0_func)(struct _qdpack_simulation *, struct qdpack_hilbert_space_t *, struct _qdpack_operator_t *); int (*H1_func)(struct _qdpack_simulation *, struct qdpack_hilbert_space_t *, struct _qdpack_operator_t *); int (*Ht_func)(struct _qdpack_simulation *, struct _qdpack_operator_t *, struct _qdpack_operator_t *, struct _qdpack_operator_t *, double); struct _qdpack_operator_t *evec; struct _qdpack_matrix *eval; struct _qdpack_operator_t *floquet_states_t; struct _qdpack_operator_t *floquet_modes; struct _qdpack_matrix *floquet_quasienergies; struct _qdpack_operator_t **floquet_X; struct _qdpack_matrix *floquet_Gamma; struct _qdpack_matrix *floquet_ss_prob; int floquet_k_max; }

user_defined_types: struct _qdpack_operator_t { int n; struct qdpack_hilbert_space_t *qs; struct _qdpack_matrix *data; }

user_defined_types: struct _qdpack_matrix { int n; struct gsl_matrix_complex *data; }

user_defined_types: struct gsl_matrix_complex { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_complex_struct *block; int owner; }


decompiled_code:
__int64 __fastcall basis_transform_derivative(__int64 a1, __int64 a2, int a3, double (__fastcall *a4)(__int64, double), double a5, double a6, double a7, double a8)
{
__int64 v10; // r13
__int64 v11; // r12
__int64 v12; // xmm0_8
double v14; // [rsp+8h] [rbp-30h]

v10 = basis_transform(a1, a2, a3, a4, a5 - 0.000001, a6, a7, a8);
v11 = basis_transform(a1, a2, a3, a4, a5 + 0.000001, a5, a7, a8);
qdpack_operator_sub(v11, v10);
v14 = a4(a1, a5);
if ( a4(a1, 0.0) <= v14 )
v12 = LC8;
else
v12 = LC7;
qdpack_operator_scale(v11, *(double *)&v12, 0.0);
qdpack_operator_free(v10);
return v11;
}

original_code:
qdpack_operator_t *
basis_transform_derivative(qdpack_simulation_t *sim, qdpack_hilbert_space_t *qs, int n, ho_w_func_t ho_w_cb, double t)
{
    double h;
    gsl_complex z;
    qdpack_operator_t *S1, *S2;
    h = 1e-6;
    S1 = basis_transform(sim, qs, n, ho_w_cb, t-h);
    S2 = basis_transform(sim, qs, n, ho_w_cb, t+h);
    qdpack_operator_sub(S2, S1);
    if (ho_w_cb(t, sim) < ho_w_cb(0.0, sim))
    {
        do {(&z)->dat[0]=(-1.0 / (2.0 * h)); (&z)->dat[1]=(0.0);} while(0);
    }
    else
    {
        do {(&z)->dat[0]=(1.0 / (2.0 * h)); (&z)->dat[1]=(0.0);} while(0);
    }
    qdpack_operator_scale(S2, z);
    qdpack_operator_free(S1);
    return S2;
}

canonical_original_code:
struct _qdpack_operator_t *basis_transform_derivative(struct _qdpack_simulation *sim, struct qdpack_hilbert_space_t *qs, int n, double (*ho_w_cb)(double, void *), double t)
{
    double h;
    struct gsl_complex z;
    struct _qdpack_operator_t *S1; struct _qdpack_operator_t *S2;
    h = 1e-6;
    S1 = basis_transform(sim, qs, n, ho_w_cb, t-h);
    S2 = basis_transform(sim, qs, n, ho_w_cb, t+h);
    qdpack_operator_sub(S2, S1);
    if (ho_w_cb(t, sim) < ho_w_cb(0.0, sim))
    {
        do {(&z)->dat[0]=(-1.0 / (2.0 * h)); (&z)->dat[1]=(0.0);} while(0);
    }
    else
    {
        do {(&z)->dat[0]=(1.0 / (2.0 * h)); (&z)->dat[1]=(0.0);} while(0);
    }
    qdpack_operator_scale(S2, z);
    qdpack_operator_free(S1);
    return S2;
}

variable_types: h double

variable_types:
z
struct gsl_complex { double dat[2]; }

variable_types: struct _qdpack_operator_t { int n; struct qdpack_hilbert_space_t { int nsubsys; int *nstates; } *qs; struct _qdpack_matrix { int n; struct gsl_matrix_complex { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_complex_struct { unsigned long size; double *data; } *block; int owner; } *data; } *data; } *

user_defined_types: struct _qdpack_state { int n; struct qdpack_hilbert_space_t *qs; struct _qdpack_matrix *data; }


decompiled_code:
double __fastcall qdpack_entanglement_neumann_entropy(int *a1)
{
__int64 v1; // r13
__int64 v2; // r12
__int64 v3; // r14
__int64 v4; // rbx
double v5; // xmm2_8
double v6; // xmm0_8

v1 = qdpack_matrix_alloc(a1[1], *a1);
qdpack_matrix_memcpy(v1, *((_QWORD *)a1 + 2));
v2 = qdpack_matrix_alloc(a1[1], 1LL);
v3 = qdpack_matrix_alloc(a1[1], *a1);
qdpack_matrix_eigen_hermv(v1, v2, v3, 0LL);
if ( a1[1] <= 0 )
{
v5 = 0.0;
}
else
{
v4 = 0LL;
v5 = 0.0;
do
{
v6 = qdpack_matrix_get(v2, v4++, 0LL);
v5 = v5 - v6 * log(v6);
}
while ( a1[1] > (int)v4 );
}
qdpack_matrix_free(v1);
qdpack_matrix_free(v2);
qdpack_matrix_free(v3);
return v5;
}

canonical_decompiled_code:
double __fastcall func0(int *a1)
{
__int64 v1; // r13
__int64 v2; // r12
__int64 v3; // r14
__int64 v4; // rbx
double v5; // xmm2_8
double v6; // xmm0_8

v1 = qdpack_matrix_alloc(a1[1], *a1);
qdpack_matrix_memcpy(v1, *((_QWORD *)a1 + 2));
v2 = qdpack_matrix_alloc(a1[1], 1LL);
v3 = qdpack_matrix_alloc(a1[1], *a1);
qdpack_matrix_eigen_hermv(v1, v2, v3, 0LL);
if ( a1[1] <= 0 )
{
v5 = 0.0;
}
else
{
v4 = 0LL;
v5 = 0.0;
do
{
v6 = qdpack_matrix_get(v2, v4++, 0LL);
v5 = v5 - v6 * log(v6);
}
while ( a1[1] > (int)v4 );
}
qdpack_matrix_free(v1);
qdpack_matrix_free(v2);
qdpack_matrix_free(v3);
return v5;
}

original_code:
double
qdpack_entanglement_neumann_entropy(qdpack_operator_t *rho)
{
    int i;
    double e, ne = 0.0;
    qdpack_matrix_t *rho_w;
    qdpack_matrix_t *eval, *evec;
    rho_w = qdpack_matrix_alloc(rho->m, rho->n);
    qdpack_matrix_memcpy(rho_w, rho->data);
    eval = qdpack_matrix_alloc(rho->m, 1);
    evec = qdpack_matrix_alloc(rho->m, rho->n);
    qdpack_matrix_eigen_hermv(rho_w, eval, evec, 0);
    for (i = 0; i < rho->m; i++)
    {
        e = ((qdpack_matrix_get(eval, i, 0)).dat[0]);
        ne += - e * log(e);
    }
    qdpack_matrix_free(rho_w);
    qdpack_matrix_free(eval);
    qdpack_matrix_free(evec);
    return ne;
}

canonical_original_code:
double qdpack_entanglement_neumann_entropy(struct _qdpack_operator_t *rho)
{
    int i;
    double e; double ne = 0.0;
    struct _qdpack_matrix *rho_w;
    struct _qdpack_matrix *eval; struct _qdpack_matrix *evec;
    rho_w = qdpack_matrix_alloc(rho->m, rho->n);
    qdpack_matrix_memcpy(rho_w, rho->data);
    eval = qdpack_matrix_alloc(rho->m, 1);
    evec = qdpack_matrix_alloc(rho->m, rho->n);
    qdpack_matrix_eigen_hermv(rho_w, eval, evec, 0);
    for (i = 0; i < rho->m; i++)
    {
        e = ((qdpack_matrix_get(eval, i, 0)).dat[0]);
        ne += - e * log(e);
    }
    qdpack_matrix_free(rho_w);
    qdpack_matrix_free(eval);
    qdpack_matrix_free(evec);
    return ne;
}

variable_types: e double

variable_types: ne double

variable_types: struct _qdpack_matrix { int n; struct gsl_matrix_complex { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_complex_struct { unsigned long size; double *data; } *block; int owner; } *data; } *

return_type: double

user_defined_types: struct qdpack_hilbert_space_t { int nsubsys; int *nstates; }


decompiled_code:
double __fastcall qdpack_entanglement_log_neg(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // r12
__int64 v4; // r13
double v5; // xmm2_8
double v6; // xmm0_8
double v8; // [rsp+8h] [rbp-30h]

v1 = 0LL;
v2 = qdpack_matrix_alloc(4LL, 4LL);
qdpack_matrix_memcpy(v2, *(_QWORD *)(a1 + 16));
qdpack_operator_get(a1, 2LL, 0LL);
qdpack_matrix_set(v2, 0LL, 2LL);
qdpack_operator_get(a1, 2LL, 1LL);
qdpack_matrix_set(v2, 0LL, 3LL);
qdpack_operator_get(a1, 3LL, 0LL);
qdpack_matrix_set(v2, 1LL, 2LL);
qdpack_operator_get(a1, 3LL, 1LL);
qdpack_matrix_set(v2, 1LL, 3LL);
qdpack_operator_get(a1, 0LL, 2LL);
qdpack_matrix_set(v2, 2LL, 0LL);
qdpack_operator_get(a1, 0LL, 3LL);
qdpack_matrix_set(v2, 2LL, 1LL);
qdpack_operator_get(a1, 1LL, 2LL);
qdpack_matrix_set(v2, 3LL, 0LL);
qdpack_operator_get(a1, 1LL, 3LL);
qdpack_matrix_set(v2, 3LL, 1LL);
v3 = qdpack_matrix_alloc(4LL, 1LL);
v4 = qdpack_matrix_alloc(4LL, 4LL);
qdpack_matrix_eigen_hermv(v2, v3, v4, 0LL);
v5 = 0.0;
do
{
v6 = qdpack_matrix_get(v3, v1++, 0LL);
v5 = v5 + gsl_complex_abs(v6);
}
while ( v1 != 4 );
v8 = log2(v5);
qdpack_matrix_free(v2);
qdpack_matrix_free(v3);
qdpack_matrix_free(v4);
return v8;
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // r12
__int64 v4; // r13
double v5; // xmm2_8
double v6; // xmm0_8
double v8; // [rsp+8h] [rbp-30h]

v1 = 0LL;
v2 = qdpack_matrix_alloc(4LL, 4LL);
qdpack_matrix_memcpy(v2, *(_QWORD *)(a1 + 16));
qdpack_operator_get(a1, 2LL, 0LL);
qdpack_matrix_set(v2, 0LL, 2LL);
qdpack_operator_get(a1, 2LL, 1LL);
qdpack_matrix_set(v2, 0LL, 3LL);
qdpack_operator_get(a1, 3LL, 0LL);
qdpack_matrix_set(v2, 1LL, 2LL);
qdpack_operator_get(a1, 3LL, 1LL);
qdpack_matrix_set(v2, 1LL, 3LL);
qdpack_operator_get(a1, 0LL, 2LL);
qdpack_matrix_set(v2, 2LL, 0LL);
qdpack_operator_get(a1, 0LL, 3LL);
qdpack_matrix_set(v2, 2LL, 1LL);
qdpack_operator_get(a1, 1LL, 2LL);
qdpack_matrix_set(v2, 3LL, 0LL);
qdpack_operator_get(a1, 1LL, 3LL);
qdpack_matrix_set(v2, 3LL, 1LL);
v3 = qdpack_matrix_alloc(4LL, 1LL);
v4 = qdpack_matrix_alloc(4LL, 4LL);
qdpack_matrix_eigen_hermv(v2, v3, v4, 0LL);
v5 = 0.0;
do
{
v6 = qdpack_matrix_get(v3, v1++, 0LL);
v5 = v5 + gsl_complex_abs(v6);
}
while ( v1 != 4 );
v8 = log2(v5);
qdpack_matrix_free(v2);
qdpack_matrix_free(v3);
qdpack_matrix_free(v4);
return v8;
}

original_code:
double
qdpack_entanglement_log_neg(qdpack_operator_t *rho)
{
    int i;
    double ln, sum_eval;
    qdpack_matrix_t *rho_pt;
    qdpack_matrix_t *eval, *evec;
    rho_pt = qdpack_matrix_alloc(4,4);
    qdpack_matrix_memcpy(rho_pt, rho->data);
    qdpack_matrix_set(rho_pt, 0, 2, qdpack_operator_get(rho, 2, 0));
    qdpack_matrix_set(rho_pt, 0, 3, qdpack_operator_get(rho, 2, 1));
    qdpack_matrix_set(rho_pt, 1, 2, qdpack_operator_get(rho, 3, 0));
    qdpack_matrix_set(rho_pt, 1, 3, qdpack_operator_get(rho, 3, 1));
    qdpack_matrix_set(rho_pt, 2, 0, qdpack_operator_get(rho, 0, 2));
    qdpack_matrix_set(rho_pt, 2, 1, qdpack_operator_get(rho, 0, 3));
    qdpack_matrix_set(rho_pt, 3, 0, qdpack_operator_get(rho, 1, 2));
    qdpack_matrix_set(rho_pt, 3, 1, qdpack_operator_get(rho, 1, 3));
    eval = qdpack_matrix_alloc(4, 1);
    evec = qdpack_matrix_alloc(4, 4);
    qdpack_matrix_eigen_hermv(rho_pt, eval, evec, 0);
    sum_eval = 0;
    for (i = 0; i < 4; i++)
    {
        sum_eval += gsl_complex_abs(qdpack_matrix_get(eval, i, 0));
    }
    ln = log2(sum_eval);
    qdpack_matrix_free(rho_pt);
    qdpack_matrix_free(eval);
    qdpack_matrix_free(evec);
    return ln;
}

canonical_original_code:
double qdpack_entanglement_log_neg(struct _qdpack_operator_t *rho)
{
    int i;
    double ln; double sum_eval;
    struct _qdpack_matrix *rho_pt;
    struct _qdpack_matrix *eval; struct _qdpack_matrix *evec;
    rho_pt = qdpack_matrix_alloc(4,4);
    qdpack_matrix_memcpy(rho_pt, rho->data);
    qdpack_matrix_set(rho_pt, 0, 2, qdpack_operator_get(rho, 2, 0));
    qdpack_matrix_set(rho_pt, 0, 3, qdpack_operator_get(rho, 2, 1));
    qdpack_matrix_set(rho_pt, 1, 2, qdpack_operator_get(rho, 3, 0));
    qdpack_matrix_set(rho_pt, 1, 3, qdpack_operator_get(rho, 3, 1));
    qdpack_matrix_set(rho_pt, 2, 0, qdpack_operator_get(rho, 0, 2));
    qdpack_matrix_set(rho_pt, 2, 1, qdpack_operator_get(rho, 0, 3));
    qdpack_matrix_set(rho_pt, 3, 0, qdpack_operator_get(rho, 1, 2));
    qdpack_matrix_set(rho_pt, 3, 1, qdpack_operator_get(rho, 1, 3));
    eval = qdpack_matrix_alloc(4, 1);
    evec = qdpack_matrix_alloc(4, 4);
    qdpack_matrix_eigen_hermv(rho_pt, eval, evec, 0);
    sum_eval = 0;
    for (i = 0; i < 4; i++)
    {
        sum_eval += gsl_complex_abs(qdpack_matrix_get(eval, i, 0));
    }
    ln = log2(sum_eval);
    qdpack_matrix_free(rho_pt);
    qdpack_matrix_free(eval);
    qdpack_matrix_free(evec);
    return ln;
}

variable_types: ln double

user_defined_types: struct gsl_block_complex_struct { unsigned long size; double *data; }


decompiled_code:
double __fastcall qdpack_entanglement_concurrence(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // r12
__int64 v4; // r15
__int64 v5; // r14
__int64 v6; // r13
double v7; // xmm0_8
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8
__int64 v11; // rbx
__int64 v12; // rsi
double v13; // xmm0_8
__int64 v14; // rbx
__int64 i; // r14
__int64 v16; // rdx
double v17; // xmm0_8
double v18; // xmm0_8
double v19; // rbx
double v20; // rbx
double v21; // rbx
__int64 v23; // [rsp+0h] [rbp-88h]
__int64 v24; // [rsp+8h] [rbp-80h]
__int64 v25; // [rsp+10h] [rbp-78h]
double v26; // [rsp+18h] [rbp-70h]
double v27; // [rsp+20h] [rbp-68h]
double v28; // [rsp+20h] [rbp-68h]
double v29; // [rsp+20h] [rbp-68h]
double v30; // [rsp+20h] [rbp-68h]
double v31; // [rsp+20h] [rbp-68h]
double v32; // [rsp+30h] [rbp-58h]
double v33; // [rsp+40h] [rbp-48h]

v2 = qdpack_matrix_alloc(4LL, 1LL);
v3 = qdpack_matrix_alloc(4LL, 4LL);
v4 = qdpack_operator_alloc(a1);
v5 = qdpack_operator_alloc(a1);
operator_sigma_y(v4, a1, 0LL);
v23 = v5;
operator_sigma_y(v5, a1, 1LL);
v6 = qdpack_operator_alloc(a1);
v24 = qdpack_operator_alloc(a1);
v25 = qdpack_operator_alloc(a1);
v27 = gsl_complex_rect(0.0);
v7 = gsl_complex_rect(1.0);
qdpack_operator_blas_zgemm(111LL, 111LL, v4, v5, v6, v7, 0.0, v27, 0.0);
v28 = gsl_complex_rect(0.0);
v8 = gsl_complex_rect(1.0);
qdpack_operator_blas_zgemm(111LL, 111LL, a2, v6, v24, v8, 0.0, v28, 0.0);
v29 = gsl_complex_rect(0.0);
v9 = gsl_complex_rect(1.0);
qdpack_operator_blas_zgemm(113LL, 111LL, a2, v6, v25, v9, 0.0, v29, 0.0);
v30 = gsl_complex_rect(0.0);
v10 = gsl_complex_rect(1.0);
v11 = 0LL;
qdpack_operator_blas_zgemm(111LL, 111LL, v24, v25, v6, v10, 0.0, v30, 0.0);
puts("rr = ");
qdpack_operator_print(v6);
qdpack_matrix_eigen_zgeev(*(_QWORD *)(v6 + 16), v2, v3, 0LL);
puts("Eigenvalues = ");
do
{
v12 = v11++;
v13 = qdpack_matrix_get(v2, v12, 0LL);
printf("\t(%f, %f)", v13, 0.0);
}
while ( v11 != 4 );
v14 = 0LL;
putchar(10);
puts("evec = ");
do
{
for ( i = 0LL; i != 4; ++i )
{
v16 = i;
v17 = qdpack_matrix_get(v3, v14, v16);
printf("\t(%f, %f)", v17, 0.0);
}
++v14;
putchar(10);
}
while ( v14 != 4 );
qdpack_matrix_get(v2, 3LL, 0LL);
v33 = qdpack_matrix_get(v2, 3LL, 0LL);
qdpack_matrix_get(v2, 2LL, 0LL);
v32 = qdpack_matrix_get(v2, 2LL, 0LL);
qdpack_matrix_get(v2, 1LL, 0LL);
v31 = qdpack_matrix_get(v2, 1LL, 0LL);
qdpack_matrix_get(v2, 0LL, 0LL);
v18 = qdpack_matrix_get(v2, 0LL, 0LL);
printf("c: eigvals: (%f, %f), (%f, %f), (%f, %f), (%f, %f)\n", v18, 0.0, v31, 0.0, v32, 0.0, v33, 0.0);
v19 = qdpack_matrix_get(v2, 0LL, 0LL);
v20 = v19 - qdpack_matrix_get(v2, 1LL, 0LL);
v21 = v20 - qdpack_matrix_get(v2, 2LL, 0LL);
v26 = fmax(0.0, v21 - qdpack_matrix_get(v2, 3LL, 0LL));
qdpack_operator_free(v4);
qdpack_operator_free(v23);
qdpack_operator_free(v6);
qdpack_operator_free(v24);
qdpack_operator_free(v25);
qdpack_matrix_free(v3);
qdpack_matrix_free(v2);
return v26;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // r12
__int64 v4; // r15
__int64 v5; // r14
__int64 v6; // r13
double v7; // xmm0_8
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8
__int64 v11; // rbx
__int64 v12; // rsi
double v13; // xmm0_8
__int64 v14; // rbx
__int64 i; // r14
__int64 v16; // rdx
double v17; // xmm0_8
double v18; // xmm0_8
double v19; // rbx
double v20; // rbx
double v21; // rbx
__int64 v23; // [rsp+0h] [rbp-88h]
__int64 v24; // [rsp+8h] [rbp-80h]
__int64 v25; // [rsp+10h] [rbp-78h]
double v26; // [rsp+18h] [rbp-70h]
double v27; // [rsp+20h] [rbp-68h]
double v28; // [rsp+20h] [rbp-68h]
double v29; // [rsp+20h] [rbp-68h]
double v30; // [rsp+20h] [rbp-68h]
double v31; // [rsp+20h] [rbp-68h]
double v32; // [rsp+30h] [rbp-58h]
double v33; // [rsp+40h] [rbp-48h]

v2 = qdpack_matrix_alloc(4LL, 1LL);
v3 = qdpack_matrix_alloc(4LL, 4LL);
v4 = qdpack_operator_alloc(a1);
v5 = qdpack_operator_alloc(a1);
operator_sigma_y(v4, a1, 0LL);
v23 = v5;
operator_sigma_y(v5, a1, 1LL);
v6 = qdpack_operator_alloc(a1);
v24 = qdpack_operator_alloc(a1);
v25 = qdpack_operator_alloc(a1);
v27 = gsl_complex_rect(0.0);
v7 = gsl_complex_rect(1.0);
qdpack_operator_blas_zgemm(111LL, 111LL, v4, v5, v6, v7, 0.0, v27, 0.0);
v28 = gsl_complex_rect(0.0);
v8 = gsl_complex_rect(1.0);
qdpack_operator_blas_zgemm(111LL, 111LL, a2, v6, v24, v8, 0.0, v28, 0.0);
v29 = gsl_complex_rect(0.0);
v9 = gsl_complex_rect(1.0);
qdpack_operator_blas_zgemm(113LL, 111LL, a2, v6, v25, v9, 0.0, v29, 0.0);
v30 = gsl_complex_rect(0.0);
v10 = gsl_complex_rect(1.0);
v11 = 0LL;
qdpack_operator_blas_zgemm(111LL, 111LL, v24, v25, v6, v10, 0.0, v30, 0.0);
puts("rr = ");
qdpack_operator_print(v6);
qdpack_matrix_eigen_zgeev(*(_QWORD *)(v6 + 16), v2, v3, 0LL);
puts("Eigenvalues = ");
do
{
v12 = v11++;
v13 = qdpack_matrix_get(v2, v12, 0LL);
printf("\t(%f, %f)", v13, 0.0);
}
while ( v11 != 4 );
v14 = 0LL;
putchar(10);
puts("evec = ");
do
{
for ( i = 0LL; i != 4; ++i )
{
v16 = i;
v17 = qdpack_matrix_get(v3, v14, v16);
printf("\t(%f, %f)", v17, 0.0);
}
++v14;
putchar(10);
}
while ( v14 != 4 );
qdpack_matrix_get(v2, 3LL, 0LL);
v33 = qdpack_matrix_get(v2, 3LL, 0LL);
qdpack_matrix_get(v2, 2LL, 0LL);
v32 = qdpack_matrix_get(v2, 2LL, 0LL);
qdpack_matrix_get(v2, 1LL, 0LL);
v31 = qdpack_matrix_get(v2, 1LL, 0LL);
qdpack_matrix_get(v2, 0LL, 0LL);
v18 = qdpack_matrix_get(v2, 0LL, 0LL);
printf("c: eigvals: (%f, %f), (%f, %f), (%f, %f), (%f, %f)\n", v18, 0.0, v31, 0.0, v32, 0.0, v33, 0.0);
v19 = qdpack_matrix_get(v2, 0LL, 0LL);
v20 = v19 - qdpack_matrix_get(v2, 1LL, 0LL);
v21 = v20 - qdpack_matrix_get(v2, 2LL, 0LL);
v26 = fmax(0.0, v21 - qdpack_matrix_get(v2, 3LL, 0LL));
qdpack_operator_free(v4);
qdpack_operator_free(v23);
qdpack_operator_free(v6);
qdpack_operator_free(v24);
qdpack_operator_free(v25);
qdpack_matrix_free(v3);
qdpack_matrix_free(v2);
return v26;
}

original_code:
double
qdpack_entanglement_concurrence(qdpack_hilbert_space_t *qs, qdpack_operator_t *rho)
{
    double c = 0.0;
    qdpack_operator_t *y1, *y2, *y, *ws1, *ws2;
    qdpack_matrix_t *eval = qdpack_matrix_alloc(4, 1);
    qdpack_matrix_t *evec = qdpack_matrix_alloc(4, 4);
    y1 = qdpack_operator_alloc(qs);
    y2 = qdpack_operator_alloc(qs);
    operator_sigma_y(y1, qs, 0);
    operator_sigma_y(y2, qs, 1);
    y = qdpack_operator_alloc(qs);
    ws1 = qdpack_operator_alloc(qs);
    ws2 = qdpack_operator_alloc(qs);
    qdpack_operator_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), y1, y2, (gsl_complex_rect(0.0,0.0)), y);
    qdpack_operator_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), rho, y, (gsl_complex_rect(0.0,0.0)), ws1);
    qdpack_operator_blas_zgemm(CblasConjTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), rho, y, (gsl_complex_rect(0.0,0.0)), ws2);
    qdpack_operator_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), ws1, ws2, (gsl_complex_rect(0.0,0.0)), y);
    printf("rr = \n"); qdpack_operator_print(y);
    qdpack_matrix_eigen_zgeev(y->data, eval, evec, 0);
    {
        int i, j, n = 4;
        printf("Eigenvalues = \n");
        for (i = 0; i < n; i++)
        {
                gsl_complex z;
                z = qdpack_matrix_get(eval, i, 0);
                printf("\t(%f, %f)", ((z).dat[0]), ((z).dat[1]));
        }
        printf("\n");
        printf("evec = \n");
        for (i = 0; i < n; i++)
        {
                for (j = 0; j < n; j++)
                {
                        gsl_complex z;
                        z = qdpack_matrix_get(evec, i, j);
                        printf("\t(%f, %f)", ((z).dat[0]), ((z).dat[1]));
                }
                printf("\n");
        }
    }
    printf("c: eigvals: (%f, %f), (%f, %f), (%f, %f), (%f, %f)\n",
           ((qdpack_matrix_get(eval, 0, 0)).dat[0]), ((qdpack_matrix_get(eval, 0, 0)).dat[1]),
           ((qdpack_matrix_get(eval, 1, 0)).dat[0]), ((qdpack_matrix_get(eval, 1, 0)).dat[1]),
           ((qdpack_matrix_get(eval, 2, 0)).dat[0]), ((qdpack_matrix_get(eval, 2, 0)).dat[1]),
           ((qdpack_matrix_get(eval, 3, 0)).dat[0]), ((qdpack_matrix_get(eval, 3, 0)).dat[1]));
    c = + ((qdpack_matrix_get(eval, 0, 0)).dat[0]) - ((qdpack_matrix_get(eval, 1, 0)).dat[0])
        - ((qdpack_matrix_get(eval, 2, 0)).dat[0]) - ((qdpack_matrix_get(eval, 3, 0)).dat[0]);
    c = (c < 0.0) ? 0.0 : c;
    qdpack_operator_free(y1);
    qdpack_operator_free(y2);
    qdpack_operator_free(y);
    qdpack_operator_free(ws1);
    qdpack_operator_free(ws2);
    qdpack_matrix_free(evec);
    qdpack_matrix_free(eval);
    return c;
}

canonical_original_code:
double qdpack_entanglement_concurrence(struct qdpack_hilbert_space_t *qs, struct _qdpack_operator_t *rho)
{
    double c = 0.0;
    struct _qdpack_operator_t *y1; struct _qdpack_operator_t *y2; struct _qdpack_operator_t *y; struct _qdpack_operator_t *ws1; struct _qdpack_operator_t *ws2;
    struct _qdpack_matrix *eval = qdpack_matrix_alloc(4, 1);
    struct _qdpack_matrix *evec = qdpack_matrix_alloc(4, 4);
    y1 = qdpack_operator_alloc(qs);
    y2 = qdpack_operator_alloc(qs);
    operator_sigma_y(y1, qs, 0);
    operator_sigma_y(y2, qs, 1);
    y = qdpack_operator_alloc(qs);
    ws1 = qdpack_operator_alloc(qs);
    ws2 = qdpack_operator_alloc(qs);
    qdpack_operator_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), y1, y2, (gsl_complex_rect(0.0,0.0)), y);
    qdpack_operator_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), rho, y, (gsl_complex_rect(0.0,0.0)), ws1);
    qdpack_operator_blas_zgemm(CblasConjTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), rho, y, (gsl_complex_rect(0.0,0.0)), ws2);
    qdpack_operator_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), ws1, ws2, (gsl_complex_rect(0.0,0.0)), y);
    printf("rr = \n"); qdpack_operator_print(y);
    qdpack_matrix_eigen_zgeev(y->data, eval, evec, 0);
    {
        int i; int j; int n = 4;
        printf("Eigenvalues = \n");
        for (i = 0; i < n; i++)
        {
                struct gsl_complex z;
                z = qdpack_matrix_get(eval, i, 0);
                printf("\t(%f, %f)", ((z).dat[0]), ((z).dat[1]));
        }
        printf("\n");
        printf("evec = \n");
        for (i = 0; i < n; i++)
        {
                for (j = 0; j < n; j++)
                {
                        struct gsl_complex z;
                        z = qdpack_matrix_get(evec, i, j);
                        printf("\t(%f, %f)", ((z).dat[0]), ((z).dat[1]));
                }
                printf("\n");
        }
    }
    printf("c: eigvals: (%f, %f), (%f, %f), (%f, %f), (%f, %f)\n",
           ((qdpack_matrix_get(eval, 0, 0)).dat[0]), ((qdpack_matrix_get(eval, 0, 0)).dat[1]),
           ((qdpack_matrix_get(eval, 1, 0)).dat[0]), ((qdpack_matrix_get(eval, 1, 0)).dat[1]),
           ((qdpack_matrix_get(eval, 2, 0)).dat[0]), ((qdpack_matrix_get(eval, 2, 0)).dat[1]),
           ((qdpack_matrix_get(eval, 3, 0)).dat[0]), ((qdpack_matrix_get(eval, 3, 0)).dat[1]));
    c = + ((qdpack_matrix_get(eval, 0, 0)).dat[0]) - ((qdpack_matrix_get(eval, 1, 0)).dat[0])
        - ((qdpack_matrix_get(eval, 2, 0)).dat[0]) - ((qdpack_matrix_get(eval, 3, 0)).dat[0]);
    c = (c < 0.0) ? 0.0 : c;
    qdpack_operator_free(y1);
    qdpack_operator_free(y2);
    qdpack_operator_free(y);
    qdpack_operator_free(ws1);
    qdpack_operator_free(ws2);
    qdpack_matrix_free(evec);
    qdpack_matrix_free(eval);
    return c;
}

variable_types: struct qdpack_hilbert_space_t { int nsubsys; int *nstates; } *

variable_types: struct _qdpack_operator_t { int n; struct qdpack_hilbert_space_t *qs; struct _qdpack_matrix { int n; struct gsl_matrix_complex { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_complex_struct { unsigned long size; double *data; } *block; int owner; } *data; } *data; } *

variable_types: c double

variable_types: n int


decompiled_code:
__int64 __fastcall gsl_ext_matrix_convert(_QWORD *a1, _QWORD *a2)
{
unsigned int v2; // er13
__int64 i; // rbx
unsigned int v4; // er14
__int64 v5; // r12
double v6; // xmm0_8

if ( *a2 != *a1 )
return 0xFFFFFFFFLL;
if ( a2[1] != a1[1] )
return 0xFFFFFFFFLL;
v2 = 0;
for ( i = 0LL; *a2 > (unsigned __int64)v2; i = v2 )
{
v4 = 0;
v5 = 0LL;
do
{
v6 = gsl_matrix_get(a2, i, v5);
gsl_matrix_complex_set(a1, i, v5, v6, 0.0);
v5 = ++v4;
}
while ( (unsigned __int64)v4 < *a2 );
++v2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2)
{
unsigned int v2; // er13
__int64 i; // rbx
unsigned int v4; // er14
__int64 v5; // r12
double v6; // xmm0_8

if ( *a2 != *a1 )
return 0xFFFFFFFFLL;
if ( a2[1] != a1[1] )
return 0xFFFFFFFFLL;
v2 = 0;
for ( i = 0LL; *a2 > (unsigned __int64)v2; i = v2 )
{
v4 = 0;
v5 = 0LL;
do
{
v6 = gsl_matrix_get(a2, i, v5);
gsl_matrix_complex_set(a1, i, v5, v6, 0.0);
v5 = ++v4;
}
while ( (unsigned __int64)v4 < *a2 );
++v2;
}
return 0LL;
}

original_code:
int
gsl_ext_matrix_convert(gsl_matrix_complex *dst, gsl_matrix *src)
{
    unsigned int i, j;
    gsl_complex z;
    if (src->size1 != dst->size1 || src->size2 != dst->size2)
        return -1;
    for (i = 0; i < src->size1; i++)
    {
        for (j = 0; j < src->size1; j++)
        {
            do {(&z)->dat[0]=(gsl_matrix_get(src, i, j)); (&z)->dat[1]=(0.0);} while(0);
            gsl_matrix_complex_set(dst, i, j, z);
        }
    }
    return 0;
}

canonical_original_code:
int gsl_ext_matrix_convert(struct gsl_matrix_complex *dst, struct gsl_matrix *src)
{
    unsigned int i; unsigned int j;
    struct gsl_complex z;
    if (src->size1 != dst->size1 || src->size2 != dst->size2)
        return -1;
    for (i = 0; i < src->size1; i++)
    {
        for (j = 0; j < src->size1; j++)
        {
            do {(&z)->dat[0]=(gsl_matrix_get(src, i, j)); (&z)->dat[1]=(0.0);} while(0);
            gsl_matrix_complex_set(dst, i, j, z);
        }
    }
    return 0;
}

variable_types: struct gsl_matrix_complex { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_complex_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

return_type: int

user_defined_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }


decompiled_code:
__int64 __fastcall gsl_ext_expm_complex(_QWORD *a1, __int64 a2)
{
int v2; // er14
__int64 v3; // r13
__int64 v4; // rbp

v2 = 50;
v3 = gsl_matrix_complex_alloc(*a1, a1[1]);
v4 = gsl_matrix_complex_alloc(*a1, a1[1]);
gsl_matrix_complex_set_identity(v3);
gsl_matrix_complex_set_identity(a2);
do
{
gsl_matrix_complex_scale(a2, 1.0 / (double)v2, 0.0);
gsl_blas_zgemm(111LL, 111LL, a2, a1, v4, 1.0, 0.0, 0.0, 0.0);
gsl_matrix_complex_add(v4, v3);
gsl_matrix_complex_memcpy(a2, v4);
--v2;
}
while ( v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2)
{
int v2; // er14
__int64 v3; // r13
__int64 v4; // rbp

v2 = 50;
v3 = gsl_matrix_complex_alloc(*a1, a1[1]);
v4 = gsl_matrix_complex_alloc(*a1, a1[1]);
gsl_matrix_complex_set_identity(v3);
gsl_matrix_complex_set_identity(a2);
do
{
gsl_matrix_complex_scale(a2, 1.0 / (double)v2, 0.0);
gsl_blas_zgemm(111LL, 111LL, a2, a1, v4, 1.0, 0.0, 0.0, 0.0);
gsl_matrix_complex_add(v4, v3);
gsl_matrix_complex_memcpy(a2, v4);
--v2;
}
while ( v2 );
return 0LL;
}

original_code:
int
gsl_ext_expm_complex(gsl_matrix_complex *A, gsl_matrix_complex *eA)
{
    int i;
    gsl_complex alpha, beta, z;
    gsl_matrix_complex *I, *T;
    I = gsl_matrix_complex_alloc(A->size1, A->size2);
    T = gsl_matrix_complex_alloc(A->size1, A->size2);
    do {(&alpha)->dat[0]=(1.0); (&alpha)->dat[1]=(0.0);} while(0);
    do {(&beta)->dat[0]=(0.0); (&beta)->dat[1]=(0.0);} while(0);
    gsl_matrix_complex_set_identity(I);
    gsl_matrix_complex_set_identity(eA);
    for (i = 50; i > 0; i--)
    {
        do {(&z)->dat[0]=(1.0 / i); (&z)->dat[1]=(0.0);} while(0);
        gsl_matrix_complex_scale(eA, z);
        gsl_blas_zgemm(CblasNoTrans, CblasNoTrans, alpha, eA, A, beta, T);
        gsl_matrix_complex_add(T, I);
        gsl_matrix_complex_memcpy(eA, T);
    }
    return 0;
}

canonical_original_code:
int gsl_ext_expm_complex(struct gsl_matrix_complex *A, struct gsl_matrix_complex *eA)
{
    int i;
    struct gsl_complex alpha; struct gsl_complex beta; struct gsl_complex z;
    struct gsl_matrix_complex *I; struct gsl_matrix_complex *T;
    I = gsl_matrix_complex_alloc(A->size1, A->size2);
    T = gsl_matrix_complex_alloc(A->size1, A->size2);
    do {(&alpha)->dat[0]=(1.0); (&alpha)->dat[1]=(0.0);} while(0);
    do {(&beta)->dat[0]=(0.0); (&beta)->dat[1]=(0.0);} while(0);
    gsl_matrix_complex_set_identity(I);
    gsl_matrix_complex_set_identity(eA);
    for (i = 50; i > 0; i--)
    {
        do {(&z)->dat[0]=(1.0 / i); (&z)->dat[1]=(0.0);} while(0);
        gsl_matrix_complex_scale(eA, z);
        gsl_blas_zgemm(CblasNoTrans, CblasNoTrans, alpha, eA, A, beta, T);
        gsl_matrix_complex_add(T, I);
        gsl_matrix_complex_memcpy(eA, T);
    }
    return 0;
}

variable_types:
eA
struct gsl_matrix_complex *

variable_types: i int

variable_types:
alpha
struct gsl_complex { double dat[2]; }

variable_types:
beta
struct gsl_complex { double dat[2]; }


original_code:
int
gsl_ext_eigen_zgeev(gsl_matrix_complex *A_gsl, gsl_matrix_complex *evec, gsl_vector_complex *eval)
{
    integer n,i,j,info,lwork, ldvl, ldvr, lda;
    doublecomplex *A,*vr,*vl,*w,*work;
    doublereal *rwork;
    char jobvl,jobvr;
    n = A_gsl->size1;
    A = (doublecomplex *)malloc((size_t)n * n * sizeof(doublecomplex));
    w = (doublecomplex *)malloc((size_t)n * sizeof(doublecomplex));
    vr = (doublecomplex *)malloc((size_t)n * n * sizeof(doublecomplex));
    vl = (doublecomplex *)malloc((size_t)n * n * sizeof(doublecomplex));
    lwork = 16 * n;
    work = (doublecomplex *)malloc((size_t)lwork * sizeof(doublecomplex));
    rwork = (doublereal *)malloc((size_t)lwork * sizeof(doublereal));
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            gsl_complex z;
            double re,im;
            z = gsl_matrix_complex_get(A_gsl, i, j);
            re = ((z).dat[0]);
            im = ((z).dat[1]);
            A[j*n+i] = (doublecomplex){re,im};
        }
    }
    jobvl='N';
    jobvr='V';
    lda = n;
    ldvr = n;
    ldvl = n;
    zgeev_(&jobvl, &jobvr, &n, A, &lda, w, vl, &ldvl, vr, &ldvr, work, &lwork, rwork, &info);
    for (i = 0; i < n; i++)
    {
        gsl_complex z;
        do {(&z)->dat[0]=(w[i].r); (&z)->dat[1]=(w[i].i);} while(0);
        gsl_vector_complex_set(eval, i, z);
    }
    for (j = 0; j < n; j++)
    {
        for (i = 0; i < n; i++)
        {
            gsl_complex z;
            do {(&z)->dat[0]=(vr[j*n+i].r); (&z)->dat[1]=(vr[j*n+i].i);} while(0);
            gsl_matrix_complex_set(evec, i, j, z);
        }
    }
    if (info != 0)
    {
        printf("zgeev_: error: info = %d\n", (int)info);
    }
    free(A);
    free(w);
    free(vr);
    free(vl);
    free(work);
    free(rwork);
    return 0;
}

canonical_original_code:
int gsl_ext_eigen_zgeev(struct gsl_matrix_complex *A_gsl, struct gsl_matrix_complex *evec, struct gsl_vector_complex *eval)
{
    int n; int i; int j; int info; int lwork; int ldvl; int ldvr; int lda;
    struct doublecomplex *A; struct doublecomplex *vr; struct doublecomplex *vl; struct doublecomplex *w; struct doublecomplex *work;
    double *rwork;
    char jobvl; char jobvr;
    n = A_gsl->size1;
    A = (struct doublecomplex *)malloc((unsigned long)n * n * sizeof(doublecomplex));
    w = (struct doublecomplex *)malloc((unsigned long)n * sizeof(doublecomplex));
    vr = (struct doublecomplex *)malloc((unsigned long)n * n * sizeof(doublecomplex));
    vl = (struct doublecomplex *)malloc((unsigned long)n * n * sizeof(doublecomplex));
    lwork = 16 * n;
    work = (struct doublecomplex *)malloc((unsigned long)lwork * sizeof(doublecomplex));
    rwork = (double *)malloc((unsigned long)lwork * sizeof(doublereal));
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            struct gsl_complex z;
            double re; double im;
            z = gsl_matrix_complex_get(A_gsl, i, j);
            re = ((z).dat[0]);
            im = ((z).dat[1]);
            A[j*n+i] = (struct doublecomplex){re,im};
        }
    }
    jobvl='N';
    jobvr='V';
    lda = n;
    ldvr = n;
    ldvl = n;
    zgeev_(&jobvl, &jobvr, &n, A, &lda, w, vl, &ldvl, vr, &ldvr, work, &lwork, rwork, &info);
    for (i = 0; i < n; i++)
    {
        struct gsl_complex z;
        do {(&z)->dat[0]=(w[i].r); (&z)->dat[1]=(w[i].i);} while(0);
        gsl_vector_complex_set(eval, i, z);
    }
    for (j = 0; j < n; j++)
    {
        for (i = 0; i < n; i++)
        {
            struct gsl_complex z;
            do {(&z)->dat[0]=(vr[j*n+i].r); (&z)->dat[1]=(vr[j*n+i].i);} while(0);
            gsl_matrix_complex_set(evec, i, j, z);
        }
    }
    if (info != 0)
    {
        printf("zgeev_: error: info = %d\n", (int)info);
    }
    free(A);
    free(w);
    free(vr);
    free(vl);
    free(work);
    free(rwork);
    return 0;
}

variable_types:
evec
struct gsl_matrix_complex *

variable_types: struct gsl_vector_complex { unsigned long size; unsigned long stride; double *data; struct gsl_block_complex_struct *block; int owner; } *

variable_types: j int

variable_types: info int

variable_types: lwork int

variable_types: ldvl int

variable_types: ldvr int

variable_types: lda int

variable_types:
A
struct doublecomplex { double r; } *

variable_types:
vr
struct doublecomplex { double r; } *

variable_types:
vl
struct doublecomplex { double r; } *

variable_types:
w
struct doublecomplex { double r; } *

variable_types:
work
struct doublecomplex { double r; } *

variable_types:
rwork
double *

variable_types: jobvl char

variable_types: jobvr char

variable_types:
z
struct gsl_complex { double dat[2]; }

variable_types: re double

variable_types: im double


decompiled_code:
__int64 __fastcall gsl_ext_eigen_sort(_QWORD *a1, unsigned __int64 *a2, int a3, double a4, double a5)
{
_QWORD *v5; // r13
__int64 v6; // rdi
__int64 v9; // r14
int *v10; // rbp
unsigned __int64 v11; // rax
__int64 v12; // rdx
unsigned __int64 v13; // rdx
unsigned __int64 i; // r12
int v15; // er13
double v16; // xmm0_8
unsigned __int64 v17; // r12
__int64 v18; // r13
unsigned __int64 v19; // r15
double v20; // xmm0_8
__int64 v21; // rdx
double v22; // xmm0_8
__int64 v23; // rsi
double v25; // xmm0_8
double v26; // xmm2_8
double v28; // [rsp+8h] [rbp-50h]
double v29; // [rsp+8h] [rbp-50h]
unsigned __int64 v30; // [rsp+10h] [rbp-48h]
unsigned __int64 v31; // [rsp+10h] [rbp-48h]
__int64 v32; // [rsp+18h] [rbp-40h]

v5 = a1;
v6 = *a1;
if ( v6 != v5[1] || v6 != *a2 )
return 0xFFFFFFFFLL;
v9 = gsl_matrix_complex_alloc(v6, v6);
v32 = gsl_vector_complex_alloc(*a2);
v10 = (int *)malloc(4 * *a2);
gsl_matrix_complex_memcpy(v9, v5);
gsl_vector_complex_memcpy(v32, a2);
v11 = *a2;
v12 = 0LL;
if ( *a2 )
{
do
{
v10[v12] = v12;
++v12;
}
while ( v12 != v11 );
if ( v11 == 1 )
{
LABEL_18:
v17 = 0LL;
do
{
v18 = v10[v17];
v19 = 0LL;
do
{
v20 = gsl_matrix_complex_get(v9, v18, v19);
v21 = v19++;
gsl_matrix_complex_set(a1, v17, v21, v20, a5);
}
while ( *a2 > v19 );
v22 = gsl_vector_complex_get(v32);
v23 = v17++;
gsl_vector_complex_set(a2, v23, v22, a5);
}
while ( *a2 > v17 );
goto LABEL_22;
}
}
v13 = 0LL;
do
{
if ( ++v13 < v11 )
{
for ( i = v13; v11 > i; ++i )
{
while ( !a3 )
{
v30 = v13;
v15 = v10[v13 - 1];
gsl_vector_complex_get(a2);
v28 = gsl_complex_abs(a2);
gsl_vector_complex_get(a2);
v16 = gsl_complex_abs(a2);
v13 = v30;
if ( v28 > v16 )
goto LABEL_13;
LABEL_15:
v11 = *a2;
if ( *a2 <= ++i )
goto LABEL_16;
}
if ( a3 == 3 )
{
v31 = v13;
v15 = v10[v13 - 1];
gsl_vector_complex_get(a2);
v29 = gsl_complex_arg(a2);
gsl_vector_complex_get(a2);
v25 = gsl_complex_arg(a2);
v26 = v29;
v13 = v31;
if ( v29 > 3.141592653589793 )
v26 = v29 - 6.283185307179586;
a5 = *(double *)&LC5;
if ( v26 <= -3.141592653589793 )
v26 = v26 + 6.283185307179586;
if ( v25 > 3.141592653589793 )
v25 = v25 - 6.283185307179586;
if ( v25 <= -3.141592653589793 )
v25 = v25 + 6.283185307179586;
if ( v26 <= v25 )
goto LABEL_15;
LABEL_13:
if ( v15 != -1 )
{
v10[v13 - 1] = v10[i];
v10[i] = v15;
}
goto LABEL_15;
}
}
}
LABEL_16:
;
}
while ( v11 - 1 > v13 );
if ( v11 )
goto LABEL_18;
LABEL_22:
gsl_matrix_complex_free(v9);
gsl_vector_complex_free(v32);
free(v10);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, unsigned __int64 *a2, int a3, double a4, double a5)
{
_QWORD *v5; // r13
__int64 v6; // rdi
__int64 v9; // r14
int *v10; // rbp
unsigned __int64 v11; // rax
__int64 v12; // rdx
unsigned __int64 v13; // rdx
unsigned __int64 i; // r12
int v15; // er13
double v16; // xmm0_8
unsigned __int64 v17; // r12
__int64 v18; // r13
unsigned __int64 v19; // r15
double v20; // xmm0_8
__int64 v21; // rdx
double v22; // xmm0_8
__int64 v23; // rsi
double v25; // xmm0_8
double v26; // xmm2_8
double v28; // [rsp+8h] [rbp-50h]
double v29; // [rsp+8h] [rbp-50h]
unsigned __int64 v30; // [rsp+10h] [rbp-48h]
unsigned __int64 v31; // [rsp+10h] [rbp-48h]
__int64 v32; // [rsp+18h] [rbp-40h]

v5 = a1;
v6 = *a1;
if ( v6 != v5[1] || v6 != *a2 )
return 0xFFFFFFFFLL;
v9 = gsl_matrix_complex_alloc(v6, v6);
v32 = gsl_vector_complex_alloc(*a2);
v10 = (int *)malloc(4 * *a2);
gsl_matrix_complex_memcpy(v9, v5);
gsl_vector_complex_memcpy(v32, a2);
v11 = *a2;
v12 = 0LL;
if ( *a2 )
{
do
{
v10[v12] = v12;
++v12;
}
while ( v12 != v11 );
if ( v11 == 1 )
{
LABEL_18:
v17 = 0LL;
do
{
v18 = v10[v17];
v19 = 0LL;
do
{
v20 = gsl_matrix_complex_get(v9, v18, v19);
v21 = v19++;
gsl_matrix_complex_set(a1, v17, v21, v20, a5);
}
while ( *a2 > v19 );
v22 = gsl_vector_complex_get(v32);
v23 = v17++;
gsl_vector_complex_set(a2, v23, v22, a5);
}
while ( *a2 > v17 );
goto LABEL_22;
}
}
v13 = 0LL;
do
{
if ( ++v13 < v11 )
{
for ( i = v13; v11 > i; ++i )
{
while ( !a3 )
{
v30 = v13;
v15 = v10[v13 - 1];
gsl_vector_complex_get(a2);
v28 = gsl_complex_abs(a2);
gsl_vector_complex_get(a2);
v16 = gsl_complex_abs(a2);
v13 = v30;
if ( v28 > v16 )
goto LABEL_13;
LABEL_15:
v11 = *a2;
if ( *a2 <= ++i )
goto LABEL_16;
}
if ( a3 == 3 )
{
v31 = v13;
v15 = v10[v13 - 1];
gsl_vector_complex_get(a2);
v29 = gsl_complex_arg(a2);
gsl_vector_complex_get(a2);
v25 = gsl_complex_arg(a2);
v26 = v29;
v13 = v31;
if ( v29 > 3.141592653589793 )
v26 = v29 - 6.283185307179586;
a5 = *(double *)&LC5;
if ( v26 <= -3.141592653589793 )
v26 = v26 + 6.283185307179586;
if ( v25 > 3.141592653589793 )
v25 = v25 - 6.283185307179586;
if ( v25 <= -3.141592653589793 )
v25 = v25 + 6.283185307179586;
if ( v26 <= v25 )
goto LABEL_15;
LABEL_13:
if ( v15 != -1 )
{
v10[v13 - 1] = v10[i];
v10[i] = v15;
}
goto LABEL_15;
}
}
}
LABEL_16:
;
}
while ( v11 - 1 > v13 );
if ( v11 )
goto LABEL_18;
LABEL_22:
gsl_matrix_complex_free(v9);
gsl_vector_complex_free(v32);
free(v10);
return 0LL;
}

original_code:
int
gsl_ext_eigen_sort(gsl_matrix_complex *evec, gsl_vector_complex *eval, int sort_order)
{
    gsl_complex z;
      gsl_matrix_complex *evec_copy;
    gsl_vector_complex *eval_copy;
    int *idx_map, i, j, idx_temp;
    double p1, p2;
    if ((evec->size1 != evec->size2) || (evec->size1 != eval->size))
    {
        return -1;
    }
    evec_copy = gsl_matrix_complex_alloc(evec->size1, evec->size2);
    eval_copy = gsl_vector_complex_alloc(eval->size);
    idx_map = (int *)malloc(sizeof(int) * eval->size);
    gsl_matrix_complex_memcpy(evec_copy, evec);
    gsl_vector_complex_memcpy(eval_copy, eval);
    for (i = 0; i < eval->size; i++)
    {
        idx_map[i] = i;
    }
    for (i = 0; i < eval->size - 1; i++)
    {
        for (j = i+1; j < eval->size; j++)
        {
            idx_temp = -1;
            if (sort_order == 0)
            {
                p1 = gsl_complex_abs(gsl_vector_complex_get(eval, idx_map[i]));
                p2 = gsl_complex_abs(gsl_vector_complex_get(eval, idx_map[j]));
                if (p1 > p2)
                {
                    idx_temp = idx_map[i];
                }
            }
            if (sort_order == 3)
            {
                p1 = gsl_complex_arg(gsl_vector_complex_get(eval, idx_map[i]));
                p2 = gsl_complex_arg(gsl_vector_complex_get(eval, idx_map[j]));
                if (p1 > 3.14159265358979323846) p1 -= 2*3.14159265358979323846;
                if (p1 <= -3.14159265358979323846) p1 += 2*3.14159265358979323846;
                if (p2 > 3.14159265358979323846) p2 -= 2*3.14159265358979323846;
                if (p2 <= -3.14159265358979323846) p2 += 2*3.14159265358979323846;
                if (p2 < p1)
                {
                    idx_temp = idx_map[i];
                }
            }
            if (idx_temp != -1)
            {
                idx_map[i] = idx_map[j];
                idx_map[j] = idx_temp;
            }
        }
    }
    for (i = 0; i < eval->size; i++)
    {
        for (j = 0; j < eval->size; j++)
        {
            z = gsl_matrix_complex_get(evec_copy, idx_map[i], j);
            gsl_matrix_complex_set(evec, i, j, z);
        }
        z = gsl_vector_complex_get(eval_copy, idx_map[i]);
        gsl_vector_complex_set(eval, i, z);
    }
    gsl_matrix_complex_free(evec_copy);
    gsl_vector_complex_free(eval_copy);
    free(idx_map);
    return 0;
}

canonical_original_code:
int gsl_ext_eigen_sort(struct gsl_matrix_complex *evec, struct gsl_vector_complex *eval, int sort_order)
{
    struct gsl_complex z;
      struct gsl_matrix_complex *evec_copy;
    struct gsl_vector_complex *eval_copy;
    int *idx_map; int i; int j; int idx_temp;
    double p1; double p2;
    if ((evec->size1 != evec->size2) || (evec->size1 != eval->size))
    {
        return -1;
    }
    evec_copy = gsl_matrix_complex_alloc(evec->size1, evec->size2);
    eval_copy = gsl_vector_complex_alloc(eval->size);
    idx_map = (int *)malloc(sizeof(int) * eval->size);
    gsl_matrix_complex_memcpy(evec_copy, evec);
    gsl_vector_complex_memcpy(eval_copy, eval);
    for (i = 0; i < eval->size; i++)
    {
        idx_map[i] = i;
    }
    for (i = 0; i < eval->size - 1; i++)
    {
        for (j = i+1; j < eval->size; j++)
        {
            idx_temp = -1;
            if (sort_order == 0)
            {
                p1 = gsl_complex_abs(gsl_vector_complex_get(eval, idx_map[i]));
                p2 = gsl_complex_abs(gsl_vector_complex_get(eval, idx_map[j]));
                if (p1 > p2)
                {
                    idx_temp = idx_map[i];
                }
            }
            if (sort_order == 3)
            {
                p1 = gsl_complex_arg(gsl_vector_complex_get(eval, idx_map[i]));
                p2 = gsl_complex_arg(gsl_vector_complex_get(eval, idx_map[j]));
                if (p1 > 3.14159265358979323846) p1 -= 2*3.14159265358979323846;
                if (p1 <= -3.14159265358979323846) p1 += 2*3.14159265358979323846;
                if (p2 > 3.14159265358979323846) p2 -= 2*3.14159265358979323846;
                if (p2 <= -3.14159265358979323846) p2 += 2*3.14159265358979323846;
                if (p2 < p1)
                {
                    idx_temp = idx_map[i];
                }
            }
            if (idx_temp != -1)
            {
                idx_map[i] = idx_map[j];
                idx_map[j] = idx_temp;
            }
        }
    }
    for (i = 0; i < eval->size; i++)
    {
        for (j = 0; j < eval->size; j++)
        {
            z = gsl_matrix_complex_get(evec_copy, idx_map[i], j);
            gsl_matrix_complex_set(evec, i, j, z);
        }
        z = gsl_vector_complex_get(eval_copy, idx_map[i]);
        gsl_vector_complex_set(eval, i, z);
    }
    gsl_matrix_complex_free(evec_copy);
    gsl_vector_complex_free(eval_copy);
    free(idx_map);
    return 0;
}

variable_types: struct gsl_matrix_complex { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_complex_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: struct gsl_vector_complex { unsigned long size; unsigned long stride; double *data; struct gsl_block_complex_struct *block; int owner; } *

variable_types: struct gsl_vector_complex { unsigned long size; unsigned long stride; double *data; struct gsl_block_complex_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall qdpack_simulation_init(__int64 a1)
{
__int64 v2; // rdi
__int64 result; // rax

if ( a1 )
{
*(_QWORD *)a1 = 0LL;
v2 = a1 + 8;
result = 0LL;
*(_QWORD *)(v2 + 3224) = 0LL;
memset(
(void *)(v2 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v2 & 0xFFFFFFF8) + 3240) >> 3));
*(_DWORD *)(a1 + 2768) = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v2; // rdi
__int64 result; // rax

if ( a1 )
{
*(_QWORD *)a1 = 0LL;
v2 = a1 + 8;
result = 0LL;
*(_QWORD *)(v2 + 3224) = 0LL;
memset(
(void *)(v2 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v2 & 0xFFFFFFF8) + 3240) >> 3));
*(_DWORD *)(a1 + 2768) = 1;
}
return result;
}

original_code:
void
qdpack_simulation_init(qdpack_simulation_t *sp)
{
    if (sp)
    {
        memset((void *)sp, 0, sizeof(qdpack_simulation_t));
        sp->cont_basis_transform = 0;
        sp->option_me_eb = 0;
        sp->option_adaptive = 1;
        sp->H0 = ((void *)0);
        sp->H1 = ((void *)0);
        sp->H_t = ((void *)0);
        sp->H0_func = ((void *)0);
        sp->H1_func = ((void *)0);
        sp->Ht_func = ((void *)0);
        sp->h_td_A = 0.0;
        sp->h_td_w = 0.0;
    }
    return;
}

canonical_original_code:
void qdpack_simulation_init(struct _qdpack_simulation *sp)
{
    if (sp)
    {
        memset((void *)sp, 0, sizeof(qdpack_simulation_t));
        sp->cont_basis_transform = 0;
        sp->option_me_eb = 0;
        sp->option_adaptive = 1;
        sp->H0 = ((void *)0);
        sp->H1 = ((void *)0);
        sp->H_t = ((void *)0);
        sp->H0_func = ((void *)0);
        sp->H1_func = ((void *)0);
        sp->Ht_func = ((void *)0);
        sp->h_td_A = 0.0;
        sp->h_td_w = 0.0;
    }
    return;
}

variable_types: struct _qdpack_simulation { struct qdpack_hilbert_space_t { int nsubsys; int *nstates; } *qs; double Ti; double Tf; double dT; char simsig[1024]; double T_w; struct _qdpack_operator_t { int n; struct qdpack_hilbert_space_t *qs; struct _qdpack_matrix { int n; struct gsl_matrix_complex { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_complex_struct { unsigned long size; double *data; } *block; int owner; } *data; } *data; } *H0; struct _qdpack_operator_t *H1; struct _qdpack_operator_t *H_t; struct _qdpack_operator_t *H_a; struct _qdpack_operator_t *H_b; struct _qdpack_operator_t *do_a[20]; struct _qdpack_operator_t *do_ad[20]; struct _qdpack_operator_t *do_aad[20]; struct _qdpack_operator_t *do_ada[20]; struct _qdpack_operator_t *do_a_eb[20]; struct _qdpack_operator_t *do_ad_eb[20]; struct _qdpack_operator_t *do_aad_eb[20]; struct _qdpack_operator_t *do_ada_eb[20]; struct _qdpack_operator_t *ws1; struct _qdpack_operator_t *ws2; struct _qdpack_operator_t *op_tmp; double do_g1[20]; double do_g2[20]; int do_n; void *parameters; struct _qdpack_operator_t *dSSt; double (*ho_w_func)(double, void *); int cont_basis_transform; int option_me_eb; int option_adaptive; double g0; struct _qdpack_operator_t *N_op[10]; struct _qdpack_operator_t *a; struct _qdpack_operator_t *n_op; struct _qdpack_state { int n; struct qdpack_hilbert_space_t *qs; struct _qdpack_matrix *data; } *psi_f; double h_td_A; double h_td_w; int (*H0_func)(struct _qdpack_simulation *, struct qdpack_hilbert_space_t *, struct _qdpack_operator_t *); int (*H1_func)(struct _qdpack_simulation *, struct qdpack_hilbert_space_t *, struct _qdpack_operator_t *); int (*Ht_func)(struct _qdpack_simulation *, struct _qdpack_operator_t *, struct _qdpack_operator_t *, struct _qdpack_operator_t *, double); struct _qdpack_operator_t *evec; struct _qdpack_matrix *eval; struct _qdpack_operator_t *floquet_states_t; struct _qdpack_operator_t *floquet_modes; struct _qdpack_matrix *floquet_quasienergies; struct _qdpack_operator_t **floquet_X; struct _qdpack_matrix *floquet_Gamma; struct _qdpack_matrix *floquet_ss_prob; int floquet_k_max; } *

return_type: void


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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 1064) )
result = qdpack_operator_free();
if ( *(_QWORD *)(a1 + 1072) )
result = qdpack_operator_free();
}
return result;
}

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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 1064) )
result = qdpack_operator_free();
if ( *(_QWORD *)(a1 + 1072) )
result = qdpack_operator_free();
}
return result;
}

original_code:
void
qdpack_simulation_free(qdpack_simulation_t *sp)
{
    if (sp)
    {
        if (sp->H0) qdpack_operator_free(sp->H0);
        if (sp->H1) qdpack_operator_free(sp->H1);
    }
    return;
}

canonical_original_code:
void qdpack_simulation_free(struct _qdpack_simulation *sp)
{
    if (sp)
    {
        if (sp->H0) qdpack_operator_free(sp->H0);
        if (sp->H1) qdpack_operator_free(sp->H1);
    }
    return;
}


decompiled_code:
void __fastcall sup_norm(_QWORD *a1, double a2, double a3)
{
unsigned int v3; // er12
__int64 v4; // rbp
unsigned int v5; // ebx
__int64 j; // rdx
double v7; // [rsp+8h] [rbp-38h]
double i; // [rsp+10h] [rbp-30h]

v3 = 0;
v4 = 0LL;
for ( i = 0.0; (unsigned __int64)v3 < *a1; v4 = v3 )
{
v5 = 0;
for ( j = 0LL; (unsigned __int64)v5 < a1[1]; j = v5 )
{
while ( 1 )
{
v7 = gsl_matrix_complex_get(a1, v4, j);
if ( ((double (*)(void))gsl_complex_abs)() > i )
break;
j = ++v5;
if ( (unsigned __int64)v5 >= a1[1] )
goto LABEL_7;
}
i = gsl_complex_abs(v7, a3);
++v5;
}
LABEL_7:
++v3;
}
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1, double a2, double a3)
{
unsigned int v3; // er12
__int64 v4; // rbp
unsigned int v5; // ebx
__int64 j; // rdx
double v7; // [rsp+8h] [rbp-38h]
double i; // [rsp+10h] [rbp-30h]

v3 = 0;
v4 = 0LL;
for ( i = 0.0; (unsigned __int64)v3 < *a1; v4 = v3 )
{
v5 = 0;
for ( j = 0LL; (unsigned __int64)v5 < a1[1]; j = v5 )
{
while ( 1 )
{
v7 = gsl_matrix_complex_get(a1, v4, j);
if ( ((double (*)(void))gsl_complex_abs)() > i )
break;
j = ++v5;
if ( (unsigned __int64)v5 >= a1[1] )
goto LABEL_7;
}
i = gsl_complex_abs(v7, a3);
++v5;
}
LABEL_7:
++v3;
}
}

original_code:
inline
static double
sup_norm(const gsl_matrix_complex * A)
{
    unsigned int i, j;
      double max = 0.0;
    for (i = 0; i < A->size1; i++)
    {
        for (j = 0; j < A->size2; j++)
        {
            gsl_complex z = gsl_matrix_complex_get(A, i, j);
            if (gsl_complex_abs(z) > max)
                max = gsl_complex_abs(z);
        }
    }
      return max;
}

canonical_original_code:
inline static double sup_norm(struct gsl_matrix_complex *A)
{
    unsigned int i; unsigned int j;
      double max = 0.0;
    for (i = 0; i < A->size1; i++)
    {
        for (j = 0; j < A->size2; j++)
        {
            struct gsl_complex z = gsl_matrix_complex_get(A, i, j);
            if (gsl_complex_abs(z) > max)
                max = gsl_complex_abs(z);
        }
    }
      return max;
}

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types: max double


original_code:
static
mvl_suggestion_t
obtain_suggestion(const gsl_matrix_complex * A, gsl_mode_t mode)
{
  const unsigned int mode_prec = ((mode) & (unsigned int)7);
  const double norm_A = sup_norm(A);
  if(norm_A < 0.01) return mvl_tab[mode_prec][0];
  else if(norm_A < 0.1) return mvl_tab[mode_prec][1];
  else if(norm_A < 1.0) return mvl_tab[mode_prec][2];
  else if(norm_A < 10.0) return mvl_tab[mode_prec][3];
  else if(norm_A < 100.0) return mvl_tab[mode_prec][4];
  else if(norm_A < 1000.0) return mvl_tab[mode_prec][5];
  else
  {
    const double extra = log(1.01*norm_A/1000.0) / 0.69314718055994530942;
    const int extra_i = (unsigned int) ceil(extra);
    mvl_suggestion_t s = mvl_tab[mode][5];
    s.j += extra_i;
    return s;
  }
}

canonical_original_code:
static struct moler_vanloan_optimal_suggestion obtain_suggestion(struct gsl_matrix_complex *A, unsigned int mode)
{
  unsigned int mode_prec = ((mode) & (unsigned int)7);
  double norm_A = sup_norm(A);
  if(norm_A < 0.01) return mvl_tab[mode_prec][0];
  else if(norm_A < 0.1) return mvl_tab[mode_prec][1];
  else if(norm_A < 1.0) return mvl_tab[mode_prec][2];
  else if(norm_A < 10.0) return mvl_tab[mode_prec][3];
  else if(norm_A < 100.0) return mvl_tab[mode_prec][4];
  else if(norm_A < 1000.0) return mvl_tab[mode_prec][5];
  else
  {
    double extra = log(1.01*norm_A/1000.0) / 0.69314718055994530942;
    int extra_i = (unsigned int) ceil(extra);
    struct moler_vanloan_optimal_suggestion s = mvl_tab[mode][5];
    s.j += extra_i;
    return s;
  }
}

variable_types:
mode
unsigned int

variable_types: extra double

variable_types: struct moler_vanloan_optimal_suggestion { int k; int j; }


decompiled_code:
__int64 __fastcall matrix_complex_exp_series(_QWORD *a1, __int64 a2, int a3)
{
__int64 v4; // rbp
double v5; // xmm1_8
int v6; // ebx

v4 = gsl_matrix_complex_calloc(*a1, a1[1]);
gsl_matrix_complex_memcpy(a2, a1);
v5 = (double)a3;
v6 = a3 - 1;
gsl_matrix_complex_scale(a2, 1.0 / v5, 0.0);
gsl_matrix_complex_add_diagonal(a2, 1.0, 0.0);
if ( v6 > 0 )
{
do
{
gsl_blas_zgemm(111LL, 111LL, a1, a2, v4, 1.0, 0.0, 0.0, 0.0);
gsl_matrix_complex_scale(v4, 1.0 / (double)v6, 0.0);
gsl_matrix_complex_add_diagonal(v4, 1.0, 0.0);
gsl_matrix_complex_memcpy(a2, v4);
--v6;
}
while ( v6 );
}
return gsl_matrix_complex_free(v4);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2, int a3)
{
__int64 v4; // rbp
double v5; // xmm1_8
int v6; // ebx

v4 = gsl_matrix_complex_calloc(*a1, a1[1]);
gsl_matrix_complex_memcpy(a2, a1);
v5 = (double)a3;
v6 = a3 - 1;
gsl_matrix_complex_scale(a2, 1.0 / v5, 0.0);
gsl_matrix_complex_add_diagonal(a2, 1.0, 0.0);
if ( v6 > 0 )
{
do
{
gsl_blas_zgemm(111LL, 111LL, a1, a2, v4, 1.0, 0.0, 0.0, 0.0);
gsl_matrix_complex_scale(v4, 1.0 / (double)v6, 0.0);
gsl_matrix_complex_add_diagonal(v4, 1.0, 0.0);
gsl_matrix_complex_memcpy(a2, v4);
--v6;
}
while ( v6 );
}
return gsl_matrix_complex_free(v4);
}

original_code:
static void
matrix_complex_exp_series(
  const gsl_matrix_complex * B,
  gsl_matrix_complex * eB,
  int number_of_terms
  )
{
  int count;
  gsl_matrix_complex *temp = gsl_matrix_complex_calloc(B->size1, B->size2);
  gsl_complex z;
  gsl_complex alpha, beta;
  do {(&alpha)->dat[0]=(1.0); (&alpha)->dat[1]=(0.0);} while(0);
  do {(&beta)->dat[0]=(0.0); (&beta)->dat[1]=(0.0);} while(0);
  gsl_matrix_complex_memcpy(eB, B);
  do {(&z)->dat[0]=(1.0/number_of_terms); (&z)->dat[1]=(0.0);} while(0);
  gsl_matrix_complex_scale(eB, z);
  do {(&z)->dat[0]=(1.0); (&z)->dat[1]=(0.0);} while(0);
  gsl_matrix_complex_add_diagonal(eB, z);
  for(count = number_of_terms-1; count >= 1; --count)
  {
    gsl_blas_zgemm(CblasNoTrans, CblasNoTrans, alpha, B, eB, beta, temp);
    do {(&z)->dat[0]=(1.0/count); (&z)->dat[1]=(0.0);} while(0);
    gsl_matrix_complex_scale(temp, z);
    do {(&z)->dat[0]=(1.0); (&z)->dat[1]=(0.0);} while(0);
    gsl_matrix_complex_add_diagonal(temp, z);
    gsl_matrix_complex_memcpy(eB, temp);
  }
  gsl_matrix_complex_free(temp);
}

canonical_original_code:
static void matrix_complex_exp_series(struct gsl_matrix_complex *B, struct gsl_matrix_complex *eB, int number_of_terms)
{
  int count;
  struct gsl_matrix_complex *temp = gsl_matrix_complex_calloc(B->size1, B->size2);
  struct gsl_complex z;
  struct gsl_complex alpha; struct gsl_complex beta;
  do {(&alpha)->dat[0]=(1.0); (&alpha)->dat[1]=(0.0);} while(0);
  do {(&beta)->dat[0]=(0.0); (&beta)->dat[1]=(0.0);} while(0);
  gsl_matrix_complex_memcpy(eB, B);
  do {(&z)->dat[0]=(1.0/number_of_terms); (&z)->dat[1]=(0.0);} while(0);
  gsl_matrix_complex_scale(eB, z);
  do {(&z)->dat[0]=(1.0); (&z)->dat[1]=(0.0);} while(0);
  gsl_matrix_complex_add_diagonal(eB, z);
  for(count = number_of_terms-1; count >= 1; --count)
  {
    gsl_blas_zgemm(CblasNoTrans, CblasNoTrans, alpha, B, eB, beta, temp);
    do {(&z)->dat[0]=(1.0/count); (&z)->dat[1]=(0.0);} while(0);
    gsl_matrix_complex_scale(temp, z);
    do {(&z)->dat[0]=(1.0); (&z)->dat[1]=(0.0);} while(0);
    gsl_matrix_complex_add_diagonal(temp, z);
    gsl_matrix_complex_memcpy(eB, temp);
  }
  gsl_matrix_complex_free(temp);
}

variable_types:
eB
struct gsl_matrix_complex *

variable_types: count int

variable_types:
alpha
struct gsl_complex { double dat[2]; }

variable_types:
beta
struct gsl_complex { double dat[2]; }