decompiled_code:
__int64 __fastcall qdpack_operator_traceout_multi(__int64 a1, __int64 a2, int *a3, double a4, double a5)
{
__int64 v7; // rbx
__int64 v8; // r13
int v9; // ebx
double v10; // rbx
unsigned int v11; // er12
__int64 v12; // rsi
__int64 v13; // rdi
__int64 v14; // rax
int v15; // edx
__int64 v16; // rcx
int v17; // er8
int v18; // ebp
int v19; // eax
double v20; // xmm3_8
double v21; // xmm2_8
int v23; // [rsp+Ch] [rbp-1ACh]
__int64 j; // [rsp+18h] [rbp-1A0h]
__int64 v26; // [rsp+20h] [rbp-198h]
__int64 i; // [rsp+28h] [rbp-190h]
__int64 v28; // [rsp+30h] [rbp-188h]
__int64 v29; // [rsp+38h] [rbp-180h]
int v30[20]; // [rsp+40h] [rbp-178h] BYREF
int v31[20]; // [rsp+90h] [rbp-128h] BYREF
int v32[20]; // [rsp+E0h] [rbp-D8h] BYREF
int v33[34]; // [rsp+130h] [rbp-88h] BYREF

v7 = 0LL;
v8 = qdpack_hilbert_space_copy(a1);
for ( i = qdpack_hilbert_space_new(); *a3 > (int)v7; ++v7 )
{
while ( *(_DWORD *)(*((_QWORD *)a3 + 1) + 4 * v7) )
{
if ( *a3 <= (int)++v7 )
goto LABEL_6;
}
qdpack_hilbert_space_add(i, *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4 * v7));
*(_DWORD *)(*(_QWORD *)(v8 + 8) + 4 * v7) = 1;
}
LABEL_6:
v9 = qdpack_hilbert_space_nstates(i);
v23 = qdpack_hilbert_space_nstates(v8);
v29 = qdpack_operator_alloc(i);
if ( v29 )
{
if ( v9 > 0 )
{
v26 = 0LL;
v28 = v9;
do
{
qdpack_hilbert_space_state_vector(i, (unsigned int)v26, v32);
for ( j = 0LL; j != v28; ++j )
{
v10 = 0.0;
v11 = 0;
qdpack_hilbert_space_state_vector(i, (unsigned int)j, v33);
if ( v23 > 0 )
{
do
{
qdpack_hilbert_space_state_vector(v8, v11, v30);
qdpack_hilbert_space_state_vector(v8, v11, v31);
v12 = *a3;
if ( (int)v12 > 0 )
{
v13 = *((_QWORD *)a3 + 1);
v14 = 0LL;
v15 = 0;
do
{
if ( !*(_DWORD *)(v13 + 4 * v14) )
{
v16 = v15++;
v17 = v32[v16];
LODWORD(v16) = v33[v16];
v30[v14] = v17;
v31[v14] = v16;
}
++v14;
}
while ( v12 != v14 );
}
++v11;
v18 = qdpack_hilbert_space_state_number(a1, v30);
v19 = qdpack_hilbert_space_state_number(a1, v31);
v20 = a5;
a5 = 0.0;
v21 = qdpack_operator_get(a2, v18, v19);
v10 = gsl_complex_add(v10, 0.0, v21, v20);
}
while ( v23 != v11 );
}
a5 = 0.0;
qdpack_operator_set(v29, v26, j, v10, 0.0);
}
++v26;
}
while ( v28 != v26 );
}
}
else
{
fwrite("qdpack_operator_traceout: Failed to allocate dm_part (Out of memory?).\n", 1uLL, 0x47uLL, stderr);
}
return v29;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, int *a3, double a4, double a5)
{
__int64 v7; // rbx
__int64 v8; // r13
int v9; // ebx
double v10; // rbx
unsigned int v11; // er12
__int64 v12; // rsi
__int64 v13; // rdi
__int64 v14; // rax
int v15; // edx
__int64 v16; // rcx
int v17; // er8
int v18; // ebp
int v19; // eax
double v20; // xmm3_8
double v21; // xmm2_8
int v23; // [rsp+Ch] [rbp-1ACh]
__int64 j; // [rsp+18h] [rbp-1A0h]
__int64 v26; // [rsp+20h] [rbp-198h]
__int64 i; // [rsp+28h] [rbp-190h]
__int64 v28; // [rsp+30h] [rbp-188h]
__int64 v29; // [rsp+38h] [rbp-180h]
int v30[20]; // [rsp+40h] [rbp-178h] BYREF
int v31[20]; // [rsp+90h] [rbp-128h] BYREF
int v32[20]; // [rsp+E0h] [rbp-D8h] BYREF
int v33[34]; // [rsp+130h] [rbp-88h] BYREF

v7 = 0LL;
v8 = qdpack_hilbert_space_copy(a1);
for ( i = qdpack_hilbert_space_new(); *a3 > (int)v7; ++v7 )
{
while ( *(_DWORD *)(*((_QWORD *)a3 + 1) + 4 * v7) )
{
if ( *a3 <= (int)++v7 )
goto LABEL_6;
}
qdpack_hilbert_space_add(i, *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4 * v7));
*(_DWORD *)(*(_QWORD *)(v8 + 8) + 4 * v7) = 1;
}
LABEL_6:
v9 = qdpack_hilbert_space_nstates(i);
v23 = qdpack_hilbert_space_nstates(v8);
v29 = qdpack_operator_alloc(i);
if ( v29 )
{
if ( v9 > 0 )
{
v26 = 0LL;
v28 = v9;
do
{
qdpack_hilbert_space_state_vector(i, (unsigned int)v26, v32);
for ( j = 0LL; j != v28; ++j )
{
v10 = 0.0;
v11 = 0;
qdpack_hilbert_space_state_vector(i, (unsigned int)j, v33);
if ( v23 > 0 )
{
do
{
qdpack_hilbert_space_state_vector(v8, v11, v30);
qdpack_hilbert_space_state_vector(v8, v11, v31);
v12 = *a3;
if ( (int)v12 > 0 )
{
v13 = *((_QWORD *)a3 + 1);
v14 = 0LL;
v15 = 0;
do
{
if ( !*(_DWORD *)(v13 + 4 * v14) )
{
v16 = v15++;
v17 = v32[v16];
LODWORD(v16) = v33[v16];
v30[v14] = v17;
v31[v14] = v16;
}
++v14;
}
while ( v12 != v14 );
}
++v11;
v18 = qdpack_hilbert_space_state_number(a1, v30);
v19 = qdpack_hilbert_space_state_number(a1, v31);
v20 = a5;
a5 = 0.0;
v21 = qdpack_operator_get(a2, v18, v19);
v10 = gsl_complex_add(v10, 0.0, v21, v20);
}
while ( v23 != v11 );
}
a5 = 0.0;
qdpack_operator_set(v29, v26, j, v10, 0.0);
}
++v26;
}
while ( v28 != v26 );
}
}
else
{
fwrite("qdpack_operator_traceout: Failed to allocate dm_part (Out of memory?).\n", 1uLL, 0x47uLL, stderr);
}
return v29;
}

original_code:
qdpack_operator_t *
qdpack_operator_traceout_multi(qdpack_hilbert_space_t *qs, qdpack_operator_t *dm, qdpack_hilbert_space_t *mask)
{
    int i, j, ii, jj, k, ns_trace, ns_sub, n, m;
    qdpack_operator_t *dm_sub;
    gsl_complex dm_ij;
    qdpack_hilbert_space_state_vector_t qsv_trace_i, qsv_trace_j, qsv_sub_i, qsv_sub_j;
    qdpack_hilbert_space_t *qs_sub, *qs_trace;
    qs_trace = qdpack_hilbert_space_copy(qs);
    qs_sub = qdpack_hilbert_space_new();
    for (n = 0; n < mask->nsubsys; n++)
    {
        if (mask->nstates[n] == 0)
        {
            qdpack_hilbert_space_add(qs_sub, qs->nstates[n]);
            qs_trace->nstates[n] = 1;
        }
    }
    ns_sub = qdpack_hilbert_space_nstates(qs_sub);
    ns_trace = qdpack_hilbert_space_nstates(qs_trace);
    if ((dm_sub = qdpack_operator_alloc(qs_sub)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_operator_traceout: Failed to allocate dm_part (Out of memory?).\n");
        return ((void *)0);
    }
    for (i = 0; i < ns_sub; i++)
    {
        qdpack_hilbert_space_state_vector(qs_sub, i, qsv_sub_i);
        for (j = 0; j < ns_sub; j++)
        {
            qdpack_hilbert_space_state_vector(qs_sub, j, qsv_sub_j);
            do {(&dm_ij)->dat[0]=(0.0); (&dm_ij)->dat[1]=(0.0);} while(0);
            for (k = 0; k < ns_trace; k++)
            {
                qdpack_hilbert_space_state_vector(qs_trace, k, qsv_trace_i);
                qdpack_hilbert_space_state_vector(qs_trace, k, qsv_trace_j);
                m = 0;
                for (n = 0; n < mask->nsubsys; n++)
                {
                    if (mask->nstates[n] == 0)
                    {
                        qsv_trace_i[n] = qsv_sub_i[m];
                        qsv_trace_j[n] = qsv_sub_j[m];
                        m++;
                    }
                }
                ii = qdpack_hilbert_space_state_number(qs, qsv_trace_i);
                jj = qdpack_hilbert_space_state_number(qs, qsv_trace_j);
                dm_ij = gsl_complex_add(dm_ij, qdpack_operator_get(dm, ii, jj));
            }
            qdpack_operator_set(dm_sub, i, j, dm_ij);
        }
    }
    return dm_sub;
}

canonical_original_code:
struct _qdpack_operator_t *qdpack_operator_traceout_multi(struct qdpack_hilbert_space_t *qs, struct _qdpack_operator_t *dm, struct qdpack_hilbert_space_t *mask)
{
    int i; int j; int ii; int jj; int k; int ns_trace; int ns_sub; int n; int m;
    struct _qdpack_operator_t *dm_sub;
    struct gsl_complex dm_ij;
    int qsv_trace_i[20]; int qsv_trace_j[20]; int qsv_sub_i[20]; int qsv_sub_j[20];
    struct qdpack_hilbert_space_t *qs_sub; struct qdpack_hilbert_space_t *qs_trace;
    qs_trace = qdpack_hilbert_space_copy(qs);
    qs_sub = qdpack_hilbert_space_new();
    for (n = 0; n < mask->nsubsys; n++)
    {
        if (mask->nstates[n] == 0)
        {
            qdpack_hilbert_space_add(qs_sub, qs->nstates[n]);
            qs_trace->nstates[n] = 1;
        }
    }
    ns_sub = qdpack_hilbert_space_nstates(qs_sub);
    ns_trace = qdpack_hilbert_space_nstates(qs_trace);
    if ((dm_sub = qdpack_operator_alloc(qs_sub)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_operator_traceout: Failed to allocate dm_part (Out of memory?).\n");
        return ((void *)0);
    }
    for (i = 0; i < ns_sub; i++)
    {
        qdpack_hilbert_space_state_vector(qs_sub, i, qsv_sub_i);
        for (j = 0; j < ns_sub; j++)
        {
            qdpack_hilbert_space_state_vector(qs_sub, j, qsv_sub_j);
            do {(&dm_ij)->dat[0]=(0.0); (&dm_ij)->dat[1]=(0.0);} while(0);
            for (k = 0; k < ns_trace; k++)
            {
                qdpack_hilbert_space_state_vector(qs_trace, k, qsv_trace_i);
                qdpack_hilbert_space_state_vector(qs_trace, k, qsv_trace_j);
                m = 0;
                for (n = 0; n < mask->nsubsys; n++)
                {
                    if (mask->nstates[n] == 0)
                    {
                        qsv_trace_i[n] = qsv_sub_i[m];
                        qsv_trace_j[n] = qsv_sub_j[m];
                        m++;
                    }
                }
                ii = qdpack_hilbert_space_state_number(qs, qsv_trace_i);
                jj = qdpack_hilbert_space_state_number(qs, qsv_trace_j);
                dm_ij = gsl_complex_add(dm_ij, qdpack_operator_get(dm, ii, jj));
            }
            qdpack_operator_set(dm_sub, i, j, dm_ij);
        }
    }
    return dm_sub;
}

variable_types:
mask
struct qdpack_hilbert_space_t *

variable_types: i int

variable_types: m int

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; } *


repo: jrjohansson/qdpack

decompiled_code:
__int64 __fastcall qdpack_wf_tensor(__int64 a1, int *a2, __int64 a3, double a4, double a5)
{
int v8; // eax
__int64 v9; // r12
double v10; // r15
double v11; // xmm4_8
__int64 v12; // r14
__int64 v13; // rsi
__int64 v14; // rdi
double v15; // xmm2_8
double v16; // xmm3_8
__int64 result; // rax
double v18; // [rsp+0h] [rbp-98h]
__int64 v19; // [rsp+8h] [rbp-90h]
int v20[34]; // [rsp+10h] [rbp-88h] BYREF

v8 = qdpack_hilbert_space_nstates(a2);
if ( a2 && a3 && *a2 == *(_DWORD *)(a3 + 160) )
{
v9 = 0LL;
v19 = v8;
if ( v8 > 0 )
{
do
{
qdpack_hilbert_space_state_vector(a2, (unsigned int)v9, v20);
v10 = *(double *)&LC1;
v11 = 0.0;
if ( *a2 > 0 )
{
v12 = 0LL;
do
{
v13 = v20[v12];
v14 = *(_QWORD *)(a3 + 8 * v12);
v18 = v11;
++v12;
v15 = qdpack_state_get(v14, v13);
v16 = a5;
a5 = v18;
v10 = gsl_complex_mul(v10, v18, v15, v16);
v11 = a5;
}
while ( *a2 > (int)v12 );
}
a5 = v11;
qdpack_state_set(a1, v9++, v10, v11);
}
while ( v9 != v19 );
}
result = 0LL;
}
else
{
fwrite("qdpack_wf_tensor: NULL arguments or system-size/wf_list mismatch.\n", 1uLL, 0x42uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int *a2, __int64 a3, double a4, double a5)
{
int v8; // eax
__int64 v9; // r12
double v10; // r15
double v11; // xmm4_8
__int64 v12; // r14
__int64 v13; // rsi
__int64 v14; // rdi
double v15; // xmm2_8
double v16; // xmm3_8
__int64 result; // rax
double v18; // [rsp+0h] [rbp-98h]
__int64 v19; // [rsp+8h] [rbp-90h]
int v20[34]; // [rsp+10h] [rbp-88h] BYREF

v8 = qdpack_hilbert_space_nstates(a2);
if ( a2 && a3 && *a2 == *(_DWORD *)(a3 + 160) )
{
v9 = 0LL;
v19 = v8;
if ( v8 > 0 )
{
do
{
qdpack_hilbert_space_state_vector(a2, (unsigned int)v9, v20);
v10 = *(double *)&LC1;
v11 = 0.0;
if ( *a2 > 0 )
{
v12 = 0LL;
do
{
v13 = v20[v12];
v14 = *(_QWORD *)(a3 + 8 * v12);
v18 = v11;
++v12;
v15 = qdpack_state_get(v14, v13);
v16 = a5;
a5 = v18;
v10 = gsl_complex_mul(v10, v18, v15, v16);
v11 = a5;
}
while ( *a2 > (int)v12 );
}
a5 = v11;
qdpack_state_set(a1, v9++, v10, v11);
}
while ( v9 != v19 );
}
result = 0LL;
}
else
{
fwrite("qdpack_wf_tensor: NULL arguments or system-size/wf_list mismatch.\n", 1uLL, 0x42uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
qdpack_wf_tensor(qdpack_state_t *wf_full, qdpack_hilbert_space_t *qs, qdpack_state_list_t *wf_list)
{
    int ns, i, k;
    gsl_complex wf_i;
    qdpack_hilbert_space_state_vector_t qsv1;
    ns = qdpack_hilbert_space_nstates(qs);
    if (qs == ((void *)0) || wf_list == ((void *)0) || qs->nsubsys != wf_list->len)
    {
        fprintf(stderr, "qdpack_wf_tensor: NULL arguments or system-size/wf_list mismatch.\n");
        return -1;
    }
    for (i = 0; i < ns; i++)
    {
        qdpack_hilbert_space_state_vector(qs, i, qsv1);
        do {(&wf_i)->dat[0]=(1.0); (&wf_i)->dat[1]=(0.0);} while(0);
        for (k = 0; k < qs->nsubsys; k++)
        {
            wf_i = gsl_complex_mul(wf_i, qdpack_state_get(wf_list->wf[k], qsv1[k]));
        }
        qdpack_state_set(wf_full, i, wf_i);
    }
    return 0;
}

canonical_original_code:
int qdpack_wf_tensor(struct _qdpack_state *wf_full, struct qdpack_hilbert_space_t *qs, struct qdpack_state_list_t *wf_list)
{
    int ns; int i; int k;
    struct gsl_complex wf_i;
    int qsv1[20];
    ns = qdpack_hilbert_space_nstates(qs);
    if (qs == ((void *)0) || wf_list == ((void *)0) || qs->nsubsys != wf_list->len)
    {
        fprintf(stderr, "qdpack_wf_tensor: NULL arguments or system-size/wf_list mismatch.\n");
        return -1;
    }
    for (i = 0; i < ns; i++)
    {
        qdpack_hilbert_space_state_vector(qs, i, qsv1);
        do {(&wf_i)->dat[0]=(1.0); (&wf_i)->dat[1]=(0.0);} while(0);
        for (k = 0; k < qs->nsubsys; k++)
        {
            wf_i = gsl_complex_mul(wf_i, qdpack_state_get(wf_list->wf[k], qsv1[k]));
        }
        qdpack_state_set(wf_full, i, wf_i);
    }
    return 0;
}

variable_types: struct _qdpack_state { 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; } *

variable_types:
qs
struct qdpack_hilbert_space_t *

variable_types: struct qdpack_state_list_t { struct _qdpack_state *wf[20]; int len; } *

variable_types: ns int

variable_types: k int

return_type: int

user_defined_types: struct _qdpack_state { 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 qdpack_wf_list_init(__int64 a1)
{
__int64 v2; // rdi
__int64 result; // rax

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

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

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

original_code:
void
qdpack_wf_list_init(qdpack_state_list_t *wf_list)
{
    int i;
    if (wf_list != ((void *)0))
    {
        for (i = 0; i < 20; i++)
            wf_list->wf[i] = ((void *)0);
        wf_list->len = 0;
    }
}

canonical_original_code:
void qdpack_wf_list_init(struct qdpack_state_list_t *wf_list)
{
    int i;
    if (wf_list != ((void *)0))
    {
        for (i = 0; i < 20; i++)
            wf_list->wf[i] = ((void *)0);
        wf_list->len = 0;
    }
}

variable_types: struct qdpack_state_list_t { struct _qdpack_state { 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; } *wf[20]; int len; } *

return_type: void

user_defined_types: struct qdpack_state_list_t { struct _qdpack_state *wf[20]; int len; }


decompiled_code:
size_t __fastcall qdpack_wf_list_append(__int64 a1, __int64 a2)
{
size_t result; // rax

result = *(int *)(a1 + 160);
if ( (int)result > 19 )
return fwrite("qdpack_wf_list_append: Reached max size.\n", 1uLL, 0x29uLL, stderr);
*(_DWORD *)(a1 + 160) = result + 1;
*(_QWORD *)(a1 + 8 * result) = a2;
return result;
}

canonical_decompiled_code:
size_t __fastcall func8(__int64 a1, __int64 a2)
{
size_t result; // rax

result = *(int *)(a1 + 160);
if ( (int)result > 19 )
return fwrite("qdpack_wf_list_append: Reached max size.\n", 1uLL, 0x29uLL, stderr);
*(_DWORD *)(a1 + 160) = result + 1;
*(_QWORD *)(a1 + 8 * result) = a2;
return result;
}

original_code:
void
qdpack_wf_list_append(qdpack_state_list_t *wf_list, qdpack_state_t *wf)
{
    if (wf_list->len < 20)
        wf_list->wf[wf_list->len++] = wf;
    else
        fprintf(stderr, "qdpack_wf_list_append: Reached max size.\n");
}

canonical_original_code:
void qdpack_wf_list_append(struct qdpack_state_list_t *wf_list, struct _qdpack_state *wf)
{
    if (wf_list->len < 20)
        wf_list->wf[wf_list->len++] = wf;
    else
        fprintf(stderr, "qdpack_wf_list_append: Reached max size.\n");
}

variable_types:
wf
struct _qdpack_state *

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

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


decompiled_code:
__int64 __fastcall qdpack_wf_list_free_entries(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rdi

result = *(unsigned int *)(a1 + 160);
if ( (int)result > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(a1 + 8 * v3++);
result = qdpack_state_free(v4);
}
while ( *(_DWORD *)(a1 + 160) > (int)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rdi

result = *(unsigned int *)(a1 + 160);
if ( (int)result > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(a1 + 8 * v3++);
result = qdpack_state_free(v4);
}
while ( *(_DWORD *)(a1 + 160) > (int)v3 );
}
return result;
}

original_code:
void
qdpack_wf_list_free_entries(qdpack_state_list_t *wf_list)
{
    int i;
    for (i = 0; i < wf_list->len; i++)
        qdpack_state_free(wf_list->wf[i]);
}

canonical_original_code:
void qdpack_wf_list_free_entries(struct qdpack_state_list_t *wf_list)
{
    int i;
    for (i = 0; i < wf_list->len; i++)
        qdpack_state_free(wf_list->wf[i]);
}


decompiled_code:
__int64 __fastcall qdpack_wf_traceout(__int64 a1, __int64 a2, int a3, double a4, double a5)
{
__int64 v6; // rbp
double v7; // xmm0_8
__int64 v8; // r12

v6 = qdpack_operator_alloc(a1);
v7 = qdpack_state_to_operator(v6, a2);
v8 = qdpack_operator_traceout(a1, v6, a3, v7, a5);
qdpack_operator_free(v6);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, int a3, double a4, double a5)
{
__int64 v6; // rbp
double v7; // xmm0_8
__int64 v8; // r12

v6 = qdpack_operator_alloc(a1);
v7 = qdpack_state_to_operator(v6, a2);
v8 = func4(a1, v6, a3, v7, a5);
qdpack_operator_free(v6);
return v8;
}

original_code:
qdpack_operator_t *
qdpack_wf_traceout(qdpack_hilbert_space_t *qs, qdpack_state_t *wf, int n)
{
    qdpack_operator_t *dm, *dm_part;
    dm = qdpack_operator_alloc(qs);
    qdpack_state_to_operator(dm, wf);
    dm_part = qdpack_operator_traceout(qs, dm, n);
    qdpack_operator_free(dm);
    return dm_part;
}

canonical_original_code:
struct _qdpack_operator_t *qdpack_wf_traceout(struct qdpack_hilbert_space_t *qs, struct _qdpack_state *wf, int n)
{
    struct _qdpack_operator_t *dm; struct _qdpack_operator_t *dm_part;
    dm = qdpack_operator_alloc(qs);
    qdpack_state_to_operator(dm, wf);
    dm_part = qdpack_operator_traceout(qs, dm, n);
    qdpack_operator_free(dm);
    return dm_part;
}

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

variable_types: n int

return_type: 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_operator_t { int n; struct qdpack_hilbert_space_t *qs; struct _qdpack_matrix *data; }


decompiled_code:
__int64 __fastcall ss_idx_major(int a1, int a2, int a3)
{
return (unsigned int)(a2 * a1 + a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3)
{
return (unsigned int)(a2 * a1 + a3);
}

original_code:
int
ss_idx_major(int N, int a, int b)
{
    return N*a + b;
}

variable_types: N int

variable_types: a int

variable_types: b int


original_code:
int
ss_idx_minor_ms(int N, int J)
{
    return floor(((double)J)/N);
}

variable_types: J int


original_code:
int
ss_idx_minor_ls(int N, int J)
{
    return J - N * floor(((double)J)/N);
}


decompiled_code:
_QWORD *qdpack_hilbert_space_new()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x10uLL);
v1 = v0;
if ( v0 )
{
*(_DWORD *)v0 = 0;
v0[1] = 0LL;
}
else
{
fwrite("Failed ot allocate a new qdpack_hilbert_space_t object\n", 1uLL, 0x37uLL, stderr);
}
return v1;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x10uLL);
v1 = v0;
if ( v0 )
{
*(_DWORD *)v0 = 0;
v0[1] = 0LL;
}
else
{
fwrite("Failed ot allocate a new qdpack_hilbert_space_t object\n", 1uLL, 0x37uLL, stderr);
}
return v1;
}

original_code:
qdpack_hilbert_space_t *
qdpack_hilbert_space_new()
{
    qdpack_hilbert_space_t *qs;
    if ((qs = malloc(sizeof(qdpack_hilbert_space_t))) == ((void *)0))
    {
        fprintf(stderr, "Failed ot allocate a new qdpack_hilbert_space_t object\n");
        return 0;
    }
    qs->nsubsys = 0;
    qs->nstates = ((void *)0);
    return qs;
}

canonical_original_code:
struct qdpack_hilbert_space_t *qdpack_hilbert_space_new()
{
    struct qdpack_hilbert_space_t *qs;
    if ((qs = malloc(sizeof(qdpack_hilbert_space_t))) == ((void *)0))
    {
        fprintf(stderr, "Failed ot allocate a new qdpack_hilbert_space_t object\n");
        return 0;
    }
    qs->nsubsys = 0;
    qs->nstates = ((void *)0);
    return qs;
}

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


original_code:
void
qdpack_hilbert_space_add(qdpack_hilbert_space_t *qs, int M)
{
    int *nss, i;
    nss = malloc(sizeof(int) * (qs->nsubsys + 1));
    for (i = 0; i < qs->nsubsys; i++)
        nss[i] = qs->nstates[i];
    nss[qs->nsubsys] = M;
    qs->nsubsys = qs->nsubsys + 1;
    free(qs->nstates);
    qs->nstates = nss;
}

canonical_original_code:
void qdpack_hilbert_space_add(struct qdpack_hilbert_space_t *qs, int M)
{
    int *nss; int i;
    nss = malloc(sizeof(int) * (qs->nsubsys + 1));
    for (i = 0; i < qs->nsubsys; i++)
        nss[i] = qs->nstates[i];
    nss[qs->nsubsys] = M;
    qs->nsubsys = qs->nsubsys + 1;
    free(qs->nstates);
    qs->nstates = nss;
}

variable_types: M int

variable_types:
nss
int *

variable_types: i int


decompiled_code:
int __fastcall qdpack_hilbert_space_print(unsigned int *a1)
{
__int64 v1; // rbx
__int64 v2; // rsi

printf("Quantum system with %d sub systems: ", *a1);
if ( (int)*a1 > 0 )
{
v1 = 0LL;
do
{
v2 = *(unsigned int *)(*((_QWORD *)a1 + 1) + 4 * v1++);
printf("%d ", v2);
}
while ( (int)*a1 > (int)v1 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func5(unsigned int *a1)
{
__int64 v1; // rbx
__int64 v2; // rsi

printf("Quantum system with %d sub systems: ", *a1);
if ( (int)*a1 > 0 )
{
v1 = 0LL;
do
{
v2 = *(unsigned int *)(*((_QWORD *)a1 + 1) + 4 * v1++);
printf("%d ", v2);
}
while ( (int)*a1 > (int)v1 );
}
return putchar(10);
}

original_code:
void
qdpack_hilbert_space_print(qdpack_hilbert_space_t *qs)
{
    int i;
    printf("Quantum system with %d sub systems: ", qs->nsubsys);
    for (i = 0; i < qs->nsubsys; i++)
        printf("%d ", qs->nstates[i]);
    printf("\n");
}

canonical_original_code:
void qdpack_hilbert_space_print(struct qdpack_hilbert_space_t *qs)
{
    int i;
    printf("Quantum system with %d sub systems: ", qs->nsubsys);
    for (i = 0; i < qs->nsubsys; i++)
        printf("%d ", qs->nstates[i]);
    printf("\n");
}


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

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

original_code:
void
qdpack_hilbert_space_free(qdpack_hilbert_space_t *qs)
{
    free(qs->nstates);
    free(qs);
}

canonical_original_code:
void qdpack_hilbert_space_free(struct qdpack_hilbert_space_t *qs)
{
    free(qs->nstates);
    free(qs);
}


decompiled_code:
__int64 __fastcall qdpack_hilbert_space_nstates(__int64 a1)
{
_DWORD *v1; // rdx
unsigned int v2; // er8
_DWORD *v3; // rax
__int64 v4; // rcx

if ( *(int *)a1 <= 0 )
return 1LL;
v1 = *(_DWORD **)(a1 + 8);
v2 = 1;
v3 = v1 + 1;
v4 = (__int64)&v1[*(_DWORD *)a1 - 1 + 1];
while ( 1 )
{
v2 *= *v1;
v1 = v3;
if ( v3 == (_DWORD *)v4 )
break;
++v3;
}
return v2;
}

original_code:
int
qdpack_hilbert_space_nstates(qdpack_hilbert_space_t *qs)
{
    int i, ns = 1;
    for (i = 0; i < qs->nsubsys; i++)
    {
        ns *= qs->nstates[i];
    }
    return ns;
}

canonical_original_code:
int qdpack_hilbert_space_nstates(struct qdpack_hilbert_space_t *qs)
{
    int i; int ns = 1;
    for (i = 0; i < qs->nsubsys; i++)
    {
        ns *= qs->nstates[i];
    }
    return ns;
}


decompiled_code:
__int64 __fastcall qdpack_hilbert_space_state_vector(__int64 a1)
{
__int64 result; // rax
int v2; // er9
__int64 v3; // r10
int v4; // esi
__int64 v5; // rcx
__int64 v6; // rdi

result = qdpack_hilbert_space_nstates(a1);
v4 = result;
LODWORD(v5) = *(_DWORD *)a1 - 1;
if ( (int)v5 >= 0 )
{
v6 = *(_QWORD *)(a1 + 8);
v5 = (int)v5;
do
{
v4 /= *(int *)(v6 + 4 * v5);
result = (unsigned int)(v2 / v4);
*(_DWORD *)(v3 + 4 * v5--) = result;
v2 %= v4;
}
while ( (int)v5 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
int v2; // er9
__int64 v3; // r10
int v4; // esi
__int64 v5; // rcx
__int64 v6; // rdi

result = func7(a1);
v4 = result;
LODWORD(v5) = *(_DWORD *)a1 - 1;
if ( (int)v5 >= 0 )
{
v6 = *(_QWORD *)(a1 + 8);
v5 = (int)v5;
do
{
v4 /= *(int *)(v6 + 4 * v5);
result = (unsigned int)(v2 / v4);
*(_DWORD *)(v3 + 4 * v5--) = result;
v2 %= v4;
}
while ( (int)v5 >= 0 );
}
return result;
}

original_code:
void
qdpack_hilbert_space_state_vector(qdpack_hilbert_space_t *qs, int qsn, qdpack_hilbert_space_state_vector_t qsv)
{
    int i, acc;
    acc = qdpack_hilbert_space_nstates(qs);
    for (i = qs->nsubsys-1; i >= 0; i--)
    {
        acc = acc / qs->nstates[i];
        qsv[i] = floor(qsn/acc);
        qsn -= qsv[i] * acc;
    }
}

canonical_original_code:
void qdpack_hilbert_space_state_vector(struct qdpack_hilbert_space_t *qs, int qsn, int qsv[20])
{
    int i; int acc;
    acc = qdpack_hilbert_space_nstates(qs);
    for (i = qs->nsubsys-1; i >= 0; i--)
    {
        acc = acc / qs->nstates[i];
        qsv[i] = floor(qsn/acc);
        qsn -= qsv[i] * acc;
    }
}

variable_types: qsn int

variable_types:
qsv
int [20]

variable_types: acc int


decompiled_code:
__int64 __fastcall qdpack_hilbert_space_state_vector_print(int *a1, __int64 a2)
{
__int64 v3; // rbx
__int64 v4; // rsi

if ( *a1 <= 0 )
return 0LL;
v3 = 0LL;
do
{
v4 = *(unsigned int *)(a2 + 4 * v3++);
printf("%d ", v4);
}
while ( *a1 > (int)v3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1, __int64 a2)
{
__int64 v3; // rbx
__int64 v4; // rsi

if ( *a1 <= 0 )
return 0LL;
v3 = 0LL;
do
{
v4 = *(unsigned int *)(a2 + 4 * v3++);
printf("%d ", v4);
}
while ( *a1 > (int)v3 );
return 0LL;
}

original_code:
int
qdpack_hilbert_space_state_vector_print(qdpack_hilbert_space_t *qs, qdpack_hilbert_space_state_vector_t qsv)
{
    int i;
    for (i = 0; i < qs->nsubsys; i++)
        printf("%d ", qsv[i]);
    return 0;
}

canonical_original_code:
int qdpack_hilbert_space_state_vector_print(struct qdpack_hilbert_space_t *qs, int qsv[20])
{
    int i;
    for (i = 0; i < qs->nsubsys; i++)
        printf("%d ", qsv[i]);
    return 0;
}


decompiled_code:
__int64 __fastcall qdpack_hilbert_space_state_number(int *a1, __int64 a2)
{
__int64 v4; // rsi
__int64 v5; // r9
int v6; // edx
__int64 v7; // rax
unsigned int v8; // er8
int v9; // ecx

v4 = *a1;
if ( (int)v4 <= 0 )
return 0LL;
v5 = *((_QWORD *)a1 + 1);
v6 = 1;
v7 = 0LL;
v8 = 0;
do
{
v9 = v6 * *(_DWORD *)(a2 + 4 * v7);
v6 *= *(_DWORD *)(v5 + 4 * v7++);
v8 += v9;
}
while ( v4 != v7 );
return v8;
}

original_code:
int
qdpack_hilbert_space_state_number(qdpack_hilbert_space_t *qs, qdpack_hilbert_space_state_vector_t qsv)
{
    int qsn, i, acc_nqs;
    qsn = 0;
    acc_nqs = 1;
    for (i = 0; i < qs->nsubsys; i++)
    {
        qsn += acc_nqs * qsv[i];
        acc_nqs *= qs->nstates[i];
    }
    return qsn;
}

canonical_original_code:
int qdpack_hilbert_space_state_number(struct qdpack_hilbert_space_t *qs, int qsv[20])
{
    int qsn; int i; int acc_nqs;
    qsn = 0;
    acc_nqs = 1;
    for (i = 0; i < qs->nsubsys; i++)
    {
        qsn += acc_nqs * qsv[i];
        acc_nqs *= qs->nstates[i];
    }
    return qsn;
}


decompiled_code:
void __fastcall qdpack_state_free(void *ptr)
{
if ( ptr )
{
qdpack_hilbert_space_free(*((_QWORD *)ptr + 1));
qdpack_matrix_free(*((_QWORD *)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
qdpack_hilbert_space_free(*((_QWORD *)ptr + 1));
qdpack_matrix_free(*((_QWORD *)ptr + 2));
free(ptr);
}
}

original_code:
void
qdpack_state_free(qdpack_state_t *op)
{
    if (op == ((void *)0))
    {
        return;
    }
    qdpack_hilbert_space_free(op->qs);
    qdpack_matrix_free(op->data);
    free(op);
}

canonical_original_code:
void qdpack_state_free(struct _qdpack_state *op)
{
    if (op == ((void *)0))
    {
        return;
    }
    qdpack_hilbert_space_free(op->qs);
    qdpack_matrix_free(op->data);
    free(op);
}

variable_types: struct _qdpack_state { 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; } *


decompiled_code:
void __fastcall qdpack_state_memcpy(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rax
__int64 v5; // rsi
__int64 v6; // rdi

if ( a2 && a1 )
{
*(_DWORD *)a1 = *(_DWORD *)a2;
v3 = *(_QWORD *)(a1 + 8);
if ( v3 )
qdpack_hilbert_space_free(v3);
v4 = qdpack_hilbert_space_copy(*(_QWORD *)(a2 + 8));
v5 = *(_QWORD *)(a2 + 16);
v6 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 8) = v4;
qdpack_matrix_memcpy(v6, v5);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rax
__int64 v5; // rsi
__int64 v6; // rdi

if ( a2 && a1 )
{
*(_DWORD *)a1 = *(_DWORD *)a2;
v3 = *(_QWORD *)(a1 + 8);
if ( v3 )
qdpack_hilbert_space_free(v3);
v4 = qdpack_hilbert_space_copy(*(_QWORD *)(a2 + 8));
v5 = *(_QWORD *)(a2 + 16);
v6 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 8) = v4;
qdpack_matrix_memcpy(v6, v5);
}
}

original_code:
void
qdpack_state_memcpy(qdpack_state_t *dst, qdpack_state_t *src)
{
    if (src == ((void *)0) || dst == ((void *)0))
        return;
    dst->n = src->n;
    if (dst->qs)
        qdpack_hilbert_space_free(dst->qs);
    dst->qs = qdpack_hilbert_space_copy(src->qs);
    qdpack_matrix_memcpy(dst->data, src->data);
}

canonical_original_code:
void qdpack_state_memcpy(struct _qdpack_state *dst, struct _qdpack_state *src)
{
    if (src == ((void *)0) || dst == ((void *)0))
        return;
    dst->n = src->n;
    if (dst->qs)
        qdpack_hilbert_space_free(dst->qs);
    dst->qs = qdpack_hilbert_space_copy(src->qs);
    qdpack_matrix_memcpy(dst->data, src->data);
}

variable_types:
src
struct _qdpack_state *


decompiled_code:
__int64 __fastcall qdpack_state_get(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
result = qdpack_matrix_get(*(_QWORD *)(a1 + 16), a2, 0LL);
else
result = gsl_complex_rect(0.0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
result = qdpack_matrix_get(*(_QWORD *)(a1 + 16), a2, 0LL);
else
result = gsl_complex_rect(0.0);
return result;
}

original_code:
gsl_complex
qdpack_state_get(qdpack_state_t *op, size_t i)
{
    if (op == ((void *)0))
        return (gsl_complex_rect(0.0,0.0));
    return qdpack_matrix_get(op->data, i, 0);
}

canonical_original_code:
struct gsl_complex qdpack_state_get(struct _qdpack_state *op, unsigned long i)
{
    if (op == ((void *)0))
        return (gsl_complex_rect(0.0,0.0));
    return qdpack_matrix_get(op->data, i, 0);
}

variable_types:
i
unsigned long

return_type: struct gsl_complex { double dat[2]; }


decompiled_code:
__int64 __fastcall qdpack_state_set(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
result = qdpack_matrix_set(*(_QWORD *)(a1 + 16), a2, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
result = qdpack_matrix_set(*(_QWORD *)(a1 + 16), a2, 0LL);
return result;
}

original_code:
void
qdpack_state_set(qdpack_state_t *state, size_t i, gsl_complex value)
{
    if (state == ((void *)0))
        return;
    qdpack_matrix_set(state->data, i, 0, value);
}

canonical_original_code:
void qdpack_state_set(struct _qdpack_state *state, unsigned long i, struct gsl_complex value)
{
    if (state == ((void *)0))
        return;
    qdpack_matrix_set(state->data, i, 0, value);
}

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


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

if ( a1 )
result = qdpack_matrix_set_zero(*(_QWORD *)(a1 + 16));
return result;
}

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

if ( a1 )
result = qdpack_matrix_set_zero(*(_QWORD *)(a1 + 16));
return result;
}

original_code:
void
qdpack_state_set_zero(qdpack_state_t *op)
{
    if (op == ((void *)0))
        return;
    return qdpack_matrix_set_zero(op->data);
}

canonical_original_code:
void qdpack_state_set_zero(struct _qdpack_state *op)
{
    if (op == ((void *)0))
        return;
    return qdpack_matrix_set_zero(op->data);
}


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

if ( a1 )
result = qdpack_matrix_scale(*(_QWORD *)(a1 + 16));
return result;
}

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

if ( a1 )
result = qdpack_matrix_scale(*(_QWORD *)(a1 + 16));
return result;
}

original_code:
void
qdpack_state_scale(qdpack_state_t *op, gsl_complex z)
{
    if (op == ((void *)0))
        return;
    qdpack_matrix_scale(op->data, z);
}

canonical_original_code:
void qdpack_state_scale(struct _qdpack_state *op, struct gsl_complex z)
{
    if (op == ((void *)0))
        return;
    qdpack_matrix_scale(op->data, z);
}

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


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

if ( a1 && a2 )
result = qdpack_matrix_add(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16));
else
result = fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", "qdpack_state_add");
return result;
}

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

if ( a1 && a2 )
result = qdpack_matrix_add(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16));
else
result = fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", "qdpack_state_add");
return result;
}

original_code:
void
qdpack_state_add(qdpack_state_t *op1, qdpack_state_t *op2)
{
    if (op1 == ((void *)0) || op2 == ((void *)0))
    {
        fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", __PRETTY_FUNCTION__);
        return;
    }
    qdpack_matrix_add(op1->data, op2->data);
}

canonical_original_code:
void qdpack_state_add(struct _qdpack_state *op1, struct _qdpack_state *op2)
{
    if (op1 == ((void *)0) || op2 == ((void *)0))
    {
        fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", __PRETTY_FUNCTION__);
        return;
    }
    qdpack_matrix_add(op1->data, op2->data);
}


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

if ( a1 && a2 )
result = qdpack_matrix_sub(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16));
else
result = fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", "qdpack_state_sub");
return result;
}

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

if ( a1 && a2 )
result = qdpack_matrix_sub(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16));
else
result = fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", "qdpack_state_sub");
return result;
}

original_code:
void
qdpack_state_sub(qdpack_state_t *op1, qdpack_state_t *op2)
{
    if (op1 == ((void *)0) || op2 == ((void *)0))
    {
        fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", __PRETTY_FUNCTION__);
        return;
    }
    qdpack_matrix_sub(op1->data, op2->data);
}

canonical_original_code:
void qdpack_state_sub(struct _qdpack_state *op1, struct _qdpack_state *op2)
{
    if (op1 == ((void *)0) || op2 == ((void *)0))
    {
        fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", __PRETTY_FUNCTION__);
        return;
    }
    qdpack_matrix_sub(op1->data, op2->data);
}


decompiled_code:
__int64 __fastcall qdpack_state_dot(__int64 a1, __int64 a2)
{
return qdpack_matrix_dot(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
return qdpack_matrix_dot(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16));
}

original_code:
gsl_complex
qdpack_state_dot(qdpack_state_t *a, qdpack_state_t *b)
{
    return qdpack_matrix_dot(a->data, b->data);
}

canonical_original_code:
struct gsl_complex qdpack_state_dot(struct _qdpack_state *a, struct _qdpack_state *b)
{
    return qdpack_matrix_dot(a->data, b->data);
}

variable_types:
b
struct _qdpack_state *


decompiled_code:
__int64 __fastcall qdpack_state_expectation_value(__int64 a1, __int64 a2)
{
return qdpack_matrix_multiply_vmv(*(_QWORD *)(a2 + 16), *(_QWORD *)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
return qdpack_matrix_multiply_vmv(*(_QWORD *)(a2 + 16), *(_QWORD *)(a1 + 16));
}

original_code:
gsl_complex
qdpack_state_expectation_value(qdpack_state_t *wf, qdpack_operator_t *op)
{
    return qdpack_matrix_multiply_vmv(op->data, wf->data);
}

canonical_original_code:
struct gsl_complex qdpack_state_expectation_value(struct _qdpack_state *wf, struct _qdpack_operator_t *op)
{
    return qdpack_matrix_multiply_vmv(op->data, wf->data);
}

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


decompiled_code:
void __fastcall qdpack_operator_free(void *ptr)
{
if ( ptr )
{
qdpack_hilbert_space_free(*((_QWORD *)ptr + 1));
qdpack_matrix_free(*((_QWORD *)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
if ( ptr )
{
qdpack_hilbert_space_free(*((_QWORD *)ptr + 1));
qdpack_matrix_free(*((_QWORD *)ptr + 2));
free(ptr);
}
}

original_code:
void
qdpack_operator_free(qdpack_operator_t *op)
{
    if (op == ((void *)0))
    {
        return;
    }
    qdpack_hilbert_space_free(op->qs);
    qdpack_matrix_free(op->data);
    free(op);
}

canonical_original_code:
void qdpack_operator_free(struct _qdpack_operator_t *op)
{
    if (op == ((void *)0))
    {
        return;
    }
    qdpack_hilbert_space_free(op->qs);
    qdpack_matrix_free(op->data);
    free(op);
}

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; } *


decompiled_code:
void __fastcall qdpack_operator_memcpy(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rax
__int64 v5; // rsi
__int64 v6; // rdi

if ( a2 && a1 )
{
*(_DWORD *)a1 = *(_DWORD *)a2;
*(_DWORD *)(a1 + 4) = *(_DWORD *)(a2 + 4);
v3 = *(_QWORD *)(a1 + 8);
if ( v3 )
qdpack_hilbert_space_free(v3);
v4 = qdpack_hilbert_space_copy(*(_QWORD *)(a2 + 8));
v5 = *(_QWORD *)(a2 + 16);
v6 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 8) = v4;
qdpack_matrix_memcpy(v6, v5);
}
}

original_code:
void
qdpack_operator_memcpy(qdpack_operator_t *dst, qdpack_operator_t *src)
{
    if (src == ((void *)0) || dst == ((void *)0))
        return;
    dst->n = src->n;
    dst->m = src->m;
    if (dst->qs)
        qdpack_hilbert_space_free(dst->qs);
    dst->qs = qdpack_hilbert_space_copy(src->qs);
    qdpack_matrix_memcpy(dst->data, src->data);
}

canonical_original_code:
void qdpack_operator_memcpy(struct _qdpack_operator_t *dst, struct _qdpack_operator_t *src)
{
    if (src == ((void *)0) || dst == ((void *)0))
        return;
    dst->n = src->n;
    dst->m = src->m;
    if (dst->qs)
        qdpack_hilbert_space_free(dst->qs);
    dst->qs = qdpack_hilbert_space_copy(src->qs);
    qdpack_matrix_memcpy(dst->data, src->data);
}

variable_types:
src
struct _qdpack_operator_t *


decompiled_code:
__int64 __fastcall qdpack_operator_get(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( a1 )
result = qdpack_matrix_get(*(_QWORD *)(a1 + 16), a2, a3);
else
result = gsl_complex_rect(0.0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( a1 )
result = qdpack_matrix_get(*(_QWORD *)(a1 + 16), a2, a3);
else
result = gsl_complex_rect(0.0);
return result;
}

original_code:
gsl_complex
qdpack_operator_get(qdpack_operator_t *op, size_t i, size_t j)
{
    if (op == ((void *)0))
        return (gsl_complex_rect(0.0,0.0));
    return qdpack_matrix_get(op->data, i, j);
}

canonical_original_code:
struct gsl_complex qdpack_operator_get(struct _qdpack_operator_t *op, unsigned long i, unsigned long j)
{
    if (op == ((void *)0))
        return (gsl_complex_rect(0.0,0.0));
    return qdpack_matrix_get(op->data, i, j);
}

variable_types:
j
unsigned long


decompiled_code:
__int64 __fastcall qdpack_operator_set(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( a1 )
result = qdpack_matrix_set(*(_QWORD *)(a1 + 16), a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( a1 )
result = qdpack_matrix_set(*(_QWORD *)(a1 + 16), a2, a3);
return result;
}

original_code:
void
qdpack_operator_set(qdpack_operator_t *op, size_t i, size_t j, gsl_complex value)
{
    if (op == ((void *)0))
        return;
    return qdpack_matrix_set(op->data, i, j, value);
}

canonical_original_code:
void qdpack_operator_set(struct _qdpack_operator_t *op, unsigned long i, unsigned long j, struct gsl_complex value)
{
    if (op == ((void *)0))
        return;
    return qdpack_matrix_set(op->data, i, j, value);
}


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

if ( a1 )
result = qdpack_matrix_set_all(*(_QWORD *)(a1 + 16));
return result;
}

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

if ( a1 )
result = qdpack_matrix_set_all(*(_QWORD *)(a1 + 16));
return result;
}

original_code:
void
qdpack_operator_set_all(qdpack_operator_t *op, gsl_complex value)
{
    if (op == ((void *)0))
        return;
    return qdpack_matrix_set_all(op->data, value);
}

canonical_original_code:
void qdpack_operator_set_all(struct _qdpack_operator_t *op, struct gsl_complex value)
{
    if (op == ((void *)0))
        return;
    return qdpack_matrix_set_all(op->data, value);
}


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

if ( a1 )
result = qdpack_matrix_set_zero(*(_QWORD *)(a1 + 16));
return result;
}

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

if ( a1 )
result = qdpack_matrix_set_zero(*(_QWORD *)(a1 + 16));
return result;
}

original_code:
void
qdpack_operator_set_zero(qdpack_operator_t *op)
{
    if (op == ((void *)0))
        return;
    return qdpack_matrix_set_zero(op->data);
}

canonical_original_code:
void qdpack_operator_set_zero(struct _qdpack_operator_t *op)
{
    if (op == ((void *)0))
        return;
    return qdpack_matrix_set_zero(op->data);
}


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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 16) )
result = qdpack_matrix_set_identity();
}
return result;
}

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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 16) )
result = qdpack_matrix_set_identity();
}
return result;
}

original_code:
void
qdpack_operator_set_identity(qdpack_operator_t *op)
{
    if (op && op->data)
    {
        qdpack_matrix_set_identity(op->data);
    }
}

canonical_original_code:
void qdpack_operator_set_identity(struct _qdpack_operator_t *op)
{
    if (op && op->data)
    {
        qdpack_matrix_set_identity(op->data);
    }
}


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

if ( a1 )
result = qdpack_matrix_scale(*(_QWORD *)(a1 + 16));
return result;
}

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

if ( a1 )
result = qdpack_matrix_scale(*(_QWORD *)(a1 + 16));
return result;
}

original_code:
void
qdpack_operator_scale(qdpack_operator_t *op, gsl_complex z)
{
    if (op == ((void *)0))
        return;
    qdpack_matrix_scale(op->data, z);
}

canonical_original_code:
void qdpack_operator_scale(struct _qdpack_operator_t *op, struct gsl_complex z)
{
    if (op == ((void *)0))
        return;
    qdpack_matrix_scale(op->data, z);
}


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

if ( a1 && a2 )
result = qdpack_matrix_add(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16));
else
result = fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", "qdpack_operator_add");
return result;
}

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

if ( a1 && a2 )
result = qdpack_matrix_add(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16));
else
result = fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", "qdpack_operator_add");
return result;
}

original_code:
void
qdpack_operator_add(qdpack_operator_t *op1, qdpack_operator_t *op2)
{
    if (op1 == ((void *)0) || op2 == ((void *)0))
    {
        fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", __PRETTY_FUNCTION__);
        return;
    }
    qdpack_matrix_add(op1->data, op2->data);
}

canonical_original_code:
void qdpack_operator_add(struct _qdpack_operator_t *op1, struct _qdpack_operator_t *op2)
{
    if (op1 == ((void *)0) || op2 == ((void *)0))
    {
        fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", __PRETTY_FUNCTION__);
        return;
    }
    qdpack_matrix_add(op1->data, op2->data);
}


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

if ( a1 && a2 )
result = qdpack_matrix_sub(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16));
else
result = fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", "qdpack_operator_sub");
return result;
}

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

if ( a1 && a2 )
result = qdpack_matrix_sub(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16));
else
result = fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", "qdpack_operator_sub");
return result;
}

original_code:
void
qdpack_operator_sub(qdpack_operator_t *op1, qdpack_operator_t *op2)
{
    if (op1 == ((void *)0) || op2 == ((void *)0))
    {
        fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", __PRETTY_FUNCTION__);
        return;
    }
    qdpack_matrix_sub(op1->data, op2->data);
}

canonical_original_code:
void qdpack_operator_sub(struct _qdpack_operator_t *op1, struct _qdpack_operator_t *op2)
{
    if (op1 == ((void *)0) || op2 == ((void *)0))
    {
        fprintf(stderr, "%s: ERROR: op1 or op2 is NULL\n", __PRETTY_FUNCTION__);
        return;
    }
    qdpack_matrix_sub(op1->data, op2->data);
}


decompiled_code:
int __fastcall qdpack_operator_blas_zgemm(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v5; // rdx
int result; // eax

if ( a3 && (v5 = *(_QWORD *)(a3 + 16), a4) && v5 && *(_QWORD *)(a4 + 16) && a5 && *(_QWORD *)(a5 + 16) )
result = qdpack_matrix_blas_zgemm();
else
result = fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_blas_zgemm");
return result;
}

canonical_decompiled_code:
int __fastcall func20(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v5; // rdx
int result; // eax

if ( a3 && (v5 = *(_QWORD *)(a3 + 16), a4) && v5 && *(_QWORD *)(a4 + 16) && a5 && *(_QWORD *)(a5 + 16) )
result = qdpack_matrix_blas_zgemm();
else
result = fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_blas_zgemm");
return result;
}

original_code:
void
qdpack_operator_blas_zgemm(CBLAS_TRANSPOSE_t transA,
                           CBLAS_TRANSPOSE_t transB,
                           gsl_complex alpha,
                           qdpack_operator_t *A,
                           qdpack_operator_t *B,
                           gsl_complex beta,
                           qdpack_operator_t *C)
{
    if (A && A->data && B && B->data && C && C->data)
    {
        qdpack_matrix_blas_zgemm(transA, transB, alpha, A->data, B->data, beta, C->data);
    }
    else
    {
        fprintf(stderr, "%s: ERROR: NULL valued operator\n", __PRETTY_FUNCTION__);
    }
}

canonical_original_code:
void qdpack_operator_blas_zgemm(enum CBLAS_TRANSPOSE transA, enum CBLAS_TRANSPOSE transB, struct gsl_complex alpha, struct _qdpack_operator_t *A, struct _qdpack_operator_t *B, struct gsl_complex beta, struct _qdpack_operator_t *C)
{
    if (A && A->data && B && B->data && C && C->data)
    {
        qdpack_matrix_blas_zgemm(transA, transB, alpha, A->data, B->data, beta, C->data);
    }
    else
    {
        fprintf(stderr, "%s: ERROR: NULL valued operator\n", __PRETTY_FUNCTION__);
    }
}

variable_types: enum CBLAS_TRANSPOSE { CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113 }

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

variable_types:
B
struct _qdpack_operator_t *

variable_types:
beta
struct gsl_complex

variable_types:
C
struct _qdpack_operator_t *


decompiled_code:
int __fastcall qdpack_operator_multiply(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdi
int result; // eax

if ( a1 && (v3 = *(_QWORD *)(a1 + 16), a2) && v3 && *(_QWORD *)(a2 + 16) && a3 && *(_QWORD *)(a3 + 16) )
result = qdpack_matrix_multiply();
else
result = fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_multiply");
return result;
}

canonical_decompiled_code:
int __fastcall func21(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdi
int result; // eax

if ( a1 && (v3 = *(_QWORD *)(a1 + 16), a2) && v3 && *(_QWORD *)(a2 + 16) && a3 && *(_QWORD *)(a3 + 16) )
result = qdpack_matrix_multiply();
else
result = fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_multiply");
return result;
}

original_code:
void
qdpack_operator_multiply(qdpack_operator_t *A, qdpack_operator_t *B, qdpack_operator_t *C)
{
    if (A && A->data && B && B->data && C && C->data)
    {
        qdpack_matrix_multiply(A->data, B->data, C->data);
    }
    else
    {
        fprintf(stderr, "%s: ERROR: NULL valued operator\n", __PRETTY_FUNCTION__);
    }
}

canonical_original_code:
void qdpack_operator_multiply(struct _qdpack_operator_t *A, struct _qdpack_operator_t *B, struct _qdpack_operator_t *C)
{
    if (A && A->data && B && B->data && C && C->data)
    {
        qdpack_matrix_multiply(A->data, B->data, C->data);
    }
    else
    {
        fprintf(stderr, "%s: ERROR: NULL valued operator\n", __PRETTY_FUNCTION__);
    }
}


decompiled_code:
int __fastcall qdpack_operator_state_multiply(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12
__int64 v4; // r14
__int64 v5; // r13
double v6; // xmm0_8
double v8; // [rsp+18h] [rbp-20h]

if ( !a1 )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_state_multiply");
if ( !*(_QWORD *)(a1 + 16) )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_state_multiply");
if ( !a2 )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_state_multiply");
if ( !*(_QWORD *)(a2 + 16) )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_state_multiply");
if ( !a3 )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_state_multiply");
v3 = *(_QWORD *)(a3 + 16);
if ( !v3 )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_state_multiply");
v8 = gsl_complex_rect(0.0);
v4 = *(_QWORD *)(a2 + 16);
v5 = *(_QWORD *)(a1 + 16);
v6 = gsl_complex_rect(1.0);
return qdpack_matrix_blas_zgemm(111LL, 111LL, v5, v4, v3, v6, 0.0, v8, 0.0);
}

canonical_decompiled_code:
int __fastcall func22(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12
__int64 v4; // r14
__int64 v5; // r13
double v6; // xmm0_8
double v8; // [rsp+18h] [rbp-20h]

if ( !a1 )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_state_multiply");
if ( !*(_QWORD *)(a1 + 16) )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_state_multiply");
if ( !a2 )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_state_multiply");
if ( !*(_QWORD *)(a2 + 16) )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_state_multiply");
if ( !a3 )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_state_multiply");
v3 = *(_QWORD *)(a3 + 16);
if ( !v3 )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_operator_state_multiply");
v8 = gsl_complex_rect(0.0);
v4 = *(_QWORD *)(a2 + 16);
v5 = *(_QWORD *)(a1 + 16);
v6 = gsl_complex_rect(1.0);
return qdpack_matrix_blas_zgemm(111LL, 111LL, v5, v4, v3, v6, 0.0, v8, 0.0);
}

original_code:
void
qdpack_operator_state_multiply(qdpack_operator_t *A, qdpack_state_t *B, qdpack_state_t *C)
{
    if (A && A->data && B && B->data && C && C->data)
    {
        qdpack_matrix_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), A->data, B->data, (gsl_complex_rect(0.0,0.0)), C->data);
    }
    else
    {
        fprintf(stderr, "%s: ERROR: NULL valued operator\n", __PRETTY_FUNCTION__);
    }
}

canonical_original_code:
void qdpack_operator_state_multiply(struct _qdpack_operator_t *A, struct _qdpack_state *B, struct _qdpack_state *C)
{
    if (A && A->data && B && B->data && C && C->data)
    {
        qdpack_matrix_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), A->data, B->data, (gsl_complex_rect(0.0,0.0)), C->data);
    }
    else
    {
        fprintf(stderr, "%s: ERROR: NULL valued operator\n", __PRETTY_FUNCTION__);
    }
}

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

variable_types:
C
struct _qdpack_state *


decompiled_code:
double __fastcall qdpack_operator_expectation_value(int *a1, __int64 a2, double a3, double a4)
{
__int64 v4; // r12
double v5; // xmm4_8
__int64 v6; // rbx
double v7; // xmm5_8
__int64 v8; // rdx
__int64 v9; // rsi
double v10; // xmm2_8
double v11; // xmm3_8
double v13; // [rsp+0h] [rbp-28h]
double v14; // [rsp+8h] [rbp-20h]
double v15; // [rsp+8h] [rbp-20h]

v4 = qdpack_matrix_alloc(a1[1], *a1);
qdpack_matrix_multiply(*(_QWORD *)(a2 + 16), *((_QWORD *)a1 + 2), v4);
if ( a1[1] <= 0 )
{
v7 = 0.0;
}
else
{
v5 = 0.0;
v6 = 0LL;
v7 = 0.0;
do
{
v8 = v6;
v9 = v6;
v14 = v7;
v13 = v5;
++v6;
v10 = qdpack_matrix_get(v4, v9, v8);
v11 = a4;
a4 = v13;
v7 = gsl_complex_add(v14, v13, v10, v11);
v5 = v13;
}
while ( a1[1] > (int)v6 );
}
v15 = v7;
qdpack_matrix_free(v4);
return v15;
}

canonical_decompiled_code:
double __fastcall func23(int *a1, __int64 a2, double a3, double a4)
{
__int64 v4; // r12
double v5; // xmm4_8
__int64 v6; // rbx
double v7; // xmm5_8
__int64 v8; // rdx
__int64 v9; // rsi
double v10; // xmm2_8
double v11; // xmm3_8
double v13; // [rsp+0h] [rbp-28h]
double v14; // [rsp+8h] [rbp-20h]
double v15; // [rsp+8h] [rbp-20h]

v4 = qdpack_matrix_alloc(a1[1], *a1);
qdpack_matrix_multiply(*(_QWORD *)(a2 + 16), *((_QWORD *)a1 + 2), v4);
if ( a1[1] <= 0 )
{
v7 = 0.0;
}
else
{
v5 = 0.0;
v6 = 0LL;
v7 = 0.0;
do
{
v8 = v6;
v9 = v6;
v14 = v7;
v13 = v5;
++v6;
v10 = qdpack_matrix_get(v4, v9, v8);
v11 = a4;
a4 = v13;
v7 = gsl_complex_add(v14, v13, v10, v11);
v5 = v13;
}
while ( a1[1] > (int)v6 );
}
v15 = v7;
qdpack_matrix_free(v4);
return v15;
}

original_code:
gsl_complex
qdpack_operator_expectation_value(qdpack_operator_t *rho, qdpack_operator_t *op)
{
    qdpack_matrix_t *prod;
    gsl_complex tr;
    int i;
    prod = qdpack_matrix_alloc(rho->m, rho->n);
    qdpack_matrix_multiply(op->data, rho->data, prod);
    do {(&tr)->dat[0]=(0.0); (&tr)->dat[1]=(0.0);} while(0);
    for (i = 0; i < rho->m; i++)
    {
        tr = gsl_complex_add(tr, qdpack_matrix_get(prod, i, i));
    }
    qdpack_matrix_free(prod);
    return tr;
}

canonical_original_code:
struct gsl_complex qdpack_operator_expectation_value(struct _qdpack_operator_t *rho, struct _qdpack_operator_t *op)
{
    struct _qdpack_matrix *prod;
    struct gsl_complex tr;
    int i;
    prod = qdpack_matrix_alloc(rho->m, rho->n);
    qdpack_matrix_multiply(op->data, rho->data, prod);
    do {(&tr)->dat[0]=(0.0); (&tr)->dat[1]=(0.0);} while(0);
    for (i = 0; i < rho->m; i++)
    {
        tr = gsl_complex_add(tr, qdpack_matrix_get(prod, i, i));
    }
    qdpack_matrix_free(prod);
    return tr;
}

variable_types:
op
struct _qdpack_operator_t *

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; } *

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

variable_types: i int


decompiled_code:
double __fastcall qdpack_operator_trace(__int64 a1, double result, double a3)
{
double v3; // xmm4_8
double v4; // xmm5_8
__int64 v5; // rbx
__int64 v6; // rdx
__int64 v7; // rsi
double v8; // xmm3_8
double v9; // [rsp+0h] [rbp-28h]
double v10; // [rsp+8h] [rbp-20h]

if ( *(int *)(a1 + 4) <= 0 )
return 0.0;
v3 = 0.0;
v4 = 0.0;
v5 = 0LL;
do
{
v6 = v5;
v7 = v5;
v10 = v4;
v9 = v3;
++v5;
qdpack_operator_get(a1, v7, v6);
v8 = a3;
a3 = v9;
result = gsl_complex_add(v10, v9, result, v8);
v4 = result;
v3 = v9;
}
while ( *(_DWORD *)(a1 + 4) > (int)v5 );
return result;
}

canonical_decompiled_code:
double __fastcall func24(__int64 a1, double result, double a3)
{
double v3; // xmm4_8
double v4; // xmm5_8
__int64 v5; // rbx
__int64 v6; // rdx
__int64 v7; // rsi
double v8; // xmm3_8
double v9; // [rsp+0h] [rbp-28h]
double v10; // [rsp+8h] [rbp-20h]

if ( *(int *)(a1 + 4) <= 0 )
return 0.0;
v3 = 0.0;
v4 = 0.0;
v5 = 0LL;
do
{
v6 = v5;
v7 = v5;
v10 = v4;
v9 = v3;
++v5;
func12(a1, v7, v6);
v8 = a3;
a3 = v9;
result = gsl_complex_add(v10, v9, result, v8);
v4 = result;
v3 = v9;
}
while ( *(_DWORD *)(a1 + 4) > (int)v5 );
return result;
}

original_code:
gsl_complex
qdpack_operator_trace(qdpack_operator_t *rho)
{
    int i;
    gsl_complex tr;
    do {(&tr)->dat[0]=(0.0); (&tr)->dat[1]=(0.0);} while(0);
    for (i = 0; i < rho->m; i++)
    {
        tr = gsl_complex_add(tr, qdpack_operator_get(rho, i, i));
    }
    return tr;
}

canonical_original_code:
struct gsl_complex qdpack_operator_trace(struct _qdpack_operator_t *rho)
{
    int i;
    struct gsl_complex tr;
    do {(&tr)->dat[0]=(0.0); (&tr)->dat[1]=(0.0);} while(0);
    for (i = 0; i < rho->m; i++)
    {
        tr = gsl_complex_add(tr, qdpack_operator_get(rho, i, i));
    }
    return tr;
}


original_code:
int
qdpack_floquet_modes(qdpack_simulation_t *sim, qdpack_hilbert_space_t *qs)
{
    qdpack_operator_t *U;
    qdpack_matrix_t *Uevec;
    qdpack_matrix_t *Ueval;
    int i, qsn = qdpack_hilbert_space_nstates(qs);
    U = qdpack_operator_alloc(qs);
    qdpack_operator_set_zero(U);
    sim->Ti = 0.0;
    sim->Tf = 2*3.14159265358979323846/sim->h_td_w;
    sim->dT = 2*3.14159265358979323846/sim->h_td_w;
    if (qdpack_propagator(sim, qs, U, ((void *)0)) == -1)
    {
        fprintf(stderr, "Evaluation of the propagator failed.\n");
        return -1;
    }
    Ueval = qdpack_matrix_alloc(qsn, 0);
    Uevec = qdpack_matrix_alloc(qsn, qsn);
    sim->floquet_quasienergies = qdpack_matrix_alloc(qsn, 0);
    sim->floquet_modes = qdpack_operator_alloc(qs);
    qdpack_matrix_eigen_zgeev(U->data, Ueval, Uevec, 3);
    qdpack_matrix_memcpy(sim->floquet_modes->data, Uevec);
    for (i = 0; i < Ueval->m; i++)
    {
        double arg = gsl_complex_arg(qdpack_matrix_get(Ueval, i, 0));
        if (arg > 3.14159265358979323846) arg -= 2*3.14159265358979323846;
        if (arg <= -3.14159265358979323846) arg += 2*3.14159265358979323846;
        qdpack_matrix_set(sim->floquet_quasienergies, i, 0, gsl_complex_rect(-arg/sim->Tf, 0.0));
    }
    qdpack_matrix_free(Uevec);
    qdpack_matrix_free(Ueval);
    qdpack_operator_free(U);
    return 0;
}

canonical_original_code:
int qdpack_floquet_modes(struct _qdpack_simulation *sim, struct qdpack_hilbert_space_t *qs)
{
    struct _qdpack_operator_t *U;
    struct _qdpack_matrix *Uevec;
    struct _qdpack_matrix *Ueval;
    int i; int qsn = qdpack_hilbert_space_nstates(qs);
    U = qdpack_operator_alloc(qs);
    qdpack_operator_set_zero(U);
    sim->Ti = 0.0;
    sim->Tf = 2*3.14159265358979323846/sim->h_td_w;
    sim->dT = 2*3.14159265358979323846/sim->h_td_w;
    if (qdpack_propagator(sim, qs, U, ((void *)0)) == -1)
    {
        fprintf(stderr, "Evaluation of the propagator failed.\n");
        return -1;
    }
    Ueval = qdpack_matrix_alloc(qsn, 0);
    Uevec = qdpack_matrix_alloc(qsn, qsn);
    sim->floquet_quasienergies = qdpack_matrix_alloc(qsn, 0);
    sim->floquet_modes = qdpack_operator_alloc(qs);
    qdpack_matrix_eigen_zgeev(U->data, Ueval, Uevec, 3);
    qdpack_matrix_memcpy(sim->floquet_modes->data, Uevec);
    for (i = 0; i < Ueval->m; i++)
    {
        double arg = gsl_complex_arg(qdpack_matrix_get(Ueval, i, 0));
        if (arg > 3.14159265358979323846) arg -= 2*3.14159265358979323846;
        if (arg <= -3.14159265358979323846) arg += 2*3.14159265358979323846;
        qdpack_matrix_set(sim->floquet_quasienergies, i, 0, gsl_complex_rect(-arg/sim->Tf, 0.0));
    }
    qdpack_matrix_free(Uevec);
    qdpack_matrix_free(Ueval);
    qdpack_operator_free(U);
    return 0;
}

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; } *

variable_types:
qs
struct qdpack_hilbert_space_t *

variable_types: qsn int

variable_types: arg double

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; }


decompiled_code:
__int64 __fastcall qdpack_floquet_modes_t(__int64 a1, __int64 a2, double a3)
{
__int64 v3; // rax
__int64 v4; // r13
__int64 v5; // rbx
double v6; // xmm0_8
__int64 v7; // r12
double v8; // xmm1_8
double v9; // xmm0_8
__int64 v10; // rcx
__int64 v11; // r12
_DWORD *v12; // rax
__int64 i; // rbx
double v14; // xmm1_8
double v15; // xmm2_8
double v16; // xmm3_8
__int64 v17; // rdx
unsigned int v18; // er12
double v20; // [rsp+8h] [rbp-40h]
double v21; // [rsp+10h] [rbp-38h]
double v22; // [rsp+10h] [rbp-38h]

v3 = qdpack_operator_alloc(a2);
*(_QWORD *)(a1 + 8) = 0LL;
v4 = v3;
*(double *)(a1 + 16) = a3;
*(double *)(a1 + 24) = a3;
if ( (unsigned int)qdpack_propagator(a1, a2, v3, 0LL) == -1 )
{
v18 = -1;
fwrite("Evaluation of the propagator failed.\n", 1uLL, 0x25uLL, stderr);
}
else
{
v5 = *(_QWORD *)(a1 + 3144);
v6 = gsl_complex_rect(0.0, 0.0);
v7 = *(_QWORD *)(a1 + 3152);
v21 = v6;
v8 = 0.0;
v9 = gsl_complex_rect(1.0, 0.0);
v10 = v7;
v11 = 0LL;
qdpack_operator_blas_zgemm(111LL, 111LL, v4, v10, v5, v9, 0.0, v21, 0.0);
v12 = *(_DWORD **)(a1 + 3160);
if ( (int)v12[1] > 0 )
{
do
{
for ( i = 0LL; *v12 > (int)i; v12 = *(_DWORD **)(a1 + 3160) )
{
v22 = qdpack_operator_get(*(_QWORD *)(a1 + 3144), v11, i);
v20 = v8;
v14 = a3 * qdpack_matrix_get(*(_QWORD *)(a1 + 3168), i, 0LL);
v15 = gsl_complex_polar(1.0, v14);
v16 = v14;
v8 = v20;
gsl_complex_mul(v22, v20, v15, v16);
v17 = i++;
qdpack_operator_set(*(_QWORD *)(a1 + 3160), v11, v17);
}
++v11;
}
while ( v12[1] > (int)v11 );
}
v18 = 0;
qdpack_operator_free(v4);
}
return v18;
}

original_code:
int
qdpack_floquet_modes_t(qdpack_simulation_t *sim,
                       qdpack_hilbert_space_t *qs,
                       double t)
{
    qdpack_operator_t *U;
    int i, j;
    U = qdpack_operator_alloc(qs);
    sim->Ti = 0.0;
       sim->Tf = t;
    sim->dT = t;
    if (qdpack_propagator(sim, qs, U, ((void *)0)) == -1)
    {
        fprintf(stderr, "Evaluation of the propagator failed.\n");
        return -1;
    }
    qdpack_operator_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), U, sim->floquet_modes, (gsl_complex_rect(0.0,0.0)), sim->floquet_states_t);
    for (i = 0; i < sim->floquet_modes_t->m; i++)
    {
        for (j = 0; j < sim->floquet_modes_t->n; j++)
        {
            gsl_complex z1, z2;
            z1 = qdpack_operator_get(sim->floquet_states_t, i, j);
            z2 = gsl_complex_mul(z1, gsl_complex_polar(1.0, ((qdpack_matrix_get(sim->floquet_quasienergies, j, 0)).dat[0]) * t));
            qdpack_operator_set(sim->floquet_modes_t, i, j, z2);
        }
    }
    qdpack_operator_free(U);
    return 0;
}

canonical_original_code:
int qdpack_floquet_modes_t(struct _qdpack_simulation *sim, struct qdpack_hilbert_space_t *qs, double t)
{
    struct _qdpack_operator_t *U;
    int i; int j;
    U = qdpack_operator_alloc(qs);
    sim->Ti = 0.0;
       sim->Tf = t;
    sim->dT = t;
    if (qdpack_propagator(sim, qs, U, ((void *)0)) == -1)
    {
        fprintf(stderr, "Evaluation of the propagator failed.\n");
        return -1;
    }
    qdpack_operator_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), U, sim->floquet_modes, (gsl_complex_rect(0.0,0.0)), sim->floquet_states_t);
    for (i = 0; i < sim->floquet_modes_t->m; i++)
    {
        for (j = 0; j < sim->floquet_modes_t->n; j++)
        {
            struct gsl_complex z1; struct gsl_complex z2;
            z1 = qdpack_operator_get(sim->floquet_states_t, i, j);
            z2 = gsl_complex_mul(z1, gsl_complex_polar(1.0, ((qdpack_matrix_get(sim->floquet_quasienergies, j, 0)).dat[0]) * t));
            qdpack_operator_set(sim->floquet_modes_t, i, j, z2);
        }
    }
    qdpack_operator_free(U);
    return 0;
}

variable_types: t double

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; } *

variable_types: j int