ConvertSRTTimestamp

decompiled_code:
__int64 __fastcall ConvertSRTTimestamp(const char **a1, _DWORD *a2)
{
const char *v2; // r12
__int64 i; // rbp
int v4; // ebx
char v5; // r14
const unsigned __int16 **v6; // r15
__int16 v7; // di
int v8; // ebp
__int64 j; // r14
char v10; // r11
__int16 v11; // cx
int v12; // ebp
__int64 k; // r14
char v14; // r9
__int16 v15; // dx
int v16; // ebp
__int64 l; // r14
char v18; // di
unsigned __int16 v19; // dx
__int64 v20; // r14
const char *v22; // rax
char *v23; // r12
__int64 v24; // r13
const char *v25; // rax
char *v26; // r15
__int64 v27; // rbp
const char *v28; // rax
char *v29; // rbx
__int64 v30; // r12
const char *v31; // rax
char *v32; // r13
__int64 v33; // r15
unsigned int v34; // [rsp+Ch] [rbp-5Ch]
unsigned int v35; // [rsp+Ch] [rbp-5Ch]
unsigned int v36; // [rsp+Ch] [rbp-5Ch]
unsigned int v37; // [rsp+Ch] [rbp-5Ch]
int v39; // [rsp+20h] [rbp-48h] BYREF
int v40; // [rsp+24h] [rbp-44h] BYREF
int v41; // [rsp+28h] [rbp-40h] BYREF
int v42[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v42[0] = 0;
v41 = 0;
v40 = 0;
v39 = 0;
if ( !a1 )
{
v2 = 0LL;
goto LABEL_71;
}
v2 = *a1;
if ( !*a1 )
{
v34 = 0;
v4 = 1;
goto LABEL_12;
}
if ( ((*_ctype_b_loc())[*v2] & 0x800) == 0 )
{
LABEL_71:
v34 = 0;
v4 = 1;
goto LABEL_12;
}
for ( i = 0LL; ; ++i )
{
v34 = i;
v4 = i + 1;
assert_wrapper(v2 != 0LL);
v5 = v2[i + 1];
if ( !v5 )
break;
v6 = _ctype_b_loc();
v7 = (*v6)[v5] & 0x800;
if ( v5 != 58 && !v7 )
break;
if ( !v7 )
{
v8 = i + 2;
assert_wrapper(v34 <= 3);
*((_BYTE *)v42 + v34) = 0;
for ( j = 0LL; ; ++j )
{
v35 = j;
v4 = v8 + j;
assert_wrapper(v2 != 0LL);
v10 = v2[(unsigned int)(v8 + j)];
if ( !v10 )
break;
v11 = (*v6)[v10] & 0x800;
if ( v10 != 58 && !v11 )
break;
if ( !v11 )
{
v12 = v4 + 1;
assert_wrapper((unsigned int)j <= 3);
*((_BYTE *)&v41 + (unsigned int)j) = 0;
for ( k = 0LL; ; ++k )
{
v36 = k;
v4 = v12 + k;
assert_wrapper(v2 != 0LL);
v14 = v2[(unsigned int)(v12 + k)];
if ( !v14 )
break;
v15 = (*v6)[v14] & 0x800;
if ( v14 != 44 && !v15 )
break;
if ( !v15 )
{
v16 = v4 + 1;
assert_wrapper((unsigned int)k <= 3);
*((_BYTE *)&v40 + (unsigned int)k) = 0;
for ( l = 0LL; ; ++l )
{
v37 = l;
v4 = v16 + l;
assert_wrapper(v2 != 0LL);
v18 = v2[(unsigned int)(v16 + l)];
if ( !v18 )
goto LABEL_40;
v19 = (*v6)[v18];
if ( (v19 & 0x800) == 0 )
{
if ( (v19 & 0x2000) == 0 )
goto LABEL_37;
LABEL_40:
assert_wrapper((unsigned int)l <= 3);
*((_BYTE *)&v39 + (unsigned int)l) = 0;
goto LABEL_41;
}
if ( l == 4 )
break;
*((_BYTE *)&v39 + l) = v18;
}
v37 = 4;
goto LABEL_37;
}
if ( k == 4 )
{
v36 = 4;
goto LABEL_30;
}
*((_BYTE *)&v40 + k) = v14;
}
goto LABEL_30;
}
if ( j == 4 )
{
v35 = 4;
goto LABEL_21;
}
*((_BYTE *)&v41 + j) = v10;
}
goto LABEL_21;
}
if ( i == 4 )
{
v34 = 4;
break;
}
*((_BYTE *)v42 + i) = v5;
}
LABEL_12:
assert_wrapper(v34 <= 3);
*((_BYTE *)v42 + v34) = 0;
v35 = 0;
LABEL_21:
assert_wrapper(v35 <= 3);
*((_BYTE *)&v41 + v35) = 0;
v36 = 0;
LABEL_30:
assert_wrapper(v36 <= 3);
*((_BYTE *)&v40 + v36) = 0;
v37 = 0;
LABEL_37:
assert_wrapper(v37 <= 3);
*((_BYTE *)&v39 + v37) = 0;
printf("Error: Invalid timestamp \"%s\"\n", v2);
if ( a2 )
{
*a2 = 1;
v20 = 0LL;
}
else
{
puts("Aborting");
exit_wrapper(1LL);
LABEL_41:
assert_wrapper((a1 != 0LL) & (unsigned __int8)(v2 != 0LL));
*a1 = &v2[v4 + 1];
v22 = (const char *)RemoveLeadingZeroes(v42);
v23 = (char *)v22;
if ( *v22 == 48 )
{
v20 = 0LL;
}
else
{
v24 = atol(v22);
if ( v24 <= 0 )
{
puts("Error converting string to integer\nAborting");
free(v23);
if ( a2 )
{
*a2 = 2;
return 0LL;
}
exit_wrapper(2LL);
}
v20 = 3600000 * v24;
}
free(v23);
v25 = (const char *)RemoveLeadingZeroes(&v41);
v26 = (char *)v25;
if ( *v25 != 48 )
{
v27 = atol(v25);
if ( v27 <= 0 )
{
puts("Error converting string to integer\nAborting");
free(v26);
if ( a2 )
{
*a2 = 2;
return 0LL;
}
exit_wrapper(2LL);
}
v20 += 60000 * v27;
}
free(v26);
v28 = (const char *)RemoveLeadingZeroes(&v40);
v29 = (char *)v28;
if ( *v28 != 48 )
{
v30 = atol(v28);
if ( v30 <= 0 )
{
puts("Error converting string to integer\nAborting");
free(v29);
if ( a2 )
{
*a2 = 3;
return 0LL;
}
exit_wrapper(3LL);
}
v20 += 1000 * v30;
}
free(v29);
v31 = (const char *)RemoveLeadingZeroes(&v39);
v32 = (char *)v31;
if ( *v31 != 48 )
{
v33 = atol(v31);
if ( v33 <= 0 )
{
puts("Error converting string to integer\nAborting");
free(v32);
if ( a2 )
{
*a2 = 4;
return 0LL;
}
exit_wrapper(4LL);
}
v20 += v33;
}
free(v32);
}
return v20;
}

original_code:
unsigned long ConvertSRTTimestamp(char **ptr,int *errorstatus)
{
 char *temp=((void *)0);
 unsigned int ctr=1;
 char failed=0;
 char hours[3 +1]={0};
 char minutes[3 +1]={0};
 char seconds[3 +1]={0};
 char millis[3 +1]={0};
 unsigned int index=0;
 unsigned long sum=0;
 long conversion=0;
 if(ptr == ((void *)0))
  failed=1;
 else
 {
  temp=*ptr;
  if(temp == ((void *)0))
   failed=1;
 }
 if((temp != ((void *)0)) && !((*__ctype_b_loc ())[(int) ((temp[0]))] & (unsigned short int) _ISdigit))
  failed=1;
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || (!((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit) && (temp[ctr] != ':')))
   failed=1;
  else
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit))
   {
    if(index > 3)
     failed=2;
    else
     hours[index++]=temp[ctr++];
   }
   else
   {
    ctr++;
    break;
   }
  }
 }
 assert_wrapper(index < 3 +1);
 hours[index]='\0';
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || (!((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit) && (temp[ctr] != ':')))
   failed=1;
  else
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit))
   {
    if(index > 3)
     failed=2;
    else
     minutes[index++]=temp[ctr++];
   }
   else
   {
    ctr++;
    break;
   }
  }
 }
 assert_wrapper(index < 3 +1);
 minutes[index]='\0';
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || (!((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit) && (temp[ctr] != ',')))
   failed=1;
  else
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit))
   {
    if(index > 3)
     failed=2;
    else
     seconds[index++]=temp[ctr++];
   }
   else
   {
    ctr++;
    break;
   }
  }
 }
 assert_wrapper(index < 3 +1);
 seconds[index]='\0';
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || !((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit))
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISspace) || (temp[ctr] == '\0'))
    break;
   else
    failed=1;
  }
  else
  {
   if(index > 3)
    failed=2;
   else
    millis[index++]=temp[ctr++];
  }
 }
 assert_wrapper(index < 3 +1);
 millis[index]='\0';
 if(failed)
 {
  printf("Error: Invalid timestamp \"%s\"\n",temp);
  if(errorstatus != ((void *)0))
  {
   *errorstatus=1;
   return 0;
  }
  else
  {
   (void) puts("Aborting");
   exit_wrapper(1);
  }
 }
 assert_wrapper((ptr != ((void *)0)) && (temp != ((void *)0)));
 *ptr=&(temp[ctr+1]);
 temp=RemoveLeadingZeroes(hours);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=2;
    return 0;
   }
   else
    exit_wrapper(2);
  }
  sum+=conversion*3600000;
 }
 free(temp);
 temp=RemoveLeadingZeroes(minutes);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=2;
    return 0;
   }
   else
    exit_wrapper(2);
  }
  sum+=conversion*60000;
 }
 free(temp);
 temp=RemoveLeadingZeroes(seconds);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=3;
    return 0;
   }
   else
    exit_wrapper(3);
  }
  sum+=conversion*1000;
 }
 free(temp);
 temp=RemoveLeadingZeroes(millis);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=4;
    return 0;
   }
   else
    exit_wrapper(4);
  }
  sum+=conversion;
 }
 free(temp);
 return sum;
}

canonical_original_code:
unsigned long ConvertSRTTimestamp(char **ptr, int *errorstatus)
{
 char *temp = ((void *)0);
 unsigned int ctr = 1;
 char failed = 0;
 char hours[-1] = {0};
 char minutes[-1] = {0};
 char seconds[-1] = {0};
 char millis[-1] = {0};
 unsigned int index = 0;
 unsigned long sum = 0;
 long conversion = 0;
 if(ptr == ((void *)0))
  failed=1;
 else
 {
  temp=*ptr;
  if(temp == ((void *)0))
   failed=1;
 }
 if((temp != ((void *)0)) && !((*__ctype_b_loc ())[(int) ((temp[0]))] & (unsigned short) _ISdigit))
  failed=1;
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || (!((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit) && (temp[ctr] != ':')))
   failed=1;
  else
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit))
   {
    if(index > 3)
     failed=2;
    else
     hours[index++]=temp[ctr++];
   }
   else
   {
    ctr++;
    break;
   }
  }
 }
 assert_wrapper(index < 3 +1);
 hours[index]='\0';
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || (!((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit) && (temp[ctr] != ':')))
   failed=1;
  else
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit))
   {
    if(index > 3)
     failed=2;
    else
     minutes[index++]=temp[ctr++];
   }
   else
   {
    ctr++;
    break;
   }
  }
 }
 assert_wrapper(index < 3 +1);
 minutes[index]='\0';
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || (!((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit) && (temp[ctr] != ',')))
   failed=1;
  else
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit))
   {
    if(index > 3)
     failed=2;
    else
     seconds[index++]=temp[ctr++];
   }
   else
   {
    ctr++;
    break;
   }
  }
 }
 assert_wrapper(index < 3 +1);
 seconds[index]='\0';
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || !((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit))
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISspace) || (temp[ctr] == '\0'))
    break;
   else
    failed=1;
  }
  else
  {
   if(index > 3)
    failed=2;
   else
    millis[index++]=temp[ctr++];
  }
 }
 assert_wrapper(index < 3 +1);
 millis[index]='\0';
 if(failed)
 {
  printf("Error: Invalid timestamp \"%s\"\n",temp);
  if(errorstatus != ((void *)0))
  {
   *errorstatus=1;
   return 0;
  }
  else
  {
   (void) puts("Aborting");
   exit_wrapper(1);
  }
 }
 assert_wrapper((ptr != ((void *)0)) && (temp != ((void *)0)));
 *ptr=&(temp[ctr+1]);
 temp=RemoveLeadingZeroes(hours);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=2;
    return 0;
   }
   else
    exit_wrapper(2);
  }
  sum+=conversion*3600000;
 }
 free(temp);
 temp=RemoveLeadingZeroes(minutes);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=2;
    return 0;
   }
   else
    exit_wrapper(2);
  }
  sum+=conversion*60000;
 }
 free(temp);
 temp=RemoveLeadingZeroes(seconds);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=3;
    return 0;
   }
   else
    exit_wrapper(3);
  }
  sum+=conversion*1000;
 }
 free(temp);
 temp=RemoveLeadingZeroes(millis);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=4;
    return 0;
   }
   else
    exit_wrapper(4);
  }
  sum+=conversion;
 }
 free(temp);
 return sum;
}

variable_types:
ptr
char **

variable_types:
errorstatus
int *

variable_types:
temp
char *

variable_types:
ctr
unsigned int

variable_types: failed char

variable_types:
hours
char [-1]

variable_types:
minutes
char [-1]

variable_types:
seconds
char [-1]

variable_types:
millis
char [-1]

variable_types:
index
unsigned int

variable_types:
sum
unsigned long

variable_types: conversion long

return_type: unsigned long


repo: cincodenada/editor-on-fire

original_code:
static void eof_bpm_estimator_callback(void * buffer, int nsamples, int stereo)
{
 int i;
 unsigned short * buffer_sp = (unsigned short *)buffer;
 int iter = stereo ? 2 : 1;
 for(i = 0; i < nsamples / iter; i++)
 {
  eof_bpm_estimator_buffer[i] = (float)((long)buffer_sp[i * iter] - 0x8000) / (float)0x8000;
  if(stereo)
  {
   eof_bpm_estimator_buffer[i] += (float)((long)buffer_sp[i * iter + 1] - 0x8000) / (float)0x8000;
   eof_bpm_estimator_buffer[i] /= 2.0;
  }
 }
 minibpm_process(eof_bpm_estimator_state, eof_bpm_estimator_buffer, nsamples / iter);
}

canonical_original_code:
static void eof_bpm_estimator_callback(void *buffer, int nsamples, int stereo)
{
 int i;
 unsigned short *buffer_sp = (unsigned short *)buffer;
 int iter = stereo ? 2 : 1;
 for(i = 0; i < nsamples / iter; i++)
 {
  eof_bpm_estimator_buffer[i] = (float)((long)buffer_sp[i * iter] - 0x8000) / (float)0x8000;
  if(stereo)
  {
   eof_bpm_estimator_buffer[i] += (float)((long)buffer_sp[i * iter + 1] - 0x8000) / (float)0x8000;
   eof_bpm_estimator_buffer[i] /= 2.0;
  }
 }
 minibpm_process(eof_bpm_estimator_state, eof_bpm_estimator_buffer, nsamples / iter);
}

variable_types:
buffer
void *

variable_types: nsamples int

variable_types: stereo int

variable_types: i int

variable_types: iter int

return_type: void


original_code:
int EOF_TRANSFER_FROM_LC(EOF_VOCAL_TRACK * tp, struct _LYRICSSTRUCT_ * lp)
{
 struct Lyric_Line *curline;
 struct Lyric_Piece *curpiece;
 EOF_LYRIC *temp;
 unsigned long start=0;
 char startfound=0;
 char overdrive=0;
 eof_log("EOF_TRANSFER_FROM_LC() entered", 1);
 if((tp == ((void *)0)) || (lp == ((void *)0)))
  return -1;
 curline=lp->lines;
 while(curline != ((void *)0))
 {
  startfound = 0;
  overdrive = 0;
  curpiece=curline->pieces;
  while(curpiece != ((void *)0))
  {
   if((startfound == 0) && (curpiece->pitch != 96))
   {
    startfound = 1;
    start=curpiece->start;
   }
   if(curpiece->overdrive)
    overdrive = 1;
   temp=eof_vocal_track_add_lyric(tp);
   if(temp == ((void *)0))
    return -1;
   if((curpiece->pitch == 254) || (!lp->pitch_tracking))
    temp->note=0;
   else
    temp->note=(char)curpiece->pitch;
   temp->pos=curpiece->start;
   temp->length=(long)curpiece->duration;
   if(ustrlen(curpiece->lyric) > 255)
    return -1;
   if(curpiece->pitch == 96)
    (void) ustrzcpy(temp->text, 0x7fffffff, "");
   else
    (void) ustrzcpy(temp->text, 0x7fffffff, curpiece->lyric);
   if((curpiece->next == ((void *)0)) && startfound)
   {
    (void) eof_vocal_track_add_line(tp,start,curpiece->start + curpiece->duration);
    if(overdrive && (tp->lines > 0))
     tp->line[tp->lines-1].flags |= 1;
   }
   curpiece=curpiece->next;
  }
  curline=curline->next;
 }
 eof_log("\tLyrics imported", 1);
 return 0;
}

canonical_original_code:
int EOF_TRANSFER_FROM_LC(struct EOF_VOCAL_TRACK *tp, struct _LYRICSSTRUCT_ *lp)
{
 struct Lyric_Line *curline;
 struct Lyric_Piece *curpiece;
 struct EOF_LYRIC *temp;
 unsigned long start = 0;
 char startfound = 0;
 char overdrive = 0;
 eof_log("EOF_TRANSFER_FROM_LC() entered", 1);
 if((tp == ((void *)0)) || (lp == ((void *)0)))
  return -1;
 curline=lp->lines;
 while(curline != ((void *)0))
 {
  startfound = 0;
  overdrive = 0;
  curpiece=curline->pieces;
  while(curpiece != ((void *)0))
  {
   if((startfound == 0) && (curpiece->pitch != 96))
   {
    startfound = 1;
    start=curpiece->start;
   }
   if(curpiece->overdrive)
    overdrive = 1;
   temp=eof_vocal_track_add_lyric(tp);
   if(temp == ((void *)0))
    return -1;
   if((curpiece->pitch == 254) || (!lp->pitch_tracking))
    temp->note=0;
   else
    temp->note=(char)curpiece->pitch;
   temp->pos=curpiece->start;
   temp->length=(long)curpiece->duration;
   if(ustrlen(curpiece->lyric) > 255)
    return -1;
   if(curpiece->pitch == 96)
    (void) ustrzcpy(temp->text, 0x7fffffff, "");
   else
    (void) ustrzcpy(temp->text, 0x7fffffff, curpiece->lyric);
   if((curpiece->next == ((void *)0)) && startfound)
   {
    (void) eof_vocal_track_add_line(tp,start,curpiece->start + curpiece->duration);
    if(overdrive && (tp->lines > 0))
     tp->line[tp->lines-1].flags |= 1;
   }
   curpiece=curpiece->next;
  }
  curline=curline->next;
 }
 eof_log("\tLyrics imported", 1);
 return 0;
}

variable_types: struct EOF_VOCAL_TRACK { unsigned char toneset; struct EOF_TRACK_ENTRY { char track_format; char track_behavior; char track_type; unsigned long tracknum; char name[-1]; char altname[-1]; unsigned char difficulty; unsigned char numdiffs; unsigned long flags; } *parent; struct EOF_LYRIC { unsigned char type; unsigned char note; char text[-1]; unsigned long midi_pos; long midi_length; unsigned long pos; long length; unsigned long flags; unsigned char tflags; } *lyric[32768]; unsigned long lyrics; struct EOF_PHRASE_SECTION { unsigned long midi_start_pos; unsigned long midi_end_pos; unsigned long start_pos; unsigned long end_pos; unsigned long flags; char name[-1]; unsigned char difficulty; } line[4096]; unsigned long lines; } *

variable_types: struct _LYRICSSTRUCT_ { struct Lyric_Line { struct Lyric_Piece { unsigned long start; unsigned long duration; unsigned char pitch; char overdrive; char freestyle; char groupswithnext; char hasequal; char *lyric; char leadspace; char trailspace; struct Lyric_Piece *next; struct Lyric_Piece *prev; } *pieces; struct Lyric_Piece *curpiece; struct Lyric_Line *prev; struct Lyric_Line *next; unsigned long piececount; unsigned long start; unsigned long duration; } *lines; struct Lyric_Line *curline; struct Lyric_Piece *lastpiece; struct Lyric_Piece *prevlineslast; unsigned long linecount; char line_on; char lyric_defined; char lyric_on; char overdrive_on; char freestyle_on; char *TitleStringID; char *ArtistStringID; char *AlbumStringID; char *EditorStringID; char *OffsetStringID; char *YearStringID; char *Title; char *Artist; char *Album; char *Editor; char *Offset; char *Year; long realoffset; char offsetoverride; char srcoffsetoverride; long srcrealoffset; unsigned long startstamp; char nohyphens; char noplus; char grouping; char defaultfilter; char verbose; char quick; char pitch_tracking; char startstampspecified; char brute; char marklines; char nolyrics; char notenames; char relative; char nopitch; char reinit; char nofstyle; unsigned long piececount; char *filter; unsigned char in_format; unsigned char out_format; double explicittempo; unsigned char last_pitch; struct OmitID3frame { char *frameid; struct OmitID3frame *next; } *nosrctag; char rocksmithver; char *outfilename; char *infilename; char *srclyrname; char *srcrhythmname; char *dstlyrname; char *srcfilename; char *inputtrack; char *outputtrack; } *

variable_types:
start
unsigned long

variable_types: startfound char

variable_types: overdrive char

return_type: int

user_defined_types: struct EOF_VOCAL_TRACK { unsigned char toneset; struct EOF_TRACK_ENTRY *parent; struct EOF_LYRIC *lyric[32768]; unsigned long lyrics; struct EOF_PHRASE_SECTION line[4096]; unsigned long lines; }

user_defined_types: struct _LYRICSSTRUCT_ { struct Lyric_Line *lines; struct Lyric_Line *curline; struct Lyric_Piece *lastpiece; struct Lyric_Piece *prevlineslast; unsigned long linecount; char line_on; char lyric_defined; char lyric_on; char overdrive_on; char freestyle_on; char *TitleStringID; char *ArtistStringID; char *AlbumStringID; char *EditorStringID; char *OffsetStringID; char *YearStringID; char *Title; char *Artist; char *Album; char *Editor; char *Offset; char *Year; long realoffset; char offsetoverride; char srcoffsetoverride; long srcrealoffset; unsigned long startstamp; char nohyphens; char noplus; char grouping; char defaultfilter; char verbose; char quick; char pitch_tracking; char startstampspecified; char brute; char marklines; char nolyrics; char notenames; char relative; char nopitch; char reinit; char nofstyle; unsigned long piececount; char *filter; unsigned char in_format; unsigned char out_format; double explicittempo; unsigned char last_pitch; struct OmitID3frame *nosrctag; char rocksmithver; char *outfilename; char *infilename; char *srclyrname; char *srcrhythmname; char *dstlyrname; char *srcfilename; char *inputtrack; char *outputtrack; }

user_defined_types: struct Lyric_Line { struct Lyric_Piece *pieces; struct Lyric_Piece *curpiece; struct Lyric_Line *prev; struct Lyric_Line *next; unsigned long piececount; unsigned long start; unsigned long duration; }


repo: cinsk/xobstack

decompiled_code:
void __noreturn print_and_abort()
{
fprintf(stderr, "%s\n", "memory exhausted");
exit(1);
}

canonical_decompiled_code:
void __noreturn func6()
{
fprintf(stderr, "%s\n", "memory exhausted");
exit(1);
}

original_code:
static void
__attribute__ ((noreturn))
print_and_abort (void)
{
  fprintf (stderr, "%s\n", "memory exhausted");
  exit (1);
}

canonical_original_code:
static void print_and_abort()
{
  fprintf (stderr, "%s\n", "memory exhausted");
  exit (1);
}


original_code:
void
xobs_free (struct xobs *h, void *obj)
{
  register struct _xobs_chunk *lp;
  register struct _xobs_chunk *plp;
  lp = h->chunk;
  while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
    {
      plp = lp->prev;
      do { if ((h) -> use_extra_arg) (*(h)->freefun) ((h)->extra_arg, (lp)); else (*(void (*) (void *)) (h)->freefun) ((lp)); } while (0);
      lp = plp;
      h->maybe_empty_object = 1;
    }
  if (lp)
    {
      h->object_base = h->next_free = (char *) (obj);
      h->chunk_limit = lp->limit;
      h->chunk = lp;
    }
  else if (obj != 0)
    abort ();
}

canonical_original_code:
void xobs_free(struct xobs *h, void *obj)
{
  register struct _xobs_chunk *lp;
  register struct _xobs_chunk *plp;
  lp = h->chunk;
  while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
    {
      plp = lp->prev;
      do { if ((h) -> use_extra_arg) (*(h)->freefun) ((h)->extra_arg, (lp)); else (*(void (*)(void *)) (h)->freefun) ((lp)); } while (0);
      lp = plp;
      h->maybe_empty_object = 1;
    }
  if (lp)
    {
      h->object_base = h->next_free = (char *) (obj);
      h->chunk_limit = lp->limit;
      h->chunk = lp;
    }
  else if (obj != 0)
    abort ();
}

variable_types: struct xobs { long chunk_size; struct _xobs_chunk { char *limit; struct _xobs_chunk *prev; char contents[4]; } *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _xobs_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _xobs_chunk *); void (*failfun)(struct xobs *self); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; } *

variable_types:
obj
void *

user_defined_types: struct xobs { long chunk_size; struct _xobs_chunk *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _xobs_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _xobs_chunk *); void (*failfun)(struct xobs *self); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; }


decompiled_code:
__int64 xobs_sprintf_(_QWORD *a1, const char *a2, ...)
{
int v3; // er12
int v4; // ebp
char *v5; // rdi
void (__fastcall *v7)(_QWORD *); // rax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
v3 = vsnprintf(0LL, 0LL, a2, arg);
v4 = v3 + 1;
if ( a1[4] - a1[3] >= v3 + 1 || (unsigned int)_xobs_newchunk(a1, (unsigned int)v4) )
{
a1[3] += v4;
}
else
{
v7 = (void (__fastcall *)(_QWORD *))a1[9];
if ( v7 )
{
v7(a1);
}
else if ( xobs_alloc_failed_handler )
{
xobs_alloc_failed_handler();
}
}
v5 = (char *)(a1[2] + (unsigned int)a1[3] - (unsigned int)a1[2] - 1LL - v3);
va_end(arg);
va_start(arg, a2);
vsnprintf(v5, v4, a2, arg);
--a1[3];
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 func13(_QWORD *a1, const char *a2, ...)
{
int v3; // er12
int v4; // ebp
char *v5; // rdi
void (__fastcall *v7)(_QWORD *); // rax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
v3 = vsnprintf(0LL, 0LL, a2, arg);
v4 = v3 + 1;
if ( a1[4] - a1[3] >= v3 + 1 || (unsigned int)_xobs_newchunk(a1, (unsigned int)v4) )
{
a1[3] += v4;
}
else
{
v7 = (void (__fastcall *)(_QWORD *))a1[9];
if ( v7 )
{
v7(a1);
}
else if ( xobs_alloc_failed_handler )
{
xobs_alloc_failed_handler();
}
}
v5 = (char *)(a1[2] + (unsigned int)a1[3] - (unsigned int)a1[2] - 1LL - v3);
va_end(arg);
va_start(arg, a2);
vsnprintf(v5, v4, a2, arg);
--a1[3];
return (unsigned int)v3;
}

original_code:
int
xobs_sprintf_(struct xobs *obs, const char *format, ...)
{
  int len;
  va_list ap;
  char *p;
  __builtin_va_start(ap,format);
  len = vsnprintf(((void *)0), 0, format, ap);
  __builtin_va_end(ap);
  __extension__ ({ struct xobs *__o = (obs); int __len = (len + 1); int ___ok = 1; if (__o->chunk_limit - __o->next_free < __len) ___ok = _xobs_newchunk (__o, __len); if (___ok) ((__o)->next_free += (__len)); else do { if ((__o)->failfun) (*(__o)->failfun)(__o); else if (xobs_alloc_failed_handler) (*xobs_alloc_failed_handler)(); } while (0); ___ok; });
  p = ((void *) ((obs)->object_base)) + __extension__ ({ struct xobs const *__o = (obs); (unsigned) (__o->next_free - __o->object_base); }) - (len + 1);
  __builtin_va_start(ap,format);
  vsnprintf(p, len + 1, format, ap);
  __builtin_va_end(ap);
  obs->next_free--;
  return len;
}

canonical_original_code:
int xobs_sprintf_(struct xobs *obs, char *format, ...)
{
  int len;
  __builtin_va_list ap;
  char *p;
  __builtin_va_start(ap,format);
  len = vsnprintf(((void *)0), 0, format, ap);
  __builtin_va_end(ap);
  __extension__ ({ struct xobs *__o = (obs); int __len = (len + 1); int ___ok = 1; if (__o->chunk_limit - __o->next_free < __len) ___ok = _xobs_newchunk (__o, __len); if (___ok) ((__o)->next_free += (__len)); else do { if ((__o)->failfun) (*(__o)->failfun)(__o); else if (xobs_alloc_failed_handler) (*xobs_alloc_failed_handler)(); } while (0); ___ok; });
  p = ((void *) ((obs)->object_base)) + __extension__ ({ struct xobs *__o = (obs); (unsigned int) (__o->next_free - __o->object_base); }) - (len + 1);
  __builtin_va_start(ap,format);
  vsnprintf(p, len + 1, format, ap);
  __builtin_va_end(ap);
  obs->next_free--;
  return len;
}

variable_types:
format
char *

variable_types: len int

variable_types:
p
char *

user_defined_types: struct _xobs_chunk { char *limit; struct _xobs_chunk *prev; char contents[4]; }


toDecimal

repo: ciuncan/HuffmanDecompress

decompiled_code:
__int64 __fastcall toDecimal(__int64 a1, int a2)
{
char v3; // di
__int64 v4; // rax
unsigned int v5; // esi
char v6; // di

v3 = a2;
LODWORD(v4) = a2 - 1;
if ( a2 - 1 < 0 )
return 0;
v4 = (int)v4;
v5 = 0;
v6 = v3 - 1;
do
{
v5 |= *(unsigned __int8 *)(a1 + v4) << (v6 - v4);
--v4;
}
while ( (int)v4 >= 0 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
char v3; // di
__int64 v4; // rax
unsigned int v5; // esi
char v6; // di

v3 = a2;
LODWORD(v4) = a2 - 1;
if ( a2 - 1 < 0 )
return 0;
v4 = (int)v4;
v5 = 0;
v6 = v3 - 1;
do
{
v5 |= *(unsigned __int8 *)(a1 + v4) << (v6 - v4);
--v4;
}
while ( (int)v4 >= 0 );
return v5;
}

original_code:
int toDecimal(unsigned char* bits, int length) {
    int i;
    int val = 0;
    for(i = length-1; i >= 0; --i) {
        val |= bits[i] << (length - i - 1);
    }
    return val;
}

canonical_original_code:
int toDecimal(unsigned char *bits, int length) {
    int i;
    int val = 0;
    for(i = length-1; i >= 0; --i) {
        val |= bits[i] << (length - i - 1);
    }
    return val;
}

variable_types:
bits
unsigned char *

variable_types: length int

variable_types: val int


equals

decompiled_code:
__int64 __fastcall equals(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax

if ( a3 <= 0 )
return 1LL;
v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( ++v3 == a3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax

if ( a3 <= 0 )
return 1LL;
v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( ++v3 == a3 )
return 1LL;
}
return 0LL;
}

original_code:
int equals(unsigned char* first, unsigned char* second, int length) {
    int i;
    for(i = 0; i < length; ++i) {
        if(first[i] != second[i]) {
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int equals(unsigned char *first, unsigned char *second, int length) {
    int i;
    for(i = 0; i < length; ++i) {
        if(first[i] != second[i]) {
            return 0;
        }
    }
    return 1;
}

variable_types:
first
unsigned char *

variable_types:
second
unsigned char *


searchForCode

decompiled_code:
__int64 __fastcall searchForCode(__int64 a1, int a2)
{
__int64 v2; // rbx

v2 = 0LL;
while ( !(unsigned int)equals(codes[v2], a1, a2) )
{
if ( ++v2 == 255 )
return 42LL;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
__int64 v2; // rbx

v2 = 0LL;
while ( !(unsigned int)func12(codes[v2], a1, a2) )
{
if ( ++v2 == 255 )
return 42LL;
}
return (unsigned int)v2;
}

original_code:
char searchForCode(unsigned char* code, int length) {
    int i;
    for(i = 0; i < 255; ++i) {
        if(equals(codes[i], code, length)) {
            return (char) i;
        }
    }
    return '*';
}

canonical_original_code:
char searchForCode(unsigned char *code, int length) {
    int i;
    for(i = 0; i < 255; ++i) {
        if(equals(codes[i], code, length)) {
            return (char) i;
        }
    }
    return '*';
}

variable_types:
code
unsigned char *

variable_types: i int

return_type: char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 2 )
{
argv[1] = "file2.txt";
argv[2] = "file3.txt";
}
createDecompressedFile(argv[1], argv[2]);
printOutputAsCharacters(argv[2]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 2 )
{
argv[1] = "file2.txt";
argv[2] = "file3.txt";
}
func15(argv[1], argv[2]);
func16(argv[2]);
return 0;
}

original_code:
int main(int argc, char** argv) {
    if(argc < 3) {
        argv[1] = "file2.txt";
        argv[2] = "file3.txt";
    }
    createDecompressedFile(argv[1], argv[2]);
    printOutputAsCharacters(argv[2]);
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    if(argc < 3) {
        argv[1] = "file2.txt";
        argv[2] = "file3.txt";
    }
    createDecompressedFile(argv[1], argv[2]);
    printOutputAsCharacters(argv[2]);
    return (0);
}

variable_types: argc int

variable_types:
argv
char **


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

if ( a1 == 128 )
return 13LL;
if ( a1 > 0x80 )
{
if ( a1 == 2048 )
{
result = 14LL;
}
else if ( a1 <= 0x800 )
{
result = 8LL;
if ( a1 != 512 )
{
if ( a1 == 1024 )
{
result = 9LL;
}
else
{
result = 0LL;
if ( a1 == 256 )
result = 7LL;
}
}
}
else
{
result = 11LL;
if ( a1 != 0x4000 )
{
if ( a1 == 0x8000 )
{
result = 15LL;
}
else
{
result = 0LL;
if ( a1 == 4096 )
result = 10LL;
}
}
}
}
else if ( a1 > 0x20 )
{
result = 0LL;
if ( a1 == 64 )
result = 6LL;
}
else if ( a1 )
{
switch ( a1 )
{
case 1u:
result = 1LL;
break;
case 2u:
result = 2LL;
break;
case 4u:
result = 3LL;
break;
case 8u:
result = 12LL;
break;
case 0x10u:
result = 4LL;
break;
case 0x20u:
result = 5LL;
break;
default:
result = 0LL;
break;
}
}
else
{
result = 0LL;
}
return result;
}

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

if ( a1 == 128 )
return 13LL;
if ( a1 > 0x80 )
{
if ( a1 == 2048 )
{
result = 14LL;
}
else if ( a1 <= 0x800 )
{
result = 8LL;
if ( a1 != 512 )
{
if ( a1 == 1024 )
{
result = 9LL;
}
else
{
result = 0LL;
if ( a1 == 256 )
result = 7LL;
}
}
}
else
{
result = 11LL;
if ( a1 != 0x4000 )
{
if ( a1 == 0x8000 )
{
result = 15LL;
}
else
{
result = 0LL;
if ( a1 == 4096 )
result = 10LL;
}
}
}
}
else if ( a1 > 0x20 )
{
result = 0LL;
if ( a1 == 64 )
result = 6LL;
}
else if ( a1 )
{
switch ( a1 )
{
case 1u:
result = 1LL;
break;
case 2u:
result = 2LL;
break;
case 4u:
result = 3LL;
break;
case 8u:
result = 12LL;
break;
case 0x10u:
result = 4LL;
break;
case 0x20u:
result = 5LL;
break;
default:
result = 0LL;
break;
}
}
else
{
result = 0LL;
}
return result;
}

original_code:
uint8_t key_value(enum chip8_key key)
{
 switch(key)
 {
  case KEY_0:
   return 0x0;
  case KEY_1:
   return 0x1;
  case KEY_2:
   return 0x2;
  case KEY_3:
   return 0x3;
  case KEY_4:
   return 0x4;
  case KEY_5:
   return 0x5;
  case KEY_6:
   return 0x6;
  case KEY_7:
   return 0x7;
  case KEY_8:
   return 0x8;
  case KEY_9:
   return 0x9;
  case KEY_A:
   return 0xA;
  case KEY_B:
   return 0xB;
  case KEY_C:
   return 0xC;
  case KEY_D:
   return 0xD;
  case KEY_E:
   return 0xE;
  case KEY_F:
   return 0xF;
 }
 return 0x0;
}

canonical_original_code:
unsigned char key_value(enum chip8_key key)
{
 switch(key)
 {
  case KEY_0:
   return 0x0;
  case KEY_1:
   return 0x1;
  case KEY_2:
   return 0x2;
  case KEY_3:
   return 0x3;
  case KEY_4:
   return 0x4;
  case KEY_5:
   return 0x5;
  case KEY_6:
   return 0x6;
  case KEY_7:
   return 0x7;
  case KEY_8:
   return 0x8;
  case KEY_9:
   return 0x9;
  case KEY_A:
   return 0xA;
  case KEY_B:
   return 0xB;
  case KEY_C:
   return 0xC;
  case KEY_D:
   return 0xD;
  case KEY_E:
   return 0xE;
  case KEY_F:
   return 0xF;
 }
 return 0x0;
}

return_type: unsigned char


decompiled_code:
__int16 __fastcall keypad_helper(__int64 a1, __int64 a2, __int16 a3, __int64 a4, __int64 a5, __int64 a6, char a7, int a8)
{
__int16 result; // ax

switch ( a8 )
{
case 'b':
a3 = 2048;
break;
case 'c':
a3 = 512;
break;
case 'd':
a3 = 32;
break;
case 'e':
a3 = 2;
break;
case 'f':
a3 = 64;
break;
case 'g':
a3 = 128;
break;
case 'h':
a3 = 4096;
break;
case 'j':
a3 = 0x2000;
break;
case 'k':
a3 = 0x4000;
break;
case 'l':
a3 = 0x8000;
break;
case 'q':
*(_BYTE *)(a1 + 54) = 8;
break;
case 'r':
a3 = 4;
break;
case 's':
a3 = 16;
break;
case 't':
a3 = 8;
break;
case 'v':
a3 = 1024;
break;
case 'w':
a3 = 1;
break;
case 'x':
a3 = 256;
break;
default:
break;
}
if ( a7 == 2 )
result = *(_WORD *)(a1 + 2108) | a3;
else
result = *(_WORD *)(a1 + 2108) & ~a3;
*(_WORD *)(a1 + 2108) = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func3(__int64 a1, __int64 a2, __int16 a3, __int64 a4, __int64 a5, __int64 a6, char a7, int a8)
{
__int16 result; // ax

switch ( a8 )
{
case 'b':
a3 = 2048;
break;
case 'c':
a3 = 512;
break;
case 'd':
a3 = 32;
break;
case 'e':
a3 = 2;
break;
case 'f':
a3 = 64;
break;
case 'g':
a3 = 128;
break;
case 'h':
a3 = 4096;
break;
case 'j':
a3 = 0x2000;
break;
case 'k':
a3 = 0x4000;
break;
case 'l':
a3 = 0x8000;
break;
case 'q':
*(_BYTE *)(a1 + 54) = 8;
break;
case 'r':
a3 = 4;
break;
case 's':
a3 = 16;
break;
case 't':
a3 = 8;
break;
case 'v':
a3 = 1024;
break;
case 'w':
a3 = 1;
break;
case 'x':
a3 = 256;
break;
default:
break;
}
if ( a7 == 2 )
result = *(_WORD *)(a1 + 2108) | a3;
else
result = *(_WORD *)(a1 + 2108) & ~a3;
*(_WORD *)(a1 + 2108) = result;
return result;
}

original_code:
void keypad_helper(cpu_t* cpu,SDL_KeyboardEvent ke)
{
 enum chip8_key affected_key;
 switch(ke.keysym.sym)
 {
  case SDLK_w:
   affected_key = KEY_1;
   break;
  case SDLK_e:
   affected_key = KEY_2;
   break;
  case SDLK_r:
   affected_key = KEY_3;
   break;
  case SDLK_t:
   affected_key = KEY_C;
   break;
  case SDLK_s:
   affected_key = KEY_4;
   break;
  case SDLK_d:
   affected_key = KEY_5;
   break;
  case SDLK_f:
   affected_key = KEY_6;
   break;
  case SDLK_g:
   affected_key = KEY_D;
   break;
  case SDLK_x:
   affected_key = KEY_7;
   break;
  case SDLK_c:
   affected_key = KEY_8;
   break;
  case SDLK_v:
   affected_key = KEY_9;
   break;
  case SDLK_b:
   affected_key = KEY_E;
   break;
  case SDLK_h:
   affected_key = KEY_A;
   break;
  case SDLK_j:
   affected_key = KEY_0;
   break;
  case SDLK_k:
   affected_key = KEY_B;
   break;
  case SDLK_l:
   affected_key = KEY_F;
   break;
  case SDLK_q:
   cpu->errno = EUSRQ;
   break;
  default:
   break;
 }
 if(ke.type == SDL_KEYDOWN)
 {
  cpu->keypad |= affected_key;
 }
 else
 {
  cpu->keypad &= ~affected_key;
 }
}

canonical_original_code:
void keypad_helper(struct cpu_t *cpu, struct SDL_KeyboardEvent ke)
{
 enum chip8_key affected_key;
 switch(ke.keysym.sym)
 {
  case SDLK_w:
   affected_key = KEY_1;
   break;
  case SDLK_e:
   affected_key = KEY_2;
   break;
  case SDLK_r:
   affected_key = KEY_3;
   break;
  case SDLK_t:
   affected_key = KEY_C;
   break;
  case SDLK_s:
   affected_key = KEY_4;
   break;
  case SDLK_d:
   affected_key = KEY_5;
   break;
  case SDLK_f:
   affected_key = KEY_6;
   break;
  case SDLK_g:
   affected_key = KEY_D;
   break;
  case SDLK_x:
   affected_key = KEY_7;
   break;
  case SDLK_c:
   affected_key = KEY_8;
   break;
  case SDLK_v:
   affected_key = KEY_9;
   break;
  case SDLK_b:
   affected_key = KEY_E;
   break;
  case SDLK_h:
   affected_key = KEY_A;
   break;
  case SDLK_j:
   affected_key = KEY_0;
   break;
  case SDLK_k:
   affected_key = KEY_B;
   break;
  case SDLK_l:
   affected_key = KEY_F;
   break;
  case SDLK_q:
   cpu->errno = EUSRQ;
   break;
  default:
   break;
 }
 if(ke.type == SDL_KEYDOWN)
 {
  cpu->keypad |= affected_key;
 }
 else
 {
  cpu->keypad &= ~affected_key;
 }
}

variable_types: struct cpu_t { unsigned char registers[16]; unsigned char delay; unsigned char sound; unsigned char stack_pointer; unsigned short pc; unsigned short stack[16]; unsigned char errno; unsigned short address; unsigned char screen[64][32]; unsigned char draw; unsigned short keypad; unsigned char *memory; enum boolean { b_FALSE=0, b_TRUE=1 } wait; unsigned short breakpoint; enum boolean { b_FALSE=0, b_TRUE=1 } stepping; } *

variable_types: struct SDL_KeyboardEvent { unsigned char type; unsigned char which; unsigned char state; struct SDL_keysym { unsigned char scancode; enum SDLKey { SDLK_UNKNOWN=0, SDLK_FIRST=0, SDLK_BACKSPACE=8, SDLK_TAB=9, SDLK_CLEAR=12, SDLK_RETURN=13, SDLK_PAUSE=19, SDLK_ESCAPE=27, SDLK_SPACE=32, SDLK_EXCLAIM=33, SDLK_QUOTEDBL=34, SDLK_HASH=35, SDLK_DOLLAR=36, SDLK_AMPERSAND=38, SDLK_QUOTE=39, SDLK_LEFTPAREN=40, SDLK_RIGHTPAREN=41, SDLK_ASTERISK=42, SDLK_PLUS=43, SDLK_COMMA=44, SDLK_MINUS=45, SDLK_PERIOD=46, SDLK_SLASH=47, SDLK_0=48, SDLK_1=49, SDLK_2=50, SDLK_3=51, SDLK_4=52, SDLK_5=53, SDLK_6=54, SDLK_7=55, SDLK_8=56, SDLK_9=57, SDLK_COLON=58, SDLK_SEMICOLON=59, SDLK_LESS=60, SDLK_EQUALS=61, SDLK_GREATER=62, SDLK_QUESTION=63, SDLK_AT=64, SDLK_LEFTBRACKET=91, SDLK_BACKSLASH=92, SDLK_RIGHTBRACKET=93, SDLK_CARET=94, SDLK_UNDERSCORE=95, SDLK_BACKQUOTE=96, SDLK_a=97, SDLK_b=98, SDLK_c=99, SDLK_d=100, SDLK_e=101, SDLK_f=102, SDLK_g=103, SDLK_h=104, SDLK_i=105, SDLK_j=106, SDLK_k=107, SDLK_l=108, SDLK_m=109, SDLK_n=110, SDLK_o=111, SDLK_p=112, SDLK_q=113, SDLK_r=114, SDLK_s=115, SDLK_t=116, SDLK_u=117, SDLK_v=118, SDLK_w=119, SDLK_x=120, SDLK_y=121, SDLK_z=122, SDLK_DELETE=127, SDLK_WORLD_0=160, SDLK_WORLD_1=161, SDLK_WORLD_2=162, SDLK_WORLD_3=163, SDLK_WORLD_4=164, SDLK_WORLD_5=165, SDLK_WORLD_6=166, SDLK_WORLD_7=167, SDLK_WORLD_8=168, SDLK_WORLD_9=169, SDLK_WORLD_10=170, SDLK_WORLD_11=171, SDLK_WORLD_12=172, SDLK_WORLD_13=173, SDLK_WORLD_14=174, SDLK_WORLD_15=175, SDLK_WORLD_16=176, SDLK_WORLD_17=177, SDLK_WORLD_18=178, SDLK_WORLD_19=179, SDLK_WORLD_20=180, SDLK_WORLD_21=181, SDLK_WORLD_22=182, SDLK_WORLD_23=183, SDLK_WORLD_24=184, SDLK_WORLD_25=185, SDLK_WORLD_26=186, SDLK_WORLD_27=187, SDLK_WORLD_28=188, SDLK_WORLD_29=189, SDLK_WORLD_30=190, SDLK_WORLD_31=191, SDLK_WORLD_32=192, SDLK_WORLD_33=193, SDLK_WORLD_34=194, SDLK_WORLD_35=195, SDLK_WORLD_36=196, SDLK_WORLD_37=197, SDLK_WORLD_38=198, SDLK_WORLD_39=199, SDLK_WORLD_40=200, SDLK_WORLD_41=201, SDLK_WORLD_42=202, SDLK_WORLD_43=203, SDLK_WORLD_44=204, SDLK_WORLD_45=205, SDLK_WORLD_46=206, SDLK_WORLD_47=207, SDLK_WORLD_48=208, SDLK_WORLD_49=209, SDLK_WORLD_50=210, SDLK_WORLD_51=211, SDLK_WORLD_52=212, SDLK_WORLD_53=213, SDLK_WORLD_54=214, SDLK_WORLD_55=215, SDLK_WORLD_56=216, SDLK_WORLD_57=217, SDLK_WORLD_58=218, SDLK_WORLD_59=219, SDLK_WORLD_60=220, SDLK_WORLD_61=221, SDLK_WORLD_62=222, SDLK_WORLD_63=223, SDLK_WORLD_64=224, SDLK_WORLD_65=225, SDLK_WORLD_66=226, SDLK_WORLD_67=227, SDLK_WORLD_68=228, SDLK_WORLD_69=229, SDLK_WORLD_70=230, SDLK_WORLD_71=231, SDLK_WORLD_72=232, SDLK_WORLD_73=233, SDLK_WORLD_74=234, SDLK_WORLD_75=235, SDLK_WORLD_76=236, SDLK_WORLD_77=237, SDLK_WORLD_78=238, SDLK_WORLD_79=239, SDLK_WORLD_80=240, SDLK_WORLD_81=241, SDLK_WORLD_82=242, SDLK_WORLD_83=243, SDLK_WORLD_84=244, SDLK_WORLD_85=245, SDLK_WORLD_86=246, SDLK_WORLD_87=247, SDLK_WORLD_88=248, SDLK_WORLD_89=249, SDLK_WORLD_90=250, SDLK_WORLD_91=251, SDLK_WORLD_92=252, SDLK_WORLD_93=253, SDLK_WORLD_94=254, SDLK_WORLD_95=255, SDLK_KP0=256, SDLK_KP1=257, SDLK_KP2=258, SDLK_KP3=259, SDLK_KP4=260, SDLK_KP5=261, SDLK_KP6=262, SDLK_KP7=263, SDLK_KP8=264, SDLK_KP9=265, SDLK_KP_PERIOD=266, SDLK_KP_DIVIDE=267, SDLK_KP_MULTIPLY=268, SDLK_KP_MINUS=269, SDLK_KP_PLUS=270, SDLK_KP_ENTER=271, SDLK_KP_EQUALS=272, SDLK_UP=273, SDLK_DOWN=274, SDLK_RIGHT=275, SDLK_LEFT=276, SDLK_INSERT=277, SDLK_HOME=278, SDLK_END=279, SDLK_PAGEUP=280, SDLK_PAGEDOWN=281, SDLK_F1=282, SDLK_F2=283, SDLK_F3=284, SDLK_F4=285, SDLK_F5=286, SDLK_F6=287, SDLK_F7=288, SDLK_F8=289, SDLK_F9=290, SDLK_F10=291, SDLK_F11=292, SDLK_F12=293, SDLK_F13=294, SDLK_F14=295, SDLK_F15=296, SDLK_NUMLOCK=300, SDLK_CAPSLOCK=301, SDLK_SCROLLOCK=302, SDLK_RSHIFT=303, SDLK_LSHIFT=304, SDLK_RCTRL=305, SDLK_LCTRL=306, SDLK_RALT=307, SDLK_LALT=308, SDLK_RMETA=309, SDLK_LMETA=310, SDLK_LSUPER=311, SDLK_RSUPER=312, SDLK_MODE=313, SDLK_COMPOSE=314, SDLK_HELP=315, SDLK_PRINT=316, SDLK_SYSREQ=317, SDLK_BREAK=318, SDLK_MENU=319, SDLK_POWER=320, SDLK_EURO=321, SDLK_UNDO=322, SDLK_LAST=323 } sym; enum SDLMod { KMOD_NONE=0, KMOD_LSHIFT=1, KMOD_RSHIFT=2, KMOD_LCTRL=64, KMOD_RCTRL=128, KMOD_LALT=256, KMOD_RALT=512, KMOD_LMETA=1024, KMOD_RMETA=2048, KMOD_NUM=4096, KMOD_CAPS=8192, KMOD_MODE=16384, KMOD_RESERVED=32768 } mod; unsigned short unicode; } keysym; }

user_defined_types: struct SDL_KeyboardEvent { unsigned char type; unsigned char which; unsigned char state; struct SDL_keysym keysym; }

user_defined_types: struct cpu_t { unsigned char registers[16]; unsigned char delay; unsigned char sound; unsigned char stack_pointer; unsigned short pc; unsigned short stack[16]; unsigned char errno; unsigned short address; unsigned char screen[64][32]; unsigned char draw; unsigned short keypad; unsigned char *memory; enum boolean wait; unsigned short breakpoint; enum boolean stepping; }

user_defined_types: struct SDL_keysym { unsigned char scancode; enum SDLKey sym; enum SDLMod mod; unsigned short unicode; }


repo: cjpl/daq

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
__int16 v4; // bx
__int16 v5; // dx
__int64 v6; // rdi
unsigned int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)(argc - 3) > 1 )
{
puts("Usage: CAENVMEDemo V1718 <VMEDevice>");
puts(" CAENVMEDemo V2718 <VMEDevice> <VMELink>");
exit(1);
}
v3 = argv[1];
if ( !strcmp(v3, "V1718") )
{
if ( argc != 3 )
{
puts(" CAENVMEDemo V1718 <VMEDevice>");
exit(1);
}
v4 = atoi(argv[2]);
v5 = 0;
v6 = 0LL;
}
else
{
if ( strcmp(v3, "V2718") )
{
puts("Usage: CAENVMEDemo V1718 <VMEDevice>");
puts(" CAENVMEDemo V2718 <VMEDevice> <VMELink>");
exit(1);
}
if ( argc != 4 )
{
puts(" CAENVMEDemo V2718 <VMEDevice> <VMELink>");
exit(1);
}
v4 = atoi(argv[2]);
v5 = atoi(argv[3]);
v6 = 1LL;
}
if ( (unsigned int)CAENVME_Init(v6, (unsigned int)v4, (unsigned int)v5, v8) )
{
puts("\n\n Error opening the device");
exit(1);
}
con_init();
CaenVmeManual((int)v8[0], 1LL);
con_end();
CAENVME_End(v8[0]);
return 0;
}

original_code:
int main(int argc, void *argv[])
{
    CVBoardTypes VMEBoard;
    short Link;
    short Device;
    int32_t BHandle;
    if( (argc != 3) && (argc != 4) )
    {
        printf("Usage: CAENVMEDemo V1718 <VMEDevice>\n");
        printf("       CAENVMEDemo V2718 <VMEDevice> <VMELink>\n");
        exit(1);
    }
    else
    {
        if( strcmp((char*)argv[1], "V1718") == 0 )
        {
            if( argc == 3 )
            {
                VMEBoard = cvV1718;
                Device = atoi((const char*)argv[2]);
                Link = 0;
            }
            else
            {
                printf("       CAENVMEDemo V1718 <VMEDevice>\n");
                exit(1);
            }
        }
        else
        {
            if( strcmp((char*)argv[1], "V2718") == 0 )
            {
                if( argc == 4 )
                {
                    Device = atoi((const char*) argv[2]);
                    Link = atoi((const char*) argv[3]);
                    VMEBoard = cvV2718;
                }
                else
                {
                    printf("       CAENVMEDemo V2718 <VMEDevice> <VMELink>\n");
                    exit(1);
                }
            }
            else
            {
                printf("Usage: CAENVMEDemo V1718 <VMEDevice>\n");
                printf("       CAENVMEDemo V2718 <VMEDevice> <VMELink>\n");
                exit(1);
            }
        }
    }
    if( CAENVME_Init(VMEBoard, Device, Link, &BHandle) != cvSuccess )
    {
        printf("\n\n Error opening the device\n");
        exit(1);
    }
    con_init() ;
    CaenVmeManual(BHandle,1) ;
    con_end() ;
    CAENVME_End(BHandle);
}

canonical_original_code:
int main(int argc, void *argv[])
{
    enum CVBoardTypes VMEBoard;
    short Link;
    short Device;
    int BHandle;
    if( (argc != 3) && (argc != 4) )
    {
        printf("Usage: CAENVMEDemo V1718 <VMEDevice>\n");
        printf("       CAENVMEDemo V2718 <VMEDevice> <VMELink>\n");
        exit(1);
    }
    else
    {
        if( strcmp((char *)argv[1], "V1718") == 0 )
        {
            if( argc == 3 )
            {
                VMEBoard = cvV1718;
                Device = atoi((char *)argv[2]);
                Link = 0;
            }
            else
            {
                printf("       CAENVMEDemo V1718 <VMEDevice>\n");
                exit(1);
            }
        }
        else
        {
            if( strcmp((char *)argv[1], "V2718") == 0 )
            {
                if( argc == 4 )
                {
                    Device = atoi((char *) argv[2]);
                    Link = atoi((char *) argv[3]);
                    VMEBoard = cvV2718;
                }
                else
                {
                    printf("       CAENVMEDemo V2718 <VMEDevice> <VMELink>\n");
                    exit(1);
                }
            }
            else
            {
                printf("Usage: CAENVMEDemo V1718 <VMEDevice>\n");
                printf("       CAENVMEDemo V2718 <VMEDevice> <VMELink>\n");
                exit(1);
            }
        }
    }
    if( CAENVME_Init(VMEBoard, Device, Link, &BHandle) != cvSuccess )
    {
        printf("\n\n Error opening the device\n");
        exit(1);
    }
    con_init() ;
    CaenVmeManual(BHandle,1) ;
    con_end() ;
    CAENVME_End(BHandle);
}

variable_types:
argv
void *[]

variable_types: Link short

variable_types: Device short

variable_types: BHandle int


decompiled_code:
int con_init()
{
initscr();
cbreak();
noecho();
nodelay(stdscr, 0);
return curs_set(0);
}

canonical_decompiled_code:
int func0()
{
initscr();
cbreak();
noecho();
nodelay(stdscr, 0);
return curs_set(0);
}

original_code:
void con_init()
{
    initscr();
    cbreak();
    noecho();
    nodelay(stdscr, 0);
    curs_set(0);
}


decompiled_code:
int con_end()
{
return endwin();
}

canonical_decompiled_code:
int func1()
{
return endwin();
}

original_code:
void con_end()
{
    endwin();
}

canonical_original_code:
void con_end()
{
    endwin();
}


decompiled_code:
int __fastcall write_log(const char *a1)
{
if ( !log_file )
{
log_file = fopen(LOG_FILE_NAME, "w");
if ( !log_file )
{
puts("\n\nCan't open log file\n");
exit(0);
}
}
fprintf(log_file, "%s\n", a1);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
if ( !log_file )
{
log_file = fopen(LOG_FILE_NAME, "w");
if ( !log_file )
{
puts("\n\nCan't open log file\n");
exit(0);
}
}
fprintf(log_file, "%s\n", a1);
return fflush(stdout);
}

original_code:
void write_log(char *msg)
{
    if(log_file == ((void *)0))
    {
        log_file = fopen(LOG_FILE_NAME,"w");
        if(log_file == ((void *)0))
        {
            printf("\n\nCan't open log file\n\n");
            exit(0);
        }
    }
    fprintf(log_file,"%s\n",msg);
    fflush(stdout);
}

variable_types:
msg
char *


decompiled_code:
int con_getch()
{
int result; // eax

do
result = wgetch(stdscr);
while ( result == -1 );
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax

do
result = wgetch(stdscr);
while ( result == -1 );
return result;
}

original_code:
int con_getch(void)
{
    int i;
    while( ( i = wgetch(stdscr) ) == (-1) );
    return i;
}

canonical_original_code:
int con_getch()
{
    int i;
    while( ( i = wgetch(stdscr) ) == (-1) );
    return i;
}


decompiled_code:
__int64 con_kbhit()
{
unsigned int v0; // ebx

nodelay(stdscr, 1);
v0 = wgetch(stdscr);
if ( v0 == -1 )
v0 = 0;
nodelay(stdscr, 0);
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebx

nodelay(stdscr, 1);
v0 = wgetch(stdscr);
if ( v0 == -1 )
v0 = 0;
nodelay(stdscr, 0);
return v0;
}

original_code:
char con_kbhit()
{
    int i, g;
    nodelay(stdscr, 1);
    i = ( ( g = wgetch(stdscr) ) == (-1) ? 0 : g );
    nodelay(stdscr, 0);
    return i;
}

canonical_original_code:
char con_kbhit()
{
    int i; int g;
    nodelay(stdscr, 1);
    i = ( ( g = wgetch(stdscr) ) == (-1) ? 0 : g );
    nodelay(stdscr, 0);
    return i;
}

variable_types: g int


decompiled_code:
__int64 __fastcall con_scanf(char *a1, __int64 a2)
{
unsigned int v2; // ebx

echo();
v2 = scanw(a1, a2);
wrefresh(stdscr);
noecho();
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, __int64 a2)
{
unsigned int v2; // ebx

echo();
v2 = scanw(a1, a2);
wrefresh(stdscr);
noecho();
return v2;
}

original_code:
int con_scanf(char *fmt, void *app)
{
    int i;
    echo();
    i = scanw(fmt,app);
    wrefresh(stdscr);
    noecho();
    return i;
}

variable_types:
fmt
char *

variable_types:
app
void *


decompiled_code:
__int64 con_printf(char *a1, ...)
{
unsigned int v1; // ebx
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a1);
v1 = vwprintw(stdscr, a1, va);
wrefresh(stdscr);
return v1;
}

canonical_decompiled_code:
__int64 func6(char *a1, ...)
{
unsigned int v1; // ebx
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a1);
v1 = vwprintw(stdscr, a1, va);
wrefresh(stdscr);
return v1;
}

original_code:
int con_printf(char *fmt,...)
{
    va_list marker;
    int i;
    __builtin_va_start(marker,fmt);
    i = vwprintw(stdscr,fmt,marker);
    __builtin_va_end(marker);
    wrefresh(stdscr);
    return i;
}

canonical_original_code:
int con_printf(char *fmt, ...)
{
    __builtin_va_list marker;
    int i;
    __builtin_va_start(marker,fmt);
    i = vwprintw(stdscr,fmt,marker);
    __builtin_va_end(marker);
    wrefresh(stdscr);
    return i;
}


gotoxy

decompiled_code:
int __fastcall gotoxy(int a1, int a2)
{
wmove(stdscr, a2 - 1, a1 - 1);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2)
{
wmove(stdscr, a2 - 1, a1 - 1);
return wrefresh(stdscr);
}

original_code:
void gotoxy(int x, int y)
{
    wmove(stdscr,(y-1),(x-1));
    wrefresh(stdscr);
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 con_printf_xy(int a1, int a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a3);
wmove(stdscr, a2 - 1, a1 - 1);
wrefresh(stdscr);
LODWORD(a3) = vwprintw(stdscr, a3, va);
wrefresh(stdscr);
return (unsigned int)a3;
}

canonical_decompiled_code:
__int64 func8(int a1, int a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a3);
wmove(stdscr, a2 - 1, a1 - 1);
wrefresh(stdscr);
LODWORD(a3) = vwprintw(stdscr, a3, va);
wrefresh(stdscr);
return (unsigned int)a3;
}

original_code:
int con_printf_xy(unsigned int xpos, unsigned int ypos, char *fmt,...)
{
    va_list marker;
    int i;
    wmove(stdscr,(ypos-1),(xpos-1));
    wrefresh(stdscr);
    __builtin_va_start(marker,fmt);
    i = vwprintw(stdscr,fmt,marker);
    __builtin_va_end(marker);
    wrefresh(stdscr);
    return i;
}

canonical_original_code:
int con_printf_xy(unsigned int xpos, unsigned int ypos, char *fmt, ...)
{
    __builtin_va_list marker;
    int i;
    wmove(stdscr,(ypos-1),(xpos-1));
    wrefresh(stdscr);
    __builtin_va_start(marker,fmt);
    i = vwprintw(stdscr,fmt,marker);
    __builtin_va_end(marker);
    wrefresh(stdscr);
    return i;
}

variable_types:
xpos
unsigned int

variable_types:
ypos
unsigned int


clrscr

decompiled_code:
int clrscr()
{
wclear(stdscr);
wmove(stdscr, 0, 0);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func9()
{
wclear(stdscr);
wmove(stdscr, 0, 0);
return wrefresh(stdscr);
}

original_code:
void clrscr(void)
{
    wclear(stdscr);
    wmove(stdscr,(0),(0));
    wrefresh(stdscr);
}

canonical_original_code:
void clrscr()
{
    wclear(stdscr);
    wmove(stdscr,(0),(0));
    wrefresh(stdscr);
}


decompiled_code:
int __fastcall clear_line(int a1)
{
gotoxy(1, a1);
return wclrtoeol(stdscr);
}

canonical_decompiled_code:
int __fastcall func10(int a1)
{
func7(1, a1);
return wclrtoeol(stdscr);
}

original_code:
void clear_line(unsigned int line)
{
    gotoxy(1, line);
    wclrtoeol(stdscr);
}

variable_types:
line
unsigned int


delay

decompiled_code:
int __fastcall delay(int a1)
{
return usleep(1000 * a1);
}

canonical_decompiled_code:
int __fastcall func11(int a1)
{
return usleep(1000 * a1);
}

original_code:
void delay(int msec)
{
    usleep(msec*1000);
}

variable_types: msec int


repo: cklin/mdm

decompiled_code:
__int64 __fastcall serv_listen(char *name)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // ebp
_BYTE v5[104]; // [rsp+0h] [rbp-98h] BYREF
int v6; // [rsp+68h] [rbp-30h]
__int16 v7; // [rsp+6Ch] [rbp-2Ch]

v1 = socket(1, 1, 0);
if ( v1 < 0 )
{
warn("socket");
v2 = -1;
}
else
{
v2 = v1;
v3 = strlen(name);
if ( v3 > 0x6B )
{
warnx("serv_listen: socket name too long");
v2 = -2;
}
else
{
memset(v5, 0, sizeof(v5));
v6 = 0;
v7 = 0;
*(_WORD *)v5 = 1;
strcpy(&v5[2], name);
unlink(name);
if ( bind(v2, (const struct sockaddr *)v5, v3 + 2) < 0 )
{
warn("bind");
v2 = -3;
}
else if ( listen(v2, 5) < 0 )
{
warn("listen");
v2 = -4;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *name)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // ebp
_BYTE v5[104]; // [rsp+0h] [rbp-98h] BYREF
int v6; // [rsp+68h] [rbp-30h]
__int16 v7; // [rsp+6Ch] [rbp-2Ch]

v1 = socket(1, 1, 0);
if ( v1 < 0 )
{
warn("socket");
v2 = -1;
}
else
{
v2 = v1;
v3 = strlen(name);
if ( v3 > 0x6B )
{
warnx("serv_listen: socket name too long");
v2 = -2;
}
else
{
memset(v5, 0, sizeof(v5));
v6 = 0;
v7 = 0;
*(_WORD *)v5 = 1;
strcpy(&v5[2], name);
unlink(name);
if ( bind(v2, (const struct sockaddr *)v5, v3 + 2) < 0 )
{
warn("bind");
v2 = -3;
}
else if ( listen(v2, 5) < 0 )
{
warn("listen");
v2 = -4;
}
}
}
return v2;
}

original_code:
int serv_listen(const char *name)
{
  int sockfd, addrlen;
  struct sockaddr_un unix_addr;
  struct sockaddr *sock_addr;
  sockfd = socket(1, SOCK_STREAM, 0);
  if (sockfd < 0) {
    warn("socket");
    return -1;
  }
  addrlen = strlen(name);
  if (addrlen >= sizeof (unix_addr.sun_path)) {
    warnx("serv_listen: socket name too long");
    return -2;
  }
  addrlen += sizeof (unix_addr.sun_family);
  memset(&unix_addr, 0, sizeof (unix_addr));
  unix_addr.sun_family = 1;
  strcpy(unix_addr.sun_path, name);
  unlink(name);
  sock_addr = (struct sockaddr *) &unix_addr;
  if (bind(sockfd, sock_addr, addrlen) < 0) {
    warn("bind");
    return -3;
  }
  if (listen(sockfd, 5) < 0) {
    warn("listen");
    return -4;
  }
  return sockfd;
}

canonical_original_code:
int serv_listen(char *name)
{
  int sockfd; int addrlen;
  struct sockaddr_un unix_addr;
  struct sockaddr *sock_addr;
  sockfd = socket(1, SOCK_STREAM, 0);
  if (sockfd < 0) {
    warn("socket");
    return -1;
  }
  addrlen = strlen(name);
  if (addrlen >= sizeof (unix_addr.sun_path)) {
    warnx("serv_listen: socket name too long");
    return -2;
  }
  addrlen += sizeof (unix_addr.sun_family);
  memset(&unix_addr, 0, sizeof (unix_addr));
  unix_addr.sun_family = 1;
  strcpy(unix_addr.sun_path, name);
  unlink(name);
  sock_addr = (struct sockaddr *) &unix_addr;
  if (bind(sockfd, sock_addr, addrlen) < 0) {
    warn("bind");
    return -3;
  }
  if (listen(sockfd, 5) < 0) {
    warn("listen");
    return -4;
  }
  return sockfd;
}

variable_types:
name
char *

variable_types: sockfd int

variable_types: addrlen int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

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


decompiled_code:
__int64 __fastcall serv_accept(int a1)
{
int v1; // ebx

v1 = accept(a1, 0LL, 0LL);
if ( v1 < 0 )
warn("accept");
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // ebx

v1 = accept(a1, 0LL, 0LL);
if ( v1 < 0 )
warn("accept");
return (unsigned int)v1;
}

original_code:
int serv_accept(int listenfd)
{
  int connfd;
  connfd = accept(listenfd, ((void *)0), ((void *)0));
  if (connfd < 0)
    warn("accept");
  return connfd;
}

variable_types: listenfd int

variable_types: connfd int


decompiled_code:
__int64 __fastcall cli_conn(char *src)
{
int v1; // eax
unsigned int v2; // ebp
unsigned int v3; // ebx
_BYTE v5[104]; // [rsp+0h] [rbp-98h] BYREF
int v6; // [rsp+68h] [rbp-30h]
__int16 v7; // [rsp+6Ch] [rbp-2Ch]

v1 = socket(1, 1, 0);
if ( v1 < 0 )
{
warn("socket");
v2 = -1;
}
else
{
v2 = v1;
v3 = strlen(src);
if ( v3 > 0x6B )
{
warnx("serv_listen: socket name too long");
v2 = -2;
}
else
{
memset(v5, 0, sizeof(v5));
v6 = 0;
v7 = 0;
*(_WORD *)v5 = 1;
strcpy(&v5[2], src);
if ( connect(v2, (const struct sockaddr *)v5, v3 + 2) < 0 )
{
warn("connect");
v2 = -3;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src)
{
int v1; // eax
unsigned int v2; // ebp
unsigned int v3; // ebx
_BYTE v5[104]; // [rsp+0h] [rbp-98h] BYREF
int v6; // [rsp+68h] [rbp-30h]
__int16 v7; // [rsp+6Ch] [rbp-2Ch]

v1 = socket(1, 1, 0);
if ( v1 < 0 )
{
warn("socket");
v2 = -1;
}
else
{
v2 = v1;
v3 = strlen(src);
if ( v3 > 0x6B )
{
warnx("serv_listen: socket name too long");
v2 = -2;
}
else
{
memset(v5, 0, sizeof(v5));
v6 = 0;
v7 = 0;
*(_WORD *)v5 = 1;
strcpy(&v5[2], src);
if ( connect(v2, (const struct sockaddr *)v5, v3 + 2) < 0 )
{
warn("connect");
v2 = -3;
}
}
}
return v2;
}

original_code:
int cli_conn(const char *name)
{
  int sockfd, addrlen;
  struct sockaddr_un unix_addr;
  struct sockaddr *sock_addr;
  sockfd = socket(1, SOCK_STREAM, 0);
  if (sockfd < 0) {
    warn("socket");
    return -1;
  }
  addrlen = strlen(name);
  if (addrlen >= sizeof (unix_addr.sun_path)) {
    warnx("serv_listen: socket name too long");
    return -2;
  }
  addrlen += sizeof (unix_addr.sun_family);
  memset(&unix_addr, 0, sizeof (unix_addr));
  unix_addr.sun_family = 1;
  strcpy(unix_addr.sun_path, name);
  sock_addr = (struct sockaddr *) &unix_addr;
  if (connect(sockfd, sock_addr, addrlen) < 0) {
    warn("connect");
    return -3;
  }
  return sockfd;
}

canonical_original_code:
int cli_conn(char *name)
{
  int sockfd; int addrlen;
  struct sockaddr_un unix_addr;
  struct sockaddr *sock_addr;
  sockfd = socket(1, SOCK_STREAM, 0);
  if (sockfd < 0) {
    warn("socket");
    return -1;
  }
  addrlen = strlen(name);
  if (addrlen >= sizeof (unix_addr.sun_path)) {
    warnx("serv_listen: socket name too long");
    return -2;
  }
  addrlen += sizeof (unix_addr.sun_family);
  memset(&unix_addr, 0, sizeof (unix_addr));
  unix_addr.sun_family = 1;
  strcpy(unix_addr.sun_path, name);
  sock_addr = (struct sockaddr *) &unix_addr;
  if (connect(sockfd, sock_addr, addrlen) < 0) {
    warn("connect");
    return -3;
  }
  return sockfd;
}

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

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


readn

decompiled_code:
size_t __fastcall readn(int fd, void *buf, size_t nbytes)
{
size_t v3; // r14
size_t v5; // rbp
ssize_t v6; // rax
ssize_t v7; // rbx

v3 = nbytes;
if ( !nbytes )
return v3;
v5 = nbytes;
while ( 1 )
{
v6 = read(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
if ( v6 < 0 )
warn("read");
return v7;
}

canonical_decompiled_code:
size_t __fastcall func3(int fd, void *buf, size_t nbytes)
{
size_t v3; // r14
size_t v5; // rbp
ssize_t v6; // rax
ssize_t v7; // rbx

v3 = nbytes;
if ( !nbytes )
return v3;
v5 = nbytes;
while ( 1 )
{
v6 = read(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
if ( v6 < 0 )
warn("read");
return v7;
}

original_code:
ssize_t readn(int fd, void *vptr, size_t n)
{
  size_t remaining;
  ssize_t received;
  char *ptr;
  remaining = n;
  ptr = vptr;
  while (remaining > 0) {
    received = read(fd, ptr, remaining);
    if (received <= 0) {
      if (received < 0) warn("read");
      return received;
    }
    remaining -= received;
    ptr += received;
  }
  return n;
}

canonical_original_code:
long readn(int fd, void *vptr, unsigned long n)
{
  unsigned long remaining;
  long received;
  char *ptr;
  remaining = n;
  ptr = vptr;
  while (remaining > 0) {
    received = read(fd, ptr, remaining);
    if (received <= 0) {
      if (received < 0) warn("read");
      return received;
    }
    remaining -= received;
    ptr += received;
  }
  return n;
}

variable_types: fd int

variable_types:
vptr
void *

variable_types:
n
unsigned long

variable_types:
remaining
unsigned long

variable_types: received long

variable_types:
ptr
char *

return_type: long


writen

decompiled_code:
size_t __fastcall writen(int fd, void *buf, size_t n)
{
size_t v3; // r14
size_t v5; // rbp
ssize_t v6; // rax
ssize_t v7; // rbx

v3 = n;
if ( !n )
return v3;
v5 = n;
while ( 1 )
{
v6 = write(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
if ( v6 < 0 )
warn("write");
return v7;
}

canonical_decompiled_code:
size_t __fastcall func4(int fd, void *buf, size_t n)
{
size_t v3; // r14
size_t v5; // rbp
ssize_t v6; // rax
ssize_t v7; // rbx

v3 = n;
if ( !n )
return v3;
v5 = n;
while ( 1 )
{
v6 = write(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
if ( v6 < 0 )
warn("write");
return v7;
}

original_code:
ssize_t writen(int fd, const void *vptr, size_t n)
{
  size_t remaining;
  ssize_t written;
  const char *ptr;
  remaining = n;
  ptr = vptr;
  while (remaining > 0) {
    written = write(fd, ptr, remaining);
    if (written <= 0) {
      if (written < 0) warn("write");
      return written;
    }
    remaining -= written;
    ptr += written;
  }
  return n;
}

canonical_original_code:
long writen(int fd, void *vptr, unsigned long n)
{
  unsigned long remaining;
  long written;
  char *ptr;
  remaining = n;
  ptr = vptr;
  while (remaining > 0) {
    written = write(fd, ptr, remaining);
    if (written <= 0) {
      if (written < 0) warn("write");
      return written;
    }
    remaining -= written;
    ptr += written;
  }
  return n;
}

variable_types: written long


decompiled_code:
__int64 __fastcall send_fd(int fd, int a2)
{
_DWORD *v2; // rax
char v4; // [rsp+Fh] [rbp-69h] BYREF
struct msghdr message; // [rsp+10h] [rbp-68h] BYREF
__int64 v6[5]; // [rsp+50h] [rbp-28h] BYREF

v4 = 0;
v6[0] = (__int64)&v4;
v6[1] = 1LL;
message.msg_iov = (iovec *)v6;
message.msg_iovlen = 1LL;
message.msg_name = 0LL;
message.msg_namelen = 0;
if ( !cmptr )
cmptr = xmalloc(20LL);
v2 = (_DWORD *)cmptr;
*(_DWORD *)(cmptr + 8) = 1;
v2[3] = 1;
*(_QWORD *)v2 = 20LL;
message.msg_control = v2;
message.msg_controllen = 20LL;
v2[4] = a2;
if ( sendmsg(fd, &message, 0) == 1 )
return 0LL;
warn("send_fd sendmsg");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, int a2)
{
_DWORD *v2; // rax
char v4; // [rsp+Fh] [rbp-69h] BYREF
struct msghdr message; // [rsp+10h] [rbp-68h] BYREF
__int64 v6[5]; // [rsp+50h] [rbp-28h] BYREF

v4 = 0;
v6[0] = (__int64)&v4;
v6[1] = 1LL;
message.msg_iov = (iovec *)v6;
message.msg_iovlen = 1LL;
message.msg_name = 0LL;
message.msg_namelen = 0;
if ( !cmptr )
cmptr = xmalloc(20LL);
v2 = (_DWORD *)cmptr;
*(_DWORD *)(cmptr + 8) = 1;
v2[3] = 1;
*(_QWORD *)v2 = 20LL;
message.msg_control = v2;
message.msg_controllen = 20LL;
v2[4] = a2;
if ( sendmsg(fd, &message, 0) == 1 )
return 0LL;
warn("send_fd sendmsg");
return 0xFFFFFFFFLL;
}

original_code:
int send_fd(int sockfd, int fd)
{
  struct iovec iov;
  struct msghdr msg;
  char ch;
  ch = 0;
  iov.iov_base = &ch;
  iov.iov_len = 1;
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  msg.msg_name = ((void *)0);
  msg.msg_namelen = 0;
  if (!cmptr) cmptr = xmalloc((sizeof (struct cmsghdr)+sizeof (int)));
  cmptr->cmsg_level = 1;
  cmptr->cmsg_type = SCM_RIGHTS;
  cmptr->cmsg_len = (sizeof (struct cmsghdr)+sizeof (int));
  msg.msg_control = (caddr_t) cmptr;
  msg.msg_controllen = (sizeof (struct cmsghdr)+sizeof (int));
  *(int *) ((cmptr)->__cmsg_data) = fd;
  if (sendmsg(sockfd, &msg, 0) != 1) {
    warn("send_fd sendmsg");
    return -1;
  }
  return 0;
}

canonical_original_code:
int send_fd(int sockfd, int fd)
{
  struct iovec iov;
  struct msghdr msg;
  char ch;
  ch = 0;
  iov.iov_base = &ch;
  iov.iov_len = 1;
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  msg.msg_name = ((void *)0);
  msg.msg_namelen = 0;
  if (!cmptr) cmptr = xmalloc((sizeof (struct cmsghdr)+sizeof (int)));
  cmptr->cmsg_level = 1;
  cmptr->cmsg_type = SCM_RIGHTS;
  cmptr->cmsg_len = (sizeof (struct cmsghdr)+sizeof (int));
  msg.msg_control = (char *) cmptr;
  msg.msg_controllen = (sizeof (struct cmsghdr)+sizeof (int));
  *(int *) ((cmptr)->__cmsg_data) = fd;
  if (sendmsg(sockfd, &msg, 0) != 1) {
    warn("send_fd sendmsg");
    return -1;
  }
  return 0;
}

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types: ch char

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

user_defined_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; }


decompiled_code:
__int64 __fastcall recv_fd(int fd)
{
unsigned int *v1; // rbx
int v2; // eax
__int64 result; // rax
char v4; // [rsp+Fh] [rbp-69h] BYREF
struct msghdr message; // [rsp+10h] [rbp-68h] BYREF
__int64 v6[5]; // [rsp+50h] [rbp-28h] BYREF

v6[0] = (__int64)&v4;
v6[1] = 1LL;
message.msg_iov = (iovec *)v6;
message.msg_iovlen = 1LL;
message.msg_name = 0LL;
message.msg_namelen = 0;
v1 = (unsigned int *)xmalloc(20LL);
message.msg_control = v1;
message.msg_controllen = 20LL;
v2 = recvmsg(fd, &message, 0);
if ( v2 < 0 )
{
warn("recv_fd recvmsg");
result = 0xFFFFFFFFLL;
}
else if ( v2 )
{
if ( v4 || message.msg_controllen != 20 )
{
warnx("recv_fd: protocol error");
result = 4294967293LL;
}
else
{
result = v1[4];
}
}
else
{
warnx("recv_fd: connection closed by server");
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd)
{
unsigned int *v1; // rbx
int v2; // eax
__int64 result; // rax
char v4; // [rsp+Fh] [rbp-69h] BYREF
struct msghdr message; // [rsp+10h] [rbp-68h] BYREF
__int64 v6[5]; // [rsp+50h] [rbp-28h] BYREF

v6[0] = (__int64)&v4;
v6[1] = 1LL;
message.msg_iov = (iovec *)v6;
message.msg_iovlen = 1LL;
message.msg_name = 0LL;
message.msg_namelen = 0;
v1 = (unsigned int *)xmalloc(20LL);
message.msg_control = v1;
message.msg_controllen = 20LL;
v2 = recvmsg(fd, &message, 0);
if ( v2 < 0 )
{
warn("recv_fd recvmsg");
result = 0xFFFFFFFFLL;
}
else if ( v2 )
{
if ( v4 || message.msg_controllen != 20 )
{
warnx("recv_fd: protocol error");
result = 4294967293LL;
}
else
{
result = v1[4];
}
}
else
{
warnx("recv_fd: connection closed by server");
result = 4294967294LL;
}
return result;
}

original_code:
int recv_fd(int sockfd)
{
  struct cmsghdr *cmptr = ((void *)0);
  struct iovec iov;
  struct msghdr msg;
  char ch;
  int nread;
  iov.iov_base = &ch;
  iov.iov_len = 1;
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  msg.msg_name = ((void *)0);
  msg.msg_namelen = 0;
  if (!cmptr) cmptr = xmalloc((sizeof (struct cmsghdr)+sizeof (int)));
  msg.msg_control = (caddr_t) cmptr;
  msg.msg_controllen = (sizeof (struct cmsghdr)+sizeof (int));
  nread = recvmsg(sockfd, &msg, 0);
  if (nread < 0) {
    warn("recv_fd recvmsg");
    return -1;
  }
  if (nread == 0) {
    warnx("recv_fd: connection closed by server");
    return -2;
  }
  if (ch == 0)
    if (msg.msg_controllen == (sizeof (struct cmsghdr)+sizeof (int)))
      return *(int *) ((cmptr)->__cmsg_data);
  warnx("recv_fd: protocol error");
  return -3;
}

canonical_original_code:
int recv_fd(int sockfd)
{
  struct cmsghdr *cmptr = ((void *)0);
  struct iovec iov;
  struct msghdr msg;
  char ch;
  int nread;
  iov.iov_base = &ch;
  iov.iov_len = 1;
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  msg.msg_name = ((void *)0);
  msg.msg_namelen = 0;
  if (!cmptr) cmptr = xmalloc((sizeof (struct cmsghdr)+sizeof (int)));
  msg.msg_control = (char *) cmptr;
  msg.msg_controllen = (sizeof (struct cmsghdr)+sizeof (int));
  nread = recvmsg(sockfd, &msg, 0);
  if (nread < 0) {
    warn("recv_fd recvmsg");
    return -1;
  }
  if (nread == 0) {
    warnx("recv_fd: connection closed by server");
    return -2;
  }
  if (ch == 0)
    if (msg.msg_controllen == (sizeof (struct cmsghdr)+sizeof (int)))
      return *(int *) ((cmptr)->__cmsg_data);
  warnx("recv_fd: protocol error");
  return -3;
}

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

variable_types: struct iovec { void *iov_base; unsigned long iov_len; }

variable_types: nread int


decompiled_code:
size_t __fastcall write_int(int a1, int a2)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return writen(a1, buf, 4uLL);
}

canonical_decompiled_code:
size_t __fastcall func7(int a1, int a2)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return func4(a1, buf, 4uLL);
}

original_code:
ssize_t write_int(int fd, int v)
{
  return writen(fd, &v, sizeof (int));
}

canonical_original_code:
long write_int(int fd, int v)
{
  return writen(fd, &v, sizeof (int));
}

variable_types: v int


decompiled_code:
size_t __fastcall write_pid(int a1, int a2)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return writen(a1, buf, 4uLL);
}

canonical_decompiled_code:
size_t __fastcall func8(int a1, int a2)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return func4(a1, buf, 4uLL);
}

original_code:
ssize_t write_pid(int fd, pid_t v)
{
  return writen(fd, &v, sizeof (pid_t));
}

canonical_original_code:
long write_pid(int fd, int v)
{
  return writen(fd, &v, sizeof (pid_t));
}


decompiled_code:
size_t __fastcall write_time(int a1, __int64 a2)
{
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

buf = a2;
return writen(a1, &buf, 8uLL);
}

canonical_decompiled_code:
size_t __fastcall func9(int a1, __int64 a2)
{
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

buf = a2;
return func4(a1, &buf, 8uLL);
}

original_code:
ssize_t write_time(int fd, time_t v)
{
  return writen(fd, &v, sizeof (time_t));
}

canonical_original_code:
long write_time(int fd, long v)
{
  return writen(fd, &v, sizeof (time_t));
}

variable_types: v long


decompiled_code:
__int64 __fastcall check_sockdir(const char *a1)
{
__int64 result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( lstat(a1, &v2) < 0 )
err(110, "stat(\"%s\")", a1);
result = v2.st_mode;
if ( (v2.st_mode & 0xF000) != 0x4000 )
errx(111, "%s is not a directory", a1);
if ( (v2.st_mode & 2) != 0 )
errx(112, "%s is world-writable", a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
__int64 result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( lstat(a1, &v2) < 0 )
err(110, "stat(\"%s\")", a1);
result = v2.st_mode;
if ( (v2.st_mode & 0xF000) != 0x4000 )
errx(111, "%s is not a directory", a1);
if ( (v2.st_mode & 2) != 0 )
errx(112, "%s is world-writable", a1);
return result;
}

original_code:
void check_sockdir(const char *path)
{
  struct stat st;
  if (lstat(path, &st) < 0)
    err(110, "stat(\"%s\")", path);
  if (! ((((st.st_mode)) & 0170000) == (0040000)))
    errx(111, "%s is not a directory", path);
  if (st.st_mode & ((0200 >> 3) >> 3))
    errx(112, "%s is world-writable", path);
}

canonical_original_code:
void check_sockdir(char *path)
{
  struct stat st;
  if (lstat(path, &st) < 0)
    err(110, "stat(\"%s\")", path);
  if (! ((((st.st_mode)) & 0170000) == (0040000)))
    errx(111, "%s is not a directory", path);
  if (st.st_mode & ((0200 >> 3) >> 3))
    errx(112, "%s is world-writable", path);
}

variable_types:
path
char *

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


conflict

decompiled_code:
__int64 __fastcall conflict(char a1, char a2, int a3)
{
unsigned int v3; // eax

LOBYTE(v3) = a1 == 87;
LOBYTE(a3) = a1 != a2;
return a3 | v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, char a2, int a3)
{
unsigned int v3; // eax

LOBYTE(v3) = a1 == 87;
LOBYTE(a3) = a1 != a2;
return a3 | v3;
}

original_code:
static _Bool conflict(char c1, char c2)
{
  return (c1 == 'W' || c1 != c2);
}


decompiled_code:
const unsigned __int16 *__fastcall read_iospec(__int64 a1, __int64 a2)
{
const unsigned __int16 *result; // rax
char v4; // bl
const unsigned __int16 *v5; // rbp
const unsigned __int16 **v6; // rcx
char v7; // dl
int v8; // esi

*(_QWORD *)(a2 + 8) = 0LL;
result = (const unsigned __int16 *)xstrdup();
*(_QWORD *)a2 = result;
v4 = *(_BYTE *)result;
if ( *(_BYTE *)result )
{
v5 = result;
v6 = _ctype_b_loc();
v7 = 0;
v8 = 0;
do
{
result = *v6;
if ( ((*v6)[v4] & 0x2000) != 0 )
{
*(_BYTE *)v5 = 0;
v7 = 1;
}
else if ( v7 )
{
if ( !*(_QWORD *)(a2 + 8) )
*(_QWORD *)(a2 + 8) = v5;
++v8;
v7 = 0;
}
v5 = (const unsigned __int16 *)((char *)v5 + 1);
v4 = *(_BYTE *)v5;
}
while ( *(_BYTE *)v5 );
}
else
{
v8 = 0;
}
*(_DWORD *)(a2 + 16) = v8;
return result;
}

canonical_decompiled_code:
const unsigned __int16 *__fastcall func2(__int64 a1, __int64 a2)
{
const unsigned __int16 *result; // rax
char v4; // bl
const unsigned __int16 *v5; // rbp
const unsigned __int16 **v6; // rcx
char v7; // dl
int v8; // esi

*(_QWORD *)(a2 + 8) = 0LL;
result = (const unsigned __int16 *)xstrdup();
*(_QWORD *)a2 = result;
v4 = *(_BYTE *)result;
if ( *(_BYTE *)result )
{
v5 = result;
v6 = _ctype_b_loc();
v7 = 0;
v8 = 0;
do
{
result = *v6;
if ( ((*v6)[v4] & 0x2000) != 0 )
{
*(_BYTE *)v5 = 0;
v7 = 1;
}
else if ( v7 )
{
if ( !*(_QWORD *)(a2 + 8) )
*(_QWORD *)(a2 + 8) = v5;
++v8;
v7 = 0;
}
v5 = (const unsigned __int16 *)((char *)v5 + 1);
v4 = *(_BYTE *)v5;
}
while ( *(_BYTE *)v5 );
}
else
{
v8 = 0;
}
*(_DWORD *)(a2 + 16) = v8;
return result;
}

original_code:
static void read_iospec(const char *spec, iospec *ios)
{
  int count;
  _Bool new_token;
  char *cp;
  ios->resources = ((void *)0);
  ios->name = xstrdup(spec);
  new_token = 0;
  for (cp=ios->name, count=0; *cp; cp++) {
    if (((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short int) _ISspace)) {
      new_token = 1;
      *cp = '\0';
      continue;
    }
    if (new_token) {
      if (ios->resources == ((void *)0))
        ios->resources = cp;
      new_token = 0;
      count++;
    }
  }
  ios->res_count = count;
}

canonical_original_code:
static void read_iospec(char *spec, struct iospec *ios)
{
  int count;
  _Bool new_token;
  char *cp;
  ios->resources = ((void *)0);
  ios->name = xstrdup(spec);
  new_token = 0;
  for (cp=ios->name, count=0; *cp; cp++) {
    if (((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short) _ISspace)) {
      new_token = 1;
      *cp = '\0';
      continue;
    }
    if (new_token) {
      if (ios->resources == ((void *)0))
        ios->resources = cp;
      new_token = 0;
      count++;
    }
  }
  ios->res_count = count;
}

variable_types:
spec
char *

variable_types: struct iospec { char *name; char *resources; int res_count; } *

variable_types: count int

variable_types:
cp
char *


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

if ( uti_count <= 0 )
return 0LL;
v2 = 24LL * (unsigned int)uti_count;
v3 = 0LL;
while ( 1 )
{
if ( !strcmp(a2, *(const char **)((char *)&utit + v3 + 8)) )
{
result = conflict(a1, *((_BYTE *)&utit + v3), v4);
if ( (_BYTE)result )
break;
}
v3 += 24LL;
if ( v2 == v3 )
return 0LL;
}
return result;
}

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

if ( uti_count <= 0 )
return 0LL;
v2 = 24LL * (unsigned int)uti_count;
v3 = 0LL;
while ( 1 )
{
if ( !strcmp(a2, *(const char **)((char *)&utit + v3 + 8)) )
{
result = func1(a1, *((_BYTE *)&utit + v3), v4);
if ( (_BYTE)result )
break;
}
v3 += 24LL;
if ( v2 == v3 )
return 0LL;
}
return result;
}

original_code:
static _Bool check_conflict(char usage, const char *name)
{
  int index;
  for (index=0; index<uti_count; index++)
    if (strcmp(name, utit[index].name) == 0)
      if (conflict(usage, utit[index].usage))
        return 1;
  return 0;
}

canonical_original_code:
static _Bool check_conflict(char usage, char *name)
{
  int index;
  for (index=0; index<uti_count; index++)
    if (strcmp(name, utit[index].name) == 0)
      if (conflict(usage, utit[index].usage))
        return 1;
  return 0;
}

variable_types: usage char

variable_types:
name
char *

variable_types: index int


decompiled_code:
__int64 __fastcall find_iospec(char *s1)
{
int v1; // er13
const char **v2; // rbp
int v3; // ebx

v1 = ios_count;
if ( ios_count <= 0 )
return 0LL;
v2 = (const char **)&iost;
v3 = 0;
while ( strcmp(s1, *v2) )
{
++v3;
v2 += 3;
if ( v3 == v1 )
return 0LL;
}
return (__int64)&iost + 24 * v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s1)
{
int v1; // er13
const char **v2; // rbp
int v3; // ebx

v1 = ios_count;
if ( ios_count <= 0 )
return 0LL;
v2 = (const char **)&iost;
v3 = 0;
while ( strcmp(s1, *v2) )
{
++v3;
v2 += 3;
if ( v3 == v1 )
return 0LL;
}
return (__int64)&iost + 24 * v3;
}

original_code:
static iospec *find_iospec(const char *name)
{
  int index;
  for (index=0; index<ios_count; index++)
    if (strcmp(name, iost[index].name) == 0)
      return iost+index;
  return ((void *)0);
}

canonical_original_code:
static struct iospec *find_iospec(char *name)
{
  int index;
  for (index=0; index<ios_count; index++)
    if (strcmp(name, iost[index].name) == 0)
      return iost+index;
  return ((void *)0);
}

return_type: struct iospec { char *name; char *resources; int res_count; } *


decompiled_code:
__int64 __fastcall calc_usage(const char *a1, __int64 a2)
{
const char *v2; // rbx
__int64 result; // rax
const char *v4; // [rsp+8h] [rbp-20h] BYREF

iterate_spec(a2, 0LL);
do
{
if ( !(unsigned __int8)iterate_spec(0LL, &v4) )
return 45LL;
v2 = v4;
}
while ( strcmp(a1, v4 + 1) );
result = *(unsigned __int8 *)v2;
if ( (_BYTE)result == 48 && *a1 == 45 )
result = calc_usage(&s1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, __int64 a2)
{
const char *v2; // rbx
__int64 result; // rax
const char *v4; // [rsp+8h] [rbp-20h] BYREF

func0(a2, 0LL);
do
{
if ( !(unsigned __int8)func0(0LL, &v4) )
return 45LL;
v2 = v4;
}
while ( strcmp(a1, v4 + 1) );
result = *(unsigned __int8 *)v2;
if ( (_BYTE)result == 48 && *a1 == 45 )
result = func5(&s1, a2);
return result;
}

original_code:
static char calc_usage(const char *opt, iospec *ios)
{
  char *cp;
  iterate_spec(ios, ((void *)0));
  while (iterate_spec(((void *)0), &cp))
    if (strcmp(opt, cp+1) == 0) {
      if (*cp == '0' && *opt == '-')
        return calc_usage("", ios);
      return *cp;
    }
  return '-';
}

canonical_original_code:
static char calc_usage(char *opt, struct iospec *ios)
{
  char *cp;
  iterate_spec(ios, ((void *)0));
  while (iterate_spec(((void *)0), &cp))
    if (strcmp(opt, cp+1) == 0) {
      if (*cp == '0' && *opt == '-')
        return calc_usage("", ios);
      return *cp;
    }
  return '-';
}

variable_types:
opt
char *

user_defined_types: struct iospec { char *name; char *resources; int res_count; }


decompiled_code:
__int64 __fastcall add_utilization(char a1, const char *a2)
{
int v2; // er12
__int128 *v3; // rbx
int v4; // ebp
__int64 result; // rax
__int64 v6; // rdx

v2 = uti_count;
if ( uti_count <= 0 )
{
v2 = 0;
}
else
{
v3 = &utit;
v4 = 0;
while ( strcmp(a2, *((const char **)v3 + 1)) || *(_BYTE *)v3 != a1 )
{
++v4;
v3 = (__int128 *)((char *)v3 + 24);
if ( v4 == v2 )
{
if ( v2 == 4096 )
LABEL_13:
errx(124, "Utilization table is full");
goto LABEL_10;
}
}
if ( v4 == 4096 )
goto LABEL_13;
if ( v2 > v4 )
{
result = (unsigned int)(LODWORD(qword_8F0[3 * v4]) + 1);
LODWORD(qword_8F0[3 * v4]) = result;
return result;
}
v2 = v4;
}
LABEL_10:
*((_BYTE *)&utit + 24 * v2) = a1;
v6 = xstrdup(a2);
result = 3LL * v2;
*((_QWORD *)&utit + result + 1) = v6;
LODWORD(qword_8F0[result]) = 1;
++uti_count;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1, const char *a2)
{
int v2; // er12
__int128 *v3; // rbx
int v4; // ebp
__int64 result; // rax
__int64 v6; // rdx

v2 = uti_count;
if ( uti_count <= 0 )
{
v2 = 0;
}
else
{
v3 = &utit;
v4 = 0;
while ( strcmp(a2, *((const char **)v3 + 1)) || *(_BYTE *)v3 != a1 )
{
++v4;
v3 = (__int128 *)((char *)v3 + 24);
if ( v4 == v2 )
{
if ( v2 == 4096 )
LABEL_13:
errx(124, "Utilization table is full");
goto LABEL_10;
}
}
if ( v4 == 4096 )
goto LABEL_13;
if ( v2 > v4 )
{
result = (unsigned int)(LODWORD(qword_8F0[3 * v4]) + 1);
LODWORD(qword_8F0[3 * v4]) = result;
return result;
}
v2 = v4;
}
LABEL_10:
*((_BYTE *)&utit + 24 * v2) = a1;
v6 = xstrdup(a2);
result = 3LL * v2;
*((_QWORD *)&utit + result + 1) = v6;
LODWORD(qword_8F0[result]) = 1;
++uti_count;
return result;
}

original_code:
static void add_utilization(char usage, const char *name)
{
  int index;
  for (index=0; index<uti_count; index++)
    if (strcmp(name, utit[index].name) == 0)
      if (usage == utit[index].usage)
        break;
  if (index == 4096)
    errx(124, "Utilization table is full");
  if (index < uti_count)
    utit[index].count++;
  else {
    utit[index].usage = usage;
    utit[index].name = xstrdup(name);
    utit[index].count = 1;
    uti_count++;
  }
}

canonical_original_code:
static void add_utilization(char usage, char *name)
{
  int index;
  for (index=0; index<uti_count; index++)
    if (strcmp(name, utit[index].name) == 0)
      if (usage == utit[index].usage)
        break;
  if (index == 4096)
    errx(124, "Utilization table is full");
  if (index < uti_count)
    utit[index].count++;
  else {
    utit[index].usage = usage;
    utit[index].name = xstrdup(name);
    utit[index].count = 1;
    uti_count++;
  }
}


decompiled_code:
__int64 __fastcall del_utilization(char a1, const char *a2)
{
int v2; // er12
__int128 *v3; // rbx
int v4; // ebp
__int64 result; // rax
__int64 v6; // rbp
__int64 v7; // r12

v2 = uti_count;
if ( uti_count <= 0 )
goto LABEL_9;
v3 = &utit;
v4 = 0;
while ( strcmp(a2, *((const char **)v3 + 1)) || *(_BYTE *)v3 != a1 )
{
++v4;
v3 = (__int128 *)((char *)v3 + 24);
if ( v4 == v2 )
goto LABEL_9;
}
if ( v2 <= v4 )
LABEL_9:
_assert_fail("index < uti_count", "library/hazard.c", 0xCEu, "del_utilization");
result = (unsigned int)(LODWORD(qword_8F0[3 * v4]) - 1);
LODWORD(qword_8F0[3 * v4]) = result;
if ( !(_DWORD)result )
{
free(*((void **)&utit + 3 * v4 + 1));
uti_count = v2 - 1;
v6 = 3LL * v4;
v7 = v2 - 1;
*(__int128 *)((char *)&utit + v6 * 8) = (__int128)_mm_loadu_si128((const __m128i *)((char *)&utit + 24 * v7));
result = qword_8F0[3 * v7];
qword_8F0[v6] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, const char *a2)
{
int v2; // er12
__int128 *v3; // rbx
int v4; // ebp
__int64 result; // rax
__int64 v6; // rbp
__int64 v7; // r12

v2 = uti_count;
if ( uti_count <= 0 )
goto LABEL_9;
v3 = &utit;
v4 = 0;
while ( strcmp(a2, *((const char **)v3 + 1)) || *(_BYTE *)v3 != a1 )
{
++v4;
v3 = (__int128 *)((char *)v3 + 24);
if ( v4 == v2 )
goto LABEL_9;
}
if ( v2 <= v4 )
LABEL_9:
_assert_fail("index < uti_count", "library/hazard.c", 0xCEu, "del_utilization");
result = (unsigned int)(LODWORD(qword_8F0[3 * v4]) - 1);
LODWORD(qword_8F0[3 * v4]) = result;
if ( !(_DWORD)result )
{
free(*((void **)&utit + 3 * v4 + 1));
uti_count = v2 - 1;
v6 = 3LL * v4;
v7 = v2 - 1;
*(__int128 *)((char *)&utit + v6 * 8) = (__int128)_mm_loadu_si128((const __m128i *)((char *)&utit + 24 * v7));
result = qword_8F0[3 * v7];
qword_8F0[v6] = result;
}
return result;
}

original_code:
static void del_utilization(char usage, const char *name)
{
  int index;
  for (index=0; index<uti_count; index++)
    if (strcmp(name, utit[index].name) == 0)
      if (usage == utit[index].usage)
        break;
  ((void) sizeof ((index < uti_count) ? 1 : 0), __extension__ ({ if (index < uti_count) ; else __assert_fail ("index < uti_count", "library/hazard.c", 206, __extension__ __PRETTY_FUNCTION__); }));
  if (--utit[index].count == 0) {
    free(utit[index].name);
    utit[index] = utit[--uti_count];
  }
}

canonical_original_code:
static void del_utilization(char usage, char *name)
{
  int index;
  for (index=0; index<uti_count; index++)
    if (strcmp(name, utit[index].name) == 0)
      if (usage == utit[index].usage)
        break;
  ((void) sizeof ((index < uti_count) ? 1 : 0), __extension__ ({ if (index < uti_count) ; else __assert_fail ("index < uti_count", "library/hazard.c", 206, __extension__ __PRETTY_FUNCTION__); }));
  if (--utit[index].count == 0) {
    free(utit[index].name);
    utit[index] = utit[--uti_count];
  }
}


decompiled_code:
__int64 __fastcall validate_job(_QWORD *a1)
{
char v2; // [rsp+7h] [rbp-11h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
_assert_fail("cmd->buffer", "library/hazard.c", 0x113u, "validate_job");
iterate_usage((__int64)a1, 0LL, 0LL);
while ( (unsigned __int8)iterate_usage(0LL, &v3, &v2) )
{
if ( (unsigned __int8)check_conflict(v2, v3) )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
char v2; // [rsp+7h] [rbp-11h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
_assert_fail("cmd->buffer", "library/hazard.c", 0x113u, "validate_job");
func8((__int64)a1, 0LL, 0LL);
while ( (unsigned __int8)func8(0LL, &v3, &v2) )
{
if ( (unsigned __int8)func3(v2, v3) )
return 0LL;
}
return 1LL;
}

original_code:
_Bool validate_job(sv *cmd)
{
  char *res, usage;
  ((void) sizeof ((cmd->buffer) ? 1 : 0), __extension__ ({ if (cmd->buffer) ; else __assert_fail ("cmd->buffer", "library/hazard.c", 275, __extension__ __PRETTY_FUNCTION__); }));
  iterate_usage(cmd, ((void *)0), ((void *)0));
  while (iterate_usage(((void *)0), &res, &usage))
    if (check_conflict(usage, res))
      return 0;
  return 1;
}

canonical_original_code:
_Bool validate_job(struct sv *cmd)
{
  char *res; char usage;
  ((void) sizeof ((cmd->buffer) ? 1 : 0), __extension__ ({ if (cmd->buffer) ; else __assert_fail ("cmd->buffer", "library/hazard.c", 275, __extension__ __PRETTY_FUNCTION__); }));
  iterate_usage(cmd, ((void *)0), ((void *)0));
  while (iterate_usage(((void *)0), &res, &usage))
    if (check_conflict(usage, res))
      return 0;
  return 1;
}

variable_types: struct sv { char *buffer; char **svec; } *

variable_types:
res
char *


decompiled_code:
__int64 __fastcall register_job(_QWORD *a1)
{
__int64 result; // rax
char v2; // [rsp+7h] [rbp-11h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
_assert_fail("cmd->buffer", "library/hazard.c", 0x11Fu, "register_job");
iterate_usage((__int64)a1, 0LL, 0LL);
while ( 1 )
{
result = iterate_usage(0LL, &v3, &v2);
if ( !(_BYTE)result )
break;
add_utilization(v2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1)
{
__int64 result; // rax
char v2; // [rsp+7h] [rbp-11h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
_assert_fail("cmd->buffer", "library/hazard.c", 0x11Fu, "register_job");
func8((__int64)a1, 0LL, 0LL);
while ( 1 )
{
result = func8(0LL, &v3, &v2);
if ( !(_BYTE)result )
break;
func6(v2, v3);
}
return result;
}

original_code:
void register_job(sv *cmd)
{
  char *res, usage;
  ((void) sizeof ((cmd->buffer) ? 1 : 0), __extension__ ({ if (cmd->buffer) ; else __assert_fail ("cmd->buffer", "library/hazard.c", 287, __extension__ __PRETTY_FUNCTION__); }));
  iterate_usage(cmd, ((void *)0), ((void *)0));
  while (iterate_usage(((void *)0), &res, &usage))
    add_utilization(usage, res);
}

canonical_original_code:
void register_job(struct sv *cmd)
{
  char *res; char usage;
  ((void) sizeof ((cmd->buffer) ? 1 : 0), __extension__ ({ if (cmd->buffer) ; else __assert_fail ("cmd->buffer", "library/hazard.c", 287, __extension__ __PRETTY_FUNCTION__); }));
  iterate_usage(cmd, ((void *)0), ((void *)0));
  while (iterate_usage(((void *)0), &res, &usage))
    add_utilization(usage, res);
}

user_defined_types: struct sv { char *buffer; char **svec; }


decompiled_code:
__int64 __fastcall unregister_job(_QWORD *a1)
{
__int64 result; // rax
char v2; // [rsp+7h] [rbp-11h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
_assert_fail("cmd->buffer", "library/hazard.c", 0x129u, "unregister_job");
iterate_usage((__int64)a1, 0LL, 0LL);
while ( 1 )
{
result = iterate_usage(0LL, &v3, &v2);
if ( !(_BYTE)result )
break;
del_utilization(v2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
__int64 result; // rax
char v2; // [rsp+7h] [rbp-11h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
_assert_fail("cmd->buffer", "library/hazard.c", 0x129u, "unregister_job");
func8((__int64)a1, 0LL, 0LL);
while ( 1 )
{
result = func8(0LL, &v3, &v2);
if ( !(_BYTE)result )
break;
func7(v2, v3);
}
return result;
}

original_code:
void unregister_job(sv *cmd)
{
  char *res, usage;
  ((void) sizeof ((cmd->buffer) ? 1 : 0), __extension__ ({ if (cmd->buffer) ; else __assert_fail ("cmd->buffer", "library/hazard.c", 297, __extension__ __PRETTY_FUNCTION__); }));
  iterate_usage(cmd, ((void *)0), ((void *)0));
  while (iterate_usage(((void *)0), &res, &usage))
    del_utilization(usage, res);
}

canonical_original_code:
void unregister_job(struct sv *cmd)
{
  char *res; char usage;
  ((void) sizeof ((cmd->buffer) ? 1 : 0), __extension__ ({ if (cmd->buffer) ; else __assert_fail ("cmd->buffer", "library/hazard.c", 297, __extension__ __PRETTY_FUNCTION__); }));
  iterate_usage(cmd, ((void *)0), ((void *)0));
  while (iterate_usage(((void *)0), &res, &usage))
    del_utilization(usage, res);
}


decompiled_code:
unsigned __int64 __fastcall jiffy_to_sec(unsigned __int64 a1)
{
if ( !clk_tck_1 )
clk_tck_1 = sysconf(2);
return a1 / clk_tck_1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int64 a1)
{
if ( !clk_tck_1 )
clk_tck_1 = sysconf(2);
return a1 / clk_tck_1;
}

original_code:
static time_t jiffy_to_sec(unsigned long long jiffy)
{
  static unsigned long long clk_tck;
  if (clk_tck == 0)
    clk_tck = sysconf(_SC_CLK_TCK);
  return jiffy/clk_tck;
}

canonical_original_code:
static long jiffy_to_sec(unsigned long long jiffy)
{
  static unsigned long long clk_tck;
  if (clk_tck == 0)
    clk_tck = sysconf(_SC_CLK_TCK);
  return jiffy/clk_tck;
}

variable_types:
jiffy
unsigned long long


decompiled_code:
__int64 __fastcall proc_stat(unsigned int a1, __int64 a2)
{
int v2; // ebx
__int64 result; // rax
int v4; // er12
char *v5; // rax
int v6; // edx
__int64 v7; // rbx
char v8[1024]; // [rsp+0h] [rbp-448h] BYREF
char s[40]; // [rsp+400h] [rbp-48h] BYREF
unsigned __int64 v10; // [rsp+428h] [rbp-20h] BYREF

snprintf(s, 0x28uLL, "/proc/%d/stat", a1);
v2 = open(s, 0);
result = 0LL;
if ( v2 >= 0 )
{
v4 = read(v2, v8, 0x3FFuLL);
close(v2);
result = 0LL;
if ( v4 >= 0 )
{
v8[v4] = 0;
v5 = strrchr(v8, 41);
v6 = sscanf(
v5 + 2,
"%c %d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %lu %*lu %*ld %*ld %*ld %*ld %*ld %*ld %llu",
a2,
a2 + 4,
a2 + 8,
&v10);
result = 0LL;
if ( v6 == 4 )
{
*(_QWORD *)(a2 + 8) = jiffy_to_sec(*(_QWORD *)(a2 + 8));
v7 = boot_time();
*(_QWORD *)(a2 + 16) = jiffy_to_sec(v10) + v7;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
int v2; // ebx
__int64 result; // rax
int v4; // er12
char *v5; // rax
int v6; // edx
__int64 v7; // rbx
char v8[1024]; // [rsp+0h] [rbp-448h] BYREF
char s[40]; // [rsp+400h] [rbp-48h] BYREF
unsigned __int64 v10; // [rsp+428h] [rbp-20h] BYREF

snprintf(s, 0x28uLL, "/proc/%d/stat", a1);
v2 = open(s, 0);
result = 0LL;
if ( v2 >= 0 )
{
v4 = read(v2, v8, 0x3FFuLL);
close(v2);
result = 0LL;
if ( v4 >= 0 )
{
v8[v4] = 0;
v5 = strrchr(v8, 41);
v6 = sscanf(
v5 + 2,
"%c %d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %lu %*lu %*ld %*ld %*ld %*ld %*ld %*ld %llu",
a2,
a2 + 4,
a2 + 8,
&v10);
result = 0LL;
if ( v6 == 4 )
{
*(_QWORD *)(a2 + 8) = func1(*(_QWORD *)(a2 + 8));
v7 = func0();
*(_QWORD *)(a2 + 16) = func1(v10) + v7;
result = 1LL;
}
}
}
return result;
}

original_code:
_Bool proc_stat(pid_t pid, proc *pptr)
{
  unsigned long long start_jiffies;
  char path[40], buffer[1024], *start;
  int stat_fd, num;
  snprintf(path, sizeof (path), "/proc/%d/stat", pid);
  stat_fd = open(path, 00);
  if (stat_fd < 0) return 0;
  num = read(stat_fd, buffer, sizeof (buffer)-1);
  close(stat_fd);
  if (num < 0) return 0;
  buffer[num] = '\0';
  start = strrchr(buffer, ')')+2;
  if (start == ((void *)0)) return 0;
  num = sscanf(start,
               "%c "
               "%d %*d %*d %*d %*d "
               "%*u %*lu %*lu %*lu %*lu "
               "%lu %*lu %*ld %*ld "
               "%*ld %*ld %*ld %*ld "
               "%llu",
               &(pptr->state),
               &(pptr->ppid),
               &(pptr->utime),
               &start_jiffies);
  if (num != 4) return 0;
  pptr->utime = jiffy_to_sec(pptr->utime);
  pptr->start_time = boot_time() + jiffy_to_sec(start_jiffies);
  return 1;
}

canonical_original_code:
_Bool proc_stat(int pid, struct proc *pptr)
{
  unsigned long long start_jiffies;
  char path[40]; char buffer[1024]; char *start;
  int stat_fd; int num;
  snprintf(path, sizeof (path), "/proc/%d/stat", pid);
  stat_fd = open(path, 00);
  if (stat_fd < 0) return 0;
  num = read(stat_fd, buffer, sizeof (buffer)-1);
  close(stat_fd);
  if (num < 0) return 0;
  buffer[num] = '\0';
  start = strrchr(buffer, ')')+2;
  if (start == ((void *)0)) return 0;
  num = sscanf(start,
               "%c "
               "%d %*d %*d %*d %*d "
               "%*u %*lu %*lu %*lu %*lu "
               "%lu %*lu %*ld %*ld "
               "%*ld %*ld %*ld %*ld "
               "%llu",
               &(pptr->state),
               &(pptr->ppid),
               &(pptr->utime),
               &start_jiffies);
  if (num != 4) return 0;
  pptr->utime = jiffy_to_sec(pptr->utime);
  pptr->start_time = boot_time() + jiffy_to_sec(start_jiffies);
  return 1;
}

variable_types: pid int

variable_types: struct proc { char state; int ppid; unsigned long utime; long start_time; } *

variable_types:
path
char [40]

variable_types:
buffer
char [1024]

variable_types:
start
char *

variable_types: num int


decompiled_code:
const char *__fastcall time_string(unsigned __int64 a1)
{
const char *result; // rax

result = "99:59+";
if ( a1 <= 0x176F )
{
sprintf(buffer_0, "%2lu:%02lu ", a1 / 0x3C, a1 % 0x3C);
result = buffer_0;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(unsigned __int64 a1)
{
const char *result; // rax

result = "99:59+";
if ( a1 <= 0x176F )
{
sprintf(buffer_0, "%2lu:%02lu ", a1 / 0x3C, a1 % 0x3C);
result = buffer_0;
}
return result;
}

original_code:
char *time_string(unsigned long seconds)
{
  static char buffer[10];
  unsigned long minutes;
  minutes = seconds / 60;
  seconds %= 60;
  if (minutes > 99)
    return "99:59+";
  sprintf(buffer, "%2lu:%02lu ", minutes, seconds);
  return buffer;
}

variable_types:
seconds
unsigned long

variable_types:
buffer
char [10]

variable_types:
minutes
unsigned long

return_type: char *


decompiled_code:
__int64 __fastcall read_block(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rax
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
readn(a1, v4, 4LL);
result = v4[0];
if ( v4[0] )
{
v3 = xmalloc((int)v4[0]);
*a2 = v3;
readn((unsigned int)a1, v3, (int)v4[0]);
result = v4[0];
if ( *(_BYTE *)(*a2 + (int)v4[0] - 1) )
{
warnx("read_block: input is not null-terminated");
result = 4294967294LL;
}
}
else
{
*a2 = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rax
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
readn(a1, v4, 4LL);
result = v4[0];
if ( v4[0] )
{
v3 = xmalloc((int)v4[0]);
*a2 = v3;
readn((unsigned int)a1, v3, (int)v4[0]);
result = v4[0];
if ( *(_BYTE *)(*a2 + (int)v4[0] - 1) )
{
warnx("read_block: input is not null-terminated");
result = 4294967294LL;
}
}
else
{
*a2 = 0LL;
}
return result;
}

original_code:
static int read_block(int fd, char **buffer)
{
  int size = 0;
  readn(fd, &size, sizeof (int));
  if (size == 0) {
    *buffer = ((void *)0);
    return 0;
  }
  *buffer = xmalloc(size);
  readn(fd, *buffer, size);
  if ((*buffer)[size-1]) {
    warnx("read_block: input is not null-terminated");
    return -2;
  }
  return size;
}

variable_types: fd int

variable_types:
buffer
char **

variable_types: size int