logout

repo: ComdivByZero/linux-work-time-control

decompiled_code:
int logout()
{
if ( system("gnome-session-quit --logout --no-prompt --force") )
fwrite("Can not quit by gnome-session-quit\n", 1uLL, 0x23uLL, stderr);
if ( system("qdbus org.kde.ksmserver /KSMServer logout 0 0 0") )
fwrite("Can not quit by qdbus org.kde.ksmserver\n", 1uLL, 0x28uLL, stderr);
if ( !memcmp(getenv("XDG_CURRENT_DESKTOP"), "XFCE", 4uLL) && system("xfce4-session-logout --logout") )
fwrite("Can not quit by xfce4-session-logout\n", 1uLL, 0x25uLL, stderr);
return puts("logout");
}

canonical_decompiled_code:
int func9()
{
if ( system("gnome-session-quit --logout --no-prompt --force") )
fwrite("Can not quit by gnome-session-quit\n", 1uLL, 0x23uLL, stderr);
if ( system("qdbus org.kde.ksmserver /KSMServer logout 0 0 0") )
fwrite("Can not quit by qdbus org.kde.ksmserver\n", 1uLL, 0x28uLL, stderr);
if ( !memcmp(getenv("XDG_CURRENT_DESKTOP"), "XFCE", 4uLL) && system("xfce4-session-logout --logout") )
fwrite("Can not quit by xfce4-session-logout\n", 1uLL, 0x25uLL, stderr);
return puts("logout");
}

original_code:
static void logout(void) {
 if (0 != system("gnome-session-quit --logout --no-prompt --force")) {
  fprintf(stderr, "Can not quit by gnome-session-quit\n");
 }
 if (0 != system("qdbus org.kde.ksmserver /KSMServer logout 0 0 0")) {
  fprintf(stderr, "Can not quit by qdbus org.kde.ksmserver\n");
 }
 if (strncmp(getenv("XDG_CURRENT_DESKTOP"), "XFCE", 4) == 0) {
  if (0 != system("xfce4-session-logout --logout")) {
   fprintf(stderr, "Can not quit by xfce4-session-logout\n");
  }
 }
 printf("logout\n");
}

canonical_original_code:
static void logout() {
 if (0 != system("gnome-session-quit --logout --no-prompt --force")) {
  fprintf(stderr, "Can not quit by gnome-session-quit\n");
 }
 if (0 != system("qdbus org.kde.ksmserver /KSMServer logout 0 0 0")) {
  fprintf(stderr, "Can not quit by qdbus org.kde.ksmserver\n");
 }
 if (strncmp(getenv("XDG_CURRENT_DESKTOP"), "XFCE", 4) == 0) {
  if (0 != system("xfce4-session-logout --logout")) {
   fprintf(stderr, "Can not quit by xfce4-session-logout\n");
  }
 }
 printf("logout\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int v4; // eax

if ( argc <= 1 )
{
control();
}
else
{
v3 = argv[1];
if ( !strcmp(v3, "-h") )
{
puts("Yet not writed");
}
else
{
v4 = atoi(v3);
if ( v4 <= 0 )
fprintf(stderr, "Wrong paremeter %s\n", v3);
else
prepare(v4);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int v4; // eax

if ( argc <= 1 )
{
func10();
}
else
{
v3 = argv[1];
if ( !strcmp(v3, "-h") )
{
puts("Yet not writed");
}
else
{
v4 = atoi(v3);
if ( v4 <= 0 )
fprintf(stderr, "Wrong paremeter %s\n", v3);
else
func7(v4);
}
}
return 0;
}

original_code:
extern int main(int argc, char *argv[]) {
 int minutes;
 if (argc > 1) {
  if (strcmp(argv[1], "-h") == 0) {
   printf("Yet not writed\n");
  } else {
   minutes = atoi(argv[1]);
   if (minutes > 0) {
    prepare(minutes);
   } else {
    fprintf(stderr, "Wrong paremeter %s\n", argv[1]);
   }
  }
 } else {
  control();
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: minutes int

return_type: int


compCount

repo: Conservatory/MailListStats

decompiled_code:
_BOOL8 __fastcall compCount(__int64 a1, __int64 a2)
{
return *(_QWORD *)(a1 + 176) > *(_QWORD *)(a2 + 176);
}

original_code:
int compCount(nTptr a, nTptr b) {
  return (a->count > b->count);
}

canonical_original_code:
int compCount(struct bestTEXT *a, struct bestTEXT *b) {
  return (a->count > b->count);
}

variable_types: struct bestTEXT { char text[160]; long size; long quote; long count; struct bestTEXT *next; } *

variable_types:
b
struct bestTEXT *


Alokuj

decompiled_code:
void *Alokuj()
{
return malloc(0xC0uLL);
}

canonical_decompiled_code:
void *func1()
{
return malloc(0xC0uLL);
}

original_code:
nTptr Alokuj() {
  return (nTptr)malloc(sizeof(struct bestTEXT));
}

canonical_original_code:
struct bestTEXT *Alokuj() {
  return (struct bestTEXT *)malloc(sizeof(struct bestTEXT));
}

return_type: struct bestTEXT { char text[160]; long size; long quote; long count; struct bestTEXT *next; } *


compSize

decompiled_code:
_BOOL8 __fastcall compSize(__int64 a1, __int64 a2)
{
return *(_QWORD *)(a1 + 160) > *(_QWORD *)(a2 + 160);
}

original_code:
int compSize(nTptr a, nTptr b) {
  return (a->size > b->size);
}

canonical_original_code:
int compSize(struct bestTEXT *a, struct bestTEXT *b) {
  return (a->size > b->size);
}

user_defined_types: struct bestTEXT { char text[160]; long size; long quote; long count; struct bestTEXT *next; }


InsertEntry

original_code:
nTptr InsertEntry(nTptr first, nTptr newone, int (*comp)()) {
  nTptr akt,akt2;
  if (first==((void *)0)) return newone;
  if (comp(newone,first)) {
     newone->next=first;
     return newone;
  }
  akt=first;
  if (akt->next!=((void *)0)) while (!(comp(newone,akt->next))) {
    akt=akt->next;
    if (akt->next==((void *)0)) break;
  }
  akt2=akt->next;
  akt->next=newone;
  newone->next=akt2;
  return first;
}

canonical_original_code:
struct bestTEXT *InsertEntry(struct bestTEXT *first, struct bestTEXT *newone, int (*comp)()) {
  struct bestTEXT *akt; struct bestTEXT *akt2;
  if (first==((void *)0)) return newone;
  if (comp(newone,first)) {
     newone->next=first;
     return newone;
  }
  akt=first;
  if (akt->next!=((void *)0)) while (!(comp(newone,akt->next))) {
    akt=akt->next;
    if (akt->next==((void *)0)) break;
  }
  akt2=akt->next;
  akt->next=newone;
  newone->next=akt2;
  return first;
}

variable_types:
first
struct bestTEXT *

variable_types:
newone
struct bestTEXT *

variable_types:
comp
int (*)()


AddEntry

original_code:
nTptr AddEntry(nTptr first, char *t, long size, long quote, int (*comp)()) {
  nTptr prev,akt,newone;
  prev=((void *)0);
  akt=first;
  while (akt!=((void *)0)) {
    if (!strncmp(akt->text,t,160)) {
       (akt->count)++;
       (akt->size)+=size;
       (akt->quote)+=quote;
       if (prev!=((void *)0)) prev->next=akt->next;
       if (akt==first) first=akt->next;
       return InsertEntry(first,akt,comp);
    }
    prev=akt;
    akt=akt->next;
  }
  if ((newone=Alokuj())==((void *)0)) myWarn("Not enough memory!","",4);
  myCopy(newone->text,t,160);
  newone->size=size;
  newone->quote=quote;
  newone->count=1;
  newone->next=((void *)0);
  return InsertEntry(first,newone,comp);
}

canonical_original_code:
struct bestTEXT *AddEntry(struct bestTEXT *first, char *t, long size, long quote, int (*comp)()) {
  struct bestTEXT *prev; struct bestTEXT *akt; struct bestTEXT *newone;
  prev=((void *)0);
  akt=first;
  while (akt!=((void *)0)) {
    if (!strncmp(akt->text,t,160)) {
       (akt->count)++;
       (akt->size)+=size;
       (akt->quote)+=quote;
       if (prev!=((void *)0)) prev->next=akt->next;
       if (akt==first) first=akt->next;
       return InsertEntry(first,akt,comp);
    }
    prev=akt;
    akt=akt->next;
  }
  if ((newone=Alokuj())==((void *)0)) myWarn("Not enough memory!","",4);
  myCopy(newone->text,t,160);
  newone->size=size;
  newone->quote=quote;
  newone->count=1;
  newone->next=((void *)0);
  return InsertEntry(first,newone,comp);
}

variable_types:
t
char *

variable_types: size long

variable_types: quote long


SortQuote

decompiled_code:
__int64 __fastcall SortQuote(_QWORD *a1)
{
_QWORD *v1; // rbp
__int64 v2; // r12
_QWORD *v3; // rbx
__int64 v4; // rax

v1 = a1;
if ( !a1 )
return 0LL;
v2 = 0LL;
do
{
v3 = Alokuj();
if ( !v3 )
myWarn("Not enough memory!", &unk_CA0, 4LL);
myCopy(v3, v1, 160LL);
v3[20] = v1[20];
v4 = v1[21];
v3[21] = v4;
v3[22] = (int)(float)((float)((float)(int)v4 / (float)(int)v1[20]) * 10000.0);
v3[23] = 0LL;
v2 = InsertEntry(v2, (__int64)v3, (unsigned int (__fastcall *)(__int64, __int64))compCount);
v1 = (_QWORD *)v1[23];
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
_QWORD *v1; // rbp
__int64 v2; // r12
_QWORD *v3; // rbx
__int64 v4; // rax

v1 = a1;
if ( !a1 )
return 0LL;
v2 = 0LL;
do
{
v3 = func1();
if ( !v3 )
myWarn("Not enough memory!", &unk_CA0, 4LL);
myCopy(v3, v1, 160LL);
v3[20] = v1[20];
v4 = v1[21];
v3[21] = v4;
v3[22] = (int)(float)((float)((float)(int)v4 / (float)(int)v1[20]) * 10000.0);
v3[23] = 0LL;
v2 = func4(v2, (__int64)v3, (unsigned int (__fastcall *)(__int64, __int64))compCount);
v1 = (_QWORD *)v1[23];
}
while ( v1 );
return v2;
}

original_code:
nTptr SortQuote(nTptr oldfirst) {
  nTptr akt,akt2,newfirst;
  newfirst=((void *)0);
  for (akt=oldfirst; akt!=((void *)0); akt=akt->next) {
     if ((akt2=Alokuj())==((void *)0)) myWarn("Not enough memory!","",4);
     myCopy(akt2->text,akt->text,160);
     akt2->size =akt->size;
     akt2->quote=akt->quote;
     akt2->count=(int)((float)(akt->quote)/(akt->size)*10000);
     akt2->next=((void *)0);
     newfirst=InsertEntry(newfirst,akt2,compCount);
  }
  return newfirst;
}

canonical_original_code:
struct bestTEXT *SortQuote(struct bestTEXT *oldfirst) {
  struct bestTEXT *akt; struct bestTEXT *akt2; struct bestTEXT *newfirst;
  newfirst=((void *)0);
  for (akt=oldfirst; akt!=((void *)0); akt=akt->next) {
     if ((akt2=Alokuj())==((void *)0)) myWarn("Not enough memory!","",4);
     myCopy(akt2->text,akt->text,160);
     akt2->size =akt->size;
     akt2->quote=akt->quote;
     akt2->count=(int)((float)(akt->quote)/(akt->size)*10000);
     akt2->next=((void *)0);
     newfirst=InsertEntry(newfirst,akt2,compCount);
  }
  return newfirst;
}

variable_types:
oldfirst
struct bestTEXT *


SortSize

decompiled_code:
__int64 __fastcall SortSize(_QWORD *a1, int a2)
{
_QWORD *v2; // rbp
__int64 v3; // r12
_QWORD *v4; // rbx
__int64 v5; // rdx
__int64 v6; // rcx

v2 = a1;
if ( !a1 )
return 0LL;
v3 = 0LL;
do
{
v4 = Alokuj();
if ( !v4 )
myWarn("Not enough memory!", &unk_CA0, 4LL);
myCopy(v4, v2, 160LL);
v4[20] = v2[20];
v5 = v2[21];
v4[21] = v5;
v6 = 1LL;
if ( a2 )
v6 = v2[22];
v4[22] = (v2[20] - v5) / v6;
v4[23] = 0LL;
v3 = InsertEntry(v3, (__int64)v4, (unsigned int (__fastcall *)(__int64, __int64))compCount);
v2 = (_QWORD *)v2[23];
}
while ( v2 );
return v3;
}

original_code:
nTptr SortSize(nTptr oldfirst, int avg) {
  nTptr akt,akt2,newfirst;
  newfirst=((void *)0);
  for (akt=oldfirst; akt!=((void *)0); akt=akt->next) {
     if ((akt2=Alokuj())==((void *)0)) myWarn("Not enough memory!","",4);
     myCopy(akt2->text,akt->text,160);
     akt2->size =akt->size;
     akt2->quote=akt->quote;
     akt2->count=(akt->size - akt->quote) / ((avg) ? akt->count:1);
     akt2->next=((void *)0);
     newfirst=InsertEntry(newfirst,akt2,compCount);
  }
  return newfirst;
}

canonical_original_code:
struct bestTEXT *SortSize(struct bestTEXT *oldfirst, int avg) {
  struct bestTEXT *akt; struct bestTEXT *akt2; struct bestTEXT *newfirst;
  newfirst=((void *)0);
  for (akt=oldfirst; akt!=((void *)0); akt=akt->next) {
     if ((akt2=Alokuj())==((void *)0)) myWarn("Not enough memory!","",4);
     myCopy(akt2->text,akt->text,160);
     akt2->size =akt->size;
     akt2->quote=akt->quote;
     akt2->count=(akt->size - akt->quote) / ((avg) ? akt->count:1);
     akt2->next=((void *)0);
     newfirst=InsertEntry(newfirst,akt2,compCount);
  }
  return newfirst;
}

variable_types: avg int


replaceStr

decompiled_code:
char *__fastcall replaceStr(__int64 a1, int a2, int a3, const char *a4)
{
size_t v5; // rbp
char v7[296]; // [rsp+0h] [rbp-128h] BYREF

myCopy(v7, a1 + a3 + 1, 256LL);
v5 = (int)strlen(a4);
strncpy((char *)(a1 + a2), a4, v5);
return strcpy((char *)(a1 + a2 + v5), v7);
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, int a2, int a3, const char *a4)
{
size_t v5; // rbp
char v7[296]; // [rsp+0h] [rbp-128h] BYREF

myCopy(v7, a1 + a3 + 1, 256LL);
v5 = (int)strlen(a4);
strncpy((char *)(a1 + a2), a4, v5);
return strcpy((char *)(a1 + a2 + v5), v7);
}

original_code:
void replaceStr(char *input, int so, int eo, char *repl) {
 char tmp[256];
 int l;
 myCopy(tmp,input+eo+1,256);
 l=strlen(repl);
 strncpy(input+so,repl,l);
 strcpy(input+so+l,tmp);
}

variable_types:
input
char *

variable_types: so int

variable_types: eo int

variable_types:
repl
char *

variable_types:
tmp
char [256]

variable_types: l int

return_type: void


decompiled_code:
int __fastcall Decode_QuotedPrint(char *string)
{
char v1; // dl
char *v2; // rax
int result; // eax
char nptr[4]; // [rsp+Ch] [rbp-5Ch] BYREF
regmatch_t v5; // [rsp+10h] [rbp-58h] BYREF
int v6; // [rsp+18h] [rbp-50h]
int v7; // [rsp+1Ch] [rbp-4Ch]

v1 = *string;
if ( *string )
{
v2 = string;
do
{
if ( v1 == 95 )
*v2 = 32;
v1 = *++v2;
}
while ( *v2 );
}
while ( 1 )
{
result = regexec(&r_hex, string, 0xAuLL, &v5, 0);
if ( result )
break;
myCopy(nptr, &string[v6 + 1], 3LL);
nptr[0] = strtol(nptr, 0LL, 16);
nptr[1] = 0;
replaceStr((__int64)string, v6, v7 - 1, nptr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *string)
{
char v1; // dl
char *v2; // rax
int result; // eax
char nptr[4]; // [rsp+Ch] [rbp-5Ch] BYREF
regmatch_t v5; // [rsp+10h] [rbp-58h] BYREF
int v6; // [rsp+18h] [rbp-50h]
int v7; // [rsp+1Ch] [rbp-4Ch]

v1 = *string;
if ( *string )
{
v2 = string;
do
{
if ( v1 == 95 )
*v2 = 32;
v1 = *++v2;
}
while ( *v2 );
}
while ( 1 )
{
result = regexec(&r_hex, string, 0xAuLL, &v5, 0);
if ( result )
break;
myCopy(nptr, &string[v6 + 1], 3LL);
nptr[0] = strtol(nptr, 0LL, 16);
nptr[1] = 0;
func0((__int64)string, v6, v7 - 1, nptr);
}
return result;
}

original_code:
void Decode_QuotedPrint(char *encoded, char *charset) {
 regmatch_t pm[10];
 char hex[4];
 char *tmp;
 int ihex;
 for (tmp=encoded; *tmp!='\0'; tmp++) if (*tmp=='_') *tmp=' ';
 while (!regexec(&r_hex, encoded, 10, pm, 0)) {
   myCopy(hex,encoded+pm[1].rm_so+1,3);
   ihex=strtol(hex,((void *)0),16);
   hex[0]=ihex;
   hex[1]='\0';
   replaceStr(encoded,pm[1].rm_so,pm[1].rm_eo-1,hex);
 }
}

canonical_original_code:
void Decode_QuotedPrint(char *encoded, char *charset) {
 struct regmatch_t pm[10];
 char hex[4];
 char *tmp;
 int ihex;
 for (tmp=encoded; *tmp!='\0'; tmp++) if (*tmp=='_') *tmp=' ';
 while (!regexec(&r_hex, encoded, 10, pm, 0)) {
   myCopy(hex,encoded+pm[1].rm_so+1,3);
   ihex=strtol(hex,((void *)0),16);
   hex[0]=ihex;
   hex[1]='\0';
   replaceStr(encoded,pm[1].rm_so,pm[1].rm_eo-1,hex);
 }
}

variable_types:
encoded
char *

variable_types:
charset
char *

variable_types: struct regmatch_t { int rm_so; int rm_eo; } [10]

variable_types:
hex
char [4]

variable_types:
tmp
char *

variable_types: ihex int


decompiled_code:
__int64 __fastcall base64_table(char *a1)
{
char v1; // al
bool v2; // zf
__int64 result; // rax

v1 = *a1;
if ( (unsigned __int8)(*a1 - 65) <= 0x19u )
return (unsigned int)(v1 - 65);
if ( (unsigned __int8)(v1 - 97) <= 0x19u )
return (unsigned int)(v1 - 71);
if ( (unsigned __int8)(v1 - 48) <= 9u )
return (unsigned int)(v1 + 4);
if ( v1 == 43 )
return 62LL;
v2 = v1 == 47;
result = 0LL;
if ( v2 )
result = 63LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char v1; // al
bool v2; // zf
__int64 result; // rax

v1 = *a1;
if ( (unsigned __int8)(*a1 - 65) <= 0x19u )
return (unsigned int)(v1 - 65);
if ( (unsigned __int8)(v1 - 97) <= 0x19u )
return (unsigned int)(v1 - 71);
if ( (unsigned __int8)(v1 - 48) <= 9u )
return (unsigned int)(v1 + 4);
if ( v1 == 43 )
return 62LL;
v2 = v1 == 47;
result = 0LL;
if ( v2 )
result = 63LL;
return result;
}

original_code:
int base64_table(char *lookup) {
 if (*lookup>='A' && *lookup<='Z') return *lookup-65;
 if (*lookup>='a' && *lookup<='z') return *lookup-71;
 if (*lookup>='0' && *lookup<='9') return *lookup+04;
 if (*lookup=='+') return 62;
 if (*lookup=='/') return 63;
 return 0;
}

variable_types:
lookup
char *


original_code:
void Decode_base64(char *encoded, char *charset) {
 char decoded[76]="";
 char ch;
 char *tmp,*tmp2;
 unsigned long bits24,mask24;
 int i;
 tmp2=decoded;
 for (tmp=encoded; *tmp!='\0'; tmp+=4) {
   bits24=0;
   for (i=0; i<4; i++) {
     if (*(tmp+i)!='=') bits24+=base64_table(tmp+i);
     bits24 = bits24 << 6;
   }
   bits24 = bits24 >> 6;
   mask24=255 << 16;
   for (i=2; i>=0; i--) {
     ch=(short)((bits24 & mask24) >> (i*8));
     if (ch!='\0') *(tmp2++)=ch;
     mask24 = mask24 >> 8;
   }
 }
 *tmp2='\0';
 strcpy(encoded,decoded);
}

canonical_original_code:
void Decode_base64(char *encoded, char *charset) {
 char decoded[76] = "";
 char ch;
 char *tmp; char *tmp2;
 unsigned long bits24; unsigned long mask24;
 int i;
 tmp2=decoded;
 for (tmp=encoded; *tmp!='\0'; tmp+=4) {
   bits24=0;
   for (i=0; i<4; i++) {
     if (*(tmp+i)!='=') bits24+=base64_table(tmp+i);
     bits24 = bits24 << 6;
   }
   bits24 = bits24 >> 6;
   mask24=255 << 16;
   for (i=2; i>=0; i--) {
     ch=(short)((bits24 & mask24) >> (i*8));
     if (ch!='\0') *(tmp2++)=ch;
     mask24 = mask24 >> 8;
   }
 }
 *tmp2='\0';
 strcpy(encoded,decoded);
}

variable_types:
decoded
char [76]

variable_types: ch char

variable_types: i int


decompiled_code:
int compile_mime_regex()
{
int result; // eax
char v1[79]; // [rsp+1h] [rbp-87h] BYREF
char pattern[56]; // [rsp+50h] [rbp-38h] BYREF

strcpy(pattern, "(=\\?([0-9a-z-]*)\\?B\\?([0-9a-z+/=]*)\\?=)");
strcpy(&v1[15], "(=\\?([0-9a-z-]*)\\?Q\\?(([!-<]|[>-~]|=[0-9a-f]{2}|\\0x9| |_)*)\\?=)");
strcpy(v1, "(=[0-9a-z]{2})");
if ( regcomp(&r_base64, pattern, 3) > 0 )
myWarn("Error compiling regex!", "(mime_base64)", 5LL);
if ( regcomp(&r_qp, &v1[15], 3) > 0 )
myWarn("Error compiling regex!", "(mime_qp)", 5LL);
result = regcomp(&r_hex, v1, 3);
if ( result > 0 )
result = myWarn("Error compiling regex!", "(mime_hex)", 5LL);
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax
char v1[79]; // [rsp+1h] [rbp-87h] BYREF
char pattern[56]; // [rsp+50h] [rbp-38h] BYREF

strcpy(pattern, "(=\\?([0-9a-z-]*)\\?B\\?([0-9a-z+/=]*)\\?=)");
strcpy(&v1[15], "(=\\?([0-9a-z-]*)\\?Q\\?(([!-<]|[>-~]|=[0-9a-f]{2}|\\0x9| |_)*)\\?=)");
strcpy(v1, "(=[0-9a-z]{2})");
if ( regcomp(&r_base64, pattern, 3) > 0 )
myWarn("Error compiling regex!", "(mime_base64)", 5LL);
if ( regcomp(&r_qp, &v1[15], 3) > 0 )
myWarn("Error compiling regex!", "(mime_qp)", 5LL);
result = regcomp(&r_hex, v1, 3);
if ( result > 0 )
result = myWarn("Error compiling regex!", "(mime_hex)", 5LL);
return result;
}

variable_types:
sB
char []

variable_types:
sQ
char []

variable_types:
sH
char []


decompiled_code:
int __fastcall Decode_mime_string(char *string)
{
int v1; // edx
int v2; // edx
int v3; // edx
int v4; // edx
int result; // eax
regmatch_t v6; // [rsp+0h] [rbp-D8h] BYREF
int v7; // [rsp+8h] [rbp-D0h]
int v8; // [rsp+Ch] [rbp-CCh]
int v9; // [rsp+10h] [rbp-C8h]
int v10; // [rsp+14h] [rbp-C4h]
int v11; // [rsp+18h] [rbp-C0h]
int v12; // [rsp+1Ch] [rbp-BCh]
char stringa[80]; // [rsp+50h] [rbp-88h] BYREF
char v14[56]; // [rsp+A0h] [rbp-38h] BYREF

while ( !regexec(&r_qp, string, 0xAuLL, &v6, 0) )
{
v1 = v10 - v9 + 1;
if ( v1 > 40 )
v1 = 40;
myCopy(v14, &string[v9], v1);
v2 = v12 - v11 + 1;
if ( v2 > 76 )
v2 = 76;
myCopy(stringa, &string[v11], v2);
Decode_QuotedPrint(stringa);
replaceStr((__int64)string, v7, v8 - 1, stringa);
}
while ( 1 )
{
result = regexec(&r_base64, string, 0xAuLL, &v6, 0);
if ( result )
break;
v3 = v10 - v9 + 1;
if ( v3 > 40 )
v3 = 40;
myCopy(v14, &string[v9], v3);
v4 = v12 - v11 + 1;
if ( v4 > 76 )
v4 = 76;
myCopy(stringa, &string[v11], v4);
Decode_base64(stringa);
replaceStr((__int64)string, v7, v8 - 1, stringa);
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(char *string)
{
int v1; // edx
int v2; // edx
int v3; // edx
int v4; // edx
int result; // eax
regmatch_t v6; // [rsp+0h] [rbp-D8h] BYREF
int v7; // [rsp+8h] [rbp-D0h]
int v8; // [rsp+Ch] [rbp-CCh]
int v9; // [rsp+10h] [rbp-C8h]
int v10; // [rsp+14h] [rbp-C4h]
int v11; // [rsp+18h] [rbp-C0h]
int v12; // [rsp+1Ch] [rbp-BCh]
char stringa[80]; // [rsp+50h] [rbp-88h] BYREF
char v14[56]; // [rsp+A0h] [rbp-38h] BYREF

while ( !regexec(&r_qp, string, 0xAuLL, &v6, 0) )
{
v1 = v10 - v9 + 1;
if ( v1 > 40 )
v1 = 40;
myCopy(v14, &string[v9], v1);
v2 = v12 - v11 + 1;
if ( v2 > 76 )
v2 = 76;
myCopy(stringa, &string[v11], v2);
func1(stringa);
func0((__int64)string, v7, v8 - 1, stringa);
}
while ( 1 )
{
result = regexec(&r_base64, string, 0xAuLL, &v6, 0);
if ( result )
break;
v3 = v10 - v9 + 1;
if ( v3 > 40 )
v3 = 40;
myCopy(v14, &string[v9], v3);
v4 = v12 - v11 + 1;
if ( v4 > 76 )
v4 = 76;
myCopy(stringa, &string[v11], v4);
func3(stringa);
func0((__int64)string, v7, v8 - 1, stringa);
}
return result;
}

original_code:
void Decode_mime_string(char *txt, unsigned int max_size) {
 int i;
 char charset[40];
 char enc[76];
 regmatch_t pm[10];
 while (!regexec(&r_qp, txt, 10, pm, 0)) {
   i=pm[2].rm_eo - pm[2].rm_so + 1;
   myCopy(charset, txt+pm[2].rm_so, (i>40)?40:i);
   i=pm[3].rm_eo - pm[3].rm_so + 1;
   myCopy(enc, txt+pm[3].rm_so, (i>76)?76:i);
   Decode_QuotedPrint(enc,charset);
   replaceStr(txt,pm[1].rm_so,pm[1].rm_eo-1,enc);
 }
 while (!regexec(&r_base64, txt, 10, pm, 0)) {
   i=pm[2].rm_eo - pm[2].rm_so + 1;
   myCopy(charset, txt+pm[2].rm_so, (i>40)?40:i);
   i=pm[3].rm_eo - pm[3].rm_so + 1;
   myCopy(enc, txt+pm[3].rm_so, (i>76)?76:i);
   Decode_base64(enc,charset);
   replaceStr(txt,pm[1].rm_so,pm[1].rm_eo-1,enc);
 }
}

canonical_original_code:
void Decode_mime_string(char *txt, unsigned int max_size) {
 int i;
 char charset[40];
 char enc[76];
 struct regmatch_t pm[10];
 while (!regexec(&r_qp, txt, 10, pm, 0)) {
   i=pm[2].rm_eo - pm[2].rm_so + 1;
   myCopy(charset, txt+pm[2].rm_so, (i>40)?40:i);
   i=pm[3].rm_eo - pm[3].rm_so + 1;
   myCopy(enc, txt+pm[3].rm_so, (i>76)?76:i);
   Decode_QuotedPrint(enc,charset);
   replaceStr(txt,pm[1].rm_so,pm[1].rm_eo-1,enc);
 }
 while (!regexec(&r_base64, txt, 10, pm, 0)) {
   i=pm[2].rm_eo - pm[2].rm_so + 1;
   myCopy(charset, txt+pm[2].rm_so, (i>40)?40:i);
   i=pm[3].rm_eo - pm[3].rm_so + 1;
   myCopy(enc, txt+pm[3].rm_so, (i>76)?76:i);
   Decode_base64(enc,charset);
   replaceStr(txt,pm[1].rm_so,pm[1].rm_eo-1,enc);
 }
}

variable_types:
txt
char *

variable_types:
charset
char [40]

variable_types:
enc
char [76]

user_defined_types: struct regmatch_t { int rm_so; int rm_eo; }


repo: Conservatory/quark

decompiled_code:
int __fastcall change_uid(__uid_t uid)
{
int result; // eax

if ( setgid(0) )
{
perror("setuid to root failed");
result = 1;
}
else if ( setgid(uid) )
{
perror("setgid failed");
result = 1;
}
else if ( setuid(uid) )
{
perror("setuid failed");
result = 1;
}
else if ( setegid(uid) )
{
perror("seteugid failed");
result = 1;
}
else
{
result = seteuid(uid);
if ( result )
{
perror("seteuid failed");
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__uid_t uid)
{
int result; // eax

if ( setgid(0) )
{
perror("setuid to root failed");
result = 1;
}
else if ( setgid(uid) )
{
perror("setgid failed");
result = 1;
}
else if ( setuid(uid) )
{
perror("setuid failed");
result = 1;
}
else if ( setegid(uid) )
{
perror("seteugid failed");
result = 1;
}
else
{
result = seteuid(uid);
if ( result )
{
perror("seteuid failed");
result = 1;
}
}
return result;
}

original_code:
int change_uid(int suid) {
  if(setgid(0)) {
    perror("setuid to root failed");
    return 1;
  }
  if(setgid(suid)) {
    perror("setgid failed");
    return 1;
  }
  if(setuid(suid)) {
    perror("setuid failed");
    return 1;
  }
  if(setegid(suid)) {
    perror("seteugid failed");
    return 1;
  }
  if(seteuid(suid)) {
    perror("seteuid failed");
    return 1;
  }
  return 0;
}

variable_types: suid int


redditCookieFree

repo: Cotix/cReddit

decompiled_code:
void __fastcall redditCookieFree(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}
}

original_code:
__attribute__((visibility("default"))) void redditCookieFree(RedditCookieLink *link)
{
    if (link == ((void *)0))
        return ;
    free(link->name);
    free(link->data);
    free(link);
}

canonical_original_code:
void redditCookieFree(struct RedditCookieLink *link)
{
    if (link == ((void *)0))
        return ;
    free(link->name);
    free(link->data);
    free(link);
}

variable_types: struct RedditCookieLink { struct RedditCookieLink *next; char *name; char *data; } *


redditRemoveCookie

decompiled_code:
void __fastcall redditRemoveCookie(char *s2)
{
_QWORD *v1; // r13
void *v2; // rbx
_QWORD *v3; // r12

v1 = currentRedditState;
if ( currentRedditState )
{
v2 = (void *)*currentRedditState;
if ( *currentRedditState )
{
v3 = 0LL;
while ( strcmp(*((const char **)v2 + 1), s2) )
{
v3 = v2;
if ( !*(_QWORD *)v2 )
return;
v2 = *(void **)v2;
}
if ( v3 )
*v3 = *(_QWORD *)v2;
else
*v1 = *(_QWORD *)v2;
redditCookieFree(v2);
}
}
}

canonical_decompiled_code:
void __fastcall func1(char *s2)
{
_QWORD *v1; // r13
void *v2; // rbx
_QWORD *v3; // r12

v1 = currentRedditState;
if ( currentRedditState )
{
v2 = (void *)*currentRedditState;
if ( *currentRedditState )
{
v3 = 0LL;
while ( strcmp(*((const char **)v2 + 1), s2) )
{
v3 = v2;
if ( !*(_QWORD *)v2 )
return;
v2 = *(void **)v2;
}
if ( v3 )
*v3 = *(_QWORD *)v2;
else
*v1 = *(_QWORD *)v2;
func0(v2);
}
}
}

original_code:
__attribute__((visibility("default"))) void redditRemoveCookie(char *name)
{
    RedditCookieLink *prev = ((void *)0), *node;
    if (currentRedditState == ((void *)0)) return ;
    for(node = currentRedditState->base; node != ((void *)0); prev = node, node = node->next) {
        if (strcmp(node->name, name) == 0) {
            if (prev != ((void *)0))
                prev->next = node->next;
            else
                currentRedditState->base = node->next;
            redditCookieFree(node);
            break;
        }
    }
}

canonical_original_code:
void redditRemoveCookie(char *name)
{
    struct RedditCookieLink *prev = ((void *)0); struct RedditCookieLink *node;
    if (currentRedditState == ((void *)0)) return ;
    for(node = currentRedditState->base; node != ((void *)0); prev = node, node = node->next) {
        if (strcmp(node->name, name) == 0) {
            if (prev != ((void *)0))
                prev->next = node->next;
            else
                currentRedditState->base = node->next;
            redditCookieFree(node);
            break;
        }
    }
}

variable_types:
name
char *

user_defined_types: struct RedditCookieLink { struct RedditCookieLink *next; char *name; char *data; }


redditGetCookieString

decompiled_code:
char *redditGetCookieString()
{
char *v0; // rbx
__int64 *v1; // rbp
int v2; // er13
int v3; // er12

v0 = (char *)currentRedditState;
if ( currentRedditState )
{
v1 = (__int64 *)*currentRedditState;
if ( *currentRedditState )
{
v2 = 0;
v0 = 0LL;
do
{
v3 = strlen((const char *)v1[1]);
v2 += v3 + strlen((const char *)v1[2]) + 2;
v0 = (char *)rrealloc(v0, v2);
if ( (__int64 *)*currentRedditState == v1 )
*v0 = 0;
else
*(_WORD *)&v0[strlen(v0)] = 38;
strcat(v0, (const char *)v1[1]);
*(_WORD *)&v0[strlen(v0)] = 61;
strcat(v0, (const char *)v1[2]);
v1 = (__int64 *)*v1;
}
while ( v1 );
}
else
{
v0 = 0LL;
}
}
return v0;
}

canonical_decompiled_code:
char *func2()
{
char *v0; // rbx
__int64 *v1; // rbp
int v2; // er13
int v3; // er12

v0 = (char *)currentRedditState;
if ( currentRedditState )
{
v1 = (__int64 *)*currentRedditState;
if ( *currentRedditState )
{
v2 = 0;
v0 = 0LL;
do
{
v3 = strlen((const char *)v1[1]);
v2 += v3 + strlen((const char *)v1[2]) + 2;
v0 = (char *)rrealloc(v0, v2);
if ( (__int64 *)*currentRedditState == v1 )
*v0 = 0;
else
*(_WORD *)&v0[strlen(v0)] = 38;
strcat(v0, (const char *)v1[1]);
*(_WORD *)&v0[strlen(v0)] = 61;
strcat(v0, (const char *)v1[2]);
v1 = (__int64 *)*v1;
}
while ( v1 );
}
else
{
v0 = 0LL;
}
}
return v0;
}

original_code:
__attribute__((visibility("default"))) char *redditGetCookieString()
{
    char *cookieStr = ((void *)0);
    int currentLength = 0;
    RedditCookieLink *node;
    if (currentRedditState == ((void *)0)) return ((void *)0);
    for(node = currentRedditState->base; node != ((void *)0); node = node->next) {
        int add_size = strlen(node->name) + strlen(node->data) + 2;
        currentLength += add_size;
        cookieStr = rrealloc(cookieStr, currentLength);
        if (node != currentRedditState->base)
            strcat(cookieStr, "&");
        else
            cookieStr[0] = 0;
        strcat(cookieStr, node->name);
        strcat(cookieStr, "=");
        strcat(cookieStr, node->data);
    }
    return cookieStr;
}

canonical_original_code:
char *redditGetCookieString()
{
    char *cookieStr = ((void *)0);
    int currentLength = 0;
    struct RedditCookieLink *node;
    if (currentRedditState == ((void *)0)) return ((void *)0);
    for(node = currentRedditState->base; node != ((void *)0); node = node->next) {
        int add_size = strlen(node->name) + strlen(node->data) + 2;
        currentLength += add_size;
        cookieStr = rrealloc(cookieStr, currentLength);
        if (node != currentRedditState->base)
            strcat(cookieStr, "&");
        else
            cookieStr[0] = 0;
        strcat(cookieStr, node->name);
        strcat(cookieStr, "=");
        strcat(cookieStr, node->data);
    }
    return cookieStr;
}

variable_types:
cookieStr
char *

variable_types: currentLength int

return_type: char *


redditStateNew

decompiled_code:
_QWORD *redditStateNew()
{
_QWORD *result; // rax

result = (_QWORD *)rmalloc(16LL);
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = (_QWORD *)rmalloc(16LL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
__attribute__((visibility("default"))) RedditState *redditStateNew()
{
    RedditState *state;
    state = rmalloc(sizeof(RedditState));
    state->base = ((void *)0);
    state->userAgent = ((void *)0);
    return state;
}

canonical_original_code:
struct RedditState *redditStateNew()
{
    struct RedditState *state;
    state = rmalloc(sizeof(RedditState));
    state->base = ((void *)0);
    state->userAgent = ((void *)0);
    return state;
}

variable_types: struct RedditState { struct RedditCookieLink { struct RedditCookieLink *next; char *name; char *data; } *base; char *userAgent; } *

user_defined_types: struct RedditState { struct RedditCookieLink *base; char *userAgent; }


redditStateFree

decompiled_code:
void __fastcall redditStateFree(void *ptr)
{
_QWORD *v2; // rbx
_QWORD *v3; // rdi

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
redditCookieFree(v3);
}
while ( v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *v2; // rbx
_QWORD *v3; // rdi

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
redditCookieFree(v3);
}
while ( v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
__attribute__((visibility("default"))) void redditStateFree(RedditState *state)
{
    if (state == ((void *)0))
        return ;
    RedditCookieLink *tmp;
    RedditCookieLink *node;
    for(node = state->base; node != ((void *)0); node = tmp) {
        tmp = node->next;
        redditCookieFree(node);
    }
    free(state->userAgent);
    free(state);
}

canonical_original_code:
void redditStateFree(struct RedditState *state)
{
    if (state == ((void *)0))
        return ;
    struct RedditCookieLink *tmp;
    struct RedditCookieLink *node;
    for(node = state->base; node != ((void *)0); node = tmp) {
        tmp = node->next;
        redditCookieFree(node);
    }
    free(state->userAgent);
    free(state);
}


redditStateGet

decompiled_code:
__int64 redditStateGet()
{
return currentRedditState;
}

canonical_decompiled_code:
__int64 func2()
{
return currentRedditState;
}

original_code:
__attribute__((visibility("default"))) RedditState *redditStateGet()
{
    return currentRedditState;
}

canonical_original_code:
struct RedditState *redditStateGet()
{
    return currentRedditState;
}

return_type: struct RedditState { struct RedditCookieLink { struct RedditCookieLink *next; char *name; char *data; } *base; char *userAgent; } *


optReadString

original_code:
static optResponse optReadString (optParser *parser, optOption *option)
{
    parser->curopt++;
    strcpy(option->svalue, parser->argv[parser->curopt]);
    return OPT_CONTINUE;
}

canonical_original_code:
static enum optResponse optReadString(struct optParser *parser, struct optOption *option)
{
    parser->curopt++;
    strcpy(option->svalue, parser->argv[parser->curopt]);
    return OPT_CONTINUE;
}

variable_types: struct optParser { int argc; char **argv; int curopt; int optCount; struct optOption { char opt_long[-1]; char opt_short; enum optArgument { OPT_NONE=0, OPT_INT=1, OPT_STRING=2 } arg; char helpText[-1]; unsigned int isSet; int ivalue; char svalue[-1]; } **options; } *

variable_types:
option
struct optOption *

return_type: enum optResponse { OPT_SUCCESS=0, OPT_UNKNOWN=1, OPT_UNUSED=2, OPT_CONTINUE=3 }

user_defined_types: struct optParser { int argc; char **argv; int curopt; int optCount; struct optOption **options; }

user_defined_types: struct optOption { char opt_long[-1]; char opt_short; enum optArgument arg; char helpText[-1]; unsigned int isSet; int ivalue; char svalue[-1]; }


optReadInt

original_code:
static optResponse optReadInt (optParser *parser, optOption *option)
{
    parser->curopt++;
    option->ivalue = atoi(parser->argv[parser->curopt]);
    return OPT_CONTINUE;
}

canonical_original_code:
static enum optResponse optReadInt(struct optParser *parser, struct optOption *option)
{
    parser->curopt++;
    option->ivalue = atoi(parser->argv[parser->curopt]);
    return OPT_CONTINUE;
}

user_defined_types: enum optResponse { OPT_SUCCESS=0, OPT_UNKNOWN=1, OPT_UNUSED=2, OPT_CONTINUE=3 }

user_defined_types: enum optArgument { OPT_NONE=0, OPT_INT=1, OPT_STRING=2 }


optProcessOption

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

*(_BYTE *)(a2 + 437) |= 1u;
v2 = *(_DWORD *)(a2 + 32);
if ( v2 == 1 )
return optReadInt(a1, a2);
if ( v2 == 2 )
return optReadString(a1, a2);
return 3LL;
}

original_code:
static optResponse optProcessOption (optParser *parser, optOption *option)
{
    option->isSet = 1;
    switch (option->arg) {
    case OPT_INT:
        return optReadInt(parser, option);
    case OPT_STRING:
        return optReadString(parser, option);
    default:
        break;
    }
    return OPT_CONTINUE;
}

canonical_original_code:
static enum optResponse optProcessOption(struct optParser *parser, struct optOption *option)
{
    option->isSet = 1;
    switch (option->arg) {
    case OPT_INT:
        return optReadInt(parser, option);
    case OPT_STRING:
        return optReadString(parser, option);
    default:
        break;
    }
    return OPT_CONTINUE;
}


optParseLong

decompiled_code:
__int64 __fastcall optParseLong(__int64 a1)
{
const char **v1; // rbp
const char *v2; // rbx
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = *(const char ***)(a1 + 32);
strcpy(v4, (const char *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * *(int *)(a1 + 16)) + 2LL));
v2 = *v1;
if ( !*v1 )
return 1LL;
while ( strcmp(v2, v4) )
{
v2 = *++v1;
if ( !*v1 )
return 1LL;
}
return optProcessOption(a1, (__int64)v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
const char **v1; // rbp
const char *v2; // rbx
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = *(const char ***)(a1 + 32);
strcpy(v4, (const char *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * *(int *)(a1 + 16)) + 2LL));
v2 = *v1;
if ( !*v1 )
return 1LL;
while ( strcmp(v2, v4) )
{
v2 = *++v1;
if ( !*v1 )
return 1LL;
}
return func2(a1, (__int64)v2);
}

original_code:
static optResponse optParseLong (optParser *parser)
{
    optOption **option = parser->options;
    char str[30];
    strcpy(str, parser->argv[parser->curopt] + 2);
    for (; *option != ((void *)0); option++)
        if (strcmp((*option)->opt_long, str) == 0)
            return optProcessOption(parser, *option);
    if (*option == ((void *)0))
        return OPT_UNKNOWN;
    return OPT_CONTINUE;
}

canonical_original_code:
static enum optResponse optParseLong(struct optParser *parser)
{
    struct optOption **option = parser->options;
    char str[30];
    strcpy(str, parser->argv[parser->curopt] + 2);
    for (; *option != ((void *)0); option++)
        if (strcmp((*option)->opt_long, str) == 0)
            return optProcessOption(parser, *option);
    if (*option == ((void *)0))
        return OPT_UNKNOWN;
    return OPT_CONTINUE;
}

variable_types: struct optOption { char opt_long[-1]; char opt_short; enum optArgument { OPT_NONE=0, OPT_INT=1, OPT_STRING=2 } arg; char helpText[-1]; unsigned int isSet; int ivalue; char svalue[-1]; } **

variable_types:
str
char [30]


optCheckOpts

original_code:
static optResponse optCheckOpts (optParser *parser)
{
    optOption **option = parser->options;
    char c = parser->argv[parser->curopt][parser->offset];
    for (; *option != ((void *)0); option++)
        if ((*option)->opt_short == c)
            return optProcessOption(parser, *option);
    if (*option == ((void *)0))
        return OPT_UNKNOWN;
    return OPT_CONTINUE;
}

canonical_original_code:
static enum optResponse optCheckOpts(struct optParser *parser)
{
    struct optOption **option = parser->options;
    char c = parser->argv[parser->curopt][parser->offset];
    for (; *option != ((void *)0); option++)
        if ((*option)->opt_short == c)
            return optProcessOption(parser, *option);
    if (*option == ((void *)0))
        return OPT_UNKNOWN;
    return OPT_CONTINUE;
}

variable_types: c char


optParseChars

decompiled_code:
__int64 __fastcall optParseChars(__int64 a1)
{
int v1; // ebp
unsigned int v2; // edx
int v3; // eax

v1 = strlen(*(const char **)(*(_QWORD *)(a1 + 8) + 8LL * *(int *)(a1 + 16)));
*(_DWORD *)(a1 + 20) = 1;
if ( v1 <= 1 )
return 3;
do
{
v2 = optCheckOpts(a1);
if ( v2 != 3 )
break;
v3 = *(_DWORD *)(a1 + 20) + 1;
*(_DWORD *)(a1 + 20) = v3;
}
while ( v3 < v1 );
return v2;
}

original_code:
static optResponse optParseChars (optParser *parser)
{
    int len;
    optResponse res = OPT_CONTINUE;
    len = strlen(parser->argv[parser->curopt]);
    for (parser->offset = 1; parser->offset < len; parser->offset++) {
        res = optCheckOpts(parser);
        if (res != OPT_CONTINUE)
            break;
    }
    return res;
}

canonical_original_code:
static enum optResponse optParseChars(struct optParser *parser)
{
    int len;
    enum optResponse res = OPT_CONTINUE;
    len = strlen(parser->argv[parser->curopt]);
    for (parser->offset = 1; parser->offset < len; parser->offset++) {
        res = optCheckOpts(parser);
        if (res != OPT_CONTINUE)
            break;
    }
    return res;
}

variable_types: len int

variable_types: enum optResponse { OPT_SUCCESS=0, OPT_UNKNOWN=1, OPT_UNUSED=2, OPT_CONTINUE=3 }


optAddOptions

decompiled_code:
__int64 __fastcall optAddOptions(__int64 a1, __int64 a2, int a3)
{
int v5; // er13
__int64 result; // rax
int v7; // eax
void *v8; // rax

v5 = *(_DWORD *)(a1 + 24);
*(_DWORD *)(a1 + 24) = v5 + a3;
for ( result = (unsigned int)(v5 + a3 + 1);
(int)result >= *(_DWORD *)(a1 + 28);
result = (unsigned int)(*(_DWORD *)(a1 + 24) + 1) )
{
v7 = *(_DWORD *)(a1 + 28);
*(_DWORD *)(a1 + 28) = v7 + 100;
v8 = realloc(*(void **)(a1 + 32), 8LL * (v7 + 100));
*(_QWORD *)(a1 + 32) = v8;
memset(v8, 0, 0x320uLL);
}
if ( a3 > 0 )
{
result = 8LL * v5;
do
{
*(_QWORD *)(*(_QWORD *)(a1 + 32) + result) = a2;
result += 8LL;
a2 += 496LL;
}
while ( result != 8 * (v5 + (unsigned __int64)(unsigned int)(a3 - 1) + 1) );
}
return result;
}

original_code:
void optAddOptions (optParser *parser, optOption *options, int optionCount)
{
    const int blockSize = 100;
    int opt = parser->optCount, i;
    parser->optCount += optionCount;
    if (parser->optCount + 1 >= parser->optAllocCount) {
        do {
            parser->optAllocCount += blockSize;
            parser->options = realloc(parser->options, parser->optAllocCount * sizeof(optOption*));
            memset(parser->options, 0, blockSize * sizeof(optOption*));
        } while (parser->optCount + 1 >= parser->optAllocCount);
    }
    for (i = 0; i < optionCount; i++)
        parser->options[opt + i] = options + i;
}

canonical_original_code:
void optAddOptions(struct optParser *parser, struct optOption *options, int optionCount)
{
    int blockSize = 100;
    int opt = parser->optCount; int i;
    parser->optCount += optionCount;
    if (parser->optCount + 1 >= parser->optAllocCount) {
        do {
            parser->optAllocCount += blockSize;
            parser->options = realloc(parser->options, parser->optAllocCount * sizeof(struct optOption *));
            memset(parser->options, 0, blockSize * sizeof(struct optOption *));
        } while (parser->optCount + 1 >= parser->optAllocCount);
    }
    for (i = 0; i < optionCount; i++)
        parser->options[opt + i] = options + i;
}

variable_types:
options
struct optOption *

variable_types: optionCount int

variable_types: blockSize int

variable_types: opt int

variable_types: i int


optClearParser

decompiled_code:
void __fastcall optClearParser(__int64 a1)
{
free(*(void **)(a1 + 32));
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
free(*(void **)(a1 + 32));
}

original_code:
void optClearParser (optParser *parser)
{
    free(parser->options);
}

canonical_original_code:
void optClearParser(struct optParser *parser)
{
    free(parser->options);
}


optRunParser

decompiled_code:
__int64 __fastcall optRunParser(__int64 a1)
{
__int64 result; // rax
int v3; // edi
int v4; // er8
_BYTE *v5; // rdx

if ( !*(_QWORD *)(a1 + 32) )
return 0LL;
++*(_DWORD *)(a1 + 16);
result = 3LL;
LABEL_3:
v3 = *(_DWORD *)(a1 + 16);
v4 = *(_DWORD *)a1;
while ( (_DWORD)result == 3 && v3 != v4 )
{
v5 = *(_BYTE **)(*(_QWORD *)(a1 + 8) + 8LL * v3);
result = 2LL;
if ( *v5 == 45 )
{
if ( v5[1] == 45 )
result = optParseLong(a1);
else
result = optParseChars(a1);
++*(_DWORD *)(a1 + 16);
goto LABEL_3;
}
}
if ( v3 == v4 && (_DWORD)result == 3 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
int v3; // edi
int v4; // er8
_BYTE *v5; // rdx

if ( !*(_QWORD *)(a1 + 32) )
return 0LL;
++*(_DWORD *)(a1 + 16);
result = 3LL;
LABEL_3:
v3 = *(_DWORD *)(a1 + 16);
v4 = *(_DWORD *)a1;
while ( (_DWORD)result == 3 && v3 != v4 )
{
v5 = *(_BYTE **)(*(_QWORD *)(a1 + 8) + 8LL * v3);
result = 2LL;
if ( *v5 == 45 )
{
if ( v5[1] == 45 )
result = func3(a1);
else
result = func5(a1);
++*(_DWORD *)(a1 + 16);
goto LABEL_3;
}
}
if ( v3 == v4 && (_DWORD)result == 3 )
result = 0LL;
return result;
}

original_code:
optResponse optRunParser (optParser *parser)
{
    optResponse res = OPT_CONTINUE;
    if (parser->options == ((void *)0))
        return OPT_SUCCESS;
    parser->curopt++;
    while ((parser->curopt != parser->argc) && res == OPT_CONTINUE) {
        if ((parser->argv)[parser->curopt][0] == '-') {
            if (parser->argv[parser->curopt][1] == '-')
                res = optParseLong(parser);
            else
                res = optParseChars(parser);
            parser->curopt++;
        } else {
            res = OPT_UNUSED;
        }
    }
    if (parser->curopt == parser->argc && res == OPT_CONTINUE)
        res = OPT_SUCCESS;
    return res;
}

canonical_original_code:
enum optResponse optRunParser(struct optParser *parser)
{
    enum optResponse res = OPT_CONTINUE;
    if (parser->options == ((void *)0))
        return OPT_SUCCESS;
    parser->curopt++;
    while ((parser->curopt != parser->argc) && res == OPT_CONTINUE) {
        if ((parser->argv)[parser->curopt][0] == '-') {
            if (parser->argv[parser->curopt][1] == '-')
                res = optParseLong(parser);
            else
                res = optParseChars(parser);
            parser->curopt++;
        } else {
            res = OPT_UNUSED;
        }
    }
    if (parser->curopt == parser->argc && res == OPT_CONTINUE)
        res = OPT_SUCCESS;
    return res;
}


decompiled_code:
__int64 __fastcall jsmn_alloc_token(__int64 a1, __int64 a2, unsigned __int64 a3)
{
int v3; // eax
__int64 result; // rax

v3 = *(_DWORD *)(a1 + 4);
if ( v3 >= a3 )
return 0LL;
*(_DWORD *)(a1 + 4) = v3 + 1;
result = a2 + 28LL * v3;
*(_DWORD *)(result + 8) = -1;
*(_DWORD *)(result + 4) = -1;
*(_DWORD *)(result + 12) = 0;
*(_BYTE *)(result + 16) &= 0xFEu;
*(_DWORD *)(result + 24) = -1;
*(_DWORD *)(result + 20) = 0;
return result;
}

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

v3 = *(_DWORD *)(a1 + 4);
if ( v3 >= a3 )
return 0LL;
*(_DWORD *)(a1 + 4) = v3 + 1;
result = a2 + 28LL * v3;
*(_DWORD *)(result + 8) = -1;
*(_DWORD *)(result + 4) = -1;
*(_DWORD *)(result + 12) = 0;
*(_BYTE *)(result + 16) &= 0xFEu;
*(_DWORD *)(result + 24) = -1;
*(_DWORD *)(result + 20) = 0;
return result;
}

original_code:
static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser,
  jsmntok_t *tokens, size_t num_tokens) {
 jsmntok_t *tok;
 if (parser->toknext >= num_tokens) {
  return ((void *)0);
 }
 tok = &tokens[parser->toknext++];
 tok->start = tok->end = -1;
 tok->size = 0;
 tok->is_key = 0;
 tok->parent = -1;
 tok->full_size = 0;
 return tok;
}

canonical_original_code:
static struct jsmntok_t *jsmn_alloc_token(struct jsmn_parser *parser, struct jsmntok_t *tokens, unsigned long num_tokens) {
 struct jsmntok_t *tok;
 if (parser->toknext >= num_tokens) {
  return ((void *)0);
 }
 tok = &tokens[parser->toknext++];
 tok->start = tok->end = -1;
 tok->size = 0;
 tok->is_key = 0;
 tok->parent = -1;
 tok->full_size = 0;
 return tok;
}

variable_types: struct jsmn_parser { unsigned int pos; int toknext; int toksuper; } *

variable_types:
tokens
struct jsmntok_t *

variable_types: struct jsmntok_t { enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 } type; int start; int end; int size; unsigned int is_key; int full_size; int parent; } *

user_defined_types: struct jsmntok_t { enum jsmntype_t type; int start; int end; int size; unsigned int is_key; int full_size; int parent; }


decompiled_code:
__int64 __fastcall jsmn_fill_token(__int64 a1, int a2, int a3, int a4, char a5)
{
__int64 result; // rax

*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = a3;
*(_DWORD *)(a1 + 8) = a4;
*(_DWORD *)(a1 + 12) = 0;
result = a5 & 1;
*(_BYTE *)(a1 + 16) = result | *(_BYTE *)(a1 + 16) & 0xFE;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3, int a4, char a5)
{
__int64 result; // rax

*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = a3;
*(_DWORD *)(a1 + 8) = a4;
*(_DWORD *)(a1 + 12) = 0;
result = a5 & 1;
*(_BYTE *)(a1 + 16) = result | *(_BYTE *)(a1 + 16) & 0xFE;
return result;
}

original_code:
static void jsmn_fill_token(jsmntok_t *token, jsmntype_t type,
                            int start, int end, int on_key) {
 token->type = type;
 token->start = start;
 token->end = end;
 token->size = 0;
 token->is_key = on_key;
}

canonical_original_code:
static void jsmn_fill_token(struct jsmntok_t *token, enum jsmntype_t type, int start, int end, int on_key) {
 token->type = type;
 token->start = start;
 token->end = end;
 token->size = 0;
 token->is_key = on_key;
}

variable_types: enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 }

variable_types: start int

variable_types: end int


decompiled_code:
__int64 __fastcall jsmn_parse_primitive(int *a1, __int64 a2, __int64 a3, char a4, unsigned __int64 a5)
{
int v6; // ebp
char v7; // cl
unsigned int v8; // eax
__int64 v9; // rax
__int64 v10; // r13
__int64 result; // rax

v6 = *a1;
v7 = *(_BYTE *)(a2 + (unsigned int)*a1);
if ( !v7 )
{
LABEL_12:
*a1 = v6;
return 4294967293LL;
}
v8 = v6 + 1;
while ( v7 > 44 )
{
if ( (v7 & 0xDF) == 93 )
goto LABEL_9;
LABEL_4:
if ( (unsigned __int8)(v7 - 32) > 0x5Eu )
{
*a1 = v6;
return 4294967294LL;
}
*a1 = v8;
v7 = *(_BYTE *)(a2 + v8++);
if ( !v7 )
goto LABEL_12;
}
if ( v7 <= 8 || ((1LL << v7) & 0x100100002600LL) == 0 )
goto LABEL_4;
LABEL_9:
v9 = jsmn_alloc_token((__int64)a1, a3, a5);
v10 = v9;
if ( v9 )
{
jsmn_fill_token(v9, 0, v6, *a1, a4);
*(_DWORD *)(v10 + 24) = a1[2];
--*a1;
result = 0LL;
}
else
{
*a1 = v6;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static jsmnerr_t jsmn_parse_primitive(jsmn_parser *parser, const char *js,
  jsmntok_t *tokens, int on_key, size_t num_tokens) {
 jsmntok_t *token;
 int start;
 start = parser->pos;
 for (; js[parser->pos] != '\0'; parser->pos++) {
  switch (js[parser->pos]) {
   case '\t' : case '\r' : case '\n' : case ' ' :
   case ',' : case ']' : case '}' :
    goto found;
  }
  if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
   parser->pos = start;
   return JSMN_ERROR_INVAL;
  }
 }
 parser->pos = start;
 return JSMN_ERROR_PART;
found:
 token = jsmn_alloc_token(parser, tokens, num_tokens);
 if (token == ((void *)0)) {
  parser->pos = start;
  return JSMN_ERROR_NOMEM;
 }
 jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos, on_key);
 token->parent = parser->toksuper;
 parser->pos--;
 return JSMN_SUCCESS;
}

canonical_original_code:
static enum jsmnerr_t jsmn_parse_primitive(struct jsmn_parser *parser, char *js, struct jsmntok_t *tokens, int on_key, unsigned long num_tokens) {
 struct jsmntok_t *token;
 int start;
 start = parser->pos;
 for (; js[parser->pos] != '\0'; parser->pos++) {
  switch (js[parser->pos]) {
   case '\t' : case '\r' : case '\n' : case ' ' :
   case ',' : case ']' : case '}' :
    goto found;
  }
  if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
   parser->pos = start;
   return JSMN_ERROR_INVAL;
  }
 }
 parser->pos = start;
 return JSMN_ERROR_PART;
found:
 token = jsmn_alloc_token(parser, tokens, num_tokens);
 if (token == ((void *)0)) {
  parser->pos = start;
  return JSMN_ERROR_NOMEM;
 }
 jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos, on_key);
 token->parent = parser->toksuper;
 parser->pos--;
 return JSMN_SUCCESS;
}

variable_types:
js
char *

return_type: enum jsmnerr_t { JSMN_ERROR_NOMEM=-1, JSMN_ERROR_INVAL=-2, JSMN_ERROR_PART=-3, JSMN_SUCCESS=0 }

user_defined_types: struct jsmn_parser { unsigned int pos; int toknext; int toksuper; }

user_defined_types: enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 }


decompiled_code:
__int64 __fastcall jsmn_parse_string(int *a1, __int64 a2, __int64 a3, char a4, unsigned __int64 a5)
{
int v7; // ebp
unsigned int v8; // eax
char v9; // dl
__int64 v11; // rax
__int64 v12; // r13
__int64 result; // rax
unsigned int v14; // eax
char v15; // al

v7 = *a1;
v8 = v7 + 1;
++*a1;
v9 = *(_BYTE *)(a2 + (unsigned int)(v7 + 1));
if ( v9 )
{
while ( v9 != 34 )
{
if ( v9 == 92 )
{
v14 = v8 + 1;
*a1 = v14;
v15 = *(_BYTE *)(a2 + v14);
if ( v15 > 117 )
goto LABEL_14;
if ( v15 > 91 )
{
switch ( v15 )
{
case '\\':
case 'b':
case 'f':
case 'n':
case 'r':
case 't':
case 'u':
goto LABEL_8;
default:
goto LABEL_14;
}
}
if ( v15 != 34 && v15 != 47 )
{
LABEL_14:
*a1 = v7;
return 4294967294LL;
}
}
LABEL_8:
v8 = *a1 + 1;
*a1 = v8;
v9 = *(_BYTE *)(a2 + v8);
if ( !v9 )
goto LABEL_15;
}
v11 = jsmn_alloc_token((__int64)a1, a3, a5);
v12 = v11;
if ( v11 )
{
jsmn_fill_token(v11, 3, v7 + 1, *a1, a4);
*(_DWORD *)(v12 + 24) = a1[2];
result = 0LL;
}
else
{
*a1 = v7;
result = 0xFFFFFFFFLL;
}
}
else
{
LABEL_15:
*a1 = v7;
result = 4294967293LL;
}
return result;
}

original_code:
static jsmnerr_t jsmn_parse_string(jsmn_parser *parser, const char *js,
  jsmntok_t *tokens, int on_key, size_t num_tokens) {
 jsmntok_t *token;
 int start = parser->pos;
 parser->pos++;
 for (; js[parser->pos] != '\0'; parser->pos++) {
  char c = js[parser->pos];
  if (c == '\"') {
   token = jsmn_alloc_token(parser, tokens, num_tokens);
   if (token == ((void *)0)) {
    parser->pos = start;
    return JSMN_ERROR_NOMEM;
   }
   jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos, on_key);
   token->parent = parser->toksuper;
   return JSMN_SUCCESS;
  }
  if (c == '\\') {
   parser->pos++;
   switch (js[parser->pos]) {
    case '\"': case '/' : case '\\' : case 'b' :
    case 'f' : case 'r' : case 'n' : case 't' :
     break;
    case 'u':
     break;
    default:
     parser->pos = start;
     return JSMN_ERROR_INVAL;
   }
  }
 }
 parser->pos = start;
 return JSMN_ERROR_PART;
}

canonical_original_code:
static enum jsmnerr_t jsmn_parse_string(struct jsmn_parser *parser, char *js, struct jsmntok_t *tokens, int on_key, unsigned long num_tokens) {
 struct jsmntok_t *token;
 int start = parser->pos;
 parser->pos++;
 for (; js[parser->pos] != '\0'; parser->pos++) {
  char c = js[parser->pos];
  if (c == '\"') {
   token = jsmn_alloc_token(parser, tokens, num_tokens);
   if (token == ((void *)0)) {
    parser->pos = start;
    return JSMN_ERROR_NOMEM;
   }
   jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos, on_key);
   token->parent = parser->toksuper;
   return JSMN_SUCCESS;
  }
  if (c == '\\') {
   parser->pos++;
   switch (js[parser->pos]) {
    case '\"': case '/' : case '\\' : case 'b' :
    case 'f' : case 'r' : case 'n' : case 't' :
     break;
    case 'u':
     break;
    default:
     parser->pos = start;
     return JSMN_ERROR_INVAL;
   }
  }
 }
 parser->pos = start;
 return JSMN_ERROR_PART;
}

user_defined_types: enum jsmnerr_t { JSMN_ERROR_NOMEM=-1, JSMN_ERROR_INVAL=-2, JSMN_ERROR_PART=-3, JSMN_SUCCESS=0 }


original_code:
jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, jsmntok_t *tokens,
  unsigned int num_tokens) {
 jsmnerr_t r;
 int i;
 int k;
 int on_key = 1;
 jsmntok_t *token;
 for (; js[parser->pos] != '\0'; parser->pos++) {
  char c;
  jsmntype_t type;
  c = js[parser->pos];
  switch (c) {
   case '{': case '[':
    token = jsmn_alloc_token(parser, tokens, num_tokens);
    if (token == ((void *)0))
     return JSMN_ERROR_NOMEM;
    token->is_key = 0;
    if (parser->toksuper != -1) {
     tokens[parser->toksuper].size++;
     token->parent = parser->toksuper;
    }
    token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
    token->start = parser->pos;
    parser->toksuper = parser->toknext - 1;
    on_key = 1;
    break;
   case '}': case ']':
    type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
    if (parser->toknext < 1) {
     return JSMN_ERROR_INVAL;
    }
    token = &tokens[parser->toknext - 1];
    for (;;) {
     if (token->start != -1 && token->end == -1) {
      if (token->type != type) {
       return JSMN_ERROR_INVAL;
      }
      token->end = parser->pos + 1;
      parser->toksuper = token->parent;
      break;
     }
     if (token->parent == -1) {
      break;
     }
     token = &tokens[token->parent];
    }
    on_key = 1;
    break;
   case '\"':
    r = jsmn_parse_string(parser, js, tokens, on_key, num_tokens);
    if (r < 0) return r;
    if (parser->toksuper != -1)
     tokens[parser->toksuper].size++;
    break;
   case ':':
    on_key = 0;
    break;
   case ',':
    on_key = 1;
    break;
   case '\t' : case '\r' : case '\n' : case ' ':
    break;
   case '-': case '0': case '1' : case '2': case '3' : case '4':
   case '5': case '6': case '7' : case '8': case '9':
   case 't': case 'f': case 'n' :
    r = jsmn_parse_primitive(parser, js, tokens, on_key, num_tokens);
    if (r < 0) return r;
    if (parser->toksuper != -1)
     tokens[parser->toksuper].size++;
    break;
   default:
    return JSMN_ERROR_INVAL;
  }
 }
 for (i = parser->toknext - 1; i >= 0; i--) {
  if (tokens[i].start != -1 && tokens[i].end == -1) {
   return JSMN_ERROR_PART;
  }
  if (tokens[i].type == JSMN_OBJECT || tokens[i].type == JSMN_ARRAY) {
   tokens[i].full_size += tokens[i].size;
   for (k = tokens[i].parent; k != -1; k = tokens[k].parent) {
    tokens[k].full_size += tokens[i].size;
   }
  }
 }
 return JSMN_SUCCESS;
}

canonical_original_code:
enum jsmnerr_t jsmn_parse(struct jsmn_parser *parser, char *js, struct jsmntok_t *tokens, unsigned int num_tokens) {
 enum jsmnerr_t r;
 int i;
 int k;
 int on_key = 1;
 struct jsmntok_t *token;
 for (; js[parser->pos] != '\0'; parser->pos++) {
  char c;
  enum jsmntype_t type;
  c = js[parser->pos];
  switch (c) {
   case '{': case '[':
    token = jsmn_alloc_token(parser, tokens, num_tokens);
    if (token == ((void *)0))
     return JSMN_ERROR_NOMEM;
    token->is_key = 0;
    if (parser->toksuper != -1) {
     tokens[parser->toksuper].size++;
     token->parent = parser->toksuper;
    }
    token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
    token->start = parser->pos;
    parser->toksuper = parser->toknext - 1;
    on_key = 1;
    break;
   case '}': case ']':
    type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
    if (parser->toknext < 1) {
     return JSMN_ERROR_INVAL;
    }
    token = &tokens[parser->toknext - 1];
    for (;;) {
     if (token->start != -1 && token->end == -1) {
      if (token->type != type) {
       return JSMN_ERROR_INVAL;
      }
      token->end = parser->pos + 1;
      parser->toksuper = token->parent;
      break;
     }
     if (token->parent == -1) {
      break;
     }
     token = &tokens[token->parent];
    }
    on_key = 1;
    break;
   case '\"':
    r = jsmn_parse_string(parser, js, tokens, on_key, num_tokens);
    if (r < 0) return r;
    if (parser->toksuper != -1)
     tokens[parser->toksuper].size++;
    break;
   case ':':
    on_key = 0;
    break;
   case ',':
    on_key = 1;
    break;
   case '\t' : case '\r' : case '\n' : case ' ':
    break;
   case '-': case '0': case '1' : case '2': case '3' : case '4':
   case '5': case '6': case '7' : case '8': case '9':
   case 't': case 'f': case 'n' :
    r = jsmn_parse_primitive(parser, js, tokens, on_key, num_tokens);
    if (r < 0) return r;
    if (parser->toksuper != -1)
     tokens[parser->toksuper].size++;
    break;
   default:
    return JSMN_ERROR_INVAL;
  }
 }
 for (i = parser->toknext - 1; i >= 0; i--) {
  if (tokens[i].start != -1 && tokens[i].end == -1) {
   return JSMN_ERROR_PART;
  }
  if (tokens[i].type == JSMN_OBJECT || tokens[i].type == JSMN_ARRAY) {
   tokens[i].full_size += tokens[i].size;
   for (k = tokens[i].parent; k != -1; k = tokens[k].parent) {
    tokens[k].full_size += tokens[i].size;
   }
  }
 }
 return JSMN_SUCCESS;
}

variable_types: enum jsmnerr_t { JSMN_ERROR_NOMEM=-1, JSMN_ERROR_INVAL=-2, JSMN_ERROR_PART=-3, JSMN_SUCCESS=0 }

variable_types: k int


rmalloc

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

result = malloc(a1);
if ( !result )
exit(1);
return result;
}

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

result = malloc(a1);
if ( !result )
exit(1);
return result;
}

original_code:
void *rmalloc(size_t bytes)
{
    void *m = malloc(bytes);
    if (m == ((void *)0))
        exit(1);
    return m;
}

canonical_original_code:
void *rmalloc(unsigned long bytes)
{
    void *m = malloc(bytes);
    if (m == ((void *)0))
        exit(1);
    return m;
}

variable_types:
bytes
unsigned long

variable_types:
m
void *

return_type: void *


rrealloc

decompiled_code:
void *__fastcall rrealloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
exit(1);
return result;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
exit(1);
return result;
}

original_code:
void *rrealloc(void *old, size_t bytes)
{
    void *m = realloc(old, bytes);
    if (m == ((void *)0))
        exit(1);
    return m;
}

canonical_original_code:
void *rrealloc(void *old, unsigned long bytes)
{
    void *m = realloc(old, bytes);
    if (m == ((void *)0))
        exit(1);
    return m;
}

variable_types:
old
void *


redditGlobalInit

decompiled_code:
__int64 redditGlobalInit()
{
return curl_global_init(3LL);
}

canonical_decompiled_code:
__int64 func2()
{
return curl_global_init(3LL);
}

original_code:
__attribute__((visibility("default"))) void redditGlobalInit()
{
    curl_global_init(((1<<0)|(1<<1)));
    do { ; } while (0);
}


redditGlobalCleanup

decompiled_code:
__int64 redditGlobalCleanup()
{
return curl_global_cleanup();
}

canonical_decompiled_code:
__int64 func3()
{
return curl_global_cleanup();
}

original_code:
__attribute__((visibility("default"))) void redditGlobalCleanup()
{
    curl_global_cleanup();
    do { ; } while (0);
}


redditLinkNew

decompiled_code:
_QWORD *redditLinkNew()
{
_QWORD *v0; // rdx

v0 = (_QWORD *)rmalloc(128LL);
*v0 = 0LL;
v0[15] = 0LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 128) >> 3));
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rdx

v0 = (_QWORD *)rmalloc(128LL);
*v0 = 0LL;
v0[15] = 0LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 128) >> 3));
return v0;
}

original_code:
__attribute__((visibility("default"))) RedditLink *redditLinkNew ()
{
    RedditLink *link = rmalloc(sizeof(RedditLink));
    memset(link, 0, sizeof(RedditLink));
    return link;
}

canonical_original_code:
struct RedditLink *redditLinkNew()
{
    struct RedditLink *link = rmalloc(sizeof(RedditLink));
    memset(link, 0, sizeof(RedditLink));
    return link;
}

variable_types: struct RedditLink { struct RedditLink *next; char *id; char *permalink; char *author; char *url; char *title; char *selftext; char *titleEsc; char *selftextEsc; int *wtitleEsc; int *wselftextEsc; int score; int downs; int ups; int numComments; int numReports; char *created_utc; unsigned int flags; unsigned int advance; } *


redditLinkFree

decompiled_code:
void __fastcall redditLinkFree(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 6));
free(*((void **)ptr + 5));
free(*((void **)ptr + 8));
free(*((void **)ptr + 7));
free(*((void **)ptr + 10));
free(*((void **)ptr + 9));
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 6));
free(*((void **)ptr + 5));
free(*((void **)ptr + 8));
free(*((void **)ptr + 7));
free(*((void **)ptr + 10));
free(*((void **)ptr + 9));
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}
}

original_code:
__attribute__((visibility("default"))) void redditLinkFree (RedditLink *link)
{
    if (link == ((void *)0))
        return ;
    free(link->selftext);
    free(link->title);
    free(link->selftextEsc);
    free(link->titleEsc);
    free(link->wselftextEsc);
    free(link->wtitleEsc);
    free(link->id);
    free(link->permalink);
    free(link->author);
    free(link->url);
    free(link);
}

canonical_original_code:
void redditLinkFree(struct RedditLink *link)
{
    if (link == ((void *)0))
        return ;
    free(link->selftext);
    free(link->title);
    free(link->selftextEsc);
    free(link->titleEsc);
    free(link->wselftextEsc);
    free(link->wtitleEsc);
    free(link->id);
    free(link->permalink);
    free(link->author);
    free(link->url);
    free(link);
}

user_defined_types: struct RedditLink { struct RedditLink *next; char *id; char *permalink; char *author; char *url; char *title; char *selftext; char *titleEsc; char *selftextEsc; int *wtitleEsc; int *wselftextEsc; int score; int downs; int ups; int numComments; int numReports; char *created_utc; unsigned int flags; unsigned int advance; }


redditLinkListNew

decompiled_code:
_QWORD *redditLinkListNew()
{
_QWORD *result; // rax

result = (_QWORD *)rmalloc(40LL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *result; // rax

result = (_QWORD *)rmalloc(40LL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
return result;
}

original_code:
__attribute__((visibility("default"))) RedditLinkList *redditLinkListNew()
{
    RedditLinkList *list = rmalloc(sizeof(RedditLinkList));
    memset(list, 0, sizeof(RedditLinkList));
    return list;
}

canonical_original_code:
struct RedditLinkList *redditLinkListNew()
{
    struct RedditLinkList *list = rmalloc(sizeof(RedditLinkList));
    memset(list, 0, sizeof(RedditLinkList));
    return list;
}

variable_types: struct RedditLinkList { char *subreddit; char *modhash; enum RedditListType { REDDIT_HOT=0, REDDIT_NEW=1, REDDIT_RISING=2, REDDIT_CONTR=3, REDDIT_TOP=4 } type; int linkCount; struct RedditLink { struct RedditLink *next; char *id; char *permalink; char *author; char *url; char *title; char *selftext; char *titleEsc; char *selftextEsc; int *wtitleEsc; int *wselftextEsc; int score; int downs; int ups; int numComments; int numReports; char *created_utc; unsigned int flags; unsigned int advance; } **links; char *afterId; } *

user_defined_types: struct RedditLinkList { char *subreddit; char *modhash; enum RedditListType type; int linkCount; struct RedditLink **links; char *afterId; }


redditLinkListFreeLinks

original_code:
__attribute__((visibility("default"))) void redditLinkListFreeLinks (RedditLinkList *list)
{
    int i;
    if (list == ((void *)0))
        return ;
    for (i = 0; i < list->linkCount; i++)
        redditLinkFree(list->links[i]);
    free(list->links);
    list->links = ((void *)0);
    list->linkCount = 0;
}

canonical_original_code:
void redditLinkListFreeLinks(struct RedditLinkList *list)
{
    int i;
    if (list == ((void *)0))
        return ;
    for (i = 0; i < list->linkCount; i++)
        redditLinkFree(list->links[i]);
    free(list->links);
    list->links = ((void *)0);
    list->linkCount = 0;
}

user_defined_types: enum RedditListType { REDDIT_HOT=0, REDDIT_NEW=1, REDDIT_RISING=2, REDDIT_CONTR=3, REDDIT_TOP=4 }


redditLinkListFree

decompiled_code:
void __fastcall redditLinkListFree(void *ptr)
{
if ( ptr )
{
redditLinkListFreeLinks((__int64)ptr);
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 4));
free(ptr);
}
}

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

original_code:
__attribute__((visibility("default"))) void redditLinkListFree (RedditLinkList *list)
{
    if (list == ((void *)0))
        return ;
    redditLinkListFreeLinks(list);
    free(list->subreddit);
    free(list->modhash);
    free(list->afterId);
    free(list);
}

canonical_original_code:
void redditLinkListFree(struct RedditLinkList *list)
{
    if (list == ((void *)0))
        return ;
    redditLinkListFreeLinks(list);
    free(list->subreddit);
    free(list->modhash);
    free(list->afterId);
    free(list);
}


redditLinkListAddLink

decompiled_code:
__int64 __fastcall redditLinkListAddLink(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 20);
*(_DWORD *)(a1 + 20) = v2 + 1;
result = rrealloc(*(_QWORD *)(a1 + 24), 8LL * (v2 + 1));
*(_QWORD *)(a1 + 24) = result;
*(_QWORD *)(result + 8LL * *(int *)(a1 + 20) - 8) = a2;
return result;
}

original_code:
__attribute__((visibility("default"))) void redditLinkListAddLink (RedditLinkList *list, RedditLink *link)
{
    list->linkCount++;
    list->links = rrealloc(list->links, list->linkCount * sizeof(RedditLink*));
    list->links[list->linkCount - 1] = link;
}

canonical_original_code:
void redditLinkListAddLink(struct RedditLinkList *list, struct RedditLink *link)
{
    list->linkCount++;
    list->links = rrealloc(list->links, list->linkCount * sizeof(struct RedditLink *));
    list->links[list->linkCount - 1] = link;
}

variable_types:
link
struct RedditLink *


redditGetListing

decompiled_code:
__int64 __fastcall redditGetListing(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebx
size_t v4; // rax
__int64 v5[35]; // [rsp+0h] [rbp-538h] BYREF
void *ptr; // [rsp+118h] [rbp-420h] BYREF
char dest[1048]; // [rsp+120h] [rbp-418h] BYREF

ptr = 0LL;
memset(v5, 0, sizeof(v5));
v5[0] = (__int64)"modhash";
LODWORD(v5[1]) = 2;
v5[2] = a1 + 8;
BYTE4(v5[5]) = 1;
v5[7] = (__int64)"kind";
LODWORD(v5[8]) = 2;
v5[9] = (__int64)&ptr;
BYTE4(v5[12]) = 1;
v5[14] = (__int64)"data";
v5[15] = 0x200000003LL;
v5[20] = (__int64)getListingHelper;
v5[21] = (__int64)"after";
LODWORD(v5[22]) = 2;
v5[23] = a1 + 32;
BYTE4(v5[26]) = 1;
strcpy(dest, "http://www.reddit.com");
if ( *(_QWORD *)a1 )
strcat(dest, *(const char **)a1);
v1 = *(_DWORD *)(a1 + 16);
switch ( v1 )
{
case 1:
strcat(dest, "/new");
break;
case 2:
*(_QWORD *)&dest[strlen(dest)] = 0x676E697369722FLL;
break;
case 3:
strcat(dest, "/controversial");
break;
case 4:
strcat(dest, "/top");
break;
}
strcat(dest, ".json");
if ( *(int *)(a1 + 20) > 0 )
{
v4 = strlen(dest);
sprintf(&dest[v4], "?after=%s", *(const char **)(a1 + 32));
}
v2 = redditRunParser(dest, 0LL, v5, a1);
free(ptr);
if ( v2 )
v2 = 2;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebx
size_t v4; // rax
__int64 v5[35]; // [rsp+0h] [rbp-538h] BYREF
void *ptr; // [rsp+118h] [rbp-420h] BYREF
char dest[1048]; // [rsp+120h] [rbp-418h] BYREF

ptr = 0LL;
memset(v5, 0, sizeof(v5));
v5[0] = (__int64)"modhash";
LODWORD(v5[1]) = 2;
v5[2] = a1 + 8;
BYTE4(v5[5]) = 1;
v5[7] = (__int64)"kind";
LODWORD(v5[8]) = 2;
v5[9] = (__int64)&ptr;
BYTE4(v5[12]) = 1;
v5[14] = (__int64)"data";
v5[15] = 0x200000003LL;
v5[20] = (__int64)getListingHelper;
v5[21] = (__int64)"after";
LODWORD(v5[22]) = 2;
v5[23] = a1 + 32;
BYTE4(v5[26]) = 1;
strcpy(dest, "http://www.reddit.com");
if ( *(_QWORD *)a1 )
strcat(dest, *(const char **)a1);
v1 = *(_DWORD *)(a1 + 16);
switch ( v1 )
{
case 1:
strcat(dest, "/new");
break;
case 2:
*(_QWORD *)&dest[strlen(dest)] = 0x676E697369722FLL;
break;
case 3:
strcat(dest, "/controversial");
break;
case 4:
strcat(dest, "/top");
break;
}
strcat(dest, ".json");
if ( *(int *)(a1 + 20) > 0 )
{
v4 = strlen(dest);
sprintf(&dest[v4], "?after=%s", *(const char **)(a1 + 32));
}
v2 = redditRunParser(dest, 0LL, v5, a1);
free(ptr);
if ( v2 )
v2 = 2;
return v2;
}

original_code:
__attribute__((visibility("default"))) RedditErrno redditGetListing (RedditLinkList *list)
{
    char subred[1024], *kindStr = ((void *)0);
    TokenParserResult res;
    TokenIdent ids[] = {
        {.name = "modhash", .type = TOKEN_STRING, .action = TOKEN_SET, .value = &(list->modhash), .freeFlag = 1},
        {.name = "kind", .type = TOKEN_STRING, .action = TOKEN_SET, .value = &(kindStr), .freeFlag = 1},
        {.name = "data", .type = TOKEN_OBJECT, .action = TOKEN_CHECK_CALL, .funcCallback = &(getListingHelper)},
        {.name = "after", .type = TOKEN_STRING, .action = TOKEN_SET, .value = &(list->afterId), .freeFlag = 1},
        {0}
    };
    strcpy(subred, "http://www.reddit.com");
    if (list->subreddit != ((void *)0))
        strcat(subred, list->subreddit);
    if (list->type == REDDIT_NEW)
        strcat(subred, "/new");
    else if (list->type == REDDIT_RISING)
        strcat(subred, "/rising");
    else if (list->type == REDDIT_CONTR)
        strcat(subred, "/controversial");
    else if (list->type == REDDIT_TOP)
        strcat(subred, "/top");
    strcat(subred, ".json");
    if (list->linkCount > 0)
        sprintf(subred + strlen(subred), "?after=%s", list->afterId);
    res = redditRunParser(subred, ((void *)0), ids, list);
    free(kindStr);
    if (res == TOKEN_PARSER_SUCCESS)
        return REDDIT_SUCCESS;
    else
        return REDDIT_ERROR_RESPONSE;
}

canonical_original_code:
enum RedditErrno redditGetListing(struct RedditLinkList *list)
{
    char subred[1024]; char *kindStr = ((void *)0);
    enum TokenParserResult res;
    struct TokenIdent ids[] = {
        {.name = "modhash", .type = TOKEN_STRING, .action = TOKEN_SET, .value = &(list->modhash), .freeFlag = 1},
        {.name = "kind", .type = TOKEN_STRING, .action = TOKEN_SET, .value = &(kindStr), .freeFlag = 1},
        {.name = "data", .type = TOKEN_OBJECT, .action = TOKEN_CHECK_CALL, .funcCallback = &(getListingHelper)},
        {.name = "after", .type = TOKEN_STRING, .action = TOKEN_SET, .value = &(list->afterId), .freeFlag = 1},
        {0}
    };
    strcpy(subred, "http://www.reddit.com");
    if (list->subreddit != ((void *)0))
        strcat(subred, list->subreddit);
    if (list->type == REDDIT_NEW)
        strcat(subred, "/new");
    else if (list->type == REDDIT_RISING)
        strcat(subred, "/rising");
    else if (list->type == REDDIT_CONTR)
        strcat(subred, "/controversial");
    else if (list->type == REDDIT_TOP)
        strcat(subred, "/top");
    strcat(subred, ".json");
    if (list->linkCount > 0)
        sprintf(subred + strlen(subred), "?after=%s", list->afterId);
    res = redditRunParser(subred, ((void *)0), ids, list);
    free(kindStr);
    if (res == TOKEN_PARSER_SUCCESS)
        return REDDIT_SUCCESS;
    else
        return REDDIT_ERROR_RESPONSE;
}

variable_types:
subred
char [1024]

variable_types:
kindStr
char *

variable_types: enum TokenParserResult { TOKEN_PARSER_SUCCESS=0, TOKEN_PARSER_CURL_FAIL=1, TOKEN_PARSER_JSON_FAIL=2 }

variable_types: struct TokenIdent { char *name; enum { TOKEN_BOOL=0, TOKEN_INT=1, TOKEN_STRING=2, TOKEN_OBJECT=3, TOKEN_DATE=4 } type; enum { TOKEN_SET=0, TOKEN_SET_PARSE=1, TOKEN_CHECK_CALL=2 } action; void *value; char **parseStr; int **parseStrWide; unsigned int bitMask; _Bool freeFlag; void (*funcCallback)(struct TokenParser { struct MemoryBlock { char *memory; unsigned long size; } *block; struct jsmntok_t { enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 } type; int start; int end; int size; unsigned int is_key; int full_size; int parent; } *tokens; int tokenCount; int currentToken; } *parser, struct TokenIdent *idents, __builtin_va_list args); } []

return_type: enum RedditErrno { REDDIT_SUCCESS=0, REDDIT_ERROR=1, REDDIT_ERROR_RESPONSE=2, REDDIT_ERROR_NOTCON=3, REDDIT_ERROR_USER=4 }

user_defined_types: struct TokenIdent { char *name; enum { TOKEN_BOOL=0, TOKEN_INT=1, TOKEN_STRING=2, TOKEN_OBJECT=3, TOKEN_DATE=4 } type; enum { TOKEN_SET=0, TOKEN_SET_PARSE=1, TOKEN_CHECK_CALL=2 } action; void *value; char **parseStr; int **parseStrWide; unsigned int bitMask; _Bool freeFlag; void (*funcCallback)(struct TokenParser *parser, struct TokenIdent *idents, __builtin_va_list args); }

user_defined_types: struct TokenParser { struct MemoryBlock *block; struct jsmntok_t *tokens; int tokenCount; int currentToken; }


handleCookie

original_code:
static void handleCookie (TokenParser *parser, TokenIdent *idents, va_list args)
{
    char *tmp = ((void *)0);
    do { tmp = rrealloc(tmp, parser->tokens[parser->currentToken].end - parser->tokens[parser->currentToken].start + 1); memcpy(tmp, parser->block->memory + parser->tokens[parser->currentToken].start, parser->tokens[parser->currentToken].end - parser->tokens[parser->currentToken].start); tmp[parser->tokens[parser->currentToken].end - parser->tokens[parser->currentToken].start] = 0; } while (0);
    redditCookieNew("reddit_session", tmp);
    free(tmp);
}

canonical_original_code:
static void handleCookie(struct TokenParser *parser, struct TokenIdent *idents, __builtin_va_list args)
{
    char *tmp = ((void *)0);
    do { tmp = rrealloc(tmp, parser->tokens[parser->currentToken].end - parser->tokens[parser->currentToken].start + 1); memcpy(tmp, parser->block->memory + parser->tokens[parser->currentToken].start, parser->tokens[parser->currentToken].end - parser->tokens[parser->currentToken].start); tmp[parser->tokens[parser->currentToken].end - parser->tokens[parser->currentToken].start] = 0; } while (0);
    redditCookieNew("reddit_session", tmp);
    free(tmp);
}

variable_types: struct TokenParser { struct MemoryBlock { char *memory; unsigned long size; } *block; struct jsmntok_t { enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 } type; int start; int end; int size; unsigned int is_key; int full_size; int parent; } *tokens; int tokenCount; int currentToken; } *

variable_types: struct TokenIdent { char *name; enum { TOKEN_BOOL=0, TOKEN_INT=1, TOKEN_STRING=2, TOKEN_OBJECT=3, TOKEN_DATE=4 } type; enum { TOKEN_SET=0, TOKEN_SET_PARSE=1, TOKEN_CHECK_CALL=2 } action; void *value; char **parseStr; int **parseStrWide; unsigned int bitMask; _Bool freeFlag; void (*funcCallback)(struct TokenParser *parser, struct TokenIdent *idents, __builtin_va_list args); } *

variable_types:
tmp
char *


redditUserNew

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

result = rmalloc(40LL);
*(_QWORD *)result = 0LL;
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 32) = 0LL;
*(_DWORD *)(result + 24) = -1;
*(_DWORD *)(result + 28) = -1;
return result;
}

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

result = rmalloc(40LL);
*(_QWORD *)result = 0LL;
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 32) = 0LL;
*(_DWORD *)(result + 24) = -1;
*(_DWORD *)(result + 28) = -1;
return result;
}

original_code:
__attribute__((visibility("default"))) RedditUser *redditUserNew()
{
    RedditUser *log = rmalloc(sizeof(RedditUser));
    memset(log, 0, sizeof(RedditUser));
    log->commentKarma = -1;
    log->linkKarma = -1;
    return log;
}

canonical_original_code:
struct RedditUser *redditUserNew()
{
    struct RedditUser *log = rmalloc(sizeof(RedditUser));
    memset(log, 0, sizeof(RedditUser));
    log->commentKarma = -1;
    log->linkKarma = -1;
    return log;
}

variable_types: struct RedditUser { char *name; char *modhash; char *id; int commentKarma; int linkKarma; unsigned int flags; } *


redditUserFree

decompiled_code:
void __fastcall redditUserFree(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(*((void **)ptr + 2));
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(*((void **)ptr + 2));
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
__attribute__((visibility("default"))) void redditUserFree (RedditUser *log)
{
    if (log == ((void *)0))
        return ;
    free(log->name);
    free(log->id);
    free(log->modhash);
    free(log);
}

canonical_original_code:
void redditUserFree(struct RedditUser *log)
{
    if (log == ((void *)0))
        return ;
    free(log->name);
    free(log->id);
    free(log->modhash);
    free(log);
}

user_defined_types: struct RedditUser { char *name; char *modhash; char *id; int commentKarma; int linkKarma; unsigned int flags; }


redditUserLoggedNew

decompiled_code:
__int64 redditUserLoggedNew()
{
__int64 v0; // rbx

v0 = rmalloc(16LL);
*(_QWORD *)(v0 + 8) = redditUserNew();
*(_BYTE *)(v0 + 4) = 0;
*(_DWORD *)v0 = -1;
return v0;
}

original_code:
__attribute__((visibility("default"))) RedditUserLogged *redditUserLoggedNew()
{
    RedditUserLogged *user = rmalloc(sizeof(RedditUserLogged));
    user->userInfo = redditUserNew();
    user->stayLoggedOn = 0;
    user->userState = REDDIT_USER_OFFLINE;
    return user;
}

canonical_original_code:
struct RedditUserLogged *redditUserLoggedNew()
{
    struct RedditUserLogged *user = rmalloc(sizeof(RedditUserLogged));
    user->userInfo = redditUserNew();
    user->stayLoggedOn = 0;
    user->userState = REDDIT_USER_OFFLINE;
    return user;
}

variable_types: struct RedditUserLogged { enum RedditUserState { REDDIT_USER_LOGGED_ON=0, REDDIT_USER_OFFLINE=-1 } userState; _Bool stayLoggedOn; struct RedditUser { char *name; char *modhash; char *id; int commentKarma; int linkKarma; unsigned int flags; } *userInfo; } *

user_defined_types: struct RedditUserLogged { enum RedditUserState userState; _Bool stayLoggedOn; struct RedditUser *userInfo; }


redditUserLoggedFree

decompiled_code:
void __fastcall redditUserLoggedFree(void *ptr)
{
if ( ptr )
{
redditUserFree(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
if ( ptr )
{
func2(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
__attribute__((visibility("default"))) void redditUserLoggedFree(RedditUserLogged *user)
{
    if (user == ((void *)0))
        return ;
    redditUserFree(user->userInfo);
    free(user);
}

canonical_original_code:
void redditUserLoggedFree(struct RedditUserLogged *user)
{
    if (user == ((void *)0))
        return ;
    redditUserFree(user->userInfo);
    free(user);
}

user_defined_types: enum RedditUserState { REDDIT_USER_LOGGED_ON=0, REDDIT_USER_OFFLINE=-1 }


userUpdateHelper

decompiled_code:
char __fastcall userUpdateHelper(__int64 a1, const char **a2, int *a3)
{
const char **v4; // r8
unsigned int v5; // eax
void ***v6; // r9
const char **v7; // rax
const char *v8; // rsi
bool v9; // zf
void **v10; // rbp
void *v11; // rdi

v4 = a2;
v5 = *a3;
if ( (unsigned int)*a3 > 0x2F )
{
v6 = (void ***)*((_QWORD *)a3 + 1);
LOBYTE(v7) = (_BYTE)v6 + 8;
*((_QWORD *)a3 + 1) = v6 + 1;
}
else
{
v6 = (void ***)(*((_QWORD *)a3 + 2) + v5);
LODWORD(v7) = v5 + 8;
*a3 = (int)v7;
}
v8 = *a2;
if ( *v4 )
{
while ( 1 )
{
v9 = strcmp(v8, "kind") == 0;
LOBYTE(v7) = !v9;
if ( v9 )
break;
v4 += 7;
v8 = *v4;
if ( !*v4 )
return (char)v7;
}
v7 = (const char **)v4[2];
if ( v7 )
{
v9 = strcmp(*v7, "t2") == 0;
LOBYTE(v7) = !v9;
if ( v9 )
{
v10 = *v6;
v11 = **v6;
if ( v11 )
redditUserFree(v11);
v7 = (const char **)redditGetUser(a1);
*v10 = v7;
}
}
}
return (char)v7;
}

canonical_decompiled_code:
char __fastcall func6(__int64 a1, const char **a2, int *a3)
{
const char **v4; // r8
unsigned int v5; // eax
void ***v6; // r9
const char **v7; // rax
const char *v8; // rsi
bool v9; // zf
void **v10; // rbp
void *v11; // rdi

v4 = a2;
v5 = *a3;
if ( (unsigned int)*a3 > 0x2F )
{
v6 = (void ***)*((_QWORD *)a3 + 1);
LOBYTE(v7) = (_BYTE)v6 + 8;
*((_QWORD *)a3 + 1) = v6 + 1;
}
else
{
v6 = (void ***)(*((_QWORD *)a3 + 2) + v5);
LODWORD(v7) = v5 + 8;
*a3 = (int)v7;
}
v8 = *a2;
if ( *v4 )
{
while ( 1 )
{
v9 = strcmp(v8, "kind") == 0;
LOBYTE(v7) = !v9;
if ( v9 )
break;
v4 += 7;
v8 = *v4;
if ( !*v4 )
return (char)v7;
}
v7 = (const char **)v4[2];
if ( v7 )
{
v9 = strcmp(*v7, "t2") == 0;
LOBYTE(v7) = !v9;
if ( v9 )
{
v10 = *v6;
v11 = **v6;
if ( v11 )
func2(v11);
v7 = (const char **)func5(a1);
*v10 = v7;
}
}
}
return (char)v7;
}

original_code:
static void userUpdateHelper (TokenParser *parser, TokenIdent *idents, va_list args)
{
    RedditUser **user = __builtin_va_arg(args,RedditUser**);
    int i;
    for (i = 0; idents[i].name != ((void *)0); i++) {
        if (strcmp(idents[i].name, "kind") == 0) {
            if (idents[i].value != ((void *)0) && strcmp(*((char**)idents[i].value), "t2") == 0) {
                if (*user != ((void *)0))
                    redditUserFree(*user);
                *user = redditGetUser(parser);
            }
            break;
        }
    }
}

canonical_original_code:
static void userUpdateHelper(struct TokenParser *parser, struct TokenIdent *idents, __builtin_va_list args)
{
    struct RedditUser **user = __builtin_va_arg(args,RedditUser**);
    int i;
    for (i = 0; idents[i].name != ((void *)0); i++) {
        if (strcmp(idents[i].name, "kind") == 0) {
            if (idents[i].value != ((void *)0) && strcmp(*((char **)idents[i].value), "t2") == 0) {
                if (*user != ((void *)0))
                    redditUserFree(*user);
                *user = redditGetUser(parser);
            }
            break;
        }
    }
}

variable_types: struct RedditUser { char *name; char *modhash; char *id; int commentKarma; int linkKarma; unsigned int flags; } **

variable_types: i int

user_defined_types: struct MemoryBlock { char *memory; unsigned long size; }


redditUserLoggedLogin

decompiled_code:
__int64 __fastcall redditUserLoggedLogin(__int64 a1, const char *a2, const char *a3)
{
const char *v4; // rax
__int64 result; // rax
const char *v6; // [rsp+0h] [rbp-10E8h] BYREF
int v7; // [rsp+8h] [rbp-10E0h]
int v8; // [rsp+Ch] [rbp-10DCh]
__int64 v9[19]; // [rsp+10h] [rbp-10D8h] BYREF
unsigned int v10; // [rsp+B4h] [rbp-1034h] BYREF
char v11[6]; // [rsp+BAh] [rbp-102Eh] BYREF
char s[4136]; // [rsp+C0h] [rbp-1028h] BYREF

v10 = 0;
memset(v9, 0, sizeof(v9));
v6 = "errors";
v7 = 3;
v8 = 2;
v9[4] = (__int64)handleErrorArray;
v9[5] = (__int64)"cookie";
v9[6] = 0x200000003LL;
v9[11] = (__int64)handleCookie;
if ( !a3 || !a2 )
return 4LL;
redditRemoveCookie("reddit_session");
v4 = (const char *)trueFalseString(v11, *(unsigned __int8 *)(a1 + 4));
sprintf(s, "api_type=json&rem=%s&user=%s&passwd=%s", v4, a2, a3);
if ( (unsigned int)redditRunParser("http://www.reddit.com/api/login.json", s, &v6, &v10) )
{
result = 2LL;
}
else
{
result = v10;
if ( !v10 )
{
*(_DWORD *)a1 = 0;
return result;
}
}
*(_DWORD *)a1 = -1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2, const char *a3)
{
const char *v4; // rax
__int64 result; // rax
const char *v6; // [rsp+0h] [rbp-10E8h] BYREF
int v7; // [rsp+8h] [rbp-10E0h]
int v8; // [rsp+Ch] [rbp-10DCh]
__int64 v9[19]; // [rsp+10h] [rbp-10D8h] BYREF
unsigned int v10; // [rsp+B4h] [rbp-1034h] BYREF
char v11[6]; // [rsp+BAh] [rbp-102Eh] BYREF
char s[4136]; // [rsp+C0h] [rbp-1028h] BYREF

v10 = 0;
memset(v9, 0, sizeof(v9));
v6 = "errors";
v7 = 3;
v8 = 2;
v9[4] = (__int64)handleErrorArray;
v9[5] = (__int64)"cookie";
v9[6] = 0x200000003LL;
v9[11] = (__int64)handleCookie;
if ( !a3 || !a2 )
return 4LL;
redditRemoveCookie("reddit_session");
v4 = (const char *)trueFalseString(v11, *(unsigned __int8 *)(a1 + 4));
sprintf(s, "api_type=json&rem=%s&user=%s&passwd=%s", v4, a2, a3);
if ( (unsigned int)redditRunParser("http://www.reddit.com/api/login.json", s, &v6, &v10) )
{
result = 2LL;
}
else
{
result = v10;
if ( !v10 )
{
*(_DWORD *)a1 = 0;
return result;
}
}
*(_DWORD *)a1 = -1;
return result;
}

original_code:
__attribute__((visibility("default"))) RedditErrno redditUserLoggedLogin (RedditUserLogged *log, char *name, char *passwd)
{
    char loginInfo[4096];
    char tf[6];
    RedditErrno response = REDDIT_SUCCESS;
    TokenParserResult res;
    TokenIdent ids[] = {
        {.name = "errors", .type = TOKEN_OBJECT, .action = TOKEN_CHECK_CALL, .funcCallback = &(handleErrorArray)},
        {.name = "cookie", .type = TOKEN_OBJECT, .action = TOKEN_CHECK_CALL, .funcCallback = &(handleCookie)},
        {0}
    };
    if (!(passwd) || !(name))
        return REDDIT_ERROR_USER;
    redditRemoveCookie("reddit_session");
    sprintf(loginInfo, "api_type=json&rem=%s&user=%s&passwd=%s", trueFalseString(tf, log->stayLoggedOn), name, passwd);
    res = redditRunParser("http://www.reddit.com" "/api" "/login" ".json", loginInfo, ids, &response);
    if (res != TOKEN_PARSER_SUCCESS)
        response = REDDIT_ERROR_RESPONSE;
    if (response == REDDIT_SUCCESS)
        log->userState = REDDIT_USER_LOGGED_ON;
    else
        log->userState = REDDIT_USER_OFFLINE;
    return response;
}

canonical_original_code:
enum RedditErrno redditUserLoggedLogin(struct RedditUserLogged *log, char *name, char *passwd)
{
    char loginInfo[4096];
    char tf[6];
    enum RedditErrno response = REDDIT_SUCCESS;
    enum TokenParserResult res;
    struct TokenIdent ids[] = {
        {.name = "errors", .type = TOKEN_OBJECT, .action = TOKEN_CHECK_CALL, .funcCallback = &(handleErrorArray)},
        {.name = "cookie", .type = TOKEN_OBJECT, .action = TOKEN_CHECK_CALL, .funcCallback = &(handleCookie)},
        {0}
    };
    if (!(passwd) || !(name))
        return REDDIT_ERROR_USER;
    redditRemoveCookie("reddit_session");
    sprintf(loginInfo, "api_type=json&rem=%s&user=%s&passwd=%s", trueFalseString(tf, log->stayLoggedOn), name, passwd);
    res = redditRunParser("http://www.reddit.com" "/api" "/login" ".json", loginInfo, ids, &response);
    if (res != TOKEN_PARSER_SUCCESS)
        response = REDDIT_ERROR_RESPONSE;
    if (response == REDDIT_SUCCESS)
        log->userState = REDDIT_USER_LOGGED_ON;
    else
        log->userState = REDDIT_USER_OFFLINE;
    return response;
}

variable_types:
name
char *

variable_types:
passwd
char *

variable_types:
loginInfo
char [4096]

variable_types:
tf
char [6]

variable_types: enum RedditErrno { REDDIT_SUCCESS=0, REDDIT_ERROR=1, REDDIT_ERROR_RESPONSE=2, REDDIT_ERROR_NOTCON=3, REDDIT_ERROR_USER=4 }

user_defined_types: enum TokenParserResult { TOKEN_PARSER_SUCCESS=0, TOKEN_PARSER_CURL_FAIL=1, TOKEN_PARSER_JSON_FAIL=2 }


redditUserLoggedUpdate

decompiled_code:
__int64 __fastcall redditUserLoggedUpdate(__int64 a1)
{
unsigned int v1; // ebx
const char *v3; // [rsp+0h] [rbp-B8h] BYREF
__int64 v4[20]; // [rsp+8h] [rbp-B0h] BYREF
void *ptr; // [rsp+A8h] [rbp-10h] BYREF

ptr = 0LL;
memset(v4, 0, sizeof(v4));
v3 = "kind";
LODWORD(v4[0]) = 2;
v4[1] = (__int64)&ptr;
BYTE4(v4[4]) = 1;
v4[6] = (__int64)"data";
v4[7] = 0x200000003LL;
v4[12] = (__int64)userUpdateHelper;
v1 = redditRunParser("http://www.reddit.com/api/me.json", 0LL, &v3, a1 + 8);
free(ptr);
if ( v1 )
v1 = 2;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
unsigned int v1; // ebx
const char *v3; // [rsp+0h] [rbp-B8h] BYREF
__int64 v4[20]; // [rsp+8h] [rbp-B0h] BYREF
void *ptr; // [rsp+A8h] [rbp-10h] BYREF

ptr = 0LL;
memset(v4, 0, sizeof(v4));
v3 = "kind";
LODWORD(v4[0]) = 2;
v4[1] = (__int64)&ptr;
BYTE4(v4[4]) = 1;
v4[6] = (__int64)"data";
v4[7] = 0x200000003LL;
v4[12] = (__int64)userUpdateHelper;
v1 = redditRunParser("http://www.reddit.com/api/me.json", 0LL, &v3, a1 + 8);
free(ptr);
if ( v1 )
v1 = 2;
return v1;
}

original_code:
__attribute__((visibility("default"))) RedditErrno redditUserLoggedUpdate (RedditUserLogged *user)
{
    TokenParserResult res;
    char *kindStr = ((void *)0);
    TokenIdent ids[] = {
        {.name = "kind", .type = TOKEN_STRING, .action = TOKEN_SET, .value = &(kindStr), .freeFlag = 1},
        {.name = "data", .type = TOKEN_OBJECT, .action = TOKEN_CHECK_CALL, .funcCallback = &(userUpdateHelper)},
        {0}
    };
    res = redditRunParser("http://www.reddit.com" "/api" "/me" ".json", ((void *)0), ids, &(user->userInfo));
    free(kindStr);
    if (res == TOKEN_PARSER_SUCCESS)
        return REDDIT_SUCCESS;
    else
        return REDDIT_ERROR_RESPONSE;
}

canonical_original_code:
enum RedditErrno redditUserLoggedUpdate(struct RedditUserLogged *user)
{
    enum TokenParserResult res;
    char *kindStr = ((void *)0);
    struct TokenIdent ids[] = {
        {.name = "kind", .type = TOKEN_STRING, .action = TOKEN_SET, .value = &(kindStr), .freeFlag = 1},
        {.name = "data", .type = TOKEN_OBJECT, .action = TOKEN_CHECK_CALL, .funcCallback = &(userUpdateHelper)},
        {0}
    };
    res = redditRunParser("http://www.reddit.com" "/api" "/me" ".json", ((void *)0), ids, &(user->userInfo));
    free(kindStr);
    if (res == TOKEN_PARSER_SUCCESS)
        return REDDIT_SUCCESS;
    else
        return REDDIT_ERROR_RESPONSE;
}

user_defined_types: enum RedditErrno { REDDIT_SUCCESS=0, REDDIT_ERROR=1, REDDIT_ERROR_RESPONSE=2, REDDIT_ERROR_NOTCON=3, REDDIT_ERROR_USER=4 }


decompiled_code:
char *__fastcall valloc_sprintf(char *format, __gnuc_va_list arg)
{
size_t v2; // rbx
char *v3; // rax
char *v4; // rbp
__m128i arga; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+18h] [rbp-30h]

arga = _mm_loadu_si128((const __m128i *)arg);
v7 = *((_QWORD *)arg + 2);
v2 = vsnprintf(0LL, 0LL, format, &arga) + 1;
v3 = (char *)malloc(v2);
v4 = v3;
if ( v3 )
{
*v3 = 0;
vsnprintf(v3, v2, format, arg);
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func0(char *format, __gnuc_va_list arg)
{
size_t v2; // rbx
char *v3; // rax
char *v4; // rbp
__m128i arga; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+18h] [rbp-30h]

arga = _mm_loadu_si128((const __m128i *)arg);
v7 = *((_QWORD *)arg + 2);
v2 = vsnprintf(0LL, 0LL, format, &arga) + 1;
v3 = (char *)malloc(v2);
v4 = v3;
if ( v3 )
{
*v3 = 0;
vsnprintf(v3, v2, format, arg);
}
return v4;
}

original_code:
static char *valloc_sprintf (const char *format, va_list lst)
{
    va_list cpy;
    __builtin_va_copy(cpy,lst);
    size_t size = vsnprintf(((void *)0), 0, format, cpy) + 1;
    char *buf = malloc(size);
    if (!buf)
        return ((void *)0);
    buf[0] = '\0';
    vsnprintf(buf, size, format, lst);
    return buf;
}

canonical_original_code:
static char *valloc_sprintf(char *format, __builtin_va_list lst)
{
    __builtin_va_list cpy;
    __builtin_va_copy(cpy,lst);
    unsigned long size = vsnprintf(((void *)0), 0, format, cpy) + 1;
    char *buf = malloc(size);
    if (!buf)
        return ((void *)0);
    buf[0] = '\0';
    vsnprintf(buf, size, format, lst);
    return buf;
}

variable_types:
format
char *

variable_types:
size
unsigned long

variable_types:
buf
char *


decompiled_code:
char *alloc_sprintf(char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
return valloc_sprintf(a1, arg);
}

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

va_start(arg, a1);
return func0(a1, arg);
}

original_code:
char *alloc_sprintf (const char *format, ...)
{
    char *ret;
    va_list lst;
    __builtin_va_start(lst,format);
    ret = valloc_sprintf(format, lst);
    __builtin_va_end(lst);
    return ret;
}

canonical_original_code:
char *alloc_sprintf(char *format, ...)
{
    char *ret;
    __builtin_va_list lst;
    __builtin_va_start(lst,format);
    ret = valloc_sprintf(format, lst);
    __builtin_va_end(lst);
    return ret;
}

variable_types:
ret
char *


repo: CovertIII/Tron-Clone

decompiled_code:
double __fastcall v2Add(double a1, double a2, double a3)
{
return a1 + a3;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3)
{
return a1 + a3;
}

original_code:
vector2 v2Add(vector2 a, vector2 b) {
 vector2 c;
 c.x = a.x + b.x;
 c.y = a.y + b.y;
 return c;
}

canonical_original_code:
struct vector2 v2Add(struct vector2 a, struct vector2 b) {
 struct vector2 c;
 c.x = a.x + b.x;
 c.y = a.y + b.y;
 return c;
}

variable_types:
a
struct vector2

variable_types:
b
struct vector2

variable_types:
c
struct vector2 { double x; }

return_type: struct vector2 { double x; }


decompiled_code:
double __fastcall v2Sub(double a1, double a2, double a3)
{
return a1 - a3;
}

canonical_decompiled_code:
double __fastcall func1(double a1, double a2, double a3)
{
return a1 - a3;
}

original_code:
vector2 v2Sub(vector2 a, vector2 b) {
 vector2 c;
 c.x = a.x - b.x;
 c.y = a.y - b.y;
 return c;
}

canonical_original_code:
struct vector2 v2Sub(struct vector2 a, struct vector2 b) {
 struct vector2 c;
 c.x = a.x - b.x;
 c.y = a.y - b.y;
 return c;
}


decompiled_code:
__m128d __fastcall v2Neg(__m128d a1)
{
return _mm_xor_pd(a1, (__m128d)_mm_loadl_epi64((const __m128i *)&LC0));
}

canonical_decompiled_code:
__m128d __fastcall func2(__m128d a1)
{
return _mm_xor_pd(a1, (__m128d)_mm_loadl_epi64((const __m128i *)&LC0));
}

original_code:
vector2 v2Neg(vector2 a) {
 a.x = -a.x;
 a.y = -a.y;
 return a;
}

canonical_original_code:
struct vector2 v2Neg(struct vector2 a) {
 a.x = -a.x;
 a.y = -a.y;
 return a;
}


original_code:
vector2 v2sMul(float f, vector2 v) {
 v.x = f*v.x;
 v.y = f*v.y;
 return v;
}

canonical_original_code:
struct vector2 v2sMul(float f, struct vector2 v) {
 v.x = f*v.x;
 v.y = f*v.y;
 return v;
}

variable_types: f float

variable_types:
v
struct vector2


decompiled_code:
double __fastcall v2Polar(float a1, float a2)
{
double cosx; // [rsp+10h] [rbp-18h] BYREF
double sinx[2]; // [rsp+18h] [rbp-10h] BYREF

sincos(a2, sinx, &cosx);
return a1 * cosx;
}

canonical_decompiled_code:
double __fastcall func4(float a1, float a2)
{
double cosx; // [rsp+10h] [rbp-18h] BYREF
double sinx[2]; // [rsp+18h] [rbp-10h] BYREF

sincos(a2, sinx, &cosx);
return a1 * cosx;
}

original_code:
vector2 v2Polar(float len, float angle) {
 vector2 a;
 a.x = len*cos(angle);
 a.y = len*sin(angle);
 return a;
}

canonical_original_code:
struct vector2 v2Polar(float len, float angle) {
 struct vector2 a;
 a.x = len*cos(angle);
 a.y = len*sin(angle);
 return a;
}

variable_types: len float

variable_types: angle float

variable_types:
a
struct vector2 { double x; }


decompiled_code:
float __fastcall v2Dot(double a1, double a2, double a3, double a4)
{
return a1 * a3 + a2 * a4;
}

canonical_decompiled_code:
float __fastcall func5(double a1, double a2, double a3, double a4)
{
return a1 * a3 + a2 * a4;
}

original_code:
float v2Dot(vector2 a, vector2 b) {
 return a.x*b.x + a.y*b.y;
}

canonical_original_code:
float v2Dot(struct vector2 a, struct vector2 b) {
 return a.x*b.x + a.y*b.y;
}

return_type: float


decompiled_code:
float __fastcall v2Cross(double a1, double a2, double a3, double a4)
{
return a1 * a4 - a2 * a3;
}

canonical_decompiled_code:
float __fastcall func6(double a1, double a2, double a3, double a4)
{
return a1 * a4 - a2 * a3;
}

original_code:
float v2Cross(vector2 a, vector2 b) {
 return a.x*b.y - a.y*b.x;
}

canonical_original_code:
float v2Cross(struct vector2 a, struct vector2 b) {
 return a.x*b.y - a.y*b.x;
}


decompiled_code:
float __fastcall v2Len(double a1, double a2)
{
double v2; // xmm0_8
float result; // xmm0_4

v2 = a1 * a1 + a2 * a2;
if ( v2 < 0.0 )
result = sqrt(v2);
else
result = sqrt(v2);
return result;
}

canonical_decompiled_code:
float __fastcall func7(double a1, double a2)
{
double v2; // xmm0_8
float result; // xmm0_4

v2 = a1 * a1 + a2 * a2;
if ( v2 < 0.0 )
result = sqrt(v2);
else
result = sqrt(v2);
return result;
}

original_code:
float v2Len(vector2 v) {
 return sqrt(v.x*v.x + v.y*v.y);
}

canonical_original_code:
float v2Len(struct vector2 v) {
 return sqrt(v.x*v.x + v.y*v.y);
}

variable_types:
v
struct vector2 { double x; }


decompiled_code:
double __fastcall v2Unit(double a1, double a2)
{
double v4; // [rsp+8h] [rbp-20h]

v4 = a1 / v2Len(a1, a2);
v2Len(a1, a2);
return v4;
}

canonical_decompiled_code:
double __fastcall func8(double a1, double a2)
{
double v4; // [rsp+8h] [rbp-20h]

v4 = a1 / func7(a1, a2);
func7(a1, a2);
return v4;
}

original_code:
vector2 v2Unit(vector2 v) {
 vector2 a;
 a.x = v.x/v2Len(v);
 a.y = v.y/v2Len(v);
 return a;
}

canonical_original_code:
struct vector2 v2Unit(struct vector2 v) {
 struct vector2 a;
 a.x = v.x/v2Len(v);
 a.y = v.y/v2Len(v);
 return a;
}


decompiled_code:
float __fastcall v2SPow(double a1, double a2)
{
return a1 * a1 + a2 * a2;
}

canonical_decompiled_code:
float __fastcall func9(double a1, double a2)
{
return a1 * a1 + a2 * a2;
}

original_code:
float v2SPow(vector2 v) {
 return v.x*v.x + v.y*v.y;
}

canonical_original_code:
float v2SPow(struct vector2 v) {
 return v.x*v.x + v.y*v.y;
}


decompiled_code:
float __fastcall v2Arg(double a1, double a2)
{
return atan2(a2, a1);
}

canonical_decompiled_code:
float __fastcall func10(double a1, double a2)
{
return atan2(a2, a1);
}

original_code:
float v2Arg(vector2 v) {
 return atan2(v.y,v.x);
}

canonical_original_code:
float v2Arg(struct vector2 v) {
 return atan2(v.y,v.x);
}