original_code:
void sigsegv_handler(int sig, siginfo_t* siginfo, void* ptr __attribute__((unused)) )
{
  switch(sig) {
    case 11:
      SI = *siginfo;
      sig_error = 1;
      atexit(write_siginfo);
      exit(0);
      break;
    default:
      sig_error = -1;
  }
}

canonical_original_code:
void sigsegv_handler(int sig, struct siginfo_t *siginfo, void *ptr)
{
  switch(sig) {
    case 11:
      SI = *siginfo;
      sig_error = 1;
      atexit(write_siginfo);
      exit(0);
      break;
    default:
      sig_error = -1;
  }
}

variable_types: sig int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
ptr
void *

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


fatal

decompiled_code:
void __fastcall __noreturn fatal(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void fatal(const char* msg )
{
  perror(msg);
  exit(1);
}

canonical_original_code:
void fatal(char *msg)
{
  perror(msg);
  exit(1);
}

variable_types:
msg
char *

return_type: void


decompiled_code:
void *init_mem()
{
void *result; // rax

memsize = 4 * sysconf(30);
result = mmap(0LL, memsize, 3, 34, -1, 0LL);
mem = result;
if ( !result )
fatal("mmap");
return result;
}

canonical_decompiled_code:
void *func12()
{
void *result; // rax

memsize = 4 * sysconf(30);
result = mmap(0LL, memsize, 3, 34, -1, 0LL);
mem = result;
if ( !result )
func11("mmap");
return result;
}

original_code:
void init_mem()
{
  int pagesize = sysconf( _SC_PAGESIZE);
  memsize = 4* pagesize;
  mem = mmap(((void *)0), memsize, 0x1 | 0x2, 0x02 | 0x20, -1, 0);
  if(mem == ((void *)0)) {
    fatal("mmap");
  }
}

variable_types: pagesize int


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

for ( result = 0LL; !sig_error; *((_BYTE *)mem + result++) = a1 )
{
if ( memsize <= (int)result )
break;
}
return result;
}

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

for ( result = 0LL; !sig_error; *((_BYTE *)mem + result++) = a1 )
{
if ( memsize <= (int)result )
break;
}
return result;
}

original_code:
void mem_set(char a)
{
  for (int i = 0; sig_error == 0 && i < memsize; i++) {
    ((char*)mem)[i] = a;
  }
}

canonical_original_code:
void mem_set(char a)
{
  for (int i = 0; sig_error == 0 && i < memsize; i++) {
    ((char *)mem)[i] = a;
  }
}

variable_types: a char

variable_types: i int


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

result = mprotect(mem, memsize, 1);
if ( result == -1 )
fatal("mprotect");
return result;
}

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

result = mprotect(mem, memsize, 1);
if ( result == -1 )
func11("mprotect");
return result;
}

original_code:
void mem_set_protread()
{
  if(mprotect(mem, memsize, 0x1) == -1) {
    fatal("mprotect");
  }
}


decompiled_code:
void simple_sigsegv_handler()
{
sig_error = -1;
}

canonical_decompiled_code:
void func15()
{
sig_error = -1;
}

original_code:
void simple_sigsegv_handler(int sig __attribute__((unused)) )
{
  sig_error = -1;
}

canonical_original_code:
void simple_sigsegv_handler(int sig)
{
  sig_error = -1;
}


decompiled_code:
int set_sigsegvhandler()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_flags = 4;
v1.sa_handler = (__sighandler_t)sigsegv_handler;
result = sigaction(11, &v1, 0LL);
if ( result == -1 )
fatal("sigaction");
return result;
}

canonical_decompiled_code:
int func16()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_flags = 4;
v1.sa_handler = (__sighandler_t)sigsegv_handler;
result = sigaction(11, &v1, 0LL);
if ( result == -1 )
func11("sigaction");
return result;
}

original_code:
void set_sigsegvhandler()
{
  struct sigaction act;
  memset(&act, 0, sizeof(struct sigaction));
  act.sa_flags = 4 ;
  act.__sigaction_handler.sa_sigaction = sigsegv_handler;
  if(sigaction(11, &act, ((void *)0)) == -1) {
    fatal("sigaction");
  }
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }


decompiled_code:
void dirnotify_cleanup(void)
{
;
}

canonical_decompiled_code:
void func0(void)
{
;
}

original_code:
void dirnotify_cleanup()
{
}

canonical_original_code:
void dirnotify_cleanup()
{
}


killpid

decompiled_code:
void killpid(void)
{
sleep(4u);
kill(pid, 2);
}

canonical_decompiled_code:
void func2(void)
{
sleep(4u);
kill(pid, 2);
}

original_code:
void killpid()
{
  sleep(4);
  kill(pid, 2);
}


fatal

canonical_decompiled_code:
void __fastcall __noreturn func5(const char *a1)
{
perror(a1);
exit(1);
}


decompiled_code:
int __fastcall dirnotify_init(char *name)
{
int v1; // eax
int result; // eax

v1 = inotify_init();
notify_fd = v1;
if ( v1 == -1 )
fatal("inotify init");
result = inotify_add_watch(v1, name, 0x1000FFFu);
dir_fd = result;
if ( result == -1 )
fatal("inotify add");
return result;
}

canonical_decompiled_code:
int __fastcall func6(char *name)
{
int v1; // eax
int result; // eax

v1 = inotify_init();
notify_fd = v1;
if ( v1 == -1 )
func5("inotify init");
result = inotify_add_watch(v1, name, 0x1000FFFu);
dir_fd = result;
if ( result == -1 )
func5("inotify add");
return result;
}

variable_types:
dirname
char *


decompiled_code:
int __fastcall dirnotify_printname(__int64 a1)
{
int result; // eax

if ( *(_DWORD *)(a1 + 12) )
result = puts((const char *)(a1 + 16));
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
int result; // eax

if ( *(_DWORD *)(a1 + 12) )
result = puts((const char *)(a1 + 16));
return result;
}

original_code:
void dirnotify_printname(const struct inotify_event* event)
{
  if(event->len > 0)
  {
    puts(event->name);
  }
}

canonical_original_code:
void dirnotify_printname(struct inotify_event *event)
{
  if(event->len > 0)
  {
    puts(event->name);
  }
}

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


decompiled_code:
unsigned int __fastcall dirnotify_process(__int64 a1)
{
unsigned int result; // eax

result = *(_DWORD *)(a1 + 4);
if ( result > 0x20 )
{
if ( result == 256 )
{
puts("Received: IN_CREATE");
result = dirnotify_printname(a1);
}
else if ( result <= 0x100 )
{
if ( result == 64 )
{
puts("Received: IN_MOVED_FROM");
dirnotify_printname(a1);
if ( to_cookie > 0 && *(_DWORD *)(a1 + 8) == to_cookie )
{
result = printf(" ...renamed from %s\n", &to_name);
from_cookie = -1;
}
else
{
result = *(_DWORD *)(a1 + 8);
from_cookie = result;
if ( *(_DWORD *)(a1 + 12) )
result = (unsigned int)strcpy(&from_name, (const char *)(a1 + 16));
else
from_name = 0;
}
}
else if ( result == 128 )
{
puts("Received: IN_MOVED_TO");
dirnotify_printname(a1);
if ( from_cookie > 0 && *(_DWORD *)(a1 + 8) == from_cookie )
{
result = printf(" ...renamed to %s\n", &from_name);
to_cookie = -1;
}
else
{
result = *(_DWORD *)(a1 + 8);
to_cookie = result;
if ( *(_DWORD *)(a1 + 12) )
result = (unsigned int)strcpy(&to_name, (const char *)(a1 + 16));
else
to_name = 0;
}
}
}
else
{
switch ( result )
{
case 0x400u:
puts("Received: IN_DELETE_SELF");
dirnotify_printname(a1);
fatal("Directory deleted, exiting");
case 0x800u:
puts("Received: IN_MOVE_SELF");
result = dirnotify_printname(a1);
break;
case 0x200u:
puts("Received: IN_DELETE");
result = dirnotify_printname(a1);
break;
}
}
}
else if ( result )
{
switch ( result )
{
case 1u:
puts("Received: IN_ACCESS");
result = dirnotify_printname(a1);
break;
case 2u:
puts("Received: IN_MODIFY");
result = dirnotify_printname(a1);
break;
case 4u:
puts("Received: IN_ATTRIB");
result = dirnotify_printname(a1);
break;
case 8u:
puts("Received: IN_CLOSE_WRITE");
result = dirnotify_printname(a1);
break;
case 0x10u:
puts("Received: IN_CLOSE_NOWRITE");
result = dirnotify_printname(a1);
break;
case 0x20u:
puts("Received: IN_OPEN");
result = dirnotify_printname(a1);
break;
default:
return result;
}
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func8(__int64 a1)
{
unsigned int result; // eax

result = *(_DWORD *)(a1 + 4);
if ( result > 0x20 )
{
if ( result == 256 )
{
puts("Received: IN_CREATE");
result = func7(a1);
}
else if ( result <= 0x100 )
{
if ( result == 64 )
{
puts("Received: IN_MOVED_FROM");
func7(a1);
if ( to_cookie > 0 && *(_DWORD *)(a1 + 8) == to_cookie )
{
result = printf(" ...renamed from %s\n", &to_name);
from_cookie = -1;
}
else
{
result = *(_DWORD *)(a1 + 8);
from_cookie = result;
if ( *(_DWORD *)(a1 + 12) )
result = (unsigned int)strcpy(&from_name, (const char *)(a1 + 16));
else
from_name = 0;
}
}
else if ( result == 128 )
{
puts("Received: IN_MOVED_TO");
func7(a1);
if ( from_cookie > 0 && *(_DWORD *)(a1 + 8) == from_cookie )
{
result = printf(" ...renamed to %s\n", &from_name);
to_cookie = -1;
}
else
{
result = *(_DWORD *)(a1 + 8);
to_cookie = result;
if ( *(_DWORD *)(a1 + 12) )
result = (unsigned int)strcpy(&to_name, (const char *)(a1 + 16));
else
to_name = 0;
}
}
}
else
{
switch ( result )
{
case 0x400u:
puts("Received: IN_DELETE_SELF");
func7(a1);
func5("Directory deleted, exiting");
case 0x800u:
puts("Received: IN_MOVE_SELF");
result = func7(a1);
break;
case 0x200u:
puts("Received: IN_DELETE");
result = func7(a1);
break;
}
}
}
else if ( result )
{
switch ( result )
{
case 1u:
puts("Received: IN_ACCESS");
result = func7(a1);
break;
case 2u:
puts("Received: IN_MODIFY");
result = func7(a1);
break;
case 4u:
puts("Received: IN_ATTRIB");
result = func7(a1);
break;
case 8u:
puts("Received: IN_CLOSE_WRITE");
result = func7(a1);
break;
case 0x10u:
puts("Received: IN_CLOSE_NOWRITE");
result = func7(a1);
break;
case 0x20u:
puts("Received: IN_OPEN");
result = func7(a1);
break;
default:
return result;
}
}
return result;
}

original_code:
void dirnotify_process(const struct inotify_event* event)
{
  switch(event->mask) {
    case 0x00000001: puts("Received: " "IN_ACCESS" "");dirnotify_printname(event);
      break;
    case 0x00000004: puts("Received: " "IN_ATTRIB" "");dirnotify_printname(event);
      break;
    case 0x00000008: puts("Received: " "IN_CLOSE_WRITE" "");dirnotify_printname(event);
      break;
    case 0x00000010: puts("Received: " "IN_CLOSE_NOWRITE" "");dirnotify_printname(event);
      break;
    case 0x00000100: puts("Received: " "IN_CREATE" "");dirnotify_printname(event);
      break;
    case 0x00000200: puts("Received: " "IN_DELETE" "");dirnotify_printname(event);
      break;
    case 0x00000400: puts("Received: " "IN_DELETE_SELF" "");dirnotify_printname(event);
      fatal("Directory deleted, exiting");
      break;
    case 0x00000002: puts("Received: " "IN_MODIFY" "");dirnotify_printname(event);
      break;
    case 0x00000800: puts("Received: " "IN_MOVE_SELF" "");dirnotify_printname(event);
      break;
    case 0x00000040: puts("Received: " "IN_MOVED_FROM" "");dirnotify_printname(event);
      if(to_cookie > 0 && event->cookie == (unsigned)to_cookie)
      {
        printf(" ...renamed from %s\n", to_name);
        from_cookie = -1;
      } else {
        from_cookie = event->cookie;
        if(event->len > 0) {
          strcpy(from_name, event->name);
        } else {
          from_name[0] = '\0';
        }
      }
      break;
    case 0x00000080: puts("Received: " "IN_MOVED_TO" "");dirnotify_printname(event);
      if(from_cookie > 0 && event->cookie == (unsigned)from_cookie)
      {
        printf(" ...renamed to %s\n", from_name);
        to_cookie = -1;
      } else {
        to_cookie = event->cookie;
        if(event->len > 0) {
          strcpy(to_name, event->name);
        } else {
          to_name[0] = '\0';
        }
      }
      break;
    case 0x00000020: puts("Received: " "IN_OPEN" "");dirnotify_printname(event);
      break;
  }
}

canonical_original_code:
void dirnotify_process(struct inotify_event *event)
{
  switch(event->mask) {
    case 0x00000001: puts("Received: " "IN_ACCESS" "");dirnotify_printname(event);
      break;
    case 0x00000004: puts("Received: " "IN_ATTRIB" "");dirnotify_printname(event);
      break;
    case 0x00000008: puts("Received: " "IN_CLOSE_WRITE" "");dirnotify_printname(event);
      break;
    case 0x00000010: puts("Received: " "IN_CLOSE_NOWRITE" "");dirnotify_printname(event);
      break;
    case 0x00000100: puts("Received: " "IN_CREATE" "");dirnotify_printname(event);
      break;
    case 0x00000200: puts("Received: " "IN_DELETE" "");dirnotify_printname(event);
      break;
    case 0x00000400: puts("Received: " "IN_DELETE_SELF" "");dirnotify_printname(event);
      fatal("Directory deleted, exiting");
      break;
    case 0x00000002: puts("Received: " "IN_MODIFY" "");dirnotify_printname(event);
      break;
    case 0x00000800: puts("Received: " "IN_MOVE_SELF" "");dirnotify_printname(event);
      break;
    case 0x00000040: puts("Received: " "IN_MOVED_FROM" "");dirnotify_printname(event);
      if(to_cookie > 0 && event->cookie == (unsigned int)to_cookie)
      {
        printf(" ...renamed from %s\n", to_name);
        from_cookie = -1;
      } else {
        from_cookie = event->cookie;
        if(event->len > 0) {
          strcpy(from_name, event->name);
        } else {
          from_name[0] = '\0';
        }
      }
      break;
    case 0x00000080: puts("Received: " "IN_MOVED_TO" "");dirnotify_printname(event);
      if(from_cookie > 0 && event->cookie == (unsigned int)from_cookie)
      {
        printf(" ...renamed to %s\n", from_name);
        to_cookie = -1;
      } else {
        to_cookie = event->cookie;
        if(event->len > 0) {
          strcpy(to_name, event->name);
        } else {
          to_name[0] = '\0';
        }
      }
      break;
    case 0x00000020: puts("Received: " "IN_OPEN" "");dirnotify_printname(event);
      break;
  }
}

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


decompiled_code:
void __noreturn dirnotify_watch()
{
int v0; // eax
int v1; // er14
int v2; // er12
int v3; // ebx
_BYTE v4[320]; // [rsp+0h] [rbp-140h] BYREF

while ( 1 )
{
v0 = read(notify_fd, v4, 0x110uLL);
v1 = v0;
if ( v0 == -1 )
break;
v2 = 0;
if ( v0 > 0 )
{
do
{
dirnotify_process((__int64)&v4[v2]);
v3 = *(_DWORD *)&v4[v2 + 12];
info("next..");
v2 += v3 + 16;
}
while ( v1 > v2 );
}
info("--");
fflush(stdout);
}
fatal("read");
}

original_code:
void dirnotify_watch()
{
  int maxsize = sizeof(struct inotify_event) + 255 + 1;
  char buf[maxsize];
  int size;
  while( 1 > 0) {
    if((size = read(notify_fd, buf, maxsize)) == -1)
      fatal("read");
    for(int i = 0; i < size; i = i + sizeof(struct inotify_event)){
      struct inotify_event* this = (struct inotify_event*)(buf + i);
      dirnotify_process(this);
      i = i + this -> len;
      info("next..");
    }
    info("--");
    fflush(stdout);
  }
}

canonical_original_code:
void dirnotify_watch()
{
  int maxsize = sizeof(struct inotify_event) + 255 + 1;
  char buf[-1];
  int size;
  while( 1 > 0) {
    if((size = read(notify_fd, buf, maxsize)) == -1)
      fatal("read");
    for(int i = 0; i < size; i = i + sizeof(struct inotify_event)){
      struct inotify_event *this = (struct inotify_event*)(buf + i);
      dirnotify_process(this);
      i = i + this -> len;
      info("next..");
    }
    info("--");
    fflush(stdout);
  }
}

variable_types: maxsize int

variable_types:
buf
char [-1]

variable_types: size int


decompiled_code:
int set_siginth()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_handler = sigint_handler;
result = sigaction(2, &v1, 0LL);
if ( result )
fatal("sigaction");
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_handler = sigint_handler;
result = sigaction(2, &v1, 0LL);
if ( result )
func5("sigaction");
return result;
}

original_code:
void set_siginth()
{
  struct sigaction act;
  memset(&act, 0, sizeof(struct sigaction));
  act.__sigaction_handler.sa_handler = sigint_handler;
  if(sigaction(2, &act, ((void *)0)) != 0) {
    fatal("sigaction");
  }
}

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


watch

decompiled_code:
void __fastcall __noreturn watch(char *format)
{
dirnotify_init(format);
if ( atexit(dirnotify_cleanup) )
fatal("atexit");
info("Watching dir:");
info(format);
dirnotify_watch();
}

canonical_decompiled_code:
void __fastcall __noreturn func11(char *format)
{
func6(format);
if ( atexit(dirnotify_cleanup) )
func5("atexit");
func4("Watching dir:");
func4(format);
func9();
}

original_code:
int watch(const char* name)
{
  dirnotify_init(name);
  if(atexit(dirnotify_cleanup) != 0) {
    fatal("atexit");
  }
  info("Watching dir:");
  info(name);
  dirnotify_watch();
  exit(0);
}

canonical_original_code:
int watch(char *name)
{
  dirnotify_init(name);
  if(atexit(dirnotify_cleanup) != 0) {
    fatal("atexit");
  }
  info("Watching dir:");
  info(name);
  dirnotify_watch();
  exit(0);
}

variable_types:
name
char *

return_type: int


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

if ( *a2 != -1 )
_assert_fail("(*fd) == -1", "7.c", 0xA1u, "open_read");
result = open(a1, 0);
*a2 = result;
if ( result < 0 )
fatal("openr");
return result;
}

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

if ( *a2 != -1 )
_assert_fail("(*fd) == -1", "7.c", 0xA1u, "open_read");
result = open(a1, 0);
*a2 = result;
if ( result < 0 )
func5("openr");
return result;
}

original_code:
void open_read(const char* fullname, int* fd)
{
  ((void) sizeof (((*fd) == -1) ? 1 : 0), __extension__ ({ if ((*fd) == -1) ; else __assert_fail ("(*fd) == -1", "7.c", 161, __extension__ __PRETTY_FUNCTION__); }));
  if(((*fd) = open(fullname, 00)) < 0) {
    fatal("openr");
  }
}

canonical_original_code:
void open_read(char *fullname, int *fd)
{
  ((void) sizeof (((*fd) == -1) ? 1 : 0), __extension__ ({ if ((*fd) == -1) ; else __assert_fail ("(*fd) == -1", "7.c", 161, __extension__ __PRETTY_FUNCTION__); }));
  if(((*fd) = open(fullname, 00)) < 0) {
    fatal("openr");
  }
}

variable_types:
fullname
char *

variable_types:
fd
int *


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

if ( *a2 != -1 )
_assert_fail("(*fd) == -1", "7.c", 0xA9u, "open_write");
result = open(a1, 2);
*a2 = result;
if ( result < 0 )
fatal("openw");
return result;
}

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

if ( *a2 != -1 )
_assert_fail("(*fd) == -1", "7.c", 0xA9u, "open_write");
result = open(a1, 2);
*a2 = result;
if ( result < 0 )
func5("openw");
return result;
}

original_code:
void open_write(const char* fullname, int* fd)
{
  ((void) sizeof (((*fd) == -1) ? 1 : 0), __extension__ ({ if ((*fd) == -1) ; else __assert_fail ("(*fd) == -1", "7.c", 169, __extension__ __PRETTY_FUNCTION__); }));
  if(((*fd) = open(fullname, 02)) < 0) {
    fatal("openw");
  }
}

canonical_original_code:
void open_write(char *fullname, int *fd)
{
  ((void) sizeof (((*fd) == -1) ? 1 : 0), __extension__ ({ if ((*fd) == -1) ; else __assert_fail ("(*fd) == -1", "7.c", 169, __extension__ __PRETTY_FUNCTION__); }));
  if(((*fd) = open(fullname, 02)) < 0) {
    fatal("openw");
  }
}


decompiled_code:
void __fastcall create_new_file(const char *a1)
{
int v1; // ebx
int fd[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( creat(a1, 0x1C0u) < 0 && *_errno_location() != 17 )
fatal("creat");
fd[0] = -1;
open_write(a1, fd);
v1 = 4;
do
{
write(fd[0], "tt0t0t0t0tnananananananananananananananananananananan", 0xAuLL);
--v1;
}
while ( v1 );
close_descriptor(fd);
}

canonical_decompiled_code:
void __fastcall func15(const char *a1)
{
int v1; // ebx
int fd[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( creat(a1, 0x1C0u) < 0 && *_errno_location() != 17 )
func5("creat");
fd[0] = -1;
func14(a1, fd);
v1 = 4;
do
{
write(fd[0], "tt0t0t0t0tnananananananananananananananananananananan", 0xAuLL);
--v1;
}
while ( v1 );
func12(fd);
}

original_code:
void create_new_file(const char* name)
{
  if(creat(name, (0100 | 0400 | 0200)) < 0 && (*__errno_location ()) != 17) {
    fatal("creat");
  }
  int ind = -1;
  open_write(name, &ind);
  for (int i = 0; i < 4; i++) {
    write(ind, "tt0t0t0t0tnananananananananananananananananananananan", 10);
  }
  close_descriptor(&ind);
}

canonical_original_code:
void create_new_file(char *name)
{
  if(creat(name, (0100 | 0400 | 0200)) < 0 && (*__errno_location ()) != 17) {
    fatal("creat");
  }
  int ind = -1;
  open_write(name, &ind);
  for (int i = 0; i < 4; i++) {
    write(ind, "tt0t0t0t0tnananananananananananananananananananananan", 10);
  }
  close_descriptor(&ind);
}

variable_types: ind int


decompiled_code:
void __fastcall forge_new_file(char *dest, char *src, int *a3)
{
unsigned int v3; // er12
int v4; // eax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

v3 = *a3;
close_descriptor(a3);
v4 = rand();
sprintf(v5, "lala77%d5aa%ld", v3, v4);
strcpy(dest, src);
strcat(dest, v5);
create_new_file(dest);
}

canonical_decompiled_code:
void __fastcall func16(char *dest, char *src, int *a3)
{
unsigned int v3; // er12
int v4; // eax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

v3 = *a3;
func12(a3);
v4 = rand();
sprintf(v5, "lala77%d5aa%ld", v3, v4);
strcpy(dest, src);
strcat(dest, v5);
func15(dest);
}

original_code:
void forge_new_file(char* name, const char* prefix, int* fd)
{
  int oldfd = *fd;
  close_descriptor(fd);
  char buf[255];
  sprintf(buf, "lala77%d5aa%ld", oldfd, (size_t) rand());
  strcpy(name, prefix);
  strcat(name, buf);
  create_new_file(name);
}

canonical_original_code:
void forge_new_file(char *name, char *prefix, int *fd)
{
  int oldfd = *fd;
  close_descriptor(fd);
  char buf[255];
  sprintf(buf, "lala77%d5aa%ld", oldfd, (unsigned long) rand());
  strcpy(name, prefix);
  strcat(name, buf);
  create_new_file(name);
}

variable_types:
prefix
char *

variable_types: oldfd int

variable_types:
buf
char [255]


decompiled_code:
int hackNCreate_cleanup()
{
if ( ind != -1 )
close_descriptor(&ind);
unlink(fullname);
return unlink("totally_not_an_old_dir");
}

canonical_decompiled_code:
int func17()
{
if ( ind != -1 )
func12(&ind);
unlink(fullname);
return unlink("totally_not_an_old_dir");
}

original_code:
void hackNCreate_cleanup()
{
  if(ind != -1) {
    close_descriptor(&ind);
  }
  unlink(fullname);
  unlink("totally_not_an_old_dir");
}


hackNCreate

decompiled_code:
void __fastcall hackNCreate(char *path)
{
__int64 v1; // [rsp+0h] [rbp-1E8h] BYREF
char v2[144]; // [rsp+20h] [rbp-1C8h] BYREF
__int64 v3; // [rsp+B0h] [rbp-138h]
__int64 v4; // [rsp+B8h] [rbp-130h]
char dest[2]; // [rsp+C0h] [rbp-128h] BYREF
struct timeb timebuf; // [rsp+1D0h] [rbp-18h] BYREF

ftime(&timebuf);
srand(LODWORD(timebuf.time) + timebuf.millitm);
strcpy(dest, path);
*(_WORD *)&dest[strlen(dest)] = 47;
forge_new_file(fullname, dest, &ind);
v3 = 0LL;
v4 = 0LL;
memset(v2, 0, sizeof(v2));
while ( 1 )
{
switch ( rand() % 12 )
{
case 0:
goto LABEL_3;
case 1:
puts("-------------testing attrib..");
if ( chmod(fullname, 0x1C0u) )
fatal("chmod1");
if ( chmod(fullname, 0x1F0u) )
fatal("chmod2");
break;
case 3:
puts("-------------testing close_nowrite..");
LABEL_3:
puts("-------------testing access..");
close_descriptor(&ind);
open_read(fullname, &ind);
if ( read(ind, &v1, 0x14uLL) < 0 )
fatal("read");
close_descriptor(&ind);
break;
case 4:
goto LABEL_11;
case 5:
puts("-------------testing create..");
if ( unlink(fullname) )
fatal("unlink");
goto LABEL_25;
case 6:
puts("-------------testing modify..");
LABEL_11:
puts("-------------testing close_write..");
close_descriptor(&ind);
open_write(fullname, &ind);
write(ind, "wriiiiiiting...", 6uLL);
close_descriptor(&ind);
break;
case 7:
puts("-------------testing delete..");
if ( unlink(fullname) )
fatal("unlink");
goto LABEL_25;
case 8:
puts("-------------testing delete_self..");
if ( unlink(fullname) )
fatal("unlink");
close_descriptor(&ind);
if ( rmdir(path) )
fatal("rmdir");
fwrite("Deleted dir, exiting..\n", 1uLL, 0x17uLL, stderr);
exit(0);
case 9:
puts("-------------testing move_self..");
close_descriptor(&ind);
unlink(fullname);
if ( rename(path, "totally_not_an_old_dir") )
fatal("rmdir");
fwrite("Renamed old dir, exiting..\n", 1uLL, 0x1BuLL, stderr);
exit(0);
case 10:
puts("-------------testing move_to..");
create_new_file("OpSys7Thrash");
if ( unlink(fullname) )
fatal("unlink");
close_descriptor(&ind);
if ( rename("OpSys7Thrash", fullname) )
fatal("rename");
break;
case 11:
puts("-------------testing move_from..");
if ( rename(fullname, "OpSys7Thrash") )
fatal("rename");
if ( unlink("OpSys7Thrash") )
fatal("unlink");
LABEL_25:
forge_new_file(fullname, dest, &ind);
break;
default:
break;
}
sleep(2u);
}
}

canonical_decompiled_code:
void __fastcall func18(char *path)
{
__int64 v1; // [rsp+0h] [rbp-1E8h] BYREF
char v2[144]; // [rsp+20h] [rbp-1C8h] BYREF
__int64 v3; // [rsp+B0h] [rbp-138h]
__int64 v4; // [rsp+B8h] [rbp-130h]
char dest[2]; // [rsp+C0h] [rbp-128h] BYREF
struct timeb timebuf; // [rsp+1D0h] [rbp-18h] BYREF

ftime(&timebuf);
srand(LODWORD(timebuf.time) + timebuf.millitm);
strcpy(dest, path);
*(_WORD *)&dest[strlen(dest)] = 47;
func16(fullname, dest, &ind);
v3 = 0LL;
v4 = 0LL;
memset(v2, 0, sizeof(v2));
while ( 1 )
{
switch ( rand() % 12 )
{
case 0:
goto LABEL_3;
case 1:
puts("-------------testing attrib..");
if ( chmod(fullname, 0x1C0u) )
func5("chmod1");
if ( chmod(fullname, 0x1F0u) )
func5("chmod2");
break;
case 3:
puts("-------------testing close_nowrite..");
LABEL_3:
puts("-------------testing access..");
func12(&ind);
func13(fullname, &ind);
if ( read(ind, &v1, 0x14uLL) < 0 )
func5("read");
func12(&ind);
break;
case 4:
goto LABEL_11;
case 5:
puts("-------------testing create..");
if ( unlink(fullname) )
func5("unlink");
goto LABEL_25;
case 6:
puts("-------------testing modify..");
LABEL_11:
puts("-------------testing close_write..");
func12(&ind);
func14(fullname, &ind);
write(ind, "wriiiiiiting...", 6uLL);
func12(&ind);
break;
case 7:
puts("-------------testing delete..");
if ( unlink(fullname) )
func5("unlink");
goto LABEL_25;
case 8:
puts("-------------testing delete_self..");
if ( unlink(fullname) )
func5("unlink");
func12(&ind);
if ( rmdir(path) )
func5("rmdir");
fwrite("Deleted dir, exiting..\n", 1uLL, 0x17uLL, stderr);
exit(0);
case 9:
puts("-------------testing move_self..");
func12(&ind);
unlink(fullname);
if ( rename(path, "totally_not_an_old_dir") )
func5("rmdir");
fwrite("Renamed old dir, exiting..\n", 1uLL, 0x1BuLL, stderr);
exit(0);
case 10:
puts("-------------testing move_to..");
func15("OpSys7Thrash");
if ( unlink(fullname) )
func5("unlink");
func12(&ind);
if ( rename("OpSys7Thrash", fullname) )
func5("rename");
break;
case 11:
puts("-------------testing move_from..");
if ( rename(fullname, "OpSys7Thrash") )
func5("rename");
if ( unlink("OpSys7Thrash") )
func5("unlink");
LABEL_25:
func16(fullname, dest, &ind);
break;
default:
break;
}
sleep(2u);
}
}

original_code:
void hackNCreate(const char* name)
{
  struct timeb t;
  ftime(&t);
  srand( t.time + t.millitm );
  char prefix[255 + 2];
  strcpy(prefix, name);
  strcat(prefix, "/");
  forge_new_file(fullname, prefix, &ind);
  struct utimbuf ut;
  memset(&ut, 0, sizeof(ut));
  struct stat buf;
  memset(&buf, 0, sizeof(buf));
  while( 1 > 0) {
    switch(rand() % 12) {
      case 3:
        printf("-------------testing close_nowrite..\n");
      case 0:
        printf("-------------testing access..\n");
        close_descriptor(&ind);
        open_read(fullname, &ind);
        char b[20];
        if(read(ind, (void*)b, sizeof(b)) < 0) {
          fatal("read");
        }
        close_descriptor(&ind);
        break;
      case 1:
        printf("-------------testing attrib..\n");
        if(chmod(fullname, (0100 | 0400 | 0200)) != 0) {
          fatal("chmod1");
        }
        if(chmod(fullname, ((0100 | 0400 | 0200) | (0200 >> 3) | (0400 >> 3))) != 0) {
          fatal("chmod2");
        }
        break;
      case 6:
        printf("-------------testing modify..\n");
      case 4:
        printf("-------------testing close_write..\n");
        close_descriptor(&ind);
        open_write(fullname, &ind);
        write(ind, "wriiiiiiting...", 6);
        close_descriptor(&ind);
        break;
      case 5:
        printf("-------------testing create..\n");
        if(unlink(fullname) != 0) {
          fatal("unlink");
        }
        forge_new_file(fullname, prefix, &ind);
        break;
      case 7:
        printf("-------------testing delete..\n");
        if(unlink(fullname) != 0) {
          fatal("unlink");
        }
        forge_new_file(fullname, prefix, &ind);
        break;
      case 10:
        printf("-------------testing move_to..\n");
        create_new_file("OpSys7Thrash");
        if(unlink(fullname) != 0) {
          fatal("unlink");
        }
        close_descriptor(&ind);
        if(rename("OpSys7Thrash", fullname) != 0) {
          fatal("rename");
        }
        break;
      case 11:
        printf("-------------testing move_from..\n");
        if(rename(fullname, "OpSys7Thrash") != 0) {
          fatal("rename");
        }
        if(unlink("OpSys7Thrash") != 0) {
          fatal("unlink");
        }
        forge_new_file(fullname, prefix, &ind);
        break;
      case 8:
        printf("-------------testing delete_self..\n");
        if(unlink(fullname) != 0) {
          fatal("unlink");
        }
        close_descriptor(&ind);
        if(rmdir(name) != 0) {
          fatal("rmdir");
        } else {
          fprintf(stderr, "Deleted dir, exiting..\n");
          exit(0);
        }
        break;
      case 9:
        printf("-------------testing move_self..\n");
        close_descriptor(&ind);
        unlink(fullname);
        if(rename(name, "totally_not_an_old_dir") != 0) {
          fatal("rmdir");
        } else {
          fprintf(stderr, "Renamed old dir, exiting..\n");
          exit(0);
        }
        break;
    }
    sleep(2);
  }
}

canonical_original_code:
void hackNCreate(char *name)
{
  struct timeb t;
  ftime(&t);
  srand( t.time + t.millitm );
  char prefix[-1];
  strcpy(prefix, name);
  strcat(prefix, "/");
  forge_new_file(fullname, prefix, &ind);
  struct utimbuf ut;
  memset(&ut, 0, sizeof(ut));
  struct stat buf;
  memset(&buf, 0, sizeof(buf));
  while( 1 > 0) {
    switch(rand() % 12) {
      case 3:
        printf("-------------testing close_nowrite..\n");
      case 0:
        printf("-------------testing access..\n");
        close_descriptor(&ind);
        open_read(fullname, &ind);
        char b[20];
        if(read(ind, (void *)b, sizeof(b)) < 0) {
          fatal("read");
        }
        close_descriptor(&ind);
        break;
      case 1:
        printf("-------------testing attrib..\n");
        if(chmod(fullname, (0100 | 0400 | 0200)) != 0) {
          fatal("chmod1");
        }
        if(chmod(fullname, ((0100 | 0400 | 0200) | (0200 >> 3) | (0400 >> 3))) != 0) {
          fatal("chmod2");
        }
        break;
      case 6:
        printf("-------------testing modify..\n");
      case 4:
        printf("-------------testing close_write..\n");
        close_descriptor(&ind);
        open_write(fullname, &ind);
        write(ind, "wriiiiiiting...", 6);
        close_descriptor(&ind);
        break;
      case 5:
        printf("-------------testing create..\n");
        if(unlink(fullname) != 0) {
          fatal("unlink");
        }
        forge_new_file(fullname, prefix, &ind);
        break;
      case 7:
        printf("-------------testing delete..\n");
        if(unlink(fullname) != 0) {
          fatal("unlink");
        }
        forge_new_file(fullname, prefix, &ind);
        break;
      case 10:
        printf("-------------testing move_to..\n");
        create_new_file("OpSys7Thrash");
        if(unlink(fullname) != 0) {
          fatal("unlink");
        }
        close_descriptor(&ind);
        if(rename("OpSys7Thrash", fullname) != 0) {
          fatal("rename");
        }
        break;
      case 11:
        printf("-------------testing move_from..\n");
        if(rename(fullname, "OpSys7Thrash") != 0) {
          fatal("rename");
        }
        if(unlink("OpSys7Thrash") != 0) {
          fatal("unlink");
        }
        forge_new_file(fullname, prefix, &ind);
        break;
      case 8:
        printf("-------------testing delete_self..\n");
        if(unlink(fullname) != 0) {
          fatal("unlink");
        }
        close_descriptor(&ind);
        if(rmdir(name) != 0) {
          fatal("rmdir");
        } else {
          fprintf(stderr, "Deleted dir, exiting..\n");
          exit(0);
        }
        break;
      case 9:
        printf("-------------testing move_self..\n");
        close_descriptor(&ind);
        unlink(fullname);
        if(rename(name, "totally_not_an_old_dir") != 0) {
          fatal("rmdir");
        } else {
          fprintf(stderr, "Renamed old dir, exiting..\n");
          exit(0);
        }
        break;
    }
    sleep(2);
  }
}

variable_types: struct timeb { long time; unsigned short millitm; short timezone; short dstflag; }

variable_types:
prefix
char [-1]

variable_types: struct utimbuf { long actime; long modtime; }

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:
b
char [20]

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


fatal

decompiled_code:
void __fastcall __noreturn fatal(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void fatal(const char* msg )
{
  perror(msg);
  exit(1);
}

variable_types:
msg
char *


sperm

decompiled_code:
void *sperm()
{
strmode();
return &local_buff_0;
}

canonical_decompiled_code:
void *func10()
{
strmode();
return &local_buff_0;
}

original_code:
char const * sperm(__mode_t mode)
{
  static char local_buff[20] = {0};
  strmode(mode, local_buff);
  return local_buff;
}

canonical_original_code:
char *sperm(unsigned int mode)
{
  static char local_buff[20] = {0};
  strmode(mode, local_buff);
  return local_buff;
}

variable_types:
mode
unsigned int

return_type: char *


decompiled_code:
void __fastcall print_info(char *a1)
{
char *v1; // rbx
const char *v2; // rax
struct passwd *v3; // rax
struct group *v4; // rax
struct tm *v5; // rbp
char *v6; // rax
char v7[256]; // [rsp+0h] [rbp-1A8h] BYREF
struct stat v8; // [rsp+100h] [rbp-A8h] BYREF

if ( *a1 == 47 )
{
v1 = a1;
}
else
{
v1 = a1;
do
++v1;
while ( *v1 != 47 );
}
if ( v1[1] )
{
if ( (unsigned int)stat(a1, &v8) == -1 )
fatal("stat");
printf("%6d ", LODWORD(v8.st_ino));
printf("%4jd ", (unsigned __int64)v8.st_blocks >> 1);
v2 = (const char *)sperm();
printf("%10.10s", v2);
printf("%4d ", LODWORD(v8.st_nlink));
v3 = getpwuid(v8.st_uid);
if ( v3 )
printf("%-8.8s ", v3->pw_name);
else
printf("%-8d ", v8.st_uid);
v4 = getgrgid(v8.st_gid);
if ( v4 )
printf("%-8.8s ", v4->gr_name);
else
printf("%-8d ", v8.st_gid);
printf("%9jd ", v8.st_size);
v5 = localtime(&v8.st_mtim.tv_sec);
v6 = nl_langinfo(131112);
strftime(v7, 0x100uLL, v6, v5);
printf("%s ", v7);
puts(v1 + 1);
}
}

canonical_decompiled_code:
void __fastcall func11(char *a1)
{
char *v1; // rbx
const char *v2; // rax
struct passwd *v3; // rax
struct group *v4; // rax
struct tm *v5; // rbp
char *v6; // rax
char v7[256]; // [rsp+0h] [rbp-1A8h] BYREF
struct stat v8; // [rsp+100h] [rbp-A8h] BYREF

if ( *a1 == 47 )
{
v1 = a1;
}
else
{
v1 = a1;
do
++v1;
while ( *v1 != 47 );
}
if ( v1[1] )
{
if ( (unsigned int)func15(a1, &v8) == -1 )
func9("stat");
printf("%6d ", LODWORD(v8.st_ino));
printf("%4jd ", (unsigned __int64)v8.st_blocks >> 1);
v2 = (const char *)func10();
printf("%10.10s", v2);
printf("%4d ", LODWORD(v8.st_nlink));
v3 = getpwuid(v8.st_uid);
if ( v3 )
printf("%-8.8s ", v3->pw_name);
else
printf("%-8d ", v8.st_uid);
v4 = getgrgid(v8.st_gid);
if ( v4 )
printf("%-8.8s ", v4->gr_name);
else
printf("%-8d ", v8.st_gid);
printf("%9jd ", v8.st_size);
v5 = localtime(&v8.st_mtim.tv_sec);
v6 = nl_langinfo(131112);
strftime(v7, 0x100uLL, v6, v5);
printf("%s ", v7);
puts(v1 + 1);
}
}

original_code:
void print_info(const char* name)
{
  const char* from_slash = name;
  for (; from_slash[0] != '/'; from_slash++) {
  }
  from_slash++;
  if(*from_slash == '\0') {
    return;
  }
  struct stat buf;
  if( stat(name, &buf) == -1) {
    fatal("stat");
  }
  printf("%6d ", (int)buf.st_ino);
  printf("%4jd ", (size_t)buf.st_blocks / 2);
  printf("%10.10s", sperm(buf.st_mode));
  printf("%4d ", (int)buf.st_nlink);
  struct passwd *pwd;
  struct group *grp;
  struct tm *tm;
  char datestring[256];
  if((pwd = getpwuid(buf.st_uid)) != ((void *)0)) {
    printf("%-8.8s ", pwd->pw_name);
  } else {
    printf("%-8d ", buf.st_uid);
  }
  if((grp = getgrgid(buf.st_gid)) != ((void *)0)) {
    printf("%-8.8s ", grp->gr_name);
  } else {
    printf("%-8d ", buf.st_gid);
  }
  printf("%9jd ", (size_t)buf.st_size);
  tm = localtime(&buf.st_mtim.tv_sec);
  strftime(datestring, sizeof(datestring), nl_langinfo(D_T_FMT), tm);
  printf("%s ", datestring);
  printf("%s\n", from_slash);
}

canonical_original_code:
void print_info(char *name)
{
  char *from_slash = name;
  for (; from_slash[0] != '/'; from_slash++) {
  }
  from_slash++;
  if(*from_slash == '\0') {
    return;
  }
  struct stat buf;
  if( stat(name, &buf) == -1) {
    fatal("stat");
  }
  printf("%6d ", (int)buf.st_ino);
  printf("%4jd ", (unsigned long)buf.st_blocks / 2);
  printf("%10.10s", sperm(buf.st_mode));
  printf("%4d ", (int)buf.st_nlink);
  struct passwd *pwd;
  struct group *grp;
  struct tm *tm;
  char datestring[256];
  if((pwd = getpwuid(buf.st_uid)) != ((void *)0)) {
    printf("%-8.8s ", pwd->pw_name);
  } else {
    printf("%-8d ", buf.st_uid);
  }
  if((grp = getgrgid(buf.st_gid)) != ((void *)0)) {
    printf("%-8.8s ", grp->gr_name);
  } else {
    printf("%-8d ", buf.st_gid);
  }
  printf("%9jd ", (unsigned long)buf.st_size);
  tm = localtime(&buf.st_mtim.tv_sec);
  strftime(datestring, sizeof(datestring), nl_langinfo(D_T_FMT), tm);
  printf("%s ", datestring);
  printf("%s\n", from_slash);
}

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: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
datestring
char [256]

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


fatal

canonical_decompiled_code:
void __fastcall __noreturn func10(const char *a1)
{
perror(a1);
exit(1);
}


decompiled_code:
__int64 get_termsize()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-10h] BYREF

v1 = 0LL;
ioctl(0, 0x5413uLL, &v1);
result = WORD1(v1) * (unsigned int)(unsigned __int16)v1;
termsize = WORD1(v1) * (unsigned __int16)v1;
should_print_termsize = 1;
return result;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-10h] BYREF

v1 = 0LL;
ioctl(0, 0x5413uLL, &v1);
result = WORD1(v1) * (unsigned int)(unsigned __int16)v1;
termsize = WORD1(v1) * (unsigned __int16)v1;
should_print_termsize = 1;
return result;
}

original_code:
void get_termsize()
{
  struct winsize arg;
  memset(&arg, 0, sizeof(struct winsize));
  ioctl(0, 0x5413, &arg);
  termsize = arg.ws_row * arg.ws_col;
  should_print_termsize = 1 > 0;
}

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


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

if ( a1 == 28 )
result = get_termsize();
return result;
}

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

if ( a1 == 28 )
result = func11();
return result;
}

original_code:
void sigwinch_handler(int sig)
{
  switch(sig) {
    case 28:
      get_termsize();
      break;
    default:
      break;
  }
}

variable_types: sig int


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

if ( !should_print_termsize )
__assert_fail("should_print_termsize", "4.c", 0x12u, "print_termsize");
result = printf("Termsize: %d\n", (unsigned int)termsize);
should_print_termsize = 0;
return result;
}

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

if ( !should_print_termsize )
__assert_fail("should_print_termsize", "4.c", 0x12u, "print_termsize");
result = printf("Termsize: %d\n", (unsigned int)termsize);
should_print_termsize = 0;
return result;
}

original_code:
void print_termsize()
{
  ((void) sizeof ((should_print_termsize) ? 1 : 0), __extension__ ({ if (should_print_termsize) ; else __assert_fail ("should_print_termsize", "4.c", 18, __extension__ __PRETTY_FUNCTION__); }));
  int ts = termsize;
  printf("Termsize: %d\n", ts);
  should_print_termsize = 1 < 0;
}

variable_types: ts int


decompiled_code:
int set_handlers()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_handler = sigint_handler;
if ( sigaction(2, &v1, 0LL) == -1 )
fatal("SIGINT sigaction");
v1.sa_handler = (__sighandler_t)sigwinch_handler;
result = sigaction(28, &v1, 0LL);
if ( result == -1 )
fatal("SIGWINCH sigaction");
return result;
}

canonical_decompiled_code:
int func14()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

memset(&v1.sa_mask, 0, 0x90uLL);
v1.sa_handler = sigint_handler;
if ( sigaction(2, &v1, 0LL) == -1 )
func10("SIGINT sigaction");
v1.sa_handler = (__sighandler_t)sigwinch_handler;
result = sigaction(28, &v1, 0LL);
if ( result == -1 )
func10("SIGWINCH sigaction");
return result;
}

original_code:
void set_handlers()
{
  struct sigaction act;
  memset(&act, 0, sizeof(struct sigaction));
  act.__sigaction_handler.sa_handler = sigint_handler;
  if(sigaction(2, &act, ((void *)0)) == -1) {
    fatal("SIGINT sigaction");
  }
  act.__sigaction_handler.sa_handler = sigwinch_handler;
  if(sigaction(28, &act, ((void *)0)) == -1) {
    fatal("SIGWINCH sigaction");
  }
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }


decompiled_code:
int free_mem()
{
return munmap(mem, memsize);
}

canonical_decompiled_code:
int func7()
{
return munmap(mem, memsize);
}

original_code:
void free_mem()
{
  munmap(mem, memsize);
}


decompiled_code:
int unlink_f()
{
return unlink("8_random_name");
}

canonical_decompiled_code:
int func8()
{
return unlink("8_random_name");
}

original_code:
void unlink_f()
{
  unlink("8_random_name");
}


canonical_decompiled_code:
void __fastcall __noreturn func11(const char *a1)
{
perror(a1);
exit(1);
}


decompiled_code:
int print_mincore()
{
unsigned __int8 *v0; // r13
unsigned __int8 *v1; // rbx
unsigned __int8 *v2; // r13
unsigned int v3; // ebp
unsigned int v4; // er12

v0 = (unsigned __int8 *)malloc(0x81uLL);
if ( mincore(mem, memsize, v0) == -1 )
fatal("mincore");
v1 = v0;
v2 = v0 + 128;
v3 = 0;
v4 = 0;
do
{
if ( (*v1 & 1) != 0 )
{
if ( v4 )
print_mincore_helper(83, v4);
++v3;
v4 = 0;
}
else
{
if ( v3 )
print_mincore_helper(77, v3);
++v4;
v3 = 0;
}
++v1;
}
while ( v2 != v1 );
if ( v4 )
print_mincore_helper(83, v4);
if ( v3 )
print_mincore_helper(77, v3);
return putchar(10);
}

canonical_decompiled_code:
int func13()
{
unsigned __int8 *v0; // r13
unsigned __int8 *v1; // rbx
unsigned __int8 *v2; // r13
unsigned int v3; // ebp
unsigned int v4; // er12

v0 = (unsigned __int8 *)malloc(0x81uLL);
if ( mincore(mem, memsize, v0) == -1 )
func11("mincore");
v1 = v0;
v2 = v0 + 128;
v3 = 0;
v4 = 0;
do
{
if ( (*v1 & 1) != 0 )
{
if ( v4 )
func12(83, v4);
++v3;
v4 = 0;
}
else
{
if ( v3 )
func12(77, v3);
++v4;
v3 = 0;
}
++v1;
}
while ( v2 != v1 );
if ( v4 )
func12(83, v4);
if ( v3 )
func12(77, v3);
return putchar(10);
}

original_code:
void print_mincore()
{
  unsigned char* coredump = malloc(128 + 1);
  if(mincore(mem, memsize, coredump) == -1) {
    fatal("mincore");
  }
  int s = 0, m = 0;
  for (int i = 0; i < 128; i++) {
    switch(coredump[i] & 1) {
      case 0:
        if(m != 0) {
          _print_mincore_helper('M', m);
          m = 0;
        }
        s++;
        break;
      case 1:
        if(s != 0) {
          _print_mincore_helper('S', s);
          s = 0;
        }
        m++;
        break;
    }
  }
  if(s != 0) {
    _print_mincore_helper('S', s);
    s = 0;
  }
  if(m != 0) {
    _print_mincore_helper('M', m);
    m = 0;
  }
  putchar('\n');
}

canonical_original_code:
void print_mincore()
{
  unsigned char *coredump = malloc(128 + 1);
  if(mincore(mem, memsize, coredump) == -1) {
    fatal("mincore");
  }
  int s = 0; int m = 0;
  for (int i = 0; i < 128; i++) {
    switch(coredump[i] & 1) {
      case 0:
        if(m != 0) {
          _print_mincore_helper('M', m);
          m = 0;
        }
        s++;
        break;
      case 1:
        if(s != 0) {
          _print_mincore_helper('S', s);
          s = 0;
        }
        m++;
        break;
    }
  }
  if(s != 0) {
    _print_mincore_helper('S', s);
    s = 0;
  }
  if(m != 0) {
    _print_mincore_helper('M', m);
    m = 0;
  }
  putchar('\n');
}

variable_types:
coredump
unsigned char *

variable_types: s int

variable_types: m int

variable_types: i int


decompiled_code:
int __fastcall mem_advise(int advice)
{
int result; // eax

result = madvise(mem, memsize, advice);
if ( result == -1 )
fatal("madvise");
return result;
}

canonical_decompiled_code:
int __fastcall func14(int advice)
{
int result; // eax

result = madvise(mem, memsize, advice);
if ( result == -1 )
func11("madvise");
return result;
}

original_code:
void mem_advise(int advise)
{
  if(madvise(mem, memsize, advise) == -1) {
    fatal("madvise");
  }
}

variable_types: advise int


decompiled_code:
int free_fd()
{
return close_descriptor(&fd);
}

canonical_decompiled_code:
int func16()
{
return func15(&fd);
}

original_code:
void free_fd()
{
  close_descriptor(&fd);
}


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

result = (memsize >> 1) - 1;
*((_BYTE *)mem + result) = 98;
return result;
}

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

result = (memsize >> 1) - 1;
*((_BYTE *)mem + result) = 98;
return result;
}

original_code:
void mem_touch()
{
  int index = (memsize >> 1) -1;
  mem[index] = 'b';
}

variable_types: index int


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

result = mlock(mem, memsize >> 1);
if ( result )
fatal("mlock");
return result;
}

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

result = mlock(mem, memsize >> 1);
if ( result )
func11("mlock");
return result;
}

original_code:
void mem_lock()
{
  if(mlock(mem, memsize >> 1) != 0) {
    fatal("mlock");
  }
}


decompiled_code:
void *mem_init()
{
int v0; // eax
void *result; // rax

memsize = (unsigned int)sysconf(30) << 7;
v0 = open("8_random_name", 578, 438LL);
fd = v0;
if ( v0 < 0 )
fatal("creat");
if ( ftruncate(v0, memsize) )
fatal("ftruncate");
result = mmap(0LL, memsize, 3, 2, fd, 0LL);
mem = result;
if ( result == (void *)-1LL )
fatal("mmap");
if ( !init )
{
atexit(free_fd);
atexit(free_mem);
result = (void *)atexit(unlink_f);
init = 1;
}
return result;
}

canonical_decompiled_code:
void *func19()
{
int v0; // eax
void *result; // rax

memsize = (unsigned int)sysconf(30) << 7;
v0 = open("8_random_name", 578, 438LL);
fd = v0;
if ( v0 < 0 )
func11("creat");
if ( ftruncate(v0, memsize) )
func11("ftruncate");
result = mmap(0LL, memsize, 3, 2, fd, 0LL);
mem = result;
if ( result == (void *)-1LL )
func11("mmap");
if ( !init )
{
func24(free_fd);
func24(free_mem);
result = (void *)func24(unlink_f);
init = 1;
}
return result;
}


decompiled_code:
void *mem_reset()
{
void *result; // rax

if ( init )
{
free_fd();
free_mem();
result = mem_init();
}
return result;
}

canonical_decompiled_code:
void *func20()
{
void *result; // rax

if ( init )
{
func16();
func7();
result = func19();
}
return result;
}

original_code:
void mem_reset()
{
  if(init == 0){
    return;
  }
  free_fd();
  free_mem();
  mem_init();
}


decompiled_code:
int DO_STH_PRODUCTIVE()
{
puts(" ( pages: [M]emory, [S]wapped out )");
puts("start..");
print_mincore();
puts(" ..after dontneed:");
mem_advise(4);
print_mincore();
mem_reset();
puts(" ..after willneed:");
mem_advise(3);
print_mincore();
mem_reset();
puts(" ..after random:");
mem_advise(1);
mem_touch();
print_mincore();
mem_reset();
puts(" ..after sequential");
mem_advise(2);
mem_touch();
print_mincore();
mem_reset();
puts(" ..locking");
mem_lock();
mem_advise(4);
puts("after lock & swapout");
return print_mincore();
}

canonical_decompiled_code:
int func21()
{
puts(" ( pages: [M]emory, [S]wapped out )");
puts("start..");
func13();
puts(" ..after dontneed:");
func14(4);
func13();
func20();
puts(" ..after willneed:");
func14(3);
func13();
func20();
puts(" ..after random:");
func14(1);
func17();
func13();
func20();
puts(" ..after sequential");
func14(2);
func17();
func13();
func20();
puts(" ..locking");
func18();
func14(4);
puts("after lock & swapout");
return func13();
}

original_code:
void DO_STH_PRODUCTIVE()
{
    puts("  ( pages: [M]emory, [S]wapped out )");
    puts("start..");
    print_mincore();
    puts(" ..after dontneed:");
  mem_advise(4);
    print_mincore();
  mem_reset();
    puts(" ..after willneed:");
  mem_advise(3);
    print_mincore();
  mem_reset();
    puts(" ..after random:");
  mem_advise(1);
  mem_touch();
    print_mincore();
  mem_reset();
    puts(" ..after sequential");
  mem_advise(2);
  mem_touch();
    print_mincore();
  mem_reset();
    puts(" ..locking");
    mem_lock();
  mem_advise(4);
  puts("after lock & swapout");
  print_mincore();
}


error

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

if ( !a2 )
{
fprintf(stderr, "%s\n", a1);
exit(1);
}
if ( a2 == 1 )
result = fprintf(stdout, "%s\n", a1);
return result;
}

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

if ( !a2 )
{
fprintf(stderr, "%s\n", a1);
exit(1);
}
if ( a2 == 1 )
result = fprintf(stdout, "%s\n", a1);
return result;
}

original_code:
void error(const char* message, int infoLevel)
{
  switch(infoLevel) {
    case 0:
      fprintf(stderr, "%s\n", message);
      exit(1);
    case 1:
      fprintf(stdout, "%s\n", message);
      break;
    default:
      break;
  }
}

canonical_original_code:
void error(char *message, int infoLevel)
{
  switch(infoLevel) {
    case 0:
      fprintf(stderr, "%s\n", message);
      exit(1);
    case 1:
      fprintf(stdout, "%s\n", message);
      break;
    default:
      break;
  }
}

variable_types:
message
char *

variable_types: infoLevel int


delay

decompiled_code:
int __fastcall delay(int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_nsec = a1 % 1000000000;
v2.tv_sec = a1 / 1000000000;
return nanosleep(&v2, &v2);
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_nsec = a1 % 1000000000;
v2.tv_sec = a1 / 1000000000;
return nanosleep(&v2, &v2);
}

original_code:
void delay(int r)
{
  struct timespec nSleepTime;
  memset(&nSleepTime, 0, sizeof(struct timespec));
  nSleepTime.tv_nsec = r % (1000000000);
  nSleepTime.tv_sec = r / (1000000000);
  nanosleep(&nSleepTime, &nSleepTime);
}

variable_types: r int

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


NOP

decompiled_code:
void NOP()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void NOP()
{
  asm volatile("nop");
}

canonical_original_code:
void NOP()
{
  asm volatile("nop");
}


ThreadMain

repo: scola/twittrouter

decompiled_code:
__int64 __fastcall ThreadMain(void *ptr)
{
pthread_t v1; // rax
unsigned int v2; // ebp

v1 = pthread_self();
pthread_detach(v1);
v2 = *(_DWORD *)ptr;
free(ptr);
HandleTCPClient(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
pthread_t v1; // rax
unsigned int v2; // ebp

v1 = pthread_self();
pthread_detach(v1);
v2 = *(_DWORD *)ptr;
free(ptr);
HandleTCPClient(v2);
return 0LL;
}

original_code:
void *ThreadMain(void *threadArgs) {
    pthread_detach(pthread_self());
    int clntSock = ((struct ThreadArgs *) threadArgs)->clntSock;
    free(threadArgs);
    HandleTCPClient(clntSock);
    return (((void *)0));
}

variable_types:
threadArgs
void *

variable_types: clntSock int

return_type: void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
char *v4; // r15
char *v5; // r13
int v6; // ebx
char v7; // al
_QWORD *v8; // rax
struct tm *v9; // rax
__int64 v10; // r12
__int64 v11; // rbp
int v12; // er14
_DWORD *v13; // r13
int v14; // er13
int v15; // eax
int v16; // ebx
int v18; // [rsp+Ch] [rbp-114Ch]
struct timeval timer; // [rsp+10h] [rbp-1148h] BYREF
char s[8]; // [rsp+20h] [rbp-1138h] BYREF
__int64 v21; // [rsp+28h] [rbp-1130h]
char v22[4080]; // [rsp+30h] [rbp-1128h] BYREF
fd_set exceptfds; // [rsp+1020h] [rbp-138h] BYREF
fd_set readfds; // [rsp+10A0h] [rbp-B8h] BYREF

root = (__int64)"/www/twittrouter";
servPort = (__int64)"9999";
opterr = 0;
v3 = 0LL;
v4 = 0LL;
v5 = "/etc/config/twittrouter.json";
v6 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "p:r:c:t:u:f:ha");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'a':
v6 = 1;
break;
case 'c':
v5 = optarg;
break;
case 'h':
usage();
exit(0);
case 'p':
servPort = (__int64)optarg;
break;
case 'r':
root = (__int64)optarg;
break;
case 't':
v4 = optarg;
break;
case 'u':
v3 = optarg;
break;
default:
continue;
}
}
if ( opterr )
{
usage();
exit(1);
}
if ( !v5 )
{
LABEL_19:
if ( v3 )
{
if ( (unsigned __int8)get_friendship(v3) )
printf("Congratulations! Verify success,%s is your twitter friend\n", v3);
else
puts("Sorry! Maybe you have not config your network to go through to evil GFW,or try another friend again");
exit(0);
}
if ( v6 )
{
*(_QWORD *)s = 0LL;
LOWORD(v21) = 0;
request_token_example_get();
printf("PIN: ");
_isoc99_scanf("%s", s);
printf("pin=%s\n", s);
if ( (unsigned __int8)access_token_example_get(s) )
{
puts("Congratulations! auth success");
dump_jconf(v5);
}
else
{
puts("Sorry! auth failed");
}
exit(0);
}
arpList = CreatEmptyLink();
timer.tv_sec = time(0LL);
v9 = localtime(&timer.tv_sec);
strftime(s, 0x14uLL, "%F %T", v9);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mserver listening at port %s...\n\n", s, (const char *)servPort);
v18 = SetupTCPServerSocket(servPort);
if ( v18 < 0 )
FATAL("unable to establish");
v10 = 1LL << (v18 % 64);
v11 = v18 / 64;
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
memset(&exceptfds, 0, sizeof(exceptfds));
readfds.fds_bits[v11] |= v10;
exceptfds.fds_bits[v11] |= v10;
timer.tv_sec = 1LL;
timer.tv_usec = 0LL;
if ( select(v18 + 1, &readfds, 0LL, &exceptfds, &timer) == -1 )
ERROR("select");
if ( (exceptfds.fds_bits[v11] & v10) != 0 )
ERROR("servSock error\n");
if ( (readfds.fds_bits[v11] & v10) != 0 )
{
v12 = AcceptTCPConnection((unsigned int)v18);
v13 = malloc(4uLL);
if ( !v13 )
FATAL("malloc() failed");
*v13 = v12;
create_thread((void *(*)(void *))ThreadMain, v13);
}
v14 = v6 % 10;
if ( !(v6 % 10) )
{
*(_QWORD *)s = 0LL;
v21 = 0LL;
memset(v22, 0, sizeof(v22));
v15 = open("/proc/net/arp", 0);
v16 = v15;
if ( v15 != -1 )
{
read(v15, s, 0x1000uLL);
scan_arp_and_block(s);
close(v16);
}
v6 = v14;
}
++v6;
}
}
v8 = (_QWORD *)read_jconf(v5);
conf = (__int64)v8;
if ( v4 )
{
v8[1] = v4;
}
else if ( !v8[1] )
{
goto LABEL_25;
}
if ( v8[2] && v8[3] && v8[4] && v8[5] )
goto LABEL_19;
LABEL_25:
usage();
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
char *v4; // r15
char *v5; // r13
int v6; // ebx
char v7; // al
_QWORD *v8; // rax
struct tm *v9; // rax
__int64 v10; // r12
__int64 v11; // rbp
int v12; // er14
_DWORD *v13; // r13
int v14; // er13
int v15; // eax
int v16; // ebx
int v18; // [rsp+Ch] [rbp-114Ch]
struct timeval timer; // [rsp+10h] [rbp-1148h] BYREF
char s[8]; // [rsp+20h] [rbp-1138h] BYREF
__int64 v21; // [rsp+28h] [rbp-1130h]
char v22[4080]; // [rsp+30h] [rbp-1128h] BYREF
fd_set exceptfds; // [rsp+1020h] [rbp-138h] BYREF
fd_set readfds; // [rsp+10A0h] [rbp-B8h] BYREF

root = (__int64)"/www/twittrouter";
servPort = (__int64)"9999";
opterr = 0;
v3 = 0LL;
v4 = 0LL;
v5 = "/etc/config/twittrouter.json";
v6 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "p:r:c:t:u:f:ha");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'a':
v6 = 1;
break;
case 'c':
v5 = optarg;
break;
case 'h':
usage();
exit(0);
case 'p':
servPort = (__int64)optarg;
break;
case 'r':
root = (__int64)optarg;
break;
case 't':
v4 = optarg;
break;
case 'u':
v3 = optarg;
break;
default:
continue;
}
}
if ( opterr )
{
usage();
exit(1);
}
if ( !v5 )
{
LABEL_19:
if ( v3 )
{
if ( (unsigned __int8)get_friendship(v3) )
printf("Congratulations! Verify success,%s is your twitter friend\n", v3);
else
puts("Sorry! Maybe you have not config your network to go through to evil GFW,or try another friend again");
exit(0);
}
if ( v6 )
{
*(_QWORD *)s = 0LL;
LOWORD(v21) = 0;
request_token_example_get();
printf("PIN: ");
_isoc99_scanf("%s", s);
printf("pin=%s\n", s);
if ( (unsigned __int8)access_token_example_get(s) )
{
puts("Congratulations! auth success");
dump_jconf(v5);
}
else
{
puts("Sorry! auth failed");
}
exit(0);
}
arpList = CreatEmptyLink();
timer.tv_sec = time(0LL);
v9 = localtime(&timer.tv_sec);
strftime(s, 0x14uLL, "%F %T", v9);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mserver listening at port %s...\n\n", s, (const char *)servPort);
v18 = SetupTCPServerSocket(servPort);
if ( v18 < 0 )
FATAL("unable to establish");
v10 = 1LL << (v18 % 64);
v11 = v18 / 64;
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
memset(&exceptfds, 0, sizeof(exceptfds));
readfds.fds_bits[v11] |= v10;
exceptfds.fds_bits[v11] |= v10;
timer.tv_sec = 1LL;
timer.tv_usec = 0LL;
if ( select(v18 + 1, &readfds, 0LL, &exceptfds, &timer) == -1 )
ERROR("select");
if ( (exceptfds.fds_bits[v11] & v10) != 0 )
ERROR("servSock error\n");
if ( (readfds.fds_bits[v11] & v10) != 0 )
{
v12 = AcceptTCPConnection((unsigned int)v18);
v13 = malloc(4uLL);
if ( !v13 )
FATAL("malloc() failed");
*v13 = v12;
func0((void *(*)(void *))ThreadMain, v13);
}
v14 = v6 % 10;
if ( !(v6 % 10) )
{
*(_QWORD *)s = 0LL;
v21 = 0LL;
memset(v22, 0, sizeof(v22));
v15 = open("/proc/net/arp", 0);
v16 = v15;
if ( v15 != -1 )
{
read(v15, s, 0x1000uLL);
scan_arp_and_block(s);
close(v16);
}
v6 = v14;
}
++v6;
}
}
v8 = (_QWORD *)read_jconf(v5);
conf = (__int64)v8;
if ( v4 )
{
v8[1] = v4;
}
else if ( !v8[1] )
{
goto LABEL_25;
}
if ( v8[2] && v8[3] && v8[4] && v8[5] )
goto LABEL_19;
LABEL_25:
usage();
exit(1);
}

original_code:
int main(int argc, char *argv[]) {
    int auth_flags = 0;
    char c;
    char *conf_path = "/etc/config/twittrouter.json";
    char *TwitterID = ((void *)0);
    char *userfortest = ((void *)0);
    root = "/www/twittrouter";
    servPort = "9999";
    opterr = 0;
    while ((c = getopt (argc, argv, "p:r:c:t:u:f:ha")) != -1) {
        switch (c)
        {
            case 'r':
                root = optarg;
                break;
            case 'p':
                servPort = optarg;
                break;
            case 'c':
                conf_path = optarg;
                break;
            case 'u':
                userfortest = optarg;
                break;
            case 't':
                TwitterID = optarg;
                break;
            case 'h':
                usage();
                exit(0);
                break;
            case 'a':
                auth_flags = 1;
                break;
            default:
                break;
        }
    }
    if (opterr) {
        usage();
        exit(1);
    }
    if (conf_path != ((void *)0))
    {
        conf = read_jconf(conf_path);
        if (TwitterID) conf->TwitterID = TwitterID;
        if (conf->TwitterID == ((void *)0) ||
            conf->CONSUMER_KEY == ((void *)0) || conf->CONSUMER_SECRET == ((void *)0) ||
            conf->OAUTH_TOKEN == ((void *)0) || conf->OAUTH_TOKEN_SECRET == ((void *)0)) {
            usage();
            exit(1);
        }
    }
    if(userfortest != ((void *)0)) {
        if(get_friendship(userfortest)) {
            printf("Congratulations! Verify success,%s is your twitter friend\n", userfortest);
        }
        else {
            printf("Sorry! Maybe you have not config your network to go through to evil GFW,or try another friend again\n");
        }
        exit(0);
    }
    if (auth_flags)
    {
        char pin[10] = {0};
        request_token_example_get();
        printf("PIN: ");
        scanf("%s", pin);
        printf("pin=%s\n", pin);
        if(access_token_example_get(pin)) {
            printf("Congratulations! auth success\n");
            dump_jconf(conf_path);
        }
        else {
            printf("Sorry! auth failed\n");
        }
        exit(0);
    }
    arpList = CreatEmptyLink();
    do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "server listening at port %s...\n" "\n", timestr,servPort);}while(0);
    int servSock = SetupTCPServerSocket(servPort);
    if (servSock < 0)
        FATAL("unable to establish");
    fd_set readset, errorset;
    int max_fd = servSock + 1;
    int loop_count = 0;
    for (;;) {
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readset)->__fds_bits)[0]) : "memory"); } while (0);
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&errorset)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&readset)->__fds_bits)[((servSock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((servSock) % (8 * (int) sizeof (__fd_mask)))))));
        ((void) (((&errorset)->__fds_bits)[((servSock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((servSock) % (8 * (int) sizeof (__fd_mask)))))));
        struct timeval timeout = {
          .tv_sec = 1,
          .tv_usec = 0,
        };
        if (-1 == select(max_fd, &readset, ((void *)0), &errorset, &timeout)) {
            ERROR("select");
        }
        if (((((&errorset)->__fds_bits)[((servSock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((servSock) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            ERROR("servSock error\n");
        }
        if(((((&readset)->__fds_bits)[((servSock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((servSock) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            int clntSock = AcceptTCPConnection(servSock);
            struct ThreadArgs *threadArgs = (struct ThreadArgs *) malloc(
                 sizeof(struct ThreadArgs)
                );
            if (threadArgs == ((void *)0))
                FATAL("malloc() failed");
            threadArgs->clntSock = clntSock;
            create_thread(ThreadMain,(void *)threadArgs);
        }
        if(loop_count % 10 == 0){
            int fd;
            char buf[BUFSIZE] = {0};
            if ((fd=open("/proc/net/arp", 00)) != -1)
            {
                read(fd, buf, BUFSIZE);
                scan_arp_and_block(buf);
                close(fd);
            }
            loop_count = 0;
        }
        loop_count++;
    }
}

canonical_original_code:
int main(int argc, char *argv[]) {
    int auth_flags = 0;
    char c;
    char *conf_path = "/etc/config/twittrouter.json";
    char *TwitterID = ((void *)0);
    char *userfortest = ((void *)0);
    root = "/www/twittrouter";
    servPort = "9999";
    opterr = 0;
    while ((c = getopt (argc, argv, "p:r:c:t:u:f:ha")) != -1) {
        switch (c)
        {
            case 'r':
                root = optarg;
                break;
            case 'p':
                servPort = optarg;
                break;
            case 'c':
                conf_path = optarg;
                break;
            case 'u':
                userfortest = optarg;
                break;
            case 't':
                TwitterID = optarg;
                break;
            case 'h':
                usage();
                exit(0);
                break;
            case 'a':
                auth_flags = 1;
                break;
            default:
                break;
        }
    }
    if (opterr) {
        usage();
        exit(1);
    }
    if (conf_path != ((void *)0))
    {
        conf = read_jconf(conf_path);
        if (TwitterID) conf->TwitterID = TwitterID;
        if (conf->TwitterID == ((void *)0) ||
            conf->CONSUMER_KEY == ((void *)0) || conf->CONSUMER_SECRET == ((void *)0) ||
            conf->OAUTH_TOKEN == ((void *)0) || conf->OAUTH_TOKEN_SECRET == ((void *)0)) {
            usage();
            exit(1);
        }
    }
    if(userfortest != ((void *)0)) {
        if(get_friendship(userfortest)) {
            printf("Congratulations! Verify success,%s is your twitter friend\n", userfortest);
        }
        else {
            printf("Sorry! Maybe you have not config your network to go through to evil GFW,or try another friend again\n");
        }
        exit(0);
    }
    if (auth_flags)
    {
        char pin[10] = {0};
        request_token_example_get();
        printf("PIN: ");
        scanf("%s", pin);
        printf("pin=%s\n", pin);
        if(access_token_example_get(pin)) {
            printf("Congratulations! auth success\n");
            dump_jconf(conf_path);
        }
        else {
            printf("Sorry! auth failed\n");
        }
        exit(0);
    }
    arpList = CreatEmptyLink();
    do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;32m %s INFO: \e[0m" "server listening at port %s...\n" "\n", timestr,servPort);}while(0);
    int servSock = SetupTCPServerSocket(servPort);
    if (servSock < 0)
        FATAL("unable to establish");
    struct fd_set readset; struct fd_set errorset;
    int max_fd = servSock + 1;
    int loop_count = 0;
    for (;;) {
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readset)->__fds_bits)[0]) : "memory"); } while (0);
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&errorset)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&readset)->__fds_bits)[((servSock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((servSock) % (8 * (int) sizeof (__fd_mask)))))));
        ((void) (((&errorset)->__fds_bits)[((servSock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((servSock) % (8 * (int) sizeof (__fd_mask)))))));
        struct timeval timeout = {
          .tv_sec = 1,
          .tv_usec = 0,
        };
        if (-1 == select(max_fd, &readset, ((void *)0), &errorset, &timeout)) {
            ERROR("select");
        }
        if (((((&errorset)->__fds_bits)[((servSock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((servSock) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            ERROR("servSock error\n");
        }
        if(((((&readset)->__fds_bits)[((servSock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((servSock) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            int clntSock = AcceptTCPConnection(servSock);
            struct ThreadArgs *threadArgs = (struct ThreadArgs *) malloc(
                 sizeof(struct ThreadArgs)
                );
            if (threadArgs == ((void *)0))
                FATAL("malloc() failed");
            threadArgs->clntSock = clntSock;
            create_thread(ThreadMain,(void *)threadArgs);
        }
        if(loop_count % 10 == 0){
            int fd;
            char buf[-1] = {0};
            if ((fd=open("/proc/net/arp", 00)) != -1)
            {
                read(fd, buf, BUFSIZE);
                scan_arp_and_block(buf);
                close(fd);
            }
            loop_count = 0;
        }
        loop_count++;
    }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c char

variable_types:
TwitterID
char *

variable_types:
userfortest
char *

variable_types:
pin
char [10]

variable_types: now long

variable_types:
timestr
char [20]

variable_types: servSock int

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

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

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

variable_types:
threadArgs
struct ThreadArgs { int clntSock; } *

variable_types: fd int

variable_types:
buf
char [-1]


ERROR

decompiled_code:
int __fastcall ERROR(const char *a1)
{
int *v1; // rax
char *v2; // rbp
struct tm *v3; // rax
time_t timer; // [rsp+8h] [rbp-40h] BYREF
char s[56]; // [rsp+10h] [rbp-38h] BYREF

v1 = _errno_location();
v2 = strerror(*v1);
timer = time(0LL);
v3 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v3);
return fprintf(stderr, "\x1B[01;35m %s ERROR: \x1B[0m%s: %s\n", s, a1, v2);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int *v1; // rax
char *v2; // rbp
struct tm *v3; // rax
time_t timer; // [rsp+8h] [rbp-40h] BYREF
char s[56]; // [rsp+10h] [rbp-38h] BYREF

v1 = _errno_location();
v2 = strerror(*v1);
timer = time(0LL);
v3 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v3);
return fprintf(stderr, "\x1B[01;35m %s ERROR: \x1B[0m%s: %s\n", s, a1, v2);
}

original_code:
void ERROR(const char *s)
{
    char *msg = strerror((*__errno_location ()));
    do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;35m %s ERROR: \e[0m" "%s: %s" "\n", timestr, s, msg);}while(0);
}

canonical_original_code:
void ERROR(char *s)
{
    char *msg = strerror((*__errno_location ()));
    do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;35m %s ERROR: \e[0m" "%s: %s" "\n", timestr, s, msg);}while(0);
}

variable_types:
s
char *

variable_types:
msg
char *


itoa

variable_types: i int

variable_types:
p
char *


decompiled_code:
char *__fastcall ss_strndup(char *s, size_t n)
{
char *v2; // rbp

if ( strlen(s) <= n )
return strdup(s);
v2 = (char *)malloc(n + 1);
strncpy(v2, s, n);
v2[n] = 0;
return v2;
}

canonical_decompiled_code:
char *__fastcall func2(char *s, size_t n)
{
char *v2; // rbp

if ( strlen(s) <= n )
return strdup(s);
v2 = (char *)malloc(n + 1);
strncpy(v2, s, n);
v2[n] = 0;
return v2;
}

original_code:
char *ss_strndup(const char *s, size_t n)
{
    size_t len = strlen(s);
    char *ret;
    if (len <= n) return strdup(s);
    ret = malloc(n + 1);
    strncpy(ret, s, n);
    ret[n] = '\0';
    return ret;
}

canonical_original_code:
char *ss_strndup(char *s, unsigned long n)
{
    unsigned long len = strlen(s);
    char *ret;
    if (len <= n) return strdup(s);
    ret = malloc(n + 1);
    strncpy(ret, s, n);
    ret[n] = '\0';
    return ret;
}

variable_types:
n
unsigned long

variable_types:
len
unsigned long

variable_types:
ret
char *


FATAL

decompiled_code:
void __fastcall __noreturn FATAL(const char *a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v1);
fprintf(stderr, "\x1B[01;35m %s ERROR: \x1B[0m%s\n", s, a1);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v1);
fprintf(stderr, "\x1B[01;35m %s ERROR: \x1B[0m%s\n", s, a1);
exit(-1);
}

original_code:
void FATAL(const char *msg)
{
    do { time_t now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;35m %s ERROR: \e[0m" "%s" "\n", timestr, msg);}while(0);
    exit(-1);
}

canonical_original_code:
void FATAL(char *msg)
{
    do { long now = time(((void *)0)); char timestr[20]; strftime(timestr, 20, "%F %T", localtime(&now)); fprintf(stderr, "\e[01;35m %s ERROR: \e[0m" "%s" "\n", timestr, msg);}while(0);
    exit(-1);
}


decompiled_code:
char *__fastcall str_replace(char *haystack, const char *a2, const char *a3)
{
char *v3; // rbp
const char *v4; // r14
int v6; // er15
const char *v7; // rax
int v8; // er13
int i; // ebx
char *v10; // rax
size_t v11; // rax
char *v12; // r12
int v13; // er13
signed int v14; // ebx
size_t v15; // r15
int v17; // [rsp+4h] [rbp-54h]
char *src; // [rsp+8h] [rbp-50h]
int v19; // [rsp+10h] [rbp-48h]
char *v20; // [rsp+18h] [rbp-40h]

v3 = haystack;
if ( !haystack )
return 0LL;
v4 = a2;
if ( !a2 )
v4 = &needle;
v6 = strlen(v4);
v17 = v6;
v7 = &needle;
if ( a3 )
v7 = a3;
src = (char *)v7;
v8 = strlen(v7);
v19 = v8;
for ( i = 0; ; ++i )
{
v10 = strstr(haystack, v4);
if ( !v10 )
break;
haystack = &v10[v6];
}
v11 = strlen(v3);
v20 = (char *)malloc(i * (v8 - v6) + v11 + 1);
v12 = v20;
if ( v20 )
{
v13 = i - 1;
if ( i )
{
do
{
v14 = (unsigned int)strstr(v3, v4) - (_DWORD)v3;
v15 = v14;
strncpy(v12, v3, v15);
v12 = &strcpy(&v12[v15], src)[v19];
v3 += v17 + v14;
--v13;
}
while ( v13 != -1 );
}
else
{
v12 = v20;
}
strcpy(v12, v3);
}
return v20;
}

canonical_decompiled_code:
char *__fastcall func4(char *haystack, const char *a2, const char *a3)
{
char *v3; // rbp
const char *v4; // r14
int v6; // er15
const char *v7; // rax
int v8; // er13
int i; // ebx
char *v10; // rax
size_t v11; // rax
char *v12; // r12
int v13; // er13
signed int v14; // ebx
size_t v15; // r15
int v17; // [rsp+4h] [rbp-54h]
char *src; // [rsp+8h] [rbp-50h]
int v19; // [rsp+10h] [rbp-48h]
char *v20; // [rsp+18h] [rbp-40h]

v3 = haystack;
if ( !haystack )
return 0LL;
v4 = a2;
if ( !a2 )
v4 = &needle;
v6 = strlen(v4);
v17 = v6;
v7 = &needle;
if ( a3 )
v7 = a3;
src = (char *)v7;
v8 = strlen(v7);
v19 = v8;
for ( i = 0; ; ++i )
{
v10 = strstr(haystack, v4);
if ( !v10 )
break;
haystack = &v10[v6];
}
v11 = strlen(v3);
v20 = (char *)malloc(i * (v8 - v6) + v11 + 1);
v12 = v20;
if ( v20 )
{
v13 = i - 1;
if ( i )
{
do
{
v14 = (unsigned int)strstr(v3, v4) - (_DWORD)v3;
v15 = v14;
strncpy(v12, v3, v15);
v12 = &strcpy(&v12[v15], src)[v19];
v3 += v17 + v14;
--v13;
}
while ( v13 != -1 );
}
else
{
v12 = v20;
}
strcpy(v12, v3);
}
return v20;
}

original_code:
char *str_replace(char *orig, char *rep, char *with) {
    char *result;
    char *ins;
    char *tmp;
    int len_rep;
    int len_with;
    int len_front;
    int count;
    if (!orig)
        return ((void *)0);
    if (!rep)
        rep = "";
    len_rep = strlen(rep);
    if (!with)
        with = "";
    len_with = strlen(with);
    ins = orig;
    for (count = 0; (tmp = strstr(ins, rep)) != ((void *)0); ++count) {
        ins = tmp + len_rep;
    }
    tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1);
    if (!result)
        return ((void *)0);
    while (count--) {
        ins = strstr(orig, rep);
        len_front = ins - orig;
        tmp = strncpy(tmp, orig, len_front) + len_front;
        tmp = strcpy(tmp, with) + len_with;
        orig += len_front + len_rep;
    }
    strcpy(tmp, orig);
    return result;
}

variable_types:
orig
char *

variable_types:
rep
char *

variable_types:
with
char *

variable_types:
result
char *

variable_types:
ins
char *

variable_types:
tmp
char *

variable_types: count int


usage

decompiled_code:
int usage()
{
putchar(10);
printf("twittrouter --version %s\n\n", "0.1.5");
puts(" maintained by Scola <shaozheng.wu@gmail.com>\n");
puts(" usage:\n");
puts(" Firstly,test whether the default oauth works normally");
puts(" Try to run [twittrouter -u kfc]");
puts(" Second,authorize your own twitter account");
puts(" Try to run [twittrouter -a]");
puts(" If the two step above works normally,then run [/etc/init.d/twittrouter start]");
puts(" Optional,you can add your own device mac address into whitelist of /etc/config/twittrouter.json");
putchar(10);
puts(" [-p <servPort>] server port,the default value is 9999");
puts(" [-c <config path>] twittrouter.json path,default /etc/config/twittrouter.json");
puts(" [-r <root>] html file path for the server,default /www/twittrouter");
puts(" [-h <help>] get the usage of the twittrouter");
puts(" [-u <username>] just use to test the oauth and network config");
puts(" [-a <authorize>] authorize and get twitter acess token");
return putchar(10);
}

canonical_decompiled_code:
int func5()
{
putchar(10);
printf("twittrouter --version %s\n\n", "0.1.5");
puts(" maintained by Scola <shaozheng.wu@gmail.com>\n");
puts(" usage:\n");
puts(" Firstly,test whether the default oauth works normally");
puts(" Try to run [twittrouter -u kfc]");
puts(" Second,authorize your own twitter account");
puts(" Try to run [twittrouter -a]");
puts(" If the two step above works normally,then run [/etc/init.d/twittrouter start]");
puts(" Optional,you can add your own device mac address into whitelist of /etc/config/twittrouter.json");
putchar(10);
puts(" [-p <servPort>] server port,the default value is 9999");
puts(" [-c <config path>] twittrouter.json path,default /etc/config/twittrouter.json");
puts(" [-r <root>] html file path for the server,default /www/twittrouter");
puts(" [-h <help>] get the usage of the twittrouter");
puts(" [-u <username>] just use to test the oauth and network config");
puts(" [-a <authorize>] authorize and get twitter acess token");
return putchar(10);
}

original_code:
void usage()
{
    printf("\n");
    printf("twittrouter --version %s\n\n", "0.1.5");
    printf("  maintained by Scola <shaozheng.wu@gmail.com>\n\n");
    printf("  usage:\n\n");
    printf("    Firstly,test whether the default oauth works normally\n");
    printf("    Try to run [twittrouter -u kfc]\n");
    printf("    Second,authorize your own twitter account\n");
    printf("    Try to run [twittrouter -a]\n");
    printf("    If the two step above works normally,then run [/etc/init.d/twittrouter start]\n");
    printf("    Optional,you can add your own device mac address into whitelist of /etc/config/twittrouter.json\n");
    printf("\n");
    printf("    [-p <servPort>]       server port,the default value is 9999\n");
    printf("    [-c <config path>]    twittrouter.json path,default /etc/config/twittrouter.json\n");
    printf("    [-r <root>]           html file path for the server,default /www/twittrouter\n");
    printf("    [-h <help>]           get the usage of the twittrouter\n");
    printf("    [-u <username>]       just use to test the oauth and network config\n");
    printf("    [-a <authorize>]      authorize and get twitter acess token\n");
    printf("\n");
}


original_code:
void sha1_init(sha1nfo *s) {
 s->state[0] = 0x67452301;
 s->state[1] = 0xefcdab89;
 s->state[2] = 0x98badcfe;
 s->state[3] = 0x10325476;
 s->state[4] = 0xc3d2e1f0;
 s->byteCount = 0;
 s->bufferOffset = 0;
}

canonical_original_code:
void sha1_init(struct sha1nfo *s) {
 s->state[0] = 0x67452301;
 s->state[1] = 0xefcdab89;
 s->state[2] = 0x98badcfe;
 s->state[3] = 0x10325476;
 s->state[4] = 0xc3d2e1f0;
 s->byteCount = 0;
 s->bufferOffset = 0;
}

variable_types: struct sha1nfo { unsigned int buffer[-1]; unsigned int state[-1]; unsigned int byteCount; unsigned char bufferOffset; unsigned char keyBuffer[64]; unsigned char innerHash[20]; } *


decompiled_code:
__int64 __fastcall sha1_rol32(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

original_code:
uint32_t sha1_rol32(uint32_t number, uint8_t bits) {
 return ((number << bits) | (number >> (32-bits)));
}

canonical_original_code:
unsigned int sha1_rol32(unsigned int number, unsigned char bits) {
 return ((number << bits) | (number >> (32-bits)));
}

variable_types:
number
unsigned int

variable_types:
bits
unsigned char

return_type: unsigned int


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

*(_BYTE *)(a1 + (*(_BYTE *)(a1 + 88) ^ 3u)) = a2;
result = (unsigned int)(unsigned __int8)(*(_BYTE *)(a1 + 88))++ + 1;
if ( (_BYTE)result == 64 )
{
result = sha1_hashBlock(a1);
*(_BYTE *)(a1 + 88) = 0;
}
return result;
}

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

*(_BYTE *)(a1 + (*(_BYTE *)(a1 + 88) ^ 3u)) = a2;
result = (unsigned int)(unsigned __int8)(*(_BYTE *)(a1 + 88))++ + 1;
if ( (_BYTE)result == 64 )
{
result = func2(a1);
*(_BYTE *)(a1 + 88) = 0;
}
return result;
}

original_code:
void sha1_addUncounted(sha1nfo *s, uint8_t data) {
 uint8_t * const b = (uint8_t*) s->buffer;
 b[s->bufferOffset ^ 3] = data;
 s->bufferOffset++;
 if (s->bufferOffset == 64) {
  sha1_hashBlock(s);
  s->bufferOffset = 0;
 }
}

canonical_original_code:
void sha1_addUncounted(struct sha1nfo *s, unsigned char data) {
 unsigned char *b = (uint8_t*) s->buffer;
 b[s->bufferOffset ^ 3] = data;
 s->bufferOffset++;
 if (s->bufferOffset == 64) {
  sha1_hashBlock(s);
  s->bufferOffset = 0;
 }
}

variable_types:
data
unsigned char

variable_types:
b
unsigned char *

user_defined_types: struct sha1nfo { unsigned int buffer[-1]; unsigned int state[-1]; unsigned int byteCount; unsigned char bufferOffset; unsigned char keyBuffer[64]; unsigned char innerHash[20]; }


decompiled_code:
__int64 __fastcall sha1_writebyte(__int64 a1, char a2)
{
++*(_DWORD *)(a1 + 84);
return sha1_addUncounted(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char a2)
{
++*(_DWORD *)(a1 + 84);
return func3(a1, a2);
}

original_code:
void sha1_writebyte(sha1nfo *s, uint8_t data) {
 ++s->byteCount;
 sha1_addUncounted(s, data);
}

canonical_original_code:
void sha1_writebyte(struct sha1nfo *s, unsigned char data) {
 ++s->byteCount;
 sha1_addUncounted(s, data);
}


decompiled_code:
__int64 __fastcall sha1_write(__int64 a1, char *a2, __int64 a3)
{
char *v3; // rbx
char *v4; // rbp
__int64 result; // rax

if ( a3 )
{
v3 = a2;
v4 = &a2[a3];
do
result = sha1_writebyte(a1, *v3++);
while ( v4 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char *a2, __int64 a3)
{
char *v3; // rbx
char *v4; // rbp
__int64 result; // rax

if ( a3 )
{
v3 = a2;
v4 = &a2[a3];
do
result = func4(a1, *v3++);
while ( v4 != v3 );
}
return result;
}

original_code:
void sha1_write(sha1nfo *s, const char *data, size_t len) {
 for (;len--;) sha1_writebyte(s, (uint8_t) *data++);
}

canonical_original_code:
void sha1_write(struct sha1nfo *s, char *data, unsigned long len) {
 for (;len--;) sha1_writebyte(s, (unsigned char) *data++);
}

variable_types:
data
char *


decompiled_code:
__int64 __fastcall sha1_pad(__int64 a1)
{
sha1_addUncounted(a1, 128);
while ( *(_BYTE *)(a1 + 88) != 56 )
sha1_addUncounted(a1, 0);
sha1_addUncounted(a1, 0);
sha1_addUncounted(a1, 0);
sha1_addUncounted(a1, 0);
sha1_addUncounted(a1, *(_DWORD *)(a1 + 84) >> 29);
sha1_addUncounted(a1, *(_DWORD *)(a1 + 84) >> 21);
sha1_addUncounted(a1, *(_DWORD *)(a1 + 84) >> 13);
sha1_addUncounted(a1, *(_DWORD *)(a1 + 84) >> 5);
return sha1_addUncounted(a1, 8 * *(_BYTE *)(a1 + 84));
}

original_code:
void sha1_pad(sha1nfo *s) {
 sha1_addUncounted(s, 0x80);
 while (s->bufferOffset != 56) sha1_addUncounted(s, 0x00);
 sha1_addUncounted(s, 0);
 sha1_addUncounted(s, 0);
 sha1_addUncounted(s, 0);
 sha1_addUncounted(s, s->byteCount >> 29);
 sha1_addUncounted(s, s->byteCount >> 21);
 sha1_addUncounted(s, s->byteCount >> 13);
 sha1_addUncounted(s, s->byteCount >> 5);
 sha1_addUncounted(s, s->byteCount << 3);
}

canonical_original_code:
void sha1_pad(struct sha1nfo *s) {
 sha1_addUncounted(s, 0x80);
 while (s->bufferOffset != 56) sha1_addUncounted(s, 0x00);
 sha1_addUncounted(s, 0);
 sha1_addUncounted(s, 0);
 sha1_addUncounted(s, 0);
 sha1_addUncounted(s, s->byteCount >> 29);
 sha1_addUncounted(s, s->byteCount >> 21);
 sha1_addUncounted(s, s->byteCount >> 13);
 sha1_addUncounted(s, s->byteCount >> 5);
 sha1_addUncounted(s, s->byteCount << 3);
}


variable_types: i int

return_type: unsigned char *


original_code:
void sha1_initHmac(sha1nfo *s, const uint8_t* key, int keyLength) {
 uint8_t i;
 memset(s->keyBuffer, 0, 64);
 if (keyLength > 64) {
  sha1_init(s);
  for (;keyLength--;) sha1_writebyte(s, *key++);
  memcpy(s->keyBuffer, sha1_result(s), 20);
 } else {
  memcpy(s->keyBuffer, key, keyLength);
 }
 sha1_init(s);
 for (i=0; i<64; i++) {
  sha1_writebyte(s, s->keyBuffer[i] ^ 0x36);
 }
}

canonical_original_code:
void sha1_initHmac(struct sha1nfo *s, unsigned char *key, int keyLength) {
 unsigned char i;
 memset(s->keyBuffer, 0, 64);
 if (keyLength > 64) {
  sha1_init(s);
  for (;keyLength--;) sha1_writebyte(s, *key++);
  memcpy(s->keyBuffer, sha1_result(s), 20);
 } else {
  memcpy(s->keyBuffer, key, keyLength);
 }
 sha1_init(s);
 for (i=0; i<64; i++) {
  sha1_writebyte(s, s->keyBuffer[i] ^ 0x36);
 }
}

variable_types:
key
unsigned char *

variable_types: keyLength int

variable_types:
i
unsigned char


original_code:
uint8_t* sha1_resultHmac(sha1nfo *s) {
 uint8_t i;
 memcpy(s->innerHash,sha1_result(s),20);
 sha1_init(s);
 for (i=0; i<64; i++) sha1_writebyte(s, s->keyBuffer[i] ^ 0x5c);
 for (i=0; i<20; i++) sha1_writebyte(s, s->innerHash[i]);
 return sha1_result(s);
}

canonical_original_code:
unsigned char *sha1_resultHmac(struct sha1nfo *s) {
 unsigned char i;
 memcpy(s->innerHash,sha1_result(s),20);
 sha1_init(s);
 for (i=0; i<64; i++) sha1_writebyte(s, s->keyBuffer[i] ^ 0x5c);
 for (i=0; i<20; i++) sha1_writebyte(s, s->innerHash[i]);
 return sha1_result(s);
}


decompiled_code:
__int64 __fastcall oauth_sign_hmac_sha1_raw(char *a1, __int64 a2, char *a3, int a4)
{
__int64 v4; // rax
_BYTE v6[200]; // [rsp+0h] [rbp-C8h] BYREF

sha1_initHmac((__int64)v6, a3, a4);
sha1_write((__int64)v6, a1, a2);
v4 = sha1_resultHmac((__int64)v6);
return oauth_encode_base64(20LL, v4);
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, __int64 a2, char *a3, int a4)
{
__int64 v4; // rax
_BYTE v6[200]; // [rsp+0h] [rbp-C8h] BYREF

func8((__int64)v6, a3, a4);
func5((__int64)v6, a1, a2);
v4 = func9((__int64)v6);
return oauth_encode_base64(20LL, v4);
}

original_code:
char *oauth_sign_hmac_sha1_raw (const char *m, const size_t ml, const char *k, const size_t kl) {
 sha1nfo s;
 sha1_initHmac(&s, (const uint8_t*) k, kl);
 sha1_write(&s, m, ml);
 unsigned char *digest = sha1_resultHmac(&s);
  return oauth_encode_base64(20, digest);
}

canonical_original_code:
char *oauth_sign_hmac_sha1_raw(char *m, unsigned long ml, char *k, unsigned long kl) {
 struct sha1nfo s;
 sha1_initHmac(&s, (unsigned char *) k, kl);
 sha1_write(&s, m, ml);
 unsigned char *digest = sha1_resultHmac(&s);
  return oauth_encode_base64(20, digest);
}

variable_types:
m
char *

variable_types:
ml
unsigned long

variable_types:
k
char *

variable_types:
kl
unsigned long

variable_types: struct sha1nfo { unsigned int buffer[-1]; unsigned int state[-1]; unsigned int byteCount; unsigned char bufferOffset; unsigned char keyBuffer[64]; unsigned char innerHash[20]; }

variable_types:
digest
unsigned char *


decompiled_code:
__int64 __fastcall oauth_sign_hmac_sha1(char *s, char *a2)
{
int v2; // er12
__int64 v3; // rax

v2 = strlen(a2);
v3 = strlen(s);
return oauth_sign_hmac_sha1_raw(s, v3, a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func11(char *s, char *a2)
{
int v2; // er12
__int64 v3; // rax

v2 = strlen(a2);
v3 = strlen(s);
return func10(s, v3, a2, v2);
}

original_code:
char *oauth_sign_hmac_sha1 (const char *m, const char *k) {
  return(oauth_sign_hmac_sha1_raw (m, strlen(m), k, strlen(k)));
}

canonical_original_code:
char *oauth_sign_hmac_sha1(char *m, char *k) {
  return(oauth_sign_hmac_sha1_raw (m, strlen(m), k, strlen(k)));
}


decompiled_code:
__int64 __fastcall oauth_body_hash_data(__int64 a1, char *a2)
{
char *v2; // rbx
__m128i *v3; // rbx
const __m128i *v4; // rax
_BYTE v6[200]; // [rsp+0h] [rbp-C8h] BYREF

v2 = a2;
sha1_init((__int64)v6);
if ( a1 )
{
do
sha1_writebyte((__int64)v6, *v2++);
while ( &a2[a1] != v2 );
}
v3 = (__m128i *)xmalloc(20LL);
v4 = (const __m128i *)sha1_result((__int64)v6);
*v3 = _mm_loadu_si128(v4);
v3[1].m128i_i32[0] = v4[1].m128i_i32[0];
return oauth_body_hash_encode(20LL, v3);
}

original_code:
char *oauth_body_hash_data(size_t length, const char *data) {
 sha1nfo s;
 sha1_init(&s);
 for (;length--;) sha1_writebyte(&s, *data++);
  unsigned char *dgst = xmalloc(20*sizeof(char));
  memcpy(dgst, sha1_result(&s), 20);
  return oauth_body_hash_encode(20, dgst);
}

canonical_original_code:
char *oauth_body_hash_data(unsigned long length, char *data) {
 struct sha1nfo s;
 sha1_init(&s);
 for (;length--;) sha1_writebyte(&s, *data++);
  unsigned char *dgst = xmalloc(20*sizeof(char));
  memcpy(dgst, sha1_result(&s), 20);
  return oauth_body_hash_encode(20, dgst);
}

variable_types:
length
unsigned long

variable_types:
dgst
unsigned char *


decompiled_code:
__int64 oauth_sign_rsa_sha1()
{
return xstrdup("---RSA/PK11-is-not-supported-by-this-version-of-liboauth---");
}

canonical_decompiled_code:
__int64 func13()
{
return xstrdup("---RSA/PK11-is-not-supported-by-this-version-of-liboauth---");
}

original_code:
char *oauth_sign_rsa_sha1 (const char *m, const char *k) {
 return xstrdup("---RSA/PK11-is-not-supported-by-this-version-of-liboauth---");
}

canonical_original_code:
char *oauth_sign_rsa_sha1(char *m, char *k) {
 return xstrdup("---RSA/PK11-is-not-supported-by-this-version-of-liboauth---");
}


decompiled_code:
__int64 oauth_verify_rsa_sha1()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func14()
{
return 0xFFFFFFFFLL;
}

original_code:
int oauth_verify_rsa_sha1 (const char *m, const char *c, const char *sig) {
 return -1;
}

canonical_original_code:
int oauth_verify_rsa_sha1(char *m, char *c, char *sig) {
 return -1;
}

variable_types:
c
char *

variable_types:
sig
char *


decompiled_code:
ssize_t __fastcall send_to_client(int a1, const void *a2, int a3)
{
ssize_t result; // rax

result = send(a1, a2, a3, 0);
if ( result < 0 )
result = ERROR("send() failed");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func0(int a1, const void *a2, int a3)
{
ssize_t result; // rax

result = send(a1, a2, a3, 0);
if ( result < 0 )
result = ERROR("send() failed");
return result;
}

original_code:
static void send_to_client(int clntSocket, char *buffer, int send_byte) {
    ssize_t numBytesSent = send(clntSocket, buffer, send_byte, 0);
    if (numBytesSent < 0)
        ERROR("send() failed");
}

canonical_original_code:
static void send_to_client(int clntSocket, char *buffer, int send_byte) {
    long numBytesSent = send(clntSocket, buffer, send_byte, 0);
    if (numBytesSent < 0)
        ERROR("send() failed");
}

variable_types: clntSocket int

variable_types:
buffer
char *

variable_types: numBytesSent long