original_code:
void solve_matrix (nsieve_t *ns){
 printf ("\nStarting gaussian elimination... \n");
 long start = clock();
 const int hmlen = (ns->rels_needed -1)/64 + 1;
 const int hmsize = ns->rels_needed;
 uint64_t *history[hmsize];
 uint32_t rmos[hmsize];
 for (int i=0; i < hmsize; i++){
  history[i] = (uint64_t *) calloc (hmlen, sizeof(uint64_t));
  flip_bit (history[i], i);
  rmos[i] = rightmost_1 (ns->relns[i].row, ns->fb_len);
 }
 uint64_t *expm[ns->rels_needed];
 for (int i=0; i < hmsize; i++){
  expm[i] = (uint64_t *) malloc (ns->row_len * sizeof(uint64_t));
  for (int j=0; j<ns->row_len; j++){
   expm[i][j] = ns->relns[i].row[j];
  }
 }
 const int expm_rows = ns->rels_needed;
 const int expm_cols = ns->fb_len + 1;
 for (int col = expm_cols-1; col >= 0; col --){
  if ((expm_cols - col) % 50 == 0){
   printf("Column %d of %d\r", expm_cols - col, expm_cols);
   fflush(stdout);
  }
  int pivot = 0;
  while (pivot < expm_rows && rmos[pivot] != col){
   pivot ++;
  }
  for (int yolanda = pivot + 1; yolanda < expm_rows; yolanda++){
   if (rmos[yolanda] == col){
    xor_row (ns->relns[yolanda].row, ns->relns[pivot].row, ns->row_len);
    xor_row (history[yolanda], history[pivot], hmlen);
    rmos[yolanda] = rightmost_1 (ns->relns[yolanda].row, col);
   }
  }
 }
 printf("\nMatrix solved; deducing factors...\n");
 ns->timing.matsolve_time = clock() - start;
 start = clock();
 __gmpz_divexact_ui (ns->N, ns->N, ns->multiplier);
 mpz_t ncopy, temp;
 __gmpz_init_set (ncopy, ns->N);
 __gmpz_inits (temp, ((void *)0));
 uint16_t factor_counts[ns->fb_len+1];
 for (int row = 0; row < expm_rows; row ++){
  if (is_zero_vec (ns->relns[row].row, ns->row_len)){
   memset (factor_counts, 0, 2 * (ns->fb_len + 1));
   int relct = 0;
   int partialct = 0;
   uint64_t check [ns->row_len];
   clear_row (check, ns);
   for (int i=0; i < hmsize; i++){
    if (get_bit (history[row], i) == 1){
     xor_row (check, expm[i], ns->row_len);
    }
   }
   if (is_zero_vec (check, ns->row_len)){
   } else {
    printf("Check FAILED for row = %d\n", row);
   }
   mpz_t lhs, rhs;
   __gmpz_inits (lhs, rhs, ((void *)0));
   __gmpz_set_ui(lhs, 1);
   __gmpz_set_ui(rhs, 1);
   for (int relnum = 0; relnum < hmsize; relnum ++){
    if (get_bit (history[row], relnum) == 1){
     matrel_t *m = &ns->relns[relnum];
     if (!rel_check (m->r1, ns)){
      printf ("relation failed check. [%s]\n", m->r2==((void *)0)?"full":"partial, r1");
     } else {
     }
     multiply_in_lhs (lhs, m->r1, ns);
     add_factors_to_table (factor_counts, m->r1);
     relct ++;
     if (m->r2 != ((void *)0)){
      partialct ++;
      if (m->r1->cofactor != m->r2->cofactor){
       printf("AAAH - cofactors disagree! (%d and %d)\n", m->r1->cofactor, m->r2->cofactor);
      }
      if (!rel_check (m->r2, ns)){
       printf ("relation failed check. [partial, r2]\n");
      }
      multiply_in_lhs (lhs, m->r2, ns);
      add_factors_to_table (factor_counts, m->r2);
      __gmpz_mul_ui (rhs, rhs, m->r1->cofactor);
     }
    }
   }
   int is_good = construct_rhs (factor_counts, rhs, ns);
   if ( ! is_good ) {
    printf ("construct_rhs check failed.\n");
    continue;
   }
   __gmpz_mod (lhs, lhs, ns->N);
   __gmpz_mod (rhs, rhs, ns->N);
   __gmpz_sub (temp, rhs, lhs);
   __gmpz_gcd (temp, temp, ncopy);
   __gmpz_abs (temp, temp);
   if ((__builtin_constant_p (1) && (1) == 0 ? ((temp)->_mp_size < 0 ? -1 : (temp)->_mp_size > 0) : __gmpz_cmp_ui (temp,1)) > 0){
    if (__gmpz_cmp (temp, ns->N) != 0){
     if (__gmpz_divisible_p(ncopy, temp)){
      if (__gmpz_probab_prime_p (temp, 10)){
       __gmpz_out_str (stdout, 10, temp);
       printf (" (prp)\n");
       __gmpz_divexact(ncopy, ncopy, temp);
       if (__gmpz_probab_prime_p (ncopy, 10)){
        __gmpz_out_str(stdout, 10, ncopy);
        printf (" (prp)\n");
        __gmpz_set_ui(ncopy, 1);
       }
       if ((__builtin_constant_p (1) && (1) == 0 ? ((ncopy)->_mp_size < 0 ? -1 : (ncopy)->_mp_size > 0) : __gmpz_cmp_ui (ncopy,1)) == 0){
        __gmpz_clears(lhs, rhs, temp, ncopy, ((void *)0));
        ns->timing.facdeduct_time = clock() - start;
        return;
       }
      }
     }
    }
   }
   __gmpz_clears(lhs, rhs, ((void *)0));
  }
 }
 if ((__builtin_constant_p (1) && (1) == 0 ? ((ncopy)->_mp_size < 0 ? -1 : (ncopy)->_mp_size > 0) : __gmpz_cmp_ui (ncopy,1)) != 0){
  __gmpz_out_str (stdout, 10, ncopy);
  if (__gmpz_probab_prime_p (ncopy, 10)){
   printf (" (prp)\n");
  } else {
   printf (" (c)\n");
  }
 }
 ns->timing.facdeduct_time = clock() - start;
}

canonical_original_code:
void solve_matrix(struct nsieve_t *ns){
 printf ("\nStarting gaussian elimination... \n");
 long start = clock();
 int hmlen = (ns->rels_needed -1)/64 + 1;
 int hmsize = ns->rels_needed;
 unsigned long *history[-1];
 unsigned int rmos[-1];
 for (int i = 0; i < hmsize; i++){
  history[i] = (unsigned long *) calloc (hmlen, sizeof(unsigned long));
  flip_bit (history[i], i);
  rmos[i] = rightmost_1 (ns->relns[i].row, ns->fb_len);
 }
 unsigned long *expm[-1];
 for (int i = 0; i < hmsize; i++){
  expm[i] = (unsigned long *) malloc (ns->row_len * sizeof(unsigned long));
  for (int j = 0; j<ns->row_len; j++){
   expm[i][j] = ns->relns[i].row[j];
  }
 }
 int expm_rows = ns->rels_needed;
 int expm_cols = ns->fb_len + 1;
 for (int col = expm_cols-1; col >= 0; col --){
  if ((expm_cols - col) % 50 == 0){
   printf("Column %d of %d\r", expm_cols - col, expm_cols);
   fflush(stdout);
  }
  int pivot = 0;
  while (pivot < expm_rows && rmos[pivot] != col){
   pivot ++;
  }
  for (int yolanda = pivot + 1; yolanda < expm_rows; yolanda++){
   if (rmos[yolanda] == col){
    xor_row (ns->relns[yolanda].row, ns->relns[pivot].row, ns->row_len);
    xor_row (history[yolanda], history[pivot], hmlen);
    rmos[yolanda] = rightmost_1 (ns->relns[yolanda].row, col);
   }
  }
 }
 printf("\nMatrix solved; deducing factors...\n");
 ns->timing.matsolve_time = clock() - start;
 start = clock();
 __gmpz_divexact_ui (ns->N, ns->N, ns->multiplier);
 struct __mpz_struct ncopy[1]; struct __mpz_struct temp[1];
 __gmpz_init_set (ncopy, ns->N);
 __gmpz_inits (temp, ((void *)0));
 unsigned short factor_counts[-1];
 for (int row = 0; row < expm_rows; row ++){
  if (is_zero_vec (ns->relns[row].row, ns->row_len)){
   memset (factor_counts, 0, 2 * (ns->fb_len + 1));
   int relct = 0;
   int partialct = 0;
   unsigned long check[-1];
   clear_row (check, ns);
   for (int i = 0; i < hmsize; i++){
    if (get_bit (history[row], i) == 1){
     xor_row (check, expm[i], ns->row_len);
    }
   }
   if (is_zero_vec (check, ns->row_len)){
   } else {
    printf("Check FAILED for row = %d\n", row);
   }
   struct __mpz_struct lhs[1]; struct __mpz_struct rhs[1];
   __gmpz_inits (lhs, rhs, ((void *)0));
   __gmpz_set_ui(lhs, 1);
   __gmpz_set_ui(rhs, 1);
   for (int relnum = 0; relnum < hmsize; relnum ++){
    if (get_bit (history[row], relnum) == 1){
     struct matrel_t *m = &ns->relns[relnum];
     if (!rel_check (m->r1, ns)){
      printf ("relation failed check. [%s]\n", m->r2==((void *)0)?"full":"partial, r1");
     } else {
     }
     multiply_in_lhs (lhs, m->r1, ns);
     add_factors_to_table (factor_counts, m->r1);
     relct ++;
     if (m->r2 != ((void *)0)){
      partialct ++;
      if (m->r1->cofactor != m->r2->cofactor){
       printf("AAAH - cofactors disagree! (%d and %d)\n", m->r1->cofactor, m->r2->cofactor);
      }
      if (!rel_check (m->r2, ns)){
       printf ("relation failed check. [partial, r2]\n");
      }
      multiply_in_lhs (lhs, m->r2, ns);
      add_factors_to_table (factor_counts, m->r2);
      __gmpz_mul_ui (rhs, rhs, m->r1->cofactor);
     }
    }
   }
   int is_good = construct_rhs (factor_counts, rhs, ns);
   if ( ! is_good ) {
    printf ("construct_rhs check failed.\n");
    continue;
   }
   __gmpz_mod (lhs, lhs, ns->N);
   __gmpz_mod (rhs, rhs, ns->N);
   __gmpz_sub (temp, rhs, lhs);
   __gmpz_gcd (temp, temp, ncopy);
   __gmpz_abs (temp, temp);
   if ((__builtin_constant_p (1) && (1) == 0 ? ((temp)->_mp_size < 0 ? -1 : (temp)->_mp_size > 0) : __gmpz_cmp_ui (temp,1)) > 0){
    if (__gmpz_cmp (temp, ns->N) != 0){
     if (__gmpz_divisible_p(ncopy, temp)){
      if (__gmpz_probab_prime_p (temp, 10)){
       __gmpz_out_str (stdout, 10, temp);
       printf (" (prp)\n");
       __gmpz_divexact(ncopy, ncopy, temp);
       if (__gmpz_probab_prime_p (ncopy, 10)){
        __gmpz_out_str(stdout, 10, ncopy);
        printf (" (prp)\n");
        __gmpz_set_ui(ncopy, 1);
       }
       if ((__builtin_constant_p (1) && (1) == 0 ? ((ncopy)->_mp_size < 0 ? -1 : (ncopy)->_mp_size > 0) : __gmpz_cmp_ui (ncopy,1)) == 0){
        __gmpz_clears(lhs, rhs, temp, ncopy, ((void *)0));
        ns->timing.facdeduct_time = clock() - start;
        return;
       }
      }
     }
    }
   }
   __gmpz_clears(lhs, rhs, ((void *)0));
  }
 }
 if ((__builtin_constant_p (1) && (1) == 0 ? ((ncopy)->_mp_size < 0 ? -1 : (ncopy)->_mp_size > 0) : __gmpz_cmp_ui (ncopy,1)) != 0){
  __gmpz_out_str (stdout, 10, ncopy);
  if (__gmpz_probab_prime_p (ncopy, 10)){
   printf (" (prp)\n");
  } else {
   printf (" (c)\n");
  }
 }
 ns->timing.facdeduct_time = clock() - start;
}

variable_types: struct nsieve_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *r1; struct relation *r2; unsigned long *row; } *relns; unsigned int lp_bound; struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation *rel; struct htentry *next; } **buckets; } partials; int nthreads; unsigned long *threads; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; } timing; } *

variable_types: start long

variable_types: hmlen int

variable_types: hmsize int

variable_types:
history
unsigned long *[-1]

variable_types:
rmos
unsigned int [-1]

variable_types: i int

variable_types:
expm
unsigned long *[-1]

variable_types: j int

variable_types: col int

variable_types: pivot int

variable_types: yolanda int

variable_types: row int

variable_types: relct int

variable_types: partialct int

variable_types:
check
unsigned long [-1]

variable_types: relnum int

variable_types: struct matrel_t { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *r1; struct relation *r2; unsigned long *row; } *


repo: albinoBandicoot/nsieve

decompiled_code:
void __fastcall clear_row(__int64 a1, __int64 a2)
{
__int64 v2; // rax

if ( *(_DWORD *)(a2 + 84) )
{
v2 = 0LL;
do
*(_QWORD *)(a1 + 8 * v2++) = 0LL;
while ( *(_DWORD *)(a2 + 84) > (unsigned int)v2 );
}
}

original_code:
void clear_row (uint64_t *m, nsieve_t *ns){
 for (int i=0; i < ns->row_len; i++){
  m[i] = 0;
 }
}

canonical_original_code:
void clear_row(unsigned long *m, struct nsieve_t *ns){
 for (int i = 0; i < ns->row_len; i++){
  m[i] = 0;
 }
}

variable_types:
m
unsigned long *

variable_types: struct nsieve_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *r1; struct relation *r2; unsigned long *row; } *relns; unsigned int lp_bound; struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation *rel; struct htentry *next; } **buckets; } partials; int nthreads; unsigned long *threads; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; } timing; } *

return_type: void

user_defined_types: struct nsieve_t { struct __mpz_struct N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t *relns; unsigned int lp_bound; struct hashtable_t partials; int nthreads; unsigned long *threads; union pthread_mutex_t lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t timing; }

user_defined_types: struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry **buckets; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct matrel_t { struct relation *r1; struct relation *r2; unsigned long *row; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct relation { struct poly_t *poly; int x; unsigned int cofactor; struct flentry *factors; }

user_defined_types: struct poly_t { struct poly_group_t *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; }


original_code:
int get_bit (uint64_t *m, int pos){
 int block = pos/64;
 uint64_t mask = 1ull << (pos % 64);
 return (m[block] & mask) > 0 ? 1 : 0;
}

canonical_original_code:
int get_bit(unsigned long *m, int pos){
 int block = pos/64;
 unsigned long mask = 1ull << (pos % 64);
 return (m[block] & mask) > 0 ? 1 : 0;
}

variable_types: pos int

variable_types: block int

variable_types:
mask
unsigned long

return_type: int


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

result = a2 / 64;
*(_QWORD *)(a1 + 8 * result) ^= 1LL << (a2 % 64);
return result;
}

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

result = a2 / 64;
*(_QWORD *)(a1 + 8 * result) ^= 1LL << (a2 % 64);
return result;
}

original_code:
void flip_bit (uint64_t *m, int pos){
 int block = pos/64;
 uint64_t mask = 1ull << (pos % 64);
 m[block] = m[block] ^ mask;
}

canonical_original_code:
void flip_bit(unsigned long *m, int pos){
 int block = pos/64;
 unsigned long mask = 1ull << (pos % 64);
 m[block] = m[block] ^ mask;
}


original_code:
void xor_row (uint64_t *res, uint64_t *op, int len){
 for (int i=0; i<len; i++){
  res[i] = res[i] ^ op[i];
 }
}

canonical_original_code:
void xor_row(unsigned long *res, unsigned long *op, int len){
 for (int i = 0; i<len; i++){
  res[i] = res[i] ^ op[i];
 }
}

variable_types:
res
unsigned long *

variable_types:
op
unsigned long *

variable_types: len int

variable_types: i int


original_code:
int rightmost_1 (uint64_t *m, int max_i){
 int block = max_i / 64;
 while (block > 0 && m[block] == 0) block--;
 if (m[block] == 0) return -1;
 uint64_t x = m[block];
 int pos = 0;
 while ((x & (1ull << 63)) == 0){
  pos++;
  x = x << 1;
 }
 int res = (63 - pos) + 64 * block;
 return res;
}

canonical_original_code:
int rightmost_1(unsigned long *m, int max_i){
 int block = max_i / 64;
 while (block > 0 && m[block] == 0) block--;
 if (m[block] == 0) return -1;
 unsigned long x = m[block];
 int pos = 0;
 while ((x & (1ull << 63)) == 0){
  pos++;
  x = x << 1;
 }
 int res = (63 - pos) + 64 * block;
 return res;
}

variable_types:
x
unsigned long

variable_types: res int


decompiled_code:
__int64 __fastcall is_zero_vec(_QWORD *a1, int a2)
{
_QWORD *v2; // rax

if ( a2 <= 0 )
return 1LL;
v2 = a1;
while ( !*v2 )
{
if ( ++v2 == &a1[(unsigned int)(a2 - 1) + 1] )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, int a2)
{
_QWORD *v2; // rax

if ( a2 <= 0 )
return 1LL;
v2 = a1;
while ( !*v2 )
{
if ( ++v2 == &a1[(unsigned int)(a2 - 1) + 1] )
return 1LL;
}
return 0LL;
}

original_code:
int is_zero_vec (uint64_t *m, int len){
 for (int i=0; i<len; i++){
  if (m[i] != 0) return 0;
 }
 return 1;
}

canonical_original_code:
int is_zero_vec(unsigned long *m, int len){
 for (int i = 0; i<len; i++){
  if (m[i] != 0) return 0;
 }
 return 1;
}


decompiled_code:
int __fastcall print_row(__int64 a1, int a2)
{
int i; // ebx

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
if ( get_bit(a1, i) )
fputc(49, stderr);
else
fputc(48, stderr);
}
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, int a2)
{
int i; // ebx

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
if ( func1(a1, i) )
fputc(49, stderr);
else
fputc(48, stderr);
}
}
return fputc(10, stderr);
}

original_code:
void print_row (uint64_t *m, int max_i){
 for (int i=0; i<max_i; i++){
  if (get_bit(m, i) == 1){
   fprintf(stderr, "1");
  } else {
   fprintf(stderr, "0");
  }
 }
 fprintf(stderr, "\n");
}

canonical_original_code:
void print_row(unsigned long *m, int max_i){
 for (int i = 0; i<max_i; i++){
  if (get_bit(m, i) == 1){
   fprintf(stderr, "1");
  } else {
   fprintf(stderr, "0");
  }
 }
 fprintf(stderr, "\n");
}


decompiled_code:
void *__fastcall ht_init(__int64 a1)
{
void *result; // rax

*(_DWORD *)(a1 + 104) = 5483;
result = calloc(0x156BuLL, 8uLL);
*(_QWORD *)(a1 + 112) = result;
*(_DWORD *)(a1 + 108) = 0;
return result;
}

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

*(_DWORD *)(a1 + 104) = 5483;
result = calloc(0x156BuLL, 8uLL);
*(_QWORD *)(a1 + 112) = result;
*(_DWORD *)(a1 + 108) = 0;
return result;
}

original_code:
void ht_init (nsieve_t *ns){
 ns->partials.nbuckets = 5483;
 ns->partials.buckets = (ht_entry_t **)(calloc(5483, sizeof(ht_entry_t*)));
 ns->partials.nentries = 0;
}

canonical_original_code:
void ht_init(struct nsieve_t *ns){
 ns->partials.nbuckets = 5483;
 ns->partials.buckets = (struct htentry **)(calloc(5483, sizeof(struct htentry *)));
 ns->partials.nentries = 0;
}

user_defined_types: struct htentry { struct relation *rel; struct htentry *next; }

user_defined_types: struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; }

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

user_defined_types: struct flentry { unsigned int fac; struct flentry *next; }

user_defined_types: struct poly_group_t { struct __mpz_struct a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; }


decompiled_code:
__int64 __fastcall hash_partial(int a1)
{
return (unsigned int)(263633281 * a1 + 135666227);
}

original_code:
uint32_t hash_partial (uint32_t cofactor){
 return (cofactor * 263633281) + 135666227;
}

canonical_original_code:
unsigned int hash_partial(unsigned int cofactor){
 return (cofactor * 263633281) + 135666227;
}

variable_types:
cofactor
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall ht_count_bucket(_QWORD *a1)
{
__int64 result; // rax
int v2; // esi
int v3; // eax
int v4; // ecx
int v5; // edx

result = 0LL;
if ( a1 )
{
v2 = *(_DWORD *)(*a1 + 12LL);
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = *(_DWORD *)(*a1 + 12LL);
if ( v5 == v2 )
{
++v3;
a1 = (_QWORD *)a1[1];
if ( !a1 )
return (unsigned int)(v4 + v3 - 1);
v5 = v2;
}
else
{
v4 = v4 + v3 - 1;
v3 = 0;
}
v2 = v5;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
__int64 result; // rax
int v2; // esi
int v3; // eax
int v4; // ecx
int v5; // edx

result = 0LL;
if ( a1 )
{
v2 = *(_DWORD *)(*a1 + 12LL);
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = *(_DWORD *)(*a1 + 12LL);
if ( v5 == v2 )
{
++v3;
a1 = (_QWORD *)a1[1];
if ( !a1 )
return (unsigned int)(v4 + v3 - 1);
v5 = v2;
}
else
{
v4 = v4 + v3 - 1;
v3 = 0;
}
v2 = v5;
}
}
return result;
}

original_code:
uint32_t ht_count_bucket (ht_entry_t *h){
 if (h == ((void *)0)) return 0;
 uint32_t res = 0;
 uint32_t ct = 0;
 uint32_t curr_cofactor = h->rel->cofactor;
 while (1){
  while (h != ((void *)0) && h->rel->cofactor == curr_cofactor){
   ct ++;
   h = h->next;
  }
  res += ct - 1;
  if (h == ((void *)0)){
   return res;
  }
  curr_cofactor = h->rel->cofactor;
  ct = 0;
 }
 return 0;
}

canonical_original_code:
unsigned int ht_count_bucket(struct htentry *h){
 if (h == ((void *)0)) return 0;
 unsigned int res = 0;
 unsigned int ct = 0;
 unsigned int curr_cofactor = h->rel->cofactor;
 while (1){
  while (h != ((void *)0) && h->rel->cofactor == curr_cofactor){
   ct ++;
   h = h->next;
  }
  res += ct - 1;
  if (h == ((void *)0)){
   return res;
  }
  curr_cofactor = h->rel->cofactor;
  ct = 0;
 }
 return 0;
}

variable_types: struct htentry { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *rel; struct htentry *next; } *

variable_types:
res
unsigned int

variable_types:
ct
unsigned int


decompiled_code:
__int64 __fastcall ht_count(unsigned int *a1)
{
unsigned int v1; // ebp
_QWORD **v2; // rbx
__int64 v3; // r12

v1 = *a1;
if ( *a1 )
{
v2 = (_QWORD **)*((_QWORD *)a1 + 1);
v3 = (__int64)&v2[v1];
v1 = 0;
do
v1 += ht_count_bucket(*v2++);
while ( v2 != (_QWORD **)v3 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1)
{
unsigned int v1; // ebp
_QWORD **v2; // rbx
__int64 v3; // r12

v1 = *a1;
if ( *a1 )
{
v2 = (_QWORD **)*((_QWORD *)a1 + 1);
v3 = (__int64)&v2[v1];
v1 = 0;
do
v1 += func9(*v2++);
while ( v2 != (_QWORD **)v3 );
}
return v1;
}

original_code:
uint32_t ht_count (hashtable_t *ht){
 uint32_t res = 0;
 for (int i=0; i < ht->nbuckets; i++){
  res += ht_count_bucket (ht->buckets[i]);
 }
 return res;
}

canonical_original_code:
unsigned int ht_count(struct hashtable_t *ht){
 unsigned int res = 0;
 for (int i = 0; i < ht->nbuckets; i++){
  res += ht_count_bucket (ht->buckets[i]);
 }
 return res;
}

variable_types: struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *rel; struct htentry *next; } **buckets; } *


original_code:
uint32_t find_root (mpz_t k, uint32_t p){
 mpz_t pol, temp, temp2;
 __gmpz_inits (pol, temp, temp2, ((void *)0));
 __gmpz_fdiv_r_ui (temp, k, p);
 uint32_t a = __gmpz_get_ui (temp);
 if (p == 2){
  return a;
 }
 uint32_t res = 0;
 if (p % 4 == 3){
  uint32_t m = p/4;
  __gmpz_set_ui(pol, p);
  __gmpz_powm_ui (temp, temp, m+1, pol);
  return __gmpz_get_ui (temp);
 } else if (p % 8 == 5){
  uint32_t m = p/8;
  __gmpz_set_ui (pol, p);
  __gmpz_powm_ui (temp2, temp, 2*m+1, pol);
  if ((__builtin_constant_p (1) && (1) == 0 ? ((temp2)->_mp_size < 0 ? -1 : (temp2)->_mp_size > 0) : __gmpz_cmp_ui (temp2,1)) == 0){
   __gmpz_powm_ui(temp2, temp, m+1, pol);
   res = __gmpz_get_ui (temp2);
   __gmpz_clears (pol, temp, temp2, ((void *)0));
   return res;
  } else {
   __gmpz_mul_ui(temp, temp, 4);
   __gmpz_powm_ui(temp2, temp, m+1, pol);
   if (__gmpz_divisible_ui_p(temp2, 2)){
    res = __gmpz_get_ui(temp2)/2;
    __gmpz_clears (pol, temp, temp2, ((void *)0));
    return res;
   } else {
    res = (__gmpz_get_ui(temp2)+p)/2;
    __gmpz_clears (pol, temp, temp2, ((void *)0));
    return res;
   }
  }
 }
 uint32_t s = p-1;
 uint32_t e = 0;
 while (s % 2 == 0){
  s /= 2;
  e ++;
 }
 __gmpz_set_ui (pol, p);
 __gmpz_set_ui(temp2, 2);
 __gmpz_powm_ui (temp, temp2, (p-1)/2, pol);
 while ((__builtin_constant_p (p-1) && (p-1) == 0 ? ((temp)->_mp_size < 0 ? -1 : (temp)->_mp_size > 0) : __gmpz_cmp_ui (temp,p-1)) != 0){
  __gmpz_add_ui (temp2, temp2, 1);
  __gmpz_powm_ui (temp, temp2, (p-1)/2, pol);
 }
 mpz_t x, b, g;
 __gmpz_inits (x, b, g, ((void *)0));
 __gmpz_set_ui (temp, a);
 __gmpz_powm_ui (x, temp, (s+1)/2, pol);
 __gmpz_powm_ui (b, temp, s, pol);
 __gmpz_powm_ui (g, temp2, s, pol);
 uint32_t r = e;
 uint32_t m;
tshanks_mainloop:
 m = 0;
 __gmpz_set (temp, b);
 while ((__builtin_constant_p (1) && (1) == 0 ? ((temp)->_mp_size < 0 ? -1 : (temp)->_mp_size > 0) : __gmpz_cmp_ui (temp,1)) != 0){
  __gmpz_mul (temp, temp, temp);
  __gmpz_mod (temp, temp, pol);
  m++;
 }
 if (m == 0){
  uint32_t res = __gmpz_get_ui (x);
  __gmpz_clears (x, b, g, pol, temp, temp2, ((void *)0));
  return res;
 } else {
  __gmpz_ui_pow_ui (temp, 2, r-m-1);
  __gmpz_powm (temp, g, temp, pol);
  __gmpz_mul (x, x, temp);
  __gmpz_mod (x, x, pol);
  __gmpz_mul (temp, temp, temp);
  __gmpz_mod (temp, temp, pol);
  __gmpz_mul (b, b, temp);
  __gmpz_mod (b, b, pol);
  __gmpz_set (g, temp);
  r = m;
 }
 goto tshanks_mainloop;
 __gmpz_clears (pol, temp, temp2, ((void *)0));
 uint32_t t = 0;
 while ( t*t % p != a && t < p/2 + 1 ){
  t ++;
 }
 if (t*t%p == a) return t;
 return -1;
}

canonical_original_code:
unsigned int find_root(struct __mpz_struct k[1], unsigned int p){
 struct __mpz_struct pol[1]; struct __mpz_struct temp[1]; struct __mpz_struct temp2[1];
 __gmpz_inits (pol, temp, temp2, ((void *)0));
 __gmpz_fdiv_r_ui (temp, k, p);
 unsigned int a = __gmpz_get_ui (temp);
 if (p == 2){
  return a;
 }
 unsigned int res = 0;
 if (p % 4 == 3){
  unsigned int m = p/4;
  __gmpz_set_ui(pol, p);
  __gmpz_powm_ui (temp, temp, m+1, pol);
  return __gmpz_get_ui (temp);
 } else if (p % 8 == 5){
  unsigned int m = p/8;
  __gmpz_set_ui (pol, p);
  __gmpz_powm_ui (temp2, temp, 2*m+1, pol);
  if ((__builtin_constant_p (1) && (1) == 0 ? ((temp2)->_mp_size < 0 ? -1 : (temp2)->_mp_size > 0) : __gmpz_cmp_ui (temp2,1)) == 0){
   __gmpz_powm_ui(temp2, temp, m+1, pol);
   res = __gmpz_get_ui (temp2);
   __gmpz_clears (pol, temp, temp2, ((void *)0));
   return res;
  } else {
   __gmpz_mul_ui(temp, temp, 4);
   __gmpz_powm_ui(temp2, temp, m+1, pol);
   if (__gmpz_divisible_ui_p(temp2, 2)){
    res = __gmpz_get_ui(temp2)/2;
    __gmpz_clears (pol, temp, temp2, ((void *)0));
    return res;
   } else {
    res = (__gmpz_get_ui(temp2)+p)/2;
    __gmpz_clears (pol, temp, temp2, ((void *)0));
    return res;
   }
  }
 }
 unsigned int s = p-1;
 unsigned int e = 0;
 while (s % 2 == 0){
  s /= 2;
  e ++;
 }
 __gmpz_set_ui (pol, p);
 __gmpz_set_ui(temp2, 2);
 __gmpz_powm_ui (temp, temp2, (p-1)/2, pol);
 while ((__builtin_constant_p (p-1) && (p-1) == 0 ? ((temp)->_mp_size < 0 ? -1 : (temp)->_mp_size > 0) : __gmpz_cmp_ui (temp,p-1)) != 0){
  __gmpz_add_ui (temp2, temp2, 1);
  __gmpz_powm_ui (temp, temp2, (p-1)/2, pol);
 }
 struct __mpz_struct x[1]; struct __mpz_struct b[1]; struct __mpz_struct g[1];
 __gmpz_inits (x, b, g, ((void *)0));
 __gmpz_set_ui (temp, a);
 __gmpz_powm_ui (x, temp, (s+1)/2, pol);
 __gmpz_powm_ui (b, temp, s, pol);
 __gmpz_powm_ui (g, temp2, s, pol);
 unsigned int r = e;
 unsigned int m;
tshanks_mainloop:
 m = 0;
 __gmpz_set (temp, b);
 while ((__builtin_constant_p (1) && (1) == 0 ? ((temp)->_mp_size < 0 ? -1 : (temp)->_mp_size > 0) : __gmpz_cmp_ui (temp,1)) != 0){
  __gmpz_mul (temp, temp, temp);
  __gmpz_mod (temp, temp, pol);
  m++;
 }
 if (m == 0){
  unsigned int res = __gmpz_get_ui (x);
  __gmpz_clears (x, b, g, pol, temp, temp2, ((void *)0));
  return res;
 } else {
  __gmpz_ui_pow_ui (temp, 2, r-m-1);
  __gmpz_powm (temp, g, temp, pol);
  __gmpz_mul (x, x, temp);
  __gmpz_mod (x, x, pol);
  __gmpz_mul (temp, temp, temp);
  __gmpz_mod (temp, temp, pol);
  __gmpz_mul (b, b, temp);
  __gmpz_mod (b, b, pol);
  __gmpz_set (g, temp);
  r = m;
 }
 goto tshanks_mainloop;
 __gmpz_clears (pol, temp, temp2, ((void *)0));
 unsigned int t = 0;
 while ( t*t % p != a && t < p/2 + 1 ){
  t ++;
 }
 if (t*t%p == a) return t;
 return -1;
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
p
unsigned int

variable_types:
a
unsigned int

variable_types:
m
unsigned int

variable_types:
s
unsigned int

variable_types:
e
unsigned int

variable_types:
r
unsigned int

variable_types:
t
unsigned int


mod

decompiled_code:
__int64 __fastcall mod(int a1, unsigned int a2)
{
unsigned int v2; // edx

if ( a1 > 0 )
return a1 % a2;
v2 = a2 + a1 % a2;
if ( a2 == v2 )
v2 = 0;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, unsigned int a2)
{
unsigned int v2; // edx

if ( a1 > 0 )
return a1 % a2;
v2 = a2 + a1 % a2;
if ( a2 == v2 )
v2 = 0;
return v2;
}

original_code:
inline uint32_t mod (int32_t x, uint32_t p){
 if (x > 0){
  return x % p;
 } else {
  uint32_t z = p + (x % p);
  if (z == p) return 0;
  return z;
 }
}

canonical_original_code:
inline unsigned int mod(int x, unsigned int p){
 if (x > 0){
  return x % p;
 } else {
  unsigned int z = p + (x % p);
  if (z == p) return 0;
  return z;
 }
}

variable_types: x int

variable_types:
z
unsigned int


decompiled_code:
_BOOL8 __fastcall mpz_fits_64(__int64 a1)
{
return (unsigned __int64)_gmpz_sizeinbase(a1, 2LL) <= 0x3E;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(__int64 a1)
{
return (unsigned __int64)_gmpz_sizeinbase(a1, 2LL) <= 0x3E;
}

original_code:
int mpz_fits_64 (mpz_t a){
 return __gmpz_sizeinbase (a, 2) < 63;
}

canonical_original_code:
int mpz_fits_64(struct __mpz_struct a[1]){
 return __gmpz_sizeinbase (a, 2) < 63;
}


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

if ( (unsigned int)_gmpz_fits_ulong_p() )
result = _gmpz_get_ui(a1);
else
result = _gmpz_getlimbn(a1, 0LL);
return result;
}

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

if ( (unsigned int)_gmpz_fits_ulong_p() )
result = _gmpz_get_ui(a1);
else
result = _gmpz_getlimbn(a1, 0LL);
return result;
}

original_code:
uint64_t mpz_get_64 (mpz_t a){
 if (__gmpz_fits_ulong_p (a)){
  return (uint64_t) __gmpz_get_ui(a);
 }
 uint64_t res = 0;
 if (sizeof(mp_limb_t) == 4){
  res = __gmpz_getlimbn (a, 1);
  res = (res << 32) | __gmpz_getlimbn(a, 0);
 } else {
  res = __gmpz_getlimbn (a, 0);
 }
 return res;
}

canonical_original_code:
unsigned long mpz_get_64(struct __mpz_struct a[1]){
 if (__gmpz_fits_ulong_p (a)){
  return (unsigned long) __gmpz_get_ui(a);
 }
 unsigned long res = 0;
 if (sizeof(mp_limb_t) == 4){
  res = __gmpz_getlimbn (a, 1);
  res = (res << 32) | __gmpz_getlimbn(a, 0);
 } else {
  res = __gmpz_getlimbn (a, 0);
 }
 return res;
}

variable_types:
res
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall fl_check(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = *(_QWORD *)(a1 + 16);
if ( !v2 )
return 1LL;
while ( *(_DWORD *)v2 <= *(_DWORD *)(a2 + 32) )
{
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 1LL;
}
return 0LL;
}

original_code:
int fl_check (rel_t *rel, nsieve_t *ns){
 fl_entry_t *entry = rel->factors;
 while (entry != ((void *)0)){
  if (entry->fac > ns->fb_len){
   return 0;
  }
  entry = entry->next;
 }
 return 1;
}

canonical_original_code:
int fl_check(struct relation *rel, struct nsieve_t *ns){
 struct flentry *entry = rel->factors;
 while (entry != ((void *)0)){
  if (entry->fac > ns->fb_len){
   return 0;
  }
  entry = entry->next;
 }
 return 1;
}

variable_types: struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *

variable_types: struct nsieve_t { struct __mpz_struct N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t { struct relation *r1; struct relation *r2; unsigned long *row; } *relns; unsigned int lp_bound; struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation *rel; struct htentry *next; } **buckets; } partials; int nthreads; unsigned long *threads; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; } timing; } *


decompiled_code:
void __fastcall fl_fillrow(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int *i; // rbx
__int64 v6; // rsi

clear_row(a2, a3);
for ( i = *(unsigned int **)(a1 + 16); i; i = (unsigned int *)*((_QWORD *)i + 1) )
{
v6 = *i;
if ( (unsigned int)v6 > *(_DWORD *)(a3 + 32) + 1 )
printf("WARNING - bad factor: %d\n", v6);
flip_bit(a2, *i);
}
}

canonical_decompiled_code:
void __fastcall func17(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int *i; // rbx
__int64 v6; // rsi

func0(a2, a3);
for ( i = *(unsigned int **)(a1 + 16); i; i = (unsigned int *)*((_QWORD *)i + 1) )
{
v6 = *i;
if ( (unsigned int)v6 > *(_DWORD *)(a3 + 32) + 1 )
printf("WARNING - bad factor: %d\n", v6);
func2(a2, *i);
}
}

original_code:
void fl_fillrow (rel_t *rel, uint64_t *row, nsieve_t *ns){
 clear_row (row, ns);
 fl_entry_t *entry = rel->factors;
 while (entry != ((void *)0)){
  if (entry->fac > ns->fb_len+1){
   printf ("WARNING - bad factor: %d\n", entry->fac);
  }
  flip_bit (row, entry->fac);
  entry = entry->next;
 }
}

canonical_original_code:
void fl_fillrow(struct relation *rel, unsigned long *row, struct nsieve_t *ns){
 clear_row (row, ns);
 struct flentry *entry = rel->factors;
 while (entry != ((void *)0)){
  if (entry->fac > ns->fb_len+1){
   printf ("WARNING - bad factor: %d\n", entry->fac);
  }
  flip_bit (row, entry->fac);
  entry = entry->next;
 }
}

variable_types:
row
unsigned long *

variable_types: struct flentry { unsigned int fac; struct flentry *next; } *


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

v2 = *(_QWORD *)(a1 + 16);
if ( v2 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
result = *(_QWORD *)(a2 + 16);
*(_QWORD *)(v3 + 8) = result;
}
else
{
result = *(_QWORD *)(a2 + 16);
*(_QWORD *)(a1 + 16) = result;
}
return result;
}

original_code:
void fl_concat (rel_t *res, rel_t *victim){
 fl_entry_t *entry = res->factors;
 if (entry == ((void *)0)){
  res->factors = victim->factors;
 } else {
  while (entry->next != ((void *)0)){
   entry = entry->next;
  }
  entry->next = victim->factors;
 }
}

canonical_original_code:
void fl_concat(struct relation *res, struct relation *victim){
 struct flentry *entry = res->factors;
 if (entry == ((void *)0)){
  res->factors = victim->factors;
 } else {
  while (entry->next != ((void *)0)){
   entry = entry->next;
  }
  entry->next = victim->factors;
 }
}

variable_types:
victim
struct relation *


decompiled_code:
void __fastcall rel_free(void *ptr)
{
fl_free((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func19(void *ptr)
{
func15((__int64)ptr);
free(ptr);
}

original_code:
void rel_free (rel_t *rel){
 fl_free (rel);
 free (rel);
}

canonical_original_code:
void rel_free(struct relation *rel){
 fl_free (rel);
 free (rel);
}


decompiled_code:
__int64 __fastcall fb_lookup(unsigned int a1, __int64 a2)
{
int v3; // ecx
int v4; // edx
__int64 v5; // r9
__int64 v6; // rax
unsigned int v7; // esi

v3 = *(_DWORD *)(a2 + 32) - 1;
v4 = v3 / 2;
if ( v3 > 1 )
{
v5 = *(_QWORD *)(a2 + 48);
LODWORD(v6) = 0;
while ( 1 )
{
v7 = *(_DWORD *)(v5 + 4LL * v4);
if ( v7 <= a1 )
{
if ( v7 >= a1 )
return (unsigned int)(v4 + 1);
LODWORD(v6) = v4;
v4 = (v3 + v4) / 2;
}
else
{
v3 = v4;
v4 = ((int)v6 + v4) / 2;
}
if ( v3 - (int)v6 <= 1 )
goto LABEL_10;
}
}
LODWORD(v6) = 0;
LABEL_10:
if ( (int)v6 >= v3 )
return -a1;
v6 = (int)v6;
while ( *(_DWORD *)(*(_QWORD *)(a2 + 48) + 4 * v6) != a1 )
{
if ( v3 <= (int)++v6 )
return -a1;
}
return (unsigned int)(v6 + 1);
}

original_code:
int fb_lookup (uint32_t p, nsieve_t *ns){
 int low = 0;
 int high = ns->fb_len - 1;
 int guess = (low + high)/2;
 while (high - low > 1){
  if (p < ns->fb[guess]){
   high = guess;
   guess = (high + low)/2;
  } else if (p > ns->fb[guess]){
   low = guess;
   guess = (high + low)/2;
  } else {
   return guess + 1;
  }
 }
 for (int i=low; i<high; i++){
  if (p == ns->fb[i]){
   return i+1;
  }
 }
 return -p;
}

canonical_original_code:
int fb_lookup(unsigned int p, struct nsieve_t *ns){
 int low = 0;
 int high = ns->fb_len - 1;
 int guess = (low + high)/2;
 while (high - low > 1){
  if (p < ns->fb[guess]){
   high = guess;
   guess = (high + low)/2;
  } else if (p > ns->fb[guess]){
   low = guess;
   guess = (high + low)/2;
  } else {
   return guess + 1;
  }
 }
 for (int i = low; i<high; i++){
  if (p == ns->fb[i]){
   return i+1;
  }
 }
 return -p;
}

variable_types: struct nsieve_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *r1; struct relation *r2; unsigned long *row; } *relns; unsigned int lp_bound; struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation *rel; struct htentry *next; } **buckets; } partials; int nthreads; unsigned long *threads; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; } timing; } *

variable_types: low int

variable_types: high int

variable_types: guess int

variable_types: i int


decompiled_code:
clock_t __fastcall combine_partials(__int64 a1)
{
clock_t v1; // r12
__int64 v2; // rbx
clock_t result; // rax

v1 = clock();
if ( *(_DWORD *)(a1 + 104) )
{
v2 = 0LL;
do
{
if ( 100 * ((int)v2 / 100) == (_DWORD)v2 )
{
printf("Combining bucket %d\r", (unsigned int)v2);
fflush(stdout);
}
if ( *(_DWORD *)(a1 + 76) >= *(_DWORD *)(a1 + 40) )
break;
combine_bucket(*(_QWORD **)(*(_QWORD *)(a1 + 112) + 8 * v2++), a1);
}
while ( *(_DWORD *)(a1 + 104) > (unsigned int)v2 );
}
result = clock() - v1;
*(_QWORD *)(a1 + 216) = result;
return result;
}

canonical_decompiled_code:
clock_t __fastcall func1(__int64 a1)
{
clock_t v1; // r12
__int64 v2; // rbx
clock_t result; // rax

v1 = clock();
if ( *(_DWORD *)(a1 + 104) )
{
v2 = 0LL;
do
{
if ( 100 * ((int)v2 / 100) == (_DWORD)v2 )
{
printf("Combining bucket %d\r", (unsigned int)v2);
fflush(stdout);
}
if ( *(_DWORD *)(a1 + 76) >= *(_DWORD *)(a1 + 40) )
break;
func0(*(_QWORD **)(*(_QWORD *)(a1 + 112) + 8 * v2++), a1);
}
while ( *(_DWORD *)(a1 + 104) > (unsigned int)v2 );
}
result = clock() - v1;
*(_QWORD *)(a1 + 216) = result;
return result;
}

original_code:
void combine_partials (nsieve_t *ns){
 long start = clock();
 for (int i=0; i < ns->partials.nbuckets; i++){
  if (i % 100 == 0){
   printf("Combining bucket %d\r", i);
   fflush(stdout);
  }
  if (ns->nfull >= ns->rels_needed){
   ns->timing.filter_time = clock() - start;
   return;
  }
  combine_bucket (ns->partials.buckets[i], ns);
 }
 ns->timing.filter_time = clock() - start;
}

canonical_original_code:
void combine_partials(struct nsieve_t *ns){
 long start = clock();
 for (int i = 0; i < ns->partials.nbuckets; i++){
  if (i % 100 == 0){
   printf("Combining bucket %d\r", i);
   fflush(stdout);
  }
  if (ns->nfull >= ns->rels_needed){
   ns->timing.filter_time = clock() - start;
   return;
  }
  combine_bucket (ns->partials.buckets[i], ns);
 }
 ns->timing.filter_time = clock() - start;
}

variable_types: start long


original_code:
void build_matrix (nsieve_t * ns){
 for (int i=0; i < ns->nfull; i++){
  ns->relns[i].row = (uint64_t *) calloc (ns->row_len, 8);
  fl_fillrow (ns->relns[i].r1, ns->relns[i].row, ns);
 }
 combine_partials (ns);
}

canonical_original_code:
void build_matrix(struct nsieve_t *ns){
 for (int i = 0; i < ns->nfull; i++){
  ns->relns[i].row = (unsigned long *) calloc (ns->row_len, 8);
  fl_fillrow (ns->relns[i].r1, ns->relns[i].row, ns);
 }
 combine_partials (ns);
}


filter

decompiled_code:
void filter()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void filter (nsieve_t *ns){
}

canonical_original_code:
void filter(struct nsieve_t *ns){
}


tdiv

decompiled_code:
__int64 __fastcall tdiv(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rbp

while ( 1 )
{
result = __gmpz_divisible_ui_p();
if ( !(_DWORD)result )
break;
__gmpz_divexact_ui();
puts("2");
}
v3 = 3LL;
if ( a2 > 3 )
{
do
{
while ( 1 )
{
result = __gmpz_divisible_ui_p();
if ( !(_DWORD)result )
break;
__gmpz_divexact_ui();
printf("%ld\n", v3);
}
v3 += 2LL;
}
while ( v3 < a2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rbp

while ( 1 )
{
result = __gmpz_divisible_ui_p();
if ( !(_DWORD)result )
break;
__gmpz_divexact_ui();
puts("2");
}
v3 = 3LL;
if ( a2 > 3 )
{
do
{
while ( 1 )
{
result = __gmpz_divisible_ui_p();
if ( !(_DWORD)result )
break;
__gmpz_divexact_ui();
printf("%ld\n", v3);
}
v3 += 2LL;
}
while ( v3 < a2 );
}
return result;
}

original_code:
void tdiv (mpz_t n, int bound){
 while (__gmpz_divisible_ui_p (n, 2)){
  __gmpz_divexact_ui (n, n, 2);
  printf("2\n");
 }
 long t = 3;
 while (t < bound){
  while (__gmpz_divisible_ui_p (n, t)){
   __gmpz_divexact_ui (n, n, t);
   printf("%ld\n", t);
  }
  t += 2;
 }
}

canonical_original_code:
void tdiv(struct __mpz_struct n[1], int bound){
 while (__gmpz_divisible_ui_p (n, 2)){
  __gmpz_divexact_ui (n, n, 2);
  printf("2\n");
 }
 long t = 3;
 while (t < bound){
  while (__gmpz_divisible_ui_p (n, t)){
   __gmpz_divexact_ui (n, n, t);
   printf("%ld\n", t);
  }
  t += 2;
 }
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types: bound int

variable_types: t long


rho

decompiled_code:
__int64 __fastcall rho(__int64 a1, int a2)
{
__int64 result; // rax
int i; // er12
int v4; // ebp

__gmpz_inits();
__gmpz_set_ui();
result = __gmpz_set_ui();
if ( a2 )
{
for ( i = 0; ; ++i )
{
__gmpz_set_ui();
v4 = 128;
do
{
__gmpz_mul();
__gmpz_add_ui();
__gmpz_mod();
__gmpz_mul();
__gmpz_add_ui();
__gmpz_mul();
__gmpz_add_ui();
__gmpz_mod();
__gmpz_sub();
__gmpz_mul();
__gmpz_mod();
--v4;
}
while ( v4 );
__gmpz_gcd();
if ( (unsigned int)__gmpz_cmp_ui() )
{
if ( (unsigned int)__gmpz_probab_prime_p() )
{
__gmpz_out_str();
putchar(10);
}
else
{
__gmpz_out_str();
puts(" (composite)");
}
__gmpz_divexact();
if ( !(unsigned int)__gmpz_cmp_ui() )
return __gmpz_clears();
if ( (unsigned int)__gmpz_probab_prime_p() )
break;
}
result = (unsigned int)(i + 1);
if ( i == (unsigned int)(a2 - 1) >> 7 )
return result;
}
__gmpz_out_str();
putchar(10);
result = __gmpz_clears();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
__int64 result; // rax
int i; // er12
int v4; // ebp

__gmpz_inits();
__gmpz_set_ui();
result = __gmpz_set_ui();
if ( a2 )
{
for ( i = 0; ; ++i )
{
__gmpz_set_ui();
v4 = 128;
do
{
__gmpz_mul();
__gmpz_add_ui();
__gmpz_mod();
__gmpz_mul();
__gmpz_add_ui();
__gmpz_mul();
__gmpz_add_ui();
__gmpz_mod();
__gmpz_sub();
__gmpz_mul();
__gmpz_mod();
--v4;
}
while ( v4 );
__gmpz_gcd();
if ( (unsigned int)__gmpz_cmp_ui() )
{
if ( (unsigned int)__gmpz_probab_prime_p() )
{
__gmpz_out_str();
putchar(10);
}
else
{
__gmpz_out_str();
puts(" (composite)");
}
__gmpz_divexact();
if ( !(unsigned int)__gmpz_cmp_ui() )
return __gmpz_clears();
if ( (unsigned int)__gmpz_probab_prime_p() )
break;
}
result = (unsigned int)(i + 1);
if ( i == (unsigned int)(a2 - 1) >> 7 )
return result;
}
__gmpz_out_str();
putchar(10);
result = __gmpz_clears();
}
return result;
}

original_code:
void rho (mpz_t n, unsigned int steps, int printrem){
 mpz_t x, y, g, temp;
 __gmpz_inits (x, y, g, temp, ((void *)0));
 __gmpz_set_ui (x, 2);
 __gmpz_set_ui (y, 2);
 int ct = 0;
 while (ct < steps){
  __gmpz_set_ui (g, 1);
  for (int i=0; i < 128; i++){
   __gmpz_mul (temp, x, x);
   __gmpz_add_ui (temp, temp, 1);
   __gmpz_mod (x, temp, n);
   __gmpz_mul (temp, y, y);
   __gmpz_add_ui (temp, temp, 1);
   __gmpz_mul (y, temp, temp);
   __gmpz_add_ui (temp, y, 1);
   __gmpz_mod (y, temp, n);
   __gmpz_sub (temp, x, y);
   __gmpz_mul (g, g, temp);
   __gmpz_mod (g, g, n);
  }
  __gmpz_gcd (g, g, n);
  if ((__builtin_constant_p (1) && (1) == 0 ? ((g)->_mp_size < 0 ? -1 : (g)->_mp_size > 0) : __gmpz_cmp_ui (g,1)) != 0){
   if (__gmpz_probab_prime_p (g, 12)){
    __gmpz_out_str (stdout, 10, g);
    printf("\n");
    __gmpz_divexact (n, n, g);
   } else {
    __gmpz_out_str (stdout, 10, g);
    printf (" (composite)\n");
    __gmpz_divexact (n, n, g);
   }
   if ((__builtin_constant_p (1) && (1) == 0 ? ((n)->_mp_size < 0 ? -1 : (n)->_mp_size > 0) : __gmpz_cmp_ui (n,1)) == 0){
    __gmpz_clears (x, y, g, temp, ((void *)0));
    return;
   }
   if (__gmpz_probab_prime_p (n, 12)){
    __gmpz_out_str (stdout, 10, n);
    printf ("\n");
    __gmpz_clears (x, y, g, temp, ((void *)0));
    return;
   }
  }
  ct += 128;
 }
}

canonical_original_code:
void rho(struct __mpz_struct n[1], unsigned int steps, int printrem){
 struct __mpz_struct x[1]; struct __mpz_struct y[1]; struct __mpz_struct g[1]; struct __mpz_struct temp[1];
 __gmpz_inits (x, y, g, temp, ((void *)0));
 __gmpz_set_ui (x, 2);
 __gmpz_set_ui (y, 2);
 int ct = 0;
 while (ct < steps){
  __gmpz_set_ui (g, 1);
  for (int i = 0; i < 128; i++){
   __gmpz_mul (temp, x, x);
   __gmpz_add_ui (temp, temp, 1);
   __gmpz_mod (x, temp, n);
   __gmpz_mul (temp, y, y);
   __gmpz_add_ui (temp, temp, 1);
   __gmpz_mul (y, temp, temp);
   __gmpz_add_ui (temp, y, 1);
   __gmpz_mod (y, temp, n);
   __gmpz_sub (temp, x, y);
   __gmpz_mul (g, g, temp);
   __gmpz_mod (g, g, n);
  }
  __gmpz_gcd (g, g, n);
  if ((__builtin_constant_p (1) && (1) == 0 ? ((g)->_mp_size < 0 ? -1 : (g)->_mp_size > 0) : __gmpz_cmp_ui (g,1)) != 0){
   if (__gmpz_probab_prime_p (g, 12)){
    __gmpz_out_str (stdout, 10, g);
    printf("\n");
    __gmpz_divexact (n, n, g);
   } else {
    __gmpz_out_str (stdout, 10, g);
    printf (" (composite)\n");
    __gmpz_divexact (n, n, g);
   }
   if ((__builtin_constant_p (1) && (1) == 0 ? ((n)->_mp_size < 0 ? -1 : (n)->_mp_size > 0) : __gmpz_cmp_ui (n,1)) == 0){
    __gmpz_clears (x, y, g, temp, ((void *)0));
    return;
   }
   if (__gmpz_probab_prime_p (n, 12)){
    __gmpz_out_str (stdout, 10, n);
    printf ("\n");
    __gmpz_clears (x, y, g, temp, ((void *)0));
    return;
   }
  }
  ct += 128;
 }
}

variable_types:
steps
unsigned int

variable_types: printrem int

variable_types: ct int


crear

original_code:
void crear(servidor* lista){
    strcpy(lista->nombre,"NIL");
    strcpy(lista->dns,"NIL");
    lista->puerto = 0;
    lista->tiempoRespuesta = 0;
    lista->siguiente = ((void *)0);
}

canonical_original_code:
void crear(struct servidor *lista){
    strcpy(lista->nombre,"NIL");
    strcpy(lista->dns,"NIL");
    lista->puerto = 0;
    lista->tiempoRespuesta = 0;
    lista->siguiente = ((void *)0);
}

variable_types: struct servidor { char nombre[128]; char dns[128]; int puerto; int tiempoRespuesta; struct servidor *siguiente; } *


inicializar

decompiled_code:
char *__fastcall inicializar(char *src, char *a2, int a3, __int64 a4)
{
char *result; // rax

strcpy((char *)a4, src);
result = strcpy((char *)(a4 + 128), a2);
*(_DWORD *)(a4 + 256) = a3;
*(_DWORD *)(a4 + 260) = 0;
*(_QWORD *)(a4 + 264) = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *src, char *a2, int a3, __int64 a4)
{
char *result; // rax

strcpy((char *)a4, src);
result = strcpy((char *)(a4 + 128), a2);
*(_DWORD *)(a4 + 256) = a3;
*(_DWORD *)(a4 + 260) = 0;
*(_QWORD *)(a4 + 264) = 0LL;
return result;
}

original_code:
void inicializar(char* nombre, char* dns, int puerto, servidor* lista){
    strcpy(lista->nombre,nombre);
    strcpy(lista->dns,dns);
    lista->puerto = puerto;
    lista->tiempoRespuesta = 0;
    lista->siguiente = ((void *)0);
}

canonical_original_code:
void inicializar(char *nombre, char *dns, int puerto, struct servidor *lista){
    strcpy(lista->nombre,nombre);
    strcpy(lista->dns,dns);
    lista->puerto = puerto;
    lista->tiempoRespuesta = 0;
    lista->siguiente = ((void *)0);
}

variable_types:
nombre
char *

variable_types:
dns
char *

variable_types: puerto int

user_defined_types: struct servidor { char nombre[128]; char dns[128]; int puerto; int tiempoRespuesta; struct servidor *siguiente; }


insertar

decompiled_code:
char *__fastcall insertar(const char *a1, __int64 a2)
{
const char *v2; // rax
const char *v3; // rbx
void *v4; // r12
char *result; // rax

v2 = a1;
if ( !strcmp(a1, "NIL") )
return inicializar((char *)a2, (char *)(a2 + 128), *(_DWORD *)(a2 + 256), (__int64)a1);
do
{
v3 = v2;
v2 = (const char *)*((_QWORD *)v2 + 33);
}
while ( v2 );
v4 = malloc(0x110uLL);
result = inicializar((char *)a2, (char *)(a2 + 128), *(_DWORD *)(a2 + 256), (__int64)v4);
*((_QWORD *)v3 + 33) = v4;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1, __int64 a2)
{
const char *v2; // rax
const char *v3; // rbx
void *v4; // r12
char *result; // rax

v2 = a1;
if ( !strcmp(a1, "NIL") )
return func1((char *)a2, (char *)(a2 + 128), *(_DWORD *)(a2 + 256), (__int64)a1);
do
{
v3 = v2;
v2 = (const char *)*((_QWORD *)v2 + 33);
}
while ( v2 );
v4 = malloc(0x110uLL);
result = func1((char *)a2, (char *)(a2 + 128), *(_DWORD *)(a2 + 256), (__int64)v4);
*((_QWORD *)v3 + 33) = v4;
return result;
}

original_code:
void insertar(servidor* lista, servidor* servNuevo){
    servidor *temp = lista;
    if(strcmp(temp->nombre,"NIL")!=0){
        while(temp->siguiente != ((void *)0)){
            temp = temp->siguiente;
        }
        servidor *ele = (servidor *) malloc(sizeof(servidor));
        inicializar(servNuevo->nombre,servNuevo->dns,servNuevo->puerto,ele);
        temp->siguiente = ele;
    }else{
        inicializar(servNuevo->nombre,servNuevo->dns,servNuevo->puerto,lista);
    }
}

canonical_original_code:
void insertar(struct servidor *lista, struct servidor *servNuevo){
    struct servidor *temp = lista;
    if(strcmp(temp->nombre,"NIL")!=0){
        while(temp->siguiente != ((void *)0)){
            temp = temp->siguiente;
        }
        struct servidor *ele = (servidor *) malloc(sizeof(servidor));
        inicializar(servNuevo->nombre,servNuevo->dns,servNuevo->puerto,ele);
        temp->siguiente = ele;
    }else{
        inicializar(servNuevo->nombre,servNuevo->dns,servNuevo->puerto,lista);
    }
}

variable_types:
servNuevo
struct servidor *


imprimir

decompiled_code:
int __fastcall imprimir(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

v1 = a1;
for ( result = puts("Lista de Centros de Servicio:"); v1; v1 = *(_QWORD *)(v1 + 264) )
{
printf("Nombre centro: %s\n", (const char *)v1);
printf("DNS: %s\n", (const char *)(v1 + 128));
printf("Puerto: %d\n", *(unsigned int *)(v1 + 256));
printf("Tiempo de Respuesta: %d\n", *(unsigned int *)(v1 + 260));
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

v1 = a1;
for ( result = puts("Lista de Centros de Servicio:"); v1; v1 = *(_QWORD *)(v1 + 264) )
{
printf("Nombre centro: %s\n", (const char *)v1);
printf("DNS: %s\n", (const char *)(v1 + 128));
printf("Puerto: %d\n", *(unsigned int *)(v1 + 256));
printf("Tiempo de Respuesta: %d\n", *(unsigned int *)(v1 + 260));
result = putchar(10);
}
return result;
}

original_code:
void imprimir(servidor* lista){
    servidor *aux = lista;
    printf("Lista de Centros de Servicio:\n");
    while(aux != ((void *)0)){
        printf("Nombre centro: %s\n",aux->nombre);
        printf("DNS: %s\n",aux->dns);
        printf("Puerto: %d\n",aux->puerto);
        printf("Tiempo de Respuesta: %d\n",aux->tiempoRespuesta);
        printf("\n");
        aux = aux->siguiente;
    }
}

canonical_original_code:
void imprimir(struct servidor *lista){
    struct servidor *aux = lista;
    printf("Lista de Centros de Servicio:\n");
    while(aux != ((void *)0)){
        printf("Nombre centro: %s\n",aux->nombre);
        printf("DNS: %s\n",aux->dns);
        printf("Puerto: %d\n",aux->puerto);
        printf("Tiempo de Respuesta: %d\n",aux->tiempoRespuesta);
        printf("\n");
        aux = aux->siguiente;
    }
}


ordenarPorTiempo

decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall ordenarPorTiempo(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 result; // rax

v1 = a1;
v2 = *(_QWORD *)(a1 + 264);
if ( v2 )
{
while ( 1 )
{
result = *(unsigned int *)(v2 + 260);
if ( *(_DWORD *)(v1 + 260) > (int)result )
{
inicializar((char *)v1, (char *)(v1 + 128), *(_DWORD *)(v1 + 256), 0LL);
loc_104 = *(_DWORD *)(v1 + 260);
strcpy((char *)v1, (const char *)v2);
strcpy((char *)(v1 + 128), (const char *)(v2 + 128));
*(_DWORD *)(v1 + 256) = *(_DWORD *)(v2 + 256);
*(_DWORD *)(v1 + 260) = *(_DWORD *)(v2 + 260);
strcpy((char *)v2, 0LL);
strcpy((char *)(v2 + 128), (const char *)&loc_80);
*(_DWORD *)(v2 + 256) = *(_DWORD *)((char *)&loc_FF + 1);
result = loc_104;
*(_DWORD *)(v2 + 260) = loc_104;
}
v2 = *(_QWORD *)(v2 + 264);
if ( !v2 )
{
v1 = *(_QWORD *)(v1 + 264);
v2 = *(_QWORD *)(v1 + 264);
if ( !v2 )
break;
}
}
}
return result;
}

original_code:
void ordenarPorTiempo(servidor* lista){
    servidor *aux = lista;
    servidor *cont;
    for(; aux->siguiente != ((void *)0); aux = aux->siguiente){
        for(cont = aux->siguiente; cont != ((void *)0); cont = cont->siguiente){
            if(aux->tiempoRespuesta > cont->tiempoRespuesta){
                servidor *temp;
                inicializar(aux->nombre,aux->dns,aux->puerto,temp);
                temp->tiempoRespuesta = aux->tiempoRespuesta;
                strcpy(aux->nombre,cont->nombre);
                strcpy(aux->dns,cont->dns);
                aux->puerto = cont->puerto;
                aux->tiempoRespuesta = cont->tiempoRespuesta;
                strcpy(cont->nombre,temp->nombre);
                strcpy(cont->dns,temp->dns);
                cont->puerto = temp->puerto;
                cont->tiempoRespuesta = temp->tiempoRespuesta;
            }
        }
    }
}

canonical_original_code:
void ordenarPorTiempo(struct servidor *lista){
    struct servidor *aux = lista;
    struct servidor *cont;
    for(; aux->siguiente != ((void *)0); aux = aux->siguiente){
        for(cont = aux->siguiente; cont != ((void *)0); cont = cont->siguiente){
            if(aux->tiempoRespuesta > cont->tiempoRespuesta){
                struct servidor *temp;
                inicializar(aux->nombre,aux->dns,aux->puerto,temp);
                temp->tiempoRespuesta = aux->tiempoRespuesta;
                strcpy(aux->nombre,cont->nombre);
                strcpy(aux->dns,cont->dns);
                aux->puerto = cont->puerto;
                aux->tiempoRespuesta = cont->tiempoRespuesta;
                strcpy(cont->nombre,temp->nombre);
                strcpy(cont->dns,temp->dns);
                cont->puerto = temp->puerto;
                cont->tiempoRespuesta = temp->tiempoRespuesta;
            }
        }
    }
}


abrirConexion

decompiled_code:
__int64 __fastcall abrirConexion(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
v4.sa_family = 2;
*(_WORD *)v4.sa_data = a1;
*(_DWORD *)&v4.sa_data[2] = 0;
if ( bind(v1, &v4, 0x10u) < 0 )
{
close(v2);
v2 = -2;
}
else if ( listen(v2, 5) < 0 )
{
close(v2);
v2 = -3;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
v4.sa_family = 2;
*(_WORD *)v4.sa_data = a1;
*(_DWORD *)&v4.sa_data[2] = 0;
if ( bind(v1, &v4, 0x10u) < 0 )
{
close(v2);
v2 = -2;
}
else if ( listen(v2, 5) < 0 )
{
close(v2);
v2 = -3;
}
return v2;
}

original_code:
int abrirConexion(int puerto)
{
    struct sockaddr_in direccion;
    int descriptorS;
    descriptorS = socket (2, SOCK_STREAM, 0);
    if (descriptorS < 0){
        return -1;
    }
    direccion.sin_family = 2;
    direccion.sin_port = puerto;
    direccion.sin_addr.s_addr =((in_addr_t) 0x00000000);
    if( bind(descriptorS, (struct sockaddr *)&direccion, sizeof(direccion)) < 0){
        close(descriptorS);
        return -2;
    }
    if (listen(descriptorS, 5) < 0){
        close (descriptorS);
        return -3;
    }
    return descriptorS;
}

canonical_original_code:
int abrirConexion(int puerto)
{
    struct sockaddr_in direccion;
    int descriptorS;
    descriptorS = socket (2, SOCK_STREAM, 0);
    if (descriptorS < 0){
        return -1;
    }
    direccion.sin_family = 2;
    direccion.sin_port = puerto;
    direccion.sin_addr.s_addr =((unsigned int) 0x00000000);
    if( bind(descriptorS, (struct sockaddr *)&direccion, sizeof(direccion)) < 0){
        close(descriptorS);
        return -2;
    }
    if (listen(descriptorS, 5) < 0){
        close (descriptorS);
        return -3;
    }
    return descriptorS;
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: descriptorS int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


aceptarConexion

decompiled_code:
int __fastcall aceptarConexion(int a1)
{
int result; // eax
struct sockaddr v2; // [rsp+0h] [rbp-28h] BYREF
socklen_t addr_len[3]; // [rsp+1Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
result = accept(a1, &v2, addr_len);
if ( result < 0 )
result = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
int result; // eax
struct sockaddr v2; // [rsp+0h] [rbp-28h] BYREF
socklen_t addr_len[3]; // [rsp+1Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
result = accept(a1, &v2, addr_len);
if ( result < 0 )
result = -1;
return result;
}

original_code:
int aceptarConexion(int descriptor)
{
    socklen_t logintudCliente;
    struct sockaddr cliente;
    int dSocket;
    logintudCliente = sizeof(cliente);
    dSocket = accept(descriptor, &cliente, &logintudCliente);
    if(dSocket < 0) {
        return -1;
    }
    return dSocket;
}

canonical_original_code:
int aceptarConexion(int descriptor)
{
    unsigned int logintudCliente;
    struct sockaddr cliente;
    int dSocket;
    logintudCliente = sizeof(cliente);
    dSocket = accept(descriptor, &cliente, &logintudCliente);
    if(dSocket < 0) {
        return -1;
    }
    return dSocket;
}

variable_types: descriptor int

variable_types:
logintudCliente
unsigned int

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

variable_types: dSocket int


escribirSocket

decompiled_code:
__int64 __fastcall escribirSocket(int fd, void *buf)
{
size_t v2; // rax
int v3; // edx
__int64 result; // rax

v2 = strlen((const char *)buf);
v3 = write(fd, buf, v2);
result = 1LL;
if ( v3 < 0 )
result = (unsigned int)*_errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, void *buf)
{
size_t v2; // rax
int v3; // edx
__int64 result; // rax

v2 = strlen((const char *)buf);
v3 = write(fd, buf, v2);
result = 1LL;
if ( v3 < 0 )
result = (unsigned int)*_errno_location();
return result;
}

original_code:
int escribirSocket(int descriptor, char *datos)
{
    int n;
    n =write(descriptor,datos,strlen(datos));
    if (n < 0) {
        return (*__errno_location ());
    } else {
        return 1;
    }
}

variable_types:
datos
char *

variable_types: n int


fatalerror

decompiled_code:
void __fastcall __noreturn fatalerror(const char *a1, int a2)
{
fprintf(stderr, "%s: %s\n", (const char *)programname, a1);
fflush(stdout);
exit(a2);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1, int a2)
{
fprintf(stderr, "%s: %s\n", (const char *)programname, a1);
fflush(stdout);
exit(a2);
}

original_code:
void fatalerror(char *message, int errortype) {
  fprintf(stderr, "%s: %s\n", programname, message);
  fflush(stdout);
  exit(errortype);
}

variable_types:
message
char *

variable_types: errortype int


trim

decompiled_code:
char *__fastcall trim(char *s)
{
__int64 v2; // rbx
int v3; // eax
__int64 v4; // rdx

while ( isspace(*s) )
++s;
v2 = (int)(strlen(s) - 1);
do
{
v3 = isspace(s[v2]);
v4 = v2--;
}
while ( v3 );
s[v4 + 1] = 0;
return s;
}

canonical_decompiled_code:
char *__fastcall func2(char *s)
{
__int64 v2; // rbx
int v3; // eax
__int64 v4; // rdx

while ( isspace(*s) )
++s;
v2 = (int)(strlen(s) - 1);
do
{
v3 = isspace(s[v2]);
v4 = v2--;
}
while ( v3 );
s[v4 + 1] = 0;
return s;
}

original_code:
char* trim(char *cadena){
    int i;
    while(isspace(*cadena)){
        cadena++;
    }
    for (i = strlen(cadena)- 1; (isspace(cadena[i])); i--) ;
    cadena[i + 1] = '\0';
    return cadena;
}

canonical_original_code:
char *trim(char *cadena){
    int i;
    while(isspace(*cadena)){
        cadena++;
    }
    for (i = strlen(cadena)- 1; (isspace(cadena[i])); i--) ;
    cadena[i + 1] = '\0';
    return cadena;
}

variable_types:
cadena
char *

variable_types: i int

return_type: char *


crearConexion

decompiled_code:
__int64 __fastcall crearConexion(char *name, __int16 a2)
{
struct hostent *v2; // rax
struct hostent *v3; // rbx
int v4; // ebx
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

puts("intentando conectarme");
v2 = gethostbyname(name);
if ( v2 )
{
v3 = v2;
printf("intentando conectarme 1: %d\n", v2);
v6.sa_family = 2;
*(_DWORD *)&v6.sa_data[2] = **(_DWORD **)v3->h_addr_list;
*(_WORD *)v6.sa_data = a2;
v4 = socket(2, 1, 0);
if ( v4 < 0 )
{
v4 = -2;
}
else
{
puts("intentando conectarme 2");
if ( connect(v4, &v6, 0x10u) < 0 )
v4 = -3;
else
printf("conexion %d\n", (unsigned int)v4);
}
}
else
{
v4 = -1;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *name, __int16 a2)
{
struct hostent *v2; // rax
struct hostent *v3; // rbx
int v4; // ebx
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

puts("intentando conectarme");
v2 = gethostbyname(name);
if ( v2 )
{
v3 = v2;
printf("intentando conectarme 1: %d\n", v2);
v6.sa_family = 2;
*(_DWORD *)&v6.sa_data[2] = **(_DWORD **)v3->h_addr_list;
*(_WORD *)v6.sa_data = a2;
v4 = socket(2, 1, 0);
if ( v4 < 0 )
{
v4 = -2;
}
else
{
puts("intentando conectarme 2");
if ( connect(v4, &v6, 0x10u) < 0 )
v4 = -3;
else
printf("conexion %d\n", (unsigned int)v4);
}
}
else
{
v4 = -1;
}
return (unsigned int)v4;
}

original_code:
int crearConexion(char *nombre_host, int puerto){
    struct sockaddr_in direccionHost;
    struct hostent *host;
    int descSocket;
    host = ((void *)0);
    printf("intentando conectarme\n");
    host = gethostbyname (nombre_host);
    if (host == ((void *)0)) {
        return -1;
    }
    printf("intentando conectarme 1: %d\n",host);
    direccionHost.sin_family = 2;
    direccionHost.sin_addr.s_addr = ((struct in_addr *)(host->h_addr_list[0]))->s_addr;
    direccionHost.sin_port = puerto;
    descSocket = socket (2, SOCK_STREAM, 0);
    if (descSocket < 0){
        return -2;
    }
    printf("intentando conectarme 2\n");
    if (connect (descSocket,(struct sockaddr *)&direccionHost, sizeof (direccionHost)) < 0){
        return -3;
    }
    printf("conexion %d\n",descSocket);
    return descSocket;
}

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: descSocket int


escribeSocket

decompiled_code:
_BOOL8 __fastcall escribeSocket(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
return (int)write(fd, buf, v2) >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
return (int)write(fd, buf, v2) >= 0;
}

original_code:
int escribeSocket(int descriptor, char *mensaje){
    int n;
    n = write(descriptor,mensaje,strlen(mensaje));
    if (n < 0) {
        return 0;
    } else {
        return 1;
    }
}

variable_types:
mensaje
char *


escribirSocket

canonical_original_code:
int escribirSocket(int descriptor, char *datos)
{
    int n;
    n =write(descriptor,datos,strlen(datos));
    if (n < 0) {
        return (*__errno_location ());
    } else {
        return 1;
    }
}


makeTransientImg

repo: alebugariu/egioc

decompiled_code:
__int64 __fastcall makeTransientImg(unsigned int *a1)
{
unsigned int i; // er13
__int64 result; // rax
unsigned int j; // ebx

for ( i = 0; a1[1] > i; ++i )
{
for ( j = 0; *a1 > j; ++j )
result = putXPMpixel((__int64)a1, j, i, j);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int *a1)
{
unsigned int i; // er13
__int64 result; // rax
unsigned int j; // ebx

for ( i = 0; a1[1] > i; ++i )
{
for ( j = 0; *a1 > j; ++j )
result = func8((__int64)a1, j, i, j);
}
return result;
}

original_code:
void
makeTransientImg(XPM *img){
 int ypix = 0;
 int xpix = 0;
 int colIndex = 0;
 for(ypix = 0; ypix < img->height; ++ypix){
  colIndex = 0;
  for(xpix = 0; xpix < img->width; ++xpix){
   putXPMpixel(img, xpix, ypix, colIndex);
   colIndex ++;
  }
 }
}

canonical_original_code:
void makeTransientImg(struct XPM *img){
 int ypix = 0;
 int xpix = 0;
 int colIndex = 0;
 for(ypix = 0; ypix < img->height; ++ypix){
  colIndex = 0;
  for(xpix = 0; xpix < img->width; ++xpix){
   putXPMpixel(img, xpix, ypix, colIndex);
   colIndex ++;
  }
 }
}

variable_types: struct XPM { unsigned int width; unsigned int height; unsigned short chrperpixel; unsigned int ncolors; struct XPMColor { struct Color { unsigned short red; unsigned short green; unsigned short blue; } clr; char *chars; char *key; } *colta; unsigned short **data; } *

variable_types: ypix int

variable_types: xpix int

variable_types: colIndex int

user_defined_types: struct XPM { unsigned int width; unsigned int height; unsigned short chrperpixel; unsigned int ncolors; struct XPMColor *colta; unsigned short **data; }

user_defined_types: struct XPMColor { struct Color clr; char *chars; char *key; }


assignColorTable

original_code:
void
assignColorTable(XPM *img){
 XPMColor clrData;
 unsigned short clrIndex = 0;
 clrData.clr.blue = 0;
 clrData.clr.green = 0;
 clrData.clr.red = 0;
 for(clrIndex = 0; clrIndex < img->ncolors; ++clrIndex){
  clrData.key = (char *)malloc(sizeof(char) + 1);
  strcpy(clrData.key, "c");
  clrData.chars = (char *)malloc(img->chrperpixel * sizeof(char));
  sprintf(clrData.chars, "%02X", clrIndex);
  setXPMColor(img, clrIndex, clrData);
  clrData.clr.red += 255/img->ncolors;
 }
}

canonical_original_code:
void assignColorTable(struct XPM *img){
 struct XPMColor clrData;
 unsigned short clrIndex = 0;
 clrData.clr.blue = 0;
 clrData.clr.green = 0;
 clrData.clr.red = 0;
 for(clrIndex = 0; clrIndex < img->ncolors; ++clrIndex){
  clrData.key = (char *)malloc(sizeof(char) + 1);
  strcpy(clrData.key, "c");
  clrData.chars = (char *)malloc(img->chrperpixel * sizeof(char));
  sprintf(clrData.chars, "%02X", clrIndex);
  setXPMColor(img, clrIndex, clrData);
  clrData.clr.red += 255/img->ncolors;
 }
}

variable_types: struct XPMColor { struct Color { unsigned short red; unsigned short green; unsigned short blue; } clr; char *chars; char *key; }

variable_types:
clrIndex
unsigned short


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v4; // [rsp+8h] [rbp-10h] BYREF

v4 = newXPM(0x32u, 0x32u, 2, 0x32u);
assignColorTable((__int64)v4);
makeTransientImg(v4);
saveXPMtofile(v4, "tema1.xpm");
freeXPM((void **)&v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v4; // [rsp+8h] [rbp-10h] BYREF

v4 = newXPM(0x32u, 0x32u, 2, 0x32u);
func11((__int64)v4);
func12(v4);
func10(v4, "tema1.xpm");
func7((void **)&v4);
return 0;
}

original_code:
int
main(int argc, char *argv[]){
 XPM *img = newXPM(50, 50, 2, 50);
 assignColorTable(img);
 makeTransientImg(img);
 saveXPMtofile(img, "tema1.xpm");
 freeXPM(&img);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 struct XPM *img = newXPM(50, 50, 2, 50);
 assignColorTable(img);
 makeTransientImg(img);
 saveXPMtofile(img, "tema1.xpm");
 freeXPM(&img);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

user_defined_types: struct Color { unsigned short red; unsigned short green; unsigned short blue; }


degToRad

decompiled_code:
double __fastcall degToRad(int a1)
{
return (double)a1 * 3.14159265 / 180.0;
}

canonical_decompiled_code:
double __fastcall func1(int a1)
{
return (double)a1 * 3.14159265 / 180.0;
}

original_code:
double degToRad(int angle)
{
 return angle * 3.14159265/180;
}

variable_types: angle int

return_type: double


initTranslation

original_code:
void initTranslation(struct transMatrix * m, int tx, int ty)
{
  m->matrix[0][0] = 1; m->matrix[0][1] = 0; m->matrix[0][2] = tx;
  m->matrix[1][0] = 0; m->matrix[1][1] = 1; m->matrix[1][2] = ty;
  m->matrix[2][0] = 0; m->matrix[2][1] = 0; m->matrix[2][2] = 1;
}

canonical_original_code:
void initTranslation(struct transMatrix *m, int tx, int ty)
{
  m->matrix[0][0] = 1; m->matrix[0][1] = 0; m->matrix[0][2] = tx;
  m->matrix[1][0] = 0; m->matrix[1][1] = 1; m->matrix[1][2] = ty;
  m->matrix[2][0] = 0; m->matrix[2][1] = 0; m->matrix[2][2] = 1;
}

variable_types: struct transMatrix { double matrix[3][3]; } *

variable_types: tx int

variable_types: ty int


initRotation

decompiled_code:
__int64 __fastcall initRotation(__int64 a1, int a2)
{
double v2; // xmm0_8
__int64 v3; // xmm0_8
double v4; // xmm1_8
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

v2 = degToRad(a2);
sincos(v2, sinx, (double *)&v6);
v3 = v6;
v4 = sinx[0];
*(_QWORD *)a1 = v6;
*(_OWORD *)(a1 + 8) = *(_QWORD *)&v4 ^ (unsigned __int64)LC9;
*(double *)(a1 + 24) = v4;
*(_QWORD *)(a1 + 32) = v3;
*(_QWORD *)(a1 + 40) = 0LL;
*(_QWORD *)(a1 + 48) = 0LL;
*(_QWORD *)(a1 + 56) = 0LL;
result = LC7;
*(_QWORD *)(a1 + 64) = LC7;
return result;
}

original_code:
void initRotation(struct transMatrix * m, int angle)
{
  double radAngle = degToRad(angle);
  m->matrix[0][0] = cos(radAngle); m->matrix[0][1] = -1*sin(radAngle); m->matrix[0][2] = 0;
  m->matrix[1][0] = sin(radAngle); m->matrix[1][1] = cos(radAngle); m->matrix[1][2] = 0;
  m->matrix[2][0] = 0; m->matrix[2][1] = 0; m->matrix[2][2] = 1;
}

canonical_original_code:
void initRotation(struct transMatrix *m, int angle)
{
  double radAngle = degToRad(angle);
  m->matrix[0][0] = cos(radAngle); m->matrix[0][1] = -1*sin(radAngle); m->matrix[0][2] = 0;
  m->matrix[1][0] = sin(radAngle); m->matrix[1][1] = cos(radAngle); m->matrix[1][2] = 0;
  m->matrix[2][0] = 0; m->matrix[2][1] = 0; m->matrix[2][2] = 1;
}

variable_types: radAngle double

user_defined_types: struct transMatrix { double matrix[3][3]; }


initScale

original_code:
void initScale(struct transMatrix * m, double sx, double sy)
{
  m->matrix[0][0] = sx; m->matrix[0][1] = 0; m->matrix[0][2] = 0;
  m->matrix[1][0] = 0; m->matrix[1][1] = sy; m->matrix[1][2] = 0;
  m->matrix[2][0] = 0; m->matrix[2][1] = 0; m->matrix[2][2] = 1;
}

canonical_original_code:
void initScale(struct transMatrix *m, double sx, double sy)
{
  m->matrix[0][0] = sx; m->matrix[0][1] = 0; m->matrix[0][2] = 0;
  m->matrix[1][0] = 0; m->matrix[1][1] = sy; m->matrix[1][2] = 0;
  m->matrix[2][0] = 0; m->matrix[2][1] = 0; m->matrix[2][2] = 1;
}

variable_types: sx double

variable_types: sy double


matrixProduct

decompiled_code:
char *__fastcall matrixProduct(double *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, char a16, int a17, int a18, char a19)
{
char *v19; // rcx
char *result; // rax
double v21; // xmm4_8
double v22; // xmm3_8
double v23; // xmm2_8
double *v24; // rdx

v19 = &a7;
do
{
result = &a16;
v21 = *(double *)v19;
v22 = *((double *)v19 + 1);
v23 = *((double *)v19 + 2);
v24 = a1;
do
{
*v24 = v23 * *((double *)result + 6) + v21 * *(double *)result + 0.0 + v22 * *((double *)result + 3);
result += 8;
++v24;
}
while ( result != &a19 );
a1 += 3;
v19 += 24;
}
while ( v19 != &a16 );
return result;
}

canonical_decompiled_code:
char *__fastcall func5(double *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, char a16, int a17, int a18, char a19)
{
char *v19; // rcx
char *result; // rax
double v21; // xmm4_8
double v22; // xmm3_8
double v23; // xmm2_8
double *v24; // rdx

v19 = &a7;
do
{
result = &a16;
v21 = *(double *)v19;
v22 = *((double *)v19 + 1);
v23 = *((double *)v19 + 2);
v24 = a1;
do
{
*v24 = v23 * *((double *)result + 6) + v21 * *(double *)result + 0.0 + v22 * *((double *)result + 3);
result += 8;
++v24;
}
while ( result != &a19 );
a1 += 3;
v19 += 24;
}
while ( v19 != &a16 );
return result;
}

original_code:
void matrixProduct(struct transMatrix *prod, struct transMatrix a, struct transMatrix b)
{
 int lin, col, index;
        double sum;
        for(lin=0; lin<3; lin++)
            for(col=0; col<3; col++)
            {
                sum = 0;
                for(index=0; index<3; index++)
                    sum+= a.matrix[lin][index]*b.matrix[index][col];
                prod->matrix[lin][col] = sum;
            }
}

canonical_original_code:
void matrixProduct(struct transMatrix *prod, struct transMatrix a, struct transMatrix b)
{
 int lin; int col; int index;
        double sum;
        for(lin=0; lin<3; lin++)
            for(col=0; col<3; col++)
            {
                sum = 0;
                for(index=0; index<3; index++)
                    sum+= a.matrix[lin][index]*b.matrix[index][col];
                prod->matrix[lin][col] = sum;
            }
}

variable_types:
a
struct transMatrix

variable_types:
b
struct transMatrix

variable_types: lin int

variable_types: col int

variable_types: index int

variable_types: sum double


matrixVectorProduct

decompiled_code:
char *__fastcall matrixVectorProduct(double *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, char a15, int a16, int a17, int a18, int a19, int a20, int a21, int a22, int a23, double a24, double a25, double a26)
{
char *result; // rax
double v19; // xmm5_8
double v20; // xmm4_8
double v21; // xmm3_8

result = &a15;
v19 = a24;
v20 = a25;
v21 = a26;
do
{
*a1 = v21 * *((double *)result + 2) + v19 * *(double *)result + 0.0 + v20 * *((double *)result + 1);
result += 24;
++a1;
}
while ( result != (char *)&a24 );
return result;
}

canonical_decompiled_code:
char *__fastcall func6(double *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, char a15, int a16, int a17, int a18, int a19, int a20, int a21, int a22, int a23, double a24, double a25, double a26)
{
char *result; // rax
double v19; // xmm5_8
double v20; // xmm4_8
double v21; // xmm3_8

result = &a15;
v19 = a24;
v20 = a25;
v21 = a26;
do
{
*a1 = v21 * *((double *)result + 2) + v19 * *(double *)result + 0.0 + v20 * *((double *)result + 1);
result += 24;
++a1;
}
while ( result != (char *)&a24 );
return result;
}

original_code:
void matrixVectorProduct(struct homoCoord *prod, struct transMatrix m, struct homoCoord vect)
{
 int lin, col;
        double sum = 0;
        for(lin=0; lin<3; lin++)
           {
  sum = 0;
                for(col=0; col<3; col++)
                    sum+= m.matrix[lin][col]*vect.coord[col];
                prod->coord[lin] = sum;
           }
}

canonical_original_code:
void matrixVectorProduct(struct homoCoord *prod, struct transMatrix m, struct homoCoord vect)
{
 int lin; int col;
        double sum = 0;
        for(lin=0; lin<3; lin++)
           {
  sum = 0;
                for(col=0; col<3; col++)
                    sum+= m.matrix[lin][col]*vect.coord[col];
                prod->coord[lin] = sum;
           }
}

variable_types:
prod
struct homoCoord { double coord[3]; } *

variable_types: struct transMatrix { double matrix[3][3]; }

variable_types:
vect
struct homoCoord


initHomoVector

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

*(double *)a1 = a2;
*(double *)(a1 + 8) = a3;
result = LC7;
*(_QWORD *)(a1 + 16) = LC7;
return result;
}

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

*(double *)a1 = a2;
*(double *)(a1 + 8) = a3;
result = LC7;
*(_QWORD *)(a1 + 16) = LC7;
return result;
}

original_code:
void initHomoVector(struct homoCoord *point, double x, double y)
{
 point->coord[0] = x;
        point->coord[1] = y;
        point->coord[2] = 1;
}

variable_types:
point
struct homoCoord { double coord[3]; } *

variable_types: x double

variable_types: y double


applyTransforms

original_code:
void
applyTransforms(struct trans *tlist, struct GENode *glist){
  struct trans *ptl = tlist;
  struct GENode *pgl = ((void *)0);
  struct transMatrix m, aux;
  struct homoCoord start;
  struct homoCoord end;
  while(((void *)0) != ptl){
    pgl = glist;
    while(((void *)0) != pgl){
      switch(pgl->el.type)
      {case LINE: initHomoVector(&start, pgl->el.data.line.st.x, pgl->el.data.line.st.y);
                  initHomoVector(&end, pgl->el.data.line.en.x, pgl->el.data.line.en.y);
                  break;
       default: break;
      }
      switch(ptl->tType){
      case TRANSLATION: initTranslation(&m, ptl->data.t.tx, ptl->data.t.ty);
                 break;
      case SCALING: initScale(&m, ptl->data.s.sx, ptl->data.s.sy);
                    if (!(ptl->data.s.px == 0 && ptl->data.s.py == 0))
                        {
                          initTranslation(&aux, -1*ptl->data.s.px, -1*ptl->data.s.py);
                          matrixProduct(&m, m, aux);
                          initTranslation(&aux, ptl->data.s.px, ptl->data.s.py);
                          matrixProduct(&m, m, aux);
                        }
              break;
      case ROTATION: initRotation(&m, ptl->data.r.u);
                     if (!(ptl->data.s.px == 0 && ptl->data.s.py == 0))
                        {
                          initTranslation(&aux, -1*ptl->data.r.px, -1*ptl->data.r.py);
                          matrixProduct(&m, m, aux);
                          initTranslation(&aux, ptl->data.s.px, ptl->data.s.py);
                          matrixProduct(&m, m, aux);
                        }
              break;
      default: break;
      }
      matrixVectorProduct(&start, m, start);
      matrixVectorProduct(&end, m, end);
      twoDCoord(&pgl->el.data.line.st, start);
      twoDCoord(&pgl->el.data.line.en, end);
      pgl = pgl->next;
    }
    ptl = ptl->next;
  }
}

canonical_original_code:
void applyTransforms(struct trans *tlist, struct GENode *glist){
  struct trans *ptl = tlist;
  struct GENode *pgl = ((void *)0);
  struct transMatrix m; struct transMatrix aux;
  struct homoCoord start;
  struct homoCoord end;
  while(((void *)0) != ptl){
    pgl = glist;
    while(((void *)0) != pgl){
      switch(pgl->el.type)
      {case LINE: initHomoVector(&start, pgl->el.data.line.st.x, pgl->el.data.line.st.y);
                  initHomoVector(&end, pgl->el.data.line.en.x, pgl->el.data.line.en.y);
                  break;
       default: break;
      }
      switch(ptl->tType){
      case TRANSLATION: initTranslation(&m, ptl->data.t.tx, ptl->data.t.ty);
                 break;
      case SCALING: initScale(&m, ptl->data.s.sx, ptl->data.s.sy);
                    if (!(ptl->data.s.px == 0 && ptl->data.s.py == 0))
                        {
                          initTranslation(&aux, -1*ptl->data.s.px, -1*ptl->data.s.py);
                          matrixProduct(&m, m, aux);
                          initTranslation(&aux, ptl->data.s.px, ptl->data.s.py);
                          matrixProduct(&m, m, aux);
                        }
              break;
      case ROTATION: initRotation(&m, ptl->data.r.u);
                     if (!(ptl->data.s.px == 0 && ptl->data.s.py == 0))
                        {
                          initTranslation(&aux, -1*ptl->data.r.px, -1*ptl->data.r.py);
                          matrixProduct(&m, m, aux);
                          initTranslation(&aux, ptl->data.s.px, ptl->data.s.py);
                          matrixProduct(&m, m, aux);
                        }
              break;
      default: break;
      }
      matrixVectorProduct(&start, m, start);
      matrixVectorProduct(&end, m, end);
      twoDCoord(&pgl->el.data.line.st, start);
      twoDCoord(&pgl->el.data.line.en, end);
      pgl = pgl->next;
    }
    ptl = ptl->next;
  }
}

variable_types: struct trans { union { struct { int px; double sx; } s; struct { int tx; } t; struct { int px; int u; } r; } data; enum TransformType { TRANSLATION=0, SCALING=1, ROTATION=2 } tType; struct trans *next; } *

variable_types: struct GENode { struct GElement { union { struct Point { int x; int y; } point; struct { struct Point st; struct Point en; } line; } data; enum GElementType { UNDEFINED_ELEMENT=0, BLANK=1, LINE=2, POINT=3 } type; } el; struct GENode *next; } *

variable_types:
start
struct homoCoord { double coord[3]; }

variable_types:
end
struct homoCoord { double coord[3]; }

user_defined_types: struct trans { union { struct { int px; double sx; } s; struct { int tx; } t; struct { int px; int u; } r; } data; enum TransformType tType; struct trans *next; }

user_defined_types: struct GENode { struct GElement el; struct GENode *next; }

user_defined_types: struct GElement { union { struct Point point; struct { struct Point st; struct Point en; } line; } data; enum GElementType type; }


bresenhamY

decompiled_code:
__int64 __fastcall bresenhamY(__int64 a1, __int64 a2, __int64 a3, int a4, unsigned __int16 a5)
{
int v6; // er9
unsigned int v7; // ebp
__int64 v8; // rcx
int v9; // ebx
__int64 result; // rax
int v11; // edi
int v12; // esi
int v13; // er12
int v14; // er15
int v17; // [rsp+8h] [rbp-38h]

v6 = a4;
v7 = a2;
v8 = a2 >> 32;
v9 = HIDWORD(a2);
result = a3 >> 32;
v11 = a3 - a2;
v12 = a2 - a3;
if ( !v6 )
v12 = v11;
v13 = 2 * v12 - (HIDWORD(a3) - v8);
if ( (int)v8 <= SHIDWORD(a3) )
{
v14 = HIDWORD(a3);
v17 = 2 * (v12 - (HIDWORD(a3) - v8));
do
{
result = putXPMpixel(a1, v7, *(_DWORD *)(a1 + 4) - v9, a5);
if ( v13 > 0 )
{
v13 += v17;
result = v7-- + 1;
if ( !a4 )
v7 = result;
}
else
{
v13 += 2 * v12;
}
++v9;
}
while ( v9 <= v14 );
}
return result;
}

original_code:
static void
bresenhamY (XPM *canvas, Point q, Point r, int symmetry, unsigned short clrIndex)
{
    int dx, dy, D, x, y;
    if(symmetry == 0)
        dx = r.x - q.x;
    else dx = q.x - r.x;
    dy = r.y - q.y;
    D = 2*dx - dy;
    x = q.x;
    for (y = q.y; y <= r.y; y++)
    {
        putXPMpixel(canvas, x, canvas->height - y, clrIndex);
        if (D <= 0) D += 2 * dx;
        else
        {
            D += 2*(dx - dy);
            if(symmetry == 0)
                x++;
            else x--;
        }
    }
}

canonical_original_code:
static void bresenhamY(struct XPM *canvas, struct Point q, struct Point r, int symmetry, unsigned short clrIndex)
{
    int dx; int dy; int D; int x; int y;
    if(symmetry == 0)
        dx = r.x - q.x;
    else dx = q.x - r.x;
    dy = r.y - q.y;
    D = 2*dx - dy;
    x = q.x;
    for (y = q.y; y <= r.y; y++)
    {
        putXPMpixel(canvas, x, canvas->height - y, clrIndex);
        if (D <= 0) D += 2 * dx;
        else
        {
            D += 2*(dx - dy);
            if(symmetry == 0)
                x++;
            else x--;
        }
    }
}

variable_types: struct XPM { unsigned int width; unsigned int height; struct { int windowTop; int windowLeft; int windowBottom; int windowRight; } displayRegion; unsigned short chrperpixel; unsigned int ncolors; struct XPMColor { struct Color { unsigned short red; unsigned short green; unsigned short blue; } clr; char *chars; char *key; } *colta; unsigned short **data; } *

variable_types:
q
struct Point { int x; int y; }

variable_types:
r
struct Point

variable_types: symmetry int

variable_types:
clrIndex
unsigned short

variable_types: dx int

variable_types: dy int

variable_types: D int

variable_types: x int

variable_types: y int

user_defined_types: struct XPM { unsigned int width; unsigned int height; struct { int windowTop; int windowLeft; int windowBottom; int windowRight; } displayRegion; unsigned short chrperpixel; unsigned int ncolors; struct XPMColor *colta; unsigned short **data; }


bresenhamX

decompiled_code:
__int64 __fastcall bresenhamX(__int64 a1, __int64 a2, __int64 a3, int a4, unsigned __int16 a5)
{
int v6; // ebp
int v7; // edi
__int64 result; // rax
int v9; // er12
signed int v10; // ebx
signed int v11; // er15
int v14; // [rsp+8h] [rbp-38h]
int v15; // [rsp+Ch] [rbp-34h]

v6 = HIDWORD(a2);
v7 = a3 - a2;
result = (unsigned int)(HIDWORD(a2) - HIDWORD(a3));
if ( !a4 )
result = (unsigned int)(HIDWORD(a3) - HIDWORD(a2));
v15 = 2 * result;
v9 = 2 * result - v7;
if ( (int)a2 <= (int)a3 )
{
v10 = a2;
v11 = a3;
v14 = 2 * (result - v7);
do
{
result = putXPMpixel(a1, v10, *(_DWORD *)(a1 + 4) - v6, a5);
if ( v9 > 0 )
{
v9 += v14;
result = (unsigned int)(v6-- + 1);
if ( !a4 )
v6 = result;
}
else
{
v9 += v15;
}
++v10;
}
while ( v10 <= v11 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, int a4, unsigned __int16 a5)
{
int v6; // ebp
int v7; // edi
__int64 result; // rax
int v9; // er12
signed int v10; // ebx
signed int v11; // er15
int v14; // [rsp+8h] [rbp-38h]
int v15; // [rsp+Ch] [rbp-34h]

v6 = HIDWORD(a2);
v7 = a3 - a2;
result = (unsigned int)(HIDWORD(a2) - HIDWORD(a3));
if ( !a4 )
result = (unsigned int)(HIDWORD(a3) - HIDWORD(a2));
v15 = 2 * result;
v9 = 2 * result - v7;
if ( (int)a2 <= (int)a3 )
{
v10 = a2;
v11 = a3;
v14 = 2 * (result - v7);
do
{
result = func4(a1, v10, *(_DWORD *)(a1 + 4) - v6, a5);
if ( v9 > 0 )
{
v9 += v14;
result = (unsigned int)(v6-- + 1);
if ( !a4 )
v6 = result;
}
else
{
v9 += v15;
}
++v10;
}
while ( v10 <= v11 );
}
return result;
}

original_code:
static void
bresenhamX (XPM *canvas, Point q, Point r, int symmetry, unsigned short clrIndex)
{
    int dx, dy, D, x, y;
    dx = r.x - q.x;
    if (symmetry == 0)
        dy = r.y - q.y;
    else dy = q.y - r.y;
    D = 2*dy - dx;
    y = q.y;
    for (x = q.x; x <= r.x; x++)
    {
      putXPMpixel(canvas, x, canvas->height - y, clrIndex);
        if (D <= 0) D += 2 * dy;
        else
        {
            D += 2*(dy - dx);
            if(symmetry == 0)
                y++;
            else y--;
        }
    }
}

canonical_original_code:
static void bresenhamX(struct XPM *canvas, struct Point q, struct Point r, int symmetry, unsigned short clrIndex)
{
    int dx; int dy; int D; int x; int y;
    dx = r.x - q.x;
    if (symmetry == 0)
        dy = r.y - q.y;
    else dy = q.y - r.y;
    D = 2*dy - dx;
    y = q.y;
    for (x = q.x; x <= r.x; x++)
    {
      putXPMpixel(canvas, x, canvas->height - y, clrIndex);
        if (D <= 0) D += 2 * dy;
        else
        {
            D += 2*(dy - dx);
            if(symmetry == 0)
                y++;
            else y--;
        }
    }
}


assignXPMColorTable

original_code:
void
assignXPMColorTable(XPM *img, const unsigned char vColors[][3], int clrCnt){
  XPMColor clrData;
  int clrIndex = 0;
  char charsFormat[10];
  if(clrCnt > img->ncolors ||
     clrCnt > pow(2, img->chrperpixel * 8) - 1) return;
  for(clrIndex = 1; clrIndex <= clrCnt; clrIndex ++){
    clrData.clr.blue = vColors[clrIndex - 1][0];
    clrData.clr.green = vColors[clrIndex - 1][1];
    clrData.clr.red = vColors[clrIndex - 1][2];
    clrData.key = (char *)malloc(2 * sizeof(char));
    strcpy(clrData.key, "c");
    clrData.chars = (char *)malloc((1 + img->chrperpixel) * sizeof(char));
    switch(img->chrperpixel){
    case 1:
      if(clrCnt <= 0x0F) sprintf(clrData.chars, "%1X", clrIndex);
      else sprintf(clrData.chars, "%c", clrIndex);
      break;
    default:
      sprintf(charsFormat, "%%0%dX", img->chrperpixel);
      sprintf(clrData.chars, charsFormat, clrIndex);
      break;
    }
    setXPMColor(img, clrIndex - 1, clrData);
  }
}

canonical_original_code:
void assignXPMColorTable(struct XPM *img, unsigned char vColors[][3], int clrCnt){
  struct XPMColor clrData;
  int clrIndex = 0;
  char charsFormat[10];
  if(clrCnt > img->ncolors ||
     clrCnt > pow(2, img->chrperpixel * 8) - 1) return;
  for(clrIndex = 1; clrIndex <= clrCnt; clrIndex ++){
    clrData.clr.blue = vColors[clrIndex - 1][0];
    clrData.clr.green = vColors[clrIndex - 1][1];
    clrData.clr.red = vColors[clrIndex - 1][2];
    clrData.key = (char *)malloc(2 * sizeof(char));
    strcpy(clrData.key, "c");
    clrData.chars = (char *)malloc((1 + img->chrperpixel) * sizeof(char));
    switch(img->chrperpixel){
    case 1:
      if(clrCnt <= 0x0F) sprintf(clrData.chars, "%1X", clrIndex);
      else sprintf(clrData.chars, "%c", clrIndex);
      break;
    default:
      sprintf(charsFormat, "%%0%dX", img->chrperpixel);
      sprintf(clrData.chars, charsFormat, clrIndex);
      break;
    }
    setXPMColor(img, clrIndex - 1, clrData);
  }
}

variable_types:
vColors
unsigned char [][3]

variable_types: clrCnt int

variable_types: struct XPMColor { struct Color { unsigned short red; unsigned short green; unsigned short blue; } clr; char *chars; char *key; }

variable_types: clrIndex int

variable_types:
charsFormat
char [10]


cohenSutherlandFrameLine

decompiled_code:
__int64 __fastcall cohenSutherlandFrameLine(_DWORD *a1, _DWORD *a2, int *a3)
{
unsigned __int8 v4; // bp
unsigned __int8 v5; // al
int v6; // er9
unsigned int v7; // edx

v4 = getRegionCode(a1, a2);
v5 = getRegionCode(a1, a3);
v7 = 1;
if ( v5 | v4 )
{
v7 = 0;
if ( (v5 & v4) == 0 )
{
trimLineToRegion(a1, a2, a3, v4, v5, v6);
v7 = cohenSutherlandFrameLine(a1, a2, a3);
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1, _DWORD *a2, int *a3)
{
unsigned __int8 v4; // bp
unsigned __int8 v5; // al
int v6; // er9
unsigned int v7; // edx

v4 = func0(a1, a2);
v5 = func0(a1, a3);
v7 = 1;
if ( v5 | v4 )
{
v7 = 0;
if ( (v5 & v4) == 0 )
{
func1(a1, a2, a3, v4, v5, v6);
v7 = func10(a1, a2, a3);
}
}
return v7;
}

original_code:
int
cohenSutherlandFrameLine(XPM *canvas, Point *pStart, Point *pEnd)
{
  unsigned char codeStart = getRegionCode(canvas, pStart);
  unsigned char codeEnd = getRegionCode(canvas,pEnd);
    if((codeStart | codeEnd) == 0) return 1;
    if((codeStart & codeEnd) != 0) return 0;
    trimLineToRegion(canvas, pStart, pEnd, codeStart, codeEnd);
    return cohenSutherlandFrameLine(canvas, pStart, pEnd);
}

canonical_original_code:
int cohenSutherlandFrameLine(struct XPM *canvas, struct Point *pStart, struct Point *pEnd)
{
  unsigned char codeStart = getRegionCode(canvas, pStart);
  unsigned char codeEnd = getRegionCode(canvas,pEnd);
    if((codeStart | codeEnd) == 0) return 1;
    if((codeStart & codeEnd) != 0) return 0;
    trimLineToRegion(canvas, pStart, pEnd, codeStart, codeEnd);
    return cohenSutherlandFrameLine(canvas, pStart, pEnd);
}

variable_types:
pStart
struct Point { int x; int y; } *

variable_types:
pEnd
struct Point *

variable_types:
codeStart
unsigned char

variable_types:
codeEnd
unsigned char