writeulonglong

decompiled_code:
__int64 __fastcall writeulonglong(__int64 a1, __int64 a2, unsigned __int64 a3, unsigned int a4, int a5)
{
unsigned __int64 v7; // rbx
unsigned int v8; // ebp
unsigned __int64 v9; // rcx
unsigned int v10; // er13
char *v11; // rdi
char *v12; // rax
unsigned __int64 v13; // rax
unsigned int v15; // esi

v7 = a3;
if ( a3 <= 9 )
{
v8 = 1;
}
else
{
v8 = 1;
do
{
v9 = a3;
++v8;
a3 /= 0xAuLL;
}
while ( v9 > 0x63 );
}
if ( a4 < v8 )
a4 = v8;
v10 = a4;
if ( !a1 )
return v10;
v11 = (char *)(a4 + a1);
if ( !a5 && a4 > v8 )
{
v12 = (char *)memset(&v11[~(unsigned __int64)(a4 - v8 - 1)], 32, a4 - v8);
a4 = v8;
v11 = v12;
}
do
{
*--v11 = v7 % 0xA + 48;
v13 = v7;
v7 /= 0xAuLL;
}
while ( v13 > 9 );
if ( a5 != 1 )
return v10;
v15 = a4 - v8;
if ( !v15 )
return v10;
memset(&v11[~(unsigned __int64)(v15 - 1)], 32, v15 - 1 + 1LL);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, unsigned __int64 a3, unsigned int a4, int a5)
{
unsigned __int64 v7; // rbx
unsigned int v8; // ebp
unsigned __int64 v9; // rcx
unsigned int v10; // er13
char *v11; // rdi
char *v12; // rax
unsigned __int64 v13; // rax
unsigned int v15; // esi

v7 = a3;
if ( a3 <= 9 )
{
v8 = 1;
}
else
{
v8 = 1;
do
{
v9 = a3;
++v8;
a3 /= 0xAuLL;
}
while ( v9 > 0x63 );
}
if ( a4 < v8 )
a4 = v8;
v10 = a4;
if ( !a1 )
return v10;
v11 = (char *)(a4 + a1);
if ( !a5 && a4 > v8 )
{
v12 = (char *)memset(&v11[~(unsigned __int64)(a4 - v8 - 1)], 32, a4 - v8);
a4 = v8;
v11 = v12;
}
do
{
*--v11 = v7 % 0xA + 48;
v13 = v7;
v7 /= 0xAuLL;
}
while ( v13 > 9 );
if ( a5 != 1 )
return v10;
v15 = a4 - v8;
if ( !v15 )
return v10;
memset(&v11[~(unsigned __int64)(v15 - 1)], 32, v15 - 1 + 1LL);
return v10;
}

original_code:
int writeulonglong(register char *s, char *end, unsigned long long u, unsigned int width,
     int align)
{
  register unsigned int len;
  unsigned long long q;
  int retval;
  len = 1;
  q = u;
  while (q > 9) {
    ++len;
    q /= 10;
  }
  if (len > width)
    width = len;
  retval = width;
  if (s) {
    s += width;
    if (align == 0) {
      while (width > len) {
 *--s = ' ';
 --width;
      }
    }
    do {
      *--s = '0' + (u % 10);
      u /= 10;
    } while (u);
    if (align == 1) {
      width -= len;
      while (width--)
 *--s = ' ';
    }
  }
  return retval;
}

canonical_original_code:
int writeulonglong(char *s, char *end, unsigned long long u, unsigned int width, int align)
{
  register unsigned int len;
  unsigned long long q;
  int retval;
  len = 1;
  q = u;
  while (q > 9) {
    ++len;
    q /= 10;
  }
  if (len > width)
    width = len;
  retval = width;
  if (s) {
    s += width;
    if (align == 0) {
      while (width > len) {
 *--s = ' ';
 --width;
      }
    }
    do {
      *--s = '0' + (u % 10);
      u /= 10;
    } while (u);
    if (align == 1) {
      width -= len;
      while (width--)
 *--s = ' ';
    }
  }
  return retval;
}

variable_types:
end
char *

variable_types:
u
unsigned long long

variable_types:
width
unsigned int

variable_types: align int

variable_types:
len
unsigned int

variable_types:
q
unsigned long long

variable_types: retval int


writelonglong

repo: tenchman/gsclu

decompiled_code:
__int64 __fastcall writelonglong(_BYTE *a1, __int64 a2, signed __int64 a3, unsigned int a4, int a5)
{
int v5; // ebx

v5 = 0;
if ( a3 < 0 )
{
*a1 = 45;
a3 = -a3;
++a1;
v5 = 1;
}
return v5 + (unsigned int)writeulonglong((__int64)a1, a2, a3, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func10(_BYTE *a1, __int64 a2, signed __int64 a3, unsigned int a4, int a5)
{
int v5; // ebx

v5 = 0;
if ( a3 < 0 )
{
*a1 = 45;
a3 = -a3;
++a1;
v5 = 1;
}
return v5 + (unsigned int)func9((__int64)a1, a2, a3, a4, a5);
}

original_code:
int writelonglong(register char *s, char *end, long long l, unsigned int width,
    int align)
{
  register unsigned int len = 0;
  if (l < 0LL) {
    *s++ = '-';
    ++len;
    l = -l;
  }
  return len + writeulonglong(s, end, (unsigned long long) l, width, align);
}

canonical_original_code:
int writelonglong(char *s, char *end, long long l, unsigned int width, int align)
{
  register unsigned int len = 0;
  if (l < 0LL) {
    *s++ = '-';
    ++len;
    l = -l;
  }
  return len + writeulonglong(s, end, (unsigned long long) l, width, align);
}

variable_types:
s
char *

variable_types:
l
long long

return_type: int


writestring

decompiled_code:
__int64 __fastcall writestring(void *s, unsigned __int64 a2, const char *a3, int a4)
{
_BYTE *v5; // rbp
const char *v6; // rbx
int v7; // eax
unsigned int v8; // er14
int v9; // edx
char v10; // al
char v11; // al

v5 = s;
v6 = a3;
v7 = strlen(a3);
v8 = v7;
if ( v7 <= a4 )
{
v9 = a4 - v7;
if ( (unsigned __int64)s < a2 )
goto LABEL_5;
}
else
{
v9 = 0;
if ( (unsigned __int64)s >= a2 )
goto LABEL_8;
v10 = *v6;
*(_BYTE *)s = *v6;
if ( v10 )
{
do
{
++v5;
++v6;
if ( a2 <= (unsigned __int64)v5 )
break;
LABEL_5:
v11 = *v6;
*v5 = *v6;
}
while ( v11 );
}
}
if ( v9 )
memset(v5, 32, v9);
LABEL_8:
if ( a4 )
v8 = a4;
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func11(void *s, unsigned __int64 a2, const char *a3, int a4)
{
_BYTE *v5; // rbp
const char *v6; // rbx
int v7; // eax
unsigned int v8; // er14
int v9; // edx
char v10; // al
char v11; // al

v5 = s;
v6 = a3;
v7 = strlen(a3);
v8 = v7;
if ( v7 <= a4 )
{
v9 = a4 - v7;
if ( (unsigned __int64)s < a2 )
goto LABEL_5;
}
else
{
v9 = 0;
if ( (unsigned __int64)s >= a2 )
goto LABEL_8;
v10 = *v6;
*(_BYTE *)s = *v6;
if ( v10 )
{
do
{
++v5;
++v6;
if ( a2 <= (unsigned __int64)v5 )
break;
LABEL_5:
v11 = *v6;
*v5 = *v6;
}
while ( v11 );
}
}
if ( v9 )
memset(v5, 32, v9);
LABEL_8:
if ( a4 )
v8 = a4;
return v8;
}

original_code:
int writestring(char *s, char *end, char *str, int width)
{
  int len = strlen(str);
  int pad = len > width ? 0 : width - len;
  while (s < end) {
    if (!(*s = *str))
      break;
    ++s;
    ++str;
  }
  while (pad) {
    *s++ = ' ';
    --pad;
  }
  return width ? width : len;
}

variable_types:
str
char *

variable_types: width int

variable_types: len int

variable_types: pad int


decompiled_code:
ssize_t __fastcall strbuf_write(__int64 a1, int a2)
{
size_t v2; // rdx
ssize_t result; // rax

if ( a1 && (v2 = *(unsigned int *)(a1 + 8), (_DWORD)v2) )
result = write(a2, *(const void **)a1, v2);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func0(__int64 a1, int a2)
{
size_t v2; // rdx
ssize_t result; // rax

if ( a1 && (v2 = *(unsigned int *)(a1 + 8), (_DWORD)v2) )
result = write(a2, *(const void **)a1, v2);
else
result = 0LL;
return result;
}

original_code:
size_t strbuf_write(strbuf_t * strbuf, int fd)
{
  size_t retval = 0;
  if ((strbuf?strbuf->len:0))
    retval = write(fd, strbuf->s, strbuf->len);
  return retval;
}

canonical_original_code:
unsigned long strbuf_write(struct strbuf_t *strbuf, int fd)
{
  unsigned long retval = 0;
  if ((strbuf?strbuf->len:0))
    retval = write(fd, strbuf->s, strbuf->len);
  return retval;
}

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

variable_types: fd int

variable_types:
retval
unsigned long

return_type: unsigned long


decompiled_code:
size_t __fastcall strbuf_prepends(__int64 a1, const char *a2)
{
size_t v2; // r12

v2 = 0LL;
if ( !a2 )
return v2;
v2 = strlen(a2);
if ( strbuf_check(a1, v2) )
return v2;
memmove((void *)(*(_QWORD *)a1 + v2), *(const void **)a1, (unsigned int)(*(_DWORD *)(a1 + 8) + 1));
memcpy(*(void **)a1, a2, v2);
*(_DWORD *)(a1 + 8) += v2;
return v2;
}

canonical_decompiled_code:
size_t __fastcall func0(__int64 a1, const char *a2)
{
size_t v2; // r12

v2 = 0LL;
if ( !a2 )
return v2;
v2 = strlen(a2);
if ( strbuf_check(a1, v2) )
return v2;
memmove((void *)(*(_QWORD *)a1 + v2), *(const void **)a1, (unsigned int)(*(_DWORD *)(a1 + 8) + 1));
memcpy(*(void **)a1, a2, v2);
*(_DWORD *)(a1 + 8) += v2;
return v2;
}

original_code:
size_t strbuf_prepends(strbuf_t * strbuf, const char *s)
{
  size_t len = 0;
  if (s) {
    len = strlen(s);
    if (strbuf_check(strbuf, len) == 0) {
      memmove(strbuf->s + len, strbuf->s, strbuf->len + 1);
      memcpy(strbuf->s, s, len);
      strbuf->len += len;
    }
  }
  return len;
}

canonical_original_code:
unsigned long strbuf_prepends(struct strbuf_t *strbuf, char *s)
{
  unsigned long len = 0;
  if (s) {
    len = strlen(s);
    if (strbuf_check(strbuf, len) == 0) {
      memmove(strbuf->s + len, strbuf->s, strbuf->len + 1);
      memcpy(strbuf->s, s, len);
      strbuf->len += len;
    }
  }
  return len;
}

variable_types:
len
unsigned long

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


tryopen

decompiled_code:
const char *__fastcall tryopen(const char *a1)
{
int v2; // edi
const char *result; // rax

v2 = open(a1, 0);
result = 0LL;
if ( v2 > 0 )
{
close(v2);
result = a1;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
int v2; // edi
const char *result; // rax

v2 = open(a1, 0);
result = 0LL;
if ( v2 > 0 )
{
close(v2);
result = a1;
}
return result;
}

original_code:
char *tryopen(const char *path)
{
  int fd;
  char *result = ((void *)0);
  if ((fd = open(path, 00)) > 0) {
    close(fd);
    result = (char *) path;
  }
  return result;
}

canonical_original_code:
char *tryopen(char *path)
{
  int fd;
  char *result = ((void *)0);
  if ((fd = open(path, 00)) > 0) {
    close(fd);
    result = (char *) path;
  }
  return result;
}

variable_types:
path
char *

variable_types:
result
char *

return_type: char *


decompiled_code:
void __fastcall __noreturn die_protocol(__int64 a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
*(_DWORD *)(a1 + 20) = -3;
die(a1, "protocol not supported", 0LL, a2, a3, a4, a5, a6, a7, a8, a9);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(__int64 a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
*(_DWORD *)(a1 + 20) = -3;
func3(a1, "protocol not supported", 0LL, a2, a3, a4, a5, a6, a7, a8, a9);
}

original_code:
void die_protocol(connection_t * conn)
{
  conn->code = -3;
  die(conn, "protocol not supported", ((void *)0));
}

canonical_original_code:
void die_protocol(struct connection_s *conn)
{
  conn->code = -3;
  die(conn, "protocol not supported", ((void *)0));
}

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

return_type: void

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:
void __fastcall __noreturn die_sys(__int64 a1, const void *a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10)
{
int *v10; // rax
char *v11; // rax
double v12; // xmm4_8
double v13; // xmm5_8

*(_DWORD *)(a1 + 20) = -1;
v10 = _errno_location();
v11 = strerror(*v10);
die(a1, a2, (__int64)v11, a3, a4, a5, a6, v12, v13, a9, a10);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(__int64 a1, const void *a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10)
{
int *v10; // rax
char *v11; // rax
double v12; // xmm4_8
double v13; // xmm5_8

*(_DWORD *)(a1 + 20) = -1;
v10 = _errno_location();
v11 = strerror(*v10);
func3(a1, a2, (__int64)v11, a3, a4, a5, a6, v12, v13, a9, a10);
}

original_code:
void die_sys(connection_t * conn, const char *message)
{
  conn->code = -1;
  die(conn, message, strerror((*__errno_location ())));
}

canonical_original_code:
void die_sys(struct connection_s *conn, char *message)
{
  conn->code = -1;
  die(conn, message, strerror((*__errno_location ())));
}

variable_types:
message
char *

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:
void __fastcall __noreturn die_write(__int64 a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
die_sys(a1, "write error", a2, a3, a4, a5, a6, a7, a8, a9);
}

canonical_decompiled_code:
void __fastcall __noreturn func6(__int64 a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
func5(a1, "write error", a2, a3, a4, a5, a6, a7, a8, a9);
}

original_code:
void die_write(connection_t * conn)
{
  die_sys(conn, "write error");
}

canonical_original_code:
void die_write(struct connection_s *conn)
{
  die_sys(conn, "write error");
}


decompiled_code:
const char *__fastcall tryopen_alt(__int64 a1, const char *a2, const char *a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
const char *v11; // r12
double v12; // xmm4_8
double v13; // xmm5_8
double v16; // xmm4_8
double v17; // xmm5_8

if ( a2 )
{
v11 = tryopen(a2);
if ( !v11 )
die_sys(a1, a2, a4, a5, a6, a7, v12, v13, a10, a11);
}
else
{
v11 = tryopen(a3);
if ( !v11 && *_errno_location() != 2 )
die_sys(a1, a3, a4, a5, a6, a7, v16, v17, a10, a11);
}
return v11;
}

canonical_decompiled_code:
const char *__fastcall func7(__int64 a1, const char *a2, const char *a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
const char *v11; // r12
double v12; // xmm4_8
double v13; // xmm5_8
double v16; // xmm4_8
double v17; // xmm5_8

if ( a2 )
{
v11 = func1(a2);
if ( !v11 )
func5(a1, a2, a4, a5, a6, a7, v12, v13, a10, a11);
}
else
{
v11 = func1(a3);
if ( !v11 && *_errno_location() != 2 )
func5(a1, a3, a4, a5, a6, a7, v16, v17, a10, a11);
}
return v11;
}

original_code:
char *tryopen_alt(connection_t * conn, const char *file1, const char *file2)
{
  char *result = ((void *)0);
  if (file1) {
    if (!(result = tryopen(file1)))
      die_sys(conn, file1);
  } else {
    if ((result = tryopen(file2)) == ((void *)0) && (*__errno_location ()) != 2)
      die_sys(conn, file2);
  }
  return result;
}

canonical_original_code:
char *tryopen_alt(struct connection_s *conn, char *file1, char *file2)
{
  char *result = ((void *)0);
  if (file1) {
    if (!(result = tryopen(file1)))
      die_sys(conn, file1);
  } else {
    if ((result = tryopen(file2)) == ((void *)0) && (*__errno_location ()) != 2)
      die_sys(conn, file2);
  }
  return result;
}


cleanup

original_code:
void cleanup(connection_t * conn, int how)
{
  if (conn->flags & (1<<0))
    gtget_ssl_close(conn);
  if (conn->sockfd > 0)
    close(conn->sockfd);
  memset(conn->response, 0, sizeof(response_header_t));
  conn->ressource = ((void *)0);
  conn->remote->host = ((void *)0);
  if (how) {
    if (conn->postfd > 0)
      close(conn->postfd);
    conn->postfd = 0;
    if (conn->outfd > 1)
      close(conn->outfd);
    conn->outfd = -1;
    if (conn->conffd > 1)
      close(conn->conffd);
    conn->conffd = -1;
    if (how > 1)
      unlink(conn->outfile);
  }
}

canonical_original_code:
void cleanup(struct connection_s *conn, int how)
{
  if (conn->flags & (1<<0))
    gtget_ssl_close(conn);
  if (conn->sockfd > 0)
    close(conn->sockfd);
  memset(conn->response, 0, sizeof(response_header_t));
  conn->ressource = ((void *)0);
  conn->remote->host = ((void *)0);
  if (how) {
    if (conn->postfd > 0)
      close(conn->postfd);
    conn->postfd = 0;
    if (conn->outfd > 1)
      close(conn->outfd);
    conn->outfd = -1;
    if (conn->conffd > 1)
      close(conn->conffd);
    conn->conffd = -1;
    if (how > 1)
      unlink(conn->outfile);
  }
}

variable_types: how int


die

decompiled_code:
void __fastcall __noreturn die(__int64 a1, const void *a2, __int64 a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
size_t v12; // rax
double v13; // xmm4_8
double v14; // xmm5_8

v12 = str_len(a2);
write(2, a2, v12);
if ( a3 )
write2f(": %s\n", a4, a5, a6, a7, v13, v14, a10, a11, a3);
else
write(2, "\n", 1uLL);
cleanup(a1, 2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(__int64 a1, const void *a2, __int64 a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
size_t v12; // rax
double v13; // xmm4_8
double v14; // xmm5_8

v12 = str_len(a2);
write(2, a2, v12);
if ( a3 )
func2(": %s\n", a4, a5, a6, a7, v13, v14, a10, a11, a3);
else
write(2, "\n", 1uLL);
func0(a1, 2);
exit(1);
}

original_code:
void die(connection_t * conn, const char *msg1, const char *msg2)
{
  write(2, msg1, str_len(msg1));
  if (msg2)
    write2f(": %s\n", msg2);
  else
    write(2, "\n", 1);
  cleanup(conn, 2);
  _exit(1);
}

canonical_original_code:
void die(struct connection_s *conn, char *msg1, char *msg2)
{
  write(2, msg1, str_len(msg1));
  if (msg2)
    write2f(": %s\n", msg2);
  else
    write(2, "\n", 1);
  cleanup(conn, 2);
  _exit(1);
}


decompiled_code:
__int64 __fastcall strbuf_vappendf(__int64 a1, const char *a2, void *a3)
{
int v3; // eax
__int64 v4; // rcx
__int64 v5; // r8
char *ptr; // [rsp+8h] [rbp-10h] BYREF

ptr = 0LL;
v3 = vasprintf(&ptr, a2, a3);
v5 = 0LL;
if ( v3 != -1 )
v5 = strbuf_nappends(a1, ptr, v3, v4, 0LL);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, void *a3)
{
int v3; // eax
__int64 v4; // rcx
__int64 v5; // r8
char *ptr; // [rsp+8h] [rbp-10h] BYREF

ptr = 0LL;
v3 = vasprintf(&ptr, a2, a3);
v5 = 0LL;
if ( v3 != -1 )
v5 = strbuf_nappends(a1, ptr, v3, v4, 0LL);
return v5;
}

original_code:
size_t strbuf_vappendf(strbuf_t * strbuf, const char *format, va_list ap)
{
  size_t len = 0;
  int r;
  char *s = ((void *)0);
  if (-1 != (r = vasprintf(&s, format, ap))) {
    len = strbuf_nappends(strbuf, s, r);
  }
  return len;
}

canonical_original_code:
unsigned long strbuf_vappendf(struct strbuf_t *strbuf, char *format, __builtin_va_list ap)
{
  unsigned long len = 0;
  int r;
  char *s = ((void *)0);
  if (-1 != (r = vasprintf(&s, format, ap))) {
    len = strbuf_nappends(strbuf, s, r);
  }
  return len;
}

variable_types:
format
char *

variable_types: r int


decompiled_code:
__int64 __fastcall fmt_long(_BYTE *a1, __int64 a2)
{
if ( a2 >= 0 )
return ((__int64 (*)(void))fmt_ulong)();
*a1 = 45;
return fmt_ulong(a1 + 1, -a2) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2)
{
if ( a2 >= 0 )
return ((__int64 (*)(void))fmt_ulong)();
*a1 = 45;
return fmt_ulong(a1 + 1, -a2) + 1;
}

original_code:
size_t fmt_long(char *dest, long n)
{
  if (n >= 0)
    return fmt_ulong(dest, n);
  *dest++ = '-';
  return 1 + fmt_ulong(dest, -n);
}

canonical_original_code:
unsigned long fmt_long(char *dest, long n)
{
  if (n >= 0)
    return fmt_ulong(dest, n);
  *dest++ = '-';
  return 1 + fmt_ulong(dest, -n);
}

variable_types:
dest
char *

variable_types: n long


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

v2[(int)fmt_xlonglong(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_xlonglong(v2)] = 0;
return strbuf_appends(a1, v2);
}

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

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

variable_types:
l
unsigned long long

variable_types:
buf
char [41]


decompiled_code:
size_t __fastcall strbuf_nappends(__int64 a1, const char *a2, size_t a3)
{
size_t v5; // rax
__int64 v6; // rdi

if ( a2 )
{
v5 = strlen(a2);
if ( v5 <= a3 )
a3 = v5;
if ( a1 )
{
v6 = *(unsigned int *)(a1 + 8);
if ( (unsigned int)(*(_DWORD *)(a1 + 12) - v6) >= a3 + 1 )
goto LABEL_6;
}
if ( strbuf_realloc(a1, a3) != -1 )
{
v6 = *(unsigned int *)(a1 + 8);
LABEL_6:
memcpy((void *)(*(_QWORD *)a1 + v6), a2, a3 + 1);
*(_DWORD *)(a1 + 8) += a3;
return a3;
}
}
return 0LL;
}

canonical_decompiled_code:
size_t __fastcall func0(__int64 a1, const char *a2, size_t a3)
{
size_t v5; // rax
__int64 v6; // rdi

if ( a2 )
{
v5 = strlen(a2);
if ( v5 <= a3 )
a3 = v5;
if ( a1 )
{
v6 = *(unsigned int *)(a1 + 8);
if ( (unsigned int)(*(_DWORD *)(a1 + 12) - v6) >= a3 + 1 )
goto LABEL_6;
}
if ( strbuf_realloc(a1, a3) != -1 )
{
v6 = *(unsigned int *)(a1 + 8);
LABEL_6:
memcpy((void *)(*(_QWORD *)a1 + v6), a2, a3 + 1);
*(_DWORD *)(a1 + 8) += a3;
return a3;
}
}
return 0LL;
}

original_code:
size_t strbuf_nappends(strbuf_t * strbuf, const char *s, const size_t n)
{
  size_t len = 0;
  if (s) {
    len = strlen(s);
    len = (n < len) ? n : len;
    if ((strbuf?strbuf->total-strbuf->len:0) < len + 1) {
      if (strbuf_realloc(strbuf, len) == (size_t)-1)
 return 0;
    }
    memcpy(strbuf->s + strbuf->len, s, len + 1);
    strbuf->len += len;
  }
  return len;
}

canonical_original_code:
unsigned long strbuf_nappends(struct strbuf_t *strbuf, char *s, unsigned long n)
{
  unsigned long len = 0;
  if (s) {
    len = strlen(s);
    len = (n < len) ? n : len;
    if ((strbuf?strbuf->total-strbuf->len:0) < len + 1) {
      if (strbuf_realloc(strbuf, len) == (unsigned long)-1)
 return 0;
    }
    memcpy(strbuf->s + strbuf->len, s, len + 1);
    strbuf->len += len;
  }
  return len;
}

variable_types:
s
char *

variable_types:
n
unsigned long


original_code:
int parse_mac(unsigned char *mac, char *str)
{
  int i;
  int count;
  char c;
  unsigned char val;
  int colon_ok = 1;
  for (i = 0; i < 6; i++) {
    mac[i] = 0;
  }
  for (i = 0; i < 6; i++) {
    count = 0;
    val = 0;
    do {
      c = toupper(*str++);
      if (c >= '0' && c <= '9') {
 val = (val * 16) + (c - '0');
      } else if (c >= 'A' && c <= 'F') {
 val = (val * 16) + (c - 'A') + 10;
      } else if (c == ':') {
 if (colon_ok || count-- != 0)
   break;
      } else if (c == '\0') {
 str--;
 break;
      } else {
 return 0;
      }
      colon_ok = 1;
    } while (++count < 2);
    colon_ok = (count < 2);
    *mac++ = val;
  }
  if (*str)
    return 0;
  return 1;
}

variable_types:
mac
unsigned char *

variable_types:
str
char *

variable_types: i int

variable_types: count int

variable_types: c char

variable_types:
val
unsigned char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r15
const char *v4; // r14
int v5; // er13
__int16 v6; // r12
int v7; // eax
unsigned __int16 v8; // ax
__int64 v9; // rdx
const char *v10; // r13
int v11; // eax
__int64 v12; // rdx
const char *v13; // rbp
const char *v14; // rdi
unsigned __int16 v15; // ax
__int64 v16; // rdx
char *v17; // rcx
__int64 i; // rax
int v19; // eax
int v20; // ebp
char *v22; // rbp
size_t v23; // rax
const void *v24; // rsi
size_t v25; // rdx
int *v26; // rbx
char *v27; // rax
size_t v28; // r12
char *v29; // rax
__int64 v30; // [rsp+8h] [rbp-460h]
int optval; // [rsp+10h] [rbp-458h] BYREF
struct in_addr inp; // [rsp+14h] [rbp-454h] BYREF
char v33[6]; // [rsp+1Ah] [rbp-44Eh] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-448h] BYREF
int buf; // [rsp+30h] [rbp-438h] BYREF
__int16 v36; // [rsp+34h] [rbp-434h]
char v37; // [rsp+36h] [rbp-432h] BYREF
char v38; // [rsp+96h] [rbp-3D2h] BYREF

v3 = "255.255.255.255";
v4 = "00a0c9852a5f";
v5 = 0;
optval = 1;
v6 = _bswap_16(0x7FFFLL, argv, envp);
while ( 2 )
{
v7 = getopt(argc, (char *const *)argv, "hvp:m:b:");
if ( v7 != -1 )
{
if ( v7 != 63 )
{
switch ( v7 )
{
case 'b':
v3 = optarg;
continue;
case 'h':
break;
case 'm':
v4 = optarg;
continue;
case 'p':
v8 = atoi(optarg);
v6 = _bswap_16(v8, argv, v9);
continue;
case 'v':
++v5;
continue;
default:
continue;
}
}
LABEL_27:
usage((void *)*argv);
}
break;
}
if ( v5 )
{
write(1, "Version: ", 0xAuLL);
v22 = versionid;
v23 = strlen(versionid);
write(1, v22, v23);
write(1, "\n", 2uLL);
exit(0);
}
v10 = argv[_bss_start];
v11 = _bss_start;
v12 = _bss_start;
if ( !v10 )
goto LABEL_26;
v13 = argv[v12 + 1];
++_bss_start;
if ( !v13 )
{
v4 = v10;
LABEL_26:
v13 = v3;
v10 = v4;
goto LABEL_14;
}
v14 = argv[v12 + 2];
v30 = v12 * 8;
_bss_start = v11 + 2;
if ( v14 )
{
_bss_start = v11 + 3;
v15 = atoi(v14);
v6 = _bswap_16(v15, argv, v16);
if ( *(const char **)((char *)argv + v30 + 24) )
goto LABEL_27;
}
LABEL_14:
if ( !(unsigned int)parse_mac(v33, v10) )
{
write(1, "Illegal MAC address: ", 0x16uLL);
v24 = v10;
v25 = strlen(v10);
goto LABEL_29;
}
if ( !inet_aton(v13, &inp) )
inp.s_addr = **(_DWORD **)gethostbyname(v13)->h_addr_list;
buf = -1;
v17 = &v37;
v36 = -1;
do
{
for ( i = 0LL; i != 6; ++i )
v17[i] = v33[i];
v17 += 6;
}
while ( &v38 != v17 );
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(struct in_addr *)&addr.sa_data[2] = inp;
*(_WORD *)addr.sa_data = v6;
v19 = socket(2, 2, 0);
v20 = v19;
if ( v19 < 0 )
{
write(1, "Can't allocate socket\n", 0x17uLL);
exit(1);
}
if ( setsockopt(v19, 1, 6, &optval, 4u) < 0 )
{
write(1, "Can't set socket option SO_BROADCAST: ", 0x27uLL);
v26 = __errno_location();
v27 = strerror(*v26);
v28 = strlen(v27);
v29 = strerror(*v26);
v25 = v28;
v24 = v29;
LABEL_29:
write(1, v24, v25);
write(1, "\n", 2uLL);
exit(1);
}
sendto(v20, &buf, 0x66uLL, 0, &addr, 0x10u);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r15
const char *v4; // r14
int v5; // er13
__int16 v6; // r12
int v7; // eax
unsigned __int16 v8; // ax
__int64 v9; // rdx
const char *v10; // r13
int v11; // eax
__int64 v12; // rdx
const char *v13; // rbp
const char *v14; // rdi
unsigned __int16 v15; // ax
__int64 v16; // rdx
char *v17; // rcx
__int64 i; // rax
int v19; // eax
int v20; // ebp
char *v22; // rbp
size_t v23; // rax
const void *v24; // rsi
size_t v25; // rdx
int *v26; // rbx
char *v27; // rax
size_t v28; // r12
char *v29; // rax
__int64 v30; // [rsp+8h] [rbp-460h]
int optval; // [rsp+10h] [rbp-458h] BYREF
struct in_addr inp; // [rsp+14h] [rbp-454h] BYREF
char v33[6]; // [rsp+1Ah] [rbp-44Eh] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-448h] BYREF
int buf; // [rsp+30h] [rbp-438h] BYREF
__int16 v36; // [rsp+34h] [rbp-434h]
char v37; // [rsp+36h] [rbp-432h] BYREF
char v38; // [rsp+96h] [rbp-3D2h] BYREF

v3 = "255.255.255.255";
v4 = "00a0c9852a5f";
v5 = 0;
optval = 1;
v6 = func7(0x7FFFLL, argv, envp);
while ( 2 )
{
v7 = getopt(argc, (char *const *)argv, "hvp:m:b:");
if ( v7 != -1 )
{
if ( v7 != 63 )
{
switch ( v7 )
{
case 'b':
v3 = optarg;
continue;
case 'h':
break;
case 'm':
v4 = optarg;
continue;
case 'p':
v8 = atoi(optarg);
v6 = func7(v8, argv, v9);
continue;
case 'v':
++v5;
continue;
default:
continue;
}
}
LABEL_27:
func8((void *)*argv);
}
break;
}
if ( v5 )
{
write(1, "Version: ", 0xAuLL);
v22 = versionid;
v23 = strlen(versionid);
write(1, v22, v23);
write(1, "\n", 2uLL);
exit(0);
}
v10 = argv[_bss_start];
v11 = _bss_start;
v12 = _bss_start;
if ( !v10 )
goto LABEL_26;
v13 = argv[v12 + 1];
++_bss_start;
if ( !v13 )
{
v4 = v10;
LABEL_26:
v13 = v3;
v10 = v4;
goto LABEL_14;
}
v14 = argv[v12 + 2];
v30 = v12 * 8;
_bss_start = v11 + 2;
if ( v14 )
{
_bss_start = v11 + 3;
v15 = atoi(v14);
v6 = func7(v15, argv, v16);
if ( *(const char **)((char *)argv + v30 + 24) )
goto LABEL_27;
}
LABEL_14:
if ( !(unsigned int)func9(v33, v10) )
{
write(1, "Illegal MAC address: ", 0x16uLL);
v24 = v10;
v25 = strlen(v10);
goto LABEL_29;
}
if ( !inet_aton(v13, &inp) )
inp.s_addr = **(_DWORD **)gethostbyname(v13)->h_addr_list;
buf = -1;
v17 = &v37;
v36 = -1;
do
{
for ( i = 0LL; i != 6; ++i )
v17[i] = v33[i];
v17 += 6;
}
while ( &v38 != v17 );
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(struct in_addr *)&addr.sa_data[2] = inp;
*(_WORD *)addr.sa_data = v6;
v19 = socket(2, 2, 0);
v20 = v19;
if ( v19 < 0 )
{
write(1, "Can't allocate socket\n", 0x17uLL);
exit(1);
}
if ( setsockopt(v19, 1, 6, &optval, 4u) < 0 )
{
write(1, "Can't set socket option SO_BROADCAST: ", 0x27uLL);
v26 = __errno_location();
v27 = strerror(*v26);
v28 = strlen(v27);
v29 = strerror(*v26);
v25 = v28;
v24 = v29;
LABEL_29:
write(1, v24, v25);
write(1, "\n", 2uLL);
exit(1);
}
sendto(v20, &buf, 0x66uLL, 0, &addr, 0x10u);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int sock;
  int optval = 1;
  int version = 0;
  int i, c, rc;
  size_t j;
  char msg[1024];
  int msglen = 0;
  struct sockaddr_in bcast;
  struct hostent *he;
  struct in_addr inaddr;
  unsigned char macaddr[6];
  char *mac = "00a0c9852a5f";
  char *target = "255.255.255.255";
  short bport = htons(32767);
  while ((c = getopt(argc, argv, "hvp:m:b:")) != (-1)) {
    switch (c) {
    case 'b':
      target = optarg;
      break;
    case 'm':
      mac = optarg;
      break;
    case 'p':
      bport = htons(atoi(optarg));
      break;
    case 'v':
      version++;
      break;
    case 'h':
    case '?':
      usage(argv[0]);
    }
  }
  if (version) {
    write(1, "Version: ", sizeof("Version: "));
    write(1, versionid, strlen(versionid));
    write(1, "\n", sizeof("\n"));
    exit(0);
  }
  if (argv[optind] != ((void *)0)) {
    mac = argv[optind++];
  }
  if (argv[optind] != ((void *)0)) {
    target = argv[optind++];
  }
  if (argv[optind] != ((void *)0)) {
    bport = htons(atoi(argv[optind++]));
  }
  if (argv[optind] != ((void *)0)) {
    usage(argv[0]);
  }
  if (!parse_mac(macaddr, mac)) {
    write(1, "Illegal MAC address: ", sizeof("Illegal MAC address: "));
    write(1, mac, strlen(mac));
    write(1, "\n", sizeof("\n"));
    exit(1);
  }
  if (!inet_aton(target, &inaddr)) {
    he = gethostbyname(target);
    inaddr = *(struct in_addr *) he->h_addr_list[0];
  }
  for (i = 0; i < 6; i++) {
    msg[msglen++] = 0xff;
  }
  for (i = 0; i < 16; i++) {
    for (j = 0; j < sizeof(macaddr); j++) {
      msg[msglen++] = macaddr[j];
    }
  }
  memset(&bcast, 0, sizeof(bcast));
  bcast.sin_family = 2;
  bcast.sin_addr.s_addr = inaddr.s_addr;
  bcast.sin_port = bport;
  sock = socket(2, SOCK_DGRAM, 0);
  if (sock < 0) {
    write(1, "Can't allocate socket\n", sizeof("Can't allocate socket\n"));
    exit(1);
  }
  if ((rc =
       setsockopt(sock, 1, 6, &optval,
    sizeof(optval))) < 0) {
    write(1, "Can't set socket option SO_BROADCAST: ", sizeof("Can't set socket option SO_BROADCAST: "));
    write(1, strerror((*__errno_location ())), strlen(strerror((*__errno_location ()))));
    write(1, "\n", sizeof("\n"));
    exit(1);
  }
  sendto(sock, &msg, msglen, 0, (struct sockaddr *) &bcast, sizeof(bcast));
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int sock;
  int optval = 1;
  int version = 0;
  int i; int c; int rc;
  unsigned long j;
  char msg[1024];
  int msglen = 0;
  struct sockaddr_in bcast;
  struct hostent *he;
  struct in_addr inaddr;
  unsigned char macaddr[6];
  char *mac = "00a0c9852a5f";
  char *target = "255.255.255.255";
  short bport = htons(32767);
  while ((c = getopt(argc, argv, "hvp:m:b:")) != (-1)) {
    switch (c) {
    case 'b':
      target = optarg;
      break;
    case 'm':
      mac = optarg;
      break;
    case 'p':
      bport = htons(atoi(optarg));
      break;
    case 'v':
      version++;
      break;
    case 'h':
    case '?':
      usage(argv[0]);
    }
  }
  if (version) {
    write(1, "Version: ", sizeof("Version: "));
    write(1, versionid, strlen(versionid));
    write(1, "\n", sizeof("\n"));
    exit(0);
  }
  if (argv[optind] != ((void *)0)) {
    mac = argv[optind++];
  }
  if (argv[optind] != ((void *)0)) {
    target = argv[optind++];
  }
  if (argv[optind] != ((void *)0)) {
    bport = htons(atoi(argv[optind++]));
  }
  if (argv[optind] != ((void *)0)) {
    usage(argv[0]);
  }
  if (!parse_mac(macaddr, mac)) {
    write(1, "Illegal MAC address: ", sizeof("Illegal MAC address: "));
    write(1, mac, strlen(mac));
    write(1, "\n", sizeof("\n"));
    exit(1);
  }
  if (!inet_aton(target, &inaddr)) {
    he = gethostbyname(target);
    inaddr = *(struct in_addr *) he->h_addr_list[0];
  }
  for (i = 0; i < 6; i++) {
    msg[msglen++] = 0xff;
  }
  for (i = 0; i < 16; i++) {
    for (j = 0; j < sizeof(macaddr); j++) {
      msg[msglen++] = macaddr[j];
    }
  }
  memset(&bcast, 0, sizeof(bcast));
  bcast.sin_family = 2;
  bcast.sin_addr.s_addr = inaddr.s_addr;
  bcast.sin_port = bport;
  sock = socket(2, SOCK_DGRAM, 0);
  if (sock < 0) {
    write(1, "Can't allocate socket\n", sizeof("Can't allocate socket\n"));
    exit(1);
  }
  if ((rc =
       setsockopt(sock, 1, 6, &optval,
    sizeof(optval))) < 0) {
    write(1, "Can't set socket option SO_BROADCAST: ", sizeof("Can't set socket option SO_BROADCAST: "));
    write(1, strerror((*__errno_location ())), strlen(strerror((*__errno_location ()))));
    write(1, "\n", sizeof("\n"));
    exit(1);
  }
  sendto(sock, &msg, msglen, 0, (struct sockaddr *) &bcast, sizeof(bcast));
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: sock int

variable_types: optval int

variable_types: version int

variable_types: c int

variable_types: rc int

variable_types:
j
unsigned long

variable_types:
msg
char [1024]

variable_types: msglen int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types:
inaddr
struct in_addr { unsigned int s_addr; }

variable_types:
macaddr
unsigned char [6]

variable_types:
mac
char *

variable_types:
target
char *

variable_types: bport short

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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


usage

decompiled_code:
void __fastcall __noreturn usage(void *buf)
{
size_t v1; // rax

write(1, "Usage: ", 8uLL);
v1 = strlen((const char *)buf);
write(1, buf, v1);
write(
1,
"[options] [mac] [broadcast] [port]\n"
" -b addr broadcast address\n"
" -m mac mac address of host\n"
" -p port UDP port to broadcast to\n"
" -v version\n",
0xA7uLL);
exit(0);
}

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

write(1, "Usage: ", 8uLL);
v1 = strlen((const char *)buf);
write(1, buf, v1);
write(
1,
"[options] [mac] [broadcast] [port]\n"
" -b addr broadcast address\n"
" -m mac mac address of host\n"
" -p port UDP port to broadcast to\n"
" -v version\n",
0xA7uLL);
exit(0);
}

original_code:
void usage(char *name)
{
  write(1, "Usage: ", sizeof("Usage: "));
  write(1, name, strlen(name));
  write(1, "[options] [mac] [broadcast] [port]\n" "    -b addr    broadcast address\n" "    -m mac     mac address of host\n" "    -p port    UDP port to broadcast to\n" "    -v         version\n", sizeof("[options] [mac] [broadcast] [port]\n" "    -b addr    broadcast address\n" "    -m mac     mac address of host\n" "    -p port    UDP port to broadcast to\n" "    -v         version\n"));
  exit(0);
}

variable_types:
name
char *


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

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

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

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

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


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

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

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

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

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


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

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

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

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

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


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 )
return (unsigned int)v6;
}
else if ( *(_DWORD *)(a1 + 232) <= 3u )
{
return (unsigned int)v6;
}
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 )
return (unsigned int)v6;
}
else if ( *(_DWORD *)(a1 + 232) <= 3u )
{
return (unsigned int)v6;
}
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


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


decompiled_code:
__int64 __fastcall str_eol(char *a1, __int64 *a2)
{
int v2; // eax
char v4; // cl
char *v5; // rdx
char v6; // si
char *v7; // rax
__int64 v8; // rdx
__int64 result; // rax

v2 = *a1;
v4 = *a1;
if ( *a1 )
{
v5 = a1;
while ( 1 )
{
v6 = v4;
v4 = v5[1];
if ( v2 == 10 || v2 == 13 )
break;
v2 = v4;
++v5;
if ( !v4 )
{
v7 = v5;
v8 = 0LL;
result = v7 - a1;
goto LABEL_7;
}
}
result = v5 - a1;
if ( v4 != 13 && v4 != 10 || (v8 = 2LL, v6 == v4) )
v8 = 1LL;
}
else
{
result = 0LL;
v8 = 0LL;
}
LABEL_7:
if ( a2 )
*a2 = v8;
return result;
}

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; // rax
__int64 v3; // r8
char v4; // al
_BYTE *v5; // rcx

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
__int64 v3; // r8
char v4; // al
_BYTE *v5; // rcx

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

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)
{
size_t v3; // rax

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

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

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

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 *


decompiled_code:
__int64 __fastcall timer_stop(struct timeval *a1)
{
__suseconds_t v2; // rax
__suseconds_t v3; // rdi
__time_t v4; // rdx
__int64 v5; // rcx
__int64 v6; // rdx
__int64 result; // rax
__time_t v8; // rcx

gettimeofday(a1 + 1, 0LL);
v2 = a1[1].tv_usec;
v3 = a1->tv_usec;
if ( v2 < v3 )
{
v8 = a1[1].tv_sec;
v2 += 1000000LL;
a1[1].tv_usec = v2;
v4 = v8 - 1;
a1[1].tv_sec = v8 - 1;
}
else
{
v4 = a1[1].tv_sec;
}
v5 = 1000 * (v4 - a1->tv_sec);
v6 = (unsigned __int128)(0x20C49BA5E353F7CFLL * (__int128)(v2 - v3)) >> 64;
result = (v2 - v3) >> 63;
a1[2].tv_sec = (v6 >> 7) - result + v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(struct timeval *a1)
{
__suseconds_t v2; // rax
__suseconds_t v3; // rdi
__time_t v4; // rdx
__int64 v5; // rcx
__int64 v6; // rdx
__int64 result; // rax
__time_t v8; // rcx

gettimeofday(a1 + 1, 0LL);
v2 = a1[1].tv_usec;
v3 = a1->tv_usec;
if ( v2 < v3 )
{
v8 = a1[1].tv_sec;
v2 += 1000000LL;
a1[1].tv_usec = v2;
v4 = v8 - 1;
a1[1].tv_sec = v8 - 1;
}
else
{
v4 = a1[1].tv_sec;
}
v5 = 1000 * (v4 - a1->tv_sec);
v6 = (unsigned __int128)(0x20C49BA5E353F7CFLL * (__int128)(v2 - v3)) >> 64;
result = (v2 - v3) >> 63;
a1[2].tv_sec = (v6 >> 7) - result + v5;
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; } *

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:
unsigned __int64 __fastcall fmt_xlonglong(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r12

v2 = HIDWORD(a2);
if ( HIDWORD(a2) )
{
v2 = (int)fmt_xlong(a1, HIDWORD(a2));
if ( a1 )
a1 += v2;
}
return v2 + fmt_xlong(a1, (unsigned int)a2);
}

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

v2 = HIDWORD(a2);
if ( HIDWORD(a2) )
{
v2 = (int)fmt_xlong(a1, HIDWORD(a2));
if ( a1 )
a1 += v2;
}
return v2 + fmt_xlong(a1, (unsigned int)a2);
}

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


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; // rbx
unsigned int v2; // eax
const char *v3; // r12
size_t v4; // rbp
const char **v5; // rbx

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

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

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

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; // rbp
__int64 v6; // r12

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; // rbp
__int64 v6; // r12

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)
{
size_t v3; // rbx
void *v4; // rdi
__int64 result; // rax
void *v6; // rax

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

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

v3 = a2;
LOBYTE(v3) = -1;
v4 = *(void **)a1;
if ( v4 )
{
v3 = a2 + *(unsigned int *)(a1 + 8);
LOBYTE(v3) = -1;
}
if ( v3 < a2 )
return -1LL;
v6 = realloc(v4, v3);
if ( !v6 )
return -1LL;
*(_QWORD *)a1 = v6;
result = 0LL;
*(_DWORD *)(a1 + 12) = v3;
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;
*(_QWORD *)(a1 + 8) = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
void *v2; // rdi

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

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

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
char *v4; // r14
char *v5; // r13
const char *v6; // r12
int v7; // eax
struct passwd *v8; // rax
int v9; // ebp
__int64 v11; // [rsp+0h] [rbp-88h]
int v12; // [rsp+Ch] [rbp-7Ch]
char *endptr; // [rsp+18h] [rbp-70h] BYREF
char dest[16]; // [rsp+20h] [rbp-68h] BYREF
__int128 v15; // [rsp+30h] [rbp-58h]
__int64 v16; // [rsp+40h] [rbp-48h]

v3 = 0;
v4 = "/dev/net/tun";
v5 = 0LL;
v6 = "";
v12 = 0;
v11 = geteuid();
while ( 2 )
{
v7 = getopt(argc, (char *const *)argv, "bd:f:t:u:");
if ( v7 > 0 )
{
switch ( v7 )
{
case 'b':
v12 = 1;
continue;
case 'd':
v6 = optarg;
v3 = 1;
continue;
case 'f':
v4 = optarg;
continue;
case 't':
v6 = optarg;
continue;
case 'u':
v5 = optarg;
v8 = getpwnam(optarg);
if ( v8 )
{
v11 = v8->pw_uid;
}
else
{
v11 = strtol(optarg, &endptr, 0);
if ( *endptr )
{
write2(optarg);
write2(": is neither a username nor a numeric uid.\n");
Usage();
}
}
continue;
default:
goto LABEL_26;
}
}
break;
}
if ( argc - _bss_start > 0 )
LABEL_26:
Usage();
v9 = open(v4, 2);
if ( v9 < 0 )
{
write2("Failed to open - ");
write2(v4);
exit(1);
}
v15 = 0LL;
v16 = 0LL;
LOWORD(v15) = 4098;
*(_OWORD *)dest = 0LL;
strncpy(dest, v6, 0xFuLL);
if ( ioctl(v9, 0x400454CAuLL, dest) < 0 )
{
perror("TUNSETIFF");
exit(1);
}
if ( v3 )
{
if ( ioctl(v9, 0x400454CBuLL, 0LL) >= 0 )
{
write1("Set '");
write1(dest);
write1("' nonpersistent\n");
return 0;
}
LABEL_28:
perror("TUNSETPERSIST");
exit(1);
}
if ( ioctl(v9, 0x400454CBuLL, 1LL) < 0 || ioctl(v9, 0x400454CCuLL, v11) < 0 )
goto LABEL_28;
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)
{
int v3; // er15
char *v4; // r14
char *v5; // r13
const char *v6; // r12
int v7; // eax
struct passwd *v8; // rax
int v9; // ebp
__int64 v11; // [rsp+0h] [rbp-88h]
int v12; // [rsp+Ch] [rbp-7Ch]
char *endptr; // [rsp+18h] [rbp-70h] BYREF
char dest[16]; // [rsp+20h] [rbp-68h] BYREF
__int128 v15; // [rsp+30h] [rbp-58h]
__int64 v16; // [rsp+40h] [rbp-48h]

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

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

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

if ( a2 >= 0 )
return ((__int64 (*)(void))fmt_ulonglong)();
v2 = 0LL;
if ( a1 )
{
*a1 = 45;
v2 = a1 + 1;
}
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; // r12
unsigned __int64 v3; // rax
_BYTE *v4; // rax
size_t v6; // r13

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

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r12
unsigned __int64 v3; // rax
_BYTE *v4; // rax
size_t v6; // r13

v2 = a2;
if ( a1 )
{
v3 = *(unsigned int *)(a1 + 8);
if ( v3 > a2 )
{
v4 = *(_BYTE **)a1;
*(_DWORD *)(a1 + 8) = a2;
v4[a2] = 0;
return v2;
}
}
else
{
v3 = 0LL;
}
if ( a2 > v3 )
{
v6 = (int)a2 - *(_DWORD *)(a1 + 8);
if ( strbuf_check(a1, v6) )
{
v2 = 0LL;
}
else
{
memset(*(void **)a1, 32, v6);
*(_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; // ebp
void *v4; // r12
int *v5; // rax
int v6; // er13
int *v7; // rbx
void *result; // rax

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

canonical_decompiled_code:
void *__fastcall func0(const char *a1, struct stat *a2)
{
int v2; // eax
int v3; // ebp
void *v4; // r12
int *v5; // rax
int v6; // er13
int *v7; // rbx
void *result; // rax

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

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


decompiled_code:
__int64 __fastcall str_casecmp(__int64 a1, __int64 a2)
{
__int64 v4; // rsi
int v5; // edx
int v6; // ecx
unsigned int v7; // eax
unsigned int v8; // edx
unsigned int v9; // edx
unsigned int v10; // ecx

v4 = 0LL;
do
{
v5 = *(char *)(a2 + v4);
v6 = *(char *)(a1 + v4);
v7 = v5 - 65;
v8 = v5 - 33;
if ( v7 < 0x1A )
v7 = v8;
v9 = v6 - 65;
v10 = v6 - 33;
if ( v9 < 0x1A )
v9 = v10;
if ( v7 != v9 )
break;
++v4;
}
while ( v7 != -65 );
return v9 - v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v4; // rsi
int v5; // edx
int v6; // ecx
unsigned int v7; // eax
unsigned int v8; // edx
unsigned int v9; // edx
unsigned int v10; // ecx

v4 = 0LL;
do
{
v5 = *(char *)(a2 + v4);
v6 = *(char *)(a1 + v4);
v7 = v5 - 65;
v8 = v5 - 33;
if ( v7 < 0x1A )
v7 = v8;
v9 = v6 - 65;
v10 = v6 - 33;
if ( v9 < 0x1A )
v9 = v10;
if ( v7 != v9 )
break;
++v4;
}
while ( v7 != -65 );
return v9 - v7;
}

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


main

repo: terimai/mmpeephole

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

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

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

v4 = open("/dev/mmpeephole", 0, envp);
if ( v4 == -1 )
{
perror("open mmpeephole device");
exit(1);
}
v5 = (char *)argv[1];
v6 = v4;
v7 = (char **)(argv + 1);
if ( v5 )
{
do
{
++v7;
func7(v6, v5);
v5 = *v7;
}
while ( *v7 );
}
close(v6);
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 *[]


decompiled_code:
int __fastcall print_mmap_handler(int fd, char *file)
{
int v2; // eax
int v3; // ebp
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; // ebp
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


repo: terjr/bitless-simulator

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

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

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

v3 = (unsigned int)func10("mordi.wav", v6, &v5);
printf("Read %d samples\n", v3);
func9(v5, (unsigned int)v3, 120LL);
v9 = v7;
return func11("output.wav", v8, v5, (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 )
return a1;
v2 = &a1[v1 - 1];
if ( *v2 != 10 )
return a1;
*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 )
return a1;
v2 = &a1[v1 - 1];
if ( *v2 != 10 )
return a1;
*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

decompiled_code:
__int64 __fastcall isint(const char *a1)
{
size_t v1; // r12
char v2; // bl
__int64 result; // rax
char *v4; // rbx

v1 = strlen(a1);
v2 = *a1;
result = (__int64)strchr("0123456789", *a1);
if ( v1 == 1 )
return result != 0;
if ( result || v2 == 45 )
{
if ( (int)v1 <= 1 )
{
LABEL_11:
result = 1LL;
}
else
{
v4 = (char *)(a1 + 1);
while ( strchr("0123456789", *v4) )
{
if ( &a1[(unsigned int)(v1 - 2) + 2] == ++v4 )
goto LABEL_11;
}
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
size_t v1; // r12
char v2; // bl
__int64 result; // rax
char *v4; // rbx

v1 = strlen(a1);
v2 = *a1;
result = (__int64)strchr("0123456789", *a1);
if ( v1 == 1 )
return result != 0;
if ( result || v2 == 45 )
{
if ( (int)v1 <= 1 )
{
LABEL_11:
result = 1LL;
}
else
{
v4 = (char *)(a1 + 1);
while ( strchr("0123456789", *v4) )
{
if ( &a1[(unsigned int)(v1 - 2) + 2] == ++v4 )
goto LABEL_11;
}
result = 0LL;
}
}
return result;
}

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; // er8
__int64 result; // rax
void *ptr; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

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

canonical_decompiled_code:
__int64 func0(__int64 a1, __int64 a2, const char *a3, ...)
{
int v3; // er8
__int64 result; // rax
void *ptr; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
ptr = 0LL;
v3 = vasprintf((char **)&ptr, a3, arg);
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_constprop_0(a1, a2, 1LL, "%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 ( func3(a1, a2, 1LL, "%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 result; // xmm0_8
double v3[2]; // [rsp+18h] [rbp-10h] BYREF

if ( get_value_internal_constprop_0(a1, a2, 1LL, "%lf", v3) )
result = v3[0];
return result;
}

canonical_decompiled_code:
double __fastcall func6(__int64 a1, __int64 a2)
{
double result; // xmm0_8
double v3[2]; // [rsp+18h] [rbp-10h] BYREF

if ( func3(a1, a2, 1LL, "%lf", v3) )
result = v3[0];
return result;
}

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 )
set_ivalue_cold();
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 )
func14();
return func0((__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 )
set_dvalue_cold();
return set_value_internal((__int64)a1, a2, "%lf", a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, __int64 a2, double a3)
{
if ( !a1 || *a1 )
func15();
return func0((__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);
}