decompiled_code:
__int64 __fastcall edid_parse1(unsigned __int8 *a1, _BYTE *a2, int a3, _DWORD *a4, _DWORD *a5, _DWORD *a6)
{
unsigned int v6; // er8
unsigned __int8 *v8; // r12
int v9; // ebp
unsigned __int8 v10; // r13
unsigned __int8 v11; // r13
int v12; // eax
unsigned int v13; // er12
unsigned __int8 v14; // bp
_BYTE *v15; // r14
_BYTE *v16; // r15
__int64 i; // rax
unsigned __int8 *v18; // rax
unsigned int v19; // ebx
int v20; // er13
bool v21; // cf
__int64 v22; // r12
_BYTE *v23; // r14
int v24; // er13
unsigned __int8 *v25; // rax
unsigned int v26; // ebp
unsigned int v27; // er14
unsigned __int8 v28; // dl
unsigned int v29; // er12
__int64 v30; // r12
_BYTE *v31; // r14
__int64 result; // rax
unsigned __int8 v33; // [rsp+10h] [rbp-78h]
__int64 j; // [rsp+10h] [rbp-78h]
unsigned int v35; // [rsp+10h] [rbp-78h]
int v36; // [rsp+18h] [rbp-70h]
unsigned __int8 *v37; // [rsp+18h] [rbp-70h]
unsigned __int8 v38; // [rsp+20h] [rbp-68h]
unsigned __int8 *v39; // [rsp+20h] [rbp-68h]
unsigned __int8 v40; // [rsp+28h] [rbp-60h]
unsigned __int8 *v41; // [rsp+28h] [rbp-60h]
unsigned int v44; // [rsp+44h] [rbp-44h]
_BYTE *v45; // [rsp+48h] [rbp-40h]

v6 = a1[1];
if ( *a1 == 2 )
{
*a6 = (unsigned __int8)v6 > 2u;
v40 = a1[2];
printf("libhdmi:rev:%d offset:%d\r\n", v6, v40);
if ( (a1[3] & 0x40) != 0 )
*a4 = 1;
if ( v40 <= 4u )
{
v44 = a3 - 1;
v45 = a2 + 4;
LABEL_27:
v39 = (unsigned __int8 *)&edid_esttim3_flag_offset;
v16 = &v45[4 * v44];
for ( i = 72LL; ; i = *v39 )
{
v18 = &a1[i];
v41 = v18;
if ( *(_DWORD *)v18 == -150994944 && !v18[4] )
{
for ( j = 6LL; j != 12; ++j )
{
v19 = 7;
v20 = v41[j];
do
{
while ( 1 )
{
if ( _bittest(&v20, v19) )
{
v22 = (unsigned int)get_vesanr_from_est_timing(3u, j, v19);
printf("libhdmi:EstTim3 try vesa_nr:%d\r\n", v22);
if ( a3 > 0 )
break;
}
LABEL_34:
v21 = v19-- == 0;
if ( v21 )
goto LABEL_42;
}
v23 = a2;
while ( 1 )
{
printf("libhdmi:with:%d\r\n", (unsigned __int8)v23[1]);
if ( !*v23 && (unsigned __int8)v23[1] == (_DWORD)v22 )
break;
v23 += 4;
if ( v16 == v23 )
goto LABEL_34;
}
v23[2] = 1;
printf("libhdmi:EstTim3 vesa_nr:%d\r\n", (unsigned int)v22);
v21 = v19-- == 0;
}
while ( !v21 );
LABEL_42:
;
}
}
if ( (unsigned __int8 *)((char *)&edid_esttim3_flag_offset + 3) == ++v39 )
break;
}
v24 = 72;
v37 = (unsigned __int8 *)&edid_stdtim9_flag_offset;
v25 = a1 + 72;
if ( *((_DWORD *)a1 + 18) == -100663296 )
goto LABEL_47;
LABEL_45:
while ( (unsigned __int8 *)((char *)&edid_stdtim9_flag_offset + 3) != ++v37 )
{
v24 = *v37;
v25 = &a1[(unsigned __int8)v24];
if ( *(_DWORD *)v25 == -100663296 )
{
LABEL_47:
v26 = 0;
if ( !v25[4] )
{
do
{
while ( 1 )
{
v24 += 2 * v26++ + 5;
v27 = 8 * a1[(unsigned __int8)v24] + 248;
v28 = a1[(unsigned __int8)v24 + 1];
v35 = (v28 & 0x3F) + 60;
v29 = (int)(v27 * edid_stdtim_ar[2 * (v28 >> 6) + 1]) / edid_stdtim_ar[2 * (v28 >> 6)];
printf("libhdmi:xres:%d yres:%d freq:%d\r\n", v27, v29, v35);
v30 = (unsigned int)get_vesanr_from_std_timing(v27, v29, v35);
printf("libhdmi:StdTim9to16 try vesa_nr:%d\r\n", v30);
v31 = a2;
if ( a3 > 0 )
break;
LABEL_52:
if ( v26 == 6 )
goto LABEL_45;
}
while ( 1 )
{
printf("libhdmi:with:%d\r\n", (unsigned __int8)v31[1]);
if ( !*v31 && (unsigned __int8)v31[1] == (_DWORD)v30 )
break;
v31 += 4;
if ( v16 == v31 )
goto LABEL_52;
}
v31[2] = 1;
printf("libhdmi:StdTim9to16 %d vesa_nr:%d\r\n", v26, (unsigned int)v30);
}
while ( v26 != 6 );
}
}
}
result = 0LL;
}
else
{
v33 = 4;
v44 = a3 - 1;
v45 = a2 + 4;
while ( 1 )
{
v8 = &a1[v33];
v9 = *v8 & 0x1F;
v10 = *v8 >> 5;
v38 = *v8 & 0x1F;
if ( v9 + v40 > 127 )
break;
printf("libhdmi:code:%d blklen:%d\r\n", v10, *v8 & 0x1F);
if ( v10 == 2 )
{
v11 = v33 + 1;
v12 = (unsigned __int8)(v33 + 1);
v36 = v12 + v9;
if ( v12 < v12 + v9 )
{
do
{
v13 = a1[v11] & 0x7F;
v14 = a1[v11] & 0x7F;
printf("libhdmi:try ceanr:%d\r\n", v14);
v15 = a2;
if ( a3 > 0 )
{
while ( 1 )
{
printf("libhdmi:with:%d\r\n", (unsigned __int8)v15[1]);
if ( *v15 == 1 && v15[1] == v14 )
break;
v15 += 4;
if ( &a2[4 * (a3 - 1) + 4] == v15 )
goto LABEL_18;
}
v15[2] = 1;
printf("libhdmi:cea:%d\r\n", v13);
}
LABEL_18:
++v11;
}
while ( v11 < v36 );
}
}
else if ( v10 == 3 && v38 > 4u )
{
printf("libhdmi:source physaddr:%02x%02x\r\n", v8[4], v8[5]);
if ( v38 > 9u )
{
if ( (v8[8] & 0x80u) != 0 )
{
*a5 = 2 * v8[9] - 2;
a5[1] = 2 * v8[10] - 2;
}
if ( v38 > 0xBu && (v8[8] & 0x40) != 0 )
{
a5[2] = 2 * v8[11] - 2;
a5[1] = 2 * v8[12] - 2;
}
}
}
v33 += v38 + 1;
if ( v40 <= v33 )
goto LABEL_27;
}
result = 4294967293LL;
}
}
else
{
printf("libhdmi:edid bl1 tag:%02x or rev:%02x\r\n", *a1, a1[1]);
result = 4294967290LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1, _BYTE *a2, int a3, _DWORD *a4, _DWORD *a5, _DWORD *a6)
{
unsigned int v6; // er8
unsigned __int8 *v8; // r12
int v9; // ebp
unsigned __int8 v10; // r13
unsigned __int8 v11; // r13
int v12; // eax
unsigned int v13; // er12
unsigned __int8 v14; // bp
_BYTE *v15; // r14
_BYTE *v16; // r15
__int64 i; // rax
unsigned __int8 *v18; // rax
unsigned int v19; // ebx
int v20; // er13
bool v21; // cf
__int64 v22; // r12
_BYTE *v23; // r14
int v24; // er13
unsigned __int8 *v25; // rax
unsigned int v26; // ebp
unsigned int v27; // er14
unsigned __int8 v28; // dl
unsigned int v29; // er12
__int64 v30; // r12
_BYTE *v31; // r14
__int64 result; // rax
unsigned __int8 v33; // [rsp+10h] [rbp-78h]
__int64 j; // [rsp+10h] [rbp-78h]
unsigned int v35; // [rsp+10h] [rbp-78h]
int v36; // [rsp+18h] [rbp-70h]
unsigned __int8 *v37; // [rsp+18h] [rbp-70h]
unsigned __int8 v38; // [rsp+20h] [rbp-68h]
unsigned __int8 *v39; // [rsp+20h] [rbp-68h]
unsigned __int8 v40; // [rsp+28h] [rbp-60h]
unsigned __int8 *v41; // [rsp+28h] [rbp-60h]
unsigned int v44; // [rsp+44h] [rbp-44h]
_BYTE *v45; // [rsp+48h] [rbp-40h]

v6 = a1[1];
if ( *a1 == 2 )
{
*a6 = (unsigned __int8)v6 > 2u;
v40 = a1[2];
printf("libhdmi:rev:%d offset:%d\r\n", v6, v40);
if ( (a1[3] & 0x40) != 0 )
*a4 = 1;
if ( v40 <= 4u )
{
v44 = a3 - 1;
v45 = a2 + 4;
LABEL_27:
v39 = (unsigned __int8 *)&edid_esttim3_flag_offset;
v16 = &v45[4 * v44];
for ( i = 72LL; ; i = *v39 )
{
v18 = &a1[i];
v41 = v18;
if ( *(_DWORD *)v18 == -150994944 && !v18[4] )
{
for ( j = 6LL; j != 12; ++j )
{
v19 = 7;
v20 = v41[j];
do
{
while ( 1 )
{
if ( _bittest(&v20, v19) )
{
v22 = (unsigned int)func0(3u, j, v19);
printf("libhdmi:EstTim3 try vesa_nr:%d\r\n", v22);
if ( a3 > 0 )
break;
}
LABEL_34:
v21 = v19-- == 0;
if ( v21 )
goto LABEL_42;
}
v23 = a2;
while ( 1 )
{
printf("libhdmi:with:%d\r\n", (unsigned __int8)v23[1]);
if ( !*v23 && (unsigned __int8)v23[1] == (_DWORD)v22 )
break;
v23 += 4;
if ( v16 == v23 )
goto LABEL_34;
}
v23[2] = 1;
printf("libhdmi:EstTim3 vesa_nr:%d\r\n", (unsigned int)v22);
v21 = v19-- == 0;
}
while ( !v21 );
LABEL_42:
;
}
}
if ( (unsigned __int8 *)((char *)&edid_esttim3_flag_offset + 3) == ++v39 )
break;
}
v24 = 72;
v37 = (unsigned __int8 *)&edid_stdtim9_flag_offset;
v25 = a1 + 72;
if ( *((_DWORD *)a1 + 18) == -100663296 )
goto LABEL_47;
LABEL_45:
while ( (unsigned __int8 *)((char *)&edid_stdtim9_flag_offset + 3) != ++v37 )
{
v24 = *v37;
v25 = &a1[(unsigned __int8)v24];
if ( *(_DWORD *)v25 == -100663296 )
{
LABEL_47:
v26 = 0;
if ( !v25[4] )
{
do
{
while ( 1 )
{
v24 += 2 * v26++ + 5;
v27 = 8 * a1[(unsigned __int8)v24] + 248;
v28 = a1[(unsigned __int8)v24 + 1];
v35 = (v28 & 0x3F) + 60;
v29 = (int)(v27 * edid_stdtim_ar[2 * (v28 >> 6) + 1]) / edid_stdtim_ar[2 * (v28 >> 6)];
printf("libhdmi:xres:%d yres:%d freq:%d\r\n", v27, v29, v35);
v30 = (unsigned int)func1(v27, v29, v35);
printf("libhdmi:StdTim9to16 try vesa_nr:%d\r\n", v30);
v31 = a2;
if ( a3 > 0 )
break;
LABEL_52:
if ( v26 == 6 )
goto LABEL_45;
}
while ( 1 )
{
printf("libhdmi:with:%d\r\n", (unsigned __int8)v31[1]);
if ( !*v31 && (unsigned __int8)v31[1] == (_DWORD)v30 )
break;
v31 += 4;
if ( v16 == v31 )
goto LABEL_52;
}
v31[2] = 1;
printf("libhdmi:StdTim9to16 %d vesa_nr:%d\r\n", v26, (unsigned int)v30);
}
while ( v26 != 6 );
}
}
}
result = 0LL;
}
else
{
v33 = 4;
v44 = a3 - 1;
v45 = a2 + 4;
while ( 1 )
{
v8 = &a1[v33];
v9 = *v8 & 0x1F;
v10 = *v8 >> 5;
v38 = *v8 & 0x1F;
if ( v9 + v40 > 127 )
break;
printf("libhdmi:code:%d blklen:%d\r\n", v10, *v8 & 0x1F);
if ( v10 == 2 )
{
v11 = v33 + 1;
v12 = (unsigned __int8)(v33 + 1);
v36 = v12 + v9;
if ( v12 < v12 + v9 )
{
do
{
v13 = a1[v11] & 0x7F;
v14 = a1[v11] & 0x7F;
printf("libhdmi:try ceanr:%d\r\n", v14);
v15 = a2;
if ( a3 > 0 )
{
while ( 1 )
{
printf("libhdmi:with:%d\r\n", (unsigned __int8)v15[1]);
if ( *v15 == 1 && v15[1] == v14 )
break;
v15 += 4;
if ( &a2[4 * (a3 - 1) + 4] == v15 )
goto LABEL_18;
}
v15[2] = 1;
printf("libhdmi:cea:%d\r\n", v13);
}
LABEL_18:
++v11;
}
while ( v11 < v36 );
}
}
else if ( v10 == 3 && v38 > 4u )
{
printf("libhdmi:source physaddr:%02x%02x\r\n", v8[4], v8[5]);
if ( v38 > 9u )
{
if ( (v8[8] & 0x80u) != 0 )
{
*a5 = 2 * v8[9] - 2;
a5[1] = 2 * v8[10] - 2;
}
if ( v38 > 0xBu && (v8[8] & 0x40) != 0 )
{
a5[2] = 2 * v8[11] - 2;
a5[1] = 2 * v8[12] - 2;
}
}
}
v33 += v38 + 1;
if ( v40 <= v33 )
goto LABEL_27;
}
result = 4294967293LL;
}
}
else
{
printf("libhdmi:edid bl1 tag:%02x or rev:%02x\r\n", *a1, a1[1]);
result = 4294967290LL;
}
return result;
}

original_code:
int edid_parse1(__u8 *data, struct video_format formats[], int nr_formats,
  int *basic_audio_support, struct edid_latency *edid_latency,
  int *hdmi)
{
 __u8 tag;
 __u8 rev;
 __u8 offset;
 __u8 blockp;
 __u8 code;
 __u8 length = 0;
 __u8 ceanr;
 int index;
 int index2;
 int cnt;
 __u8 est_timing3;
 int byte;
 int bit;
 int vesa_nr;
 int xres;
 int yres;
 int ar_index;
 int freq;
 __u8 edidp;
 __u8 *p;
 tag = *(data + 0x00);
 rev = *(data + 0x01);
 if (tag != 0x02) {
  printf("libhdmi:" "edid bl1 tag:%02x or rev:%02x""\r\n", tag, rev);
  return -6;
 }
 if (rev >= 0x03)
  *hdmi = 1;
 else
  *hdmi = 0;
 offset = *(data + 0x02);
 printf("libhdmi:" "rev:%d offset:%d""\r\n", rev, offset);
 if (*(data + 0x03) &
   0x40) {
  *basic_audio_support = 1;
 }
 for (edidp = 0x04; edidp < offset;
    edidp = edidp + length + 1) {
  code = (*(data + edidp) & 0xE0) >>
      5;
  length = *(data + edidp) & 0x1F;
  if ((offset + length) >= 0x80)
   return -3;
  printf("libhdmi:" "code:%d blklen:%d""\r\n", code, length);
  switch (code) {
  case 0x02:
   for (blockp = edidp + 1; blockp < edidp + 1 + length;
       blockp++) {
    ceanr = *(data + blockp) & 0x7F;
    printf("libhdmi:" "try ceanr:%d""\r\n", ceanr);
    for (cnt = 0; cnt < nr_formats; cnt++) {
     printf("libhdmi:" "with:%d""\r\n", formats[cnt].vesaceanr);
     if ((formats[cnt].cea == 1) &&
      (formats[cnt].vesaceanr ==
        ceanr)) {
      formats[cnt].sink_support = 1;
      printf("libhdmi:" "cea:%d""\r\n", ceanr);
      break;
     }
    }
   }
   break;
  case 0x03:
   p = data + edidp;
   if (length >= (4 + 1)) {
    printf("libhdmi:" "source physaddr:%02x%02x""\r\n", *(p + 4), *(p + 4 + 1));
   }
   if ((length >= 10) &&
    (*(p + 8) &
     0x80)) {
    edid_latency->video_latency =
    2 * (*(p + 9) - 1);
    edid_latency->audio_latency =
    2 * (*(p + 10) - 1);
   }
   if ((length >= 12) &&
    (*(p + 8) &
     0x40)) {
    edid_latency->intlcd_video_latency =
    2 * (*(p + 11) - 1);
    edid_latency->audio_latency =
    2 * (*(p + 12) - 1);
   }
   break;
  default:
   break;
  }
 }
 for (index = 0; index <= 2; index++) {
  edidp = edid_esttim3_flag_offset[index];
  if (memcmp(data + edidp, edid_esttim3_flag,
    sizeof(edid_esttim3_flag)) != 0)
   continue;
  for (byte = 6;
    byte <= 11; byte++) {
   est_timing3 = *(data + edidp + byte);
   for (bit = 7; bit >= 0; bit--) {
    if ((est_timing3 & (1 << bit)) == 0)
     continue;
    vesa_nr = get_vesanr_from_est_timing(3, byte,
         bit);
    printf("libhdmi:" "EstTim3 try vesa_nr:%d""\r\n", vesa_nr);
    for (cnt = 0; cnt < nr_formats; cnt++) {
     printf("libhdmi:" "with:%d""\r\n", formats[cnt].vesaceanr);
     if ((formats[cnt].cea == 0) &&
      (formats[cnt].vesaceanr ==
        vesa_nr)) {
      formats[cnt].sink_support = 1;
      printf("libhdmi:" "EstTim3 vesa_nr:%d""\r\n", vesa_nr);
      break;
     }
    }
   }
  }
 }
 for (index2 = 0; index2 <= 2; index2++) {
  edidp = edid_stdtim9_flag_offset[index2];
  if (memcmp(data + edidp, edid_stdtim9_flag,
    sizeof(edid_stdtim9_flag)) != 0)
   continue;
  for (index = 0; index < 6; index++) {
   edidp += 5 + index * 2;
   xres = (*(data + edidp) + 31) * 8;
   byte = *(data + edidp + 1);
   ar_index = (byte & 0xC0) >>
      6;
   yres = xres * edid_stdtim_ar[ar_index].y /
      edid_stdtim_ar[ar_index].x;
   freq = 60 + ((byte & 0x3F) >>
      0);
   printf("libhdmi:" "xres:%d yres:%d freq:%d""\r\n", xres, yres, freq);
   vesa_nr = get_vesanr_from_std_timing(xres, yres, freq);
   printf("libhdmi:" "StdTim9to16 try vesa_nr:%d""\r\n", vesa_nr);
   for (cnt = 0; cnt < nr_formats; cnt++) {
    printf("libhdmi:" "with:%d""\r\n", formats[cnt].vesaceanr);
    if ((formats[cnt].cea == 0) &&
      (formats[cnt].vesaceanr ==
        vesa_nr)) {
     formats[cnt].sink_support = 1;
     printf("libhdmi:" "StdTim9to16 %d vesa_nr:%d""\r\n", index + 1, vesa_nr);
     break;
    }
   }
  }
 }
 return 0;
}

canonical_original_code:
int edid_parse1(unsigned char *data, struct video_format formats[], int nr_formats, int *basic_audio_support, struct edid_latency *edid_latency, int *hdmi)
{
 unsigned char tag;
 unsigned char rev;
 unsigned char offset;
 unsigned char blockp;
 unsigned char code;
 unsigned char length = 0;
 unsigned char ceanr;
 int index;
 int index2;
 int cnt;
 unsigned char est_timing3;
 int byte;
 int bit;
 int vesa_nr;
 int xres;
 int yres;
 int ar_index;
 int freq;
 unsigned char edidp;
 unsigned char *p;
 tag = *(data + 0x00);
 rev = *(data + 0x01);
 if (tag != 0x02) {
  printf("libhdmi:" "edid bl1 tag:%02x or rev:%02x""\r\n", tag, rev);
  return -6;
 }
 if (rev >= 0x03)
  *hdmi = 1;
 else
  *hdmi = 0;
 offset = *(data + 0x02);
 printf("libhdmi:" "rev:%d offset:%d""\r\n", rev, offset);
 if (*(data + 0x03) &
   0x40) {
  *basic_audio_support = 1;
 }
 for (edidp = 0x04; edidp < offset;
    edidp = edidp + length + 1) {
  code = (*(data + edidp) & 0xE0) >>
      5;
  length = *(data + edidp) & 0x1F;
  if ((offset + length) >= 0x80)
   return -3;
  printf("libhdmi:" "code:%d blklen:%d""\r\n", code, length);
  switch (code) {
  case 0x02:
   for (blockp = edidp + 1; blockp < edidp + 1 + length;
       blockp++) {
    ceanr = *(data + blockp) & 0x7F;
    printf("libhdmi:" "try ceanr:%d""\r\n", ceanr);
    for (cnt = 0; cnt < nr_formats; cnt++) {
     printf("libhdmi:" "with:%d""\r\n", formats[cnt].vesaceanr);
     if ((formats[cnt].cea == 1) &&
      (formats[cnt].vesaceanr ==
        ceanr)) {
      formats[cnt].sink_support = 1;
      printf("libhdmi:" "cea:%d""\r\n", ceanr);
      break;
     }
    }
   }
   break;
  case 0x03:
   p = data + edidp;
   if (length >= (4 + 1)) {
    printf("libhdmi:" "source physaddr:%02x%02x""\r\n", *(p + 4), *(p + 4 + 1));
   }
   if ((length >= 10) &&
    (*(p + 8) &
     0x80)) {
    edid_latency->video_latency =
    2 * (*(p + 9) - 1);
    edid_latency->audio_latency =
    2 * (*(p + 10) - 1);
   }
   if ((length >= 12) &&
    (*(p + 8) &
     0x40)) {
    edid_latency->intlcd_video_latency =
    2 * (*(p + 11) - 1);
    edid_latency->audio_latency =
    2 * (*(p + 12) - 1);
   }
   break;
  default:
   break;
  }
 }
 for (index = 0; index <= 2; index++) {
  edidp = edid_esttim3_flag_offset[index];
  if (memcmp(data + edidp, edid_esttim3_flag,
    sizeof(edid_esttim3_flag)) != 0)
   continue;
  for (byte = 6;
    byte <= 11; byte++) {
   est_timing3 = *(data + edidp + byte);
   for (bit = 7; bit >= 0; bit--) {
    if ((est_timing3 & (1 << bit)) == 0)
     continue;
    vesa_nr = get_vesanr_from_est_timing(3, byte,
         bit);
    printf("libhdmi:" "EstTim3 try vesa_nr:%d""\r\n", vesa_nr);
    for (cnt = 0; cnt < nr_formats; cnt++) {
     printf("libhdmi:" "with:%d""\r\n", formats[cnt].vesaceanr);
     if ((formats[cnt].cea == 0) &&
      (formats[cnt].vesaceanr ==
        vesa_nr)) {
      formats[cnt].sink_support = 1;
      printf("libhdmi:" "EstTim3 vesa_nr:%d""\r\n", vesa_nr);
      break;
     }
    }
   }
  }
 }
 for (index2 = 0; index2 <= 2; index2++) {
  edidp = edid_stdtim9_flag_offset[index2];
  if (memcmp(data + edidp, edid_stdtim9_flag,
    sizeof(edid_stdtim9_flag)) != 0)
   continue;
  for (index = 0; index < 6; index++) {
   edidp += 5 + index * 2;
   xres = (*(data + edidp) + 31) * 8;
   byte = *(data + edidp + 1);
   ar_index = (byte & 0xC0) >>
      6;
   yres = xres * edid_stdtim_ar[ar_index].y /
      edid_stdtim_ar[ar_index].x;
   freq = 60 + ((byte & 0x3F) >>
      0);
   printf("libhdmi:" "xres:%d yres:%d freq:%d""\r\n", xres, yres, freq);
   vesa_nr = get_vesanr_from_std_timing(xres, yres, freq);
   printf("libhdmi:" "StdTim9to16 try vesa_nr:%d""\r\n", vesa_nr);
   for (cnt = 0; cnt < nr_formats; cnt++) {
    printf("libhdmi:" "with:%d""\r\n", formats[cnt].vesaceanr);
    if ((formats[cnt].cea == 0) &&
      (formats[cnt].vesaceanr ==
        vesa_nr)) {
     formats[cnt].sink_support = 1;
     printf("libhdmi:" "StdTim9to16 %d vesa_nr:%d""\r\n", index + 1, vesa_nr);
     break;
    }
   }
  }
 }
 return 0;
}

variable_types: struct edid_latency { int video_latency; int audio_latency; int intlcd_video_latency; int intlcd_audio_latency; } *

variable_types:
hdmi
int *

variable_types:
tag
unsigned char

variable_types:
rev
unsigned char

variable_types:
offset
unsigned char

variable_types:
blockp
unsigned char

variable_types:
code
unsigned char

variable_types:
length
unsigned char

variable_types:
ceanr
unsigned char

variable_types: byte int

variable_types:
p
unsigned char *

user_defined_types: struct video_format { unsigned char cea; unsigned char vesaceanr; unsigned char sink_support; unsigned char prio; }


edidreq

repo: igloocommunity/hdmiservice

original_code:
int edidreq(__u8 block, __u32 cmd_id)
{
 int res = 0;
 int ret = 0;
 int edidsize = 0;
 int val;
 __u8 buf[512];
 __u8 ediddata[0x80];
 printf("libhdmi:" "%s begin""\r\n", __func__);
 res = edid_read(block, ediddata);
 if (res == 0)
  edidsize = 0x80;
 val = 0x12;
 memcpy(&buf[0], &val, 4);
 memcpy(&buf[4], &cmd_id, 4);
 val = edidsize + 1;
 memcpy(&buf[8], &val, 4);
 buf[12] = res;
 memcpy(&buf[12 + 1], ediddata, edidsize);
 ret = clientsocket_send(buf, 12 + val);
 printf("libhdmi:" "%s end""\r\n", __func__);
 return ret;
}

canonical_original_code:
int edidreq(unsigned char block, unsigned int cmd_id)
{
 int res = 0;
 int ret = 0;
 int edidsize = 0;
 int val;
 unsigned char buf[512];
 unsigned char ediddata[128];
 printf("libhdmi:" "%s begin""\r\n", __func__);
 res = edid_read(block, ediddata);
 if (res == 0)
  edidsize = 0x80;
 val = 0x12;
 memcpy(&buf[0], &val, 4);
 memcpy(&buf[4], &cmd_id, 4);
 val = edidsize + 1;
 memcpy(&buf[8], &val, 4);
 buf[12] = res;
 memcpy(&buf[12 + 1], ediddata, edidsize);
 ret = clientsocket_send(buf, 12 + val);
 printf("libhdmi:" "%s end""\r\n", __func__);
 return ret;
}

variable_types:
block
unsigned char

variable_types: res int

variable_types: ret int

variable_types: edidsize int

variable_types: val int

variable_types:
buf
unsigned char [512]

variable_types:
ediddata
unsigned char [128]

return_type: int


repo: ignar/c-algorithms

decompiled_code:
__int64 __fastcall cmp_x(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a1 + 1) - *((_DWORD *)a2 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a1 + 1) - *((_DWORD *)a2 + 1));
}

original_code:
int cmp_x(const void *a1, const void *a2)
{
    Point *p1 = (Point*)a1;
    Point *p2 = (Point*)a2;
    return p1->x - p2->x;
}

canonical_original_code:
int cmp_x(void *a1, void *a2)
{
    struct Point *p1 = (Point*)a1;
    struct Point *p2 = (Point*)a2;
    return p1->x - p2->x;
}

variable_types: struct Point { int id; int x; int y; int sx; int sy; } *


decompiled_code:
__int64 __fastcall cmp_y(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a1 + 2) - *((_DWORD *)a2 + 2));
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a1 + 2) - *((_DWORD *)a2 + 2));
}

original_code:
int cmp_y(const void *a1, const void *a2)
{
    Point *p1 = (Point*)a1;
    Point *p2 = (Point*)a2;
    return p1->y - p2->y;
}

canonical_original_code:
int cmp_y(void *a1, void *a2)
{
    struct Point *p1 = (Point*)a1;
    struct Point *p2 = (Point*)a2;
    return p1->y - p2->y;
}

user_defined_types: struct Point { int id; int x; int y; int sx; int sy; }


decompiled_code:
int __fastcall plot_points(_DWORD *a1, __int64 a2, int a3, int a4)
{
__int64 v6; // rbp

v6 = 0LL;
init_pair(1, 2, 0);
init_pair(2, 1, 0);
wattr_on(stdscr, 0x100uLL, 0LL);
if ( a2 )
{
do
{
while ( *a1 != a4 && *a1 != a3 )
{
if ( wmove(stdscr, a1[4], a1[3]) != -1 )
waddch(stdscr, LODWORD(acs_map[63]));
++v6;
a1 += 5;
if ( a2 == v6 )
return wattr_off(stdscr, 0x100uLL, 0LL);
}
wattr_off(stdscr, 0x100uLL, 0LL);
wattr_on(stdscr, 0x200uLL, 0LL);
if ( wmove(stdscr, a1[4], a1[3]) != -1 )
waddch(stdscr, LODWORD(acs_map[48]));
++v6;
a1 += 5;
wattr_off(stdscr, 0x200uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
while ( a2 != v6 );
}
return wattr_off(stdscr, 0x100uLL, 0LL);
}

canonical_decompiled_code:
int __fastcall func2(_DWORD *a1, __int64 a2, int a3, int a4)
{
__int64 v6; // rbp

v6 = 0LL;
init_pair(1, 2, 0);
init_pair(2, 1, 0);
wattr_on(stdscr, 0x100uLL, 0LL);
if ( a2 )
{
do
{
while ( *a1 != a4 && *a1 != a3 )
{
if ( wmove(stdscr, a1[4], a1[3]) != -1 )
waddch(stdscr, LODWORD(acs_map[63]));
++v6;
a1 += 5;
if ( a2 == v6 )
return wattr_off(stdscr, 0x100uLL, 0LL);
}
wattr_off(stdscr, 0x100uLL, 0LL);
wattr_on(stdscr, 0x200uLL, 0LL);
if ( wmove(stdscr, a1[4], a1[3]) != -1 )
waddch(stdscr, LODWORD(acs_map[48]));
++v6;
a1 += 5;
wattr_off(stdscr, 0x200uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
while ( a2 != v6 );
}
return wattr_off(stdscr, 0x100uLL, 0LL);
}

variable_types: struct Point { int id; int x; int y; int sx; int sy; } []

variable_types:
len
unsigned long

variable_types:
i
unsigned long

return_type: void


decompiled_code:
int __fastcall print_points(unsigned int *a1, __int64 a2)
{
__int64 i; // rbp
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // rsi
__int64 v8; // rdx

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v5 = a1[1];
v6 = a1[2];
v7 = i;
v8 = *a1;
a1 += 5;
printf("i:%ld Point<id:%d; x:%d; y:%d>\n", v7, v8, v5, v6);
}
}
return putchar(10);
}

original_code:
void print_points(Point points[], size_t len)
{
    for(size_t i = 0; i < len; i++) {
        printf("i:%ld Point<id:%d; x:%d; y:%d>\n", i, points[i].id, points[i].x, points[i].y);
    }
    printf("\n");
    return;
}

canonical_original_code:
void print_points(struct Point points[], unsigned long len)
{
    for(unsigned long i = 0; i < len; i++) {
        printf("i:%ld Point<id:%d; x:%d; y:%d>\n", i, points[i].id, points[i].x, points[i].y);
    }
    printf("\n");
    return;
}


decompiled_code:
void __fastcall sort_points_x(void *a1, size_t a2)
{
qsort(a1, a2, 0x14uLL, (__compar_fn_t)cmp_x);
}

canonical_decompiled_code:
void __fastcall func4(void *a1, size_t a2)
{
qsort(a1, a2, 0x14uLL, (__compar_fn_t)cmp_x);
}

original_code:
void sort_points_x(Point points[], size_t len)
{
    qsort(points, len, sizeof(Point), cmp_x);
}

canonical_original_code:
void sort_points_x(struct Point points[], unsigned long len)
{
    qsort(points, len, sizeof(Point), cmp_x);
}


decompiled_code:
void __fastcall sort_points_y(void *a1, size_t a2)
{
qsort(a1, a2, 0x14uLL, (__compar_fn_t)cmp_y);
}

canonical_decompiled_code:
void __fastcall func5(void *a1, size_t a2)
{
qsort(a1, a2, 0x14uLL, (__compar_fn_t)cmp_y);
}

original_code:
void sort_points_y(Point points[], size_t len)
{
    qsort(points, len, sizeof(Point), cmp_y);
}

canonical_original_code:
void sort_points_y(struct Point points[], unsigned long len)
{
    qsort(points, len, sizeof(Point), cmp_y);
}


dist

original_code:
double dist(Point p1, Point p2)
{
    double dist = sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) + .0);
    return dist;
}

canonical_original_code:
double dist(struct Point p1, struct Point p2)
{
    double dist = sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) + .0);
    return dist;
}

variable_types: struct Point { int id; int x; int y; int sx; int sy; }

variable_types: dist double

return_type: double


original_code:
void scale_points(Point points[], size_t len)
{
    struct winsize w;
    ioctl(1, 0x5413, &w);
    int max_y = 0,
        max_x = 0,
        mx_p,
        mx_t;
    for(size_t i = 0; i < len; i++) {
        max_y = (((max_y) > (points[i].y)) ? (max_y) : (points[i].y));
        max_x = (((max_x) > (points[i].x)) ? (max_x) : (points[i].x));
    }
    mx_p = (((max_y) > (max_x)) ? (max_y) : (max_x));
    mx_t = (((w.ws_col) < (w.ws_row)) ? (w.ws_col) : (w.ws_row));
    do { if (0) fprintf(stderr, "Terminal max res is set to %d, max point coord is %d\n", mx_t, mx_p); } while (0);
    if(mx_p > mx_t) {
        float k = (float)mx_t / (float)mx_p;
        do { if (0) fprintf(stderr, "Points coordinates needs to be scaled with k:%f\n", k); } while (0);
        for(size_t i = 0; i < len; i++) {
            points[i].sx = round((float)points[i].x * k);
            points[i].sy = round((float)points[i].y * k);
            do { if (0) fprintf(stderr, "Scaling (%d:%d) => (%d:%d)\n", points[i].x, points[i].y, points[i].sx, points[i].sy); } while (0);
        }
    }
    for(size_t i = 0; i < len; i++)
        points[i].sy = w.ws_row - points[i].sy;
    return;
}

canonical_original_code:
void scale_points(struct Point points[], unsigned long len)
{
    struct winsize w;
    ioctl(1, 0x5413, &w);
    int max_y = 0; int max_x = 0; int mx_p; int mx_t;
    for(unsigned long i = 0; i < len; i++) {
        max_y = (((max_y) > (points[i].y)) ? (max_y) : (points[i].y));
        max_x = (((max_x) > (points[i].x)) ? (max_x) : (points[i].x));
    }
    mx_p = (((max_y) > (max_x)) ? (max_y) : (max_x));
    mx_t = (((w.ws_col) < (w.ws_row)) ? (w.ws_col) : (w.ws_row));
    do { if (0) fprintf(stderr, "Terminal max res is set to %d, max point coord is %d\n", mx_t, mx_p); } while (0);
    if(mx_p > mx_t) {
        float k = (float)mx_t / (float)mx_p;
        do { if (0) fprintf(stderr, "Points coordinates needs to be scaled with k:%f\n", k); } while (0);
        for(unsigned long i = 0; i < len; i++) {
            points[i].sx = round((float)points[i].x * k);
            points[i].sy = round((float)points[i].y * k);
            do { if (0) fprintf(stderr, "Scaling (%d:%d) => (%d:%d)\n", points[i].x, points[i].y, points[i].sx, points[i].sy); } while (0);
        }
    }
    for(unsigned long i = 0; i < len; i++)
        points[i].sy = w.ws_row - points[i].sy;
    return;
}

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }

variable_types: k float


original_code:
Line * find_cls_pair(struct Point points[], int left, int right)
{
    do { if (0) fprintf(stderr, "Receive left:%d and right:%d\n", left, right); } while (0);
    Line * sht = malloc(sizeof(Line));
    if(left+1 == right) {
        sht->dist = dist(points[left], points[left+1]);
        sht->fid = points[left].id;
        sht->sid = points[left+1].id;
        do { if (0) fprintf(stderr, "Only two points and line is Line<dist:%f; fid:%d; sid:%d>\n\n", sht->dist, sht->fid, sht->sid); } while (0);
        return sht;
    }
    if((right - left) < 3) {
        double d1 = dist(points[left], points[left+1]);
        double d2 = dist(points[left+1], points[right]);
        do { if (0) fprintf(stderr, "Comparing Point<id:%d; x:%d; y:%d> and Point<id:%d; x:%d; y:%d> and Point<id:%d; x:%d; y:%d>\n", points[left].id, points[left].x, points[left].y, points[left+1].id, points[left+1].x, points[left+1].y, points[right].id, points[right].x, points[right].y); } while (0);
        do { if (0) fprintf(stderr, "Distances are %f and %f\n", d1, d2); } while (0);
        if(d1 < d2) {
            sht->dist = d1;
            sht->fid = points[left].id;
            sht->sid = points[left+1].id;
        } else {
            sht->dist = d2;
            sht->fid = points[left+1].id;
            sht->sid = points[right].id;
        }
        do { if (0) fprintf(stderr, "Found new shortest distance Line<dist:%f; fid:%d; sid:%d>\n", sht->dist, sht->fid, sht->sid); } while (0);
        return sht;
    }
    int m = (left + right) >> 1;
    double mid = points[right].x - points[left].x;
    do { if (0) fprintf(stderr, "Splitting by (%d; %d) and (%d, %d)\n\n", left, m, m+1, right); } while (0);
    Line * shtf = find_cls_pair(points, left, m);
    Line * shts = find_cls_pair(points, m+1, right);
    do { if (0) fprintf(stderr, "Plane first Line<dist:%f; fid:%d; sid:%d>\n", shtf->dist, shtf->fid, shtf->sid); } while (0);
    do { if (0) fprintf(stderr, "Plane second Line<dist:%f; fid:%d; sid:%d>\n", shts->dist, shts->fid, shts->sid); } while (0);
    if (shtf->dist < shts->dist) {
        free(shts);
        sht = shtf;
    } else {
        free(shtf);
        sht = shts;
    }
    do { if (0) fprintf(stderr, "Shortest Plane is Line<dist:%f; fid:%d; sid:%d>\n\n", sht->dist, sht->fid, sht->sid); } while (0);
    sort_points_y(points+left, right-left);
    do { if (0) fprintf(stderr, "Checking Plane1 < mid < Plane2 left:%d right:%d min_dist:%f\n", left, right, sht->dist); } while (0);
    for(int i = left, j = left + 1; i < right-1; i++, j++) {
        if(abs(points[i].x - mid) <= sht->dist) {
            if((points[i].y - sht->dist) <= points[j].y) {
                double d = dist(points[i], points[j]);
                do { if (0) fprintf(stderr, "Comparing Point<id:%d; x:%d; y:%d> and Point<id:%d; x:%d; y:%d> distance is %f\n", points[i].id, points[i].x, points[i].y, points[j].id, points[j].x, points[j].y, d); } while (0);
                if(d < sht->dist) {
                    sht->dist = d;
                    sht->fid = points[i].id;
                    sht->sid = points[j].id;
                    do { if (0) fprintf(stderr, "Found new shortest distance Line<dist:%f; fid:%d; sid:%d>\n", sht->dist, sht->fid, sht->sid); } while (0);
                }
            }
        }
    }
    do { if (0) fprintf(stderr, "\n"); } while (0);
    return sht;
}

canonical_original_code:
struct Line *find_cls_pair(struct Point points[], int left, int right)
{
    do { if (0) fprintf(stderr, "Receive left:%d and right:%d\n", left, right); } while (0);
    struct Line *sht = malloc(sizeof(Line));
    if(left+1 == right) {
        sht->dist = dist(points[left], points[left+1]);
        sht->fid = points[left].id;
        sht->sid = points[left+1].id;
        do { if (0) fprintf(stderr, "Only two points and line is Line<dist:%f; fid:%d; sid:%d>\n\n", sht->dist, sht->fid, sht->sid); } while (0);
        return sht;
    }
    if((right - left) < 3) {
        double d1 = dist(points[left], points[left+1]);
        double d2 = dist(points[left+1], points[right]);
        do { if (0) fprintf(stderr, "Comparing Point<id:%d; x:%d; y:%d> and Point<id:%d; x:%d; y:%d> and Point<id:%d; x:%d; y:%d>\n", points[left].id, points[left].x, points[left].y, points[left+1].id, points[left+1].x, points[left+1].y, points[right].id, points[right].x, points[right].y); } while (0);
        do { if (0) fprintf(stderr, "Distances are %f and %f\n", d1, d2); } while (0);
        if(d1 < d2) {
            sht->dist = d1;
            sht->fid = points[left].id;
            sht->sid = points[left+1].id;
        } else {
            sht->dist = d2;
            sht->fid = points[left+1].id;
            sht->sid = points[right].id;
        }
        do { if (0) fprintf(stderr, "Found new shortest distance Line<dist:%f; fid:%d; sid:%d>\n", sht->dist, sht->fid, sht->sid); } while (0);
        return sht;
    }
    int m = (left + right) >> 1;
    double mid = points[right].x - points[left].x;
    do { if (0) fprintf(stderr, "Splitting by (%d; %d) and (%d, %d)\n\n", left, m, m+1, right); } while (0);
    struct Line *shtf = find_cls_pair(points, left, m);
    struct Line *shts = find_cls_pair(points, m+1, right);
    do { if (0) fprintf(stderr, "Plane first Line<dist:%f; fid:%d; sid:%d>\n", shtf->dist, shtf->fid, shtf->sid); } while (0);
    do { if (0) fprintf(stderr, "Plane second Line<dist:%f; fid:%d; sid:%d>\n", shts->dist, shts->fid, shts->sid); } while (0);
    if (shtf->dist < shts->dist) {
        free(shts);
        sht = shtf;
    } else {
        free(shtf);
        sht = shts;
    }
    do { if (0) fprintf(stderr, "Shortest Plane is Line<dist:%f; fid:%d; sid:%d>\n\n", sht->dist, sht->fid, sht->sid); } while (0);
    sort_points_y(points+left, right-left);
    do { if (0) fprintf(stderr, "Checking Plane1 < mid < Plane2 left:%d right:%d min_dist:%f\n", left, right, sht->dist); } while (0);
    for(int i = left; int j = left + 1; i < right-1; i++, j++) {
        if(abs(points[i].x - mid) <= sht->dist) {
            if((points[i].y - sht->dist) <= points[j].y) {
                double d = dist(points[i], points[j]);
                do { if (0) fprintf(stderr, "Comparing Point<id:%d; x:%d; y:%d> and Point<id:%d; x:%d; y:%d> distance is %f\n", points[i].id, points[i].x, points[i].y, points[j].id, points[j].x, points[j].y, d); } while (0);
                if(d < sht->dist) {
                    sht->dist = d;
                    sht->fid = points[i].id;
                    sht->sid = points[j].id;
                    do { if (0) fprintf(stderr, "Found new shortest distance Line<dist:%f; fid:%d; sid:%d>\n", sht->dist, sht->fid, sht->sid); } while (0);
                }
            }
        }
    }
    do { if (0) fprintf(stderr, "\n"); } while (0);
    return sht;
}

variable_types: left int

variable_types: right int

variable_types: struct Line { double dist; int fid; int sid; } *

variable_types: m int

variable_types: mid double

variable_types: i int

variable_types: j int

variable_types: d double


fibonacci

decompiled_code:
void __fastcall fibonacci(int a1, __int64 a2, int a3)
{
__int64 v3; // rax
unsigned __int64 v4; // rcx
int v5; // edx

if ( a3 <= a1 )
{
v3 = a2 + 4LL * a3;
v4 = a2 + 4 * (a3 + (unsigned __int64)(unsigned int)(a1 - a3)) + 4;
do
{
v5 = *(_DWORD *)(v3 - 4) + *(_DWORD *)(v3 - 8);
v3 += 4LL;
*(_DWORD *)(v3 - 4) = v5;
}
while ( v3 != v4 );
}
}

original_code:
void fibonacci(int n, int seq[], int last_in_seq)
{
    if(last_in_seq <= n) {
        seq[last_in_seq] = seq[last_in_seq-1] + seq[last_in_seq-2];
        fibonacci(n, seq, last_in_seq+1);
    }
    return;
}

variable_types: n int

variable_types:
seq
int []


decompiled_code:
int __fastcall print_array(__int64 a1, __int64 a2)
{
__int64 v3; // rbx
__int64 v4; // rsi

putchar(40);
if ( a2 )
{
v3 = 0LL;
while ( 1 )
{
v4 = *(unsigned int *)(a1 + 4 * v3++);
printf("%d", v4);
if ( v3 == a2 )
break;
printf(", ");
}
}
return puts(")");
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, __int64 a2)
{
__int64 v3; // rbx
__int64 v4; // rsi

putchar(40);
if ( a2 )
{
v3 = 0LL;
while ( 1 )
{
v4 = *(unsigned int *)(a1 + 4 * v3++);
printf("%d", v4);
if ( v3 == a2 )
break;
printf(", ");
}
}
return puts(")");
}

original_code:
void print_array(int array[], size_t count)
{
    printf("(");
    for(size_t i = 0; i < count; i++) {
        printf("%d", array[i]);
        if(i+1 < count) {
            printf(", ");
        }
    }
    printf(")\n");
    return;
}

canonical_original_code:
void print_array(int array[], unsigned long count)
{
    printf("(");
    for(unsigned long i = 0; i < count; i++) {
        printf("%d", array[i]);
        if(i+1 < count) {
            printf(", ");
        }
    }
    printf(")\n");
    return;
}

variable_types:
array
int []

variable_types:
count
unsigned long


decompiled_code:
void *__fastcall split_string(void *src, char *delim, _QWORD *a3)
{
size_t v3; // r15
void *v4; // r12
char *v5; // rax
char *v6; // rbx
__int64 v7; // r13
void *v8; // r15
__int64 v9; // r14
_QWORD *v10; // rax

v3 = strlen((const char *)src);
v4 = malloc(v3);
memcpy(v4, src, v3);
v5 = strtok((char *)v4, delim);
if ( v5 )
{
v6 = v5;
v7 = 0LL;
v8 = 0LL;
do
{
LODWORD(v9) = v7 + 1;
v10 = realloc(v8, 8 * v7);
v10[v7] = v6;
v8 = v10;
++v7;
v6 = strtok(0LL, delim);
}
while ( v6 );
v9 = (int)v9;
}
else
{
v8 = 0LL;
v9 = 0LL;
}
*a3 = v9;
free(v4);
return v8;
}

canonical_decompiled_code:
void *__fastcall func9(void *src, char *delim, _QWORD *a3)
{
size_t v3; // r15
void *v4; // r12
char *v5; // rax
char *v6; // rbx
__int64 v7; // r13
void *v8; // r15
__int64 v9; // r14
_QWORD *v10; // rax

v3 = strlen((const char *)src);
v4 = malloc(v3);
memcpy(v4, src, v3);
v5 = strtok((char *)v4, delim);
if ( v5 )
{
v6 = v5;
v7 = 0LL;
v8 = 0LL;
do
{
LODWORD(v9) = v7 + 1;
v10 = realloc(v8, 8 * v7);
v10[v7] = v6;
v8 = v10;
++v7;
v6 = strtok(0LL, delim);
}
while ( v6 );
v9 = (int)v9;
}
else
{
v8 = 0LL;
v9 = 0LL;
}
*a3 = v9;
free(v4);
return v8;
}

original_code:
char ** split_string(const char *string, const char *delim, size_t *len)
{
    int n_spaces = 0;
    char **res = ((void *)0);
    char *str = malloc(strlen(string));
    memcpy(str, string, strlen(string));
    char *part = strtok(str, delim);
    while(part) {
        res = realloc(res, sizeof(char*) * n_spaces);
        res[n_spaces] = part;
        n_spaces++;
        part = strtok(((void *)0), delim);
    }
    *len = n_spaces;
    free(str);
    return res;
}

canonical_original_code:
char **split_string(char *string, char *delim, unsigned long *len)
{
    int n_spaces = 0;
    char **res = ((void *)0);
    char *str = malloc(strlen(string));
    memcpy(str, string, strlen(string));
    char *part = strtok(str, delim);
    while(part) {
        res = realloc(res, sizeof(char *) * n_spaces);
        res[n_spaces] = part;
        n_spaces++;
        part = strtok(((void *)0), delim);
    }
    *len = n_spaces;
    free(str);
    return res;
}

variable_types:
string
char *

variable_types:
delim
char *

variable_types:
len
unsigned long *

variable_types:
res
char **

variable_types:
str
char *

variable_types:
part
char *

return_type: char **


trimwhitespace

decompiled_code:
size_t __fastcall trimwhitespace(void *dest, void *src)
{
const char *v2; // rbp
size_t v3; // r12
const unsigned __int16 *v4; // r13
size_t v5; // rdx
const char *v6; // rax
size_t v7; // rax

v2 = (const char *)src;
v3 = strlen((const char *)src);
v4 = *__ctype_b_loc();
while ( (v4[*v2] & 0x2000) != 0 )
++v2;
v5 = strlen(v2);
v6 = &v2[v5 - 1];
if ( v2 < v6 )
{
while ( (v4[*v6] & 0x2000) != 0 )
{
if ( v2 == v6 - 1 )
goto LABEL_10;
--v6;
}
++v6;
}
else
{
v6 = &v2[v5];
}
LABEL_10:
v7 = v6 - v2;
if ( v7 <= v3 )
v3 = v7;
memcpy(dest, v2, v3);
*((_BYTE *)dest + v3) = 0;
return v3;
}

canonical_decompiled_code:
size_t __fastcall func10(void *dest, void *src)
{
const char *v2; // rbp
size_t v3; // r12
const unsigned __int16 *v4; // r13
size_t v5; // rdx
const char *v6; // rax
size_t v7; // rax

v2 = (const char *)src;
v3 = strlen((const char *)src);
v4 = *__ctype_b_loc();
while ( (v4[*v2] & 0x2000) != 0 )
++v2;
v5 = strlen(v2);
v6 = &v2[v5 - 1];
if ( v2 < v6 )
{
while ( (v4[*v6] & 0x2000) != 0 )
{
if ( v2 == v6 - 1 )
goto LABEL_10;
--v6;
}
++v6;
}
else
{
v6 = &v2[v5];
}
LABEL_10:
v7 = v6 - v2;
if ( v7 <= v3 )
v3 = v7;
memcpy(dest, v2, v3);
*((_BYTE *)dest + v3) = 0;
return v3;
}

original_code:
size_t trimwhitespace(char *out, const char *str)
{
    size_t len = strlen(str);
    const char *end;
    while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace)) str++;
    end = str + strlen(str) - 1;
    while(end > str && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISspace)) end--;
    end++;
    size_t out_size;
    out_size = (end - str) < len ? (end - str) : len;
    memcpy(out, str, out_size);
    out[out_size] = 0;
    return out_size;
}

canonical_original_code:
unsigned long trimwhitespace(char *out, char *str)
{
    unsigned long len = strlen(str);
    char *end;
    while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace)) str++;
    end = str + strlen(str) - 1;
    while(end > str && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISspace)) end--;
    end++;
    unsigned long out_size;
    out_size = (end - str) < len ? (end - str) : len;
    memcpy(out, str, out_size);
    out[out_size] = 0;
    return out_size;
}

variable_types:
out
char *

variable_types:
len
unsigned long

variable_types:
end
char *

return_type: unsigned long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
const unsigned __int16 **v4; // rax
__int64 v5; // rsi
int v6; // eax
__int64 v7; // r13
void *v8; // rsp
int result; // eax
_BYTE v10[3]; // [rsp+0h] [rbp-10h] BYREF
char v11; // [rsp+3h] [rbp-Dh] BYREF

if ( argc == 2 )
{
v3 = argv[1];
v4 = __ctype_b_loc();
v5 = *v3;
if ( ((*v4)[v5] & 0x800) != 0 )
{
v6 = atoi(v3);
if ( v6 < 0 )
{
puts("Number have to be greater or equal to 0");
result = 1;
}
else
{
v7 = v6;
v8 = alloca(4LL * v6);
*(_QWORD *)(4 * ((unsigned __int64)&v11 >> 2)) = 0x100000000LL;
fibonacci((unsigned int)v6, v10, 2LL);
print_array(v10, v7);
result = 0;
}
}
else
{
printf("'%c' is not a number\n", v5);
result = 1;
}
}
else
{
puts("Usage:\n> fibonacci N\n\nWhere N >= 0");
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
const unsigned __int16 **v4; // rax
__int64 v5; // rsi
int v6; // eax
__int64 v7; // r13
void *v8; // rsp
int result; // eax
_BYTE v10[3]; // [rsp+0h] [rbp-10h] BYREF
char v11; // [rsp+3h] [rbp-Dh] BYREF

if ( argc == 2 )
{
v3 = argv[1];
v4 = __ctype_b_loc();
v5 = *v3;
if ( ((*v4)[v5] & 0x800) != 0 )
{
v6 = atoi(v3);
if ( v6 < 0 )
{
puts("Number have to be greater or equal to 0");
result = 1;
}
else
{
v7 = v6;
v8 = alloca(4LL * v6);
*(_QWORD *)(4 * ((unsigned __int64)&v11 >> 2)) = 0x100000000LL;
func7((unsigned int)v6, v10, 2LL);
func8(v10, v7);
result = 0;
}
}
else
{
printf("'%c' is not a number\n", v5);
result = 1;
}
}
else
{
puts("Usage:\n> fibonacci N\n\nWhere N >= 0");
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv) {
    char *result = all_tests();
    if (result != 0) {
        printf("%s\n", result);
    }
    else {
        printf("ALL TESTS PASSED\n");
    }
    printf("Tests run: %d\n", tests_run);
    return result != 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
result
char *


shift

decompiled_code:
__int64 __fastcall shift(void *dest, unsigned __int64 a2, int a3)
{
__int64 result; // rax
unsigned __int64 v5; // rdx
unsigned __int64 v6; // rtt
size_t v7; // r14
size_t v8; // r12
void *v9; // rsp
char *v10; // [rsp-48h] [rbp-48h] BYREF
char *v11; // [rsp-40h] [rbp-40h]

v6 = (int)abs32(a3);
result = v6 / a2;
v5 = v6 % a2;
if ( v6 % a2 )
{
v7 = 4 * v5;
v8 = 4 * (a2 - v5);
v9 = alloca(4 * v5);
if ( a3 < 0 )
{
v10 = (char *)dest + v8;
v11 = (char *)dest + 4 * v5;
memcpy(&v10, dest, 4 * v5);
memmove(dest, v11, v8);
result = (__int64)memcpy(v10, &v10, v7);
}
else
{
v11 = (char *)dest + 4 * v5;
memcpy(&v10, (char *)dest + v8, 4 * v5);
memmove(v11, dest, v8);
result = (__int64)memcpy(dest, &v10, v7);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *dest, unsigned __int64 a2, int a3)
{
__int64 result; // rax
unsigned __int64 v5; // rdx
unsigned __int64 v6; // rtt
size_t v7; // r14
size_t v8; // r12
void *v9; // rsp
char *v10; // [rsp-48h] [rbp-48h] BYREF
char *v11; // [rsp-40h] [rbp-40h]

v6 = (int)abs32(a3);
result = v6 / a2;
v5 = v6 % a2;
if ( v6 % a2 )
{
v7 = 4 * v5;
v8 = 4 * (a2 - v5);
v9 = alloca(4 * v5);
if ( a3 < 0 )
{
v10 = (char *)dest + v8;
v11 = (char *)dest + 4 * v5;
memcpy(&v10, dest, 4 * v5);
memmove(dest, v11, v8);
result = (__int64)memcpy(v10, &v10, v7);
}
else
{
v11 = (char *)dest + 4 * v5;
memcpy(&v10, (char *)dest + v8, 4 * v5);
memmove(v11, dest, v8);
result = (__int64)memcpy(dest, &v10, v7);
}
}
return result;
}

original_code:
void shift(int a[], size_t nmemb, int dst)
{
    int left = dst < 0;
    dst = abs(dst) % nmemb;
    if(dst) {
        int b[dst];
        if(left) {
            bcopy(a, b, dst * sizeof(int));
            bcopy(&a[dst], a, (nmemb - dst) * sizeof(int));
            bcopy(b, &a[nmemb - dst], dst * sizeof(int));
        } else {
            bcopy(&a[nmemb - dst], b, dst * sizeof(int));
            bcopy(a, &a[dst], (nmemb - dst) * sizeof(int));
            bcopy(b, a, dst * sizeof(int));
        }
    }
}

canonical_original_code:
void shift(int a[], unsigned long nmemb, int dst)
{
    int left = dst < 0;
    dst = abs(dst) % nmemb;
    if(dst) {
        int b[-1];
        if(left) {
            bcopy(a, b, dst * sizeof(int));
            bcopy(&a[dst], a, (nmemb - dst) * sizeof(int));
            bcopy(b, &a[nmemb - dst], dst * sizeof(int));
        } else {
            bcopy(&a[nmemb - dst], b, dst * sizeof(int));
            bcopy(a, &a[dst], (nmemb - dst) * sizeof(int));
            bcopy(b, a, dst * sizeof(int));
        }
    }
}

variable_types:
a
int []

variable_types:
nmemb
unsigned long

variable_types: dst int

variable_types: left int

variable_types:
b
int [-1]


decompiled_code:
void __fastcall merge_two_arrays(const void *a1, __int64 a2, const void *a3, __int64 a4, void *a5)
{
__int64 v6; // rbp
__int64 v7; // rbx
_DWORD *v8; // r12
int *v9; // r14
_DWORD *v10; // r15
_DWORD *v11; // r13
int v12; // eax
int v13; // esi
int v14; // esi
int v15; // esi
size_t v16; // [rsp+0h] [rbp-58h]
size_t n; // [rsp+8h] [rbp-50h]
int *src; // [rsp+10h] [rbp-48h]
_DWORD *srca; // [rsp+10h] [rbp-48h]
int *srcb; // [rsp+10h] [rbp-48h]

v6 = a4;
v7 = a2;
v8 = malloc(4 * (a2 + a4));
v9 = (int *)malloc(4 * a2);
v10 = malloc(4 * v6);
memcpy(v9, a1, 4 * a2);
memcpy(v10, a3, 4 * v6);
n = (int)a2 + (int)v6;
if ( (int)a2 + (int)v6 > 0 )
{
v11 = v8;
v16 = (size_t)&v8[(unsigned int)(a2 + v6)];
do
{
while ( !v7 )
{
*v11 = *v10;
LABEL_9:
v14 = v6--;
++v11;
srca = shifted_array((__int64)v10, v14);
free(v10);
print_array(v8, n);
v10 = srca;
if ( v11 == (_DWORD *)v16 )
goto LABEL_10;
}
v12 = *v9;
if ( v6 )
{
if ( *v10 <= v12 )
{
*v11 = *v10;
goto LABEL_9;
}
*v11 = v12;
v13 = v7--;
src = (int *)shifted_array((__int64)v9, v13);
free(v9);
print_array(v8, n);
v9 = src;
}
else
{
*v11 = v12;
v15 = v7--;
srcb = (int *)shifted_array((__int64)v9, v15);
free(v9);
v9 = srcb;
}
++v11;
}
while ( v11 != (_DWORD *)v16 );
}
LABEL_10:
memcpy(a5, v8, 4 * n);
free(v8);
free(v9);
free(v10);
}

original_code:
void merge_two_arrays(int a1[], size_t l1, int a2[], size_t l2, int array[])
{
    int *compound = malloc((l1 + l2) * sizeof(*a1));
    int *left = malloc(l1 * sizeof(*a1));
    int *right = malloc(l2 * sizeof(*a2));
    memcpy(left, a1, l1*sizeof(*a1));
    memcpy(right, a2, l2*sizeof(*a2));
    int cnt = (int)(l1 + l2);
    for(int i = 0; i < cnt; i++) {
        if(l1 == 0) {
            compound[i] = right[0];
            int *new_right = shifted_array(right, (int)l2);
            free(right);
            right = new_right;
            l2--;
            print_array(compound, cnt);
        } else if (l2 == 0) {
            compound[i] = left[0];
            int *new_left = shifted_array(left, (int)l1);
            free(left);
            left = new_left;
            l1--;
        } else {
            if(left[0] < right[0]) {
                compound[i] = left[0];
                int *new_left = shifted_array(left, (int)l1);
                free(left);
                left = new_left;
                l1--;
                print_array(compound, cnt);
            } else {
                compound[i] = right[0];
                int *new_right = shifted_array(right, (int)l2);
                free(right);
                right = new_right;
                l2--;
                print_array(compound, cnt);
            }
        }
    }
    memcpy(array, compound, cnt*sizeof(*compound));
    free(compound);
    free(left);
    free(right);
    return;
}

canonical_original_code:
void merge_two_arrays(int a1[], unsigned long l1, int a2[], unsigned long l2, int array[])
{
    int *compound = malloc((l1 + l2) * sizeof(*a1));
    int *left = malloc(l1 * sizeof(*a1));
    int *right = malloc(l2 * sizeof(*a2));
    memcpy(left, a1, l1*sizeof(*a1));
    memcpy(right, a2, l2*sizeof(*a2));
    int cnt = (int)(l1 + l2);
    for(int i = 0; i < cnt; i++) {
        if(l1 == 0) {
            compound[i] = right[0];
            int *new_right = shifted_array(right, (int)l2);
            free(right);
            right = new_right;
            l2--;
            print_array(compound, cnt);
        } else if (l2 == 0) {
            compound[i] = left[0];
            int *new_left = shifted_array(left, (int)l1);
            free(left);
            left = new_left;
            l1--;
        } else {
            if(left[0] < right[0]) {
                compound[i] = left[0];
                int *new_left = shifted_array(left, (int)l1);
                free(left);
                left = new_left;
                l1--;
                print_array(compound, cnt);
            } else {
                compound[i] = right[0];
                int *new_right = shifted_array(right, (int)l2);
                free(right);
                right = new_right;
                l2--;
                print_array(compound, cnt);
            }
        }
    }
    memcpy(array, compound, cnt*sizeof(*compound));
    free(compound);
    free(left);
    free(right);
    return;
}

variable_types:
array
int []

variable_types:
compound
int *

variable_types:
left
int *

variable_types:
right
int *

variable_types: cnt int

variable_types: i int


merge

original_code:
void merge(int a[], int m, int b[], int n, int sorted[]) {
    int i, j, k;
    j = k = 0;
    for (i = 0; i < m + n;) {
        if (j < m && k < n) {
            if (a[j] < b[k]) {
                sorted[i] = a[j];
                j++;
            }
            else {
                sorted[i] = b[k];
                k++;
            }
            i++;
        }
        else if (j == m) {
            for (; i < m + n;) {
                sorted[i] = b[k];
                k++;
                i++;
            }
        }
        else {
            for (; i < m + n;) {
                sorted[i] = a[j];
                j++;
                i++;
            }
        }
    }
}

canonical_original_code:
void merge(int a[], int m, int b[], int n, int sorted[]) {
    int i; int j; int k;
    j = k = 0;
    for (i = 0; i < m + n;) {
        if (j < m && k < n) {
            if (a[j] < b[k]) {
                sorted[i] = a[j];
                j++;
            }
            else {
                sorted[i] = b[k];
                k++;
            }
            i++;
        }
        else if (j == m) {
            for (; i < m + n;) {
                sorted[i] = b[k];
                k++;
                i++;
            }
        }
        else {
            for (; i < m + n;) {
                sorted[i] = a[j];
                j++;
                i++;
            }
        }
    }
}

variable_types: m int

variable_types:
b
int []

variable_types: n int

variable_types:
sorted
int []

variable_types: j int

variable_types: k int


decompiled_code:
void __fastcall split_n_sort(void *src, __int64 a2)
{
int v2; // ebp
__int64 v3; // r13
void *v4; // r12
void *v5; // rax
size_t v6; // rdx
char *v7; // rsi
void *v8; // r9
void *v9; // rax
void *v10; // r8
int v11; // ecx
int v12; // esi
__int64 v13; // rdx
void *v14; // rax
void *v15; // rax
void *v16; // rax

if ( a2 != 1 )
{
v2 = (int)a2 / 2;
v3 = 4LL * ((int)a2 / 2);
if ( a2 == 2 )
{
v4 = malloc(4LL * v2);
memcpy(v4, src, 4LL * v2);
v16 = malloc(4LL * v2);
v7 = (char *)src + v3;
v6 = 4LL * v2;
v8 = v16;
}
else
{
if ( (a2 & 1) != 0 )
{
split_n_sort(src);
split_n_sort((char *)src + v3 + 4);
v4 = malloc(v3 + 4);
memcpy(v4, src, v3 + 4);
v14 = malloc(4LL * v2);
v15 = memcpy(v14, (char *)src + v3 + 4, 4LL * v2);
v10 = src;
v11 = (int)a2 / 2;
v12 = v2 + 1;
v13 = (__int64)v15;
goto LABEL_6;
}
split_n_sort(src);
split_n_sort((char *)src + v3);
v4 = malloc(4LL * v2);
memcpy(v4, src, 4LL * v2);
v5 = malloc(4LL * v2);
v6 = 4LL * v2;
v7 = (char *)src + v3;
v8 = v5;
}
v9 = memcpy(v8, v7, v6);
v10 = src;
v11 = v2;
v12 = v2;
v13 = (__int64)v9;
LABEL_6:
merge((__int64)v4, v12, v13, v11, (__int64)v10);
}
}

original_code:
void split_n_sort(int array[], size_t count)
{
    if(count == 1) return;
    int c2 = (int)count/2;
    if(count == 2) {
        int *t1 = malloc(c2*sizeof(*array));
        memcpy(t1, array, c2*sizeof(*array));
        int *t2 = malloc(c2*sizeof(*array));
        memcpy(t2, array+c2, c2*sizeof(*array));
        merge(t1, c2, t2, c2, array);
    } else {
        if(count % 2) {
            split_n_sort(array, c2+1);
            split_n_sort(array+c2+1, c2);
            int *t1 = malloc((c2+1)*sizeof(*array));
            memcpy(t1, array, (c2+1)*sizeof(*array));
            int *t2 = malloc(c2*sizeof(*array));
            memcpy(t2, array+c2+1, c2*sizeof(*array));
            merge(t1, c2+1, t2, c2, array);
        } else {
            split_n_sort(array, c2);
            split_n_sort(array+c2, c2);
            int *t1 = malloc(c2*sizeof(*array));
            memcpy(t1, array, c2*sizeof(*array));
            int *t2 = malloc(c2*sizeof(*array));
            memcpy(t2, array+c2, c2*sizeof(*array));
            merge(t1, c2, t2, c2, array);
        }
    }
    return;
}

canonical_original_code:
void split_n_sort(int array[], unsigned long count)
{
    if(count == 1) return;
    int c2 = (int)count/2;
    if(count == 2) {
        int *t1 = malloc(c2*sizeof(*array));
        memcpy(t1, array, c2*sizeof(*array));
        int *t2 = malloc(c2*sizeof(*array));
        memcpy(t2, array+c2, c2*sizeof(*array));
        merge(t1, c2, t2, c2, array);
    } else {
        if(count % 2) {
            split_n_sort(array, c2+1);
            split_n_sort(array+c2+1, c2);
            int *t1 = malloc((c2+1)*sizeof(*array));
            memcpy(t1, array, (c2+1)*sizeof(*array));
            int *t2 = malloc(c2*sizeof(*array));
            memcpy(t2, array+c2+1, c2*sizeof(*array));
            merge(t1, c2+1, t2, c2, array);
        } else {
            split_n_sort(array, c2);
            split_n_sort(array+c2, c2);
            int *t1 = malloc(c2*sizeof(*array));
            memcpy(t1, array, c2*sizeof(*array));
            int *t2 = malloc(c2*sizeof(*array));
            memcpy(t2, array+c2, c2*sizeof(*array));
            merge(t1, c2, t2, c2, array);
        }
    }
    return;
}

variable_types:
count
unsigned long


canonical_decompiled_code:
int __fastcall func12(__int64 a1, __int64 a2)
{
__int64 v3; // rbx
__int64 v4; // rsi

putchar(40);
if ( a2 )
{
v3 = 0LL;
while ( 1 )
{
v4 = *(unsigned int *)(a1 + 4 * v3++);
printf("%d", v4);
if ( v3 == a2 )
break;
printf(", ");
}
}
return puts(")");
}

variable_types:
i
unsigned long


canonical_decompiled_code:
void *__fastcall func13(void *src, char *delim, _QWORD *a3)
{
size_t v3; // r15
void *v4; // r12
char *v5; // rax
char *v6; // rbx
__int64 v7; // r13
void *v8; // r15
__int64 v9; // r14
_QWORD *v10; // rax

v3 = strlen((const char *)src);
v4 = malloc(v3);
memcpy(v4, src, v3);
v5 = strtok((char *)v4, delim);
if ( v5 )
{
v6 = v5;
v7 = 0LL;
v8 = 0LL;
do
{
LODWORD(v9) = v7 + 1;
v10 = realloc(v8, 8 * v7);
v10[v7] = v6;
v8 = v10;
++v7;
v6 = strtok(0LL, delim);
}
while ( v6 );
v9 = (int)v9;
}
else
{
v8 = 0LL;
v9 = 0LL;
}
*a3 = v9;
free(v4);
return v8;
}

variable_types:
string
char *

variable_types:
delim
char *

variable_types:
len
unsigned long *

variable_types:
res
char **

variable_types:
str
char *

variable_types:
part
char *


trimwhitespace

canonical_decompiled_code:
size_t __fastcall func14(void *dest, void *src)
{
const char *v2; // rbp
size_t v3; // r12
const unsigned __int16 *v4; // r13
size_t v5; // rdx
const char *v6; // rax
size_t v7; // rax

v2 = (const char *)src;
v3 = strlen((const char *)src);
v4 = *__ctype_b_loc();
while ( (v4[*v2] & 0x2000) != 0 )
++v2;
v5 = strlen(v2);
v6 = &v2[v5 - 1];
if ( v2 < v6 )
{
while ( (v4[*v6] & 0x2000) != 0 )
{
if ( v2 == v6 - 1 )
goto LABEL_10;
--v6;
}
++v6;
}
else
{
v6 = &v2[v5];
}
LABEL_10:
v7 = v6 - v2;
if ( v7 <= v3 )
v3 = v7;
memcpy(dest, v2, v3);
*((_BYTE *)dest + v3) = 0;
return v3;
}

variable_types:
out
char *

variable_types:
len
unsigned long

variable_types:
end
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
_DWORD *v4; // r12
int result; // eax

if ( argc <= 1 )
{
puts("Give me the initial array");
result = 1;
}
else
{
v3 = 1LL;
v4 = malloc(4LL * (argc - 1));
do
{
v4[v3 - 1] = atoi(argv[v3]);
++v3;
}
while ( argc != v3 );
split_n_sort(v4);
print_array(v4, argc - 1);
free(v4);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
_DWORD *v4; // r12
int result; // eax

if ( argc <= 1 )
{
puts("Give me the initial array");
result = 1;
}
else
{
v3 = 1LL;
v4 = malloc(4LL * (argc - 1));
do
{
v4[v3 - 1] = atoi(argv[v3]);
++v3;
}
while ( argc != v3 );
func11(v4);
func12(v4, argc - 1);
free(v4);
result = 0;
}
return result;
}

canonical_original_code:
int main(int argc, char **argv) {
    char *result = all_tests();
    if (result != 0) {
        printf("%s\n", result);
    }
    else {
        printf("ALL TESTS PASSED\n");
    }
    printf("Tests run: %d\n", tests_run);
    return result != 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
result
char *


repo: igorcanadi/FreEBS

decompiled_code:
void __fastcall generate_random(_BYTE *a1, int a2)
{
_BYTE *v2; // rbp

if ( a2 > 0 )
{
v2 = a1;
do
*v2++ = rand() % 26 + 97;
while ( v2 != &a1[a2 - 1 + 1] );
}
}

original_code:
void generate_random(char *buf, int len) {
    int i;
    for (i = 0; i < len; ++i) {
        buf[i] = 'a' + rand() % 26;
    }
}

variable_types:
buf
char *

variable_types: len int

variable_types: i int


decompiled_code:
int basic_test()
{
char *v0; // rbp
char *v1; // r12
__int64 v2; // rax
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // r13
__int64 v6; // rax
__int64 v7; // r13
void *v8; // r14
__int64 v9; // r13
__int64 v10; // r13
__int64 v12[6]; // [rsp+8h] [rbp-30h] BYREF

v0 = (char *)malloc(0x2000uLL);
v1 = (char *)malloc(0x2000uLL);
generate_random(v0, 0x2000);
v2 = create_lsvd("/scratch/test_disk", 0x80000LL);
if ( !v2 )
_assert_fail("lsvd != NULL", "test.c", 0x32u, "basic_test");
v3 = v2;
if ( (unsigned int)write_lsvd(v2, v0, 2LL, 11LL, 1LL) )
_assert_fail("write_lsvd(lsvd, data, 2, 11, 1) == 0", "test.c", 0x33u, "basic_test");
if ( (unsigned int)write_lsvd(v3, v0, 2LL, 11LL, 2LL) )
_assert_fail("write_lsvd(lsvd, data, 2, 11, 2) == 0", "test.c", 0x34u, "basic_test");
if ( (unsigned int)write_lsvd(v3, v0, 1LL, 11LL, 3LL) )
_assert_fail("write_lsvd(lsvd, data, 1, 11, 3) == 0", "test.c", 0x35u, "basic_test");
if ( (unsigned int)close_lsvd(v3) )
_assert_fail("close_lsvd(lsvd) == 0", "test.c", 0x36u, "basic_test");
v4 = open_lsvd("/scratch/test_disk");
v5 = v4;
if ( !v4 )
_assert_fail("lsvd != NULL", "test.c", 0x39u, "basic_test");
if ( get_version(v4) != 3 )
_assert_fail("get_version(lsvd) == 3", "test.c", 0x3Au, "basic_test");
if ( *(_QWORD *)(*(_QWORD *)(v5 + 24) + 8LL) != 0x80000LL )
_assert_fail("lsvd->sblock->size == SIZE / SECTOR_SIZE", "test.c", 0x3Bu, "basic_test");
if ( (unsigned int)read_lsvd(v5, v1, 2LL, 11LL, 3LL) )
_assert_fail("read_lsvd(lsvd, buffer, 2, 11, 3) == 0", "test.c", 0x3Cu, "basic_test");
if ( strncmp(v0, v1, 0x2000uLL) )
_assert_fail("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 0x3Du, "basic_test");
if ( (unsigned int)close_lsvd(v5) )
_assert_fail("close_lsvd(lsvd) == 0", "test.c", 0x3Eu, "basic_test");
if ( (unsigned int)cleanup_lsvd("/scratch/test_disk", "/scratch/test_disk_smaller") )
_assert_fail(
"cleanup_lsvd(\"/scratch/test_disk\", \"/scratch/test_disk_smaller\") == 0",
"test.c",
0x40u,
"basic_test");
v6 = open_lsvd("/scratch/test_disk_smaller");
v7 = v6;
if ( !v6 )
_assert_fail("lsvd != NULL", "test.c", 0x44u, "basic_test");
if ( get_version(v6) != 3 )
_assert_fail("get_version(lsvd) == 3", "test.c", 0x45u, "basic_test");
if ( *(_QWORD *)(*(_QWORD *)(v7 + 24) + 8LL) != 0x80000LL )
_assert_fail("lsvd->sblock->size == SIZE / SECTOR_SIZE", "test.c", 0x46u, "basic_test");
if ( (unsigned int)read_lsvd(v7, v1, 2LL, 11LL, 3LL) )
_assert_fail("read_lsvd(lsvd, buffer, 2, 11, 3) == 0", "test.c", 0x47u, "basic_test");
if ( strncmp(v0, v1, 0x2000uLL) )
_assert_fail("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 0x48u, "basic_test");
generate_random(v0, 0x2000);
if ( (unsigned int)write_lsvd(v7, v0, 2LL, 10LL, 4LL) )
_assert_fail("write_lsvd(lsvd, data, 2, 10, 4) == 0", "test.c", 0x4Cu, "basic_test");
if ( (unsigned int)write_lsvd(v7, v0, 1LL, 12LL, 5LL) )
_assert_fail("write_lsvd(lsvd, data, 1, 12, 5) == 0", "test.c", 0x4Du, "basic_test");
if ( (unsigned int)read_lsvd(v7, v1, 2LL, 10LL, 5LL) )
_assert_fail("read_lsvd(lsvd, buffer, 2, 10, 5) == 0", "test.c", 0x4Fu, "basic_test");
if ( strncmp(v0, v1, 0x2000uLL) )
_assert_fail("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 0x50u, "basic_test");
if ( (unsigned int)read_lsvd(v7, v1, 1LL, 12LL, 5LL) )
_assert_fail("read_lsvd(lsvd, buffer, 1, 12, 5) == 0", "test.c", 0x51u, "basic_test");
if ( strncmp(v0, v1, 0x1000uLL) )
_assert_fail("strncmp(data, buffer, SECTOR_SIZE) == 0", "test.c", 0x52u, "basic_test");
v8 = (void *)get_writes_lsvd(v7, 4LL, v12);
if ( !v8 )
_assert_fail("writes_buf != NULL", "test.c", 0x54u, "basic_test");
if ( (unsigned int)close_lsvd(v7) )
_assert_fail("close_lsvd(lsvd) == 0", "test.c", 0x55u, "basic_test");
v9 = open_lsvd("/scratch/test_disk");
if ( (unsigned int)put_writes_lsvd(v9, 4LL, v8, v12[0]) )
_assert_fail("put_writes_lsvd(lsvd, 4, writes_buf, size) == 0", "test.c", 0x58u, "basic_test");
if ( (unsigned int)close_lsvd(v9) )
_assert_fail("close_lsvd(lsvd) == 0", "test.c", 0x59u, "basic_test");
v10 = open_lsvd("/scratch/test_disk");
if ( (unsigned int)read_lsvd(v10, v1, 1LL, 10LL, 5LL) )
_assert_fail("read_lsvd(lsvd, buffer, 1, 10, 5) == 0", "test.c", 0x5Cu, "basic_test");
if ( strncmp(v0, v1, 0x2000uLL) )
_assert_fail("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 0x5Du, "basic_test");
if ( (unsigned int)read_lsvd(v10, v1, 1LL, 12LL, 5LL) )
_assert_fail("read_lsvd(lsvd, buffer, 1, 12, 5) == 0", "test.c", 0x5Eu, "basic_test");
if ( strncmp(v0, v1, 0x1000uLL) )
_assert_fail("strncmp(data, buffer, SECTOR_SIZE) == 0", "test.c", 0x5Fu, "basic_test");
if ( (unsigned int)close_lsvd(v10) )
_assert_fail("close_lsvd(lsvd) == 0", "test.c", 0x60u, "basic_test");
free(v8);
free(v0);
free(v1);
return puts("All seems to work!");
}

canonical_decompiled_code:
int func1()
{
char *v0; // rbp
char *v1; // r12
__int64 v2; // rax
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // r13
__int64 v6; // rax
__int64 v7; // r13
void *v8; // r14
__int64 v9; // r13
__int64 v10; // r13
__int64 v12[6]; // [rsp+8h] [rbp-30h] BYREF

v0 = (char *)malloc(0x2000uLL);
v1 = (char *)malloc(0x2000uLL);
func0(v0, 0x2000);
v2 = create_lsvd("/scratch/test_disk", 0x80000LL);
if ( !v2 )
_assert_fail("lsvd != NULL", "test.c", 0x32u, "basic_test");
v3 = v2;
if ( (unsigned int)write_lsvd(v2, v0, 2LL, 11LL, 1LL) )
_assert_fail("write_lsvd(lsvd, data, 2, 11, 1) == 0", "test.c", 0x33u, "basic_test");
if ( (unsigned int)write_lsvd(v3, v0, 2LL, 11LL, 2LL) )
_assert_fail("write_lsvd(lsvd, data, 2, 11, 2) == 0", "test.c", 0x34u, "basic_test");
if ( (unsigned int)write_lsvd(v3, v0, 1LL, 11LL, 3LL) )
_assert_fail("write_lsvd(lsvd, data, 1, 11, 3) == 0", "test.c", 0x35u, "basic_test");
if ( (unsigned int)close_lsvd(v3) )
_assert_fail("close_lsvd(lsvd) == 0", "test.c", 0x36u, "basic_test");
v4 = open_lsvd("/scratch/test_disk");
v5 = v4;
if ( !v4 )
_assert_fail("lsvd != NULL", "test.c", 0x39u, "basic_test");
if ( get_version(v4) != 3 )
_assert_fail("get_version(lsvd) == 3", "test.c", 0x3Au, "basic_test");
if ( *(_QWORD *)(*(_QWORD *)(v5 + 24) + 8LL) != 0x80000LL )
_assert_fail("lsvd->sblock->size == SIZE / SECTOR_SIZE", "test.c", 0x3Bu, "basic_test");
if ( (unsigned int)read_lsvd(v5, v1, 2LL, 11LL, 3LL) )
_assert_fail("read_lsvd(lsvd, buffer, 2, 11, 3) == 0", "test.c", 0x3Cu, "basic_test");
if ( strncmp(v0, v1, 0x2000uLL) )
_assert_fail("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 0x3Du, "basic_test");
if ( (unsigned int)close_lsvd(v5) )
_assert_fail("close_lsvd(lsvd) == 0", "test.c", 0x3Eu, "basic_test");
if ( (unsigned int)cleanup_lsvd("/scratch/test_disk", "/scratch/test_disk_smaller") )
_assert_fail(
"cleanup_lsvd(\"/scratch/test_disk\", \"/scratch/test_disk_smaller\") == 0",
"test.c",
0x40u,
"basic_test");
v6 = open_lsvd("/scratch/test_disk_smaller");
v7 = v6;
if ( !v6 )
_assert_fail("lsvd != NULL", "test.c", 0x44u, "basic_test");
if ( get_version(v6) != 3 )
_assert_fail("get_version(lsvd) == 3", "test.c", 0x45u, "basic_test");
if ( *(_QWORD *)(*(_QWORD *)(v7 + 24) + 8LL) != 0x80000LL )
_assert_fail("lsvd->sblock->size == SIZE / SECTOR_SIZE", "test.c", 0x46u, "basic_test");
if ( (unsigned int)read_lsvd(v7, v1, 2LL, 11LL, 3LL) )
_assert_fail("read_lsvd(lsvd, buffer, 2, 11, 3) == 0", "test.c", 0x47u, "basic_test");
if ( strncmp(v0, v1, 0x2000uLL) )
_assert_fail("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 0x48u, "basic_test");
func0(v0, 0x2000);
if ( (unsigned int)write_lsvd(v7, v0, 2LL, 10LL, 4LL) )
_assert_fail("write_lsvd(lsvd, data, 2, 10, 4) == 0", "test.c", 0x4Cu, "basic_test");
if ( (unsigned int)write_lsvd(v7, v0, 1LL, 12LL, 5LL) )
_assert_fail("write_lsvd(lsvd, data, 1, 12, 5) == 0", "test.c", 0x4Du, "basic_test");
if ( (unsigned int)read_lsvd(v7, v1, 2LL, 10LL, 5LL) )
_assert_fail("read_lsvd(lsvd, buffer, 2, 10, 5) == 0", "test.c", 0x4Fu, "basic_test");
if ( strncmp(v0, v1, 0x2000uLL) )
_assert_fail("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 0x50u, "basic_test");
if ( (unsigned int)read_lsvd(v7, v1, 1LL, 12LL, 5LL) )
_assert_fail("read_lsvd(lsvd, buffer, 1, 12, 5) == 0", "test.c", 0x51u, "basic_test");
if ( strncmp(v0, v1, 0x1000uLL) )
_assert_fail("strncmp(data, buffer, SECTOR_SIZE) == 0", "test.c", 0x52u, "basic_test");
v8 = (void *)get_writes_lsvd(v7, 4LL, v12);
if ( !v8 )
_assert_fail("writes_buf != NULL", "test.c", 0x54u, "basic_test");
if ( (unsigned int)close_lsvd(v7) )
_assert_fail("close_lsvd(lsvd) == 0", "test.c", 0x55u, "basic_test");
v9 = open_lsvd("/scratch/test_disk");
if ( (unsigned int)put_writes_lsvd(v9, 4LL, v8, v12[0]) )
_assert_fail("put_writes_lsvd(lsvd, 4, writes_buf, size) == 0", "test.c", 0x58u, "basic_test");
if ( (unsigned int)close_lsvd(v9) )
_assert_fail("close_lsvd(lsvd) == 0", "test.c", 0x59u, "basic_test");
v10 = open_lsvd("/scratch/test_disk");
if ( (unsigned int)read_lsvd(v10, v1, 1LL, 10LL, 5LL) )
_assert_fail("read_lsvd(lsvd, buffer, 1, 10, 5) == 0", "test.c", 0x5Cu, "basic_test");
if ( strncmp(v0, v1, 0x2000uLL) )
_assert_fail("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 0x5Du, "basic_test");
if ( (unsigned int)read_lsvd(v10, v1, 1LL, 12LL, 5LL) )
_assert_fail("read_lsvd(lsvd, buffer, 1, 12, 5) == 0", "test.c", 0x5Eu, "basic_test");
if ( strncmp(v0, v1, 0x1000uLL) )
_assert_fail("strncmp(data, buffer, SECTOR_SIZE) == 0", "test.c", 0x5Fu, "basic_test");
if ( (unsigned int)close_lsvd(v10) )
_assert_fail("close_lsvd(lsvd) == 0", "test.c", 0x60u, "basic_test");
free(v8);
free(v0);
free(v1);
return puts("All seems to work!");
}

original_code:
void basic_test() {
    struct lsvd_disk *lsvd;
    char *writes_buf;
    size_t size;
    char *data, *buffer;
    data = (char *)malloc(2*4096);
    buffer = (char *)malloc(2*4096);
    generate_random(data, 2*4096);
    lsvd = create_lsvd("/scratch/test_disk", 2*1024*1024*1024LL / 4096);
    ((void) sizeof ((lsvd != ((void *)0)) ? 1 : 0), __extension__ ({ if (lsvd != ((void *)0)) ; else __assert_fail ("lsvd != NULL", "test.c", 50, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((write_lsvd(lsvd, data, 2, 11, 1) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 2, 11, 1) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 2, 11, 1) == 0", "test.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((write_lsvd(lsvd, data, 2, 11, 2) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 2, 11, 2) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 2, 11, 2) == 0", "test.c", 52, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((write_lsvd(lsvd, data, 1, 11, 3) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 1, 11, 3) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 1, 11, 3) == 0", "test.c", 53, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((close_lsvd(lsvd) == 0) ? 1 : 0), __extension__ ({ if (close_lsvd(lsvd) == 0) ; else __assert_fail ("close_lsvd(lsvd) == 0", "test.c", 54, __extension__ __PRETTY_FUNCTION__); }));
    lsvd = open_lsvd("/scratch/test_disk");
    ((void) sizeof ((lsvd != ((void *)0)) ? 1 : 0), __extension__ ({ if (lsvd != ((void *)0)) ; else __assert_fail ("lsvd != NULL", "test.c", 57, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((get_version(lsvd) == 3) ? 1 : 0), __extension__ ({ if (get_version(lsvd) == 3) ; else __assert_fail ("get_version(lsvd) == 3", "test.c", 58, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((lsvd->sblock->size == 2*1024*1024*1024LL / 4096) ? 1 : 0), __extension__ ({ if (lsvd->sblock->size == 2*1024*1024*1024LL / 4096) ; else __assert_fail ("lsvd->sblock->size == SIZE / SECTOR_SIZE", "test.c", 59, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((read_lsvd(lsvd, buffer, 2, 11, 3) == 0) ? 1 : 0), __extension__ ({ if (read_lsvd(lsvd, buffer, 2, 11, 3) == 0) ; else __assert_fail ("read_lsvd(lsvd, buffer, 2, 11, 3) == 0", "test.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp(data, buffer, 2*4096) == 0) ? 1 : 0), __extension__ ({ if (strncmp(data, buffer, 2*4096) == 0) ; else __assert_fail ("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((close_lsvd(lsvd) == 0) ? 1 : 0), __extension__ ({ if (close_lsvd(lsvd) == 0) ; else __assert_fail ("close_lsvd(lsvd) == 0", "test.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((cleanup_lsvd("/scratch/test_disk", "/scratch/test_disk_smaller") == 0) ? 1 : 0), __extension__ ({ if (cleanup_lsvd("/scratch/test_disk", "/scratch/test_disk_smaller") == 0) ; else __assert_fail ("cleanup_lsvd(\"/scratch/test_disk\", \"/scratch/test_disk_smaller\") == 0", "test.c", 64, __extension__ __PRETTY_FUNCTION__); }));
    lsvd = open_lsvd("/scratch/test_disk_smaller");
    ((void) sizeof ((lsvd != ((void *)0)) ? 1 : 0), __extension__ ({ if (lsvd != ((void *)0)) ; else __assert_fail ("lsvd != NULL", "test.c", 68, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((get_version(lsvd) == 3) ? 1 : 0), __extension__ ({ if (get_version(lsvd) == 3) ; else __assert_fail ("get_version(lsvd) == 3", "test.c", 69, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((lsvd->sblock->size == 2*1024*1024*1024LL / 4096) ? 1 : 0), __extension__ ({ if (lsvd->sblock->size == 2*1024*1024*1024LL / 4096) ; else __assert_fail ("lsvd->sblock->size == SIZE / SECTOR_SIZE", "test.c", 70, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((read_lsvd(lsvd, buffer, 2, 11, 3) == 0) ? 1 : 0), __extension__ ({ if (read_lsvd(lsvd, buffer, 2, 11, 3) == 0) ; else __assert_fail ("read_lsvd(lsvd, buffer, 2, 11, 3) == 0", "test.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp(data, buffer, 2*4096) == 0) ? 1 : 0), __extension__ ({ if (strncmp(data, buffer, 2*4096) == 0) ; else __assert_fail ("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    generate_random(data, 2*4096);
    ((void) sizeof ((write_lsvd(lsvd, data, 2, 10, 4) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 2, 10, 4) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 2, 10, 4) == 0", "test.c", 76, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((write_lsvd(lsvd, data, 1, 12, 5) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 1, 12, 5) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 1, 12, 5) == 0", "test.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((read_lsvd(lsvd, buffer, 2, 10, 5) == 0) ? 1 : 0), __extension__ ({ if (read_lsvd(lsvd, buffer, 2, 10, 5) == 0) ; else __assert_fail ("read_lsvd(lsvd, buffer, 2, 10, 5) == 0", "test.c", 79, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp(data, buffer, 2*4096) == 0) ? 1 : 0), __extension__ ({ if (strncmp(data, buffer, 2*4096) == 0) ; else __assert_fail ("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 80, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((read_lsvd(lsvd, buffer, 1, 12, 5) == 0) ? 1 : 0), __extension__ ({ if (read_lsvd(lsvd, buffer, 1, 12, 5) == 0) ; else __assert_fail ("read_lsvd(lsvd, buffer, 1, 12, 5) == 0", "test.c", 81, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp(data, buffer, 4096) == 0) ? 1 : 0), __extension__ ({ if (strncmp(data, buffer, 4096) == 0) ; else __assert_fail ("strncmp(data, buffer, SECTOR_SIZE) == 0", "test.c", 82, __extension__ __PRETTY_FUNCTION__); }));
    writes_buf = get_writes_lsvd(lsvd, 4, &size);
    ((void) sizeof ((writes_buf != ((void *)0)) ? 1 : 0), __extension__ ({ if (writes_buf != ((void *)0)) ; else __assert_fail ("writes_buf != NULL", "test.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((close_lsvd(lsvd) == 0) ? 1 : 0), __extension__ ({ if (close_lsvd(lsvd) == 0) ; else __assert_fail ("close_lsvd(lsvd) == 0", "test.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    lsvd = open_lsvd("/scratch/test_disk");
    ((void) sizeof ((put_writes_lsvd(lsvd, 4, writes_buf, size) == 0) ? 1 : 0), __extension__ ({ if (put_writes_lsvd(lsvd, 4, writes_buf, size) == 0) ; else __assert_fail ("put_writes_lsvd(lsvd, 4, writes_buf, size) == 0", "test.c", 88, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((close_lsvd(lsvd) == 0) ? 1 : 0), __extension__ ({ if (close_lsvd(lsvd) == 0) ; else __assert_fail ("close_lsvd(lsvd) == 0", "test.c", 89, __extension__ __PRETTY_FUNCTION__); }));
    lsvd = open_lsvd("/scratch/test_disk");
    ((void) sizeof ((read_lsvd(lsvd, buffer, 1, 10, 5) == 0) ? 1 : 0), __extension__ ({ if (read_lsvd(lsvd, buffer, 1, 10, 5) == 0) ; else __assert_fail ("read_lsvd(lsvd, buffer, 1, 10, 5) == 0", "test.c", 92, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp(data, buffer, 2*4096) == 0) ? 1 : 0), __extension__ ({ if (strncmp(data, buffer, 2*4096) == 0) ; else __assert_fail ("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 93, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((read_lsvd(lsvd, buffer, 1, 12, 5) == 0) ? 1 : 0), __extension__ ({ if (read_lsvd(lsvd, buffer, 1, 12, 5) == 0) ; else __assert_fail ("read_lsvd(lsvd, buffer, 1, 12, 5) == 0", "test.c", 94, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp(data, buffer, 4096) == 0) ? 1 : 0), __extension__ ({ if (strncmp(data, buffer, 4096) == 0) ; else __assert_fail ("strncmp(data, buffer, SECTOR_SIZE) == 0", "test.c", 95, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((close_lsvd(lsvd) == 0) ? 1 : 0), __extension__ ({ if (close_lsvd(lsvd) == 0) ; else __assert_fail ("close_lsvd(lsvd) == 0", "test.c", 96, __extension__ __PRETTY_FUNCTION__); }));
    free(writes_buf);
    free(data);
    free(buffer);
    printf("All seems to work!\n");
}

canonical_original_code:
void basic_test() {
    struct lsvd_disk *lsvd;
    char *writes_buf;
    unsigned long size;
    char *data; char *buffer;
    data = (char *)malloc(2*4096);
    buffer = (char *)malloc(2*4096);
    generate_random(data, 2*4096);
    lsvd = create_lsvd("/scratch/test_disk", 2*1024*1024*1024LL / 4096);
    ((void) sizeof ((lsvd != ((void *)0)) ? 1 : 0), __extension__ ({ if (lsvd != ((void *)0)) ; else __assert_fail ("lsvd != NULL", "test.c", 50, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((write_lsvd(lsvd, data, 2, 11, 1) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 2, 11, 1) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 2, 11, 1) == 0", "test.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((write_lsvd(lsvd, data, 2, 11, 2) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 2, 11, 2) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 2, 11, 2) == 0", "test.c", 52, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((write_lsvd(lsvd, data, 1, 11, 3) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 1, 11, 3) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 1, 11, 3) == 0", "test.c", 53, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((close_lsvd(lsvd) == 0) ? 1 : 0), __extension__ ({ if (close_lsvd(lsvd) == 0) ; else __assert_fail ("close_lsvd(lsvd) == 0", "test.c", 54, __extension__ __PRETTY_FUNCTION__); }));
    lsvd = open_lsvd("/scratch/test_disk");
    ((void) sizeof ((lsvd != ((void *)0)) ? 1 : 0), __extension__ ({ if (lsvd != ((void *)0)) ; else __assert_fail ("lsvd != NULL", "test.c", 57, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((get_version(lsvd) == 3) ? 1 : 0), __extension__ ({ if (get_version(lsvd) == 3) ; else __assert_fail ("get_version(lsvd) == 3", "test.c", 58, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((lsvd->sblock->size == 2*1024*1024*1024LL / 4096) ? 1 : 0), __extension__ ({ if (lsvd->sblock->size == 2*1024*1024*1024LL / 4096) ; else __assert_fail ("lsvd->sblock->size == SIZE / SECTOR_SIZE", "test.c", 59, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((read_lsvd(lsvd, buffer, 2, 11, 3) == 0) ? 1 : 0), __extension__ ({ if (read_lsvd(lsvd, buffer, 2, 11, 3) == 0) ; else __assert_fail ("read_lsvd(lsvd, buffer, 2, 11, 3) == 0", "test.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp(data, buffer, 2*4096) == 0) ? 1 : 0), __extension__ ({ if (strncmp(data, buffer, 2*4096) == 0) ; else __assert_fail ("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((close_lsvd(lsvd) == 0) ? 1 : 0), __extension__ ({ if (close_lsvd(lsvd) == 0) ; else __assert_fail ("close_lsvd(lsvd) == 0", "test.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((cleanup_lsvd("/scratch/test_disk", "/scratch/test_disk_smaller") == 0) ? 1 : 0), __extension__ ({ if (cleanup_lsvd("/scratch/test_disk", "/scratch/test_disk_smaller") == 0) ; else __assert_fail ("cleanup_lsvd(\"/scratch/test_disk\", \"/scratch/test_disk_smaller\") == 0", "test.c", 64, __extension__ __PRETTY_FUNCTION__); }));
    lsvd = open_lsvd("/scratch/test_disk_smaller");
    ((void) sizeof ((lsvd != ((void *)0)) ? 1 : 0), __extension__ ({ if (lsvd != ((void *)0)) ; else __assert_fail ("lsvd != NULL", "test.c", 68, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((get_version(lsvd) == 3) ? 1 : 0), __extension__ ({ if (get_version(lsvd) == 3) ; else __assert_fail ("get_version(lsvd) == 3", "test.c", 69, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((lsvd->sblock->size == 2*1024*1024*1024LL / 4096) ? 1 : 0), __extension__ ({ if (lsvd->sblock->size == 2*1024*1024*1024LL / 4096) ; else __assert_fail ("lsvd->sblock->size == SIZE / SECTOR_SIZE", "test.c", 70, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((read_lsvd(lsvd, buffer, 2, 11, 3) == 0) ? 1 : 0), __extension__ ({ if (read_lsvd(lsvd, buffer, 2, 11, 3) == 0) ; else __assert_fail ("read_lsvd(lsvd, buffer, 2, 11, 3) == 0", "test.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp(data, buffer, 2*4096) == 0) ? 1 : 0), __extension__ ({ if (strncmp(data, buffer, 2*4096) == 0) ; else __assert_fail ("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    generate_random(data, 2*4096);
    ((void) sizeof ((write_lsvd(lsvd, data, 2, 10, 4) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 2, 10, 4) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 2, 10, 4) == 0", "test.c", 76, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((write_lsvd(lsvd, data, 1, 12, 5) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 1, 12, 5) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 1, 12, 5) == 0", "test.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((read_lsvd(lsvd, buffer, 2, 10, 5) == 0) ? 1 : 0), __extension__ ({ if (read_lsvd(lsvd, buffer, 2, 10, 5) == 0) ; else __assert_fail ("read_lsvd(lsvd, buffer, 2, 10, 5) == 0", "test.c", 79, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp(data, buffer, 2*4096) == 0) ? 1 : 0), __extension__ ({ if (strncmp(data, buffer, 2*4096) == 0) ; else __assert_fail ("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 80, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((read_lsvd(lsvd, buffer, 1, 12, 5) == 0) ? 1 : 0), __extension__ ({ if (read_lsvd(lsvd, buffer, 1, 12, 5) == 0) ; else __assert_fail ("read_lsvd(lsvd, buffer, 1, 12, 5) == 0", "test.c", 81, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp(data, buffer, 4096) == 0) ? 1 : 0), __extension__ ({ if (strncmp(data, buffer, 4096) == 0) ; else __assert_fail ("strncmp(data, buffer, SECTOR_SIZE) == 0", "test.c", 82, __extension__ __PRETTY_FUNCTION__); }));
    writes_buf = get_writes_lsvd(lsvd, 4, &size);
    ((void) sizeof ((writes_buf != ((void *)0)) ? 1 : 0), __extension__ ({ if (writes_buf != ((void *)0)) ; else __assert_fail ("writes_buf != NULL", "test.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((close_lsvd(lsvd) == 0) ? 1 : 0), __extension__ ({ if (close_lsvd(lsvd) == 0) ; else __assert_fail ("close_lsvd(lsvd) == 0", "test.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    lsvd = open_lsvd("/scratch/test_disk");
    ((void) sizeof ((put_writes_lsvd(lsvd, 4, writes_buf, size) == 0) ? 1 : 0), __extension__ ({ if (put_writes_lsvd(lsvd, 4, writes_buf, size) == 0) ; else __assert_fail ("put_writes_lsvd(lsvd, 4, writes_buf, size) == 0", "test.c", 88, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((close_lsvd(lsvd) == 0) ? 1 : 0), __extension__ ({ if (close_lsvd(lsvd) == 0) ; else __assert_fail ("close_lsvd(lsvd) == 0", "test.c", 89, __extension__ __PRETTY_FUNCTION__); }));
    lsvd = open_lsvd("/scratch/test_disk");
    ((void) sizeof ((read_lsvd(lsvd, buffer, 1, 10, 5) == 0) ? 1 : 0), __extension__ ({ if (read_lsvd(lsvd, buffer, 1, 10, 5) == 0) ; else __assert_fail ("read_lsvd(lsvd, buffer, 1, 10, 5) == 0", "test.c", 92, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp(data, buffer, 2*4096) == 0) ? 1 : 0), __extension__ ({ if (strncmp(data, buffer, 2*4096) == 0) ; else __assert_fail ("strncmp(data, buffer, 2*SECTOR_SIZE) == 0", "test.c", 93, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((read_lsvd(lsvd, buffer, 1, 12, 5) == 0) ? 1 : 0), __extension__ ({ if (read_lsvd(lsvd, buffer, 1, 12, 5) == 0) ; else __assert_fail ("read_lsvd(lsvd, buffer, 1, 12, 5) == 0", "test.c", 94, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((strncmp(data, buffer, 4096) == 0) ? 1 : 0), __extension__ ({ if (strncmp(data, buffer, 4096) == 0) ; else __assert_fail ("strncmp(data, buffer, SECTOR_SIZE) == 0", "test.c", 95, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((close_lsvd(lsvd) == 0) ? 1 : 0), __extension__ ({ if (close_lsvd(lsvd) == 0) ; else __assert_fail ("close_lsvd(lsvd) == 0", "test.c", 96, __extension__ __PRETTY_FUNCTION__); }));
    free(writes_buf);
    free(data);
    free(buffer);
    printf("All seems to work!\n");
}

variable_types: struct lsvd_disk { int fd; unsigned long version; unsigned long *sector_to_offset; struct superblock { unsigned int magic; unsigned int uid; unsigned long size; unsigned long last_checkpoint; } *sblock; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } checkpoint_cond; unsigned long checkpoint_t; int checkpoint_state; } *

variable_types:
size
unsigned long

variable_types:
data
char *

variable_types:
buffer
char *

user_defined_types: struct lsvd_disk { int fd; unsigned long version; unsigned long *sector_to_offset; struct superblock *sblock; union pthread_mutex_t mutex; union pthread_cond_t checkpoint_cond; unsigned long checkpoint_t; int checkpoint_state; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
int __fastcall measure_speed_of_one_write(__int64 a1, __int64 a2)
{
__int64 i; // rbx
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rsi
int result; // eax

for ( i = 1LL; i != 16385; ++i )
{
v4 = rdtsc_start();
if ( (unsigned int)write_lsvd(a1, a2, 1LL, 0LL, i) )
_assert_fail("write_lsvd(lsvd, data, 1, 0, ++version) == 0", "test.c", 0x6Fu, "measure_speed_of_one_write");
v5 = rdtsc_end();
v6 = (unsigned int)i;
result = printf("%d %llu\n", v6, v5 - v4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
__int64 i; // rbx
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rsi
int result; // eax

for ( i = 1LL; i != 16385; ++i )
{
v4 = rdtsc_start();
if ( (unsigned int)write_lsvd(a1, a2, 1LL, 0LL, i) )
_assert_fail("write_lsvd(lsvd, data, 1, 0, ++version) == 0", "test.c", 0x6Fu, "measure_speed_of_one_write");
v5 = rdtsc_end();
v6 = (unsigned int)i;
result = printf("%d %llu\n", v6, v5 - v4);
}
return result;
}

original_code:
void measure_speed_of_one_write(struct lsvd_disk *lsvd, char *data) {
    int i, version = 0;
    uint64_t start_time, end_time;
    for (i = 1; i <= 1024*16; ++i) {
        start_time = rdtsc_start();
        ((void) sizeof ((write_lsvd(lsvd, data, 1, 0, ++version) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 1, 0, ++version) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 1, 0, ++version) == 0", "test.c", 111, __extension__ __PRETTY_FUNCTION__); }));
        end_time = rdtsc_end();
        printf("%d %llu\n", i, end_time - start_time);
    }
}

canonical_original_code:
void measure_speed_of_one_write(struct lsvd_disk *lsvd, char *data) {
    int i; int version = 0;
    unsigned long start_time; unsigned long end_time;
    for (i = 1; i <= 1024*16; ++i) {
        start_time = rdtsc_start();
        ((void) sizeof ((write_lsvd(lsvd, data, 1, 0, ++version) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 1, 0, ++version) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 1, 0, ++version) == 0", "test.c", 111, __extension__ __PRETTY_FUNCTION__); }));
        end_time = rdtsc_end();
        printf("%d %llu\n", i, end_time - start_time);
    }
}

variable_types: version int

user_defined_types: struct superblock { unsigned int magic; unsigned int uid; unsigned long size; unsigned long last_checkpoint; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
int __fastcall measure_increasing_buffer_sizes(__int64 a1, __int64 a2)
{
__int64 i; // rbx
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rsi
int result; // eax

for ( i = 1LL; i != 16385; ++i )
{
v4 = rdtsc_start();
if ( (unsigned int)write_lsvd(a1, a2, i, 0LL, i) )
_assert_fail("write_lsvd(lsvd, data, i, 0, ++version) == 0", "test.c", 0x7Bu, "measure_increasing_buffer_sizes");
v5 = rdtsc_end();
v6 = (unsigned int)i;
result = printf("%d %llu\n", v6, v5 - v4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2)
{
__int64 i; // rbx
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rsi
int result; // eax

for ( i = 1LL; i != 16385; ++i )
{
v4 = rdtsc_start();
if ( (unsigned int)write_lsvd(a1, a2, i, 0LL, i) )
_assert_fail("write_lsvd(lsvd, data, i, 0, ++version) == 0", "test.c", 0x7Bu, "measure_increasing_buffer_sizes");
v5 = rdtsc_end();
v6 = (unsigned int)i;
result = printf("%d %llu\n", v6, v5 - v4);
}
return result;
}

original_code:
void measure_increasing_buffer_sizes(struct lsvd_disk *lsvd, char *data) {
    int i, version = 0;
    uint64_t start_time, end_time;
    for (i = 1; i <= 1024*16; ++i) {
        start_time = rdtsc_start();
        ((void) sizeof ((write_lsvd(lsvd, data, i, 0, ++version) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, i, 0, ++version) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, i, 0, ++version) == 0", "test.c", 123, __extension__ __PRETTY_FUNCTION__); }));
        end_time = rdtsc_end();
        printf("%d %llu\n", i, end_time - start_time);
    }
}

canonical_original_code:
void measure_increasing_buffer_sizes(struct lsvd_disk *lsvd, char *data) {
    int i; int version = 0;
    unsigned long start_time; unsigned long end_time;
    for (i = 1; i <= 1024*16; ++i) {
        start_time = rdtsc_start();
        ((void) sizeof ((write_lsvd(lsvd, data, i, 0, ++version) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, i, 0, ++version) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, i, 0, ++version) == 0", "test.c", 123, __extension__ __PRETTY_FUNCTION__); }));
        end_time = rdtsc_end();
        printf("%d %llu\n", i, end_time - start_time);
    }
}


decompiled_code:
__int64 __fastcall measure_constant_buffer_sizes(__int64 a1, __int64 a2)
{
int v2; // ebx
int v3; // er13
__int64 v4; // rbp
__int64 v5; // r12
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-50h]
__int64 v9; // [rsp+10h] [rbp-48h]

v2 = 0;
v8 = 1LL;
do
{
v3 = v2 + 1;
v4 = 0LL;
v5 = v2 + 1LL;
v9 = rdtsc_start();
do
{
v2 = v3 + v4;
if ( (unsigned int)write_lsvd(a1, a2, 1LL, v4, v5 + v4) )
_assert_fail("write_lsvd(lsvd, data, 1, j, ++version) == 0", "test.c", 0x88u, "measure_constant_buffer_sizes");
++v4;
}
while ( v4 != v8 );
v6 = rdtsc_end();
printf("%d %llu\n", (unsigned int)v8, v6 - v9);
result = v4 + 1;
v8 = v4 + 1;
}
while ( v4 != 0x4000 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
int v2; // ebx
int v3; // er13
__int64 v4; // rbp
__int64 v5; // r12
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-50h]
__int64 v9; // [rsp+10h] [rbp-48h]

v2 = 0;
v8 = 1LL;
do
{
v3 = v2 + 1;
v4 = 0LL;
v5 = v2 + 1LL;
v9 = rdtsc_start();
do
{
v2 = v3 + v4;
if ( (unsigned int)write_lsvd(a1, a2, 1LL, v4, v5 + v4) )
_assert_fail("write_lsvd(lsvd, data, 1, j, ++version) == 0", "test.c", 0x88u, "measure_constant_buffer_sizes");
++v4;
}
while ( v4 != v8 );
v6 = rdtsc_end();
printf("%d %llu\n", (unsigned int)v8, v6 - v9);
result = v4 + 1;
v8 = v4 + 1;
}
while ( v4 != 0x4000 );
return result;
}

original_code:
void measure_constant_buffer_sizes(struct lsvd_disk *lsvd, char *data) {
    int i, j, version = 0;
    uint64_t start_time, end_time;
    for (i = 1; i <= 1024*16; ++i) {
        start_time = rdtsc_start();
        for (j = 0; j < i; ++j) {
            ((void) sizeof ((write_lsvd(lsvd, data, 1, j, ++version) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 1, j, ++version) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 1, j, ++version) == 0", "test.c", 136, __extension__ __PRETTY_FUNCTION__); }));
        }
        end_time = rdtsc_end();
        printf("%d %llu\n", i, end_time - start_time);
    }
}

canonical_original_code:
void measure_constant_buffer_sizes(struct lsvd_disk *lsvd, char *data) {
    int i; int j; int version = 0;
    unsigned long start_time; unsigned long end_time;
    for (i = 1; i <= 1024*16; ++i) {
        start_time = rdtsc_start();
        for (j = 0; j < i; ++j) {
            ((void) sizeof ((write_lsvd(lsvd, data, 1, j, ++version) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 1, j, ++version) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 1, j, ++version) == 0", "test.c", 136, __extension__ __PRETTY_FUNCTION__); }));
        }
        end_time = rdtsc_end();
        printf("%d %llu\n", i, end_time - start_time);
    }
}

variable_types: j int


benchmarks

decompiled_code:
void benchmarks()
{
_BYTE *v0; // rbp
__int64 v1; // r12

v0 = malloc(0x4000000uLL);
generate_random(v0, 0x4000000);
v1 = create_lsvd("/scratch/test_disk", 0x80000LL);
measure_constant_buffer_sizes(v1, (__int64)v0);
close_lsvd(v1);
free(v0);
}

canonical_decompiled_code:
void func5()
{
_BYTE *v0; // rbp
__int64 v1; // r12

v0 = malloc(0x4000000uLL);
func0(v0, 0x4000000);
v1 = create_lsvd("/scratch/test_disk", 0x80000LL);
func4(v1, (__int64)v0);
close_lsvd(v1);
free(v0);
}

original_code:
void benchmarks() {
    struct lsvd_disk *lsvd;
    char *data = (char *)malloc(1024*16*4096);
    generate_random(data, 1024*16*4096);
    lsvd = create_lsvd("/scratch/test_disk", 2*1024*1024*1024LL / 4096);
    measure_constant_buffer_sizes(lsvd, data);
    close_lsvd(lsvd);
    free(data);
}


decompiled_code:
void test_checkpointing()
{
__int64 v0; // rbx
_BYTE *v1; // rbp
__int64 v2; // r12

v0 = 1LL;
v1 = malloc(0x64000uLL);
generate_random(v1, 409600);
v2 = create_lsvd("/scratch/test_disk", 0x80000LL);
do
{
if ( (unsigned int)write_lsvd(v2, v1, 100LL, 0LL, v0) )
_assert_fail("write_lsvd(lsvd, data, 100, 0, i+1) == 0", "test.c", 0xA8u, "test_checkpointing");
++v0;
}
while ( v0 != 50001 );
close_lsvd(v2);
free(v1);
}

canonical_decompiled_code:
void func6()
{
__int64 v0; // rbx
_BYTE *v1; // rbp
__int64 v2; // r12

v0 = 1LL;
v1 = malloc(0x64000uLL);
func0(v1, 409600);
v2 = create_lsvd("/scratch/test_disk", 0x80000LL);
do
{
if ( (unsigned int)write_lsvd(v2, v1, 100LL, 0LL, v0) )
_assert_fail("write_lsvd(lsvd, data, 100, 0, i+1) == 0", "test.c", 0xA8u, "test_checkpointing");
++v0;
}
while ( v0 != 50001 );
close_lsvd(v2);
free(v1);
}

original_code:
void test_checkpointing() {
    int i;
    struct lsvd_disk *lsvd;
    char *data = (char *)malloc(4096 * 100);
    generate_random(data, 4096 * 100);
    lsvd = create_lsvd("/scratch/test_disk", 2*1024*1024*1024LL / 4096);
    for (i = 0; i < 50000; ++i) {
        ((void) sizeof ((write_lsvd(lsvd, data, 100, 0, i+1) == 0) ? 1 : 0), __extension__ ({ if (write_lsvd(lsvd, data, 100, 0, i+1) == 0) ; else __assert_fail ("write_lsvd(lsvd, data, 100, 0, i+1) == 0", "test.c", 168, __extension__ __PRETTY_FUNCTION__); }));
    }
    close_lsvd(lsvd);
    free(data);
}


handleExit

decompiled_code:
void handleExit()
{
eflag = 1;
}

canonical_decompiled_code:
void func0()
{
eflag = 1;
}

original_code:
void handleExit(int sig){
    eflag = 1;
}

canonical_original_code:
void handleExit(int sig){
    eflag = 1;
}

variable_types: sig int


canonical_original_code:
void generate_random(char *buf, int len) {
    int i;
    for (i = 0; i < len; ++i) {
        buf[i] = 'a' + rand() % 26;
    }
}