decompiled_code:
__int64 __fastcall check_fourcc(char *needle)
{
char *v1; // r8
__int64 result; // rax
char v3[1880]; // [rsp+0h] [rbp-758h] BYREF

strcpy(
v3,
"3IV1 3IV2 8BPSAASC ABYR ADV1 ADVJ AEMI AFLC AFLI AJPG AMPG ANIM AP41 ASLCASV1 ASV2 ASVX AUR2 AURA AVC1 AVRNBA81 BINK"
" BLZ0 BT20 BTCV BW10 BYR1 BYR2CC12 CDVC CFCC CGDI CHAM CJPG CMYK CPLA CRAM CSCD CTRX CVIDCWLT CXY1 CXY2 CYUV CYUYD26"
"1 D263 DAVC DCL1 DCL2 DCL3 DCL4 DCL5 DIV3 DIV4 DIV5 DIVXDM4V DMB1 DMB2 DMK2 DSVD DUCK DV25 DV50 DVAN DVCS DVE2 DVH1D"
"VHD DVSD DVSL DVX1 DVX2 DVX3 DX50 DXGM DXTC DXTNEKQ0 ELK0 EM2V ES07 ESCP ETV1 ETV2 ETVCFFV1 FLJP FMP4 FMVC FPS1 FRWA"
" FRWD FVF1GEOX GJPG GLZW GPEG GWLTH260 H261 H262 H263 H264 H265 H266 H267 H268 H269HDYC HFYU HMCR HMRRI263 ICLB IGOR"
" IJPG ILVC ILVR IPDV IR21 IRAW ISMEIV30 IV31 IV32 IV33 IV34 IV35 IV36 IV37 IV38 IV39 IV40 IV41IV41 IV43 IV44 IV45 IV"
"46 IV47 IV48 IV49 IV50JBYR JPEG JPGLKMVCL261 L263 LBYR LCMW LCW2 LEAD LGRY LJ11 LJ22 LJ2K LJ44 LJPGLMP2 LMP4 LSVC LS"
"VM LSVX LZO1M261 M263 M4CC M4S2 MC12 MCAM MJ2C MJPG MMES MP2A MP2T MP2VMP42 MP43 MP4A MP4S MP4T MP4V MPEG MPG4 MPGI "
"MR16 MRCA MRLEMSVC MSZHMTX1 MTX2 MTX3 MTX4 MTX5 MTX6 MTX7 MTX8 MTX9MVI1 MVI2 MWV1NAVI NDSC NDSM NDSP NDSS NDXC NDXH "
"NDXP NDXS NHVU NTN1 NTN2NVDS NVHSNVS0 NVS1 NVS2 NVS3 NVS4 NVS5NVT0 NVT1 NVT2 NVT3 NVT4 NVT5PDVC PGVV PHMO PIM1 PIM2 "
"PIMJ PIXL PJPG PVEZ PVMM PVW2QPEG QPEQRGBT RLE RLE4 RLE8 RMP4 RPZA RT21 RV20 RV30 RV40 S422 SAN3SDCC SEDG SFMC SMP4 "
"SMSC SMSD SMSV SP40 SP44 SP54 SPIG SQZ2STVA STVB STVC STVX STVY SV10 SVQ1 SVQ3TLMS TLST TM20 TM2X TMIC TMOT TR20 TSC"
"C TV10 TVJP TVMJ TY0NTY2C TY2NUCOD ULTIV210 V261 V655 VCR1 VCR2 VCR3 VCR4 VCR5 VCR6 VCR7 VCR8 VCR9VDCT VDOM VDTZ VGP"
"X VIDS VIFP VIVO VIXL VLV1 VP30 VP31 VP40VP50 VP60 VP61 VP62 VP70 VP80 VQC1 VQC2 VQJC VSSV VUUU VX1KVX2K VXSP VYU9 V"
"YUYWBVC WHAM WINX WJPG WMV1 WMV2 WMV3 WMVA WNV1 WVC1X263 X264 XLV0 XMPG XVIDXWV0 XWV1 XWV2 XWV3 XWV4 XWV5 XWV6 XWV7 "
"XWV8 XWV9XXANY16 Y411 Y41P Y444 Y8 YC12 YUV8 YUV9 YUVP YUY2 YUYV YV12 YV16YV92ZLIB ZMBV ZPEG ZYGO ZYYY");
if ( needle )
{
v1 = strchr(needle, 32);
result = 1LL;
if ( !v1 )
result = strstr(v3, needle) == 0LL;
}
else
{
fwrite("fourcc cannot be NULL", 1uLL, 0x15uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *needle)
{
char *v1; // r8
__int64 result; // rax
char v3[1880]; // [rsp+0h] [rbp-758h] BYREF

strcpy(
v3,
"3IV1 3IV2 8BPSAASC ABYR ADV1 ADVJ AEMI AFLC AFLI AJPG AMPG ANIM AP41 ASLCASV1 ASV2 ASVX AUR2 AURA AVC1 AVRNBA81 BINK"
" BLZ0 BT20 BTCV BW10 BYR1 BYR2CC12 CDVC CFCC CGDI CHAM CJPG CMYK CPLA CRAM CSCD CTRX CVIDCWLT CXY1 CXY2 CYUV CYUYD26"
"1 D263 DAVC DCL1 DCL2 DCL3 DCL4 DCL5 DIV3 DIV4 DIV5 DIVXDM4V DMB1 DMB2 DMK2 DSVD DUCK DV25 DV50 DVAN DVCS DVE2 DVH1D"
"VHD DVSD DVSL DVX1 DVX2 DVX3 DX50 DXGM DXTC DXTNEKQ0 ELK0 EM2V ES07 ESCP ETV1 ETV2 ETVCFFV1 FLJP FMP4 FMVC FPS1 FRWA"
" FRWD FVF1GEOX GJPG GLZW GPEG GWLTH260 H261 H262 H263 H264 H265 H266 H267 H268 H269HDYC HFYU HMCR HMRRI263 ICLB IGOR"
" IJPG ILVC ILVR IPDV IR21 IRAW ISMEIV30 IV31 IV32 IV33 IV34 IV35 IV36 IV37 IV38 IV39 IV40 IV41IV41 IV43 IV44 IV45 IV"
"46 IV47 IV48 IV49 IV50JBYR JPEG JPGLKMVCL261 L263 LBYR LCMW LCW2 LEAD LGRY LJ11 LJ22 LJ2K LJ44 LJPGLMP2 LMP4 LSVC LS"
"VM LSVX LZO1M261 M263 M4CC M4S2 MC12 MCAM MJ2C MJPG MMES MP2A MP2T MP2VMP42 MP43 MP4A MP4S MP4T MP4V MPEG MPG4 MPGI "
"MR16 MRCA MRLEMSVC MSZHMTX1 MTX2 MTX3 MTX4 MTX5 MTX6 MTX7 MTX8 MTX9MVI1 MVI2 MWV1NAVI NDSC NDSM NDSP NDSS NDXC NDXH "
"NDXP NDXS NHVU NTN1 NTN2NVDS NVHSNVS0 NVS1 NVS2 NVS3 NVS4 NVS5NVT0 NVT1 NVT2 NVT3 NVT4 NVT5PDVC PGVV PHMO PIM1 PIM2 "
"PIMJ PIXL PJPG PVEZ PVMM PVW2QPEG QPEQRGBT RLE RLE4 RLE8 RMP4 RPZA RT21 RV20 RV30 RV40 S422 SAN3SDCC SEDG SFMC SMP4 "
"SMSC SMSD SMSV SP40 SP44 SP54 SPIG SQZ2STVA STVB STVC STVX STVY SV10 SVQ1 SVQ3TLMS TLST TM20 TM2X TMIC TMOT TR20 TSC"
"C TV10 TVJP TVMJ TY0NTY2C TY2NUCOD ULTIV210 V261 V655 VCR1 VCR2 VCR3 VCR4 VCR5 VCR6 VCR7 VCR8 VCR9VDCT VDOM VDTZ VGP"
"X VIDS VIFP VIVO VIXL VLV1 VP30 VP31 VP40VP50 VP60 VP61 VP62 VP70 VP80 VQC1 VQC2 VQJC VSSV VUUU VX1KVX2K VXSP VYU9 V"
"YUYWBVC WHAM WINX WJPG WMV1 WMV2 WMV3 WMVA WNV1 WVC1X263 X264 XLV0 XMPG XVIDXWV0 XWV1 XWV2 XWV3 XWV4 XWV5 XWV6 XWV7 "
"XWV8 XWV9XXANY16 Y411 Y41P Y444 Y8 YC12 YUV8 YUV9 YUVP YUY2 YUYV YV12 YV16YV92ZLIB ZMBV ZPEG ZYGO ZYYY");
if ( needle )
{
v1 = strchr(needle, 32);
result = 1LL;
if ( !v1 )
result = strstr(v3, needle) == 0LL;
}
else
{
fwrite("fourcc cannot be NULL", 1uLL, 0x15uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
check_fourcc(const char *fourcc)
{
 int ret = 0;
 const char valid_fourcc[] =
  "3IV1 3IV2 8BPS"
  "AASC ABYR ADV1 ADVJ AEMI AFLC AFLI AJPG AMPG ANIM AP41 ASLC"
  "ASV1 ASV2 ASVX AUR2 AURA AVC1 AVRN"
  "BA81 BINK BLZ0 BT20 BTCV BW10 BYR1 BYR2"
  "CC12 CDVC CFCC CGDI CHAM CJPG CMYK CPLA CRAM CSCD CTRX CVID"
  "CWLT CXY1 CXY2 CYUV CYUY"
  "D261 D263 DAVC DCL1 DCL2 DCL3 DCL4 DCL5 DIV3 DIV4 DIV5 DIVX"
  "DM4V DMB1 DMB2 DMK2 DSVD DUCK DV25 DV50 DVAN DVCS DVE2 DVH1"
  "DVHD DVSD DVSL DVX1 DVX2 DVX3 DX50 DXGM DXTC DXTN"
  "EKQ0 ELK0 EM2V ES07 ESCP ETV1 ETV2 ETVC"
  "FFV1 FLJP FMP4 FMVC FPS1 FRWA FRWD FVF1"
  "GEOX GJPG GLZW GPEG GWLT"
  "H260 H261 H262 H263 H264 H265 H266 H267 H268 H269"
  "HDYC HFYU HMCR HMRR"
  "I263 ICLB IGOR IJPG ILVC ILVR IPDV IR21 IRAW ISME"
  "IV30 IV31 IV32 IV33 IV34 IV35 IV36 IV37 IV38 IV39 IV40 IV41"
  "IV41 IV43 IV44 IV45 IV46 IV47 IV48 IV49 IV50"
  "JBYR JPEG JPGL"
  "KMVC"
  "L261 L263 LBYR LCMW LCW2 LEAD LGRY LJ11 LJ22 LJ2K LJ44 LJPG"
  "LMP2 LMP4 LSVC LSVM LSVX LZO1"
  "M261 M263 M4CC M4S2 MC12 MCAM MJ2C MJPG MMES MP2A MP2T MP2V"
  "MP42 MP43 MP4A MP4S MP4T MP4V MPEG MPG4 MPGI MR16 MRCA MRLE"
  "MSVC MSZH"
  "MTX1 MTX2 MTX3 MTX4 MTX5 MTX6 MTX7 MTX8 MTX9"
  "MVI1 MVI2 MWV1"
  "NAVI NDSC NDSM NDSP NDSS NDXC NDXH NDXP NDXS NHVU NTN1 NTN2"
  "NVDS NVHS"
  "NVS0 NVS1 NVS2 NVS3 NVS4 NVS5"
  "NVT0 NVT1 NVT2 NVT3 NVT4 NVT5"
  "PDVC PGVV PHMO PIM1 PIM2 PIMJ PIXL PJPG PVEZ PVMM PVW2"
  "QPEG QPEQ"
  "RGBT RLE RLE4 RLE8 RMP4 RPZA RT21 RV20 RV30 RV40 S422 SAN3"
  "SDCC SEDG SFMC SMP4 SMSC SMSD SMSV SP40 SP44 SP54 SPIG SQZ2"
  "STVA STVB STVC STVX STVY SV10 SVQ1 SVQ3"
  "TLMS TLST TM20 TM2X TMIC TMOT TR20 TSCC TV10 TVJP TVMJ TY0N"
  "TY2C TY2N"
  "UCOD ULTI"
  "V210 V261 V655 VCR1 VCR2 VCR3 VCR4 VCR5 VCR6 VCR7 VCR8 VCR9"
  "VDCT VDOM VDTZ VGPX VIDS VIFP VIVO VIXL VLV1 VP30 VP31 VP40"
  "VP50 VP60 VP61 VP62 VP70 VP80 VQC1 VQC2 VQJC VSSV VUUU VX1K"
  "VX2K VXSP VYU9 VYUY"
  "WBVC WHAM WINX WJPG WMV1 WMV2 WMV3 WMVA WNV1 WVC1"
  "X263 X264 XLV0 XMPG XVID"
  "XWV0 XWV1 XWV2 XWV3 XWV4 XWV5 XWV6 XWV7 XWV8 XWV9"
  "XXAN"
  "Y16 Y411 Y41P Y444 Y8 YC12 YUV8 YUV9 YUVP YUY2 YUYV YV12 YV16"
  "YV92"
  "ZLIB ZMBV ZPEG ZYGO ZYYY";
 if (!fourcc) {
  (void)fputs("fourcc cannot be NULL", stderr);
  return -1;
 }
 if (strchr(fourcc, ' ') || !strstr(valid_fourcc, fourcc))
  ret = 1;
 return ret;
}

canonical_original_code:
int check_fourcc(char *fourcc)
{
 int ret = 0;
 char valid_fourcc[] = "3IV1 3IV2 8BPS"
  "AASC ABYR ADV1 ADVJ AEMI AFLC AFLI AJPG AMPG ANIM AP41 ASLC"
  "ASV1 ASV2 ASVX AUR2 AURA AVC1 AVRN"
  "BA81 BINK BLZ0 BT20 BTCV BW10 BYR1 BYR2"
  "CC12 CDVC CFCC CGDI CHAM CJPG CMYK CPLA CRAM CSCD CTRX CVID"
  "CWLT CXY1 CXY2 CYUV CYUY"
  "D261 D263 DAVC DCL1 DCL2 DCL3 DCL4 DCL5 DIV3 DIV4 DIV5 DIVX"
  "DM4V DMB1 DMB2 DMK2 DSVD DUCK DV25 DV50 DVAN DVCS DVE2 DVH1"
  "DVHD DVSD DVSL DVX1 DVX2 DVX3 DX50 DXGM DXTC DXTN"
  "EKQ0 ELK0 EM2V ES07 ESCP ETV1 ETV2 ETVC"
  "FFV1 FLJP FMP4 FMVC FPS1 FRWA FRWD FVF1"
  "GEOX GJPG GLZW GPEG GWLT"
  "H260 H261 H262 H263 H264 H265 H266 H267 H268 H269"
  "HDYC HFYU HMCR HMRR"
  "I263 ICLB IGOR IJPG ILVC ILVR IPDV IR21 IRAW ISME"
  "IV30 IV31 IV32 IV33 IV34 IV35 IV36 IV37 IV38 IV39 IV40 IV41"
  "IV41 IV43 IV44 IV45 IV46 IV47 IV48 IV49 IV50"
  "JBYR JPEG JPGL"
  "KMVC"
  "L261 L263 LBYR LCMW LCW2 LEAD LGRY LJ11 LJ22 LJ2K LJ44 LJPG"
  "LMP2 LMP4 LSVC LSVM LSVX LZO1"
  "M261 M263 M4CC M4S2 MC12 MCAM MJ2C MJPG MMES MP2A MP2T MP2V"
  "MP42 MP43 MP4A MP4S MP4T MP4V MPEG MPG4 MPGI MR16 MRCA MRLE"
  "MSVC MSZH"
  "MTX1 MTX2 MTX3 MTX4 MTX5 MTX6 MTX7 MTX8 MTX9"
  "MVI1 MVI2 MWV1"
  "NAVI NDSC NDSM NDSP NDSS NDXC NDXH NDXP NDXS NHVU NTN1 NTN2"
  "NVDS NVHS"
  "NVS0 NVS1 NVS2 NVS3 NVS4 NVS5"
  "NVT0 NVT1 NVT2 NVT3 NVT4 NVT5"
  "PDVC PGVV PHMO PIM1 PIM2 PIMJ PIXL PJPG PVEZ PVMM PVW2"
  "QPEG QPEQ"
  "RGBT RLE RLE4 RLE8 RMP4 RPZA RT21 RV20 RV30 RV40 S422 SAN3"
  "SDCC SEDG SFMC SMP4 SMSC SMSD SMSV SP40 SP44 SP54 SPIG SQZ2"
  "STVA STVB STVC STVX STVY SV10 SVQ1 SVQ3"
  "TLMS TLST TM20 TM2X TMIC TMOT TR20 TSCC TV10 TVJP TVMJ TY0N"
  "TY2C TY2N"
  "UCOD ULTI"
  "V210 V261 V655 VCR1 VCR2 VCR3 VCR4 VCR5 VCR6 VCR7 VCR8 VCR9"
  "VDCT VDOM VDTZ VGPX VIDS VIFP VIVO VIXL VLV1 VP30 VP31 VP40"
  "VP50 VP60 VP61 VP62 VP70 VP80 VQC1 VQC2 VQJC VSSV VUUU VX1K"
  "VX2K VXSP VYU9 VYUY"
  "WBVC WHAM WINX WJPG WMV1 WMV2 WMV3 WMVA WNV1 WVC1"
  "X263 X264 XLV0 XMPG XVID"
  "XWV0 XWV1 XWV2 XWV3 XWV4 XWV5 XWV6 XWV7 XWV8 XWV9"
  "XXAN"
  "Y16 Y411 Y41P Y444 Y8 YC12 YUV8 YUV9 YUVP YUY2 YUYV YV12 YV16"
  "YV92"
  "ZLIB ZMBV ZPEG ZYGO ZYYY";
 if (!fourcc) {
  (void)fputs("fourcc cannot be NULL", stderr);
  return -1;
 }
 if (strchr(fourcc, ' ') || !strstr(valid_fourcc, fourcc))
  ret = 1;
 return ret;
}

variable_types:
fourcc
char *

variable_types: ret int


repo: Rolinh/yuvcutter

decompiled_code:
__int64 __fastcall check_yuvfile(char *s1)
{
char *v1; // rax
char *v2; // rbx
__int64 result; // rax

v1 = strrchr(s1, 46);
if ( !v1 || (v2 = v1, !strcasecmp(s1, v1)) )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(strcasecmp(v2 + 1, "yuv") != 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
char *v1; // rax
char *v2; // rbx
__int64 result; // rax

v1 = strrchr(s1, 46);
if ( !v1 || (v2 = v1, !strcasecmp(s1, v1)) )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(strcasecmp(v2 + 1, "yuv") != 0);
return result;
}

original_code:
int
check_yuvfile(const char *filename)
{
 char *ext;
 ext = strrchr(filename, '.');
 if (!ext || (strcasecmp(filename, ext) == 0))
  return -1;
 if (strcasecmp(ext + 1, "yuv") == 0)
  return 0;
 return -1;
}

canonical_original_code:
int check_yuvfile(char *filename)
{
 char *ext;
 ext = strrchr(filename, '.');
 if (!ext || (strcasecmp(filename, ext) == 0))
  return -1;
 if (strcasecmp(ext + 1, "yuv") == 0)
  return 0;
 return -1;
}

variable_types:
filename
char *

variable_types:
ext
char *

return_type: int


decompiled_code:
int __fastcall print_options(const char *a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, int a6, unsigned int a7)
{
int result; // eax

printf(" Input file name: %s\n", a1);
printf(" Height: %u\n", a2);
printf(" Width: %u\n", a3);
printf(" YUV mode: %u\n", a5);
result = printf(" Number of frames: %u\n", a7);
if ( !a6 )
{
printf(" # of frames to cut: %u\n", a4);
result = printf("Resulting number of frames: %u\n\n", a7 - a4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, int a6, unsigned int a7)
{
int result; // eax

printf(" Input file name: %s\n", a1);
printf(" Height: %u\n", a2);
printf(" Width: %u\n", a3);
printf(" YUV mode: %u\n", a5);
result = printf(" Number of frames: %u\n", a7);
if ( !a6 )
{
printf(" # of frames to cut: %u\n", a4);
result = printf("Resulting number of frames: %u\n\n", a7 - a4);
}
return result;
}

original_code:
void
print_options(const char *filename, unsigned int height, unsigned int width,
    unsigned int nb_frames, int yuv_mode, int countflag,
    unsigned int frame_count)
{
 (void)printf("           Input file name: %s\n", filename);
 (void)printf("                    Height: %u\n", height);
 (void)printf("                     Width: %u\n", width);
 (void)printf("                  YUV mode: %u\n", yuv_mode);
 (void)printf("          Number of frames: %u\n", frame_count);
 if (!countflag) {
  (void)printf("        # of frames to cut: %u\n", nb_frames);
  (void)printf("Resulting number of frames: %u\n\n",
        frame_count - nb_frames);
 }
}

canonical_original_code:
void print_options(char *filename, unsigned int height, unsigned int width, unsigned int nb_frames, int yuv_mode, int countflag, unsigned int frame_count)
{
 (void)printf("           Input file name: %s\n", filename);
 (void)printf("                    Height: %u\n", height);
 (void)printf("                     Width: %u\n", width);
 (void)printf("                  YUV mode: %u\n", yuv_mode);
 (void)printf("          Number of frames: %u\n", frame_count);
 if (!countflag) {
  (void)printf("        # of frames to cut: %u\n", nb_frames);
  (void)printf("Resulting number of frames: %u\n\n",
        frame_count - nb_frames);
 }
}

variable_types:
height
unsigned int

variable_types:
width
unsigned int

variable_types: countflag int

return_type: void


decompiled_code:
int __fastcall disp_perct_bar(double a1)
{
int v1; // ebx

v1 = 0;
putchar(91);
if ( a1 <= 0.0 )
goto LABEL_8;
do
{
v1 += 5;
putchar(35);
}
while ( a1 > (double)v1 );
if ( v1 <= 99 )
{
LABEL_8:
do
{
v1 += 5;
putchar(32);
}
while ( v1 <= 99 );
}
return putchar(93);
}

canonical_decompiled_code:
int __fastcall func2(double a1)
{
int v1; // ebx

v1 = 0;
putchar(91);
if ( a1 <= 0.0 )
goto LABEL_8;
do
{
v1 += 5;
putchar(35);
}
while ( a1 > (double)v1 );
if ( v1 <= 99 )
{
LABEL_8:
do
{
v1 += 5;
putchar(32);
}
while ( v1 <= 99 );
}
return putchar(93);
}

original_code:
void
disp_perct_bar(double perct)
{
 int i, j;
 int barinc = 5;
 (void)putchar('[');
 for (i = 0; i < perct; i += barinc)
  (void)putchar('#');
 for (j = i; j < 100; j += barinc)
  (void)putchar(' ');
 (void)putchar(']');
}

canonical_original_code:
void disp_perct_bar(double perct)
{
 int i; int j;
 int barinc = 5;
 (void)putchar('[');
 for (i = 0; i < perct; i += barinc)
  (void)putchar('#');
 for (j = i; j < 100; j += barinc)
  (void)putchar(' ');
 (void)putchar(']');
}

variable_types: perct double

variable_types: i int

variable_types: j int

variable_types: barinc int


usage

decompiled_code:
void __fastcall __noreturn usage(int status)
{
if ( status )
fwrite("Try yuvcutter -h for more info\n", 1uLL, 0x1FuLL, stderr);
else
puts(
"Usage:\n"
"yuvcutter [input.yuv] [OPTION(S)] [-C] [-H HEIGHT] [-M YUV_MODE] [-N NB_FRAMES] [-W WIDTH]\n"
"\n"
"Common options:\n"
"\t-h\t\tShow this help and exit\n"
"\t-v\t\tActivate verbose mode\n"
"\t-V\t\tShow program version and exit\n"
"\n"
"Specific options:\n"
"\t-C\t\tCount the number of frames in the input file\n"
"\t-H HEIGHT\tSpecify video height\n"
"\t-M YUV_MODE\tSpecify YUV mode (420, 422 or 444)\n"
"\t-N NB_FRAMES\tSpecify the number of frames to cut\n"
"\t-W WIDTH\tSpecify video width\n"
"\n"
"Read yuvcutter manual page for more details");
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(int status)
{
if ( status )
fwrite("Try yuvcutter -h for more info\n", 1uLL, 0x1FuLL, stderr);
else
puts(
"Usage:\n"
"yuvcutter [input.yuv] [OPTION(S)] [-C] [-H HEIGHT] [-M YUV_MODE] [-N NB_FRAMES] [-W WIDTH]\n"
"\n"
"Common options:\n"
"\t-h\t\tShow this help and exit\n"
"\t-v\t\tActivate verbose mode\n"
"\t-V\t\tShow program version and exit\n"
"\n"
"Specific options:\n"
"\t-C\t\tCount the number of frames in the input file\n"
"\t-H HEIGHT\tSpecify video height\n"
"\t-M YUV_MODE\tSpecify YUV mode (420, 422 or 444)\n"
"\t-N NB_FRAMES\tSpecify the number of frames to cut\n"
"\t-W WIDTH\tSpecify video width\n"
"\n"
"Read yuvcutter manual page for more details");
exit(status);
}

original_code:
void
usage(int status)
{
 if (status != 0)
  (void)fprintf(stderr, "Try yuvcutter -h for more info\n");
 else {
  (void)printf("Usage:\nyuvcutter [input.yuv] [OPTION(S)] [-C] "
        "[-H HEIGHT] [-M YUV_MODE] [-N NB_FRAMES] "
        "[-W WIDTH]\n\n"
   "Common options:\n"
   "\t-h\t\tShow this help and exit\n"
   "\t-v\t\tActivate verbose mode\n"
   "\t-V\t\tShow program version and exit\n\n"
   "Specific options:\n"
   "\t-C\t\tCount the number of frames in the input file\n"
   "\t-H HEIGHT\tSpecify video height\n"
   "\t-M YUV_MODE\tSpecify YUV mode (420, 422 or 444)\n"
   "\t-N NB_FRAMES\tSpecify the number of frames to cut\n"
   "\t-W WIDTH\tSpecify video width\n\n"
   "Read yuvcutter manual page for more details\n");
 }
 exit(status);
}

variable_types: status int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
unsigned int v4; // er12
int v5; // er15
unsigned int v6; // er13
int v7; // eax
unsigned int *v8; // rax
unsigned int *v9; // rbp
unsigned int v10; // eax
int v12; // [rsp+Ch] [rbp-4Ch]
int v13; // [rsp+10h] [rbp-48h]
int v14; // [rsp+14h] [rbp-44h]
int v15; // [rsp+18h] [rbp-40h]
int v16; // [rsp+1Ch] [rbp-3Ch]

v3 = (char *)argv[1];
if ( v3 )
{
if ( *v3 == 45 )
v3 = "input.yuv";
}
else
{
v3 = "input.yuv";
}
v14 = 1080;
v4 = 420;
v5 = 0;
v6 = 1;
v13 = 1920;
v15 = 0;
v12 = 0;
v16 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "hvCF:H:M:N:VW:");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'C':
v15 = 1;
break;
case 'H':
v14 = strtoul(optarg, 0LL, 10);
break;
case 'M':
v4 = strtol(optarg, 0LL, 10);
break;
case 'N':
v6 = strtoul(optarg, 0LL, 10);
break;
case 'V':
v12 = 1;
break;
case 'W':
v13 = strtoul(optarg, 0LL, 10);
break;
case 'h':
v5 = 1;
break;
case 'v':
v16 = 1;
break;
default:
usage(1);
}
}
if ( v12 )
{
v5 = 0;
printf("yuvcutter %s\n", "0.3.2");
return v5;
}
if ( v5 )
usage(0);
if ( (unsigned int)check_yuvfile(v3) == -1 )
{
v5 = 1;
fwrite("Please, choose a YUV file\n", 1uLL, 0x1AuLL, stderr);
return v5;
}
if ( (v4 & 0xFFFFFFFD) != 420 && v4 != 444 )
{
v5 = 1;
fprintf(stderr, "Please, choose either 420, 422 or 444 as YUV mode: %d is not supported\n", v4);
return v5;
}
v8 = (unsigned int *)count(v3, v14, v13, v4, v6);
v9 = v8;
if ( !v8 )
return 1;
v10 = *v8;
if ( v10 <= v6 )
{
fwrite(
"You cannot cut the same amount or more frames than there actually is in the video.\n",
1uLL,
0x53uLL,
stderr);
return 1;
}
if ( v16 )
print_options(v3, v14, v13, v6, v4, v15, v10);
if ( v15 )
{
printf("Number of frames in %s: %u\n", v3, *v9);
goto LABEL_25;
}
if ( (unsigned int)cut(v3, v14, v13, v6, v4, (__int64)v9) == -1 )
return 1;
LABEL_25:
free(v9);
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
unsigned int v4; // er12
int v5; // er15
unsigned int v6; // er13
int v7; // eax
unsigned int *v8; // rax
unsigned int *v9; // rbp
unsigned int v10; // eax
int v12; // [rsp+Ch] [rbp-4Ch]
int v13; // [rsp+10h] [rbp-48h]
int v14; // [rsp+14h] [rbp-44h]
int v15; // [rsp+18h] [rbp-40h]
int v16; // [rsp+1Ch] [rbp-3Ch]

v3 = (char *)argv[1];
if ( v3 )
{
if ( *v3 == 45 )
v3 = "input.yuv";
}
else
{
v3 = "input.yuv";
}
v14 = 1080;
v4 = 420;
v5 = 0;
v6 = 1;
v13 = 1920;
v15 = 0;
v12 = 0;
v16 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "hvCF:H:M:N:VW:");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'C':
v15 = 1;
break;
case 'H':
v14 = strtoul(optarg, 0LL, 10);
break;
case 'M':
v4 = strtol(optarg, 0LL, 10);
break;
case 'N':
v6 = strtoul(optarg, 0LL, 10);
break;
case 'V':
v12 = 1;
break;
case 'W':
v13 = strtoul(optarg, 0LL, 10);
break;
case 'h':
v5 = 1;
break;
case 'v':
v16 = 1;
break;
default:
func4(1);
}
}
if ( v12 )
{
v5 = 0;
printf("yuvcutter %s\n", "0.3.2");
return v5;
}
if ( v5 )
func4(0);
if ( (unsigned int)func0(v3) == -1 )
{
v5 = 1;
fwrite("Please, choose a YUV file\n", 1uLL, 0x1AuLL, stderr);
return v5;
}
if ( (v4 & 0xFFFFFFFD) != 420 && v4 != 444 )
{
v5 = 1;
fprintf(stderr, "Please, choose either 420, 422 or 444 as YUV mode: %d is not supported\n", v4);
return v5;
}
v8 = (unsigned int *)count(v3, v14, v13, v4, v6);
v9 = v8;
if ( !v8 )
return 1;
v10 = *v8;
if ( v10 <= v6 )
{
fwrite(
"You cannot cut the same amount or more frames than there actually is in the video.\n",
1uLL,
0x53uLL,
stderr);
return 1;
}
if ( v16 )
func1(v3, v14, v13, v6, v4, v15, v10);
if ( v15 )
{
printf("Number of frames in %s: %u\n", v3, *v9);
goto LABEL_25;
}
if ( (unsigned int)func3(v3, v14, v13, v6, v4, (__int64)v9) == -1 )
return 1;
LABEL_25:
free(v9);
return v5;
}

original_code:
int
main(int argc, char *argv[])
{
 int ch;
 int helpflag = 0;
 int verboseflag = 0;
 int versionflag = 0;
 int countflag = 0;
 unsigned int width = 1920;
 unsigned int height = 1080;
 unsigned int nb_frames = 1;
 int yuv_mode = 420;
 const char *filename = "input.yuv";
 struct yuv_file *video;
 if (argv[1] && argv[1][0] != '-') {
  filename = argv[1];
 }
 while ((ch = getopt(argc, argv, "hvCF:H:M:N:VW:")) != -1) {
  switch(ch) {
  case 'h':
   helpflag = 1;
   break;
  case 'v':
   verboseflag = 1;
   break;
  case 'C':
   countflag = 1;
   break;
  case 'H':
   height = (unsigned int)strtoul(optarg, ((void *)0), 10);
   break;
  case 'M':
   yuv_mode = (int)strtol(optarg, ((void *)0), 10);
   break;
  case 'N':
   nb_frames = (unsigned int)strtoul(optarg, ((void *)0), 10);
   break;
  case 'V':
   versionflag = 1;
   break;
  case 'W':
   width = (unsigned int)strtoul(optarg, ((void *)0), 10);
   break;
  default:
   usage(1);
  }
 }
 if (versionflag) {
  (void)printf("yuvcutter %s\n", "0.3.2");
  return 0;
 }
 if (helpflag)
  usage(0);
 if (check_yuvfile(filename) == -1) {
  (void)fprintf(stderr, "Please, choose a YUV file\n");
  return 1;
 }
 if (!(yuv_mode == 420 || yuv_mode == 422 || yuv_mode == 444)) {
  (void)fprintf(stderr, "Please, choose either 420, 422 or 444 as"
         " YUV mode: %d is not supported\n", yuv_mode);
  return 1;
 }
 if (!(video = count(filename, height, width, yuv_mode, nb_frames)))
  return 1;
 if (nb_frames >= video->frame_count) {
  (void)fprintf(stderr, "You cannot cut the same amount or more "
         "frames than there actually is in the video.\n");
  return 1;
 }
 if (verboseflag)
  print_options(filename, height, width, nb_frames, yuv_mode,
         countflag, video->frame_count);
 if (countflag) {
  (void)printf("Number of frames in %s: %u\n",
        filename, video->frame_count);
 } else {
  if (cut(filename, height, width, nb_frames, yuv_mode, video)
    == -1)
   return 1;
 }
 free(video);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int ch;
 int helpflag = 0;
 int verboseflag = 0;
 int versionflag = 0;
 int countflag = 0;
 unsigned int width = 1920;
 unsigned int height = 1080;
 unsigned int nb_frames = 1;
 int yuv_mode = 420;
 char *filename = "input.yuv";
 struct yuv_file *video;
 if (argv[1] && argv[1][0] != '-') {
  filename = argv[1];
 }
 while ((ch = getopt(argc, argv, "hvCF:H:M:N:VW:")) != -1) {
  switch(ch) {
  case 'h':
   helpflag = 1;
   break;
  case 'v':
   verboseflag = 1;
   break;
  case 'C':
   countflag = 1;
   break;
  case 'H':
   height = (unsigned int)strtoul(optarg, ((void *)0), 10);
   break;
  case 'M':
   yuv_mode = (int)strtol(optarg, ((void *)0), 10);
   break;
  case 'N':
   nb_frames = (unsigned int)strtoul(optarg, ((void *)0), 10);
   break;
  case 'V':
   versionflag = 1;
   break;
  case 'W':
   width = (unsigned int)strtoul(optarg, ((void *)0), 10);
   break;
  default:
   usage(1);
  }
 }
 if (versionflag) {
  (void)printf("yuvcutter %s\n", "0.3.2");
  return 0;
 }
 if (helpflag)
  usage(0);
 if (check_yuvfile(filename) == -1) {
  (void)fprintf(stderr, "Please, choose a YUV file\n");
  return 1;
 }
 if (!(yuv_mode == 420 || yuv_mode == 422 || yuv_mode == 444)) {
  (void)fprintf(stderr, "Please, choose either 420, 422 or 444 as"
         " YUV mode: %d is not supported\n", yuv_mode);
  return 1;
 }
 if (!(video = count(filename, height, width, yuv_mode, nb_frames)))
  return 1;
 if (nb_frames >= video->frame_count) {
  (void)fprintf(stderr, "You cannot cut the same amount or more "
         "frames than there actually is in the video.\n");
  return 1;
 }
 if (verboseflag)
  print_options(filename, height, width, nb_frames, yuv_mode,
         countflag, video->frame_count);
 if (countflag) {
  (void)printf("Number of frames in %s: %u\n",
        filename, video->frame_count);
 } else {
  if (cut(filename, height, width, nb_frames, yuv_mode, video)
    == -1)
   return 1;
 }
 free(video);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ch int

variable_types: helpflag int

variable_types: verboseflag int

variable_types: versionflag int

variable_types: struct yuv_file { unsigned int frame_count; long size_origin; long size_new; } *


repo: Rotwang/stuff

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
size_t v4; // rbp
unsigned int v5; // ebx
char *v6; // r15
int v7; // er13
__int64 v8; // rbp
int v9; // er12
char v10; // r14
char *v11; // rax
unsigned int v12; // edx
unsigned int buf[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v3 = time(0LL);
srand(v3);
v4 = atoi(argv[1]) % 0x7FFFFFFFu;
v5 = v4;
v6 = (char *)malloc(v4);
v7 = open("/dev/urandom", 0);
if ( (_DWORD)v4 )
memset(v6, 0, 4 * v4);
v8 = 0LL;
v9 = 1;
v10 = 0;
do
{
while ( 1 )
{
++v8;
read(v7, buf, 4uLL);
v12 = buf[0] % v5;
buf[0] = v12;
if ( v12 )
{
v11 = &v6[4 * v12];
if ( !*(_DWORD *)v11 && !v10 )
{
*(_DWORD *)v11 = 1;
v10 = 1;
}
goto LABEL_7;
}
if ( v10 )
break;
LABEL_7:
if ( v9 == v5 )
goto LABEL_11;
}
++v9;
v10 = 0;
}
while ( v9 != v5 );
LABEL_11:
printf("%llu\n", v8);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 srand(time(((void *)0)));
 pris_t prisoners_n = atoi(argv[1]);
 prisoners_n %= 2147483647;
 _Bool bulb_lit = 0;
 pris_t leader = 0;
 pris_t prisoner;
 pris_t counter = 1;
 pris_t *state = malloc(sizeof(_Bool) * prisoners_n);
 long long days = 0;
 int rand_fd = open("/dev/urandom", 00);
 for (pris_t i = 0; i < prisoners_n; i++)
  state[i] = 0;
 while (1) {
  ++days;
  read(rand_fd, (void *)&prisoner, sizeof(prisoner));
  prisoner %= prisoners_n;
  if (prisoner != leader) {
   if (state[prisoner] == 0 && bulb_lit == 0){
    bulb_lit = 1;
    state[prisoner] = 1;
   }
  } else {
   if (bulb_lit == 1) {
    bulb_lit = 0;
    ++counter;
   }
  }
  if (counter == prisoners_n) {
   printf("%llu\n", days);
   return 0;
  }
 }
}

canonical_original_code:
int main(int argc, char *argv[]) {
 srand(time(((void *)0)));
 unsigned int prisoners_n = atoi(argv[1]);
 prisoners_n %= 2147483647;
 _Bool bulb_lit = 0;
 unsigned int leader = 0;
 unsigned int prisoner;
 unsigned int counter = 1;
 unsigned int *state = malloc(sizeof(_Bool) * prisoners_n);
 long long days = 0;
 int rand_fd = open("/dev/urandom", 00);
 for (unsigned int i = 0; i < prisoners_n; i++)
  state[i] = 0;
 while (1) {
  ++days;
  read(rand_fd, (void *)&prisoner, sizeof(prisoner));
  prisoner %= prisoners_n;
  if (prisoner != leader) {
   if (state[prisoner] == 0 && bulb_lit == 0){
    bulb_lit = 1;
    state[prisoner] = 1;
   }
  } else {
   if (bulb_lit == 1) {
    bulb_lit = 0;
    ++counter;
   }
  }
  if (counter == prisoners_n) {
   printf("%llu\n", days);
   return 0;
  }
 }
}

variable_types:
leader
unsigned int

variable_types:
prisoner
unsigned int

variable_types:
counter
unsigned int

variable_types:
state
unsigned int *

variable_types:
days
long long

variable_types:
i
unsigned int


usage

repo: RowanMSEResearchLab/xutil

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("Usage: %s [-top] windowId\n", a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
printf("Usage: %s [-top] windowId\n", a1);
exit(0);
}

original_code:
void usage ( char * cmd) {
 printf ("Usage: %s [-top] windowId\n", cmd );
 exit ( 0 );
}

canonical_original_code:
void usage(char *cmd) {
 printf ("Usage: %s [-top] windowId\n", cmd );
 exit ( 0 );
}

variable_types:
cmd
char *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v4; // rbx
bool v5; // cf
bool v6; // zf
int v7; // er13
unsigned int v8; // er15
const char **v9; // r12
const char *v10; // rdi
__int64 v11; // rcx
const char *v12; // rsi

initialize(argc, argv, envp);
if ( argc > 1 )
{
v4 = argv + 1;
v5 = 0;
v6 = 1;
v7 = 0;
v8 = -1;
v9 = &argv[(unsigned int)(argc - 2) + 2];
do
{
while ( 1 )
{
v11 = 5LL;
v10 = "-top";
v12 = *v4;
do
{
if ( !v11 )
break;
v5 = *v12 < (unsigned int)*v10;
v6 = *v12++ == *v10++;
--v11;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
break;
v10 = *v4++;
v8 = atoi(v10);
v5 = v4 < v9;
v6 = v4 == v9;
if ( v4 == v9 )
goto LABEL_9;
}
++v4;
v7 = 1;
v5 = v4 < v9;
v6 = v4 == v9;
}
while ( v4 != v9 );
LABEL_9:
if ( v8 != -1 )
{
if ( v7 )
{
v12 = (const char *)(unsigned int)getRoot(v10, v12);
printf("Level 0 (root)--> %d\n", v12);
v8 = getAncestorBelowRoot(v8);
}
printTree(v8, v12);
exit(0);
}
}
usage(*argv);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v4; // rbx
bool v5; // cf
bool v6; // zf
int v7; // er13
unsigned int v8; // er15
const char **v9; // r12
const char *v10; // rdi
__int64 v11; // rcx
const char *v12; // rsi

initialize(argc, argv, envp);
if ( argc > 1 )
{
v4 = argv + 1;
v5 = 0;
v6 = 1;
v7 = 0;
v8 = -1;
v9 = &argv[(unsigned int)(argc - 2) + 2];
do
{
while ( 1 )
{
v11 = 5LL;
v10 = "-top";
v12 = *v4;
do
{
if ( !v11 )
break;
v5 = *v12 < (unsigned int)*v10;
v6 = *v12++ == *v10++;
--v11;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
break;
v10 = *v4++;
v8 = atoi(v10);
v5 = v4 < v9;
v6 = v4 == v9;
if ( v4 == v9 )
goto LABEL_9;
}
++v4;
v7 = 1;
v5 = v4 < v9;
v6 = v4 == v9;
}
while ( v4 != v9 );
LABEL_9:
if ( v8 != -1 )
{
if ( v7 )
{
v12 = (const char *)(unsigned int)getRoot(v10, v12);
printf("Level 0 (root)--> %d\n", v12);
v8 = getAncestorBelowRoot(v8);
}
printTree(v8, v12);
exit(0);
}
}
func0(*argv);
}

original_code:
void main ( int argc, char *argv[] ) {
 int topwid, i;
 int top;
 top = 0;
 topwid = -1;
 initialize ( );
 for (i = 1; i < argc; i++) {
  if (strcmp (argv[i], "-top") == 0)
   top = 1;
  else
   topwid = atoi (argv[i]);
 }
 if (topwid == -1)
  usage (argv[0]);
 if (top) {
  printf ("Level 0 (root)--> %d\n", getRoot());
  topwid = getAncestorBelowRoot ( topwid);
 }
 printTree ( topwid );
 exit ( 0 );
}

canonical_original_code:
void main(int argc, char *argv[]) {
 int topwid; int i;
 int top;
 top = 0;
 topwid = -1;
 initialize ( );
 for (i = 1; i < argc; i++) {
  if (strcmp (argv[i], "-top") == 0)
   top = 1;
  else
   topwid = atoi (argv[i]);
 }
 if (topwid == -1)
  usage (argv[0]);
 if (top) {
  printf ("Level 0 (root)--> %d\n", getRoot());
  topwid = getAncestorBelowRoot ( topwid);
 }
 printTree ( topwid );
 exit ( 0 );
}

variable_types: topwid int

variable_types: i int

variable_types: top int


assemblePath

repo: Rsoft-/libspk

decompiled_code:
char *__fastcall assemblePath(char *a1, const char *a2, const char *a3)
{
char *v4; // rax

v4 = stpcpy(a1, a2);
*v4 = 47;
return strcpy(v4 + 1, a3);
}

canonical_decompiled_code:
char *__fastcall func7(char *a1, const char *a2, const char *a3)
{
char *v4; // rax

v4 = stpcpy(a1, a2);
*v4 = 47;
return strcpy(v4 + 1, a3);
}

original_code:
void assemblePath(char* out, char* path, char* fileName) {
  strcpy(out, path);
  strcat(out, "/");
  strcat(out, fileName);
}

canonical_original_code:
void assemblePath(char *out, char *path, char *fileName) {
  strcpy(out, path);
  strcat(out, "/");
  strcat(out, fileName);
}

variable_types:
out
char *

variable_types:
path
char *

variable_types:
fileName
char *


parsequotastr

repo: Rupreht/cpquota

decompiled_code:
void __fastcall parsequotastr(const char *a1, __int64 a2)
{
const char *v2; // rbx
char v3; // al
__int64 v4; // rdx

v2 = a1;
*(_QWORD *)a2 = 0LL;
*(_DWORD *)(a2 + 8) = 0;
if ( a1 )
{
while ( 1 )
{
v3 = *v2;
if ( !*v2 )
break;
while ( (unsigned __int8)(v3 - 48) > 9u )
{
v3 = *++v2;
if ( !v3 )
return;
}
v4 = 0LL;
do
{
++v2;
v4 = (char)(v3 - 48) + 10 * v4;
v3 = *v2;
}
while ( (unsigned __int8)(*v2 - 48) <= 9u );
if ( v3 == 67 )
{
*(_DWORD *)(a2 + 8) = v4;
}
else if ( v3 == 83 )
{
*(_QWORD *)a2 = v4;
}
else
{
fprintf(stderr, "WARN: quota string '%s' not parseable\n", a1);
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(const char *a1, __int64 a2)
{
const char *v2; // rbx
char v3; // al
__int64 v4; // rdx

v2 = a1;
*(_QWORD *)a2 = 0LL;
*(_DWORD *)(a2 + 8) = 0;
if ( a1 )
{
while ( 1 )
{
v3 = *v2;
if ( !*v2 )
break;
while ( (unsigned __int8)(v3 - 48) > 9u )
{
v3 = *++v2;
if ( !v3 )
return;
}
v4 = 0LL;
do
{
++v2;
v4 = (char)(v3 - 48) + 10 * v4;
v3 = *v2;
}
while ( (unsigned __int8)(*v2 - 48) <= 9u );
if ( v3 == 67 )
{
*(_DWORD *)(a2 + 8) = v4;
}
else if ( v3 == 83 )
{
*(_QWORD *)a2 = v4;
}
else
{
fprintf(stderr, "WARN: quota string '%s' not parseable\n", a1);
}
}
}
}

original_code:
static void parsequotastr(const char *quota, struct maildirquota *q) {
    off_t i;
    const char *quota_start = quota;
    q->nbytes = 0;
    q->nmessages = 0;
    while (quota && *quota) {
        if (!( (*quota) >= '0' && (*quota) <= '9')) {
            ++quota;
            continue;
        }
        i = 0;
        while (( (*quota) >= '0' && (*quota) <= '9'))
            i = i * 10 + (*quota++ -'0');
        switch (*quota) {
            case 'S':
                q->nbytes = i;
                break;
            case 'C':
                q->nmessages = i;
                break;
            default:
                fprintf(stderr, "WARN: quota string '%s' not parseable\n",
                        quota_start);
                break;
        }
    }
}

canonical_original_code:
static void parsequotastr(char *quota, struct maildirquota *q) {
    long i;
    char *quota_start = quota;
    q->nbytes = 0;
    q->nmessages = 0;
    while (quota && *quota) {
        if (!( (*quota) >= '0' && (*quota) <= '9')) {
            ++quota;
            continue;
        }
        i = 0;
        while (( (*quota) >= '0' && (*quota) <= '9'))
            i = i * 10 + (*quota++ -'0');
        switch (*quota) {
            case 'S':
                q->nbytes = i;
                break;
            case 'C':
                q->nmessages = i;
                break;
            default:
                fprintf(stderr, "WARN: quota string '%s' not parseable\n",
                        quota_start);
                break;
        }
    }
}

variable_types:
quota
char *

variable_types: struct maildirquota { long nbytes; int nmessages; } *

variable_types: i long


decompiled_code:
__int64 __fastcall maildir_safeopen_stat(char *file, int a2, __int64 a3, struct stat *a4)
{
int v5; // eax
unsigned int v6; // er12
int v8; // edi
int v9; // edi
struct stat v10; // [rsp+0h] [rbp-B8h] BYREF

v5 = open(file, a2 | 0x800);
v6 = v5;
if ( v5 >= 0 )
{
if ( fcntl(v5, 4, a2 & 0x400) || fstat(v6, a4) || lstat(file, &v10) )
{
v8 = v6;
v6 = -1;
close(v8);
}
else if ( a4->st_dev != v10.st_dev || a4->st_ino != v10.st_ino )
{
v9 = v6;
v6 = -1;
close(v9);
*_errno_location() = 2;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *file, int a2, __int64 a3, struct stat *a4)
{
int v5; // eax
unsigned int v6; // er12
int v8; // edi
int v9; // edi
struct stat v10; // [rsp+0h] [rbp-B8h] BYREF

v5 = open(file, a2 | 0x800);
v6 = v5;
if ( v5 >= 0 )
{
if ( fcntl(v5, 4, a2 & 0x400) || fstat(v6, a4) || lstat(file, &v10) )
{
v8 = v6;
v6 = -1;
close(v8);
}
else if ( a4->st_dev != v10.st_dev || a4->st_ino != v10.st_ino )
{
v9 = v6;
v6 = -1;
close(v9);
*_errno_location() = 2;
}
}
return v6;
}

original_code:
int maildir_safeopen_stat(const char *path, int mode, int perm,
       struct stat *stat1)
{
 struct stat stat2;
 int fd=open(path, mode
   | 04000
   , perm);
 if (fd < 0) return (fd);
 if (fcntl(fd, 4, (mode & 02000)) || fstat(fd, stat1)
     || lstat(path, &stat2))
 {
  close(fd);
  return (-1);
 }
 if (stat1->st_dev != stat2.st_dev || stat1->st_ino != stat2.st_ino)
 {
  close(fd);
  (*__errno_location ())=2;
  return (-1);
 }
 return (fd);
}

canonical_original_code:
int maildir_safeopen_stat(char *path, int mode, int perm, struct stat *stat1)
{
 struct stat stat2;
 int fd = open(path, mode
   | 04000
   , perm);
 if (fd < 0) return (fd);
 if (fcntl(fd, 4, (mode & 02000)) || fstat(fd, stat1)
     || lstat(path, &stat2))
 {
  close(fd);
  return (-1);
 }
 if (stat1->st_dev != stat2.st_dev || stat1->st_ino != stat2.st_ino)
 {
  close(fd);
  (*__errno_location ())=2;
  return (-1);
 }
 return (fd);
}

variable_types: mode int

variable_types: perm int

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

variable_types: fd int

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


decompiled_code:
__int64 __fastcall maildir_safeopen(char *a1, int a2, __int64 a3)
{
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

return maildir_safeopen_stat(a1, a2, a3, &v4);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, int a2, __int64 a3)
{
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

return func1(a1, a2, a3, &v4);
}

original_code:
int maildir_safeopen(const char *path, int mode, int perm)
{
 struct stat stat1;
 return maildir_safeopen_stat(path, mode, perm, &stat1);
}

canonical_original_code:
int maildir_safeopen(char *path, int mode, int perm)
{
 struct stat stat1;
 return maildir_safeopen_stat(path, mode, perm, &stat1);
}

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


decompiled_code:
__int64 __fastcall maildir_openquotafile_init(__int64 a1, const char *a2)
{
size_t v2; // rax
char *v3; // rax
char *v4; // r12
char *v5; // rax
unsigned int v6; // er13

v2 = strlen(a2);
v3 = (char *)malloc(v2 + 13);
*(_QWORD *)a1 = 0LL;
v4 = v3;
*(_QWORD *)(a1 + 208) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 216) >> 3));
*(_DWORD *)a1 = -1;
if ( !v3 )
return (unsigned int)-1;
v5 = strdup(a2);
*(_QWORD *)(a1 + 8) = v5;
if ( v5 )
{
*(_QWORD *)(a1 + 16) = v4;
strcpy(v4, a2);
strcat(v4, "/maildirsize");
v6 = do_maildir_openquotafile(a1, v4);
if ( v6 )
{
free(v4);
free(*(void **)(a1 + 8));
}
}
else
{
v6 = -1;
free(v4);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
size_t v2; // rax
char *v3; // rax
char *v4; // r12
char *v5; // rax
unsigned int v6; // er13

v2 = strlen(a2);
v3 = (char *)malloc(v2 + 13);
*(_QWORD *)a1 = 0LL;
v4 = v3;
*(_QWORD *)(a1 + 208) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 216) >> 3));
*(_DWORD *)a1 = -1;
if ( !v3 )
return (unsigned int)-1;
v5 = strdup(a2);
*(_QWORD *)(a1 + 8) = v5;
if ( v5 )
{
*(_QWORD *)(a1 + 16) = v4;
strcpy(v4, a2);
strcat(v4, "/maildirsize");
v6 = func3(a1, v4);
if ( v6 )
{
free(v4);
free(*(void **)(a1 + 8));
}
}
else
{
v6 = -1;
free(v4);
}
return v6;
}

original_code:
int maildir_openquotafile_init(struct maildirsize *info,
        const char *maildir) {
    int rc;
    char *buf=(char *)malloc(strlen(maildir)+sizeof("/maildirsize"));
    memset(info, 0, sizeof (*info));
    info->fd = -1;
    if (!buf)
        return (-1);
    info->maildir=strdup(maildir);
    if (!info->maildir)
    {
        free(buf);
        return (-1);
    }
    strcat(strcpy(info->maildirsizefile = buf, maildir), "/maildirsize");
    rc = do_maildir_openquotafile(info, buf);
    if (rc == 0)
        return (0);
    free(buf);
    free(info->maildir);
    return (rc);
}

canonical_original_code:
int maildir_openquotafile_init(struct maildirsize *info, char *maildir) {
    int rc;
    char *buf = (char *)malloc(strlen(maildir)+sizeof("/maildirsize"));
    memset(info, 0, sizeof (*info));
    info->fd = -1;
    if (!buf)
        return (-1);
    info->maildir=strdup(maildir);
    if (!info->maildir)
    {
        free(buf);
        return (-1);
    }
    strcat(strcpy(info->maildirsizefile = buf, maildir), "/maildirsize");
    rc = do_maildir_openquotafile(info, buf);
    if (rc == 0)
        return (0);
    free(buf);
    free(info->maildir);
    return (rc);
}

variable_types: struct maildirsize { int fd; char *maildir; char *maildirsizefile; struct maildirquota { long nbytes; int nmessages; } quota; struct maildirquota size; int recalculation_needed; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } statbuf; unsigned int nlines; } *

variable_types:
maildir
char *

variable_types: rc int

variable_types:
buf
char *

user_defined_types: struct maildirsize { int fd; char *maildir; char *maildirsizefile; struct maildirquota quota; struct maildirquota size; int recalculation_needed; struct stat statbuf; unsigned int nlines; }


decompiled_code:
void __fastcall maildir_closequotafile(__int64 a1)
{
void *v2; // rdi
void *v3; // rdi
int v4; // edi

v2 = *(void **)(a1 + 8);
if ( v2 )
free(v2);
v3 = *(void **)(a1 + 16);
*(_QWORD *)(a1 + 8) = 0LL;
if ( v3 )
free(v3);
v4 = *(_DWORD *)a1;
*(_QWORD *)(a1 + 16) = 0LL;
if ( v4 >= 0 )
close(v4);
*(_DWORD *)a1 = -1;
}

original_code:
void maildir_closequotafile(struct maildirsize *info) {
 if (info->maildir)
  free (info->maildir);
 info->maildir=((void *)0);
 if (info->maildirsizefile)
  free (info->maildirsizefile);
 info->maildirsizefile=((void *)0);
 if (info->fd >= 0)
  close(info->fd);
 info->fd= -1;
}

user_defined_types: struct maildirquota { long nbytes; int nmessages; }

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


malloc

repo: RuslanKutdusov/usefull

decompiled_code:
__int64 __fastcall malloc(__int64 a1)
{
if ( !malloc_orig )
malloc_orig = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "malloc");
printf("malloc %lu\n", a1);
return malloc_orig(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( !malloc_orig )
malloc_orig = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "malloc");
printf("malloc %lu\n", a1);
return malloc_orig(a1);
}

original_code:
void* malloc( size_t size )
{
 if( malloc_orig == ((void *)0) )
  malloc_orig = dlsym( ((void *) -1l), "malloc" );
 printf("malloc %lu\n", size );
 return malloc_orig( size );
}

canonical_original_code:
void *malloc(unsigned long size)
{
 if( malloc_orig == ((void *)0) )
  malloc_orig = dlsym( ((void *) -1l), "malloc" );
 printf("malloc %lu\n", size );
 return malloc_orig( size );
}

variable_types:
size
unsigned long

return_type: void *


free

decompiled_code:
__int64 __fastcall free(__int64 a1)
{
if ( !free_orig )
free_orig = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "free");
puts("free");
return free_orig(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
if ( !free_orig )
free_orig = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "free");
puts("free");
return free_orig(a1);
}

original_code:
void free( void* ptr )
{
 if( free_orig == ((void *)0) )
  free_orig = dlsym( ((void *) -1l), "free" );
 printf("free\n" );
 free_orig( ptr );
}

canonical_original_code:
void free(void *ptr)
{
 if( free_orig == ((void *)0) )
  free_orig = dlsym( ((void *) -1l), "free" );
 printf("free\n" );
 free_orig( ptr );
}

variable_types:
ptr
void *


calloc

decompiled_code:
__int64 __fastcall calloc(__int64 a1, __int64 a2)
{
puts("calloc");
if ( !calloc_orig )
calloc_orig = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "calloc");
printf("calloc %lu\n", a2 * a1);
return calloc_orig(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
puts("calloc");
if ( !calloc_orig )
calloc_orig = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "calloc");
printf("calloc %lu\n", a2 * a1);
return calloc_orig(a1, a2);
}

original_code:
void* calloc( size_t nmemb, size_t size )
{
 printf("calloc\n");
 if( calloc_orig == ((void *)0) )
  calloc_orig = dlsym( ((void *) -1l), "calloc" );
 printf("calloc %lu\n", nmemb * size );
 return calloc_orig( nmemb, size );
}

canonical_original_code:
void *calloc(unsigned long nmemb, unsigned long size)
{
 printf("calloc\n");
 if( calloc_orig == ((void *)0) )
  calloc_orig = dlsym( ((void *) -1l), "calloc" );
 printf("calloc %lu\n", nmemb * size );
 return calloc_orig( nmemb, size );
}

variable_types:
nmemb
unsigned long


realloc

decompiled_code:
__int64 __fastcall realloc(__int64 a1, __int64 a2)
{
if ( !realloc_orig )
realloc_orig = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "realloc");
printf("realloc %lu\n", a2);
return realloc_orig(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
if ( !realloc_orig )
realloc_orig = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "realloc");
printf("realloc %lu\n", a2);
return realloc_orig(a1, a2);
}

original_code:
void* realloc( void *ptr, size_t size )
{
 if( realloc_orig == ((void *)0) )
  realloc_orig = dlsym( ((void *) -1l), "realloc" );
 printf("realloc %lu\n", size );
 return realloc_orig( ptr, size );
}

canonical_original_code:
void *realloc(void *ptr, unsigned long size)
{
 if( realloc_orig == ((void *)0) )
  realloc_orig = dlsym( ((void *) -1l), "realloc" );
 printf("realloc %lu\n", size );
 return realloc_orig( ptr, size );
}


decompiled_code:
__int64 __fastcall get_os_name(__int64 a1, __int64 a2)
{
__int64 result; // rax

for ( result = 0LL; result != 8; ++result )
*(_BYTE *)(a1 + result) = *(_BYTE *)(a2 + result + 3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 result; // rax

for ( result = 0LL; result != 8; ++result )
*(_BYTE *)(a1 + result) = *(_BYTE *)(a2 + result + 3);
return result;
}

original_code:
void get_os_name(char *os_name, char *mmap) {
 int i;
 for(i = 0; i < 8; i++) {
  os_name[i] = mmap[3+i];
 }
}

variable_types:
mmap
char *

variable_types: i int


decompiled_code:
__int64 __fastcall get_sectors_per_cluster(__int64 a1)
{
return (unsigned int)*(char *)(a1 + 13);
}

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

original_code:
int get_sectors_per_cluster(char *mmap) {
 return mmap[13];
}


decompiled_code:
__int64 __fastcall get_total_fats(__int64 a1)
{
return (unsigned int)*(char *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return (unsigned int)*(char *)(a1 + 16);
}

original_code:
int get_total_fats(char *mmap) {
 return mmap[16];
}


decompiled_code:
__int64 __fastcall get_two_byte_value(__int64 a1, int a2)
{
return *(unsigned __int8 *)(a1 + a2) + (*(unsigned __int8 *)(a1 + a2 + 1) << 8);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
return *(unsigned __int8 *)(a1 + a2) + (*(unsigned __int8 *)(a1 + a2 + 1) << 8);
}

original_code:
int get_two_byte_value(char *mmap, int offset) {
 int *tmp1 = malloc(sizeof(int));
 int *tmp2 = malloc(sizeof(int));
 int retVal;
 * tmp1 = (unsigned char) mmap[offset];
 * tmp2 = (unsigned char) mmap[offset + 1];
 retVal = *tmp1 + ((*tmp2) << 8);
 free(tmp1);
 free(tmp2);
 return retVal;
}

variable_types: offset int

variable_types: retVal int


decompiled_code:
__int64 __fastcall get_total_sectors(__int64 a1)
{
return get_two_byte_value(a1, 19);
}

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

original_code:
int get_total_sectors(char *mmap) {
 return get_two_byte_value(mmap, 19);
}


decompiled_code:
__int64 __fastcall get_bytes_per_sector(__int64 a1)
{
return get_two_byte_value(a1, 11);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return func10(a1, 11);
}

original_code:
int get_bytes_per_sector(char *mmap) {
 return get_two_byte_value(mmap, 11);
}


decompiled_code:
__int64 __fastcall get_disk_label(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // r8
__int64 v4; // r9
int v5; // er10
__int64 v6; // r11
int v7; // esi
__int64 v8; // rax
__int64 v9; // rcx
int v10; // esi
__int64 result; // rax
char v12; // dl
int v13; // edi
__int64 v14; // rdi

v2 = get_bytes_per_sector(a2);
v6 = v2;
v7 = 19 * v2;
v8 = 19 * v2;
v9 = v4 + v8 + 512;
v10 = v7 - (v4 + v8);
while ( 2 )
{
result = v9 - 512;
do
{
v12 = *(_BYTE *)(result + 11);
v13 = v10 + result;
if ( (v12 & 8) != 0 && (v12 & 0xF) != 15 )
{
result = 0LL;
v14 = v4 + v13;
do
{
*(_BYTE *)(v3 + result) = *(_BYTE *)(v14 + result);
++result;
}
while ( result != 11 );
return result;
}
result += 32LL;
}
while ( result != v9 );
v9 += v6;
if ( --v5 )
continue;
break;
}
return result;
}

original_code:
void get_disk_label(char *disk_label, char *mmap) {
 int bytes_per_sector = get_bytes_per_sector(mmap);
 int i;
 for (i = 19; i <= 32; i ++) {
  int j = 0;
  for (j = 0; j < 16; j++) {
   int attributeValue = mmap[(i * bytes_per_sector) + (j * 32) + 11];
   if ((attributeValue & 0x08) == 0x08 && (attributeValue & 0x0F) != 0x0F) {
    int k;
    for(k = 0; k < 11; k++) {
     disk_label[k] = mmap[(i * bytes_per_sector) + (j * 32) + k];
    }
    return;
   }
  }
 }
}

variable_types: j int

variable_types: attributeValue int

variable_types: k int


decompiled_code:
__int64 __fastcall get_total_size(__int64 a1)
{
int v1; // eax
int v2; // ecx

get_total_sectors(a1);
v1 = get_bytes_per_sector(a1);
return (unsigned int)(v2 * v1);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
int v1; // eax
int v2; // ecx

func11(a1);
v1 = func12(a1);
return (unsigned int)(v2 * v1);
}

original_code:
int get_total_size(char *mmap) {
 return get_total_sectors(mmap) * get_bytes_per_sector(mmap);
}


original_code:
int get_free_size(char *mmap) {
 int bytes_per_sector = get_bytes_per_sector(mmap);
 int free_sectors = 0;
 int i;
 for (i = 2; i <= 2848; i ++) {
  int *tmp1 = malloc(sizeof(int));
  int *tmp2 = malloc(sizeof(int));
  int result = 0;
  if (i % 2 == 0) {
   *tmp1 = (unsigned char) mmap[512 + (3*i)/2];
   *tmp2 = (unsigned char) mmap[513 + (3*i)/2];
   *tmp2 = *tmp2 & 0x0F;
   result = *tmp1 + (*tmp2 << 8);
  } else {
   *tmp1 = (unsigned char) mmap[512 + (3*i)/2];
   *tmp1 = *tmp1 & 0xF0;
   *tmp2 = (unsigned char) mmap[513 + (3*i)/2];
   result = (*tmp1 >> 4) + (*tmp2 << 4);
  }
  if (result == 0x00) {
   free_sectors ++;
  }
 }
 printf("Free sectors: %d\n", free_sectors);
 return free_sectors * bytes_per_sector;
}

variable_types: result int


original_code:
int get_total_files_in_root(char *mmap) {
 int bytes_per_sector = get_bytes_per_sector(mmap);
 int files = 0;
 int i;
 for (i = 19; i <= 32; i ++) {
  int j = 0;
  for (j = 0; j < 16; j++) {
   int attributeValue = mmap[(i * bytes_per_sector) + (j * 32) + 11];
   if (mmap[(i * bytes_per_sector) + (j * 32)] == 0x00) {
    return files;
   }
   if ((attributeValue & 0x0F) != 0x0F && (attributeValue & 0x08) != 0x08 && (attributeValue & 0x10) != 0x10) {
    files ++;
   }
  }
 }
 return files;
}

variable_types: files int


decompiled_code:
__int64 __fastcall get_sectors_per_fat(__int64 a1)
{
return get_two_byte_value(a1, 22);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return func10(a1, 22);
}

original_code:
int get_sectors_per_fat(char *mmap) {
 return get_two_byte_value(mmap, 22);
}


decompiled_code:
__int64 __fastcall get_max_root_directory_entries(__int64 a1)
{
return get_two_byte_value(a1, 17);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return func10(a1, 17);
}

original_code:
int get_max_root_directory_entries(char *mmap) {
 return get_two_byte_value(mmap, 17);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char *v4; // r13
const char *v5; // r14
int v6; // eax
int v7; // er12
void *v8; // rbp
unsigned int v9; // ebx
unsigned int v10; // er15
int result; // eax
unsigned int v12; // [rsp+8h] [rbp-D0h]
unsigned int v13; // [rsp+Ch] [rbp-CCh]
struct stat stat_buf; // [rsp+10h] [rbp-C8h] BYREF

if ( argc == 2 )
{
v3 = argv[1];
v4 = (char *)malloc(8uLL);
v5 = (const char *)malloc(0xBuLL);
v6 = open(v3, 0);
v7 = v6;
if ( !v6 )
{
perror("Error opening file for reading");
exit(1);
}
fstat(v6, &stat_buf);
v8 = mmap(0LL, stat_buf.st_size, 1, 1, v7, 0LL);
get_os_name(v4, v8);
get_disk_label(v5);
v13 = get_total_size(v8);
v9 = get_total_fats();
v10 = get_sectors_per_fat();
v12 = get_free_size();
LODWORD(v8) = get_total_files_in_root(v8);
printf("OS Name: %s\n", v4);
printf("Label of the disk: %s\n", v5);
printf("Total size of the disk: %d\n", v13);
printf("Free size on the disk: %d\n", v12);
puts("==========================================");
printf("Number of files in the root directory: %d\n", (unsigned int)v8);
puts("==========================================");
printf("Number of FAT copies: %d\n", v9);
printf("Sectors per FAT: %d\n", v10);
free(v4);
close(v7);
result = 0;
}
else
{
fwrite("Usage: diskinfo <file system image>\n", 1uLL, 0x24uLL, _bss_start);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char *v4; // r13
const char *v5; // r14
int v6; // eax
int v7; // er12
void *v8; // rbp
unsigned int v9; // ebx
unsigned int v10; // er15
int result; // eax
unsigned int v12; // [rsp+8h] [rbp-D0h]
unsigned int v13; // [rsp+Ch] [rbp-CCh]
struct stat stat_buf; // [rsp+10h] [rbp-C8h] BYREF

if ( argc == 2 )
{
v3 = argv[1];
v4 = (char *)malloc(8uLL);
v5 = (const char *)malloc(0xBuLL);
v6 = open(v3, 0);
v7 = v6;
if ( !v6 )
{
perror("Error opening file for reading");
exit(1);
}
func21(v6, &stat_buf);
v8 = mmap(0LL, stat_buf.st_size, 1, 1, v7, 0LL);
func7(v4, v8);
func13(v5);
v13 = func14(v8);
v9 = func9();
v10 = func17();
v12 = func15();
LODWORD(v8) = func16(v8);
printf("OS Name: %s\n", v4);
printf("Label of the disk: %s\n", v5);
printf("Total size of the disk: %d\n", v13);
printf("Free size on the disk: %d\n", v12);
puts("==========================================");
printf("Number of files in the root directory: %d\n", (unsigned int)v8);
puts("==========================================");
printf("Number of FAT copies: %d\n", v9);
printf("Sectors per FAT: %d\n", v10);
free(v4);
close(v7);
result = 0;
}
else
{
fwrite("Usage: diskinfo <file system image>\n", 1uLL, 0x24uLL, _bss_start);
result = -1;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
 if(argc != 2)
 {
  fprintf(stderr, "Usage: diskinfo <file system image>\n");
  return -1;
 }
 char *file_system_image = argv[1];
 char *os_name = malloc(sizeof(char) * 8);
 char *disk_label = malloc(sizeof(char) * 11);
 int disk_size_total = 0;
 int disk_size_free = 0;
 int num_files_in_root = 0;
 int num_fat_copies = 0;
 int sectors_per_fat = 0;
 int fd;
 struct stat file_stats;
 char *map;
 if ((fd = open(file_system_image, 00))) {
  fstat(fd, &file_stats);
  map = mmap(((void *)0), file_stats.st_size, 0x1, 0x01, fd, 0);
  get_os_name(os_name, map);
  get_disk_label(disk_label, map);
  disk_size_total = get_total_size(map);
  num_fat_copies = get_total_fats(map);
  sectors_per_fat = get_sectors_per_fat(map);
  disk_size_free = get_free_size(map);
  num_files_in_root = get_total_files_in_root(map);
 } else {
  perror("Error opening file for reading");
  exit(1);
 }
 printf("OS Name: %s\n", os_name);
 printf("Label of the disk: %s\n", disk_label);
 printf("Total size of the disk: %d\n", disk_size_total);
 printf("Free size on the disk: %d\n", disk_size_free);
 printf("==========================================\n");
 printf("Number of files in the root directory: %d\n", num_files_in_root);
 printf("==========================================\n");
 printf("Number of FAT copies: %d\n", num_fat_copies);
 printf("Sectors per FAT: %d\n", sectors_per_fat);
 free(os_name);
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: fd int

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

variable_types:
map
char *


decompiled_code:
__pid_t __fastcall sigchld_handler(unsigned int a1)
{
__pid_t result; // eax

while ( 1 )
{
result = waitpid(-1, 0LL, 1);
if ( result <= 0 )
break;
printf("\nSIGCHLD handler activated. Received signal %d\n", a1);
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func7(unsigned int a1)
{
__pid_t result; // eax

while ( 1 )
{
result = waitpid(-1, 0LL, 1);
if ( result <= 0 )
break;
printf("\nSIGCHLD handler activated. Received signal %d\n", a1);
}
return result;
}

original_code:
static void sigchld_handler (int signal)
{
 while (waitpid(-1, ((void *)0), 1) > 0) {
  if (1) printf("\nSIGCHLD handler activated. Received signal %d\n", signal);
 }
}

canonical_original_code:
static void sigchld_handler(int signal)
{
 while (waitpid(-1, ((void *)0), 1) > 0) {
  if (1) printf("\nSIGCHLD handler activated. Received signal %d\n", signal);
 }
}

variable_types: signal int


decompiled_code:
void go_home()
{
char *v0; // rbp

v0 = getenv("HOME");
printf("User's home directory: %s\n", v0);
if ( chdir(v0) < 0 )
perror("Error on chdir");
}

canonical_decompiled_code:
void func8()
{
char *v0; // rbp

v0 = getenv("HOME");
printf("User's home directory: %s\n", v0);
if ( chdir(v0) < 0 )
perror("Error on chdir");
}

original_code:
void go_home() {
 char *home_dir = getenv("HOME");
  if (1) printf("User's home directory: %s\n", home_dir);
  if (chdir(home_dir) < 0) perror ("Error on chdir");
}


decompiled_code:
void __fastcall change_directory(char *path)
{
if ( path && (*path != 126 || path[1]) )
{
printf("Changing to directory: %s\n", path);
if ( chdir(path) < 0 )
perror("Error on chdir");
}
else
{
go_home();
}
}

canonical_decompiled_code:
void __fastcall func9(char *path)
{
if ( path && (*path != 126 || path[1]) )
{
printf("Changing to directory: %s\n", path);
if ( chdir(path) < 0 )
perror("Error on chdir");
}
else
{
func8();
}
}

original_code:
void change_directory(char *directory) {
 if (directory == ((void *)0)) {
  go_home();
 } else if (strcmp(directory, "~") == 0) {
  go_home();
 } else {
  if (1) printf("Changing to directory: %s\n", directory);
  if (chdir(directory) < 0) perror ("Error on chdir");
 }
}

variable_types:
directory
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
size_t v4; // r15
char *v5; // rax
int v6; // eax
char *v7; // rax
const char *v8; // rbp
char *v9; // rdi
char **v10; // rbp
char *v11; // rbx
size_t v12; // r12
int v13; // er14
char **v14; // rax
char *v15; // r12
int v16; // er12
char **v17; // rax
__int64 v18; // rbx
const char *v19; // rdx
__int64 v20; // rsi
char *v21; // rax
__pid_t v22; // eax
__pid_t v23; // er13
__pid_t v24; // eax
__pid_t v25; // eax
__int64 v26; // rbx
__int64 v27; // rsi
char *ptr; // [rsp+8h] [rbp-F0h]
int stat_loc; // [rsp+1Ch] [rbp-DCh] BYREF
struct sigaction v31; // [rsp+20h] [rbp-D8h] BYREF

v31.sa_handler = (__sighandler_t)sigchld_handler;
memset(&v31.sa_mask, 0, 0x90uLL);
if ( !sigaction(17, &v31, 0LL) )
{
while ( 1 )
{
while ( 1 )
{
do
{
v3 = 0;
v4 = 0LL;
v5 = getcwd(0LL, 0LL);
v6 = snprintf(0LL, 0LL, "RSI: %s > ", v5);
ptr = (char *)malloc(v6 + 1);
v7 = getcwd(0LL, 0LL);
sprintf(ptr, "RSI: %s > ", v7);
v8 = (const char *)readline();
printf("Command: %s\n", v8);
v9 = (char *)v8;
v10 = 0LL;
v11 = strtok(v9, " ");
}
while ( !v11 );
do
{
v12 = v4 * 8;
++v4;
v13 = v3++;
v14 = (char **)realloc(v10, v4 * 8);
v15 = (char *)v14 + v12;
v10 = v14;
*(_QWORD *)v15 = v11;
v11 = strtok(0LL, " ");
}
while ( v11 );
if ( **(_BYTE **)v15 != 38 || *(_BYTE *)(*(_QWORD *)v15 + 1LL) )
{
v16 = 0;
v17 = (char **)realloc(v10, 8LL * (v13 + 2));
v17[v4] = 0LL;
v10 = v17;
}
else
{
v3 = v13;
puts("They want to run the process in the background!");
*(_QWORD *)v15 = 0LL;
v16 = 1;
}
v18 = 0LL;
do
{
v19 = v10[v18];
v20 = (unsigned int)v18++;
printf("Argument %d = %s\n", v20, v19);
}
while ( v3 >= (int)v18 );
if ( v3 )
{
v21 = *v10;
if ( **v10 == 99 && v21[1] == 100 && !v21[2] )
break;
}
v22 = fork();
v23 = v22;
if ( v22 < 0 )
{
perror("Error forking.");
exit(0);
}
if ( v22 )
{
v25 = getpid();
printf("PARENT: PID of Parent = %ld and PID of its child = %ld\n", v25, v23);
v26 = (unsigned int)waitpid(v23, &stat_loc, v16);
printf("PARENT: Return value of waitpid: %d\n", v26);
printf("PARENT: Child returned with status: %d\n", (unsigned int)stat_loc);
if ( (_DWORD)v26 == -1 )
{
perror("Fail on waitpid");
exit(1);
}
v27 = stat_loc & 0x7F;
if ( (stat_loc & 0x7F) != 0 )
{
if ( (char)(v27 + 1) > 1 )
{
printf("The child was killed by signal %d\n", v27);
}
else if ( (_BYTE)stat_loc == 127 )
{
printf("The child was stopped by delivery of signal %d\n", BYTE1(stat_loc));
}
else if ( stat_loc == 0xFFFF )
{
puts("The child was resumed by delivery of SIGCONT.");
}
}
else
{
printf("The child terminated normally, status code = %d\n", BYTE1(stat_loc));
}
}
else
{
v24 = getpid();
printf("CHILD: PID of Child = %ld\n", v24);
if ( execvp(*v10, v10) < 0 )
printf("%s: command not found\n", *v10);
}
LABEL_14:
setbuf(stdin, 0LL);
free(v10);
free(ptr);
}
if ( v3 <= 2 )
{
change_directory(v10[1]);
goto LABEL_14;
}
puts("Usage: cd [directory name]");
}
}
perror("sigaction");
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
size_t v4; // r15
char *v5; // rax
int v6; // eax
char *v7; // rax
const char *v8; // rbp
char *v9; // rdi
char **v10; // rbp
char *v11; // rbx
size_t v12; // r12
int v13; // er14
char **v14; // rax
char *v15; // r12
int v16; // er12
char **v17; // rax
__int64 v18; // rbx
const char *v19; // rdx
__int64 v20; // rsi
char *v21; // rax
__pid_t v22; // eax
__pid_t v23; // er13
__pid_t v24; // eax
__pid_t v25; // eax
__int64 v26; // rbx
__int64 v27; // rsi
char *ptr; // [rsp+8h] [rbp-F0h]
int stat_loc; // [rsp+1Ch] [rbp-DCh] BYREF
struct sigaction v31; // [rsp+20h] [rbp-D8h] BYREF

v31.sa_handler = (__sighandler_t)sigchld_handler;
memset(&v31.sa_mask, 0, 0x90uLL);
if ( !sigaction(17, &v31, 0LL) )
{
while ( 1 )
{
while ( 1 )
{
do
{
v3 = 0;
v4 = 0LL;
v5 = getcwd(0LL, 0LL);
v6 = snprintf(0LL, 0LL, "RSI: %s > ", v5);
ptr = (char *)malloc(v6 + 1);
v7 = getcwd(0LL, 0LL);
sprintf(ptr, "RSI: %s > ", v7);
v8 = (const char *)readline();
printf("Command: %s\n", v8);
v9 = (char *)v8;
v10 = 0LL;
v11 = strtok(v9, " ");
}
while ( !v11 );
do
{
v12 = v4 * 8;
++v4;
v13 = v3++;
v14 = (char **)realloc(v10, v4 * 8);
v15 = (char *)v14 + v12;
v10 = v14;
*(_QWORD *)v15 = v11;
v11 = strtok(0LL, " ");
}
while ( v11 );
if ( **(_BYTE **)v15 != 38 || *(_BYTE *)(*(_QWORD *)v15 + 1LL) )
{
v16 = 0;
v17 = (char **)realloc(v10, 8LL * (v13 + 2));
v17[v4] = 0LL;
v10 = v17;
}
else
{
v3 = v13;
puts("They want to run the process in the background!");
*(_QWORD *)v15 = 0LL;
v16 = 1;
}
v18 = 0LL;
do
{
v19 = v10[v18];
v20 = (unsigned int)v18++;
printf("Argument %d = %s\n", v20, v19);
}
while ( v3 >= (int)v18 );
if ( v3 )
{
v21 = *v10;
if ( **v10 == 99 && v21[1] == 100 && !v21[2] )
break;
}
v22 = fork();
v23 = v22;
if ( v22 < 0 )
{
perror("Error forking.");
exit(0);
}
if ( v22 )
{
v25 = getpid();
printf("PARENT: PID of Parent = %ld and PID of its child = %ld\n", v25, v23);
v26 = (unsigned int)waitpid(v23, &stat_loc, v16);
printf("PARENT: Return value of waitpid: %d\n", v26);
printf("PARENT: Child returned with status: %d\n", (unsigned int)stat_loc);
if ( (_DWORD)v26 == -1 )
{
perror("Fail on waitpid");
exit(1);
}
v27 = stat_loc & 0x7F;
if ( (stat_loc & 0x7F) != 0 )
{
if ( (char)(v27 + 1) > 1 )
{
printf("The child was killed by signal %d\n", v27);
}
else if ( (_BYTE)stat_loc == 127 )
{
printf("The child was stopped by delivery of signal %d\n", BYTE1(stat_loc));
}
else if ( stat_loc == 0xFFFF )
{
puts("The child was resumed by delivery of SIGCONT.");
}
}
else
{
printf("The child terminated normally, status code = %d\n", BYTE1(stat_loc));
}
}
else
{
v24 = getpid();
printf("CHILD: PID of Child = %ld\n", v24);
if ( execvp(*v10, v10) < 0 )
printf("%s: command not found\n", *v10);
}
LABEL_14:
setbuf(stdin, 0LL);
free(v10);
free(ptr);
}
if ( v3 <= 2 )
{
func9(v10[1]);
goto LABEL_14;
}
puts("Usage: cd [directory name]");
}
}
perror("sigaction");
return 1;
}

original_code:
int main()
{
 char * user_command;
 pid_t child_pid;
 int child_status;
 struct sigaction action;
 memset (&action, '\0', sizeof(action));
    action.__sigaction_handler.sa_handler = sigchld_handler;
 if (sigaction(17, &action, 0)) {
  perror ("sigaction");
  return 1;
 }
 int inputting = 1;
 while (inputting) {
  char * prompt = malloc(snprintf(((void *)0), 0, "RSI: %s > ", getcwd(0, 0)) + 1);
  sprintf(prompt, "RSI: %s > ", getcwd(0, 0));
  user_command = readline(prompt);
  if (1) printf("Command: %s\n", user_command);
  char **arguments = ((void *)0);
  int number_of_arguments = 0;
  int i;
  int background_process = 0;
  char *argument = strtok(user_command, " ");
  while (argument != ((void *)0)) {
   number_of_arguments ++;
   arguments = realloc (arguments, sizeof (char*) * number_of_arguments);
   arguments[number_of_arguments - 1] = argument;
   argument = strtok(((void *)0), " ");
  }
  if (number_of_arguments == 0) {
   continue;
  }
  if (strcmp(arguments[number_of_arguments - 1], "&") == 0) {
   background_process = 1;
   if (1) printf("They want to run the process in the background!\n");
   arguments[number_of_arguments - 1] = ((void *)0);
   number_of_arguments --;
  } else {
   arguments = realloc (arguments, sizeof (char*) * (number_of_arguments + 1));
   arguments[number_of_arguments] = ((void *)0);
  }
  if (1) {
   for (i = 0; i < (number_of_arguments + 1); i++)
    printf ("Argument %d = %s\n", i, arguments[i]);
  }
  if (number_of_arguments >= 1 && strcmp(arguments[0], "cd") == 0) {
   if (number_of_arguments > 2) {
    printf("Usage: cd [directory name]\n");
    continue;
   }
   change_directory(arguments[1]);
  } else {
   child_pid = fork();
   if (child_pid >= 0) {
    if (child_pid == 0) {
     if (1) printf("CHILD: PID of Child = %ld\n", (long) getpid());
     if (execvp(arguments[0], arguments) < 0) {
      printf("%s: command not found\n", arguments[0]);
     }
    } else {
     int opts = 0;
     if (background_process) {
      opts = 1;
     }
     int retVal;
     if (1) printf("PARENT: PID of Parent = %ld and PID of its child = %ld\n", (long) getpid(), (long) child_pid);
     retVal = waitpid(child_pid, &child_status, opts);
     if (1) printf("PARENT: Return value of waitpid: %d\n", retVal);
     if (1) printf("PARENT: Child returned with status: %d\n", child_status);
     if (retVal == -1) {
      perror("Fail on waitpid");
      exit(1);
     }
      if ((((child_status) & 0x7f) == 0)) {
      printf("The child terminated normally, status code = %d\n", (((child_status) & 0xff00) >> 8));
     } else if ((((signed char) (((child_status) & 0x7f) + 1) >> 1) > 0)) {
      printf("The child was killed by signal %d\n", ((child_status) & 0x7f));
     } else if ((((child_status) & 0xff) == 0x7f)) {
      printf("The child was stopped by delivery of signal %d\n", (((child_status) & 0xff00) >> 8));
     } else if (((child_status) == 0xffff)) {
      printf("The child was resumed by delivery of SIGCONT.\n");
     }
    }
   } else {
    perror("Error forking.");
    exit(0);
   }
  }
  setbuf(stdin, ((void *)0));
  free(arguments);
  free(prompt);
 }
}

canonical_original_code:
int main()
{
 char *user_command;
 int child_pid;
 int child_status;
 struct sigaction action;
 memset (&action, '\0', sizeof(action));
    action.__sigaction_handler.sa_handler = sigchld_handler;
 if (sigaction(17, &action, 0)) {
  perror ("sigaction");
  return 1;
 }
 int inputting = 1;
 while (inputting) {
  char *prompt = malloc(snprintf(((void *)0), 0, "RSI: %s > ", getcwd(0, 0)) + 1);
  sprintf(prompt, "RSI: %s > ", getcwd(0, 0));
  user_command = readline(prompt);
  if (1) printf("Command: %s\n", user_command);
  char **arguments = ((void *)0);
  int number_of_arguments = 0;
  int i;
  int background_process = 0;
  char *argument = strtok(user_command, " ");
  while (argument != ((void *)0)) {
   number_of_arguments ++;
   arguments = realloc (arguments, sizeof (char *) * number_of_arguments);
   arguments[number_of_arguments - 1] = argument;
   argument = strtok(((void *)0), " ");
  }
  if (number_of_arguments == 0) {
   continue;
  }
  if (strcmp(arguments[number_of_arguments - 1], "&") == 0) {
   background_process = 1;
   if (1) printf("They want to run the process in the background!\n");
   arguments[number_of_arguments - 1] = ((void *)0);
   number_of_arguments --;
  } else {
   arguments = realloc (arguments, sizeof (char *) * (number_of_arguments + 1));
   arguments[number_of_arguments] = ((void *)0);
  }
  if (1) {
   for (i = 0; i < (number_of_arguments + 1); i++)
    printf ("Argument %d = %s\n", i, arguments[i]);
  }
  if (number_of_arguments >= 1 && strcmp(arguments[0], "cd") == 0) {
   if (number_of_arguments > 2) {
    printf("Usage: cd [directory name]\n");
    continue;
   }
   change_directory(arguments[1]);
  } else {
   child_pid = fork();
   if (child_pid >= 0) {
    if (child_pid == 0) {
     if (1) printf("CHILD: PID of Child = %ld\n", (long) getpid());
     if (execvp(arguments[0], arguments) < 0) {
      printf("%s: command not found\n", arguments[0]);
     }
    } else {
     int opts = 0;
     if (background_process) {
      opts = 1;
     }
     int retVal;
     if (1) printf("PARENT: PID of Parent = %ld and PID of its child = %ld\n", (long) getpid(), (long) child_pid);
     retVal = waitpid(child_pid, &child_status, opts);
     if (1) printf("PARENT: Return value of waitpid: %d\n", retVal);
     if (1) printf("PARENT: Child returned with status: %d\n", child_status);
     if (retVal == -1) {
      perror("Fail on waitpid");
      exit(1);
     }
      if ((((child_status) & 0x7f) == 0)) {
      printf("The child terminated normally, status code = %d\n", (((child_status) & 0xff00) >> 8));
     } else if ((((char) (((child_status) & 0x7f) + 1) >> 1) > 0)) {
      printf("The child was killed by signal %d\n", ((child_status) & 0x7f));
     } else if ((((child_status) & 0xff) == 0x7f)) {
      printf("The child was stopped by delivery of signal %d\n", (((child_status) & 0xff00) >> 8));
     } else if (((child_status) == 0xffff)) {
      printf("The child was resumed by delivery of SIGCONT.\n");
     }
    }
   } else {
    perror("Error forking.");
    exit(0);
   }
  }
  setbuf(stdin, ((void *)0));
  free(arguments);
  free(prompt);
 }
}

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

variable_types: inputting int

variable_types:
prompt
char *

variable_types:
arguments
char **

variable_types:
argument
char *

variable_types: opts int

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

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


writec

repo: Ryu-chan/CLIB

decompiled_code:
bool __fastcall writec(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL) > 0;
}

canonical_decompiled_code:
bool __fastcall func0(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL) > 0;
}

original_code:
bool writec(
 char c
){
 return ( write(1,&c,1) > 0 );
}

canonical_original_code:
char writec(char c){
 return ( write(1,&c,1) > 0 );
}

variable_types: c char

return_type: char


fwritec

decompiled_code:
bool __fastcall fwritec(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return write(a1, buf, 1uLL) > 0;
}

canonical_decompiled_code:
bool __fastcall func1(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return write(a1, buf, 1uLL) > 0;
}

original_code:
bool fwritec(
 int fd,
 char c
){
 return ( write(fd,&c,1) > 0 );
}

canonical_original_code:
char fwritec(int fd, char c){
 return ( write(fd,&c,1) > 0 );
}


writes

decompiled_code:
__int64 __fastcall writes(char *a1)
{
char *v1; // rsi
_BYTE *v2; // rbx

if ( !a1 )
return 1LL;
v1 = a1;
if ( !*a1 )
return 1LL;
do
{
v2 = v1 + 1;
if ( write(1, v1, 1uLL) <= 0 )
return 0LL;
++v1;
}
while ( *v2 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char *v1; // rsi
_BYTE *v2; // rbx

if ( !a1 )
return 1LL;
v1 = a1;
if ( !*a1 )
return 1LL;
do
{
v2 = v1 + 1;
if ( write(1, v1, 1uLL) <= 0 )
return 0LL;
++v1;
}
while ( *v2 );
return 1LL;
}

original_code:
bool writes(
 const char* str
){
 if(str!=((void *)0))
  while(*str!='\0')
   if( write(1,str++,1) <= 0) return 0;
 return 1;
}

canonical_original_code:
char writes(char *str){
 if(str!=((void *)0))
  while(*str!='\0')
   if( write(1,str++,1) <= 0) return 0;
 return 1;
}

variable_types:
str
char *


fwrites

decompiled_code:
__int64 __fastcall fwrites(int fd, _BYTE *a2)
{
if ( !a2 )
return 1LL;
while ( 1 )
{
if ( !*a2 )
return 1LL;
if ( write(fd, a2, 1uLL) <= 0 )
break;
++a2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, _BYTE *a2)
{
if ( !a2 )
return 1LL;
while ( 1 )
{
if ( !*a2 )
return 1LL;
if ( write(fd, a2, 1uLL) <= 0 )
break;
++a2;
}
return 0LL;
}

original_code:
bool fwrites(
 int fd,
 const char* str
){
 if(str!=((void *)0))
  while(*str!='\0')
   if( write(fd,str++,1) <= 0) return 0;
 return 1;
}

canonical_original_code:
char fwrites(int fd, char *str){
 if(str!=((void *)0))
  while(*str!='\0')
   if( write(fd,str++,1) <= 0) return 0;
 return 1;
}


writef

decompiled_code:
bool __fastcall writef(__m128i a1)
{
float v1; // er14
bool result; // al

v1 = COERCE_FLOAT(_mm_cvtsi128_si32(a1));
if ( (unsigned __int8)writei((unsigned int)(int)*(float *)a1.m128i_i32) && (unsigned __int8)writec(46LL) )
result = (unsigned __int8)writei((unsigned int)(int)(float)((float)(v1 - (float)(int)*(float *)a1.m128i_i32)
* 100000.0)) != 0;
else
result = 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func0(__m128i a1)
{
float v1; // er14
bool result; // al

v1 = COERCE_FLOAT(_mm_cvtsi128_si32(a1));
if ( (unsigned __int8)writei((unsigned int)(int)*(float *)a1.m128i_i32) && (unsigned __int8)writec(46LL) )
result = (unsigned __int8)writei((unsigned int)(int)(float)((float)(v1 - (float)(int)*(float *)a1.m128i_i32)
* 100000.0)) != 0;
else
result = 0;
return result;
}

original_code:
bool writef(
 float f
){
 int part;
 part = (int)f;
 if(!writei(part)) return 0;
 if(!writec('.')) return 0;
 f-=part;
 part = ((int)(f*100000));
 if(!writei(part)) return 0;
 return 1;
}

canonical_original_code:
char writef(float f){
 int part;
 part = (int)f;
 if(!writei(part)) return 0;
 if(!writec('.')) return 0;
 f-=part;
 part = ((int)(f*100000));
 if(!writei(part)) return 0;
 return 1;
}

variable_types: f float

variable_types: part int


fwritef

decompiled_code:
bool __fastcall fwritef(__int64 a1, __m128i a2)
{
float v2; // ebx
bool result; // al

v2 = COERCE_FLOAT(_mm_cvtsi128_si32(a2));
if ( (unsigned __int8)fwritei(a1, (unsigned int)(int)*(float *)a2.m128i_i32)
&& (unsigned __int8)fwritec((unsigned int)a1, 46LL) )
{
result = (unsigned __int8)fwritei((unsigned int)a1, (unsigned int)(int)(float)(v2 * 100000.0)) != 0;
}
else
{
result = 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, __m128i a2)
{
float v2; // ebx
bool result; // al

v2 = COERCE_FLOAT(_mm_cvtsi128_si32(a2));
if ( (unsigned __int8)fwritei(a1, (unsigned int)(int)*(float *)a2.m128i_i32)
&& (unsigned __int8)fwritec((unsigned int)a1, 46LL) )
{
result = (unsigned __int8)fwritei((unsigned int)a1, (unsigned int)(int)(float)(v2 * 100000.0)) != 0;
}
else
{
result = 0;
}
return result;
}

original_code:
bool fwritef(
 int fd,
 float f
){
 int part;
 part = (int)f;
 if(!fwritei(fd,part)) return 0;
 if(!fwritec(fd,'.')) return 0;
 part = ((int)(f*100000));
 if(!fwritei(fd,part)) return 0;
 return 1;
}

canonical_original_code:
char fwritef(int fd, float f){
 int part;
 part = (int)f;
 if(!fwritei(fd,part)) return 0;
 if(!fwritec(fd,'.')) return 0;
 part = ((int)(f*100000));
 if(!fwritei(fd,part)) return 0;
 return 1;
}


writeb

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

if ( a1 )
result = writes("TRUE");
else
result = writes("FALSE");
return result;
}

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

if ( a1 )
result = writes("TRUE");
else
result = writes("FALSE");
return result;
}

original_code:
bool writeb(
 bool c
){
 if(c==0)
  return writes("FALSE");
 return writes("TRUE");
}

canonical_original_code:
char writeb(char c){
 if(c==0)
  return writes("FALSE");
 return writes("TRUE");
}


fwriteb

decompiled_code:
__int64 __fastcall fwriteb(__int64 a1, char a2)
{
__int64 result; // rax

if ( a2 )
result = fwrites(a1, "TRUE");
else
result = fwrites(a1, "FALSE");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
__int64 result; // rax

if ( a2 )
result = fwrites(a1, "TRUE");
else
result = fwrites(a1, "FALSE");
return result;
}

original_code:
bool fwriteb(
 int fd,
 bool c
){
 if(c==0)
  return fwrites(fd,"FALSE");
 return fwrites(fd,"TRUE");
}

canonical_original_code:
char fwriteb(int fd, char c){
 if(c==0)
  return fwrites(fd,"FALSE");
 return fwrites(fd,"TRUE");
}


xmalloc

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

result = malloc(a1);
if ( !result )
{
write(2, "Virtual Memory Exhausted\n", 0x19uLL);
exit(1);
}
return result;
}

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

result = malloc(a1);
if ( !result )
{
write(2, "Virtual Memory Exhausted\n", 0x19uLL);
exit(1);
}
return result;
}

original_code:
void* xmalloc(
 int n
){
 void* p;
 p = malloc(n);
 if (p == 0){
  write(2,"Virtual Memory Exhausted\n",25);
  exit(1);
 }
 return p;
}

canonical_original_code:
void *xmalloc(int n){
 void *p;
 p = malloc(n);
 if (p == 0){
  write(2,"Virtual Memory Exhausted\n",25);
  exit(1);
 }
 return p;
}

variable_types: n int

variable_types:
p
void *


writei

decompiled_code:
__int64 __fastcall writei(int a1)
{
int v1; // ebp
unsigned int v2; // er12
unsigned int v3; // ebx
int v4; // eax

v1 = abs32(a1);
v2 = v1;
if ( a1 >= 0 || (unsigned __int8)writec(45LL) )
{
v3 = 1;
if ( v1 > 9 )
{
do
v3 *= 10;
while ( v3 <= v1 / 0xAu );
}
while ( 1 )
{
v4 = v2 / v3 + 48;
v2 %= v3;
if ( !(unsigned __int8)writec((unsigned int)(char)v4) )
break;
v3 /= 0xAu;
if ( !v3 )
return 1LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // ebp
unsigned int v2; // er12
unsigned int v3; // ebx
int v4; // eax

v1 = abs32(a1);
v2 = v1;
if ( a1 >= 0 || (unsigned __int8)writec(45LL) )
{
v3 = 1;
if ( v1 > 9 )
{
do
v3 *= 10;
while ( v3 <= v1 / 0xAu );
}
while ( 1 )
{
v4 = v2 / v3 + 48;
v2 %= v3;
if ( !(unsigned __int8)writec((unsigned int)(char)v4) )
break;
v3 /= 0xAu;
if ( !v3 )
return 1LL;
}
}
return 0LL;
}

original_code:
bool writei(
 int n
){
 unsigned int i;
 i = (n < 0) ? -n : n;
 if (n < 0)
  if(!writec('-'))return 0;
 for (n = 1; n <= (i / 10); n *= 10)
  ;
 for (; n; i %= n, n /= 10)
  if(!writec('0' + (i / n)) )return 0;
 return 1;
}

canonical_original_code:
char writei(int n){
 unsigned int i;
 i = (n < 0) ? -n : n;
 if (n < 0)
  if(!writec('-'))return 0;
 for (n = 1; n <= (i / 10); n *= 10)
  ;
 for (; n; i %= n, n /= 10)
  if(!writec('0' + (i / n)) )return 0;
 return 1;
}

variable_types:
i
unsigned int


fwritei

decompiled_code:
__int64 __fastcall fwritei(__int64 a1, int a2)
{
int v2; // er12
unsigned int v3; // er13
unsigned int v4; // ebx
int v5; // eax

v2 = abs32(a2);
v3 = v2;
if ( a2 >= 0 || (unsigned __int8)fwritec(a1, 45LL) )
{
v4 = 1;
if ( v2 > 9 )
{
do
v4 *= 10;
while ( v4 <= v2 / 0xAu );
}
while ( 1 )
{
v5 = v3 / v4 + 48;
v3 %= v4;
if ( !(unsigned __int8)fwritec((unsigned int)a1, (unsigned int)(char)v5) )
break;
v4 /= 0xAu;
if ( !v4 )
return 1LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // er12
unsigned int v3; // er13
unsigned int v4; // ebx
int v5; // eax

v2 = abs32(a2);
v3 = v2;
if ( a2 >= 0 || (unsigned __int8)fwritec(a1, 45LL) )
{
v4 = 1;
if ( v2 > 9 )
{
do
v4 *= 10;
while ( v4 <= v2 / 0xAu );
}
while ( 1 )
{
v5 = v3 / v4 + 48;
v3 %= v4;
if ( !(unsigned __int8)fwritec((unsigned int)a1, (unsigned int)(char)v5) )
break;
v4 /= 0xAu;
if ( !v4 )
return 1LL;
}
}
return 0LL;
}

original_code:
bool fwritei(
 int fd,
 int n
){
 unsigned int i;
 i = (n < 0) ? -n : n;
 if (n < 0)
  if(!fwritec(fd,'-')) return 0;
 for (n = 1; n <= (i / 10); n *= 10)
  ;
 for (; n; i %= n, n /= 10)
  if(!fwritec(fd,'0' + (i / n)) )return 0;
 return 1;
}

canonical_original_code:
char fwritei(int fd, int n){
 unsigned int i;
 i = (n < 0) ? -n : n;
 if (n < 0)
  if(!fwritec(fd,'-')) return 0;
 for (n = 1; n <= (i / 10); n *= 10)
  ;
 for (; n; i %= n, n /= 10)
  if(!fwritec(fd,'0' + (i / n)) )return 0;
 return 1;
}

variable_types: fd int


original_code:
char* str_combine(
 char** vect,
 const char* delim
){
 int t;
 int c;
 int i;
 char* str;
 if(vect==((void *)0)||*vect==((void *)0))
  return ((void *)0);
 c=0;
 t=0;
 while(vect[t] !=((void *)0)){
  c+=(str_len(vect[t++])+1);
 }
 str = (char*)xmalloc( ((t-1)*str_len(delim)+(c)) *sizeof(char));
 t = 0;
 c = 0;
 i = 0;
 while(vect[t] != ((void *)0)){
  while(vect[t][i] != '\0'){
   str[c++] = vect[t][i++];
  }
  i=0;
  while(delim[i]!='\0'){
   str[c++] = delim[i++];
  }
  t++;
  i=0;
 }
 str[c-str_len(delim)] = '\0';
 return str;
}

canonical_original_code:
char *str_combine(char **vect, char *delim){
 int t;
 int c;
 int i;
 char *str;
 if(vect==((void *)0)||*vect==((void *)0))
  return ((void *)0);
 c=0;
 t=0;
 while(vect[t] !=((void *)0)){
  c+=(str_len(vect[t++])+1);
 }
 str = (char *)xmalloc( ((t-1)*str_len(delim)+(c)) *sizeof(char));
 t = 0;
 c = 0;
 i = 0;
 while(vect[t] != ((void *)0)){
  while(vect[t][i] != '\0'){
   str[c++] = vect[t][i++];
  }
  i=0;
  while(delim[i]!='\0'){
   str[c++] = delim[i++];
  }
  t++;
  i=0;
 }
 str[c-str_len(delim)] = '\0';
 return str;
}

variable_types:
vect
char **

variable_types:
delim
char *

variable_types: t int

variable_types: c int

variable_types: i int

return_type: char *


original_code:
int str_rev(
 char* str
){
 int b;
 int bb;
 b = str_len(str) + 1;
 bb = b - 1;
 while ( (b -= 2) > 0 ){
  (*str) ^= (str[b]);
  (str[b]) ^= (*str);
  (*str) ^= (str[b]);
  str++;
 }
 return bb;
}

canonical_original_code:
int str_rev(char *str){
 int b;
 int bb;
 b = str_len(str) + 1;
 bb = b - 1;
 while ( (b -= 2) > 0 ){
  (*str) ^= (str[b]);
  (str[b]) ^= (*str);
  (*str) ^= (str[b]);
  str++;
 }
 return bb;
}

variable_types: b int

variable_types: bb int


writee

decompiled_code:
__int64 writee()
{
return writec(10LL);
}

canonical_decompiled_code:
__int64 func0()
{
return writec(10LL);
}

original_code:
bool writee(
){
 return writec('\n');
}

canonical_original_code:
char writee(){
 return writec('\n');
}


fwritee

decompiled_code:
__int64 __fastcall fwritee(__int64 a1)
{
return fwritec(a1, 10LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return fwritec(a1, 10LL);
}

original_code:
bool fwritee(
 int fd
){
 return fwritec(fd,'\n');
}

canonical_original_code:
char fwritee(int fd){
 return fwritec(fd,'\n');
}


shift

repo: S-trace/eView

decompiled_code:
__int64 __fastcall shift(int a1, int a2, int *a3, int a4)
{
int v5; // er8
int *v7; // rax
int v10; // er11
int v11; // edx
int v12; // esi
int v13; // ecx
__int64 result; // rax
int v15; // edx

v5 = a4 * overlap / 100;
if ( a2 <= 1 )
return (unsigned int)(a4 - v5);
v7 = a3;
v10 = a1 + a4;
v11 = 0;
while ( 1 )
{
v12 = *v7;
if ( *v7 == -1 )
break;
v13 = v7[128];
if ( v13 == -1 )
break;
if ( v13 > v10 )
goto LABEL_8;
++v11;
++v7;
if ( a2 < v11 )
{
v12 = a3[v11];
LABEL_8:
result = (unsigned int)(a4 - v5);
if ( a1 >= v12 )
return result;
goto LABEL_9;
}
}
v12 = a3[--v11];
result = (unsigned int)(a4 - v5);
if ( a1 >= v12 )
return result;
LABEL_9:
result = (unsigned int)(v12 - a1);
if ( v5 >= v12 - a3[v11 + 127] && v5 <= (int)result )
{
result = (unsigned int)(result - v5);
v15 = a3[v11 + 1];
if ( a1 + (int)result < v15 )
result = (unsigned int)(v15 - a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int *a3, int a4)
{
int v5; // er8
int *v7; // rax
int v10; // er11
int v11; // edx
int v12; // esi
int v13; // ecx
__int64 result; // rax
int v15; // edx

v5 = a4 * overlap / 100;
if ( a2 <= 1 )
return (unsigned int)(a4 - v5);
v7 = a3;
v10 = a1 + a4;
v11 = 0;
while ( 1 )
{
v12 = *v7;
if ( *v7 == -1 )
break;
v13 = v7[128];
if ( v13 == -1 )
break;
if ( v13 > v10 )
goto LABEL_8;
++v11;
++v7;
if ( a2 < v11 )
{
v12 = a3[v11];
LABEL_8:
result = (unsigned int)(a4 - v5);
if ( a1 >= v12 )
return result;
goto LABEL_9;
}
}
v12 = a3[--v11];
result = (unsigned int)(a4 - v5);
if ( a1 >= v12 )
return result;
LABEL_9:
result = (unsigned int)(v12 - a1);
if ( v5 >= v12 - a3[v11 + 127] && v5 <= (int)result )
{
result = (unsigned int)(result - v5);
v15 = a3[v11 + 1];
if ( a1 + (int)result < v15 )
result = (unsigned int)(v15 - a1);
}
return result;
}

original_code:
int shift (int left_screen_edge, int frames_count, int frame_map[][128], int display_size)
{
  int frame_number;
  int start_of_frame;
  int right_screen_edge = left_screen_edge + display_size;
  int overlap_pixels=display_size*overlap/100;
  int gap_size;
  int shift_value;
  if (frames_count < 2)
    return display_size-overlap_pixels;
  for (frame_number=0; frame_number <= frames_count; frame_number++)
  {
    if (frame_map[0][frame_number] == -1 || frame_map[1][frame_number] == -1)
    {
      frame_number--;
      break;
    }
    if (frame_map[1][frame_number] > right_screen_edge)
      break;
  }
  start_of_frame = frame_map[0][frame_number];
  if (start_of_frame <= left_screen_edge)
    return display_size-overlap_pixels;
  gap_size = frame_map[0][frame_number]-frame_map[1][frame_number-1];
  shift_value = start_of_frame-left_screen_edge;
  if (gap_size > overlap_pixels || shift_value < overlap_pixels)
    return start_of_frame-left_screen_edge;
  else
  {
    int shift_candidate=start_of_frame-left_screen_edge-overlap_pixels;
    int next_frame_start=frame_map[0][frame_number+1];
    if (next_frame_start > left_screen_edge+shift_candidate)
      return next_frame_start-left_screen_edge;
    else
      return shift_candidate;
  }
}

canonical_original_code:
int shift(int left_screen_edge, int frames_count, int frame_map[][128], int display_size)
{
  int frame_number;
  int start_of_frame;
  int right_screen_edge = left_screen_edge + display_size;
  int overlap_pixels = display_size*overlap/100;
  int gap_size;
  int shift_value;
  if (frames_count < 2)
    return display_size-overlap_pixels;
  for (frame_number=0; frame_number <= frames_count; frame_number++)
  {
    if (frame_map[0][frame_number] == -1 || frame_map[1][frame_number] == -1)
    {
      frame_number--;
      break;
    }
    if (frame_map[1][frame_number] > right_screen_edge)
      break;
  }
  start_of_frame = frame_map[0][frame_number];
  if (start_of_frame <= left_screen_edge)
    return display_size-overlap_pixels;
  gap_size = frame_map[0][frame_number]-frame_map[1][frame_number-1];
  shift_value = start_of_frame-left_screen_edge;
  if (gap_size > overlap_pixels || shift_value < overlap_pixels)
    return start_of_frame-left_screen_edge;
  else
  {
    int shift_candidate = start_of_frame-left_screen_edge-overlap_pixels;
    int next_frame_start = frame_map[0][frame_number+1];
    if (next_frame_start > left_screen_edge+shift_candidate)
      return next_frame_start-left_screen_edge;
    else
      return shift_candidate;
  }
}


decompiled_code:
__int64 __fastcall shift_back(int a1, int a2, __int64 a3, int a4)
{
__int64 v4; // r9
int v6; // esi
int v7; // er8
int v8; // eax
__int64 v9; // rdx
int v10; // ecx
int v11; // edx
int v12; // eax
__int64 result; // rax
int v14; // ecx
unsigned int v15; // esi

v4 = a2;
v6 = a4;
v7 = a4 * overlap / 100;
if ( (int)v4 <= 1 )
return (unsigned int)(v6 - v7);
v8 = v4 - 1;
v9 = a3 + 4 * v4;
while ( 1 )
{
v10 = *(_DWORD *)(v9 - 4);
if ( v10 < a1 )
break;
--v8;
v9 -= 4LL;
if ( v8 == -1 )
goto LABEL_5;
}
v10 = *(_DWORD *)(a3 + 4LL * (v8 + 1));
LABEL_5:
v11 = *(_DWORD *)(a3 + 4LL * v8 + 512);
v12 = v10 - v11;
if ( v6 < v10 - v11 )
{
result = (unsigned int)(v6 + v12);
if ( a1 < v10 )
result = (unsigned int)(result - (v10 - a1));
return result;
}
v14 = a1 + v6;
if ( v7 >= v12 )
{
if ( a1 >= v11 )
{
result = (unsigned int)(v14 - v11);
if ( a1 - v11 < v7 )
return result;
goto LABEL_11;
}
}
else
{
v7 = 0;
if ( a1 >= v11 )
{
LABEL_11:
v6 = v14 - v11;
return (unsigned int)(v6 - v7);
}
}
v15 = v6 - v7;
result = (unsigned int)(v14 - v11);
if ( v14 <= v11 )
result = v15;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, __int64 a3, int a4)
{
__int64 v4; // r9
int v6; // esi
int v7; // er8
int v8; // eax
__int64 v9; // rdx
int v10; // ecx
int v11; // edx
int v12; // eax
__int64 result; // rax
int v14; // ecx
unsigned int v15; // esi

v4 = a2;
v6 = a4;
v7 = a4 * overlap / 100;
if ( (int)v4 <= 1 )
return (unsigned int)(v6 - v7);
v8 = v4 - 1;
v9 = a3 + 4 * v4;
while ( 1 )
{
v10 = *(_DWORD *)(v9 - 4);
if ( v10 < a1 )
break;
--v8;
v9 -= 4LL;
if ( v8 == -1 )
goto LABEL_5;
}
v10 = *(_DWORD *)(a3 + 4LL * (v8 + 1));
LABEL_5:
v11 = *(_DWORD *)(a3 + 4LL * v8 + 512);
v12 = v10 - v11;
if ( v6 < v10 - v11 )
{
result = (unsigned int)(v6 + v12);
if ( a1 < v10 )
result = (unsigned int)(result - (v10 - a1));
return result;
}
v14 = a1 + v6;
if ( v7 >= v12 )
{
if ( a1 >= v11 )
{
result = (unsigned int)(v14 - v11);
if ( a1 - v11 < v7 )
return result;
goto LABEL_11;
}
}
else
{
v7 = 0;
if ( a1 >= v11 )
{
LABEL_11:
v6 = v14 - v11;
return (unsigned int)(v6 - v7);
}
}
v15 = v6 - v7;
result = (unsigned int)(v14 - v11);
if ( v14 <= v11 )
result = v15;
return result;
}

original_code:
int shift_back (int left_screen_edge, int frames_count, int frame_map[][128], int display_size)
{
  int frame_number;
  int end_of_frame;
  int right_screen_edge=left_screen_edge+display_size;
  int overlap_pixels=display_size*overlap/100;
  int gap_size;
  if (frames_count < 2)
    return display_size-overlap_pixels;
  for(frame_number = frames_count - 1; frame_number >= 0; frame_number--)
  {
    if (frame_map[0][frame_number] < left_screen_edge)
      break;
  }
  end_of_frame = frame_map[1][frame_number];
  gap_size = frame_map[0][frame_number+1] - frame_map[1][frame_number];
  if (gap_size > display_size)
  {
    if (left_screen_edge < frame_map[0][frame_number+1])
      return gap_size+display_size-(frame_map[0][frame_number+1]-left_screen_edge);
    else
      return gap_size+display_size;
  }
  if (gap_size > overlap_pixels)
    overlap_pixels=0;
  if (end_of_frame <= left_screen_edge)
    return left_screen_edge-end_of_frame < overlap_pixels ? right_screen_edge-end_of_frame : right_screen_edge-end_of_frame-overlap_pixels;
  else
  {
    if (end_of_frame < left_screen_edge+display_size)
      return right_screen_edge-end_of_frame;
    else
      return display_size-overlap_pixels;
  }
}

canonical_original_code:
int shift_back(int left_screen_edge, int frames_count, int frame_map[][128], int display_size)
{
  int frame_number;
  int end_of_frame;
  int right_screen_edge = left_screen_edge+display_size;
  int overlap_pixels = display_size*overlap/100;
  int gap_size;
  if (frames_count < 2)
    return display_size-overlap_pixels;
  for(frame_number = frames_count - 1; frame_number >= 0; frame_number--)
  {
    if (frame_map[0][frame_number] < left_screen_edge)
      break;
  }
  end_of_frame = frame_map[1][frame_number];
  gap_size = frame_map[0][frame_number+1] - frame_map[1][frame_number];
  if (gap_size > display_size)
  {
    if (left_screen_edge < frame_map[0][frame_number+1])
      return gap_size+display_size-(frame_map[0][frame_number+1]-left_screen_edge);
    else
      return gap_size+display_size;
  }
  if (gap_size > overlap_pixels)
    overlap_pixels=0;
  if (end_of_frame <= left_screen_edge)
    return left_screen_edge-end_of_frame < overlap_pixels ? right_screen_edge-end_of_frame : right_screen_edge-end_of_frame-overlap_pixels;
  else
  {
    if (end_of_frame < left_screen_edge+display_size)
      return right_screen_edge-end_of_frame;
    else
      return display_size-overlap_pixels;
  }
}