findNonSpace

decompiled_code:
__int64 __fastcall findNonSpace(__int64 a1, signed int a2)
{
char v2; // dl
__int64 v3; // rax
unsigned int v4; // er8
char v5; // dl
__int64 result; // rax
unsigned int v7; // er8

v2 = *(_BYTE *)(a1 + a2);
if ( v2 == 32 )
{
v3 = a2 + 1;
do
{
v4 = v3++;
v5 = *(_BYTE *)(a1 + v3 - 1);
}
while ( v5 == 32 );
if ( !v5 )
v4 = -1;
result = v4;
}
else
{
v7 = a2;
if ( !v2 )
v7 = -1;
result = v7;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, signed int a2)
{
char v2; // dl
__int64 v3; // rax
unsigned int v4; // er8
char v5; // dl
__int64 result; // rax
unsigned int v7; // er8

v2 = *(_BYTE *)(a1 + a2);
if ( v2 == 32 )
{
v3 = a2 + 1;
do
{
v4 = v3++;
v5 = *(_BYTE *)(a1 + v3 - 1);
}
while ( v5 == 32 );
if ( !v5 )
v4 = -1;
result = v4;
}
else
{
v7 = a2;
if ( !v2 )
v7 = -1;
result = v7;
}
return result;
}

original_code:
int findNonSpace(char *s, int start) {
  int i;
  for (i = start ; ((s[i] == ' ') && (s[i] != '\0')) ; i++)
                 ;
  if (s[i] == '\0')
    return -1;
  else
    return i;
}


testalloc

repo: peterbourgon/hose-poet

decompiled_code:
void *__fastcall testalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "Out of memory trying to allocate %d bytes\n", a1);
fwrite("Program terminated\n", 1uLL, 0x13uLL, stderr);
exit(2);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func9(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "Out of memory trying to allocate %d bytes\n", a1);
fwrite("Program terminated\n", 1uLL, 0x13uLL, stderr);
exit(2);
}
return result;
}

original_code:
void *testalloc(size_t size) {
  void *toreturn;
  toreturn = (void *)malloc(size);
  if (toreturn == ((void *)0)) {
    fprintf(stderr, "Out of memory trying to allocate %d bytes\n", size);
    fprintf(stderr, "Program terminated\n");
    exit(2);
  } else {
    return toreturn;
  }
}

canonical_original_code:
void *testalloc(unsigned long size) {
  void *toreturn;
  toreturn = (void *)malloc(size);
  if (toreturn == ((void *)0)) {
    fprintf(stderr, "Out of memory trying to allocate %d bytes\n", size);
    fprintf(stderr, "Program terminated\n");
    exit(2);
  } else {
    return toreturn;
  }
}

variable_types:
size
unsigned long

variable_types:
toreturn
void *

return_type: void *


freeBlocks

decompiled_code:
void __fastcall freeBlocks(void *ptr)
{
if ( ptr )
{
freeBlocks(*((void **)ptr + 129));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
if ( ptr )
{
func12(*((void **)ptr + 129));
free(ptr);
}
}

original_code:
void freeBlocks(struct StringBlock *block) {
  if (block == ((void *)0)) {
    return;
  } else {
    freeBlocks(block->next);
    free(block);
  }
}

variable_types: struct StringBlock { char block[1024]; int length; struct StringBlock *next; } *

return_type: void


lineLength

decompiled_code:
__int64 __fastcall lineLength(__int64 a1)
{
__int64 result; // rax
int v2; // edx

for ( result = 0LL; a1; result = (unsigned int)(v2 + result) )
{
v2 = *(_DWORD *)(a1 + 1024);
a1 = *(_QWORD *)(a1 + 1032);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 result; // rax
int v2; // edx

for ( result = 0LL; a1; result = (unsigned int)(v2 + result) )
{
v2 = *(_DWORD *)(a1 + 1024);
a1 = *(_QWORD *)(a1 + 1032);
}
return result;
}

original_code:
int lineLength(struct StringBlock *block) {
  if (block == ((void *)0)) {
    return 0;
  } else {
    return block->length + lineLength(block->next);
  }
}

return_type: int

user_defined_types: struct StringBlock { char block[1024]; int length; struct StringBlock *next; }


cmpLongLine

decompiled_code:
__int64 __fastcall cmpLongLine(unsigned __int64 a1, __int64 a2)
{
__int64 v3; // rdi
int v4; // er11
int v5; // er9
__int64 i; // rax
char v7; // cl
int v8; // edx

v3 = a2;
if ( !(a2 | a1) )
return 0LL;
while ( 1 )
{
if ( !v3 )
return (unsigned int)*(char *)a1;
v4 = *(_DWORD *)(a1 + 1024);
v5 = *(_DWORD *)(v3 + 1024);
if ( v4 <= 0 )
{
v8 = 0;
}
else
{
for ( i = 0LL; i != v4; ++i )
{
v8 = i;
if ( v5 <= (int)i )
break;
v7 = *(_BYTE *)(a1 + i);
if ( v7 != *(_BYTE *)(v3 + i) )
return (unsigned int)(v7 - *(char *)(v3 + i));
++v8;
}
}
if ( v5 < v4 )
return (unsigned int)*(char *)(a1 + v8);
if ( v5 > v4 )
break;
v3 = *(_QWORD *)(v3 + 1032);
a1 = *(_QWORD *)(a1 + 1032);
if ( !(a1 | v3) )
return 0LL;
}
return (unsigned int)-*(char *)(v3 + v8);
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int64 a1, __int64 a2)
{
__int64 v3; // rdi
int v4; // er11
int v5; // er9
__int64 i; // rax
char v7; // cl
int v8; // edx

v3 = a2;
if ( !(a2 | a1) )
return 0LL;
while ( 1 )
{
if ( !v3 )
return (unsigned int)*(char *)a1;
v4 = *(_DWORD *)(a1 + 1024);
v5 = *(_DWORD *)(v3 + 1024);
if ( v4 <= 0 )
{
v8 = 0;
}
else
{
for ( i = 0LL; i != v4; ++i )
{
v8 = i;
if ( v5 <= (int)i )
break;
v7 = *(_BYTE *)(a1 + i);
if ( v7 != *(_BYTE *)(v3 + i) )
return (unsigned int)(v7 - *(char *)(v3 + i));
++v8;
}
}
if ( v5 < v4 )
return (unsigned int)*(char *)(a1 + v8);
if ( v5 > v4 )
break;
v3 = *(_QWORD *)(v3 + 1032);
a1 = *(_QWORD *)(a1 + 1032);
if ( !(a1 | v3) )
return 0LL;
}
return (unsigned int)-*(char *)(v3 + v8);
}

original_code:
int cmpLongLine(struct StringBlock *a, struct StringBlock *b) {
  int i;
  if ((a == ((void *)0)) && (b == ((void *)0))) {
    return 0;
  } else if (b == ((void *)0)) {
    return a->block[0];
  } else if (b == ((void *)0)) {
    return 0 - a->block[0];
  } else {
    for (i = 0 ; i < a->length && i < b->length ; i++) {
      if (a->block[i] != b->block[i]) {
 return a->block[i] - b->block[i];
      }
    }
    if (a->length > b->length) {
      return a->block[i];
    } else if (b->length > a->length) {
      return -1 * b->block[i];
    } else {
      return cmpLongLine(a->next, b->next);
    }
  }
}

variable_types:
b
struct StringBlock *

variable_types: i int


findSpace

decompiled_code:
__int64 __fastcall findSpace(_BYTE *a1)
{
__int64 v1; // rax
char v2; // dl
unsigned int v3; // er8
__int64 result; // rax
unsigned int v5; // er8

if ( (*a1 & 0xDF) != 0 )
{
v1 = 1LL;
do
{
v2 = a1[v1];
v3 = v1++;
}
while ( (v2 & 0xDF) != 0 );
if ( !v2 )
v3 = -1;
result = v3;
}
else
{
v5 = 0;
if ( !*a1 )
v5 = -1;
result = v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1)
{
__int64 v1; // rax
char v2; // dl
unsigned int v3; // er8
__int64 result; // rax
unsigned int v5; // er8

if ( (*a1 & 0xDF) != 0 )
{
v1 = 1LL;
do
{
v2 = a1[v1];
v3 = v1++;
}
while ( (v2 & 0xDF) != 0 );
if ( !v2 )
v3 = -1;
result = v3;
}
else
{
v5 = 0;
if ( !*a1 )
v5 = -1;
result = v5;
}
return result;
}

original_code:
int findSpace(char *s) {
  int i;
  for (i = 0 ; ((s[i] != ' ') && (s[i] != '\0')) ; i++)
                  ;
  if (s[i] == '\0')
    return -1;
  else
    return i;
}

variable_types:
s
char *


stringToWordEntry

decompiled_code:
__int64 __fastcall stringToWordEntry(const char *a1)
{
__int64 v1; // r12
size_t v2; // rax
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rbx

v1 = 0LL;
v2 = strlen(a1);
v3 = getStringParts(a1, 0LL, v2);
if ( (int)countStringParts(v3) > 1 )
{
v4 = testalloc(48LL);
*(_QWORD *)(v4 + 8) = v3;
v5 = *(_QWORD *)(v3 + 16);
v1 = v4;
*(_QWORD *)(v4 + 24) = 0LL;
*(_QWORD *)(v4 + 16) = v5;
for ( *(_DWORD *)(v4 + 32) = 0; v5; v5 = *(_QWORD *)(v5 + 16) )
{
while ( 1 )
{
if ( (unsigned int)isSyllable(v5) )
{
++*(_DWORD *)(v1 + 32);
if ( (unsigned int)isPrimaryStress(v5) )
break;
}
v5 = *(_QWORD *)(v5 + 16);
if ( !v5 )
goto LABEL_8;
}
*(_QWORD *)(v1 + 24) = v5;
}
LABEL_8:
*(_QWORD *)(v1 + 40) = 0LL;
*(_QWORD *)v1 = a1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
__int64 v1; // r12
size_t v2; // rax
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rbx

v1 = 0LL;
v2 = strlen(a1);
v3 = getStringParts(a1, 0LL, v2);
if ( (int)countStringParts(v3) > 1 )
{
v4 = testalloc(48LL);
*(_QWORD *)(v4 + 8) = v3;
v5 = *(_QWORD *)(v3 + 16);
v1 = v4;
*(_QWORD *)(v4 + 24) = 0LL;
*(_QWORD *)(v4 + 16) = v5;
for ( *(_DWORD *)(v4 + 32) = 0; v5; v5 = *(_QWORD *)(v5 + 16) )
{
while ( 1 )
{
if ( (unsigned int)isSyllable(v5) )
{
++*(_DWORD *)(v1 + 32);
if ( (unsigned int)isPrimaryStress(v5) )
break;
}
v5 = *(_QWORD *)(v5 + 16);
if ( !v5 )
goto LABEL_8;
}
*(_QWORD *)(v1 + 24) = v5;
}
LABEL_8:
*(_QWORD *)(v1 + 40) = 0LL;
*(_QWORD *)v1 = a1;
}
return v1;
}

original_code:
struct WordEntry *stringToWordEntry(char *string) {
  struct WordEntry *toreturn;
  struct StringPart *parts;
  struct StringPart *current;
  parts = getStringParts(string, 0, strlen(string));
  if (countStringParts(parts) < 2) return ((void *)0);
  toreturn = (struct WordEntry *)testalloc(sizeof(struct WordEntry));
  toreturn->word = parts;
  toreturn->phonemes = parts->next;
  toreturn->rhymekey = ((void *)0);
  toreturn->syllables = 0;
  for (current = parts->next ; current != ((void *)0) ;
       current = current->next) {
    if (isSyllable(current)) {
      toreturn->syllables++;
      if (isPrimaryStress(current))
 toreturn->rhymekey = current;
    }
  }
  toreturn->alternate = ((void *)0);
  toreturn->string = string;
  return toreturn;
}

variable_types:
string
char *

variable_types: struct WordEntry { char *string; struct StringPart { char *string; int length; struct StringPart *next; } *word; struct StringPart *phonemes; struct StringPart *rhymekey; int syllables; struct WordEntry *alternate; } *

user_defined_types: struct WordEntry { char *string; struct StringPart *word; struct StringPart *phonemes; struct StringPart *rhymekey; int syllables; struct WordEntry *alternate; }


isMultiplePronunciation

decompiled_code:
_BOOL8 __fastcall isMultiplePronunciation(__int64 a1)
{
return *(_BYTE *)(**(_QWORD **)(a1 + 8) + *(int *)(*(_QWORD *)(a1 + 8) + 8LL) - 1LL) == 41;
}

original_code:
int isMultiplePronunciation(struct WordEntry *entry) {
  if (entry->word->string[entry->word->length - 1] == ')')
    return 1;
  else
    return 0;
}

user_defined_types: struct StringPart { char *string; int length; struct StringPart *next; }


freeWordEntry

decompiled_code:
void __fastcall freeWordEntry(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void freeWordEntry(struct WordEntry *entry) {
  free(entry->string);
  free(entry);
}


popWordEntry

original_code:
struct WordEntry *popWordEntry(struct WordEntryStack **stack) {
  struct WordEntryStack *head;
  struct WordEntry *toreturn;
  head = *stack;
  if (head == ((void *)0)) return ((void *)0);
  *stack = head->next;
  toreturn = head->entry;
  free(head);
  return toreturn;
}

variable_types: struct WordEntryStack { struct WordEntry *entry; struct WordEntryStack *next; } **

variable_types: struct WordEntryStack { struct WordEntry { char *string; struct StringPart { char *string; int length; struct StringPart *next; } *word; struct StringPart *phonemes; struct StringPart *rhymekey; int syllables; struct WordEntry *alternate; } *entry; struct WordEntryStack *next; } *


reverseWordEntryStack

decompiled_code:
__int64 __fastcall reverseWordEntryStack(__int64 *a1)
{
__int64 v1; // rax
__int64 *v3; // [rsp+8h] [rbp-20h] BYREF
__int64 v4; // [rsp+18h] [rbp-10h] BYREF

v3 = a1;
v4 = 0LL;
if ( !a1 )
return 0LL;
do
{
v1 = popWordEntry(&v3);
pushWordEntry(&v4, v1);
}
while ( v3 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
__int64 v1; // rax
__int64 *v3; // [rsp+8h] [rbp-20h] BYREF
__int64 v4; // [rsp+18h] [rbp-10h] BYREF

v3 = a1;
v4 = 0LL;
if ( !a1 )
return 0LL;
do
{
v1 = func4(&v3);
pushWordEntry(&v4, v1);
}
while ( v3 );
return v4;
}

original_code:
struct WordEntryStack *reverseWordEntryStack(struct WordEntryStack *stack) {
  struct WordEntryStack *toreturn = ((void *)0);
  while (stack != ((void *)0)) {
    pushWordEntry(&toreturn, popWordEntry(&stack));
  }
  return toreturn;
}

variable_types:
stack
struct WordEntryStack *

return_type: struct WordEntryStack { struct WordEntry { char *string; struct StringPart { char *string; int length; struct StringPart *next; } *word; struct StringPart *phonemes; struct StringPart *rhymekey; int syllables; struct WordEntry *alternate; } *entry; struct WordEntryStack *next; } *

user_defined_types: struct WordEntryStack { struct WordEntry *entry; struct WordEntryStack *next; }


freeWordEntryStack

decompiled_code:
void __fastcall freeWordEntryStack(void *ptr)
{
if ( ptr )
{
freeWordEntryStack(*((void **)ptr + 1));
freeWordEntry(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
if ( ptr )
{
func6(*((void **)ptr + 1));
func3(*(void **)ptr);
free(ptr);
}
}

original_code:
void freeWordEntryStack(struct WordEntryStack *stack) {
  if (stack == ((void *)0)) return;
  else {
    freeWordEntryStack(stack->next);
    freeWordEntry(stack->entry);
    free(stack);
  }
}


freeOnlyEntryTree

decompiled_code:
void __fastcall freeOnlyEntryTree(void *ptr)
{
if ( ptr )
{
freeOnlyEntryTree(*((void **)ptr + 2));
freeOnlyEntryTree(*((void **)ptr + 3));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
if ( ptr )
{
func7(*((void **)ptr + 2));
func7(*((void **)ptr + 3));
free(ptr);
}
}

original_code:
void freeOnlyEntryTree(struct WordEntryTree *tree) {
  if (tree == ((void *)0)) return;
  else {
    freeOnlyEntryTree(tree->lesser);
    freeOnlyEntryTree(tree->greater);
    free(tree);
  }
}

variable_types: struct WordEntryTree { struct StringPart { char *string; int length; struct StringPart *next; } *rhymekey; struct WordEntryStack { struct WordEntry { char *string; struct StringPart *word; struct StringPart *phonemes; struct StringPart *rhymekey; int syllables; struct WordEntry *alternate; } *entry; struct WordEntryStack *next; } *rhymes; struct WordEntryTree *lesser; struct WordEntryTree *greater; } *

user_defined_types: struct WordEntryTree { struct StringPart *rhymekey; struct WordEntryStack *rhymes; struct WordEntryTree *lesser; struct WordEntryTree *greater; }


isBaseWord

decompiled_code:
_BOOL8 __fastcall isBaseWord(__int64 a1, __int64 a2)
{
char **v2; // rax
__int64 v3; // r9
char *v4; // rcx
char v5; // dl
__int64 v6; // rax
int v7; // edi
_BOOL8 result; // rax

if ( isMultiplePronunciation(a1) )
return 0LL;
v2 = *(char ***)(a2 + 8);
v3 = *(_QWORD *)(a1 + 8);
v4 = *v2;
v5 = **v2;
if ( v5 == 40 )
{
v7 = 0;
LABEL_9:
result = *(_DWORD *)(v3 + 8) == v7;
}
else
{
v6 = 1LL;
while ( *(_BYTE *)(*(_QWORD *)v3 + v6 - 1) == v5 )
{
v7 = v6++;
v5 = v4[v6 - 1];
if ( v5 == 40 )
goto LABEL_9;
}
result = 0LL;
}
return result;
}

original_code:
int isBaseWord(struct WordEntry *entry, struct WordEntry *multiple) {
  int i;
  if (isMultiplePronunciation(entry)) return 0;
  for (i = 0 ; multiple->word->string[i] != '(' ; i++) {
    if (entry->word->string[i] != multiple->word->string[i])
      return 0;
  }
  if (i == entry->word->length)
    return 1;
  else
    return 0;
}

variable_types:
multiple
struct WordEntry *


addMultiplePronunciation

decompiled_code:
__int64 __fastcall addMultiplePronunciation(__int64 *a1, __int64 a2, int a3)
{
__int64 *v3; // r10
__int64 v5; // rbx
__int64 v6; // r10
__int64 result; // rax

if ( !a1 )
return 1LL;
v3 = a1;
while ( 1 )
{
v5 = *v3;
if ( isBaseWord(*v3, a2) )
break;
v3 = *(__int64 **)(v6 + 8);
if ( !v3 )
return 1LL;
}
if ( *(_QWORD *)(v5 + 40) )
{
while ( !a3 || (unsigned int)cmpStringParts(*(_QWORD *)(a2 + 24), *(_QWORD *)(v5 + 24)) )
{
v5 = *(_QWORD *)(v5 + 40);
if ( !*(_QWORD *)(v5 + 40) )
goto LABEL_12;
}
result = 0LL;
}
else
{
LABEL_12:
if ( !a3 || (unsigned int)cmpStringParts(*(_QWORD *)(a2 + 24), *(_QWORD *)(v5 + 24)) )
{
*(_QWORD *)(v5 + 40) = a2;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, __int64 a2, int a3)
{
__int64 *v3; // r10
__int64 v5; // rbx
__int64 v6; // r10
__int64 result; // rax

if ( !a1 )
return 1LL;
v3 = a1;
while ( 1 )
{
v5 = *v3;
if ( func8(*v3, a2) )
break;
v3 = *(__int64 **)(v6 + 8);
if ( !v3 )
return 1LL;
}
if ( *(_QWORD *)(v5 + 40) )
{
while ( !a3 || (unsigned int)cmpStringParts(*(_QWORD *)(a2 + 24), *(_QWORD *)(v5 + 24)) )
{
v5 = *(_QWORD *)(v5 + 40);
if ( !*(_QWORD *)(v5 + 40) )
goto LABEL_12;
}
result = 0LL;
}
else
{
LABEL_12:
if ( !a3 || (unsigned int)cmpStringParts(*(_QWORD *)(a2 + 24), *(_QWORD *)(v5 + 24)) )
{
*(_QWORD *)(v5 + 40) = a2;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int addMultiplePronunciation(struct WordEntryStack *stack,
         struct WordEntry *entry,
         int skipduplicates) {
  struct WordEntryStack *base;
  struct WordEntry *alternate;
  for (base = stack ; (base != ((void *)0)) && (!isBaseWord(base->entry, entry)) ;
       base = base->next) ;
  if (base == ((void *)0)) return 1;
  alternate = base->entry;
  while (alternate->alternate != ((void *)0)) {
    if (skipduplicates &&
 (cmpStringParts(entry->rhymekey, alternate->rhymekey) == 0)) return 0;
    else alternate = alternate->alternate;
  }
  if (!skipduplicates ||
      cmpStringParts(entry->rhymekey, alternate->rhymekey) != 0) {
    alternate->alternate = entry;
    return 1;
  } else {
    return 0;
  }
}

variable_types:
entry
struct WordEntry *

variable_types: skipduplicates int


fatalError

decompiled_code:
void __fastcall __noreturn fatalError(char *format)
{
fprintf(stderr, format);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(char *format)
{
fprintf(stderr, format);
exit(1);
}

original_code:
void fatalError(char s[]) {
  fprintf(stderr, s);
  exit(1);
}

variable_types:
s
char []


swapSyllableModes

decompiled_code:
__int64 __fastcall swapSyllableModes(_DWORD *a1)
{
__int64 result; // rax

result = *a1 | 1u;
if ( (*a1 & 1) != 0 )
result = *a1 & 0xFFFFFFFE;
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1)
{
__int64 result; // rax

result = *a1 | 1u;
if ( (*a1 & 1) != 0 )
result = *a1 & 0xFFFFFFFE;
*a1 = result;
return result;
}

original_code:
void swapSyllableModes(int *flags) {
  if (*flags & 1) {
    *flags &= ~1;
  } else {
    *flags |= 1;
  }
}

variable_types:
flags
int *


swapMergedModes

decompiled_code:
__int64 __fastcall swapMergedModes(_DWORD *a1)
{
__int64 result; // rax

result = *a1 | 4u;
if ( (*a1 & 4) != 0 )
result = *a1 & 0xFFFFFFFB;
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1)
{
__int64 result; // rax

result = *a1 | 4u;
if ( (*a1 & 4) != 0 )
result = *a1 & 0xFFFFFFFB;
*a1 = result;
return result;
}

original_code:
void swapMergedModes(int *flags) {
  if (*flags & 4) {
    *flags &= ~4;
  } else {
    *flags |= 4;
  }
}


testalloc

canonical_decompiled_code:
void *__fastcall func7(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "Out of memory trying to allocate %d bytes\n", a1);
fwrite("Program terminated\n", 1uLL, 0x13uLL, stderr);
exit(2);
}
return result;
}

original_code:
void *testalloc(size_t size) {
  void *toreturn;
  toreturn = (void *)malloc(size);
  if (toreturn == ((void *)0)) {
    fprintf(stderr, "Out of memory trying to allocate %d bytes\n", size);
    fprintf(stderr, "Program terminated\n");
    exit(2);
  } else {
    return toreturn;
  }
}

variable_types:
size
unsigned long


freeBlocks

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
if ( ptr )
{
func10(*((void **)ptr + 129));
free(ptr);
}
}

original_code:
void freeBlocks(struct StringBlock *block) {
  if (block == ((void *)0)) {
    return;
  } else {
    freeBlocks(block->next);
    free(block);
  }
}


lineLength

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 result; // rax
int v2; // edx

for ( result = 0LL; a1; result = (unsigned int)(v2 + result) )
{
v2 = *(_DWORD *)(a1 + 1024);
a1 = *(_QWORD *)(a1 + 1032);
}
return result;
}

original_code:
int lineLength(struct StringBlock *block) {
  if (block == ((void *)0)) {
    return 0;
  } else {
    return block->length + lineLength(block->next);
  }
}


cmpLongLine

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int64 a1, __int64 a2)
{
__int64 v3; // rdi
int v4; // er11
int v5; // er9
__int64 i; // rax
char v7; // cl
int v8; // edx

v3 = a2;
if ( !(a2 | a1) )
return 0LL;
while ( 1 )
{
if ( !v3 )
return (unsigned int)*(char *)a1;
v4 = *(_DWORD *)(a1 + 1024);
v5 = *(_DWORD *)(v3 + 1024);
if ( v4 <= 0 )
{
v8 = 0;
}
else
{
for ( i = 0LL; i != v4; ++i )
{
v8 = i;
if ( v5 <= (int)i )
break;
v7 = *(_BYTE *)(a1 + i);
if ( v7 != *(_BYTE *)(v3 + i) )
return (unsigned int)(v7 - *(char *)(v3 + i));
++v8;
}
}
if ( v5 < v4 )
return (unsigned int)*(char *)(a1 + v8);
if ( v5 > v4 )
break;
v3 = *(_QWORD *)(v3 + 1032);
a1 = *(_QWORD *)(a1 + 1032);
if ( !(a1 | v3) )
return 0LL;
}
return (unsigned int)-*(char *)(v3 + v8);
}

original_code:
int cmpLongLine(struct StringBlock *a, struct StringBlock *b) {
  int i;
  if ((a == ((void *)0)) && (b == ((void *)0))) {
    return 0;
  } else if (b == ((void *)0)) {
    return a->block[0];
  } else if (b == ((void *)0)) {
    return 0 - a->block[0];
  } else {
    for (i = 0 ; i < a->length && i < b->length ; i++) {
      if (a->block[i] != b->block[i]) {
 return a->block[i] - b->block[i];
      }
    }
    if (a->length > b->length) {
      return a->block[i];
    } else if (b->length > a->length) {
      return -1 * b->block[i];
    } else {
      return cmpLongLine(a->next, b->next);
    }
  }
}


repo: petersenna/rdtscbench

decompiled_code:
int __fastcall rdtscb_measure(const char *a1, int a2, int a3, void (__fastcall *a4)(char *, char *))
{
int v6; // ebx
long double v7; // fst7
long double x; // [rsp+10h] [rbp-68h]
char v10[8]; // [rsp+30h] [rbp-48h] BYREF
__int64 v11; // [rsp+38h] [rbp-40h]
char v12[8]; // [rsp+40h] [rbp-38h] BYREF
__int64 v13; // [rsp+48h] [rbp-30h]

printf("%s: ", a1);
if ( a2 <= 0 )
{
x = 1.0;
}
else
{
v6 = a2;
x = 1.0;
do
{
while ( 1 )
{
a4(v10, v12);
x = (long double)(unsigned int)(int)(double)((int)v13 - (int)v11) * x;
if ( a3 == 1 )
break;
if ( !--v6 )
goto LABEL_6;
}
printf(" %llu, ", v13 - v11);
--v6;
}
while ( v6 );
}
LABEL_6:
v7 = powl(x, 1.0 / (long double)a2);
return printf("%25.6Lf clocks. Geom. mean of %4.0d values.\n", v7, (unsigned int)a2);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, int a2, int a3, void (__fastcall *a4)(char *, char *))
{
int v6; // ebx
long double v7; // fst7
long double x; // [rsp+10h] [rbp-68h]
char v10[8]; // [rsp+30h] [rbp-48h] BYREF
__int64 v11; // [rsp+38h] [rbp-40h]
char v12[8]; // [rsp+40h] [rbp-38h] BYREF
__int64 v13; // [rsp+48h] [rbp-30h]

printf("%s: ", a1);
if ( a2 <= 0 )
{
x = 1.0;
}
else
{
v6 = a2;
x = 1.0;
do
{
while ( 1 )
{
a4(v10, v12);
x = (long double)(unsigned int)(int)(double)((int)v13 - (int)v11) * x;
if ( a3 == 1 )
break;
if ( !--v6 )
goto LABEL_6;
}
printf(" %llu, ", v13 - v11);
--v6;
}
while ( v6 );
}
LABEL_6:
v7 = powl(x, 1.0 / (long double)a2);
return printf("%25.6Lf clocks. Geom. mean of %4.0d values.\n", v7, (unsigned int)a2);
}

original_code:
void inline rdtscb_measure (char msg[32], int repeats, int detailed, void (*function)( struct timespec *ts, struct timespec *te ) ){
 struct timespec begin, end, diff;
 long double acc = 1;
 int i = 0;
 printf ("%s: ", msg);
 for ( i = repeats; i > 0; i-- ){
  function( &begin, &end );
  diff.tv_nsec = end.tv_nsec - begin.tv_nsec;
  acc *= (long)(double)diff.tv_nsec;
  if ( detailed == 1 )
   printf ( " %llu, ", diff.tv_nsec );
 }
 long double power = 1;
 power /= repeats;
 long double valuemean = powl ( acc, power );
 printf ("%25.6Lf clocks. Geom. mean of %4.0d values.\n", valuemean, repeats );
}

canonical_original_code:
inline void rdtscb_measure(char msg[32], int repeats, int detailed, void (*function)(struct timespec *ts, struct timespec *te)){
 struct timespec begin; struct timespec end; struct timespec diff;
 long double acc = 1;
 int i = 0;
 printf ("%s: ", msg);
 for ( i = repeats; i > 0; i-- ){
  function( &begin, &end );
  diff.tv_nsec = end.tv_nsec - begin.tv_nsec;
  acc *= (long)(double)diff.tv_nsec;
  if ( detailed == 1 )
   printf ( " %llu, ", diff.tv_nsec );
 }
 long double power = 1;
 power /= repeats;
 long double valuemean = powl ( acc, power );
 printf ("%25.6Lf clocks. Geom. mean of %4.0d values.\n", valuemean, repeats );
}

variable_types:
msg
char [32]

variable_types: repeats int

variable_types: detailed int

variable_types: void (*)(struct timespec { long tv_sec; long tv_nsec; } *ts, struct timespec *te)

variable_types:
acc
long double

variable_types:
power
long double

variable_types:
valuemean
long double


decompiled_code:
unsigned __int64 __fastcall rdtscb_getticks(__int64 a1)
{
unsigned __int64 v6; // rdx
unsigned __int64 result; // rax

__asm { cpuid }
result = __rdtsc();
v6 = (unsigned __int64)HIDWORD(result) << 32;
result = (unsigned int)result;
*(_QWORD *)(a1 + 8) = (unsigned int)result | v6;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1)
{
unsigned __int64 v6; // rdx
unsigned __int64 result; // rax

__asm { cpuid }
result = __rdtsc();
v6 = (unsigned __int64)HIDWORD(result) << 32;
result = (unsigned int)result;
*(_QWORD *)(a1 + 8) = (unsigned int)result | v6;
return result;
}

original_code:
__inline__ void rdtscb_getticks(struct timespec *ts) {
 unsigned int a, d;
 asm("cpuid");
 asm volatile("rdtsc" : "=a" (a), "=d" (d));
 ts->tv_nsec = (((uint64_t)a) | (((uint64_t)d) << 32));
}

canonical_original_code:
__inline__ void rdtscb_getticks(struct timespec *ts) {
 unsigned int a; unsigned int d;
 asm("cpuid");
 asm volatile("rdtsc" : "=a" (a), "=d" (d));
 ts->tv_nsec = (((unsigned long)a) | (((unsigned long)d) << 32));
}

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

variable_types:
a
unsigned int

variable_types:
d
unsigned int


SIMPLEMATH

decompiled_code:
unsigned __int64 __fastcall SIMPLEMATH(__int64 a1, __int64 a2)
{
rdtscb_getticks(a1);
return rdtscb_getticks(a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(__int64 a1, __int64 a2)
{
func8(a1);
return func8(a2);
}

original_code:
void inline SIMPLEMATH ( struct timespec *ts, struct timespec *te ){
 uint64_t i,a,b,c,d;
 a = 1, b = 2, c = 4, d = 8;
 rdtscb_getticks ( ts );
 for (i = 0; i < 100000LL; i++){
  a = ( ( d * c ) / b);
  a--;b++;c++;d++;
 }
 rdtscb_getticks ( te );
}

canonical_original_code:
inline void SIMPLEMATH(struct timespec *ts, struct timespec *te){
 unsigned long i; unsigned long a; unsigned long b; unsigned long c; unsigned long d;
 a = 1, b = 2, c = 4, d = 8;
 rdtscb_getticks ( ts );
 for (i = 0; i < 100000LL; i++){
  a = ( ( d * c ) / b);
  a--;b++;c++;d++;
 }
 rdtscb_getticks ( te );
}

variable_types:
te
struct timespec *

variable_types:
i
unsigned long

variable_types:
a
unsigned long

variable_types:
b
unsigned long

variable_types:
c
unsigned long

variable_types:
d
unsigned long

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


MMEM

decompiled_code:
// attributes: thunk
unsigned __int64 __fastcall MMEM(__int64 a1, __int64 a2)
{
return SIMPLEMATH(a1, a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(__int64 a1, __int64 a2)
{
return func10(a1, a2);
}

original_code:
void inline MMEM ( struct timespec *ts, struct timespec *te ){
 unsigned int size = 1000000;
 char *mem;
 rdtscb_getticks ( ts );
 mem = malloc ( size * sizeof ( char ) );
 rdtscb_getticks ( te );
 free ( mem );
}

canonical_original_code:
inline void MMEM(struct timespec *ts, struct timespec *te){
 unsigned int size = 1000000;
 char *mem;
 rdtscb_getticks ( ts );
 mem = malloc ( size * sizeof ( char ) );
 rdtscb_getticks ( te );
 free ( mem );
}

variable_types:
size
unsigned int

variable_types:
mem
char *


GMEM

decompiled_code:
// attributes: thunk
unsigned __int64 __fastcall GMEM(__int64 a1, __int64 a2)
{
return SIMPLEMATH(a1, a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func12(__int64 a1, __int64 a2)
{
return func10(a1, a2);
}

original_code:
void inline GMEM ( struct timespec *ts, struct timespec *te ){
 unsigned int size = 1000000000;
 char *mem;
 rdtscb_getticks ( ts );
 mem = malloc ( size * sizeof ( char ) );
 rdtscb_getticks ( te );
 free ( mem );
}

canonical_original_code:
inline void GMEM(struct timespec *ts, struct timespec *te){
 unsigned int size = 1000000000;
 char *mem;
 rdtscb_getticks ( ts );
 mem = malloc ( size * sizeof ( char ) );
 rdtscb_getticks ( te );
 free ( mem );
}


GETTIMEOFDAY

decompiled_code:
unsigned __int64 __fastcall GETTIMEOFDAY(__int64 a1, __int64 a2)
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

rdtscb_getticks(a1);
gettimeofday(&tv, &tz);
return rdtscb_getticks(a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func13(__int64 a1, __int64 a2)
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

func8(a1);
gettimeofday(&tv, &tz);
return func8(a2);
}

original_code:
void inline GETTIMEOFDAY ( struct timespec *ts, struct timespec *te ){
 struct timeval tv;
 struct timezone tz;
 int time;
 rdtscb_getticks ( ts );
 time = gettimeofday ( &tv, &tz );
 rdtscb_getticks ( te );
}

canonical_original_code:
inline void GETTIMEOFDAY(struct timespec *ts, struct timespec *te){
 struct timeval tv;
 struct timezone tz;
 int time;
 rdtscb_getticks ( ts );
 time = gettimeofday ( &tv, &tz );
 rdtscb_getticks ( te );
}

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

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

variable_types: time int


SYSCONF

decompiled_code:
unsigned __int64 __fastcall SYSCONF(__int64 a1, __int64 a2)
{
rdtscb_getticks(a1);
sysconf(0);
return rdtscb_getticks(a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func14(__int64 a1, __int64 a2)
{
func8(a1);
sysconf(0);
return func8(a2);
}

original_code:
void inline SYSCONF ( struct timespec *ts, struct timespec *te ){
 long conf;
 rdtscb_getticks ( ts );
 conf = sysconf(_SC_ARG_MAX);
 rdtscb_getticks ( te );
}

canonical_original_code:
inline void SYSCONF(struct timespec *ts, struct timespec *te){
 long conf;
 rdtscb_getticks ( ts );
 conf = sysconf(_SC_ARG_MAX);
 rdtscb_getticks ( te );
}

variable_types: conf long


PIPES

decompiled_code:
__pid_t __fastcall PIPES(__int64 a1, __int64 a2)
{
__pid_t v2; // eax
int v3; // ebp
size_t v4; // rax
char buf; // [rsp+Fh] [rbp-49h] BYREF
int pipedes[2]; // [rsp+10h] [rbp-48h] BYREF
int v8[2]; // [rsp+18h] [rbp-40h] BYREF
char s[8]; // [rsp+20h] [rbp-38h] BYREF
__int64 v10; // [rsp+28h] [rbp-30h]
char dest[16]; // [rsp+30h] [rbp-28h] BYREF

strcpy(s, "message");
v10 = 0LL;
if ( pipe(pipedes) == -1 || pipe(v8) == -1 )
{
perror("pipe");
exit(1);
}
*(_OWORD *)dest = 0LL;
v2 = fork();
if ( v2 == -1 )
{
perror("fork");
exit(1);
}
if ( !v2 )
{
close(pipedes[1]);
close(v8[0]);
while ( read(pipedes[0], &buf, 1uLL) > 0 )
write(v8[1], &buf, 1uLL);
write(v8[1], "\n", 1uLL);
close(pipedes[0]);
close(v8[1]);
_exit(0);
}
close(pipedes[0]);
close(v8[1]);
v3 = 0;
rdtscb_getticks(a1);
v4 = strlen(s);
write(pipedes[1], s, v4);
close(pipedes[1]);
while ( read(v8[0], &buf, 1uLL) > 0 )
{
++v3;
strncat(dest, &buf, 1uLL);
}
dest[v3 - 1] = 0;
if ( strcmp(s, dest) )
exit(1);
rdtscb_getticks(a2);
close(pipedes[0]);
close(v8[0]);
return wait(0LL);
}

canonical_decompiled_code:
__pid_t __fastcall func15(__int64 a1, __int64 a2)
{
__pid_t v2; // eax
int v3; // ebp
size_t v4; // rax
char buf; // [rsp+Fh] [rbp-49h] BYREF
int pipedes[2]; // [rsp+10h] [rbp-48h] BYREF
int v8[2]; // [rsp+18h] [rbp-40h] BYREF
char s[8]; // [rsp+20h] [rbp-38h] BYREF
__int64 v10; // [rsp+28h] [rbp-30h]
char dest[16]; // [rsp+30h] [rbp-28h] BYREF

strcpy(s, "message");
v10 = 0LL;
if ( pipe(pipedes) == -1 || pipe(v8) == -1 )
{
perror("pipe");
exit(1);
}
*(_OWORD *)dest = 0LL;
v2 = fork();
if ( v2 == -1 )
{
perror("fork");
exit(1);
}
if ( !v2 )
{
close(pipedes[1]);
close(v8[0]);
while ( read(pipedes[0], &buf, 1uLL) > 0 )
write(v8[1], &buf, 1uLL);
write(v8[1], "\n", 1uLL);
close(pipedes[0]);
close(v8[1]);
_exit(0);
}
close(pipedes[0]);
close(v8[1]);
v3 = 0;
func8(a1);
v4 = strlen(s);
write(pipedes[1], s, v4);
close(pipedes[1]);
while ( read(v8[0], &buf, 1uLL) > 0 )
{
++v3;
strncat(dest, &buf, 1uLL);
}
dest[v3 - 1] = 0;
if ( strcmp(s, dest) )
exit(1);
func8(a2);
close(pipedes[0]);
close(v8[0]);
return wait(0LL);
}

original_code:
void inline PIPES ( struct timespec *ts, struct timespec *te ){
 char send[16]="message", recive[16];
 int pipePtoC[2], pipeCtoP[2], i;
 pid_t cpid;
 char buf;
 if ((pipe(pipePtoC) == -1) || (pipe(pipeCtoP) == -1)) {
  perror("pipe");
  exit(1);
 }
 for ( i=0; i < sizeof(recive); i++ )
  recive[i] = '\0';
 cpid = fork();
 if (cpid == -1) {
  perror("fork");
  exit(1);
 }
 if (cpid == 0) {
  close(pipePtoC[1]);
  close(pipeCtoP[0]);
  while (read(pipePtoC[0], &buf, 1) > 0)
   write(pipeCtoP[1], &buf, 1);
  write(pipeCtoP[1], "\n", 1);
  close(pipePtoC[0]);
  close(pipeCtoP[1]);
  _exit(0);
 } else {
  close(pipePtoC[0]);
  close(pipeCtoP[1]);
  rdtscb_getticks ( ts );
  write(pipePtoC[1], send, strlen(send));
  close(pipePtoC[1]);
  i=0;
  while (read(pipeCtoP[0], &buf, 1) > 0){
   strncat(recive, &buf, 1);
   i++;
  }
  recive[(i-1)]='\0';
  if ( strcmp ( send, recive ) != 0 )
   exit (1);
  rdtscb_getticks ( te );
  close(pipePtoC[0]);
  close(pipeCtoP[0]);
  wait(((void *)0));
 }
}

canonical_original_code:
inline void PIPES(struct timespec *ts, struct timespec *te){
 char send[16] = "message"; char recive[16];
 int pipePtoC[2]; int pipeCtoP[2]; int i;
 int cpid;
 char buf;
 if ((pipe(pipePtoC) == -1) || (pipe(pipeCtoP) == -1)) {
  perror("pipe");
  exit(1);
 }
 for ( i=0; i < sizeof(recive); i++ )
  recive[i] = '\0';
 cpid = fork();
 if (cpid == -1) {
  perror("fork");
  exit(1);
 }
 if (cpid == 0) {
  close(pipePtoC[1]);
  close(pipeCtoP[0]);
  while (read(pipePtoC[0], &buf, 1) > 0)
   write(pipeCtoP[1], &buf, 1);
  write(pipeCtoP[1], "\n", 1);
  close(pipePtoC[0]);
  close(pipeCtoP[1]);
  _exit(0);
 } else {
  close(pipePtoC[0]);
  close(pipeCtoP[1]);
  rdtscb_getticks ( ts );
  write(pipePtoC[1], send, strlen(send));
  close(pipePtoC[1]);
  i=0;
  while (read(pipeCtoP[0], &buf, 1) > 0){
   strncat(recive, &buf, 1);
   i++;
  }
  recive[(i-1)]='\0';
  if ( strcmp ( send, recive ) != 0 )
   exit (1);
  rdtscb_getticks ( te );
  close(pipePtoC[0]);
  close(pipeCtoP[0]);
  wait(((void *)0));
 }
}

variable_types:
send
char [16]

variable_types:
recive
char [16]

variable_types:
pipePtoC
int [2]

variable_types:
pipeCtoP
int [2]

variable_types: i int

variable_types: cpid int

variable_types: buf char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // er13

if ( argc <= 2 )
{
printf(
"Error. You need to specify two numbers as arguments.\n"
"\n"
" %s <repeats> <acc repeats> <optional detailed run parameter. Try 1>\n"
"\n",
*argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
rdtscb_measure("sysconf() ", v3, argc != 3, SYSCONF);
sleep(5u);
rdtscb_measure("gettimeofday() ", v3, argc != 3, GETTIMEOFDAY);
sleep(5u);
rdtscb_measure("malloc[1M] ", v3, argc != 3, MMEM);
sleep(5u);
rdtscb_measure("malloc[1G] ", v3, argc != 3, GMEM);
sleep(5u);
rdtscb_measure("2pipes[] ", v3, argc != 3, PIPES);
sleep(5u);
rdtscb_measure("simplemath[] ", v3, argc != 3, SIMPLEMATH);
sleep(5u);
rdtscb_accuracy(v4, argc != 3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // er13

if ( argc <= 2 )
{
printf(
"Error. You need to specify two numbers as arguments.\n"
"\n"
" %s <repeats> <acc repeats> <optional detailed run parameter. Try 1>\n"
"\n",
*argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
func7("sysconf() ", v3, argc != 3, SYSCONF);
sleep(5u);
func7("gettimeofday() ", v3, argc != 3, GETTIMEOFDAY);
sleep(5u);
func7("malloc[1M] ", v3, argc != 3, MMEM);
sleep(5u);
func7("malloc[1G] ", v3, argc != 3, GMEM);
sleep(5u);
func7("2pipes[] ", v3, argc != 3, PIPES);
sleep(5u);
func7("simplemath[] ", v3, argc != 3, SIMPLEMATH);
sleep(5u);
func9(v4, argc != 3);
return 0;
}

original_code:
int main (int argc, char *argv[]){
 struct timespec begin, end;
 int accrepeats, repeats, detailed = 0;
 if ( argc < 3 ){
  printf ("Error. You need to specify two numbers as arguments.\n\n %s <repeats> <acc repeats> <optional detailed run parameter. Try 1>\n\n" , argv[0]);
  exit (1);
 }
 repeats = atoi(argv[1]);
 accrepeats = atoi(argv[2]);
 if ( argc > 3 )
  detailed = 1;
 rdtscb_measure ( "sysconf()      ", repeats, detailed, &SYSCONF );
 sleep(5);
 rdtscb_measure ( "gettimeofday() ", repeats, detailed, &GETTIMEOFDAY );
 sleep(5);
 rdtscb_measure ( "malloc[1M]     ", repeats, detailed, &MMEM );
 sleep(5);
 rdtscb_measure ( "malloc[1G]     ", repeats, detailed, &GMEM );
 sleep(5);
 rdtscb_measure ( "2pipes[]       ", repeats, detailed, &PIPES );
 sleep(5);
 rdtscb_measure ( "simplemath[]   ", repeats, detailed, &SIMPLEMATH );
 sleep(5);
 rdtscb_accuracy (accrepeats, detailed );
}

canonical_original_code:
int main(int argc, char *argv[]){
 struct timespec begin; struct timespec end;
 int accrepeats; int repeats; int detailed = 0;
 if ( argc < 3 ){
  printf ("Error. You need to specify two numbers as arguments.\n\n %s <repeats> <acc repeats> <optional detailed run parameter. Try 1>\n\n" , argv[0]);
  exit (1);
 }
 repeats = atoi(argv[1]);
 accrepeats = atoi(argv[2]);
 if ( argc > 3 )
  detailed = 1;
 rdtscb_measure ( "sysconf()      ", repeats, detailed, &SYSCONF );
 sleep(5);
 rdtscb_measure ( "gettimeofday() ", repeats, detailed, &GETTIMEOFDAY );
 sleep(5);
 rdtscb_measure ( "malloc[1M]     ", repeats, detailed, &MMEM );
 sleep(5);
 rdtscb_measure ( "malloc[1G]     ", repeats, detailed, &GMEM );
 sleep(5);
 rdtscb_measure ( "2pipes[]       ", repeats, detailed, &PIPES );
 sleep(5);
 rdtscb_measure ( "simplemath[]   ", repeats, detailed, &SIMPLEMATH );
 sleep(5);
 rdtscb_accuracy (accrepeats, detailed );
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types: accrepeats int

variable_types: repeats int

variable_types: detailed int


variable_types:
msg
char [32]

variable_types: void (*)(struct timespec { long tv_sec; long tv_nsec; } *ts, struct timespec *te)

variable_types:
acc
long double

variable_types:
power
long double

variable_types:
valuemean
long double


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

variable_types:
a
unsigned int

variable_types:
d
unsigned int


decompiled_code:
unsigned __int64 __fastcall MATRIX1(__int64 a1, __int64 a2)
{
rdtscb_getticks(a1);
memset(&matrix, 0xFFu, 0x1C20uLL);
return rdtscb_getticks(a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(__int64 a1, __int64 a2)
{
func8(a1);
memset(&matrix, 0xFFu, 0x1C20uLL);
return func8(a2);
}

original_code:
void inline MATRIX1 (struct timespec *ts, struct timespec *te){
 int x, y;
 rdtscb_getticks ( ts );
 for (x = 0; x < 60; ++x){
  for (y = 0; y < 30; ++y){
   matrix[x][y] = -1;
  }
 }
 rdtscb_getticks ( te );
}

canonical_original_code:
inline void MATRIX1(struct timespec *ts, struct timespec *te){
 int x; int y;
 rdtscb_getticks ( ts );
 for (x = 0; x < 60; ++x){
  for (y = 0; y < 30; ++y){
   matrix[x][y] = -1;
  }
 }
 rdtscb_getticks ( te );
}

variable_types:
te
struct timespec *

variable_types: x int

variable_types: y int


decompiled_code:
// attributes: thunk
unsigned __int64 __fastcall MATRIX2(__int64 a1, __int64 a2)
{
return MATRIX1(a1, a2);
}

original_code:
void inline MATRIX2 (struct timespec *ts, struct timespec *te){
 register int x,y;
 rdtscb_getticks ( ts );
 for (x = 0; x < 60; ++x){
  for (y = 0; y < 30; ++y){
   matrix[x][y] = -1;
  }
 }
 rdtscb_getticks ( te );
}

canonical_original_code:
inline void MATRIX2(struct timespec *ts, struct timespec *te){
 register int x; register int y;
 rdtscb_getticks ( ts );
 for (x = 0; x < 60; ++x){
  for (y = 0; y < 30; ++y){
   matrix[x][y] = -1;
  }
 }
 rdtscb_getticks ( te );
}


decompiled_code:
unsigned __int64 __fastcall MATRIX3(__int64 a1, __int64 a2)
{
char *v2; // rdx
char *v3; // rax

rdtscb_getticks(a1);
v2 = (char *)&end;
do
{
v3 = v2 - 7200;
do
{
*(_DWORD *)v3 = -1;
v3 += 120;
}
while ( v3 != v2 );
v2 = v3 + 4;
}
while ( v3 != (char *)4225812 );
return rdtscb_getticks(a2);
}

original_code:
void inline MATRIX3 (struct timespec *ts, struct timespec *te){
 register int x,y;
 rdtscb_getticks ( ts );
 for (y = 0; y < 30; ++y){
  for (x = 0; x < 60; ++x){
   matrix[x][y] = -1;
  }
 }
 rdtscb_getticks ( te );
}

canonical_original_code:
inline void MATRIX3(struct timespec *ts, struct timespec *te){
 register int x; register int y;
 rdtscb_getticks ( ts );
 for (y = 0; y < 30; ++y){
  for (x = 0; x < 60; ++x){
   matrix[x][y] = -1;
  }
 }
 rdtscb_getticks ( te );
}


decompiled_code:
unsigned __int64 __fastcall MATRIX4(__int64 a1, __int64 a2)
{
char *v2; // rdx
char *v3; // rax

rdtscb_getticks(a1);
v2 = (char *)&matrix;
do
{
v3 = v2 - 7680;
do
{
*(_DWORD *)v3 = -1;
v3 += 128;
}
while ( v3 != v2 );
v2 = v3 + 4;
}
while ( v3 != (char *)&unk_405EFC );
return rdtscb_getticks(a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func13(__int64 a1, __int64 a2)
{
char *v2; // rdx
char *v3; // rax

func8(a1);
v2 = (char *)&matrix;
do
{
v3 = v2 - 7680;
do
{
*(_DWORD *)v3 = -1;
v3 += 128;
}
while ( v3 != v2 );
v2 = v3 + 4;
}
while ( v3 != (char *)&unk_405EFC );
return func8(a2);
}

original_code:
void inline MATRIX4 (struct timespec *ts, struct timespec *te){
 register int x,y;
 rdtscb_getticks ( ts );
 for (y = 0; y < 32; ++y){
  for (x = 0; x < 60; ++x){
   matrix_a[x][y] = -1;
  }
 }
 rdtscb_getticks ( te );
}

canonical_original_code:
inline void MATRIX4(struct timespec *ts, struct timespec *te){
 register int x; register int y;
 rdtscb_getticks ( ts );
 for (y = 0; y < 32; ++y){
  for (x = 0; x < 60; ++x){
   matrix_a[x][y] = -1;
  }
 }
 rdtscb_getticks ( te );
}


decompiled_code:
unsigned __int64 __fastcall MATRIX5(__int64 a1, __int64 a2)
{
rdtscb_getticks(a1);
memset(&matrix, 0xFFu, 0x1C20uLL);
return rdtscb_getticks(a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func14(__int64 a1, __int64 a2)
{
func8(a1);
memset(&matrix, 0xFFu, 0x1C20uLL);
return func8(a2);
}

original_code:
void inline MATRIX5 (struct timespec *ts, struct timespec *te){
 register int index;
 register int *matrix_ptr;
 rdtscb_getticks ( ts );
 matrix_ptr = &matrix[0][0];
 for (index = 0; index < 60 * 30; ++index){
  *matrix_ptr = -1;
  matrix_ptr++;
 }
 rdtscb_getticks ( te );
}

canonical_original_code:
inline void MATRIX5(struct timespec *ts, struct timespec *te){
 register int index;
 register int *matrix_ptr;
 rdtscb_getticks ( ts );
 matrix_ptr = &matrix[0][0];
 for (index = 0; index < 60 * 30; ++index){
  *matrix_ptr = -1;
  matrix_ptr++;
 }
 rdtscb_getticks ( te );
}

variable_types: index int


decompiled_code:
unsigned __int64 __fastcall MATRIX6(__int64 a1, __int64 a2)
{
rdtscb_getticks(a1);
memset(&matrix, 0xFFu, 0x1C20uLL);
return rdtscb_getticks(a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func15(__int64 a1, __int64 a2)
{
func8(a1);
memset(&matrix, 0xFFu, 0x1C20uLL);
return func8(a2);
}

original_code:
void inline MATRIX6 (struct timespec *ts, struct timespec *te){
 register int *matrix_ptr;
 rdtscb_getticks ( ts );
 for (matrix_ptr = &matrix[0][0];
  matrix_ptr <= &matrix[60 - 1][30 - 1];
  ++matrix_ptr){
  *matrix_ptr = -1;
 }
 rdtscb_getticks ( te );
}

canonical_original_code:
inline void MATRIX6(struct timespec *ts, struct timespec *te){
 register int *matrix_ptr;
 rdtscb_getticks ( ts );
 for (matrix_ptr = &matrix[0][0];
  matrix_ptr <= &matrix[60 - 1][30 - 1];
  ++matrix_ptr){
  *matrix_ptr = -1;
 }
 rdtscb_getticks ( te );
}


decompiled_code:
unsigned __int64 __fastcall MATRIX8(__int64 a1, __int64 a2)
{
rdtscb_getticks(a1);
memset(&matrix, 0xFFu, 0x1C20uLL);
return rdtscb_getticks(a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func16(__int64 a1, __int64 a2)
{
func8(a1);
memset(&matrix, 0xFFu, 0x1C20uLL);
return func8(a2);
}

original_code:
void inline MATRIX8 (struct timespec *ts, struct timespec *te){
 register int *matrix_ptr;
 rdtscb_getticks ( ts );
 memset (matrix, -1, sizeof(matrix));;
 rdtscb_getticks ( te );
}

canonical_original_code:
inline void MATRIX8(struct timespec *ts, struct timespec *te){
 register int *matrix_ptr;
 rdtscb_getticks ( ts );
 memset (matrix, -1, sizeof(matrix));;
 rdtscb_getticks ( te );
}


initmatrix

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

result = -1LL;
memset(&matrix, 0xFFu, 0x1C20uLL);
return result;
}

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

result = -1LL;
memset(&matrix, 0xFFu, 0x1C20uLL);
return result;
}

original_code:
void initmatrix(){
 memset (matrix, -1, sizeof(matrix));
}


decompiled_code:
unsigned __int64 __fastcall MATRIX7(__int64 a1, __int64 a2)
{
rdtscb_getticks(a1);
initmatrix();
return rdtscb_getticks(a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func18(__int64 a1, __int64 a2)
{
func8(a1);
func17();
return func8(a2);
}

original_code:
void inline MATRIX7 (struct timespec *ts, struct timespec *te){
 register int *matrix_ptr;
 rdtscb_getticks ( ts );
 initmatrix();
 rdtscb_getticks ( te );
}

canonical_original_code:
inline void MATRIX7(struct timespec *ts, struct timespec *te){
 register int *matrix_ptr;
 rdtscb_getticks ( ts );
 initmatrix();
 rdtscb_getticks ( te );
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // er13

if ( argc <= 2 )
{
printf(
"Error. You need to specify two numbers as arguments.\n"
"\n"
" %s <repeats> <acc repeats> <optional detailed run parameter. Try 1>\n"
"\n",
*argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
rdtscb_measure("matrix1() ", v3, argc != 3, MATRIX1);
sleep(5u);
rdtscb_measure("matrix2() ", v3, argc != 3, MATRIX2);
sleep(5u);
rdtscb_measure("matrix3() ", v3, argc != 3, MATRIX3);
sleep(5u);
rdtscb_measure("matrix4() ", v3, argc != 3, MATRIX4);
sleep(5u);
rdtscb_measure("matrix5() ", v3, argc != 3, MATRIX5);
sleep(5u);
rdtscb_measure("matrix6() ", v3, argc != 3, MATRIX6);
sleep(5u);
rdtscb_measure("matrix7() ", v3, argc != 3, MATRIX7);
sleep(5u);
rdtscb_measure("matrix8() ", v3, argc != 3, MATRIX8);
sleep(5u);
rdtscb_accuracy(v4, argc != 3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // er13

if ( argc <= 2 )
{
printf(
"Error. You need to specify two numbers as arguments.\n"
"\n"
" %s <repeats> <acc repeats> <optional detailed run parameter. Try 1>\n"
"\n",
*argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
func7("matrix1() ", v3, argc != 3, MATRIX1);
sleep(5u);
func7("matrix2() ", v3, argc != 3, MATRIX2);
sleep(5u);
func7("matrix3() ", v3, argc != 3, MATRIX3);
sleep(5u);
func7("matrix4() ", v3, argc != 3, MATRIX4);
sleep(5u);
func7("matrix5() ", v3, argc != 3, MATRIX5);
sleep(5u);
func7("matrix6() ", v3, argc != 3, MATRIX6);
sleep(5u);
func7("matrix7() ", v3, argc != 3, MATRIX7);
sleep(5u);
func7("matrix8() ", v3, argc != 3, MATRIX8);
sleep(5u);
func9(v4, argc != 3);
return 0;
}

original_code:
int main (int argc, char *argv[]){
 struct timespec begin, end;
 int accrepeats, repeats, detailed = 0;
 if ( argc < 3 ){
  printf ("Error. You need to specify two numbers as arguments.\n\n %s <repeats> <acc repeats> <optional detailed run parameter. Try 1>\n\n" , argv[0]);
  exit (1);
 }
 repeats = atoi(argv[1]);
 accrepeats = atoi(argv[2]);
 if ( argc > 3 )
  detailed = 1;
 rdtscb_measure ( "matrix1()       ", repeats, detailed, &MATRIX1 );
 sleep(5);
 rdtscb_measure ( "matrix2()       ", repeats, detailed, &MATRIX2 );
 sleep(5);
 rdtscb_measure ( "matrix3()       ", repeats, detailed, &MATRIX3 );
 sleep(5);
 rdtscb_measure ( "matrix4()       ", repeats, detailed, &MATRIX4 );
 sleep(5);
 rdtscb_measure ( "matrix5()       ", repeats, detailed, &MATRIX5 );
 sleep(5);
 rdtscb_measure ( "matrix6()       ", repeats, detailed, &MATRIX6 );
 sleep(5);
 rdtscb_measure ( "matrix7()       ", repeats, detailed, &MATRIX7 );
 sleep(5);
 rdtscb_measure ( "matrix8()       ", repeats, detailed, &MATRIX8 );
 sleep(5);
 rdtscb_accuracy (accrepeats, detailed );
}

canonical_original_code:
int main(int argc, char *argv[]){
 struct timespec begin; struct timespec end;
 int accrepeats; int repeats; int detailed = 0;
 if ( argc < 3 ){
  printf ("Error. You need to specify two numbers as arguments.\n\n %s <repeats> <acc repeats> <optional detailed run parameter. Try 1>\n\n" , argv[0]);
  exit (1);
 }
 repeats = atoi(argv[1]);
 accrepeats = atoi(argv[2]);
 if ( argc > 3 )
  detailed = 1;
 rdtscb_measure ( "matrix1()       ", repeats, detailed, &MATRIX1 );
 sleep(5);
 rdtscb_measure ( "matrix2()       ", repeats, detailed, &MATRIX2 );
 sleep(5);
 rdtscb_measure ( "matrix3()       ", repeats, detailed, &MATRIX3 );
 sleep(5);
 rdtscb_measure ( "matrix4()       ", repeats, detailed, &MATRIX4 );
 sleep(5);
 rdtscb_measure ( "matrix5()       ", repeats, detailed, &MATRIX5 );
 sleep(5);
 rdtscb_measure ( "matrix6()       ", repeats, detailed, &MATRIX6 );
 sleep(5);
 rdtscb_measure ( "matrix7()       ", repeats, detailed, &MATRIX7 );
 sleep(5);
 rdtscb_measure ( "matrix8()       ", repeats, detailed, &MATRIX8 );
 sleep(5);
 rdtscb_accuracy (accrepeats, detailed );
}

variable_types: argc int

variable_types:
argv
char *[]


GETPID

decompiled_code:
unsigned __int64 __fastcall GETPID(__int64 a1, __int64 a2)
{
rdtscb_getticks(a1);
getpid();
return rdtscb_getticks(a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(__int64 a1, __int64 a2)
{
func8(a1);
getpid();
return func8(a2);
}

original_code:
void inline GETPID ( struct timespec *ts, struct timespec *te ){
 pid_t pid;
 rdtscb_getticks ( ts );
 pid = getpid();
 rdtscb_getticks ( te );
}

canonical_original_code:
inline void GETPID(struct timespec *ts, struct timespec *te){
 int pid;
 rdtscb_getticks ( ts );
 pid = getpid();
 rdtscb_getticks ( te );
}

variable_types: pid int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // ebp

if ( argc <= 2 )
{
printf(
"Error. You need to specify two numbers as arguments.\n"
"\n"
" %s <repeats> <acc repeats> <optional detailed run parameter. Try 1>\n"
"\n",
*argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
rdtscb_measure("getpid() ", v3, argc != 3, GETPID);
sleep(5u);
rdtscb_accuracy(v4, argc != 3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // ebp

if ( argc <= 2 )
{
printf(
"Error. You need to specify two numbers as arguments.\n"
"\n"
" %s <repeats> <acc repeats> <optional detailed run parameter. Try 1>\n"
"\n",
*argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
func7("getpid() ", v3, argc != 3, GETPID);
sleep(5u);
func9(v4, argc != 3);
return 0;
}

original_code:
int main (int argc, char *argv[]){
 struct timespec begin, end;
 int accrepeats, repeats, detailed = 0;
 if ( argc < 3 ){
  printf ("Error. You need to specify two numbers as arguments.\n\n %s <repeats> <acc repeats> <optional detailed run parameter. Try 1>\n\n" , argv[0]);
  exit (1);
 }
 repeats = atoi(argv[1]);
 accrepeats = atoi(argv[2]);
 if ( argc > 3 )
  detailed = 1;
 rdtscb_measure ( "getpid()       ", repeats, detailed, &GETPID );
 sleep(5);
 rdtscb_accuracy (accrepeats, detailed);
}

canonical_original_code:
int main(int argc, char *argv[]){
 struct timespec begin; struct timespec end;
 int accrepeats; int repeats; int detailed = 0;
 if ( argc < 3 ){
  printf ("Error. You need to specify two numbers as arguments.\n\n %s <repeats> <acc repeats> <optional detailed run parameter. Try 1>\n\n" , argv[0]);
  exit (1);
 }
 repeats = atoi(argv[1]);
 accrepeats = atoi(argv[2]);
 if ( argc > 3 )
  detailed = 1;
 rdtscb_measure ( "getpid()       ", repeats, detailed, &GETPID );
 sleep(5);
 rdtscb_accuracy (accrepeats, detailed);
}

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

variable_types: accrepeats int

variable_types: repeats int


repo: pevargas/netsys

decompiled_code:
__int64 __fastcall init_net_lib(unsigned int a1, double a2)
{
double v2; // xmm0_8
__int64 result; // rax

if ( a2 < 0.0 || a2 > 1.0 )
{
printf("%f : Error in setting packet lost probability!\n", a2);
exit(0);
}
srand(a1);
v2 = a2 * 1000.0;
result = (unsigned int)(int)v2;
p_threshold = (int)v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, double a2)
{
double v2; // xmm0_8
__int64 result; // rax

if ( a2 < 0.0 || a2 > 1.0 )
{
printf("%f : Error in setting packet lost probability!\n", a2);
exit(0);
}
srand(a1);
v2 = a2 * 1000.0;
result = (unsigned int)(int)v2;
p_threshold = (int)v2;
return result;
}

original_code:
void init_net_lib(double f1, unsigned int seed)
{
 if ((f1 < 0) || (f1 > 1)) {
  printf("%f : Error in setting packet lost probability!\n",f1);
  exit(0);
 }
 else {
  srand(seed);
  p_threshold = (int)(f1 * 1000);
 }
}

variable_types:
seed
unsigned int


decompiled_code:
__int64 __fastcall sendto_(int fd, void *buf, unsigned int a3, int a4, const struct sockaddr *a5, socklen_t a6)
{
if ( p_threshold < (int)((double)rand() / 2147483647.0 * 1000.0) )
a3 = sendto(fd, buf, (int)a3, a4, a5, a6);
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, void *buf, unsigned int a3, int a4, const struct sockaddr *a5, socklen_t a6)
{
if ( p_threshold < (int)((double)rand() / 2147483647.0 * 1000.0) )
a3 = sendto(fd, buf, (int)a3, a4, a5, a6);
return a3;
}

original_code:
int sendto_(int i1, void* c1, int i2, int i3, struct sockaddr* sa, int i4)
{
 int rnd;
 double rnd_max = (double)2147483647;
 rnd = ((rand() / rnd_max) * 1000);
 if (rnd > p_threshold) {
  return sendto(i1, c1, i2, i3, sa, i4);
 }
 return i2;
}

canonical_original_code:
int sendto_(int i1, void *c1, int i2, int i3, struct sockaddr *sa, int i4)
{
 int rnd;
 double rnd_max = (double)2147483647;
 rnd = ((rand() / rnd_max) * 1000);
 if (rnd > p_threshold) {
  return sendto(i1, c1, i2, i3, sa, i4);
 }
 return i2;
}

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

variable_types: rnd int


isQuit

decompiled_code:
_BOOL8 __fastcall isQuit(const char *a1)
{
__int64 v1; // rbx
const __int32_t **v2; // rcx
char *v3; // rax

v1 = *a1;
if ( (_BYTE)v1 )
{
v2 = __ctype_tolower_loc();
v3 = (char *)a1;
do
{
*v3++ = (*v2)[v1];
v1 = *v3;
}
while ( (_BYTE)v1 );
}
return strcmp("exit", a1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char *a1)
{
__int64 v1; // rbx
const __int32_t **v2; // rcx
char *v3; // rax

v1 = *a1;
if ( (_BYTE)v1 )
{
v2 = __ctype_tolower_loc();
v3 = (char *)a1;
do
{
*v3++ = (*v2)[v1];
v1 = *v3;
}
while ( (_BYTE)v1 );
}
return strcmp("exit", a1) == 0;
}

original_code:
int isQuit ( char cmd[ ] ) {
  int i;
  for (i = 0; cmd[i]; ++i ) cmd[i] = tolower( cmd[i] );
  if ( strcmp( "exit", cmd ) == 0 ) return 1;
  return 0;
}

canonical_original_code:
int isQuit(char cmd[]) {
  int i;
  for (i = 0; cmd[i]; ++i ) cmd[i] = tolower( cmd[i] );
  if ( strcmp( "exit", cmd ) == 0 ) return 1;
  return 0;
}

variable_types:
cmd
char []

variable_types: i int


main

repo: pflanze/dev-c-with-gc

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi
__int64 v4; // rbx
__int64 v5; // rbp
const char *v6; // rdi
void (__fastcall **v7)(__int64, __int64, _QWORD, __int64); // rax
__int64 v9; // rbp
int v10; // eax
const char *v11; // rdx

if ( argc == 2 )
{
v9 = atol(argv[1]);
v10 = evenp_proc(zerop_flat, v9);
v11 = "yes";
if ( !v10 )
v11 = "no";
printf("is number %ld even?: %s\n", v9, v11);
}
else
{
v3 = argc - 1;
if ( v3 < 0 )
{
v5 = 0LL;
}
else
{
v4 = v3;
v5 = 0LL;
do
{
v6 = argv[v4--];
v5 = cons(v6, v5, envp);
}
while ( (int)v4 >= 0 );
}
v7 = (void (__fastcall **)(__int64, __int64, _QWORD, __int64))make_printlis_proc(&_GNU_EH_FRAME_HDR, "argv");
(*v7)((__int64)(v7 + 1), v5, 0LL, v5);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi
__int64 v4; // rbx
__int64 v5; // rbp
const char *v6; // rdi
void (__fastcall **v7)(__int64, __int64, _QWORD, __int64); // rax
__int64 v9; // rbp
int v10; // eax
const char *v11; // rdx

if ( argc == 2 )
{
v9 = atol(argv[1]);
v10 = func8(zerop_flat, v9);
v11 = "yes";
if ( !v10 )
v11 = "no";
printf("is number %ld even?: %s\n", v9, v11);
}
else
{
v3 = argc - 1;
if ( v3 < 0 )
{
v5 = 0LL;
}
else
{
v4 = v3;
v5 = 0LL;
do
{
v6 = argv[v4--];
v5 = cons(v6, v5, envp);
}
while ( (int)v4 >= 0 );
}
v7 = (void (__fastcall **)(__int64, __int64, _QWORD, __int64))make_printlis_proc(&_GNU_EH_FRAME_HDR, "argv");
(*v7)((__int64)(v7 + 1), v5, 0LL, v5);
}
return 0;
}

original_code:
int main (int argc, char** argv) {
    if (argc==2) {
 long v= atol(argv[1]);
 printf("is number %ld even?: %s\n",
        v,
        (evenp->proc(&(evenp->env), v) ? "yes" : "no"));
    } else {
 pair_t* lis=((void *)0);
 int i;
 for (i=argc-1; i>=0; i--) {
     lis= cons(argv[i], lis);
 }
 struct printlis_closure* myprintlis= make_printlis->proc(&(make_printlis->env), "argv");
 myprintlis->proc(&(myprintlis->env), lis, 0, lis);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    if (argc==2) {
 long v = atol(argv[1]);
 printf("is number %ld even?: %s\n",
        v,
        (evenp->proc(&(evenp->env), v) ? "yes" : "no"));
    } else {
 struct pair *lis = ((void *)0);
 int i;
 for (i=argc-1; i>=0; i--) {
     lis= cons(argv[i], lis);
 }
 struct printlis_closure *myprintlis = make_printlis->proc(&(make_printlis->env), "argv");
 myprintlis->proc(&(myprintlis->env), lis, 0, lis);
    }
    return 0;
}

variable_types:
argv
char **

variable_types: v long

variable_types:
lis
struct pair { void *car; void *cdr; } *

variable_types: struct printlis_closure { void (*proc)(struct printlis_env { char *prefix; } *env, struct pair { void *car; void *cdr; } *lis, int i, struct pair *origlis); struct printlis_env env; } *

user_defined_types: struct printlis_closure { void (*proc)(struct printlis_env *env, struct pair *lis, int i, struct pair *origlis); struct printlis_env env; }


decompiled_code:
_BOOL8 __fastcall zerop_proc(__int64 a1, __int64 a2)
{
return a2 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, __int64 a2)
{
return a2 == 0;
}

original_code:
static BOOL zerop_proc (const struct zerop_env* env, long n) {
    return (n == 0);
}

canonical_original_code:
static int zerop_proc(struct zerop_env *env, long n) {
    return (n == 0);
}

variable_types:
env
struct zerop_env {  } *

variable_types: n long


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

if ( zerop_proc((__int64)&make_printlis_flat, a2) )
result = 1LL;
else
result = oddp_proc(evenp_flat, a2 - 1);
return result;
}

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

if ( func7((__int64)&make_printlis_flat, a2) )
result = 1LL;
else
result = func9(evenp_flat, a2 - 1);
return result;
}

original_code:
static BOOL evenp_proc (const struct evenp_env* env, long n) {
    if (zerop->proc(&(zerop->env), n)) {
 return 1;
    } else {
 return oddp->proc(&(oddp->env), n-1);
    }
}

canonical_original_code:
static int evenp_proc(struct evenp_env *env, long n) {
    if (zerop->proc(&(zerop->env), n)) {
 return 1;
    } else {
 return oddp->proc(&(oddp->env), n-1);
    }
}

variable_types:
env
struct evenp_env {  } *


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

if ( zerop_proc((__int64)&make_printlis_flat, a2) )
result = 0LL;
else
result = evenp_proc((__int64)zerop_flat, a2 - 1);
return result;
}

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

if ( func7((__int64)&make_printlis_flat, a2) )
result = 0LL;
else
result = func8((__int64)zerop_flat, a2 - 1);
return result;
}

original_code:
static BOOL oddp_proc (const struct oddp_env* env, long n) {
    if (zerop->proc(&(zerop->env), n)) {
 return 0;
    } else {
 return evenp->proc(&(evenp->env), n-1);
    }
}

canonical_original_code:
static int oddp_proc(struct oddp_env *env, long n) {
    if (zerop->proc(&(zerop->env), n)) {
 return 0;
    } else {
 return evenp->proc(&(evenp->env), n-1);
    }
}

variable_types:
env
struct oddp_env {  } *


decompiled_code:
void __fastcall __noreturn printlis_proc(const char **a1, __int64 a2, unsigned int a3, __int64 a4)
{
__int64 v7; // rdx

while ( 1 )
{
for ( ; a2; a2 = *(_QWORD *)(a2 + 8) )
{
v7 = a3++;
printf("%s element %i is value: '%s'\n", *a1, v7, *(const char **)a2);
}
a2 = a4;
}
}

canonical_decompiled_code:
void __fastcall __noreturn func10(const char **a1, __int64 a2, unsigned int a3, __int64 a4)
{
__int64 v7; // rdx

while ( 1 )
{
for ( ; a2; a2 = *(_QWORD *)(a2 + 8) )
{
v7 = a3++;
printf("%s element %i is value: '%s'\n", *a1, v7, *(const char **)a2);
}
a2 = a4;
}
}

original_code:
static void printlis_proc (struct printlis_env* env, pair_t* lis, int i, pair_t* origlis) {
    if (! lis) {
 printlis_proc(env, origlis, i, origlis);
    } else {
 printf("%s element %i is value: '%s'\n",
        env->prefix, i, (char*)(lis->car));
 printlis_proc(env, lis->cdr, i+1, origlis);
    }
}

canonical_original_code:
static void printlis_proc(struct printlis_env *env, struct pair *lis, int i, struct pair *origlis) {
    if (! lis) {
 printlis_proc(env, origlis, i, origlis);
    } else {
 printf("%s element %i is value: '%s'\n",
        env->prefix, i, (char *)(lis->car));
 printlis_proc(env, lis->cdr, i+1, origlis);
    }
}

variable_types:
env
struct printlis_env { char *prefix; } *

variable_types:
origlis
struct pair *

user_defined_types:
struct printlis_env { char *prefix; }
struct pair { void *car; void *cdr; }


repo: pfohjo/nitro

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
int v4; // er12
int v5; // eax
int v6; // ebp
void *v7; // r13
__int64 v8; // r14
int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
int v12; // ebx
unsigned int v13; // eax
__int64 v15; // [rsp+8h] [rbp-2A0h] BYREF
__int64 v16; // [rsp+14h] [rbp-294h] BYREF
int v17; // [rsp+1Ch] [rbp-28Ch]
struct stat v18; // [rsp+20h] [rbp-288h] BYREF
__int64 v19[18]; // [rsp+B0h] [rbp-1F8h] BYREF
char v20[240]; // [rsp+140h] [rbp-168h] BYREF
__int64 v21; // [rsp+230h] [rbp-78h]

go = 1;
signal(2, sig_handler);
if ( argc <= 2 )
{
v4 = -1;
puts("Usage: [qemu pid] [guest ram filename]");
}
else
{
v3 = (char *)argv[2];
puts("Mapping Guest Memory...");
v4 = stat(v3, &v18);
if ( v4 == -1 )
{
perror("stat");
}
else
{
v5 = open(v3, 2);
v6 = v5;
if ( v5 == -1 )
{
v4 = -1;
perror("open");
}
else
{
v7 = mmap(0LL, v18.st_size, 3, 1, v5, 0LL);
if ( v7 == (void *)-1LL )
{
v4 = -1;
perror("mmap");
close(v6);
}
else
{
puts("Initializing KVM...");
v4 = init_kvm();
if ( v4 )
{
v4 = -1;
puts("Unable to initialize kvm, exiting.");
}
else
{
puts("Initialized\n");
v8 = (unsigned int)atoi(argv[1]);
printf("calling attach_vm() with creator pid: %d...\n", v8);
v9 = attach_vm((unsigned int)v8);
if ( v9 < 0 )
{
v4 = -1;
puts("Error attaching to VM, exiting");
}
else
{
printf("attach_vm() returned %d\n\n", (unsigned int)v9);
puts("calling attach_vcpus()...");
v10 = attach_vcpus();
printf("attach_vcpus() returned %d\n\n", v10);
puts("calling set_syscall_trap()...");
v16 = 0x4A0000009FLL;
v17 = 170;
v11 = set_syscall_trap(&v16, 3LL);
printf("set_syscall_trap() returned %d\n\n", v11);
if ( go )
{
while ( 1 )
{
v12 = get_event(0LL, &v15);
if ( (unsigned int)get_regs(0LL, v19) )
{
puts("Error getting regs, exiting");
continue_vm(0LL);
goto LABEL_17;
}
if ( (unsigned int)get_sregs(0LL, v20) )
break;
if ( v12 == 2 )
{
printf("Syscall trapped key: 0x%lX cr3: 0x%llX rax: 0x%llX\n", v15, v21, v19[0]);
}
else if ( v12 == 3 )
{
printf("Sysret trapped key: 0x%lX cr3: 0x%llX\n", v15, v21);
}
continue_vm(0LL);
if ( !go )
goto LABEL_17;
}
puts("Error getting sregs, exiting");
continue_vm(0LL);
}
LABEL_17:
puts("calling unset_syscall_trap()...");
v13 = unset_syscall_trap();
printf("unset_syscall_trap() returned %d\n\n", v13);
close_kvm();
munmap(v7, v18.st_size);
close(v6);
}
}
}
}
}
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
int v4; // er12
int v5; // eax
int v6; // ebp
void *v7; // r13
__int64 v8; // r14
int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
int v12; // ebx
unsigned int v13; // eax
__int64 v15; // [rsp+8h] [rbp-2A0h] BYREF
__int64 v16; // [rsp+14h] [rbp-294h] BYREF
int v17; // [rsp+1Ch] [rbp-28Ch]
struct stat v18; // [rsp+20h] [rbp-288h] BYREF
__int64 v19[18]; // [rsp+B0h] [rbp-1F8h] BYREF
char v20[240]; // [rsp+140h] [rbp-168h] BYREF
__int64 v21; // [rsp+230h] [rbp-78h]

go = 1;
signal(2, sig_handler);
if ( argc <= 2 )
{
v4 = -1;
puts("Usage: [qemu pid] [guest ram filename]");
}
else
{
v3 = (char *)argv[2];
puts("Mapping Guest Memory...");
v4 = func24(v3, &v18);
if ( v4 == -1 )
{
perror("stat");
}
else
{
v5 = open(v3, 2);
v6 = v5;
if ( v5 == -1 )
{
v4 = -1;
perror("open");
}
else
{
v7 = mmap(0LL, v18.st_size, 3, 1, v5, 0LL);
if ( v7 == (void *)-1LL )
{
v4 = -1;
perror("mmap");
close(v6);
}
else
{
puts("Initializing KVM...");
v4 = func11();
if ( v4 )
{
v4 = -1;
puts("Unable to initialize kvm, exiting.");
}
else
{
puts("Initialized\n");
v8 = (unsigned int)atoi(argv[1]);
printf("calling attach_vm() with creator pid: %d...\n", v8);
v9 = func14((unsigned int)v8);
if ( v9 < 0 )
{
v4 = -1;
puts("Error attaching to VM, exiting");
}
else
{
printf("attach_vm() returned %d\n\n", (unsigned int)v9);
puts("calling attach_vcpus()...");
v10 = func15();
printf("attach_vcpus() returned %d\n\n", v10);
puts("calling set_syscall_trap()...");
v16 = 0x4A0000009FLL;
v17 = 170;
v11 = func16(&v16, 3LL);
printf("set_syscall_trap() returned %d\n\n", v11);
if ( go )
{
while ( 1 )
{
v12 = func20(0LL, &v15);
if ( (unsigned int)func18(0LL, v19) )
{
puts("Error getting regs, exiting");
func21(0LL);
goto LABEL_17;
}
if ( (unsigned int)func19(0LL, v20) )
break;
if ( v12 == 2 )
{
printf("Syscall trapped key: 0x%lX cr3: 0x%llX rax: 0x%llX\n", v15, v21, v19[0]);
}
else if ( v12 == 3 )
{
printf("Sysret trapped key: 0x%lX cr3: 0x%llX\n", v15, v21);
}
func21(0LL);
if ( !go )
goto LABEL_17;
}
puts("Error getting sregs, exiting");
func21(0LL);
}
LABEL_17:
puts("calling unset_syscall_trap()...");
v13 = func17();
printf("unset_syscall_trap() returned %d\n\n", v13);
func12();
munmap(v7, v18.st_size);
close(v6);
}
}
}
}
}
}
return v4;
}

original_code:
int main(int argc, char **argv){
  int ram_fd;
  char *ram, *ram_filename;
  struct stat ram_fs;
  int num_vcpus;
  pid_t creator;
  int vmfd;
  int rv;
  int sc[3];
  struct kvm_regs regs;
  struct kvm_sregs sregs;
  union event_data event_data;
  go = 1;
  signal(2, sig_handler);
  if (argc < 3){
    printf("Usage: [qemu pid] [guest ram filename]\n");
    return -1;
  }
  ram_filename = argv[2];
  printf("Mapping Guest Memory...\n");
  if (stat(ram_filename, &ram_fs) == -1){
    perror("stat");
    return -1;
  }
  if ((ram_fd = open(ram_filename,02)) == -1){
    perror("open");
    return -1;
  }
  if((ram = mmap(((void *)0), ram_fs.st_size, (0x1 | 0x2), 0x01, ram_fd, 0)) == (void*)-1){
    perror("mmap");
    close(ram_fd);
    return -1;
  }
  printf("Initializing KVM...\n");
  if(init_kvm()){
    printf("Unable to initialize kvm, exiting.\n");
    return -1;
  }
  printf("Initialized\n\n");
  creator = (pid_t)atoi(argv[1]);
  printf("calling attach_vm() with creator pid: %d...\n",creator);
  vmfd = attach_vm(creator);
  if(vmfd < 0){
    printf("Error attaching to VM, exiting\n");
    return -1;
  }
  printf("attach_vm() returned %d\n\n",vmfd);
  printf("calling attach_vcpus()...\n");
  num_vcpus = attach_vcpus();
  printf("attach_vcpus() returned %d\n\n",num_vcpus);
  printf("calling set_syscall_trap()...\n");
  sc[0] = 0x9f;
  sc[1] = 0x4a;
  sc[2] = 0xaa;
  rv = set_syscall_trap(sc,3);
  printf("set_syscall_trap() returned %d\n\n",rv);
  while(go){
    rv = get_event(0,&event_data);
    if(get_regs(0,&regs)){
      printf("Error getting regs, exiting\n");
      continue_vm(0);
      break;
    }
    if(get_sregs(0,&sregs)){
      printf("Error getting sregs, exiting\n");
      continue_vm(0);
      break;
    }
    if(rv == 2)
      printf("Syscall trapped key: 0x%lX cr3: 0x%llX rax: 0x%llX\n",event_data.syscall,sregs.cr3,regs.rax);
    else if(rv == 3)
      printf("Sysret trapped key: 0x%lX cr3: 0x%llX\n",event_data.syscall,sregs.cr3);
    rv = continue_vm(0);
  }
  printf("calling unset_syscall_trap()...\n");
  rv = unset_syscall_trap();
  printf("unset_syscall_trap() returned %d\n\n",rv);
  close_kvm();
  munmap(ram,ram_fs.st_size);
  close(ram_fd);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  int ram_fd;
  char *ram; char *ram_filename;
  struct stat ram_fs;
  int num_vcpus;
  int creator;
  int vmfd;
  int rv;
  int sc[3];
  struct kvm_regs regs;
  struct kvm_sregs sregs;
  union event_data event_data;
  go = 1;
  signal(2, sig_handler);
  if (argc < 3){
    printf("Usage: [qemu pid] [guest ram filename]\n");
    return -1;
  }
  ram_filename = argv[2];
  printf("Mapping Guest Memory...\n");
  if (stat(ram_filename, &ram_fs) == -1){
    perror("stat");
    return -1;
  }
  if ((ram_fd = open(ram_filename,02)) == -1){
    perror("open");
    return -1;
  }
  if((ram = mmap(((void *)0), ram_fs.st_size, (0x1 | 0x2), 0x01, ram_fd, 0)) == (void *)-1){
    perror("mmap");
    close(ram_fd);
    return -1;
  }
  printf("Initializing KVM...\n");
  if(init_kvm()){
    printf("Unable to initialize kvm, exiting.\n");
    return -1;
  }
  printf("Initialized\n\n");
  creator = (int)atoi(argv[1]);
  printf("calling attach_vm() with creator pid: %d...\n",creator);
  vmfd = attach_vm(creator);
  if(vmfd < 0){
    printf("Error attaching to VM, exiting\n");
    return -1;
  }
  printf("attach_vm() returned %d\n\n",vmfd);
  printf("calling attach_vcpus()...\n");
  num_vcpus = attach_vcpus();
  printf("attach_vcpus() returned %d\n\n",num_vcpus);
  printf("calling set_syscall_trap()...\n");
  sc[0] = 0x9f;
  sc[1] = 0x4a;
  sc[2] = 0xaa;
  rv = set_syscall_trap(sc,3);
  printf("set_syscall_trap() returned %d\n\n",rv);
  while(go){
    rv = get_event(0,&event_data);
    if(get_regs(0,&regs)){
      printf("Error getting regs, exiting\n");
      continue_vm(0);
      break;
    }
    if(get_sregs(0,&sregs)){
      printf("Error getting sregs, exiting\n");
      continue_vm(0);
      break;
    }
    if(rv == 2)
      printf("Syscall trapped key: 0x%lX cr3: 0x%llX rax: 0x%llX\n",event_data.syscall,sregs.cr3,regs.rax);
    else if(rv == 3)
      printf("Sysret trapped key: 0x%lX cr3: 0x%llX\n",event_data.syscall,sregs.cr3);
    rv = continue_vm(0);
  }
  printf("calling unset_syscall_trap()...\n");
  rv = unset_syscall_trap();
  printf("unset_syscall_trap() returned %d\n\n",rv);
  close_kvm();
  munmap(ram,ram_fs.st_size);
  close(ram_fd);
  return 0;
}

variable_types: argc int

variable_types:
ram
char *

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

variable_types: creator int

variable_types: vmfd int

variable_types: rv int

variable_types:
sc
int [3]

variable_types: struct kvm_regs { unsigned long long rax; unsigned long long rsi; unsigned long long r8; unsigned long long r12; unsigned long long rip; }

variable_types: struct kvm_sregs { struct kvm_segment { unsigned long long base; unsigned int limit; unsigned short selector; unsigned char type; unsigned char present; unsigned char unusable; unsigned char padding; } cs; struct kvm_segment tr; struct kvm_dtable { unsigned long long base; unsigned short limit; unsigned short padding[3]; } gdt; unsigned long long cr0; unsigned long long efer; unsigned long long apic_base; unsigned long long interrupt_bitmap[-1]; }

variable_types: union event_data { unsigned long syscall; }

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

user_defined_types: struct kvm_sregs { struct kvm_segment cs; struct kvm_segment tr; struct kvm_dtable gdt; unsigned long long cr0; unsigned long long efer; unsigned long long apic_base; unsigned long long interrupt_bitmap[-1]; }


decompiled_code:
void sig_handler()
{
go = 0;
}

canonical_decompiled_code:
void func7()
{
go = 0;
}

original_code:
void sig_handler(int signum){
  go = 0;
}

canonical_original_code:
void sig_handler(int signum){
  go = 0;
}

variable_types: signum int


decompiled_code:
__int64 init_kvm()
{
int v0; // eax
__int64 result; // rax

kvm_vmfd = 0;
memset(&vcpus, 0, 0x200uLL);
*(&vcpus + 128) = 0;
v0 = open("/dev/kvm", 2);
if ( v0 < 0 )
{
kvm_fd = 0;
result = (unsigned int)-*__errno_location();
}
else
{
kvm_fd = v0;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // eax
__int64 result; // rax

kvm_vmfd = 0;
memset(&vcpus, 0, 0x200uLL);
*(&vcpus + 128) = 0;
v0 = open("/dev/kvm", 2);
if ( v0 < 0 )
{
kvm_fd = 0;
result = (unsigned int)-*__errno_location();
}
else
{
kvm_fd = v0;
result = 0LL;
}
return result;
}

original_code:
int init_kvm(){
  kvm_vmfd = 0;
  memset(&vcpus,0,sizeof(struct nitro_vcpus));
  if((kvm_fd = open("/dev/kvm", 02)) < 0){
    kvm_fd = 0;
    return -(*__errno_location ());
  }
  return 0;
}

user_defined_types: struct nitro_vcpus { int num_vcpus; int ids[64]; int fds[64]; }


decompiled_code:
__int64 close_kvm()
{
__int64 v0; // rbx
int v1; // edi

if ( vcpus > 0 )
{
v0 = 0LL;
do
{
v1 = fd[v0];
if ( v1 > 0 )
close(v1);
++v0;
}
while ( vcpus > (int)v0 );
}
if ( kvm_vmfd > 0 )
close(kvm_vmfd);
close(kvm_fd);
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rbx
int v1; // edi

if ( vcpus > 0 )
{
v0 = 0LL;
do
{
v1 = fd[v0];
if ( v1 > 0 )
close(v1);
++v0;
}
while ( vcpus > (int)v0 );
}
if ( kvm_vmfd > 0 )
close(kvm_vmfd);
close(kvm_fd);
return 0LL;
}

original_code:
int close_kvm(){
  int i;
  for(i=0;i<vcpus.num_vcpus;i++){
    if(vcpus.fds[i]>0)
      close(vcpus.fds[i]);
  }
  if(kvm_vmfd>0){
    close(kvm_vmfd);
  }
  close(kvm_fd);
  return 0;
}

variable_types: i int


decompiled_code:
int __fastcall get_num_vms(__int64 a1, __int64 a2)
{
return kvm_ioctl(44768, a2);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, __int64 a2)
{
return func8(44768, a2);
}


decompiled_code:
int __fastcall attach_vm(int a1)
{
int result; // eax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = a1;
result = kvm_ioctl(1074048737, (__int64)v2);
kvm_vmfd = result;
if ( result > 0 )
result = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func14(int a1)
{
int result; // eax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = a1;
result = func8(1074048737, (__int64)v2);
kvm_vmfd = result;
if ( result > 0 )
result = 0;
return result;
}


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

result = kvm_vm_ioctl(-2113622302, (__int64)&vcpus);
if ( !result )
result = vcpus;
return result;
}

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

result = func9(-2113622302, (__int64)&vcpus);
if ( !result )
result = vcpus;
return result;
}


decompiled_code:
int __fastcall set_syscall_trap(__int64 a1, int a2)
{
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
int v4; // [rsp+8h] [rbp-10h]

v4 = a2;
v3 = a1;
return kvm_vm_ioctl(1074835171, (__int64)&v3);
}

original_code:
int set_syscall_trap(int *sc, int sc_size){
  struct nitro_syscall_trap sct;
  sct.size = sc_size;
  sct.syscalls = sc;
  return kvm_vm_ioctl((((1U) << (((0 +8)+8)+14)) | (((0xAE)) << (0 +8)) | (((0xE3)) << 0) | ((((sizeof(struct nitro_syscall_trap)))) << ((0 +8)+8))),&sct);
}

variable_types:
sc
int *

variable_types: struct nitro_syscall_trap { int *syscalls; int size; }


decompiled_code:
int __fastcall unset_syscall_trap(__int64 a1, __int64 a2)
{
return kvm_vm_ioctl(44772, a2);
}

canonical_decompiled_code:
int __fastcall func17(__int64 a1, __int64 a2)
{
return func9(44772, a2);
}


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

if ( vcpus <= a1 )
result = -1;
else
result = kvm_vcpu_ioctl(fd[a1], -2138001689);
return result;
}

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

if ( vcpus <= a1 )
result = -1;
else
result = func10(fd[a1], -2138001689);
return result;
}

original_code:
int get_regs(int vcpu_id, struct kvm_regs *regs){
  if(vcpu_id >= vcpus.num_vcpus)
    return -1;
  return kvm_vcpu_ioctl(vcpus.fds[vcpu_id],(((2U) << (((0 +8)+8)+14)) | (((0xAE)) << (0 +8)) | (((0xE7)) << 0) | ((((sizeof(struct kvm_regs)))) << ((0 +8)+8))),regs);
}

variable_types: struct kvm_regs { unsigned long long rax; unsigned long long rsi; unsigned long long r8; unsigned long long r12; unsigned long long rip; } *


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

if ( vcpus <= a1 )
result = -1;
else
result = kvm_vcpu_ioctl(fd[a1], -2126991639);
return result;
}

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

if ( vcpus <= a1 )
result = -1;
else
result = func10(fd[a1], -2126991639);
return result;
}

original_code:
int get_sregs(int vcpu_id, struct kvm_sregs *sregs){
  if(vcpu_id >= vcpus.num_vcpus)
    return -1;
  return kvm_vcpu_ioctl(vcpus.fds[vcpu_id],(((2U) << (((0 +8)+8)+14)) | (((0xAE)) << (0 +8)) | (((0xE9)) << 0) | ((((sizeof(struct kvm_sregs)))) << ((0 +8)+8))),sregs);
}

variable_types: struct kvm_sregs { struct kvm_segment { unsigned long long base; unsigned int limit; unsigned short selector; unsigned char type; unsigned char present; unsigned char unusable; unsigned char padding; } cs; struct kvm_segment tr; struct kvm_dtable { unsigned long long base; unsigned short limit; unsigned short padding[3]; } gdt; unsigned long long cr0; unsigned long long efer; unsigned long long apic_base; unsigned long long interrupt_bitmap[-1]; } *


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

if ( vcpus <= a1 )
result = -1;
else
result = kvm_vcpu_ioctl(fd[a1], -2146914587);
return result;
}

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

if ( vcpus <= a1 )
result = -1;
else
result = func10(fd[a1], -2146914587);
return result;
}

original_code:
int get_event(int vcpu_id, union event_data *ed){
  if(vcpu_id >= vcpus.num_vcpus)
    return -1;
  return kvm_vcpu_ioctl(vcpus.fds[vcpu_id],(((2U) << (((0 +8)+8)+14)) | (((0xAE)) << (0 +8)) | (((0xE5)) << 0) | ((((sizeof(union event_data)))) << ((0 +8)+8))),ed);
}

variable_types: union event_data { unsigned long syscall; } *


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

if ( vcpus <= a1 )
result = -1;
else
result = kvm_vcpu_ioctl(fd[a1], 44774);
return result;
}

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

if ( vcpus <= a1 )
result = -1;
else
result = func10(fd[a1], 44774);
return result;
}


SIGhandler

decompiled_code:
void SIGhandler()
{
pthread_mutex_lock(&mutexVarSuspendido);
suspendido = 1;
pthread_mutex_unlock(&mutexVarSuspendido);
puts("\nRecibi la senial USR1.");
}

canonical_decompiled_code:
void func0()
{
pthread_mutex_lock(&mutexVarSuspendido);
suspendido = 1;
pthread_mutex_unlock(&mutexVarSuspendido);
puts("\nRecibi la senial USR1.");
}

original_code:
void SIGhandler(int sig)
{
 pthread_mutex_lock(&mutexVarSuspendido);
 suspendido = 1;
 pthread_mutex_unlock(&mutexVarSuspendido);
 printf("\nRecibi la senial USR1.\n");
}

variable_types: sig int


decompiled_code:
__int64 comprobar_archivo_configuracion()
{
__int64 v0; // rax
char *v1; // r12
char *v2; // rax
const char *v3; // r13
char *v4; // rax
const char *v5; // r13
char *v6; // rax
const char *v7; // r13
char *v8; // rax
const char *v9; // r13
char *v10; // rax
const char *v11; // rbp
char *v12; // rbp
char *v13; // rax
const char *v14; // r13
char *v15; // rax
const char *v16; // r13
char *v17; // rax
char *v18; // r13
char *v20; // rax
char *v21; // r13

v0 = leer_archivo("pp.conf");
if ( v0 )
{
v1 = (char *)v0;
do
{
v12 = strtok(v1, "\n");
v1 = strtok(0LL, byte_106C);
if ( strstr(v12, "mps") )
{
strtok(v12, " ");
v13 = strtok(0LL, ";");
v14 = v13;
if ( v13 )
{
if ( atoi(v13) != max_mps )
{
pthread_mutex_lock(&mutexVarMaxMPS);
max_mps = atoi(v14);
pthread_mutex_unlock(&mutexVarMaxMPS);
}
}
}
if ( strstr(v12, "mmp") )
{
strtok(v12, " ");
v15 = strtok(0LL, ";");
v16 = v15;
if ( v15 )
{
if ( atoi(v15) != max_mmp )
{
pthread_mutex_lock(&mutexVarMaxMMP);
max_mmp = atoi(v16);
pthread_mutex_unlock(&mutexVarMaxMMP);
}
}
}
if ( strstr(v12, "lpl") )
{
strtok(v12, " ");
v17 = strtok(0LL, ";");
v18 = v17;
if ( v17 )
{
if ( strcmp(lpl, v17) )
{
pthread_mutex_lock(&mutexVarLPL);
lpl = v18;
pthread_mutex_unlock(&mutexVarLPL);
}
}
}
if ( strstr(v12, "lpn") )
{
strtok(v12, " ");
v2 = strtok(0LL, ";");
v3 = v2;
if ( v2 )
{
if ( atoi(v2) != lpn )
{
pthread_mutex_lock(&mutexVarLPN);
lpn = atoi(v3);
pthread_mutex_unlock(&mutexVarLPN);
}
}
}
if ( strstr(v12, "lpr") )
{
strtok(v12, " ");
v4 = strtok(0LL, ";");
v5 = v4;
if ( v4 )
{
if ( atoi(v4) != lpr )
{
pthread_mutex_lock(&mutexVarLPR);
lpr = atoi(v5);
pthread_mutex_unlock(&mutexVarLPR);
}
}
}
if ( strstr(v12, "finQ") )
{
strtok(v12, " ");
v6 = strtok(0LL, ";");
v7 = v6;
if ( v6 )
{
if ( atoi(v6) != finQ )
{
pthread_mutex_lock(&mutexVarFinQuantum);
finQ = atoi(v7);
pthread_mutex_unlock(&mutexVarFinQuantum);
}
}
}
if ( strstr(v12, "finIO") )
{
strtok(v12, " ");
v8 = strtok(0LL, ";");
v9 = v8;
if ( v8 )
{
if ( atoi(v8) != finQ )
{
pthread_mutex_lock(&mutexVarFinIO);
finIO = atoi(v9);
pthread_mutex_unlock(&mutexVarFinIO);
}
}
}
if ( strstr(v12, "espera_estandar") )
{
if ( !strstr(v12, "espera_estandar_io") )
{
strtok(v12, " ");
v20 = strtok(0LL, ";");
v21 = v20;
if ( v20 )
{
if ( strcmp(espera_estandar, v20) )
{
pthread_mutex_lock(&mutexVarEsperaEstandar);
espera_estandar = v21;
pthread_mutex_unlock(&mutexVarEsperaEstandar);
}
}
}
}
if ( strstr(v12, "alfa") )
{
strtok(v12, " ");
v10 = strtok(0LL, ";");
v11 = v10;
if ( v10 )
{
if ( atof(v10) != *(double *)&alfa )
{
pthread_mutex_lock(&mutexVarAlfa);
alfa = atof(v11);
pthread_mutex_unlock(&mutexVarAlfa);
}
}
}
}
while ( v1 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
char *v1; // r12
char *v2; // rax
const char *v3; // r13
char *v4; // rax
const char *v5; // r13
char *v6; // rax
const char *v7; // r13
char *v8; // rax
const char *v9; // r13
char *v10; // rax
const char *v11; // rbp
char *v12; // rbp
char *v13; // rax
const char *v14; // r13
char *v15; // rax
const char *v16; // r13
char *v17; // rax
char *v18; // r13
char *v20; // rax
char *v21; // r13

v0 = leer_archivo("pp.conf");
if ( v0 )
{
v1 = (char *)v0;
do
{
v12 = strtok(v1, "\n");
v1 = strtok(0LL, byte_106C);
if ( strstr(v12, "mps") )
{
strtok(v12, " ");
v13 = strtok(0LL, ";");
v14 = v13;
if ( v13 )
{
if ( atoi(v13) != max_mps )
{
pthread_mutex_lock(&mutexVarMaxMPS);
max_mps = atoi(v14);
pthread_mutex_unlock(&mutexVarMaxMPS);
}
}
}
if ( strstr(v12, "mmp") )
{
strtok(v12, " ");
v15 = strtok(0LL, ";");
v16 = v15;
if ( v15 )
{
if ( atoi(v15) != max_mmp )
{
pthread_mutex_lock(&mutexVarMaxMMP);
max_mmp = atoi(v16);
pthread_mutex_unlock(&mutexVarMaxMMP);
}
}
}
if ( strstr(v12, "lpl") )
{
strtok(v12, " ");
v17 = strtok(0LL, ";");
v18 = v17;
if ( v17 )
{
if ( strcmp(lpl, v17) )
{
pthread_mutex_lock(&mutexVarLPL);
lpl = v18;
pthread_mutex_unlock(&mutexVarLPL);
}
}
}
if ( strstr(v12, "lpn") )
{
strtok(v12, " ");
v2 = strtok(0LL, ";");
v3 = v2;
if ( v2 )
{
if ( atoi(v2) != lpn )
{
pthread_mutex_lock(&mutexVarLPN);
lpn = atoi(v3);
pthread_mutex_unlock(&mutexVarLPN);
}
}
}
if ( strstr(v12, "lpr") )
{
strtok(v12, " ");
v4 = strtok(0LL, ";");
v5 = v4;
if ( v4 )
{
if ( atoi(v4) != lpr )
{
pthread_mutex_lock(&mutexVarLPR);
lpr = atoi(v5);
pthread_mutex_unlock(&mutexVarLPR);
}
}
}
if ( strstr(v12, "finQ") )
{
strtok(v12, " ");
v6 = strtok(0LL, ";");
v7 = v6;
if ( v6 )
{
if ( atoi(v6) != finQ )
{
pthread_mutex_lock(&mutexVarFinQuantum);
finQ = atoi(v7);
pthread_mutex_unlock(&mutexVarFinQuantum);
}
}
}
if ( strstr(v12, "finIO") )
{
strtok(v12, " ");
v8 = strtok(0LL, ";");
v9 = v8;
if ( v8 )
{
if ( atoi(v8) != finQ )
{
pthread_mutex_lock(&mutexVarFinIO);
finIO = atoi(v9);
pthread_mutex_unlock(&mutexVarFinIO);
}
}
}
if ( strstr(v12, "espera_estandar") )
{
if ( !strstr(v12, "espera_estandar_io") )
{
strtok(v12, " ");
v20 = strtok(0LL, ";");
v21 = v20;
if ( v20 )
{
if ( strcmp(espera_estandar, v20) )
{
pthread_mutex_lock(&mutexVarEsperaEstandar);
espera_estandar = v21;
pthread_mutex_unlock(&mutexVarEsperaEstandar);
}
}
}
}
if ( strstr(v12, "alfa") )
{
strtok(v12, " ");
v10 = strtok(0LL, ";");
v11 = v10;
if ( v10 )
{
if ( atof(v10) != *(double *)&alfa )
{
pthread_mutex_lock(&mutexVarAlfa);
alfa = atof(v11);
pthread_mutex_unlock(&mutexVarAlfa);
}
}
}
}
while ( v1 );
}
return 0LL;
}

original_code:
int comprobar_archivo_configuracion(){
 char *nombre_archivo="pp.conf";
 char *texto_del_archivo =leer_archivo(nombre_archivo);
 char *linea;
 char *valor;
 while( texto_del_archivo != ((void *)0)){
  linea = strtok(texto_del_archivo,"\n");
  texto_del_archivo = strtok(((void *)0),"\0");
  if( strstr(linea,"mps")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && max_mps!=atoi(valor)){
    pthread_mutex_lock(&mutexVarMaxMPS);
    max_mps=atoi(valor);
    pthread_mutex_unlock(&mutexVarMaxMPS);
   }
  }
  if( strstr(linea,"mmp")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && max_mmp!=atoi(valor)){
    pthread_mutex_lock(&mutexVarMaxMMP);
    max_mmp=atoi(valor);
    pthread_mutex_unlock(&mutexVarMaxMMP);
   }
  }
  if( strstr(linea,"lpl")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && strcmp(lpl,valor)){
    pthread_mutex_lock(&mutexVarLPL);
    lpl=valor;
    pthread_mutex_unlock(&mutexVarLPL);
   }
  }
  if( strstr(linea,"lpn")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && lpn!=atoi(valor)){
    pthread_mutex_lock(&mutexVarLPN);
    lpn=atoi(valor);
    pthread_mutex_unlock(&mutexVarLPN);
   }
  }
  if( strstr(linea,"lpr")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && lpr != atoi(valor)){
    pthread_mutex_lock(&mutexVarLPR);
    lpr=atoi(valor);
    pthread_mutex_unlock(&mutexVarLPR);
   }
  }
  if( strstr(linea,"finQ")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && finQ != atoi(valor)){
    pthread_mutex_lock(&mutexVarFinQuantum);
    finQ=atoi(valor);
    pthread_mutex_unlock(&mutexVarFinQuantum);
   }
  }
  if( strstr(linea,"finIO")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && finQ != atoi(valor)){
    pthread_mutex_lock(&mutexVarFinIO);
    finIO=atoi(valor);
    pthread_mutex_unlock(&mutexVarFinIO);
   }
  }
  if( strstr(linea,"espera_estandar") && strstr(linea,"espera_estandar_io") == ((void *)0)){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && strcmp(espera_estandar,valor)!=0){
    pthread_mutex_lock(&mutexVarEsperaEstandar);
    espera_estandar=valor;
    pthread_mutex_unlock(&mutexVarEsperaEstandar);
   }
  }
  if( strstr(linea,"alfa") ){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && alfa!=atof(valor)){
    pthread_mutex_lock(&mutexVarAlfa);
    alfa=atof(valor);
    pthread_mutex_unlock(&mutexVarAlfa);
   }
  }
 }
 return 0;
}

canonical_original_code:
int comprobar_archivo_configuracion(){
 char *nombre_archivo = "pp.conf";
 char *texto_del_archivo = leer_archivo(nombre_archivo);
 char *linea;
 char *valor;
 while( texto_del_archivo != ((void *)0)){
  linea = strtok(texto_del_archivo,"\n");
  texto_del_archivo = strtok(((void *)0),"\0");
  if( strstr(linea,"mps")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && max_mps!=atoi(valor)){
    pthread_mutex_lock(&mutexVarMaxMPS);
    max_mps=atoi(valor);
    pthread_mutex_unlock(&mutexVarMaxMPS);
   }
  }
  if( strstr(linea,"mmp")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && max_mmp!=atoi(valor)){
    pthread_mutex_lock(&mutexVarMaxMMP);
    max_mmp=atoi(valor);
    pthread_mutex_unlock(&mutexVarMaxMMP);
   }
  }
  if( strstr(linea,"lpl")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && strcmp(lpl,valor)){
    pthread_mutex_lock(&mutexVarLPL);
    lpl=valor;
    pthread_mutex_unlock(&mutexVarLPL);
   }
  }
  if( strstr(linea,"lpn")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && lpn!=atoi(valor)){
    pthread_mutex_lock(&mutexVarLPN);
    lpn=atoi(valor);
    pthread_mutex_unlock(&mutexVarLPN);
   }
  }
  if( strstr(linea,"lpr")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && lpr != atoi(valor)){
    pthread_mutex_lock(&mutexVarLPR);
    lpr=atoi(valor);
    pthread_mutex_unlock(&mutexVarLPR);
   }
  }
  if( strstr(linea,"finQ")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && finQ != atoi(valor)){
    pthread_mutex_lock(&mutexVarFinQuantum);
    finQ=atoi(valor);
    pthread_mutex_unlock(&mutexVarFinQuantum);
   }
  }
  if( strstr(linea,"finIO")){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && finQ != atoi(valor)){
    pthread_mutex_lock(&mutexVarFinIO);
    finIO=atoi(valor);
    pthread_mutex_unlock(&mutexVarFinIO);
   }
  }
  if( strstr(linea,"espera_estandar") && strstr(linea,"espera_estandar_io") == ((void *)0)){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && strcmp(espera_estandar,valor)!=0){
    pthread_mutex_lock(&mutexVarEsperaEstandar);
    espera_estandar=valor;
    pthread_mutex_unlock(&mutexVarEsperaEstandar);
   }
  }
  if( strstr(linea,"alfa") ){
   valor = strtok(linea," ");
   valor = strtok(((void *)0),";");
   if( valor != ((void *)0) && alfa!=atof(valor)){
    pthread_mutex_lock(&mutexVarAlfa);
    alfa=atof(valor);
    pthread_mutex_unlock(&mutexVarAlfa);
   }
  }
 }
 return 0;
}

variable_types:
linea
char *

variable_types:
valor
char *