gotoxy

decompiled_code:
int __fastcall gotoxy(int a1, int a2)
{
wmove(stdscr, a2 - 1, a1 - 1);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2)
{
wmove(stdscr, a2 - 1, a1 - 1);
return wrefresh(stdscr);
}

original_code:
void gotoxy(int x, int y)
{
    wmove(stdscr,(y-1),(x-1));
    wrefresh(stdscr);
}

variable_types: x int

variable_types: y int


repo: cjpl/daq

decompiled_code:
__int64 con_printf_xy(int a1, int a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a3);
wmove(stdscr, a2 - 1, a1 - 1);
wrefresh(stdscr);
LODWORD(a3) = vwprintw(stdscr, a3, va);
wrefresh(stdscr);
return (unsigned int)a3;
}

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

va_start(va, a3);
wmove(stdscr, a2 - 1, a1 - 1);
wrefresh(stdscr);
LODWORD(a3) = vwprintw(stdscr, a3, va);
wrefresh(stdscr);
return (unsigned int)a3;
}

original_code:
int con_printf_xy(unsigned int xpos, unsigned int ypos, char *fmt,...)
{
    va_list marker;
    int i;
    wmove(stdscr,(ypos-1),(xpos-1));
    wrefresh(stdscr);
    __builtin_va_start(marker,fmt);
    i = vwprintw(stdscr,fmt,marker);
    __builtin_va_end(marker);
    wrefresh(stdscr);
    return i;
}

canonical_original_code:
int con_printf_xy(unsigned int xpos, unsigned int ypos, char *fmt, ...)
{
    __builtin_va_list marker;
    int i;
    wmove(stdscr,(ypos-1),(xpos-1));
    wrefresh(stdscr);
    __builtin_va_start(marker,fmt);
    i = vwprintw(stdscr,fmt,marker);
    __builtin_va_end(marker);
    wrefresh(stdscr);
    return i;
}

variable_types:
xpos
unsigned int

variable_types:
ypos
unsigned int

variable_types:
fmt
char *

variable_types: i int

return_type: int


clrscr

decompiled_code:
int clrscr()
{
wclear(stdscr);
wmove(stdscr, 0, 0);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func9()
{
wclear(stdscr);
wmove(stdscr, 0, 0);
return wrefresh(stdscr);
}

original_code:
void clrscr(void)
{
    wclear(stdscr);
    wmove(stdscr,(0),(0));
    wrefresh(stdscr);
}

canonical_original_code:
void clrscr()
{
    wclear(stdscr);
    wmove(stdscr,(0),(0));
    wrefresh(stdscr);
}

return_type: void


decompiled_code:
int __fastcall clear_line(int a1)
{
gotoxy(1, a1);
return wclrtoeol(stdscr);
}

canonical_decompiled_code:
int __fastcall func10(int a1)
{
func7(1, a1);
return wclrtoeol(stdscr);
}

original_code:
void clear_line(unsigned int line)
{
    gotoxy(1, line);
    wclrtoeol(stdscr);
}

variable_types:
line
unsigned int


delay

decompiled_code:
int __fastcall delay(int a1)
{
return usleep(1000 * a1);
}

canonical_decompiled_code:
int __fastcall func11(int a1)
{
return usleep(1000 * a1);
}

original_code:
void delay(int msec)
{
    usleep(msec*1000);
}

variable_types: msec int


repo: cklin/mdm

decompiled_code:
__int64 __fastcall serv_listen(char *name)
{
int v1; // eax
unsigned int v2; // er12
size_t v3; // rbx
_BYTE v5[104]; // [rsp+0h] [rbp-98h] BYREF
int v6; // [rsp+68h] [rbp-30h]
__int16 v7; // [rsp+6Ch] [rbp-2Ch]

v1 = socket(1, 1, 0);
if ( v1 < 0 )
{
v2 = -1;
warn("socket");
}
else
{
v2 = v1;
v3 = strlen(name);
if ( (unsigned int)v3 > 0x6B )
{
v2 = -2;
warnx("serv_listen: socket name too long");
}
else
{
memset(v5, 0, sizeof(v5));
*(_WORD *)v5 = 1;
v6 = 0;
v7 = 0;
memcpy(&v5[2], name, v3 + 1);
unlink(name);
if ( bind(v2, (const struct sockaddr *)v5, v3 + 2) < 0 )
{
v2 = -3;
warn("bind");
}
else if ( listen(v2, 5) < 0 )
{
v2 = -4;
warn("listen");
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *name)
{
int v1; // eax
unsigned int v2; // er12
size_t v3; // rbx
_BYTE v5[104]; // [rsp+0h] [rbp-98h] BYREF
int v6; // [rsp+68h] [rbp-30h]
__int16 v7; // [rsp+6Ch] [rbp-2Ch]

v1 = socket(1, 1, 0);
if ( v1 < 0 )
{
v2 = -1;
warn("socket");
}
else
{
v2 = v1;
v3 = strlen(name);
if ( (unsigned int)v3 > 0x6B )
{
v2 = -2;
warnx("serv_listen: socket name too long");
}
else
{
memset(v5, 0, sizeof(v5));
*(_WORD *)v5 = 1;
v6 = 0;
v7 = 0;
memcpy(&v5[2], name, v3 + 1);
unlink(name);
if ( bind(v2, (const struct sockaddr *)v5, v3 + 2) < 0 )
{
v2 = -3;
warn("bind");
}
else if ( listen(v2, 5) < 0 )
{
v2 = -4;
warn("listen");
}
}
}
return v2;
}

original_code:
int serv_listen(const char *name)
{
  int sockfd, addrlen;
  struct sockaddr_un unix_addr;
  struct sockaddr *sock_addr;
  sockfd = socket(1, SOCK_STREAM, 0);
  if (sockfd < 0) {
    warn("socket");
    return -1;
  }
  addrlen = strlen(name);
  if (addrlen >= sizeof (unix_addr.sun_path)) {
    warnx("serv_listen: socket name too long");
    return -2;
  }
  addrlen += sizeof (unix_addr.sun_family);
  memset(&unix_addr, 0, sizeof (unix_addr));
  unix_addr.sun_family = 1;
  strcpy(unix_addr.sun_path, name);
  unlink(name);
  sock_addr = (struct sockaddr *) &unix_addr;
  if (bind(sockfd, sock_addr, addrlen) < 0) {
    warn("bind");
    return -3;
  }
  if (listen(sockfd, 5) < 0) {
    warn("listen");
    return -4;
  }
  return sockfd;
}

canonical_original_code:
int serv_listen(char *name)
{
  int sockfd; int addrlen;
  struct sockaddr_un unix_addr;
  struct sockaddr *sock_addr;
  sockfd = socket(1, SOCK_STREAM, 0);
  if (sockfd < 0) {
    warn("socket");
    return -1;
  }
  addrlen = strlen(name);
  if (addrlen >= sizeof (unix_addr.sun_path)) {
    warnx("serv_listen: socket name too long");
    return -2;
  }
  addrlen += sizeof (unix_addr.sun_family);
  memset(&unix_addr, 0, sizeof (unix_addr));
  unix_addr.sun_family = 1;
  strcpy(unix_addr.sun_path, name);
  unlink(name);
  sock_addr = (struct sockaddr *) &unix_addr;
  if (bind(sockfd, sock_addr, addrlen) < 0) {
    warn("bind");
    return -3;
  }
  if (listen(sockfd, 5) < 0) {
    warn("listen");
    return -4;
  }
  return sockfd;
}

variable_types:
name
char *

variable_types: sockfd int

variable_types: addrlen int

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

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


decompiled_code:
__int64 __fastcall serv_accept(int a1)
{
int v1; // er12

v1 = accept(a1, 0LL, 0LL);
if ( v1 < 0 )
warn("accept");
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // er12

v1 = accept(a1, 0LL, 0LL);
if ( v1 < 0 )
warn("accept");
return (unsigned int)v1;
}

original_code:
int serv_accept(int listenfd)
{
  int connfd;
  connfd = accept(listenfd, ((void *)0), ((void *)0));
  if (connfd < 0)
    warn("accept");
  return connfd;
}

variable_types: listenfd int

variable_types: connfd int


decompiled_code:
__int64 __fastcall cli_conn(void *src)
{
int v1; // eax
unsigned int v2; // er12
size_t v3; // rbx
_BYTE v5[104]; // [rsp+0h] [rbp-98h] BYREF
int v6; // [rsp+68h] [rbp-30h]
__int16 v7; // [rsp+6Ch] [rbp-2Ch]

v1 = socket(1, 1, 0);
if ( v1 < 0 )
{
v2 = -1;
warn("socket");
}
else
{
v2 = v1;
v3 = strlen((const char *)src);
if ( (unsigned int)v3 > 0x6B )
{
v2 = -2;
warnx("serv_listen: socket name too long");
}
else
{
memset(v5, 0, sizeof(v5));
*(_WORD *)v5 = 1;
v6 = 0;
v7 = 0;
memcpy(&v5[2], src, v3 + 1);
if ( connect(v2, (const struct sockaddr *)v5, v3 + 2) < 0 )
{
v2 = -3;
warn("connect");
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *src)
{
int v1; // eax
unsigned int v2; // er12
size_t v3; // rbx
_BYTE v5[104]; // [rsp+0h] [rbp-98h] BYREF
int v6; // [rsp+68h] [rbp-30h]
__int16 v7; // [rsp+6Ch] [rbp-2Ch]

v1 = socket(1, 1, 0);
if ( v1 < 0 )
{
v2 = -1;
warn("socket");
}
else
{
v2 = v1;
v3 = strlen((const char *)src);
if ( (unsigned int)v3 > 0x6B )
{
v2 = -2;
warnx("serv_listen: socket name too long");
}
else
{
memset(v5, 0, sizeof(v5));
*(_WORD *)v5 = 1;
v6 = 0;
v7 = 0;
memcpy(&v5[2], src, v3 + 1);
if ( connect(v2, (const struct sockaddr *)v5, v3 + 2) < 0 )
{
v2 = -3;
warn("connect");
}
}
}
return v2;
}

original_code:
int cli_conn(const char *name)
{
  int sockfd, addrlen;
  struct sockaddr_un unix_addr;
  struct sockaddr *sock_addr;
  sockfd = socket(1, SOCK_STREAM, 0);
  if (sockfd < 0) {
    warn("socket");
    return -1;
  }
  addrlen = strlen(name);
  if (addrlen >= sizeof (unix_addr.sun_path)) {
    warnx("serv_listen: socket name too long");
    return -2;
  }
  addrlen += sizeof (unix_addr.sun_family);
  memset(&unix_addr, 0, sizeof (unix_addr));
  unix_addr.sun_family = 1;
  strcpy(unix_addr.sun_path, name);
  sock_addr = (struct sockaddr *) &unix_addr;
  if (connect(sockfd, sock_addr, addrlen) < 0) {
    warn("connect");
    return -3;
  }
  return sockfd;
}

canonical_original_code:
int cli_conn(char *name)
{
  int sockfd; int addrlen;
  struct sockaddr_un unix_addr;
  struct sockaddr *sock_addr;
  sockfd = socket(1, SOCK_STREAM, 0);
  if (sockfd < 0) {
    warn("socket");
    return -1;
  }
  addrlen = strlen(name);
  if (addrlen >= sizeof (unix_addr.sun_path)) {
    warnx("serv_listen: socket name too long");
    return -2;
  }
  addrlen += sizeof (unix_addr.sun_family);
  memset(&unix_addr, 0, sizeof (unix_addr));
  unix_addr.sun_family = 1;
  strcpy(unix_addr.sun_path, name);
  sock_addr = (struct sockaddr *) &unix_addr;
  if (connect(sockfd, sock_addr, addrlen) < 0) {
    warn("connect");
    return -3;
  }
  return sockfd;
}

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


readn

decompiled_code:
size_t __fastcall readn(int fd, void *buf, size_t nbytes)
{
size_t v3; // r14
size_t v5; // rbx
ssize_t v6; // rax
ssize_t v7; // r12

v3 = nbytes;
if ( !nbytes )
return v3;
v5 = nbytes;
while ( 1 )
{
v6 = read(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
if ( v6 )
{
warn("read");
return v7;
}
return v7;
}

canonical_decompiled_code:
size_t __fastcall func3(int fd, void *buf, size_t nbytes)
{
size_t v3; // r14
size_t v5; // rbx
ssize_t v6; // rax
ssize_t v7; // r12

v3 = nbytes;
if ( !nbytes )
return v3;
v5 = nbytes;
while ( 1 )
{
v6 = read(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
if ( v6 )
{
warn("read");
return v7;
}
return v7;
}

original_code:
ssize_t readn(int fd, void *vptr, size_t n)
{
  size_t remaining;
  ssize_t received;
  char *ptr;
  remaining = n;
  ptr = vptr;
  while (remaining > 0) {
    received = read(fd, ptr, remaining);
    if (received <= 0) {
      if (received < 0) warn("read");
      return received;
    }
    remaining -= received;
    ptr += received;
  }
  return n;
}

canonical_original_code:
long readn(int fd, void *vptr, unsigned long n)
{
  unsigned long remaining;
  long received;
  char *ptr;
  remaining = n;
  ptr = vptr;
  while (remaining > 0) {
    received = read(fd, ptr, remaining);
    if (received <= 0) {
      if (received < 0) warn("read");
      return received;
    }
    remaining -= received;
    ptr += received;
  }
  return n;
}

variable_types: fd int

variable_types:
vptr
void *

variable_types:
n
unsigned long

variable_types:
remaining
unsigned long

variable_types: received long

variable_types:
ptr
char *

return_type: long


writen

decompiled_code:
size_t __fastcall writen(int fd, void *buf, size_t n)
{
size_t v3; // r14
size_t v5; // rbx
ssize_t v6; // rax
ssize_t v7; // r12

v3 = n;
if ( !n )
return v3;
v5 = n;
while ( 1 )
{
v6 = write(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
if ( v6 )
{
warn("write");
return v7;
}
return v7;
}

canonical_decompiled_code:
size_t __fastcall func4(int fd, void *buf, size_t n)
{
size_t v3; // r14
size_t v5; // rbx
ssize_t v6; // rax
ssize_t v7; // r12

v3 = n;
if ( !n )
return v3;
v5 = n;
while ( 1 )
{
v6 = write(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
if ( v6 )
{
warn("write");
return v7;
}
return v7;
}

original_code:
ssize_t writen(int fd, const void *vptr, size_t n)
{
  size_t remaining;
  ssize_t written;
  const char *ptr;
  remaining = n;
  ptr = vptr;
  while (remaining > 0) {
    written = write(fd, ptr, remaining);
    if (written <= 0) {
      if (written < 0) warn("write");
      return written;
    }
    remaining -= written;
    ptr += written;
  }
  return n;
}

canonical_original_code:
long writen(int fd, void *vptr, unsigned long n)
{
  unsigned long remaining;
  long written;
  char *ptr;
  remaining = n;
  ptr = vptr;
  while (remaining > 0) {
    written = write(fd, ptr, remaining);
    if (written <= 0) {
      if (written < 0) warn("write");
      return written;
    }
    remaining -= written;
    ptr += written;
  }
  return n;
}

variable_types: written long


decompiled_code:
__int64 __fastcall send_fd(int fd, int a2)
{
_DWORD *v2; // rax
char v4; // [rsp+Fh] [rbp-69h] BYREF
__int64 v5[2]; // [rsp+10h] [rbp-68h] BYREF
struct msghdr message; // [rsp+20h] [rbp-58h] BYREF

v4 = 0;
v5[0] = (__int64)&v4;
message.msg_iov = (iovec *)v5;
v2 = (_DWORD *)cmptr;
v5[1] = 1LL;
message.msg_iovlen = 1LL;
message.msg_name = 0LL;
message.msg_namelen = 0;
if ( !cmptr )
{
v2 = (_DWORD *)xmalloc(20LL);
cmptr = (__int64)v2;
}
*(_QWORD *)v2 = 20LL;
*((_QWORD *)v2 + 1) = 0x100000001LL;
message.msg_control = v2;
message.msg_controllen = 20LL;
v2[4] = a2;
if ( sendmsg(fd, &message, 0) == 1 )
return 0LL;
warn("send_fd sendmsg");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, int a2)
{
_DWORD *v2; // rax
char v4; // [rsp+Fh] [rbp-69h] BYREF
__int64 v5[2]; // [rsp+10h] [rbp-68h] BYREF
struct msghdr message; // [rsp+20h] [rbp-58h] BYREF

v4 = 0;
v5[0] = (__int64)&v4;
message.msg_iov = (iovec *)v5;
v2 = (_DWORD *)cmptr;
v5[1] = 1LL;
message.msg_iovlen = 1LL;
message.msg_name = 0LL;
message.msg_namelen = 0;
if ( !cmptr )
{
v2 = (_DWORD *)xmalloc(20LL);
cmptr = (__int64)v2;
}
*(_QWORD *)v2 = 20LL;
*((_QWORD *)v2 + 1) = 0x100000001LL;
message.msg_control = v2;
message.msg_controllen = 20LL;
v2[4] = a2;
if ( sendmsg(fd, &message, 0) == 1 )
return 0LL;
warn("send_fd sendmsg");
return 0xFFFFFFFFLL;
}

original_code:
int send_fd(int sockfd, int fd)
{
  struct iovec iov;
  struct msghdr msg;
  char ch;
  ch = 0;
  iov.iov_base = &ch;
  iov.iov_len = 1;
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  msg.msg_name = ((void *)0);
  msg.msg_namelen = 0;
  if (!cmptr) cmptr = xmalloc((sizeof (struct cmsghdr)+sizeof (int)));
  cmptr->cmsg_level = 1;
  cmptr->cmsg_type = SCM_RIGHTS;
  cmptr->cmsg_len = (sizeof (struct cmsghdr)+sizeof (int));
  msg.msg_control = (caddr_t) cmptr;
  msg.msg_controllen = (sizeof (struct cmsghdr)+sizeof (int));
  *(int *) ((cmptr)->__cmsg_data) = fd;
  if (sendmsg(sockfd, &msg, 0) != 1) {
    warn("send_fd sendmsg");
    return -1;
  }
  return 0;
}

canonical_original_code:
int send_fd(int sockfd, int fd)
{
  struct iovec iov;
  struct msghdr msg;
  char ch;
  ch = 0;
  iov.iov_base = &ch;
  iov.iov_len = 1;
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  msg.msg_name = ((void *)0);
  msg.msg_namelen = 0;
  if (!cmptr) cmptr = xmalloc((sizeof (struct cmsghdr)+sizeof (int)));
  cmptr->cmsg_level = 1;
  cmptr->cmsg_type = SCM_RIGHTS;
  cmptr->cmsg_len = (sizeof (struct cmsghdr)+sizeof (int));
  msg.msg_control = (char *) cmptr;
  msg.msg_controllen = (sizeof (struct cmsghdr)+sizeof (int));
  *(int *) ((cmptr)->__cmsg_data) = fd;
  if (sendmsg(sockfd, &msg, 0) != 1) {
    warn("send_fd sendmsg");
    return -1;
  }
  return 0;
}

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types: ch char

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

user_defined_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; }


decompiled_code:
__int64 __fastcall recv_fd(int fd)
{
unsigned int *v1; // rbx
int v2; // eax
__int64 result; // rax
char v4; // [rsp+Fh] [rbp-69h] BYREF
__int64 v5[2]; // [rsp+10h] [rbp-68h] BYREF
struct msghdr message; // [rsp+20h] [rbp-58h] BYREF

v5[1] = 1LL;
v5[0] = (__int64)&v4;
message.msg_iov = (iovec *)v5;
message.msg_iovlen = 1LL;
message.msg_name = 0LL;
message.msg_namelen = 0;
message.msg_control = (void *)xmalloc(20LL);
v1 = (unsigned int *)message.msg_control;
message.msg_controllen = 20LL;
v2 = recvmsg(fd, &message, 0);
if ( v2 < 0 )
{
warn("recv_fd recvmsg");
result = 0xFFFFFFFFLL;
}
else if ( v2 )
{
if ( v4 || message.msg_controllen != 20 )
{
warnx("recv_fd: protocol error");
result = 4294967293LL;
}
else
{
result = v1[4];
}
}
else
{
warnx("recv_fd: connection closed by server");
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd)
{
unsigned int *v1; // rbx
int v2; // eax
__int64 result; // rax
char v4; // [rsp+Fh] [rbp-69h] BYREF
__int64 v5[2]; // [rsp+10h] [rbp-68h] BYREF
struct msghdr message; // [rsp+20h] [rbp-58h] BYREF

v5[1] = 1LL;
v5[0] = (__int64)&v4;
message.msg_iov = (iovec *)v5;
message.msg_iovlen = 1LL;
message.msg_name = 0LL;
message.msg_namelen = 0;
message.msg_control = (void *)xmalloc(20LL);
v1 = (unsigned int *)message.msg_control;
message.msg_controllen = 20LL;
v2 = recvmsg(fd, &message, 0);
if ( v2 < 0 )
{
warn("recv_fd recvmsg");
result = 0xFFFFFFFFLL;
}
else if ( v2 )
{
if ( v4 || message.msg_controllen != 20 )
{
warnx("recv_fd: protocol error");
result = 4294967293LL;
}
else
{
result = v1[4];
}
}
else
{
warnx("recv_fd: connection closed by server");
result = 4294967294LL;
}
return result;
}

original_code:
int recv_fd(int sockfd)
{
  struct cmsghdr *cmptr = ((void *)0);
  struct iovec iov;
  struct msghdr msg;
  char ch;
  int nread;
  iov.iov_base = &ch;
  iov.iov_len = 1;
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  msg.msg_name = ((void *)0);
  msg.msg_namelen = 0;
  if (!cmptr) cmptr = xmalloc((sizeof (struct cmsghdr)+sizeof (int)));
  msg.msg_control = (caddr_t) cmptr;
  msg.msg_controllen = (sizeof (struct cmsghdr)+sizeof (int));
  nread = recvmsg(sockfd, &msg, 0);
  if (nread < 0) {
    warn("recv_fd recvmsg");
    return -1;
  }
  if (nread == 0) {
    warnx("recv_fd: connection closed by server");
    return -2;
  }
  if (ch == 0)
    if (msg.msg_controllen == (sizeof (struct cmsghdr)+sizeof (int)))
      return *(int *) ((cmptr)->__cmsg_data);
  warnx("recv_fd: protocol error");
  return -3;
}

canonical_original_code:
int recv_fd(int sockfd)
{
  struct cmsghdr *cmptr = ((void *)0);
  struct iovec iov;
  struct msghdr msg;
  char ch;
  int nread;
  iov.iov_base = &ch;
  iov.iov_len = 1;
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  msg.msg_name = ((void *)0);
  msg.msg_namelen = 0;
  if (!cmptr) cmptr = xmalloc((sizeof (struct cmsghdr)+sizeof (int)));
  msg.msg_control = (char *) cmptr;
  msg.msg_controllen = (sizeof (struct cmsghdr)+sizeof (int));
  nread = recvmsg(sockfd, &msg, 0);
  if (nread < 0) {
    warn("recv_fd recvmsg");
    return -1;
  }
  if (nread == 0) {
    warnx("recv_fd: connection closed by server");
    return -2;
  }
  if (ch == 0)
    if (msg.msg_controllen == (sizeof (struct cmsghdr)+sizeof (int)))
      return *(int *) ((cmptr)->__cmsg_data);
  warnx("recv_fd: protocol error");
  return -3;
}

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

variable_types: struct iovec { void *iov_base; unsigned long iov_len; }

variable_types: nread int


decompiled_code:
size_t __fastcall write_int(int a1, int a2)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return writen(a1, buf, 4uLL);
}

canonical_decompiled_code:
size_t __fastcall func7(int a1, int a2)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return func4(a1, buf, 4uLL);
}

original_code:
ssize_t write_int(int fd, int v)
{
  return writen(fd, &v, sizeof (int));
}

canonical_original_code:
long write_int(int fd, int v)
{
  return writen(fd, &v, sizeof (int));
}

variable_types: v int


decompiled_code:
// attributes: thunk
size_t __fastcall write_pid(int a1, int a2)
{
return write_int(a1, a2);
}

canonical_decompiled_code:
size_t __fastcall func8(int a1, int a2)
{
return func7(a1, a2);
}

original_code:
ssize_t write_pid(int fd, pid_t v)
{
  return writen(fd, &v, sizeof (pid_t));
}

canonical_original_code:
long write_pid(int fd, int v)
{
  return writen(fd, &v, sizeof (pid_t));
}


decompiled_code:
size_t __fastcall write_time(int a1, __int64 a2)
{
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

buf = a2;
return writen(a1, &buf, 8uLL);
}

canonical_decompiled_code:
size_t __fastcall func9(int a1, __int64 a2)
{
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

buf = a2;
return func4(a1, &buf, 8uLL);
}

original_code:
ssize_t write_time(int fd, time_t v)
{
  return writen(fd, &v, sizeof (time_t));
}

canonical_original_code:
long write_time(int fd, long v)
{
  return writen(fd, &v, sizeof (time_t));
}

variable_types: v long


decompiled_code:
__int64 __fastcall check_sockdir(const char *a1)
{
__int64 result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( lstat(a1, &v2) < 0 )
err(110, "stat(\"%s\")", a1);
result = v2.st_mode;
if ( (v2.st_mode & 0xF000) != 0x4000 )
errx(111, "%s is not a directory", a1);
if ( (v2.st_mode & 2) != 0 )
errx(112, "%s is world-writable", a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
__int64 result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( lstat(a1, &v2) < 0 )
err(110, "stat(\"%s\")", a1);
result = v2.st_mode;
if ( (v2.st_mode & 0xF000) != 0x4000 )
errx(111, "%s is not a directory", a1);
if ( (v2.st_mode & 2) != 0 )
errx(112, "%s is world-writable", a1);
return result;
}

original_code:
void check_sockdir(const char *path)
{
  struct stat st;
  if (lstat(path, &st) < 0)
    err(110, "stat(\"%s\")", path);
  if (! ((((st.st_mode)) & 0170000) == (0040000)))
    errx(111, "%s is not a directory", path);
  if (st.st_mode & ((0200 >> 3) >> 3))
    errx(112, "%s is world-writable", path);
}

canonical_original_code:
void check_sockdir(char *path)
{
  struct stat st;
  if (lstat(path, &st) < 0)
    err(110, "stat(\"%s\")", path);
  if (! ((((st.st_mode)) & 0170000) == (0040000)))
    errx(111, "%s is not a directory", path);
  if (st.st_mode & ((0200 >> 3) >> 3))
    errx(112, "%s is world-writable", path);
}

variable_types:
path
char *

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


conflict

decompiled_code:
__int64 __fastcall conflict(char a1, char a2, int a3)
{
unsigned int v3; // eax

LOBYTE(v3) = a1 == 87;
LOBYTE(a3) = a1 != a2;
return a3 | v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, char a2, int a3)
{
unsigned int v3; // eax

LOBYTE(v3) = a1 == 87;
LOBYTE(a3) = a1 != a2;
return a3 | v3;
}

original_code:
static _Bool conflict(char c1, char c2)
{
  return (c1 == 'W' || c1 != c2);
}


decompiled_code:
const unsigned __int16 *__fastcall read_iospec(__int64 a1, __int64 a2)
{
const unsigned __int16 *result; // rax
__int64 v4; // rbx
const unsigned __int16 *v5; // rbp
const unsigned __int16 **v6; // rax
char v7; // dl
int v8; // esi
const unsigned __int16 **v9; // rcx

*(_QWORD *)(a2 + 8) = 0LL;
result = (const unsigned __int16 *)xstrdup();
*(_QWORD *)a2 = result;
v4 = *(char *)result;
if ( (_BYTE)v4 )
{
v5 = result;
v6 = _ctype_b_loc();
v7 = 0;
v8 = 0;
v9 = v6;
do
{
while ( 1 )
{
result = *v9;
if ( ((*v9)[v4] & 0x2000) == 0 )
break;
*(_BYTE *)v5 = 0;
v4 = *((char *)v5 + 1);
v5 = (const unsigned __int16 *)((char *)v5 + 1);
v7 = 1;
if ( !(_BYTE)v4 )
goto LABEL_10;
}
if ( v7 )
{
if ( !*(_QWORD *)(a2 + 8) )
*(_QWORD *)(a2 + 8) = v5;
++v8;
v7 = 0;
}
v4 = *((char *)v5 + 1);
v5 = (const unsigned __int16 *)((char *)v5 + 1);
}
while ( (_BYTE)v4 );
LABEL_10:
*(_DWORD *)(a2 + 16) = v8;
}
else
{
*(_DWORD *)(a2 + 16) = 0;
}
return result;
}

canonical_decompiled_code:
const unsigned __int16 *__fastcall func2(__int64 a1, __int64 a2)
{
const unsigned __int16 *result; // rax
__int64 v4; // rbx
const unsigned __int16 *v5; // rbp
const unsigned __int16 **v6; // rax
char v7; // dl
int v8; // esi
const unsigned __int16 **v9; // rcx

*(_QWORD *)(a2 + 8) = 0LL;
result = (const unsigned __int16 *)xstrdup();
*(_QWORD *)a2 = result;
v4 = *(char *)result;
if ( (_BYTE)v4 )
{
v5 = result;
v6 = _ctype_b_loc();
v7 = 0;
v8 = 0;
v9 = v6;
do
{
while ( 1 )
{
result = *v9;
if ( ((*v9)[v4] & 0x2000) == 0 )
break;
*(_BYTE *)v5 = 0;
v4 = *((char *)v5 + 1);
v5 = (const unsigned __int16 *)((char *)v5 + 1);
v7 = 1;
if ( !(_BYTE)v4 )
goto LABEL_10;
}
if ( v7 )
{
if ( !*(_QWORD *)(a2 + 8) )
*(_QWORD *)(a2 + 8) = v5;
++v8;
v7 = 0;
}
v4 = *((char *)v5 + 1);
v5 = (const unsigned __int16 *)((char *)v5 + 1);
}
while ( (_BYTE)v4 );
LABEL_10:
*(_DWORD *)(a2 + 16) = v8;
}
else
{
*(_DWORD *)(a2 + 16) = 0;
}
return result;
}

original_code:
static void read_iospec(const char *spec, iospec *ios)
{
  int count;
  _Bool new_token;
  char *cp;
  ios->resources = ((void *)0);
  ios->name = xstrdup(spec);
  new_token = 0;
  for (cp=ios->name, count=0; *cp; cp++) {
    if (((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short int) _ISspace)) {
      new_token = 1;
      *cp = '\0';
      continue;
    }
    if (new_token) {
      if (ios->resources == ((void *)0))
        ios->resources = cp;
      new_token = 0;
      count++;
    }
  }
  ios->res_count = count;
}

canonical_original_code:
static void read_iospec(char *spec, struct iospec *ios)
{
  int count;
  _Bool new_token;
  char *cp;
  ios->resources = ((void *)0);
  ios->name = xstrdup(spec);
  new_token = 0;
  for (cp=ios->name, count=0; *cp; cp++) {
    if (((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short) _ISspace)) {
      new_token = 1;
      *cp = '\0';
      continue;
    }
    if (new_token) {
      if (ios->resources == ((void *)0))
        ios->resources = cp;
      new_token = 0;
      count++;
    }
  }
  ios->res_count = count;
}

variable_types:
spec
char *

variable_types: struct iospec { char *name; char *resources; int res_count; } *

variable_types: count int

variable_types:
cp
char *


decompiled_code:
__int64 __fastcall check_conflict(char a1, const char *a2)
{
__int64 v2; // r12
__int64 v3; // rbx
int v4; // edx
__int64 result; // rax

if ( uti_count <= 0 )
return 0LL;
v2 = 24LL * uti_count;
v3 = 0LL;
while ( 1 )
{
if ( !strcmp(a2, *(const char **)((char *)&utit + v3 + 8)) )
{
result = conflict(a1, *((_BYTE *)&utit + v3), v4);
if ( (_BYTE)result )
break;
}
v3 += 24LL;
if ( v2 == v3 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, const char *a2)
{
__int64 v2; // r12
__int64 v3; // rbx
int v4; // edx
__int64 result; // rax

if ( uti_count <= 0 )
return 0LL;
v2 = 24LL * uti_count;
v3 = 0LL;
while ( 1 )
{
if ( !strcmp(a2, *(const char **)((char *)&utit + v3 + 8)) )
{
result = func1(a1, *((_BYTE *)&utit + v3), v4);
if ( (_BYTE)result )
break;
}
v3 += 24LL;
if ( v2 == v3 )
return 0LL;
}
return result;
}

original_code:
static _Bool check_conflict(char usage, const char *name)
{
  int index;
  for (index=0; index<uti_count; index++)
    if (strcmp(name, utit[index].name) == 0)
      if (conflict(usage, utit[index].usage))
        return 1;
  return 0;
}

canonical_original_code:
static _Bool check_conflict(char usage, char *name)
{
  int index;
  for (index=0; index<uti_count; index++)
    if (strcmp(name, utit[index].name) == 0)
      if (conflict(usage, utit[index].usage))
        return 1;
  return 0;
}

variable_types: usage char

variable_types:
name
char *

variable_types: index int


decompiled_code:
__int64 __fastcall find_iospec(char *s1)
{
int v1; // er13
const char **v2; // rbp
int v3; // ebx

v1 = ios_count;
if ( ios_count <= 0 )
return 0LL;
v2 = (const char **)&iost;
v3 = 0;
while ( strcmp(s1, *v2) )
{
++v3;
v2 += 3;
if ( v3 == v1 )
return 0LL;
}
return (__int64)&iost + 24 * v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s1)
{
int v1; // er13
const char **v2; // rbp
int v3; // ebx

v1 = ios_count;
if ( ios_count <= 0 )
return 0LL;
v2 = (const char **)&iost;
v3 = 0;
while ( strcmp(s1, *v2) )
{
++v3;
v2 += 3;
if ( v3 == v1 )
return 0LL;
}
return (__int64)&iost + 24 * v3;
}

original_code:
static iospec *find_iospec(const char *name)
{
  int index;
  for (index=0; index<ios_count; index++)
    if (strcmp(name, iost[index].name) == 0)
      return iost+index;
  return ((void *)0);
}

canonical_original_code:
static struct iospec *find_iospec(char *name)
{
  int index;
  for (index=0; index<ios_count; index++)
    if (strcmp(name, iost[index].name) == 0)
      return iost+index;
  return ((void *)0);
}

return_type: struct iospec { char *name; char *resources; int res_count; } *


decompiled_code:
__int64 __fastcall calc_usage(const char *a1, __int64 a2)
{
const char *v2; // rbx
__int64 result; // rax
const char *v4; // [rsp+8h] [rbp-20h] BYREF

iterate_spec(a2, 0LL);
do
{
if ( !(unsigned __int8)iterate_spec(0LL, (__int64 *)&v4) )
return 45LL;
v2 = v4;
}
while ( strcmp(a1, v4 + 1) );
result = *(unsigned __int8 *)v2;
if ( (_BYTE)result == 48 && *a1 == 45 )
result = calc_usage(&s1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, __int64 a2)
{
const char *v2; // rbx
__int64 result; // rax
const char *v4; // [rsp+8h] [rbp-20h] BYREF

func0(a2, 0LL);
do
{
if ( !(unsigned __int8)func0(0LL, (__int64 *)&v4) )
return 45LL;
v2 = v4;
}
while ( strcmp(a1, v4 + 1) );
result = *(unsigned __int8 *)v2;
if ( (_BYTE)result == 48 && *a1 == 45 )
result = func5(&s1, a2);
return result;
}

original_code:
static char calc_usage(const char *opt, iospec *ios)
{
  char *cp;
  iterate_spec(ios, ((void *)0));
  while (iterate_spec(((void *)0), &cp))
    if (strcmp(opt, cp+1) == 0) {
      if (*cp == '0' && *opt == '-')
        return calc_usage("", ios);
      return *cp;
    }
  return '-';
}

canonical_original_code:
static char calc_usage(char *opt, struct iospec *ios)
{
  char *cp;
  iterate_spec(ios, ((void *)0));
  while (iterate_spec(((void *)0), &cp))
    if (strcmp(opt, cp+1) == 0) {
      if (*cp == '0' && *opt == '-')
        return calc_usage("", ios);
      return *cp;
    }
  return '-';
}

variable_types:
opt
char *

return_type: char

user_defined_types: struct iospec { char *name; char *resources; int res_count; }


decompiled_code:
__int64 __fastcall add_utilization(char a1, const char *a2)
{
int v2; // er12
__int128 *v3; // rbx
int v4; // ebp
__int64 result; // rax

v2 = uti_count;
if ( uti_count <= 0 )
{
v4 = 0;
}
else
{
v3 = &utit;
v4 = 0;
do
{
if ( !strcmp(a2, *((const char **)v3 + 1)) && *(_BYTE *)v3 == a1 )
{
result = 3LL * v4;
++LODWORD(qword_970[3 * v4]);
return result;
}
++v4;
v3 = (__int128 *)((char *)v3 + 24);
}
while ( v4 != v2 );
if ( v4 == 4096 )
errx(124, "Utilization table is full");
}
*((_BYTE *)&utit + 24 * v4) = a1;
result = xstrdup(a2);
++uti_count;
*((_QWORD *)&utit + 3 * v4 + 1) = result;
LODWORD(qword_970[3 * v4]) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1, const char *a2)
{
int v2; // er12
__int128 *v3; // rbx
int v4; // ebp
__int64 result; // rax

v2 = uti_count;
if ( uti_count <= 0 )
{
v4 = 0;
}
else
{
v3 = &utit;
v4 = 0;
do
{
if ( !strcmp(a2, *((const char **)v3 + 1)) && *(_BYTE *)v3 == a1 )
{
result = 3LL * v4;
++LODWORD(qword_970[3 * v4]);
return result;
}
++v4;
v3 = (__int128 *)((char *)v3 + 24);
}
while ( v4 != v2 );
if ( v4 == 4096 )
errx(124, "Utilization table is full");
}
*((_BYTE *)&utit + 24 * v4) = a1;
result = xstrdup(a2);
++uti_count;
*((_QWORD *)&utit + 3 * v4 + 1) = result;
LODWORD(qword_970[3 * v4]) = 1;
return result;
}

original_code:
static void add_utilization(char usage, const char *name)
{
  int index;
  for (index=0; index<uti_count; index++)
    if (strcmp(name, utit[index].name) == 0)
      if (usage == utit[index].usage)
        break;
  if (index == 4096)
    errx(124, "Utilization table is full");
  if (index < uti_count)
    utit[index].count++;
  else {
    utit[index].usage = usage;
    utit[index].name = xstrdup(name);
    utit[index].count = 1;
    uti_count++;
  }
}

canonical_original_code:
static void add_utilization(char usage, char *name)
{
  int index;
  for (index=0; index<uti_count; index++)
    if (strcmp(name, utit[index].name) == 0)
      if (usage == utit[index].usage)
        break;
  if (index == 4096)
    errx(124, "Utilization table is full");
  if (index < uti_count)
    utit[index].count++;
  else {
    utit[index].usage = usage;
    utit[index].name = xstrdup(name);
    utit[index].count = 1;
    uti_count++;
  }
}


decompiled_code:
int __fastcall del_utilization(char a1, const char *a2)
{
int v2; // er13
__int128 *v3; // rbx
int v4; // ebp
char *v5; // r12
__int64 v6; // rax
__int64 v7; // rbx
__int64 v9; // rax

v2 = uti_count;
if ( uti_count <= 0 )
LABEL_6:
_assert_fail("index < uti_count", "library/hazard.c", 0xCEu, "del_utilization");
v3 = &utit;
v4 = 0;
while ( 1 )
{
v5 = (char *)*((_QWORD *)v3 + 1);
LODWORD(v6) = strcmp(a2, v5);
if ( !(_DWORD)v6 && *(_BYTE *)v3 == a1 )
break;
++v4;
v3 = (__int128 *)((char *)v3 + 24);
if ( v4 == v2 )
goto LABEL_6;
}
v7 = 24LL * v4;
if ( (*(_DWORD *)((char *)&utit + v7 + 16))-- == 1 )
{
free(v5);
uti_count = v2 - 1;
v9 = 3LL * (v2 - 1);
*(__int128 *)((char *)&utit + 24 * v4) = (__int128)_mm_loadu_si128((const __m128i *)((char *)&utit + v9 * 8));
v6 = qword_970[v9];
*(_QWORD *)((char *)&utit + v7 + 16) = v6;
}
return v6;
}

canonical_decompiled_code:
int __fastcall func7(char a1, const char *a2)
{
int v2; // er13
__int128 *v3; // rbx
int v4; // ebp
char *v5; // r12
__int64 v6; // rax
__int64 v7; // rbx
__int64 v9; // rax

v2 = uti_count;
if ( uti_count <= 0 )
LABEL_6:
_assert_fail("index < uti_count", "library/hazard.c", 0xCEu, "del_utilization");
v3 = &utit;
v4 = 0;
while ( 1 )
{
v5 = (char *)*((_QWORD *)v3 + 1);
LODWORD(v6) = strcmp(a2, v5);
if ( !(_DWORD)v6 && *(_BYTE *)v3 == a1 )
break;
++v4;
v3 = (__int128 *)((char *)v3 + 24);
if ( v4 == v2 )
goto LABEL_6;
}
v7 = 24LL * v4;
if ( (*(_DWORD *)((char *)&utit + v7 + 16))-- == 1 )
{
free(v5);
uti_count = v2 - 1;
v9 = 3LL * (v2 - 1);
*(__int128 *)((char *)&utit + 24 * v4) = (__int128)_mm_loadu_si128((const __m128i *)((char *)&utit + v9 * 8));
v6 = qword_970[v9];
*(_QWORD *)((char *)&utit + v7 + 16) = v6;
}
return v6;
}

original_code:
static void del_utilization(char usage, const char *name)
{
  int index;
  for (index=0; index<uti_count; index++)
    if (strcmp(name, utit[index].name) == 0)
      if (usage == utit[index].usage)
        break;
  ((void) sizeof ((index < uti_count) ? 1 : 0), __extension__ ({ if (index < uti_count) ; else __assert_fail ("index < uti_count", "library/hazard.c", 206, __extension__ __PRETTY_FUNCTION__); }));
  if (--utit[index].count == 0) {
    free(utit[index].name);
    utit[index] = utit[--uti_count];
  }
}

canonical_original_code:
static void del_utilization(char usage, char *name)
{
  int index;
  for (index=0; index<uti_count; index++)
    if (strcmp(name, utit[index].name) == 0)
      if (usage == utit[index].usage)
        break;
  ((void) sizeof ((index < uti_count) ? 1 : 0), __extension__ ({ if (index < uti_count) ; else __assert_fail ("index < uti_count", "library/hazard.c", 206, __extension__ __PRETTY_FUNCTION__); }));
  if (--utit[index].count == 0) {
    free(utit[index].name);
    utit[index] = utit[--uti_count];
  }
}


decompiled_code:
__int64 __fastcall validate_job(_QWORD *a1)
{
char v2; // [rsp+7h] [rbp-11h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
_assert_fail("cmd->buffer", "library/hazard.c", 0x113u, "validate_job");
iterate_usage((__int64)a1, 0LL, 0LL);
do
{
if ( !(unsigned __int8)iterate_usage(0LL, &v3, &v2) )
return 1LL;
}
while ( !(unsigned __int8)check_conflict(v2, v3) );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
char v2; // [rsp+7h] [rbp-11h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
_assert_fail("cmd->buffer", "library/hazard.c", 0x113u, "validate_job");
func8((__int64)a1, 0LL, 0LL);
do
{
if ( !(unsigned __int8)func8(0LL, &v3, &v2) )
return 1LL;
}
while ( !(unsigned __int8)func3(v2, v3) );
return 0LL;
}

original_code:
_Bool validate_job(sv *cmd)
{
  char *res, usage;
  ((void) sizeof ((cmd->buffer) ? 1 : 0), __extension__ ({ if (cmd->buffer) ; else __assert_fail ("cmd->buffer", "library/hazard.c", 275, __extension__ __PRETTY_FUNCTION__); }));
  iterate_usage(cmd, ((void *)0), ((void *)0));
  while (iterate_usage(((void *)0), &res, &usage))
    if (check_conflict(usage, res))
      return 0;
  return 1;
}

canonical_original_code:
_Bool validate_job(struct sv *cmd)
{
  char *res; char usage;
  ((void) sizeof ((cmd->buffer) ? 1 : 0), __extension__ ({ if (cmd->buffer) ; else __assert_fail ("cmd->buffer", "library/hazard.c", 275, __extension__ __PRETTY_FUNCTION__); }));
  iterate_usage(cmd, ((void *)0), ((void *)0));
  while (iterate_usage(((void *)0), &res, &usage))
    if (check_conflict(usage, res))
      return 0;
  return 1;
}

variable_types: struct sv { char *buffer; char **svec; } *

variable_types:
res
char *


decompiled_code:
__int64 __fastcall register_job(_QWORD *a1)
{
__int64 result; // rax
char v2; // [rsp+7h] [rbp-11h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
_assert_fail("cmd->buffer", "library/hazard.c", 0x11Fu, "register_job");
iterate_usage((__int64)a1, 0LL, 0LL);
while ( 1 )
{
result = iterate_usage(0LL, &v3, &v2);
if ( !(_BYTE)result )
break;
add_utilization(v2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1)
{
__int64 result; // rax
char v2; // [rsp+7h] [rbp-11h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
_assert_fail("cmd->buffer", "library/hazard.c", 0x11Fu, "register_job");
func8((__int64)a1, 0LL, 0LL);
while ( 1 )
{
result = func8(0LL, &v3, &v2);
if ( !(_BYTE)result )
break;
func6(v2, v3);
}
return result;
}

original_code:
void register_job(sv *cmd)
{
  char *res, usage;
  ((void) sizeof ((cmd->buffer) ? 1 : 0), __extension__ ({ if (cmd->buffer) ; else __assert_fail ("cmd->buffer", "library/hazard.c", 287, __extension__ __PRETTY_FUNCTION__); }));
  iterate_usage(cmd, ((void *)0), ((void *)0));
  while (iterate_usage(((void *)0), &res, &usage))
    add_utilization(usage, res);
}

canonical_original_code:
void register_job(struct sv *cmd)
{
  char *res; char usage;
  ((void) sizeof ((cmd->buffer) ? 1 : 0), __extension__ ({ if (cmd->buffer) ; else __assert_fail ("cmd->buffer", "library/hazard.c", 287, __extension__ __PRETTY_FUNCTION__); }));
  iterate_usage(cmd, ((void *)0), ((void *)0));
  while (iterate_usage(((void *)0), &res, &usage))
    add_utilization(usage, res);
}

user_defined_types: struct sv { char *buffer; char **svec; }


decompiled_code:
__int64 __fastcall unregister_job(_QWORD *a1)
{
__int64 result; // rax
char v2; // [rsp+7h] [rbp-11h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
_assert_fail("cmd->buffer", "library/hazard.c", 0x129u, "unregister_job");
iterate_usage((__int64)a1, 0LL, 0LL);
while ( 1 )
{
result = iterate_usage(0LL, &v3, &v2);
if ( !(_BYTE)result )
break;
del_utilization(v2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
__int64 result; // rax
char v2; // [rsp+7h] [rbp-11h] BYREF
const char *v3; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
_assert_fail("cmd->buffer", "library/hazard.c", 0x129u, "unregister_job");
func8((__int64)a1, 0LL, 0LL);
while ( 1 )
{
result = func8(0LL, &v3, &v2);
if ( !(_BYTE)result )
break;
func7(v2, v3);
}
return result;
}

original_code:
void unregister_job(sv *cmd)
{
  char *res, usage;
  ((void) sizeof ((cmd->buffer) ? 1 : 0), __extension__ ({ if (cmd->buffer) ; else __assert_fail ("cmd->buffer", "library/hazard.c", 297, __extension__ __PRETTY_FUNCTION__); }));
  iterate_usage(cmd, ((void *)0), ((void *)0));
  while (iterate_usage(((void *)0), &res, &usage))
    del_utilization(usage, res);
}

canonical_original_code:
void unregister_job(struct sv *cmd)
{
  char *res; char usage;
  ((void) sizeof ((cmd->buffer) ? 1 : 0), __extension__ ({ if (cmd->buffer) ; else __assert_fail ("cmd->buffer", "library/hazard.c", 297, __extension__ __PRETTY_FUNCTION__); }));
  iterate_usage(cmd, ((void *)0), ((void *)0));
  while (iterate_usage(((void *)0), &res, &usage))
    del_utilization(usage, res);
}


decompiled_code:
unsigned __int64 __fastcall jiffy_to_sec(unsigned __int64 a1)
{
if ( !clk_tck_1 )
clk_tck_1 = sysconf(2);
return a1 / clk_tck_1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int64 a1)
{
if ( !clk_tck_1 )
clk_tck_1 = sysconf(2);
return a1 / clk_tck_1;
}

original_code:
static time_t jiffy_to_sec(unsigned long long jiffy)
{
  static unsigned long long clk_tck;
  if (clk_tck == 0)
    clk_tck = sysconf(_SC_CLK_TCK);
  return jiffy/clk_tck;
}

canonical_original_code:
static long jiffy_to_sec(unsigned long long jiffy)
{
  static unsigned long long clk_tck;
  if (clk_tck == 0)
    clk_tck = sysconf(_SC_CLK_TCK);
  return jiffy/clk_tck;
}

variable_types:
jiffy
unsigned long long


decompiled_code:
__int64 __fastcall proc_stat(unsigned int a1, __int64 a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12
char *v5; // rax
__int64 result; // rax
__int64 v7; // rbp
unsigned __int64 v8; // rbp
unsigned __int64 v9; // [rsp+8h] [rbp-450h] BYREF
char s[48]; // [rsp+10h] [rbp-448h] BYREF
char buf[1048]; // [rsp+40h] [rbp-418h] BYREF

snprintf(s, 0x28uLL, "/proc/%d/stat", a1);
v2 = open(s, 0);
if ( v2 < 0 )
return 0LL;
v3 = v2;
v4 = read(v2, buf, 0x3FFuLL);
close(v3);
if ( v4 < 0 )
return 0LL;
buf[v4] = 0;
v5 = strrchr(buf, 41);
if ( sscanf(
v5 + 2,
"%c %d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %lu %*lu %*ld %*ld %*ld %*ld %*ld %*ld %llu",
a2,
a2 + 4,
a2 + 8,
&v9) != 4 )
return 0LL;
*(_QWORD *)(a2 + 8) = jiffy_to_sec(*(_QWORD *)(a2 + 8));
v7 = boot_time();
v8 = jiffy_to_sec(v9) + v7;
result = 1LL;
*(_QWORD *)(a2 + 16) = v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12
char *v5; // rax
__int64 result; // rax
__int64 v7; // rbp
unsigned __int64 v8; // rbp
unsigned __int64 v9; // [rsp+8h] [rbp-450h] BYREF
char s[48]; // [rsp+10h] [rbp-448h] BYREF
char buf[1048]; // [rsp+40h] [rbp-418h] BYREF

snprintf(s, 0x28uLL, "/proc/%d/stat", a1);
v2 = open(s, 0);
if ( v2 < 0 )
return 0LL;
v3 = v2;
v4 = read(v2, buf, 0x3FFuLL);
close(v3);
if ( v4 < 0 )
return 0LL;
buf[v4] = 0;
v5 = strrchr(buf, 41);
if ( sscanf(
v5 + 2,
"%c %d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %lu %*lu %*ld %*ld %*ld %*ld %*ld %*ld %llu",
a2,
a2 + 4,
a2 + 8,
&v9) != 4 )
return 0LL;
*(_QWORD *)(a2 + 8) = func1(*(_QWORD *)(a2 + 8));
v7 = func0();
v8 = func1(v9) + v7;
result = 1LL;
*(_QWORD *)(a2 + 16) = v8;
return result;
}

original_code:
_Bool proc_stat(pid_t pid, proc *pptr)
{
  unsigned long long start_jiffies;
  char path[40], buffer[1024], *start;
  int stat_fd, num;
  snprintf(path, sizeof (path), "/proc/%d/stat", pid);
  stat_fd = open(path, 00);
  if (stat_fd < 0) return 0;
  num = read(stat_fd, buffer, sizeof (buffer)-1);
  close(stat_fd);
  if (num < 0) return 0;
  buffer[num] = '\0';
  start = strrchr(buffer, ')')+2;
  if (start == ((void *)0)) return 0;
  num = sscanf(start,
               "%c "
               "%d %*d %*d %*d %*d "
               "%*u %*lu %*lu %*lu %*lu "
               "%lu %*lu %*ld %*ld "
               "%*ld %*ld %*ld %*ld "
               "%llu",
               &(pptr->state),
               &(pptr->ppid),
               &(pptr->utime),
               &start_jiffies);
  if (num != 4) return 0;
  pptr->utime = jiffy_to_sec(pptr->utime);
  pptr->start_time = boot_time() + jiffy_to_sec(start_jiffies);
  return 1;
}

canonical_original_code:
_Bool proc_stat(int pid, struct proc *pptr)
{
  unsigned long long start_jiffies;
  char path[40]; char buffer[1024]; char *start;
  int stat_fd; int num;
  snprintf(path, sizeof (path), "/proc/%d/stat", pid);
  stat_fd = open(path, 00);
  if (stat_fd < 0) return 0;
  num = read(stat_fd, buffer, sizeof (buffer)-1);
  close(stat_fd);
  if (num < 0) return 0;
  buffer[num] = '\0';
  start = strrchr(buffer, ')')+2;
  if (start == ((void *)0)) return 0;
  num = sscanf(start,
               "%c "
               "%d %*d %*d %*d %*d "
               "%*u %*lu %*lu %*lu %*lu "
               "%lu %*lu %*ld %*ld "
               "%*ld %*ld %*ld %*ld "
               "%llu",
               &(pptr->state),
               &(pptr->ppid),
               &(pptr->utime),
               &start_jiffies);
  if (num != 4) return 0;
  pptr->utime = jiffy_to_sec(pptr->utime);
  pptr->start_time = boot_time() + jiffy_to_sec(start_jiffies);
  return 1;
}

variable_types: pid int

variable_types: struct proc { char state; int ppid; unsigned long utime; long start_time; } *

variable_types:
path
char [40]

variable_types:
buffer
char [1024]

variable_types:
start
char *

variable_types: num int


decompiled_code:
const char *__fastcall time_string(unsigned __int64 a1)
{
if ( a1 > 0x176F )
return "99:59+";
sprintf(buffer_0, "%2lu:%02lu ", a1 / 0x3C, a1 % 0x3C);
return buffer_0;
}

canonical_decompiled_code:
const char *__fastcall func3(unsigned __int64 a1)
{
if ( a1 > 0x176F )
return "99:59+";
sprintf(buffer_0, "%2lu:%02lu ", a1 / 0x3C, a1 % 0x3C);
return buffer_0;
}

original_code:
char *time_string(unsigned long seconds)
{
  static char buffer[10];
  unsigned long minutes;
  minutes = seconds / 60;
  seconds %= 60;
  if (minutes > 99)
    return "99:59+";
  sprintf(buffer, "%2lu:%02lu ", minutes, seconds);
  return buffer;
}

variable_types:
seconds
unsigned long

variable_types:
buffer
char [10]

variable_types:
minutes
unsigned long

return_type: char *


decompiled_code:
__int64 __fastcall read_block(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rdx
unsigned int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = 0;
readn(a1, v5, 4LL);
result = v5[0];
if ( v5[0] )
{
v3 = xmalloc((int)v5[0]);
v4 = (int)v5[0];
*a2 = v3;
readn((unsigned int)a1, v3, v4);
result = (int)v5[0];
if ( *(_BYTE *)(*a2 + (int)v5[0] - 1) )
{
warnx("read_block: input is not null-terminated");
result = 4294967294LL;
}
}
else
{
*a2 = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rdx
unsigned int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = 0;
readn(a1, v5, 4LL);
result = v5[0];
if ( v5[0] )
{
v3 = xmalloc((int)v5[0]);
v4 = (int)v5[0];
*a2 = v3;
readn((unsigned int)a1, v3, v4);
result = (int)v5[0];
if ( *(_BYTE *)(*a2 + (int)v5[0] - 1) )
{
warnx("read_block: input is not null-terminated");
result = 4294967294LL;
}
}
else
{
*a2 = 0LL;
}
return result;
}

original_code:
static int read_block(int fd, char **buffer)
{
  int size = 0;
  readn(fd, &size, sizeof (int));
  if (size == 0) {
    *buffer = ((void *)0);
    return 0;
  }
  *buffer = xmalloc(size);
  readn(fd, *buffer, size);
  if ((*buffer)[size-1]) {
    warnx("read_block: input is not null-terminated");
    return -2;
  }
  return size;
}

variable_types: fd int

variable_types:
buffer
char **

variable_types: size int


decompiled_code:
__int64 __fastcall read_sv(__int64 a1, __int64 *a2)
{
__int64 result; // rax
unsigned int v3; // [rsp+Ch] [rbp-2Ch]
int v4[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

readn(a1, v4, 4LL);
++v4[0];
a2[1] = xmalloc(8LL * v4[0]);
result = read_block((unsigned int)a1, a2);
if ( (int)result > 0 )
{
v3 = result;
unpack_svec_isra_0(a2, result);
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 *a2)
{
__int64 result; // rax
unsigned int v3; // [rsp+Ch] [rbp-2Ch]
int v4[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

readn(a1, v4, 4LL);
++v4[0];
a2[1] = xmalloc(8LL * v4[0]);
result = func0((unsigned int)a1, a2);
if ( (int)result > 0 )
{
v3 = result;
func1(a2, result);
result = v3;
}
return result;
}

original_code:
int read_sv(int fd, sv *sv)
{
  int size, count;
  readn(fd, &count, sizeof (int));
  sv->svec = xmalloc(++count * sizeof (char *));
  size = read_block(fd, &(sv->buffer));
  if (size > 0) unpack_svec(sv, size);
  return size;
}

canonical_original_code:
int read_sv(int fd, struct sv *sv)
{
  int size; int count;
  readn(fd, &count, sizeof (int));
  sv->svec = xmalloc(++count * sizeof (char *));
  size = read_block(fd, &(sv->buffer));
  if (size > 0) unpack_svec(sv, size);
  return size;
}

variable_types: count int


decompiled_code:
__int64 __fastcall write_string(unsigned int a1, const char *a2)
{
__int64 v2; // r12

v2 = (unsigned int)strlen(a2) + 1;
write_int(a1, v2);
writen(a1, a2, (int)v2);
return (unsigned int)v2;
}

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

v2 = (unsigned int)strlen(a2) + 1;
write_int(a1, v2);
writen(a1, a2, (int)v2);
return (unsigned int)v2;
}

original_code:
int write_string(int fd, const char buffer[])
{
  int size;
  size = strlen(buffer)+1;
  write_int(fd, size);
  writen(fd, buffer, size);
  return size;
}

canonical_original_code:
int write_string(int fd, char buffer[])
{
  int size;
  size = strlen(buffer)+1;
  write_int(fd, size);
  writen(fd, buffer, size);
  return size;
}

variable_types:
buffer
char []


decompiled_code:
__int64 __fastcall write_sv(unsigned int a1, const char **a2)
{
const char *v4; // rdi
__int64 v5; // rbp
unsigned int v6; // er13
int v7; // eax
__int64 v8; // rsi
const char *v9; // rbp
const char **v10; // rbx
size_t v11; // rax

v4 = *a2;
if ( *a2 )
{
v5 = 1LL;
v6 = 0;
do
{
v7 = strlen(v4);
v8 = (unsigned int)v5++;
v4 = a2[v5 - 1];
v6 += v7 + 1;
}
while ( v4 );
}
else
{
v6 = 0;
v8 = 0LL;
}
write_int(a1, v8);
write_int(a1, v6);
v9 = *a2;
if ( *a2 )
{
v10 = a2 + 1;
do
{
++v10;
v11 = strlen(v9);
writen(a1, v9, v11 + 1);
v9 = *(v10 - 1);
}
while ( v9 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, const char **a2)
{
const char *v4; // rdi
__int64 v5; // rbp
unsigned int v6; // er13
int v7; // eax
__int64 v8; // rsi
const char *v9; // rbp
const char **v10; // rbx
size_t v11; // rax

v4 = *a2;
if ( *a2 )
{
v5 = 1LL;
v6 = 0;
do
{
v7 = strlen(v4);
v8 = (unsigned int)v5++;
v4 = a2[v5 - 1];
v6 += v7 + 1;
}
while ( v4 );
}
else
{
v6 = 0;
v8 = 0LL;
}
write_int(a1, v8);
write_int(a1, v6);
v9 = *a2;
if ( *a2 )
{
v10 = a2 + 1;
do
{
++v10;
v11 = strlen(v9);
writen(a1, v9, v11 + 1);
v9 = *(v10 - 1);
}
while ( v9 );
}
return 0LL;
}

original_code:
int write_sv(int fd, char *const svec[])
{
  int index, size;
  for (index=0, size=0; svec[index]; index++, size++)
    size += strlen(svec[index]);
  write_int(fd, index);
  write_int(fd, size);
  for (index=0; svec[index]; index++)
    writen(fd, svec[index], strlen(svec[index])+1);
  return 0;
}

canonical_original_code:
int write_sv(int fd, char *svec[])
{
  int index; int size;
  for (index=0, size=0; svec[index]; index++, size++)
    size += strlen(svec[index]);
  write_int(fd, index);
  write_int(fd, size);
  for (index=0; svec[index]; index++)
    writen(fd, svec[index], strlen(svec[index])+1);
  return 0;
}

variable_types:
svec
char *[]

variable_types: index int


decompiled_code:
__int64 __fastcall read_job(__int64 a1, __int64 *a2)
{
readn(a1, a2 + 4, 4LL);
read_sv((unsigned int)a1, a2);
return read_sv((unsigned int)a1, a2 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 *a2)
{
readn(a1, a2 + 4, 4LL);
func2((unsigned int)a1, a2);
return func2((unsigned int)a1, a2 + 2);
}

original_code:
void read_job(int fd, job *job)
{
  readn(fd, &(job->cwd), sizeof (int));
  read_sv(fd, &(job->cmd));
  read_sv(fd, &(job->env));
}

canonical_original_code:
void read_job(int fd, struct job *job)
{
  readn(fd, &(job->cwd), sizeof (int));
  read_sv(fd, &(job->cmd));
  read_sv(fd, &(job->env));
}

variable_types: struct job { struct sv { char *buffer; char **svec; } cmd; int cwd; } *


decompiled_code:
__int64 __fastcall write_job(__int64 a1, __int64 a2)
{
write_int(a1, *(unsigned int *)(a2 + 32));
write_sv(a1, *(const char ***)(a2 + 8));
return write_sv(a1, *(const char ***)(a2 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
write_int(a1, *(unsigned int *)(a2 + 32));
func4(a1, *(const char ***)(a2 + 8));
return func4(a1, *(const char ***)(a2 + 24));
}

original_code:
void write_job(int fd, const job *job)
{
  write_int(fd, job->cwd);
  write_sv(fd, job->cmd.svec);
  write_sv(fd, job->env.svec);
}

canonical_original_code:
void write_job(int fd, struct job *job)
{
  write_int(fd, job->cwd);
  write_sv(fd, job->cmd.svec);
  write_sv(fd, job->env.svec);
}


xmalloc

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

result = malloc(a1);
if ( a1 )
{
if ( !result )
errx(100, "Memory allocation failure (%u bytes)", a1);
}
return result;
}

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

result = malloc(a1);
if ( a1 )
{
if ( !result )
errx(100, "Memory allocation failure (%u bytes)", a1);
}
return result;
}

original_code:
void *xmalloc(size_t size)
{
  void *ptr = malloc(size);
  if (size > 0 && ptr == ((void *)0))
    errx(100, "Memory allocation failure (%u bytes)", size);
  return ptr;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
  void *ptr = malloc(size);
  if (size > 0 && ptr == ((void *)0))
    errx(100, "Memory allocation failure (%u bytes)", size);
  return ptr;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *

return_type: void *


decompiled_code:
char *__fastcall path_join(char *src, char *a2)
{
int v2; // ebx
int v3; // eax
char *v4; // r12
__int64 v5; // rdi

if ( !src || !a2 )
errx(101, "NULL argument in path_join");
if ( *src != 47 )
errx(102, "Relative path argument 1 in path_join");
if ( strchr(a2, 47) )
errx(103, "Relative path argument 2 in path_join");
v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)xmalloc(v2 + v3 + 2);
strcpy(v4, src);
v5 = v2;
if ( v4[v2 - 1] != 47 )
{
v4[v2] = 47;
v5 = v2 + 1;
}
strcpy(&v4[v5], a2);
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(char *src, char *a2)
{
int v2; // ebx
int v3; // eax
char *v4; // r12
__int64 v5; // rdi

if ( !src || !a2 )
errx(101, "NULL argument in path_join");
if ( *src != 47 )
errx(102, "Relative path argument 1 in path_join");
if ( strchr(a2, 47) )
errx(103, "Relative path argument 2 in path_join");
v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)func0(v2 + v3 + 2);
strcpy(v4, src);
v5 = v2;
if ( v4[v2 - 1] != 47 )
{
v4[v2] = 47;
v5 = v2 + 1;
}
strcpy(&v4[v5], a2);
return v4;
}

original_code:
char *path_join(const char *path, const char *name)
{
  int path_len, name_len;
  char *pathname;
  if (path == ((void *)0) || name == ((void *)0))
    errx(101, "NULL argument in path_join");
  if (path[0] != '/')
    errx(102, "Relative path argument 1 in path_join");
  if (strchr(name, '/'))
    errx(103, "Relative path argument 2 in path_join");
  path_len = strlen(path);
  name_len = strlen(name);
  pathname = xmalloc(path_len+name_len+2);
  strcpy(pathname, path);
  if (pathname[path_len-1] != '/')
    pathname[path_len++] = '/';
  strcpy(pathname+path_len, name);
  return pathname;
}

canonical_original_code:
char *path_join(char *path, char *name)
{
  int path_len; int name_len;
  char *pathname;
  if (path == ((void *)0) || name == ((void *)0))
    errx(101, "NULL argument in path_join");
  if (path[0] != '/')
    errx(102, "Relative path argument 1 in path_join");
  if (strchr(name, '/'))
    errx(103, "Relative path argument 2 in path_join");
  path_len = strlen(path);
  name_len = strlen(name);
  pathname = xmalloc(path_len+name_len+2);
  strcpy(pathname, path);
  if (pathname[path_len-1] != '/')
    pathname[path_len++] = '/';
  strcpy(pathname+path_len, name);
  return pathname;
}

variable_types:
path
char *

variable_types:
name
char *

variable_types:
pathname
char *


xstrdup

decompiled_code:
char *__fastcall xstrdup(const char *a1)
{
char *result; // rax

result = strdup(a1);
if ( !result )
err(104, "strdup");
return result;
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1)
{
char *result; // rax

result = strdup(a1);
if ( !result )
err(104, "strdup");
return result;
}

original_code:
char *xstrdup(const char *s)
{
  char *dup = strdup(s);
  if (dup == ((void *)0)) err(104, "strdup");
  return dup;
}

canonical_original_code:
char *xstrdup(char *s)
{
  char *dup = strdup(s);
  if (dup == ((void *)0)) err(104, "strdup");
  return dup;
}

variable_types:
s
char *

variable_types:
dup
char *


decompiled_code:
void __fastcall release_sv(void **a1)
{
free(*a1);
free(a1[1]);
*a1 = 0LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(void **a1)
{
free(*a1);
free(a1[1]);
*a1 = 0LL;
a1[1] = 0LL;
}

original_code:
void release_sv(sv *sv)
{
  free(sv->buffer);
  free(sv->svec);
  sv->buffer = ((void *)0);
  sv->svec = ((void *)0);
}

canonical_original_code:
void release_sv(struct sv *sv)
{
  free(sv->buffer);
  free(sv->svec);
  sv->buffer = ((void *)0);
  sv->svec = ((void *)0);
}

variable_types: struct sv { char *buffer; char **svec; } *


decompiled_code:
void __fastcall release_job(void **a1)
{
release_sv(a1);
release_sv(a1 + 2);
}

canonical_decompiled_code:
void __fastcall func4(void **a1)
{
func3(a1);
func3(a1 + 2);
}

original_code:
void release_job(job *job)
{
  release_sv(&(job->cmd));
  release_sv(&(job->env));
}

canonical_original_code:
void release_job(struct job *job)
{
  release_sv(&(job->cmd));
  release_sv(&(job->env));
}


decompiled_code:
void __fastcall flatten_sv(__int64 a1)
{
_BYTE *v1; // rax
_BYTE **v2; // rdx
_BYTE *v3; // rdx
__int64 v4; // rsi

v1 = *(_BYTE **)a1;
if ( !*(_QWORD *)a1 || (v2 = *(_BYTE ***)(a1 + 8)) == 0LL )
_assert_fail("sv->buffer != NULL && sv->svec != NULL", "library/buffer.c", 0x54u, "flatten_sv");
v3 = *v2;
if ( v1 != v3 )
_assert_fail("sv->svec[0] == sv->buffer", "library/buffer.c", 0x55u, "flatten_sv");
v4 = 8LL;
while ( 1 )
{
while ( *v3 )
*v1++ = *v3++;
*v1 = 32;
v3 = *(_BYTE **)(*(_QWORD *)(a1 + 8) + v4);
v4 += 8LL;
if ( !v3 )
break;
++v1;
}
*v1 = 0;
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void flatten_sv(sv *sv)
{
  char *vp, *bp;
  int index;
  ((void) sizeof ((sv->buffer != ((void *)0) && sv->svec != ((void *)0)) ? 1 : 0), __extension__ ({ if (sv->buffer != ((void *)0) && sv->svec != ((void *)0)) ; else __assert_fail ("sv->buffer != NULL && sv->svec != NULL", "library/buffer.c", 84, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((sv->svec[0] == sv->buffer) ? 1 : 0), __extension__ ({ if (sv->svec[0] == sv->buffer) ; else __assert_fail ("sv->svec[0] == sv->buffer", "library/buffer.c", 85, __extension__ __PRETTY_FUNCTION__); }));
  for (index=0, bp=sv->buffer; sv->svec[index]; index++) {
    vp = sv->svec[index];
    while (*vp) *(bp++) = *(vp++);
    *(bp++) = ' ';
  }
  *(--bp) = '\0';
  free(sv->svec);
  sv->svec = ((void *)0);
}

canonical_original_code:
void flatten_sv(struct sv *sv)
{
  char *vp; char *bp;
  int index;
  ((void) sizeof ((sv->buffer != ((void *)0) && sv->svec != ((void *)0)) ? 1 : 0), __extension__ ({ if (sv->buffer != ((void *)0) && sv->svec != ((void *)0)) ; else __assert_fail ("sv->buffer != NULL && sv->svec != NULL", "library/buffer.c", 84, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((sv->svec[0] == sv->buffer) ? 1 : 0), __extension__ ({ if (sv->svec[0] == sv->buffer) ; else __assert_fail ("sv->svec[0] == sv->buffer", "library/buffer.c", 85, __extension__ __PRETTY_FUNCTION__); }));
  for (index=0, bp=sv->buffer; sv->svec[index]; index++) {
    vp = sv->svec[index];
    while (*vp) *(bp++) = *(vp++);
    *(bp++) = ' ';
  }
  *(--bp) = '\0';
  free(sv->svec);
  sv->svec = ((void *)0);
}

variable_types:
vp
char *

variable_types:
bp
char *


repo: cknadler/marktab-c

original_code:
static size_t utf8_length(const char* utf8_data) {
   size_t i = 0, j = 0;
   while (utf8_data[i]) {
     if ((utf8_data[i] & 0xC0) != 0x80) j++;
     i++;
   }
   return j;
}

canonical_original_code:
static unsigned long utf8_length(char *utf8_data) {
   unsigned long i = 0; unsigned long j = 0;
   while (utf8_data[i]) {
     if ((utf8_data[i] & 0xC0) != 0x80) j++;
     i++;
   }
   return j;
}

variable_types:
i
unsigned long

variable_types:
j
unsigned long

return_type: unsigned long


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

result = malloc(0x20uLL);
if ( !result )
_assert_fail("string != NULL", "src/mt_string.c", 0x16u, "mt_string_new");
*result = 0LL;
result[1] = 0LL;
result[3] = 0LL;
return result;
}

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

result = malloc(0x20uLL);
if ( !result )
_assert_fail("string != NULL", "src/mt_string.c", 0x16u, "mt_string_new");
*result = 0LL;
result[1] = 0LL;
result[3] = 0LL;
return result;
}

original_code:
MtString* mt_string_new()
{
  MtString* const string = ((MtString *) malloc(sizeof(MtString)));
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 22, __extension__ __PRETTY_FUNCTION__); }));
  string->utf8_data = ((void *)0);
  string->size = 0;
  string->hash = 0;
  return string;
}

canonical_original_code:
struct MtString *mt_string_new()
{
  struct MtString *string = ((MtString *) malloc(sizeof(MtString)));
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 22, __extension__ __PRETTY_FUNCTION__); }));
  string->utf8_data = ((void *)0);
  string->size = 0;
  string->hash = 0;
  return string;
}

variable_types: struct MtString { char *utf8_data; unsigned long size; unsigned long length; unsigned long hash; } *


decompiled_code:
void *__fastcall mt_string_set_utf8(__int64 a1, char *a2)
{
size_t v3; // rax
size_t v4; // r12
size_t v5; // r13
__int64 v6; // rax
void *v7; // rdi
size_t v8; // rdx
void *result; // rax

if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0x68u, "mt_string_set_utf8");
if ( !a2 )
_assert_fail("utf8_data != NULL", "src/mt_string.c", 0x69u, "mt_string_set_utf8");
v3 = strlen(a2);
v4 = v3;
v5 = v3 + 1;
if ( *(_QWORD *)(a1 + 8) < v3 + 1 )
*(_QWORD *)a1 = realloc(*(void **)a1, v3 + 1);
*(_QWORD *)(a1 + 8) = v5;
v6 = utf8_length(a2);
v7 = *(void **)a1;
*(_QWORD *)(a1 + 16) = v6;
memcpy(v7, a2, v8);
result = *(void **)a1;
if ( *(_BYTE *)(*(_QWORD *)a1 + v4) )
_assert_fail("string->utf8_data[size] == '\\0'", "src/mt_string.c", 0x7Bu, "mt_string_set_utf8");
*(_QWORD *)(a1 + 24) = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, char *a2)
{
size_t v3; // rax
size_t v4; // r12
size_t v5; // r13
__int64 v6; // rax
void *v7; // rdi
size_t v8; // rdx
void *result; // rax

if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0x68u, "mt_string_set_utf8");
if ( !a2 )
_assert_fail("utf8_data != NULL", "src/mt_string.c", 0x69u, "mt_string_set_utf8");
v3 = strlen(a2);
v4 = v3;
v5 = v3 + 1;
if ( *(_QWORD *)(a1 + 8) < v3 + 1 )
*(_QWORD *)a1 = realloc(*(void **)a1, v3 + 1);
*(_QWORD *)(a1 + 8) = v5;
v6 = func0(a2);
v7 = *(void **)a1;
*(_QWORD *)(a1 + 16) = v6;
memcpy(v7, a2, v8);
result = *(void **)a1;
if ( *(_BYTE *)(*(_QWORD *)a1 + v4) )
_assert_fail("string->utf8_data[size] == '\\0'", "src/mt_string.c", 0x7Bu, "mt_string_set_utf8");
*(_QWORD *)(a1 + 24) = 0LL;
return result;
}

original_code:
void mt_string_set_utf8(MtString* string, const char* utf8_data)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 104, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((utf8_data != ((void *)0)) ? 1 : 0), __extension__ ({ if (utf8_data != ((void *)0)) ; else __assert_fail ("utf8_data != NULL", "src/mt_string.c", 105, __extension__ __PRETTY_FUNCTION__); }));
  size_t size = strlen(utf8_data);
  ((void) sizeof ((utf8_data[size] == '\0') ? 1 : 0), __extension__ ({ if (utf8_data[size] == '\0') ; else __assert_fail ("utf8_data[size] == '\\0'", "src/mt_string.c", 110, __extension__ __PRETTY_FUNCTION__); }));
  if (string->size < size + 1)
    string->utf8_data = realloc(string->utf8_data, size + 1);
  string->size = size + 1;
  string->length = utf8_length(utf8_data);
  memcpy(string->utf8_data, utf8_data, size + 1);
  ((void) sizeof ((string->utf8_data[size] == '\0') ? 1 : 0), __extension__ ({ if (string->utf8_data[size] == '\0') ; else __assert_fail ("string->utf8_data[size] == '\\0'", "src/mt_string.c", 123, __extension__ __PRETTY_FUNCTION__); }));
  string->hash = 0;
}

canonical_original_code:
void mt_string_set_utf8(struct MtString *string, char *utf8_data)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 104, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((utf8_data != ((void *)0)) ? 1 : 0), __extension__ ({ if (utf8_data != ((void *)0)) ; else __assert_fail ("utf8_data != NULL", "src/mt_string.c", 105, __extension__ __PRETTY_FUNCTION__); }));
  unsigned long size = strlen(utf8_data);
  ((void) sizeof ((utf8_data[size] == '\0') ? 1 : 0), __extension__ ({ if (utf8_data[size] == '\0') ; else __assert_fail ("utf8_data[size] == '\\0'", "src/mt_string.c", 110, __extension__ __PRETTY_FUNCTION__); }));
  if (string->size < size + 1)
    string->utf8_data = realloc(string->utf8_data, size + 1);
  string->size = size + 1;
  string->length = utf8_length(utf8_data);
  memcpy(string->utf8_data, utf8_data, size + 1);
  ((void) sizeof ((string->utf8_data[size] == '\0') ? 1 : 0), __extension__ ({ if (string->utf8_data[size] == '\0') ; else __assert_fail ("string->utf8_data[size] == '\\0'", "src/mt_string.c", 123, __extension__ __PRETTY_FUNCTION__); }));
  string->hash = 0;
}

user_defined_types: struct MtString { char *utf8_data; unsigned long size; unsigned long length; unsigned long hash; }


decompiled_code:
char **__fastcall mt_string_new_from_integer(unsigned int a1)
{
char **v1; // r12

v1 = (char **)mt_string_new_from_utf8(" ");
sprintf(*v1, "%d", a1);
v1[2] = (char *)utf8_length(*v1);
return v1;
}

canonical_decompiled_code:
char **__fastcall func3(unsigned int a1)
{
char **v1; // r12

v1 = (char **)mt_string_new_from_utf8(" ");
sprintf(*v1, "%d", a1);
v1[2] = (char *)func0(*v1);
return v1;
}

original_code:
MtString* mt_string_new_from_integer(int integer)
{
  MtString* string = mt_string_new_from_utf8("               ");
  sprintf(string->utf8_data,"%d", integer);
  string->length = utf8_length(string->utf8_data);
  return string;
}

canonical_original_code:
struct MtString *mt_string_new_from_integer(int integer)
{
  struct MtString *string = mt_string_new_from_utf8("               ");
  sprintf(string->utf8_data,"%d", integer);
  string->length = utf8_length(string->utf8_data);
  return string;
}

variable_types: integer int

return_type: struct MtString { char *utf8_data; unsigned long size; unsigned long length; unsigned long hash; } *


decompiled_code:
char **__fastcall mt_string_new_from_real(double a1)
{
char **v1; // r12

v1 = (char **)mt_string_new_from_utf8(" ");
sprintf(*v1, "%lg", a1);
v1[2] = (char *)utf8_length(*v1);
return v1;
}

canonical_decompiled_code:
char **__fastcall func4(double a1)
{
char **v1; // r12

v1 = (char **)mt_string_new_from_utf8(" ");
sprintf(*v1, "%lg", a1);
v1[2] = (char *)func0(*v1);
return v1;
}

original_code:
MtString* mt_string_new_from_real(double real)
{
  MtString* string = mt_string_new_from_utf8("               ");
  sprintf(string->utf8_data, "%lg", real);
  string->length = utf8_length(string->utf8_data);
  return string;
}

canonical_original_code:
struct MtString *mt_string_new_from_real(double real)
{
  struct MtString *string = mt_string_new_from_utf8("               ");
  sprintf(string->utf8_data, "%lg", real);
  string->length = utf8_length(string->utf8_data);
  return string;
}

variable_types: real double


decompiled_code:
size_t __fastcall mt_string_cat_utf8(__int64 a1, char *a2)
{
size_t v3; // rax
size_t v4; // rdx
size_t v5; // r12
size_t v6; // rsi
__int64 v7; // rdx
_BYTE *v8; // rdx
size_t result; // rax

if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0x90u, "mt_string_cat_utf8");
if ( !a2 )
_assert_fail("utf8_data != NULL", "src/mt_string.c", 0x91u, "mt_string_cat_utf8");
v3 = strlen(a2);
v4 = *(_QWORD *)(a1 + 8);
v5 = v3;
v6 = v3 + v4 + 1;
if ( v4 < v6 )
*(_QWORD *)a1 = realloc(*(void **)a1, v6);
*(_QWORD *)(a1 + 16) += utf8_length(a2);
memcpy((void *)(v7 + *(_QWORD *)a1), a2, v5 + 1);
v8 = *(_BYTE **)a1;
result = v5 + *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = result;
if ( v8[result] )
_assert_fail("string->utf8_data[string->size] == '\\0'", "src/mt_string.c", 0xA4u, "mt_string_cat_utf8");
*(_QWORD *)(a1 + 24) = 0LL;
return result;
}

canonical_decompiled_code:
size_t __fastcall func6(__int64 a1, char *a2)
{
size_t v3; // rax
size_t v4; // rdx
size_t v5; // r12
size_t v6; // rsi
__int64 v7; // rdx
_BYTE *v8; // rdx
size_t result; // rax

if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0x90u, "mt_string_cat_utf8");
if ( !a2 )
_assert_fail("utf8_data != NULL", "src/mt_string.c", 0x91u, "mt_string_cat_utf8");
v3 = strlen(a2);
v4 = *(_QWORD *)(a1 + 8);
v5 = v3;
v6 = v3 + v4 + 1;
if ( v4 < v6 )
*(_QWORD *)a1 = realloc(*(void **)a1, v6);
*(_QWORD *)(a1 + 16) += func0(a2);
memcpy((void *)(v7 + *(_QWORD *)a1), a2, v5 + 1);
v8 = *(_BYTE **)a1;
result = v5 + *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = result;
if ( v8[result] )
_assert_fail("string->utf8_data[string->size] == '\\0'", "src/mt_string.c", 0xA4u, "mt_string_cat_utf8");
*(_QWORD *)(a1 + 24) = 0LL;
return result;
}

original_code:
void mt_string_cat_utf8(MtString* string, const char* utf8_data)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 144, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((utf8_data != ((void *)0)) ? 1 : 0), __extension__ ({ if (utf8_data != ((void *)0)) ; else __assert_fail ("utf8_data != NULL", "src/mt_string.c", 145, __extension__ __PRETTY_FUNCTION__); }));
  size_t size = strlen(utf8_data);
  ((void) sizeof ((utf8_data[size] == '\0') ? 1 : 0), __extension__ ({ if (utf8_data[size] == '\0') ; else __assert_fail ("utf8_data[size] == '\\0'", "src/mt_string.c", 150, __extension__ __PRETTY_FUNCTION__); }));
  if (string->size < string->size + size + 1)
    string->utf8_data = realloc(string->utf8_data, string->size + size + 1);
  string->length += utf8_length(utf8_data);
  memcpy(string->utf8_data + string->size, utf8_data, size + 1);
  string->size = string->size + size;
  ((void) sizeof ((string->utf8_data[string->size] == '\0') ? 1 : 0), __extension__ ({ if (string->utf8_data[string->size] == '\0') ; else __assert_fail ("string->utf8_data[string->size] == '\\0'", "src/mt_string.c", 164, __extension__ __PRETTY_FUNCTION__); }));
  string->hash = 0;
}

canonical_original_code:
void mt_string_cat_utf8(struct MtString *string, char *utf8_data)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 144, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((utf8_data != ((void *)0)) ? 1 : 0), __extension__ ({ if (utf8_data != ((void *)0)) ; else __assert_fail ("utf8_data != NULL", "src/mt_string.c", 145, __extension__ __PRETTY_FUNCTION__); }));
  unsigned long size = strlen(utf8_data);
  ((void) sizeof ((utf8_data[size] == '\0') ? 1 : 0), __extension__ ({ if (utf8_data[size] == '\0') ; else __assert_fail ("utf8_data[size] == '\\0'", "src/mt_string.c", 150, __extension__ __PRETTY_FUNCTION__); }));
  if (string->size < string->size + size + 1)
    string->utf8_data = realloc(string->utf8_data, string->size + size + 1);
  string->length += utf8_length(utf8_data);
  memcpy(string->utf8_data + string->size, utf8_data, size + 1);
  string->size = string->size + size;
  ((void) sizeof ((string->utf8_data[string->size] == '\0') ? 1 : 0), __extension__ ({ if (string->utf8_data[string->size] == '\0') ; else __assert_fail ("string->utf8_data[string->size] == '\\0'", "src/mt_string.c", 164, __extension__ __PRETTY_FUNCTION__); }));
  string->hash = 0;
}


decompiled_code:
size_t __fastcall mt_string_cat(__int64 a1, char **a2)
{
size_t result; // rax

if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0x83u, "mt_string_cat");
if ( !a2 )
_assert_fail("src != NULL", "src/mt_string.c", 0x84u, "mt_string_cat");
result = mt_string_cat_utf8(a1, *a2);
*(_QWORD *)(a1 + 24) = 0LL;
return result;
}

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

if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0x83u, "mt_string_cat");
if ( !a2 )
_assert_fail("src != NULL", "src/mt_string.c", 0x84u, "mt_string_cat");
result = func6(a1, *a2);
*(_QWORD *)(a1 + 24) = 0LL;
return result;
}

original_code:
void mt_string_cat(MtString* string, const MtString* src)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 131, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((src != ((void *)0)) ? 1 : 0), __extension__ ({ if (src != ((void *)0)) ; else __assert_fail ("src != NULL", "src/mt_string.c", 132, __extension__ __PRETTY_FUNCTION__); }));
  mt_string_cat_utf8(string, src->utf8_data);
  string->hash = 0;
}

canonical_original_code:
void mt_string_cat(struct MtString *string, struct MtString *src)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 131, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((src != ((void *)0)) ? 1 : 0), __extension__ ({ if (src != ((void *)0)) ; else __assert_fail ("src != NULL", "src/mt_string.c", 132, __extension__ __PRETTY_FUNCTION__); }));
  mt_string_cat_utf8(string, src->utf8_data);
  string->hash = 0;
}

variable_types:
src
struct MtString *


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

if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0xACu, "mt_string_copy");
if ( !a2 )
_assert_fail("src != NULL", "src/mt_string.c", 0xADu, "mt_string_copy");
mt_string_set_utf8(a1, *(char **)a2);
result = *(_QWORD *)(a2 + 24);
*(_QWORD *)(a1 + 24) = result;
return result;
}

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

if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0xACu, "mt_string_copy");
if ( !a2 )
_assert_fail("src != NULL", "src/mt_string.c", 0xADu, "mt_string_copy");
func2(a1, *(char **)a2);
result = *(_QWORD *)(a2 + 24);
*(_QWORD *)(a1 + 24) = result;
return result;
}

original_code:
void mt_string_copy(MtString* string, const MtString* src)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 172, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((src != ((void *)0)) ? 1 : 0), __extension__ ({ if (src != ((void *)0)) ; else __assert_fail ("src != NULL", "src/mt_string.c", 173, __extension__ __PRETTY_FUNCTION__); }));
  mt_string_set_utf8(string, src->utf8_data);
  string->hash = src->hash;
}

canonical_original_code:
void mt_string_copy(struct MtString *string, struct MtString *src)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 172, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((src != ((void *)0)) ? 1 : 0), __extension__ ({ if (src != ((void *)0)) ; else __assert_fail ("src != NULL", "src/mt_string.c", 173, __extension__ __PRETTY_FUNCTION__); }));
  mt_string_set_utf8(string, src->utf8_data);
  string->hash = src->hash;
}


decompiled_code:
int __fastcall mt_string_compare(__int64 a1, __int64 a2)
{
size_t v2; // rdx
const char *v3; // rdi

if ( !a1 )
_assert_fail("string1 != NULL", "src/mt_string.c", 0xB8u, "mt_string_compare");
if ( !a2 )
_assert_fail("string2 != NULL", "src/mt_string.c", 0xB9u, "mt_string_compare");
v2 = *(_QWORD *)(a1 + 16);
v3 = *(const char **)a1;
if ( *(_QWORD *)(a2 + 16) >= v2 )
v2 = *(_QWORD *)(a2 + 16);
return strncmp(v3, *(const char **)a2, v2);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, __int64 a2)
{
size_t v2; // rdx
const char *v3; // rdi

if ( !a1 )
_assert_fail("string1 != NULL", "src/mt_string.c", 0xB8u, "mt_string_compare");
if ( !a2 )
_assert_fail("string2 != NULL", "src/mt_string.c", 0xB9u, "mt_string_compare");
v2 = *(_QWORD *)(a1 + 16);
v3 = *(const char **)a1;
if ( *(_QWORD *)(a2 + 16) >= v2 )
v2 = *(_QWORD *)(a2 + 16);
return strncmp(v3, *(const char **)a2, v2);
}

original_code:
int mt_string_compare(const MtString* string1, const MtString* string2)
{
  ((void) sizeof ((string1 != ((void *)0)) ? 1 : 0), __extension__ ({ if (string1 != ((void *)0)) ; else __assert_fail ("string1 != NULL", "src/mt_string.c", 184, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((string2 != ((void *)0)) ? 1 : 0), __extension__ ({ if (string2 != ((void *)0)) ; else __assert_fail ("string2 != NULL", "src/mt_string.c", 185, __extension__ __PRETTY_FUNCTION__); }));
  size_t size = (string1->length > string2->length)?
    string1->length : string2->length;
  return strncmp(string1->utf8_data, string2->utf8_data, size);
}

canonical_original_code:
int mt_string_compare(struct MtString *string1, struct MtString *string2)
{
  ((void) sizeof ((string1 != ((void *)0)) ? 1 : 0), __extension__ ({ if (string1 != ((void *)0)) ; else __assert_fail ("string1 != NULL", "src/mt_string.c", 184, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((string2 != ((void *)0)) ? 1 : 0), __extension__ ({ if (string2 != ((void *)0)) ; else __assert_fail ("string2 != NULL", "src/mt_string.c", 185, __extension__ __PRETTY_FUNCTION__); }));
  unsigned long size = (string1->length > string2->length)?
    string1->length : string2->length;
  return strncmp(string1->utf8_data, string2->utf8_data, size);
}


decompiled_code:
int __fastcall mt_string_compare_utf8(__int64 a1, char *a2)
{
unsigned __int64 v2; // rax
__int64 v3; // rcx

if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0xC5u, "mt_string_compare_utf8");
if ( !a2 )
_assert_fail("utf8_data != NULL", "src/mt_string.c", 0xC6u, "mt_string_compare_utf8");
v2 = utf8_length(a2);
if ( *(_QWORD *)(v3 + 16) >= v2 )
v2 = *(_QWORD *)(v3 + 16);
return strncmp(*(const char **)v3, a2, v2);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, char *a2)
{
unsigned __int64 v2; // rax
__int64 v3; // rcx

if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0xC5u, "mt_string_compare_utf8");
if ( !a2 )
_assert_fail("utf8_data != NULL", "src/mt_string.c", 0xC6u, "mt_string_compare_utf8");
v2 = func0(a2);
if ( *(_QWORD *)(v3 + 16) >= v2 )
v2 = *(_QWORD *)(v3 + 16);
return strncmp(*(const char **)v3, a2, v2);
}

original_code:
int mt_string_compare_utf8(MtString* string, const char* utf8_data)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 197, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((utf8_data != ((void *)0)) ? 1 : 0), __extension__ ({ if (utf8_data != ((void *)0)) ; else __assert_fail ("utf8_data != NULL", "src/mt_string.c", 198, __extension__ __PRETTY_FUNCTION__); }));
  size_t ulen = utf8_length(utf8_data);
  size_t size = (string->length > ulen)?
    string->length : ulen;
  return strncmp(string->utf8_data, utf8_data, size);
}

canonical_original_code:
int mt_string_compare_utf8(struct MtString *string, char *utf8_data)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 197, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((utf8_data != ((void *)0)) ? 1 : 0), __extension__ ({ if (utf8_data != ((void *)0)) ; else __assert_fail ("utf8_data != NULL", "src/mt_string.c", 198, __extension__ __PRETTY_FUNCTION__); }));
  unsigned long ulen = utf8_length(utf8_data);
  unsigned long size = (string->length > ulen)?
    string->length : ulen;
  return strncmp(string->utf8_data, utf8_data, size);
}

variable_types:
ulen
unsigned long


decompiled_code:
void __fastcall mt_string_clear(__int64 a1)
{
if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0xD3u, "mt_string_clear");
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0xD3u, "mt_string_clear");
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
}

original_code:
void mt_string_clear(MtString* string)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 211, __extension__ __PRETTY_FUNCTION__); }));
  free(string->utf8_data);
  string->utf8_data = ((void *)0);
  string->size = 0;
  string->length = 0;
  string->hash = 0;
}

canonical_original_code:
void mt_string_clear(struct MtString *string)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 211, __extension__ __PRETTY_FUNCTION__); }));
  free(string->utf8_data);
  string->utf8_data = ((void *)0);
  string->size = 0;
  string->length = 0;
  string->hash = 0;
}


decompiled_code:
__int64 __fastcall mt_string_get_utf8(__int64 a1)
{
if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0xE1u, "mt_string_get_utf8");
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0xE1u, "mt_string_get_utf8");
return *(_QWORD *)a1;
}

original_code:
const char* mt_string_get_utf8(MtString* string)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 225, __extension__ __PRETTY_FUNCTION__); }));
  return string->utf8_data;
}

canonical_original_code:
char *mt_string_get_utf8(struct MtString *string)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 225, __extension__ __PRETTY_FUNCTION__); }));
  return string->utf8_data;
}


decompiled_code:
__int64 __fastcall mt_string_get_size(__int64 a1)
{
if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0xE8u, "mt_string_get_size");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0xE8u, "mt_string_get_size");
return *(_QWORD *)(a1 + 8);
}

original_code:
size_t mt_string_get_size(const MtString* string)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 232, __extension__ __PRETTY_FUNCTION__); }));
  return string->size;
}

canonical_original_code:
unsigned long mt_string_get_size(struct MtString *string)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 232, __extension__ __PRETTY_FUNCTION__); }));
  return string->size;
}


decompiled_code:
__int64 __fastcall mt_string_get_length(__int64 a1)
{
if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0xEFu, "mt_string_get_length");
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
if ( !a1 )
_assert_fail("string != NULL", "src/mt_string.c", 0xEFu, "mt_string_get_length");
return *(_QWORD *)(a1 + 16);
}

original_code:
size_t mt_string_get_length(const MtString* string)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 239, __extension__ __PRETTY_FUNCTION__); }));
  return string->length;
}

canonical_original_code:
unsigned long mt_string_get_length(struct MtString *string)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 239, __extension__ __PRETTY_FUNCTION__); }));
  return string->length;
}


decompiled_code:
void __fastcall mt_string_free(void *ptr)
{
if ( !ptr )
_assert_fail("string != NULL", "src/mt_string.c", 0xF6u, "mt_string_free");
mt_string_clear((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func15(void *ptr)
{
if ( !ptr )
_assert_fail("string != NULL", "src/mt_string.c", 0xF6u, "mt_string_free");
func11((__int64)ptr);
free(ptr);
}

original_code:
void mt_string_free(MtString* string)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 246, __extension__ __PRETTY_FUNCTION__); }));
  mt_string_clear(string);
  (free(string));
}

canonical_original_code:
void mt_string_free(struct MtString *string)
{
  ((void) sizeof ((string != ((void *)0)) ? 1 : 0), __extension__ ({ if (string != ((void *)0)) ; else __assert_fail ("string != NULL", "src/mt_string.c", 246, __extension__ __PRETTY_FUNCTION__); }));
  mt_string_clear(string);
  (free(string));
}


decompiled_code:
int __fastcall invalid_string(unsigned int a1)
{
return fprintf(stderr, "Invalid string %d\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
return fprintf(stderr, "Invalid string %d\n", a1);
}

original_code:
static void
invalid_string(int string)
{
  fprintf(stderr, "Invalid string %d\n", string);
}

variable_types: string int


decompiled_code:
int __fastcall invalid_conf_option(const char *a1)
{
return fprintf(stderr, "Invalid config option: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return fprintf(stderr, "Invalid config option: %s\n", a1);
}

original_code:
static void
invalid_conf_option(char* op)
{
  fprintf(stderr, "Invalid config option: %s\n", op);
}

canonical_original_code:
static void invalid_conf_option(char *op)
{
  fprintf(stderr, "Invalid config option: %s\n", op);
}

variable_types:
op
char *


decompiled_code:
int __fastcall invalid_conf_data(const char *a1)
{
return fprintf(stderr, "Invalid config data for option: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return fprintf(stderr, "Invalid config data for option: %s\n", a1);
}

original_code:
static void
invalid_conf_data(char* op)
{
  fprintf(stderr, "Invalid config data for option: %s\n", op);
}

canonical_original_code:
static void invalid_conf_data(char *op)
{
  fprintf(stderr, "Invalid config data for option: %s\n", op);
}


decompiled_code:
int __fastcall undefined_symbol(const char *a1)
{
return fprintf(stderr, "Undefined symbol: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
return fprintf(stderr, "Undefined symbol: %s\n", a1);
}

original_code:
static void
undefined_symbol(char* sym)
{
  fprintf(stderr, "Undefined symbol: %s\n", sym);
}

canonical_original_code:
static void undefined_symbol(char *sym)
{
  fprintf(stderr, "Undefined symbol: %s\n", sym);
}

variable_types:
sym
char *


decompiled_code:
_QWORD *mtr_scope_new()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x10uLL);
if ( !v0 )
_assert_fail("scope != NULL", "src/mtr.c", 0xDu, "mtr_scope_new");
*(_DWORD *)v0 = 0;
v1 = v0;
v0[1] = mt_queue_new();
return v1;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x10uLL);
if ( !v0 )
_assert_fail("scope != NULL", "src/mtr.c", 0xDu, "mtr_scope_new");
*(_DWORD *)v0 = 0;
v1 = v0;
v0[1] = mt_queue_new();
return v1;
}

original_code:
MtrScope* mtr_scope_new()
{
  MtrScope* scope = ((MtrScope *) malloc(sizeof(MtrScope)));
  ((void) sizeof ((scope != ((void *)0)) ? 1 : 0), __extension__ ({ if (scope != ((void *)0)) ; else __assert_fail ("scope != NULL", "src/mtr.c", 13, __extension__ __PRETTY_FUNCTION__); }));
  scope->last_note_string = 0;
  scope->current_object_queue = mt_queue_new();
  return scope;
}

canonical_original_code:
struct MtrScope *mtr_scope_new()
{
  struct MtrScope *scope = ((MtrScope *) malloc(sizeof(MtrScope)));
  ((void) sizeof ((scope != ((void *)0)) ? 1 : 0), __extension__ ({ if (scope != ((void *)0)) ; else __assert_fail ("scope != NULL", "src/mtr.c", 13, __extension__ __PRETTY_FUNCTION__); }));
  scope->last_note_string = 0;
  scope->current_object_queue = mt_queue_new();
  return scope;
}

variable_types: struct MtrScope { int last_note_string; struct MtQueue { int length; struct MtQueueNode { void *value; struct MtQueueNode *next; } *front; struct MtQueueNode *back; } *current_object_queue; } *

user_defined_types: struct MtrScope { int last_note_string; struct MtQueue *current_object_queue; }

user_defined_types: struct MtQueue { int length; struct MtQueueNode *front; struct MtQueueNode *back; }


decompiled_code:
void __fastcall mtr_scope_free(void *a1)
{
if ( !a1 )
_assert_fail("scope != NULL", "src/mtr.c", 0x17u, "mtr_scope_free");
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
if ( !a1 )
_assert_fail("scope != NULL", "src/mtr.c", 0x17u, "mtr_scope_free");
free(a1);
}

original_code:
void mtr_scope_free(MtrScope* scope)
{
  ((void) sizeof ((scope != ((void *)0)) ? 1 : 0), __extension__ ({ if (scope != ((void *)0)) ; else __assert_fail ("scope != NULL", "src/mtr.c", 23, __extension__ __PRETTY_FUNCTION__); }));
  scope->current_object_queue = ((void *)0);
  (free(scope));
}

canonical_original_code:
void mtr_scope_free(struct MtrScope *scope)
{
  ((void) sizeof ((scope != ((void *)0)) ? 1 : 0), __extension__ ({ if (scope != ((void *)0)) ; else __assert_fail ("scope != NULL", "src/mtr.c", 23, __extension__ __PRETTY_FUNCTION__); }));
  scope->current_object_queue = ((void *)0);
  (free(scope));
}

user_defined_types: struct MtQueueNode { void *value; struct MtQueueNode *next; }


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

MTR[0] = mt_stack_new();
MTR[1] = mt_queue_new();
result = mt_hash_new();
MTR[2] = result;
return result;
}

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

MTR[0] = mt_stack_new();
MTR[1] = mt_queue_new();
result = mt_hash_new();
MTR[2] = result;
return result;
}

original_code:
void mtr_init()
{
  MTR.scopes = mt_stack_new();
  MTR.sections = mt_queue_new();
  MTR.symbol_table = mt_hash_new();
}


decompiled_code:
__int64 mtr_current_object_queue()
{
return *(_QWORD *)(mt_stack_top(MTR[0]) + 8);
}

canonical_decompiled_code:
__int64 func3()
{
return *(_QWORD *)(mt_stack_top(MTR[0]) + 8);
}

original_code:
MtQueue* mtr_current_object_queue()
{
  MtrScope* scope = mt_stack_top(MTR.scopes);
  return scope->current_object_queue;
}

canonical_original_code:
struct MtQueue *mtr_current_object_queue()
{
  struct MtrScope *scope = mt_stack_top(MTR.scopes);
  return scope->current_object_queue;
}

return_type: struct MtQueue { int length; struct MtQueueNode { void *value; struct MtQueueNode *next; } *front; struct MtQueueNode *back; } *


decompiled_code:
__int64 mtr_last_note_string()
{
return *(unsigned int *)mt_stack_top(MTR[0]);
}

canonical_decompiled_code:
__int64 func4()
{
return *(unsigned int *)mt_stack_top(MTR[0]);
}

original_code:
int mtr_last_note_string()
{
  MtrScope* scope = mt_stack_top(MTR.scopes);
  return scope->last_note_string;
}

canonical_original_code:
int mtr_last_note_string()
{
  struct MtrScope *scope = mt_stack_top(MTR.scopes);
  return scope->last_note_string;
}


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

if ( !a1 )
_assert_fail("object != NULL", "src/mtr.c", 0x3Au, "mtr_current_object_queue_enqueue");
v1 = mt_stack_top(MTR[0]);
return mt_queue_enqueue(*(_QWORD *)(v1 + 8), a1);
}

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

if ( !a1 )
_assert_fail("object != NULL", "src/mtr.c", 0x3Au, "mtr_current_object_queue_enqueue");
v1 = mt_stack_top(MTR[0]);
return mt_queue_enqueue(*(_QWORD *)(v1 + 8), a1);
}

original_code:
void mtr_current_object_queue_enqueue(MtObject* object)
{
  ((void) sizeof ((object != ((void *)0)) ? 1 : 0), __extension__ ({ if (object != ((void *)0)) ; else __assert_fail ("object != NULL", "src/mtr.c", 58, __extension__ __PRETTY_FUNCTION__); }));
  MtrScope* scope = mt_stack_top(MTR.scopes);
  mt_queue_enqueue(scope->current_object_queue, object);
}

canonical_original_code:
void mtr_current_object_queue_enqueue(struct MtObject *object)
{
  ((void) sizeof ((object != ((void *)0)) ? 1 : 0), __extension__ ({ if (object != ((void *)0)) ; else __assert_fail ("object != NULL", "src/mtr.c", 58, __extension__ __PRETTY_FUNCTION__); }));
  struct MtrScope *scope = mt_stack_top(MTR.scopes);
  mt_queue_enqueue(scope->current_object_queue, object);
}

variable_types: struct MtObject { enum MtObjectType { MT_OBJ_NONE=0, MT_OBJ_NOTE=1, MT_OBJ_CHORD=2, MT_OBJ_TRANSITION=3, MT_OBJ_SEQUENCE=4, MT_OBJ_REST=5, MT_OBJ_SYMBOL=6 } type; union asvalue { struct MtNote { enum MtNoteType { MT_NOTE_NONE=0, MT_NOTE_NOTE=1, MT_NOTE_MUTE=2 } type; int string; int fret; enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; int size; } *note; struct MtChord { struct MtQueue { int length; struct MtQueueNode { void *value; struct MtQueueNode *next; } *front; struct MtQueueNode *back; } *notes; enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; int size; } *chord; struct MtTransition { enum MtTransitionType { MT_TRANSITION_NONE=0, MT_TRANSITION_BEND=1, MT_TRANSITION_SLIDE_UP=2, MT_TRANSITION_SLIDE_DOWN=3, MT_TRANSITION_HAMMER_ON=4, MT_TRANSITION_PULL_OFF=5 } type; struct MtObject *destination; } *transition; struct MtSequence { enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; struct MtQueue *objects; } *sequence; struct MtSymbol { struct MtString { char *utf8_data; unsigned long size; unsigned long length; unsigned long hash; } *name; enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; } *symbol; } as; } *

user_defined_types: struct MtObject { enum MtObjectType type; union asvalue as; }

user_defined_types: union asvalue { struct MtNote *note; struct MtChord *chord; struct MtTransition *transition; struct MtSequence *sequence; struct MtSymbol *symbol; }

user_defined_types: struct MtNote { enum MtNoteType type; int string; int fret; enum MtModifier modifier; int size; }

user_defined_types: struct MtChord { struct MtQueue *notes; enum MtModifier modifier; int size; }

user_defined_types: struct MtTransition { enum MtTransitionType type; struct MtObject *destination; }

user_defined_types: struct MtSequence { enum MtModifier modifier; struct MtQueue *objects; }

user_defined_types: struct MtSymbol { struct MtString *name; enum MtModifier modifier; }


decompiled_code:
__int64 mtr_scope_push()
{
_QWORD *v0; // rax

v0 = mtr_scope_new();
return mt_stack_push(MTR[0], v0);
}

canonical_decompiled_code:
__int64 func6()
{
_QWORD *v0; // rax

v0 = func0();
return mt_stack_push(MTR[0], v0);
}

original_code:
void mtr_scope_push()
{
  mt_stack_push(MTR.scopes, mtr_scope_new());
}


decompiled_code:
void mtr_scope_pop()
{
void *v0; // rax

v0 = (void *)mt_stack_pop(MTR[0]);
if ( !v0 )
_assert_fail("scope != NULL", "src/mtr.c", 0x48u, "mtr_scope_pop");
mtr_scope_free(v0);
}

canonical_decompiled_code:
void func7()
{
void *v0; // rax

v0 = (void *)mt_stack_pop(MTR[0]);
if ( !v0 )
_assert_fail("scope != NULL", "src/mtr.c", 0x48u, "mtr_scope_pop");
func1(v0);
}

original_code:
void mtr_scope_pop()
{
  MtrScope* scope = mt_stack_pop(MTR.scopes);
  ((void) sizeof ((scope != ((void *)0)) ? 1 : 0), __extension__ ({ if (scope != ((void *)0)) ; else __assert_fail ("scope != NULL", "src/mtr.c", 72, __extension__ __PRETTY_FUNCTION__); }));
  mtr_scope_free(scope);
}

canonical_original_code:
void mtr_scope_pop()
{
  struct MtrScope *scope = mt_stack_pop(MTR.scopes);
  ((void) sizeof ((scope != ((void *)0)) ? 1 : 0), __extension__ ({ if (scope != ((void *)0)) ; else __assert_fail ("scope != NULL", "src/mtr.c", 72, __extension__ __PRETTY_FUNCTION__); }));
  mtr_scope_free(scope);
}


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

v0 = mtr_current_object_queue();
return mt_queue_enqueue(MTR[1], v0);
}

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

v0 = func3();
return mt_queue_enqueue(MTR[1], v0);
}

original_code:
void mtr_section_push()
{
  mt_queue_enqueue(MTR.sections, mtr_current_object_queue());
}


decompiled_code:
__int64 mtr_destroy()
{
mtr_scope_pop();
mt_stack_free(MTR[0]);
return mt_hash_free(MTR[2]);
}

canonical_decompiled_code:
__int64 func9()
{
func7();
mt_stack_free(MTR[0]);
return mt_hash_free(MTR[2]);
}

original_code:
void mtr_destroy()
{
  mtr_scope_pop();
  mt_stack_free(MTR.scopes);
  mt_hash_free(MTR.symbol_table);
}


yywrap

decompiled_code:
__int64 yywrap()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
int yywrap()
{
  return 1;
}

canonical_original_code:
int yywrap()
{
  return 1;
}


yyerror

decompiled_code:
__int64 __fastcall yyerror(const char *a1)
{
fprintf(stderr, "On line %i: %s\n", yylineno, a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
fprintf(stderr, "On line %i: %s\n", yylineno, a1);
return 1LL;
}

original_code:
int yyerror(const char* msg)
{
  fprintf(stderr, "On line %i: %s\n", yylineno, msg);
  return 1;
}

canonical_original_code:
int yyerror(char *msg)
{
  fprintf(stderr, "On line %i: %s\n", yylineno, msg);
  return 1;
}

variable_types:
msg
char *


decompiled_code:
void marktab_rend_stdin()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void marktab_rend_stdin()
{
}

canonical_original_code:
void marktab_rend_stdin()
{
}