decompiled_code:
__int64 __fastcall cmp_2_card(char a1, char a2)
{
int v2; // eax
int v3; // ecx
unsigned int v4; // er8

get_card_index_in_order(a1);
v2 = get_card_index_in_order(a2);
if ( v3 == -1 || v2 == -1 )
return (unsigned int)-10;
v4 = 0;
if ( v3 != v2 )
v4 = 2 * (v3 <= v2) - 1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1, char a2)
{
int v2; // eax
int v3; // ecx
unsigned int v4; // er8

func7(a1);
v2 = func7(a2);
if ( v3 == -1 || v2 == -1 )
return (unsigned int)-10;
v4 = 0;
if ( v3 != v2 )
v4 = 2 * (v3 <= v2) - 1;
return v4;
}

original_code:
int cmp_2_card(const T_A_CARD c1, const T_A_CARD c2)
{
  int i1,i2;
  i1=get_card_index_in_order(c1);
  i2=get_card_index_in_order(c2);
  if(i1==-1 || i2==-1)
 return -10;
  if(i1==i2)
 return 0;
  if(i1>i2)
 return -1;
  else
 return 1;
}

canonical_original_code:
int cmp_2_card(char c1, char c2)
{
  int i1; int i2;
  i1=get_card_index_in_order(c1);
  i2=get_card_index_in_order(c2);
  if(i1==-1 || i2==-1)
 return -10;
  if(i1==i2)
 return 0;
  if(i1>i2)
 return -1;
  else
 return 1;
}


decompiled_code:
__int64 __fastcall sort_cards(char *s)
{
char v1; // r13
char *v2; // r14
char v3; // r11
__int64 v4; // r9
char v5; // r10
int v6; // eax
__int64 v7; // r9
int v8; // er12
__int64 v9; // rbp
char v10; // si
int v11; // eax
char v13; // [rsp+0h] [rbp-48h] BYREF
char v14; // [rsp+1h] [rbp-47h] BYREF

strcpy(&v13, s);
v1 = v13;
*s = 0;
if ( v1 )
{
v2 = &v14;
v3 = 0;
while ( 2 )
{
LODWORD(v4) = 0;
v5 = v1;
LABEL_7:
v8 = v4;
v9 = (int)v4;
v10 = v3;
while ( v3 )
{
v6 = cmp_2_card(v5, v10);
if ( v6 != -10 )
{
v4 = v7 + 1;
if ( v6 != -1 )
break;
v3 = s[v4];
goto LABEL_7;
}
}
v11 = strlen(s);
if ( (int)v9 <= v11 )
memmove(
&s[v11 + 1LL - (unsigned int)(v11 - v8)],
&s[v11 - (unsigned __int64)(unsigned int)(v11 - v8)],
(unsigned int)(v11 - v8) + 1LL);
++v2;
s[v9] = v1;
v1 = *(v2 - 1);
if ( v1 )
{
v3 = *s;
continue;
}
break;
}
}
return 1LL;
}

original_code:
int sort_cards(T_CARDS cards)
{
  T_CARDS cs;
  int i=0,j,k,ret;
  T_A_CARD c1,c2;
  strcpy(cs,cards);
  cards[0]='\0';
  while((c1=*(cs+i++))){
 j=0;
 while((c2=*(cards+j))){
   ret=cmp_2_card(c1,c2);
   if(ret==-10)
  continue;
   if(ret==-1)
  ++j;
   else
  break;
 }
 for(k=strlen(cards);k>=j;k--)
   *(cards+k+1)=*(cards+k);
 *(cards+j)=c1;
  }
  return 1;
}

canonical_original_code:
int sort_cards(char cards[21])
{
  char cs[21];
  int i = 0; int j; int k; int ret;
  char c1; char c2;
  strcpy(cs,cards);
  cards[0]='\0';
  while((c1=*(cs+i++))){
 j=0;
 while((c2=*(cards+j))){
   ret=cmp_2_card(c1,c2);
   if(ret==-10)
  continue;
   if(ret==-1)
  ++j;
   else
  break;
 }
 for(k=strlen(cards);k>=j;k--)
   *(cards+k+1)=*(cards+k);
 *(cards+j)=c1;
  }
  return 1;
}

variable_types:
cards
char [21]

variable_types:
cs
char [21]

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: ret int

return_type: int


decompiled_code:
__int64 __fastcall del_card(char *a1, char a2)
{
char v2; // dl
__int64 result; // rax
__int64 v4; // rcx
char *v5; // rsi
char *v6; // rax
char *v7; // rdx
char v8; // cl

v2 = *a1;
result = 0LL;
if ( *a1 )
{
while ( 1 )
{
v4 = (int)result;
if ( a2 == v2 )
break;
v2 = a1[++result];
if ( !v2 )
return 0LL;
}
v5 = &a1[(int)result];
if ( *v5 )
{
v6 = &a1[(int)result + 1];
v7 = &a1[v4];
do
{
v8 = *v6;
v5 = v6;
++v7;
++v6;
*(v7 - 1) = v8;
}
while ( v8 );
}
*v5 = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, char a2)
{
char v2; // dl
__int64 result; // rax
__int64 v4; // rcx
char *v5; // rsi
char *v6; // rax
char *v7; // rdx
char v8; // cl

v2 = *a1;
result = 0LL;
if ( *a1 )
{
while ( 1 )
{
v4 = (int)result;
if ( a2 == v2 )
break;
v2 = a1[++result];
if ( !v2 )
return 0LL;
}
v5 = &a1[(int)result];
if ( *v5 )
{
v6 = &a1[(int)result + 1];
v7 = &a1[v4];
do
{
v8 = *v6;
v5 = v6;
++v7;
++v6;
*(v7 - 1) = v8;
}
while ( v8 );
}
*v5 = 0;
result = 1LL;
}
return result;
}

original_code:
int del_card(T_CARDS cards, const T_A_CARD a_card)
{
  int i=0;
  T_A_CARD c;
  while((c=*(cards+i)) && c!=a_card){
 ++i;
  }
  if(!c)
 return 0;
  while(*(cards+i)){
 *(cards+i)=*(cards+i+1);
 i++;
  }
  *(cards+i)='\0';
  return 1;
}

canonical_original_code:
int del_card(char cards[21], char a_card)
{
  int i = 0;
  char c;
  while((c=*(cards+i)) && c!=a_card){
 ++i;
  }
  if(!c)
 return 0;
  while(*(cards+i)){
 *(cards+i)=*(cards+i+1);
 i++;
  }
  *(cards+i)='\0';
  return 1;
}

variable_types: c char


decompiled_code:
__int64 __fastcall del_cards(char *dest, char *a2)
{
__int64 result; // rax
char v4; // si
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

strcpy(v5, dest);
while ( 1 )
{
v4 = *a2;
if ( !*a2 )
break;
++a2;
result = del_card(v5, v4);
if ( !(_DWORD)result )
return result;
}
strcpy(dest, v5);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *dest, char *a2)
{
__int64 result; // rax
char v4; // si
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

strcpy(v5, dest);
while ( 1 )
{
v4 = *a2;
if ( !*a2 )
break;
++a2;
result = func10(v5, v4);
if ( !(_DWORD)result )
return result;
}
strcpy(dest, v5);
return 1LL;
}

original_code:
int del_cards(T_CARDS cards, const T_CARDS cards_small)
{
  T_A_CARD c;
  T_CARDS cs;
  int i=0;
  strcpy(cs,cards);
  while((c=*(cards_small+i++))){
 if(!del_card(cs,c))
   return 0;
  }
  strcpy(cards,cs);
  return 1;
}

canonical_original_code:
int del_cards(char cards[21], char cards_small[21])
{
  char c;
  char cs[21];
  int i = 0;
  strcpy(cs,cards);
  while((c=*(cards_small+i++))){
 if(!del_card(cs,c))
   return 0;
  }
  strcpy(cards,cs);
  return 1;
}


decompiled_code:
__int64 __fastcall in_cards(char *src, char *a2)
{
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

strcpy(v3, src);
return del_cards(v3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(char *src, char *a2)
{
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

strcpy(v3, src);
return func11(v3, a2);
}

original_code:
int in_cards(const T_CARDS cards, const T_CARDS cards_small)
{
  T_CARDS cs;
  strcpy(cs,cards);
  return(del_cards(cs,cards_small));
}

canonical_original_code:
int in_cards(char cards[21], char cards_small[21])
{
  char cs[21];
  strcpy(cs,cards);
  return(del_cards(cs,cards_small));
}


hello

repo: mapleelpam/gobject-learing

decompiled_code:
int hello()
{
return printf("hello ");
}

canonical_decompiled_code:
int func8()
{
return printf("hello ");
}

original_code: void hello() { printf("hello "); }

canonical_original_code: void hello() { printf("hello "); }

return_type: void


decompiled_code:
int __fastcall B_real_method_a(__int64 a1)
{
return printf("this is %s %d\n", "B_real_method_a", *(unsigned int *)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
return printf("this is %s %d\n", "B_real_method_a", *(unsigned int *)(a1 + 16));
}

original_code:
void B_real_method_a( void* p)
{
 struct B* this = p;
 printf("this is %s %d\n",__FUNCTION__,this->b);
}

canonical_original_code:
void B_real_method_a(void *p)
{
 struct B *this = p;
 printf("this is %s %d\n",__FUNCTION__,this->b);
}

variable_types:
p
void *

variable_types: struct B { struct A { int a; void (*method_a)(void *); } parent; int b; void (*method_b)(void *); } *

user_defined_types: struct B { struct A parent; int b; void (*method_b)(void *); }


decompiled_code:
void __fastcall A_init(__int64 a1)
{
*(_DWORD *)a1 = 1;
*(_QWORD *)(a1 + 8) = A_real_method_a;
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
*(_DWORD *)a1 = 1;
*(_QWORD *)(a1 + 8) = A_real_method_a;
}

original_code:
void A_init( struct A* a)
{
 a -> a = 1;
 a -> method_a = A_real_method_a;
}

canonical_original_code:
void A_init(struct A *a)
{
 a -> a = 1;
 a -> method_a = A_real_method_a;
}

variable_types: struct A { int a; void (*method_a)(void *); } *


decompiled_code:
void B_new()
{
void *v0; // rdi

v0 = malloc(0x20uLL);
A_init((__int64)v0);
B_init((__int64)v0);
}

canonical_decompiled_code:
void func12()
{
void *v0; // rdi

v0 = malloc(0x20uLL);
func10((__int64)v0);
func11((__int64)v0);
}

original_code:
struct B* B_new()
{
 struct B* pb = malloc(sizeof(struct B));
 struct A* pa = (struct A*) pb;
 A_init( pa );
 B_init( pb );
 return pb;
}

canonical_original_code:
struct B *B_new()
{
 struct B *pb = malloc(sizeof(struct B));
 struct A *pa = (struct A*) pb;
 A_init( pa );
 B_init( pb );
 return pb;
}

return_type: struct B { struct A { int a; void (*method_a)(void *); } parent; int b; void (*method_b)(void *); } *


decompiled_code:
__int64 __fastcall error_test(__int64 (*a1)(void))
{
return a1();
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 (*a1)(void))
{
return a1();
}

original_code:
void error_test( FP callback )
{
 if( 1 ){
  callback();
 }
}

canonical_original_code:
void error_test(void (*callback)())
{
 if( 1 ){
  callback();
 }
}

variable_types:
callback
void (*)()


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
error_test(error_0, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8(error_0, argv, envp);
return 0;
}

original_code:
int main()
{
 void error() { printf("error happened\n"); }
 error_test( error );
}


decompiled_code:
int __fastcall a_real_method(unsigned int *a1)
{
return printf("%d,%d\n", *a1, a1[1]);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
return printf("%d,%d\n", *a1, a1[1]);
}

original_code:
void a_real_method( void* p)
{
 struct A* this = p;
 printf("%d,%d\n",this->a,this->b);
}

canonical_original_code:
void a_real_method(void *p)
{
 struct A *this = p;
 printf("%d,%d\n",this->a,this->b);
}

variable_types: struct A { int a; int b; void (*method)(void *); } *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = 0x200000001LL;
v4[1] = (__int64)a_real_method;
a_real_method(v4, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = 0x200000001LL;
v4[1] = (__int64)a_real_method;
func7(v4, argv, envp);
return 0;
}

original_code:
int main()
{
 struct A a;
 a.a = 1;
 a.b = 2;
 a.method = a_real_method;
 a.method( &a );
}

variable_types: struct A { int a; int b; void (*method)(void *); }


decompiled_code:
int show_help()
{
puts("fujitsu usb touchscreen utility");
puts("usage:");
puts("\torientation 0|1|2|3: set driver orientation");
puts("\tcalibrate 0|1: activate calibration mode");
return puts("\twritecalibrate a b c d: write calibration values");
}

canonical_decompiled_code:
int func7()
{
puts("fujitsu usb touchscreen utility");
puts("usage:");
puts("\torientation 0|1|2|3: set driver orientation");
puts("\tcalibrate 0|1: activate calibration mode");
return puts("\twritecalibrate a b c d: write calibration values");
}

original_code:
void show_help(void) {
 printf("fujitsu usb touchscreen utility\n");
 printf("usage:\n");
 printf("	orientation 0|1|2|3: set driver orientation\n");
 printf("	calibrate 0|1: activate calibration mode\n");
 printf("	writecalibrate a b c d: write calibration values\n");
}

canonical_original_code:
void show_help() {
 printf("fujitsu usb touchscreen utility\n");
 printf("usage:\n");
 printf("	orientation 0|1|2|3: set driver orientation\n");
 printf("	calibrate 0|1: activate calibration mode\n");
 printf("	writecalibrate a b c d: write calibration values\n");
}


showhelp

repo: marcelog/Pakman

decompiled_code:
size_t showhelp()
{
unsigned int v0; // ebx
__int64 v1; // rax
__int64 v2; // rdi
const char *v3; // r12
const char *v4; // rax

v0 = 1;
fwrite("\nPAKMAN Help:\n\n", 1uLL, 0xFuLL, stdout);
do
{
v1 = pakman_strcmddesc(v0);
v2 = v0++;
v3 = (const char *)v1;
v4 = (const char *)pakman_strcmd(v2);
fprintf(stdout, "\t%s\t\t%s\n", v4, v3);
}
while ( v0 != 11 );
return fwrite("\n\n", 1uLL, 2uLL, stdout);
}

canonical_decompiled_code:
size_t func0()
{
unsigned int v0; // ebx
__int64 v1; // rax
__int64 v2; // rdi
const char *v3; // r12
const char *v4; // rax

v0 = 1;
fwrite("\nPAKMAN Help:\n\n", 1uLL, 0xFuLL, stdout);
do
{
v1 = pakman_strcmddesc(v0);
v2 = v0++;
v3 = (const char *)v1;
v4 = (const char *)pakman_strcmd(v2);
fprintf(stdout, "\t%s\t\t%s\n", v4, v3);
}
while ( v0 != 11 );
return fwrite("\n\n", 1uLL, 2uLL, stdout);
}

original_code:
void
showhelp(void)
{
 pakman_cmd_t i;
 fprintf(stdout, "\nPAKMAN Help:\n\n");
 for(i = 1; i < PAKMAN_CMD_DUMMY2; i++)
  fprintf(stdout, "\t%s\t\t%s\n", pakman_strcmd(i), pakman_strcmddesc(i));
 fprintf(stdout, "\n\n");
}

canonical_original_code:
void showhelp()
{
 enum pakman_cmd_t i;
 fprintf(stdout, "\nPAKMAN Help:\n\n");
 for(i = 1; i < PAKMAN_CMD_DUMMY2; i++)
  fprintf(stdout, "\t%s\t\t%s\n", pakman_strcmd(i), pakman_strcmddesc(i));
 fprintf(stdout, "\n\n");
}

variable_types: enum pakman_cmd_t { PAKMAN_CMD_DUMMY1=0, PAKMAN_CMD_SHOW=1, PAKMAN_CMD_QUERY=2, PAKMAN_CMD_SEARCH=3, PAKMAN_CMD_INSTALL=4, PAKMAN_CMD_DEINSTALL=5, PAKMAN_CMD_VERIFY=6, PAKMAN_CMD_CREATEDB=7, PAKMAN_CMD_HELP=8, PAKMAN_CMD_CREATE=9, PAKMAN_CMD_UPDATE=10, PAKMAN_CMD_DUMMY2=11 }


decompiled_code:
__int64 __fastcall pakman_chflags(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = (unsigned int)lchflags() == 0 ? 1 : 8;
else
result = 5LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = (unsigned int)lchflags() == 0 ? 1 : 8;
else
result = 5LL;
return result;
}

original_code:
pakman_error_t
pakman_chflags(const char *path, int flags)
{
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 if(lchflags(path, flags))
  return PAKMAN_ERROR_OSERROR;
 return PAKMAN_ERROR_NOERROR;
}

canonical_original_code:
enum pakman_error_t pakman_chflags(char *path, int flags)
{
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 if(lchflags(path, flags))
  return PAKMAN_ERROR_OSERROR;
 return PAKMAN_ERROR_NOERROR;
}

variable_types:
path
char *

variable_types: flags int

return_type: enum pakman_error_t { PAKMAN_ERROR_DUMMY1=0, PAKMAN_ERROR_NOERROR=1, PAKMAN_ERROR_UNDEF=2, PAKMAN_ERROR_NOTIMPL=3, PAKMAN_ERROR_NARGS=4, PAKMAN_ERROR_INVARGS=5, PAKMAN_ERROR_DBERROR=6, PAKMAN_ERROR_DBEXISTS=7, PAKMAN_ERROR_OSERROR=8, PAKMAN_ERROR_SHAFAILS=9, PAKMAN_ERROR_FILENEXISTS=10, PAKMAN_ERROR_NOTDIR=11, PAKMAN_ERROR_NOTFILE=12, PAKMAN_ERROR_PKGINSTALLED=13, PAKMAN_ERROR_PKGNINSTALLED=14, PAKMAN_ERROR_PKGAINSTALLED=15, PAKMAN_ERROR_FILEEXISTS=16, PAKMAN_ERROR_KEYNOTFOUND=17, PAKMAN_ERROR_DEPNOTFOUND=18, PAKMAN_ERROR_PKGPROTECTED=19, PAKMAN_ERROR_DUMMY2=20 }


decompiled_code:
__int64 __fastcall pakman_chown(const char *a1, __uid_t a2, __gid_t a3)
{
__int64 result; // rax

if ( a1 )
result = lchown(a1, a2, a3) == 0 ? 1 : 8;
else
result = 5LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __uid_t a2, __gid_t a3)
{
__int64 result; // rax

if ( a1 )
result = lchown(a1, a2, a3) == 0 ? 1 : 8;
else
result = 5LL;
return result;
}

original_code:
pakman_error_t
pakman_chown(const char *path, uid_t uid, gid_t gid)
{
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 if(lchown(path, uid, gid))
  return PAKMAN_ERROR_OSERROR;
 return PAKMAN_ERROR_NOERROR;
}

canonical_original_code:
enum pakman_error_t pakman_chown(char *path, unsigned int uid, unsigned int gid)
{
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 if(lchown(path, uid, gid))
  return PAKMAN_ERROR_OSERROR;
 return PAKMAN_ERROR_NOERROR;
}

variable_types:
uid
unsigned int

variable_types:
gid
unsigned int

user_defined_types: enum pakman_error_t { PAKMAN_ERROR_DUMMY1=0, PAKMAN_ERROR_NOERROR=1, PAKMAN_ERROR_UNDEF=2, PAKMAN_ERROR_NOTIMPL=3, PAKMAN_ERROR_NARGS=4, PAKMAN_ERROR_INVARGS=5, PAKMAN_ERROR_DBERROR=6, PAKMAN_ERROR_DBEXISTS=7, PAKMAN_ERROR_OSERROR=8, PAKMAN_ERROR_SHAFAILS=9, PAKMAN_ERROR_FILENEXISTS=10, PAKMAN_ERROR_NOTDIR=11, PAKMAN_ERROR_NOTFILE=12, PAKMAN_ERROR_PKGINSTALLED=13, PAKMAN_ERROR_PKGNINSTALLED=14, PAKMAN_ERROR_PKGAINSTALLED=15, PAKMAN_ERROR_FILEEXISTS=16, PAKMAN_ERROR_KEYNOTFOUND=17, PAKMAN_ERROR_DEPNOTFOUND=18, PAKMAN_ERROR_PKGPROTECTED=19, PAKMAN_ERROR_DUMMY2=20 }


decompiled_code:
__int64 __fastcall pakman_chmod(char *file, __mode_t mode)
{
if ( !file )
return 5LL;
fprintf(stdout, "%s: %s %o\n", "pakman_chmod", file, mode);
return lchmod(file, mode) == 0 ? 1 : 8;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *file, __mode_t mode)
{
if ( !file )
return 5LL;
fprintf(stdout, "%s: %s %o\n", "pakman_chmod", file, mode);
return lchmod(file, mode) == 0 ? 1 : 8;
}

original_code:
pakman_error_t
pakman_chmod(const char *path, mode_t mode)
{
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 fprintf(stdout, "%s: %s %o\n", __FUNCTION__, path, mode);
 if(lchmod(path, mode))
  return PAKMAN_ERROR_OSERROR;
 else
  return PAKMAN_ERROR_NOERROR;
}

canonical_original_code:
enum pakman_error_t pakman_chmod(char *path, unsigned int mode)
{
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 fprintf(stdout, "%s: %s %o\n", __FUNCTION__, path, mode);
 if(lchmod(path, mode))
  return PAKMAN_ERROR_OSERROR;
 else
  return PAKMAN_ERROR_NOERROR;
}

variable_types:
mode
unsigned int


decompiled_code:
__int64 __fastcall pakman_rmdir(const char *a1)
{
__int64 result; // rax

if ( a1 )
result = rmdir(a1) == 0 ? 1 : 8;
else
result = 5LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
__int64 result; // rax

if ( a1 )
result = rmdir(a1) == 0 ? 1 : 8;
else
result = 5LL;
return result;
}

original_code:
pakman_error_t
pakman_rmdir(const char *path)
{
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 if(rmdir(path))
  return PAKMAN_ERROR_OSERROR;
 else
  return PAKMAN_ERROR_NOERROR;
}

canonical_original_code:
enum pakman_error_t pakman_rmdir(char *path)
{
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 if(rmdir(path))
  return PAKMAN_ERROR_OSERROR;
 else
  return PAKMAN_ERROR_NOERROR;
}


decompiled_code:
__int64 __fastcall pakman_exists(const char *a1)
{
int v1; // er8
__int64 result; // rax
int v3; // edx
int v4; // er8
struct stat v5; // [rsp-18h] [rbp-98h] BYREF

if ( !a1 )
return 5LL;
v1 = stat(a1, &v5);
result = 10LL;
if ( !v1 )
{
v3 = v5.st_mode & 0xF000;
switch ( v3 )
{
case 24576:
result = 5LL;
break;
case 8192:
result = 6LL;
break;
case 16384:
result = 2LL;
break;
case 4096:
result = 8LL;
break;
case 40960:
result = 3LL;
break;
default:
result = 1LL;
if ( v3 != 0x8000 )
{
v4 = S_ISSOCK();
result = 4LL;
if ( !v4 )
result = (unsigned int)S_ISWHT(v5.st_mode) == 0 ? 9 : 7;
}
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
int v1; // er8
__int64 result; // rax
int v3; // edx
int v4; // er8
struct stat v5; // [rsp-18h] [rbp-98h] BYREF

if ( !a1 )
return 5LL;
v1 = stat(a1, &v5);
result = 10LL;
if ( !v1 )
{
v3 = v5.st_mode & 0xF000;
switch ( v3 )
{
case 24576:
result = 5LL;
break;
case 8192:
result = 6LL;
break;
case 16384:
result = 2LL;
break;
case 4096:
result = 8LL;
break;
case 40960:
result = 3LL;
break;
default:
result = 1LL;
if ( v3 != 0x8000 )
{
v4 = S_ISSOCK();
result = 4LL;
if ( !v4 )
result = (unsigned int)S_ISWHT(v5.st_mode) == 0 ? 9 : 7;
}
break;
}
}
return result;
}

original_code:
pakman_error_t
pakman_exists(const char *path)
{
 struct stat sb;
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 if(stat(path, &sb))
  return PAKMAN_ERROR_FILENEXISTS;
 if(((((sb.st_mode)) & 0170000) == (0060000)))
  return PAKMAN_FILE_BLOCK;
 else if(((((sb.st_mode)) & 0170000) == (0020000)))
  return PAKMAN_FILE_CHAR;
 else if(((((sb.st_mode)) & 0170000) == (0040000)))
  return PAKMAN_FILE_DIRECTORY;
 else if(((((sb.st_mode)) & 0170000) == (0010000)))
  return PAKMAN_FILE_FIFO;
 else if(((((sb.st_mode)) & 0170000) == (0120000)))
  return PAKMAN_FILE_SYMBOLIC;
 else if(((((sb.st_mode)) & 0170000) == (0100000)))
  return PAKMAN_FILE_REGULAR;
 else if(S_ISSOCK(sb.st_mode))
  return PAKMAN_FILE_SOCKET;
 else if(S_ISWHT(sb.st_mode))
  return PAKMAN_FILE_WHITEOUT;
 return PAKMAN_FILE_UNKNOWN;
}

canonical_original_code:
enum pakman_error_t pakman_exists(char *path)
{
 struct stat sb;
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 if(stat(path, &sb))
  return PAKMAN_ERROR_FILENEXISTS;
 if(((((sb.st_mode)) & 0170000) == (0060000)))
  return PAKMAN_FILE_BLOCK;
 else if(((((sb.st_mode)) & 0170000) == (0020000)))
  return PAKMAN_FILE_CHAR;
 else if(((((sb.st_mode)) & 0170000) == (0040000)))
  return PAKMAN_FILE_DIRECTORY;
 else if(((((sb.st_mode)) & 0170000) == (0010000)))
  return PAKMAN_FILE_FIFO;
 else if(((((sb.st_mode)) & 0170000) == (0120000)))
  return PAKMAN_FILE_SYMBOLIC;
 else if(((((sb.st_mode)) & 0170000) == (0100000)))
  return PAKMAN_FILE_REGULAR;
 else if(S_ISSOCK(sb.st_mode))
  return PAKMAN_FILE_SOCKET;
 else if(S_ISWHT(sb.st_mode))
  return PAKMAN_FILE_WHITEOUT;
 return PAKMAN_FILE_UNKNOWN;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall pakman_mkdir(char *file, __mode_t mode, __uid_t uid, __gid_t gid)
{
int v7; // eax
unsigned int v8; // er13
struct passwd *v9; // r13
struct group *v10; // rax

if ( file )
{
if ( *file == 47 && !file[1] )
return 1LL;
if ( !*file )
return 1LL;
fprintf(stdout, "%s: %s...", "pakman_mkdir", file);
v7 = pakman_exists(file);
if ( v7 == 10 )
{
fwrite("Mkdir...", 1uLL, 8uLL, stdout);
if ( mkdir(file, mode) )
{
v8 = 8;
goto LABEL_9;
}
if ( uid != 99999 )
{
v9 = getpwuid(uid);
v10 = getgrgid(gid);
fprintf(stdout, "Chowning to: %s:%s...", v9->pw_name, v10->gr_name);
v8 = pakman_chown(file, uid, gid);
if ( v8 != 1 )
goto LABEL_9;
}
if ( mode != 8888 )
{
fprintf(stdout, "Chmod'ing to: %o...", mode);
v8 = pakman_chmod(file, mode);
if ( v8 != 1 )
goto LABEL_9;
}
}
else
{
v8 = 11;
if ( v7 != 2 )
{
LABEL_9:
fprintf(stdout, "Could not fully create %s\n", file);
return v8;
}
fwrite("Skipping mkdir...", 1uLL, 0x11uLL, stdout);
}
fwrite("Done!\n", 1uLL, 6uLL, stdout);
return 1LL;
}
return 5LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *file, __mode_t mode, __uid_t uid, __gid_t gid)
{
int v7; // eax
unsigned int v8; // er13
struct passwd *v9; // r13
struct group *v10; // rax

if ( file )
{
if ( *file == 47 && !file[1] )
return 1LL;
if ( !*file )
return 1LL;
fprintf(stdout, "%s: %s...", "pakman_mkdir", file);
v7 = func4(file);
if ( v7 == 10 )
{
fwrite("Mkdir...", 1uLL, 8uLL, stdout);
if ( mkdir(file, mode) )
{
v8 = 8;
goto LABEL_9;
}
if ( uid != 99999 )
{
v9 = getpwuid(uid);
v10 = getgrgid(gid);
fprintf(stdout, "Chowning to: %s:%s...", v9->pw_name, v10->gr_name);
v8 = func1(file, uid, gid);
if ( v8 != 1 )
goto LABEL_9;
}
if ( mode != 8888 )
{
fprintf(stdout, "Chmod'ing to: %o...", mode);
v8 = func2(file, mode);
if ( v8 != 1 )
goto LABEL_9;
}
}
else
{
v8 = 11;
if ( v7 != 2 )
{
LABEL_9:
fprintf(stdout, "Could not fully create %s\n", file);
return v8;
}
fwrite("Skipping mkdir...", 1uLL, 0x11uLL, stdout);
}
fwrite("Done!\n", 1uLL, 6uLL, stdout);
return 1LL;
}
return 5LL;
}

original_code:
pakman_error_t
pakman_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid)
{
 pakman_error_t r = PAKMAN_ERROR_NOERROR;
 pakman_file_type_t ft;
 struct passwd *uidp;
 struct group *gidp;
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 if(!strcmp(path, "/"))
  return r;
 if(strlen(path) < 1)
  return r;
 fprintf(stdout, "%s: %s...", __FUNCTION__, path);
 ft = pakman_exists(path);
 if(ft == PAKMAN_ERROR_FILENEXISTS)
 {
  fprintf(stdout, "Mkdir...");
  if(mkdir(path, mode))
  {
   r = PAKMAN_ERROR_OSERROR;
   goto pakman_mkdir_exit;
  }
 } else {
  if(ft == PAKMAN_FILE_DIRECTORY)
  {
   fprintf(stdout, "Skipping mkdir...");
   r = PAKMAN_ERROR_NOERROR;
   goto pakman_mkdir_exit;
  } else {
   r = PAKMAN_ERROR_NOTDIR;
   goto pakman_mkdir_exit;
  }
 }
 if(uid != 99999)
 {
  uidp = getpwuid(uid);
  gidp = getgrgid(gid);
  fprintf(stdout, "Chowning to: %s:%s...", uidp->pw_name, gidp->gr_name);
  r = pakman_chown(path, uid, gid);
  if(r != PAKMAN_ERROR_NOERROR)
   goto pakman_mkdir_exit;
 }
 if(mode != 8888)
 {
  fprintf(stdout, "Chmod'ing to: %o...", mode);
  r = pakman_chmod(path, mode);
  if(r != PAKMAN_ERROR_NOERROR)
   goto pakman_mkdir_exit;
 }
pakman_mkdir_exit:
 if(r == PAKMAN_ERROR_NOERROR)
  fprintf(stdout, "Done!\n");
 else
  fprintf(stdout, "Could not fully create %s\n", path);
 return r;
}

canonical_original_code:
enum pakman_error_t pakman_mkdir(char *path, unsigned int mode, unsigned int uid, unsigned int gid)
{
 enum pakman_error_t r = PAKMAN_ERROR_NOERROR;
 enum pakman_file_type_t ft;
 struct passwd *uidp;
 struct group *gidp;
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 if(!strcmp(path, "/"))
  return r;
 if(strlen(path) < 1)
  return r;
 fprintf(stdout, "%s: %s...", __FUNCTION__, path);
 ft = pakman_exists(path);
 if(ft == PAKMAN_ERROR_FILENEXISTS)
 {
  fprintf(stdout, "Mkdir...");
  if(mkdir(path, mode))
  {
   r = PAKMAN_ERROR_OSERROR;
   goto pakman_mkdir_exit;
  }
 } else {
  if(ft == PAKMAN_FILE_DIRECTORY)
  {
   fprintf(stdout, "Skipping mkdir...");
   r = PAKMAN_ERROR_NOERROR;
   goto pakman_mkdir_exit;
  } else {
   r = PAKMAN_ERROR_NOTDIR;
   goto pakman_mkdir_exit;
  }
 }
 if(uid != 99999)
 {
  uidp = getpwuid(uid);
  gidp = getgrgid(gid);
  fprintf(stdout, "Chowning to: %s:%s...", uidp->pw_name, gidp->gr_name);
  r = pakman_chown(path, uid, gid);
  if(r != PAKMAN_ERROR_NOERROR)
   goto pakman_mkdir_exit;
 }
 if(mode != 8888)
 {
  fprintf(stdout, "Chmod'ing to: %o...", mode);
  r = pakman_chmod(path, mode);
  if(r != PAKMAN_ERROR_NOERROR)
   goto pakman_mkdir_exit;
 }
pakman_mkdir_exit:
 if(r == PAKMAN_ERROR_NOERROR)
  fprintf(stdout, "Done!\n");
 else
  fprintf(stdout, "Could not fully create %s\n", path);
 return r;
}

variable_types: enum pakman_error_t { PAKMAN_ERROR_DUMMY1=0, PAKMAN_ERROR_NOERROR=1, PAKMAN_ERROR_UNDEF=2, PAKMAN_ERROR_NOTIMPL=3, PAKMAN_ERROR_NARGS=4, PAKMAN_ERROR_INVARGS=5, PAKMAN_ERROR_DBERROR=6, PAKMAN_ERROR_DBEXISTS=7, PAKMAN_ERROR_OSERROR=8, PAKMAN_ERROR_SHAFAILS=9, PAKMAN_ERROR_FILENEXISTS=10, PAKMAN_ERROR_NOTDIR=11, PAKMAN_ERROR_NOTFILE=12, PAKMAN_ERROR_PKGINSTALLED=13, PAKMAN_ERROR_PKGNINSTALLED=14, PAKMAN_ERROR_PKGAINSTALLED=15, PAKMAN_ERROR_FILEEXISTS=16, PAKMAN_ERROR_KEYNOTFOUND=17, PAKMAN_ERROR_DEPNOTFOUND=18, PAKMAN_ERROR_PKGPROTECTED=19, PAKMAN_ERROR_DUMMY2=20 }

variable_types: enum pakman_file_type_t { PAKMAN_FILE_ERROR=0, PAKMAN_FILE_REGULAR=1, PAKMAN_FILE_DIRECTORY=2, PAKMAN_FILE_SYMBOLIC=3, PAKMAN_FILE_SOCKET=4, PAKMAN_FILE_BLOCK=5, PAKMAN_FILE_CHAR=6, PAKMAN_FILE_WHITEOUT=7, PAKMAN_FILE_FIFO=8, PAKMAN_FILE_UNKNOWN=9 }

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

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


decompiled_code:
__int64 __fastcall pakman_rmkdir(char *s, __mode_t a2, __uid_t a3, __gid_t a4)
{
int v5; // ebp
size_t v6; // rdx
char *v7; // r13
__int64 result; // rax
int v9; // ebx
char *v10; // [rsp+8h] [rbp-450h]
char file[1080]; // [rsp+20h] [rbp-438h] BYREF

if ( !s )
return 5LL;
v5 = 0;
fprintf(stdout, "%s: %s...\n", "pakman_rmkdir", s);
v6 = strlen(s);
v10 = &s[v6];
memset(file, 0, 0x400uLL);
if ( v6 > 1 )
{
v5 = 1;
file[0] = *s;
}
while ( 1 )
{
v7 = &s[v5];
if ( v7 >= v10 )
break;
if ( *v7 == 47 )
{
v9 = v5 - 1;
if ( strlen(s) > v5 )
{
v9 = v5++;
v7 = &s[v5];
}
result = pakman_mkdir(file, a2, a3, a4);
file[v9] = 47;
if ( v10 <= v7 || (_DWORD)result != 1 )
return result;
}
else
{
file[v5++] = *v7;
}
}
return pakman_mkdir(file, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s, __mode_t a2, __uid_t a3, __gid_t a4)
{
int v5; // ebp
size_t v6; // rdx
char *v7; // r13
__int64 result; // rax
int v9; // ebx
char *v10; // [rsp+8h] [rbp-450h]
char file[1080]; // [rsp+20h] [rbp-438h] BYREF

if ( !s )
return 5LL;
v5 = 0;
fprintf(stdout, "%s: %s...\n", "pakman_rmkdir", s);
v6 = strlen(s);
v10 = &s[v6];
memset(file, 0, 0x400uLL);
if ( v6 > 1 )
{
v5 = 1;
file[0] = *s;
}
while ( 1 )
{
v7 = &s[v5];
if ( v7 >= v10 )
break;
if ( *v7 == 47 )
{
v9 = v5 - 1;
if ( strlen(s) > v5 )
{
v9 = v5++;
v7 = &s[v5];
}
result = func5(file, a2, a3, a4);
file[v9] = 47;
if ( v10 <= v7 || (_DWORD)result != 1 )
return result;
}
else
{
file[v5++] = *v7;
}
}
return func5(file, a2, a3, a4);
}

original_code:
pakman_error_t
pakman_rmkdir(const char *path, mode_t mode, uid_t uid, gid_t gid)
{
 char *start;
 char *end;
 char buffer[1024];
 int i;
 pakman_error_t r = PAKMAN_ERROR_NOERROR;
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 fprintf(stdout, "%s: %s...\n", __FUNCTION__, path);
 start = (char *)path;
 end = start + strlen(start);
 i = 0;
 memset(buffer, 0, sizeof(buffer));
 if(strlen(path) > 1)
 {
  buffer[i] = start[i];
  i = 1;
 }
 do
 {
  for(; (start + i) < end; i++)
  {
   if(start[i] == '/')
   {
    if(strlen(path) > i)
     i++;
    break;
   } else
    buffer[i] = start[i];
  }
  r = pakman_mkdir(buffer, mode, uid, gid);
  buffer[i-1] = '/';
 } while(((start + i) < end) && (r == PAKMAN_ERROR_NOERROR));
 return r;
}

canonical_original_code:
enum pakman_error_t pakman_rmkdir(char *path, unsigned int mode, unsigned int uid, unsigned int gid)
{
 char *start;
 char *end;
 char buffer[1024];
 int i;
 enum pakman_error_t r = PAKMAN_ERROR_NOERROR;
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 fprintf(stdout, "%s: %s...\n", __FUNCTION__, path);
 start = (char *)path;
 end = start + strlen(start);
 i = 0;
 memset(buffer, 0, sizeof(buffer));
 if(strlen(path) > 1)
 {
  buffer[i] = start[i];
  i = 1;
 }
 do
 {
  for(; (start + i) < end; i++)
  {
   if(start[i] == '/')
   {
    if(strlen(path) > i)
     i++;
    break;
   } else
    buffer[i] = start[i];
  }
  r = pakman_mkdir(buffer, mode, uid, gid);
  buffer[i-1] = '/';
 } while(((start + i) < end) && (r == PAKMAN_ERROR_NOERROR));
 return r;
}

variable_types:
start
char *

variable_types:
end
char *

variable_types:
buffer
char [1024]

variable_types: i int


decompiled_code:
__int64 __fastcall pakman_utimes(const char *a1, __time_t a2, __int64 a3)
{
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+10h] [rbp-18h]
__int64 v6; // [rsp+18h] [rbp-10h]

if ( !a1 )
return 5LL;
v4.tv_sec = a2;
v4.tv_usec = 0LL;
v5 = a3;
v6 = 0LL;
return lutimes(a1, &v4) == 0 ? 1 : 8;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, __time_t a2, __int64 a3)
{
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+10h] [rbp-18h]
__int64 v6; // [rsp+18h] [rbp-10h]

if ( !a1 )
return 5LL;
v4.tv_sec = a2;
v4.tv_usec = 0LL;
v5 = a3;
v6 = 0LL;
return lutimes(a1, &v4) == 0 ? 1 : 8;
}

original_code:
pakman_error_t
pakman_utimes(const char *path, time_t a, time_t m, time_t c)
{
 struct timeval t[2];
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 t[0].tv_sec = a;
 t[0].tv_usec = 0;
 t[1].tv_sec = m;
 t[1].tv_usec = 0;
 if(lutimes(path, (struct timeval *)&t))
  return PAKMAN_ERROR_OSERROR;
 else
  return PAKMAN_ERROR_NOERROR;
}

canonical_original_code:
enum pakman_error_t pakman_utimes(char *path, long a, long m, long c)
{
 struct timeval t[2];
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 t[0].tv_sec = a;
 t[0].tv_usec = 0;
 t[1].tv_sec = m;
 t[1].tv_usec = 0;
 if(lutimes(path, (struct timeval *)&t))
  return PAKMAN_ERROR_OSERROR;
 else
  return PAKMAN_ERROR_NOERROR;
}

variable_types: a long

variable_types: m long

variable_types: c long

variable_types: struct timeval { long tv_sec; long tv_usec; } [2]


decompiled_code:
__int64 __fastcall pakman_rm(const char *a1)
{
__int64 result; // rax

if ( a1 )
result = unlink(a1) == 0 ? 1 : 8;
else
result = 5LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
__int64 result; // rax

if ( a1 )
result = unlink(a1) == 0 ? 1 : 8;
else
result = 5LL;
return result;
}

original_code:
pakman_error_t
pakman_rm(const char *path)
{
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 if(unlink(path))
  return PAKMAN_ERROR_OSERROR;
 else
  return PAKMAN_ERROR_NOERROR;
}

canonical_original_code:
enum pakman_error_t pakman_rm(char *path)
{
 if(!path)
  return PAKMAN_ERROR_INVARGS;
 if(unlink(path))
  return PAKMAN_ERROR_OSERROR;
 else
  return PAKMAN_ERROR_NOERROR;
}

variable_types:
path
char *


decompiled_code:
const char *__fastcall pakman_strcmd(int a1)
{
const char *result; // rax

result = "NULL. Not a command?";
if ( (unsigned int)(a1 - 1) <= 9 )
result = COMMANDS_STR[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

result = "NULL. Not a command?";
if ( (unsigned int)(a1 - 1) <= 9 )
result = COMMANDS_STR[a1];
return result;
}

original_code:
const char *
pakman_strcmd(pakman_cmd_t c)
{
 if((c > PAKMAN_CMD_DUMMY1) && (c < PAKMAN_CMD_DUMMY2))
  return COMMANDS_STR[c];
 else
  return "NULL. Not a command?";
}

canonical_original_code:
char *pakman_strcmd(enum pakman_cmd_t c)
{
 if((c > PAKMAN_CMD_DUMMY1) && (c < PAKMAN_CMD_DUMMY2))
  return COMMANDS_STR[c];
 else
  return "NULL. Not a command?";
}

variable_types: enum pakman_cmd_t { PAKMAN_CMD_DUMMY1=0, PAKMAN_CMD_SHOW=1, PAKMAN_CMD_QUERY=2, PAKMAN_CMD_SEARCH=3, PAKMAN_CMD_INSTALL=4, PAKMAN_CMD_DEINSTALL=5, PAKMAN_CMD_VERIFY=6, PAKMAN_CMD_CREATEDB=7, PAKMAN_CMD_HELP=8, PAKMAN_CMD_CREATE=9, PAKMAN_CMD_UPDATE=10, PAKMAN_CMD_DUMMY2=11 }

return_type: char *


decompiled_code:
const char *__fastcall pakman_strcmddesc(int a1)
{
const char *result; // rax

result = "NULL. Not a command?";
if ( (unsigned int)(a1 - 1) <= 9 )
result = COMMANDS_DESCR[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
const char *result; // rax

result = "NULL. Not a command?";
if ( (unsigned int)(a1 - 1) <= 9 )
result = COMMANDS_DESCR[a1];
return result;
}

original_code:
const char *
pakman_strcmddesc(pakman_cmd_t c)
{
 if((c > PAKMAN_CMD_DUMMY1) && (c < PAKMAN_CMD_DUMMY2))
  return COMMANDS_DESCR[c];
 else
  return "NULL. Not a command?";
}

canonical_original_code:
char *pakman_strcmddesc(enum pakman_cmd_t c)
{
 if((c > PAKMAN_CMD_DUMMY1) && (c < PAKMAN_CMD_DUMMY2))
  return COMMANDS_DESCR[c];
 else
  return "NULL. Not a command?";
}

user_defined_types: enum pakman_cmd_t { PAKMAN_CMD_DUMMY1=0, PAKMAN_CMD_SHOW=1, PAKMAN_CMD_QUERY=2, PAKMAN_CMD_SEARCH=3, PAKMAN_CMD_INSTALL=4, PAKMAN_CMD_DEINSTALL=5, PAKMAN_CMD_VERIFY=6, PAKMAN_CMD_CREATEDB=7, PAKMAN_CMD_HELP=8, PAKMAN_CMD_CREATE=9, PAKMAN_CMD_UPDATE=10, PAKMAN_CMD_DUMMY2=11 }


decompiled_code:
const char *__fastcall pakman_pkg_strstatus(int a1)
{
const char *result; // rax

result = "NULL. Not a status?";
if ( (unsigned int)(a1 - 1) <= 2 )
result = (&PAKMAN_PKG_STATUS_STR)[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(int a1)
{
const char *result; // rax

result = "NULL. Not a status?";
if ( (unsigned int)(a1 - 1) <= 2 )
result = (&PAKMAN_PKG_STATUS_STR)[a1];
return result;
}

original_code:
const char *
pakman_pkg_strstatus(pakman_pstatus_t c)
{
 if((c > PAKMAN_PKG_DUMMY1) && (c < PAKMAN_PKG_DUMMY2))
  return PAKMAN_PKG_STATUS_STR[c];
 else
  return "NULL. Not a status?";
}

canonical_original_code:
char *pakman_pkg_strstatus(enum pakman_pstatus_t c)
{
 if((c > PAKMAN_PKG_DUMMY1) && (c < PAKMAN_PKG_DUMMY2))
  return PAKMAN_PKG_STATUS_STR[c];
 else
  return "NULL. Not a status?";
}

variable_types: enum pakman_pstatus_t { PAKMAN_PKG_DUMMY1=0, PAKMAN_PKG_INSTALLED=1, PAKMAN_PKG_INSTALLING=2, PAKMAN_PKG_REMOVED=3, PAKMAN_PKG_DUMMY2=4 }


decompiled_code:
__int64 __fastcall pakman_pkg_getstatus(__int64 a1)
{
unsigned int v1; // er12
const char *v2; // rax

if ( !a1 )
return 5LL;
v1 = 1;
while ( 1 )
{
v2 = pakman_pkg_strstatus(v1);
if ( !strcmp(v2, (const char *)(a1 + 5368)) )
break;
if ( ++v1 == 4 )
return 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v1; // er12
const char *v2; // rax

if ( !a1 )
return 5LL;
v1 = 1;
while ( 1 )
{
v2 = func2(v1);
if ( !strcmp(v2, (const char *)(a1 + 5368)) )
break;
if ( ++v1 == 4 )
return 0;
}
return v1;
}

original_code:
pakman_pstatus_t
pakman_pkg_getstatus(pakman_header_t *hdr)
{
 pakman_pstatus_t i;
 if(!hdr)
  return PAKMAN_ERROR_INVARGS;
 for(i = PAKMAN_PKG_DUMMY1 + 1; i < PAKMAN_PKG_DUMMY2; i++)
  if(!strcmp(pakman_pkg_strstatus(i), hdr->status2))
   break;
 return i == PAKMAN_PKG_DUMMY2 ? 0 : i;
}

canonical_original_code:
enum pakman_pstatus_t pakman_pkg_getstatus(struct pakman_header_t *hdr)
{
 enum pakman_pstatus_t i;
 if(!hdr)
  return PAKMAN_ERROR_INVARGS;
 for(i = PAKMAN_PKG_DUMMY1 + 1; i < PAKMAN_PKG_DUMMY2; i++)
  if(!strcmp(pakman_pkg_strstatus(i), hdr->status2))
   break;
 return i == PAKMAN_PKG_DUMMY2 ? 0 : i;
}

variable_types: struct pakman_header_t { char name[128]; long time; long time2; long files; long directories; char version[16]; char arch[8]; char description[1024]; char prefix[4096]; char status1[64]; char status2[64]; char depends[1024]; } *

return_type: enum pakman_pstatus_t { PAKMAN_PKG_DUMMY1=0, PAKMAN_PKG_INSTALLED=1, PAKMAN_PKG_INSTALLING=2, PAKMAN_PKG_REMOVED=3, PAKMAN_PKG_DUMMY2=4 }


decompiled_code:
void *__fastcall pakman_malloc(size_t a1)
{
return calloc(a1, 1uLL);
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
return calloc(a1, 1uLL);
}

original_code:
void *
pakman_malloc(long size)
{
 void *b = malloc(size);
 if(b)
  memset(b, 0, size);
 return b;
}

canonical_original_code:
void *pakman_malloc(long size)
{
 void *b = malloc(size);
 if(b)
  memset(b, 0, size);
 return b;
}

variable_types: size long

variable_types:
b
void *

return_type: void *


decompiled_code:
void __fastcall pakman_free(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void
pakman_free(void *b)
{
 if(b)
  free(b);
}


decompiled_code:
int __fastcall gdbm_error_handler(const char *a1)
{
int result; // eax

if ( a1 )
result = fprintf(stdout, "%s: %s.\n", "gdbm_error_handler", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax

if ( a1 )
result = fprintf(stdout, "%s: %s.\n", "gdbm_error_handler", a1);
return result;
}

original_code:
static void
gdbm_error_handler(char *str)
{
 if(!str)
  return;
 fprintf(stdout, "%s: %s.\n", __FUNCTION__, str);
 return;
}

variable_types:
str
char *


decompiled_code:
__int64 pakman_db_version()
{
return gdbm_version;
}

canonical_decompiled_code:
__int64 func1()
{
return gdbm_version;
}

original_code:
const char *
pakman_db_version(void)
{
 return gdbm_version;
}

canonical_original_code:
char *pakman_db_version()
{
 return gdbm_version;
}


decompiled_code:
const char *__fastcall pakman_strerror(int a1)
{
const char *result; // rax

result = "NULL. Not an errorcode?";
if ( (unsigned int)(a1 - 1) <= 0x12 )
result = (&PAKMAN_ERROR_STR)[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

result = "NULL. Not an errorcode?";
if ( (unsigned int)(a1 - 1) <= 0x12 )
result = (&PAKMAN_ERROR_STR)[a1];
return result;
}

original_code:
const char *
pakman_strerror(pakman_error_t e)
{
 if((e > PAKMAN_ERROR_DUMMY1) && (e < PAKMAN_ERROR_DUMMY2))
  return PAKMAN_ERROR_STR[e];
 else
  return "NULL. Not an errorcode?";
}

canonical_original_code:
char *pakman_strerror(enum pakman_error_t e)
{
 if((e > PAKMAN_ERROR_DUMMY1) && (e < PAKMAN_ERROR_DUMMY2))
  return PAKMAN_ERROR_STR[e];
 else
  return "NULL. Not an errorcode?";
}

variable_types: enum pakman_error_t { PAKMAN_ERROR_DUMMY1=0, PAKMAN_ERROR_NOERROR=1, PAKMAN_ERROR_UNDEF=2, PAKMAN_ERROR_NOTIMPL=3, PAKMAN_ERROR_NARGS=4, PAKMAN_ERROR_INVARGS=5, PAKMAN_ERROR_DBERROR=6, PAKMAN_ERROR_DBEXISTS=7, PAKMAN_ERROR_OSERROR=8, PAKMAN_ERROR_SHAFAILS=9, PAKMAN_ERROR_FILENEXISTS=10, PAKMAN_ERROR_NOTDIR=11, PAKMAN_ERROR_NOTFILE=12, PAKMAN_ERROR_PKGINSTALLED=13, PAKMAN_ERROR_PKGNINSTALLED=14, PAKMAN_ERROR_PKGAINSTALLED=15, PAKMAN_ERROR_FILEEXISTS=16, PAKMAN_ERROR_KEYNOTFOUND=17, PAKMAN_ERROR_DEPNOTFOUND=18, PAKMAN_ERROR_PKGPROTECTED=19, PAKMAN_ERROR_DUMMY2=20 }


repo: marchalvincent/BatailleNavale

decompiled_code:
__int64 new_event_num()
{
unsigned int v0; // er12

if ( !event_num )
pthread_mutex_init(&event_lock, 0LL);
pthread_mutex_lock(&event_lock);
v0 = event_num++;
pthread_mutex_unlock(&event_lock);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er12

if ( !event_num )
pthread_mutex_init(&event_lock, 0LL);
pthread_mutex_lock(&event_lock);
v0 = event_num++;
pthread_mutex_unlock(&event_lock);
return v0;
}

original_code:
static int new_event_num ()
{
   int res;
   if (_event_num == 0) pthread_mutex_init (&_event_lock,((void *)0));
   pthread_mutex_lock (&_event_lock);
   res = _event_num++;
   pthread_mutex_unlock (&_event_lock);
   return res;
}

canonical_original_code:
static int new_event_num()
{
   int res;
   if (_event_num == 0) pthread_mutex_init (&_event_lock,((void *)0));
   pthread_mutex_lock (&_event_lock);
   res = _event_num++;
   pthread_mutex_unlock (&_event_lock);
   return res;
}

variable_types: res int


main

repo: marcinbis/mb-rt-data

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct sched_param param; // [rsp+Ch] [rbp-Ch] BYREF

new_controller(argc, argv, envp);
new_msg();
new_io();
param.__sched_priority = 52;
if ( sched_setscheduler(0, 1, &param) == -1 )
printf("[%s:%d:%s()]: sched_setscheduler() failed\n", "main.c", 35LL, "main");
if ( mlockall(3) == -1 )
printf("[%s:%d:%s()]: mlockall() failed\n", "main.c", 41LL, "main");
while ( 1 )
do_fsm_step();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct sched_param param; // [rsp+Ch] [rbp-Ch] BYREF

func16(argc, argv, envp);
func14();
func10();
param.__sched_priority = 52;
if ( sched_setscheduler(0, 1, &param) == -1 )
printf("[%s:%d:%s()]: sched_setscheduler() failed\n", "main.c", 35LL, "main");
if ( mlockall(3) == -1 )
printf("[%s:%d:%s()]: mlockall() failed\n", "main.c", 41LL, "main");
while ( 1 )
func17();
}

original_code:
int main(int argc, char ** argv)
{
 struct sched_param sp;
 struct controller_t * c = new_controller();
 struct msg_t * msg = new_msg();
 struct io_t * io = new_io();
 sp.sched_priority = 52;
 if (sched_setscheduler(0, 1, &sp) == -1)
        {
                printf("[%s:%d:%s()]: " "sched_setscheduler() failed" "\n", "main.c", 35, __func__);
        }
 if (mlockall( 1|2 ) == -1)
 {
  printf("[%s:%d:%s()]: " "mlockall() failed" "\n", "main.c", 41, __func__);
 }
 while (1)
 {
  do_fsm_step();
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct sched_param sp;
 struct controller_t *c = new_controller();
 struct msg_t *msg = new_msg();
 struct io_t *io = new_io();
 sp.sched_priority = 52;
 if (sched_setscheduler(0, 1, &sp) == -1)
        {
                printf("[%s:%d:%s()]: " "sched_setscheduler() failed" "\n", "main.c", 35, __func__);
        }
 if (mlockall( 1|2 ) == -1)
 {
  printf("[%s:%d:%s()]: " "mlockall() failed" "\n", "main.c", 41, __func__);
 }
 while (1)
 {
  do_fsm_step();
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct sched_param { int sched_priority; }

variable_types: struct controller_t { int (*get_pwm_work)(struct controller_t *); int shm_fd; struct shm_content_t { int pwm_work; } *shm_content; } *

variable_types: struct msg_t { int (*put)(struct msg_t *, int); int mq; } *

variable_types: struct io_t { void (*wait_for_foot_switch)(struct io_t *); void (*pwm_set)(struct io_t *, int); } *

user_defined_types: struct controller_t { int (*get_pwm_work)(struct controller_t *); int shm_fd; struct shm_content_t *shm_content; }


decompiled_code:
unsigned int wait_for_foot_switch()
{
printf("[%s:%d:%s()]: wait_for_foot_switch\n", "io.c", 44LL, "wait_for_foot_switch");
return sleep(5u);
}

canonical_decompiled_code:
unsigned int func7()
{
printf("[%s:%d:%s()]: wait_for_foot_switch\n", "io.c", 44LL, "wait_for_foot_switch");
return sleep(5u);
}

original_code:
void wait_for_foot_switch(struct io_t * io)
{
 printf("[%s:%d:%s()]: " "wait_for_foot_switch" "\n", "io.c", 44, __func__);
 sleep(5);
 return;
}

canonical_original_code:
void wait_for_foot_switch(struct io_t *io)
{
 printf("[%s:%d:%s()]: " "wait_for_foot_switch" "\n", "io.c", 44, __func__);
 sleep(5);
 return;
}

user_defined_types: struct io_t { void (*wait_for_foot_switch)(struct io_t *); void (*pwm_set)(struct io_t *, int); }


decompiled_code:
int __fastcall pwm_set(__int64 a1, unsigned int a2)
{
set_pulse(a2);
return printf("[%s:%d:%s()]: pwm_work set to: %d\n", "io.c", 56LL, "pwm_set", a2);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, unsigned int a2)
{
func12(a2);
return printf("[%s:%d:%s()]: pwm_work set to: %d\n", "io.c", 56LL, "pwm_set", a2);
}

original_code:
void pwm_set(struct io_t * io, int pwm_work)
{
 set_pulse(pwm_work);
 printf("[%s:%d:%s()]: " "pwm_work set to: %d" "\n", "io.c", 56, __func__, pwm_work);
}

canonical_original_code:
void pwm_set(struct io_t *io, int pwm_work)
{
 set_pulse(pwm_work);
 printf("[%s:%d:%s()]: " "pwm_work set to: %d" "\n", "io.c", 56, __func__, pwm_work);
}


decompiled_code:
__int64 __fastcall new_io_tail(unsigned int (**a1)())
{
*a1 = wait_for_foot_switch;
a1[1] = (unsigned int (*)())pwm_set;
return init_hardware();
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int (**a1)())
{
*a1 = wait_for_foot_switch;
a1[1] = (unsigned int (*)())pwm_set;
return func11();
}

original_code:
void new_io_tail(struct io_t * io)
{
 io->wait_for_foot_switch = &wait_for_foot_switch;
 io->pwm_set = &pwm_set;
 init_hardware();
}

canonical_original_code:
void new_io_tail(struct io_t *io)
{
 io->wait_for_foot_switch = &wait_for_foot_switch;
 io->pwm_set = &pwm_set;
 init_hardware();
}


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

result = io_3;
if ( !io_3 )
{
io_3 = (__int64)malloc(0x10uLL);
new_io_tail((unsigned int (**)())io_3);
printf("[%s:%d:%s()]: io_t: inicialized\n", "io.c", 31LL, "new_io");
result = io_3;
}
return result;
}

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

result = io_3;
if ( !io_3 )
{
io_3 = (__int64)malloc(0x10uLL);
func9((unsigned int (**)())io_3);
printf("[%s:%d:%s()]: io_t: inicialized\n", "io.c", 31LL, "new_io");
result = io_3;
}
return result;
}

original_code:
struct io_t * new_io(void)
{
 static struct io_t * io = ((void *)0);
 if (io == ((void *)0))
 {
  io = malloc(sizeof(struct io_t));
  new_io_tail(io);
  printf("[%s:%d:%s()]: " "io_t: inicialized" "\n", "io.c", 31, __func__);
 }
 return io;
}

canonical_original_code:
struct io_t *new_io()
{
 static struct io_t *io = ((void *)0);
 if (io == ((void *)0))
 {
  io = malloc(sizeof(struct io_t));
  new_io_tail(io);
  printf("[%s:%d:%s()]: " "io_t: inicialized" "\n", "io.c", 31, __func__);
 }
 return io;
}

return_type: struct io_t { void (*wait_for_foot_switch)(struct io_t *); void (*pwm_set)(struct io_t *, int); } *


decompiled_code:
int init_hardware()
{
return printf("[%s:%d:%s()]: Hardware initialized.\n\n", "pwm.c", 8LL, "init_hardware");
}

canonical_decompiled_code:
int func11()
{
return printf("[%s:%d:%s()]: Hardware initialized.\n\n", "pwm.c", 8LL, "init_hardware");
}

original_code:
void init_hardware(void)
{
 printf("[%s:%d:%s()]: " "Hardware initialized.\n" "\n", "pwm.c", 8, __func__);
}

canonical_original_code:
void init_hardware()
{
 printf("[%s:%d:%s()]: " "Hardware initialized.\n" "\n", "pwm.c", 8, __func__);
}


decompiled_code:
int __fastcall set_pulse(unsigned int a1)
{
return printf("[%s:%d:%s()]: Pulse set to: %d\n\n", "pwm.c", 13LL, "set_pulse", a1);
}

canonical_decompiled_code:
int __fastcall func12(unsigned int a1)
{
return printf("[%s:%d:%s()]: Pulse set to: %d\n\n", "pwm.c", 13LL, "set_pulse", a1);
}

original_code:
void set_pulse(int val)
{
 printf("[%s:%d:%s()]: " "Pulse set to: %d\n" "\n", "pwm.c", 13, __func__, val);
}

variable_types: val int


decompiled_code:
__int64 msg_put()
{
struct timespec tp; // [rsp+8h] [rbp-20h] BYREF

clock_gettime(0, &tp);
return mq_send();
}

canonical_decompiled_code:
__int64 func13()
{
struct timespec tp; // [rsp+8h] [rbp-20h] BYREF

clock_gettime(0, &tp);
return mq_send();
}

original_code:
int msg_put(struct msg_t * msg, int msg_id)
{
 message_t m;
 m.msg_id = msg_id;
 clock_gettime(0, &m.msg_timestamp);
 return mq_send(msg->mq, (char *)&m, sizeof(message_t), 0);
}

canonical_original_code:
int msg_put(struct msg_t *msg, int msg_id)
{
 struct message_t m;
 m.msg_id = msg_id;
 clock_gettime(0, &m.msg_timestamp);
 return mq_send(msg->mq, (char *)&m, sizeof(message_t), 0);
}

variable_types: struct message_t { enum STATES { WAIT_FOR_TRIGGER=0, PWM_ON=1, PWM_OFF=2 } msg_id; struct timespec { long tv_sec; long tv_nsec; } msg_timestamp; }

user_defined_types: struct message_t { enum STATES msg_id; struct timespec msg_timestamp; }

user_defined_types: struct msg_t { int (*put)(struct msg_t *, int); int mq; }


decompiled_code:
__int64 new_msg()
{
__int64 result; // rax
_QWORD *v1; // rax
_QWORD *v2; // rbx
int v3; // eax

result = msg_1;
if ( !msg_1 )
{
v1 = malloc(0x10uLL);
*v1 = msg_put;
v2 = v1;
msg_1 = (__int64)v1;
v3 = mq_open();
*((_DWORD *)v2 + 2) = v3;
if ( v3 == -1 )
printf(
"[%s:%d:%s()]: msg_t: message queue open failed, error messages will be dropped\n",
"msg.c",
47LL,
"new_msg");
printf("[%s:%d:%s()]: msg_t: inicialized\n", "msg.c", 50LL, "new_msg");
result = msg_1;
}
return result;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 result; // rax
_QWORD *v1; // rax
_QWORD *v2; // rbx
int v3; // eax

result = msg_1;
if ( !msg_1 )
{
v1 = malloc(0x10uLL);
*v1 = msg_put;
v2 = v1;
msg_1 = (__int64)v1;
v3 = mq_open();
*((_DWORD *)v2 + 2) = v3;
if ( v3 == -1 )
printf(
"[%s:%d:%s()]: msg_t: message queue open failed, error messages will be dropped\n",
"msg.c",
47LL,
"new_msg");
printf("[%s:%d:%s()]: msg_t: inicialized\n", "msg.c", 50LL, "new_msg");
result = msg_1;
}
return result;
}

original_code:
struct msg_t * new_msg(void)
{
 struct mq_attr attr = {
  .mq_flags = 04000,
  .mq_maxmsg = 1024,
  .mq_msgsize = sizeof(message_t),
 };
 static struct msg_t * msg = ((void *)0);
 if (msg == ((void *)0))
 {
  msg = malloc(sizeof(struct msg_t));
  msg->put = &msg_put;
  msg->mq = mq_open("/laser", 01 | 04000 | 0100, 0400 | 0200, &attr);
  if (msg->mq == -1)
  {
   printf("[%s:%d:%s()]: " "msg_t: message queue open failed, error messages will be dropped" "\n", "msg.c", 47, __func__);
  }
  printf("[%s:%d:%s()]: " "msg_t: inicialized" "\n", "msg.c", 50, __func__);
 }
 return msg;
}

canonical_original_code:
struct msg_t *new_msg()
{
 struct mq_attr attr = {
  .mq_flags = 04000,
  .mq_maxmsg = 1024,
  .mq_msgsize = sizeof(message_t),
 };
 static struct msg_t *msg = ((void *)0);
 if (msg == ((void *)0))
 {
  msg = malloc(sizeof(struct msg_t));
  msg->put = &msg_put;
  msg->mq = mq_open("/laser", 01 | 04000 | 0100, 0400 | 0200, &attr);
  if (msg->mq == -1)
  {
   printf("[%s:%d:%s()]: " "msg_t: message queue open failed, error messages will be dropped" "\n", "msg.c", 47, __func__);
  }
  printf("[%s:%d:%s()]: " "msg_t: inicialized" "\n", "msg.c", 50, __func__);
 }
 return msg;
}

variable_types: struct mq_attr { long mq_flags; long mq_maxmsg; long mq_msgsize; long mq_curmsgs; long __pad[4]; }

return_type: struct msg_t { int (*put)(struct msg_t *, int); int mq; } *


decompiled_code:
__int64 __fastcall controller_get_pwm_work(__int64 a1)
{
return **(unsigned int **)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return **(unsigned int **)(a1 + 16);
}

original_code:
int controller_get_pwm_work(struct controller_t * c)
{
 return c->shm_content->pwm_work;
}

canonical_original_code:
int controller_get_pwm_work(struct controller_t *c)
{
 return c->shm_content->pwm_work;
}


decompiled_code:
__int64 new_controller()
{
__int64 v0; // r12
_DWORD *v2; // rax
void *v3; // rax

v0 = c_1;
if ( !c_1 )
{
v2 = malloc(0x18uLL);
*(_QWORD *)v2 = controller_get_pwm_work;
c_1 = (__int64)v2;
v2[2] = shm_open("/laser", 66, 0x180u);
v0 = c_1;
ftruncate(*(_DWORD *)(c_1 + 8), 4LL);
v3 = mmap(0LL, 4uLL, 3, 1, *(_DWORD *)(v0 + 8), 0LL);
*(_QWORD *)(v0 + 16) = v3;
if ( v3 == (void *)-1LL )
{
printf("[%s:%d:%s()]: mmap() failed\n", "controller.c", 40LL, "new_controller");
v0 = c_1;
}
}
return v0;
}

original_code:
struct controller_t * new_controller(void)
{
 static struct controller_t * c = ((void *)0);
 if (c == ((void *)0))
 {
  c = malloc(sizeof(struct controller_t));
  c->get_pwm_work = &controller_get_pwm_work;
  c->shm_fd = shm_open("/laser", 0100 | 02, 0400 | 0200);
  ftruncate(c->shm_fd, (sizeof(shm_content_t)));
  c->shm_content = (shm_content_t *) mmap(((void *)0), (sizeof(shm_content_t)), 0x1 | 0x2, 0x01, c->shm_fd, 0);
  if (c->shm_content == ((void *) -1))
         {
                 printf("[%s:%d:%s()]: " "mmap() failed" "\n", "controller.c", 40, __func__);
         }
 }
 return c;
}

canonical_original_code:
struct controller_t *new_controller()
{
 static struct controller_t *c = ((void *)0);
 if (c == ((void *)0))
 {
  c = malloc(sizeof(struct controller_t));
  c->get_pwm_work = &controller_get_pwm_work;
  c->shm_fd = shm_open("/laser", 0100 | 02, 0400 | 0200);
  ftruncate(c->shm_fd, (sizeof(shm_content_t)));
  c->shm_content = (struct shm_content_t *) mmap(((void *)0), (sizeof(shm_content_t)), 0x1 | 0x2, 0x01, c->shm_fd, 0);
  if (c->shm_content == ((void *) -1))
         {
                 printf("[%s:%d:%s()]: " "mmap() failed" "\n", "controller.c", 40, __func__);
         }
 }
 return c;
}

return_type: struct controller_t { int (*get_pwm_work)(struct controller_t *); int shm_fd; struct shm_content_t { int pwm_work; } *shm_content; } *


decompiled_code:
int do_fsm_step()
{
__int64 v0; // rbp
__int64 (__fastcall **v1)(_QWORD, __int64); // rbx
__int64 (__fastcall **v2)(_QWORD); // r12
int result; // eax
void (__fastcall *v4)(__int64, _QWORD); // rbx
unsigned int v5; // eax
struct timespec v6; // [rsp+0h] [rbp-28h] BYREF

v0 = new_io();
v1 = (__int64 (__fastcall **)(_QWORD, __int64))new_msg();
v2 = (__int64 (__fastcall **)(_QWORD))new_controller();
result = state_1;
switch ( state_1 )
{
case 1:
printf("[%s:%d:%s()]: PWM_ON\n", "fsm.c", 47LL, "do_fsm_step");
(*v1)(v1, 1LL);
clock_gettime(1, &v6);
v4 = *(void (__fastcall **)(__int64, _QWORD))(v0 + 8);
v5 = (*v2)(v2);
v4(v0, v5);
if ( v6.tv_nsec + 900000000 > 999999999 )
{
++v6.tv_sec;
v6.tv_nsec -= 100000000LL;
}
else
{
v6.tv_nsec += 900000000LL;
}
result = clock_nanosleep(1, 1, &v6, 0LL);
state_1 = 2;
break;
case 2:
printf("[%s:%d:%s()]: PWM_OFF\n", "fsm.c", 76LL, "do_fsm_step");
(*(void (__fastcall **)(__int64, _QWORD))(v0 + 8))(v0, 0LL);
result = (*v1)(v1, 2LL);
state_1 = 0;
break;
case 0:
printf("[%s:%d:%s()]: WAIT_FOR_TRIGGER\n", "fsm.c", 39LL, "do_fsm_step");
(*v1)(v1, 0LL);
result = (*(__int64 (__fastcall **)(__int64))v0)(v0);
state_1 = 1;
break;
}
return result;
}

canonical_decompiled_code:
int func17()
{
__int64 v0; // rbp
__int64 (__fastcall **v1)(_QWORD, __int64); // rbx
__int64 (__fastcall **v2)(_QWORD); // r12
int result; // eax
void (__fastcall *v4)(__int64, _QWORD); // rbx
unsigned int v5; // eax
struct timespec v6; // [rsp+0h] [rbp-28h] BYREF

v0 = func10();
v1 = (__int64 (__fastcall **)(_QWORD, __int64))func14();
v2 = (__int64 (__fastcall **)(_QWORD))func16();
result = state_1;
switch ( state_1 )
{
case 1:
printf("[%s:%d:%s()]: PWM_ON\n", "fsm.c", 47LL, "do_fsm_step");
(*v1)(v1, 1LL);
clock_gettime(1, &v6);
v4 = *(void (__fastcall **)(__int64, _QWORD))(v0 + 8);
v5 = (*v2)(v2);
v4(v0, v5);
if ( v6.tv_nsec + 900000000 > 999999999 )
{
++v6.tv_sec;
v6.tv_nsec -= 100000000LL;
}
else
{
v6.tv_nsec += 900000000LL;
}
result = clock_nanosleep(1, 1, &v6, 0LL);
state_1 = 2;
break;
case 2:
printf("[%s:%d:%s()]: PWM_OFF\n", "fsm.c", 76LL, "do_fsm_step");
(*(void (__fastcall **)(__int64, _QWORD))(v0 + 8))(v0, 0LL);
result = (*v1)(v1, 2LL);
state_1 = 0;
break;
case 0:
printf("[%s:%d:%s()]: WAIT_FOR_TRIGGER\n", "fsm.c", 39LL, "do_fsm_step");
(*v1)(v1, 0LL);
result = (*(__int64 (__fastcall **)(__int64))v0)(v0);
state_1 = 1;
break;
}
return result;
}

original_code:
void do_fsm_step()
{
 struct io_t * io = new_io();
 struct msg_t * msg = new_msg();
 struct controller_t * c = new_controller();
 static int state = WAIT_FOR_TRIGGER;
 struct timespec timeout;
 switch (state)
 {
  case WAIT_FOR_TRIGGER:
   printf("[%s:%d:%s()]: " "WAIT_FOR_TRIGGER" "\n", "fsm.c", 39, __func__);
   msg->put(msg,WAIT_FOR_TRIGGER);
   io->wait_for_foot_switch(io);
   state = PWM_ON;
   break;;
  case PWM_ON:
   printf("[%s:%d:%s()]: " "PWM_ON" "\n", "fsm.c", 47, __func__);
   msg->put(msg,PWM_ON);
   clock_gettime(1, &timeout);
   io->pwm_set(io,c->get_pwm_work(c));
                        timeout.tv_nsec += 900000000l;
                        if (timeout.tv_nsec >= 1000000000l)
                        {
                                timeout.tv_nsec -= 1000000000l;
                                timeout.tv_sec++;
                        }
   clock_nanosleep(1, 1, &timeout, ((void *)0));
   state = PWM_OFF;
   break;
  case PWM_OFF:
   printf("[%s:%d:%s()]: " "PWM_OFF" "\n", "fsm.c", 76, __func__);
   io->pwm_set(io,0);
   msg->put(msg,PWM_OFF);
   state = WAIT_FOR_TRIGGER;
   break;
 }
}

canonical_original_code:
void do_fsm_step()
{
 struct io_t *io = new_io();
 struct msg_t *msg = new_msg();
 struct controller_t *c = new_controller();
 static int state = WAIT_FOR_TRIGGER;
 struct timespec timeout;
 switch (state)
 {
  case WAIT_FOR_TRIGGER:
   printf("[%s:%d:%s()]: " "WAIT_FOR_TRIGGER" "\n", "fsm.c", 39, __func__);
   msg->put(msg,WAIT_FOR_TRIGGER);
   io->wait_for_foot_switch(io);
   state = PWM_ON;
   break;;
  case PWM_ON:
   printf("[%s:%d:%s()]: " "PWM_ON" "\n", "fsm.c", 47, __func__);
   msg->put(msg,PWM_ON);
   clock_gettime(1, &timeout);
   io->pwm_set(io,c->get_pwm_work(c));
                        timeout.tv_nsec += 900000000l;
                        if (timeout.tv_nsec >= 1000000000l)
                        {
                                timeout.tv_nsec -= 1000000000l;
                                timeout.tv_sec++;
                        }
   clock_nanosleep(1, 1, &timeout, ((void *)0));
   state = PWM_OFF;
   break;
  case PWM_OFF:
   printf("[%s:%d:%s()]: " "PWM_OFF" "\n", "fsm.c", 76, __func__);
   io->pwm_set(io,0);
   msg->put(msg,PWM_OFF);
   state = WAIT_FOR_TRIGGER;
   break;
 }
}

variable_types: state int

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


repo: marcinlos/cmm-compiler

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
int v4; // ebp
__int64 *v5; // rbx
__int64 v6; // rbx
int v8; // eax
char v9[8216]; // [rsp+0h] [rbp-2018h] BYREF

v3 = parse_stdin(argc, argv, envp);
if ( v3 )
{
v4 = 1;
v5 = (__int64 *)build_ir(v3);
puts("-----------------------------------------------------");
v6 = *v5;
puts(".data");
if ( !v6 )
return 0;
while ( 1 )
{
while ( 1 )
{
ir_pretty_print(v9);
v8 = *(_DWORD *)v6;
if ( *(_DWORD *)v6 == 1 )
break;
if ( v4 == 1 )
{
puts(".text");
v8 = *(_DWORD *)v6;
}
if ( v8 == 7 )
goto LABEL_11;
LABEL_7:
printf(" %s\n", v9);
v4 = *(_DWORD *)v6;
v6 = *(_QWORD *)(v6 + 64);
if ( !v6 )
return 0;
}
if ( v4 == 1 )
goto LABEL_7;
puts(".data");
if ( *(_DWORD *)v6 != 7 )
goto LABEL_7;
LABEL_11:
puts(v9);
v4 = *(_DWORD *)v6;
v6 = *(_QWORD *)(v6 + 64);
if ( !v6 )
return 0;
}
}
fwrite("Errors too severe to generate meaningful output,better luck next time. \nSorry!", 1uLL, 0x4EuLL, stderr);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
    node* root = parse_stdin();
    if (root == ((void *)0))
    {
        fprintf(stderr, "Errors too severe to generate meaningful output,"
            "better luck next time. \nSorry!");
    }
    else
    {
        char buffer[8192];
        ir_code* code = build_ir(root);
        printf("-----------------------------------------------------\n");
        ir_list* c = code->codes;
        printf(".data\n");
        int prev = IR_DATA;
        while (c)
        {
            ir_pretty_print(buffer, c->item);
            if (c->item.type == IR_DATA && prev != IR_DATA)
                printf(".data\n");
            else if (c->item.type != IR_DATA && prev == IR_DATA)
                printf(".text\n");
            if (c->item.type != IR_LABEL)
                printf("    %s\n", buffer);
            else
                printf("%s\n", buffer);
            prev = c->item.type;
            c = c->next;
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct node *root = parse_stdin();
    if (root == ((void *)0))
    {
        fprintf(stderr, "Errors too severe to generate meaningful output,"
            "better luck next time. \nSorry!");
    }
    else
    {
        char buffer[8192];
        struct ir_code *code = build_ir(root);
        printf("-----------------------------------------------------\n");
        struct ir_list *c = code->codes;
        printf(".data\n");
        int prev = IR_DATA;
        while (c)
        {
            ir_pretty_print(buffer, c->item);
            if (c->item.type == IR_DATA && prev != IR_DATA)
                printf(".data\n");
            else if (c->item.type != IR_DATA && prev == IR_DATA)
                printf(".text\n");
            if (c->item.type != IR_LABEL)
                printf("    %s\n", buffer);
            else
                printf("%s\n", buffer);
            prev = c->item.type;
            c = c->next;
        }
    }
    return 0;
}

variable_types:
argv
char *[]

variable_types: struct node { enum node_type { NODE_DECL=0, NODE_FUN=1 } type; union { struct fun_def { struct decl { enum value_type { TYPE_INT=0, TYPE_CHAR=1, TYPE_VOID=2 } type; int is_extern; struct decltor_list { struct decltor { enum decltor_type { DECLTOR_FUN=0, DECLTOR_ARRAY=1, DECLTOR_SIMPLE=2 } type; char *name; union { struct decl_list { struct decl *declaration; struct decl_list *next; } *params; struct expr { enum expr_type { EXP_ID=0, EXP_INT=1, EXP_CHAR=2, EXP_STRING=3, EXP_PLUS=100, EXP_MINUS=101, EXP_TIMES=102, EXP_DIV=103, EXP_EQ=104, EXP_NEQ=105, EXP_LTE=106, EXP_GTE=107, EXP_LT=108, EXP_GT=109, EXP_AND=110, EXP_OR=111, EXP_UNMINUS=150, EXP_NEG=151, EXP_INDEX=200, EXP_CALL=201 } type; union { union { struct { struct expr *left; struct expr *right; }; struct { char *id; struct expr_list { struct expr *expression; struct expr_list *next; } *args; }; struct { struct expr *expression; struct expr *index; }; }; union { char *string; int integer; char character; }; }; } *elements; }; } *declarator; struct decltor_list *next; } *declarators; } *signature; struct decl_list *declarations; struct stmt_list { struct stmt { enum stmt_type { STM_IF=0, STM_WHILE=1, STM_FOR=2, STM_EXP=100, STM_RETURN=101, STM_ASSIGN=102, STM_COMPOUND=200 } type; union { struct { char *name; struct expr *index; struct expr *expression; }; struct { struct stmt *init; struct expr *condition; struct stmt *update; struct stmt *body; struct stmt *else_body; }; struct stmt_list *list; }; } *statement; struct stmt_list *next; } *statements; } *function; struct decl *declaration; }; struct node *next; } *

variable_types:
buffer
char [8192]

variable_types: struct ir_code { struct ir_list { struct ir_item { enum ir_type { IR_EMPTY=0, IR_DATA=1, IR_BINOP=2, IR_UNOP=3, IR_COPY=4, IR_GOTO=5, IR_BRANCH=6, IR_LABEL=7, IR_LIDX=8, IR_RIDX=9, IR_ADDR=10, IR_LDEREF=11, IR_RDEREF=12, IR_ENTER=13, IR_LEAVE=14, IR_PARAM=15, IR_CALL=16, IR_RET=17, IR_RET_VAL=18, IR_RETRIEVE=19 } type; union { struct { struct address { enum addr_type { ADDR_EMPTY=0, ADDR_SYMBOL=1, ADDR_SYMBOL_NAME=2, ADDR_IMM_INT=3, ADDR_IMM_CHAR=4, ADDR_IMM_STRING=5 } type; union { int integer; char character; char *string; struct symbol_info { enum symbol_type { SYM_NONE=0, SYM_FUN=1, SYM_VAR=2, SYM_LITERAL=3 } symbol_type; char *name; struct scope_info { struct symbol_info *symbols; struct scope_info *parent; struct scope_info *next; struct scope_info *children; } *scope; union { struct { struct type { enum basic_type { T_VOID=0, T_INT=1, T_CHAR=2, T_INT_ARRAY=3, T_CHAR_ARRAY=4 } type; int elements; } var_type; struct codegen_info { enum storage_type { ST_UNKNOWN=0, ST_REG=1, ST_LOCAL=2, ST_GLOBAL=3 } storage; int size; union { int reg; int offset; }; } codegen; }; struct { struct type ret_type; struct scope_info *params; }; char *literal; }; struct symbol_info *next; } *symbol; char *symbol_name; }; } x; union { enum ir_binop { IR_PLUS=0, IR_MINUS=1, IR_TIMES=2, IR_DIV=3, IR_AND=4, IR_OR=5 } binop; enum ir_unop { IR_NEG=0 } unop; enum ir_relop { IR_EQ=0, IR_NEQ=1, IR_GT=2, IR_GTE=3, IR_LT=4, IR_LTE=5 } relop; }; }; struct { char *name; enum ir_data { DATA_RAW=0, DATA_STRING=1 } data_type; union { int bytes; char *text; }; }; struct { char *label; int offset; }; }; } item; struct ir_list *next; } *codes; struct symbol_table { struct scope_info *top_level; struct symbol_info *literals; } table; } *

variable_types: prev int

user_defined_types: struct node { enum node_type type; union { struct fun_def *function; struct decl *declaration; }; struct node *next; }

user_defined_types: struct ir_code { struct ir_list *codes; struct symbol_table table; }

user_defined_types: struct ir_list { struct ir_item item; struct ir_list *next; }

user_defined_types: struct ir_item { enum ir_type type; union { struct { struct address x; union { enum ir_binop binop; enum ir_unop unop; enum ir_relop relop; }; }; struct { char *name; enum ir_data data_type; union { int bytes; char *text; }; }; struct { char *label; int offset; }; }; }

user_defined_types: struct fun_def { struct decl *signature; struct decl_list *declarations; struct stmt_list *statements; }

user_defined_types: struct address { enum addr_type type; union { int integer; char character; char *string; struct symbol_info *symbol; char *symbol_name; }; }

user_defined_types: struct decl { enum value_type type; int is_extern; struct decltor_list *declarators; }

user_defined_types: struct stmt_list { struct stmt *statement; struct stmt_list *next; }

user_defined_types: struct decltor_list { struct decltor *declarator; struct decltor_list *next; }

user_defined_types: struct stmt { enum stmt_type type; union { struct { char *name; struct expr *index; struct expr *expression; }; struct { struct stmt *init; struct expr *condition; struct stmt *update; struct stmt *body; struct stmt *else_body; }; struct stmt_list *list; }; }

user_defined_types: struct symbol_info { enum symbol_type symbol_type; char *name; struct scope_info *scope; union { struct { struct type var_type; struct codegen_info codegen; }; struct { struct type ret_type; struct scope_info *params; }; char *literal; }; struct symbol_info *next; }

user_defined_types: struct decltor { enum decltor_type type; char *name; union { struct decl_list *params; struct expr *elements; }; }

user_defined_types: struct type { enum basic_type type; int elements; }

user_defined_types: struct codegen_info { enum storage_type storage; int size; union { int reg; int offset; }; }

user_defined_types: struct expr { enum expr_type type; union { union { struct { struct expr *left; struct expr *right; }; struct { char *id; struct expr_list *args; }; struct { struct expr *expression; struct expr *index; }; }; union { char *string; int integer; char character; }; }; }


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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
line_list* empty_line_list(void)
{
    line_list* node = malloc(sizeof(line_list));
    node->line = ((void *)0);
    node->next = ((void *)0);
    return node;
}

canonical_original_code:
struct line_list *empty_line_list()
{
    struct line_list *node = malloc(sizeof(line_list));
    node->line = ((void *)0);
    node->next = ((void *)0);
    return node;
}

variable_types: struct line_list { char *line; struct line_list *next; } *


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

if ( a1 )
{
v1 = a1;
do
{
result = puts(*(const char **)v1);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return result;
}

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

if ( a1 )
{
v1 = a1;
do
{
result = puts(*(const char **)v1);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return result;
}

original_code:
void print_line_list(line_list* lines)
{
    while (lines != ((void *)0))
    {
        printf("%s\n", lines->line);
        lines = lines->next;
    }
}

canonical_original_code:
void print_line_list(struct line_list *lines)
{
    while (lines != ((void *)0))
    {
        printf("%s\n", lines->line);
        lines = lines->next;
    }
}

user_defined_types: struct line_list { char *line; struct line_list *next; }


decompiled_code:
void __fastcall free_line_list(void *ptr)
{
void **v1; // rbx
void **v2; // rdi

if ( ptr )
{
v1 = (void **)ptr;
do
{
free(*v1);
v2 = v1;
v1 = (void **)v1[1];
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void **v1; // rbx
void **v2; // rdi

if ( ptr )
{
v1 = (void **)ptr;
do
{
free(*v1);
v2 = v1;
v1 = (void **)v1[1];
free(v2);
}
while ( v1 );
}
}

original_code:
void free_line_list(line_list* lines)
{
    while (lines != ((void *)0))
    {
        free(lines->line);
        line_list* tmp = lines;
        lines = lines->next;
        free(tmp);
    }
}

canonical_original_code:
void free_line_list(struct line_list *lines)
{
    while (lines != ((void *)0))
    {
        free(lines->line);
        struct line_list *tmp = lines;
        lines = lines->next;
        free(tmp);
    }
}


decompiled_code:
__int64 __fastcall append_symbol(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

if ( !a1 )
return a2;
v2 = a1;
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 48);
}
while ( v2 );
*(_QWORD *)(v3 + 48) = a2;
return a1;
}

original_code:
static symbol_info* append_symbol(symbol_info* list, symbol_info* node)
{
    symbol_info* head = list, *prev = ((void *)0);
    while (head != ((void *)0))
    {
        prev = head;
        head = head->next;
    }
    if (prev != ((void *)0))
        prev->next = node;
    else
        list = node;
    return list;
}

canonical_original_code:
static struct symbol_info *append_symbol(struct symbol_info *list, struct symbol_info *node)
{
    struct symbol_info *head = list; struct symbol_info *prev = ((void *)0);
    while (head != ((void *)0))
    {
        prev = head;
        head = head->next;
    }
    if (prev != ((void *)0))
        prev->next = node;
    else
        list = node;
    return list;
}

variable_types:
list
struct symbol_info *

variable_types:
node
struct symbol_info *

variable_types: struct symbol_info { enum symbol_type { SYM_NONE=0, SYM_FUN=1, SYM_VAR=2, SYM_LITERAL=3 } symbol_type; char *name; struct scope_info { struct symbol_info *symbols; struct scope_info *parent; struct scope_info *next; struct scope_info *children; } *scope; union { struct { struct type { enum basic_type { T_VOID=0, T_INT=1, T_CHAR=2, T_INT_ARRAY=3, T_CHAR_ARRAY=4 } type; int elements; } var_type; struct codegen_info { enum storage_type { ST_UNKNOWN=0, ST_REG=1, ST_LOCAL=2, ST_GLOBAL=3 } storage; int size; union { int reg; int offset; }; } codegen; }; struct { struct type ret_type; struct scope_info *params; }; char *literal; }; struct symbol_info *next; } *


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

result = malloc(0x38uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[6] = 0LL;
result[2] = 0LL;
return result;
}

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

result = malloc(0x38uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[6] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
static symbol_info* empty_symbol(void)
{
    symbol_info* sym = malloc(sizeof(symbol_info));
    sym->symbol_type = SYM_NONE;
    sym->name = ((void *)0);
    sym->next = ((void *)0);
    sym->scope = ((void *)0);
    return sym;
}

canonical_original_code:
static struct symbol_info *empty_symbol()
{
    struct symbol_info *sym = malloc(sizeof(symbol_info));
    sym->symbol_type = SYM_NONE;
    sym->name = ((void *)0);
    sym->next = ((void *)0);
    sym->scope = ((void *)0);
    return sym;
}

return_type: struct symbol_info { enum symbol_type { SYM_NONE=0, SYM_FUN=1, SYM_VAR=2, SYM_LITERAL=3 } symbol_type; char *name; struct scope_info { struct symbol_info *symbols; struct scope_info *parent; struct scope_info *next; struct scope_info *children; } *scope; union { struct { struct type { enum basic_type { T_VOID=0, T_INT=1, T_CHAR=2, T_INT_ARRAY=3, T_CHAR_ARRAY=4 } type; int elements; } var_type; struct codegen_info { enum storage_type { ST_UNKNOWN=0, ST_REG=1, ST_LOCAL=2, ST_GLOBAL=3 } storage; int size; union { int reg; int offset; }; } codegen; }; struct { struct type ret_type; struct scope_info *params; }; char *literal; }; struct symbol_info *next; } *


decompiled_code:
void __fastcall free_symbol_info(void *ptr)
{
void *v2; // rbx

while ( 1 )
{
if ( !ptr )
_assert_fail("sym && \"free_symbol_info: NULL argument\"", "symbol_table.c", 0x4Bu, "free_symbol_info");
v2 = (void *)*((_QWORD *)ptr + 6);
free(*((void **)ptr + 1));
if ( *(_DWORD *)ptr == 3 )
break;
free(ptr);
if ( !v2 )
return;
LABEL_3:
ptr = v2;
}
free(*((void **)ptr + 3));
free(ptr);
if ( v2 )
goto LABEL_3;
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void *v2; // rbx

while ( 1 )
{
if ( !ptr )
_assert_fail("sym && \"free_symbol_info: NULL argument\"", "symbol_table.c", 0x4Bu, "free_symbol_info");
v2 = (void *)*((_QWORD *)ptr + 6);
free(*((void **)ptr + 1));
if ( *(_DWORD *)ptr == 3 )
break;
free(ptr);
if ( !v2 )
return;
LABEL_3:
ptr = v2;
}
free(*((void **)ptr + 3));
free(ptr);
if ( v2 )
goto LABEL_3;
}

original_code:
void free_symbol_info(symbol_info* sym)
{
    ((void) sizeof ((sym && "free_symbol_info: NULL argument") ? 1 : 0), __extension__ ({ if (sym && "free_symbol_info: NULL argument") ; else __assert_fail ("sym && \"free_symbol_info: NULL argument\"", "symbol_table.c", 75, __extension__ __PRETTY_FUNCTION__); }));
    symbol_info* next = sym->next;
    free(sym->name);
    if (sym->symbol_type == SYM_LITERAL)
    {
        free(sym->literal);
    }
    free(sym);
    if (next)
    {
        free_symbol_info(next);
    }
}

canonical_original_code:
void free_symbol_info(struct symbol_info *sym)
{
    ((void) sizeof ((sym && "free_symbol_info: NULL argument") ? 1 : 0), __extension__ ({ if (sym && "free_symbol_info: NULL argument") ; else __assert_fail ("sym && \"free_symbol_info: NULL argument\"", "symbol_table.c", 75, __extension__ __PRETTY_FUNCTION__); }));
    struct symbol_info *next = sym->next;
    free(sym->name);
    if (sym->symbol_type == SYM_LITERAL)
    {
        free(sym->literal);
    }
    free(sym);
    if (next)
    {
        free_symbol_info(next);
    }
}

user_defined_types: enum symbol_type { SYM_NONE=0, SYM_FUN=1, SYM_VAR=2, SYM_LITERAL=3 }

user_defined_types: struct scope_info { struct symbol_info *symbols; struct scope_info *parent; struct scope_info *next; struct scope_info *children; }

user_defined_types: enum basic_type { T_VOID=0, T_INT=1, T_CHAR=2, T_INT_ARRAY=3, T_CHAR_ARRAY=4 }

user_defined_types: enum storage_type { ST_UNKNOWN=0, ST_REG=1, ST_LOCAL=2, ST_GLOBAL=3 }


decompiled_code:
__int64 __fastcall sym_add_symbol(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 *v3; // rcx

if ( !a1 )
_assert_fail("scope && \"sym_add_symbol: NULL scope\"", "symbol_table.c", 0x66u, "sym_add_symbol");
if ( !a2 )
_assert_fail("symbol && \"sym_add_symbol: NULL symbol\"", "symbol_table.c", 0x67u, "sym_add_symbol");
result = append_symbol(*a1, a2);
*v3 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 *v3; // rcx

if ( !a1 )
_assert_fail("scope && \"sym_add_symbol: NULL scope\"", "symbol_table.c", 0x66u, "sym_add_symbol");
if ( !a2 )
_assert_fail("symbol && \"sym_add_symbol: NULL symbol\"", "symbol_table.c", 0x67u, "sym_add_symbol");
result = func0(*a1, a2);
*v3 = result;
return result;
}

original_code:
void sym_add_symbol(scope_info* scope, symbol_info* symbol)
{
    ((void) sizeof ((scope && "sym_add_symbol: NULL scope") ? 1 : 0), __extension__ ({ if (scope && "sym_add_symbol: NULL scope") ; else __assert_fail ("scope && \"sym_add_symbol: NULL scope\"", "symbol_table.c", 102, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((symbol && "sym_add_symbol: NULL symbol") ? 1 : 0), __extension__ ({ if (symbol && "sym_add_symbol: NULL symbol") ; else __assert_fail ("symbol && \"sym_add_symbol: NULL symbol\"", "symbol_table.c", 103, __extension__ __PRETTY_FUNCTION__); }));
    scope->symbols = append_symbol(scope->symbols, symbol);
}

canonical_original_code:
void sym_add_symbol(struct scope_info *scope, struct symbol_info *symbol)
{
    ((void) sizeof ((scope && "sym_add_symbol: NULL scope") ? 1 : 0), __extension__ ({ if (scope && "sym_add_symbol: NULL scope") ; else __assert_fail ("scope && \"sym_add_symbol: NULL scope\"", "symbol_table.c", 102, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((symbol && "sym_add_symbol: NULL symbol") ? 1 : 0), __extension__ ({ if (symbol && "sym_add_symbol: NULL symbol") ; else __assert_fail ("symbol && \"sym_add_symbol: NULL symbol\"", "symbol_table.c", 103, __extension__ __PRETTY_FUNCTION__); }));
    scope->symbols = append_symbol(scope->symbols, symbol);
}

variable_types: struct scope_info { struct symbol_info { enum symbol_type { SYM_NONE=0, SYM_FUN=1, SYM_VAR=2, SYM_LITERAL=3 } symbol_type; char *name; struct scope_info *scope; union { struct { struct type { enum basic_type { T_VOID=0, T_INT=1, T_CHAR=2, T_INT_ARRAY=3, T_CHAR_ARRAY=4 } type; int elements; } var_type; struct codegen_info { enum storage_type { ST_UNKNOWN=0, ST_REG=1, ST_LOCAL=2, ST_GLOBAL=3 } storage; int size; union { int reg; int offset; }; } codegen; }; struct { struct type ret_type; struct scope_info *params; }; char *literal; }; struct symbol_info *next; } *symbols; struct scope_info *parent; struct scope_info *next; struct scope_info *children; } *

variable_types:
symbol
struct symbol_info *


decompiled_code:
__int64 __fastcall sym_add_param(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("fun && \"sym_add_param: NULL function\"", "symbol_table.c", 0x44u, "sym_add_param");
return sym_add_symbol(*(__int64 **)(a1 + 32), a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("fun && \"sym_add_param: NULL function\"", "symbol_table.c", 0x44u, "sym_add_param");
return func3(*(__int64 **)(a1 + 32), a2);
}

original_code:
void sym_add_param(symbol_info* fun, symbol_info* param)
{
    ((void) sizeof ((fun && "sym_add_param: NULL function") ? 1 : 0), __extension__ ({ if (fun && "sym_add_param: NULL function") ; else __assert_fail ("fun && \"sym_add_param: NULL function\"", "symbol_table.c", 68, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((fun && "sym_add_param: NULL param") ? 1 : 0), __extension__ ({ if (fun && "sym_add_param: NULL param") ; else __assert_fail ("fun && \"sym_add_param: NULL param\"", "symbol_table.c", 69, __extension__ __PRETTY_FUNCTION__); }));
    sym_add_symbol(fun->params, param);
}

canonical_original_code:
void sym_add_param(struct symbol_info *fun, struct symbol_info *param)
{
    ((void) sizeof ((fun && "sym_add_param: NULL function") ? 1 : 0), __extension__ ({ if (fun && "sym_add_param: NULL function") ; else __assert_fail ("fun && \"sym_add_param: NULL function\"", "symbol_table.c", 68, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((fun && "sym_add_param: NULL param") ? 1 : 0), __extension__ ({ if (fun && "sym_add_param: NULL param") ; else __assert_fail ("fun && \"sym_add_param: NULL param\"", "symbol_table.c", 69, __extension__ __PRETTY_FUNCTION__); }));
    sym_add_symbol(fun->params, param);
}

variable_types:
param
struct symbol_info *


decompiled_code:
__int64 __fastcall sym_add_child_scope(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( !a1 )
_assert_fail("parent && \"sym_add_child_scope: NULL parent\"", "symbol_table.c", 0x6Du, "sym_add_child_scope");
if ( !a2 )
_assert_fail("child && \"sym_add_child_scope: NULL child\"", "symbol_table.c", 0x6Eu, "sym_add_child_scope");
result = *(_QWORD *)(a1 + 24);
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v3 + 16) = a2;
}
else
{
*(_QWORD *)(a1 + 24) = a2;
}
return result;
}

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

if ( !a1 )
_assert_fail("parent && \"sym_add_child_scope: NULL parent\"", "symbol_table.c", 0x6Du, "sym_add_child_scope");
if ( !a2 )
_assert_fail("child && \"sym_add_child_scope: NULL child\"", "symbol_table.c", 0x6Eu, "sym_add_child_scope");
result = *(_QWORD *)(a1 + 24);
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v3 + 16) = a2;
}
else
{
*(_QWORD *)(a1 + 24) = a2;
}
return result;
}

original_code:
void sym_add_child_scope(scope_info* parent, scope_info* child)
{
    ((void) sizeof ((parent && "sym_add_child_scope: NULL parent") ? 1 : 0), __extension__ ({ if (parent && "sym_add_child_scope: NULL parent") ; else __assert_fail ("parent && \"sym_add_child_scope: NULL parent\"", "symbol_table.c", 109, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((child && "sym_add_child_scope: NULL child") ? 1 : 0), __extension__ ({ if (child && "sym_add_child_scope: NULL child") ; else __assert_fail ("child && \"sym_add_child_scope: NULL child\"", "symbol_table.c", 110, __extension__ __PRETTY_FUNCTION__); }));
    if (parent->children == ((void *)0))
        parent->children = child;
    else
    {
        scope_info* i = parent->children;
        while (i ->next != ((void *)0))
            i = i->next;
        i->next = child;
    }
}

canonical_original_code:
void sym_add_child_scope(struct scope_info *parent, struct scope_info *child)
{
    ((void) sizeof ((parent && "sym_add_child_scope: NULL parent") ? 1 : 0), __extension__ ({ if (parent && "sym_add_child_scope: NULL parent") ; else __assert_fail ("parent && \"sym_add_child_scope: NULL parent\"", "symbol_table.c", 109, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((child && "sym_add_child_scope: NULL child") ? 1 : 0), __extension__ ({ if (child && "sym_add_child_scope: NULL child") ; else __assert_fail ("child && \"sym_add_child_scope: NULL child\"", "symbol_table.c", 110, __extension__ __PRETTY_FUNCTION__); }));
    if (parent->children == ((void *)0))
        parent->children = child;
    else
    {
        struct scope_info *i = parent->children;
        while (i ->next != ((void *)0))
            i = i->next;
        i->next = child;
    }
}

variable_types:
child
struct scope_info *


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

if ( !a1 )
_assert_fail("scope && \"free_scope_info: NULL argument\"", "symbol_table.c", 0x7Du, "free_scope_info");
v2 = *a1;
if ( v2 )
free_symbol_info(v2);
if ( a1[3] )
free_scope_info();
if ( a1[2] )
free_scope_info();
free(a1);
}

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

if ( !a1 )
_assert_fail("scope && \"free_scope_info: NULL argument\"", "symbol_table.c", 0x7Du, "free_scope_info");
v2 = *a1;
if ( v2 )
func2(v2);
if ( a1[3] )
func6();
if ( a1[2] )
func6();
free(a1);
}

original_code:
void free_scope_info(scope_info* scope)
{
    ((void) sizeof ((scope && "free_scope_info: NULL argument") ? 1 : 0), __extension__ ({ if (scope && "free_scope_info: NULL argument") ; else __assert_fail ("scope && \"free_scope_info: NULL argument\"", "symbol_table.c", 125, __extension__ __PRETTY_FUNCTION__); }));
    if (scope->symbols != ((void *)0))
        free_symbol_info(scope->symbols);
    if (scope->children != ((void *)0))
        free_scope_info(scope->children);
    if (scope->next != ((void *)0))
        free_scope_info(scope->next);
    free(scope);
}

canonical_original_code:
void free_scope_info(struct scope_info *scope)
{
    ((void) sizeof ((scope && "free_scope_info: NULL argument") ? 1 : 0), __extension__ ({ if (scope && "free_scope_info: NULL argument") ; else __assert_fail ("scope && \"free_scope_info: NULL argument\"", "symbol_table.c", 125, __extension__ __PRETTY_FUNCTION__); }));
    if (scope->symbols != ((void *)0))
        free_symbol_info(scope->symbols);
    if (scope->children != ((void *)0))
        free_scope_info(scope->children);
    if (scope->next != ((void *)0))
        free_scope_info(scope->next);
    free(scope);
}


decompiled_code:
__int64 __fastcall sym_find_no_traverse(char *s2, __int64 *a2)
{
__int64 i; // r12

for ( i = *a2; i; i = *(_QWORD *)(i + 48) )
{
if ( !strcmp(*(const char **)(i + 8), s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s2, __int64 *a2)
{
__int64 i; // r12

for ( i = *a2; i; i = *(_QWORD *)(i + 48) )
{
if ( !strcmp(*(const char **)(i + 8), s2) )
break;
}
return i;
}

original_code:
symbol_info* sym_find_no_traverse(const char* name, scope_info* scope)
{
    symbol_info* info = scope->symbols;
    while (info != ((void *)0))
    {
        if (strcmp(info->name, name) == 0)
            return info;
        else
            info = info->next;
    }
    return ((void *)0);
}

canonical_original_code:
struct symbol_info *sym_find_no_traverse(char *name, struct scope_info *scope)
{
    struct symbol_info *info = scope->symbols;
    while (info != ((void *)0))
    {
        if (strcmp(info->name, name) == 0)
            return info;
        else
            info = info->next;
    }
    return ((void *)0);
}

variable_types:
name
char *

variable_types:
scope
struct scope_info *


decompiled_code:
__int64 __fastcall sym_find(char *s2, __int64 *a2)
{
__int64 result; // rax

do
{
result = sym_find_no_traverse(s2, a2);
if ( result )
break;
a2 = (__int64 *)a2[1];
}
while ( a2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s2, __int64 *a2)
{
__int64 result; // rax

do
{
result = func7(s2, a2);
if ( result )
break;
a2 = (__int64 *)a2[1];
}
while ( a2 );
return result;
}

original_code:
symbol_info* sym_find(const char* name, scope_info* scope)
{
    symbol_info* info = sym_find_no_traverse(name, scope);
    if (info == ((void *)0) && scope->parent != ((void *)0))
    {
        return sym_find(name, scope->parent);
    }
    return info;
}

canonical_original_code:
struct symbol_info *sym_find(char *name, struct scope_info *scope)
{
    struct symbol_info *info = sym_find_no_traverse(name, scope);
    if (info == ((void *)0) && scope->parent != ((void *)0))
    {
        return sym_find(name, scope->parent);
    }
    return info;
}


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

v2 = *(void ***)ptr;
if ( v2 )
free_scope_info(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free_symbol_info(v3);
free(ptr);
}

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

v2 = *(void ***)ptr;
if ( v2 )
func6(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
func2(v3);
free(ptr);
}

original_code:
void free_symbol_table(symbol_table* table)
{
    if (table->top_level)
        free_scope_info(table->top_level);
    if (table->literals)
        free_symbol_info(table->literals);
    free(table);
}

canonical_original_code:
void free_symbol_table(struct symbol_table *table)
{
    if (table->top_level)
        free_scope_info(table->top_level);
    if (table->literals)
        free_symbol_info(table->literals);
    free(table);
}

variable_types: struct symbol_table { struct scope_info { struct symbol_info { enum symbol_type { SYM_NONE=0, SYM_FUN=1, SYM_VAR=2, SYM_LITERAL=3 } symbol_type; char *name; struct scope_info *scope; union { struct { struct type { enum basic_type { T_VOID=0, T_INT=1, T_CHAR=2, T_INT_ARRAY=3, T_CHAR_ARRAY=4 } type; int elements; } var_type; struct codegen_info { enum storage_type { ST_UNKNOWN=0, ST_REG=1, ST_LOCAL=2, ST_GLOBAL=3 } storage; int size; union { int reg; int offset; }; } codegen; }; struct { struct type ret_type; struct scope_info *params; }; char *literal; }; struct symbol_info *next; } *symbols; struct scope_info *parent; struct scope_info *next; struct scope_info *children; } *top_level; struct symbol_info *literals; } *

user_defined_types: struct symbol_table { struct scope_info *top_level; struct symbol_info *literals; }


decompiled_code:
void sym_print_strings()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
int sym_print_strings(char* buffer, symbol_table* table)
{
}

canonical_original_code:
int sym_print_strings(char *buffer, struct symbol_table *table)
{
}

variable_types:
buffer
char *


decompiled_code:
signed __int64 __fastcall sym_print_symbol(char *a1, __int64 a2)
{
char *v2; // rbx
int v3; // eax
_BYTE v5[280]; // [rsp+0h] [rbp-118h] BYREF

if ( !a2 )
_assert_fail("info && \"sym_print_symbol: NULL info\"", "symbol_table.c", 0xF4u, "sym_print_symbol");
v2 = &a1[sprintf(a1, "%s:\t", *(const char **)(a2 + 8))];
if ( *(_DWORD *)a2 == 1 )
{
type_print(v5, *(_QWORD *)(a2 + 24));
v3 = sprintf(v2, "() -> %s", v5);
goto LABEL_5;
}
if ( *(_DWORD *)a2 == 2 )
{
type_print(v5, *(_QWORD *)(a2 + 24));
v3 = sprintf(v2, "%s", v5);
LABEL_5:
v2 += v3;
}
return v2 - a1;
}

canonical_decompiled_code:
signed __int64 __fastcall func12(char *a1, __int64 a2)
{
char *v2; // rbx
int v3; // eax
_BYTE v5[280]; // [rsp+0h] [rbp-118h] BYREF

if ( !a2 )
_assert_fail("info && \"sym_print_symbol: NULL info\"", "symbol_table.c", 0xF4u, "sym_print_symbol");
v2 = &a1[sprintf(a1, "%s:\t", *(const char **)(a2 + 8))];
if ( *(_DWORD *)a2 == 1 )
{
type_print(v5, *(_QWORD *)(a2 + 24));
v3 = sprintf(v2, "() -> %s", v5);
goto LABEL_5;
}
if ( *(_DWORD *)a2 == 2 )
{
type_print(v5, *(_QWORD *)(a2 + 24));
v3 = sprintf(v2, "%s", v5);
LABEL_5:
v2 += v3;
}
return v2 - a1;
}

original_code:
int sym_print_symbol(char* buffer, symbol_info* info)
{
    ((void) sizeof ((info && "sym_print_symbol: NULL info") ? 1 : 0), __extension__ ({ if (info && "sym_print_symbol: NULL info") ; else __assert_fail ("info && \"sym_print_symbol: NULL info\"", "symbol_table.c", 244, __extension__ __PRETTY_FUNCTION__); }));
    char* p = buffer;
    p += sprintf(p, "%s:\t", info->name);
    char type_buffer[256];
    switch (info->symbol_type)
    {
    case SYM_FUN:
        type_print(type_buffer, info->ret_type);
        p += sprintf(p, "() -> %s", type_buffer);
        break;
    case SYM_VAR:
        type_print(type_buffer, info->var_type);
        p += sprintf(p, "%s", type_buffer);
        break;
    }
    return p - buffer;
}

canonical_original_code:
int sym_print_symbol(char *buffer, struct symbol_info *info)
{
    ((void) sizeof ((info && "sym_print_symbol: NULL info") ? 1 : 0), __extension__ ({ if (info && "sym_print_symbol: NULL info") ; else __assert_fail ("info && \"sym_print_symbol: NULL info\"", "symbol_table.c", 244, __extension__ __PRETTY_FUNCTION__); }));
    char *p = buffer;
    p += sprintf(p, "%s:\t", info->name);
    char type_buffer[256];
    switch (info->symbol_type)
    {
    case SYM_FUN:
        type_print(type_buffer, info->ret_type);
        p += sprintf(p, "() -> %s", type_buffer);
        break;
    case SYM_VAR:
        type_print(type_buffer, info->var_type);
        p += sprintf(p, "%s", type_buffer);
        break;
    }
    return p - buffer;
}

variable_types:
p
char *


decompiled_code:
signed __int64 __fastcall sym_print_scope(char *a1, const void **a2)
{
int v2; // eax
__int64 v3; // r12
char *v4; // rbx
char *v5; // rbx

if ( !a2 )
_assert_fail("scope && \"sym_print_scope: NULL scope\"", "symbol_table.c", 0xE5u, "sym_print_scope");
v2 = sprintf(a1, "scope: %p (parent %p)\n", a2, a2[1]);
v3 = (__int64)*a2;
v4 = &a1[v2];
if ( *a2 )
{
do
{
v5 = &v4[(int)sym_print_symbol(v4, v3)];
*(_WORD *)v5 = 10;
v3 = *(_QWORD *)(v3 + 48);
v4 = v5 + 1;
}
while ( v3 );
}
return v4 - a1;
}

canonical_decompiled_code:
signed __int64 __fastcall func13(char *a1, const void **a2)
{
int v2; // eax
__int64 v3; // r12
char *v4; // rbx
char *v5; // rbx

if ( !a2 )
_assert_fail("scope && \"sym_print_scope: NULL scope\"", "symbol_table.c", 0xE5u, "sym_print_scope");
v2 = sprintf(a1, "scope: %p (parent %p)\n", a2, a2[1]);
v3 = (__int64)*a2;
v4 = &a1[v2];
if ( *a2 )
{
do
{
v5 = &v4[(int)func12(v4, v3)];
*(_WORD *)v5 = 10;
v3 = *(_QWORD *)(v3 + 48);
v4 = v5 + 1;
}
while ( v3 );
}
return v4 - a1;
}

original_code:
int sym_print_scope(char* buffer, scope_info* scope)
{
    ((void) sizeof ((scope && "sym_print_scope: NULL scope") ? 1 : 0), __extension__ ({ if (scope && "sym_print_scope: NULL scope") ; else __assert_fail ("scope && \"sym_print_scope: NULL scope\"", "symbol_table.c", 229, __extension__ __PRETTY_FUNCTION__); }));
    char* p = buffer;
    p += sprintf(p, "scope: %p (parent %p)\n", scope, scope->parent);
    symbol_info* symbol = scope->symbols;
    while (symbol != ((void *)0))
    {
        p += sym_print_symbol(p, symbol);
        p += sprintf(p, "\n");
        symbol = symbol->next;
    }
    return p - buffer;
}

canonical_original_code:
int sym_print_scope(char *buffer, struct scope_info *scope)
{
    ((void) sizeof ((scope && "sym_print_scope: NULL scope") ? 1 : 0), __extension__ ({ if (scope && "sym_print_scope: NULL scope") ; else __assert_fail ("scope && \"sym_print_scope: NULL scope\"", "symbol_table.c", 229, __extension__ __PRETTY_FUNCTION__); }));
    char *p = buffer;
    p += sprintf(p, "scope: %p (parent %p)\n", scope, scope->parent);
    struct symbol_info *symbol = scope->symbols;
    while (symbol != ((void *)0))
    {
        p += sym_print_symbol(p, symbol);
        p += sprintf(p, "\n");
        symbol = symbol->next;
    }
    return p - buffer;
}


decompiled_code:
signed __int64 __fastcall print_scope_tree(char *a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rbp
char *i; // rbx
int v5; // eax

if ( !a2 )
_assert_fail("scope && \"print_scope_tree: NULL scope\"", "symbol_table.c", 0xCBu, "print_scope_tree");
v2 = sym_print_scope(a1, (const void **)a2);
v3 = *(_QWORD *)(a2 + 24);
for ( i = &a1[v2]; v3; i += v5 )
{
v5 = print_scope_tree(i, v3);
v3 = *(_QWORD *)(v3 + 16);
}
return i - a1;
}

canonical_decompiled_code:
signed __int64 __fastcall func14(char *a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rbp
char *i; // rbx
int v5; // eax

if ( !a2 )
_assert_fail("scope && \"print_scope_tree: NULL scope\"", "symbol_table.c", 0xCBu, "print_scope_tree");
v2 = func13(a1, (const void **)a2);
v3 = *(_QWORD *)(a2 + 24);
for ( i = &a1[v2]; v3; i += v5 )
{
v5 = func14(i, v3);
v3 = *(_QWORD *)(v3 + 16);
}
return i - a1;
}

original_code:
static int print_scope_tree(char* buffer, scope_info* scope)
{
    ((void) sizeof ((scope && "print_scope_tree: NULL scope") ? 1 : 0), __extension__ ({ if (scope && "print_scope_tree: NULL scope") ; else __assert_fail ("scope && \"print_scope_tree: NULL scope\"", "symbol_table.c", 203, __extension__ __PRETTY_FUNCTION__); }));
    char* p = buffer;
    p += sym_print_scope(buffer, scope);
    scope_info* child = scope->children;
    while (child != ((void *)0))
    {
        p += print_scope_tree(p, child);
        child = child->next;
    }
    return p - buffer;
}

canonical_original_code:
static int print_scope_tree(char *buffer, struct scope_info *scope)
{
    ((void) sizeof ((scope && "print_scope_tree: NULL scope") ? 1 : 0), __extension__ ({ if (scope && "print_scope_tree: NULL scope") ; else __assert_fail ("scope && \"print_scope_tree: NULL scope\"", "symbol_table.c", 203, __extension__ __PRETTY_FUNCTION__); }));
    char *p = buffer;
    p += sym_print_scope(buffer, scope);
    struct scope_info *child = scope->children;
    while (child != ((void *)0))
    {
        p += print_scope_tree(p, child);
        child = child->next;
    }
    return p - buffer;
}


decompiled_code:
signed __int64 __fastcall sym_print_table(char *a1, __int64 *a2)
{
if ( !a2 )
_assert_fail("table && \"sym_print_table: NULL table\"", "symbol_table.c", 0xDFu, "sym_print_table");
return print_scope_tree(a1, *a2);
}

canonical_decompiled_code:
signed __int64 __fastcall func15(char *a1, __int64 *a2)
{
if ( !a2 )
_assert_fail("table && \"sym_print_table: NULL table\"", "symbol_table.c", 0xDFu, "sym_print_table");
return func14(a1, *a2);
}

original_code:
int sym_print_table(char* buffer, symbol_table* table)
{
    ((void) sizeof ((table && "sym_print_table: NULL table") ? 1 : 0), __extension__ ({ if (table && "sym_print_table: NULL table") ; else __assert_fail ("table && \"sym_print_table: NULL table\"", "symbol_table.c", 223, __extension__ __PRETTY_FUNCTION__); }));
    return print_scope_tree(buffer, table->top_level);
}

canonical_original_code:
int sym_print_table(char *buffer, struct symbol_table *table)
{
    ((void) sizeof ((table && "sym_print_table: NULL table") ? 1 : 0), __extension__ ({ if (table && "sym_print_table: NULL table") ; else __assert_fail ("table && \"sym_print_table: NULL table\"", "symbol_table.c", 223, __extension__ __PRETTY_FUNCTION__); }));
    return print_scope_tree(buffer, table->top_level);
}