decompiled_code:
_BOOL8 __fastcall output_write_headers(__int64 a1)
{
void *v1; // r12
_BYTE *v2; // r14
int v4; // er13
signed int v5; // ebp
int v6; // ebx
_BYTE *v7; // rsi
char v8; // dl
signed int v9; // esi
_BYTE *v10; // rax
_BYTE *v11; // r9
char *v12; // rax
_BYTE *v13; // r15
int v14; // ebx
_BOOL8 result; // rax
void *src; // [rsp+8h] [rbp-60h]
_BYTE *v17; // [rsp+28h] [rbp-40h] BYREF

v4 = 0;
v5 = 0;
v6 = 0;
v7 = *(_BYTE **)a1;
v17 = *(_BYTE **)a1;
while ( 1 )
{
v10 = findDelimiter(&v17, &v7[*(int *)(a1 + 8)]);
if ( !v10 )
break;
if ( !v11 )
goto LABEL_10;
v8 = *v11 & 0x1F;
v9 = (_DWORD)v10 - (_DWORD)v11;
if ( v8 == 7 )
{
v2 = v11;
v6 = (_DWORD)v10 - (_DWORD)v11;
goto LABEL_10;
}
if ( v8 == 8 )
{
src = v11;
v4 = (_DWORD)v10 - (_DWORD)v11;
goto LABEL_10;
}
LABEL_5:
if ( v8 == 6 )
v1 = v11;
if ( v8 == 6 )
v5 = v9;
if ( !v10 )
goto LABEL_20;
LABEL_10:
v7 = *(_BYTE **)a1;
}
if ( !v11 )
goto LABEL_20;
v8 = *v11 & 0x1F;
v9 = *(_QWORD *)a1 + *(_DWORD *)(a1 + 8) - (_DWORD)v11;
if ( v8 == 7 )
{
v6 = *(_QWORD *)a1 + *(_DWORD *)(a1 + 8) - (_DWORD)v11;
v2 = v11;
goto LABEL_20;
}
if ( v8 != 8 )
goto LABEL_5;
src = v11;
v4 = *(_QWORD *)a1 + *(_DWORD *)(a1 + 8) - (_DWORD)v11;
LABEL_20:
v12 = (char *)malloc(v6 + v4 + 11);
v13 = v12;
if ( !v12 )
return 0LL;
*v12 = 1;
v12[1] = v2[1];
v12[2] = v2[2];
v12[3] = v2[3];
*((_WORD *)v12 + 2) = -7681;
*((_WORD *)v12 + 3) = __ROL2__(v6, 8);
memcpy(v12 + 8, v2, v6);
v13[v6 + 8] = 1;
v13[v6 + 9] = BYTE1(v4);
v13[v6 + 10] = v4;
memcpy(&v13[v6 + 11], src, v4);
v14 = mk_write_header(
writer,
"simplerecorder",
"V_MPEG4/ISO/AVC",
v13,
(unsigned int)(v6 + v4 + 11),
40000000LL,
50000LL,
(unsigned int)width,
(unsigned int)height,
(unsigned int)width,
(unsigned int)height,
0LL);
free(v13);
if ( v14 < 0 )
return 0LL;
result = 1LL;
if ( !v5 )
return result;
if ( (int)mk_start_frame(writer) < 0 )
return 0LL;
writing_frame = 1;
return write_frame_data(v1, v5);
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
void *v1; // r12
_BYTE *v2; // r14
int v4; // er13
signed int v5; // ebp
int v6; // ebx
_BYTE *v7; // rsi
char v8; // dl
signed int v9; // esi
_BYTE *v10; // rax
_BYTE *v11; // r9
char *v12; // rax
_BYTE *v13; // r15
int v14; // ebx
_BOOL8 result; // rax
void *src; // [rsp+8h] [rbp-60h]
_BYTE *v17; // [rsp+28h] [rbp-40h] BYREF

v4 = 0;
v5 = 0;
v6 = 0;
v7 = *(_BYTE **)a1;
v17 = *(_BYTE **)a1;
while ( 1 )
{
v10 = findDelimiter(&v17, &v7[*(int *)(a1 + 8)]);
if ( !v10 )
break;
if ( !v11 )
goto LABEL_10;
v8 = *v11 & 0x1F;
v9 = (_DWORD)v10 - (_DWORD)v11;
if ( v8 == 7 )
{
v2 = v11;
v6 = (_DWORD)v10 - (_DWORD)v11;
goto LABEL_10;
}
if ( v8 == 8 )
{
src = v11;
v4 = (_DWORD)v10 - (_DWORD)v11;
goto LABEL_10;
}
LABEL_5:
if ( v8 == 6 )
v1 = v11;
if ( v8 == 6 )
v5 = v9;
if ( !v10 )
goto LABEL_20;
LABEL_10:
v7 = *(_BYTE **)a1;
}
if ( !v11 )
goto LABEL_20;
v8 = *v11 & 0x1F;
v9 = *(_QWORD *)a1 + *(_DWORD *)(a1 + 8) - (_DWORD)v11;
if ( v8 == 7 )
{
v6 = *(_QWORD *)a1 + *(_DWORD *)(a1 + 8) - (_DWORD)v11;
v2 = v11;
goto LABEL_20;
}
if ( v8 != 8 )
goto LABEL_5;
src = v11;
v4 = *(_QWORD *)a1 + *(_DWORD *)(a1 + 8) - (_DWORD)v11;
LABEL_20:
v12 = (char *)malloc(v6 + v4 + 11);
v13 = v12;
if ( !v12 )
return 0LL;
*v12 = 1;
v12[1] = v2[1];
v12[2] = v2[2];
v12[3] = v2[3];
*((_WORD *)v12 + 2) = -7681;
*((_WORD *)v12 + 3) = __ROL2__(v6, 8);
memcpy(v12 + 8, v2, v6);
v13[v6 + 8] = 1;
v13[v6 + 9] = BYTE1(v4);
v13[v6 + 10] = v4;
memcpy(&v13[v6 + 11], src, v4);
v14 = mk_write_header(
writer,
"simplerecorder",
"V_MPEG4/ISO/AVC",
v13,
(unsigned int)(v6 + v4 + 11),
40000000LL,
50000LL,
(unsigned int)width,
(unsigned int)height,
(unsigned int)width,
(unsigned int)height,
0LL);
free(v13);
if ( v14 < 0 )
return 0LL;
result = 1LL;
if ( !v5 )
return result;
if ( (int)mk_start_frame(writer) < 0 )
return 0LL;
writing_frame = 1;
return func0(v1, v5);
}

original_code:
int output_write_headers(struct encoded_pic_t *headers)
{
 uint8_t *avcC;
 int avcC_len;
 uint8_t *tmp, *last = ((void *)0);
 uint8_t *sps, *pps, *sei;
 int sps_len=0, pps_len=0, sei_len=0;
 int ret;
 uint64_t frame_duration = 1000000000ull/25;
 for(tmp = headers->buffer;;){
  uint8_t *st = findDelimiter(&tmp, headers->buffer + headers->length);
  int len = st ? st-last : headers->buffer + headers->length - last;
  if(last){
   switch(*last&31){
   case 6:
    sei = last;
    sei_len = len;
    break;
   case 7:
    sps = last;
    sps_len = len;
    break;
   case 8:
    pps = last;
    pps_len = len;
    break;
   }
  }
  last = tmp;
  if(!st)
   break;
 }
 avcC_len = 5 + 1 + 2 + sps_len + 1 + 2 + pps_len;
 avcC = malloc( avcC_len );
 if( !avcC )
  return 0;
 avcC[0] = 1;
 avcC[1] = sps[1];
 avcC[2] = sps[2];
 avcC[3] = sps[3];
 avcC[4] = 0xff;
 avcC[5] = 0xe1;
 avcC[6] = sps_len >> 8;
 avcC[7] = sps_len;
 memcpy( avcC+8, sps, sps_len );
 avcC[8+sps_len] = 1;
 avcC[9+sps_len] = pps_len >> 8;
 avcC[10+sps_len] = pps_len;
 memcpy( avcC+11+sps_len, pps, pps_len );
 ret = mk_write_header( writer, "simplerecorder", "V_MPEG4/ISO/AVC",
         avcC, avcC_len, frame_duration, 50000,
         width, height, width, height, 0);
 free( avcC );
 if(ret < 0)
  return 0;
 if(sei_len){
  if(mk_start_frame(writer) < 0)
   return 0;
  writing_frame = 1;
  if(!write_frame_data(sei, sei_len))
   return 0;
 }
 return 1;
}

canonical_original_code:
int output_write_headers(struct encoded_pic_t *headers)
{
 unsigned char *avcC;
 int avcC_len;
 unsigned char *tmp; unsigned char *last = ((void *)0);
 unsigned char *sps; unsigned char *pps; unsigned char *sei;
 int sps_len = 0; int pps_len = 0; int sei_len = 0;
 int ret;
 unsigned long frame_duration = 1000000000ull/25;
 for(tmp = headers->buffer;;){
  unsigned char *st = findDelimiter(&tmp, headers->buffer + headers->length);
  int len = st ? st-last : headers->buffer + headers->length - last;
  if(last){
   switch(*last&31){
   case 6:
    sei = last;
    sei_len = len;
    break;
   case 7:
    sps = last;
    sps_len = len;
    break;
   case 8:
    pps = last;
    pps_len = len;
    break;
   }
  }
  last = tmp;
  if(!st)
   break;
 }
 avcC_len = 5 + 1 + 2 + sps_len + 1 + 2 + pps_len;
 avcC = malloc( avcC_len );
 if( !avcC )
  return 0;
 avcC[0] = 1;
 avcC[1] = sps[1];
 avcC[2] = sps[2];
 avcC[3] = sps[3];
 avcC[4] = 0xff;
 avcC[5] = 0xe1;
 avcC[6] = sps_len >> 8;
 avcC[7] = sps_len;
 memcpy( avcC+8, sps, sps_len );
 avcC[8+sps_len] = 1;
 avcC[9+sps_len] = pps_len >> 8;
 avcC[10+sps_len] = pps_len;
 memcpy( avcC+11+sps_len, pps, pps_len );
 ret = mk_write_header( writer, "simplerecorder", "V_MPEG4/ISO/AVC",
         avcC, avcC_len, frame_duration, 50000,
         width, height, width, height, 0);
 free( avcC );
 if(ret < 0)
  return 0;
 if(sei_len){
  if(mk_start_frame(writer) < 0)
   return 0;
  writing_frame = 1;
  if(!write_frame_data(sei, sei_len))
   return 0;
 }
 return 1;
}

variable_types:
avcC
unsigned char *

variable_types:
tmp
unsigned char *

variable_types:
last
unsigned char *

variable_types:
sps
unsigned char *

variable_types:
pps
unsigned char *

variable_types:
sei
unsigned char *

variable_types: ret int

variable_types:
st
unsigned char *

variable_types: len int


decompiled_code:
__int64 __fastcall output_write_frame(char **a1)
{
__int64 result; // rax
int v2; // ebx
char *v3; // rbp
char v4; // al

result = 1LL;
v2 = *((_DWORD *)a1 + 2);
if ( v2 )
{
v3 = *a1;
v4 = **a1;
if ( v2 > 0 )
{
while ( 1 )
{
v4 = *v3;
if ( *v3 )
break;
++v3;
if ( !--v2 )
goto LABEL_7;
}
}
if ( v4 == 1 )
{
if ( (writing_frame || (int)mk_start_frame(writer) >= 0)
&& write_frame_data(v3 + 1, v2 - 1)
&& (int)mk_set_frame_flags(writer, 1000LL * (_QWORD)a1[2], *((_DWORD *)a1 + 6) == 0, *((_DWORD *)a1 + 6) == 2) >= 0 )
{
writing_frame = 0;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
LABEL_7:
fwrite("invalid NAL delimiter\n", 1uLL, 0x16uLL, stderr);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char **a1)
{
__int64 result; // rax
int v2; // ebx
char *v3; // rbp
char v4; // al

result = 1LL;
v2 = *((_DWORD *)a1 + 2);
if ( v2 )
{
v3 = *a1;
v4 = **a1;
if ( v2 > 0 )
{
while ( 1 )
{
v4 = *v3;
if ( *v3 )
break;
++v3;
if ( !--v2 )
goto LABEL_7;
}
}
if ( v4 == 1 )
{
if ( (writing_frame || (int)mk_start_frame(writer) >= 0)
&& func0(v3 + 1, v2 - 1)
&& (int)mk_set_frame_flags(writer, 1000LL * (_QWORD)a1[2], *((_DWORD *)a1 + 6) == 0, *((_DWORD *)a1 + 6) == 2) >= 0 )
{
writing_frame = 0;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
LABEL_7:
fwrite("invalid NAL delimiter\n", 1uLL, 0x16uLL, stderr);
result = 0LL;
}
}
return result;
}

original_code:
int output_write_frame(struct encoded_pic_t *encoded)
{
 uint8_t *ptr = encoded->buffer;
 int length = encoded->length;
 if(length == 0)
  return 1;
 while(length>0 && *ptr == 0){
  ptr++;
  length--;
 }
 if(!length || *ptr != 0x01){
  fprintf(stderr, "invalid NAL delimiter\n");
  return 0;
 }
 if(!writing_frame)
  if(mk_start_frame(writer) < 0)
   return 0;
 if(!write_frame_data(ptr+1, length-1))
  return 0;
 if(mk_set_frame_flags(writer, encoded->timepoint*1000 ,
  encoded->frame_type==FRAME_TYPE_I, encoded->frame_type==FRAME_TYPE_B)<0)
  return 0;
 writing_frame = 0;
 return 1;
}

canonical_original_code:
int output_write_frame(struct encoded_pic_t *encoded)
{
 unsigned char *ptr = encoded->buffer;
 int length = encoded->length;
 if(length == 0)
  return 1;
 while(length>0 && *ptr == 0){
  ptr++;
  length--;
 }
 if(!length || *ptr != 0x01){
  fprintf(stderr, "invalid NAL delimiter\n");
  return 0;
 }
 if(!writing_frame)
  if(mk_start_frame(writer) < 0)
   return 0;
 if(!write_frame_data(ptr+1, length-1))
  return 0;
 if(mk_set_frame_flags(writer, encoded->timepoint*1000 ,
  encoded->frame_type==FRAME_TYPE_I, encoded->frame_type==FRAME_TYPE_B)<0)
  return 0;
 writing_frame = 0;
 return 1;
}

variable_types: struct encoded_pic_t { unsigned char *buffer; int length; unsigned long long timepoint; enum H264_FRAME_TYPE { FRAME_TYPE_I=0, FRAME_TYPE_P=1, FRAME_TYPE_B=2 } frame_type; void *usr_def; } *

variable_types:
ptr
unsigned char *

variable_types: length int

return_type: int

user_defined_types: struct encoded_pic_t { unsigned char *buffer; int length; unsigned long long timepoint; enum H264_FRAME_TYPE frame_type; void *usr_def; }


decompiled_code:
void output_close()
{
mk_close(writer, 0LL);
free(cache);
}

canonical_decompiled_code:
void func4()
{
mk_close(writer, 0LL);
free(cache);
}

original_code:
void output_close()
{
 mk_close(writer, 0);
 free(cache);
}

return_type: void


applog

decompiled_code:
char *applog(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-110h] BYREF
char s[64]; // [rsp+20h] [rbp-F8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
return strcat(&log_buf, s);
}

canonical_decompiled_code:
char *func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-110h] BYREF
char s[64]; // [rsp+20h] [rbp-F8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
return strcat(&log_buf, s);
}

original_code:
void applog(const char *format, ...)
{
 char buf[64];
 va_list args;
 __builtin_va_start(args,format);
 vsprintf(buf, format, args);
 strcat(log_buf,buf);
 __builtin_va_end(args);
}

canonical_original_code:
void applog(char *format, ...)
{
 char buf[64];
 __builtin_va_list args;
 __builtin_va_start(args,format);
 vsprintf(buf, format, args);
 strcat(log_buf,buf);
 __builtin_va_end(args);
}

variable_types:
format
char *

variable_types:
buf
char [64]


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

printf("\r\x1B[K%s", &log_buf);
result = fflush(stdout);
log_buf = 0;
return result;
}

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

printf("\r\x1B[K%s", &log_buf);
result = fflush(stdout);
log_buf = 0;
return result;
}

original_code:
void applog_flush()
{
 printf("\r\x1b[K%s", log_buf);
 fflush(stdout);
 log_buf[0] = '\0';
}


min

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

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

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

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

original_code:
static int min(int x, int y)
{
 return x<y ? x : y;
}

variable_types: x int

variable_types: y int


original_code:
void v4lconvert_yuv420_to_bgr24__(const unsigned char *src, unsigned char *dest,
  int width, int height, int yvu)
{
 int i, j;
 const unsigned char *ysrc = src;
 const unsigned char *usrc, *vsrc;
 if (yvu) {
  vsrc = src + width * height;
  usrc = vsrc + (width * height) / 4;
 } else {
  usrc = src + width * height;
  vsrc = usrc + (width * height) / 4;
 }
 for (i = 0; i < height; i++) {
  for (j = 0; j < width; j += 2) {
   int u1 = (((*usrc - 128) << 7) + (*usrc - 128)) >> 6;
   int rg = (((*usrc - 128) << 1) + (*usrc - 128) +
     ((*vsrc - 128) << 2) + ((*vsrc - 128) << 1)) >> 3;
   int v1 = (((*vsrc - 128) << 1) + (*vsrc - 128)) >> 1;
   *dest++ = (unsigned char)(((*ysrc + u1) > 0xFF) ? 0xff : (((*ysrc + u1) < 0) ? 0 : (*ysrc + u1)));
   *dest++ = (unsigned char)(((*ysrc - rg) > 0xFF) ? 0xff : (((*ysrc - rg) < 0) ? 0 : (*ysrc - rg)));
   *dest++ = (unsigned char)(((*ysrc + v1) > 0xFF) ? 0xff : (((*ysrc + v1) < 0) ? 0 : (*ysrc + v1)));
   ysrc++;
   *dest++ = (unsigned char)(((*ysrc + u1) > 0xFF) ? 0xff : (((*ysrc + u1) < 0) ? 0 : (*ysrc + u1)));
   *dest++ = (unsigned char)(((*ysrc - rg) > 0xFF) ? 0xff : (((*ysrc - rg) < 0) ? 0 : (*ysrc - rg)));
   *dest++ = (unsigned char)(((*ysrc + v1) > 0xFF) ? 0xff : (((*ysrc + v1) < 0) ? 0 : (*ysrc + v1)));
   ysrc++;
   usrc++;
   vsrc++;
  }
  if (!(i & 1)) {
   usrc -= width / 2;
   vsrc -= width / 2;
  }
 }
}

canonical_original_code:
void v4lconvert_yuv420_to_bgr24__(unsigned char *src, unsigned char *dest, int width, int height, int yvu)
{
 int i; int j;
 unsigned char *ysrc = src;
 unsigned char *usrc; unsigned char *vsrc;
 if (yvu) {
  vsrc = src + width * height;
  usrc = vsrc + (width * height) / 4;
 } else {
  usrc = src + width * height;
  vsrc = usrc + (width * height) / 4;
 }
 for (i = 0; i < height; i++) {
  for (j = 0; j < width; j += 2) {
   int u1 = (((*usrc - 128) << 7) + (*usrc - 128)) >> 6;
   int rg = (((*usrc - 128) << 1) + (*usrc - 128) +
     ((*vsrc - 128) << 2) + ((*vsrc - 128) << 1)) >> 3;
   int v1 = (((*vsrc - 128) << 1) + (*vsrc - 128)) >> 1;
   *dest++ = (unsigned char)(((*ysrc + u1) > 0xFF) ? 0xff : (((*ysrc + u1) < 0) ? 0 : (*ysrc + u1)));
   *dest++ = (unsigned char)(((*ysrc - rg) > 0xFF) ? 0xff : (((*ysrc - rg) < 0) ? 0 : (*ysrc - rg)));
   *dest++ = (unsigned char)(((*ysrc + v1) > 0xFF) ? 0xff : (((*ysrc + v1) < 0) ? 0 : (*ysrc + v1)));
   ysrc++;
   *dest++ = (unsigned char)(((*ysrc + u1) > 0xFF) ? 0xff : (((*ysrc + u1) < 0) ? 0 : (*ysrc + u1)));
   *dest++ = (unsigned char)(((*ysrc - rg) > 0xFF) ? 0xff : (((*ysrc - rg) < 0) ? 0 : (*ysrc - rg)));
   *dest++ = (unsigned char)(((*ysrc + v1) > 0xFF) ? 0xff : (((*ysrc + v1) < 0) ? 0 : (*ysrc + v1)));
   ysrc++;
   usrc++;
   vsrc++;
  }
  if (!(i & 1)) {
   usrc -= width / 2;
   vsrc -= width / 2;
  }
 }
}

variable_types:
src
unsigned char *

variable_types:
dest
unsigned char *

variable_types: width int

variable_types: height int

variable_types: yvu int

variable_types: i int

variable_types: j int

variable_types:
ysrc
unsigned char *

variable_types:
usrc
unsigned char *

variable_types:
vsrc
unsigned char *

variable_types: rg int


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

v1 = open("/dev/fb0", 2);
fd_scr = v1;
if ( v1 < 0 )
{
perror("open framebuffer /dev/fb0");
result = 0LL;
}
else
{
v2 = v1;
if ( ioctl(v1, 0x4600uLL, &vinfo) < 0 )
{
perror("FBIOGET_VSCREENINFO");
}
else
{
if ( ioctl(v2, 0x4611uLL, 0LL) < 0 )
perror("FBIOBLANK");
system("echo 0 >/sys/class/graphics/fbcon/cursor_blink");
scr_height = dword_624;
scr_bpp = dword_638;
scr_width = vinfo;
printf(
"framebuffer: width=%d, height=%d, bpp=%d\n",
(unsigned int)vinfo,
(unsigned int)dword_624,
(unsigned int)dword_638);
if ( ((scr_bpp - 24) & 0xFFFFFFF7) != 0 )
{
fprintf(stderr, "%s\n", "scr_bpp!=32 && scr_bpp!=24, not supported");
}
else
{
scr_buf = mmap(0LL, scr_height * scr_width * scr_bpp / 8, 3, 1, fd_scr, 0LL);
if ( scr_buf )
{
bgr24_buf = malloc(3 * *(_DWORD *)(a1 + 28) * *(_DWORD *)(a1 + 24));
if ( bgr24_buf )
return 1LL;
perror("malloc");
munmap(scr_buf, scr_bpp * scr_height * scr_width / 8);
}
else
{
perror("mmap framebuffer");
}
}
}
close(fd_scr);
result = 0LL;
}
return result;
}

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

v1 = open("/dev/fb0", 2);
fd_scr = v1;
if ( v1 < 0 )
{
perror("open framebuffer /dev/fb0");
result = 0LL;
}
else
{
v2 = v1;
if ( ioctl(v1, 0x4600uLL, &vinfo) < 0 )
{
perror("FBIOGET_VSCREENINFO");
}
else
{
if ( ioctl(v2, 0x4611uLL, 0LL) < 0 )
perror("FBIOBLANK");
system("echo 0 >/sys/class/graphics/fbcon/cursor_blink");
scr_height = dword_624;
scr_bpp = dword_638;
scr_width = vinfo;
printf(
"framebuffer: width=%d, height=%d, bpp=%d\n",
(unsigned int)vinfo,
(unsigned int)dword_624,
(unsigned int)dword_638);
if ( ((scr_bpp - 24) & 0xFFFFFFF7) != 0 )
{
fprintf(stderr, "%s\n", "scr_bpp!=32 && scr_bpp!=24, not supported");
}
else
{
scr_buf = mmap(0LL, scr_height * scr_width * scr_bpp / 8, 3, 1, fd_scr, 0LL);
if ( scr_buf )
{
bgr24_buf = malloc(3 * *(_DWORD *)(a1 + 28) * *(_DWORD *)(a1 + 24));
if ( bgr24_buf )
return 1LL;
perror("malloc");
munmap(scr_buf, scr_bpp * scr_height * scr_width / 8);
}
else
{
perror("mmap framebuffer");
}
}
}
close(fd_scr);
result = 0LL;
}
return result;
}

original_code:
int preview_init(struct picture_t *info)
{
 fd_scr = open("/dev/fb0", 02);
 if(fd_scr < 0){
  perror("open framebuffer ""/dev/fb0");
  return 0;
 }
 if(ioctl(fd_scr, 0x4600, &vinfo) < 0) {
  perror("FBIOGET_VSCREENINFO");
  goto error;
 }
 if(ioctl(fd_scr, 0x4611, FB_BLANK_UNBLANK) < 0) {
  perror("FBIOBLANK");
 }
 system("echo 0 >/sys/class/graphics/fbcon/cursor_blink");
 scr_bpp = vinfo.bits_per_pixel;
 scr_width = vinfo.xres;
 scr_height = vinfo.yres;
 printf("framebuffer: width=%d, height=%d, bpp=%d\n", scr_width, scr_height, scr_bpp);
 if(scr_bpp!=32 && scr_bpp!=24){
  fprintf(stderr, "%s\n", "scr_bpp!=32 && scr_bpp!=24, not supported");
  goto error;
 }
 scr_buf = mmap(0, scr_width*scr_height*scr_bpp/8, 0x1|0x2, 0x01, fd_scr, 0);
 if(scr_buf <= 0) {
  perror("mmap framebuffer");
  goto error;
 }
 bgr24_buf = malloc(info->width*info->height*3);
 if(!bgr24_buf){
  perror("malloc");
  goto error_malloc;
 }
 return 1;
error_malloc:
 munmap(scr_buf, scr_width*scr_height*scr_bpp/8);
error:
 close(fd_scr);
 return 0;
}

variable_types: struct picture_t { unsigned char *buffer; struct timeval { long tv_sec; long tv_usec; } timestamp; int width; } *

user_defined_types: struct picture_t { unsigned char *buffer; struct timeval timestamp; int width; }


original_code:
int preview_display(struct picture_t *pic)
{
 int min_width = min(pic->width, scr_width);
 int min_height = min(pic->height, scr_height);
 v4lconvert_yuv420_to_bgr24__(pic->buffer, bgr24_buf, pic->width, pic->height, 0);
 if(scr_bpp == 32){
  int i,j;
  for(i=0; i<min_height; i++){
   unsigned char *ptr_d, *ptr_s;
   ptr_d = scr_buf+4*scr_width*i;
   ptr_s = bgr24_buf+3*pic->width*i;
   for(j=0; j<min_width; j++){
    *ptr_d++ = *ptr_s++;
    *ptr_d++ = *ptr_s++;
    *ptr_d++ = *ptr_s++;
    *ptr_d++ = 0;
   }
  }
 }else if(scr_bpp == 24){
  int i,j;
  for(i=0; i<min_height; i++){
   unsigned char *ptr_d, *ptr_s;
   ptr_d = scr_buf+3*scr_width*i;
   ptr_s = bgr24_buf+3*pic->width*i;
   for(j=0; j<min_width; j++){
    *ptr_d++ = *ptr_s++;
    *ptr_d++ = *ptr_s++;
    *ptr_d++ = *ptr_s++;
   }
  }
 }
 return 1;
}

canonical_original_code:
int preview_display(struct picture_t *pic)
{
 int min_width = min(pic->width, scr_width);
 int min_height = min(pic->height, scr_height);
 v4lconvert_yuv420_to_bgr24__(pic->buffer, bgr24_buf, pic->width, pic->height, 0);
 if(scr_bpp == 32){
  int i; int j;
  for(i=0; i<min_height; i++){
   unsigned char *ptr_d; unsigned char *ptr_s;
   ptr_d = scr_buf+4*scr_width*i;
   ptr_s = bgr24_buf+3*pic->width*i;
   for(j=0; j<min_width; j++){
    *ptr_d++ = *ptr_s++;
    *ptr_d++ = *ptr_s++;
    *ptr_d++ = *ptr_s++;
    *ptr_d++ = 0;
   }
  }
 }else if(scr_bpp == 24){
  int i; int j;
  for(i=0; i<min_height; i++){
   unsigned char *ptr_d; unsigned char *ptr_s;
   ptr_d = scr_buf+3*scr_width*i;
   ptr_s = bgr24_buf+3*pic->width*i;
   for(j=0; j<min_width; j++){
    *ptr_d++ = *ptr_s++;
    *ptr_d++ = *ptr_s++;
    *ptr_d++ = *ptr_s++;
   }
  }
 }
 return 1;
}

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


decompiled_code:
int preview_close()
{
free(bgr24_buf);
munmap(scr_buf, scr_height * scr_width * scr_bpp / 8);
return close(fd_scr);
}

canonical_decompiled_code:
int func4()
{
free(bgr24_buf);
munmap(scr_buf, scr_height * scr_width * scr_bpp / 8);
return close(fd_scr);
}

original_code:
void preview_close()
{
 free(bgr24_buf);
 munmap(scr_buf, scr_width*scr_height*scr_bpp/8);
 close(fd_scr);
}


decompiled_code:
__int64 init_defualt_scmask()
{
__int64 result; // rax
_DWORD *v1; // rdx

LODWORD(result) = 0;
v1 = &unk_26E4;
memset(MINIMAL_SCSET, 0, sizeof(MINIMAL_SCSET));
while ( 1 )
{
result = (int)result;
MINIMAL_SCSET[(int)result] = -1;
if ( v1 == (_DWORD *)10068 )
break;
LODWORD(result) = *v1++;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
_DWORD *v1; // rdx

LODWORD(result) = 0;
v1 = &unk_26E4;
memset(MINIMAL_SCSET, 0, sizeof(MINIMAL_SCSET));
while ( 1 )
{
result = (int)result;
MINIMAL_SCSET[(int)result] = -1;
if ( v1 == (_DWORD *)10068 )
break;
LODWORD(result) = *v1++;
}
return result;
}

original_code:
static void init_defualt_scmask()
{
 memset(&MINIMAL_SCSET, 0, sizeof(struct scmask));
 int i, len = sizeof(sc_safe) / sizeof(int);
 for(i=0; i<len; i++)
  MINIMAL_SCSET.set[sc_safe[i]] = -1;
}

canonical_original_code:
static void init_defualt_scmask()
{
 memset(&MINIMAL_SCSET, 0, sizeof(struct scmask));
 int i; int len = sizeof(sc_safe) / sizeof(int);
 for(i=0; i<len; i++)
  MINIMAL_SCSET.set[sc_safe[i]] = -1;
}

variable_types: len int


original_code:
static int sc_handle(struct sablebox* pbox, struct __child_t* pson, struct profile* ret)
{
 static long scno = -1;
 if(pson->insyscall){
  pson->insyscall = 0;
  if(scno == 12){
   long newbrk;
   newbrk = ptrace(PTRACE_PEEKUSER, pson->pid, 10 * 8, 0);
   if(newbrk == -1){
    if((*__errno_location ()) != 3){
     perror("ptrace:""237");
     ret->status = 4;
    }
    return 1;
   }
   if(pson->program_break)
    ret->memory += newbrk - pson->program_break;
   pson->program_break = newbrk;
  }
 }else{
  pson->insyscall = 1;
  scno = ptrace(PTRACE_PEEKUSER, pson->pid, 15 * 8, 0);
  if(scno == -1 || scno >= 512){
   if((*__errno_location ()) != 3){
    perror("ptrace:""253");
    ret->status = 4;
   }
   return 1;
  }
  if(!pbox->scp->set[scno]){
   if(scno == 2) {
    long addr;
    union{
     long x;
     char c[8];
    }data;
    addr = ptrace(PTRACE_PEEKUSER, pson->pid, 14 * 8, 0);
    data.x = ptrace(2, pson->pid, addr, 0);
    data.c[0] = '\0';
    if(addr != -1 && data.x != -1 && ptrace(5, pson->pid, addr, data.x) != -1){
     puts("modify the first argument of open");
    }
   }else {
    ret->status = 1;
    ret->info = scnames[scno];
    return 1;
   }
  }
  if(pbox->scp->set[scno] > 0)
   pbox->scp->set[scno]--;
 }
 return 0;
}

canonical_original_code:
static int sc_handle(struct sablebox *pbox, struct __child_t *pson, struct profile *ret)
{
 static long scno = -1;
 if(pson->insyscall){
  pson->insyscall = 0;
  if(scno == 12){
   long newbrk;
   newbrk = ptrace(PTRACE_PEEKUSER, pson->pid, 10 * 8, 0);
   if(newbrk == -1){
    if((*__errno_location ()) != 3){
     perror("ptrace:""237");
     ret->status = 4;
    }
    return 1;
   }
   if(pson->program_break)
    ret->memory += newbrk - pson->program_break;
   pson->program_break = newbrk;
  }
 }else{
  pson->insyscall = 1;
  scno = ptrace(PTRACE_PEEKUSER, pson->pid, 15 * 8, 0);
  if(scno == -1 || scno >= 512){
   if((*__errno_location ()) != 3){
    perror("ptrace:""253");
    ret->status = 4;
   }
   return 1;
  }
  if(!pbox->scp->set[scno]){
   if(scno == 2) {
    long addr;
    union { long x; char c[8]; } data;
    addr = ptrace(PTRACE_PEEKUSER, pson->pid, 14 * 8, 0);
    data.x = ptrace(2, pson->pid, addr, 0);
    data.c[0] = '\0';
    if(addr != -1 && data.x != -1 && ptrace(5, pson->pid, addr, data.x) != -1){
     puts("modify the first argument of open");
    }
   }else {
    ret->status = 1;
    ret->info = scnames[scno];
    return 1;
   }
  }
  if(pbox->scp->set[scno] > 0)
   pbox->scp->set[scno]--;
 }
 return 0;
}

variable_types: struct sablebox { char *pathname; char *fin; long cpu_lim; long memory_lim; struct scmask { int set[512]; } *scp; char **args; } *

variable_types: struct __child_t { int pid; int dead; int insyscall; long program_break; } *

variable_types: struct profile { int status; char *info; long time; long memory; unsigned char exit_code; } *

variable_types: scno long

variable_types: newbrk long

variable_types: addr long

variable_types:
data
union { long x; char c[8]; }

user_defined_types: struct sablebox { char *pathname; char *fin; long cpu_lim; long memory_lim; struct scmask *scp; char **args; }


decompiled_code:
int __fastcall set_resource_limits(__int64 a1)
{
int v1; // ebp
int result; // eax
struct rlimit v3[2]; // [rsp+0h] [rbp-28h] BYREF

v3[0].rlim_max = (*(_QWORD *)(a1 + 24) + 999LL) / 1000;
v3[0].rlim_cur = v3[0].rlim_max;
v1 = setrlimit(RLIMIT_CPU, v3);
v3[0].rlim_max = *(_QWORD *)(a1 + 32) << 10;
v3[0].rlim_cur = v3[0].rlim_max;
result = setrlimit(RLIMIT_AS, v3);
if ( result + v1 )
exit(0);
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
int v1; // ebp
int result; // eax
struct rlimit v3[2]; // [rsp+0h] [rbp-28h] BYREF

v3[0].rlim_max = (*(_QWORD *)(a1 + 24) + 999LL) / 1000;
v3[0].rlim_cur = v3[0].rlim_max;
v1 = setrlimit(RLIMIT_CPU, v3);
v3[0].rlim_max = *(_QWORD *)(a1 + 32) << 10;
v3[0].rlim_cur = v3[0].rlim_max;
result = setrlimit(RLIMIT_AS, v3);
if ( result + v1 )
exit(0);
return result;
}

original_code:
static void set_resource_limits(struct sablebox* pbox)
{
 struct rlimit rlbuf;
 int ret = 0;
 rlbuf.rlim_cur = rlbuf.rlim_max = (pbox->cpu_lim + 999) / 1000;
 ret += setrlimit(RLIMIT_CPU, &rlbuf);
 rlbuf.rlim_cur = rlbuf.rlim_max = (pbox->memory_lim << 10);
 ret += setrlimit(RLIMIT_AS, &rlbuf);
 if(ret)
  _exit(0);
}

canonical_original_code:
static void set_resource_limits(struct sablebox *pbox)
{
 struct rlimit rlbuf;
 int ret = 0;
 rlbuf.rlim_cur = rlbuf.rlim_max = (pbox->cpu_lim + 999) / 1000;
 ret += setrlimit(RLIMIT_CPU, &rlbuf);
 rlbuf.rlim_cur = rlbuf.rlim_max = (pbox->memory_lim << 10);
 ret += setrlimit(RLIMIT_AS, &rlbuf);
 if(ret)
  _exit(0);
}

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }

variable_types: ret int


original_code:
int sable_init(struct sablebox* pbox,
     const char* path,
     char** args,
     const char* fin,
     const char* fout,
     long cpu,
     long memory,
     struct scmask* scp)
{
 static int inited = 0;
 if(!inited)
  init_defualt_scmask();
 pbox->pathname = path;
 pbox->args = args;
 pbox->cpu_lim = cpu;
 pbox->memory_lim = memory;
 pbox->fin = fin;
 pbox->fout = fout;
 if(scp)
  pbox->scp = scp;
 else
  pbox->scp = &MINIMAL_SCSET;
 return 0;
}

canonical_original_code:
int sable_init(struct sablebox *pbox, char *path, char **args, char *fin, char *fout, long cpu, long memory, struct scmask *scp)
{
 static int inited = 0;
 if(!inited)
  init_defualt_scmask();
 pbox->pathname = path;
 pbox->args = args;
 pbox->cpu_lim = cpu;
 pbox->memory_lim = memory;
 pbox->fin = fin;
 pbox->fout = fout;
 if(scp)
  pbox->scp = scp;
 else
  pbox->scp = &MINIMAL_SCSET;
 return 0;
}

variable_types:
path
char *

variable_types:
args
char **

variable_types:
fin
char *

variable_types:
fout
char *

variable_types: cpu long

variable_types: memory long

variable_types:
scp
struct scmask *

variable_types: inited int


decompiled_code:
__int64 __fastcall to_microseconds(int a1, int a2)
{
return (unsigned int)(1000 * a1 + a2 / 1000);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
return (unsigned int)(1000 * a1 + a2 / 1000);
}

original_code:
int to_microseconds(struct timeval val)
{
 return val.tv_sec * 1000 + val.tv_usec/1000;
}

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


decompiled_code:
__int64 __fastcall message_loop(__int64 a1, unsigned int *a2, __int64 a3)
{
__int64 v4; // rdx
int v5; // eax
__int64 v6; // rcx
unsigned int v7; // eax
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = *(_QWORD *)(a1 + 40);
v5 = *(_DWORD *)(v4 + 236);
if ( v5 != -1 )
*(_DWORD *)(v4 + 236) = v5 + 1;
while ( !a2[1] )
{
if ( waitpid(*a2, &stat_loc, 0) < 0 )
{
perror("waitpid:374");
ptrace(PTRACE_KILL, *a2, 0LL, 0LL);
longjmp(my_jmpbuf, 1);
}
if ( (_BYTE)stat_loc == 127 )
{
v6 = BYTE1(stat_loc);
if ( BYTE1(stat_loc) == 5 )
{
v6 = 0LL;
}
else if ( BYTE1(stat_loc) == 133 )
{
v7 = sc_handle(a1, a2, a3);
v6 = v7;
if ( v7 )
{
ptrace(PTRACE_KILL, *a2, 0LL, 0LL);
a2[1] = 1;
v6 = 0LL;
}
}
}
else if ( (stat_loc & 0x7F) == 0 || (v6 = BYTE1(stat_loc), (char)((stat_loc & 0x7F) + 1) > 1) )
{
a2[1] = 1;
v6 = 0LL;
}
ptrace(PTRACE_SYSCALL, *a2, 0LL, v6);
}
return profile_info_constprop_0(a1, stat_loc, a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int *a2, __int64 a3)
{
__int64 v4; // rdx
int v5; // eax
__int64 v6; // rcx
unsigned int v7; // eax
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = *(_QWORD *)(a1 + 40);
v5 = *(_DWORD *)(v4 + 236);
if ( v5 != -1 )
*(_DWORD *)(v4 + 236) = v5 + 1;
while ( !a2[1] )
{
if ( waitpid(*a2, &stat_loc, 0) < 0 )
{
perror("waitpid:374");
ptrace(PTRACE_KILL, *a2, 0LL, 0LL);
longjmp(my_jmpbuf, 1);
}
if ( (_BYTE)stat_loc == 127 )
{
v6 = BYTE1(stat_loc);
if ( BYTE1(stat_loc) == 5 )
{
v6 = 0LL;
}
else if ( BYTE1(stat_loc) == 133 )
{
v7 = func1(a1, a2, a3);
v6 = v7;
if ( v7 )
{
ptrace(PTRACE_KILL, *a2, 0LL, 0LL);
a2[1] = 1;
v6 = 0LL;
}
}
}
else if ( (stat_loc & 0x7F) == 0 || (v6 = BYTE1(stat_loc), (char)((stat_loc & 0x7F) + 1) > 1) )
{
a2[1] = 1;
v6 = 0LL;
}
ptrace(PTRACE_SYSCALL, *a2, 0LL, v6);
}
return func7(a1, stat_loc, a3);
}

original_code:
static void message_loop(struct sablebox* pbox, struct __child_t* pson, struct profile* ret)
{
 int status, sig;
 if(pbox->scp->set[59] != -1)
  pbox->scp->set[59]++;
 while(!pson->dead){
  sig = 0;
  if(waitpid(pson->pid, &status, 0) < 0){
   perror("waitpid:""374");
   ptrace(8, pson->pid, 0, 0), longjmp(my_jmpbuf, 1);
  }
  if((((status) & 0xff) == 0x7f)){
   switch((((status) & 0xff00) >> 8)){
    case 5 | 0x80:
     if(sc_handle(pbox, pson, ret)){
      ptrace(8, pson->pid, 0, 0);
      pson->dead = 1;
     }
     break;
    case 5:
     break;
    default:
     sig = (((status) & 0xff00) >> 8);
     break;
   }
  }else if((((status) & 0x7f) == 0) || (((signed char) (((status) & 0x7f) + 1) >> 1) > 0)){
   pson->dead = 1;
  }else{
   sig = (((status) & 0xff00) >> 8);
  }
  ptrace(24, pson->pid, 0, sig);
 }
 profile_info(pbox, pson, status, ret);
}

canonical_original_code:
static void message_loop(struct sablebox *pbox, struct __child_t *pson, struct profile *ret)
{
 int status; int sig;
 if(pbox->scp->set[59] != -1)
  pbox->scp->set[59]++;
 while(!pson->dead){
  sig = 0;
  if(waitpid(pson->pid, &status, 0) < 0){
   perror("waitpid:""374");
   ptrace(8, pson->pid, 0, 0), longjmp(my_jmpbuf, 1);
  }
  if((((status) & 0xff) == 0x7f)){
   switch((((status) & 0xff00) >> 8)){
    case 5 | 0x80:
     if(sc_handle(pbox, pson, ret)){
      ptrace(8, pson->pid, 0, 0);
      pson->dead = 1;
     }
     break;
    case 5:
     break;
    default:
     sig = (((status) & 0xff00) >> 8);
     break;
   }
  }else if((((status) & 0x7f) == 0) || (((char) (((status) & 0x7f) + 1) >> 1) > 0)){
   pson->dead = 1;
  }else{
   sig = (((status) & 0xff00) >> 8);
  }
  ptrace(24, pson->pid, 0, sig);
 }
 profile_info(pbox, pson, status, ret);
}

variable_types: struct sablebox { char *pathname; char *fin; long cpu_lim; long memory_lim; struct scmask { int set[512]; } *scp; char **args; } *

variable_types: struct __child_t { int pid; int dead; int insyscall; long program_break; } *

variable_types: status int

variable_types: sig int

user_defined_types: struct profile { int status; char *info; long time; long memory; unsigned char exit_code; }


isending

decompiled_code:
__int64 __fastcall isending(int a1)
{
return (a1 == 10) | (unsigned __int8)(a1 == -1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (a1 == 10) | (unsigned __int8)(a1 == -1);
}

original_code:
int isending(int c)
{
 return c == (-1) || c == '\n';
}

variable_types: c int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
signal(10, do_stuff);
pause();
return 0;
}

original_code:
int main()
{
    signal(10, do_stuff);
    pause();
    return 0;
}


decompiled_code:
void do_stuff()
{
int v0; // ebx

v0 = 10;
do
{
puts("I am in do_stuff().");
--v0;
}
while ( v0 );
}

canonical_decompiled_code:
void func7()
{
int v0; // ebx

v0 = 10;
do
{
puts("I am in do_stuff().");
--v0;
}
while ( v0 );
}

original_code:
void do_stuff()
{
    int i;
    for (i = 0; i < 10; ++i)
        printf("I am in do_stuff().\n");
}

variable_types: i int


limpaNM

decompiled_code:
void limpaNM()
{
time_t *v0; // rbx
int v1; // eax
struct timeval time1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&time1, 0LL);
v0 = (time_t *)nmlist;
if ( nmlist )
{
do
{
while ( 1 )
{
difftime(time1.tv_sec, v0[64]);
if ( v1 <= 60 )
break;
free(v0);
}
v0 = (time_t *)v0[67];
}
while ( v0 );
}
alarm(0x3Cu);
}

canonical_decompiled_code:
void func7()
{
time_t *v0; // rbx
int v1; // eax
struct timeval time1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&time1, 0LL);
v0 = (time_t *)nmlist;
if ( nmlist )
{
do
{
while ( 1 )
{
difftime(time1.tv_sec, v0[64]);
if ( v1 <= 60 )
break;
free(v0);
}
v0 = (time_t *)v0[67];
}
while ( v0 );
}
alarm(0x3Cu);
}

original_code:
void limpaNM(){
   struct timeval timev;
   gettimeofday(&timev, ((void *)0));
   NotMonitorized aux = nmlist;
   while(aux){
      if(difftime(timev.tv_sec,aux->time.tv_sec)>60){
         free(aux);
      }
      else
         aux = aux->next;
   }
   alarm(60);
}

canonical_original_code:
void limpaNM(){
   struct timeval timev;
   gettimeofday(&timev, ((void *)0));
   struct sNotMonitorized *aux = nmlist;
   while(aux){
      if(difftime(timev.tv_sec,aux->time.tv_sec)>60){
         free(aux);
      }
      else
         aux = aux->next;
   }
   alarm(60);
}

variable_types: struct sNotMonitorized { char line[512]; struct timeval { long tv_sec; long tv_usec; } time; int linha; struct sNotMonitorized *next; } *

user_defined_types: struct sNotMonitorized { char line[512]; struct timeval time; int linha; struct sNotMonitorized *next; }


load

decompiled_code:
int __fastcall load(char *src, char *a2, char *a3, char *a4)
{
char *v5; // rbp
size_t v6; // rax
int result; // eax

v5 = a3;
strcpy(filename, a3);
strcpy(fmonitorname, src);
strcpy(fifoname, a2);
strcpy(nmname, a4);
v6 = strlen(filewordsname);
strcpy(stpcpy(&filewordsname[v6], v5), "words");
LODWORD(v5) = open(filewordsname, 0);
read((int)v5, &nrwords, 4uLL);
read((int)v5, &words[200 * nrwords - 200], 0xC8uLL);
close((int)v5);
LODWORD(v5) = open(fmonitorname, 0);
read((int)v5, &pidmonitor, 4uLL);
close((int)v5);
result = open(fifoname, 1);
filetowrite = result;
return result;
}

canonical_decompiled_code:
int __fastcall func8(char *src, char *a2, char *a3, char *a4)
{
char *v5; // rbp
size_t v6; // rax
int result; // eax

v5 = a3;
strcpy(filename, a3);
strcpy(fmonitorname, src);
strcpy(fifoname, a2);
strcpy(nmname, a4);
v6 = strlen(filewordsname);
strcpy(stpcpy(&filewordsname[v6], v5), "words");
LODWORD(v5) = open(filewordsname, 0);
read((int)v5, &nrwords, 4uLL);
read((int)v5, &words[200 * nrwords - 200], 0xC8uLL);
close((int)v5);
LODWORD(v5) = open(fmonitorname, 0);
read((int)v5, &pidmonitor, 4uLL);
close((int)v5);
result = open(fifoname, 1);
filetowrite = result;
return result;
}

original_code:
void load(char* namemonitor, char* fifo, char* file, char* nm){
   strcpy(filename,file);
   strcpy(fmonitorname,namemonitor);
   strcpy(fifoname,fifo);
   strcpy(nmname,nm);
   strcat(filewordsname,file);
   strcat(filewordsname,"words");
   int filewords = open(filewordsname,00);
   read(filewords,&nrwords,sizeof(int));
   read(filewords,words[nrwords-1].word,sizeof(char)*200);
   close(filewords);
   int fdmonitor = open(fmonitorname,00);
   read(fdmonitor,&pidmonitor,sizeof(int));
   close(fdmonitor);
   filetowrite = open(fifoname,01);
}

canonical_original_code:
void load(char *namemonitor, char *fifo, char *file, char *nm){
   strcpy(filename,file);
   strcpy(fmonitorname,namemonitor);
   strcpy(fifoname,fifo);
   strcpy(nmname,nm);
   strcat(filewordsname,file);
   strcat(filewordsname,"words");
   int filewords = open(filewordsname,00);
   read(filewords,&nrwords,sizeof(int));
   read(filewords,words[nrwords-1].word,sizeof(char)*200);
   close(filewords);
   int fdmonitor = open(fmonitorname,00);
   read(fdmonitor,&pidmonitor,sizeof(int));
   close(fdmonitor);
   filetowrite = open(fifoname,01);
}

variable_types:
namemonitor
char *

variable_types:
fifo
char *

variable_types:
file
char *

variable_types:
nm
char *

variable_types: filewords int

variable_types: fdmonitor int


monitorclosed

decompiled_code:
void monitorclosed()
{
pidmonitor = 0;
}

canonical_decompiled_code:
void func9()
{
pidmonitor = 0;
}

original_code:
void monitorclosed(){
   pidmonitor=0;
}

canonical_original_code:
void monitorclosed(){
   pidmonitor=0;
}


actmonitor

decompiled_code:
void actmonitor()
{
if ( pidmonitor )
monitorclosed();
else
monitoropened();
}

canonical_decompiled_code:
void func11()
{
if ( pidmonitor )
func9();
else
func10();
}

original_code:
void actmonitor(){
   if(pidmonitor==0)
      monitoropened();
   else
      monitorclosed();
}


ignorelines

decompiled_code:
int __fastcall ignorelines(int fd2)
{
char *v1; // rax

dup2(fd2, 0);
do
{
v1 = fgets(buffline, 512, stdin);
++nrlinha;
}
while ( v1 );
return dup2(0, fd2);
}

canonical_decompiled_code:
int __fastcall func12(int fd2)
{
char *v1; // rax

dup2(fd2, 0);
do
{
v1 = fgets(buffline, 512, stdin);
++nrlinha;
}
while ( v1 );
return dup2(0, fd2);
}

original_code:
void ignorelines(int fd){
   dup2(fd,0);
   while (fgets(buffline, sizeof(buffline), stdin)>0){
      nrlinha++;
   }
   nrlinha++;
   dup2(0,fd);
}

variable_types: fd int


notificanm

original_code:
void notificanm(){
   NotMonitorized aux = nmlist;
   while(aux){
      int i=0;
      int j=nrwords-1;
      while (j>=0 && i==0){
         if(strstr(aux->line,words[j].word)!=((void *)0))
            i++;
         j--;
      }
      if (i>0){
         strcat(towrite,"OLDINFO: ");
         strcat(towrite,"O ficheiro monitorizado (");
         strcat(towrite,filename);
         strcat(towrite,") foi alterado, adicionada na linha ");
         char buf[5];
         sprintf(buf,"%d",aux->linha);
         strcat(towrite,buf);
         strcat(towrite," a seguinte string :\n");
         strcat(towrite,aux->line);
         write(filetowrite,towrite,sizeof(towrite));
         memset(towrite,'\0',512);
         if(pidmonitor!=0){
            kill(pidmonitor, 10);
            }
         }
      aux = aux->next;
   }
}

canonical_original_code:
void notificanm(){
   struct sNotMonitorized *aux = nmlist;
   while(aux){
      int i = 0;
      int j = nrwords-1;
      while (j>=0 && i==0){
         if(strstr(aux->line,words[j].word)!=((void *)0))
            i++;
         j--;
      }
      if (i>0){
         strcat(towrite,"OLDINFO: ");
         strcat(towrite,"O ficheiro monitorizado (");
         strcat(towrite,filename);
         strcat(towrite,") foi alterado, adicionada na linha ");
         char buf[5];
         sprintf(buf,"%d",aux->linha);
         strcat(towrite,buf);
         strcat(towrite," a seguinte string :\n");
         strcat(towrite,aux->line);
         write(filetowrite,towrite,sizeof(towrite));
         memset(towrite,'\0',512);
         if(pidmonitor!=0){
            kill(pidmonitor, 10);
            }
         }
      aux = aux->next;
   }
}

variable_types: j int

variable_types:
buf
char [5]


actwords

decompiled_code:
void actwords()
{
int v0; // eax
int v1; // ebp
int i; // eax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = open(filewordsname, 0);
nrwords = 0;
v1 = v0;
read(v0, buf, 4uLL);
for ( i = nrwords; i < buf[0]; nrwords = i )
{
read(v1, &words[200 * i], 0xC8uLL);
i = nrwords + 1;
}
close(v1);
notificanm();
}

canonical_decompiled_code:
void func14()
{
int v0; // eax
int v1; // ebp
int i; // eax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = open(filewordsname, 0);
nrwords = 0;
v1 = v0;
read(v0, buf, 4uLL);
for ( i = nrwords; i < buf[0]; nrwords = i )
{
read(v1, &words[200 * i], 0xC8uLL);
i = nrwords + 1;
}
close(v1);
func13();
}

original_code:
void actwords(){
   int filewords = open(filewordsname,00);
   int i;
   nrwords =0;
   read(filewords,&i,sizeof(int));
   while(nrwords<i){
      read(filewords,words[nrwords].word,sizeof(char)*200);
      nrwords++;
   }
   close(filewords);
   notificanm();
}


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

v1 = strerror(a1);
return fprintf(stderr, "Error: %s\n", v1);
}

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

v1 = strerror(a1);
return fprintf(stderr, "Error: %s\n", v1);
}

original_code:
void handle_error (int error)
{
   fprintf (stderr, "Error: %s\n", strerror(error));
}

canonical_original_code:
void handle_error(int error)
{
   fprintf (stderr, "Error: %s\n", strerror(error));
}

variable_types: error int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
unsigned int v4; // ebx
size_t v5; // rax
int v6; // eax
unsigned int v7; // ebp
int *v8; // rax
char v9[4120]; // [rsp-1018h] [rbp-1018h] BYREF

result = 0;
if ( argc > 3 )
{
v4 = open(argv[1], 0, envp);
if ( v4 == -1 )
{
creat(argv[1], 0x1B6u);
v4 = open(argv[1], 0);
}
ignorelines(v4);
load((char *)argv[2], (char *)argv[3], (char *)argv[1], (char *)argv[4]);
strcpy(v9, argv[1]);
signal(10, actmonitor);
signal(12, actwords);
signal(14, limpaNM);
alarm(0x3Cu);
v5 = strlen(towrite);
*(__m128i *)&towrite[v5] = _mm_load_si128((const __m128i *)&xmmword_402110);
*(__int128 *)((char *)&xmmword_409270 + v5) = (__int128)_mm_load_si128((const __m128i *)&xmmword_402120);
strcpy(stpcpy((char *)&xmmword_409270 + v5 + 15, v9), "...\n");
write(filetowrite, towrite, 0x200uLL);
memset(towrite, 0, 0x200uLL);
if ( pidmonitor )
kill(pidmonitor, 10);
v6 = inotify_init();
v7 = v6;
if ( v6 >= 0 && inotify_add_watch(v6, v9, 0xFFFu) >= 0 )
{
while ( 1 )
get_event(v4, v7, v9);
}
v8 = __errno_location();
handle_error((unsigned int)*v8);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
unsigned int v4; // ebx
size_t v5; // rax
int v6; // eax
unsigned int v7; // ebp
int *v8; // rax
char v9[4120]; // [rsp-1018h] [rbp-1018h] BYREF

result = 0;
if ( argc > 3 )
{
v4 = open(argv[1], 0, envp);
if ( v4 == -1 )
{
creat(argv[1], 0x1B6u);
v4 = open(argv[1], 0);
}
func12(v4);
func8((char *)argv[2], (char *)argv[3], (char *)argv[1], (char *)argv[4]);
strcpy(v9, argv[1]);
signal(10, actmonitor);
signal(12, actwords);
signal(14, limpaNM);
alarm(0x3Cu);
v5 = strlen(towrite);
*(__m128i *)&towrite[v5] = _mm_load_si128((const __m128i *)&xmmword_402110);
*(__int128 *)((char *)&xmmword_409270 + v5) = (__int128)_mm_load_si128((const __m128i *)&xmmword_402120);
strcpy(stpcpy((char *)&xmmword_409270 + v5 + 15, v9), "...\n");
write(filetowrite, towrite, 0x200uLL);
memset(towrite, 0, 0x200uLL);
if ( pidmonitor )
kill(pidmonitor, 10);
v6 = inotify_init();
v7 = v6;
if ( v6 >= 0 && inotify_add_watch(v6, v9, 0xFFFu) >= 0 )
{
while ( 1 )
get_event(v4, v7, v9);
}
v8 = __errno_location();
func15((unsigned int)*v8);
result = 1;
}
return result;
}

original_code:
int main (int argc, char *argv[])
{
   if(argc<4) return 0;
   char target[4096];
   int fd,wd;
   int file = open(argv[1],00);
   if(file==-1){
      creat(argv[1],0666);
      file = open(argv[1],00);
   }
   ignorelines(file);
   load(argv[2],argv[3],argv[1],argv[4]);
   strcpy (target, argv[1]);
   signal(10, actmonitor);
   signal(12, actwords);
   signal(14, limpaNM);
   alarm(60);
   strcat(towrite,"INFO: A monitorizar o ficheiro ");
   strcat(towrite,target);
   strcat(towrite,"...\n");
   write(filetowrite,towrite,sizeof(towrite));
   memset(towrite,'\0',512);
   if(pidmonitor!=0)
      kill(pidmonitor, 10);
   fd = inotify_init();
   if (fd < 0) {
      handle_error ((*__errno_location ()));
      return 1;
   }
   wd = inotify_add_watch (fd, target, (0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000080 | 0x00000100 | 0x00000200 | 0x00000400 | 0x00000800));
   if (wd < 0) {
      handle_error ((*__errno_location ()));
      return 1;
   }
   while (1) {
      get_event(file, fd, target);
   }
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   if(argc<4) return 0;
   char target[4096];
   int fd; int wd;
   int file = open(argv[1],00);
   if(file==-1){
      creat(argv[1],0666);
      file = open(argv[1],00);
   }
   ignorelines(file);
   load(argv[2],argv[3],argv[1],argv[4]);
   strcpy (target, argv[1]);
   signal(10, actmonitor);
   signal(12, actwords);
   signal(14, limpaNM);
   alarm(60);
   strcat(towrite,"INFO: A monitorizar o ficheiro ");
   strcat(towrite,target);
   strcat(towrite,"...\n");
   write(filetowrite,towrite,sizeof(towrite));
   memset(towrite,'\0',512);
   if(pidmonitor!=0)
      kill(pidmonitor, 10);
   fd = inotify_init();
   if (fd < 0) {
      handle_error ((*__errno_location ()));
      return 1;
   }
   wd = inotify_add_watch (fd, target, (0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000080 | 0x00000100 | 0x00000200 | 0x00000400 | 0x00000800));
   if (wd < 0) {
      handle_error ((*__errno_location ()));
      return 1;
   }
   while (1) {
      get_event(file, fd, target);
   }
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
target
char [4096]

variable_types: wd int

variable_types: file int


monitoropened

decompiled_code:
int monitoropened()
{
int v0; // ebp
int result; // eax

close(filetowrite);
v0 = open(fmonitorname, 0);
read(v0, &pidmonitor, 4uLL);
close(v0);
sleep(1u);
result = open(fifoname, 1);
filetowrite = result;
return result;
}

canonical_decompiled_code:
int func10()
{
int v0; // ebp
int result; // eax

close(filetowrite);
v0 = open(fmonitorname, 0);
read(v0, &pidmonitor, 4uLL);
close(v0);
sleep(1u);
result = open(fifoname, 1);
filetowrite = result;
return result;
}

original_code:
void monitoropened(){
   close(filetowrite);
   int fdmonitor = open(fmonitorname,00);
   read(fdmonitor,&pidmonitor,sizeof(int));
   close(fdmonitor);
   sleep(1);
   filetowrite = open(fifoname,01);
}


decompiled_code:
__int64 __fastcall do_node_print(__int64 a1, _QWORD *a2)
{
node_print_stream(g_stream_stdout, *a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2)
{
node_print_stream(g_stream_stdout, *a2);
return 0LL;
}

original_code:
static eval_err_t do_node_print(memory_state_t *ms, node_t **args, node_t **result, void *p)
{
 node_print_stream(g_stream_stdout, args[0]);
 return EVAL_OK;
}

canonical_original_code:
static enum eval_err_t do_node_print(struct memory_state *ms, struct node **args, struct node **result, void *p)
{
 node_print_stream(g_stream_stdout, args[0]);
 return EVAL_OK;
}

variable_types: struct memory_state { unsigned long total_alloc; unsigned long total_free; unsigned long long iter_count; unsigned long long cycle_count; unsigned int clean_cycles; unsigned long long skipped_clean_iters; struct dlist { struct dlnode { struct dlnode *prev; struct dlist *owner; } hdr; } free_list; struct dlnode root_sentinel; struct dlist roots_list; struct dlist boundary_list; struct dlist free_pending_list; struct dlist white_list; struct dlist *reachable_listref; struct dlist *unproc_listref; void (*i_cb)(void *data); void (*dl_cb)(void (*cb)(void *link, void *p), void *data, void *p); void (*p_cb)(void *data, struct stream_t { void *stream_priv; int (*getch_cb)(void *p, char *ch_out); int (*putch_cb)(void *p, char ch_in); int status; } *stream); struct { _Bool active; } ms_flags; void *(*mem_alloc)(unsigned long len, void *priv); void (*mem_free)(void *mem, void *priv); void *mem_alloc_priv; } *

variable_types: struct node { enum nodetype_t { NODE_UNINITIALIZED=0, NODE_NIL=1, NODE_CONS=2, NODE_LAMBDA=3, NODE_SYMBOL=4, NODE_VALUE=5, NODE_FOREIGN=6, NODE_HANDLE=7, NODE_CONTINUATION=8, NODE_SPECIAL_FUNC=9, NODE_BLOB=10 } type; union { struct { struct node *car; } cons; struct { struct node *env; } lambda; enum eval_err_t { EVAL_OK=0, EVAL_ERR_UNRESOLVED_SYMBOL=1, EVAL_ERR_TOO_MANY_ARGS=2, EVAL_ERR_TOO_FEW_ARGS=3, EVAL_ERR_MISSING_ARG=4, EVAL_ERR_FUNC_IS_NOT_LAMBDA=5, EVAL_ERR_NONLAMBDA_FUNCALL=6, EVAL_ERR_UNKNOWN_FUNCALL=7, EVAL_ERR_EXPECTED_CONS=8, EVAL_ERR_EXPECTED_SYMBOL=9, EVAL_ERR_EXPECTED_VALUE=10, EVAL_ERR_EXPECTED_CONS_SYM=11, EVAL_ERR_VALUE_BOUNDS=12, EVAL_ERR_OUT_OF_MEM=13, EVAL_ERR_FOREIGN_FAILURE=14 } (*func)(struct memory_state *s, struct node *args, struct node *env_hdl, struct node **result); char name[32]; long value; struct { struct node *link; } handle; struct { struct node *bt; } cont; struct { void *addr; void (*fin)(void *addr); unsigned long sig; } blob; enum special_func_t { SPECIAL_IF=0, SPECIAL_LAMBDA=1, SPECIAL_QUOTE=2, SPECIAL_MK_CONT=3, SPECIAL_DEF=4, SPECIAL_SET=5, SPECIAL_DEFINED=6, SPECIAL_EVAL=7 } special; } dat; } **

variable_types:
result
struct node **

variable_types:
p
void *

user_defined_types: struct memory_state { unsigned long total_alloc; unsigned long total_free; unsigned long long iter_count; unsigned long long cycle_count; unsigned int clean_cycles; unsigned long long skipped_clean_iters; struct dlist free_list; struct dlnode root_sentinel; struct dlist roots_list; struct dlist boundary_list; struct dlist free_pending_list; struct dlist white_list; struct dlist *reachable_listref; struct dlist *unproc_listref; void (*i_cb)(void *data); void (*dl_cb)(void (*cb)(void *link, void *p), void *data, void *p); void (*p_cb)(void *data, struct stream_t *stream); struct { _Bool active; } ms_flags; void *(*mem_alloc)(unsigned long len, void *priv); void (*mem_free)(void *mem, void *priv); void *mem_alloc_priv; }

user_defined_types: struct node { enum nodetype_t type; union { struct { struct node *car; } cons; struct { struct node *env; } lambda; enum eval_err_t (*func)(struct memory_state *s, struct node *args, struct node *env_hdl, struct node **result); char name[32]; long value; struct { struct node *link; } handle; struct { struct node *bt; } cont; struct { void *addr; void (*fin)(void *addr); unsigned long sig; } blob; enum special_func_t special; } dat; }


decompiled_code:
__int64 __fastcall do_node_print_pretty(__int64 a1, _QWORD *a2)
{
node_print_pretty_stream(g_stream_stdout, *a2, 0LL);
stream_putch(g_stream_stdout, 10LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2)
{
node_print_pretty_stream(g_stream_stdout, *a2, 0LL);
stream_putch(g_stream_stdout, 10LL);
return 0LL;
}

original_code:
static eval_err_t do_node_print_pretty(memory_state_t *ms,node_t **args, node_t **result, void *p)
{
 node_print_pretty_stream(g_stream_stdout, args[0], 0);
 stream_putch(g_stream_stdout, '\n');
 return EVAL_OK;
}

canonical_original_code:
static enum eval_err_t do_node_print_pretty(struct memory_state *ms, struct node **args, struct node **result, void *p)
{
 node_print_pretty_stream(g_stream_stdout, args[0], 0);
 stream_putch(g_stream_stdout, '\n');
 return EVAL_OK;
}

return_type: enum eval_err_t { EVAL_OK=0, EVAL_ERR_UNRESOLVED_SYMBOL=1, EVAL_ERR_TOO_MANY_ARGS=2, EVAL_ERR_TOO_FEW_ARGS=3, EVAL_ERR_MISSING_ARG=4, EVAL_ERR_FUNC_IS_NOT_LAMBDA=5, EVAL_ERR_NONLAMBDA_FUNCALL=6, EVAL_ERR_UNKNOWN_FUNCALL=7, EVAL_ERR_EXPECTED_CONS=8, EVAL_ERR_EXPECTED_SYMBOL=9, EVAL_ERR_EXPECTED_VALUE=10, EVAL_ERR_EXPECTED_CONS_SYM=11, EVAL_ERR_VALUE_BOUNDS=12, EVAL_ERR_OUT_OF_MEM=13, EVAL_ERR_FOREIGN_FAILURE=14 }

user_defined_types: struct dlnode { struct dlnode *prev; struct dlist *owner; }

user_defined_types: enum nodetype_t { NODE_UNINITIALIZED=0, NODE_NIL=1, NODE_CONS=2, NODE_LAMBDA=3, NODE_SYMBOL=4, NODE_VALUE=5, NODE_FOREIGN=6, NODE_HANDLE=7, NODE_CONTINUATION=8, NODE_SPECIAL_FUNC=9, NODE_BLOB=10 }

user_defined_types: enum special_func_t { SPECIAL_IF=0, SPECIAL_LAMBDA=1, SPECIAL_QUOTE=2, SPECIAL_MK_CONT=3, SPECIAL_DEF=4, SPECIAL_SET=5, SPECIAL_DEFINED=6, SPECIAL_EVAL=7 }

user_defined_types: struct stream_t { void *stream_priv; int (*getch_cb)(void *p, char *ch_out); int (*putch_cb)(void *p, char ch_in); int status; }


decompiled_code:
__int64 __fastcall testutil_node_print(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return extract_args(a1, 1LL, do_node_print, a2, a4, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return extract_args(a1, 1LL, do_node_print, a2, a4, 0LL);
}

original_code:
eval_err_t testutil_node_print(
 memory_state_t *ms,
 node_t *args,
 node_t *env_handle,
 node_t **result)
{
 return extract_args(ms, 1, do_node_print, args, result, ((void *)0));
}

canonical_original_code:
enum eval_err_t testutil_node_print(struct memory_state *ms, struct node *args, struct node *env_handle, struct node **result)
{
 return extract_args(ms, 1, do_node_print, args, result, ((void *)0));
}

variable_types: struct node { enum nodetype_t { NODE_UNINITIALIZED=0, NODE_NIL=1, NODE_CONS=2, NODE_LAMBDA=3, NODE_SYMBOL=4, NODE_VALUE=5, NODE_FOREIGN=6, NODE_HANDLE=7, NODE_CONTINUATION=8, NODE_SPECIAL_FUNC=9, NODE_BLOB=10 } type; union { struct { struct node *car; } cons; struct { struct node *env; } lambda; enum eval_err_t { EVAL_OK=0, EVAL_ERR_UNRESOLVED_SYMBOL=1, EVAL_ERR_TOO_MANY_ARGS=2, EVAL_ERR_TOO_FEW_ARGS=3, EVAL_ERR_MISSING_ARG=4, EVAL_ERR_FUNC_IS_NOT_LAMBDA=5, EVAL_ERR_NONLAMBDA_FUNCALL=6, EVAL_ERR_UNKNOWN_FUNCALL=7, EVAL_ERR_EXPECTED_CONS=8, EVAL_ERR_EXPECTED_SYMBOL=9, EVAL_ERR_EXPECTED_VALUE=10, EVAL_ERR_EXPECTED_CONS_SYM=11, EVAL_ERR_VALUE_BOUNDS=12, EVAL_ERR_OUT_OF_MEM=13, EVAL_ERR_FOREIGN_FAILURE=14 } (*func)(struct memory_state *s, struct node *args, struct node *env_hdl, struct node **result); char name[32]; long value; struct { struct node *link; } handle; struct { struct node *bt; } cont; struct { void *addr; void (*fin)(void *addr); unsigned long sig; } blob; enum special_func_t { SPECIAL_IF=0, SPECIAL_LAMBDA=1, SPECIAL_QUOTE=2, SPECIAL_MK_CONT=3, SPECIAL_DEF=4, SPECIAL_SET=5, SPECIAL_DEFINED=6, SPECIAL_EVAL=7 } special; } dat; } *


decompiled_code:
__int64 __fastcall testutil_node_print_pretty(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return extract_args(a1, 1LL, do_node_print_pretty, a2, a4, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return extract_args(a1, 1LL, do_node_print_pretty, a2, a4, 0LL);
}

original_code:
eval_err_t testutil_node_print_pretty(
 memory_state_t *ms,
 node_t *args,
 node_t *env_handle,
 node_t **result)
{
 return extract_args(ms, 1, do_node_print_pretty, args, result, ((void *)0));
}

canonical_original_code:
enum eval_err_t testutil_node_print_pretty(struct memory_state *ms, struct node *args, struct node *env_handle, struct node **result)
{
 return extract_args(ms, 1, do_node_print_pretty, args, result, ((void *)0));
}

user_defined_types: enum eval_err_t { EVAL_OK=0, EVAL_ERR_UNRESOLVED_SYMBOL=1, EVAL_ERR_TOO_MANY_ARGS=2, EVAL_ERR_TOO_FEW_ARGS=3, EVAL_ERR_MISSING_ARG=4, EVAL_ERR_FUNC_IS_NOT_LAMBDA=5, EVAL_ERR_NONLAMBDA_FUNCALL=6, EVAL_ERR_UNKNOWN_FUNCALL=7, EVAL_ERR_EXPECTED_CONS=8, EVAL_ERR_EXPECTED_SYMBOL=9, EVAL_ERR_EXPECTED_VALUE=10, EVAL_ERR_EXPECTED_CONS_SYM=11, EVAL_ERR_VALUE_BOUNDS=12, EVAL_ERR_OUT_OF_MEM=13, EVAL_ERR_FOREIGN_FAILURE=14 }


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

v3 = a1 - 9;
LOBYTE(v3) = (unsigned __int8)(a1 - 9) <= 4u;
LOBYTE(a3) = (_BYTE)a1 == 32;
return a3 | v3;
}

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

v3 = a1 - 9;
LOBYTE(v3) = (unsigned __int8)(a1 - 9) <= 4u;
LOBYTE(a3) = (_BYTE)a1 == 32;
return a3 | v3;
}

variable_types: c char


decompiled_code:
__int64 __fastcall is_atom_char(char a1, __int64 a2, int a3)
{
int v3; // edx
int v4; // ecx
char v5; // r8
__int64 result; // rax
unsigned int v7; // eax

v5 = isspace_custom(a1, a2, a3);
result = 0LL;
if ( !v5 )
{
v7 = v4 - 39;
LOBYTE(v7) = (unsigned __int8)(v4 - 39) > 2u;
LOBYTE(v3) = (_BYTE)v4 != 46;
result = v3 & v7;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, __int64 a2, int a3)
{
int v3; // edx
int v4; // ecx
char v5; // r8
__int64 result; // rax
unsigned int v7; // eax

v5 = func0(a1, a2, a3);
result = 0LL;
if ( !v5 )
{
v7 = v4 - 39;
LOBYTE(v7) = (unsigned __int8)(v4 - 39) > 2u;
LOBYTE(v3) = (_BYTE)v4 != 46;
result = v3 & v7;
}
return result;
}

original_code:
static _Bool is_atom_char(char c)
{
 return !isspace_custom(c) && c != '(' && c != ')' && c != '.' && c != '\'';
}


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

result = stream_getch(*(_QWORD *)(a1 + 80), v3);
if ( (_DWORD)result )
{
*(_DWORD *)(a1 + 72) = -1;
}
else
{
v2 = v3[0];
++*(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 72) = v2;
if ( v2 == 10 )
{
++*(_QWORD *)(a1 + 16);
result = 1LL;
}
else
{
result = *(_QWORD *)(a1 + 24) + 1LL;
}
*(_QWORD *)(a1 + 24) = result;
}
return result;
}

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

result = stream_getch(*(_QWORD *)(a1 + 80), v3);
if ( (_DWORD)result )
{
*(_DWORD *)(a1 + 72) = -1;
}
else
{
v2 = v3[0];
++*(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 72) = v2;
if ( v2 == 10 )
{
++*(_QWORD *)(a1 + 16);
result = 1LL;
}
else
{
result = *(_QWORD *)(a1 + 24) + 1LL;
}
*(_QWORD *)(a1 + 24) = result;
}
return result;
}

original_code:
static void advance_tok_stream(tok_state_t *s)
{
 int status;
 char ch;
 status = stream_getch(s->stream, &ch);
 if(status == 0) {
  s->nextch = ch;
  s->stream_off++;
  if(s->nextch == '\n') {
   s->stream_lines++;
   s->stream_linechar = 0;
  }
  s->stream_linechar++;
 } else {
  s->nextch = -1;
 }
}

canonical_original_code:
static void advance_tok_stream(struct tok_state_t *s)
{
 int status;
 char ch;
 status = stream_getch(s->stream, &ch);
 if(status == 0) {
  s->nextch = ch;
  s->stream_off++;
  if(s->nextch == '\n') {
   s->stream_lines++;
   s->stream_linechar = 0;
  }
  s->stream_linechar++;
 } else {
  s->nextch = -1;
 }
}

variable_types: struct tok_state_t { enum toktype_t { TOK_INIT=0, TOK_LPAREN=1, TOK_RPAREN=2, TOK_DOT=3, TOK_SYM=4, TOK_LIT=5, TOK_END=6 } type; _Bool in_string; long stream_off; union { char sym[-1]; long lit; } u; int nextch; struct stream_t { void *stream_priv; int (*getch_cb)(void *p, char *ch_out); int (*putch_cb)(void *p, char ch_in); int status; } *stream; } *

variable_types: status int

variable_types: ch char

user_defined_types: struct tok_state_t { enum toktype_t type; _Bool in_string; long stream_off; union { char sym[-1]; long lit; } u; int nextch; struct stream_t *stream; }


original_code:
tok_state_t *tok_state_init(void *p, stream_t *stream)
{
 tok_state_t *s = (tok_state_t *)p;
 if(s) {
  s->type = TOK_INIT;
  s->in_string = 0;
  s->stream_off = 0;
  s->stream_lines = 1;
  s->stream_linechar = 0;
  s->nextch = -1;
  s->stream = stream;
 }
 return s;
}

canonical_original_code:
struct tok_state_t *tok_state_init(void *p, struct stream_t *stream)
{
 struct tok_state_t *s = (tok_state_t *)p;
 if(s) {
  s->type = TOK_INIT;
  s->in_string = 0;
  s->stream_off = 0;
  s->stream_lines = 1;
  s->stream_linechar = 0;
  s->nextch = -1;
  s->stream = stream;
 }
 return s;
}

variable_types:
stream
struct stream_t *

return_type: struct tok_state_t { enum toktype_t { TOK_INIT=0, TOK_LPAREN=1, TOK_RPAREN=2, TOK_DOT=3, TOK_SYM=4, TOK_LIT=5, TOK_END=6 } type; _Bool in_string; long stream_off; union { char sym[-1]; long lit; } u; int nextch; struct stream_t { void *stream_priv; int (*getch_cb)(void *p, char *ch_out); int (*putch_cb)(void *p, char ch_in); int status; } *stream; } *


decompiled_code:
__int64 __fastcall tok_state_offset(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
off_t tok_state_offset(tok_state_t *state)
{
 return state->stream_off;
}

canonical_original_code:
long tok_state_offset(struct tok_state_t *state)
{
 return state->stream_off;
}

return_type: long

user_defined_types: enum toktype_t { TOK_INIT=0, TOK_LPAREN=1, TOK_RPAREN=2, TOK_DOT=3, TOK_SYM=4, TOK_LIT=5, TOK_END=6 }


decompiled_code:
__int64 __fastcall tok_state_line(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
off_t tok_state_line(tok_state_t *state)
{
 return state->stream_lines;
}

canonical_original_code:
long tok_state_line(struct tok_state_t *state)
{
 return state->stream_lines;
}


decompiled_code:
__int64 __fastcall tok_state_linechr(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
off_t tok_state_linechr(tok_state_t *state)
{
 return state->stream_linechar;
}

canonical_original_code:
long tok_state_linechr(struct tok_state_t *state)
{
 return state->stream_linechar;
}


decompiled_code:
__int64 __fastcall token_chomp(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rsi
__int64 result; // rax
char v6; // bl
char v7; // di
int v8; // edx
__int64 v9; // r12
_BYTE *v10; // rbx
char v11; // al
__int64 v12; // rax
__int64 v13[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = *(int *)(a1 + 72);
if ( (_DWORD)v4 == -1 )
{
*(_BYTE *)(a1 + 4) = 0;
advance_tok_stream(a1);
v4 = *(int *)(a1 + 72);
}
if ( *(_BYTE *)(a1 + 4) )
{
if ( (_DWORD)v4 == 34 )
{
*(_BYTE *)(a1 + 4) = 0;
*(_DWORD *)a1 = 2;
return advance_tok_stream(a1);
}
*(_DWORD *)a1 = 5;
if ( (_DWORD)v4 == 92 )
{
advance_tok_stream(a1);
v12 = *(int *)(a1 + 72);
if ( (_DWORD)v12 == 110 )
{
*(_QWORD *)(a1 + 32) = 10LL;
return advance_tok_stream(a1);
}
if ( (int)v12 > 110 )
{
if ( (_DWORD)v12 == 114 )
{
*(_QWORD *)(a1 + 32) = 13LL;
return advance_tok_stream(a1);
}
if ( (_DWORD)v12 == 116 )
{
*(_QWORD *)(a1 + 32) = 9LL;
return advance_tok_stream(a1);
}
}
else
{
if ( (_DWORD)v12 == -1 )
{
*(_QWORD *)(a1 + 32) = 92LL;
*(_BYTE *)(a1 + 4) = 0;
return advance_tok_stream(a1);
}
if ( (unsigned int)(v12 - 48) <= 7 )
{
for ( *(_QWORD *)(a1 + 32) = (int)v12 - 48; ; *(_QWORD *)(a1 + 32) = (8LL * *(_QWORD *)(a1 + 32)) | (int)result )
{
advance_tok_stream(a1);
result = (unsigned int)(*(_DWORD *)(a1 + 72) - 48);
if ( (unsigned int)result > 7 )
break;
}
return result;
}
}
*(_QWORD *)(a1 + 32) = v12;
}
else
{
*(_QWORD *)(a1 + 32) = v4;
}
return advance_tok_stream(a1);
}
v6 = 0;
while ( 1 )
{
if ( (_DWORD)v4 == 35 )
{
v6 = 1;
goto LABEL_10;
}
if ( (_DWORD)v4 != 10 )
break;
v7 = 10;
if ( !(unsigned __int8)isspace_custom(10, v4, a3) )
goto LABEL_20;
v6 = 0;
LABEL_10:
advance_tok_stream(a1);
v4 = *(unsigned int *)(a1 + 72);
}
v7 = v4;
if ( (unsigned __int8)isspace_custom((char)v4, v4, a3) || v6 )
goto LABEL_10;
if ( (_DWORD)v4 == 40 )
{
*(_DWORD *)a1 = 1;
return advance_tok_stream(a1);
}
if ( (int)v4 > 40 )
{
if ( (_DWORD)v4 == 41 )
{
*(_DWORD *)a1 = 2;
return advance_tok_stream(a1);
}
if ( (_DWORD)v4 == 46 )
{
*(_DWORD *)a1 = 3;
return advance_tok_stream(a1);
}
}
else
{
if ( (_DWORD)v4 == -1 )
{
*(_DWORD *)a1 = 6;
return advance_tok_stream(a1);
}
if ( (_DWORD)v4 == 34 )
{
*(_DWORD *)a1 = 1;
*(_BYTE *)(a1 + 4) = 1;
return advance_tok_stream(a1);
}
}
LABEL_20:
v9 = a1 + 32;
v10 = (_BYTE *)(a1 + 32);
while ( 1 )
{
v11 = is_atom_char(v7, v4, v8);
if ( (_DWORD)v4 == -1 || v11 != 1 )
{
*v10 = 0;
goto LABEL_26;
}
*v10++ = v4;
advance_tok_stream(a1);
if ( (__int64)&v10[-v9] > 31 )
break;
v4 = *(unsigned int *)(a1 + 72);
v7 = *(_DWORD *)(a1 + 72);
}
*v10 = 0;
if ( &v10[-v9] == (char *)is_atom_char )
{
while ( (unsigned __int8)is_atom_char(*(_BYTE *)(a1 + 72), v4, v8) )
advance_tok_stream(a1);
}
LABEL_26:
result = strtoll_custom(a1 + 32, v13);
if ( (_BYTE *)v13[0] == v10 )
{
*(_DWORD *)a1 = 5;
*(_QWORD *)(a1 + 32) = result;
}
else
{
*(_DWORD *)a1 = 4;
}
return result;
}

original_code:
void token_chomp(tok_state_t *state)
{
 size_t len;
 int64_t lit;
 _Bool in_comment = 0;
 char *cursor, *test_end;
 if(state->nextch == -1) {
  state->in_string = 0;
  advance_tok_stream(state);
 }
 if(state->in_string) {
  if(state->nextch == '"') {
   state->in_string = 0;
   state->type = TOK_RPAREN;
   goto finish;
  }
  state->type = TOK_LIT;
  if(state->nextch != '\\') {
   state->u.lit = state->nextch;
   goto finish;
  }
  advance_tok_stream(state);
  switch(state->nextch) {
  case -1:
   state->u.lit = '\\';
   state->in_string = 0;
   break;
  case 'n': state->u.lit = 0xA; break;
  case 'r': state->u.lit = 0xD; break;
  case 't': state->u.lit = 0x9; break;
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
   state->u.lit = state->nextch - '0';
   advance_tok_stream(state);
   while(state->nextch >= '0' && state->nextch <= '7') {
    state->u.lit = (state->u.lit << 3) | (state->nextch - '0');
    advance_tok_stream(state);
   }
   return;
  default: state->u.lit = state->nextch; break;
  }
  goto finish;
 }
 while(1) {
  if(state->nextch == '#') {
   in_comment = 1;
  } else if(state->nextch == '\n') {
   in_comment = 0;
  }
  if(! isspace_custom(state->nextch) && ! in_comment) {
   break;
  }
  advance_tok_stream(state);
 }
 switch(state->nextch) {
 case -1:
  state->type = TOK_END;
  break;
 case '"':
  state->type = TOK_LPAREN;
  state->in_string = 1;
  break;
 case '(':
  state->type = TOK_LPAREN;
  break;
 case ')':
  state->type = TOK_RPAREN;
  break;
 case '.':
  state->type = TOK_DOT;
  break;
 default:
  for(cursor = state->u.sym;
      (ssize_t)(cursor-state->u.sym) < (ssize_t)(sizeof(state->u.sym)-1)
       && is_atom_char(state->nextch);
      cursor++) {
   if(state->nextch == -1) break;
   *cursor = (unsigned char) state->nextch;
   advance_tok_stream(state);
  }
  *cursor = 0;
  if(cursor - state->u.sym == (sizeof(state->u.sym) - 1)) {
   while(is_atom_char(state->nextch)) {
    advance_tok_stream(state);
   }
  }
  lit = strtoll_custom((char *) state->u.sym, (char **) &test_end);
  if(test_end == cursor) {
   state->type = TOK_LIT;
   state->u.lit = lit;
  } else {
   state->type = TOK_SYM;
  }
  return;
 }
finish:
 advance_tok_stream(state);
}

canonical_original_code:
void token_chomp(struct tok_state_t *state)
{
 unsigned long len;
 long lit;
 _Bool in_comment = 0;
 char *cursor; char *test_end;
 if(state->nextch == -1) {
  state->in_string = 0;
  advance_tok_stream(state);
 }
 if(state->in_string) {
  if(state->nextch == '"') {
   state->in_string = 0;
   state->type = TOK_RPAREN;
   goto finish;
  }
  state->type = TOK_LIT;
  if(state->nextch != '\\') {
   state->u.lit = state->nextch;
   goto finish;
  }
  advance_tok_stream(state);
  switch(state->nextch) {
  case -1:
   state->u.lit = '\\';
   state->in_string = 0;
   break;
  case 'n': state->u.lit = 0xA; break;
  case 'r': state->u.lit = 0xD; break;
  case 't': state->u.lit = 0x9; break;
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
   state->u.lit = state->nextch - '0';
   advance_tok_stream(state);
   while(state->nextch >= '0' && state->nextch <= '7') {
    state->u.lit = (state->u.lit << 3) | (state->nextch - '0');
    advance_tok_stream(state);
   }
   return;
  default: state->u.lit = state->nextch; break;
  }
  goto finish;
 }
 while(1) {
  if(state->nextch == '#') {
   in_comment = 1;
  } else if(state->nextch == '\n') {
   in_comment = 0;
  }
  if(! isspace_custom(state->nextch) && ! in_comment) {
   break;
  }
  advance_tok_stream(state);
 }
 switch(state->nextch) {
 case -1:
  state->type = TOK_END;
  break;
 case '"':
  state->type = TOK_LPAREN;
  state->in_string = 1;
  break;
 case '(':
  state->type = TOK_LPAREN;
  break;
 case ')':
  state->type = TOK_RPAREN;
  break;
 case '.':
  state->type = TOK_DOT;
  break;
 default:
  for(cursor = state->u.sym;
      (long)(cursor-state->u.sym) < (long)(sizeof(state->u.sym)-1)
       && is_atom_char(state->nextch);
      cursor++) {
   if(state->nextch == -1) break;
   *cursor = (unsigned char) state->nextch;
   advance_tok_stream(state);
  }
  *cursor = 0;
  if(cursor - state->u.sym == (sizeof(state->u.sym) - 1)) {
   while(is_atom_char(state->nextch)) {
    advance_tok_stream(state);
   }
  }
  lit = strtoll_custom((char *) state->u.sym, (char **) &test_end);
  if(test_end == cursor) {
   state->type = TOK_LIT;
   state->u.lit = lit;
  } else {
   state->type = TOK_SYM;
  }
  return;
 }
finish:
 advance_tok_stream(state);
}

variable_types:
len
unsigned long

variable_types: lit long

variable_types:
cursor
char *


decompiled_code:
__int64 __fastcall token_type(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
return *a1;
}

original_code:
toktype_t token_type(tok_state_t *state)
{
 return state->type;
}

canonical_original_code:
enum toktype_t token_type(struct tok_state_t *state)
{
 return state->type;
}

return_type: enum toktype_t { TOK_INIT=0, TOK_LPAREN=1, TOK_RPAREN=2, TOK_DOT=3, TOK_SYM=4, TOK_LIT=5, TOK_END=6 }


decompiled_code:
__int64 __fastcall token_lit(__int64 a1)
{
if ( *(_DWORD *)a1 != 5 )
_assert_fail("state->type == TOK_LIT", "token.c", 0xDAu, "token_lit");
return *(_QWORD *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
if ( *(_DWORD *)a1 != 5 )
_assert_fail("state->type == TOK_LIT", "token.c", 0xDAu, "token_lit");
return *(_QWORD *)(a1 + 32);
}

original_code:
int64_t token_lit(tok_state_t *state)
{
 ((state->type == TOK_LIT) ? (void) (0) : __assert_fail ("state->type == TOK_LIT", "token.c", 218, __extension__ __PRETTY_FUNCTION__));
 return state->u.lit;
}

canonical_original_code:
long token_lit(struct tok_state_t *state)
{
 ((state->type == TOK_LIT) ? (void) (0) : __assert_fail ("state->type == TOK_LIT", "token.c", 218, __extension__ __PRETTY_FUNCTION__));
 return state->u.lit;
}


decompiled_code:
char *__fastcall token_type_str(unsigned int *a1)
{
return (&token_type_names)[*a1];
}

canonical_decompiled_code:
char *__fastcall func10(unsigned int *a1)
{
return (&token_type_names)[*a1];
}

original_code:
char *token_type_str(tok_state_t *state)
{
 return token_type_names[state->type];
}

canonical_original_code:
char *token_type_str(struct tok_state_t *state)
{
 return token_type_names[state->type];
}

return_type: char *


decompiled_code:
__int64 __fastcall token_print(__int64 a1, unsigned int *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rax
__int64 v8; // rax
__int64 v9; // [rsp+0h] [rbp-28h] BYREF

v6 = *a2;
if ( (_DWORD)v6 == 4 )
return stream_put(a1, "TOK_SYM(", a2 + 8, ")\n", 0LL, 0LL);
if ( (_DWORD)v6 != 5 )
return stream_put(a1, (&token_type_names)[v6], "\n", 0LL, 0LL, a6);
v8 = fmt_u64(&v9, *((_QWORD *)a2 + 4));
return stream_put(a1, "TOK_LIT(0x", v8, ")\n", 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rax
__int64 v8; // rax
__int64 v9; // [rsp+0h] [rbp-28h] BYREF

v6 = *a2;
if ( (_DWORD)v6 == 4 )
return stream_put(a1, "TOK_SYM(", a2 + 8, ")\n", 0LL, 0LL);
if ( (_DWORD)v6 != 5 )
return stream_put(a1, (&token_type_names)[v6], "\n", 0LL, 0LL, a6);
v8 = fmt_u64(&v9, *((_QWORD *)a2 + 4));
return stream_put(a1, "TOK_LIT(0x", v8, ")\n", 0LL, 0LL);
}

original_code:
void token_print(stream_t *s, tok_state_t *state)
{
 char buf[17];
 switch(state->type) {
 case TOK_SYM:
  _stream_put(s, "TOK_SYM(", state->u.sym, ")\n", ((void *)0), ((void *)0));
  break;
 case TOK_LIT:
  _stream_put(s, "TOK_LIT(0x", fmt_u64(buf, state->u.lit), ")\n", ((void *)0), ((void *)0));
  break;
 default:
  _stream_put(s, token_type_names[state->type], "\n", ((void *)0), ((void *)0));
  break;
 }
}

canonical_original_code:
void token_print(struct stream_t *s, struct tok_state_t *state)
{
 char buf[17];
 switch(state->type) {
 case TOK_SYM:
  _stream_put(s, "TOK_SYM(", state->u.sym, ")\n", ((void *)0), ((void *)0));
  break;
 case TOK_LIT:
  _stream_put(s, "TOK_LIT(0x", fmt_u64(buf, state->u.lit), ")\n", ((void *)0), ((void *)0));
  break;
 default:
  _stream_put(s, token_type_names[state->type], "\n", ((void *)0), ((void *)0));
  break;
 }
}

variable_types: struct stream_t { void *stream_priv; int (*getch_cb)(void *p, char *ch_out); int (*putch_cb)(void *p, char ch_in); int status; } *

variable_types: struct tok_state_t { enum toktype_t { TOK_INIT=0, TOK_LPAREN=1, TOK_RPAREN=2, TOK_DOT=3, TOK_SYM=4, TOK_LIT=5, TOK_END=6 } type; _Bool in_string; long stream_off; union { char sym[-1]; long lit; } u; int nextch; struct stream_t *stream; } *

variable_types:
buf
char [17]


decompiled_code:
__int64 __fastcall make_foreign_b_shra(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_shra);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_shra);
}

original_code: static node_t *make_foreign_b_shra (memory_state_t *ms) { return node_foreign_new(ms, foreign_b_shra); }

canonical_original_code: static struct node *make_foreign_b_shra(struct memory_state *ms) { return node_foreign_new(ms, foreign_b_shra); }

variable_types:
ms
struct memory_state *

return_type: struct node { enum nodetype_t { NODE_UNINITIALIZED=0, NODE_NIL=1, NODE_CONS=2, NODE_LAMBDA=3, NODE_SYMBOL=4, NODE_VALUE=5, NODE_FOREIGN=6, NODE_HANDLE=7, NODE_CONTINUATION=8, NODE_SPECIAL_FUNC=9, NODE_BLOB=10 } type; union { struct { struct node *car; } cons; struct { struct node *env; } lambda; enum eval_err_t { EVAL_OK=0, EVAL_ERR_UNRESOLVED_SYMBOL=1, EVAL_ERR_TOO_MANY_ARGS=2, EVAL_ERR_TOO_FEW_ARGS=3, EVAL_ERR_MISSING_ARG=4, EVAL_ERR_FUNC_IS_NOT_LAMBDA=5, EVAL_ERR_NONLAMBDA_FUNCALL=6, EVAL_ERR_UNKNOWN_FUNCALL=7, EVAL_ERR_EXPECTED_CONS=8, EVAL_ERR_EXPECTED_SYMBOL=9, EVAL_ERR_EXPECTED_VALUE=10, EVAL_ERR_EXPECTED_CONS_SYM=11, EVAL_ERR_VALUE_BOUNDS=12, EVAL_ERR_OUT_OF_MEM=13, EVAL_ERR_FOREIGN_FAILURE=14 } (*func)(struct memory_state { unsigned long total_alloc; unsigned long total_free; unsigned long long iter_count; unsigned long long cycle_count; unsigned int clean_cycles; unsigned long long skipped_clean_iters; struct dlist { struct dlnode { struct dlnode *prev; struct dlist *owner; } hdr; } free_list; struct dlnode root_sentinel; struct dlist roots_list; struct dlist boundary_list; struct dlist free_pending_list; struct dlist white_list; struct dlist *reachable_listref; struct dlist *unproc_listref; void (*i_cb)(void *data); void (*dl_cb)(void (*cb)(void *link, void *p), void *data, void *p); void (*p_cb)(void *data, struct stream_t { void *stream_priv; int (*getch_cb)(void *p, char *ch_out); int (*putch_cb)(void *p, char ch_in); int status; } *stream); struct { _Bool active; } ms_flags; void *(*mem_alloc)(unsigned long len, void *priv); void (*mem_free)(void *mem, void *priv); void *mem_alloc_priv; } *s, struct node *args, struct node *env_hdl, struct node **result); char name[32]; long value; struct { struct node *link; } handle; struct { struct node *bt; } cont; struct { void *addr; void (*fin)(void *addr); unsigned long sig; } blob; enum special_func_t { SPECIAL_IF=0, SPECIAL_LAMBDA=1, SPECIAL_QUOTE=2, SPECIAL_MK_CONT=3, SPECIAL_DEF=4, SPECIAL_SET=5, SPECIAL_DEFINED=6, SPECIAL_EVAL=7 } special; } dat; } *


decompiled_code:
__int64 __fastcall make_foreign_b_shr(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_shr);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_shr);
}

original_code: static node_t *make_foreign_b_shr (memory_state_t *ms) { return node_foreign_new(ms, foreign_b_shr); }

canonical_original_code: static struct node *make_foreign_b_shr(struct memory_state *ms) { return node_foreign_new(ms, foreign_b_shr); }


decompiled_code:
__int64 __fastcall make_foreign_b_shl(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_shl);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_shl);
}

original_code: static node_t *make_foreign_b_shl (memory_state_t *ms) { return node_foreign_new(ms, foreign_b_shl); }

canonical_original_code: static struct node *make_foreign_b_shl(struct memory_state *ms) { return node_foreign_new(ms, foreign_b_shl); }


decompiled_code:
__int64 __fastcall make_foreign_b_xor(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_xor);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_xor);
}

original_code: static node_t *make_foreign_b_xor (memory_state_t *ms) { return node_foreign_new(ms, foreign_b_xor); }

canonical_original_code: static struct node *make_foreign_b_xor(struct memory_state *ms) { return node_foreign_new(ms, foreign_b_xor); }


decompiled_code:
__int64 __fastcall make_foreign_b_nand(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_nand);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_nand);
}

original_code: static node_t *make_foreign_b_nand (memory_state_t *ms) { return node_foreign_new(ms, foreign_b_nand); }

canonical_original_code: static struct node *make_foreign_b_nand(struct memory_state *ms) { return node_foreign_new(ms, foreign_b_nand); }


decompiled_code:
__int64 __fastcall make_foreign_b_or(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_or);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_or);
}

original_code: static node_t *make_foreign_b_or (memory_state_t *ms) { return node_foreign_new(ms, foreign_b_or); }

canonical_original_code: static struct node *make_foreign_b_or(struct memory_state *ms) { return node_foreign_new(ms, foreign_b_or); }


decompiled_code:
__int64 __fastcall make_foreign_b_and(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_and);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return node_foreign_new(a1, &foreign_b_and);
}

original_code: static node_t *make_foreign_b_and (memory_state_t *ms) { return node_foreign_new(ms, foreign_b_and); }

canonical_original_code: static struct node *make_foreign_b_and(struct memory_state *ms) { return node_foreign_new(ms, foreign_b_and); }


decompiled_code:
__int64 __fastcall make_foreign_rem(__int64 a1)
{
return node_foreign_new(a1, &foreign_rem);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return node_foreign_new(a1, &foreign_rem);
}

original_code: static node_t *make_foreign_rem (memory_state_t *ms) { return node_foreign_new(ms, foreign_rem); }

canonical_original_code: static struct node *make_foreign_rem(struct memory_state *ms) { return node_foreign_new(ms, foreign_rem); }


decompiled_code:
__int64 __fastcall make_foreign_div(__int64 a1)
{
return node_foreign_new(a1, &foreign_div);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return node_foreign_new(a1, &foreign_div);
}

original_code: static node_t *make_foreign_div (memory_state_t *ms) { return node_foreign_new(ms, foreign_div); }

canonical_original_code: static struct node *make_foreign_div(struct memory_state *ms) { return node_foreign_new(ms, foreign_div); }


decompiled_code:
__int64 __fastcall make_foreign_mul(__int64 a1)
{
return node_foreign_new(a1, &foreign_mul);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return node_foreign_new(a1, &foreign_mul);
}

original_code: static node_t *make_foreign_mul (memory_state_t *ms) { return node_foreign_new(ms, foreign_mul); }

canonical_original_code: static struct node *make_foreign_mul(struct memory_state *ms) { return node_foreign_new(ms, foreign_mul); }


decompiled_code:
__int64 __fastcall make_foreign_sub(__int64 a1)
{
return node_foreign_new(a1, &foreign_sub);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return node_foreign_new(a1, &foreign_sub);
}

original_code: static node_t *make_foreign_sub (memory_state_t *ms) { return node_foreign_new(ms, foreign_sub); }

canonical_original_code: static struct node *make_foreign_sub(struct memory_state *ms) { return node_foreign_new(ms, foreign_sub); }


decompiled_code:
__int64 __fastcall make_foreign_add(__int64 a1)
{
return node_foreign_new(a1, &foreign_add);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return node_foreign_new(a1, &foreign_add);
}

original_code: static node_t *make_foreign_add (memory_state_t *ms) { return node_foreign_new(ms, foreign_add); }

canonical_original_code: static struct node *make_foreign_add(struct memory_state *ms) { return node_foreign_new(ms, foreign_add); }


decompiled_code:
__int64 __fastcall make_foreign_addc_p(__int64 a1)
{
return node_foreign_new(a1, &foreign_addc_p);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return node_foreign_new(a1, &foreign_addc_p);
}

original_code: static node_t *make_foreign_addc_p (memory_state_t *ms) { return node_foreign_new(ms, foreign_addc_p); }

canonical_original_code: static struct node *make_foreign_addc_p(struct memory_state *ms) { return node_foreign_new(ms, foreign_addc_p); }


decompiled_code:
__int64 __fastcall make_foreign_ugt_p(__int64 a1)
{
return node_foreign_new(a1, &foreign_ugt_p);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return node_foreign_new(a1, &foreign_ugt_p);
}

original_code: static node_t *make_foreign_ugt_p (memory_state_t *ms) { return node_foreign_new(ms, foreign_ugt_p); }

canonical_original_code: static struct node *make_foreign_ugt_p(struct memory_state *ms) { return node_foreign_new(ms, foreign_ugt_p); }


decompiled_code:
__int64 __fastcall make_foreign_ult_p(__int64 a1)
{
return node_foreign_new(a1, &foreign_ult_p);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return node_foreign_new(a1, &foreign_ult_p);
}

original_code: static node_t *make_foreign_ult_p (memory_state_t *ms) { return node_foreign_new(ms, foreign_ult_p); }

canonical_original_code: static struct node *make_foreign_ult_p(struct memory_state *ms) { return node_foreign_new(ms, foreign_ult_p); }


decompiled_code:
__int64 __fastcall make_foreign_gt_p(__int64 a1)
{
return node_foreign_new(a1, &foreign_gt_p);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return node_foreign_new(a1, &foreign_gt_p);
}

original_code: static node_t *make_foreign_gt_p (memory_state_t *ms) { return node_foreign_new(ms, foreign_gt_p); }

canonical_original_code: static struct node *make_foreign_gt_p(struct memory_state *ms) { return node_foreign_new(ms, foreign_gt_p); }


decompiled_code:
__int64 __fastcall make_foreign_lt_p(__int64 a1)
{
return node_foreign_new(a1, &foreign_lt_p);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return node_foreign_new(a1, &foreign_lt_p);
}

original_code: static node_t *make_foreign_lt_p (memory_state_t *ms) { return node_foreign_new(ms, foreign_lt_p); }

canonical_original_code: static struct node *make_foreign_lt_p(struct memory_state *ms) { return node_foreign_new(ms, foreign_lt_p); }


decompiled_code:
__int64 __fastcall make_foreign_eq_p(__int64 a1)
{
return node_foreign_new(a1, &foreign_eq_p);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return node_foreign_new(a1, &foreign_eq_p);
}

original_code: static node_t *make_foreign_eq_p (memory_state_t *ms) { return node_foreign_new(ms, foreign_eq_p); }

canonical_original_code: static struct node *make_foreign_eq_p(struct memory_state *ms) { return node_foreign_new(ms, foreign_eq_p); }


decompiled_code:
__int64 __fastcall make_foreign_smeq_p(__int64 a1)
{
return node_foreign_new(a1, &foreign_smeq_p);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return node_foreign_new(a1, &foreign_smeq_p);
}

original_code: static node_t *make_foreign_smeq_p (memory_state_t *ms) { return node_foreign_new(ms, foreign_smeq_p); }

canonical_original_code: static struct node *make_foreign_smeq_p(struct memory_state *ms) { return node_foreign_new(ms, foreign_smeq_p); }


decompiled_code:
__int64 __fastcall make_foreign_cons(__int64 a1)
{
return node_foreign_new(a1, &foreign_cons);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
return node_foreign_new(a1, &foreign_cons);
}

original_code: static node_t *make_foreign_cons (memory_state_t *ms) { return node_foreign_new(ms, foreign_cons); }

canonical_original_code: static struct node *make_foreign_cons(struct memory_state *ms) { return node_foreign_new(ms, foreign_cons); }


decompiled_code:
__int64 __fastcall make_foreign_splsym(__int64 a1)
{
return node_foreign_new(a1, &foreign_splsym);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
return node_foreign_new(a1, &foreign_splsym);
}

original_code: static node_t *make_foreign_splsym (memory_state_t *ms) { return node_foreign_new(ms, foreign_splsym); }

canonical_original_code: static struct node *make_foreign_splsym(struct memory_state *ms) { return node_foreign_new(ms, foreign_splsym); }


decompiled_code:
__int64 __fastcall make_foreign_mksym(__int64 a1)
{
return node_foreign_new(a1, &foreign_mksym);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
return node_foreign_new(a1, &foreign_mksym);
}

original_code: static node_t *make_foreign_mksym (memory_state_t *ms) { return node_foreign_new(ms, foreign_mksym); }

canonical_original_code: static struct node *make_foreign_mksym(struct memory_state *ms) { return node_foreign_new(ms, foreign_mksym); }


decompiled_code:
__int64 __fastcall make_foreign_cdr(__int64 a1)
{
return node_foreign_new(a1, &foreign_cdr);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
return node_foreign_new(a1, &foreign_cdr);
}

original_code: static node_t *make_foreign_cdr (memory_state_t *ms) { return node_foreign_new(ms, foreign_cdr); }

canonical_original_code: static struct node *make_foreign_cdr(struct memory_state *ms) { return node_foreign_new(ms, foreign_cdr); }


decompiled_code:
__int64 __fastcall make_foreign_car(__int64 a1)
{
return node_foreign_new(a1, &foreign_car);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1)
{
return node_foreign_new(a1, &foreign_car);
}

original_code: static node_t *make_foreign_car (memory_state_t *ms) { return node_foreign_new(ms, foreign_car); }

canonical_original_code: static struct node *make_foreign_car(struct memory_state *ms) { return node_foreign_new(ms, foreign_car); }


decompiled_code:
__int64 __fastcall make_foreign_func_p(__int64 a1)
{
return node_foreign_new(a1, &foreign_func_p);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1)
{
return node_foreign_new(a1, &foreign_func_p);
}

original_code: static node_t *make_foreign_func_p (memory_state_t *ms) { return node_foreign_new(ms, foreign_func_p); }

canonical_original_code: static struct node *make_foreign_func_p(struct memory_state *ms) { return node_foreign_new(ms, foreign_func_p); }


decompiled_code:
__int64 __fastcall make_foreign_cons_p(__int64 a1)
{
return node_foreign_new(a1, &foreign_cons_p);
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1)
{
return node_foreign_new(a1, &foreign_cons_p);
}

original_code: static node_t *make_foreign_cons_p (memory_state_t *ms) { return node_foreign_new(ms, foreign_cons_p); }

canonical_original_code: static struct node *make_foreign_cons_p(struct memory_state *ms) { return node_foreign_new(ms, foreign_cons_p); }


decompiled_code:
__int64 __fastcall make_foreign_sym_p(__int64 a1)
{
return node_foreign_new(a1, &foreign_sym_p);
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1)
{
return node_foreign_new(a1, &foreign_sym_p);
}

original_code: static node_t *make_foreign_sym_p (memory_state_t *ms) { return node_foreign_new(ms, foreign_sym_p); }

canonical_original_code: static struct node *make_foreign_sym_p(struct memory_state *ms) { return node_foreign_new(ms, foreign_sym_p); }


decompiled_code:
__int64 __fastcall make_foreign_val_p(__int64 a1)
{
return node_foreign_new(a1, &foreign_val_p);
}

canonical_decompiled_code:
__int64 __fastcall func27(__int64 a1)
{
return node_foreign_new(a1, &foreign_val_p);
}

original_code: static node_t *make_foreign_val_p (memory_state_t *ms) { return node_foreign_new(ms, foreign_val_p); }

canonical_original_code: static struct node *make_foreign_val_p(struct memory_state *ms) { return node_foreign_new(ms, foreign_val_p); }


decompiled_code:
__int64 __fastcall make_foreign_nil_p(__int64 a1)
{
return node_foreign_new(a1, &foreign_nil_p);
}

canonical_decompiled_code:
__int64 __fastcall func28(__int64 a1)
{
return node_foreign_new(a1, &foreign_nil_p);
}

original_code: static node_t *make_foreign_nil_p (memory_state_t *ms) { return node_foreign_new(ms, foreign_nil_p); }

canonical_original_code: static struct node *make_foreign_nil_p(struct memory_state *ms) { return node_foreign_new(ms, foreign_nil_p); }


decompiled_code:
__int64 __fastcall make_special_EVAL(__int64 a1)
{
return node_special_func_new(a1, 7LL);
}

canonical_decompiled_code:
__int64 __fastcall func29(__int64 a1)
{
return node_special_func_new(a1, 7LL);
}

original_code: static node_t *make_special_EVAL (memory_state_t *ms) { return node_special_func_new(ms, SPECIAL_EVAL); }

canonical_original_code: static struct node *make_special_EVAL(struct memory_state *ms) { return node_special_func_new(ms, SPECIAL_EVAL); }


decompiled_code:
__int64 __fastcall make_special_DEFINED(__int64 a1)
{
return node_special_func_new(a1, 6LL);
}

canonical_decompiled_code:
__int64 __fastcall func30(__int64 a1)
{
return node_special_func_new(a1, 6LL);
}

original_code: static node_t *make_special_DEFINED (memory_state_t *ms) { return node_special_func_new(ms, SPECIAL_DEFINED); }

canonical_original_code: static struct node *make_special_DEFINED(struct memory_state *ms) { return node_special_func_new(ms, SPECIAL_DEFINED); }


decompiled_code:
__int64 __fastcall make_special_SET(__int64 a1)
{
return node_special_func_new(a1, 5LL);
}

canonical_decompiled_code:
__int64 __fastcall func31(__int64 a1)
{
return node_special_func_new(a1, 5LL);
}

original_code: static node_t *make_special_SET (memory_state_t *ms) { return node_special_func_new(ms, SPECIAL_SET); }

canonical_original_code: static struct node *make_special_SET(struct memory_state *ms) { return node_special_func_new(ms, SPECIAL_SET); }


decompiled_code:
__int64 __fastcall make_special_DEF(__int64 a1)
{
return node_special_func_new(a1, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func32(__int64 a1)
{
return node_special_func_new(a1, 4LL);
}

original_code: static node_t *make_special_DEF (memory_state_t *ms) { return node_special_func_new(ms, SPECIAL_DEF); }

canonical_original_code: static struct node *make_special_DEF(struct memory_state *ms) { return node_special_func_new(ms, SPECIAL_DEF); }


decompiled_code:
__int64 __fastcall make_special_MK_CONT(__int64 a1)
{
return node_special_func_new(a1, 3LL);
}

canonical_decompiled_code:
__int64 __fastcall func33(__int64 a1)
{
return node_special_func_new(a1, 3LL);
}

original_code: static node_t *make_special_MK_CONT (memory_state_t *ms) { return node_special_func_new(ms, SPECIAL_MK_CONT); }

canonical_original_code: static struct node *make_special_MK_CONT(struct memory_state *ms) { return node_special_func_new(ms, SPECIAL_MK_CONT); }


decompiled_code:
__int64 __fastcall make_special_LAMBDA(__int64 a1)
{
return node_special_func_new(a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func34(__int64 a1)
{
return node_special_func_new(a1, 1LL);
}

original_code: static node_t *make_special_LAMBDA (memory_state_t *ms) { return node_special_func_new(ms, SPECIAL_LAMBDA); }

canonical_original_code: static struct node *make_special_LAMBDA(struct memory_state *ms) { return node_special_func_new(ms, SPECIAL_LAMBDA); }


decompiled_code:
__int64 __fastcall make_special_IF(__int64 a1)
{
return node_special_func_new(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func35(__int64 a1)
{
return node_special_func_new(a1, 0LL);
}

original_code: static node_t *make_special_IF (memory_state_t *ms) { return node_special_func_new(ms, SPECIAL_IF); }

canonical_original_code: static struct node *make_special_IF(struct memory_state *ms) { return node_special_func_new(ms, SPECIAL_IF); }


decompiled_code:
__int64 __fastcall make_special_QUOTE(__int64 a1)
{
return node_special_func_new(a1, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func36(__int64 a1)
{
return node_special_func_new(a1, 2LL);
}

original_code: static node_t *make_special_QUOTE (memory_state_t *ms) { return node_special_func_new(ms, SPECIAL_QUOTE); }

canonical_original_code: static struct node *make_special_QUOTE(struct memory_state *ms) { return node_special_func_new(ms, SPECIAL_QUOTE); }


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

do
result = memory_gc_iterate(a1);
while ( !(_BYTE)result );
return result;
}

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

do
result = memory_gc_iterate(a1);
while ( !(_BYTE)result );
return result;
}

original_code:
static inline void memory_gc_cycle(memory_state_t *s)
 { while(!memory_gc_iterate(s)); }

canonical_original_code:
static inline void memory_gc_cycle(struct memory_state *s)
 { while(!memory_gc_iterate(s)); }

variable_types: struct memory_state { unsigned long total_alloc; unsigned long total_free; unsigned long long iter_count; unsigned long long cycle_count; unsigned int clean_cycles; unsigned long long skipped_clean_iters; struct dlist { struct dlnode { struct dlnode *prev; struct dlist *owner; } hdr; } free_list; struct dlnode root_sentinel; struct dlist roots_list; struct dlist boundary_list; struct dlist free_pending_list; struct dlist white_list; struct dlist *reachable_listref; struct dlist *unproc_listref; void (*i_cb)(void *data); void (*dl_cb)(void (*cb)(void *link, void *p), void *data, void *p); void (*p_cb)(void *data, struct stream_t { void *stream_priv; int (*getch_cb)(void *p, char *ch_out); int (*putch_cb)(void *p, char ch_in); int status; } *stream); struct { _Bool active; } ms_flags; void *(*mem_alloc)(unsigned long len, void *priv); void (*mem_free)(void *mem, void *priv); void *mem_alloc_priv; } *


decompiled_code:
bool __fastcall dlnode_is_terminal(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == a1;
}

canonical_decompiled_code:
bool __fastcall func0(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == a1;
}

original_code:
static inline _Bool dlnode_is_terminal(dlnode_t *n)
 { return n == &(n->owner->hdr); }

canonical_original_code:
static inline _Bool dlnode_is_terminal(struct dlnode *n)
 { return n == &(n->owner->hdr); }

variable_types: struct dlnode { struct dlnode *prev; struct dlist { struct dlnode hdr; } *owner; } *


decompiled_code:
bool __fastcall dlist_is_empty(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

original_code:
static inline _Bool dlist_is_empty(dlist_t *l)
 { return l->hdr.next == &(l->hdr); }

canonical_original_code:
static inline _Bool dlist_is_empty(struct dlist *l)
 { return l->hdr.next == &(l->hdr); }

variable_types: struct dlist { struct dlnode { struct dlnode *prev; struct dlist *owner; } hdr; } *


decompiled_code:
__int64 __fastcall hdr_to_fmcell(__int64 a1)
{
return a1 - 8;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return a1 - 8;
}

original_code:
static free_mem_cell_t *hdr_to_fmcell(dlnode_t *hdr)
{
 char *base = (char *) hdr - __builtin_offsetof (free_mem_cell_t, u.hdr);
 return (free_mem_cell_t *) base;
}

canonical_original_code:
static struct free_mem_cell_t *hdr_to_fmcell(struct dlnode *hdr)
{
 char *base = (char *) hdr - __builtin_offsetof (free_mem_cell_t, u.hdr);
 return (struct free_mem_cell_t *) base;
}

variable_types:
hdr
struct dlnode *

variable_types:
base
char *

return_type: struct free_mem_cell_t { unsigned long len; union { struct dlnode { struct dlnode *prev; struct dlist { struct dlnode hdr; } *owner; } hdr; int data[]; } u; } *

user_defined_types: struct free_mem_cell_t { unsigned long len; union { struct dlnode hdr; int data[]; } u; }


decompiled_code:
__int64 __fastcall dlist_insertfirst(__int64 a1, __int64 a2)
{
return dlnode_insert(a1, a2, *(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return dlnode_insert(a1, a2, *(_QWORD *)(a1 + 8));
}

original_code:
static inline void dlist_insertfirst(dlist_t *l, dlnode_t *n)
 { dlnode_insert(&(l->hdr), n, l->hdr.next); }

canonical_original_code:
static inline void dlist_insertfirst(struct dlist *l, struct dlnode *n)
 { dlnode_insert(&(l->hdr), n, l->hdr.next); }

variable_types:
n
struct dlnode *


decompiled_code:
bool __fastcall fmcache_state_reset(__int64 a1)
{
__int64 v1; // rax
void *v2; // rax
bool result; // al

while ( 1 )
{
result = dlist_is_empty(a1);
if ( result )
break;
v1 = dlist_first_isra_0(*(_QWORD *)(a1 + 8));
v2 = (void *)dlnode_remove(v1);
free(v2);
}
*(_QWORD *)(a1 + 48) = 0LL;
return result;
}

canonical_decompiled_code:
bool __fastcall func6(__int64 a1)
{
__int64 v1; // rax
void *v2; // rax
bool result; // al

while ( 1 )
{
result = func1(a1);
if ( result )
break;
v1 = func4(*(_QWORD *)(a1 + 8));
v2 = (void *)dlnode_remove(v1);
free(v2);
}
*(_QWORD *)(a1 + 48) = 0LL;
return result;
}

original_code:
void fmcache_state_reset(fmcache_state_t * state)
{
 dlnode_t *n;
 while(! dlist_is_empty(&(state->free_list))) {
  n = dlnode_remove(dlist_first(&(state->free_list)));
  free(n);
 }
 state->alloc_count = 0;
}

canonical_original_code:
void fmcache_state_reset(struct fmcache_state_t *state)
{
 struct dlnode *n;
 while(! dlist_is_empty(&(state->free_list))) {
  n = dlnode_remove(dlist_first(&(state->free_list)));
  free(n);
 }
 state->alloc_count = 0;
}

variable_types: struct fmcache_state_t { struct dlist { struct dlnode { struct dlnode *prev; struct dlist *owner; } hdr; } free_list; void *(*mem_alloc)(unsigned long len, void *priv); void (*mem_free)(void *mem, void *priv); void *alloc_p; unsigned long alloc_count; unsigned long free_count; } *

user_defined_types: struct fmcache_state_t { struct dlist free_list; void *(*mem_alloc)(unsigned long len, void *priv); void (*mem_free)(void *mem, void *priv); void *alloc_p; unsigned long alloc_count; unsigned long free_count; }