decompiled_code:
__int64 __fastcall node_add_tail(unsigned __int64 *a1, unsigned __int64 a2)
{
__int64 result; // rax

if ( a1[1] )
{
node_insert(a1[1], 0LL, a2);
result = 0LL;
}
else
{
if ( *a1 )
{
fwrite("List corrupted\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
*a1 = a2;
result = 0LL;
a1[1] = a2;
}
return result;
}

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

if ( a1[1] )
{
func10(a1[1], 0LL, a2);
result = 0LL;
}
else
{
if ( *a1 )
{
fwrite("List corrupted\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
*a1 = a2;
result = 0LL;
a1[1] = a2;
}
return result;
}

original_code:
int
node_add_tail(struct list* lst, struct node* this)
{
        if (lst->tail == ((void *)0))
        {
                if (lst->head != ((void *)0))
                {
                        fprintf(stderr, "List corrupted\n");
                        exit(1);
                }
                else
                {
                        lst->head = this;
                        lst->tail = this;
                        return 0;
                }
        }
        node_insert(lst->tail, ((void *)0), this);
        return 0;
}

canonical_original_code:
int node_add_tail(struct list *lst, struct node *this)
{
        if (lst->tail == ((void *)0))
        {
                if (lst->head != ((void *)0))
                {
                        fprintf(stderr, "List corrupted\n");
                        exit(1);
                }
                else
                {
                        lst->head = this;
                        lst->tail = this;
                        return 0;
                }
        }
        node_insert(lst->tail, ((void *)0), this);
        return 0;
}

variable_types:
this
struct node *


repo: bemk/xorll

decompiled_code:
__int64 __fastcall node_add_head(unsigned __int64 *a1, unsigned __int64 a2)
{
__int64 result; // rax

if ( *a1 )
{
node_insert(0LL, *a1, a2);
result = 0LL;
}
else
{
if ( a1[1] )
{
fwrite("List corrupted\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
*a1 = a2;
result = 0LL;
a1[1] = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int64 *a1, unsigned __int64 a2)
{
__int64 result; // rax

if ( *a1 )
{
func10(0LL, *a1, a2);
result = 0LL;
}
else
{
if ( a1[1] )
{
fwrite("List corrupted\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
*a1 = a2;
result = 0LL;
a1[1] = a2;
}
return result;
}

original_code:
int node_add_head(struct list* lst, struct node* this)
{
        if (lst->head == ((void *)0))
        {
                if (lst->tail != ((void *)0))
                {
                        fprintf(stderr, "List corrupted\n");
                        exit(1);
                }
                else
                {
                        lst->head = this;
                        lst->tail = this;
                        return 0;
                }
        }
        node_insert(((void *)0), lst->head, this);
        return 0;
}

canonical_original_code:
int node_add_head(struct list *lst, struct node *this)
{
        if (lst->head == ((void *)0))
        {
                if (lst->tail != ((void *)0))
                {
                        fprintf(stderr, "List corrupted\n");
                        exit(1);
                }
                else
                {
                        lst->head = this;
                        lst->tail = this;
                        return 0;
                }
        }
        node_insert(((void *)0), lst->head, this);
        return 0;
}

variable_types: struct list { struct node { void *ptr; int data; struct list *lst; } *head; struct node *tail; } *

return_type: int

user_defined_types: struct list { struct node *head; struct node *tail; }


decompiled_code:
__int64 __fastcall node_get_next(__int64 a1, _QWORD *a2)
{
return a1 ^ *a2;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, _QWORD *a2)
{
return a1 ^ *a2;
}

original_code:
struct node*
node_get_next(struct node* prev, struct node* this)
{
        ulong l_prev = (ulong)prev;
        ulong l_this = (ulong)this->ptr;
        ulong l_next = l_prev ^ l_this;
        return (struct node*)l_next;
}

canonical_original_code:
struct node *node_get_next(struct node *prev, struct node *this)
{
        unsigned long l_prev = (ulong)prev;
        unsigned long l_this = (ulong)this->ptr;
        unsigned long l_next = l_prev ^ l_this;
        return (struct node *)l_next;
}

variable_types:
prev
struct node *

return_type: struct node { void *ptr; int data; struct list { struct node *head; struct node *tail; } *lst; } *

user_defined_types: struct node { void *ptr; int data; struct list *lst; }


decompiled_code:
int __fastcall debug_list(__int64 *a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
__int64 v3; // r12
__int64 v4; // rdx
__int64 v5; // rdi
__int64 v6; // rax

v1 = *a1;
if ( *a1 )
{
v2 = 0;
v3 = 0LL;
while ( 1 )
{
v4 = v2++;
fprintf(stdout, "%d) Current data %X\n", v4, *(unsigned int *)(v1 + 8));
v5 = v3;
v3 = v1;
v6 = node_get_next(v5, (_QWORD *)v1);
if ( !v6 )
break;
v1 = v6;
}
}
return fputc(10, stdout);
}

canonical_decompiled_code:
int __fastcall func14(__int64 *a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
__int64 v3; // r12
__int64 v4; // rdx
__int64 v5; // rdi
__int64 v6; // rax

v1 = *a1;
if ( *a1 )
{
v2 = 0;
v3 = 0LL;
while ( 1 )
{
v4 = v2++;
fprintf(stdout, "%d) Current data %X\n", v4, *(unsigned int *)(v1 + 8));
v5 = v3;
v3 = v1;
v6 = func13(v5, (_QWORD *)v1);
if ( !v6 )
break;
v1 = v6;
}
}
return fputc(10, stdout);
}

original_code:
void debug_list(struct list* lst)
{
        struct node* carriage = lst->head;
        struct node* last = ((void *)0);
        struct node* new;
        int i = 0;
        while (carriage != ((void *)0))
        {
                fprintf(stdout, "%d) Current data %X\n", i, carriage->data);
                new = node_get_next(last, carriage);
                last = carriage;
                carriage = new;
                i++;
        }
        fprintf(stdout, "\n");
}

canonical_original_code:
void debug_list(struct list *lst)
{
        struct node *carriage = lst->head;
        struct node *last = ((void *)0);
        struct node *new;
        int i = 0;
        while (carriage != ((void *)0))
        {
                fprintf(stdout, "%d) Current data %X\n", i, carriage->data);
                new = node_get_next(last, carriage);
                last = carriage;
                carriage = new;
                i++;
        }
        fprintf(stdout, "\n");
}

variable_types: struct node { void *ptr; int data; struct list { struct node *head; struct node *tail; } *lst; } *

variable_types: i int

return_type: void


decompiled_code:
__int64 __fastcall read_n(int a1, unsigned __int64 *a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v5; // rsi
__int64 result; // rax
ssize_t v8; // rax
ssize_t v9; // rax
int v10; // edx

v5 = *a2;
if ( v5 > a4 )
return 0LL;
v8 = read(a1, (void *)(a3 + v5), a4 - v5);
if ( v8 == -1 )
{
v10 = *_errno_location();
if ( v10 == 4 )
return 3LL;
result = 2LL;
if ( v10 == 11 )
return 3LL;
}
else
{
if ( v8 )
{
v9 = *a2 + v8;
*a2 = v9;
if ( v9 == a4 )
return 0LL;
return 3LL;
}
*_errno_location() = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, unsigned __int64 *a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v5; // rsi
__int64 result; // rax
ssize_t v8; // rax
ssize_t v9; // rax
int v10; // edx

v5 = *a2;
if ( v5 > a4 )
return 0LL;
v8 = read(a1, (void *)(a3 + v5), a4 - v5);
if ( v8 == -1 )
{
v10 = *_errno_location();
if ( v10 == 4 )
return 3LL;
result = 2LL;
if ( v10 == 11 )
return 3LL;
}
else
{
if ( v8 )
{
v9 = *a2 + v8;
*a2 = v9;
if ( v9 == a4 )
return 0LL;
return 3LL;
}
*_errno_location() = 0;
result = 1LL;
}
return result;
}

original_code:
static enum read_status read_n(int fd, size_t* filled, void* buf, size_t size) {
  ssize_t ret;
  if (*filled > size)
    return READ_DONE;
  ret = read(fd, (char*) buf + *filled, size - *filled);
  if (ret == -1) {
    if ((*__errno_location ()) == 4 || (*__errno_location ()) == 11 || (*__errno_location ()) == 11)
      return READ_AGAIN;
    return READ_ERROR;
  } else if (ret == 0) {
    (*__errno_location ()) = 0;
    return READ_EOF;
  }
  *filled += (size_t) ret;
  if (*filled == size)
    return READ_DONE;
  return READ_AGAIN;
}

canonical_original_code:
static enum read_status read_n(int fd, unsigned long *filled, void *buf, unsigned long size) {
  long ret;
  if (*filled > size)
    return READ_DONE;
  ret = read(fd, (char *) buf + *filled, size - *filled);
  if (ret == -1) {
    if ((*__errno_location ()) == 4 || (*__errno_location ()) == 11 || (*__errno_location ()) == 11)
      return READ_AGAIN;
    return READ_ERROR;
  } else if (ret == 0) {
    (*__errno_location ()) = 0;
    return READ_EOF;
  }
  *filled += (unsigned long) ret;
  if (*filled == size)
    return READ_DONE;
  return READ_AGAIN;
}

variable_types: fd int

variable_types:
filled
unsigned long *

variable_types:
buf
void *

variable_types:
size
unsigned long

variable_types: ret long

return_type: enum read_status { READ_DONE=0, READ_EOF=1, READ_ERROR=2, READ_AGAIN=3 }


decompiled_code:
int __fastcall inspect_msg(__int64 a1)
{
__int64 v1; // rsi
int result; // eax
const char *v3; // rsi

fwrite("Mumble: ", 1uLL, 8uLL, stdout);
v1 = *(unsigned int *)(a1 + 8);
switch ( (int)v1 )
{
case 0:
result = printf("Init(%u, %u)\n", *(unsigned int *)(a1 + 12), *(unsigned int *)(a1 + 16));
break;
case 1:
result = printf("Shmem(%s)\n", (const char *)(a1 + 12));
break;
case 2:
result = printf(
"Blit(%u, %u, %u, %u)\n",
*(unsigned int *)(a1 + 12),
*(unsigned int *)(a1 + 16),
*(unsigned int *)(a1 + 20),
*(unsigned int *)(a1 + 24));
break;
case 3:
result = printf(
"Active(%u, %u, %u, %u)\n",
*(unsigned int *)(a1 + 12),
*(unsigned int *)(a1 + 16),
*(unsigned int *)(a1 + 20),
*(unsigned int *)(a1 + 24));
break;
case 4:
result = printf("Pid(%u)\n", *(unsigned int *)(a1 + 12));
break;
case 5:
result = printf("Fps(%f)\n", *(float *)(a1 + 12));
break;
case 6:
v3 = "true";
if ( !*(_BYTE *)(a1 + 12) )
v3 = "false";
result = printf("Interactive(%s)\n", v3);
break;
default:
result = printf("??? %u %d\n", v1, *(unsigned int *)(a1 + 4));
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
__int64 v1; // rsi
int result; // eax
const char *v3; // rsi

fwrite("Mumble: ", 1uLL, 8uLL, stdout);
v1 = *(unsigned int *)(a1 + 8);
switch ( (int)v1 )
{
case 0:
result = printf("Init(%u, %u)\n", *(unsigned int *)(a1 + 12), *(unsigned int *)(a1 + 16));
break;
case 1:
result = printf("Shmem(%s)\n", (const char *)(a1 + 12));
break;
case 2:
result = printf(
"Blit(%u, %u, %u, %u)\n",
*(unsigned int *)(a1 + 12),
*(unsigned int *)(a1 + 16),
*(unsigned int *)(a1 + 20),
*(unsigned int *)(a1 + 24));
break;
case 3:
result = printf(
"Active(%u, %u, %u, %u)\n",
*(unsigned int *)(a1 + 12),
*(unsigned int *)(a1 + 16),
*(unsigned int *)(a1 + 20),
*(unsigned int *)(a1 + 24));
break;
case 4:
result = printf("Pid(%u)\n", *(unsigned int *)(a1 + 12));
break;
case 5:
result = printf("Fps(%f)\n", *(float *)(a1 + 12));
break;
case 6:
v3 = "true";
if ( !*(_BYTE *)(a1 + 12) )
v3 = "false";
result = printf("Interactive(%s)\n", v3);
break;
default:
result = printf("??? %u %d\n", v1, *(unsigned int *)(a1 + 4));
break;
}
return result;
}

original_code:
static void inspect_msg(struct OverlayMsg* msg) {
  fputs("Mumble: ", stdout);
  switch (msg->omh.uiType) {
    case 0:
      printf("Init(%u, %u)\n", msg->body.omi.uiWidth, msg->body.omi.uiHeight);
      break;
    case 1:
      printf("Shmem(%s)\n", msg->body.oms.a_cName);
      break;
    case 2:
      printf("Blit(%u, %u, %u, %u)\n", msg->body.omb.x, msg->body.omb.y, msg->body.omb.w, msg->body.omb.h);
      break;
    case 3:
      printf("Active(%u, %u, %u, %u)\n", msg->body.oma.x, msg->body.oma.y, msg->body.oma.w, msg->body.oma.h);
      break;
    case 4:
      printf("Pid(%u)\n", msg->body.omp.pid);
      break;
    case 5:
      printf("Fps(%f)\n", (double) msg->body.omf.fps);
      break;
    case 6:
      printf("Interactive(%s)\n", msg->body.omin.state ? "true" : "false");
      break;
    default:
      printf("??? %u %d\n", msg->omh.uiType, msg->omh.iLength);
      break;
  }
}

canonical_original_code:
static void inspect_msg(struct OverlayMsg *msg) {
  fputs("Mumble: ", stdout);
  switch (msg->omh.uiType) {
    case 0:
      printf("Init(%u, %u)\n", msg->body.omi.uiWidth, msg->body.omi.uiHeight);
      break;
    case 1:
      printf("Shmem(%s)\n", msg->body.oms.a_cName);
      break;
    case 2:
      printf("Blit(%u, %u, %u, %u)\n", msg->body.omb.x, msg->body.omb.y, msg->body.omb.w, msg->body.omb.h);
      break;
    case 3:
      printf("Active(%u, %u, %u, %u)\n", msg->body.oma.x, msg->body.oma.y, msg->body.oma.w, msg->body.oma.h);
      break;
    case 4:
      printf("Pid(%u)\n", msg->body.omp.pid);
      break;
    case 5:
      printf("Fps(%f)\n", (double) msg->body.omf.fps);
      break;
    case 6:
      printf("Interactive(%s)\n", msg->body.omin.state ? "true" : "false");
      break;
    default:
      printf("??? %u %d\n", msg->omh.uiType, msg->omh.iLength);
      break;
  }
}

variable_types: struct OverlayMsg { struct OverlayMsgHeader { unsigned int uiMagic; int iLength; unsigned int uiType; } omh; union { struct OverlayMsgShmem { char a_cName[2048]; } oms; struct OverlayMsgInit { unsigned int uiWidth; unsigned int uiHeight; } omi; struct OverlayMsgBlit { unsigned int x; } omb; struct OverlayMsgActive { unsigned int x; } oma; struct OverlayMsgPid { unsigned int pid; } omp; struct OverlayMsgFps { float fps; } omf; struct OverlayMsgInteractive { char state; } omin; } body; } *

user_defined_types: struct OverlayMsg { struct OverlayMsgHeader omh; union { struct OverlayMsgShmem oms; struct OverlayMsgInit omi; struct OverlayMsgBlit omb; struct OverlayMsgActive oma; struct OverlayMsgPid omp; struct OverlayMsgFps omf; struct OverlayMsgInteractive omin; } body; }


decompiled_code:
void *__fastcall open_mumble_shm(size_t len, char *name)
{
int v2; // eax
int v3; // ebp
void *v4; // r12
int *v5; // rax
int v6; // er13
int *v7; // rbx

v2 = shm_open(name, 0, 0x180u);
if ( v2 == -1 )
{
v4 = 0LL;
perror("shm_open");
}
else
{
v3 = v2;
v4 = mmap(0LL, len, 1, 1, v2, 0LL);
v5 = _errno_location();
v6 = *v5;
v7 = v5;
close(v3);
*v7 = v6;
if ( !v4 )
perror("mmap");
}
return v4;
}

canonical_decompiled_code:
void *__fastcall func2(size_t len, char *name)
{
int v2; // eax
int v3; // ebp
void *v4; // r12
int *v5; // rax
int v6; // er13
int *v7; // rbx

v2 = shm_open(name, 0, 0x180u);
if ( v2 == -1 )
{
v4 = 0LL;
perror("shm_open");
}
else
{
v3 = v2;
v4 = mmap(0LL, len, 1, 1, v2, 0LL);
v5 = _errno_location();
v6 = *v5;
v7 = v5;
close(v3);
*v7 = v6;
if ( !v4 )
perror("mmap");
}
return v4;
}

original_code:
static void* open_mumble_shm(size_t mmap_size, const char* name) {
  int fd;
  void* ptr;
  int my_errno;
  fd = shm_open(name, 00, 0600);
  if (fd == -1) {
    perror("shm_open");
    return ((void *)0);
  }
  ptr = mmap(((void *)0), mmap_size, 0x1, 0x01, fd, 0);
  my_errno = (*__errno_location ());
  close(fd);
  (*__errno_location ()) = my_errno;
  if (ptr == 0) {
    perror("mmap");
    return ((void *)0);
  }
  return ptr;
}

canonical_original_code:
static void *open_mumble_shm(unsigned long mmap_size, char *name) {
  int fd;
  void *ptr;
  int my_errno;
  fd = shm_open(name, 00, 0600);
  if (fd == -1) {
    perror("shm_open");
    return ((void *)0);
  }
  ptr = mmap(((void *)0), mmap_size, 0x1, 0x01, fd, 0);
  my_errno = (*__errno_location ());
  close(fd);
  (*__errno_location ()) = my_errno;
  if (ptr == 0) {
    perror("mmap");
    return ((void *)0);
  }
  return ptr;
}

variable_types:
name
char *

variable_types:
ptr
void *

return_type: void *


decompiled_code:
__int64 __fastcall get_mumble_pipe_path(char *a1, const char *a2)
{
__m128i *v2; // rax
__int64 result; // rax

v2 = (__m128i *)stpcpy(a1, a2);
if ( (unsigned __int64)((char *)v2 - a1 + 19) > 0x6C )
{
*_errno_location() = 36;
result = 0xFFFFFFFFLL;
}
else
{
strcpy(v2[1].m128i_i8, "pe");
*v2 = _mm_load_si128((const __m128i *)&FILENAME_BIT_0);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, const char *a2)
{
__m128i *v2; // rax
__int64 result; // rax

v2 = (__m128i *)stpcpy(a1, a2);
if ( (unsigned __int64)((char *)v2 - a1 + 19) > 0x6C )
{
*_errno_location() = 36;
result = 0xFFFFFFFFLL;
}
else
{
strcpy(v2[1].m128i_i8, "pe");
*v2 = _mm_load_si128((const __m128i *)&FILENAME_BIT_0);
result = 0LL;
}
return result;
}

original_code:
static int get_mumble_pipe_path(char* buf, const char* home) {
  static const char FILENAME_BIT[] = "/" "MumbleOverlayPipe";
  size_t len;
  strcpy(buf, home);
  len = strlen(buf);
  if (len + sizeof(FILENAME_BIT) > (sizeof(((struct sockaddr_un*) 0)->sun_path))) {
    (*__errno_location ()) = 36;
    return -1;
  }
  strcpy(buf + len, FILENAME_BIT);
  return 0;
}

canonical_original_code:
static int get_mumble_pipe_path(char *buf, char *home) {
  static char FILENAME_BIT[] = "/" "MumbleOverlayPipe";
  unsigned long len;
  strcpy(buf, home);
  len = strlen(buf);
  if (len + sizeof(FILENAME_BIT) > (sizeof(((struct sockaddr_un *) 0)->sun_path))) {
    (*__errno_location ()) = 36;
    return -1;
  }
  strcpy(buf + len, FILENAME_BIT);
  return 0;
}

variable_types:
buf
char *

variable_types:
home
char *

variable_types:
len
unsigned long

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
__int64 __fastcall open_unix_socket(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
struct sockaddr v4[7]; // [rsp+0h] [rbp-78h] BYREF

v4[0].sa_family = 1;
if ( (unsigned int)get_mumble_pipe_path(v4[0].sa_data, a1) == -1 )
goto LABEL_6;
v1 = socket(1, 1, 0);
v2 = v1;
if ( v1 == -1 )
goto LABEL_6;
if ( connect(v1, v4, 0x6Eu) == -1 )
{
close(v2);
LABEL_6:
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
struct sockaddr v4[7]; // [rsp+0h] [rbp-78h] BYREF

v4[0].sa_family = 1;
if ( (unsigned int)func4(v4[0].sa_data, a1) == -1 )
goto LABEL_6;
v1 = socket(1, 1, 0);
v2 = v1;
if ( v1 == -1 )
goto LABEL_6;
if ( connect(v1, v4, 0x6Eu) == -1 )
{
close(v2);
LABEL_6:
v2 = -1;
}
return v2;
}

original_code:
static int open_unix_socket(const char* path) {
  int sock;
  struct sockaddr_un addr;
  addr.sun_family = 1;
  if (get_mumble_pipe_path(addr.sun_path, path) == -1)
    return -1;
  sock = socket(1, SOCK_STREAM, 0);
  if (sock == -1)
    return -1;
  if (connect(sock, (struct sockaddr*) &addr, sizeof addr) == -1) {
    close(sock);
    return -1;
  }
  return sock;
}

canonical_original_code:
static int open_unix_socket(char *path) {
  int sock;
  struct sockaddr_un addr;
  addr.sun_family = 1;
  if (get_mumble_pipe_path(addr.sun_path, path) == -1)
    return -1;
  sock = socket(1, SOCK_STREAM, 0);
  if (sock == -1)
    return -1;
  if (connect(sock, (struct sockaddr *) &addr, sizeof addr) == -1) {
    close(sock);
    return -1;
  }
  return sock;
}

variable_types:
path
char *

variable_types: sock int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall send_mumble_init_msg(int fd, unsigned __int16 a2, unsigned __int16 a3)
{
unsigned __int64 v3; // rbp
ssize_t v4; // rax
ssize_t v5; // rbx
int v6; // eax
__int64 v8; // [rsp+0h] [rbp-838h] BYREF
int v9; // [rsp+8h] [rbp-830h]
int v10; // [rsp+Ch] [rbp-82Ch]
int v11; // [rsp+10h] [rbp-828h]

v3 = 0LL;
v8 = 0x800000005LL;
v9 = 0;
v10 = a2;
v11 = a3;
do
{
v4 = write(fd, &v8, 20 - v3);
v5 = v4;
if ( v4 == -1 )
{
v6 = *_errno_location();
if ( v6 != 11 && v6 != 4 )
{
LABEL_7:
close(fd);
return 0xFFFFFFFFLL;
}
}
else if ( !v4 )
{
goto LABEL_7;
}
v3 += v5;
}
while ( v3 <= 0x13 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd, unsigned __int16 a2, unsigned __int16 a3)
{
unsigned __int64 v3; // rbp
ssize_t v4; // rax
ssize_t v5; // rbx
int v6; // eax
__int64 v8; // [rsp+0h] [rbp-838h] BYREF
int v9; // [rsp+8h] [rbp-830h]
int v10; // [rsp+Ch] [rbp-82Ch]
int v11; // [rsp+10h] [rbp-828h]

v3 = 0LL;
v8 = 0x800000005LL;
v9 = 0;
v10 = a2;
v11 = a3;
do
{
v4 = write(fd, &v8, 20 - v3);
v5 = v4;
if ( v4 == -1 )
{
v6 = *_errno_location();
if ( v6 != 11 && v6 != 4 )
{
LABEL_7:
close(fd);
return 0xFFFFFFFFLL;
}
}
else if ( !v4 )
{
goto LABEL_7;
}
v3 += v5;
}
while ( v3 <= 0x13 );
return 0LL;
}

original_code:
static int send_mumble_init_msg(int sock, uint16_t width, uint16_t height) {
  size_t msg_written, msgsize;
  struct OverlayMsg msg;
  ssize_t ret;
  msg.omh.uiMagic = 0x00000005;
  msg.omh.uiType = 0;
  msg.omh.iLength = sizeof(struct OverlayMsgInit);
  msg.body.omi.uiWidth = width;
  msg.body.omi.uiHeight = height;
  msgsize = sizeof(struct OverlayMsgHeader) + sizeof(struct OverlayMsgInit);
  msg_written = 0;
  while (msg_written < msgsize) {
    ret = write(sock, &msg, msgsize - msg_written);
    if ((ret == -1 && ((*__errno_location ()) != 11 && (*__errno_location ()) != 4)) || ret == 0) {
      close(sock);
      return -1;
    }
    msg_written += (size_t) ret;
  }
  return 0;
}

canonical_original_code:
static int send_mumble_init_msg(int sock, unsigned short width, unsigned short height) {
  unsigned long msg_written; unsigned long msgsize;
  struct OverlayMsg msg;
  long ret;
  msg.omh.uiMagic = 0x00000005;
  msg.omh.uiType = 0;
  msg.omh.iLength = sizeof(struct OverlayMsgInit);
  msg.body.omi.uiWidth = width;
  msg.body.omi.uiHeight = height;
  msgsize = sizeof(struct OverlayMsgHeader) + sizeof(struct OverlayMsgInit);
  msg_written = 0;
  while (msg_written < msgsize) {
    ret = write(sock, &msg, msgsize - msg_written);
    if ((ret == -1 && ((*__errno_location ()) != 11 && (*__errno_location ()) != 4)) || ret == 0) {
      close(sock);
      return -1;
    }
    msg_written += (unsigned long) ret;
  }
  return 0;
}

variable_types:
width
unsigned short

variable_types:
height
unsigned short

variable_types:
msgsize
unsigned long

variable_types: struct OverlayMsg { struct OverlayMsgHeader { unsigned int uiMagic; int iLength; unsigned int uiType; } omh; union { struct OverlayMsgShmem { char a_cName[2048]; } oms; struct OverlayMsgInit { unsigned int uiWidth; unsigned int uiHeight; } omi; struct OverlayMsgBlit { unsigned int x; } omb; struct OverlayMsgActive { unsigned int x; } oma; struct OverlayMsgPid { unsigned int pid; } omp; struct OverlayMsgFps { float fps; } omf; struct OverlayMsgInteractive { char state; } omin; } body; }


decompiled_code:
__int64 __fastcall inotify_init_watch_creates(char *name)
{
int v1; // eax
unsigned int v2; // er12
int v4; // edi

v1 = inotify_init();
v2 = v1;
if ( v1 == -1 )
{
perror("inotify_init");
}
else if ( inotify_add_watch(v1, name, 0x100u) == -1 )
{
perror("inotify_add_watch");
v4 = v2;
v2 = -1;
close(v4);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *name)
{
int v1; // eax
unsigned int v2; // er12
int v4; // edi

v1 = inotify_init();
v2 = v1;
if ( v1 == -1 )
{
perror("inotify_init");
}
else if ( inotify_add_watch(v1, name, 0x100u) == -1 )
{
perror("inotify_add_watch");
v4 = v2;
v2 = -1;
close(v4);
}
return v2;
}

original_code:
static int inotify_init_watch_creates(const char* dir) {
  int inotify;
  if ((inotify = inotify_init()) == -1) {
    perror("inotify_init");
    return -1;
  }
  if (inotify_add_watch(inotify, dir, 0x00000100) == -1) {
    perror("inotify_add_watch");
    close(inotify);
    return -1;
  }
  return inotify;
}

canonical_original_code:
static int inotify_init_watch_creates(char *dir) {
  int inotify;
  if ((inotify = inotify_init()) == -1) {
    perror("inotify_init");
    return -1;
  }
  if (inotify_add_watch(inotify, dir, 0x00000100) == -1) {
    perror("inotify_add_watch");
    close(inotify);
    return -1;
  }
  return inotify;
}

variable_types:
dir
char *

variable_types: inotify int


repo: benf/car

decompiled_code:
int __fastcall tx_cmd(unsigned __int8 a1, unsigned __int8 a2)
{
putc(170, stdout);
usleep(1u);
putc(a1, stdout);
usleep(1u);
putc(a2, stdout);
usleep(1u);
fflush(stdout);
fprintf(stderr, "%c: %x\n", a1, a2);
return usleep(5u);
}

canonical_decompiled_code:
int __fastcall func7(unsigned __int8 a1, unsigned __int8 a2)
{
putc(170, stdout);
usleep(1u);
putc(a1, stdout);
usleep(1u);
putc(a2, stdout);
usleep(1u);
fflush(stdout);
fprintf(stderr, "%c: %x\n", a1, a2);
return usleep(5u);
}

original_code:
void tx_cmd(uint8_t cmd, uint8_t param) {
 putc(0xAA, stdout);
 usleep(1);
 putc(cmd, stdout);
 usleep(1);
 putc(param, stdout);
 usleep(1);
 fflush(stdout);
 fprintf(stderr, "%c: %x\n", cmd, param);
 usleep(5);
}

canonical_original_code:
void tx_cmd(unsigned char cmd, unsigned char param) {
 putc(0xAA, stdout);
 usleep(1);
 putc(cmd, stdout);
 usleep(1);
 putc(param, stdout);
 usleep(1);
 fflush(stdout);
 fprintf(stderr, "%c: %x\n", cmd, param);
 usleep(5);
}

variable_types:
cmd
unsigned char

variable_types:
param
unsigned char


getTimeNow

repo: bengioe/ekanz

decompiled_code:
double getTimeNow()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(1, &v1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
double func0()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(1, &v1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double getTimeNow(){
    struct timespec t;
    clock_gettime(1, &t);;
    return t.tv_sec + (double) t.tv_nsec * 1e-9;
}

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

return_type: double


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rbp
double v6; // xmm0_8
double v8; // [rsp+8h] [rbp-10h]

ek_init_type(argc, argv, envp);
v3 = ek_raw_readfile(argv[1]);
v4 = ek_parse_text(v3, "test.py");
ek_parse_print_ast(v4);
putchar(10);
v8 = getTimeNow();
v5 = ek_bc_compile_ast(v4);
ek_bc_print(v5);
ek_vm_run(v5);
v6 = getTimeNow();
printf("%f seconds\n", v6 - v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rbp
double v6; // xmm0_8
double v8; // [rsp+8h] [rbp-10h]

ek_init_type(argc, argv, envp);
v3 = ek_raw_readfile(argv[1]);
v4 = ek_parse_text(v3, "test.py");
ek_parse_print_ast(v4);
putchar(10);
v8 = func0();
v5 = ek_bc_compile_ast(v4);
ek_bc_print(v5);
ek_vm_run(v5);
v6 = func0();
printf("%f seconds\n", v6 - v8);
return 0;
}

original_code:
int main(int argc, char** argv){
  ek_init_type();
  if (0){
    ek_type* strType = ek_type_derive(ek_NoneType, "__getitem__", 11);
    strType = ek_type_derive(strType, "__len__", 7);
    return 0;
  }
  char* file_data = ek_raw_readfile(argv[1]);
  ek_ast_node* ast = ek_parse_text(file_data, "test.py");
  ek_parse_print_ast(ast);
  printf("\n");
  double t0 = getTimeNow();
  ek_bytecode* bc = ek_bc_compile_ast(ast);
  ek_bc_print(bc);
  ek_vm_run(bc);
  double t1 = getTimeNow();
  printf("%f seconds\n",t1-t0);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  ek_init_type();
  if (0){
    struct ek_type *strType = ek_type_derive(ek_NoneType, "__getitem__", 11);
    strType = ek_type_derive(strType, "__len__", 7);
    return 0;
  }
  char *file_data = ek_raw_readfile(argv[1]);
  struct ek_ast_node *ast = ek_parse_text(file_data, "test.py");
  ek_parse_print_ast(ast);
  printf("\n");
  double t0 = getTimeNow();
  struct ek_bytecode *bc = ek_bc_compile_ast(ast);
  ek_bc_print(bc);
  ek_vm_run(bc);
  double t1 = getTimeNow();
  printf("%f seconds\n",t1-t0);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct ek_ast_node { char *tokstr; int toklen; int type; struct ek_ast_node *left; struct ek_ast_node *right; unsigned short local_scope_size; unsigned char isCompiledUnit; union x { struct var { unsigned int scoperef; int scopepos; struct ek_type { char *map; unsigned long map_size; unsigned long nentries; unsigned int extra_space; struct ek_type_entry { char *str; unsigned int strlen; unsigned int index; unsigned long xhash; unsigned long yhash; struct ek_type_entry *next; } *entry; } *predicted_type; } var; struct jit { unsigned char isLeafUnit; char *block; } jit; } x; } *

variable_types: struct ek_bytecode { char *data; int size; char *startptr; struct ek_bytecode *next; struct ek_basicblock { char *bcstart; char *bcend; struct ek_bblockversion { int nassumptions; int *types; void *code; } *bbv; } *startbb; struct ek_basicblock *bb; } *

user_defined_types: struct ek_type { char *map; unsigned long map_size; unsigned long nentries; unsigned int extra_space; struct ek_type_entry *entry; }

user_defined_types: struct ek_ast_node { char *tokstr; int toklen; int type; struct ek_ast_node *left; struct ek_ast_node *right; unsigned short local_scope_size; unsigned char isCompiledUnit; union x x; }

user_defined_types: struct ek_bytecode { char *data; int size; char *startptr; struct ek_bytecode *next; struct ek_basicblock *startbb; struct ek_basicblock *bb; }

user_defined_types: union x { struct var var; struct jit jit; }

user_defined_types: struct var { unsigned int scoperef; int scopepos; struct ek_type *predicted_type; }

user_defined_types: struct ek_basicblock { char *bcstart; char *bcend; struct ek_bblockversion *bbv; }


xhash

decompiled_code:
__int64 __fastcall xhash(char *a1, __int64 a2)
{
__int64 result; // rax
char *v3; // rsi
__int64 v4; // rdx

result = 0xCBF29CE484222325LL;
if ( a2 > 0 )
{
v3 = &a1[a2];
do
{
v4 = *a1++;
result = 0x100000001B3LL * (v4 ^ result);
}
while ( v3 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, __int64 a2)
{
__int64 result; // rax
char *v3; // rsi
__int64 v4; // rdx

result = 0xCBF29CE484222325LL;
if ( a2 > 0 )
{
v3 = &a1[a2];
do
{
v4 = *a1++;
result = 0x100000001B3LL * (v4 ^ result);
}
while ( v3 != a1 );
}
return result;
}

variable_types:
s
char *

variable_types: l long

variable_types:
h
unsigned long

return_type: unsigned long


yhash

decompiled_code:
__int64 __fastcall yhash(char *a1, __int64 a2)
{
char *v2; // rsi
__int64 result; // rax
__int64 v4; // rdx

if ( a2 <= 0 )
return 961748927LL;
v2 = &a1[a2];
result = 961748927LL;
do
{
v4 = *a1++;
result = 160481183 * (v4 + 32 * result);
}
while ( a1 != v2 );
return result;
}

original_code:
unsigned long yhash(char* s, long l){
  unsigned long h = 961748927;
  while (l-->0){h = ((h<<5) + *s++) * 160481183;}
  return h;
}

canonical_original_code:
unsigned long yhash(char *s, long l){
  unsigned long h = 961748927;
  while (l-->0){h = ((h<<5) + *s++) * 160481183;}
  return h;
}


decompiled_code:
_QWORD *ek_type_new()
{
_QWORD *result; // rax

result = malloc(0x28uLL);
result[1] = 0LL;
*result = 0LL;
result[2] = 0LL;
result[4] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *result; // rax

result = malloc(0x28uLL);
result[1] = 0LL;
*result = 0LL;
result[2] = 0LL;
result[4] = 0LL;
return result;
}

original_code:
ek_type* ek_type_new(){
  ek_type* t = malloc(sizeof(ek_type));
  t->map_size = 0;
  t->map = 0;
  t->nentries = 0;
  t->entry = ((void *)0);
  return t;
}

canonical_original_code:
struct ek_type *ek_type_new(){
  struct ek_type *t = malloc(sizeof(ek_type));
  t->map_size = 0;
  t->map = 0;
  t->nentries = 0;
  t->entry = ((void *)0);
  return t;
}

variable_types: struct ek_type { char *map; unsigned long map_size; unsigned long nentries; unsigned int extra_space; struct ek_type_entry { char *str; unsigned int strlen; unsigned int index; unsigned long xhash; unsigned long yhash; struct ek_type_entry *next; } *entry; } *


decompiled_code:
void ek_init_type()
{
_QWORD *v0; // rax

if ( !ek_NoneType )
{
ek_NoneType = (__int64)ek_type_new();
ek_NoneType = (__int64)ek_type_derive((_QWORD *)ek_NoneType, "__str__", 7LL);
ek_NoneType = (__int64)ek_type_derive((_QWORD *)ek_NoneType, "__eq__", 6LL);
ek_None = (__int64)ek_type_instanciate(ek_NoneType);
ek_IntType = (__int64)ek_type_new();
ek_FuncType = (__int64)ek_type_new();
v0 = ek_type_new();
*((_DWORD *)v0 + 6) = 8;
ek_CFuncType = (__int64)v0;
ek_StrType = (__int64)ek_type_new();
ek_StrType = (__int64)ek_type_derive((_QWORD *)ek_StrType, "__str__", 7LL);
*(_DWORD *)(ek_StrType + 24) = 16;
}
}

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

if ( !ek_NoneType )
{
ek_NoneType = (__int64)func2();
ek_NoneType = (__int64)ek_type_derive((_QWORD *)ek_NoneType, "__str__", 7LL);
ek_NoneType = (__int64)ek_type_derive((_QWORD *)ek_NoneType, "__eq__", 6LL);
ek_None = (__int64)ek_type_instanciate(ek_NoneType);
ek_IntType = (__int64)func2();
ek_FuncType = (__int64)func2();
v0 = func2();
*((_DWORD *)v0 + 6) = 8;
ek_CFuncType = (__int64)v0;
ek_StrType = (__int64)func2();
ek_StrType = (__int64)ek_type_derive((_QWORD *)ek_StrType, "__str__", 7LL);
*(_DWORD *)(ek_StrType + 24) = 16;
}
}

original_code:
void ek_init_type(){
  if (ek_NoneType == ((void *)0)){
    ek_NoneType = ek_type_new();
    ek_NoneType = ek_type_derive(ek_NoneType, "__str__", 7);
    ek_NoneType = ek_type_derive(ek_NoneType, "__eq__", 6);
    ek_None = ek_type_instanciate(ek_NoneType);
    ek_IntType = ek_type_new();
    ek_FuncType = ek_type_new();
    ek_CFuncType = ek_type_new();
    ek_CFuncType->extra_space = sizeof(void*);
    ek_StrType = ek_type_new();
    ek_StrType = ek_type_derive(ek_StrType, "__str__", 7);
    ek_StrType->extra_space = sizeof(char*) + sizeof(unsigned long);
  }
}

canonical_original_code:
void ek_init_type(){
  if (ek_NoneType == ((void *)0)){
    ek_NoneType = ek_type_new();
    ek_NoneType = ek_type_derive(ek_NoneType, "__str__", 7);
    ek_NoneType = ek_type_derive(ek_NoneType, "__eq__", 6);
    ek_None = ek_type_instanciate(ek_NoneType);
    ek_IntType = ek_type_new();
    ek_FuncType = ek_type_new();
    ek_CFuncType = ek_type_new();
    ek_CFuncType->extra_space = sizeof(void *);
    ek_StrType = ek_type_new();
    ek_StrType = ek_type_derive(ek_StrType, "__str__", 7);
    ek_StrType->extra_space = sizeof(char *) + sizeof(unsigned long);
  }
}


decompiled_code:
__int64 __fastcall ek_obj_setextra(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

result = *a1;
a1[*(_QWORD *)(*a1 + 16) + 1 + a2] = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

result = *a1;
a1[*(_QWORD *)(*a1 + 16) + 1 + a2] = a3;
return result;
}

original_code:
void ek_obj_setextra(ekop o, uint64_t pos, ekop v){
  *(((ekop*)o->data) + o->type->nentries + pos) = v;
}

canonical_original_code:
void ek_obj_setextra(struct ek_obj *o, unsigned long pos, struct ek_obj *v){
  *(((struct ek_obj **)o->data) + o->type->nentries + pos) = v;
}

variable_types: struct ek_obj { struct ek_type { char *map; unsigned long map_size; unsigned long nentries; unsigned int extra_space; struct ek_type_entry { char *str; unsigned int strlen; unsigned int index; unsigned long xhash; unsigned long yhash; struct ek_type_entry *next; } *entry; } *type; char data[]; } *

variable_types:
pos
unsigned long

variable_types:
v
struct ek_obj *

user_defined_types: struct ek_obj { struct ek_type *type; char data[]; }


decompiled_code:
__int64 __fastcall ek_obj_getextra(__int64 a1, __int64 a2)
{
return *(_QWORD *)(a1 + 8 * (*(_QWORD *)(*(_QWORD *)a1 + 16LL) + a2) + 8);
}

original_code:
ekop ek_obj_getextra(ekop o, uint64_t pos){
  return *(((ekop*)o->data) + o->type->nentries + pos);
}

canonical_original_code:
struct ek_obj *ek_obj_getextra(struct ek_obj *o, unsigned long pos){
  return *(((struct ek_obj **)o->data) + o->type->nentries + pos);
}

variable_types:
o
struct ek_obj *

return_type: struct ek_obj { struct ek_type { char *map; unsigned long map_size; unsigned long nentries; unsigned int extra_space; struct ek_type_entry { char *str; unsigned int strlen; unsigned int index; unsigned long xhash; unsigned long yhash; struct ek_type_entry *next; } *entry; } *type; char data[]; } *


decompiled_code:
__int64 __fastcall ek_obj_setattr_str(__int64 a1, char *a2, __int64 a3)
{
__int64 v4; // rax
__int64 result; // rax

v4 = strlen(a2);
result = *(char *)(**(_QWORD **)a1 + (unsigned __int64)xhash(a2, v4) % *(_QWORD *)(*(_QWORD *)a1 + 8LL));
*(_QWORD *)(a1 + 8 * result + 8) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char *a2, __int64 a3)
{
__int64 v4; // rax
__int64 result; // rax

v4 = strlen(a2);
result = *(char *)(**(_QWORD **)a1 + (unsigned __int64)func0(a2, v4) % *(_QWORD *)(*(_QWORD *)a1 + 8LL));
*(_QWORD *)(a1 + 8 * result + 8) = a3;
return result;
}

original_code:
void ek_obj_setattr_str(ekop o, char* s, ekop v){
  unsigned long hash = xhash(s, strlen(s)) % o->type->map_size;
  *((ekop*)o->data + o->type->map[hash]) = v;
}

canonical_original_code:
void ek_obj_setattr_str(struct ek_obj *o, char *s, struct ek_obj *v){
  unsigned long hash = xhash(s, strlen(s)) % o->type->map_size;
  *((struct ek_obj **)o->data + o->type->map[hash]) = v;
}

variable_types:
hash
unsigned long

user_defined_types: struct ek_type_entry { char *str; unsigned int strlen; unsigned int index; unsigned long xhash; unsigned long yhash; struct ek_type_entry *next; }


decompiled_code:
__int64 __fastcall ek_obj_getattr_strn(__int64 a1, char *a2, int a3)
{
unsigned __int64 v3; // rax
__int64 v4; // r8

v3 = xhash(a2, a3);
return *(_QWORD *)(v4 + 8LL * *(char *)(**(_QWORD **)v4 + v3 % *(_QWORD *)(*(_QWORD *)v4 + 8LL)) + 8);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2, int a3)
{
unsigned __int64 v3; // rax
__int64 v4; // r8

v3 = func0(a2, a3);
return *(_QWORD *)(v4 + 8LL * *(char *)(**(_QWORD **)v4 + v3 % *(_QWORD *)(*(_QWORD *)v4 + 8LL)) + 8);
}

original_code:
ekop ek_obj_getattr_strn(ekop o, char* s, int l){
  unsigned long hash = xhash(s, l) % o->type->map_size;
  return *((ekop*)o->data + o->type->map[hash]);
}

canonical_original_code:
struct ek_obj *ek_obj_getattr_strn(struct ek_obj *o, char *s, int l){
  unsigned long hash = xhash(s, l) % o->type->map_size;
  return *((struct ek_obj **)o->data + o->type->map[hash]);
}

variable_types: l int


decompiled_code:
void *__fastcall arraylist_remove(__int64 a1, int a2)
{
__int64 v2; // rdx
size_t v3; // r14
int v4; // er13
char *v5; // r12
void *v6; // r15

v2 = *(unsigned int *)(a1 + 12);
if ( a2 < 0 || (int)v2 < a2 )
fprintf(stderr, "your index is out of bounds. size:%d index %d\n", v2, (unsigned int)a2);
v3 = *(int *)(a1 + 8);
v4 = *(_DWORD *)(a1 + 8);
v5 = (char *)(*(_QWORD *)a1 + a2 * v4);
v6 = malloc(v3);
if ( !v6 )
{
fwrite("Ran out of memory", 1uLL, 0x11uLL, stderr);
v3 = *(int *)(a1 + 8);
v4 = *(_DWORD *)(a1 + 8);
}
memcpy(v6, v5, v3);
memmove(v5, &v5[v3], v4 * (~a2 + *(_DWORD *)(a1 + 12)));
--*(_DWORD *)(a1 + 12);
return v6;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1, int a2)
{
__int64 v2; // rdx
size_t v3; // r14
int v4; // er13
char *v5; // r12
void *v6; // r15

v2 = *(unsigned int *)(a1 + 12);
if ( a2 < 0 || (int)v2 < a2 )
fprintf(stderr, "your index is out of bounds. size:%d index %d\n", v2, (unsigned int)a2);
v3 = *(int *)(a1 + 8);
v4 = *(_DWORD *)(a1 + 8);
v5 = (char *)(*(_QWORD *)a1 + a2 * v4);
v6 = malloc(v3);
if ( !v6 )
{
fwrite("Ran out of memory", 1uLL, 0x11uLL, stderr);
v3 = *(int *)(a1 + 8);
v4 = *(_DWORD *)(a1 + 8);
}
memcpy(v6, v5, v3);
memmove(v5, &v5[v3], v4 * (~a2 + *(_DWORD *)(a1 + 12)));
--*(_DWORD *)(a1 + 12);
return v6;
}

original_code:
void* arraylist_remove(arraylist *list, int index){
 if(index>list->size||index<0)
  fprintf(stderr,"your index is out of bounds. size:%d index %d\n",list->size,index);
 void *position=list->array+index*list->element_size;
 void *element;
 if((element=malloc(list->element_size))==((void *)0)) fprintf(stderr,"Ran out of memory");
 memcpy(element,position,list->element_size);
 memmove(position,position+list->element_size,list->element_size*(list->size-index-1));
 --list->size;
 return element;
}

canonical_original_code:
void *arraylist_remove(struct arraylist *list, int index){
 if(index>list->size||index<0)
  fprintf(stderr,"your index is out of bounds. size:%d index %d\n",list->size,index);
 void *position = list->array+index*list->element_size;
 void *element;
 if((element=malloc(list->element_size))==((void *)0)) fprintf(stderr,"Ran out of memory");
 memcpy(element,position,list->element_size);
 memmove(position,position+list->element_size,list->element_size*(list->size-index-1));
 --list->size;
 return element;
}

variable_types: struct arraylist { void *array; int element_size; int size; int capacity; } *

variable_types: index int

variable_types:
position
void *

variable_types:
element
void *


decompiled_code:
void *__fastcall arraylist_removeEnd(__int64 a1)
{
return arraylist_remove(a1, *(_DWORD *)(a1 + 12) - 1);
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
return func0(a1, *(_DWORD *)(a1 + 12) - 1);
}

original_code:
void* arraylist_removeEnd(arraylist *list){
 return arraylist_remove(list,list->size-1);
}

canonical_original_code:
void *arraylist_removeEnd(struct arraylist *list){
 return arraylist_remove(list,list->size-1);
}

user_defined_types: struct arraylist { void *array; int element_size; int size; int capacity; }


decompiled_code:
__int64 __fastcall arraylist_get(__int64 a1, int a2)
{
__int64 v2; // rdx

v2 = *(unsigned int *)(a1 + 12);
if ( a2 < 0 || (int)v2 <= a2 )
fprintf(stderr, "your index is out of bounds. size:%d index %d\n", v2, (unsigned int)a2);
return *(_QWORD *)a1 + *(_DWORD *)(a1 + 8) * a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 v2; // rdx

v2 = *(unsigned int *)(a1 + 12);
if ( a2 < 0 || (int)v2 <= a2 )
fprintf(stderr, "your index is out of bounds. size:%d index %d\n", v2, (unsigned int)a2);
return *(_QWORD *)a1 + *(_DWORD *)(a1 + 8) * a2;
}

original_code:
void* arraylist_get(arraylist *list, int index){
 if(index>=list->size||index<0)
  fprintf(stderr,"your index is out of bounds. size:%d index %d\n",list->size,index);
 return list->array+index*list->element_size;
}

canonical_original_code:
void *arraylist_get(struct arraylist *list, int index){
 if(index>=list->size||index<0)
  fprintf(stderr,"your index is out of bounds. size:%d index %d\n",list->size,index);
 return list->array+index*list->element_size;
}


decompiled_code:
void *__fastcall arraylist_set(__int64 a1, int a2, const void *a3)
{
__int64 v4; // rdx
size_t v5; // r12
void *v6; // rbp
void *v7; // r15

v4 = *(unsigned int *)(a1 + 12);
if ( a2 < 0 || (int)v4 <= a2 )
fprintf(stderr, "your index is out of bounds. size:%d index %d\n", v4, (unsigned int)a2);
v5 = *(int *)(a1 + 8);
v6 = (void *)(*(_QWORD *)a1 + (int)v5 * a2);
v7 = malloc(v5);
if ( !v7 )
{
fwrite("Ran out of memory", 1uLL, 0x11uLL, stderr);
v5 = *(int *)(a1 + 8);
}
memcpy(v7, v6, v5);
memcpy(v6, a3, v5);
return v7;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, int a2, const void *a3)
{
__int64 v4; // rdx
size_t v5; // r12
void *v6; // rbp
void *v7; // r15

v4 = *(unsigned int *)(a1 + 12);
if ( a2 < 0 || (int)v4 <= a2 )
fprintf(stderr, "your index is out of bounds. size:%d index %d\n", v4, (unsigned int)a2);
v5 = *(int *)(a1 + 8);
v6 = (void *)(*(_QWORD *)a1 + (int)v5 * a2);
v7 = malloc(v5);
if ( !v7 )
{
fwrite("Ran out of memory", 1uLL, 0x11uLL, stderr);
v5 = *(int *)(a1 + 8);
}
memcpy(v7, v6, v5);
memcpy(v6, a3, v5);
return v7;
}

original_code:
void* arraylist_set(arraylist *list, int index, void* itemPtr){
 if(index>=list->size||index<0)
  fprintf(stderr,"your index is out of bounds. size:%d index %d\n",list->size,index);
 void *object;
 void *position=list->array+index*list->element_size;
 if((object=malloc(list->element_size))==((void *)0)){
  fprintf(stderr,"Ran out of memory");
 }
 memcpy(object,position,list->element_size);
 memcpy(position, itemPtr, list->element_size);
 return object;
}

canonical_original_code:
void *arraylist_set(struct arraylist *list, int index, void *itemPtr){
 if(index>=list->size||index<0)
  fprintf(stderr,"your index is out of bounds. size:%d index %d\n",list->size,index);
 void *object;
 void *position = list->array+index*list->element_size;
 if((object=malloc(list->element_size))==((void *)0)){
  fprintf(stderr,"Ran out of memory");
 }
 memcpy(object,position,list->element_size);
 memcpy(position, itemPtr, list->element_size);
 return object;
}

variable_types:
itemPtr
void *

variable_types:
object
void *


decompiled_code:
void __fastcall arraylist_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void arraylist_free(arraylist *list){
 free(list->array);
 free(list);
}

canonical_original_code:
void arraylist_free(struct arraylist *list){
 free(list->array);
 free(list);
}


decompiled_code:
__int64 __fastcall arraylist_size(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
int arraylist_size(arraylist *list){
 return list->size;
}

canonical_original_code:
int arraylist_size(struct arraylist *list){
 return list->size;
}


decompiled_code:
_BOOL8 __fastcall arraylist_isEmpty(__int64 a1)
{
return *(_DWORD *)(a1 + 12) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return *(_DWORD *)(a1 + 12) == 0;
}

original_code:
int arraylist_isEmpty(arraylist *list){
 return list->size==0;
}

canonical_original_code:
int arraylist_isEmpty(struct arraylist *list){
 return list->size==0;
}


decompiled_code:
void __fastcall arraylist_clear(__int64 a1)
{
*(_DWORD *)(a1 + 12) = 0;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
*(_DWORD *)(a1 + 12) = 0;
}

original_code:
void arraylist_clear(arraylist *list){
 list->size=0;
}

canonical_original_code:
void arraylist_clear(struct arraylist *list){
 list->size=0;
}


decompiled_code:
void __fastcall arraylist_swap(__int64 a1, int a2, int a3)
{
const void *v4; // rax
void *v5; // r12
void *v6; // rbp

v4 = (const void *)arraylist_get(a1, a3);
v5 = arraylist_set(a1, a2, v4);
v6 = arraylist_set(a1, a3, v5);
free(v5);
free(v6);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2, int a3)
{
const void *v4; // rax
void *v5; // r12
void *v6; // rbp

v4 = (const void *)func2(a1, a3);
v5 = func3(a1, a2, v4);
v6 = func3(a1, a3, v5);
free(v5);
free(v6);
}

original_code:
void arraylist_swap(arraylist *list, int firstIndex, int secondIndex){
 void* a=arraylist_set(list,firstIndex,arraylist_get(list,secondIndex));
 void* b=arraylist_set(list,secondIndex,a);
 free(a);
 free(b);
}

canonical_original_code:
void arraylist_swap(struct arraylist *list, int firstIndex, int secondIndex){
 void *a = arraylist_set(list,firstIndex,arraylist_get(list,secondIndex));
 void *b = arraylist_set(list,secondIndex,a);
 free(a);
 free(b);
}

variable_types: firstIndex int

variable_types: secondIndex int

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
void __fastcall arraylist_resize(__int64 a1)
{
int v2; // eax
int v3; // ebp
void *v4; // r12
void *v5; // rax
void *v6; // rdi

v2 = *(_DWORD *)(a1 + 16);
v3 = *(_DWORD *)(a1 + 8);
v4 = *(void **)a1;
*(_DWORD *)(a1 + 16) = 2 * v2;
v5 = malloc(v3 * 2 * v2);
*(_QWORD *)a1 = v5;
if ( v5 )
{
v6 = v5;
}
else
{
fwrite("Ran out of memory", 1uLL, 0x11uLL, stderr);
v3 = *(_DWORD *)(a1 + 8);
v6 = *(void **)a1;
}
memcpy(v6, v4, *(_DWORD *)(a1 + 12) * v3);
free(v4);
}

original_code:
void arraylist_resize(arraylist *list){
 void *sparePointer=list->array;
 list->capacity*=2;
 if((list->array=malloc(list->capacity*list->element_size))==((void *)0)){
  fprintf(stderr,"Ran out of memory");
 }
 memcpy(list->array, sparePointer, list->size*list->element_size);
 free(sparePointer);
}

canonical_original_code:
void arraylist_resize(struct arraylist *list){
 void *sparePointer = list->array;
 list->capacity*=2;
 if((list->array=malloc(list->capacity*list->element_size))==((void *)0)){
  fprintf(stderr,"Ran out of memory");
 }
 memcpy(list->array, sparePointer, list->size*list->element_size);
 free(sparePointer);
}

variable_types:
sparePointer
void *


decompiled_code:
void *__fastcall arraylist_add(__int64 a1, int a2, const void *a3)
{
__int64 v4; // rdx
int v5; // er14
char *v6; // r12
void *result; // rax

v4 = *(unsigned int *)(a1 + 12);
if ( (int)v4 < a2 || a2 < 0 )
{
fprintf(stderr, "your index is out of bounds. size:%d index %d\n", v4, (unsigned int)a2);
LODWORD(v4) = *(_DWORD *)(a1 + 12);
v5 = *(_DWORD *)(a1 + 8);
if ( *(_DWORD *)(a1 + 16) != (_DWORD)v4 )
goto LABEL_4;
LABEL_6:
arraylist_resize(a1);
LODWORD(v4) = *(_DWORD *)(a1 + 12);
goto LABEL_4;
}
v5 = *(_DWORD *)(a1 + 8);
if ( *(_DWORD *)(a1 + 16) == (_DWORD)v4 )
goto LABEL_6;
LABEL_4:
v6 = (char *)(*(_QWORD *)a1 + v5 * a2);
memmove(&v6[v5], v6, v5 * ((int)v4 - a2));
result = memcpy(v6, a3, v5);
++*(_DWORD *)(a1 + 12);
return result;
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1, int a2, const void *a3)
{
__int64 v4; // rdx
int v5; // er14
char *v6; // r12
void *result; // rax

v4 = *(unsigned int *)(a1 + 12);
if ( (int)v4 < a2 || a2 < 0 )
{
fprintf(stderr, "your index is out of bounds. size:%d index %d\n", v4, (unsigned int)a2);
LODWORD(v4) = *(_DWORD *)(a1 + 12);
v5 = *(_DWORD *)(a1 + 8);
if ( *(_DWORD *)(a1 + 16) != (_DWORD)v4 )
goto LABEL_4;
LABEL_6:
func9(a1);
LODWORD(v4) = *(_DWORD *)(a1 + 12);
goto LABEL_4;
}
v5 = *(_DWORD *)(a1 + 8);
if ( *(_DWORD *)(a1 + 16) == (_DWORD)v4 )
goto LABEL_6;
LABEL_4:
v6 = (char *)(*(_QWORD *)a1 + v5 * a2);
memmove(&v6[v5], v6, v5 * ((int)v4 - a2));
result = memcpy(v6, a3, v5);
++*(_DWORD *)(a1 + 12);
return result;
}

original_code:
void arraylist_add(arraylist *list,int index, void* itemPtr){
 if(index>list->size||index<0)
  fprintf(stderr,"your index is out of bounds. size:%d index %d\n",list->size,index);
 int elem_size=list->element_size;
 if(list->size==list->capacity){
  arraylist_resize(list);
 }
 void *position=list->array+index*elem_size;
 memmove(position+elem_size,position, elem_size*(list->size-index));
 memcpy(position, itemPtr, elem_size);
 ++list->size;
}

canonical_original_code:
void arraylist_add(struct arraylist *list, int index, void *itemPtr){
 if(index>list->size||index<0)
  fprintf(stderr,"your index is out of bounds. size:%d index %d\n",list->size,index);
 int elem_size = list->element_size;
 if(list->size==list->capacity){
  arraylist_resize(list);
 }
 void *position = list->array+index*elem_size;
 memmove(position+elem_size,position, elem_size*(list->size-index));
 memcpy(position, itemPtr, elem_size);
 ++list->size;
}


decompiled_code:
void *__fastcall arraylist_addEnd(__int64 a1, const void *a2)
{
return arraylist_add(a1, *(_DWORD *)(a1 + 12), a2);
}

canonical_decompiled_code:
void *__fastcall func11(__int64 a1, const void *a2)
{
return func10(a1, *(_DWORD *)(a1 + 12), a2);
}

original_code:
void arraylist_addEnd(arraylist *list, void* itemPtr){
 arraylist_add(list,list->size,itemPtr);
}

canonical_original_code:
void arraylist_addEnd(struct arraylist *list, void *itemPtr){
 arraylist_add(list,list->size,itemPtr);
}


decompiled_code:
int __fastcall arraylist_print(__int64 a1, void (__fastcall *a2)(__int64))
{
int v3; // ebx
int v4; // esi
__int64 v5; // rax

v3 = 0;
putchar(91);
if ( *(int *)(a1 + 12) > 0 )
{
while ( 1 )
{
v4 = v3++;
v5 = arraylist_get(a1, v4);
a2(v5);
if ( *(_DWORD *)(a1 + 12) <= v3 )
break;
putchar(44);
}
}
return puts("]");
}

original_code:
void arraylist_print(arraylist *list, void (*printelem)(void *)){
 int i;
 printf("[");
 for(i=0;i<list->size;++i){
  if(i!=0) printf(",");
  printelem(arraylist_get(list,i));
 }
 printf("]\n");
}

canonical_original_code:
void arraylist_print(struct arraylist *list, void (*printelem)(void *)){
 int i;
 printf("[");
 for(i=0;i<list->size;++i){
  if(i!=0) printf(",");
  printelem(arraylist_get(list,i));
 }
 printf("]\n");
}

variable_types:
printelem
void (*)(void *)

variable_types: i int


decompiled_code:
int __fastcall arraylist_printInt(unsigned int *a1)
{
return printf("%d", *a1);
}

canonical_decompiled_code:
int __fastcall func13(unsigned int *a1)
{
return printf("%d", *a1);
}

original_code:
void arraylist_printInt(void* i){
 int j=*((int*)i);
 printf("%d",j);
}

canonical_original_code:
void arraylist_printInt(void *i){
 int j = *((int*)i);
 printf("%d",j);
}

variable_types:
i
void *

variable_types: j int


repo: benkasminbullock/cfunctions

decompiled_code:
void *__fastcall malloc_or_exit(size_t a1, int a2)
{
void *result; // rax
const char *v3; // rdx

result = malloc(a1);
if ( result )
{
++n_mallocs;
}
else
{
error((int)"out of memory", a2, v3);
result = (void *)calloc_or_exit();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1, int a2)
{
void *result; // rax
const char *v3; // rdx

result = malloc(a1);
if ( result )
{
++n_mallocs;
}
else
{
error((int)"out of memory", a2, v3);
result = (void *)func1();
}
return result;
}

original_code:
void *
malloc_or_exit (size_t s)
{
    void * v;
    v = malloc (s);
    if (! v) {
 error ("out of memory");
    }
    n_mallocs++;
    return v;
}

canonical_original_code:
void *malloc_or_exit(unsigned long s)
{
    void *v;
    v = malloc (s);
    if (! v) {
 error ("out of memory");
    }
    n_mallocs++;
    return v;
}

variable_types:
s
unsigned long

variable_types:
v
void *


decompiled_code:
void *__fastcall calloc_or_exit(size_t a1, size_t a2)
{
void *result; // rax
const char *v3; // rdx

result = calloc(a1, a2);
if ( result )
{
++n_mallocs;
}
else
{
error((int)"out of memory", a2, v3);
result = (void *)realloc_or_exit();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1, size_t a2)
{
void *result; // rax
const char *v3; // rdx

result = calloc(a1, a2);
if ( result )
{
++n_mallocs;
}
else
{
error((int)"out of memory", a2, v3);
result = (void *)func2();
}
return result;
}

original_code:
void *
calloc_or_exit (size_t s, size_t size)
{
    void * v;
    v = calloc (s, size);
    if (! v) {
 error ("out of memory");
    }
    n_mallocs++;
    return v;
}

canonical_original_code:
void *calloc_or_exit(unsigned long s, unsigned long size)
{
    void *v;
    v = calloc (s, size);
    if (! v) {
 error ("out of memory");
    }
    n_mallocs++;
    return v;
}

variable_types:
size
unsigned long


decompiled_code:
void *__fastcall realloc_or_exit(void *a1, size_t a2)
{
void *result; // rax
const char *v3; // rdx

if ( !a1 )
++n_mallocs;
result = realloc(a1, a2);
if ( !result )
{
error((int)"out of memory", a2, v3);
result = (void *)fseek_or_exit();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *result; // rax
const char *v3; // rdx

if ( !a1 )
++n_mallocs;
result = realloc(a1, a2);
if ( !result )
{
error((int)"out of memory", a2, v3);
result = (void *)func3();
}
return result;
}

original_code:
void *
realloc_or_exit (void * v, size_t s)
{
    if (! v) {
 n_mallocs++;
    }
    v = realloc (v, s);
    if (! v) {
 error ("out of memory");
    }
    return v;
}

canonical_original_code:
void *realloc_or_exit(void *v, unsigned long s)
{
    if (! v) {
 n_mallocs++;
    }
    v = realloc (v, s);
    if (! v) {
 error ("out of memory");
    }
    return v;
}


decompiled_code:
int __fastcall stat_or_exit(const char *errnum, struct stat *a2)
{
int result; // eax
int *v3; // rax
char *v4; // rax

result = stat(errnum, a2);
if ( result == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
error((int)"stat failed on %s: %s", (int)errnum, v4);
result = fclose_or_exit();
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(const char *errnum, struct stat *a2)
{
int result; // eax
int *v3; // rax
char *v4; // rax

result = stat(errnum, a2);
if ( result == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
error((int)"stat failed on %s: %s", (int)errnum, v4);
result = func7();
}
return result;
}

original_code:
void
stat_or_exit (const char * file_name, struct stat * buf)
{
    if (stat (file_name, buf) == -1) {
 error ("stat failed on %s: %s", file_name, strerror ((*__errno_location ())));
    }
}

canonical_original_code:
void stat_or_exit(char *file_name, struct stat *buf)
{
    if (stat (file_name, buf) == -1) {
 error ("stat failed on %s: %s", file_name, strerror ((*__errno_location ())));
    }
}

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]; } *

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


decompiled_code:
__int64 __fastcall free_or_exit(void *a1)
{
__int64 result; // rax

if ( a1 )
{
free(a1);
--n_mallocs;
result = 0LL;
}
else
{
fprintf(stderr, "%s:%d: Attempt to free null pointer.\n", "sys-or-exit.c", 132LL);
result = 1LL;
}
return result;
}

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

if ( a1 )
{
free(a1);
--n_mallocs;
result = 0LL;
}
else
{
fprintf(stderr, "%s:%d: Attempt to free null pointer.\n", "sys-or-exit.c", 132LL);
result = 1LL;
}
return result;
}

original_code:
or_exit_t
free_or_exit (void * memory)
{
    if (! memory) {
 fprintf (stderr, "%s:%d: Attempt to free null pointer.\n",
   "sys-or-exit.c", 132);
 return or_exit_null_pointer;
    }
    free (memory);
    n_mallocs--;
    return or_exit_ok;
}

canonical_original_code:
enum or_exit_t free_or_exit(void *memory)
{
    if (! memory) {
 fprintf (stderr, "%s:%d: Attempt to free null pointer.\n",
   "sys-or-exit.c", 132);
 return or_exit_null_pointer;
    }
    free (memory);
    n_mallocs--;
    return or_exit_ok;
}

variable_types:
memory
void *

return_type: enum or_exit_t { or_exit_ok=0, or_exit_null_pointer=1 }


decompiled_code:
char *__fastcall strdup_or_exit(const char *a1)
{
char *result; // rax
int *v2; // rax
char *v3; // rsi
const char *v4; // rdx

result = strdup(a1);
if ( result )
{
++n_mallocs;
}
else
{
v2 = _errno_location();
v3 = strerror(*v2);
error((int)"strdup failed: %s", (int)v3, v4);
result = (char *)chmod_or_exit((int)"strdup failed: %s", v3);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func9(const char *a1)
{
char *result; // rax
int *v2; // rax
char *v3; // rsi
const char *v4; // rdx

result = strdup(a1);
if ( result )
{
++n_mallocs;
}
else
{
v2 = _errno_location();
v3 = strerror(*v2);
error((int)"strdup failed: %s", (int)v3, v4);
result = (char *)func10((int)"strdup failed: %s", v3);
}
return result;
}

original_code:
char *
strdup_or_exit (const char * todup)
{
    char * dupped;
    dupped = strdup (todup);
    if (! dupped) {
 error ("strdup failed: %s", strerror ((*__errno_location ())));
    }
    n_mallocs++;
    return dupped;
}

canonical_original_code:
char *strdup_or_exit(char *todup)
{
    char *dupped;
    dupped = strdup (todup);
    if (! dupped) {
 error ("strdup failed: %s", strerror ((*__errno_location ())));
    }
    n_mallocs++;
    return dupped;
}

variable_types:
todup
char *

variable_types:
dupped
char *

return_type: char *


decompiled_code:
int __fastcall chmod_or_exit(const char *errnum, char *format)
{
int result; // eax
int *v3; // rax
char *v4; // rax

result = chmod(errnum, (__mode_t)format);
if ( result )
{
v3 = _errno_location();
v4 = strerror(*v3);
error((int)"Could not chmod (%s, %o): %s", (int)errnum, (const char *)(unsigned int)format, v4);
result = unlink_or_exit((int)"Could not chmod (%s, %o): %s");
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(const char *errnum, char *format)
{
int result; // eax
int *v3; // rax
char *v4; // rax

result = chmod(errnum, (__mode_t)format);
if ( result )
{
v3 = _errno_location();
v4 = strerror(*v3);
error((int)"Could not chmod (%s, %o): %s", (int)errnum, (const char *)(unsigned int)format, v4);
result = func11((int)"Could not chmod (%s, %o): %s");
}
return result;
}

original_code:
void
chmod_or_exit (const char * path, mode_t mode)
{
    int status;
    status = chmod (path, mode);
    if (status) {
 error ("Could not chmod (%s, %o): %s", path, mode, strerror ((*__errno_location ())));
    }
}

canonical_original_code:
void chmod_or_exit(char *path, unsigned int mode)
{
    int status;
    status = chmod (path, mode);
    if (status) {
 error ("Could not chmod (%s, %o): %s", path, mode, strerror ((*__errno_location ())));
    }
}

variable_types:
path
char *

variable_types:
mode
unsigned int

variable_types: status int


decompiled_code:
int __fastcall unlink_or_exit(const char *errnum)
{
int result; // eax
int *v2; // rax
char *v3; // rax

result = unlink(errnum);
if ( result )
{
v2 = _errno_location();
v3 = strerror(*v2);
error((int)"Could not unlink (%s): %s", (int)errnum, v3);
result = memory_check();
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(const char *errnum)
{
int result; // eax
int *v2; // rax
char *v3; // rax

result = unlink(errnum);
if ( result )
{
v2 = _errno_location();
v3 = strerror(*v2);
error((int)"Could not unlink (%s): %s", (int)errnum, v3);
result = func12();
}
return result;
}

original_code:
void
unlink_or_exit (const char * path)
{
    int status;
    status = unlink (path);
    if (status) {
 error ("Could not unlink (%s): %s", path, strerror ((*__errno_location ())));
    }
}

canonical_original_code:
void unlink_or_exit(char *path)
{
    int status;
    status = unlink (path);
    if (status) {
 error ("Could not unlink (%s): %s", path, strerror ((*__errno_location ())));
    }
}


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

if ( n_mallocs )
result = fprintf(stderr, "%s:%d: n_mallocs = %d\n", "sys-or-exit.c", 179LL, (unsigned int)n_mallocs);
return result;
}

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

if ( n_mallocs )
result = fprintf(stderr, "%s:%d: n_mallocs = %d\n", "sys-or-exit.c", 179LL, (unsigned int)n_mallocs);
return result;
}

original_code:
void
memory_check ()
{
    if (n_mallocs != 0) {
 fprintf (stderr, "%s:%d: n_mallocs = %d\n",
   "sys-or-exit.c", 179, n_mallocs);
    }
}

canonical_original_code:
void memory_check()
{
    if (n_mallocs != 0) {
 fprintf (stderr, "%s:%d: n_mallocs = %d\n",
   "sys-or-exit.c", 179, n_mallocs);
    }
}


dirname

decompiled_code:
char *__fastcall dirname(char *src)
{
char *v1; // rbp
char *v2; // rax
size_t v3; // rbx
char *v4; // rax
char *result; // rax

v1 = src;
v2 = strrchr(src, 47);
if ( v2 )
{
if ( src < v2 )
{
do
{
if ( *v2 != 47 )
break;
--v2;
}
while ( src != v2 );
}
v3 = (int)v2 - (int)src + 1;
}
else
{
v3 = 1LL;
v1 = (char *)&unk_414;
}
v4 = (char *)malloc_or_exit();
++backup_n_mallocs;
result = strncpy(v4, v1, v3);
result[v3] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
char *v1; // rbp
char *v2; // rax
size_t v3; // rbx
char *v4; // rax
char *result; // rax

v1 = src;
v2 = strrchr(src, 47);
if ( v2 )
{
if ( src < v2 )
{
do
{
if ( *v2 != 47 )
break;
--v2;
}
while ( src != v2 );
}
v3 = (int)v2 - (int)src + 1;
}
else
{
v3 = 1LL;
v1 = (char *)&unk_414;
}
v4 = (char *)malloc_or_exit();
++backup_n_mallocs;
result = strncpy(v4, v1, v3);
result[v3] = 0;
return result;
}

original_code:
static char *
dirname (const char * path)
{
    char *newpath;
    char *slash;
    int length;
    slash = strrchr (path, '/');
    if (slash == 0) {
 path = ".";
 length = 1;
    }
    else {
 while (slash > path && *slash == '/') {
     slash--;
 }
 length = slash - path + 1;
    }
    newpath = malloc_or_exit (length + 1);
    backup_n_mallocs++;
    strncpy (newpath, path, length);
    newpath[length] = 0;
    return newpath;
}

canonical_original_code:
static char *dirname(char *path)
{
    char *newpath;
    char *slash;
    int length;
    slash = strrchr (path, '/');
    if (slash == 0) {
 path = ".";
 length = 1;
    }
    else {
 while (slash > path && *slash == '/') {
     slash--;
 }
 length = slash - path + 1;
    }
    newpath = malloc_or_exit (length + 1);
    backup_n_mallocs++;
    strncpy (newpath, path, length);
    newpath[length] = 0;
    return newpath;
}

variable_types:
newpath
char *

variable_types:
slash
char *

variable_types: length int


decompiled_code:
__int64 __fastcall version_number(const char *a1, const char *a2, int a3)
{
unsigned int v3; // er12
__int64 v4; // rbp
const unsigned __int16 **v5; // rax
const char *v6; // rdx
const unsigned __int16 *v7; // rdi
__int64 v8; // rax
unsigned int v9; // ecx

v3 = 0;
v4 = a3;
if ( !strncmp(a1, a2, a3) )
{
v3 = 0;
v5 = _ctype_b_loc();
v6 = &a2[v4];
v7 = *v5;
v8 = a2[v4];
if ( (v7[v8] & 0x800) != 0 )
{
v9 = 0;
do
{
++v6;
v9 = v8 + 10 * v9 - 48;
LODWORD(v8) = *v6;
}
while ( (v7[*v6] & 0x800) != 0 );
if ( (_BYTE)v8 == 126 && !v6[1] )
v3 = v9;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2, int a3)
{
unsigned int v3; // er12
__int64 v4; // rbp
const unsigned __int16 **v5; // rax
const char *v6; // rdx
const unsigned __int16 *v7; // rdi
__int64 v8; // rax
unsigned int v9; // ecx

v3 = 0;
v4 = a3;
if ( !strncmp(a1, a2, a3) )
{
v3 = 0;
v5 = _ctype_b_loc();
v6 = &a2[v4];
v7 = *v5;
v8 = a2[v4];
if ( (v7[v8] & 0x800) != 0 )
{
v9 = 0;
do
{
++v6;
v9 = v8 + 10 * v9 - 48;
LODWORD(v8) = *v6;
}
while ( (v7[*v6] & 0x800) != 0 );
if ( (_BYTE)v8 == 126 && !v6[1] )
v3 = v9;
}
}
return v3;
}

original_code:
static int
version_number (const char * base, const char * backup, int base_length)
{
    int version;
    const char *p;
    version = 0;
    if (!strncmp (base, backup, base_length) && ((*__ctype_b_loc ())[(int) ((backup[base_length]))] & (unsigned short int) _ISdigit)) {
 for (p = &backup[base_length]; ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit); p++) {
     version = version * 10 + *p - '0';
 }
 if (p[0] != '~' || p[1]) {
     version = 0;
 }
    }
    return version;
}

canonical_original_code:
static int version_number(char *base, char *backup, int base_length)
{
    int version;
    char *p;
    version = 0;
    if (!strncmp (base, backup, base_length) && ((*__ctype_b_loc ())[(int) ((backup[base_length]))] & (unsigned short) _ISdigit)) {
 for (p = &backup[base_length]; ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit); p++) {
     version = version * 10 + *p - '0';
 }
 if (p[0] != '~' || p[1]) {
     version = 0;
 }
    }
    return version;
}

variable_types:
base
char *

variable_types:
backup
char *

variable_types: version int

variable_types:
p
char *


decompiled_code:
char *__fastcall make_version_name(const char *a1, unsigned int a2)
{
size_t v2; // rbp
char *v3; // r12

v2 = (int)(strlen(a1) + 16);
v3 = (char *)malloc_or_exit(v2);
++backup_n_mallocs;
snprintf(v3, v2, "%s.~%d~", a1, a2);
return v3;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1, unsigned int a2)
{
size_t v2; // rbp
char *v3; // r12

v2 = (int)(strlen(a1) + 16);
v3 = (char *)malloc_or_exit(v2);
++backup_n_mallocs;
snprintf(v3, v2, "%s.~%d~", a1, a2);
return v3;
}

original_code:
static char *
make_version_name (const char * file, int version)
{
    char * backup_name;
    int maxlen;
    maxlen = strlen (file) + 16;
    backup_name = malloc_or_exit (maxlen);
    backup_n_mallocs++;
    snprintf (backup_name, maxlen, "%s.~%d~", file, version);
    return backup_name;
}

canonical_original_code:
static char *make_version_name(char *file, int version)
{
    char *backup_name;
    int maxlen;
    maxlen = strlen (file) + 16;
    backup_name = malloc_or_exit (maxlen);
    backup_n_mallocs++;
    snprintf (backup_name, maxlen, "%s.~%d~", file, version);
    return backup_name;
}

variable_types:
file
char *

variable_types: maxlen int


decompiled_code:
char *__fastcall find_backup_file_name(char *src)
{
char *v1; // rax
char *v2; // r13
char *v3; // rax
char *v4; // r12
int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // eax
__int64 v9; // r9
const char *v10; // r8
__int64 v11; // rcx

v1 = basename(src);
v2 = concat_constprop_0(v1);
v3 = dirname(src);
if ( !v3 )
{
fprintf(stderr, "%s:%d: failed to make dirname.\n", "backup.c", 164LL);
exit(1);
}
v4 = v3;
v5 = max_backup_version(v2, v3);
v6 = free_or_exit(v2);
if ( v6 )
{
v9 = v6;
v10 = "free_or_exit (base_versions)";
v11 = 169LL;
LABEL_7:
fprintf(stderr, "%s:%d: %s failed with status %d\n", "backup.c", v11, v10, v9);
exit(1);
}
--backup_n_mallocs;
v7 = free_or_exit(v4);
if ( v7 )
{
v9 = v7;
v10 = "free_or_exit (dir)";
v11 = 171LL;
goto LABEL_7;
}
--backup_n_mallocs;
return make_version_name(src, v5 + 1);
}

canonical_decompiled_code:
char *__fastcall func5(char *src)
{
char *v1; // rax
char *v2; // r13
char *v3; // rax
char *v4; // r12
int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // eax
__int64 v9; // r9
const char *v10; // r8
__int64 v11; // rcx

v1 = basename(src);
v2 = func4(v1);
v3 = func0(src);
if ( !v3 )
{
fprintf(stderr, "%s:%d: failed to make dirname.\n", "backup.c", 164LL);
exit(1);
}
v4 = v3;
v5 = func2(v2, v3);
v6 = free_or_exit(v2);
if ( v6 )
{
v9 = v6;
v10 = "free_or_exit (base_versions)";
v11 = 169LL;
LABEL_7:
fprintf(stderr, "%s:%d: %s failed with status %d\n", "backup.c", v11, v10, v9);
exit(1);
}
--backup_n_mallocs;
v7 = free_or_exit(v4);
if ( v7 )
{
v9 = v7;
v10 = "free_or_exit (dir)";
v11 = 171LL;
goto LABEL_7;
}
--backup_n_mallocs;
return func3(src, v5 + 1);
}

original_code:
char *
find_backup_file_name (char *file)
{
    char *dir;
    char *base_versions;
    int highest_backup;
    base_versions = concat (basename (file), ".~");
    dir = dirname (file);
    if (dir == 0) {
 fprintf (stderr, "%s:%d: failed to make dirname.\n",
   "backup.c", 164);
 exit (1);
    }
    highest_backup = max_backup_version (base_versions, dir);
    { or_exit_t status = free_or_exit (base_versions); if (status != or_exit_ok) { fprintf (stderr, "%s:%d: %s failed with status %d\n", "backup.c", 169, "free_or_exit (base_versions)", status); exit (1); } };
    backup_n_mallocs--;
    { or_exit_t status = free_or_exit (dir); if (status != or_exit_ok) { fprintf (stderr, "%s:%d: %s failed with status %d\n", "backup.c", 171, "free_or_exit (dir)", status); exit (1); } };
    backup_n_mallocs--;
    return make_version_name (file, highest_backup + 1);
}

canonical_original_code:
char *find_backup_file_name(char *file)
{
    char *dir;
    char *base_versions;
    int highest_backup;
    base_versions = concat (basename (file), ".~");
    dir = dirname (file);
    if (dir == 0) {
 fprintf (stderr, "%s:%d: failed to make dirname.\n",
   "backup.c", 164);
 exit (1);
    }
    highest_backup = max_backup_version (base_versions, dir);
    { enum or_exit_t status = free_or_exit (base_versions); if (status != or_exit_ok) { fprintf (stderr, "%s:%d: %s failed with status %d\n", "backup.c", 169, "free_or_exit (base_versions)", status); exit (1); } };
    backup_n_mallocs--;
    { enum or_exit_t status = free_or_exit (dir); if (status != or_exit_ok) { fprintf (stderr, "%s:%d: %s failed with status %d\n", "backup.c", 171, "free_or_exit (dir)", status); exit (1); } };
    backup_n_mallocs--;
    return make_version_name (file, highest_backup + 1);
}

variable_types:
dir
char *

variable_types: enum or_exit_t { or_exit_ok=0, or_exit_null_pointer=1 }


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

result = free_or_exit(a1);
if ( (_DWORD)result )
{
fprintf(
stderr,
"%s:%d: %s failed with status %d\n",
"backup.c",
181LL,
"free_or_exit (backup_name)",
(unsigned int)result);
exit(1);
}
--backup_n_mallocs;
return result;
}

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

result = free_or_exit(a1);
if ( (_DWORD)result )
{
fprintf(
stderr,
"%s:%d: %s failed with status %d\n",
"backup.c",
181LL,
"free_or_exit (backup_name)",
(unsigned int)result);
exit(1);
}
--backup_n_mallocs;
return result;
}

original_code:
void
free_backup_name (char * backup_name)
{
    { or_exit_t status = free_or_exit (backup_name); if (status != or_exit_ok) { fprintf (stderr, "%s:%d: %s failed with status %d\n", "backup.c", 181, "free_or_exit (backup_name)", status); exit (1); } };
    backup_n_mallocs--;
}

canonical_original_code:
void free_backup_name(char *backup_name)
{
    { enum or_exit_t status = free_or_exit (backup_name); if (status != or_exit_ok) { fprintf (stderr, "%s:%d: %s failed with status %d\n", "backup.c", 181, "free_or_exit (backup_name)", status); exit (1); } };
    backup_n_mallocs--;
}

user_defined_types: enum or_exit_t { or_exit_ok=0, or_exit_null_pointer=1 }


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

if ( backup_n_mallocs )
result = fprintf(stderr, "%s:%d: backup_n_mallocs = %d.\n", "backup.c", 192LL, (unsigned int)backup_n_mallocs);
return result;
}

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

if ( backup_n_mallocs )
result = fprintf(stderr, "%s:%d: backup_n_mallocs = %d.\n", "backup.c", 192LL, (unsigned int)backup_n_mallocs);
return result;
}

original_code:
void
backup_memory_check ()
{
    if (backup_n_mallocs != 0) {
 fprintf (stderr, "%s:%d: backup_n_mallocs = %d.\n",
   "backup.c", 192, backup_n_mallocs);
    }
}

canonical_original_code:
void backup_memory_check()
{
    if (backup_n_mallocs != 0) {
 fprintf (stderr, "%s:%d: backup_n_mallocs = %d.\n",
   "backup.c", 192, backup_n_mallocs);
    }
}


lwarning

decompiled_code:
size_t lwarning(unsigned int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
fprintf(stderr, "%s:%u: warning: ", "SOURCE NAME UNDEFINED", a1);
vfprintf(stderr, a2, arg);
return fwrite(".\n", 1uLL, 2uLL, stderr);
}

canonical_decompiled_code:
size_t func0(unsigned int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
fprintf(stderr, "%s:%u: warning: ", "SOURCE NAME UNDEFINED", a1);
vfprintf(stderr, a2, arg);
return fwrite(".\n", 1uLL, 2uLL, stderr);
}

original_code:
void
    lwarning (unsigned line_number, const char * format, ...)
{
    va_list a;
    fprintf (stderr, "%s:%u: warning: ", source_name, line_number);
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
}

canonical_original_code:
void lwarning(unsigned int line_number, char *format, ...)
{
    __builtin_va_list a;
    fprintf (stderr, "%s:%u: warning: ", source_name, line_number);
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
}

variable_types:
format
char *


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

va_start(arg, a1);
fprintf(stderr, "%s:%u: error: ", "SOURCE NAME UNDEFINED", *(unsigned int *)source_line);
vfprintf(stderr, a1, arg);
fwrite(".\n", 1uLL, 2uLL, stderr);
exit(1);
}

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

va_start(arg, a1);
fprintf(stderr, "%s:%u: error: ", "SOURCE NAME UNDEFINED", *(unsigned int *)source_line);
vfprintf(stderr, a1, arg);
fwrite(".\n", 1uLL, 2uLL, stderr);
exit(1);
}

original_code:
void
line_error (const char * format, ... )
{
    va_list a;
    fprintf (stderr, "%s:%u: error: ", source_name, * source_line);
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
    exit (1);
}

canonical_original_code:
void line_error(char *format, ...)
{
    __builtin_va_list a;
    fprintf (stderr, "%s:%u: error: ", source_name, * source_line);
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
    exit (1);
}


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

va_start(arg, format);
fprintf(stderr, "%s:%u: warning: ", "SOURCE NAME UNDEFINED", *(unsigned int *)source_line);
vfprintf(stderr, format, arg);
return fwrite(".\n", 1uLL, 2uLL, stderr);
}

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

va_start(arg, format);
fprintf(stderr, "%s:%u: warning: ", "SOURCE NAME UNDEFINED", *(unsigned int *)source_line);
vfprintf(stderr, format, arg);
return fwrite(".\n", 1uLL, 2uLL, stderr);
}

original_code:
void
    line_warning (const char * format, ... )
{
    va_list a;
    fprintf (stderr, "%s:%u: warning: ", source_name, * source_line);
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
}

canonical_original_code:
void line_warning(char *format, ...)
{
    __builtin_va_list a;
    fprintf (stderr, "%s:%u: warning: ", source_name, * source_line);
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
}


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

va_start(arg, format);
fprintf(stdout, "%s:%u: ", "SOURCE NAME UNDEFINED", *(unsigned int *)source_line);
vfprintf(stdout, format, arg);
return fwrite(".\n", 1uLL, 2uLL, stdout);
}

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

va_start(arg, format);
fprintf(stdout, "%s:%u: ", "SOURCE NAME UNDEFINED", *(unsigned int *)source_line);
vfprintf(stdout, format, arg);
return fwrite(".\n", 1uLL, 2uLL, stdout);
}

original_code:
void
line_info (const char * format, ... )
{
    va_list a;
    fprintf (stdout, "%s:%u: ", source_name, * source_line);
    __builtin_va_start(a,format); vfprintf (stdout, format, a); fprintf (stdout, ".\n"); __builtin_va_end(a);
}

canonical_original_code:
void line_info(char *format, ...)
{
    __builtin_va_list a;
    fprintf (stdout, "%s:%u: ", source_name, * source_line);
    __builtin_va_start(a,format); vfprintf (stdout, format, a); fprintf (stdout, ".\n"); __builtin_va_end(a);
}


error

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

va_start(arg, format);
fprintf(stderr, "%s: error: ", program_name);
vfprintf(stderr, format, arg);
fwrite(".\n", 1uLL, 2uLL, stderr);
exit(1);
}

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

va_start(arg, format);
fprintf(stderr, "%s: error: ", program_name);
vfprintf(stderr, format, arg);
fwrite(".\n", 1uLL, 2uLL, stderr);
exit(1);
}

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

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


warning

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

va_start(arg, format);
fprintf(stderr, "%s: warning: ", program_name);
vfprintf(stderr, format, arg);
return fwrite(".\n", 1uLL, 2uLL, stderr);
}

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

va_start(arg, format);
fprintf(stderr, "%s: warning: ", program_name);
vfprintf(stderr, format, arg);
return fwrite(".\n", 1uLL, 2uLL, stderr);
}

original_code:
void
warning (const char * format, ... )
{
    va_list a;
    fprintf ( stderr, "%s: warning: ", program_name );
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
}

canonical_original_code:
void warning(char *format, ...)
{
    __builtin_va_list a;
    fprintf ( stderr, "%s: warning: ", program_name );
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
}


bug

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

va_start(arg, a3);
fprintf(stderr, "%s:%s:%u: internal error: ", program_name, a1, a2);
fprintf(stderr, "%s:%s:%u: internal error: ", program_name, a1, a2);
vfprintf(stderr, a3, arg);
fwrite(".\n", 1uLL, 2uLL, stderr);
exit(1);
}

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

va_start(arg, a3);
fprintf(stderr, "%s:%s:%u: internal error: ", program_name, a1, a2);
fprintf(stderr, "%s:%s:%u: internal error: ", program_name, a1, a2);
vfprintf(stderr, a3, arg);
fwrite(".\n", 1uLL, 2uLL, stderr);
exit(1);
}

original_code:
void
bug (const char * file, unsigned line, const char * format, ... )
{
    va_list a;
    fprintf ( stderr, "%s:%s:%u: internal error: ",
       program_name, file, line );
    fprintf ( stderr, "%s:%s:%u: internal error: ",
       program_name, file, line );
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
    exit (1);
}

canonical_original_code:
void bug(char *file, unsigned int line, char *format, ...)
{
    __builtin_va_list a;
    fprintf ( stderr, "%s:%s:%u: internal error: ",
       program_name, file, line );
    fprintf ( stderr, "%s:%s:%u: internal error: ",
       program_name, file, line );
    __builtin_va_start(a,format); vfprintf (stderr, format, a); fprintf (stderr, ".\n"); __builtin_va_end(a);
    exit (1);
}

variable_types:
line
unsigned int


decompiled_code:
void __fastcall set_program_name(char *a1)
{
program_name = a1;
}

canonical_decompiled_code:
void __fastcall func7(char *a1)
{
program_name = a1;
}

original_code:
void
set_program_name (const char * name)
{
    program_name = name;
}

canonical_original_code:
void set_program_name(char *name)
{
    program_name = name;
}

variable_types:
name
char *


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

result = *a1;
if ( *a1 )
{
*(_QWORD *)(result + 8) = a2;
result = *a1;
*(_QWORD *)(a2 + 16) = *a1;
}
*a1 = a2;
return result;
}

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

result = *a1;
if ( *a1 )
{
*(_QWORD *)(result + 8) = a2;
result = *a1;
*(_QWORD *)(a2 + 16) = *a1;
}
*a1 = a2;
return result;
}

original_code:
static void
type_list_add (struct type ** a, struct type * b)
{
    if (* a) {
        (* a)->next = b;
        b->prev = * a;
    }
    * a = b;
}

canonical_original_code:
static void type_list_add(struct type **a, struct type *b)
{
    if (* a) {
        (* a)->next = b;
        b->prev = * a;
    }
    * a = b;
}

variable_types: struct type { unsigned char *name; struct type *next; struct type *prev; } **

variable_types:
b
struct type *


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

result = calloc_or_exit(1LL, 88LL);
++arg_n_mallocs;
return result;
}

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

result = calloc_or_exit(1LL, 88LL);
++arg_n_mallocs;
return result;
}

original_code:
static struct arg *
new_arg ()
{
    struct arg * value;
    value = calloc_or_exit (1, sizeof (* value));
    arg_n_mallocs++;
    return value;
}

canonical_original_code:
static struct arg *new_arg()
{
    struct arg *value;
    value = calloc_or_exit (1, sizeof (* value));
    arg_n_mallocs++;
    return value;
}

variable_types: struct arg { enum { TYPE=0, POINTER=1, SUFFIX=2, CPP_MUDDLE=3 } parse_state; struct type { unsigned char *name; struct type *next; struct type *prev; } *name; struct shared_type { struct type *t; int ref_count; } *types; struct type *pointers; struct type *suffixes; unsigned int line; struct arg *prev; struct arg *next; char *function_pointer; char *function_pointer_arguments; unsigned int is_typedef; unsigned int is_function_pointer; } *

user_defined_types: struct arg { enum { TYPE=0, POINTER=1, SUFFIX=2, CPP_MUDDLE=3 } parse_state; struct type *name; struct shared_type *types; struct type *pointers; struct type *suffixes; unsigned int line; struct arg *prev; struct arg *next; char *function_pointer; char *function_pointer_arguments; unsigned int is_typedef; unsigned int is_function_pointer; }


decompiled_code:
char *__fastcall check_cpp_muddle(_DWORD *a1, const char *a2)
{
char *result; // rax

result = strchr(a2, 64);
if ( result )
{
*a1 = 3;
result = (char *)line_warning("cfunctions was unable to adequately cope with some complex C preprocessor instructions");
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(_DWORD *a1, const char *a2)
{
char *result; // rax

result = strchr(a2, 64);
if ( result )
{
*a1 = 3;
result = (char *)line_warning("cfunctions was unable to adequately cope with some complex C preprocessor instructions");
}
return result;
}

original_code:
static void
check_cpp_muddle (struct arg * a, const char * t)
{
    char * at;
    at = strchr (t, '@');
    if (at) {
 a->parse_state = CPP_MUDDLE;
 line_warning ("cfunctions was unable to adequately cope with "
        "some complex C preprocessor instructions");
    }
}

canonical_original_code:
static void check_cpp_muddle(struct arg *a, char *t)
{
    char *at;
    at = strchr (t, '@');
    if (at) {
 a->parse_state = CPP_MUDDLE;
 line_warning ("cfunctions was unable to adequately cope with "
        "some complex C preprocessor instructions");
    }
}

variable_types:
t
char *

variable_types:
at
char *

user_defined_types: struct type { unsigned char *name; struct type *next; struct type *prev; }

user_defined_types: struct shared_type { struct type *t; int ref_count; }


decompiled_code:
__int64 __fastcall type_free(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
__int64 result; // rax

if ( a1 )
{
do
{
v1 = a1;
a1 = (_QWORD *)a1[2];
}
while ( a1 );
do
{
v2 = v1;
v1 = (_QWORD *)v1[1];
free_or_exit(*v2);
*v2 = 0LL;
--arg_n_mallocs;
result = free_or_exit(v2);
--arg_n_mallocs;
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
__int64 result; // rax

if ( a1 )
{
do
{
v1 = a1;
a1 = (_QWORD *)a1[2];
}
while ( a1 );
do
{
v2 = v1;
v1 = (_QWORD *)v1[1];
free_or_exit(*v2);
*v2 = 0LL;
--arg_n_mallocs;
result = free_or_exit(v2);
--arg_n_mallocs;
}
while ( v1 );
}
return result;
}

original_code:
static void
type_free (struct type * t)
{
    if (! t) {
 return;
    }
    while (t->prev) {
 t = t->prev;
    }
    while (t) {
 struct type * prev;
 prev = t;
 t = prev->next;
 free_or_exit (prev->name);
 prev->name = 0;
 arg_n_mallocs--;
 free_or_exit (prev);
 prev = 0;
 arg_n_mallocs--;
    }
}

canonical_original_code:
static void type_free(struct type *t)
{
    if (! t) {
 return;
    }
    while (t->prev) {
 t = t->prev;
    }
    while (t) {
 struct type *prev;
 prev = t;
 t = prev->next;
 free_or_exit (prev->name);
 prev->name = 0;
 arg_n_mallocs--;
 free_or_exit (prev);
 prev = 0;
 arg_n_mallocs--;
    }
}

variable_types: struct type { unsigned char *name; struct type *next; struct type *prev; } *


decompiled_code:
__int64 arg_start()
{
__int64 v0; // r12
__int64 v1; // rax

v0 = new_arg();
v1 = calloc_or_exit(1LL, 16LL);
++arg_n_mallocs;
*(_QWORD *)(v0 + 16) = v1;
*(_DWORD *)(v1 + 8) = 1;
return v0;
}

original_code:
struct arg *
arg_start ()
{
    struct arg * a;
    a = new_arg ();
    a->types = calloc_or_exit (1, sizeof (* a->types));
    arg_n_mallocs++;
    a->types->ref_count = 1;
    return a;
}

canonical_original_code:
struct arg *arg_start()
{
    struct arg *a;
    a = new_arg ();
    a->types = calloc_or_exit (1, sizeof (* a->types));
    arg_n_mallocs++;
    a->types->ref_count = 1;
    return a;
}

return_type: struct arg { enum { TYPE=0, POINTER=1, SUFFIX=2, CPP_MUDDLE=3 } parse_state; struct type { unsigned char *name; struct type *next; struct type *prev; } *name; struct shared_type { struct type *t; int ref_count; } *types; struct type *pointers; struct type *suffixes; unsigned int line; struct arg *prev; struct arg *next; char *function_pointer; char *function_pointer_arguments; unsigned int is_typedef; unsigned int is_function_pointer; } *


decompiled_code:
__int64 __fastcall arg_share(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
int v3; // edx
bool v4; // zf

result = new_arg();
v2 = *(_QWORD *)(a1 + 16);
v3 = *(_DWORD *)(v2 + 8);
*(_QWORD *)(result + 16) = v2;
if ( v3 )
{
v4 = *(_QWORD *)(a1 + 56) == 0LL;
*(_DWORD *)(v2 + 8) = v3 + 1;
*(_DWORD *)result = 1;
*(_QWORD *)(result + 48) = a1;
if ( v4 )
{
*(_QWORD *)(a1 + 56) = result;
return result;
}
}
else
{
bug("argument.c", 54LL, "zero ref count in copied argument");
}
bug("argument.c", 60LL, "non-zero next argument in arg");
return arg_add();
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
int v3; // edx
bool v4; // zf

result = func2();
v2 = *(_QWORD *)(a1 + 16);
v3 = *(_DWORD *)(v2 + 8);
*(_QWORD *)(result + 16) = v2;
if ( v3 )
{
v4 = *(_QWORD *)(a1 + 56) == 0LL;
*(_DWORD *)(v2 + 8) = v3 + 1;
*(_DWORD *)result = 1;
*(_QWORD *)(result + 48) = a1;
if ( v4 )
{
*(_QWORD *)(a1 + 56) = result;
return result;
}
}
else
{
bug("argument.c", 54LL, "zero ref count in copied argument");
}
bug("argument.c", 60LL, "non-zero next argument in arg");
return func9();
}

original_code:
struct arg *
arg_share (struct arg * a)
{
    struct arg * b;
    b = new_arg ();
    b->types = a->types;
    if (a->types->ref_count == 0) {
 bug ("argument.c", 54, "zero ref count in copied argument");
    }
    b->types->ref_count++;
    b->parse_state = POINTER;
    b->prev = a;
    if (a->next) {
 bug ("argument.c", 60, "non-zero next argument in arg");
    }
    a->next = b;
    return b;
}

canonical_original_code:
struct arg *arg_share(struct arg *a)
{
    struct arg *b;
    b = new_arg ();
    b->types = a->types;
    if (a->types->ref_count == 0) {
 bug ("argument.c", 54, "zero ref count in copied argument");
    }
    b->types->ref_count++;
    b->parse_state = POINTER;
    b->prev = a;
    if (a->next) {
 bug ("argument.c", 60, "non-zero next argument in arg");
    }
    a->next = b;
    return b;
}

variable_types:
a
struct arg *


decompiled_code:
void *__fastcall arg_add(__int64 *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
__int64 v4; // rax
_QWORD *v5; // r13
void *v6; // rax
void *result; // rax
__int64 v8; // rcx
__int64 v9; // rdi

v2 = strlen(a2);
if ( !v2 )
goto LABEL_16;
v3 = v2;
v4 = calloc_or_exit(1LL, 24LL);
++arg_n_mallocs;
v5 = (_QWORD *)v4;
v6 = (void *)malloc_or_exit((unsigned int)(v3 + 1));
++arg_n_mallocs;
*v5 = v6;
result = memcpy(v6, a2, (unsigned int)(v3 + 1));
if ( *a2 == 42 )
{
*(_DWORD *)a1 = 1;
return (void *)type_list_add(a1 + 3, (__int64)v5);
}
v8 = *(unsigned int *)a1;
if ( (_DWORD)v8 == 2 )
{
result = check_cpp_muddle(a1, a2);
v8 = *(unsigned int *)a1;
if ( (_DWORD)v8 == 2 )
{
if ( strchr(a2, 91) )
return (void *)type_list_add(a1 + 4, (__int64)v5);
goto LABEL_18;
}
}
if ( (unsigned int)v8 <= 2 )
{
if ( !(_DWORD)v8 )
{
v9 = a1[2];
if ( *(int *)(v9 + 8) <= 1 )
return (void *)type_list_add((__int64 *)v9, (__int64)v5);
goto LABEL_17;
}
return (void *)type_list_add(a1 + 3, (__int64)v5);
}
if ( (_DWORD)v8 != 3 )
{
bug("argument.c", 142LL, "a->parse_state had bad value %d", v8);
LABEL_16:
bug("argument.c", 102LL, "Length of string is zero in arg_add");
LABEL_17:
bug("argument.c", 129LL, "addition to a shared type list");
LABEL_18:
bug("argument.c", 118LL, "no [ in suffix, string is %s", a2);
result = (void *)arg_put_name();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func9(__int64 *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
__int64 v4; // rax
_QWORD *v5; // r13
void *v6; // rax
void *result; // rax
__int64 v8; // rcx
__int64 v9; // rdi

v2 = strlen(a2);
if ( !v2 )
goto LABEL_16;
v3 = v2;
v4 = calloc_or_exit(1LL, 24LL);
++arg_n_mallocs;
v5 = (_QWORD *)v4;
v6 = (void *)malloc_or_exit((unsigned int)(v3 + 1));
++arg_n_mallocs;
*v5 = v6;
result = memcpy(v6, a2, (unsigned int)(v3 + 1));
if ( *a2 == 42 )
{
*(_DWORD *)a1 = 1;
return (void *)func0(a1 + 3, (__int64)v5);
}
v8 = *(unsigned int *)a1;
if ( (_DWORD)v8 == 2 )
{
result = func3(a1, a2);
v8 = *(unsigned int *)a1;
if ( (_DWORD)v8 == 2 )
{
if ( strchr(a2, 91) )
return (void *)func0(a1 + 4, (__int64)v5);
goto LABEL_18;
}
}
if ( (unsigned int)v8 <= 2 )
{
if ( !(_DWORD)v8 )
{
v9 = a1[2];
if ( *(int *)(v9 + 8) <= 1 )
return (void *)func0((__int64 *)v9, (__int64)v5);
goto LABEL_17;
}
return (void *)func0(a1 + 3, (__int64)v5);
}
if ( (_DWORD)v8 != 3 )
{
bug("argument.c", 142LL, "a->parse_state had bad value %d", v8);
LABEL_16:
bug("argument.c", 102LL, "Length of string is zero in arg_add");
LABEL_17:
bug("argument.c", 129LL, "addition to a shared type list");
LABEL_18:
bug("argument.c", 118LL, "no [ in suffix, string is %s", a2);
result = (void *)func10();
}
return result;
}

original_code:
void
arg_add (struct arg * a, const char * t, int yyleng)
{
    unsigned t_len;
    struct type * x;
    t_len = strlen (t);
    if (t_len == 0) {
 bug ("argument.c", 102, "Length of string is zero in arg_add");
    }
    x = calloc_or_exit (1, sizeof (struct type));
    arg_n_mallocs++;
    x->name = malloc_or_exit (t_len + 1);
    arg_n_mallocs++;
    memcpy (x->name, t, t_len + 1);
    if (t[0] == '*') {
        a->parse_state = POINTER;
    }
    if (a->parse_state == SUFFIX) {
        check_cpp_muddle (a, t);
    }
    switch (a->parse_state) {
    case SUFFIX:
        if (! strchr (t, '[')) {
            bug ("argument.c", 118, "no [ in suffix, string is %s", t);
        }
        type_list_add (& a->suffixes, x);
        break;
    case POINTER:
        type_list_add (& a->pointers, x);
        break;
    case TYPE:
        if (a->types->ref_count > 1) {
            bug ("argument.c", 129, "addition to a shared type list");
        }
        else {
            type_list_add (& a->types->t, x);
        }
        break;
    case CPP_MUDDLE:
        break;
    default:
        bug ("argument.c", 142, "a->parse_state had bad value %d", a->parse_state);
    }
}

canonical_original_code:
void arg_add(struct arg *a, char *t, int yyleng)
{
    unsigned int t_len;
    struct type *x;
    t_len = strlen (t);
    if (t_len == 0) {
 bug ("argument.c", 102, "Length of string is zero in arg_add");
    }
    x = calloc_or_exit (1, sizeof (struct type));
    arg_n_mallocs++;
    x->name = malloc_or_exit (t_len + 1);
    arg_n_mallocs++;
    memcpy (x->name, t, t_len + 1);
    if (t[0] == '*') {
        a->parse_state = POINTER;
    }
    if (a->parse_state == SUFFIX) {
        check_cpp_muddle (a, t);
    }
    switch (a->parse_state) {
    case SUFFIX:
        if (! strchr (t, '[')) {
            bug ("argument.c", 118, "no [ in suffix, string is %s", t);
        }
        type_list_add (& a->suffixes, x);
        break;
    case POINTER:
        type_list_add (& a->pointers, x);
        break;
    case TYPE:
        if (a->types->ref_count > 1) {
            bug ("argument.c", 129, "addition to a shared type list");
        }
        else {
            type_list_add (& a->types->t, x);
        }
        break;
    case CPP_MUDDLE:
        break;
    default:
        bug ("argument.c", 142, "a->parse_state had bad value %d", a->parse_state);
    }
}

variable_types: yyleng int