sortTags

decompiled_code:
__int64 __fastcall sortTags(__int64 a1)
{
int v1; // edx
__int64 v2; // rcx
__int64 v3; // rax
__int64 v4; // rdi
__int64 v5; // rcx

qsort(*(void **)(a1 + 16), *(int *)(a1 + 24), 0x10uLL, (__compar_fn_t)compareEventTags);
v1 = *(_DWORD *)(a1 + 24);
if ( v1 <= 1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 16);
v3 = v2 + 16;
v4 = v2 + 16LL * (unsigned int)(v1 - 2) + 32;
while ( 1 )
{
v5 = *(unsigned int *)(v3 - 16);
if ( *(_DWORD *)v3 == (_DWORD)v5 )
break;
v3 += 16LL;
if ( v3 == v4 )
return 0LL;
}
fprintf(
stderr,
"%s: duplicate tag entries (%d:%s and %d:%s)\n",
"EventTagMap",
v5,
*(const char **)(v3 + 8),
(unsigned int)v5,
*(const char **)(v3 - 8));
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // edx
__int64 v2; // rcx
__int64 v3; // rax
__int64 v4; // rdi
__int64 v5; // rcx

qsort(*(void **)(a1 + 16), *(int *)(a1 + 24), 0x10uLL, (__compar_fn_t)compareEventTags);
v1 = *(_DWORD *)(a1 + 24);
if ( v1 <= 1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 16);
v3 = v2 + 16;
v4 = v2 + 16LL * (unsigned int)(v1 - 2) + 32;
while ( 1 )
{
v5 = *(unsigned int *)(v3 - 16);
if ( *(_DWORD *)v3 == (_DWORD)v5 )
break;
v3 += 16LL;
if ( v3 == v4 )
return 0LL;
}
fprintf(
stderr,
"%s: duplicate tag entries (%d:%s and %d:%s)\n",
"EventTagMap",
v5,
*(const char **)(v3 + 8),
(unsigned int)v5,
*(const char **)(v3 - 8));
return 0xFFFFFFFFLL;
}

original_code:
static int sortTags(EventTagMap* map)
{
    int i;
    qsort(map->tagArray, map->numTags, sizeof(EventTag), compareEventTags);
    for (i = 1; i < map->numTags; i++) {
        if (map->tagArray[i].tagIndex == map->tagArray[i-1].tagIndex) {
            fprintf(stderr, "%s: duplicate tag entries (%d:%s and %d:%s)\n",
                "EventTagMap",
                map->tagArray[i].tagIndex, map->tagArray[i].tagStr,
                map->tagArray[i-1].tagIndex, map->tagArray[i-1].tagStr);
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
static int sortTags(struct EventTagMap *map)
{
    int i;
    qsort(map->tagArray, map->numTags, sizeof(EventTag), compareEventTags);
    for (i = 1; i < map->numTags; i++) {
        if (map->tagArray[i].tagIndex == map->tagArray[i-1].tagIndex) {
            fprintf(stderr, "%s: duplicate tag entries (%d:%s and %d:%s)\n",
                "EventTagMap",
                map->tagArray[i].tagIndex, map->tagArray[i].tagStr,
                map->tagArray[i-1].tagIndex, map->tagArray[i-1].tagStr);
            return -1;
        }
    }
    return 0;
}

variable_types: i int


repo: ykli/misc

decompiled_code:
void __fastcall android_closeEventTagMap(void *ptr)
{
if ( ptr )
{
munmap(*(void **)ptr, *((_QWORD *)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
if ( ptr )
{
munmap(*(void **)ptr, *((_QWORD *)ptr + 1));
free(ptr);
}
}

original_code:
void android_closeEventTagMap(EventTagMap* map)
{
    if (map == ((void *)0))
        return;
    munmap(map->mapAddr, map->mapLen);
    free(map);
}

canonical_original_code:
void android_closeEventTagMap(struct EventTagMap *map)
{
    if (map == ((void *)0))
        return;
    munmap(map->mapAddr, map->mapLen);
    free(map);
}

variable_types: struct EventTagMap { void *mapAddr; unsigned long mapLen; struct EventTag { unsigned int tagIndex; char *tagStr; } *tagArray; int numTags; } *

return_type: void

user_defined_types: struct EventTagMap { void *mapAddr; unsigned long mapLen; struct EventTag *tagArray; int numTags; }


original_code:
const char* android_lookupEventTag(const EventTagMap* map, int tag)
{
    int hi, lo, mid;
    lo = 0;
    hi = map->numTags-1;
    while (lo <= hi) {
        int cmp;
        mid = (lo+hi)/2;
        cmp = map->tagArray[mid].tagIndex - tag;
        if (cmp < 0) {
            lo = mid + 1;
        } else if (cmp > 0) {
            hi = mid - 1;
        } else {
            return map->tagArray[mid].tagStr;
        }
    }
    return ((void *)0);
}

canonical_original_code:
char *android_lookupEventTag(struct EventTagMap *map, int tag)
{
    int hi; int lo; int mid;
    lo = 0;
    hi = map->numTags-1;
    while (lo <= hi) {
        int cmp;
        mid = (lo+hi)/2;
        cmp = map->tagArray[mid].tagIndex - tag;
        if (cmp < 0) {
            lo = mid + 1;
        } else if (cmp > 0) {
            hi = mid - 1;
        } else {
            return map->tagArray[mid].tagStr;
        }
    }
    return ((void *)0);
}

variable_types: tag int

variable_types: hi int

variable_types: lo int

variable_types: mid int

variable_types: cmp int

return_type: char *

user_defined_types: struct EventTag { unsigned int tagIndex; char *tagStr; }


original_code:
__inline static void fft_proc(coef_t *xr,
                            coef_t *xi,
                            fftfloat *refac,
                            fftfloat *imfac,
                            int32_t size)
{
    register int32_t step, shift, pos;
    register int32_t x1;
    register int32_t x2;
    int32_t exp, estep;
    int64_t v2r, v2i;
    estep = size;
    for (step = 1; step < size; step = (step<<1)) {
        x2 = 0;
        estep >>= 1;
        for (pos = 0; pos < size; pos += (step<<1)) {
            x1 = x2;
            x2 += step;
            exp = 0;
            for (shift = 0; shift < step; shift++) {
                v2r = (real_t)(((int64_t)(xr[x2])*(refac[exp])) >> 16) - (real_t)(((int64_t)(xi[x2])*(imfac[exp])) >> 16);
                v2i = (real_t)(((int64_t)(xr[x2])*(imfac[exp])) >> 16) + (real_t)(((int64_t)(xi[x2])*(refac[exp])) >> 16);
                xr[x2] = xr[x1] - v2r;
                xr[x1] += v2r;
                xi[x2] = xi[x1] - v2i;
                xi[x1] += v2i;
                exp += estep;
                x1++;
                x2++;
            }
        }
    }
}

canonical_original_code:
__inline static void fft_proc(int *xr, int *xi, int *refac, int *imfac, int size)
{
    register int step; register int shift; register int pos;
    register int x1;
    register int x2;
    int exp; int estep;
    long v2r; long v2i;
    estep = size;
    for (step = 1; step < size; step = (step<<1)) {
        x2 = 0;
        estep >>= 1;
        for (pos = 0; pos < size; pos += (step<<1)) {
            x1 = x2;
            x2 += step;
            exp = 0;
            for (shift = 0; shift < step; shift++) {
                v2r = (real_t)(((long)(xr[x2])*(refac[exp])) >> 16) - (real_t)(((long)(xi[x2])*(imfac[exp])) >> 16);
                v2i = (real_t)(((long)(xr[x2])*(imfac[exp])) >> 16) + (real_t)(((long)(xi[x2])*(refac[exp])) >> 16);
                xr[x2] = xr[x1] - v2r;
                xr[x1] += v2r;
                xi[x2] = xi[x1] - v2i;
                xi[x1] += v2i;
                exp += estep;
                x1++;
                x2++;
            }
        }
    }
}

variable_types:
xr
int *

variable_types:
xi
int *

variable_types:
refac
int *

variable_types:
imfac
int *

variable_types: size int

variable_types: step int

variable_types: shift int

variable_types: pos int

variable_types: exp int

variable_types: estep int


decompiled_code:
void __fastcall fft_terminate(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
}

original_code:
void fft_terminate( FFT_Tables *fft_tables )
{
    fft_tables->costbl = ((void *)0);
    fft_tables->negsintbl = ((void *)0);
    fft_tables->reordertbl = ((void *)0);
    if ( fft_tables->reordertbl )
        free(fft_tables->reordertbl);
}

canonical_original_code:
void fft_terminate(struct FFT_Tables *fft_tables)
{
    fft_tables->costbl = ((void *)0);
    fft_tables->negsintbl = ((void *)0);
    fft_tables->reordertbl = ((void *)0);
    if ( fft_tables->reordertbl )
        free(fft_tables->reordertbl);
}

variable_types: struct FFT_Tables { int *costbl; int *negsintbl; unsigned short *reordertbl; } *


fft

original_code:
void fft( FFT_Tables *fft_tables, coef_t *xr, coef_t *xi, int32_t logm)
{
    reorder( fft_tables, xr, logm);
    reorder( fft_tables, xi, logm);
    fft_proc( xr, xi, fft_tables->costbl, fft_tables->negsintbl, 1 << logm );
}

canonical_original_code:
void fft(struct FFT_Tables *fft_tables, int *xr, int *xi, int logm)
{
    reorder( fft_tables, xr, logm);
    reorder( fft_tables, xi, logm);
    fft_proc( xr, xi, fft_tables->costbl, fft_tables->negsintbl, 1 << logm );
}

variable_types: logm int

user_defined_types: struct FFT_Tables { int *costbl; int *negsintbl; unsigned short *reordertbl; }


original_code:
static void Sid_Sync_reset( enc_interface_State *st )
{
   st->sid_update_counter = 3;
   st->sid_handover_debt = 0;
   st->prev_ft = TX_SPEECH_GOOD;
}

canonical_original_code:
static void Sid_Sync_reset(struct enc_interface_State *st)
{
   st->sid_update_counter = 3;
   st->sid_handover_debt = 0;
   st->prev_ft = TX_SPEECH_GOOD;
}

variable_types: struct enc_interface_State { short sid_update_counter; short sid_handover_debt; long dtx; enum TXFrameType { TX_SPEECH_GOOD=0, TX_SID_FIRST=1, TX_SID_UPDATE=2, TX_NO_DATA=3, TX_SPEECH_DEGRADED=4, TX_SPEECH_BAD=5, TX_SID_BAD=6, TX_ONSET=7, TX_N_FRAMETYPES=8 } prev_ft; void *encoderState; } *

user_defined_types: struct enc_interface_State { short sid_update_counter; short sid_handover_debt; long dtx; enum TXFrameType prev_ft; void *encoderState; }


EncoderMMS

original_code:
static int EncoderMMS( enum Mode mode, Word16 *param, UWord8 *stream, enum
      TXFrameType frame_type, enum Mode speech_mode )
{
   Word32 j = 0, k;
   Word16 *mask;
   int resultFrameSize = block_size[mode] - !EncoderIncludeHeaderByte;
   memset(stream, 0, resultFrameSize);
   if (EncoderIncludeHeaderByte) {
     *stream = toc_byte[mode];
     stream++;
   }
   if ( mode == 15 ) {
      return 1;
   }
   else if ( mode == MRDTX ) {
      mask = order_MRDTX;
      for ( j = 1; j < 36; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
      if ( frame_type == TX_SID_UPDATE )
         *stream += 0x01;
      *stream <<= 3;
      *stream += ( unsigned char )(speech_mode & 0x0007);
   *stream <<= 1;
      return 6;
   }
   else if ( mode == MR475 ) {
      mask = order_MR475;
      for ( j = 1; j < 96; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR515 ) {
      mask = order_MR515;
      for ( j = 1; j < 104; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR59 ) {
      mask = order_MR59;
      for ( j = 1; j < 119; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR67 ) {
      mask = order_MR67;
      for ( j = 1; j < 135; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR74 ) {
      mask = order_MR74;
      for ( j = 1; j < 149; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR795 ) {
      mask = order_MR795;
      for ( j = 1; j < 160; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR102 ) {
      mask = order_MR102;
      for ( j = 1; j < 205; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR122 ) {
      mask = order_MR122;
      for ( j = 1; j < 245; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   if ( (k = (j % 8)) )
       *stream <<= ( 8 - k );
   return resultFrameSize;
}

canonical_original_code:
static int EncoderMMS(enum Mode mode, short *param, unsigned char *stream, enum TXFrameType frame_type, enum Mode speech_mode)
{
   long j = 0; long k;
   short *mask;
   int resultFrameSize = block_size[mode] - !EncoderIncludeHeaderByte;
   memset(stream, 0, resultFrameSize);
   if (EncoderIncludeHeaderByte) {
     *stream = toc_byte[mode];
     stream++;
   }
   if ( mode == 15 ) {
      return 1;
   }
   else if ( mode == MRDTX ) {
      mask = order_MRDTX;
      for ( j = 1; j < 36; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
      if ( frame_type == TX_SID_UPDATE )
         *stream += 0x01;
      *stream <<= 3;
      *stream += ( unsigned char )(speech_mode & 0x0007);
   *stream <<= 1;
      return 6;
   }
   else if ( mode == MR475 ) {
      mask = order_MR475;
      for ( j = 1; j < 96; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR515 ) {
      mask = order_MR515;
      for ( j = 1; j < 104; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR59 ) {
      mask = order_MR59;
      for ( j = 1; j < 119; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR67 ) {
      mask = order_MR67;
      for ( j = 1; j < 135; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR74 ) {
      mask = order_MR74;
      for ( j = 1; j < 149; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR795 ) {
      mask = order_MR795;
      for ( j = 1; j < 160; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR102 ) {
      mask = order_MR102;
      for ( j = 1; j < 205; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   else if ( mode == MR122 ) {
      mask = order_MR122;
      for ( j = 1; j < 245; j++ ) {
         if ( param[ * mask] & *( mask + 1 ) )
            *stream += 0x01;
         mask += 2;
         if ( j % 8 )
            *stream <<= 1;
         else
            stream++;
      }
   }
   if ( (k = (j % 8)) )
       *stream <<= ( 8 - k );
   return resultFrameSize;
}

variable_types:
param
short *

variable_types:
stream
unsigned char *

variable_types: enum TXFrameType { TX_SPEECH_GOOD=0, TX_SID_FIRST=1, TX_SID_UPDATE=2, TX_NO_DATA=3, TX_SPEECH_DEGRADED=4, TX_SPEECH_BAD=5, TX_SID_BAD=6, TX_ONSET=7, TX_N_FRAMETYPES=8 }

variable_types: j long

variable_types: k long

variable_types:
mask
short *

variable_types: resultFrameSize int

return_type: int


original_code:
int Encoder_Interface_Encode( void *st, enum Mode mode, Word16 *speech,
      UWord8 *serial,
      int force_speech )
{
   Word16 prm[57];
   const Word16 *homing;
   Word16 homing_size;
   enc_interface_State * s;
   enum TXFrameType txFrameType;
   int i, noHoming = 0;
   enum Mode used_mode = -force_speech;
   memset(prm,0,sizeof(Word16)*57);
   s = ( enc_interface_State * )st;
   for ( i = 0; i < 160; i++ ) {
      noHoming = speech[i] ^ 0x0008;
      if ( noHoming )
         break;
   }
   if (noHoming){
      Speech_Encode_Frame( s->encoderState, mode, speech, prm, &used_mode );
   }
   else {
      switch ( mode ) {
         case MR122:
            homing = dhf_MR122;
            homing_size = 18;
            break;
         case MR102:
            homing = dhf_MR102;
            homing_size = 12;
            break;
         case MR795:
            homing = dhf_MR795;
            homing_size = 8;
            break;
         case MR74:
            homing = dhf_MR74;
            homing_size = 7;
            break;
         case MR67:
            homing = dhf_MR67;
            homing_size = 7;
            break;
         case MR59:
            homing = dhf_MR59;
            homing_size = 7;
            break;
         case MR515:
            homing = dhf_MR515;
            homing_size = 7;
            break;
         case MR475:
            homing = dhf_MR475;
            homing_size = 7;
            break;
         default:
            homing = ((void *)0);
            homing_size = 0;
            break;
      }
      for( i = 0; i < homing_size; i++){
         prm[i] = homing[i];
      }
      memset(&prm[homing_size], 0, (57 - homing_size)*sizeof(Word16));
      used_mode = mode;
   }
   if ( used_mode == MRDTX ) {
      s->sid_update_counter--;
      if ( s->prev_ft == TX_SPEECH_GOOD ) {
         txFrameType = TX_SID_FIRST;
         s->sid_update_counter = 3;
      }
      else {
         if ( ( s->sid_handover_debt > 0 ) && ( s->sid_update_counter > 2 ) ) {
            txFrameType = TX_SID_UPDATE;
            s->sid_handover_debt--;
         }
         else {
            if ( s->sid_update_counter == 0 ) {
               txFrameType = TX_SID_UPDATE;
               s->sid_update_counter = 8;
            }
            else {
               txFrameType = TX_NO_DATA;
               used_mode = 15;
            }
         }
      }
   }
   else {
      s->sid_update_counter = 8;
      txFrameType = TX_SPEECH_GOOD;
   }
   s->prev_ft = txFrameType;
   if ( noHoming == 0 ) {
      Speech_Encode_Frame_reset( s->encoderState, s->dtx );
      Sid_Sync_reset( s );
   }
   return EncoderMMS( used_mode, prm, serial, txFrameType, mode );
}

canonical_original_code:
int Encoder_Interface_Encode(void *st, enum Mode mode, short *speech, unsigned char *serial, int force_speech)
{
   short prm[57];
   short *homing;
   short homing_size;
   struct enc_interface_State *s;
   enum TXFrameType txFrameType;
   int i; int noHoming = 0;
   enum Mode used_mode = -force_speech;
   memset(prm,0,sizeof(Word16)*57);
   s = ( struct enc_interface_State * )st;
   for ( i = 0; i < 160; i++ ) {
      noHoming = speech[i] ^ 0x0008;
      if ( noHoming )
         break;
   }
   if (noHoming){
      Speech_Encode_Frame( s->encoderState, mode, speech, prm, &used_mode );
   }
   else {
      switch ( mode ) {
         case MR122:
            homing = dhf_MR122;
            homing_size = 18;
            break;
         case MR102:
            homing = dhf_MR102;
            homing_size = 12;
            break;
         case MR795:
            homing = dhf_MR795;
            homing_size = 8;
            break;
         case MR74:
            homing = dhf_MR74;
            homing_size = 7;
            break;
         case MR67:
            homing = dhf_MR67;
            homing_size = 7;
            break;
         case MR59:
            homing = dhf_MR59;
            homing_size = 7;
            break;
         case MR515:
            homing = dhf_MR515;
            homing_size = 7;
            break;
         case MR475:
            homing = dhf_MR475;
            homing_size = 7;
            break;
         default:
            homing = ((void *)0);
            homing_size = 0;
            break;
      }
      for( i = 0; i < homing_size; i++){
         prm[i] = homing[i];
      }
      memset(&prm[homing_size], 0, (57 - homing_size)*sizeof(Word16));
      used_mode = mode;
   }
   if ( used_mode == MRDTX ) {
      s->sid_update_counter--;
      if ( s->prev_ft == TX_SPEECH_GOOD ) {
         txFrameType = TX_SID_FIRST;
         s->sid_update_counter = 3;
      }
      else {
         if ( ( s->sid_handover_debt > 0 ) && ( s->sid_update_counter > 2 ) ) {
            txFrameType = TX_SID_UPDATE;
            s->sid_handover_debt--;
         }
         else {
            if ( s->sid_update_counter == 0 ) {
               txFrameType = TX_SID_UPDATE;
               s->sid_update_counter = 8;
            }
            else {
               txFrameType = TX_NO_DATA;
               used_mode = 15;
            }
         }
      }
   }
   else {
      s->sid_update_counter = 8;
      txFrameType = TX_SPEECH_GOOD;
   }
   s->prev_ft = txFrameType;
   if ( noHoming == 0 ) {
      Speech_Encode_Frame_reset( s->encoderState, s->dtx );
      Sid_Sync_reset( s );
   }
   return EncoderMMS( used_mode, prm, serial, txFrameType, mode );
}

variable_types:
st
void *

variable_types:
speech
short *

variable_types:
serial
unsigned char *

variable_types:
prm
short [57]

variable_types:
homing
short *

variable_types: i int

variable_types: noHoming int

user_defined_types: enum TXFrameType { TX_SPEECH_GOOD=0, TX_SID_FIRST=1, TX_SID_UPDATE=2, TX_NO_DATA=3, TX_SPEECH_DEGRADED=4, TX_SPEECH_BAD=5, TX_SID_BAD=6, TX_ONSET=7, TX_N_FRAMETYPES=8 }


decompiled_code:
void __fastcall Encoder_Interface_exit(void *ptr)
{
Speech_Encode_Frame_exit((char *)ptr + 24);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
Speech_Encode_Frame_exit((char *)ptr + 24);
free(ptr);
}

original_code:
void Encoder_Interface_exit( void *state )
{
   enc_interface_State * s;
   s = ( enc_interface_State * )state;
   Speech_Encode_Frame_exit( &s->encoderState );
   free( s );
   state = ((void *)0);
}

canonical_original_code:
void Encoder_Interface_exit(void *state)
{
   struct enc_interface_State *s;
   s = ( struct enc_interface_State * )state;
   Speech_Encode_Frame_exit( &s->encoderState );
   free( s );
   state = ((void *)0);
}

variable_types:
state
void *


GetSRIndex

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

result = 0LL;
if ( a1 <= 0x16770 )
{
result = 1LL;
if ( a1 <= 0x1257B )
{
result = 2LL;
if ( a1 <= 0xD881 )
{
result = 3LL;
if ( a1 <= 0xB3B8 )
{
result = 4LL;
if ( a1 <= 0x92BD )
{
result = 5LL;
if ( a1 <= 0x6C40 )
{
result = 6LL;
if ( a1 <= 0x59DB )
{
result = 7LL;
if ( a1 <= 0x495E )
{
result = 8LL;
if ( a1 <= 0x361F )
{
result = 9LL;
if ( a1 <= 0x2CED )
result = (unsigned int)(a1 < 0x24AF) + 10;
}
}
}
}
}
}
}
}
}
return result;
}

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

result = 0LL;
if ( a1 <= 0x16770 )
{
result = 1LL;
if ( a1 <= 0x1257B )
{
result = 2LL;
if ( a1 <= 0xD881 )
{
result = 3LL;
if ( a1 <= 0xB3B8 )
{
result = 4LL;
if ( a1 <= 0x92BD )
{
result = 5LL;
if ( a1 <= 0x6C40 )
{
result = 6LL;
if ( a1 <= 0x59DB )
{
result = 7LL;
if ( a1 <= 0x495E )
{
result = 8LL;
if ( a1 <= 0x361F )
{
result = 9LL;
if ( a1 <= 0x2CED )
result = (unsigned int)(a1 < 0x24AF) + 10;
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
int32_t GetSRIndex(uint32_t sampleRate)
{
    if (92017 <= sampleRate) return 0;
    if (75132 <= sampleRate) return 1;
    if (55426 <= sampleRate) return 2;
    if (46009 <= sampleRate) return 3;
    if (37566 <= sampleRate) return 4;
    if (27713 <= sampleRate) return 5;
    if (23004 <= sampleRate) return 6;
    if (18783 <= sampleRate) return 7;
    if (13856 <= sampleRate) return 8;
    if (11502 <= sampleRate) return 9;
    if (9391 <= sampleRate) return 10;
    return 11;
}

canonical_original_code:
int GetSRIndex(unsigned int sampleRate)
{
    if (92017 <= sampleRate) return 0;
    if (75132 <= sampleRate) return 1;
    if (55426 <= sampleRate) return 2;
    if (46009 <= sampleRate) return 3;
    if (37566 <= sampleRate) return 4;
    if (27713 <= sampleRate) return 5;
    if (23004 <= sampleRate) return 6;
    if (18783 <= sampleRate) return 7;
    if (13856 <= sampleRate) return 8;
    if (11502 <= sampleRate) return 9;
    if (9391 <= sampleRate) return 10;
    return 11;
}

variable_types:
sampleRate
unsigned int


MaxBitrate

variable_types:
sampleRate
unsigned long

return_type: unsigned int


MinBitrate

decompiled_code:
__int64 MinBitrate()
{
return 8000LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 8000LL;
}

original_code:
uint32_t MinBitrate()
{
    return 8000;
}

canonical_original_code:
unsigned int MinBitrate()
{
    return 8000;
}


GetMaxPredSfb

decompiled_code:
__int64 __fastcall GetMaxPredSfb(int a1)
{
return (unsigned int)MaxPredSfb[a1];
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return (unsigned int)MaxPredSfb[a1];
}

original_code:
int32_t GetMaxPredSfb(int32_t samplingRateIdx)
{
    return MaxPredSfb[samplingRateIdx];
}

canonical_original_code:
int GetMaxPredSfb(int samplingRateIdx)
{
    return MaxPredSfb[samplingRateIdx];
}

variable_types: samplingRateIdx int


MaxBitresSize

decompiled_code:
__int64 __fastcall MaxBitresSize(__int64 a1, __int64 a2)
{
return 6144 - (unsigned int)(((a1 << 16) / (unsigned __int64)(a2 << 10)) >> 16);
}

original_code:
uint32_t MaxBitresSize(ulong_t bitRate, ulong_t sampleRate)
{
    return 6144 - (((((real_t)(bitRate))<<16)/(sampleRate<<10))>>(16));
}

canonical_original_code:
unsigned int MaxBitresSize(unsigned long bitRate, unsigned long sampleRate)
{
    return 6144 - (((((real_t)(bitRate))<<16)/(sampleRate<<10))>>(16));
}

variable_types:
bitRate
unsigned long


decompiled_code:
__int64 __fastcall str_to_binary(_BYTE *a1)
{
_BYTE *v1; // rcx
__int64 result; // rax

v1 = a1 + 32;
LODWORD(result) = 0;
do
{
result = (unsigned int)(2 * result);
if ( *a1 == 49 )
result = (unsigned int)result | 1;
++a1;
}
while ( a1 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1)
{
_BYTE *v1; // rcx
__int64 result; // rax

v1 = a1 + 32;
LODWORD(result) = 0;
do
{
result = (unsigned int)(2 * result);
if ( *a1 == 49 )
result = (unsigned int)result | 1;
++a1;
}
while ( a1 != v1 );
return result;
}

original_code:
int str_to_binary(char * str_val)
{
 int i, val = 0;
 for (i = 0; i < 32; i++) {
  val = val<<1;
  if (str_val[i] == '1')
   val |= 1;
 }
 return val;
}

canonical_original_code:
int str_to_binary(char *str_val)
{
 int i; int val = 0;
 for (i = 0; i < 32; i++) {
  val = val<<1;
  if (str_val[i] == '1')
   val |= 1;
 }
 return val;
}

variable_types: val int


decompiled_code:
double __fastcall timestamp_diff_in_seconds(int a1, __int64 a2, int a3, __int64 a4)
{
int v4; // er8
int v5; // eax

v4 = a3 - a1;
v5 = a4 - a2;
if ( a4 - a2 < 0 )
{
--v4;
v5 = a4 + 1000000000 - a2;
}
return (double)v5 * 0.000000001 + (double)v4;
}

original_code:
static double timestamp_diff_in_seconds(timestamp_type start, timestamp_type end)
{
  struct timespec temp;
  if ((end.tv_nsec-start.tv_nsec)<0) {
    temp.tv_sec = end.tv_sec-start.tv_sec-1;
    temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
  } else {
    temp.tv_sec = end.tv_sec-start.tv_sec;
    temp.tv_nsec = end.tv_nsec-start.tv_nsec;
  }
  return temp.tv_sec + 1e-9*temp.tv_nsec;
}

canonical_original_code:
static double timestamp_diff_in_seconds(struct timespec start, struct timespec end)
{
  struct timespec temp;
  if ((end.tv_nsec-start.tv_nsec)<0) {
    temp.tv_sec = end.tv_sec-start.tv_sec-1;
    temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
  } else {
    temp.tv_sec = end.tv_sec-start.tv_sec;
    temp.tv_nsec = end.tv_nsec-start.tv_nsec;
  }
  return temp.tv_sec + 1e-9*temp.tv_nsec;
}

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

variable_types:
end
struct timespec

return_type: double


decompiled_code:
int __fastcall get_timestamp(struct timespec *tp)
{
return clock_gettime(0, tp);
}

canonical_decompiled_code:
int __fastcall func8(struct timespec *tp)
{
return clock_gettime(0, tp);
}

original_code:
static void get_timestamp(timestamp_type *t)
{
  clock_gettime(0, t);
}

canonical_original_code:
static void get_timestamp(struct timespec *t)
{
  clock_gettime(0, t);
}

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


decompiled_code:
int __fastcall print_array(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx
int result; // eax

if ( a2 > 0 )
{
v2 = a1;
do
result = printf("%d\n", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx
int result; // eax

if ( a2 > 0 )
{
v2 = a1;
do
result = printf("%d\n", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return result;
}

original_code:
void print_array(int *a, const int n) {
  for (int i = 0; i < n; i++) {
    printf("%d\n", a[i]);
  }
}

canonical_original_code:
void print_array(int *a, int n) {
  for (int i = 0; i < n; i++) {
    printf("%d\n", a[i]);
  }
}

variable_types:
a
int *

variable_types: n int


bits

decompiled_code:
__int64 __fastcall bits(unsigned int a1, char a2, char a3)
{
return (a1 >> a2) & ~(-1 << a3);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, char a2, char a3)
{
return (a1 >> a2) & ~(-1 << a3);
}

original_code:
unsigned bits(unsigned x, int k, int j) {
  return (x >> k) & ~(~0 << j);
}

canonical_original_code:
unsigned int bits(unsigned int x, int k, int j) {
  return (x >> k) & ~(~0 << j);
}

variable_types:
x
unsigned int

variable_types: k int

variable_types: j int


original_code:
void radix_sort(int *a, const int n) {
  int* t = malloc(n*sizeof(int));
  int count[(1 << 8)];
  for (int pass = 0; pass < 32/8; pass++) {
    for (int j = 0; j < (1 << 8); j++) count[j] = 0;
    for (int i = 0; i < n; i++) {
      count[bits(a[i], pass*8, 8)]++;
    }
    for (int j = 1; j < (1 << 8); j++) {
      count[j] = count[j-1] + count[j];
    }
    for (int i = n-1; i >= 0; i--) {
      int idx = --count[bits(a[i], pass*8, 8)];
      t[idx] = a[i];
    }
    for (int i = 0; i < n; i++) a[i] = t[i];
  }
  free(t);
}

canonical_original_code:
void radix_sort(int *a, int n) {
  int *t = malloc(n*sizeof(int));
  int count[-1];
  for (int pass = 0; pass < 32/8; pass++) {
    for (int j = 0; j < (1 << 8); j++) count[j] = 0;
    for (int i = 0; i < n; i++) {
      count[bits(a[i], pass*8, 8)]++;
    }
    for (int j = 1; j < (1 << 8); j++) {
      count[j] = count[j-1] + count[j];
    }
    for (int i = n-1; i >= 0; i--) {
      int idx = --count[bits(a[i], pass*8, 8)];
      t[idx] = a[i];
    }
    for (int i = 0; i < n; i++) a[i] = t[i];
  }
  free(t);
}

variable_types:
t
int *

variable_types:
count
int [-1]

variable_types: pass int

variable_types: idx int


usage

decompiled_code:
size_t usage()
{
fwrite("Incorrect usage!\n", 1uLL, 0x11uLL, stderr);
fwrite("Usage: radix_sort [f] [n]\n", 1uLL, 0x1AuLL, stderr);
fwrite(" [f] - input file to be sorted\n", 1uLL, 0x20uLL, stderr);
fwrite(" [n] - number of elements in the file\n", 1uLL, 0x27uLL, stderr);
return fwrite(" [r] - print sorted results 0/1, 0 by default\n", 1uLL, 0x2FuLL, stderr);
}

canonical_decompiled_code:
size_t func9()
{
fwrite("Incorrect usage!\n", 1uLL, 0x11uLL, stderr);
fwrite("Usage: radix_sort [f] [n]\n", 1uLL, 0x1AuLL, stderr);
fwrite(" [f] - input file to be sorted\n", 1uLL, 0x20uLL, stderr);
fwrite(" [n] - number of elements in the file\n", 1uLL, 0x27uLL, stderr);
return fwrite(" [r] - print sorted results 0/1, 0 by default\n", 1uLL, 0x2FuLL, stderr);
}

original_code:
void usage() {
  fprintf(stderr, "Incorrect usage!\n");
  fprintf(stderr, "Usage: radix_sort [f] [n]\n");
  fprintf(stderr, "  [f] - input file to be sorted\n");
  fprintf(stderr, "  [n] - number of elements in the file\n");
  fprintf(stderr, "  [r] - print sorted results 0/1, 0 by default\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // ebx
unsigned int *v5; // r13
int v6; // er12
double v7; // rbp
struct timespec v9; // [rsp+0h] [rbp-48h] BYREF
struct timespec tp; // [rsp+10h] [rbp-38h] BYREF

if ( argc <= 2 )
{
usage();
v6 = 1;
}
else
{
v3 = 0;
if ( argc > 3 )
v3 = atoi(argv[3]);
v4 = atoi(argv[2]);
v5 = (unsigned int *)malloc(4LL * v4);
v6 = init_array(argv[1], 0, v4, (__int64)v5);
if ( v6 )
{
printf("File %s could not be opened!\n", argv[1]);
v6 = 1;
}
else
{
get_timestamp(&tp);
radix_sort(v5, v4);
get_timestamp(&v9);
v7 = timestamp_diff_in_seconds(tp.tv_sec, tp.tv_nsec, v9.tv_sec, v9.tv_nsec);
printf("%f s\n", v7);
printf("%d elements sorted\n", (unsigned int)v4);
printf("%f elements/s\n", (double)v4 / v7);
if ( v3 )
print_array(v5, v4);
free(v5);
}
}
return v6;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // ebx
unsigned int *v5; // r13
int v6; // er12
double v7; // rbp
struct timespec v9; // [rsp+0h] [rbp-48h] BYREF
struct timespec tp; // [rsp+10h] [rbp-38h] BYREF

if ( argc <= 2 )
{
func9();
v6 = 1;
}
else
{
v3 = 0;
if ( argc > 3 )
v3 = atoi(argv[3]);
v4 = atoi(argv[2]);
v5 = (unsigned int *)malloc(4LL * v4);
v6 = func11(argv[1], 0, v4, (__int64)v5);
if ( v6 )
{
printf("File %s could not be opened!\n", argv[1]);
v6 = 1;
}
else
{
func8(&tp);
func13(v5, v4);
func8(&v9);
v7 = func7(tp.tv_sec, tp.tv_nsec, v9.tv_sec, v9.tv_nsec);
printf("%f s\n", v7);
printf("%d elements sorted\n", (unsigned int)v4);
printf("%f elements/s\n", (double)v4 / v7);
if ( v3 )
func10(v5, v4);
free(v5);
}
}
return v6;
}

original_code:
int main(int argc, char** argv)
{
  int print_results = 0;
  if (argc < 3) {
    usage();
    return 1;
  } else if (argc > 3) {
    print_results = atoi(argv[3]);
  }
  const int n = atoi(argv[2]);
  int* a = malloc(sizeof(int) * n);
  if (init_array(argv[1], 0, n, &a[0]) != 0) {
    printf("File %s could not be opened!\n", argv[1]);
    return 1;
  }
  timestamp_type time1, time2;
  get_timestamp(&time1);
  radix_sort(&a[0], n);
  get_timestamp(&time2);
  double elapsed = timestamp_diff_in_seconds(time1,time2);
  printf("%f s\n", elapsed);
  printf("%d elements sorted\n", n);
  printf("%f elements/s\n", n / elapsed);
  if (print_results) {
    print_array(&a[0], n);
  }
  free(a);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int print_results = 0;
  if (argc < 3) {
    usage();
    return 1;
  } else if (argc > 3) {
    print_results = atoi(argv[3]);
  }
  int n = atoi(argv[2]);
  int *a = malloc(sizeof(int) * n);
  if (init_array(argv[1], 0, n, &a[0]) != 0) {
    printf("File %s could not be opened!\n", argv[1]);
    return 1;
  }
  struct timespec time1; struct timespec time2;
  get_timestamp(&time1);
  radix_sort(&a[0], n);
  get_timestamp(&time2);
  double elapsed = timestamp_diff_in_seconds(time1,time2);
  printf("%f s\n", elapsed);
  printf("%d elements sorted\n", n);
  printf("%f elements/s\n", n / elapsed);
  if (print_results) {
    print_array(&a[0], n);
  }
  free(a);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: elapsed double

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


decompiled_code:
__int64 __fastcall random_in_range(int a1, int a2)
{
return (unsigned int)(rand() % (a2 + 1 - a1) + a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
return (unsigned int)(rand() % (a2 + 1 - a1) + a1);
}

original_code:
int random_in_range(int min, int max) {
  return (rand() % (max + 1 - min)) + min;
}

variable_types: min int

variable_types: max int


usage

decompiled_code:
size_t usage()
{
fwrite("Incorrect usage!\n", 1uLL, 0x11uLL, stderr);
fwrite("Usage: dataset_gen [n] [min] [max]\n", 1uLL, 0x23uLL, stderr);
fwrite(" [n] - number of elements in the dataset\n", 1uLL, 0x2AuLL, stderr);
fwrite(" [min] - min value of element\n", 1uLL, 0x1FuLL, stderr);
fwrite(" [max] - max value of element\n", 1uLL, 0x1FuLL, stderr);
return fwrite(" <digits> - optional, number of digits in each element\n", 1uLL, 0x38uLL, stderr);
}

canonical_decompiled_code:
size_t func7()
{
fwrite("Incorrect usage!\n", 1uLL, 0x11uLL, stderr);
fwrite("Usage: dataset_gen [n] [min] [max]\n", 1uLL, 0x23uLL, stderr);
fwrite(" [n] - number of elements in the dataset\n", 1uLL, 0x2AuLL, stderr);
fwrite(" [min] - min value of element\n", 1uLL, 0x1FuLL, stderr);
fwrite(" [max] - max value of element\n", 1uLL, 0x1FuLL, stderr);
return fwrite(" <digits> - optional, number of digits in each element\n", 1uLL, 0x38uLL, stderr);
}

original_code:
void usage() {
  fprintf(stderr, "Incorrect usage!\n");
  fprintf(stderr, "Usage: dataset_gen [n] [min] [max]\n");
  fprintf(stderr, "  [n] - number of elements in the dataset\n");
  fprintf(stderr, "  [min] - min value of element\n");
  fprintf(stderr, "  [max] - max value of element\n");
  fprintf(stderr, "  <digits> - optional, number of digits in each element\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebp
int v5; // er12
int v6; // er13
int v7; // er14
int i; // ebx
unsigned int v9; // eax
int result; // eax
int v11; // ebx
unsigned int v12; // eax

if ( argc <= 3 )
{
usage();
return -1;
}
v3 = time(0LL);
srand(v3);
v4 = atoi(argv[1]);
v5 = atoi(argv[2]);
v6 = atoi(argv[3]);
if ( argc <= 4 )
{
v7 = -1;
}
else
{
v7 = atoi(argv[4]);
if ( v7 > 0 )
{
if ( v4 <= 0 )
return 0;
for ( i = 0; i != v4; ++i )
{
v9 = random_in_range(v5, v6);
printf("%d\n", v9);
}
return 0;
}
}
v11 = 0;
result = 0;
if ( v4 > 0 )
{
do
{
v12 = random_in_range(v5, v6);
printf("%0*d\n", v7, v12);
++v11;
}
while ( v4 != v11 );
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebp
int v5; // er12
int v6; // er13
int v7; // er14
int i; // ebx
unsigned int v9; // eax
int result; // eax
int v11; // ebx
unsigned int v12; // eax

if ( argc <= 3 )
{
func7();
return -1;
}
v3 = time(0LL);
srand(v3);
v4 = atoi(argv[1]);
v5 = atoi(argv[2]);
v6 = atoi(argv[3]);
if ( argc <= 4 )
{
v7 = -1;
}
else
{
v7 = atoi(argv[4]);
if ( v7 > 0 )
{
if ( v4 <= 0 )
return 0;
for ( i = 0; i != v4; ++i )
{
v9 = func8(v5, v6);
printf("%d\n", v9);
}
return 0;
}
}
v11 = 0;
result = 0;
if ( v4 > 0 )
{
do
{
v12 = func8(v5, v6);
printf("%0*d\n", v7, v12);
++v11;
}
while ( v4 != v11 );
result = 0;
}
return result;
}

original_code:
int main(int argc, char** argv) {
  if (argc < 4) {
    usage();
    return -1;
  }
  srand(time(0));
  int n = atoi(argv[1]);
  int min = atoi(argv[2]);
  int max = atoi(argv[3]);
  int digits = -1;
  if (argc > 4) {
    digits = atoi(argv[4]);
  }
  if (digits > 0) {
    for (int i = 0; i < n; i++) {
      printf("%d\n", random_in_range(min, max));
    }
  } else {
    for (int i = 0; i < n; i++) {
      printf("%0*d\n", digits, random_in_range(min, max));
    }
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  if (argc < 4) {
    usage();
    return -1;
  }
  srand(time(0));
  int n = atoi(argv[1]);
  int min = atoi(argv[2]);
  int max = atoi(argv[3]);
  int digits = -1;
  if (argc > 4) {
    digits = atoi(argv[4]);
  }
  if (digits > 0) {
    for (int i = 0; i < n; i++) {
      printf("%d\n", random_in_range(min, max));
    }
  } else {
    for (int i = 0; i < n; i++) {
      printf("%0*d\n", digits, random_in_range(min, max));
    }
  }
  return 0;
}

variable_types: digits int

variable_types: i int


decompiled_code:
float __fastcall s0(float a1, float a2, float a3, float a4, float a5, float a6)
{
return (float)((float)((float)((float)(a1 + a2) + a3) + a4) + a5) + a6;
}

canonical_decompiled_code:
float __fastcall func6(float a1, float a2, float a3, float a4, float a5, float a6)
{
return (float)((float)((float)((float)(a1 + a2) + a3) + a4) + a5) + a6;
}

original_code:
float s0(float a, float b, float c, float d, float e, float f)
{
        return a+b+c+d+e+f;
}

variable_types: a float

variable_types: b float

variable_types: c float

variable_types: d float

variable_types: e float

variable_types: f float

return_type: float


decompiled_code:
float __fastcall s1(float a1, float a2, float a3, float a4, float a5, float a6)
{
return (float)((float)((float)((float)(a1 * a2) * a3) * a4) * a5) * a6;
}

canonical_decompiled_code:
float __fastcall func7(float a1, float a2, float a3, float a4, float a5, float a6)
{
return (float)((float)((float)((float)(a1 * a2) * a3) * a4) * a5) * a6;
}

original_code:
float s1(float a, float b, float c, float d, float e, float f)
{
  return a*b*c*d*e*f;
}


decompiled_code:
float __fastcall s2(float a1, float a2, float a3, float a4, float a5, float a6)
{
return (float)((float)((float)((float)((float)(a1 * a1) + (float)(a2 * a2)) + (float)(a3 * a3)) + (float)(a4 * a4))
+ (float)(a5 * a5))
+ (float)(a6 * a6);
}

canonical_decompiled_code:
float __fastcall func8(float a1, float a2, float a3, float a4, float a5, float a6)
{
return (float)((float)((float)((float)((float)(a1 * a1) + (float)(a2 * a2)) + (float)(a3 * a3)) + (float)(a4 * a4))
+ (float)(a5 * a5))
+ (float)(a6 * a6);
}

original_code:
float s2(float a, float b, float c, float d, float e, float f)
{
 return a*a+b*b+c*c+d*d+e*e+f*f;
}


decompiled_code:
__int64 __fastcall read_address(unsigned __int8 *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 *a1)
{
return *a1;
}

original_code:
static int
read_address(unsigned long addr)
{
    return *((unsigned char*)addr);
}

canonical_original_code:
static int read_address(unsigned long addr)
{
    return *((unsigned char *)addr);
}

variable_types:
addr
unsigned long


decompiled_code:
void __noreturn on_SIGSEGV()
{
segv = 1;
siglongjmp(env, 1);
}

canonical_decompiled_code:
void __noreturn func8()
{
segv = 1;
siglongjmp(env, 1);
}

original_code:
static void
on_SIGSEGV(int sig)
{
    segv = 1;
    siglongjmp(env, 1);
}

variable_types: sig int


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

signal(11, (__sighandler_t)on_SIGSEGV);
while ( 1 )
{
nptr = getcmdline("> ");
if ( !nptr )
break;
if ( __sigsetjmp(env, 1) )
{
if ( segv )
{
puts("not allocated");
segv = 0;
}
}
else
{
v3 = (unsigned __int8 *)strtoul(nptr, 0LL, 10);
v4 = read_address(v3);
printf("%d\n", v4);
}
}
exit(0);
}

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

signal(11, (__sighandler_t)on_SIGSEGV);
while ( 1 )
{
nptr = func9("> ");
if ( !nptr )
break;
if ( __sigsetjmp(env, 1) )
{
if ( segv )
{
puts("not allocated");
segv = 0;
}
}
else
{
v3 = (unsigned __int8 *)strtoul(nptr, 0LL, 10);
v4 = func7(v3);
printf("%d\n", v4);
}
}
exit(0);
}

original_code:
int
main(int argc, char *argv[])
{
    char *line;
    signal(11, on_SIGSEGV);
    while (line = getcmdline("> ")) {
        if (__sigsetjmp (env, 1) == 0) {
            printf("%d\n", read_address(strtoul(line, ((void *)0), 10)));
        }
        else {
            if (segv) {
                printf("not allocated\n");
                segv = 0;
            }
        }
    }
    exit(0);
}

variable_types:
argv
char *[]

variable_types:
line
char *


decompiled_code:
__int64 __fastcall get_group_id(const char *a1)
{
struct group *v1; // rax

v1 = getgrnam(a1);
if ( !v1 )
{
fprintf(stderr, "no such group: %s\n", a1);
exit(1);
}
return v1->gr_gid;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
struct group *v1; // rax

v1 = getgrnam(a1);
if ( !v1 )
{
fprintf(stderr, "no such group: %s\n", a1);
exit(1);
}
return v1->gr_gid;
}

original_code:
static gid_t
get_group_id(char *group)
{
    struct group *gr;
    gr = getgrnam(group);
    if (!gr) {
        fprintf(stderr, "no such group: %s\n", group);
        exit(1);
    }
    return gr->gr_gid;
}

canonical_original_code:
static unsigned int get_group_id(char *group)
{
    struct group *gr;
    gr = getgrnam(group);
    if (!gr) {
        fprintf(stderr, "no such group: %s\n", group);
        exit(1);
    }
    return gr->gr_gid;
}

variable_types:
group
char *

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *


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

if ( argc > 1 )
{
v3 = get_group_id(argv[1]);
if ( argc > 2 )
{
v4 = argv + 2;
do
{
if ( chown(*v4, 0xFFFFFFFF, v3) < 0 )
perror(*v4);
++v4;
}
while ( v4 != &argv[(unsigned int)(argc - 3) + 3] );
}
exit(1);
}
fwrite("no group name given\n", 1uLL, 0x14uLL, stderr);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__gid_t v3; // ebp
const char **v4; // rbx

if ( argc > 1 )
{
v3 = func7(argv[1]);
if ( argc > 2 )
{
v4 = argv + 2;
do
{
if ( chown(*v4, 0xFFFFFFFF, v3) < 0 )
perror(*v4);
++v4;
}
while ( v4 != &argv[(unsigned int)(argc - 3) + 3] );
}
exit(1);
}
fwrite("no group name given\n", 1uLL, 0x14uLL, stderr);
exit(1);
}

original_code:
int
main(int argc, char *argv[])
{
    gid_t gid;
    int i;
    if (argc < 2) {
        fprintf(stderr, "no group name given\n");
        exit(1);
    }
    gid = get_group_id(argv[1]);
    for (i = 2; i < argc; i++) {
        if (chown(argv[i], -1, gid) < 0) {
            perror(argv[i]);
        }
    }
    exit(1);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned int gid;
    int i;
    if (argc < 2) {
        fprintf(stderr, "no group name given\n");
        exit(1);
    }
    gid = get_group_id(argv[1]);
    for (i = 2; i < argc; i++) {
        if (chown(argv[i], -1, gid) < 0) {
            perror(argv[i]);
        }
    }
    exit(1);
}

variable_types: argc int

variable_types:
gid
unsigned int


decompiled_code:
struct passwd *__fastcall user_name(__uid_t a1)
{
struct passwd *result; // rax

result = getpwuid(a1);
if ( result )
result = (struct passwd *)result->pw_name;
return result;
}

canonical_decompiled_code:
struct passwd *__fastcall func7(__uid_t a1)
{
struct passwd *result; // rax

result = getpwuid(a1);
if ( result )
result = (struct passwd *)result->pw_name;
return result;
}

original_code:
static char *
user_name(uid_t id)
{
    struct passwd *pw;
    pw = getpwuid(id);
    if (!pw) return ((void *)0);
    return pw->pw_name;
}

canonical_original_code:
static char *user_name(unsigned int id)
{
    struct passwd *pw;
    pw = getpwuid(id);
    if (!pw) return ((void *)0);
    return pw->pw_name;
}

variable_types:
id
unsigned int

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
struct group *__fastcall group_name(__gid_t a1)
{
struct group *result; // rax

result = getgrgid(a1);
if ( result )
result = (struct group *)result->gr_name;
return result;
}

canonical_decompiled_code:
struct group *__fastcall func8(__gid_t a1)
{
struct group *result; // rax

result = getgrgid(a1);
if ( result )
result = (struct group *)result->gr_name;
return result;
}

original_code:
static char *
group_name(gid_t id)
{
    struct group *gr;
    gr = getgrgid(id);
    if (!gr) return ((void *)0);
    return gr->gr_name;
}

canonical_original_code:
static char *group_name(unsigned int id)
{
    struct group *gr;
    gr = getgrgid(id);
    if (!gr) return ((void *)0);
    return gr->gr_name;
}

user_defined_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; }


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
struct passwd *v4; // rax
__int64 v5; // rbx
struct group *v6; // rax
__int64 v7; // rbx
__gid_t *v8; // rax
__gid_t *v9; // rbp
int v10; // er12
__int64 v11; // rbx
const char *v12; // r13
struct group *v13; // rax

v3 = getuid();
printf("uid=%d", v3);
v4 = user_name(v3);
if ( v4 )
printf("(%s)", (const char *)v4);
v5 = getgid();
printf(" gid=%d", v5);
v6 = group_name(v5);
if ( v6 )
printf("(%s)", (const char *)v6);
v7 = sysconf(3);
v8 = (__gid_t *)malloc(4 * v7);
v9 = v8;
if ( v8 )
{
v10 = getgroups(v7, v8);
if ( v10 >= 0 )
{
printf(" groups=");
if ( v10 > 0 )
{
v11 = 0LL;
v12 = "";
do
{
v13 = group_name(v9[v11]);
printf("%s%d(%s)", v12, v9[v11++], (const char *)v13);
v12 = ",";
}
while ( v11 != v10 );
}
putchar(10);
exit(0);
}
perror("getgroups");
exit(1);
}
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
struct passwd *v4; // rax
__int64 v5; // rbx
struct group *v6; // rax
__int64 v7; // rbx
__gid_t *v8; // rax
__gid_t *v9; // rbp
int v10; // er12
__int64 v11; // rbx
const char *v12; // r13
struct group *v13; // rax

v3 = getuid();
printf("uid=%d", v3);
v4 = func7(v3);
if ( v4 )
printf("(%s)", (const char *)v4);
v5 = getgid();
printf(" gid=%d", v5);
v6 = func8(v5);
if ( v6 )
printf("(%s)", (const char *)v6);
v7 = sysconf(3);
v8 = (__gid_t *)malloc(4 * v7);
v9 = v8;
if ( v8 )
{
v10 = getgroups(v7, v8);
if ( v10 >= 0 )
{
printf(" groups=");
if ( v10 > 0 )
{
v11 = 0LL;
v12 = "";
do
{
v13 = func8(v9[v11]);
printf("%s%d(%s)", v12, v9[v11++], (const char *)v13);
v12 = ",";
}
while ( v11 != v10 );
}
putchar(10);
exit(0);
}
perror("getgroups");
exit(1);
}
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(1);
}

original_code:
int
main(int argc, char *argv[])
{
    uid_t u;
    gid_t g;
    char *name;
    gid_t *buf;
    long group_max;
    int n;
    char *comma;
    long i;
    u = getuid();
    printf("uid=%d", u);
    if (name = user_name(u)) {
        printf("(%s)", name);
    }
    g = getgid();
    printf(" gid=%d", g);
    if (name = group_name(g)) {
        printf("(%s)", name);
    }
    group_max = sysconf(_SC_NGROUPS_MAX);
    buf = malloc(sizeof(gid_t) * group_max);
    if (!buf) {
        fprintf(stderr, "malloc failed\n");
        exit(1);
    }
    n = getgroups(group_max, buf);
    if (n < 0) {
        perror("getgroups");
        exit(1);
    }
    printf(" groups=");
    comma = "";
    for (i = 0; i < n; i++) {
        printf("%s%d(%s)", comma, buf[i], group_name(buf[i]));
        comma = ",";
    }
    printf("\n");
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned int u;
    unsigned int g;
    char *name;
    unsigned int *buf;
    long group_max;
    int n;
    char *comma;
    long i;
    u = getuid();
    printf("uid=%d", u);
    if (name = user_name(u)) {
        printf("(%s)", name);
    }
    g = getgid();
    printf(" gid=%d", g);
    if (name = group_name(g)) {
        printf("(%s)", name);
    }
    group_max = sysconf(_SC_NGROUPS_MAX);
    buf = malloc(sizeof(gid_t) * group_max);
    if (!buf) {
        fprintf(stderr, "malloc failed\n");
        exit(1);
    }
    n = getgroups(group_max, buf);
    if (n < 0) {
        perror("getgroups");
        exit(1);
    }
    printf(" groups=");
    comma = "";
    for (i = 0; i < n; i++) {
        printf("%s%d(%s)", comma, buf[i], group_name(buf[i]));
        comma = ",";
    }
    printf("\n");
    exit(0);
}

variable_types:
u
unsigned int

variable_types:
g
unsigned int

variable_types:
name
char *

variable_types:
buf
unsigned int *

variable_types: n int

variable_types:
comma
char *

variable_types: i long


showaddr

decompiled_code:
int __fastcall showaddr(const char *a1, __int64 a2)
{
printf("%s = %lx\n", a1, a2);
printf("%s%%4 = %ld\n", a1, a2 & 3);
return printf("%s%%8 = %ld\n", a1, a2 & 7);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, __int64 a2)
{
printf("%s = %lx\n", a1, a2);
printf("%s%%4 = %ld\n", a1, a2 & 3);
return printf("%s%%8 = %ld\n", a1, a2 & 7);
}

original_code:
static void
showaddr(char *label, void *a)
{
    unsigned long n = (unsigned long)a;
    printf("%s   = %lx\n", label, n);
    printf("%s%%4 = %ld\n", label, n % 4);
    printf("%s%%8 = %ld\n", label, n % 8);
}

variable_types:
label
char *

variable_types:
a
void *

variable_types:
n
unsigned long


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // [rsp+0h] [rbp-38h] BYREF
char v4[8]; // [rsp+8h] [rbp-30h] BYREF
char v5[16]; // [rsp+10h] [rbp-28h] BYREF
char v6; // [rsp+20h] [rbp-18h] BYREF
char v7[7]; // [rsp+21h] [rbp-17h] BYREF
char v8[16]; // [rsp+28h] [rbp-10h] BYREF

showaddr("st1.c1 ", (__int64)&v6);
showaddr("st1.c2 ", (__int64)v7);
showaddr("st1.n ", (__int64)v8);
showaddr("st2.u1.c", (__int64)&v3);
showaddr("st2.u2.c", (__int64)v4);
showaddr("st2.n ", (__int64)v5);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // [rsp+0h] [rbp-38h] BYREF
char v4[8]; // [rsp+8h] [rbp-30h] BYREF
char v5[16]; // [rsp+10h] [rbp-28h] BYREF
char v6; // [rsp+20h] [rbp-18h] BYREF
char v7[7]; // [rsp+21h] [rbp-17h] BYREF
char v8[16]; // [rsp+28h] [rbp-10h] BYREF

func7("st1.c1 ", (__int64)&v6);
func7("st1.c2 ", (__int64)v7);
func7("st1.n ", (__int64)v8);
func7("st2.u1.c", (__int64)&v3);
func7("st2.u2.c", (__int64)v4);
func7("st2.n ", (__int64)v5);
exit(0);
}

original_code:
int
main(int argc, char *argv[])
{
    struct some {
 char c1;
 char c2;
 long n;
    } st1;
    struct any {
 union {
     char c;
            long n;
 } u1;
 union {
     char c;
            long n;
 } u2;
 long n;
    } st2;
    showaddr("st1.c1  ", &st1.c1);
    showaddr("st1.c2  ", &st1.c2);
    showaddr("st1.n   ", &st1.n);
    showaddr("st2.u1.c", &st2.u1.c);
    showaddr("st2.u2.c", &st2.u2.c);
    showaddr("st2.n   ", &st2.n);
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct some st1;
    struct any st2;
    showaddr("st1.c1  ", &st1.c1);
    showaddr("st1.c2  ", &st1.c2);
    showaddr("st1.n   ", &st1.n);
    showaddr("st2.u1.c", &st2.u1.c);
    showaddr("st2.u2.c", &st2.u2.c);
    showaddr("st2.n   ", &st2.n);
    exit(0);
}

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall get_user_id(const char *a1)
{
struct passwd *v1; // rax

v1 = getpwnam(a1);
if ( !v1 )
{
fprintf(stderr, "no such user: %s\n", a1);
exit(1);
}
return v1->pw_uid;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
struct passwd *v1; // rax

v1 = getpwnam(a1);
if ( !v1 )
{
fprintf(stderr, "no such user: %s\n", a1);
exit(1);
}
return v1->pw_uid;
}

original_code:
static uid_t
get_user_id(char *user)
{
    struct passwd *pw;
    pw = getpwnam(user);
    if (!pw) {
        fprintf(stderr, "no such user: %s\n", user);
        exit(1);
    }
    return pw->pw_uid;
}

canonical_original_code:
static unsigned int get_user_id(char *user)
{
    struct passwd *pw;
    pw = getpwnam(user);
    if (!pw) {
        fprintf(stderr, "no such user: %s\n", user);
        exit(1);
    }
    return pw->pw_uid;
}

variable_types:
user
char *

user_defined_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; }


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

if ( argc > 1 )
{
v3 = get_user_id(argv[1]);
if ( argc > 2 )
{
v4 = argv + 2;
do
{
if ( chown(*v4, v3, 0xFFFFFFFF) < 0 )
perror(*v4);
++v4;
}
while ( v4 != &argv[(unsigned int)(argc - 3) + 3] );
}
exit(1);
}
fwrite("no user name given\n", 1uLL, 0x13uLL, stderr);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__uid_t v3; // ebp
const char **v4; // rbx

if ( argc > 1 )
{
v3 = func7(argv[1]);
if ( argc > 2 )
{
v4 = argv + 2;
do
{
if ( chown(*v4, v3, 0xFFFFFFFF) < 0 )
perror(*v4);
++v4;
}
while ( v4 != &argv[(unsigned int)(argc - 3) + 3] );
}
exit(1);
}
fwrite("no user name given\n", 1uLL, 0x13uLL, stderr);
exit(1);
}

original_code:
int
main(int argc, char *argv[])
{
    uid_t uid;
    int i;
    if (argc < 2) {
        fprintf(stderr, "no user name given\n");
        exit(1);
    }
    uid = get_user_id(argv[1]);
    for (i = 2; i < argc; i++) {
        if (chown(argv[i], uid, -1) < 0) {
            perror(argv[i]);
        }
    }
    exit(1);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned int uid;
    int i;
    if (argc < 2) {
        fprintf(stderr, "no user name given\n");
        exit(1);
    }
    uid = get_user_id(argv[1]);
    for (i = 2; i < argc; i++) {
        if (chown(argv[i], uid, -1) < 0) {
            perror(argv[i]);
        }
    }
    exit(1);
}

variable_types:
uid
unsigned int

variable_types: i int


decompiled_code:
__int64 __fastcall builtin_exit(int a1, const char **a2)
{
if ( a1 == 1 )
exit(0);
fprintf(stderr, "%s: too many arguments\n", *a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, const char **a2)
{
if ( a1 == 1 )
exit(0);
fprintf(stderr, "%s: too many arguments\n", *a2);
return 1LL;
}

original_code:
static int
builtin_exit(int argc, char *argv[])
{
    if (argc != 1) {
        fprintf(stderr, "%s: too many arguments\n", argv[0]);
        return 1;
    }
    exit(0);
}

variable_types: argc int


decompiled_code:
char *__fastcall lookup_builtin(char *s1)
{
const char *v1; // rsi
const char **v2; // rbx

v1 = builtins_list;
if ( !builtins_list )
return builtins_list;
v2 = (const char **)&builtins_list;
while ( strcmp(s1, v1) )
{
v2 += 2;
v1 = *v2;
if ( !*v2 )
return 0LL;
}
return (char *)v2;
}

canonical_decompiled_code:
char *__fastcall func11(char *s1)
{
const char *v1; // rsi
const char **v2; // rbx

v1 = builtins_list;
if ( !builtins_list )
return builtins_list;
v2 = (const char **)&builtins_list;
while ( strcmp(s1, v1) )
{
v2 += 2;
v1 = *v2;
if ( !*v2 )
return 0LL;
}
return (char *)v2;
}

original_code:
static struct builtin*
lookup_builtin(char *cmd)
{
    struct builtin *p;
    for (p = builtins_list; p->name; p++) {
        if (strcmp(cmd, p->name) == 0)
            return p;
    }
    return ((void *)0);
}

canonical_original_code:
static struct builtin *lookup_builtin(char *cmd)
{
    struct builtin *p;
    for (p = builtins_list; p->name; p++) {
        if (strcmp(cmd, p->name) == 0)
            return p;
    }
    return ((void *)0);
}

variable_types:
cmd
char *

variable_types: struct builtin { char *name; int (*f)(int argc, char *argv[]); } *


decompiled_code:
void __fastcall redirect_stdout(char *s)
{
int v1; // eax
int v2; // ebx

close(1);
v1 = open(s, 577, 438LL);
if ( v1 < 0 )
{
perror(s);
}
else
{
v2 = v1;
if ( v1 != 1 )
{
dup2(v1, 1);
close(v2);
}
}
}

canonical_decompiled_code:
void __fastcall func12(char *s)
{
int v1; // eax
int v2; // ebx

close(1);
v1 = open(s, 577, 438LL);
if ( v1 < 0 )
{
perror(s);
}
else
{
v2 = v1;
if ( v1 != 1 )
{
dup2(v1, 1);
close(v2);
}
}
}

original_code:
static void
redirect_stdout(char *path)
{
    int fd;
    close(1);
    fd = open(path, 01|01000|0100, 0666);
    if (fd < 0) {
        perror(path);
        return;
    }
    if (fd != 1) {
        dup2(fd, 1);
        close(fd);
    }
}

variable_types:
path
char *

variable_types: fd int


decompiled_code:
void __fastcall exec_pipeline(__int64 a1)
{
__int64 v1; // rbx
__pid_t v2; // eax
__int64 v3; // rax
int v4; // ebp
int v5; // er13
_DWORD *v6; // rax
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

pipedes[0] = -1;
pipedes[1] = -1;
v1 = a1;
if ( a1 )
{
while ( 1 )
{
if ( *(_DWORD *)v1 == -1 )
return;
v4 = pipedes[0];
v5 = pipedes[1];
v6 = *(_DWORD **)(v1 + 32);
if ( v6 && *v6 != -1 && pipe(pipedes) < 0 )
{
perror("pipe");
exit(3);
}
if ( lookup_builtin(**(char ***)(v1 + 8)) )
break;
v2 = fork();
*(_DWORD *)(v1 + 24) = v2;
if ( v2 < 0 )
{
perror("fork");
exit(3);
}
if ( v2 <= 0 )
{
LABEL_21:
if ( a1 != v1 )
{
close(0);
dup2(v4, 0);
close(v4);
close(v5);
}
v3 = *(_QWORD *)(v1 + 32);
if ( !v3 )
{
LABEL_28:
if ( *(_DWORD *)(v1 + 24) != -2 )
{
LABEL_29:
execvp(**(const char ***)(v1 + 8), *(char *const **)(v1 + 8));
fprintf(stderr, "%s: command not found: %s\n", (const char *)program_name, **(const char ***)(v1 + 8));
exit(1);
}
return;
}
if ( *(_DWORD *)v3 == -1 )
goto LABEL_25;
close(pipedes[0]);
close(1);
dup2(pipedes[1], 1);
close(pipedes[1]);
v3 = *(_QWORD *)(v1 + 32);
if ( !v3 )
goto LABEL_28;
if ( *(_DWORD *)v3 == -1 )
{
LABEL_25:
redirect_stdout(**(char ***)(v3 + 8));
if ( *(_DWORD *)(v1 + 24) != -2 )
goto LABEL_29;
goto LABEL_26;
}
if ( *(_DWORD *)(v1 + 24) != -2 )
goto LABEL_29;
v1 = *(_QWORD *)(v1 + 32);
}
else
{
if ( v4 != -1 )
close(v4);
if ( v5 != -1 )
close(v5);
LABEL_26:
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
return;
}
}
*(_DWORD *)(v1 + 24) = -2;
goto LABEL_21;
}
}

original_code:
static void
exec_pipeline(struct cmd *cmdhead)
{
    struct cmd *cmd;
    int fds1[2] = {-1, -1};
    int fds2[2] = {-1, -1};
    for (cmd = cmdhead; cmd && !((cmd)->argc == -1); cmd = cmd->next) {
        fds1[0] = fds2[0];
        fds1[1] = fds2[1];
        if (! (((cmd)->next == ((void *)0)) || (((cmd)->next)->argc == -1))) {
            if (pipe(fds2) < 0) {
                perror("pipe");
                exit(3);
            }
        }
        if (lookup_builtin(cmd->argv[0]) != ((void *)0)) {
            cmd->pid = -2;
        }
        else {
            cmd->pid = fork();
            if (cmd->pid < 0) {
                perror("fork");
                exit(3);
            }
            if (cmd->pid > 0) {
                if (fds1[0] != -1) close(fds1[0]);
                if (fds1[1] != -1) close(fds1[1]);
                continue;
            }
        }
        if (! ((cmd) == cmdhead)) {
            close(0); dup2(fds1[0], 0); close(fds1[0]);
            close(fds1[1]);
        }
        if (! (((cmd)->next == ((void *)0)) || (((cmd)->next)->argc == -1))) {
            close(fds2[0]);
            close(1); dup2(fds2[1], 1); close(fds2[1]);
        }
        if ((cmd->next != ((void *)0)) && ((cmd->next)->argc == -1)) {
            redirect_stdout(cmd->next->argv[0]);
        }
        if (!((cmd)->pid == -2)) {
            execvp(cmd->argv[0], cmd->argv);
            fprintf(stderr, "%s: command not found: %s\n",
                    program_name, cmd->argv[0]);
            exit(1);
        }
    }
}

variable_types: struct cmd { int argc; char **argv; int capa; int status; int pid; struct cmd *next; } *


original_code:
static struct cmd*
parse_command_line(char *p)
{
    struct cmd *cmd;
    cmd = xmalloc(sizeof(struct cmd));
    cmd->argc = 0;
    cmd->argv = xmalloc(sizeof(char*) * 8);
    cmd->capa = 8;
    cmd->next = ((void *)0);
    while (*p) {
        while (*p && ((*__ctype_b_loc ())[(int) (((int)*p))] & (unsigned short int) _ISspace))
            *p++ = '\0';
        if (! (!((*__ctype_b_loc ())[(int) (((int)*p))] & (unsigned short int) _ISspace) && ((*p) != '|') && ((*p) != '>')))
            break;
        if (*p && (!((*__ctype_b_loc ())[(int) (((int)*p))] & (unsigned short int) _ISspace) && ((*p) != '|') && ((*p) != '>'))) {
            if (cmd->capa <= cmd->argc) {
                cmd->capa *= 2;
                cmd->argv = xrealloc(cmd->argv, cmd->capa);
            }
            cmd->argv[cmd->argc] = p;
            cmd->argc++;
        }
        while (*p && (!((*__ctype_b_loc ())[(int) (((int)*p))] & (unsigned short int) _ISspace) && ((*p) != '|') && ((*p) != '>')))
            p++;
    }
    if (cmd->capa <= cmd->argc) {
        cmd->capa += 1;
        cmd->argv = xrealloc(cmd->argv, cmd->capa);
    }
    cmd->argv[cmd->argc] = ((void *)0);
    if (*p == '|' || *p == '>') {
        if (cmd == ((void *)0) || cmd->argc == 0) goto parse_error;
        cmd->next = parse_command_line(p + 1);
        if (cmd->next == ((void *)0) || cmd->next->argc == 0) goto parse_error;
        if (*p == '>') {
            if (cmd->next->argc != 1) goto parse_error;
            cmd->next->argc = -1;
        }
        *p = '\0';
    }
    return cmd;
  parse_error:
    if (cmd) free_cmd(cmd);
    return ((void *)0);
}

canonical_original_code:
static struct cmd *parse_command_line(char *p)
{
    struct cmd *cmd;
    cmd = xmalloc(sizeof(struct cmd));
    cmd->argc = 0;
    cmd->argv = xmalloc(sizeof(char *) * 8);
    cmd->capa = 8;
    cmd->next = ((void *)0);
    while (*p) {
        while (*p && ((*__ctype_b_loc ())[(int) (((int)*p))] & (unsigned short) _ISspace))
            *p++ = '\0';
        if (! (!((*__ctype_b_loc ())[(int) (((int)*p))] & (unsigned short) _ISspace) && ((*p) != '|') && ((*p) != '>')))
            break;
        if (*p && (!((*__ctype_b_loc ())[(int) (((int)*p))] & (unsigned short) _ISspace) && ((*p) != '|') && ((*p) != '>'))) {
            if (cmd->capa <= cmd->argc) {
                cmd->capa *= 2;
                cmd->argv = xrealloc(cmd->argv, cmd->capa);
            }
            cmd->argv[cmd->argc] = p;
            cmd->argc++;
        }
        while (*p && (!((*__ctype_b_loc ())[(int) (((int)*p))] & (unsigned short) _ISspace) && ((*p) != '|') && ((*p) != '>')))
            p++;
    }
    if (cmd->capa <= cmd->argc) {
        cmd->capa += 1;
        cmd->argv = xrealloc(cmd->argv, cmd->capa);
    }
    cmd->argv[cmd->argc] = ((void *)0);
    if (*p == '|' || *p == '>') {
        if (cmd == ((void *)0) || cmd->argc == 0) goto parse_error;
        cmd->next = parse_command_line(p + 1);
        if (cmd->next == ((void *)0) || cmd->next->argc == 0) goto parse_error;
        if (*p == '>') {
            if (cmd->next->argc != 1) goto parse_error;
            cmd->next->argc = -1;
        }
        *p = '\0';
    }
    return cmd;
  parse_error:
    if (cmd) free_cmd(cmd);
    return ((void *)0);
}

variable_types:
p
char *

return_type: struct cmd { int argc; char **argv; int capa; int status; int pid; struct cmd *next; } *


prompt

decompiled_code:
void prompt()
{
int *v0; // rax
__int64 v1; // rbx

fwrite("$ ", 1uLL, 2uLL, _bss_start);
fflush(_bss_start);
if ( !fgets(buf_0, 2048, stdin) )
exit(0);
v0 = parse_command_line(buf_0);
v1 = (__int64)v0;
if ( v0 )
{
if ( *v0 > 0 )
invoke_commands((__int64)v0);
free_cmd(v1);
}
else
{
fprintf(stderr, "%s: syntax error\n", (const char *)program_name);
}
}

canonical_decompiled_code:
void func18()
{
int *v0; // rax
__int64 v1; // rbx

fwrite("$ ", 1uLL, 2uLL, _bss_start);
fflush(_bss_start);
if ( !fgets(buf_0, 2048, stdin) )
exit(0);
v0 = func17(buf_0);
v1 = (__int64)v0;
if ( v0 )
{
if ( *v0 > 0 )
func15((__int64)v0);
func16(v1);
}
else
{
fprintf(stderr, "%s: syntax error\n", (const char *)program_name);
}
}

original_code:
static void
prompt(void)
{
    static char buf[2048];
    struct cmd *cmd;
    fprintf(stdout, "$ ");
    fflush(stdout);
    if (fgets(buf, 2048, stdin) == ((void *)0))
        exit(0);
    cmd = parse_command_line(buf);
    if (cmd == ((void *)0)) {
        fprintf(stderr, "%s: syntax error\n", program_name);
        return;
    }
    if (cmd->argc > 0)
        invoke_commands(cmd);
    free_cmd(cmd);
}

canonical_original_code:
static void prompt()
{
    static char buf[2048];
    struct cmd *cmd;
    fprintf(stdout, "$ ");
    fflush(stdout);
    if (fgets(buf, 2048, stdin) == ((void *)0))
        exit(0);
    cmd = parse_command_line(buf);
    if (cmd == ((void *)0)) {
        fprintf(stderr, "%s: syntax error\n", program_name);
        return;
    }
    if (cmd->argc > 0)
        invoke_commands(cmd);
    free_cmd(cmd);
}

variable_types:
buf
char [2048]

user_defined_types: struct cmd { int argc; char **argv; int capa; int status; int pid; struct cmd *next; }


decompiled_code:
__int64 __fastcall builtin_pwd(int a1, const char **a2)
{
__int64 result; // rax
char v3[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( a1 == 1 )
{
if ( getcwd(v3, 0x1000uLL) )
{
puts(v3);
result = 0LL;
}
else
{
fprintf(stderr, "%s: cannot get working directory\n", *a2);
result = 1LL;
}
}
else
{
fprintf(stderr, "%s: wrong argument\n", *a2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(int a1, const char **a2)
{
__int64 result; // rax
char v3[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( a1 == 1 )
{
if ( getcwd(v3, 0x1000uLL) )
{
puts(v3);
result = 0LL;
}
else
{
fprintf(stderr, "%s: cannot get working directory\n", *a2);
result = 1LL;
}
}
else
{
fprintf(stderr, "%s: wrong argument\n", *a2);
result = 1LL;
}
return result;
}

original_code:
static int
builtin_pwd(int argc, char *argv[])
{
    char buf[4096];
    if (argc != 1) {
        fprintf(stderr, "%s: wrong argument\n", argv[0]);
        return 1;
    }
    if (!getcwd(buf, 4096)) {
        fprintf(stderr, "%s: cannot get working directory\n", argv[0]);
        return 1;
    }
    printf("%s\n", buf);
    return 0;
}

variable_types:
buf
char [4096]


decompiled_code:
__int64 __fastcall builtin_cd(int a1, const char **a2)
{
__int64 result; // rax
int v3; // edx

if ( a1 == 2 )
{
v3 = chdir(a2[1]);
result = 0LL;
if ( v3 < 0 )
{
perror(a2[1]);
result = 1LL;
}
}
else
{
fprintf(stderr, "%s: wrong argument\n", *a2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(int a1, const char **a2)
{
__int64 result; // rax
int v3; // edx

if ( a1 == 2 )
{
v3 = chdir(a2[1]);
result = 0LL;
if ( v3 < 0 )
{
perror(a2[1]);
result = 1LL;
}
}
else
{
fprintf(stderr, "%s: wrong argument\n", *a2);
result = 1LL;
}
return result;
}

original_code:
static int
builtin_cd(int argc, char *argv[])
{
    if (argc != 2) {
        fprintf(stderr, "%s: wrong argument\n", argv[0]);
        return 1;
    }
    if (chdir(argv[1]) < 0) {
        perror(argv[1]);
        return 1;
    }
    return 0;
}


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t size)
{
void *result; // rax

result = calloc(1uLL, size);
if ( !result )
exit(3);
return result;
}

canonical_decompiled_code:
void *__fastcall func9(size_t size)
{
void *result; // rax

result = calloc(1uLL, size);
if ( !result )
exit(3);
return result;
}

original_code:
static void*
xmalloc(size_t sz)
{
    void *p;
    p = calloc(1, sz);
    if (!p)
        exit(3);
    return p;
}

canonical_original_code:
static void *xmalloc(unsigned long sz)
{
    void *p;
    p = calloc(1, sz);
    if (!p)
        exit(3);
    return p;
}

variable_types:
sz
unsigned long

variable_types:
p
void *

return_type: void *


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, size_t a2)
{
void *result; // rax

if ( !a1 )
return xmalloc(a2);
result = realloc(a1, a2);
if ( !result )
exit(3);
return result;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1, size_t a2)
{
void *result; // rax

if ( !a1 )
return func9(a2);
result = realloc(a1, a2);
if ( !result )
exit(3);
return result;
}

original_code:
static void*
xrealloc(void *ptr, size_t sz)
{
    void *p;
    if (!ptr) return xmalloc(sz);
    p = realloc(ptr, sz);
    if (!p)
        exit(3);
    return p;
}

canonical_original_code:
static void *xrealloc(void *ptr, unsigned long sz)
{
    void *p;
    if (!ptr) return xmalloc(sz);
    p = realloc(ptr, sz);
    if (!p)
        exit(3);
    return p;
}

variable_types:
ptr
void *


decompiled_code:
void __fastcall free_cmd(__int64 a1)
{
if ( *(_QWORD *)(a1 + 32) )
free_cmd();
free(*(void **)(a1 + 8));
free((void *)a1);
}

original_code:
static void
free_cmd(struct cmd *cmd)
{
    if (cmd->next != ((void *)0))
        free_cmd(cmd->next);
    free(cmd->argv);
    free(cmd);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
program_name = (__int64)*argv;
while ( 1 )
prompt();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
program_name = (__int64)*argv;
while ( 1 )
func18();
}

original_code:
int
main(int argc, char *argv[])
{
    program_name = argv[0];
    for (;;) {
        prompt();
    }
    exit(0);
}


decompiled_code:
void **read_cmd()
{
if ( !fgets(buf_0, 2048, stdin) )
exit(0);
return parse_cmd(buf_0);
}

canonical_decompiled_code:
void **func10()
{
if ( !fgets(buf_0, 2048, stdin) )
exit(0);
return func9(buf_0);
}

original_code:
static struct cmd *
read_cmd(void)
{
    static char buf[2048];
    if (fgets(buf, 2048, stdin) == ((void *)0)) {
        exit(0);
    }
    return parse_cmd(buf);
}

canonical_original_code:
static struct cmd *read_cmd()
{
    static char buf[2048];
    if (fgets(buf, 2048, stdin) == ((void *)0)) {
        exit(0);
    }
    return parse_cmd(buf);
}

return_type: struct cmd { char **argv; long argc; long capa; } *


decompiled_code:
__pid_t __fastcall invoke_cmd(const char ***a1)
{
int v1; // eax

v1 = fork();
if ( v1 < 0 )
{
perror("fork");
exit(1);
}
if ( v1 <= 0 )
{
execvp(**a1, (char *const *)*a1);
fprintf(stderr, "%s: command not found: %s\n", (const char *)program_name, **a1);
exit(1);
}
return waitpid(v1, 0LL, 0);
}

canonical_decompiled_code:
__pid_t __fastcall func11(const char ***a1)
{
int v1; // eax

v1 = fork();
if ( v1 < 0 )
{
perror("fork");
exit(1);
}
if ( v1 <= 0 )
{
execvp(**a1, (char *const *)*a1);
fprintf(stderr, "%s: command not found: %s\n", (const char *)program_name, **a1);
exit(1);
}
return waitpid(v1, 0LL, 0);
}

original_code:
static void
invoke_cmd(struct cmd *cmd)
{
    pid_t pid;
    pid = fork();
    if (pid < 0) {
        perror("fork");
        exit(1);
    }
    if (pid > 0) {
        waitpid(pid, ((void *)0), 0);
    }
    else {
        execvp(cmd->argv[0], cmd->argv);
        fprintf(stderr, "%s: command not found: %s\n",
                        program_name, cmd->argv[0]);
        exit(1);
    }
}

canonical_original_code:
static void invoke_cmd(struct cmd *cmd)
{
    int pid;
    pid = fork();
    if (pid < 0) {
        perror("fork");
        exit(1);
    }
    if (pid > 0) {
        waitpid(pid, ((void *)0), 0);
    }
    else {
        execvp(cmd->argv[0], cmd->argv);
        fprintf(stderr, "%s: command not found: %s\n",
                        program_name, cmd->argv[0]);
        exit(1);
    }
}

variable_types: struct cmd { char **argv; long argc; long capa; } *

variable_types: pid int


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
perror("malloc");
exit(1);
}
return result;
}

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

result = malloc(a1);
if ( !result )
{
perror("malloc");
exit(1);
}
return result;
}

original_code:
static void*
xmalloc(size_t size)
{
    void *p;
    p = malloc(size);
    if (!p) {
        perror("malloc");
        exit(1);
    }
    return p;
}

canonical_original_code:
static void *xmalloc(unsigned long size)
{
    void *p;
    p = malloc(size);
    if (!p) {
        perror("malloc");
        exit(1);
    }
    return p;
}

variable_types:
size
unsigned long


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, size_t a2)
{
void *result; // rax

if ( !a1 )
return xmalloc(a2);
result = realloc(a1, a2);
if ( !result )
{
perror("realloc");
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1, size_t a2)
{
void *result; // rax

if ( !a1 )
return func7(a2);
result = realloc(a1, a2);
if ( !result )
{
perror("realloc");
exit(1);
}
return result;
}

original_code:
static void*
xrealloc(void *ptr, size_t size)
{
    void *p;
    if (!ptr) return xmalloc(size);
    p = realloc(ptr, size);
    if (!p) {
        perror("realloc");
        exit(1);
    }
    return p;
}

canonical_original_code:
static void *xrealloc(void *ptr, unsigned long size)
{
    void *p;
    if (!ptr) return xmalloc(size);
    p = realloc(ptr, size);
    if (!p) {
        perror("realloc");
        exit(1);
    }
    return p;
}


decompiled_code:
void __fastcall free_cmd(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
static void
free_cmd(struct cmd *cmd)
{
    free(cmd->argv);
    free(cmd);
}

user_defined_types: struct cmd { char **argv; long argc; long capa; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
void **v3; // rax
void **v4; // rbx

program_name = (__int64)*argv;
while ( 1 )
{
fwrite("$ ", 1uLL, 2uLL, stdout);
fflush(stdout);
v3 = read_cmd();
v4 = v3;
if ( (__int64)v3[1] > 0 )
invoke_cmd((const char ***)v3);
free_cmd(v4);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
void **v3; // rax
void **v4; // rbx

program_name = (__int64)*argv;
while ( 1 )
{
fwrite("$ ", 1uLL, 2uLL, stdout);
fflush(stdout);
v3 = func10();
v4 = v3;
if ( (__int64)v3[1] > 0 )
func11((const char ***)v3);
func12(v4);
}
}

original_code:
int
main(int argc, char *argv[])
{
    program_name = argv[0];
    for (;;) {
        struct cmd *cmd;
        fprintf(stdout, "$ ");
        fflush(stdout);
        cmd = read_cmd();
        if (cmd->argc > 0) {
            invoke_cmd(cmd);
        }
        free_cmd(cmd);
    }
    exit(0);
}

variable_types:
argv
char *[]


decompiled_code:
int __fastcall do_cat(const char *a1)
{
int v1; // ebx
int v2; // eax
int result; // eax
_BYTE v4[2072]; // [rsp+0h] [rbp-818h] BYREF

v1 = open(a1, 0);
if ( v1 < 0 )
die(a1);
while ( 1 )
{
v2 = read(v1, v4, 0x800uLL);
if ( v2 < 0 )
die(a1);
if ( !v2 )
break;
if ( write(1, v4, v2) < 0 )
die(a1);
}
result = close(v1);
if ( result < 0 )
die(a1);
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
int v1; // ebx
int v2; // eax
int result; // eax
_BYTE v4[2072]; // [rsp+0h] [rbp-818h] BYREF

v1 = open(a1, 0);
if ( v1 < 0 )
func7(a1);
while ( 1 )
{
v2 = read(v1, v4, 0x800uLL);
if ( v2 < 0 )
func7(a1);
if ( !v2 )
break;
if ( write(1, v4, v2) < 0 )
func7(a1);
}
result = close(v1);
if ( result < 0 )
func7(a1);
return result;
}

original_code:
static void
do_cat(const char *path)
{
    int fd;
    unsigned char buf[2048];
    int n;
    fd = open(path, 00);
    if (fd < 0) die(path);
    for (;;) {
        n = read(fd, buf, sizeof buf);
        if (n < 0) die(path);
        if (n == 0) break;
        if (write(1, buf, n) < 0) die(path);
    }
    if (close(fd) < 0) die(path);
}

canonical_original_code:
static void do_cat(char *path)
{
    int fd;
    unsigned char buf[2048];
    int n;
    fd = open(path, 00);
    if (fd < 0) die(path);
    for (;;) {
        n = read(fd, buf, sizeof buf);
        if (n < 0) die(path);
        if (n == 0) break;
        if (write(1, buf, n) < 0) die(path);
    }
    if (close(fd) < 0) die(path);
}

variable_types:
buf
unsigned char [2048]

variable_types: n int


die

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

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

original_code:
static void
die(const char *s)
{
    perror(s);
    exit(1);
}

canonical_original_code:
static void die(char *s)
{
    perror(s);
    exit(1);
}

variable_types:
s
char *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx

if ( argc > 1 )
{
v3 = argv + 1;
do
do_cat(*v3++);
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
exit(0);
}
fprintf(_bss_start, "%s: file name not given\n", *argv);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx

if ( argc > 1 )
{
v3 = argv + 1;
do
func8(*v3++);
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
exit(0);
}
fprintf(_bss_start, "%s: file name not given\n", *argv);
exit(1);
}

original_code:
int
main(int argc, char *argv[])
{
    int i;
    if (argc < 2) {
        fprintf(stderr, "%s: file name not given\n", argv[0]);
        exit(1);
    }
    for (i = 1; i < argc; i++) {
        do_cat(argv[i]);
    }
    exit(0);
}

variable_types: argc int

variable_types: i int


decompiled_code:
int __fastcall print_error(const char *a1)
{
int *v1; // rax
char *v2; // rax

v1 = __errno_location();
v2 = strerror(*v1);
return fprintf(_bss_start, "%s: %s: %s\n", (const char *)program_name, a1, v2);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
int *v1; // rax
char *v2; // rax

v1 = __errno_location();
v2 = strerror(*v1);
return fprintf(_bss_start, "%s: %s: %s\n", (const char *)program_name, a1, v2);
}

original_code:
static void
print_error(char *s)
{
    fprintf(stderr, "%s: %s: %s\n", program_name, s, strerror((*__errno_location ())));
}


decompiled_code:
_QWORD *strbuf_new()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
void *v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
{
print_error("malloc(3)");
exit(1);
}
v1 = v0;
v2 = malloc(0x400uLL);
*v1 = v2;
if ( !v2 )
{
print_error("malloc(3)");
exit(1);
}
v1[1] = 1024LL;
return v1;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
void *v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
{
func7("malloc(3)");
exit(1);
}
v1 = v0;
v2 = malloc(0x400uLL);
*v1 = v2;
if ( !v2 )
{
func7("malloc(3)");
exit(1);
}
v1[1] = 1024LL;
return v1;
}

original_code:
static struct strbuf*
strbuf_new(void)
{
    struct strbuf *buf;
    buf = (struct strbuf*)malloc(sizeof(struct strbuf));
    if (!buf) {
        print_error("malloc(3)");
        exit(1);
    }
    buf->ptr = malloc(1024);
    if (!buf->ptr) {
        print_error("malloc(3)");
        exit(1);
    }
    buf->len = 1024;
    return buf;
}

canonical_original_code:
static struct strbuf *strbuf_new()
{
    struct strbuf *buf;
    buf = (struct strbuf *)malloc(sizeof(struct strbuf));
    if (!buf) {
        print_error("malloc(3)");
        exit(1);
    }
    buf->ptr = malloc(1024);
    if (!buf->ptr) {
        print_error("malloc(3)");
        exit(1);
    }
    buf->len = 1024;
    return buf;
}

variable_types: struct strbuf { char *ptr; unsigned long len; } *


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

if ( *(_QWORD *)(a1 + 8) <= a2 )
{
v2 = realloc(*(void **)a1, a2);
if ( !v2 )
{
print_error("realloc(3)");
exit(1);
}
*(_QWORD *)a1 = v2;
*(_QWORD *)(a1 + 8) = a2;
}
}

original_code:
static void
strbuf_realloc(struct strbuf *buf, size_t len)
{
    char *tmp;
    if (buf->len > len) return;
    tmp = realloc(buf->ptr, len);
    if (!tmp) {
        print_error("realloc(3)");
        exit(1);
    }
    buf->ptr = tmp;
    buf->len = len;
}

canonical_original_code:
static void strbuf_realloc(struct strbuf *buf, unsigned long len)
{
    char *tmp;
    if (buf->len > len) return;
    tmp = realloc(buf->ptr, len);
    if (!tmp) {
        print_error("realloc(3)");
        exit(1);
    }
    buf->ptr = tmp;
    buf->len = len;
}

variable_types:
len
unsigned long

variable_types:
tmp
char *

user_defined_types: struct strbuf { char *ptr; unsigned long len; }


traverse

decompiled_code:
int __fastcall traverse(__int64 a1)
{
return traverse0(a1, 1);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
return func10(a1, 1);
}

original_code:
static void
traverse(struct strbuf *pathbuf)
{
    traverse0(pathbuf, 1);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char **v3; // rbp
size_t v4; // rax

if ( argc != 2 )
{
fprintf(_bss_start, "Usage: %s <dir>\n", *argv);
exit(1);
}
program_name = (__int64)*argv;
v3 = (char **)strbuf_new();
v4 = strlen(argv[1]);
strbuf_realloc((__int64)v3, v4);
strcpy(*v3, argv[1]);
traverse((__int64)v3);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char **v3; // rbp
size_t v4; // rax

if ( argc != 2 )
{
fprintf(_bss_start, "Usage: %s <dir>\n", *argv);
exit(1);
}
program_name = (__int64)*argv;
v3 = (char **)func8();
v4 = strlen(argv[1]);
func9((__int64)v3, v4);
strcpy(*v3, argv[1]);
func11((__int64)v3);
exit(0);
}

original_code:
int
main(int argc, char *argv[])
{
    struct strbuf *pathbuf;
    if (argc != 2) {
        fprintf(stderr, "Usage: %s <dir>\n", argv[0]);
        exit(1);
    }
    program_name = argv[0];
    pathbuf = strbuf_new();
    strbuf_realloc(pathbuf, strlen(argv[1]));
    strcpy(pathbuf->ptr, argv[1]);
    traverse(pathbuf);
    exit(0);
}


decompiled_code:
void __fastcall __noreturn print_exit(unsigned int a1)
{
printf("Got signal %d\n", a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(unsigned int a1)
{
printf("Got signal %d\n", a1);
exit(0);
}

original_code:
void
print_exit(int sig)
{
    printf("Got signal %d\n", sig);
    exit(0);
}

variable_types: sig int


decompiled_code:
__sighandler_t __fastcall trap_signal(int sig, void (*a2)(int))
{
bool v2; // sf
__sighandler_t result; // rax
struct sigaction v4; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v5; // [rsp+A0h] [rbp-A8h] BYREF

v5.sa_handler = a2;
sigemptyset(&v5.sa_mask);
v5.sa_flags = 0x10000000;
v2 = sigaction(sig, &v5, &v4) < 0;
result = 0LL;
if ( !v2 )
result = v4.sa_handler;
return result;
}

canonical_decompiled_code:
__sighandler_t __fastcall func8(int sig, void (*a2)(int))
{
bool v2; // sf
__sighandler_t result; // rax
struct sigaction v4; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v5; // [rsp+A0h] [rbp-A8h] BYREF

v5.sa_handler = a2;
sigemptyset(&v5.sa_mask);
v5.sa_flags = 0x10000000;
v2 = sigaction(sig, &v5, &v4) < 0;
result = 0LL;
if ( !v2 )
result = v4.sa_handler;
return result;
}

original_code:
sighandler_t
trap_signal(int sig, sighandler_t handler)
{
    struct sigaction act, old;
    act.__sigaction_handler.sa_handler = handler;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0x10000000;
    if (sigaction(sig, &act, &old) < 0)
        return ((void *)0);
    return old.__sigaction_handler.sa_handler;
}

canonical_original_code:
void (*trap_signal(int sig, void (*handler)(int)))(int)
{
    struct sigaction act; struct sigaction old;
    act.__sigaction_handler.sa_handler = handler;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0x10000000;
    if (sigaction(sig, &act, &old) < 0)
        return ((void *)0);
    return old.__sigaction_handler.sa_handler;
}

variable_types:
handler
void (*)(int)

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

return_type: void (*)(int)

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
trap_signal(2, (void (*)(int))print_exit);
pause();
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func8(2, (void (*)(int))print_exit);
pause();
exit(0);
}

original_code:
int
main(int argc, char *argv[])
{
    trap_signal(2, print_exit);
    pause();
    exit(0);
}


filetype

decompiled_code:
const char *__fastcall filetype(__int16 a1)
{
int v1; // edi
const char *result; // rax

v1 = a1 & 0xF000;
result = "file";
if ( v1 != 0x8000 )
{
result = "directory";
if ( v1 != 0x4000 )
{
switch ( v1 )
{
case 8192:
result = "chardev";
break;
case 24576:
result = "blockdev";
break;
case 4096:
result = "fifo";
break;
case 40960:
result = "symlink";
break;
default:
result = "unknown";
if ( v1 == 49152 )
result = "socket";
break;
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(__int16 a1)
{
int v1; // edi
const char *result; // rax

v1 = a1 & 0xF000;
result = "file";
if ( v1 != 0x8000 )
{
result = "directory";
if ( v1 != 0x4000 )
{
switch ( v1 )
{
case 8192:
result = "chardev";
break;
case 24576:
result = "blockdev";
break;
case 4096:
result = "fifo";
break;
case 40960:
result = "symlink";
break;
default:
result = "unknown";
if ( v1 == 49152 )
result = "socket";
break;
}
}
}
return result;
}

variable_types:
mode
unsigned int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int16 v3; // bx
const char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
struct stat v8; // [rsp+0h] [rbp-98h] BYREF

if ( argc != 2 )
{
fwrite("wrong argument\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
if ( (int)lstat((char *)argv[1], &v8) >= 0 )
{
v3 = v8.st_mode;
v4 = filetype(v8.st_mode);
printf("type\t%o (%s)\n", v3 & 0xF000, v4);
printf("mode\t%o\n", v8.st_mode & 0xFFFF0FFF);
printf("dev\t%llu\n", v8.st_dev);
printf("ino\t%lu\n", v8.st_ino);
printf("rdev\t%llu\n", v8.st_rdev);
printf("nlink\t%d\n", v8.st_nlink);
printf("uid\t%d\n", v8.st_uid);
printf("gid\t%d\n", v8.st_gid);
printf("size\t%ld\n", v8.st_size);
printf("blksize\t%lu\n", v8.st_blksize);
printf("blocks\t%lu\n", v8.st_blocks);
v5 = ctime(&v8.st_atim.tv_sec);
printf("atime\t%s", v5);
v6 = ctime(&v8.st_mtim.tv_sec);
printf("mtime\t%s", v6);
v7 = ctime(&v8.st_ctim.tv_sec);
printf("ctime\t%s", v7);
exit(0);
}
perror(argv[1]);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int16 v3; // bx
const char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
struct stat v8; // [rsp+0h] [rbp-98h] BYREF

if ( argc != 2 )
{
fwrite("wrong argument\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
if ( (int)func10((char *)argv[1], &v8) >= 0 )
{
v3 = v8.st_mode;
v4 = func7(v8.st_mode);
printf("type\t%o (%s)\n", v3 & 0xF000, v4);
printf("mode\t%o\n", v8.st_mode & 0xFFFF0FFF);
printf("dev\t%llu\n", v8.st_dev);
printf("ino\t%lu\n", v8.st_ino);
printf("rdev\t%llu\n", v8.st_rdev);
printf("nlink\t%d\n", v8.st_nlink);
printf("uid\t%d\n", v8.st_uid);
printf("gid\t%d\n", v8.st_gid);
printf("size\t%ld\n", v8.st_size);
printf("blksize\t%lu\n", v8.st_blksize);
printf("blocks\t%lu\n", v8.st_blocks);
v5 = ctime(&v8.st_atim.tv_sec);
printf("atime\t%s", v5);
v6 = ctime(&v8.st_mtim.tv_sec);
printf("mtime\t%s", v6);
v7 = ctime(&v8.st_ctim.tv_sec);
printf("ctime\t%s", v7);
exit(0);
}
perror(argv[1]);
exit(1);
}

original_code:
int
main(int argc, char *argv[])
{
    struct stat st;
    if (argc != 2) {
        fprintf(stderr, "wrong argument\n");
        exit(1);
    }
    if (lstat(argv[1], &st) < 0) {
        perror(argv[1]);
        exit(1);
    }
    printf("type\t%o (%s)\n", (st.st_mode & 0170000), filetype(st.st_mode));
    printf("mode\t%o\n", st.st_mode & ~0170000);
    printf("dev\t%llu\n", (unsigned long long)st.st_dev);
    printf("ino\t%lu\n", (unsigned long)st.st_ino);
    printf("rdev\t%llu\n", (unsigned long long)st.st_rdev);
    printf("nlink\t%d\n", st.st_nlink);
    printf("uid\t%d\n", st.st_uid);
    printf("gid\t%d\n", st.st_gid);
    printf("size\t%ld\n", st.st_size);
    printf("blksize\t%lu\n", (unsigned long)st.st_blksize);
    printf("blocks\t%lu\n", (unsigned long)st.st_blocks);
    printf("atime\t%s", ctime(&st.st_atim.tv_sec));
    printf("mtime\t%s", ctime(&st.st_mtim.tv_sec));
    printf("ctime\t%s", ctime(&st.st_ctim.tv_sec));
    exit(0);
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
char *my_getcwd()
{
char *v0; // r12
int *v1; // r13
size_t v2; // rbp
char *v3; // rax

v0 = (char *)malloc(0x400uLL);
if ( v0 )
{
v1 = __errno_location();
v2 = 1024LL;
while ( 1 )
{
*v1 = 0;
if ( getcwd(v0, v2) )
break;
if ( *v1 != 34 || (v2 *= 2LL, (v3 = (char *)realloc(v0, v2)) == 0LL) )
{
free(v0);
return 0LL;
}
v0 = v3;
}
}
return v0;
}

canonical_decompiled_code:
char *func7()
{
char *v0; // r12
int *v1; // r13
size_t v2; // rbp
char *v3; // rax

v0 = (char *)malloc(0x400uLL);
if ( v0 )
{
v1 = __errno_location();
v2 = 1024LL;
while ( 1 )
{
*v1 = 0;
if ( getcwd(v0, v2) )
break;
if ( *v1 != 34 || (v2 *= 2LL, (v3 = (char *)realloc(v0, v2)) == 0LL) )
{
free(v0);
return 0LL;
}
v0 = v3;
}
}
return v0;
}

original_code:
char*
my_getcwd(void)
{
    char *buf, *tmp;
    size_t size = 1024;
    buf = malloc(size);
    if (!buf) return ((void *)0);
    for (;;) {
        (*__errno_location ()) = 0;
        if (getcwd(buf, size))
            return buf;
        if ((*__errno_location ()) != 34) break;
        size *= 2;
        tmp = realloc(buf, size);
        if (!tmp) break;
        buf = tmp;
    }
    free(buf);
    return ((void *)0);
}

canonical_original_code:
char *my_getcwd()
{
    char *buf; char *tmp;
    unsigned long size = 1024;
    buf = malloc(size);
    if (!buf) return ((void *)0);
    for (;;) {
        (*__errno_location ()) = 0;
        if (getcwd(buf, size))
            return buf;
        if ((*__errno_location ()) != 34) break;
        size *= 2;
        tmp = realloc(buf, size);
        if (!tmp) break;
        buf = tmp;
    }
    free(buf);
    return ((void *)0);
}

variable_types:
buf
char *


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbx

v3 = my_getcwd();
if ( v3 )
{
v4 = v3;
puts(v3);
free(v4);
exit(0);
}
perror("getcwd");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbx

v3 = func7();
if ( v3 )
{
v4 = v3;
puts(v3);
free(v4);
exit(0);
}
perror("getcwd");
exit(1);
}

original_code:
int
main(int argc, char *argv[])
{
    char *path;
    path = my_getcwd();
    if (!path) {
        perror("getcwd");
        exit(1);
    }
    puts(path);
    free(path);
    exit(0);
}

variable_types:
path
char *


original_code:
char
f_char(void)
{
    return 128;
}

canonical_original_code:
char f_char()
{
    return 128;
}

return_type: char


original_code:
unsigned char
f_uchar(void)
{
    return 128;
}

canonical_original_code:
unsigned char f_uchar()
{
    return 128;
}

return_type: unsigned char


decompiled_code:
__int64 f_int()
{
return 128LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 128LL;
}

original_code:
int
f_int(void)
{
    return 128;
}

canonical_original_code:
int f_int()
{
    return 128;
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char v3; // al
char v4; // al
char v5; // al

v3 = f_char(argc, argv, envp);
printf("char\t%d\n", (unsigned int)v3);
v4 = f_uchar();
printf("uchar\t%d\n", (unsigned int)v4);
v5 = f_int();
printf("int\t%d\n", (unsigned int)v5);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char v3; // al
char v4; // al
char v5; // al

v3 = func7(argc, argv, envp);
printf("char\t%d\n", (unsigned int)v3);
v4 = func8();
printf("uchar\t%d\n", (unsigned int)v4);
v5 = func9();
printf("int\t%d\n", (unsigned int)v5);
exit(0);
}

original_code:
int
main(int argc, char *argv[])
{
    char c;
    c = f_char();
    printf("char\t%d\n", (int)c);
    c = f_uchar();
    printf("uchar\t%d\n", (int)c);
    c = f_int();
    printf("int\t%d\n", (int)c);
    exit(0);
}

variable_types: c char


readshow

decompiled_code:
int __fastcall readshow(unsigned int a1)
{
int v1; // eax
int buf[4]; // [rsp+8h] [rbp-10h] BYREF

v1 = read(a1, buf, 1uLL);
if ( v1 < 0 )
{
perror("read");
exit(1);
}
if ( !v1 )
exit(0);
switch ( LOBYTE(buf[0]) )
{
case 9:
strcpy((char *)buf, "\\t");
break;
case 0xA:
strcpy((char *)buf, "\\n");
break;
case 0xB:
strcpy((char *)buf, "\\v");
break;
case 0xD:
strcpy((char *)buf, "\\r");
break;
case 0x20:
buf[0] = 2564135;
break;
default:
BYTE1(buf[0]) = 0;
break;
}
return printf("fd%d: %s\n", a1, (const char *)buf);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
int v1; // eax
int buf[4]; // [rsp+8h] [rbp-10h] BYREF

v1 = read(a1, buf, 1uLL);
if ( v1 < 0 )
{
perror("read");
exit(1);
}
if ( !v1 )
exit(0);
switch ( LOBYTE(buf[0]) )
{
case 9:
strcpy((char *)buf, "\\t");
break;
case 0xA:
strcpy((char *)buf, "\\n");
break;
case 0xB:
strcpy((char *)buf, "\\v");
break;
case 0xD:
strcpy((char *)buf, "\\r");
break;
case 0x20:
buf[0] = 2564135;
break;
default:
BYTE1(buf[0]) = 0;
break;
}
return printf("fd%d: %s\n", a1, (const char *)buf);
}

original_code:
static void
readshow(int fd)
{
    char buf[8];
    int n;
    n = read(fd, buf, 1);
    if (n < 0) {
        perror("read");
        exit(1);
    }
    if (n == 0)
        exit(0);
    switch (buf[0]) {
      case ' ': strcpy(buf, "' '"); break;
      case '\n': strcpy(buf, "\\n"); break;
      case '\r': strcpy(buf, "\\r"); break;
      case '\t': strcpy(buf, "\\t"); break;
      case '\v': strcpy(buf, "\\v"); break;
      default:
        buf[1] = '\0';
        break;
    }
    printf("fd%d: %s\n", fd, buf);
}

variable_types: fd int

variable_types:
buf
char [8]