sendData

decompiled_code:
__int64 __fastcall sendData(int *a1, __time_t a2, __suseconds_t a3)
{
int v3; // er15
__int64 v4; // r13
_BYTE *v5; // r14
__int64 v6; // rbx
int v7; // eax
int v9; // eax
__int64 v10; // [rsp+8h] [rbp-F0h]
int v11; // [rsp+14h] [rbp-E4h]
unsigned int size; // [rsp+18h] [rbp-E0h]
int size_4; // [rsp+1Ch] [rbp-DCh]
struct timeval timeout; // [rsp+20h] [rbp-D8h] BYREF
char buf; // [rsp+3Fh] [rbp-B9h] BYREF
fd_set readfds; // [rsp+40h] [rbp-B8h] BYREF

timeout.tv_sec = a2;
timeout.tv_usec = a3;
size_4 = a1[1];
v3 = *a1;
memset(&readfds, 0, sizeof(readfds));
v4 = 1LL << (v3 % 64);
readfds.fds_bits[v3 / 64] |= v4;
size = a1[2];
select(v3 + 1, &readfds, 0LL, 0LL, &timeout);
v11 = 0;
v10 = 0LL;
while ( 1 )
{
v5 = malloc(size);
if ( !v5 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/connections.c", "sendData", 169LL);
fwrite("sendBuf != NULL", 1uLL, 0xFuLL, stderr);
exit(-2);
}
v6 = 0LL;
while ( size != v6 )
{
if ( (readfds.fds_bits[v3 / 64] & v4) != 0 )
{
v7 = read(v3, &buf, 1uLL);
if ( !v7 )
{
v11 = 1;
break;
}
if ( v7 == -1 )
break;
v5[v6++] = buf;
}
}
v5[(int)v6] = 0;
if ( !(_DWORD)v6 )
{
if ( v11 )
break;
}
if ( (_DWORD)v6 )
{
v9 = send(size_4, v5, (int)v6, 0);
if ( v9 == -1 )
perror("send");
else
v10 += v9;
fprintf(stderr, "\x1B[3mTotal bytes sent: %lld\x1B[00m\r", v10);
freeWord(v5);
if ( v11 == 1 )
goto LABEL_16;
}
else
{
fprintf(stderr, "\x1B[3mTotal bytes sent: %lld\x1B[00m\r", v10);
freeWord(v5);
}
}
freeWord(v5);
LABEL_16:
putchar(10);
clearCursorLine(stdout);
puts("Done reading");
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, __time_t a2, __suseconds_t a3)
{
int v3; // er15
__int64 v4; // r13
_BYTE *v5; // r14
__int64 v6; // rbx
int v7; // eax
int v9; // eax
__int64 v10; // [rsp+8h] [rbp-F0h]
int v11; // [rsp+14h] [rbp-E4h]
unsigned int size; // [rsp+18h] [rbp-E0h]
int size_4; // [rsp+1Ch] [rbp-DCh]
struct timeval timeout; // [rsp+20h] [rbp-D8h] BYREF
char buf; // [rsp+3Fh] [rbp-B9h] BYREF
fd_set readfds; // [rsp+40h] [rbp-B8h] BYREF

timeout.tv_sec = a2;
timeout.tv_usec = a3;
size_4 = a1[1];
v3 = *a1;
memset(&readfds, 0, sizeof(readfds));
v4 = 1LL << (v3 % 64);
readfds.fds_bits[v3 / 64] |= v4;
size = a1[2];
select(v3 + 1, &readfds, 0LL, 0LL, &timeout);
v11 = 0;
v10 = 0LL;
while ( 1 )
{
v5 = malloc(size);
if ( !v5 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/connections.c", "sendData", 169LL);
fwrite("sendBuf != NULL", 1uLL, 0xFuLL, stderr);
exit(-2);
}
v6 = 0LL;
while ( size != v6 )
{
if ( (readfds.fds_bits[v3 / 64] & v4) != 0 )
{
v7 = read(v3, &buf, 1uLL);
if ( !v7 )
{
v11 = 1;
break;
}
if ( v7 == -1 )
break;
v5[v6++] = buf;
}
}
v5[(int)v6] = 0;
if ( !(_DWORD)v6 )
{
if ( v11 )
break;
}
if ( (_DWORD)v6 )
{
v9 = send(size_4, v5, (int)v6, 0);
if ( v9 == -1 )
perror("send");
else
v10 += v9;
fprintf(stderr, "\x1B[3mTotal bytes sent: %lld\x1B[00m\r", v10);
freeWord(v5);
if ( v11 == 1 )
goto LABEL_16;
}
else
{
fprintf(stderr, "\x1B[3mTotal bytes sent: %lld\x1B[00m\r", v10);
freeWord(v5);
}
}
freeWord(v5);
LABEL_16:
putchar(10);
clearCursorLine(stdout);
puts("Done reading");
return v10;
}

original_code:
LLInt sendData(fdPair *fDP, struct timeval timerStruct) {
  LLInt totalSentByteCount = 0;
  int to = fDP->toFD;
  int from = fDP->fromFD;
  fd_set descriptorSet;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&descriptorSet)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&descriptorSet)->__fds_bits)[((from) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((from) % (8 * (int) sizeof (__fd_mask)))))));
  unsigned int BUF_SIZ = fDP->bufSize;
  select(from+1, &descriptorSet, ((void *)0), ((void *)0), &timerStruct);
  int eofState = False;
  while (1) {
    char *sendBuf = (char *)malloc(sizeof(char)*BUF_SIZ);
    { if (! (sendBuf != ((void *)0))) { { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/connections.c", __func__, 169); fprintf(stderr, "sendBuf != NULL"); }; exit(-2); }; };
    int nRead = 0;
    char c;
    while (nRead < BUF_SIZ) {
      if (((((&descriptorSet)->__fds_bits)[((from) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((from) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        int readResult = read(from, &c, 1);
        if (readResult == 0) {
            eofState = True;
            break;
        } else if (readResult == -1) break;
            sendBuf[nRead] = c;
            ++nRead;
      } else {
        continue;
      }
    }
    sendBuf[nRead] = '\0';
    if ((nRead == 0) && (eofState == True)) {
      freeWord(sendBuf);
      break;
    }
    if (! nRead) {
    } else {
      int sentByteCount = send(to, sendBuf, nRead, 0);
      if (sentByteCount == -1) perror("send");
      else totalSentByteCount += sentByteCount;
    }
    fprintf(
      stderr, "\033[3mTotal bytes sent: %lld\033[00m\r", totalSentByteCount
    );
    if (sendBuf != ((void *)0)) {
      freeWord(sendBuf);
    }
    if (eofState == True) break;
  }
  printf("\n");
  clearCursorLine(stdout);
  printf("Done reading\n");
  return totalSentByteCount;
}

canonical_original_code:
long long sendData(struct fdPair *fDP, struct timeval timerStruct) {
  long long totalSentByteCount = 0;
  int to = fDP->toFD;
  int from = fDP->fromFD;
  struct fd_set descriptorSet;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&descriptorSet)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&descriptorSet)->__fds_bits)[((from) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((from) % (8 * (int) sizeof (__fd_mask)))))));
  unsigned int BUF_SIZ = fDP->bufSize;
  select(from+1, &descriptorSet, ((void *)0), ((void *)0), &timerStruct);
  int eofState = False;
  while (1) {
    char *sendBuf = (char *)malloc(sizeof(char)*BUF_SIZ);
    { if (! (sendBuf != ((void *)0))) { { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/connections.c", __func__, 169); fprintf(stderr, "sendBuf != NULL"); }; exit(-2); }; };
    int nRead = 0;
    char c;
    while (nRead < BUF_SIZ) {
      if (((((&descriptorSet)->__fds_bits)[((from) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((from) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        int readResult = read(from, &c, 1);
        if (readResult == 0) {
            eofState = True;
            break;
        } else if (readResult == -1) break;
            sendBuf[nRead] = c;
            ++nRead;
      } else {
        continue;
      }
    }
    sendBuf[nRead] = '\0';
    if ((nRead == 0) && (eofState == True)) {
      freeWord(sendBuf);
      break;
    }
    if (! nRead) {
    } else {
      int sentByteCount = send(to, sendBuf, nRead, 0);
      if (sentByteCount == -1) perror("send");
      else totalSentByteCount += sentByteCount;
    }
    fprintf(
      stderr, "\033[3mTotal bytes sent: %lld\033[00m\r", totalSentByteCount
    );
    if (sendBuf != ((void *)0)) {
      freeWord(sendBuf);
    }
    if (eofState == True) break;
  }
  printf("\n");
  clearCursorLine(stdout);
  printf("Done reading\n");
  return totalSentByteCount;
}

variable_types: struct fdPair { int fromFD; int toFD; unsigned int bufSize; enum DataState { Invalid=0, Sending=1, Receiving=2 } state; } *

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

variable_types:
totalSentByteCount
long long

variable_types: to int

variable_types: from int

variable_types:
descriptorSet
struct fd_set { long __fds_bits[-1]; }

variable_types: eofState int

variable_types:
sendBuf
char *

variable_types: nRead int

variable_types: sentByteCount int

return_type: long long

user_defined_types: struct fdPair { int fromFD; int toFD; unsigned int bufSize; enum DataState state; }


recvData

repo: uaarg/telemetry-over-wifi

decompiled_code:
__int64 __fastcall recvData(int *a1, __time_t a2, __suseconds_t a3)
{
int v3; // er15
__int64 i; // r13
char *v5; // rax
char *v6; // rbx
ssize_t v7; // rbp
size_t v8; // r12
__int64 v10; // [rsp+0h] [rbp-D8h]
int fd; // [rsp+Ch] [rbp-CCh]
struct timeval timeout; // [rsp+10h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-B8h] BYREF

timeout.tv_sec = a2;
timeout.tv_usec = a3;
fd = a1[1];
v3 = *a1;
memset(&readfds, 0, sizeof(readfds));
v10 = 1LL << (v3 % 64);
readfds.fds_bits[v3 / 64] |= v10;
select(v3 + 1, &readfds, 0LL, 0LL, &timeout);
for ( i = 0LL; ; i += v7 )
{
while ( (readfds.fds_bits[v3 / 64] & v10) == 0 )
;
v5 = (char *)malloc(0x20uLL);
v6 = v5;
if ( !v5 )
{
fwrite("Run out-of memory!!\n", 1uLL, 0x14uLL, stderr);
exit(-1);
}
v7 = recv(v3, v5, 0x1FuLL, 0);
if ( !v7 )
break;
v8 = strlen(v6);
if ( write(fd, v6, v8) != v8 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/connections.c", "recvData", 276LL);
fwrite("Write error", 1uLL, 0xBuLL, stderr);
}
free(v6);
}
freeWord(v6);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, __time_t a2, __suseconds_t a3)
{
int v3; // er15
__int64 i; // r13
char *v5; // rax
char *v6; // rbx
ssize_t v7; // rbp
size_t v8; // r12
__int64 v10; // [rsp+0h] [rbp-D8h]
int fd; // [rsp+Ch] [rbp-CCh]
struct timeval timeout; // [rsp+10h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-B8h] BYREF

timeout.tv_sec = a2;
timeout.tv_usec = a3;
fd = a1[1];
v3 = *a1;
memset(&readfds, 0, sizeof(readfds));
v10 = 1LL << (v3 % 64);
readfds.fds_bits[v3 / 64] |= v10;
select(v3 + 1, &readfds, 0LL, 0LL, &timeout);
for ( i = 0LL; ; i += v7 )
{
while ( (readfds.fds_bits[v3 / 64] & v10) == 0 )
;
v5 = (char *)malloc(0x20uLL);
v6 = v5;
if ( !v5 )
{
fwrite("Run out-of memory!!\n", 1uLL, 0x14uLL, stderr);
exit(-1);
}
v7 = recv(v3, v5, 0x1FuLL, 0);
if ( !v7 )
break;
v8 = strlen(v6);
if ( write(fd, v6, v8) != v8 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/connections.c", "recvData", 276LL);
fwrite("Write error", 1uLL, 0xBuLL, stderr);
}
free(v6);
}
freeWord(v6);
return i;
}

original_code:
LLInt recvData(fdPair *fDP, struct timeval tv) {
  fd_set monitorFDS;
  int toFD = fDP->toFD;
  int sockfd = fDP->fromFD;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&monitorFDS)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&monitorFDS)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
  select(sockfd+1, &monitorFDS, ((void *)0), ((void *)0), &tv);
  int bufferedReads = 0;
  LLInt totalBytesIn=0, nRecvdBytes=0;
  while (1) {
    if (((((&monitorFDS)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    } else {
      continue;
    }
    char *buf = (char *)malloc(sizeof(char)*MAX_BUF_LENGTH);
    if (buf == ((void *)0)) {
      fprintf(stderr, "Run out-of memory!!\n");
      exit(-1);
    }
    nRecvdBytes = recv(sockfd, buf, MAX_BUF_LENGTH - 1, 0);
    Bool breakTrue = nRecvdBytes ? False : True;
    if (breakTrue) {
      freeWord(buf);
      break;
    }
    ssize_t expectedWriteResult = strlen(buf);
    if (write(toFD, buf, expectedWriteResult) != expectedWriteResult) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/connections.c", __func__, 276); fprintf(stderr, "Write error"); };
    }
    free(buf);
    ++bufferedReads;
    totalBytesIn += nRecvdBytes;
  }
  return totalBytesIn;
}

canonical_original_code:
long long recvData(struct fdPair *fDP, struct timeval tv) {
  struct fd_set monitorFDS;
  int toFD = fDP->toFD;
  int sockfd = fDP->fromFD;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&monitorFDS)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&monitorFDS)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
  select(sockfd+1, &monitorFDS, ((void *)0), ((void *)0), &tv);
  int bufferedReads = 0;
  long long totalBytesIn = 0; long long nRecvdBytes = 0;
  while (1) {
    if (((((&monitorFDS)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    } else {
      continue;
    }
    char *buf = (char *)malloc(sizeof(char)*MAX_BUF_LENGTH);
    if (buf == ((void *)0)) {
      fprintf(stderr, "Run out-of memory!!\n");
      exit(-1);
    }
    nRecvdBytes = recv(sockfd, buf, MAX_BUF_LENGTH - 1, 0);
    enum Bool breakTrue = nRecvdBytes ? False : True;
    if (breakTrue) {
      freeWord(buf);
      break;
    }
    long expectedWriteResult = strlen(buf);
    if (write(toFD, buf, expectedWriteResult) != expectedWriteResult) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/connections.c", __func__, 276); fprintf(stderr, "Write error"); };
    }
    free(buf);
    ++bufferedReads;
    totalBytesIn += nRecvdBytes;
  }
  return totalBytesIn;
}

variable_types:
monitorFDS
struct fd_set { long __fds_bits[-1]; }

variable_types: toFD int

variable_types: sockfd int

variable_types: bufferedReads int

variable_types:
totalBytesIn
long long

variable_types:
nRecvdBytes
long long

variable_types:
buf
char *

variable_types:
breakTrue
enum Bool { False=0, True=1 }

variable_types: expectedWriteResult long

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

user_defined_types: enum DataState { Invalid=0, Sending=1, Receiving=2 }


socketConnection

decompiled_code:
__int64 __fastcall socketConnection(char *name, char *service)
{
int v2; // eax
struct addrinfo *v3; // rbx
int v4; // eax
unsigned int v5; // ebp
_WORD *v6; // rax
const char *v8; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-80h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-78h] BYREF
char buf[72]; // [rsp+40h] [rbp-48h] BYREF

if ( !name || !service )
return (unsigned int)-1;
if ( (atoi(service) & 0x8000u) != 0 )
return (unsigned int)-1;
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(name, service, &req, &pai);
if ( v2 )
{
v8 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo: %s\n", v8);
return (unsigned int)-1;
}
v3 = pai;
if ( !pai )
{
LABEL_13:
fwrite("client: failed to connect\n", 1uLL, 0x1AuLL, stderr);
return (unsigned int)-1;
}
while ( 1 )
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v5 = v4;
if ( v4 != -1 )
break;
perror("Client socket binding");
LABEL_12:
v3 = v3->ai_next;
if ( !v3 )
goto LABEL_13;
}
if ( connect(v4, v3->ai_addr, v3->ai_addrlen) == -1 )
{
close(v5);
perror("Client socket connecting");
goto LABEL_12;
}
v6 = get_in_addr(&v3->ai_addr->sa_family);
inet_ntop(v3->ai_family, v6, buf, 0x2Eu);
freeaddrinfo(pai);
printf("Client: connected to %s\n", buf);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *name, char *service)
{
int v2; // eax
struct addrinfo *v3; // rbx
int v4; // eax
unsigned int v5; // ebp
_WORD *v6; // rax
const char *v8; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-80h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-78h] BYREF
char buf[72]; // [rsp+40h] [rbp-48h] BYREF

if ( !name || !service )
return (unsigned int)-1;
if ( (atoi(service) & 0x8000u) != 0 )
return (unsigned int)-1;
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(name, service, &req, &pai);
if ( v2 )
{
v8 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo: %s\n", v8);
return (unsigned int)-1;
}
v3 = pai;
if ( !pai )
{
LABEL_13:
fwrite("client: failed to connect\n", 1uLL, 0x1AuLL, stderr);
return (unsigned int)-1;
}
while ( 1 )
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v5 = v4;
if ( v4 != -1 )
break;
perror("Client socket binding");
LABEL_12:
v3 = v3->ai_next;
if ( !v3 )
goto LABEL_13;
}
if ( connect(v4, v3->ai_addr, v3->ai_addrlen) == -1 )
{
close(v5);
perror("Client socket connecting");
goto LABEL_12;
}
v6 = get_in_addr(&v3->ai_addr->sa_family);
inet_ntop(v3->ai_family, v6, buf, 0x2Eu);
freeaddrinfo(pai);
printf("Client: connected to %s\n", buf);
return v5;
}

original_code:
int socketConnection(const char *targetHost, const char *portStr) {
  if (targetHost == ((void *)0) || portStr == ((void *)0))
    return ERROR_SOCKFD_VALUE;
  const short port = (short)atoi(portStr);
  if (port < MIN_PORT_VALUE || port > MAX_PORT_VALUE)
    return ERROR_SOCKFD_VALUE;
  int sockfd = ERROR_SOCKFD_VALUE;
  char hostAddrString[46];
  struct addrinfo hints, *servinfo, *p;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_DGRAM;
  int addrResolveResult = getaddrinfo(targetHost, portStr, &hints, &servinfo);
  if (addrResolveResult != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(addrResolveResult));
    return ERROR_SOCKFD_VALUE;
  }
  for(p = servinfo; p != ((void *)0); p = p->ai_next) {
    sockfd = socket(p->ai_family, p->ai_socktype,p->ai_protocol);
    if (sockfd == ERROR_SOCKFD_VALUE) {
      perror("Client socket binding");
      continue;
    }
    if (connect(sockfd, p->ai_addr, p->ai_addrlen) == ERROR_SOCKFD_VALUE) {
      close(sockfd);
      perror("Client socket connecting");
      continue;
    }
    break;
  }
  if (p == ((void *)0)) {
    fprintf(stderr, "client: failed to connect\n");
    return ERROR_SOCKFD_VALUE;
  }
  inet_ntop(
    p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
    hostAddrString, sizeof(hostAddrString)
  );
  freeaddrinfo(servinfo);
  printf("Client: connected to %s\n", hostAddrString);
  return sockfd;
}

canonical_original_code:
int socketConnection(char *targetHost, char *portStr) {
  if (targetHost == ((void *)0) || portStr == ((void *)0))
    return ERROR_SOCKFD_VALUE;
  short port = (short)atoi(portStr);
  if (port < MIN_PORT_VALUE || port > MAX_PORT_VALUE)
    return ERROR_SOCKFD_VALUE;
  int sockfd = ERROR_SOCKFD_VALUE;
  char hostAddrString[46];
  struct addrinfo hints; struct addrinfo *servinfo; struct addrinfo *p;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_DGRAM;
  int addrResolveResult = getaddrinfo(targetHost, portStr, &hints, &servinfo);
  if (addrResolveResult != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(addrResolveResult));
    return ERROR_SOCKFD_VALUE;
  }
  for(p = servinfo; p != ((void *)0); p = p->ai_next) {
    sockfd = socket(p->ai_family, p->ai_socktype,p->ai_protocol);
    if (sockfd == ERROR_SOCKFD_VALUE) {
      perror("Client socket binding");
      continue;
    }
    if (connect(sockfd, p->ai_addr, p->ai_addrlen) == ERROR_SOCKFD_VALUE) {
      close(sockfd);
      perror("Client socket connecting");
      continue;
    }
    break;
  }
  if (p == ((void *)0)) {
    fprintf(stderr, "client: failed to connect\n");
    return ERROR_SOCKFD_VALUE;
  }
  inet_ntop(
    p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
    hostAddrString, sizeof(hostAddrString)
  );
  freeaddrinfo(servinfo);
  printf("Client: connected to %s\n", hostAddrString);
  return sockfd;
}

variable_types:
targetHost
char *

variable_types:
portStr
char *

variable_types: port short

variable_types:
hostAddrString
char [46]

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: addrResolveResult int

return_type: int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


ihello

repo: uberblah/emu

decompiled_code:
int ihello()
{
return puts("Hello!");
}

canonical_decompiled_code:
int func0()
{
return puts("Hello!");
}

original_code:
void ihello(emu_processor* proc)
{
  printf("Hello!\n");
}

canonical_original_code:
void ihello(struct emu_processor *proc)
{
  printf("Hello!\n");
}

variable_types: struct emu_processor { void (*iset[256])(struct emu_processor *); unsigned char regs[128]; unsigned int ip; struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *device; } *

return_type: void

user_defined_types: struct emu_processor { void (*iset[256])(struct emu_processor *); unsigned char regs[128]; unsigned int ip; struct emu_device *device; }


decompiled_code:
__int64 proc_instruction_test()
{
char *v0; // rax
__int64 v1; // rbx
__int64 i; // rax
_BYTE v4[2048]; // [rsp+0h] [rbp-808h] BYREF
char v5[8]; // [rsp+800h] [rbp-8h] BYREF

puts("You should see \"Hello!\" three times now...");
v0 = v4;
do
{
*(_QWORD *)v0 = ihello;
v0 += 8;
}
while ( v0 != v5 );
v1 = emup_create(v4, 1024LL, v5);
if ( !v1 )
{
puts("OH DARN!! WE FAILED TO ALLOCATE A PROCESSOR!!");
exit(1);
}
for ( i = 0LL; i != 1024; ++i )
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(v1 + 2184) + 16LL) + i) = 0;
emup_step(v1);
emup_step(v1);
emup_step(v1);
return emup_free(v1);
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rax
__int64 v1; // rbx
__int64 i; // rax
_BYTE v4[2048]; // [rsp+0h] [rbp-808h] BYREF
char v5[8]; // [rsp+800h] [rbp-8h] BYREF

puts("You should see \"Hello!\" three times now...");
v0 = v4;
do
{
*(_QWORD *)v0 = ihello;
v0 += 8;
}
while ( v0 != v5 );
v1 = emup_create(v4, 1024LL, v5);
if ( !v1 )
{
puts("OH DARN!! WE FAILED TO ALLOCATE A PROCESSOR!!");
exit(1);
}
for ( i = 0LL; i != 1024; ++i )
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(v1 + 2184) + 16LL) + i) = 0;
emup_step(v1);
emup_step(v1);
emup_step(v1);
return emup_free(v1);
}

original_code:
void proc_instruction_test()
{
  printf("You should see \"Hello!\" three times now...\n");
  emu_instruction iset[256];
  int i = 0;
  for(; i < 256; i++) iset[i] = ihello;
  emu_processor* proc = emup_create(iset, 1024);
  if(!proc)
  {
    printf("OH DARN!! WE FAILED TO ALLOCATE A PROCESSOR!!\n");
    exit(1);
  }
  for(i = 0; i < 1024; i++) ((uint8_t*)proc->device->mem)[i] = 0;
  for(i = 0; i < 3; i++) emup_step(proc);
  emup_free(proc);
}

canonical_original_code:
void proc_instruction_test()
{
  printf("You should see \"Hello!\" three times now...\n");
  void (*iset[256])(struct emu_processor *);
  int i = 0;
  for(; i < 256; i++) iset[i] = ihello;
  struct emu_processor *proc = emup_create(iset, 1024);
  if(!proc)
  {
    printf("OH DARN!! WE FAILED TO ALLOCATE A PROCESSOR!!\n");
    exit(1);
  }
  for(i = 0; i < 1024; i++) ((unsigned char *)proc->device->mem)[i] = 0;
  for(i = 0; i < 3; i++) emup_step(proc);
  emup_free(proc);
}

variable_types: void (*[256])(struct emu_processor { void (*iset[256])(struct emu_processor *); unsigned char regs[128]; unsigned int ip; struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *device; } *)

variable_types: i int


eflip

decompiled_code:
__int64 __fastcall eflip(int a1)
{
unsigned int v2; // [rsp+0h] [rbp-4h]

BYTE2(v2) = BYTE1(a1);
HIBYTE(v2) = a1;
BYTE1(v2) = BYTE2(a1);
LOBYTE(v2) = HIBYTE(a1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
unsigned int v2; // [rsp+0h] [rbp-4h]

BYTE2(v2) = BYTE1(a1);
HIBYTE(v2) = a1;
BYTE1(v2) = BYTE2(a1);
LOBYTE(v2) = HIBYTE(a1);
return v2;
}

original_code:
uint32_t eflip(uint32_t num)
{
  uint32_t buf = num;
  uint8_t* src = (uint8_t*)(&buf);
  uint8_t* dst = (uint8_t*)(&num);
  dst += 3;
  *dst = *src;
  src++;
  dst--;
  *dst = *src;
  src++;
  dst--;
  *dst = *src;
  src++;
  dst--;
  *dst = *src;
  return num;
}

canonical_original_code:
unsigned int eflip(unsigned int num)
{
  unsigned int buf = num;
  unsigned char *src = (uint8_t*)(&buf);
  unsigned char *dst = (uint8_t*)(&num);
  dst += 3;
  *dst = *src;
  src++;
  dst--;
  *dst = *src;
  src++;
  dst--;
  *dst = *src;
  src++;
  dst--;
  *dst = *src;
  return num;
}

variable_types:
num
unsigned int

variable_types:
buf
unsigned int

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *

return_type: unsigned int


decompiled_code:
__int64 proc_register_test()
{
char *v0; // rax
__int64 v1; // rbx
_BYTE *v2; // rbp
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
int v10; // [rsp+Ch] [rbp-81Ch] BYREF
char v11[2048]; // [rsp+10h] [rbp-818h] BYREF
char v12[24]; // [rsp+810h] [rbp-18h] BYREF

v0 = v11;
do
{
*(_QWORD *)v0 = imov;
v0 += 8;
}
while ( v0 != v12 );
v1 = emup_create(v11, 1024LL, v12);
v2 = *(_BYTE **)(*(_QWORD *)(v1 + 2184) + 16LL);
v10 = eflip(-559038737);
emup_regset(v1, 0LL, &v10);
v3 = eflip(*(_DWORD *)(v1 + 2048));
printf("should be deadbeef: %x\n", v3);
v10 = 0;
emup_regget(v1, 0LL, &v10);
v4 = eflip(v10);
printf("should be deadbeef: %x\n", v4);
v5 = eflip(*(_DWORD *)(v1 + 2052));
printf("should not be deadbeef: %x\n", v5);
*v2 = 0;
v2[1] = 0;
v2[2] = 8;
emup_step(v1);
v10 = 0;
emup_regget(v1, 8LL, &v10);
v6 = eflip(v10);
printf("should be deadbeef: %x\n", v6);
v7 = eflip(*(_DWORD *)(v1 + 2052));
printf("should be same as above: %x\n", v7);
v2[3] = 0;
v2[4] = 4;
v2[5] = 5;
v2[6] = 0;
v2[7] = 14;
v2[8] = 7;
emup_step(v1);
emup_step(v1);
v10 = 0;
emup_regget(v1, 0LL, &v10);
v8 = eflip(v10);
printf("should be dedebebe: %x\n", v8);
return emup_free(v1);
}

canonical_decompiled_code:
__int64 func4()
{
char *v0; // rax
__int64 v1; // rbx
_BYTE *v2; // rbp
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
int v10; // [rsp+Ch] [rbp-81Ch] BYREF
char v11[2048]; // [rsp+10h] [rbp-818h] BYREF
char v12[24]; // [rsp+810h] [rbp-18h] BYREF

v0 = v11;
do
{
*(_QWORD *)v0 = imov;
v0 += 8;
}
while ( v0 != v12 );
v1 = emup_create(v11, 1024LL, v12);
v2 = *(_BYTE **)(*(_QWORD *)(v1 + 2184) + 16LL);
v10 = func3(-559038737);
emup_regset(v1, 0LL, &v10);
v3 = func3(*(_DWORD *)(v1 + 2048));
printf("should be deadbeef: %x\n", v3);
v10 = 0;
emup_regget(v1, 0LL, &v10);
v4 = func3(v10);
printf("should be deadbeef: %x\n", v4);
v5 = func3(*(_DWORD *)(v1 + 2052));
printf("should not be deadbeef: %x\n", v5);
*v2 = 0;
v2[1] = 0;
v2[2] = 8;
emup_step(v1);
v10 = 0;
emup_regget(v1, 8LL, &v10);
v6 = func3(v10);
printf("should be deadbeef: %x\n", v6);
v7 = func3(*(_DWORD *)(v1 + 2052));
printf("should be same as above: %x\n", v7);
v2[3] = 0;
v2[4] = 4;
v2[5] = 5;
v2[6] = 0;
v2[7] = 14;
v2[8] = 7;
emup_step(v1);
emup_step(v1);
v10 = 0;
emup_regget(v1, 0LL, &v10);
v8 = func3(v10);
printf("should be dedebebe: %x\n", v8);
return emup_free(v1);
}

original_code:
void proc_register_test()
{
  emu_instruction iset[256];
  int i = 0;
  for(; i < 256; i++) iset[i] = imov;
  emu_processor* proc = emup_create(iset, 1024);
  uint8_t* mem = proc->device->mem;
  uint32_t iobuf = eflip(0xdeadbeef);
  emup_regset(proc, 0x00 | 0x00, &iobuf);
  printf("should be deadbeef: %x\n", eflip(((uint32_t*)proc->regs)[0]));
  iobuf = 0;
  emup_regget(proc, 0x00 | 0x00, &iobuf);
  printf("should be deadbeef: %x\n", eflip(iobuf));
  printf("should not be deadbeef: %x\n", eflip(((uint32_t*)proc->regs)[1]));
  mem[0] = 0x00;
  mem[1] = 0x00 | 0x00;
  mem[2] = 0x08 | 0x00;
  emup_step(proc);
  iobuf = 0;
  emup_regget(proc, 0x08 | 0x00, &iobuf);
  printf("should be deadbeef: %x\n", eflip(iobuf));
  printf("should be same as above: %x\n", eflip(((uint32_t*)proc->regs)[1]));
  mem[3] = 0x00;
  mem[4] = 0x00 | 0x04;
  mem[5] = 0x00 | 0x05;
  mem[6] = 0x00;
  mem[7] = 0x08 | 0x06;
  mem[8] = 0x00 | 0x07;
  emup_step(proc);
  emup_step(proc);
  iobuf = 0;
  emup_regget(proc, 0x00 | 0x00, &iobuf);
  printf("should be dedebebe: %x\n", eflip(iobuf));
  emup_free(proc);
}

canonical_original_code:
void proc_register_test()
{
  void (*iset[256])(struct emu_processor *);
  int i = 0;
  for(; i < 256; i++) iset[i] = imov;
  struct emu_processor *proc = emup_create(iset, 1024);
  unsigned char *mem = proc->device->mem;
  unsigned int iobuf = eflip(0xdeadbeef);
  emup_regset(proc, 0x00 | 0x00, &iobuf);
  printf("should be deadbeef: %x\n", eflip(((unsigned int *)proc->regs)[0]));
  iobuf = 0;
  emup_regget(proc, 0x00 | 0x00, &iobuf);
  printf("should be deadbeef: %x\n", eflip(iobuf));
  printf("should not be deadbeef: %x\n", eflip(((unsigned int *)proc->regs)[1]));
  mem[0] = 0x00;
  mem[1] = 0x00 | 0x00;
  mem[2] = 0x08 | 0x00;
  emup_step(proc);
  iobuf = 0;
  emup_regget(proc, 0x08 | 0x00, &iobuf);
  printf("should be deadbeef: %x\n", eflip(iobuf));
  printf("should be same as above: %x\n", eflip(((unsigned int *)proc->regs)[1]));
  mem[3] = 0x00;
  mem[4] = 0x00 | 0x04;
  mem[5] = 0x00 | 0x05;
  mem[6] = 0x00;
  mem[7] = 0x08 | 0x06;
  mem[8] = 0x00 | 0x07;
  emup_step(proc);
  emup_step(proc);
  iobuf = 0;
  emup_regget(proc, 0x00 | 0x00, &iobuf);
  printf("should be dedebebe: %x\n", eflip(iobuf));
  emup_free(proc);
}

variable_types:
mem
unsigned char *

variable_types:
iobuf
unsigned int

user_defined_types: struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; }


imov

decompiled_code:
__int64 __fastcall imov(__int64 a1)
{
__int64 v1; // rax
unsigned __int8 v2; // bp
__int64 result; // rax
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
v1 = *(_QWORD *)(*(_QWORD *)(a1 + 2184) + 16LL) + *(unsigned int *)(a1 + 2176);
v2 = *(_BYTE *)(v1 + 2);
emup_regget(a1, *(unsigned __int8 *)(v1 + 1), v4);
result = emup_regset(a1, v2, v4);
*(_DWORD *)(a1 + 2176) += 3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
unsigned __int8 v2; // bp
__int64 result; // rax
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
v1 = *(_QWORD *)(*(_QWORD *)(a1 + 2184) + 16LL) + *(unsigned int *)(a1 + 2176);
v2 = *(_BYTE *)(v1 + 2);
emup_regget(a1, *(unsigned __int8 *)(v1 + 1), v4);
result = emup_regset(a1, v2, v4);
*(_DWORD *)(a1 + 2176) += 3;
return result;
}

original_code:
void imov(emu_processor* proc)
{
  uint32_t iobuf = 0;
  uint8_t* ip = ((uint8_t*)proc->device->mem) + proc->ip;
  uint8_t src = ip[1];
  uint8_t dst = ip[2];
  emup_regget(proc, src, &iobuf);
  emup_regset(proc, dst, &iobuf);
  proc->ip += 3;
}

canonical_original_code:
void imov(struct emu_processor *proc)
{
  unsigned int iobuf = 0;
  unsigned char *ip = ((uint8_t*)proc->device->mem) + proc->ip;
  unsigned char src = ip[1];
  unsigned char dst = ip[2];
  emup_regget(proc, src, &iobuf);
  emup_regset(proc, dst, &iobuf);
  proc->ip += 3;
}

variable_types:
ip
unsigned char *

variable_types:
src
unsigned char

variable_types:
dst
unsigned char


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
proc_instruction_test(argc, argv, envp);
proc_register_test();
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func2(argc, argv, envp);
func4();
exit(0);
}

original_code:
int main(int argc, char** argv)
{
  proc_instruction_test();
  proc_register_test();
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  proc_instruction_test();
  proc_register_test();
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
int __fastcall pinger_irq_cb(__int64 a1, unsigned int a2)
{
return printf("PING: slot=%d, msg=%d\n", *(unsigned __int8 *)(a1 + 56), a2);
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, unsigned int a2)
{
return printf("PING: slot=%d, msg=%d\n", *(unsigned __int8 *)(a1 + 56), a2);
}

original_code:
void pinger_irq_cb(emu_device* pinger, uint32_t code)
{
  printf("PING: slot=%d, msg=%d\n", pinger->id, code);
}

canonical_original_code:
void pinger_irq_cb(struct emu_device *pinger, unsigned int code)
{
  printf("PING: slot=%d, msg=%d\n", pinger->id, code);
}

variable_types: struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *

variable_types:
code
unsigned int


decompiled_code:
int __fastcall pinger_cc_cb(__int64 a1)
{
return printf("CONNECT: slot=%d\n", *(unsigned __int8 *)(a1 + 56));
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1)
{
return printf("CONNECT: slot=%d\n", *(unsigned __int8 *)(a1 + 56));
}

original_code:
void pinger_cc_cb(emu_device* pinger)
{
  printf("CONNECT: slot=%d\n", pinger->id);
}

canonical_original_code:
void pinger_cc_cb(struct emu_device *pinger)
{
  printf("CONNECT: slot=%d\n", pinger->id);
}


decompiled_code:
void __fastcall free_pinger(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void free_pinger(emu_device* pinger)
{
  free(pinger->mem);
  free(pinger);
}

canonical_original_code:
void free_pinger(struct emu_device *pinger)
{
  free(pinger->mem);
  free(pinger);
}


decompiled_code:
void __fastcall pinger_dc_cb(void *ptr)
{
printf("DISCONNECT: slot=%d\n", *((unsigned __int8 *)ptr + 56));
free_pinger(ptr);
}

canonical_decompiled_code:
void __fastcall func17(void *ptr)
{
printf("DISCONNECT: slot=%d\n", *((unsigned __int8 *)ptr + 56));
func16(ptr);
}

original_code:
void pinger_dc_cb(emu_device* pinger)
{
  printf("DISCONNECT: slot=%d\n", pinger->id);
  free_pinger(pinger);
}

canonical_original_code:
void pinger_dc_cb(struct emu_device *pinger)
{
  printf("DISCONNECT: slot=%d\n", pinger->id);
  free_pinger(pinger);
}


decompiled_code:
_QWORD *create_pinger()
{
_QWORD *v0; // rbx
void *v1; // rax

v0 = malloc(0x40uLL);
v1 = malloc(0x80uLL);
v0[2] = v1;
if ( v1 )
{
*((_DWORD *)v0 + 2) = 128;
v0[3] = pinger_irq_cb;
v0[4] = pinger_cc_cb;
v0[5] = pinger_dc_cb;
v0[6] = 0LL;
}
else
{
free(v0);
v0 = 0LL;
}
return v0;
}

canonical_decompiled_code:
_QWORD *func18()
{
_QWORD *v0; // rbx
void *v1; // rax

v0 = malloc(0x40uLL);
v1 = malloc(0x80uLL);
v0[2] = v1;
if ( v1 )
{
*((_DWORD *)v0 + 2) = 128;
v0[3] = pinger_irq_cb;
v0[4] = pinger_cc_cb;
v0[5] = pinger_dc_cb;
v0[6] = 0LL;
}
else
{
free(v0);
v0 = 0LL;
}
return v0;
}

original_code:
emu_device* create_pinger()
{
  emu_device* pinger = (emu_device*)malloc(sizeof(emu_device));
  pinger->mem = malloc(128);
  if(!pinger->mem)
  {
    free(pinger);
    return ((void *)0);
  }
  pinger->memsize = 128;
  pinger->irq_cb = pinger_irq_cb;
  pinger->cc_cb = pinger_cc_cb;
  pinger->dc_cb = pinger_dc_cb;
  pinger->data = ((void *)0);
  return pinger;
}

canonical_original_code:
struct emu_device *create_pinger()
{
  struct emu_device *pinger = (emu_device*)malloc(sizeof(emu_device));
  pinger->mem = malloc(128);
  if(!pinger->mem)
  {
    free(pinger);
    return ((void *)0);
  }
  pinger->memsize = 128;
  pinger->irq_cb = pinger_irq_cb;
  pinger->cc_cb = pinger_cc_cb;
  pinger->dc_cb = pinger_dc_cb;
  pinger->data = ((void *)0);
  return pinger;
}

return_type: struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *


decompiled_code:
void __fastcall my_disconnect(__int64 a1, unsigned __int8 a2)
{
emub_disconnect(a1, a2);
}

canonical_decompiled_code:
void __fastcall func19(__int64 a1, unsigned __int8 a2)
{
func8(a1, a2);
}

original_code:
void my_disconnect(emu_board* board, uint8_t id)
{
  emub_disconnect(board, id);
}

canonical_original_code:
void my_disconnect(struct emu_device *(*board)[256], unsigned char id)
{
  emub_disconnect(board, id);
}

variable_types: struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *(*)[256]

variable_types:
id
unsigned char


decompiled_code:
void __fastcall my_broadcast(__int64 a1, unsigned int a2)
{
emub_broadcast(a1, a2);
}

canonical_decompiled_code:
void __fastcall func20(__int64 a1, unsigned int a2)
{
func11(a1, a2);
}

original_code:
void my_broadcast(emu_board* board, uint32_t msg)
{
  emub_broadcast(board, msg);
}

canonical_original_code:
void my_broadcast(struct emu_device *(*board)[256], unsigned int msg)
{
  emub_broadcast(board, msg);
}

variable_types:
msg
unsigned int


decompiled_code:
void __fastcall my_send(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
emub_send(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func21(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
func10(a1, a2, a3);
}

original_code:
void my_send(emu_board* board, uint8_t id, uint32_t msg)
{
  emub_send(board, id, msg);
}

canonical_original_code:
void my_send(struct emu_device *(*board)[256], unsigned char id, unsigned int msg)
{
  emub_send(board, id, msg);
}


devicetest

decompiled_code:
void devicetest()
{
_QWORD *v0; // rbp
_QWORD *v1; // r12
_QWORD *v2; // rbx
unsigned int i; // ebx
int j; // ebx

v0 = emub_create();
v1 = create_pinger();
v2 = create_pinger();
printf(">>> we are connecting two pingers, in slots %d and %d\n", 0LL, 1LL);
my_connect((__int64)v0, (__int64)v1, 0);
my_connect((__int64)v0, (__int64)v2, 1u);
puts(">>> we will now broadcast the signals 0 through 10");
for ( i = 0; i != 100; i += 10 )
my_broadcast((__int64)v0, i);
puts(">>> we will now send (255 - n) to each plug n");
for ( j = 0; j != 256; ++j )
my_send((__int64)v0, j, 256 - j);
puts(">>> we will now free the board");
emub_free(v0);
}

canonical_decompiled_code:
void func22()
{
_QWORD *v0; // rbp
_QWORD *v1; // r12
_QWORD *v2; // rbx
unsigned int i; // ebx
int j; // ebx

v0 = func7();
v1 = func18();
v2 = func18();
printf(">>> we are connecting two pingers, in slots %d and %d\n", 0LL, 1LL);
my_connect((__int64)v0, (__int64)v1, 0);
my_connect((__int64)v0, (__int64)v2, 1u);
puts(">>> we will now broadcast the signals 0 through 10");
for ( i = 0; i != 100; i += 10 )
func20((__int64)v0, i);
puts(">>> we will now send (255 - n) to each plug n");
for ( j = 0; j != 256; ++j )
func21((__int64)v0, j, 256 - j);
puts(">>> we will now free the board");
func9(v0);
}

original_code:
void devicetest()
{
  emu_board* b = emub_create();
  emu_device* d1 = create_pinger();
  emu_device* d2 = create_pinger();
  int i;
  int i1 = 0;
  int i2 = 1;
  printf(">>> we are connecting two pingers, in slots %d and %d\n", i1, i2);
  my_connect(b, d1, i1);
  my_connect(b, d2, i2);
  printf(">>> we will now broadcast the signals 0 through 10\n");
  for(i = 0; i < 100; i += 10) my_broadcast(b, i);
  printf(">>> we will now send (255 - n) to each plug n\n");
  for(i = 0; i < 0x100; i++) my_send(b, i, 0x100 - i);
  printf(">>> we will now free the board\n");
  emub_free(b);
}

canonical_original_code:
void devicetest()
{
  struct emu_device *(*b)[256] = emub_create();
  struct emu_device *d1 = create_pinger();
  struct emu_device *d2 = create_pinger();
  int i;
  int i1 = 0;
  int i2 = 1;
  printf(">>> we are connecting two pingers, in slots %d and %d\n", i1, i2);
  my_connect(b, d1, i1);
  my_connect(b, d2, i2);
  printf(">>> we will now broadcast the signals 0 through 10\n");
  for(i = 0; i < 100; i += 10) my_broadcast(b, i);
  printf(">>> we will now send (255 - n) to each plug n\n");
  for(i = 0; i < 0x100; i++) my_send(b, i, 0x100 - i);
  printf(">>> we will now free the board\n");
  emub_free(b);
}

variable_types: i int


freeram

decompiled_code:
void __fastcall freeram(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func23(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void freeram(emu_device* ram)
{
  free(ram->mem);
  free(ram);
}

canonical_original_code:
void freeram(struct emu_device *ram)
{
  free(ram->mem);
  free(ram);
}


decompiled_code:
void __fastcall ram_dc_cb(void *a1)
{
freeram(a1);
}

canonical_decompiled_code:
void __fastcall func24(void *a1)
{
func23(a1);
}

original_code:
static void ram_dc_cb(emu_device* ram)
{
  freeram(ram);
}

canonical_original_code:
static void ram_dc_cb(struct emu_device *ram)
{
  freeram(ram);
}


makeram

original_code:
emu_device* makeram()
{
  emu_device* ram = (emu_device*)malloc(sizeof(emu_device));
  ram->mem = (uint8_t*)malloc(128);
  ram->memsize = 128;
  ram->irq_cb = ((void *)0);
  ram->cc_cb = ((void *)0);
  ram->dc_cb = ram_dc_cb;
  ram->data = ((void *)0);
  return ram;
}

canonical_original_code:
struct emu_device *makeram()
{
  struct emu_device *ram = (emu_device*)malloc(sizeof(emu_device));
  ram->mem = (unsigned char *)malloc(128);
  ram->memsize = 128;
  ram->irq_cb = ((void *)0);
  ram->cc_cb = ((void *)0);
  ram->dc_cb = ram_dc_cb;
  ram->data = ((void *)0);
  return ram;
}


memorytest

decompiled_code:
void memorytest()
{
_QWORD *v0; // rbx
_BYTE *v1; // rbp
_QWORD *v2; // rax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax

v0 = emub_create();
v1 = malloc(0x80uLL);
v2 = makeram();
emub_connect((__int64)v0, (__int64)v2, 0);
v3 = emub_write((__int64)v0, 0, 9, "uberblah");
printf("should be 9: %d\n", v3);
v4 = emub_write((__int64)v0, 8u, 9, "uberblah");
printf("should be 9: %d\n", v4);
v5 = emub_write((__int64)v0, 0x10u, 9, "uberblah");
printf("should be 9: %d\n", v5);
v6 = emub_read((__int64)v0, 0, 28, v1);
printf("should be 28: %d\n", v6);
printf("should be 'uberblahuberblahuberblah': %s\n", v1);
v7 = emub_write((__int64)v0, 0x7Cu, 9, "uberblah");
printf("should be 4: %d\n", v7);
v8 = emub_read((__int64)v0, 0x7Cu, 9, v1 + 4);
printf("should be 4: %d\n", v8);
printf("should be uberuberuberblahuberblah: %s\n", v1);
emub_free(v0);
free(v1);
}

canonical_decompiled_code:
void func26()
{
_QWORD *v0; // rbx
_BYTE *v1; // rbp
_QWORD *v2; // rax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax

v0 = func7();
v1 = malloc(0x80uLL);
v2 = func25();
emub_connect((__int64)v0, (__int64)v2, 0);
v3 = func13((__int64)v0, 0, 9, "uberblah");
printf("should be 9: %d\n", v3);
v4 = func13((__int64)v0, 8u, 9, "uberblah");
printf("should be 9: %d\n", v4);
v5 = func13((__int64)v0, 0x10u, 9, "uberblah");
printf("should be 9: %d\n", v5);
v6 = func12((__int64)v0, 0, 28, v1);
printf("should be 28: %d\n", v6);
printf("should be 'uberblahuberblahuberblah': %s\n", v1);
v7 = func13((__int64)v0, 0x7Cu, 9, "uberblah");
printf("should be 4: %d\n", v7);
v8 = func12((__int64)v0, 0x7Cu, 9, v1 + 4);
printf("should be 4: %d\n", v8);
printf("should be uberuberuberblahuberblah: %s\n", v1);
func9(v0);
free(v1);
}

original_code:
void memorytest()
{
  emu_board* b = emub_create();
  const char* string = "uberblah";
  char* iobuffer = (char*)malloc(128);
  emu_device* ram = makeram();
  emub_connect(b, ram, 0);
  printf("should be 9: %d\n", emub_write(b, 0x000000, 9, (void*)string));
  printf("should be 9: %d\n", emub_write(b, 0x000008, 9, (void*)string));
  printf("should be 9: %d\n", emub_write(b, 0x000010, 9, (void*)string));
  printf("should be 28: %d\n", emub_read(b, 0x000000, 28, (void*)iobuffer));
  printf("should be 'uberblahuberblahuberblah': %s\n", iobuffer);
  printf("should be 4: %d\n", emub_write(b, 124, 9, (void*)string));
  printf("should be 4: %d\n", emub_read(b, 124, 9, (void*)(iobuffer + 4)));
  printf("should be uberuberuberblahuberblah: %s\n", iobuffer);
  emub_free(b);
  free(iobuffer);
}

canonical_original_code:
void memorytest()
{
  struct emu_device *(*b)[256] = emub_create();
  char *string = "uberblah";
  char *iobuffer = (char*)malloc(128);
  struct emu_device *ram = makeram();
  emub_connect(b, ram, 0);
  printf("should be 9: %d\n", emub_write(b, 0x000000, 9, (void *)string));
  printf("should be 9: %d\n", emub_write(b, 0x000008, 9, (void *)string));
  printf("should be 9: %d\n", emub_write(b, 0x000010, 9, (void *)string));
  printf("should be 28: %d\n", emub_read(b, 0x000000, 28, (void *)iobuffer));
  printf("should be 'uberblahuberblahuberblah': %s\n", iobuffer);
  printf("should be 4: %d\n", emub_write(b, 124, 9, (void *)string));
  printf("should be 4: %d\n", emub_read(b, 124, 9, (void *)(iobuffer + 4)));
  printf("should be uberuberuberblahuberblah: %s\n", iobuffer);
  emub_free(b);
  free(iobuffer);
}

variable_types:
string
char *

variable_types:
iobuffer
char *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
devicetest();
memorytest();
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func22();
func26();
exit(0);
}

original_code:
int main(int argc, char** argv)
{
  devicetest();
  memorytest();
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  devicetest();
  memorytest();
  exit(0);
}


repo: uffejakobsen/sysvbanner

original_code:
int main(int argc, char **argv)
{
  int a, b, c, len, ind;
  char line[80];
  for (argv++; --argc; argv++) {
    len = strlen(*argv);
    if (len > 10)
      len = 10;
    for (a = 0; a < 7; a++) {
      for (b = 0; b < len; b++) {
 if ((ind = (*argv)[b] - ' ') < 0)
   ind = 0;
 for (c = 0; c < 7; c++) {
   line[b * 8 + c] = glyphs[(ind / 8 * 7) + a][(ind % 8 * 7) + c];
 }
 line[b * 8 + 7] = ' ';
      }
      for (b = len * 8 - 1; b >= 0; b--) {
 if (line[b] != ' ')
   break;
 line[b] = '\0';
      }
      puts(line);
    }
    puts("");
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int a; int b; int c; int len; int ind;
  char line[80];
  for (argv++; --argc; argv++) {
    len = strlen(*argv);
    if (len > 10)
      len = 10;
    for (a = 0; a < 7; a++) {
      for (b = 0; b < len; b++) {
 if ((ind = (*argv)[b] - ' ') < 0)
   ind = 0;
 for (c = 0; c < 7; c++) {
   line[b * 8 + c] = glyphs[(ind / 8 * 7) + a][(ind % 8 * 7) + c];
 }
 line[b * 8 + 7] = ' ';
      }
      for (b = len * 8 - 1; b >= 0; b--) {
 if (line[b] != ' ')
   break;
 line[b] = '\0';
      }
      puts(line);
    }
    puts("");
  }
  return 0;
}

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: len int

variable_types: ind int

variable_types:
line
char [80]


decompiled_code:
int imprime_mensagem()
{
return puts(s);
}

canonical_decompiled_code:
int func7()
{
return puts(s);
}

original_code:
void imprime_mensagem(){
   printf("Não sei, só sei que foi assim.\n");
}


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

if ( NUMERO_DE_ITERACOES <= 0 )
return 0;
v3 = 0;
do
{
imprime_mensagem();
++v3;
}
while ( NUMERO_DE_ITERACOES > v3 );
return 0;
}

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

if ( NUMERO_DE_ITERACOES <= 0 )
return 0;
v3 = 0;
do
{
func7();
++v3;
}
while ( NUMERO_DE_ITERACOES > v3 );
return 0;
}

original_code:
int main() {
  for (int i=0; i < NUMERO_DE_ITERACOES; i++ ){
    imprime_mensagem();
  }
  return 0;
}

canonical_original_code:
int main() {
  for (int i = 0; i < NUMERO_DE_ITERACOES; i++ ){
    imprime_mensagem();
  }
  return 0;
}


imprimeRecordistas

decompiled_code:
int __fastcall imprimeRecordistas(__int64 a1)
{
int result; // eax
const char *v2; // rbx
int v3; // ebp

result = puts(s);
if ( QUANTIDADE_DA_LISTA > 0 )
{
v2 = (const char *)(a1 + 4);
v3 = 0;
do
{
result = printf("%s %d\n", v2, *((unsigned int *)v2 - 1));
++v3;
v2 += 36;
}
while ( QUANTIDADE_DA_LISTA > v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
int result; // eax
const char *v2; // rbx
int v3; // ebp

result = puts(s);
if ( QUANTIDADE_DA_LISTA > 0 )
{
v2 = (const char *)(a1 + 4);
v3 = 0;
do
{
result = printf("%s %d\n", v2, *((unsigned int *)v2 - 1));
++v3;
v2 += 36;
}
while ( QUANTIDADE_DA_LISTA > v3 );
}
return result;
}

original_code:
void imprimeRecordistas(Jogador* jogadores){
    printf("Os seguintes valores foram lidos do arquivo binário:\n");
    for(int i=0; i<QUANTIDADE_DA_LISTA; i++){
        printf("%s %d\n", jogadores[i].nome, jogadores[i].pontuacao);
    }
}

canonical_original_code:
void imprimeRecordistas(struct Jogador_ *jogadores){
    printf("Os seguintes valores foram lidos do arquivo binário:\n");
    for(int i = 0; i<QUANTIDADE_DA_LISTA; i++){
        printf("%s %d\n", jogadores[i].nome, jogadores[i].pontuacao);
    }
}

variable_types: struct Jogador_ { int pontuacao; char nome[32]; } *


main

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

criaArquivoDeRecordistasIniciais();
v3 = lerArquivoDeRecordistas();
imprimeRecordistas((__int64)v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax

func7();
v3 = func8();
func9((__int64)v3);
return 0;
}

original_code:
int main(void) {
    criaArquivoDeRecordistasIniciais();
    Jogador* recordistas = lerArquivoDeRecordistas();
    imprimeRecordistas(recordistas);
}

canonical_original_code:
int main() {
    criaArquivoDeRecordistasIniciais();
    struct Jogador_ *recordistas = lerArquivoDeRecordistas();
    imprimeRecordistas(recordistas);
}

user_defined_types: struct Jogador_ { int pontuacao; char nome[32]; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rax
char *v4; // rbp
char *v5; // rbx
int *v6; // rbx
unsigned int *v7; // rbx
unsigned int *v8; // rbp
int v10[8]; // [rsp+0h] [rbp-58h] BYREF
int v11[8]; // [rsp+20h] [rbp-38h] BYREF
char v12; // [rsp+40h] [rbp-18h] BYREF

for ( i = 0LL; i != 8; ++i )
{
v11[i] = i;
v10[i] = i + 1;
}
v4 = soma_vet((__int64)v11, (__int64)v10);
v5 = (char *)v11;
do
{
printf("%d\t", *(unsigned int *)v5);
v5 += 4;
}
while ( v5 != &v12 );
putchar(10);
v6 = v10;
do
printf("%d\t", (unsigned int)*v6++);
while ( v11 != v6 );
putchar(10);
v7 = (unsigned int *)v4;
v8 = (unsigned int *)(v4 + 32);
do
printf("%d\t", *v7++);
while ( v8 != v7 );
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rax
char *v4; // rbp
char *v5; // rbx
int *v6; // rbx
unsigned int *v7; // rbx
unsigned int *v8; // rbp
int v10[8]; // [rsp+0h] [rbp-58h] BYREF
int v11[8]; // [rsp+20h] [rbp-38h] BYREF
char v12; // [rsp+40h] [rbp-18h] BYREF

for ( i = 0LL; i != 8; ++i )
{
v11[i] = i;
v10[i] = i + 1;
}
v4 = func7((__int64)v11, (__int64)v10);
v5 = (char *)v11;
do
{
printf("%d\t", *(unsigned int *)v5);
v5 += 4;
}
while ( v5 != &v12 );
putchar(10);
v6 = v10;
do
printf("%d\t", (unsigned int)*v6++);
while ( v11 != v6 );
putchar(10);
v7 = (unsigned int *)v4;
v8 = (unsigned int *)(v4 + 32);
do
printf("%d\t", *v7++);
while ( v8 != v7 );
putchar(10);
return 0;
}

canonical_original_code:
int main() {
  int i; int *ptr1;
  int va[8]; int vb[8];
  for(i=0; i<8; i++) {
    va[i]=i;
    vb[i]=i+1;
  }
  ptr1=soma_vet(va, vb);
  for(i=0; i<8; i++) {
    printf("%d\t", va[i]);
  }
  printf("\n");
  for(i=0; i<8; i++) {
    printf("%d\t", vb[i]);
  }
  printf("\n");
  for(i=0; i<8; i++) {
    printf("%d\t", ptr1[i]);
  }
  printf("\n");
  return 0;
}

variable_types:
va
int [8]

variable_types:
vb
int [8]


decompiled_code:
_QWORD *dynamic_string_init()
{
_QWORD *v0; // rbx

v0 = malloc(0x18uLL);
v0[2] = 1024LL;
v0[1] = 0LL;
*v0 = malloc(0x400uLL);
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rbx

v0 = malloc(0x18uLL);
v0[2] = 1024LL;
v0[1] = 0LL;
*v0 = malloc(0x400uLL);
return v0;
}

original_code:
dynamic_string *dynamic_string_init() {
 dynamic_string *str = (dynamic_string *)malloc(sizeof(dynamic_string));
 str->alloc_size = 1024;
 str->size = 0;
 str->str = (char*)malloc(sizeof(char)*str->alloc_size);
 return str;
}

canonical_original_code:
struct dynamic_string *dynamic_string_init() {
 struct dynamic_string *str = (dynamic_string *)malloc(sizeof(dynamic_string));
 str->alloc_size = 1024;
 str->size = 0;
 str->str = (char *)malloc(sizeof(char)*str->alloc_size);
 return str;
}

variable_types: struct dynamic_string { char *str; unsigned long size; unsigned long alloc_size; } *


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

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

original_code:
void dynamic_string_free(dynamic_string *str) {
 free(str->str);
 free(str);
}

canonical_original_code:
void dynamic_string_free(struct dynamic_string *str) {
 free(str->str);
 free(str);
}

user_defined_types: struct dynamic_string { char *str; unsigned long size; unsigned long alloc_size; }


decompiled_code:
void *__fastcall dynamic_string_append(__int64 a1, const void *a2, size_t a3)
{
__int64 v6; // rdi
unsigned __int64 i; // rsi
void *result; // rax

v6 = *(_QWORD *)(a1 + 8);
for ( i = *(_QWORD *)(a1 + 16); i < v6 + a3; v6 = *(_QWORD *)(a1 + 8) )
{
*(_QWORD *)a1 = realloc(*(void **)a1, 2 * i);
i = 2LL * *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 16) = i;
}
result = memcpy((void *)(*(_QWORD *)a1 + v6), a2, a3);
*(_QWORD *)(a1 + 8) += a3;
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, const void *a2, size_t a3)
{
__int64 v6; // rdi
unsigned __int64 i; // rsi
void *result; // rax

v6 = *(_QWORD *)(a1 + 8);
for ( i = *(_QWORD *)(a1 + 16); i < v6 + a3; v6 = *(_QWORD *)(a1 + 8) )
{
*(_QWORD *)a1 = realloc(*(void **)a1, 2 * i);
i = 2LL * *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 16) = i;
}
result = memcpy((void *)(*(_QWORD *)a1 + v6), a2, a3);
*(_QWORD *)(a1 + 8) += a3;
return result;
}

original_code:
void dynamic_string_append(dynamic_string *str, const char *append, size_t size) {
 while(str->size + size > str->alloc_size) {
  str->str = (char *)realloc((void *)str->str, str->alloc_size*2);
  str->alloc_size *= 2;
 }
 memcpy(((void*)str->str) + str->size, (void *)append, size);
 str->size += size;
}

canonical_original_code:
void dynamic_string_append(struct dynamic_string *str, char *append, unsigned long size) {
 while(str->size + size > str->alloc_size) {
  str->str = (char *)realloc((void *)str->str, str->alloc_size*2);
  str->alloc_size *= 2;
 }
 memcpy(((void *)str->str) + str->size, (void *)append, size);
 str->size += size;
}

variable_types:
append
char *

variable_types:
size
unsigned long


decompiled_code:
void __fastcall dynamic_string_join(__int64 a1, __int64 a2)
{
dynamic_string_append(a1, *(const void **)a2, *(_QWORD *)(a2 + 8));
dynamic_string_free((void *)a2);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2)
{
func2(a1, *(const void **)a2, *(_QWORD *)(a2 + 8));
func1((void *)a2);
}

original_code:
void dynamic_string_join(dynamic_string *joinee, dynamic_string *joiner) {
 dynamic_string_append(joinee, joiner->str, joiner->size);
 dynamic_string_free(joiner);
}

canonical_original_code:
void dynamic_string_join(struct dynamic_string *joinee, struct dynamic_string *joiner) {
 dynamic_string_append(joinee, joiner->str, joiner->size);
 dynamic_string_free(joiner);
}

variable_types:
joiner
struct dynamic_string *


decompiled_code:
__int64 __fastcall ini_linkedQueue(_QWORD *a1)
{
a1[1] = 0LL;
*a1 = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
a1[1] = 0LL;
*a1 = 0LL;
return 1LL;
}

original_code:
char ini_linkedQueue(linked_queue* queue){
  queue->m_front = queue->m_rear = ((void *)0);
  return 1;
}

canonical_original_code:
char ini_linkedQueue(struct linked_queue *queue){
  queue->m_front = queue->m_rear = ((void *)0);
  return 1;
}

variable_types: struct linked_queue { struct queueNode { void *m_data; struct queueNode *m_next; } *m_front; struct queueNode *m_rear; } *

return_type: char

user_defined_types: struct linked_queue { struct queueNode *m_front; struct queueNode *m_rear; }


decompiled_code:
__int64 __fastcall destroy_linkedQueue(__int64 *a1)
{
__int64 i; // rbx

for ( i = *a1; *a1; i = *a1 )
{
*a1 = *(_QWORD *)(i + 8);
if ( *(_QWORD *)i )
free(*(void **)i);
free((void *)i);
}
a1[1] = 0LL;
*a1 = 0LL;
return 1LL;
}

original_code:
char destroy_linkedQueue(linked_queue* queue){
  queueNode* node = ((void *)0);
  while(queue->m_front != ((void *)0)){
    node = queue->m_front;
    queue->m_front = node->m_next;
    if(node->m_data) free(node->m_data);
    free(node);
  }
  queue->m_front = queue->m_rear = ((void *)0);
  return 1;
}

canonical_original_code:
char destroy_linkedQueue(struct linked_queue *queue){
  struct queueNode *node = ((void *)0);
  while(queue->m_front != ((void *)0)){
    node = queue->m_front;
    queue->m_front = node->m_next;
    if(node->m_data) free(node->m_data);
    free(node);
  }
  queue->m_front = queue->m_rear = ((void *)0);
  return 1;
}

variable_types: struct queueNode { void *m_data; struct queueNode *m_next; } *


decompiled_code:
__int64 __fastcall clear_linkedQueue(__int64 a1)
{
_QWORD *v2; // rdi

v2 = *(_QWORD **)a1;
if ( v2 )
{
do
{
*(_QWORD *)a1 = v2[1];
free(v2);
v2 = *(_QWORD **)a1;
}
while ( *(_QWORD *)a1 );
}
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
return 1LL;
}

original_code:
char clear_linkedQueue(linked_queue * queue){
  queueNode* node = ((void *)0);
  while(queue->m_front != ((void *)0)){
    node = queue->m_front;
    queue->m_front = node->m_next;
    free(node);
  }
  queue->m_front = queue->m_rear = ((void *)0);
  return 1;
}

canonical_original_code:
char clear_linkedQueue(struct linked_queue *queue){
  struct queueNode *node = ((void *)0);
  while(queue->m_front != ((void *)0)){
    node = queue->m_front;
    queue->m_front = node->m_next;
    free(node);
  }
  queue->m_front = queue->m_rear = ((void *)0);
  return 1;
}

user_defined_types: struct queueNode { void *m_data; struct queueNode *m_next; }


decompiled_code:
__int64 __fastcall getHead_linkedQueue(_QWORD **a1, _QWORD *a2)
{
if ( !*a1 )
return 0LL;
*a2 = **a1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD **a1, _QWORD *a2)
{
if ( !*a1 )
return 0LL;
*a2 = **a1;
return 1LL;
}

original_code:
char getHead_linkedQueue(linked_queue* queue,void** data){
  if(queue->m_front == ((void *)0)) return 0;
  *data = queue->m_front->m_data;
  return 1;
}

canonical_original_code:
char getHead_linkedQueue(struct linked_queue *queue, void **data){
  if(queue->m_front == ((void *)0)) return 0;
  *data = queue->m_front->m_data;
  return 1;
}

variable_types:
data
void **


decompiled_code:
__int64 __fastcall length_linkedQueue(__int64 *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
v1 = *(_QWORD *)(v1 + 8);
++v2;
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
v1 = *(_QWORD *)(v1 + 8);
++v2;
}
while ( v1 );
return v2;
}

original_code:
unsigned int length_linkedQueue(linked_queue* queue){
  unsigned int len = 0;
  queueNode* node = queue->m_front;
  while(node){
    node = node->m_next; ++len;
  }
  return len;
}

canonical_original_code:
unsigned int length_linkedQueue(struct linked_queue *queue){
  unsigned int len = 0;
  struct queueNode *node = queue->m_front;
  while(node){
    node = node->m_next; ++len;
  }
  return len;
}

variable_types:
len
unsigned int


decompiled_code:
bool __fastcall empty_linkedQueue(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
bool __fastcall func12(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
char empty_linkedQueue(linked_queue * queue){
  if(queue->m_front == ((void *)0)) return 1;
  return 0;
}

canonical_original_code:
char empty_linkedQueue(struct linked_queue *queue){
  if(queue->m_front == ((void *)0)) return 1;
  return 0;
}


decompiled_code:
__int64 __fastcall deQueue_linkedQueue(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

v2 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
*a2 = *v2;
v3 = v2[1];
*(_QWORD *)a1 = v3;
if ( !v3 )
*(_QWORD *)(a1 + 8) = 0LL;
free(v2);
return 1LL;
}

original_code:
char deQueue_linkedQueue(linked_queue* queue,void** data){
  if(queue->m_front == ((void *)0)) return 0;
  queueNode* node = queue->m_front;
  *data = node->m_data;
  queue->m_front = node->m_next;
  if(queue->m_front == ((void *)0)) queue->m_rear = ((void *)0);
  free(node);
  return 1;
}

canonical_original_code:
char deQueue_linkedQueue(struct linked_queue *queue, void **data){
  if(queue->m_front == ((void *)0)) return 0;
  struct queueNode *node = queue->m_front;
  *data = node->m_data;
  queue->m_front = node->m_next;
  if(queue->m_front == ((void *)0)) queue->m_rear = ((void *)0);
  free(node);
  return 1;
}


original_code:
char enQueue_linkedQueue(linked_queue* queue,void* data){
  queueNode* node = (queueNode*)malloc(sizeof(queueNode));
  if(node == ((void *)0)) return -2;
  node->m_data = data; node->m_next = ((void *)0);
  if(queue->m_front == ((void *)0)){
    queue->m_front = queue->m_rear = node;
    return 1;
  }
  queue->m_rear->m_next = node;
  queue->m_rear = node;
  return 1;
}

canonical_original_code:
char enQueue_linkedQueue(struct linked_queue *queue, void *data){
  struct queueNode *node = (queueNode*)malloc(sizeof(queueNode));
  if(node == ((void *)0)) return -2;
  node->m_data = data; node->m_next = ((void *)0);
  if(queue->m_front == ((void *)0)){
    queue->m_front = queue->m_rear = node;
    return 1;
  }
  queue->m_rear->m_next = node;
  queue->m_rear = node;
  return 1;
}

variable_types:
data
void *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
_DWORD *v4; // rax
int v5; // ebx
unsigned int *v7; // [rsp+8h] [rbp-20h] BYREF
__int64 v8[3]; // [rsp+10h] [rbp-18h] BYREF

ini_linkedQueue(v8);
for ( i = 0; i != 100; ++i )
{
v4 = malloc(4uLL);
*v4 = i;
enQueue_linkedQueue(v8, (__int64)v4);
}
getHead_linkedQueue((_QWORD **)v8, &v7);
printf("%d\n", *v7);
v5 = 110;
do
{
deQueue_linkedQueue((__int64)v8, &v7);
printf("%d\t", *v7);
--v5;
}
while ( v5 );
putchar(10);
destroy_linkedQueue(v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
_DWORD *v4; // rax
int v5; // ebx
unsigned int *v7; // [rsp+8h] [rbp-20h] BYREF
__int64 v8[3]; // [rsp+10h] [rbp-18h] BYREF

func7(v8);
for ( i = 0; i != 100; ++i )
{
v4 = malloc(4uLL);
*v4 = i;
func14(v8, (__int64)v4);
}
func10((_QWORD **)v8, &v7);
printf("%d\n", *v7);
v5 = 110;
do
{
func13((__int64)v8, &v7);
printf("%d\t", *v7);
--v5;
}
while ( v5 );
putchar(10);
func8(v8);
return 0;
}

original_code:
int main(){
  linked_queue queue;
  ini_linkedQueue(&queue);
  int i = 0;
  for(i = 0;i < 100;i++){
    int * data = (int *) malloc(sizeof(int));
    *data = i;
    enQueue_linkedQueue(&queue,(void *)data);
  }
  int * data;
  getHead_linkedQueue(&queue,(void **)&data);
  printf("%d\n",*data);
  for(i = 0;i < 110;i++){
    deQueue_linkedQueue(&queue,(void **)&data);
    printf("%d\t",*data);
  }
  printf("\n");
  destroy_linkedQueue(&queue);
  return 0;
}

canonical_original_code:
int main(){
  struct linked_queue queue;
  ini_linkedQueue(&queue);
  int i = 0;
  for(i = 0;i < 100;i++){
    int *data = (int *) malloc(sizeof(int));
    *data = i;
    enQueue_linkedQueue(&queue,(void *)data);
  }
  int *data;
  getHead_linkedQueue(&queue,(void **)&data);
  printf("%d\n",*data);
  for(i = 0;i < 110;i++){
    deQueue_linkedQueue(&queue,(void **)&data);
    printf("%d\t",*data);
  }
  printf("\n");
  destroy_linkedQueue(&queue);
  return 0;
}

variable_types: struct linked_queue { struct queueNode { void *m_data; struct queueNode *m_next; } *m_front; struct queueNode *m_rear; }

variable_types: i int

variable_types:
data
int *


original_code:
char destroy_seqList(seq_list* list){
  if(list->m_pList == ((void *)0)) return 0;
  free(list->m_pList); list->m_pList = ((void *)0);
  list->m_listSize = list->m_maxListSize = 0;
}

canonical_original_code:
char destroy_seqList(struct seq_list *list){
  if(list->m_pList == ((void *)0)) return 0;
  free(list->m_pList); list->m_pList = ((void *)0);
  list->m_listSize = list->m_maxListSize = 0;
}

variable_types: struct seq_list { int m_listSize; int m_maxListSize; int *m_pList; } *


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

v1 = malloc(0x190uLL);
*(_QWORD *)(a1 + 8) = v1;
if ( v1 )
{
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 100;
result = 1LL;
}
else
{
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)a1 = 0;
result = 4294967294LL;
}
return result;
}

original_code:
char ini_seqList(seq_list* list){
  list->m_pList=(int *)malloc(sizeof(int) * 100);
  if(list->m_pList == ((void *)0)){
    list->m_listSize = list->m_maxListSize = 0;
    return -2;
  }
  list->m_listSize = 0;list->m_maxListSize = 100;
  return 1;
}

canonical_original_code:
char ini_seqList(struct seq_list *list){
  list->m_pList=(int *)malloc(sizeof(int) * 100);
  if(list->m_pList == ((void *)0)){
    list->m_listSize = list->m_maxListSize = 0;
    return -2;
  }
  list->m_listSize = 0;list->m_maxListSize = 100;
  return 1;
}

user_defined_types: struct seq_list { int m_listSize; int m_maxListSize; int *m_pList; }


original_code:
char ins_seqList(seq_list* list,const int i,const int ele){
  if(i < 0||i > (list->m_listSize))
  return 0;
  if(list->m_listSize >= list->m_maxListSize){
    int * pEle = (int*) realloc(list->m_pList,(list->m_maxListSize + 100)
    * sizeof(int));
    if(!pEle){
        return -2;
    }
    list->m_pList = pEle;
    list->m_maxListSize += 100;
  }
  int j;
  for(j = list->m_listSize;j > i;j--){
    list->m_pList[j] = list->m_pList[j-1];
  }
  list->m_pList[j]=ele;
  list->m_listSize++;
  return 1;
}

canonical_original_code:
char ins_seqList(struct seq_list *list, int i, int ele){
  if(i < 0||i > (list->m_listSize))
  return 0;
  if(list->m_listSize >= list->m_maxListSize){
    int *pEle = (int*) realloc(list->m_pList,(list->m_maxListSize + 100)
    * sizeof(int));
    if(!pEle){
        return -2;
    }
    list->m_pList = pEle;
    list->m_maxListSize += 100;
  }
  int j;
  for(j = list->m_listSize;j > i;j--){
    list->m_pList[j] = list->m_pList[j-1];
  }
  list->m_pList[j]=ele;
  list->m_listSize++;
  return 1;
}

variable_types: ele int

variable_types:
pEle
int *

variable_types: j int


decompiled_code:
__int64 __fastcall insBack_seqList(int *a1, int a2)
{
return ins_seqList(a1, *a1, a2);
}

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

original_code:
char insBack_seqList(seq_list* list,const int ele){
  return ins_seqList(list,list->m_listSize,ele);
}

canonical_original_code:
char insBack_seqList(struct seq_list *list, int ele){
  return ins_seqList(list,list->m_listSize,ele);
}


original_code:
char del_seqList(seq_list* list,const int i,int* ele){
  if(i < 0 || i >= list->m_listSize) return 0;
  int j=0;
  for(j = i;j < list->m_listSize;j++){
    *ele = list->m_pList[j];
    list->m_pList[j]=list->m_pList[j+1];
  }
  list->m_listSize--;
  return 1;
}

canonical_original_code:
char del_seqList(struct seq_list *list, int i, int *ele){
  if(i < 0 || i >= list->m_listSize) return 0;
  int j = 0;
  for(j = i;j < list->m_listSize;j++){
    *ele = list->m_pList[j];
    list->m_pList[j]=list->m_pList[j+1];
  }
  list->m_listSize--;
  return 1;
}

variable_types:
ele
int *


decompiled_code:
__int64 __fastcall delBack_seqList(int *a1, _DWORD *a2)
{
return del_seqList((__int64)a1, *a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(int *a1, _DWORD *a2)
{
return func11((__int64)a1, *a1, a2);
}

original_code:
char delBack_seqList(seq_list* list,int* ele){
  return del_seqList(list,list->m_listSize,ele);
}

canonical_original_code:
char delBack_seqList(struct seq_list *list, int *ele){
  return del_seqList(list,list->m_listSize,ele);
}


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

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)a1 > a2 )
{
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * a2);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)a1 > a2 )
{
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * a2);
result = 1LL;
}
return result;
}

original_code:
char getEle_seqList(const seq_list* list,const int i,int *ele){
  if(i < 0|| i >= list->m_listSize) return 0;
  *ele = list->m_pList[i];
  return 1;
}

canonical_original_code:
char getEle_seqList(struct seq_list *list, int i, int *ele){
  if(i < 0|| i >= list->m_listSize) return 0;
  *ele = list->m_pList[i];
  return 1;
}


decompiled_code:
__int64 __fastcall getBackEle_seqList(_DWORD *a1, _DWORD *a2)
{
return getEle_seqList((__int64)a1, *a1 - 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1, _DWORD *a2)
{
return func13((__int64)a1, *a1 - 1, a2);
}

original_code:
char getBackEle_seqList(const seq_list* list,int *ele){
  return getEle_seqList(list,list->m_listSize-1,ele);
}

canonical_original_code:
char getBackEle_seqList(struct seq_list *list, int *ele){
  return getEle_seqList(list,list->m_listSize-1,ele);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
int j; // ebx
int k; // ebx
unsigned int v7; // [rsp+Ch] [rbp-1Ch] BYREF
int v8[6]; // [rsp+10h] [rbp-18h] BYREF

ini_seqList((__int64)v8);
for ( i = 0; i != 105; ++i )
{
if ( (unsigned __int8)ins_seqList(v8, i, i) != 1 )
exit(0);
}
for ( j = 0; j != 105; ++j )
{
if ( (unsigned __int8)insBack_seqList(v8, j) != 1 )
exit(0);
}
del_seqList((__int64)v8, 20, &v7);
ins_seqList(v8, 12, 50);
for ( k = 0; k != 211; ++k )
{
getEle_seqList((__int64)v8, k, &v7);
printf("%d ", v7);
}
destroy_seqList((__int64)v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
int j; // ebx
int k; // ebx
unsigned int v7; // [rsp+Ch] [rbp-1Ch] BYREF
int v8[6]; // [rsp+10h] [rbp-18h] BYREF

func8((__int64)v8);
for ( i = 0; i != 105; ++i )
{
if ( (unsigned __int8)func9(v8, i, i) != 1 )
exit(0);
}
for ( j = 0; j != 105; ++j )
{
if ( (unsigned __int8)func10(v8, j) != 1 )
exit(0);
}
func11((__int64)v8, 20, &v7);
func9(v8, 12, 50);
for ( k = 0; k != 211; ++k )
{
func13((__int64)v8, k, &v7);
printf("%d ", v7);
}
func7((__int64)v8);
return 0;
}

original_code:
int main(){
  seq_list list;
  ini_seqList(&list);
  int i;
  for(i = 0;i < 105;i++){
    if(ins_seqList(&list,i,i) != 1){
        exit(0);
    }
  }
  for(i = 0;i < 105;i++){
    if(insBack_seqList(&list,i) != 1){
        exit(0);
    }
  }
  int ele;
  del_seqList(&list,20,&ele);
  ins_seqList(&list,12,50);
  for(i=0;i<211;i++){
    getEle_seqList(&list,i,&ele);
    printf("%d ",ele);
  }
  destroy_seqList(&list);
  return 0;
}

canonical_original_code:
int main(){
  struct seq_list list;
  ini_seqList(&list);
  int i;
  for(i = 0;i < 105;i++){
    if(ins_seqList(&list,i,i) != 1){
        exit(0);
    }
  }
  for(i = 0;i < 105;i++){
    if(insBack_seqList(&list,i) != 1){
        exit(0);
    }
  }
  int ele;
  del_seqList(&list,20,&ele);
  ins_seqList(&list,12,50);
  for(i=0;i<211;i++){
    getEle_seqList(&list,i,&ele);
    printf("%d ",ele);
  }
  destroy_seqList(&list);
  return 0;
}

variable_types: struct seq_list { int m_listSize; int m_maxListSize; int *m_pList; }


original_code:
char ini_seqQueue(seqQueue* queue){
  void ** p = (void **) malloc(sizeof(void *) * 100);
  if(p == ((void *)0)) return -2;
  queue->m_base = p; queue->m_maxSize = 100;
  queue->m_front = queue->m_rear = 0;
  return 1;
}

canonical_original_code:
char ini_seqQueue(struct seqQueue *queue){
  void **p = (void **) malloc(sizeof(void *) * 100);
  if(p == ((void *)0)) return -2;
  queue->m_base = p; queue->m_maxSize = 100;
  queue->m_front = queue->m_rear = 0;
  return 1;
}

variable_types: struct seqQueue { void **m_base; unsigned int m_front; unsigned int m_rear; unsigned int m_maxSize; } *

variable_types:
p
void **


original_code:
char destroy_seqQueue(seqQueue* queue){
  if(queue->m_base == ((void *)0)) return 0;
  while(queue->m_front != queue->m_rear){
    if(queue->m_base[queue->m_front] != ((void *)0)) free(queue->m_base[queue->m_front]);
    queue->m_front = (queue->m_front + 1) % queue->m_maxSize;
  }
  free(queue->m_base); queue->m_base = ((void *)0);
  queue->m_front = queue->m_rear = queue->m_maxSize = 0;
  return 1;
}

canonical_original_code:
char destroy_seqQueue(struct seqQueue *queue){
  if(queue->m_base == ((void *)0)) return 0;
  while(queue->m_front != queue->m_rear){
    if(queue->m_base[queue->m_front] != ((void *)0)) free(queue->m_base[queue->m_front]);
    queue->m_front = (queue->m_front + 1) % queue->m_maxSize;
  }
  free(queue->m_base); queue->m_base = ((void *)0);
  queue->m_front = queue->m_rear = queue->m_maxSize = 0;
  return 1;
}

user_defined_types: struct seqQueue { void **m_base; unsigned int m_front; unsigned int m_rear; unsigned int m_maxSize; }


decompiled_code:
__int64 __fastcall length_seqQueue(_DWORD *a1)
{
unsigned int v1; // edx
unsigned int v2; // eax
unsigned int v3; // ecx

v1 = a1[2];
v2 = a1[3];
v3 = v2 - v1;
if ( v1 > v2 )
v3 = a1[4] + v2 - v1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1)
{
unsigned int v1; // edx
unsigned int v2; // eax
unsigned int v3; // ecx

v1 = a1[2];
v2 = a1[3];
v3 = v2 - v1;
if ( v1 > v2 )
v3 = a1[4] + v2 - v1;
return v3;
}

original_code:
unsigned int length_seqQueue(seqQueue* queue){
  if(queue->m_front > queue->m_rear){
    return queue->m_maxSize - queue->m_front + queue->m_rear;
  }else{
    return queue->m_rear - queue->m_front;
  }
}

canonical_original_code:
unsigned int length_seqQueue(struct seqQueue *queue){
  if(queue->m_front > queue->m_rear){
    return queue->m_maxSize - queue->m_front + queue->m_rear;
  }else{
    return queue->m_rear - queue->m_front;
  }
}


decompiled_code:
__int64 __fastcall getHead_seqQueue(__int64 a1, _QWORD *a2)
{
unsigned int v2; // eax
unsigned int v3; // ecx

if ( !*(_QWORD *)a1 )
return 0;
v2 = *(_DWORD *)(a1 + 8);
v3 = 0;
if ( v2 != *(_DWORD *)(a1 + 12) )
{
*a2 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v2);
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, _QWORD *a2)
{
unsigned int v2; // eax
unsigned int v3; // ecx

if ( !*(_QWORD *)a1 )
return 0;
v2 = *(_DWORD *)(a1 + 8);
v3 = 0;
if ( v2 != *(_DWORD *)(a1 + 12) )
{
*a2 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v2);
v3 = 1;
}
return v3;
}

original_code:
char getHead_seqQueue(seqQueue* queue,void ** data){
  if(queue->m_base == ((void *)0) || queue->m_front == queue->m_rear) return 0;
  *data = queue->m_base[queue->m_front];
  return 1;
}

canonical_original_code:
char getHead_seqQueue(struct seqQueue *queue, void **data){
  if(queue->m_base == ((void *)0) || queue->m_front == queue->m_rear) return 0;
  *data = queue->m_base[queue->m_front];
  return 1;
}


original_code:
char enQueue_seqQueue(seqQueue* queue,void * data){
  if(queue->m_base == ((void *)0)) return 0;
  if((queue->m_rear + 1) % queue->m_maxSize == queue->m_front){
    void * p = (void *) realloc(queue->m_base,(queue->m_maxSize + 100) * sizeof(void *));
    if(p == ((void *)0)) return -2;
    queue->m_base = p; queue->m_maxSize += 100;
  }
  queue->m_base[queue->m_rear] = data;
  queue->m_rear = (queue->m_rear + 1) %queue->m_maxSize;
  return 1;
}

canonical_original_code:
char enQueue_seqQueue(struct seqQueue *queue, void *data){
  if(queue->m_base == ((void *)0)) return 0;
  if((queue->m_rear + 1) % queue->m_maxSize == queue->m_front){
    void *p = (void *) realloc(queue->m_base,(queue->m_maxSize + 100) * sizeof(void *));
    if(p == ((void *)0)) return -2;
    queue->m_base = p; queue->m_maxSize += 100;
  }
  queue->m_base[queue->m_rear] = data;
  queue->m_rear = (queue->m_rear + 1) %queue->m_maxSize;
  return 1;
}

variable_types:
p
void *


decompiled_code:
__int64 __fastcall deQueue_seqQueue(__int64 a1, _QWORD *a2)
{
unsigned int v2; // eax
unsigned int v3; // ecx

if ( !*(_QWORD *)a1 )
return 0;
v2 = *(_DWORD *)(a1 + 8);
v3 = 0;
if ( v2 != *(_DWORD *)(a1 + 12) )
{
*a2 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v2);
*(_DWORD *)(a1 + 8) = (unsigned int)(*(_DWORD *)(a1 + 8) + 1) % *(_DWORD *)(a1 + 16);
v3 = 1;
}
return v3;
}

original_code:
char deQueue_seqQueue(seqQueue* queue,void ** data){
  if(queue->m_base == ((void *)0) || queue->m_front == queue->m_rear) return 0;
  *data = queue->m_base[queue->m_front];
  queue->m_front = (queue->m_front + 1) % queue->m_maxSize;
  return 1;
}

canonical_original_code:
char deQueue_seqQueue(struct seqQueue *queue, void **data){
  if(queue->m_base == ((void *)0) || queue->m_front == queue->m_rear) return 0;
  *data = queue->m_base[queue->m_front];
  queue->m_front = (queue->m_front + 1) % queue->m_maxSize;
  return 1;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
_DWORD *v4; // rax
int v5; // ebx
int j; // ebx
_DWORD *v7; // rax
int v8; // ebx
unsigned int *v10; // [rsp+8h] [rbp-30h] BYREF
char v11[40]; // [rsp+10h] [rbp-28h] BYREF

ini_seqQueue((__int64)v11);
for ( i = 0; i != 111; ++i )
{
v4 = malloc(4uLL);
*v4 = i;
enQueue_seqQueue((__int64)v11, (__int64)v4);
}
v10 = 0LL;
getHead_seqQueue((__int64)v11, &v10);
printf("%d \n", *v10);
v5 = 20;
do
{
deQueue_seqQueue((__int64)v11, &v10);
printf("%d ", *v10);
--v5;
}
while ( v5 );
putchar(10);
for ( j = 0; j != 101; ++j )
{
v7 = malloc(4uLL);
*v7 = j;
enQueue_seqQueue((__int64)v11, (__int64)v7);
}
v8 = 200;
do
{
deQueue_seqQueue((__int64)v11, &v10);
printf("%d ", *v10);
--v8;
}
while ( v8 );
destroy_seqQueue((__int64)v11);
return 0;
}

original_code:
int main(){
  seqQueue queue;
  ini_seqQueue(&queue);
  int i = 0;
  for(i = 0;i < 111; i++){
    int * p = (int *) malloc(sizeof(int));
    *p = i;
    enQueue_seqQueue(&queue,(void *) p);
  }
  int * p = ((void *)0);
  getHead_seqQueue(&queue,(void **)&p);
  printf("%d \n",*p);
  for(i = 0;i<20;i++){
    deQueue_seqQueue(&queue,(void **)&p);
    printf("%d ",*p);
  }
  printf("\n");
  for(i = 0;i < 101; i++){
    int * p = (int *) malloc(sizeof(int));
    *p = i;
    enQueue_seqQueue(&queue,(void *) p);
  }
  for(i = 0;i < 200;i++){
    deQueue_seqQueue(&queue,(void **)&p);
    printf("%d ",*p);
  }
  destroy_seqQueue(&queue);
  return 0;
}

canonical_original_code:
int main(){
  struct seqQueue queue;
  ini_seqQueue(&queue);
  int i = 0;
  for(i = 0;i < 111; i++){
    int *p = (int *) malloc(sizeof(int));
    *p = i;
    enQueue_seqQueue(&queue,(void *) p);
  }
  int *p = ((void *)0);
  getHead_seqQueue(&queue,(void **)&p);
  printf("%d \n",*p);
  for(i = 0;i<20;i++){
    deQueue_seqQueue(&queue,(void **)&p);
    printf("%d ",*p);
  }
  printf("\n");
  for(i = 0;i < 101; i++){
    int *p = (int *) malloc(sizeof(int));
    *p = i;
    enQueue_seqQueue(&queue,(void *) p);
  }
  for(i = 0;i < 200;i++){
    deQueue_seqQueue(&queue,(void **)&p);
    printf("%d ",*p);
  }
  destroy_seqQueue(&queue);
  return 0;
}

variable_types: struct seqQueue { void **m_base; unsigned int m_front; unsigned int m_rear; unsigned int m_maxSize; }

variable_types:
p
int *


original_code:
char ini_seqStack(seqStack * stack){
  int* p = (int*) malloc(sizeof(seqStack)*100);
  if(p == ((void *)0)) return -2;
  stack->m_top = stack->m_base = p;
  stack->m_stackSize = 0;
  stack->m_maxStackSize = 100;
  return 1;
}

canonical_original_code:
char ini_seqStack(struct seqStack *stack){
  int *p = (int*) malloc(sizeof(seqStack)*100);
  if(p == ((void *)0)) return -2;
  stack->m_top = stack->m_base = p;
  stack->m_stackSize = 0;
  stack->m_maxStackSize = 100;
  return 1;
}

variable_types: struct seqStack { int *m_top; int *m_base; unsigned int m_stackSize; unsigned int m_maxStackSize; } *


decompiled_code:
__int64 __fastcall destroy_seqStack(__int64 a1)
{
void *v2; // rdi
__int64 result; // rax

v2 = *(void **)(a1 + 8);
result = 0LL;
if ( v2 )
{
free(v2);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 20) = 0;
*(_DWORD *)(a1 + 16) = 0;
result = 1LL;
}
return result;
}

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

v2 = *(void **)(a1 + 8);
result = 0LL;
if ( v2 )
{
free(v2);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 20) = 0;
*(_DWORD *)(a1 + 16) = 0;
result = 1LL;
}
return result;
}

original_code:
char destroy_seqStack(seqStack* stack){
  if(stack->m_base == ((void *)0)) return 0;
  free(stack->m_base);
  stack->m_base = stack->m_top = ((void *)0);
  stack->m_stackSize = stack->m_maxStackSize = 0;
  return 1;
}

canonical_original_code:
char destroy_seqStack(struct seqStack *stack){
  if(stack->m_base == ((void *)0)) return 0;
  free(stack->m_base);
  stack->m_base = stack->m_top = ((void *)0);
  stack->m_stackSize = stack->m_maxStackSize = 0;
  return 1;
}

user_defined_types: struct seqStack { int *m_top; int *m_base; unsigned int m_stackSize; unsigned int m_maxStackSize; }


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

*(_DWORD *)(a1 + 16) = 0;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)a1 = result;
return result;
}

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

*(_DWORD *)(a1 + 16) = 0;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)a1 = result;
return result;
}

original_code:
char clear_seqStack(seqStack* stack){
  stack->m_stackSize = 0;
  stack->m_top = stack->m_base;
}

canonical_original_code:
char clear_seqStack(struct seqStack *stack){
  stack->m_stackSize = 0;
  stack->m_top = stack->m_base;
}


decompiled_code:
__int64 __fastcall getTop_seqStack(_QWORD *a1, _DWORD *a2)
{
if ( a1[1] == *a1 )
return 0LL;
*a2 = *(_DWORD *)(*a1 - 4LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, _DWORD *a2)
{
if ( a1[1] == *a1 )
return 0LL;
*a2 = *(_DWORD *)(*a1 - 4LL);
return 1LL;
}

original_code:
char getTop_seqStack(seqStack* stack,int* ele){
  if(stack->m_base == stack->m_top) return 0;
  int* p = stack->m_top;
  *ele = *--p;
  return 1;
}

canonical_original_code:
char getTop_seqStack(struct seqStack *stack, int *ele){
  if(stack->m_base == stack->m_top) return 0;
  int *p = stack->m_top;
  *ele = *--p;
  return 1;
}


original_code:
char pop_seqStack(seqStack* stack,int* ele){
  if(stack->m_base == stack->m_top) return 0;
  stack->m_top--;
  *ele = *stack->m_top;
  --stack->m_stackSize;
  return 1;
}

canonical_original_code:
char pop_seqStack(struct seqStack *stack, int *ele){
  if(stack->m_base == stack->m_top) return 0;
  stack->m_top--;
  *ele = *stack->m_top;
  --stack->m_stackSize;
  return 1;
}


decompiled_code:
__int64 __fastcall length_seqStack(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
unsigned int length_seqStack(seqStack* stack){
  return stack->m_stackSize;
}

canonical_original_code:
unsigned int length_seqStack(struct seqStack *stack){
  return stack->m_stackSize;
}


original_code:
char push_seqStack(seqStack* stack,const int ele){
  if(stack->m_stackSize >= stack->m_maxStackSize){
    int* pTemp = (int*) realloc(stack->m_base,(stack->m_maxStackSize + 100) * sizeof(int));
    if(pTemp == ((void *)0)) return -2;
    stack->m_base = pTemp;
    stack->m_maxStackSize += 100;
  }
  *stack->m_top++ = ele;
  stack->m_stackSize += 1;
  return 1;
}

canonical_original_code:
char push_seqStack(struct seqStack *stack, int ele){
  if(stack->m_stackSize >= stack->m_maxStackSize){
    int *pTemp = (int*) realloc(stack->m_base,(stack->m_maxStackSize + 100) * sizeof(int));
    if(pTemp == ((void *)0)) return -2;
    stack->m_base = pTemp;
    stack->m_maxStackSize += 100;
  }
  *stack->m_top++ = ele;
  stack->m_stackSize += 1;
  return 1;
}

variable_types:
pTemp
int *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // esi
int j; // esi
unsigned int v6; // [rsp+8h] [rbp-30h] BYREF
unsigned int k; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v8[5]; // [rsp+10h] [rbp-28h] BYREF

ini_seqStack((__int64)v8);
k = 0;
for ( i = 0; i <= 119; k = i )
{
push_seqStack((__int64)v8, i);
i = k + 1;
}
getTop_seqStack(v8, &k);
printf("%d \n", k);
k = 0;
for ( j = 0; j <= 119; k = j )
{
push_seqStack((__int64)v8, j);
j = k + 1;
}
v6 = 0;
for ( k = 0; (int)k <= 269; ++k )
{
pop_seqStack(v8, &v6);
printf("%d ", v6);
}
putchar(10);
clear_seqStack((__int64)v8);
destroy_seqStack((__int64)v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // esi
int j; // esi
unsigned int v6; // [rsp+8h] [rbp-30h] BYREF
unsigned int k; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v8[5]; // [rsp+10h] [rbp-28h] BYREF

func7((__int64)v8);
k = 0;
for ( i = 0; i <= 119; k = i )
{
func13((__int64)v8, i);
i = k + 1;
}
func10(v8, &k);
printf("%d \n", k);
k = 0;
for ( j = 0; j <= 119; k = j )
{
func13((__int64)v8, j);
j = k + 1;
}
v6 = 0;
for ( k = 0; (int)k <= 269; ++k )
{
func11(v8, &v6);
printf("%d ", v6);
}
putchar(10);
func9((__int64)v8);
func8((__int64)v8);
return 0;
}

original_code:
int main(){
  seqStack stack;
  ini_seqStack(&stack);
  int i = 0;
  for(i = 0;i < 120;i++){
    push_seqStack(&stack,i);
  }
  getTop_seqStack(&stack,&i);
  printf("%d \n",i);
  for(i = 0;i < 120;i++){
    push_seqStack(&stack,i);
  }
  int j = 0;
  for(i = 0;i < 270;i++){
    pop_seqStack(&stack,&j);
    printf("%d ",j);
  }
  printf("\n");
  clear_seqStack(&stack);
  destroy_seqStack(&stack);
  return 0;
}

canonical_original_code:
int main(){
  struct seqStack stack;
  ini_seqStack(&stack);
  int i = 0;
  for(i = 0;i < 120;i++){
    push_seqStack(&stack,i);
  }
  getTop_seqStack(&stack,&i);
  printf("%d \n",i);
  for(i = 0;i < 120;i++){
    push_seqStack(&stack,i);
  }
  int j = 0;
  for(i = 0;i < 270;i++){
    pop_seqStack(&stack,&j);
    printf("%d ",j);
  }
  printf("\n");
  clear_seqStack(&stack);
  destroy_seqStack(&stack);
  return 0;
}

variable_types: struct seqStack { int *m_top; int *m_base; unsigned int m_stackSize; unsigned int m_maxStackSize; }


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

result = 3LL;
if ( *a1 <= *a2 )
{
LOBYTE(result) = *a1 != *a2;
result = (unsigned int)(2 * result + 2);
}
return result;
}

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

result = 3LL;
if ( *a1 <= *a2 )
{
LOBYTE(result) = *a1 != *a2;
result = (unsigned int)(2 * result + 2);
}
return result;
}

original_code:
char compare_for_int(void * a,void * b){
  int * pa = (int *) a;
  int * pb = (int *) b;
  if(*pa > *pb){
 return 3;
  }else if(*pa == *pb){
 return 2;
  }else{
 return 4;
  }
}

canonical_original_code:
char compare_for_int(void *a, void *b){
  int *pa = (int *) a;
  int *pb = (int *) b;
  if(*pa > *pb){
 return 3;
  }else if(*pa == *pb){
 return 2;
  }else{
 return 4;
  }
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
pa
int *

variable_types:
pb
int *


myPrint

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

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

original_code:
void myPrint(void * a){
  int * pa = (int *) a;
  printf("%d\t",*pa);
}

canonical_original_code:
void myPrint(void *a){
  int *pa = (int *) a;
  printf("%d\t",*pa);
}


repo: ultramailman/iniparser

decompiled_code:
_QWORD *varstr_new()
{
_QWORD *v0; // rbx
void *v1; // rax

v0 = calloc(1uLL, 0x18uLL);
if ( v0 )
{
v1 = calloc(1uLL, 1uLL);
if ( v1 )
{
*v0 = 1LL;
v0[2] = v1;
}
else
{
free(v0);
v0 = 0LL;
}
}
return v0;
}

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

v0 = calloc(1uLL, 0x18uLL);
if ( v0 )
{
v1 = calloc(1uLL, 1uLL);
if ( v1 )
{
*v0 = 1LL;
v0[2] = v1;
}
else
{
free(v0);
v0 = 0LL;
}
}
return v0;
}

original_code:
struct varstr * varstr_new(void)
{
 struct varstr * newstr = calloc(1, sizeof *newstr);
 if(newstr != ((void *)0))
 {
  char * buf = calloc(1, 1);
  if(buf != ((void *)0))
  {
   newstr->buflen = 1;
   newstr->buf = buf;
  }
  else
  {
   free(newstr);
   newstr = ((void *)0);
  }
 }
 return newstr;
}

canonical_original_code:
struct varstr *varstr_new()
{
 struct varstr *newstr = calloc(1, sizeof *newstr);
 if(newstr != ((void *)0))
 {
  char *buf = calloc(1, 1);
  if(buf != ((void *)0))
  {
   newstr->buflen = 1;
   newstr->buf = buf;
  }
  else
  {
   free(newstr);
   newstr = ((void *)0);
  }
 }
 return newstr;
}

variable_types: struct varstr { unsigned long buflen; char *buf; } *

variable_types:
buf
char *


decompiled_code:
void __fastcall varstr_del(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 2));
free(ptr);
}
}

original_code:
void varstr_del(struct varstr * str)
{
 if(str != ((void *)0))
 {
  free(str->buf);
  free(str);
 }
}

canonical_original_code:
void varstr_del(struct varstr *str)
{
 if(str != ((void *)0))
 {
  free(str->buf);
  free(str);
 }
}

user_defined_types: struct varstr { unsigned long buflen; char *buf; }


decompiled_code:
__int64 __fastcall varstr_len(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
unsigned long varstr_len(struct varstr const * str)
{
 return str->len;
}

canonical_original_code:
unsigned long varstr_len(struct varstr *str)
{
 return str->len;
}

return_type: unsigned long


original_code:
int varstr_append(struct varstr * str, char c)
{
 if(str->len + 1 == str->buflen)
 {
  char * newbuf = realloc(str->buf, str->buflen * 2);
  if(newbuf != ((void *)0))
  {
   str->buf = newbuf;
   str->buflen *= 2;
  }
  else
   return -1;
 }
 str->buf[str->len] = c;
 str->len++;
 str->buf[str->len] = 0;
 return 0;
}

canonical_original_code:
int varstr_append(struct varstr *str, char c)
{
 if(str->len + 1 == str->buflen)
 {
  char *newbuf = realloc(str->buf, str->buflen * 2);
  if(newbuf != ((void *)0))
  {
   str->buf = newbuf;
   str->buflen *= 2;
  }
  else
   return -1;
 }
 str->buf[str->len] = c;
 str->len++;
 str->buf[str->len] = 0;
 return 0;
}

variable_types: c char

variable_types:
newbuf
char *


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

if ( *(_QWORD *)(a1 + 8) <= a2 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)*(char *)(*(_QWORD *)(a1 + 16) + a2);
return result;
}

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

if ( *(_QWORD *)(a1 + 8) <= a2 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)*(char *)(*(_QWORD *)(a1 + 16) + a2);
return result;
}

original_code:
int varstr_get(struct varstr * str, unsigned long i)
{
 if(i < str->len)
  return str->buf[i];
 else
  return -1;
}

canonical_original_code:
int varstr_get(struct varstr *str, unsigned long i)
{
 if(i < str->len)
  return str->buf[i];
 else
  return -1;
}

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall varstr_set(__int64 a1, unsigned __int64 a2, char a3)
{
if ( *(_QWORD *)(a1 + 8) <= a2 )
return 0xFFFFFFFFLL;
*(_BYTE *)(*(_QWORD *)(a1 + 16) + a2) = a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int64 a2, char a3)
{
if ( *(_QWORD *)(a1 + 8) <= a2 )
return 0xFFFFFFFFLL;
*(_BYTE *)(*(_QWORD *)(a1 + 16) + a2) = a3;
return 0LL;
}

original_code:
int varstr_set(struct varstr * str, unsigned long i, char c)
{
 if(i < str->len)
 {
  str->buf[i] = c;
  return 0;
 }
 else
  return -1;
}

canonical_original_code:
int varstr_set(struct varstr *str, unsigned long i, char c)
{
 if(i < str->len)
 {
  str->buf[i] = c;
  return 0;
 }
 else
  return -1;
}


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

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

original_code:
char const * varstr_view(struct varstr * str)
{
 return str->buf;
}

canonical_original_code:
char *varstr_view(struct varstr *str)
{
 return str->buf;
}

return_type: char *


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

if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
return (unsigned int)(a1 - 87);
result = (unsigned int)(a1 - 55);
if ( (unsigned __int8)(a1 - 65) >= 0x1Au )
result = 0xFFFFFFFFLL;
return result;
}

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

if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
return (unsigned int)(a1 - 87);
result = (unsigned int)(a1 - 55);
if ( (unsigned __int8)(a1 - 65) >= 0x1Au )
result = 0xFFFFFFFFLL;
return result;
}


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

LOBYTE(result) = *a1;
if ( !*a1 )
return 0LL;
while ( a2 != (_BYTE)result )
{
result = (unsigned __int8)*++a1;
if ( !(_BYTE)result )
return result;
}
return 1LL;
}

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

LOBYTE(result) = *a1;
if ( !*a1 )
return 0LL;
while ( a2 != (_BYTE)result )
{
result = (unsigned __int8)*++a1;
if ( !(_BYTE)result )
return result;
}
return 1LL;
}

original_code:
_Bool cstr_has(char const * cstr, char c)
{
 while(*cstr != 0)
 {
  if(*cstr == c)
   return 1;
  cstr++;
 }
 return 0;
}

canonical_original_code:
_Bool cstr_has(char *cstr, char c)
{
 while(*cstr != 0)
 {
  if(*cstr == c)
   return 1;
  cstr++;
 }
 return 0;
}

variable_types:
cstr
char *


decompiled_code:
__int64 __fastcall cstr_remove_trailing(char *a1, _BYTE *a2)
{
char *i; // r12
char v3; // bp
__int64 result; // rax
int v5; // ebx
__int64 v6; // rdx
int v7; // ebx
char *v8; // rbp

for ( i = a1; ; ++i )
{
v3 = *i;
result = cstr_has(a2, *i);
if ( !(_BYTE)result )
break;
}
if ( i == a1 )
{
result = 1LL;
v7 = -1;
if ( !*a1 )
goto LABEL_13;
do
v5 = result++;
while ( a1[result - 1] );
}
else
{
if ( v3 )
{
result = 1LL;
do
{
a1[result - 1] = v3;
v5 = result;
v6 = result++;
v3 = i[result - 1];
}
while ( v3 );
}
else
{
v5 = 0;
v6 = 0LL;
}
a1[v6] = 0;
}
v7 = v5 - 1;
if ( v7 >= 0 )
{
v8 = &a1[v7];
do
{
result = cstr_has(a2, *v8);
if ( !(_BYTE)result )
break;
--v7;
--v8;
}
while ( v7 != -1 );
}
LABEL_13:
a1[v7 + 1] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, _BYTE *a2)
{
char *i; // r12
char v3; // bp
__int64 result; // rax
int v5; // ebx
__int64 v6; // rdx
int v7; // ebx
char *v8; // rbp

for ( i = a1; ; ++i )
{
v3 = *i;
result = func1(a2, *i);
if ( !(_BYTE)result )
break;
}
if ( i == a1 )
{
result = 1LL;
v7 = -1;
if ( !*a1 )
goto LABEL_13;
do
v5 = result++;
while ( a1[result - 1] );
}
else
{
if ( v3 )
{
result = 1LL;
do
{
a1[result - 1] = v3;
v5 = result;
v6 = result++;
v3 = i[result - 1];
}
while ( v3 );
}
else
{
v5 = 0;
v6 = 0LL;
}
a1[v6] = 0;
}
v7 = v5 - 1;
if ( v7 >= 0 )
{
v8 = &a1[v7];
do
{
result = func1(a2, *v8);
if ( !(_BYTE)result )
break;
--v7;
--v8;
}
while ( v7 != -1 );
}
LABEL_13:
a1[v7 + 1] = 0;
return result;
}

original_code:
void cstr_remove_trailing(char * cstr, char const * charset)
{
 char * begin = cstr;
 while(cstr_has(charset, *begin))
  begin++;
 int i = 0;
 if(cstr != begin)
 {
  for(; begin[i] != 0; i++)
   cstr[i] = begin[i];
  cstr[i] = 0;
 }
 else
 {
  while(cstr[i] != 0)
   i++;
 }
 i--;
 while(i >= 0 && cstr_has(charset, cstr[i]))
  i--;
 cstr[i + 1] = 0;
}

canonical_original_code:
void cstr_remove_trailing(char *cstr, char *charset)
{
 char *begin = cstr;
 while(cstr_has(charset, *begin))
  begin++;
 int i = 0;
 if(cstr != begin)
 {
  for(; begin[i] != 0; i++)
   cstr[i] = begin[i];
  cstr[i] = 0;
 }
 else
 {
  while(cstr[i] != 0)
   i++;
 }
 i--;
 while(i >= 0 && cstr_has(charset, cstr[i]))
  i--;
 cstr[i + 1] = 0;
}

variable_types:
charset
char *

variable_types:
begin
char *

variable_types: i int


decompiled_code:
__int64 __fastcall cstr_chomp(char *a1)
{
return cstr_remove_trailing(a1, byte_454);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
return func2(a1, byte_454);
}

original_code:
void cstr_chomp(char * cstr)
{
 cstr_remove_trailing(cstr, " \t\n");
}

canonical_original_code:
void cstr_chomp(char *cstr)
{
 cstr_remove_trailing(cstr, " \t\n");
}