decompiled_code:
__int64 __fastcall algebraic_factor(int *a1, unsigned int a2, int a3)
{
int v3; // ecx
unsigned int v4; // ebx
int v5; // er9
int v6; // er8
int v7; // esi
int v8; // edi
int v9; // edx
unsigned int v10; // er15
__m128i v11; // xmm4
int i; // eax
int v13; // ebp
int v14; // er14
unsigned int v15; // er13
int v16; // ebp
unsigned int v17; // edx
int j; // eax
__int64 v20; // rax
int v21; // edx
__int64 v22; // rax
char *v23; // rax
void *v24; // rax
int v25; // ebp
int v26; // eax
unsigned int v27; // edx
unsigned int v28; // er12
int v29; // ebp
unsigned int v30; // er13
unsigned int v31; // er15
unsigned int v32; // esi
unsigned int v33; // edx
int k; // eax
char *v35; // rax
void *v36; // rax
int v37; // [rsp+0h] [rbp-D8h]
int v38; // [rsp+4h] [rbp-D4h]
int v40; // [rsp+10h] [rbp-C8h]
__m128i *v41; // [rsp+10h] [rbp-C8h]
char *v42; // [rsp+10h] [rbp-C8h]
__m128i *ptr; // [rsp+18h] [rbp-C0h]
char *ptrb; // [rsp+18h] [rbp-C0h]
unsigned int ptra; // [rsp+18h] [rbp-C0h]
size_t v46; // [rsp+20h] [rbp-B8h]
int v47; // [rsp+20h] [rbp-B8h]
unsigned int v49; // [rsp+2Ch] [rbp-ACh]
int v50; // [rsp+2Ch] [rbp-ACh]
size_t v51; // [rsp+30h] [rbp-A8h]
int v52; // [rsp+38h] [rbp-A0h]
int v53; // [rsp+3Ch] [rbp-9Ch]
int v54[4]; // [rsp+40h] [rbp-98h]
int v55; // [rsp+50h] [rbp-88h]
int v56; // [rsp+54h] [rbp-84h]
__m128i v57; // [rsp+60h] [rbp-78h] BYREF
char v58[16]; // [rsp+70h] [rbp-68h] BYREF
char v59[16]; // [rsp+80h] [rbp-58h] BYREF
char v60[72]; // [rsp+90h] [rbp-48h] BYREF

v3 = a3;
v4 = *a1;
v5 = a3 & 1;
if ( (a3 & 1) != 0 )
{
v40 = 0;
if ( a3 > 8 )
{
LABEL_6:
v6 = v40;
v7 = 3;
while ( 1 )
{
while ( 1 )
{
v8 = v3 % v7;
if ( !(v3 % v7) )
break;
LABEL_10:
v7 += 2;
if ( v3 / v7 < v7 )
goto LABEL_11;
}
if ( !((int)v4 % v7) )
{
do
{
v5 *= v7;
v9 = (v3 / v7) >> 31;
v3 /= v7;
}
while ( !(unsigned int)(__SPAIR64__(v9, v3) % v7) );
goto LABEL_10;
}
do
{
++v8;
v21 = (v3 / v7) >> 31;
v3 /= v7;
}
while ( !(unsigned int)(__SPAIR64__(v21, v3) % v7) );
v22 = v6++;
v54[v22] = v7;
v7 += 2;
*(&v55 + v22) = v8;
if ( v3 / v7 < v7 )
{
LABEL_11:
v40 = v6;
goto LABEL_12;
}
}
}
if ( !((int)v4 % a3) )
{
v5 = a3;
goto LABEL_36;
}
goto LABEL_59;
}
v40 = *a1 & 1;
if ( (v4 & 1) != 0 )
{
do
{
v3 >>= 1;
++v5;
}
while ( (v3 & 1) == 0 );
v55 = v5;
v5 = v3 & 1;
v40 = v5;
v54[0] = 2;
if ( v3 > 8 )
goto LABEL_6;
}
else
{
v5 = 1;
do
{
v3 >>= 1;
v5 *= 2;
}
while ( (v3 & 1) == 0 );
if ( v3 > 8 )
goto LABEL_6;
}
LABEL_12:
if ( v3 > 1 )
{
if ( !((int)v4 % v3) )
{
v5 *= v3;
goto LABEL_15;
}
LABEL_59:
v54[v40] = v3;
*(&v55 + v40++) = 1;
goto LABEL_16;
}
LABEL_15:
if ( v40 )
{
LABEL_16:
v10 = 1;
v11 = _mm_loadu_si128((const __m128i *)(*((_QWORD *)a1 + 2) + 16LL * a1[2] - 16));
*((_QWORD *)a1 + 4) = 0LL;
v57 = v11;
if ( v5 > 0 )
{
for ( i = 0; i != v5; ++i )
v10 *= a2;
}
v13 = v55;
v14 = v54[0];
v37 = v55;
v52 = v4 * v5;
v15 = v4 * v5;
_gmpz_init(v58);
_gmpz_init(v59);
_gmpz_init(v60);
_gmpz_set_ui(v58, 1LL);
if ( v13 < 0 )
{
v38 = 0;
}
else
{
v38 = 0;
v16 = 0;
v49 = v10;
do
{
cn_eval(v59, v4, v10);
_gmpz_divexact(v60, v59, v58);
_gmpz_gcd(v60, v60, &v57);
if ( (unsigned int)_gmpz_cmp_ui(v60, 1LL) )
{
ptr = (__m128i *)aur_factor(v60, v15, a2);
if ( ptr )
{
v38 += 2;
v46 = 16LL * v38;
v23 = (char *)realloc(*((void **)a1 + 4), v46);
*((_QWORD *)a1 + 4) = v23;
*(__m128i *)&v23[v46 - 32] = _mm_loadu_si128(ptr);
*(__m128i *)(*((_QWORD *)a1 + 4) + v46 - 16) = _mm_loadu_si128(ptr + 1);
free(ptr);
}
else if ( (unsigned int)_gmpz_cmp(v60, &v57) )
{
ptrb = (char *)(16LL * ++v38);
v24 = realloc(*((void **)a1 + 4), (size_t)ptrb);
*((_QWORD *)a1 + 4) = v24;
_gmpz_init(&ptrb[(_QWORD)v24 - 16]);
_gmpz_swap(&ptrb[*((_QWORD *)a1 + 4) - 16], v60);
}
}
_gmpz_swap(v58, v59);
v15 *= v14;
if ( v14 > 1 )
{
v17 = v10;
for ( j = 1; j != v14; ++j )
v17 *= v10;
v10 = v17;
}
++v16;
}
while ( v37 >= v16 );
v10 = v49;
}
_gmpz_clear(v58);
_gmpz_clear(v59);
_gmpz_clear(v60);
if ( v40 != 1 )
{
v25 = v56;
v50 = v54[1];
v53 = v56;
_gmpz_init(v58);
_gmpz_init(v59);
_gmpz_init(v60);
v47 = 1;
if ( v25 > 0 )
{
while ( 1 )
{
ptra = v10;
v26 = 1;
v27 = v10;
if ( v50 > 1 )
{
do
{
++v26;
v27 *= v10;
}
while ( v50 != v26 );
ptra = v27;
}
v28 = v50 * v52;
v52 *= v50;
_gmpz_set_ui(v58, 1LL);
if ( v37 >= 0 )
{
v29 = 0;
v30 = v10;
v31 = ptra;
do
{
cn_eval(v60, v4, v30);
cn_eval(v59, v4, v31);
_gmpz_divexact(v59, v59, v60);
_gmpz_divexact(v60, v59, v58);
_gmpz_gcd(v60, v60, &v57);
if ( (unsigned int)_gmpz_cmp_ui(v60, 1LL) )
{
v41 = (__m128i *)aur_factor(v60, v28, a2);
if ( v41 )
{
v38 += 2;
v51 = 16LL * v38;
v35 = (char *)realloc(*((void **)a1 + 4), v51);
*((_QWORD *)a1 + 4) = v35;
*(__m128i *)&v35[v51 - 32] = _mm_loadu_si128(v41);
*(__m128i *)(*((_QWORD *)a1 + 4) + v51 - 16) = _mm_loadu_si128(v41 + 1);
free(v41);
}
else if ( (unsigned int)_gmpz_cmp(v60, &v57) )
{
v42 = (char *)(16LL * ++v38);
v36 = realloc(*((void **)a1 + 4), (size_t)v42);
*((_QWORD *)a1 + 4) = v36;
_gmpz_init(&v42[(_QWORD)v36 - 16]);
_gmpz_swap(&v42[*((_QWORD *)a1 + 4) - 16], v60);
}
}
_gmpz_swap(v58, v59);
v28 *= v14;
if ( v14 > 1 )
{
v32 = v31;
v33 = v30;
for ( k = 1; k != v14; ++k )
{
v33 *= v30;
v32 *= v31;
}
v31 = v32;
v30 = v33;
}
++v29;
}
while ( v37 >= v29 );
}
if ( v53 < ++v47 )
break;
v10 = ptra;
}
}
_gmpz_clear(v58);
_gmpz_clear(v59);
_gmpz_clear(v60);
}
return (unsigned int)v38;
}
LABEL_36:
v20 = aur_factor(*((_QWORD *)a1 + 2) + 16LL * a1[2] - 16, v4 * v5, a2);
v38 = 0;
if ( v20 )
{
*((_QWORD *)a1 + 4) = v20;
v38 = 2;
}
return (unsigned int)v38;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, unsigned int a2, int a3)
{
int v3; // ecx
unsigned int v4; // ebx
int v5; // er9
int v6; // er8
int v7; // esi
int v8; // edi
int v9; // edx
unsigned int v10; // er15
__m128i v11; // xmm4
int i; // eax
int v13; // ebp
int v14; // er14
unsigned int v15; // er13
int v16; // ebp
unsigned int v17; // edx
int j; // eax
__int64 v20; // rax
int v21; // edx
__int64 v22; // rax
char *v23; // rax
void *v24; // rax
int v25; // ebp
int v26; // eax
unsigned int v27; // edx
unsigned int v28; // er12
int v29; // ebp
unsigned int v30; // er13
unsigned int v31; // er15
unsigned int v32; // esi
unsigned int v33; // edx
int k; // eax
char *v35; // rax
void *v36; // rax
int v37; // [rsp+0h] [rbp-D8h]
int v38; // [rsp+4h] [rbp-D4h]
int v40; // [rsp+10h] [rbp-C8h]
__m128i *v41; // [rsp+10h] [rbp-C8h]
char *v42; // [rsp+10h] [rbp-C8h]
__m128i *ptr; // [rsp+18h] [rbp-C0h]
char *ptrb; // [rsp+18h] [rbp-C0h]
unsigned int ptra; // [rsp+18h] [rbp-C0h]
size_t v46; // [rsp+20h] [rbp-B8h]
int v47; // [rsp+20h] [rbp-B8h]
unsigned int v49; // [rsp+2Ch] [rbp-ACh]
int v50; // [rsp+2Ch] [rbp-ACh]
size_t v51; // [rsp+30h] [rbp-A8h]
int v52; // [rsp+38h] [rbp-A0h]
int v53; // [rsp+3Ch] [rbp-9Ch]
int v54[4]; // [rsp+40h] [rbp-98h]
int v55; // [rsp+50h] [rbp-88h]
int v56; // [rsp+54h] [rbp-84h]
__m128i v57; // [rsp+60h] [rbp-78h] BYREF
char v58[16]; // [rsp+70h] [rbp-68h] BYREF
char v59[16]; // [rsp+80h] [rbp-58h] BYREF
char v60[72]; // [rsp+90h] [rbp-48h] BYREF

v3 = a3;
v4 = *a1;
v5 = a3 & 1;
if ( (a3 & 1) != 0 )
{
v40 = 0;
if ( a3 > 8 )
{
LABEL_6:
v6 = v40;
v7 = 3;
while ( 1 )
{
while ( 1 )
{
v8 = v3 % v7;
if ( !(v3 % v7) )
break;
LABEL_10:
v7 += 2;
if ( v3 / v7 < v7 )
goto LABEL_11;
}
if ( !((int)v4 % v7) )
{
do
{
v5 *= v7;
v9 = (v3 / v7) >> 31;
v3 /= v7;
}
while ( !(unsigned int)(__SPAIR64__(v9, v3) % v7) );
goto LABEL_10;
}
do
{
++v8;
v21 = (v3 / v7) >> 31;
v3 /= v7;
}
while ( !(unsigned int)(__SPAIR64__(v21, v3) % v7) );
v22 = v6++;
v54[v22] = v7;
v7 += 2;
*(&v55 + v22) = v8;
if ( v3 / v7 < v7 )
{
LABEL_11:
v40 = v6;
goto LABEL_12;
}
}
}
if ( !((int)v4 % a3) )
{
v5 = a3;
goto LABEL_36;
}
goto LABEL_59;
}
v40 = *a1 & 1;
if ( (v4 & 1) != 0 )
{
do
{
v3 >>= 1;
++v5;
}
while ( (v3 & 1) == 0 );
v55 = v5;
v5 = v3 & 1;
v40 = v5;
v54[0] = 2;
if ( v3 > 8 )
goto LABEL_6;
}
else
{
v5 = 1;
do
{
v3 >>= 1;
v5 *= 2;
}
while ( (v3 & 1) == 0 );
if ( v3 > 8 )
goto LABEL_6;
}
LABEL_12:
if ( v3 > 1 )
{
if ( !((int)v4 % v3) )
{
v5 *= v3;
goto LABEL_15;
}
LABEL_59:
v54[v40] = v3;
*(&v55 + v40++) = 1;
goto LABEL_16;
}
LABEL_15:
if ( v40 )
{
LABEL_16:
v10 = 1;
v11 = _mm_loadu_si128((const __m128i *)(*((_QWORD *)a1 + 2) + 16LL * a1[2] - 16));
*((_QWORD *)a1 + 4) = 0LL;
v57 = v11;
if ( v5 > 0 )
{
for ( i = 0; i != v5; ++i )
v10 *= a2;
}
v13 = v55;
v14 = v54[0];
v37 = v55;
v52 = v4 * v5;
v15 = v4 * v5;
_gmpz_init(v58);
_gmpz_init(v59);
_gmpz_init(v60);
_gmpz_set_ui(v58, 1LL);
if ( v13 < 0 )
{
v38 = 0;
}
else
{
v38 = 0;
v16 = 0;
v49 = v10;
do
{
cn_eval(v59, v4, v10);
_gmpz_divexact(v60, v59, v58);
_gmpz_gcd(v60, v60, &v57);
if ( (unsigned int)_gmpz_cmp_ui(v60, 1LL) )
{
ptr = (__m128i *)aur_factor(v60, v15, a2);
if ( ptr )
{
v38 += 2;
v46 = 16LL * v38;
v23 = (char *)realloc(*((void **)a1 + 4), v46);
*((_QWORD *)a1 + 4) = v23;
*(__m128i *)&v23[v46 - 32] = _mm_loadu_si128(ptr);
*(__m128i *)(*((_QWORD *)a1 + 4) + v46 - 16) = _mm_loadu_si128(ptr + 1);
free(ptr);
}
else if ( (unsigned int)_gmpz_cmp(v60, &v57) )
{
ptrb = (char *)(16LL * ++v38);
v24 = realloc(*((void **)a1 + 4), (size_t)ptrb);
*((_QWORD *)a1 + 4) = v24;
_gmpz_init(&ptrb[(_QWORD)v24 - 16]);
_gmpz_swap(&ptrb[*((_QWORD *)a1 + 4) - 16], v60);
}
}
_gmpz_swap(v58, v59);
v15 *= v14;
if ( v14 > 1 )
{
v17 = v10;
for ( j = 1; j != v14; ++j )
v17 *= v10;
v10 = v17;
}
++v16;
}
while ( v37 >= v16 );
v10 = v49;
}
_gmpz_clear(v58);
_gmpz_clear(v59);
_gmpz_clear(v60);
if ( v40 != 1 )
{
v25 = v56;
v50 = v54[1];
v53 = v56;
_gmpz_init(v58);
_gmpz_init(v59);
_gmpz_init(v60);
v47 = 1;
if ( v25 > 0 )
{
while ( 1 )
{
ptra = v10;
v26 = 1;
v27 = v10;
if ( v50 > 1 )
{
do
{
++v26;
v27 *= v10;
}
while ( v50 != v26 );
ptra = v27;
}
v28 = v50 * v52;
v52 *= v50;
_gmpz_set_ui(v58, 1LL);
if ( v37 >= 0 )
{
v29 = 0;
v30 = v10;
v31 = ptra;
do
{
cn_eval(v60, v4, v30);
cn_eval(v59, v4, v31);
_gmpz_divexact(v59, v59, v60);
_gmpz_divexact(v60, v59, v58);
_gmpz_gcd(v60, v60, &v57);
if ( (unsigned int)_gmpz_cmp_ui(v60, 1LL) )
{
v41 = (__m128i *)aur_factor(v60, v28, a2);
if ( v41 )
{
v38 += 2;
v51 = 16LL * v38;
v35 = (char *)realloc(*((void **)a1 + 4), v51);
*((_QWORD *)a1 + 4) = v35;
*(__m128i *)&v35[v51 - 32] = _mm_loadu_si128(v41);
*(__m128i *)(*((_QWORD *)a1 + 4) + v51 - 16) = _mm_loadu_si128(v41 + 1);
free(v41);
}
else if ( (unsigned int)_gmpz_cmp(v60, &v57) )
{
v42 = (char *)(16LL * ++v38);
v36 = realloc(*((void **)a1 + 4), (size_t)v42);
*((_QWORD *)a1 + 4) = v36;
_gmpz_init(&v42[(_QWORD)v36 - 16]);
_gmpz_swap(&v42[*((_QWORD *)a1 + 4) - 16], v60);
}
}
_gmpz_swap(v58, v59);
v28 *= v14;
if ( v14 > 1 )
{
v32 = v31;
v33 = v30;
for ( k = 1; k != v14; ++k )
{
v33 *= v30;
v32 *= v31;
}
v31 = v32;
v30 = v33;
}
++v29;
}
while ( v37 >= v29 );
}
if ( v53 < ++v47 )
break;
v10 = ptra;
}
}
_gmpz_clear(v58);
_gmpz_clear(v59);
_gmpz_clear(v60);
}
return (unsigned int)v38;
}
LABEL_36:
v20 = aur_factor(*((_QWORD *)a1 + 2) + 16LL * a1[2] - 16, v4 * v5, a2);
v38 = 0;
if ( v20 )
{
*((_QWORD *)a1 + 4) = v20;
v38 = 2;
}
return (unsigned int)v38;
}

original_code:
static int algebraic_factor(cn_t cn, int k, int p){
  int factor[4];
  int faccnt[4];
  int pfactors = 0;
  int n = cn->n;
  int i, j;
  {
    int pp = p;
    p = 1;
    pfactors = 0;
    if((pp & 0x1) == 0){
      if((n & 0x1) == 0){
        do{
          pp >>= 1;
          p <<= 1;
        }while((pp & 0x1) == 0);
      }else{
        int cnt = 0;
        do{
          pp >>= 1;
          cnt++;
        }while((pp & 0x1) == 0);
        factor[pfactors] = 2;
        faccnt[pfactors++] = cnt;
      }
    }
    for(i = 3; i <= pp / i; i += 2){
      if(pp % i != 0) continue;
      if(n % i == 0){
        do{
          pp /= i;
          p *= i;
        }while(pp % i == 0);
      }else{
        int cnt = 0;
        do{
          pp /= i;
          cnt++;
        }while(pp % i == 0);
        factor[pfactors] = i;
        faccnt[pfactors++] = cnt;
      }
    }
    if(pp > 1){
      if(n % pp == 0){
        p *= pp;
      }else{
        factor[pfactors] = pp;
        faccnt[pfactors++] = 1;
      }
    }
  }
  if(pfactors == 0){
    mpz_t *afs = aur_factor(cn->factor[cn->nfactors-1], p*n, k);
    if(afs == ((void *)0)) return 0;
    cn->newfactor = afs;
    return 2;
  }
  {
    int kp;
    int nnewfactors = 0;
    mpz_t comp;
    memcpy(comp, cn->factor[cn->nfactors-1], sizeof(mpz_t));
    cn->newfactor = ((void *)0);
    kp = 1;
    for(i = 0; i < p; i++){
      kp *= k;
    }
                         {
      int f = factor[0];
      int cnt = faccnt[0];
      int kpq = kp;
      int pnq = p*n;
      mpz_t prev, cur, alf;
      __gmpz_init(prev);
      __gmpz_init(cur);
      __gmpz_init(alf);
      __gmpz_set_ui(prev, 1);
      for(i = 0; i <= cnt; i++){
        cn_eval(cur, n, kpq);
        __gmpz_divexact(alf, cur, prev);
        __gmpz_gcd(alf, alf, comp);
        if((__builtin_constant_p (1) && (1) == 0 ? ((alf)->_mp_size < 0 ? -1 : (alf)->_mp_size > 0) : __gmpz_cmp_ui (alf,1)) != 0){
          mpz_t *afs = aur_factor(alf, pnq, k);
          if(afs != ((void *)0)){
            nnewfactors += 2;
            cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
            memcpy(cn->newfactor[nnewfactors-2], afs[0], sizeof(mpz_t));
            memcpy(cn->newfactor[nnewfactors-1], afs[1], sizeof(mpz_t));
            free(afs);
          }else if(__gmpz_cmp(alf, comp) != 0){
            nnewfactors += 1;
            cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
            __gmpz_init(cn->newfactor[nnewfactors-1]);
            __gmpz_swap(cn->newfactor[nnewfactors-1], alf);
          }
        }
        __gmpz_swap(prev, cur);
        pnq *= f;
        {
          int tmp = kpq;
          int _;
          for(_ = 1; _ < f; _++){
            kpq *= tmp;
          }
        }
      }
      __gmpz_clear(prev);
      __gmpz_clear(cur);
      __gmpz_clear(alf);
    }
    if(pfactors >= 2){
      int f0 = factor[0];
      int f1 = factor[1];
      int cnt0 = faccnt[0];
      int cnt1 = faccnt[1];
      int kpr = kp;
      int pnr = p*n;
      mpz_t prev, cur, alf;
      __gmpz_init(prev);
      __gmpz_init(cur);
      __gmpz_init(alf);
      for(i = 1; i <= cnt1; i++){
        int kpqrprev = kpr;
        int kpqrcur;
        int pnqr;
        kpqrcur = kpr;
        for(j = 1; j < f1; j++){
          kpqrcur *= kpr;
        }
        kpr = kpqrcur;
        pnr *= f1;
        pnqr = pnr;
        __gmpz_set_ui(prev, 1);
        for(j = 0; j <= cnt0; j++){
          cn_eval(alf, n, kpqrprev);
          cn_eval(cur, n, kpqrcur);
          __gmpz_divexact(cur, cur, alf);
          __gmpz_divexact(alf, cur, prev);
          __gmpz_gcd(alf, alf, comp);
          if((__builtin_constant_p (1) && (1) == 0 ? ((alf)->_mp_size < 0 ? -1 : (alf)->_mp_size > 0) : __gmpz_cmp_ui (alf,1)) != 0){
            mpz_t *afs = aur_factor(alf, pnqr, k);
            if(afs != ((void *)0)){
              nnewfactors += 2;
              cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
              memcpy(cn->newfactor[nnewfactors-2], afs[0], sizeof(mpz_t));
              memcpy(cn->newfactor[nnewfactors-1], afs[1], sizeof(mpz_t));
              free(afs);
            }else if(__gmpz_cmp(alf, comp) != 0){
              nnewfactors += 1;
              cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
              __gmpz_init(cn->newfactor[nnewfactors-1]);
              __gmpz_swap(cn->newfactor[nnewfactors-1], alf);
            }
          }
          __gmpz_swap(prev, cur);
          pnqr *= f0;
          {
            int tmpprev = kpqrprev;
            int tmpcur = kpqrcur;
            int _;
            for(_ = 1; _ < f0; _++){
              kpqrprev *= tmpprev;
              kpqrcur *= tmpcur;
            }
          }
        }
      }
      __gmpz_clear(prev);
      __gmpz_clear(cur);
      __gmpz_clear(alf);
    }
    return nnewfactors;
  }
}

canonical_original_code:
static int algebraic_factor(struct _cn_t *cn, int k, int p){
  int factor[4];
  int faccnt[4];
  int pfactors = 0;
  int n = cn->n;
  int i; int j;
  {
    int pp = p;
    p = 1;
    pfactors = 0;
    if((pp & 0x1) == 0){
      if((n & 0x1) == 0){
        do{
          pp >>= 1;
          p <<= 1;
        }while((pp & 0x1) == 0);
      }else{
        int cnt = 0;
        do{
          pp >>= 1;
          cnt++;
        }while((pp & 0x1) == 0);
        factor[pfactors] = 2;
        faccnt[pfactors++] = cnt;
      }
    }
    for(i = 3; i <= pp / i; i += 2){
      if(pp % i != 0) continue;
      if(n % i == 0){
        do{
          pp /= i;
          p *= i;
        }while(pp % i == 0);
      }else{
        int cnt = 0;
        do{
          pp /= i;
          cnt++;
        }while(pp % i == 0);
        factor[pfactors] = i;
        faccnt[pfactors++] = cnt;
      }
    }
    if(pp > 1){
      if(n % pp == 0){
        p *= pp;
      }else{
        factor[pfactors] = pp;
        faccnt[pfactors++] = 1;
      }
    }
  }
  if(pfactors == 0){
    struct __mpz_struct (*afs)[1] = aur_factor(cn->factor[cn->nfactors-1], p*n, k);
    if(afs == ((void *)0)) return 0;
    cn->newfactor = afs;
    return 2;
  }
  {
    int kp;
    int nnewfactors = 0;
    struct __mpz_struct comp[1];
    memcpy(comp, cn->factor[cn->nfactors-1], sizeof(mpz_t));
    cn->newfactor = ((void *)0);
    kp = 1;
    for(i = 0; i < p; i++){
      kp *= k;
    }
                         {
      int f = factor[0];
      int cnt = faccnt[0];
      int kpq = kp;
      int pnq = p*n;
      struct __mpz_struct prev[1]; struct __mpz_struct cur[1]; struct __mpz_struct alf[1];
      __gmpz_init(prev);
      __gmpz_init(cur);
      __gmpz_init(alf);
      __gmpz_set_ui(prev, 1);
      for(i = 0; i <= cnt; i++){
        cn_eval(cur, n, kpq);
        __gmpz_divexact(alf, cur, prev);
        __gmpz_gcd(alf, alf, comp);
        if((__builtin_constant_p (1) && (1) == 0 ? ((alf)->_mp_size < 0 ? -1 : (alf)->_mp_size > 0) : __gmpz_cmp_ui (alf,1)) != 0){
          struct __mpz_struct (*afs)[1] = aur_factor(alf, pnq, k);
          if(afs != ((void *)0)){
            nnewfactors += 2;
            cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
            memcpy(cn->newfactor[nnewfactors-2], afs[0], sizeof(mpz_t));
            memcpy(cn->newfactor[nnewfactors-1], afs[1], sizeof(mpz_t));
            free(afs);
          }else if(__gmpz_cmp(alf, comp) != 0){
            nnewfactors += 1;
            cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
            __gmpz_init(cn->newfactor[nnewfactors-1]);
            __gmpz_swap(cn->newfactor[nnewfactors-1], alf);
          }
        }
        __gmpz_swap(prev, cur);
        pnq *= f;
        {
          int tmp = kpq;
          int _;
          for(_ = 1; _ < f; _++){
            kpq *= tmp;
          }
        }
      }
      __gmpz_clear(prev);
      __gmpz_clear(cur);
      __gmpz_clear(alf);
    }
    if(pfactors >= 2){
      int f0 = factor[0];
      int f1 = factor[1];
      int cnt0 = faccnt[0];
      int cnt1 = faccnt[1];
      int kpr = kp;
      int pnr = p*n;
      struct __mpz_struct prev[1]; struct __mpz_struct cur[1]; struct __mpz_struct alf[1];
      __gmpz_init(prev);
      __gmpz_init(cur);
      __gmpz_init(alf);
      for(i = 1; i <= cnt1; i++){
        int kpqrprev = kpr;
        int kpqrcur;
        int pnqr;
        kpqrcur = kpr;
        for(j = 1; j < f1; j++){
          kpqrcur *= kpr;
        }
        kpr = kpqrcur;
        pnr *= f1;
        pnqr = pnr;
        __gmpz_set_ui(prev, 1);
        for(j = 0; j <= cnt0; j++){
          cn_eval(alf, n, kpqrprev);
          cn_eval(cur, n, kpqrcur);
          __gmpz_divexact(cur, cur, alf);
          __gmpz_divexact(alf, cur, prev);
          __gmpz_gcd(alf, alf, comp);
          if((__builtin_constant_p (1) && (1) == 0 ? ((alf)->_mp_size < 0 ? -1 : (alf)->_mp_size > 0) : __gmpz_cmp_ui (alf,1)) != 0){
            struct __mpz_struct (*afs)[1] = aur_factor(alf, pnqr, k);
            if(afs != ((void *)0)){
              nnewfactors += 2;
              cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
              memcpy(cn->newfactor[nnewfactors-2], afs[0], sizeof(mpz_t));
              memcpy(cn->newfactor[nnewfactors-1], afs[1], sizeof(mpz_t));
              free(afs);
            }else if(__gmpz_cmp(alf, comp) != 0){
              nnewfactors += 1;
              cn->newfactor = realloc(cn->newfactor, nnewfactors * sizeof(mpz_t));
              __gmpz_init(cn->newfactor[nnewfactors-1]);
              __gmpz_swap(cn->newfactor[nnewfactors-1], alf);
            }
          }
          __gmpz_swap(prev, cur);
          pnqr *= f0;
          {
            int tmpprev = kpqrprev;
            int tmpcur = kpqrcur;
            int _;
            for(_ = 1; _ < f0; _++){
              kpqrprev *= tmpprev;
              kpqrcur *= tmpcur;
            }
          }
        }
      }
      __gmpz_clear(prev);
      __gmpz_clear(cur);
      __gmpz_clear(alf);
    }
    return nnewfactors;
  }
}

variable_types: struct _cn_t { int n; int x; int nfactors; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*factor)[1]; char flag; int lf_digit; struct __mpz_struct (*newfactor)[1]; } *

variable_types: k int

variable_types: p int

variable_types:
factor
int [4]

variable_types:
faccnt
int [4]

variable_types: pfactors int

variable_types: n int

variable_types: j int

variable_types: pp int

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

variable_types: kp int

variable_types: nnewfactors int

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

variable_types: f int

variable_types: kpq int

variable_types: pnq int

variable_types: tmp int

variable_types: kpr int

variable_types: pnr int

variable_types: kpqrprev int

variable_types: kpqrcur int

variable_types: pnqr int

variable_types: tmpprev int

variable_types: tmpcur int

user_defined_types: struct _cn_t { int n; int x; int nfactors; struct __mpz_struct (*factor)[1]; char flag; int lf_digit; struct __mpz_struct (*newfactor)[1]; }


decompiled_code:
__int64 __fastcall cn_check_algebraic_factor(int *a1)
{
int v1; // er8
int v3; // ecx
int v4; // edi
unsigned int i; // esi
int v6; // edx
int v7; // eax
__int64 v9; // rax
unsigned int v10; // er8

v1 = a1[1];
if ( v1 > 3 )
{
v3 = 2;
do
v4 = v3++;
while ( 1 << v3 <= v1 );
do
{
for ( i = 2; ; ++i )
{
v6 = 0;
v7 = 1;
do
{
++v6;
v7 *= i;
}
while ( v6 != v4 );
if ( v1 == v7 )
return algebraic_factor(a1, i, v6);
if ( v1 < v7 )
break;
}
--v4;
}
while ( v4 != 1 );
}
v9 = aur_factor(*((_QWORD *)a1 + 2) + 16LL * a1[2] - 16, (unsigned int)*a1, (unsigned int)v1);
v10 = 0;
if ( v9 )
{
*((_QWORD *)a1 + 4) = v9;
v10 = 2;
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
int v1; // er8
int v3; // ecx
int v4; // edi
unsigned int i; // esi
int v6; // edx
int v7; // eax
__int64 v9; // rax
unsigned int v10; // er8

v1 = a1[1];
if ( v1 > 3 )
{
v3 = 2;
do
v4 = v3++;
while ( 1 << v3 <= v1 );
do
{
for ( i = 2; ; ++i )
{
v6 = 0;
v7 = 1;
do
{
++v6;
v7 *= i;
}
while ( v6 != v4 );
if ( v1 == v7 )
return func0(a1, i, v6);
if ( v1 < v7 )
break;
}
--v4;
}
while ( v4 != 1 );
}
v9 = aur_factor(*((_QWORD *)a1 + 2) + 16LL * a1[2] - 16, (unsigned int)*a1, (unsigned int)v1);
v10 = 0;
if ( v9 )
{
*((_QWORD *)a1 + 4) = v9;
v10 = 2;
}
return v10;
}

original_code:
int cn_check_algebraic_factor(cn_t cn){
  int x = cn->x;
  int p;
  for(p = 2; (1 << p) <= x; p++);
  while(--p > 1){
    int k = 2;
    while(1){
      int m = 1;
      int i;
      for(i = 0; i < p; i++){
        m *= k;
      }
      if(m == x){
        return algebraic_factor(cn, k, p);
      }
      if(m > x) break;
      k++;
    }
  }
  {
    mpz_t *afs = aur_factor(cn->factor[cn->nfactors-1], cn->n, x);
    if(afs == ((void *)0)) return 0;
    cn->newfactor = afs;
    return 2;
  }
}

canonical_original_code:
int cn_check_algebraic_factor(struct _cn_t *cn){
  int x = cn->x;
  int p;
  for(p = 2; (1 << p) <= x; p++);
  while(--p > 1){
    int k = 2;
    while(1){
      int m = 1;
      int i;
      for(i = 0; i < p; i++){
        m *= k;
      }
      if(m == x){
        return algebraic_factor(cn, k, p);
      }
      if(m > x) break;
      k++;
    }
  }
  {
    struct __mpz_struct (*afs)[1] = aur_factor(cn->factor[cn->nfactors-1], cn->n, x);
    if(afs == ((void *)0)) return 0;
    cn->newfactor = afs;
    return 2;
  }
}

variable_types: struct _cn_t { int n; int x; int nfactors; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*factor)[1]; char flag; int lf_digit; struct __mpz_struct (*newfactor)[1]; } *

variable_types: x int

variable_types: p int

variable_types: k int

variable_types: m int

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall cn_eval(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax
unsigned int v5; // edx
int v6; // ebx
__int64 v7; // r13
int v8; // er14
__int64 v9; // r12
__int64 result; // rax
__int64 v11; // r15
int v12; // ebx

v4 = cn_poly(a2);
v6 = v5;
v7 = v4;
v8 = v5;
v9 = pow_list(a3, v5);
result = _gmpz_set_ui(a1, 0LL);
if ( v6 >= 0 )
{
v11 = 0LL;
while ( 1 )
{
v12 = *(_DWORD *)(v7 + 4 * v11);
if ( v12 > 0 )
break;
if ( v12 )
{
do
{
result = _gmpz_sub(a1, a1, v9);
++v12;
}
while ( v12 );
++v11;
v9 += 16LL;
if ( v8 < (int)v11 )
return result;
}
else
{
LABEL_5:
++v11;
v9 += 16LL;
if ( v8 < (int)v11 )
return result;
}
}
do
{
result = _gmpz_add(a1, a1, v9);
--v12;
}
while ( v12 );
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax
unsigned int v5; // edx
int v6; // ebx
__int64 v7; // r13
int v8; // er14
__int64 v9; // r12
__int64 result; // rax
__int64 v11; // r15
int v12; // ebx

v4 = cn_poly(a2);
v6 = v5;
v7 = v4;
v8 = v5;
v9 = pow_list(a3, v5);
result = _gmpz_set_ui(a1, 0LL);
if ( v6 >= 0 )
{
v11 = 0LL;
while ( 1 )
{
v12 = *(_DWORD *)(v7 + 4 * v11);
if ( v12 > 0 )
break;
if ( v12 )
{
do
{
result = _gmpz_sub(a1, a1, v9);
++v12;
}
while ( v12 );
++v11;
v9 += 16LL;
if ( v8 < (int)v11 )
return result;
}
else
{
LABEL_5:
++v11;
v9 += 16LL;
if ( v8 < (int)v11 )
return result;
}
}
do
{
result = _gmpz_add(a1, a1, v9);
--v12;
}
while ( v12 );
goto LABEL_5;
}
return result;
}

original_code:
void cn_eval(mpz_t cn, int n, int x){
  cnpoly_t cp;
  int *poly, degree;
  mpz_t *pw;
  int i;
  cp = cn_poly(n);
  poly = cp.poly;
  degree = cp.degree;
  pw = pow_list(x, degree);
  __gmpz_set_ui(cn, 0);
  for(i = 0; i <= degree; i++){
    int j = poly[i];
    while(j > 0){
      __gmpz_add(cn, cn, pw[i]);
      j--;
    }
    while(j < 0){
      __gmpz_sub(cn, cn, pw[i]);
      j++;
    }
  }
}

canonical_original_code:
void cn_eval(struct __mpz_struct cn[1], int n, int x){
  struct cnpoly_t cp;
  int *poly; int degree;
  struct __mpz_struct (*pw)[1];
  int i;
  cp = cn_poly(n);
  poly = cp.poly;
  degree = cp.degree;
  pw = pow_list(x, degree);
  __gmpz_set_ui(cn, 0);
  for(i = 0; i <= degree; i++){
    int j = poly[i];
    while(j > 0){
      __gmpz_add(cn, cn, pw[i]);
      j--;
    }
    while(j < 0){
      __gmpz_sub(cn, cn, pw[i]);
      j++;
    }
  }
}

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

variable_types: n int

variable_types: struct cnpoly_t { int *poly; int degree; }

variable_types:
poly
int *

variable_types: degree int

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

variable_types: j int

return_type: void


decompiled_code:
__int64 __fastcall get_inversed_poly(int a1, int a2)
{
int v2; // ebx
_DWORD *v3; // rcx
__int64 result; // rax
__int64 v5; // rsi

v2 = qword_5A8[2 * a2];
v3 = malloc(4LL * (v2 + 1));
result = 16LL * a1;
*v3 = 1;
*(__int64 *)((char *)cnpoly + result) = (__int64)v3;
if ( v2 > 0 )
{
v5 = cnpoly[2 * a2];
result = 1LL;
do
{
v3[result] = -*(_DWORD *)(v5 + 4 * result);
v3[result + 1] = *(_DWORD *)(v5 + 4 * result + 4);
result += 2LL;
}
while ( v2 >= (int)result );
}
LODWORD(qword_5A8[2 * a1]) = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
int v2; // ebx
_DWORD *v3; // rcx
__int64 result; // rax
__int64 v5; // rsi

v2 = qword_5A8[2 * a2];
v3 = malloc(4LL * (v2 + 1));
result = 16LL * a1;
*v3 = 1;
*(__int64 *)((char *)cnpoly + result) = (__int64)v3;
if ( v2 > 0 )
{
v5 = cnpoly[2 * a2];
result = 1LL;
do
{
v3[result] = -*(_DWORD *)(v5 + 4 * result);
v3[result + 1] = *(_DWORD *)(v5 + 4 * result + 4);
result += 2LL;
}
while ( v2 >= (int)result );
}
LODWORD(qword_5A8[2 * a1]) = v2;
return result;
}

original_code:
static inline void get_inversed_poly(int N, int n){
  int degree;
  int i;
  degree = cnpoly[n].degree;
  cnpoly[N].poly = malloc((degree+1) * sizeof(int));
  cnpoly[N].poly[0] = 1;
  for(i = 1; i <= degree; i++){
    cnpoly[N].poly[i] = -cnpoly[n].poly[i];
    i++;
    cnpoly[N].poly[i] = cnpoly[n].poly[i];
  }
  cnpoly[N].degree = degree;
}

variable_types: N int


decompiled_code:
__int64 __fastcall get_multipled_poly(int a1, int a2)
{
int v2; // ebp
int v3; // er13
_DWORD *v4; // r14
__int64 result; // rax
int v6; // ebx
size_t v7; // r12
int *v8; // r15
int v9; // esi
int v10; // edx
int v11; // eax

v2 = a1 / a2 * LODWORD(qword_5A8[2 * a2]);
v3 = a1 / a2;
v4 = malloc(4LL * (v2 + 1));
result = 16LL * a1;
*(__int64 *)((char *)cnpoly + result) = (__int64)v4;
*v4 = 1;
if ( v2 > 0 )
{
v6 = 1;
v7 = 4LL * (unsigned int)(v3 - 2) + 4;
v8 = (int *)(cnpoly[2 * a2] + 4);
if ( v3 <= 1 )
v7 = 4LL;
do
{
memset(&v4[v6], 0, v7);
v9 = v6 + 1;
v10 = *v8;
v11 = 2;
if ( v3 >= 2 )
v11 = v3;
++v8;
v6 += v11;
result = v9 + v11 - 2;
v4[result] = v10;
}
while ( v2 >= v6 );
}
LODWORD(qword_5A8[2 * a1]) = v2;
return result;
}

original_code:
static inline void get_multipled_poly(int N, int n){
  int degree;
  int p = N / n;
  int i, j;
  degree = p * cnpoly[n].degree;
  cnpoly[N].poly = malloc((degree+1) * sizeof(int));
  cnpoly[N].poly[0] = 1;
  for(i = j = 1; i <= degree; ){
    int k = p - 1;
    do{
      cnpoly[N].poly[i++] = 0;
      k--;
    }while(k > 0);
    cnpoly[N].poly[i++] = cnpoly[n].poly[j++];
  }
  cnpoly[N].degree = degree;
}

canonical_original_code:
static inline void get_multipled_poly(int N, int n){
  int degree;
  int p = N / n;
  int i; int j;
  degree = p * cnpoly[n].degree;
  cnpoly[N].poly = malloc((degree+1) * sizeof(int));
  cnpoly[N].poly[0] = 1;
  for(i = j = 1; i <= degree; ){
    int k = p - 1;
    do{
      cnpoly[N].poly[i++] = 0;
      k--;
    }while(k > 0);
    cnpoly[N].poly[i++] = cnpoly[n].poly[j++];
  }
  cnpoly[N].degree = degree;
}


original_code:
static void cn_poly_init(int N){
  int factor[4];
  int nfactors = 0;
  int n = N;
  int p;
  int i;
  if((n & 0x1) == 0){
    do{
      n >>= 1;
    }while((n & 0x1) == 0);
    factor[nfactors++] = 2;
    p = 2;
  }else{
    p = 1;
  }
  for(i = 3; i <= n / i; i += 2){
    if(n % i != 0) continue;
    do{
      n /= i;
    }while(n % i == 0);
    factor[nfactors++] = i;
    p *= i;
  }
  if(n > 1){
    factor[nfactors++] = n;
    p *= n;
  }
  cn_poly_init_with_factors(p, factor, nfactors);
  if(N != p){
    get_multipled_poly(N, p);
  }
}

variable_types:
factor
int [4]

variable_types: nfactors int


decompiled_code:
__int64 __fastcall cn_poly(int a1)
{
if ( !cnpoly[2 * a1] )
cn_poly_init(a1);
return cnpoly[2 * a1];
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
if ( !cnpoly[2 * a1] )
func2(a1);
return cnpoly[2 * a1];
}

canonical_original_code:
struct cnpoly_t cn_poly(int N){
  if(cnpoly[N].poly == ((void *)0)){
    cn_poly_init(N);
  }
  return cnpoly[N];
}

return_type: struct cnpoly_t { int *poly; int degree; }


decompiled_code:
const char *cnpoly_init()
{
const char *result; // rax

result = (const char *)cnpoly;
do
{
*(_QWORD *)result = 0LL;
result += 16;
}
while ( result != "cn_poly.c" );
return result;
}

canonical_decompiled_code:
const char *func4()
{
const char *result; // rax

result = (const char *)cnpoly;
do
{
*(_QWORD *)result = 0LL;
result += 16;
}
while ( result != "cn_poly.c" );
return result;
}

original_code:
void cnpoly_init(){
  int i;
  for(i = 0; i <= 1000; i++){
    cnpoly[i].poly = ((void *)0);
  }
}


decompiled_code:
void cnpoly_free()
{
const char *v0; // rbx
void *v1; // rdi

v0 = (const char *)cnpoly;
do
{
v1 = *(void **)v0;
v0 += 16;
free(v1);
}
while ( v0 != "cn_poly.c" );
}

canonical_decompiled_code:
void func5()
{
const char *v0; // rbx
void *v1; // rdi

v0 = (const char *)cnpoly;
do
{
v1 = *(void **)v0;
v0 += 16;
free(v1);
}
while ( v0 != "cn_poly.c" );
}

original_code:
void cnpoly_free(){
  int i;
  for(i = 0; i <= 1000; i++){
    free(cnpoly[i].poly);
  }
}


decompiled_code:
__int64 __fastcall pow_list_append(int a1, int a2)
{
__int64 v2; // r12
__int64 v3; // rbx
char *v4; // rdi
__int64 result; // rax
int v6; // ebp
char *i; // rbx
char *v8; // rax

v2 = a1;
v3 = 2LL * a1;
v4 = (char *)powlist[v3];
if ( SHIDWORD(qword_208[v3]) < a2 )
{
v8 = (char *)realloc(v4, 16LL * (a2 + 1));
powlist[v3] = (__int64)v8;
v4 = v8;
}
result = 16 * v2;
v6 = LODWORD(qword_208[2 * v2]) + 1;
for ( i = &v4[16 * v6]; a2 >= v6; i += 16 )
{
++v6;
_gmpz_init(i);
result = _gmpz_mul_ui(i, i - 16, v2);
}
LODWORD(qword_208[2 * v2]) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__int64 v2; // r12
__int64 v3; // rbx
char *v4; // rdi
__int64 result; // rax
int v6; // ebp
char *i; // rbx
char *v8; // rax

v2 = a1;
v3 = 2LL * a1;
v4 = (char *)powlist[v3];
if ( SHIDWORD(qword_208[v3]) < a2 )
{
v8 = (char *)realloc(v4, 16LL * (a2 + 1));
powlist[v3] = (__int64)v8;
v4 = v8;
}
result = 16 * v2;
v6 = LODWORD(qword_208[2 * v2]) + 1;
for ( i = &v4[16 * v6]; a2 >= v6; i += 16 )
{
++v6;
_gmpz_init(i);
result = _gmpz_mul_ui(i, i - 16, v2);
}
LODWORD(qword_208[2 * v2]) = a2;
return result;
}

original_code:
static inline void pow_list_append(int x, int d){
  mpz_t *list = powlist[x].list;
  int i;
  if(powlist[x].maxdegree < d){
    powlist[x].list = list = realloc(list, (d+1) * sizeof(mpz_t));
  }
  for(i = powlist[x].degree+1; i <= d; i++){
    __gmpz_init(list[i]);
    __gmpz_mul_ui(list[i], list[i-1], x);
  }
  powlist[x].degree = d;
}

canonical_original_code:
static inline void pow_list_append(int x, int d){
  struct __mpz_struct (*list)[1] = powlist[x].list;
  int i;
  if(powlist[x].maxdegree < d){
    powlist[x].list = list = realloc(list, (d+1) * sizeof(mpz_t));
  }
  for(i = powlist[x].degree+1; i <= d; i++){
    __gmpz_init(list[i]);
    __gmpz_mul_ui(list[i], list[i-1], x);
  }
  powlist[x].degree = d;
}

variable_types: d int

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


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

v2 = malloc(0x1910uLL);
powlist[2 * a1] = (__int64)v2;
_gmpz_init_set_ui(v2, 1LL);
_gmpz_init_set_ui(powlist[2 * a1] + 16, a1);
qword_208[2 * a1] = 0x19000000001LL;
return pow_list_append(a1, a2);
}

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

v2 = malloc(0x1910uLL);
powlist[2 * a1] = (__int64)v2;
_gmpz_init_set_ui(v2, 1LL);
_gmpz_init_set_ui(powlist[2 * a1] + 16, a1);
qword_208[2 * a1] = 0x19000000001LL;
return func0(a1, a2);
}

original_code:
static inline void pow_list_init(int x, int d){
  powlist[x].list = malloc((400 +1) * sizeof(mpz_t));
  __gmpz_init_set_ui(powlist[x].list[0], 1);
  __gmpz_init_set_ui(powlist[x].list[1], x);
  powlist[x].degree = 1;
  powlist[x].maxdegree = 400;
  pow_list_append(x, d);
}


decompiled_code:
__int64 __fastcall pow_list(int a1, int a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = 2LL * a1;
result = powlist[v2];
if ( result )
{
if ( SLODWORD(powlist[v2 + 1]) < a2 )
{
pow_list_append(a1, a2);
result = powlist[2 * a1];
}
}
else
{
pow_list_init(a1, a2);
result = powlist[2 * a1];
}
return result;
}

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

v2 = 2LL * a1;
result = powlist[v2];
if ( result )
{
if ( SLODWORD(powlist[v2 + 1]) < a2 )
{
func0(a1, a2);
result = powlist[2 * a1];
}
}
else
{
func1(a1, a2);
result = powlist[2 * a1];
}
return result;
}

original_code:
mpz_t *pow_list(int x, int d){
  if(powlist[x].list == ((void *)0)){
    pow_list_init(x, d);
  }else if(powlist[x].degree < d){
    pow_list_append(x, d);
  }
  return powlist[x].list;
}

canonical_original_code:
struct __mpz_struct (*pow_list(int x, int d))[1]{
  if(powlist[x].list == ((void *)0)){
    pow_list_init(x, d);
  }else if(powlist[x].degree < d){
    pow_list_append(x, d);
  }
  return powlist[x].list;
}

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


decompiled_code:
__int64 *powlist_init()
{
__int64 *result; // rax

result = powlist;
do
{
*result = 0LL;
result += 2;
}
while ( result != (__int64 *)&unk_4090 );
return result;
}

canonical_decompiled_code:
__int64 *func3()
{
__int64 *result; // rax

result = powlist;
do
{
*result = 0LL;
result += 2;
}
while ( result != (__int64 *)&unk_4090 );
return result;
}

original_code:
void powlist_init(){
  int i;
  for(i = 0; i <= 1000; i++){
    powlist[i].list = ((void *)0);
  }
}


original_code:
void powlist_free(){
  int i;
  for(i = 0; i <= 1000; i++){
    if(powlist[i].list != ((void *)0)){
      int j;
      for(j = 0; j <= powlist[i].degree; j++){
        __gmpz_clear(powlist[i].list[j]);
      }
      free(powlist[i].list);
    }
  }
}


decompiled_code:
__int64 __fastcall read_int(char *a1, int *a2)
{
int v2; // eax
__int64 v3; // rdx
int v4; // ecx
unsigned int v5; // er8

v2 = *a1;
v3 = 1LL;
v4 = 0;
do
{
v5 = v3;
v4 = v2 + 10 * v4 - 48;
v2 = a1[v3++];
}
while ( (unsigned __int8)(v2 - 48) <= 9u );
*a2 = v4;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, int *a2)
{
int v2; // eax
__int64 v3; // rdx
int v4; // ecx
unsigned int v5; // er8

v2 = *a1;
v3 = 1LL;
v4 = 0;
do
{
v5 = v3;
v4 = v2 + 10 * v4 - 48;
v2 = a1[v3++];
}
while ( (unsigned __int8)(v2 - 48) <= 9u );
*a2 = v4;
return v5;
}

original_code:
static inline int read_int(const char *str, int *n){
  int x = 0;
  int i = 0;
  do{
    x = x * 10 + str[i++] - '0';
  }while(str[i] >= '0' && str[i] <= '9');
  *n = x;
  return i;
}

canonical_original_code:
static inline int read_int(char *str, int *n){
  int x = 0;
  int i = 0;
  do{
    x = x * 10 + str[i++] - '0';
  }while(str[i] >= '0' && str[i] <= '9');
  *n = x;
  return i;
}

variable_types:
str
char *

variable_types:
n
int *


variable_types: struct _cn_t { int n; int x; int nfactors; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*factor)[1]; char flag; int lf_digit; struct __mpz_struct (*newfactor)[1]; } *

variable_types: ix int

variable_types: cnt int


original_code:
static int pass2(cn_t cn, const char *str){
  mpz_t comp;
  int ret = 0;
  str = strchr(str+5, '(');
  str++;
  __gmpz_init(comp);
  cn_eval(comp, cn->n, cn->x);
  if(str[0] == '1' && str[1] == ')'){
    memcpy(cn->factor[0], comp, sizeof(mpz_t));
    cn->nfactors = 1;
  }else{
    int fix = 0;
    mpz_t tmpq, tmpr;
    __gmpz_init(tmpq);
    __gmpz_init(tmpr);
    do{
      mpz_t factor;
      int i = 0;
      while(*str >= '0' && *str <= '9'){
        buf[i++] = *str++;
      }
      buf[i] = '\0';
      __gmpz_init_set_str(factor, buf, 10);
      __gmpz_tdiv_qr(tmpq, tmpr, comp, factor);
      if(((tmpr)->_mp_size < 0 ? -1 : (tmpr)->_mp_size > 0)){
        if(ret == 0){
          ret = (4 | ((fix) << 8));
        }
      }else{
        __gmpz_set(comp, tmpq);
        if(!__gmpz_probab_prime_p(factor, 30)){
          if(ret == 0){
            ret = (5 | ((fix) << 8));
          }
        }
        if(fix > 0 && __gmpz_cmp(cn->factor[fix-1], factor) > 0){
          if(ret == 0){
            ret = (6 | ((fix) << 8));
          }
        }
        memcpy(cn->factor[fix++], factor, sizeof(mpz_t));
      }
    }while(*str++ == ' ');
    __gmpz_clear(tmpq);
    __gmpz_clear(tmpr);
    memcpy(cn->factor[fix++], comp, sizeof(mpz_t));
    cn->nfactors = fix;
  }
  {
    char realflag;
    int realdigit;
    realflag = __gmpz_probab_prime_p(comp, 30) ? 'P' : 'C';
    if(cn->flag != realflag){
      ret |= (1 << 3);
    }
    if(cn->nfactors > 1 && realflag == 'P'
    && __gmpz_cmp(cn->factor[cn->nfactors-2], comp) > 0){
      ret |= (1 << 4);
    }
    realdigit = strlen(__gmpz_get_str(buf, 10, comp));
    if(cn->lf_digit != realdigit){
      ret |= ((1 << 5) | ((realdigit) << 16));
    }
  }
  return ret;
}

canonical_original_code:
static int pass2(struct _cn_t *cn, char *str){
  struct __mpz_struct comp[1];
  int ret = 0;
  str = strchr(str+5, '(');
  str++;
  __gmpz_init(comp);
  cn_eval(comp, cn->n, cn->x);
  if(str[0] == '1' && str[1] == ')'){
    memcpy(cn->factor[0], comp, sizeof(mpz_t));
    cn->nfactors = 1;
  }else{
    int fix = 0;
    struct __mpz_struct tmpq[1]; struct __mpz_struct tmpr[1];
    __gmpz_init(tmpq);
    __gmpz_init(tmpr);
    do{
      struct __mpz_struct factor[1];
      int i = 0;
      while(*str >= '0' && *str <= '9'){
        buf[i++] = *str++;
      }
      buf[i] = '\0';
      __gmpz_init_set_str(factor, buf, 10);
      __gmpz_tdiv_qr(tmpq, tmpr, comp, factor);
      if(((tmpr)->_mp_size < 0 ? -1 : (tmpr)->_mp_size > 0)){
        if(ret == 0){
          ret = (4 | ((fix) << 8));
        }
      }else{
        __gmpz_set(comp, tmpq);
        if(!__gmpz_probab_prime_p(factor, 30)){
          if(ret == 0){
            ret = (5 | ((fix) << 8));
          }
        }
        if(fix > 0 && __gmpz_cmp(cn->factor[fix-1], factor) > 0){
          if(ret == 0){
            ret = (6 | ((fix) << 8));
          }
        }
        memcpy(cn->factor[fix++], factor, sizeof(mpz_t));
      }
    }while(*str++ == ' ');
    __gmpz_clear(tmpq);
    __gmpz_clear(tmpr);
    memcpy(cn->factor[fix++], comp, sizeof(mpz_t));
    cn->nfactors = fix;
  }
  {
    char realflag;
    int realdigit;
    realflag = __gmpz_probab_prime_p(comp, 30) ? 'P' : 'C';
    if(cn->flag != realflag){
      ret |= (1 << 3);
    }
    if(cn->nfactors > 1 && realflag == 'P'
    && __gmpz_cmp(cn->factor[cn->nfactors-2], comp) > 0){
      ret |= (1 << 4);
    }
    realdigit = strlen(__gmpz_get_str(buf, 10, comp));
    if(cn->lf_digit != realdigit){
      ret |= ((1 << 5) | ((realdigit) << 16));
    }
  }
  return ret;
}

variable_types: ret int

variable_types: fix int

variable_types: i int

variable_types: realflag char

variable_types: realdigit int


decompiled_code:
__int64 __fastcall cn_set_str(unsigned int *a1, __int64 a2)
{
__int64 result; // rax

result = pass1((__int64)a1, a2);
if ( !(_DWORD)result )
result = pass2(a1, a2);
return result;
}

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

result = func1((__int64)a1, a2);
if ( !(_DWORD)result )
result = func2(a1, a2);
return result;
}

original_code:
int cn_set_str(cn_t cn, const char *str){
  int ret;
  ret = pass1(cn, str);
  if(ret != 0){
    return ret;
  }
  return pass2(cn, str);
}

canonical_original_code:
int cn_set_str(struct _cn_t *cn, char *str){
  int ret;
  ret = pass1(cn, str);
  if(ret != 0){
    return ret;
  }
  return pass2(cn, str);
}


original_code:
int cn_add_factor(cn_t cn, const char *str){
  mpz_t comp, factor;
  mpz_t tmpq, tmpr;
  int i;
  __gmpz_init(factor);
  __gmpz_init(tmpq);
  __gmpz_init(tmpr);
  if(cn->flag != 'C') goto err;
  memcpy(comp, cn->factor[cn->nfactors-1], sizeof(mpz_t));
  __gmpz_set_str(factor, str, 10);
  if(!__gmpz_probab_prime_p(factor, 30)) goto err;
  __gmpz_tdiv_qr(tmpq, tmpr, comp, factor);
  if(((tmpr)->_mp_size < 0 ? -1 : (tmpr)->_mp_size > 0)) goto err;
  if((__builtin_constant_p (1) && (1) == 0 ? ((tmpq)->_mp_size < 0 ? -1 : (tmpq)->_mp_size > 0) : __gmpz_cmp_ui (tmpq,1)) <= 0) goto err;
  cn->flag = __gmpz_probab_prime_p(tmpq, 30) ? 'P' : 'C';
  cn->factor = realloc(cn->factor, (cn->nfactors+1) * sizeof(mpz_t));
  for(i = 0; i < cn->nfactors; i++){
    if(__gmpz_cmp(cn->factor[i], factor) > 0){
      memmove(cn->factor[i+1], cn->factor[i], (cn->nfactors-i) * sizeof(mpz_t));
      memcpy(cn->factor[i], factor, sizeof(mpz_t));
      cn->nfactors++;
      break;
    }
  }
  if(cn->flag == 'P'){
    for(i = 0; i < cn->nfactors; i++){
      if(__gmpz_cmp(cn->factor[i], tmpq) > 0){
        memmove(cn->factor[i+1], cn->factor[i], (cn->nfactors-i-1) * sizeof(mpz_t));
        __gmpz_set(comp, tmpq);
        memcpy(cn->factor[i], comp, sizeof(mpz_t));
        break;
      }
    }
  }else{
    __gmpz_set(cn->factor[cn->nfactors-1], tmpq);
  }
  {
    static char buf[1024];
    cn->lf_digit = strlen(__gmpz_get_str(buf, 10, cn->factor[cn->nfactors-1]));
  }
  __gmpz_clear(tmpq);
  __gmpz_clear(tmpr);
  return 0;
err:
  __gmpz_clear(factor);
  __gmpz_clear(tmpq);
  __gmpz_clear(tmpr);
  return (4 | ((0) << 8));
}

canonical_original_code:
int cn_add_factor(struct _cn_t *cn, char *str){
  struct __mpz_struct comp[1]; struct __mpz_struct factor[1];
  struct __mpz_struct tmpq[1]; struct __mpz_struct tmpr[1];
  int i;
  __gmpz_init(factor);
  __gmpz_init(tmpq);
  __gmpz_init(tmpr);
  if(cn->flag != 'C') goto err;
  memcpy(comp, cn->factor[cn->nfactors-1], sizeof(mpz_t));
  __gmpz_set_str(factor, str, 10);
  if(!__gmpz_probab_prime_p(factor, 30)) goto err;
  __gmpz_tdiv_qr(tmpq, tmpr, comp, factor);
  if(((tmpr)->_mp_size < 0 ? -1 : (tmpr)->_mp_size > 0)) goto err;
  if((__builtin_constant_p (1) && (1) == 0 ? ((tmpq)->_mp_size < 0 ? -1 : (tmpq)->_mp_size > 0) : __gmpz_cmp_ui (tmpq,1)) <= 0) goto err;
  cn->flag = __gmpz_probab_prime_p(tmpq, 30) ? 'P' : 'C';
  cn->factor = realloc(cn->factor, (cn->nfactors+1) * sizeof(mpz_t));
  for(i = 0; i < cn->nfactors; i++){
    if(__gmpz_cmp(cn->factor[i], factor) > 0){
      memmove(cn->factor[i+1], cn->factor[i], (cn->nfactors-i) * sizeof(mpz_t));
      memcpy(cn->factor[i], factor, sizeof(mpz_t));
      cn->nfactors++;
      break;
    }
  }
  if(cn->flag == 'P'){
    for(i = 0; i < cn->nfactors; i++){
      if(__gmpz_cmp(cn->factor[i], tmpq) > 0){
        memmove(cn->factor[i+1], cn->factor[i], (cn->nfactors-i-1) * sizeof(mpz_t));
        __gmpz_set(comp, tmpq);
        memcpy(cn->factor[i], comp, sizeof(mpz_t));
        break;
      }
    }
  }else{
    __gmpz_set(cn->factor[cn->nfactors-1], tmpq);
  }
  {
    static char buf[1024];
    cn->lf_digit = strlen(__gmpz_get_str(buf, 10, cn->factor[cn->nfactors-1]));
  }
  __gmpz_clear(tmpq);
  __gmpz_clear(tmpr);
  return 0;
err:
  __gmpz_clear(factor);
  __gmpz_clear(tmpq);
  __gmpz_clear(tmpr);
  return (4 | ((0) << 8));
}

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

variable_types:
buf
char [1024]


original_code:
static int q_update(int N){
  static int aurtable[4][4] = {
    { 0, 0, 0, 0},
    { 1, 1, 1, 1},
    { 2, 0, -2, 0},
    { 1, -1, 1, -1}
  };
  int factor[4];
  int nfactors = 0;
  int n = N;
  int phi;
  int k, i;
  if((n & 0x1) == 0){
    n >>= 1;
    factor[nfactors++] = 2;
    phi = 2;
  }else{
    phi = 1;
  }
  for(i = 3; i <= n / i; i += 2){
    if(n % i != 0) continue;
    n /= i;
    factor[nfactors++] = i;
    phi *= i-1;
  }
  if(n > 1){
    factor[nfactors++] = n;
    phi *= n-1;
  }
  phi = (phi+1) >> 1;
  q[0] = 0;
  k = 1;
  do{
    {
      int kk;
      kk = k + k - 1;
      for(i = 0; i < nfactors; i++){
        if(kk % factor[i] == 0){
          q[kk] = 0;
          goto nojacobi;
        }
      }
      q[kk] = jacobi(N, kk);
nojacobi:;
    }
    {
      int r = aurtable[N & 0x3][k & 0x3];
      for(i = 0; i < nfactors; i++){
        if(k % factor[i] == 0){
          r *= factor[i]-1;
        }else{
          r = -r;
        }
      }
      q[k+k] = r;
    }
    k++;
  }while(k <= phi);
  return phi;
}

canonical_original_code:
static int q_update(int N){
  static int aurtable[4][4] = {
    { 0, 0, 0, 0},
    { 1, 1, 1, 1},
    { 2, 0, -2, 0},
    { 1, -1, 1, -1}
  };
  int factor[4];
  int nfactors = 0;
  int n = N;
  int phi;
  int k; int i;
  if((n & 0x1) == 0){
    n >>= 1;
    factor[nfactors++] = 2;
    phi = 2;
  }else{
    phi = 1;
  }
  for(i = 3; i <= n / i; i += 2){
    if(n % i != 0) continue;
    n /= i;
    factor[nfactors++] = i;
    phi *= i-1;
  }
  if(n > 1){
    factor[nfactors++] = n;
    phi *= n-1;
  }
  phi = (phi+1) >> 1;
  q[0] = 0;
  k = 1;
  do{
    {
      int kk;
      kk = k + k - 1;
      for(i = 0; i < nfactors; i++){
        if(kk % factor[i] == 0){
          q[kk] = 0;
          goto nojacobi;
        }
      }
      q[kk] = jacobi(N, kk);
nojacobi:;
    }
    {
      int r = aurtable[N & 0x3][k & 0x3];
      for(i = 0; i < nfactors; i++){
        if(k % factor[i] == 0){
          r *= factor[i]-1;
        }else{
          r = -r;
        }
      }
      q[k+k] = r;
    }
    k++;
  }while(k <= phi);
  return phi;
}

variable_types:
aurtable
int [4][4]

variable_types: n int

variable_types: phi int

variable_types: k int

variable_types: kk int

variable_types: r int


decompiled_code:
__int64 __fastcall aur_Cpoly(int a1)
{
if ( !aurCpoly[2 * a1] )
aur_poly_init(a1);
return aurCpoly[2 * a1];
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
if ( !aurCpoly[2 * a1] )
aur_poly_init(a1);
return aurCpoly[2 * a1];
}

canonical_original_code:
struct aurpoly_t aur_Cpoly(int n){
  if(aurCpoly[n].poly == ((void *)0)){
    aur_poly_init(n);
  }
  return aurCpoly[n];
}

return_type: struct aurpoly_t { long *poly; int degree; }


decompiled_code:
__int64 __fastcall aur_Dpoly(int a1)
{
if ( !aurDpoly[2 * a1] )
aur_poly_init(a1);
return aurDpoly[2 * a1];
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
if ( !aurDpoly[2 * a1] )
aur_poly_init(a1);
return aurDpoly[2 * a1];
}

canonical_original_code:
struct aurpoly_t aur_Dpoly(int n){
  if(aurDpoly[n].poly == ((void *)0)){
    aur_poly_init(n);
  }
  return aurDpoly[n];
}

user_defined_types: struct aurpoly_t { long *poly; int degree; }


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

for ( result = 0LL; result != 2002; qword_B30[result] = 0LL )
{
aurCpoly[result] = 0LL;
result += 2LL;
}
return result * 8;
}

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

for ( result = 0LL; result != 2002; qword_B30[result] = 0LL )
{
aurCpoly[result] = 0LL;
result += 2LL;
}
return result * 8;
}

original_code:
void aurpoly_init(){
  int i;
  for(i = 0; i <= 1000; i++){
    aurCpoly[i].poly = ((void *)0);
    aurDpoly[i].poly = ((void *)0);
  }
}


decompiled_code:
void aurpoly_free()
{
__int64 i; // rbx
void *v1; // rdi

for ( i = 0LL; i != 2002; free((void *)qword_B30[i]) )
{
v1 = (void *)aurCpoly[i];
i += 2LL;
free(v1);
}
}

canonical_decompiled_code:
void func5()
{
__int64 i; // rbx
void *v1; // rdi

for ( i = 0LL; i != 2002; free((void *)qword_B30[i]) )
{
v1 = (void *)aurCpoly[i];
i += 2LL;
free(v1);
}
}

original_code:
void aurpoly_free(){
  int i;
  for(i = 0; i <= 1000; i++){
    free(aurCpoly[i].poly);
    free(aurDpoly[i].poly);
  }
}


main

canonical_name: main

repo: nubbel/simple-gpio

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__uid_t v4; // er13
__gid_t v5; // er14
bool v6; // cf
bool v7; // zf
int v8; // eax
const char *v9; // rdi
__int64 v10; // rcx
unsigned int v11; // er12
const char *v12; // rax
const char *v13; // rsi
char v14; // dl
bool v15; // cf
bool v16; // zf
const char *v17; // rsi
const char *v18; // rdi
__int64 v19; // rcx
int *v21; // rbp
unsigned int v22; // eax

v4 = getuid();
v5 = getgid();
if ( setuid(0) < 0 )
{
v21 = __errno_location();
v22 = (unsigned int)strerror(*v21);
fprintf(stderr, "setuid() failed: %d - %s\n", (unsigned int)*v21, (const char *)v22);
exit(-*v21);
}
if ( argc != 3 )
printUsage(argv);
v8 = atoi(argv[2]);
v9 = "export";
v10 = 7LL;
v11 = v8;
v12 = argv[1];
v13 = v12;
do
{
if ( !v10 )
break;
v6 = *v13 < (unsigned int)*v9;
v7 = *v13++ == *v9++;
--v10;
}
while ( v7 );
v14 = (!v6 && !v7) - v6;
v15 = 0;
v16 = v14 == 0;
if ( !v14 )
{
export(v11, v13);
changeOwner(v11, "value", v4, v5);
changeOwner(v11, "direction", v4, v5);
v12 = argv[1];
}
v17 = v12;
v18 = "unexport";
v19 = 9LL;
do
{
if ( !v19 )
break;
v15 = *v17 < (unsigned int)*v18;
v16 = *v17++ == *v18++;
--v19;
}
while ( v16 );
if ( (!v15 && !v16) == v15 )
unexport(v11, v17);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__uid_t v4; // er13
__gid_t v5; // er14
bool v6; // cf
bool v7; // zf
int v8; // eax
const char *v9; // rdi
__int64 v10; // rcx
unsigned int v11; // er12
const char *v12; // rax
const char *v13; // rsi
char v14; // dl
bool v15; // cf
bool v16; // zf
const char *v17; // rsi
const char *v18; // rdi
__int64 v19; // rcx
int *v21; // rbp
unsigned int v22; // eax

v4 = getuid();
v5 = getgid();
if ( setuid(0) < 0 )
{
v21 = __errno_location();
v22 = (unsigned int)strerror(*v21);
fprintf(stderr, "setuid() failed: %d - %s\n", (unsigned int)*v21, (const char *)v22);
exit(-*v21);
}
if ( argc != 3 )
func7(argv);
v8 = atoi(argv[2]);
v9 = "export";
v10 = 7LL;
v11 = v8;
v12 = argv[1];
v13 = v12;
do
{
if ( !v10 )
break;
v6 = *v13 < (unsigned int)*v9;
v7 = *v13++ == *v9++;
--v10;
}
while ( v7 );
v14 = (!v6 && !v7) - v6;
v15 = 0;
v16 = v14 == 0;
if ( !v14 )
{
func10(v11, v13);
func8(v11, "value", v4, v5);
func8(v11, "direction", v4, v5);
v12 = argv[1];
}
v17 = v12;
v18 = "unexport";
v19 = 9LL;
do
{
if ( !v19 )
break;
v15 = *v17 < (unsigned int)*v18;
v16 = *v17++ == *v18++;
--v19;
}
while ( v16 );
if ( (!v15 && !v16) == v15 )
func11(v11, v17);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int uid, gid;
 uid = getuid();
 gid = getgid();
    if (setuid(0) < 0) {
     fprintf(stderr, "setuid() failed: %d - %s\n", (*__errno_location ()), strerror((*__errno_location ())));
  exit(-(*__errno_location ()));
    }
    if (argc == 3) {
     int pin = atoi(argv[2]);
     if (strcmp(argv[1], "export") == 0) {
      export(pin);
      changeOwner(pin, "value", uid, gid);
      changeOwner(pin, "direction", uid, gid);
     }
     if (strcmp(argv[1], "unexport") == 0) {
      unexport(pin);
     }
    }
    else {
     printUsage(argv);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int uid; int gid;
 uid = getuid();
 gid = getgid();
    if (setuid(0) < 0) {
     fprintf(stderr, "setuid() failed: %d - %s\n", (*__errno_location ()), strerror((*__errno_location ())));
  exit(-(*__errno_location ()));
    }
    if (argc == 3) {
     int pin = atoi(argv[2]);
     if (strcmp(argv[1], "export") == 0) {
      export(pin);
      changeOwner(pin, "value", uid, gid);
      changeOwner(pin, "direction", uid, gid);
     }
     if (strcmp(argv[1], "unexport") == 0) {
      unexport(pin);
     }
    }
    else {
     printUsage(argv);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: uid int

variable_types: gid int

variable_types: pin int


printUsage

decompiled_code:
void __fastcall __noreturn printUsage(const char **a1)
{
fprintf(stderr, "Usage: %s export <pin>\n\n", *a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char **a1)
{
fprintf(stderr, "Usage: %s export <pin>\n\n", *a1);
exit(1);
}

original_code:
void printUsage(char *argv[]) {
 fprintf(stderr, "Usage: %s export <pin>\n\n", argv[0]);
 exit(1);
}


changeOwner

decompiled_code:
int __fastcall changeOwner(unsigned int a1, const char *a2, __uid_t a3, __gid_t a4)
{
int result; // eax
int *v7; // rbp
char *v8; // rax
char v9[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( snprintf(v9, 0x1000uLL, "/sys/class/gpio/gpio%d/%s", a1, a2) > 4095 )
return fwrite("Path of GPIO pin is too long!", 1uLL, 0x1DuLL, stderr);
result = chown(v9, a3, a4);
if ( result < 0 )
{
v7 = __errno_location();
v8 = strerror(*v7);
fprintf(stderr, "Failed to change ownership of file %s to (%d:%d): %d - %s\n", v9, a3, a4, (unsigned int)*v7, v8);
exit(-*v7);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, const char *a2, __uid_t a3, __gid_t a4)
{
int result; // eax
int *v7; // rbp
char *v8; // rax
char v9[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( snprintf(v9, 0x1000uLL, "/sys/class/gpio/gpio%d/%s", a1, a2) > 4095 )
return fwrite("Path of GPIO pin is too long!", 1uLL, 0x1DuLL, stderr);
result = chown(v9, a3, a4);
if ( result < 0 )
{
v7 = __errno_location();
v8 = strerror(*v7);
fprintf(stderr, "Failed to change ownership of file %s to (%d:%d): %d - %s\n", v9, a3, a4, (unsigned int)*v7, v8);
exit(-*v7);
}
return result;
}

original_code:
void changeOwner(int pin, const char *filename, int uid, int gid) {
   char path[4096];
   int size = snprintf(path, 4096, "/sys/class/gpio/gpio%d/%s", pin, filename);
   if (size >= 4096) {
    fprintf(stderr, "Path of GPIO pin is too long!");
     return;
   }
 if (chown(path, uid, gid) < 0) {
     fprintf(stderr, "Failed to change ownership of file %s to (%d:%d): %d - %s\n", path, uid, gid, (*__errno_location ()), strerror((*__errno_location ())));
  exit(-(*__errno_location ()));
 }
}

canonical_original_code:
void changeOwner(int pin, char *filename, int uid, int gid) {
   char path[4096];
   int size = snprintf(path, 4096, "/sys/class/gpio/gpio%d/%s", pin, filename);
   if (size >= 4096) {
    fprintf(stderr, "Path of GPIO pin is too long!");
     return;
   }
 if (chown(path, uid, gid) < 0) {
     fprintf(stderr, "Failed to change ownership of file %s to (%d:%d): %d - %s\n", path, uid, gid, (*__errno_location ()), strerror((*__errno_location ())));
  exit(-(*__errno_location ()));
 }
}

variable_types:
filename
char *

variable_types:
path
char [4096]

variable_types: size int


export

decompiled_code:
int __fastcall export(unsigned int a1)
{
return writePinToFile(a1, "/sys/class/gpio/export");
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1)
{
return func9(a1, "/sys/class/gpio/export");
}

original_code:
void export(int pin) {
 writePinToFile(pin, "/sys/class/gpio/export");
}


unexport

decompiled_code:
int __fastcall unexport(unsigned int a1)
{
return writePinToFile(a1, "/sys/class/gpio/unexport");
}

canonical_decompiled_code:
int __fastcall func11(unsigned int a1)
{
return func9(a1, "/sys/class/gpio/unexport");
}

original_code:
void unexport(int pin) {
 writePinToFile(pin, "/sys/class/gpio/unexport");
}


repo: nuclearsandwich/pash

decompiled_code:
void *parse_value()
{
void *v0; // rax
const char *v1; // rsi
void *v2; // r12

v0 = malloc(0x50uLL);
v1 = tokens;
*((_QWORD *)v0 + 9) = 0LL;
v2 = v0;
*(_DWORD *)v0 = 1;
strncpy((char *)v0 + 4, v1, 0x40uLL);
return v2;
}

canonical_decompiled_code:
void *func0()
{
void *v0; // rax
const char *v1; // rsi
void *v2; // r12

v0 = malloc(0x50uLL);
v1 = tokens;
*((_QWORD *)v0 + 9) = 0LL;
v2 = v0;
*(_DWORD *)v0 = 1;
strncpy((char *)v0 + 4, v1, 0x40uLL);
return v2;
}

original_code:
ast_node *parse_value() {
 ast_node *value = malloc(sizeof(ast_node));
 value->children = ((void *)0);
 value->type = VALUE;
 strncpy(value->token, tokens->str, 64);
 return value;
}

canonical_original_code:
struct node *parse_value() {
 struct node *value = malloc(sizeof(ast_node));
 value->children = ((void *)0);
 value->type = VALUE;
 strncpy(value->token, tokens->str, 64);
 return value;
}

variable_types: struct node { enum node_type { VARASSIGN=0, VALUE=1, VARIABLE=2, COMMAND=3, ARGLIST=4, REDIRECTLIST=5, STDIN_REDIRECT=6, STDOUT_REDIRECT=7, STDERR_REDIRECT=8, DATA_VARIABLE=9, BACKGROUND_KEY=10, NEGATED_COMMAND=11 } type; char token[64]; struct nodelist { struct node *node; struct nodelist *next; } *children; } *

user_defined_types: struct node { enum node_type type; char token[64]; struct nodelist *children; }


decompiled_code:
_QWORD *parse_variable_expression()
{
char *v0; // rbx
int v1; // ebp
_QWORD *v2; // rax
_QWORD *v3; // r8
__int64 v4; // rax

v0 = tokens;
v1 = strlen(tokens);
v2 = malloc(0x50uLL);
*(_DWORD *)v2 = 2;
v3 = v2;
v2[9] = 0LL;
if ( v1 > 0 )
{
v4 = 1LL;
do
{
*((_BYTE *)v3 + v4 + 3) = v0[v4];
++v4;
}
while ( v4 != (unsigned int)(v1 - 1) + 2LL );
}
return v3;
}

canonical_decompiled_code:
_QWORD *func1()
{
char *v0; // rbx
int v1; // ebp
_QWORD *v2; // rax
_QWORD *v3; // r8
__int64 v4; // rax

v0 = tokens;
v1 = strlen(tokens);
v2 = malloc(0x50uLL);
*(_DWORD *)v2 = 2;
v3 = v2;
v2[9] = 0LL;
if ( v1 > 0 )
{
v4 = 1LL;
do
{
*((_BYTE *)v3 + v4 + 3) = v0[v4];
++v4;
}
while ( v4 != (unsigned int)(v1 - 1) + 2LL );
}
return v3;
}

original_code:
ast_node *parse_variable_expression() {
 int i, varlen = strlen(tokens->str);
 ast_node *variable = malloc(sizeof(ast_node));
 variable->type = VARIABLE;
 variable->children = ((void *)0);
 for (i = 0; i < varlen; i++) {
  variable->token[i] = tokens->str[i + 1];
 }
 return variable;
}

canonical_original_code:
struct node *parse_variable_expression() {
 int i; int varlen = strlen(tokens->str);
 struct node *variable = malloc(sizeof(ast_node));
 variable->type = VARIABLE;
 variable->children = ((void *)0);
 for (i = 0; i < varlen; i++) {
  variable->token[i] = tokens->str[i + 1];
 }
 return variable;
}

variable_types: i int

variable_types: varlen int

return_type: struct node { enum node_type { VARASSIGN=0, VALUE=1, VARIABLE=2, COMMAND=3, ARGLIST=4, REDIRECTLIST=5, STDIN_REDIRECT=6, STDOUT_REDIRECT=7, STDERR_REDIRECT=8, DATA_VARIABLE=9, BACKGROUND_KEY=10, NEGATED_COMMAND=11 } type; char token[64]; struct nodelist { struct node *node; struct nodelist *next; } *children; } *


decompiled_code:
_DWORD *parse_data_variable()
{
char *v0; // rbx
int v1; // ebp
_DWORD *v2; // rax
_DWORD *v3; // r8
__int64 v4; // rax
__int64 v5; // rdx

v0 = tokens;
v1 = strlen(tokens);
v2 = malloc(0x50uLL);
*v2 = 9;
v3 = v2;
if ( v1 > 0 )
{
v4 = 0LL;
do
{
*((_BYTE *)v3 + v4 + 4) = v0[v4 + 3];
v5 = v4++;
}
while ( v5 != v1 - 1 );
}
return v3;
}

canonical_decompiled_code:
_DWORD *func2()
{
char *v0; // rbx
int v1; // ebp
_DWORD *v2; // rax
_DWORD *v3; // r8
__int64 v4; // rax
__int64 v5; // rdx

v0 = tokens;
v1 = strlen(tokens);
v2 = malloc(0x50uLL);
*v2 = 9;
v3 = v2;
if ( v1 > 0 )
{
v4 = 0LL;
do
{
*((_BYTE *)v3 + v4 + 4) = v0[v4 + 3];
v5 = v4++;
}
while ( v5 != v1 - 1 );
}
return v3;
}

original_code:
ast_node *parse_data_variable() {
 ast_node *data_variable;
 int i, varlen = strlen(tokens->str);
 data_variable = malloc(sizeof(ast_node));
 data_variable->type = DATA_VARIABLE;
 for (i = 0; i < varlen; i++) {
  data_variable->token[i] = tokens->str[i + 3];
 }
 return data_variable;
}

canonical_original_code:
struct node *parse_data_variable() {
 struct node *data_variable;
 int i; int varlen = strlen(tokens->str);
 data_variable = malloc(sizeof(ast_node));
 data_variable->type = DATA_VARIABLE;
 for (i = 0; i < varlen; i++) {
  data_variable->token[i] = tokens->str[i + 3];
 }
 return data_variable;
}

user_defined_types: enum node_type { VARASSIGN=0, VALUE=1, VARIABLE=2, COMMAND=3, ARGLIST=4, REDIRECTLIST=5, STDIN_REDIRECT=6, STDOUT_REDIRECT=7, STDERR_REDIRECT=8, DATA_VARIABLE=9, BACKGROUND_KEY=10, NEGATED_COMMAND=11 }

user_defined_types: struct nodelist { struct node *node; struct nodelist *next; }


decompiled_code:
void strip_head()
{
char *v0; // rdi

v0 = tokens;
if ( tokens )
{
tokens = (char *)*((_QWORD *)tokens + 8);
free(v0);
}
}

canonical_decompiled_code:
void func3()
{
char *v0; // rdi

v0 = tokens;
if ( tokens )
{
tokens = (char *)*((_QWORD *)tokens + 8);
free(v0);
}
}

original_code:
void strip_head() {
 if (tokens == ((void *)0)) {
  return;
 }
 strlist *head = tokens;
 tokens = head->next;
 free(head);
}

canonical_original_code:
void strip_head() {
 if (tokens == ((void *)0)) {
  return;
 }
 struct sllist *head = tokens;
 tokens = head->next;
 free(head);
}

variable_types: struct sllist { char str[64]; struct sllist *next; } *


decompiled_code:
_QWORD *parse_background_key()
{
_QWORD *result; // rax

strip_head();
result = malloc(0x50uLL);
*(_DWORD *)result = 10;
result[9] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func4()
{
_QWORD *result; // rax

func3();
result = malloc(0x50uLL);
*(_DWORD *)result = 10;
result[9] = 0LL;
return result;
}

original_code:
ast_node *parse_background_key() {
 strip_head();
 ast_node *background_key = malloc(sizeof(ast_node));
 background_key->type = BACKGROUND_KEY;
 background_key->children = ((void *)0);
 return background_key;
}

canonical_original_code:
struct node *parse_background_key() {
 strip_head();
 struct node *background_key = malloc(sizeof(ast_node));
 background_key->type = BACKGROUND_KEY;
 background_key->children = ((void *)0);
 return background_key;
}


decompiled_code:
__int64 __fastcall contains_eql(const char *a1)
{
size_t v1; // rdx
__int64 v2; // rax
unsigned int v3; // er8

v1 = strlen(a1);
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( v1 == v2 )
break;
if ( a1[v2++] == 61 )
return v3;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
size_t v1; // rdx
__int64 v2; // rax
unsigned int v3; // er8

v1 = strlen(a1);
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( v1 == v2 )
break;
if ( a1[v2++] == 61 )
return v3;
}
return (unsigned int)-1;
}

original_code:
int contains_eql(char *str) {
 int i;
 for (i = 0; i < strlen(str); i++) {
  if (str[i] == '=') {
   return i;
  }
 }
 return -1;
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall contains_colon(const char *a1)
{
size_t v1; // rdx
__int64 v2; // rax
unsigned int v3; // er8

v1 = strlen(a1);
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( v1 == v2 )
break;
if ( a1[v2++] == 58 )
return v3;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
size_t v1; // rdx
__int64 v2; // rax
unsigned int v3; // er8

v1 = strlen(a1);
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( v1 == v2 )
break;
if ( a1[v2++] == 58 )
return v3;
}
return (unsigned int)-1;
}

original_code:
int contains_colon(char *str) {
 int i;
 for (i = 0; i < strlen(str); i++) {
  if (str[i] == ':') {
   return i;
  }
 }
 return -1;
}


decompiled_code:
__int64 is_redirect_token()
{
int v0; // edx

v0 = (unsigned __int8)*tokens;
if ( v0 == 60 && !tokens[1] )
return 4LL;
if ( v0 == 62 && !tokens[1] )
return 1LL;
if ( *tokens == 50 && tokens[1] == 62 && !tokens[2] )
return 2LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // edx

v0 = (unsigned __int8)*tokens;
if ( v0 == 60 && !tokens[1] )
return 4LL;
if ( v0 == 62 && !tokens[1] )
return 1LL;
if ( *tokens == 50 && tokens[1] == 62 && !tokens[2] )
return 2LL;
return 0LL;
}

original_code:
int is_redirect_token() {
 if (strcmp(tokens->str, "<") == 0) {
  return 4;
 } else if (strcmp(tokens->str, ">") == 0) {
  return 1;
 } else if (strcmp(tokens->str, "2>") == 0) {
  return 2;
 } else {
  return 0;
 }
}


decompiled_code:
_BOOL8 is_background_key()
{
int v0; // eax

v0 = (unsigned __int8)*tokens - 38;
if ( *tokens == 38 )
v0 = (unsigned __int8)tokens[1];
return v0 == 0;
}

canonical_decompiled_code:
_BOOL8 func8()
{
int v0; // eax

v0 = (unsigned __int8)*tokens - 38;
if ( *tokens == 38 )
v0 = (unsigned __int8)tokens[1];
return v0 == 0;
}

original_code:
int is_background_key() {
 if (strcmp(tokens->str, "&") == 0) {
  return 1;
 } else {
  return 0;
 }
}


decompiled_code:
_BOOL8 is_special_token()
{
int v0; // eax
_BOOL4 v1; // er8
int v2; // eax
int v3; // eax

v0 = is_redirect_token();
v1 = 1;
if ( !v0 && !is_background_key() )
{
v2 = (unsigned __int8)*tokens;
if ( v2 != 38 || tokens[1] != 38 || tokens[2] )
{
v3 = v2 - 124;
if ( !v3 )
{
v3 = (unsigned __int8)tokens[1] - 124;
if ( tokens[1] == 124 )
v3 = (unsigned __int8)tokens[2];
}
v1 = v3 == 0;
}
}
return v1;
}

canonical_decompiled_code:
_BOOL8 func9()
{
int v0; // eax
_BOOL4 v1; // er8
int v2; // eax
int v3; // eax

v0 = func7();
v1 = 1;
if ( !v0 && !func8() )
{
v2 = (unsigned __int8)*tokens;
if ( v2 != 38 || tokens[1] != 38 || tokens[2] )
{
v3 = v2 - 124;
if ( !v3 )
{
v3 = (unsigned __int8)tokens[1] - 124;
if ( tokens[1] == 124 )
v3 = (unsigned __int8)tokens[2];
}
v1 = v3 == 0;
}
}
return v1;
}

original_code:
int is_special_token() {
 if (is_redirect_token() || is_background_key()) {
  return 1;
 }
 if (strcmp(tokens->str, "&&") == 0) {
  return 1;
 } else if (strcmp(tokens->str, "||") == 0) {
  return 1;
 } else {
  return 0;
 }
}


decompiled_code:
_QWORD *parse_arg()
{
_BYTE *v0; // rcx

if ( !tokens )
return 0LL;
if ( is_special_token() )
return 0LL;
if ( *v0 == 36 )
return parse_variable_expression();
if ( *(_WORD *)v0 == 17443 && v0[2] == 58 )
return parse_data_variable();
return parse_value();
}

canonical_decompiled_code:
_QWORD *func10()
{
_BYTE *v0; // rcx

if ( !tokens )
return 0LL;
if ( func9() )
return 0LL;
if ( *v0 == 36 )
return func1();
if ( *(_WORD *)v0 == 17443 && v0[2] == 58 )
return func2();
return func0();
}

original_code:
ast_node *parse_arg() {
 if (tokens == ((void *)0) || is_special_token()) {
  return ((void *)0);
 }
 if (tokens->str[0] == '$') {
  return parse_variable_expression();
 }
 if (tokens->str[0] == '#' && tokens->str[1] == 'D' && tokens->str[2] == ':') {
  return parse_data_variable();
 }
 return parse_value();
}

canonical_original_code:
struct node *parse_arg() {
 if (tokens == ((void *)0) || is_special_token()) {
  return ((void *)0);
 }
 if (tokens->str[0] == '$') {
  return parse_variable_expression();
 }
 if (tokens->str[0] == '#' && tokens->str[1] == 'D' && tokens->str[2] == ':') {
  return parse_data_variable();
 }
 return parse_value();
}


decompiled_code:
_QWORD *parse_arg_list()
{
_QWORD *v0; // r12
_QWORD *v1; // rax
_QWORD *v2; // r13
_QWORD *v3; // rax
_QWORD *v4; // rbp
_QWORD *v5; // rax
_QWORD *v6; // rbx

v0 = malloc(0x50uLL);
v1 = malloc(0x10uLL);
*(_DWORD *)v0 = 4;
v2 = v1;
v0[9] = v1;
v3 = parse_arg();
v2[1] = 0LL;
*v2 = v3;
if ( v3 )
strip_head();
v4 = parse_arg();
if ( v4 )
{
strip_head();
while ( 1 )
{
v5 = malloc(0x10uLL);
v2[1] = v5;
v6 = v5;
*v5 = v4;
v5[1] = 0LL;
v4 = parse_arg();
if ( !v4 )
break;
strip_head();
v2 = v6;
}
}
return v0;
}

original_code:
ast_node *parse_arg_list() {
 ast_node *arg_list = malloc(sizeof(ast_node)), *arg_node;
 ast_nodelist *head, *tail;
 head = tail = malloc(sizeof(ast_nodelist));
 arg_list->type = ARGLIST;
 arg_list->children = head;
 arg_node = parse_arg();
 tail->node = arg_node;
 tail->next = ((void *)0);
 if (arg_node != ((void *)0)) {
  strip_head();
 }
 arg_node = parse_arg();
 if (arg_node != ((void *)0)) {
  strip_head();
 }
 while (arg_node != ((void *)0)) {
  tail->next = malloc(sizeof(ast_nodelist));
  tail = tail->next;
  tail->node = arg_node;
  tail->next = ((void *)0);
  arg_node = parse_arg();
  if (arg_node != ((void *)0)) {
   strip_head();
  }
 }
 return arg_list;
}

canonical_original_code:
struct node *parse_arg_list() {
 struct node *arg_list = malloc(sizeof(ast_node)); struct node *arg_node;
 struct nodelist *head; struct nodelist *tail;
 head = tail = malloc(sizeof(ast_nodelist));
 arg_list->type = ARGLIST;
 arg_list->children = head;
 arg_node = parse_arg();
 tail->node = arg_node;
 tail->next = ((void *)0);
 if (arg_node != ((void *)0)) {
  strip_head();
 }
 arg_node = parse_arg();
 if (arg_node != ((void *)0)) {
  strip_head();
 }
 while (arg_node != ((void *)0)) {
  tail->next = malloc(sizeof(ast_nodelist));
  tail = tail->next;
  tail->node = arg_node;
  tail->next = ((void *)0);
  arg_node = parse_arg();
  if (arg_node != ((void *)0)) {
   strip_head();
  }
 }
 return arg_list;
}

variable_types: struct nodelist { struct node { enum node_type { VARASSIGN=0, VALUE=1, VARIABLE=2, COMMAND=3, ARGLIST=4, REDIRECTLIST=5, STDIN_REDIRECT=6, STDOUT_REDIRECT=7, STDERR_REDIRECT=8, DATA_VARIABLE=9, BACKGROUND_KEY=10, NEGATED_COMMAND=11 } type; char token[64]; struct nodelist *children; } *node; struct nodelist *next; } *


decompiled_code:
_DWORD *parse_redirect_list()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
char *v2; // rax
char *v3; // rbp
char **v4; // rax
char **i; // rbx
char **v6; // rax

v0 = malloc(0x50uLL);
*v0 = 5;
v1 = v0;
v2 = parse_redirect();
if ( v2 )
{
v3 = v2;
v4 = (char **)malloc(0x50uLL);
*((_QWORD *)v1 + 9) = v4;
for ( i = v4; ; i = v6 )
{
*i = v3;
i[1] = 0LL;
v3 = parse_redirect();
if ( !v3 )
break;
v6 = (char **)malloc(0x10uLL);
i[1] = (char *)v6;
}
}
return v1;
}

canonical_decompiled_code:
_DWORD *func13()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
char *v2; // rax
char *v3; // rbp
char **v4; // rax
char **i; // rbx
char **v6; // rax

v0 = malloc(0x50uLL);
*v0 = 5;
v1 = v0;
v2 = func12();
if ( v2 )
{
v3 = v2;
v4 = (char **)malloc(0x50uLL);
*((_QWORD *)v1 + 9) = v4;
for ( i = v4; ; i = v6 )
{
*i = v3;
i[1] = 0LL;
v3 = func12();
if ( !v3 )
break;
v6 = (char **)malloc(0x10uLL);
i[1] = (char *)v6;
}
}
return v1;
}

original_code:
ast_node *parse_redirect_list() {
 ast_node *redirect, *redirect_list = malloc(sizeof(ast_node));
 ast_nodelist *tail_child;
 redirect_list->type = REDIRECTLIST;
 redirect = parse_redirect();
 if (redirect != ((void *)0)) {
  redirect_list->children = malloc(sizeof(ast_node));
  redirect_list->children->node = redirect;
  redirect_list->children->next = ((void *)0);
  tail_child = redirect_list->children;
  redirect = parse_redirect();
 }
 while (redirect != ((void *)0)) {
  tail_child->next = malloc(sizeof(ast_nodelist));
  tail_child = tail_child->next;
  tail_child->node = redirect;
  tail_child->next = ((void *)0);
  redirect = parse_redirect();
 }
 return redirect_list;
}

canonical_original_code:
struct node *parse_redirect_list() {
 struct node *redirect; struct node *redirect_list = malloc(sizeof(ast_node));
 struct nodelist *tail_child;
 redirect_list->type = REDIRECTLIST;
 redirect = parse_redirect();
 if (redirect != ((void *)0)) {
  redirect_list->children = malloc(sizeof(ast_node));
  redirect_list->children->node = redirect;
  redirect_list->children->next = ((void *)0);
  tail_child = redirect_list->children;
  redirect = parse_redirect();
 }
 while (redirect != ((void *)0)) {
  tail_child->next = malloc(sizeof(ast_nodelist));
  tail_child = tail_child->next;
  tail_child->node = redirect;
  tail_child->next = ((void *)0);
  redirect = parse_redirect();
 }
 return redirect_list;
}


decompiled_code:
char *parse_command()
{
char *v0; // rax
const char *v1; // rsi
char *v2; // r12
_QWORD *v3; // rbx
_QWORD *v4; // rbp
_QWORD *v5; // rax
_DWORD *v6; // rax
_QWORD *v7; // rax
_QWORD *v8; // rbp
_QWORD *v9; // rax
_QWORD *v11; // rbx
_QWORD *v12; // rax
bool v13; // zf
_QWORD *v14; // rbp

v0 = (char *)malloc(0x50uLL);
v1 = tokens;
*(_DWORD *)v0 = 3;
v2 = v0;
strncpy(v0 + 4, v1, 0x40uLL);
strip_head();
if ( !tokens )
return v2;
if ( is_special_token() )
{
if ( (unsigned int)is_redirect_token() )
{
v3 = (_QWORD *)*((_QWORD *)v2 + 9);
v4 = 0LL;
if ( !v3 )
{
v14 = malloc(0x10uLL);
*((_QWORD *)v2 + 9) = v14;
*v14 = parse_redirect_list();
*(_QWORD *)(*((_QWORD *)v2 + 9) + 8LL) = 0LL;
LABEL_6:
if ( !tokens )
return v2;
goto LABEL_7;
}
LABEL_5:
v5 = malloc(0x10uLL);
v4[1] = v5;
v3 = v5;
v6 = parse_redirect_list();
v3[1] = 0LL;
*v3 = v6;
goto LABEL_6;
}
v3 = 0LL;
}
else
{
v11 = malloc(0x10uLL);
*((_QWORD *)v2 + 9) = v11;
v12 = parse_arg_list();
v13 = tokens == 0LL;
*v11 = v12;
v3 = (_QWORD *)*((_QWORD *)v2 + 9);
v3[1] = 0LL;
if ( v13 )
return v2;
if ( (unsigned int)is_redirect_token() )
{
v4 = v3;
goto LABEL_5;
}
}
LABEL_7:
if ( is_background_key() )
{
if ( *((_QWORD *)v2 + 9) )
{
v7 = malloc(0x10uLL);
v3[1] = v7;
}
else
{
v7 = malloc(0x10uLL);
*((_QWORD *)v2 + 9) = v7;
}
v8 = v7;
v9 = parse_background_key();
v8[1] = 0LL;
*v8 = v9;
}
return v2;
}

canonical_decompiled_code:
char *func14()
{
char *v0; // rax
const char *v1; // rsi
char *v2; // r12
_QWORD *v3; // rbx
_QWORD *v4; // rbp
_QWORD *v5; // rax
_DWORD *v6; // rax
_QWORD *v7; // rax
_QWORD *v8; // rbp
_QWORD *v9; // rax
_QWORD *v11; // rbx
_QWORD *v12; // rax
bool v13; // zf
_QWORD *v14; // rbp

v0 = (char *)malloc(0x50uLL);
v1 = tokens;
*(_DWORD *)v0 = 3;
v2 = v0;
strncpy(v0 + 4, v1, 0x40uLL);
func3();
if ( !tokens )
return v2;
if ( func9() )
{
if ( (unsigned int)func7() )
{
v3 = (_QWORD *)*((_QWORD *)v2 + 9);
v4 = 0LL;
if ( !v3 )
{
v14 = malloc(0x10uLL);
*((_QWORD *)v2 + 9) = v14;
*v14 = func13();
*(_QWORD *)(*((_QWORD *)v2 + 9) + 8LL) = 0LL;
LABEL_6:
if ( !tokens )
return v2;
goto LABEL_7;
}
LABEL_5:
v5 = malloc(0x10uLL);
v4[1] = v5;
v3 = v5;
v6 = func13();
v3[1] = 0LL;
*v3 = v6;
goto LABEL_6;
}
v3 = 0LL;
}
else
{
v11 = malloc(0x10uLL);
*((_QWORD *)v2 + 9) = v11;
v12 = func11();
v13 = tokens == 0LL;
*v11 = v12;
v3 = (_QWORD *)*((_QWORD *)v2 + 9);
v3[1] = 0LL;
if ( v13 )
return v2;
if ( (unsigned int)func7() )
{
v4 = v3;
goto LABEL_5;
}
}
LABEL_7:
if ( func8() )
{
if ( *((_QWORD *)v2 + 9) )
{
v7 = malloc(0x10uLL);
v3[1] = v7;
}
else
{
v7 = malloc(0x10uLL);
*((_QWORD *)v2 + 9) = v7;
}
v8 = v7;
v9 = func4();
v8[1] = 0LL;
*v8 = v9;
}
return v2;
}

original_code:
ast_node *parse_command() {
 ast_node *command = malloc(sizeof(ast_node));
 ast_nodelist *tail_child = ((void *)0);
 command->type = COMMAND;
 strncpy(command->token, tokens->str, 64);
 strip_head();
 if (tokens != ((void *)0) && !is_special_token()) {
  command->children = malloc(sizeof(ast_nodelist));
  command->children->node = parse_arg_list();
  command->children->next = ((void *)0);
  tail_child = command->children;
 }
 if (tokens != ((void *)0) && is_redirect_token()) {
  if (command->children == ((void *)0)) {
   command->children = malloc(sizeof(ast_nodelist));
   command->children->node = parse_redirect_list();
   command->children->next = ((void *)0);
  } else {
   tail_child->next = malloc(sizeof(ast_nodelist));
   tail_child = tail_child->next;
   tail_child->node = parse_redirect_list();
   tail_child->next = ((void *)0);
  }
 }
 if (tokens != ((void *)0) && is_background_key()) {
  if (command->children == ((void *)0)) {
   tail_child = command->children = malloc(sizeof(ast_nodelist));
  } else {
   tail_child->next = malloc(sizeof(ast_nodelist));
   tail_child = tail_child->next;
  }
   tail_child->node = parse_background_key();
   tail_child->next = ((void *)0);
 }
 return command;
}

canonical_original_code:
struct node *parse_command() {
 struct node *command = malloc(sizeof(ast_node));
 struct nodelist *tail_child = ((void *)0);
 command->type = COMMAND;
 strncpy(command->token, tokens->str, 64);
 strip_head();
 if (tokens != ((void *)0) && !is_special_token()) {
  command->children = malloc(sizeof(ast_nodelist));
  command->children->node = parse_arg_list();
  command->children->next = ((void *)0);
  tail_child = command->children;
 }
 if (tokens != ((void *)0) && is_redirect_token()) {
  if (command->children == ((void *)0)) {
   command->children = malloc(sizeof(ast_nodelist));
   command->children->node = parse_redirect_list();
   command->children->next = ((void *)0);
  } else {
   tail_child->next = malloc(sizeof(ast_nodelist));
   tail_child = tail_child->next;
   tail_child->node = parse_redirect_list();
   tail_child->next = ((void *)0);
  }
 }
 if (tokens != ((void *)0) && is_background_key()) {
  if (command->children == ((void *)0)) {
   tail_child = command->children = malloc(sizeof(ast_nodelist));
  } else {
   tail_child->next = malloc(sizeof(ast_nodelist));
   tail_child = tail_child->next;
  }
   tail_child->node = parse_background_key();
   tail_child->next = ((void *)0);
 }
 return command;
}


decompiled_code:
_DWORD *parse_negated_command()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
_QWORD *v2; // rax

v0 = malloc(0x50uLL);
*v0 = 11;
v1 = v0;
strip_head();
v2 = malloc(0x10uLL);
v2[1] = 0LL;
*((_QWORD *)v1 + 9) = v2;
*v2 = parse_command();
return v1;
}

original_code:
ast_node *parse_negated_command() {
 ast_node *negated_command = malloc(sizeof(ast_node));
 negated_command->type = NEGATED_COMMAND;
 strip_head();
 negated_command->children = malloc(sizeof(ast_nodelist));
 negated_command->children->next = ((void *)0);
 negated_command->children->node = parse_command();
 return negated_command;
}

canonical_original_code:
struct node *parse_negated_command() {
 struct node *negated_command = malloc(sizeof(ast_node));
 negated_command->type = NEGATED_COMMAND;
 strip_head();
 negated_command->children = malloc(sizeof(ast_nodelist));
 negated_command->children->next = ((void *)0);
 negated_command->children->node = parse_command();
 return negated_command;
}


decompiled_code:
char *__fastcall parse_network_command(int a1)
{
_OWORD *v1; // rbp
char *v2; // rax
char *v3; // r13
char *v4; // r12
char *v5; // rax

v1 = malloc(0x48uLL);
v2 = (char *)malloc(0x48uLL);
v3 = tokens;
*(_QWORD *)v1 = 6845299LL;
v4 = v2;
v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = 0LL;
*((_QWORD *)v1 + 1) = 0LL;
v3[a1] = 0;
strncpy(v2, v3, 0x40uLL);
strncpy(v3, &v3[a1 + 1], 63 - a1);
v5 = tokens;
*((_QWORD *)v1 + 8) = v4;
tokens = (char *)v1;
*((_QWORD *)v4 + 8) = v5;
return parse_command();
}

original_code:
ast_node *parse_network_command(int colonidx) {
 strlist *ssh_token, *hostname_token;
 ssh_token = malloc(sizeof(strlist));
 hostname_token = malloc(sizeof(strlist));
 strncpy(ssh_token->str, "ssh", 64);
 tokens->str[colonidx] = '\0';
 strncpy(hostname_token->str, tokens->str, 64);
 strncpy(tokens->str, &tokens->str[colonidx+1], 64 - (colonidx + 1));
 ssh_token->next = hostname_token;
 hostname_token->next = tokens;
 tokens = ssh_token;
 return parse_command();
}

canonical_original_code:
struct node *parse_network_command(int colonidx) {
 struct sllist *ssh_token; struct sllist *hostname_token;
 ssh_token = malloc(sizeof(strlist));
 hostname_token = malloc(sizeof(strlist));
 strncpy(ssh_token->str, "ssh", 64);
 tokens->str[colonidx] = '\0';
 strncpy(hostname_token->str, tokens->str, 64);
 strncpy(tokens->str, &tokens->str[colonidx+1], 64 - (colonidx + 1));
 ssh_token->next = hostname_token;
 hostname_token->next = tokens;
 tokens = ssh_token;
 return parse_command();
}

variable_types: colonidx int

user_defined_types: struct sllist { char str[64]; struct sllist *next; }


decompiled_code:
_BOOL8 __fastcall is_negation(unsigned __int8 *a1)
{
int v1; // eax

v1 = *a1 - 33;
if ( *a1 == 33 )
v1 = a1[1];
return v1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(unsigned __int8 *a1)
{
int v1; // eax

v1 = *a1 - 33;
if ( *a1 == 33 )
v1 = a1[1];
return v1 == 0;
}

original_code:
int is_negation(char *str) {
 if (strcmp(str, "!") == 0) {
  return 1;
 } else {
  return 0;
 }
}


parse

decompiled_code:
char *parse()
{
char *v0; // rbp
int v1; // eax
int v2; // edi

v0 = tokens;
v1 = contains_eql(tokens);
if ( v1 != -1 )
return parse_var_assign(v1);
v2 = contains_colon(v0);
if ( v2 != -1 )
return parse_network_command(v2);
if ( is_negation((unsigned __int8 *)v0) )
return (char *)parse_negated_command();
return parse_command();
}

canonical_decompiled_code:
char *func18()
{
char *v0; // rbp
int v1; // eax
int v2; // edi

v0 = tokens;
v1 = func5(tokens);
if ( v1 != -1 )
return parse_var_assign(v1);
v2 = func6(v0);
if ( v2 != -1 )
return func16(v2);
if ( func17((unsigned __int8 *)v0) )
return (char *)func15();
return func14();
}

original_code:
ast_node *parse() {
 int eql, colon;
 ast_node *root;
 if ((eql = contains_eql(tokens->str)) != -1) {
  root = parse_var_assign(eql);
 } else if ((colon = contains_colon(tokens->str)) != -1) {
  root = parse_network_command(colon);
 } else if (is_negation(tokens->str)) {
  root = parse_negated_command();
 } else {
  root = parse_command();
 }
 return root;
}

canonical_original_code:
struct node *parse() {
 int eql; int colon;
 struct node *root;
 if ((eql = contains_eql(tokens->str)) != -1) {
  root = parse_var_assign(eql);
 } else if ((colon = contains_colon(tokens->str)) != -1) {
  root = parse_network_command(colon);
 } else if (is_negation(tokens->str)) {
  root = parse_negated_command();
 } else {
  root = parse_command();
 }
 return root;
}

variable_types: eql int

variable_types: colon int


decompiled_code:
size_t parser_error()
{
return fwrite("Parser error\n", 1uLL, 0xDuLL, stderr);
}

canonical_decompiled_code:
size_t func19()
{
return fwrite("Parser error\n", 1uLL, 0xDuLL, stderr);
}

original_code:
void parser_error() {
 fprintf(stderr, "Parser error\n");
 return;
}


decompiled_code:
int __fastcall interpret_var_assign(__int64 a1)
{
return setenv(
(const char *)(**(_QWORD **)(a1 + 72) + 4LL),
(const char *)(**(_QWORD **)(*(_QWORD *)(a1 + 72) + 8LL) + 4LL),
1);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
return setenv(
(const char *)(**(_QWORD **)(a1 + 72) + 4LL),
(const char *)(**(_QWORD **)(*(_QWORD *)(a1 + 72) + 8LL) + 4LL),
1);
}

original_code:
int interpret_var_assign(ast_node *var_assign) {
 char *varname, *value;
 varname = var_assign->children->node->token;
 value = var_assign->children->next->node->token;
 return setenv(varname, value, 1);
}

canonical_original_code:
int interpret_var_assign(struct node *var_assign) {
 char *varname; char *value;
 varname = var_assign->children->node->token;
 value = var_assign->children->next->node->token;
 return setenv(varname, value, 1);
}

variable_types:
varname
char *

variable_types:
value
char *


original_code:
char *interpret_variable(ast_node *variable) {
 char *value = (char*)malloc(sizeof(char) * 256);
 char *envar = getenv(variable->token);
 if (envar != ((void *)0)) {
  strncpy(value, envar, 256);
 } else {
  strncpy(value, "", 256);
 }
 return value;
}

canonical_original_code:
char *interpret_variable(struct node *variable) {
 char *value = (char*)malloc(sizeof(char) * 256);
 char *envar = getenv(variable->token);
 if (envar != ((void *)0)) {
  strncpy(value, envar, 256);
 } else {
  strncpy(value, "", 256);
 }
 return value;
}

variable_types:
envar
char *

return_type: char *


decompiled_code:
__int64 __fastcall interpret_data_variable(__int64 a1)
{
return resolve_data(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return resolve_data(a1 + 4);
}

original_code:
char *interpret_data_variable(ast_node *data_variable) {
 return resolve_data(data_variable->token);
}

canonical_original_code:
char *interpret_data_variable(struct node *data_variable) {
 return resolve_data(data_variable->token);
}


decompiled_code:
__int64 __fastcall interpret_value(__int64 a1)
{
return a1 + 4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return a1 + 4;
}

original_code:
char *interpret_value(ast_node *value) {
 return value->token;
}

canonical_original_code:
char *interpret_value(struct node *value) {
 return value->token;
}


decompiled_code:
char *__fastcall interpret_arg(__int64 a1)
{
if ( *(_DWORD *)a1 == 2 )
return interpret_variable(a1);
if ( *(_DWORD *)a1 == 9 )
return (char *)interpret_data_variable(a1);
return (char *)interpret_value(a1);
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1)
{
if ( *(_DWORD *)a1 == 2 )
return func1(a1);
if ( *(_DWORD *)a1 == 9 )
return (char *)func2(a1);
return (char *)func3(a1);
}

original_code:
char *interpret_arg(ast_node *arg) {
 if (arg->type == VARIABLE) {
  return interpret_variable(arg);
 } else if (arg->type == DATA_VARIABLE) {
  return interpret_data_variable(arg);
 } else {
  return interpret_value(arg);
 }
}

canonical_original_code:
char *interpret_arg(struct node *arg) {
 if (arg->type == VARIABLE) {
  return interpret_variable(arg);
 } else if (arg->type == DATA_VARIABLE) {
  return interpret_data_variable(arg);
 } else {
  return interpret_value(arg);
 }
}


decompiled_code:
_BOOL8 __fastcall interpret_negated_command(__int64 a1)
{
return (unsigned int)interpret_command(**(_QWORD **)(a1 + 72)) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return (unsigned int)func5(**(_QWORD **)(a1 + 72)) == 0;
}

original_code:
int interpret_negated_command(ast_node *negated_command) {
 int command_status;
 command_status = interpret_command(negated_command->children->node);
 if (command_status == 0) {
  return 1;
 } else {
  return 0;
 }
}

canonical_original_code:
int interpret_negated_command(struct node *negated_command) {
 int command_status;
 command_status = interpret_command(negated_command->children->node);
 if (command_status == 0) {
  return 1;
 } else {
  return 0;
 }
}


decompiled_code:
int set_exitstatuses()
{
unsigned int i; // ebx
int result; // eax
unsigned int v2; // eax
char name[2]; // [rsp+Bh] [rbp-Dh] BYREF
char s[11]; // [rsp+Dh] [rbp-Bh] BYREF

for ( i = 0; i != 10; ++i )
{
while ( 1 )
{
sprintf(name, "?%1d", i);
v2 = fifo_peek(10LL, &exitstatuses, exitstatus_head, i);
if ( v2 == -99 )
break;
++i;
sprintf(s, "%3d", v2);
result = setenv(name, s, 1);
if ( i == 10 )
return result;
}
result = unsetenv(name);
}
return result;
}

canonical_decompiled_code:
int func7()
{
unsigned int i; // ebx
int result; // eax
unsigned int v2; // eax
char name[2]; // [rsp+Bh] [rbp-Dh] BYREF
char s[11]; // [rsp+Dh] [rbp-Bh] BYREF

for ( i = 0; i != 10; ++i )
{
while ( 1 )
{
sprintf(name, "?%1d", i);
v2 = fifo_peek(10LL, &exitstatuses, exitstatus_head, i);
if ( v2 == -99 )
break;
++i;
sprintf(s, "%3d", v2);
result = setenv(name, s, 1);
if ( i == 10 )
return result;
}
result = unsetenv(name);
}
return result;
}

original_code:
void set_exitstatuses() {
 int i, status;
 char var[2];
 char val[3];
 for (i = 0; i < 10; i++) {
  sprintf(var, "?%1d", i);
  status = fifo_peek(10, exitstatuses,
    exitstatus_head, i);
  if (status != -99) {
   sprintf(val, "%3d", status);
   setenv(var, val, 1);
  } else {
   unsetenv(var);
  }
 }
 return;
}

canonical_original_code:
void set_exitstatuses() {
 int i; int status;
 char var[2];
 char val[3];
 for (i = 0; i < 10; i++) {
  sprintf(var, "?%1d", i);
  status = fifo_peek(10, exitstatuses,
    exitstatus_head, i);
  if (status != -99) {
   sprintf(val, "%3d", status);
   setenv(var, val, 1);
  } else {
   unsetenv(var);
  }
 }
 return;
}

variable_types: status int

variable_types:
var
char [2]

variable_types:
val
char [3]


decompiled_code:
void __fastcall free_ast(void **a1)
{
if ( a1 )
{
if ( a1[9] )
free_ast_list(a1[9]);
else
free(a1);
}
}

canonical_decompiled_code:
void __fastcall func9(void **a1)
{
if ( a1 )
{
if ( a1[9] )
func8(a1[9]);
else
free(a1);
}
}

original_code:
void free_ast(ast_node *root) {
 if (root != ((void *)0)) {
  if (root->children == ((void *)0)) {
   free(root);
  } else {
   free_ast_list(root->children);
  }
 }
}

canonical_original_code:
void free_ast(struct node *root) {
 if (root != ((void *)0)) {
  if (root->children == ((void *)0)) {
   free(root);
  } else {
   free_ast_list(root->children);
  }
 }
}


interpret

decompiled_code:
void __fastcall interpret(void **a1)
{
__int64 v1; // rcx

if ( *(_DWORD *)a1 )
{
if ( *(_DWORD *)a1 == 11 )
v1 = interpret_negated_command((__int64)a1);
else
v1 = (unsigned int)interpret_command((__int64)a1);
}
else
{
v1 = (unsigned int)interpret_var_assign((__int64)a1);
}
fifo_push(10LL, &exitstatuses, exitstatus_head, v1);
set_exitstatuses();
free_ast(a1);
}

canonical_decompiled_code:
void __fastcall func10(void **a1)
{
__int64 v1; // rcx

if ( *(_DWORD *)a1 )
{
if ( *(_DWORD *)a1 == 11 )
v1 = func6((__int64)a1);
else
v1 = (unsigned int)func5((__int64)a1);
}
else
{
v1 = (unsigned int)func0((__int64)a1);
}
fifo_push(10LL, &exitstatuses, exitstatus_head, v1);
func7();
func9(a1);
}

original_code:
void interpret(ast_node *root) {
 int exit_status;
 if (root->type == VARASSIGN) {
  exit_status = interpret_var_assign(root);
 } else if (root->type == NEGATED_COMMAND) {
  exit_status = interpret_negated_command(root);
 }else {
  exit_status = interpret_command(root);
 }
 fifo_push(10, exitstatuses, exitstatus_head, exit_status);
 set_exitstatuses();
 free_ast(root);
 return;
}

canonical_original_code:
void interpret(struct node *root) {
 int exit_status;
 if (root->type == VARASSIGN) {
  exit_status = interpret_var_assign(root);
 } else if (root->type == NEGATED_COMMAND) {
  exit_status = interpret_negated_command(root);
 }else {
  exit_status = interpret_command(root);
 }
 fifo_push(10, exitstatuses, exitstatus_head, exit_status);
 set_exitstatuses();
 free_ast(root);
 return;
}


chomp

decompiled_code:
const char *__fastcall chomp(const char *a1)
{
const char *v1; // rax

v1 = &a1[(int)strlen(a1) - 1];
if ( *v1 == 10 )
*v1 = 0;
return a1;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1)
{
const char *v1; // rax

v1 = &a1[(int)strlen(a1) - 1];
if ( *v1 == 10 )
*v1 = 0;
return a1;
}

original_code:
char *chomp(char* str) {
 int len = strlen(str);
 if (str[len - 1] == '\n') {
  str[len - 1] = '\0';
 }
 return str;
}

canonical_original_code:
char *chomp(char *str) {
 int len = strlen(str);
 if (str[len - 1] == '\n') {
  str[len - 1] = '\0';
 }
 return str;
}

variable_types: len int


searchVariable

decompiled_code:
char *__fastcall searchVariable(char *a1, char *a2)
{
char *v2; // rax
char *v3; // rdi
char *result; // rax

v2 = strtok(a1, delimToken);
if ( !v2 )
return 0LL;
v3 = v2;
while ( 1 )
{
result = searchPath(v3, a2);
if ( result )
break;
v3 = strtok(0LL, delimToken);
if ( !v3 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, char *a2)
{
char *v2; // rax
char *v3; // rdi
char *result; // rax

v2 = strtok(a1, delimToken);
if ( !v2 )
return 0LL;
v3 = v2;
while ( 1 )
{
result = func0(v3, a2);
if ( result )
break;
v3 = strtok(0LL, delimToken);
if ( !v3 )
return 0LL;
}
return result;
}

original_code:
char* searchVariable(char* inputVariable, char* inputExecutableName)
{
 char* currentPath = strtok(inputVariable, delimToken);
 if(currentPath == ((void *)0))
  return ((void *)0);
 while(currentPath != ((void *)0))
 {
  char* filePath = searchPath(currentPath, inputExecutableName);
  if(filePath != ((void *)0))
   return filePath;
  currentPath = strtok(((void *)0), delimToken);
 }
 return ((void *)0);
}

canonical_original_code:
char *searchVariable(char *inputVariable, char *inputExecutableName)
{
 char *currentPath = strtok(inputVariable, delimToken);
 if(currentPath == ((void *)0))
  return ((void *)0);
 while(currentPath != ((void *)0))
 {
  char *filePath = searchPath(currentPath, inputExecutableName);
  if(filePath != ((void *)0))
   return filePath;
  currentPath = strtok(((void *)0), delimToken);
 }
 return ((void *)0);
}

variable_types:
inputVariable
char *

variable_types:
inputExecutableName
char *

variable_types:
currentPath
char *

variable_types:
filePath
char *


decompiled_code:
char *__fastcall resolve_data(char *a1)
{
char *v1; // rax

v1 = getenv("DATA");
return searchVariable(v1, a1);
}

canonical_decompiled_code:
char *__fastcall func2(char *a1)
{
char *v1; // rax

v1 = getenv("DATA");
return func1(v1, a1);
}

original_code:
char* resolve_data(char* inputExecutableName)
{
 return searchVariable(getenv("DATA"), inputExecutableName);
}

canonical_original_code:
char *resolve_data(char *inputExecutableName)
{
 return searchVariable(getenv("DATA"), inputExecutableName);
}


decompiled_code:
char *__fastcall resolve_path(char *a1)
{
char *v1; // rax

v1 = getenv("PATH");
return searchVariable(v1, a1);
}

canonical_decompiled_code:
char *__fastcall func3(char *a1)
{
char *v1; // rax

v1 = getenv("PATH");
return func1(v1, a1);
}

original_code:
char* resolve_path(char* inputExecutableName)
{
 return searchVariable(getenv("PATH"), inputExecutableName);
}

canonical_original_code:
char *resolve_path(char *inputExecutableName)
{
 return searchVariable(getenv("PATH"), inputExecutableName);
}