euli

original_code:
int euli(double *const Up1, double const*const U, sConst const*const psc,pfLinearOp pfTimeStep, pfBC pfBoundary)
{
    if (strcmp("real","real")==0)
    {
        addfields(psc->pUrhs,U,psc->pdSource,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUrhs,psc->pUk1,psc->sSize,psc->sInvX);
        pfBoundary(psc->pUk1,psc->sSize);
        addfields(psc->pUrhs,psc->pUk1,psc->pdSource,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUrhs,Up1,psc->sSize,psc->sInvY);
        pfBoundary(Up1,psc->sSize);
    }
    else if (strcmp("real","fourier")==0)
    {
        addfields(psc->pUrhs,U,psc->pdSource,psc->dDt,psc->sSize);
        invMat(psc->pUrhs,Up1,psc->sSize,psc->sInvX);
        pfBoundary(Up1,psc->sSize);
    }
    return 0;
}

canonical_original_code:
int euli(double *Up1, double *U, struct sConst *psc, int (*pfTimeStep)(double *, double *, struct sConst *), void (*pfBoundary)(double *, struct _sFieldSize *))
{
    if (strcmp("real","real")==0)
    {
        addfields(psc->pUrhs,U,psc->pdSource,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUrhs,psc->pUk1,psc->sSize,psc->sInvX);
        pfBoundary(psc->pUk1,psc->sSize);
        addfields(psc->pUrhs,psc->pUk1,psc->pdSource,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUrhs,Up1,psc->sSize,psc->sInvY);
        pfBoundary(Up1,psc->sSize);
    }
    else if (strcmp("real","fourier")==0)
    {
        addfields(psc->pUrhs,U,psc->pdSource,psc->dDt,psc->sSize);
        invMat(psc->pUrhs,Up1,psc->sSize,psc->sInvX);
        pfBoundary(Up1,psc->sSize);
    }
    return 0;
}

variable_types:
U
double *

variable_types: int (*)(double *, double *, struct sConst *)

variable_types: void (*)(double *, struct _sFieldSize *)


eulis

original_code:
int eulis(double *const Up1, double const*const U, sConst const*const psc,pfLinearOp pfTimeStep, pfBC pfBoundary)
{
    if (strcmp("real","real")==0)
    {
        addfields(psc->pUrhs,U,psc->pdSource,psc->dDt,psc->sSize);
        sor(Up1,psc->pUrhs,psc->sSorMat,psc->sSize);
        pfBoundary(Up1,psc->sSize);
    }
    else if (strcmp("real","fourier")==0)
    {
        euli(Up1,U,psc,pfTimeStep,pfBoundary);
    }
    return 0;
}

canonical_original_code:
int eulis(double *Up1, double *U, struct sConst *psc, int (*pfTimeStep)(double *, double *, struct sConst *), void (*pfBoundary)(double *, struct _sFieldSize *))
{
    if (strcmp("real","real")==0)
    {
        addfields(psc->pUrhs,U,psc->pdSource,psc->dDt,psc->sSize);
        sor(Up1,psc->pUrhs,psc->sSorMat,psc->sSize);
        pfBoundary(Up1,psc->sSize);
    }
    else if (strcmp("real","fourier")==0)
    {
        euli(Up1,U,psc,pfTimeStep,pfBoundary);
    }
    return 0;
}

variable_types: struct sConst { double dDt; double dEta; long Tmax; long TIO; struct sGeomOp { double dRFactor; double dRmin; double *pdRadius; unsigned long iSize; } *sGeom; struct sLaplacianOp { double *pdCnstGradp; double *pdCnstGradm; double **ppdCnst; double dFactor; unsigned long iSizeX; unsigned long iSizeY; } *sLapTor; struct _sFieldSize { long iSize1; long iSize2; int iSizeC; } *sSize; struct _sFieldDiscret { double dDx1; double dDx2; double dKx1; double dKx2; } *sSteps; double *pdSource; double *pInit; double *pdMKy; double *pUrhs; double *pUtmp; double *pUk1; double *pUk2; double *pUk3; double *pUk4; struct _sInvLap { double *a; double *gam; double *bet; enum H2D_INV_DIRECT { _X=0, _Y=1, _XF=2, _XY=3 } dir; double *z; double *u; double beta; double gamma; } *sInvX; struct _sInvLap *sInvY; struct _sSOR { double *vecA; double *vecB; double *vecC; double *vecD; double *vecE; double rsor; } *sSorMat; enum H2D_INV_DIRECT { _X=0, _Y=1, _XF=2, _XY=3 } eDir; } *

return_type: int

user_defined_types: struct sConst { double dDt; double dEta; long Tmax; long TIO; struct sGeomOp *sGeom; struct sLaplacianOp *sLapTor; struct _sFieldSize *sSize; struct _sFieldDiscret *sSteps; double *pdSource; double *pInit; double *pdMKy; double *pUrhs; double *pUtmp; double *pUk1; double *pUk2; double *pUk3; double *pUk4; struct _sInvLap *sInvX; struct _sInvLap *sInvY; struct _sSOR *sSorMat; enum H2D_INV_DIRECT eDir; }

user_defined_types: struct _sInvLap { double *a; double *gam; double *bet; enum H2D_INV_DIRECT dir; double *z; double *u; double beta; double gamma; }


cranck

original_code:
int cranck(double *const Up1, double const*const U, sConst *const psc,pfLinearOp pfTimeStep, pfBC pfBoundary)
{
    if (strcmp("real","real")==0)
    {
        psc->eDir =_X;
        pfTimeStep(psc->pUrhs,U,psc);
        addfields(psc->pUk1,U,psc->pUrhs,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUk1,psc->pUk2,psc->sSize,psc->sInvY);
        pfBoundary(psc->pUk2,psc->sSize);
        psc->eDir =_Y;
        pfTimeStep(psc->pUrhs,psc->pUk2,psc);
        addfields(psc->pUk1,psc->pUk2,psc->pUrhs,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUk1,Up1,psc->sSize,psc->sInvX);
        pfBoundary(Up1,psc->sSize);
    }
    else if (strcmp("real","fourier")==0)
    {
        psc->eDir =_XF;
        pfTimeStep(psc->pUrhs,U,psc);
        addfields(psc->pUk1,U,psc->pUrhs,0.5*psc->dDt,psc->sSize);
        addfields(psc->pUk1,U,psc->pdSource,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUk1,Up1,psc->sSize,psc->sInvX);
        pfBoundary(Up1,psc->sSize);
    }
    return 0;
}

canonical_original_code:
int cranck(double *Up1, double *U, struct sConst *psc, int (*pfTimeStep)(double *, double *, struct sConst *), void (*pfBoundary)(double *, struct _sFieldSize *))
{
    if (strcmp("real","real")==0)
    {
        psc->eDir =_X;
        pfTimeStep(psc->pUrhs,U,psc);
        addfields(psc->pUk1,U,psc->pUrhs,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUk1,psc->pUk2,psc->sSize,psc->sInvY);
        pfBoundary(psc->pUk2,psc->sSize);
        psc->eDir =_Y;
        pfTimeStep(psc->pUrhs,psc->pUk2,psc);
        addfields(psc->pUk1,psc->pUk2,psc->pUrhs,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUk1,Up1,psc->sSize,psc->sInvX);
        pfBoundary(Up1,psc->sSize);
    }
    else if (strcmp("real","fourier")==0)
    {
        psc->eDir =_XF;
        pfTimeStep(psc->pUrhs,U,psc);
        addfields(psc->pUk1,U,psc->pUrhs,0.5*psc->dDt,psc->sSize);
        addfields(psc->pUk1,U,psc->pdSource,0.5*psc->dDt,psc->sSize);
        invMat(psc->pUk1,Up1,psc->sSize,psc->sInvX);
        pfBoundary(Up1,psc->sSize);
    }
    return 0;
}

user_defined_types: enum H2D_INV_DIRECT { _X=0, _Y=1, _XF=2, _XY=3 }

user_defined_types: struct sGeomOp { double dRFactor; double dRmin; double *pdRadius; unsigned long iSize; }

user_defined_types: struct sLaplacianOp { double *pdCnstGradp; double *pdCnstGradm; double **ppdCnst; double dFactor; unsigned long iSizeX; unsigned long iSizeY; }

user_defined_types: struct _sFieldSize { long iSize1; long iSize2; int iSizeC; }

user_defined_types: struct _sFieldDiscret { double dDx1; double dDx2; double dKx1; double dKx2; }

user_defined_types: struct _sSOR { double *vecA; double *vecB; double *vecC; double *vecD; double *vecE; double rsor; }


mygetFileExt

decompiled_code:
_BOOL8 __fastcall mygetFileExt(const char *a1, __int64 a2, __int64 a3)
{
return sscanf(a1, "%[a-zA-Z0-9_].%[a-zA-Z0-9]", a2, a3) != 2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1, __int64 a2, __int64 a3)
{
return sscanf(a1, "%[a-zA-Z0-9_].%[a-zA-Z0-9]", a2, a3) != 2;
}

original_code:
int mygetFileExt(char const*const filename, char *const name, char *const fileExt)
{
    static const char FCNAME[] = "mygetFileExt";
    int extractval=sscanf(filename,"%[a-zA-Z0-9_].%[a-zA-Z0-9]",name,fileExt);
    if (extractval!=2)
        return 1;
    return 0;
}

canonical_original_code:
int mygetFileExt(char *filename, char *name, char *fileExt)
{
    static char FCNAME[] = "mygetFileExt";
    int extractval = sscanf(filename,"%[a-zA-Z0-9_].%[a-zA-Z0-9]",name,fileExt);
    if (extractval!=2)
        return 1;
    return 0;
}

variable_types:
filename
char *

variable_types:
name
char *

variable_types:
fileExt
char *

variable_types:
FCNAME
char []

variable_types: extractval int


repo: GNOME/gnome-nettool

decompiled_code:
int __fastcall process_icmp(_BYTE *a1, int a2, _QWORD *a3)
{
int result; // eax
__int64 *v4; // rbp
unsigned int v5; // er13
double v7; // r12
unsigned int v8; // ebx
unsigned int v9; // ebp
char *v10; // rax

result = 4 * (*a1 & 0xF);
v4 = (__int64 *)&a1[result];
v5 = a2 - result;
if ( a2 - result <= 7 )
{
fprintf(stderr, "icmplen (%d) < 8", v5);
exit(-3);
}
if ( !*(_BYTE *)v4 )
{
result = *((unsigned __int16 *)v4 + 2);
if ( result == pid )
{
if ( (int)v5 <= 15 )
{
fprintf(stderr, "icmplen (%d) < 16", v5);
exit(-3);
}
tv_sub(a3, v4 + 1);
v7 = (double)(int)*a3 * 1000.0 + (double)(int)a3[1] / 1000.0;
v8 = (unsigned __int8)a1[8];
v9 = *((unsigned __int16 *)v4 + 3);
v10 = inet_ntoa(*(struct in_addr *)(*((_QWORD *)pr + 1) + 4LL));
result = printf("%d bytes from %s: seq=%u, ttl=%d, rtt=%.3f ms\n", v5, v10, v9, v8, v7);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(_BYTE *a1, int a2, _QWORD *a3)
{
int result; // eax
__int64 *v4; // rbp
unsigned int v5; // er13
double v7; // r12
unsigned int v8; // ebx
unsigned int v9; // ebp
char *v10; // rax

result = 4 * (*a1 & 0xF);
v4 = (__int64 *)&a1[result];
v5 = a2 - result;
if ( a2 - result <= 7 )
{
fprintf(stderr, "icmplen (%d) < 8", v5);
exit(-3);
}
if ( !*(_BYTE *)v4 )
{
result = *((unsigned __int16 *)v4 + 2);
if ( result == pid )
{
if ( (int)v5 <= 15 )
{
fprintf(stderr, "icmplen (%d) < 16", v5);
exit(-3);
}
func9(a3, v4 + 1);
v7 = (double)(int)*a3 * 1000.0 + (double)(int)a3[1] / 1000.0;
v8 = (unsigned __int8)a1[8];
v9 = *((unsigned __int16 *)v4 + 3);
v10 = inet_ntoa(*(struct in_addr *)(*((_QWORD *)pr + 1) + 4LL));
result = printf("%d bytes from %s: seq=%u, ttl=%d, rtt=%.3f ms\n", v5, v10, v9, v8, v7);
}
}
return result;
}

original_code:
void
process_icmp (char *ptr, ssize_t len, struct timeval *tvrecv)
{
 int hlen1, icmplen;
 double rtt;
 struct ip *ip;
 struct icmp *icmp;
 struct timeval *tvsend;
 struct sockaddr_in *sin = ((void *)0);
 ip = (struct ip *) ptr;
 hlen1 = ip->ip_hl << 2;
 icmp = (struct icmp *) (ptr + hlen1);
 if ((icmplen = len - hlen1) < 8) {
  fprintf (stderr, "icmplen (%d) < 8", icmplen);
  exit (-3);
 }
 if (icmp->icmp_type == 0) {
  if (icmp->icmp_hun.ih_idseq.icd_id != pid)
   return;
  if (icmplen < 16) {
   fprintf (stderr, "icmplen (%d) < 16", icmplen);
   exit (-3);
  }
  tvsend = (struct timeval *) icmp->icmp_dun.id_data;
  tv_sub (tvrecv, tvsend);
  rtt = tvrecv->tv_sec * 1000.0 + tvrecv->tv_usec / 1000.0;
  sin = (struct sockaddr_in *) pr->sarecv;
  printf ("%d bytes from %s: seq=%u, ttl=%d, rtt=%.3f ms\n",
   icmplen, inet_ntoa (sin->sin_addr),
   icmp->icmp_hun.ih_idseq.icd_seq, ip->ip_ttl, rtt);
 }
}

canonical_original_code:
void process_icmp(char *ptr, long len, struct timeval *tvrecv)
{
 int hlen1; int icmplen;
 double rtt;
 struct ip *ip;
 struct icmp *icmp;
 struct timeval *tvsend;
 struct sockaddr_in *sin = ((void *)0);
 ip = (struct ip *) ptr;
 hlen1 = ip->ip_hl << 2;
 icmp = (struct icmp *) (ptr + hlen1);
 if ((icmplen = len - hlen1) < 8) {
  fprintf (stderr, "icmplen (%d) < 8", icmplen);
  exit (-3);
 }
 if (icmp->icmp_type == 0) {
  if (icmp->icmp_hun.ih_idseq.icd_id != pid)
   return;
  if (icmplen < 16) {
   fprintf (stderr, "icmplen (%d) < 16", icmplen);
   exit (-3);
  }
  tvsend = (struct timeval *) icmp->icmp_dun.id_data;
  tv_sub (tvrecv, tvsend);
  rtt = tvrecv->tv_sec * 1000.0 + tvrecv->tv_usec / 1000.0;
  sin = (struct sockaddr_in *) pr->sarecv;
  printf ("%d bytes from %s: seq=%u, ttl=%d, rtt=%.3f ms\n",
   icmplen, inet_ntoa (sin->sin_addr),
   icmp->icmp_hun.ih_idseq.icd_seq, ip->ip_ttl, rtt);
 }
}

variable_types:
ptr
char *

variable_types: len long

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

variable_types: icmplen int

variable_types: rtt double

variable_types: struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr { unsigned int s_addr; } ip_src; } *

variable_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr { unsigned int s_addr; } ih_gwaddr; struct ih_idseq { unsigned short icd_id; unsigned short icd_seq; } ih_idseq; unsigned int ih_void; struct ih_pmtu { unsigned short ipm_void; unsigned short ipm_nextmtu; } ih_pmtu; struct ih_rtradv { unsigned char irt_num_addrs; unsigned char irt_wpa; unsigned short irt_lifetime; } ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; } idi_ip; } id_ip; struct icmp_ra_addr { unsigned int ira_addr; unsigned int ira_preference; } id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; } *

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

return_type: void

user_defined_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr ih_gwaddr; struct ih_idseq ih_idseq; unsigned int ih_void; struct ih_pmtu ih_pmtu; struct ih_rtradv ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip idi_ip; } id_ip; struct icmp_ra_addr id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; }

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


original_code:
unsigned short
in_cksum (unsigned short *addr, int len)
{
 int nleft = len;
 int sum = 0;
 unsigned short *w = addr;
 unsigned short answer = 0;
 while (nleft > 1) {
  sum += *w++;
  nleft -= 2;
 }
 if (nleft == 1) {
  *(unsigned char *) (&answer) = *(unsigned char *) w;
  sum += answer;
 }
 sum = (sum >> 16) + (sum & 0xffff);
 sum += (sum >> 16);
 answer = ~sum;
 return (answer);
}

canonical_original_code:
unsigned short in_cksum(unsigned short *addr, int len)
{
 int nleft = len;
 int sum = 0;
 unsigned short *w = addr;
 unsigned short answer = 0;
 while (nleft > 1) {
  sum += *w++;
  nleft -= 2;
 }
 if (nleft == 1) {
  *(unsigned char *) (&answer) = *(unsigned char *) w;
  sum += answer;
 }
 sum = (sum >> 16) + (sum & 0xffff);
 sum += (sum >> 16);
 answer = ~sum;
 return (answer);
}

variable_types:
addr
unsigned short *

variable_types: len int

variable_types: nleft int

variable_types: sum int

variable_types:
w
unsigned short *

variable_types:
answer
unsigned short

return_type: unsigned short


decompiled_code:
int send_icmp()
{
__int16 v0; // ax
int v1; // ebx
int result; // eax
unsigned int v3; // er12
unsigned int v4; // ebp
char *v5; // rax

sendbuf = 8;
byte_404201 = 0;
word_404204 = pid;
v0 = nsent++;
word_404206 = v0;
gettimeofday(&tv, 0LL);
v1 = datalen + 8;
word_404202 = 0;
word_404202 = in_cksum(&sendbuf, datalen + 8);
result = sendto(sockfd, &sendbuf, v1, 0, *(const struct sockaddr **)pr, *((_DWORD *)pr + 4));
if ( verbose )
{
v3 = (unsigned __int16)word_404204;
v4 = (unsigned __int16)word_404206;
v5 = inet_ntoa(*(struct in_addr *)(*(_QWORD *)pr + 4LL));
result = printf("%d bytes sent to %s: seq=%u, id=%d\n", (unsigned int)v1, v5, v4, v3);
}
return result;
}

canonical_decompiled_code:
int func12()
{
__int16 v0; // ax
int v1; // ebx
int result; // eax
unsigned int v3; // er12
unsigned int v4; // ebp
char *v5; // rax

sendbuf = 8;
byte_404201 = 0;
word_404204 = pid;
v0 = nsent++;
word_404206 = v0;
gettimeofday(&tv, 0LL);
v1 = datalen + 8;
word_404202 = 0;
word_404202 = func11(&sendbuf, datalen + 8);
result = sendto(sockfd, &sendbuf, v1, 0, *(const struct sockaddr **)pr, *((_DWORD *)pr + 4));
if ( verbose )
{
v3 = (unsigned __int16)word_404204;
v4 = (unsigned __int16)word_404206;
v5 = inet_ntoa(*(struct in_addr *)(*(_QWORD *)pr + 4LL));
result = printf("%d bytes sent to %s: seq=%u, id=%d\n", (unsigned int)v1, v5, v4, v3);
}
return result;
}

original_code:
void
send_icmp (void)
{
 int len;
 struct icmp *icmp;
 struct sockaddr_in *sin = ((void *)0);
 icmp = (struct icmp *) sendbuf;
 icmp->icmp_type = 8;
 icmp->icmp_code = 0;
 icmp->icmp_hun.ih_idseq.icd_id = pid;
 icmp->icmp_hun.ih_idseq.icd_seq = nsent++;
 gettimeofday ((struct timeval *) icmp->icmp_dun.id_data, ((void *)0));
 len = 8 + datalen;
 icmp->icmp_cksum = 0;
 icmp->icmp_cksum = in_cksum ((u_short *) icmp, len);
 sendto (sockfd, sendbuf, len, 0, pr->sasend, pr->salen);
 sin = (struct sockaddr_in *) pr->sasend;
 if (verbose) {
  printf ("%d bytes sent to %s: seq=%u, id=%d\n",
   len, inet_ntoa (sin->sin_addr),
   icmp->icmp_hun.ih_idseq.icd_seq, icmp->icmp_hun.ih_idseq.icd_id);
 }
}

canonical_original_code:
void send_icmp()
{
 int len;
 struct icmp *icmp;
 struct sockaddr_in *sin = ((void *)0);
 icmp = (struct icmp *) sendbuf;
 icmp->icmp_type = 8;
 icmp->icmp_code = 0;
 icmp->icmp_hun.ih_idseq.icd_id = pid;
 icmp->icmp_hun.ih_idseq.icd_seq = nsent++;
 gettimeofday ((struct timeval *) icmp->icmp_dun.id_data, ((void *)0));
 len = 8 + datalen;
 icmp->icmp_cksum = 0;
 icmp->icmp_cksum = in_cksum ((unsigned short *) icmp, len);
 sendto (sockfd, sendbuf, len, 0, pr->sasend, pr->salen);
 sin = (struct sockaddr_in *) pr->sasend;
 if (verbose) {
  printf ("%d bytes sent to %s: seq=%u, id=%d\n",
   len, inet_ntoa (sin->sin_addr),
   icmp->icmp_hun.ih_idseq.icd_seq, icmp->icmp_hun.ih_idseq.icd_id);
 }
}

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

user_defined_types: struct ih_idseq { unsigned short icd_id; unsigned short icd_seq; }

user_defined_types: struct ih_pmtu { unsigned short ipm_void; unsigned short ipm_nextmtu; }

user_defined_types: struct ih_rtradv { unsigned char irt_num_addrs; unsigned char irt_wpa; unsigned short irt_lifetime; }

user_defined_types: struct icmp_ra_addr { unsigned int ira_addr; unsigned int ira_preference; }

user_defined_types: struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; }


decompiled_code:
void sig_alrm()
{
send_icmp();
alarm(1u);
}

canonical_decompiled_code:
void func13()
{
func12();
alarm(1u);
}

original_code:
void
sig_alrm (int signo)
{
 send_icmp ();
 alarm (1);
 return;
}

canonical_original_code:
void sig_alrm(int signo)
{
 send_icmp ();
 alarm (1);
 return;
}

variable_types: signo int


readloop

decompiled_code:
unsigned int __fastcall readloop(int a1)
{
__uid_t v1; // eax
int v2; // ebp
ssize_t v3; // rax
int v4; // ebx
struct timeval v6; // [rsp+0h] [rbp-618h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-5FCh] BYREF
char buf[1500]; // [rsp+20h] [rbp-5F8h] BYREF
int optval[7]; // [rsp+5FCh] [rbp-1Ch] BYREF

sockfd = socket(**(unsigned __int16 **)pr, 3, *((_DWORD *)pr + 5));
v1 = getuid();
setuid(v1);
optval[0] = 61440;
setsockopt(sockfd, 1, 8, optval, 4u);
sig_alrm();
v2 = 0;
do
{
while ( 1 )
{
addr_len = *((_DWORD *)pr + 4);
v3 = recvfrom(sockfd, buf, 0x5DCuLL, 0, *((struct sockaddr **)pr + 1), &addr_len);
v4 = v3;
if ( v3 >= 0 )
break;
if ( *__errno_location() != 4 )
{
perror("recvfrom error");
break;
}
}
gettimeofday(&v6, 0LL);
process_icmp(buf, v4, &v6);
}
while ( a1 <= 0 || a1 != ++v2 );
return alarm(0);
}

canonical_decompiled_code:
unsigned int __fastcall func14(int a1)
{
__uid_t v1; // eax
int v2; // ebp
ssize_t v3; // rax
int v4; // ebx
struct timeval v6; // [rsp+0h] [rbp-618h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-5FCh] BYREF
char buf[1500]; // [rsp+20h] [rbp-5F8h] BYREF
int optval[7]; // [rsp+5FCh] [rbp-1Ch] BYREF

sockfd = socket(**(unsigned __int16 **)pr, 3, *((_DWORD *)pr + 5));
v1 = getuid();
setuid(v1);
optval[0] = 61440;
setsockopt(sockfd, 1, 8, optval, 4u);
func13();
v2 = 0;
do
{
while ( 1 )
{
addr_len = *((_DWORD *)pr + 4);
v3 = recvfrom(sockfd, buf, 0x5DCuLL, 0, *((struct sockaddr **)pr + 1), &addr_len);
v4 = v3;
if ( v3 >= 0 )
break;
if ( *__errno_location() != 4 )
{
perror("recvfrom error");
break;
}
}
gettimeofday(&v6, 0LL);
func10(buf, v4, &v6);
}
while ( a1 <= 0 || a1 != ++v2 );
return alarm(0);
}

original_code:
void
readloop (int count)
{
 int size;
 char recvbuf[1500];
 socklen_t len;
 ssize_t n;
 struct timeval tval;
 int i = 0;
 sockfd = socket (pr->sasend->sa_family, SOCK_RAW, pr->icmpproto);
 setuid (getuid ());
 size = 60 * 1024;
 setsockopt (sockfd, 1, 8, &size, sizeof (size));
 sig_alrm (14);
 for (;;) {
  len = pr->salen;
  n = recvfrom (sockfd, recvbuf, sizeof (recvbuf), 0,
         pr->sarecv, &len);
  if (n < 0) {
   if ((*__errno_location ()) == 4) {
    continue;
    i++;
   } else {
    perror ("recvfrom error");
   }
  }
  gettimeofday (&tval, ((void *)0));
  process_icmp (recvbuf, n, &tval);
  if (count > 0) {
   i++;
   if (i == count) {
    alarm (0);
    break;
   }
  }
 }
}

canonical_original_code:
void readloop(int count)
{
 int size;
 char recvbuf[1500];
 unsigned int len;
 long n;
 struct timeval tval;
 int i = 0;
 sockfd = socket (pr->sasend->sa_family, SOCK_RAW, pr->icmpproto);
 setuid (getuid ());
 size = 60 * 1024;
 setsockopt (sockfd, 1, 8, &size, sizeof (size));
 sig_alrm (14);
 for (;;) {
  len = pr->salen;
  n = recvfrom (sockfd, recvbuf, sizeof (recvbuf), 0,
         pr->sarecv, &len);
  if (n < 0) {
   if ((*__errno_location ()) == 4) {
    continue;
    i++;
   } else {
    perror ("recvfrom error");
   }
  }
  gettimeofday (&tval, ((void *)0));
  process_icmp (recvbuf, n, &tval);
  if (count > 0) {
   i++;
   if (i == count) {
    alarm (0);
    break;
   }
  }
 }
}

variable_types: count int

variable_types: size int

variable_types:
recvbuf
char [1500]

variable_types:
len
unsigned int

variable_types: n long

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

variable_types: i int


decompiled_code:
void __fastcall __noreturn do_ping(char *name, int a2)
{
struct hostent *v2; // rax
struct hostent *v3; // rbx
unsigned int v4; // er12
char *v5; // rax
_QWORD *v6; // rbx
__int16 v7[2]; // [rsp+0h] [rbp-28h] BYREF
struct in_addr dest; // [rsp+4h] [rbp-24h] BYREF

pid = getpid();
signal(14, (__sighandler_t)sig_alrm);
v2 = gethostbyname(name);
if ( v2 )
{
v3 = v2;
v7[0] = 2;
dest.s_addr = _bswap_32(0);
v7[1] = _bswap_16(1);
memcpy(&dest, *(const void **)v3->h_addr_list, v3->h_length);
v4 = datalen;
v5 = inet_ntoa(dest);
printf("PING %s (%s): %d data bytes\n", v3->h_name, v5, v4);
v6 = malloc(0x18uLL);
pr = v6;
*v6 = v7;
v6[1] = calloc(1uLL, 0x10uLL);
*((_DWORD *)v6 + 4) = 16;
*((_DWORD *)v6 + 5) = 1;
readloop(a2);
free(pr);
exit(0);
}
perror("Host unknown");
exit(3);
}

canonical_decompiled_code:
void __fastcall __noreturn func15(char *name, int a2)
{
struct hostent *v2; // rax
struct hostent *v3; // rbx
unsigned int v4; // er12
char *v5; // rax
_QWORD *v6; // rbx
__int16 v7[2]; // [rsp+0h] [rbp-28h] BYREF
struct in_addr dest; // [rsp+4h] [rbp-24h] BYREF

pid = getpid();
signal(14, (__sighandler_t)sig_alrm);
v2 = gethostbyname(name);
if ( v2 )
{
v3 = v2;
v7[0] = 2;
dest.s_addr = func7(0);
v7[1] = func8(1);
memcpy(&dest, *(const void **)v3->h_addr_list, v3->h_length);
v4 = datalen;
v5 = inet_ntoa(dest);
printf("PING %s (%s): %d data bytes\n", v3->h_name, v5, v4);
v6 = malloc(0x18uLL);
pr = v6;
*v6 = v7;
v6[1] = calloc(1uLL, 0x10uLL);
*((_DWORD *)v6 + 4) = 16;
*((_DWORD *)v6 + 5) = 1;
func14(a2);
free(pr);
exit(0);
}
perror("Host unknown");
exit(3);
}

original_code:
void
do_ping (const char *host, int count)
{
 struct hostent *hp;
 struct sockaddr_in addr;
 pid = getpid ();
 signal (14, sig_alrm);
 if ((hp = gethostbyname (host)) == ((void *)0)) {
  perror ("Host unknown");
  exit (3);
 }
 addr.sin_family = 2;
 addr.sin_addr.s_addr = htonl (((in_addr_t) 0x00000000));
 addr.sin_port = htons (1);
 memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
 printf ("PING %s (%s): %d data bytes\n", hp->h_name,
  inet_ntoa (addr.sin_addr), datalen);
 pr = malloc (sizeof (struct proto));
 pr->sasend = (struct sockaddr *) &(addr);
 pr->sarecv = calloc (1, sizeof (addr));
 pr->salen = sizeof (addr);
 pr->icmpproto = IPPROTO_ICMP;
 readloop (count);
 free (pr);
 exit (0);
}

canonical_original_code:
void do_ping(char *host, int count)
{
 struct hostent *hp;
 struct sockaddr_in addr;
 pid = getpid ();
 signal (14, sig_alrm);
 if ((hp = gethostbyname (host)) == ((void *)0)) {
  perror ("Host unknown");
  exit (3);
 }
 addr.sin_family = 2;
 addr.sin_addr.s_addr = htonl (((unsigned int) 0x00000000));
 addr.sin_port = htons (1);
 memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
 printf ("PING %s (%s): %d data bytes\n", hp->h_name,
  inet_ntoa (addr.sin_addr), datalen);
 pr = malloc (sizeof (struct proto));
 pr->sasend = (struct sockaddr *) &(addr);
 pr->sarecv = calloc (1, sizeof (addr));
 pr->salen = sizeof (addr);
 pr->icmpproto = IPPROTO_ICMP;
 readloop (count);
 free (pr);
 exit (0);
}

variable_types:
host
char *

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

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

user_defined_types: struct proto { struct sockaddr *sasend; struct sockaddr *sarecv; unsigned int salen; int icmpproto; }

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


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = 0;
while ( 1 )
{
longind[0] = 0;
opterr = 0;
v4 = getopt_long(argc, (char *const *)argv, "c:vh", &long_options_0, longind);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'h':
printf("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
puts(" -h, --help\t\tPrint this help.");
puts(" -c, --count=NUMBER\tSet limit of packets to send");
puts(" -v, --verbose\tShow the packets sent");
break;
case 'v':
verbose = 1;
break;
case 'c':
v3 = atoi(optarg);
if ( v3 <= 0 )
{
printf("%s: Bad number of packets to transmit.\n", "gnome-ping-helper");
exit(-1);
}
break;
default:
printf("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
puts("Try 'gnome-ping-helper --help' for more information");
exit(-1);
}
}
if ( optind < argc )
{
if ( argc - optind != 1 )
{
printf("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
puts("Try 'gnome-ping-helper --help' for more information");
exit(-1);
}
do_ping((char *)argv[optind], v3);
}
printf("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
puts("Try 'gnome-ping-helper --help' for more information");
exit(-1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = 0;
while ( 1 )
{
longind[0] = 0;
opterr = 0;
v4 = getopt_long(argc, (char *const *)argv, "c:vh", &long_options_0, longind);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'h':
printf("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
puts(" -h, --help\t\tPrint this help.");
puts(" -c, --count=NUMBER\tSet limit of packets to send");
puts(" -v, --verbose\tShow the packets sent");
break;
case 'v':
verbose = 1;
break;
case 'c':
v3 = atoi(optarg);
if ( v3 <= 0 )
{
printf("%s: Bad number of packets to transmit.\n", "gnome-ping-helper");
exit(-1);
}
break;
default:
printf("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
puts("Try 'gnome-ping-helper --help' for more information");
exit(-1);
}
}
if ( optind < argc )
{
if ( argc - optind != 1 )
{
printf("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
puts("Try 'gnome-ping-helper --help' for more information");
exit(-1);
}
func15((char *)argv[optind], v3);
}
printf("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
puts("Try 'gnome-ping-helper --help' for more information");
exit(-1);
}

original_code:
int
main (int argc, char **argv)
{
 int c;
 int count = 0;
 char *host;
 for (;;) {
  int option_index = 0;
  static struct option long_options[] = {
   {"count", 1, 0, 'c'},
   {"verbose", 0, 0, 'v'},
   {"help", 0, 0, 'h'}
  };
  opterr = 0;
  c = getopt_long (argc, argv, "c:vh",
     long_options, &option_index);
  if (c == -1)
   break;
  switch (c) {
  case 'v':
   verbose = 1;
   break;
  case 'c':
   count = atoi (optarg);
   if (count <= 0) {
    printf ("%s: Bad number of packets to transmit.\n", "gnome-ping-helper");
    exit (-1);
   }
   break;
  case 'h':
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("  -h,  --help\t\tPrint this help.\n");
   printf ("  -c,  --count=NUMBER\tSet limit of packets to send\n");
   printf ("  -v,  --verbose\tShow the packets sent\n");
   break;
  default:
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("Try 'gnome-ping-helper --help' for more information\n");
   exit (-1);
  }
 }
 if (optind < argc) {
  if (argc - optind != 1) {
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("Try 'gnome-ping-helper --help' for more information\n");
   exit (-1);
  } else {
   host = argv[optind];
   do_ping (host, count);
  }
 } else {
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("Try 'gnome-ping-helper --help' for more information\n");
   exit (-1);
 }
 return (0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 int c;
 int count = 0;
 char *host;
 for (;;) {
  int option_index = 0;
  static struct option long_options[] = {
   {"count", 1, 0, 'c'},
   {"verbose", 0, 0, 'v'},
   {"help", 0, 0, 'h'}
  };
  opterr = 0;
  c = getopt_long (argc, argv, "c:vh",
     long_options, &option_index);
  if (c == -1)
   break;
  switch (c) {
  case 'v':
   verbose = 1;
   break;
  case 'c':
   count = atoi (optarg);
   if (count <= 0) {
    printf ("%s: Bad number of packets to transmit.\n", "gnome-ping-helper");
    exit (-1);
   }
   break;
  case 'h':
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("  -h,  --help\t\tPrint this help.\n");
   printf ("  -c,  --count=NUMBER\tSet limit of packets to send\n");
   printf ("  -v,  --verbose\tShow the packets sent\n");
   break;
  default:
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("Try 'gnome-ping-helper --help' for more information\n");
   exit (-1);
  }
 }
 if (optind < argc) {
  if (argc - optind != 1) {
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("Try 'gnome-ping-helper --help' for more information\n");
   exit (-1);
  } else {
   host = argv[optind];
   do_ping (host, count);
  }
 } else {
   printf ("Usage: %s [-c count] [-v] host\n\n", "gnome-ping-helper");
   printf ("Try 'gnome-ping-helper --help' for more information\n");
   exit (-1);
 }
 return (0);
}

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


repo: GNU-Pony/libpassphrase

decompiled_code:
int __fastcall passphrase_disable_echo1(int fd)
{
struct termios vars0; // [rsp+0h] [rbp+0h] BYREF

tcgetattr(fd, &vars0);
*(__m128i *)&saved_stty.c_iflag = _mm_loadu_si128((const __m128i *)&vars0);
*(__m128i *)&saved_stty.c_line = _mm_loadu_si128((const __m128i *)&vars0.c_line);
*(__m128i *)&saved_stty.c_cc[15] = _mm_loadu_si128((const __m128i *)&vars0.c_cc[15]);
*(_QWORD *)&saved_stty.c_cc[31] = *(_QWORD *)&vars0.c_cc[31];
saved_stty.c_ospeed = vars0.c_ospeed;
vars0.c_lflag &= 0xFFFFFFF5;
return tcsetattr(fd, 2, &vars0);
}

canonical_decompiled_code:
int __fastcall func0(int fd)
{
struct termios vars0; // [rsp+0h] [rbp+0h] BYREF

tcgetattr(fd, &vars0);
*(__m128i *)&saved_stty.c_iflag = _mm_loadu_si128((const __m128i *)&vars0);
*(__m128i *)&saved_stty.c_line = _mm_loadu_si128((const __m128i *)&vars0.c_line);
*(__m128i *)&saved_stty.c_cc[15] = _mm_loadu_si128((const __m128i *)&vars0.c_cc[15]);
*(_QWORD *)&saved_stty.c_cc[31] = *(_QWORD *)&vars0.c_cc[31];
saved_stty.c_ospeed = vars0.c_ospeed;
vars0.c_lflag &= 0xFFFFFFF5;
return tcsetattr(fd, 2, &vars0);
}

original_code:
void passphrase_disable_echo1(int fdin)
{
  struct termios stty;
  tcgetattr(fdin, &stty);
  saved_stty = stty;
  stty.c_lflag &= (tcflag_t)~0000010;
  stty.c_lflag &= (tcflag_t)~0000002;
  tcsetattr(fdin, 2, &stty);
}

canonical_original_code:
void passphrase_disable_echo1(int fdin)
{
  struct termios stty;
  tcgetattr(fdin, &stty);
  saved_stty = stty;
  stty.c_lflag &= (unsigned int)~0000010;
  stty.c_lflag &= (unsigned int)~0000002;
  tcsetattr(fdin, 2, &stty);
}

variable_types: fdin int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
int passphrase_disable_echo()
{
return passphrase_disable_echo1(0);
}

canonical_decompiled_code:
int func1()
{
return func0(0);
}

original_code:
void passphrase_disable_echo(void)
{
  passphrase_disable_echo1(0);
}

canonical_original_code:
void passphrase_disable_echo()
{
  passphrase_disable_echo1(0);
}


decompiled_code:
int __fastcall passphrase_reenable_echo1(int a1)
{
return tcsetattr(a1, 2, &saved_stty);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
return tcsetattr(a1, 2, &saved_stty);
}

original_code:
void passphrase_reenable_echo1(int fdin)
{
  tcsetattr(fdin, 2, &saved_stty);
}


decompiled_code:
int passphrase_reenable_echo()
{
return passphrase_reenable_echo1(0);
}

canonical_decompiled_code:
int func3()
{
return func2(0);
}

original_code:
void passphrase_reenable_echo(void)
{
  passphrase_reenable_echo1(0);
}

canonical_original_code:
void passphrase_reenable_echo()
{
  passphrase_reenable_echo1(0);
}


fdgetc

decompiled_code:
__int64 __fastcall fdgetc(int a1)
{
__int64 result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( read(a1, buf, 1uLL) <= 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned __int8)buf[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( read(a1, buf, 1uLL) <= 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned __int8)buf[0];
return result;
}

original_code:
static int fdgetc(int fd)
{
  unsigned char c;
  if (read(fd, &c, sizeof(c)) <= 0)
    return -1;
  return (int)c;
}

variable_types: fd int

variable_types:
c
unsigned char


original_code:
static void passcheck_start(struct passcheck_state* state, int flags)
{
  const char* command;
  int pipe_rw[2] = { -1, -1 };
  int exec_rw[2] = { -1, -1 };
  pid_t pid;
  ssize_t n;
  int i = 0;
  state->pid = -1;
  state->flags = (flags & 1) ? (flags ^ 1) : 0;
  if (state->flags == 0)
    return;
  if (state->flags & 4)
    state->flags &= ~2;
  command = getenv("LIBPASSPHRASE_METER");
  if (!command || !*command)
    command = "passcheck";
  state->label = getenv("LIBPASSPHRASE_STRENGTH_LABEL");
  if (!(state->label) || !*(state->label))
    state->label = "Strength:";
  do { if (pipe(state->pipe_rw)) { state->pipe_rw[0] = state->pipe_rw[1] = -1; goto fail; } } while (0);
  do { if (pipe(pipe_rw)) { pipe_rw[0] = pipe_rw[1] = -1; goto fail; } } while (0);
  do { if (pipe(exec_rw)) { exec_rw[0] = exec_rw[1] = -1; goto fail; } } while (0);
  if (fcntl(exec_rw[1], 2, 1) == -1)
    goto fail;
  pid = fork();
  if (pid == -1)
    {
      state->flags = 0;
      goto fail;
    }
  close(exec_rw[!!pid]), exec_rw[!!pid] = -1;
  close(state->pipe_rw[!!pid]), state->pipe_rw[!!pid] = -1;
  close(pipe_rw[!pid]), pipe_rw[!pid] = -1;
  state->pipe_rw[!!pid] = pipe_rw[!!pid], pipe_rw[!!pid] = -1;
  if (pid == 0)
    {
      gid_t gid = getgid(), egid = getegid();
      uid_t uid = getuid(), euid = geteuid();
      int fd;
      if ((state->pipe_rw[0] != 0) && (state->pipe_rw[1] == 0))
 {
   fd = dup(state->pipe_rw[1]);
   if (fd == -1)
     goto child_fail;
   state->pipe_rw[1] = fd;
 }
      for (i = 0; i <= 1; i++)
 if (state->pipe_rw[i] != i)
   {
     close(i);
     fd = dup2(state->pipe_rw[i], i);
     if (fd == -1)
       goto child_fail;
     close(state->pipe_rw[i]);
     state->pipe_rw[i] = fd;
   }
      close(2);
      if (egid != gid)
 if (setregid(gid, gid) && gid)
   goto child_fail;
      if (euid != uid)
 if (setreuid(uid, uid) && uid)
   goto child_fail;
      execlp(command, command, "-r", ((void *)0));
    child_fail:
      n = write(exec_rw[1], &i, sizeof(i));
      _exit(!!n);
    }
 rewait:
  n = read(exec_rw[0], &i, sizeof(i));
  if ((n < 0) && ((*__errno_location ()) == 4))
    goto rewait;
  if (n)
    {
    rereap:
      if ((waitpid(pid, &i, 0) == -1) && ((*__errno_location ()) == 4))
 goto rereap;
      goto fail;
    }
  if (state->flags & 2)
    {
      struct termios stty;
      struct termios saved_stty;
      tcgetattr(2, &stty);
      saved_stty = stty;
      stty.c_oflag &= (tcflag_t)~0000004;
      tcsetattr(2, 2, &stty);
      fprintf(stderr, "\n\033[A");
      fflush(stderr);
      tcsetattr(2, 2, &saved_stty);
    }
  close(exec_rw[0]);
  state->pid = pid;
  return;
 fail:
  if (state->pipe_rw[0] >= 0) close(state->pipe_rw[0]);
  if (state->pipe_rw[1] >= 0) close(state->pipe_rw[1]);
  if (pipe_rw[0] >= 0) close(pipe_rw[0]);
  if (pipe_rw[1] >= 0) close(pipe_rw[1]);
  if (exec_rw[0] >= 0) close(exec_rw[0]);
  if (exec_rw[1] >= 0) close(exec_rw[1]);
  state->pid = -1;
  state->flags = 0;
}

canonical_original_code:
static void passcheck_start(struct passcheck_state *state, int flags)
{
  char *command;
  int pipe_rw[2] = { -1, -1 };
  int exec_rw[2] = { -1, -1 };
  int pid;
  long n;
  int i = 0;
  state->pid = -1;
  state->flags = (flags & 1) ? (flags ^ 1) : 0;
  if (state->flags == 0)
    return;
  if (state->flags & 4)
    state->flags &= ~2;
  command = getenv("LIBPASSPHRASE_METER");
  if (!command || !*command)
    command = "passcheck";
  state->label = getenv("LIBPASSPHRASE_STRENGTH_LABEL");
  if (!(state->label) || !*(state->label))
    state->label = "Strength:";
  do { if (pipe(state->pipe_rw)) { state->pipe_rw[0] = state->pipe_rw[1] = -1; goto fail; } } while (0);
  do { if (pipe(pipe_rw)) { pipe_rw[0] = pipe_rw[1] = -1; goto fail; } } while (0);
  do { if (pipe(exec_rw)) { exec_rw[0] = exec_rw[1] = -1; goto fail; } } while (0);
  if (fcntl(exec_rw[1], 2, 1) == -1)
    goto fail;
  pid = fork();
  if (pid == -1)
    {
      state->flags = 0;
      goto fail;
    }
  close(exec_rw[!!pid]), exec_rw[!!pid] = -1;
  close(state->pipe_rw[!!pid]), state->pipe_rw[!!pid] = -1;
  close(pipe_rw[!pid]), pipe_rw[!pid] = -1;
  state->pipe_rw[!!pid] = pipe_rw[!!pid], pipe_rw[!!pid] = -1;
  if (pid == 0)
    {
      unsigned int gid = getgid(); unsigned int egid = getegid();
      unsigned int uid = getuid(); unsigned int euid = geteuid();
      int fd;
      if ((state->pipe_rw[0] != 0) && (state->pipe_rw[1] == 0))
 {
   fd = dup(state->pipe_rw[1]);
   if (fd == -1)
     goto child_fail;
   state->pipe_rw[1] = fd;
 }
      for (i = 0; i <= 1; i++)
 if (state->pipe_rw[i] != i)
   {
     close(i);
     fd = dup2(state->pipe_rw[i], i);
     if (fd == -1)
       goto child_fail;
     close(state->pipe_rw[i]);
     state->pipe_rw[i] = fd;
   }
      close(2);
      if (egid != gid)
 if (setregid(gid, gid) && gid)
   goto child_fail;
      if (euid != uid)
 if (setreuid(uid, uid) && uid)
   goto child_fail;
      execlp(command, command, "-r", ((void *)0));
    child_fail:
      n = write(exec_rw[1], &i, sizeof(i));
      _exit(!!n);
    }
 rewait:
  n = read(exec_rw[0], &i, sizeof(i));
  if ((n < 0) && ((*__errno_location ()) == 4))
    goto rewait;
  if (n)
    {
    rereap:
      if ((waitpid(pid, &i, 0) == -1) && ((*__errno_location ()) == 4))
 goto rereap;
      goto fail;
    }
  if (state->flags & 2)
    {
      struct termios stty;
      struct termios saved_stty;
      tcgetattr(2, &stty);
      saved_stty = stty;
      stty.c_oflag &= (unsigned int)~0000004;
      tcsetattr(2, 2, &stty);
      fprintf(stderr, "\n\033[A");
      fflush(stderr);
      tcsetattr(2, 2, &saved_stty);
    }
  close(exec_rw[0]);
  state->pid = pid;
  return;
 fail:
  if (state->pipe_rw[0] >= 0) close(state->pipe_rw[0]);
  if (state->pipe_rw[1] >= 0) close(state->pipe_rw[1]);
  if (pipe_rw[0] >= 0) close(pipe_rw[0]);
  if (pipe_rw[1] >= 0) close(pipe_rw[1]);
  if (exec_rw[0] >= 0) close(exec_rw[0]);
  if (exec_rw[1] >= 0) close(exec_rw[1]);
  state->pid = -1;
  state->flags = 0;
}

variable_types: struct passcheck_state { char *label; int pipe_rw[2]; int pid; int flags; } *

variable_types: flags int

variable_types:
command
char *

variable_types: pid int

variable_types:
gid
unsigned int

variable_types:
egid
unsigned int

variable_types:
uid
unsigned int

variable_types:
euid
unsigned int

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
void __fastcall passcheck_stop(__int64 a1)
{
int stat_loc[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( *(_DWORD *)(a1 + 20) )
{
close(*(_DWORD *)(a1 + 8));
close(*(_DWORD *)(a1 + 12));
free(strength);
strength = 0LL;
strength_size = 0LL;
while ( waitpid(*(_DWORD *)(a1 + 16), stat_loc, 0) == -1 && *_errno_location() == 4 )
;
if ( (*(_BYTE *)(a1 + 20) & 2) != 0 )
fwrite("\x1B[s\x1B[E\x1B[0K\x1B[u", 1uLL, 0xDuLL, stderr);
else
fwrite("\x1B[B\x1B[0K\x1B[A", 1uLL, 0xAuLL, stderr);
fflush(stderr);
*(_DWORD *)(a1 + 20) = 0;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
int stat_loc[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( *(_DWORD *)(a1 + 20) )
{
close(*(_DWORD *)(a1 + 8));
close(*(_DWORD *)(a1 + 12));
free(strength);
strength = 0LL;
strength_size = 0LL;
while ( waitpid(*(_DWORD *)(a1 + 16), stat_loc, 0) == -1 && *_errno_location() == 4 )
;
if ( (*(_BYTE *)(a1 + 20) & 2) != 0 )
fwrite("\x1B[s\x1B[E\x1B[0K\x1B[u", 1uLL, 0xDuLL, stderr);
else
fwrite("\x1B[B\x1B[0K\x1B[A", 1uLL, 0xAuLL, stderr);
fflush(stderr);
*(_DWORD *)(a1 + 20) = 0;
}
}

original_code:
static void passcheck_stop(struct passcheck_state* state)
{
  int _status;
  if (state->flags == 0)
    return;
  close(state->pipe_rw[0]);
  close(state->pipe_rw[1]);
  free(strength), strength = ((void *)0);
  strength_size = 0;
rereap:
  if ((waitpid(state->pid, &_status, 0) == -1) && ((*__errno_location ()) == 4))
    goto rereap;
  if (state->flags & 2)
    fprintf(stderr, "\033[s\033[E\033[0K\033[u");
  else
    fprintf(stderr, "\033[B\033[0K\033[A");
  fflush(stderr);
  state->flags = 0;
}

canonical_original_code:
static void passcheck_stop(struct passcheck_state *state)
{
  int _status;
  if (state->flags == 0)
    return;
  close(state->pipe_rw[0]);
  close(state->pipe_rw[1]);
  free(strength), strength = ((void *)0);
  strength_size = 0;
rereap:
  if ((waitpid(state->pid, &_status, 0) == -1) && ((*__errno_location ()) == 4))
    goto rereap;
  if (state->flags & 2)
    fprintf(stderr, "\033[s\033[E\033[0K\033[u");
  else
    fprintf(stderr, "\033[B\033[0K\033[A");
  fflush(stderr);
  state->flags = 0;
}

user_defined_types: struct passcheck_state { char *label; int pipe_rw[2]; int pid; int flags; }


decompiled_code:
void __fastcall passcheck_update(__int64 a1, const char *a2, size_t a3)
{
int i; // er13
ssize_t v6; // rax
size_t v7; // rbx
size_t v8; // rsi
char *v9; // rax
ssize_t v10; // rax
const char *v11; // r12
char *v12; // rax
char *v13; // rax
int *v14; // r13
unsigned __int64 v15; // r12
char *v16; // r15
ssize_t v17; // rax
const char *v18; // rdx

if ( *(_DWORD *)(a1 + 20) )
{
for ( i = 2; ; i = 1 )
{
if ( a3 )
{
do
{
while ( 1 )
{
v6 = write(*(_DWORD *)(a1 + 12), a2, a3);
if ( v6 < 0 )
break;
a2 += v6;
a3 -= v6;
if ( !a3 )
goto LABEL_6;
}
}
while ( *_errno_location() == 4 );
goto LABEL_9;
}
LABEL_6:
a2 = "\n";
a3 = 1LL;
if ( i == 1 )
break;
}
v7 = 0LL;
do
{
while ( 1 )
{
LABEL_14:
if ( strength_size == v7 )
{
v8 = 2 * v7;
if ( !v7 )
v8 = 8LL;
strength_size = v8;
v9 = (char *)realloc(strength, v8);
if ( !v9 )
goto LABEL_9;
strength = v9;
}
v10 = read(*(_DWORD *)(a1 + 8), &strength[v7], strength_size + ~v7);
if ( v10 > 0 )
break;
if ( !v10 || *_errno_location() != 4 )
goto LABEL_9;
}
v7 += v10;
v11 = strength;
strength[v7] = 0;
v12 = strpbrk(v11, LC15);
}
while ( !v12 );
if ( *v12 == 27 )
{
v13 = strpbrk(v11, "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm~");
if ( !v13 )
goto LABEL_9;
v11 = v13 + 1;
}
*strpbrk(v11, LC17) = 0;
v14 = _errno_location();
*v14 = 0;
v15 = strtoull(v11, 0LL, 10);
if ( v15 || !*v14 )
{
do
{
LABEL_28:
v16 = strength;
if ( memchr(strength, 10, v7) )
{
v18 = "1;31mWell-known common password";
if ( v15 )
{
v18 = "31mExtremely week";
if ( v15 > 0x96 )
{
v18 = "33mWeek";
if ( v15 > 0xC8 )
{
v18 = "32mGood";
if ( v15 > 0xFA )
{
v18 = "1;32mStrong";
if ( v15 >= 0x15F )
v18 = "1;7;32mPerfect";
}
}
}
}
if ( (*(_BYTE *)(a1 + 20) & 2) != 0 )
fprintf(stderr, "\x1B[s\x1B[E\x1B[0K%s \x1B[%s\x1B[m (%lli)\x1B[u", *(const char **)a1, v18, v15);
else
fprintf(stderr, "\x1B[B\x1B[s\x1B[0K\x1B[%s\x1B[m (%lli)\x1B[u\x1B[A", v18, v15);
fflush(stderr);
return;
}
v17 = read(*(_DWORD *)(a1 + 8), v16, strength_size);
v7 = v17;
}
while ( v17 > 0 );
if ( v17 && *v14 == 4 )
{
v7 = 0LL;
goto LABEL_14;
}
}
else if ( *v14 == 34 )
{
v15 = -1LL;
goto LABEL_28;
}
LABEL_9:
passcheck_stop(a1);
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, const char *a2, size_t a3)
{
int i; // er13
ssize_t v6; // rax
size_t v7; // rbx
size_t v8; // rsi
char *v9; // rax
ssize_t v10; // rax
const char *v11; // r12
char *v12; // rax
char *v13; // rax
int *v14; // r13
unsigned __int64 v15; // r12
char *v16; // r15
ssize_t v17; // rax
const char *v18; // rdx

if ( *(_DWORD *)(a1 + 20) )
{
for ( i = 2; ; i = 1 )
{
if ( a3 )
{
do
{
while ( 1 )
{
v6 = write(*(_DWORD *)(a1 + 12), a2, a3);
if ( v6 < 0 )
break;
a2 += v6;
a3 -= v6;
if ( !a3 )
goto LABEL_6;
}
}
while ( *_errno_location() == 4 );
goto LABEL_9;
}
LABEL_6:
a2 = "\n";
a3 = 1LL;
if ( i == 1 )
break;
}
v7 = 0LL;
do
{
while ( 1 )
{
LABEL_14:
if ( strength_size == v7 )
{
v8 = 2 * v7;
if ( !v7 )
v8 = 8LL;
strength_size = v8;
v9 = (char *)realloc(strength, v8);
if ( !v9 )
goto LABEL_9;
strength = v9;
}
v10 = read(*(_DWORD *)(a1 + 8), &strength[v7], strength_size + ~v7);
if ( v10 > 0 )
break;
if ( !v10 || *_errno_location() != 4 )
goto LABEL_9;
}
v7 += v10;
v11 = strength;
strength[v7] = 0;
v12 = strpbrk(v11, LC15);
}
while ( !v12 );
if ( *v12 == 27 )
{
v13 = strpbrk(v11, "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm~");
if ( !v13 )
goto LABEL_9;
v11 = v13 + 1;
}
*strpbrk(v11, LC17) = 0;
v14 = _errno_location();
*v14 = 0;
v15 = strtoull(v11, 0LL, 10);
if ( v15 || !*v14 )
{
do
{
LABEL_28:
v16 = strength;
if ( memchr(strength, 10, v7) )
{
v18 = "1;31mWell-known common password";
if ( v15 )
{
v18 = "31mExtremely week";
if ( v15 > 0x96 )
{
v18 = "33mWeek";
if ( v15 > 0xC8 )
{
v18 = "32mGood";
if ( v15 > 0xFA )
{
v18 = "1;32mStrong";
if ( v15 >= 0x15F )
v18 = "1;7;32mPerfect";
}
}
}
}
if ( (*(_BYTE *)(a1 + 20) & 2) != 0 )
fprintf(stderr, "\x1B[s\x1B[E\x1B[0K%s \x1B[%s\x1B[m (%lli)\x1B[u", *(const char **)a1, v18, v15);
else
fprintf(stderr, "\x1B[B\x1B[s\x1B[0K\x1B[%s\x1B[m (%lli)\x1B[u\x1B[A", v18, v15);
fflush(stderr);
return;
}
v17 = read(*(_DWORD *)(a1 + 8), v16, strength_size);
v7 = v17;
}
while ( v17 > 0 );
if ( v17 && *v14 == 4 )
{
v7 = 0LL;
goto LABEL_14;
}
}
else if ( *v14 == 34 )
{
v15 = -1LL;
goto LABEL_28;
}
LABEL_9:
func2(a1);
}
}

original_code:
static void passcheck_update(struct passcheck_state* state, const char* passphrase, size_t len)
{
  size_t strength_ptr = 0;
  ssize_t n;
  int i;
  void* new;
  char* p;
  unsigned long long int value;
  const char* desc;
  if (state->flags == 0)
    return;
  for (i = 0; i < 2; i++, passphrase = "\n", len = 1)
    while (len)
      {
 n = write(state->pipe_rw[1], passphrase, len);
 if (n < 0)
   {
     if ((*__errno_location ()) == 4)
       continue;
     goto fail;
   }
 passphrase += (size_t)n;
 len -= (size_t)n;
      }
 again:
  if (strength_ptr == strength_size)
    {
      strength_size = strength_size ? (strength_size << 1) : 8;
      new = realloc(strength, strength_size * sizeof(char));
      if (new == ((void *)0))
 goto fail;
      strength = new;
    }
  n = read(state->pipe_rw[0], strength + strength_ptr, strength_size - 1 - strength_ptr);
  if (n <= 0)
    {
      if (n && ((*__errno_location ()) == 4))
 goto again;
      goto fail;
    }
  strength_ptr += (size_t)n;
  strength[strength_ptr] = '\0';
  p = strpbrk(strength, " \t\r\f\n\v");
  if (p == ((void *)0))
    goto again;
  if (*p == '\033')
    {
      p = strpbrk(strength, "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm~");
      if (p == ((void *)0))
 goto fail;
      p++;
    }
  else
    p = strength;
  *(strpbrk(p, " \t\r\f\n\v\033")) = '\0';
  (*__errno_location ()) = 0;
  value = strtoull(p, ((void *)0), 10);
  if ((value == 0) && (*__errno_location ()))
    {
      if ((*__errno_location ()) != 34)
 goto fail;
      value = (0x7fffffffffffffffLL * 2ULL + 1ULL);
    }
  while (memchr(strength, '\n', strength_ptr) == ((void *)0))
    {
      strength_ptr = 0;
      n = read(state->pipe_rw[0], strength, strength_size);
      if (n <= 0)
 {
   if (n && ((*__errno_location ()) == 4))
     goto again;
   goto fail;
 }
      strength_ptr = (size_t)n;
    }
  strength_ptr = 0;
  if (0);
  else if (value == 0) desc = "1;31""m""Well-known common password"; else if (value <= 150) desc = "31""m""Extremely week"; else if (value <= 200) desc = "33""m""Week"; else if (value <= 250) desc = "32""m""Good"; else if (value <= 350) desc = "1;32""m""Strong"; else if (1) desc = "1;7;32""m""Perfect";
  if (state->flags & 2)
    fprintf(stderr, "\033[s\033[E\033[0K%s \033[%s\033[m (%lli)\033[u", state->label, desc, value);
  else
    fprintf(stderr, "\033[B\033[s\033[0K\033[%s\033[m (%lli)\033[u\033[A", desc, value);
  fflush(stderr);
  return;
 fail:
  passcheck_stop(state);
}

canonical_original_code:
static void passcheck_update(struct passcheck_state *state, char *passphrase, unsigned long len)
{
  unsigned long strength_ptr = 0;
  long n;
  int i;
  void *new;
  char *p;
  unsigned long long value;
  char *desc;
  if (state->flags == 0)
    return;
  for (i = 0; i < 2; i++, passphrase = "\n", len = 1)
    while (len)
      {
 n = write(state->pipe_rw[1], passphrase, len);
 if (n < 0)
   {
     if ((*__errno_location ()) == 4)
       continue;
     goto fail;
   }
 passphrase += (unsigned long)n;
 len -= (unsigned long)n;
      }
 again:
  if (strength_ptr == strength_size)
    {
      strength_size = strength_size ? (strength_size << 1) : 8;
      new = realloc(strength, strength_size * sizeof(char));
      if (new == ((void *)0))
 goto fail;
      strength = new;
    }
  n = read(state->pipe_rw[0], strength + strength_ptr, strength_size - 1 - strength_ptr);
  if (n <= 0)
    {
      if (n && ((*__errno_location ()) == 4))
 goto again;
      goto fail;
    }
  strength_ptr += (unsigned long)n;
  strength[strength_ptr] = '\0';
  p = strpbrk(strength, " \t\r\f\n\v");
  if (p == ((void *)0))
    goto again;
  if (*p == '\033')
    {
      p = strpbrk(strength, "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm~");
      if (p == ((void *)0))
 goto fail;
      p++;
    }
  else
    p = strength;
  *(strpbrk(p, " \t\r\f\n\v\033")) = '\0';
  (*__errno_location ()) = 0;
  value = strtoull(p, ((void *)0), 10);
  if ((value == 0) && (*__errno_location ()))
    {
      if ((*__errno_location ()) != 34)
 goto fail;
      value = (0x7fffffffffffffffLL * 2ULL + 1ULL);
    }
  while (memchr(strength, '\n', strength_ptr) == ((void *)0))
    {
      strength_ptr = 0;
      n = read(state->pipe_rw[0], strength, strength_size);
      if (n <= 0)
 {
   if (n && ((*__errno_location ()) == 4))
     goto again;
   goto fail;
 }
      strength_ptr = (unsigned long)n;
    }
  strength_ptr = 0;
  if (0);
  else if (value == 0) desc = "1;31""m""Well-known common password"; else if (value <= 150) desc = "31""m""Extremely week"; else if (value <= 200) desc = "33""m""Week"; else if (value <= 250) desc = "32""m""Good"; else if (value <= 350) desc = "1;32""m""Strong"; else if (1) desc = "1;7;32""m""Perfect";
  if (state->flags & 2)
    fprintf(stderr, "\033[s\033[E\033[0K%s \033[%s\033[m (%lli)\033[u", state->label, desc, value);
  else
    fprintf(stderr, "\033[B\033[s\033[0K\033[%s\033[m (%lli)\033[u\033[A", desc, value);
  fflush(stderr);
  return;
 fail:
  passcheck_stop(state);
}

variable_types:
passphrase
char *

variable_types:
len
unsigned long

variable_types: n long

variable_types: i int

variable_types:
new
void *

variable_types:
p
char *

variable_types:
value
unsigned long long

variable_types:
desc
char *


decompiled_code:
char *__fastcall passphrase_read2(int a1, int a2)
{
char *v2; // rbp
__int64 v3; // r12
__int64 v4; // r14
int v5; // eax
_BYTE v7[88]; // [rsp+0h] [rbp-58h] BYREF

v2 = (char *)malloc(0x20uLL);
if ( v2 )
{
passcheck_start((__int64)v7, a2);
v3 = 0LL;
v4 = 32LL;
while ( 1 )
{
v5 = fdgetc(a1);
if ( v5 < 0 || v5 == 10 )
break;
if ( v5 )
{
v2[v3] = v5;
passcheck_update((__int64)v7, v2, v3 + 1);
fflush(stderr);
if ( v4 == v3 + 1 )
{
v2 = xrealloc(v2, v4, 2 * v4);
if ( !v2 )
return v2;
v4 *= 2LL;
}
++v3;
}
}
passcheck_stop((__int64)v7);
v2[v3] = 0;
fputc(10, stderr);
}
return v2;
}

original_code:
char* passphrase_read2(int fdin, int flags)
{
  char* rc = malloc(32 * sizeof(char));
  size_t size = 32;
  size_t len = 0;
  int c;
  struct passcheck_state passcheck;
  if (rc == ((void *)0))
    return ((void *)0);
  passcheck_start(&passcheck, flags);
  for (;;)
    {
      c = fdgetc(fdin);
      if ((c < 0) || (c == '\n'))
 {
   passcheck_stop(&passcheck);
   break;
 }
      if (c == 0)
 continue;
      do { do { ; } while (0); *(rc + len++) = (char)c; do { ; } while (0); } while (0);
      passcheck_update(&passcheck, rc, len);
      do { fflush(stderr); } while (0);
      if (len == size)
 {
   if ((rc = xrealloc(rc, (size_t)size, (size_t)size << 1)) == ((void *)0))
     return ((void *)0);
   size <<= 1L;
 }
    }
  *(rc + len) = 0;
  fprintf(stderr, "\n");
  return rc;
}

canonical_original_code:
char *passphrase_read2(int fdin, int flags)
{
  char *rc = malloc(32 * sizeof(char));
  unsigned long size = 32;
  unsigned long len = 0;
  int c;
  struct passcheck_state passcheck;
  if (rc == ((void *)0))
    return ((void *)0);
  passcheck_start(&passcheck, flags);
  for (;;)
    {
      c = fdgetc(fdin);
      if ((c < 0) || (c == '\n'))
 {
   passcheck_stop(&passcheck);
   break;
 }
      if (c == 0)
 continue;
      do { do { ; } while (0); *(rc + len++) = (char)c; do { ; } while (0); } while (0);
      passcheck_update(&passcheck, rc, len);
      do { fflush(stderr); } while (0);
      if (len == size)
 {
   if ((rc = xrealloc(rc, (unsigned long)size, (unsigned long)size << 1)) == ((void *)0))
     return ((void *)0);
   size <<= 1L;
 }
    }
  *(rc + len) = 0;
  fprintf(stderr, "\n");
  return rc;
}

variable_types: fdin int

variable_types:
rc
char *

variable_types:
size
unsigned long

variable_types: c int

variable_types: struct passcheck_state { char *label; int pipe_rw[2]; int pid; int flags; }

return_type: char *


decompiled_code:
char *passphrase_read()
{
return passphrase_read2(0, 0);
}

canonical_decompiled_code:
char *func5()
{
return func4(0, 0);
}

original_code:
char* passphrase_read(void)
{
  return passphrase_read2(0, 0);
}


decompiled_code:
__int64 __fastcall passphrase_wipe(__int64 a1, __int64 a2)
{
return passphrase_explicit_memset________________(a1, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return passphrase_explicit_memset________________(a1, 0LL, a2);
}

original_code:
__attribute__((optimize("-O0")))
void passphrase_wipe(char* ptr, size_t n)
{
  passphrase_explicit_memset________________(ptr, 0, n);
}

canonical_original_code:
void passphrase_wipe(char *ptr, unsigned long n)
{
  passphrase_explicit_memset________________(ptr, 0, n);
}

variable_types:
ptr
char *

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall passphrase_wipe1(const char *a1)
{
__int64 (__fastcall *v1)(const char *, _QWORD, size_t); // rbx
size_t v2; // rax

v1 = (__int64 (__fastcall *)(const char *, _QWORD, size_t))passphrase_explicit_memset________________;
v2 = strlen(a1);
return v1(a1, 0LL, v2);
}

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

v1 = (__int64 (__fastcall *)(const char *, _QWORD, size_t))passphrase_explicit_memset________________;
v2 = strlen(a1);
return v1(a1, 0LL, v2);
}

original_code:
__attribute__((optimize("-O0")))
void passphrase_wipe1(char* ptr)
{
  passphrase_explicit_memset________________(ptr, 0, strlen(ptr));
}

canonical_original_code:
void passphrase_wipe1(char *ptr)
{
  passphrase_explicit_memset________________(ptr, 0, strlen(ptr));
}


cmalloc

repo: GRAVITYLab/OSUFlow

decompiled_code:
void *__fastcall cmalloc(int a1)
{
void *result; // rax

if ( !a1 )
return 0LL;
result = malloc(a1);
if ( !result )
_assert_fail("buf != NULL", "util.c", 0xFu, "cmalloc");
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *result; // rax

if ( !a1 )
return 0LL;
result = malloc(a1);
if ( !result )
_assert_fail("buf != NULL", "util.c", 0xFu, "cmalloc");
return result;
}

original_code:
void* cmalloc(int size) {
  if (size == 0) {
    return ((void *)0);
  }
  void* buf = malloc(size);
  ((void) sizeof ((buf != ((void *)0)) ? 1 : 0), __extension__ ({ if (buf != ((void *)0)) ; else __assert_fail ("buf != NULL", "util.c", 15, __extension__ __PRETTY_FUNCTION__); }));
  return buf;
}

canonical_original_code:
void *cmalloc(int size) {
  if (size == 0) {
    return ((void *)0);
  }
  void *buf = malloc(size);
  ((void) sizeof ((buf != ((void *)0)) ? 1 : 0), __extension__ ({ if (buf != ((void *)0)) ; else __assert_fail ("buf != NULL", "util.c", 15, __extension__ __PRETTY_FUNCTION__); }));
  return buf;
}

variable_types: size int

variable_types:
buf
void *

return_type: void *


cfree

decompiled_code:
void __fastcall cfree(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void cfree(void* buf) {
  if (buf != ((void *)0)) {
    free(buf);
  }
}

canonical_original_code:
void cfree(void *buf) {
  if (buf != ((void *)0)) {
    free(buf);
  }
}


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

result = (unsigned int)(int)a1;
if ( (float)(a1 - (float)(int)result) > 0.0 )
result = (unsigned int)(int)(float)(a1 + 1.0);
return result;
}

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

result = (unsigned int)(int)a1;
if ( (float)(a1 - (float)(int)result) > 0.0 )
result = (unsigned int)(int)(float)(a1 + 1.0);
return result;
}

original_code:
int ceil_pos(float val) {
  return (val - (int)val > 0) ? (int)(val + 1) : (int)val;
}

variable_types: val float


bsearchx

decompiled_code:
__int64 __fastcall bsearchx(__int64 a1, __int64 a2, int a3, int a4, __int64 (__fastcall *a5)(__int64, __int64))
{
unsigned __int64 v6; // rbp
int v7; // eax
__int64 result; // rax
__int64 v9; // r12
__int64 v10; // rbx
int v11; // eax
int v12; // eax
int v15; // [rsp+1Ch] [rbp-3Ch]

if ( a3 > 1 )
{
v15 = a3 - 1;
v6 = a3 - 1;
if ( (int)a5(a1, a2 + a4) < 0 )
{
v7 = a5(a1, a2);
if ( v7 < 0 )
result = 0xFFFFFFFFLL;
else
result = v7 > 0;
return result;
}
LABEL_6:
v9 = a2;
while ( 1 )
{
v10 = v9 + a4 * (v6 >> 1);
v11 = a5(a1, v10);
if ( !v11 )
return 2 * (unsigned int)((v10 - a2) / a4);
if ( v11 > 0 )
{
v9 = v10 + a4;
if ( (int)a5(a1, v9) < 0 )
return 2 * (unsigned int)((v10 - a2) / a4) + 1;
--v6;
}
v6 >>= 1;
if ( !v6 )
goto LABEL_15;
}
}
v15 = a3 - 1;
v6 = a3 - 1;
if ( a3 != 1 )
goto LABEL_6;
v15 = 0;
LABEL_15:
v12 = a5(a1, a2 + v15 * a4);
if ( v12 > 0 )
return (unsigned int)(2 * a3 - 1);
if ( v12 )
return 0xFFFFFFFFLL;
return (unsigned int)(2 * v15);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3, int a4, __int64 (__fastcall *a5)(__int64, __int64))
{
unsigned __int64 v6; // rbp
int v7; // eax
__int64 result; // rax
__int64 v9; // r12
__int64 v10; // rbx
int v11; // eax
int v12; // eax
int v15; // [rsp+1Ch] [rbp-3Ch]

if ( a3 > 1 )
{
v15 = a3 - 1;
v6 = a3 - 1;
if ( (int)a5(a1, a2 + a4) < 0 )
{
v7 = a5(a1, a2);
if ( v7 < 0 )
result = 0xFFFFFFFFLL;
else
result = v7 > 0;
return result;
}
LABEL_6:
v9 = a2;
while ( 1 )
{
v10 = v9 + a4 * (v6 >> 1);
v11 = a5(a1, v10);
if ( !v11 )
return 2 * (unsigned int)((v10 - a2) / a4);
if ( v11 > 0 )
{
v9 = v10 + a4;
if ( (int)a5(a1, v9) < 0 )
return 2 * (unsigned int)((v10 - a2) / a4) + 1;
--v6;
}
v6 >>= 1;
if ( !v6 )
goto LABEL_15;
}
}
v15 = a3 - 1;
v6 = a3 - 1;
if ( a3 != 1 )
goto LABEL_6;
v15 = 0;
LABEL_15:
v12 = a5(a1, a2 + v15 * a4);
if ( v12 > 0 )
return (unsigned int)(2 * a3 - 1);
if ( v12 )
return 0xFFFFFFFFLL;
return (unsigned int)(2 * v15);
}

original_code:
int bsearchx(void *key, void *item_data, int num_items, int item_size,
             int (*compare)(const void *, const void *)) {
  int cmp;
  char* base = (char*)item_data;
  size_t lim;
  char* item;
  if (num_items > 1 && compare(key, item_data + item_size) < 0) {
    int cmp = compare(key, item_data);
    if (cmp < 0) {
      return -1;
    } else if (cmp > 0) {
      return 1;
    } else {
      return 0;
    }
  }
  for (lim = num_items - 1; lim > 0; lim >>= 1) {
    item = base + (lim >> 1) * item_size;
    cmp = compare(key, item);
    if (cmp == 0) {
      return ((item - (char*)item_data) / item_size) * 2;
    }
    if (cmp > 0) {
      if (compare(key, item + item_size) < 0) {
        return (((item - (char*)item_data) / item_size) * 2) + 1;
      }
      base = item + item_size;
      lim--;
    }
  }
  cmp = compare(key, item_data + (item_size * (num_items - 1)));
  if (cmp > 0) {
    return (num_items * 2) - 1;
  } else if (cmp == 0) {
    return (num_items * 2) - 2;
  } else {
    return -1;
  }
}

canonical_original_code:
int bsearchx(void *key, void *item_data, int num_items, int item_size, int (*compare)(void *, void *)) {
  int cmp;
  char *base = (char*)item_data;
  unsigned long lim;
  char *item;
  if (num_items > 1 && compare(key, item_data + item_size) < 0) {
    int cmp = compare(key, item_data);
    if (cmp < 0) {
      return -1;
    } else if (cmp > 0) {
      return 1;
    } else {
      return 0;
    }
  }
  for (lim = num_items - 1; lim > 0; lim >>= 1) {
    item = base + (lim >> 1) * item_size;
    cmp = compare(key, item);
    if (cmp == 0) {
      return ((item - (char *)item_data) / item_size) * 2;
    }
    if (cmp > 0) {
      if (compare(key, item + item_size) < 0) {
        return (((item - (char *)item_data) / item_size) * 2) + 1;
      }
      base = item + item_size;
      lim--;
    }
  }
  cmp = compare(key, item_data + (item_size * (num_items - 1)));
  if (cmp > 0) {
    return (num_items * 2) - 1;
  } else if (cmp == 0) {
    return (num_items * 2) - 2;
  } else {
    return -1;
  }
}

variable_types:
key
void *

variable_types:
compare
int (*)(void *, void *)

variable_types: cmp int

variable_types:
base
char *

variable_types:
lim
unsigned long

variable_types:
item
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
void **v6; // rbp
int v7; // eax
void *v8; // rbx
void *v9; // r12
int v10; // eax
void *v11; // rax
unsigned int v12; // eax
int v13; // er13
unsigned int i; // ebx
int result; // eax
unsigned int v16; // eax
int v17; // er13
unsigned int j; // ebx
char v19[168]; // [rsp+0h] [rbp-A8h] BYREF

v3 = 0LL;
if ( argc == 5 )
{
do
{
printf("\n argc = %d , i = %d , argv[i] = %s ", 5LL, (unsigned int)v3, argv[v3]);
++v3;
}
while ( v3 != 5 );
v4 = calc_total_numb_of_elemts(argv[3], 32LL);
printf("\n\nTotal number of elements of set A = %d \n", v4);
v5 = calc_total_numb_of_elemts(argv[4], 32LL);
printf("Total number of elements of set B = %d \n", v5);
v6 = (void **)malloc(0x18uLL);
if ( v6 )
{
v7 = calc_total_numb_of_elemts(argv[3], 32LL);
*(_DWORD *)v6 = v7;
v6[1] = (void *)argv[3];
v8 = calloc(v7, 0x10uLL);
v6[2] = v8;
if ( v8 )
{
v9 = malloc(0x18uLL);
if ( v9 )
{
v10 = calc_total_numb_of_elemts(argv[4], 32LL);
*(_DWORD *)v9 = v10;
*((_QWORD *)v9 + 1) = argv[4];
v11 = calloc(v10, 0x10uLL);
*((_QWORD *)v9 + 2) = v11;
if ( v11 )
{
v12 = parse_elmt_of_set(v6, 32LL);
printf("\nparse_elmt_of_set for set A return : %d \n", v12);
v13 = *(_DWORD *)v6;
v19[0] = 0;
puts("\n Elements of set A : ");
if ( v13 > 0 )
{
for ( i = 0; i != v13; ++i )
{
if ( !(unsigned int)get_element(v6, i, v19, 128LL) )
printf("\nElement N %d = %s", i, v19);
}
}
search_twin_elemts_into_set(v6);
puts("\n\nList of Twin elements for each element into set A:");
print_twin_elements(v6);
v16 = parse_elmt_of_set(v9, 32LL);
printf("\n\nparse_elmt_of_set for set B return : %d \n", v16);
v17 = *(_DWORD *)v9;
v19[0] = 0;
puts("\n Elements of set B : ");
if ( v17 > 0 )
{
for ( j = 0; j != v17; ++j )
{
if ( !(unsigned int)get_element(v9, j, v19, 128LL) )
printf("\nElement N %d = %s", j, v19);
}
}
search_twin_elemts_into_set(v9);
puts("\n\nList of Twin elements for each element into set B:");
print_twin_elements(v9);
puts("\n A union B = ");
operation_union(v6, v9, stdout);
puts("\n A intersection B = ");
operation_intersection(v6, v9, stdout);
puts("\n A difference B = ");
operation_difference(v6, v9, stdout);
free(*((void **)v9 + 2));
free(v9);
free(v6[2]);
free(v6);
puts("\n");
result = 0;
}
else
{
free(v9);
free(v6[2]);
free(v6);
perror("\n ERROR : Bad memory allocation (phase 2) for secondary set ! \n ");
result = 1;
}
}
else
{
free(v8);
free(v6);
perror("\n ERROR : Bad memory allocation (phase 1) for secondary set ! \n ");
result = 1;
}
}
else
{
free(v6);
perror("\n ERROR : Bad memory allocation (phase 2) for primary set ! \n ");
result = 1;
}
}
else
{
perror("\n ERROR : Bad memory allocation (phase 1) for primary set ! \n ");
result = 1;
}
}
else
{
print_help(argc, argv, envp);
result = 1;
}
return result;
}

original_code:
int main( int argc, char* argv[], char* envp[] )
{
    int i = 0;
    int j = 0;
    char buf[128];
    int res = 0;
    struct tabl_elemts_of_set* tbl_elem_A = ((void *)0);
    struct tabl_elemts_of_set* tbl_elem_B = ((void *)0);
    if( argc != 5 )
    {
        print_help();
        return 1;
    }
    for( i = 0; i < argc; i++)
    {
        printf("\n argc = %d , i = %d , argv[i] = %s ", argc, i, *(argv +i) );
    }
    res = calc_total_numb_of_elemts( *(argv+3), ' ' );
    printf("\n\nTotal number of elements of set A = %d \n", res);
    res = calc_total_numb_of_elemts( *(argv+4), ' ' );
    printf("Total number of elements of set B = %d \n", res);
    tbl_elem_A = (tabl_elemts_of_set*) malloc( sizeof(tabl_elemts_of_set) );
    if( tbl_elem_A == ((void *)0) )
    {
        perror("\n ERROR : Bad memory allocation (phase 1) for primary set ! \n ");
        return 1;
    }
    tbl_elem_A->total_numb = calc_total_numb_of_elemts( *(argv+3), ' ' );
    tbl_elem_A->str_of_set = *(argv+3);
    tbl_elem_A->arr_elemts = ((void *)0);
    tbl_elem_A->arr_elemts = (some_elemt_in_str*) calloc(
                                                          (tbl_elem_A->total_numb),
                                                           sizeof(some_elemt_in_str) );
    if( (tbl_elem_A->arr_elemts) == ((void *)0) )
    {
        free( tbl_elem_A );
        perror("\n ERROR : Bad memory allocation (phase 2) for primary set ! \n ");
        return 1;
    }
    tbl_elem_B = (tabl_elemts_of_set*) malloc( sizeof(tabl_elemts_of_set) );
    if( tbl_elem_B == ((void *)0) )
    {
        free( (void*) (tbl_elem_A->arr_elemts) );
        free( tbl_elem_A );
        perror("\n ERROR : Bad memory allocation (phase 1) for secondary set ! \n ");
        return 1;
    }
    tbl_elem_B->total_numb = calc_total_numb_of_elemts( *(argv+4), ' ' );
    tbl_elem_B->str_of_set = *(argv+4);
    tbl_elem_B->arr_elemts = ((void *)0);
    tbl_elem_B->arr_elemts = (some_elemt_in_str*) calloc(
                                                         (tbl_elem_B->total_numb),
                                                           sizeof(some_elemt_in_str) );
    if( (tbl_elem_B->arr_elemts) == ((void *)0) )
    {
        free( tbl_elem_B );
        free( (void*) (tbl_elem_A->arr_elemts) );
        free( tbl_elem_A );
        perror("\n ERROR : Bad memory allocation (phase 2) for secondary set ! \n ");
        return 1;
    }
    res = parse_elmt_of_set( tbl_elem_A, ' ' );
    printf("\nparse_elmt_of_set  for set A return : %d \n", res);
    res = tbl_elem_A->total_numb;
    buf[0] = 0;
    printf("\n Elements of set A : \n");
    for( i = 0 ; i < res; i++)
    {
        j = get_element( tbl_elem_A, i, buf, 128 );
        if( j == 0 )
        {
            printf("\nElement N %d = %s", i, buf);
        }
    }
    res = search_twin_elemts_into_set( tbl_elem_A );
    printf("\n\nList of Twin elements for each element into set A:\n");
    print_twin_elements( tbl_elem_A );
    res = parse_elmt_of_set( tbl_elem_B, ' ' );
    printf("\n\nparse_elmt_of_set  for set B return : %d \n", res);
    res = tbl_elem_B->total_numb;
    buf[0] = 0;
    printf("\n Elements of set B : \n");
    for( i = 0 ; i < res; i++)
    {
        j = get_element( tbl_elem_B, i, buf, 128 );
        if( j == 0 )
        {
            printf("\nElement N %d = %s", i, buf);
        }
    }
    res = search_twin_elemts_into_set( tbl_elem_B );
    printf("\n\nList of Twin elements for each element into set B:\n");
    print_twin_elements( tbl_elem_B );
    printf("\n A union B = \n");
    res = operation_union( tbl_elem_A, tbl_elem_B, stdout );
    printf("\n A intersection B = \n");
    res = operation_intersection( tbl_elem_A, tbl_elem_B, stdout );
    printf("\n A difference B = \n");
    res = operation_difference( tbl_elem_A, tbl_elem_B, stdout );
    free( (void*) (tbl_elem_B->arr_elemts) );
    free( tbl_elem_B );
    free( (void*) (tbl_elem_A->arr_elemts) );
    free( tbl_elem_A );
    printf("\n\n");
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[], char *envp[])
{
    int i = 0;
    int j = 0;
    char buf[128];
    int res = 0;
    struct tabl_elemts_of_set *tbl_elem_A = ((void *)0);
    struct tabl_elemts_of_set *tbl_elem_B = ((void *)0);
    if( argc != 5 )
    {
        print_help();
        return 1;
    }
    for( i = 0; i < argc; i++)
    {
        printf("\n argc = %d , i = %d , argv[i] = %s ", argc, i, *(argv +i) );
    }
    res = calc_total_numb_of_elemts( *(argv+3), ' ' );
    printf("\n\nTotal number of elements of set A = %d \n", res);
    res = calc_total_numb_of_elemts( *(argv+4), ' ' );
    printf("Total number of elements of set B = %d \n", res);
    tbl_elem_A = (struct tabl_elemts_of_set *) malloc( sizeof(tabl_elemts_of_set) );
    if( tbl_elem_A == ((void *)0) )
    {
        perror("\n ERROR : Bad memory allocation (phase 1) for primary set ! \n ");
        return 1;
    }
    tbl_elem_A->total_numb = calc_total_numb_of_elemts( *(argv+3), ' ' );
    tbl_elem_A->str_of_set = *(argv+3);
    tbl_elem_A->arr_elemts = ((void *)0);
    tbl_elem_A->arr_elemts = (struct some_elemt_in_str *) calloc(
                                                          (tbl_elem_A->total_numb),
                                                           sizeof(some_elemt_in_str) );
    if( (tbl_elem_A->arr_elemts) == ((void *)0) )
    {
        free( tbl_elem_A );
        perror("\n ERROR : Bad memory allocation (phase 2) for primary set ! \n ");
        return 1;
    }
    tbl_elem_B = (struct tabl_elemts_of_set *) malloc( sizeof(tabl_elemts_of_set) );
    if( tbl_elem_B == ((void *)0) )
    {
        free( (void *) (tbl_elem_A->arr_elemts) );
        free( tbl_elem_A );
        perror("\n ERROR : Bad memory allocation (phase 1) for secondary set ! \n ");
        return 1;
    }
    tbl_elem_B->total_numb = calc_total_numb_of_elemts( *(argv+4), ' ' );
    tbl_elem_B->str_of_set = *(argv+4);
    tbl_elem_B->arr_elemts = ((void *)0);
    tbl_elem_B->arr_elemts = (struct some_elemt_in_str *) calloc(
                                                         (tbl_elem_B->total_numb),
                                                           sizeof(some_elemt_in_str) );
    if( (tbl_elem_B->arr_elemts) == ((void *)0) )
    {
        free( tbl_elem_B );
        free( (void *) (tbl_elem_A->arr_elemts) );
        free( tbl_elem_A );
        perror("\n ERROR : Bad memory allocation (phase 2) for secondary set ! \n ");
        return 1;
    }
    res = parse_elmt_of_set( tbl_elem_A, ' ' );
    printf("\nparse_elmt_of_set  for set A return : %d \n", res);
    res = tbl_elem_A->total_numb;
    buf[0] = 0;
    printf("\n Elements of set A : \n");
    for( i = 0 ; i < res; i++)
    {
        j = get_element( tbl_elem_A, i, buf, 128 );
        if( j == 0 )
        {
            printf("\nElement N %d = %s", i, buf);
        }
    }
    res = search_twin_elemts_into_set( tbl_elem_A );
    printf("\n\nList of Twin elements for each element into set A:\n");
    print_twin_elements( tbl_elem_A );
    res = parse_elmt_of_set( tbl_elem_B, ' ' );
    printf("\n\nparse_elmt_of_set  for set B return : %d \n", res);
    res = tbl_elem_B->total_numb;
    buf[0] = 0;
    printf("\n Elements of set B : \n");
    for( i = 0 ; i < res; i++)
    {
        j = get_element( tbl_elem_B, i, buf, 128 );
        if( j == 0 )
        {
            printf("\nElement N %d = %s", i, buf);
        }
    }
    res = search_twin_elemts_into_set( tbl_elem_B );
    printf("\n\nList of Twin elements for each element into set B:\n");
    print_twin_elements( tbl_elem_B );
    printf("\n A union B = \n");
    res = operation_union( tbl_elem_A, tbl_elem_B, stdout );
    printf("\n A intersection B = \n");
    res = operation_intersection( tbl_elem_A, tbl_elem_B, stdout );
    printf("\n A difference B = \n");
    res = operation_difference( tbl_elem_A, tbl_elem_B, stdout );
    free( (void *) (tbl_elem_B->arr_elemts) );
    free( tbl_elem_B );
    free( (void *) (tbl_elem_A->arr_elemts) );
    free( tbl_elem_A );
    printf("\n\n");
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
envp
char *[]

variable_types: i int

variable_types: j int

variable_types:
buf
char [128]

variable_types: res int

variable_types: struct tabl_elemts_of_set { int total_numb; char *str_of_set; struct some_elemt_in_str { int pos_begin; int quantity_symb; int idx_prev_twin; int idx_next_twin; } *arr_elemts; } *

user_defined_types: struct tabl_elemts_of_set { int total_numb; char *str_of_set; struct some_elemt_in_str *arr_elemts; }


decompiled_code:
__int64 __fastcall get_element(unsigned int *a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
_DWORD *v6; // rsi
__int64 v7; // rax
int v8; // edx
int v9; // ecx
unsigned __int64 v10; // rsi
int v11; // edx

if ( !a1 )
return 0xFFFFFFFFLL;
result = *a1;
if ( (_DWORD)result )
{
if ( *((_QWORD *)a1 + 1) )
{
if ( (int)result <= a2 )
{
result = 4294967293LL;
}
else if ( a3 )
{
if ( a4 )
{
v6 = (_DWORD *)(*((_QWORD *)a1 + 2) + 16LL * a2);
LODWORD(v7) = *v6;
v8 = v6[1];
v9 = a4 - 1;
if ( *v6 >= *v6 + v8 )
{
v11 = 0;
}
else
{
v7 = (int)v7;
v10 = (int)v7 + (unsigned __int64)(unsigned int)(v8 - 1) + 1;
v11 = 0;
do
{
if ( v9 > v11 )
*(_BYTE *)(a3 + v11++) = *(_BYTE *)(*((_QWORD *)a1 + 1) + v7);
++v7;
}
while ( v7 != v10 );
}
*(_BYTE *)(a3 + v11) = 0;
result = 0LL;
}
else
{
result = 4294967291LL;
}
}
else
{
result = 4294967292LL;
}
}
else
{
result = 4294967294LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
_DWORD *v6; // rsi
__int64 v7; // rax
int v8; // edx
int v9; // ecx
unsigned __int64 v10; // rsi
int v11; // edx

if ( !a1 )
return 0xFFFFFFFFLL;
result = *a1;
if ( (_DWORD)result )
{
if ( *((_QWORD *)a1 + 1) )
{
if ( (int)result <= a2 )
{
result = 4294967293LL;
}
else if ( a3 )
{
if ( a4 )
{
v6 = (_DWORD *)(*((_QWORD *)a1 + 2) + 16LL * a2);
LODWORD(v7) = *v6;
v8 = v6[1];
v9 = a4 - 1;
if ( *v6 >= *v6 + v8 )
{
v11 = 0;
}
else
{
v7 = (int)v7;
v10 = (int)v7 + (unsigned __int64)(unsigned int)(v8 - 1) + 1;
v11 = 0;
do
{
if ( v9 > v11 )
*(_BYTE *)(a3 + v11++) = *(_BYTE *)(*((_QWORD *)a1 + 1) + v7);
++v7;
}
while ( v7 != v10 );
}
*(_BYTE *)(a3 + v11) = 0;
result = 0LL;
}
else
{
result = 4294967291LL;
}
}
else
{
result = 4294967292LL;
}
}
else
{
result = 4294967294LL;
}
}
return result;
}

original_code:
int get_element( const tabl_elemts_of_set* tbl_elemts, int idx_elmt,
                                     char* val_elmt, const size_t size_val_el )
{
    int i = 0;
    int j = 0;
    int tot_numb_elm = 0;
    int beg_elm = 0;
    int end_elm = 0;
    int quant_symb = 0;
    int size_buf = 0;
    if( tbl_elemts == ((void *)0) ) return -1;
    tot_numb_elm = tbl_elemts->total_numb;
    if( tot_numb_elm == 0 ) return 0;
    if( (tbl_elemts->str_of_set) == ((void *)0) ) return -2;
    if( idx_elmt > (tot_numb_elm - 1) ) return -3;
    if( val_elmt == ((void *)0) ) return -4;
    if( size_val_el == 0 ) return -5;
    beg_elm = ((tbl_elemts->arr_elemts) + idx_elmt)->pos_begin;
    quant_symb = ((tbl_elemts->arr_elemts) + idx_elmt)->quantity_symb;
    end_elm = beg_elm + quant_symb;
    size_buf = size_val_el - 1;
    j = 0;
    for( i = beg_elm; i < end_elm; i++ )
    {
        if( j < size_buf )
        {
            *(val_elmt + j++) = *((tbl_elemts->str_of_set) + i);
        }
    }
    *(val_elmt + j) = 0;
    return 0;
}

canonical_original_code:
int get_element(struct tabl_elemts_of_set *tbl_elemts, int idx_elmt, char *val_elmt, unsigned long size_val_el)
{
    int i = 0;
    int j = 0;
    int tot_numb_elm = 0;
    int beg_elm = 0;
    int end_elm = 0;
    int quant_symb = 0;
    int size_buf = 0;
    if( tbl_elemts == ((void *)0) ) return -1;
    tot_numb_elm = tbl_elemts->total_numb;
    if( tot_numb_elm == 0 ) return 0;
    if( (tbl_elemts->str_of_set) == ((void *)0) ) return -2;
    if( idx_elmt > (tot_numb_elm - 1) ) return -3;
    if( val_elmt == ((void *)0) ) return -4;
    if( size_val_el == 0 ) return -5;
    beg_elm = ((tbl_elemts->arr_elemts) + idx_elmt)->pos_begin;
    quant_symb = ((tbl_elemts->arr_elemts) + idx_elmt)->quantity_symb;
    end_elm = beg_elm + quant_symb;
    size_buf = size_val_el - 1;
    j = 0;
    for( i = beg_elm; i < end_elm; i++ )
    {
        if( j < size_buf )
        {
            *(val_elmt + j++) = *((tbl_elemts->str_of_set) + i);
        }
    }
    *(val_elmt + j) = 0;
    return 0;
}

user_defined_types: struct some_elemt_in_str { int pos_begin; int quantity_symb; int idx_prev_twin; int idx_next_twin; }


original_code:
int parse_elmt_of_set( const tabl_elemts_of_set* tbl_elemts,
                                                     const char separator )
{
    int i, j;
    int len_str = 0;
    int count_elem = 0;
    const char* str = ((void *)0);
    char current = 0;
    enum { CHARS_OF_SEPARATOR, CHARS_OF_ELEM } state = CHARS_OF_SEPARATOR;
    if( tbl_elemts == ((void *)0) ) return -1;
    if( (tbl_elemts->total_numb) == 0 ) return -2;
    len_str = strlen( tbl_elemts->str_of_set );
    str = tbl_elemts->str_of_set;
    for( i = 0; i < len_str; i++ )
    {
        current = *(str + i);
        switch( state )
        {
            case CHARS_OF_SEPARATOR :
            {
                if( current != separator )
                {
                    state = CHARS_OF_ELEM;
                    ((tbl_elemts->arr_elemts) + count_elem)->pos_begin = i;
                    j = 1;
                }
                break;
            }
            case CHARS_OF_ELEM :
            {
                if( current == separator )
                {
                    state = CHARS_OF_SEPARATOR;
                    ((tbl_elemts->arr_elemts) + count_elem)->quantity_symb = j;
                    count_elem++;
                }
                else
                {
                    j++;
                }
                break;
            }
        }
    }
    if( state == CHARS_OF_ELEM )
    {
        ((tbl_elemts->arr_elemts) + count_elem)->quantity_symb = j;
        count_elem++;
    }
    return count_elem;
}

canonical_original_code:
int parse_elmt_of_set(struct tabl_elemts_of_set *tbl_elemts, char separator)
{
    int i; int j;
    int len_str = 0;
    int count_elem = 0;
    char *str = ((void *)0);
    char current = 0;
    enum { CHARS_OF_SEPARATOR=0, CHARS_OF_ELEM=1 } state = CHARS_OF_SEPARATOR;
    if( tbl_elemts == ((void *)0) ) return -1;
    if( (tbl_elemts->total_numb) == 0 ) return -2;
    len_str = strlen( tbl_elemts->str_of_set );
    str = tbl_elemts->str_of_set;
    for( i = 0; i < len_str; i++ )
    {
        current = *(str + i);
        switch( state )
        {
            case CHARS_OF_SEPARATOR :
            {
                if( current != separator )
                {
                    state = CHARS_OF_ELEM;
                    ((tbl_elemts->arr_elemts) + count_elem)->pos_begin = i;
                    j = 1;
                }
                break;
            }
            case CHARS_OF_ELEM :
            {
                if( current == separator )
                {
                    state = CHARS_OF_SEPARATOR;
                    ((tbl_elemts->arr_elemts) + count_elem)->quantity_symb = j;
                    count_elem++;
                }
                else
                {
                    j++;
                }
                break;
            }
        }
    }
    if( state == CHARS_OF_ELEM )
    {
        ((tbl_elemts->arr_elemts) + count_elem)->quantity_symb = j;
        count_elem++;
    }
    return count_elem;
}

variable_types: separator char

variable_types:
str
char *

variable_types: current char


decompiled_code:
__int64 __fastcall calc_total_numb_of_elemts(const char *a1, char a2)
{
int v3; // eax
int v4; // edx
const char *v5; // rax
__int64 v6; // rsi
_BOOL4 v7; // ecx
int v8; // edi
char v9; // dl

v3 = strlen(a1);
if ( v3 <= 0 )
return 0;
v4 = v3;
v5 = a1;
v6 = (__int64)&a1[v4 - 1 + 1];
v7 = 0;
v8 = 0;
do
{
v9 = *v5;
if ( v7 )
{
if ( v9 == a2 )
{
++v8;
v7 = 0;
}
}
else
{
v7 = v9 != a2;
}
++v5;
}
while ( v5 != (const char *)v6 );
return (unsigned int)(v7 + v8);
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, char a2)
{
int v3; // eax
int v4; // edx
const char *v5; // rax
__int64 v6; // rsi
_BOOL4 v7; // ecx
int v8; // edi
char v9; // dl

v3 = strlen(a1);
if ( v3 <= 0 )
return 0;
v4 = v3;
v5 = a1;
v6 = (__int64)&a1[v4 - 1 + 1];
v7 = 0;
v8 = 0;
do
{
v9 = *v5;
if ( v7 )
{
if ( v9 == a2 )
{
++v8;
v7 = 0;
}
}
else
{
v7 = v9 != a2;
}
++v5;
}
while ( v5 != (const char *)v6 );
return (unsigned int)(v7 + v8);
}

original_code:
int calc_total_numb_of_elemts( const char* const str_of_set,
                                                         const char separator )
{
    int i;
    int len_str;
    int tot_numb_of_elemts = 0;
    char current = 0;
    enum { CHARS_OF_SEPARATOR, CHARS_OF_ELEM } state = CHARS_OF_SEPARATOR;
    len_str = strlen( str_of_set );
    for( i = 0; i < len_str; i++ )
    {
        current = *(str_of_set + i);
        switch( state )
        {
            case CHARS_OF_SEPARATOR :
            {
                if( current != separator )
                {
                    state = CHARS_OF_ELEM;
                }
                break;
            }
            case CHARS_OF_ELEM :
            {
                if( current == separator )
                {
                    state = CHARS_OF_SEPARATOR;
                    tot_numb_of_elemts++;
                }
                break;
            }
        }
    }
    if( state == CHARS_OF_ELEM ) tot_numb_of_elemts++;
    return tot_numb_of_elemts;
}

canonical_original_code:
int calc_total_numb_of_elemts(char *str_of_set, char separator)
{
    int i;
    int len_str;
    int tot_numb_of_elemts = 0;
    char current = 0;
    enum { CHARS_OF_SEPARATOR=0, CHARS_OF_ELEM=1 } state = CHARS_OF_SEPARATOR;
    len_str = strlen( str_of_set );
    for( i = 0; i < len_str; i++ )
    {
        current = *(str_of_set + i);
        switch( state )
        {
            case CHARS_OF_SEPARATOR :
            {
                if( current != separator )
                {
                    state = CHARS_OF_ELEM;
                }
                break;
            }
            case CHARS_OF_ELEM :
            {
                if( current == separator )
                {
                    state = CHARS_OF_SEPARATOR;
                    tot_numb_of_elemts++;
                }
                break;
            }
        }
    }
    if( state == CHARS_OF_ELEM ) tot_numb_of_elemts++;
    return tot_numb_of_elemts;
}


decompiled_code:
int print_help()
{
return puts("\nUsage : wrksets -p <union | intersection | difference> \"set A\" \"set B\" \n");
}

canonical_decompiled_code:
int func0()
{
return puts("\nUsage : wrksets -p <union | intersection | difference> \"set A\" \"set B\" \n");
}

original_code:
void print_help()
{
    printf("\nUsage :  wrksets -p <union | intersection | " "difference> \"set A\" \"set B\" \n\n");
    return;
}


original_code:
void print_twin_elements( tabl_elemts_of_set* tbl_elemts )
{
    int i = 0;
    int j = 0;
    int k = 0;
    int N = 0;
    int beg_elm = 0;
    int len_elm = 0;
    const char* elemt = ((void *)0);
    N = tbl_elemts->total_numb;
    if( !N ) return;
    for( i = 0; i < N; i++ )
    {
 if( ((tbl_elemts->arr_elemts + i)->idx_prev_twin) == -1 )
 {
     printf("\n");
     j = i;
     beg_elm = (tbl_elemts->arr_elemts + j)->pos_begin;
     elemt = tbl_elemts->str_of_set + beg_elm;
            len_elm = (tbl_elemts->arr_elemts + j)->quantity_symb;
     print_element_by_chars( elemt, len_elm, stdout);
     printf(" : ");
     while( (tbl_elemts->arr_elemts + j)->idx_next_twin != -1 )
     {
  k = (tbl_elemts->arr_elemts + j)->idx_next_twin;
  j = k;
  beg_elm = (tbl_elemts->arr_elemts + j)->pos_begin;
         elemt = tbl_elemts->str_of_set + beg_elm;
                len_elm = (tbl_elemts->arr_elemts + j)->quantity_symb;
  print_element_by_chars( elemt, len_elm, stdout);
         printf(" ; ");
     }
 }
    }
    printf("\n");
    return;
}

canonical_original_code:
void print_twin_elements(struct tabl_elemts_of_set *tbl_elemts)
{
    int i = 0;
    int j = 0;
    int k = 0;
    int N = 0;
    int beg_elm = 0;
    int len_elm = 0;
    char *elemt = ((void *)0);
    N = tbl_elemts->total_numb;
    if( !N ) return;
    for( i = 0; i < N; i++ )
    {
 if( ((tbl_elemts->arr_elemts + i)->idx_prev_twin) == -1 )
 {
     printf("\n");
     j = i;
     beg_elm = (tbl_elemts->arr_elemts + j)->pos_begin;
     elemt = tbl_elemts->str_of_set + beg_elm;
            len_elm = (tbl_elemts->arr_elemts + j)->quantity_symb;
     print_element_by_chars( elemt, len_elm, stdout);
     printf(" : ");
     while( (tbl_elemts->arr_elemts + j)->idx_next_twin != -1 )
     {
  k = (tbl_elemts->arr_elemts + j)->idx_next_twin;
  j = k;
  beg_elm = (tbl_elemts->arr_elemts + j)->pos_begin;
         elemt = tbl_elemts->str_of_set + beg_elm;
                len_elm = (tbl_elemts->arr_elemts + j)->quantity_symb;
  print_element_by_chars( elemt, len_elm, stdout);
         printf(" ; ");
     }
 }
    }
    printf("\n");
    return;
}

variable_types: k int

variable_types: N int

variable_types:
elemt
char *


original_code:
int search_twin_elemts_into_set( tabl_elemts_of_set* tbl_elemts )
{
    int i = 0;
    int j = 0;
    int N = 0;
    int res = 0;
    int len_elm_1 = 0;
    int len_elm_2 = 0;
    int beg_elm_1 = 0;
    int beg_elm_2 = 0;
    int adjac_twin = 0;
    const char* elemt_1 = ((void *)0);
    const char* elemt_2 = ((void *)0);
    N = tbl_elemts->total_numb;
    if( N == 0 ) return 0;
    for( i = 0; i < N; i++ )
    {
        if( ((tbl_elemts->arr_elemts + i)->idx_prev_twin) ==
     ((tbl_elemts->arr_elemts + i)->idx_next_twin)
   )
 {
     adjac_twin = i;
     (tbl_elemts->arr_elemts + i)->idx_prev_twin = -1;
     (tbl_elemts->arr_elemts + i)->idx_next_twin = -1;
     beg_elm_1 = (tbl_elemts->arr_elemts + i)->pos_begin;
     elemt_1 = tbl_elemts->str_of_set + beg_elm_1;
            len_elm_1 = (tbl_elemts->arr_elemts + i)->quantity_symb;
     for( j = (i + 1); j < N; j++ )
     {
  len_elm_2 = (tbl_elemts->arr_elemts + j)->quantity_symb;
         if( len_elm_1 == len_elm_2 )
         {
             beg_elm_2 = (tbl_elemts->arr_elemts + j)->pos_begin;
             elemt_2 = tbl_elemts->str_of_set + beg_elm_2;
             res = strncmp( elemt_1, elemt_2, len_elm_1 );
             if( !res )
             {
          (tbl_elemts->arr_elemts + j)->idx_prev_twin = adjac_twin;
   (tbl_elemts->arr_elemts + j)->idx_next_twin = -1;
   (tbl_elemts->arr_elemts + adjac_twin)->idx_next_twin = j;
   adjac_twin = j;
             }
         }
     }
 }
    }
    return 0;
}

canonical_original_code:
int search_twin_elemts_into_set(struct tabl_elemts_of_set *tbl_elemts)
{
    int i = 0;
    int j = 0;
    int N = 0;
    int res = 0;
    int len_elm_1 = 0;
    int len_elm_2 = 0;
    int beg_elm_1 = 0;
    int beg_elm_2 = 0;
    int adjac_twin = 0;
    char *elemt_1 = ((void *)0);
    char *elemt_2 = ((void *)0);
    N = tbl_elemts->total_numb;
    if( N == 0 ) return 0;
    for( i = 0; i < N; i++ )
    {
        if( ((tbl_elemts->arr_elemts + i)->idx_prev_twin) ==
     ((tbl_elemts->arr_elemts + i)->idx_next_twin)
   )
 {
     adjac_twin = i;
     (tbl_elemts->arr_elemts + i)->idx_prev_twin = -1;
     (tbl_elemts->arr_elemts + i)->idx_next_twin = -1;
     beg_elm_1 = (tbl_elemts->arr_elemts + i)->pos_begin;
     elemt_1 = tbl_elemts->str_of_set + beg_elm_1;
            len_elm_1 = (tbl_elemts->arr_elemts + i)->quantity_symb;
     for( j = (i + 1); j < N; j++ )
     {
  len_elm_2 = (tbl_elemts->arr_elemts + j)->quantity_symb;
         if( len_elm_1 == len_elm_2 )
         {
             beg_elm_2 = (tbl_elemts->arr_elemts + j)->pos_begin;
             elemt_2 = tbl_elemts->str_of_set + beg_elm_2;
             res = strncmp( elemt_1, elemt_2, len_elm_1 );
             if( !res )
             {
          (tbl_elemts->arr_elemts + j)->idx_prev_twin = adjac_twin;
   (tbl_elemts->arr_elemts + j)->idx_next_twin = -1;
   (tbl_elemts->arr_elemts + adjac_twin)->idx_next_twin = j;
   adjac_twin = j;
             }
         }
     }
 }
    }
    return 0;
}


RunErrorHandler

decompiled_code:
__int64 __fastcall RunErrorHandler(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 272);
if ( v1 )
{
*(_DWORD *)(a1 + 272) = v1 - 1;
syslog(3, "Errors encountered");
result = 0LL;
}
else
{
syslog(3, "Too many errors, closing connection");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 272);
if ( v1 )
{
*(_DWORD *)(a1 + 272) = v1 - 1;
syslog(3, "Errors encountered");
result = 0LL;
}
else
{
syslog(3, "Too many errors, closing connection");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int RunErrorHandler(struct Transaction *t)
{
  if ( t->errors ) {
    t->errors--;
    syslog(3,"Errors encountered");
    return 0;
  } else {
    syslog(3,"Too many errors, closing connection");
    return -1;
  }
}

variable_types: struct Transaction { int socket; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } *address; char client_name[256]; int errors; int file; long start_time; int byte_count; } *

user_defined_types: struct Transaction { int socket; struct sockaddr_storage *address; char client_name[256]; int errors; int file; long start_time; int byte_count; }


decompiled_code:
__int64 clean_up_child_process()
{
__int64 result; // rax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

wait((__WAIT_STATUS)&stat_loc);
result = LODWORD(stat_loc.__uptr);
child_exit_status = (int)stat_loc.__uptr;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

wait((__WAIT_STATUS)&stat_loc);
result = LODWORD(stat_loc.__uptr);
child_exit_status = (int)stat_loc.__uptr;
return result;
}

original_code:
void clean_up_child_process (int signal_number)
{
  int status;
  wait (&status);
  child_exit_status = status;
}

canonical_original_code:
void clean_up_child_process(int signal_number)
{
  int status;
  wait (&status);
  child_exit_status = status;
}

variable_types: status int


PrintTransactionTime

decompiled_code:
void __fastcall PrintTransactionTime(__int64 a1)
{
int v1; // eax
int v2; // ebx
int v3; // eax

v1 = time(0LL);
v2 = v1 - *(_DWORD *)(a1 + 280);
if ( v1 == *(_DWORD *)(a1 + 280) )
v2 = 1;
syslog(
3,
"%s: Transfer complete, %d bytes in %d seconds",
(const char *)(a1 + 16),
*(unsigned int *)(a1 + 288),
(unsigned int)v2);
v3 = *(_DWORD *)(a1 + 288) / v2;
if ( v3 > 1000000 )
{
syslog(3, "%d MB/s", (unsigned int)v3);
}
else if ( v3 <= 1000 )
{
syslog(3, "%d B/s", (unsigned int)v3);
}
else
{
syslog(3, "%d kB/s", (unsigned int)v3);
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
int v1; // eax
int v2; // ebx
int v3; // eax

v1 = time(0LL);
v2 = v1 - *(_DWORD *)(a1 + 280);
if ( v1 == *(_DWORD *)(a1 + 280) )
v2 = 1;
syslog(
3,
"%s: Transfer complete, %d bytes in %d seconds",
(const char *)(a1 + 16),
*(unsigned int *)(a1 + 288),
(unsigned int)v2);
v3 = *(_DWORD *)(a1 + 288) / v2;
if ( v3 > 1000000 )
{
syslog(3, "%d MB/s", (unsigned int)v3);
}
else if ( v3 <= 1000 )
{
syslog(3, "%d B/s", (unsigned int)v3);
}
else
{
syslog(3, "%d kB/s", (unsigned int)v3);
}
}

original_code:
static void PrintTransactionTime(struct Transaction *t)
{
  int diff = time(((void *)0)) - t->start_time;
  if ( diff == 0 )
    diff = 1;
  syslog(3,"%s: Transfer complete, %d bytes in %d seconds", t->client_name, t->byte_count, diff);
  int rate = t->byte_count / diff;
  if ( rate > 1000000 ) {
    syslog(3,"%d MB/s", rate);
  } else if ( rate > 1000 ) {
    syslog(3,"%d kB/s", rate);
  } else {
    syslog(3,"%d B/s", rate);
  }
}

variable_types: diff int

variable_types: rate int

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }


decompiled_code:
__int64 __fastcall Trans_SetupSocket(__int64 a1, _WORD *a2)
{
int v2; // eax
_WORD *v3; // rax
unsigned int v4; // ebp

*(_QWORD *)(a1 + 8) = a2;
v2 = socket(2, 2, 0);
*(_DWORD *)a1 = v2;
if ( v2 == -1 )
{
v4 = -1;
syslog(3, "listner: socket");
}
else
{
v3 = get_in_addr(a2);
inet_ntop((unsigned __int16)*a2, v3, (char *)(a1 + 16), 0x100u);
v4 = 0;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _WORD *a2)
{
int v2; // eax
_WORD *v3; // rax
unsigned int v4; // ebp

*(_QWORD *)(a1 + 8) = a2;
v2 = socket(2, 2, 0);
*(_DWORD *)a1 = v2;
if ( v2 == -1 )
{
v4 = -1;
syslog(3, "listner: socket");
}
else
{
v3 = get_in_addr(a2);
inet_ntop((unsigned __int16)*a2, v3, (char *)(a1 + 16), 0x100u);
v4 = 0;
}
return v4;
}

original_code:
int Trans_SetupSocket(struct Transaction *t, struct sockaddr_storage *address)
{
  t->address = address;
  if ((t->socket = socket(2, SOCK_DGRAM, IPPROTO_IP)) == -1) {
    syslog(3,"listner: socket");
    return -1;
  }
  inet_ntop(address->ss_family,get_in_addr((struct sockaddr *)address),t->client_name, sizeof (t->client_name));
  return 0;
}

variable_types:
address
struct sockaddr_storage *


decompiled_code:
ssize_t __fastcall TFTP_Send_Error(__int64 a1, int a2)
{
const struct sockaddr *v2; // rbp
size_t v3; // rax
char v5[4]; // [rsp+0h] [rbp-228h] BYREF
char dest[548]; // [rsp+4h] [rbp-224h] BYREF

v5[0] = 0;
v5[1] = 3;
v5[2] = 0;
v5[3] = a2;
strcpy(dest, (&ErrorMsg)[a2]);
v2 = *(const struct sockaddr **)(a1 + 8);
v3 = strlen(dest);
return sendto(*(_DWORD *)a1, v5, v3 + 5, 0, v2, 0x10u);
}

canonical_decompiled_code:
ssize_t __fastcall func5(__int64 a1, int a2)
{
const struct sockaddr *v2; // rbp
size_t v3; // rax
char v5[4]; // [rsp+0h] [rbp-228h] BYREF
char dest[548]; // [rsp+4h] [rbp-224h] BYREF

v5[0] = 0;
v5[1] = 3;
v5[2] = 0;
v5[3] = a2;
strcpy(dest, (&ErrorMsg)[a2]);
v2 = *(const struct sockaddr **)(a1 + 8);
v3 = strlen(dest);
return sendto(*(_DWORD *)a1, v5, v3 + 5, 0, v2, 0x10u);
}

original_code:
void TFTP_Send_Error(struct Transaction *t, int error_type)
{
  char buf[(512+2+2)];
  buf[0] = 0;
  buf[1] = 3;
  buf[2] = 0;
  buf[3] = error_type;
  strcpy(buf+4, ErrorMsg[error_type]);
  sendto(t->socket, buf, strlen(buf+4)+5, 0, (const struct sockaddr *) t->address, sizeof(struct sockaddr));
}

canonical_original_code:
void TFTP_Send_Error(struct Transaction *t, int error_type)
{
  char buf[-1];
  buf[0] = 0;
  buf[1] = 3;
  buf[2] = 0;
  buf[3] = error_type;
  strcpy(buf+4, ErrorMsg[error_type]);
  sendto(t->socket, buf, strlen(buf+4)+5, 0, (struct sockaddr *) t->address, sizeof(struct sockaddr));
}

variable_types:
buf
char [-1]