printUsage

decompiled_code:
int __fastcall printUsage(const char *a1, const char *a2)
{
if ( a2 )
fprintf(stderr, "%s\n", a2);
printf("Usage: %s <operation> [options...]\n\n", a1);
puts("Operations has to be one of the following:\n");
puts("Search:");
puts("\t--search\t\tSearches the questions database.");
puts("\t--intitle <string>\tA string that must appear verbatim in the title.");
puts("\t--tagged <string>\tList of tags delimited by semicolons at least one has to be on the questions.");
puts("\t--nottagged <string>\tList of tags delimited by semicolons that must not be in the question.");
putchar(10);
puts("Users:");
puts("\t--users\t\t\tSearches the users database.");
puts("\t--id <string>\t\tList of user ids delimited by a semicolon.");
puts("\t--filter <string>\tA string that must appear in the users name.");
putchar(10);
puts("Questions:");
puts("\t--questions\t\tSearches the questions database with answers.");
puts("\t--id <string>\t\tList of question ids delimited by a semicolon.");
putchar(10);
puts("Generic parameters:\n");
puts("\t--pagesize <size>\tHow many items per page? 100 maximum.");
puts("\t--page <page>\t\tWhat page do you want to see?");
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, const char *a2)
{
if ( a2 )
fprintf(stderr, "%s\n", a2);
printf("Usage: %s <operation> [options...]\n\n", a1);
puts("Operations has to be one of the following:\n");
puts("Search:");
puts("\t--search\t\tSearches the questions database.");
puts("\t--intitle <string>\tA string that must appear verbatim in the title.");
puts("\t--tagged <string>\tList of tags delimited by semicolons at least one has to be on the questions.");
puts("\t--nottagged <string>\tList of tags delimited by semicolons that must not be in the question.");
putchar(10);
puts("Users:");
puts("\t--users\t\t\tSearches the users database.");
puts("\t--id <string>\t\tList of user ids delimited by a semicolon.");
puts("\t--filter <string>\tA string that must appear in the users name.");
putchar(10);
puts("Questions:");
puts("\t--questions\t\tSearches the questions database with answers.");
puts("\t--id <string>\t\tList of question ids delimited by a semicolon.");
putchar(10);
puts("Generic parameters:\n");
puts("\t--pagesize <size>\tHow many items per page? 100 maximum.");
puts("\t--page <page>\t\tWhat page do you want to see?");
return putchar(10);
}

original_code:
void printUsage (const char *name, const char *msg) {
    if (msg != ((void *)0))
        fprintf(stderr, "%s\n", msg);
    printf("Usage: %s <operation> [options...]\n\n", name);
    printf("Operations has to be one of the following:\n\n");
    printf("Search:\n");
    printf("\t--search\t\tSearches the questions database.\n");
    printf("\t--intitle <string>\tA string that must appear verbatim in the title.\n");
    printf("\t--tagged <string>\tList of tags delimited by semicolons at least one has to be on the questions.\n");
    printf("\t--nottagged <string>\tList of tags delimited by semicolons that must not be in the question.\n");
    printf("\n");
    printf("Users:\n");
    printf("\t--users\t\t\tSearches the users database.\n");
    printf("\t--id <string>\t\tList of user ids delimited by a semicolon.\n");
    printf("\t--filter <string>\tA string that must appear in the users name.\n");
    printf("\n");
    printf("Questions:\n");
    printf("\t--questions\t\tSearches the questions database with answers.\n");
    printf("\t--id <string>\t\tList of question ids delimited by a semicolon.\n");
    printf("\n");
    printf("Generic parameters:\n\n");
    printf("\t--pagesize <size>\tHow many items per page? 100 maximum.\n");
    printf("\t--page <page>\t\tWhat page do you want to see?\n");
    printf("\n");
}

canonical_original_code:
void printUsage(char *name, char *msg) {
    if (msg != ((void *)0))
        fprintf(stderr, "%s\n", msg);
    printf("Usage: %s <operation> [options...]\n\n", name);
    printf("Operations has to be one of the following:\n\n");
    printf("Search:\n");
    printf("\t--search\t\tSearches the questions database.\n");
    printf("\t--intitle <string>\tA string that must appear verbatim in the title.\n");
    printf("\t--tagged <string>\tList of tags delimited by semicolons at least one has to be on the questions.\n");
    printf("\t--nottagged <string>\tList of tags delimited by semicolons that must not be in the question.\n");
    printf("\n");
    printf("Users:\n");
    printf("\t--users\t\t\tSearches the users database.\n");
    printf("\t--id <string>\t\tList of user ids delimited by a semicolon.\n");
    printf("\t--filter <string>\tA string that must appear in the users name.\n");
    printf("\n");
    printf("Questions:\n");
    printf("\t--questions\t\tSearches the questions database with answers.\n");
    printf("\t--id <string>\t\tList of question ids delimited by a semicolon.\n");
    printf("\n");
    printf("Generic parameters:\n\n");
    printf("\t--pagesize <size>\tHow many items per page? 100 maximum.\n");
    printf("\t--page <page>\t\tWhat page do you want to see?\n");
    printf("\n");
}

variable_types:
msg
char *


processArguments

repo: ebobby/stackoverflow-cli

decompiled_code:
__int64 __fastcall processArguments(int argc, char **argv, __int64 a3)
{
int v4; // eax
unsigned int v5; // er8
__int64 result; // rax
int longind[7]; // [rsp+0h] [rbp-1Ch] BYREF

*(_OWORD *)a3 = 0LL;
*(_OWORD *)(a3 + 16) = 0LL;
*(_OWORD *)(a3 + 32) = 0LL;
*(_OWORD *)(a3 + 48) = 0LL;
while ( 1 )
{
longind[0] = 0;
v4 = getopt_long(argc, argv, "SUn:g:t:s:p:f:h?", &getopt_long_opts_0, longind);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'Q':
*(_DWORD *)a3 = 3;
break;
case 'S':
*(_DWORD *)a3 = 1;
break;
case 'U':
*(_DWORD *)a3 = 2;
break;
case 'f':
*(_QWORD *)(a3 + 32) = optarg;
break;
case 'g':
*(_QWORD *)(a3 + 16) = optarg;
break;
case 'i':
*(_QWORD *)(a3 + 40) = optarg;
break;
case 'n':
*(_QWORD *)(a3 + 8) = optarg;
break;
case 'p':
*(_QWORD *)(a3 + 56) = optarg;
break;
case 's':
*(_QWORD *)(a3 + 48) = optarg;
break;
case 't':
*(_QWORD *)(a3 + 24) = optarg;
break;
default:
continue;
}
}
if ( *(_DWORD *)a3 )
{
v5 = 1;
if ( *(_DWORD *)a3 == 3 && !*(_QWORD *)(a3 + 40) )
{
printUsage(*argv, "This operation needs --id to be specified.\n");
v5 = 0;
}
result = v5;
}
else
{
printUsage(*argv, 0LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int argc, char **argv, __int64 a3)
{
int v4; // eax
unsigned int v5; // er8
__int64 result; // rax
int longind[7]; // [rsp+0h] [rbp-1Ch] BYREF

*(_OWORD *)a3 = 0LL;
*(_OWORD *)(a3 + 16) = 0LL;
*(_OWORD *)(a3 + 32) = 0LL;
*(_OWORD *)(a3 + 48) = 0LL;
while ( 1 )
{
longind[0] = 0;
v4 = getopt_long(argc, argv, "SUn:g:t:s:p:f:h?", &getopt_long_opts_0, longind);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'Q':
*(_DWORD *)a3 = 3;
break;
case 'S':
*(_DWORD *)a3 = 1;
break;
case 'U':
*(_DWORD *)a3 = 2;
break;
case 'f':
*(_QWORD *)(a3 + 32) = optarg;
break;
case 'g':
*(_QWORD *)(a3 + 16) = optarg;
break;
case 'i':
*(_QWORD *)(a3 + 40) = optarg;
break;
case 'n':
*(_QWORD *)(a3 + 8) = optarg;
break;
case 'p':
*(_QWORD *)(a3 + 56) = optarg;
break;
case 's':
*(_QWORD *)(a3 + 48) = optarg;
break;
case 't':
*(_QWORD *)(a3 + 24) = optarg;
break;
default:
continue;
}
}
if ( *(_DWORD *)a3 )
{
v5 = 1;
if ( *(_DWORD *)a3 == 3 && !*(_QWORD *)(a3 + 40) )
{
func0(*argv, "This operation needs --id to be specified.\n");
v5 = 0;
}
result = v5;
}
else
{
func0(*argv, 0LL);
result = 0LL;
}
return result;
}

original_code:
int processArguments (int argc, char **argv, stackoverflow_cli_opts *opts) {
    static const struct option getopt_long_opts[] = {
        { "search", 0, ((void *)0), 'S' },
        { "nottagged", 1, ((void *)0), 'n' },
        { "tagged", 1, ((void *)0), 'g' },
        { "intitle", 1, ((void *)0), 't' },
        { "pagesize", 1, ((void *)0), 's' },
        { "page", 1, ((void *)0), 'p' },
        { "users", 0, ((void *)0), 'U' },
        { "filter", 1, ((void *)0), 'f' },
        { "id", 1, ((void *)0), 'i' },
        { "questions", 0, ((void *)0), 'Q' },
        { ((void *)0), 0, ((void *)0), 0 }
    };
    char *optstring = "SUn:g:t:s:p:f:h?";
    memset(opts, 0, sizeof(stackoverflow_cli_opts));
    opts->operation = none;
    for (;;) {
        int opt_index = 0;
        int opt = getopt_long(argc, argv, optstring, getopt_long_opts, &opt_index);
        if (opt == -1)
            break;
        switch (opt) {
        case 'S':
            opts->operation = search;
            break;
        case 'U':
            opts->operation = users;
            break;
        case 'Q':
            opts->operation = questions;
            break;
        case 'n':
            opts->nottagged = optarg;
            break;
        case 'g':
            opts->tagged = optarg;
            break;
        case 't':
            opts->intitle = optarg;
            break;
        case 's':
            opts->pagesize = optarg;
            break;
        case 'p':
            opts->page = optarg;
            break;
        case 'f':
            opts->filter = optarg;
            break;
        case 'i':
            opts->id = optarg;
            break;
        case 'h':
        case '?':
        default:
            break;
        }
    }
    if (opts->operation == none) {
        printUsage(argv[0], ((void *)0));
        return 0;
    }
    if (opts->operation == questions && opts->id == ((void *)0)) {
        printUsage(argv[0], "This operation needs --id to be specified.\n");
        return 0;
    }
    return 1;
}

canonical_original_code:
int processArguments(int argc, char **argv, struct stackoverflow_cli_opts *opts) {
    static struct option getopt_long_opts[] = {
        { "search", 0, ((void *)0), 'S' },
        { "nottagged", 1, ((void *)0), 'n' },
        { "tagged", 1, ((void *)0), 'g' },
        { "intitle", 1, ((void *)0), 't' },
        { "pagesize", 1, ((void *)0), 's' },
        { "page", 1, ((void *)0), 'p' },
        { "users", 0, ((void *)0), 'U' },
        { "filter", 1, ((void *)0), 'f' },
        { "id", 1, ((void *)0), 'i' },
        { "questions", 0, ((void *)0), 'Q' },
        { ((void *)0), 0, ((void *)0), 0 }
    };
    char *optstring = "SUn:g:t:s:p:f:h?";
    memset(opts, 0, sizeof(stackoverflow_cli_opts));
    opts->operation = none;
    for (;;) {
        int opt_index = 0;
        int opt = getopt_long(argc, argv, optstring, getopt_long_opts, &opt_index);
        if (opt == -1)
            break;
        switch (opt) {
        case 'S':
            opts->operation = search;
            break;
        case 'U':
            opts->operation = users;
            break;
        case 'Q':
            opts->operation = questions;
            break;
        case 'n':
            opts->nottagged = optarg;
            break;
        case 'g':
            opts->tagged = optarg;
            break;
        case 't':
            opts->intitle = optarg;
            break;
        case 's':
            opts->pagesize = optarg;
            break;
        case 'p':
            opts->page = optarg;
            break;
        case 'f':
            opts->filter = optarg;
            break;
        case 'i':
            opts->id = optarg;
            break;
        case 'h':
        case '?':
        default:
            break;
        }
    }
    if (opts->operation == none) {
        printUsage(argv[0], ((void *)0));
        return 0;
    }
    if (opts->operation == questions && opts->id == ((void *)0)) {
        printUsage(argv[0], "This operation needs --id to be specified.\n");
        return 0;
    }
    return 1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct stackoverflow_cli_opts { enum stackoverflow_operation { none=0, search=1, users=2, questions=3, user=4 } operation; char *nottagged; char *tagged; char *intitle; char *filter; char *id; char *pagesize; char *page; } *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types:
optstring
char *

variable_types: opt int

return_type: int

user_defined_types: struct stackoverflow_cli_opts { enum stackoverflow_operation operation; char *nottagged; char *tagged; char *intitle; char *filter; char *id; char *pagesize; char *page; }


requestCallback

decompiled_code:
size_t __fastcall requestCallback(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v4; // rsi
size_t result; // rax
char *v7; // rax
__int64 v8; // rdx
size_t v9; // rax

v4 = a3 * a2;
if ( v4 )
{
v7 = (char *)realloc(*(void **)(a4 + 8), v4 + *(_QWORD *)a4 + 1);
*(_QWORD *)(a4 + 8) = v7;
if ( !v7 )
{
printf("Not enough memory!");
exit(1);
}
memcpy(&v7[*(_QWORD *)a4], src, v4);
v8 = *(_QWORD *)(a4 + 8);
v9 = v4 + *(_QWORD *)a4;
*(_QWORD *)a4 = v9;
*(_BYTE *)(v8 + v9) = 0;
result = v4;
}
else
{
result = 0LL;
*(_QWORD *)(a4 + 8) = 0LL;
*(_QWORD *)a4 = 0LL;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v4; // rsi
size_t result; // rax
char *v7; // rax
__int64 v8; // rdx
size_t v9; // rax

v4 = a3 * a2;
if ( v4 )
{
v7 = (char *)realloc(*(void **)(a4 + 8), v4 + *(_QWORD *)a4 + 1);
*(_QWORD *)(a4 + 8) = v7;
if ( !v7 )
{
printf("Not enough memory!");
exit(1);
}
memcpy(&v7[*(_QWORD *)a4], src, v4);
v8 = *(_QWORD *)(a4 + 8);
v9 = v4 + *(_QWORD *)a4;
*(_QWORD *)a4 = v9;
*(_BYTE *)(v8 + v9) = 0;
result = v4;
}
else
{
result = 0LL;
*(_QWORD *)(a4 + 8) = 0LL;
*(_QWORD *)a4 = 0LL;
}
return result;
}

original_code:
static size_t requestCallback (char *ptr, size_t size, size_t nmemb, void *usr) {
    size_t realsize = size * nmemb;
    responseObject *response = (responseObject *)usr;
    if (realsize != 0) {
        response->data = realloc(response->data, response->size + realsize + 1);
        if (response->data == ((void *)0)) {
            printf("Not enough memory!");
            exit(1);
        }
        memcpy(&response->data[response->size], ptr, realsize);
        response->size += realsize;
        response->data[response->size] = 0;
    } else {
        response->data = ((void *)0);
        response->size = 0;
    }
    return realsize;
}

canonical_original_code:
static unsigned long requestCallback(char *ptr, unsigned long size, unsigned long nmemb, void *usr) {
    unsigned long realsize = size * nmemb;
    struct responseObject *response = (responseObject *)usr;
    if (realsize != 0) {
        response->data = realloc(response->data, response->size + realsize + 1);
        if (response->data == ((void *)0)) {
            printf("Not enough memory!");
            exit(1);
        }
        memcpy(&response->data[response->size], ptr, realsize);
        response->size += realsize;
        response->data[response->size] = 0;
    } else {
        response->data = ((void *)0);
        response->size = 0;
    }
    return realsize;
}

variable_types:
ptr
char *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
usr
void *

variable_types:
realsize
unsigned long

variable_types: struct responseObject { unsigned long size; char *data; } *

return_type: unsigned long


freeWebResponse

decompiled_code:
void __fastcall freeWebResponse(_QWORD *a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = (void *)a1[1];
if ( v2 )
free(v2);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = (void *)a1[1];
if ( v2 )
free(v2);
*a1 = 0LL;
}
}

original_code:
void freeWebResponse (responseObject *response) {
    if (response == ((void *)0))
        return;
    if (response->data != ((void *)0))
        free(response->data);
    response->size = 0;
}

canonical_original_code:
void freeWebResponse(struct responseObject *response) {
    if (response == ((void *)0))
        return;
    if (response->data != ((void *)0))
        free(response->data);
    response->size = 0;
}

return_type: void

user_defined_types: struct responseObject { unsigned long size; char *data; }


IoNotifyInit

repo: ebortolini/MonitorB

decompiled_code:
int IoNotifyInit()
{
return inotify_init();
}

canonical_decompiled_code:
int func0()
{
return inotify_init();
}

original_code:
int IoNotifyInit(){
 return inotify_init();
}


AddWatcher

decompiled_code:
__int64 __fastcall AddWatcher(char *name)
{
int v1; // eax
unsigned int v2; // er8

if ( !name )
return 0xFFFFFFFFLL;
v1 = inotify_add_watch(*((_DWORD *)name + 125), name, *((_DWORD *)name + 127));
v2 = 1;
*((_DWORD *)name + 126) = v1;
if ( v1 < 0 )
v2 = -1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *name)
{
int v1; // eax
unsigned int v2; // er8

if ( !name )
return 0xFFFFFFFFLL;
v1 = inotify_add_watch(*((_DWORD *)name + 125), name, *((_DWORD *)name + 127));
v2 = 1;
*((_DWORD *)name + 126) = v1;
if ( v1 < 0 )
v2 = -1;
return v2;
}

original_code:
int AddWatcher(TargetToMonitor * Target){
 if(!Target )
  return -1;
 Target->WatchHandle = inotify_add_watch(Target->InitHandle,
   Target->DictoryName,Target->Flags);
 if (Target->WatchHandle < 0)
  return -1;
 return 1;
}

canonical_original_code:
int AddWatcher(struct STargetToMonitor *Target){
 if(!Target )
  return -1;
 Target->WatchHandle = inotify_add_watch(Target->InitHandle,
   Target->DictoryName,Target->Flags);
 if (Target->WatchHandle < 0)
  return -1;
 return 1;
}

variable_types: struct STargetToMonitor { char DictoryName[500]; int InitHandle; int WatchHandle; int Flags; struct STargetToMonitor *Next; } *


RemoveWatcher

decompiled_code:
int __fastcall RemoveWatcher(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
result = inotify_rm_watch(*(_DWORD *)(v1 + 500), *(_DWORD *)(v1 + 504));
v1 = *(_QWORD *)(v1 + 512);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
result = inotify_rm_watch(*(_DWORD *)(v1 + 500), *(_DWORD *)(v1 + 504));
v1 = *(_QWORD *)(v1 + 512);
}
while ( v1 );
}
return result;
}

original_code:
void RemoveWatcher(TargetToMonitor * Queue){
 TargetToMonitor * AuxQueue = Queue;
 while(AuxQueue){
  inotify_rm_watch(AuxQueue->InitHandle, AuxQueue->WatchHandle);
  AuxQueue = AuxQueue->Next;
 }
}

canonical_original_code:
void RemoveWatcher(struct STargetToMonitor *Queue){
 struct STargetToMonitor *AuxQueue = Queue;
 while(AuxQueue){
  inotify_rm_watch(AuxQueue->InitHandle, AuxQueue->WatchHandle);
  AuxQueue = AuxQueue->Next;
 }
}

user_defined_types: struct STargetToMonitor { char DictoryName[500]; int InitHandle; int WatchHandle; int Flags; struct STargetToMonitor *Next; }


InstallWatchers

decompiled_code:
__int64 __fastcall InstallWatchers(char *name)
{
char *v1; // rbx
int v2; // eax

if ( !name )
return 1LL;
v1 = name;
do
{
v2 = AddWatcher(v1);
if ( v2 == -1 )
_assert_fail("ReturnedValue != -1", "IoNotify.c", 0x24u, "InstallWatchers");
if ( v2 < 0 )
return 0xFFFFFFFFLL;
v1 = (char *)*((_QWORD *)v1 + 64);
}
while ( v1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *name)
{
char *v1; // rbx
int v2; // eax

if ( !name )
return 1LL;
v1 = name;
do
{
v2 = func1(v1);
if ( v2 == -1 )
_assert_fail("ReturnedValue != -1", "IoNotify.c", 0x24u, "InstallWatchers");
if ( v2 < 0 )
return 0xFFFFFFFFLL;
v1 = (char *)*((_QWORD *)v1 + 64);
}
while ( v1 );
return 1LL;
}

original_code:
int InstallWatchers(TargetToMonitor * Queue){
 TargetToMonitor * AuxQueue = Queue;
 int ReturnedValue;
 while(AuxQueue){
  ReturnedValue = AddWatcher(AuxQueue);
  ((void) sizeof ((ReturnedValue != -1) ? 1 : 0), __extension__ ({ if (ReturnedValue != -1) ; else __assert_fail ("ReturnedValue != -1", "IoNotify.c", 36, __extension__ __PRETTY_FUNCTION__); }));
  if(ReturnedValue < 0){
   return -1;
  }
  AuxQueue = AuxQueue->Next;
 }
 return 1;
}

canonical_original_code:
int InstallWatchers(struct STargetToMonitor *Queue){
 struct STargetToMonitor *AuxQueue = Queue;
 int ReturnedValue;
 while(AuxQueue){
  ReturnedValue = AddWatcher(AuxQueue);
  ((void) sizeof ((ReturnedValue != -1) ? 1 : 0), __extension__ ({ if (ReturnedValue != -1) ; else __assert_fail ("ReturnedValue != -1", "IoNotify.c", 36, __extension__ __PRETTY_FUNCTION__); }));
  if(ReturnedValue < 0){
   return -1;
  }
  AuxQueue = AuxQueue->Next;
 }
 return 1;
}

variable_types: ReturnedValue int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v5; // eax
_BYTE v6[500]; // [rsp+0h] [rbp-208h] BYREF
int v7; // [rsp+1F4h] [rbp-14h]
int v8; // [rsp+1F8h] [rbp-10h]

v7 = IoNotifyInit(argc, argv, envp);
if ( v7 < 0 )
{
printf("\n\tError");
v8 = 966;
if ( v7 < 0 )
return -1;
}
else
{
v8 = 966;
}
v3 = readFile(v6);
printQueueInfo(v3);
if ( (int)InstallWatchers(v3) >= 0 )
{
setbuf(stdout, 0LL);
while ( 1 )
{
setbuf(stdout, 0LL);
v5 = HasEvents((unsigned int)v7, 2LL);
if ( v5 < 0 )
break;
if ( v5 )
ProcessEvent(v6, v3);
sleep(2u);
}
}
return -1;
}

original_code:
int main(){
 int ret;
 TargetToMonitor *Target;
 Info Info;
 Info.InitHandle = IoNotifyInit();
 if(Info.InitHandle < 0)
 {
  printf("\n\tError");
 }
 Info.Flags = 0x00000100 | 0x00000200 | 0x00000002 | 0x00000004 | 0x00000040 | 0x00000080;
 if(Info.InitHandle < 0)
  return -1;
 Target = readFile(&Info);
 printQueueInfo(Target);
 ret = InstallWatchers(Target);
 if(ret < 0)
  return -1;
 setbuf(stdout, ((void *)0));
 while(1){
  setbuf(stdout, ((void *)0));
  ret = HasEvents(Info.InitHandle, 2);
  if (ret < 0)
   return -1;
  else if(ret)
   ProcessEvent(&Info, Target);
  sleep(2);
 }
 RemoveWatcher(Target);
    close( Info.InitHandle );
 return 1;
}

canonical_original_code:
int main(){
 int ret;
 struct STargetToMonitor *Target;
 struct SInfo Info;
 Info.InitHandle = IoNotifyInit();
 if(Info.InitHandle < 0)
 {
  printf("\n\tError");
 }
 Info.Flags = 0x00000100 | 0x00000200 | 0x00000002 | 0x00000004 | 0x00000040 | 0x00000080;
 if(Info.InitHandle < 0)
  return -1;
 Target = readFile(&Info);
 printQueueInfo(Target);
 ret = InstallWatchers(Target);
 if(ret < 0)
  return -1;
 setbuf(stdout, ((void *)0));
 while(1){
  setbuf(stdout, ((void *)0));
  ret = HasEvents(Info.InitHandle, 2);
  if (ret < 0)
   return -1;
  else if(ret)
   ProcessEvent(&Info, Target);
  sleep(2);
 }
 RemoveWatcher(Target);
    close( Info.InitHandle );
 return 1;
}

variable_types: ret int

variable_types: struct SInfo { char Directory[500]; int InitHandle; int Flags; }


CreateNode

decompiled_code:
void *CreateNode()
{
return malloc(0x208uLL);
}

canonical_decompiled_code:
void *func0()
{
return malloc(0x208uLL);
}

original_code:
TargetToMonitor * CreateNode(){
 TargetToMonitor * NewNode;
 NewNode = (TargetToMonitor *)malloc(sizeof(TargetToMonitor));
 if(!NewNode){
  return ((void *)0);
 }
 return NewNode;
}

canonical_original_code:
struct STargetToMonitor *CreateNode(){
 struct STargetToMonitor *NewNode;
 NewNode = (struct STargetToMonitor *)malloc(sizeof(TargetToMonitor));
 if(!NewNode){
  return ((void *)0);
 }
 return NewNode;
}

return_type: struct STargetToMonitor { char DictoryName[500]; int InitHandle; int WatchHandle; int Flags; struct STargetToMonitor *Next; } *


initData

decompiled_code:
__int64 __fastcall initData(__int64 a1, __int64 a2)
{
int v2; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *(_DWORD *)(a2 + 504);
*(_QWORD *)(a1 + 512) = 0LL;
*(_DWORD *)(a1 + 508) = v2;
*(_DWORD *)(a1 + 500) = *(_DWORD *)(a2 + 500);
strcpy((char *)a1, (const char *)a2);
return 1LL;
}

original_code:
int initData(TargetToMonitor * Node, Info * info){
 if(!Node)
  return -1;
 Node->Next = ((void *)0);
 Node->Flags = info->Flags;
 Node->InitHandle = info->InitHandle;
 strcpy(Node->DictoryName,info->Directory);
 return 1;
}

canonical_original_code:
int initData(struct STargetToMonitor *Node, struct SInfo *info){
 if(!Node)
  return -1;
 Node->Next = ((void *)0);
 Node->Flags = info->Flags;
 Node->InitHandle = info->InitHandle;
 strcpy(Node->DictoryName,info->Directory);
 return 1;
}

variable_types: struct SInfo { char Directory[500]; int InitHandle; int Flags; } *


AddNewNode

decompiled_code:
void *__fastcall AddNewNode(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
void *v4; // rax
void *v5; // r12
void *v7; // rax

v2 = a1;
if ( a1 )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[64];
}
while ( v2 );
v4 = CreateNode();
v3[64] = v4;
v5 = v4;
if ( v4 )
{
v5 = a1;
initData((__int64)v4, a2);
}
return v5;
}
v7 = CreateNode();
v5 = v7;
if ( !v7 )
return v5;
initData((__int64)v7, a2);
return v5;
}

canonical_decompiled_code:
void *__fastcall func2(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
void *v4; // rax
void *v5; // r12
void *v7; // rax

v2 = a1;
if ( a1 )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[64];
}
while ( v2 );
v4 = func0();
v3[64] = v4;
v5 = v4;
if ( v4 )
{
v5 = a1;
func1((__int64)v4, a2);
}
return v5;
}
v7 = func0();
v5 = v7;
if ( !v7 )
return v5;
func1((__int64)v7, a2);
return v5;
}

original_code:
TargetToMonitor * AddNewNode(TargetToMonitor * QueueOfTargets, Info * info){
 TargetToMonitor * AuxTarget;
 if(!QueueOfTargets){
  AuxTarget = CreateNode();
  if(!AuxTarget)
   return ((void *)0);
  initData(AuxTarget, info);
  return AuxTarget;
 }
 AuxTarget = QueueOfTargets;
 while(AuxTarget->Next != ((void *)0))
  AuxTarget = AuxTarget->Next;
 AuxTarget->Next = CreateNode();
 AuxTarget = AuxTarget->Next;
 if(!AuxTarget)
  return ((void *)0);
 initData(AuxTarget, info);
 return QueueOfTargets;
}

canonical_original_code:
struct STargetToMonitor *AddNewNode(struct STargetToMonitor *QueueOfTargets, struct SInfo *info){
 struct STargetToMonitor *AuxTarget;
 if(!QueueOfTargets){
  AuxTarget = CreateNode();
  if(!AuxTarget)
   return ((void *)0);
  initData(AuxTarget, info);
  return AuxTarget;
 }
 AuxTarget = QueueOfTargets;
 while(AuxTarget->Next != ((void *)0))
  AuxTarget = AuxTarget->Next;
 AuxTarget->Next = CreateNode();
 AuxTarget = AuxTarget->Next;
 if(!AuxTarget)
  return ((void *)0);
 initData(AuxTarget, info);
 return QueueOfTargets;
}

variable_types:
QueueOfTargets
struct STargetToMonitor *

user_defined_types: struct SInfo { char Directory[500]; int InitHandle; int Flags; }


printQueueInfo

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

if ( a1 )
{
v1 = a1;
do
{
printf("\n\tDir Name: %s", (const char *)v1);
v1 = *(_QWORD *)(v1 + 512);
}
while ( v1 );
}
return putchar(10);
}

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

if ( a1 )
{
v1 = a1;
do
{
printf("\n\tDir Name: %s", (const char *)v1);
v1 = *(_QWORD *)(v1 + 512);
}
while ( v1 );
}
return putchar(10);
}

original_code:
void printQueueInfo(TargetToMonitor * QueueOfTargets){
 TargetToMonitor * AuxTarget = QueueOfTargets;
 while (AuxTarget){
  printf("\n\tDir Name: %s", AuxTarget->DictoryName);
  AuxTarget = AuxTarget->Next;
 }
 printf("\n");
}

canonical_original_code:
void printQueueInfo(struct STargetToMonitor *QueueOfTargets){
 struct STargetToMonitor *AuxTarget = QueueOfTargets;
 while (AuxTarget){
  printf("\n\tDir Name: %s", AuxTarget->DictoryName);
  AuxTarget = AuxTarget->Next;
 }
 printf("\n");
}


HasEvents

decompiled_code:
int __fastcall HasEvents(int a1, int a2)
{
__time_t v2; // r8
struct timeval v4; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v2 = a2;
memset(&readfds, 0, sizeof(readfds));
v4.tv_usec = 0LL;
if ( a2 <= 0 )
v2 = 1LL;
v4.tv_sec = v2;
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
return select(1024, &readfds, 0LL, 0LL, &v4);
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2)
{
__time_t v2; // r8
struct timeval v4; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v2 = a2;
memset(&readfds, 0, sizeof(readfds));
v4.tv_usec = 0LL;
if ( a2 <= 0 )
v2 = 1LL;
v4.tv_sec = v2;
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
return select(1024, &readfds, 0LL, 0LL, &v4);
}

original_code:
int HasEvents(int Handle, int TimeOut){
 fd_set rfds;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
 struct timeval Time;
 Time.tv_sec = TimeOut < 1 ? 1 : TimeOut;
 Time.tv_usec = 0;
 ((void) (((&rfds)->__fds_bits)[((Handle) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((Handle) % (8 * (int) sizeof (__fd_mask)))))));
 return select (1024, &rfds, ((void *)0), ((void *)0), &Time);
}

canonical_original_code:
int HasEvents(int Handle, int TimeOut){
 struct fd_set rfds;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
 struct timeval Time;
 Time.tv_sec = TimeOut < 1 ? 1 : TimeOut;
 Time.tv_usec = 0;
 ((void) (((&rfds)->__fds_bits)[((Handle) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((Handle) % (8 * (int) sizeof (__fd_mask)))))));
 return select (1024, &rfds, ((void *)0), ((void *)0), &Time);
}

variable_types: Handle int

variable_types: TimeOut int

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

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


GetTarget

decompiled_code:
__int64 __fastcall GetTarget(int a1, __int64 a2)
{
if ( !a2 || a1 < 0 )
return 0LL;
while ( *(_DWORD *)(a2 + 504) != a1 )
{
a2 = *(_QWORD *)(a2 + 512);
if ( !a2 )
return 0LL;
}
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, __int64 a2)
{
if ( !a2 || a1 < 0 )
return 0LL;
while ( *(_DWORD *)(a2 + 504) != a1 )
{
a2 = *(_QWORD *)(a2 + 512);
if ( !a2 )
return 0LL;
}
return a2;
}

original_code:
TargetToMonitor * GetTarget(int Descriptor, TargetToMonitor * Targets){
 if(!Targets || Descriptor < 0)
  return ((void *)0);
 TargetToMonitor * AuxTarget = Targets;
 while(AuxTarget){
  if(AuxTarget->WatchHandle == Descriptor)
   return AuxTarget;
  AuxTarget = AuxTarget->Next;
 }
 return ((void *)0);
}

canonical_original_code:
struct STargetToMonitor *GetTarget(int Descriptor, struct STargetToMonitor *Targets){
 if(!Targets || Descriptor < 0)
  return ((void *)0);
 struct STargetToMonitor *AuxTarget = Targets;
 while(AuxTarget){
  if(AuxTarget->WatchHandle == Descriptor)
   return AuxTarget;
  AuxTarget = AuxTarget->Next;
 }
 return ((void *)0);
}

variable_types: Descriptor int

variable_types:
Targets
struct STargetToMonitor *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
const char *v4; // rax
char *i; // rbp
int result; // eax

if ( argc == 3 )
{
v3 = (void *)TKCreate((char *)argv[1], (char *)argv[2]);
v4 = (const char *)TKGetNextToken(v3);
for ( i = (char *)v4; v4; i = (char *)v4 )
{
puts(v4);
free(i);
v4 = (const char *)TKGetNextToken(v3);
}
TKDestroy(v3);
result = 0;
}
else
{
puts("Error: Invalid number of arguments!!!");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
const char *v4; // rax
char *i; // rbp
int result; // eax

if ( argc == 3 )
{
v3 = (void *)TKCreate((char *)argv[1], (char *)argv[2]);
v4 = (const char *)func8(v3);
for ( i = (char *)v4; v4; i = (char *)v4 )
{
puts(v4);
free(i);
v4 = (const char *)func8(v3);
}
func7(v3);
result = 0;
}
else
{
puts("Error: Invalid number of arguments!!!");
result = -1;
}
return result;
}

original_code:
int main(int argc, char **argv){
 TokenizerT *tk;
 int size;
 char* token;
 if (argc!=3){
  puts("Error: Invalid number of arguments!!!");
  return -1;
 }
 size=strlen(argv[1]);
 tk = TKCreate(argv[1],argv[2]);
 do{
  token = TKGetNextToken(tk);
  if(token!=0){
   printf("%s\n",token);
   free(token);
  }
 }while(token!=0);
 TKDestroy(tk);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 struct TokenizerT_ *tk;
 int size;
 char *token;
 if (argc!=3){
  puts("Error: Invalid number of arguments!!!");
  return -1;
 }
 size=strlen(argv[1]);
 tk = TKCreate(argv[1],argv[2]);
 do{
  token = TKGetNextToken(tk);
  if(token!=0){
   printf("%s\n",token);
   free(token);
  }
 }while(token!=0);
 TKDestroy(tk);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct TokenizerT_ { char *sep; char *string; char *currPos; } *

variable_types: size int

variable_types:
token
char *


TKDestroy

decompiled_code:
void __fastcall TKDestroy(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void TKDestroy(TokenizerT *tk) {
 free(tk->sep);
 free(tk->string);
 free(tk);
}

canonical_original_code:
void TKDestroy(struct TokenizerT_ *tk) {
 free(tk->sep);
 free(tk->string);
 free(tk);
}

user_defined_types: struct TokenizerT_ { char *sep; char *string; char *currPos; }


TKGetNextToken

decompiled_code:
char *__fastcall TKGetNextToken(const char **a1)
{
const char *v1; // r13
const char *v2; // r14
const char *v3; // rbx
char *v4; // rax
char *v5; // rbp
char *result; // rax
char *v7; // r13
const char *v8; // rbx
int v9; // er13
int v10; // eax
size_t v11; // rbp
char *v12; // r13

v1 = *a1;
v2 = a1[2];
v3 = v2;
v4 = strpbrk(v2, *a1);
if ( v4 )
{
v5 = v4;
while ( v2[1] )
{
v3 = v5 + 1;
if ( v2 != v5 )
{
v9 = strlen(v2);
v10 = strlen(v5);
v11 = v9 - v10;
v12 = (char *)malloc(v9 - v10 + 1);
strncpy(v12, v2, v11);
v12[v11] = 0;
result = v12;
a1[2] = v3;
return result;
}
a1[2] = v3;
v5 = strpbrk(v5 + 1, v1);
if ( !v5 )
goto LABEL_10;
v2 = v3;
}
if ( !*v2 || v2 == v5 )
return 0LL;
v3 = v2;
}
else
{
LABEL_10:
if ( !*v3 )
return 0LL;
}
v7 = strdup(v3);
v8 = &v3[strlen(v3)];
result = v7;
a1[2] = v8;
return result;
}

canonical_decompiled_code:
char *__fastcall func8(const char **a1)
{
const char *v1; // r13
const char *v2; // r14
const char *v3; // rbx
char *v4; // rax
char *v5; // rbp
char *result; // rax
char *v7; // r13
const char *v8; // rbx
int v9; // er13
int v10; // eax
size_t v11; // rbp
char *v12; // r13

v1 = *a1;
v2 = a1[2];
v3 = v2;
v4 = strpbrk(v2, *a1);
if ( v4 )
{
v5 = v4;
while ( v2[1] )
{
v3 = v5 + 1;
if ( v2 != v5 )
{
v9 = strlen(v2);
v10 = strlen(v5);
v11 = v9 - v10;
v12 = (char *)malloc(v9 - v10 + 1);
strncpy(v12, v2, v11);
v12[v11] = 0;
result = v12;
a1[2] = v3;
return result;
}
a1[2] = v3;
v5 = strpbrk(v5 + 1, v1);
if ( !v5 )
goto LABEL_10;
v2 = v3;
}
if ( !*v2 || v2 == v5 )
return 0LL;
v3 = v2;
}
else
{
LABEL_10:
if ( !*v3 )
return 0LL;
}
v7 = strdup(v3);
v8 = &v3[strlen(v3)];
result = v7;
a1[2] = v8;
return result;
}

original_code:
char *TKGetNextToken(TokenizerT *tk) {
 char* delim;
 char* token;
 int length;
 delim = strpbrk(tk->currPos,tk->sep);
 while(delim!=((void *)0) && tk->currPos[1]!='\0'){
  if(delim!=tk->currPos){
   length= (strlen(tk->currPos)-strlen(delim));
   token= (char*)malloc(length+1);
   strncpy(token,tk->currPos,length);
   token[length]='\0';
   tk->currPos = delim+1;
   return token;
   }
  else{
   tk->currPos = tk->currPos+1; delim = strpbrk(tk->currPos,
   tk->sep);
   }
  }
 if (tk->currPos[0]!='\0'&& tk->currPos!=delim){
  token = strdup(tk->currPos);
  tk->currPos=tk->currPos+strlen(tk->currPos);
  return token;
 }
  return 0;
}

canonical_original_code:
char *TKGetNextToken(struct TokenizerT_ *tk) {
 char *delim;
 char *token;
 int length;
 delim = strpbrk(tk->currPos,tk->sep);
 while(delim!=((void *)0) && tk->currPos[1]!='\0'){
  if(delim!=tk->currPos){
   length= (strlen(tk->currPos)-strlen(delim));
   token= (char *)malloc(length+1);
   strncpy(token,tk->currPos,length);
   token[length]='\0';
   tk->currPos = delim+1;
   return token;
   }
  else{
   tk->currPos = tk->currPos+1; delim = strpbrk(tk->currPos,
   tk->sep);
   }
  }
 if (tk->currPos[0]!='\0'&& tk->currPos!=delim){
  token = strdup(tk->currPos);
  tk->currPos=tk->currPos+strlen(tk->currPos);
  return token;
 }
  return 0;
}

variable_types:
delim
char *

variable_types: length int

return_type: char *


decompiled_code:
__int64 init_net()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
int init_net()
{
 return 0;
}

canonical_original_code:
int init_net()
{
 return 0;
}


decompiled_code:
void cleanup_net()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void cleanup_net()
{
}

canonical_original_code:
void cleanup_net()
{
}


decompiled_code:
__int64 net_errno()
{
return (unsigned int)*_errno_location();
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)*_errno_location();
}

original_code:
int net_errno()
{
 return (*__errno_location ());
}


decompiled_code:
// attributes: thunk
int net_close(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int func3(int fd)
{
return close(fd);
}

original_code:
int net_close(int s)
{
 return close(s);
}

variable_types: s int


decompiled_code:
int __fastcall net_ioctl(int fd, unsigned __int64 request)
{
return ioctl(fd, request);
}

canonical_decompiled_code:
int __fastcall func4(int fd, unsigned __int64 request)
{
return ioctl(fd, request);
}

original_code:
int net_ioctl(int s, long cmd, unsigned long* argp)
{
 return ioctl(s, cmd, argp);
}

canonical_original_code:
int net_ioctl(int s, long cmd, unsigned long *argp)
{
 return ioctl(s, cmd, argp);
}

variable_types: cmd long

variable_types:
argp
unsigned long *


msleep

decompiled_code:
// attributes: thunk
int msleep(__useconds_t useconds)
{
return usleep(useconds);
}

canonical_decompiled_code:
int func0(__useconds_t useconds)
{
return usleep(useconds);
}

original_code:
void msleep(int microsec) {
 usleep((unsigned long) microsec);
}

variable_types: microsec int


decompiled_code:
__int64 *device_init()
{
__int64 v0; // rax
_QWORD *v1; // rdx
__int64 *result; // rax

usb_find_busses();
usb_find_devices();
v0 = usb_get_busses();
if ( !v0 )
return 0LL;
v1 = (_QWORD *)v0;
while ( 1 )
{
result = (__int64 *)v1[515];
if ( result )
break;
LABEL_8:
v1 = (_QWORD *)*v1;
if ( !v1 )
return 0LL;
}
while ( *((_DWORD *)result + 1034) != 133523 )
{
result = (__int64 *)*result;
if ( !result )
goto LABEL_8;
}
return result;
}

canonical_decompiled_code:
__int64 *func1()
{
__int64 v0; // rax
_QWORD *v1; // rdx
__int64 *result; // rax

usb_find_busses();
usb_find_devices();
v0 = usb_get_busses();
if ( !v0 )
return 0LL;
v1 = (_QWORD *)v0;
while ( 1 )
{
result = (__int64 *)v1[515];
if ( result )
break;
LABEL_8:
v1 = (_QWORD *)*v1;
if ( !v1 )
return 0LL;
}
while ( *((_DWORD *)result + 1034) != 133523 )
{
result = (__int64 *)*result;
if ( !result )
goto LABEL_8;
}
return result;
}

original_code:
struct usb_device *device_init()
{
    struct usb_bus *usb_bus;
    struct usb_device *dev;
    usb_find_busses();
    usb_find_devices();
    for (usb_bus = usb_get_busses(); usb_bus; usb_bus = usb_bus->next) {
        for (dev = usb_bus->devices; dev; dev = dev->next)
            {
                if ((dev->descriptor.idVendor == 0x0993) &&
                    (dev->descriptor.idProduct == 0x0002))
                    {
                        return dev;
                    }
            }
    }
    return ((void *)0);
}

variable_types: struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *devices; unsigned int location; struct usb_device *root_dev; } *

variable_types: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device *devices; unsigned int location; struct usb_device *root_dev; } *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *

user_defined_types: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus *bus; struct usb_device_descriptor descriptor; struct usb_config_descriptor *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; }

user_defined_types: struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface *interface; unsigned char *extra; int extralen; }

user_defined_types: struct usb_interface { struct usb_interface_descriptor *altsetting; int num_altsetting; }

user_defined_types: struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor *endpoint; unsigned char *extra; int extralen; }


decompiled_code:
__int64 __fastcall parse_int(__int64 a1, int *a2)
{
__int64 result; // rax
int v3; // edx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

result = strtol((const char *)(a1 + *a2), &endptr, 10);
v3 = (_DWORD)endptr + *a2 - (a1 + *a2);
*a2 = v3;
if ( *(_BYTE *)(a1 + v3) == 44 )
*a2 = v3 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int *a2)
{
__int64 result; // rax
int v3; // edx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

result = strtol((const char *)(a1 + *a2), &endptr, 10);
v3 = (_DWORD)endptr + *a2 - (a1 + *a2);
*a2 = v3;
if ( *(_BYTE *)(a1 + v3) == 44 )
*a2 = v3 + 1;
return result;
}

original_code:
int parse_int(char *msg, int *offset)
{
    char *t;
    int i;
    i = strtol(&msg[*offset], &t, 10);
    *offset = *offset + (t-&msg[*offset]);
    if (msg[*offset]==',')
        *offset = *offset + 1;
    return i;
}

variable_types:
msg
char *

variable_types:
offset
int *

variable_types:
t
char *

variable_types: i int


decompiled_code:
void __fastcall cleanup_command(__int64 a1)
{
if ( a1 )
{
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
}
}

original_code:
void cleanup_command(struct reader_command *command)
{
    if (command == ((void *)0))
        return;
    memset(command, 0, sizeof(struct reader_command));
    command->cmd = r_NULL;
    command->ip1 = 0;
    command->ip2 = 0;
    command->n = 0;
    if (command->sp1 != ((void *)0)) {
        free(command->sp1);
        command->sp1 = ((void *)0);
    }
}

variable_types: struct reader_command { enum reader_command_t { r_NULL=0, r_gethostbyname=1, r_socket=2, r_connect=3, r_send=4, r_recv=5, r_close=6 } cmd; int n; char *sp1; int ip1; int ip2; } *

user_defined_types: struct reader_command { enum reader_command_t cmd; int n; char *sp1; int ip1; int ip2; }


repo: ebylaska/Simple-CPSD

decompiled_code:
void __fastcall set_Dirac_alpha(float a1)
{
int v1; // xmm0_4

*(float *)&v1 = a1 * 0.6666666666666666;
alpha = v1;
}

variable_types: aa float


decompiled_code:
float Dirac_alpha()
{
return *(float *)α
}

canonical_decompiled_code:
float func1()
{
return *(float *)α
}

original_code:
float Dirac_alpha()
{
   return alpha;
}

canonical_original_code:
float Dirac_alpha()
{
   return alpha;
}

return_type: float


variable_types: ispin int

variable_types:
rho
float []

variable_types:
vx
float []

variable_types:
ex
float []

variable_types: n float

variable_types: xi float

variable_types: f float

variable_types: df float


phafac

variable_types: nfft int

variable_types: pi float

variable_types:
unitg
float *

variable_types: nion int

variable_types: ii int

variable_types: k int

variable_types: nffth int

variable_types:
rex
float *

variable_types:
qex
float *


strfac

original_code:
void strfac(const int nfft,
               const float *ex1,
               const float *ex2,
               const float *ex3,
               float *exi)
{
   int i,j,k,ir,jr,kr,kk,nffth;
   nffth = nfft/2;
   kk = 0;
   kr = 0;
   for (k=0; k<nfft; ++k)
   {
      jr = 0;
      for (j=0; j<nfft; ++j)
      {
         ir = 0;
         for (i=0; i<=nffth; ++i)
         {
            exi[kk] = ex1[ir] * (ex2[jr]*ex3[kr] - ex2[jr+1]*ex3[kr+1])
                      - ex1[ir+1] * (ex2[jr]*ex3[kr+1] + ex2[jr+1]*ex3[kr]);
            exi[kk+1] = ex1[ir+1] * (ex2[jr]*ex3[kr] - ex2[jr+1]*ex3[kr+1])
                      + ex1[ir] * (ex2[jr]*ex3[kr+1] + ex2[jr+1]*ex3[kr]);
            kk += 2;
            ir +=2;
         }
         jr += 2;
      }
      kr +=2;
   }
}

canonical_original_code:
void strfac(int nfft, float *ex1, float *ex2, float *ex3, float *exi)
{
   int i; int j; int k; int ir; int jr; int kr; int kk; int nffth;
   nffth = nfft/2;
   kk = 0;
   kr = 0;
   for (k=0; k<nfft; ++k)
   {
      jr = 0;
      for (j=0; j<nfft; ++j)
      {
         ir = 0;
         for (i=0; i<=nffth; ++i)
         {
            exi[kk] = ex1[ir] * (ex2[jr]*ex3[kr] - ex2[jr+1]*ex3[kr+1])
                      - ex1[ir+1] * (ex2[jr]*ex3[kr+1] + ex2[jr+1]*ex3[kr]);
            exi[kk+1] = ex1[ir+1] * (ex2[jr]*ex3[kr] - ex2[jr+1]*ex3[kr+1])
                      + ex1[ir] * (ex2[jr]*ex3[kr+1] + ex2[jr+1]*ex3[kr]);
            kk += 2;
            ir +=2;
         }
         jr += 2;
      }
      kr +=2;
   }
}

variable_types:
exi
float *

variable_types: i int

variable_types: j int

variable_types: ir int

variable_types: jr int

variable_types: kr int

variable_types: kk int


decompiled_code:
unsigned __int64 __fastcall get_masker(int a1, float *a2, _DWORD *a3, float a4)
{
float v4; // xmm12_4
_DWORD *v6; // rdi
int v8; // ebx
int v9; // er13
unsigned __int64 result; // rax
int v11; // esi
int v12; // er8
int v13; // ecx
int v14; // er8
float v15; // xmm3_4
int v16; // edx
float v17; // xmm2_4
float v18; // xmm10_4
float v19; // xmm7_4
float v20; // xmm4_4
float v21; // xmm9_4
float v22; // xmm8_4
float v23; // xmm6_4
int v24; // edx
float v25; // xmm5_4
float v26; // xmm3_4
float v27; // xmm2_4

v4 = a4;
v6 = a3;
v8 = a1 / 2;
v9 = a1 / 2 + 1;
result = (unsigned int)(a1 * a1 * v9);
if ( (int)result > 0 )
{
result = (unsigned __int64)memset(a3, 0, 4LL * (int)result);
v4 = a4;
v6 = (_DWORD *)result;
}
v11 = 1 - v8;
if ( v8 > 1 - v8 )
{
do
{
v12 = v11 + a1;
v13 = 1 - v8;
if ( v11 >= 0 )
v12 = v11;
v14 = a1 * v9 * v12;
do
{
if ( a1 > 1 )
{
v15 = (float)v13;
v16 = v13 + a1;
v17 = (float)v11;
if ( v13 >= 0 )
v16 = v13;
v18 = *a2;
v19 = a2[1];
v20 = a2[2];
LODWORD(result) = 0;
v21 = a2[3] * v15;
v22 = a2[6] * v17;
v23 = a2[4] * v15;
v24 = v14 + v9 * v16;
v25 = a2[7] * v17;
v26 = v15 * a2[5];
v27 = v17 * a2[8];
do
{
if ( v4 > (float)((float)((float)((float)((float)((float)(int)result * v20) + v26) + v27)
* (float)((float)((float)((float)(int)result * v20) + v26) + v27))
+ (float)((float)((float)((float)((float)((float)(int)result * v18) + v21) + v22)
* (float)((float)((float)((float)(int)result * v18) + v21) + v22))
+ (float)((float)((float)((float)((float)(int)result * v19) + v23) + v25)
* (float)((float)((float)((float)(int)result * v19) + v23) + v25)))) )
v6[v24 + (int)result] = 1;
result = (unsigned int)(result + 1);
}
while ( v8 > (int)result );
}
++v13;
}
while ( v8 != v13 );
++v11;
}
while ( v8 != v11 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int a1, float *a2, _DWORD *a3, float a4)
{
float v4; // xmm12_4
_DWORD *v6; // rdi
int v8; // ebx
int v9; // er13
unsigned __int64 result; // rax
int v11; // esi
int v12; // er8
int v13; // ecx
int v14; // er8
float v15; // xmm3_4
int v16; // edx
float v17; // xmm2_4
float v18; // xmm10_4
float v19; // xmm7_4
float v20; // xmm4_4
float v21; // xmm9_4
float v22; // xmm8_4
float v23; // xmm6_4
int v24; // edx
float v25; // xmm5_4
float v26; // xmm3_4
float v27; // xmm2_4

v4 = a4;
v6 = a3;
v8 = a1 / 2;
v9 = a1 / 2 + 1;
result = (unsigned int)(a1 * a1 * v9);
if ( (int)result > 0 )
{
result = (unsigned __int64)memset(a3, 0, 4LL * (int)result);
v4 = a4;
v6 = (_DWORD *)result;
}
v11 = 1 - v8;
if ( v8 > 1 - v8 )
{
do
{
v12 = v11 + a1;
v13 = 1 - v8;
if ( v11 >= 0 )
v12 = v11;
v14 = a1 * v9 * v12;
do
{
if ( a1 > 1 )
{
v15 = (float)v13;
v16 = v13 + a1;
v17 = (float)v11;
if ( v13 >= 0 )
v16 = v13;
v18 = *a2;
v19 = a2[1];
v20 = a2[2];
LODWORD(result) = 0;
v21 = a2[3] * v15;
v22 = a2[6] * v17;
v23 = a2[4] * v15;
v24 = v14 + v9 * v16;
v25 = a2[7] * v17;
v26 = v15 * a2[5];
v27 = v17 * a2[8];
do
{
if ( v4 > (float)((float)((float)((float)((float)((float)(int)result * v20) + v26) + v27)
* (float)((float)((float)((float)(int)result * v20) + v26) + v27))
+ (float)((float)((float)((float)((float)((float)(int)result * v18) + v21) + v22)
* (float)((float)((float)((float)(int)result * v18) + v21) + v22))
+ (float)((float)((float)((float)((float)(int)result * v19) + v23) + v25)
* (float)((float)((float)((float)(int)result * v19) + v23) + v25)))) )
v6[v24 + (int)result] = 1;
result = (unsigned int)(result + 1);
}
while ( v8 > (int)result );
}
++v13;
}
while ( v8 != v13 );
++v11;
}
while ( v8 != v11 );
}
return result;
}

original_code:
void get_masker(const int nfft, const float ggcut, const float *unitg, int *masker1)
{
   int i,j,k,k1,k2,k3,nffth,nfft3d,indx;
   float gx,gy,gz,gg;
   nfft3d = (nfft/2+1)*nfft*nfft;
   nffth = nfft/2;
   for (k=0; k<nfft3d; ++k) masker1[k] = 0;
   for (k3=(-nffth+1); k3<nffth; ++k3)
   for (k2=(-nffth+1); k2<nffth; ++k2)
   for (k1=0; k1<nffth; ++k1)
   {
     gx = k1*unitg[0] + k2*unitg[3] + k3*unitg[6];
     gy = k1*unitg[1] + k2*unitg[4] + k3*unitg[7];
     gz = k1*unitg[2] + k2*unitg[5] + k3*unitg[8];
     gg = gx*gx + gy*gy + gz*gz;
     i=k1; if (i<0) i += nfft;
     j=k2; if (j<0) j += nfft;
     k=k3; if (k<0) k += nfft;
     indx = i + j*(nffth+1) + k*(nffth+1)*nfft;
     if (gg < ggcut) masker1[indx] = 1;
   }
}

canonical_original_code:
void get_masker(int nfft, float ggcut, float *unitg, int *masker1)
{
   int i; int j; int k; int k1; int k2; int k3; int nffth; int nfft3d; int indx;
   float gx; float gy; float gz; float gg;
   nfft3d = (nfft/2+1)*nfft*nfft;
   nffth = nfft/2;
   for (k=0; k<nfft3d; ++k) masker1[k] = 0;
   for (k3=(-nffth+1); k3<nffth; ++k3)
   for (k2=(-nffth+1); k2<nffth; ++k2)
   for (k1=0; k1<nffth; ++k1)
   {
     gx = k1*unitg[0] + k2*unitg[3] + k3*unitg[6];
     gy = k1*unitg[1] + k2*unitg[4] + k3*unitg[7];
     gz = k1*unitg[2] + k2*unitg[5] + k3*unitg[8];
     gg = gx*gx + gy*gy + gz*gz;
     i=k1; if (i<0) i += nfft;
     j=k2; if (j<0) j += nfft;
     k=k3; if (k<0) k += nfft;
     indx = i + j*(nffth+1) + k*(nffth+1)*nfft;
     if (gg < ggcut) masker1[indx] = 1;
   }
}

variable_types: ggcut float

variable_types: indx int

variable_types: gx float

variable_types: gy float

variable_types: gz float

variable_types: gg float


eigsrt

canonical_original_code:
void eigsrt(float *D, float *V, int n)
{
   int i; int j; int k;
   float p;
   for (i=0; i<(n-1); ++i)
   {
      k = i;
      p = D[i];
      for(j=i+1; j<n; ++j)
         if (D[j]>=p)
         {
            k = j;
            p = D[j];
         }
      if (k!=i)
      {
         D[k] = D[i];
         D[i] = p;
         for (j=0; j<n; ++j)
         {
            p = V[j+i*n];
            V[j+i*n] = V[j+k*n];
            V[j+k*n] = p;
         }
      }
   }
}

variable_types:
D
float *

variable_types:
V
float *

variable_types: n int

variable_types: k int

variable_types: p float


gsdot

decompiled_code:
float __fastcall gsdot(int a1, __int64 a2, __int64 a3)
{
float v5; // [rsp+Ch] [rbp-2Ch]
int v6; // [rsp+10h] [rbp-28h] BYREF
int v7; // [rsp+14h] [rbp-24h] BYREF
int v8; // [rsp+18h] [rbp-20h] BYREF
int v9[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v8 = a1 / 2 + 1;
v9[0] = 1;
v6 = a1 * a1;
v7 = a1 * a1 * v8;
v5 = sdot_(&v7, a2, v9, a3);
return v5 + v5 - sdot_(&v6, a2, &v8, a3);
}

canonical_decompiled_code:
float __fastcall func0(int a1, __int64 a2, __int64 a3)
{
float v5; // [rsp+Ch] [rbp-2Ch]
int v6; // [rsp+10h] [rbp-28h] BYREF
int v7; // [rsp+14h] [rbp-24h] BYREF
int v8; // [rsp+18h] [rbp-20h] BYREF
int v9[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v8 = a1 / 2 + 1;
v9[0] = 1;
v6 = a1 * a1;
v7 = a1 * a1 * v8;
v5 = sdot_(&v7, a2, v9, a3);
return v5 + v5 - sdot_(&v6, a2, &v8, a3);
}

original_code:
float gsdot(const int nfft, const float *psi1, const float *psi2)
{
   int nfft2,nfft3,nffth2;
   int one=1;
   nffth2 = (nfft/2+1);
   nfft2 = nfft*nfft;
   nfft3 = (nfft/2+1)*nfft*nfft;
   return( 2.0*sdot_(&nfft3,psi1,&one,psi2,&one)
           - sdot_(&nfft2,psi1,&nffth2,psi2,&nffth2) );
}

canonical_original_code:
float gsdot(int nfft, float *psi1, float *psi2)
{
   int nfft2; int nfft3; int nffth2;
   int one = 1;
   nffth2 = (nfft/2+1);
   nfft2 = nfft*nfft;
   nfft3 = (nfft/2+1)*nfft*nfft;
   return( 2.0*sdot_(&nfft3,psi1,&one,psi2,&one)
           - sdot_(&nfft2,psi1,&nffth2,psi2,&nffth2) );
}

variable_types: nfft int

variable_types: one int


decompiled_code:
void __fastcall set_Vosko_beta(float a1)
{
beta = LODWORD(a1);
}

canonical_decompiled_code:
void __fastcall func0(float a1)
{
beta = LODWORD(a1);
}

original_code:
void set_Vosko_beta(float bb)
{
   beta = bb;
}

variable_types: bb float


Vosko

variable_types: ispin int

variable_types:
dn
float []

variable_types:
xcp
float []

variable_types:
xce
float *

variable_types: i int

variable_types: rs float

variable_types: nup float

variable_types: ndown float

variable_types: n float

variable_types: xi float

variable_types: x float

variable_types: xxp float

variable_types: dxxp float

variable_types: xxf float

variable_types: dxxf float

variable_types: f float

variable_types: df float

variable_types: denominator float


decompiled_code:
float current_second()
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, &tz);
return (double)SLODWORD(tv.tv_usec) * 0.000001 + (double)(LODWORD(tv.tv_sec) - 1236025000);
}

canonical_decompiled_code:
float func0()
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, &tz);
return (double)SLODWORD(tv.tv_usec) * 0.000001 + (double)(LODWORD(tv.tv_sec) - 1236025000);
}

original_code:
float current_second()
{
  struct timeval tp;
  struct timezone tz;
  double t0,t1,t2;
  gettimeofday(&tp,&tz);
  t0 = ((double) (tp.tv_sec-((long) 1236025000)));
  t0 += ((double) tp.tv_usec)*1e-6;
  return ((float) t0);
}

canonical_original_code:
float current_second()
{
  struct timeval tp;
  struct timezone tz;
  double t0; double t1; double t2;
  gettimeofday(&tp,&tz);
  t0 = ((double) (tp.tv_sec-((long) 1236025000)));
  t0 += ((double) tp.tv_usec)*1e-6;
  return ((float) t0);
}

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

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


message

decompiled_code:
int __fastcall message(int a1)
{
char *v1; // rsi
__int64 i; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char v5[24]; // [rsp+10h] [rbp-28h] BYREF
__int16 v6; // [rsp+28h] [rbp-10h]

time(&timer);
v1 = ctime(&timer);
for ( i = 0LL; i != 25; ++i )
v5[i] = v1[i];
v6 = 0;
switch ( a1 )
{
case 1:
v1 = "job started";
break;
case 2:
v1 = "iteration started";
break;
case 3:
v1 = "iteration ended";
break;
case 4:
v1 = "job completed";
break;
case 5:
v1 = "job terminated";
break;
}
return printf(" >>> %s on %s <<<\n", v1, v5);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
char *v1; // rsi
__int64 i; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char v5[24]; // [rsp+10h] [rbp-28h] BYREF
__int16 v6; // [rsp+28h] [rbp-10h]

time(&timer);
v1 = ctime(&timer);
for ( i = 0LL; i != 25; ++i )
v5[i] = v1[i];
v6 = 0;
switch ( a1 )
{
case 1:
v1 = "job started";
break;
case 2:
v1 = "iteration started";
break;
case 3:
v1 = "iteration ended";
break;
case 4:
v1 = "job completed";
break;
case 5:
v1 = "job terminated";
break;
}
return printf(" >>> %s on %s <<<\n", v1, v5);
}

original_code:
void message(const int n)
{
   int i;
   char *msg,date[26];
   time_t t0,t1;
   t1 = time(&t0);
   msg = ctime(&t0);
   for (i=0; i<25; ++i)
      date[i] = msg[i];
   date[24] = '\0';
   date[25] = '\0';
   if (n==1) msg = "job started";
   if (n==2) msg = "iteration started";
   if (n==3) msg = "iteration ended";
   if (n==4) msg = "job completed";
   if (n==5) msg = "job terminated";
   printf("          >>>   %s on %s    <<<\n",msg,date);
}

canonical_original_code:
void message(int n)
{
   int i;
   char *msg; char date[26];
   long t0; long t1;
   t1 = time(&t0);
   msg = ctime(&t0);
   for (i=0; i<25; ++i)
      date[i] = msg[i];
   date[24] = '\0';
   date[25] = '\0';
   if (n==1) msg = "job started";
   if (n==2) msg = "iteration started";
   if (n==3) msg = "iteration ended";
   if (n==4) msg = "job completed";
   if (n==5) msg = "job terminated";
   printf("          >>>   %s on %s    <<<\n",msg,date);
}

variable_types: n int

variable_types:
msg
char *

variable_types:
date
char [26]


dowork

repo: ecashin/low

decompiled_code:
void *__fastcall dowork(void *a1)
{
__int64 v1; // rbx
__int64 v3; // rax
__int64 v4; // rax

if ( type != 2 )
{
if ( type == 3 )
{
if ( niters > 0 )
{
*((_DWORD *)a1 + 2) += niters;
return a1;
}
}
else
{
if ( type != 1 )
{
v1 = 0LL;
while ( niters > v1 )
{
++v1;
pthread_mutex_lock(&mutex);
++count;
pthread_mutex_unlock(&mutex);
}
return a1;
}
v4 = 0LL;
if ( niters > 0 )
{
do
{
_InterlockedAdd64((volatile signed __int64 *)&count, 1uLL);
++v4;
}
while ( niters > v4 );
return a1;
}
}
return a1;
}
v3 = 0LL;
if ( niters <= 0 )
return a1;
do
{
_InterlockedAdd64((volatile signed __int64 *)a1 + 1, 1uLL);
++v3;
}
while ( niters > v3 );
return a1;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
__int64 v1; // rbx
__int64 v3; // rax
__int64 v4; // rax

if ( type != 2 )
{
if ( type == 3 )
{
if ( niters > 0 )
{
*((_DWORD *)a1 + 2) += niters;
return a1;
}
}
else
{
if ( type != 1 )
{
v1 = 0LL;
while ( niters > v1 )
{
++v1;
pthread_mutex_lock(&mutex);
++count;
pthread_mutex_unlock(&mutex);
}
return a1;
}
v4 = 0LL;
if ( niters > 0 )
{
do
{
_InterlockedAdd64((volatile signed __int64 *)&count, 1uLL);
++v4;
}
while ( niters > v4 );
return a1;
}
}
return a1;
}
v3 = 0LL;
if ( niters <= 0 )
return a1;
do
{
_InterlockedAdd64((volatile signed __int64 *)a1 + 1, 1uLL);
++v3;
}
while ( niters > v3 );
return a1;
}

original_code:
static void *
dowork(void *data)
{
 int i;
 struct tinfo *ti = (struct tinfo *) data;
 switch (type) {
 case LKADDSH:
  for (i = 0; i < niters; ++i)
   asm volatile("lock; addq $1, %0"
         : "=m" (count)
         : "m" (count));
  break;
 case LKADDNO:
  for (i = 0; i < niters; ++i)
   asm volatile("lock; addq $1, %0"
         : "=m" (ti->t.count)
         : "m" (ti->t.count));
  break;
 case ADDNO:
  for (i = 0; i < niters; ++i)
   ti->t.count += 1;
  break;
 case MUTEX:
 default:
  for (i = 0; i < niters; ++i) {
   pthread_mutex_lock(&mutex);
   count++;
   pthread_mutex_unlock(&mutex);
  }
  break;
 }
 return data;
}

canonical_original_code:
static void *dowork(void *data)
{
 int i;
 struct tinfo *ti = (struct tinfo *) data;
 switch (type) {
 case LKADDSH:
  for (i = 0; i < niters; ++i)
   asm volatile("lock; addq $1, %0"
         : "=m" (count)
         : "m" (count));
  break;
 case LKADDNO:
  for (i = 0; i < niters; ++i)
   asm volatile("lock; addq $1, %0"
         : "=m" (ti->t.count)
         : "m" (ti->t.count));
  break;
 case ADDNO:
  for (i = 0; i < niters; ++i)
   ti->t.count += 1;
  break;
 case MUTEX:
 default:
  for (i = 0; i < niters; ++i) {
   pthread_mutex_lock(&mutex);
   count++;
   pthread_mutex_unlock(&mutex);
  }
  break;
 }
 return data;
}

variable_types:
data
void *

variable_types: i int

variable_types: struct tinfo { union { struct perthread { unsigned long tinfo; unsigned int count; } t; char pad[64]; }; } *

return_type: void *

user_defined_types: struct tinfo { union { struct perthread t; char pad[64]; }; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
__int64 v4; // r12
__int64 v5; // rcx
void *v6; // rax
void *v7; // r14
pthread_t *v8; // rbp
pthread_t *v9; // rbx
__int64 v10; // r12
__int64 i; // rbx
const char *v12; // rsi
char *endptr[6]; // [rsp+8h] [rbp-30h] BYREF

if ( argc <= 1 )
{
niters = 10000LL;
v3 = 10LL;
LABEL_3:
type = 0;
v4 = 10000LL;
v5 = 0LL;
goto LABEL_4;
}
v3 = strtol(argv[1], endptr, 0);
if ( argv[1] == endptr[0] )
goto LABEL_29;
niters = 10000LL;
if ( argc == 2 )
goto LABEL_3;
niters = strtol(argv[2], endptr, 0);
v4 = niters;
if ( argv[2] == endptr[0] )
goto LABEL_29;
type = 0;
if ( argc == 3 )
{
v5 = 0LL;
}
else
{
type = strtol(argv[3], endptr, 0);
v5 = (unsigned int)type;
if ( argv[3] == endptr[0] )
LABEL_29:
exit(1);
}
LABEL_4:
printf("%ld threads for %ld iterations, test type %d\n", v3, v4, v5);
if ( pthread_mutex_init(&mutex, 0LL) )
{
perror("pthread_mutex_init");
goto LABEL_29;
}
v6 = malloc(v3 << 6);
v7 = v6;
if ( !v6 )
{
perror("malloc");
exit(1);
}
v8 = (pthread_t *)v6;
v9 = (pthread_t *)v6;
v10 = 0LL;
if ( v3 > 0 )
{
while ( 1 )
{
if ( pthread_create(v9, 0LL, dowork, v9) )
{
perror("pthread_create");
exit(1);
}
v9 += 8;
if ( v3 == v10 + 1 )
break;
++v10;
}
for ( i = 0LL; ; ++i )
{
if ( pthread_join(*v8, 0LL) )
{
perror("pthead_join");
exit(1);
}
if ( (unsigned int)(type - 2) <= 1 )
count += *((_DWORD *)v8 + 2);
v8 += 8;
if ( v10 == i )
break;
}
}
pthread_mutex_destroy(&mutex);
free(v7);
v12 = (const char *)&unk_402004;
if ( niters * v3 != count )
v12 = "WRONG";
printf("%s: resulting count is %lu\n", v12);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 struct tinfo *a;
 long int n;
 int i;
 char *end;
 n = 10;
 if (argc > 1) {
  n = strtol(argv[1], &end, 0);
  if (end == argv[1])
   exit(1);
 }
 niters = 10000;
 if (argc > 2) {
  niters = strtol(argv[2], &end, 0);
  if (end == argv[2])
   exit(1);
 }
 type = MUTEX;
 if (argc > 3) {
  type = (int) strtol(argv[3], &end, 0);
  if (end == argv[3])
   exit(1);
 }
 printf("%ld threads for %ld iterations, test type %d\n",
        n, niters, type);
 if (pthread_mutex_init(&mutex, ((void *)0))) {
  perror("pthread_mutex_init");
  exit(1);
 }
 a = malloc(n * sizeof *a);
 if (!a) {
  perror("malloc");
  exit(1);
 }
 for (i = 0; i < n; ++i)
  if (pthread_create(&a[i].t.tinfo, ((void *)0), dowork, &a[i])) {
   perror("pthread_create");
   exit(1);
  }
 for (i = 0; i < n; ++i) {
  if (pthread_join(a[i].t.tinfo, ((void *)0))) {
   perror("pthead_join");
   exit(1);
  }
  if (type == LKADDNO || type == ADDNO)
   count += a[i].t.count;
 }
 pthread_mutex_destroy(&mutex);
 free(a);
 printf("%s: resulting count is %lu\n",
        (n * niters) == count ? "OK" : "WRONG",
        (unsigned long) count);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct tinfo *a;
 long n;
 int i;
 char *end;
 n = 10;
 if (argc > 1) {
  n = strtol(argv[1], &end, 0);
  if (end == argv[1])
   exit(1);
 }
 niters = 10000;
 if (argc > 2) {
  niters = strtol(argv[2], &end, 0);
  if (end == argv[2])
   exit(1);
 }
 type = MUTEX;
 if (argc > 3) {
  type = (int) strtol(argv[3], &end, 0);
  if (end == argv[3])
   exit(1);
 }
 printf("%ld threads for %ld iterations, test type %d\n",
        n, niters, type);
 if (pthread_mutex_init(&mutex, ((void *)0))) {
  perror("pthread_mutex_init");
  exit(1);
 }
 a = malloc(n * sizeof *a);
 if (!a) {
  perror("malloc");
  exit(1);
 }
 for (i = 0; i < n; ++i)
  if (pthread_create(&a[i].t.tinfo, ((void *)0), dowork, &a[i])) {
   perror("pthread_create");
   exit(1);
  }
 for (i = 0; i < n; ++i) {
  if (pthread_join(a[i].t.tinfo, ((void *)0))) {
   perror("pthead_join");
   exit(1);
  }
  if (type == LKADDNO || type == ADDNO)
   count += a[i].t.count;
 }
 pthread_mutex_destroy(&mutex);
 free(a);
 printf("%s: resulting count is %lu\n",
        (n * niters) == count ? "OK" : "WRONG",
        (unsigned long) count);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: n long

variable_types:
end
char *

user_defined_types: struct perthread { unsigned long tinfo; unsigned int count; }


pr

decompiled_code:
int __fastcall pr(_BYTE *a1)
{
_BYTE *v1; // rbx
_BYTE *v2; // rax

v1 = a1 + 9;
do
{
printf("%d%d", *v1 >> 4, *v1 & 0xF);
v2 = v1--;
}
while ( a1 != v2 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(_BYTE *a1)
{
_BYTE *v1; // rbx
_BYTE *v2; // rax

v1 = a1 + 9;
do
{
printf("%d%d", *v1 >> 4, *v1 & 0xF);
v2 = v1--;
}
while ( a1 != v2 );
return putchar(10);
}

original_code:
void pr(unsigned char *bcd)
{
 int i;
 for (i = 9; i >= 0; --i)
  printf("%d%d", bcd[i] >> 4 & 0xf, bcd[i] & 0xf);
 putchar('\n');
}

variable_types:
bcd
unsigned char *


main

original_code:
int main(void)
{
 float a = 0.1;
 float b = 0.2;
 unsigned char bcda[10] = {
  9<<4|9, 0,
 };
 unsigned char bcdb[10] = {
  1, 1, 0,
 };
 long double aa = 0.1, bb = 0.2;
 printf("sizeof long double: %lu\n", sizeof aa);
 printf("%g + %g = %g\n", a, b, a + b);
 printf("%Lg + %Lg = %Lg\n", aa, bb, aa + bb);
 pr(bcda);
 pr(bcdb);
 bcddemo(bcda, bcdb);
 pr(bcda);
 return 0;
}

canonical_original_code:
int main()
{
 float a = 0.1;
 float b = 0.2;
 unsigned char bcda[10] = {
  9<<4|9, 0,
 };
 unsigned char bcdb[10] = {
  1, 1, 0,
 };
 long double aa = 0.1; long double bb = 0.2;
 printf("sizeof long double: %lu\n", sizeof aa);
 printf("%g + %g = %g\n", a, b, a + b);
 printf("%Lg + %Lg = %Lg\n", aa, bb, aa + bb);
 pr(bcda);
 pr(bcdb);
 bcddemo(bcda, bcdb);
 pr(bcda);
 return 0;
}

variable_types: a float

variable_types: b float

variable_types:
bcda
unsigned char [10]

variable_types:
bcdb
unsigned char [10]

variable_types:
aa
long double

variable_types:
bb
long double


cbchar

decompiled_code:
__int64 __fastcall cbchar(unsigned __int8 a1)
{
unsigned __int8 v1; // al
unsigned int i; // er8

v1 = a1;
for ( i = 0; v1; v1 >>= 1 )
i += v1 & 1;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 a1)
{
unsigned __int8 v1; // al
unsigned int i; // er8

v1 = a1;
for ( i = 0; v1; v1 >>= 1 )
i += v1 & 1;
return i;
}

original_code:
static inline int cbchar(unsigned char c)
{
 int b;
 for (b = 0; c; c >>= 1)
  b += c & 1;
 return b;
}

variable_types:
c
unsigned char

variable_types: b int


cntbits

decompiled_code:
__int64 __fastcall cntbits(unsigned __int8 *a1, __int64 a2)
{
int i; // ebp
unsigned __int8 v4; // di
unsigned __int8 *v5; // r12
int v6; // eax
unsigned __int64 *v7; // rdi
unsigned __int8 *v8; // rbx
unsigned int v9; // er9
unsigned __int8 v10; // di
int v11; // eax
int v12; // er9

for ( i = 0; a2; --a2 )
{
if ( ((unsigned __int8)a1 & 7) == 0 )
break;
v4 = *a1++;
i += cbchar(v4);
}
v5 = &a1[a2];
v6 = ifloor_constprop_0(a2);
v7 = (unsigned __int64 *)a1;
v8 = &a1[v6];
v9 = i + countbits(v7, v6);
if ( v5 > v8 )
{
do
{
v10 = *v8++;
v11 = cbchar(v10);
v9 = v11 + v12;
}
while ( v5 != v8 );
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 *a1, __int64 a2)
{
int i; // ebp
unsigned __int8 v4; // di
unsigned __int8 *v5; // r12
int v6; // eax
unsigned __int64 *v7; // rdi
unsigned __int8 *v8; // rbx
unsigned int v9; // er9
unsigned __int8 v10; // di
int v11; // eax
int v12; // er9

for ( i = 0; a2; --a2 )
{
if ( ((unsigned __int8)a1 & 7) == 0 )
break;
v4 = *a1++;
i += func9(v4);
}
v5 = &a1[a2];
v6 = func10(a2);
v7 = (unsigned __int64 *)a1;
v8 = &a1[v6];
v9 = i + func7(v7, v6);
if ( v5 > v8 )
{
do
{
v10 = *v8++;
v11 = func9(v10);
v9 = v11 + v12;
}
while ( v5 != v8 );
}
return v9;
}

original_code:
static inline int cntbits(uint16_t *a, size_t n)
{
 int b = 0;
 unsigned char *p = (unsigned char *) a;
 unsigned char *e;
 const int blksiz = 8;
 for (; n > 0 && ((unsigned long) p) % blksiz; ++p, --n)
  b += cbchar(*p);
 e = &p[n];
 n = ifloor(e - p, blksiz);
 b += countbits((uint16_t *) p, n);
 for (p += n; p < e; ++p)
  b += cbchar(*p);
 return b;
}

canonical_original_code:
static inline int cntbits(unsigned short *a, unsigned long n)
{
 int b = 0;
 unsigned char *p = (unsigned char *) a;
 unsigned char *e;
 int blksiz = 8;
 for (; n > 0 && ((unsigned long) p) % blksiz; ++p, --n)
  b += cbchar(*p);
 e = &p[n];
 n = ifloor(e - p, blksiz);
 b += countbits((unsigned short *) p, n);
 for (p += n; p < e; ++p)
  b += cbchar(*p);
 return b;
}

variable_types:
a
unsigned short *

variable_types:
n
unsigned long

variable_types:
p
unsigned char *

variable_types:
e
unsigned char *

variable_types: blksiz int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // eax
__int64 v5; // rcx
unsigned int v6; // eax
int v7; // eax
__int64 v8; // rcx
__int64 v9; // rbx
int v10; // er12
__int16 v12; // [rsp+0h] [rbp-4E3Ah]
unsigned __int8 v13; // [rsp+2h] [rbp-4E38h] BYREF
char v14[20023]; // [rsp+3h] [rbp-4E37h] BYREF

v3 = 0LL;
v4 = canpopcnt(argc, argv, envp);
v5 = 1LL;
if ( v4 )
{
do
{
*(&v12 + v5) = v5;
v6 = v5;
do
{
v3 += v6 & 1;
v6 >>= 1;
}
while ( v6 );
++v5;
}
while ( v5 != 10001 );
printf("initialized array with total of %lu bits set\n", v3);
printf("countbits with %lu bits set ... ", v3);
fflush(stdout);
if ( (int)cntbits(&v13, 20000LL) != v3 )
__assert_fail("n == m", "main.c", 0x45u, "main");
puts("ok.");
cbchar(v13);
v7 = cbchar((unsigned __int8)v14[19998]);
v9 = v3 - (v7 + v8);
printf("countbits on unaligned sub-array with %lu bits set ... ", v9);
fflush(stdout);
if ( v9 != (int)cntbits(v14, 19998LL) )
__assert_fail("n == m", "main.c", 0x4Eu, "main");
puts("ok.");
fwrite("zero-length input ... ", 1uLL, 0x16uLL, stdout);
fflush(stdout);
v10 = cntbits(&v13, 0LL);
if ( v10 )
__assert_fail("cntbits(a, 0) == 0", "main.c", 0x53u, "main");
puts("ok.");
}
else
{
v10 = 1;
fwrite("no POPCNT support in CPU\n", 1uLL, 0x19uLL, stderr);
}
return v10;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // eax
__int64 v5; // rcx
unsigned int v6; // eax
int v7; // eax
__int64 v8; // rcx
__int64 v9; // rbx
int v10; // er12
__int16 v12; // [rsp+0h] [rbp-4E3Ah]
unsigned __int8 v13; // [rsp+2h] [rbp-4E38h] BYREF
char v14[20023]; // [rsp+3h] [rbp-4E37h] BYREF

v3 = 0LL;
v4 = func8(argc, argv, envp);
v5 = 1LL;
if ( v4 )
{
do
{
*(&v12 + v5) = v5;
v6 = v5;
do
{
v3 += v6 & 1;
v6 >>= 1;
}
while ( v6 );
++v5;
}
while ( v5 != 10001 );
printf("initialized array with total of %lu bits set\n", v3);
printf("countbits with %lu bits set ... ", v3);
fflush(stdout);
if ( (int)func11(&v13, 20000LL) != v3 )
__assert_fail("n == m", "main.c", 0x45u, "main");
puts("ok.");
func9(v13);
v7 = func9((unsigned __int8)v14[19998]);
v9 = v3 - (v7 + v8);
printf("countbits on unaligned sub-array with %lu bits set ... ", v9);
fflush(stdout);
if ( v9 != (int)func11(v14, 19998LL) )
__assert_fail("n == m", "main.c", 0x4Eu, "main");
puts("ok.");
fwrite("zero-length input ... ", 1uLL, 0x16uLL, stdout);
fflush(stdout);
v10 = func11(&v13, 0LL);
if ( v10 )
__assert_fail("cntbits(a, 0) == 0", "main.c", 0x53u, "main");
puts("ok.");
}
else
{
v10 = 1;
fwrite("no POPCNT support in CPU\n", 1uLL, 0x19uLL, stderr);
}
return v10;
}

original_code:
int main(void)
{
 int i;
 unsigned j;
 unsigned long n;
 unsigned long m;
 uint16_t a[10000];
 unsigned char *p;
 if (!canpopcnt()) {
  fprintf(stderr, "no POPCNT support in CPU\n");
  return 1;
 }
 for (i = 0, n = 0; i < sizeof a / sizeof a[0]; ++i) {
  j = i + 1;
  a[i] = j;
  while (j) {
   n += j & 1;
   j >>= 1;
  }
 }
 printf("initialized array with total of %lu bits set\n", n);
 m = n;
 printf("countbits with %lu bits set ... ", n);
 fflush(stdout);
 n = cntbits(a, sizeof a);
 ((void) sizeof ((n == m) ? 1 : 0), __extension__ ({ if (n == m) ; else __assert_fail ("n == m", "main.c", 69, __extension__ __PRETTY_FUNCTION__); }));
 puts("ok.");
 p = (unsigned char *) a;
 m = n - cbchar(p[0]) - cbchar(p[(sizeof a) - 1]);
 printf("countbits on unaligned sub-array with %lu bits set ... ", m);
 fflush(stdout);
 n = cntbits((uint16_t *)(p+1), (sizeof a) - 2);
 ((void) sizeof ((n == m) ? 1 : 0), __extension__ ({ if (n == m) ; else __assert_fail ("n == m", "main.c", 78, __extension__ __PRETTY_FUNCTION__); }));
 puts("ok.");
 fputs("zero-length input ... ", stdout);
 fflush(stdout);
 ((void) sizeof ((cntbits(a, 0) == 0) ? 1 : 0), __extension__ ({ if (cntbits(a, 0) == 0) ; else __assert_fail ("cntbits(a, 0) == 0", "main.c", 83, __extension__ __PRETTY_FUNCTION__); }));
 puts("ok.");
 return 0;
}

canonical_original_code:
int main()
{
 int i;
 unsigned int j;
 unsigned long n;
 unsigned long m;
 unsigned short a[10000];
 unsigned char *p;
 if (!canpopcnt()) {
  fprintf(stderr, "no POPCNT support in CPU\n");
  return 1;
 }
 for (i = 0, n = 0; i < sizeof a / sizeof a[0]; ++i) {
  j = i + 1;
  a[i] = j;
  while (j) {
   n += j & 1;
   j >>= 1;
  }
 }
 printf("initialized array with total of %lu bits set\n", n);
 m = n;
 printf("countbits with %lu bits set ... ", n);
 fflush(stdout);
 n = cntbits(a, sizeof a);
 ((void) sizeof ((n == m) ? 1 : 0), __extension__ ({ if (n == m) ; else __assert_fail ("n == m", "main.c", 69, __extension__ __PRETTY_FUNCTION__); }));
 puts("ok.");
 p = (unsigned char *) a;
 m = n - cbchar(p[0]) - cbchar(p[(sizeof a) - 1]);
 printf("countbits on unaligned sub-array with %lu bits set ... ", m);
 fflush(stdout);
 n = cntbits((unsigned short *)(p+1), (sizeof a) - 2);
 ((void) sizeof ((n == m) ? 1 : 0), __extension__ ({ if (n == m) ; else __assert_fail ("n == m", "main.c", 78, __extension__ __PRETTY_FUNCTION__); }));
 puts("ok.");
 fputs("zero-length input ... ", stdout);
 fflush(stdout);
 ((void) sizeof ((cntbits(a, 0) == 0) ? 1 : 0), __extension__ ({ if (cntbits(a, 0) == 0) ; else __assert_fail ("cntbits(a, 0) == 0", "main.c", 83, __extension__ __PRETTY_FUNCTION__); }));
 puts("ok.");
 return 0;
}

variable_types: i int

variable_types:
j
unsigned int

variable_types:
m
unsigned long

variable_types:
a
unsigned short [10000]


prfeature

decompiled_code:
int __fastcall prfeature(unsigned int a1, unsigned int a2)
{
void *v2; // rcx

v2 = &unk_402004;
if ( ((a1 >> a2) & 1) == 0 )
v2 = &unk_402008;
return printf(" %46s (bit %2d): %s\n", features[a2], a2, v2);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, unsigned int a2)
{
void *v2; // rcx

v2 = &unk_402004;
if ( ((a1 >> a2) & 1) == 0 )
v2 = &unk_402008;
return printf(" %46s (bit %2d): %s\n", features[a2], a2, v2);
}

original_code:
void prfeature(unsigned int cpuid, int i)
{
 char *yes = cpuid >> i & 1 ? "yes" : "no";
 printf("  %46s (bit %2d): %s\n", features[i], i, yes);
}

variable_types:
cpuid
unsigned int

variable_types:
yes
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
void *v4; // rsi
void *v5; // rsi
void *v6; // rsi
unsigned int v7; // ebx
__int64 v8; // rsi

v3 = (unsigned int)cpuidfn(1LL, argv, envp);
printf("%016lx\n", v3);
v4 = &unk_402008;
if ( (v3 & 0x80000) != 0 )
v4 = &unk_402004;
printf("sse4.1: %s\n", v4);
v5 = &unk_402008;
if ( (v3 & 0x100000) != 0 )
v5 = &unk_402004;
printf("sse4.2: %s\n", v5);
v6 = &unk_402008;
if ( (v3 & 0x800000) != 0 )
v6 = &unk_402004;
v7 = 0;
printf("popcnt: %s\n", v6);
do
{
v8 = v7++;
prfeature((unsigned int)v3, v8);
}
while ( v7 != 31 );
return 0;
}

original_code:
int main(void)
{
 int i;
 unsigned long n = (unsigned long) cpuidfn(1);
 printf("%016lx\n", n);
 printf("sse4.1: %s\n", (n >> (19) & 1) ? "yes" : "no");
 printf("sse4.2: %s\n", (n >> (20) & 1) ? "yes" : "no");
 printf("popcnt: %s\n", (n >> (23) & 1) ? "yes" : "no");
 for (i = 0; i < sizeof features / sizeof features[0]; ++i)
  prfeature(n, i);
 return 0;
}

canonical_original_code:
int main()
{
 int i;
 unsigned long n = (unsigned long) cpuidfn(1);
 printf("%016lx\n", n);
 printf("sse4.1: %s\n", (n >> (19) & 1) ? "yes" : "no");
 printf("sse4.2: %s\n", (n >> (20) & 1) ? "yes" : "no");
 printf("popcnt: %s\n", (n >> (23) & 1) ? "yes" : "no");
 for (i = 0; i < sizeof features / sizeof features[0]; ++i)
  prfeature(n, i);
 return 0;
}


loadstr

decompiled_code:
void *__fastcall loadstr(void *dest, void *src, size_t n)
{
size_t v4; // rax

memset(dest, 0, n);
v4 = strlen((const char *)src);
if ( n <= v4 )
v4 = n;
return memmove(dest, src, v4);
}

canonical_decompiled_code:
void *__fastcall func9(void *dest, void *src, size_t n)
{
size_t v4; // rax

memset(dest, 0, n);
v4 = strlen((const char *)src);
if ( n <= v4 )
v4 = n;
return memmove(dest, src, v4);
}

original_code:
void loadstr(char *buf, char *s, size_t m)
{
 size_t n;
 memset(buf, 0, m);
 n = strlen(s);
 if (n > m)
  n = m;
 memmove(buf, s, n);
}

canonical_original_code:
void loadstr(char *buf, char *s, unsigned long m)
{
 unsigned long n;
 memset(buf, 0, m);
 n = strlen(s);
 if (n > m)
  n = m;
 memmove(buf, s, n);
}

variable_types:
buf
char *

variable_types:
s
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
size_t v4; // r13
size_t v5; // rax
size_t v6; // rdx
__int64 v7; // rax
__int128 v9[2]; // [rsp+0h] [rbp-428h] BYREF
char v10[480]; // [rsp+20h] [rbp-408h] BYREF
char s[16]; // [rsp+200h] [rbp-228h] BYREF
__int128 v12; // [rsp+210h] [rbp-218h]
char v13[480]; // [rsp+220h] [rbp-208h] BYREF

v3 = cpuidfn(1LL, argv, envp);
memset(v10, 0, sizeof(v10));
v9[0] = (__int128)_mm_load_si128((const __m128i *)&xmmword_402060);
v9[1] = 0LL;
memset(v13, 0, sizeof(v13));
*(__m128i *)s = _mm_load_si128((const __m128i *)&xmmword_402070);
v12 = 0LL;
if ( (v3 & 0x100000) == 0 )
{
fwrite("cpuid says this CPU hasn't SSE 4.2\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
if ( argc > 1 )
{
loadstr(v9, (void *)argv[1], 0x1FFuLL);
v4 = strlen((const char *)v9);
if ( argc == 2 )
{
v5 = 16LL;
}
else
{
loadstr(s, (void *)argv[2], 0x1FFuLL);
v5 = strlen(s);
}
}
else
{
v4 = 16LL;
v5 = 16LL;
}
v6 = v4;
if ( v5 <= v4 )
v6 = v5;
v7 = diffidx(v9, s, v6);
printf("\"%s\" and \"%s\" differ at byte index %lu\n", (const char *)v9, s, v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
size_t v4; // r13
size_t v5; // rax
size_t v6; // rdx
__int64 v7; // rax
__int128 v9[2]; // [rsp+0h] [rbp-428h] BYREF
char v10[480]; // [rsp+20h] [rbp-408h] BYREF
char s[16]; // [rsp+200h] [rbp-228h] BYREF
__int128 v12; // [rsp+210h] [rbp-218h]
char v13[480]; // [rsp+220h] [rbp-208h] BYREF

v3 = func8(1LL, argv, envp);
memset(v10, 0, sizeof(v10));
v9[0] = (__int128)_mm_load_si128((const __m128i *)&xmmword_402060);
v9[1] = 0LL;
memset(v13, 0, sizeof(v13));
*(__m128i *)s = _mm_load_si128((const __m128i *)&xmmword_402070);
v12 = 0LL;
if ( (v3 & 0x100000) == 0 )
{
fwrite("cpuid says this CPU hasn't SSE 4.2\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
if ( argc > 1 )
{
func9(v9, (void *)argv[1], 0x1FFuLL);
v4 = strlen((const char *)v9);
if ( argc == 2 )
{
v5 = 16LL;
}
else
{
func9(s, (void *)argv[2], 0x1FFuLL);
v5 = strlen(s);
}
}
else
{
v4 = 16LL;
v5 = 16LL;
}
v6 = v4;
if ( v5 <= v4 )
v6 = v5;
v7 = func7(v9, s, v6);
printf("\"%s\" and \"%s\" differ at byte index %lu\n", (const char *)v9, s, v7);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 unsigned long n = (unsigned long) cpuidfn(1);
 char a[512] = "0123456789abcdef";
 char b[512] = "01c3456789abCdef";
 size_t alen = strlen(a);
 size_t blen = strlen(b);
 if ((n >> (20) & 1) == 0) {
  fputs("cpuid says this CPU hasn't SSE 4.2\n", stderr);
  exit(1);
 }
 if (argc > 1) {
  loadstr(a, argv[1], sizeof a - 1);
  alen = strlen(a);
 }
 if (argc > 2) {
  loadstr(b, argv[2], sizeof b - 1);
  blen = strlen(b);
 }
 printf("\"%s\" and \"%s\" differ at byte index %lu\n",
        a, b, diffidx(a, b, alen > blen ? blen : alen));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long n = (unsigned long) cpuidfn(1);
 char a[512] = "0123456789abcdef";
 char b[512] = "01c3456789abCdef";
 unsigned long alen = strlen(a);
 unsigned long blen = strlen(b);
 if ((n >> (20) & 1) == 0) {
  fputs("cpuid says this CPU hasn't SSE 4.2\n", stderr);
  exit(1);
 }
 if (argc > 1) {
  loadstr(a, argv[1], sizeof a - 1);
  alen = strlen(a);
 }
 if (argc > 2) {
  loadstr(b, argv[2], sizeof b - 1);
  blen = strlen(b);
 }
 printf("\"%s\" and \"%s\" differ at byte index %lu\n",
        a, b, diffidx(a, b, alen > blen ? blen : alen));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
a
char [512]

variable_types:
b
char [512]

variable_types:
alen
unsigned long

variable_types:
blen
unsigned long


repo: eceforge/vitasign

decompiled_code:
__int64 __fastcall int64_lo(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1;
}

original_code: static inline uint32_t int64_lo(int64_t x) { return (x & ((1ULL << 32) - 1)); }

canonical_original_code: static inline unsigned int int64_lo(long x) { return (x & ((1ULL << 32) - 1)); }

variable_types: x long

return_type: unsigned int


decompiled_code:
__int64 __fastcall int64_add(__int64 a1, __int64 a2)
{
return a1 + a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return a1 + a2;
}

original_code: static inline int64_t int64_add(int64_t x, int64_t y) { return (x + y); }

canonical_original_code: static inline long int64_add(long x, long y) { return (x + y); }

variable_types: y long

return_type: long


decompiled_code:
__int64 __fastcall int64_mul_i32_i32(int a1, int a2)
{
return a2 * a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
return a2 * a1;
}

original_code: static inline int64_t int64_mul_i32_i32(int32_t x, int32_t y) { return (x * y); }

canonical_original_code: static inline long int64_mul_i32_i32(int x, int y) { return (x * y); }

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall fix16_add(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(a1 + a2);
if ( (a1 ^ a2) >= 0 && (int)(result ^ a1) < 0 )
result = 0x80000000LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(a1 + a2);
if ( (a1 ^ a2) >= 0 && (int)(result ^ a1) < 0 )
result = 0x80000000LL;
return result;
}

canonical_original_code:
int fix16_add(int a, int b)
{
  unsigned int _a = a; unsigned int _b = b;
  unsigned int sum = _a + _b;
  if (!((_a ^ _b) & 0x80000000) && ((_a ^ sum) & 0x80000000))
    return fix16_overflow;
  return sum;
}

variable_types: a int

variable_types: b int

variable_types:
sum
unsigned int


decompiled_code:
__int64 __fastcall fix16_sub(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(a1 - a2);
if ( (a1 ^ a2) < 0 && (int)(result ^ a1) < 0 )
result = 0x80000000LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(a1 - a2);
if ( (a1 ^ a2) < 0 && (int)(result ^ a1) < 0 )
result = 0x80000000LL;
return result;
}

original_code:
fix16_t fix16_sub(fix16_t a, fix16_t b)
{
  uint32_t _a = a, _b = b;
  uint32_t diff = _a - _b;
  if (((_a ^ _b) & 0x80000000) && ((_a ^ diff) & 0x80000000))
    return fix16_overflow;
  return diff;
}

canonical_original_code:
int fix16_sub(int a, int b)
{
  unsigned int _a = a; unsigned int _b = b;
  unsigned int diff = _a - _b;
  if (((_a ^ _b) & 0x80000000) && ((_a ^ diff) & 0x80000000))
    return fix16_overflow;
  return diff;
}

variable_types:
diff
unsigned int


decompiled_code:
__int64 __fastcall fix16_sadd(int a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = fix16_add(a1, a2);
if ( (_DWORD)result == 0x80000000 && v3 > 0 )
result = 0x7FFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = func4(a1, a2);
if ( (_DWORD)result == 0x80000000 && v3 > 0 )
result = 0x7FFFFFFFLL;
return result;
}

original_code:
fix16_t fix16_sadd(fix16_t a, fix16_t b)
{
  fix16_t result = fix16_add(a, b);
  if (result == fix16_overflow)
    return (a > 0) ? fix16_max : fix16_min;
  return result;
}

canonical_original_code:
int fix16_sadd(int a, int b)
{
  int result = fix16_add(a, b);
  if (result == fix16_overflow)
    return (a > 0) ? fix16_max : fix16_min;
  return result;
}

variable_types: result int


decompiled_code:
__int64 __fastcall fix16_ssub(int a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = fix16_sub(a1, a2);
if ( (_DWORD)result == 0x80000000 && v3 > 0 )
result = 0x7FFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = func5(a1, a2);
if ( (_DWORD)result == 0x80000000 && v3 > 0 )
result = 0x7FFFFFFFLL;
return result;
}

original_code:
fix16_t fix16_ssub(fix16_t a, fix16_t b)
{
  fix16_t result = fix16_sub(a, b);
  if (result == fix16_overflow)
    return (a > 0) ? fix16_max : fix16_min;
  return result;
}

canonical_original_code:
int fix16_ssub(int a, int b)
{
  int result = fix16_sub(a, b);
  if (result == fix16_overflow)
    return (a > 0) ? fix16_max : fix16_min;
  return result;
}


original_code:
fix16_t fix16_mul(fix16_t inArg0, fix16_t inArg1)
{
  int64_t product = (int64_t)inArg0 * inArg1;
  uint32_t upper = (product >> 47);
  if (product < 0)
  {
    if (~upper)
        return fix16_overflow;
    product--;
  }
  else
  {
    if (upper)
        return fix16_overflow;
  }
  fix16_t result = product >> 16;
  result += (product & 0x8000) >> 15;
  return result;
}

canonical_original_code:
int fix16_mul(int inArg0, int inArg1)
{
  long product = (int64_t)inArg0 * inArg1;
  unsigned int upper = (product >> 47);
  if (product < 0)
  {
    if (~upper)
        return fix16_overflow;
    product--;
  }
  else
  {
    if (upper)
        return fix16_overflow;
  }
  int result = product >> 16;
  result += (product & 0x8000) >> 15;
  return result;
}

variable_types: product long

variable_types:
upper
unsigned int


decompiled_code:
__int64 __fastcall fix16_smul(int a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = fix16_mul(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 < 0 != v3 >= 0 )
result = 0x7FFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = func8(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 < 0 != v3 >= 0 )
result = 0x7FFFFFFFLL;
return result;
}

original_code:
fix16_t fix16_smul(fix16_t inArg0, fix16_t inArg1) {
  fix16_t result = fix16_mul(inArg0, inArg1);
  if (result == fix16_overflow)
  {
    if ((inArg0 >= 0) == (inArg1 >= 0))
      return fix16_max;
    else
      return fix16_min;
  }
  return result;
}

canonical_original_code:
int fix16_smul(int inArg0, int inArg1) {
  int result = fix16_mul(inArg0, inArg1);
  if (result == fix16_overflow)
  {
    if ((inArg0 >= 0) == (inArg1 >= 0))
      return fix16_max;
    else
      return fix16_min;
  }
  return result;
}


original_code:
fix16_t fix16_div(fix16_t a, fix16_t b)
{
  if (b == 0)
      return fix16_min;
  uint32_t remainder = (a >= 0) ? a : (-a);
  uint32_t divider = (b >= 0) ? b : (-b);
  uint32_t quotient = 0;
  int bit_pos = 17;
  if (divider & 0xFFF00000)
  {
    uint32_t shifted_div = ((divider >> 17) + 1);
    quotient = remainder / shifted_div;
    remainder -= ((uint64_t)quotient * divider) >> 17;
  }
  while (!(divider & 0xF) && bit_pos >= 4)
  {
    divider >>= 4;
    bit_pos -= 4;
  }
  while (remainder && bit_pos >= 0)
  {
    int shift = __builtin_clzl(remainder);
    if (shift > bit_pos) shift = bit_pos;
    remainder <<= shift;
    bit_pos -= shift;
    uint32_t div = remainder / divider;
    remainder = remainder % divider;
    quotient += div << bit_pos;
    if (div & ~(0xFFFFFFFF >> bit_pos))
        return fix16_overflow;
    remainder <<= 1;
    bit_pos--;
  }
  quotient++;
  fix16_t result = quotient >> 1;
  if ((a ^ b) & 0x80000000)
  {
    if (result == fix16_min)
        return fix16_overflow;
    result = -result;
  }
  return result;
}

canonical_original_code:
int fix16_div(int a, int b)
{
  if (b == 0)
      return fix16_min;
  unsigned int remainder = (a >= 0) ? a : (-a);
  unsigned int divider = (b >= 0) ? b : (-b);
  unsigned int quotient = 0;
  int bit_pos = 17;
  if (divider & 0xFFF00000)
  {
    unsigned int shifted_div = ((divider >> 17) + 1);
    quotient = remainder / shifted_div;
    remainder -= ((unsigned long)quotient * divider) >> 17;
  }
  while (!(divider & 0xF) && bit_pos >= 4)
  {
    divider >>= 4;
    bit_pos -= 4;
  }
  while (remainder && bit_pos >= 0)
  {
    int shift = __builtin_clzl(remainder);
    if (shift > bit_pos) shift = bit_pos;
    remainder <<= shift;
    bit_pos -= shift;
    unsigned int div = remainder / divider;
    remainder = remainder % divider;
    quotient += div << bit_pos;
    if (div & ~(0xFFFFFFFF >> bit_pos))
        return fix16_overflow;
    remainder <<= 1;
    bit_pos--;
  }
  quotient++;
  int result = quotient >> 1;
  if ((a ^ b) & 0x80000000)
  {
    if (result == fix16_min)
        return fix16_overflow;
    result = -result;
  }
  return result;
}

variable_types:
remainder
unsigned int

variable_types:
divider
unsigned int

variable_types:
quotient
unsigned int

variable_types: shift int

variable_types:
div
unsigned int


decompiled_code:
__int64 __fastcall fix16_sdiv(int a1, int a2)
{
__int64 result; // rax

result = fix16_div(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 < 0 != a2 >= 0 )
result = 0x7FFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
__int64 result; // rax

result = func10(a1, a2);
if ( (_DWORD)result == 0x80000000 && a1 < 0 != a2 >= 0 )
result = 0x7FFFFFFFLL;
return result;
}

original_code:
fix16_t fix16_sdiv(fix16_t inArg0, fix16_t inArg1) {
  fix16_t result = fix16_div(inArg0, inArg1);
  if (result == fix16_overflow)
  {
    if ((inArg0 >= 0) == (inArg1 >= 0))
      return fix16_max;
    else
      return fix16_min;
  }
  return result;
}

canonical_original_code:
int fix16_sdiv(int inArg0, int inArg1) {
  int result = fix16_div(inArg0, inArg1);
  if (result == fix16_overflow)
  {
    if ((inArg0 >= 0) == (inArg1 >= 0))
      return fix16_max;
    else
      return fix16_min;
  }
  return result;
}


original_code:
fix16_t fix16_lerp8(fix16_t inArg0, fix16_t inArg1, uint8_t inFract) {
 int64_t tempOut = int64_mul_i32_i32(inArg0, ((1 << 8) - inFract));
 tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
 tempOut = int64_shift(tempOut, -8);
 return (fix16_t)int64_lo(tempOut);
}

canonical_original_code:
int fix16_lerp8(int inArg0, int inArg1, unsigned char inFract) {
 long tempOut = int64_mul_i32_i32(inArg0, ((1 << 8) - inFract));
 tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
 tempOut = int64_shift(tempOut, -8);
 return (int)int64_lo(tempOut);
}

variable_types:
inFract
unsigned char

variable_types: tempOut long


original_code:
fix16_t fix16_lerp16(fix16_t inArg0, fix16_t inArg1, uint16_t inFract) {
 int64_t tempOut = int64_mul_i32_i32(inArg0, ((1 << 16) - inFract));
 tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
 tempOut = int64_shift(tempOut, -16);
 return (fix16_t)int64_lo(tempOut);
}

canonical_original_code:
int fix16_lerp16(int inArg0, int inArg1, unsigned short inFract) {
 long tempOut = int64_mul_i32_i32(inArg0, ((1 << 16) - inFract));
 tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract));
 tempOut = int64_shift(tempOut, -16);
 return (int)int64_lo(tempOut);
}

variable_types:
inFract
unsigned short


decompiled_code:
__int64 __fastcall fix16_lerp32(int a1, int a2, unsigned int a3)
{
return (__int64)(a2 * (unsigned __int64)a3 + -a3 * (__int64)a1) >> 32;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, int a2, unsigned int a3)
{
return (__int64)(a2 * (unsigned __int64)a3 + -a3 * (__int64)a1) >> 32;
}

original_code:
fix16_t fix16_lerp32(fix16_t inArg0, fix16_t inArg1, uint32_t inFract) {
 int64_t tempOut;
 tempOut = ((int64_t)inArg0 * (0 - inFract));
 tempOut += ((int64_t)inArg1 * inFract);
 tempOut >>= 32;
 return (fix16_t)tempOut;
}

canonical_original_code:
int fix16_lerp32(int inArg0, int inArg1, unsigned int inFract) {
 long tempOut;
 tempOut = ((long)inArg0 * (0 - inFract));
 tempOut += ((long)inArg1 * inFract);
 tempOut >>= 32;
 return (int)tempOut;
}

variable_types:
inFract
unsigned int


decompiled_code:
__int64 __fastcall fract32_create(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( a2 > a1 )
result = a1 % a2 * (0xFFFFFFFF / (a2 - 1));
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a2 > a1 )
result = a1 % a2 * (0xFFFFFFFF / (a2 - 1));
return result;
}

original_code:
fract32_t fract32_create(uint32_t inNumerator, uint32_t inDenominator) {
 if(inDenominator <= inNumerator)
  return 0xFFFFFFFF;
 uint32_t tempMod = (inNumerator % inDenominator);
 uint32_t tempDiv = (0xFFFFFFFF / (inDenominator - 1));
 return (tempMod * tempDiv);
}

canonical_original_code:
unsigned int fract32_create(unsigned int inNumerator, unsigned int inDenominator) {
 if(inDenominator <= inNumerator)
  return 0xFFFFFFFF;
 unsigned int tempMod = (inNumerator % inDenominator);
 unsigned int tempDiv = (0xFFFFFFFF / (inDenominator - 1));
 return (tempMod * tempDiv);
}

variable_types:
inNumerator
unsigned int

variable_types:
inDenominator
unsigned int

variable_types:
tempMod
unsigned int

variable_types:
tempDiv
unsigned int


decompiled_code:
__int64 __fastcall fract32_invert(int a1)
{
return (unsigned int)~a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)~a1;
}

original_code:
fract32_t fract32_invert(fract32_t inFract) {
 return (0xFFFFFFFF - inFract);
}

canonical_original_code:
unsigned int fract32_invert(unsigned int inFract) {
 return (0xFFFFFFFF - inFract);
}


decompiled_code:
unsigned __int64 __fastcall fract32_usmul(unsigned int a1, unsigned int a2)
{
return (a2 * (unsigned __int64)a1) >> 32;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
return (a2 * (unsigned __int64)a1) >> 32;
}

original_code:
uint32_t fract32_usmul(uint32_t inVal, fract32_t inFract) {
 return (uint32_t)(((uint64_t)inVal * (uint64_t)inFract) >> 32);
}

canonical_original_code:
unsigned int fract32_usmul(unsigned int inVal, unsigned int inFract) {
 return (unsigned int)(((unsigned long)inVal * (unsigned long)inFract) >> 32);
}

variable_types:
inVal
unsigned int


decompiled_code:
unsigned __int64 __fastcall fract32_smul(signed int a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( a1 < 0 )
result = (unsigned int)-(__int64)fract32_usmul(-a1, a2);
else
result = fract32_usmul(a1, a2);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(signed int a1, unsigned int a2)
{
unsigned __int64 result; // rax

if ( a1 < 0 )
result = (unsigned int)-(__int64)func2(-a1, a2);
else
result = func2(a1, a2);
return result;
}

original_code:
int32_t fract32_smul(int32_t inVal, fract32_t inFract) {
 if(inVal < 0)
  return -fract32_usmul(-inVal, inFract);
 return fract32_usmul(inVal, inFract);
}

canonical_original_code:
int fract32_smul(int inVal, unsigned int inFract) {
 if(inVal < 0)
  return -fract32_usmul(-inVal, inFract);
 return fract32_usmul(inVal, inFract);
}

variable_types: inVal int