decompiled_code:
__int64 qdpack_dm_pure_3LS()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // rbx

v0 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v0, 3LL);
v1 = qdpack_operator_alloc(v0);
v2 = v1;
if ( v1 )
{
qdpack_operator_set_zero(v1);
qdpack_operator_set(v2, 0LL, 0LL, 1.0, 0.0);
qdpack_hilbert_space_free(v0);
}
else
{
fwrite("qdpack_dm_pure_3LS: Failed to allocate dm (Out of memory?).\n", 1uLL, 0x3CuLL, stderr);
}
return v2;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // rbx

v0 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v0, 3LL);
v1 = qdpack_operator_alloc(v0);
v2 = v1;
if ( v1 )
{
qdpack_operator_set_zero(v1);
qdpack_operator_set(v2, 0LL, 0LL, 1.0, 0.0);
qdpack_hilbert_space_free(v0);
}
else
{
fwrite("qdpack_dm_pure_3LS: Failed to allocate dm (Out of memory?).\n", 1uLL, 0x3CuLL, stderr);
}
return v2;
}

original_code:
qdpack_operator_t *
qdpack_dm_pure_3LS(double p_ex)
{
    qdpack_operator_t *dm;
    gsl_complex z;
    qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, 3);
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_dm_pure_3LS: Failed to allocate dm (Out of memory?).\n");
        return ((void *)0);
    }
    qdpack_operator_set_zero(dm);
    do {(&z)->dat[0]=(1.0); (&z)->dat[1]=(0.0);} while(0);
    qdpack_operator_set(dm, 0, 0, z);
    qdpack_hilbert_space_free(qs);
    return dm;
}

canonical_original_code:
struct _qdpack_operator_t *qdpack_dm_pure_3LS(double p_ex)
{
    struct _qdpack_operator_t *dm;
    struct gsl_complex z;
    struct qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, 3);
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_dm_pure_3LS: Failed to allocate dm (Out of memory?).\n");
        return ((void *)0);
    }
    qdpack_operator_set_zero(dm);
    do {(&z)->dat[0]=(1.0); (&z)->dat[1]=(0.0);} while(0);
    qdpack_operator_set(dm, 0, 0, z);
    qdpack_hilbert_space_free(qs);
    return dm;
}

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


repo: jrjohansson/qdpack

decompiled_code:
__int64 __fastcall qdpack_dm_boson_thermal(int a1, double a2, double a3)
{
__int64 v3; // r13
double v4; // rbx
__int64 v5; // rax
__int64 v6; // r12
__int64 i; // rbx
double v8; // xmm0_8
double v10; // [rsp+10h] [rbp-38h]
double v11; // [rsp+18h] [rbp-30h]

v3 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v3, (unsigned int)a1);
*(_QWORD *)&v10 = *(_QWORD *)&a2 ^ LC5;
v4 = exp(COERCE_DOUBLE(*(_QWORD *)&a2 ^ LC5) / (a3 + a3));
v11 = v4 / (1.0 - exp(v10 / a3));
v5 = qdpack_operator_alloc(v3);
v6 = v5;
if ( v5 )
{
qdpack_operator_set_zero(v5);
if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
{
v8 = exp(((double)(int)i + 0.5) * v10 / a3);
qdpack_operator_set(v6, i, i, v8 / v11, 0.0);
}
}
qdpack_hilbert_space_free(v3);
}
else
{
fwrite("qdpack_dm_boson_thermal: Failed to allocate dm (Out of memory?).\n", 1uLL, 0x41uLL, stderr);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, double a2, double a3)
{
__int64 v3; // r13
double v4; // rbx
__int64 v5; // rax
__int64 v6; // r12
__int64 i; // rbx
double v8; // xmm0_8
double v10; // [rsp+10h] [rbp-38h]
double v11; // [rsp+18h] [rbp-30h]

v3 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v3, (unsigned int)a1);
*(_QWORD *)&v10 = *(_QWORD *)&a2 ^ LC5;
v4 = exp(COERCE_DOUBLE(*(_QWORD *)&a2 ^ LC5) / (a3 + a3));
v11 = v4 / (1.0 - exp(v10 / a3));
v5 = qdpack_operator_alloc(v3);
v6 = v5;
if ( v5 )
{
qdpack_operator_set_zero(v5);
if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
{
v8 = exp(((double)(int)i + 0.5) * v10 / a3);
qdpack_operator_set(v6, i, i, v8 / v11, 0.0);
}
}
qdpack_hilbert_space_free(v3);
}
else
{
fwrite("qdpack_dm_boson_thermal: Failed to allocate dm (Out of memory?).\n", 1uLL, 0x41uLL, stderr);
}
return v6;
}

original_code:
qdpack_operator_t *
qdpack_dm_boson_thermal(double w, double w_th, int N)
{
    qdpack_operator_t *dm;
    gsl_complex z;
    double Z, p;
    int n;
    qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    Z = exp(-w / (2*w_th)) / (1 - exp(-w/w_th));
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_dm_boson_thermal: Failed to allocate dm (Out of memory?).\n");
        return ((void *)0);
    }
    qdpack_operator_set_zero(dm);
    for (n = 0; n < N; n++)
    {
        p = exp(-w*(n + 0.5) / w_th) / Z;
        do {(&z)->dat[0]=(p); (&z)->dat[1]=(0.0);} while(0);
        qdpack_operator_set(dm, n, n, z);
    }
    qdpack_hilbert_space_free(qs);
    return dm;
}

canonical_original_code:
struct _qdpack_operator_t *qdpack_dm_boson_thermal(double w, double w_th, int N)
{
    struct _qdpack_operator_t *dm;
    struct gsl_complex z;
    double Z; double p;
    int n;
    struct qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    Z = exp(-w / (2*w_th)) / (1 - exp(-w/w_th));
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_dm_boson_thermal: Failed to allocate dm (Out of memory?).\n");
        return ((void *)0);
    }
    qdpack_operator_set_zero(dm);
    for (n = 0; n < N; n++)
    {
        p = exp(-w*(n + 0.5) / w_th) / Z;
        do {(&z)->dat[0]=(p); (&z)->dat[1]=(0.0);} while(0);
        qdpack_operator_set(dm, n, n, z);
    }
    qdpack_hilbert_space_free(qs);
    return dm;
}

variable_types: w double

variable_types: N 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; } *

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

variable_types: Z double

variable_types: p double

variable_types: n int

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 qdpack_dm_coherent_state(int a1, int a2, double a3, double a4)
{
__int64 v6; // rsi
__int64 v7; // rdi
__int64 v8; // r14
__int64 v9; // r12
__int64 v10; // rbx
double v12; // [rsp+20h] [rbp-88h]
long double v13; // [rsp+20h] [rbp-88h]
double v15; // [rsp+38h] [rbp-70h]
double v16; // [rsp+38h] [rbp-70h]
int v17; // [rsp+40h] [rbp-68h]
double x; // [rsp+50h] [rbp-58h]
__int64 v19; // [rsp+58h] [rbp-50h]
double cosx; // [rsp+60h] [rbp-48h] BYREF
double sinx[8]; // [rsp+68h] [rbp-40h] BYREF

v19 = qdpack_hilbert_space_new();
v6 = (unsigned int)a1;
qdpack_hilbert_space_add(v19, (unsigned int)a1);
v7 = v19;
v8 = qdpack_operator_alloc(v19);
if ( v8 )
{
if ( a1 > 0 )
{
x = COERCE_DOUBLE(*(_QWORD *)&a3 ^ LC5) * a3;
v17 = a2;
v9 = 0LL;
do
{
v10 = 0LL;
do
{
v12 = exp(x);
v15 = pow(a3, (double)v17);
v13 = v15 / fact_sqrt(v7, v6) * v12;
v16 = pow(a3, (double)(a2 + (int)v10));
*(double *)&v13 = v16 / fact_sqrt(v7, v6) * v13;
sincos((double)((int)v9 - (int)v10) * a4, sinx, &cosx);
v6 = v9;
v7 = v8;
qdpack_operator_set(v8, v9, v10++, *(double *)&v13 * cosx, *(double *)&v13 * sinx[0]);
}
while ( v10 != a1 );
++v9;
++v17;
}
while ( v9 != a1 );
}
qdpack_hilbert_space_free(v19);
}
else
{
fwrite("qdpack_dm_coherent_state: Failed to allocate dm (Out of memory?).\n", 1uLL, 0x42uLL, stderr);
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2, double a3, double a4)
{
__int64 v6; // rsi
__int64 v7; // rdi
__int64 v8; // r14
__int64 v9; // r12
__int64 v10; // rbx
double v12; // [rsp+20h] [rbp-88h]
long double v13; // [rsp+20h] [rbp-88h]
double v15; // [rsp+38h] [rbp-70h]
double v16; // [rsp+38h] [rbp-70h]
int v17; // [rsp+40h] [rbp-68h]
double x; // [rsp+50h] [rbp-58h]
__int64 v19; // [rsp+58h] [rbp-50h]
double cosx; // [rsp+60h] [rbp-48h] BYREF
double sinx[8]; // [rsp+68h] [rbp-40h] BYREF

v19 = qdpack_hilbert_space_new();
v6 = (unsigned int)a1;
qdpack_hilbert_space_add(v19, (unsigned int)a1);
v7 = v19;
v8 = qdpack_operator_alloc(v19);
if ( v8 )
{
if ( a1 > 0 )
{
x = COERCE_DOUBLE(*(_QWORD *)&a3 ^ LC5) * a3;
v17 = a2;
v9 = 0LL;
do
{
v10 = 0LL;
do
{
v12 = exp(x);
v15 = pow(a3, (double)v17);
v13 = v15 / fact_sqrt(v7, v6) * v12;
v16 = pow(a3, (double)(a2 + (int)v10));
*(double *)&v13 = v16 / fact_sqrt(v7, v6) * v13;
sincos((double)((int)v9 - (int)v10) * a4, sinx, &cosx);
v6 = v9;
v7 = v8;
qdpack_operator_set(v8, v9, v10++, *(double *)&v13 * cosx, *(double *)&v13 * sinx[0]);
}
while ( v10 != a1 );
++v9;
++v17;
}
while ( v9 != a1 );
}
qdpack_hilbert_space_free(v19);
}
else
{
fwrite("qdpack_dm_coherent_state: Failed to allocate dm (Out of memory?).\n", 1uLL, 0x42uLL, stderr);
}
return v8;
}

original_code:
qdpack_operator_t *
qdpack_dm_coherent_state(double r, double theta, int N, int offset)
{
    int m, n;
    qdpack_operator_t *dm;
    gsl_complex z;
    qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_dm_coherent_state: Failed to allocate dm (Out of memory?).\n");
        return ((void *)0);
    }
    for (m = 0; m < N; m++)
    {
        for (n = 0; n < N; n++)
        {
            double dmij = exp(-r * r) * (pow(r, (double)(m+offset)) / fact_sqrt(m+offset)) * (pow(r, (double)(n+offset)) / fact_sqrt(n+offset));
            do {(&z)->dat[0]=(dmij * cos((m-n) * theta)); (&z)->dat[1]=(dmij * sin((m-n) * theta));} while(0);
            qdpack_operator_set(dm, m, n, z);
        }
    }
    qdpack_hilbert_space_free(qs);
    return dm;
}

canonical_original_code:
struct _qdpack_operator_t *qdpack_dm_coherent_state(double r, double theta, int N, int offset)
{
    int m; int n;
    struct _qdpack_operator_t *dm;
    struct gsl_complex z;
    struct qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_dm_coherent_state: Failed to allocate dm (Out of memory?).\n");
        return ((void *)0);
    }
    for (m = 0; m < N; m++)
    {
        for (n = 0; n < N; n++)
        {
            double dmij = exp(-r * r) * (pow(r, (double)(m+offset)) / fact_sqrt(m+offset)) * (pow(r, (double)(n+offset)) / fact_sqrt(n+offset));
            do {(&z)->dat[0]=(dmij * cos((m-n) * theta)); (&z)->dat[1]=(dmij * sin((m-n) * theta));} while(0);
            qdpack_operator_set(dm, m, n, z);
        }
    }
    qdpack_hilbert_space_free(qs);
    return dm;
}

variable_types: r double

variable_types: theta double

variable_types: offset int

variable_types: m int

variable_types: dmij double

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


decompiled_code:
__int64 __fastcall qdpack_dm_fock_state(int a1, unsigned int a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rbp
double v5; // xmm0_8

v2 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v2, a2);
if ( (int)a2 <= a1 )
{
fwrite("qdpack_dm_fock_state: n >= N.\n", 1uLL, 0x1EuLL, stderr);
v4 = 0LL;
}
else
{
v3 = qdpack_operator_alloc(v2);
v4 = v3;
if ( v3 )
{
qdpack_operator_set_zero(v3);
v5 = gsl_complex_rect(1.0, 0.0);
qdpack_operator_set(v4, a1, a1, v5, 0.0);
qdpack_hilbert_space_free(v2);
}
else
{
fwrite("qdpack_dm_fock_state: Failed to allocate dm (Out of memory?).\n", 1uLL, 0x3EuLL, stderr);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, unsigned int a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rbp
double v5; // xmm0_8

v2 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v2, a2);
if ( (int)a2 <= a1 )
{
fwrite("qdpack_dm_fock_state: n >= N.\n", 1uLL, 0x1EuLL, stderr);
v4 = 0LL;
}
else
{
v3 = qdpack_operator_alloc(v2);
v4 = v3;
if ( v3 )
{
qdpack_operator_set_zero(v3);
v5 = gsl_complex_rect(1.0, 0.0);
qdpack_operator_set(v4, a1, a1, v5, 0.0);
qdpack_hilbert_space_free(v2);
}
else
{
fwrite("qdpack_dm_fock_state: Failed to allocate dm (Out of memory?).\n", 1uLL, 0x3EuLL, stderr);
}
}
return v4;
}

original_code:
qdpack_operator_t *
qdpack_dm_fock_state(int n, int N)
{
    qdpack_operator_t *dm;
    qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    if (n >= N)
    {
                fprintf(stderr, "qdpack_dm_fock_state: n >= N.\n");
                return ((void *)0);
    }
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_dm_fock_state: Failed to allocate dm (Out of memory?).\n");
        return ((void *)0);
    }
    qdpack_operator_set_zero(dm);
    qdpack_operator_set(dm, n, n, (gsl_complex_rect(1.0,0.0)));
    qdpack_hilbert_space_free(qs);
    return dm;
}

canonical_original_code:
struct _qdpack_operator_t *qdpack_dm_fock_state(int n, int N)
{
    struct _qdpack_operator_t *dm;
    struct qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    if (n >= N)
    {
                fprintf(stderr, "qdpack_dm_fock_state: n >= N.\n");
                return ((void *)0);
    }
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_dm_fock_state: Failed to allocate dm (Out of memory?).\n");
        return ((void *)0);
    }
    qdpack_operator_set_zero(dm);
    qdpack_operator_set(dm, n, n, (gsl_complex_rect(1.0,0.0)));
    qdpack_hilbert_space_free(qs);
    return dm;
}

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_dm_uniform_superposition(int a1)
{
__int64 v1; // rbp
__int64 v2; // r12
double v3; // xmm0_8
double v4; // xmm0_8

v1 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v1, (unsigned int)a1);
if ( a1 <= 0 )
{
fwrite("qdpack_dm_fock_state: n >= N.\n", 1uLL, 0x1EuLL, stderr);
v2 = 0LL;
}
else
{
v2 = qdpack_operator_alloc(v1);
if ( v2 )
{
v3 = (double)a1;
if ( (double)a1 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
qdpack_operator_set_all(v2, 1.0 / v4, 0.0);
qdpack_hilbert_space_free(v1);
}
else
{
fwrite("qdpack_dm_fock_state: Failed to allocate dm (Out of memory?).\n", 1uLL, 0x3EuLL, stderr);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 v1; // rbp
__int64 v2; // r12
double v3; // xmm0_8
double v4; // xmm0_8

v1 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v1, (unsigned int)a1);
if ( a1 <= 0 )
{
fwrite("qdpack_dm_fock_state: n >= N.\n", 1uLL, 0x1EuLL, stderr);
v2 = 0LL;
}
else
{
v2 = qdpack_operator_alloc(v1);
if ( v2 )
{
v3 = (double)a1;
if ( (double)a1 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
qdpack_operator_set_all(v2, 1.0 / v4, 0.0);
qdpack_hilbert_space_free(v1);
}
else
{
fwrite("qdpack_dm_fock_state: Failed to allocate dm (Out of memory?).\n", 1uLL, 0x3EuLL, stderr);
}
}
return v2;
}

original_code:
qdpack_operator_t *
qdpack_dm_uniform_superposition(int N)
{
    gsl_complex z;
    qdpack_operator_t *dm;
    qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    if (0 >= N)
    {
         fprintf(stderr, "qdpack_dm_fock_state: n >= N.\n");
         return ((void *)0);
    }
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_dm_fock_state: Failed to allocate dm (Out of memory?).\n");
        return ((void *)0);
    }
    do {(&z)->dat[0]=(1.0/sqrt(N)); (&z)->dat[1]=(0);} while(0);
    qdpack_operator_set_all(dm, z);
    qdpack_hilbert_space_free(qs);
    return dm;
}

canonical_original_code:
struct _qdpack_operator_t *qdpack_dm_uniform_superposition(int N)
{
    struct gsl_complex z;
    struct _qdpack_operator_t *dm;
    struct qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    if (0 >= N)
    {
         fprintf(stderr, "qdpack_dm_fock_state: n >= N.\n");
         return ((void *)0);
    }
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_dm_fock_state: Failed to allocate dm (Out of memory?).\n");
        return ((void *)0);
    }
    do {(&z)->dat[0]=(1.0/sqrt(N)); (&z)->dat[1]=(0);} while(0);
    qdpack_operator_set_all(dm, z);
    qdpack_hilbert_space_free(qs);
    return dm;
}


decompiled_code:
__int64 __fastcall qdpack_dm_uniform_mixture(int a1)
{
__int64 v1; // r14
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rbx

if ( a1 <= 0 )
{
fwrite("qdpack_dm_fock_state: n >= N.\n", 1uLL, 0x1EuLL, stderr);
v3 = 0LL;
}
else
{
v1 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v1, (unsigned int)a1);
v2 = qdpack_operator_alloc(v1);
v3 = v2;
if ( v2 )
{
qdpack_operator_set_zero(v2);
if ( *(int *)(v3 + 4) > 0 )
{
v4 = 0LL;
do
{
qdpack_operator_set(v3, v4, v4, 1.0 / (double)a1, 0.0);
++v4;
}
while ( *(_DWORD *)(v3 + 4) > (int)v4 );
}
qdpack_hilbert_space_free(v1);
}
else
{
fwrite("qdpack_dm_fock_state: Failed to allocate dm (Out of memory?).\n", 1uLL, 0x3EuLL, stderr);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 v1; // r14
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rbx

if ( a1 <= 0 )
{
fwrite("qdpack_dm_fock_state: n >= N.\n", 1uLL, 0x1EuLL, stderr);
v3 = 0LL;
}
else
{
v1 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v1, (unsigned int)a1);
v2 = qdpack_operator_alloc(v1);
v3 = v2;
if ( v2 )
{
qdpack_operator_set_zero(v2);
if ( *(int *)(v3 + 4) > 0 )
{
v4 = 0LL;
do
{
qdpack_operator_set(v3, v4, v4, 1.0 / (double)a1, 0.0);
++v4;
}
while ( *(_DWORD *)(v3 + 4) > (int)v4 );
}
qdpack_hilbert_space_free(v1);
}
else
{
fwrite("qdpack_dm_fock_state: Failed to allocate dm (Out of memory?).\n", 1uLL, 0x3EuLL, stderr);
}
}
return v3;
}

original_code:
qdpack_operator_t *
qdpack_dm_uniform_mixture(int N)
{
    int i;
    gsl_complex z;
    qdpack_operator_t *dm;
    qdpack_hilbert_space_t *qs;
    if (0 >= N)
    {
         fprintf(stderr, "qdpack_dm_fock_state: n >= N.\n");
         return ((void *)0);
    }
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_dm_fock_state: Failed to allocate dm (Out of memory?).\n");
        return ((void *)0);
    }
    do {(&z)->dat[0]=(1.0/N); (&z)->dat[1]=(0);} while(0);
    qdpack_operator_set_zero(dm);
    for (i = 0; i < dm->m; i++)
    {
        qdpack_operator_set(dm, i, i, z);
    }
    qdpack_hilbert_space_free(qs);
    return dm;
}

canonical_original_code:
struct _qdpack_operator_t *qdpack_dm_uniform_mixture(int N)
{
    int i;
    struct gsl_complex z;
    struct _qdpack_operator_t *dm;
    struct qdpack_hilbert_space_t *qs;
    if (0 >= N)
    {
         fprintf(stderr, "qdpack_dm_fock_state: n >= N.\n");
         return ((void *)0);
    }
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_dm_fock_state: Failed to allocate dm (Out of memory?).\n");
        return ((void *)0);
    }
    do {(&z)->dat[0]=(1.0/N); (&z)->dat[1]=(0);} while(0);
    qdpack_operator_set_zero(dm);
    for (i = 0; i < dm->m; i++)
    {
        qdpack_operator_set(dm, i, i, z);
    }
    qdpack_hilbert_space_free(qs);
    return dm;
}

variable_types: i int


decompiled_code:
__int64 __fastcall qdpack_dm_mix(__int64 a1, __int64 a2, __int64 a3)
{
qdpack_operator_memcpy();
qdpack_operator_add(a1, a3);
qdpack_operator_scale(a1, 0.5, 0.0);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3)
{
qdpack_operator_memcpy();
qdpack_operator_add(a1, a3);
qdpack_operator_scale(a1, 0.5, 0.0);
return 0LL;
}

original_code:
int
qdpack_dm_mix(qdpack_operator_t *rho_mix, qdpack_operator_t *rho1, qdpack_operator_t *rho2)
{
    gsl_complex z;
    do {(&z)->dat[0]=(0.5); (&z)->dat[1]=(0.0);} while(0);
    qdpack_operator_memcpy(rho_mix, rho1);
    qdpack_operator_add(rho_mix, rho2);
    qdpack_operator_scale(rho_mix, z);
    return 0;
}

canonical_original_code:
int qdpack_dm_mix(struct _qdpack_operator_t *rho_mix, struct _qdpack_operator_t *rho1, struct _qdpack_operator_t *rho2)
{
    struct gsl_complex z;
    do {(&z)->dat[0]=(0.5); (&z)->dat[1]=(0.0);} while(0);
    qdpack_operator_memcpy(rho_mix, rho1);
    qdpack_operator_add(rho_mix, rho2);
    qdpack_operator_scale(rho_mix, z);
    return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall qdpack_wf_coherent_state(int a1, int a2, double a3, double a4)
{
__int64 v6; // r15
__int64 v7; // rsi
__int64 v8; // rax
__int64 v9; // r12
__int64 v10; // rdi
__int64 v11; // rbx
double v13; // xmm0_8
double v14; // [rsp+10h] [rbp-78h]
double v15; // [rsp+10h] [rbp-78h]
double v16; // [rsp+18h] [rbp-70h]
double x; // [rsp+38h] [rbp-50h]
double cosx; // [rsp+40h] [rbp-48h] BYREF
double sinx[8]; // [rsp+48h] [rbp-40h] BYREF

v6 = qdpack_hilbert_space_new();
v7 = (unsigned int)a1;
qdpack_hilbert_space_add(v6, (unsigned int)a1);
v8 = qdpack_state_alloc(v6);
v9 = v8;
if ( v8 )
{
v10 = v8;
qdpack_state_set_zero(v8);
if ( a3 == 0.0 )
{
v13 = gsl_complex_rect(1.0, 0.0);
qdpack_state_set(v9, 0LL, v13, 0.0);
}
else if ( a1 > 0 )
{
x = COERCE_DOUBLE(*(_QWORD *)&a3 ^ LC5) * a3 * 0.5;
v11 = 0LL;
do
{
v14 = exp(x);
v16 = pow(a3, (double)(a2 + (int)v11));
v15 = v16 / fact_sqrt(v10, v7) * v14;
sincos((double)(int)v11 * a4, sinx, &cosx);
v7 = v11;
v10 = v9;
qdpack_state_set(v9, v11++, v15 * cosx, v15 * sinx[0]);
}
while ( v11 != a1 );
}
qdpack_hilbert_space_free(v6);
}
else
{
fprintf(stderr, "%s: Failed to allocate wf (Out of memory?).\n", "qdpack_wf_coherent_state");
qdpack_hilbert_space_free(v6);
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2, double a3, double a4)
{
__int64 v6; // r15
__int64 v7; // rsi
__int64 v8; // rax
__int64 v9; // r12
__int64 v10; // rdi
__int64 v11; // rbx
double v13; // xmm0_8
double v14; // [rsp+10h] [rbp-78h]
double v15; // [rsp+10h] [rbp-78h]
double v16; // [rsp+18h] [rbp-70h]
double x; // [rsp+38h] [rbp-50h]
double cosx; // [rsp+40h] [rbp-48h] BYREF
double sinx[8]; // [rsp+48h] [rbp-40h] BYREF

v6 = qdpack_hilbert_space_new();
v7 = (unsigned int)a1;
qdpack_hilbert_space_add(v6, (unsigned int)a1);
v8 = qdpack_state_alloc(v6);
v9 = v8;
if ( v8 )
{
v10 = v8;
qdpack_state_set_zero(v8);
if ( a3 == 0.0 )
{
v13 = gsl_complex_rect(1.0, 0.0);
qdpack_state_set(v9, 0LL, v13, 0.0);
}
else if ( a1 > 0 )
{
x = COERCE_DOUBLE(*(_QWORD *)&a3 ^ LC5) * a3 * 0.5;
v11 = 0LL;
do
{
v14 = exp(x);
v16 = pow(a3, (double)(a2 + (int)v11));
v15 = v16 / fact_sqrt(v10, v7) * v14;
sincos((double)(int)v11 * a4, sinx, &cosx);
v7 = v11;
v10 = v9;
qdpack_state_set(v9, v11++, v15 * cosx, v15 * sinx[0]);
}
while ( v11 != a1 );
}
qdpack_hilbert_space_free(v6);
}
else
{
fprintf(stderr, "%s: Failed to allocate wf (Out of memory?).\n", "qdpack_wf_coherent_state");
qdpack_hilbert_space_free(v6);
}
return v9;
}

original_code:
qdpack_state_t *
qdpack_wf_coherent_state(double r, double theta, int N, int offset)
{
    int n;
    gsl_complex z;
    qdpack_state_t *wf;
    qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    if ((wf = qdpack_state_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "%s: Failed to allocate wf (Out of memory?).\n", __PRETTY_FUNCTION__);
        qdpack_hilbert_space_free(qs);
        return ((void *)0);
    }
    qdpack_state_set_zero(wf);
    if (r == 0)
    {
        qdpack_state_set(wf, 0, (gsl_complex_rect(1.0,0.0)));
    }
    else
    {
        for (n = 0; n < N; n++)
        {
            double wfi = exp(-r * r / 2.0) * (pow(r, (double)(n+offset)) / fact_sqrt(n+offset));
            do {(&z)->dat[0]=(wfi * cos(n * theta)); (&z)->dat[1]=(wfi * sin(n * theta));} while(0);
            qdpack_state_set(wf, n, z);
        }
    }
    qdpack_hilbert_space_free(qs);
    return wf;
}

canonical_original_code:
struct _qdpack_state *qdpack_wf_coherent_state(double r, double theta, int N, int offset)
{
    int n;
    struct gsl_complex z;
    struct _qdpack_state *wf;
    struct qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    if ((wf = qdpack_state_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "%s: Failed to allocate wf (Out of memory?).\n", __PRETTY_FUNCTION__);
        qdpack_hilbert_space_free(qs);
        return ((void *)0);
    }
    qdpack_state_set_zero(wf);
    if (r == 0)
    {
        qdpack_state_set(wf, 0, (gsl_complex_rect(1.0,0.0)));
    }
    else
    {
        for (n = 0; n < N; n++)
        {
            double wfi = exp(-r * r / 2.0) * (pow(r, (double)(n+offset)) / fact_sqrt(n+offset));
            do {(&z)->dat[0]=(wfi * cos(n * theta)); (&z)->dat[1]=(wfi * sin(n * theta));} while(0);
            qdpack_state_set(wf, n, z);
        }
    }
    qdpack_hilbert_space_free(qs);
    return wf;
}

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: wfi double

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


decompiled_code:
__int64 __fastcall qdpack_wf_superposition(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx

v2 = qdpack_state_alloc(*(_QWORD *)(a1 + 8));
v3 = v2;
if ( v2 )
{
qdpack_state_memcpy(v2, a1);
qdpack_state_add(v3, a2);
qdpack_state_scale(v3, 0.7071067811865476, 0.0);
}
else
{
fwrite("qdpack_wf_fock_state: Failed to allocate wf (Out of memory?).\n", 1uLL, 0x3EuLL, stderr);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx

v2 = qdpack_state_alloc(*(_QWORD *)(a1 + 8));
v3 = v2;
if ( v2 )
{
qdpack_state_memcpy(v2, a1);
qdpack_state_add(v3, a2);
qdpack_state_scale(v3, 0.7071067811865476, 0.0);
}
else
{
fwrite("qdpack_wf_fock_state: Failed to allocate wf (Out of memory?).\n", 1uLL, 0x3EuLL, stderr);
}
return v3;
}

original_code:
qdpack_state_t *
qdpack_wf_superposition(qdpack_state_t *wf1, qdpack_state_t *wf2)
{
    qdpack_state_t *wf;
    gsl_complex z;
    do {(&z)->dat[0]=(sqrt(0.5)); (&z)->dat[1]=(0.0);} while(0);
    if ((wf = qdpack_state_alloc(wf1->qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_wf_fock_state: Failed to allocate wf (Out of memory?).\n");
        wf = ((void *)0);
    }
    else
    {
        qdpack_state_memcpy(wf, wf1);
        qdpack_state_add(wf, wf2);
        qdpack_state_scale(wf, z);
    }
    return wf;
}

canonical_original_code:
struct _qdpack_state *qdpack_wf_superposition(struct _qdpack_state *wf1, struct _qdpack_state *wf2)
{
    struct _qdpack_state *wf;
    struct gsl_complex z;
    do {(&z)->dat[0]=(sqrt(0.5)); (&z)->dat[1]=(0.0);} while(0);
    if ((wf = qdpack_state_alloc(wf1->qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_wf_fock_state: Failed to allocate wf (Out of memory?).\n");
        wf = ((void *)0);
    }
    else
    {
        qdpack_state_memcpy(wf, wf1);
        qdpack_state_add(wf, wf2);
        qdpack_state_scale(wf, z);
    }
    return wf;
}

return_type: 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:
__int64 __fastcall qdpack_wf_fock_state(int a1, unsigned int a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rbp
double v5; // xmm0_8

if ( a1 >= (int)a2 )
{
fwrite("qdpack_wf_fock_state: n >= N.\n", 1uLL, 0x1EuLL, stderr);
v4 = 0LL;
}
else
{
v2 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v2, a2);
v3 = qdpack_state_alloc(v2);
v4 = v3;
if ( v3 )
{
qdpack_state_set_zero(v3);
v5 = gsl_complex_rect(1.0, 0.0);
qdpack_state_set(v4, a1, v5, 0.0);
}
else
{
fwrite("qdpack_wf_fock_state: Failed to allocate wf (Out of memory?).\n", 1uLL, 0x3EuLL, stderr);
}
qdpack_hilbert_space_free(v2);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, unsigned int a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rbp
double v5; // xmm0_8

if ( a1 >= (int)a2 )
{
fwrite("qdpack_wf_fock_state: n >= N.\n", 1uLL, 0x1EuLL, stderr);
v4 = 0LL;
}
else
{
v2 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v2, a2);
v3 = qdpack_state_alloc(v2);
v4 = v3;
if ( v3 )
{
qdpack_state_set_zero(v3);
v5 = gsl_complex_rect(1.0, 0.0);
qdpack_state_set(v4, a1, v5, 0.0);
}
else
{
fwrite("qdpack_wf_fock_state: Failed to allocate wf (Out of memory?).\n", 1uLL, 0x3EuLL, stderr);
}
qdpack_hilbert_space_free(v2);
}
return v4;
}

original_code:
qdpack_state_t *
qdpack_wf_fock_state(int n, int N)
{
    qdpack_state_t *wf;
    qdpack_hilbert_space_t *qs;
    if (n >= N)
    {
        fprintf(stderr, "qdpack_wf_fock_state: n >= N.\n");
        return ((void *)0);
    }
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    if ((wf = qdpack_state_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_wf_fock_state: Failed to allocate wf (Out of memory?).\n");
        wf = ((void *)0);
    }
    else
    {
        qdpack_state_set_zero(wf);
        qdpack_state_set(wf, n, (gsl_complex_rect(1.0,0.0)));
    }
    qdpack_hilbert_space_free(qs);
    return wf;
}

canonical_original_code:
struct _qdpack_state *qdpack_wf_fock_state(int n, int N)
{
    struct _qdpack_state *wf;
    struct qdpack_hilbert_space_t *qs;
    if (n >= N)
    {
        fprintf(stderr, "qdpack_wf_fock_state: n >= N.\n");
        return ((void *)0);
    }
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, N);
    if ((wf = qdpack_state_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_wf_fock_state: Failed to allocate wf (Out of memory?).\n");
        wf = ((void *)0);
    }
    else
    {
        qdpack_state_set_zero(wf);
        qdpack_state_set(wf, n, (gsl_complex_rect(1.0,0.0)));
    }
    qdpack_hilbert_space_free(qs);
    return wf;
}


decompiled_code:
__int64 __fastcall qdpack_state_to_operator(_DWORD *a1, int *a2, double a3, double a4)
{
int v4; // eax
__int64 v5; // r12
__int64 result; // rax
double v7; // r15
double v8; // xmm0_8
double v9; // xmm2_8
double v10; // xmm0_8
__int64 i; // rbx

v4 = *a2;
if ( a1[1] == *a2 && v4 == *a1 )
{
v5 = 0LL;
if ( v4 > 0 )
{
do
{
for ( i = 0LL; *a2 > (int)i; ++i )
{
v7 = qdpack_state_get(a2, v5);
v8 = qdpack_state_get(a2, i);
v9 = gsl_complex_conjugate(v8);
v10 = gsl_complex_mul(v7, a4, v9, a4);
qdpack_operator_set(a1, v5, i, v10, a4);
}
++v5;
}
while ( *a2 > (int)v5 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
fwrite("qdpack_state_to_operator: vector-matrix size mismatch\n", 1uLL, 0x36uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_DWORD *a1, int *a2, double a3, double a4)
{
int v4; // eax
__int64 v5; // r12
__int64 result; // rax
double v7; // r15
double v8; // xmm0_8
double v9; // xmm2_8
double v10; // xmm0_8
__int64 i; // rbx

v4 = *a2;
if ( a1[1] == *a2 && v4 == *a1 )
{
v5 = 0LL;
if ( v4 > 0 )
{
do
{
for ( i = 0LL; *a2 > (int)i; ++i )
{
v7 = qdpack_state_get(a2, v5);
v8 = qdpack_state_get(a2, i);
v9 = gsl_complex_conjugate(v8);
v10 = gsl_complex_mul(v7, a4, v9, a4);
qdpack_operator_set(a1, v5, i, v10, a4);
}
++v5;
}
while ( *a2 > (int)v5 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
fwrite("qdpack_state_to_operator: vector-matrix size mismatch\n", 1uLL, 0x36uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
qdpack_state_to_operator(qdpack_operator_t *rho, qdpack_state_t *wf)
{
    gsl_complex x, y;
    int i, j;
    if ((rho->m) != (wf->n) || (rho->n) != (wf->n))
    {
        fprintf(stderr, "qdpack_state_to_operator: vector-matrix size mismatch\n");
        return -1;
    }
    for (i = 0; i < wf->n; i++)
    {
        for (j = 0; j < wf->n; j++)
        {
            x = qdpack_state_get(wf, i);
            y = qdpack_state_get(wf, j);
            qdpack_operator_set(rho, i, j, gsl_complex_mul(x, gsl_complex_conjugate(y)));
        }
    }
    return 0;
}

canonical_original_code:
int qdpack_state_to_operator(struct _qdpack_operator_t *rho, struct _qdpack_state *wf)
{
    struct gsl_complex x; struct gsl_complex y;
    int i; int j;
    if ((rho->m) != (wf->n) || (rho->n) != (wf->n))
    {
        fprintf(stderr, "qdpack_state_to_operator: vector-matrix size mismatch\n");
        return -1;
    }
    for (i = 0; i < wf->n; i++)
    {
        for (j = 0; j < wf->n; j++)
        {
            x = qdpack_state_get(wf, i);
            y = qdpack_state_get(wf, j);
            qdpack_operator_set(rho, i, j, gsl_complex_mul(x, gsl_complex_conjugate(y)));
        }
    }
    return 0;
}

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

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

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

variable_types: j int


decompiled_code:
__int64 __fastcall qdpack_operator_tensor(__int64 a1, int *a2, __int64 a3, double a4, double a5)
{
int v6; // eax
__int64 result; // rax
__int64 v8; // r15
double v9; // rbp
__int64 v10; // r12
double v11; // xmm2_8
double v12; // xmm3_8
__int64 v13; // [rsp+8h] [rbp-F0h]
__int64 v14; // [rsp+10h] [rbp-E8h]
int v15[20]; // [rsp+20h] [rbp-D8h] BYREF
int v16[34]; // [rsp+70h] [rbp-88h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int *a2, __int64 a3, double a4, double a5)
{
int v6; // eax
__int64 result; // rax
__int64 v8; // r15
double v9; // rbp
__int64 v10; // r12
double v11; // xmm2_8
double v12; // xmm3_8
__int64 v13; // [rsp+8h] [rbp-F0h]
__int64 v14; // [rsp+10h] [rbp-E8h]
int v15[20]; // [rsp+20h] [rbp-D8h] BYREF
int v16[34]; // [rsp+70h] [rbp-88h] BYREF

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

original_code:
int
qdpack_operator_tensor(qdpack_operator_t *dm_full, qdpack_hilbert_space_t *qs, qdpack_operator_list_t *dm_list)
{
    int ns, i, j, k;
    gsl_complex dm_ij;
    qdpack_hilbert_space_state_vector_t qsv1, qsv2;
    ns = qdpack_hilbert_space_nstates(qs);
    if (qs == ((void *)0) || dm_list == ((void *)0) || qs->nsubsys != dm_list->len)
    {
        fprintf(stderr, "qdpack_operator_tensor: NULL arguments or system-size/dm_list mismatch.\n");
        return -1;
    }
    for (i = 0; i < ns; i++)
    {
        qdpack_hilbert_space_state_vector(qs, i, qsv1);
        for (j = 0; j < ns; j++)
        {
            qdpack_hilbert_space_state_vector(qs, j, qsv2);
            do {(&dm_ij)->dat[0]=(1.0); (&dm_ij)->dat[1]=(0.0);} while(0);
            for (k = 0; k < qs->nsubsys; k++)
            {
                dm_ij = gsl_complex_mul(dm_ij, qdpack_operator_get(dm_list->dm[k],qsv1[k],qsv2[k]));
            }
            qdpack_operator_set(dm_full, i, j, dm_ij);
        }
    }
    return 0;
}

canonical_original_code:
int qdpack_operator_tensor(struct _qdpack_operator_t *dm_full, struct qdpack_hilbert_space_t *qs, struct qdpack_operator_list_t *dm_list)
{
    int ns; int i; int j; int k;
    struct gsl_complex dm_ij;
    int qsv1[20]; int qsv2[20];
    ns = qdpack_hilbert_space_nstates(qs);
    if (qs == ((void *)0) || dm_list == ((void *)0) || qs->nsubsys != dm_list->len)
    {
        fprintf(stderr, "qdpack_operator_tensor: NULL arguments or system-size/dm_list mismatch.\n");
        return -1;
    }
    for (i = 0; i < ns; i++)
    {
        qdpack_hilbert_space_state_vector(qs, i, qsv1);
        for (j = 0; j < ns; j++)
        {
            qdpack_hilbert_space_state_vector(qs, j, qsv2);
            do {(&dm_ij)->dat[0]=(1.0); (&dm_ij)->dat[1]=(0.0);} while(0);
            for (k = 0; k < qs->nsubsys; k++)
            {
                dm_ij = gsl_complex_mul(dm_ij, qdpack_operator_get(dm_list->dm[k],qsv1[k],qsv2[k]));
            }
            qdpack_operator_set(dm_full, i, j, dm_ij);
        }
    }
    return 0;
}

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:
qs
struct qdpack_hilbert_space_t *

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

variable_types: ns int

variable_types: k int


decompiled_code:
void __fastcall qdpack_operator_list_init(_QWORD *a1)
{
_QWORD *v1; // rax

if ( a1 )
{
v1 = a1;
do
*v1++ = 0LL;
while ( v1 != a1 + 20 );
*((_DWORD *)a1 + 40) = 0;
}
}

original_code:
void
qdpack_operator_list_init(qdpack_operator_list_t *dm_list)
{
    int i;
    if (dm_list != ((void *)0))
    {
        for (i = 0; i < 20; i++)
            dm_list->dm[i] = ((void *)0);
        dm_list->len = 0;
    }
}

canonical_original_code:
void qdpack_operator_list_init(struct qdpack_operator_list_t *dm_list)
{
    int i;
    if (dm_list != ((void *)0))
    {
        for (i = 0; i < 20; i++)
            dm_list->dm[i] = ((void *)0);
        dm_list->len = 0;
    }
}

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

return_type: void

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


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

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

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

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

original_code:
void
qdpack_operator_list_append(qdpack_operator_list_t *dm_list, qdpack_operator_t *dm)
{
    if (dm_list->len < 20)
        dm_list->dm[dm_list->len++] = dm;
    else
        fprintf(stderr, "qdpack_operator_list_append: Reached max size.\n");
}

canonical_original_code:
void qdpack_operator_list_append(struct qdpack_operator_list_t *dm_list, struct _qdpack_operator_t *dm)
{
    if (dm_list->len < 20)
        dm_list->dm[dm_list->len++] = dm;
    else
        fprintf(stderr, "qdpack_operator_list_append: Reached max size.\n");
}

variable_types:
dm
struct _qdpack_operator_t *


decompiled_code:
__int64 __fastcall qdpack_operator_list_free_entries(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 160) > 0 )
{
v1 = 0LL;
do
result = qdpack_operator_free(*(_QWORD *)(a1 + 8 * v1++));
while ( *(_DWORD *)(a1 + 160) > (int)v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 160) > 0 )
{
v1 = 0LL;
do
result = qdpack_operator_free(*(_QWORD *)(a1 + 8 * v1++));
while ( *(_DWORD *)(a1 + 160) > (int)v1 );
}
return result;
}

original_code:
void
qdpack_operator_list_free_entries(qdpack_operator_list_t *dm_list)
{
    int i;
    for (i = 0; i < dm_list->len; i++)
        qdpack_operator_free(dm_list->dm[i]);
}

canonical_original_code:
void qdpack_operator_list_free_entries(struct qdpack_operator_list_t *dm_list)
{
    int i;
    for (i = 0; i < dm_list->len; i++)
        qdpack_operator_free(dm_list->dm[i]);
}


decompiled_code:
__int64 __fastcall qdpack_operator_traceout(__int64 a1, __int64 a2, int a3, double a4, double a5)
{
int v5; // ebx
__int64 v6; // r12
__int64 v7; // rbp
int v8; // er13
__int64 v9; // rbx
unsigned int k; // er13
int v11; // ebp
int v12; // eax
double v13; // xmm2_8
double v14; // xmm3_8
double v16; // [rsp+0h] [rbp-118h]
int v17; // [rsp+18h] [rbp-100h]
__int64 j; // [rsp+20h] [rbp-F8h]
__int64 i; // [rsp+28h] [rbp-F0h]
__int64 v21; // [rsp+30h] [rbp-E8h]
__int64 v22; // [rsp+38h] [rbp-E0h]
int v23[20]; // [rsp+40h] [rbp-D8h] BYREF
int v24[34]; // [rsp+90h] [rbp-88h] BYREF

v5 = a3;
v6 = qdpack_hilbert_space_new();
v7 = v5;
qdpack_hilbert_space_add(v6, *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * v5));
v8 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * v5);
v22 = qdpack_operator_alloc(v6);
if ( v22 )
{
v9 = qdpack_hilbert_space_copy(a1);
*(_DWORD *)(*(_QWORD *)(v9 + 8) + 4 * v7) = 1;
v17 = qdpack_hilbert_space_nstates(v9);
if ( v8 > 0 )
{
v21 = (unsigned int)v8;
for ( i = 0LL; i != v21; ++i )
{
for ( j = 0LL; j != v21; ++j )
{
v16 = 0.0;
if ( v17 > 0 )
{
for ( k = 0; k != v17; ++k )
{
qdpack_hilbert_space_state_vector(v9, k, v23);
qdpack_hilbert_space_state_vector(v9, k, v24);
v24[a3] = i;
v23[a3] = j;
v11 = qdpack_hilbert_space_state_number(a1, v24);
v12 = qdpack_hilbert_space_state_number(a1, v23);
v13 = qdpack_operator_get(a2, v11, v12);
v14 = a5;
a5 = 0.0;
v16 = gsl_complex_add(v16, 0.0, v13, v14);
}
}
a5 = 0.0;
qdpack_operator_set(v22, i, j, v16, 0.0);
}
}
}
}
else
{
fwrite("qdpack_operator_traceout: Failed to allocate dm_part (Out of memory?).\n", 1uLL, 0x47uLL, stderr);
}
return v22;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, int a3, double a4, double a5)
{
int v5; // ebx
__int64 v6; // r12
__int64 v7; // rbp
int v8; // er13
__int64 v9; // rbx
unsigned int k; // er13
int v11; // ebp
int v12; // eax
double v13; // xmm2_8
double v14; // xmm3_8
double v16; // [rsp+0h] [rbp-118h]
int v17; // [rsp+18h] [rbp-100h]
__int64 j; // [rsp+20h] [rbp-F8h]
__int64 i; // [rsp+28h] [rbp-F0h]
__int64 v21; // [rsp+30h] [rbp-E8h]
__int64 v22; // [rsp+38h] [rbp-E0h]
int v23[20]; // [rsp+40h] [rbp-D8h] BYREF
int v24[34]; // [rsp+90h] [rbp-88h] BYREF

v5 = a3;
v6 = qdpack_hilbert_space_new();
v7 = v5;
qdpack_hilbert_space_add(v6, *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * v5));
v8 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * v5);
v22 = qdpack_operator_alloc(v6);
if ( v22 )
{
v9 = qdpack_hilbert_space_copy(a1);
*(_DWORD *)(*(_QWORD *)(v9 + 8) + 4 * v7) = 1;
v17 = qdpack_hilbert_space_nstates(v9);
if ( v8 > 0 )
{
v21 = (unsigned int)v8;
for ( i = 0LL; i != v21; ++i )
{
for ( j = 0LL; j != v21; ++j )
{
v16 = 0.0;
if ( v17 > 0 )
{
for ( k = 0; k != v17; ++k )
{
qdpack_hilbert_space_state_vector(v9, k, v23);
qdpack_hilbert_space_state_vector(v9, k, v24);
v24[a3] = i;
v23[a3] = j;
v11 = qdpack_hilbert_space_state_number(a1, v24);
v12 = qdpack_hilbert_space_state_number(a1, v23);
v13 = qdpack_operator_get(a2, v11, v12);
v14 = a5;
a5 = 0.0;
v16 = gsl_complex_add(v16, 0.0, v13, v14);
}
}
a5 = 0.0;
qdpack_operator_set(v22, i, j, v16, 0.0);
}
}
}
}
else
{
fwrite("qdpack_operator_traceout: Failed to allocate dm_part (Out of memory?).\n", 1uLL, 0x47uLL, stderr);
}
return v22;
}

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

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

variable_types: n int

variable_types: ii int

variable_types: jj int

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


decompiled_code:
__int64 __fastcall qdpack_operator_traceout_multi(__int64 a1, __int64 a2, int *a3, double a4, double a5)
{
__int64 v7; // r15
__int64 v8; // rbx
int v9; // ebp
int v10; // ebx
__int64 v12; // rax
int v13; // edx
int v14; // ebp
int v15; // eax
double v16; // xmm2_8
double v17; // xmm3_8
unsigned int i; // er13
int v19; // esi
__int64 v20; // rdi
double v21; // [rsp+8h] [rbp-1C0h]
__int64 v23; // [rsp+20h] [rbp-1A8h]
__int64 v24; // [rsp+28h] [rbp-1A0h]
__int64 v25; // [rsp+30h] [rbp-198h]
__int64 v26; // [rsp+38h] [rbp-190h]
__int64 v27; // [rsp+40h] [rbp-188h]
int v28[20]; // [rsp+50h] [rbp-178h] BYREF
int v29[20]; // [rsp+A0h] [rbp-128h] BYREF
int v30[20]; // [rsp+F0h] [rbp-D8h] BYREF
int v31[34]; // [rsp+140h] [rbp-88h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, int *a3, double a4, double a5)
{
__int64 v7; // r15
__int64 v8; // rbx
int v9; // ebp
int v10; // ebx
__int64 v12; // rax
int v13; // edx
int v14; // ebp
int v15; // eax
double v16; // xmm2_8
double v17; // xmm3_8
unsigned int i; // er13
int v19; // esi
__int64 v20; // rdi
double v21; // [rsp+8h] [rbp-1C0h]
__int64 v23; // [rsp+20h] [rbp-1A8h]
__int64 v24; // [rsp+28h] [rbp-1A0h]
__int64 v25; // [rsp+30h] [rbp-198h]
__int64 v26; // [rsp+38h] [rbp-190h]
__int64 v27; // [rsp+40h] [rbp-188h]
int v28[20]; // [rsp+50h] [rbp-178h] BYREF
int v29[20]; // [rsp+A0h] [rbp-128h] BYREF
int v30[20]; // [rsp+F0h] [rbp-D8h] BYREF
int v31[34]; // [rsp+140h] [rbp-88h] BYREF

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

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


decompiled_code:
__int64 __fastcall qdpack_wf_tensor(__int64 a1, int *a2, __int64 a3, double a4, double a5)
{
int v6; // eax
__int64 v7; // r15
double v8; // rbp
__int64 v9; // r12
double v10; // xmm2_8
double v11; // xmm3_8
__int64 result; // rax
__int64 v13; // [rsp+0h] [rbp-98h]
int v14[34]; // [rsp+10h] [rbp-88h] BYREF

v6 = qdpack_hilbert_space_nstates(a2);
if ( a2 && a3 && *a2 == *(_DWORD *)(a3 + 160) )
{
v13 = (unsigned int)v6;
v7 = 0LL;
if ( v6 <= 0 )
{
result = 0LL;
}
else
{
do
{
qdpack_hilbert_space_state_vector(a2, (unsigned int)v7, v14);
v8 = *(double *)&LC1;
if ( *a2 > 0 )
{
v9 = 0LL;
do
{
v10 = qdpack_state_get(*(_QWORD *)(a3 + 8 * v9), v14[v9]);
v11 = a5;
a5 = *(double *)&LC2;
v8 = gsl_complex_mul(v8, 0.0, v10, v11);
++v9;
}
while ( *a2 > (int)v9 );
}
a5 = *(double *)&LC2;
qdpack_state_set(a1, v7++, v8, 0.0);
}
while ( v7 != v13 );
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 v6; // eax
__int64 v7; // r15
double v8; // rbp
__int64 v9; // r12
double v10; // xmm2_8
double v11; // xmm3_8
__int64 result; // rax
__int64 v13; // [rsp+0h] [rbp-98h]
int v14[34]; // [rsp+10h] [rbp-88h] BYREF

v6 = qdpack_hilbert_space_nstates(a2);
if ( a2 && a3 && *a2 == *(_DWORD *)(a3 + 160) )
{
v13 = (unsigned int)v6;
v7 = 0LL;
if ( v6 <= 0 )
{
result = 0LL;
}
else
{
do
{
qdpack_hilbert_space_state_vector(a2, (unsigned int)v7, v14);
v8 = *(double *)&LC1;
if ( *a2 > 0 )
{
v9 = 0LL;
do
{
v10 = qdpack_state_get(*(_QWORD *)(a3 + 8 * v9), v14[v9]);
v11 = a5;
a5 = *(double *)&LC2;
v8 = gsl_complex_mul(v8, 0.0, v10, v11);
++v9;
}
while ( *a2 > (int)v9 );
}
a5 = *(double *)&LC2;
qdpack_state_set(a1, v7++, v8, 0.0);
}
while ( v7 != v13 );
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: struct qdpack_state_list_t { struct _qdpack_state *wf[20]; int len; } *


decompiled_code:
void __fastcall qdpack_wf_list_init(_QWORD *a1)
{
_QWORD *v1; // rax

if ( a1 )
{
v1 = a1;
do
*v1++ = 0LL;
while ( v1 != a1 + 20 );
*((_DWORD *)a1 + 40) = 0;
}
}

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

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

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

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

LODWORD(result) = *(_DWORD *)(a1 + 160);
if ( (int)result > 19 )
return fwrite("qdpack_wf_list_append: Reached max size.\n", 1uLL, 0x29uLL, stderr);
*(_DWORD *)(a1 + 160) = result + 1;
result = (int)result;
*(_QWORD *)(a1 + 8LL * (int)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 *


decompiled_code:
__int64 __fastcall qdpack_wf_list_free_entries(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 160) > 0 )
{
v1 = 0LL;
do
result = qdpack_state_free(*(_QWORD *)(a1 + 8 * v1++));
while ( *(_DWORD *)(a1 + 160) > (int)v1 );
}
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; // rbx
double v7; // xmm0_8
__int64 v8; // rbp

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; // rbx
double v7; // xmm0_8
__int64 v8; // rbp

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:
qs
struct qdpack_hilbert_space_t *

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

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:
__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; // rbx

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; // rbx

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

return_type: 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 *


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

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

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

printf("Quantum system with %d sub systems: ", *a1);
if ( (int)*a1 > 0 )
{
v1 = 0LL;
do
printf("%d ", *(unsigned int *)(*((_QWORD *)a1 + 1) + 4 * v1++));
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");
}

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


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; // rax
__int64 v2; // rcx
unsigned int v3; // edx

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

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

variable_types: ns int


decompiled_code:
__int64 __fastcall qdpack_hilbert_space_state_vector(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax
int v7; // edx
int v8; // ecx
int v9; // edi
__int64 v10; // rcx

result = qdpack_hilbert_space_nstates(a1);
v7 = *(_DWORD *)a1;
v8 = *(_DWORD *)a1 - 1;
if ( v8 >= 0 )
{
v9 = result;
v10 = 4LL * v8;
do
{
v9 /= *(int *)(*(_QWORD *)(a1 + 8) + v10);
result = (unsigned int)(a2 / v9);
*(_DWORD *)(a3 + v10) = result;
a2 %= v9;
v10 -= 4LL;
}
while ( v10 != 4 * (v7 - (unsigned __int64)(unsigned int)(v7 - 1)) - 8 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax
int v7; // edx
int v8; // ecx
int v9; // edi
__int64 v10; // rcx

result = func7(a1);
v7 = *(_DWORD *)a1;
v8 = *(_DWORD *)a1 - 1;
if ( v8 >= 0 )
{
v9 = result;
v10 = 4LL * v8;
do
{
v9 /= *(int *)(*(_QWORD *)(a1 + 8) + v10);
result = (unsigned int)(a2 / v9);
*(_DWORD *)(a3 + v10) = result;
a2 %= v9;
v10 -= 4LL;
}
while ( v10 != 4 * (v7 - (unsigned __int64)(unsigned int)(v7 - 1)) - 8 );
}
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: i int

variable_types: acc int


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

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

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

if ( *a1 <= 0 )
return 0LL;
v2 = 0LL;
do
printf("%d ", *(unsigned int *)(a2 + 4 * v2++));
while ( *a1 > (int)v2 );
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(__int64 a1, __int64 a2)
{
int v3; // edi
__int64 v4; // r9
__int64 v5; // rax
int v6; // edx
unsigned int v7; // ecx

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

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

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

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v3; // rdi

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

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

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

canonical_decompiled_code:
void __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v3; // 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);
*(_QWORD *)(a1 + 8) = qdpack_hilbert_space_copy(*(_QWORD *)(a2 + 8));
qdpack_matrix_memcpy(*(_QWORD *)(a1 + 16), *(_QWORD *)(a2 + 16));
}
}

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
__int64 v6; // rcx
int result; // eax

if ( a3 && (v5 = *(_QWORD *)(a3 + 16), a4) && v5 && (v6 = *(_QWORD *)(a4 + 16), a5) && v6 && *(_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
__int64 v6; // rcx
int result; // eax

if ( a3 && (v5 = *(_QWORD *)(a3 + 16), a4) && v5 && (v6 = *(_QWORD *)(a4 + 16), a5) && v6 && *(_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 *