decompiled_code:
__int64 usb_open()
{
return usb_os_open();
}

canonical_decompiled_code:
__int64 func2()
{
return usb_os_open();
}

canonical_original_code:
struct usb_dev_handle *usb_open(struct usb_device *dev)
{
    return usb_os_open(dev);
}

variable_types:
dev
struct usb_device *

return_type: struct usb_dev_handle { int fd; struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *devices; unsigned int location; struct usb_device *root_dev; } *bus; struct usb_device *device; int config; int interface; int altsetting; void *impl_info; } *

user_defined_types: struct usb_dev_handle { int fd; struct usb_bus *bus; struct usb_device *device; int config; int interface; int altsetting; void *impl_info; }

user_defined_types: struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device *devices; unsigned int location; struct usb_device *root_dev; }

user_defined_types: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus *bus; struct usb_device_descriptor descriptor; struct usb_config_descriptor *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; }

user_defined_types: struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface *interface; unsigned char *extra; int extralen; }

user_defined_types: struct usb_interface { struct usb_interface_descriptor *altsetting; int num_altsetting; }

user_defined_types: struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor *endpoint; unsigned char *extra; int extralen; }


repo: realthunder/usbip

decompiled_code:
__int64 __fastcall usb_get_string(__int64 a1, int a2, unsigned int a3, __int64 a4, __int64 a5)
{
return usb_control_msg(a1, 128LL, 6LL, (unsigned int)(a2 + 768), a3, a4, a5, 1000LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, unsigned int a3, __int64 a4, __int64 a5)
{
return usb_control_msg(a1, 128LL, 6LL, (unsigned int)(a2 + 768), a3, a4, a5, 1000LL);
}

original_code:
int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
 size_t buflen)
{
  return usb_control_msg(dev, 0x80, 0x06,
   (0x03 << 8) + index, langid, buf, buflen, 1000);
}

canonical_original_code:
int usb_get_string(struct usb_dev_handle *dev, int index, int langid, char *buf, unsigned long buflen)
{
  return usb_control_msg(dev, 0x80, 0x06,
   (0x03 << 8) + index, langid, buf, buflen, 1000);
}

variable_types: struct usb_dev_handle { int fd; struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *devices; unsigned int location; struct usb_device *root_dev; } *bus; struct usb_device *device; int config; int interface; int altsetting; void *impl_info; } *

variable_types: index int

variable_types: langid int

variable_types:
buf
char *

variable_types:
buflen
unsigned long

return_type: int


original_code:
int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf, size_t buflen)
{
  char tbuf[255];
  int ret, langid, si, di;
  ret = usb_get_string(dev, 0, 0, tbuf, sizeof(tbuf));
  if (ret < 0)
    return ret;
  if (ret < 4)
    return -5;
  langid = tbuf[2] | (tbuf[3] << 8);
  ret = usb_get_string(dev, index, langid, tbuf, sizeof(tbuf));
  if (ret < 0)
    return ret;
  if (tbuf[1] != 0x03)
    return -5;
  if (tbuf[0] > ret)
    return -27;
  for (di = 0, si = 2; si < tbuf[0]; si += 2) {
    if (di >= (buflen - 1))
      break;
    if (tbuf[si + 1])
      buf[di++] = '?';
    else
      buf[di++] = tbuf[si];
  }
  buf[di] = 0;
  return di;
}

canonical_original_code:
int usb_get_string_simple(struct usb_dev_handle *dev, int index, char *buf, unsigned long buflen)
{
  char tbuf[255];
  int ret; int langid; int si; int di;
  ret = usb_get_string(dev, 0, 0, tbuf, sizeof(tbuf));
  if (ret < 0)
    return ret;
  if (ret < 4)
    return -5;
  langid = tbuf[2] | (tbuf[3] << 8);
  ret = usb_get_string(dev, index, langid, tbuf, sizeof(tbuf));
  if (ret < 0)
    return ret;
  if (tbuf[1] != 0x03)
    return -5;
  if (tbuf[0] > ret)
    return -27;
  for (di = 0, si = 2; si < tbuf[0]; si += 2) {
    if (di >= (buflen - 1))
      break;
    if (tbuf[si + 1])
      buf[di++] = '?';
    else
      buf[di++] = tbuf[si];
  }
  buf[di] = 0;
  return di;
}

variable_types:
tbuf
char [255]

variable_types: ret int

variable_types: si int

variable_types: di int

user_defined_types: struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; }

user_defined_types: struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; }


decompiled_code:
__int64 __fastcall usb_close(void *ptr)
{
unsigned int v1; // ebp

v1 = usb_os_close();
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
unsigned int v1; // ebp

v1 = usb_os_close();
free(ptr);
return v1;
}

original_code:
int usb_close(usb_dev_handle *dev)
{
  int ret;
  ret = usb_os_close(dev);
  free(dev);
  return ret;
}

canonical_original_code:
int usb_close(struct usb_dev_handle *dev)
{
  int ret;
  ret = usb_os_close(dev);
  free(dev);
  return ret;
}


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

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

original_code:
struct usb_device *usb_device(usb_dev_handle *dev)
{
  return dev->device;
}

canonical_original_code:
struct usb_device *usb_device(struct usb_dev_handle *dev)
{
  return dev->device;
}

variable_types: struct usb_dev_handle { int fd; struct usb_bus *bus; struct usb_device *device; int config; int interface; int altsetting; void *impl_info; } *

return_type: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device *devices; unsigned int location; struct usb_device *root_dev; } *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *


decompiled_code:
void __fastcall usb_free_dev(void *ptr)
{
usb_destroy_configuration();
free(*((void **)ptr + 522));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
usb_destroy_configuration();
free(*((void **)ptr + 522));
free(ptr);
}

original_code:
void usb_free_dev(struct usb_device *dev)
{
  usb_destroy_configuration(dev);
  free(dev->children);
  free(dev);
}

variable_types: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device *devices; unsigned int location; struct usb_device *root_dev; } *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *

return_type: void


decompiled_code:
__int64 usb_find_devices()
{
_QWORD *v0; // r15
char **v2; // rax
char **v3; // rax
char *v4; // r13
char *v5; // r14
char *i; // rbx
char *v7; // rbp
_QWORD *v8; // rdi
_QWORD *v9; // rbx
_QWORD *v10; // rax
__int64 v11; // rax
__int64 v12; // rax
void *v13; // rbp
int v14; // eax
unsigned int v15; // [rsp+Ch] [rbp-4Ch]
void *ptr; // [rsp+18h] [rbp-40h] BYREF

v0 = (_QWORD *)usb_busses;
if ( !usb_busses )
return 0;
v15 = 0;
while ( 1 )
{
v14 = usb_os_find_devices(v0, &ptr);
if ( v14 < 0 )
break;
v5 = (char *)v0[515];
while ( v5 )
{
v4 = v5;
v5 = *(char **)v5;
for ( i = (char *)ptr; i; i = v7 )
{
v7 = *(char **)i;
if ( !strcmp(v4 + 16, i + 16) )
{
v2 = (char **)*((_QWORD *)i + 1);
if ( v2 )
*v2 = v7;
else
ptr = v7;
if ( *(_QWORD *)i )
*(_QWORD *)(*(_QWORD *)i + 8LL) = *((_QWORD *)i + 1);
*((_QWORD *)i + 1) = 0LL;
*(_QWORD *)i = 0LL;
usb_free_dev(i);
goto LABEL_16;
}
}
v3 = (char **)*((_QWORD *)v4 + 1);
if ( v3 )
*v3 = v5;
else
v0[515] = v5;
if ( *(_QWORD *)v4 )
*(_QWORD *)(*(_QWORD *)v4 + 8LL) = *((_QWORD *)v4 + 1);
*((_QWORD *)v4 + 1) = 0LL;
*(_QWORD *)v4 = 0LL;
usb_free_dev(v4);
++v15;
LABEL_16:
;
}
v9 = ptr;
if ( ptr )
{
do
{
v8 = v9;
v9 = (_QWORD *)*v9;
v10 = (_QWORD *)v8[1];
if ( v10 )
*v10 = v9;
else
ptr = v9;
if ( *v8 )
*(_QWORD *)(*v8 + 8LL) = v8[1];
v8[1] = 0LL;
*v8 = 0LL;
v11 = v0[515];
if ( v11 )
{
*v8 = v11;
*(_QWORD *)(v11 + 8) = v8;
}
v8[1] = 0LL;
v0[515] = v8;
if ( !v8[519] )
{
v12 = usb_open();
v13 = (void *)v12;
if ( v12 )
{
usb_fetch_and_parse_descriptors(v12);
usb_close(v13);
}
}
++v15;
}
while ( v9 );
}
usb_os_determine_children(v0);
v0 = (_QWORD *)*v0;
if ( !v0 )
return v15;
}
return (unsigned int)v14;
}

original_code:
int usb_find_devices(void)
{
  struct usb_bus *bus;
  int ret, changes = 0;
  for (bus = usb_busses; bus; bus = bus->next) {
    struct usb_device *devices, *dev;
    ret = usb_os_find_devices(bus, &devices);
    if (ret < 0)
      return ret;
    dev = bus->devices;
    while (dev) {
      int found = 0;
      struct usb_device *ndev, *tdev = dev->next;
      ndev = devices;
      while (ndev) {
        struct usb_device *tndev = ndev->next;
        if (!strcmp(dev->filename, ndev->filename)) {
          do { if (ndev->prev) ndev->prev->next = ndev->next; else devices = ndev->next; if (ndev->next) ndev->next->prev = ndev->prev; ndev->prev = ((void *)0); ndev->next = ((void *)0); } while (0);
          usb_free_dev(ndev);
          found = 1;
          break;
        }
        ndev = tndev;
      }
      if (!found) {
        do { if (dev->prev) dev->prev->next = dev->next; else bus->devices = dev->next; if (dev->next) dev->next->prev = dev->prev; dev->prev = ((void *)0); dev->next = ((void *)0); } while (0);
        usb_free_dev(dev);
        changes++;
      }
      dev = tdev;
    }
    dev = devices;
    while (dev) {
      struct usb_device *tdev = dev->next;
      do { if (dev->prev) dev->prev->next = dev->next; else devices = dev->next; if (dev->next) dev->next->prev = dev->prev; dev->prev = ((void *)0); dev->next = ((void *)0); } while (0);
      do { if (bus->devices) { dev->next = bus->devices; dev->next->prev = dev; } else dev->next = ((void *)0); dev->prev = ((void *)0); bus->devices = dev; } while(0);
      if (!dev->config) {
        usb_dev_handle *udev;
        udev = usb_open(dev);
        if (udev) {
          usb_fetch_and_parse_descriptors(udev);
          usb_close(udev);
        }
      }
      changes++;
      dev = tdev;
    }
    usb_os_determine_children(bus);
  }
  return changes;
}

canonical_original_code:
int usb_find_devices()
{
  struct usb_bus *bus;
  int ret; int changes = 0;
  for (bus = usb_busses; bus; bus = bus->next) {
    struct usb_device *devices; struct usb_device *dev;
    ret = usb_os_find_devices(bus, &devices);
    if (ret < 0)
      return ret;
    dev = bus->devices;
    while (dev) {
      int found = 0;
      struct usb_device *ndev; struct usb_device *tdev = dev->next;
      ndev = devices;
      while (ndev) {
        struct usb_device *tndev = ndev->next;
        if (!strcmp(dev->filename, ndev->filename)) {
          do { if (ndev->prev) ndev->prev->next = ndev->next; else devices = ndev->next; if (ndev->next) ndev->next->prev = ndev->prev; ndev->prev = ((void *)0); ndev->next = ((void *)0); } while (0);
          usb_free_dev(ndev);
          found = 1;
          break;
        }
        ndev = tndev;
      }
      if (!found) {
        do { if (dev->prev) dev->prev->next = dev->next; else bus->devices = dev->next; if (dev->next) dev->next->prev = dev->prev; dev->prev = ((void *)0); dev->next = ((void *)0); } while (0);
        usb_free_dev(dev);
        changes++;
      }
      dev = tdev;
    }
    dev = devices;
    while (dev) {
      struct usb_device *tdev = dev->next;
      do { if (dev->prev) dev->prev->next = dev->next; else devices = dev->next; if (dev->next) dev->next->prev = dev->prev; dev->prev = ((void *)0); dev->next = ((void *)0); } while (0);
      do { if (bus->devices) { dev->next = bus->devices; dev->next->prev = dev; } else dev->next = ((void *)0); dev->prev = ((void *)0); bus->devices = dev; } while(0);
      if (!dev->config) {
        struct usb_dev_handle *udev;
        udev = usb_open(dev);
        if (udev) {
          usb_fetch_and_parse_descriptors(udev);
          usb_close(udev);
        }
      }
      changes++;
      dev = tdev;
    }
    usb_os_determine_children(bus);
  }
  return changes;
}

variable_types: struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *devices; unsigned int location; struct usb_device *root_dev; } *

variable_types: changes int

variable_types: found int


decompiled_code:
__int64 usb_get_busses()
{
return usb_busses;
}

canonical_decompiled_code:
__int64 func9()
{
return usb_busses;
}

original_code:
struct usb_bus *usb_get_busses(void)
{
  return usb_busses;
}

canonical_original_code:
struct usb_bus *usb_get_busses()
{
  return usb_busses;
}

return_type: struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *devices; unsigned int location; struct usb_device *root_dev; } *


decompiled_code:
void __fastcall usb_free_bus(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func10(void *a1)
{
free(a1);
}

original_code:
void usb_free_bus(struct usb_bus *bus)
{
  free(bus);
}


original_code:
int usb_find_busses(void)
{
  struct usb_bus *busses, *bus;
  int ret, changes = 0;
  ret = usb_os_find_busses(&busses);
  if (ret < 0)
    return ret;
  bus = usb_busses;
  while (bus) {
    int found = 0;
    struct usb_bus *nbus, *tbus = bus->next;
    nbus = busses;
    while (nbus) {
      struct usb_bus *tnbus = nbus->next;
      if (!strcmp(bus->dirname, nbus->dirname)) {
        do { if (nbus->prev) nbus->prev->next = nbus->next; else busses = nbus->next; if (nbus->next) nbus->next->prev = nbus->prev; nbus->prev = ((void *)0); nbus->next = ((void *)0); } while (0);
        usb_free_bus(nbus);
        found = 1;
        break;
      }
      nbus = tnbus;
    }
    if (!found) {
      do { if (bus->prev) bus->prev->next = bus->next; else usb_busses = bus->next; if (bus->next) bus->next->prev = bus->prev; bus->prev = ((void *)0); bus->next = ((void *)0); } while (0);
      usb_free_bus(bus);
      changes++;
    }
    bus = tbus;
  }
  bus = busses;
  while (bus) {
    struct usb_bus *tbus = bus->next;
    do { if (bus->prev) bus->prev->next = bus->next; else busses = bus->next; if (bus->next) bus->next->prev = bus->prev; bus->prev = ((void *)0); bus->next = ((void *)0); } while (0);
    do { if (usb_busses) { bus->next = usb_busses; bus->next->prev = bus; } else bus->next = ((void *)0); bus->prev = ((void *)0); usb_busses = bus; } while(0);
    changes++;
    bus = tbus;
  }
  return changes;
}

canonical_original_code:
int usb_find_busses()
{
  struct usb_bus *busses; struct usb_bus *bus;
  int ret; int changes = 0;
  ret = usb_os_find_busses(&busses);
  if (ret < 0)
    return ret;
  bus = usb_busses;
  while (bus) {
    int found = 0;
    struct usb_bus *nbus; struct usb_bus *tbus = bus->next;
    nbus = busses;
    while (nbus) {
      struct usb_bus *tnbus = nbus->next;
      if (!strcmp(bus->dirname, nbus->dirname)) {
        do { if (nbus->prev) nbus->prev->next = nbus->next; else busses = nbus->next; if (nbus->next) nbus->next->prev = nbus->prev; nbus->prev = ((void *)0); nbus->next = ((void *)0); } while (0);
        usb_free_bus(nbus);
        found = 1;
        break;
      }
      nbus = tnbus;
    }
    if (!found) {
      do { if (bus->prev) bus->prev->next = bus->next; else usb_busses = bus->next; if (bus->next) bus->next->prev = bus->prev; bus->prev = ((void *)0); bus->next = ((void *)0); } while (0);
      usb_free_bus(bus);
      changes++;
    }
    bus = tbus;
  }
  bus = busses;
  while (bus) {
    struct usb_bus *tbus = bus->next;
    do { if (bus->prev) bus->prev->next = bus->next; else busses = bus->next; if (bus->next) bus->next->prev = bus->prev; bus->prev = ((void *)0); bus->next = ((void *)0); } while (0);
    do { if (usb_busses) { bus->next = usb_busses; bus->next->prev = bus; } else bus->next = ((void *)0); bus->prev = ((void *)0); usb_busses = bus; } while(0);
    changes++;
    bus = tbus;
  }
  return changes;
}


decompiled_code:
__int64 __fastcall put_unaligned_le16(__int16 a1, _WORD *a2)
{
*a2 = a1;
return HIBYTE(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 a1, _WORD *a2)
{
*a2 = a1;
return HIBYTE(a1);
}

original_code:
static inline void put_unaligned_le16(__u16 val, __u16 *cp)
{
 __u8 *p = (void *)cp;
 *p++ = (__u8) val;
 *p++ = (__u8) (val >> 8);
}

canonical_original_code:
static inline void put_unaligned_le16(unsigned short val, unsigned short *cp)
{
 unsigned char *p = (void *)cp;
 *p++ = (unsigned char) val;
 *p++ = (__u8) (val >> 8);
}

variable_types:
val
unsigned short

variable_types:
cp
unsigned short *

variable_types:
p
unsigned char *


decompiled_code:
__int64 __fastcall utf8_to_utf16le(_BYTE *a1, _WORD *a2, int a3)
{
unsigned int v5; // ebx
__int16 v6; // di

if ( !a3 )
return 0;
v5 = 0;
while ( 1 )
{
LOBYTE(v6) = *a1;
if ( !*a1 )
break;
if ( (v6 & 0x80u) == 0 )
{
++a1;
v6 = (unsigned __int8)v6;
}
else if ( (v6 & 0xE0) == 0xC0 )
{
if ( (a1[1] & 0xC0) != 0xC0 )
return (unsigned int)-1;
v6 = ((unsigned __int8)v6 << 6) & 0x7C0 | a1[1] & 0x3F;
a1 += 2;
}
else
{
if ( (v6 & 0xF0) != 0xE0 )
return (unsigned int)-1;
if ( (a1[1] & 0xC0) != 0xC0 )
return (unsigned int)-1;
if ( (a1[2] & 0xC0) != 0xC0 )
return (unsigned int)-1;
v6 = ((unsigned __int8)v6 << 12) | ((a1[1] & 0x3F) << 6) | a1[2] & 0x3F;
if ( (unsigned __int16)(v6 + 10240) <= 0x7FFu )
return (unsigned int)-1;
a1 += 3;
}
put_unaligned_le16(v6, a2);
if ( a3 == ++v5 )
return v5;
++a2;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, _WORD *a2, int a3)
{
unsigned int v5; // ebx
__int16 v6; // di

if ( !a3 )
return 0;
v5 = 0;
while ( 1 )
{
LOBYTE(v6) = *a1;
if ( !*a1 )
break;
if ( (v6 & 0x80u) == 0 )
{
++a1;
v6 = (unsigned __int8)v6;
}
else if ( (v6 & 0xE0) == 0xC0 )
{
if ( (a1[1] & 0xC0) != 0xC0 )
return (unsigned int)-1;
v6 = ((unsigned __int8)v6 << 6) & 0x7C0 | a1[1] & 0x3F;
a1 += 2;
}
else
{
if ( (v6 & 0xF0) != 0xE0 )
return (unsigned int)-1;
if ( (a1[1] & 0xC0) != 0xC0 )
return (unsigned int)-1;
if ( (a1[2] & 0xC0) != 0xC0 )
return (unsigned int)-1;
v6 = ((unsigned __int8)v6 << 12) | ((a1[1] & 0x3F) << 6) | a1[2] & 0x3F;
if ( (unsigned __int16)(v6 + 10240) <= 0x7FFu )
return (unsigned int)-1;
a1 += 3;
}
func0(v6, a2);
if ( a3 == ++v5 )
return v5;
++a2;
}
return v5;
}

original_code:
static int utf8_to_utf16le(const char *s, __u16 *cp, unsigned len)
{
 int count = 0;
 __u8 c;
 __u16 uchar;
 while (len != 0 && (c = (__u8) *s++) != 0) {
  if (c & 0x80) {
   if ((c & 0xe0) == 0xc0) {
    uchar = (c & 0x1f) << 6;
    c = (__u8) *s++;
    if ((c & 0xc0) != 0xc0)
     goto fail;
    c &= 0x3f;
    uchar |= c;
   } else if ((c & 0xf0) == 0xe0) {
    uchar = (c & 0x0f) << 12;
    c = (__u8) *s++;
    if ((c & 0xc0) != 0xc0)
     goto fail;
    c &= 0x3f;
    uchar |= c << 6;
    c = (__u8) *s++;
    if ((c & 0xc0) != 0xc0)
     goto fail;
    c &= 0x3f;
    uchar |= c;
    if (0xd800 <= uchar && uchar <= 0xdfff)
     goto fail;
   } else
    goto fail;
  } else
   uchar = c;
  put_unaligned_le16 (uchar, cp++);
  count++;
  len--;
 }
 return count;
fail:
 return -1;
}

canonical_original_code:
static int utf8_to_utf16le(char *s, unsigned short *cp, unsigned int len)
{
 int count = 0;
 unsigned char c;
 unsigned short uchar;
 while (len != 0 && (c = (__u8) *s++) != 0) {
  if (c & 0x80) {
   if ((c & 0xe0) == 0xc0) {
    uchar = (c & 0x1f) << 6;
    c = (__u8) *s++;
    if ((c & 0xc0) != 0xc0)
     goto fail;
    c &= 0x3f;
    uchar |= c;
   } else if ((c & 0xf0) == 0xe0) {
    uchar = (c & 0x0f) << 12;
    c = (__u8) *s++;
    if ((c & 0xc0) != 0xc0)
     goto fail;
    c &= 0x3f;
    uchar |= c << 6;
    c = (__u8) *s++;
    if ((c & 0xc0) != 0xc0)
     goto fail;
    c &= 0x3f;
    uchar |= c;
    if (0xd800 <= uchar && uchar <= 0xdfff)
     goto fail;
   } else
    goto fail;
  } else
   uchar = c;
  put_unaligned_le16 (uchar, cp++);
  count++;
  len--;
 }
 return count;
fail:
 return -1;
}

variable_types:
s
char *

variable_types:
len
unsigned int

variable_types: count int

variable_types:
c
unsigned char

variable_types:
uchar
unsigned short


original_code:
int
usb_gadget_get_string (struct usb_gadget_strings *table, int id, __u8 *buf)
{
 struct usb_string *s;
 int len;
 if (id == 0) {
  buf [0] = 4;
  buf [1] = 0x03;
  buf [2] = (__u8) table->language;
  buf [3] = (__u8) (table->language >> 8);
  return 4;
 }
 for (s = table->strings; s && s->s; s++)
  if (s->id == id)
   break;
 if (!s || !s->s)
  return -22;
 len = strlen (s->s);
 if (len > 126)
  len = 126;
 memset (buf + 2, 0, 2 * len);
 len = utf8_to_utf16le(s->s, (__u16 *)&buf[2], len);
 if (len < 0)
  return -22;
 buf [0] = (len + 1) * 2;
 buf [1] = 0x03;
 return buf [0];
}

canonical_original_code:
int usb_gadget_get_string(struct usb_gadget_strings *table, int id, unsigned char *buf)
{
 struct usb_string *s;
 int len;
 if (id == 0) {
  buf [0] = 4;
  buf [1] = 0x03;
  buf [2] = (unsigned char) table->language;
  buf [3] = (__u8) (table->language >> 8);
  return 4;
 }
 for (s = table->strings; s && s->s; s++)
  if (s->id == id)
   break;
 if (!s || !s->s)
  return -22;
 len = strlen (s->s);
 if (len > 126)
  len = 126;
 memset (buf + 2, 0, 2 * len);
 len = utf8_to_utf16le(s->s, (unsigned short *)&buf[2], len);
 if (len < 0)
  return -22;
 buf [0] = (len + 1) * 2;
 buf [1] = 0x03;
 return buf [0];
}

variable_types: struct usb_gadget_strings { unsigned short language; struct usb_string { unsigned char id; char *s; } *strings; } *

variable_types: id int

variable_types:
buf
unsigned char *

variable_types: len int

user_defined_types: struct usb_gadget_strings { unsigned short language; struct usb_string *strings; }


decompiled_code:
char *usb_os_strerror()
{
char *result; // rax

result = (char *)&usb_error_str;
if ( usb_error_type != 1 )
{
if ( usb_error_type == 2 )
{
result = "Unknown error";
if ( usb_error_errno >= -499999 )
result = strerror(usb_error_errno);
}
else
{
result = "Unknown error";
if ( !usb_error_type )
result = "No error";
}
}
return result;
}

canonical_decompiled_code:
char *func0()
{
char *result; // rax

result = (char *)&usb_error_str;
if ( usb_error_type != 1 )
{
if ( usb_error_type == 2 )
{
result = "Unknown error";
if ( usb_error_errno >= -499999 )
result = strerror(usb_error_errno);
}
else
{
result = "Unknown error";
if ( !usb_error_type )
result = "No error";
}
}
return result;
}

original_code:
char *usb_os_strerror(void)
{
  switch (usb_error_type) {
  case USB_ERROR_TYPE_NONE:
    return "No error";
  case USB_ERROR_TYPE_STRING:
    return usb_error_str;
  case USB_ERROR_TYPE_ERRNO:
    if (usb_error_errno > -500000)
      return strerror(usb_error_errno);
    else
      return "Unknown error";
  }
  return "Unknown error";
}

canonical_original_code:
char *usb_os_strerror()
{
  switch (usb_error_type) {
  case USB_ERROR_TYPE_NONE:
    return "No error";
  case USB_ERROR_TYPE_STRING:
    return usb_error_str;
  case USB_ERROR_TYPE_ERRNO:
    if (usb_error_errno > -500000)
      return strerror(usb_error_errno);
    else
      return "Unknown error";
  }
  return "Unknown error";
}

return_type: char *


xlBanner

decompiled_code:
const char *xlBanner()
{
return "XLISP 3.3, September 6, 2002 Copyright (c) 1984-2002, by David Betz";
}

canonical_decompiled_code:
const char *func1()
{
return "XLISP 3.3, September 6, 2002 Copyright (c) 1984-2002, by David Betz";
}

original_code:
char *xlBanner(void)
{
    return "XLISP 3.3, September 6, 2002 Copyright (c) 1984-2002, by David Betz";
}


xlCleanup

decompiled_code:
__int64 xlCleanup()
{
__int64 v0; // rax

v0 = xlEnter("CLEANUP");
return xlThrowError(v0);
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax

v0 = xlEnter("CLEANUP");
return xlThrowError(v0);
}

original_code:
void xlCleanup(void)
{
    xlThrowError(xlEnter("CLEANUP"));
}

canonical_original_code:
void xlCleanup()
{
    xlThrowError(xlEnter("CLEANUP"));
}


xlTopLevel

decompiled_code:
__int64 xlTopLevel()
{
__int64 v0; // rax

v0 = xlEnter("RESET");
return xlThrowError(v0);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax

v0 = xlEnter("RESET");
return xlThrowError(v0);
}

original_code:
void xlTopLevel(void)
{
    xlThrowError(xlEnter("RESET"));
}

canonical_original_code:
void xlTopLevel()
{
    xlThrowError(xlEnter("RESET"));
}


xlContinue

decompiled_code:
void xlContinue()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void xlContinue(void)
{
}

canonical_original_code:
void xlContinue()
{
}


xlBreak

decompiled_code:
void xlBreak()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void xlBreak(void)
{
}

canonical_original_code:
void xlBreak()
{
}


xlWrapUp

decompiled_code:
__int64 xlWrapUp()
{
if ( xlTranscriptFP )
xlosClose();
return xlosExit(0LL);
}

canonical_decompiled_code:
__int64 func6()
{
if ( xlTranscriptFP )
xlosClose();
return xlosExit(0LL);
}

original_code:
void xlWrapUp(void)
{
    if (xlTranscriptFP != ((void *)0))
        xlosClose(xlTranscriptFP);
    xlosExit(0);
}

canonical_original_code:
void xlWrapUp()
{
    if (xlTranscriptFP != ((void *)0))
        xlosClose(xlTranscriptFP);
    xlosExit(0);
}


xlFmtError

decompiled_code:
__int64 xlFmtError(char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
fmterror((__int64)"\nError: ", a1, (unsigned int *)va);
return xlCallErrorHandler();
}

canonical_decompiled_code:
__int64 func7(char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
fmterror((__int64)"\nError: ", a1, (unsigned int *)va);
return xlCallErrorHandler();
}

original_code:
void xlFmtError(char *fmt,...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    fmterror("\nError: ",fmt,ap);
    __builtin_va_end(ap);
    xlCallErrorHandler();
}

canonical_original_code:
void xlFmtError(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    fmterror("\nError: ",fmt,ap);
    __builtin_va_end(ap);
    xlCallErrorHandler();
}

variable_types:
fmt
char *


xlFmtAbort

decompiled_code:
__int64 xlFmtAbort(char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
fmterror((__int64)"\nAbort: ", a1, (unsigned int *)va);
return xlJumpToTarget(0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 func9(char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
fmterror((__int64)"\nAbort: ", a1, (unsigned int *)va);
return xlJumpToTarget(0xFFFFFFFFLL);
}

original_code:
void xlFmtAbort(char *fmt,...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    fmterror("\nAbort: ",fmt,ap);
    __builtin_va_end(ap);
    xlJumpToTarget(-1);
}

canonical_original_code:
void xlFmtAbort(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    fmterror("\nAbort: ",fmt,ap);
    __builtin_va_end(ap);
    xlJumpToTarget(-1);
}


xlFatal

decompiled_code:
__int64 xlFatal(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
xlosError(s);
return xlosExit(1LL);
}

canonical_decompiled_code:
__int64 func11(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
xlosError(s);
return xlosExit(1LL);
}

original_code:
void xlFatal(char *fmt,...)
{
    char buf[1024];
    va_list ap;
    __builtin_va_start(ap,fmt);
    vsprintf(buf,fmt,ap);
    __builtin_va_end(ap);
    xlosError(buf);
    xlosExit(1);
}

canonical_original_code:
void xlFatal(char *fmt, ...)
{
    char buf[1024];
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    vsprintf(buf,fmt,ap);
    __builtin_va_end(ap);
    xlosError(buf);
    xlosExit(1);
}

variable_types:
buf
char [1024]


xlInfo

decompiled_code:
int xlInfo(char *format, ...)
{
int result; // eax
char v2; // di
char *v3; // rbx
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
result = vsprintf(s, format, arg);
v2 = s[0];
if ( s[0] )
{
v3 = s;
do
{
++v3;
result = xlosConsolePutC((unsigned int)v2);
v2 = *v3;
}
while ( *v3 );
}
return result;
}

canonical_decompiled_code:
int func12(char *format, ...)
{
int result; // eax
char v2; // di
char *v3; // rbx
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
result = vsprintf(s, format, arg);
v2 = s[0];
if ( s[0] )
{
v3 = s;
do
{
++v3;
result = xlosConsolePutC((unsigned int)v2);
v2 = *v3;
}
while ( *v3 );
}
return result;
}

original_code:
void xlInfo(char *fmt,...)
{
    char buf[1024],*p=buf;
    va_list ap;
    __builtin_va_start(ap,fmt);
    vsprintf(buf,fmt,ap);
    __builtin_va_end(ap);
    while (*p != '\0')
        xlosConsolePutC(*p++);
}

canonical_original_code:
void xlInfo(char *fmt, ...)
{
    char buf[1024]; char *p = buf;
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    vsprintf(buf,fmt,ap);
    __builtin_va_end(ap);
    while (*p != '\0')
        xlosConsolePutC(*p++);
}

variable_types:
p
char *


decompiled_code:
__int64 ccode_restore()
{
xlCSP -= 8LL;
return (*(__int64 (**)(void))*xlCSP)();
}

canonical_decompiled_code:
__int64 func0()
{
xlCSP -= 8LL;
return (*(__int64 (**)(void))*xlCSP)();
}

original_code:
static void ccode_restore(void)
{
    xlCContinuation *cc;
    cc = (xlCContinuation *)(*--xlCSP);
    (*cc->cc_cont)();
}

canonical_original_code:
static void ccode_restore()
{
    struct xlCContinuation *cc;
    cc = (struct xlCContinuation *)(*--xlCSP);
    (*cc->cc_cont)();
}

variable_types: struct xlCContinuation { void (*cc_cont)(); void (*cc_unwind)(); int cc_cnt; char *cc_names; } *


decompiled_code:
__int64 ccode_unwind()
{
__int64 v0; // rdx
__int64 (*v1)(void); // rax
__int64 result; // rax

v0 = xlCSP - 8LL;
xlCSP = v0;
v1 = *(__int64 (**)(void))(*(_QWORD *)v0 + 8LL);
if ( v1 )
return v1();
result = 8LL * *(int *)(*(_QWORD *)v0 + 16LL);
xlCSP = v0 - result;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rdx
__int64 (*v1)(void); // rax
__int64 result; // rax

v0 = xlCSP - 8LL;
xlCSP = v0;
v1 = *(__int64 (**)(void))(*(_QWORD *)v0 + 8LL);
if ( v1 )
return v1();
result = 8LL * *(int *)(*(_QWORD *)v0 + 16LL);
xlCSP = v0 - result;
return result;
}

original_code:
static void ccode_unwind(void)
{
    xlCContinuation *cc;
    cc = (xlCContinuation *)(*--xlCSP);
    if (cc->cc_unwind)
        (*cc->cc_unwind)();
    else
        (xlCSP -= (cc->cc_cnt));
}

canonical_original_code:
static void ccode_unwind()
{
    struct xlCContinuation *cc;
    cc = (struct xlCContinuation *)(*--xlCSP);
    if (cc->cc_unwind)
        (*cc->cc_unwind)();
    else
        (xlCSP -= (cc->cc_cnt));
}

user_defined_types: struct xlCContinuation { void (*cc_cont)(); void (*cc_unwind)(); int cc_cnt; char *cc_names; }


showstring

decompiled_code:
char *__fastcall showstring(char *a1, int a2)
{
char *v2; // rbx
char v3; // al
_BYTE *i; // rdx
_BYTE v6[40]; // [rsp+0h] [rbp-28h] BYREF

v2 = a1;
v3 = *a1;
for ( i = v6; *v2; v3 = *v2 )
{
++v2;
if ( v3 == a2 )
break;
*i++ = v3;
}
*i = 0;
xlErrPutStr(v6);
return v2;
}

canonical_decompiled_code:
char *__fastcall func5(char *a1, int a2)
{
char *v2; // rbx
char v3; // al
_BYTE *i; // rdx
_BYTE v6[40]; // [rsp+0h] [rbp-28h] BYREF

v2 = a1;
v3 = *a1;
for ( i = v6; *v2; v3 = *v2 )
{
++v2;
if ( v3 == a2 )
break;
*i++ = v3;
}
*i = 0;
xlErrPutStr(v6);
return v2;
}

original_code:
static char *showstring(char *str,int bch)
{
    char buf[20],*p;
    int ch;
    for (p = buf; *str != '\0' && (ch = *str++) != bch; )
        *p++ = ch;
    *p = '\0';
    xlErrPutStr(buf);
    return str;
}

canonical_original_code:
static char *showstring(char *str, int bch)
{
    char buf[20]; char *p;
    int ch;
    for (p = buf; *str != '\0' && (ch = *str++) != bch; )
        *p++ = ch;
    *p = '\0';
    xlErrPutStr(buf);
    return str;
}

variable_types:
str
char *

variable_types: bch int

variable_types:
buf
char [20]

variable_types: ch int


xcallwi

decompiled_code:
__int64 xcallwi()
{
return do_withfile(1, (__int64)"r");
}

original_code:
void xcallwi(void)
{
    do_withfile(0x0001,"r");
}

canonical_original_code:
void xcallwi()
{
    do_withfile(0x0001,"r");
}


xcallwo

decompiled_code:
__int64 xcallwo()
{
return do_withfile(18, (__int64)"w");
}

original_code:
void xcallwo(void)
{
    do_withfile(0x0002 | 0x0010,"w");
}

canonical_original_code:
void xcallwo()
{
    do_withfile(0x0002 | 0x0010,"w");
}


xload

decompiled_code:
__int64 xload()
{
return do_load(xlFalse);
}

canonical_decompiled_code:
__int64 func20()
{
return func12(xlFalse);
}

original_code:
void xload(void)
{
    do_load(xlFalse);
}

canonical_original_code:
void xload()
{
    do_load(xlFalse);
}


xloadnoisily

decompiled_code:
__int64 xloadnoisily()
{
return do_load(xlTrue);
}

canonical_decompiled_code:
__int64 func21()
{
return func12(xlTrue);
}

original_code:
void xloadnoisily(void)
{
    do_load(xlTrue);
}

canonical_original_code:
void xloadnoisily()
{
    do_load(xlTrue);
}


writeptr

decompiled_code:
char *__fastcall writeptr(__int64 a1)
{
char *v1; // rbx
char *result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF
char v4; // [rsp+10h] [rbp-8h] BYREF

v3 = a1;
v1 = (char *)&v3;
do
{
putc(*v1++, fp);
result = &v4;
}
while ( v1 != &v4 );
return result;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1)
{
char *v1; // rbx
char *result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF
char v4; // [rsp+10h] [rbp-8h] BYREF

v3 = a1;
v1 = (char *)&v3;
do
{
putc(*v1++, fp);
result = &v4;
}
while ( v1 != &v4 );
return result;
}

original_code:
static void writeptr(long off)
{
    char *p = (char *)&off;
    int n = sizeof(long);
    while (--n >= 0)
        putc(*p++,fp);
}

variable_types: off long

variable_types: n int


setoffset

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

result = foff;
if ( off != foff )
{
putc(0, fp);
writeptr(off);
result = off;
foff = off;
}
return result;
}

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

result = foff;
if ( off != foff )
{
putc(0, fp);
func1(off);
result = off;
foff = off;
}
return result;
}

original_code:
static void setoffset(void)
{
    if (off != foff) {
        putc(0,fp);
        writeptr(off);
        foff = off;
    }
}

canonical_original_code:
static void setoffset()
{
    if (off != foff) {
        putc(0,fp);
        writeptr(off);
        foff = off;
    }
}


readptr

decompiled_code:
__int64 readptr()
{
char *v0; // rbx
__int64 v2; // [rsp+8h] [rbp-10h] BYREF
char v3; // [rsp+10h] [rbp-8h] BYREF

v0 = (char *)&v2;
do
*v0++ = getc(fp);
while ( v0 != &v3 );
return v2;
}

canonical_decompiled_code:
__int64 func4()
{
char *v0; // rbx
__int64 v2; // [rsp+8h] [rbp-10h] BYREF
char v3; // [rsp+10h] [rbp-8h] BYREF

v0 = (char *)&v2;
do
*v0++ = getc(fp);
while ( v0 != &v3 );
return v2;
}

original_code:
static long readptr(void)
{
    long off;
    char *p = (char *)&off;
    int n = sizeof(long);
    while (--n >= 0)
        *p++ = getc(fp);
    return off;
}

canonical_original_code:
static long readptr()
{
    long off;
    char *p = (char *)&off;
    int n = sizeof(long);
    while (--n >= 0)
        *p++ = getc(fp);
    return off;
}

return_type: long


xlStdPutStr

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

v1 = xlCurOutput();
return xlPutStr(v1, a1);
}

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

v1 = xlCurOutput();
return xlPutStr(v1, a1);
}

original_code:
void xlStdPutStr(char *str)
{
    xlPutStr(xlCurOutput(),str);
}


xlErrPutStr

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

v1 = xlCurError();
return xlPutStr(v1, a1);
}

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

v1 = xlCurError();
return xlPutStr(v1, a1);
}

original_code:
void xlErrPutStr(char *str)
{
    xlPutStr(xlCurError(),str);
}


fasleof

decompiled_code:
__int64 fasleof()
{
return xlFmtError("unexpected eof in fasl file");
}

canonical_decompiled_code:
__int64 func0()
{
return xlFmtError("unexpected eof in fasl file");
}

original_code:
static void fasleof(void)
{
    xlFmtError("unexpected eof in fasl file");
}

canonical_original_code:
static void fasleof()
{
    xlFmtError("unexpected eof in fasl file");
}


xlFreeString

decompiled_code:
void __fastcall xlFreeString(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func12(void *a1)
{
free(a1);
}

original_code:
void xlFreeString(char *str)
{
    free(str);
}


xlSetIdleHandler

decompiled_code:
void __fastcall xlSetIdleHandler(__int64 a1, __int64 a2)
{
idleHandler = a1;
idleData = a2;
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, __int64 a2)
{
idleHandler = a1;
idleData = a2;
}

original_code:
void xlSetIdleHandler(void (*handler)(void *data),void *data)
{
    idleHandler = handler;
    idleData = data;
}

canonical_original_code:
void xlSetIdleHandler(void (*handler)(void *data), void *data)
{
    idleHandler = handler;
    idleData = data;
}

variable_types:
handler
void (*)(void *data)

variable_types:
data
void *


xlIdle

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

result = 0LL;
if ( idleHandler )
{
idleHandler(idleData);
xlosFlushOutput();
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( idleHandler )
{
idleHandler(idleData);
xlosFlushOutput();
result = 1LL;
}
return result;
}

original_code:
int xlIdle(void)
{
    if (idleHandler) {
        (*idleHandler)(idleData);
        xlosFlushOutput();
        return 1;
    }
    return 0;
}

canonical_original_code:
int xlIdle()
{
    if (idleHandler) {
        (*idleHandler)(idleData);
        xlosFlushOutput();
        return 1;
    }
    return 0;
}


xlosSetRand

decompiled_code:
void __fastcall xlosSetRand(__int64 a1)
{
rseed = a1;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
rseed = a1;
}

original_code:
void xlosSetRand(long seed)
{
    rseed = seed;
}

variable_types: seed long


xlosRand

decompiled_code:
__int64 __fastcall xlosRand(__int64 a1)
{
__int64 v2; // rax

if ( rseed )
{
v2 = -2836 * (rseed / 127773) + 16807 * (rseed % 127773);
rseed = v2 + (v2 < 0 ? 0x7FFFFFFFuLL : 0);
}
else
{
rseed = 16807LL;
}
return rseed % a1;
}

original_code:
long xlosRand(long n)
{
    long k1;
    if (rseed == 0L) rseed = 1L;
    k1 = rseed / 127773L;
    if ((rseed = 16807L * (rseed - k1 * 127773L) - k1 * 2836L) < 0L)
        rseed += 2147483647L;
    return rseed % n;
}

variable_types: n long


xlosInfo

decompiled_code:
__int64 xlosInfo()
{
char v1[88]; // [rsp+0h] [rbp-58h] BYREF

sprintf(v1, "\n[ Free: %ld, GC calls: %ld, Total: %ld ]", xlNFree, xlGCCalls, xlTotal);
return xlErrPutStr(v1);
}

canonical_decompiled_code:
__int64 func7()
{
char v1[88]; // [rsp+0h] [rbp-58h] BYREF

sprintf(v1, "\n[ Free: %ld, GC calls: %ld, Total: %ld ]", xlNFree, xlGCCalls, xlTotal);
return xlErrPutStr(v1);
}

original_code:
void xlosInfo(void)
{
    extern long xlNFree,xlGCCalls,xlTotal;
    char buf[80];
    sprintf(buf,"\n[ Free: %ld, GC calls: %ld, Total: %ld ]",xlNFree,xlGCCalls,xlTotal);
    xlErrPutStr(buf);
}

canonical_original_code:
void xlosInfo()
{
    extern long xlNFree; extern long xlGCCalls; extern long xlTotal;
    char buf[80];
    sprintf(buf,"\n[ Free: %ld, GC calls: %ld, Total: %ld ]",xlNFree,xlGCCalls,xlTotal);
    xlErrPutStr(buf);
}

variable_types: xlNFree long

variable_types: xlGCCalls long

variable_types: xlTotal long

variable_types:
buf
char [80]


xlosCheck

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

result = (unsigned int)xlosConsoleCheck();
switch ( (int)result )
{
case 2:
xlosConsoleFlush();
result = xlBreak();
break;
case 3:
xlosConsoleFlush();
result = xlTopLevel();
break;
case 19:
do
result = xlosConsoleCheck();
while ( (_DWORD)result != 17 );
break;
case 20:
result = xlosInfo();
break;
case 28:
result = xlWrapUp();
break;
default:
return result;
}
return result;
}

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

result = (unsigned int)xlosConsoleCheck();
switch ( (int)result )
{
case 2:
xlosConsoleFlush();
result = xlBreak();
break;
case 3:
xlosConsoleFlush();
result = xlTopLevel();
break;
case 19:
do
result = xlosConsoleCheck();
while ( (_DWORD)result != 17 );
break;
case 20:
result = func7();
break;
case 28:
result = xlWrapUp();
break;
default:
return result;
}
return result;
}

original_code:
void xlosCheck(void)
{
    switch (xlosConsoleCheck()) {
    case '\002':
        xlosConsoleFlush();
        xlBreak();
        break;
    case '\003':
        xlosConsoleFlush();
        xlTopLevel();
        break;
    case '\024':
        xlosInfo();
        break;
    case '\023':
        while (xlosConsoleCheck() != '\021')
            ;
        break;
    case '\034':
        xlWrapUp();
        break;
    }
}

canonical_original_code:
void xlosCheck()
{
    switch (xlosConsoleCheck()) {
    case '\002':
        xlosConsoleFlush();
        xlBreak();
        break;
    case '\003':
        xlosConsoleFlush();
        xlTopLevel();
        break;
    case '\024':
        xlosInfo();
        break;
    case '\023':
        while (xlosConsoleCheck() != '\021')
            ;
        break;
    case '\034':
        xlWrapUp();
        break;
    }
}


xlosTime

decompiled_code:
time_t xlosTime()
{
return time(0LL);
}

canonical_decompiled_code:
time_t func9()
{
return time(0LL);
}

original_code:
time_t xlosTime(void)
{
    return time(0);
}

canonical_original_code:
long xlosTime()
{
    return time(0);
}


xlosAlloc

decompiled_code:
void *__fastcall xlosAlloc(size_t size)
{
return calloc(1uLL, size);
}

canonical_decompiled_code:
void *__fastcall func10(size_t size)
{
return calloc(1uLL, size);
}

original_code:
void *xlosAlloc(long size)
{
    return calloc(1,(size_t)size);
}

canonical_original_code:
void *xlosAlloc(long size)
{
    return calloc(1,(unsigned long)size);
}

variable_types: size long

return_type: void *


xlosFree

decompiled_code:
void __fastcall xlosFree(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func11(void *a1)
{
free(a1);
}

original_code:
void xlosFree(void *ptr)
{
    free(ptr);
}

canonical_original_code:
void xlosFree(void *ptr)
{
    free(ptr);
}

variable_types:
ptr
void *


xlosGetEnv

decompiled_code:
char *__fastcall xlosGetEnv(const char *a1)
{
return getenv(a1);
}

canonical_decompiled_code:
char *__fastcall func12(const char *a1)
{
return getenv(a1);
}

original_code:
char *xlosGetEnv(char *name)
{
    return getenv(name);
}

variable_types:
name
char *


ostatbol

decompiled_code:
_BOOL8 ostatbol()
{
return lposition == 0;
}

canonical_decompiled_code:
_BOOL8 func1()
{
return lposition == 0;
}

original_code:
static int ostatbol(void)
{
    return lposition == 0;
}

canonical_original_code:
static int ostatbol()
{
    return lposition == 0;
}


ostflush

decompiled_code:
void ostflush()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
static void ostflush(void)
{
}

canonical_original_code:
static void ostflush()
{
}


ostcheck

decompiled_code:
__int64 ostcheck()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 0LL;
}

original_code:
static int ostcheck(void)
{
    return 0;
}

canonical_original_code:
static int ostcheck()
{
    return 0;
}


osflushoutput

decompiled_code:
void osflushoutput()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
static void osflushoutput(void)
{
}

canonical_original_code:
static void osflushoutput()
{
}


ostputc

decompiled_code:
int __fastcall ostputc(int a1)
{
int v1; // eax

v1 = 0;
if ( a1 != 10 )
v1 = lposition + 1;
lposition = v1;
return putchar(a1);
}

canonical_decompiled_code:
int __fastcall func6(int a1)
{
int v1; // eax

v1 = 0;
if ( a1 != 10 )
v1 = lposition + 1;
lposition = v1;
return putchar(a1);
}

original_code:
static void ostputc(int ch)
{
   if (ch == '\n')
        lposition = 0;
   else
        ++lposition;
   putchar(ch);
}


ostgetc

decompiled_code:
int ostgetc()
{
return getchar();
}

canonical_decompiled_code:
int func7()
{
return getchar();
}

original_code:
static int ostgetc(void)
{
    return getchar();
}

canonical_original_code:
static int ostgetc()
{
    return getchar();
}


osfmodtime

decompiled_code:
_BOOL8 __fastcall osfmodtime(const char *a1, __time_t *a2)
{
int v2; // eax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v2 = stat(a1, &v4);
*a2 = v4.st_mtim.tv_sec;
return v2 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char *a1, __time_t *a2)
{
int v2; // eax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v2 = stat(a1, &v4);
*a2 = v4.st_mtim.tv_sec;
return v2 == 0;
}

original_code:
static int osfmodtime(char *fname,long *pModTime)
{
    struct stat info;
    int sts = stat(fname,&info);
    *pModTime = info.st_mtim.tv_sec;
    return sts == 0;
}

canonical_original_code:
static int osfmodtime(char *fname, long *pModTime)
{
    struct stat info;
    int sts = stat(fname,&info);
    *pModTime = info.st_mtim.tv_sec;
    return sts == 0;
}

variable_types:
fname
char *

variable_types:
pModTime
long *

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

variable_types: sts int

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


oserror

decompiled_code:
__int64 __fastcall oserror(const char *a1)
{
return xlInfo("error: %s\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
return xlInfo("error: %s\n", a1);
}

original_code:
static void oserror(char *msg)
{
    xlInfo("error: %s\n",msg);
}

variable_types:
msg
char *


osexit

decompiled_code:
void __fastcall __noreturn osexit(int a1)
{
exit(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(int a1)
{
exit(a1);
}

original_code:
static void osexit(int sts)
{
    exit(sts);
}


osparsepath

decompiled_code:
char *__fastcall osparsepath(char **a1)
{
char *v1; // rbp
char v2; // al
char *v3; // rbx
char *result; // rax

v1 = *a1;
v2 = **a1;
if ( v2 )
{
v3 = &buf_0;
while ( v2 != 58 )
{
++v1;
*v3++ = v2;
v2 = *v1;
if ( !*v1 )
goto LABEL_7;
}
++v1;
LABEL_7:
*v3 = 0;
if ( v3 <= &buf_0 )
{
*a1 = v1;
result = &buf_0;
if ( v3 == &buf_0 )
result = 0LL;
}
else
{
if ( *(v3 - 1) != 47 )
*(_WORD *)&v3[strlen(v3)] = 47;
*a1 = v1;
result = &buf_0;
}
}
else
{
buf_0 = 0;
*a1 = v1;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func11(char **a1)
{
char *v1; // rbp
char v2; // al
char *v3; // rbx
char *result; // rax

v1 = *a1;
v2 = **a1;
if ( v2 )
{
v3 = &buf_0;
while ( v2 != 58 )
{
++v1;
*v3++ = v2;
v2 = *v1;
if ( !*v1 )
goto LABEL_7;
}
++v1;
LABEL_7:
*v3 = 0;
if ( v3 <= &buf_0 )
{
*a1 = v1;
result = &buf_0;
if ( v3 == &buf_0 )
result = 0LL;
}
else
{
if ( *(v3 - 1) != 47 )
*(_WORD *)&v3[strlen(v3)] = 47;
*a1 = v1;
result = &buf_0;
}
}
else
{
buf_0 = 0;
*a1 = v1;
result = 0LL;
}
return result;
}

original_code:
static char *osparsepath(char **pp)
{
    static char buf[256];
    char *src,*dst;
    for (src = *pp, dst = buf; *src != '\0'; *dst++ = *src++)
 if (*src == ':') {
     ++src;
     break;
 }
    *dst = '\0';
    if (dst > buf && dst[-1] != '/')
 strcat(dst,"/");
    *pp = src;
    return dst == buf ? ((void *)0) : buf;
}

canonical_original_code:
static char *osparsepath(char **pp)
{
    static char buf[256];
    char *src; char *dst;
    for (src = *pp, dst = buf; *src != '\0'; *dst++ = *src++)
 if (*src == ':') {
     ++src;
     break;
 }
    *dst = '\0';
    if (dst > buf && dst[-1] != '/')
 strcat(dst,"/");
    *pp = src;
    return dst == buf ? ((void *)0) : buf;
}

variable_types:
pp
char **

variable_types:
buf
char [256]

variable_types:
src
char *

variable_types:
dst
char *


osloadpath

decompiled_code:
char *osloadpath()
{
char *result; // rax

result = getenv("XLPATH");
if ( !result )
result = (char *)progpath;
return result;
}

canonical_decompiled_code:
char *func12()
{
char *result; // rax

result = getenv("XLPATH");
if ( !result )
result = (char *)progpath;
return result;
}

original_code:
static char *osloadpath(void)
{
    char *path;
    if ((path = getenv("XLPATH")) == ((void *)0))
        path = progpath;
    return path;
}

canonical_original_code:
static char *osloadpath()
{
    char *path;
    if ((path = getenv("XLPATH")) == ((void *)0))
        path = progpath;
    return path;
}

variable_types:
path
char *


xlosLoadPath

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

if ( *(_QWORD *)callbacks )
result = (*(__int64 (**)(void))callbacks)();
else
result = 0LL;
return result;
}

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

if ( *(_QWORD *)callbacks )
result = (*(__int64 (**)(void))callbacks)();
else
result = 0LL;
return result;
}

original_code:
char *xlosLoadPath(void)
{
    return callbacks->loadPath ? (*callbacks->loadPath)() : ((void *)0);
}

canonical_original_code:
char *xlosLoadPath()
{
    return callbacks->loadPath ? (*callbacks->loadPath)() : ((void *)0);
}


xlosParsePath

decompiled_code:
__int64 xlosParsePath()
{
__int64 (*v0)(void); // rax
__int64 result; // rax

v0 = *(__int64 (**)(void))(callbacks + 8);
if ( v0 )
result = v0();
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 (*v0)(void); // rax
__int64 result; // rax

v0 = *(__int64 (**)(void))(callbacks + 8);
if ( v0 )
result = v0();
else
result = 0LL;
return result;
}

original_code:
char *xlosParsePath(char **pp)
{
    return callbacks->parsePath ? (*callbacks->parsePath)(pp) : ((void *)0);
}


xlosDirectorySeparator

decompiled_code:
__int64 xlosDirectorySeparator()
{
__int64 (*v0)(void); // rax
__int64 result; // rax

v0 = *(__int64 (**)(void))(callbacks + 16);
if ( v0 )
result = v0();
else
result = 92LL;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 (*v0)(void); // rax
__int64 result; // rax

v0 = *(__int64 (**)(void))(callbacks + 16);
if ( v0 )
result = v0();
else
result = 92LL;
return result;
}

original_code:
int xlosDirectorySeparator(void)
{
    return callbacks->directorySeparator ? (*callbacks->directorySeparator)() : '\\';
}

canonical_original_code:
int xlosDirectorySeparator()
{
    return callbacks->directorySeparator ? (*callbacks->directorySeparator)() : '\\';
}


xlosFileModTime

decompiled_code:
__int64 xlosFileModTime()
{
__int64 (*v0)(void); // rdx
__int64 result; // rax

v0 = *(__int64 (**)(void))(callbacks + 40);
result = 0LL;
if ( v0 )
result = v0();
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 (*v0)(void); // rdx
__int64 result; // rax

v0 = *(__int64 (**)(void))(callbacks + 40);
result = 0LL;
if ( v0 )
result = v0();
return result;
}

original_code:
int xlosFileModTime(char *fname,long *pModTime)
{
    return callbacks->fileModTime ? (*callbacks->fileModTime)(fname,pModTime) : 0;
}

canonical_original_code:
int xlosFileModTime(char *fname, long *pModTime)
{
    return callbacks->fileModTime ? (*callbacks->fileModTime)(fname,pModTime) : 0;
}


xlosConsoleGetC

decompiled_code:
__int64 xlosConsoleGetC()
{
__int64 (*v0)(void); // rax
int v1; // eax
unsigned int v2; // ebx

v0 = *(__int64 (**)(void))(callbacks + 48);
if ( !v0 )
return (unsigned int)-1;
v1 = v0();
v2 = v1;
if ( v1 != -1 && xlTranscriptFP )
putc(v1, xlTranscriptFP);
return v2;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 (*v0)(void); // rax
int v1; // eax
unsigned int v2; // ebx

v0 = *(__int64 (**)(void))(callbacks + 48);
if ( !v0 )
return (unsigned int)-1;
v1 = v0();
v2 = v1;
if ( v1 != -1 && xlTranscriptFP )
putc(v1, xlTranscriptFP);
return v2;
}

original_code:
int xlosConsoleGetC(void)
{
    int ch;
    ch = callbacks->consoleGetC ? (*callbacks->consoleGetC)() : (-1);
    if (xlTranscriptFP && ch != (-1))
        putc(ch,xlTranscriptFP);
    return ch;
}

canonical_original_code:
int xlosConsoleGetC()
{
    int ch;
    ch = callbacks->consoleGetC ? (*callbacks->consoleGetC)() : (-1);
    if (xlTranscriptFP && ch != (-1))
        putc(ch,xlTranscriptFP);
    return ch;
}

variable_types: ch int


xlosConsolePutC

decompiled_code:
int __fastcall xlosConsolePutC(int c)
{
__int64 (__fastcall *v1)(_QWORD); // rax

xlosCheck();
v1 = *(__int64 (__fastcall **)(_QWORD))(callbacks + 56);
if ( v1 )
LODWORD(v1) = v1((unsigned int)c);
if ( xlTranscriptFP )
LODWORD(v1) = putc(c, xlTranscriptFP);
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func8(int c)
{
__int64 (__fastcall *v1)(_QWORD); // rax

xlosCheck();
v1 = *(__int64 (__fastcall **)(_QWORD))(callbacks + 56);
if ( v1 )
LODWORD(v1) = v1((unsigned int)c);
if ( xlTranscriptFP )
LODWORD(v1) = putc(c, xlTranscriptFP);
return (int)v1;
}

original_code:
void xlosConsolePutC(int ch)
{
    xlosCheck();
    if (callbacks->consolePutC)
        (*callbacks->consolePutC)(ch);
    if (xlTranscriptFP)
        putc(ch,xlTranscriptFP);
}


xlosConsolePutS

decompiled_code:
int __fastcall xlosConsolePutS(char *a1)
{
char *v1; // rbx
char v2; // di
int result; // eax

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
++v1;
result = xlosConsolePutC(v2);
v2 = *v1;
}
while ( *v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(char *a1)
{
char *v1; // rbx
char v2; // di
int result; // eax

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
++v1;
result = func8(v2);
v2 = *v1;
}
while ( *v1 );
}
return result;
}

original_code:
void xlosConsolePutS(char *str)
{
    while (*str)
        xlosConsolePutC(*str++);
}

variable_types:
str
char *


xlosConsoleAtBOLP

decompiled_code:
__int64 xlosConsoleAtBOLP()
{
__int64 (*v0)(void); // rdx
__int64 result; // rax

v0 = *(__int64 (**)(void))(callbacks + 64);
result = 0LL;
if ( v0 )
result = v0();
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 (*v0)(void); // rdx
__int64 result; // rax

v0 = *(__int64 (**)(void))(callbacks + 64);
result = 0LL;
if ( v0 )
result = v0();
return result;
}

original_code:
int xlosConsoleAtBOLP(void)
{
    return callbacks->consoleAtBOLP ? (*callbacks->consoleAtBOLP)() : 0;
}

canonical_original_code:
int xlosConsoleAtBOLP()
{
    return callbacks->consoleAtBOLP ? (*callbacks->consoleAtBOLP)() : 0;
}


xlosConsoleCheck

decompiled_code:
__int64 xlosConsoleCheck()
{
__int64 (*v0)(void); // rdx
__int64 result; // rax

v0 = *(__int64 (**)(void))(callbacks + 88);
result = 0LL;
if ( v0 )
result = v0();
return result;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 (*v0)(void); // rdx
__int64 result; // rax

v0 = *(__int64 (**)(void))(callbacks + 88);
result = 0LL;
if ( v0 )
result = v0();
return result;
}

original_code:
int xlosConsoleCheck(void)
{
    return callbacks->consoleCheck ? (*callbacks->consoleCheck)() : 0;
}

canonical_original_code:
int xlosConsoleCheck()
{
    return callbacks->consoleCheck ? (*callbacks->consoleCheck)() : 0;
}


decompiled_code:
__int64 state_return()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 0LL;
}

original_code:
monad_t* state_return(void* v)
{
    state_t* st = malloc(sizeof(state_t));
    tuple_t* generator_func()
    {
        tuple_t* tuple = malloc(sizeof(tuple_t));
        tuple->fst = v;
        tuple->snd = (void*)(generator_func);
        return tuple;
    }
    st->runstate = (void*)generator_func;
    return ((void *)0);
}

canonical_original_code:
struct monad *state_return(void *v)
{
    struct state *st = malloc(sizeof(state_t));
    tuple_t* generator_func()
    {
        struct tuple *tuple = malloc(sizeof(tuple_t));
        tuple->fst = v;
        tuple->snd = (void *)(generator_func);
        return tuple;
    }
    st->runstate = (void *)generator_func;
    return ((void *)0);
}

variable_types:
v
void *

variable_types: struct state { struct tuple { void *fst; void *snd; } *(*runstate)(void *); } *

return_type: struct monad { void *mvalue; struct monad *(*mreturn)(void *); struct monad *(*mbind)(struct monad *, struct monad *(*)(struct monad *, void *)); } *

user_defined_types: struct state { struct tuple *(*runstate)(void *); }


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

if ( !a1 )
{
puts("Error: state_get - no monad!");
result = 0LL;
}
return result;
}

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

if ( !a1 )
{
puts("Error: state_get - no monad!");
result = 0LL;
}
return result;
}

original_code:
void* state_get(monad_t* m)
{
    if(!m) {
        printf("Error: state_get - no monad!\n");
        return ((void *)0);
    }
    state_t* st = m->mvalue;
}

canonical_original_code:
void *state_get(struct monad *m)
{
    if(!m) {
        printf("Error: state_get - no monad!\n");
        return ((void *)0);
    }
    struct state *st = m->mvalue;
}

variable_types: struct monad { void *mvalue; struct monad *(*mreturn)(void *); struct monad *(*mbind)(struct monad *, struct monad *(*)(struct monad *, void *)); } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx
_QWORD *v4; // rax

v3 = roll(0);
printf("rolled: %lu\n", *v3);
v4 = roll(v3[1]);
printf("rolled: %lu\n", *v4);
return 0;
}

original_code:
int main()
{
    tuple_t t = {0, 0};
    tuple_t* t2 = roll((uintptr_t)t.snd);
    printf("rolled: %lu\n",(uintptr_t)t2->fst);
    tuple_t* t3 = roll((uintptr_t)t2->snd);
    printf("rolled: %lu\n",(uintptr_t)t3->fst);
    return 0;
}

canonical_original_code:
int main()
{
    struct tuple t = {0, 0};
    struct tuple *t2 = roll((uintptr_t)t.snd);
    printf("rolled: %lu\n",(unsigned long)t2->fst);
    struct tuple *t3 = roll((uintptr_t)t2->snd);
    printf("rolled: %lu\n",(unsigned long)t3->fst);
    return 0;
}

variable_types:
t
struct tuple { void *fst; void *snd; }

variable_types: struct tuple { void *fst; void *snd; } *


repo: rebeccaskinner/cudalib

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
_BYTE v5[24584]; // [rsp+0h] [rbp-6008h] BYREF

memcpy(v5, aAbcabcabcabcab, 0x6000uLL);
v3 = cuda_interstitial_to_planar(v5, 24576LL);
print_matrix_generic(24LL, 64LL, 1LL, 3LL, 3LL, v3, &print_char);
return 0;
}

variable_types:
bm
unsigned char []

variable_types:
planar
unsigned char *


decompiled_code:
char *__fastcall generate_double_matrix(int a1, int a2)
{
char *v2; // r15
int v3; // er13
int i; // er12
double *v5; // rbx

v2 = (char *)malloc(a1 * a2);
if ( a2 > 0 )
{
v3 = 0;
for ( i = 0; i != a2; ++i )
{
if ( a1 > 0 )
{
v5 = (double *)&v2[8 * v3];
do
*v5++ = (double)(rand() % 100000 + 100) / 100.0;
while ( v5 != (double *)&v2[8 * v3 + 8 + 8 * (unsigned __int64)(unsigned int)(a1 - 1)] );
}
v3 += a1;
}
}
return v2;
}

original_code:
double* generate_double_matrix(int width, int height)
{
    double* mat = (double*)malloc(width*height);
    for(int j = 0; j < height; ++j)
        for(int k = 0; k < width; ++k)
            *(mat+((j*width)+k)) = ((double)((rand()%100000)+100)/100.0);
    return mat;
}

canonical_original_code:
double *generate_double_matrix(int width, int height)
{
    double *mat = (double*)malloc(width*height);
    for(int j = 0; j < height; ++j)
        for(int k = 0; k < width; ++k)
            *(mat+((j*width)+k)) = ((double)((rand()%100000)+100)/100.0);
    return mat;
}

variable_types: width int

variable_types: height int

variable_types:
mat
double *

variable_types: j int

variable_types: k int

return_type: double *


decompiled_code:
int __fastcall print_byte(unsigned __int8 *a1)
{
return printf(" 0x%02X ", *a1);
}

canonical_decompiled_code:
int __fastcall func2(unsigned __int8 *a1)
{
return printf(" 0x%02X ", *a1);
}

original_code:
void print_byte(void* b)
{
    printf(" 0x%02X ",*((byte*)(b)));
}

canonical_original_code:
void print_byte(void *b)
{
    printf(" 0x%02X ",*((unsigned char *)(b)));
}

variable_types:
b
void *


decompiled_code:
int __fastcall print_char(char *a1)
{
return printf(" %c ", (unsigned int)*a1);
}

canonical_decompiled_code:
int __fastcall func3(char *a1)
{
return printf(" %c ", (unsigned int)*a1);
}

original_code:
void print_char(void* b)
{
    printf(" %c ",*((char*)(b)));
}

canonical_original_code:
void print_char(void *b)
{
    printf(" %c ",*((char *)(b)));
}


decompiled_code:
int __fastcall print_double(double *a1)
{
return printf(" %+08.3f ", *a1);
}

canonical_decompiled_code:
int __fastcall func4(double *a1)
{
return printf(" %+08.3f ", *a1);
}

original_code:
void print_double(void* d)
{
    printf(" %+08.3f ",*((double*)(d)));
}

canonical_original_code:
void print_double(void *d)
{
    printf(" %+08.3f ",*((double *)(d)));
}

variable_types:
d
void *


original_code:
void print_matrix_generic(int elem_w, int elem_h, int elem_size,
                          int elem_width, int group_size, byte* elems,
                          elem_fn print_fn)
{
    int v_len = (elem_h * elem_size);
    int h_len = (elem_w * elem_size);
    color_printf(0,1,0,"+");
    for(int i = 0; i < elem_w; ++i)
    {
        for(int j = 0; j < elem_width; ++j)
            color_printf(0,1,0,"-");
            color_printf(0,1,0,"+");
    }
    printf("\n");
    for(int h = 0; h < elem_h; ++h)
    {
        color_printf(0,1,0,"|");
        for(int w = 0; w < elem_w; ++w)
        {
            print_fn(elems+((h*h_len)+(w*elem_size)));
            if(!((w+1)%group_size))
                color_printf(0,1,0,"|");
            else
                color_printf(0,4,0,"|");
        }
        printf("\n");
        color_printf(0,1,0,"+");
        for(int i = 0; i < elem_w; ++i)
        {
            for(int j = 0; j < elem_width; ++j)
            {
                if(!((h+1)%group_size))
                    color_printf(0,1,0,"-");
                else
                    color_printf(0,4,0,"-");
            }
            if((!((i+1)%group_size)) || !((h+1)%group_size))
                color_printf(0,1,0,"+");
            else
                color_printf(0,4,0,"+");
        }
        printf("\n");
    }
}

canonical_original_code:
void print_matrix_generic(int elem_w, int elem_h, int elem_size, int elem_width, int group_size, unsigned char *elems, void (*print_fn)(void *))
{
    int v_len = (elem_h * elem_size);
    int h_len = (elem_w * elem_size);
    color_printf(0,1,0,"+");
    for(int i = 0; i < elem_w; ++i)
    {
        for(int j = 0; j < elem_width; ++j)
            color_printf(0,1,0,"-");
            color_printf(0,1,0,"+");
    }
    printf("\n");
    for(int h = 0; h < elem_h; ++h)
    {
        color_printf(0,1,0,"|");
        for(int w = 0; w < elem_w; ++w)
        {
            print_fn(elems+((h*h_len)+(w*elem_size)));
            if(!((w+1)%group_size))
                color_printf(0,1,0,"|");
            else
                color_printf(0,4,0,"|");
        }
        printf("\n");
        color_printf(0,1,0,"+");
        for(int i = 0; i < elem_w; ++i)
        {
            for(int j = 0; j < elem_width; ++j)
            {
                if(!((h+1)%group_size))
                    color_printf(0,1,0,"-");
                else
                    color_printf(0,4,0,"-");
            }
            if((!((i+1)%group_size)) || !((h+1)%group_size))
                color_printf(0,1,0,"+");
            else
                color_printf(0,4,0,"+");
        }
        printf("\n");
    }
}

variable_types:
elems
unsigned char *

variable_types: i int

variable_types: h int

variable_types: w int


decompiled_code:
int __fastcall color_start(unsigned int a1, int a2, int a3)
{
return printf("%c[%d;%d;%dm", 27LL, a1, (unsigned int)(a2 + 30), (unsigned int)(a3 + 40));
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, int a2, int a3)
{
return printf("%c[%d;%d;%dm", 27LL, a1, (unsigned int)(a2 + 30), (unsigned int)(a3 + 40));
}

original_code:
void color_start(int mode, int fg, int bg)
{
    printf("%c[%d;%d;%dm",0x1B,mode,30+fg,40+bg);
}

variable_types: mode int

variable_types: fg int

variable_types: bg int


decompiled_code:
int color_stop()
{
return color_start(0, 7, 0);
}

canonical_decompiled_code:
int func1()
{
return func0(0, 7, 0);
}

original_code:
void color_stop()
{
    color_start(0,7,0);
}


decompiled_code:
int color_printf(unsigned int a1, int a2, int a3, const char *a4, __int64 a5, __int64 a6, ...)
{
gcc_va_list arg; // [rsp+28h] [rbp-C8h] BYREF
__int64 v9; // [rsp+60h] [rbp-90h]
__int64 v10; // [rsp+68h] [rbp-88h]

va_start(arg, a6);
v9 = a5;
v10 = a6;
color_start(a1, a2, a3);
arg[0].gp_offset = 32;
vprintf(a4, arg);
return color_stop();
}

canonical_decompiled_code:
int func2(unsigned int a1, int a2, int a3, const char *a4, __int64 a5, __int64 a6, ...)
{
gcc_va_list arg; // [rsp+28h] [rbp-C8h] BYREF
__int64 v9; // [rsp+60h] [rbp-90h]
__int64 v10; // [rsp+68h] [rbp-88h]

va_start(arg, a6);
v9 = a5;
v10 = a6;
func0(a1, a2, a3);
arg[0].gp_offset = 32;
vprintf(a4, arg);
return func1();
}

original_code:
void color_printf(int mode, int fg, int bg, const char* fmt, ...)
{
    color_start(mode,fg,bg);
    va_list va;
    __builtin_va_start(va,fmt);
    vprintf(fmt, va);
    __builtin_va_end(va);
    color_stop();
}

canonical_original_code:
void color_printf(int mode, int fg, int bg, char *fmt, ...)
{
    color_start(mode,fg,bg);
    __builtin_va_list va;
    __builtin_va_start(va,fmt);
    vprintf(fmt, va);
    __builtin_va_end(va);
    color_stop();
}

variable_types:
fmt
char *


decompiled_code:
double *__fastcall generate_double_matrix(unsigned __int64 a1, unsigned __int64 a2)
{
double *v3; // [rsp+10h] [rbp-10h]
int j; // [rsp+18h] [rbp-8h]
int i; // [rsp+1Ch] [rbp-4h]

v3 = (double *)malloc(a2 * a1);
for ( i = 0; a2 > i; ++i )
{
for ( j = 0; a1 > j; ++j )
v3[a1 * i + j] = (double)(rand() % 100000 + 100) / 100.0;
}
return v3;
}

canonical_decompiled_code:
double *__fastcall func0(unsigned __int64 a1, unsigned __int64 a2)
{
double *v3; // [rsp+10h] [rbp-10h]
int j; // [rsp+18h] [rbp-8h]
int i; // [rsp+1Ch] [rbp-4h]

v3 = (double *)malloc(a2 * a1);
for ( i = 0; a2 > i; ++i )
{
for ( j = 0; a1 > j; ++j )
v3[a1 * i + j] = (double)(rand() % 100000 + 100) / 100.0;
}
return v3;
}


decompiled_code:
int __fastcall print_byte(void *a1)
{
return printf(" 0x%02X ", *(unsigned __int8 *)a1);
}

canonical_decompiled_code:
int __fastcall func1(void *a1)
{
return printf(" 0x%02X ", *(unsigned __int8 *)a1);
}


decompiled_code:
int __fastcall print_double(void *a1)
{
return printf(" %+08.3f ", *(double *)a1);
}

canonical_decompiled_code:
int __fastcall func2(void *a1)
{
return printf(" %+08.3f ", *(double *)a1);
}


decompiled_code:
__int64 __fastcall print_matrix_generic(int a1, int a2, int a3, int a4, int a5, unsigned __int8 *a6, void (__fastcall *a7)(void *))
{
__int64 result; // rax
int v12; // [rsp+20h] [rbp-20h]
int n; // [rsp+28h] [rbp-18h]
int m; // [rsp+2Ch] [rbp-14h]
int l; // [rsp+30h] [rbp-10h]
unsigned int k; // [rsp+34h] [rbp-Ch]
int j; // [rsp+38h] [rbp-8h]
int i; // [rsp+3Ch] [rbp-4h]

v12 = a3 * a1;
color_printf(0LL, 1LL, 0LL, "+");
for ( i = 0; i < a1; ++i )
{
for ( j = 0; j < a4; ++j )
color_printf(0LL, 1LL, 0LL, "-");
color_printf(0LL, 1LL, 0LL, "+");
}
putchar(10);
for ( k = 0; ; ++k )
{
result = k;
if ( (int)k >= a2 )
break;
color_printf(0LL, 1LL, 0LL, "|");
for ( l = 0; l < a1; ++l )
{
a7(&a6[v12 * k + a3 * l]);
if ( (l + 1) % a5 )
color_printf(0LL, 4LL, 0LL, "|");
else
color_printf(0LL, 1LL, 0LL, "|");
}
putchar(10);
color_printf(0LL, 1LL, 0LL, "+");
for ( m = 0; m < a1; ++m )
{
for ( n = 0; n < a4; ++n )
{
if ( (int)(k + 1) % a5 )
color_printf(0LL, 4LL, 0LL, "-");
else
color_printf(0LL, 1LL, 0LL, "-");
}
if ( (m + 1) % a5 && (int)(k + 1) % a5 )
color_printf(0LL, 4LL, 0LL, "+");
else
color_printf(0LL, 1LL, 0LL, "+");
}
putchar(10);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, int a3, int a4, int a5, unsigned __int8 *a6, void (__fastcall *a7)(void *))
{
__int64 result; // rax
int v12; // [rsp+20h] [rbp-20h]
int n; // [rsp+28h] [rbp-18h]
int m; // [rsp+2Ch] [rbp-14h]
int l; // [rsp+30h] [rbp-10h]
unsigned int k; // [rsp+34h] [rbp-Ch]
int j; // [rsp+38h] [rbp-8h]
int i; // [rsp+3Ch] [rbp-4h]

v12 = a3 * a1;
color_printf(0LL, 1LL, 0LL, "+");
for ( i = 0; i < a1; ++i )
{
for ( j = 0; j < a4; ++j )
color_printf(0LL, 1LL, 0LL, "-");
color_printf(0LL, 1LL, 0LL, "+");
}
putchar(10);
for ( k = 0; ; ++k )
{
result = k;
if ( (int)k >= a2 )
break;
color_printf(0LL, 1LL, 0LL, "|");
for ( l = 0; l < a1; ++l )
{
a7(&a6[v12 * k + a3 * l]);
if ( (l + 1) % a5 )
color_printf(0LL, 4LL, 0LL, "|");
else
color_printf(0LL, 1LL, 0LL, "|");
}
putchar(10);
color_printf(0LL, 1LL, 0LL, "+");
for ( m = 0; m < a1; ++m )
{
for ( n = 0; n < a4; ++n )
{
if ( (int)(k + 1) % a5 )
color_printf(0LL, 4LL, 0LL, "-");
else
color_printf(0LL, 1LL, 0LL, "-");
}
if ( (m + 1) % a5 && (int)(k + 1) % a5 )
color_printf(0LL, 4LL, 0LL, "+");
else
color_printf(0LL, 1LL, 0LL, "+");
}
putchar(10);
}
return result;
}


repo: rebryant/Cloud-BDD

decompiled_code:
void __fastcall set_verblevel(int a1)
{
verblevel = a1;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
verblevel = a1;
}

original_code:
void set_verblevel(int level)
{
    verblevel = level;
}

variable_types: level int


decompiled_code:
bool __fastcall set_logfile(const char *a1)
{
logfile = fopen(a1, "w");
return logfile != 0LL;
}

canonical_decompiled_code:
bool __fastcall func2(const char *a1)
{
logfile = fopen(a1, "w");
return logfile != 0LL;
}

original_code:
_Bool set_logfile(char *file_name)
{
    logfile = fopen(file_name, "w");
    return logfile != ((void *)0);
}


err

decompiled_code:
void __noreturn err(char a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( !errfile )
init_files(stdout, stdout);
va_start(arg, a2);
fwrite("Error: ", 1uLL, 7uLL, errfile);
vfprintf(errfile, a2, arg);
fputc(10, errfile);
fflush(errfile);
if ( logfile )
{
va_end(arg);
va_start(arg, a2);
fwrite("Error: ", 1uLL, 7uLL, logfile);
vfprintf(logfile, a2, arg);
fputc(10, logfile);
fflush(logfile);
fclose(logfile);
}
if ( a1 )
{
if ( fatal_fun )
fatal_fun();
exit(1);
}
}

canonical_decompiled_code:
void __noreturn func4(char a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( !errfile )
func0(stdout, stdout);
va_start(arg, a2);
fwrite("Error: ", 1uLL, 7uLL, errfile);
vfprintf(errfile, a2, arg);
fputc(10, errfile);
fflush(errfile);
if ( logfile )
{
va_end(arg);
va_start(arg, a2);
fwrite("Error: ", 1uLL, 7uLL, logfile);
vfprintf(logfile, a2, arg);
fputc(10, logfile);
fflush(logfile);
fclose(logfile);
}
if ( a1 )
{
if ( fatal_fun )
fatal_fun();
exit(1);
}
}

original_code:
void err(_Bool fatal, char *fmt, ...)
{
    va_list ap;
    if (!errfile)
 init_files(stdout, stdout);
    __builtin_va_start(ap,fmt);
    fprintf(errfile, "Error: ");
    vfprintf(errfile, fmt, ap);
    fprintf(errfile, "\n");
    fflush(errfile);
    __builtin_va_end(ap);
    if (logfile) {
 __builtin_va_start(ap,fmt);
 fprintf(logfile, "Error: ");
 vfprintf(logfile, fmt, ap);
 fprintf(logfile, "\n");
 fflush(logfile);
 __builtin_va_end(ap);
 fclose(logfile);
    }
    if (fatal) {
 if (fatal_fun)
     fatal_fun();
 exit(1);
    }
}

canonical_original_code:
void err(_Bool fatal, char *fmt, ...)
{
    __builtin_va_list ap;
    if (!errfile)
 init_files(stdout, stdout);
    __builtin_va_start(ap,fmt);
    fprintf(errfile, "Error: ");
    vfprintf(errfile, fmt, ap);
    fprintf(errfile, "\n");
    fflush(errfile);
    __builtin_va_end(ap);
    if (logfile) {
 __builtin_va_start(ap,fmt);
 fprintf(logfile, "Error: ");
 vfprintf(logfile, fmt, ap);
 fprintf(logfile, "\n");
 fflush(logfile);
 __builtin_va_end(ap);
 fclose(logfile);
    }
    if (fatal) {
 if (fatal_fun)
     fatal_fun();
 exit(1);
    }
}


decompiled_code:
unsigned __int64 __fastcall check_exceed(__int64 a1)
{
unsigned __int64 v1; // rdi
unsigned __int64 result; // rax

v1 = current_bytes + a1;
result = (__int64)mblimit << 20;
if ( result < v1 && mblimit > 0 )
err(1, "Exceeded memory limit of %u megabytes with %lu bytes", (unsigned int)mblimit, v1);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(__int64 a1)
{
unsigned __int64 v1; // rdi
unsigned __int64 result; // rax

v1 = current_bytes + a1;
result = (__int64)mblimit << 20;
if ( result < v1 && mblimit > 0 )
func4(1, "Exceeded memory limit of %u megabytes with %lu bytes", (unsigned int)mblimit, v1);
return result;
}

original_code:
static void check_exceed(size_t new_bytes) {
    size_t limit_bytes = (size_t) mblimit << 20;
    size_t request_bytes = new_bytes + current_bytes;
    if (mblimit > 0 && request_bytes > limit_bytes) {
 err(1, "Exceeded memory limit of %u megabytes with %lu bytes", mblimit, request_bytes);
    }
}

canonical_original_code:
static void check_exceed(unsigned long new_bytes) {
    unsigned long limit_bytes = (size_t) mblimit << 20;
    unsigned long request_bytes = new_bytes + current_bytes;
    if (mblimit > 0 && request_bytes > limit_bytes) {
 err(1, "Exceeded memory limit of %u megabytes with %lu bytes", mblimit, request_bytes);
    }
}


sigalrmhandler

decompiled_code:
void __noreturn sigalrmhandler()
{
err(1, "Timeout after %d seconds", timelimit);
}

canonical_decompiled_code:
void __noreturn func6()
{
func4(1, "Timeout after %d seconds", timelimit);
}

original_code:
void sigalrmhandler(int sig) {
    err(1, "Timeout after %d seconds", timelimit);
}

variable_types: sig int


report

decompiled_code:
void report(int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( !verbfile )
init_files(stdout, stdout);
if ( verblevel >= a1 )
{
va_start(arg, a2);
vfprintf(verbfile, a2, arg);
fputc(10, verbfile);
fflush(verbfile);
if ( logfile )
{
va_end(arg);
va_start(arg, a2);
vfprintf(logfile, a2, arg);
fputc(10, logfile);
fflush(logfile);
}
}
}

canonical_decompiled_code:
void func7(int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( !verbfile )
func0(stdout, stdout);
if ( verblevel >= a1 )
{
va_start(arg, a2);
vfprintf(verbfile, a2, arg);
fputc(10, verbfile);
fflush(verbfile);
if ( logfile )
{
va_end(arg);
va_start(arg, a2);
vfprintf(logfile, a2, arg);
fputc(10, logfile);
fflush(logfile);
}
}
}

original_code:
void report(int level, char *fmt, ...)
{
    va_list ap;
    if (!verbfile)
 init_files(stdout, stdout);
    if (level <= verblevel) {
 __builtin_va_start(ap,fmt);
 vfprintf(verbfile, fmt, ap);
 fprintf(verbfile, "\n");
 fflush(verbfile);
 __builtin_va_end(ap);
 if (logfile) {
     __builtin_va_start(ap,fmt);
     vfprintf(logfile, fmt, ap);
     fprintf(logfile, "\n");
     fflush(logfile);
     __builtin_va_end(ap);
 }
    }
}

canonical_original_code:
void report(int level, char *fmt, ...)
{
    __builtin_va_list ap;
    if (!verbfile)
 init_files(stdout, stdout);
    if (level <= verblevel) {
 __builtin_va_start(ap,fmt);
 vfprintf(verbfile, fmt, ap);
 fprintf(verbfile, "\n");
 fflush(verbfile);
 __builtin_va_end(ap);
 if (logfile) {
     __builtin_va_start(ap,fmt);
     vfprintf(logfile, fmt, ap);
     fprintf(logfile, "\n");
     fflush(logfile);
     __builtin_va_end(ap);
 }
    }
}


decompiled_code:
void report_noreturn(int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( !verbfile )
init_files(stdout, stdout);
if ( verblevel >= a1 )
{
va_start(arg, a2);
vfprintf(verbfile, a2, arg);
fflush(verbfile);
if ( logfile )
{
va_end(arg);
va_start(arg, a2);
vfprintf(logfile, a2, arg);
fflush(logfile);
}
}
}

canonical_decompiled_code:
void func8(int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( !verbfile )
func0(stdout, stdout);
if ( verblevel >= a1 )
{
va_start(arg, a2);
vfprintf(verbfile, a2, arg);
fflush(verbfile);
if ( logfile )
{
va_end(arg);
va_start(arg, a2);
vfprintf(logfile, a2, arg);
fflush(logfile);
}
}
}

original_code:
void report_noreturn(int level, char *fmt, ...)
{
    va_list ap;
    if (!verbfile)
 init_files(stdout, stdout);
    if (level <= verblevel) {
 __builtin_va_start(ap,fmt);
 vfprintf(verbfile, fmt, ap);
 fflush(verbfile);
 __builtin_va_end(ap);
 if (logfile) {
     __builtin_va_start(ap,fmt);
     vfprintf(logfile, fmt, ap);
     fflush(logfile);
     __builtin_va_end(ap);
 }
    }
}

canonical_original_code:
void report_noreturn(int level, char *fmt, ...)
{
    __builtin_va_list ap;
    if (!verbfile)
 init_files(stdout, stdout);
    if (level <= verblevel) {
 __builtin_va_start(ap,fmt);
 vfprintf(verbfile, fmt, ap);
 fflush(verbfile);
 __builtin_va_end(ap);
 if (logfile) {
     __builtin_va_start(ap,fmt);
     vfprintf(logfile, fmt, ap);
     fflush(logfile);
     __builtin_va_end(ap);
 }
    }
}


decompiled_code:
void report_noreturn_nostdout(int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( !verbfile )
init_files(stdout, stdout);
if ( verblevel >= a1 )
{
if ( verbfile != stdout )
{
va_start(arg, a2);
vfprintf(verbfile, a2, arg);
fflush(verbfile);
}
if ( logfile )
{
va_end(arg);
va_start(arg, a2);
vfprintf(logfile, a2, arg);
fflush(logfile);
}
}
}

canonical_decompiled_code:
void func9(int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( !verbfile )
func0(stdout, stdout);
if ( verblevel >= a1 )
{
if ( verbfile != stdout )
{
va_start(arg, a2);
vfprintf(verbfile, a2, arg);
fflush(verbfile);
}
if ( logfile )
{
va_end(arg);
va_start(arg, a2);
vfprintf(logfile, a2, arg);
fflush(logfile);
}
}
}

original_code:
void report_noreturn_nostdout(int level, char *fmt, ...)
{
    va_list ap;
    if (!verbfile)
 init_files(stdout, stdout);
    if (level <= verblevel) {
 if (verbfile != stdout) {
     __builtin_va_start(ap,fmt);
     vfprintf(verbfile, fmt, ap);
     fflush(verbfile);
     __builtin_va_end(ap);
 }
 if (logfile) {
     __builtin_va_start(ap,fmt);
     vfprintf(logfile, fmt, ap);
     fflush(logfile);
     __builtin_va_end(ap);
 }
    }
}

canonical_original_code:
void report_noreturn_nostdout(int level, char *fmt, ...)
{
    __builtin_va_list ap;
    if (!verbfile)
 init_files(stdout, stdout);
    if (level <= verblevel) {
 if (verbfile != stdout) {
     __builtin_va_start(ap,fmt);
     vfprintf(verbfile, fmt, ap);
     fflush(verbfile);
     __builtin_va_end(ap);
 }
 if (logfile) {
     __builtin_va_start(ap,fmt);
     vfprintf(logfile, fmt, ap);
     fflush(logfile);
     __builtin_va_end(ap);
 }
    }
}


decompiled_code:
void __fastcall __noreturn fail_fun(char *format, __int64 a2)
{
size_t v2; // rax
void (*v3)(void); // rdx

sprintf(fail_buf, format, a2);
fail_buf[strlen(fail_buf)] = 10;
v2 = strlen(fail_buf);
rval = write(1, fail_buf, v2 + 1);
if ( logfile )
{
fputs(fail_buf, logfile);
v3 = (void (*)(void))fatal_fun;
if ( !fatal_fun )
goto LABEL_4;
}
else
{
v3 = (void (*)(void))fatal_fun;
if ( !fatal_fun )
goto LABEL_6;
}
v3();
LABEL_4:
if ( logfile )
fclose(logfile);
LABEL_6:
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(char *format, __int64 a2)
{
size_t v2; // rax
void (*v3)(void); // rdx

sprintf(fail_buf, format, a2);
fail_buf[strlen(fail_buf)] = 10;
v2 = strlen(fail_buf);
rval = write(1, fail_buf, v2 + 1);
if ( logfile )
{
fputs(fail_buf, logfile);
v3 = (void (*)(void))fatal_fun;
if ( !fatal_fun )
goto LABEL_4;
}
else
{
v3 = (void (*)(void))fatal_fun;
if ( !fatal_fun )
goto LABEL_6;
}
v3();
LABEL_4:
if ( logfile )
fclose(logfile);
LABEL_6:
exit(1);
}

original_code:
void fail_fun(char *format, char *msg) {
    sprintf(fail_buf, format, msg);
    fail_buf[strlen(fail_buf)] = '\n';
    rval = write(1, fail_buf, strlen(fail_buf)+1);
    if (logfile) {
 fputs(fail_buf, logfile);
    }
    if (fatal_fun)
 fatal_fun();
    if (logfile)
 fclose(logfile);
    exit(1);
}

variable_types:
format
char *

variable_types:
msg
char *


decompiled_code:
void *__fastcall malloc_or_fail(size_t size, __int64 a2)
{
void *result; // rax
size_t v3; // rbx
__int64 v4; // rdi
__int64 v5; // rdx

check_exceed(size);
result = malloc(size);
if ( !result )
fail_fun("Malloc returned NULL in %s", a2);
++allocate_cnt;
allocate_bytes += size;
v3 = current_bytes + size;
v4 = v3;
current_bytes = v3;
v5 = v3;
if ( peak_bytes >= v3 )
v5 = peak_bytes;
peak_bytes = v5;
if ( last_peak_bytes >= v3 )
v4 = last_peak_bytes;
last_peak_bytes = v4;
return result;
}

canonical_decompiled_code:
void *__fastcall func11(size_t size, __int64 a2)
{
void *result; // rax
size_t v3; // rbx
__int64 v4; // rdi
__int64 v5; // rdx

func5(size);
result = malloc(size);
if ( !result )
func10("Malloc returned NULL in %s", a2);
++allocate_cnt;
allocate_bytes += size;
v3 = current_bytes + size;
v4 = v3;
current_bytes = v3;
v5 = v3;
if ( peak_bytes >= v3 )
v5 = peak_bytes;
peak_bytes = v5;
if ( last_peak_bytes >= v3 )
v4 = last_peak_bytes;
last_peak_bytes = v4;
return result;
}

original_code:
void * malloc_or_fail(size_t bytes, char *fun_name) {
    check_exceed(bytes);
    void *p = malloc(bytes);
    if (!p) {
 fail_fun("Malloc returned NULL in %s", fun_name);
 return ((void *)0);
    }
    allocate_cnt++;
    allocate_bytes += bytes;
    current_bytes += bytes;
    peak_bytes = ((peak_bytes)<(current_bytes)?(current_bytes):(peak_bytes));
    last_peak_bytes = ((last_peak_bytes)<(current_bytes)?(current_bytes):(last_peak_bytes));
    return p;
}

canonical_original_code:
void *malloc_or_fail(unsigned long bytes, char *fun_name) {
    check_exceed(bytes);
    void *p = malloc(bytes);
    if (!p) {
 fail_fun("Malloc returned NULL in %s", fun_name);
 return ((void *)0);
    }
    allocate_cnt++;
    allocate_bytes += bytes;
    current_bytes += bytes;
    peak_bytes = ((peak_bytes)<(current_bytes)?(current_bytes):(peak_bytes));
    last_peak_bytes = ((last_peak_bytes)<(current_bytes)?(current_bytes):(last_peak_bytes));
    return p;
}

variable_types:
bytes
unsigned long

variable_types:
p
void *


decompiled_code:
void *__fastcall calloc_or_fail(size_t nmemb, size_t size, __int64 a3)
{
size_t v4; // rbx
void *v5; // rax
void *v6; // rdx
unsigned __int64 v7; // rax
__int64 v8; // rcx

v4 = size * nmemb;
check_exceed(size * nmemb);
v5 = calloc(nmemb, size);
if ( !v5 )
fail_fun("Calloc returned NULL in %s", a3);
v6 = v5;
++allocate_cnt;
allocate_bytes += v4;
v7 = current_bytes + v4;
current_bytes = v7;
v8 = v7;
if ( peak_bytes >= v7 )
v8 = peak_bytes;
peak_bytes = v8;
if ( last_peak_bytes >= v7 )
v7 = last_peak_bytes;
last_peak_bytes = v7;
return v6;
}

canonical_decompiled_code:
void *__fastcall func12(size_t nmemb, size_t size, __int64 a3)
{
size_t v4; // rbx
void *v5; // rax
void *v6; // rdx
unsigned __int64 v7; // rax
__int64 v8; // rcx

v4 = size * nmemb;
func5(size * nmemb);
v5 = calloc(nmemb, size);
if ( !v5 )
func10("Calloc returned NULL in %s", a3);
v6 = v5;
++allocate_cnt;
allocate_bytes += v4;
v7 = current_bytes + v4;
current_bytes = v7;
v8 = v7;
if ( peak_bytes >= v7 )
v8 = peak_bytes;
peak_bytes = v8;
if ( last_peak_bytes >= v7 )
v7 = last_peak_bytes;
last_peak_bytes = v7;
return v6;
}

original_code:
void *calloc_or_fail(size_t cnt, size_t bytes, char *fun_name) {
    check_exceed(cnt*bytes);
    void *p = calloc(cnt, bytes);
    if (!p) {
 fail_fun("Calloc returned NULL in %s", fun_name);
 return ((void *)0);
    }
    allocate_cnt++;
    allocate_bytes += cnt * bytes;
    current_bytes += cnt * bytes;
    peak_bytes = ((peak_bytes)<(current_bytes)?(current_bytes):(peak_bytes));
    last_peak_bytes = ((last_peak_bytes)<(current_bytes)?(current_bytes):(last_peak_bytes));
    return p;
}

canonical_original_code:
void *calloc_or_fail(unsigned long cnt, unsigned long bytes, char *fun_name) {
    check_exceed(cnt*bytes);
    void *p = calloc(cnt, bytes);
    if (!p) {
 fail_fun("Calloc returned NULL in %s", fun_name);
 return ((void *)0);
    }
    allocate_cnt++;
    allocate_bytes += cnt * bytes;
    current_bytes += cnt * bytes;
    peak_bytes = ((peak_bytes)<(current_bytes)?(current_bytes):(peak_bytes));
    last_peak_bytes = ((last_peak_bytes)<(current_bytes)?(current_bytes):(last_peak_bytes));
    return p;
}

variable_types:
cnt
unsigned long


decompiled_code:
void *__fastcall realloc_or_fail(void *ptr, unsigned __int64 a2, size_t a3, __int64 a4)
{
void *result; // rax
unsigned __int64 v7; // rdx
__int64 v8; // rcx

if ( a3 > a2 )
check_exceed(a3 - a2);
result = realloc(ptr, a3);
if ( !result )
fail_fun("Realloc returned NULL in %s", a4);
++allocate_cnt;
allocate_bytes += a3;
v7 = current_bytes + a3 - a2;
current_bytes = v7;
v8 = v7;
if ( peak_bytes >= v7 )
v8 = peak_bytes;
peak_bytes = v8;
if ( last_peak_bytes >= v7 )
v7 = last_peak_bytes;
last_peak_bytes = v7;
++free_cnt;
free_bytes += a2;
return result;
}

canonical_decompiled_code:
void *__fastcall func13(void *ptr, unsigned __int64 a2, size_t a3, __int64 a4)
{
void *result; // rax
unsigned __int64 v7; // rdx
__int64 v8; // rcx

if ( a3 > a2 )
func5(a3 - a2);
result = realloc(ptr, a3);
if ( !result )
func10("Realloc returned NULL in %s", a4);
++allocate_cnt;
allocate_bytes += a3;
v7 = current_bytes + a3 - a2;
current_bytes = v7;
v8 = v7;
if ( peak_bytes >= v7 )
v8 = peak_bytes;
peak_bytes = v8;
if ( last_peak_bytes >= v7 )
v7 = last_peak_bytes;
last_peak_bytes = v7;
++free_cnt;
free_bytes += a2;
return result;
}

original_code:
void * realloc_or_fail(void *old, size_t old_bytes, size_t new_bytes,
         char *fun_name) {
    if (new_bytes > old_bytes)
 check_exceed(new_bytes-old_bytes);
    void *p = realloc(old, new_bytes);
    if (!p) {
 fail_fun("Realloc returned NULL in %s", fun_name);
 return ((void *)0);
    }
    allocate_cnt++;
    allocate_bytes += new_bytes;
    current_bytes += (new_bytes-old_bytes);
    peak_bytes = ((peak_bytes)<(current_bytes)?(current_bytes):(peak_bytes));
    last_peak_bytes = ((last_peak_bytes)<(current_bytes)?(current_bytes):(last_peak_bytes));
    free_cnt++;
    free_bytes += old_bytes;
    return p;
}

canonical_original_code:
void *realloc_or_fail(void *old, unsigned long old_bytes, unsigned long new_bytes, char *fun_name) {
    if (new_bytes > old_bytes)
 check_exceed(new_bytes-old_bytes);
    void *p = realloc(old, new_bytes);
    if (!p) {
 fail_fun("Realloc returned NULL in %s", fun_name);
 return ((void *)0);
    }
    allocate_cnt++;
    allocate_bytes += new_bytes;
    current_bytes += (new_bytes-old_bytes);
    peak_bytes = ((peak_bytes)<(current_bytes)?(current_bytes):(peak_bytes));
    last_peak_bytes = ((last_peak_bytes)<(current_bytes)?(current_bytes):(last_peak_bytes));
    free_cnt++;
    free_bytes += old_bytes;
    return p;
}

variable_types:
old
void *


decompiled_code:
char *__fastcall strsave_or_fail(char *src, __int64 a2)
{
size_t v3; // rbp
char *v4; // rdi
unsigned __int64 v5; // rax
__int64 v6; // rdx

if ( !src )
return 0LL;
v3 = strlen(src);
check_exceed(v3 + 1);
v4 = (char *)malloc(v3 + 1);
if ( !v4 )
fail_fun("strsave failed in %s", a2);
++allocate_cnt;
allocate_bytes += v3 + 1;
v5 = v3 + current_bytes + 1;
current_bytes = v5;
v6 = v5;
if ( peak_bytes >= v5 )
v6 = peak_bytes;
peak_bytes = v6;
if ( last_peak_bytes >= v5 )
v5 = last_peak_bytes;
last_peak_bytes = v5;
return strcpy(v4, src);
}

canonical_decompiled_code:
char *__fastcall func14(char *src, __int64 a2)
{
size_t v3; // rbp
char *v4; // rdi
unsigned __int64 v5; // rax
__int64 v6; // rdx

if ( !src )
return 0LL;
v3 = strlen(src);
func5(v3 + 1);
v4 = (char *)malloc(v3 + 1);
if ( !v4 )
func10("strsave failed in %s", a2);
++allocate_cnt;
allocate_bytes += v3 + 1;
v5 = v3 + current_bytes + 1;
current_bytes = v5;
v6 = v5;
if ( peak_bytes >= v5 )
v6 = peak_bytes;
peak_bytes = v6;
if ( last_peak_bytes >= v5 )
v5 = last_peak_bytes;
last_peak_bytes = v5;
return strcpy(v4, src);
}

original_code:
char *strsave_or_fail(char *s, char *fun_name) {
    if (!s)
 return ((void *)0);
    size_t len = strlen(s);
    check_exceed(len+1);
    char *ss = malloc(len+1);
    if (!ss) {
 fail_fun("strsave failed in %s", fun_name);
    }
    allocate_cnt++;
    allocate_bytes += len+1;
    current_bytes += len+1;
    peak_bytes = ((peak_bytes)<(current_bytes)?(current_bytes):(peak_bytes));
    last_peak_bytes = ((last_peak_bytes)<(current_bytes)?(current_bytes):(last_peak_bytes));
    return strcpy(ss, s);
}

canonical_original_code:
char *strsave_or_fail(char *s, char *fun_name) {
    if (!s)
 return ((void *)0);
    unsigned long len = strlen(s);
    check_exceed(len+1);
    char *ss = malloc(len+1);
    if (!ss) {
 fail_fun("strsave failed in %s", fun_name);
    }
    allocate_cnt++;
    allocate_bytes += len+1;
    current_bytes += len+1;
    peak_bytes = ((peak_bytes)<(current_bytes)?(current_bytes):(peak_bytes));
    last_peak_bytes = ((last_peak_bytes)<(current_bytes)?(current_bytes):(last_peak_bytes));
    return strcpy(ss, s);
}

variable_types:
s
char *

variable_types:
len
unsigned long

variable_types:
ss
char *