repo: DanteCpp/libmatrix

decompiled_code:
void __fastcall __noreturn matrix_error(const char *a1)
{
perror(a1);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
perror(a1);
exit(-1);
}

original_code:
void
matrix_error( char * msg )
{
    perror(msg);
    exit(-1);
}

canonical_original_code:
void matrix_error(char *msg)
{
    perror(msg);
    exit(-1);
}

variable_types:
msg
char *

return_type: void


decompiled_code:
void __fastcall matrix_destroy(void *ptr)
{
__int64 i; // rbx
void *v3; // rdi

if ( !ptr )
matrix_error("matrix_destroy(): m == NULL");
for ( i = 0LL; *(_DWORD *)ptr > (int)i; ++i )
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * i);
free(v3);
}
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 i; // rbx
void *v3; // rdi

if ( !ptr )
func0("matrix_destroy(): m == NULL");
for ( i = 0LL; *(_DWORD *)ptr > (int)i; ++i )
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * i);
free(v3);
}
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void
matrix_destroy( Matrix *m )
{
    if ( m == ((void *)0) )
        matrix_error("matrix_destroy(): m == NULL")
            ;
    for( int i = 0; i < m->rows; i++ )
        free( m->values[i] );
    free( m->values );
    free( m );
}

canonical_original_code:
void matrix_destroy(struct Matrix *m)
{
    if ( m == ((void *)0) )
        matrix_error("matrix_destroy(): m == NULL")
            ;
    for( int i = 0; i < m->rows; i++ )
        free( m->values[i] );
    free( m->values );
    free( m );
}

variable_types: struct Matrix { int rows; int columns; double **values; } *

variable_types: i int


decompiled_code:
void __fastcall matrix_fill_random(__int64 a1)
{
__int64 i; // r13
__int64 j; // rbx

if ( !a1 )
matrix_error("matrix_fill_random(): m == NULL");
for ( i = 0LL; *(_DWORD *)a1 > (int)i; ++i )
{
for ( j = 0LL; *(_DWORD *)(a1 + 4) > (int)j; ++j )
*(double *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * i) + 8 * j) = (double)rand() / 2147483647.0;
}
}

original_code:
void
matrix_fill_random( Matrix *m )
{
    if ( m == ((void *)0) )
        matrix_error("matrix_fill_random(): m == NULL")
            ;
    for ( int row = 0; row < m->rows; row++ )
        for ( int column = 0; column < m->columns; column++ )
            m->values[row][column] = (Field) rand() / (2147483647)
                ;
}

canonical_original_code:
void matrix_fill_random(struct Matrix *m)
{
    if ( m == ((void *)0) )
        matrix_error("matrix_fill_random(): m == NULL")
            ;
    for ( int row = 0; row < m->rows; row++ )
        for ( int column = 0; column < m->columns; column++ )
            m->values[row][column] = (double) rand() / (2147483647)
                ;
}

variable_types: row int

variable_types: column int

user_defined_types: struct Matrix { int rows; int columns; double **values; }


decompiled_code:
int __fastcall matrix_print(__int64 a1)
{
__int64 i; // r13
__int64 j; // rbx
double v3; // xmm0_8
int result; // eax

if ( !a1 )
matrix_error("matrix_print(): m == NULL");
for ( i = 0LL; *(_DWORD *)a1 > (int)i; result = putchar(10) )
{
for ( j = 0LL; *(_DWORD *)(a1 + 4) > (int)j; ++j )
{
v3 = *(double *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * i) + 8 * j);
printf("%.2f ", v3);
}
++i;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 i; // r13
__int64 j; // rbx
double v3; // xmm0_8
int result; // eax

if ( !a1 )
func0("matrix_print(): m == NULL");
for ( i = 0LL; *(_DWORD *)a1 > (int)i; result = putchar(10) )
{
for ( j = 0LL; *(_DWORD *)(a1 + 4) > (int)j; ++j )
{
v3 = *(double *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * i) + 8 * j);
printf("%.2f ", v3);
}
++i;
}
return result;
}

original_code:
void
matrix_print( Matrix *m )
{
    if ( m == ((void *)0) )
        matrix_error("matrix_print(): m == NULL")
            ;
    for ( int row = 0; row < m->rows; row++ )
    {
        for ( int column = 0; column < m->columns; column++ )
            printf("%.2f ", m->values[row][column]);
        printf("\n");
    }
}

canonical_original_code:
void matrix_print(struct Matrix *m)
{
    if ( m == ((void *)0) )
        matrix_error("matrix_print(): m == NULL")
            ;
    for ( int row = 0; row < m->rows; row++ )
    {
        for ( int column = 0; column < m->columns; column++ )
            printf("%.2f ", m->values[row][column]);
        printf("\n");
    }
}


decompiled_code:
__int64 __fastcall matrix_copy(__int64 a1, int *a2)
{
__int64 result; // rax
__int64 v5; // rsi
__int64 v6; // r8
__int64 v7; // rdi
int v8; // er9
__int64 v9; // rcx
__int64 v10; // rdx

if ( !a1 || !a2 )
matrix_error("matrix_copy(): from == NULL || to == NULL");
if ( !(unsigned int)matrix_same_size() )
matrix_error("matrix_copy(): !matrix_same_size(from,to)");
result = *a2;
if ( (int)result > 0 )
{
v5 = a2[1];
v6 = 8 * result;
v7 = 0LL;
v8 = a2[1];
do
{
if ( v8 > 0 )
{
v9 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + v7);
v10 = *(_QWORD *)(*((_QWORD *)a2 + 1) + v7);
result = 0LL;
do
{
*(_QWORD *)(v10 + 8 * result) = *(_QWORD *)(v9 + 8 * result);
++result;
}
while ( v5 != result );
}
v7 += 8LL;
}
while ( v7 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int *a2)
{
__int64 result; // rax
__int64 v5; // rsi
__int64 v6; // r8
__int64 v7; // rdi
int v8; // er9
__int64 v9; // rcx
__int64 v10; // rdx

if ( !a1 || !a2 )
func0("matrix_copy(): from == NULL || to == NULL");
if ( !(unsigned int)matrix_same_size() )
func0("matrix_copy(): !matrix_same_size(from,to)");
result = *a2;
if ( (int)result > 0 )
{
v5 = a2[1];
v6 = 8 * result;
v7 = 0LL;
v8 = a2[1];
do
{
if ( v8 > 0 )
{
v9 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + v7);
v10 = *(_QWORD *)(*((_QWORD *)a2 + 1) + v7);
result = 0LL;
do
{
*(_QWORD *)(v10 + 8 * result) = *(_QWORD *)(v9 + 8 * result);
++result;
}
while ( v5 != result );
}
v7 += 8LL;
}
while ( v7 != v6 );
}
return result;
}

original_code:
void
matrix_copy( Matrix *from, Matrix * to )
{
    if ( from == ((void *)0) || to == ((void *)0) )
        matrix_error("matrix_copy(): from == NULL || to == NULL")
            ;
    if(!matrix_same_size(from,to))
        matrix_error("matrix_copy(): !matrix_same_size(from,to)")
            ;
    for ( int row = 0; row < to->rows; row++ )
        for ( int column = 0; column < to->columns; column++ )
            to->values[row][column] = from->values[row][column];
}

canonical_original_code:
void matrix_copy(struct Matrix *from, struct Matrix *to)
{
    if ( from == ((void *)0) || to == ((void *)0) )
        matrix_error("matrix_copy(): from == NULL || to == NULL")
            ;
    if(!matrix_same_size(from,to))
        matrix_error("matrix_copy(): !matrix_same_size(from,to)")
            ;
    for ( int row = 0; row < to->rows; row++ )
        for ( int column = 0; column < to->columns; column++ )
            to->values[row][column] = from->values[row][column];
}

variable_types:
to
struct Matrix *


decompiled_code:
double *__fastcall matrix_fill_Field(int *a1, double a2)
{
double *result; // rax
int v3; // er8
__int64 v4; // rsi
__int64 v5; // rcx
__int64 v6; // r9
double *v7; // rdx

if ( !a1 )
matrix_error("matrix_fill_Field(): m == NULL");
result = (double *)*a1;
if ( (int)result > 0 )
{
v3 = a1[1];
v4 = 8LL * (_QWORD)result;
v5 = 0LL;
result = (double *)(unsigned int)(v3 - 1);
v6 = 8LL * (_QWORD)result + 8;
do
{
if ( v3 > 0 )
{
result = *(double **)(*((_QWORD *)a1 + 1) + v5);
v7 = (double *)((char *)result + v6);
do
*result++ = a2;
while ( result != v7 );
}
v5 += 8LL;
}
while ( v5 != v4 );
}
return result;
}

canonical_decompiled_code:
double *__fastcall func6(int *a1, double a2)
{
double *result; // rax
int v3; // er8
__int64 v4; // rsi
__int64 v5; // rcx
__int64 v6; // r9
double *v7; // rdx

if ( !a1 )
func0("matrix_fill_Field(): m == NULL");
result = (double *)*a1;
if ( (int)result > 0 )
{
v3 = a1[1];
v4 = 8LL * (_QWORD)result;
v5 = 0LL;
result = (double *)(unsigned int)(v3 - 1);
v6 = 8LL * (_QWORD)result + 8;
do
{
if ( v3 > 0 )
{
result = *(double **)(*((_QWORD *)a1 + 1) + v5);
v7 = (double *)((char *)result + v6);
do
*result++ = a2;
while ( result != v7 );
}
v5 += 8LL;
}
while ( v5 != v4 );
}
return result;
}

original_code:
void
matrix_fill_Field( Matrix *m , Field r )
{
  if ( m == ((void *)0) )
    matrix_error("matrix_fill_Field(): m == NULL")
        ;
  for ( int row = 0; row < m->rows; row++ )
    for ( int column = 0; column < m->columns; column++ )
      m->values[row][column] = r
        ;
}

canonical_original_code:
void matrix_fill_Field(struct Matrix *m, double r)
{
  if ( m == ((void *)0) )
    matrix_error("matrix_fill_Field(): m == NULL")
        ;
  for ( int row = 0; row < m->rows; row++ )
    for ( int column = 0; column < m->columns; column++ )
      m->values[row][column] = r
        ;
}

variable_types: r double


decompiled_code:
__int64 __fastcall matrix_fill_triangular_up(int *a1)
{
__int64 result; // rax
__int64 v2; // r9
__int64 v3; // rcx
__int64 v4; // rdx

result = matrix_is_square();
if ( !(_DWORD)result )
matrix_error("matrix_fill_triangular_up(): !matrix_is_square(m)");
v2 = *a1;
v3 = 0LL;
if ( (int)v2 > 0 )
{
do
{
v4 = 8LL;
LODWORD(result) = 0;
while ( 1 )
{
result = (unsigned int)(result + 1);
if ( (_DWORD)v2 == (_DWORD)result )
break;
if ( (int)result > (int)v3 )
*(_QWORD *)(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v3) + v4) = 0LL;
v4 += 8LL;
}
++v3;
}
while ( v3 != v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1)
{
__int64 result; // rax
__int64 v2; // r9
__int64 v3; // rcx
__int64 v4; // rdx

result = matrix_is_square();
if ( !(_DWORD)result )
func0("matrix_fill_triangular_up(): !matrix_is_square(m)");
v2 = *a1;
v3 = 0LL;
if ( (int)v2 > 0 )
{
do
{
v4 = 8LL;
LODWORD(result) = 0;
while ( 1 )
{
result = (unsigned int)(result + 1);
if ( (_DWORD)v2 == (_DWORD)result )
break;
if ( (int)result > (int)v3 )
*(_QWORD *)(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v3) + v4) = 0LL;
v4 += 8LL;
}
++v3;
}
while ( v3 != v2 );
}
return result;
}

original_code:
void
matrix_fill_triangular_up( Matrix * m)
{
    if( ! matrix_is_square(m) )
        matrix_error("matrix_fill_triangular_up(): !matrix_is_square(m)")
            ;
    for( int i=0 ; i < m->rows ; i++)
        for( int j=0 ; j < m->rows; j++ )
           if( i < j )
                m->values[i][j] = 0
                    ;
}

canonical_original_code:
void matrix_fill_triangular_up(struct Matrix *m)
{
    if( ! matrix_is_square(m) )
        matrix_error("matrix_fill_triangular_up(): !matrix_is_square(m)")
            ;
    for( int i = 0; i < m->rows ; i++)
        for( int j = 0; j < m->rows; j++ )
           if( i < j )
                m->values[i][j] = 0
                    ;
}

variable_types: j int


decompiled_code:
__int64 __fastcall matrix_fill_triangular_down(int *a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx

result = matrix_is_square();
if ( !(_DWORD)result )
matrix_error("matrix_fill_triangular_up(): !matrix_is_square(m)");
v2 = *a1;
v3 = 0LL;
if ( (int)v2 > 0 )
{
do
{
for ( result = 0LL; result != v2; ++result )
{
if ( (int)result < (int)v3 )
*(_QWORD *)(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v3) + 8 * result) = 0LL;
}
++v3;
}
while ( v3 != v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx

result = matrix_is_square();
if ( !(_DWORD)result )
func0("matrix_fill_triangular_up(): !matrix_is_square(m)");
v2 = *a1;
v3 = 0LL;
if ( (int)v2 > 0 )
{
do
{
for ( result = 0LL; result != v2; ++result )
{
if ( (int)result < (int)v3 )
*(_QWORD *)(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v3) + 8 * result) = 0LL;
}
++v3;
}
while ( v3 != v2 );
}
return result;
}

original_code:
void
matrix_fill_triangular_down( Matrix * m)
{
    if( ! matrix_is_square(m) )
        matrix_error("matrix_fill_triangular_up(): !matrix_is_square(m)")
            ;
    for( int i=0 ; i < m->rows ; i++)
        for( int j=0 ; j < m->rows; j++ )
           if( i > j )
                m->values[i][j] = 0
                    ;
}

canonical_original_code:
void matrix_fill_triangular_down(struct Matrix *m)
{
    if( ! matrix_is_square(m) )
        matrix_error("matrix_fill_triangular_up(): !matrix_is_square(m)")
            ;
    for( int i = 0; i < m->rows ; i++)
        for( int j = 0; j < m->rows; j++ )
           if( i > j )
                m->values[i][j] = 0
                    ;
}


decompiled_code:
__int64 __fastcall matrix_new_scalar(int a1, double a2)
{
int *v2; // rbp
__int64 v3; // r12

v2 = matrix_new_identity(a1);
v3 = matrix_scalar_mul(v2, a2);
matrix_destroy(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, double a2)
{
int *v2; // rbp
__int64 v3; // r12

v2 = func10(a1);
v3 = matrix_scalar_mul(v2, a2);
func1(v2);
return v3;
}

original_code:
Matrix *
matrix_new_scalar( int dim, Field r )
{
    Matrix * m = matrix_new_identity(dim);
    Matrix * scal = matrix_scalar_mul( r, m );
    matrix_destroy(m);
    return scal;
}

canonical_original_code:
struct Matrix *matrix_new_scalar(int dim, double r)
{
    struct Matrix *m = matrix_new_identity(dim);
    struct Matrix *scal = matrix_scalar_mul( r, m );
    matrix_destroy(m);
    return scal;
}

variable_types: dim int

return_type: struct Matrix { int rows; int columns; double **values; } *


original_code:
Matrix *
matrix_new_values( int rows, int columns, ... )
{
    va_list entry;
    Matrix * m = matrix_new(rows,columns);
  __builtin_va_start(entry,columns);
    for( int y = 0 ; y < rows ; y++ )
        for( int x = 0; x < columns ; x++ )
            m->values[y][x] = __builtin_va_arg(entry,Field)
                ;
 __builtin_va_end(entry);
 return m;
}

canonical_original_code:
struct Matrix *matrix_new_values(int rows, int columns, ...)
{
    __builtin_va_list entry;
    struct Matrix *m = matrix_new(rows,columns);
  __builtin_va_start(entry,columns);
    for( int y = 0; y < rows ; y++ )
        for( int x = 0; x < columns ; x++ )
            m->values[y][x] = __builtin_va_arg(entry,Field)
                ;
 __builtin_va_end(entry);
 return m;
}

variable_types: rows int

variable_types: columns int

variable_types: y int

variable_types: x int


original_code:
Matrix *
matrix_add( Matrix * m1, Matrix * m2 )
{
    if( !matrix_same_size(m1,m2))
        matrix_error("matrix_add(): !matrix_same_size(m1,m2)")
            ;
    Matrix * add = matrix_new(m1->rows,m1->columns);
    for ( int row = 0; row < m1->rows; row++ )
        for ( int column = 0; column < m1->columns; column++ )
            add->values[row][column] = m1->values[row][column] + m2->values[row][column]
                    ;
    return add;
}

canonical_original_code:
struct Matrix *matrix_add(struct Matrix *m1, struct Matrix *m2)
{
    if( !matrix_same_size(m1,m2))
        matrix_error("matrix_add(): !matrix_same_size(m1,m2)")
            ;
    struct Matrix *add = matrix_new(m1->rows,m1->columns);
    for ( int row = 0; row < m1->rows; row++ )
        for ( int column = 0; column < m1->columns; column++ )
            add->values[row][column] = m1->values[row][column] + m2->values[row][column]
                    ;
    return add;
}


original_code:
Matrix *
matrix_scalar_mul( Field s, Matrix * m)
{
    Matrix * mul = matrix_new(m->rows,m->columns);
    for ( int row = 0; row < mul->rows; row++ )
        for ( int column = 0; column < mul->columns; column++ )
            mul->values[row][column] = s * m->values[row][column]
                    ;
    return mul;
}

canonical_original_code:
struct Matrix *matrix_scalar_mul(double s, struct Matrix *m)
{
    struct Matrix *mul = matrix_new(m->rows,m->columns);
    for ( int row = 0; row < mul->rows; row++ )
        for ( int column = 0; column < mul->columns; column++ )
            mul->values[row][column] = s * m->values[row][column]
                    ;
    return mul;
}

variable_types: s double

variable_types:
m
struct Matrix *


original_code:
Matrix *
matrix_trasposition( Matrix * m )
{
    Matrix * t = matrix_new(m->columns, m->rows);
    for ( int row = 0; row < m->rows; row++ )
        for ( int column = 0; column < m->columns; column++ )
            t->values[column][row] = m->values[row][column]
                ;
  return t;
}

canonical_original_code:
struct Matrix *matrix_trasposition(struct Matrix *m)
{
    struct Matrix *t = matrix_new(m->columns, m->rows);
    for ( int row = 0; row < m->rows; row++ )
        for ( int column = 0; column < m->columns; column++ )
            t->values[column][row] = m->values[row][column]
                ;
  return t;
}


original_code:
Matrix *
matrix_multiplication( Matrix * m1, Matrix * m2 )
{
    if( !matrix_can_mul(m1,m2) )
        matrix_error("matrix_multiplication(): !matrix_can_mul(m1,m2)")
            ;
    Matrix *mul = matrix_new_zero( m1->rows, m2->columns );
    for ( int row = 0; row < m1->rows; row++ )
        for ( int column = 0; column < m2->columns; column++ )
            for ( int i = 0; i < m1->columns; i++ )
                mul->values[row][column] += m1->values[row][i] * m2->values[i][column]
                    ;
    return mul;
}

canonical_original_code:
struct Matrix *matrix_multiplication(struct Matrix *m1, struct Matrix *m2)
{
    if( !matrix_can_mul(m1,m2) )
        matrix_error("matrix_multiplication(): !matrix_can_mul(m1,m2)")
            ;
    struct Matrix *mul = matrix_new_zero( m1->rows, m2->columns );
    for ( int row = 0; row < m1->rows; row++ )
        for ( int column = 0; column < m2->columns; column++ )
            for ( int i = 0; i < m1->columns; i++ )
                mul->values[row][column] += m1->values[row][i] * m2->values[i][column]
                    ;
    return mul;
}


decompiled_code:
double __fastcall matrix_trace(__int64 a1, __int64 a2)
{
double *v2; // rdx
__int64 v3; // rdi
int v4; // eax
__int64 v5; // rcx
double result; // xmm0_8
double *v7; // rax
__int64 v8; // rcx

v3 = matrix_get_diagonal();
v4 = *(_DWORD *)(v3 + 4);
if ( v4 <= 0 )
{
result = 0.0;
}
else
{
v5 = (unsigned int)(v4 - 1);
result = 0.0;
v2 = **(double ***)(v3 + 8);
v7 = v2 + 1;
v8 = (__int64)&v2[v5 + 1];
while ( 1 )
{
result = result + *v2;
v2 = v7;
if ( v7 == (double *)v8 )
break;
++v7;
}
}
matrix_destroy(v3, a2, v2);
return result;
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1, __int64 a2)
{
double *v2; // rdx
__int64 v3; // rdi
int v4; // eax
__int64 v5; // rcx
double result; // xmm0_8
double *v7; // rax
__int64 v8; // rcx

v3 = matrix_get_diagonal();
v4 = *(_DWORD *)(v3 + 4);
if ( v4 <= 0 )
{
result = 0.0;
}
else
{
v5 = (unsigned int)(v4 - 1);
result = 0.0;
v2 = **(double ***)(v3 + 8);
v7 = v2 + 1;
v8 = (__int64)&v2[v5 + 1];
while ( 1 )
{
result = result + *v2;
v2 = v7;
if ( v7 == (double *)v8 )
break;
++v7;
}
}
matrix_destroy(v3, a2, v2);
return result;
}

original_code:
Field
matrix_trace( Matrix * m )
{
    Field tr = 0;
    Matrix * d = matrix_get_diagonal(m);
    for( int i = 0 ; i < d->columns ; i++ )
        tr += d->values[0][i]
            ;
    matrix_destroy(d);
    return tr;
}

canonical_original_code:
double matrix_trace(struct Matrix *m)
{
    double tr = 0;
    struct Matrix *d = matrix_get_diagonal(m);
    for( int i = 0; i < d->columns ; i++ )
        tr += d->values[0][i]
            ;
    matrix_destroy(d);
    return tr;
}

variable_types: tr double

return_type: double


decompiled_code:
double __fastcall matrix_determinant(__int64 a1)
{
int v1; // eax
__int64 v2; // rbx
__int64 v3; // rbp
double v4; // xmm0_8
__int64 v5; // rdx
double v7; // [rsp+0h] [rbp-28h]

v1 = *(_DWORD *)(a1 + 4);
if ( v1 == 1 )
{
matrix_error("matrix_determinant(): n==1");
v1 = *(_DWORD *)(a1 + 4);
}
if ( v1 == 2 )
return *(double *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) + 8LL) * ***(double ***)(a1 + 8)
- **(double **)(*(_QWORD *)(a1 + 8) + 8LL) * *(double *)(**(_QWORD **)(a1 + 8) + 8LL);
if ( v1 <= 0 )
return 0.0;
v2 = 0LL;
v7 = 0.0;
do
{
v3 = matrix_get_minor(0LL, a1, (unsigned int)v2);
v4 = pow(-1.0, (double)(int)v2) * *(double *)(**(_QWORD **)(a1 + 8) + 8 * v2);
++v2;
v7 = matrix_determinant(v3) * v4 + v7;
matrix_destroy(v3, a1, v5);
}
while ( *(_DWORD *)(a1 + 4) > (int)v2 );
return v7;
}

original_code:
Field
matrix_determinant( Matrix *m )
{
    if( m->columns == 1)
        matrix_error("matrix_determinant(): n==1")
            ;
    if ( m->columns == 2 )
        return m->values[0][0] * m->values[1][1] - m->values[1][0] * m->values[0][1]
            ;
    Field det = 0;
    Matrix * minor = ((void *)0);
    for ( int column = 0; column < m->columns; column++ )
    {
        minor = matrix_get_minor( 0, m, column );
        det += pow( -1, column ) * m->values[0][column] * matrix_determinant( minor );
        matrix_destroy(minor);
    }
    return det;
}

canonical_original_code:
double matrix_determinant(struct Matrix *m)
{
    if( m->columns == 1)
        matrix_error("matrix_determinant(): n==1")
            ;
    if ( m->columns == 2 )
        return m->values[0][0] * m->values[1][1] - m->values[1][0] * m->values[0][1]
            ;
    double det = 0;
    struct Matrix *minor = ((void *)0);
    for ( int column = 0; column < m->columns; column++ )
    {
        minor = matrix_get_minor( 0, m, column );
        det += pow( -1, column ) * m->values[0][column] * matrix_determinant( minor );
        matrix_destroy(minor);
    }
    return det;
}

variable_types: det double


decompiled_code:
__int64 __fastcall matrix_cofactors(int *a1)
{
__int64 i; // r14
__int64 j; // rbx
__int64 v3; // rbp
__int64 v4; // rdx
double v6; // [rsp+8h] [rbp-50h]
__int64 v7; // [rsp+18h] [rbp-40h]

v7 = 0LL;
for ( i = matrix_new_zero((unsigned int)*a1, (unsigned int)a1[1]); *a1 > (int)v7; ++v7 )
{
for ( j = 0LL; a1[1] > (int)j; ++j )
{
v3 = matrix_get_minor((unsigned int)v7, a1, (unsigned int)j);
v6 = pow(-1.0, (double)((int)v7 + (int)j));
*(double *)(*(_QWORD *)(*(_QWORD *)(i + 8) + 8 * v7) + 8 * j) = matrix_determinant(v3) * v6;
matrix_destroy(v3, a1, v4);
}
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1)
{
__int64 i; // r14
__int64 j; // rbx
__int64 v3; // rbp
__int64 v4; // rdx
double v6; // [rsp+8h] [rbp-50h]
__int64 v7; // [rsp+18h] [rbp-40h]

v7 = 0LL;
for ( i = matrix_new_zero((unsigned int)*a1, (unsigned int)a1[1]); *a1 > (int)v7; ++v7 )
{
for ( j = 0LL; a1[1] > (int)j; ++j )
{
v3 = matrix_get_minor((unsigned int)v7, a1, (unsigned int)j);
v6 = pow(-1.0, (double)((int)v7 + (int)j));
*(double *)(*(_QWORD *)(*(_QWORD *)(i + 8) + 8 * v7) + 8 * j) = func5(v3) * v6;
matrix_destroy(v3, a1, v4);
}
}
return i;
}

original_code:
Matrix *
matrix_cofactors( Matrix * m )
{
    Matrix * r = matrix_new_zero(m->rows,m->columns);
    for( int row=0 ; row < m->rows ; row++ )
        for( int column=0; column < m->columns ; column++ )
        {
            Matrix * minor = matrix_get_minor( row, m, column );
            r->values[row][column] = pow( -1, row+column ) * matrix_determinant(minor);
            matrix_destroy(minor);
        }
    return r;
}

canonical_original_code:
struct Matrix *matrix_cofactors(struct Matrix *m)
{
    struct Matrix *r = matrix_new_zero(m->rows,m->columns);
    for( int row = 0; row < m->rows ; row++ )
        for( int column = 0; column < m->columns ; column++ )
        {
            struct Matrix *minor = matrix_get_minor( row, m, column );
            r->values[row][column] = pow( -1, row+column ) * matrix_determinant(minor);
            matrix_destroy(minor);
        }
    return r;
}


decompiled_code:
__int64 __fastcall matrix_adjunct(int *a1, __int64 a2)
{
unsigned int *v2; // rbp
__int64 v3; // r12
__int64 v4; // rdx

v2 = (unsigned int *)matrix_cofactors(a1);
v3 = matrix_trasposition(v2);
matrix_destroy(v2, a2, v4);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1, __int64 a2)
{
unsigned int *v2; // rbp
__int64 v3; // r12
__int64 v4; // rdx

v2 = (unsigned int *)func7(a1);
v3 = func2(v2);
matrix_destroy(v2, a2, v4);
return v3;
}

original_code:
Matrix *
matrix_adjunct( Matrix * m )
{
    Matrix * r = matrix_cofactors(m);
    Matrix * t = matrix_trasposition(r);
    matrix_destroy(r);
    return t;
}

canonical_original_code:
struct Matrix *matrix_adjunct(struct Matrix *m)
{
    struct Matrix *r = matrix_cofactors(m);
    struct Matrix *t = matrix_trasposition(r);
    matrix_destroy(r);
    return t;
}


decompiled_code:
int *__fastcall matrix_inverse(int *a1, __int64 a2)
{
unsigned int *v2; // r12
double v3; // xmm1_8

v2 = (unsigned int *)matrix_adjunct(a1, a2);
v3 = matrix_determinant((__int64)a1);
return matrix_scalar_mul(v2, 1.0 / v3);
}

canonical_decompiled_code:
int *__fastcall func9(int *a1, __int64 a2)
{
unsigned int *v2; // r12
double v3; // xmm1_8

v2 = (unsigned int *)func8(a1, a2);
v3 = func5((__int64)a1);
return func1(v2, 1.0 / v3);
}

original_code:
Matrix *
matrix_inverse( Matrix * m )
{
 Matrix * adj = matrix_adjunct(m);
    return matrix_scalar_mul(1/matrix_determinant(m),adj);
}

canonical_original_code:
struct Matrix *matrix_inverse(struct Matrix *m)
{
 struct Matrix *adj = matrix_adjunct(m);
    return matrix_scalar_mul(1/matrix_determinant(m),adj);
}


original_code:
Matrix *
matrix_get_minor( int skip_row, Matrix *m, int skip_col )
{
    if( !matrix_is_square(m) )
        matrix_error("matrix_get_minor(): !matrix_is_square(m)")
            ;
    int i = 0, j = 0;
    Matrix * minor = matrix_new(m->rows-1,m->columns-1);
    for ( int row = 0; row < m->rows; row++ )
    {
        if ( row == skip_row )
            continue
                ;
          j=0;
        for ( int column = 0; column < m->columns; column++ )
        {
            if ( column == skip_col )
                continue
                    ;
            minor->values[i][j] = m->values[row][column];
            j++;
        }
        i++;
    }
    return minor;
}

canonical_original_code:
struct Matrix *matrix_get_minor(int skip_row, struct Matrix *m, int skip_col)
{
    if( !matrix_is_square(m) )
        matrix_error("matrix_get_minor(): !matrix_is_square(m)")
            ;
    int i = 0; int j = 0;
    struct Matrix *minor = matrix_new(m->rows-1,m->columns-1);
    for ( int row = 0; row < m->rows; row++ )
    {
        if ( row == skip_row )
            continue
                ;
          j=0;
        for ( int column = 0; column < m->columns; column++ )
        {
            if ( column == skip_col )
                continue
                    ;
            minor->values[i][j] = m->values[row][column];
            j++;
        }
        i++;
    }
    return minor;
}


original_code:
Matrix *
matrix_get_sub( int x1 , int x2, Matrix * m, int y1, int y2 )
{
    if( x2-x1+1 > m->rows || y2-y1+1 > m->columns )
        matrix_error("matrix_get_sub(): x2-x1+1 > m->rows || y2-y1+1 > m->columns")
            ;
 Matrix *minor = matrix_new_zero( x2-x1+1, y2-y1+1 );
 int i = 0;
    Field *temp = malloc( minor->rows * minor->columns * sizeof(Field) );
    memset(temp,minor->rows * minor->columns, sizeof(Field));
    if( temp == ((void *)0) )
        matrix_error("matrix_get_minor(): temp == NULL")
            ;
    for( int row = y1 ; row < (y2+1) ; row++ )
  for( int column = x1 ; column < (x2+1) ; column++ )
      temp[i++] = m->values[row][column]
       ;
    i = 0;
    for( int row = 0 ; row < minor->rows ; row++ )
  for( int column = 0 ; column < minor->columns ; column++ )
      minor->values[row][column] = temp[i++]
       ;
    return minor;
}

canonical_original_code:
struct Matrix *matrix_get_sub(int x1, int x2, struct Matrix *m, int y1, int y2)
{
    if( x2-x1+1 > m->rows || y2-y1+1 > m->columns )
        matrix_error("matrix_get_sub(): x2-x1+1 > m->rows || y2-y1+1 > m->columns")
            ;
 struct Matrix *minor = matrix_new_zero( x2-x1+1, y2-y1+1 );
 int i = 0;
    double *temp = malloc( minor->rows * minor->columns * sizeof(Field) );
    memset(temp,minor->rows * minor->columns, sizeof(Field));
    if( temp == ((void *)0) )
        matrix_error("matrix_get_minor(): temp == NULL")
            ;
    for( int row = y1; row < (y2+1) ; row++ )
  for( int column = x1; column < (x2+1) ; column++ )
      temp[i++] = m->values[row][column]
       ;
    i = 0;
    for( int row = 0; row < minor->rows ; row++ )
  for( int column = 0; column < minor->columns ; column++ )
      minor->values[row][column] = temp[i++]
       ;
    return minor;
}

variable_types:
temp
double *


original_code:
Matrix *
matrix_get_row( Matrix * m, int r )
{
    if( r >= m->rows )
        matrix_error("matrix_get_row(): r >= m->rows")
            ;
    Matrix * row = matrix_new(1,m->columns);
    for( int column = 0 ; column < m->columns ; column++ )
        row->values[0][column] = m->values[r][column]
            ;
    return row;
}

canonical_original_code:
struct Matrix *matrix_get_row(struct Matrix *m, int r)
{
    if( r >= m->rows )
        matrix_error("matrix_get_row(): r >= m->rows")
            ;
    struct Matrix *row = matrix_new(1,m->columns);
    for( int column = 0; column < m->columns ; column++ )
        row->values[0][column] = m->values[r][column]
            ;
    return row;
}

variable_types: r int

variable_types: struct Matrix { int rows; int columns; double **values; } *


original_code:
Matrix *
matrix_get_column( Matrix * m, int c )
{
    if( c >= m->columns )
        matrix_error("matrix_get_column(): c >= m->columns")
            ;
    Matrix * column = matrix_new(m->rows,1);
    for( int row = 0 ; row < m->rows ; row++ )
         column->values[row][0] = m->values[row][c]
            ;
    return column;
}

canonical_original_code:
struct Matrix *matrix_get_column(struct Matrix *m, int c)
{
    if( c >= m->columns )
        matrix_error("matrix_get_column(): c >= m->columns")
            ;
    struct Matrix *column = matrix_new(m->rows,1);
    for( int row = 0; row < m->rows ; row++ )
         column->values[row][0] = m->values[row][c]
            ;
    return column;
}

variable_types: c int

variable_types: row int


decompiled_code:
__int64 __fastcall matrix_get_diagonal(int *a1)
{
__int64 v1; // rax
__int64 v2; // rcx
__int64 v3; // r8
__int64 v4; // rdi
__int64 v5; // rcx
__int64 v6; // rsi
__int64 v7; // rax

if ( !(unsigned int)matrix_is_square(a1) )
matrix_error("matrix_get_diagonal(): !matrix_issquare(m)");
v1 = matrix_new(1LL, (unsigned int)a1[1]);
v2 = *a1;
v3 = v1;
if ( (int)v2 > 0 )
{
v4 = *((_QWORD *)a1 + 1);
v5 = 8 * v2;
v6 = **(_QWORD **)(v1 + 8);
v7 = 0LL;
do
{
*(_QWORD *)(v6 + v7) = *(_QWORD *)(*(_QWORD *)(v4 + v7) + v7);
v7 += 8LL;
}
while ( v5 != v7 );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1)
{
__int64 v1; // rax
__int64 v2; // rcx
__int64 v3; // r8
__int64 v4; // rdi
__int64 v5; // rcx
__int64 v6; // rsi
__int64 v7; // rax

if ( !(unsigned int)matrix_is_square(a1) )
matrix_error("matrix_get_diagonal(): !matrix_issquare(m)");
v1 = matrix_new(1LL, (unsigned int)a1[1]);
v2 = *a1;
v3 = v1;
if ( (int)v2 > 0 )
{
v4 = *((_QWORD *)a1 + 1);
v5 = 8 * v2;
v6 = **(_QWORD **)(v1 + 8);
v7 = 0LL;
do
{
*(_QWORD *)(v6 + v7) = *(_QWORD *)(*(_QWORD *)(v4 + v7) + v7);
v7 += 8LL;
}
while ( v5 != v7 );
}
return v3;
}

original_code:
Matrix *
matrix_get_diagonal( Matrix * m )
{
    if( !matrix_is_square(m) )
        matrix_error("matrix_get_diagonal(): !matrix_issquare(m)")
            ;
    Matrix * diagonal = matrix_new( 1, m->columns );
    for( int i = 0 ; i < m->rows ; i++ )
        diagonal->values[0][i] = m->values[i][i]
            ;
    return diagonal;
}

canonical_original_code:
struct Matrix *matrix_get_diagonal(struct Matrix *m)
{
    if( !matrix_is_square(m) )
        matrix_error("matrix_get_diagonal(): !matrix_issquare(m)")
            ;
    struct Matrix *diagonal = matrix_new( 1, m->columns );
    for( int i = 0; i < m->rows ; i++ )
        diagonal->values[0][i] = m->values[i][i]
            ;
    return diagonal;
}

variable_types: i int


decompiled_code:
__int64 __fastcall matrix_set_value(__int64 a1, int a2, int a3, double a4)
{
__int64 result; // rax

result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
*(double *)(result + 8LL * a3) = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, int a3, double a4)
{
__int64 result; // rax

result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
*(double *)(result + 8LL * a3) = a4;
return result;
}

original_code:
void
matrix_set_value(Matrix * m, int x, int y, Field v)
{
  m->values[x][y] = v;
}

canonical_original_code:
void matrix_set_value(struct Matrix *m, int x, int y, double v)
{
  m->values[x][y] = v;
}

variable_types: v double


original_code:
void
matrix_set_sub( Matrix * from, int y , int x, Matrix * to )
{
    if( y+from->rows > to->rows || x+from->columns > to->columns )
         matrix_error("matrix_set_minor(): y+from->rows > to->rows || x+from->columns > to->columns")
            ;
    for( int row = 0 ; row < from->rows ; row++ )
  for( int column = 0 ; column < from->columns ; column++ )
      to->values[row+y][column+x] = from->values[row][column]
       ;
}

canonical_original_code:
void matrix_set_sub(struct Matrix *from, int y, int x, struct Matrix *to)
{
    if( y+from->rows > to->rows || x+from->columns > to->columns )
         matrix_error("matrix_set_minor(): y+from->rows > to->rows || x+from->columns > to->columns")
            ;
    for( int row = 0; row < from->rows ; row++ )
  for( int column = 0; column < from->columns ; column++ )
      to->values[row+y][column+x] = from->values[row][column]
       ;
}

variable_types:
to
struct Matrix *

variable_types: column int


decompiled_code:
__int64 __fastcall matrix_set_row(__int64 a1, int a2, __int64 a3)
{
if ( *(_DWORD *)(a1 + 4) != *(_DWORD *)(a3 + 4) )
matrix_error("matrix_set_row(): from->columns != to->columns");
return matrix_set_sub(a1, 0, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, __int64 a3)
{
if ( *(_DWORD *)(a1 + 4) != *(_DWORD *)(a3 + 4) )
matrix_error("matrix_set_row(): from->columns != to->columns");
return func6(a1, 0, a2, a3);
}

original_code:
void
matrix_set_row( Matrix * from, int r , Matrix * to )
{
    if( from->columns != to->columns )
        matrix_error("matrix_set_row(): from->columns != to->columns")
            ;
    matrix_set_sub(from, 0, r, to);
}

canonical_original_code:
void matrix_set_row(struct Matrix *from, int r, struct Matrix *to)
{
    if( from->columns != to->columns )
        matrix_error("matrix_set_row(): from->columns != to->columns")
            ;
    matrix_set_sub(from, 0, r, to);
}


decompiled_code:
__int64 __fastcall matrix_set_column(_DWORD *a1, int a2, _DWORD *a3)
{
if ( *a1 != *a3 )
matrix_error("matrix_set_column(): from->rows != to->rows");
return matrix_set_sub((__int64)a1, a2, 0, (__int64)a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, int a2, _DWORD *a3)
{
if ( *a1 != *a3 )
matrix_error("matrix_set_column(): from->rows != to->rows");
return func6((__int64)a1, a2, 0, (__int64)a3);
}

original_code:
void
matrix_set_column( Matrix * from, int c , Matrix * to )
{
    if( from->rows != to->rows )
        matrix_error("matrix_set_column(): from->rows != to->rows")
            ;
    matrix_set_sub(from, c, 0, to);
}

canonical_original_code:
void matrix_set_column(struct Matrix *from, int c, struct Matrix *to)
{
    if( from->rows != to->rows )
        matrix_error("matrix_set_column(): from->rows != to->rows")
            ;
    matrix_set_sub(from, c, 0, to);
}


decompiled_code:
__int64 __fastcall matrix_set_diagonal(unsigned int *a1, int *a2)
{
__int64 result; // rax
int v3; // edx
__int64 v4; // rcx
__int64 v5; // rdi
__int64 v6; // rsi
__int64 v7; // rcx
__int64 v8; // rcx
__int64 v9; // rsi
__int64 v10; // rcx
__int64 v11; // rdi

if ( (unsigned int)matrix_is_vector() && (unsigned int)matrix_is_square(a2) )
{
result = *a1;
v3 = a2[1];
if ( (_DWORD)result != 1 )
{
LABEL_4:
if ( (_DWORD)result != v3 )
result = matrix_error("matrix_set_diagonal(): d->rows != m->columns");
v4 = *a2;
if ( (int)v4 > 0 )
{
v5 = *((_QWORD *)a1 + 1);
v6 = *((_QWORD *)a2 + 1);
v7 = 8 * v4;
result = 0LL;
do
{
*(_QWORD *)(*(_QWORD *)(v6 + result) + result) = **(_QWORD **)(v5 + result);
result += 8LL;
}
while ( v7 != result );
}
return result;
}
}
else
{
matrix_error("matrix_set_diagonal(): !( matrix_isvector(d) && matrix_issquare(m))");
result = *a1;
v3 = a2[1];
if ( (_DWORD)result != 1 )
goto LABEL_4;
}
if ( a1[1] != v3 )
result = matrix_error("matrix_set_diagonal(): d->columns != m->columns ");
v8 = *a2;
if ( (int)v8 > 0 )
{
v9 = *((_QWORD *)a2 + 1);
v10 = 8 * v8;
v11 = **((_QWORD **)a1 + 1);
result = 0LL;
do
{
*(_QWORD *)(*(_QWORD *)(v9 + result) + result) = *(_QWORD *)(v11 + result);
result += 8LL;
}
while ( result != v10 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1, int *a2)
{
__int64 result; // rax
int v3; // edx
__int64 v4; // rcx
__int64 v5; // rdi
__int64 v6; // rsi
__int64 v7; // rcx
__int64 v8; // rcx
__int64 v9; // rsi
__int64 v10; // rcx
__int64 v11; // rdi

if ( (unsigned int)matrix_is_vector() && (unsigned int)matrix_is_square(a2) )
{
result = *a1;
v3 = a2[1];
if ( (_DWORD)result != 1 )
{
LABEL_4:
if ( (_DWORD)result != v3 )
result = matrix_error("matrix_set_diagonal(): d->rows != m->columns");
v4 = *a2;
if ( (int)v4 > 0 )
{
v5 = *((_QWORD *)a1 + 1);
v6 = *((_QWORD *)a2 + 1);
v7 = 8 * v4;
result = 0LL;
do
{
*(_QWORD *)(*(_QWORD *)(v6 + result) + result) = **(_QWORD **)(v5 + result);
result += 8LL;
}
while ( v7 != result );
}
return result;
}
}
else
{
matrix_error("matrix_set_diagonal(): !( matrix_isvector(d) && matrix_issquare(m))");
result = *a1;
v3 = a2[1];
if ( (_DWORD)result != 1 )
goto LABEL_4;
}
if ( a1[1] != v3 )
result = matrix_error("matrix_set_diagonal(): d->columns != m->columns ");
v8 = *a2;
if ( (int)v8 > 0 )
{
v9 = *((_QWORD *)a2 + 1);
v10 = 8 * v8;
v11 = **((_QWORD **)a1 + 1);
result = 0LL;
do
{
*(_QWORD *)(*(_QWORD *)(v9 + result) + result) = *(_QWORD *)(v11 + result);
result += 8LL;
}
while ( result != v10 );
}
return result;
}

original_code:
void
matrix_set_diagonal( Matrix * d, Matrix * m )
{
    if( !( matrix_is_vector(d) && matrix_is_square(m)) )
        matrix_error("matrix_set_diagonal(): !( matrix_isvector(d) && matrix_issquare(m))")
            ;
    if( d->rows == 1 )
    {
        if( d->columns != m->columns )
            matrix_error("matrix_set_diagonal(): d->columns != m->columns ")
                ;
        for( int i = 0 ; i < m->rows ; i++ )
            m->values[i][i] = d->values[0][i]
                ;
    }
    else
    {
        if( d->rows != m->columns )
            matrix_error("matrix_set_diagonal(): d->rows != m->columns")
                ;
        for( int i = 0 ; i < m->rows ; i++ )
            m->values[i][i] = d->values[i][0]
                ;
    }
}

canonical_original_code:
void matrix_set_diagonal(struct Matrix *d, struct Matrix *m)
{
    if( !( matrix_is_vector(d) && matrix_is_square(m)) )
        matrix_error("matrix_set_diagonal(): !( matrix_isvector(d) && matrix_issquare(m))")
            ;
    if( d->rows == 1 )
    {
        if( d->columns != m->columns )
            matrix_error("matrix_set_diagonal(): d->columns != m->columns ")
                ;
        for( int i = 0; i < m->rows ; i++ )
            m->values[i][i] = d->values[0][i]
                ;
    }
    else
    {
        if( d->rows != m->columns )
            matrix_error("matrix_set_diagonal(): d->rows != m->columns")
                ;
        for( int i = 0; i < m->rows ; i++ )
            m->values[i][i] = d->values[i][0]
                ;
    }
}


original_code:
void
matrix_filter( Matrix * m, Field (*func)(Field) )
{
    for ( int row = 0; row < m->rows; row++ )
        for ( int column = 0; column < m->columns; column++ )
            m->values[row][column] = (*func)( m->values[row][column] )
                    ;
}

canonical_original_code:
void matrix_filter(struct Matrix *m, double (*func)(double))
{
    for ( int row = 0; row < m->rows; row++ )
        for ( int column = 0; column < m->columns; column++ )
            m->values[row][column] = (*func)( m->values[row][column] )
                    ;
}

variable_types:
func
double (*)(double)


decompiled_code:
void __fastcall matrix_norm_euclide(__int64 a1)
{
double **v1; // rdx
double v2; // xmm1_8
double **v3; // rax
__int64 v4; // rcx
double v5; // xmm0_8

if ( (unsigned int)matrix_is_vector(a1) )
{
if ( *(int *)a1 > 0 )
{
v1 = *(double ***)(a1 + 8);
v2 = 0.0;
v3 = v1 + 1;
v4 = (__int64)&v1[(unsigned int)(*(_DWORD *)a1 - 1) + 1];
while ( 1 )
{
v5 = **v1;
v1 = v3;
v2 = v2 + v5 * v5;
if ( v3 == (double **)v4 )
break;
++v3;
}
if ( v2 < 0.0 )
sqrt(v2);
}
}
else
{
matrix_error("matrix_norm_euclide(): matrix_is_vector(v)");
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
double **v1; // rdx
double v2; // xmm1_8
double **v3; // rax
__int64 v4; // rcx
double v5; // xmm0_8

if ( (unsigned int)matrix_is_vector(a1) )
{
if ( *(int *)a1 > 0 )
{
v1 = *(double ***)(a1 + 8);
v2 = 0.0;
v3 = v1 + 1;
v4 = (__int64)&v1[(unsigned int)(*(_DWORD *)a1 - 1) + 1];
while ( 1 )
{
v5 = **v1;
v1 = v3;
v2 = v2 + v5 * v5;
if ( v3 == (double **)v4 )
break;
++v3;
}
if ( v2 < 0.0 )
sqrt(v2);
}
}
else
{
matrix_error("matrix_norm_euclide(): matrix_is_vector(v)");
}
}

original_code:
Field
matrix_norm_euclide(Matrix * v){
  if(matrix_is_vector(v))
  {
    Field sum = 0;
    for(int i=0;i<v->rows;i++)
      sum+=pow(v->values[i][0],2)
        ;
    return sqrt(sum);
  }
  else
  {
    matrix_error("matrix_norm_euclide(): matrix_is_vector(v)");
    return -1;
  }
}

canonical_original_code:
double matrix_norm_euclide(struct Matrix *v){
  if(matrix_is_vector(v))
  {
    double sum = 0;
    for(int i = 0;i<v->rows;i++)
      sum+=pow(v->values[i][0],2)
        ;
    return sqrt(sum);
  }
  else
  {
    matrix_error("matrix_norm_euclide(): matrix_is_vector(v)");
    return -1;
  }
}

variable_types: sum double


original_code:
Matrix *
matrix_gram_schmidt(Matrix * V)
{
  long n = V->rows;
  long m = V->columns;
  Matrix * Q = matrix_new_zero(n,m);
  double r = 0;
  double norm = 0;
  for(int k=0; k<n; k++)
    norm += (V->values[k][0])*(V->values[k][0])
      ;
    norm = sqrt(norm);
  for(int k=0; k<n; k++)
    (Q->values[k][0])=(V->values[k][0])/norm
      ;
  norm = 0;
  for(int i =1; i < m; i++)
  {
    for(int k=0; k<n; k++)
      Q->values[k][i]=V->values[k][i]
        ;
    for(int j=0; j<i;j++)
    {
      for(int k=0; k<n; k++)
        r+=(Q->values[k][j])*(V->values[k][i])
          ;
      for(int k=0; k<n; k++)
        (Q->values[k][i])-=(r*(Q->values[k][j]))
          ;
      r = 0;
    }
    for(int k=0; k<n; k++)
      norm += (Q->values[k][i])*(Q->values[k][i])
        ;
    norm = sqrt(norm);
    for(int k=0; k<n; k++)
      Q->values[k][i]=(Q->values[k][i])/norm
        ;
    norm = 0;
  }
  return Q;
}

canonical_original_code:
struct Matrix *matrix_gram_schmidt(struct Matrix *V)
{
  long n = V->rows;
  long m = V->columns;
  struct Matrix *Q = matrix_new_zero(n,m);
  double r = 0;
  double norm = 0;
  for(int k = 0; k<n; k++)
    norm += (V->values[k][0])*(V->values[k][0])
      ;
    norm = sqrt(norm);
  for(int k = 0; k<n; k++)
    (Q->values[k][0])=(V->values[k][0])/norm
      ;
  norm = 0;
  for(int i = 1; i < m; i++)
  {
    for(int k = 0; k<n; k++)
      Q->values[k][i]=V->values[k][i]
        ;
    for(int j = 0; j<i;j++)
    {
      for(int k = 0; k<n; k++)
        r+=(Q->values[k][j])*(V->values[k][i])
          ;
      for(int k = 0; k<n; k++)
        (Q->values[k][i])-=(r*(Q->values[k][j]))
          ;
      r = 0;
    }
    for(int k = 0; k<n; k++)
      norm += (Q->values[k][i])*(Q->values[k][i])
        ;
    norm = sqrt(norm);
    for(int k = 0; k<n; k++)
      Q->values[k][i]=(Q->values[k][i])/norm
        ;
    norm = 0;
  }
  return Q;
}

variable_types:
V
struct Matrix *

variable_types: n long

variable_types: m long

variable_types: r double

variable_types: norm double

variable_types: k int

variable_types: j int


decompiled_code:
_BOOL8 __fastcall matrix_same_size(_QWORD *a1, _QWORD *a2)
{
return *a1 == *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_QWORD *a1, _QWORD *a2)
{
return *a1 == *a2;
}

original_code:
int
matrix_same_size( Matrix * m1, Matrix * m2)
{
    if(m1->columns == m2->columns && m1->rows == m2->rows )
        return 1;
    else
        return 0;
}

canonical_original_code:
int matrix_same_size(struct Matrix *m1, struct Matrix *m2)
{
    if(m1->columns == m2->columns && m1->rows == m2->rows )
        return 1;
    else
        return 0;
}

return_type: int


decompiled_code:
_BOOL8 __fastcall matrix_is_equal(int *a1, _QWORD *a2)
{
_BOOL8 result; // rax
__int64 v3; // r8
__int64 v4; // rax
__int64 v5; // r10
__int64 v6; // r9
__int64 v7; // rax

result = matrix_same_size(a1, a2);
if ( result )
{
v4 = *a1;
if ( (int)v4 <= 0 )
{
LABEL_10:
result = 1LL;
}
else
{
v5 = 8 * v4;
v6 = 0LL;
while ( a1[1] <= 0 )
{
LABEL_9:
v6 += 8LL;
if ( v6 == v5 )
goto LABEL_10;
}
v7 = 0LL;
while ( *(double *)(*(_QWORD *)(*((_QWORD *)a1 + 1) + v6) + 8 * v7) == *(double *)(*(_QWORD *)(*(_QWORD *)(v3 + 8) + v6)
+ 8 * v7) )
{
if ( a1[1] == ++v7 )
goto LABEL_9;
}
result = 0LL;
}
}
return result;
}

original_code:
int
matrix_is_equal( Matrix *m1, Matrix * m2 )
{
    if(!matrix_same_size(m1,m2))
        return 0
            ;
    for ( int row = 0; row < m1->rows; row++ )
        for ( int column = 0; column < m1->columns; column++ )
            if( m1->values[row][column] != m2->values[row][column])
                return 0
                    ;
    return 1;
}

canonical_original_code:
int matrix_is_equal(struct Matrix *m1, struct Matrix *m2)
{
    if(!matrix_same_size(m1,m2))
        return 0
            ;
    for ( int row = 0; row < m1->rows; row++ )
        for ( int column = 0; column < m1->columns; column++ )
            if( m1->values[row][column] != m2->values[row][column])
                return 0
                    ;
    return 1;
}


decompiled_code:
_BOOL8 __fastcall matrix_is_square(_DWORD *a1)
{
return *a1 == a1[1];
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_DWORD *a1)
{
return *a1 == a1[1];
}

original_code:
int
matrix_is_square( Matrix * m )
{
    if( m->rows == m->columns )
        return 1;
    else
        return 0;
}

canonical_original_code:
int matrix_is_square(struct Matrix *m)
{
    if( m->rows == m->columns )
        return 1;
    else
        return 0;
}


decompiled_code:
__int64 __fastcall matrix_is_vector(unsigned int *a1)
{
__int64 result; // rax

result = *a1;
if ( (_DWORD)result != 1 )
result = a1[1] == 1;
return result;
}

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

result = *a1;
if ( (_DWORD)result != 1 )
result = a1[1] == 1;
return result;
}

original_code:
int
matrix_is_vector( Matrix * m )
{
    if( m->rows == 1 || m->columns == 1 )
        return 1;
    else
        return 0;
}

canonical_original_code:
int matrix_is_vector(struct Matrix *m)
{
    if( m->rows == 1 || m->columns == 1 )
        return 1;
    else
        return 0;
}


decompiled_code:
_BOOL8 __fastcall matrix_can_mul(__int64 a1, _DWORD *a2)
{
return *(_DWORD *)(a1 + 4) == *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, _DWORD *a2)
{
return *(_DWORD *)(a1 + 4) == *a2;
}

original_code:
int
matrix_can_mul( Matrix * m1, Matrix * m2 )
{
    if ( m1->columns == m2->rows )
        return 1;
    else
        return 0;
}

canonical_original_code:
int matrix_can_mul(struct Matrix *m1, struct Matrix *m2)
{
    if ( m1->columns == m2->rows )
        return 1;
    else
        return 0;
}


decompiled_code:
_BOOL8 matrix_is_sigular()
{
return matrix_determinant() == 0.0;
}

canonical_decompiled_code:
_BOOL8 func5()
{
return matrix_determinant() == 0.0;
}

original_code:
int
matrix_is_sigular( Matrix * m )
{
    if( matrix_determinant(m) == 0 )
        return 1;
    else
        return 0;
}

canonical_original_code:
int matrix_is_sigular(struct Matrix *m)
{
    if( matrix_determinant(m) == 0 )
        return 1;
    else
        return 0;
}


IFDHCreateChannel

repo: FlexCOS/lib-tty-ifdhandler

decompiled_code:
__int64 IFDHCreateChannel()
{
const char *v0; // rdx
__int64 v1; // rcx
const char *v2; // r8

log_msg();
return getDevice(0LL, "%s:%d:%s() IFDHCreateChannel", v0, v1, v2);
}

canonical_decompiled_code:
__int64 func1()
{
const char *v0; // rdx
__int64 v1; // rcx
const char *v2; // r8

log_msg();
return func12(0LL, "%s:%d:%s() IFDHCreateChannel", v0, v1, v2);
}

original_code:
RESPONSECODE IFDHCreateChannel ( DWORD Lun, DWORD Channel ) {
 log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHCreateChannel", "ifdhandler.c", 65, __FUNCTION__);
 return getDevice();
}

canonical_original_code:
long IFDHCreateChannel(unsigned long Lun, unsigned long Channel) {
 log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHCreateChannel", "ifdhandler.c", 65, __FUNCTION__);
 return getDevice();
}

variable_types:
Lun
unsigned long

variable_types:
Channel
unsigned long

return_type: long


IFDHCreateChannelByName

decompiled_code:
__int64 __fastcall IFDHCreateChannelByName(__int64 a1, __int64 a2)
{
const char *v2; // rdx
__int64 v3; // rcx
const char *v4; // r8

log_msg();
return getSerialPortByName(a2, "%s:%d:%s() IFDHCreateChannelByName", v2, v3, v4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
const char *v2; // rdx
__int64 v3; // rcx
const char *v4; // r8

log_msg();
return func13(a2, "%s:%d:%s() IFDHCreateChannelByName", v2, v3, v4);
}

original_code:
RESPONSECODE IFDHCreateChannelByName(DWORD Lun, LPSTR deviceName)
{
 log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHCreateChannelByName", "ifdhandler.c", 72, __FUNCTION__);
 return getSerialPortByName(deviceName);
}

canonical_original_code:
long IFDHCreateChannelByName(unsigned long Lun, char *deviceName)
{
 log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHCreateChannelByName", "ifdhandler.c", 72, __FUNCTION__);
 return getSerialPortByName(deviceName);
}

variable_types:
deviceName
char *


IFDHCloseChannel

decompiled_code:
__int64 IFDHCloseChannel()
{
const char *v0; // rdx
__int64 v1; // rcx
const char *v2; // r8

log_msg();
closeSerialPort(0LL, "%s:%d:%s() IFDHCloseChannel", v0, v1, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
const char *v0; // rdx
__int64 v1; // rcx
const char *v2; // r8

log_msg();
func11(0LL, "%s:%d:%s() IFDHCloseChannel", v0, v1, v2);
return 0LL;
}

original_code:
RESPONSECODE IFDHCloseChannel ( DWORD Lun ) {
    log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHCloseChannel", "ifdhandler.c", 88, __FUNCTION__);
 closeSerialPort();
    return 0;
}

canonical_original_code:
long IFDHCloseChannel(unsigned long Lun) {
    log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHCloseChannel", "ifdhandler.c", 88, __FUNCTION__);
 closeSerialPort();
    return 0;
}


IFDHGetCapabilities

decompiled_code:
__int64 __fastcall IFDHGetCapabilities(__int64 a1, __int64 a2, _QWORD *a3, _BYTE *a4)
{
__int64 result; // rax

log_msg();
if ( a2 == 771 )
{
readUID(a3, a4);
result = 0LL;
}
else if ( (unsigned __int64)(a2 - 4014) > 1 )
{
*a3 = 0LL;
result = 600LL;
}
else
{
*a3 = 1LL;
result = 0LL;
*a4 = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, _QWORD *a3, _BYTE *a4)
{
__int64 result; // rax

log_msg();
if ( a2 == 771 )
{
func15(a3, a4);
result = 0LL;
}
else if ( (unsigned __int64)(a2 - 4014) > 1 )
{
*a3 = 0LL;
result = 600LL;
}
else
{
*a3 = 1LL;
result = 0LL;
*a4 = 1;
}
return result;
}

original_code:
RESPONSECODE IFDHGetCapabilities ( DWORD Lun, DWORD Tag,
       PDWORD Length, PUCHAR Value ) {
 log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHGetCapabilities", "ifdhandler.c", 114, __FUNCTION__);
 RESPONSECODE rv;
    switch (Tag)
    {
    case 0x0303:
  readUID(Length, Value);
  rv = 0;
  break;
    case 0x0FAE:
  (*Length) = 1;
  (*Value) = 1;
  rv = 0;
  break;
    case 0x0FAF:
  (*Length) = 1;
  (*Value) = 1;
  rv = 0;
  break;
    default:
  (*Length) = 0;
  rv = 600;
    }
 return rv;
}

canonical_original_code:
long IFDHGetCapabilities(unsigned long Lun, unsigned long Tag, unsigned long *Length, unsigned char *Value) {
 log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHGetCapabilities", "ifdhandler.c", 114, __FUNCTION__);
 long rv;
    switch (Tag)
    {
    case 0x0303:
  readUID(Length, Value);
  rv = 0;
  break;
    case 0x0FAE:
  (*Length) = 1;
  (*Value) = 1;
  rv = 0;
  break;
    case 0x0FAF:
  (*Length) = 1;
  (*Value) = 1;
  rv = 0;
  break;
    default:
  (*Length) = 0;
  rv = 600;
    }
 return rv;
}

variable_types:
Tag
unsigned long

variable_types:
Length
unsigned long *

variable_types:
Value
unsigned char *

variable_types: rv long


IFDHSetCapabilities

decompiled_code:
__int64 IFDHSetCapabilities()
{
log_msg();
return 600LL;
}

canonical_decompiled_code:
__int64 func5()
{
log_msg();
return 600LL;
}

original_code:
RESPONSECODE IFDHSetCapabilities ( DWORD Lun, DWORD Tag,
          DWORD Length, PUCHAR Value ) {
    log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHSetCapabilities", "ifdhandler.c", 161, __FUNCTION__);
 return 600;
}

canonical_original_code:
long IFDHSetCapabilities(unsigned long Lun, unsigned long Tag, unsigned long Length, unsigned char *Value) {
    log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHSetCapabilities", "ifdhandler.c", 161, __FUNCTION__);
 return 600;
}

variable_types:
Length
unsigned long


IFDHSetProtocolParameters

decompiled_code:
__int64 __fastcall IFDHSetProtocolParameters(__int64 a1, __int64 a2)
{
log_msg();
return (unsigned __int64)(a2 - 1) >= 2 ? 0x25F : 0;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
log_msg();
return (unsigned __int64)(a2 - 1) >= 2 ? 0x25F : 0;
}

original_code:
RESPONSECODE IFDHSetProtocolParameters ( DWORD Lun, DWORD Protocol,
       UCHAR Flags, UCHAR PTS1,
       UCHAR PTS2, UCHAR PTS3) {
 log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHSetProtocolParameters", "ifdhandler.c", 186, __FUNCTION__);
 if (Protocol != 0x0001 && Protocol != 0x0002)
 {
  return 607;
 }
 return 0;
}

canonical_original_code:
long IFDHSetProtocolParameters(unsigned long Lun, unsigned long Protocol, unsigned char Flags, unsigned char PTS1, unsigned char PTS2, unsigned char PTS3) {
 log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHSetProtocolParameters", "ifdhandler.c", 186, __FUNCTION__);
 if (Protocol != 0x0001 && Protocol != 0x0002)
 {
  return 607;
 }
 return 0;
}

variable_types:
Protocol
unsigned long

variable_types:
Flags
unsigned char


IFDHPowerICC

decompiled_code:
__int64 __fastcall IFDHPowerICC(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax

log_msg();
if ( (a2 & 0xFFFFFFFFFFFFFFFDLL) == 500 )
{
readUID(a4, a3);
result = 0LL;
}
else
{
*a4 = 0LL;
result = 614LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax

log_msg();
if ( (a2 & 0xFFFFFFFFFFFFFFFDLL) == 500 )
{
func15(a4, a3);
result = 0LL;
}
else
{
*a4 = 0LL;
result = 614LL;
}
return result;
}

original_code:
RESPONSECODE IFDHPowerICC ( DWORD Lun, DWORD Action,
       PUCHAR Atr, PDWORD AtrLength ) {
 log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHPowerICC", "ifdhandler.c", 234, __FUNCTION__);
 RESPONSECODE rv;
 switch (Action)
 {
  case 502:
  case 500:
   readUID(AtrLength, Atr);
   rv = 0;
   break;
  default:
   *AtrLength = 0;
   Atr = 0;
   rv = 614;
   break;
 }
 return rv;
}

canonical_original_code:
long IFDHPowerICC(unsigned long Lun, unsigned long Action, unsigned char *Atr, unsigned long *AtrLength) {
 log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHPowerICC", "ifdhandler.c", 234, __FUNCTION__);
 long rv;
 switch (Action)
 {
  case 502:
  case 500:
   readUID(AtrLength, Atr);
   rv = 0;
   break;
  default:
   *AtrLength = 0;
   Atr = 0;
   rv = 614;
   break;
 }
 return rv;
}

variable_types:
Action
unsigned long

variable_types:
Atr
unsigned char *

variable_types:
AtrLength
unsigned long *


IFDHControl

decompiled_code:
__int64 __fastcall IFDHControl(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, _QWORD *a7)
{
log_msg();
*a7 = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, _QWORD *a7)
{
log_msg();
*a7 = 0LL;
return 0LL;
}

original_code:
RESPONSECODE IFDHControl(DWORD Lun, DWORD dwControlCode, PUCHAR TxBuffer,
       DWORD TxLength, PUCHAR RxBuffer,
  DWORD RxLength, PDWORD pdwBytesReturned) {
 log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHControl", "ifdhandler.c", 323, __FUNCTION__);
   *pdwBytesReturned = 0;
 return 0;
}

canonical_original_code:
long IFDHControl(unsigned long Lun, unsigned long dwControlCode, unsigned char *TxBuffer, unsigned long TxLength, unsigned char *RxBuffer, unsigned long RxLength, unsigned long *pdwBytesReturned) {
 log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "IFDHControl", "ifdhandler.c", 323, __FUNCTION__);
   *pdwBytesReturned = 0;
 return 0;
}

variable_types:
dwControlCode
unsigned long

variable_types:
TxBuffer
unsigned char *

variable_types:
TxLength
unsigned long

variable_types:
RxBuffer
unsigned char *

variable_types:
RxLength
unsigned long

variable_types:
pdwBytesReturned
unsigned long *


IFDHICCPresence

decompiled_code:
__int64 IFDHICCPresence()
{
__int64 result; // rax

if ( (unsigned int)readPresence() == 1 )
{
log_msg();
result = 615LL;
}
else
{
log_msg();
result = 616LL;
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax

if ( (unsigned int)func16() == 1 )
{
log_msg();
result = 615LL;
}
else
{
log_msg();
result = 616LL;
}
return result;
}

original_code:
RESPONSECODE IFDHICCPresence( DWORD Lun ) {
 int ret = 0;
 ret = readPresence();
 if (ret == 1)
 {
  log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "present", "ifdhandler.c", 343, __FUNCTION__);
  return 615;
 }
 else
 {
  log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "not present", "ifdhandler.c", 348, __FUNCTION__);
  return 616;
 }
}

canonical_original_code:
long IFDHICCPresence(unsigned long Lun) {
 int ret = 0;
 ret = readPresence();
 if (ret == 1)
 {
  log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "present", "ifdhandler.c", 343, __FUNCTION__);
  return 615;
 }
 else
 {
  log_msg(PCSC_LOG_DEBUG, "%s:%d:%s() " "not present", "ifdhandler.c", 348, __FUNCTION__);
  return 616;
 }
}

variable_types:
Lun
unsigned long

variable_types: ret int


main

canonical_name: main

repo: Ismuur/Magic

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int64 v4; // rdx

v3 = SDL_GetTicks(argc, argv, envp) + 16;
init("Jeu test");
load_game();
atexit((void (*)(void))&end);
while ( 1 )
{
gere_key();
update();
draw();
delay(v3);
v3 = SDL_GetTicks(v3, argv, v4) + 16;
}
}

original_code:
int main()
{
  unsigned int frame_limit;
  int go;
  frame_limit = SDL_GetTicks() + 16;
  go = 1;
  init("Jeu test");
  load_game();
  atexit(end);
  while (go)
    {
      gere_key();
      update();
      draw();
      delay(frame_limit);
      frame_limit = SDL_GetTicks() + 16;
    }
  exit(0);
}

variable_types: go int


draw

decompiled_code:
__int64 draw()
{
draw_image(map, 0, 0);
draw_map();
SDL_Flip(game);
return SDL_Delay(1LL);
}

canonical_decompiled_code:
__int64 func1()
{
func0(map, 0, 0);
draw_map();
SDL_Flip(game);
return SDL_Delay(1LL);
}

original_code:
void draw()
{
  draw_image(map.background, 0, 0);
  draw_map();
  SDL_Flip(game.screen);
  SDL_Delay(1);
}


delay

decompiled_code:
__int64 __fastcall delay(unsigned int a1)
{
__int64 result; // rax

result = SDL_GetTicks();
if ( (unsigned int)result <= a1 )
{
if ( (int)result + 16 >= a1 )
result = SDL_Delay(a1 - (unsigned int)result);
else
result = SDL_Delay(16LL);
}
return result;
}

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

result = SDL_GetTicks();
if ( (unsigned int)result <= a1 )
{
if ( (int)result + 16 >= a1 )
result = SDL_Delay(a1 - (unsigned int)result);
else
result = SDL_Delay(16LL);
}
return result;
}

original_code:
void delay(unsigned int limit)
{
  unsigned int ticks;
  ticks = SDL_GetTicks();
  if (limit < ticks)
    return ;
  if (limit > ticks + 16)
    SDL_Delay(16);
  else
    SDL_Delay(limit - ticks);
}

variable_types:
limit
unsigned int

variable_types:
ticks
unsigned int


decompiled_code:
__int64 __fastcall my_putchar_count(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 1LL;
}

original_code:
int my_putchar_count(char c)
{
  write(1, &c, 1);
  return (1);
}

variable_types: c char


decompiled_code:
__int64 __fastcall my_putchar_count_e(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(2, buf, 1uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(2, buf, 1uLL);
return 1LL;
}

original_code:
int my_putchar_count_e(char c)
{
  write(2, &c, 1);
  return (1);
}


decompiled_code:
__int64 __fastcall my_putstr_count(_BYTE *a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = 1LL;
result = 0LL;
if ( *a1 )
{
do
{
my_putchar();
result = (unsigned int)v1++;
}
while ( a1[v1 - 1] );
}
}
else
{
my_putstr("(null)");
result = 6LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = 1LL;
result = 0LL;
if ( *a1 )
{
do
{
my_putchar();
result = (unsigned int)v1++;
}
while ( a1[v1 - 1] );
}
}
else
{
my_putstr("(null)");
result = 6LL;
}
return result;
}

original_code:
int my_putstr_count(char *str)
{
  int i;
  i = 0;
  if (str == 0)
    {
      my_putstr("(null)");
      return (6);
    }
  while (str[i] != '\0')
    {
      my_putchar(str[i]);
      i = i + 1;
    }
  return (i);
}

variable_types:
str
char *

variable_types: i int


decompiled_code:
__int64 __fastcall my_putstr_count_e(_BYTE *a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = 1LL;
result = 0LL;
if ( *a1 )
{
do
{
my_putchar_count_e();
result = (unsigned int)v1++;
}
while ( a1[v1 - 1] );
}
}
else
{
my_putstr_count_e("(null)");
result = 6LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = 1LL;
result = 0LL;
if ( *a1 )
{
do
{
my_putchar_count_e();
result = (unsigned int)v1++;
}
while ( a1[v1 - 1] );
}
}
else
{
func1("(null)");
result = 6LL;
}
return result;
}

original_code:
int my_putstr_count_e(char *str)
{
  int i;
  i = 0;
  if (str == 0)
    {
      my_putstr_count_e("(null)");
      return (6);
    }
  while (str[i] != '\0')
    {
      my_putchar_count_e(str[i]);
      i = i + 1;
    }
  return (i);
}


decompiled_code:
__int64 __fastcall check_zero(int a1)
{
if ( a1 )
return 1LL;
my_putchar(48LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
if ( a1 )
return 1LL;
my_putchar(48LL);
return 0LL;
}

original_code:
int check_zero(unsigned int nb)
{
  if (nb == 0)
    {
      my_putchar(48);
      return (0);
    }
  else
    return (1);
}

variable_types:
nb
unsigned int


decompiled_code:
__int64 __fastcall my_putunnbr_base(unsigned int a1, __int64 a2)
{
unsigned int v3; // ebx
unsigned int i; // er13
unsigned int v5; // ebx
int v6; // er14
int v7; // eax
unsigned int v8; // er14

if ( !(unsigned int)check_zero(a1) )
return 1LL;
v3 = 1;
for ( i = my_strlen(a2); a1 >= v3; v3 *= i )
;
v5 = v3 / i;
if ( v5 == 1 )
{
v8 = 1;
}
else
{
v6 = 0;
do
{
my_putchar((unsigned int)*(char *)(a2 + a1 / v5 % i));
v5 /= i;
v7 = v6++;
}
while ( v5 != 1 );
v8 = v7 + 2;
}
my_putchar((unsigned int)*(char *)(a2 + a1 % i));
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
unsigned int v3; // ebx
unsigned int i; // er13
unsigned int v5; // ebx
int v6; // er14
int v7; // eax
unsigned int v8; // er14

if ( !(unsigned int)func0(a1) )
return 1LL;
v3 = 1;
for ( i = my_strlen(a2); a1 >= v3; v3 *= i )
;
v5 = v3 / i;
if ( v5 == 1 )
{
v8 = 1;
}
else
{
v6 = 0;
do
{
my_putchar((unsigned int)*(char *)(a2 + a1 / v5 % i));
v5 /= i;
v7 = v6++;
}
while ( v5 != 1 );
v8 = v7 + 2;
}
my_putchar((unsigned int)*(char *)(a2 + a1 % i));
return v8;
}

original_code:
int my_putunnbr_base(unsigned int nb, char *str)
{
  unsigned int mult;
  int size;
  int compteur;
  unsigned int result;
  if (check_zero(nb) == 0)
    return (1);
  mult = 1;
  compteur = 0;
  size = my_strlen(str);
  result = nb;
  while (mult <= nb)
    mult *= size;
  mult /= size;
  while (mult != 1)
    {
      result = nb;
      result /= mult;
      my_putchar(str[result % size]);
      mult /= size;
      compteur++;
    }
  my_putchar(str[nb % size]);
  return (compteur + 1);
}

variable_types:
mult
unsigned int

variable_types: size int

variable_types: compteur int

variable_types:
result
unsigned int


decompiled_code:
__int64 __fastcall flag_p(unsigned int a1, __int64 a2)
{
int v2; // ebx
__int64 result; // rax

if ( a1 )
{
v2 = my_putstr_count("0x");
result = v2 + (unsigned int)my_putunnbr_base(a1, a2) - 2;
}
else
{
my_putstr("(nil)");
result = 3LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
int v2; // ebx
__int64 result; // rax

if ( a1 )
{
v2 = my_putstr_count("0x");
result = v2 + (unsigned int)func1(a1, a2) - 2;
}
else
{
my_putstr("(nil)");
result = 3LL;
}
return result;
}

original_code:
int flag_p(unsigned int nb, char *str)
{
  if (nb == 0)
    {
      my_putstr("(nil)");
      return (3);
    }
  else
    return (my_putstr_count("0x") - 2 + my_putunnbr_base(nb, str));
}


decompiled_code:
__int64 __fastcall my_putunnbr_base_e(unsigned int a1, __int64 a2)
{
unsigned int v3; // ebx
unsigned int i; // er13
unsigned int v5; // ebx
int v6; // er14
int v7; // eax
unsigned int v8; // er14

if ( !(unsigned int)check_zero(a1) )
return 1LL;
v3 = 1;
for ( i = my_strlen(a2); a1 >= v3; v3 *= i )
;
v5 = v3 / i;
if ( v5 == 1 )
{
v8 = 1;
}
else
{
v6 = 0;
do
{
my_putchar_count_e((unsigned int)*(char *)(a2 + a1 / v5 % i));
v5 /= i;
v7 = v6++;
}
while ( v5 != 1 );
v8 = v7 + 2;
}
my_putchar_count_e((unsigned int)*(char *)(a2 + a1 % i));
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2)
{
unsigned int v3; // ebx
unsigned int i; // er13
unsigned int v5; // ebx
int v6; // er14
int v7; // eax
unsigned int v8; // er14

if ( !(unsigned int)func0(a1) )
return 1LL;
v3 = 1;
for ( i = my_strlen(a2); a1 >= v3; v3 *= i )
;
v5 = v3 / i;
if ( v5 == 1 )
{
v8 = 1;
}
else
{
v6 = 0;
do
{
my_putchar_count_e((unsigned int)*(char *)(a2 + a1 / v5 % i));
v5 /= i;
v7 = v6++;
}
while ( v5 != 1 );
v8 = v7 + 2;
}
my_putchar_count_e((unsigned int)*(char *)(a2 + a1 % i));
return v8;
}

original_code:
int my_putunnbr_base_e(unsigned int nb, char *str)
{
  unsigned int mult;
  int size;
  int compteur;
  unsigned int result;
  if (check_zero(nb) == 0)
    return (1);
  mult = 1;
  compteur = 0;
  size = my_strlen(str);
  result = nb;
  while (mult <= nb)
    mult *= size;
  mult /= size;
  while (mult != 1)
    {
      result = nb;
      result /= mult;
      my_putchar_count_e(str[result % size]);
      mult /= size;
      compteur++;
    }
  my_putchar_count_e(str[nb % size]);
  return (compteur + 1);
}


decompiled_code:
void __noreturn my_exit()
{
my_printf();
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
my_printf();
exit(1);
}

original_code:
void my_exit(char *str)
{
  my_printf(str);
  exit(1);
}


init

decompiled_code:
__int64 __fastcall init(__int64 a1)
{
if ( (unsigned int)SDL_Init(32LL) == -1 )
my_exit("SDL Init Error\n");
game = SDL_SetVideoMode(640LL, 480LL, 32LL, 17LL);
if ( !game )
my_exit("SDL Set Video Mode Error\n");
SDL_WM_SetCaption(a1, 0LL);
return SDL_ShowCursor(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( (unsigned int)SDL_Init(32LL) == -1 )
func0("SDL Init Error\n");
game = SDL_SetVideoMode(640LL, 480LL, 32LL, 17LL);
if ( !game )
func0("SDL Set Video Mode Error\n");
SDL_WM_SetCaption(a1, 0LL);
return SDL_ShowCursor(0LL);
}

original_code:
void init(char *title)
{
  if (SDL_Init(0x00000020) == -1)
    my_exit("SDL Init Error\n");
  if(!(game.screen = SDL_SetVideoMode(640, 480, 32, 0x00000001 | 0x00000010)))
    my_exit("SDL Set Video Mode Error\n");
  SDL_WM_SetCaption(title, ((void *)0));
  SDL_ShowCursor(0);
}

variable_types:
title
char *


decompiled_code:
__int64 load_game()
{
__int64 v0; // rax
bool v1; // zf

map[0] = load_image("Sprites/background.bmp");
v0 = load_image("Sprites/tileset.bmp");
v1 = map[0] == 0;
map[1] = v0;
if ( v1 || !v0 )
{
puts("Erreur dans le chargement");
exit(1);
}
return load_map("Map/map1.txt");
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
bool v1; // zf

map[0] = load_image("Sprites/background.bmp");
v0 = load_image("Sprites/tileset.bmp");
v1 = map[0] == 0;
map[1] = v0;
if ( v1 || !v0 )
{
puts("Erreur dans le chargement");
exit(1);
}
return load_map("Map/map1.txt");
}

original_code:
void load_game()
{
  map.background = load_image("Sprites/background.bmp");
  map.tile_set = load_image("Sprites/tileset.bmp");
  if (!map.background || !map.tile_set)
    {
      printf("Erreur dans le chargement\n");
      exit (1);
    }
  load_map("Map/map1.txt");
}


end

decompiled_code:
__int64 end()
{
if ( map[0] )
SDL_FreeSurface();
if ( map[1] )
SDL_FreeSurface();
return SDL_Quit();
}

canonical_decompiled_code:
__int64 func3()
{
if ( map[0] )
SDL_FreeSurface();
if ( map[1] )
SDL_FreeSurface();
return SDL_Quit();
}

original_code:
void end()
{
  if (map.background)
    SDL_FreeSurface(map.background);
  if (map.tile_set)
    SDL_FreeSurface(map.tile_set);
  SDL_Quit();
}


decompiled_code:
__int64 __fastcall check_modif(int a1)
{
unsigned __int64 v1; // rdx
__int64 result; // rax
__int64 v3; // rcx

if ( (unsigned __int8)(a1 - 99) <= 0x10u )
{
v1 = (0x10043uLL >> ((unsigned __int8)a1 - 99)) & 1;
if ( (_BYTE)a1 == 111 )
{
LABEL_4:
result = 1LL;
goto LABEL_5;
}
goto LABEL_3;
}
if ( (unsigned __int8)(a1 - 37) > 0x3Du )
{
LOBYTE(v1) = 0;
if ( (_BYTE)a1 == 111 )
goto LABEL_4;
LABEL_3:
if ( (_BYTE)a1 == 120 )
goto LABEL_4;
LABEL_11:
result = (unsigned __int8)(v1 | ((_BYTE)a1 == 0));
if ( (_BYTE)a1 == 88 )
return 1LL;
goto LABEL_6;
}
v3 = 0x2000400000000001LL;
result = 1LL;
if ( !_bittest64(&v3, (unsigned int)(a1 - 37)) )
{
LOBYTE(v1) = 0;
goto LABEL_11;
}
LABEL_5:
if ( (_BYTE)a1 == 88 )
return 1LL;
LABEL_6:
if ( (_BYTE)a1 == 112 )
return 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned __int64 v1; // rdx
__int64 result; // rax
__int64 v3; // rcx

if ( (unsigned __int8)(a1 - 99) <= 0x10u )
{
v1 = (0x10043uLL >> ((unsigned __int8)a1 - 99)) & 1;
if ( (_BYTE)a1 == 111 )
{
LABEL_4:
result = 1LL;
goto LABEL_5;
}
goto LABEL_3;
}
if ( (unsigned __int8)(a1 - 37) > 0x3Du )
{
LOBYTE(v1) = 0;
if ( (_BYTE)a1 == 111 )
goto LABEL_4;
LABEL_3:
if ( (_BYTE)a1 == 120 )
goto LABEL_4;
LABEL_11:
result = (unsigned __int8)(v1 | ((_BYTE)a1 == 0));
if ( (_BYTE)a1 == 88 )
return 1LL;
goto LABEL_6;
}
v3 = 0x2000400000000001LL;
result = 1LL;
if ( !_bittest64(&v3, (unsigned int)(a1 - 37)) )
{
LOBYTE(v1) = 0;
goto LABEL_11;
}
LABEL_5:
if ( (_BYTE)a1 == 88 )
return 1LL;
LABEL_6:
if ( (_BYTE)a1 == 112 )
return 1LL;
return result;
}

variable_types: retour int


decompiled_code:
__int64 my_perror(char *a1, ...)
{
int v2; // esi
char v3; // al
__int64 v4; // rsi
int v5; // edi
char v6; // r8
int v7; // er9
int v8; // eax
int v10; // [rsp+0h] [rbp-D8h] BYREF
unsigned int i; // [rsp+4h] [rbp-D4h] BYREF
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF
__int64 v13; // [rsp+28h] [rbp-B0h]
__int64 v14; // [rsp+30h] [rbp-A8h]
__int64 v15; // [rsp+38h] [rbp-A0h]
__int64 v16; // [rsp+40h] [rbp-98h]
__int64 v17; // [rsp+48h] [rbp-90h]

va_start(va, a1);
v13 = va_arg(va, _QWORD);
v14 = va_arg(va, _QWORD);
v15 = va_arg(va, _QWORD);
v16 = va_arg(va, _QWORD);
v17 = va_arg(va, _QWORD);
va_end(va);
va_start(va, a1);
v10 = 0;
v2 = 0;
v3 = *a1;
for ( i = 0; v3; v3 = a1[v10] )
{
while ( v3 != 37 )
{
incr(&v10, &i, (__int64)a1);
v2 = v10;
v3 = a1[v10];
if ( !v3 )
return i;
}
v10 = v2 + 1;
v4 = v2 + 1;
do
v5 = a1[v4++];
while ( !(unsigned int)check_modif(v5) );
if ( v6 )
v10 = v7;
v8 = recup_flag(v5, (unsigned int *)va, 0, (__int64)"0123456789abcdef");
i += v8;
v2 = ++v10;
}
return i;
}

canonical_decompiled_code:
__int64 func3(char *a1, ...)
{
int v2; // esi
char v3; // al
__int64 v4; // rsi
int v5; // edi
char v6; // r8
int v7; // er9
int v8; // eax
int v10; // [rsp+0h] [rbp-D8h] BYREF
unsigned int i; // [rsp+4h] [rbp-D4h] BYREF
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF
__int64 v13; // [rsp+28h] [rbp-B0h]
__int64 v14; // [rsp+30h] [rbp-A8h]
__int64 v15; // [rsp+38h] [rbp-A0h]
__int64 v16; // [rsp+40h] [rbp-98h]
__int64 v17; // [rsp+48h] [rbp-90h]

va_start(va, a1);
v13 = va_arg(va, _QWORD);
v14 = va_arg(va, _QWORD);
v15 = va_arg(va, _QWORD);
v16 = va_arg(va, _QWORD);
v17 = va_arg(va, _QWORD);
va_end(va);
va_start(va, a1);
v10 = 0;
v2 = 0;
v3 = *a1;
for ( i = 0; v3; v3 = a1[v10] )
{
while ( v3 != 37 )
{
func1(&v10, &i, (__int64)a1);
v2 = v10;
v3 = a1[v10];
if ( !v3 )
return i;
}
v10 = v2 + 1;
v4 = v2 + 1;
do
v5 = a1[v4++];
while ( !(unsigned int)func0(v5) );
if ( v6 )
v10 = v7;
v8 = func2(v5, (unsigned int *)va, 0, (__int64)"0123456789abcdef");
i += v8;
v2 = ++v10;
}
return i;
}

original_code:
int my_perror(const char *format, ...)
{
  int i;
  va_list ap;
  int compt;
  i = 0;
  compt = 0;
  __builtin_va_start(ap,format);
  while (format[i] != '\0')
    {
      if (format[i] != '%')
 incr(&i, &compt, format);
      else
 {
   i++;
   while (check_modif(format[i]) == 0)
     i++;
   compt = compt + recup_flag(format[i], ap, 0, "0123456789abcdef");
   i += 1;
 }
    }
  __builtin_va_end(ap);
  return (compt);
}

canonical_original_code:
int my_perror(char *format, ...)
{
  int i;
  __builtin_va_list ap;
  int compt;
  i = 0;
  compt = 0;
  __builtin_va_start(ap,format);
  while (format[i] != '\0')
    {
      if (format[i] != '%')
 incr(&i, &compt, format);
      else
 {
   i++;
   while (check_modif(format[i]) == 0)
     i++;
   compt = compt + recup_flag(format[i], ap, 0, "0123456789abcdef");
   i += 1;
 }
    }
  __builtin_va_end(ap);
  return (compt);
}

variable_types:
format
char *

variable_types: compt int


decompiled_code:
__int64 __fastcall my_putnbr_bin(int a1)
{
int v1; // edx
unsigned int v2; // er8
unsigned int v3; // er12
int v4; // eax
__int64 result; // rax

if ( a1 )
{
v1 = 1;
v2 = 0;
v3 = 0;
do
{
++v3;
v4 = v1 * (a1 % 2);
v1 *= 10;
v2 += v4;
a1 /= 2;
}
while ( a1 );
my_putnbr(v2);
result = v3;
}
else
{
my_putnbr(0LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // edx
unsigned int v2; // er8
unsigned int v3; // er12
int v4; // eax
__int64 result; // rax

if ( a1 )
{
v1 = 1;
v2 = 0;
v3 = 0;
do
{
++v3;
v4 = v1 * (a1 % 2);
v1 *= 10;
v2 += v4;
a1 /= 2;
}
while ( a1 );
my_putnbr(v2);
result = v3;
}
else
{
my_putnbr(0LL);
result = 0LL;
}
return result;
}

original_code:
int my_putnbr_bin(int nb)
{
  int i;
  int result;
  int mult;
  mult = 1;
  i = 0;
  result = 0;
  while (nb != 0)
    {
      result += (nb % 2) * mult ;
      mult *= 10;
      nb /= 2;
      i++;
    }
  my_putnbr(result);
  return (i);
}

variable_types: nb int

variable_types: result int

variable_types: mult int


decompiled_code:
__int64 __fastcall my_putnbr_bin_e(int a1)
{
int v1; // edx
unsigned int v2; // er8
unsigned int v3; // er12
int v4; // eax
__int64 result; // rax

if ( a1 )
{
v1 = 1;
v2 = 0;
v3 = 0;
do
{
++v3;
v4 = v1 * (a1 % 2);
v1 *= 10;
v2 += v4;
a1 /= 2;
}
while ( a1 );
my_putnbr_count_e(v2);
result = v3;
}
else
{
my_putnbr_count_e(0LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // edx
unsigned int v2; // er8
unsigned int v3; // er12
int v4; // eax
__int64 result; // rax

if ( a1 )
{
v1 = 1;
v2 = 0;
v3 = 0;
do
{
++v3;
v4 = v1 * (a1 % 2);
v1 *= 10;
v2 += v4;
a1 /= 2;
}
while ( a1 );
my_putnbr_count_e(v2);
result = v3;
}
else
{
my_putnbr_count_e(0LL);
result = 0LL;
}
return result;
}

original_code:
int my_putnbr_bin_e(int nb)
{
  int i;
  int result;
  int mult;
  mult = 1;
  i = 0;
  result = 0;
  while (nb != 0)
    {
      result += (nb % 2) * mult ;
      mult *= 10;
      nb /= 2;
      i++;
    }
  my_putnbr_count_e(result);
  return (i);
}


decompiled_code:
__int64 __fastcall my_convert_oct(int a1)
{
char *v1; // rcx
__int64 v2; // rsi
__int64 v3; // rdx
int v4; // eax
char v6[13]; // [rsp+Bh] [rbp-Dh] BYREF

v6[0] = 92;
v6[4] = 0;
if ( !a1 )
{
v4 = 0;
LABEL_5:
v2 = 48LL;
memset(&v6[3LL - v4 - (unsigned int)(2 - v4)], 48, (unsigned int)(2 - v4) + 1LL);
goto LABEL_6;
}
v1 = v6;
v2 = (unsigned int)v6 + 1;
do
{
v3 = (unsigned int)(a1 >> 31) >> 29;
v1[3] = a1 % 8 + 48;
v4 = v2 - (_DWORD)v1--;
a1 /= 8;
}
while ( a1 );
if ( v4 != 3 )
goto LABEL_5;
LABEL_6:
my_putstr(v6, v2, v3, v1);
return 4LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
char *v1; // rcx
__int64 v2; // rsi
__int64 v3; // rdx
int v4; // eax
char v6[13]; // [rsp+Bh] [rbp-Dh] BYREF

v6[0] = 92;
v6[4] = 0;
if ( !a1 )
{
v4 = 0;
LABEL_5:
v2 = 48LL;
memset(&v6[3LL - v4 - (unsigned int)(2 - v4)], 48, (unsigned int)(2 - v4) + 1LL);
goto LABEL_6;
}
v1 = v6;
v2 = (unsigned int)v6 + 1;
do
{
v3 = (unsigned int)(a1 >> 31) >> 29;
v1[3] = a1 % 8 + 48;
v4 = v2 - (_DWORD)v1--;
a1 /= 8;
}
while ( a1 );
if ( v4 != 3 )
goto LABEL_5;
LABEL_6:
my_putstr(v6, v2, v3, v1);
return 4LL;
}

original_code:
int my_convert_oct(int nb)
{
  char result[5];
  int i;
  i = 0;
  result[0] = '\\';
  result[4] = '\0';
  while (nb != 0)
    {
      result[3 - i] = (nb % 8) + 48;
      nb /= 8;
      i++;
    }
  while (3 - i != 0)
    {
      result[3 - i] = '0';
      i++;
    }
  my_putstr(result);
  return (4);
}

variable_types:
result
char [5]


decompiled_code:
__int64 __fastcall my_putstr_oct(char *a1)
{
char v1; // al
char *v2; // rbx
unsigned int v3; // er12
__int64 v4; // rdi

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = 0;
do
{
while ( 1 )
{
v4 = (unsigned int)v1;
if ( (unsigned __int8)(v1 - 32) > 0x5Eu )
break;
my_putchar(v4);
v1 = *v2++;
++v3;
if ( !v1 )
return v3;
}
++v2;
v3 += my_convert_oct(v4);
v1 = *(v2 - 1);
}
while ( v1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char v1; // al
char *v2; // rbx
unsigned int v3; // er12
__int64 v4; // rdi

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = 0;
do
{
while ( 1 )
{
v4 = (unsigned int)v1;
if ( (unsigned __int8)(v1 - 32) > 0x5Eu )
break;
my_putchar(v4);
v1 = *v2++;
++v3;
if ( !v1 )
return v3;
}
++v2;
v3 += func0(v4);
v1 = *(v2 - 1);
}
while ( v1 );
return v3;
}

original_code:
int my_putstr_oct(char *str)
{
  int i;
  int compteur;
  i = 0;
  compteur = 0;
  while (str[i] != '\0')
    {
      if (str[i] >= 32 && str[i] < 127)
 {
   my_putchar(str[i]);
   compteur++;
 }
      else
 compteur += my_convert_oct(str[i]);
      i++;
    }
  return (compteur);
}


decompiled_code:
__int64 __fastcall my_putstr_oct_e(char *a1)
{
char v1; // al
_BYTE *v2; // rbx
unsigned int v3; // er12
__int64 v4; // rdi

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = 0;
do
{
while ( 1 )
{
v4 = (unsigned int)v1;
if ( (unsigned __int8)(v1 - 32) > 0x5Eu )
break;
++v2;
++v3;
my_putchar_count_e(v4);
v1 = *(v2 - 1);
if ( !v1 )
return v3;
}
++v2;
v3 += my_convert_oct(v4);
v1 = *(v2 - 1);
}
while ( v1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char v1; // al
_BYTE *v2; // rbx
unsigned int v3; // er12
__int64 v4; // rdi

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = 0;
do
{
while ( 1 )
{
v4 = (unsigned int)v1;
if ( (unsigned __int8)(v1 - 32) > 0x5Eu )
break;
++v2;
++v3;
my_putchar_count_e(v4);
v1 = *(v2 - 1);
if ( !v1 )
return v3;
}
++v2;
v3 += func0(v4);
v1 = *(v2 - 1);
}
while ( v1 );
return v3;
}

original_code:
int my_putstr_oct_e(char *str)
{
  int i;
  int compteur;
  i = 0;
  compteur = 0;
  while (str[i] != '\0')
    {
      if (str[i] >= 32 && str[i] < 127)
 {
   my_putchar_count_e(str[i]);
   compteur++;
 }
      else
 compteur += my_convert_oct(str[i]);
      i++;
    }
  return (compteur);
}


decompiled_code:
__int64 __fastcall my_putnbr_oct(int a1)
{
int v1; // edx
unsigned int v2; // er12
unsigned int v3; // er8
int v4; // eax
__int64 result; // rax

if ( a1 )
{
v1 = 1;
v2 = 0;
v3 = 0;
do
{
v4 = v1 * (a1 % 8);
v1 *= 10;
v3 += v4;
++v2;
a1 /= 8;
}
while ( a1 );
my_putnbr(v3);
result = v2;
}
else
{
my_putnbr(0LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // edx
unsigned int v2; // er12
unsigned int v3; // er8
int v4; // eax
__int64 result; // rax

if ( a1 )
{
v1 = 1;
v2 = 0;
v3 = 0;
do
{
v4 = v1 * (a1 % 8);
v1 *= 10;
v3 += v4;
++v2;
a1 /= 8;
}
while ( a1 );
my_putnbr(v3);
result = v2;
}
else
{
my_putnbr(0LL);
result = 0LL;
}
return result;
}

original_code:
int my_putnbr_oct(int nb)
{
  int result;
  int compteur;
  int mult;
  result = 0;
  compteur = 0;
  mult = 1;
  while (nb != 0)
    {
      result += mult * (nb % 8);
      mult *= 10;
      nb /= 8;
      compteur++;
    }
  my_putnbr(result);
  return (compteur);
}


decompiled_code:
__int64 __fastcall my_putnbr_oct_e(int a1)
{
int v1; // edx
unsigned int v2; // er12
unsigned int v3; // er8
int v4; // eax
__int64 result; // rax

if ( a1 )
{
v1 = 1;
v2 = 0;
v3 = 0;
do
{
v4 = v1 * (a1 % 8);
v1 *= 10;
v3 += v4;
++v2;
a1 /= 8;
}
while ( a1 );
my_putnbr_count_e(v3);
result = v2;
}
else
{
my_putnbr_count_e(0LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
int v1; // edx
unsigned int v2; // er12
unsigned int v3; // er8
int v4; // eax
__int64 result; // rax

if ( a1 )
{
v1 = 1;
v2 = 0;
v3 = 0;
do
{
v4 = v1 * (a1 % 8);
v1 *= 10;
v3 += v4;
++v2;
a1 /= 8;
}
while ( a1 );
my_putnbr_count_e(v3);
result = v2;
}
else
{
my_putnbr_count_e(0LL);
result = 0LL;
}
return result;
}

original_code:
int my_putnbr_oct_e(int nb)
{
  int result;
  int compteur;
  int mult;
  result = 0;
  compteur = 0;
  mult = 1;
  while (nb != 0)
    {
      result += mult * (nb % 8);
      mult *= 10;
      nb /= 8;
      compteur++;
    }
  my_putnbr_count_e(result);
  return (compteur);
}


decompiled_code:
__int64 my_printf(char *a1, ...)
{
int v2; // esi
char v3; // al
__int64 v4; // rsi
int v5; // edi
char v6; // r8
int v7; // er9
int v8; // eax
int v10; // [rsp+0h] [rbp-D8h] BYREF
unsigned int i; // [rsp+4h] [rbp-D4h] BYREF
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF
__int64 v13; // [rsp+28h] [rbp-B0h]
__int64 v14; // [rsp+30h] [rbp-A8h]
__int64 v15; // [rsp+38h] [rbp-A0h]
__int64 v16; // [rsp+40h] [rbp-98h]
__int64 v17; // [rsp+48h] [rbp-90h]

va_start(va, a1);
v13 = va_arg(va, _QWORD);
v14 = va_arg(va, _QWORD);
v15 = va_arg(va, _QWORD);
v16 = va_arg(va, _QWORD);
v17 = va_arg(va, _QWORD);
va_end(va);
va_start(va, a1);
v10 = 0;
v2 = 0;
v3 = *a1;
for ( i = 0; v3; v3 = a1[v10] )
{
while ( v3 != 37 )
{
incr(&v10, &i, (__int64)a1);
v2 = v10;
v3 = a1[v10];
if ( !v3 )
return i;
}
v10 = v2 + 1;
v4 = v2 + 1;
do
v5 = a1[v4++];
while ( !(unsigned int)check_modif(v5) );
if ( v6 )
v10 = v7;
v8 = recup_flag(v5, (unsigned int *)va, 0, (__int64)"0123456789abcdef");
i += v8;
v2 = ++v10;
}
return i;
}

original_code:
int my_printf(const char *format, ...)
{
  int i;
  va_list ap;
  int compt;
  i = 0;
  compt = 0;
  __builtin_va_start(ap,format);
  while (format[i] != '\0')
    {
      if (format[i] != '%')
 incr(&i, &compt, format);
      else
 {
   i++;
   while (check_modif(format[i]) == 0)
     i++;
   compt = compt + recup_flag(format[i], ap, 0, "0123456789abcdef");
   i += 1;
 }
    }
  __builtin_va_end(ap);
  return (compt);
}

canonical_original_code:
int my_printf(char *format, ...)
{
  int i;
  __builtin_va_list ap;
  int compt;
  i = 0;
  compt = 0;
  __builtin_va_start(ap,format);
  while (format[i] != '\0')
    {
      if (format[i] != '%')
 incr(&i, &compt, format);
      else
 {
   i++;
   while (check_modif(format[i]) == 0)
     i++;
   compt = compt + recup_flag(format[i], ap, 0, "0123456789abcdef");
   i += 1;
 }
    }
  __builtin_va_end(ap);
  return (compt);
}


decompiled_code:
__int64 __fastcall my_putnbr_count(int a1)
{
int v1; // ebp
int v2; // ebx
unsigned int v3; // er13
unsigned int v4; // eax

v1 = a1;
if ( a1 < 0 )
{
v1 = -a1;
v2 = 1;
my_putchar(45LL);
if ( -a1 > 9 )
goto LABEL_3;
LABEL_8:
my_putchar((unsigned __int8)(v1 + 48));
return 1LL;
}
v2 = 1;
if ( a1 <= 9 )
goto LABEL_8;
do
LABEL_3:
v2 *= 10;
while ( v1 / v2 > 9 );
v3 = 0;
do
{
++v3;
v4 = v1 / v2;
v2 /= 0xAu;
my_putchar((unsigned __int8)(v4 % 0xA + 48));
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // ebp
int v2; // ebx
unsigned int v3; // er13
unsigned int v4; // eax

v1 = a1;
if ( a1 < 0 )
{
v1 = -a1;
v2 = 1;
my_putchar(45LL);
if ( -a1 > 9 )
goto LABEL_3;
LABEL_8:
my_putchar((unsigned __int8)(v1 + 48));
return 1LL;
}
v2 = 1;
if ( a1 <= 9 )
goto LABEL_8;
do
LABEL_3:
v2 *= 10;
while ( v1 / v2 > 9 );
v3 = 0;
do
{
++v3;
v4 = v1 / v2;
v2 /= 0xAu;
my_putchar((unsigned __int8)(v4 % 0xA + 48));
}
while ( v2 );
return v3;
}

original_code:
int my_putnbr_count(int nb)
{
  int i;
  int compteur;
  compteur = 0;
  i = 1;
  if (nb < 0)
    {
      nb = nb * -1;
      my_putchar('-');
    }
  while ((nb / i) > 9)
    {
      i = i * 10;
    }
  while (i > 0)
    {
      my_putchar((nb / i) % 10 + 48);
      i = i / 10;
      compteur++;
    }
  return (compteur);
}


decompiled_code:
__int64 __fastcall my_putnbr_count_e(int a1)
{
int v1; // ebp
int v2; // ebx
unsigned int v3; // er13
unsigned int v4; // eax

v1 = a1;
if ( a1 < 0 )
{
v1 = -a1;
v2 = 1;
my_putchar(45LL);
if ( -a1 > 9 )
goto LABEL_3;
LABEL_8:
my_putchar_count_e((unsigned int)(v1 + 48));
return 1LL;
}
v2 = 1;
if ( a1 <= 9 )
goto LABEL_8;
do
LABEL_3:
v2 *= 10;
while ( v1 / v2 > 9 );
v3 = 0;
do
{
++v3;
v4 = v1 / v2;
v2 /= 0xAu;
my_putchar_count_e(v4 % 0xA + 48);
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // ebp
int v2; // ebx
unsigned int v3; // er13
unsigned int v4; // eax

v1 = a1;
if ( a1 < 0 )
{
v1 = -a1;
v2 = 1;
my_putchar(45LL);
if ( -a1 > 9 )
goto LABEL_3;
LABEL_8:
my_putchar_count_e((unsigned int)(v1 + 48));
return 1LL;
}
v2 = 1;
if ( a1 <= 9 )
goto LABEL_8;
do
LABEL_3:
v2 *= 10;
while ( v1 / v2 > 9 );
v3 = 0;
do
{
++v3;
v4 = v1 / v2;
v2 /= 0xAu;
my_putchar_count_e(v4 % 0xA + 48);
}
while ( v2 );
return v3;
}

original_code:
int my_putnbr_count_e(int nb)
{
  int i;
  int compteur;
  compteur = 0;
  i = 1;
  if (nb < 0)
    {
      nb = nb * -1;
      my_putchar('-');
    }
  while ((nb / i) > 9)
    {
      i = i * 10;
    }
  while (i > 0)
    {
      my_putchar_count_e((nb / i) % 10 + 48);
      i = i / 10;
      compteur++;
    }
  return (compteur);
}


original_code:
void draw_map()
{
  int x;
  int y;
  int x1;
  int x2;
  int mapX;
  int y1;
  int y2;
  int mapY;
  int xsource;
  int ysource;
  int a;
  mapX = map.startX / 32;
  x1 = (map.startX % 32) * -1;
  x2 = x1 + 640 + (x1 == 0 ? 0 : 32);
  mapY = map.startY / 32;
  y1 = (map.startY % 32) * -1;
  y2 = y2 + 480 + (y1 == 0 ? 0 : 32);
  y = y1;
  while (y <= y2)
    {
      x = x1;
      mapX = map.startX / 32;
      while (x <= x2)
 {
   a = map.tile_tab[mapY][mapX];
   ysource = a / 10 * 32;
   xsource = a % 10 * 32;
   draw_tile(map.tile_set, x, y, xsource, ysource);
   mapX++;
   x+= 32;
 }
      mapY++;
      y += 32;
    }
}

variable_types: x int

variable_types: y int

variable_types: mapX int

variable_types: mapY int

variable_types: xsource int

variable_types: ysource int

variable_types: a int


update

original_code:
void update()
{
  if (ev.left == 1)
    {
      map.startX -= 32;
      if (map.startX < 0)
 map.startX = 0;
    }
  else if (ev.right == 1)
    {
      map.startX += 32;
      if (map.startX + 640 >= map.maxX)
 map.startX = map.maxX - 640;
    }
  if (ev.up == 1)
    {
      map.startY -= 32;
      if (map.startY < 0)
 map.startY = 0;
    }
  else if (ev.down == 1)
    {
      map.startY += 32;
      if (map.startY + 480 >= map.maxY)
 map.startY = map.maxY - 480;
    }
}


repo: JeffreyVdb/Thinkd

decompiled_code:
int __fastcall print_usage(const char **a1, const char **a2)
{
const char **v3; // rbx
const char *v4; // rdi
const char **v5; // r13
size_t v6; // rbp
size_t v7; // rax
int result; // eax
const char *i; // r8
__int64 v10; // rdx
const char *v11; // r9

v3 = a1;
v4 = *a1;
if ( v4 )
{
v5 = v3;
v6 = 0LL;
do
{
v7 = strlen(v4);
if ( v6 < v7 )
v6 = v7;
v4 = v5[4];
v5 += 4;
}
while ( v4 );
}
else
{
LODWORD(v6) = 0;
}
result = fprintf(stdout, "Usage for %s\n\nOPTIONS:\n", "thinkd");
for ( i = *v3; *v3; i = *v3 )
{
v10 = *((unsigned int *)v3 + 6);
v11 = *a2;
v3 += 4;
++a2;
result = fprintf(stdout, "\t-%-5c --%-*s\t%s\n", v10, v6, i, v11);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char **a1, const char **a2)
{
const char **v3; // rbx
const char *v4; // rdi
const char **v5; // r13
size_t v6; // rbp
size_t v7; // rax
int result; // eax
const char *i; // r8
__int64 v10; // rdx
const char *v11; // r9

v3 = a1;
v4 = *a1;
if ( v4 )
{
v5 = v3;
v6 = 0LL;
do
{
v7 = strlen(v4);
if ( v6 < v7 )
v6 = v7;
v4 = v5[4];
v5 += 4;
}
while ( v4 );
}
else
{
LODWORD(v6) = 0;
}
result = fprintf(stdout, "Usage for %s\n\nOPTIONS:\n", "thinkd");
for ( i = *v3; *v3; i = *v3 )
{
v10 = *((unsigned int *)v3 + 6);
v11 = *a2;
v3 += 4;
++a2;
result = fprintf(stdout, "\t-%-5c --%-*s\t%s\n", v10, v6, i, v11);
}
return result;
}

original_code:
static void print_usage(const struct option *opts, const char **opt_help)
{
 const struct option *opt;
 const char **help;
 size_t longest_opt = (size_t) 0, siz;
 for (opt = opts; opt->name; ++opt) {
  if ((siz = strlen(opt->name)) > longest_opt)
   longest_opt = siz;
 }
 fprintf(stdout, "Usage for %s\n\nOPTIONS:\n", "thinkd");
 for (opt = opts, help = opt_help; opt->name; ++opt, ++help) {
  fprintf(stdout, "\t-%-5c --%-*s\t%s\n",
   opt->val, (int) longest_opt, opt->name, *help);
 }
}

canonical_original_code:
static void print_usage(struct option *opts, char **opt_help)
{
 struct option *opt;
 char **help;
 unsigned long longest_opt = (size_t) 0; unsigned long siz;
 for (opt = opts; opt->name; ++opt) {
  if ((siz = strlen(opt->name)) > longest_opt)
   longest_opt = siz;
 }
 fprintf(stdout, "Usage for %s\n\nOPTIONS:\n", "thinkd");
 for (opt = opts, help = opt_help; opt->name; ++opt, ++help) {
  fprintf(stdout, "\t-%-5c --%-*s\t%s\n",
   opt->val, (int) longest_opt, opt->name, *help);
 }
}

variable_types: struct option { char *name; int has_arg; int *flag; int val; } *

variable_types:
help
char **

variable_types:
siz
unsigned long


decompiled_code:
__int64 open_log()
{
unsigned int v0; // er12
unsigned int v1; // eax
int *v3; // rbx
char *v4; // rax

v0 = thinkd_open_log();
if ( v0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "OPEN_LOG: %d (%s)\n", (unsigned int)*v3, v4);
}
else
{
v1 = getpid();
thinkd_log(6LL, "%s is starting, process %d (undaemonized).", "thinkd", v1);
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12
unsigned int v1; // eax
int *v3; // rbx
char *v4; // rax

v0 = thinkd_open_log();
if ( v0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "OPEN_LOG: %d (%s)\n", (unsigned int)*v3, v4);
}
else
{
v1 = getpid();
thinkd_log(6LL, "%s is starting, process %d (undaemonized).", "thinkd", v1);
}
return v0;
}

original_code:
static int open_log()
{
 int retval = 0;
 if ((retval = thinkd_open_log()) != 0) {
  fprintf(stderr, "OPEN_LOG" ": %d (%s)" "\n", (*__errno_location ()), strerror((*__errno_location ())));
  return retval;
 }
 thinkd_log(6, "%s is starting, process %d (undaemonized).",
     "thinkd", (int) getpid());
 return retval;
}

variable_types: retval int


decompiled_code:
int cleanup_before_exit()
{
unsigned int v0; // eax
int result; // eax
int v2; // [rsp+0h] [rbp-8h]

v0 = getpid();
thinkd_log(5LL, "%s process %d is stopping", "thinkd", v0);
thinkd_close_log();
pthread_mutex_destroy(&conf_mutex);
if ( lockfile )
result = unlink(lockfile);
else
result = v2;
return result;
}

canonical_decompiled_code:
int func3()
{
unsigned int v0; // eax
int result; // eax
int v2; // [rsp+0h] [rbp-8h]

v0 = getpid();
thinkd_log(5LL, "%s process %d is stopping", "thinkd", v0);
thinkd_close_log();
pthread_mutex_destroy(&conf_mutex);
if ( lockfile )
result = unlink(lockfile);
else
result = v2;
return result;
}

original_code:
static void cleanup_before_exit()
{
 thinkd_log(5, "%s process %d is stopping",
     "thinkd", (int) getpid());
 thinkd_close_log();
 pthread_mutex_destroy(&conf_mutex);
 if (lockfile)
  unlink(lockfile);
}


decompiled_code:
__uid_t validate_user()
{
__uid_t result; // eax

result = geteuid();
if ( result )
{
thinkd_log(3LL, "uid %d is required to run this process", 0LL);
cleanup_before_exit();
exit(1);
}
return result;
}

canonical_decompiled_code:
__uid_t func4()
{
__uid_t result; // eax

result = geteuid();
if ( result )
{
thinkd_log(3LL, "uid %d is required to run this process", 0LL);
func3();
exit(1);
}
return result;
}

original_code:
static void validate_user()
{
 const uid_t required_uid = 0;
 if ((geteuid()) == required_uid)
  return;
 thinkd_log(3, "uid %d is required to run this process",
     (int) required_uid);
 cleanup_before_exit();
 exit(1);
}

canonical_original_code:
static void validate_user()
{
 unsigned int required_uid = 0;
 if ((geteuid()) == required_uid)
  return;
 thinkd_log(3, "uid %d is required to run this process",
     (int) required_uid);
 cleanup_before_exit();
 exit(1);
}


decompiled_code:
void __noreturn clean_and_exit()
{
cleanup_before_exit();
exit(0);
}

canonical_decompiled_code:
void __noreturn func5()
{
func3();
exit(0);
}

original_code:
static void clean_and_exit()
{
 cleanup_before_exit();
 exit(0);
}


decompiled_code:
int __fastcall handle_cmd_args(int *a1, char *const **a2)
{
int result; // eax
int longind; // [rsp+Ch] [rbp-BCh] BYREF
const char *v4[4]; // [rsp+10h] [rbp-B8h] BYREF
struct option longopts; // [rsp+30h] [rbp-98h] BYREF
const char *v6; // [rsp+50h] [rbp-78h]
int v7; // [rsp+58h] [rbp-70h]
__int64 v8; // [rsp+60h] [rbp-68h]
int v9; // [rsp+68h] [rbp-60h]
const char *v10; // [rsp+70h] [rbp-58h]
int v11; // [rsp+78h] [rbp-50h]
__int64 v12; // [rsp+80h] [rbp-48h]
int v13; // [rsp+88h] [rbp-40h]
__int64 v14; // [rsp+90h] [rbp-38h]
int v15; // [rsp+98h] [rbp-30h]
__int64 v16; // [rsp+A0h] [rbp-28h]
int v17; // [rsp+A8h] [rbp-20h]

longopts.name = "help";
longopts.has_arg = 0;
longopts.flag = 0LL;
longopts.val = 104;
v6 = "version";
v7 = 0;
v8 = 0LL;
v9 = 118;
v10 = "no-probe";
v11 = 0;
v12 = 0LL;
v13 = 110;
v14 = 0LL;
v15 = 0;
v16 = 0LL;
v17 = 0;
v4[0] = "print help message";
v4[1] = "print version of this program";
v4[2] = "do not try detecting the power mode";
while ( 1 )
{
result = getopt_long(*a1, *a2, "hvn", &longopts, &longind);
if ( result == -1 )
return result;
if ( result == 110 )
{
probing = 0;
}
else
{
if ( result > 110 )
{
if ( result == 118 )
{
printf("%s %s\n", "thinkd", "2.1");
clean_and_exit();
}
LABEL_12:
print_usage(&longopts.name, v4);
cleanup_before_exit();
exit(1);
}
if ( result )
{
if ( result == 104 )
{
print_usage(&longopts.name, v4);
clean_and_exit();
}
goto LABEL_12;
}
}
}
}

canonical_decompiled_code:
int __fastcall func6(int *a1, char *const **a2)
{
int result; // eax
int longind; // [rsp+Ch] [rbp-BCh] BYREF
const char *v4[4]; // [rsp+10h] [rbp-B8h] BYREF
struct option longopts; // [rsp+30h] [rbp-98h] BYREF
const char *v6; // [rsp+50h] [rbp-78h]
int v7; // [rsp+58h] [rbp-70h]
__int64 v8; // [rsp+60h] [rbp-68h]
int v9; // [rsp+68h] [rbp-60h]
const char *v10; // [rsp+70h] [rbp-58h]
int v11; // [rsp+78h] [rbp-50h]
__int64 v12; // [rsp+80h] [rbp-48h]
int v13; // [rsp+88h] [rbp-40h]
__int64 v14; // [rsp+90h] [rbp-38h]
int v15; // [rsp+98h] [rbp-30h]
__int64 v16; // [rsp+A0h] [rbp-28h]
int v17; // [rsp+A8h] [rbp-20h]

longopts.name = "help";
longopts.has_arg = 0;
longopts.flag = 0LL;
longopts.val = 104;
v6 = "version";
v7 = 0;
v8 = 0LL;
v9 = 118;
v10 = "no-probe";
v11 = 0;
v12 = 0LL;
v13 = 110;
v14 = 0LL;
v15 = 0;
v16 = 0LL;
v17 = 0;
v4[0] = "print help message";
v4[1] = "print version of this program";
v4[2] = "do not try detecting the power mode";
while ( 1 )
{
result = getopt_long(*a1, *a2, "hvn", &longopts, &longind);
if ( result == -1 )
return result;
if ( result == 110 )
{
probing = 0;
}
else
{
if ( result > 110 )
{
if ( result == 118 )
{
printf("%s %s\n", "thinkd", "2.1");
func5();
}
LABEL_12:
func0(&longopts.name, v4);
func3();
exit(1);
}
if ( result )
{
if ( result == 104 )
{
func0(&longopts.name, v4);
func5();
}
goto LABEL_12;
}
}
}
}

original_code:
static void handle_cmd_args(int *argc, char ***argv)
{
 int c, option_index;
 const struct option opts[] = {
  {"help", 0, 0, 'h'},
  {"version", 0, 0, 'v'},
  {"no-probe", 0, 0, 'n'},
  {((void *)0), 0, 0, 0}
 };
 const char * opts_help[] = {
  "print help message",
  "print version of this program",
  "do not try detecting the power mode"
 };
 while ((c = getopt_long(*argc, *argv, "hvn", opts, &option_index)) != -1) {
  switch (c) {
  case 0:
   break;
  case 'n':
   probing = 0;
   break;
  case 'v':
   printf("%s %s\n", "thinkd", "2.1");
   clean_and_exit();
  case 'h':
   print_usage(opts, opts_help);
   clean_and_exit();
  case '?':
  default:
   print_usage(opts, opts_help);
   cleanup_before_exit();
   exit(1);
   break;
  }
 }
}

canonical_original_code:
static void handle_cmd_args(int *argc, char ***argv)
{
 int c; int option_index;
 struct option opts[] = {
  {"help", 0, 0, 'h'},
  {"version", 0, 0, 'v'},
  {"no-probe", 0, 0, 'n'},
  {((void *)0), 0, 0, 0}
 };
 char *opts_help[] = {
  "print help message",
  "print version of this program",
  "do not try detecting the power mode"
 };
 while ((c = getopt_long(*argc, *argv, "hvn", opts, &option_index)) != -1) {
  switch (c) {
  case 0:
   break;
  case 'n':
   probing = 0;
   break;
  case 'v':
   printf("%s %s\n", "thinkd", "2.1");
   clean_and_exit();
  case 'h':
   print_usage(opts, opts_help);
   clean_and_exit();
  case '?':
  default:
   print_usage(opts, opts_help);
   cleanup_before_exit();
   exit(1);
   break;
  }
 }
}

variable_types:
argc
int *

variable_types:
argv
char ***

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []