decompiled_code:
void __fastcall print_info(char *a1)
{
char *i; // rbx
const char *v2; // rax
struct passwd *v3; // rax
struct group *v4; // rax
struct tm *v5; // r12
char *v6; // rax
struct stat v7; // [rsp+0h] [rbp-1A8h] BYREF
char s[280]; // [rsp+90h] [rbp-118h] BYREF

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

canonical_decompiled_code:
void __fastcall func11(char *a1)
{
char *i; // rbx
const char *v2; // rax
struct passwd *v3; // rax
struct group *v4; // rax
struct tm *v5; // r12
char *v6; // rax
struct stat v7; // [rsp+0h] [rbp-1A8h] BYREF
char s[280]; // [rsp+90h] [rbp-118h] BYREF

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

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

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

canonical_decompiled_code:
void __fastcall __noreturn func10(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:
__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

v1.sa_handler = sigint_handler;
memset(&v1.sa_mask, 0, 0x90uLL);
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

v1.sa_handler = sigint_handler;
memset(&v1.sa_mask, 0, 0x90uLL);
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)(); }

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

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


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; // rbx
unsigned __int8 *v1; // r13
unsigned int v2; // ebp
unsigned int v3; // er12

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

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

v0 = (unsigned __int8 *)malloc(0x81uLL);
if ( mincore(mem, memsize, v0) == -1 )
func11("mincore");
v1 = v0 + 128;
v2 = 0;
v3 = 0;
do
{
while ( (*v0 & 1) != 0 )
{
if ( v3 )
func12(83, v3);
++v0;
++v2;
v3 = 0;
if ( v1 == v0 )
goto LABEL_10;
}
if ( v2 )
func12(77, v2);
++v0;
++v3;
v2 = 0;
}
while ( v1 != v0 );
LABEL_10:
if ( v3 )
{
func12(83, v3);
if ( !v2 )
return putchar(10);
LABEL_14:
func12(77, v2);
return putchar(10);
}
if ( v2 )
goto LABEL_14;
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_sec = a1 / 1000000000;
v2.tv_nsec = a1 % 1000000000;
return nanosleep(&v2, &v2);
}

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

v2.tv_sec = a1 / 1000000000;
v2.tv_nsec = 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:
void *__fastcall ThreadMain(void *a1)
{
pthread_t v1; // rax
unsigned int v2; // er12

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

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
pthread_t v1; // rax
unsigned int v2; // er12

v1 = pthread_self();
pthread_detach(v1);
v2 = *(_DWORD *)a1;
free(a1);
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; // r15
int v4; // er14
char *v5; // r13
char *v6; // r12
char v7; // al
_QWORD *v8; // rax
struct tm *v9; // rax
__int64 v10; // rbp
__int64 v11; // rbx
int v12; // eax
int v13; // eax
int v14; // er14
_DWORD *v15; // r8
int v17; // [rsp+0h] [rbp-1158h]
int v18; // [rsp+4h] [rbp-1154h]
struct timeval timeout; // [rsp+10h] [rbp-1148h] BYREF
fd_set readfds; // [rsp+20h] [rbp-1138h] BYREF
fd_set timer; // [rsp+A0h] [rbp-10B8h] BYREF
char s[16]; // [rsp+120h] [rbp-1038h] BYREF
char v23[4080]; // [rsp+130h] [rbp-1028h] BYREF

v3 = 0LL;
v4 = 0;
v5 = 0LL;
v6 = "/etc/config/twittrouter.json";
root = (__int64)"/www/twittrouter";
servPort = (__int64)"9999";
opterr = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "p:r:c:t:u:f:ha");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'a':
v4 = 1;
break;
case 'c':
v6 = optarg;
break;
case 'h':
usage();
exit(0);
case 'p':
servPort = (__int64)optarg;
break;
case 'r':
root = (__int64)optarg;
break;
case 't':
v3 = optarg;
break;
case 'u':
v5 = optarg;
break;
default:
continue;
}
}
if ( !opterr )
{
if ( !v6 )
goto LABEL_19;
v8 = (_QWORD *)read_jconf(v6);
conf = (__int64)v8;
if ( v3 )
{
v8[1] = v3;
}
else if ( !v8[1] )
{
goto LABEL_24;
}
if ( v8[2] && v8[3] && v8[4] && v8[5] )
{
LABEL_19:
if ( v5 )
{
if ( (unsigned __int8)get_friendship(v5) )
printf("Congratulations! Verify success,%s is your twitter friend\n", v5);
else
puts("Sorry! Maybe you have not config your network to go through to evil GFW,or try another friend again");
}
else
{
if ( !v4 )
{
arpList = CreatEmptyLink();
timer.fds_bits[0] = time(0LL);
v9 = localtime(timer.fds_bits);
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 = v18 / 64;
v11 = 1LL << (v18 % 64);
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
memset(&timer, 0, sizeof(timer));
readfds.fds_bits[v10] |= v11;
timer.fds_bits[v10] |= v11;
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
if ( select(v18 + 1, &readfds, 0LL, &timer, &timeout) == -1 )
ERROR("select");
if ( (timer.fds_bits[v10] & v11) != 0 )
ERROR("servSock error\n");
if ( (readfds.fds_bits[v10] & v11) != 0 )
{
v17 = AcceptTCPConnection((unsigned int)v18);
v15 = malloc(4uLL);
if ( !v15 )
{
FATAL("malloc() failed");
v15 = 0LL;
}
*v15 = v17;
create_thread_constprop_0(v15);
}
v12 = -858993459 * v4++;
if ( __ROR4__(v12, 1) <= 0x19999999u )
{
*(_OWORD *)s = 0LL;
memset(v23, 0, sizeof(v23));
v13 = open("/proc/net/arp", 0);
v14 = v13;
if ( v13 != -1 )
{
read(v13, s, 0x1000uLL);
scan_arp_and_block(s);
close(v14);
}
v4 = 1;
}
}
}
*(_QWORD *)s = 0LL;
*(_WORD *)&s[8] = 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(v6);
}
else
{
puts("Sorry! auth failed");
}
}
exit(0);
}
}
LABEL_24:
usage();
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
int v4; // er14
char *v5; // r13
char *v6; // r12
char v7; // al
_QWORD *v8; // rax
struct tm *v9; // rax
__int64 v10; // rbp
__int64 v11; // rbx
int v12; // eax
int v13; // eax
int v14; // er14
_DWORD *v15; // r8
int v17; // [rsp+0h] [rbp-1158h]
int v18; // [rsp+4h] [rbp-1154h]
struct timeval timeout; // [rsp+10h] [rbp-1148h] BYREF
fd_set readfds; // [rsp+20h] [rbp-1138h] BYREF
fd_set timer; // [rsp+A0h] [rbp-10B8h] BYREF
char s[16]; // [rsp+120h] [rbp-1038h] BYREF
char v23[4080]; // [rsp+130h] [rbp-1028h] BYREF

v3 = 0LL;
v4 = 0;
v5 = 0LL;
v6 = "/etc/config/twittrouter.json";
root = (__int64)"/www/twittrouter";
servPort = (__int64)"9999";
opterr = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "p:r:c:t:u:f:ha");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'a':
v4 = 1;
break;
case 'c':
v6 = optarg;
break;
case 'h':
usage();
exit(0);
case 'p':
servPort = (__int64)optarg;
break;
case 'r':
root = (__int64)optarg;
break;
case 't':
v3 = optarg;
break;
case 'u':
v5 = optarg;
break;
default:
continue;
}
}
if ( !opterr )
{
if ( !v6 )
goto LABEL_19;
v8 = (_QWORD *)read_jconf(v6);
conf = (__int64)v8;
if ( v3 )
{
v8[1] = v3;
}
else if ( !v8[1] )
{
goto LABEL_24;
}
if ( v8[2] && v8[3] && v8[4] && v8[5] )
{
LABEL_19:
if ( v5 )
{
if ( (unsigned __int8)get_friendship(v5) )
printf("Congratulations! Verify success,%s is your twitter friend\n", v5);
else
puts("Sorry! Maybe you have not config your network to go through to evil GFW,or try another friend again");
}
else
{
if ( !v4 )
{
arpList = CreatEmptyLink();
timer.fds_bits[0] = time(0LL);
v9 = localtime(timer.fds_bits);
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 = v18 / 64;
v11 = 1LL << (v18 % 64);
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
memset(&timer, 0, sizeof(timer));
readfds.fds_bits[v10] |= v11;
timer.fds_bits[v10] |= v11;
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
if ( select(v18 + 1, &readfds, 0LL, &timer, &timeout) == -1 )
ERROR("select");
if ( (timer.fds_bits[v10] & v11) != 0 )
ERROR("servSock error\n");
if ( (readfds.fds_bits[v10] & v11) != 0 )
{
v17 = AcceptTCPConnection((unsigned int)v18);
v15 = malloc(4uLL);
if ( !v15 )
{
FATAL("malloc() failed");
v15 = 0LL;
}
*v15 = v17;
func1(v15);
}
v12 = -858993459 * v4++;
if ( __ROR4__(v12, 1) <= 0x19999999u )
{
*(_OWORD *)s = 0LL;
memset(v23, 0, sizeof(v23));
v13 = open("/proc/net/arp", 0);
v14 = v13;
if ( v13 != -1 )
{
read(v13, s, 0x1000uLL);
scan_arp_and_block(s);
close(v14);
}
v4 = 1;
}
}
}
*(_QWORD *)s = 0LL;
*(_WORD *)&s[8] = 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(v6);
}
else
{
puts("Sorry! auth failed");
}
}
exit(0);
}
}
LABEL_24:
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]

return_type: int


ERROR

decompiled_code:
int __fastcall ERROR(const char *a1)
{
int *v1; // rax
char *v2; // rbx
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; // rbx
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 *

return_type: char *


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

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

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

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

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, char *needle, char *src)
{
char *v3; // r13
char *v4; // rbp
char *v5; // r12
int v6; // er15
int i; // ebx
char *v8; // rax
int v9; // er14
size_t v10; // rax
int v11; // er15
__int64 v12; // rax
char *v13; // r14
signed int v14; // ebx
size_t v17; // [rsp+0h] [rbp-58h]
int v18; // [rsp+Ch] [rbp-4Ch]
__int64 v19; // [rsp+10h] [rbp-48h]
char *v20; // [rsp+18h] [rbp-40h]

if ( !haystack )
return 0LL;
v3 = haystack;
v4 = needle;
v5 = src;
if ( !needle )
{
v18 = 0;
v4 = (char *)&unk_4D6;
if ( src )
goto LABEL_4;
LABEL_15:
v6 = 0;
v5 = (char *)&unk_4D6;
goto LABEL_5;
}
v18 = strlen(needle);
if ( !v5 )
goto LABEL_15;
LABEL_4:
v6 = strlen(v5);
LABEL_5:
for ( i = 0; ; ++i )
{
v8 = strstr(haystack, v4);
if ( !v8 )
break;
haystack = &v8[v18];
}
v9 = v6;
v10 = strlen(v3);
v20 = (char *)malloc(i * (v6 - v18) + v10 + 1);
if ( !v20 )
return 0LL;
v11 = i - 1;
if ( i )
{
v12 = v9;
v13 = v20;
v19 = v12;
do
{
v14 = (unsigned int)strstr(v3, v4) - (_DWORD)v3;
v17 = v14;
strncpy(v13, v3, v17);
v13 = &strcpy(&v13[v17], v5)[v19];
v3 += v18 + v14;
}
while ( v11-- != 0 );
}
else
{
v13 = v20;
}
strcpy(v13, v3);
return v20;
}

canonical_decompiled_code:
char *__fastcall func4(char *haystack, char *needle, char *src)
{
char *v3; // r13
char *v4; // rbp
char *v5; // r12
int v6; // er15
int i; // ebx
char *v8; // rax
int v9; // er14
size_t v10; // rax
int v11; // er15
__int64 v12; // rax
char *v13; // r14
signed int v14; // ebx
size_t v17; // [rsp+0h] [rbp-58h]
int v18; // [rsp+Ch] [rbp-4Ch]
__int64 v19; // [rsp+10h] [rbp-48h]
char *v20; // [rsp+18h] [rbp-40h]

if ( !haystack )
return 0LL;
v3 = haystack;
v4 = needle;
v5 = src;
if ( !needle )
{
v18 = 0;
v4 = (char *)&unk_4D6;
if ( src )
goto LABEL_4;
LABEL_15:
v6 = 0;
v5 = (char *)&unk_4D6;
goto LABEL_5;
}
v18 = strlen(needle);
if ( !v5 )
goto LABEL_15;
LABEL_4:
v6 = strlen(v5);
LABEL_5:
for ( i = 0; ; ++i )
{
v8 = strstr(haystack, v4);
if ( !v8 )
break;
haystack = &v8[v18];
}
v9 = v6;
v10 = strlen(v3);
v20 = (char *)malloc(i * (v6 - v18) + v10 + 1);
if ( !v20 )
return 0LL;
v11 = i - 1;
if ( i )
{
v12 = v9;
v13 = v20;
v19 = v12;
do
{
v14 = (unsigned int)strstr(v3, v4) - (_DWORD)v3;
v17 = v14;
strncpy(v13, v3, v17);
v13 = &strcpy(&v13[v17], v5)[v19];
v3 += v18 + v14;
}
while ( v11-- != 0 );
}
else
{
v13 = v20;
}
strcpy(v13, 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((_DWORD *)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((_DWORD *)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; // rbp
char *v4; // rbx
char v5; // si
__int64 result; // rax

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

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

if ( a3 )
{
v3 = &a2[a3];
v4 = a2;
do
{
v5 = *v4++;
result = func4(a1, v5);
}
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);
}


decompiled_code:
__int64 __fastcall sha1_result(__int64 a1)
{
unsigned int *v2; // rdi
unsigned int *v3; // rax
unsigned int v4; // edx

sha1_pad(a1);
v2 = (unsigned int *)(a1 + 84);
v3 = (unsigned int *)(a1 + 64);
do
{
v4 = *v3++;
*(v3 - 1) = _byteswap_ulong(v4);
}
while ( v3 != v2 );
return a1 + 64;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned int *v2; // rdi
unsigned int *v3; // rax
unsigned int v4; // edx

func6(a1);
v2 = (unsigned int *)(a1 + 84);
v3 = (unsigned int *)(a1 + 64);
do
{
v4 = *v3++;
*(v3 - 1) = _byteswap_ulong(v4);
}
while ( v3 != v2 );
return a1 + 64;
}

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; // er13
__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; // er13
__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
char *v3; // rbp
char v4; // si
__m128i *v5; // rbp
const __m128i *v6; // rax
_BYTE v8[200]; // [rsp+0h] [rbp-C8h] BYREF

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

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


decompiled_code:
int __fastcall handle_http_get(int a1, const char *a2)
{
const char *v2; // r13
size_t v3; // rax
struct tm *v4; // rax
int v5; // eax
int v6; // ebp
int v7; // ebx
const char *v8; // rax
char *v9; // r13
unsigned int v10; // eax
time_t timer; // [rsp+0h] [rbp-10B0h] BYREF
char dest[16]; // [rsp+8h] [rbp-10A8h] BYREF
__int128 v14; // [rsp+18h] [rbp-1098h]
__int128 v15; // [rsp+28h] [rbp-1088h]
__int128 v16; // [rsp+38h] [rbp-1078h]
__int128 v17; // [rsp+48h] [rbp-1068h]
__int128 v18; // [rsp+58h] [rbp-1058h]
__int128 v19; // [rsp+68h] [rbp-1048h]
__int128 v20; // [rsp+78h] [rbp-1038h]
char s[4136]; // [rsp+88h] [rbp-1028h] BYREF

v2 = root;
*(_OWORD *)dest = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
strcpy(dest, root);
v3 = strlen(v2);
strcpy(&dest[v3], a2);
timer = time(0LL);
v4 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v4);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mresponse to client and send file: %s\n", s, dest);
v5 = open(dest, 0);
if ( v5 == -1 )
return send_to_client(a1, "HTTP/1.0 404 Not Found\r\n\r\n", 26);
v6 = v5;
send_to_client(a1, "HTTP/1.0 200 OK\r\n\r\n", 19);
while ( 1 )
{
v7 = read(v6, s, 0x1000uLL);
if ( v7 <= 0 )
break;
if ( !strcmp(strrchr(dest, 46), ".html") )
{
v8 = (const char *)str_replace(s, "twitterid", *(_QWORD *)(conf + 8LL));
v9 = (char *)v8;
if ( v8 )
{
v10 = (unsigned int)strstr(v8, "</html>");
send_to_client(a1, v9, v10 - (_DWORD)v9 + 7);
free(v9);
}
}
else
{
send_to_client(a1, s, v7);
}
}
return close(v6);
}

canonical_decompiled_code:
int __fastcall func1(int a1, const char *a2)
{
const char *v2; // r13
size_t v3; // rax
struct tm *v4; // rax
int v5; // eax
int v6; // ebp
int v7; // ebx
const char *v8; // rax
char *v9; // r13
unsigned int v10; // eax
time_t timer; // [rsp+0h] [rbp-10B0h] BYREF
char dest[16]; // [rsp+8h] [rbp-10A8h] BYREF
__int128 v14; // [rsp+18h] [rbp-1098h]
__int128 v15; // [rsp+28h] [rbp-1088h]
__int128 v16; // [rsp+38h] [rbp-1078h]
__int128 v17; // [rsp+48h] [rbp-1068h]
__int128 v18; // [rsp+58h] [rbp-1058h]
__int128 v19; // [rsp+68h] [rbp-1048h]
__int128 v20; // [rsp+78h] [rbp-1038h]
char s[4136]; // [rsp+88h] [rbp-1028h] BYREF

v2 = root;
*(_OWORD *)dest = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
strcpy(dest, root);
v3 = strlen(v2);
strcpy(&dest[v3], a2);
timer = time(0LL);
v4 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v4);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mresponse to client and send file: %s\n", s, dest);
v5 = open(dest, 0);
if ( v5 == -1 )
return func0(a1, "HTTP/1.0 404 Not Found\r\n\r\n", 26);
v6 = v5;
func0(a1, "HTTP/1.0 200 OK\r\n\r\n", 19);
while ( 1 )
{
v7 = read(v6, s, 0x1000uLL);
if ( v7 <= 0 )
break;
if ( !strcmp(strrchr(dest, 46), ".html") )
{
v8 = (const char *)str_replace(s, "twitterid", *(_QWORD *)(conf + 8LL));
v9 = (char *)v8;
if ( v8 )
{
v10 = (unsigned int)strstr(v8, "</html>");
func0(a1, v9, v10 - (_DWORD)v9 + 7);
free(v9);
}
}
else
{
func0(a1, s, v7);
}
}
return close(v6);
}

original_code:
static void handle_http_get(int clntSocket, char* file) {
    char data_to_send[BUFSIZE];
    char path[128] = {'\0',};
    int bytes_read;
    int fd;
    strcpy(path, root);
    strcpy(&path[strlen(root)], file);
    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" "response to client and send file: %s" "\n", timestr, path);}while(0);
    if ((fd=open(path, 00)) != -1)
    {
        send_to_client(clntSocket, "HTTP/1.0 200 OK\r\n\r\n", 19);
        while ((bytes_read=read(fd, data_to_send, BUFSIZE)) > 0) {
            if (strcmp(strrchr(path,'.'), ".html") == 0) {
                char *replaced_id = str_replace(data_to_send, "twitterid", conf->TwitterID);
                if (replaced_id) {
                    send_to_client(clntSocket,replaced_id, strstr(replaced_id,"</html>") - replaced_id + 7);
                    free(replaced_id);
                }
            } else {
                send_to_client(clntSocket,data_to_send, bytes_read);
            }
        }
        close(fd);
    }
    else {
        send_to_client(clntSocket, "HTTP/1.0 404 Not Found\r\n\r\n", 26);
    }
}

canonical_original_code:
static void handle_http_get(int clntSocket, char *file) {
    char data_to_send[-1];
    char path[128] = {'\0',};
    int bytes_read;
    int fd;
    strcpy(path, root);
    strcpy(&path[strlen(root)], file);
    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" "response to client and send file: %s" "\n", timestr, path);}while(0);
    if ((fd=open(path, 00)) != -1)
    {
        send_to_client(clntSocket, "HTTP/1.0 200 OK\r\n\r\n", 19);
        while ((bytes_read=read(fd, data_to_send, BUFSIZE)) > 0) {
            if (strcmp(strrchr(path,'.'), ".html") == 0) {
                char *replaced_id = str_replace(data_to_send, "twitterid", conf->TwitterID);
                if (replaced_id) {
                    send_to_client(clntSocket,replaced_id, strstr(replaced_id,"</html>") - replaced_id + 7);
                    free(replaced_id);
                }
            } else {
                send_to_client(clntSocket,data_to_send, bytes_read);
            }
        }
        close(fd);
    }
    else {
        send_to_client(clntSocket, "HTTP/1.0 404 Not Found\r\n\r\n", 26);
    }
}

variable_types:
file
char *

variable_types:
path
char [128]

variable_types: fd int

variable_types: now long

variable_types:
timestr
char [20]


decompiled_code:
char *__fastcall get_twitter_id(int fd, char *haystack, const char *a3, __int64 a4)
{
char *v7; // rax
char v8; // dl
char *v9; // rsi
__int64 i; // rax
struct tm *v11; // rax
int v12; // er15
char *v13; // r14
struct tm *v14; // rax
__int64 v15; // r12
__int64 v16; // rax
char v17; // dl
struct tm *v19; // rax
struct tm *v20; // rax
struct tm *v21; // rax
struct tm *v22; // rax
struct tm *v23; // rax
char *v24; // [rsp+8h] [rbp-1090h]
time_t v25; // [rsp+18h] [rbp-1080h] BYREF
char nptr[16]; // [rsp+20h] [rbp-1078h] BYREF
int v27; // [rsp+30h] [rbp-1068h]
time_t timer[4]; // [rsp+40h] [rbp-1058h] BYREF
char s[16]; // [rsp+60h] [rbp-1038h] BYREF
char v30[4080]; // [rsp+70h] [rbp-1028h] BYREF

v7 = strstr(haystack, "Content-Length");
if ( v7 )
{
v8 = v7[16];
v9 = v7;
v27 = 0;
*(_OWORD *)nptr = 0LL;
for ( i = 0LL; v8 != 10; v8 = v9[i + 16] )
{
if ( (unsigned __int8)(v8 - 48) <= 9u )
{
nptr[i] = v8;
}
else if ( (unsigned __int8)(v9[i + 15] - 48) <= 9u )
{
break;
}
++i;
}
timer[0] = time(0LL);
v11 = localtime(timer);
strftime(s, 0x14uLL, "%F %T", v11);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mcontent_length_value = %s\n", s, nptr);
if ( nptr[0] )
{
v12 = atoi(nptr);
if ( v12 <= 26 )
{
v13 = strstr(haystack, "uname=");
*(_OWORD *)s = 0LL;
memset(v30, 0, sizeof(v30));
v24 = strstr(haystack, "\r\n\r\n");
v25 = time(0LL);
v14 = localtime(&v25);
strftime((char *)timer, 0x14uLL, "%F %T", v14);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mfirst recv length = %d\n", (const char *)timer, a4);
if ( v24 && (v15 = v24 - haystack + v12 + 4, v15 <= a4) )
{
if ( !v13 )
{
v25 = time(0LL);
v20 = localtime(&v25);
strftime((char *)timer, 0x14uLL, "%F %T", v20);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mexpect length = %d\n", (const char *)timer, v15);
return v13;
}
}
else if ( !v13 )
{
if ( recv(fd, s, 0x1000uLL, 0) <= 0 )
{
ERROR("recv() failed");
return v13;
}
v25 = time(0LL);
v21 = localtime(&v25);
strftime((char *)timer, 0x14uLL, "%F %T", v21);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mget username start\n", (const char *)timer);
v25 = time(0LL);
v22 = localtime(&v25);
strftime((char *)timer, 0x14uLL, "%F %T", v22);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0m%s\n", (const char *)timer, s);
v25 = time(0LL);
v23 = localtime(&v25);
strftime((char *)timer, 0x14uLL, "%F %T", v23);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mget username finished\n", (const char *)timer);
v13 = strstr(s, "uname=");
if ( !v13 )
return 0LL;
}
v16 = 6LL;
if ( v12 > 6 )
{
while ( 1 )
{
v17 = v13[v16];
if ( (unsigned __int8)(v17 - 48) > 9u && v17 != 95 && (unsigned __int8)((v17 & 0xDF) - 65) > 0x19u )
break;
a3[v16++ - 6] = v17;
if ( v12 == v16 )
{
v13 = (char *)a3;
v25 = time(0LL);
v19 = localtime(&v25);
strftime((char *)timer, 0x14uLL, "%F %T", v19);
fprintf(
stderr,
"\x1B[01;32m %s INFO: \x1B[0ma friend of twitter %s is verifying...\n\n",
(const char *)timer,
a3);
return v13;
}
}
}
handle_http_get(fd, "/VERIFY_FAILED.html");
}
}
}
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func2(int fd, char *haystack, const char *a3, __int64 a4)
{
char *v7; // rax
char v8; // dl
char *v9; // rsi
__int64 i; // rax
struct tm *v11; // rax
int v12; // er15
char *v13; // r14
struct tm *v14; // rax
__int64 v15; // r12
__int64 v16; // rax
char v17; // dl
struct tm *v19; // rax
struct tm *v20; // rax
struct tm *v21; // rax
struct tm *v22; // rax
struct tm *v23; // rax
char *v24; // [rsp+8h] [rbp-1090h]
time_t v25; // [rsp+18h] [rbp-1080h] BYREF
char nptr[16]; // [rsp+20h] [rbp-1078h] BYREF
int v27; // [rsp+30h] [rbp-1068h]
time_t timer[4]; // [rsp+40h] [rbp-1058h] BYREF
char s[16]; // [rsp+60h] [rbp-1038h] BYREF
char v30[4080]; // [rsp+70h] [rbp-1028h] BYREF

v7 = strstr(haystack, "Content-Length");
if ( v7 )
{
v8 = v7[16];
v9 = v7;
v27 = 0;
*(_OWORD *)nptr = 0LL;
for ( i = 0LL; v8 != 10; v8 = v9[i + 16] )
{
if ( (unsigned __int8)(v8 - 48) <= 9u )
{
nptr[i] = v8;
}
else if ( (unsigned __int8)(v9[i + 15] - 48) <= 9u )
{
break;
}
++i;
}
timer[0] = time(0LL);
v11 = localtime(timer);
strftime(s, 0x14uLL, "%F %T", v11);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mcontent_length_value = %s\n", s, nptr);
if ( nptr[0] )
{
v12 = atoi(nptr);
if ( v12 <= 26 )
{
v13 = strstr(haystack, "uname=");
*(_OWORD *)s = 0LL;
memset(v30, 0, sizeof(v30));
v24 = strstr(haystack, "\r\n\r\n");
v25 = time(0LL);
v14 = localtime(&v25);
strftime((char *)timer, 0x14uLL, "%F %T", v14);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mfirst recv length = %d\n", (const char *)timer, a4);
if ( v24 && (v15 = v24 - haystack + v12 + 4, v15 <= a4) )
{
if ( !v13 )
{
v25 = time(0LL);
v20 = localtime(&v25);
strftime((char *)timer, 0x14uLL, "%F %T", v20);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mexpect length = %d\n", (const char *)timer, v15);
return v13;
}
}
else if ( !v13 )
{
if ( recv(fd, s, 0x1000uLL, 0) <= 0 )
{
ERROR("recv() failed");
return v13;
}
v25 = time(0LL);
v21 = localtime(&v25);
strftime((char *)timer, 0x14uLL, "%F %T", v21);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mget username start\n", (const char *)timer);
v25 = time(0LL);
v22 = localtime(&v25);
strftime((char *)timer, 0x14uLL, "%F %T", v22);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0m%s\n", (const char *)timer, s);
v25 = time(0LL);
v23 = localtime(&v25);
strftime((char *)timer, 0x14uLL, "%F %T", v23);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mget username finished\n", (const char *)timer);
v13 = strstr(s, "uname=");
if ( !v13 )
return 0LL;
}
v16 = 6LL;
if ( v12 > 6 )
{
while ( 1 )
{
v17 = v13[v16];
if ( (unsigned __int8)(v17 - 48) > 9u && v17 != 95 && (unsigned __int8)((v17 & 0xDF) - 65) > 0x19u )
break;
a3[v16++ - 6] = v17;
if ( v12 == v16 )
{
v13 = (char *)a3;
v25 = time(0LL);
v19 = localtime(&v25);
strftime((char *)timer, 0x14uLL, "%F %T", v19);
fprintf(
stderr,
"\x1B[01;32m %s INFO: \x1B[0ma friend of twitter %s is verifying...\n\n",
(const char *)timer,
a3);
return v13;
}
}
}
func1(fd, "/VERIFY_FAILED.html");
}
}
}
return 0LL;
}

original_code:
static char* get_twitter_id(int clntSocket, char *poststr, char *user, ssize_t buffer_len) {
    if(!poststr) return ((void *)0);
    char *content_length = strstr(poststr, "Content-Length");
    if(!content_length) return ((void *)0);
    int i = 0;
    char content_length_value[20] = {'\0',};
    while(*(content_length + 16 + i) != '\n') {
        if(*(content_length + 16 + i) >= '0' && *(content_length + 16 + i) <= '9') {
            content_length_value[i] = *(content_length + 16 + i);
        } else {
            if(*(content_length + 16 + i - 1) >= '0' && *(content_length + 16 + i - 1) <= '9') {
                break;
            }
        }
        i++;
    }
    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" "content_length_value = %s" "\n", timestr,content_length_value);}while(0);
    if (content_length_value[0] == '\0') return ((void *)0);
    int length = atoi(content_length_value);
    if(length - 6 > 20) {
        return ((void *)0);
    }
    char *username = strstr(poststr,"uname=");
    char buffer[BUFSIZE] = {'\0',};
    char *crlf = strstr(poststr,"\r\n\r\n");
    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" "first recv length = %d" "\n", timestr, buffer_len);}while(0);
    if(crlf != ((void *)0) && crlf - poststr + 4 + length <= buffer_len && username == ((void *)0)) {
        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" "expect length = %d" "\n", timestr, crlf - poststr + 4 + length);}while(0);
        return ((void *)0);
    }
    if(username == ((void *)0)) {
        ssize_t numBytesRcvd = recv(clntSocket, buffer, BUFSIZE, 0);
        if (numBytesRcvd <= 0){
            ERROR("recv() failed");
            return ((void *)0);
        }
        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" "get username start" "\n", timestr);}while(0);
        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" "%s" "\n", timestr,buffer);}while(0);
        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" "get username finished" "\n", timestr);}while(0);
        username = strstr(buffer,"uname=");
        if(username == ((void *)0)) return ((void *)0);
    }
    if(length <= 6) {
        handle_http_get(clntSocket, "/VERIFY_FAILED.html");
        return ((void *)0);
    }
    int j = 0;
    char *word = username + 6;
    while(j + 6 < length) {
        if(*(word + j) == '_' ||
        (*(word + j) >= '0' && *(word + j) <= '9') ||
        (*(word + j) >= 'A' && *(word + j) <= 'Z') ||
        (*(word + j) >= 'a' && *(word + j) <= 'z')) {
            user[j] = *(word + j);
            j++;
        } else {
            handle_http_get(clntSocket, "/VERIFY_FAILED.html");
            return ((void *)0);
        }
    }
    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" "a friend of twitter %s is verifying...\n" "\n", timestr, user);}while(0);
    return user;
}

canonical_original_code:
static char *get_twitter_id(int clntSocket, char *poststr, char *user, long buffer_len) {
    if(!poststr) return ((void *)0);
    char *content_length = strstr(poststr, "Content-Length");
    if(!content_length) return ((void *)0);
    int i = 0;
    char content_length_value[20] = {'\0',};
    while(*(content_length + 16 + i) != '\n') {
        if(*(content_length + 16 + i) >= '0' && *(content_length + 16 + i) <= '9') {
            content_length_value[i] = *(content_length + 16 + i);
        } else {
            if(*(content_length + 16 + i - 1) >= '0' && *(content_length + 16 + i - 1) <= '9') {
                break;
            }
        }
        i++;
    }
    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" "content_length_value = %s" "\n", timestr,content_length_value);}while(0);
    if (content_length_value[0] == '\0') return ((void *)0);
    int length = atoi(content_length_value);
    if(length - 6 > 20) {
        return ((void *)0);
    }
    char *username = strstr(poststr,"uname=");
    char buffer[-1] = {'\0',};
    char *crlf = strstr(poststr,"\r\n\r\n");
    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" "first recv length = %d" "\n", timestr, buffer_len);}while(0);
    if(crlf != ((void *)0) && crlf - poststr + 4 + length <= buffer_len && username == ((void *)0)) {
        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" "expect length = %d" "\n", timestr, crlf - poststr + 4 + length);}while(0);
        return ((void *)0);
    }
    if(username == ((void *)0)) {
        long numBytesRcvd = recv(clntSocket, buffer, BUFSIZE, 0);
        if (numBytesRcvd <= 0){
            ERROR("recv() failed");
            return ((void *)0);
        }
        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" "get username start" "\n", timestr);}while(0);
        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" "%s" "\n", timestr,buffer);}while(0);
        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" "get username finished" "\n", timestr);}while(0);
        username = strstr(buffer,"uname=");
        if(username == ((void *)0)) return ((void *)0);
    }
    if(length <= 6) {
        handle_http_get(clntSocket, "/VERIFY_FAILED.html");
        return ((void *)0);
    }
    int j = 0;
    char *word = username + 6;
    while(j + 6 < length) {
        if(*(word + j) == '_' ||
        (*(word + j) >= '0' && *(word + j) <= '9') ||
        (*(word + j) >= 'A' && *(word + j) <= 'Z') ||
        (*(word + j) >= 'a' && *(word + j) <= 'z')) {
            user[j] = *(word + j);
            j++;
        } else {
            handle_http_get(clntSocket, "/VERIFY_FAILED.html");
            return ((void *)0);
        }
    }
    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" "a friend of twitter %s is verifying...\n" "\n", timestr, user);}while(0);
    return user;
}

variable_types:
poststr
char *

variable_types:
user
char *

variable_types: i int

variable_types: length int

variable_types:
username
char *

variable_types:
buffer
char [-1]

variable_types:
crlf
char *

variable_types: numBytesRcvd long

variable_types: j int

variable_types:
word
char *


SetupTCPServerSocket

decompiled_code:
__int64 __fastcall SetupTCPServerSocket(char *service)
{
struct addrinfo *v1; // rbp
int v2; // eax
unsigned int v3; // er12
int v4; // edi
int v6; // [rsp+0h] [rbp-D8h] BYREF
socklen_t len; // [rsp+4h] [rbp-D4h] BYREF
struct addrinfo *pai; // [rsp+8h] [rbp-D0h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-98h] BYREF

*(_QWORD *)&req.ai_flags = 0x200000001LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(0LL, service, &req, &pai) )
ERROR("getaddrinfo() failed");
v1 = pai;
if ( !pai )
{
v3 = -1;
goto LABEL_10;
}
while ( 1 )
{
v2 = socket(v1->ai_family, v1->ai_socktype, v1->ai_protocol);
v3 = v2;
if ( v2 >= 0 )
break;
LABEL_8:
v1 = v1->ai_next;
if ( !v1 )
{
v1 = pai;
goto LABEL_10;
}
}
v6 = 1;
setsockopt(v2, 1, 2, &v6, 4u);
if ( bind(v3, v1->ai_addr, v1->ai_addrlen) || listen(v3, 5) )
{
v4 = v3;
v3 = -1;
close(v4);
goto LABEL_8;
}
len = 128;
if ( getsockname(v3, &addr, &len) < 0 )
ERROR("getsockname() failed");
fwrite("Binding to ", 1uLL, 0xBuLL, stdout);
PrintSocketAddress(&addr, stdout, 0LL);
fputc(10, stdout);
v1 = pai;
LABEL_10:
freeaddrinfo(v1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *service)
{
struct addrinfo *v1; // rbp
int v2; // eax
unsigned int v3; // er12
int v4; // edi
int v6; // [rsp+0h] [rbp-D8h] BYREF
socklen_t len; // [rsp+4h] [rbp-D4h] BYREF
struct addrinfo *pai; // [rsp+8h] [rbp-D0h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-98h] BYREF

*(_QWORD *)&req.ai_flags = 0x200000001LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(0LL, service, &req, &pai) )
ERROR("getaddrinfo() failed");
v1 = pai;
if ( !pai )
{
v3 = -1;
goto LABEL_10;
}
while ( 1 )
{
v2 = socket(v1->ai_family, v1->ai_socktype, v1->ai_protocol);
v3 = v2;
if ( v2 >= 0 )
break;
LABEL_8:
v1 = v1->ai_next;
if ( !v1 )
{
v1 = pai;
goto LABEL_10;
}
}
v6 = 1;
setsockopt(v2, 1, 2, &v6, 4u);
if ( bind(v3, v1->ai_addr, v1->ai_addrlen) || listen(v3, 5) )
{
v4 = v3;
v3 = -1;
close(v4);
goto LABEL_8;
}
len = 128;
if ( getsockname(v3, &addr, &len) < 0 )
ERROR("getsockname() failed");
fwrite("Binding to ", 1uLL, 0xBuLL, stdout);
PrintSocketAddress(&addr, stdout, 0LL);
fputc(10, stdout);
v1 = pai;
LABEL_10:
freeaddrinfo(v1);
return v3;
}

original_code:
int SetupTCPServerSocket(const char *service) {
    struct addrinfo addrCriteria;
    memset(&addrCriteria, 0, sizeof(addrCriteria));
    addrCriteria.ai_family = 2;
    addrCriteria.ai_flags = 0x0001;
    addrCriteria.ai_socktype = SOCK_STREAM;
    addrCriteria.ai_protocol = IPPROTO_TCP;
    struct addrinfo *servAddr;
    int rtnVal = getaddrinfo(((void *)0), service, &addrCriteria, &servAddr);
    if (rtnVal != 0)
        ERROR("getaddrinfo() failed");
    int servSock = -1;
    for (struct addrinfo *addr = servAddr; addr != ((void *)0); addr = addr->ai_next) {
        servSock = socket(addr->ai_family, addr->ai_socktype,
                addr->ai_protocol);
        if (servSock < 0)
            continue;
        int opt = 1;
        setsockopt(servSock, 1, 2, &opt, sizeof(opt));
        if ((bind(servSock, addr->ai_addr, addr->ai_addrlen) == 0) &&
                (listen(servSock, MAXPENDING) == 0)) {
            struct sockaddr_storage localAddr;
            socklen_t addrSize = sizeof(localAddr);
            if (getsockname(servSock, (struct sockaddr *) &localAddr, &addrSize) < 0)
                ERROR("getsockname() failed");
            fputs("Binding to ", stdout);
            PrintSocketAddress((struct sockaddr *) &localAddr, stdout, 0);
            fputc('\n', stdout);
            break;
        }
        close(servSock);
        servSock = -1;
    }
    freeaddrinfo(servAddr);
    return servSock;
}

canonical_original_code:
int SetupTCPServerSocket(char *service) {
    struct addrinfo addrCriteria;
    memset(&addrCriteria, 0, sizeof(addrCriteria));
    addrCriteria.ai_family = 2;
    addrCriteria.ai_flags = 0x0001;
    addrCriteria.ai_socktype = SOCK_STREAM;
    addrCriteria.ai_protocol = IPPROTO_TCP;
    struct addrinfo *servAddr;
    int rtnVal = getaddrinfo(((void *)0), service, &addrCriteria, &servAddr);
    if (rtnVal != 0)
        ERROR("getaddrinfo() failed");
    int servSock = -1;
    for (struct addrinfo *addr = servAddr; addr != ((void *)0); addr = addr->ai_next) {
        servSock = socket(addr->ai_family, addr->ai_socktype,
                addr->ai_protocol);
        if (servSock < 0)
            continue;
        int opt = 1;
        setsockopt(servSock, 1, 2, &opt, sizeof(opt));
        if ((bind(servSock, addr->ai_addr, addr->ai_addrlen) == 0) &&
                (listen(servSock, MAXPENDING) == 0)) {
            struct sockaddr_storage localAddr;
            unsigned int addrSize = sizeof(localAddr);
            if (getsockname(servSock, (struct sockaddr *) &localAddr, &addrSize) < 0)
                ERROR("getsockname() failed");
            fputs("Binding to ", stdout);
            PrintSocketAddress((struct sockaddr *) &localAddr, stdout, 0);
            fputc('\n', stdout);
            break;
        }
        close(servSock);
        servSock = -1;
    }
    freeaddrinfo(servAddr);
    return servSock;
}

variable_types:
service
char *

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

variable_types: rtnVal int

variable_types: servSock int

variable_types: opt int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
addrSize
unsigned int

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


AcceptTCPConnection

decompiled_code:
__int64 __fastcall AcceptTCPConnection(int a1)
{
int v1; // er12
socklen_t addr_len; // [rsp+Ch] [rbp-8Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-88h] BYREF

addr_len = 128;
v1 = accept(a1, &addr, &addr_len);
if ( v1 < 0 )
ERROR("accept() failed");
fwrite("Handling client ", 1uLL, 0x10uLL, stdout);
PrintSocketAddress(&addr, stdout, 0LL);
fputc(10, stdout);
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // er12
socklen_t addr_len; // [rsp+Ch] [rbp-8Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-88h] BYREF

addr_len = 128;
v1 = accept(a1, &addr, &addr_len);
if ( v1 < 0 )
ERROR("accept() failed");
fwrite("Handling client ", 1uLL, 0x10uLL, stdout);
PrintSocketAddress(&addr, stdout, 0LL);
fputc(10, stdout);
return (unsigned int)v1;
}

original_code:
int AcceptTCPConnection(int servSock) {
    struct sockaddr_storage clntAddr;
    socklen_t clntAddrLen = sizeof(clntAddr);
    int clntSock = accept(servSock, (struct sockaddr *) &clntAddr, &clntAddrLen);
    if (clntSock < 0)
        ERROR("accept() failed");
    fputs("Handling client ", stdout);
    PrintSocketAddress((struct sockaddr *) &clntAddr, stdout,0);
    fputc('\n', stdout);
    return clntSock;
}

canonical_original_code:
int AcceptTCPConnection(int servSock) {
    struct sockaddr_storage clntAddr;
    unsigned int clntAddrLen = sizeof(clntAddr);
    int clntSock = accept(servSock, (struct sockaddr *) &clntAddr, &clntAddrLen);
    if (clntSock < 0)
        ERROR("accept() failed");
    fputs("Handling client ", stdout);
    PrintSocketAddress((struct sockaddr *) &clntAddr, stdout,0);
    fputc('\n', stdout);
    return clntSock;
}

variable_types:
clntAddrLen
unsigned int

variable_types: clntSock int

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

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


HandleTCPClient

decompiled_code:
int __fastcall HandleTCPClient(int fd)
{
ssize_t v1; // rax
__int64 v2; // r12
struct tm *v3; // rax
struct tm *v4; // rax
int result; // eax
char *v6; // rax
const char *v7; // r8
char *v8; // rsi
time_t timer; // [rsp+8h] [rbp-1040h] BYREF
char s[16]; // [rsp+10h] [rbp-1038h] BYREF
int v11; // [rsp+20h] [rbp-1028h]
int buf; // [rsp+30h] [rbp-1018h] BYREF
__int16 v13; // [rsp+34h] [rbp-1014h]
char v14; // [rsp+36h] [rbp-1012h]

v1 = recv(fd, &buf, 0x1000uLL, 0);
if ( v1 <= 0 )
{
ERROR("recv() failed");
result = close(fd);
}
else
{
v2 = v1;
timer = time(0LL);
v3 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v3);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mfirst recv start\n\n", s);
printf("%s", (const char *)&buf);
timer = time(0LL);
v4 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v4);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mrecv finished\n\n", s);
if ( strstr((const char *)&buf, "HTTP/1.") )
{
if ( (_WORD)buf == 17735 && BYTE2(buf) == 84 )
{
strtok((char *)&buf, " \t\n");
v6 = strtok(0LL, " \t");
v7 = v6;
if ( v6 )
{
if ( strcmp(v6, "/favicon.ico") && strcmp(v6, "/twitter-logo-1.png") )
v7 = "/BASEHTML.html";
}
else
{
v7 = "/BASEHTML.html";
}
handle_http_get(fd, v7);
}
else if ( buf == 1414745936 && v13 == 12064 && v14 == 32 )
{
v11 = 0;
*(_OWORD *)s = 0LL;
v8 = get_twitter_id(fd, (char *)&buf, s, v2);
if ( v8 )
handle_http_post(fd, (__int64)v8);
}
}
else
{
send(fd, "HTTP/1.0 400 Bad Request\r\n\r\n", 0x1CuLL, 0);
}
shutdown(fd, 2);
result = close(fd);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(int fd)
{
ssize_t v1; // rax
__int64 v2; // r12
struct tm *v3; // rax
struct tm *v4; // rax
int result; // eax
char *v6; // rax
const char *v7; // r8
char *v8; // rsi
time_t timer; // [rsp+8h] [rbp-1040h] BYREF
char s[16]; // [rsp+10h] [rbp-1038h] BYREF
int v11; // [rsp+20h] [rbp-1028h]
int buf; // [rsp+30h] [rbp-1018h] BYREF
__int16 v13; // [rsp+34h] [rbp-1014h]
char v14; // [rsp+36h] [rbp-1012h]

v1 = recv(fd, &buf, 0x1000uLL, 0);
if ( v1 <= 0 )
{
ERROR("recv() failed");
result = close(fd);
}
else
{
v2 = v1;
timer = time(0LL);
v3 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v3);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mfirst recv start\n\n", s);
printf("%s", (const char *)&buf);
timer = time(0LL);
v4 = localtime(&timer);
strftime(s, 0x14uLL, "%F %T", v4);
fprintf(stderr, "\x1B[01;32m %s INFO: \x1B[0mrecv finished\n\n", s);
if ( strstr((const char *)&buf, "HTTP/1.") )
{
if ( (_WORD)buf == 17735 && BYTE2(buf) == 84 )
{
strtok((char *)&buf, " \t\n");
v6 = strtok(0LL, " \t");
v7 = v6;
if ( v6 )
{
if ( strcmp(v6, "/favicon.ico") && strcmp(v6, "/twitter-logo-1.png") )
v7 = "/BASEHTML.html";
}
else
{
v7 = "/BASEHTML.html";
}
func1(fd, v7);
}
else if ( buf == 1414745936 && v13 == 12064 && v14 == 32 )
{
v11 = 0;
*(_OWORD *)s = 0LL;
v8 = func2(fd, (char *)&buf, s, v2);
if ( v8 )
func3(fd, (__int64)v8);
}
}
else
{
send(fd, "HTTP/1.0 400 Bad Request\r\n\r\n", 0x1CuLL, 0);
}
shutdown(fd, 2);
result = close(fd);
}
return result;
}

original_code:
void HandleTCPClient(int clntSocket) {
    char buffer[BUFSIZE];
    ssize_t numBytesRcvd = recv(clntSocket, buffer, BUFSIZE, 0);
    if (numBytesRcvd <= 0){
        ERROR("recv() failed");
        close(clntSocket);
        return;
    }
    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" "first recv start\n" "\n", timestr);}while(0);
    printf("%s",buffer);
    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" "recv finished\n" "\n", timestr);}while(0);
    if (strstr(buffer, "HTTP/1.") == ((void *)0))
    {
        send(clntSocket, "HTTP/1.0 400 Bad Request\r\n\r\n", 28, 0);
    } else if (strncmp(buffer, "GET", 3) == 0) {
        char *req_file = strtok (buffer, " \t\n");
        req_file = strtok (((void *)0), " \t");
        if (req_file == ((void *)0) || (strcmp(req_file, "/favicon.ico") && strcmp(req_file, "/twitter-logo-1.png"))) {
            req_file = "/BASEHTML.html";
        }
        handle_http_get(clntSocket, req_file);
    } else if (strncmp(buffer, "POST / ", 7) == 0){
            char friend[20] = {'\0',};
            char *friend_id = get_twitter_id(clntSocket, buffer, friend, numBytesRcvd);
            if(friend_id)
                handle_http_post(clntSocket, friend_id);
    }
    shutdown(clntSocket, SHUT_RDWR);
    close(clntSocket);
}

canonical_original_code:
void HandleTCPClient(int clntSocket) {
    char buffer[-1];
    long numBytesRcvd = recv(clntSocket, buffer, BUFSIZE, 0);
    if (numBytesRcvd <= 0){
        ERROR("recv() failed");
        close(clntSocket);
        return;
    }
    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" "first recv start\n" "\n", timestr);}while(0);
    printf("%s",buffer);
    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" "recv finished\n" "\n", timestr);}while(0);
    if (strstr(buffer, "HTTP/1.") == ((void *)0))
    {
        send(clntSocket, "HTTP/1.0 400 Bad Request\r\n\r\n", 28, 0);
    } else if (strncmp(buffer, "GET", 3) == 0) {
        char *req_file = strtok (buffer, " \t\n");
        req_file = strtok (((void *)0), " \t");
        if (req_file == ((void *)0) || (strcmp(req_file, "/favicon.ico") && strcmp(req_file, "/twitter-logo-1.png"))) {
            req_file = "/BASEHTML.html";
        }
        handle_http_get(clntSocket, req_file);
    } else if (strncmp(buffer, "POST / ", 7) == 0){
            char friend[20] = {'\0',};
            char *friend_id = get_twitter_id(clntSocket, buffer, friend, numBytesRcvd);
            if(friend_id)
                handle_http_post(clntSocket, friend_id);
    }
    shutdown(clntSocket, SHUT_RDWR);
    close(clntSocket);
}

variable_types: clntSocket int

variable_types: now long

variable_types:
timestr
char [20]

variable_types:
friend
char [20]


WriteMemoryCallback

original_code:
static size_t
WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) {
  size_t realsize = size * nmemb;
  struct MemoryStruct *mem = (struct MemoryStruct *)data;
  mem->data = (char *)xrealloc(mem->data, mem->size + realsize + 1);
  if (mem->data) {
    memcpy(&(mem->data[mem->size]), ptr, realsize);
    mem->size += realsize;
    mem->data[mem->size] = 0;
  }
  return realsize;
}

canonical_original_code:
static unsigned long WriteMemoryCallback(void *ptr, unsigned long size, unsigned long nmemb, void *data) {
  unsigned long realsize = size * nmemb;
  struct MemoryStruct *mem = (struct MemoryStruct *)data;
  mem->data = (char *)xrealloc(mem->data, mem->size + realsize + 1);
  if (mem->data) {
    memcpy(&(mem->data[mem->size]), ptr, realsize);
    mem->size += realsize;
    mem->data[mem->size] = 0;
  }
  return realsize;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
data
void *

variable_types:
realsize
unsigned long

variable_types: struct MemoryStruct { char *data; unsigned long size; unsigned long start_size; void (*callback)(void *, int, unsigned long, unsigned long); void *callback_data; } *

return_type: unsigned long


decompiled_code:
const char *__fastcall access_token_request_data(const char *a1)
{
char *v1; // rbp
const char *v2; // rax
const char *v3; // r12
__int128 v5[9]; // [rsp+0h] [rbp-98h] BYREF

v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
v5[4] = 0LL;
v5[5] = 0LL;
v5[6] = 0LL;
v5[7] = 0LL;
snprintf(
(char *)v5,
0x80uLL,
"https://api.twitter.com/1.1/friendships/lookup.json?screen_name=%s,%s",
*(const char **)(conf + 8LL),
a1);
v1 = (char *)oauth_sign_url2(
v5,
0LL,
0LL,
0LL,
*(_QWORD *)(conf + 16LL),
*(_QWORD *)(conf + 24LL),
*(_QWORD *)(conf + 32LL),
*(_QWORD *)(conf + 40LL));
printf("request URL:%s\n\n", v1);
v2 = (const char *)curl_http_get((__int64)v1);
v3 = v2;
if ( v2 )
{
printf("HTTP-reply: %s\n", v2);
if ( !v1 )
return v3;
LABEL_3:
free(v1);
return v3;
}
puts("HTTP request for an oauth request-token failed.");
if ( v1 )
goto LABEL_3;
return 0LL;
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1)
{
char *v1; // rbp
const char *v2; // rax
const char *v3; // r12
__int128 v5[9]; // [rsp+0h] [rbp-98h] BYREF

v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v5[3] = 0LL;
v5[4] = 0LL;
v5[5] = 0LL;
v5[6] = 0LL;
v5[7] = 0LL;
snprintf(
(char *)v5,
0x80uLL,
"https://api.twitter.com/1.1/friendships/lookup.json?screen_name=%s,%s",
*(const char **)(conf + 8LL),
a1);
v1 = (char *)oauth_sign_url2(
v5,
0LL,
0LL,
0LL,
*(_QWORD *)(conf + 16LL),
*(_QWORD *)(conf + 24LL),
*(_QWORD *)(conf + 32LL),
*(_QWORD *)(conf + 40LL));
printf("request URL:%s\n\n", v1);
v2 = (const char *)func0((__int64)v1);
v3 = v2;
if ( v2 )
{
printf("HTTP-reply: %s\n", v2);
if ( !v1 )
return v3;
LABEL_3:
free(v1);
return v3;
}
puts("HTTP request for an oauth request-token failed.");
if ( v1 )
goto LABEL_3;
return 0LL;
}

original_code:
static char* access_token_request_data(char *username) {
    char *req_url = ((void *)0);
    char *reply;
    char friendship_url[MAXSTRINGLENGTH] = {'\0',};
    snprintf(friendship_url, MAXSTRINGLENGTH, "https://api.twitter.com/1.1/friendships/lookup.json?screen_name=%s,%s", conf->TwitterID, username);
    req_url = oauth_sign_url2(friendship_url, ((void *)0), OA_HMAC,
                              ((void *)0), conf->CONSUMER_KEY , conf->CONSUMER_SECRET ,
                              conf->OAUTH_TOKEN , conf->OAUTH_TOKEN_SECRET);
    printf("request URL:%s\n\n", req_url);
    reply = curl_http_get(req_url);
    if (!reply)
        printf("HTTP request for an oauth request-token failed.\n");
    else {
        printf("HTTP-reply: %s\n", reply);
    }
    if(req_url) free(req_url);
    if(reply) return reply;
    else return ((void *)0);
}

canonical_original_code:
static char *access_token_request_data(char *username) {
    char *req_url = ((void *)0);
    char *reply;
    char friendship_url[-1] = {'\0',};
    snprintf(friendship_url, MAXSTRINGLENGTH, "https://api.twitter.com/1.1/friendships/lookup.json?screen_name=%s,%s", conf->TwitterID, username);
    req_url = oauth_sign_url2(friendship_url, ((void *)0), OA_HMAC,
                              ((void *)0), conf->CONSUMER_KEY , conf->CONSUMER_SECRET ,
                              conf->OAUTH_TOKEN , conf->OAUTH_TOKEN_SECRET);
    printf("request URL:%s\n\n", req_url);
    reply = curl_http_get(req_url);
    if (!reply)
        printf("HTTP request for an oauth request-token failed.\n");
    else {
        printf("HTTP-reply: %s\n", reply);
    }
    if(req_url) free(req_url);
    if(reply) return reply;
    else return ((void *)0);
}

variable_types:
username
char *

variable_types:
reply
char *


decompiled_code:
bool __fastcall parser_friendship_json(char *s)
{
char *v1; // rbx
char *v2; // rdi
bool result; // al
char *v4; // rdi
char *v5; // rax

if ( !s )
return 0;
v1 = strchr(s, 123);
v2 = strrchr(s, 123);
result = v1 != v2 && v1 != 0LL;
if ( result )
{
v4 = strstr(v2, "connections");
if ( v4 )
{
v5 = strchr(v4, 58);
result = memcmp(strchr(v5, 34), "\"none", 5uLL) != 0;
}
else
{
result = 0;
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func3(char *s)
{
char *v1; // rbx
char *v2; // rdi
bool result; // al
char *v4; // rdi
char *v5; // rax

if ( !s )
return 0;
v1 = strchr(s, 123);
v2 = strrchr(s, 123);
result = v1 != v2 && v1 != 0LL;
if ( result )
{
v4 = strstr(v2, "connections");
if ( v4 )
{
v5 = strchr(v4, 58);
result = memcmp(strchr(v5, 34), "\"none", 5uLL) != 0;
}
else
{
result = 0;
}
}
return result;
}

original_code:
static _Bool parser_friendship_json(char *friendship) {
    if (!friendship) return 0;
    char *first_front = strchr(friendship,'{');
    char *second_front = strrchr(friendship,'{');
    if(first_front && first_front != second_front ) {
        char *connections = strstr(second_front,"connections");
        if(connections == ((void *)0)) {
            return 0;
        }
        char *colon = strchr(connections,':');
        if(strncmp(strchr(colon,'"'),"\"none",5) == 0)
            return 0;
        else
            return 1;
    }else {
        return 0;
    }
}

variable_types:
friendship
char *

variable_types:
connections
char *

variable_types:
colon
char *