main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v4; // r14
int v5; // ebx
const char *v6; // r13
int v7; // er8
const char *v8; // rbp
__int64 v9; // r9
const char *v10; // rdi
int v11; // er13
Display *v12; // rax
Display *v13; // rdi
__int64 v14; // rax
char v15; // al
int v16; // er8
unsigned __int64 v17; // rbx
int v18; // er9
Window v19; // rax
Screen *v20; // rax
unsigned __int64 v21; // rdx
unsigned __int64 v22; // rax
int v23; // eax
int v24; // eax
const char *v25; // r8
Display *v26; // rax
Display *v27; // rdi
__int64 v28; // rax
__int64 v29; // rcx
unsigned int v30; // eax
int v31; // [rsp+0h] [rbp-1D8h]
int v32; // [rsp+4h] [rbp-1D4h]
int v33; // [rsp+8h] [rbp-1D0h]
int v34; // [rsp+Ch] [rbp-1CCh]
const char *v35; // [rsp+10h] [rbp-1C8h]
const char *v36; // [rsp+18h] [rbp-1C0h]
int v37; // [rsp+18h] [rbp-1C0h]
XWMHints v38; // [rsp+20h] [rbp-1B8h] BYREF
XSizeHints v39; // [rsp+60h] [rbp-178h] BYREF
XSetWindowAttributes v40; // [rsp+B0h] [rbp-128h] BYREF
XGCValues v41; // [rsp+120h] [rbp-B8h] BYREF

if ( getenv("_SYNC") )
Xdebug = 1;
v35 = *argv;
if ( argc <= 1 )
{
v26 = XOpenDisplay(0LL);
dsp = v26;
v27 = v26;
if ( v26 )
{
v28 = v26->default_screen;
v4 = 0LL;
screen = v28;
visual = v27->screens[v28].root_visual;
cmap_size = visual->map_entries;
ATOM_WM_PROTOCOLS = XInternAtom(v27, "WM_PROTOCOLS", 0);
v31 = 1;
ATOM_WM_DELETE_WINDOW = XInternAtom(dsp, "WM_DELETE_WINDOW", 0);
v33 = 0;
v34 = 0;
v32 = 0;
goto LABEL_41;
}
goto LABEL_48;
}
v31 = 1;
v4 = 0LL;
v5 = 1;
v6 = 0LL;
v34 = 0;
v33 = 0;
v7 = 0;
v32 = 0;
while ( 1 )
{
while ( 1 )
{
v8 = argv[v5];
v9 = v5;
if ( strcmp(v8, "-geometry") )
break;
v4 = argv[v9 + 1];
++v5;
LABEL_6:
if ( argc <= ++v5 )
goto LABEL_10;
}
if ( strcmp(argv[v5], "-display") )
{
if ( !strcmp(argv[v5], "-dump") )
{
v7 = 1;
}
else if ( !strcmp(argv[v5], "-nobw") )
{
v32 = 1;
}
else if ( !strcmp(argv[v5], "-half") )
{
v33 = 1;
}
else
{
v37 = v7;
v23 = strcmp(argv[v5], "-noinst");
v7 = v37;
if ( v23 )
{
v24 = strcmp(v8, "-iconwin");
v7 = v37;
if ( v24 )
{
fprintf(
stderr,
"usage: %s [-display dpystr] [-geometry geomstr]\n\t[-dump] [-nobw] [-half] [-noinst] [-iconwin]\n",
v35);
exit(1);
}
v34 = 1;
}
else
{
v31 = 0;
}
}
goto LABEL_6;
}
v6 = argv[v9 + 1];
v5 += 2;
if ( argc <= v5 )
{
LABEL_10:
v10 = v6;
v36 = v6;
v11 = v7;
v12 = XOpenDisplay(v10);
dsp = v12;
v13 = v12;
if ( v12 )
{
v14 = v12->default_screen;
screen = v14;
visual = v13->screens[v14].root_visual;
cmap_size = visual->map_entries;
ATOM_WM_PROTOCOLS = XInternAtom(v13, "WM_PROTOCOLS", 0);
ATOM_WM_DELETE_WINDOW = XInternAtom(dsp, "WM_DELETE_WINDOW", 0);
if ( v11 )
dumpCmap();
if ( !v31 )
{
v39.flags = 0LL;
*(_QWORD *)&v39.x = 0x10000000100LL;
*(_QWORD *)&v39.width = 0x8000000080LL;
if ( v4 )
goto LABEL_15;
width = 128;
v18 = 128;
v17 = 2048LL;
v16 = 128;
height = 128;
v40.event_mask = 163841LL;
LABEL_21:
win = XCreateWindow(
dsp,
dsp->screens[(__int64)dsp->default_screen].root,
v39.x,
v39.y,
v16,
v18,
1u,
dsp->screens[(__int64)screen].root_depth,
1u,
visual,
v17,
&v40);
XSetStandardProperties(dsp, win, " XColor ", " XCOLOR ", 0LL, (char **)argv, argc, &v39);
v38.input = 1;
v38.flags = 1LL;
if ( v34 )
{
v40.event_mask = 0x8000LL;
if ( v31 )
v40.colormap = cmap;
v19 = XCreateWindow(
dsp,
dsp->screens[(__int64)dsp->default_screen].root,
0,
0,
0x30u,
0x30u,
0,
dsp->screens[(__int64)screen].root_depth,
1u,
visual,
v17,
&v40);
v38.flags |= 8uLL;
v38.icon_window = v19;
if ( v31 )
{
*(_QWORD *)&v41.function = v19;
v41.plane_mask = win;
XSetWMColormapWindows(dsp, win, (Window *)&v41, 2);
}
}
XSetWMHints(dsp, win, &v38);
XSetWMProtocols(dsp, win, &ATOM_WM_DELETE_WINDOW, 1);
v20 = &dsp->screens[(__int64)screen];
v21 = v20->black_pixel;
v22 = v20->white_pixel;
v41.foreground = v21;
v41.background = v22;
gc = XCreateGC(dsp, win, 0xCuLL, &v41);
XMapWindow(dsp, win);
HandleEvents();
XUnmapWindow(dsp, win);
XDestroyWindow(dsp, win);
XFlush(dsp);
XCloseDisplay(dsp);
exit(0);
}
LABEL_41:
v29 = (unsigned int)cmap_size;
if ( v33 )
v29 = (unsigned int)(cmap_size >> 1);
v30 = XCreateHSBColormap(dsp, (unsigned int)screen, &cmap, v29, v32 ^ 1u, &visual, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0);
if ( v30 )
{
fprintf(stderr, "%s: unable to create colormap (%d).\n", v35, v30);
exit(1);
}
v39.flags = 0LL;
*(_QWORD *)&v39.x = 0x10000000100LL;
*(_QWORD *)&v39.width = 0x8000000080LL;
if ( v4 )
{
LABEL_15:
v15 = XParseGeometry(v4, &v39.x, &v39.y, (unsigned int *)&v39.width, (unsigned int *)&v39.height);
if ( (v15 & 3) != 0 )
v39.flags |= 1uLL;
if ( (v15 & 0xC) != 0 )
v39.flags |= 2uLL;
v16 = v39.width;
v40.event_mask = 163841LL;
v17 = 2048LL;
v18 = v39.height;
width = v39.width;
height = v39.height;
if ( !v31 )
goto LABEL_21;
}
else
{
width = 128;
v18 = 128;
v16 = 128;
height = 128;
v40.event_mask = 163841LL;
}
v17 = 10240LL;
v40.colormap = cmap;
goto LABEL_21;
}
v25 = v36;
if ( v36 )
{
LABEL_37:
fprintf(stderr, "%s: unable to open display, %s.\n", v35, v25);
exit(1);
}
LABEL_48:
v25 = "no display specified";
goto LABEL_37;
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v4; // r14
int v5; // ebx
const char *v6; // r13
int v7; // er8
const char *v8; // rbp
__int64 v9; // r9
const char *v10; // rdi
int v11; // er13
Display *v12; // rax
Display *v13; // rdi
__int64 v14; // rax
char v15; // al
int v16; // er8
unsigned __int64 v17; // rbx
int v18; // er9
Window v19; // rax
Screen *v20; // rax
unsigned __int64 v21; // rdx
unsigned __int64 v22; // rax
int v23; // eax
int v24; // eax
const char *v25; // r8
Display *v26; // rax
Display *v27; // rdi
__int64 v28; // rax
__int64 v29; // rcx
unsigned int v30; // eax
int v31; // [rsp+0h] [rbp-1D8h]
int v32; // [rsp+4h] [rbp-1D4h]
int v33; // [rsp+8h] [rbp-1D0h]
int v34; // [rsp+Ch] [rbp-1CCh]
const char *v35; // [rsp+10h] [rbp-1C8h]
const char *v36; // [rsp+18h] [rbp-1C0h]
int v37; // [rsp+18h] [rbp-1C0h]
XWMHints v38; // [rsp+20h] [rbp-1B8h] BYREF
XSizeHints v39; // [rsp+60h] [rbp-178h] BYREF
XSetWindowAttributes v40; // [rsp+B0h] [rbp-128h] BYREF
XGCValues v41; // [rsp+120h] [rbp-B8h] BYREF

if ( getenv("_SYNC") )
Xdebug = 1;
v35 = *argv;
if ( argc <= 1 )
{
v26 = XOpenDisplay(0LL);
dsp = v26;
v27 = v26;
if ( v26 )
{
v28 = v26->default_screen;
v4 = 0LL;
screen = v28;
visual = v27->screens[v28].root_visual;
cmap_size = visual->map_entries;
ATOM_WM_PROTOCOLS = XInternAtom(v27, "WM_PROTOCOLS", 0);
v31 = 1;
ATOM_WM_DELETE_WINDOW = XInternAtom(dsp, "WM_DELETE_WINDOW", 0);
v33 = 0;
v34 = 0;
v32 = 0;
goto LABEL_41;
}
goto LABEL_48;
}
v31 = 1;
v4 = 0LL;
v5 = 1;
v6 = 0LL;
v34 = 0;
v33 = 0;
v7 = 0;
v32 = 0;
while ( 1 )
{
while ( 1 )
{
v8 = argv[v5];
v9 = v5;
if ( strcmp(v8, "-geometry") )
break;
v4 = argv[v9 + 1];
++v5;
LABEL_6:
if ( argc <= ++v5 )
goto LABEL_10;
}
if ( strcmp(argv[v5], "-display") )
{
if ( !strcmp(argv[v5], "-dump") )
{
v7 = 1;
}
else if ( !strcmp(argv[v5], "-nobw") )
{
v32 = 1;
}
else if ( !strcmp(argv[v5], "-half") )
{
v33 = 1;
}
else
{
v37 = v7;
v23 = strcmp(argv[v5], "-noinst");
v7 = v37;
if ( v23 )
{
v24 = strcmp(v8, "-iconwin");
v7 = v37;
if ( v24 )
{
fprintf(
stderr,
"usage: %s [-display dpystr] [-geometry geomstr]\n\t[-dump] [-nobw] [-half] [-noinst] [-iconwin]\n",
v35);
exit(1);
}
v34 = 1;
}
else
{
v31 = 0;
}
}
goto LABEL_6;
}
v6 = argv[v9 + 1];
v5 += 2;
if ( argc <= v5 )
{
LABEL_10:
v10 = v6;
v36 = v6;
v11 = v7;
v12 = XOpenDisplay(v10);
dsp = v12;
v13 = v12;
if ( v12 )
{
v14 = v12->default_screen;
screen = v14;
visual = v13->screens[v14].root_visual;
cmap_size = visual->map_entries;
ATOM_WM_PROTOCOLS = XInternAtom(v13, "WM_PROTOCOLS", 0);
ATOM_WM_DELETE_WINDOW = XInternAtom(dsp, "WM_DELETE_WINDOW", 0);
if ( v11 )
func0();
if ( !v31 )
{
v39.flags = 0LL;
*(_QWORD *)&v39.x = 0x10000000100LL;
*(_QWORD *)&v39.width = 0x8000000080LL;
if ( v4 )
goto LABEL_15;
width = 128;
v18 = 128;
v17 = 2048LL;
v16 = 128;
height = 128;
v40.event_mask = 163841LL;
LABEL_21:
win = XCreateWindow(
dsp,
dsp->screens[(__int64)dsp->default_screen].root,
v39.x,
v39.y,
v16,
v18,
1u,
dsp->screens[(__int64)screen].root_depth,
1u,
visual,
v17,
&v40);
XSetStandardProperties(dsp, win, " XColor ", " XCOLOR ", 0LL, (char **)argv, argc, &v39);
v38.input = 1;
v38.flags = 1LL;
if ( v34 )
{
v40.event_mask = 0x8000LL;
if ( v31 )
v40.colormap = cmap;
v19 = XCreateWindow(
dsp,
dsp->screens[(__int64)dsp->default_screen].root,
0,
0,
0x30u,
0x30u,
0,
dsp->screens[(__int64)screen].root_depth,
1u,
visual,
v17,
&v40);
v38.flags |= 8uLL;
v38.icon_window = v19;
if ( v31 )
{
*(_QWORD *)&v41.function = v19;
v41.plane_mask = win;
XSetWMColormapWindows(dsp, win, (Window *)&v41, 2);
}
}
XSetWMHints(dsp, win, &v38);
XSetWMProtocols(dsp, win, &ATOM_WM_DELETE_WINDOW, 1);
v20 = &dsp->screens[(__int64)screen];
v21 = v20->black_pixel;
v22 = v20->white_pixel;
v41.foreground = v21;
v41.background = v22;
gc = XCreateGC(dsp, win, 0xCuLL, &v41);
XMapWindow(dsp, win);
func4();
XUnmapWindow(dsp, win);
XDestroyWindow(dsp, win);
XFlush(dsp);
XCloseDisplay(dsp);
exit(0);
}
LABEL_41:
v29 = (unsigned int)cmap_size;
if ( v33 )
v29 = (unsigned int)(cmap_size >> 1);
v30 = XCreateHSBColormap(dsp, (unsigned int)screen, &cmap, v29, v32 ^ 1u, &visual, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0);
if ( v30 )
{
fprintf(stderr, "%s: unable to create colormap (%d).\n", v35, v30);
exit(1);
}
v39.flags = 0LL;
*(_QWORD *)&v39.x = 0x10000000100LL;
*(_QWORD *)&v39.width = 0x8000000080LL;
if ( v4 )
{
LABEL_15:
v15 = XParseGeometry(v4, &v39.x, &v39.y, (unsigned int *)&v39.width, (unsigned int *)&v39.height);
if ( (v15 & 3) != 0 )
v39.flags |= 1uLL;
if ( (v15 & 0xC) != 0 )
v39.flags |= 2uLL;
v16 = v39.width;
v40.event_mask = 163841LL;
v17 = 2048LL;
v18 = v39.height;
width = v39.width;
height = v39.height;
if ( !v31 )
goto LABEL_21;
}
else
{
width = 128;
v18 = 128;
v16 = 128;
height = 128;
v40.event_mask = 163841LL;
}
v17 = 10240LL;
v40.colormap = cmap;
goto LABEL_21;
}
v25 = v36;
if ( v36 )
{
LABEL_37:
fprintf(stderr, "%s: unable to open display, %s.\n", v35, v25);
exit(1);
}
LABEL_48:
v25 = "no display specified";
goto LABEL_37;
}
}
}

original_code:
int
main(
    int argc,
    char *argv[]
    )
{
    XSetWindowAttributes xswa;
    XGCValues xgcv;
    XSizeHints size_hints;
    XWMHints wmhints;
    int i;
    int geomStat;
    char *geom = ((void *)0);
    char *displayName = ((void *)0);
    int stat;
    int dump = 0;
    int nobw = 0;
    int half = 0;
    int install = 1;
    int mask;
    int useiconwin = 0;
    const char *pname;
    if (getenv("_SYNC")) {
 extern int _Xdebug;
 _Xdebug = 1;
    }
    pname = argv[0];
    for (i = 1; i < argc; i++) {
 if (!strcmp(argv[i], "-geometry"))
     geom = argv[++i];
 else if (!strcmp(argv[i], "-display"))
     displayName = argv[++i];
 else if (!strcmp(argv[i], "-dump"))
     dump = 1;
 else if (!strcmp(argv[i], "-nobw"))
     nobw = 1;
 else if (!strcmp(argv[i], "-half"))
     half = 1;
 else if (!strcmp(argv[i], "-noinst"))
     install = 0;
 else if (!strcmp(argv[i], "-iconwin"))
     useiconwin = 1;
 else
     do { fprintf(stderr, "usage:  %s [-display dpystr] [-geometry geomstr]\n" "\t[-dump] [-nobw] [-half] [-noinst] [-iconwin]\n", pname) ; exit(1); } while (0);
    }
    if (!(dsp = XOpenDisplay(displayName))) {
 do { fprintf(stderr, "%s: unable to open display, %s.\n", pname, displayName ? displayName : "no display specified") ; exit(1); } while (0);
    }
    screen = (((_XPrivDisplay)(dsp))->default_screen);
    visual = (((&((_XPrivDisplay)(dsp))->screens[(((_XPrivDisplay)(dsp))->default_screen)]))->root_visual);
    cmap_size = visual->map_entries;
    ATOM_WM_PROTOCOLS = XInternAtom(dsp, "WM_PROTOCOLS", 0);
    ATOM_WM_DELETE_WINDOW = XInternAtom(dsp, "WM_DELETE_WINDOW", 0);
    if (dump)
 dumpCmap();
    if (install) {
     stat = XCreateHSBColormap(dsp, screen, &cmap, half
     ? (cmap_size>>1) : cmap_size,
          0.0, 1.0, 1.0,
          1.0, 1.0, 1.0, !nobw, &visual);
     if (stat != 0)
  do { fprintf(stderr, "%s: unable to create colormap (%d).\n", pname, stat) ; exit(1); } while (0);
    }
    size_hints.x = 256;
    size_hints.y = 256;
    size_hints.width = 128;
    size_hints.height = 128;
    size_hints.flags = 0;
    if (geom) {
 geomStat = XParseGeometry(geom, &(size_hints.x),
      &(size_hints.y),
      (unsigned int *) &(size_hints.width),
      (unsigned int *) &(size_hints.height));
 if (geomStat & (0x0001 | 0x0002)) {
     size_hints.flags |= (1L << 0);
 }
 if (geomStat & (0x0004 | 0x0008)) {
     size_hints.flags |= (1L << 1);
 }
    }
    width = size_hints.width;
    height = size_hints.height;
    xswa.event_mask = (1L<<15) | (1L<<0) | (1L<<17);
    mask = (1L<<11);
    if (install) {
     xswa.colormap = cmap;
     mask |= (1L<<13);
    }
    win = XCreateWindow(
   dsp,
   ((&((_XPrivDisplay)(dsp))->screens[(((_XPrivDisplay)(dsp))->default_screen)])->root),
   size_hints.x,
   size_hints.y,
   size_hints.width,
   size_hints.height,
   1,
   ((&((_XPrivDisplay)(dsp))->screens[screen])->root_depth),
   1,
   visual,
   mask,
   &xswa
 );
    XSetStandardProperties(dsp, win, " XColor ", " XCOLOR ",
      0L, argv, argc, &size_hints);
    wmhints.flags = (1L << 0);
    wmhints.input = 1;
    if (useiconwin) {
 Window icon;
 xswa.event_mask = (1L<<15);
 mask = (1L<<11);
 if (install) {
     xswa.colormap = cmap;
     mask |= (1L<<13);
 }
 icon = XCreateWindow(dsp, ((&((_XPrivDisplay)(dsp))->screens[(((_XPrivDisplay)(dsp))->default_screen)])->root),
     0, 0, 48, 48, 0, ((&((_XPrivDisplay)(dsp))->screens[screen])->root_depth),
     1, visual, mask, &xswa);
 wmhints.flags |= (1L << 3);
 wmhints.icon_window = icon;
 if (install) {
     Window cmapwins[2];
     cmapwins[0] = icon;
     cmapwins[1] = win;
     XSetWMColormapWindows(dsp, win, cmapwins, 2);
 }
    }
    XSetWMHints(dsp, win, &wmhints);
    XSetWMProtocols(dsp, win, &ATOM_WM_DELETE_WINDOW, 1);
    xgcv.foreground = ((&((_XPrivDisplay)(dsp))->screens[screen])->black_pixel);
    xgcv.background = ((&((_XPrivDisplay)(dsp))->screens[screen])->white_pixel);
    gc = XCreateGC(dsp, win, (1L<<2) | (1L<<3), &xgcv);
    XMapWindow(dsp, win);
    HandleEvents();
    XUnmapWindow(dsp, win);
    XDestroyWindow(dsp, win);
    XFlush(dsp);
    XCloseDisplay(dsp);
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct XSetWindowAttributes xswa;
    struct XGCValues xgcv;
    struct XSizeHints size_hints;
    struct XWMHints wmhints;
    int i;
    int geomStat;
    char *geom = ((void *)0);
    char *displayName = ((void *)0);
    int stat;
    int dump = 0;
    int nobw = 0;
    int half = 0;
    int install = 1;
    int mask;
    int useiconwin = 0;
    char *pname;
    if (getenv("_SYNC")) {
 extern int _Xdebug;
 _Xdebug = 1;
    }
    pname = argv[0];
    for (i = 1; i < argc; i++) {
 if (!strcmp(argv[i], "-geometry"))
     geom = argv[++i];
 else if (!strcmp(argv[i], "-display"))
     displayName = argv[++i];
 else if (!strcmp(argv[i], "-dump"))
     dump = 1;
 else if (!strcmp(argv[i], "-nobw"))
     nobw = 1;
 else if (!strcmp(argv[i], "-half"))
     half = 1;
 else if (!strcmp(argv[i], "-noinst"))
     install = 0;
 else if (!strcmp(argv[i], "-iconwin"))
     useiconwin = 1;
 else
     do { fprintf(stderr, "usage:  %s [-display dpystr] [-geometry geomstr]\n" "\t[-dump] [-nobw] [-half] [-noinst] [-iconwin]\n", pname) ; exit(1); } while (0);
    }
    if (!(dsp = XOpenDisplay(displayName))) {
 do { fprintf(stderr, "%s: unable to open display, %s.\n", pname, displayName ? displayName : "no display specified") ; exit(1); } while (0);
    }
    screen = (((_XPrivDisplay)(dsp))->default_screen);
    visual = (((&((_XPrivDisplay)(dsp))->screens[(((_XPrivDisplay)(dsp))->default_screen)]))->root_visual);
    cmap_size = visual->map_entries;
    ATOM_WM_PROTOCOLS = XInternAtom(dsp, "WM_PROTOCOLS", 0);
    ATOM_WM_DELETE_WINDOW = XInternAtom(dsp, "WM_DELETE_WINDOW", 0);
    if (dump)
 dumpCmap();
    if (install) {
     stat = XCreateHSBColormap(dsp, screen, &cmap, half
     ? (cmap_size>>1) : cmap_size,
          0.0, 1.0, 1.0,
          1.0, 1.0, 1.0, !nobw, &visual);
     if (stat != 0)
  do { fprintf(stderr, "%s: unable to create colormap (%d).\n", pname, stat) ; exit(1); } while (0);
    }
    size_hints.x = 256;
    size_hints.y = 256;
    size_hints.width = 128;
    size_hints.height = 128;
    size_hints.flags = 0;
    if (geom) {
 geomStat = XParseGeometry(geom, &(size_hints.x),
      &(size_hints.y),
      (unsigned int *) &(size_hints.width),
      (unsigned int *) &(size_hints.height));
 if (geomStat & (0x0001 | 0x0002)) {
     size_hints.flags |= (1L << 0);
 }
 if (geomStat & (0x0004 | 0x0008)) {
     size_hints.flags |= (1L << 1);
 }
    }
    width = size_hints.width;
    height = size_hints.height;
    xswa.event_mask = (1L<<15) | (1L<<0) | (1L<<17);
    mask = (1L<<11);
    if (install) {
     xswa.colormap = cmap;
     mask |= (1L<<13);
    }
    win = XCreateWindow(
   dsp,
   ((&((_XPrivDisplay)(dsp))->screens[(((_XPrivDisplay)(dsp))->default_screen)])->root),
   size_hints.x,
   size_hints.y,
   size_hints.width,
   size_hints.height,
   1,
   ((&((_XPrivDisplay)(dsp))->screens[screen])->root_depth),
   1,
   visual,
   mask,
   &xswa
 );
    XSetStandardProperties(dsp, win, " XColor ", " XCOLOR ",
      0L, argv, argc, &size_hints);
    wmhints.flags = (1L << 0);
    wmhints.input = 1;
    if (useiconwin) {
 unsigned long icon;
 xswa.event_mask = (1L<<15);
 mask = (1L<<11);
 if (install) {
     xswa.colormap = cmap;
     mask |= (1L<<13);
 }
 icon = XCreateWindow(dsp, ((&((_XPrivDisplay)(dsp))->screens[(((_XPrivDisplay)(dsp))->default_screen)])->root),
     0, 0, 48, 48, 0, ((&((_XPrivDisplay)(dsp))->screens[screen])->root_depth),
     1, visual, mask, &xswa);
 wmhints.flags |= (1L << 3);
 wmhints.icon_window = icon;
 if (install) {
     unsigned long cmapwins[2];
     cmapwins[0] = icon;
     cmapwins[1] = win;
     XSetWMColormapWindows(dsp, win, cmapwins, 2);
 }
    }
    XSetWMHints(dsp, win, &wmhints);
    XSetWMProtocols(dsp, win, &ATOM_WM_DELETE_WINDOW, 1);
    xgcv.foreground = ((&((_XPrivDisplay)(dsp))->screens[screen])->black_pixel);
    xgcv.background = ((&((_XPrivDisplay)(dsp))->screens[screen])->white_pixel);
    gc = XCreateGC(dsp, win, (1L<<2) | (1L<<3), &xgcv);
    XMapWindow(dsp, win);
    HandleEvents();
    XUnmapWindow(dsp, win);
    XDestroyWindow(dsp, win);
    XFlush(dsp);
    XCloseDisplay(dsp);
    exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct XSetWindowAttributes { unsigned long background_pixmap; unsigned long background_pixel; unsigned long border_pixmap; unsigned long border_pixel; int bit_gravity; int win_gravity; int backing_store; unsigned long backing_planes; unsigned long backing_pixel; int save_under; long event_mask; long do_not_propagate_mask; int override_redirect; unsigned long colormap; unsigned long cursor; }

variable_types: struct XGCValues { int function; unsigned long plane_mask; unsigned long foreground; unsigned long background; int line_width; int line_style; int cap_style; int join_style; int fill_style; int fill_rule; int arc_mode; unsigned long tile; unsigned long stipple; int ts_x_origin; int ts_y_origin; unsigned long font; int subwindow_mode; int graphics_exposures; int clip_x_origin; int clip_y_origin; unsigned long clip_mask; int dash_offset; char dashes; }

variable_types: struct XSizeHints { long flags; int x; int width; int min_width; int max_width; int width_inc; struct { int x; int y; } min_aspect; int base_width; int win_gravity; }

variable_types: struct XWMHints { long flags; int input; int initial_state; unsigned long icon_pixmap; unsigned long icon_window; int icon_x; unsigned long icon_mask; unsigned long window_group; }

variable_types: i int

variable_types: geomStat int

variable_types:
geom
char *

variable_types:
displayName
char *

variable_types: stat int

variable_types: dump int

variable_types: nobw int

variable_types: half int

variable_types: install int

variable_types: mask int

variable_types: useiconwin int

variable_types:
pname
char *

variable_types:
icon
unsigned long

variable_types:
cmapwins
unsigned long [2]


repo: aszeszo/xnv

decompiled_code:
void __noreturn fatal_error(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fprintf(stderr, "%s: error: ", (const char *)program);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fprintf(stderr, "%s: error: ", (const char *)program);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

original_code:
void
fatal_error (const char *format, ...)
{
 va_list args;
 __builtin_va_start(args,format);
 (void) fprintf(stderr, "%s: error: ", program);
 (void) vfprintf(stderr, format, args);
 (void) fprintf(stderr, "\n");
 __builtin_va_end(args);
 exit(1);
}

canonical_original_code:
void fatal_error(char *format, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,format);
 (void) fprintf(stderr, "%s: error: ", program);
 (void) vfprintf(stderr, format, args);
 (void) fprintf(stderr, "\n");
 __builtin_va_end(args);
 exit(1);
}

variable_types:
format
char *

return_type: void


warning

decompiled_code:
void __noreturn warning(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("Warning: ", 1uLL, 9uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("Warning: ", 1uLL, 9uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

original_code:
void
warning (const char *format, ...)
{
 va_list args;
 __builtin_va_start(args,format);
 (void) fprintf(stderr, "Warning: ");
 (void) vfprintf(stderr, format, args);
 (void) fprintf(stderr, "\n");
 __builtin_va_end(args);
 exit(1);
}

canonical_original_code:
void warning(char *format, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,format);
 (void) fprintf(stderr, "Warning: ");
 (void) vfprintf(stderr, format, args);
 (void) fprintf(stderr, "\n");
 __builtin_va_end(args);
 exit(1);
}


usage

decompiled_code:
void __noreturn usage()
{
fprintf(stderr, "usage: %s <op> [-display name] [-warn]\n", (const char *)program);
fwrite("<op> = save | init | discard | dealloc | show | NeWSinit\n", 1uLL, 0x39uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fprintf(stderr, "usage: %s <op> [-display name] [-warn]\n", (const char *)program);
fwrite("<op> = save | init | discard | dealloc | show | NeWSinit\n", 1uLL, 0x39uLL, stderr);
exit(1);
}

original_code:
static void
usage ()
{
 fprintf(stderr, "usage: %s <op> [-display name] [-warn]\n", program);
 fprintf(stderr, "<op> = save | init | discard | dealloc | show | NeWSinit\n");
 exit(1);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr, "usage: %s <op> [-display name] [-warn]\n", program);
 fprintf(stderr, "<op> = save | init | discard | dealloc | show | NeWSinit\n");
 exit(1);
}


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char **v4; // rbx
void (*v5)(void); // rbp

program = (__int64)*argv;
if ( argc <= 1 )
goto LABEL_11;
v3 = (const char **)argv[1];
v4 = argv;
if ( !strcmp("save", (const char *)v3) )
{
v5 = (void (*)(void))&cmc_save;
}
else if ( !strcmp("init", (const char *)v3) )
{
v5 = (void (*)(void))&cmc_init;
}
else if ( !strcmp("show", (const char *)v3) )
{
v5 = (void (*)(void))&cmc_show;
}
else if ( !strcmp("discard", (const char *)v3) )
{
v5 = (void (*)(void))&cmc_discard;
}
else
{
if ( strcmp("dealloc", (const char *)v3) )
{
argv = v3;
*(_QWORD *)&argc = "NeWSinit";
if ( !strcmp("NeWSinit", (const char *)v3) )
{
v5 = (void (*)(void))&cmc_NeWSinit;
goto LABEL_10;
}
LABEL_11:
usage(*(_QWORD *)&argc, argv, envp);
}
v5 = (void (*)(void))&cmc_dealloc;
}
LABEL_10:
process_arguments(v4 + 2);
v5();
exit(0);
}

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

program = (__int64)*argv;
if ( argc <= 1 )
goto LABEL_11;
v3 = (const char **)argv[1];
v4 = argv;
if ( !strcmp("save", (const char *)v3) )
{
v5 = (void (*)(void))&cmc_save;
}
else if ( !strcmp("init", (const char *)v3) )
{
v5 = (void (*)(void))&cmc_init;
}
else if ( !strcmp("show", (const char *)v3) )
{
v5 = (void (*)(void))&cmc_show;
}
else if ( !strcmp("discard", (const char *)v3) )
{
v5 = (void (*)(void))&cmc_discard;
}
else
{
if ( strcmp("dealloc", (const char *)v3) )
{
argv = v3;
*(_QWORD *)&argc = "NeWSinit";
if ( !strcmp("NeWSinit", (const char *)v3) )
{
v5 = (void (*)(void))&cmc_NeWSinit;
goto LABEL_10;
}
LABEL_11:
func0(*(_QWORD *)&argc, argv, envp);
}
v5 = (void (*)(void))&cmc_dealloc;
}
LABEL_10:
func3(v4 + 2);
v5();
exit(0);
}

original_code:
int
main (int argc, char **argv)
{
 void (*op)();
 program = argv[0];
 if (argc <= 1)
  usage();
 ++argv;
 if (!strcmp("save", *argv))
  op = cmc_save;
 else if (!strcmp("init", *argv))
  op = cmc_init;
 else if (!strcmp("show", *argv))
  op = cmc_show;
 else if (!strcmp("discard", *argv))
  op = cmc_discard;
 else if (!strcmp("dealloc", *argv))
  op = cmc_dealloc;
 else if (!strcmp("NeWSinit", *argv))
  op = cmc_NeWSinit;
 else
  usage();
 process_arguments(++argv);
 op();
 exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 void (*op)();
 program = argv[0];
 if (argc <= 1)
  usage();
 ++argv;
 if (!strcmp("save", *argv))
  op = cmc_save;
 else if (!strcmp("init", *argv))
  op = cmc_init;
 else if (!strcmp("show", *argv))
  op = cmc_show;
 else if (!strcmp("discard", *argv))
  op = cmc_discard;
 else if (!strcmp("dealloc", *argv))
  op = cmc_dealloc;
 else if (!strcmp("NeWSinit", *argv))
  op = cmc_NeWSinit;
 else
  usage();
 process_arguments(++argv);
 op();
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
op
void (*)()

return_type: int


Hash

decompiled_code:
__int64 __fastcall Hash(_BYTE *a1, int a2)
{
int v2; // eax
int v3; // edx

v2 = (char)*a1;
if ( !*a1 )
return 0LL;
v3 = 0;
do
{
++a1;
v3 += v2;
v2 = (char)*a1;
}
while ( *a1 );
return (unsigned int)((int)abs32(v3) % a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, int a2)
{
int v2; // eax
int v3; // edx

v2 = (char)*a1;
if ( !*a1 )
return 0LL;
v3 = 0;
do
{
++a1;
v3 += v2;
v2 = (char)*a1;
}
while ( *a1 );
return (unsigned int)((int)abs32(v3) % a2);
}

original_code:
static int Hash(char *name, int nEntries)
{
  register int val = 0;
  while (*name) val += *name++;
  if (val < 0) val = -val;
  return (val % nEntries);
}

variable_types:
name
char *

variable_types: nEntries int

variable_types: val int


decompiled_code:
int cmc_discard()
{
const char *v0; // rbp
int result; // eax

v0 = (const char *)comp_colors_filename(basename_arg);
result = unlink(v0);
if ( result < 0 )
{
fatal_error("cannot remove file '%s'", v0);
JUMPOUT(0x2DLL);
}
return result;
}

canonical_decompiled_code:
int func0()
{
const char *v0; // rbp
int result; // eax

v0 = (const char *)comp_colors_filename(basename_arg);
result = unlink(v0);
if ( result < 0 )
{
fatal_error("cannot remove file '%s'", v0);
JUMPOUT(0x2DLL);
}
return result;
}

original_code:
void
cmc_discard (void)
{
 const char *filename = comp_colors_filename(basename_arg);
 if (unlink(filename) < 0)
  fatal_error("cannot remove file '%s'", filename);
}

canonical_original_code:
void cmc_discard()
{
 char *filename = comp_colors_filename(basename_arg);
 if (unlink(filename) < 0)
  fatal_error("cannot remove file '%s'", filename);
}

variable_types:
filename
char *


ScanArgs

decompiled_code:
int __fastcall ScanArgs(int a1, __int64 *a2)
{
char *v2; // rax
int i; // ebx
__int64 v4; // rdx
__int64 v5; // rcx
char *v6; // rbp
char *v7; // rax
__int64 v8; // rbp
char *v9; // r14
int result; // eax

prog = *a2;
v2 = strrchr((const char *)prog, 47);
if ( v2 )
prog = (__int64)++v2;
if ( a1 > 1 )
{
for ( i = 1; i < a1; ++i )
{
LABEL_8:
v4 = i;
v2 = (char *)a2[v4];
if ( *v2 == 45 )
{
v5 = (unsigned int)v2[1];
LODWORD(v2) = (unsigned __int8)(v2[1] - 97);
switch ( (char)v2 )
{
case 0:
++doANSI;
++reentrant;
continue;
case 1:
++bigFile;
continue;
case 5:
v2 = (char *)a2[v4 + 1];
++i;
special_h = (__int64)v2;
continue;
case 7:
v6 = (char *)a2[v4 + 1];
++i;
hfile = v6;
v7 = strrchr(v6, 47);
if ( v7 )
v6 = v7 + 1;
LODWORD(v2) = (unsigned int)strcpy(&headid, v6);
v8 = headid;
if ( headid )
{
v9 = &headid;
do
{
if ( (_BYTE)v8 == 46 )
{
*v9 = 95;
}
else if ( (v8 & 0x80u) == 0LL )
{
v2 = (char *)*_ctype_b_loc();
if ( (v2[2 * v8 + 1] & 2) != 0 )
{
LODWORD(v2) = (*_ctype_toupper_loc())[v8];
*v9 = (char)v2;
}
}
v8 = *++v9;
}
while ( (_BYTE)v8 );
}
continue;
case 13:
LODWORD(v2) = 1;
noUserNames = 1;
continue;
case 14:
v2 = (char *)a2[v4 + 1];
++i;
ofile = v2;
continue;
case 15:
++pad;
continue;
case 17:
++i;
++reentrant;
if ( a1 <= i )
return (int)v2;
goto LABEL_8;
case 18:
++i;
LODWORD(v2) = atoi((const char *)a2[v4 + 1]);
maxstring = (int)v2;
if ( (int)v2 <= 79 )
{
LODWORD(v2) = fprintf(stderr, "%s: -s %d is the minimum\n", (const char *)prog, 80LL);
maxstring = 80;
}
continue;
case 22:
continue;
default:
fprintf(stderr, "%s: bad option '-%c'\n", (const char *)prog, v5);
Usage();
return result;
}
}
if ( ifile )
{
fprintf(stderr, "%s: Only one input file can be specified.\n", (const char *)prog);
Usage();
}
ifile = (char *)a2[i];
}
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func1(int a1, __int64 *a2)
{
char *v2; // rax
int i; // ebx
__int64 v4; // rdx
__int64 v5; // rcx
char *v6; // rbp
char *v7; // rax
__int64 v8; // rbp
char *v9; // r14
int result; // eax

prog = *a2;
v2 = strrchr((const char *)prog, 47);
if ( v2 )
prog = (__int64)++v2;
if ( a1 > 1 )
{
for ( i = 1; i < a1; ++i )
{
LABEL_8:
v4 = i;
v2 = (char *)a2[v4];
if ( *v2 == 45 )
{
v5 = (unsigned int)v2[1];
LODWORD(v2) = (unsigned __int8)(v2[1] - 97);
switch ( (char)v2 )
{
case 0:
++doANSI;
++reentrant;
continue;
case 1:
++bigFile;
continue;
case 5:
v2 = (char *)a2[v4 + 1];
++i;
special_h = (__int64)v2;
continue;
case 7:
v6 = (char *)a2[v4 + 1];
++i;
hfile = v6;
v7 = strrchr(v6, 47);
if ( v7 )
v6 = v7 + 1;
LODWORD(v2) = (unsigned int)strcpy(&headid, v6);
v8 = headid;
if ( headid )
{
v9 = &headid;
do
{
if ( (_BYTE)v8 == 46 )
{
*v9 = 95;
}
else if ( (v8 & 0x80u) == 0LL )
{
v2 = (char *)*_ctype_b_loc();
if ( (v2[2 * v8 + 1] & 2) != 0 )
{
LODWORD(v2) = (*_ctype_toupper_loc())[v8];
*v9 = (char)v2;
}
}
v8 = *++v9;
}
while ( (_BYTE)v8 );
}
continue;
case 13:
LODWORD(v2) = 1;
noUserNames = 1;
continue;
case 14:
v2 = (char *)a2[v4 + 1];
++i;
ofile = v2;
continue;
case 15:
++pad;
continue;
case 17:
++i;
++reentrant;
if ( a1 <= i )
return (int)v2;
goto LABEL_8;
case 18:
++i;
LODWORD(v2) = atoi((const char *)a2[v4 + 1]);
maxstring = (int)v2;
if ( (int)v2 <= 79 )
{
LODWORD(v2) = fprintf(stderr, "%s: -s %d is the minimum\n", (const char *)prog, 80LL);
maxstring = 80;
}
continue;
case 22:
continue;
default:
fprintf(stderr, "%s: bad option '-%c'\n", (const char *)prog, v5);
func0();
return result;
}
}
if ( ifile )
{
fprintf(stderr, "%s: Only one input file can be specified.\n", (const char *)prog);
func0();
}
ifile = (char *)a2[i];
}
}
return (int)v2;
}

original_code:
static void ScanArgs(int argc, char *argv[])
{
    char *slash;
    char *c;
    int i = 0;
    prog = argv[i++];
    slash = (strrchr((prog),('/')));
    if (slash)
 prog = slash + 1;
    while (i < argc) {
 if (*argv[i] != '-') {
     if (ifile != ((void *)0)) {
  fprintf(stderr, "%s:  Only one input file can be specified.\n", prog);
  Usage();
     } else {
  ifile = argv[i];
     }
 } else {
     switch (*(argv[i]+1)) {
     case 'a':
  doANSI++;
  reentrant++;
  break;
     case 'b':
  bigFile++;
  break;
     case 'f':
  special_h = argv[++i];
  break;
     case 'h':
  hfile = argv[++i];
  slash = (strrchr((hfile),('/')));
  strcpy(headid, slash ? slash+1 : hfile);
  for (c = headid; *c != '\0'; c++) {
      if (*c == '.') *c = '_';
      else if ((((*c) & ~0x7f) == 0) && ((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISlower)) *c = toupper(*c);
  }
  break;
     case 'o':
  ofile = argv[++i];
  break;
     case 'r':
  reentrant++;
  break;
     case 's':
  if ((maxstring = atoi(argv[++i])) < 80) {
      fprintf(stderr,"%s: -s %d is the minimum\n", prog, 80);
      maxstring = 80;
  }
  break;
     case 'w':
      break;
      case 'n':
       noUserNames = 1;
  break;
     case 'p':
  pad++;
  break;
     default:
  fprintf(stderr, "%s:  bad option '-%c'\n", prog, *(argv[i]+1));
  Usage();
  break;
     }
 }
 i++;
    }
}

canonical_original_code:
static void ScanArgs(int argc, char *argv[])
{
    char *slash;
    char *c;
    int i = 0;
    prog = argv[i++];
    slash = (strrchr((prog),('/')));
    if (slash)
 prog = slash + 1;
    while (i < argc) {
 if (*argv[i] != '-') {
     if (ifile != ((void *)0)) {
  fprintf(stderr, "%s:  Only one input file can be specified.\n", prog);
  Usage();
     } else {
  ifile = argv[i];
     }
 } else {
     switch (*(argv[i]+1)) {
     case 'a':
  doANSI++;
  reentrant++;
  break;
     case 'b':
  bigFile++;
  break;
     case 'f':
  special_h = argv[++i];
  break;
     case 'h':
  hfile = argv[++i];
  slash = (strrchr((hfile),('/')));
  strcpy(headid, slash ? slash+1 : hfile);
  for (c = headid; *c != '\0'; c++) {
      if (*c == '.') *c = '_';
      else if ((((*c) & ~0x7f) == 0) && ((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISlower)) *c = toupper(*c);
  }
  break;
     case 'o':
  ofile = argv[++i];
  break;
     case 'r':
  reentrant++;
  break;
     case 's':
  if ((maxstring = atoi(argv[++i])) < 80) {
      fprintf(stderr,"%s: -s %d is the minimum\n", prog, 80);
      maxstring = 80;
  }
  break;
     case 'w':
      break;
      case 'n':
       noUserNames = 1;
  break;
     case 'p':
  pad++;
  break;
     default:
  fprintf(stderr, "%s:  bad option '-%c'\n", prog, *(argv[i]+1));
  Usage();
  break;
     }
 }
 i++;
    }
}

variable_types:
argv
char *[]

variable_types:
slash
char *

variable_types:
c
char *

variable_types: i int


Usage

decompiled_code:
void __noreturn Usage()
{
fwrite("Usage: pswrap [options] [input-file]\n", 1uLL, 0x26uLL, stderr);
fwrite(" -a produce ANSI C procedure prototypes\n", 1uLL, 0x38uLL, stderr);
fwrite(" -b process a big file\n", 1uLL, 0x27uLL, stderr);
fwrite(" -f filename include special header\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -h filename specify header filename\n", 1uLL, 0x2CuLL, stderr);
fwrite(" -o filename specify output C filename\n", 1uLL, 0x2EuLL, stderr);
fwrite(" -r make wraps re-entrant\n", 1uLL, 0x2AuLL, stderr);
fwrite(" -s length set maximum string length\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("Usage: pswrap [options] [input-file]\n", 1uLL, 0x26uLL, stderr);
fwrite(" -a produce ANSI C procedure prototypes\n", 1uLL, 0x38uLL, stderr);
fwrite(" -b process a big file\n", 1uLL, 0x27uLL, stderr);
fwrite(" -f filename include special header\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -h filename specify header filename\n", 1uLL, 0x2CuLL, stderr);
fwrite(" -o filename specify output C filename\n", 1uLL, 0x2EuLL, stderr);
fwrite(" -r make wraps re-entrant\n", 1uLL, 0x2AuLL, stderr);
fwrite(" -s length set maximum string length\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}

original_code:
static void Usage(void)
{
    fprintf(stderr,"Usage:  pswrap [options] [input-file]\n");
    fprintf(stderr,"    -a              produce ANSI C procedure prototypes\n");
    fprintf(stderr,"    -b              process a big file\n");
    fprintf(stderr,"    -f filename     include special header\n");
    fprintf(stderr,"    -h filename     specify header filename\n");
    fprintf(stderr,"    -o filename     specify output C filename\n");
    fprintf(stderr,"    -r              make wraps re-entrant\n");
    fprintf(stderr,"    -s length       set maximum string length\n");
    exit(1);
}

canonical_original_code:
static void Usage()
{
    fprintf(stderr,"Usage:  pswrap [options] [input-file]\n");
    fprintf(stderr,"    -a              produce ANSI C procedure prototypes\n");
    fprintf(stderr,"    -b              process a big file\n");
    fprintf(stderr,"    -f filename     include special header\n");
    fprintf(stderr,"    -h filename     specify header filename\n");
    fprintf(stderr,"    -o filename     specify output C filename\n");
    fprintf(stderr,"    -r              make wraps re-entrant\n");
    fprintf(stderr,"    -s length       set maximum string length\n");
    exit(1);
}


main

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

ScanArgs(argc, (__int64 *)argv);
if ( ifile )
{
gotInFile = 1;
if ( !freopen(ifile, "r", stdin) )
{
fprintf(stderr, "%s: can't open %s for input\n", (const char *)prog, ifile);
exit(1);
}
}
else
{
ifile = "stdin";
}
v3 = maxstring;
string_temp = (__int64)malloc((unsigned int)(maxstring + 1));
if ( !string_temp )
{
fprintf(stderr, "%s: can't allocate %d char string; try a smaller -s value\n", (const char *)prog, v3);
exit(1);
}
if ( ofile )
{
if ( !freopen(ofile, "w", stdout) )
{
fprintf(stderr, "%s: can't open %s for output\n", (const char *)prog, ofile);
exit(1);
}
}
else
{
ofile = "stdout";
}
InitOFile();
if ( hfile )
{
header = (__int64)fopen(hfile, "w");
if ( !header )
{
fprintf(stderr, "%s: can't open %s for output\n", (const char *)prog, hfile);
exit(1);
}
}
else if ( !header )
{
LABEL_9:
InitWellKnownPSNames();
v4 = yyparse();
if ( v4 )
{
fprintf(stderr, "%s: error in parsing %s\n", (const char *)prog, ifile);
}
else
{
v4 = errorCount;
if ( errorCount )
{
fprintf(stderr, "%s: errors were encountered\n", (const char *)prog);
v4 = errorCount;
}
}
if ( hfile )
FinishHFile();
exit(v4);
}
InitHFile();
goto LABEL_9;
}

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

func1(argc, (__int64 *)argv);
if ( ifile )
{
gotInFile = 1;
if ( !freopen(ifile, "r", stdin) )
{
fprintf(stderr, "%s: can't open %s for input\n", (const char *)prog, ifile);
exit(1);
}
}
else
{
ifile = "stdin";
}
v3 = maxstring;
string_temp = (__int64)malloc((unsigned int)(maxstring + 1));
if ( !string_temp )
{
fprintf(stderr, "%s: can't allocate %d char string; try a smaller -s value\n", (const char *)prog, v3);
exit(1);
}
if ( ofile )
{
if ( !freopen(ofile, "w", stdout) )
{
fprintf(stderr, "%s: can't open %s for output\n", (const char *)prog, ofile);
exit(1);
}
}
else
{
ofile = "stdout";
}
InitOFile();
if ( hfile )
{
header = (__int64)fopen(hfile, "w");
if ( !header )
{
fprintf(stderr, "%s: can't open %s for output\n", (const char *)prog, hfile);
exit(1);
}
}
else if ( !header )
{
LABEL_9:
InitWellKnownPSNames();
v4 = yyparse();
if ( v4 )
{
fprintf(stderr, "%s: error in parsing %s\n", (const char *)prog, ifile);
}
else
{
v4 = errorCount;
if ( errorCount )
{
fprintf(stderr, "%s: errors were encountered\n", (const char *)prog);
v4 = errorCount;
}
}
if ( hfile )
FinishHFile();
exit(v4);
}
InitHFile();
goto LABEL_9;
}

original_code:
int main(int argc, char *argv[])
{
    int retval;
    ScanArgs(argc, argv);
    if (ifile == ((void *)0))
 ifile = "stdin";
    else {
 gotInFile = 1;
 if (freopen(ifile,"r",stdin) == ((void *)0)) {
     fprintf(stderr, "%s:  can't open %s for input\n", prog, ifile);
     exit(1);
 }
    }
    if ((string_temp = (char *) malloc((unsigned) (maxstring+1))) == 0) {
 fprintf(stderr, "%s:  can't allocate %d char string; try a smaller -s value\n", prog, maxstring);
 exit(1);
    }
    if (ofile == ((void *)0))
  ofile = "stdout";
    else {
     if (freopen(ofile,"w",stdout) == ((void *)0)) {
     fprintf(stderr, "%s:  can't open %s for output\n", prog, ofile);
     exit(1);
 }
    }
    InitOFile();
    if (hfile != ((void *)0)) {
 if ((header = fopen(hfile,"w")) == ((void *)0)) {
     fprintf(stderr, "%s:  can't open %s for output\n", prog, hfile);
     exit(1);
 }
    }
    if (header != ((void *)0)) InitHFile();
    InitWellKnownPSNames();
    if ((retval = yyparse()) != 0)
 fprintf(stderr,"%s: error in parsing %s\n",prog,ifile);
    else if (errorCount != 0) {
 fprintf(stderr,"%s: errors were encountered\n",prog);
 retval = errorCount;
    }
    if (hfile != ((void *)0)) FinishHFile();
    exit (retval);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int retval;
    ScanArgs(argc, argv);
    if (ifile == ((void *)0))
 ifile = "stdin";
    else {
 gotInFile = 1;
 if (freopen(ifile,"r",stdin) == ((void *)0)) {
     fprintf(stderr, "%s:  can't open %s for input\n", prog, ifile);
     exit(1);
 }
    }
    if ((string_temp = (char *) malloc((unsigned int) (maxstring+1))) == 0) {
 fprintf(stderr, "%s:  can't allocate %d char string; try a smaller -s value\n", prog, maxstring);
 exit(1);
    }
    if (ofile == ((void *)0))
  ofile = "stdout";
    else {
     if (freopen(ofile,"w",stdout) == ((void *)0)) {
     fprintf(stderr, "%s:  can't open %s for output\n", prog, ofile);
     exit(1);
 }
    }
    InitOFile();
    if (hfile != ((void *)0)) {
 if ((header = fopen(hfile,"w")) == ((void *)0)) {
     fprintf(stderr, "%s:  can't open %s for output\n", prog, hfile);
     exit(1);
 }
    }
    if (header != ((void *)0)) InitHFile();
    InitWellKnownPSNames();
    if ((retval = yyparse()) != 0)
 fprintf(stderr,"%s: error in parsing %s\n",prog,ifile);
    else if (errorCount != 0) {
 fprintf(stderr,"%s: errors were encountered\n",prog);
 retval = errorCount;
    }
    if (hfile != ((void *)0)) FinishHFile();
    exit (retval);
}

variable_types: retval int


decompiled_code:
char *__fastcall fn_absolutize(char *a1)
{
char *v1; // r12
char *v2; // rdx

v1 = a1;
if ( *a1 != 47 )
{
v2 = getenv("HOME");
v1 = filename_0;
if ( !v2 )
v2 = "/";
sprintf(filename_0, "%s/%s", v2, a1);
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1)
{
char *v1; // r12
char *v2; // rdx

v1 = a1;
if ( *a1 != 47 )
{
v2 = getenv("HOME");
v1 = filename_0;
if ( !v2 )
v2 = "/";
sprintf(filename_0, "%s/%s", v2, a1);
}
return v1;
}

original_code:
static const char *
fn_absolutize (const char *relname)
{
 static char filename[256];
 const char *homedir;
 if (*relname == '/')
  return relname;
 if (!(homedir = (char *) getenv("HOME")))
  homedir = "/";
 sprintf(filename, "%s/%s", homedir, relname);
 return filename;
}

canonical_original_code:
static char *fn_absolutize(char *relname)
{
 static char filename[256];
 char *homedir;
 if (*relname == '/')
  return relname;
 if (!(homedir = (char *) getenv("HOME")))
  homedir = "/";
 sprintf(filename, "%s/%s", homedir, relname);
 return filename;
}

variable_types:
relname
char *

variable_types:
filename
char [256]

variable_types:
homedir
char *

return_type: char *


decompiled_code:
char *__fastcall comp_colors_filename(char *a1)
{
if ( !a1 )
a1 = ".owcolors";
return fn_absolutize(a1);
}

canonical_decompiled_code:
char *__fastcall func3(char *a1)
{
if ( !a1 )
a1 = ".owcolors";
return func1(a1);
}

original_code:
const char *
comp_colors_filename (const char *basename)
{
 if (!basename)
  basename = ".owcolors";
 return fn_absolutize(basename);
}

canonical_original_code:
char *comp_colors_filename(char *basename)
{
 if (!basename)
  basename = ".owcolors";
 return fn_absolutize(basename);
}

variable_types:
basename
char *


HSBramp

original_code:
void
HSBramp(
    double h1,
    double s1,
    double b1,
    double h2,
    double s2,
    double b2,
    int start,
    int end,
    u_char *red,
    u_char *green,
    u_char *blue)
{
    double dh,
                ds,
                db;
    register u_char *r,
               *g,
               *b;
    register int i;
    r = red;
    g = green;
    b = blue;
    dh = (h2 - h1) / 255.0;
    ds = (s2 - s1) / 255.0;
    db = (b2 - b1) / 255.0;
    for (i = start; i <= end; i++) {
 hsb2rgb(h1, s1, b1, r++, g++, b++);
 h1 += dh;
 s1 += ds;
 b1 += db;
    }
}

canonical_original_code:
void HSBramp(double h1, double s1, double b1, double h2, double s2, double b2, int start, int end, unsigned char *red, unsigned char *green, unsigned char *blue)
{
    double dh; double ds; double db;
    register unsigned char *r; register unsigned char *g; register unsigned char *b;
    register int i;
    r = red;
    g = green;
    b = blue;
    dh = (h2 - h1) / 255.0;
    ds = (s2 - s1) / 255.0;
    db = (b2 - b1) / 255.0;
    for (i = start; i <= end; i++) {
 hsb2rgb(h1, s1, b1, r++, g++, b++);
 h1 += dh;
 s1 += ds;
 b1 += db;
    }
}

variable_types: start int

variable_types: end int

variable_types:
red
unsigned char *

variable_types:
green
unsigned char *

variable_types:
blue
unsigned char *

variable_types: dh double

variable_types: ds double

variable_types: db double

variable_types:
r
unsigned char *

variable_types:
g
unsigned char *

variable_types:
b
unsigned char *


decompiled_code:
__int64 __fastcall hsb2rgb(_BYTE *a1, _BYTE *a2, _BYTE *a3, __m128d a4, double a5, double a6)
{
unsigned __int64 v6; // xmm8_8
__m128d v7; // xmm8
unsigned __int64 v8; // xmm6_8
__m128d v9; // xmm6
double v10; // xmm2_8
double v11; // xmm0_8
int v12; // ecx
int v13; // er8
int v14; // er9
__int64 result; // rax

v6 = *(unsigned __int64 *)&a4.m128d_f64[0];
if ( COERCE_DOUBLE(*(_QWORD *)&a4.m128d_f64[0] & LC1) < 4.503599627370496e15 )
{
v7.m128d_f64[0] = (double)(int)a4.m128d_f64[0];
v6 = COERCE_UNSIGNED_INT64(v7.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v7, a4) & LC2)) | ~LC1 & *(_QWORD *)&a4.m128d_f64[0];
}
a4.m128d_f64[0] = (a4.m128d_f64[0] - *(double *)&v6) * 6.0;
v8 = *(unsigned __int64 *)&a4.m128d_f64[0];
if ( COERCE_DOUBLE(*(_QWORD *)&a4.m128d_f64[0] & LC1) < 4.503599627370496e15 )
{
v9.m128d_f64[0] = (double)(int)a4.m128d_f64[0];
v8 = COERCE_UNSIGNED_INT64(v9.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v9, a4) & LC2)) | ~LC1 & *(_QWORD *)&a4.m128d_f64[0];
}
v10 = a6 * 255.0;
v11 = a4.m128d_f64[0] - (float)(int)*(double *)&v8;
v12 = (int)((1.0 - a5) * v10);
v13 = (int)((1.0 - v11 * a5) * v10);
v14 = (int)((1.0 - a5 * (1.0 - v11)) * v10);
result = (unsigned int)(int)*(double *)&v8;
switch ( (int)result )
{
case 0:
result = (unsigned int)(int)v10;
*a1 = result;
*a2 = v14;
*a3 = v12;
break;
case 1:
result = (unsigned int)(int)v10;
*a1 = v13;
*a2 = result;
*a3 = v12;
break;
case 2:
result = (unsigned int)(int)v10;
*a1 = v12;
*a2 = result;
*a3 = v14;
break;
case 3:
result = (unsigned int)(int)v10;
*a1 = v12;
*a2 = v13;
*a3 = result;
break;
case 4:
result = (unsigned int)(int)v10;
*a1 = v14;
*a2 = v12;
*a3 = result;
break;
case 5:
result = (unsigned int)(int)v10;
*a1 = result;
*a2 = v12;
*a3 = v13;
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, _BYTE *a2, _BYTE *a3, __m128d a4, double a5, double a6)
{
unsigned __int64 v6; // xmm8_8
__m128d v7; // xmm8
unsigned __int64 v8; // xmm6_8
__m128d v9; // xmm6
double v10; // xmm2_8
double v11; // xmm0_8
int v12; // ecx
int v13; // er8
int v14; // er9
__int64 result; // rax

v6 = *(unsigned __int64 *)&a4.m128d_f64[0];
if ( COERCE_DOUBLE(*(_QWORD *)&a4.m128d_f64[0] & LC1) < 4.503599627370496e15 )
{
v7.m128d_f64[0] = (double)(int)a4.m128d_f64[0];
v6 = COERCE_UNSIGNED_INT64(v7.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v7, a4) & LC2)) | ~LC1 & *(_QWORD *)&a4.m128d_f64[0];
}
a4.m128d_f64[0] = (a4.m128d_f64[0] - *(double *)&v6) * 6.0;
v8 = *(unsigned __int64 *)&a4.m128d_f64[0];
if ( COERCE_DOUBLE(*(_QWORD *)&a4.m128d_f64[0] & LC1) < 4.503599627370496e15 )
{
v9.m128d_f64[0] = (double)(int)a4.m128d_f64[0];
v8 = COERCE_UNSIGNED_INT64(v9.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v9, a4) & LC2)) | ~LC1 & *(_QWORD *)&a4.m128d_f64[0];
}
v10 = a6 * 255.0;
v11 = a4.m128d_f64[0] - (float)(int)*(double *)&v8;
v12 = (int)((1.0 - a5) * v10);
v13 = (int)((1.0 - v11 * a5) * v10);
v14 = (int)((1.0 - a5 * (1.0 - v11)) * v10);
result = (unsigned int)(int)*(double *)&v8;
switch ( (int)result )
{
case 0:
result = (unsigned int)(int)v10;
*a1 = result;
*a2 = v14;
*a3 = v12;
break;
case 1:
result = (unsigned int)(int)v10;
*a1 = v13;
*a2 = result;
*a3 = v12;
break;
case 2:
result = (unsigned int)(int)v10;
*a1 = v12;
*a2 = result;
*a3 = v14;
break;
case 3:
result = (unsigned int)(int)v10;
*a1 = v12;
*a2 = v13;
*a3 = result;
break;
case 4:
result = (unsigned int)(int)v10;
*a1 = v14;
*a2 = v12;
*a3 = result;
break;
case 5:
result = (unsigned int)(int)v10;
*a1 = result;
*a2 = v12;
*a3 = v13;
break;
default:
return result;
}
return result;
}

original_code:
static void
hsb2rgb(
    double H,
    double S,
    double B,
    u_char *r,
    u_char *g,
    u_char *b)
{
    register int i;
    register double f,
                bb;
    register u_char p,
                q,
                t;
    H -= floor(H);
    H *= 6.0;
    i = floor(H);
    f = H - (float) i;
    bb = 255.0 * B;
    p = (u_char) (bb * (1.0 - S));
    q = (u_char) (bb * (1.0 - (S * f)));
    t = (u_char) (bb * (1.0 - (S * (1.0 - f))));
    switch (i) {
    case 0:
 *r = (u_char) bb;
 *g = t;
 *b = p;
 break;
    case 1:
 *r = q;
 *g = (u_char) bb;
 *b = p;
 break;
    case 2:
 *r = p;
 *g = (u_char) bb;
 *b = t;
 break;
    case 3:
 *r = p;
 *g = q;
 *b = (u_char) bb;
 break;
    case 4:
 *r = t;
 *g = p;
 *b = (u_char) bb;
 break;
    case 5:
 *r = (u_char) bb;
 *g = p;
 *b = q;
 break;
    }
}

canonical_original_code:
static void hsb2rgb(double H, double S, double B, unsigned char *r, unsigned char *g, unsigned char *b)
{
    register int i;
    register double f; register double bb;
    register unsigned char p; register unsigned char q; register unsigned char t;
    H -= floor(H);
    H *= 6.0;
    i = floor(H);
    f = H - (float) i;
    bb = 255.0 * B;
    p = (u_char) (bb * (1.0 - S));
    q = (u_char) (bb * (1.0 - (S * f)));
    t = (u_char) (bb * (1.0 - (S * (1.0 - f))));
    switch (i) {
    case 0:
 *r = (unsigned char) bb;
 *g = t;
 *b = p;
 break;
    case 1:
 *r = q;
 *g = (unsigned char) bb;
 *b = p;
 break;
    case 2:
 *r = p;
 *g = (unsigned char) bb;
 *b = t;
 break;
    case 3:
 *r = p;
 *g = q;
 *b = (unsigned char) bb;
 break;
    case 4:
 *r = t;
 *g = p;
 *b = (unsigned char) bb;
 break;
    case 5:
 *r = (unsigned char) bb;
 *g = p;
 *b = q;
 break;
    }
}

variable_types: H double

variable_types: S double

variable_types: B double

variable_types: i int

variable_types: f double

variable_types: bb double

variable_types:
p
unsigned char

variable_types:
q
unsigned char

variable_types:
t
unsigned char


original_code:
static long
parse_long (const char *s)
{
    const char *fmt = "%lu";
    long retval = 0;
    if (s && *s) {
 if (*s == '0') s++, fmt = "%lo";
 if (*s == 'x' || *s == 'X') s++, fmt = "%lx";
 (void) sscanf (s, fmt, &retval);
    }
    return retval;
}

canonical_original_code:
static long parse_long(char *s)
{
    char *fmt = "%lu";
    long retval = 0;
    if (s && *s) {
 if (*s == '0') s++, fmt = "%lo";
 if (*s == 'x' || *s == 'X') s++, fmt = "%lx";
 (void) sscanf (s, fmt, &retval);
    }
    return retval;
}

variable_types:
s
char *

variable_types:
fmt
char *

variable_types: retval long

return_type: long


usage

decompiled_code:
void __noreturn usage()
{
const char *v0; // rdx
const char **v1; // rbx

fprintf(stderr, "usage:\n %s [-options ...] [windowid] ...\n\n", (const char *)ProgramName);
fwrite("where options include:\n", 1uLL, 0x17uLL, stderr);
v0 = help_0[0];
if ( help_0[0] )
{
v1 = (const char **)help_0;
do
{
++v1;
fprintf(stderr, "%s\n", v0);
v0 = *v1;
}
while ( *v1 );
}
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
const char *v0; // rdx
const char **v1; // rbx

fprintf(stderr, "usage:\n %s [-options ...] [windowid] ...\n\n", (const char *)ProgramName);
fwrite("where options include:\n", 1uLL, 0x17uLL, stderr);
v0 = help_0[0];
if ( help_0[0] )
{
v1 = (const char **)help_0;
do
{
++v1;
fprintf(stderr, "%s\n", v0);
v0 = *v1;
}
while ( *v1 );
}
exit(1);
}

original_code:
static void
usage (void)
{
    static const char *help[] = {
"    -display displayname             X server to contact",
"    -format {hex, decimal, octal}    format used to print window id",
"    -indent number                   amount to indent per level",
"    -long                            print a long listing",
"    -resources                       print a listing of widget resources",
"",
((void *)0)};
    const char **cpp;
    fprintf (stderr, "usage:\n        %s [-options ...] [windowid] ...\n\n",
      ProgramName);
    fprintf (stderr, "where options include:\n");
    for (cpp = help; *cpp; cpp++) {
 fprintf (stderr, "%s\n", *cpp);
    }
    exit (1);
}

canonical_original_code:
static void usage()
{
    static char *help[] = {
"    -display displayname             X server to contact",
"    -format {hex, decimal, octal}    format used to print window id",
"    -indent number                   amount to indent per level",
"    -long                            print a long listing",
"    -resources                       print a listing of widget resources",
"",
((void *)0)};
    char **cpp;
    fprintf (stderr, "usage:\n        %s [-options ...] [windowid] ...\n\n",
      ProgramName);
    fprintf (stderr, "where options include:\n");
    for (cpp = help; *cpp; cpp++) {
 fprintf (stderr, "%s\n", *cpp);
    }
    exit (1);
}

variable_types:
help
char *[]

variable_types:
cpp
char **


InitHFile

decompiled_code:
int InitHFile()
{
EmitVersion(header, ifile, hfile);
return fprintf(header, "#ifndef %s\n#define %s\n", (const char *)&headid, (const char *)&headid);
}

canonical_decompiled_code:
int func1()
{
func0(header, ifile, hfile);
return fprintf(header, "#ifndef %s\n#define %s\n", (const char *)&headid, (const char *)&headid);
}

original_code:
void InitHFile(void)
{
    (void) EmitVersion(header, ifile, hfile);
    fprintf(header,"#ifndef %s\n#define %s\n",headid,headid);
}

canonical_original_code:
void InitHFile()
{
    (void) EmitVersion(header, ifile, hfile);
    fprintf(header,"#ifndef %s\n#define %s\n",headid,headid);
}


FinishHFile

decompiled_code:
int FinishHFile()
{
fprintf(header, "\n#endif /* %s */\n", (const char *)&headid);
return fclose(header);
}

canonical_decompiled_code:
int func2()
{
fprintf(header, "\n#endif /* %s */\n", (const char *)&headid);
return fclose(header);
}

original_code:
void FinishHFile(void)
{
    fprintf(header,"\n#endif /* %s */\n",headid);
    fclose(header);
}

canonical_original_code:
void FinishHFile()
{
    fprintf(header,"\n#endif /* %s */\n",headid);
    fclose(header);
}


InitOFile

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

outlineno += EmitVersion(stdout, ifile, ofile);
printf("#include %s\n", "<DPS/dpsfriends.h>");
puts("#include <string.h>");
outlineno += 3;
if ( special_h )
{
printf("#include \"%s\"\n\n", special_h);
++outlineno;
}
result = printf("#line 1 \"%s\"\n", ifile);
++outlineno;
return result;
}

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

outlineno += func0(stdout, ifile, ofile);
printf("#include %s\n", "<DPS/dpsfriends.h>");
puts("#include <string.h>");
outlineno += 3;
if ( special_h )
{
printf("#include \"%s\"\n\n", special_h);
++outlineno;
}
result = printf("#line 1 \"%s\"\n", ifile);
++outlineno;
return result;
}

original_code:
void InitOFile(void)
{
    outlineno += EmitVersion(stdout, ifile, ofile);
    printf("#include %s\n", "<DPS/dpsfriends.h>");
    printf("#include <string.h>\n");
    outlineno += 3;
    if (special_h) {
 printf("#include \"%s\"\n\n", special_h);
        outlineno ++;
    }
    printf("#line 1 \"%s\"\n",ifile);
    outlineno++;
}

canonical_original_code:
void InitOFile()
{
    outlineno += EmitVersion(stdout, ifile, ofile);
    printf("#include %s\n", "<DPS/dpsfriends.h>");
    printf("#include <string.h>\n");
    outlineno += 3;
    if (special_h) {
 printf("#include \"%s\"\n\n", special_h);
        outlineno ++;
    }
    printf("#line 1 \"%s\"\n",ifile);
    outlineno++;
}


PSWStringLength

decompiled_code:
__int64 __fastcall PSWStringLength(char *a1)
{
char v1; // al
unsigned int i; // er8
char v3; // dl
char *v4; // rax

v1 = *a1;
for ( i = 0; *a1; v1 = *a1 )
{
while ( 1 )
{
v3 = a1[1];
if ( v1 == 92 )
break;
v1 = *++a1;
++i;
if ( !v1 )
return i;
}
v4 = a1 + 2;
a1 += 4;
if ( v3 == 92 )
a1 = v4;
++i;
}
return i;
}

original_code:
int PSWStringLength(char *s)
{
    register char *c = s;
    register int len = 0;
    while (*c != '\0') {
 if (*c++ == '\\') {
     if (*c++ != '\\') c += 2;
 }
 len++;
    }
    return (len);
}

variable_types:
c
char *

variable_types: len int


PSWOutputStringChars

decompiled_code:
int __fastcall PSWOutputStringChars(char *a1)
{
int v1; // ebp
char *v2; // rbx
int v3; // edi
int result; // eax
char v5; // r12
int v6; // ebp
int v7; // edi

if ( *a1 )
{
v1 = 0;
v2 = a1;
while ( 1 )
{
putc(39, stdout);
v3 = *v2;
if ( *v2 <= 39 )
break;
if ( (_BYTE)v3 != 92 )
goto LABEL_6;
putc(92, stdout);
v5 = v2[1];
fputc(v5, stdout);
if ( v5 == 92 )
{
v2 += 2;
}
else
{
putc(v2[2], stdout);
v7 = v2[3];
v2 += 4;
putc(v7, stdout);
}
LABEL_7:
result = putc(39, stdout);
if ( *v2 )
{
v6 = v1 + 1;
if ( v6 <= 15 )
{
result = putc(44, stdout);
}
else
{
result = fwrite(",\n ", 1uLL, 7uLL, stdout);
++outlineno;
}
v1 = v6 & 0xF;
if ( *v2 )
continue;
}
return result;
}
if ( (char)v3 > 7 )
{
switch ( (char)v3 )
{
case 8:
++v2;
fwrite(&unk_397, 1uLL, 2uLL, stdout);
break;
case 9:
++v2;
fwrite("\\t", 1uLL, 2uLL, stdout);
break;
case 10:
++v1;
++v2;
fwrite("\\012", 1uLL, 4uLL, stdout);
break;
case 12:
++v2;
fwrite(&unk_39A, 1uLL, 2uLL, stdout);
break;
case 13:
++v1;
++v2;
fwrite("\\015", 1uLL, 4uLL, stdout);
break;
case 34:
++v2;
fwrite(&unk_394, 1uLL, 2uLL, stdout);
break;
case 39:
++v2;
fwrite(&unk_391, 1uLL, 2uLL, stdout);
break;
default:
goto LABEL_6;
}
goto LABEL_7;
}
LABEL_6:
--v1;
++v2;
putc(v3, stdout);
goto LABEL_7;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *a1)
{
int v1; // ebp
char *v2; // rbx
int v3; // edi
int result; // eax
char v5; // r12
int v6; // ebp
int v7; // edi

if ( *a1 )
{
v1 = 0;
v2 = a1;
while ( 1 )
{
putc(39, stdout);
v3 = *v2;
if ( *v2 <= 39 )
break;
if ( (_BYTE)v3 != 92 )
goto LABEL_6;
putc(92, stdout);
v5 = v2[1];
fputc(v5, stdout);
if ( v5 == 92 )
{
v2 += 2;
}
else
{
putc(v2[2], stdout);
v7 = v2[3];
v2 += 4;
putc(v7, stdout);
}
LABEL_7:
result = putc(39, stdout);
if ( *v2 )
{
v6 = v1 + 1;
if ( v6 <= 15 )
{
result = putc(44, stdout);
}
else
{
result = fwrite(",\n ", 1uLL, 7uLL, stdout);
++outlineno;
}
v1 = v6 & 0xF;
if ( *v2 )
continue;
}
return result;
}
if ( (char)v3 > 7 )
{
switch ( (char)v3 )
{
case 8:
++v2;
fwrite(&unk_397, 1uLL, 2uLL, stdout);
break;
case 9:
++v2;
fwrite("\\t", 1uLL, 2uLL, stdout);
break;
case 10:
++v1;
++v2;
fwrite("\\012", 1uLL, 4uLL, stdout);
break;
case 12:
++v2;
fwrite(&unk_39A, 1uLL, 2uLL, stdout);
break;
case 13:
++v1;
++v2;
fwrite("\\015", 1uLL, 4uLL, stdout);
break;
case 34:
++v2;
fwrite(&unk_394, 1uLL, 2uLL, stdout);
break;
case 39:
++v2;
fwrite(&unk_391, 1uLL, 2uLL, stdout);
break;
default:
goto LABEL_6;
}
goto LABEL_7;
}
LABEL_6:
--v1;
++v2;
putc(v3, stdout);
goto LABEL_7;
}
return result;
}

original_code:
void PSWOutputStringChars(char *s)
{
    register char *c = s;
    register char b;
    register int perline = 0;
    while (*c != '\0') {
    putc('\'',stdout);
    switch (b = *c++) {
     case '\\':
         putc('\\',stdout);
  fputc(b = *c++,stdout);
         if (b != '\\') {putc(*c++,stdout);putc(*c++,stdout);}
  break;
     case '\'':
         fprintf(stdout,"\\'");
  break;
     case '\"':
         fprintf(stdout,"\\\"");
  break;
     case '\b':
         fprintf(stdout,"\\b");
  break;
     case '\f':
         fprintf(stdout,"\\f");
  break;
     case '\012':
         fprintf(stdout,"\\012"); perline++;
  break;
     case '\015':
         fprintf(stdout,"\\015"); perline++;
  break;
     case '\t':
         fprintf(stdout,"\\t");
  break;
     default:
  putc(b,stdout); perline--;
  break;
 }
 putc('\'',stdout);
 if (*c != '\0') {
     if (++perline >= 16) {
  fprintf(stdout,",\n     ");
  outlineno++;
     }
     else {putc(',',stdout);}
     perline %= 16;
 }
    }
}

variable_types: b char

variable_types: perline int


PSWHexStringLength

decompiled_code:
__int64 __fastcall PSWHexStringLength(const char *a1)
{
return (unsigned int)((int)(strlen(a1) + 1) / 2);
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
return (unsigned int)((int)(strlen(a1) + 1) / 2);
}

original_code:
int PSWHexStringLength(char *s)
{
    return ((int) (strlen(s)+1)/2);
}


PSWOutputHexStringChars

decompiled_code:
int __fastcall PSWOutputHexStringChars(unsigned __int8 *a1)
{
int result; // eax
unsigned __int8 *v2; // rbx
unsigned __int8 *v3; // rdx
int v4; // ebp
char v5; // al
int v6; // ebp
char v7[27]; // [rsp+Dh] [rbp-1Bh] BYREF

result = *a1;
v7[2] = 0;
v7[0] = result;
if ( (_BYTE)result )
{
v2 = a1;
v3 = a1 + 1;
v4 = 0;
do
{
v5 = v2[1];
v2 += 2;
v7[1] = v5;
if ( !v5 )
v2 = v3;
result = fprintf(stdout, "0x%s", v7);
if ( !*v2 )
break;
v6 = v4 + 1;
if ( v6 <= 15 )
{
putc(44, stdout);
}
else
{
fwrite(",\n ", 1uLL, 7uLL, stdout);
++outlineno;
}
result = *v2;
v4 = v6 & 0xF;
v3 = v2 + 1;
v7[0] = result;
}
while ( (_BYTE)result );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned __int8 *a1)
{
int result; // eax
unsigned __int8 *v2; // rbx
unsigned __int8 *v3; // rdx
int v4; // ebp
char v5; // al
int v6; // ebp
char v7[27]; // [rsp+Dh] [rbp-1Bh] BYREF

result = *a1;
v7[2] = 0;
v7[0] = result;
if ( (_BYTE)result )
{
v2 = a1;
v3 = a1 + 1;
v4 = 0;
do
{
v5 = v2[1];
v2 += 2;
v7[1] = v5;
if ( !v5 )
v2 = v3;
result = fprintf(stdout, "0x%s", v7);
if ( !*v2 )
break;
v6 = v4 + 1;
if ( v6 <= 15 )
{
putc(44, stdout);
}
else
{
fwrite(",\n ", 1uLL, 7uLL, stdout);
++outlineno;
}
result = *v2;
v4 = v6 & 0xF;
v3 = v2 + 1;
v7[0] = result;
}
while ( (_BYTE)result );
}
return result;
}

original_code:
void PSWOutputHexStringChars(register char *s)
{
    register int perline = 0;
    char tmp[3];
    tmp[2] ='\0';
    while ((tmp[0] = *s++)!= '\0') {
 tmp[1] = *s ? *s++ : '\0';
 fprintf(stdout,"0x%s",tmp);
 if (*s != '\0') {
     if (++perline >= 16) {
  fprintf(stdout,",\n     ");
  outlineno++;
     }
     else {putc(',',stdout);}
     perline %= 16;
 }
    }
}

canonical_original_code:
void PSWOutputHexStringChars(char *s)
{
    register int perline = 0;
    char tmp[3];
    tmp[2] ='\0';
    while ((tmp[0] = *s++)!= '\0') {
 tmp[1] = *s ? *s++ : '\0';
 fprintf(stdout,"0x%s",tmp);
 if (*s != '\0') {
     if (++perline >= 16) {
  fprintf(stdout,",\n     ");
  outlineno++;
     }
     else {putc(',',stdout);}
     perline %= 16;
 }
    }
}

variable_types:
tmp
char [3]


original_code:
static void
print_xcolors (XColor *colors, int ncolors)
{
 register XColor *c;
 register int i;
 int planes;
 for (c = colors; c < colors + ncolors; c++) {
            planes = c->red | c->green | c->blue;
            for(i = 4; i > 1 && (planes&0xf)==0; i--) {
                c->red >>= 4;
                c->green >>= 4;
                c->blue >>= 4;
                planes >>= 4;
            }
            printf("#%0*x%0*x%0*x\n", i, c->red, i, c->green, i, c->blue);
 }
}

canonical_original_code:
static void print_xcolors(struct XColor *colors, int ncolors)
{
 register struct XColor *c;
 register int i;
 int planes;
 for (c = colors; c < colors + ncolors; c++) {
            planes = c->red | c->green | c->blue;
            for(i = 4; i > 1 && (planes&0xf)==0; i--) {
                c->red >>= 4;
                c->green >>= 4;
                c->blue >>= 4;
                planes >>= 4;
            }
            printf("#%0*x%0*x%0*x\n", i, c->red, i, c->green, i, c->blue);
 }
}

variable_types: struct XColor { unsigned long pixel; unsigned short red; char flags; char pad; } *

variable_types: ncolors int

variable_types: planes int


hsbramp

original_code:
void
hsbramp(
    double h1,
    double s1,
    double b1,
    double h2,
    double s2,
    double b2,
    int count,
    u_char *red,
    u_char *green,
    u_char *blue)
{
    double dh;
    double ds;
    double db;
    dh = (h2 - h1) / count;
    ds = (s2 - s1) / count;
    db = (b2 - b1) / count;
    while (count--) {
 hsb2rgb(h1, s1, b1, red++, green++, blue++);
 h1 += dh;
 s1 += ds;
 b1 += db;
    }
}

canonical_original_code:
void hsbramp(double h1, double s1, double b1, double h2, double s2, double b2, int count, unsigned char *red, unsigned char *green, unsigned char *blue)
{
    double dh;
    double ds;
    double db;
    dh = (h2 - h1) / count;
    ds = (s2 - s1) / count;
    db = (b2 - b1) / count;
    while (count--) {
 hsb2rgb(h1, s1, b1, red++, green++, blue++);
 h1 += dh;
 s1 += ds;
 b1 += db;
    }
}

variable_types: count int

variable_types:
red
unsigned char *

variable_types:
green
unsigned char *

variable_types:
blue
unsigned char *

variable_types: dh double

variable_types: ds double

variable_types: db double


original_code:
static void
hsb2rgb(
    double H,
    double S,
    double B,
    u_char *r,
    u_char *g,
    u_char *b)
{
    int i;
    double f;
    double bb;
    u_char p;
    u_char q;
    u_char t;
    H -= floor(H);
    H *= 6.0;
    i = floor(H);
    f = H - (float) i;
    bb = 255.0 * B;
    p = (u_char) (bb * (1.0 - S));
    q = (u_char) (bb * (1.0 - (S * f)));
    t = (u_char) (bb * (1.0 - (S * (1.0 - f))));
    switch (i) {
    case 0:
 *r = (u_char) bb;
 *g = t;
 *b = p;
 break;
    case 1:
 *r = q;
 *g = (u_char) bb;
 *b = p;
 break;
    case 2:
 *r = p;
 *g = (u_char) bb;
 *b = t;
 break;
    case 3:
 *r = p;
 *g = q;
 *b = (u_char) bb;
 break;
    case 4:
 *r = t;
 *g = p;
 *b = (u_char) bb;
 break;
    case 5:
 *r = (u_char) bb;
 *g = p;
 *b = q;
 break;
    }
}

canonical_original_code:
static void hsb2rgb(double H, double S, double B, unsigned char *r, unsigned char *g, unsigned char *b)
{
    int i;
    double f;
    double bb;
    unsigned char p;
    unsigned char q;
    unsigned char t;
    H -= floor(H);
    H *= 6.0;
    i = floor(H);
    f = H - (float) i;
    bb = 255.0 * B;
    p = (u_char) (bb * (1.0 - S));
    q = (u_char) (bb * (1.0 - (S * f)));
    t = (u_char) (bb * (1.0 - (S * (1.0 - f))));
    switch (i) {
    case 0:
 *r = (unsigned char) bb;
 *g = t;
 *b = p;
 break;
    case 1:
 *r = q;
 *g = (unsigned char) bb;
 *b = p;
 break;
    case 2:
 *r = p;
 *g = (unsigned char) bb;
 *b = t;
 break;
    case 3:
 *r = p;
 *g = q;
 *b = (unsigned char) bb;
 break;
    case 4:
 *r = t;
 *g = p;
 *b = (unsigned char) bb;
 break;
    case 5:
 *r = (unsigned char) bb;
 *g = p;
 *b = q;
 break;
    }
}

variable_types: H double

variable_types: S double

variable_types: B double

variable_types:
r
unsigned char *

variable_types:
g
unsigned char *

variable_types:
b
unsigned char *

variable_types: i int

variable_types: f double

variable_types: bb double

variable_types:
p
unsigned char

variable_types:
q
unsigned char

variable_types:
t
unsigned char


decompiled_code:
__int64 init_fates()
{
__int64 i; // rsi
__int64 result; // rax
int v2; // ecx

for ( i = 0LL; i != 256; ++i )
{
result = (unsigned int)i;
v2 = 0;
if ( !i )
{
LABEL_6:
fates[i] = 2;
continue;
}
do
{
++v2;
result = ((_DWORD)result - 1) & (unsigned int)result;
}
while ( (_DWORD)result );
if ( v2 == 3 )
{
fates[i] = 0;
}
else
{
if ( v2 != 2 )
goto LABEL_6;
fates[i] = 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 i; // rsi
__int64 result; // rax
int v2; // ecx

for ( i = 0LL; i != 256; ++i )
{
result = (unsigned int)i;
v2 = 0;
if ( !i )
{
LABEL_6:
fates[i] = 2;
continue;
}
do
{
++v2;
result = ((_DWORD)result - 1) & (unsigned int)result;
}
while ( (_DWORD)result );
if ( v2 == 3 )
{
fates[i] = 0;
}
else
{
if ( v2 != 2 )
goto LABEL_6;
fates[i] = 1;
}
}
return result;
}

original_code:
static void
init_fates()
{
    int i, bits, neighbors;
    for (i = 0; i < 256; i++) {
 neighbors = 0;
 for (bits = i; bits; bits &= (bits - 1))
     neighbors++;
 if (neighbors == 3)
     fates[i] = 0;
 else if (neighbors == 2)
     fates[i] = 1;
 else
     fates[i] = 2;
    }
}

canonical_original_code:
static void init_fates()
{
    int i; int bits; int neighbors;
    for (i = 0; i < 256; i++) {
 neighbors = 0;
 for (bits = i; bits; bits &= (bits - 1))
     neighbors++;
 if (neighbors == 3)
     fates[i] = 0;
 else if (neighbors == 2)
     fates[i] = 1;
 else
     fates[i] = 2;
    }
}

variable_types: bits int

variable_types: neighbors int


repo: aszlig/striptimes

decompiled_code:
__int64 __fastcall patch_gzip(int fd)
{
__int64 result; // rax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = 0;
if ( lseek(fd, 4LL, 0) == -1 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(write(fd, buf, 4uLL) == -1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
__int64 result; // rax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = 0;
if ( lseek(fd, 4LL, 0) == -1 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(write(fd, buf, 4uLL) == -1);
return result;
}

original_code:
int patch_gzip(int fd)
{
    const int32_t ts = 0;
    if (lseek(fd, 4, 0) == -1) return -1;
    if (write(fd, &ts, 4) == -1) return -1;
    return 0;
}

canonical_original_code:
int patch_gzip(int fd)
{
    int ts = 0;
    if (lseek(fd, 4, 0) == -1) return -1;
    if (write(fd, &ts, 4) == -1) return -1;
    return 0;
}

variable_types: fd int

variable_types: ts int


decompiled_code:
__int64 __fastcall patch_ar(int fd)
{
unsigned int v1; // eax
unsigned int v2; // er8
int v3; // eax
char buf[2]; // [rsp+4h] [rbp-14h] BYREF
char nptr[18]; // [rsp+6h] [rbp-12h] BYREF

if ( lseek(fd, 7LL, 0) == -1 )
return (unsigned int)-1;
while ( 1 )
{
while ( 1 )
{
v1 = read(fd, buf, 1uLL);
v2 = v1;
if ( v1 != 1 )
break;
if ( buf[0] != 10 )
goto LABEL_4;
}
if ( !v1 )
return v2;
LABEL_4:
if ( lseek(fd, 15LL, 1) == -1
|| write(fd, "0 ", 0xCuLL) == -1
|| lseek(fd, 20LL, 1) == -1
|| read(fd, nptr, 0xAuLL) != 10
|| read(fd, buf, 2uLL) != 2 )
{
return (unsigned int)-1;
}
if ( buf[0] != 96 || buf[1] != 10 )
break;
v3 = atoi(nptr);
if ( lseek(fd, v3, 1) == -1 )
return (unsigned int)-1;
}
*_errno_location() = 22;
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd)
{
unsigned int v1; // eax
unsigned int v2; // er8
int v3; // eax
char buf[2]; // [rsp+4h] [rbp-14h] BYREF
char nptr[18]; // [rsp+6h] [rbp-12h] BYREF

if ( lseek(fd, 7LL, 0) == -1 )
return (unsigned int)-1;
while ( 1 )
{
while ( 1 )
{
v1 = read(fd, buf, 1uLL);
v2 = v1;
if ( v1 != 1 )
break;
if ( buf[0] != 10 )
goto LABEL_4;
}
if ( !v1 )
return v2;
LABEL_4:
if ( lseek(fd, 15LL, 1) == -1
|| write(fd, "0 ", 0xCuLL) == -1
|| lseek(fd, 20LL, 1) == -1
|| read(fd, nptr, 0xAuLL) != 10
|| read(fd, buf, 2uLL) != 2 )
{
return (unsigned int)-1;
}
if ( buf[0] != 96 || buf[1] != 10 )
break;
v3 = atoi(nptr);
if ( lseek(fd, v3, 1) == -1 )
return (unsigned int)-1;
}
*_errno_location() = 22;
return (unsigned int)-1;
}

original_code:
int patch_ar(int fd)
{
    int len;
    char buf[2];
    char size[10];
    if (lseek(fd, 7, 0) == -1) return -1;
    for (;;) {
        while ((len = read(fd, buf, 1)) == 1)
            if (*buf != '\n') break;
        if (len == 0)
            break;
        if (lseek(fd, 15, 1) == -1) return -1;
        if (write(fd, "0           ", 12) == -1) return -1;
        if (lseek(fd, 20, 1) == -1) return -1;
        if (read(fd, size, 10) != 10) return -1;
        if (read(fd, buf, 2) != 2) return -1;
        if (buf[0] != '`' || buf[1] != '\n') {
            (*__errno_location ()) = 22;
            return -1;
        }
        if (lseek(fd, atoi(size), 1) == -1) return -1;
    }
    return 0;
}

variable_types: len int

variable_types:
buf
char [2]

variable_types:
size
char [10]


main

decompiled_code:
__int64 __fastcall main(int a1, char **a2, char **a3)
{
char **v3; // rbx
__int64 v4; // rbp
__int64 v5; // rdi
__int64 result; // rax

if ( a1 <= 1 )
{
fprintf(stderr, "Usage: %s FILENAME...\n", *a2);
result = 1LL;
}
else
{
v3 = &a2[a1 - 1];
v4 = (__int64)&v3[-(a1 - 2) - 1];
do
{
v5 = (__int64)*v3--;
sub_401220(v5, a2, a3);
}
while ( v3 != (char **)v4 );
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall main(int a1, char **a2, char **a3)
{
char **v3; // rbx
__int64 v4; // rbp
__int64 v5; // rdi
__int64 result; // rax

if ( a1 <= 1 )
{
fprintf(stderr, "Usage: %s FILENAME...\n", *a2);
result = 1LL;
}
else
{
v3 = &a2[a1 - 1];
v4 = (__int64)&v3[-(a1 - 2) - 1];
do
{
v5 = (__int64)*v3--;
func6(v5, a2, a3);
}
while ( v3 != (char **)v4 );
result = 0LL;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    if (argc <= 1) {
        fprintf(stderr, "Usage: %s FILENAME...\n", argv[0]);
        return 1;
    }
    while (argc-- > 1)
        progress(argv[argc]);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: atecle/CacheSim

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // er12
int v5; // eax
const char *v6; // r13
const char *v7; // r15
unsigned int v8; // er14
const char *v10; // rdi
int v11; // eax
int v12; // esi
int v13; // edi
void *v14; // rsp
__int64 v15; // rax
bool v16; // cl
bool v17; // dl
_BYTE v18[8]; // [rsp+0h] [rbp-40h] BYREF
_BYTE *v19; // [rsp+8h] [rbp-38h]

checkInput(argc, argv, envp);
v4 = atoi(argv[1]);
v5 = atoi(argv[3]);
v6 = argv[2];
v7 = argv[5];
v8 = v5;
if ( v6[5] == 58 )
{
v10 = argv[2];
v19 = v18;
v11 = strlen(v10);
v12 = v11 - 6;
v13 = v11;
v14 = alloca(v11 - 6);
if ( v11 > 6 )
{
v15 = 7LL;
do
{
v18[v15 - 7] = v6[v15 - 1];
v16 = v12 > (int)v15 - 6;
v17 = v13 > (int)v15++;
}
while ( v17 && v16 );
}
}
direct(argv[6], v4, v8, v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // er12
int v5; // eax
const char *v6; // r13
const char *v7; // r15
unsigned int v8; // er14
const char *v10; // rdi
int v11; // eax
int v12; // esi
int v13; // edi
void *v14; // rsp
__int64 v15; // rax
bool v16; // cl
bool v17; // dl
_BYTE v18[8]; // [rsp+0h] [rbp-40h] BYREF
_BYTE *v19; // [rsp+8h] [rbp-38h]

checkInput(argc, argv, envp);
v4 = atoi(argv[1]);
v5 = atoi(argv[3]);
v6 = argv[2];
v7 = argv[5];
v8 = v5;
if ( v6[5] == 58 )
{
v10 = argv[2];
v19 = v18;
v11 = strlen(v10);
v12 = v11 - 6;
v13 = v11;
v14 = alloca(v11 - 6);
if ( v11 > 6 )
{
v15 = 7LL;
do
{
v18[v15 - 7] = v6[v15 - 1];
v16 = v12 > (int)v15 - 6;
v17 = v13 > (int)v15++;
}
while ( v17 && v16 );
}
}
func12(argv[6], v4, v8, v7);
return 0;
}

original_code:
int main (int argc, char **argv)
{
    checkInput(argc, argv);
    int cache_size = atoi(argv[1]);
    int block_size = atoi(argv[3]);
    int num_lines;
    int num_sets;
    char *w_pol = argv[5];
    if (strcmp(argv[2], "direct")) {
        num_lines = 1;
        num_sets = cache_size/(block_size);
    }
    if (strcmp(argv[2], "assoc")) {
        num_sets = 1;
        num_lines = cache_size/block_size;
    }
    if (argv[2][5] == ':') {
        char *input = argv[2];
        int len = strlen(input);
        char n_way[len - 6];
        int i;
        int j;
        for (i = 6, j = 0; i < len && j < (len - 6); i++, j++)
        {
            n_way[j] = argv[2][i];
        }
        num_lines = atoi(n_way);
    }
    direct(argv[6], cache_size, block_size, w_pol);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    checkInput(argc, argv);
    int cache_size = atoi(argv[1]);
    int block_size = atoi(argv[3]);
    int num_lines;
    int num_sets;
    char *w_pol = argv[5];
    if (strcmp(argv[2], "direct")) {
        num_lines = 1;
        num_sets = cache_size/(block_size);
    }
    if (strcmp(argv[2], "assoc")) {
        num_sets = 1;
        num_lines = cache_size/block_size;
    }
    if (argv[2][5] == ':') {
        char *input = argv[2];
        int len = strlen(input);
        char n_way[-1];
        int i;
        int j;
        for (i = 6, j = 0; i < len && j < (len - 6); i++, j++)
        {
            n_way[j] = argv[2][i];
        }
        num_lines = atoi(n_way);
    }
    direct(argv[6], cache_size, block_size, w_pol);
    return 0;
}

variable_types:
argv
char **

variable_types:
input
char *

variable_types: j int


help

decompiled_code:
void __noreturn help()
{
fwrite("<USAGE>: ", 1uLL, 9uLL, stderr);
fwrite(
"sim [-h] <cache size> <associativity> <block size> <replace alg> <write policy> <trace file>\n",
1uLL,
0x5DuLL,
stderr);
fputc(10, stderr);
fwrite("[-h]: Display usage information \n", 1uLL, 0x21uLL, stderr);
fputc(10, stderr);
fwrite(
"<cache size>: Total size of cache. Must be power of two and must equal to (number of sets x <set size> x <block size>) \n",
1uLL,
0x78uLL,
stderr);
fputc(10, stderr);
fwrite("<associativity>: 'direct', 'assoc', or 'assoc:n' \n", 1uLL, 0x32uLL, stderr);
fputc(10, stderr);
fwrite("\t'direct' simulates direct mapped cache.\n", 1uLL, 0x29uLL, stderr);
fwrite("\t'assoc' simulates a fully associative cache'. \n", 1uLL, 0x30uLL, stderr);
fwrite("\t'assoc:n' simulates an n-way associative cache. n must be a power of two.\n", 1uLL, 0x4BuLL, stderr);
fputc(10, stderr);
fwrite("<block size>: Must be power of 2, specifies size of cache block.\n", 1uLL, 0x41uLL, stderr);
fputc(10, stderr);
fwrite("<replace alg> : 'FIFO', 'LRU', or 'Random' \n", 1uLL, 0x2CuLL, stderr);
fputc(10, stderr);
fwrite("\t'FIFO' simulates first in first out replacement algorithm.\n", 1uLL, 0x3CuLL, stderr);
fwrite("\t 'LRU' simulates least recently used replacement algorithm.\n", 1uLL, 0x3DuLL, stderr);
fwrite("\t 'Random' simulates random replacement algorithm.\n", 1uLL, 0x33uLL, stderr);
fputc(10, stderr);
fwrite("<write policy>: 'wt' simulates write through cache. 'wb' simulates write back cache\n", 1uLL, 0x54uLL, stderr);
fputc(10, stderr);
fwrite(
"<trace file>: name of the file that contains memory access traces generated using Pin.\n",
1uLL,
0x57uLL,
stderr);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
fwrite("<USAGE>: ", 1uLL, 9uLL, stderr);
fwrite(
"sim [-h] <cache size> <associativity> <block size> <replace alg> <write policy> <trace file>\n",
1uLL,
0x5DuLL,
stderr);
fputc(10, stderr);
fwrite("[-h]: Display usage information \n", 1uLL, 0x21uLL, stderr);
fputc(10, stderr);
fwrite(
"<cache size>: Total size of cache. Must be power of two and must equal to (number of sets x <set size> x <block size>) \n",
1uLL,
0x78uLL,
stderr);
fputc(10, stderr);
fwrite("<associativity>: 'direct', 'assoc', or 'assoc:n' \n", 1uLL, 0x32uLL, stderr);
fputc(10, stderr);
fwrite("\t'direct' simulates direct mapped cache.\n", 1uLL, 0x29uLL, stderr);
fwrite("\t'assoc' simulates a fully associative cache'. \n", 1uLL, 0x30uLL, stderr);
fwrite("\t'assoc:n' simulates an n-way associative cache. n must be a power of two.\n", 1uLL, 0x4BuLL, stderr);
fputc(10, stderr);
fwrite("<block size>: Must be power of 2, specifies size of cache block.\n", 1uLL, 0x41uLL, stderr);
fputc(10, stderr);
fwrite("<replace alg> : 'FIFO', 'LRU', or 'Random' \n", 1uLL, 0x2CuLL, stderr);
fputc(10, stderr);
fwrite("\t'FIFO' simulates first in first out replacement algorithm.\n", 1uLL, 0x3CuLL, stderr);
fwrite("\t 'LRU' simulates least recently used replacement algorithm.\n", 1uLL, 0x3DuLL, stderr);
fwrite("\t 'Random' simulates random replacement algorithm.\n", 1uLL, 0x33uLL, stderr);
fputc(10, stderr);
fwrite("<write policy>: 'wt' simulates write through cache. 'wb' simulates write back cache\n", 1uLL, 0x54uLL, stderr);
fputc(10, stderr);
fwrite(
"<trace file>: name of the file that contains memory access traces generated using Pin.\n",
1uLL,
0x57uLL,
stderr);
exit(0);
}

original_code:
void help() {
    fprintf(stderr, "<USAGE>: ");
    fprintf(stderr,"sim [-h] <cache size> <associativity> <block size> <replace alg> <write policy> <trace file>\n");
    fprintf(stderr,"\n");
    fprintf(stderr,"[-h]: Display usage information \n");
    fprintf(stderr,"\n");
    fprintf(stderr, "<cache size>: Total size of cache. Must be power of two and must equal to (number of sets x <set size> x <block size>) \n");
    fprintf(stderr, "\n");
    fprintf(stderr, "<associativity>: 'direct', 'assoc', or 'assoc:n' \n");
    fprintf(stderr, "\n");
    fprintf(stderr, "\t'direct' simulates direct mapped cache.\n");
    fprintf(stderr, "\t'assoc' simulates a fully associative cache'. \n");
    fprintf(stderr, "\t'assoc:n' simulates an n-way associative cache. n must be a power of two.\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "<block size>: Must be power of 2, specifies size of cache block.\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "<replace alg> : 'FIFO', 'LRU', or 'Random' \n");
    fprintf(stderr, "\n");
    fprintf(stderr, "\t'FIFO' simulates first in first out replacement algorithm.\n");
    fprintf(stderr, "\t 'LRU' simulates least recently used replacement algorithm.\n");
    fprintf(stderr, "\t 'Random' simulates random replacement algorithm.\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "<write policy>: 'wt' simulates write through cache. 'wb' simulates write back cache\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "<trace file>: name of the file that contains memory access traces generated using Pin.\n");
    exit(0);
}


decompiled_code:
__int64 __fastcall isPower2(int a1)
{
return ((a1 & (a1 - 1)) == 0) & (unsigned __int8)(a1 > 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return ((a1 & (a1 - 1)) == 0) & (unsigned __int8)(a1 > 0);
}

variable_types: x int


getBlock

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

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

original_code:
int getBlock(int w, int b) {
    int mask = (1 << b) - 1;
    int block = w & mask;
    return block;
}

variable_types: w int

variable_types: b int

variable_types: mask int

variable_types: block int


getSetIndex

decompiled_code:
// attributes: thunk
__int64 __fastcall getSetIndex(int a1, char a2)
{
return getBlock(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, char a2)
{
return func9(a1, a2);
}

original_code:
int getSetIndex(int w, int s) {
    int mask = (1 << s) - 1;
    int set_index = w & mask;
    return set_index;
}

variable_types: s int


isHit

decompiled_code:
__int64 __fastcall isHit(__int64 a1, int a2, unsigned int a3)
{
unsigned int *v3; // rsi
__int64 result; // rax

v3 = (unsigned int *)(a1 + 16LL * a2);
result = *v3;
if ( (_DWORD)result )
{
result = 1LL;
if ( v3[1] != a3 )
{
v3[1] = a3;
result = 0LL;
}
}
else
{
*v3 = 1;
v3[1] = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2, unsigned int a3)
{
unsigned int *v3; // rsi
__int64 result; // rax

v3 = (unsigned int *)(a1 + 16LL * a2);
result = *v3;
if ( (_DWORD)result )
{
result = 1LL;
if ( v3[1] != a3 )
{
v3[1] = a3;
result = 0LL;
}
}
else
{
*v3 = 1;
v3[1] = a3;
}
return result;
}

original_code:
int isHit(struct Address *cache, int set_index, int tag) {
    if (cache[set_index].valid_bit == 0) {
        cache[set_index].valid_bit = 1;
        cache[set_index].tag = tag;
        return 0;
    }
    else {
        if (cache[set_index].tag == tag)
        {
            return 1;
        }
        cache[set_index].tag = tag;
        return 0;
    }
}

variable_types: struct Address { int valid_bit; int tag; int set_index; int dirty_bit; } *

variable_types: tag int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rdx
__int64 v5; // rax
char v7[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = my_malloc(4LL, argv, envp);
my_free(v3);
my_free(v3);
my_free(v7);
v5 = my_malloc(4LL, argv, v4);
my_free(v5);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rdx
__int64 v5; // rax
char v7[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = func8(4LL, argv, envp);
func9(v3);
func9(v3);
func9(v7);
v5 = func8(4LL, argv, v4);
func9(v5);
return 1;
}

original_code:
int main(int argc, char **argv) {
    int *x = my_malloc(sizeof(int));
    my_free(x);
    my_free(x);
    int y;
    my_free(&y);
    char *t = my_malloc(4);
    my_free(t);
    return 1;
}

variable_types:
x
int *

variable_types: y int

variable_types:
t
char *


decompiled_code:
void __fastcall remove_from_arr(__int64 a1)
{
__int64 v1; // rax

if ( i > 0 )
{
v1 = 0LL;
while ( arr[v1] != a1 )
{
if ( ++v1 == i )
return;
}
arr[(int)v1] = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
__int64 v1; // rax

if ( i > 0 )
{
v1 = 0LL;
while ( arr[v1] != a1 )
{
if ( ++v1 == i )
return;
}
arr[(int)v1] = 0LL;
}
}

original_code:
void remove_from_arr(MemEntry *p){
 int j;
 for(j=0;j<i;j++){
  if(p == arr[j]){
   arr[j]= ((void *)0);
   return;
  }
 }
}

canonical_original_code:
void remove_from_arr(struct MemEntry *p){
 int j;
 for(j=0;j<i;j++){
  if(p == arr[j]){
   arr[j]= ((void *)0);
   return;
  }
 }
}

variable_types: struct MemEntry { struct MemEntry *prev; struct MemEntry *succ; unsigned int size; int isfree; } *


original_code:
void *
my_malloc( unsigned int size )
{
 struct MemEntry * p;
 struct MemEntry * succ;
 p = root;
 while ( p != 0 )
 {
  if ( p->size < size )
  {
   p = p->succ;
  }
  else if ( !p->isfree )
  {
   p = p->succ;
  }
  else if ( p->size < (size + sizeof(struct MemEntry)) )
  {
   p->isfree = 0;
   remove_from_arr(p);
   return (char *)p + sizeof(struct MemEntry);
  }
  else
  {
   succ = (struct MemEntry *)((char *)p + sizeof(struct MemEntry) + size);
   succ->prev = p;
   succ->succ = p->succ;
   if(p->succ != 0)
    p->succ->prev = succ;
   p->succ = succ;
   succ->size = p->size - sizeof(struct MemEntry) - size;
   succ->isfree = 1;
   p->size = size;
   p->isfree = 0;
   last = (p == last) ? succ : last;
   remove_from_arr(p);
   return (char *)p + sizeof(struct MemEntry);
  }
 }
 if ( (p = (struct MemEntry *)sbrk( sizeof(struct MemEntry) + size )) == (void *)-1 )
 {
  return 0;
 }
 else if ( last == 0 )
 {
  printf( "BKR making first chunk size %d\n", size );
  p->prev = 0;
  p->succ = 0;
  p->size = size;
  p->isfree = 0;
  root = last = p;
  return (char *)p + sizeof(struct MemEntry);
 }
 else
 {
  printf( "BKR making another chunk size %d\n", size );
  p->prev = last;
  p->succ = last->succ;
  p->size = size;
  p->isfree = 0;
  last->succ = p;
  last = p;
  return (char *)p + sizeof(struct MemEntry);
 }
 return 0;
}

canonical_original_code:
void *my_malloc(unsigned int size)
{
 struct MemEntry *p;
 struct MemEntry *succ;
 p = root;
 while ( p != 0 )
 {
  if ( p->size < size )
  {
   p = p->succ;
  }
  else if ( !p->isfree )
  {
   p = p->succ;
  }
  else if ( p->size < (size + sizeof(struct MemEntry)) )
  {
   p->isfree = 0;
   remove_from_arr(p);
   return (char *)p + sizeof(struct MemEntry);
  }
  else
  {
   succ = (struct MemEntry *)((char *)p + sizeof(struct MemEntry) + size);
   succ->prev = p;
   succ->succ = p->succ;
   if(p->succ != 0)
    p->succ->prev = succ;
   p->succ = succ;
   succ->size = p->size - sizeof(struct MemEntry) - size;
   succ->isfree = 1;
   p->size = size;
   p->isfree = 0;
   last = (p == last) ? succ : last;
   remove_from_arr(p);
   return (char *)p + sizeof(struct MemEntry);
  }
 }
 if ( (p = (struct MemEntry *)sbrk( sizeof(struct MemEntry) + size )) == (void *)-1 )
 {
  return 0;
 }
 else if ( last == 0 )
 {
  printf( "BKR making first chunk size %d\n", size );
  p->prev = 0;
  p->succ = 0;
  p->size = size;
  p->isfree = 0;
  root = last = p;
  return (char *)p + sizeof(struct MemEntry);
 }
 else
 {
  printf( "BKR making another chunk size %d\n", size );
  p->prev = last;
  p->succ = last->succ;
  p->size = size;
  p->isfree = 0;
  last->succ = p;
  last = p;
  return (char *)p + sizeof(struct MemEntry);
 }
 return 0;
}

variable_types:
size
unsigned int

return_type: void *

user_defined_types: struct MemEntry { struct MemEntry *prev; struct MemEntry *succ; unsigned int size; int isfree; }


original_code:
void
my_free( void * p )
{
 struct MemEntry * ptr;
 struct MemEntry * pred;
 struct MemEntry * succ;
 ptr = (struct MemEntry *)((char *)p - sizeof(struct MemEntry));
    struct MemEntry *temp = root;
    while (root != 0) {
        if (ptr == root) {
            break;
        }
        root = root->succ;
        if(root == 0){
            printf("<ERROR>: Has not been malloc or freed already\n");
            root = temp;
            return;
        }
    }
    int j;
    for (j = 0; j < i; j++) {
        if (ptr == arr[j]) {
            printf("<ERROR>: Has already been freed\n");
            return;
        }
    }
    root = temp;
 if ( (pred = ptr->prev) != 0 && pred->isfree )
 {
  pred->size += sizeof(struct MemEntry) + ptr->size;
  pred->succ = ptr->succ;
  ptr->isfree=1;
  pred->succ = ptr->succ;
  if(ptr->succ != 0)
   ptr->succ->prev = pred;
  printf( "BKR freeing block %#x merging with predecessor new size is %d.\n", p, pred->size );
 }
 else
 {
  printf( "BKR freeing block %#x.\n", p );
        arr[i++] = ptr;
  ptr->isfree = 1;
  pred = ptr;
 }
 if ( (succ = ptr->succ) != 0 && succ->isfree )
 {
  pred->size += sizeof(struct MemEntry) + succ->size;
  pred->succ = succ->succ;
  pred->isfree = 1;
  if(succ->succ != 0)
   succ->succ->prev=pred;
        arr[i++] = ptr;
  printf( "BKR freeing block %#x merging with successor new size is %d.\n", p, pred->size );
 }
}

canonical_original_code:
void my_free(void *p)
{
 struct MemEntry *ptr;
 struct MemEntry *pred;
 struct MemEntry *succ;
 ptr = (struct MemEntry *)((char *)p - sizeof(struct MemEntry));
    struct MemEntry *temp = root;
    while (root != 0) {
        if (ptr == root) {
            break;
        }
        root = root->succ;
        if(root == 0){
            printf("<ERROR>: Has not been malloc or freed already\n");
            root = temp;
            return;
        }
    }
    int j;
    for (j = 0; j < i; j++) {
        if (ptr == arr[j]) {
            printf("<ERROR>: Has already been freed\n");
            return;
        }
    }
    root = temp;
 if ( (pred = ptr->prev) != 0 && pred->isfree )
 {
  pred->size += sizeof(struct MemEntry) + ptr->size;
  pred->succ = ptr->succ;
  ptr->isfree=1;
  pred->succ = ptr->succ;
  if(ptr->succ != 0)
   ptr->succ->prev = pred;
  printf( "BKR freeing block %#x merging with predecessor new size is %d.\n", p, pred->size );
 }
 else
 {
  printf( "BKR freeing block %#x.\n", p );
        arr[i++] = ptr;
  ptr->isfree = 1;
  pred = ptr;
 }
 if ( (succ = ptr->succ) != 0 && succ->isfree )
 {
  pred->size += sizeof(struct MemEntry) + succ->size;
  pred->succ = succ->succ;
  pred->isfree = 1;
  if(succ->succ != 0)
   succ->succ->prev=pred;
        arr[i++] = ptr;
  printf( "BKR freeing block %#x merging with successor new size is %d.\n", p, pred->size );
 }
}

variable_types:
p
void *


repo: atenart/SimpleDroidRPC

decompiled_code:
__int64 set_async()
{
__int64 result; // rax

result = cur_method;
*(_DWORD *)(cur_method + 24) = 1;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

result = cur_method;
*(_DWORD *)(cur_method + 24) = 1;
return result;
}

original_code:
void set_async () {
  cur_method->async = 1;
}

canonical_original_code:
void set_async() {
  cur_method->async = 1;
}


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

result = cur_method;
*(_QWORD *)(cur_method + 16) = a1;
return result;
}

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

result = cur_method;
*(_QWORD *)(cur_method + 16) = a1;
return result;
}

original_code:
void set_return (char* type) {
  cur_method->ret_type = type;
}

canonical_original_code:
void set_return(char *type) {
  cur_method->ret_type = type;
}

variable_types:
type
char *