decompiled_code:
__int64 __fastcall fmt_ulonglong(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v3; // rdx
__int64 v4; // rdi
unsigned __int64 v5; // rcx
__int64 v6; // rcx
__int64 v7; // r9

if ( a2 <= 9 )
{
v6 = a1 + 1;
v4 = 1LL;
if ( !a1 )
return v4;
goto LABEL_6;
}
v3 = a2;
v4 = 1LL;
do
{
v5 = v3;
v3 /= 0xAuLL;
++v4;
}
while ( v5 > 0x63 );
if ( a1 )
{
v6 = a1 + v4;
if ( v4 )
{
LABEL_6:
v7 = v6 - v4;
do
{
*(_BYTE *)--v6 = a2 % 0xA + 48;
a2 /= 0xAuLL;
}
while ( v6 != v7 );
return v4;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v3; // rdx
__int64 v4; // rdi
unsigned __int64 v5; // rcx
__int64 v6; // rcx
__int64 v7; // r9

if ( a2 <= 9 )
{
v6 = a1 + 1;
v4 = 1LL;
if ( !a1 )
return v4;
goto LABEL_6;
}
v3 = a2;
v4 = 1LL;
do
{
v5 = v3;
v3 /= 0xAuLL;
++v4;
}
while ( v5 > 0x63 );
if ( a1 )
{
v6 = a1 + v4;
if ( v4 )
{
LABEL_6:
v7 = v6 - v4;
do
{
*(_BYTE *)--v6 = a2 % 0xA + 48;
a2 /= 0xAuLL;
}
while ( v6 != v7 );
return v4;
}
}
return v4;
}

original_code:
size_t fmt_ulonglong(char *dest, unsigned long long int i)
{
  register unsigned long len;
  unsigned long long tmp, len2;
  for (len = 1, tmp = i; tmp > 9; ++len)
    tmp /= 10;
  if (dest)
    for (tmp = i, dest += len, len2 = len + 1; --len2; tmp /= 10)
      *--dest = (tmp % 10) + '0';
  return len;
}

canonical_original_code:
unsigned long fmt_ulonglong(char *dest, unsigned long long i)
{
  register unsigned long len;
  unsigned long long tmp; unsigned long long len2;
  for (len = 1, tmp = i; tmp > 9; ++len)
    tmp /= 10;
  if (dest)
    for (tmp = i, dest += len, len2 = len + 1; --len2; tmp /= 10)
      *--dest = (tmp % 10) + '0';
  return len;
}

variable_types:
dest
char *

variable_types:
i
unsigned long long

variable_types:
len
unsigned long

variable_types:
tmp
unsigned long long


repo: tenchman/gsclu

decompiled_code:
__int64 __fastcall std_write(__int64 a1, const void *a2, size_t a3)
{
int v3; // ebx

v3 = -1;
if ( !timedout )
{
alarm(*(_DWORD *)(a1 + 64));
v3 = write(*(_DWORD *)a1, a2, a3);
alarm(0);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const void *a2, size_t a3)
{
int v3; // ebx

v3 = -1;
if ( !timedout )
{
alarm(*(_DWORD *)(a1 + 64));
v3 = write(*(_DWORD *)a1, a2, a3);
alarm(0);
}
return v3;
}

original_code:
static ssize_t std_write(connection_t * c, char *buf, size_t n)
{
  int r = 0;
  if (timedout)
    r = -1;
  else {
    alarm(c->timeout);
    r = write(c->sockfd, buf, n);
    alarm(0);
  }
  return r;
}

canonical_original_code:
static long std_write(struct connection_s *c, char *buf, unsigned long n)
{
  int r = 0;
  if (timedout)
    r = -1;
  else {
    alarm(c->timeout);
    r = write(c->sockfd, buf, n);
    alarm(0);
  }
  return r;
}

variable_types: struct connection_s { int sockfd; int postfd; int outfd; int conffd; int httpversion; int code; char *outfile; char *caFile; char *ccFile; char *ckFile; char *cwd; int timeout; int method; char *postdata; unsigned long postlen; char *uri; struct destination_t { char *host; char *auth; int port; } *remote; struct destination_t *proxy; struct response_header_t { char *reasonstr; char *location; char *digest; unsigned long contentlength; unsigned long chunklength; unsigned long bodylength; unsigned long totallength; unsigned long headerlength; int chunked; int reason; } *response; void *ssl; char *ressource; struct GTtimer_t { struct timeval { long tv_sec; long tv_usec; } start; struct timeval stop; unsigned long elapsed; } connect_timer; struct GTtimer_t timer; long (*write)(struct connection_s *, char *, unsigned long); long (*read)(struct connection_s *, char *, unsigned long); unsigned int verbosity; unsigned int flags; } *

variable_types:
buf
char *

variable_types:
n
unsigned long

variable_types: r int

return_type: long

user_defined_types: struct connection_s { int sockfd; int postfd; int outfd; int conffd; int httpversion; int code; char *outfile; char *caFile; char *ccFile; char *ckFile; char *cwd; int timeout; int method; char *postdata; unsigned long postlen; char *uri; struct destination_t *remote; struct destination_t *proxy; struct response_header_t *response; void *ssl; char *ressource; struct GTtimer_t connect_timer; struct GTtimer_t timer; long (*write)(struct connection_s *, char *, unsigned long); long (*read)(struct connection_s *, char *, unsigned long); unsigned int verbosity; unsigned int flags; }

user_defined_types: struct GTtimer_t { struct timeval start; struct timeval stop; unsigned long elapsed; }


decompiled_code:
__int64 __fastcall std_read(__int64 a1, void *a2, size_t a3)
{
int v3; // ebx

v3 = -1;
if ( !timedout )
{
alarm(*(_DWORD *)(a1 + 64));
v3 = read(*(_DWORD *)a1, a2, a3);
alarm(0);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, void *a2, size_t a3)
{
int v3; // ebx

v3 = -1;
if ( !timedout )
{
alarm(*(_DWORD *)(a1 + 64));
v3 = read(*(_DWORD *)a1, a2, a3);
alarm(0);
}
return v3;
}

original_code:
static ssize_t std_read(connection_t * c, char *buf, size_t n)
{
  int r = -1;
  if (!timedout) {
    alarm(c->timeout);
    r = read(c->sockfd, buf, n);
    alarm(0);
  }
  return r;
}

canonical_original_code:
static long std_read(struct connection_s *c, char *buf, unsigned long n)
{
  int r = -1;
  if (!timedout) {
    alarm(c->timeout);
    r = read(c->sockfd, buf, n);
    alarm(0);
  }
  return r;
}

user_defined_types: struct destination_t { char *host; char *auth; int port; }

user_defined_types: struct response_header_t { char *reasonstr; char *location; char *digest; unsigned long contentlength; unsigned long chunklength; unsigned long bodylength; unsigned long totallength; unsigned long headerlength; int chunked; int reason; }

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


decompiled_code:
__int64 __fastcall do_write(__int64 a1, __int64 a2, const void *a3, int a4)
{
__int64 v5; // r12
ssize_t v6; // rbp

v5 = a4;
v6 = write(*(_DWORD *)(a1 + 8), a3, a4);
if ( v5 != v6 )
die_write(a1);
if ( (*(_BYTE *)(a1 + 236) & 2) != 0 )
mbedtls_md5_update(a2, a3, v6);
if ( *(_DWORD *)(a1 + 232) > 3u )
write2f("DOWRITE: wrote %d bytes\n", v6);
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, const void *a3, int a4)
{
__int64 v5; // r12
ssize_t v6; // rbp

v5 = a4;
v6 = write(*(_DWORD *)(a1 + 8), a3, a4);
if ( v5 != v6 )
die_write(a1);
if ( (*(_BYTE *)(a1 + 236) & 2) != 0 )
mbedtls_md5_update(a2, a3, v6);
if ( *(_DWORD *)(a1 + 232) > 3u )
write2f("DOWRITE: wrote %d bytes\n", v6);
return (unsigned int)v6;
}

original_code:
int do_write(connection_t * conn, mbedtls_md5_context * ctx, const char *buf, int len)
{
  ssize_t w;
  if ((w = write(conn->outfd, buf, len)) != len)
    die_write(conn);
  if (conn->flags & (1<<1))
    mbedtls_md5_update(ctx, (unsigned char *) buf, w);
  if (conn->verbosity >= 4)
    write2f("DOWRITE: wrote %d bytes\n", w);
  return w;
}

canonical_original_code:
int do_write(struct connection_s *conn, struct mbedtls_md5_context *ctx, char *buf, int len)
{
  long w;
  if ((w = write(conn->outfd, buf, len)) != len)
    die_write(conn);
  if (conn->flags & (1<<1))
    mbedtls_md5_update(ctx, (unsigned char *) buf, w);
  if (conn->verbosity >= 4)
    write2f("DOWRITE: wrote %d bytes\n", w);
  return w;
}

variable_types: struct mbedtls_md5_context { unsigned int total[2]; unsigned int state[4]; unsigned char buffer[64]; } *

variable_types: len int

variable_types: w long

return_type: int


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

va_start(va, a2);
*(_DWORD *)(a1 + 8) = 0;
return (int)strbuf_vappendf(a1, a2, va);
}

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

va_start(va, a2);
*(_DWORD *)(a1 + 8) = 0;
return (int)strbuf_vappendf(a1, a2, va);
}

original_code:
size_t strbuf_putf(strbuf_t * strbuf, const char *format, ...)
{
  va_list ap;
  int retval;
  __builtin_va_start(ap,format);
  strbuf->len = 0;
  retval = strbuf_vappendf(strbuf, format, ap);
  __builtin_va_end(ap);
  return retval;
}

canonical_original_code:
unsigned long strbuf_putf(struct strbuf_t *strbuf, char *format, ...)
{
  __builtin_va_list ap;
  int retval;
  __builtin_va_start(ap,format);
  strbuf->len = 0;
  retval = strbuf_vappendf(strbuf, format, ap);
  __builtin_va_end(ap);
  return retval;
}

variable_types: struct strbuf_t { char *s; unsigned int len; unsigned int total; } *

variable_types:
format
char *

variable_types: retval int

return_type: unsigned long


original_code:
size_t str_eol(const char *line, size_t * len)
{
  char *tmp = (char *) line;
  int c;
  size_t incr = 0;
  while ((c = *tmp)) {
    if (c == '\n' || c == '\r') {
      if ((tmp[1] == '\n' || tmp[1] == '\r') && tmp[1] != c)
 incr = 2;
      else
 incr = 1;
      break;
    }
    ++tmp;
  }
  if (len)
    *len = incr;
  return tmp - line;
}

canonical_original_code:
unsigned long str_eol(char *line, unsigned long *len)
{
  char *tmp = (char *) line;
  int c;
  unsigned long incr = 0;
  while ((c = *tmp)) {
    if (c == '\n' || c == '\r') {
      if ((tmp[1] == '\n' || tmp[1] == '\r') && tmp[1] != c)
 incr = 2;
      else
 incr = 1;
      break;
    }
    ++tmp;
  }
  if (len)
    *len = incr;
  return tmp - line;
}

variable_types:
line
char *

variable_types:
len
unsigned long *

variable_types:
tmp
char *

variable_types: c int

variable_types:
incr
unsigned long


tohex

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

result = (unsigned int)(a1 + 48);
if ( (char)a1 >= 10 )
result = (unsigned int)(a1 + 87);
return result;
}

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

result = (unsigned int)(a1 + 48);
if ( (char)a1 >= 10 )
result = (unsigned int)(a1 + 87);
return result;
}

original_code:
static inline char tohex(char c)
{
  return c >= 10 ? c - 10 + 'a' : c + '0';
}

variable_types: c char

return_type: char


decompiled_code:
__int64 __fastcall fmt_xlong(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rbp

v2 = a2;
if ( a2 <= 0xF )
{
v4 = 1LL;
}
else
{
v3 = a2;
v4 = 1LL;
do
{
v3 >>= 4;
++v4;
}
while ( v3 > 0xF );
}
if ( a1 )
{
v5 = a1 + v4;
do
{
*(_BYTE *)--v5 = tohex(v2 & 0xF);
v2 >>= 4;
}
while ( v2 );
}
return v4;
}

original_code:
size_t fmt_xlong(char *dest, unsigned long i)
{
  register unsigned long len, tmp;
  for (len = 1, tmp = i; tmp > 15; ++len)
    tmp >>= 4;
  if (dest)
    for (tmp = i, dest += len;;) {
      *--dest = tohex(tmp & 15);
      if (!(tmp >>= 4))
 break;
    }
  return len;
}

canonical_original_code:
unsigned long fmt_xlong(char *dest, unsigned long i)
{
  register unsigned long len; register unsigned long tmp;
  for (len = 1, tmp = i; tmp > 15; ++len)
    tmp >>= 4;
  if (dest)
    for (tmp = i, dest += len;;) {
      *--dest = tohex(tmp & 15);
      if (!(tmp >>= 4))
 break;
    }
  return len;
}

variable_types:
dest
char *

variable_types:
i
unsigned long

variable_types:
len
unsigned long

variable_types:
tmp
unsigned long


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

result = 0LL;
if ( a2 )
{
v3 = strlen(a2);
result = strbuf_nappends(a1, a2, v3);
}
return result;
}

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

result = 0LL;
if ( a2 )
{
v3 = strlen(a2);
result = strbuf_nappends(a1, a2, v3);
}
return result;
}

original_code:
size_t strbuf_appends(strbuf_t * strbuf, const char *s)
{
  size_t len = 0;
  if (s) {
    len = strlen(s);
    return strbuf_nappends(strbuf, s, len);
  }
  return len;
}

canonical_original_code:
unsigned long strbuf_appends(struct strbuf_t *strbuf, char *s)
{
  unsigned long len = 0;
  if (s) {
    len = strlen(s);
    return strbuf_nappends(strbuf, s, len);
  }
  return len;
}

variable_types:
s
char *

user_defined_types: struct strbuf_t { char *s; unsigned int len; unsigned int total; }


decompiled_code:
__int64 __fastcall timer_stop(struct timeval *a1)
{
__suseconds_t v1; // rax
__suseconds_t v2; // rdx
__suseconds_t v3; // rsi
__int64 result; // rax

gettimeofday(a1 + 1, 0LL);
v1 = a1[1].tv_usec;
v2 = a1->tv_usec;
if ( v1 < v2 )
{
a1[1].tv_usec = v1 + 1000000;
--a1[1].tv_sec;
}
v3 = a1[1].tv_usec - v2;
result = 0x20C49BA5E353F7CFLL * v3;
a1[2].tv_sec = v3 / 1000 + 1000 * (a1[1].tv_sec - a1->tv_sec);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(struct timeval *a1)
{
__suseconds_t v1; // rax
__suseconds_t v2; // rdx
__suseconds_t v3; // rsi
__int64 result; // rax

gettimeofday(a1 + 1, 0LL);
v1 = a1[1].tv_usec;
v2 = a1->tv_usec;
if ( v1 < v2 )
{
a1[1].tv_usec = v1 + 1000000;
--a1[1].tv_sec;
}
v3 = a1[1].tv_usec - v2;
result = 0x20C49BA5E353F7CFLL * v3;
a1[2].tv_sec = v3 / 1000 + 1000 * (a1[1].tv_sec - a1->tv_sec);
return result;
}

original_code:
void timer_stop(GTtimer_t * timer)
{
  gettimeofday(&timer->stop, (struct timezone *) 0);
  if (timer->stop.tv_usec < timer->start.tv_usec) {
    timer->stop.tv_usec += 1000000;
    timer->stop.tv_sec--;
  }
  timer->elapsed = (timer->stop.tv_usec - timer->start.tv_usec) / 1000;
  timer->elapsed += (timer->stop.tv_sec - timer->start.tv_sec) * 1000;
}

canonical_original_code:
void timer_stop(struct GTtimer_t *timer)
{
  gettimeofday(&timer->stop, (struct timezone *) 0);
  if (timer->stop.tv_usec < timer->start.tv_usec) {
    timer->stop.tv_usec += 1000000;
    timer->stop.tv_sec--;
  }
  timer->elapsed = (timer->stop.tv_usec - timer->start.tv_usec) / 1000;
  timer->elapsed += (timer->stop.tv_sec - timer->start.tv_sec) * 1000;
}

variable_types: struct GTtimer_t { struct timeval { long tv_sec; long tv_usec; } start; struct timeval stop; unsigned long elapsed; } *

return_type: void

user_defined_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


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

va_start(va, a2);
return (int)strbuf_vappendf(a1, a2, va);
}

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

va_start(va, a2);
return (int)strbuf_vappendf(a1, a2, va);
}

original_code:
size_t strbuf_appendf(strbuf_t * strbuf, const char *format, ...)
{
  va_list ap;
  int retval;
  __builtin_va_start(ap,format);
  retval = strbuf_vappendf(strbuf, format, ap);
  __builtin_va_end(ap);
  return retval;
}

canonical_original_code:
unsigned long strbuf_appendf(struct strbuf_t *strbuf, char *format, ...)
{
  __builtin_va_list ap;
  int retval;
  __builtin_va_start(ap,format);
  retval = strbuf_vappendf(strbuf, format, ap);
  __builtin_va_end(ap);
  return retval;
}


decompiled_code:
int __fastcall timer_start(struct timeval *a1)
{
a1[2].tv_sec = 0LL;
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(struct timeval *a1)
{
a1[2].tv_sec = 0LL;
return gettimeofday(a1, 0LL);
}

original_code:
void timer_start(GTtimer_t * timer)
{
  timer->elapsed = 0;
  gettimeofday(&timer->start, (struct timezone *) 0);
}

canonical_original_code:
void timer_start(struct GTtimer_t *timer)
{
  timer->elapsed = 0;
  gettimeofday(&timer->start, (struct timezone *) 0);
}


decompiled_code:
__int64 __fastcall strbuf_puts(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
return strbuf_appends();
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
return strbuf_appends();
}

original_code:
size_t strbuf_puts(strbuf_t * strbuf, const char *s)
{
  strbuf->len = 0;
  return strbuf_appends(strbuf, s);
}

canonical_original_code:
unsigned long strbuf_puts(struct strbuf_t *strbuf, char *s)
{
  strbuf->len = 0;
  return strbuf_appends(strbuf, s);
}


decompiled_code:
__int64 __fastcall fmt_xlonglong(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // r12
int v3; // ebp

v2 = a1;
v3 = 0;
if ( HIDWORD(a2) )
{
v3 = ((__int64 (*)(void))fmt_xlong)();
if ( a1 )
v2 = a1 + v3;
}
return fmt_xlong(v2, (unsigned int)a2) + v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // r12
int v3; // ebp

v2 = a1;
v3 = 0;
if ( HIDWORD(a2) )
{
v3 = ((__int64 (*)(void))fmt_xlong)();
if ( a1 )
v2 = a1 + v3;
}
return fmt_xlong(v2, (unsigned int)a2) + v3;
}

original_code:
size_t fmt_xlonglong(char *dest, unsigned long long i)
{
  int tmp = 0;
  if (i >> 32) {
    tmp = fmt_xlong(dest, i >> 32);
    if (dest)
      dest += tmp;
  }
  return tmp + fmt_xlong(dest, i & 0xffffffff);
}

canonical_original_code:
unsigned long fmt_xlonglong(char *dest, unsigned long long i)
{
  int tmp = 0;
  if (i >> 32) {
    tmp = fmt_xlong(dest, i >> 32);
    if (dest)
      dest += tmp;
  }
  return tmp + fmt_xlong(dest, i & 0xffffffff);
}

variable_types:
i
unsigned long long

variable_types: tmp int


decompiled_code:
void *__fastcall tio_tls_error(unsigned int a1)
{
memset(&tio_buf, 0, 0x400uLL);
mbedtls_strerror(a1, &tio_buf, 1024LL);
return &tio_buf;
}

canonical_decompiled_code:
void *__fastcall func4(unsigned int a1)
{
memset(&tio_buf, 0, 0x400uLL);
mbedtls_strerror(a1, &tio_buf, 1024LL);
return &tio_buf;
}

original_code:
static char *tio_tls_error(int ret)
{
  memset(tio_buf, 0, sizeof(tio_buf));
  mbedtls_strerror(ret, (char *) tio_buf, sizeof(tio_buf));
  return tio_buf;
}

variable_types: ret int

return_type: char *


decompiled_code:
__int64 __fastcall tio_connect(_DWORD *a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
int v4; // [rsp+Ch] [rbp-2Ch] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

snprintf(s, 0x10uLL, "%d", a3);
v4 = 0;
result = mbedtls_net_connect(&v4, a2, s, 0LL);
if ( !(_DWORD)result )
*a1 = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_DWORD *a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
int v4; // [rsp+Ch] [rbp-2Ch] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

snprintf(s, 0x10uLL, "%d", a3);
v4 = 0;
result = mbedtls_net_connect(&v4, a2, s, 0LL);
if ( !(_DWORD)result )
*a1 = v4;
return result;
}

original_code:
int tio_connect(int *fd, const char *server, int port)
{
  int ret = -1;
  char sport[16];
  snprintf(sport, sizeof(sport), "%d", port);
  mbedtls_net_context ctx = {};
  if (0 == (ret = mbedtls_net_connect(&ctx, server, sport, 0)))
    *fd = ctx.fd;
  return ret;
}

canonical_original_code:
int tio_connect(int *fd, char *server, int port)
{
  int ret = -1;
  char sport[16];
  snprintf(sport, sizeof(sport), "%d", port);
  struct mbedtls_net_context ctx = {};
  if (0 == (ret = mbedtls_net_connect(&ctx, server, sport, 0)))
    *fd = ctx.fd;
  return ret;
}

variable_types:
fd
int *

variable_types:
server
char *

variable_types: port int

variable_types:
sport
char [16]

variable_types:
ctx
struct mbedtls_net_context { int fd; }


getcaseenv

decompiled_code:
const char *__fastcall getcaseenv(char *s2)
{
char **v1; // rbp
unsigned int v2; // eax
const char *v3; // rbx
char **v4; // rbp
size_t v5; // r12

v1 = _environ;
if ( !s2 || !_environ )
return 0LL;
v2 = strlen(s2);
v3 = *v1;
if ( *v1 )
{
v4 = v1 + 1;
v5 = v2;
while ( strncasecmp(v3, s2, v5) || v3[v5] != 61 )
{
v3 = *v4++;
if ( !v3 )
return v3;
}
v3 += v5 + 1;
}
return v3;
}

canonical_decompiled_code:
const char *__fastcall func0(char *s2)
{
char **v1; // rbp
unsigned int v2; // eax
const char *v3; // rbx
char **v4; // rbp
size_t v5; // r12

v1 = _environ;
if ( !s2 || !_environ )
return 0LL;
v2 = strlen(s2);
v3 = *v1;
if ( *v1 )
{
v4 = v1 + 1;
v5 = v2;
while ( strncasecmp(v3, s2, v5) || v3[v5] != 61 )
{
v3 = *v4++;
if ( !v3 )
return v3;
}
v3 += v5 + 1;
}
return v3;
}

original_code:
char *getcaseenv(const char *s)
{
  int i;
  unsigned int len;
  if (((void *)0) == __environ || ((void *)0) == s)
    return ((void *)0);
  len = strlen(s);
  for (i = 0; __environ[i]; ++i)
    if (0 == (strncasecmp(__environ[i], s, len)) && ('=' == __environ[i][len]))
      return __environ[i] + len + 1;
  return ((void *)0);
}

canonical_original_code:
char *getcaseenv(char *s)
{
  int i;
  unsigned int len;
  if (((void *)0) == __environ || ((void *)0) == s)
    return ((void *)0);
  len = strlen(s);
  for (i = 0; __environ[i]; ++i)
    if (0 == (strncasecmp(__environ[i], s, len)) && ('=' == __environ[i][len]))
      return __environ[i] + len + 1;
  return ((void *)0);
}

variable_types: i int

variable_types:
len
unsigned int


decompiled_code:
__int64 __fastcall strbuf_appendcn(__int64 a1, char a2, size_t a3)
{
void *v4; // rax
void *v5; // rbx
__int64 v6; // rbp

v4 = malloc(a3 + 1);
if ( !v4 )
return 0LL;
v5 = v4;
memset(v4, a2, a3);
v6 = strbuf_nappends(a1, v5, a3);
free(v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, size_t a3)
{
void *v4; // rax
void *v5; // rbx
__int64 v6; // rbp

v4 = malloc(a3 + 1);
if ( !v4 )
return 0LL;
v5 = v4;
memset(v4, a2, a3);
v6 = strbuf_nappends(a1, v5, a3);
free(v5);
return v6;
}

original_code:
size_t strbuf_appendcn(strbuf_t * strbuf, const char c, const size_t n)
{
  char *tmp = malloc(n + 1);
  size_t len = 0;
  if (tmp) {
    memset(tmp, c, n);
    len = strbuf_nappends(strbuf, tmp, n);
    free(tmp);
  }
  return len;
}

canonical_original_code:
unsigned long strbuf_appendcn(struct strbuf_t *strbuf, char c, unsigned long n)
{
  char *tmp = malloc(n + 1);
  unsigned long len = 0;
  if (tmp) {
    memset(tmp, c, n);
    len = strbuf_nappends(strbuf, tmp, n);
    free(tmp);
  }
  return len;
}

variable_types: struct strbuf_t { char *s; unsigned int len; unsigned int total; } *

variable_types: c char

variable_types:
n
unsigned long

variable_types:
tmp
char *


decompiled_code:
__int64 __fastcall strbuf_realloc(__int64 a1, size_t a2)
{
void *v3; // rdi
size_t v4; // rbx
__int64 result; // rax
void *v6; // rax

v3 = *(void **)a1;
v4 = a2;
LOBYTE(v4) = -1;
if ( v3 )
{
v4 = a2 + *(unsigned int *)(a1 + 8);
LOBYTE(v4) = -1;
}
result = -1LL;
if ( v4 >= a2 )
{
v6 = realloc(v3, v4);
if ( v6 )
{
*(_QWORD *)a1 = v6;
*(_DWORD *)(a1 + 12) = v4;
result = 0LL;
}
else
{
result = -1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, size_t a2)
{
void *v3; // rdi
size_t v4; // rbx
__int64 result; // rax
void *v6; // rax

v3 = *(void **)a1;
v4 = a2;
LOBYTE(v4) = -1;
if ( v3 )
{
v4 = a2 + *(unsigned int *)(a1 + 8);
LOBYTE(v4) = -1;
}
result = -1LL;
if ( v4 >= a2 )
{
v6 = realloc(v3, v4);
if ( v6 )
{
*(_QWORD *)a1 = v6;
*(_DWORD *)(a1 + 12) = v4;
result = 0LL;
}
else
{
result = -1LL;
}
}
return result;
}

original_code:
size_t strbuf_realloc(strbuf_t * strbuf, size_t len)
{
  size_t l;
  char *tmp;
  if (strbuf->s) {
    l = (strbuf->len + len) | 0xFF;
  } else {
    l = len | 0xFF;
  }
  if (l < len) {
  } else if (((void *)0) == (tmp = realloc(strbuf->s, l))) {
  } else {
    strbuf->s = tmp;
    strbuf->total = l;
    return 0;
  }
  return (size_t)-1;
}

canonical_original_code:
unsigned long strbuf_realloc(struct strbuf_t *strbuf, unsigned long len)
{
  unsigned long l;
  char *tmp;
  if (strbuf->s) {
    l = (strbuf->len + len) | 0xFF;
  } else {
    l = len | 0xFF;
  }
  if (l < len) {
  } else if (((void *)0) == (tmp = realloc(strbuf->s, l))) {
  } else {
    strbuf->s = tmp;
    strbuf->total = l;
    return 0;
  }
  return (unsigned long)-1;
}

variable_types:
len
unsigned long

variable_types:
l
unsigned long


decompiled_code:
void __fastcall strbuf_nullify(__int64 a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = *(void **)a1;
if ( v2 )
free(v2);
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 8) = 0;
}
}

original_code:
void strbuf_nullify(strbuf_t * strbuf)
{
  if (strbuf) {
    if (strbuf->s)
      free(strbuf->s);
    strbuf->s = ((void *)0);
    strbuf->len = strbuf->total = 0;
  }
}

canonical_original_code:
void strbuf_nullify(struct strbuf_t *strbuf)
{
  if (strbuf) {
    if (strbuf->s)
      free(strbuf->s);
    strbuf->s = ((void *)0);
    strbuf->len = strbuf->total = 0;
  }
}


decompiled_code:
ssize_t __fastcall write1(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
return write(1, buf, v1);
}

canonical_decompiled_code:
ssize_t __fastcall func7(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
return write(1, buf, v1);
}

original_code:
void write1(char *s)
{
  write(1, s, strlen(s));
}

variable_types:
s
char *


decompiled_code:
ssize_t __fastcall write2(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
return write(2, buf, v1);
}

canonical_decompiled_code:
ssize_t __fastcall func8(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
return write(2, buf, v1);
}

original_code:
void write2(char *s)
{
  write(2, s, strlen(s));
}


Usage

decompiled_code:
void __noreturn Usage()
{
write2(
"Create: tunctl [-b] [-u owner] [-t device-name] [-f tun-clone-device]\n"
"Delete: tunctl -d device-name [-f tun-clone-device]\n"
"\n"
"The default tun clone device is /dev/net/tun - some systems use\n"
"/dev/misc/net/tun instead\n"
"\n"
"-b will result in brief output (just the device name)\n");
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
func8(
"Create: tunctl [-b] [-u owner] [-t device-name] [-f tun-clone-device]\n"
"Delete: tunctl -d device-name [-f tun-clone-device]\n"
"\n"
"The default tun clone device is /dev/net/tun - some systems use\n"
"/dev/misc/net/tun instead\n"
"\n"
"-b will result in brief output (just the device name)\n");
exit(1);
}

original_code:
static void Usage(void)
{
  write2
      ("Create: tunctl [-b] [-u owner] [-t device-name] [-f tun-clone-device]\n"
       "Delete: tunctl -d device-name [-f tun-clone-device]\n\n"
       "The default tun clone device is /dev/net/tun - some systems use\n"
       "/dev/misc/net/tun instead\n\n"
       "-b will result in brief output (just the device name)\n");
  exit(1);
}

canonical_original_code:
static void Usage()
{
  write2
      ("Create: tunctl [-b] [-u owner] [-t device-name] [-f tun-clone-device]\n"
       "Delete: tunctl -d device-name [-f tun-clone-device]\n\n"
       "The default tun clone device is /dev/net/tun - some systems use\n"
       "/dev/misc/net/tun instead\n\n"
       "-b will result in brief output (just the device name)\n");
  exit(1);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
const char *v4; // r12
char *v5; // r13
int v6; // eax
struct passwd *v7; // rax
int v8; // ebx
int result; // eax
__int64 v10; // [rsp+0h] [rbp-88h]
int v11; // [rsp+8h] [rbp-80h]
int v12; // [rsp+Ch] [rbp-7Ch]
char *endptr; // [rsp+18h] [rbp-70h] BYREF
char dest[8]; // [rsp+20h] [rbp-68h] BYREF
__int64 v15; // [rsp+28h] [rbp-60h]
__int64 v16; // [rsp+30h] [rbp-58h]
__int64 v17; // [rsp+38h] [rbp-50h]
__int64 v18; // [rsp+40h] [rbp-48h]

v10 = geteuid();
v3 = "/dev/net/tun";
v4 = "";
v12 = 0;
v11 = 0;
v5 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "bd:f:t:u:");
if ( v6 <= 0 )
break;
switch ( v6 )
{
case 'b':
v12 = 1;
break;
case 'd':
v4 = optarg;
v11 = 1;
break;
case 'f':
v3 = optarg;
break;
case 't':
v4 = optarg;
break;
case 'u':
v5 = optarg;
v7 = getpwnam(optarg);
if ( v7 )
{
v10 = v7->pw_uid;
}
else
{
v10 = strtol(optarg, &endptr, 0);
if ( *endptr )
{
write2(optarg);
write2(": is neither a username nor a numeric uid.\n");
Usage();
}
}
break;
default:
Usage();
return result;
}
}
if ( argc - _bss_start > 0 )
Usage();
v8 = open(v3, 2);
if ( v8 < 0 )
{
write2("Failed to open - ");
write2(v3);
exit(1);
}
*(_QWORD *)dest = 0LL;
v15 = 0LL;
v16 = 4098LL;
v17 = 0LL;
v18 = 0LL;
strncpy(dest, v4, 0xFuLL);
if ( ioctl(v8, 0x400454CAuLL, dest) < 0 )
{
perror("TUNSETIFF");
exit(1);
}
if ( v11 )
{
if ( ioctl(v8, 0x400454CBuLL, 0LL) < 0 )
{
perror("TUNSETPERSIST");
exit(1);
}
write1("Set '");
write1(dest);
write1("' nonpersistent\n");
}
else
{
if ( ioctl(v8, 0x400454CBuLL, 1LL) < 0 )
{
perror("TUNSETPERSIST");
exit(1);
}
if ( ioctl(v8, 0x400454CCuLL, v10) < 0 )
{
perror("TUNSETPERSIST");
exit(1);
}
if ( v12 )
{
write1(dest);
}
else
{
write1("Set '");
write1(dest);
write1("' persistent");
if ( v5 )
{
write1(" and owned by ");
write1(v5);
}
}
write1("\n");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
const char *v4; // r12
char *v5; // r13
int v6; // eax
struct passwd *v7; // rax
int v8; // ebx
int result; // eax
__int64 v10; // [rsp+0h] [rbp-88h]
int v11; // [rsp+8h] [rbp-80h]
int v12; // [rsp+Ch] [rbp-7Ch]
char *endptr; // [rsp+18h] [rbp-70h] BYREF
char dest[8]; // [rsp+20h] [rbp-68h] BYREF
__int64 v15; // [rsp+28h] [rbp-60h]
__int64 v16; // [rsp+30h] [rbp-58h]
__int64 v17; // [rsp+38h] [rbp-50h]
__int64 v18; // [rsp+40h] [rbp-48h]

v10 = geteuid();
v3 = "/dev/net/tun";
v4 = "";
v12 = 0;
v11 = 0;
v5 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "bd:f:t:u:");
if ( v6 <= 0 )
break;
switch ( v6 )
{
case 'b':
v12 = 1;
break;
case 'd':
v4 = optarg;
v11 = 1;
break;
case 'f':
v3 = optarg;
break;
case 't':
v4 = optarg;
break;
case 'u':
v5 = optarg;
v7 = getpwnam(optarg);
if ( v7 )
{
v10 = v7->pw_uid;
}
else
{
v10 = strtol(optarg, &endptr, 0);
if ( *endptr )
{
func8(optarg);
func8(": is neither a username nor a numeric uid.\n");
func9();
}
}
break;
default:
func9();
return result;
}
}
if ( argc - _bss_start > 0 )
func9();
v8 = open(v3, 2);
if ( v8 < 0 )
{
func8("Failed to open - ");
func8(v3);
exit(1);
}
*(_QWORD *)dest = 0LL;
v15 = 0LL;
v16 = 4098LL;
v17 = 0LL;
v18 = 0LL;
strncpy(dest, v4, 0xFuLL);
if ( ioctl(v8, 0x400454CAuLL, dest) < 0 )
{
perror("TUNSETIFF");
exit(1);
}
if ( v11 )
{
if ( ioctl(v8, 0x400454CBuLL, 0LL) < 0 )
{
perror("TUNSETPERSIST");
exit(1);
}
func7("Set '");
func7(dest);
func7("' nonpersistent\n");
}
else
{
if ( ioctl(v8, 0x400454CBuLL, 1LL) < 0 )
{
perror("TUNSETPERSIST");
exit(1);
}
if ( ioctl(v8, 0x400454CCuLL, v10) < 0 )
{
perror("TUNSETPERSIST");
exit(1);
}
if ( v12 )
{
func7(dest);
}
else
{
func7("Set '");
func7(dest);
func7("' persistent");
if ( v5 )
{
func7(" and owned by ");
func7(v5);
}
}
func7("\n");
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
  struct ifreq ifr;
  struct passwd *pw;
  char *strowner = ((void *)0);
  long owner = geteuid();
  int tap_fd, opt, delete = 0, brief = 0;
  char *tun = "", *file = "/dev/net/tun", *end;
  while ((opt = getopt(argc, argv, "bd:f:t:u:")) > 0) {
    switch (opt) {
    case 'b':
      brief = 1;
      break;
    case 'd':
      delete = 1;
      tun = optarg;
      break;
    case 'f':
      file = optarg;
      break;
    case 'u':
      strowner = optarg;
      pw = getpwnam(optarg);
      if (pw != ((void *)0)) {
 owner = pw->pw_uid;
 break;
      }
      owner = strtol(optarg, &end, 0);
      if (*end != '\0') {
 write2(optarg);
 write2(": is neither a username nor a numeric uid.\n");
 Usage();
      }
      break;
    case 't':
      tun = optarg;
      break;
    case 'h':
    default:
      Usage();
    }
  }
  argv += optind;
  argc -= optind;
  if (argc > 0)
    Usage();
  if ((tap_fd = open(file, 02)) < 0) {
    write2("Failed to open - ");
    write2(file);
    exit(1);
  }
  memset(&ifr, 0, sizeof(ifr));
  ifr.ifr_ifru.ifru_flags = 0x0002 | 0x1000;
  strncpy(ifr.ifr_ifrn.ifrn_name, tun, sizeof(ifr.ifr_ifrn.ifrn_name) - 1);
  if (ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) &ifr) < 0) {
    perror("TUNSETIFF");
    exit(1);
  }
  if (delete) {
    if (ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((203)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), 0) < 0) {
      perror("TUNSETPERSIST");
      exit(1);
    }
    write1("Set '");
    write1(ifr.ifr_ifrn.ifrn_name);
    write1("' nonpersistent\n");
  } else {
    if (ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((203)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), 1) < 0) {
      perror("TUNSETPERSIST");
      exit(1);
    }
    if (ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((204)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), owner) < 0) {
      perror("TUNSETPERSIST");
      exit(1);
    }
    if (brief) {
      write1(ifr.ifr_ifrn.ifrn_name);
    } else {
      write1("Set '");
      write1(ifr.ifr_ifrn.ifrn_name);
      write1("' persistent");
      if (strowner) {
 write1(" and owned by ");
 write1(strowner);
      }
    }
    write1("\n");
  }
  return (0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct ifreq ifr;
  struct passwd *pw;
  char *strowner = ((void *)0);
  long owner = geteuid();
  int tap_fd; int opt; int delete = 0; int brief = 0;
  char *tun = ""; char *file = "/dev/net/tun"; char *end;
  while ((opt = getopt(argc, argv, "bd:f:t:u:")) > 0) {
    switch (opt) {
    case 'b':
      brief = 1;
      break;
    case 'd':
      delete = 1;
      tun = optarg;
      break;
    case 'f':
      file = optarg;
      break;
    case 'u':
      strowner = optarg;
      pw = getpwnam(optarg);
      if (pw != ((void *)0)) {
 owner = pw->pw_uid;
 break;
      }
      owner = strtol(optarg, &end, 0);
      if (*end != '\0') {
 write2(optarg);
 write2(": is neither a username nor a numeric uid.\n");
 Usage();
      }
      break;
    case 't':
      tun = optarg;
      break;
    case 'h':
    default:
      Usage();
    }
  }
  argv += optind;
  argc -= optind;
  if (argc > 0)
    Usage();
  if ((tap_fd = open(file, 02)) < 0) {
    write2("Failed to open - ");
    write2(file);
    exit(1);
  }
  memset(&ifr, 0, sizeof(ifr));
  ifr.ifr_ifru.ifru_flags = 0x0002 | 0x1000;
  strncpy(ifr.ifr_ifrn.ifrn_name, tun, sizeof(ifr.ifr_ifrn.ifrn_name) - 1);
  if (ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) &ifr) < 0) {
    perror("TUNSETIFF");
    exit(1);
  }
  if (delete) {
    if (ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((203)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), 0) < 0) {
      perror("TUNSETPERSIST");
      exit(1);
    }
    write1("Set '");
    write1(ifr.ifr_ifrn.ifrn_name);
    write1("' nonpersistent\n");
  } else {
    if (ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((203)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), 1) < 0) {
      perror("TUNSETPERSIST");
      exit(1);
    }
    if (ioctl(tap_fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((204)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), owner) < 0) {
      perror("TUNSETPERSIST");
      exit(1);
    }
    if (brief) {
      write1(ifr.ifr_ifrn.ifrn_name);
    } else {
      write1("Set '");
      write1(ifr.ifr_ifrn.ifrn_name);
      write1("' persistent");
      if (strowner) {
 write1(" and owned by ");
 write1(strowner);
      }
    }
    write1("\n");
  }
  return (0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types:
strowner
char *

variable_types: owner long

variable_types: opt int

variable_types: delete int

variable_types: brief int

variable_types:
tun
char *

variable_types:
file
char *

variable_types:
end
char *

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


decompiled_code:
__int64 __fastcall fmt_longlong(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rax

if ( a2 >= 0 )
return ((__int64 (*)(void))fmt_ulonglong)();
v2 = a1;
if ( a1 )
{
v2 = a1 + 1;
*a1 = 45;
}
return fmt_ulonglong(v2, -a2) + 1;
}

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

if ( a2 >= 0 )
return ((__int64 (*)(void))fmt_ulonglong)();
v2 = a1;
if ( a1 )
{
v2 = a1 + 1;
*a1 = 45;
}
return fmt_ulonglong(v2, -a2) + 1;
}

original_code:
size_t fmt_longlong(char *dest, signed long long int i)
{
  if (i < 0) {
    if (dest)
      *dest++ = '-';
    return fmt_ulonglong(dest, -i) + 1;
  } else
    return fmt_ulonglong(dest, i);
}

canonical_original_code:
unsigned long fmt_longlong(char *dest, long long i)
{
  if (i < 0) {
    if (dest)
      *dest++ = '-';
    return fmt_ulonglong(dest, -i) + 1;
  } else
    return fmt_ulonglong(dest, i);
}

variable_types:
dest
char *

variable_types:
i
long long


decompiled_code:
__int64 __fastcall strbuf_appendllu(__int64 a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

v2[(int)fmt_ulonglong(v2)] = 0;
return strbuf_appends(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

v2[(int)fmt_ulonglong(v2)] = 0;
return strbuf_appends(a1, v2);
}

original_code:
size_t strbuf_appendllu(strbuf_t * strbuf, const unsigned long long l)
{
  char buf[41];
  int len;
  len = fmt_ulonglong(buf, l);
  buf[len] = '\0';
  return strbuf_appends(strbuf, buf);
}

canonical_original_code:
unsigned long strbuf_appendllu(struct strbuf_t *strbuf, unsigned long long l)
{
  char buf[41];
  int len;
  len = fmt_ulonglong(buf, l);
  buf[len] = '\0';
  return strbuf_appends(strbuf, buf);
}

variable_types: struct strbuf_t { char *s; unsigned int len; unsigned int total; } *

variable_types:
l
unsigned long long

variable_types:
buf
char [41]

variable_types: len int


decompiled_code:
__int64 __fastcall print_ssl_error(__int64 a1)
{
_BYTE v2[264]; // [rsp+0h] [rbp-108h] BYREF

mbedtls_strerror(a1, v2, 256LL);
return write2f("%s\n", v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
_BYTE v2[264]; // [rsp+0h] [rbp-108h] BYREF

mbedtls_strerror(a1, v2, 256LL);
return write2f("%s\n", v2);
}

original_code:
static void print_ssl_error(int e)
{
  char buf[256];
  mbedtls_strerror(e, buf, sizeof(buf));
  write2f("%s\n", buf);
}

variable_types: e int

variable_types:
buf
char [256]


decompiled_code:
unsigned __int64 __fastcall strbuf_setlength(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rax
size_t v5; // r12

v2 = a2;
if ( a1 )
{
v3 = *(unsigned int *)(a1 + 8);
if ( v3 > a2 )
{
*(_DWORD *)(a1 + 8) = a2;
*(_BYTE *)(*(_QWORD *)a1 + a2) = 0;
return v2;
}
}
else
{
v3 = 0LL;
}
if ( a2 > v3 )
{
v5 = (int)a2 - *(_DWORD *)(a1 + 8);
if ( strbuf_check(a1, v5) )
{
v2 = 0LL;
}
else
{
memset(*(void **)a1, 32, v5);
*(_BYTE *)(*(_QWORD *)a1 + a2) = 0;
}
}
return v2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rax
size_t v5; // r12

v2 = a2;
if ( a1 )
{
v3 = *(unsigned int *)(a1 + 8);
if ( v3 > a2 )
{
*(_DWORD *)(a1 + 8) = a2;
*(_BYTE *)(*(_QWORD *)a1 + a2) = 0;
return v2;
}
}
else
{
v3 = 0LL;
}
if ( a2 > v3 )
{
v5 = (int)a2 - *(_DWORD *)(a1 + 8);
if ( strbuf_check(a1, v5) )
{
v2 = 0LL;
}
else
{
memset(*(void **)a1, 32, v5);
*(_BYTE *)(*(_QWORD *)a1 + a2) = 0;
}
}
return v2;
}

original_code:
size_t strbuf_setlength(strbuf_t * strbuf, size_t len)
{
  if ((strbuf?strbuf->len:0) > len) {
    strbuf->len = len;
    strbuf->s[len] = '\0';
  } else if ((strbuf?strbuf->len:0) < len) {
    int needed = len - strbuf->len;
    if (strbuf_check(strbuf, needed) == 0) {
      memset(strbuf->s, ' ', needed);
      strbuf->s[len] = '\0';
    } else
      return 0;
  }
  return len;
}

canonical_original_code:
unsigned long strbuf_setlength(struct strbuf_t *strbuf, unsigned long len)
{
  if ((strbuf?strbuf->len:0) > len) {
    strbuf->len = len;
    strbuf->s[len] = '\0';
  } else if ((strbuf?strbuf->len:0) < len) {
    int needed = len - strbuf->len;
    if (strbuf_check(strbuf, needed) == 0) {
      memset(strbuf->s, ' ', needed);
      strbuf->s[len] = '\0';
    } else
      return 0;
  }
  return len;
}

variable_types:
len
unsigned long

variable_types: needed int


decompiled_code:
__int64 __fastcall fmt_xchar(_BYTE *a1, unsigned __int8 a2)
{
*a1 = digits[a2 >> 4];
a1[1] = digits[a2 & 0xF];
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, unsigned __int8 a2)
{
*a1 = digits[a2 >> 4];
a1[1] = digits[a2 & 0xF];
return 2LL;
}

original_code:
unsigned int fmt_xchar(char *s, unsigned char c)
{
  s[0] = digits[(c >> 4) & 0xf];
  s[1] = digits[c & 0xf];
  return 2;
}

variable_types:
s
char *

variable_types:
c
unsigned char

return_type: unsigned int


mmapfile

decompiled_code:
void *__fastcall mmapfile(const char *a1, struct stat *a2)
{
int v2; // eax
int v3; // ebx
void *v4; // rbp
int *v5; // r12
int v6; // er13

v2 = open(a1, 0);
v3 = v2;
v4 = 0LL;
if ( v2 >= 0 && fstat(v2, a2) >= 0 )
{
v4 = mmap(0LL, a2->st_size, 1, 2, v3, 0LL);
if ( v4 == (void *)-1LL )
v4 = 0LL;
}
v5 = _errno_location();
v6 = *v5;
close(v3);
*v5 = v6;
return v4;
}

canonical_decompiled_code:
void *__fastcall func0(const char *a1, struct stat *a2)
{
int v2; // eax
int v3; // ebx
void *v4; // rbp
int *v5; // r12
int v6; // er13

v2 = open(a1, 0);
v3 = v2;
v4 = 0LL;
if ( v2 >= 0 && fstat(v2, a2) >= 0 )
{
v4 = mmap(0LL, a2->st_size, 1, 2, v3, 0LL);
if ( v4 == (void *)-1LL )
v4 = 0LL;
}
v5 = _errno_location();
v6 = *v5;
close(v3);
*v5 = v6;
return v4;
}

original_code:
char *mmapfile(char *fn, struct stat *st)
{
  char *buf = ((void *)0);
  int fd = open(fn, 00);
  int __errno;
  if (fd < 0) {
  } else if (0 > fstat(fd, st)) {
  } else if ((char *)-1 == (buf = mmap((char *) 0, st->st_size, 0x1, 0x02, fd, 0))) {
    buf = ((void *)0);
  }
  __errno = (*__errno_location ());
  close(fd);
  (*__errno_location ()) = __errno;
  return buf;
}

variable_types:
fn
char *

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

variable_types:
buf
char *

variable_types: fd int

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


decompiled_code:
__int64 __fastcall strbuf_appendl(__int64 a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

v2[(int)fmt_long(v2)] = 0;
return strbuf_appends(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

v2[(int)fmt_long(v2)] = 0;
return strbuf_appends(a1, v2);
}

original_code:
size_t strbuf_appendl(strbuf_t * strbuf, const long l)
{
  char buf[41];
  int len;
  len = fmt_long(buf, l);
  buf[len] = '\0';
  return strbuf_appends(strbuf, buf);
}

canonical_original_code:
unsigned long strbuf_appendl(struct strbuf_t *strbuf, long l)
{
  char buf[41];
  int len;
  len = fmt_long(buf, l);
  buf[len] = '\0';
  return strbuf_appends(strbuf, buf);
}

variable_types: l long


original_code:
int str_casecmp(const char *s1, const char *s2)
{
  register unsigned int x2;
  register unsigned int x1;
  while (1) {
    x2 = *s2 - 'A';
    if (x2 < 26u)
      x2 += 32;
    x1 = *s1 - 'A';
    if (x1 < 26u)
      x1 += 32;
    s1++;
    s2++;
    if (x2 != x1)
      break;
    if (x1 == (unsigned int) -'A')
      break;
  }
  return x1 - x2;
}

canonical_original_code:
int str_casecmp(char *s1, char *s2)
{
  register unsigned int x2;
  register unsigned int x1;
  while (1) {
    x2 = *s2 - 'A';
    if (x2 < 26u)
      x2 += 32;
    x1 = *s1 - 'A';
    if (x1 < 26u)
      x1 += 32;
    s1++;
    s2++;
    if (x2 != x1)
      break;
    if (x1 == (unsigned int) -'A')
      break;
  }
  return x1 - x2;
}


decompiled_code:
__int64 __fastcall strbuf_appendll(__int64 a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

v2[(int)fmt_longlong(v2)] = 0;
return strbuf_appends(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

v2[(int)fmt_longlong(v2)] = 0;
return strbuf_appends(a1, v2);
}

original_code:
size_t strbuf_appendll(strbuf_t * strbuf, const long long l)
{
  char buf[41];
  int len;
  len = fmt_longlong(buf, l);
  buf[len] = '\0';
  return strbuf_appends(strbuf, buf);
}

canonical_original_code:
unsigned long strbuf_appendll(struct strbuf_t *strbuf, long long l)
{
  char buf[41];
  int len;
  len = fmt_longlong(buf, l);
  buf[len] = '\0';
  return strbuf_appends(strbuf, buf);
}

variable_types:
l
long long


repo: terimai/mmpeephole

decompiled_code:
int __fastcall print_mmap_handler(int fd, char *file)
{
int v2; // eax
int v3; // ebx
int result; // eax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
__int64 v9; // [rsp+0h] [rbp-128h] BYREF
char v10[288]; // [rsp+8h] [rbp-120h] BYREF

v2 = open(file, 0);
if ( v2 == -1 )
{
v5 = __errno_location();
v6 = strerror(*v5);
result = fprintf(stderr, "open %s: %s\n", file, v6);
}
else
{
v3 = v2;
v9 = v2;
if ( ioctl(fd, 0xC1086D01uLL, &v9) == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
fprintf(stderr, "ioctl MMPH_IOC_CMD_MMAP (file=%s): %s\n", file, v8);
}
else
{
printf("%s mmap operation = %s\n", file, v10);
}
result = close(v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int fd, char *file)
{
int v2; // eax
int v3; // ebx
int result; // eax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
__int64 v9; // [rsp+0h] [rbp-128h] BYREF
char v10[288]; // [rsp+8h] [rbp-120h] BYREF

v2 = open(file, 0);
if ( v2 == -1 )
{
v5 = __errno_location();
v6 = strerror(*v5);
result = fprintf(stderr, "open %s: %s\n", file, v6);
}
else
{
v3 = v2;
v9 = v2;
if ( ioctl(fd, 0xC1086D01uLL, &v9) == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
fprintf(stderr, "ioctl MMPH_IOC_CMD_MMAP (file=%s): %s\n", file, v8);
}
else
{
printf("%s mmap operation = %s\n", file, v10);
}
result = close(v3);
}
return result;
}

original_code:
void
print_mmap_handler(int mmph, const char *fname)
{
 struct mmph_ioc_sym_param ioc_param;
 int testfd;
 long ret;
 testfd = open(fname, 00);
 if (testfd == -1) {
  fprintf(stderr, "open %s: %s\n", fname, strerror((*__errno_location ())));
  return;
 }
 ioc_param.param = testfd;
 ret = ioctl(mmph, (((2U|1U) << (((0 +8)+8)+14)) | ((('m')) << (0 +8)) | (((0x1)) << 0) | ((((sizeof(struct mmph_ioc_sym_param)))) << ((0 +8)+8))), &ioc_param);
 if (ret == -1) {
  fprintf(stderr, "ioctl MMPH_IOC_CMD_MMAP (file=%s): %s\n",
          fname, strerror((*__errno_location ())));
  goto close_file;
 }
 printf("%s mmap operation = %s\n", fname, ioc_param.name);
close_file:
 close(testfd);
}

canonical_original_code:
void print_mmap_handler(int mmph, char *fname)
{
 struct mmph_ioc_sym_param ioc_param;
 int testfd;
 long ret;
 testfd = open(fname, 00);
 if (testfd == -1) {
  fprintf(stderr, "open %s: %s\n", fname, strerror((*__errno_location ())));
  return;
 }
 ioc_param.param = testfd;
 ret = ioctl(mmph, (((2U|1U) << (((0 +8)+8)+14)) | ((('m')) << (0 +8)) | (((0x1)) << 0) | ((((sizeof(struct mmph_ioc_sym_param)))) << ((0 +8)+8))), &ioc_param);
 if (ret == -1) {
  fprintf(stderr, "ioctl MMPH_IOC_CMD_MMAP (file=%s): %s\n",
          fname, strerror((*__errno_location ())));
  goto close_file;
 }
 printf("%s mmap operation = %s\n", fname, ioc_param.name);
close_file:
 close(testfd);
}

variable_types: mmph int

variable_types:
fname
char *

variable_types: struct mmph_ioc_sym_param { unsigned long param; char name[256]; }

variable_types: testfd int

variable_types: ret long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
char **v5; // rbx
char *v6; // rsi

v3 = open("/dev/mmpeephole", 0, envp);
if ( v3 == -1 )
{
perror("open mmpeephole device");
exit(1);
}
v4 = v3;
v5 = (char **)(argv + 1);
v6 = (char *)argv[1];
if ( v6 )
{
do
{
print_mmap_handler(v4, v6);
v6 = *++v5;
}
while ( *v5 );
}
close(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
char **v5; // rbx
char *v6; // rsi

v3 = open("/dev/mmpeephole", 0, envp);
if ( v3 == -1 )
{
perror("open mmpeephole device");
exit(1);
}
v4 = v3;
v5 = (char **)(argv + 1);
v6 = (char *)argv[1];
if ( v6 )
{
do
{
func7(v4, v6);
v6 = *++v5;
}
while ( *v5 );
}
close(v4);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
 int fd;
 fd = open("/dev/mmpeephole", 00);
 if (fd == -1) {
  perror("open mmpeephole device");
  exit(1);
 }
 while (*++argv) {
  print_mmap_handler(fd, *argv);
 }
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: terjr/bitless-simulator

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
_DWORD v5[8]; // [rsp+0h] [rbp-58h] BYREF
char v6[8]; // [rsp+20h] [rbp-38h] BYREF
int v7; // [rsp+28h] [rbp-30h]
_WORD *v8; // [rsp+48h] [rbp-10h] BYREF

v3 = (unsigned int)readWav("mordi.wav", v6, &v8);
printf("Read %d samples\n", v3);
distortion(v8, v3, 0x78u);
v5[2] = v7;
return writeWav("output.wav", v5, v8, (unsigned int)(9 * v7));
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
_DWORD v5[8]; // [rsp+0h] [rbp-58h] BYREF
char v6[8]; // [rsp+20h] [rbp-38h] BYREF
int v7; // [rsp+28h] [rbp-30h]
_WORD *v8; // [rsp+48h] [rbp-10h] BYREF

v3 = (unsigned int)func10("mordi.wav", v6, &v8);
printf("Read %d samples\n", v3);
func9(v8, v3, 0x78u);
v5[2] = v7;
return func11("output.wav", v5, v8, (unsigned int)(9 * v7));
}

original_code:
int32_t main() {
    uint16_t *samples;
    SF_INFO in, out;
    uint32_t read = readWav("mordi.wav", &in, &samples);
    printf("Read %d samples\n", read);
    distortion(samples, read, 120);
    out.samplerate = in.samplerate;
    uint32_t written = writeWav("output.wav", &out, samples, in.samplerate * 9);
    return written;
}

canonical_original_code:
int main() {
    unsigned short *samples;
    struct SF_INFO in; struct SF_INFO out;
    unsigned int read = readWav("mordi.wav", &in, &samples);
    printf("Read %d samples\n", read);
    distortion(samples, read, 120);
    out.samplerate = in.samplerate;
    unsigned int written = writeWav("output.wav", &out, samples, in.samplerate * 9);
    return written;
}

variable_types:
samples
unsigned short *

variable_types: struct SF_INFO { long frames; int samplerate; int channels; int format; int sections; int seekable; }

variable_types:
read
unsigned int

variable_types:
written
unsigned int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "usage: %s [<datafile>]\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
fprintf(stderr, "usage: %s [<datafile>]\n", a1);
exit(1);
}

original_code:
void usage(char *program) {
    fprintf(stderr, "usage: %s [<datafile>]\n", program);
    exit(1);
}

variable_types:
program
char *


decompiled_code:
const char *__fastcall remove_newline(const char *a1)
{
int v1; // eax
const char *v2; // rax

v1 = strlen(a1);
if ( v1 > 0 )
{
v2 = &a1[v1 - 1];
if ( *v2 == 10 )
*v2 = 0;
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func8(const char *a1)
{
int v1; // eax
const char *v2; // rax

v1 = strlen(a1);
if ( v1 > 0 )
{
v2 = &a1[v1 - 1];
if ( *v2 == 10 )
*v2 = 0;
}
return a1;
}

original_code:
char *remove_newline(char *s)
  {
    int len = strlen(s);
    if (len > 0 && s[len-1] == '\n')
      s[len-1] = '\0';
    return s;
  }

variable_types:
s
char *

variable_types: len int


isint

original_code:
int isint (char * str)
{
  char * nums = "0123456789";
  if( strlen(str) == 1 )
    {
      if(strchr( nums, str[0])!= ((void *)0))
        {
   return 1;
        }
      return 0;
    }
  if( ( strchr(nums,str[0]) == ((void *)0)) && str[0]!= '-'){
    return 0;
  }
  int i = 1;
  int length = strlen(str);
  for ( ; i < length ; i++)
    { if ( strchr(nums, str[i])== ((void *)0)){
 return 0;
      };
    }
  return 1;
}

canonical_original_code:
int isint(char *str)
{
  char *nums = "0123456789";
  if( strlen(str) == 1 )
    {
      if(strchr( nums, str[0])!= ((void *)0))
        {
   return 1;
        }
      return 0;
    }
  if( ( strchr(nums,str[0]) == ((void *)0)) && str[0]!= '-'){
    return 0;
  }
  int i = 1;
  int length = strlen(str);
  for ( ; i < length ; i++)
    { if ( strchr(nums, str[i])== ((void *)0)){
 return 0;
      };
    }
  return 1;
}

variable_types:
str
char *

variable_types:
nums
char *

variable_types: i int

variable_types: length int


repo: terrop/atrfs

decompiled_code:
__int64 set_value_internal(__int64 a1, __int64 a2, const char *a3, ...)
{
int v3; // edx
__int64 result; // rax
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
char *ptr; // [rsp+18h] [rbp-D0h] BYREF

va_start(va, a3);
ptr = 0LL;
v3 = vasprintf(&ptr, a3, va);
result = 0LL;
if ( v3 >= 0 )
{
entrydb_put(a1, a2, ptr);
free(ptr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func1(__int64 a1, __int64 a2, const char *a3, ...)
{
int v3; // edx
__int64 result; // rax
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
char *ptr; // [rsp+18h] [rbp-D0h] BYREF

va_start(va, a3);
ptr = 0LL;
v3 = vasprintf(&ptr, a3, va);
result = 0LL;
if ( v3 >= 0 )
{
entrydb_put(a1, a2, ptr);
free(ptr);
result = 1LL;
}
return result;
}

original_code:
static _Bool set_value_internal (struct atrfs_entry *ent, char *attr, char *fmt, ...)
{
 char *buf = ((void *)0);
 va_list list;
 __builtin_va_start(list,fmt);
 int ret = vasprintf (&buf, fmt, list);
 __builtin_va_end(list);
 if (ret < 0)
  return 0;
 entrydb_put (ent, attr, buf);
 ret = 0;
 free (buf);
 if (ret == 0)
  return 1;
 return 0;
}

canonical_original_code:
static _Bool set_value_internal(struct atrfs_entry *ent, char *attr, char *fmt, ...)
{
 char *buf = ((void *)0);
 __builtin_va_list list;
 __builtin_va_start(list,fmt);
 int ret = vasprintf (&buf, fmt, list);
 __builtin_va_end(list);
 if (ret < 0)
  return 0;
 entrydb_put (ent, attr, buf);
 ret = 0;
 free (buf);
 if (ret == 0)
  return 1;
 return 0;
}

variable_types: struct atrfs_entry { enum atrfs_entry_type { ATRFS_FILE_ENTRY=0, ATRFS_DIRECTORY_ENTRY=1, ATRFS_VIRTUAL_FILE_ENTRY=2 } e_type; struct atrfs_entry *parent; char *name; unsigned char flags; struct atrfs_entry_ops { long (*read)(struct atrfs_entry *ent, char *buf, unsigned long size, long offset); void (*write)(struct atrfs_entry *ent, char *buf, unsigned long size); int (*stat)(struct atrfs_entry *ent, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *st); struct atrfs_entry *(*lookup_entry_by_name)(struct atrfs_entry *dir, char *name); } *ops; } *

variable_types:
attr
char *

variable_types:
fmt
char *

variable_types:
buf
char *

variable_types: ret int

user_defined_types: struct atrfs_entry { enum atrfs_entry_type e_type; struct atrfs_entry *parent; char *name; unsigned char flags; struct atrfs_entry_ops *ops; }

user_defined_types: struct atrfs_entry_ops { long (*read)(struct atrfs_entry *ent, char *buf, unsigned long size, long offset); void (*write)(struct atrfs_entry *ent, char *buf, unsigned long size); int (*stat)(struct atrfs_entry *ent, struct stat *st); struct atrfs_entry *(*lookup_entry_by_name)(struct atrfs_entry *dir, char *name); }


doubletime

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

gettimeofday(&v1, 0LL);
return (double)(int)(v1.tv_usec / 10000) / 100.0 + (double)SLODWORD(v1.tv_sec);
}

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

gettimeofday(&v1, 0LL);
return (double)(int)(v1.tv_usec / 10000) / 100.0 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double doubletime(void)
{
 struct timeval tv;
 double ret;
 do
 {
  gettimeofday(&tv, ((void *)0));
  ret = tv.tv_sec + (tv.tv_usec / 10000) / 100.0;
 } while (__builtin_isnan (ret));
 return ret;
}

canonical_original_code:
double doubletime()
{
 struct timeval tv;
 double ret;
 do
 {
  gettimeofday(&tv, ((void *)0));
  ret = tv.tv_sec + (tv.tv_usec / 10000) / 100.0;
 } while (__builtin_isnan (ret));
 return ret;
}

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

variable_types: ret double

return_type: double


decompiled_code:
__int64 __fastcall get_ivalue(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( get_value_internal(a1, a2, 1, "%d", v5) )
a3 = v5[0];
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( func0(a1, a2, 1, "%d", v5) )
a3 = v5[0];
return a3;
}

original_code:
int get_ivalue (struct atrfs_entry *ent, char *attr, int def)
{
 int value;
 if (get_value_internal (ent, attr, 1, "%d", &value))
  return value;
 return def;
}

canonical_original_code:
int get_ivalue(struct atrfs_entry *ent, char *attr, int def)
{
 int value;
 if (get_value_internal (ent, attr, 1, "%d", &value))
  return value;
 return def;
}

variable_types: def int

variable_types: value int

user_defined_types: enum atrfs_entry_type { ATRFS_FILE_ENTRY=0, ATRFS_DIRECTORY_ENTRY=1, ATRFS_VIRTUAL_FILE_ENTRY=2 }

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


decompiled_code:
double __fastcall get_dvalue(__int64 a1, __int64 a2, double a3)
{
double v5[2]; // [rsp+8h] [rbp-10h] BYREF

if ( get_value_internal(a1, a2, 1, "%lf", v5) )
a3 = v5[0];
return a3;
}

canonical_decompiled_code:
double __fastcall func6(__int64 a1, __int64 a2, double a3)
{
double v5[2]; // [rsp+8h] [rbp-10h] BYREF

if ( func0(a1, a2, 1, "%lf", v5) )
a3 = v5[0];
return a3;
}

original_code:
double get_dvalue (struct atrfs_entry *ent, char *attr, double def)
{
 double value;
 if (get_value_internal (ent, attr, 1, "%lf", &value))
  return value;
 return def;
}

canonical_original_code:
double get_dvalue(struct atrfs_entry *ent, char *attr, double def)
{
 double value;
 if (get_value_internal (ent, attr, 1, "%lf", &value))
  return value;
 return def;
}

variable_types: def double

variable_types: value double


decompiled_code:
__int64 __fastcall set_ivalue(_DWORD *a1, __int64 a2, unsigned int a3)
{
if ( !a1 || *a1 )
abort();
return set_value_internal((__int64)a1, a2, "%d", a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, __int64 a2, unsigned int a3)
{
if ( !a1 || *a1 )
abort();
return func1((__int64)a1, a2, "%d", a3);
}

original_code:
void set_ivalue (struct atrfs_entry *ent, char *attr, int value)
{
 do { if (!(ent) || (ent)->e_type != (ATRFS_FILE_ENTRY)) abort ();} while(0);
 set_value_internal(ent, attr, "%d", value);
}

canonical_original_code:
void set_ivalue(struct atrfs_entry *ent, char *attr, int value)
{
 do { if (!(ent) || (ent)->e_type != (ATRFS_FILE_ENTRY)) abort ();} while(0);
 set_value_internal(ent, attr, "%d", value);
}


decompiled_code:
__int64 __fastcall set_dvalue(_DWORD *a1, __int64 a2, double a3)
{
if ( !a1 || *a1 )
abort();
return set_value_internal((__int64)a1, a2, "%lf", a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, __int64 a2, double a3)
{
if ( !a1 || *a1 )
abort();
return func1((__int64)a1, a2, "%lf", a3);
}

original_code:
void set_dvalue (struct atrfs_entry *ent, char *attr, double value)
{
 do { if (!(ent) || (ent)->e_type != (ATRFS_FILE_ENTRY)) abort ();} while(0);
 set_value_internal(ent, attr, "%lf", value);
}

canonical_original_code:
void set_dvalue(struct atrfs_entry *ent, char *attr, double value)
{
 do { if (!(ent) || (ent)->e_type != (ATRFS_FILE_ENTRY)) abort ();} while(0);
 set_value_internal(ent, attr, "%lf", value);
}


decompiled_code:
void *__fastcall uniquify_name(char *s, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
size_t v7; // rbx
int v8; // er14
char *v9; // r13
char *v10; // rbx
unsigned int v11; // ebx
void *v12; // rsp
unsigned __int64 v14; // [rsp+0h] [rbp-70h] BYREF
__int64 v15; // [rsp+8h] [rbp-68h]
void *ptr; // [rsp+10h] [rbp-60h] BYREF
__int16 v17; // [rsp+18h] [rbp-58h] BYREF
unsigned int v18; // [rsp+1Ah] [rbp-56h]
__int16 v19; // [rsp+1Eh] [rbp-52h]
void **v20; // [rsp+20h] [rbp-50h]
int v21; // [rsp+28h] [rbp-48h]
char *v22; // [rsp+38h] [rbp-38h]

v15 = a2;
v22 = &a7;
v17 = -17599;
v18 = (unsigned int)globally_unique_0;
v19 = -17847;
v20 = &ptr;
v21 = -1864106167;
ptr = strdup(s);
v7 = strlen(s);
v8 = v7;
v9 = strrchr(s, 46);
v10 = &s[v7];
if ( !v9 )
v9 = v10;
v11 = 2;
v14 = v8 + 10 + 15LL;
while ( (unsigned int)map_leaf_entries(v15, &v17) )
{
v12 = alloca(16 * (v14 / 0x10));
sprintf((char *)&v14, "%.*s %d%s", (_DWORD)v9 - (_DWORD)s, s, v11, v9);
free(ptr);
ptr = strdup((const char *)&v14);
++v11;
}
return ptr;
}

canonical_decompiled_code:
void *__fastcall func9(char *s, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
size_t v7; // rbx
int v8; // er14
char *v9; // r13
char *v10; // rbx
unsigned int v11; // ebx
void *v12; // rsp
unsigned __int64 v14; // [rsp+0h] [rbp-70h] BYREF
__int64 v15; // [rsp+8h] [rbp-68h]
void *ptr; // [rsp+10h] [rbp-60h] BYREF
__int16 v17; // [rsp+18h] [rbp-58h] BYREF
unsigned int v18; // [rsp+1Ah] [rbp-56h]
__int16 v19; // [rsp+1Eh] [rbp-52h]
void **v20; // [rsp+20h] [rbp-50h]
int v21; // [rsp+28h] [rbp-48h]
char *v22; // [rsp+38h] [rbp-38h]

v15 = a2;
v22 = &a7;
v17 = -17599;
v18 = (unsigned int)globally_unique_0;
v19 = -17847;
v20 = &ptr;
v21 = -1864106167;
ptr = strdup(s);
v7 = strlen(s);
v8 = v7;
v9 = strrchr(s, 46);
v10 = &s[v7];
if ( !v9 )
v9 = v10;
v11 = 2;
v14 = v8 + 10 + 15LL;
while ( (unsigned int)map_leaf_entries(v15, &v17) )
{
v12 = alloca(16 * (v14 / 0x10));
sprintf((char *)&v14, "%.*s %d%s", (_DWORD)v9 - (_DWORD)s, s, v11, v9);
free(ptr);
ptr = strdup((const char *)&v14);
++v11;
}
return ptr;
}

original_code:
char *uniquify_name (char *name, struct atrfs_entry *root)
{
 char *uniq = strdup (name);
 int globally_unique (struct atrfs_entry *ent)
 {
  if (strcmp (uniq, ent->name) == 0)
   return 1;
  return 0;
 }
 int len = strlen (name);
 char *ext = strrchr (name, '.');
 if (! ext)
  ext = name + strlen (name);
 int i;
 for (i = 2;; i++)
 {
  if (map_leaf_entries (root, globally_unique) == 0)
  {
   return uniq;
  } else {
   char buf[len + 10];
   sprintf (buf, "%.*s %d%s", (int)(ext - name), name, i, ext);
   free (uniq);
   uniq = strdup (buf);
  }
 }
}

canonical_original_code:
char *uniquify_name(char *name, struct atrfs_entry *root)
{
 char *uniq = strdup (name);
 int globally_unique (struct atrfs_entry *ent)
 {
  if (strcmp (uniq, ent->name) == 0)
   return 1;
  return 0;
 }
 int len = strlen (name);
 char *ext = strrchr (name, '.');
 if (! ext)
  ext = name + strlen (name);
 int i;
 for (i = 2;; i++)
 {
  if (map_leaf_entries (root, globally_unique) == 0)
  {
   return uniq;
  } else {
   char buf[-1];
   sprintf (buf, "%.*s %d%s", (int)(ext - name), name, i, ext);
   free (uniq);
   uniq = strdup (buf);
  }
 }
}

variable_types:
name
char *

variable_types:
uniq
char *

variable_types:
ext
char *

variable_types:
buf
char [-1]


decompiled_code:
char *__fastcall get_related_name(const char *a1, const char *a2, const char *a3)
{
char *v4; // rax
int v5; // ebx
char *ptr; // [rsp+8h] [rbp-30h] BYREF

ptr = 0LL;
v4 = strrchr(a1, 46);
if ( v4 )
{
v5 = (int)v4;
if ( !strcmp(v4, a2) )
asprintf(&ptr, "%.*s%s", v5 - (_DWORD)a1, a1, a3);
}
return ptr;
}

canonical_decompiled_code:
char *__fastcall func10(const char *a1, const char *a2, const char *a3)
{
char *v4; // rax
int v5; // ebx
char *ptr; // [rsp+8h] [rbp-30h] BYREF

ptr = 0LL;
v4 = strrchr(a1, 46);
if ( v4 )
{
v5 = (int)v4;
if ( !strcmp(v4, a2) )
asprintf(&ptr, "%.*s%s", v5 - (_DWORD)a1, a1, a3);
}
return ptr;
}

original_code:
char *get_related_name (char *filename, char *old_ext, char *new_ext)
{
 char *srtname = ((void *)0);
 char *ext = strrchr (filename, '.');
 if (ext && !strcmp (ext, old_ext))
  asprintf (&srtname, "%.*s%s", (int)(ext - filename), filename, new_ext);
 return srtname;
}

canonical_original_code:
char *get_related_name(char *filename, char *old_ext, char *new_ext)
{
 char *srtname = ((void *)0);
 char *ext = strrchr (filename, '.');
 if (ext && !strcmp (ext, old_ext))
  asprintf (&srtname, "%.*s%s", (int)(ext - filename), filename, new_ext);
 return srtname;
}

variable_types:
filename
char *

variable_types:
srtname
char *


decompiled_code:
char *__fastcall secs_to_timestr(double a1)
{
count_4 = (count_4 + 1) % 2;
sprintf(&buf_3[10 * count_4], "%02d:%02d", (unsigned int)((int)a1 / 60), (unsigned int)((int)a1 % 60));
return &buf_3[10 * count_4];
}

canonical_decompiled_code:
char *__fastcall func12(double a1)
{
count_4 = (count_4 + 1) % 2;
sprintf(&buf_3[10 * count_4], "%02d:%02d", (unsigned int)((int)a1 / 60), (unsigned int)((int)a1 % 60));
return &buf_3[10 * count_4];
}

original_code:
char *secs_to_timestr (double secs)
{
 static int count;
 static char buf[2][10];
 int min = (int)secs / 60;
 int sec = (int)secs % 60;
 count = (count + 1) % 2;
 sprintf (buf[count], "%02d:%02d", min, sec);
 return buf[count];
}

canonical_original_code:
char *secs_to_timestr(double secs)
{
 static int count;
 static char buf[2][10];
 int min = (int)secs / 60;
 int sec = (int)secs % 60;
 count = (count + 1) % 2;
 sprintf (buf[count], "%02d:%02d", min, sec);
 return buf[count];
}

variable_types: secs double

variable_types: count int

variable_types:
buf
char [2][10]

variable_types: min int

variable_types: sec int


decompiled_code:
char __fastcall add_file_when_supported(char *s)
{
char *v1; // rax
bool v2; // zf
__int64 v3; // rbp
char *v4; // rax
void *v5; // r12
__int64 v6; // rbp
const char *v7; // rbx
char *v8; // rax

v1 = strrchr(s, 46);
if ( v1 )
{
if ( !strcmp(v1, ".flv") || (v2 = strcmp(v1, ".webm") == 0, LOBYTE(v1) = !v2, v2) )
{
v3 = root;
v4 = basename(s);
v5 = (void *)uniquify_name(v4, v3);
v6 = create_entry(0LL);
attach_entry(root, v6, v5);
*(_QWORD *)(v6 + 48) = strdup(s);
free(v5);
v7 = (const char *)get_sha1_fast(*(_QWORD *)(v6 + 48));
entrydb_ensure_exists(v7);
v8 = strdup(v7);
LOBYTE(v1) = g_hash_table_replace(sha1_to_entry_map, v8, v6);
}
}
return (char)v1;
}

canonical_decompiled_code:
char __fastcall func0(char *s)
{
char *v1; // rax
bool v2; // zf
__int64 v3; // rbp
char *v4; // rax
void *v5; // r12
__int64 v6; // rbp
const char *v7; // rbx
char *v8; // rax

v1 = strrchr(s, 46);
if ( v1 )
{
if ( !strcmp(v1, ".flv") || (v2 = strcmp(v1, ".webm") == 0, LOBYTE(v1) = !v2, v2) )
{
v3 = root;
v4 = basename(s);
v5 = (void *)uniquify_name(v4, v3);
v6 = create_entry(0LL);
attach_entry(root, v6, v5);
*(_QWORD *)(v6 + 48) = strdup(s);
free(v5);
v7 = (const char *)get_sha1_fast(*(_QWORD *)(v6 + 48));
entrydb_ensure_exists(v7);
v8 = strdup(v7);
LOBYTE(v1) = g_hash_table_replace(sha1_to_entry_map, v8, v6);
}
}
return (char)v1;
}

original_code:
static void add_file_when_supported(const char *filename)
{
 struct atrfs_entry *ent;
 char *uniq_name;
 char *ext = strrchr (filename, '.');
 if (!ext)
  return;
 if (strcmp (ext, ".flv") && strcmp(ext, ".webm"))
  return;
 uniq_name = uniquify_name(basename(filename), root);
 ent = create_entry (ATRFS_FILE_ENTRY);
 attach_entry (root, ent, uniq_name);
 (((struct atrfs_file_entry *)(ent))->real_path) = strdup(filename);
 free(uniq_name);
 char *sha1 = get_sha1_fast ((((struct atrfs_file_entry *)(ent))->real_path));
 entrydb_ensure_exists (sha1);
 g_hash_table_replace (sha1_to_entry_map, strdup(sha1), ent);
}

canonical_original_code:
static void add_file_when_supported(char *filename)
{
 struct atrfs_entry *ent;
 char *uniq_name;
 char *ext = strrchr (filename, '.');
 if (!ext)
  return;
 if (strcmp (ext, ".flv") && strcmp(ext, ".webm"))
  return;
 uniq_name = uniquify_name(basename(filename), root);
 ent = create_entry (ATRFS_FILE_ENTRY);
 attach_entry (root, ent, uniq_name);
 (((struct atrfs_file_entry *)(ent))->real_path) = strdup(filename);
 free(uniq_name);
 char *sha1 = get_sha1_fast ((((struct atrfs_file_entry *)(ent))->real_path));
 entrydb_ensure_exists (sha1);
 g_hash_table_replace (sha1_to_entry_map, strdup(sha1), ent);
}

variable_types: struct atrfs_entry { enum atrfs_entry_type { ATRFS_FILE_ENTRY=0, ATRFS_DIRECTORY_ENTRY=1, ATRFS_VIRTUAL_FILE_ENTRY=2 } e_type; struct atrfs_entry *parent; char *name; unsigned char flags; struct atrfs_entry_ops { long (*read)(struct atrfs_entry *ent, char *buf, unsigned long size, long offset); void (*write)(struct atrfs_entry *ent, char *buf, unsigned long size); int (*stat)(struct atrfs_entry *ent, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *st); struct atrfs_entry *(*lookup_entry_by_name)(struct atrfs_entry *dir, char *name); } *ops; } *

user_defined_types: struct atrfs_file_entry { struct atrfs_entry entry; int fd; char *real_path; double start_time; struct atrfs_entry *subtitles; }


decompiled_code:
__int64 __fastcall populate_stat_dir(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rsi
const __m128i *v4; // rax
__int64 v5; // rax
__int64 v6; // rsi
const __m128i *v7; // rax

v1 = create_entry(2LL);
attach_entry(a1, v1, "top-list");
v2 = create_entry(2LL);
attach_entry(a1, v2, "last-list");
v3 = create_entry(2LL);
v4 = *(const __m128i **)(v3 + 32);
statcount_ops_2 = (__int128)_mm_loadu_si128(v4);
xmmword_790 = (__int128)_mm_loadu_si128(v4 + 1);
*((_QWORD *)&statcount_ops_2 + 1) = &write_statcount;
*(_QWORD *)(v3 + 32) = &statcount_ops_2;
attach_entry(a1, v3, "stat-count");
v5 = create_entry(2LL);
attach_entry(a1, v5, "recent");
v6 = create_entry(2LL);
v7 = *(const __m128i **)(v6 + 32);
language_ops_1 = (__int128)_mm_loadu_si128(v7);
xmmword_770 = (__int128)_mm_loadu_si128(v7 + 1);
*((_QWORD *)&language_ops_1 + 1) = &write_language;
*(_QWORD *)(v6 + 32) = &language_ops_1;
attach_entry(a1, v6, "language");
return update_stats();
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rsi
const __m128i *v4; // rax
__int64 v5; // rax
__int64 v6; // rsi
const __m128i *v7; // rax

v1 = create_entry(2LL);
attach_entry(a1, v1, "top-list");
v2 = create_entry(2LL);
attach_entry(a1, v2, "last-list");
v3 = create_entry(2LL);
v4 = *(const __m128i **)(v3 + 32);
statcount_ops_2 = (__int128)_mm_loadu_si128(v4);
xmmword_790 = (__int128)_mm_loadu_si128(v4 + 1);
*((_QWORD *)&statcount_ops_2 + 1) = &write_statcount;
*(_QWORD *)(v3 + 32) = &statcount_ops_2;
attach_entry(a1, v3, "stat-count");
v5 = create_entry(2LL);
attach_entry(a1, v5, "recent");
v6 = create_entry(2LL);
v7 = *(const __m128i **)(v6 + 32);
language_ops_1 = (__int128)_mm_loadu_si128(v7);
xmmword_770 = (__int128)_mm_loadu_si128(v7 + 1);
*((_QWORD *)&language_ops_1 + 1) = &write_language;
*(_QWORD *)(v6 + 32) = &language_ops_1;
attach_entry(a1, v6, "language");
return update_stats();
}

original_code:
static void populate_stat_dir(struct atrfs_entry *statroot)
{
 static struct atrfs_entry_ops statcount_ops;
 static struct atrfs_entry_ops language_ops;
 struct atrfs_entry *ent;
 ent = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
 attach_entry (statroot, ent, "top-list");
 ent = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
 attach_entry (statroot, ent, "last-list");
 ent = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
 statcount_ops = *ent->ops;
 statcount_ops.write = write_statcount;
 ent->ops = &statcount_ops;
 attach_entry (statroot, ent, "stat-count");
 ent = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
 attach_entry (statroot, ent, "recent");
 ent = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
 language_ops = *ent->ops;
 language_ops.write = write_language;
 ent->ops = &language_ops;
 attach_entry (statroot, ent, "language");
 update_stats();
}

variable_types: struct atrfs_entry_ops { long (*read)(struct atrfs_entry { enum atrfs_entry_type { ATRFS_FILE_ENTRY=0, ATRFS_DIRECTORY_ENTRY=1, ATRFS_VIRTUAL_FILE_ENTRY=2 } e_type; struct atrfs_entry *parent; char *name; unsigned char flags; struct atrfs_entry_ops *ops; } *ent, char *buf, unsigned long size, long offset); void (*write)(struct atrfs_entry *ent, char *buf, unsigned long size); int (*stat)(struct atrfs_entry *ent, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *st); struct atrfs_entry *(*lookup_entry_by_name)(struct atrfs_entry *dir, char *name); }


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

free(language_list);
result = strndup(a2, a3);
language_list = result;
return result;
}

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

free(language_list);
result = strndup(a2, a3);
language_list = result;
return result;
}

original_code:
static void write_language(struct atrfs_entry *ent, const char *buf, size_t size)
{
 free(language_list);
 language_list = strndup(buf, size);
}

canonical_original_code:
static void write_language(struct atrfs_entry *ent, char *buf, unsigned long size)
{
 free(language_list);
 language_list = strndup(buf, size);
}

variable_types:
buf
char *

variable_types:
size
unsigned long


decompiled_code:
int __fastcall write_statcount(__int64 a1, const char *a2)
{
int result; // eax

result = atoi(a2);
stat_count = result;
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, const char *a2)
{
int result; // eax

result = atoi(a2);
stat_count = result;
return result;
}

original_code:
static void write_statcount(struct atrfs_entry *ent, const char *buf, size_t size)
{
 stat_count = atoi(buf);
}

canonical_original_code:
static void write_statcount(struct atrfs_entry *ent, char *buf, unsigned long size)
{
 stat_count = atoi(buf);
}


decompiled_code:
__int64 __fastcall add_notify(char *name, uint32_t mask)
{
if ( notify_fd < 0 )
{
notify_fd = inotify_init1(2048);
*((_DWORD *)&pfd + 2) = notify_fd;
*((_WORD *)&pfd + 6) = 1;
}
inotify_add_watch(notify_fd, name, mask);
return tmplog("Watching '%s'\n", name);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *name, uint32_t mask)
{
if ( notify_fd < 0 )
{
notify_fd = inotify_init1(2048);
*((_DWORD *)&pfd + 2) = notify_fd;
*((_WORD *)&pfd + 6) = 1;
}
inotify_add_watch(notify_fd, name, mask);
return tmplog("Watching '%s'\n", name);
}

original_code:
void add_notify(const char *dirname, uint32_t mask)
{
 if (notify_fd < 0)
 {
  notify_fd = inotify_init1(IN_NONBLOCK);
  pfd[1].fd = notify_fd;
  pfd[1].events = 0x001;
 }
 inotify_add_watch(notify_fd, dirname, mask);
 tmplog("Watching '%s'\n", dirname);
}

canonical_original_code:
void add_notify(char *dirname, unsigned int mask)
{
 if (notify_fd < 0)
 {
  notify_fd = inotify_init1(IN_NONBLOCK);
  pfd[1].fd = notify_fd;
  pfd[1].events = 0x001;
 }
 inotify_add_watch(notify_fd, dirname, mask);
 tmplog("Watching '%s'\n", dirname);
}

variable_types:
dirname
char *

variable_types:
mask
unsigned int


decompiled_code:
ssize_t handle_notify()
{
ssize_t result; // rax
int v1; // er13
int v2; // ebp
_BYTE *v3; // rbx
int v4; // er12
const char *v5; // rdx
_BYTE v6[296]; // [rsp+0h] [rbp-128h] BYREF

result = read(notify_fd, v6, 0x100uLL);
if ( (int)result > 0 )
{
v1 = result;
v2 = 0;
do
{
v3 = &v6[v2];
result = *((unsigned int *)v3 + 3);
v4 = result + v2 + 16;
v2 = v4;
if ( (_DWORD)result )
{
v5 = "dir";
if ( (v3[7] & 0x40) == 0 )
v5 = "file";
tmplog("'%s': %s", v3 + 16, v5);
if ( (v3[5] & 0x40) != 0 )
tmplog(", Q_OVERFLOW");
if ( (v3[5] & 0x20) != 0 )
tmplog(", UNMOUNT");
if ( (char)v3[5] < 0 )
tmplog(", IGNORED");
if ( (v3[4] & 1) != 0 )
tmplog(", ACCESS");
if ( (v3[4] & 4) != 0 )
tmplog(", ATTRIB");
if ( (v3[4] & 8) != 0 )
tmplog(", CLOSE_WRITE");
if ( (v3[4] & 0x10) != 0 )
tmplog(", CLOSE_NOWRITE");
if ( (v3[5] & 1) != 0 )
tmplog(", CREATE");
if ( (v3[5] & 2) != 0 )
tmplog(", DELETE");
if ( (v3[5] & 4) != 0 )
tmplog(", DELETE_SELF");
if ( (v3[4] & 2) != 0 )
tmplog(", MODIFY");
if ( (v3[5] & 8) != 0 )
tmplog(", MOVE_SELF");
if ( (v3[4] & 0x40) != 0 )
tmplog(", MOVED_FROM (cookie=%d)", *((unsigned int *)v3 + 2));
if ( (char)v3[4] < 0 )
tmplog(", MOVED_TO (cookie=%d)", *((unsigned int *)v3 + 2));
if ( (v3[4] & 0x20) != 0 )
tmplog(", OPEN");
result = tmplog("\n");
}
}
while ( v1 > v4 );
}
return result;
}

canonical_decompiled_code:
ssize_t func1()
{
ssize_t result; // rax
int v1; // er13
int v2; // ebp
_BYTE *v3; // rbx
int v4; // er12
const char *v5; // rdx
_BYTE v6[296]; // [rsp+0h] [rbp-128h] BYREF

result = read(notify_fd, v6, 0x100uLL);
if ( (int)result > 0 )
{
v1 = result;
v2 = 0;
do
{
v3 = &v6[v2];
result = *((unsigned int *)v3 + 3);
v4 = result + v2 + 16;
v2 = v4;
if ( (_DWORD)result )
{
v5 = "dir";
if ( (v3[7] & 0x40) == 0 )
v5 = "file";
tmplog("'%s': %s", v3 + 16, v5);
if ( (v3[5] & 0x40) != 0 )
tmplog(", Q_OVERFLOW");
if ( (v3[5] & 0x20) != 0 )
tmplog(", UNMOUNT");
if ( (char)v3[5] < 0 )
tmplog(", IGNORED");
if ( (v3[4] & 1) != 0 )
tmplog(", ACCESS");
if ( (v3[4] & 4) != 0 )
tmplog(", ATTRIB");
if ( (v3[4] & 8) != 0 )
tmplog(", CLOSE_WRITE");
if ( (v3[4] & 0x10) != 0 )
tmplog(", CLOSE_NOWRITE");
if ( (v3[5] & 1) != 0 )
tmplog(", CREATE");
if ( (v3[5] & 2) != 0 )
tmplog(", DELETE");
if ( (v3[5] & 4) != 0 )
tmplog(", DELETE_SELF");
if ( (v3[4] & 2) != 0 )
tmplog(", MODIFY");
if ( (v3[5] & 8) != 0 )
tmplog(", MOVE_SELF");
if ( (v3[4] & 0x40) != 0 )
tmplog(", MOVED_FROM (cookie=%d)", *((unsigned int *)v3 + 2));
if ( (char)v3[4] < 0 )
tmplog(", MOVED_TO (cookie=%d)", *((unsigned int *)v3 + 2));
if ( (v3[4] & 0x20) != 0 )
tmplog(", OPEN");
result = tmplog("\n");
}
}
while ( v1 > v4 );
}
return result;
}

original_code:
void handle_notify(void)
{
 char ibuf[256];
 int i = 0;
 int len = read(notify_fd, ibuf, sizeof(ibuf));
 while (i < len)
 {
  struct inotify_event *ie = (struct inotify_event *)&ibuf[i];
  i += sizeof(struct inotify_event) + ie->len;
  if (!ie->len)
   continue;
  tmplog("'%s': %s", ie->name, ie->mask & 0x40000000 ? "dir" : "file");
  if (ie->mask & 0x00004000)
   tmplog(", Q_OVERFLOW");
  if (ie->mask & 0x00002000)
   tmplog(", UNMOUNT");
  if (ie->mask & 0x00008000)
   tmplog(", IGNORED");
  if (ie->mask & 0x00000001)
   tmplog(", ACCESS");
  if (ie->mask & 0x00000004)
   tmplog(", ATTRIB");
  if (ie->mask & 0x00000008)
   tmplog(", CLOSE_WRITE");
  if (ie->mask & 0x00000010)
   tmplog(", CLOSE_NOWRITE");
  if (ie->mask & 0x00000100)
   tmplog(", CREATE");
  if (ie->mask & 0x00000200)
   tmplog(", DELETE");
  if (ie->mask & 0x00000400)
   tmplog(", DELETE_SELF");
  if (ie->mask & 0x00000002)
   tmplog(", MODIFY");
  if (ie->mask & 0x00000800)
   tmplog(", MOVE_SELF");
  if (ie->mask & 0x00000040)
   tmplog(", MOVED_FROM (cookie=%d)", ie->cookie);
  if (ie->mask & 0x00000080)
   tmplog(", MOVED_TO (cookie=%d)", ie->cookie);
  if (ie->mask & 0x00000020)
   tmplog(", OPEN");
  tmplog("\n");
 }
}

canonical_original_code:
void handle_notify()
{
 char ibuf[256];
 int i = 0;
 int len = read(notify_fd, ibuf, sizeof(ibuf));
 while (i < len)
 {
  struct inotify_event *ie = (struct inotify_event *)&ibuf[i];
  i += sizeof(struct inotify_event) + ie->len;
  if (!ie->len)
   continue;
  tmplog("'%s': %s", ie->name, ie->mask & 0x40000000 ? "dir" : "file");
  if (ie->mask & 0x00004000)
   tmplog(", Q_OVERFLOW");
  if (ie->mask & 0x00002000)
   tmplog(", UNMOUNT");
  if (ie->mask & 0x00008000)
   tmplog(", IGNORED");
  if (ie->mask & 0x00000001)
   tmplog(", ACCESS");
  if (ie->mask & 0x00000004)
   tmplog(", ATTRIB");
  if (ie->mask & 0x00000008)
   tmplog(", CLOSE_WRITE");
  if (ie->mask & 0x00000010)
   tmplog(", CLOSE_NOWRITE");
  if (ie->mask & 0x00000100)
   tmplog(", CREATE");
  if (ie->mask & 0x00000200)
   tmplog(", DELETE");
  if (ie->mask & 0x00000400)
   tmplog(", DELETE_SELF");
  if (ie->mask & 0x00000002)
   tmplog(", MODIFY");
  if (ie->mask & 0x00000800)
   tmplog(", MOVE_SELF");
  if (ie->mask & 0x00000040)
   tmplog(", MOVED_FROM (cookie=%d)", ie->cookie);
  if (ie->mask & 0x00000080)
   tmplog(", MOVED_TO (cookie=%d)", ie->cookie);
  if (ie->mask & 0x00000020)
   tmplog(", OPEN");
  tmplog("\n");
 }
}

variable_types:
ibuf
char [256]

variable_types: i int

variable_types: len int

variable_types: struct inotify_event { int wd; unsigned int mask; unsigned int cookie; unsigned int len; char name[]; } *


decompiled_code:
void __fastcall set_virtual_contents(__int64 a1, __int64 a2, __int64 a3)
{
*(_QWORD *)(a1 + 40) = a2;
*(_QWORD *)(a1 + 48) = a3;
}

original_code:
static void set_virtual_contents(struct atrfs_entry *ent, char *str, size_t sz)
{
 ((struct atrfs_virtual_entry*)(ent))->m_data = str;
 ((struct atrfs_virtual_entry*)(ent))->m_size = sz;
}

canonical_original_code:
static void set_virtual_contents(struct atrfs_entry *ent, char *str, unsigned long sz)
{
 ((struct atrfs_virtual_entry *)(ent))->m_data = str;
 ((struct atrfs_virtual_entry *)(ent))->m_size = sz;
}

variable_types:
str
char *

variable_types:
sz
unsigned long

user_defined_types: struct atrfs_virtual_entry { struct atrfs_entry entry; char *m_data; unsigned long m_size; struct atrfs_entry *next; void (*set_contents)(struct atrfs_entry *vent, char *str, unsigned long sz); }


original_code:
static int virtual_stat (struct atrfs_entry *ent, struct stat *st)
{
 st->st_ino = (ino_t)(unsigned long)ent;
 st->st_nlink = 1;
 st->st_size = ((struct atrfs_virtual_entry*)(ent))->m_size;
 st->st_mode = 0100000 | 0400;
 st->st_uid = getuid();
 st->st_gid = getgid();
 st->st_atim.tv_sec =
 st->st_mtim.tv_sec =
 st->st_ctim.tv_sec = time (((void *)0));
 return 0;
}

canonical_original_code:
static int virtual_stat(struct atrfs_entry *ent, struct stat *st)
{
 st->st_ino = (unsigned long)(unsigned long)ent;
 st->st_nlink = 1;
 st->st_size = ((struct atrfs_virtual_entry *)(ent))->m_size;
 st->st_mode = 0100000 | 0400;
 st->st_uid = getuid();
 st->st_gid = getgid();
 st->st_atim.tv_sec =
 st->st_mtim.tv_sec =
 st->st_ctim.tv_sec = time (((void *)0));
 return 0;
}

variable_types:
st
struct stat *


decompiled_code:
size_t __fastcall virtual_read(__int64 a1, void *a2, size_t a3, __int64 a4)
{
size_t v4; // rbx

v4 = a3;
if ( *(_QWORD *)(a1 + 48) < a4 + a3 )
v4 = *(_QWORD *)(a1 + 48) - a4;
memcpy(a2, (const void *)(*(_QWORD *)(a1 + 40) + a4), v4);
return v4;
}

canonical_decompiled_code:
size_t __fastcall func4(__int64 a1, void *a2, size_t a3, __int64 a4)
{
size_t v4; // rbx

v4 = a3;
if ( *(_QWORD *)(a1 + 48) < a4 + a3 )
v4 = *(_QWORD *)(a1 + 48) - a4;
memcpy(a2, (const void *)(*(_QWORD *)(a1 + 40) + a4), v4);
return v4;
}

original_code:
static ssize_t virtual_read (struct atrfs_entry *ent, char *buf, size_t size, off_t offset)
{
 ssize_t count = ((struct atrfs_virtual_entry*)(ent))->m_size;
 if (offset + size > count)
  size = count - offset;
 memcpy (buf, ((struct atrfs_virtual_entry*)(ent))->m_data + offset, size);
 return size;
}

canonical_original_code:
static long virtual_read(struct atrfs_entry *ent, char *buf, unsigned long size, long offset)
{
 long count = ((struct atrfs_virtual_entry*)(ent))->m_size;
 if (offset + size > count)
  size = count - offset;
 memcpy (buf, ((struct atrfs_virtual_entry *)(ent))->m_data + offset, size);
 return size;
}

variable_types: offset long

variable_types: count long


decompiled_code:
__int64 __fastcall file_read(__int64 a1, void *a2, size_t a3, __off64_t a4)
{
return (int)pread64(*(_DWORD *)(a1 + 40), a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, void *a2, size_t a3, __off64_t a4)
{
return (int)pread64(*(_DWORD *)(a1 + 40), a2, a3, a4);
}

original_code:
static ssize_t file_read (struct atrfs_entry *ent, char *buf, size_t size, off_t offset)
{
 int ret = pread (((struct atrfs_file_entry *)(ent))->fd, buf, size, offset);
 return ret;
}

canonical_original_code:
static long file_read(struct atrfs_entry *ent, char *buf, unsigned long size, long offset)
{
 int ret = pread (((struct atrfs_file_entry *)(ent))->fd, buf, size, offset);
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall ino_to_entry(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
if ( a1 == 1 )
v1 = root;
if ( (*(_BYTE *)(v1 + 24) & 2) != 0 )
tmplog("Warning: deleted entry accessed\n");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
if ( a1 == 1 )
v1 = root;
if ( (*(_BYTE *)(v1 + 24) & 2) != 0 )
tmplog("Warning: deleted entry accessed\n");
return v1;
}

original_code:
struct atrfs_entry *ino_to_entry(fuse_ino_t ino)
{
 struct atrfs_entry *ent = (struct atrfs_entry *)ino;
 if (ino == 1)
  ent = root;
 if (ent->flags & ENTRY_DELETED)
  tmplog("Warning: deleted entry accessed\n");
 return ent;
}

canonical_original_code:
struct atrfs_entry *ino_to_entry(unsigned long ino)
{
 struct atrfs_entry *ent = (struct atrfs_entry *)ino;
 if (ino == 1)
  ent = root;
 if (ent->flags & ENTRY_DELETED)
  tmplog("Warning: deleted entry accessed\n");
 return ent;
}

variable_types:
ino
unsigned long

return_type: struct atrfs_entry { enum atrfs_entry_type { ATRFS_FILE_ENTRY=0, ATRFS_DIRECTORY_ENTRY=1, ATRFS_VIRTUAL_FILE_ENTRY=2 } e_type; struct atrfs_entry *parent; char *name; unsigned char flags; struct atrfs_entry_ops { long (*read)(struct atrfs_entry *ent, char *buf, unsigned long size, long offset); void (*write)(struct atrfs_entry *ent, char *buf, unsigned long size); int (*stat)(struct atrfs_entry *ent, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *st); struct atrfs_entry *(*lookup_entry_by_name)(struct atrfs_entry *dir, char *name); } *ops; } *


decompiled_code:
__int64 __fastcall get_watchcount(__int64 a1)
{
return get_ivalue(a1, "count", 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return get_ivalue(a1, "count", 0LL);
}

original_code:
int get_watchcount(struct atrfs_entry *ent)
{
 return get_ivalue (ent, "count", 0);
}

variable_types: struct atrfs_entry { enum atrfs_entry_type { ATRFS_FILE_ENTRY=0, ATRFS_DIRECTORY_ENTRY=1, ATRFS_VIRTUAL_FILE_ENTRY=2 } e_type; struct atrfs_entry *parent; char *name; unsigned char flags; struct atrfs_entry_ops { long (*read)(struct atrfs_entry *ent, char *buf, unsigned long size, long offset); void (*write)(struct atrfs_entry *ent, char *buf, unsigned long size); int (*stat)(struct atrfs_entry *ent, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *st); struct atrfs_entry *(*lookup_entry_by_name)(struct atrfs_entry *dir, char *name); } *ops; } *


decompiled_code:
__int64 __fastcall get_watchtime(__int64 a1)
{
return get_dvalue(a1, "watchtime", 0.0);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return get_dvalue(a1, "watchtime", 0.0);
}

original_code:
double get_watchtime(struct atrfs_entry *ent)
{
 return get_dvalue (ent, "watchtime", 0.0);
}


decompiled_code:
__int64 __fastcall file_stat(__int64 a1, struct stat64 *a2, double a3)
{
if ( stat64(*(const char **)(a1 + 48), a2) < 0 )
return (unsigned int)*_errno_location();
a2->st_nlink = (int)get_watchcount(a1);
get_watchtime(a1);
a2->st_mtim.tv_sec = (unsigned int)(int)(a3 + 946677600.0);
a2->st_ino = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, struct stat64 *a2, double a3)
{
if ( stat64(*(const char **)(a1 + 48), a2) < 0 )
return (unsigned int)*_errno_location();
a2->st_nlink = (int)func7(a1);
func8(a1);
a2->st_mtim.tv_sec = (unsigned int)(int)(a3 + 946677600.0);
a2->st_ino = a1;
return 0LL;
}

original_code:
static int file_stat (struct atrfs_entry *ent, struct stat *st)
{
 char *filename = (((struct atrfs_file_entry *)(ent))->real_path);
 if (stat (filename, st) < 0)
  return (*__errno_location ());
 st->st_nlink = get_watchcount (ent);
 st->st_mtim.tv_sec = (time_t)(get_watchtime (ent) + 946677600.0);
 st->st_ino = (ino_t)(unsigned long)ent;
 return 0;
}

canonical_original_code:
static int file_stat(struct atrfs_entry *ent, struct stat *st)
{
 char *filename = (((struct atrfs_file_entry *)(ent))->real_path);
 if (stat (filename, st) < 0)
  return (*__errno_location ());
 st->st_nlink = get_watchcount (ent);
 st->st_mtim.tv_sec = (time_t)(get_watchtime (ent) + 946677600.0);
 st->st_ino = (unsigned long)(unsigned long)ent;
 return 0;
}

variable_types:
filename
char *


original_code:
struct atrfs_entry *lookup_entry_by_name (struct atrfs_entry *dir, const char *name)
{
 do { if (!(dir) || (dir)->e_type != (ATRFS_DIRECTORY_ENTRY)) abort ();} while(0);
 return dir->ops->lookup_entry_by_name (dir, name);
}

canonical_original_code:
struct atrfs_entry *lookup_entry_by_name(struct atrfs_entry *dir, char *name)
{
 do { if (!(dir) || (dir)->e_type != (ATRFS_DIRECTORY_ENTRY)) abort ();} while(0);
 return dir->ops->lookup_entry_by_name (dir, name);
}

variable_types:
dir
struct atrfs_entry *

variable_types:
name
char *


decompiled_code:
__int64 __fastcall map_leaf_entries(__int64 a1, __int64 (*a2)(void))
{
__int64 v2; // rax
__int64 v3; // r13
int **v4; // rbp
unsigned int v5; // ebx
int v6; // eax

if ( !a1 || *(_DWORD *)a1 != 1 )
abort();
v2 = g_hash_table_get_values(*(_QWORD *)(a1 + 40));
v3 = v2;
if ( v2 )
{
v4 = (int **)v2;
do
{
v6 = **v4;
if ( v6 == 1 )
{
v5 = map_leaf_entries(*v4, a2);
if ( v5 )
goto LABEL_14;
}
else
{
if ( (v6 & 0xFFFFFFFD) != 0 )
abort();
v5 = a2();
if ( v5 )
goto LABEL_14;
}
v4 = (int **)v4[1];
}
while ( v4 );
v5 = 0;
}
else
{
v5 = 0;
}
LABEL_14:
g_list_free(v3);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 (*a2)(void))
{
__int64 v2; // rax
__int64 v3; // r13
int **v4; // rbp
unsigned int v5; // ebx
int v6; // eax

if ( !a1 || *(_DWORD *)a1 != 1 )
abort();
v2 = g_hash_table_get_values(*(_QWORD *)(a1 + 40));
v3 = v2;
if ( v2 )
{
v4 = (int **)v2;
do
{
v6 = **v4;
if ( v6 == 1 )
{
v5 = func16(*v4, a2);
if ( v5 )
goto LABEL_14;
}
else
{
if ( (v6 & 0xFFFFFFFD) != 0 )
abort();
v5 = a2();
if ( v5 )
goto LABEL_14;
}
v4 = (int **)v4[1];
}
while ( v4 );
v5 = 0;
}
else
{
v5 = 0;
}
LABEL_14:
g_list_free(v3);
return v5;
}

original_code:
int map_leaf_entries (struct atrfs_entry *root, int (*fn) (struct atrfs_entry *ent))
{
 do { if (!(root) || (root)->e_type != (ATRFS_DIRECTORY_ENTRY)) abort ();} while(0);
 int ret = 0;
 GList *p, *entries = g_hash_table_get_values (((struct atrfs_directory_entry *)(root))->contents);
 struct atrfs_entry *ent;
 for (p = entries; p; p = p->next)
 {
  ent = p->data;
  switch (ent->e_type)
  {
  default:
   abort ();
  case ATRFS_DIRECTORY_ENTRY:
   ret = map_leaf_entries (ent, fn);
   if (ret)
    goto out;
   break;
  case ATRFS_VIRTUAL_FILE_ENTRY:
  case ATRFS_FILE_ENTRY:
   ret = fn (ent);
   if (ret)
    goto out;
   break;
  }
 }
out:
 g_list_free (entries);
 return ret;
}

canonical_original_code:
int map_leaf_entries(struct atrfs_entry *root, int (*fn)(struct atrfs_entry *ent))
{
 do { if (!(root) || (root)->e_type != (ATRFS_DIRECTORY_ENTRY)) abort ();} while(0);
 int ret = 0;
 struct _GList *p; struct _GList *entries = g_hash_table_get_values (((struct atrfs_directory_entry *)(root))->contents);
 struct atrfs_entry *ent;
 for (p = entries; p; p = p->next)
 {
  ent = p->data;
  switch (ent->e_type)
  {
  default:
   abort ();
  case ATRFS_DIRECTORY_ENTRY:
   ret = map_leaf_entries (ent, fn);
   if (ret)
    goto out;
   break;
  case ATRFS_VIRTUAL_FILE_ENTRY:
  case ATRFS_FILE_ENTRY:
   ret = fn (ent);
   if (ret)
    goto out;
   break;
  }
 }
out:
 g_list_free (entries);
 return ret;
}

variable_types:
fn
int (*)(struct atrfs_entry *ent)

variable_types: struct _GList { void *data; struct _GList *next; struct _GList *prev; } *


decompiled_code:
__int64 __fastcall get_realname(__int64 a1)
{
return *(_QWORD *)(a1 + 48);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)(a1 + 48);
}

original_code:
static char *get_realname(struct atrfs_entry *ent)
{
 return (((struct atrfs_file_entry *)(ent))->real_path);
}


decompiled_code:
char *get_countstr()
{
unsigned int v0; // eax

v0 = get_watchcount();
sprintf(buf_1, "%d", v0);
return buf_1;
}

canonical_decompiled_code:
char *func1()
{
unsigned int v0; // eax

v0 = get_watchcount();
sprintf(buf_1, "%d", v0);
return buf_1;
}

original_code:
static char *get_countstr(struct atrfs_entry *ent)
{
 static char buf[10];
 sprintf(buf, "%d", get_watchcount (ent));
 return buf;
}

variable_types:
buf
char [10]


decompiled_code:
__int64 get_watchtimestr()
{
get_watchtime();
return secs_to_timestr();
}

canonical_decompiled_code:
__int64 func2()
{
get_watchtime();
return secs_to_timestr();
}

original_code:
static char *get_watchtimestr(struct atrfs_entry *ent)
{
 return secs_to_timestr (get_watchtime (ent));
}


decompiled_code:
__int64 get_lengthstr()
{
get_length();
return secs_to_timestr();
}

canonical_decompiled_code:
__int64 func3()
{
get_length();
return secs_to_timestr();
}

original_code:
static char *get_lengthstr(struct atrfs_entry *ent)
{
 return secs_to_timestr (get_length (ent));
}


decompiled_code:
void atrfs_init()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void atrfs_init(void *userdata, struct fuse_conn_info *conn)
{
}

variable_types:
userdata
void *

variable_types: struct fuse_conn_info { unsigned int proto_major; unsigned int proto_minor; unsigned int async_read; unsigned int max_write; unsigned int max_readahead; unsigned int capable; unsigned int want; unsigned int max_background; unsigned int congestion_threshold; unsigned int reserved[23]; } *


decompiled_code:
__int64 atrfs_destroy()
{
tmplog("destroy()\n");
return close_entrydb();
}

canonical_decompiled_code:
__int64 func1()
{
tmplog("destroy()\n");
return close_entrydb();
}

original_code:
void atrfs_destroy(void *userdata)
{
 tmplog("destroy()\n");
 close_entrydb ();
}


decompiled_code:
__int64 __fastcall get_sha1_fast(char *path)
{
int v1; // ebp
const char *v2; // r12
size_t v3; // rax

v1 = getxattr(path, "user.sha1", 0LL, 0LL);
sha1_2 = 0LL;
if ( v1 > 0 )
goto LABEL_2;
v2 = (const char *)get_sha1(path);
sha1_2 = (__int64)v2;
v3 = strlen(v2);
if ( setxattr(path, "user.sha1", v2, v3 + 1, 0) )
perror("Can't set SHA1");
if ( !sha1_2 )
{
LABEL_2:
getxattr(path, "user.sha1", &buf_1, (unsigned int)v1);
sha1_2 = (__int64)&buf_1;
}
return sha1_2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *path)
{
int v1; // ebp
const char *v2; // r12
size_t v3; // rax

v1 = getxattr(path, "user.sha1", 0LL, 0LL);
sha1_2 = 0LL;
if ( v1 > 0 )
goto LABEL_2;
v2 = (const char *)get_sha1(path);
sha1_2 = (__int64)v2;
v3 = strlen(v2);
if ( setxattr(path, "user.sha1", v2, v3 + 1, 0) )
perror("Can't set SHA1");
if ( !sha1_2 )
{
LABEL_2:
getxattr(path, "user.sha1", &buf_1, (unsigned int)v1);
sha1_2 = (__int64)&buf_1;
}
return sha1_2;
}

original_code:
char *get_sha1_fast (char *filename)
{
 int len = getxattr (filename, "user.sha1", ((void *)0), 0);
 static char *sha1;
 static char buf[32];
 sha1 = ((void *)0);
 if (len <= 0)
 {
  sha1 = get_sha1 (filename);
  if (setxattr (filename, "user.sha1", sha1, strlen (sha1) + 1, 0))
   perror ("Can't set SHA1");
 }
 if (! sha1)
 {
  getxattr (filename, "user.sha1", buf, len);
  sha1 = buf;
 }
 return sha1;
}

canonical_original_code:
char *get_sha1_fast(char *filename)
{
 int len = getxattr (filename, "user.sha1", ((void *)0), 0);
 static char *sha1;
 static char buf[32];
 sha1 = ((void *)0);
 if (len <= 0)
 {
  sha1 = get_sha1 (filename);
  if (setxattr (filename, "user.sha1", sha1, strlen (sha1) + 1, 0))
   perror ("Can't set SHA1");
 }
 if (! sha1)
 {
  getxattr (filename, "user.sha1", buf, len);
  sha1 = buf;
 }
 return sha1;
}

variable_types: len int

variable_types:
buf
char [32]


decompiled_code:
__int64 entrydb_exec(__int64 a1, const char *a2, ...)
{
unsigned int v2; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
const char *v5; // [rsp+20h] [rbp-C8h] BYREF
char *ptr; // [rsp+28h] [rbp-C0h] BYREF

va_start(arg, a2);
ptr = 0LL;
v5 = 0LL;
vasprintf(&ptr, a2, arg);
sqlite3_exec(entrydb, ptr, a1, 0LL, &v5);
v2 = 1;
if ( v5 )
{
tmplog("%s while executing: \"%s\"\n", v5, ptr);
sqlite3_free(v5);
v2 = 0;
}
free(ptr);
return v2;
}

canonical_decompiled_code:
__int64 func2(__int64 a1, const char *a2, ...)
{
unsigned int v2; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
const char *v5; // [rsp+20h] [rbp-C8h] BYREF
char *ptr; // [rsp+28h] [rbp-C0h] BYREF

va_start(arg, a2);
ptr = 0LL;
v5 = 0LL;
vasprintf(&ptr, a2, arg);
sqlite3_exec(entrydb, ptr, a1, 0LL, &v5);
v2 = 1;
if ( v5 )
{
tmplog("%s while executing: \"%s\"\n", v5, ptr);
sqlite3_free(v5);
v2 = 0;
}
free(ptr);
return v2;
}

original_code:
_Bool entrydb_exec (int (*callback)(void *data, int ncols, char **values, char **names), char *cmdfmt, ...)
{
 char *cmd = ((void *)0), *err = ((void *)0);
 _Bool ret = 1;
 va_list list;
 __builtin_va_start(list,cmdfmt);
 vasprintf (&cmd, cmdfmt, list);
 sqlite3_exec (entrydb, cmd, callback, ((void *)0), &err);
 __builtin_va_end(list);
 if (err)
 {
  tmplog ("%s while executing: \"%s\"\n", err, cmd);
  sqlite3_free (err);
  ret = 0;
 }
 free (cmd);
 return ret;
}

canonical_original_code:
_Bool entrydb_exec(int (*callback)(void *data, int ncols, char **values, char **names), char *cmdfmt, ...)
{
 char *cmd = ((void *)0); char *err = ((void *)0);
 _Bool ret = 1;
 __builtin_va_list list;
 __builtin_va_start(list,cmdfmt);
 vasprintf (&cmd, cmdfmt, list);
 sqlite3_exec (entrydb, cmd, callback, ((void *)0), &err);
 __builtin_va_end(list);
 if (err)
 {
  tmplog ("%s while executing: \"%s\"\n", err, cmd);
  sqlite3_free (err);
  ret = 0;
 }
 free (cmd);
 return ret;
}

variable_types: int (*)(void *data, int ncols, char **values, char **names)

variable_types:
cmdfmt
char *

variable_types:
cmd
char *

variable_types:
err
char *