decompiled_code:
char __fastcall multshare_prg(__int64 a1, __int64 a2, _BYTE *a3, int a4)
{
char result; // al
__int64 i; // rbx
_BYTE *v7; // r15
__int64 v8; // rbp
__int64 v9; // r13
char v10; // bl
char v11; // al
char v12; // [rsp+Fh] [rbp-59h]
__int64 v13; // [rsp+18h] [rbp-50h]
__int64 v14; // [rsp+20h] [rbp-48h]
int v16; // [rsp+2Ch] [rbp-3Ch]

result = a4;
if ( a4 > 0 )
{
v13 = (unsigned int)a4;
v16 = a4 - 1;
for ( i = 0LL; i != v13; ++i )
{
result = multtable(*(unsigned __int8 *)(a1 + i), *(unsigned __int8 *)(a2 + i));
a3[i] = result;
}
v7 = a3;
v8 = 1LL;
if ( v13 != 1 )
{
do
{
v9 = v8;
v14 = v8 + 1;
do
{
v10 = get_robprg((unsigned int)a4);
v12 = v10 ^ multtable(*(unsigned __int8 *)(a1 + v8 - 1), *(unsigned __int8 *)(a2 + v9));
v11 = multtable(*(unsigned __int8 *)(a1 + v9), *(unsigned __int8 *)(a2 + v8 - 1));
*v7 ^= v10;
result = v12 ^ v11;
a3[v9++] ^= result;
}
while ( v8 + 1 + (unsigned int)(v16 - v8) != v9 );
++v8;
++v7;
}
while ( v14 != v13 );
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func10(__int64 a1, __int64 a2, _BYTE *a3, int a4)
{
char result; // al
__int64 i; // rbx
_BYTE *v7; // r15
__int64 v8; // rbp
__int64 v9; // r13
char v10; // bl
char v11; // al
char v12; // [rsp+Fh] [rbp-59h]
__int64 v13; // [rsp+18h] [rbp-50h]
__int64 v14; // [rsp+20h] [rbp-48h]
int v16; // [rsp+2Ch] [rbp-3Ch]

result = a4;
if ( a4 > 0 )
{
v13 = (unsigned int)a4;
v16 = a4 - 1;
for ( i = 0LL; i != v13; ++i )
{
result = multtable(*(unsigned __int8 *)(a1 + i), *(unsigned __int8 *)(a2 + i));
a3[i] = result;
}
v7 = a3;
v8 = 1LL;
if ( v13 != 1 )
{
do
{
v9 = v8;
v14 = v8 + 1;
do
{
v10 = get_robprg((unsigned int)a4);
v12 = v10 ^ multtable(*(unsigned __int8 *)(a1 + v8 - 1), *(unsigned __int8 *)(a2 + v9));
v11 = multtable(*(unsigned __int8 *)(a1 + v9), *(unsigned __int8 *)(a2 + v8 - 1));
*v7 ^= v10;
result = v12 ^ v11;
a3[v9++] ^= result;
}
while ( v8 + 1 + (unsigned int)(v16 - v8) != v9 );
++v8;
++v7;
}
while ( v14 != v13 );
}
}
return result;
}

original_code:
void multshare_prg(byte *a,byte *b,byte *c,int n)
{
  int i,j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
    {
      byte tmp=get_robprg(n);
      byte tmp2=(tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
  }
}

canonical_original_code:
void multshare_prg(unsigned char *a, unsigned char *b, unsigned char *c, int n)
{
  int i; int j;
  for(i=0;i<n;i++)
    c[i]=multtable(a[i],b[i]);
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
    {
      unsigned char tmp = get_robprg(n);
      unsigned char tmp2 = (tmp ^ multtable(a[i],b[j])) ^ multtable(a[j],b[i]);
      c[i]^=tmp;
      c[j]^=tmp2;
    }
  }
}


repo: coron/htable

decompiled_code:
void __fastcall multshare_flr(__int64 a1, __int64 a2, _BYTE *a3, int a4)
{
multshare_prg(a1, a2, a3, a4);
locality_refresh((__int64)a3, a4);
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, __int64 a2, _BYTE *a3, int a4)
{
func10(a1, a2, a3, a4);
func2((__int64)a3, a4);
}

original_code:
void multshare_flr(byte *a,byte *b,byte *c,int n)
{
  multshare_prg(a,b,c,n);
  locality_refresh(c,n);
}

canonical_original_code:
void multshare_flr(unsigned char *a, unsigned char *b, unsigned char *c, int n)
{
  multshare_prg(a,b,c,n);
  locality_refresh(c,n);
}

variable_types:
a
unsigned char *

variable_types:
b
unsigned char *

variable_types:
c
unsigned char *

variable_types: n int

return_type: void


decompiled_code:
__int64 __fastcall subbyte_rp_share_flr(__int64 a1, unsigned int a2)
{
locality_refresh(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_flr);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2)
{
func2(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_flr);
}

original_code:
void subbyte_rp_share_flr(byte *a,int n)
{
  locality_refresh(a,n);
  subbyte_rp_share_func(a,n,multshare_flr);
}

canonical_original_code:
void subbyte_rp_share_flr(unsigned char *a, int n)
{
  locality_refresh(a,n);
  subbyte_rp_share_func(a,n,multshare_flr);
}


max

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

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

original_code:
int max(int a,int b)
{
  if (a>b) return a;
  return b;
}

canonical_original_code:
int max(int a, int b)
{
  if (a>b) return a;
  return b;
}

variable_types: a int

variable_types: b int

return_type: int


decompiled_code:
__int64 __fastcall rprg_flr(int a1)
{
int v1; // ecx
int v2; // eax
int v3; // eax
int v4; // ecx
__int64 result; // rax
int v6; // edx
int v7; // eax
int v8; // eax
int v9; // ecx

v1 = a1 - 1;
v2 = a1 * a1;
if ( (a1 & 1) != 0 )
{
v6 = v2 + 2;
v7 = v2 - 1;
if ( v7 < 0 )
v7 = v6;
v8 = max((v7 >> 2) + 5 * v1 / 2, 4 * v1);
result = (unsigned int)(v9 * v8);
}
else
{
v3 = max(5 * a1 / 2 + (v2 >> 2) - 3, 4 * v1);
result = (unsigned int)(v4 * v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
int v1; // ecx
int v2; // eax
int v3; // eax
int v4; // ecx
__int64 result; // rax
int v6; // edx
int v7; // eax
int v8; // eax
int v9; // ecx

v1 = a1 - 1;
v2 = a1 * a1;
if ( (a1 & 1) != 0 )
{
v6 = v2 + 2;
v7 = v2 - 1;
if ( v7 < 0 )
v7 = v6;
v8 = func13((v7 >> 2) + 5 * v1 / 2, 4 * v1);
result = (unsigned int)(v9 * v8);
}
else
{
v3 = func13(5 * a1 / 2 + (v2 >> 2) - 3, 4 * v1);
result = (unsigned int)(v4 * v3);
}
return result;
}

variable_types: loc int


decompiled_code:
__int64 __fastcall rprg_ilr(int a1)
{
return (unsigned int)(4 * (a1 - 1) * (a1 - 1));
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
return (unsigned int)(4 * (a1 - 1) * (a1 - 1));
}

original_code:
int rprg_ilr(int n)
{
  int loc=4*(n-1);
  return (n-1)*loc;
}

canonical_original_code:
int rprg_ilr(int n)
{
  int loc = 4*(n-1);
  return (n-1)*loc;
}


decompiled_code:
__int64 __fastcall subbyte_rp_share_ilr(__int64 a1, unsigned int a2)
{
locality_refresh(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_ilr);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned int a2)
{
func2(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_ilr);
}

original_code:
void subbyte_rp_share_ilr(byte *a,int n)
{
  locality_refresh(a,n);
  subbyte_rp_share_func(a,n,multshare_ilr);
}

canonical_original_code:
void subbyte_rp_share_ilr(unsigned char *a, int n)
{
  locality_refresh(a,n);
  subbyte_rp_share_func(a,n,multshare_ilr);
}


decompiled_code:
__int64 __fastcall subbyte_rp_share_ilr2(__int64 a1, unsigned int a2)
{
locality_refresh(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_ilr2);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, unsigned int a2)
{
func2(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_ilr2);
}

original_code:
void subbyte_rp_share_ilr2(byte *a,int n)
{
  locality_refresh(a,n);
  subbyte_rp_share_func(a,n,multshare_ilr2);
}

canonical_original_code:
void subbyte_rp_share_ilr2(unsigned char *a, int n)
{
  locality_refresh(a,n);
  subbyte_rp_share_func(a,n,multshare_ilr2);
}


decompiled_code:
__int64 __fastcall subbyte_rp_share_flr_mprg(__int64 a1, unsigned int a2)
{
locality_refresh_mprg(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_flr_mprg);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned int a2)
{
func4(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_flr_mprg);
}

original_code:
void subbyte_rp_share_flr_mprg(byte *a,int n)
{
  locality_refresh_mprg(a,n);
  subbyte_rp_share_func(a,n,multshare_flr_mprg);
}

canonical_original_code:
void subbyte_rp_share_flr_mprg(unsigned char *a, int n)
{
  locality_refresh_mprg(a,n);
  subbyte_rp_share_func(a,n,multshare_flr_mprg);
}


decompiled_code:
__int64 __fastcall subbyte_rp_share_ilr_mprg(__int64 a1, unsigned int a2)
{
locality_refresh_mprg(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_ilr_mprg);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned int a2)
{
func4(a1, a2);
return subbyte_rp_share_func(a1, a2, multshare_ilr_mprg);
}

original_code:
void subbyte_rp_share_ilr_mprg(byte *a,int n)
{
  locality_refresh_mprg(a,n);
  subbyte_rp_share_func(a,n,multshare_ilr_mprg);
}

canonical_original_code:
void subbyte_rp_share_ilr_mprg(unsigned char *a, int n)
{
  locality_refresh_mprg(a,n);
  subbyte_rp_share_func(a,n,multshare_ilr_mprg);
}


decompiled_code:
__int64 __fastcall subbyte_rp_share_flr_mprgmat(__int64 a1, __int64 a2)
{
return subbyte_rp_share_func(a1, a2, multshare_flr_mprgmat);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, __int64 a2)
{
return subbyte_rp_share_func(a1, a2, multshare_flr_mprgmat);
}

original_code:
void subbyte_rp_share_flr_mprgmat(byte *a,int n)
{
  subbyte_rp_share_func(a,n,multshare_flr_mprgmat);
}

canonical_original_code:
void subbyte_rp_share_flr_mprgmat(unsigned char *a, int n)
{
  subbyte_rp_share_func(a,n,multshare_flr_mprgmat);
}


original_code:
byte get_prgmat(tprgmat *prgmat)
{
  byte res;
  if(prgmat->flag==0)
    res=prgmat->r[prgmat->x] ^ prgmat->s[prgmat->y];
  else
    res=prgmat->r[prgmat->y] ^ prgmat->s[prgmat->x];
  if((prgmat->flag==0) && (prgmat->x!=prgmat->y))
  {
    prgmat->flag=1;
    return res;
  }
  prgmat->flag=0;
  prgmat->y++;
  if(prgmat->y>prgmat->m)
  {
    prgmat->y=0;
    prgmat->x++;
    prgmat->m++;
    if(prgmat->m>=prgmat->dmax)
    {
      fprintf(stderr,"prgmat: dmax too small\n");
      exit(0);
    }
    prgmat->r[prgmat->m]=xorshf96();
    prgmat->s[prgmat->m]=xorshf96();
  }
  return res;
}

canonical_original_code:
unsigned char get_prgmat(struct tprgmat *prgmat)
{
  unsigned char res;
  if(prgmat->flag==0)
    res=prgmat->r[prgmat->x] ^ prgmat->s[prgmat->y];
  else
    res=prgmat->r[prgmat->y] ^ prgmat->s[prgmat->x];
  if((prgmat->flag==0) && (prgmat->x!=prgmat->y))
  {
    prgmat->flag=1;
    return res;
  }
  prgmat->flag=0;
  prgmat->y++;
  if(prgmat->y>prgmat->m)
  {
    prgmat->y=0;
    prgmat->x++;
    prgmat->m++;
    if(prgmat->m>=prgmat->dmax)
    {
      fprintf(stderr,"prgmat: dmax too small\n");
      exit(0);
    }
    prgmat->r[prgmat->m]=xorshf96();
    prgmat->s[prgmat->m]=xorshf96();
  }
  return res;
}

variable_types: struct tprgmat { int x; unsigned char *r; unsigned char *s; int flag; int m; int dmax; } *

variable_types:
res
unsigned char

return_type: unsigned char


decompiled_code:
void __fastcall free_prgmat(__int64 a1)
{
free(*(void **)(a1 + 8));
free(*(void **)(a1 + 16));
}

original_code:
void free_prgmat(tprgmat *prgmat)
{
  free(prgmat->r);
  free(prgmat->s);
}

canonical_original_code:
void free_prgmat(struct tprgmat *prgmat)
{
  free(prgmat->r);
  free(prgmat->s);
}

user_defined_types: struct tprgmat { int x; unsigned char *r; unsigned char *s; int flag; int m; int dmax; }


decompiled_code:
void *__fastcall init_mprgmat(int a1, int a2, int a3)
{
int v3; // er13
size_t v5; // r12
void *v7; // rax
__int64 v8; // r13
__int64 v9; // rdi
size_t v10; // r12
void *result; // rax
__int64 v12; // rbp
__int64 v13; // rdi

v3 = 3 * a2 - 3;
v5 = 40LL * v3;
v7 = malloc(v5);
mprgmat = v7;
if ( v3 > 0 )
{
v8 = 0LL;
while ( 1 )
{
v9 = (__int64)v7 + v8;
v8 += 40LL;
init_prgmat(v9, a3);
if ( v5 == v8 )
break;
v7 = mprgmat;
}
}
v10 = 40LL * a1;
result = malloc(v10);
*(&mprgmat + 1) = result;
if ( a1 > 0 )
{
v12 = 0LL;
while ( 1 )
{
v13 = (__int64)result + v12;
v12 += 40LL;
result = init_prgmat(v13, a3);
if ( v10 == v12 )
break;
result = *(&mprgmat + 1);
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(int a1, int a2, int a3)
{
int v3; // er13
size_t v5; // r12
void *v7; // rax
__int64 v8; // r13
__int64 v9; // rdi
size_t v10; // r12
void *result; // rax
__int64 v12; // rbp
__int64 v13; // rdi

v3 = 3 * a2 - 3;
v5 = 40LL * v3;
v7 = malloc(v5);
mprgmat = v7;
if ( v3 > 0 )
{
v8 = 0LL;
while ( 1 )
{
v9 = (__int64)v7 + v8;
v8 += 40LL;
init_prgmat(v9, a3);
if ( v5 == v8 )
break;
v7 = mprgmat;
}
}
v10 = 40LL * a1;
result = malloc(v10);
*(&mprgmat + 1) = result;
if ( a1 > 0 )
{
v12 = 0LL;
while ( 1 )
{
v13 = (__int64)result + v12;
v12 += 40LL;
result = init_prgmat(v13, a3);
if ( v10 == v12 )
break;
result = *(&mprgmat + 1);
}
}
return result;
}

original_code:
void init_mprgmat(int ni,int n,int dmax)
{
  mprgmat.vabc=malloc(3*(n-1)*sizeof(tprgmat));
  for(int i=0;i<3*(n-1);i++)
    init_prgmat(&mprgmat.vabc[i],dmax);
  mprgmat.vi=malloc(ni*sizeof(tprgmat));
  for(int i=0;i<ni;i++)
    init_prgmat(&mprgmat.vi[i],dmax);
}

canonical_original_code:
void init_mprgmat(int ni, int n, int dmax)
{
  mprgmat.vabc=malloc(3*(n-1)*sizeof(tprgmat));
  for(int i = 0;i<3*(n-1);i++)
    init_prgmat(&mprgmat.vabc[i],dmax);
  mprgmat.vi=malloc(ni*sizeof(tprgmat));
  for(int i = 0;i<ni;i++)
    init_prgmat(&mprgmat.vi[i],dmax);
}

variable_types: ni int

variable_types: dmax int

variable_types: i int


decompiled_code:
__int64 __fastcall get_mprgmatabc(int a1, int a2, int a3)
{
return get_prgmat((int *)mprgmat + 10 * a2 + 10 * a1 * (a3 - 1));
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, int a3)
{
return func0((int *)mprgmat + 10 * a2 + 10 * a1 * (a3 - 1));
}

original_code:
byte get_mprgmatabc(int type,int i,int n)
{
  return get_prgmat(&mprgmat.vabc[type*(n-1)+i]);
}

canonical_original_code:
unsigned char get_mprgmatabc(int type, int i, int n)
{
  return get_prgmat(&mprgmat.vabc[type*(n-1)+i]);
}

variable_types: type int


decompiled_code:
__int64 __fastcall get_mprgmati(int a1)
{
return get_prgmat((int *)*(&mprgmat + 1) + 10 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return func0((int *)*(&mprgmat + 1) + 10 * a1);
}

original_code:
byte get_mprgmati(int i)
{
  return get_prgmat(&mprgmat.vi[i]);
}

canonical_original_code:
unsigned char get_mprgmati(int i)
{
  return get_prgmat(&mprgmat.vi[i]);
}


decompiled_code:
void __fastcall free_mprgmat(int a1, int a2)
{
__int64 v2; // r12
__int64 v3; // rbx
char *v4; // rdi
__int64 v5; // rbx
char *v6; // rdi

v2 = a1;
if ( 3 * a2 - 3 > 0 )
{
v3 = 0LL;
do
{
v4 = (char *)mprgmat + v3;
v3 += 40LL;
free_prgmat((__int64)v4);
}
while ( v3 != 40LL * (3 * a2 - 3) );
}
if ( (int)v2 > 0 )
{
v5 = 0LL;
do
{
v6 = (char *)*(&mprgmat + 1) + v5;
v5 += 40LL;
free_prgmat((__int64)v6);
}
while ( 40 * v2 != v5 );
}
free(mprgmat);
free(*(&mprgmat + 1));
}

original_code:
void free_mprgmat(int ni,int n)
{
  for(int i=0;i<3*(n-1);i++)
    free_prgmat(&mprgmat.vabc[i]);
  for(int i=0;i<ni;i++)
    free_prgmat(&mprgmat.vi[i]);
  free(mprgmat.vabc);
  free(mprgmat.vi);
}

canonical_original_code:
void free_mprgmat(int ni, int n)
{
  for(int i = 0;i<3*(n-1);i++)
    free_prgmat(&mprgmat.vabc[i]);
  for(int i = 0;i<ni;i++)
    free_prgmat(&mprgmat.vi[i]);
  free(mprgmat.vabc);
  free(mprgmat.vi);
}


decompiled_code:
int __fastcall check_ciphertext(const void *a1, const void *a2, int a3)
{
int result; // eax

result = memcmp(a1, a2, a3);
if ( result )
{
fwrite("Error: incorrect ciphertext\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(const void *a1, const void *a2, int a3)
{
int result; // eax

result = memcmp(a1, a2, a3);
if ( result )
{
fwrite("Error: incorrect ciphertext\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
return result;
}

original_code:
void check_ciphertext(byte *out,byte *outex,int nbyte)
{
  if(memcmp(out,outex,nbyte)!=0)
  {
    fprintf(stderr,"Error: incorrect ciphertext\n");
    exit(1);
  }
}

canonical_original_code:
void check_ciphertext(unsigned char *out, unsigned char *outex, int nbyte)
{
  if(memcmp(out,outex,nbyte)!=0)
  {
    fprintf(stderr,"Error: incorrect ciphertext\n");
    exit(1);
  }
}

variable_types:
out
unsigned char *

variable_types:
outex
unsigned char *

variable_types: nbyte int


decompiled_code:
__int64 xorshf96()
{
unsigned __int64 v0; // rdx
__int64 v1; // rax
__int64 result; // rax

++randcount;
v0 = (x << 16) ^ x ^ (((x << 16) ^ (unsigned __int64)x) >> 5);
v1 = y;
y = z;
x = v1;
result = (2 * v0) ^ v0 ^ z ^ v1;
z = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int64 v0; // rdx
__int64 v1; // rax
__int64 result; // rax

++randcount;
v0 = (x << 16) ^ x ^ (((x << 16) ^ (unsigned __int64)x) >> 5);
v1 = y;
y = z;
x = v1;
result = (2 * v0) ^ v0 ^ z ^ v1;
z = result;
return result;
}

original_code:
unsigned long xorshf96(void) {
  unsigned long t;
  randcount++;
  x ^= x << 16;
  x ^= x >> 5;
  x ^= x << 1;
  t = x;
  x = y;
  y = z;
  z = t ^ x ^ y;
  return z;
}

canonical_original_code:
unsigned long xorshf96() {
  unsigned long t;
  randcount++;
  x ^= x << 16;
  x ^= x >> 5;
  x ^= x << 1;
  t = x;
  x = y;
  y = z;
  z = t ^ x ^ y;
  return z;
}

variable_types:
t
unsigned long

return_type: unsigned long


decompiled_code:
void init_randcount()
{
randcount = 0;
}

canonical_decompiled_code:
void func1()
{
randcount = 0;
}

original_code:
void init_randcount()
{
  randcount=0;
}

canonical_original_code:
void init_randcount()
{
  randcount=0;
}


decompiled_code:
__int64 get_randcount()
{
return (unsigned int)randcount;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)randcount;
}

original_code:
unsigned int get_randcount()
{
  return randcount;
}

return_type: unsigned int


decompiled_code:
void __fastcall set_randcount(int a1)
{
randcount = a1;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
randcount = a1;
}

original_code:
void set_randcount(unsigned int randc)
{
  randcount=randc;
}

variable_types:
randc
unsigned int


share

decompiled_code:
void *__fastcall share(char a1, _BYTE *a2, int a3)
{
void *result; // rax

*a2 = a1;
if ( a3 > 1 )
result = memset(a2 + 1, 0, (unsigned int)(a3 - 1));
return result;
}

canonical_decompiled_code:
void *__fastcall func4(char a1, _BYTE *a2, int a3)
{
void *result; // rax

*a2 = a1;
if ( a3 > 1 )
result = memset(a2 + 1, 0, (unsigned int)(a3 - 1));
return result;
}

original_code:
void share(byte x,byte a[],int n)
{
  int i;
  a[0]=x;
  for(i=1;i<n;i++)
    a[i]=0;
}

canonical_original_code:
void share(unsigned char x, unsigned char a[], int n)
{
  int i;
  a[0]=x;
  for(i=1;i<n;i++)
    a[i]=0;
}

variable_types:
x
unsigned char

variable_types:
a
unsigned char []


refresh

decompiled_code:
__int64 __fastcall refresh(_BYTE *a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
_BYTE *v5; // rsi
__int64 v6; // r8

result = (unsigned int)a2;
if ( a2 > 1 )
{
v5 = a1 + 1;
v6 = (__int64)&a1[(unsigned int)(result - 2) + 2];
do
{
result = xorshf96(a1, v5, a3, a4, v6);
*a1 ^= result;
*v5++ ^= result;
}
while ( v5 != (_BYTE *)v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
_BYTE *v5; // rsi
__int64 v6; // r8

result = (unsigned int)a2;
if ( a2 > 1 )
{
v5 = a1 + 1;
v6 = (__int64)&a1[(unsigned int)(result - 2) + 2];
do
{
result = func0(a1, v5, a3, a4, v6);
*a1 ^= result;
*v5++ ^= result;
}
while ( v5 != (_BYTE *)v6 );
}
return result;
}

original_code:
void refresh(byte a[],int n)
{
  int i;
  for(i=1;i<n;i++)
  {
    byte tmp=xorshf96();
    a[0]=a[0] ^ tmp;
    a[i]=a[i] ^ tmp;
  }
}

canonical_original_code:
void refresh(unsigned char a[], int n)
{
  int i;
  for(i=1;i<n;i++)
  {
    unsigned char tmp = xorshf96();
    a[0]=a[0] ^ tmp;
    a[i]=a[i] ^ tmp;
  }
}

variable_types: n int

variable_types:
tmp
unsigned char


decode

decompiled_code:
char __fastcall decode(_BYTE *a1, int a2)
{
__int64 v2; // rdx
char result; // al

if ( a2 <= 0 )
return 0;
v2 = (__int64)&a1[a2 - 1 + 1];
result = 0;
do
result ^= *a1++;
while ( a1 != (_BYTE *)v2 );
return result;
}

canonical_decompiled_code:
char __fastcall func7(_BYTE *a1, int a2)
{
__int64 v2; // rdx
char result; // al

if ( a2 <= 0 )
return 0;
v2 = (__int64)&a1[a2 - 1 + 1];
result = 0;
do
result ^= *a1++;
while ( a1 != (_BYTE *)v2 );
return result;
}

original_code:
byte decode(byte a[],int n)
{
  byte r=0;
  for(int i=0;i<n;i++)
    r^=a[i];
  return r;
}

canonical_original_code:
unsigned char decode(unsigned char a[], int n)
{
  unsigned char r = 0;
  for(int i = 0;i<n;i++)
    r^=a[i];
  return r;
}

variable_types:
r
unsigned char


repo: cosino/modbus-utils

decompiled_code:
__int64 __fastcall parse_not_negative_int(char *s)
{
__int64 result; // rax
unsigned int v2; // [rsp+Ch] [rbp-1Ch] BYREF

if ( sscanf(s, "0x%x", &v2) > 0 || sscanf(s, "%d", &v2) > 0 )
result = v2;
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s)
{
__int64 result; // rax
unsigned int v2; // [rsp+Ch] [rbp-1Ch] BYREF

if ( sscanf(s, "0x%x", &v2) > 0 || sscanf(s, "%d", &v2) > 0 )
result = v2;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int parse_not_negative_int(char *addr)
{
 int val;
 int ret;
 ret = sscanf(addr, "0x%x", &val);
 if (ret < 1)
  ret = sscanf(addr, "%d", &val);
 if (ret < 1)
  return -1;
 return val;
}

variable_types:
addr
char *

variable_types: val int

variable_types: ret int


decompiled_code:
int usage_common_opts()
{
const char *v0; // rdx

v0 = "rtu";
if ( modbus_type )
v0 = "tcp";
return fprintf(
stderr,
"where <options> are:\n"
"\t--debug | -D - enable debug messages (more increase verbosity)\n"
"\t--device | -d <dev> - specify MODBUS device to use (default is %s)\n"
"\t <dev> can be:\n"
"\t - rtu[:<ttydev>[,<baud>[,<bits><parity><stop>]]]\n"
"\t default: rtu:%s,%d,%d,%c,%d\n"
"\t - tcp[:<address>[,<port>]]\n"
"\t default: tcp:%s,%d\n"
"\t--help | -h - show this help message\n",
v0,
modbus_parms,
*((unsigned int *)&modbus_parms + 2),
*((unsigned int *)&modbus_parms + 3),
(unsigned int)*((char *)&modbus_parms + 16),
*((unsigned int *)&modbus_parms + 5),
*(&modbus_parms + 3),
*((unsigned int *)&modbus_parms + 8));
}

canonical_decompiled_code:
int func3()
{
const char *v0; // rdx

v0 = "rtu";
if ( modbus_type )
v0 = "tcp";
return fprintf(
stderr,
"where <options> are:\n"
"\t--debug | -D - enable debug messages (more increase verbosity)\n"
"\t--device | -d <dev> - specify MODBUS device to use (default is %s)\n"
"\t <dev> can be:\n"
"\t - rtu[:<ttydev>[,<baud>[,<bits><parity><stop>]]]\n"
"\t default: rtu:%s,%d,%d,%c,%d\n"
"\t - tcp[:<address>[,<port>]]\n"
"\t default: tcp:%s,%d\n"
"\t--help | -h - show this help message\n",
v0,
modbus_parms,
*((unsigned int *)&modbus_parms + 2),
*((unsigned int *)&modbus_parms + 3),
(unsigned int)*((char *)&modbus_parms + 16),
*((unsigned int *)&modbus_parms + 5),
*(&modbus_parms + 3),
*((unsigned int *)&modbus_parms + 8));
}

original_code:
void usage_common_opts(void)
{
 fprintf(stderr, "where <options> are:\n"
  "\t--debug  | -D        - enable debug messages (more increase verbosity)\n"
  "\t--device | -d <dev>  - specify MODBUS device to use (default is %s)\n"
  "\t                       <dev> can be:\n"
  "\t                       - rtu[:<ttydev>[,<baud>[,<bits><parity><stop>]]]\n"
  "\t                            default: rtu:%s,%d,%d,%c,%d\n"
  "\t                       - tcp[:<address>[,<port>]]\n"
  "\t                            default: tcp:%s,%d\n"
  "\t--help   | -h        - show this help message\n",
   modbus_type == RTU ? "rtu" : "tcp",
   modbus_parms.rtu.serial_dev,
   modbus_parms.rtu.baud,
   modbus_parms.rtu.bytes,
   modbus_parms.rtu.parity,
   modbus_parms.rtu.stop,
   modbus_parms.tcp.address,
   modbus_parms.tcp.port);
}

canonical_original_code:
void usage_common_opts()
{
 fprintf(stderr, "where <options> are:\n"
  "\t--debug  | -D        - enable debug messages (more increase verbosity)\n"
  "\t--device | -d <dev>  - specify MODBUS device to use (default is %s)\n"
  "\t                       <dev> can be:\n"
  "\t                       - rtu[:<ttydev>[,<baud>[,<bits><parity><stop>]]]\n"
  "\t                            default: rtu:%s,%d,%d,%c,%d\n"
  "\t                       - tcp[:<address>[,<port>]]\n"
  "\t                            default: tcp:%s,%d\n"
  "\t--help   | -h        - show this help message\n",
   modbus_type == RTU ? "rtu" : "tcp",
   modbus_parms.rtu.serial_dev,
   modbus_parms.rtu.baud,
   modbus_parms.rtu.bytes,
   modbus_parms.rtu.parity,
   modbus_parms.rtu.stop,
   modbus_parms.tcp.address,
   modbus_parms.tcp.port);
}


decompiled_code:
__int64 __fastcall check_common_opts(int argc, char **argv)
{
int v4; // eax
int v5; // eax
bool v6; // cf
bool v7; // zf
__int64 v8; // rcx
const char *v9; // rdi
const char *v10; // rsi
char v11; // al
bool v12; // cf
bool v13; // zf
__int64 v14; // rcx
const char *v15; // rsi
const char *v16; // rdi
void *v17; // rdi
void *v18; // rdi
int longind; // [rsp+4h] [rbp-A4h] BYREF
void *ptr; // [rsp+8h] [rbp-A0h] BYREF
struct option longopts; // [rsp+10h] [rbp-98h] BYREF
const char *v23; // [rsp+30h] [rbp-78h]
int v24; // [rsp+38h] [rbp-70h]
__int64 v25; // [rsp+40h] [rbp-68h]
int v26; // [rsp+48h] [rbp-60h]
const char *v27; // [rsp+50h] [rbp-58h]
int v28; // [rsp+58h] [rbp-50h]
__int64 v29; // [rsp+60h] [rbp-48h]
int v30; // [rsp+68h] [rbp-40h]

longopts.name = "debug";
v23 = "device";
longopts.has_arg = 0;
longopts.flag = 0LL;
longopts.val = 68;
v24 = 1;
v25 = 0LL;
v26 = 100;
v27 = "help";
v28 = 0;
v29 = 0LL;
v30 = 104;
while ( 1 )
{
longind = 0;
v4 = getopt_long(argc, argv, "Dd:h", &longopts, &longind);
if ( v4 == -1 )
break;
if ( v4 == 68 )
{
++enable_debug;
}
else if ( v4 > 68 )
{
if ( v4 != 100 )
{
if ( v4 == 104 )
usage();
LABEL_22:
exit(1);
}
v5 = sscanf(optarg, "%m[a-z]", &ptr);
v6 = v5 == 0;
v7 = v5 == 1;
if ( v5 != 1 )
{
fwrite("must specify a MODBUS type\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
v8 = 4LL;
v9 = "rtu";
v10 = (const char *)ptr;
do
{
if ( !v8 )
break;
v6 = *v10 < (unsigned int)*v9;
v7 = *v10++ == *v9++;
--v8;
}
while ( v7 );
v11 = (!v6 && !v7) - v6;
v12 = 0;
v13 = v11 == 0;
if ( v11 )
{
v14 = 4LL;
v15 = (const char *)ptr;
v16 = "tcp";
do
{
if ( !v14 )
break;
v12 = *v15 < (unsigned int)*v16;
v13 = *v15++ == *v16++;
--v14;
}
while ( v13 );
if ( (!v12 && !v13) != v12 )
{
fwrite("unknow MODBUS type\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
v17 = ptr;
free(ptr);
modbus_type = 1;
if ( (int)parse_tcp_opts_constprop_0(v17, v15) < 0 )
{
fwrite("invalid TCP options\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
else
{
v18 = ptr;
free(ptr);
modbus_type = 0;
if ( (int)parse_rtu_opts_constprop_0(v18, v10) < 0 )
{
fwrite("invalid RTU options\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
}
else
{
if ( v4 )
goto LABEL_22;
if ( !*((_QWORD *)&longopts.flag + 4 * longind) )
{
fprintf(stderr, "fatal error in %s():%d\n", "check_common_opts", 143LL);
exit(1);
}
}
}
if ( !enable_debug )
{
if ( !modbus_type || modbus_type == 1 )
return (unsigned int)optind;
LABEL_38:
fprintf(stderr, "fatal error in %s():%d\n", "check_common_opts", 219LL);
goto LABEL_22;
}
fprintf(stderr, "%s[%4d]: %s: debug is on\n", "common.c", 200LL, "check_common_opts");
if ( modbus_type )
{
if ( modbus_type != 1 )
goto LABEL_38;
if ( enable_debug )
fprintf(
stderr,
"%s[%4d]: %s: modbus tcp:%s,%d\n",
"common.c",
212LL,
"check_common_opts",
*(&modbus_parms + 3),
*((unsigned int *)&modbus_parms + 8));
}
else if ( enable_debug )
{
fprintf(
stderr,
"%s[%4d]: %s: modbus rtu:%s,%d,%d,%c,%d\n",
"common.c",
203LL,
"check_common_opts",
modbus_parms,
*((unsigned int *)&modbus_parms + 2),
*((unsigned int *)&modbus_parms + 3),
(unsigned int)*((char *)&modbus_parms + 16),
*((unsigned int *)&modbus_parms + 5));
}
return (unsigned int)optind;
}

canonical_decompiled_code:
__int64 __fastcall func4(int argc, char **argv)
{
int v4; // eax
int v5; // eax
bool v6; // cf
bool v7; // zf
__int64 v8; // rcx
const char *v9; // rdi
const char *v10; // rsi
char v11; // al
bool v12; // cf
bool v13; // zf
__int64 v14; // rcx
const char *v15; // rsi
const char *v16; // rdi
void *v17; // rdi
void *v18; // rdi
int longind; // [rsp+4h] [rbp-A4h] BYREF
void *ptr; // [rsp+8h] [rbp-A0h] BYREF
struct option longopts; // [rsp+10h] [rbp-98h] BYREF
const char *v23; // [rsp+30h] [rbp-78h]
int v24; // [rsp+38h] [rbp-70h]
__int64 v25; // [rsp+40h] [rbp-68h]
int v26; // [rsp+48h] [rbp-60h]
const char *v27; // [rsp+50h] [rbp-58h]
int v28; // [rsp+58h] [rbp-50h]
__int64 v29; // [rsp+60h] [rbp-48h]
int v30; // [rsp+68h] [rbp-40h]

longopts.name = "debug";
v23 = "device";
longopts.has_arg = 0;
longopts.flag = 0LL;
longopts.val = 68;
v24 = 1;
v25 = 0LL;
v26 = 100;
v27 = "help";
v28 = 0;
v29 = 0LL;
v30 = 104;
while ( 1 )
{
longind = 0;
v4 = getopt_long(argc, argv, "Dd:h", &longopts, &longind);
if ( v4 == -1 )
break;
if ( v4 == 68 )
{
++enable_debug;
}
else if ( v4 > 68 )
{
if ( v4 != 100 )
{
if ( v4 == 104 )
usage();
LABEL_22:
exit(1);
}
v5 = sscanf(optarg, "%m[a-z]", &ptr);
v6 = v5 == 0;
v7 = v5 == 1;
if ( v5 != 1 )
{
fwrite("must specify a MODBUS type\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
v8 = 4LL;
v9 = "rtu";
v10 = (const char *)ptr;
do
{
if ( !v8 )
break;
v6 = *v10 < (unsigned int)*v9;
v7 = *v10++ == *v9++;
--v8;
}
while ( v7 );
v11 = (!v6 && !v7) - v6;
v12 = 0;
v13 = v11 == 0;
if ( v11 )
{
v14 = 4LL;
v15 = (const char *)ptr;
v16 = "tcp";
do
{
if ( !v14 )
break;
v12 = *v15 < (unsigned int)*v16;
v13 = *v15++ == *v16++;
--v14;
}
while ( v13 );
if ( (!v12 && !v13) != v12 )
{
fwrite("unknow MODBUS type\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
v17 = ptr;
free(ptr);
modbus_type = 1;
if ( (int)func1(v17, v15) < 0 )
{
fwrite("invalid TCP options\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
else
{
v18 = ptr;
free(ptr);
modbus_type = 0;
if ( (int)func2(v18, v10) < 0 )
{
fwrite("invalid RTU options\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
}
else
{
if ( v4 )
goto LABEL_22;
if ( !*((_QWORD *)&longopts.flag + 4 * longind) )
{
fprintf(stderr, "fatal error in %s():%d\n", "check_common_opts", 143LL);
exit(1);
}
}
}
if ( !enable_debug )
{
if ( !modbus_type || modbus_type == 1 )
return (unsigned int)optind;
LABEL_38:
fprintf(stderr, "fatal error in %s():%d\n", "check_common_opts", 219LL);
goto LABEL_22;
}
fprintf(stderr, "%s[%4d]: %s: debug is on\n", "common.c", 200LL, "check_common_opts");
if ( modbus_type )
{
if ( modbus_type != 1 )
goto LABEL_38;
if ( enable_debug )
fprintf(
stderr,
"%s[%4d]: %s: modbus tcp:%s,%d\n",
"common.c",
212LL,
"check_common_opts",
*(&modbus_parms + 3),
*((unsigned int *)&modbus_parms + 8));
}
else if ( enable_debug )
{
fprintf(
stderr,
"%s[%4d]: %s: modbus rtu:%s,%d,%d,%c,%d\n",
"common.c",
203LL,
"check_common_opts",
modbus_parms,
*((unsigned int *)&modbus_parms + 2),
*((unsigned int *)&modbus_parms + 3),
(unsigned int)*((char *)&modbus_parms + 16),
*((unsigned int *)&modbus_parms + 5));
}
return (unsigned int)optind;
}

original_code:
int check_common_opts(int argc, char *argv[])
{
 int c;
 struct option long_options[] = {
  {"debug", 0, 0, 'D'},
  {"device", 1, 0, 'd'},
  {"help", 0, 0, 'h'},
 };
 char *str;
 int ret;
 while (1) {
  int option_index = 0;
  c = getopt_long(argc, argv, "Dd:h",
    long_options, &option_index);
  if (c == -1)
   break;
  switch (c) {
  case 0:
   do { if (__builtin_expect(!!(long_options[option_index].flag == ((void *)0)), 0)) do { fprintf(stderr, "fatal error in %s():%d" "\n" , __func__, 143); exit(1); } while (0); } while(0);
   break;
  case 'D':
   enable_debug++;
   break;
  case 'd':
   ret = sscanf(optarg, "%m[a-z]", &str);
   if (ret != 1) {
    fprintf(stderr, "must specify a MODBUS type" "\n");
    exit(1);
   }
   if (strcmp(str, "rtu") == 0) {
    free(str);
    modbus_type = RTU;
    ret = parse_rtu_opts(optarg);
    if (ret < 0) {
     fprintf(stderr, "invalid RTU options" "\n");
     exit(1);
    }
   } else if (strcmp(str, "tcp") == 0) {
    free(str);
    modbus_type = TCP;
    ret = parse_tcp_opts(optarg);
    if (ret < 0) {
     fprintf(stderr, "invalid TCP options" "\n");
     exit(1);
    }
   } else {
    fprintf(stderr, "unknow MODBUS type" "\n");
    exit(1);
   }
   break;
  case 'h':
   usage();
  case ':':
   exit(1);
  case '?':
   exit(1);
  default:
   exit(1);
  }
 }
 do { if (__builtin_expect(!!(enable_debug), 0)) fprintf(stderr, "%s[%4d]: %s: " "debug is on" "\n" , "common.c", 200, __func__); } while (0);
 switch (modbus_type) {
 case RTU:
  do { if (__builtin_expect(!!(enable_debug), 0)) fprintf(stderr, "%s[%4d]: %s: " "modbus rtu:%s,%d,%d,%c,%d" "\n" , "common.c", 203, __func__ , modbus_parms.rtu.serial_dev, modbus_parms.rtu.baud, modbus_parms.rtu.bytes, modbus_parms.rtu.parity, modbus_parms.rtu.stop); } while (0);
  break;
 case TCP:
  do { if (__builtin_expect(!!(enable_debug), 0)) fprintf(stderr, "%s[%4d]: %s: " "modbus tcp:%s,%d" "\n" , "common.c", 212, __func__ , modbus_parms.tcp.address, modbus_parms.tcp.port); } while (0);
  break;
 default:
  do { fprintf(stderr, "fatal error in %s():%d" "\n" , __func__, 219); exit(1); } while (0);
 }
 return optind;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

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

variable_types:
str
char *


decompiled_code:
__int64 __fastcall parse_addr(char *a1)
{
__int64 result; // rax

result = parse_not_negative_int(a1);
if ( (unsigned int)(result - 1) >= 0xFE )
result = 0xFFFFFFFFLL;
return result;
}

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

result = func0(a1);
if ( (unsigned int)(result - 1) >= 0xFE )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int parse_addr(char *addr)
{
 int val;
 val = parse_not_negative_int(addr);
 if (val < 1 || val > 254)
  return -1;
 return val;
}


decompiled_code:
// attributes: thunk
__int64 __fastcall parse_datum(char *a1)
{
return parse_reg_localalias(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
return func6(a1);
}

original_code:
int parse_datum(char *datum)
{
 int val;
 val = parse_not_negative_int(datum);
 if (val < 0 || val > 0xffff)
  return -1;
 return val;
}

variable_types:
datum
char *


usage

repo: cosino/modbusfs

decompiled_code:
int usage()
{
fprintf(stderr, "usage: %s [<dev>] <mountpoint> [options]\n", program_invocation_short_name);
fwrite("where <dev> can be:\n\n\trtu:[<ttydev>[,<baud>[,<bits><parity><stop>]]]\n", 1uLL, 0x45uLL, stderr);
return fputc(10, stderr);
}

canonical_decompiled_code:
int func0()
{
fprintf(stderr, "usage: %s [<dev>] <mountpoint> [options]\n", program_invocation_short_name);
fwrite("where <dev> can be:\n\n\trtu:[<ttydev>[,<baud>[,<bits><parity><stop>]]]\n", 1uLL, 0x45uLL, stderr);
return fputc(10, stderr);
}

original_code:
static void usage(void)
{
 fprintf(stderr, "usage: %s [<dev>] <mountpoint> [options]\n", program_invocation_short_name);
 fprintf(stderr, "where <dev> can be:\n\n"
  "\trtu:[<ttydev>[,<baud>[,<bits><parity><stop>]]]\n");
 fprintf(stderr, "\n");
}

canonical_original_code:
static void usage()
{
 fprintf(stderr, "usage: %s [<dev>] <mountpoint> [options]\n", program_invocation_short_name);
 fprintf(stderr, "where <dev> can be:\n\n"
  "\trtu:[<ttydev>[,<baud>[,<bits><parity><stop>]]]\n");
 fprintf(stderr, "\n");
}


decompiled_code:
__int64 __fastcall parse_rtu_opts(const char *a1)
{
if ( !*a1 )
return 0LL;
if ( sscanf(a1, "%32[a-zA-Z0-9/_],%d,%d%c%d", modbus_parms, &dword_124, &dword_128, &byte_12C, &dword_130) <= 0 )
return 0xFFFFFFFFLL;
if ( enable_debug )
fprintf(
stderr,
"*** %s[%4d]: %s: serial_dev=%s baud=%d bytes=%d parity=%c stop=%d\n",
"modbusfs.c",
60LL,
"parse_rtu_opts",
modbus_parms,
(unsigned int)dword_124,
(unsigned int)dword_128,
(unsigned int)byte_12C,
(unsigned int)dword_130);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
if ( !*a1 )
return 0LL;
if ( sscanf(a1, "%32[a-zA-Z0-9/_],%d,%d%c%d", modbus_parms, &dword_124, &dword_128, &byte_12C, &dword_130) <= 0 )
return 0xFFFFFFFFLL;
if ( enable_debug )
fprintf(
stderr,
"*** %s[%4d]: %s: serial_dev=%s baud=%d bytes=%d parity=%c stop=%d\n",
"modbusfs.c",
60LL,
"parse_rtu_opts",
modbus_parms,
(unsigned int)dword_124,
(unsigned int)dword_128,
(unsigned int)byte_12C,
(unsigned int)dword_130);
return 0LL;
}

original_code:
static int parse_rtu_opts(char *opts)
{
 int ret;
 if (strlen(opts) == 0)
  return 0;
 ret = sscanf(opts, "%" "32" "[a-zA-Z0-9/_],%d,%d%c%d",
       modbus_parms.rtu.serial_dev,
       &modbus_parms.rtu.baud,
       &modbus_parms.rtu.bytes,
       &modbus_parms.rtu.parity, &modbus_parms.rtu.stop);
 if (ret < 1)
  return -1;
 do { if (__builtin_expect(!!(enable_debug), 0)) fprintf(stderr, "*** %s[%4d]: %s: " "serial_dev=%s baud=%d bytes=%d parity=%c stop=%d" "\n" , "modbusfs.c", 60, __func__ , modbus_parms.rtu.serial_dev, modbus_parms.rtu.baud, modbus_parms.rtu.bytes, modbus_parms.rtu.parity, modbus_parms.rtu.stop); } while (0);
 return 0;
}

variable_types:
opts
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char **v4; // r13
char *v5; // rbp
unsigned int v6; // er12
char *v7; // rax
bool v8; // cf
bool v9; // zf
const char *v11; // rdi
__int64 v12; // rcx
__int64 v13[2]; // [rsp+38h] [rbp-48h] BYREF
__int64 v14; // [rsp+48h] [rbp-38h]

LODWORD(v13[0]) = 0;
v13[1] = 0LL;
LODWORD(v14) = 0;
if ( argc > 0 )
{
v3 = argv;
v4 = &argv[(unsigned int)(argc - 1) + 1];
do
{
while ( 1 )
{
v5 = (char *)*v3;
v6 = *(unsigned __int8 *)*v3;
if ( v6 != 45 || v5[1] != 104 || v5[2] )
{
if ( strcmp(*v3, "--help") )
break;
}
usage();
argv = (const char **)"-ho";
fuse_opt_add_arg(v13, "-ho");
LABEL_6:
if ( ++v3 == v4 )
return modbusfs_start((unsigned int)modbus_type, argv, envp);
}
argv = (const char **)(&loc_39 + 1);
v7 = index(*v3, 58);
if ( v7 && v6 == 114 && v5[1] == 116 && v5[2] == 117 )
{
modbus_type = 0;
if ( (int)parse_rtu_opts(v7 + 1) < 0 )
{
fwrite("invalid RTU options\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
goto LABEL_6;
}
v8 = v6 < 0x2D;
v9 = v6 == 45;
if ( v6 == 45 )
{
v8 = (unsigned __int8)v5[1] < 0x64u;
v9 = v5[1] == 100;
if ( v5[1] == 100 )
{
v8 = 0;
v9 = v5[2] == 0;
if ( !v5[2] )
goto LABEL_28;
}
}
v11 = "--debug";
v12 = 8LL;
argv = (const char **)v5;
do
{
if ( !v12 )
break;
v8 = *(_BYTE *)argv < *v11;
v9 = *(_BYTE *)argv == *v11;
argv = (const char **)((char *)argv + 1);
++v11;
--v12;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
{
LABEL_28:
if ( ++enable_debug <= 1 )
goto LABEL_6;
}
argv = (const char **)v5;
++v3;
fuse_opt_add_arg(v13, v5);
}
while ( v3 != v4 );
}
return modbusfs_start((unsigned int)modbus_type, argv, envp);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char **v4; // r13
char *v5; // rbp
unsigned int v6; // er12
char *v7; // rax
bool v8; // cf
bool v9; // zf
const char *v11; // rdi
__int64 v12; // rcx
__int64 v13[2]; // [rsp+38h] [rbp-48h] BYREF
__int64 v14; // [rsp+48h] [rbp-38h]

LODWORD(v13[0]) = 0;
v13[1] = 0LL;
LODWORD(v14) = 0;
if ( argc > 0 )
{
v3 = argv;
v4 = &argv[(unsigned int)(argc - 1) + 1];
do
{
while ( 1 )
{
v5 = (char *)*v3;
v6 = *(unsigned __int8 *)*v3;
if ( v6 != 45 || v5[1] != 104 || v5[2] )
{
if ( strcmp(*v3, "--help") )
break;
}
func0();
argv = (const char **)"-ho";
fuse_opt_add_arg(v13, "-ho");
LABEL_6:
if ( ++v3 == v4 )
return modbusfs_start((unsigned int)modbus_type, argv, envp);
}
argv = (const char **)(&loc_39 + 1);
v7 = index(*v3, 58);
if ( v7 && v6 == 114 && v5[1] == 116 && v5[2] == 117 )
{
modbus_type = 0;
if ( (int)func1(v7 + 1) < 0 )
{
fwrite("invalid RTU options\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
goto LABEL_6;
}
v8 = v6 < 0x2D;
v9 = v6 == 45;
if ( v6 == 45 )
{
v8 = (unsigned __int8)v5[1] < 0x64u;
v9 = v5[1] == 100;
if ( v5[1] == 100 )
{
v8 = 0;
v9 = v5[2] == 0;
if ( !v5[2] )
goto LABEL_28;
}
}
v11 = "--debug";
v12 = 8LL;
argv = (const char **)v5;
do
{
if ( !v12 )
break;
v8 = *(_BYTE *)argv < *v11;
v9 = *(_BYTE *)argv == *v11;
argv = (const char **)((char *)argv + 1);
++v11;
--v12;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
{
LABEL_28:
if ( ++enable_debug <= 1 )
goto LABEL_6;
}
argv = (const char **)v5;
++v3;
fuse_opt_add_arg(v13, v5);
}
while ( v3 != v4 );
}
return modbusfs_start((unsigned int)modbus_type, argv, envp);
}

original_code:
int main(int argc, char *argv[])
{
 struct fuse_args args = { 0, ((void *)0), 0 };
 int i;
 char *ptr;
 int ret;
 for (i = 0; i < argc; i++) {
  if (strcmp(argv[i], "-h") == 0 ||
      strcmp(argv[i], "--help") == 0) {
   usage();
   fuse_opt_add_arg(&args, "-ho");
   continue;
  }
  ptr = index(argv[i], ':');
  if (ptr && strncmp(argv[i], "rtu", sizeof("rtu") - 1) == 0) {
   modbus_type = RTU;
   ret = parse_rtu_opts(ptr + 1);
   if (ret < 0) {
    fprintf(stderr, "invalid RTU options" "\n");
    exit(1);
   }
   continue;
  }
  if (strcmp(argv[i], "-d") == 0 ||
      strcmp(argv[i], "--debug") == 0) {
   enable_debug++;
   if (enable_debug < 2)
    continue;
  }
  fuse_opt_add_arg(&args, argv[i]);
 }
 return modbusfs_start(args, modbus_type, modbus_parms);
}

variable_types: struct fuse_args { int argc; char **argv; int allocated; }

variable_types: i int

variable_types:
ptr
char *


pPlaceUniformDisk

original_code:
Error pPlaceUniformDisk(ParticleContainer *particleContainer)
{
  Particle *p;
  unsigned int numParticles = particleContainer->_numParticles;
  double radius = particleContainer->_radius;
  unsigned int i;
  for (i=0; i < numParticles; i++)
    {
      p = &(particleContainer->_particles[i]);
      if ((p->_position = malloc(sizeof(double) * 2)) == ((void *)0))
 {
   return MEMORY_ERROR;
 }
      double theta = 2 * 3.1415926535897932385 * drand48();
      double r = drand48();
      p->_position[0] = sqrt(r * radius) * cos(theta);
      p->_position[1] = sqrt(r * radius) * sin(theta);
    }
  return NO_ERROR;
}

canonical_original_code:
enum Error pPlaceUniformDisk(struct ParticleContainer *particleContainer)
{
  struct Particle *p;
  unsigned int numParticles = particleContainer->_numParticles;
  double radius = particleContainer->_radius;
  unsigned int i;
  for (i=0; i < numParticles; i++)
    {
      p = &(particleContainer->_particles[i]);
      if ((p->_position = malloc(sizeof(double) * 2)) == ((void *)0))
 {
   return MEMORY_ERROR;
 }
      double theta = 2 * 3.1415926535897932385 * drand48();
      double r = drand48();
      p->_position[0] = sqrt(r * radius) * cos(theta);
      p->_position[1] = sqrt(r * radius) * sin(theta);
    }
  return NO_ERROR;
}

variable_types: struct ParticleContainer { unsigned int _numParticles; unsigned int _numDimensions; enum Shape { SQUARE=0, DISK=1 } _shape; double _radius; struct Particle { struct ParticleProperties { unsigned int _id; char *_name; } *_properties; double *_position; } *_particles; struct ParticleStats { double *_positionMean; double *_positionVariance; double _distanceMean; double _distanceVariance; double _distanceInvSqrMean; double _distanceInvSqrVariance; } *_particleStats; } *

variable_types:
numParticles
unsigned int

variable_types: radius double

variable_types:
i
unsigned int

variable_types: theta double

variable_types: r double

return_type: enum Error { MEMORY_ERROR=0, DIVIDE_BY_ZERO_ERROR=1, NO_ERROR=2 }

user_defined_types: struct ParticleContainer { unsigned int _numParticles; unsigned int _numDimensions; enum Shape _shape; double _radius; struct Particle *_particles; struct ParticleStats *_particleStats; }

user_defined_types: struct Particle { struct ParticleProperties *_properties; double *_position; }


pPlaceUniformSquare

original_code:
Error pPlaceUniformSquare(ParticleContainer *particleContainer)
{
  Particle *p;
  unsigned int numParticles = particleContainer->_numParticles;
  double radius = particleContainer->_radius;
  unsigned int i;
  for (i=0; i < numParticles; i++)
    {
      p = &(particleContainer->_particles[i]);
      if ((p->_position = malloc(sizeof(double) * 2)) == ((void *)0))
 {
   return MEMORY_ERROR;
 }
      double x = drand48();
      double y = drand48();
      p->_position[0] = 2.0 * radius * (x - 0.5);
      p->_position[1] = 2.0 * radius * (y - 0.5);
    }
  return NO_ERROR;
}

canonical_original_code:
enum Error pPlaceUniformSquare(struct ParticleContainer *particleContainer)
{
  struct Particle *p;
  unsigned int numParticles = particleContainer->_numParticles;
  double radius = particleContainer->_radius;
  unsigned int i;
  for (i=0; i < numParticles; i++)
    {
      p = &(particleContainer->_particles[i]);
      if ((p->_position = malloc(sizeof(double) * 2)) == ((void *)0))
 {
   return MEMORY_ERROR;
 }
      double x = drand48();
      double y = drand48();
      p->_position[0] = 2.0 * radius * (x - 0.5);
      p->_position[1] = 2.0 * radius * (y - 0.5);
    }
  return NO_ERROR;
}

variable_types: struct Particle { struct ParticleProperties { unsigned int _id; char *_name; } *_properties; double *_position; } *

variable_types: x double

variable_types: y double

user_defined_types: enum Error { MEMORY_ERROR=0, DIVIDE_BY_ZERO_ERROR=1, NO_ERROR=2 }

user_defined_types: struct ParticleStats { double *_positionMean; double *_positionVariance; double _distanceMean; double _distanceVariance; double _distanceInvSqrMean; double _distanceInvSqrVariance; }


pPlaceUniform

decompiled_code:
__int64 __fastcall pPlaceUniform(double *a1)
{
int v1; // eax
__int64 result; // rax

v1 = *((_DWORD *)a1 + 2);
if ( v1 )
{
if ( v1 == 1 )
{
*((_DWORD *)a1 + 1) = 2;
result = pPlaceUniformDisk(a1);
}
else
{
result = 0LL;
}
}
else
{
*((_DWORD *)a1 + 1) = 2;
result = pPlaceUniformSquare(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(double *a1)
{
int v1; // eax
__int64 result; // rax

v1 = *((_DWORD *)a1 + 2);
if ( v1 )
{
if ( v1 == 1 )
{
*((_DWORD *)a1 + 1) = 2;
result = func0(a1);
}
else
{
result = 0LL;
}
}
else
{
*((_DWORD *)a1 + 1) = 2;
result = func1(a1);
}
return result;
}

original_code:
Error pPlaceUniform(ParticleContainer *particleContainer)
{
  Error error;
  switch (particleContainer->_shape)
    {
    case DISK:
      particleContainer->_numDimensions = 2;
      error = pPlaceUniformDisk(particleContainer);
      break;
    case SQUARE:
      particleContainer->_numDimensions = 2;
      error = pPlaceUniformSquare(particleContainer);
      break;
    }
  return error;
}

canonical_original_code:
enum Error pPlaceUniform(struct ParticleContainer *particleContainer)
{
  enum Error error;
  switch (particleContainer->_shape)
    {
    case DISK:
      particleContainer->_numDimensions = 2;
      error = pPlaceUniformDisk(particleContainer);
      break;
    case SQUARE:
      particleContainer->_numDimensions = 2;
      error = pPlaceUniformSquare(particleContainer);
      break;
    }
  return error;
}

variable_types: enum Error { MEMORY_ERROR=0, DIVIDE_BY_ZERO_ERROR=1, NO_ERROR=2 }

user_defined_types: struct ParticleProperties { unsigned int _id; char *_name; }


pCreateParticles

decompiled_code:
__int64 __fastcall pCreateParticles(double **a1, unsigned int a2, int a3, double a4)
{
double *v5; // rax
double *v6; // rbp
void *v7; // rax

v5 = (double *)malloc(0x28uLL);
*a1 = v5;
v6 = v5;
*(_DWORD *)v5 = a2;
*((_DWORD *)v5 + 2) = a3;
v5[4] = 0.0;
v5[2] = a4;
v7 = malloc(16LL * a2);
*((_QWORD *)v6 + 3) = v7;
if ( !v7 )
return 0LL;
pPlaceUniform(v6);
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(double **a1, unsigned int a2, int a3, double a4)
{
double *v5; // rax
double *v6; // rbp
void *v7; // rax

v5 = (double *)malloc(0x28uLL);
*a1 = v5;
v6 = v5;
*(_DWORD *)v5 = a2;
*((_DWORD *)v5 + 2) = a3;
v5[4] = 0.0;
v5[2] = a4;
v7 = malloc(16LL * a2);
*((_QWORD *)v6 + 3) = v7;
if ( !v7 )
return 0LL;
func2(v6);
return 2LL;
}

original_code:
Error pCreateParticles(ParticleContainer **particleContainer, unsigned int numParticles, Shape shape, double radius)
{
  *particleContainer = (ParticleContainer *) malloc(sizeof(ParticleContainer));
  (*particleContainer)->_numParticles = numParticles;
  (*particleContainer)->_shape = shape;
  (*particleContainer)->_radius = radius;
  (*particleContainer)->_particleStats = ((void *)0);
  if (((*particleContainer)->_particles = (Particle *) malloc(sizeof(Particle) * (*particleContainer)->_numParticles)) == ((void *)0))
    {
      return MEMORY_ERROR;
    }
  pPlaceUniform(*particleContainer);
  return NO_ERROR;
}

canonical_original_code:
enum Error pCreateParticles(struct ParticleContainer **particleContainer, unsigned int numParticles, enum Shape shape, double radius)
{
  *particleContainer = (struct ParticleContainer *) malloc(sizeof(ParticleContainer));
  (*particleContainer)->_numParticles = numParticles;
  (*particleContainer)->_shape = shape;
  (*particleContainer)->_radius = radius;
  (*particleContainer)->_particleStats = ((void *)0);
  if (((*particleContainer)->_particles = (struct Particle *) malloc(sizeof(Particle) * (*particleContainer)->_numParticles)) == ((void *)0))
    {
      return MEMORY_ERROR;
    }
  pPlaceUniform(*particleContainer);
  return NO_ERROR;
}

variable_types: struct ParticleContainer { unsigned int _numParticles; unsigned int _numDimensions; enum Shape { SQUARE=0, DISK=1 } _shape; double _radius; struct Particle { struct ParticleProperties { unsigned int _id; char *_name; } *_properties; double *_position; } *_particles; struct ParticleStats { double *_positionMean; double *_positionVariance; double _distanceMean; double _distanceVariance; double _distanceInvSqrMean; double _distanceInvSqrVariance; } *_particleStats; } **

variable_types:
shape
enum Shape { SQUARE=0, DISK=1 }


pDistance

original_code:
Error pDistance(Particle *p, Particle *q, unsigned int numDimensions, double *distance)
{
  unsigned int i;
  *distance = 0.0;
  for (i = 0; i<numDimensions; i++)
    {
      *distance += pow((p->_position[i] - q->_position[i]), 2);
    }
  *distance = sqrt(*distance);
  return NO_ERROR;
}

canonical_original_code:
enum Error pDistance(struct Particle *p, struct Particle *q, unsigned int numDimensions, double *distance)
{
  unsigned int i;
  *distance = 0.0;
  for (i = 0; i<numDimensions; i++)
    {
      *distance += pow((p->_position[i] - q->_position[i]), 2);
    }
  *distance = sqrt(*distance);
  return NO_ERROR;
}

variable_types:
q
struct Particle *

variable_types:
numDimensions
unsigned int

variable_types:
distance
double *


pInverseSquareDistance

decompiled_code:
__int64 __fastcall pInverseSquareDistance(__int64 a1, __int64 a2, int a3, double *a4)
{
double v5; // xmm0_8
__int64 result; // rax

pDistance(a1, a2, a3, a4);
v5 = *a4;
if ( v5 == 0.0 )
return 1LL;
result = 2LL;
*a4 = 1.0 / (v5 * v5);
return result;
}

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

func4(a1, a2, a3, a4);
v5 = *a4;
if ( v5 == 0.0 )
return 1LL;
result = 2LL;
*a4 = 1.0 / (v5 * v5);
return result;
}

original_code:
Error pInverseSquareDistance(Particle *p, Particle *q, unsigned int numDimensions, double *invSqrDistance)
{
  pDistance(p, q, numDimensions, invSqrDistance);
  if (*invSqrDistance == 0.0)
    {
      return DIVIDE_BY_ZERO_ERROR;
    }
  *invSqrDistance = 1.0 / (*invSqrDistance * *invSqrDistance);
  return NO_ERROR;
}

canonical_original_code:
enum Error pInverseSquareDistance(struct Particle *p, struct Particle *q, unsigned int numDimensions, double *invSqrDistance)
{
  pDistance(p, q, numDimensions, invSqrDistance);
  if (*invSqrDistance == 0.0)
    {
      return DIVIDE_BY_ZERO_ERROR;
    }
  *invSqrDistance = 1.0 / (*invSqrDistance * *invSqrDistance);
  return NO_ERROR;
}

variable_types:
invSqrDistance
double *


pCalcDistanceInvSqrMean

decompiled_code:
__int64 __fastcall pCalcDistanceInvSqrMean(unsigned int *a1)
{
__int64 v1; // rbp
unsigned int v2; // er14
__int64 i; // rbx
__int64 v4; // rsi
__int64 v5; // r15
double v6; // xmm0_8
__int64 v7; // r13
__int64 result; // rax
double v9; // [rsp+10h] [rbp-58h]
double v10[8]; // [rsp+28h] [rbp-40h] BYREF

v1 = *a1;
v2 = a1[1];
v10[0] = 0.0;
if ( (_DWORD)v1 )
{
v9 = 0.0;
for ( i = 0LL; i != v1; ++i )
{
v4 = *((_QWORD *)a1 + 3);
v5 = 0LL;
v6 = 0.0;
v7 = v4 + 16 * i;
while ( 1 )
{
if ( (_DWORD)v5 != (_DWORD)i )
{
result = pInverseSquareDistance(v7, 16 * v5 + v4, v2, v10);
if ( (_DWORD)result != 2 )
return result;
v6 = v6 + v10[0];
}
if ( v1 == ++v5 )
break;
v4 = *((_QWORD *)a1 + 3);
}
v9 = v6 / (double)((int)v1 - 1) + v9;
}
}
else
{
v9 = 0.0;
LODWORD(v1) = 0;
}
*(double *)(*((_QWORD *)a1 + 4) + 32LL) = v9 / (double)(int)v1;
return 2LL;
}

original_code:
Error pCalcDistanceInvSqrMean(ParticleContainer *particleContainer)
{
  unsigned int i;
  unsigned int j;
  unsigned int numDimensions = particleContainer->_numDimensions;
  unsigned int numParticles = particleContainer->_numParticles;
  Error error;
  double invSqrDistanceMeanSum = 0.0;
  double invSqrDistanceParticle = 0.0;
  double invSqrDistanceParticleSum = 0.0;
  Particle *p;
  Particle *q;
  for (i = 0; i < numParticles; i++)
    {
      invSqrDistanceParticleSum = 0.0;
      p = &(particleContainer->_particles[i]);
      for (j = 0; j < numParticles; j++)
 {
   q = &(particleContainer->_particles[j]);
   if ( i == j )
     {
       continue;
     }
   if ((error = pInverseSquareDistance(p, q, numDimensions, &invSqrDistanceParticle)) != NO_ERROR)
     {
       return error;
     }
   invSqrDistanceParticleSum += invSqrDistanceParticle;
 }
      invSqrDistanceMeanSum += invSqrDistanceParticleSum / (numParticles - 1);
    }
  particleContainer->_particleStats->_distanceInvSqrMean = invSqrDistanceMeanSum / numParticles;
  return NO_ERROR;
}

canonical_original_code:
enum Error pCalcDistanceInvSqrMean(struct ParticleContainer *particleContainer)
{
  unsigned int i;
  unsigned int j;
  unsigned int numDimensions = particleContainer->_numDimensions;
  unsigned int numParticles = particleContainer->_numParticles;
  enum Error error;
  double invSqrDistanceMeanSum = 0.0;
  double invSqrDistanceParticle = 0.0;
  double invSqrDistanceParticleSum = 0.0;
  struct Particle *p;
  struct Particle *q;
  for (i = 0; i < numParticles; i++)
    {
      invSqrDistanceParticleSum = 0.0;
      p = &(particleContainer->_particles[i]);
      for (j = 0; j < numParticles; j++)
 {
   q = &(particleContainer->_particles[j]);
   if ( i == j )
     {
       continue;
     }
   if ((error = pInverseSquareDistance(p, q, numDimensions, &invSqrDistanceParticle)) != NO_ERROR)
     {
       return error;
     }
   invSqrDistanceParticleSum += invSqrDistanceParticle;
 }
      invSqrDistanceMeanSum += invSqrDistanceParticleSum / (numParticles - 1);
    }
  particleContainer->_particleStats->_distanceInvSqrMean = invSqrDistanceMeanSum / numParticles;
  return NO_ERROR;
}

variable_types:
j
unsigned int

variable_types: invSqrDistanceMeanSum double

variable_types: invSqrDistanceParticle double

variable_types: invSqrDistanceParticleSum double


pCalcDistanceInvSqrVariance

original_code:
Error pCalcDistanceInvSqrVariance(ParticleContainer *particleContainer)
{
  unsigned int i;
  unsigned int j;
  unsigned int numDimensions = particleContainer->_numDimensions;
  unsigned int numParticles = particleContainer->_numParticles;
  double invSqrDistanceMean = particleContainer->_particleStats->_distanceInvSqrMean;
  Error error;
  double invSqrDistanceVarianceSum = 0.0;
  double invSqrDistanceParticle = 0.0;
  double invSqrDistanceParticleSum = 0.0;
  Particle *p;
  Particle *q;
  for (i = 0; i < numParticles; i++)
    {
      invSqrDistanceParticleSum = 0.0;
      p = &(particleContainer->_particles[i]);
      for (j = 0; j < numParticles; j++)
 {
   q = &(particleContainer->_particles[j]);
   if ( i == j )
     {
       continue;
     }
   if ((error = pInverseSquareDistance(p, q, numDimensions, &invSqrDistanceParticle)) != NO_ERROR)
     {
       return error;
     }
   invSqrDistanceParticleSum += pow(invSqrDistanceParticle - invSqrDistanceMean, 2);
 }
      invSqrDistanceVarianceSum += invSqrDistanceParticleSum / (numParticles - 1);
    }
  particleContainer->_particleStats->_distanceInvSqrVariance = invSqrDistanceVarianceSum / numParticles;
  return NO_ERROR;
}

canonical_original_code:
enum Error pCalcDistanceInvSqrVariance(struct ParticleContainer *particleContainer)
{
  unsigned int i;
  unsigned int j;
  unsigned int numDimensions = particleContainer->_numDimensions;
  unsigned int numParticles = particleContainer->_numParticles;
  double invSqrDistanceMean = particleContainer->_particleStats->_distanceInvSqrMean;
  enum Error error;
  double invSqrDistanceVarianceSum = 0.0;
  double invSqrDistanceParticle = 0.0;
  double invSqrDistanceParticleSum = 0.0;
  struct Particle *p;
  struct Particle *q;
  for (i = 0; i < numParticles; i++)
    {
      invSqrDistanceParticleSum = 0.0;
      p = &(particleContainer->_particles[i]);
      for (j = 0; j < numParticles; j++)
 {
   q = &(particleContainer->_particles[j]);
   if ( i == j )
     {
       continue;
     }
   if ((error = pInverseSquareDistance(p, q, numDimensions, &invSqrDistanceParticle)) != NO_ERROR)
     {
       return error;
     }
   invSqrDistanceParticleSum += pow(invSqrDistanceParticle - invSqrDistanceMean, 2);
 }
      invSqrDistanceVarianceSum += invSqrDistanceParticleSum / (numParticles - 1);
    }
  particleContainer->_particleStats->_distanceInvSqrVariance = invSqrDistanceVarianceSum / numParticles;
  return NO_ERROR;
}

variable_types: struct ParticleContainer { unsigned int _numParticles; unsigned int _numDimensions; enum Shape { SQUARE=0, DISK=1 } _shape; double _radius; struct Particle { struct ParticleProperties { unsigned int _id; char *_name; } *_properties; double *_position; } *_particles; struct ParticleStats { double *_positionMean; double *_positionVariance; double _distanceMean; double _distanceVariance; double _distanceInvSqrMean; double _distanceInvSqrVariance; } *_particleStats; } *

variable_types:
i
unsigned int

variable_types:
numParticles
unsigned int

variable_types: invSqrDistanceMean double

variable_types: invSqrDistanceVarianceSum double


pGenStatistics

decompiled_code:
__int64 __fastcall pGenStatistics(__int64 a1)
{
*(_QWORD *)(a1 + 32) = malloc(0x30uLL);
pCalcPositionMean(a1);
pCalcPositionVariance(a1);
pCalcDistanceMean((unsigned int *)a1);
pCalcDistanceVariance((unsigned int *)a1);
pCalcDistanceInvSqrMean((unsigned int *)a1);
pCalcDistanceInvSqrVariance((unsigned int *)a1);
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
*(_QWORD *)(a1 + 32) = malloc(0x30uLL);
func0(a1);
func1(a1);
func2((unsigned int *)a1);
func3((unsigned int *)a1);
func4((unsigned int *)a1);
func5((unsigned int *)a1);
return 2LL;
}

original_code:
Error pGenStatistics(ParticleContainer *particleContainer)
{
  particleContainer->_particleStats = (ParticleStats *) malloc(sizeof(ParticleStats));
  pCalcPositionMean(particleContainer);
  pCalcPositionVariance(particleContainer);
  pCalcDistanceMean(particleContainer);
  pCalcDistanceVariance(particleContainer);
  pCalcDistanceInvSqrMean(particleContainer);
  pCalcDistanceInvSqrVariance(particleContainer);
  return NO_ERROR;
}

canonical_original_code:
enum Error pGenStatistics(struct ParticleContainer *particleContainer)
{
  particleContainer->_particleStats = (struct ParticleStats *) malloc(sizeof(ParticleStats));
  pCalcPositionMean(particleContainer);
  pCalcPositionVariance(particleContainer);
  pCalcDistanceMean(particleContainer);
  pCalcDistanceVariance(particleContainer);
  pCalcDistanceInvSqrMean(particleContainer);
  pCalcDistanceInvSqrVariance(particleContainer);
  return NO_ERROR;
}


pPrintStatistics

decompiled_code:
int __fastcall pPrintStatistics(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
__int64 v3; // r12
__int64 v4; // rbx
const char *i; // rsi
double v6; // xmm0_8
unsigned int v7; // eax
__int64 v9; // rbx
const char *j; // rsi
double v11; // xmm0_8
__int64 v12[7]; // [rsp+0h] [rbp-38h]

printf("numParticles %u\n", *a1);
v1 = a1[2];
if ( v1 )
{
if ( v1 == 1 )
puts("shape disk");
}
else
{
puts("shape square");
}
v2 = a1[1];
v3 = *((_QWORD *)a1 + 4);
v12[1] = (__int64)aYzt;
v12[2] = (__int64)&aYzt[1];
v12[3] = (__int64)&aYzt[2];
if ( v2 )
{
v4 = 0LL;
for ( i = (const char *)&unk_811; ; i = (const char *)v12[v4] )
{
v6 = *(double *)(*(_QWORD *)v3 + 8 * v4++);
printf("%sMean %f\n", i, v6);
v7 = a1[1];
if ( v7 <= (unsigned int)v4 )
break;
}
if ( v7 )
{
v9 = 0LL;
for ( j = (const char *)&unk_811; ; j = (const char *)v12[v9] )
{
v11 = *(double *)(*(_QWORD *)(v3 + 8) + 8 * v9++);
printf("%sVariance %f\n", j, v11);
if ( a1[1] <= (unsigned int)v9 )
break;
}
}
}
printf("distanceMean %f\n", *(double *)(v3 + 16));
printf("distanceVariance %f\n", *(double *)(v3 + 24));
printf("distanceInverseSquareMean %f\n", *(double *)(v3 + 32));
return printf("distanceInverseSquaredVariance %f\n", *(double *)(v3 + 40));
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
__int64 v3; // r12
__int64 v4; // rbx
const char *i; // rsi
double v6; // xmm0_8
unsigned int v7; // eax
__int64 v9; // rbx
const char *j; // rsi
double v11; // xmm0_8
__int64 v12[7]; // [rsp+0h] [rbp-38h]

printf("numParticles %u\n", *a1);
v1 = a1[2];
if ( v1 )
{
if ( v1 == 1 )
puts("shape disk");
}
else
{
puts("shape square");
}
v2 = a1[1];
v3 = *((_QWORD *)a1 + 4);
v12[1] = (__int64)aYzt;
v12[2] = (__int64)&aYzt[1];
v12[3] = (__int64)&aYzt[2];
if ( v2 )
{
v4 = 0LL;
for ( i = (const char *)&unk_811; ; i = (const char *)v12[v4] )
{
v6 = *(double *)(*(_QWORD *)v3 + 8 * v4++);
printf("%sMean %f\n", i, v6);
v7 = a1[1];
if ( v7 <= (unsigned int)v4 )
break;
}
if ( v7 )
{
v9 = 0LL;
for ( j = (const char *)&unk_811; ; j = (const char *)v12[v9] )
{
v11 = *(double *)(*(_QWORD *)(v3 + 8) + 8 * v9++);
printf("%sVariance %f\n", j, v11);
if ( a1[1] <= (unsigned int)v9 )
break;
}
}
}
printf("distanceMean %f\n", *(double *)(v3 + 16));
printf("distanceVariance %f\n", *(double *)(v3 + 24));
printf("distanceInverseSquareMean %f\n", *(double *)(v3 + 32));
return printf("distanceInverseSquaredVariance %f\n", *(double *)(v3 + 40));
}

original_code:
void pPrintStatistics(ParticleContainer *particleContainer)
{
  printf("numParticles %u\n", particleContainer->_numParticles);
  switch (particleContainer->_shape)
    {
    case DISK:
      printf("shape disk\n");
      break;
    case SQUARE:
      printf("shape square\n");
      break;
    }
  ParticleStats *particleStats = particleContainer->_particleStats;
  char *positions[] = {"x", "y", "z", "t"};
  unsigned int i;
  for (i=0; i<particleContainer->_numDimensions; i++)
    {
      printf("%sMean %f\n", positions[i], particleStats->_positionMean[i]);
    }
  for (i=0; i<particleContainer->_numDimensions; i++)
    {
      printf("%sVariance %f\n", positions[i], particleStats->_positionVariance[i]);
    }
  printf("distanceMean %f\n", particleStats->_distanceMean);
  printf("distanceVariance %f\n", particleStats->_distanceVariance);
  printf("distanceInverseSquareMean %f\n", particleStats->_distanceInvSqrMean);
  printf("distanceInverseSquaredVariance %f\n", particleStats->_distanceInvSqrVariance);
}

canonical_original_code:
void pPrintStatistics(struct ParticleContainer *particleContainer)
{
  printf("numParticles %u\n", particleContainer->_numParticles);
  switch (particleContainer->_shape)
    {
    case DISK:
      printf("shape disk\n");
      break;
    case SQUARE:
      printf("shape square\n");
      break;
    }
  struct ParticleStats *particleStats = particleContainer->_particleStats;
  char *positions[] = {"x", "y", "z", "t"};
  unsigned int i;
  for (i=0; i<particleContainer->_numDimensions; i++)
    {
      printf("%sMean %f\n", positions[i], particleStats->_positionMean[i]);
    }
  for (i=0; i<particleContainer->_numDimensions; i++)
    {
      printf("%sVariance %f\n", positions[i], particleStats->_positionVariance[i]);
    }
  printf("distanceMean %f\n", particleStats->_distanceMean);
  printf("distanceVariance %f\n", particleStats->_distanceVariance);
  printf("distanceInverseSquareMean %f\n", particleStats->_distanceInvSqrMean);
  printf("distanceInverseSquaredVariance %f\n", particleStats->_distanceInvSqrVariance);
}

variable_types: struct ParticleStats { double *_positionMean; double *_positionVariance; double _distanceMean; double _distanceVariance; double _distanceInvSqrMean; double _distanceInvSqrVariance; } *

variable_types:
positions
char *[]


Compute

decompiled_code:
int __fastcall Compute(float a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
struct timespec remaining; // [rsp+10h] [rbp-18h] BYREF

v2.tv_sec = (unsigned int)(int)a1;
v2.tv_nsec = (unsigned int)(int)(float)((float)(a1 - (float)(int)a1) * 1000000000.0);
return nanosleep(&v2, &remaining);
}

canonical_decompiled_code:
int __fastcall func11(float a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
struct timespec remaining; // [rsp+10h] [rbp-18h] BYREF

v2.tv_sec = (unsigned int)(int)a1;
v2.tv_nsec = (unsigned int)(int)(float)((float)(a1 - (float)(int)a1) * 1000000000.0);
return nanosleep(&v2, &remaining);
}

original_code:
void Compute ( float effort )
{
  struct timespec rqtp;
  struct timespec rmtp;
  rqtp.tv_sec = (long) effort;
  rqtp.tv_nsec = (effort - ((long) effort) ) * 1000000000 ;
  nanosleep(&rqtp, &rmtp);
}

canonical_original_code:
void Compute(float effort)
{
  struct timespec rqtp;
  struct timespec rmtp;
  rqtp.tv_sec = (long) effort;
  rqtp.tv_nsec = (effort - ((long) effort) ) * 1000000000 ;
  nanosleep(&rqtp, &rmtp);
}

variable_types: effort float

variable_types: struct timespec { long tv_sec; long tv_nsec; }


main

repo: cota/atomictest

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi
size_t v4; // rsi
size_t v5; // r13
pthread_t *v6; // r12
pthread_t *v7; // rbx
size_t v8; // rbp
size_t v9; // rbx
pthread_t v10; // rdi
__int64 v11; // rax
__int64 v12; // rdx
struct timeval v14; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF

v3 = argc - 1;
if ( v3 )
{
n_threads = strtoul(argv[v3], 0LL, 0);
v4 = n_threads;
}
else
{
n_threads = 1LL;
v4 = 1LL;
}
printf("%lu n_threads\n", v4);
v5 = n_threads;
v6 = (pthread_t *)calloc(n_threads, 8uLL);
if ( !v6 )
{
perror("threads");
exit(1);
}
if ( gettimeofday(&v14, 0LL) )
{
perror("gettimeofday");
exit(1);
}
v7 = v6;
v8 = 0LL;
if ( v5 )
{
do
{
if ( pthread_create(v7, 0LL, thread, 0LL) )
{
perror("thread_create");
exit(1);
}
++v8;
++v7;
}
while ( n_threads > v8 );
if ( n_threads )
{
v9 = 0LL;
do
{
v10 = v6[v9++];
pthread_join(v10, 0LL);
}
while ( n_threads > v9 );
}
}
if ( gettimeofday(&tv, 0LL) )
perror("gettimeofday");
tv_to_ul_isra_0(v14.tv_sec, v14.tv_usec);
v11 = tv_to_ul_isra_0(tv.tv_sec, tv.tv_usec);
printf(
"%lu ns\n%lu ops\n%lu ns/access\n",
1000 * (v11 - v12),
0x80000LL,
(unsigned __int64)(1000 * (v11 - v12)) >> 19);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi
size_t v4; // rsi
size_t v5; // r13
pthread_t *v6; // r12
pthread_t *v7; // rbx
size_t v8; // rbp
size_t v9; // rbx
pthread_t v10; // rdi
__int64 v11; // rax
__int64 v12; // rdx
struct timeval v14; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF

v3 = argc - 1;
if ( v3 )
{
n_threads = strtoul(argv[v3], 0LL, 0);
v4 = n_threads;
}
else
{
n_threads = 1LL;
v4 = 1LL;
}
printf("%lu n_threads\n", v4);
v5 = n_threads;
v6 = (pthread_t *)calloc(n_threads, 8uLL);
if ( !v6 )
{
perror("threads");
exit(1);
}
if ( gettimeofday(&v14, 0LL) )
{
perror("gettimeofday");
exit(1);
}
v7 = v6;
v8 = 0LL;
if ( v5 )
{
do
{
if ( pthread_create(v7, 0LL, thread, 0LL) )
{
perror("thread_create");
exit(1);
}
++v8;
++v7;
}
while ( n_threads > v8 );
if ( n_threads )
{
v9 = 0LL;
do
{
v10 = v6[v9++];
pthread_join(v10, 0LL);
}
while ( n_threads > v9 );
}
}
if ( gettimeofday(&tv, 0LL) )
perror("gettimeofday");
func9(v14.tv_sec, v14.tv_usec);
v11 = func9(tv.tv_sec, tv.tv_usec);
printf(
"%lu ns\n%lu ops\n%lu ns/access\n",
1000 * (v11 - v12),
0x80000LL,
(unsigned __int64)(1000 * (v11 - v12)) >> 19);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 pthread_t *threads;
 struct timeval tv_start, tv_end;
 unsigned long start, end;
 unsigned long ns;
 int rc;
 int i;
 argc--;
 if (argc == 0)
  n_threads = 1;
 else
  n_threads = strtoul(argv[argc], ((void *)0), 0);
 printf("%lu n_threads\n", n_threads);
 threads = calloc(n_threads, sizeof(pthread_t));
 if (threads == ((void *)0)) {
  perror("threads");
  exit(1);
 }
 rc = gettimeofday(&tv_start, ((void *)0));
 if (rc) {
  perror("gettimeofday");
  exit(1);
 }
 for (i = 0; i < n_threads; i++) {
  rc = pthread_create(&threads[i], ((void *)0), thread, ((void *)0));
  if (rc) {
   perror("thread_create");
   exit(1);
  }
 }
 for (i = 0; i < n_threads; i++)
  pthread_join(threads[i], ((void *)0));
 rc = gettimeofday(&tv_end, ((void *)0));
 if (rc)
  perror("gettimeofday");
 start = tv_to_ul(&tv_start);
 end = tv_to_ul(&tv_end);
 ns = (end - start) * 1000;
 printf("%lu ns\n%lu ops\n%lu ns/access\n", ns, ops, ns / ops);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long *threads;
 struct timeval tv_start; struct timeval tv_end;
 unsigned long start; unsigned long end;
 unsigned long ns;
 int rc;
 int i;
 argc--;
 if (argc == 0)
  n_threads = 1;
 else
  n_threads = strtoul(argv[argc], ((void *)0), 0);
 printf("%lu n_threads\n", n_threads);
 threads = calloc(n_threads, sizeof(pthread_t));
 if (threads == ((void *)0)) {
  perror("threads");
  exit(1);
 }
 rc = gettimeofday(&tv_start, ((void *)0));
 if (rc) {
  perror("gettimeofday");
  exit(1);
 }
 for (i = 0; i < n_threads; i++) {
  rc = pthread_create(&threads[i], ((void *)0), thread, ((void *)0));
  if (rc) {
   perror("thread_create");
   exit(1);
  }
 }
 for (i = 0; i < n_threads; i++)
  pthread_join(threads[i], ((void *)0));
 rc = gettimeofday(&tv_end, ((void *)0));
 if (rc)
  perror("gettimeofday");
 start = tv_to_ul(&tv_start);
 end = tv_to_ul(&tv_end);
 ns = (end - start) * 1000;
 printf("%lu ns\n%lu ops\n%lu ns/access\n", ns, ops, ns / ops);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
threads
unsigned long *

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
start
unsigned long

variable_types:
end
unsigned long

variable_types:
ns
unsigned long

variable_types: rc int

variable_types: i int


thread

decompiled_code:
void *__fastcall thread(void *a1)
{
__int64 v1; // rax

do
atomic_inc_constprop_0();
while ( v1 != 1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
__int64 v1; // rax

do
func7();
while ( v1 != 1 );
return 0LL;
}

original_code:
static void *thread(void *args)
{
 unsigned long i;
 for (i = 0; i < ops; i++)
  atomic_inc(&val);
 return ((void *)0);
}

variable_types:
args
void *

variable_types:
i
unsigned long

return_type: void *


JKISS

repo: cotillion/cd-gamedriver

variable_types:
t
unsigned long long


decompiled_code:
__int64 secure_rand()
{
int v0; // eax
int v1; // ebp
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = open("/dev/urandom", 0);
if ( v0 == -1 || (v1 = v0, read(v0, buf, 4uLL) != 4) )
exit(-1);
close(v1);
return buf[0];
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
int v1; // ebp
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = open("/dev/urandom", 0);
if ( v0 == -1 || (v1 = v0, read(v0, buf, 4uLL) != 4) )
exit(-1);
close(v1);
return buf[0];
}

original_code:
unsigned int
secure_rand(void)
{
    int fn;
    unsigned int r;
    fn = open("/dev/urandom", 00);
    if (fn == -1)
        exit(-1);
    if (read(fn, &r, 4) != 4)
        exit(-1);
    close(fn);
    return r;
}

canonical_original_code:
unsigned int secure_rand()
{
    int fn;
    unsigned int r;
    fn = open("/dev/urandom", 00);
    if (fn == -1)
        exit(-1);
    if (read(fn, &r, 4) != 4)
        exit(-1);
    close(fn);
    return r;
}

variable_types: fn int

variable_types:
r
unsigned int


decompiled_code:
__int64 init_random()
{
unsigned int v0; // edx
__int64 result; // rax

x = secure_rand();
do
y = secure_rand();
while ( !y );
z = secure_rand();
v0 = secure_rand();
result = 698769068 * (v0 / 0x29A65EAC);
c = v0 % 0x29A65EAC + 1;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // edx
__int64 result; // rax

x = func1();
do
y = func1();
while ( !y );
z = func1();
v0 = func1();
result = 698769068 * (v0 / 0x29A65EAC);
c = v0 % 0x29A65EAC + 1;
return result;
}

original_code:
void
init_random()
{
    x = secure_rand();
    while (!(y = secure_rand()));
    z = secure_rand();
    c = secure_rand() % 698769068 + 1;
}


decompiled_code:
__int64 __fastcall set_random_seed(int a1)
{
int v1; // eax
int v2; // eax
int v3; // eax
__int64 result; // rax

v1 = x;
x = 123456789;
x_save = v1;
v2 = y;
y = a1;
y_save = v2;
v3 = z;
z = 43219876;
z_save = v3;
result = (unsigned int)c;
c = 6543217;
c_save = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // eax
int v2; // eax
int v3; // eax
__int64 result; // rax

v1 = x;
x = 123456789;
x_save = v1;
v2 = y;
y = a1;
y_save = v2;
v3 = z;
z = 43219876;
z_save = v3;
result = (unsigned int)c;
c = 6543217;
c_save = result;
return result;
}

original_code:
void
set_random_seed(unsigned int seed) {
    x_save = x; y_save = y; z_save = z; c_save = c;
    x = 123456789; y = seed; z = 43219876; c = 6543217;
}

variable_types:
seed
unsigned int


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

x = x_save;
y = y_save;
z = z_save;
result = (unsigned int)c_save;
c = c_save;
return result;
}

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

x = x_save;
y = y_save;
z = z_save;
result = (unsigned int)c_save;
c = c_save;
return result;
}

original_code:
void
clear_random_seed() {
    x = x_save; y = y_save; z = z_save; c = c_save;
}


decompiled_code:
unsigned __int64 __fastcall random_number(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // r9
__int64 v5; // rdi
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
unsigned int v10; // eax
unsigned __int64 v11; // r8

v4 = 0LL;
if ( a1 > 0 )
{
v5 = (unsigned int)JKISS(a1, a2, a3, a4, a1, 0LL);
v10 = JKISS(v5, a2, v6, v7, v8, v9);
v4 = ((v5 << 32) + (unsigned __int64)v10) % v11;
}
return v4;
}

original_code:
long long
random_number(long long n)
{
    if (n <= 0)
        return 0;
    return ((unsigned long long)JKISS() * 4294967296 + (unsigned long long)JKISS()) % n;
}

variable_types:
n
long long

return_type: long long


original_code:
double
random_double()
{
    double x;
    unsigned int a, b;
    a = JKISS() >> 6;
    b = JKISS() >> 5;
    x = (a * 134217728.0 + b) / 9007199254740992.0;
    return x;
}

canonical_original_code:
double random_double()
{
    double x;
    unsigned int a; unsigned int b;
    a = JKISS() >> 6;
    b = JKISS() >> 5;
    x = (a * 134217728.0 + b) / 9007199254740992.0;
    return x;
}

variable_types: x double

variable_types:
a
unsigned int

variable_types:
b
unsigned int

return_type: double


decompiled_code:
__int64 init_hash()
{
__int64 v0; // rbx
unsigned int v1; // edx
__int64 result; // rax
char v3; // cl

v0 = 4LL;
do
{
v1 = secure_rand();
result = v0 - 4;
do
{
v3 = v1;
++result;
v1 >>= 8;
*(_BYTE *)(result + 95) = v3;
}
while ( result != v0 );
v0 = result + 4;
}
while ( result != 16 );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
unsigned int v1; // edx
__int64 result; // rax
char v3; // cl

v0 = 4LL;
do
{
v1 = secure_rand();
result = v0 - 4;
do
{
v3 = v1;
++result;
v1 >>= 8;
*(_BYTE *)(result + 95) = v3;
}
while ( result != v0 );
v0 = result + 4;
}
while ( result != 16 );
return result;
}

original_code:
void
init_hash() {
    int i = 0;
    while (i < sizeof(key)) {
        unsigned int rnd = secure_rand();
        for (int bit = 0; bit < sizeof(rnd); bit++) {
            unsigned char c = rnd & 0xff;
            rnd >>= 8;
            key[i] = c;
            i++;
        }
    }
}

variable_types:
rnd
unsigned int

variable_types: bit int

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall hash_string(const char *a1)
{
size_t v1; // rax

v1 = strlen(a1);
return siphash(&key, a1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
size_t v1; // rax

v1 = strlen(a1);
return siphash(&key, a1, v1);
}

original_code:
unsigned long long
hash_string(const char *s) {
    return siphash(key, (unsigned char *)s, strlen(s));
}

canonical_original_code:
unsigned long long hash_string(char *s) {
    return siphash(key, (unsigned char *)s, strlen(s));
}

variable_types:
s
char *

return_type: unsigned long long


decompiled_code:
__int64 f_upper_case()
{
__int64 result; // rax
const char *v1; // rbp
int v2; // ebx
const __int32_t **v3; // rsi
__int64 v4; // rax

result = qword_310;
if ( *qword_310 != 2 )
{
v1 = (const char *)make_mstring(*(_QWORD *)(qword_310 + 8LL));
v2 = strlen(v1) - 1;
if ( v2 >= 0 )
{
v3 = _ctype_toupper_loc();
v4 = v2;
do
{
v1[v4] = (*v3)[v1[v4]];
--v4;
}
while ( (int)v4 >= 0 );
}
pop_stack();
result = push_mstring(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
const char *v1; // rbp
int v2; // ebx
const __int32_t **v3; // rsi
__int64 v4; // rax

result = qword_310;
if ( *qword_310 != 2 )
{
v1 = (const char *)make_mstring(*(_QWORD *)(qword_310 + 8LL));
v2 = strlen(v1) - 1;
if ( v2 >= 0 )
{
v3 = _ctype_toupper_loc();
v4 = v2;
do
{
v1[v4] = (*v3)[v1[v4]];
--v4;
}
while ( (int)v4 >= 0 );
}
pop_stack();
result = push_mstring(v1);
}
return result;
}

original_code:
void
f_upper_case(int num_arg)
{
    char *str;
    int i;
    if (sp->type == 0x2)
 return;
    str = make_mstring(sp->u.string);
    for (i = strlen(str)-1; i>=0; i--)
 str[i] = toupper(str[i]);
    pop_stack();
    push_mstring(str);
}

variable_types:
str
char *


decompiled_code:
__int64 f_lower_case()
{
__int64 result; // rax
const char *v1; // rbp
int v2; // ebx
const __int32_t **v3; // rsi
__int64 v4; // rax

result = qword_310;
if ( *qword_310 != 2 )
{
v1 = (const char *)make_mstring(*(_QWORD *)(qword_310 + 8LL));
v2 = strlen(v1) - 1;
if ( v2 >= 0 )
{
v3 = _ctype_tolower_loc();
v4 = v2;
do
{
v1[v4] = (*v3)[v1[v4]];
--v4;
}
while ( (int)v4 >= 0 );
}
pop_stack();
result = push_mstring(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
const char *v1; // rbp
int v2; // ebx
const __int32_t **v3; // rsi
__int64 v4; // rax

result = qword_310;
if ( *qword_310 != 2 )
{
v1 = (const char *)make_mstring(*(_QWORD *)(qword_310 + 8LL));
v2 = strlen(v1) - 1;
if ( v2 >= 0 )
{
v3 = _ctype_tolower_loc();
v4 = v2;
do
{
v1[v4] = (*v3)[v1[v4]];
--v4;
}
while ( (int)v4 >= 0 );
}
pop_stack();
result = push_mstring(v1);
}
return result;
}

original_code:
void
f_lower_case(int num_arg)
{
    char *str;
    int i;
    if (sp->type == 0x2)
 return;
    str = make_mstring(sp->u.string);
    for (i = strlen(str)-1; i>=0; i--)
 str[i] = tolower(str[i]);
    pop_stack();
    push_mstring(str);
}


decompiled_code:
__int64 f_readable_string()
{
__int64 result; // rax
const char *v1; // rbp
int v2; // ebx
const unsigned __int16 **v3; // rsi
__int64 v4; // rax

result = qword_310;
if ( *qword_310 != 2 )
{
v1 = (const char *)make_mstring(*(_QWORD *)(qword_310 + 8LL));
v2 = strlen(v1) - 1;
if ( v2 >= 0 )
{
v3 = _ctype_b_loc();
v4 = v2;
do
{
if ( ((*v3)[(unsigned __int8)v1[v4]] & 0x4000) == 0 )
v1[v4] = 46;
--v4;
}
while ( (int)v4 >= 0 );
}
pop_stack();
result = push_mstring(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
const char *v1; // rbp
int v2; // ebx
const unsigned __int16 **v3; // rsi
__int64 v4; // rax

result = qword_310;
if ( *qword_310 != 2 )
{
v1 = (const char *)make_mstring(*(_QWORD *)(qword_310 + 8LL));
v2 = strlen(v1) - 1;
if ( v2 >= 0 )
{
v3 = _ctype_b_loc();
v4 = v2;
do
{
if ( ((*v3)[(unsigned __int8)v1[v4]] & 0x4000) == 0 )
v1[v4] = 46;
--v4;
}
while ( (int)v4 >= 0 );
}
pop_stack();
result = push_mstring(v1);
}
return result;
}

original_code:
void
f_readable_string(int num_arg)
{
    if (sp->type == 0x2)
        return;
    char *str = make_mstring(sp->u.string);
    for (int i = strlen(str) - 1; i >= 0; i--) {
        unsigned char c = str[i];
        if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISprint))
            str[i] = '.';
    }
    pop_stack();
    push_mstring(str);
}

canonical_original_code:
void f_readable_string(int num_arg)
{
    if (sp->type == 0x2)
        return;
    char *str = make_mstring(sp->u.string);
    for (int i = strlen(str) - 1; i >= 0; i--) {
        unsigned char c = str[i];
        if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISprint))
            str[i] = '.';
    }
    pop_stack();
    push_mstring(str);
}


decompiled_code:
__int64 f_strlen()
{
__int64 v0; // rbp

v0 = 0LL;
if ( *qword_310 != 2 )
v0 = (int)strlen(*(const char **)(qword_310 + 8LL));
pop_stack();
return push_number(v0);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbp

v0 = 0LL;
if ( *qword_310 != 2 )
v0 = (int)strlen(*(const char **)(qword_310 + 8LL));
pop_stack();
return push_number(v0);
}

original_code:
void
f_strlen(int xxx)
{
    int i;
    if (sp->type == 0x2)
 i = 0;
    else
 i = strlen(sp->u.string);
    pop_stack();
    push_number(i);
}

variable_types: xxx int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbp
char *v5; // r12
char *v6; // r13
__int64 v7; // rax
char v9[280]; // [rsp+0h] [rbp-118h] BYREF

setlinebuf(stdout);
putchar(10);
while ( fgets(v9, 256, stdin) )
{
v3 = strrchr(v9, 10);
if ( v3 )
*v3 = 0;
v4 = strtok(v9, ",");
v5 = strtok(0LL, ",");
v6 = strtok(0LL, ",");
if ( v5 == 0LL || v4 == 0LL || !v6 )
{
fprintf(stderr, "Invalid input format: %s\n", v9);
}
else
{
v7 = reverse_lookup(v4);
if ( !v7 )
v7 = (__int64)v4;
printf("%s,%s,%s,%s,%s\n", v4, v5, v6, v7, "");
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbp
char *v5; // r12
char *v6; // r13
__int64 v7; // rax
char v9[280]; // [rsp+0h] [rbp-118h] BYREF

setlinebuf(stdout);
putchar(10);
while ( fgets(v9, 256, stdin) )
{
v3 = strrchr(v9, 10);
if ( v3 )
*v3 = 0;
v4 = strtok(v9, ",");
v5 = strtok(0LL, ",");
v6 = strtok(0LL, ",");
if ( v5 == 0LL || v4 == 0LL || !v6 )
{
fprintf(stderr, "Invalid input format: %s\n", v9);
}
else
{
v7 = func8(v4);
if ( !v7 )
v7 = (__int64)v4;
printf("%s,%s,%s,%s,%s\n", v4, v5, v6, v7, "");
}
}
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
    char buf[0x100];
    char *local_port;
    char *remote_port;
    char *addr;
    char *ptr;
    char *ident = "";
    char *reverse;
    (void)setlinebuf(stdout);
    (void)printf("\n");
    while (1)
    {
        if (fgets(buf, sizeof(buf), stdin) == ((void *)0))
            break;
        if ((ptr = strrchr(buf, '\n')))
            *ptr = '\0';
        addr = strtok(buf, ",");
        local_port = strtok(((void *)0), ",");
        remote_port = strtok(((void *)0), ",");
        if (addr == ((void *)0) || local_port == ((void *)0) || remote_port == ((void *)0))
        {
            fprintf(stderr, "Invalid input format: %s\n", buf);
            continue;
        }
        reverse = reverse_lookup(addr);
        if (reverse == ((void *)0))
            reverse = addr;
        printf("%s,%s,%s,%s,%s\n", addr, local_port, remote_port, reverse, ident);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char buf[256];
    char *local_port;
    char *remote_port;
    char *addr;
    char *ptr;
    char *ident = "";
    char *reverse;
    (void)setlinebuf(stdout);
    (void)printf("\n");
    while (1)
    {
        if (fgets(buf, sizeof(buf), stdin) == ((void *)0))
            break;
        if ((ptr = strrchr(buf, '\n')))
            *ptr = '\0';
        addr = strtok(buf, ",");
        local_port = strtok(((void *)0), ",");
        remote_port = strtok(((void *)0), ",");
        if (addr == ((void *)0) || local_port == ((void *)0) || remote_port == ((void *)0))
        {
            fprintf(stderr, "Invalid input format: %s\n", buf);
            continue;
        }
        reverse = reverse_lookup(addr);
        if (reverse == ((void *)0))
            reverse = addr;
        printf("%s,%s,%s,%s,%s\n", addr, local_port, remote_port, reverse, ident);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
buf
char [256]

variable_types:
addr
char *

variable_types:
ptr
char *

variable_types:
ident
char *

variable_types:
reverse
char *


decompiled_code:
const char *__fastcall get_auth_name(const char *a1, unsigned int a2, unsigned int a3)
{
int v4; // eax
int v5; // ebp
struct addrinfo *v6; // r12
int v7; // eax
int v8; // er15
const char *result; // rax
unsigned int v10; // eax
int v11; // er14
__int64 v12; // r13
__int64 v13; // rbx
__int64 v14; // rcx
ssize_t v15; // rax
char v16; // al
bool v17; // zf
const char *v18; // rax
size_t n; // [rsp+0h] [rbp-518h]
int v20; // [rsp+Ch] [rbp-50Ch]
struct addrinfo *pai; // [rsp+18h] [rbp-500h] BYREF
struct timeval timeout; // [rsp+20h] [rbp-4F8h] BYREF
struct addrinfo req; // [rsp+30h] [rbp-4E8h] BYREF
fd_set writefds; // [rsp+60h] [rbp-4B8h] BYREF
char s[1080]; // [rsp+E0h] [rbp-438h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
v4 = getaddrinfo(a1, "113", &req, &pai);
v5 = v4;
if ( v4 )
{
v18 = gai_strerror(v4);
fprintf(stderr, "getaddrinfo failed: %s\n", v18);
return 0LL;
}
v6 = pai;
if ( !pai )
{
LABEL_8:
freeaddrinfo(v6);
return "";
}
while ( 1 )
{
v7 = socket(v6->ai_family, v6->ai_socktype, v6->ai_protocol);
v8 = v7;
if ( v7 != -1 )
break;
LABEL_6:
v6 = v6->ai_next;
if ( !v6 )
{
v6 = pai;
goto LABEL_8;
}
}
if ( connect(v7, v6->ai_addr, v6->ai_addrlen) == -1 )
{
close(v8);
goto LABEL_6;
}
freeaddrinfo(pai);
sprintf(s, "%u , %u\r\n", a3, a2);
n = strlen(s);
v10 = fcntl(v8, 3);
BYTE1(v10) |= 8u;
fcntl(v8, 4, v10);
memset(&writefds, 0, sizeof(writefds));
v11 = v8 + 1;
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
v12 = v8 / 64;
v13 = 1LL << (v8 % 64);
writefds.fds_bits[v12] |= v13;
if ( select(v8 + 1, 0LL, &writefds, 0LL, &timeout)
&& (writefds.fds_bits[v12] & v13) != 0
&& write(v8, s, n) == n
&& (memset(&writefds, 0, sizeof(writefds)),
writefds.fds_bits[v12] |= v13,
timeout.tv_sec = 10LL,
timeout.tv_usec = 0LL,
select(v11, &writefds, 0LL, 0LL, &timeout))
&& (v20 = 2002, (writefds.fds_bits[v12] & v13) != 0) )
{
do
{
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v12] |= v13;
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
if ( !select(v11, &writefds, 0LL, 0LL, &timeout) )
{
v14 = v5;
goto LABEL_22;
}
v14 = v5;
if ( (writefds.fds_bits[v12] & v13) == 0 )
goto LABEL_22;
v15 = read(v8, &s[v5], 1uLL);
v14 = v5;
if ( v15 != 1 )
goto LABEL_22;
v16 = s[v5];
if ( v16 == 10 )
goto LABEL_22;
v5 += (v16 & 0xFB) != 9;
if ( !--v20 )
goto LABEL_25;
}
while ( v5 != 1023 );
v14 = 1023LL;
LABEL_22:
s[v14] = 0;
close(v8);
v17 = (unsigned int)__isoc99_sscanf() == 1;
result = "%u , %u\r\n" + 9;
if ( v17 )
result = (const char *)&user_name_1;
}
else
{
LABEL_25:
close(v8);
result = "%u , %u\r\n" + 9;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(const char *a1, unsigned int a2, unsigned int a3)
{
int v4; // eax
int v5; // ebp
struct addrinfo *v6; // r12
int v7; // eax
int v8; // er15
const char *result; // rax
unsigned int v10; // eax
int v11; // er14
__int64 v12; // r13
__int64 v13; // rbx
__int64 v14; // rcx
ssize_t v15; // rax
char v16; // al
bool v17; // zf
const char *v18; // rax
size_t n; // [rsp+0h] [rbp-518h]
int v20; // [rsp+Ch] [rbp-50Ch]
struct addrinfo *pai; // [rsp+18h] [rbp-500h] BYREF
struct timeval timeout; // [rsp+20h] [rbp-4F8h] BYREF
struct addrinfo req; // [rsp+30h] [rbp-4E8h] BYREF
fd_set writefds; // [rsp+60h] [rbp-4B8h] BYREF
char s[1080]; // [rsp+E0h] [rbp-438h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
v4 = getaddrinfo(a1, "113", &req, &pai);
v5 = v4;
if ( v4 )
{
v18 = gai_strerror(v4);
fprintf(stderr, "getaddrinfo failed: %s\n", v18);
return 0LL;
}
v6 = pai;
if ( !pai )
{
LABEL_8:
freeaddrinfo(v6);
return "";
}
while ( 1 )
{
v7 = socket(v6->ai_family, v6->ai_socktype, v6->ai_protocol);
v8 = v7;
if ( v7 != -1 )
break;
LABEL_6:
v6 = v6->ai_next;
if ( !v6 )
{
v6 = pai;
goto LABEL_8;
}
}
if ( connect(v7, v6->ai_addr, v6->ai_addrlen) == -1 )
{
close(v8);
goto LABEL_6;
}
freeaddrinfo(pai);
sprintf(s, "%u , %u\r\n", a3, a2);
n = strlen(s);
v10 = fcntl(v8, 3);
BYTE1(v10) |= 8u;
fcntl(v8, 4, v10);
memset(&writefds, 0, sizeof(writefds));
v11 = v8 + 1;
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
v12 = v8 / 64;
v13 = 1LL << (v8 % 64);
writefds.fds_bits[v12] |= v13;
if ( select(v8 + 1, 0LL, &writefds, 0LL, &timeout)
&& (writefds.fds_bits[v12] & v13) != 0
&& write(v8, s, n) == n
&& (memset(&writefds, 0, sizeof(writefds)),
writefds.fds_bits[v12] |= v13,
timeout.tv_sec = 10LL,
timeout.tv_usec = 0LL,
select(v11, &writefds, 0LL, 0LL, &timeout))
&& (v20 = 2002, (writefds.fds_bits[v12] & v13) != 0) )
{
do
{
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v12] |= v13;
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
if ( !select(v11, &writefds, 0LL, 0LL, &timeout) )
{
v14 = v5;
goto LABEL_22;
}
v14 = v5;
if ( (writefds.fds_bits[v12] & v13) == 0 )
goto LABEL_22;
v15 = read(v8, &s[v5], 1uLL);
v14 = v5;
if ( v15 != 1 )
goto LABEL_22;
v16 = s[v5];
if ( v16 == 10 )
goto LABEL_22;
v5 += (v16 & 0xFB) != 9;
if ( !--v20 )
goto LABEL_25;
}
while ( v5 != 1023 );
v14 = 1023LL;
LABEL_22:
s[v14] = 0;
close(v8);
v17 = (unsigned int)__isoc99_sscanf() == 1;
result = "%u , %u\r\n" + 9;
if ( v17 )
result = (const char *)&user_name_1;
}
else
{
LABEL_25:
close(v8);
result = "%u , %u\r\n" + 9;
}
return result;
}

original_code:
char *
get_auth_name(char *addr, int local_port, int remote_port)
{
    struct addrinfo hints;
    struct addrinfo *result, *rp;
    int s, flags;
    char buf[1024];
    static char user_name[1024];
    int buflen;
    int i, n;
    struct timeval timeout;
    fd_set fs;
    memset(&hints, 0, sizeof (hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    s = getaddrinfo(addr, "113", &hints, &result);
    if (s != 0)
    {
        fprintf (stderr, "getaddrinfo failed: %s\n", gai_strerror(s));
        return ((void *)0);
    }
    for (rp = result; rp != ((void *)0); rp = rp->ai_next) {
        s = socket(rp->ai_family, rp->ai_socktype,
                     rp->ai_protocol);
        if (s == -1)
            continue;
        if (connect(s, rp->ai_addr, rp->ai_addrlen) != -1)
            break;
        close(s);
    }
    freeaddrinfo(result);
    if (rp == ((void *)0))
        return "";
   (void)sprintf(buf, "%u , %u\r\n", remote_port, local_port);
    buflen = strlen(buf);
    flags = fcntl(s, 3);
    (void)fcntl(s, 4, flags | 04000);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;
    if (select(s + 1, ((void *)0), &fs, ((void *)0), &timeout) == 0 ||
        !((((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        (void)close(s);
        return "";
    }
    if (write(s, buf, buflen) != buflen) {
        (void)close(s);
        return "";
    }
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = 10;
    timeout.tv_usec = 0;
    if (select(s + 1, &fs, ((void *)0), ((void *)0), &timeout) == 0 ||
        !((((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        (void)close(s);
        return "";
    }
    for (n = i = 0; i < sizeof buf - 1; n++) {
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
        timeout.tv_sec = 1;
        timeout.tv_usec = 0;
        if (select(s + 1, &fs, ((void *)0), ((void *)0), &timeout) == 0 ||
            !((((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0))
            break;
        if (read(s, buf + i, 1) != 1)
            break;
        if (buf[i] == '\n')
            break;
        if ( buf[i] != '\t' && buf[i] != '\r')
            i++;
        if (n > 2000) {
            (void)close(s);
            return "";
        }
    }
    buf[i] = 0;
    (void)close(s);
    if(sscanf(buf, "%*u , %*u : USERID :%*[^:]:%s", user_name) != 1)
        return "";
    else
        return user_name;
}

canonical_original_code:
char *get_auth_name(char *addr, int local_port, int remote_port)
{
    struct addrinfo hints;
    struct addrinfo *result; struct addrinfo *rp;
    int s; int flags;
    char buf[1024];
    static char user_name[1024];
    int buflen;
    int i; int n;
    struct timeval timeout;
    struct fd_set fs;
    memset(&hints, 0, sizeof (hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    s = getaddrinfo(addr, "113", &hints, &result);
    if (s != 0)
    {
        fprintf (stderr, "getaddrinfo failed: %s\n", gai_strerror(s));
        return ((void *)0);
    }
    for (rp = result; rp != ((void *)0); rp = rp->ai_next) {
        s = socket(rp->ai_family, rp->ai_socktype,
                     rp->ai_protocol);
        if (s == -1)
            continue;
        if (connect(s, rp->ai_addr, rp->ai_addrlen) != -1)
            break;
        close(s);
    }
    freeaddrinfo(result);
    if (rp == ((void *)0))
        return "";
   (void)sprintf(buf, "%u , %u\r\n", remote_port, local_port);
    buflen = strlen(buf);
    flags = fcntl(s, 3);
    (void)fcntl(s, 4, flags | 04000);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;
    if (select(s + 1, ((void *)0), &fs, ((void *)0), &timeout) == 0 ||
        !((((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        (void)close(s);
        return "";
    }
    if (write(s, buf, buflen) != buflen) {
        (void)close(s);
        return "";
    }
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = 10;
    timeout.tv_usec = 0;
    if (select(s + 1, &fs, ((void *)0), ((void *)0), &timeout) == 0 ||
        !((((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        (void)close(s);
        return "";
    }
    for (n = i = 0; i < sizeof buf - 1; n++) {
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
        timeout.tv_sec = 1;
        timeout.tv_usec = 0;
        if (select(s + 1, &fs, ((void *)0), ((void *)0), &timeout) == 0 ||
            !((((&fs)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0))
            break;
        if (read(s, buf + i, 1) != 1)
            break;
        if (buf[i] == '\n')
            break;
        if ( buf[i] != '\t' && buf[i] != '\r')
            i++;
        if (n > 2000) {
            (void)close(s);
            return "";
        }
    }
    buf[i] = 0;
    (void)close(s);
    if(sscanf(buf, "%*u , %*u : USERID :%*[^:]:%s", user_name) != 1)
        return "";
    else
        return user_name;
}

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: s int

variable_types: flags int

variable_types:
buf
char [1024]

variable_types: buflen int

variable_types: i int

variable_types: n int

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
fs
struct fd_set { long __fds_bits[-1]; }

return_type: char *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }