usage

decompiled_code:
void __noreturn usage()
{
msg_Raw(
0LL,
"Usage: multicat_validate [-k <start time>] [-r <file duration>] [-W <tolerance>] [-m <payload size>] <input directory>");
msg_Raw(0LL, " -k: start at the given position (in 27 MHz units, negative = from the end)");
msg_Raw(0LL, " -r: in directory mode, rotate file after this duration (default: 97200000000 ticks = 1 hour)");
msg_Raw(
0LL,
" -W: maximum tolerated wait time before the forthcoming packet (by default: 27000000 ticks = 1 second)");
msg_Raw(0LL, " -m: size of the payload chunk, excluding optional RTP header (default 1316)");
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
msg_Raw(
0LL,
"Usage: multicat_validate [-k <start time>] [-r <file duration>] [-W <tolerance>] [-m <payload size>] <input directory>");
msg_Raw(0LL, " -k: start at the given position (in 27 MHz units, negative = from the end)");
msg_Raw(0LL, " -r: in directory mode, rotate file after this duration (default: 97200000000 ticks = 1 hour)");
msg_Raw(
0LL,
" -W: maximum tolerated wait time before the forthcoming packet (by default: 27000000 ticks = 1 second)");
msg_Raw(0LL, " -m: size of the payload chunk, excluding optional RTP header (default 1316)");
exit(1);
}

original_code:
static void usage(void)
{
    msg_Raw( ((void *)0), "Usage: multicat_validate [-k <start time>] [-r <file duration>] [-W <tolerance>] [-m <payload size>] <input directory>" );
    msg_Raw( ((void *)0), "    -k: start at the given position (in 27 MHz units, negative = from the end)" );
    msg_Raw( ((void *)0), "    -r: in directory mode, rotate file after this duration (default: 97200000000 ticks = 1 hour)" );
    msg_Raw( ((void *)0), "    -W: maximum tolerated wait time before the forthcoming packet (by default: 27000000 ticks = 1 second)" );
    msg_Raw( ((void *)0), "    -m: size of the payload chunk, excluding optional RTP header (default 1316)" );
    exit(1);
}

canonical_original_code:
static void usage()
{
    msg_Raw( ((void *)0), "Usage: multicat_validate [-k <start time>] [-r <file duration>] [-W <tolerance>] [-m <payload size>] <input directory>" );
    msg_Raw( ((void *)0), "    -k: start at the given position (in 27 MHz units, negative = from the end)" );
    msg_Raw( ((void *)0), "    -r: in directory mode, rotate file after this duration (default: 97200000000 ticks = 1 hour)" );
    msg_Raw( ((void *)0), "    -W: maximum tolerated wait time before the forthcoming packet (by default: 27000000 ticks = 1 second)" );
    msg_Raw( ((void *)0), "    -m: size of the payload chunk, excluding optional RTP header (default 1316)" );
    exit(1);
}


HandleSTC

decompiled_code:
int __fastcall HandleSTC(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx

while ( 1 )
{
v1 = real_Date();
v2 = i_delay + a1 - v1;
if ( i_tolerance >= v2 )
break;
if ( b_status )
{
puts("0");
b_status = 0;
}
real_Sleep(v2 - i_tolerance);
}
if ( !b_status )
LODWORD(v1) = puts("1");
b_status = 1;
if ( v2 > 0 )
LODWORD(v1) = real_Sleep(v2);
return v1;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx

while ( 1 )
{
v1 = real_Date();
v2 = i_delay + a1 - v1;
if ( i_tolerance >= v2 )
break;
if ( b_status )
{
puts("0");
b_status = 0;
}
real_Sleep(v2 - i_tolerance);
}
if ( !b_status )
LODWORD(v1) = puts("1");
b_status = 1;
if ( v2 > 0 )
LODWORD(v1) = real_Sleep(v2);
return v1;
}

original_code:
static void HandleSTC( uint64_t i_stc )
{
    uint64_t i_wall;
    int64_t i_sleep;
retry:
    i_wall = real_Date() - i_delay;
    i_sleep = i_stc - i_wall;
    if ( i_sleep > i_tolerance )
    {
        if ( b_status )
        {
            printf( "0\n" );
            b_status = 0;
        }
        real_Sleep( i_sleep - i_tolerance );
        goto retry;
    }
    if ( !b_status )
        printf( "1\n" );
    b_status = 1;
    if ( i_sleep > 0 )
        real_Sleep( i_sleep );
}

canonical_original_code:
static void HandleSTC(unsigned long i_stc)
{
    unsigned long i_wall;
    long i_sleep;
retry:
    i_wall = real_Date() - i_delay;
    i_sleep = i_stc - i_wall;
    if ( i_sleep > i_tolerance )
    {
        if ( b_status )
        {
            printf( "0\n" );
            b_status = 0;
        }
        real_Sleep( i_sleep - i_tolerance );
        goto retry;
    }
    if ( !b_status )
        printf( "1\n" );
    b_status = 1;
    if ( i_sleep > 0 )
        real_Sleep( i_sleep );
}

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rbx
int v7; // eax
__int64 v8; // rax
int v9; // edi
unsigned __int64 v10; // [rsp+0h] [rbp-28h] BYREF
FILE *stream[4]; // [rsp+8h] [rbp-20h] BYREF

setvbuf(stdout, 0LL, 1, 0LL);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "k:r:W:m:h");
if ( v3 == -1 )
{
if ( optind >= argc )
usage();
psz_dir_name = (__int64)argv[optind];
puts("0");
v4 = i_delay;
if ( i_delay <= 0 )
{
i_delay = -i_delay;
v5 = real_Date() - i_delay;
}
else
{
v5 = i_delay;
i_delay = real_Date() - v4;
}
i_dir_file = GetDirFile(i_rotate_size, v5);
v6 = LookupDirAuxFile(psz_dir_name, i_dir_file, v5, i_asked_payload_size);
if ( v6 < 0 )
{
v6 = LookupDirAuxFile(psz_dir_name, ++i_dir_file, v5, i_asked_payload_size);
if ( v6 < 0 )
{
msg_Err(0LL, "position not found");
exit(1);
}
}
v7 = OpenDirFile(psz_dir_name, i_dir_file, 1LL, i_asked_payload_size, stream);
close(v7);
fseeko64(stream[0], 8 * v6, 0);
while ( 1 )
{
if ( fread(&v10, 8uLL, 1uLL, stream[0]) != 1 )
{
fclose(stream[0]);
v9 = OpenDirFile(psz_dir_name, ++i_dir_file, 1LL, i_asked_payload_size, stream);
if ( v9 < 0 )
{
msg_Err(0LL, "end of files reached");
exit(1);
}
close(v9);
}
v8 = FromSTC(&v10);
HandleSTC(v8);
}
}
if ( v3 != 109 )
break;
i_asked_payload_size = strtol(optarg, 0LL, 0);
}
if ( v3 > 109 )
break;
if ( v3 == 87 )
{
i_tolerance = strtoull(optarg, 0LL, 0);
}
else
{
if ( v3 != 107 )
goto LABEL_12;
i_delay = strtoull(optarg, 0LL, 0);
}
}
if ( v3 != 114 )
LABEL_12:
usage();
i_rotate_size = strtoull(optarg, 0LL, 0);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rbx
int v7; // eax
__int64 v8; // rax
int v9; // edi
unsigned __int64 v10; // [rsp+0h] [rbp-28h] BYREF
FILE *stream[4]; // [rsp+8h] [rbp-20h] BYREF

setvbuf(stdout, 0LL, 1, 0LL);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "k:r:W:m:h");
if ( v3 == -1 )
{
if ( optind >= argc )
func1();
psz_dir_name = (__int64)argv[optind];
puts("0");
v4 = i_delay;
if ( i_delay <= 0 )
{
i_delay = -i_delay;
v5 = real_Date() - i_delay;
}
else
{
v5 = i_delay;
i_delay = real_Date() - v4;
}
i_dir_file = GetDirFile(i_rotate_size, v5);
v6 = LookupDirAuxFile(psz_dir_name, i_dir_file, v5, i_asked_payload_size);
if ( v6 < 0 )
{
v6 = LookupDirAuxFile(psz_dir_name, ++i_dir_file, v5, i_asked_payload_size);
if ( v6 < 0 )
{
msg_Err(0LL, "position not found");
exit(1);
}
}
v7 = OpenDirFile(psz_dir_name, i_dir_file, 1LL, i_asked_payload_size, stream);
close(v7);
fseeko64(stream[0], 8 * v6, 0);
while ( 1 )
{
if ( fread(&v10, 8uLL, 1uLL, stream[0]) != 1 )
{
fclose(stream[0]);
v9 = OpenDirFile(psz_dir_name, ++i_dir_file, 1LL, i_asked_payload_size, stream);
if ( v9 < 0 )
{
msg_Err(0LL, "end of files reached");
exit(1);
}
close(v9);
}
v8 = func0(&v10);
func2(v8);
}
}
if ( v3 != 109 )
break;
i_asked_payload_size = strtol(optarg, 0LL, 0);
}
if ( v3 > 109 )
break;
if ( v3 == 87 )
{
i_tolerance = strtoull(optarg, 0LL, 0);
}
else
{
if ( v3 != 107 )
goto LABEL_12;
i_delay = strtoull(optarg, 0LL, 0);
}
}
if ( v3 != 114 )
LABEL_12:
func1();
i_rotate_size = strtoull(optarg, 0LL, 0);
}
}

original_code:
int main( int i_argc, char **pp_argv )
{
    int64_t i_wanted;
    off_t i_ret;
    if ( i_argc != 3 )
    {
        msg_Err( ((void *)0), "Usage: offsets <aux file> <27 MHz timestamp>" );
        msg_Err( ((void *)0), "[offsets is deprecated, see multicat instead]" );
        exit(1);
    }
    i_wanted = strtoll( pp_argv[2], ((void *)0), 0 );
    if ( !i_wanted )
    {
        printf( "0\n" );
        exit(0);
    }
    i_ret = LookupAuxFile( pp_argv[1], i_wanted, 0 );
    if ( i_ret == -1 )
        exit(1);
    printf( "%jd\n", (intmax_t)i_ret );
    exit(0);
}

canonical_original_code:
int main(int i_argc, char **pp_argv)
{
    long i_wanted;
    long i_ret;
    if ( i_argc != 3 )
    {
        msg_Err( ((void *)0), "Usage: offsets <aux file> <27 MHz timestamp>" );
        msg_Err( ((void *)0), "[offsets is deprecated, see multicat instead]" );
        exit(1);
    }
    i_wanted = strtoll( pp_argv[2], ((void *)0), 0 );
    if ( !i_wanted )
    {
        printf( "0\n" );
        exit(0);
    }
    i_ret = LookupAuxFile( pp_argv[1], i_wanted, 0 );
    if ( i_ret == -1 )
        exit(1);
    printf( "%jd\n", (long)i_ret );
    exit(0);
}

return_type: int


sliceStr

decompiled_code:
__int64 __fastcall sliceStr(char *s, __int64 a2, __int64 a3)
{
__int64 v3; // r14
char *v4; // r12
char *v5; // rax
char *v6; // r15
int v7; // ebp
size_t v8; // rax
int v9; // ebx

v3 = a3 / 2;
v4 = (char *)(a2 + (int)(a3 / 2));
v5 = strchr(s, *v4);
if ( v5 )
{
v6 = v5;
v7 = 0;
do
{
v8 = strlen(v6);
v9 = v8;
if ( strncmp(v6, &v4[v7], v8) )
break;
v7 += v9;
v6 = strchr(s, v4[v7]);
}
while ( v6 );
}
else
{
v7 = 0;
}
return (unsigned int)(v7 + v3);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s, __int64 a2, __int64 a3)
{
__int64 v3; // r14
char *v4; // r12
char *v5; // rax
char *v6; // r15
int v7; // ebp
size_t v8; // rax
int v9; // ebx

v3 = a3 / 2;
v4 = (char *)(a2 + (int)(a3 / 2));
v5 = strchr(s, *v4);
if ( v5 )
{
v6 = v5;
v7 = 0;
do
{
v8 = strlen(v6);
v9 = v8;
if ( strncmp(v6, &v4[v7], v8) )
break;
v7 += v9;
v6 = strchr(s, v4[v7]);
}
while ( v6 );
}
else
{
v7 = 0;
}
return (unsigned int)(v7 + v3);
}

original_code:
int sliceStr(char *str, char *fileStr, long file_size){
 int mid= file_size/2;
 char *ptr= &fileStr[mid];
 int i=0,test=0;
 char* pch=strchr(str, ptr[i]);
 while(pch!=((void *)0)){
  test= strncmp(pch, &ptr[i], strlen(pch));
  if(test == 0){
   i += strlen(pch);
   pch=strchr(str, ptr[i]);
  }else{
   break;
  }
 }
 return mid+i;
}

canonical_original_code:
int sliceStr(char *str, char *fileStr, long file_size){
 int mid = file_size/2;
 char *ptr = &fileStr[mid];
 int i = 0; int test = 0;
 char *pch = strchr(str, ptr[i]);
 while(pch!=((void *)0)){
  test= strncmp(pch, &ptr[i], strlen(pch));
  if(test == 0){
   i += strlen(pch);
   pch=strchr(str, ptr[i]);
  }else{
   break;
  }
 }
 return mid+i;
}

variable_types:
str
char *

variable_types:
fileStr
char *

variable_types: mid int

variable_types:
ptr
char *

variable_types: i int

variable_types: test int

variable_types:
pch
char *


regexFind

decompiled_code:
void *__fastcall regexFind(void *a1)
{
runRegex(*((char **)a1 + 1), *(char **)a1, *((_DWORD **)a1 + 2));
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func9(void *a1)
{
func8(*((char **)a1 + 1), *(char **)a1, *((_DWORD **)a1 + 2));
return 0LL;
}

original_code:
void *regexFind(void *context){
 struct threadData *tdata = context;
 char *str= tdata->str;
 char *searchStr= tdata->searchStr;
 int *count= tdata->count;
 runRegex(str,searchStr,count);
    return ((void *)0);
}

canonical_original_code:
void *regexFind(void *context){
 struct threadData *tdata = context;
 char *str = tdata->str;
 char *searchStr = tdata->searchStr;
 int *count = tdata->count;
 runRegex(str,searchStr,count);
    return ((void *)0);
}

variable_types:
context
void *

variable_types: struct threadData { char *searchStr; char *str; int *count; } *

variable_types:
searchStr
char *

variable_types:
count
int *

return_type: void *


printmodes

repo: wxue/UnixTools

decompiled_code:
int __fastcall printmodes(__int64 a1)
{
char v2[18]; // [rsp+6h] [rbp-12h] BYREF

strmode(a1, v2);
return printf("%s", v2);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
char v2[18]; // [rsp+6h] [rbp-12h] BYREF

strmode(a1, v2);
return printf("%s", v2);
}

original_code:
void
printmodes(mode_t md)
{
  char buf[10];
  (void)strmode(md, buf);
  printf("%s", buf);
}

canonical_original_code:
void printmodes(unsigned int md)
{
  char buf[10];
  (void)strmode(md, buf);
  printf("%s", buf);
}

variable_types:
md
unsigned int

variable_types:
buf
char [10]


getownername

decompiled_code:
char *__fastcall getownername(__uid_t a1)
{
struct passwd *v1; // rax

v1 = getpwuid(a1);
if ( !v1 )
{
fprintf(stderr, "Failed to get owner name from uid: %d\n", a1);
exit(1);
}
return v1->pw_name;
}

canonical_decompiled_code:
char *__fastcall func1(__uid_t a1)
{
struct passwd *v1; // rax

v1 = getpwuid(a1);
if ( !v1 )
{
fprintf(stderr, "Failed to get owner name from uid: %d\n", a1);
exit(1);
}
return v1->pw_name;
}

original_code:
char*
getownername(uid_t uid)
{
  struct passwd * pwdp;
  if ((pwdp = getpwuid(uid)) == ((void *)0)) {
    fprintf(stderr, "Failed to get owner name from uid: %d\n",
            uid);
    exit(1);
  }
  else
    return(pwdp->pw_name);
}

canonical_original_code:
char *getownername(unsigned int uid)
{
  struct passwd *pwdp;
  if ((pwdp = getpwuid(uid)) == ((void *)0)) {
    fprintf(stderr, "Failed to get owner name from uid: %d\n",
            uid);
    exit(1);
  }
  else
    return(pwdp->pw_name);
}

variable_types:
uid
unsigned int

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

return_type: char *


getgroupname

decompiled_code:
char *__fastcall getgroupname(__gid_t a1)
{
struct group *v1; // rax

v1 = getgrgid(a1);
if ( !v1 )
{
fprintf(stderr, "Failed to get group name from gid: %-8d\n", a1);
exit(1);
}
return v1->gr_name;
}

canonical_decompiled_code:
char *__fastcall func2(__gid_t a1)
{
struct group *v1; // rax

v1 = getgrgid(a1);
if ( !v1 )
{
fprintf(stderr, "Failed to get group name from gid: %-8d\n", a1);
exit(1);
}
return v1->gr_name;
}

original_code:
char*
getgroupname(gid_t gid)
{
  struct group *grp;
  if ((grp = getgrgid(gid)) == ((void *)0)) {
    fprintf(stderr, "Failed to get group name from gid: %-8d\n",
            gid);
    exit(1);
  }
  else
    return(grp->gr_name);
}

canonical_original_code:
char *getgroupname(unsigned int gid)
{
  struct group *grp;
  if ((grp = getgrgid(gid)) == ((void *)0)) {
    fprintf(stderr, "Failed to get group name from gid: %-8d\n",
            gid);
    exit(1);
  }
  else
    return(grp->gr_name);
}

variable_types:
gid
unsigned int

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *


printtime

decompiled_code:
int __fastcall printtime(time_t a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-60h] BYREF
char s[88]; // [rsp+10h] [rbp-58h] BYREF

timer = a1;
v1 = localtime(&timer);
strftime(s, 0x50uLL, "%b %d %H:%M ", v1);
return printf("%s ", s);
}

canonical_decompiled_code:
int __fastcall func3(time_t a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-60h] BYREF
char s[88]; // [rsp+10h] [rbp-58h] BYREF

timer = a1;
v1 = localtime(&timer);
strftime(s, 0x50uLL, "%b %d %H:%M ", v1);
return printf("%s ", s);
}

original_code:
void
printtime(time_t ptime)
{
  struct tm *ts;
  char buf[80];
  ts = localtime(&ptime);
  strftime(buf, sizeof(buf), "%b %d %H:%M ", ts);
  printf("%s ", buf);
}

canonical_original_code:
void printtime(long ptime)
{
  struct tm *ts;
  char buf[80];
  ts = localtime(&ptime);
  strftime(buf, sizeof(buf), "%b %d %H:%M ", ts);
  printf("%s ", buf);
}

variable_types: ptime long

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:
buf
char [80]


printhsize

decompiled_code:
int __fastcall printhsize(__int64 a1)
{
if ( (unsigned __int64)(a1 + 0xFFFFFFFFFFFFFFFLL) > 0x1FFFFFFFFFFFFFFELL )
return printf("%4lldE ", a1 / 0x1000000000000000LL);
if ( (unsigned __int64)(a1 + 0x3FFFFFFFFFFFFLL) > 0x7FFFFFFFFFFFELL )
return printf("%4lldP ", a1 / 0x4000000000000LL);
if ( (unsigned __int64)(a1 + 0xFFFFFFFFFFLL) > 0x1FFFFFFFFFELL )
return printf("%4lldT ", a1 / 0x10000000000LL);
if ( (unsigned __int64)(a1 + 0x3FFFFFFF) > 0x7FFFFFFE )
return printf("%4lldG ", a1 / 0x40000000);
if ( (unsigned __int64)(a1 + 0xFFFFF) > 0x1FFFFE )
return printf("%4lldM ", a1 / 0x100000);
if ( (unsigned __int64)(a1 + 1023) <= 0x7FE )
return printf("%4lldB ", a1);
return printf("%4lldK ", a1 / 1024);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
if ( (unsigned __int64)(a1 + 0xFFFFFFFFFFFFFFFLL) > 0x1FFFFFFFFFFFFFFELL )
return printf("%4lldE ", a1 / 0x1000000000000000LL);
if ( (unsigned __int64)(a1 + 0x3FFFFFFFFFFFFLL) > 0x7FFFFFFFFFFFELL )
return printf("%4lldP ", a1 / 0x4000000000000LL);
if ( (unsigned __int64)(a1 + 0xFFFFFFFFFFLL) > 0x1FFFFFFFFFELL )
return printf("%4lldT ", a1 / 0x10000000000LL);
if ( (unsigned __int64)(a1 + 0x3FFFFFFF) > 0x7FFFFFFE )
return printf("%4lldG ", a1 / 0x40000000);
if ( (unsigned __int64)(a1 + 0xFFFFF) > 0x1FFFFE )
return printf("%4lldM ", a1 / 0x100000);
if ( (unsigned __int64)(a1 + 1023) <= 0x7FE )
return printf("%4lldB ", a1);
return printf("%4lldK ", a1 / 1024);
}

variable_types: size long


printksize

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

if ( a1 && (unsigned __int64)(a1 + 1023) <= 0x7FE )
result = printf(" 1K ");
else
result = printf("%4lldK ", a1 / 1024);
return result;
}

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

if ( a1 && (unsigned __int64)(a1 + 1023) <= 0x7FE )
result = printf(" 1K ");
else
result = printf("%4lldK ", a1 / 1024);
return result;
}

original_code:
void
printksize(off_t size)
{
  if(size != 0 && size/1024 == 0)
    printf("   1K ");
  else
    printf("%4lldK ", (long long)size/1024);
}

canonical_original_code:
void printksize(long size)
{
  if(size != 0 && size/1024 == 0)
    printf("   1K ");
  else
    printf("%4lldK ", (long long)size/1024);
}


maxprint

decompiled_code:
int __fastcall maxprint(__int64 a1, int a2)
{
if ( (unsigned int)(a2 + 999999999) > 0x773593FE )
return printf("%10lld ", a1);
if ( (unsigned int)(a2 + 99999999) > 0xBEBC1FE )
return printf("%9lld ", a1);
if ( (unsigned int)(a2 + 9999999) > 0x1312CFE )
return printf("%8lld ", a1);
if ( (unsigned int)(a2 + 999999) > 0x1E847E )
return printf("%7lld ", a1);
if ( (unsigned int)(a2 + 99999) > 0x30D3E )
return printf("%6lld ", a1);
if ( (unsigned int)(a2 + 9999) > 0x4E1E )
return printf("%5lld ", a1);
if ( (unsigned int)(a2 + 999) > 0x7CE )
return printf("%4lld ", a1);
if ( (unsigned int)(a2 + 99) <= 0xC6 )
return printf("%2lld ", a1);
return printf("%3lld ", a1);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, int a2)
{
if ( (unsigned int)(a2 + 999999999) > 0x773593FE )
return printf("%10lld ", a1);
if ( (unsigned int)(a2 + 99999999) > 0xBEBC1FE )
return printf("%9lld ", a1);
if ( (unsigned int)(a2 + 9999999) > 0x1312CFE )
return printf("%8lld ", a1);
if ( (unsigned int)(a2 + 999999) > 0x1E847E )
return printf("%7lld ", a1);
if ( (unsigned int)(a2 + 99999) > 0x30D3E )
return printf("%6lld ", a1);
if ( (unsigned int)(a2 + 9999) > 0x4E1E )
return printf("%5lld ", a1);
if ( (unsigned int)(a2 + 999) > 0x7CE )
return printf("%4lld ", a1);
if ( (unsigned int)(a2 + 99) <= 0xC6 )
return printf("%2lld ", a1);
return printf("%3lld ", a1);
}

original_code:
void
maxprint(long long value, int maxvalue)
{
  if(maxvalue/100000000000)
    printf("%12lld ", value);
  else if(maxvalue/10000000000)
    printf("%11lld ", value);
  else if(maxvalue/1000000000)
    printf("%10lld ", value);
  else if(maxvalue/100000000)
    printf("%9lld ", value);
  else if(maxvalue/10000000)
    printf("%8lld ", value);
  else if(maxvalue/1000000)
    printf("%7lld ", value);
  else if(maxvalue/100000)
    printf("%6lld ", value);
  else if(maxvalue/10000)
    printf("%5lld ", value);
  else if(maxvalue/1000)
    printf("%4lld ", value);
  else if(maxvalue/100)
    printf("%3lld ", value);
  else
    printf("%2lld ", value);
}

variable_types:
value
long long

variable_types: maxvalue int


maxlenprint

decompiled_code:
void __fastcall maxlenprint(char *src, int a2)
{
char *v2; // rax
char *v3; // rbp
int v4; // ebx

v2 = (char *)malloc(a2);
if ( !v2 )
{
fwrite("malloc error!\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
v3 = v2;
v4 = a2 - strlen(src);
strcpy(v3, src);
for ( ; v4; --v4 )
*(_WORD *)&v3[strlen(v3)] = 32;
printf("%s ", v3);
free(v3);
}

canonical_decompiled_code:
void __fastcall func8(char *src, int a2)
{
char *v2; // rax
char *v3; // rbp
int v4; // ebx

v2 = (char *)malloc(a2);
if ( !v2 )
{
fwrite("malloc error!\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
v3 = v2;
v4 = a2 - strlen(src);
strcpy(v3, src);
for ( ; v4; --v4 )
*(_WORD *)&v3[strlen(v3)] = 32;
printf("%s ", v3);
free(v3);
}

original_code:
void
maxlenprint(char* value, int maxlen)
{
  char* p;
  int lack;
  p=(char*)malloc(maxlen*sizeof(char));
  if(p != ((void *)0)) {
    lack = maxlen - strlen(value);
    strcpy(p, value);
    while(lack != 0) {
      strcat(p, " ");
      lack--;
    }
    printf("%s ", p);
  }
  else {
    fprintf(stderr, "malloc error!\n");
    exit(1);
  }
  free(p);
  p=((void *)0);
}

canonical_original_code:
void maxlenprint(char *value, int maxlen)
{
  char *p;
  int lack;
  p=(char *)malloc(maxlen*sizeof(char));
  if(p != ((void *)0)) {
    lack = maxlen - strlen(value);
    strcpy(p, value);
    while(lack != 0) {
      strcat(p, " ");
      lack--;
    }
    printf("%s ", p);
  }
  else {
    fprintf(stderr, "malloc error!\n");
    exit(1);
  }
  free(p);
  p=((void *)0);
}

variable_types:
value
char *

variable_types: maxlen int

variable_types:
p
char *

variable_types: lack int


dircheck

decompiled_code:
void __fastcall __noreturn dircheck(char *a1)
{
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)stat(a1, &v1) != -1 )
{
if ( (v1.st_mode & 0xF000) != 0x4000 )
{
fprintf(stderr, "Not a directory: %s\n", a1);
exit(1);
}
exit(0);
}
if ( *__errno_location() != 2 )
{
perror("Stat Error");
exit(1);
}
fprintf(stderr, "No such directory: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(char *a1)
{
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)func13(a1, &v1) != -1 )
{
if ( (v1.st_mode & 0xF000) != 0x4000 )
{
fprintf(stderr, "Not a directory: %s\n", a1);
exit(1);
}
exit(0);
}
if ( *__errno_location() != 2 )
{
perror("Stat Error");
exit(1);
}
fprintf(stderr, "No such directory: %s\n", a1);
exit(1);
}

original_code:
void
dircheck(char *dir)
{
  struct stat dir_stat;
  if (stat(dir, &dir_stat) == -1) {
    if((*__errno_location ()) == 2) {
      fprintf(stderr, "No such directory: %s\n", dir);
      exit(1);
    }
    else {
      perror("Stat Error");
      exit(1);
    }
  }
  if(((((dir_stat.st_mode)) & 0170000) == (0040000)))
    exit(0);
  else {
    fprintf(stderr, "Not a directory: %s\n", dir);
    exit(1);
  }
}

variable_types:
dir
char *

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

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


startsws

decompiled_code:
void __fastcall __noreturn startsws(char *cp, unsigned int a2)
{
void *v2; // rbp
int v3; // eax
unsigned int v4; // er12
int v5; // eax
int v6; // ebx
struct sockaddr v7; // [rsp+0h] [rbp-48h] BYREF
socklen_t addr_len[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v2 = malloc(0x400uLL);
puts("\n-----------Starting Sever-----------");
v3 = socket(2, 1, 0);
v4 = v3;
if ( v3 > 0 )
{
printf("Socket created: %d\n", (unsigned int)v3);
puts("Binding socket ...");
puts("(Please re-run sws if pending a long time for socket binging.)\n");
}
v7.sa_family = 2;
*(_DWORD *)&v7.sa_data[2] = inet_addr(cp);
*(_WORD *)v7.sa_data = _bswap_16(a2);
if ( !bind(v4, &v7, 0x10u) )
printf("Socket Binding Completed:\n Socket: %d | Port: %d | Address: %s \n\n", v4, a2, cp);
while ( listen(v4, 5) >= 0 )
{
v5 = accept(v4, &v7, addr_len);
v6 = v5;
if ( v5 < 0 )
{
perror("server: accept");
exit(1);
}
if ( v5 > 0 )
{
printf("-----------------------");
printf("Client~ INFO");
puts("-----------------------");
}
recv(v6, v2, 0x400uLL, 0);
puts((const char *)v2);
write(v6, v2, 0x64uLL);
close(v6);
}
perror("server: listen");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(char *cp, unsigned int a2)
{
void *v2; // rbp
int v3; // eax
unsigned int v4; // er12
int v5; // eax
int v6; // ebx
struct sockaddr v7; // [rsp+0h] [rbp-48h] BYREF
socklen_t addr_len[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v2 = malloc(0x400uLL);
puts("\n-----------Starting Sever-----------");
v3 = socket(2, 1, 0);
v4 = v3;
if ( v3 > 0 )
{
printf("Socket created: %d\n", (unsigned int)v3);
puts("Binding socket ...");
puts("(Please re-run sws if pending a long time for socket binging.)\n");
}
v7.sa_family = 2;
*(_DWORD *)&v7.sa_data[2] = inet_addr(cp);
*(_WORD *)v7.sa_data = func9(a2);
if ( !bind(v4, &v7, 0x10u) )
printf("Socket Binding Completed:\n Socket: %d | Port: %d | Address: %s \n\n", v4, a2, cp);
while ( listen(v4, 5) >= 0 )
{
v5 = accept(v4, &v7, addr_len);
v6 = v5;
if ( v5 < 0 )
{
perror("server: accept");
exit(1);
}
if ( v5 > 0 )
{
printf("-----------------------");
printf("Client~ INFO");
puts("-----------------------");
}
recv(v6, v2, 0x400uLL, 0);
puts((const char *)v2);
write(v6, v2, 0x64uLL);
close(v6);
}
perror("server: listen");
exit(1);
}

original_code:
void
startsws(char *i_address, int p_port)
{
  int bufsize = 1024;
  char *buffer = malloc(bufsize);
  int socket_fd, newsocket_fd;
  socklen_t addrlen;
  struct sockaddr_in address;
  printf("\n-----------Starting Sever-----------\n");
  if ((socket_fd = socket(2, SOCK_STREAM, 0)) > 0) {
    printf("Socket created: %d\n", socket_fd);
    printf("Binding socket ...\n");
    printf("(Please re-run sws if pending a long time for socket binging.)\n\n");
  }
  address.sin_family = 2;
  address.sin_addr.s_addr = inet_addr(i_address);
  address.sin_port = htons(p_port);
  if (bind(socket_fd, (struct sockaddr *) &address,
          sizeof(address)) == 0) {
    printf("Socket Binding Completed:\n Socket: %d | Port: %d | Address: %s \n\n",
           socket_fd, p_port, i_address);
  }
  while (1) {
    if (listen(socket_fd, 5) < 0) {
      perror("server: listen");
      exit(1);
    }
    if ((newsocket_fd=accept(socket_fd, (struct sockaddr *) &address,
                          &addrlen)) < 0) {
      perror("server: accept");
      exit(1);
    }
    if (newsocket_fd > 0) {
      printf("-----------------------");
      printf("Client~ INFO");
      printf("-----------------------\n");
    }
    recv(newsocket_fd, buffer, bufsize, 0);
    printf("%s\n", buffer);
    write(newsocket_fd, buffer, 100);
    close(newsocket_fd);
  }
  free(buffer);
  close(socket_fd);
}

canonical_original_code:
void startsws(char *i_address, int p_port)
{
  int bufsize = 1024;
  char *buffer = malloc(bufsize);
  int socket_fd; int newsocket_fd;
  unsigned int addrlen;
  struct sockaddr_in address;
  printf("\n-----------Starting Sever-----------\n");
  if ((socket_fd = socket(2, SOCK_STREAM, 0)) > 0) {
    printf("Socket created: %d\n", socket_fd);
    printf("Binding socket ...\n");
    printf("(Please re-run sws if pending a long time for socket binging.)\n\n");
  }
  address.sin_family = 2;
  address.sin_addr.s_addr = inet_addr(i_address);
  address.sin_port = htons(p_port);
  if (bind(socket_fd, (struct sockaddr *) &address,
          sizeof(address)) == 0) {
    printf("Socket Binding Completed:\n Socket: %d | Port: %d | Address: %s \n\n",
           socket_fd, p_port, i_address);
  }
  while (1) {
    if (listen(socket_fd, 5) < 0) {
      perror("server: listen");
      exit(1);
    }
    if ((newsocket_fd=accept(socket_fd, (struct sockaddr *) &address,
                          &addrlen)) < 0) {
      perror("server: accept");
      exit(1);
    }
    if (newsocket_fd > 0) {
      printf("-----------------------");
      printf("Client~ INFO");
      printf("-----------------------\n");
    }
    recv(newsocket_fd, buffer, bufsize, 0);
    printf("%s\n", buffer);
    write(newsocket_fd, buffer, 100);
    close(newsocket_fd);
  }
  free(buffer);
  close(socket_fd);
}

variable_types: bufsize int

variable_types:
buffer
char *

variable_types:
addrlen
unsigned int

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

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

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


usage

decompiled_code:
void __noreturn usage()
{
fwrite("Usage: sws[-dh][-c dir][-i address][-l file][-p port]dir\n", 1uLL, 0x39uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
fwrite("Usage: sws[-dh][-c dir][-i address][-l file][-p port]dir\n", 1uLL, 0x39uLL, stderr);
exit(1);
}

original_code:
void
usage()
{
  fprintf(stderr, "Usage: sws[-dh][-c dir][-i address][-l file][-p port]dir\n");
  exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
int v4; // eax
int v5; // er14
char *v6; // rdi
int result; // eax

v3 = "127.0.0.1";
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "-dhcilp");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'c':
++_bss_start;
break;
case 'd':
flag_d = 1;
break;
case 'h':
flag_h = 1;
break;
case 'i':
v3 = (char *)argv[_bss_start++];
break;
case 'l':
++_bss_start;
break;
case 'p':
v5 = _bss_start;
atoi(argv[_bss_start]);
_bss_start = v5 + 1;
break;
default:
usage();
return result;
}
}
v6 = (char *)argv[_bss_start];
if ( !v6 )
startsws(v3);
dircheck(v6);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
int v4; // eax
int v5; // er14
char *v6; // rdi
int result; // eax

v3 = "127.0.0.1";
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "-dhcilp");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'c':
++_bss_start;
break;
case 'd':
flag_d = 1;
break;
case 'h':
flag_h = 1;
break;
case 'i':
v3 = (char *)argv[_bss_start++];
break;
case 'l':
++_bss_start;
break;
case 'p':
v5 = _bss_start;
atoi(argv[_bss_start]);
_bss_start = v5 + 1;
break;
default:
func7();
return result;
}
}
v6 = (char *)argv[_bss_start];
if ( !v6 )
func10(v3);
func8(v6);
}

original_code:
int
main(int argc, char *argv[])
{
  int ch;
  char *c_dir=((void *)0), *l_file=((void *)0), *sws_dir=((void *)0),
       *i_address = "127.0.0.1";
  int p_port = 8080;
  while ((ch = getopt(argc, argv, "-dhcilp")) != -1) {
    switch (ch) {
    case 'd':
      flag_d = 1;
      break;
    case 'h':
      flag_h = 1;
      break;
    case 'c':
      c_dir = argv[optind];
      optind++;
      break;
    case 'i':
      i_address = argv[optind];
      optind++;
      break;
    case 'l':
      l_file = argv[optind];
      optind++;
      break;
    case 'p':
      p_port = atoi(argv[optind]);
      optind++;
      break;
    default:
    case '?':
      usage();
    }
  }
  argc -= optind;
  argv += optind;
  sws_dir = *argv;
  if (sws_dir != ((void *)0))
    dircheck(sws_dir);
  startsws(i_address, p_port);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int ch;
  char *c_dir = ((void *)0); char *l_file = ((void *)0); char *sws_dir = ((void *)0); char *i_address = "127.0.0.1";
  int p_port = 8080;
  while ((ch = getopt(argc, argv, "-dhcilp")) != -1) {
    switch (ch) {
    case 'd':
      flag_d = 1;
      break;
    case 'h':
      flag_h = 1;
      break;
    case 'c':
      c_dir = argv[optind];
      optind++;
      break;
    case 'i':
      i_address = argv[optind];
      optind++;
      break;
    case 'l':
      l_file = argv[optind];
      optind++;
      break;
    case 'p':
      p_port = atoi(argv[optind]);
      optind++;
      break;
    default:
    case '?':
      usage();
    }
  }
  argc -= optind;
  argv += optind;
  sws_dir = *argv;
  if (sws_dir != ((void *)0))
    dircheck(sws_dir);
  startsws(i_address, p_port);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ch int


namecmp

decompiled_code:
int __fastcall namecmp(__int64 a1, __int64 a2)
{
return strcmp((const char *)(a1 + 112), (const char *)(a2 + 112));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2)
{
return strcmp((const char *)(a1 + 112), (const char *)(a2 + 112));
}

original_code:
int
namecmp(const FTSENT *p1, const FTSENT *p2)
{
  return (strcmp(p1->fts_name, p2->fts_name));
}

canonical_original_code:
int namecmp(struct _ftsent *p1, struct _ftsent *p2)
{
  return (strcmp(p1->fts_name, p2->fts_name));
}

variable_types: struct _ftsent { struct _ftsent *fts_cycle; struct _ftsent *fts_parent; struct _ftsent *fts_link; long fts_number; void *fts_pointer; char *fts_accpath; char *fts_path; int fts_errno; int fts_symfd; unsigned short fts_pathlen; unsigned short fts_namelen; unsigned long fts_ino; unsigned long fts_dev; unsigned long fts_nlink; short fts_level; unsigned short fts_info; unsigned short fts_flags; unsigned short fts_instr; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *fts_statp; char fts_name[1]; } *

user_defined_types: struct _ftsent { struct _ftsent *fts_cycle; struct _ftsent *fts_parent; struct _ftsent *fts_link; long fts_number; void *fts_pointer; char *fts_accpath; char *fts_path; int fts_errno; int fts_symfd; unsigned short fts_pathlen; unsigned short fts_namelen; unsigned long fts_ino; unsigned long fts_dev; unsigned long fts_nlink; short fts_level; unsigned short fts_info; unsigned short fts_flags; unsigned short fts_instr; struct stat *fts_statp; char fts_name[1]; }


mtimecmp

decompiled_code:
int __fastcall mtimecmp(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rdx
int result; // eax

v2 = *(_QWORD *)(*(_QWORD *)(a2 + 104) + 88LL);
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 104) + 88LL);
result = 1;
if ( v2 <= v3 )
{
if ( v2 < v3 )
result = -1;
else
result = strcmp((const char *)(a1 + 112), (const char *)(a2 + 112));
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rdx
int result; // eax

v2 = *(_QWORD *)(*(_QWORD *)(a2 + 104) + 88LL);
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 104) + 88LL);
result = 1;
if ( v2 <= v3 )
{
if ( v2 < v3 )
result = -1;
else
result = strcmp((const char *)(a1 + 112), (const char *)(a2 + 112));
}
return result;
}

original_code:
int
mtimecmp(const FTSENT *p1, const FTSENT *p2)
{
  if (p2->fts_statp->st_mtim.tv_sec > p1->fts_statp->st_mtim.tv_sec)
    return (1);
  else if (p2->fts_statp->st_mtim.tv_sec < p1->fts_statp->st_mtim.tv_sec)
    return (-1);
  else
    return (strcmp(p1->fts_name, p2->fts_name));
}

canonical_original_code:
int mtimecmp(struct _ftsent *p1, struct _ftsent *p2)
{
  if (p2->fts_statp->st_mtim.tv_sec > p1->fts_statp->st_mtim.tv_sec)
    return (1);
  else if (p2->fts_statp->st_mtim.tv_sec < p1->fts_statp->st_mtim.tv_sec)
    return (-1);
  else
    return (strcmp(p1->fts_name, p2->fts_name));
}

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


ctimecmp

decompiled_code:
int __fastcall ctimecmp(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rdx
int result; // eax

v2 = *(_QWORD *)(*(_QWORD *)(a2 + 104) + 104LL);
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 104) + 104LL);
result = 1;
if ( v2 <= v3 )
{
if ( v2 < v3 )
result = -1;
else
result = strcmp((const char *)(a1 + 112), (const char *)(a2 + 112));
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rdx
int result; // eax

v2 = *(_QWORD *)(*(_QWORD *)(a2 + 104) + 104LL);
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 104) + 104LL);
result = 1;
if ( v2 <= v3 )
{
if ( v2 < v3 )
result = -1;
else
result = strcmp((const char *)(a1 + 112), (const char *)(a2 + 112));
}
return result;
}

original_code:
int
ctimecmp(const FTSENT *p1, const FTSENT *p2)
{
  if (p2->fts_statp->st_ctim.tv_sec > p1->fts_statp->st_ctim.tv_sec)
    return (1);
  else if (p2->fts_statp->st_ctim.tv_sec < p1->fts_statp->st_ctim.tv_sec)
    return (-1);
  else
    return (strcmp(p1->fts_name, p2->fts_name));
}

canonical_original_code:
int ctimecmp(struct _ftsent *p1, struct _ftsent *p2)
{
  if (p2->fts_statp->st_ctim.tv_sec > p1->fts_statp->st_ctim.tv_sec)
    return (1);
  else if (p2->fts_statp->st_ctim.tv_sec < p1->fts_statp->st_ctim.tv_sec)
    return (-1);
  else
    return (strcmp(p1->fts_name, p2->fts_name));
}


atimecmp

decompiled_code:
int __fastcall atimecmp(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rdx
int result; // eax

v2 = *(_QWORD *)(*(_QWORD *)(a2 + 104) + 72LL);
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 104) + 72LL);
result = 1;
if ( v2 <= v3 )
{
if ( v2 < v3 )
result = -1;
else
result = strcmp((const char *)(a1 + 112), (const char *)(a2 + 112));
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rdx
int result; // eax

v2 = *(_QWORD *)(*(_QWORD *)(a2 + 104) + 72LL);
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 104) + 72LL);
result = 1;
if ( v2 <= v3 )
{
if ( v2 < v3 )
result = -1;
else
result = strcmp((const char *)(a1 + 112), (const char *)(a2 + 112));
}
return result;
}

original_code:
int
atimecmp(const FTSENT *p1, const FTSENT *p2)
{
  if (p2->fts_statp->st_atim.tv_sec > p1->fts_statp->st_atim.tv_sec)
    return (1);
  else if (p2->fts_statp->st_atim.tv_sec < p1->fts_statp->st_atim.tv_sec)
    return (-1);
  else
    return (strcmp(p1->fts_name, p2->fts_name));
}

canonical_original_code:
int atimecmp(struct _ftsent *p1, struct _ftsent *p2)
{
  if (p2->fts_statp->st_atim.tv_sec > p1->fts_statp->st_atim.tv_sec)
    return (1);
  else if (p2->fts_statp->st_atim.tv_sec < p1->fts_statp->st_atim.tv_sec)
    return (-1);
  else
    return (strcmp(p1->fts_name, p2->fts_name));
}


sizecmp

decompiled_code:
int __fastcall sizecmp(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rdx
int result; // eax

v2 = *(_QWORD *)(*(_QWORD *)(a2 + 104) + 48LL);
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 104) + 48LL);
result = 1;
if ( v2 <= v3 )
{
if ( v2 < v3 )
result = -1;
else
result = strcmp((const char *)(a1 + 112), (const char *)(a2 + 112));
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rdx
int result; // eax

v2 = *(_QWORD *)(*(_QWORD *)(a2 + 104) + 48LL);
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 104) + 48LL);
result = 1;
if ( v2 <= v3 )
{
if ( v2 < v3 )
result = -1;
else
result = strcmp((const char *)(a1 + 112), (const char *)(a2 + 112));
}
return result;
}

original_code:
int
sizecmp(const FTSENT *p1, const FTSENT *p2)
{
  if (p2->fts_statp->st_size > p1->fts_statp->st_size)
    return (1);
  else if (p2->fts_statp->st_size < p1->fts_statp->st_size)
    return (-1);
  else
    return (strcmp(p1->fts_name, p2->fts_name));
}

canonical_original_code:
int sizecmp(struct _ftsent *p1, struct _ftsent *p2)
{
  if (p2->fts_statp->st_size > p1->fts_statp->st_size)
    return (1);
  else if (p2->fts_statp->st_size < p1->fts_statp->st_size)
    return (-1);
  else
    return (strcmp(p1->fts_name, p2->fts_name));
}


setcmp

decompiled_code:
__int64 __fastcall setcmp(_QWORD *a1, _QWORD *a2)
{
__int64 result; // rax

if ( sortype == 2 )
{
if ( flag_c )
{
result = ctimecmp(*a1, *a2);
}
else if ( flag_u )
{
result = atimecmp(*a1, *a2);
}
else
{
result = mtimecmp(*a1, *a2);
}
}
else if ( sortype == 3 )
{
result = sizecmp(*a1, *a2);
}
else
{
result = namecmp(*a1, *a2);
}
if ( flag_r )
result = (unsigned int)-(int)result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2)
{
__int64 result; // rax

if ( sortype == 2 )
{
if ( flag_c )
{
result = ctimecmp(*a1, *a2);
}
else if ( flag_u )
{
result = atimecmp(*a1, *a2);
}
else
{
result = mtimecmp(*a1, *a2);
}
}
else if ( sortype == 3 )
{
result = sizecmp(*a1, *a2);
}
else
{
result = namecmp(*a1, *a2);
}
if ( flag_r )
result = (unsigned int)-(int)result;
return result;
}

original_code:
int
setcmp(const FTSENT **p1, const FTSENT **p2)
{
  int result;
  if(sortype == 2) {
    if(flag_c)
      result = ctimecmp(*p1, *p2);
    else if(flag_u)
      result = atimecmp(*p1, *p2);
    else
      result = mtimecmp(*p1, *p2);
  }
  else if(sortype == 3)
    result = sizecmp(*p1, *p2);
  else
    result = namecmp(*p1, *p2);
  if(flag_r)
    result = -result;
  return(result);
}

canonical_original_code:
int setcmp(struct _ftsent **p1, struct _ftsent **p2)
{
  int result;
  if(sortype == 2) {
    if(flag_c)
      result = ctimecmp(*p1, *p2);
    else if(flag_u)
      result = atimecmp(*p1, *p2);
    else
      result = mtimecmp(*p1, *p2);
  }
  else if(sortype == 3)
    result = sizecmp(*p1, *p2);
  else
    result = namecmp(*p1, *p2);
  if(flag_r)
    result = -result;
  return(result);
}

variable_types: struct _ftsent { struct _ftsent *fts_cycle; struct _ftsent *fts_parent; struct _ftsent *fts_link; long fts_number; void *fts_pointer; char *fts_accpath; char *fts_path; int fts_errno; int fts_symfd; unsigned short fts_pathlen; unsigned short fts_namelen; unsigned long fts_ino; unsigned long fts_dev; unsigned long fts_nlink; short fts_level; unsigned short fts_info; unsigned short fts_flags; unsigned short fts_instr; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *fts_statp; char fts_name[1]; } **

variable_types: result int


display

decompiled_code:
int __fastcall display(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
unsigned int v4; // er12
unsigned int v5; // er14
unsigned int v6; // er13
__int64 v7; // r15
__int64 v8; // rax
__int64 v9; // rax
unsigned int v10; // edx
unsigned int v11; // edx
const char *v12; // rax
const char *v13; // rax
size_t v14; // rax
const char *v15; // rax
const char *v16; // rax
int v17; // ecx
size_t v18; // rax
__int64 v19; // rdx
__int64 v20; // rdx
__int64 v21; // rdx
__int64 v22; // rdx
__int64 v23; // rdx
__int64 v24; // rax
__int64 v25; // rax
size_t i; // rbp
int v27; // ebp
unsigned int v29; // [rsp+4h] [rbp-54h]
unsigned int v30; // [rsp+8h] [rbp-50h]
unsigned int v31; // [rsp+Ch] [rbp-4Ch]
unsigned int v32; // [rsp+10h] [rbp-48h]
unsigned int v33; // [rsp+14h] [rbp-44h]
int v34; // [rsp+18h] [rbp-40h]
int v35; // [rsp+1Ch] [rbp-3Ch]

v2 = a2;
if ( a2 )
{
v3 = a2;
v4 = 0;
v5 = 0;
v30 = 0;
v29 = 0;
v33 = 0;
v32 = 0;
v6 = 0;
v31 = 0;
v7 = 0LL;
do
{
if ( __PAIR64__(flag_A, flag_a) || *(_BYTE *)(v3 + 112) != 46 )
{
if ( flag_s )
{
v8 = *(_QWORD *)(*(_QWORD *)(v3 + 104) + 64LL);
if ( v8 <= (int)v31 )
LODWORD(v8) = v31;
v31 = v8;
}
if ( __PAIR64__(flag_l, flag_n) )
{
v9 = *(_QWORD *)(v3 + 104);
v7 += *(_QWORD *)(v9 + 64);
if ( *(_QWORD *)(v9 + 16) > (unsigned __int64)(int)v6 )
v6 = *(_QWORD *)(v9 + 16);
if ( flag_n )
{
v10 = *(_DWORD *)(v9 + 28);
if ( v10 <= v32 )
v10 = v32;
v32 = v10;
v11 = *(_DWORD *)(v9 + 32);
if ( v11 <= v33 )
v11 = v33;
v33 = v11;
}
v12 = (const char *)getownername(*(unsigned int *)(v9 + 28));
if ( strlen(v12) > (int)v29 )
{
v15 = (const char *)getownername(*(unsigned int *)(*(_QWORD *)(v3 + 104) + 28LL));
v29 = strlen(v15);
}
v13 = (const char *)getgroupname(*(unsigned int *)(*(_QWORD *)(v3 + 104) + 32LL));
if ( strlen(v13) > (int)v30 )
{
v16 = (const char *)getgroupname(*(unsigned int *)(*(_QWORD *)(v3 + 104) + 32LL));
v30 = strlen(v16);
}
if ( *(_QWORD *)(*(_QWORD *)(v3 + 104) + 48LL) > (int)v5 )
v5 = *(_QWORD *)(*(_QWORD *)(v3 + 104) + 48LL);
}
v14 = strlen((const char *)(v3 + 112));
if ( v14 > (int)v4 )
v4 = v14;
}
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
}
else
{
v4 = 0;
v5 = 0;
v30 = 0;
v29 = 0;
v33 = 0;
v32 = 0;
v6 = 0;
v31 = 0;
v7 = 0LL;
}
if ( __PAIR64__(flag_l, flag_n) )
printf("total: %lld\n", v7);
v17 = v4 + 1;
LODWORD(v18) = t_width;
v19 = 2 * (v4 + 1);
if ( (int)v19 <= t_width )
{
v19 = (unsigned int)(t_width >> 31);
LODWORD(v19) = t_width % v17;
LODWORD(v18) = t_width / v17 - 2;
v35 = v18;
}
else
{
flag_1 = 1;
v35 = 1;
}
if ( a2 )
{
v34 = 0;
do
{
LODWORD(v18) = flag_A | flag_a;
if ( __PAIR64__(flag_A, flag_a) || *(_BYTE *)(v2 + 112) != 46 )
{
if ( flag_s )
maxprint(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 64LL), v31, v19);
LODWORD(v18) = flag_n | flag_l;
if ( __PAIR64__(flag_l, flag_n) )
{
if ( flag_i )
printf("%lld ", *(_QWORD *)(*(_QWORD *)(v2 + 104) + 8LL));
printmodes(*(unsigned int *)(*(_QWORD *)(v2 + 104) + 24LL));
maxprint(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 16LL), v6, v20);
if ( flag_n )
{
maxprint(*(unsigned int *)(*(_QWORD *)(v2 + 104) + 28LL), v32, v21);
maxprint(*(unsigned int *)(*(_QWORD *)(v2 + 104) + 32LL), v33, v22);
}
else
{
v24 = getownername(*(unsigned int *)(*(_QWORD *)(v2 + 104) + 28LL));
maxlenprint(v24, v29);
v25 = getgroupname(*(unsigned int *)(*(_QWORD *)(v2 + 104) + 32LL));
maxlenprint(v25, v30);
}
if ( flag_h )
{
printhsize(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 48LL));
}
else if ( flag_k )
{
printksize(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 48LL));
}
else
{
maxprint(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 48LL), v5, v23);
putchar(32);
}
if ( flag_u )
{
LODWORD(v18) = printtime(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 72LL));
}
else if ( flag_c )
{
LODWORD(v18) = printtime(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 104LL));
}
else
{
LODWORD(v18) = printtime(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 88LL));
}
}
if ( flag_q )
{
for ( i = 0LL; ; ++i )
{
v18 = strlen((const char *)(v2 + 112));
if ( v18 <= i )
break;
if ( ((*_ctype_b_loc())[*(char *)(v2 + i + 112)] & 0x4000) == 0 )
*(_BYTE *)(v2 + i + 112) = 63;
}
}
if ( flag_F )
{
LODWORD(v18) = flag_n | flag_l | flag_1;
if ( (_DWORD)v18 )
{
printf("%s", (const char *)(v2 + 112));
printindicator(*(unsigned int *)(*(_QWORD *)(v2 + 104) + 24LL));
LODWORD(v18) = putchar(10);
}
else if ( flag_x )
{
maxlenprint(v2 + 112, v4);
LODWORD(v18) = printf(" ");
if ( v35 < v34 )
{
LODWORD(v18) = putchar(10);
v34 = 1;
}
}
}
else
{
v27 = flag_n | flag_l | flag_1;
if ( v27 )
{
LODWORD(v18) = puts((const char *)(v2 + 112));
}
else if ( flag_x )
{
maxlenprint(v2 + 112, v4);
printf(" ");
LODWORD(v18) = ++v34;
if ( v35 < v34 )
{
LODWORD(v18) = putchar(10);
v34 = v27;
}
}
}
}
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
}
if ( flag_x )
LODWORD(v18) = putchar(10);
return v18;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
unsigned int v4; // er12
unsigned int v5; // er14
unsigned int v6; // er13
__int64 v7; // r15
__int64 v8; // rax
__int64 v9; // rax
unsigned int v10; // edx
unsigned int v11; // edx
const char *v12; // rax
const char *v13; // rax
size_t v14; // rax
const char *v15; // rax
const char *v16; // rax
int v17; // ecx
size_t v18; // rax
__int64 v19; // rdx
__int64 v20; // rdx
__int64 v21; // rdx
__int64 v22; // rdx
__int64 v23; // rdx
__int64 v24; // rax
__int64 v25; // rax
size_t i; // rbp
int v27; // ebp
unsigned int v29; // [rsp+4h] [rbp-54h]
unsigned int v30; // [rsp+8h] [rbp-50h]
unsigned int v31; // [rsp+Ch] [rbp-4Ch]
unsigned int v32; // [rsp+10h] [rbp-48h]
unsigned int v33; // [rsp+14h] [rbp-44h]
int v34; // [rsp+18h] [rbp-40h]
int v35; // [rsp+1Ch] [rbp-3Ch]

v2 = a2;
if ( a2 )
{
v3 = a2;
v4 = 0;
v5 = 0;
v30 = 0;
v29 = 0;
v33 = 0;
v32 = 0;
v6 = 0;
v31 = 0;
v7 = 0LL;
do
{
if ( __PAIR64__(flag_A, flag_a) || *(_BYTE *)(v3 + 112) != 46 )
{
if ( flag_s )
{
v8 = *(_QWORD *)(*(_QWORD *)(v3 + 104) + 64LL);
if ( v8 <= (int)v31 )
LODWORD(v8) = v31;
v31 = v8;
}
if ( __PAIR64__(flag_l, flag_n) )
{
v9 = *(_QWORD *)(v3 + 104);
v7 += *(_QWORD *)(v9 + 64);
if ( *(_QWORD *)(v9 + 16) > (unsigned __int64)(int)v6 )
v6 = *(_QWORD *)(v9 + 16);
if ( flag_n )
{
v10 = *(_DWORD *)(v9 + 28);
if ( v10 <= v32 )
v10 = v32;
v32 = v10;
v11 = *(_DWORD *)(v9 + 32);
if ( v11 <= v33 )
v11 = v33;
v33 = v11;
}
v12 = (const char *)getownername(*(unsigned int *)(v9 + 28));
if ( strlen(v12) > (int)v29 )
{
v15 = (const char *)getownername(*(unsigned int *)(*(_QWORD *)(v3 + 104) + 28LL));
v29 = strlen(v15);
}
v13 = (const char *)getgroupname(*(unsigned int *)(*(_QWORD *)(v3 + 104) + 32LL));
if ( strlen(v13) > (int)v30 )
{
v16 = (const char *)getgroupname(*(unsigned int *)(*(_QWORD *)(v3 + 104) + 32LL));
v30 = strlen(v16);
}
if ( *(_QWORD *)(*(_QWORD *)(v3 + 104) + 48LL) > (int)v5 )
v5 = *(_QWORD *)(*(_QWORD *)(v3 + 104) + 48LL);
}
v14 = strlen((const char *)(v3 + 112));
if ( v14 > (int)v4 )
v4 = v14;
}
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
}
else
{
v4 = 0;
v5 = 0;
v30 = 0;
v29 = 0;
v33 = 0;
v32 = 0;
v6 = 0;
v31 = 0;
v7 = 0LL;
}
if ( __PAIR64__(flag_l, flag_n) )
printf("total: %lld\n", v7);
v17 = v4 + 1;
LODWORD(v18) = t_width;
v19 = 2 * (v4 + 1);
if ( (int)v19 <= t_width )
{
v19 = (unsigned int)(t_width >> 31);
LODWORD(v19) = t_width % v17;
LODWORD(v18) = t_width / v17 - 2;
v35 = v18;
}
else
{
flag_1 = 1;
v35 = 1;
}
if ( a2 )
{
v34 = 0;
do
{
LODWORD(v18) = flag_A | flag_a;
if ( __PAIR64__(flag_A, flag_a) || *(_BYTE *)(v2 + 112) != 46 )
{
if ( flag_s )
maxprint(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 64LL), v31, v19);
LODWORD(v18) = flag_n | flag_l;
if ( __PAIR64__(flag_l, flag_n) )
{
if ( flag_i )
printf("%lld ", *(_QWORD *)(*(_QWORD *)(v2 + 104) + 8LL));
printmodes(*(unsigned int *)(*(_QWORD *)(v2 + 104) + 24LL));
maxprint(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 16LL), v6, v20);
if ( flag_n )
{
maxprint(*(unsigned int *)(*(_QWORD *)(v2 + 104) + 28LL), v32, v21);
maxprint(*(unsigned int *)(*(_QWORD *)(v2 + 104) + 32LL), v33, v22);
}
else
{
v24 = getownername(*(unsigned int *)(*(_QWORD *)(v2 + 104) + 28LL));
maxlenprint(v24, v29);
v25 = getgroupname(*(unsigned int *)(*(_QWORD *)(v2 + 104) + 32LL));
maxlenprint(v25, v30);
}
if ( flag_h )
{
printhsize(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 48LL));
}
else if ( flag_k )
{
printksize(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 48LL));
}
else
{
maxprint(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 48LL), v5, v23);
putchar(32);
}
if ( flag_u )
{
LODWORD(v18) = printtime(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 72LL));
}
else if ( flag_c )
{
LODWORD(v18) = printtime(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 104LL));
}
else
{
LODWORD(v18) = printtime(*(_QWORD *)(*(_QWORD *)(v2 + 104) + 88LL));
}
}
if ( flag_q )
{
for ( i = 0LL; ; ++i )
{
v18 = strlen((const char *)(v2 + 112));
if ( v18 <= i )
break;
if ( ((*_ctype_b_loc())[*(char *)(v2 + i + 112)] & 0x4000) == 0 )
*(_BYTE *)(v2 + i + 112) = 63;
}
}
if ( flag_F )
{
LODWORD(v18) = flag_n | flag_l | flag_1;
if ( (_DWORD)v18 )
{
printf("%s", (const char *)(v2 + 112));
printindicator(*(unsigned int *)(*(_QWORD *)(v2 + 104) + 24LL));
LODWORD(v18) = putchar(10);
}
else if ( flag_x )
{
maxlenprint(v2 + 112, v4);
LODWORD(v18) = printf(" ");
if ( v35 < v34 )
{
LODWORD(v18) = putchar(10);
v34 = 1;
}
}
}
else
{
v27 = flag_n | flag_l | flag_1;
if ( v27 )
{
LODWORD(v18) = puts((const char *)(v2 + 112));
}
else if ( flag_x )
{
maxlenprint(v2 + 112, v4);
printf(" ");
LODWORD(v18) = ++v34;
if ( v35 < v34 )
{
LODWORD(v18) = putchar(10);
v34 = v27;
}
}
}
}
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
}
if ( flag_x )
LODWORD(v18) = putchar(10);
return v18;
}

original_code:
void
display(FTSENT *p, FTSENT *list)
{
  FTSENT *listp;
  blkcnt_t total_b;
  total_b = 0;
  int maxblocks, maxnlink, maxuid, maxgid, maxownerlen,
      maxgrouplen, maxsize, maxnamelen;
  maxblocks = maxnlink = maxuid = maxgid
            = maxownerlen = maxgrouplen
            = maxsize = maxnamelen = 0;
  int file_counter, display_column;
  file_counter = 0;
  display_column = 1;
  int x_counter;
  for (listp = list; listp; listp = listp->fts_link) {
    if (!(flag_a || flag_A) && listp->fts_name[0] == '.')
      continue;
    if(flag_s && listp->fts_statp->st_blocks > maxblocks)
      maxblocks = listp->fts_statp->st_blocks;
    if(flag_l || flag_n) {
      total_b += listp->fts_statp->st_blocks;
    if(listp->fts_statp->st_nlink > maxnlink)
      maxnlink = listp->fts_statp->st_nlink;
    if(flag_n && listp->fts_statp->st_uid > maxuid)
      maxuid = listp->fts_statp->st_uid;
    if(flag_n && listp->fts_statp->st_gid > maxgid)
      maxgid = listp->fts_statp->st_gid;
    if(strlen(getownername(listp->fts_statp->st_uid)) > maxownerlen)
      maxownerlen = strlen(getownername(listp->fts_statp->st_uid));
    if(strlen(getgroupname(listp->fts_statp->st_gid)) > maxgrouplen)
      maxgrouplen = strlen(getgroupname(listp->fts_statp->st_gid));
    if(listp->fts_statp->st_size > maxsize)
      maxsize = listp->fts_statp->st_size;
    }
    if(strlen(listp->fts_name) > maxnamelen)
      maxnamelen = strlen(listp->fts_name);
    file_counter++;
  }
  if(flag_l || flag_n)
    printf("total: %lld\n", (long long)total_b);
  if((2*maxnamelen+2) > t_width)
    flag_1 = 1;
  else
    display_column = t_width/(maxnamelen+1)-2;
  x_counter = 0;
  for (listp = list; listp; listp = listp->fts_link) {
    if (!(flag_a || flag_A) && listp->fts_name[0] == '.')
      continue;
    if(flag_s) {
      maxprint(listp->fts_statp->st_blocks, maxblocks);
    }
    if(flag_l || flag_n) {
      if(flag_i)
        printf("%lld ", (long long)listp->fts_statp->st_ino);
      printmodes(listp->fts_statp->st_mode);
      maxprint(listp->fts_statp->st_nlink, maxnlink);
      if(flag_n) {
        maxprint(listp->fts_statp->st_uid, maxuid);
        maxprint(listp->fts_statp->st_gid, maxgid);
      }
      else {
        maxlenprint(getownername(listp->fts_statp->st_uid), maxownerlen);
        maxlenprint(getgroupname(listp->fts_statp->st_gid), maxgrouplen);
      }
      if(flag_h)
        printhsize(listp->fts_statp->st_size);
      else if(flag_k)
        printksize(listp->fts_statp->st_size);
      else {
        maxprint(listp->fts_statp->st_size, maxsize);
        printf(" ");
      }
      if(flag_u)
        printtime(listp->fts_statp->st_atim.tv_sec);
      else if(flag_c)
        printtime(listp->fts_statp->st_ctim.tv_sec);
      else
        printtime(listp->fts_statp->st_mtim.tv_sec);
    }
    if(flag_q) {
      int c = 0;
      while(c < strlen(listp->fts_name)) {
        if(!((*__ctype_b_loc ())[(int) ((listp->fts_name[c]))] & (unsigned short int) _ISprint))
          listp->fts_name[c] = '?';
        c++;
      }
    }
    if(flag_F) {
      if(flag_1 || flag_l || flag_n) {
        printf("%s", listp->fts_name);
        printindicator(listp->fts_statp->st_mode);
        printf("\n");
      }
      else if(flag_x) {
        maxlenprint(listp->fts_name, maxnamelen);
        printf("  ");
        if(x_counter > display_column) {
          printf("\n");
          x_counter = 0;
        x_counter++;
        }
      }
    }
    else {
      if(flag_1 || flag_l || flag_n)
        printf("%s\n", listp->fts_name);
      else if(flag_x) {
        maxlenprint(listp->fts_name, maxnamelen);
        printf("  ");
        x_counter++;
        if(x_counter > display_column) {
          printf("\n");
          x_counter = 0;
        }
      }
    }
  }
  if(flag_x)
    printf("\n");
}

canonical_original_code:
void display(struct _ftsent *p, struct _ftsent *list)
{
  struct _ftsent *listp;
  long total_b;
  total_b = 0;
  int maxblocks; int maxnlink; int maxuid; int maxgid; int maxownerlen; int maxgrouplen; int maxsize; int maxnamelen;
  maxblocks = maxnlink = maxuid = maxgid
            = maxownerlen = maxgrouplen
            = maxsize = maxnamelen = 0;
  int file_counter; int display_column;
  file_counter = 0;
  display_column = 1;
  int x_counter;
  for (listp = list; listp; listp = listp->fts_link) {
    if (!(flag_a || flag_A) && listp->fts_name[0] == '.')
      continue;
    if(flag_s && listp->fts_statp->st_blocks > maxblocks)
      maxblocks = listp->fts_statp->st_blocks;
    if(flag_l || flag_n) {
      total_b += listp->fts_statp->st_blocks;
    if(listp->fts_statp->st_nlink > maxnlink)
      maxnlink = listp->fts_statp->st_nlink;
    if(flag_n && listp->fts_statp->st_uid > maxuid)
      maxuid = listp->fts_statp->st_uid;
    if(flag_n && listp->fts_statp->st_gid > maxgid)
      maxgid = listp->fts_statp->st_gid;
    if(strlen(getownername(listp->fts_statp->st_uid)) > maxownerlen)
      maxownerlen = strlen(getownername(listp->fts_statp->st_uid));
    if(strlen(getgroupname(listp->fts_statp->st_gid)) > maxgrouplen)
      maxgrouplen = strlen(getgroupname(listp->fts_statp->st_gid));
    if(listp->fts_statp->st_size > maxsize)
      maxsize = listp->fts_statp->st_size;
    }
    if(strlen(listp->fts_name) > maxnamelen)
      maxnamelen = strlen(listp->fts_name);
    file_counter++;
  }
  if(flag_l || flag_n)
    printf("total: %lld\n", (long long)total_b);
  if((2*maxnamelen+2) > t_width)
    flag_1 = 1;
  else
    display_column = t_width/(maxnamelen+1)-2;
  x_counter = 0;
  for (listp = list; listp; listp = listp->fts_link) {
    if (!(flag_a || flag_A) && listp->fts_name[0] == '.')
      continue;
    if(flag_s) {
      maxprint(listp->fts_statp->st_blocks, maxblocks);
    }
    if(flag_l || flag_n) {
      if(flag_i)
        printf("%lld ", (long long)listp->fts_statp->st_ino);
      printmodes(listp->fts_statp->st_mode);
      maxprint(listp->fts_statp->st_nlink, maxnlink);
      if(flag_n) {
        maxprint(listp->fts_statp->st_uid, maxuid);
        maxprint(listp->fts_statp->st_gid, maxgid);
      }
      else {
        maxlenprint(getownername(listp->fts_statp->st_uid), maxownerlen);
        maxlenprint(getgroupname(listp->fts_statp->st_gid), maxgrouplen);
      }
      if(flag_h)
        printhsize(listp->fts_statp->st_size);
      else if(flag_k)
        printksize(listp->fts_statp->st_size);
      else {
        maxprint(listp->fts_statp->st_size, maxsize);
        printf(" ");
      }
      if(flag_u)
        printtime(listp->fts_statp->st_atim.tv_sec);
      else if(flag_c)
        printtime(listp->fts_statp->st_ctim.tv_sec);
      else
        printtime(listp->fts_statp->st_mtim.tv_sec);
    }
    if(flag_q) {
      int c = 0;
      while(c < strlen(listp->fts_name)) {
        if(!((*__ctype_b_loc ())[(int) ((listp->fts_name[c]))] & (unsigned short) _ISprint))
          listp->fts_name[c] = '?';
        c++;
      }
    }
    if(flag_F) {
      if(flag_1 || flag_l || flag_n) {
        printf("%s", listp->fts_name);
        printindicator(listp->fts_statp->st_mode);
        printf("\n");
      }
      else if(flag_x) {
        maxlenprint(listp->fts_name, maxnamelen);
        printf("  ");
        if(x_counter > display_column) {
          printf("\n");
          x_counter = 0;
        x_counter++;
        }
      }
    }
    else {
      if(flag_1 || flag_l || flag_n)
        printf("%s\n", listp->fts_name);
      else if(flag_x) {
        maxlenprint(listp->fts_name, maxnamelen);
        printf("  ");
        x_counter++;
        if(x_counter > display_column) {
          printf("\n");
          x_counter = 0;
        }
      }
    }
  }
  if(flag_x)
    printf("\n");
}

variable_types:
list
struct _ftsent *

variable_types: maxblocks int

variable_types: maxnlink int

variable_types: maxuid int

variable_types: maxgid int

variable_types: maxownerlen int

variable_types: maxgrouplen int

variable_types: maxsize int

variable_types: maxnamelen int

variable_types: c int


traverse

decompiled_code:
void __fastcall __noreturn traverse(int a1, char *const *a2, int a3, int a4)
{
int (*v8)(const FTSENT **, const FTSENT **); // rdx
FTS *v9; // rbp
int v10; // er14
char *v11; // rax
FTSENT *v12; // rax
__int64 v13; // rbx
u_short v14; // ax
const char *v15; // rax
const char *v16; // rax
FTSENT *v17; // rax

v8 = (int (*)(const FTSENT **, const FTSENT **))setcmp;
if ( flag_f )
v8 = 0LL;
v9 = fts_open(a2, a3, v8);
v10 = 0;
if ( !v9 )
{
fwrite("No such file or directory", 1uLL, 0x19uLL, stderr);
exit(1);
}
while ( 1 )
{
v12 = fts_read(v9);
v13 = (__int64)v12;
if ( !v12 )
break;
v14 = v12->fts_info;
if ( v14 == 2 )
{
fprintf(stderr, "%s: directory causes a cycle", (const char *)(v13 + 112));
}
else if ( v14 > 2u )
{
if ( v14 == 4 || v14 == 7 )
{
v11 = strerror(*(_DWORD *)(v13 + 56));
fprintf(stderr, "%s: %s", (const char *)(v13 + 112), v11);
}
}
else if ( v14 == 1 && (flag_R || !*(_WORD *)(v13 + 96)) )
{
if ( flag_d )
{
if ( __PAIR64__(flag_l, flag_n) )
{
if ( flag_i )
printf("%lld ", *(_QWORD *)(*(_QWORD *)(v13 + 104) + 8LL));
printmodes(*(unsigned int *)(*(_QWORD *)(v13 + 104) + 24LL));
printf(" %2d ", *(_QWORD *)(*(_QWORD *)(v13 + 104) + 16LL));
if ( flag_n )
{
printf(
"%d %d ",
*(unsigned int *)(*(_QWORD *)(v13 + 104) + 28LL),
*(unsigned int *)(*(_QWORD *)(v13 + 104) + 32LL));
}
else
{
v15 = (const char *)getownername(*(unsigned int *)(*(_QWORD *)(v13 + 104) + 28LL));
printf("%s ", v15);
v16 = (const char *)getgroupname(*(unsigned int *)(*(_QWORD *)(v13 + 104) + 32LL));
printf("%s ", v16);
}
if ( flag_h )
{
printhsize(*(_QWORD *)(*(_QWORD *)(v13 + 104) + 48LL));
}
else if ( flag_k )
{
printksize(*(_QWORD *)(*(_QWORD *)(v13 + 104) + 48LL));
}
else
{
printf("%6lld ", *(_QWORD *)(*(_QWORD *)(v13 + 104) + 48LL));
}
if ( flag_u )
{
printtime(*(_QWORD *)(*(_QWORD *)(v13 + 104) + 72LL));
}
else if ( flag_c )
{
printtime(*(_QWORD *)(*(_QWORD *)(v13 + 104) + 104LL));
}
else
{
printtime(*(_QWORD *)(*(_QWORD *)(v13 + 104) + 88LL));
}
}
puts(*(const char **)(v13 + 48));
}
else
{
if ( v10 )
{
printf("\n%s:\n", *(const char **)(v13 + 48));
}
else if ( flag_R || a1 > 1 )
{
printf("%s:\n", *(const char **)(v13 + 48));
v10 = 1;
}
v17 = fts_children(v9, a4);
display(v13, (__int64)v17);
}
}
}
fts_close(v9);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(int a1, char *const *a2, int a3, int a4)
{
int (*v8)(const FTSENT **, const FTSENT **); // rdx
FTS *v9; // rbp
int v10; // er14
char *v11; // rax
FTSENT *v12; // rax
__int64 v13; // rbx
u_short v14; // ax
const char *v15; // rax
const char *v16; // rax
FTSENT *v17; // rax

v8 = (int (*)(const FTSENT **, const FTSENT **))setcmp;
if ( flag_f )
v8 = 0LL;
v9 = fts_open(a2, a3, v8);
v10 = 0;
if ( !v9 )
{
fwrite("No such file or directory", 1uLL, 0x19uLL, stderr);
exit(1);
}
while ( 1 )
{
v12 = fts_read(v9);
v13 = (__int64)v12;
if ( !v12 )
break;
v14 = v12->fts_info;
if ( v14 == 2 )
{
fprintf(stderr, "%s: directory causes a cycle", (const char *)(v13 + 112));
}
else if ( v14 > 2u )
{
if ( v14 == 4 || v14 == 7 )
{
v11 = strerror(*(_DWORD *)(v13 + 56));
fprintf(stderr, "%s: %s", (const char *)(v13 + 112), v11);
}
}
else if ( v14 == 1 && (flag_R || !*(_WORD *)(v13 + 96)) )
{
if ( flag_d )
{
if ( __PAIR64__(flag_l, flag_n) )
{
if ( flag_i )
printf("%lld ", *(_QWORD *)(*(_QWORD *)(v13 + 104) + 8LL));
printmodes(*(unsigned int *)(*(_QWORD *)(v13 + 104) + 24LL));
printf(" %2d ", *(_QWORD *)(*(_QWORD *)(v13 + 104) + 16LL));
if ( flag_n )
{
printf(
"%d %d ",
*(unsigned int *)(*(_QWORD *)(v13 + 104) + 28LL),
*(unsigned int *)(*(_QWORD *)(v13 + 104) + 32LL));
}
else
{
v15 = (const char *)getownername(*(unsigned int *)(*(_QWORD *)(v13 + 104) + 28LL));
printf("%s ", v15);
v16 = (const char *)getgroupname(*(unsigned int *)(*(_QWORD *)(v13 + 104) + 32LL));
printf("%s ", v16);
}
if ( flag_h )
{
printhsize(*(_QWORD *)(*(_QWORD *)(v13 + 104) + 48LL));
}
else if ( flag_k )
{
printksize(*(_QWORD *)(*(_QWORD *)(v13 + 104) + 48LL));
}
else
{
printf("%6lld ", *(_QWORD *)(*(_QWORD *)(v13 + 104) + 48LL));
}
if ( flag_u )
{
printtime(*(_QWORD *)(*(_QWORD *)(v13 + 104) + 72LL));
}
else if ( flag_c )
{
printtime(*(_QWORD *)(*(_QWORD *)(v13 + 104) + 104LL));
}
else
{
printtime(*(_QWORD *)(*(_QWORD *)(v13 + 104) + 88LL));
}
}
puts(*(const char **)(v13 + 48));
}
else
{
if ( v10 )
{
printf("\n%s:\n", *(const char **)(v13 + 48));
}
else if ( flag_R || a1 > 1 )
{
printf("%s:\n", *(const char **)(v13 + 48));
v10 = 1;
}
v17 = fts_children(v9, a4);
func2(v13, (__int64)v17);
}
}
}
fts_close(v9);
exit(0);
}

original_code:
void
traverse(int argc, char *argv[], int p_options, int chp_options)
{
  FTS *ftsp;
  FTSENT *p, *chp;
  int wrap = 0;
  if ((ftsp = fts_open(argv, p_options, flag_f ? ((void *)0) : setcmp)) == ((void *)0)) {
    fprintf(stderr, "No such file or directory");
    exit(1);
  }
  while ((p = fts_read(ftsp)) != ((void *)0)) {
    switch (p->fts_info) {
    case 2:
      fprintf(stderr, "%s: directory causes a cycle", p->fts_name);
      break;
    case 4:
    case 7:
      fprintf(stderr, "%s: %s", p->fts_name, strerror(p->fts_errno));
      break;
    case 1:
      if (!flag_R && p->fts_level != 0)
        break;
      if(flag_d) {
        if(flag_l || flag_n) {
          if(flag_i)
            printf("%lld ", (long long)p->fts_statp->st_ino);
          printmodes(p->fts_statp->st_mode);
          printf("  %2d ", (int)p->fts_statp->st_nlink);
          if(flag_n)
            printf("%d %d ", p->fts_statp->st_uid, p->fts_statp->st_gid);
          else {
            printf("%s ", getownername(p->fts_statp->st_uid));
            printf("%s ", getgroupname(p->fts_statp->st_gid));
          }
          if(flag_h)
            printhsize(p->fts_statp->st_size);
          else if(flag_k)
            printksize(p->fts_statp->st_size);
          else
            printf("%6lld ", (long long)p->fts_statp->st_size);
          if(flag_u)
            printtime(p->fts_statp->st_atim.tv_sec);
          else if(flag_c)
            printtime(p->fts_statp->st_ctim.tv_sec);
          else
            printtime(p->fts_statp->st_mtim.tv_sec);
        }
        printf("%s\n", p->fts_path);
        break;
      }
      if (wrap)
        (void)printf("\n%s:\n", p->fts_path);
      else if (argc > 1 || flag_R) {
        (void)printf("%s:\n", p->fts_path);
        wrap = 1;
      }
      chp = fts_children(ftsp, chp_options);
      display(p, chp);
    default:
      break;
    }
  }
  fts_close(ftsp);
  exit(0);
}

canonical_original_code:
void traverse(int argc, char *argv[], int p_options, int chp_options)
{
  struct FTS *ftsp;
  struct _ftsent *p; struct _ftsent *chp;
  int wrap = 0;
  if ((ftsp = fts_open(argv, p_options, flag_f ? ((void *)0) : setcmp)) == ((void *)0)) {
    fprintf(stderr, "No such file or directory");
    exit(1);
  }
  while ((p = fts_read(ftsp)) != ((void *)0)) {
    switch (p->fts_info) {
    case 2:
      fprintf(stderr, "%s: directory causes a cycle", p->fts_name);
      break;
    case 4:
    case 7:
      fprintf(stderr, "%s: %s", p->fts_name, strerror(p->fts_errno));
      break;
    case 1:
      if (!flag_R && p->fts_level != 0)
        break;
      if(flag_d) {
        if(flag_l || flag_n) {
          if(flag_i)
            printf("%lld ", (long long)p->fts_statp->st_ino);
          printmodes(p->fts_statp->st_mode);
          printf("  %2d ", (int)p->fts_statp->st_nlink);
          if(flag_n)
            printf("%d %d ", p->fts_statp->st_uid, p->fts_statp->st_gid);
          else {
            printf("%s ", getownername(p->fts_statp->st_uid));
            printf("%s ", getgroupname(p->fts_statp->st_gid));
          }
          if(flag_h)
            printhsize(p->fts_statp->st_size);
          else if(flag_k)
            printksize(p->fts_statp->st_size);
          else
            printf("%6lld ", (long long)p->fts_statp->st_size);
          if(flag_u)
            printtime(p->fts_statp->st_atim.tv_sec);
          else if(flag_c)
            printtime(p->fts_statp->st_ctim.tv_sec);
          else
            printtime(p->fts_statp->st_mtim.tv_sec);
        }
        printf("%s\n", p->fts_path);
        break;
      }
      if (wrap)
        (void)printf("\n%s:\n", p->fts_path);
      else if (argc > 1 || flag_R) {
        (void)printf("%s:\n", p->fts_path);
        wrap = 1;
      }
      chp = fts_children(ftsp, chp_options);
      display(p, chp);
    default:
      break;
    }
  }
  fts_close(ftsp);
  exit(0);
}

variable_types: struct FTS { struct _ftsent { struct _ftsent *fts_cycle; struct _ftsent *fts_parent; struct _ftsent *fts_link; long fts_number; void *fts_pointer; char *fts_accpath; char *fts_path; int fts_errno; int fts_symfd; unsigned short fts_pathlen; unsigned short fts_namelen; unsigned long fts_ino; unsigned long fts_dev; unsigned long fts_nlink; short fts_level; unsigned short fts_info; unsigned short fts_flags; unsigned short fts_instr; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *fts_statp; char fts_name[1]; } *fts_cur; struct _ftsent *fts_child; struct _ftsent **fts_array; unsigned long fts_dev; char *fts_path; int fts_rfd; int fts_pathlen; int fts_nitems; int (*fts_compar)(void *, void *); int fts_options; } *

variable_types: wrap int

user_defined_types: struct FTS { struct _ftsent *fts_cur; struct _ftsent *fts_child; struct _ftsent **fts_array; unsigned long fts_dev; char *fts_path; int fts_rfd; int fts_pathlen; int fts_nitems; int (*fts_compar)(void *, void *); int fts_options; }


usage

decompiled_code:
void __noreturn usage()
{
fwrite(&unk_BA8, 1uLL, 0x30uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
fwrite(&unk_BA8, 1uLL, 0x30uLL, stderr);
exit(1);
}

original_code:
void
usage()
{
  fprintf(stderr, "Usage: [ −AacdFfhiklnqRrSstuw1x] [file . . .]\n");
  exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
int v5; // eax
int v6; // ebx
char **v7; // rbp
int result; // eax
char v9[2]; // [rsp+8h] [rbp-30h] BYREF
unsigned __int16 v10; // [rsp+Ah] [rbp-2Eh]

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, &shortopts);
if ( v5 == -1 )
break;
switch ( v5 )
{
case '1':
case 'x':
flag_x = 1;
flag_1 = 0;
break;
case 'A':
flag_A = 1;
break;
case 'F':
flag_F = 1;
break;
case 'R':
flag_R = 1;
break;
case 'S':
sortype = 3;
break;
case 'a':
flag_a = 1;
v4 = 32;
break;
case 'c':
flag_c = 1;
flag_u = 0;
break;
case 'd':
flag_d = 1;
v3 = 16;
break;
case 'f':
flag_f = 1;
break;
case 'h':
flag_h = 1;
break;
case 'i':
flag_i = 1;
break;
case 'k':
flag_k = 1;
break;
case 'l':
flag_l = 1;
break;
case 'n':
flag_n = 1;
break;
case 'q':
flag_q = 1;
flag_w = 0;
break;
case 'r':
flag_r = 1;
break;
case 's':
flag_s = 1;
break;
case 't':
sortype = 2;
break;
case 'u':
flag_u = 1;
flag_c = 0;
break;
case 'w':
flag_w = 1;
flag_q = 0;
break;
default:
usage();
return result;
}
}
v6 = argc - optind;
v7 = (char **)&argv[optind];
if ( !*v7 )
*v7 = (char *)&unk_C6D;
if ( !flag_1 )
flag_x = 1;
if ( isatty(1) )
{
if ( !ioctl(1, 0x5413uLL, v9) && v10 )
t_width = v10;
if ( !flag_w )
flag_q = 1;
}
else
{
if ( !flag_q )
flag_w = 1;
flag_1 = 1;
}
if ( !getuid() )
flag_A = 1;
traverse(v6, v7, v4, v3);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
int v5; // eax
int v6; // ebx
char **v7; // rbp
int result; // eax
char v9[2]; // [rsp+8h] [rbp-30h] BYREF
unsigned __int16 v10; // [rsp+Ah] [rbp-2Eh]

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, &shortopts);
if ( v5 == -1 )
break;
switch ( v5 )
{
case '1':
case 'x':
flag_x = 1;
flag_1 = 0;
break;
case 'A':
flag_A = 1;
break;
case 'F':
flag_F = 1;
break;
case 'R':
flag_R = 1;
break;
case 'S':
sortype = 3;
break;
case 'a':
flag_a = 1;
v4 = 32;
break;
case 'c':
flag_c = 1;
flag_u = 0;
break;
case 'd':
flag_d = 1;
v3 = 16;
break;
case 'f':
flag_f = 1;
break;
case 'h':
flag_h = 1;
break;
case 'i':
flag_i = 1;
break;
case 'k':
flag_k = 1;
break;
case 'l':
flag_l = 1;
break;
case 'n':
flag_n = 1;
break;
case 'q':
flag_q = 1;
flag_w = 0;
break;
case 'r':
flag_r = 1;
break;
case 's':
flag_s = 1;
break;
case 't':
sortype = 2;
break;
case 'u':
flag_u = 1;
flag_c = 0;
break;
case 'w':
flag_w = 1;
flag_q = 0;
break;
default:
func1();
return result;
}
}
v6 = argc - optind;
v7 = (char **)&argv[optind];
if ( !*v7 )
*v7 = (char *)&unk_C6D;
if ( !flag_1 )
flag_x = 1;
if ( isatty(1) )
{
if ( !ioctl(1, 0x5413uLL, v9) && v10 )
t_width = v10;
if ( !flag_w )
flag_q = 1;
}
else
{
if ( !flag_q )
flag_w = 1;
flag_1 = 1;
}
if ( !getuid() )
flag_A = 1;
func3(v6, v7, v4, v3);
}

original_code:
int
main(int argc, char *argv[])
{
  int ch;
  int p_options;
  int chp_options;
  p_options = chp_options = 0;
  struct winsize sz;
  while ((ch = getopt(argc, argv, "−AacdFfhiklnqRrSstuw1x")) != -1) {
    switch (ch) {
    case 'A':
      flag_A = 1;
      break;
    case 'a':
      flag_a = 1;
      p_options |= 0x0020;
      break;
    case 'c':
      flag_c = 1;
      flag_u = 0;
      break;
    case 'd':
      flag_d = 1;
      chp_options = 0x0010;
      break;
    case 'F':
      flag_F = 1;
      break;
    case 'f':
      flag_f = 1;
      break;
    case 'h':
      flag_h = 1;
      break;
    case 'i':
      flag_i = 1;
      break;
    case 'k':
      flag_k = 1;
      break;
    case 'l':
      flag_l = 1;
      break;
    case 'n':
      flag_n = 1;
      break;
    case 'q':
      flag_q = 1;
      flag_w = 0;
      break;
    case 'R':
      flag_R = 1;
      break;
    case 'r':
      flag_r = 1;
      break;
    case 'S':
      sortype = 3;
      break;
    case 's':
      flag_s = 1;
      break;
    case 't':
      sortype = 2;
      break;
    case 'u':
      flag_u = 1;
      flag_c = 0;
      break;
    case 'w':
      flag_w = 1;
      flag_q = 0;
      break;
    case '1':
      flag_1 = 1;
      flag_x = 0;
    case 'x':
      flag_x = 1;
      flag_1 = 0;
      break;
    default:
    case '?':
      usage();
    }
  }
  argc -= optind;
  argv += optind;
  if (*argv == ((void *)0))
    *argv = ".";
   if(!flag_1)
    flag_x = 1;
   if (isatty(1)) {
    if (ioctl(1, 0x5413, &sz) == 0 && sz.ws_col > 0)
      t_width = sz.ws_col;
    if(!flag_w)
      flag_q = 1;
  } else {
    if(!flag_q)
      flag_w = 1;
    flag_1 = 1;
  }
  if (!getuid())
    flag_A = 1;
  traverse(argc, argv, p_options, chp_options);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // r13
__int64 i; // r12
unsigned __int64 v5; // rbp
unsigned __int64 v6; // rbp
unsigned __int64 v7; // rbp
unsigned __int64 v8; // rbp
const char **v9; // rbp
_QWORD *v10; // rbx

v3 = 1LL;
for ( i = 0LL; ; ++i )
{
v10 = (_QWORD *)bitmap_create(i, argv, envp);
if ( !v10 )
{
if ( i )
{
fprintf(stderr, " NULL pointer, as size = %ld\n", i);
exit(1);
}
goto LABEL_18;
}
v5 = 0LL;
do
{
if ( (unsigned int)bitmap_test(v10, v5) )
{
fprintf(stderr, "bitmap_test() not worked at index: %ld\n", v5);
exit(1);
}
++v5;
}
while ( v10[1] >= v5 );
v6 = 0LL;
do
{
bitmap_set(v10, v6);
if ( !(unsigned int)bitmap_test(v10, v6) )
{
fprintf(stderr, "bitmap_set() not worked at index: %ld\n", v6);
exit(1);
}
++v6;
}
while ( v10[1] >= v6 );
v7 = 0LL;
do
{
bitmap_clear(v10, v7);
if ( (unsigned int)bitmap_test(v10, v7) )
{
fprintf(stderr, "bitmap_clear() not worked at index: %ld\n", v7);
exit(1);
}
++v7;
}
while ( v10[1] >= v7 );
bitmap_set_all(v10);
v8 = 0LL;
do
{
if ( !(unsigned int)bitmap_test(v10, v8) )
{
fprintf(stderr, "bitmap_set_all() not worked at index: %ld\n", v8);
exit(1);
}
++v8;
}
while ( v10[1] >= v8 );
bitmap_clear_all(v10);
v9 = 0LL;
do
{
argv = v9;
if ( (unsigned int)bitmap_test(v10, v9) )
{
fprintf(stderr, "bitmap_clear_all() not worked at index: %ld\n", v9);
exit(1);
}
v9 = (const char **)((char *)v9 + 1);
}
while ( v10[1] >= (unsigned __int64)v9 );
bitmap_destroy(v10);
if ( v3 > 0x400 )
break;
LABEL_18:
++v3;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // r13
__int64 i; // r12
unsigned __int64 v5; // rbp
unsigned __int64 v6; // rbp
unsigned __int64 v7; // rbp
unsigned __int64 v8; // rbp
const char **v9; // rbp
_QWORD *v10; // rbx

v3 = 1LL;
for ( i = 0LL; ; ++i )
{
v10 = (_QWORD *)bitmap_create(i, argv, envp);
if ( !v10 )
{
if ( i )
{
fprintf(stderr, " NULL pointer, as size = %ld\n", i);
exit(1);
}
goto LABEL_18;
}
v5 = 0LL;
do
{
if ( (unsigned int)func14(v10, v5) )
{
fprintf(stderr, "bitmap_test() not worked at index: %ld\n", v5);
exit(1);
}
++v5;
}
while ( v10[1] >= v5 );
v6 = 0LL;
do
{
func12(v10, v6);
if ( !(unsigned int)func14(v10, v6) )
{
fprintf(stderr, "bitmap_set() not worked at index: %ld\n", v6);
exit(1);
}
++v6;
}
while ( v10[1] >= v6 );
v7 = 0LL;
do
{
func13(v10, v7);
if ( (unsigned int)func14(v10, v7) )
{
fprintf(stderr, "bitmap_clear() not worked at index: %ld\n", v7);
exit(1);
}
++v7;
}
while ( v10[1] >= v7 );
func15(v10);
v8 = 0LL;
do
{
if ( !(unsigned int)func14(v10, v8) )
{
fprintf(stderr, "bitmap_set_all() not worked at index: %ld\n", v8);
exit(1);
}
++v8;
}
while ( v10[1] >= v8 );
func16(v10);
v9 = 0LL;
do
{
argv = v9;
if ( (unsigned int)func14(v10, v9) )
{
fprintf(stderr, "bitmap_clear_all() not worked at index: %ld\n", v9);
exit(1);
}
v9 = (const char **)((char *)v9 + 1);
}
while ( v10[1] >= (unsigned __int64)v9 );
func11(v10);
if ( v3 > 0x400 )
break;
LABEL_18:
++v3;
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  size_t size;
  for (size = 0; size <= 1024; ++size) {
    bitmap_t *bitmap = bitmap_create(size);
    if (bitmap == ((void *)0)) {
      if (size == 0) {
        continue;
      }
      fprintf(stderr, " NULL pointer, as size = %ld\n", size);
      exit(1);
    }
    size_t index;
    for (index = 0; index <= bitmap->size; ++index)
    {
      if (bitmap_test(bitmap, index)) {
        fprintf(stderr, "bitmap_test() not worked at index: %ld\n", index);
        exit(1);
      }
    }
    for (index = 0; index <= bitmap->size; ++index)
    {
      bitmap_set(bitmap, index);
      if (!bitmap_test(bitmap, index)) {
        fprintf(stderr, "bitmap_set() not worked at index: %ld\n", index);
        exit(1);
      }
    }
    for (index = 0; index <= bitmap->size; ++index)
    {
      bitmap_clear(bitmap, index);
      if (bitmap_test(bitmap, index)) {
        fprintf(stderr, "bitmap_clear() not worked at index: %ld\n", index);
        exit(1);
      }
    }
    bitmap_set_all(bitmap);
    for (index = 0; index <= bitmap->size; ++index)
    {
      if (!bitmap_test(bitmap, index)) {
        fprintf(stderr, "bitmap_set_all() not worked at index: %ld\n", index);
        exit(1);
      }
    }
    bitmap_clear_all(bitmap);
    for (index = 0; index <= bitmap->size; ++index)
    {
      if (bitmap_test(bitmap, index)) {
        fprintf(stderr, "bitmap_clear_all() not worked at index: %ld\n", index);
        exit(1);
      }
    }
    bitmap_destroy(bitmap);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  unsigned long size;
  for (size = 0; size <= 1024; ++size) {
    struct _bitmap *bitmap = bitmap_create(size);
    if (bitmap == ((void *)0)) {
      if (size == 0) {
        continue;
      }
      fprintf(stderr, " NULL pointer, as size = %ld\n", size);
      exit(1);
    }
    unsigned long index;
    for (index = 0; index <= bitmap->size; ++index)
    {
      if (bitmap_test(bitmap, index)) {
        fprintf(stderr, "bitmap_test() not worked at index: %ld\n", index);
        exit(1);
      }
    }
    for (index = 0; index <= bitmap->size; ++index)
    {
      bitmap_set(bitmap, index);
      if (!bitmap_test(bitmap, index)) {
        fprintf(stderr, "bitmap_set() not worked at index: %ld\n", index);
        exit(1);
      }
    }
    for (index = 0; index <= bitmap->size; ++index)
    {
      bitmap_clear(bitmap, index);
      if (bitmap_test(bitmap, index)) {
        fprintf(stderr, "bitmap_clear() not worked at index: %ld\n", index);
        exit(1);
      }
    }
    bitmap_set_all(bitmap);
    for (index = 0; index <= bitmap->size; ++index)
    {
      if (!bitmap_test(bitmap, index)) {
        fprintf(stderr, "bitmap_set_all() not worked at index: %ld\n", index);
        exit(1);
      }
    }
    bitmap_clear_all(bitmap);
    for (index = 0; index <= bitmap->size; ++index)
    {
      if (bitmap_test(bitmap, index)) {
        fprintf(stderr, "bitmap_clear_all() not worked at index: %ld\n", index);
        exit(1);
      }
    }
    bitmap_destroy(bitmap);
  }
  return 0;
}

variable_types:
size
unsigned long

variable_types: struct _bitmap { unsigned char *bitmap; unsigned long size; void (*set)(struct _bitmap *bitmap, unsigned long index); void (*clear)(struct _bitmap *bitmap, unsigned long index); void (*set_all)(struct _bitmap *bitmap); void (*clear_all)(struct _bitmap *bitmap); int (*test)(struct _bitmap *bitmap, unsigned long index); } *

variable_types:
index
unsigned long


test

original_code:
static int test(bitmap_t *bitmap, size_t index)
{
  return (bitmap->bitmap[index >> 3] & (1 << (index & 0x7))) >> (index & 0x7);
}

canonical_original_code:
static int test(struct _bitmap *bitmap, unsigned long index)
{
  return (bitmap->bitmap[index >> 3] & (1 << (index & 0x7))) >> (index & 0x7);
}

user_defined_types: struct _bitmap { unsigned char *bitmap; unsigned long size; void (*set)(struct _bitmap *bitmap, unsigned long index); void (*clear)(struct _bitmap *bitmap, unsigned long index); void (*set_all)(struct _bitmap *bitmap); void (*clear_all)(struct _bitmap *bitmap); int (*test)(struct _bitmap *bitmap, unsigned long index); }


decompiled_code:
void *__fastcall clear_all(__int64 a1)
{
return memset(*(void **)a1, 0, (*(_QWORD *)(a1 + 8) >> 3) + 1LL);
}

canonical_decompiled_code:
void *__fastcall func9(__int64 a1)
{
return memset(*(void **)a1, 0, (*(_QWORD *)(a1 + 8) >> 3) + 1LL);
}

original_code:
static void clear_all(bitmap_t *bitmap)
{
  memset(bitmap->bitmap, 0x00, (bitmap->size >> 3) + ((bitmap->size & 0x7) ? 1 : 1));
}

canonical_original_code:
static void clear_all(struct _bitmap *bitmap)
{
  memset(bitmap->bitmap, 0x00, (bitmap->size >> 3) + ((bitmap->size & 0x7) ? 1 : 1));
}


decompiled_code:
void *__fastcall set_all(__int64 a1)
{
return memset(*(void **)a1, 255, (*(_QWORD *)(a1 + 8) >> 3) + 1LL);
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1)
{
return memset(*(void **)a1, 255, (*(_QWORD *)(a1 + 8) >> 3) + 1LL);
}

original_code:
static void set_all(bitmap_t *bitmap)
{
  memset(bitmap->bitmap, 0xff, (bitmap->size >> 3) + ((bitmap->size & 0x7) ? 1 : 1));
}

canonical_original_code:
static void set_all(struct _bitmap *bitmap)
{
  memset(bitmap->bitmap, 0xff, (bitmap->size >> 3) + ((bitmap->size & 0x7) ? 1 : 1));
}


decompiled_code:
void __fastcall bitmap_destroy(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void bitmap_destroy(bitmap_t *bitmap)
{
  if (bitmap) {
    if (bitmap->bitmap) {
      free(bitmap->bitmap);
    }
    free(bitmap);
  }
}

canonical_original_code:
void bitmap_destroy(struct _bitmap *bitmap)
{
  if (bitmap) {
    if (bitmap->bitmap) {
      free(bitmap->bitmap);
    }
    free(bitmap);
  }
}


original_code:
void bitmap_set(bitmap_t *bitmap, size_t index)
{
  bitmap->set(bitmap, index);
}

canonical_original_code:
void bitmap_set(struct _bitmap *bitmap, unsigned long index)
{
  bitmap->set(bitmap, index);
}


decompiled_code:
__int64 __fastcall bitmap_clear(__int64 a1)
{
return (*(__int64 (**)(void))(a1 + 24))();
}

original_code:
void bitmap_clear(bitmap_t *bitmap, size_t index)
{
  bitmap->clear(bitmap, index);
}

canonical_original_code:
void bitmap_clear(struct _bitmap *bitmap, unsigned long index)
{
  bitmap->clear(bitmap, index);
}


original_code:
int bitmap_test(bitmap_t *bitmap, size_t index)
{
  return bitmap->test(bitmap, index);
}

canonical_original_code:
int bitmap_test(struct _bitmap *bitmap, unsigned long index)
{
  return bitmap->test(bitmap, index);
}


decompiled_code:
__int64 __fastcall bitmap_set_all(__int64 a1)
{
return (*(__int64 (**)(void))(a1 + 32))();
}

original_code:
void bitmap_set_all(bitmap_t *bitmap)
{
  bitmap->set_all(bitmap);
}

canonical_original_code:
void bitmap_set_all(struct _bitmap *bitmap)
{
  bitmap->set_all(bitmap);
}


decompiled_code:
__int64 __fastcall bitmap_clear_all(__int64 a1)
{
return (*(__int64 (**)(void))(a1 + 40))();
}

original_code:
void bitmap_clear_all(bitmap_t *bitmap)
{
  bitmap->clear_all(bitmap);
}

canonical_original_code:
void bitmap_clear_all(struct _bitmap *bitmap)
{
  bitmap->clear_all(bitmap);
}


repo: wzhliang/splitsec

decompiled_code:
void dump_section()
{
size_t v0; // rbx

v0 = (_bswap_16(*(__int16 *)((char *)&section + 1)) & 0xFFF) + 3LL;
if ( v0 != write(1, &section, v0) )
perror("write");
}

canonical_decompiled_code:
void func8()
{
size_t v0; // rbx

v0 = (func7(*(__int16 *)((char *)&section + 1)) & 0xFFF) + 3LL;
if ( v0 != write(1, &section, v0) )
perror("write");
}

original_code:
void dump_section() {
 int sec_len;
 memcpy( &sec_len, section + 1, 2 );
 sec_len = ntohs( sec_len );
 sec_len = sec_len & 0x0fff;
 if ( sec_len + 3 != write( 1, section, sec_len + 3))
 {
  perror("write");
 }
}


decompiled_code:
__int64 __fastcall get_section(int fd, _WORD *a2)
{
__int16 v2; // ax
__int16 v3; // ax
_BYTE buf[3]; // [rsp+Dh] [rbp-1Bh] BYREF

if ( (unsigned int)read(fd, buf, 3uLL) != 3 )
return 0xFFFFFFFFLL;
v2 = _bswap_16(*(__int16 *)&buf[1]);
section = *(_WORD *)buf;
byte_4040A2 = buf[2];
if ( (v2 & 0xFFF) != (unsigned int)read(fd, &word_4040A3, v2 & 0xFFF) )
return 0xFFFFFFFFLL;
v3 = word_4040A3;
*a2 = word_4040A3;
*(_DWORD *)a2 = (unsigned __int16)_bswap_16(v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, _WORD *a2)
{
__int16 v2; // ax
__int16 v3; // ax
_BYTE buf[3]; // [rsp+Dh] [rbp-1Bh] BYREF

if ( (unsigned int)read(fd, buf, 3uLL) != 3 )
return 0xFFFFFFFFLL;
v2 = func7(*(__int16 *)&buf[1]);
section = *(_WORD *)buf;
byte_4040A2 = buf[2];
if ( (v2 & 0xFFF) != (unsigned int)read(fd, &word_4040A3, v2 & 0xFFF) )
return 0xFFFFFFFFLL;
v3 = word_4040A3;
*a2 = word_4040A3;
*(_DWORD *)a2 = (unsigned __int16)func7(v3);
return 0LL;
}

original_code:
int get_section(int fd_sec, int *table_id_ext) {
 unsigned char sec_header[3];
 int r;
 int sec_len;
 r = read( fd_sec, sec_header, 3 );
 if ( r != 3 )
 {
  return -1;
 }
 memcpy( &sec_len, sec_header + 1, 2 );
 sec_len = ntohs( sec_len );
 sec_len = sec_len & 0x0fff;
 memcpy( section, sec_header, 3 );
 r = read( fd_sec, section + 3, sec_len );
 if ( r != sec_len )
 {
  return -1;
 }
 memcpy( table_id_ext, section + 3, 2 );
 *table_id_ext = ntohs( *table_id_ext );
 return 0;
}

variable_types: r int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // ebp
int result; // eax
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc <= 2 )
{
fwrite("Usage: 'subtable filename.sec table_id_ext'\n", 1uLL, 0x2CuLL, stderr);
fwrite("the tool dumps subtable from a section dump generated by ts2sec.\n", 1uLL, 0x41uLL, stderr);
result = 2;
}
else
{
v3 = open64(argv[1], 0, envp);
v4 = atoi(argv[2]);
if ( v3 >= 0 )
{
while ( !(unsigned int)get_section(v3, v6) )
{
if ( v6[0] == v4 )
{
dump_section();
if ( byte_4040A6 == byte_4040A7 )
goto LABEL_6;
}
else
{
fprintf(stderr, "Found sub-table %d\n", v6[0]);
}
}
fprintf(stderr, "File format error. %s\n", argv[1]);
LABEL_6:
close(v3);
result = 0;
}
else
{
fprintf(stderr, "Can't find file %s\n", argv[1]);
result = 2;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // ebp
int result; // eax
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc <= 2 )
{
fwrite("Usage: 'subtable filename.sec table_id_ext'\n", 1uLL, 0x2CuLL, stderr);
fwrite("the tool dumps subtable from a section dump generated by ts2sec.\n", 1uLL, 0x41uLL, stderr);
result = 2;
}
else
{
v3 = open64(argv[1], 0, envp);
v4 = atoi(argv[2]);
if ( v3 >= 0 )
{
while ( !(unsigned int)func9(v3, v6) )
{
if ( v6[0] == v4 )
{
func8();
if ( byte_4040A6 == byte_4040A7 )
goto LABEL_6;
}
else
{
fprintf(stderr, "Found sub-table %d\n", v6[0]);
}
}
fprintf(stderr, "File format error. %s\n", argv[1]);
LABEL_6:
close(v3);
result = 0;
}
else
{
fprintf(stderr, "Can't find file %s\n", argv[1]);
result = 2;
}
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 int fd_sec;
 int table_id_ext;
 int ext;
 int st;
 if (argc >= 3) {
  fd_sec = open( argv[1], 00 );
  table_id_ext = atoi( argv[2] );
 } else {
  fprintf(stderr, "Usage: 'subtable filename.sec table_id_ext'\n");
  fprintf(stderr, "the tool dumps subtable from a section dump generated by ts2sec.\n");
  return 2;
 }
 if (fd_sec < 0) {
  fprintf(stderr, "Can't find file %s\n", argv[1]);
  return 2;
 }
 while( 1 )
 {
  unsigned char cur_sec;
  unsigned char last_sec;
  st = get_section( fd_sec, &ext );
  if ( st != 0 )
  {
   fprintf(stderr, "File format error. %s\n", argv[1]);
   break;
  }
  if ( table_id_ext != ext )
  {
   fprintf(stderr, "Found sub-table %d\n", ext);
   continue;
  }
  dump_section();
  cur_sec = section[6];
  last_sec = section[7];
  if ( cur_sec == last_sec )
  {
   break;
  }
 }
 close( fd_sec );
 return 0;
}

variable_types: ext int

variable_types: st int


decompiled_code:
double __fastcall timecode_rate_to_double(int *a1)
{
return (double)*a1 / (double)a1[1];
}

canonical_decompiled_code:
double __fastcall func1(int *a1)
{
return (double)*a1 / (double)a1[1];
}

original_code:
double timecode_rate_to_double(TimecodeRate const * const r) {
  return ( (double)((r)->num) / (double)((r)->den) );
}

canonical_original_code:
double timecode_rate_to_double(struct TimecodeRate *r) {
  return ( (double)((r)->num) / (double)((r)->den) );
}

variable_types: struct TimecodeRate { int num; int den; int drop; int subframes; } *

return_type: double


decompiled_code:
int __fastcall timecode_time_to_string(char *a1, unsigned int *a2)
{
return snprintf(a1, 0xCuLL, "%02d:%02d:%02d:%02d", *a2, a2[1], a2[2], a2[3]);
}

canonical_decompiled_code:
int __fastcall func3(char *a1, unsigned int *a2)
{
return snprintf(a1, 0xCuLL, "%02d:%02d:%02d:%02d", *a2, a2[1], a2[2], a2[3]);
}

original_code:
void timecode_time_to_string (char *smptestring, TimecodeTime const * const t) {
  snprintf(smptestring, 12, "%02d:%02d:%02d:%02d",
      t->hour, t->minute, t->second, t->frame);
}

canonical_original_code:
void timecode_time_to_string(char *smptestring, struct TimecodeTime *t) {
  snprintf(smptestring, 12, "%02d:%02d:%02d:%02d",
      t->hour, t->minute, t->second, t->frame);
}

variable_types:
smptestring
char *

variable_types: struct TimecodeTime { int hour; int minute; int second; int frame; int subframe; } *


decompiled_code:
int __fastcall timecode_framenumber_to_string(char *a1, int *a2, __int64 a3)
{
unsigned int v4[10]; // [rsp+0h] [rbp-28h] BYREF

timecode_framenumber_to_time(v4, a2, a3);
return timecode_time_to_string(a1, v4);
}

canonical_decompiled_code:
int __fastcall func4(char *a1, int *a2, __int64 a3)
{
unsigned int v4[10]; // [rsp+0h] [rbp-28h] BYREF

func2(v4, a2, a3);
return func3(a1, v4);
}

original_code:
void timecode_framenumber_to_string (char *smptestring, TimecodeRate const * const r, const int64_t frameno) {
  TimecodeTime t;
  timecode_framenumber_to_time(&t, r, frameno);
  timecode_time_to_string(smptestring, &t);
}

canonical_original_code:
void timecode_framenumber_to_string(char *smptestring, struct TimecodeRate *r, long frameno) {
  struct TimecodeTime t;
  timecode_framenumber_to_time(&t, r, frameno);
  timecode_time_to_string(smptestring, &t);
}

variable_types: frameno long

variable_types: struct TimecodeTime { int hour; int minute; int second; int frame; int subframe; }

user_defined_types: struct TimecodeRate { int num; int den; int drop; int subframes; }


original_code:
void jvi_init (VInfo *ji) {
  memset (ji, 0, sizeof(VInfo));
  memset(&ji->framerate, 0, sizeof(TimecodeRate));
  ji->framerate.num = 25;
  ji->framerate.den = 1;
  ji->out_width = ji->out_height = -1;
  ji->file_frame_offset = 0.0;
}

canonical_original_code:
void jvi_init(struct VInfo *ji) {
  memset (ji, 0, sizeof(VInfo));
  memset(&ji->framerate, 0, sizeof(TimecodeRate));
  ji->framerate.num = 25;
  ji->framerate.den = 1;
  ji->out_width = ji->out_height = -1;
  ji->file_frame_offset = 0.0;
}

variable_types: struct VInfo { int movie_width; int movie_height; double movie_aspect; int out_width; int out_height; struct TimecodeRate { int num; int den; int drop; int subframes; } framerate; long frames; unsigned long buffersize; double file_frame_offset; } *

user_defined_types: struct VInfo { int movie_width; int movie_height; double movie_aspect; int out_width; int out_height; struct TimecodeRate framerate; long frames; unsigned long buffersize; double file_frame_offset; }


decompiled_code:
void jvi_free()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void jvi_free (VInfo *i) {
  ;
}

canonical_original_code:
void jvi_free(struct VInfo *i) {
  ;
}


randf

canonical_original_code:
static float randf() {
        unsigned int hi; unsigned int lo;
        lo = 16807 * (_rseed & 0xffff);
        hi = 16807 * (_rseed >> 16);
        lo += (hi & 0x7fff) << 16;
        lo += hi >> 15;
        lo = (lo & 0x7fffffff) + (lo >> 31);
        return (_rseed = lo) / 1073741824.f - 1.f;
}

variable_types:
hi
unsigned int

variable_types:
lo
unsigned int

return_type: float


original_code:
static const int64_t calc_song_pos(jack_position_t *xpos, int off) {
  if (!(xpos->valid & JackPositionBBT)) return -1;
  if (off < 0) {
    if (xpos->bar == 1 && xpos->beat == 1 && xpos->tick == 0) off = 0;
    else off = rintf(xpos->beats_per_minute * 4.0 * resync_delay / 60.0);
  }
  int64_t pos =
    off
    + 4 * ((xpos->bar - 1) * xpos->beats_per_bar + (xpos->beat - 1))
    + floor(4.0 * xpos->tick / xpos->ticks_per_beat);
  return pos;
}

canonical_original_code:
static long calc_song_pos(struct jack_position_t *xpos, int off) {
  if (!(xpos->valid & JackPositionBBT)) return -1;
  if (off < 0) {
    if (xpos->bar == 1 && xpos->beat == 1 && xpos->tick == 0) off = 0;
    else off = rintf(xpos->beats_per_minute * 4.0 * resync_delay / 60.0);
  }
  long pos = off
    + 4 * ((xpos->bar - 1) * xpos->beats_per_bar + (xpos->beat - 1))
    + floor(4.0 * xpos->tick / xpos->ticks_per_beat);
  return pos;
}

variable_types: struct jack_position_t { unsigned long unique_1; unsigned long usecs; unsigned int frame_rate; unsigned int frame; enum jack_position_bits_t { JackPositionBBT=16, JackPositionTimecode=32, JackBBTFrameOffset=64, JackAudioVideoRatio=128, JackVideoFrameOffset=256 } valid; int bar; int beat; int tick; double bar_start_tick; float beats_per_bar; float beat_type; double ticks_per_beat; double beats_per_minute; double frame_time; double next_time; unsigned int bbt_offset; float audio_frames_per_video_frame; unsigned int video_offset; int padding[7]; unsigned long unique_2; } *

variable_types: off int

variable_types: pos long

return_type: long

user_defined_types: struct jack_position_t { unsigned long unique_1; unsigned long usecs; unsigned int frame_rate; unsigned int frame; enum jack_position_bits_t valid; int bar; int beat; int tick; double bar_start_tick; float beats_per_bar; float beat_type; double ticks_per_beat; double beats_per_minute; double frame_time; double next_time; unsigned int bbt_offset; float audio_frames_per_video_frame; unsigned int video_offset; int padding[7]; unsigned long unique_2; }


decompiled_code:
void jack_finish()
{
client_state = 2;
j_client = 0LL;
}

canonical_decompiled_code:
void func14()
{
client_state = 2;
j_client = 0LL;
}

original_code:
void jack_finish(void* arg) {
  client_state = Exit;
  j_client = ((void *)0);
}

canonical_original_code:
void jack_finish(void *arg) {
  client_state = Exit;
  j_client = ((void *)0);
}

variable_types:
arg
void *


pdie

decompiled_code:
void __fastcall __noreturn pdie(char *s)
{
fflush(stdout);
perror(s);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(char *s)
{
fflush(stdout);
perror(s);
exit(1);
}

original_code:
void pdie(const char *msg)
{
    fflush(stdout);
    perror(msg);
    exit(1);
}

canonical_original_code:
void pdie(char *msg)
{
    fflush(stdout);
    perror(msg);
    exit(1);
}

variable_types:
msg
char *


die

decompiled_code:
void __noreturn die(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fflush(stdout);
fwrite("Fatal: ", 1uLL, 7uLL, errstd);
vfprintf(errstd, format, arg);
fputc(10, errstd);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fflush(stdout);
fwrite("Fatal: ", 1uLL, 7uLL, errstd);
vfprintf(errstd, format, arg);
fputc(10, errstd);
exit(1);
}

original_code:
void __attribute__ ((format (printf, 1, 2))) die(const char *fmt,...)
{
    va_list ap;
    fflush(stdout);
    fprintf(errstd,"Fatal: ");
    __builtin_va_start(ap,fmt);
    vfprintf(errstd,fmt,ap);
    __builtin_va_end(ap);
    fputc('\n',errstd);
    exit(1);
}

canonical_original_code:
void die(char *fmt, ...)
{
    __builtin_va_list ap;
    fflush(stdout);
    fprintf(errstd,"Fatal: ");
    __builtin_va_start(ap,fmt);
    vfprintf(errstd,fmt,ap);
    __builtin_va_end(ap);
    fputc('\n',errstd);
    exit(1);
}

variable_types:
fmt
char *


name

decompiled_code:
const char *__fastcall name(unsigned int a1)
{
if ( a1 == 2 )
return "Second boot sector";
if ( a1 == 16 )
return "Chain loader";
if ( a1 != 1 )
die("Internal error: Unknown stage code %d", a1);
return "First boot sector";
}

canonical_decompiled_code:
const char *__fastcall func2(unsigned int a1)
{
if ( a1 == 2 )
return "Second boot sector";
if ( a1 == 16 )
return "Chain loader";
if ( a1 != 1 )
func1("Internal error: Unknown stage code %d", a1);
return "First boot sector";
}

original_code:
static char *name(int stage)
{
    switch (stage) {
 case 1:
     return "First boot sector";
 case 2:
     return "Second boot sector";
 case 0x10:
     return "Chain loader";
 default:
     die("Internal error: Unknown stage code %d",stage);
    }
    return ((void *)0);
}

variable_types: stage int