main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx

if ( argc <= 1 )
v3 = boot_modem_i9250(argc, argv, envp);
else
v3 = boot_modem_i9100(argc, argv, envp);
if ( v3 < 0 )
printf("[xmm6260-sec]: E/failed to boot modem at %s:%s:%d\n", "modem-ctl.c", "main", 41LL);
return v3;
}

original_code:
int main(int argc, char** argv) {
 int ret;
 if (argc > 1) {
  ret = boot_modem_i9100();
 }
 else {
  ret = boot_modem_i9250();
 }
 if (ret < 0) {
  do { printf("[" "xmm6260-sec" "]: " "E/" "failed to boot modem" " at %s:%s:%d\n", "modem-ctl.c", __func__, 41); } while (0);
  goto fail;
 }
 else {
  do {} while (0);
 }
fail:
 return ret;
}

canonical_original_code:
int main(int argc, char **argv) {
 int ret;
 if (argc > 1) {
  ret = boot_modem_i9100();
 }
 else {
  ret = boot_modem_i9250();
 }
 if (ret < 0) {
  do { printf("[" "xmm6260-sec" "]: " "E/" "failed to boot modem" " at %s:%s:%d\n", "modem-ctl.c", __func__, 41); } while (0);
  goto fail;
 }
 else {
  do {} while (0);
 }
fail:
 return ret;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall c_ioctl(unsigned int a1, unsigned __int64 a2)
{
int v2; // ebx
int *v4; // rax
char *v5; // rax

v2 = ioctl(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
printf(
"[xmm6260-sec]: E/ioctl fd=%d code=%lx failed: %s at %s:%s:%d\n",
a1,
a2,
v5,
"io_helpers.c",
"c_ioctl",
41LL);
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned __int64 a2)
{
int v2; // ebx
int *v4; // rax
char *v5; // rax

v2 = ioctl(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
printf(
"[xmm6260-sec]: E/ioctl fd=%d code=%lx failed: %s at %s:%s:%d\n",
a1,
a2,
v5,
"io_helpers.c",
"c_ioctl",
41LL);
}
return (unsigned int)v2;
}

original_code:
int c_ioctl(int fd, unsigned long code, void* data) {
 int ret;
 if (!data) {
  ret = ioctl(fd, code);
 }
 else {
  ret = ioctl(fd, code, data);
 }
 if (ret < 0) {
  do { printf("[" "xmm6260-sec" "]: " "E/" "ioctl fd=%d code=%lx failed: %s" " at %s:%s:%d\n", fd, code, strerror((*__errno_location ())), "io_helpers.c", __func__, 41); } while (0);
 }
 else {
  do {} while (0);
 }
 return ret;
}

canonical_original_code:
int c_ioctl(int fd, unsigned long code, void *data) {
 int ret;
 if (!data) {
  ret = ioctl(fd, code);
 }
 else {
  ret = ioctl(fd, code, data);
 }
 if (ret < 0) {
  do { printf("[" "xmm6260-sec" "]: " "E/" "ioctl fd=%d code=%lx failed: %s" " at %s:%s:%d\n", fd, code, strerror((*__errno_location ())), "io_helpers.c", __func__, 41); } while (0);
 }
 else {
  do {} while (0);
 }
 return ret;
}

variable_types: fd int

variable_types:
code
unsigned long

variable_types:
data
void *

variable_types: ret int

return_type: int


decompiled_code:
__int64 __fastcall read_select(signed int a1, unsigned int a2)
{
int v2; // ebp
int *v4; // rax
char *v5; // rax
fd_set v6; // [rsp+0h] [rbp-A8h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-28h] BYREF

timeout.tv_sec = a2 / 0x3E8;
timeout.tv_usec = 1000 * (a2 % 0x3E8);
memset(&v6, 0, sizeof(v6));
v6.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
v2 = select(a1 + 1, &v6, 0LL, 0LL, &timeout);
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
printf(
"[xmm6260-sec]: E/failed to select the fd %d ret=%d: %s at %s:%s:%d\n",
(unsigned int)a1,
(unsigned int)v2,
v5,
"io_helpers.c",
"read_select",
65LL);
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(signed int a1, unsigned int a2)
{
int v2; // ebp
int *v4; // rax
char *v5; // rax
fd_set v6; // [rsp+0h] [rbp-A8h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-28h] BYREF

timeout.tv_sec = a2 / 0x3E8;
timeout.tv_usec = 1000 * (a2 % 0x3E8);
memset(&v6, 0, sizeof(v6));
v6.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
v2 = select(a1 + 1, &v6, 0LL, 0LL, &timeout);
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
printf(
"[xmm6260-sec]: E/failed to select the fd %d ret=%d: %s at %s:%s:%d\n",
(unsigned int)a1,
(unsigned int)v2,
v5,
"io_helpers.c",
"read_select",
65LL);
}
return (unsigned int)v2;
}

original_code:
int read_select(int fd, unsigned timeout) {
 int ret = 0;
 struct timeval tv = {
  tv.tv_sec = timeout / 1000,
  tv.tv_usec = 1000 * (timeout % 1000),
 };
 fd_set read_set;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&read_set)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ret = select(fd + 1, &read_set, 0, 0, &tv);
 if (ret < 0) {
  do { printf("[" "xmm6260-sec" "]: " "E/" "failed to select the fd %d ret=%d: %s" " at %s:%s:%d\n", fd, ret, strerror((*__errno_location ())), "io_helpers.c", __func__, 65); } while (0);
  goto fail;
 }
 if (ret < 1 || !((((&read_set)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
  do {} while (0);
  goto fail;
 }
fail:
 return ret;
}

canonical_original_code:
int read_select(int fd, unsigned int timeout) {
 int ret = 0;
 struct timeval tv = {
  tv.tv_sec = timeout / 1000,
  tv.tv_usec = 1000 * (timeout % 1000),
 };
 struct fd_set read_set;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&read_set)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ret = select(fd + 1, &read_set, 0, 0, &tv);
 if (ret < 0) {
  do { printf("[" "xmm6260-sec" "]: " "E/" "failed to select the fd %d ret=%d: %s" " at %s:%s:%d\n", fd, ret, strerror((*__errno_location ())), "io_helpers.c", __func__, 65); } while (0);
  goto fail;
 }
 if (ret < 1 || !((((&read_set)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
  do {} while (0);
  goto fail;
 }
fail:
 return ret;
}

variable_types:
timeout
unsigned int

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


receive

decompiled_code:
__int64 __fastcall receive(int fd, void *buf, size_t nbytes)
{
int v4; // eax
unsigned int v5; // ebx

v4 = read_select(fd, 0x32u);
if ( v4 > 0 )
return (unsigned int)read(fd, buf, nbytes);
v5 = v4;
printf("[xmm6260-sec]: E/failed to select the fd %d at %s:%s:%d\n", (unsigned int)fd, "io_helpers.c", "receive", 81LL);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf, size_t nbytes)
{
int v4; // eax
unsigned int v5; // ebx

v4 = func1(fd, 0x32u);
if ( v4 > 0 )
return (unsigned int)read(fd, buf, nbytes);
v5 = v4;
printf("[xmm6260-sec]: E/failed to select the fd %d at %s:%s:%d\n", (unsigned int)fd, "io_helpers.c", "receive", 81LL);
return v5;
}

original_code:
int receive(int fd, void *buf, size_t size) {
 int ret;
 if ((ret = read_select(fd, 50)) < 1) {
  do { printf("[" "xmm6260-sec" "]: " "E/" "failed to select the fd %d" " at %s:%s:%d\n", fd, "io_helpers.c", __func__, 81); } while (0);
  return ret;
 }
 else {
  do {} while (0);
 }
 return read(fd, buf, size);
}

canonical_original_code:
int receive(int fd, void *buf, unsigned long size) {
 int ret;
 if ((ret = read_select(fd, 50)) < 1) {
  do { printf("[" "xmm6260-sec" "]: " "E/" "failed to select the fd %d" " at %s:%s:%d\n", fd, "io_helpers.c", __func__, 81); } while (0);
  return ret;
 }
 else {
  do {} while (0);
 }
 return read(fd, buf, size);
}

variable_types:
buf
void *

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall expect_data(int a1, const void *a2, size_t a3)
{
void *v4; // rsp
unsigned int v5; // er12
_BYTE v7[32]; // [rsp+0h] [rbp-20h] BYREF

v4 = alloca(a3);
if ( (int)receive(a1, v7, a3) == a3 )
{
v5 = memcmp(v7, a2, a3);
hexdump(v7, a3);
}
else
{
printf("[xmm6260-sec]: E/failed to receive data at %s:%s:%d\n", "io_helpers.c", "expect_data", 96LL);
v5 = -1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, const void *a2, size_t a3)
{
void *v4; // rsp
unsigned int v5; // er12
_BYTE v7[32]; // [rsp+0h] [rbp-20h] BYREF

v4 = alloca(a3);
if ( (int)func2(a1, v7, a3) == a3 )
{
v5 = memcmp(v7, a2, a3);
hexdump(v7, a3);
}
else
{
printf("[xmm6260-sec]: E/failed to receive data at %s:%s:%d\n", "io_helpers.c", "expect_data", 96LL);
v5 = -1;
}
return v5;
}

original_code:
int expect_data(int fd, void *data, size_t size) {
 int ret;
 char buf[size];
 if ((ret = receive(fd, buf, size)) != size) {
  ret = -1;
  do { printf("[" "xmm6260-sec" "]: " "E/" "failed to receive data" " at %s:%s:%d\n", "io_helpers.c", __func__, 96); } while (0);
  return ret;
 }
 ret = memcmp(buf, data, size);
 hexdump(buf, size);
 return ret;
}

canonical_original_code:
int expect_data(int fd, void *data, unsigned long size) {
 int ret;
 char buf[-1];
 if ((ret = receive(fd, buf, size)) != size) {
  ret = -1;
  do { printf("[" "xmm6260-sec" "]: " "E/" "failed to receive data" " at %s:%s:%d\n", "io_helpers.c", __func__, 96); } while (0);
  return ret;
 }
 ret = memcmp(buf, data, size);
 hexdump(buf, size);
 return ret;
}

variable_types:
buf
char [-1]


hexdump

decompiled_code:
int __fastcall hexdump(char *a1, unsigned __int64 a2)
{
char *v2; // rbx
char *v3; // rbp
int result; // eax
__int64 v5[6]; // [rsp+0h] [rbp-58h] BYREF
char v6; // [rsp+30h] [rbp-28h]

if ( a2 )
{
v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
v5[4] = 0LL;
v5[5] = 0LL;
v6 = 0;
v2 = a1;
v3 = (char *)v5;
if ( a2 > 0x10 )
a2 = 16LL;
do
{
result = snprintf(v3, 4uLL, "%02x ", (unsigned int)*v2++);
v3 += 3;
}
while ( v2 != &a1[a2] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *a1, unsigned __int64 a2)
{
char *v2; // rbx
char *v3; // rbp
int result; // eax
__int64 v5[6]; // [rsp+0h] [rbp-58h] BYREF
char v6; // [rsp+30h] [rbp-28h]

if ( a2 )
{
v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
v5[4] = 0LL;
v5[5] = 0LL;
v6 = 0;
v2 = a1;
v3 = (char *)v5;
if ( a2 > 0x10 )
a2 = 16LL;
do
{
result = snprintf(v3, 4uLL, "%02x ", (unsigned int)*v2++);
v3 += 3;
}
while ( v2 != &a1[a2] );
}
return result;
}

original_code:
void hexdump(void* data, size_t size) {
 if (size < 1) {
  return;
 }
 char *_data = (char*)data;
 char __hd_buf[16 * 3 + 1];
 size_t len = size < 16 ? size : 16;
 memset(__hd_buf, 0, sizeof(__hd_buf));
 int i;
 for (i = 0; i < len; i++) {
  snprintf(__hd_buf + i * 3, 4, "%02x ", _data[i]);
 }
 __hd_buf[sizeof(__hd_buf) - 1] = '\0';
 do {} while (0);
}

canonical_original_code:
void hexdump(void *data, unsigned long size) {
 if (size < 1) {
  return;
 }
 char *_data = (char*)data;
 char __hd_buf[-1];
 unsigned long len = size < 16 ? size : 16;
 memset(__hd_buf, 0, sizeof(__hd_buf));
 int i;
 for (i = 0; i < len; i++) {
  snprintf(__hd_buf + i * 3, 4, "%02x ", _data[i]);
 }
 __hd_buf[sizeof(__hd_buf) - 1] = '\0';
 do {} while (0);
}

variable_types:
len
unsigned long

variable_types: i int

return_type: void


Parse

repo: aszeszo/xnv

decompiled_code:
void __fastcall Parse(int a1, __int64 a2)
{
int i; // ebp
char v4; // al
int v5; // er8
int v6; // edi
char *v7; // rsi
char v8; // r9
char v9; // dl
_BYTE *v10; // rdx

if ( a1 > 1 )
{
for ( i = a1; i > 1; --i )
{
v10 = *(_BYTE **)(a2 + 8);
if ( *v10 == 45 )
{
if ( !strcmp(*(const char **)(a2 + 8), "-display") )
{
display_name = *(char **)(a2 + 16);
a2 += 8LL;
--i;
}
else if ( !strcmp(*(const char **)(a2 + 8), "-timeout") )
{
timeout = atoi(*(const char **)(a2 + 16));
a2 += 8LL;
--i;
}
else
{
v4 = v10[1];
if ( v4 )
{
v5 = verbose;
v6 = showall;
v7 = v10 + 1;
v8 = 0;
v9 = 0;
do
{
if ( v4 == 97 )
{
++v6;
v9 = 1;
}
else
{
if ( v4 != 118 )
{
if ( v9 )
showall = v6;
if ( v8 )
verbose = v5;
fprintf(stderr, "%s: -%c: unknown option\n", (const char *)cmdname, (unsigned int)v4);
usage();
}
++v5;
v8 = 1;
}
*(_QWORD *)(a2 + 8) = v7++;
v4 = *v7;
}
while ( *v7 );
if ( v9 )
showall = v6;
if ( v8 )
verbose = v5;
}
}
}
else if ( !strcmp(*(const char **)(a2 + 8), "x11") )
{
AddProto(1);
}
else if ( !strcmp(*(const char **)(a2 + 8), "news") )
{
AddProto(2);
}
else if ( !strcmp(*(const char **)(a2 + 8), "x11news") )
{
AddProto(3);
}
else
{
if ( strcmp(*(const char **)(a2 + 8), "sunview") )
{
fprintf(stderr, "%s: %s: unknown protocol\n", (const char *)cmdname, *(const char **)(a2 + 8));
usage();
}
AddProto(4);
}
a2 += 8LL;
}
}
if ( !n_proto )
{
fprintf(stderr, "%s: no protocols specified\n", (const char *)cmdname);
usage();
}
}

canonical_decompiled_code:
void __fastcall func8(int a1, __int64 a2)
{
int i; // ebp
char v4; // al
int v5; // er8
int v6; // edi
char *v7; // rsi
char v8; // r9
char v9; // dl
_BYTE *v10; // rdx

if ( a1 > 1 )
{
for ( i = a1; i > 1; --i )
{
v10 = *(_BYTE **)(a2 + 8);
if ( *v10 == 45 )
{
if ( !strcmp(*(const char **)(a2 + 8), "-display") )
{
display_name = *(char **)(a2 + 16);
a2 += 8LL;
--i;
}
else if ( !strcmp(*(const char **)(a2 + 8), "-timeout") )
{
timeout = atoi(*(const char **)(a2 + 16));
a2 += 8LL;
--i;
}
else
{
v4 = v10[1];
if ( v4 )
{
v5 = verbose;
v6 = showall;
v7 = v10 + 1;
v8 = 0;
v9 = 0;
do
{
if ( v4 == 97 )
{
++v6;
v9 = 1;
}
else
{
if ( v4 != 118 )
{
if ( v9 )
showall = v6;
if ( v8 )
verbose = v5;
fprintf(stderr, "%s: -%c: unknown option\n", (const char *)cmdname, (unsigned int)v4);
func7();
}
++v5;
v8 = 1;
}
*(_QWORD *)(a2 + 8) = v7++;
v4 = *v7;
}
while ( *v7 );
if ( v9 )
showall = v6;
if ( v8 )
verbose = v5;
}
}
}
else if ( !strcmp(*(const char **)(a2 + 8), "x11") )
{
AddProto(1);
}
else if ( !strcmp(*(const char **)(a2 + 8), "news") )
{
AddProto(2);
}
else if ( !strcmp(*(const char **)(a2 + 8), "x11news") )
{
AddProto(3);
}
else
{
if ( strcmp(*(const char **)(a2 + 8), "sunview") )
{
fprintf(stderr, "%s: %s: unknown protocol\n", (const char *)cmdname, *(const char **)(a2 + 8));
func7();
}
AddProto(4);
}
a2 += 8LL;
}
}
if ( !n_proto )
{
fprintf(stderr, "%s: no protocols specified\n", (const char *)cmdname);
func7();
}
}

original_code:
static void
Parse (int argc, char* argv[])
{
    for (;argc > 1; argv++, argc--) {
 if (argv[1][0] == '-') {
     if (!strcmp(argv[1], "-display")) {
  display_name=argv[2];
  argv++;
  argc--;
  continue;
     }
     if (!strcmp(argv[1], "-timeout")) {
                timeout = atoi(argv[2]);
                argv++;
                argc--;
                continue;
            }
     for (; argv[1][1]; argv[1]++) {
         switch (argv[1][1]) {
         case 'a':
      showall++;
      break;
  case 'v':
      verbose++;
      break;
  default:
      fprintf(stderr, "%s: -%c: unknown option\n",
       cmdname,argv[1][1]);
      usage();
         }
     }
 }
 else {
     if (!strcmp(argv[1], "x11")) {
  AddProto(1);
     } else if (!strcmp(argv[1], "news")) {
  AddProto(2);
     } else if (!strcmp(argv[1], "x11news")) {
  AddProto(3);
     } else if (!strcmp(argv[1], "sunview")) {
  AddProto(4);
     } else {
  fprintf(stderr, "%s: %s: unknown protocol\n",
   cmdname,argv[1]);
  usage();
     }
 }
    }
    if (!n_proto) {
 fprintf(stderr, "%s: no protocols specified\n",
  cmdname);
 usage();
    }
}

canonical_original_code:
static void Parse(int argc, char *argv[])
{
    for (;argc > 1; argv++, argc--) {
 if (argv[1][0] == '-') {
     if (!strcmp(argv[1], "-display")) {
  display_name=argv[2];
  argv++;
  argc--;
  continue;
     }
     if (!strcmp(argv[1], "-timeout")) {
                timeout = atoi(argv[2]);
                argv++;
                argc--;
                continue;
            }
     for (; argv[1][1]; argv[1]++) {
         switch (argv[1][1]) {
         case 'a':
      showall++;
      break;
  case 'v':
      verbose++;
      break;
  default:
      fprintf(stderr, "%s: -%c: unknown option\n",
       cmdname,argv[1][1]);
      usage();
         }
     }
 }
 else {
     if (!strcmp(argv[1], "x11")) {
  AddProto(1);
     } else if (!strcmp(argv[1], "news")) {
  AddProto(2);
     } else if (!strcmp(argv[1], "x11news")) {
  AddProto(3);
     } else if (!strcmp(argv[1], "sunview")) {
  AddProto(4);
     } else {
  fprintf(stderr, "%s: %s: unknown protocol\n",
   cmdname,argv[1]);
  usage();
     }
 }
    }
    if (!n_proto) {
 fprintf(stderr, "%s: no protocols specified\n",
  cmdname);
 usage();
    }
}

variable_types:
argv
char *[]


ConnectToX

decompiled_code:
_BOOL8 __fastcall ConnectToX(char *a1)
{
unsigned int v1; // ebp
Display *v2; // rbx

v1 = timeout;
if ( (int)timeout > 0 )
{
signal(14, OnAlarm);
alarm(v1);
}
v2 = XOpenDisplay(a1);
display = v2;
if ( (int)timeout > 0 )
alarm(0);
return v2 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(char *a1)
{
unsigned int v1; // ebp
Display *v2; // rbx

v1 = timeout;
if ( (int)timeout > 0 )
{
signal(14, OnAlarm);
alarm(v1);
}
v2 = XOpenDisplay(a1);
display = v2;
if ( (int)timeout > 0 )
alarm(0);
return v2 != 0LL;
}

original_code:
static int
ConnectToX (const char* display_name)
{
     if(timeout > 0){
       signal(14, OnAlarm);
       alarm(timeout);
     }
     display=XOpenDisplay(display_name);
     if(timeout > 0)
       alarm(0);
     return((display != ((void *)0)));
}

canonical_original_code:
static int ConnectToX(char *display_name)
{
     if(timeout > 0){
       signal(14, OnAlarm);
       alarm(timeout);
     }
     display=XOpenDisplay(display_name);
     if(timeout > 0)
       alarm(0);
     return((display != ((void *)0)));
}


OnAlarm

decompiled_code:
void __noreturn OnAlarm()
{
fwrite("winsysck timeout\n", 1uLL, 0x11uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func10()
{
fwrite("winsysck timeout\n", 1uLL, 0x11uLL, stderr);
exit(1);
}

original_code:
static void OnAlarm(int i)
{
      fprintf(stderr, "winsysck timeout\n");
      exit(1);
}


Probe

decompiled_code:
void __noreturn Probe()
{
__int64 v0; // rbx
int v1; // ebp
__int64 v2; // r8

v0 = 0LL;
v1 = 0;
do
{
v2 = (unsigned int)proto_list[v0];
if ( !(_DWORD)v2 )
break;
if ( (_DWORD)v2 == 1 )
{
if ( ConnectToX(display_name) )
{
++v1;
if ( verbose )
puts("x11");
DisconnectFromX();
if ( !showall )
exit(0);
}
}
else if ( (unsigned int)(v2 - 2) > 2 )
{
fprintf(stderr, "%s: WSGO: proto_list[%d]==%d\n", (const char *)cmdname, (unsigned int)v0, v2);
}
++v0;
}
while ( v0 != 4 );
exit(v1 == 0);
}

canonical_decompiled_code:
void __noreturn func12()
{
__int64 v0; // rbx
int v1; // ebp
__int64 v2; // r8

v0 = 0LL;
v1 = 0;
do
{
v2 = (unsigned int)proto_list[v0];
if ( !(_DWORD)v2 )
break;
if ( (_DWORD)v2 == 1 )
{
if ( func9(display_name) )
{
++v1;
if ( verbose )
puts("x11");
func11();
if ( !showall )
exit(0);
}
}
else if ( (unsigned int)(v2 - 2) > 2 )
{
fprintf(stderr, "%s: WSGO: proto_list[%d]==%d\n", (const char *)cmdname, (unsigned int)v0, v2);
}
++v0;
}
while ( v0 != 4 );
exit(v1 == 0);
}

original_code:
static void
Probe(void)
{
    int i, found=0;
    for(i=0; (i < 4) && (proto_list[i] != 0); i++) {
 switch (proto_list[i]) {
 case 1:
     if (ConnectToX(display_name)) {
  found++;
  if (verbose) printf("%s\n","x11");
         DisconnectFromX();
  if (!showall) exit(0);
     }
     break;
 case 2:
 case 3:
 case 4:
     break;
 default:
     fprintf(stderr, "%s: WSGO: proto_list[%d]==%d\n",
      cmdname,i,proto_list[i]);
 }
    }
    exit(!found);
}

canonical_original_code:
static void Probe()
{
    int i; int found = 0;
    for(i=0; (i < 4) && (proto_list[i] != 0); i++) {
 switch (proto_list[i]) {
 case 1:
     if (ConnectToX(display_name)) {
  found++;
  if (verbose) printf("%s\n","x11");
         DisconnectFromX();
  if (!showall) exit(0);
     }
     break;
 case 2:
 case 3:
 case 4:
     break;
 default:
     fprintf(stderr, "%s: WSGO: proto_list[%d]==%d\n",
      cmdname,i,proto_list[i]);
 }
    }
    exit(!found);
}

variable_types: found int


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"usage: %s %s\n\t%s\n",
(const char *)cmdname,
"[-va] [-display display_name] [-timeout seconds] protocol [...]",
"protocol can be one of: x11 news x11news sunview");
exit(2);
}

canonical_decompiled_code:
void __noreturn func7()
{
fprintf(
stderr,
"usage: %s %s\n\t%s\n",
(const char *)cmdname,
"[-va] [-display display_name] [-timeout seconds] protocol [...]",
"protocol can be one of: x11 news x11news sunview");
exit(2);
}

original_code:
static void
usage () {
    fprintf(stderr, "usage: %s %s\n\t%s\n", cmdname,
     "[-va] [-display display_name] [-timeout seconds] protocol [...]",
     "protocol can be one of: x11 news x11news sunview");
    exit(2);
}

canonical_original_code:
static void usage() {
    fprintf(stderr, "usage: %s %s\n\t%s\n", cmdname,
     "[-va] [-display display_name] [-timeout seconds] protocol [...]",
     "protocol can be one of: x11 news x11news sunview");
    exit(2);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
cmdname = (__int64)*argv;
Parse(argc, (__int64)argv);
Probe();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
cmdname = (__int64)*argv;
func8(argc, (__int64)argv);
func12();
}

original_code:
int
main (int argc, char* argv[])
{
    cmdname=argv[0];
    Parse(argc,argv);
    Probe();
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    cmdname=argv[0];
    Parse(argc,argv);
    Probe();
    exit(0);
}


dumpCmap

decompiled_code:
int dumpCmap()
{
unsigned __int64 i; // rax
unsigned __int16 *v1; // rbx
unsigned int j; // ebp
int result; // eax
XColor v4[257]; // [rsp+0h] [rbp-1018h] BYREF

for ( i = 0LL; i != 256; ++i )
v4[i].pixel = i;
XQueryColors(dsp, dsp->screens[(__int64)screen].cmap, v4, 256);
v1 = &v4[0].red;
for ( j = 0; j != 256; ++j )
{
result = printf(
"/name%02x\t%3d %3d %3d RGBcolor def\n",
j,
(unsigned __int8)HIBYTE(*v1),
*((unsigned __int8 *)v1 + 3),
*((unsigned __int8 *)v1 + 5));
v1 += 8;
}
return result;
}

canonical_decompiled_code:
int func0()
{
unsigned __int64 i; // rax
unsigned __int16 *v1; // rbx
unsigned int j; // ebp
int result; // eax
XColor v4[257]; // [rsp+0h] [rbp-1018h] BYREF

for ( i = 0LL; i != 256; ++i )
v4[i].pixel = i;
XQueryColors(dsp, dsp->screens[(__int64)screen].cmap, v4, 256);
v1 = &v4[0].red;
for ( j = 0; j != 256; ++j )
{
result = printf(
"/name%02x\t%3d %3d %3d RGBcolor def\n",
j,
(unsigned __int8)HIBYTE(*v1),
*((unsigned __int8 *)v1 + 3),
*((unsigned __int8 *)v1 + 5));
v1 += 8;
}
return result;
}

original_code:
static void
dumpCmap(void)
{
    register int i;
    XColor color[256];
    for (i = 0; i < 256; i++)
 color[i].pixel = i;
    XQueryColors(dsp, ((&((_XPrivDisplay)(dsp))->screens[screen])->cmap), color, 256);
    for (i = 0; i < 256; i++) {
 printf("/name%02x	%3d %3d %3d RGBcolor def\n",
       i, color[i].red >> 8, color[i].green >> 8, color[i].blue >> 8);
    }
}

canonical_original_code:
static void dumpCmap()
{
    register int i;
    struct XColor color[256];
    for (i = 0; i < 256; i++)
 color[i].pixel = i;
    XQueryColors(dsp, ((&((_XPrivDisplay)(dsp))->screens[screen])->cmap), color, 256);
    for (i = 0; i < 256; i++) {
 printf("/name%02x	%3d %3d %3d RGBcolor def\n",
       i, color[i].red >> 8, color[i].green >> 8, color[i].blue >> 8);
    }
}

variable_types: struct XColor { unsigned long pixel; unsigned short red; char flags; char pad; } [256]


decompiled_code:
__int64 __fastcall redisplay_direct(Drawable a1)
{
int v1; // edx
bool v2; // zf
int v3; // ecx
int v4; // eax
int v5; // er13
int i; // ebx
int v7; // er12
int v8; // er13
int k; // ebx
int v10; // er12
int v11; // er13
int l; // ebx
int v13; // er12
__int64 result; // rax
float v15; // [rsp+0h] [rbp-48h]
int v16; // [rsp+4h] [rbp-44h]
unsigned int v17; // [rsp+4h] [rbp-44h]
int v18; // [rsp+8h] [rbp-40h]
int j; // [rsp+8h] [rbp-40h]
int v20; // [rsp+8h] [rbp-40h]
float v21; // [rsp+Ch] [rbp-3Ch]

v21 = *(float *)&LC1;
v15 = *(float *)&LC2;
if ( win == a1 )
{
v15 = (float)width * 0.0625;
v21 = (float)height / 48.0;
}
if ( !got_offsets_3 )
{
got_offsets_3 = 1;
v1 = -1;
v2 = !_BitScanForward((unsigned int *)&v3, visual->red_mask);
if ( v2 )
v3 = -1;
roffset_2 = v3;
v2 = !_BitScanForward((unsigned int *)&v3, visual->green_mask);
if ( v2 )
v3 = -1;
goffset_1 = v3;
v2 = !_BitScanForward((unsigned int *)&v4, visual->blue_mask);
if ( !v2 )
v1 = v4;
boffset_0 = v1;
}
v18 = 0;
v16 = 0;
do
{
v5 = (int)(float)((float)v16++ * v21);
for ( i = 0;
i != 16;
XFillRectangle(
dsp,
a1,
gc,
v7,
v5,
(int)(float)((float)((float)i * v15) - (float)v7),
(int)(float)((float)((float)v16 * v21) - (float)v5)) )
{
v7 = (int)(float)((float)i++ * v15);
XSetForeground(dsp, gc, (v18 - 1 + i) << roffset_2);
}
v18 += 16;
}
while ( v16 != 16 );
for ( j = 0; j != 256; j += 16 )
{
v8 = (int)(float)((float)v16++ * v21);
for ( k = 0;
k != 16;
XFillRectangle(
dsp,
a1,
gc,
v10,
v8,
(int)(float)((float)((float)k * v15) - (float)v10),
(int)(float)((float)((float)v16 * v21) - (float)v8)) )
{
v10 = (int)(float)((float)k++ * v15);
XSetForeground(dsp, gc, (j - 1 + k) << goffset_1);
}
}
v17 = 0;
v20 = 32;
do
{
v11 = (int)(float)((float)v20++ * v21);
for ( l = 0;
l != 16;
XFillRectangle(
dsp,
a1,
gc,
v13,
v11,
(int)(float)((float)((float)l * v15) - (float)v13),
(int)(float)((float)((float)v20 * v21) - (float)v11)) )
{
v13 = (int)(float)((float)l++ * v15);
XSetForeground(dsp, gc, (int)((v17 - 1 + l) << boffset_0));
}
v17 += 16;
result = v17;
}
while ( v17 != 256 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(Drawable a1)
{
int v1; // edx
bool v2; // zf
int v3; // ecx
int v4; // eax
int v5; // er13
int i; // ebx
int v7; // er12
int v8; // er13
int k; // ebx
int v10; // er12
int v11; // er13
int l; // ebx
int v13; // er12
__int64 result; // rax
float v15; // [rsp+0h] [rbp-48h]
int v16; // [rsp+4h] [rbp-44h]
unsigned int v17; // [rsp+4h] [rbp-44h]
int v18; // [rsp+8h] [rbp-40h]
int j; // [rsp+8h] [rbp-40h]
int v20; // [rsp+8h] [rbp-40h]
float v21; // [rsp+Ch] [rbp-3Ch]

v21 = *(float *)&LC1;
v15 = *(float *)&LC2;
if ( win == a1 )
{
v15 = (float)width * 0.0625;
v21 = (float)height / 48.0;
}
if ( !got_offsets_3 )
{
got_offsets_3 = 1;
v1 = -1;
v2 = !_BitScanForward((unsigned int *)&v3, visual->red_mask);
if ( v2 )
v3 = -1;
roffset_2 = v3;
v2 = !_BitScanForward((unsigned int *)&v3, visual->green_mask);
if ( v2 )
v3 = -1;
goffset_1 = v3;
v2 = !_BitScanForward((unsigned int *)&v4, visual->blue_mask);
if ( !v2 )
v1 = v4;
boffset_0 = v1;
}
v18 = 0;
v16 = 0;
do
{
v5 = (int)(float)((float)v16++ * v21);
for ( i = 0;
i != 16;
XFillRectangle(
dsp,
a1,
gc,
v7,
v5,
(int)(float)((float)((float)i * v15) - (float)v7),
(int)(float)((float)((float)v16 * v21) - (float)v5)) )
{
v7 = (int)(float)((float)i++ * v15);
XSetForeground(dsp, gc, (v18 - 1 + i) << roffset_2);
}
v18 += 16;
}
while ( v16 != 16 );
for ( j = 0; j != 256; j += 16 )
{
v8 = (int)(float)((float)v16++ * v21);
for ( k = 0;
k != 16;
XFillRectangle(
dsp,
a1,
gc,
v10,
v8,
(int)(float)((float)((float)k * v15) - (float)v10),
(int)(float)((float)((float)v16 * v21) - (float)v8)) )
{
v10 = (int)(float)((float)k++ * v15);
XSetForeground(dsp, gc, (j - 1 + k) << goffset_1);
}
}
v17 = 0;
v20 = 32;
do
{
v11 = (int)(float)((float)v20++ * v21);
for ( l = 0;
l != 16;
XFillRectangle(
dsp,
a1,
gc,
v13,
v11,
(int)(float)((float)((float)l * v15) - (float)v13),
(int)(float)((float)((float)v20 * v21) - (float)v11)) )
{
v13 = (int)(float)((float)l++ * v15);
XSetForeground(dsp, gc, (int)((v17 - 1 + l) << boffset_0));
}
v17 += 16;
result = v17;
}
while ( v17 != 256 );
return result;
}

original_code:
static void
redisplay_direct(Window window)
{
    register int i,
                j, k;
    register float fw;
    register float fh;
    static int roffset, goffset, boffset;
    static int got_offsets = 0;
    if (window == win) {
 fw = (float) width / 16.0;
 fh = (float) height / (3 * 16.0);
    } else {
 fw = (float) 48 / 16.0;
 fh = (float) 48 / (3 * 16.0);
    }
    if (!got_offsets) {
 got_offsets = 1;
 roffset = ffs(visual->red_mask)-1;
 goffset = ffs(visual->green_mask)-1;
 boffset = ffs(visual->blue_mask)-1;
    }
    k = 0;
    for (i = 0; i < 16; i++, k++) {
 register int y = (int) (k * fh);
 register int h = (k + 1) * fh - y;
 for (j = 0; j < 16; j++) {
     register int x = (int) (j * fw);
     register int w = (j + 1) * fw - x;
     XSetForeground(dsp, gc, (i * 16 + j)<<roffset);
     XFillRectangle(dsp, window, gc, x, y, w, h);
 }
    }
    for (i = 0; i < 16; i++, k++) {
 register int y = (int) (k * fh);
 register int h = (k + 1) * fh - y;
 for (j = 0; j < 16; j++) {
     register int x = (int) (j * fw);
     register int w = (j + 1) * fw - x;
     XSetForeground(dsp, gc, (i * 16 + j)<<goffset);
     XFillRectangle(dsp, window, gc, x, y, w, h);
 }
    }
    for (i = 0; i < 16; i++, k++) {
 register int y = (int) (k * fh);
 register int h = (k + 1) * fh - y;
 for (j = 0; j < 16; j++) {
     register int x = (int) (j * fw);
     register int w = (j + 1) * fw - x;
     XSetForeground(dsp, gc, (i * 16 + j)<<boffset);
     XFillRectangle(dsp, window, gc, x, y, w, h);
 }
    }
}

canonical_original_code:
static void redisplay_direct(unsigned long window)
{
    register int i; register int j; register int k;
    register float fw;
    register float fh;
    static int roffset; static int goffset; static int boffset;
    static int got_offsets = 0;
    if (window == win) {
 fw = (float) width / 16.0;
 fh = (float) height / (3 * 16.0);
    } else {
 fw = (float) 48 / 16.0;
 fh = (float) 48 / (3 * 16.0);
    }
    if (!got_offsets) {
 got_offsets = 1;
 roffset = ffs(visual->red_mask)-1;
 goffset = ffs(visual->green_mask)-1;
 boffset = ffs(visual->blue_mask)-1;
    }
    k = 0;
    for (i = 0; i < 16; i++, k++) {
 register int y = (int) (k * fh);
 register int h = (k + 1) * fh - y;
 for (j = 0; j < 16; j++) {
     register int x = (int) (j * fw);
     register int w = (j + 1) * fw - x;
     XSetForeground(dsp, gc, (i * 16 + j)<<roffset);
     XFillRectangle(dsp, window, gc, x, y, w, h);
 }
    }
    for (i = 0; i < 16; i++, k++) {
 register int y = (int) (k * fh);
 register int h = (k + 1) * fh - y;
 for (j = 0; j < 16; j++) {
     register int x = (int) (j * fw);
     register int w = (j + 1) * fw - x;
     XSetForeground(dsp, gc, (i * 16 + j)<<goffset);
     XFillRectangle(dsp, window, gc, x, y, w, h);
 }
    }
    for (i = 0; i < 16; i++, k++) {
 register int y = (int) (k * fh);
 register int h = (k + 1) * fh - y;
 for (j = 0; j < 16; j++) {
     register int x = (int) (j * fw);
     register int w = (j + 1) * fw - x;
     XSetForeground(dsp, gc, (i * 16 + j)<<boffset);
     XFillRectangle(dsp, window, gc, x, y, w, h);
 }
    }
}

variable_types:
window
unsigned long

variable_types: j int

variable_types: k int

variable_types: fw float

variable_types: fh float

variable_types: roffset int

variable_types: goffset int

variable_types: boffset int

variable_types: y int

variable_types: h int

variable_types: x int

variable_types: w int


decompiled_code:
int __fastcall redisplay_indexed(Drawable a1)
{
int v1; // er14
double v2; // xmm0_8
double v3; // xmm0_8
int result; // eax
int v5; // er13
unsigned __int64 v6; // rbp
int v7; // ebx
int v8; // er12
float v9; // [rsp+Ch] [rbp-5Ch]
unsigned __int64 v10; // [rsp+18h] [rbp-50h]
int v11; // [rsp+20h] [rbp-48h]
float v12; // [rsp+24h] [rbp-44h]

v1 = cmap_size;
if ( cmap_size == 16 )
{
v1 = 4;
}
else if ( cmap_size == 256 )
{
v1 = 16;
}
else if ( cmap_size != 2 )
{
v2 = (double)cmap_size;
if ( (double)cmap_size < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
v1 = (int)v3;
}
result = a1;
if ( win == a1 )
{
v9 = (float)width / (float)v1;
v12 = (float)height / (float)v1;
}
else
{
v9 = 48.0 / (float)v1;
v12 = v9;
}
if ( v1 > 0 )
{
v10 = 0LL;
v11 = 0;
do
{
v5 = (int)(float)((float)v11++ * v12);
v6 = v10;
v7 = 0;
do
{
v8 = (int)(float)((float)v7++ * v9);
XSetForeground(dsp, gc, v6);
result = XFillRectangle(
dsp,
a1,
gc,
v8,
v5,
(int)(float)((float)((float)v7 * v9) - (float)v8),
(int)(float)((float)((float)v11 * v12) - (float)v5));
++v6;
}
while ( v7 != v1 );
v10 += v1;
}
while ( v11 != v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(Drawable a1)
{
int v1; // er14
double v2; // xmm0_8
double v3; // xmm0_8
int result; // eax
int v5; // er13
unsigned __int64 v6; // rbp
int v7; // ebx
int v8; // er12
float v9; // [rsp+Ch] [rbp-5Ch]
unsigned __int64 v10; // [rsp+18h] [rbp-50h]
int v11; // [rsp+20h] [rbp-48h]
float v12; // [rsp+24h] [rbp-44h]

v1 = cmap_size;
if ( cmap_size == 16 )
{
v1 = 4;
}
else if ( cmap_size == 256 )
{
v1 = 16;
}
else if ( cmap_size != 2 )
{
v2 = (double)cmap_size;
if ( (double)cmap_size < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
v1 = (int)v3;
}
result = a1;
if ( win == a1 )
{
v9 = (float)width / (float)v1;
v12 = (float)height / (float)v1;
}
else
{
v9 = 48.0 / (float)v1;
v12 = v9;
}
if ( v1 > 0 )
{
v10 = 0LL;
v11 = 0;
do
{
v5 = (int)(float)((float)v11++ * v12);
v6 = v10;
v7 = 0;
do
{
v8 = (int)(float)((float)v7++ * v9);
XSetForeground(dsp, gc, v6);
result = XFillRectangle(
dsp,
a1,
gc,
v8,
v5,
(int)(float)((float)((float)v7 * v9) - (float)v8),
(int)(float)((float)((float)v11 * v12) - (float)v5));
++v6;
}
while ( v7 != v1 );
v10 += v1;
}
while ( v11 != v1 );
}
return result;
}

original_code:
static void
redisplay_indexed(Window window)
{
    int max;
    register int i,
                 j;
    register float fw;
    register float fh;
    switch (cmap_size) {
        case 2: max = 2; break;
        case 16: max = 4; break;
        case 256: max = 16; break;
        default: max = (int)sqrt((double)cmap_size);
    }
    if (window == win) {
 fw = (float) width / (float)max;
 fh = (float) height / (float)max;
    } else {
 fw = (float) 48 / (float)max;
 fh = (float) 48 / (float)max;
    }
    for (i = 0; i < max; i++) {
 register int y = (int) (i * fh);
 register int h = (i + 1) * fh - y;
 for (j = 0; j < max; j++) {
     register int x = (int) (j * fw);
     register int w = (j + 1) * fw - x;
     XSetForeground(dsp, gc, i * max + j);
     XFillRectangle(dsp, window, gc, x, y, w, h);
 }
    }
}

canonical_original_code:
static void redisplay_indexed(unsigned long window)
{
    int max;
    register int i; register int j;
    register float fw;
    register float fh;
    switch (cmap_size) {
        case 2: max = 2; break;
        case 16: max = 4; break;
        case 256: max = 16; break;
        default: max = (int)sqrt((double)cmap_size);
    }
    if (window == win) {
 fw = (float) width / (float)max;
 fh = (float) height / (float)max;
    } else {
 fw = (float) 48 / (float)max;
 fh = (float) 48 / (float)max;
    }
    for (i = 0; i < max; i++) {
 register int y = (int) (i * fh);
 register int h = (i + 1) * fh - y;
 for (j = 0; j < max; j++) {
     register int x = (int) (j * fw);
     register int w = (j + 1) * fw - x;
     XSetForeground(dsp, gc, i * max + j);
     XFillRectangle(dsp, window, gc, x, y, w, h);
 }
    }
}

variable_types: max int


redisplay

decompiled_code:
int __fastcall redisplay(Drawable a1)
{
int result; // eax

if ( (unsigned int)(visual->c_class - 4) <= 1 )
result = redisplay_direct(a1);
else
result = redisplay_indexed(a1);
return result;
}

canonical_decompiled_code:
int __fastcall func3(Drawable a1)
{
int result; // eax

if ( (unsigned int)(visual->c_class - 4) <= 1 )
result = func1(a1);
else
result = func2(a1);
return result;
}

original_code:
static void
redisplay (Window w)
{
    if (visual->class == 4 || visual->class == 5)
     redisplay_direct(w);
    else
     redisplay_indexed(w);
}

canonical_original_code:
static void redisplay(unsigned long w)
{
    if (visual->class == 4 || visual->class == 5)
     redisplay_direct(w);
    else
     redisplay_indexed(w);
}

variable_types:
w
unsigned long


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r15
const char *v4; // r14
int i; // ebx
__int64 v6; // rdx
const char *v7; // rbp
Display *v8; // rax
__int64 v9; // rcx
unsigned int v10; // eax
int v11; // er9
int v12; // er8
int v13; // ebx
char v14; // al
Window v15; // rax
Screen *v16; // rax
Display *v17; // rax
int v18; // [rsp+4h] [rbp-1E4h]
int v19; // [rsp+8h] [rbp-1E0h]
int v20; // [rsp+Ch] [rbp-1DCh]
int v21; // [rsp+10h] [rbp-1D8h]
int v22; // [rsp+14h] [rbp-1D4h]
const char *v23; // [rsp+18h] [rbp-1D0h]
Window v24[2]; // [rsp+20h] [rbp-1C8h] BYREF
XWMHints v25; // [rsp+30h] [rbp-1B8h] BYREF
XSizeHints v26; // [rsp+70h] [rbp-178h] BYREF
XGCValues v27; // [rsp+C0h] [rbp-128h] BYREF
XSetWindowAttributes v28; // [rsp+140h] [rbp-A8h] BYREF

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

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r15
const char *v4; // r14
int i; // ebx
__int64 v6; // rdx
const char *v7; // rbp
Display *v8; // rax
__int64 v9; // rcx
unsigned int v10; // eax
int v11; // er9
int v12; // er8
int v13; // ebx
char v14; // al
Window v15; // rax
Screen *v16; // rax
Display *v17; // rax
int v18; // [rsp+4h] [rbp-1E4h]
int v19; // [rsp+8h] [rbp-1E0h]
int v20; // [rsp+Ch] [rbp-1DCh]
int v21; // [rsp+10h] [rbp-1D8h]
int v22; // [rsp+14h] [rbp-1D4h]
const char *v23; // [rsp+18h] [rbp-1D0h]
Window v24[2]; // [rsp+20h] [rbp-1C8h] BYREF
XWMHints v25; // [rsp+30h] [rbp-1B8h] BYREF
XSizeHints v26; // [rsp+70h] [rbp-178h] BYREF
XGCValues v27; // [rsp+C0h] [rbp-128h] BYREF
XSetWindowAttributes v28; // [rsp+140h] [rbp-A8h] BYREF

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

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]


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 *


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

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v4; // rbp
const char *v5; // rsi
int v6; // eax
__int64 v7; // rdx
void (*v8)(void); // rbp

program = (__int64)*argv;
if ( argc > 1 )
{
v4 = argv[1];
if ( !strcmp("save", v4) )
{
v8 = (void (*)(void))&cmc_save;
}
else if ( !strcmp("init", v4) )
{
v8 = (void (*)(void))&cmc_init;
}
else if ( !strcmp("show", v4) )
{
v8 = (void (*)(void))&cmc_show;
}
else if ( !strcmp("discard", v4) )
{
v8 = (void (*)(void))&cmc_discard;
}
else if ( !strcmp("dealloc", v4) )
{
v8 = (void (*)(void))&cmc_dealloc;
}
else
{
v5 = v4;
v6 = strcmp("NeWSinit", v4);
v8 = (void (*)(void))&cmc_NeWSinit;
if ( v6 )
usage("NeWSinit", v5, v7);
}
process_arguments(argv + 2);
v8();
exit(0);
}
usage(argc, argv, envp);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v4; // rbp
const char *v5; // rsi
int v6; // eax
__int64 v7; // rdx
void (*v8)(void); // rbp

program = (__int64)*argv;
if ( argc > 1 )
{
v4 = argv[1];
if ( !strcmp("save", v4) )
{
v8 = (void (*)(void))&cmc_save;
}
else if ( !strcmp("init", v4) )
{
v8 = (void (*)(void))&cmc_init;
}
else if ( !strcmp("show", v4) )
{
v8 = (void (*)(void))&cmc_show;
}
else if ( !strcmp("discard", v4) )
{
v8 = (void (*)(void))&cmc_discard;
}
else if ( !strcmp("dealloc", v4) )
{
v8 = (void (*)(void))&cmc_dealloc;
}
else
{
v5 = v4;
v6 = strcmp("NeWSinit", v4);
v8 = (void (*)(void))&cmc_NeWSinit;
if ( v6 )
func0("NeWSinit", v5, v7);
}
func3(argv + 2);
v8();
exit(0);
}
func0(argc, argv, envp);
}

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 (*)()


Hash

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

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

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

v2 = *a1;
if ( *a1 )
{
v3 = 0;
do
{
++a1;
v3 += v2;
v2 = *a1;
}
while ( *a1 );
}
else
{
v3 = 0;
}
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; // rbx
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(0x30LL);
}
return result;
}

canonical_decompiled_code:
int func0()
{
const char *v0; // rbx
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(0x30LL);
}
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
char v4; // cl
__int64 v5; // rdx
char *v6; // rbp
char *v7; // rax
char v8; // bp
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 )
{
v5 = i;
v2 = (char *)a2[v5];
if ( *v2 == 45 )
{
v4 = v2[1];
LODWORD(v2) = (unsigned __int8)(v4 - 97);
switch ( v4 )
{
case 'a':
++doANSI;
++reentrant;
break;
case 'b':
++bigFile;
break;
case 'f':
++i;
v2 = (char *)a2[v5 + 1];
special_h = (__int64)v2;
break;
case 'h':
++i;
v6 = (char *)a2[v5 + 1];
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 ( v8 == 46 )
{
*v9 = 95;
}
else if ( v8 >= 0 )
{
v2 = (char *)*_ctype_b_loc();
if ( (v2[2 * v8 + 1] & 2) != 0 )
{
LODWORD(v2) = (*_ctype_toupper_loc())[v8];
*v9 = (char)v2;
}
}
v8 = *++v9;
}
while ( *v9 );
}
break;
case 'n':
noUserNames = 1;
break;
case 'o':
++i;
v2 = (char *)a2[v5 + 1];
ofile = v2;
break;
case 'p':
++pad;
break;
case 'r':
++reentrant;
break;
case 's':
++i;
LODWORD(v2) = atoi((const char *)a2[v5 + 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;
}
break;
case 'w':
continue;
default:
fprintf(stderr, "%s: bad option '-%c'\n", (const char *)prog, (unsigned int)v4);
Usage();
return result;
}
}
else
{
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
char v4; // cl
__int64 v5; // rdx
char *v6; // rbp
char *v7; // rax
char v8; // bp
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 )
{
v5 = i;
v2 = (char *)a2[v5];
if ( *v2 == 45 )
{
v4 = v2[1];
LODWORD(v2) = (unsigned __int8)(v4 - 97);
switch ( v4 )
{
case 'a':
++doANSI;
++reentrant;
break;
case 'b':
++bigFile;
break;
case 'f':
++i;
v2 = (char *)a2[v5 + 1];
special_h = (__int64)v2;
break;
case 'h':
++i;
v6 = (char *)a2[v5 + 1];
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 ( v8 == 46 )
{
*v9 = 95;
}
else if ( v8 >= 0 )
{
v2 = (char *)*_ctype_b_loc();
if ( (v2[2 * v8 + 1] & 2) != 0 )
{
LODWORD(v2) = (*_ctype_toupper_loc())[v8];
*v9 = (char)v2;
}
}
v8 = *++v9;
}
while ( *v9 );
}
break;
case 'n':
noUserNames = 1;
break;
case 'o':
++i;
v2 = (char *)a2[v5 + 1];
ofile = v2;
break;
case 'p':
++pad;
break;
case 'r':
++reentrant;
break;
case 's':
++i;
LODWORD(v2) = atoi((const char *)a2[v5 + 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;
}
break;
case 'w':
continue;
default:
fprintf(stderr, "%s: bad option '-%c'\n", (const char *)prog, (unsigned int)v4);
func0();
return result;
}
}
else
{
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; // ebx
int v4; // ebx

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_14:
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_14;
}

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

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_14:
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_14;
}

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(const char *a1)
{
char *result; // rax
char *v2; // rdx

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

canonical_decompiled_code:
char *__fastcall func1(const char *a1)
{
char *result; // rax
char *v2; // rdx

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

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(const char *a1)
{
if ( !a1 )
a1 = ".owcolors";
return fn_absolutize(a1);
}

canonical_decompiled_code:
char *__fastcall func3(const 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 *


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
{
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
{
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 v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
if ( v1 == 92 )
{
if ( a1[1] == 92 )
a1 += 2;
else
a1 += 4;
}
else
{
++a1;
}
++v2;
v1 = *a1;
}
while ( *a1 );
return v2;
}

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:
unsigned int __fastcall PSWOutputStringChars(char *a1)
{
char *v1; // rbp
int v2; // ebx
char v3; // r12
unsigned int result; // eax
int v5; // ebx
char v6; // di

if ( *a1 )
{
v1 = a1;
v2 = 0;
while ( 1 )
{
putc(39, stdout);
v6 = *v1;
if ( *v1 <= 39 )
break;
if ( v6 != 92 )
goto LABEL_21;
putc(92, stdout);
v3 = v1[1];
fputc(v3, stdout);
if ( v3 == 92 )
{
v1 += 2;
}
else
{
putc(v1[2], stdout);
putc(v1[3], stdout);
v1 += 4;
}
LABEL_8:
result = putc(39, stdout);
if ( *v1 )
{
v5 = v2 + 1;
if ( v5 <= 15 )
{
putc(44, stdout);
}
else
{
fwrite(",\n ", 1uLL, 7uLL, stdout);
++outlineno;
}
result = (unsigned int)(v5 >> 31) >> 28;
v2 = v5 % 16;
if ( *v1 )
continue;
}
return result;
}
if ( v6 > 7 )
{
switch ( v6 )
{
case 8:
fwrite(&unk_368, 1uLL, 2uLL, stdout);
++v1;
break;
case 9:
fwrite("\\t", 1uLL, 2uLL, stdout);
++v1;
break;
case 10:
fwrite("\\012", 1uLL, 4uLL, stdout);
++v2;
++v1;
break;
case 12:
fwrite(&unk_36B, 1uLL, 2uLL, stdout);
++v1;
break;
case 13:
fwrite("\\015", 1uLL, 4uLL, stdout);
++v2;
++v1;
break;
case 34:
fwrite(&unk_365, 1uLL, 2uLL, stdout);
++v1;
break;
case 39:
fwrite(&unk_362, 1uLL, 2uLL, stdout);
++v1;
break;
default:
goto LABEL_21;
}
goto LABEL_8;
}
LABEL_21:
putc(v6, stdout);
--v2;
++v1;
goto LABEL_8;
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func1(char *a1)
{
char *v1; // rbp
int v2; // ebx
char v3; // r12
unsigned int result; // eax
int v5; // ebx
char v6; // di

if ( *a1 )
{
v1 = a1;
v2 = 0;
while ( 1 )
{
putc(39, stdout);
v6 = *v1;
if ( *v1 <= 39 )
break;
if ( v6 != 92 )
goto LABEL_21;
putc(92, stdout);
v3 = v1[1];
fputc(v3, stdout);
if ( v3 == 92 )
{
v1 += 2;
}
else
{
putc(v1[2], stdout);
putc(v1[3], stdout);
v1 += 4;
}
LABEL_8:
result = putc(39, stdout);
if ( *v1 )
{
v5 = v2 + 1;
if ( v5 <= 15 )
{
putc(44, stdout);
}
else
{
fwrite(",\n ", 1uLL, 7uLL, stdout);
++outlineno;
}
result = (unsigned int)(v5 >> 31) >> 28;
v2 = v5 % 16;
if ( *v1 )
continue;
}
return result;
}
if ( v6 > 7 )
{
switch ( v6 )
{
case 8:
fwrite(&unk_368, 1uLL, 2uLL, stdout);
++v1;
break;
case 9:
fwrite("\\t", 1uLL, 2uLL, stdout);
++v1;
break;
case 10:
fwrite("\\012", 1uLL, 4uLL, stdout);
++v2;
++v1;
break;
case 12:
fwrite(&unk_36B, 1uLL, 2uLL, stdout);
++v1;
break;
case 13:
fwrite("\\015", 1uLL, 4uLL, stdout);
++v2;
++v1;
break;
case 34:
fwrite(&unk_365, 1uLL, 2uLL, stdout);
++v1;
break;
case 39:
fwrite(&unk_362, 1uLL, 2uLL, stdout);
++v1;
break;
default:
goto LABEL_21;
}
goto LABEL_8;
}
LABEL_21:
putc(v6, stdout);
--v2;
++v1;
goto LABEL_8;
}
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

v7[2] = 0;
result = *a1;
v7[0] = result;
if ( (_BYTE)result )
{
v2 = a1;
v3 = a1 + 1;
v4 = 0;
do
{
v5 = v2[1];
v2 += 2;
if ( !v5 )
v2 = v3;
v7[1] = v5;
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;
}
v4 = v6 % 16;
v3 = v2 + 1;
result = *v2;
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

v7[2] = 0;
result = *a1;
v7[0] = result;
if ( (_BYTE)result )
{
v2 = a1;
v3 = a1 + 1;
v4 = 0;
do
{
v5 = v2[1];
v2 += 2;
if ( !v5 )
v2 = v3;
v7[1] = v5;
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;
}
v4 = v6 % 16;
v3 = v2 + 1;
result = *v2;
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 ( !(_DWORD)i )
goto LABEL_3;
do
{
++v2;
result = ((_DWORD)result - 1) & (unsigned int)result;
}
while ( (_DWORD)result );
if ( v2 == 3 )
{
fates[i] = 0;
continue;
}
if ( v2 == 2 )
fates[i] = 1;
else
LABEL_3:
fates[i] = 2;
}
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 ( !(_DWORD)i )
goto LABEL_3;
do
{
++v2;
result = ((_DWORD)result - 1) & (unsigned int)result;
}
while ( (_DWORD)result );
if ( v2 == 3 )
{
fates[i] = 0;
continue;
}
if ( v2 == 2 )
fates[i] = 1;
else
LABEL_3:
fates[i] = 2;
}
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