decompiled_code:
void __fastcall run_bitwise_operation(char *s1, signed __int64 a2, unsigned __int64 a3, int a4)
{
unsigned int v7; // er15
const char *v8; // r14
__int64 v9; // r13
unsigned __int64 v10; // rdi
bool v11; // [rsp+Fh] [rbp-39h]

if ( !strcasecmp(s1, "and") || !strcasecmp(s1, "&") )
{
v11 = 1;
v7 = 0;
v8 = "AND &";
v9 = a2 & a3;
}
else if ( !strcasecmp(s1, "or") || !strcasecmp(s1, "|") )
{
v11 = 1;
v7 = 0;
v8 = "OR |";
v9 = a2 | a3;
}
else if ( !strcasecmp(s1, "xor") || !strcasecmp(s1, "^") )
{
v11 = 1;
v7 = 0;
v8 = "XOR ^";
v9 = a2 ^ a3;
}
else if ( !strcasecmp(s1, "twiddle") || !strcasecmp(s1, "~") )
{
v11 = 1;
v7 = 0;
v8 = "TWIDDLE ~";
v9 = ~a2;
}
else if ( !strcasecmp(s1, "rshift") || !strcasecmp(s1, ">>") )
{
v7 = a3;
v8 = "RSHIFT >>";
v9 = a2 >> a3;
v11 = (_DWORD)a3 == 0;
}
else
{
if ( strcasecmp(s1, "lshift") && strcasecmp(s1, "<<") )
{
v10 = a2;
if ( a4 > 1 )
{
printf("Unhandled bitwise operator word argument: %s\n", s1);
exit(1);
}
goto LABEL_11;
}
v7 = a3;
v8 = "LSHIFT <<";
v9 = a2 << a3;
v11 = (_DWORD)a3 == 0;
}
dec_to_bin(a2);
if ( a4 == 3 && v11 )
{
dec_to_bin(a3);
goto LABEL_9;
}
if ( a4 > 1 )
{
if ( v7 )
{
printf("%48s (%d)\n", v8, v7);
goto LABEL_10;
}
LABEL_9:
printf("%48s\n", v8);
LABEL_10:
v10 = v9;
LABEL_11:
dec_to_bin(v10);
}
}

canonical_decompiled_code:
void __fastcall func9(char *s1, signed __int64 a2, unsigned __int64 a3, int a4)
{
unsigned int v7; // er15
const char *v8; // r14
__int64 v9; // r13
unsigned __int64 v10; // rdi
bool v11; // [rsp+Fh] [rbp-39h]

if ( !strcasecmp(s1, "and") || !strcasecmp(s1, "&") )
{
v11 = 1;
v7 = 0;
v8 = "AND &";
v9 = a2 & a3;
}
else if ( !strcasecmp(s1, "or") || !strcasecmp(s1, "|") )
{
v11 = 1;
v7 = 0;
v8 = "OR |";
v9 = a2 | a3;
}
else if ( !strcasecmp(s1, "xor") || !strcasecmp(s1, "^") )
{
v11 = 1;
v7 = 0;
v8 = "XOR ^";
v9 = a2 ^ a3;
}
else if ( !strcasecmp(s1, "twiddle") || !strcasecmp(s1, "~") )
{
v11 = 1;
v7 = 0;
v8 = "TWIDDLE ~";
v9 = ~a2;
}
else if ( !strcasecmp(s1, "rshift") || !strcasecmp(s1, ">>") )
{
v7 = a3;
v8 = "RSHIFT >>";
v9 = a2 >> a3;
v11 = (_DWORD)a3 == 0;
}
else
{
if ( strcasecmp(s1, "lshift") && strcasecmp(s1, "<<") )
{
v10 = a2;
if ( a4 > 1 )
{
printf("Unhandled bitwise operator word argument: %s\n", s1);
exit(1);
}
goto LABEL_11;
}
v7 = a3;
v8 = "LSHIFT <<";
v9 = a2 << a3;
v11 = (_DWORD)a3 == 0;
}
func8(a2);
if ( a4 == 3 && v11 )
{
func8(a3);
goto LABEL_9;
}
if ( a4 > 1 )
{
if ( v7 )
{
printf("%48s (%d)\n", v8, v7);
goto LABEL_10;
}
LABEL_9:
printf("%48s\n", v8);
LABEL_10:
v10 = v9;
LABEL_11:
func8(v10);
}
}

original_code:
void run_bitwise_operation(char *word, long num1,
                         long num2, int num_of_args){
    long result = 0;
    char *opname;
    int shift = 0;
    if (strcasecmp(word, "and") == 0 || strcasecmp(word, "&") == 0){
        result = num1 & num2;
        opname = "AND &";
    }
    else if (strcasecmp(word, "or") == 0 || strcasecmp(word, "|") == 0){
        result = num1 | num2;
        opname = "OR |";
    }
    else if (strcasecmp(word, "xor") == 0 || strcasecmp(word, "^") == 0){
        result = num1 ^ num2;
        opname = "XOR ^";
    }
    else if (strcasecmp(word, "twiddle") == 0 || strcasecmp(word, "~") == 0){
        result = ~num1;
        opname = "TWIDDLE ~";
    }
    else if (strcasecmp(word, "rshift") == 0 || strcasecmp(word, ">>") == 0){
        result = num1 >> num2;
        opname = "RSHIFT >>";
        shift = num2;
    }
    else if (strcasecmp(word, "lshift") == 0 || strcasecmp(word, "<<") == 0){
        result = num1 << num2;
        opname = "LSHIFT <<";
        shift = num2;
    }
    else{
        if(num_of_args > 1){
            printf("Unhandled bitwise operator word argument: %s\n", word);
            exit(1);
        }
    }
    dec_to_bin(num1);
    if (num_of_args == 3 && !shift)
        dec_to_bin(num2);
    if (num_of_args > 1){
        if(shift)
            printf("%48s (%d)\n", opname, shift);
        else
            printf("%48s\n", opname);
        dec_to_bin(result);
    }
}

variable_types:
word
char *

variable_types: result long

variable_types:
opname
char *

variable_types: shift int


repo: jrjohansson/qdpack

decompiled_code:
void __fastcall qdpack_matrix_free(void *ptr)
{
if ( ptr )
{
gsl_matrix_complex_free(*((_QWORD *)ptr + 1));
free(ptr);
}
else
{
fprintf(stderr, "%s: ERROR: mat is NULL\n", "qdpack_matrix_free");
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
gsl_matrix_complex_free(*((_QWORD *)ptr + 1));
free(ptr);
}
else
{
fprintf(stderr, "%s: ERROR: mat is NULL\n", "qdpack_matrix_free");
}
}

original_code:
void
qdpack_matrix_free(qdpack_matrix_t *mat)
{
    if (mat == ((void *)0))
    {
        fprintf(stderr, "%s: ERROR: mat is NULL\n", __PRETTY_FUNCTION__);
        return;
    }
    gsl_matrix_complex_free(mat->data);
    free(mat);
}

canonical_original_code:
void qdpack_matrix_free(struct _qdpack_matrix *mat)
{
    if (mat == ((void *)0))
    {
        fprintf(stderr, "%s: ERROR: mat is NULL\n", __PRETTY_FUNCTION__);
        return;
    }
    gsl_matrix_complex_free(mat->data);
    free(mat);
}

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

return_type: void

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_matrix_get(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = gsl_matrix_complex_get(*(_QWORD *)(a1 + 8));
else
result = gsl_complex_rect(0.0);
return result;
}

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

if ( a1 )
result = gsl_matrix_complex_get(*(_QWORD *)(a1 + 8));
else
result = gsl_complex_rect(0.0);
return result;
}

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

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

variable_types:
i
unsigned long

variable_types:
j
unsigned long

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

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


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

if ( a1 )
result = gsl_matrix_complex_set(*(_QWORD *)(a1 + 8));
return result;
}

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

if ( a1 )
result = gsl_matrix_complex_set(*(_QWORD *)(a1 + 8));
return result;
}

original_code:
void
qdpack_matrix_set(qdpack_matrix_t *mat, size_t i, size_t j, gsl_complex value)
{
    if (mat == ((void *)0))
        return;
    return gsl_matrix_complex_set(mat->data, i, j, value);
}

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

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


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

if ( a1 )
result = gsl_matrix_complex_set_all(*(_QWORD *)(a1 + 8));
return result;
}

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

if ( a1 )
result = gsl_matrix_complex_set_all(*(_QWORD *)(a1 + 8));
return result;
}

original_code:
void
qdpack_matrix_set_all(qdpack_matrix_t *mat, gsl_complex value)
{
    if (mat == ((void *)0))
        return;
    return gsl_matrix_complex_set_all(mat->data, value);
}

canonical_original_code:
void qdpack_matrix_set_all(struct _qdpack_matrix *mat, struct gsl_complex value)
{
    if (mat == ((void *)0))
        return;
    return gsl_matrix_complex_set_all(mat->data, value);
}


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

if ( a1 )
result = gsl_matrix_complex_set_zero(*(_QWORD *)(a1 + 8));
return result;
}

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

if ( a1 )
result = gsl_matrix_complex_set_zero(*(_QWORD *)(a1 + 8));
return result;
}

original_code:
void
qdpack_matrix_set_zero(qdpack_matrix_t *mat)
{
    if (mat == ((void *)0))
        return;
    return gsl_matrix_complex_set_zero(mat->data);
}

canonical_original_code:
void qdpack_matrix_set_zero(struct _qdpack_matrix *mat)
{
    if (mat == ((void *)0))
        return;
    return gsl_matrix_complex_set_zero(mat->data);
}


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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 8) )
result = gsl_matrix_complex_set_identity();
}
return result;
}

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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 8) )
result = gsl_matrix_complex_set_identity();
}
return result;
}

original_code:
void
qdpack_matrix_set_identity(qdpack_matrix_t *mat)
{
    if (mat && mat->data)
    {
        gsl_matrix_complex_set_identity(mat->data);
    }
}

canonical_original_code:
void qdpack_matrix_set_identity(struct _qdpack_matrix *mat)
{
    if (mat && mat->data)
    {
        gsl_matrix_complex_set_identity(mat->data);
    }
}


decompiled_code:
__int64 __fastcall qdpack_matrix_memcpy(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rsi
__int64 result; // rax

if ( a2 )
{
if ( a1 )
{
*(_DWORD *)a1 = *(_DWORD *)a2;
v2 = *(_DWORD *)(a2 + 4);
v3 = *(_QWORD *)(a2 + 8);
*(_DWORD *)(a1 + 4) = v2;
result = gsl_matrix_complex_memcpy(*(_QWORD *)(a1 + 8), v3);
}
}
return result;
}

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

if ( a2 )
{
if ( a1 )
{
*(_DWORD *)a1 = *(_DWORD *)a2;
v2 = *(_DWORD *)(a2 + 4);
v3 = *(_QWORD *)(a2 + 8);
*(_DWORD *)(a1 + 4) = v2;
result = gsl_matrix_complex_memcpy(*(_QWORD *)(a1 + 8), v3);
}
}
return result;
}

original_code:
void
qdpack_matrix_memcpy(qdpack_matrix_t *dst, qdpack_matrix_t *src)
{
    if (src == ((void *)0) || dst == ((void *)0))
        return;
    dst->n = src->n;
    dst->m = src->m;
    gsl_matrix_complex_memcpy(dst->data, src->data);
}

canonical_original_code:
void qdpack_matrix_memcpy(struct _qdpack_matrix *dst, struct _qdpack_matrix *src)
{
    if (src == ((void *)0) || dst == ((void *)0))
        return;
    dst->n = src->n;
    dst->m = src->m;
    gsl_matrix_complex_memcpy(dst->data, src->data);
}

variable_types:
src
struct _qdpack_matrix *


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

if ( a1 )
result = gsl_matrix_complex_scale(*(_QWORD *)(a1 + 8));
return result;
}

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

if ( a1 )
result = gsl_matrix_complex_scale(*(_QWORD *)(a1 + 8));
return result;
}

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

original_code:
void
qdpack_matrix_blas_zgemm(CBLAS_TRANSPOSE_t transA,
                         CBLAS_TRANSPOSE_t transB,
                         gsl_complex alpha,
                         qdpack_matrix_t *A,
                         qdpack_matrix_t *B,
                         gsl_complex beta,
                         qdpack_matrix_t *C)
{
    if (A && A->data && B && B->data && C && C->data)
    {
        gsl_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_matrix_blas_zgemm(enum CBLAS_TRANSPOSE transA, enum CBLAS_TRANSPOSE transB, struct gsl_complex alpha, struct _qdpack_matrix *A, struct _qdpack_matrix *B, struct gsl_complex beta, struct _qdpack_matrix *C)
{
    if (A && A->data && B && B->data && C && C->data)
    {
        gsl_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_matrix *

variable_types:
beta
struct gsl_complex

variable_types:
C
struct _qdpack_matrix *


decompiled_code:
int __fastcall qdpack_matrix_multiply(__int64 a1, __int64 a2, __int64 a3)
{
if ( !a1 || !*(_QWORD *)(a1 + 8) || !a2 || !*(_QWORD *)(a2 + 8) || !a3 || !*(_QWORD *)(a3 + 8) )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_matrix_multiply");
gsl_complex_rect(0.0);
gsl_complex_rect(1.0);
return qdpack_matrix_blas_zgemm(111LL, 111LL, a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1, __int64 a2, __int64 a3)
{
if ( !a1 || !*(_QWORD *)(a1 + 8) || !a2 || !*(_QWORD *)(a2 + 8) || !a3 || !*(_QWORD *)(a3 + 8) )
return fprintf(stderr, "%s: ERROR: NULL valued operator\n", "qdpack_matrix_multiply");
gsl_complex_rect(0.0);
gsl_complex_rect(1.0);
return func10(111LL, 111LL, a1, a2, a3);
}

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

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


decompiled_code:
double __fastcall qdpack_matrix_multiply_vmv(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbp
_DWORD *v3; // rax
__int64 v4; // r15
_QWORD *v5; // r12
double v6; // xmm0_8
__int64 v7; // r14
__int64 v8; // r13
double v9; // xmm0_8
__int64 v10; // r15
double v11; // xmm0_8
__int64 v12; // r14
__int64 v13; // r13
double result; // xmm0_8
double v15; // [rsp+8h] [rbp-40h]
double v16; // [rsp+8h] [rbp-40h]

v2 = qdpack_matrix_alloc(*(int *)(a1 + 4), 1LL);
v3 = qdpack_matrix_alloc(1LL, 1LL);
v4 = v2[1];
v5 = v3;
v6 = gsl_complex_rect(0.0);
v7 = *(_QWORD *)(a2 + 8);
v8 = *(_QWORD *)(a1 + 8);
v15 = v6;
v9 = gsl_complex_rect(1.0);
gsl_blas_zgemm(111LL, 111LL, v8, v7, v4, v9, 0.0, v15, 0.0);
v10 = v5[1];
v11 = gsl_complex_rect(0.0);
v12 = v2[1];
v13 = *(_QWORD *)(a2 + 8);
v16 = v11;
result = gsl_complex_rect(1.0);
gsl_blas_zgemm(112LL, 111LL, v13, v12, v10, result, 0.0, v16, 0.0);
qdpack_matrix_get((__int64)v5);
qdpack_matrix_free(v5);
qdpack_matrix_free(v2);
return result;
}

original_code:
gsl_complex
qdpack_matrix_multiply_vmv(qdpack_matrix_t *mat, qdpack_matrix_t *v)
{
    qdpack_matrix_t *prod, *expt;
    gsl_complex res;
    prod = qdpack_matrix_alloc(mat->m, 1);
    expt = qdpack_matrix_alloc(1, 1);
    gsl_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), mat->data, v->data, (gsl_complex_rect(0.0,0.0)), prod->data);
    gsl_blas_zgemm(CblasTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), v->data, prod->data, (gsl_complex_rect(0.0,0.0)), expt->data);
    res = qdpack_matrix_get(expt, 0, 0);
    qdpack_matrix_free(expt);
    qdpack_matrix_free(prod);
    return res;
}

canonical_original_code:
struct gsl_complex qdpack_matrix_multiply_vmv(struct _qdpack_matrix *mat, struct _qdpack_matrix *v)
{
    struct _qdpack_matrix *prod; struct _qdpack_matrix *expt;
    struct gsl_complex res;
    prod = qdpack_matrix_alloc(mat->m, 1);
    expt = qdpack_matrix_alloc(1, 1);
    gsl_blas_zgemm(CblasNoTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), mat->data, v->data, (gsl_complex_rect(0.0,0.0)), prod->data);
    gsl_blas_zgemm(CblasTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), v->data, prod->data, (gsl_complex_rect(0.0,0.0)), expt->data);
    res = qdpack_matrix_get(expt, 0, 0);
    qdpack_matrix_free(expt);
    qdpack_matrix_free(prod);
    return res;
}

variable_types:
v
struct _qdpack_matrix *

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


decompiled_code:
__int64 __fastcall qdpack_matrix_exp(__int64 a1, __int64 a2)
{
return gsl_linalg_complex_exponential_ss(*(_QWORD *)(a1 + 8), *(_QWORD *)(a2 + 8), 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
return gsl_linalg_complex_exponential_ss(*(_QWORD *)(a1 + 8), *(_QWORD *)(a2 + 8), 0LL);
}

original_code:
void
qdpack_matrix_exp(qdpack_matrix_t *m, qdpack_matrix_t *exp_m)
{
    gsl_linalg_complex_exponential_ss(m->data, exp_m->data, 0);
}

canonical_original_code:
void qdpack_matrix_exp(struct _qdpack_matrix *m, struct _qdpack_matrix *exp_m)
{
    gsl_linalg_complex_exponential_ss(m->data, exp_m->data, 0);
}


decompiled_code:
double __fastcall qdpack_matrix_dot(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbp
__int64 v3; // r14
double v4; // xmm0_8
__int64 v5; // r13
__int64 v6; // r12
double result; // xmm0_8
double v8; // [rsp+8h] [rbp-30h]

v2 = qdpack_matrix_alloc(1LL, 1LL);
v3 = v2[1];
v4 = gsl_complex_rect(0.0);
v5 = *(_QWORD *)(a2 + 8);
v6 = *(_QWORD *)(a1 + 8);
v8 = v4;
result = gsl_complex_rect(1.0);
gsl_blas_zgemm(112LL, 111LL, v6, v5, v3, result, 0.0, v8, 0.0);
qdpack_matrix_get((__int64)v2);
qdpack_matrix_free(v2);
return result;
}

canonical_decompiled_code:
double __fastcall func14(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbp
__int64 v3; // r14
double v4; // xmm0_8
__int64 v5; // r13
__int64 v6; // r12
double result; // xmm0_8
double v8; // [rsp+8h] [rbp-30h]

v2 = qdpack_matrix_alloc(1LL, 1LL);
v3 = v2[1];
v4 = gsl_complex_rect(0.0);
v5 = *(_QWORD *)(a2 + 8);
v6 = *(_QWORD *)(a1 + 8);
v8 = v4;
result = gsl_complex_rect(1.0);
gsl_blas_zgemm(112LL, 111LL, v6, v5, v3, result, 0.0, v8, 0.0);
func1((__int64)v2);
func0(v2);
return result;
}

original_code:
gsl_complex
qdpack_matrix_dot(qdpack_matrix_t *a, qdpack_matrix_t *b)
{
    qdpack_matrix_t *prod;
    gsl_complex z;
    prod = qdpack_matrix_alloc(1, 1);
    gsl_blas_zgemm(CblasTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), a->data, b->data, (gsl_complex_rect(0.0,0.0)), prod->data);
    z = qdpack_matrix_get(prod, 0, 0);
    qdpack_matrix_free(prod);
    return z;
}

canonical_original_code:
struct gsl_complex qdpack_matrix_dot(struct _qdpack_matrix *a, struct _qdpack_matrix *b)
{
    struct _qdpack_matrix *prod;
    struct gsl_complex z;
    prod = qdpack_matrix_alloc(1, 1);
    gsl_blas_zgemm(CblasTrans, CblasNoTrans, (gsl_complex_rect(1.0,0.0)), a->data, b->data, (gsl_complex_rect(0.0,0.0)), prod->data);
    z = qdpack_matrix_get(prod, 0, 0);
    qdpack_matrix_free(prod);
    return z;
}

variable_types:
b
struct _qdpack_matrix *


decompiled_code:
__int64 __fastcall qdpack_matrix_eigen_hermv(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v6; // r12
__int64 v7; // rbx

if ( !hermv_workspace )
hermv_workspace = gsl_eigen_hermv_alloc(*(int *)(a1 + 4));
v6 = gsl_vector_alloc(*(int *)(a2 + 4));
gsl_eigen_hermv(*(_QWORD *)(a1 + 8), v6, *(_QWORD *)(a3 + 8), hermv_workspace);
gsl_eigen_hermv_sort(v6, *(_QWORD *)(a3 + 8), a4);
if ( *(int *)(a2 + 4) > 0 )
{
v7 = 0LL;
do
{
gsl_vector_get(v6, v7++);
qdpack_matrix_set(a2);
}
while ( *(_DWORD *)(a2 + 4) > (int)v7 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v6; // r12
__int64 v7; // rbx

if ( !hermv_workspace )
hermv_workspace = gsl_eigen_hermv_alloc(*(int *)(a1 + 4));
v6 = gsl_vector_alloc(*(int *)(a2 + 4));
gsl_eigen_hermv(*(_QWORD *)(a1 + 8), v6, *(_QWORD *)(a3 + 8), hermv_workspace);
gsl_eigen_hermv_sort(v6, *(_QWORD *)(a3 + 8), a4);
if ( *(int *)(a2 + 4) > 0 )
{
v7 = 0LL;
do
{
gsl_vector_get(v6, v7++);
func2(a2);
}
while ( *(_DWORD *)(a2 + 4) > (int)v7 );
}
return 0LL;
}

original_code:
int
qdpack_matrix_eigen_hermv(qdpack_matrix_t *m,
                          qdpack_matrix_t *eval,
                          qdpack_matrix_t *evec,
                          int sort_order)
{
    int i;
    gsl_vector *eval_vector;
    if (hermv_workspace == ((void *)0))
    {
        hermv_workspace = gsl_eigen_hermv_alloc(m->m);
    }
    eval_vector = gsl_vector_alloc(eval->m);
    gsl_eigen_hermv(m->data, eval_vector, evec->data, hermv_workspace);
    gsl_eigen_hermv_sort(eval_vector, evec->data, sort_order);
    for (i = 0; i < eval->m; i++)
    {
        gsl_complex z;
        do {(&z)->dat[0]=(gsl_vector_get(eval_vector, i)); (&z)->dat[1]=(0.0);} while(0);
        qdpack_matrix_set(eval, i, 0, z);
    }
    return 0;
}

canonical_original_code:
int qdpack_matrix_eigen_hermv(struct _qdpack_matrix *m, struct _qdpack_matrix *eval, struct _qdpack_matrix *evec, int sort_order)
{
    int i;
    struct gsl_vector *eval_vector;
    if (hermv_workspace == ((void *)0))
    {
        hermv_workspace = gsl_eigen_hermv_alloc(m->m);
    }
    eval_vector = gsl_vector_alloc(eval->m);
    gsl_eigen_hermv(m->data, eval_vector, evec->data, hermv_workspace);
    gsl_eigen_hermv_sort(eval_vector, evec->data, sort_order);
    for (i = 0; i < eval->m; i++)
    {
        struct gsl_complex z;
        do {(&z)->dat[0]=(gsl_vector_get(eval_vector, i)); (&z)->dat[1]=(0.0);} while(0);
        qdpack_matrix_set(eval, i, 0, z);
    }
    return 0;
}

variable_types:
eval
struct _qdpack_matrix *

variable_types:
evec
struct _qdpack_matrix *

variable_types: i int

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

return_type: int

user_defined_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; }


decompiled_code:
__int64 __fastcall qdpack_matrix_eigen_zgeev(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v6; // r12
__int64 v7; // rbx

v6 = gsl_vector_complex_alloc(*(int *)(a2 + 4));
gsl_ext_eigen_zgeev(*(_QWORD *)(a1 + 8), *(_QWORD *)(a3 + 8), v6);
gsl_ext_eigen_sort(*(_QWORD *)(a3 + 8), v6, a4);
if ( *(int *)(a2 + 4) > 0 )
{
v7 = 0LL;
do
{
gsl_vector_complex_get(v6, v7);
qdpack_matrix_set(a2);
++v7;
}
while ( *(_DWORD *)(a2 + 4) > (int)v7 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v6; // r12
__int64 v7; // rbx

v6 = gsl_vector_complex_alloc(*(int *)(a2 + 4));
gsl_ext_eigen_zgeev(*(_QWORD *)(a1 + 8), *(_QWORD *)(a3 + 8), v6);
gsl_ext_eigen_sort(*(_QWORD *)(a3 + 8), v6, a4);
if ( *(int *)(a2 + 4) > 0 )
{
v7 = 0LL;
do
{
gsl_vector_complex_get(v6, v7);
func2(a2);
++v7;
}
while ( *(_DWORD *)(a2 + 4) > (int)v7 );
}
return 0LL;
}

original_code:
int
qdpack_matrix_eigen_zgeev(qdpack_matrix_t *m,
                          qdpack_matrix_t *eval,
                          qdpack_matrix_t *evec,
                          int sort_order)
{
    int i;
    gsl_vector_complex *eval_vector;
    eval_vector = gsl_vector_complex_alloc(eval->m);
    gsl_ext_eigen_zgeev(m->data, evec->data, eval_vector);
    gsl_ext_eigen_sort(evec->data, eval_vector, sort_order);
    for (i = 0; i < eval->m; i++)
    {
        qdpack_matrix_set(eval, i, 0, gsl_vector_complex_get(eval_vector, i));
    }
    return 0;
}

canonical_original_code:
int qdpack_matrix_eigen_zgeev(struct _qdpack_matrix *m, struct _qdpack_matrix *eval, struct _qdpack_matrix *evec, int sort_order)
{
    int i;
    struct gsl_vector_complex *eval_vector;
    eval_vector = gsl_vector_complex_alloc(eval->m);
    gsl_ext_eigen_zgeev(m->data, evec->data, eval_vector);
    gsl_ext_eigen_sort(evec->data, eval_vector, sort_order);
    for (i = 0; i < eval->m; i++)
    {
        qdpack_matrix_set(eval, i, 0, gsl_vector_complex_get(eval_vector, i));
    }
    return 0;
}

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

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

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


decompiled_code:
int __fastcall qdpack_operator_print(_DWORD *a1, double a2, double a3)
{
__int64 v3; // r12
__int64 i; // rbx
double v5; // xmm0_8
__int64 v6; // rdx
int result; // eax
double v8; // [rsp+0h] [rbp-20h]

if ( (int)a1[1] > 0 )
{
v3 = 0LL;
do
{
for ( i = 0LL; *a1 > (int)i; ++i )
{
v5 = qdpack_operator_get(a1, v3, i);
v6 = i;
v8 = v5;
qdpack_operator_get(a1, v3, v6);
printf(" (%2.5f,%2.5f)", v8, a3);
}
++v3;
result = putchar(10);
}
while ( a1[1] > (int)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(_DWORD *a1, double a2, double a3)
{
__int64 v3; // r12
__int64 i; // rbx
double v5; // xmm0_8
__int64 v6; // rdx
int result; // eax
double v8; // [rsp+0h] [rbp-20h]

if ( (int)a1[1] > 0 )
{
v3 = 0LL;
do
{
for ( i = 0LL; *a1 > (int)i; ++i )
{
v5 = qdpack_operator_get(a1, v3, i);
v6 = i;
v8 = v5;
qdpack_operator_get(a1, v3, v6);
printf(" (%2.5f,%2.5f)", v8, a3);
}
++v3;
result = putchar(10);
}
while ( a1[1] > (int)v3 );
}
return result;
}

original_code:
void
qdpack_operator_print(qdpack_operator_t *m)
{
    double val_re, val_im;
    int i, j;
    for (i = 0; i < m->m; i++)
    {
           for (j = 0; j < m->n; j++)
        {
            val_re = ((qdpack_operator_get(m, i, j)).dat[0]);
            val_im = ((qdpack_operator_get(m, i, j)).dat[1]);
            printf (" (%2.5f,%2.5f)", val_re, val_im);
        }
        printf("\n");
    }
}

canonical_original_code:
void qdpack_operator_print(struct _qdpack_operator_t *m)
{
    double val_re; double val_im;
    int i; int j;
    for (i = 0; i < m->m; i++)
    {
           for (j = 0; j < m->n; j++)
        {
            val_re = ((qdpack_operator_get(m, i, j)).dat[0]);
            val_im = ((qdpack_operator_get(m, i, j)).dat[1]);
            printf (" (%2.5f,%2.5f)", val_re, val_im);
        }
        printf("\n");
    }
}

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

variable_types: j int

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


decompiled_code:
int __fastcall qdpack_operator_print_real(_DWORD *a1)
{
__int64 v1; // r12
__int64 i; // rbx
double v3; // xmm0_8
int result; // eax

if ( (int)a1[1] > 0 )
{
v1 = 0LL;
do
{
for ( i = 0LL; *a1 > (int)i; ++i )
{
while ( 1 )
{
v3 = qdpack_operator_get(a1, v1, i);
if ( v3 < 0.0 )
break;
++i;
printf(" %2.5f ", v3);
if ( *a1 <= (int)i )
goto LABEL_8;
}
printf("%2.5f ", v3);
}
LABEL_8:
++v1;
result = putchar(10);
}
while ( a1[1] > (int)v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(_DWORD *a1)
{
__int64 v1; // r12
__int64 i; // rbx
double v3; // xmm0_8
int result; // eax

if ( (int)a1[1] > 0 )
{
v1 = 0LL;
do
{
for ( i = 0LL; *a1 > (int)i; ++i )
{
while ( 1 )
{
v3 = qdpack_operator_get(a1, v1, i);
if ( v3 < 0.0 )
break;
++i;
printf(" %2.5f ", v3);
if ( *a1 <= (int)i )
goto LABEL_8;
}
printf("%2.5f ", v3);
}
LABEL_8:
++v1;
result = putchar(10);
}
while ( a1[1] > (int)v1 );
}
return result;
}

original_code:
void
qdpack_operator_print_real(qdpack_operator_t *m)
{
    double val;
    int i, j;
    for (i = 0; i < m->m; i++)
    {
           for (j = 0; j < m->n; j++)
        {
            val = ((qdpack_operator_get(m, i, j)).dat[0]);
            if (val >= 0.0)
                printf (" %2.5f  ", val);
            else
                printf ("%2.5f  ", val);
        }
        printf("\n");
    }
}

canonical_original_code:
void qdpack_operator_print_real(struct _qdpack_operator_t *m)
{
    double val;
    int i; int j;
    for (i = 0; i < m->m; i++)
    {
           for (j = 0; j < m->n; j++)
        {
            val = ((qdpack_operator_get(m, i, j)).dat[0]);
            if (val >= 0.0)
                printf (" %2.5f  ", val);
            else
                printf ("%2.5f  ", val);
        }
        printf("\n");
    }
}

variable_types: val double

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


decompiled_code:
int __fastcall qdpack_operator_print_imag(_DWORD *a1, double a2, double a3)
{
__int64 v3; // r12
__int64 i; // rbx
__int64 v5; // rdx
int result; // eax

if ( (int)a1[1] > 0 )
{
v3 = 0LL;
do
{
for ( i = 0LL; *a1 > (int)i; ++i )
{
v5 = i;
qdpack_operator_get(a1, v3, v5);
printf("%2.5f ", a3);
}
++v3;
result = putchar(10);
}
while ( a1[1] > (int)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(_DWORD *a1, double a2, double a3)
{
__int64 v3; // r12
__int64 i; // rbx
__int64 v5; // rdx
int result; // eax

if ( (int)a1[1] > 0 )
{
v3 = 0LL;
do
{
for ( i = 0LL; *a1 > (int)i; ++i )
{
v5 = i;
qdpack_operator_get(a1, v3, v5);
printf("%2.5f ", a3);
}
++v3;
result = putchar(10);
}
while ( a1[1] > (int)v3 );
}
return result;
}

original_code:
void
qdpack_operator_print_imag(qdpack_operator_t *m)
{
    int i, j;
    for (i = 0; i < m->m; i++)
    {
           for (j = 0; j < m->n; j++)
            printf ("%2.5f  ", ((qdpack_operator_get(m, i, j)).dat[1]));
        printf("\n");
    }
}

canonical_original_code:
void qdpack_operator_print_imag(struct _qdpack_operator_t *m)
{
    int i; int j;
    for (i = 0; i < m->m; i++)
    {
           for (j = 0; j < m->n; j++)
            printf ("%2.5f  ", ((qdpack_operator_get(m, i, j)).dat[1]));
        printf("\n");
    }
}


decompiled_code:
int __fastcall qdpack_operator_print_abs2(_DWORD *a1, double a2, double a3)
{
__int64 v3; // r12
__int64 v4; // rbx
__int64 v5; // rdx
double v6; // xmm0_8
int result; // eax

if ( (int)a1[1] > 0 )
{
v3 = 0LL;
do
{
v4 = 0LL;
while ( *a1 > (int)v4 )
{
v5 = v4++;
v6 = qdpack_operator_get(a1, v3, v5);
a3 = a3 * a3;
printf("%2.5f ", v6 * v6 + a3);
}
++v3;
result = putchar(10);
}
while ( a1[1] > (int)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(_DWORD *a1, double a2, double a3)
{
__int64 v3; // r12
__int64 v4; // rbx
__int64 v5; // rdx
double v6; // xmm0_8
int result; // eax

if ( (int)a1[1] > 0 )
{
v3 = 0LL;
do
{
v4 = 0LL;
while ( *a1 > (int)v4 )
{
v5 = v4++;
v6 = qdpack_operator_get(a1, v3, v5);
a3 = a3 * a3;
printf("%2.5f ", v6 * v6 + a3);
}
++v3;
result = putchar(10);
}
while ( a1[1] > (int)v3 );
}
return result;
}

original_code:
void
qdpack_operator_print_abs2(qdpack_operator_t *m)
{
    gsl_complex z;
    int i, j;
    for (i = 0; i < m->m; i++)
    {
           for (j = 0; j < m->n; j++)
        {
            z = qdpack_operator_get(m, i, j);
            printf("%2.5f  ", ((z).dat[0])*((z).dat[0]) + ((z).dat[1])*((z).dat[1]));
        }
        printf("\n");
    }
}

canonical_original_code:
void qdpack_operator_print_abs2(struct _qdpack_operator_t *m)
{
    struct gsl_complex z;
    int i; int j;
    for (i = 0; i < m->m; i++)
    {
           for (j = 0; j < m->n; j++)
        {
            z = qdpack_operator_get(m, i, j);
            printf("%2.5f  ", ((z).dat[0])*((z).dat[0]) + ((z).dat[1])*((z).dat[1]));
        }
        printf("\n");
    }
}

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


decompiled_code:
int __fastcall qdpack_state_print_real(int *a1, double a2)
{
__int64 v2; // rbx
__int64 v3; // rsi

if ( *a1 > 0 )
{
v2 = 0LL;
do
{
v3 = v2++;
qdpack_state_get(a1, v3);
printf("%2.5f ", a2);
}
while ( *a1 > (int)v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func14(int *a1, double a2)
{
__int64 v2; // rbx
__int64 v3; // rsi

if ( *a1 > 0 )
{
v2 = 0LL;
do
{
v3 = v2++;
qdpack_state_get(a1, v3);
printf("%2.5f ", a2);
}
while ( *a1 > (int)v2 );
}
return putchar(10);
}

original_code:
void
qdpack_state_print_real(qdpack_state_t *v)
{
    int i;
    for (i = 0; i < v->n; i++)
    {
        printf("%2.5f ", ((qdpack_state_get(v, i)).dat[0]));
    }
    printf("\n");
}

canonical_original_code:
void qdpack_state_print_real(struct _qdpack_state *v)
{
    int i;
    for (i = 0; i < v->n; i++)
    {
        printf("%2.5f ", ((qdpack_state_get(v, i)).dat[0]));
    }
    printf("\n");
}

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

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


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

if ( *a1 > 0 )
{
v3 = 0LL;
do
{
v4 = v3++;
qdpack_state_get(a1, v4);
printf("%2.5f ", a3);
}
while ( *a1 > (int)v3 );
}
return putchar(10);
}

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

if ( *a1 > 0 )
{
v3 = 0LL;
do
{
v4 = v3++;
qdpack_state_get(a1, v4);
printf("%2.5f ", a3);
}
while ( *a1 > (int)v3 );
}
return putchar(10);
}

original_code:
void
qdpack_state_print_imag(qdpack_state_t *v)
{
    int i;
    for (i = 0; i < v->n; i++)
    {
        printf("%2.5f ", ((qdpack_state_get(v, i)).dat[1]));
    }
    printf("\n");
}

canonical_original_code:
void qdpack_state_print_imag(struct _qdpack_state *v)
{
    int i;
    for (i = 0; i < v->n; i++)
    {
        printf("%2.5f ", ((qdpack_state_get(v, i)).dat[1]));
    }
    printf("\n");
}


decompiled_code:
__int64 __fastcall qdpack_dm_pure_TLS(double a1)
{
__int64 v1; // rbp
double v2; // xmm1_8
__int64 v3; // r12
double v4; // xmm2_8
double v5; // xmm2_8
double x; // [rsp+0h] [rbp-28h]

v1 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v1, 2LL);
v2 = a1;
v3 = qdpack_operator_alloc(v1);
if ( v3 )
{
v4 = 1.0 - a1;
if ( 1.0 - a1 < 0.0 )
{
v2 = a1;
v5 = sqrt(v4);
}
else
{
v5 = sqrt(v4);
}
if ( v2 < 0.0 )
x = sqrt(v2);
else
x = sqrt(v2);
qdpack_operator_set(v3, 0LL, 0LL, v5 * v5, 0.0);
qdpack_operator_set(v3, 0LL, 1LL, v5 * x, 0.0);
qdpack_operator_set(v3, 1LL, 0LL, v5 * x, 0.0);
qdpack_operator_set(v3, 1LL, 1LL, x * x, 0.0);
qdpack_hilbert_space_free(v1);
}
else
{
fprintf(stderr, "%s: Failed to allocate dm (Out of memory?).\n", "qdpack_dm_pure_TLS");
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(double a1)
{
__int64 v1; // rbp
double v2; // xmm1_8
__int64 v3; // r12
double v4; // xmm2_8
double v5; // xmm2_8
double x; // [rsp+0h] [rbp-28h]

v1 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v1, 2LL);
v2 = a1;
v3 = qdpack_operator_alloc(v1);
if ( v3 )
{
v4 = 1.0 - a1;
if ( 1.0 - a1 < 0.0 )
{
v2 = a1;
v5 = sqrt(v4);
}
else
{
v5 = sqrt(v4);
}
if ( v2 < 0.0 )
x = sqrt(v2);
else
x = sqrt(v2);
qdpack_operator_set(v3, 0LL, 0LL, v5 * v5, 0.0);
qdpack_operator_set(v3, 0LL, 1LL, v5 * x, 0.0);
qdpack_operator_set(v3, 1LL, 0LL, v5 * x, 0.0);
qdpack_operator_set(v3, 1LL, 1LL, x * x, 0.0);
qdpack_hilbert_space_free(v1);
}
else
{
fprintf(stderr, "%s: Failed to allocate dm (Out of memory?).\n", "qdpack_dm_pure_TLS");
}
return v3;
}

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

canonical_original_code:
struct _qdpack_operator_t *qdpack_dm_pure_TLS(double p_ex)
{
    double aa; double bb;
    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, 2);
    if ((dm = qdpack_operator_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "%s: Failed to allocate dm (Out of memory?).\n", __PRETTY_FUNCTION__);
        return ((void *)0);
    }
    aa = sqrt(1-p_ex);
    bb = sqrt(p_ex);
    do {(&z)->dat[0]=(aa * aa); (&z)->dat[1]=(0.0);} while(0); qdpack_operator_set(dm, 0, 0, z);
    do {(&z)->dat[0]=(aa * bb); (&z)->dat[1]=(0.0);} while(0); qdpack_operator_set(dm, 0, 1, z);
    do {(&z)->dat[0]=(bb * aa); (&z)->dat[1]=(0.0);} while(0); qdpack_operator_set(dm, 1, 0, z);
    do {(&z)->dat[0]=(bb * bb); (&z)->dat[1]=(0.0);} while(0); qdpack_operator_set(dm, 1, 1, z);
    qdpack_hilbert_space_free(qs);
    return dm;
}

variable_types: aa double

variable_types: bb 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_wf_pure_TLS(double a1)
{
__int64 v1; // rbp
double v2; // xmm1_8
__int64 v3; // r12
double v4; // xmm0_8
double v5; // xmm3_8
double v6; // xmm2_8
double x; // [rsp+8h] [rbp-20h]

x = a1;
v1 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v1, 2LL);
v2 = a1;
v3 = qdpack_state_alloc(v1);
if ( v3 )
{
v4 = 1.0 - a1;
if ( 1.0 - v2 < 0.0 )
{
v2 = x;
v5 = sqrt(v4);
}
else
{
v5 = sqrt(v4);
}
if ( v2 < 0.0 )
v6 = sqrt(v2);
else
v6 = sqrt(v2);
qdpack_state_set(v3, 0LL, v5, 0.0);
qdpack_state_set(v3, 1LL, v6, 0.0);
qdpack_hilbert_space_free(v1);
}
else
{
fwrite("qdpack_wf_pure_TLS: Failed to allocate wf (Out of memory?).\n", 1uLL, 0x3CuLL, stderr);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(double a1)
{
__int64 v1; // rbp
double v2; // xmm1_8
__int64 v3; // r12
double v4; // xmm0_8
double v5; // xmm3_8
double v6; // xmm2_8
double x; // [rsp+8h] [rbp-20h]

x = a1;
v1 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v1, 2LL);
v2 = a1;
v3 = qdpack_state_alloc(v1);
if ( v3 )
{
v4 = 1.0 - a1;
if ( 1.0 - v2 < 0.0 )
{
v2 = x;
v5 = sqrt(v4);
}
else
{
v5 = sqrt(v4);
}
if ( v2 < 0.0 )
v6 = sqrt(v2);
else
v6 = sqrt(v2);
qdpack_state_set(v3, 0LL, v5, 0.0);
qdpack_state_set(v3, 1LL, v6, 0.0);
qdpack_hilbert_space_free(v1);
}
else
{
fwrite("qdpack_wf_pure_TLS: Failed to allocate wf (Out of memory?).\n", 1uLL, 0x3CuLL, stderr);
}
return v3;
}

original_code:
qdpack_state_t *
qdpack_wf_pure_TLS(double p_ex)
{
    double aa, bb;
    qdpack_state_t *wf;
    gsl_complex z;
    qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, 2);
    if ((wf = qdpack_state_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_wf_pure_TLS: Failed to allocate wf (Out of memory?).\n");
        return ((void *)0);
    }
    aa = sqrt(1-p_ex);
    bb = sqrt(p_ex);
    do {(&z)->dat[0]=(aa); (&z)->dat[1]=(0.0);} while(0); qdpack_state_set(wf, 0, z);
    do {(&z)->dat[0]=(bb); (&z)->dat[1]=(0.0);} while(0); qdpack_state_set(wf, 1, z);
    qdpack_hilbert_space_free(qs);
    return wf;
}

canonical_original_code:
struct _qdpack_state *qdpack_wf_pure_TLS(double p_ex)
{
    double aa; double bb;
    struct _qdpack_state *wf;
    struct gsl_complex z;
    struct qdpack_hilbert_space_t *qs;
    qs = qdpack_hilbert_space_new();
    qdpack_hilbert_space_add(qs, 2);
    if ((wf = qdpack_state_alloc(qs)) == ((void *)0))
    {
        fprintf(stderr, "qdpack_wf_pure_TLS: Failed to allocate wf (Out of memory?).\n");
        return ((void *)0);
    }
    aa = sqrt(1-p_ex);
    bb = sqrt(p_ex);
    do {(&z)->dat[0]=(aa); (&z)->dat[1]=(0.0);} while(0); qdpack_state_set(wf, 0, z);
    do {(&z)->dat[0]=(bb); (&z)->dat[1]=(0.0);} while(0); qdpack_state_set(wf, 1, z);
    qdpack_hilbert_space_free(qs);
    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 qdpack_dm_pure_3LS()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // r12

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

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


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

v3 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v3, (unsigned int)a1);
*(_QWORD *)&v12 = *(_QWORD *)&a2 ^ LC5;
v4 = exp(COERCE_DOUBLE(*(_QWORD *)&a2 ^ LC5) / (a3 + a3));
v13 = v4 / (1.0 - exp(v12 / a3));
v5 = qdpack_operator_alloc(v3);
v6 = v5;
if ( v5 )
{
qdpack_operator_set_zero(v5);
if ( a1 > 0 )
{
v7 = 0LL;
do
{
v8 = exp(((double)(int)v7 + 0.5) * v12 / a3);
v9 = v7;
v10 = v7++;
qdpack_operator_set(v6, v10, v9, v8 / v13, 0.0);
}
while ( v7 != a1 );
}
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; // rbp
double v4; // r12
__int64 v5; // rax
__int64 v6; // r12
__int64 v7; // r13
double v8; // xmm0_8
__int64 v9; // rdx
__int64 v10; // rsi
double v12; // [rsp+10h] [rbp-38h]
double v13; // [rsp+18h] [rbp-30h]

v3 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v3, (unsigned int)a1);
*(_QWORD *)&v12 = *(_QWORD *)&a2 ^ LC5;
v4 = exp(COERCE_DOUBLE(*(_QWORD *)&a2 ^ LC5) / (a3 + a3));
v13 = v4 / (1.0 - exp(v12 / a3));
v5 = qdpack_operator_alloc(v3);
v6 = v5;
if ( v5 )
{
qdpack_operator_set_zero(v5);
if ( a1 > 0 )
{
v7 = 0LL;
do
{
v8 = exp(((double)(int)v7 + 0.5) * v12 / a3);
v9 = v7;
v10 = v7++;
qdpack_operator_set(v6, v10, v9, v8 / v13, 0.0);
}
while ( v7 != a1 );
}
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: Z double

variable_types: p double

variable_types: n int


decompiled_code:
__int64 __fastcall qdpack_dm_coherent_state(int a1, int a2, double a3, double a4)
{
__int64 v6; // rsi
__int64 v7; // rdi
__int64 v8; // r15
__int64 v9; // r12
__int64 i; // rbx
__int64 v11; // rdx
double v14; // [rsp+28h] [rbp-A0h]
double v15; // [rsp+28h] [rbp-A0h]
double v16; // [rsp+28h] [rbp-A0h]
long double v17; // [rsp+30h] [rbp-98h]
double v18; // [rsp+40h] [rbp-88h]
__int64 v19; // [rsp+48h] [rbp-80h]
double x; // [rsp+70h] [rbp-58h]
__int64 v21; // [rsp+78h] [rbp-50h]
double cosx; // [rsp+80h] [rbp-48h] BYREF
double sinx[8]; // [rsp+88h] [rbp-40h] BYREF

v6 = (unsigned int)a1;
v21 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v21, (unsigned int)a1);
v7 = v21;
v8 = qdpack_operator_alloc(v21);
if ( v8 )
{
if ( a1 > 0 )
{
v9 = 0LL;
v19 = a1;
x = COERCE_DOUBLE(*(_QWORD *)&a3 ^ LC5) * a3;
do
{
for ( i = 0LL; i != v19; ++i )
{
v14 = exp(x);
v18 = pow(a3, (double)(a2 + (int)v9));
v17 = v18 / fact_sqrt(v7, v6) * v14;
v15 = pow(a3, (double)(a2 + (int)i));
v16 = v15 / fact_sqrt(v7, v6) * v17;
sincos((double)((int)v9 - (int)i) * a4, sinx, &cosx);
v11 = i;
v6 = v9;
v7 = v8;
qdpack_operator_set(v8, v9, v11, cosx * v16, v16 * sinx[0]);
}
++v9;
}
while ( v9 != v19 );
}
qdpack_hilbert_space_free(v21);
}
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; // r15
__int64 v9; // r12
__int64 i; // rbx
__int64 v11; // rdx
double v14; // [rsp+28h] [rbp-A0h]
double v15; // [rsp+28h] [rbp-A0h]
double v16; // [rsp+28h] [rbp-A0h]
long double v17; // [rsp+30h] [rbp-98h]
double v18; // [rsp+40h] [rbp-88h]
__int64 v19; // [rsp+48h] [rbp-80h]
double x; // [rsp+70h] [rbp-58h]
__int64 v21; // [rsp+78h] [rbp-50h]
double cosx; // [rsp+80h] [rbp-48h] BYREF
double sinx[8]; // [rsp+88h] [rbp-40h] BYREF

v6 = (unsigned int)a1;
v21 = qdpack_hilbert_space_new();
qdpack_hilbert_space_add(v21, (unsigned int)a1);
v7 = v21;
v8 = qdpack_operator_alloc(v21);
if ( v8 )
{
if ( a1 > 0 )
{
v9 = 0LL;
v19 = a1;
x = COERCE_DOUBLE(*(_QWORD *)&a3 ^ LC5) * a3;
do
{
for ( i = 0LL; i != v19; ++i )
{
v14 = exp(x);
v18 = pow(a3, (double)(a2 + (int)v9));
v17 = v18 / fact_sqrt(v7, v6) * v14;
v15 = pow(a3, (double)(a2 + (int)i));
v16 = v15 / fact_sqrt(v7, v6) * v17;
sincos((double)((int)v9 - (int)i) * a4, sinx, &cosx);
v11 = i;
v6 = v9;
v7 = v8;
qdpack_operator_set(v8, v9, v11, cosx * v16, v16 * sinx[0]);
}
++v9;
}
while ( v9 != v19 );
}
qdpack_hilbert_space_free(v21);
}
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


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

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);
result = 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);
}
result = v4;
}
return result;
}

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

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);
result = 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);
}
result = v4;
}
return result;
}

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

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

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);
result = 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);
}
result = v2;
}
return result;
}

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

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);
result = 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);
}
result = v2;
}
return result;
}

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; // rbp
__int64 v2; // rax
__int64 v3; // r12
__int64 v4; // rbx
__int64 v5; // rdx
__int64 v6; // rsi
__int64 result; // rax

if ( a1 <= 0 )
{
fwrite("qdpack_dm_fock_state: n >= N.\n", 1uLL, 0x1EuLL, stderr);
result = 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
{
v5 = v4;
v6 = v4++;
qdpack_operator_set(v3, v6, v5, 1.0 / (double)a1, 0.0);
}
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);
}
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // r12
__int64 v4; // rbx
__int64 v5; // rdx
__int64 v6; // rsi
__int64 result; // rax

if ( a1 <= 0 )
{
fwrite("qdpack_dm_fock_state: n >= N.\n", 1uLL, 0x1EuLL, stderr);
result = 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
{
v5 = v4;
v6 = v4++;
qdpack_operator_set(v3, v6, v5, 1.0 / (double)a1, 0.0);
}
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);
}
result = v3;
}
return result;
}

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(a1, a2);
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(a1, a2);
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;
}

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


decompiled_code:
__int64 __fastcall qdpack_wf_coherent_state(unsigned int a1, int a2, double a3, double a4)
{
__int64 v5; // r13
__int64 v6; // rsi
__int64 v7; // r15
__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

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

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, int a2, double a3, double a4)
{
__int64 v5; // r13
__int64 v6; // rsi
__int64 v7; // r15
__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

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


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

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);
result = v3;
}
else
{
fwrite("qdpack_wf_fock_state: Failed to allocate wf (Out of memory?).\n", 1uLL, 0x3EuLL, stderr);
result = 0LL;
}
return result;
}

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

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);
result = v3;
}
else
{
fwrite("qdpack_wf_fock_state: Failed to allocate wf (Out of memory?).\n", 1uLL, 0x3EuLL, stderr);
result = 0LL;
}
return result;
}

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


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

if ( a1 >= (int)a2 )
{
fwrite("qdpack_wf_fock_state: n >= N.\n", 1uLL, 0x1EuLL, stderr);
result = 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);
result = v4;
}
return result;
}

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

if ( a1 >= (int)a2 )
{
fwrite("qdpack_wf_fock_state: n >= N.\n", 1uLL, 0x1EuLL, stderr);
result = 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);
result = v4;
}
return result;
}

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 i; // rbp
__int64 v6; // rbx
double v7; // xmm0_8
double v8; // xmm2_8
double v9; // xmm0_8
__int64 result; // rax
double v11; // [rsp+8h] [rbp-30h]

v4 = *a2;
if ( a1[1] == *a2 && v4 == *a1 )
{
for ( i = 0LL; v4 > (int)i; ++i )
{
v6 = 0LL;
if ( v4 > 0 )
{
do
{
v11 = qdpack_state_get(a2, i);
v7 = qdpack_state_get(a2, v6);
v8 = gsl_complex_conjugate(v7);
v9 = gsl_complex_mul(v11, a4, v8, a4);
qdpack_operator_set(a1, i, v6, v9, a4);
v4 = *a2;
++v6;
}
while ( *a2 > (int)v6 );
}
}
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 i; // rbp
__int64 v6; // rbx
double v7; // xmm0_8
double v8; // xmm2_8
double v9; // xmm0_8
__int64 result; // rax
double v11; // [rsp+8h] [rbp-30h]

v4 = *a2;
if ( a1[1] == *a2 && v4 == *a1 )
{
for ( i = 0LL; v4 > (int)i; ++i )
{
v6 = 0LL;
if ( v4 > 0 )
{
do
{
v11 = qdpack_state_get(a2, i);
v7 = qdpack_state_get(a2, v6);
v8 = gsl_complex_conjugate(v7);
v9 = gsl_complex_mul(v11, a4, v8, a4);
qdpack_operator_set(a1, i, v6, v9, a4);
v4 = *a2;
++v6;
}
while ( *a2 > (int)v6 );
}
}
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 v7; // eax
__int64 v8; // r13
__int64 v9; // r12
__int64 v10; // r15
double v11; // xmm5_8
double v12; // r14
__int64 v13; // rdx
__int64 v14; // rsi
__int64 v15; // rdi
double v16; // xmm2_8
double v17; // xmm3_8
__int64 v18; // rdx
__int64 result; // rax
double v20; // [rsp+8h] [rbp-F0h]
__int64 v21; // [rsp+10h] [rbp-E8h]
__int64 v22; // [rsp+18h] [rbp-E0h]
int v23[20]; // [rsp+20h] [rbp-D8h] BYREF
int v24[34]; // [rsp+70h] [rbp-88h] BYREF

v22 = a1;
v7 = qdpack_hilbert_space_nstates(a2);
if ( a2 && a3 && *a2 == *(_DWORD *)(a3 + 160) )
{
if ( v7 > 0 )
{
v8 = 0LL;
v21 = v7;
do
{
v9 = 0LL;
qdpack_hilbert_space_state_vector(a2, (unsigned int)v8, v23);
do
{
v10 = 0LL;
qdpack_hilbert_space_state_vector(a2, (unsigned int)v9, v24);
v11 = 0.0;
v12 = 1.0;
if ( *a2 > 0 )
{
do
{
v13 = v24[v10];
v14 = v23[v10];
v20 = v11;
v15 = *(_QWORD *)(a3 + 8 * v10++);
v16 = qdpack_operator_get(v15, v14, v13);
v17 = a5;
a5 = v20;
v12 = gsl_complex_mul(v12, v20, v16, v17);
v11 = a5;
}
while ( *a2 > (int)v10 );
}
v18 = v9;
a5 = v11;
++v9;
qdpack_operator_set(v22, v8, v18, v12, v11);
}
while ( v9 != v21 );
++v8;
}
while ( v8 != v21 );
}
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 v7; // eax
__int64 v8; // r13
__int64 v9; // r12
__int64 v10; // r15
double v11; // xmm5_8
double v12; // r14
__int64 v13; // rdx
__int64 v14; // rsi
__int64 v15; // rdi
double v16; // xmm2_8
double v17; // xmm3_8
__int64 v18; // rdx
__int64 result; // rax
double v20; // [rsp+8h] [rbp-F0h]
__int64 v21; // [rsp+10h] [rbp-E8h]
__int64 v22; // [rsp+18h] [rbp-E0h]
int v23[20]; // [rsp+20h] [rbp-D8h] BYREF
int v24[34]; // [rsp+70h] [rbp-88h] BYREF

v22 = a1;
v7 = qdpack_hilbert_space_nstates(a2);
if ( a2 && a3 && *a2 == *(_DWORD *)(a3 + 160) )
{
if ( v7 > 0 )
{
v8 = 0LL;
v21 = v7;
do
{
v9 = 0LL;
qdpack_hilbert_space_state_vector(a2, (unsigned int)v8, v23);
do
{
v10 = 0LL;
qdpack_hilbert_space_state_vector(a2, (unsigned int)v9, v24);
v11 = 0.0;
v12 = 1.0;
if ( *a2 > 0 )
{
do
{
v13 = v24[v10];
v14 = v23[v10];
v20 = v11;
v15 = *(_QWORD *)(a3 + 8 * v10++);
v16 = qdpack_operator_get(v15, v14, v13);
v17 = a5;
a5 = v20;
v12 = gsl_complex_mul(v12, v20, v16, v17);
v11 = a5;
}
while ( *a2 > (int)v10 );
}
v18 = v9;
a5 = v11;
++v9;
qdpack_operator_set(v22, v8, v18, v12, v11);
}
while ( v9 != v21 );
++v8;
}
while ( v8 != v21 );
}
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:
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:
__int64 __fastcall qdpack_operator_list_init(__int64 a1)
{
__int64 v2; // rdi
__int64 result; // rax

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

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

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

original_code:
void
qdpack_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; } *

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

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

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

result = *(int *)(a1 + 160);
if ( (int)result > 19 )
return fwrite("qdpack_operator_list_append: Reached max size.\n", 1uLL, 0x2FuLL, stderr);
*(_DWORD *)(a1 + 160) = result + 1;
*(_QWORD *)(a1 + 8 * 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 result; // rax
__int64 v3; // rbx
__int64 v4; // rdi

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

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

result = *(unsigned int *)(a1 + 160);
if ( (int)result > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(a1 + 8 * v3++);
result = qdpack_operator_free(v4);
}
while ( *(_DWORD *)(a1 + 160) > (int)v3 );
}
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)
{
__int64 v5; // r14
__int64 v6; // r12
int v7; // ebx
__int64 v8; // r12
double v9; // r13
double v10; // xmm5_8
unsigned int v11; // er15
int v12; // ebx
int v13; // eax
double v14; // xmm2_8
double v15; // xmm3_8
__int64 v16; // rbx
double v18; // [rsp+0h] [rbp-118h]
int v19; // [rsp+Ch] [rbp-10Ch]
int v20; // [rsp+10h] [rbp-108h]
int v21; // [rsp+14h] [rbp-104h]
__int64 v22; // [rsp+18h] [rbp-100h]
__int64 v23; // [rsp+20h] [rbp-F8h]
__int64 v24; // [rsp+28h] [rbp-F0h]
__int64 v25; // [rsp+30h] [rbp-E8h]
__int64 v26; // [rsp+38h] [rbp-E0h]
int v27[20]; // [rsp+40h] [rbp-D8h] BYREF
int v28[34]; // [rsp+90h] [rbp-88h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, int a3, double a4, double a5)
{
__int64 v5; // r14
__int64 v6; // r12
int v7; // ebx
__int64 v8; // r12
double v9; // r13
double v10; // xmm5_8
unsigned int v11; // er15
int v12; // ebx
int v13; // eax
double v14; // xmm2_8
double v15; // xmm3_8
__int64 v16; // rbx
double v18; // [rsp+0h] [rbp-118h]
int v19; // [rsp+Ch] [rbp-10Ch]
int v20; // [rsp+10h] [rbp-108h]
int v21; // [rsp+14h] [rbp-104h]
__int64 v22; // [rsp+18h] [rbp-100h]
__int64 v23; // [rsp+20h] [rbp-F8h]
__int64 v24; // [rsp+28h] [rbp-F0h]
__int64 v25; // [rsp+30h] [rbp-E8h]
__int64 v26; // [rsp+38h] [rbp-E0h]
int v27[20]; // [rsp+40h] [rbp-D8h] BYREF
int v28[34]; // [rsp+90h] [rbp-88h] BYREF

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

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