FunDecV

decompiled_code:
__int64 __fastcall FunDecV(__int64 *a1)
{
__int64 *v1; // rbx

v1 = a1;
headPr("FunDec");
if ( a1 )
{
do
{
FunDefV(*v1);
v1 = (__int64 *)v1[1];
}
while ( v1 );
}
return tailPr("FunDec");
}

canonical_decompiled_code:
__int64 __fastcall func30(__int64 *a1)
{
__int64 *v1; // rbx

v1 = a1;
headPr("FunDec");
if ( a1 )
{
do
{
func29(*v1);
v1 = (__int64 *)v1[1];
}
while ( v1 );
}
return tailPr("FunDec");
}

original_code:
void FunDecV(FunDecSP t)
{
  headPr("FunDec");
  for (; t != ((void *)0); t = t->next) {
    FunDefV(t->fdp);
  }
  tailPr("FunDec");
}

canonical_original_code:
void FunDecV(struct _FunDecS *t)
{
  headPr("FunDec");
  for (; t != ((void *)0); t = t->next) {
    FunDefV(t->fdp);
  }
  tailPr("FunDec");
}

variable_types: struct _FunDecS { struct _FunDefS { struct _FunHeadS { struct _IdentS { enum Ident_t { Init_Ident_t=0, Proc_Ident_t=1, Int_Fun_Ident_t=2, Char_Fun_Ident_t=3, Int_Const_Ident_t=4, Char_Const_Ident_t=5, Int_Var_Ident_t=6, Char_Var_Ident_t=7, IntArr_Var_Ident_t=8, CharArr_Var_Ident_t=9, Int_Para_Val_Ident_t=10, Char_Para_Val_Ident_t=11, Int_Para_Ref_Ident_t=12, Char_Para_Ref_Ident_t=13 } type; char *name; int val; int length; int line; } *idp; struct _ParaListS { struct _ParaDefS { struct _IdentS *idp; struct _ParaDefS *next; } *pdp; struct _ParaListS *next; } *plp; } *fhp; struct _BlockS { struct _ConstDecS { struct _ConstDefS { struct _IdentS *idp; } *cdp; struct _ConstDecS *next; } *cdp; struct _VarDecS { struct _VarDefS { struct _IdentS *idp; struct _VarDefS *next; } *vdp; struct _VarDecS *next; } *vdp; struct _PFDecListS { enum PFDec_t { Fun_PFDec_t=0, Proc_PFDec_t=1 } type; struct _ProcDecS { struct _ProcDefS { struct _ProcHeadS { struct _IdentS *idp; struct _ParaListS *plp; } *php; struct _BlockS *bp; } *pdp; struct _ProcDecS *next; } *pdp; struct _FunDecS *fdp; struct _PFDecListS *next; } *pfdlp; struct _CompStmtS { struct _StmtS { enum Stmt_t { Assgin_Stmt_t=0, IF_Stmt_t=1, Repeat_Stmt_t=2, Pcall_Stmt_t=3, Comp_Stmt_t=4, Read_Stmt_t=5, Write_Stmt_t=6, For_Stmt_t=7, Null_Stmt_t=8 } type; struct _AssignStmtS { enum Assgin_t { Norm_Assgin_t=0, Fun_Assgin_t=1, Array_Assgin_t=2 } type; struct _IdentS *idp; struct _ExprS { enum Addop_t { Nop_Addop_t=0, Add_Addop_t=1, Neg_Addop_t=2, Minus_Addop_t=3 } op; struct _TermS { enum Multop_t { Nop_Multop_t=0, Mult_Multop_t=1, Div_Multop_t=2 } op; struct _FactorS { enum Factor_t { Id_Factor_t=0, Array_Factor_t=1, Unsign_Factor_t=2, Expr_Factor_t=3, Funcall_Factor_t=4 } type; struct _IdentS *idp; struct _ExprS *ep; int usi; struct _FcallStmtS { struct _IdentS *idp; struct _ArgListS { struct _ExprS *ep; struct _ArgListS *next; } *alp; } *fcsp; } *fp; struct _TermS *next; } *tp; struct _ExprS *next; } *lep; struct _ExprS *rep; } *asp; struct _IfStmtS { struct _CondS { struct _ExprS *lep; enum Rela_t { Equ_Rela_t=0, Neq_Rela_t=1, Gtt_Rela_t=2, Geq_Rela_t=3, Lst_Rela_t=4, Leq_Rela_t=5 } op; struct _ExprS *rep; } *cp; struct _StmtS *tp; struct _StmtS *ep; } *ifp; struct _RepeStmtS { struct _StmtS *sp; struct _CondS *cp; } *rpp; struct _ForStmtS { enum For_t { To_For_t=0, Downto_For_t=1 } type; struct _IdentS *idp; struct _ExprS *lep; struct _ExprS *rep; struct _StmtS *sp; } *frp; struct _PcallStmtS { struct _IdentS *idp; struct _ArgListS *alp; } *pcp; struct _CompStmtS *cpp; struct _ReadStmtS { struct _IdentS *idp; struct _ReadStmtS *next; } *rdp; struct _WriteStmtS { enum Write_t { StrId_Write_t=0, Str_Write_t=1, Id_Write_t=2 } type; char *sp; struct _ExprS *ep; } *wtp; } *sp; struct _CompStmtS *next; } *csp; } *bp; } *fdp; struct _FunDecS *next; } *

user_defined_types: struct _BlockS { struct _ConstDecS *cdp; struct _VarDecS *vdp; struct _PFDecListS *pfdlp; struct _CompStmtS *csp; }

user_defined_types: struct _IdentS { enum Ident_t type; char *name; int val; int length; int line; }

user_defined_types: struct _ParaListS { struct _ParaDefS *pdp; struct _ParaListS *next; }

user_defined_types: struct _ProcDefS { struct _ProcHeadS *php; struct _BlockS *bp; }

user_defined_types: struct _IfStmtS { struct _CondS *cp; struct _StmtS *tp; struct _StmtS *ep; }

user_defined_types: struct _ForStmtS { enum For_t type; struct _IdentS *idp; struct _ExprS *lep; struct _ExprS *rep; struct _StmtS *sp; }


analyse

repo: Jeanhwea/Compiler

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

if ( a1 )
result = PgmV(a1);
return result;
}

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

if ( a1 )
result = func26(a1);
return result;
}

original_code:
void analyse(PgmSP t)
{
  if (t != ((void *)0))
    PgmV(t);
}

canonical_original_code:
void analyse(struct _PgmS *t)
{
  if (t != ((void *)0))
    PgmV(t);
}

variable_types: struct _PgmS { struct _BlockS { struct _ConstDecS { struct _ConstDefS { struct _IdentS { enum Ident_t { Init_Ident_t=0, Proc_Ident_t=1, Int_Fun_Ident_t=2, Char_Fun_Ident_t=3, Int_Const_Ident_t=4, Char_Const_Ident_t=5, Int_Var_Ident_t=6, Char_Var_Ident_t=7, IntArr_Var_Ident_t=8, CharArr_Var_Ident_t=9, Int_Para_Val_Ident_t=10, Char_Para_Val_Ident_t=11, Int_Para_Ref_Ident_t=12, Char_Para_Ref_Ident_t=13 } type; char *name; int val; int length; int line; } *idp; } *cdp; struct _ConstDecS *next; } *cdp; struct _VarDecS { struct _VarDefS { struct _IdentS *idp; struct _VarDefS *next; } *vdp; struct _VarDecS *next; } *vdp; struct _PFDecListS { enum PFDec_t { Fun_PFDec_t=0, Proc_PFDec_t=1 } type; struct _ProcDecS { struct _ProcDefS { struct _ProcHeadS { struct _IdentS *idp; struct _ParaListS { struct _ParaDefS { struct _IdentS *idp; struct _ParaDefS *next; } *pdp; struct _ParaListS *next; } *plp; } *php; struct _BlockS *bp; } *pdp; struct _ProcDecS *next; } *pdp; struct _FunDecS { struct _FunDefS { struct _FunHeadS { struct _IdentS *idp; struct _ParaListS *plp; } *fhp; struct _BlockS *bp; } *fdp; struct _FunDecS *next; } *fdp; struct _PFDecListS *next; } *pfdlp; struct _CompStmtS { struct _StmtS { enum Stmt_t { Assgin_Stmt_t=0, IF_Stmt_t=1, Repeat_Stmt_t=2, Pcall_Stmt_t=3, Comp_Stmt_t=4, Read_Stmt_t=5, Write_Stmt_t=6, For_Stmt_t=7, Null_Stmt_t=8 } type; struct _AssignStmtS { enum Assgin_t { Norm_Assgin_t=0, Fun_Assgin_t=1, Array_Assgin_t=2 } type; struct _IdentS *idp; struct _ExprS { enum Addop_t { Nop_Addop_t=0, Add_Addop_t=1, Neg_Addop_t=2, Minus_Addop_t=3 } op; struct _TermS { enum Multop_t { Nop_Multop_t=0, Mult_Multop_t=1, Div_Multop_t=2 } op; struct _FactorS { enum Factor_t { Id_Factor_t=0, Array_Factor_t=1, Unsign_Factor_t=2, Expr_Factor_t=3, Funcall_Factor_t=4 } type; struct _IdentS *idp; struct _ExprS *ep; int usi; struct _FcallStmtS { struct _IdentS *idp; struct _ArgListS { struct _ExprS *ep; struct _ArgListS *next; } *alp; } *fcsp; } *fp; struct _TermS *next; } *tp; struct _ExprS *next; } *lep; struct _ExprS *rep; } *asp; struct _IfStmtS { struct _CondS { struct _ExprS *lep; enum Rela_t { Equ_Rela_t=0, Neq_Rela_t=1, Gtt_Rela_t=2, Geq_Rela_t=3, Lst_Rela_t=4, Leq_Rela_t=5 } op; struct _ExprS *rep; } *cp; struct _StmtS *tp; struct _StmtS *ep; } *ifp; struct _RepeStmtS { struct _StmtS *sp; struct _CondS *cp; } *rpp; struct _ForStmtS { enum For_t { To_For_t=0, Downto_For_t=1 } type; struct _IdentS *idp; struct _ExprS *lep; struct _ExprS *rep; struct _StmtS *sp; } *frp; struct _PcallStmtS { struct _IdentS *idp; struct _ArgListS *alp; } *pcp; struct _CompStmtS *cpp; struct _ReadStmtS { struct _IdentS *idp; struct _ReadStmtS *next; } *rdp; struct _WriteStmtS { enum Write_t { StrId_Write_t=0, Str_Write_t=1, Id_Write_t=2 } type; char *sp; struct _ExprS *ep; } *wtp; } *sp; struct _CompStmtS *next; } *csp; } *bp; } *

return_type: void

user_defined_types: struct _ConstDecS { struct _ConstDefS *cdp; struct _ConstDecS *next; }

user_defined_types: struct _VarDecS { struct _VarDefS *vdp; struct _VarDecS *next; }

user_defined_types: struct _PFDecListS { enum PFDec_t type; struct _ProcDecS *pdp; struct _FunDecS *fdp; struct _PFDecListS *next; }

user_defined_types: struct _CompStmtS { struct _StmtS *sp; struct _CompStmtS *next; }

user_defined_types: struct _ConstDefS { struct _IdentS *idp; }

user_defined_types: struct _ProcDecS { struct _ProcDefS *pdp; struct _ProcDecS *next; }

user_defined_types: struct _FunDecS { struct _FunDefS *fdp; struct _FunDecS *next; }

user_defined_types: struct _StmtS { enum Stmt_t type; struct _AssignStmtS *asp; struct _IfStmtS *ifp; struct _RepeStmtS *rpp; struct _ForStmtS *frp; struct _PcallStmtS *pcp; struct _CompStmtS *cpp; struct _ReadStmtS *rdp; struct _WriteStmtS *wtp; }

user_defined_types: struct _FunDefS { struct _FunHeadS *fhp; struct _BlockS *bp; }

user_defined_types: struct _AssignStmtS { enum Assgin_t type; struct _IdentS *idp; struct _ExprS *lep; struct _ExprS *rep; }

user_defined_types: struct _WriteStmtS { enum Write_t type; char *sp; struct _ExprS *ep; }

user_defined_types: struct _ProcHeadS { struct _IdentS *idp; struct _ParaListS *plp; }

user_defined_types: struct _ExprS { enum Addop_t op; struct _TermS *tp; struct _ExprS *next; }

user_defined_types: struct _CondS { struct _ExprS *lep; enum Rela_t op; struct _ExprS *rep; }

user_defined_types: struct _TermS { enum Multop_t op; struct _FactorS *fp; struct _TermS *next; }

user_defined_types: struct _FactorS { enum Factor_t type; struct _IdentS *idp; struct _ExprS *ep; int usi; struct _FcallStmtS *fcsp; }

user_defined_types: struct _FcallStmtS { struct _IdentS *idp; struct _ArgListS *alp; }


decompiled_code:
__pid_t do_compile()
{
__pid_t v0; // eax
__pid_t result; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

v0 = fork();
if ( v0 < 0 )
{
fwrite("can not fork", 1uLL, 0xCuLL, stderr);
exit(1);
}
if ( v0 )
result = wait((__WAIT_STATUS)&stat_loc);
else
result = execl("/usr/bin/nasm", "nasm", "-g", "-f", "elf", asmlistf, 0LL);
return result;
}

canonical_decompiled_code:
__pid_t func0()
{
__pid_t v0; // eax
__pid_t result; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

v0 = fork();
if ( v0 < 0 )
{
fwrite("can not fork", 1uLL, 0xCuLL, stderr);
exit(1);
}
if ( v0 )
result = wait((__WAIT_STATUS)&stat_loc);
else
result = execl("/usr/bin/nasm", "nasm", "-g", "-f", "elf", asmlistf, 0LL);
return result;
}

original_code:
void do_compile(void)
{
 int state;
 pid_t pid;
 if ((pid = fork()) < 0) {
  fprintf(stderr, "can not fork");
  exit(1);
 }
 if (pid == 0) {
  execl("/usr/bin/nasm", "nasm", "-g", "-f", "elf", asmlistf, (char *)0);
 } else {
  wait(&state);
 }
}

canonical_original_code:
void do_compile()
{
 int state;
 int pid;
 if ((pid = fork()) < 0) {
  fprintf(stderr, "can not fork");
  exit(1);
 }
 if (pid == 0) {
  execl("/usr/bin/nasm", "nasm", "-g", "-f", "elf", asmlistf, (char *)0);
 } else {
  wait(&state);
 }
}

variable_types: state int

variable_types: pid int


decompiled_code:
__pid_t do_link()
{
int v0; // ebx
char *v1; // r12
char *v2; // rbp
__pid_t v3; // eax
__pid_t result; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = fnlen;
v1 = (char *)calloc(fnlen + 1, 1uLL);
v2 = (char *)calloc(v0 + 3, 1uLL);
strncpy(v1, pgm, v0);
strncpy(v2, pgm, v0);
strcat(v2, ".o");
v3 = fork();
if ( v3 < 0 )
{
fwrite("can not fork", 1uLL, 0xCuLL, stderr);
exit(1);
}
if ( v3 )
result = wait((__WAIT_STATUS)&stat_loc);
else
result = execl("/usr/bin/gcc", "gcc", "-g", "-o", v1, v2, 0LL);
return result;
}

canonical_decompiled_code:
__pid_t func1()
{
int v0; // ebx
char *v1; // r12
char *v2; // rbp
__pid_t v3; // eax
__pid_t result; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = fnlen;
v1 = (char *)calloc(fnlen + 1, 1uLL);
v2 = (char *)calloc(v0 + 3, 1uLL);
strncpy(v1, pgm, v0);
strncpy(v2, pgm, v0);
strcat(v2, ".o");
v3 = fork();
if ( v3 < 0 )
{
fwrite("can not fork", 1uLL, 0xCuLL, stderr);
exit(1);
}
if ( v3 )
result = wait((__WAIT_STATUS)&stat_loc);
else
result = execl("/usr/bin/gcc", "gcc", "-g", "-o", v1, v2, 0LL);
return result;
}

original_code:
void do_link(void)
{
 int state;
 pid_t pid;
 char *objfile;
 char *outputfile;
 outputfile = (char *)calloc(fnlen + 1, sizeof(char));
 objfile = (char *)calloc(fnlen + 3, sizeof(char));
 strncpy(outputfile, pgm, fnlen);
 strncpy(objfile, pgm, fnlen);
 strcat(objfile, ".o");
 if ((pid = fork()) < 0) {
  fprintf(stderr, "can not fork");
  exit(1);
 }
 if (pid == 0) {
  execl("/usr/bin/gcc", "gcc","-g", "-o", outputfile, objfile, (char *)0);
 } else {
  wait(&state);
 }
}

canonical_original_code:
void do_link()
{
 int state;
 int pid;
 char *objfile;
 char *outputfile;
 outputfile = (char *)calloc(fnlen + 1, sizeof(char));
 objfile = (char *)calloc(fnlen + 3, sizeof(char));
 strncpy(outputfile, pgm, fnlen);
 strncpy(objfile, pgm, fnlen);
 strcat(objfile, ".o");
 if ((pid = fork()) < 0) {
  fprintf(stderr, "can not fork");
  exit(1);
 }
 if (pid == 0) {
  execl("/usr/bin/gcc", "gcc","-g", "-o", outputfile, objfile, (char *)0);
 } else {
  wait(&state);
 }
}

variable_types:
objfile
char *

variable_types:
outputfile
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // ebp
char v5; // al
int v6; // er14
int v7; // er12
int v8; // er13
size_t v9; // rax
char *v10; // rbx
int v11; // ebp
char *v12; // rbx
int v13; // ebp
char *v14; // rbx
__int64 v15; // rax
__int64 v16; // rbx
int v18; // ebp
char *v19; // rbx
int v20; // ebp
char *v21; // rbx
int v22; // ebp
char *v23; // rbx

fwrite("compiler version 0.9.9 starting ...\n", 1uLL, 0x24uLL, stdout);
if ( argc <= 1 )
{
fwrite("usage: ./compiler <filename>\n", 1uLL, 0x1DuLL, stdout);
exit(1);
}
v3 = argc;
strcpy(pgm, argv[v3 - 1]);
source = fopen(pgm, "r");
if ( !source )
{
fprintf(stderr, "File `%s` not found\n", pgm);
exit(1);
}
if ( !strchr(pgm, 46) )
{
v9 = strlen(pgm);
*(_DWORD *)&pgm[v9] = 1935765550;
pgm[v9 + 4] = 0;
}
v4 = strcspn(pgm, ".");
fnlen = v4;
v5 = *argv[v3 - 2];
if ( v5 == 100 )
{
listing = stdout;
code = stdout;
stablist = stdout;
v6 = 0;
v7 = 0;
v8 = 1;
}
else if ( v5 == 111 )
{
listing = stdout;
code = stdout;
stablist = stdout;
v6 = 0;
v7 = 1;
v8 = 1;
}
else if ( v5 == 115 )
{
listing = stdout;
code = stdout;
stablist = stdout;
v6 = 0;
v7 = 1;
v8 = 0;
}
else
{
if ( v5 == 99 )
{
listing = stdout;
code = stdout;
stablist = stdout;
v6 = 1;
}
else
{
v6 = 0;
}
v7 = 0;
v8 = 0;
}
daglist = (__int64)stdout;
errlist = (__int64)stderr;
tiplist = (__int64)stderr;
v10 = (char *)calloc(v4 + 5, 1uLL);
asmlistf = (__int64)v10;
strncpy(v10, pgm, v4);
strcat(v10, ".asm");
asmlist = fopen(v10, "w");
if ( !asmlist )
{
fprintf(stderr, "Unable to open %s\n", (const char *)asmlistf);
exit(1);
}
if ( v7 )
{
v11 = fnlen;
v12 = (char *)calloc(fnlen + 16, 1uLL);
asmoptimf = (__int64)v12;
strncpy(v12, pgm, v11);
strcat(v12, ".optim.asm");
asmoptim = fopen(v12, "w");
if ( !asmoptim )
{
fprintf(stderr, "Unable to open %s\n", (const char *)asmoptimf);
exit(1);
}
}
v13 = fnlen;
v14 = (char *)calloc(fnlen + 5, 1uLL);
astlistf = (__int64)v14;
strncpy(v14, pgm, v13);
strcat(v14, ".xml");
astlist = fopen(v14, "w");
if ( !astlist )
{
fprintf(stderr, "Unable to open %s\n", (const char *)astlistf);
exit(1);
}
if ( !v8 )
{
v18 = fnlen;
v19 = (char *)calloc(fnlen + 6, 1uLL);
codef = (__int64)v19;
strncpy(v19, pgm, v18);
strcat(v19, ".qaud");
code = fopen(v19, "w");
if ( !code )
{
fprintf(stderr, "Unable to open %s\n", (const char *)codef);
exit(1);
}
v20 = fnlen;
v21 = (char *)calloc(fnlen + 5, 1uLL);
listingf = (__int64)v21;
strncpy(v21, pgm, v20);
strcat(v21, ".lst");
listing = fopen(v21, "w");
if ( !listing )
{
fprintf(stderr, "Unable to open %s\n", (const char *)listingf);
exit(1);
}
v22 = fnlen;
v23 = (char *)calloc(fnlen + 5, 1uLL);
stablistf = (__int64)v23;
strncpy(v23, pgm, v22);
strcat(v23, ".stb");
stablist = fopen(v23, "w");
if ( !stablist )
{
fprintf(stderr, "Unable to open %s\n", (const char *)stablistf);
exit(1);
}
}
if ( runlevel <= 2 )
exit(1);
v15 = parse();
v16 = v15;
if ( runlevel <= 1 )
exit(1);
analyse(v15);
coder(v16);
if ( runlevel <= 0 )
exit(1);
elf();
if ( v7 )
{
print_all_variables();
fclose(asmlist);
asmlist = asmoptim;
make_fgraph();
dataflow();
global_reg_alocate();
fclose(source);
fclose(astlist);
if ( !v8 )
{
fclose(code);
fclose(listing);
fclose(stablist);
}
fclose(asmoptim);
}
else
{
fclose(source);
fclose(asmlist);
fclose(astlist);
if ( !v8 )
{
fclose(code);
fclose(listing);
fclose(stablist);
}
}
if ( v6 )
{
do_compile();
do_link();
}
fwrite("__ done __\n", 1uLL, 0xBuLL, stdout);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // ebp
char v5; // al
int v6; // er14
int v7; // er12
int v8; // er13
size_t v9; // rax
char *v10; // rbx
int v11; // ebp
char *v12; // rbx
int v13; // ebp
char *v14; // rbx
__int64 v15; // rax
__int64 v16; // rbx
int v18; // ebp
char *v19; // rbx
int v20; // ebp
char *v21; // rbx
int v22; // ebp
char *v23; // rbx

fwrite("compiler version 0.9.9 starting ...\n", 1uLL, 0x24uLL, stdout);
if ( argc <= 1 )
{
fwrite("usage: ./compiler <filename>\n", 1uLL, 0x1DuLL, stdout);
exit(1);
}
v3 = argc;
strcpy(pgm, argv[v3 - 1]);
source = fopen(pgm, "r");
if ( !source )
{
fprintf(stderr, "File `%s` not found\n", pgm);
exit(1);
}
if ( !strchr(pgm, 46) )
{
v9 = strlen(pgm);
*(_DWORD *)&pgm[v9] = 1935765550;
pgm[v9 + 4] = 0;
}
v4 = strcspn(pgm, ".");
fnlen = v4;
v5 = *argv[v3 - 2];
if ( v5 == 100 )
{
listing = stdout;
code = stdout;
stablist = stdout;
v6 = 0;
v7 = 0;
v8 = 1;
}
else if ( v5 == 111 )
{
listing = stdout;
code = stdout;
stablist = stdout;
v6 = 0;
v7 = 1;
v8 = 1;
}
else if ( v5 == 115 )
{
listing = stdout;
code = stdout;
stablist = stdout;
v6 = 0;
v7 = 1;
v8 = 0;
}
else
{
if ( v5 == 99 )
{
listing = stdout;
code = stdout;
stablist = stdout;
v6 = 1;
}
else
{
v6 = 0;
}
v7 = 0;
v8 = 0;
}
daglist = (__int64)stdout;
errlist = (__int64)stderr;
tiplist = (__int64)stderr;
v10 = (char *)calloc(v4 + 5, 1uLL);
asmlistf = (__int64)v10;
strncpy(v10, pgm, v4);
strcat(v10, ".asm");
asmlist = fopen(v10, "w");
if ( !asmlist )
{
fprintf(stderr, "Unable to open %s\n", (const char *)asmlistf);
exit(1);
}
if ( v7 )
{
v11 = fnlen;
v12 = (char *)calloc(fnlen + 16, 1uLL);
asmoptimf = (__int64)v12;
strncpy(v12, pgm, v11);
strcat(v12, ".optim.asm");
asmoptim = fopen(v12, "w");
if ( !asmoptim )
{
fprintf(stderr, "Unable to open %s\n", (const char *)asmoptimf);
exit(1);
}
}
v13 = fnlen;
v14 = (char *)calloc(fnlen + 5, 1uLL);
astlistf = (__int64)v14;
strncpy(v14, pgm, v13);
strcat(v14, ".xml");
astlist = fopen(v14, "w");
if ( !astlist )
{
fprintf(stderr, "Unable to open %s\n", (const char *)astlistf);
exit(1);
}
if ( !v8 )
{
v18 = fnlen;
v19 = (char *)calloc(fnlen + 6, 1uLL);
codef = (__int64)v19;
strncpy(v19, pgm, v18);
strcat(v19, ".qaud");
code = fopen(v19, "w");
if ( !code )
{
fprintf(stderr, "Unable to open %s\n", (const char *)codef);
exit(1);
}
v20 = fnlen;
v21 = (char *)calloc(fnlen + 5, 1uLL);
listingf = (__int64)v21;
strncpy(v21, pgm, v20);
strcat(v21, ".lst");
listing = fopen(v21, "w");
if ( !listing )
{
fprintf(stderr, "Unable to open %s\n", (const char *)listingf);
exit(1);
}
v22 = fnlen;
v23 = (char *)calloc(fnlen + 5, 1uLL);
stablistf = (__int64)v23;
strncpy(v23, pgm, v22);
strcat(v23, ".stb");
stablist = fopen(v23, "w");
if ( !stablist )
{
fprintf(stderr, "Unable to open %s\n", (const char *)stablistf);
exit(1);
}
}
if ( runlevel <= 2 )
exit(1);
v15 = parse();
v16 = v15;
if ( runlevel <= 1 )
exit(1);
analyse(v15);
coder(v16);
if ( runlevel <= 0 )
exit(1);
elf();
if ( v7 )
{
print_all_variables();
fclose(asmlist);
asmlist = asmoptim;
make_fgraph();
dataflow();
global_reg_alocate();
fclose(source);
fclose(astlist);
if ( !v8 )
{
fclose(code);
fclose(listing);
fclose(stablist);
}
fclose(asmoptim);
}
else
{
fclose(source);
fclose(asmlist);
fclose(astlist);
if ( !v8 )
{
fclose(code);
fclose(listing);
fclose(stablist);
}
}
if ( v6 )
{
func0();
func1();
}
fwrite("__ done __\n", 1uLL, 0xBuLL, stdout);
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
 PgmSP ast;
 BOOL debug = 0;
 BOOL optim = 0;
 BOOL compile_and_link = 0;
 fprintf(stdout, "compiler version 0.9.9 starting ...\n");
 if (argc < 2) {
  fprintf(stdout, "usage: ./compiler <filename>\n");
  exit(1);
 }
 strcpy(pgm,argv[argc-1]);
 source = fopen(pgm, "r");
 if (source == ((void *)0)) {
  fprintf(stderr, "File `%s` not found\n", pgm);
  exit(1);
 }
 if (strchr(pgm, '.') == ((void *)0)) {
  strcat(pgm, ".pas");
 }
 fnlen = strcspn(pgm, ".");
 if (argv[argc-2][0] == 'd') {
  debug = 1;
  listing = stdout;
  code = stdout;
  stablist = stdout;
 } else if (argv[argc-2][0] == 'o') {
  debug = 1;
  optim = 1;
  listing = stdout;
  code = stdout;
  stablist = stdout;
 } else if (argv[argc-2][0] == 's') {
  optim = 1;
  listing = stdout;
  code = stdout;
  stablist = stdout;
 } else if (argv[argc-2][0] == 'c') {
  compile_and_link = 1;
  listing = stdout;
  code = stdout;
  stablist = stdout;
 }
 daglist = stdout;
 errlist = stderr;
 tiplist = stderr;
 asmlistf = (char *)calloc(fnlen + 5, sizeof(char));
 strncpy(asmlistf, pgm, fnlen);
 strcat(asmlistf, ".asm");
 asmlist = fopen(asmlistf, "w");
 if (asmlist == ((void *)0)) {
  fprintf(stderr, "Unable to open %s\n", asmlistf);
  exit(1);
 }
 if (optim) {
  asmoptimf = (char *)calloc(fnlen + 16, sizeof(char));
  strncpy(asmoptimf, pgm, fnlen);
  strcat(asmoptimf, ".optim.asm");
  asmoptim = fopen(asmoptimf, "w");
  if (asmoptim == ((void *)0)) {
   fprintf(stderr, "Unable to open %s\n", asmoptimf);
   exit(1);
  }
 }
 astlistf = (char *)calloc(fnlen + 5, sizeof(char));
 strncpy(astlistf, pgm, fnlen);
 strcat(astlistf, ".xml");
 astlist = fopen(astlistf, "w");
 if (astlist == ((void *)0)) {
  fprintf(stderr, "Unable to open %s\n", astlistf);
  exit(1);
 }
 if (!debug) {
  codef = (char *)calloc(fnlen + 6, sizeof(char));
  strncpy(codef, pgm, fnlen);
  strcat(codef, ".qaud");
  code = fopen(codef, "w");
  if (code == ((void *)0)) {
   fprintf(stderr, "Unable to open %s\n", codef);
   exit(1);
  }
  listingf = (char *)calloc(fnlen + 5, sizeof(char));
  strncpy(listingf, pgm, fnlen);
  strcat(listingf, ".lst");
  listing = fopen(listingf, "w");
  if (listing == ((void *)0)) {
   fprintf(stderr, "Unable to open %s\n", listingf);
   exit(1);
  }
  stablistf = (char *)calloc(fnlen + 5, sizeof(char));
  strncpy(stablistf, pgm, fnlen);
  strcat(stablistf, ".stb");
  stablist = fopen(stablistf, "w");
  if (stablist == ((void *)0)) {
   fprintf(stderr, "Unable to open %s\n", stablistf);
   exit(1);
  }
 }
 if (runlevel > 2) {
  ast = parse();
 } else {
  exit(1);
 }
 if (runlevel > 1) {
  analyse(ast);
  coder(ast);
 } else {
  exit(1);
 }
 if (runlevel > 0) {
  elf();
 } else {
  exit(1);
 }
 if (optim) {
  print_all_variables();
  fclose(asmlist);
  asmlist = asmoptim;
  make_fgraph();
  dataflow();
  global_reg_alocate();
 }
 fclose(source);
 if(!optim) fclose(asmlist);
 fclose(astlist);
 if (!debug) {
  fclose(code);
  fclose(listing);
  fclose(stablist);
 }
 if (optim) {
  fclose(asmoptim);
 }
 if (compile_and_link) {
  do_compile();
  do_link();
 }
 fprintf(stdout, "__ done __\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct _PgmS *ast;
 int debug = 0;
 int optim = 0;
 int compile_and_link = 0;
 fprintf(stdout, "compiler version 0.9.9 starting ...\n");
 if (argc < 2) {
  fprintf(stdout, "usage: ./compiler <filename>\n");
  exit(1);
 }
 strcpy(pgm,argv[argc-1]);
 source = fopen(pgm, "r");
 if (source == ((void *)0)) {
  fprintf(stderr, "File `%s` not found\n", pgm);
  exit(1);
 }
 if (strchr(pgm, '.') == ((void *)0)) {
  strcat(pgm, ".pas");
 }
 fnlen = strcspn(pgm, ".");
 if (argv[argc-2][0] == 'd') {
  debug = 1;
  listing = stdout;
  code = stdout;
  stablist = stdout;
 } else if (argv[argc-2][0] == 'o') {
  debug = 1;
  optim = 1;
  listing = stdout;
  code = stdout;
  stablist = stdout;
 } else if (argv[argc-2][0] == 's') {
  optim = 1;
  listing = stdout;
  code = stdout;
  stablist = stdout;
 } else if (argv[argc-2][0] == 'c') {
  compile_and_link = 1;
  listing = stdout;
  code = stdout;
  stablist = stdout;
 }
 daglist = stdout;
 errlist = stderr;
 tiplist = stderr;
 asmlistf = (char *)calloc(fnlen + 5, sizeof(char));
 strncpy(asmlistf, pgm, fnlen);
 strcat(asmlistf, ".asm");
 asmlist = fopen(asmlistf, "w");
 if (asmlist == ((void *)0)) {
  fprintf(stderr, "Unable to open %s\n", asmlistf);
  exit(1);
 }
 if (optim) {
  asmoptimf = (char *)calloc(fnlen + 16, sizeof(char));
  strncpy(asmoptimf, pgm, fnlen);
  strcat(asmoptimf, ".optim.asm");
  asmoptim = fopen(asmoptimf, "w");
  if (asmoptim == ((void *)0)) {
   fprintf(stderr, "Unable to open %s\n", asmoptimf);
   exit(1);
  }
 }
 astlistf = (char *)calloc(fnlen + 5, sizeof(char));
 strncpy(astlistf, pgm, fnlen);
 strcat(astlistf, ".xml");
 astlist = fopen(astlistf, "w");
 if (astlist == ((void *)0)) {
  fprintf(stderr, "Unable to open %s\n", astlistf);
  exit(1);
 }
 if (!debug) {
  codef = (char *)calloc(fnlen + 6, sizeof(char));
  strncpy(codef, pgm, fnlen);
  strcat(codef, ".qaud");
  code = fopen(codef, "w");
  if (code == ((void *)0)) {
   fprintf(stderr, "Unable to open %s\n", codef);
   exit(1);
  }
  listingf = (char *)calloc(fnlen + 5, sizeof(char));
  strncpy(listingf, pgm, fnlen);
  strcat(listingf, ".lst");
  listing = fopen(listingf, "w");
  if (listing == ((void *)0)) {
   fprintf(stderr, "Unable to open %s\n", listingf);
   exit(1);
  }
  stablistf = (char *)calloc(fnlen + 5, sizeof(char));
  strncpy(stablistf, pgm, fnlen);
  strcat(stablistf, ".stb");
  stablist = fopen(stablistf, "w");
  if (stablist == ((void *)0)) {
   fprintf(stderr, "Unable to open %s\n", stablistf);
   exit(1);
  }
 }
 if (runlevel > 2) {
  ast = parse();
 } else {
  exit(1);
 }
 if (runlevel > 1) {
  analyse(ast);
  coder(ast);
 } else {
  exit(1);
 }
 if (runlevel > 0) {
  elf();
 } else {
  exit(1);
 }
 if (optim) {
  print_all_variables();
  fclose(asmlist);
  asmlist = asmoptim;
  make_fgraph();
  dataflow();
  global_reg_alocate();
 }
 fclose(source);
 if(!optim) fclose(asmlist);
 fclose(astlist);
 if (!debug) {
  fclose(code);
  fclose(listing);
  fclose(stablist);
 }
 if (optim) {
  fclose(asmoptim);
 }
 if (compile_and_link) {
  do_compile();
  do_link();
 }
 fprintf(stdout, "__ done __\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: debug int

variable_types: optim int

return_type: int

user_defined_types: struct _BlockS { struct _ConstDecS *cdp; struct _VarDecS *vdp; struct _PFDecListS *pfdlp; struct _CompStmtS *csp; }

user_defined_types: struct _ConstDecS { struct _ConstDefS *cdp; struct _ConstDecS *next; }

user_defined_types: enum PFDec_t { Fun_PFDec_t=0, Proc_PFDec_t=1 }

user_defined_types: struct _VarDefS { struct _IdentS *idp; struct _VarDefS *next; }

user_defined_types: enum Stmt_t { Assgin_Stmt_t=0, IF_Stmt_t=1, Repeat_Stmt_t=2, Pcall_Stmt_t=3, Comp_Stmt_t=4, Read_Stmt_t=5, Write_Stmt_t=6, For_Stmt_t=7, Null_Stmt_t=8 }

user_defined_types: struct _IdentS { enum Ident_t type; char *name; int val; int length; int line; }

user_defined_types: struct _ProcDefS { struct _ProcHeadS *php; struct _BlockS *bp; }

user_defined_types: struct _IfStmtS { struct _CondS *cp; struct _StmtS *tp; struct _StmtS *ep; }

user_defined_types: struct _RepeStmtS { struct _StmtS *sp; struct _CondS *cp; }

user_defined_types: struct _ForStmtS { enum For_t type; struct _IdentS *idp; struct _ExprS *lep; struct _ExprS *rep; struct _StmtS *sp; }

user_defined_types: struct _PcallStmtS { struct _IdentS *idp; struct _ArgListS *alp; }

user_defined_types: struct _ReadStmtS { struct _IdentS *idp; struct _ReadStmtS *next; }

user_defined_types: enum Ident_t { Init_Ident_t=0, Proc_Ident_t=1, Int_Fun_Ident_t=2, Char_Fun_Ident_t=3, Int_Const_Ident_t=4, Char_Const_Ident_t=5, Int_Var_Ident_t=6, Char_Var_Ident_t=7, IntArr_Var_Ident_t=8, CharArr_Var_Ident_t=9, Int_Para_Val_Ident_t=10, Char_Para_Val_Ident_t=11, Int_Para_Ref_Ident_t=12, Char_Para_Ref_Ident_t=13 }

user_defined_types: enum Assgin_t { Norm_Assgin_t=0, Fun_Assgin_t=1, Array_Assgin_t=2 }

user_defined_types: enum For_t { To_For_t=0, Downto_For_t=1 }

user_defined_types: enum Write_t { StrId_Write_t=0, Str_Write_t=1, Id_Write_t=2 }

user_defined_types: struct _FunHeadS { struct _IdentS *idp; struct _ParaListS *plp; }

user_defined_types: enum Addop_t { Nop_Addop_t=0, Add_Addop_t=1, Neg_Addop_t=2, Minus_Addop_t=3 }

user_defined_types: enum Rela_t { Equ_Rela_t=0, Neq_Rela_t=1, Gtt_Rela_t=2, Geq_Rela_t=3, Lst_Rela_t=4, Leq_Rela_t=5 }

user_defined_types: struct _ParaListS { struct _ParaDefS *pdp; struct _ParaListS *next; }

user_defined_types: enum Multop_t { Nop_Multop_t=0, Mult_Multop_t=1, Div_Multop_t=2 }

user_defined_types: struct _ParaDefS { struct _IdentS *idp; struct _ParaDefS *next; }

user_defined_types: enum Factor_t { Id_Factor_t=0, Array_Factor_t=1, Unsign_Factor_t=2, Expr_Factor_t=3, Funcall_Factor_t=4 }

user_defined_types: struct _ArgListS { struct _ExprS *ep; struct _ArgListS *next; }


decompiled_code:
__int64 __fastcall dagable_bblock(__int64 a1)
{
unsigned int *v1; // rax
__int64 v2; // rcx
unsigned __int64 v3; // rdx

v1 = *(unsigned int **)(a1 + 32);
if ( !v1 )
return 1LL;
v2 = 1058536959LL;
while ( 1 )
{
v3 = *v1;
if ( (unsigned int)v3 > 0x1D )
return 0LL;
if ( !_bittest64(&v2, v3) )
return 0LL;
if ( *(unsigned int **)(a1 + 40) == v1 )
break;
v1 = (unsigned int *)*((_QWORD *)v1 + 5);
if ( !v1 )
return 1LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int *v1; // rax
__int64 v2; // rcx
unsigned __int64 v3; // rdx

v1 = *(unsigned int **)(a1 + 32);
if ( !v1 )
return 1LL;
v2 = 1058536959LL;
while ( 1 )
{
v3 = *v1;
if ( (unsigned int)v3 > 0x1D )
return 0LL;
if ( !_bittest64(&v2, v3) )
return 0LL;
if ( *(unsigned int **)(a1 + 40) == v1 )
break;
v1 = (unsigned int *)*((_QWORD *)v1 + 5);
if ( !v1 )
return 1LL;
}
return 1LL;
}

original_code:
BOOL dagable_bblock(BBSP b)
{
 QuadSP p;
 for (p = b->first; p != ((void *)0); p = p->next) {
  if (!((p->op==ADD_op)||(p->op==SUB_op)||(p->op==MUL_op)||(p->op==DIV_op)||(p->op==NEG_op)||(p->op==ASS_op)||(p->op==INC_op)||(p->op==DEC_op)||(p->op==EQU_op)||(p->op==NEQ_op)||(p->op==GTT_op)||(p->op==GEQ_op)||(p->op==LST_op)||(p->op==LEQ_op)||(p->op==READ_op)||(p->op==READC_op)||(p->op==WRI_op)||(p->op==WRC_op)||(p->op==WRS_op)||(p->op==LOAD_op)||(p->op==JMP_op)||(p->op==CALL_op)||(p->op==PUSH_op)||(p->op==PUSHA_op)||(p->op==LABEL_op))) return 0;
  if (p == b->last) break;
 }
 return 1;
}

canonical_original_code:
int dagable_bblock(struct _BBS *b)
{
 struct _QuadS *p;
 for (p = b->first; p != ((void *)0); p = p->next) {
  if (!((p->op==ADD_op)||(p->op==SUB_op)||(p->op==MUL_op)||(p->op==DIV_op)||(p->op==NEG_op)||(p->op==ASS_op)||(p->op==INC_op)||(p->op==DEC_op)||(p->op==EQU_op)||(p->op==NEQ_op)||(p->op==GTT_op)||(p->op==GEQ_op)||(p->op==LST_op)||(p->op==LEQ_op)||(p->op==READ_op)||(p->op==READC_op)||(p->op==WRI_op)||(p->op==WRC_op)||(p->op==WRS_op)||(p->op==LOAD_op)||(p->op==JMP_op)||(p->op==CALL_op)||(p->op==PUSH_op)||(p->op==PUSHA_op)||(p->op==LABEL_op))) return 0;
  if (p == b->last) break;
 }
 return 1;
}

variable_types: struct _BBS { int id; struct _QuadS { enum Quad_t { ADD_op=0, SUB_op=1, MUL_op=2, DIV_op=3, INC_op=4, DEC_op=5, NEG_op=6, LOAD_op=7, ASS_op=8, AARR_op=9, EQU_op=10, NEQ_op=11, GTT_op=12, GEQ_op=13, LST_op=14, LEQ_op=15, JMP_op=16, PUSH_op=17, PUSHA_op=18, POP_op=19, CALL_op=20, SRET_op=21, ENTER_op=22, FIN_op=23, READ_op=24, READC_op=25, WRS_op=26, WRI_op=27, WRC_op=28, LABEL_op=29 } op; struct _SymTabES { char *name; char *label; int val; int lineno; int level; int posi; enum Obj_t { Nop_Obj_t=0, Const_Obj_t=1, Var_Obj_t=2, Proc_Obj_t=3, Fun_Obj_t=4, Array_Obj_t=5, Para_Val_Obj_t=6, Para_Ref_Obj_t=7, Tmp_Obj_t=8, Label_Obj_t=9, Num_Obj_t=10, String_Obj_t=11 } obj; enum Type_t { Int_Type_t=0, Char_Type_t=1, Nop_Type_t=2 } type; struct _SymTabS { struct _SymBucketS { struct _SymTabES *ep; struct _SymBucketS *next; } **sbp; int posi_var; int posi_para; int posi_tmp; int level; struct _SymBucketS *headinfo; struct _SymBucketS *tailinfo; struct _SymTabS *prev; struct _SymTabS *next; } *stp; } *r; struct _SymTabES *s; struct _SymTabES *d; struct _QuadS *prev; struct _QuadS *next; int rm_flag; } *qhead; struct _QuadS *qtail; struct _QuadS *scope; struct _QuadS *first; struct _QuadS *last; struct _BBListS { struct _BBS *bbp; struct _BBListS *next; } *pres; struct _BBListS *posts; int use[8]; int def[8]; int in_old[8]; int out_old[8]; int in[8]; int out[8]; } *

user_defined_types: struct _BBS { int id; struct _QuadS *qhead; struct _QuadS *qtail; struct _QuadS *scope; struct _QuadS *first; struct _QuadS *last; struct _BBListS *pres; struct _BBListS *posts; int use[8]; int def[8]; int in_old[8]; int out_old[8]; int in[8]; int out[8]; }

user_defined_types: struct _QuadS { enum Quad_t op; struct _SymTabES *r; struct _SymTabES *s; struct _SymTabES *d; struct _QuadS *prev; struct _QuadS *next; int rm_flag; }

user_defined_types: struct _SymTabES { char *name; char *label; int val; int lineno; int level; int posi; enum Obj_t obj; enum Type_t type; struct _SymTabS *stp; }

user_defined_types: struct _SymTabS { struct _SymBucketS **sbp; int posi_var; int posi_para; int posi_tmp; int level; struct _SymBucketS *headinfo; struct _SymBucketS *tailinfo; struct _SymTabS *prev; struct _SymTabS *next; }


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

initLeader();
elf_header();
do
{
v0 = newBblock();
addBblock(v0);
if ( (unsigned int)dagable_bblock(v0) )
make_dag_for_bblock(v0);
else
copy_quad_for_bblock(v0);
printAllQuads(*(_QWORD *)(v0 + 8));
}
while ( !(unsigned int)quad_end() );
return link_bblock();
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx

initLeader();
elf_header();
do
{
v0 = newBblock();
addBblock(v0);
if ( (unsigned int)func0(v0) )
make_dag_for_bblock(v0);
else
copy_quad_for_bblock(v0);
printAllQuads(*(_QWORD *)(v0 + 8));
}
while ( !(unsigned int)quad_end() );
return link_bblock();
}

original_code:
void make_fgraph(void)
{
 BBSP b;
 initLeader();
 elf_header();
 do {
  b = newBblock();
  addBblock(b);
  if (dagable_bblock(b)) {
   make_dag_for_bblock(b);
  } else {
   copy_quad_for_bblock(b);
  }
  printAllQuads(b->qhead);
 } while (!quad_end());
 link_bblock();
}

canonical_original_code:
void make_fgraph()
{
 struct _BBS *b;
 initLeader();
 elf_header();
 do {
  b = newBblock();
  addBblock(b);
  if (dagable_bblock(b)) {
   make_dag_for_bblock(b);
  } else {
   copy_quad_for_bblock(b);
  }
  printAllQuads(b->qhead);
 } while (!quad_end());
 link_bblock();
}

user_defined_types: struct _BBListS { struct _BBS *bbp; struct _BBListS *next; }

user_defined_types: enum Quad_t { ADD_op=0, SUB_op=1, MUL_op=2, DIV_op=3, INC_op=4, DEC_op=5, NEG_op=6, LOAD_op=7, ASS_op=8, AARR_op=9, EQU_op=10, NEQ_op=11, GTT_op=12, GEQ_op=13, LST_op=14, LEQ_op=15, JMP_op=16, PUSH_op=17, PUSHA_op=18, POP_op=19, CALL_op=20, SRET_op=21, ENTER_op=22, FIN_op=23, READ_op=24, READC_op=25, WRS_op=26, WRI_op=27, WRC_op=28, LABEL_op=29 }

user_defined_types: enum Obj_t { Nop_Obj_t=0, Const_Obj_t=1, Var_Obj_t=2, Proc_Obj_t=3, Fun_Obj_t=4, Array_Obj_t=5, Para_Val_Obj_t=6, Para_Ref_Obj_t=7, Tmp_Obj_t=8, Label_Obj_t=9, Num_Obj_t=10, String_Obj_t=11 }

user_defined_types: enum Type_t { Int_Type_t=0, Char_Type_t=1, Nop_Type_t=2 }

user_defined_types: struct _SymBucketS { struct _SymTabES *ep; struct _SymBucketS *next; }


dataflow

decompiled_code:
__int64 dataflow()
{
__int64 result; // rax
_QWORD *v1; // rbx

cal_use_def();
do_dataflow();
printAllBblock();
rm_useless_assign();
result = printAllBblock();
v1 = (_QWORD *)bblst;
if ( bblst )
{
do
{
result = elf_for_block(*v1);
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
return result;
}

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

cal_use_def();
do_dataflow();
printAllBblock();
rm_useless_assign();
result = printAllBblock();
v1 = (_QWORD *)bblst;
if ( bblst )
{
do
{
result = elf_for_block(*v1);
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
return result;
}

original_code:
void dataflow(void)
{
 BBListSP bl;
 cal_use_def();
 do_dataflow();
 _printAllBblock();
 rm_useless_assign();
 _printAllBblock();
 for (bl = bblst; bl; bl = bl->next)
  elf_for_block(bl->bbp);
}

canonical_original_code:
void dataflow()
{
 struct _BBListS *bl;
 cal_use_def();
 do_dataflow();
 _printAllBblock();
 rm_useless_assign();
 _printAllBblock();
 for (bl = bblst; bl; bl = bl->next)
  elf_for_block(bl->bbp);
}

variable_types: struct _BBListS { struct _BBS { int id; struct _QuadS { enum Quad_t { ADD_op=0, SUB_op=1, MUL_op=2, DIV_op=3, INC_op=4, DEC_op=5, NEG_op=6, LOAD_op=7, ASS_op=8, AARR_op=9, EQU_op=10, NEQ_op=11, GTT_op=12, GEQ_op=13, LST_op=14, LEQ_op=15, JMP_op=16, PUSH_op=17, PUSHA_op=18, POP_op=19, CALL_op=20, SRET_op=21, ENTER_op=22, FIN_op=23, READ_op=24, READC_op=25, WRS_op=26, WRI_op=27, WRC_op=28, LABEL_op=29 } op; struct _SymTabES { char *name; char *label; int val; int lineno; int level; int posi; enum Obj_t { Nop_Obj_t=0, Const_Obj_t=1, Var_Obj_t=2, Proc_Obj_t=3, Fun_Obj_t=4, Array_Obj_t=5, Para_Val_Obj_t=6, Para_Ref_Obj_t=7, Tmp_Obj_t=8, Label_Obj_t=9, Num_Obj_t=10, String_Obj_t=11 } obj; enum Type_t { Int_Type_t=0, Char_Type_t=1, Nop_Type_t=2 } type; struct _SymTabS { struct _SymBucketS { struct _SymTabES *ep; struct _SymBucketS *next; } **sbp; int posi_var; int posi_para; int posi_tmp; int level; struct _SymBucketS *headinfo; struct _SymBucketS *tailinfo; struct _SymTabS *prev; struct _SymTabS *next; } *stp; } *r; struct _SymTabES *s; struct _SymTabES *d; struct _QuadS *prev; struct _QuadS *next; int rm_flag; } *qhead; struct _QuadS *qtail; struct _QuadS *scope; struct _QuadS *first; struct _QuadS *last; struct _BBListS *pres; struct _BBListS *posts; int use[8]; int def[8]; int in_old[8]; int out_old[8]; int in[8]; int out[8]; } *bbp; struct _BBListS *next; } *


decompiled_code:
__int64 global_reg_alocate()
{
return do_use_count();
}

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

original_code:
void global_reg_alocate(void)
{
 do_use_count();
}

canonical_original_code:
void global_reg_alocate()
{
 do_use_count();
}


emit

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

result = qtail;
if ( qtail )
{
*(_QWORD *)(a1 + 32) = qtail;
*(_QWORD *)(a1 + 40) = 0LL;
*(_QWORD *)(result + 40) = a1;
qtail = a1;
}
else
{
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 40) = 0LL;
qtail = a1;
qhead = a1;
}
return result;
}

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

result = qtail;
if ( qtail )
{
*(_QWORD *)(a1 + 32) = qtail;
*(_QWORD *)(a1 + 40) = 0LL;
*(_QWORD *)(result + 40) = a1;
qtail = a1;
}
else
{
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 40) = 0LL;
qtail = a1;
qhead = a1;
}
return result;
}

original_code:
void emit(QuadSP q)
{
 if (qtail == ((void *)0)) {
  q->prev = qtail;
  q->next = ((void *)0);
  qhead = qtail = q;
 } else {
  q->prev = qtail;
  q->next = ((void *)0);
  qtail->next = q;
  qtail = q;
 }
 if (ShowQuad) {
  if (runlevel > 0) {
  }
 }
}

canonical_original_code:
void emit(struct _QuadS *q)
{
 if (qtail == ((void *)0)) {
  q->prev = qtail;
  q->next = ((void *)0);
  qhead = qtail = q;
 } else {
  q->prev = qtail;
  q->next = ((void *)0);
  qtail->next = q;
  qtail = q;
 }
 if (ShowQuad) {
  if (runlevel > 0) {
  }
 }
}

variable_types: struct _QuadS { enum Quad_t { ADD_op=0, SUB_op=1, MUL_op=2, DIV_op=3, INC_op=4, DEC_op=5, NEG_op=6, LOAD_op=7, ASS_op=8, AARR_op=9, EQU_op=10, NEQ_op=11, GTT_op=12, GEQ_op=13, LST_op=14, LEQ_op=15, JMP_op=16, PUSH_op=17, PUSHA_op=18, POP_op=19, CALL_op=20, SRET_op=21, ENTER_op=22, FIN_op=23, READ_op=24, READC_op=25, WRS_op=26, WRI_op=27, WRC_op=28, LABEL_op=29 } op; struct _SymTabES { char *name; char *label; int val; int lineno; int level; int posi; enum Obj_t { Nop_Obj_t=0, Const_Obj_t=1, Var_Obj_t=2, Proc_Obj_t=3, Fun_Obj_t=4, Array_Obj_t=5, Para_Val_Obj_t=6, Para_Ref_Obj_t=7, Tmp_Obj_t=8, Label_Obj_t=9, Num_Obj_t=10, String_Obj_t=11 } obj; enum Type_t { Int_Type_t=0, Char_Type_t=1, Nop_Type_t=2 } type; struct _SymTabS { struct _SymBucketS { struct _SymTabES *ep; struct _SymBucketS *next; } **sbp; int posi_var; int posi_para; int posi_tmp; int level; struct _SymBucketS *headinfo; struct _SymBucketS *tailinfo; struct _SymTabS *prev; struct _SymTabS *next; } *stp; } *r; struct _SymTabES *s; struct _SymTabES *d; struct _QuadS *prev; struct _QuadS *next; int rm_flag; } *


printAllQuads

decompiled_code:
void __fastcall printAllQuads(__int64 a1)
{
__int64 i; // rbx

for ( i = a1; i; i = *(_QWORD *)(i + 40) )
printQuad(i);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
__int64 i; // rbx

for ( i = a1; i; i = *(_QWORD *)(i + 40) )
func1(i);
}

original_code:
void printAllQuads(QuadSP q)
{
 for (; q != ((void *)0); q = q->next) {
  printQuad(q);
 }
}

canonical_original_code:
void printAllQuads(struct _QuadS *q)
{
 for (; q != ((void *)0); q = q->next) {
  printQuad(q);
 }
}


printAllQuad

decompiled_code:
void printAllQuad()
{
printAllQuads(qhead);
}

canonical_decompiled_code:
void func3()
{
func2(qhead);
}


decompiled_code:
_BOOL8 __fastcall et_carls_function(__int64 a1, __int64 a2, __int64 a3)
{
int v5[8]; // [rsp+0h] [rbp-48h] BYREF
char v6[40]; // [rsp+20h] [rbp-28h] BYREF

et_station_getselectwords(a1, a2, v6);
et_event_getcontrol(a3, v5);
return v5[0] == 17;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
int v5[8]; // [rsp+0h] [rbp-48h] BYREF
char v6[40]; // [rsp+20h] [rbp-28h] BYREF

et_station_getselectwords(a1, a2, v6);
et_event_getcontrol(a3, v5);
return v5[0] == 17;
}

original_code:
int
et_carls_function(et_sys_id id, et_stat_id stat_id, et_event *pe)
{
  int select[6];
  int control[6];
  et_station_getselectwords(id, stat_id, select);
  et_event_getcontrol(pe, control);
  if(control[0] == 17)
  {
    return(1);
  }
  return(0);
}

canonical_original_code:
int et_carls_function(void *id, int stat_id, struct et_event_t *pe)
{
  int select[6];
  int control[6];
  et_station_getselectwords(id, stat_id, select);
  et_event_getcontrol(pe, control);
  if(control[0] == 17)
  {
    return(1);
  }
  return(0);
}

variable_types:
id
void *

variable_types: struct et_event_t { struct et_event_t *next; void *tempdata; void *pdata; char *data; unsigned long length; unsigned long memsize; unsigned long pointer; int modify; int priority; int owner; int temp; int age; int datastatus; int byteorder; int group; int place; int control[6]; char filename[-1]; } *

variable_types:
select
int [6]

variable_types:
control
int [6]


decompiled_code:
_BOOL8 __fastcall et_mon_function(__int64 a1, unsigned int a2, __int64 a3)
{
int v4; // [rsp+8h] [rbp-40h] BYREF
int v5; // [rsp+Ch] [rbp-3Ch] BYREF
int v6[14]; // [rsp+10h] [rbp-38h] BYREF

et_event_getcontrol(a3, v6);
if ( v6[0] > 15 || !v6[0] )
return 1LL;
et_station_getcue(a1, a2, &v5);
et_station_getinputcount(a1, a2, &v4);
return v4 < v5;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, unsigned int a2, __int64 a3)
{
int v4; // [rsp+8h] [rbp-40h] BYREF
int v5; // [rsp+Ch] [rbp-3Ch] BYREF
int v6[14]; // [rsp+10h] [rbp-38h] BYREF

et_event_getcontrol(a3, v6);
if ( v6[0] > 15 || !v6[0] )
return 1LL;
et_station_getcue(a1, a2, &v5);
et_station_getinputcount(a1, a2, &v4);
return v4 < v5;
}

original_code:
int
et_mon_function(et_sys_id id, et_stat_id stat_id, et_event *pe)
{
  int control[6];
  int cue, cnt;
  et_event_getcontrol(pe, control);
  if(control[0]==0) return(1);
  if(control[0]>15) return(1);
  et_station_getcue(id,stat_id,&cue);
  et_station_getinputcount(id,stat_id,&cnt);
  if(cnt<cue)
  {
    return(1);
  }
  else
  {
    return(0);
  }
}

canonical_original_code:
int et_mon_function(void *id, int stat_id, struct et_event_t *pe)
{
  int control[6];
  int cue; int cnt;
  et_event_getcontrol(pe, control);
  if(control[0]==0) return(1);
  if(control[0]>15) return(1);
  et_station_getcue(id,stat_id,&cue);
  et_station_getinputcount(id,stat_id,&cnt);
  if(cnt<cue)
  {
    return(1);
  }
  else
  {
    return(0);
  }
}

variable_types: cue int

variable_types: cnt int

user_defined_types: struct et_event_t { struct et_event_t *next; void *tempdata; void *pdata; char *data; unsigned long length; unsigned long memsize; unsigned long pointer; int modify; int priority; int owner; int temp; int age; int datastatus; int byteorder; int group; int place; int control[6]; char filename[-1]; }


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

et_event_getcontrol(a3, v4);
return (unsigned int)(v4[0] - 1) <= 0xD;
}

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

et_event_getcontrol(a3, v4);
return (unsigned int)(v4[0] - 1) <= 0xD;
}

original_code:
int
et_ced_function(et_sys_id id, et_stat_id stat_id, et_event *pe)
{
  int control[6];
  et_event_getcontrol(pe, control);
  if(control[0]>0&&control[0]<15)
  {
    return(1);
  }
  else
  {
    return(0);
  }
}

canonical_original_code:
int et_ced_function(void *id, int stat_id, struct et_event_t *pe)
{
  int control[6];
  et_event_getcontrol(pe, control);
  if(control[0]>0&&control[0]<15)
  {
    return(1);
  }
  else
  {
    return(0);
  }
}


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

et_event_getcontrol(a3, v4);
return v4[0] == 0;
}

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

et_event_getcontrol(a3, v4);
return v4[0] == 0;
}

original_code:
int
et_scaler_function(et_sys_id id, et_stat_id stat_id, et_event *pe)
{
  int control[6];
  et_event_getcontrol(pe, control);
  if(control[0]==0)
  {
    return(1);
  }
  else
  {
    return(0);
  }
}

canonical_original_code:
int et_scaler_function(void *id, int stat_id, struct et_event_t *pe)
{
  int control[6];
  et_event_getcontrol(pe, control);
  if(control[0]==0)
  {
    return(1);
  }
  else
  {
    return(0);
  }
}


repo: Jegp/OpenWrt-transfer

decompiled_code:
__int64 __fastcall write_to_socket(int fd, void *buf, int a3)
{
int v4; // ebx
int v5; // eax

v4 = a3;
if ( a3 <= 0 )
return 0LL;
while ( 1 )
{
v5 = write(fd, buf, v4);
if ( v5 < 0 )
break;
v4 -= v5;
buf = (char *)buf + v5;
if ( v4 <= 0 )
return 0LL;
}
fwrite("Failed to write to server\n", 1uLL, 0x1AuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, void *buf, int a3)
{
int v4; // ebx
int v5; // eax

v4 = a3;
if ( a3 <= 0 )
return 0LL;
while ( 1 )
{
v5 = write(fd, buf, v4);
if ( v5 < 0 )
break;
v4 -= v5;
buf = (char *)buf + v5;
if ( v4 <= 0 )
return 0LL;
}
fwrite("Failed to write to server\n", 1uLL, 0x1AuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int write_to_socket(int socketfd, void * buffer, int bytes_read) {
    int bytes_written;
    while (bytes_read > 0) {
        bytes_written = write(socketfd, buffer, bytes_read);
        if (bytes_written < 0) {
            fprintf(stderr, "Failed to write to server\n");
            return -1;
        }
        bytes_read -= bytes_written;
        buffer += bytes_written;
    }
    return 0;
}

canonical_original_code:
int write_to_socket(int socketfd, void *buffer, int bytes_read) {
    int bytes_written;
    while (bytes_read > 0) {
        bytes_written = write(socketfd, buffer, bytes_read);
        if (bytes_written < 0) {
            fprintf(stderr, "Failed to write to server\n");
            return -1;
        }
        bytes_read -= bytes_written;
        buffer += bytes_written;
    }
    return 0;
}

variable_types: socketfd int

variable_types:
buffer
void *


sendFile

decompiled_code:
__int64 __fastcall sendFile(const char *a1, int a2)
{
int v2; // ebx
int v3; // eax
unsigned int v4; // er12
_BYTE v6[1032]; // [rsp+0h] [rbp-408h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
{
fprintf(stderr, "Could not open file '%s'\n", a1);
v4 = -1;
}
else
{
while ( 1 )
{
v3 = read(v2, v6, 0x3E8uLL);
v4 = v3;
if ( !v3 )
break;
if ( v3 < 0 )
{
fwrite("Failed to read from file\n", 1uLL, 0x19uLL, stderr);
return (unsigned int)-1;
}
if ( (unsigned int)write_to_socket(a2, v6, v3) )
return (unsigned int)-1;
}
close(v2);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, int a2)
{
int v2; // ebx
int v3; // eax
unsigned int v4; // er12
_BYTE v6[1032]; // [rsp+0h] [rbp-408h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
{
fprintf(stderr, "Could not open file '%s'\n", a1);
v4 = -1;
}
else
{
while ( 1 )
{
v3 = read(v2, v6, 0x3E8uLL);
v4 = v3;
if ( !v3 )
break;
if ( v3 < 0 )
{
fwrite("Failed to read from file\n", 1uLL, 0x19uLL, stderr);
return (unsigned int)-1;
}
if ( (unsigned int)func7(a2, v6, v3) )
return (unsigned int)-1;
}
close(v2);
}
return v4;
}

original_code:
int sendFile(char * file, int socketfd) {
    int filefd, bytes_read;
    char buffer[1000];
    if ((filefd = open(file, 00)) < 0) {
        fprintf(stderr, "Could not open file '%s'\n", file);
        return -1;
    }
    while (1) {
        bytes_read = read(filefd, buffer, sizeof(buffer));
        if (bytes_read == 0) break;
        if (bytes_read < 0) {
            fprintf(stderr, "Failed to read from file\n");
            return -1;
        }
        if (write_to_socket(socketfd, (void *) buffer, bytes_read) != 0) {
            return -1;
        }
    }
    close(filefd);
    return 0;
}

canonical_original_code:
int sendFile(char *file, int socketfd) {
    int filefd; int bytes_read;
    char buffer[1000];
    if ((filefd = open(file, 00)) < 0) {
        fprintf(stderr, "Could not open file '%s'\n", file);
        return -1;
    }
    while (1) {
        bytes_read = read(filefd, buffer, sizeof(buffer));
        if (bytes_read == 0) break;
        if (bytes_read < 0) {
            fprintf(stderr, "Failed to read from file\n");
            return -1;
        }
        if (write_to_socket(socketfd, (void *) buffer, bytes_read) != 0) {
            return -1;
        }
    }
    close(filefd);
    return 0;
}

variable_types:
file
char *

variable_types: filefd int

variable_types:
buffer
char [1000]


decompiled_code:
__int64 __fastcall send_std_in(int fd)
{
int v1; // eax
size_t v3; // [rsp+0h] [rbp-18h] BYREF
char *lineptr; // [rsp+8h] [rbp-10h] BYREF

lineptr = 0LL;
while ( 1 )
{
v1 = getline(&lineptr, &v3, stdin);
if ( v1 == -1 )
break;
if ( (unsigned int)write_to_socket(fd, lineptr, v1) )
return 0xFFFFFFFFLL;
}
puts("Input ended");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd)
{
int v1; // eax
size_t v3; // [rsp+0h] [rbp-18h] BYREF
char *lineptr; // [rsp+8h] [rbp-10h] BYREF

lineptr = 0LL;
while ( 1 )
{
v1 = getline(&lineptr, &v3, stdin);
if ( v1 == -1 )
break;
if ( (unsigned int)func7(fd, lineptr, v1) )
return 0xFFFFFFFFLL;
}
puts("Input ended");
return 0LL;
}

original_code:
int send_std_in(int socketfd) {
    int bytes_read;
    char * line = ((void *)0);
    size_t size;
    while (1) {
        if ((bytes_read = getline(&line, &size, stdin)) == -1) {
            printf("Input ended\n");
            return 0;
        }
        if (write_to_socket(socketfd, (void *) line, bytes_read) != 0) {
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int send_std_in(int socketfd) {
    int bytes_read;
    char *line = ((void *)0);
    unsigned long size;
    while (1) {
        if ((bytes_read = getline(&line, &size, stdin)) == -1) {
            printf("Input ended\n");
            return 0;
        }
        if (write_to_socket(socketfd, (void *) line, bytes_read) != 0) {
            return -1;
        }
    }
    return 0;
}

variable_types:
line
char *

variable_types:
size
unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
const char *v4; // r12
const char *v5; // rsi
int v6; // eax
int v7; // er13
struct addrinfo *v8; // rbx
int v9; // eax
int v10; // ebp
const char *v12; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF

if ( (unsigned int)(argc - 2) > 1 )
{
puts("Usage: client server-address [filename]");
exit(1);
}
v3 = argv[1];
v4 = argv[2];
v5 = "Could not open file '%s'\n" + 25;
if ( v4 )
v5 = v4;
printf("Sending %s to server at '%s'\n", v5, v3);
*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v6 = getaddrinfo(v3, "3490", &req, &pai);
v7 = v6;
if ( v6 )
{
v12 = gai_strerror(v6);
fprintf(stderr, "Server error at getaddrinfo: %s\n", v12);
exit(1);
}
v8 = pai;
if ( !pai )
{
LABEL_16:
fwrite("Client: Failed to bind\n", 1uLL, 0x17uLL, stderr);
return 2;
}
while ( 1 )
{
v9 = socket(v8->ai_family, v8->ai_socktype, v8->ai_protocol);
v10 = v9;
if ( v9 != -1 )
break;
perror("Client: Failed to create socket");
LABEL_15:
v8 = v8->ai_next;
if ( !v8 )
goto LABEL_16;
}
if ( connect(v9, v8->ai_addr, v8->ai_addrlen) == -1 )
{
close(v10);
goto LABEL_15;
}
freeaddrinfo(pai);
if ( v4 )
{
if ( !(unsigned int)sendFile(v4, v10) )
goto LABEL_10;
fwrite("Client: Error while sending file\n", 1uLL, 0x21uLL, stderr);
v7 = -1;
}
else
{
if ( (unsigned int)send_std_in(v10) )
fwrite("Client: Error while sending data\n", 1uLL, 0x21uLL, stderr);
LABEL_10:
close(v10);
}
return v7;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
const char *v4; // r12
const char *v5; // rsi
int v6; // eax
int v7; // er13
struct addrinfo *v8; // rbx
int v9; // eax
int v10; // ebp
const char *v12; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF

if ( (unsigned int)(argc - 2) > 1 )
{
puts("Usage: client server-address [filename]");
exit(1);
}
v3 = argv[1];
v4 = argv[2];
v5 = "Could not open file '%s'\n" + 25;
if ( v4 )
v5 = v4;
printf("Sending %s to server at '%s'\n", v5, v3);
*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v6 = getaddrinfo(v3, "3490", &req, &pai);
v7 = v6;
if ( v6 )
{
v12 = gai_strerror(v6);
fprintf(stderr, "Server error at getaddrinfo: %s\n", v12);
exit(1);
}
v8 = pai;
if ( !pai )
{
LABEL_16:
fwrite("Client: Failed to bind\n", 1uLL, 0x17uLL, stderr);
return 2;
}
while ( 1 )
{
v9 = socket(v8->ai_family, v8->ai_socktype, v8->ai_protocol);
v10 = v9;
if ( v9 != -1 )
break;
perror("Client: Failed to create socket");
LABEL_15:
v8 = v8->ai_next;
if ( !v8 )
goto LABEL_16;
}
if ( connect(v9, v8->ai_addr, v8->ai_addrlen) == -1 )
{
close(v10);
goto LABEL_15;
}
freeaddrinfo(pai);
if ( v4 )
{
if ( !(unsigned int)func8(v4, v10) )
goto LABEL_10;
fwrite("Client: Error while sending file\n", 1uLL, 0x21uLL, stderr);
v7 = -1;
}
else
{
if ( (unsigned int)func9(v10) )
fwrite("Client: Error while sending data\n", 1uLL, 0x21uLL, stderr);
LABEL_10:
close(v10);
}
return v7;
}

original_code:
int main(int argc, char * args[]) {
    int socketfd, status;
    struct addrinfo hints, *servinfo, *current;
    struct sockaddr_storage remote_addr;
    char ipstr[46];
    socklen_t remote_addr_size;
    if (argc != 2 && argc != 3) {
        printf("Usage: client server-address [filename]\n");
        exit(1);
    }
    char * server = args[1];
    char * filename = args[2];
    printf("Sending %s to server at '%s'\n",
        (filename == ((void *)0)) ? "" : filename, server);
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0001;
    if ((status = getaddrinfo(server, "3490", &hints, &servinfo)) != 0) {
        fprintf(stderr, "Server error at getaddrinfo: %s\n", gai_strerror(status));
        exit(1);
    }
    for (current = servinfo; current != ((void *)0); current = current->ai_next) {
        void * address;
        char * ip_version;
        if (current->ai_family == 2) {
            address = &(((struct sockaddr_in *) current->ai_addr)->sin_addr);
        } else {
            address = &(((struct sockaddr_in6 *) current->ai_addr)->sin6_addr);
        }
        if ((socketfd = socket(current->ai_family,
                             current->ai_socktype,
                             current->ai_protocol)) == -1) {
            perror("Client: Failed to create socket");
            continue;
        }
        if (connect(socketfd, current->ai_addr, current->ai_addrlen) == -1) {
            close(socketfd);
            continue;
        }
        break;
    }
    if (current == ((void *)0)) {
        fprintf(stderr, "Client: Failed to bind\n");
        return 2;
    }
    freeaddrinfo(servinfo);
    if (filename == ((void *)0)) {
      if (send_std_in(socketfd) != 0) {
        fprintf(stderr, "Client: Error while sending data\n");
      }
    } else if (sendFile(filename, socketfd) != 0) {
        fprintf(stderr, "Client: Error while sending file\n");
        return -1;
    }
    close(socketfd);
    return 0;
}

canonical_original_code:
int main(int argc, char *args[]) {
    int socketfd; int status;
    struct addrinfo hints; struct addrinfo *servinfo; struct addrinfo *current;
    struct sockaddr_storage remote_addr;
    char ipstr[46];
    unsigned int remote_addr_size;
    if (argc != 2 && argc != 3) {
        printf("Usage: client server-address [filename]\n");
        exit(1);
    }
    char *server = args[1];
    char *filename = args[2];
    printf("Sending %s to server at '%s'\n",
        (filename == ((void *)0)) ? "" : filename, server);
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0001;
    if ((status = getaddrinfo(server, "3490", &hints, &servinfo)) != 0) {
        fprintf(stderr, "Server error at getaddrinfo: %s\n", gai_strerror(status));
        exit(1);
    }
    for (current = servinfo; current != ((void *)0); current = current->ai_next) {
        void *address;
        char *ip_version;
        if (current->ai_family == 2) {
            address = &(((struct sockaddr_in *) current->ai_addr)->sin_addr);
        } else {
            address = &(((struct sockaddr_in6 *) current->ai_addr)->sin6_addr);
        }
        if ((socketfd = socket(current->ai_family,
                             current->ai_socktype,
                             current->ai_protocol)) == -1) {
            perror("Client: Failed to create socket");
            continue;
        }
        if (connect(socketfd, current->ai_addr, current->ai_addrlen) == -1) {
            close(socketfd);
            continue;
        }
        break;
    }
    if (current == ((void *)0)) {
        fprintf(stderr, "Client: Failed to bind\n");
        return 2;
    }
    freeaddrinfo(servinfo);
    if (filename == ((void *)0)) {
      if (send_std_in(socketfd) != 0) {
        fprintf(stderr, "Client: Error while sending data\n");
      }
    } else if (sendFile(filename, socketfd) != 0) {
        fprintf(stderr, "Client: Error while sending file\n");
        return -1;
    }
    close(socketfd);
    return 0;
}

variable_types: argc int

variable_types:
args
char *[]

variable_types: status int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
ipstr
char [46]

variable_types:
server
char *

variable_types:
filename
char *

variable_types:
address
void *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

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

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
__int64 __fastcall write_file(const char *a1, int a2)
{
int v2; // er12
int v3; // eax
int v4; // ebx
_BYTE *v5; // rbp
int v6; // eax
_BYTE v8[152]; // [rsp+0h] [rbp-98h] BYREF

v2 = open(a1, 65, 420LL);
if ( v2 < 0 )
{
fprintf(stderr, "Failed to create file '%s'\n", a1);
v4 = -1;
}
else
{
LABEL_2:
v3 = recv(a2, v8, 0x64uLL, 0);
v4 = v3;
if ( v3 )
{
if ( v3 < 0 )
{
perror("Failure when receiving data");
v4 = -1;
}
else
{
v5 = v8;
while ( 1 )
{
v6 = write(v2, v5, (unsigned int)v4);
if ( v6 < 0 )
break;
v4 -= v6;
v5 += v6;
if ( v4 <= 0 )
goto LABEL_2;
}
fprintf(stderr, "Failed to write to file '%s'", a1);
v4 = -1;
}
}
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, int a2)
{
int v2; // er12
int v3; // eax
int v4; // ebx
_BYTE *v5; // rbp
int v6; // eax
_BYTE v8[152]; // [rsp+0h] [rbp-98h] BYREF

v2 = open(a1, 65, 420LL);
if ( v2 < 0 )
{
fprintf(stderr, "Failed to create file '%s'\n", a1);
v4 = -1;
}
else
{
LABEL_2:
v3 = recv(a2, v8, 0x64uLL, 0);
v4 = v3;
if ( v3 )
{
if ( v3 < 0 )
{
perror("Failure when receiving data");
v4 = -1;
}
else
{
v5 = v8;
while ( 1 )
{
v6 = write(v2, v5, (unsigned int)v4);
if ( v6 < 0 )
break;
v4 -= v6;
v5 += v6;
if ( v4 <= 0 )
goto LABEL_2;
}
fprintf(stderr, "Failed to write to file '%s'", a1);
v4 = -1;
}
}
}
return (unsigned int)v4;
}

original_code:
int write_file(char * filename, int connection_fd) {
    char buffer[100];
    int filefd, bytes_read, bytes_written;
    if ((filefd = open(filename, 0100 | 01, 0644)) < 0) {
        fprintf(stderr, "Failed to create file '%s'\n", filename);
        return -1;
    }
    while (1) {
        bytes_read = recv(connection_fd, buffer, sizeof(buffer), 0);
        if (bytes_read == 0) break;
        if (bytes_read < 0) {
            perror("Failure when receiving data");
            return -1;
        }
        void * p = buffer;
        while (bytes_read > 0) {
            bytes_written = write(filefd, p, bytes_read);
            if (bytes_written < 0) {
                fprintf(stderr, "Failed to write to file '%s'", filename);
                return -1;
            }
            bytes_read -= bytes_written;
            p += bytes_written;
        }
    }
    return 0;
}

canonical_original_code:
int write_file(char *filename, int connection_fd) {
    char buffer[100];
    int filefd; int bytes_read; int bytes_written;
    if ((filefd = open(filename, 0100 | 01, 0644)) < 0) {
        fprintf(stderr, "Failed to create file '%s'\n", filename);
        return -1;
    }
    while (1) {
        bytes_read = recv(connection_fd, buffer, sizeof(buffer), 0);
        if (bytes_read == 0) break;
        if (bytes_read < 0) {
            perror("Failure when receiving data");
            return -1;
        }
        void *p = buffer;
        while (bytes_read > 0) {
            bytes_written = write(filefd, p, bytes_read);
            if (bytes_written < 0) {
                fprintf(stderr, "Failed to write to file '%s'", filename);
                return -1;
            }
            bytes_read -= bytes_written;
            p += bytes_written;
        }
    }
    return 0;
}

variable_types:
buffer
char [100]

variable_types:
p
void *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
int v4; // eax
int v5; // er14
struct addrinfo *v6; // rbx
int v7; // edi
char *v8; // r13
int v9; // eax
int v10; // ebp
int v11; // ebx
double v12; // r15
const char *v13; // rax
struct stat v15; // [rsp+0h] [rbp-248h] BYREF
socklen_t addr_len; // [rsp+9Ch] [rbp-1ACh] BYREF
char s[112]; // [rsp+A0h] [rbp-1A8h] BYREF
char buf[48]; // [rsp+110h] [rbp-138h] BYREF
struct timeval tv; // [rsp+140h] [rbp-108h] BYREF
struct sockaddr addr; // [rsp+150h] [rbp-F8h] BYREF
struct addrinfo *pai; // [rsp+1D8h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+1E0h] [rbp-68h] BYREF

if ( argc == 2 )
{
v3 = (char *)argv[1];
if ( (unsigned int)stat(v3, &v15) )
{
fprintf(stderr, "Failure: Prefix '%s' could not be found\n", v3);
}
else
{
if ( (v15.st_mode & 0x4000) != 0 )
goto LABEL_4;
fprintf(stderr, "Failure: Prefix '%s' must be a directory\n", v3);
}
return -1;
}
v3 = ".";
if ( argc > 2 )
puts("Usage: server [path-prefix]");
LABEL_4:
*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v4 = getaddrinfo(0LL, "3490", &req, &pai);
v5 = v4;
if ( v4 )
{
v13 = gai_strerror(v4);
fprintf(stderr, "Server error at getaddrinfo: %s\n", v13);
exit(1);
}
v6 = pai;
if ( pai )
{
while ( 1 )
{
v7 = v6->ai_family;
v8 = v7 == 2 ? &v6->ai_addr->sa_data[2] : &v6->ai_addr->sa_data[6];
v9 = socket(v7, v6->ai_socktype, v6->ai_protocol);
v10 = v9;
if ( v9 != -1 )
break;
perror("Server: Failed to create socket");
v6 = v6->ai_next;
if ( !v6 )
goto LABEL_22;
}
if ( bind(v9, v6->ai_addr, v6->ai_addrlen) == -1 )
{
close(v10);
perror("Server: Failed to bind to socket");
exit(1);
}
inet_ntop(v6->ai_family, v8, buf, 0x2Eu);
printf("Starting server at %s...\n", buf);
freeaddrinfo(pai);
if ( listen(v10, 10) == -1 )
{
perror("Server: Failed to listen for new connections");
exit(1);
}
while ( 1 )
{
addr_len = 128;
v11 = accept(v10, &addr, &addr_len);
if ( v11 == -1 )
{
perror("Server: Error when accepting connection");
exit(1);
}
inet_ntop(addr.sa_family, &addr.sa_data[2], (char *)&v15, 0x2Eu);
gettimeofday(&tv, 0LL);
v12 = (double)(int)(1000 * LODWORD(tv.tv_sec) + tv.tv_usec / 1000);
printf("Got connection from %s at %.0f\n", (const char *)&v15, v12);
snprintf(s, 0x64uLL, "%s/%s_%.0f", v3, (const char *)&v15, v12);
if ( (unsigned int)write_file(s, v11) )
break;
printf("Successfully wrote file '%s'\n", s);
close(v11);
}
fwrite("Error, shutting down\n", 1uLL, 0x15uLL, stderr);
close(v10);
}
else
{
LABEL_22:
fwrite("Server: Failed to bind\n", 1uLL, 0x17uLL, stderr);
v5 = -1;
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
int v4; // eax
int v5; // er14
struct addrinfo *v6; // rbx
int v7; // edi
char *v8; // r13
int v9; // eax
int v10; // ebp
int v11; // ebx
double v12; // r15
const char *v13; // rax
struct stat v15; // [rsp+0h] [rbp-248h] BYREF
socklen_t addr_len; // [rsp+9Ch] [rbp-1ACh] BYREF
char s[112]; // [rsp+A0h] [rbp-1A8h] BYREF
char buf[48]; // [rsp+110h] [rbp-138h] BYREF
struct timeval tv; // [rsp+140h] [rbp-108h] BYREF
struct sockaddr addr; // [rsp+150h] [rbp-F8h] BYREF
struct addrinfo *pai; // [rsp+1D8h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+1E0h] [rbp-68h] BYREF

if ( argc == 2 )
{
v3 = (char *)argv[1];
if ( (unsigned int)func10(v3, &v15) )
{
fprintf(stderr, "Failure: Prefix '%s' could not be found\n", v3);
}
else
{
if ( (v15.st_mode & 0x4000) != 0 )
goto LABEL_4;
fprintf(stderr, "Failure: Prefix '%s' must be a directory\n", v3);
}
return -1;
}
v3 = ".";
if ( argc > 2 )
puts("Usage: server [path-prefix]");
LABEL_4:
*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v4 = getaddrinfo(0LL, "3490", &req, &pai);
v5 = v4;
if ( v4 )
{
v13 = gai_strerror(v4);
fprintf(stderr, "Server error at getaddrinfo: %s\n", v13);
exit(1);
}
v6 = pai;
if ( pai )
{
while ( 1 )
{
v7 = v6->ai_family;
v8 = v7 == 2 ? &v6->ai_addr->sa_data[2] : &v6->ai_addr->sa_data[6];
v9 = socket(v7, v6->ai_socktype, v6->ai_protocol);
v10 = v9;
if ( v9 != -1 )
break;
perror("Server: Failed to create socket");
v6 = v6->ai_next;
if ( !v6 )
goto LABEL_22;
}
if ( bind(v9, v6->ai_addr, v6->ai_addrlen) == -1 )
{
close(v10);
perror("Server: Failed to bind to socket");
exit(1);
}
inet_ntop(v6->ai_family, v8, buf, 0x2Eu);
printf("Starting server at %s...\n", buf);
freeaddrinfo(pai);
if ( listen(v10, 10) == -1 )
{
perror("Server: Failed to listen for new connections");
exit(1);
}
while ( 1 )
{
addr_len = 128;
v11 = accept(v10, &addr, &addr_len);
if ( v11 == -1 )
{
perror("Server: Error when accepting connection");
exit(1);
}
inet_ntop(addr.sa_family, &addr.sa_data[2], (char *)&v15, 0x2Eu);
gettimeofday(&tv, 0LL);
v12 = (double)(int)(1000 * LODWORD(tv.tv_sec) + tv.tv_usec / 1000);
printf("Got connection from %s at %.0f\n", (const char *)&v15, v12);
snprintf(s, 0x64uLL, "%s/%s_%.0f", v3, (const char *)&v15, v12);
if ( (unsigned int)func7(s, v11) )
break;
printf("Successfully wrote file '%s'\n", s);
close(v11);
}
fwrite("Error, shutting down\n", 1uLL, 0x15uLL, stderr);
close(v10);
}
else
{
LABEL_22:
fwrite("Server: Failed to bind\n", 1uLL, 0x17uLL, stderr);
v5 = -1;
}
return v5;
}

original_code:
int main(int argc, char * args[]) {
    int socketfd, status, new_fd;
    struct addrinfo hints, *servinfo, *current;
    struct sockaddr_storage remote_addr;
    struct timeval tv;
    char ipstr[46], filename[100];
    socklen_t remote_addr_size;
    double timestamp;
    pid_t childId;
    char * address_prefix;
    if (argc == 2) {
        struct stat file_status;
        address_prefix = args[1];
        if (stat(address_prefix, &file_status) == 0) {
            if (!(file_status.st_mode & 0040000)) {
                fprintf(stderr, "Failure: Prefix '%s' must be a directory\n", address_prefix);
                return -1;
            }
        } else {
            fprintf(stderr, "Failure: Prefix '%s' could not be found\n", address_prefix);
            return -1;
        }
    } else if (argc > 2) {
        printf("Usage: server [path-prefix]\n");
    } else {
        address_prefix = ".";
    }
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0001;
    if ((status = getaddrinfo(((void *)0), "3490", &hints, &servinfo)) != 0) {
        fprintf(stderr, "Server error at getaddrinfo: %s\n", gai_strerror(status));
        exit(1);
    }
    for (current = servinfo; current != ((void *)0); current = current->ai_next) {
        void * address;
        char * ip_version;
        if (current->ai_family == 2) {
            address = &(((struct sockaddr_in *) current->ai_addr)->sin_addr);
        } else {
            address = &(((struct sockaddr_in6 *) current->ai_addr)->sin6_addr);
        }
        if ((socketfd = socket(current->ai_family,
                             current->ai_socktype,
                             current->ai_protocol)) == -1) {
            perror("Server: Failed to create socket");
            continue;
        }
        if (bind(socketfd, current->ai_addr, current->ai_addrlen) == -1) {
            close(socketfd);
            perror("Server: Failed to bind to socket");
            exit(1);
        }
        inet_ntop(current->ai_family, address, ipstr, sizeof ipstr);
        printf("Starting server at %s...\n", ipstr);
        break;
    }
    if (current == ((void *)0)) {
        fprintf(stderr, "Server: Failed to bind\n");
        return -1;
    }
    freeaddrinfo(servinfo);
    if (listen(socketfd, 10) == -1) {
        perror("Server: Failed to listen for new connections");
        exit(1);
    }
    while (1) {
        remote_addr_size = sizeof remote_addr;
        if ((new_fd = accept(socketfd, (struct sockaddr *)&remote_addr, &remote_addr_size)) == -1) {
            perror("Server: Error when accepting connection");
            exit(1);
        }
        char s[46];
        inet_ntop(remote_addr.ss_family,
            &((struct sockaddr_in *)&remote_addr)->sin_addr,
            s, sizeof s);
        gettimeofday(&tv, ((void *)0));
        timestamp = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
        printf("Got connection from %s at %.0f\n", s, timestamp);
        snprintf(filename, sizeof(filename), "%s/%s_%.0f", address_prefix, s, timestamp);
        if (write_file(filename, new_fd) != 0) {
            fprintf(stderr, "Error, shutting down\n");
            break;
        }
        printf("Successfully wrote file '%s'\n", filename);
        close (new_fd);
    }
    close(socketfd);
    return 0;
}

canonical_original_code:
int main(int argc, char *args[]) {
    int socketfd; int status; int new_fd;
    struct addrinfo hints; struct addrinfo *servinfo; struct addrinfo *current;
    struct sockaddr_storage remote_addr;
    struct timeval tv;
    char ipstr[46]; char filename[100];
    unsigned int remote_addr_size;
    double timestamp;
    int childId;
    char *address_prefix;
    if (argc == 2) {
        struct stat file_status;
        address_prefix = args[1];
        if (stat(address_prefix, &file_status) == 0) {
            if (!(file_status.st_mode & 0040000)) {
                fprintf(stderr, "Failure: Prefix '%s' must be a directory\n", address_prefix);
                return -1;
            }
        } else {
            fprintf(stderr, "Failure: Prefix '%s' could not be found\n", address_prefix);
            return -1;
        }
    } else if (argc > 2) {
        printf("Usage: server [path-prefix]\n");
    } else {
        address_prefix = ".";
    }
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0001;
    if ((status = getaddrinfo(((void *)0), "3490", &hints, &servinfo)) != 0) {
        fprintf(stderr, "Server error at getaddrinfo: %s\n", gai_strerror(status));
        exit(1);
    }
    for (current = servinfo; current != ((void *)0); current = current->ai_next) {
        void *address;
        char *ip_version;
        if (current->ai_family == 2) {
            address = &(((struct sockaddr_in *) current->ai_addr)->sin_addr);
        } else {
            address = &(((struct sockaddr_in6 *) current->ai_addr)->sin6_addr);
        }
        if ((socketfd = socket(current->ai_family,
                             current->ai_socktype,
                             current->ai_protocol)) == -1) {
            perror("Server: Failed to create socket");
            continue;
        }
        if (bind(socketfd, current->ai_addr, current->ai_addrlen) == -1) {
            close(socketfd);
            perror("Server: Failed to bind to socket");
            exit(1);
        }
        inet_ntop(current->ai_family, address, ipstr, sizeof ipstr);
        printf("Starting server at %s...\n", ipstr);
        break;
    }
    if (current == ((void *)0)) {
        fprintf(stderr, "Server: Failed to bind\n");
        return -1;
    }
    freeaddrinfo(servinfo);
    if (listen(socketfd, 10) == -1) {
        perror("Server: Failed to listen for new connections");
        exit(1);
    }
    while (1) {
        remote_addr_size = sizeof remote_addr;
        if ((new_fd = accept(socketfd, (struct sockaddr *)&remote_addr, &remote_addr_size)) == -1) {
            perror("Server: Error when accepting connection");
            exit(1);
        }
        char s[46];
        inet_ntop(remote_addr.ss_family,
            &((struct sockaddr_in *)&remote_addr)->sin_addr,
            s, sizeof s);
        gettimeofday(&tv, ((void *)0));
        timestamp = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
        printf("Got connection from %s at %.0f\n", s, timestamp);
        snprintf(filename, sizeof(filename), "%s/%s_%.0f", address_prefix, s, timestamp);
        if (write_file(filename, new_fd) != 0) {
            fprintf(stderr, "Error, shutting down\n");
            break;
        }
        printf("Successfully wrote file '%s'\n", filename);
        close (new_fd);
    }
    close(socketfd);
    return 0;
}

variable_types: socketfd int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

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

variable_types:
filename
char [100]

variable_types: timestamp double

variable_types: childId int

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

variable_types:
s
char [46]

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

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


repo: JekaMelnikov/Numerical-Methods

decompiled_code:
double __fastcall get_h1(int a1)
{
return 1.0 / (double)a1;
}

canonical_decompiled_code:
double __fastcall func0(int a1)
{
return 1.0 / (double)a1;
}

original_code:
double get_h1 (spec_mesh mesh)
{
  return 1.0 / mesh.M1;
}

canonical_original_code:
double get_h1(struct _spec_mesh mesh)
{
  return 1.0 / mesh.M1;
}

variable_types:
mesh
struct _spec_mesh { int M1; int M2; }

return_type: double


decompiled_code:
double __fastcall get_h2(__int64 a1)
{
return 1.0 / (double)SHIDWORD(a1);
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1)
{
return 1.0 / (double)SHIDWORD(a1);
}

original_code:
double get_h2 (spec_mesh mesh)
{
  return 1.0 / mesh.M2;
}

canonical_original_code:
double get_h2(struct _spec_mesh mesh)
{
  return 1.0 / mesh.M2;
}


size

decompiled_code:
__int64 __fastcall size(__int64 a1)
{
return (unsigned int)((HIDWORD(a1) + 1) * (a1 + 1) - SHIDWORD(a1) / 4 * ((int)a1 / 5 - 1));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return (unsigned int)((HIDWORD(a1) + 1) * (a1 + 1) - SHIDWORD(a1) / 4 * ((int)a1 / 5 - 1));
}

original_code:
int size (spec_mesh mesh)
{
  return (mesh.M1 + 1) * (mesh.M2 + 1) - (mesh.M1 / 5 - 1) * (mesh.M2 / 4);
}

canonical_original_code:
int size(struct _spec_mesh mesh)
{
  return (mesh.M1 + 1) * (mesh.M2 + 1) - (mesh.M1 / 5 - 1) * (mesh.M2 / 4);
}


decompiled_code:
__int64 __fastcall boundary_size(__int64 a1)
{
return (unsigned int)(SHIDWORD(a1) / 2 + 2 * (HIDWORD(a1) + a1));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return (unsigned int)(SHIDWORD(a1) / 2 + 2 * (HIDWORD(a1) + a1));
}

original_code:
int boundary_size (spec_mesh mesh)
{
  return 2 * (mesh.M1 + mesh.M2) + mesh.M2 / 2;
}

canonical_original_code:
int boundary_size(struct _spec_mesh mesh)
{
  return 2 * (mesh.M1 + mesh.M2) + mesh.M2 / 2;
}


decompiled_code:
int __fastcall print_properties(__int64 a1)
{
unsigned int v1; // eax

v1 = size(a1);
return printf(
"Special mesh %d x %d\nh1 = %.4lf\nh2 = %.4lf\nTotal number of cells %d\n",
(unsigned int)a1,
HIDWORD(a1),
1.0 / (double)(int)a1,
1.0 / (double)SHIDWORD(a1),
v1);
}

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

v1 = func3(a1);
return printf(
"Special mesh %d x %d\nh1 = %.4lf\nh2 = %.4lf\nTotal number of cells %d\n",
(unsigned int)a1,
HIDWORD(a1),
1.0 / (double)(int)a1,
1.0 / (double)SHIDWORD(a1),
v1);
}

original_code:
void print_properties (spec_mesh mesh)
{
  printf ("Special mesh %d x %d\nh1 = %.4lf\nh2 = %.4lf\nTotal number of cells %d\n",
          mesh.M1, mesh.M2, (double)1 / mesh.M1, (double)1 / mesh.M2, size (mesh));
}

canonical_original_code:
void print_properties(struct _spec_mesh mesh)
{
  printf ("Special mesh %d x %d\nh1 = %.4lf\nh2 = %.4lf\nTotal number of cells %d\n",
          mesh.M1, mesh.M2, (double)1 / mesh.M1, (double)1 / mesh.M2, size (mesh));
}


original_code:
int get_up (spec_mesh mesh, int ind)
{
  int row, col;
  if (ind < 0 || ind >= size (mesh))
    return -1;
  row = ind / (mesh.M1 + 1);
  if (row > mesh.M2 - mesh.M2/4)
    {
      row = (ind - (mesh.M1 + 1) * (mesh.M2 + 1 - mesh.M2 / 4)) / (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      col = (ind - (mesh.M1 + 1) * (mesh.M2 + 1 - mesh.M2 / 4)) % (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      if (row == 0)
        {
          if (col > (2 * mesh.M1) / 5)
            return (mesh.M1 + 1) * (mesh.M2 - mesh.M2 / 4) + col + (mesh.M1 / 5 - 1);
          else
            return (mesh.M1 + 1) * (mesh.M2 - mesh.M2 / 4) + col;
        }
      else
        return ind - (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
    }
  else
    {
      if (row == 0)
        return -1;
      else
        return ind - (mesh.M1 + 1);
    }
}

canonical_original_code:
int get_up(struct _spec_mesh mesh, int ind)
{
  int row; int col;
  if (ind < 0 || ind >= size (mesh))
    return -1;
  row = ind / (mesh.M1 + 1);
  if (row > mesh.M2 - mesh.M2/4)
    {
      row = (ind - (mesh.M1 + 1) * (mesh.M2 + 1 - mesh.M2 / 4)) / (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      col = (ind - (mesh.M1 + 1) * (mesh.M2 + 1 - mesh.M2 / 4)) % (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      if (row == 0)
        {
          if (col > (2 * mesh.M1) / 5)
            return (mesh.M1 + 1) * (mesh.M2 - mesh.M2 / 4) + col + (mesh.M1 / 5 - 1);
          else
            return (mesh.M1 + 1) * (mesh.M2 - mesh.M2 / 4) + col;
        }
      else
        return ind - (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
    }
  else
    {
      if (row == 0)
        return -1;
      else
        return ind - (mesh.M1 + 1);
    }
}

variable_types: ind int

variable_types: row int

variable_types: col int


original_code:
int get_down (spec_mesh mesh, int ind)
{
  int row, col;
  if (ind < 0 || ind >= size (mesh))
    return -1;
  row = ind / (mesh.M1 + 1);
  if (row > mesh.M2 - mesh.M2 / 4)
    {
      row = (ind - (mesh.M1 + 1) * (mesh.M2 + 1 - mesh.M2 / 4)) / (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      col = (ind - (mesh.M1 + 1) * (mesh.M2 + 1 - mesh.M2 / 4)) % (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      if (row == mesh.M2 / 4 - 1)
        return -1;
      else
        return ind + mesh.M1 + 1 - (mesh.M1 / 5 - 1);
    }
  else
    {
      col = ind % (mesh.M1 + 1);
      if (row == mesh.M2 - mesh.M2/4)
        {
          if (col <= (2 * mesh.M1) / 5)
            return (mesh.M1 + 1) * (mesh.M2 + 1 - mesh.M2/4) + col;
          else if (col >= (3 * mesh.M1) / 5)
            return (mesh.M1 + 1) * (mesh.M2 + 1 - mesh.M2/4) + col - (mesh.M1 / 5 - 1);
          else
            return -1;
        }
      else
        return ind + (mesh.M1 + 1);
    }
}

canonical_original_code:
int get_down(struct _spec_mesh mesh, int ind)
{
  int row; int col;
  if (ind < 0 || ind >= size (mesh))
    return -1;
  row = ind / (mesh.M1 + 1);
  if (row > mesh.M2 - mesh.M2 / 4)
    {
      row = (ind - (mesh.M1 + 1) * (mesh.M2 + 1 - mesh.M2 / 4)) / (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      col = (ind - (mesh.M1 + 1) * (mesh.M2 + 1 - mesh.M2 / 4)) % (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      if (row == mesh.M2 / 4 - 1)
        return -1;
      else
        return ind + mesh.M1 + 1 - (mesh.M1 / 5 - 1);
    }
  else
    {
      col = ind % (mesh.M1 + 1);
      if (row == mesh.M2 - mesh.M2/4)
        {
          if (col <= (2 * mesh.M1) / 5)
            return (mesh.M1 + 1) * (mesh.M2 + 1 - mesh.M2/4) + col;
          else if (col >= (3 * mesh.M1) / 5)
            return (mesh.M1 + 1) * (mesh.M2 + 1 - mesh.M2/4) + col - (mesh.M1 / 5 - 1);
          else
            return -1;
        }
      else
        return ind + (mesh.M1 + 1);
    }
}


decompiled_code:
__int64 __fastcall get_left(__int64 a1, int a2)
{
int v3; // ecx
int v4; // ebp
int v5; // esi
int v6; // edx
__int64 result; // rax

if ( a2 < 0 )
return 0xFFFFFFFFLL;
if ( (int)size(a1) <= a2 )
return 0xFFFFFFFFLL;
v3 = a1 + 1;
v4 = HIDWORD(a1) - SHIDWORD(a1) / 4;
if ( v4 >= a2 / ((int)a1 + 1) )
{
if ( a2 % v3 )
result = (unsigned int)(a2 - 1);
else
result = 0xFFFFFFFFLL;
}
else
{
v5 = (int)a1 / 5 - 1;
v6 = (a2 - v3 * (v4 + 1)) % (v3 - v5);
if ( v6 )
{
if ( 3 * (int)a1 / 5 - v5 == v6 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(a2 - 1);
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
int v3; // ecx
int v4; // ebp
int v5; // esi
int v6; // edx
__int64 result; // rax

if ( a2 < 0 )
return 0xFFFFFFFFLL;
if ( (int)func3(a1) <= a2 )
return 0xFFFFFFFFLL;
v3 = a1 + 1;
v4 = HIDWORD(a1) - SHIDWORD(a1) / 4;
if ( v4 >= a2 / ((int)a1 + 1) )
{
if ( a2 % v3 )
result = (unsigned int)(a2 - 1);
else
result = 0xFFFFFFFFLL;
}
else
{
v5 = (int)a1 / 5 - 1;
v6 = (a2 - v3 * (v4 + 1)) % (v3 - v5);
if ( v6 )
{
if ( 3 * (int)a1 / 5 - v5 == v6 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(a2 - 1);
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int get_left (spec_mesh mesh, int ind)
{
  int row, col;
  if (ind < 0 || ind >= size (mesh))
    return -1;
  row = ind / (mesh.M1 + 1);
  if (row > mesh.M2 - mesh.M2 / 4)
    {
      col = (ind - (mesh.M1 + 1) * (mesh.M2 - mesh.M2 / 4 + 1)) % (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      if (col == 0 || col == (3 * mesh.M1) / 5 - (mesh.M1 / 5 - 1))
        return -1;
      else
        return ind - 1;
    }
  else
    {
      col = ind % (mesh.M1 + 1);
      if (col == 0)
        return -1;
      else
        return ind - 1;
    }
}

canonical_original_code:
int get_left(struct _spec_mesh mesh, int ind)
{
  int row; int col;
  if (ind < 0 || ind >= size (mesh))
    return -1;
  row = ind / (mesh.M1 + 1);
  if (row > mesh.M2 - mesh.M2 / 4)
    {
      col = (ind - (mesh.M1 + 1) * (mesh.M2 - mesh.M2 / 4 + 1)) % (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      if (col == 0 || col == (3 * mesh.M1) / 5 - (mesh.M1 / 5 - 1))
        return -1;
      else
        return ind - 1;
    }
  else
    {
      col = ind % (mesh.M1 + 1);
      if (col == 0)
        return -1;
      else
        return ind - 1;
    }
}


decompiled_code:
__int64 __fastcall get_right(__int64 a1, int a2)
{
int v2; // ecx
int v3; // ebp
int v4; // er8
int v5; // edx
__int64 result; // rax

if ( a2 < 0 )
return 0xFFFFFFFFLL;
if ( (int)size(a1) <= a2 )
return 0xFFFFFFFFLL;
v2 = a1 + 1;
v3 = HIDWORD(a1) - SHIDWORD(a1) / 4;
if ( v3 >= a2 / ((int)a1 + 1) )
{
if ( a2 % v2 == (_DWORD)a1 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(a2 + 1);
}
else
{
v4 = (int)a1 / 5 - 1;
v5 = (a2 - v2 * (v3 + 1)) % (v2 - v4);
if ( (_DWORD)a1 - v4 == v5 )
{
result = 0xFFFFFFFFLL;
}
else if ( 2 * ((int)a1 / 5) == v5 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)(a2 + 1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
int v2; // ecx
int v3; // ebp
int v4; // er8
int v5; // edx
__int64 result; // rax

if ( a2 < 0 )
return 0xFFFFFFFFLL;
if ( (int)func3(a1) <= a2 )
return 0xFFFFFFFFLL;
v2 = a1 + 1;
v3 = HIDWORD(a1) - SHIDWORD(a1) / 4;
if ( v3 >= a2 / ((int)a1 + 1) )
{
if ( a2 % v2 == (_DWORD)a1 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(a2 + 1);
}
else
{
v4 = (int)a1 / 5 - 1;
v5 = (a2 - v2 * (v3 + 1)) % (v2 - v4);
if ( (_DWORD)a1 - v4 == v5 )
{
result = 0xFFFFFFFFLL;
}
else if ( 2 * ((int)a1 / 5) == v5 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)(a2 + 1);
}
}
return result;
}

original_code:
int get_right (spec_mesh mesh, int ind)
{
  int row, col;
  if (ind < 0 || ind >= size (mesh))
    return -1;
  row = ind / (mesh.M1 + 1);
  if (row > mesh.M2 - mesh.M2 / 4)
    {
      col = (ind - (mesh.M1 + 1) * (mesh.M2 - mesh.M2 / 4 + 1)) % (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      if (col == mesh.M1 - (mesh.M1 / 5 - 1) || col == 2 * (mesh.M1 / 5))
        return -1;
      else
        return ind + 1;
    }
  else
    {
      col = ind % (mesh.M1 + 1);
      if (col == mesh.M1)
        return -1;
      else
        return ind + 1;
    }
}

canonical_original_code:
int get_right(struct _spec_mesh mesh, int ind)
{
  int row; int col;
  if (ind < 0 || ind >= size (mesh))
    return -1;
  row = ind / (mesh.M1 + 1);
  if (row > mesh.M2 - mesh.M2 / 4)
    {
      col = (ind - (mesh.M1 + 1) * (mesh.M2 - mesh.M2 / 4 + 1)) % (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      if (col == mesh.M1 - (mesh.M1 / 5 - 1) || col == 2 * (mesh.M1 / 5))
        return -1;
      else
        return ind + 1;
    }
  else
    {
      col = ind % (mesh.M1 + 1);
      if (col == mesh.M1)
        return -1;
      else
        return ind + 1;
    }
}


original_code:
double get_x (spec_mesh mesh, int ind)
{
  int row, col;
  row = ind / (mesh.M1 + 1);
  if (row > mesh.M2 - mesh.M2 / 4)
    {
      col = (ind - (mesh.M1 + 1) * (mesh.M2 - mesh.M2 / 4 + 1)) % (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      if (col > (2 * mesh.M1) / 5)
        col += mesh.M1 / 5 - 1;
    }
  else
    col = ind % (mesh.M1 + 1);
  return (double)(1.0 / mesh.M1) * col;
}

canonical_original_code:
double get_x(struct _spec_mesh mesh, int ind)
{
  int row; int col;
  row = ind / (mesh.M1 + 1);
  if (row > mesh.M2 - mesh.M2 / 4)
    {
      col = (ind - (mesh.M1 + 1) * (mesh.M2 - mesh.M2 / 4 + 1)) % (mesh.M1 + 1 - (mesh.M1 / 5 - 1));
      if (col > (2 * mesh.M1) / 5)
        col += mesh.M1 / 5 - 1;
    }
  else
    col = ind % (mesh.M1 + 1);
  return (double)(1.0 / mesh.M1) * col;
}


original_code:
double get_y (spec_mesh mesh, int ind)
{
  int row;
  row = ind / (mesh.M1 + 1);
  if (row > mesh.M2 - mesh.M2 / 4)
    row = (ind - (mesh.M1 + 1) * (mesh.M2 - mesh.M2 / 4 + 1)) / (mesh.M1 + 1 - (mesh.M1 / 5 - 1)) + mesh.M2 - mesh.M2 / 4 + 1;
  return (double)(1.0 / mesh.M2) * (mesh.M2 - row);
}

canonical_original_code:
double get_y(struct _spec_mesh mesh, int ind)
{
  int row;
  row = ind / (mesh.M1 + 1);
  if (row > mesh.M2 - mesh.M2 / 4)
    row = (ind - (mesh.M1 + 1) * (mesh.M2 - mesh.M2 / 4 + 1)) / (mesh.M1 + 1 - (mesh.M1 / 5 - 1)) + mesh.M2 - mesh.M2 / 4 + 1;
  return (double)(1.0 / mesh.M2) * (mesh.M2 - row);
}


repo: Jery-Mong/flyfile

decompiled_code:
void __noreturn cmd_quit()
{
bcast_offline();
list_destroy(peer_list);
winds_quit();
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
bcast_offline();
list_destroy(peer_list);
winds_quit();
exit(0);
}

original_code:
int cmd_quit(char **cmd)
{
 bcast_offline();
 list_destroy(peer_list);
 winds_quit();
 exit(0);
}

variable_types:
cmd
char **


decompiled_code:
__int64 __fastcall wait_chat_ack(__int64 a1)
{
unsigned int v1; // ebx
__int64 result; // rax

v1 = 10;
while ( 1 )
{
sleep(1u);
m_printf(&unk_771, v1);
result = *(unsigned int *)(a1 + 44);
if ( (_DWORD)result == 1 )
break;
if ( !--v1 )
{
*(_DWORD *)(a1 + 44) = 0;
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ebx
__int64 result; // rax

v1 = 10;
while ( 1 )
{
sleep(1u);
m_printf(&unk_771, v1);
result = *(unsigned int *)(a1 + 44);
if ( (_DWORD)result == 1 )
break;
if ( !--v1 )
{
*(_DWORD *)(a1 + 44) = 0;
return result;
}
}
return result;
}

original_code:
static void wait_chat_ack(struct peer *pr)
{
 int i;
 for (i = 10; i > 0; i--) {
  sleep(1);
  m_printf("%d ", i);
  if (pr->chat_rsq_stat == RSP_YES)
   return;
 }
 pr->chat_rsq_stat = RSP_NO;
}

variable_types: struct peer { int idnum; struct base_inf { char name[32]; unsigned int ip; } id; int file_rsq_stat; int chat_rsq_stat; } *

variable_types: i int

user_defined_types: struct peer { int idnum; struct base_inf id; int file_rsq_stat; int chat_rsq_stat; }


decompiled_code:
__int64 cmd_help()
{
char **v0; // rbp
unsigned int i; // ebx

v0 = cmd_list;
for ( i = 0; i != 6; ++i )
{
m_printf("%d. %s%c %s\n", i);
v0 += 3;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
char **v0; // rbp
unsigned int i; // ebx

v0 = cmd_list;
for ( i = 0; i != 6; ++i )
{
m_printf("%d. %s%c %s\n", i);
v0 += 3;
}
return 0LL;
}

original_code:
int cmd_help(char **cmd)
{
 int cmd_cnt = sizeof(cmd_list) / sizeof(cmd_list[0]);
 int i;
 for (i = 0; i < cmd_cnt; i++) {
  m_printf("%d. %s%c %s\n", i, cmd_list[i].name, 9, cmd_list[i].help_info);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall cmd_chrsq(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
int v4; // ebp
int v6; // [rsp+0h] [rbp-88h] BYREF
__m128i v7; // [rsp+4h] [rbp-84h]
__m128i v8; // [rsp+14h] [rbp-74h]
int v9; // [rsp+24h] [rbp-64h]

v2 = getpeerbyidnum(*(_QWORD *)(a1 + 8));
if ( v2 )
{
v3 = v2;
v6 = 4;
v7 = _mm_loadu_si128(self);
v8 = _mm_loadu_si128((const __m128i *)(self + 16LL));
v9 = *(_DWORD *)(self + 32LL);
v4 = getsockfd(4LL, v2);
send(v4, &v6, 0x6CuLL, 0);
close(v4);
wait_chat_ack(v3);
if ( *(_DWORD *)(v3 + 44) )
m_printf("Ok\n", &v6);
else
m_printf("Rejected\n", &v6);
}
else
{
m_printf("No Such Peer\n", a2);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
int v4; // ebp
int v6; // [rsp+0h] [rbp-88h] BYREF
__m128i v7; // [rsp+4h] [rbp-84h]
__m128i v8; // [rsp+14h] [rbp-74h]
int v9; // [rsp+24h] [rbp-64h]

v2 = getpeerbyidnum(*(_QWORD *)(a1 + 8));
if ( v2 )
{
v3 = v2;
v6 = 4;
v7 = _mm_loadu_si128(self);
v8 = _mm_loadu_si128((const __m128i *)(self + 16LL));
v9 = *(_DWORD *)(self + 32LL);
v4 = getsockfd(4LL, v2);
send(v4, &v6, 0x6CuLL, 0);
close(v4);
func1(v3);
if ( *(_DWORD *)(v3 + 44) )
m_printf("Ok\n", &v6);
else
m_printf("Rejected\n", &v6);
}
else
{
m_printf("No Such Peer\n", a2);
}
return 0LL;
}

original_code:
int cmd_chrsq(char **cmd)
{
 struct peer *pr = getpeerbyidnum(cmd[1]);
 if (pr == ((void *)0)) {
  m_printf ("No Such Peer\n");
  return 0;
 }
 struct message msg;
 msg.type = MSG_CHAT_RQST;
 memcpy(&msg.id, &self->id, sizeof(struct base_inf));
 int fd = getsockfd(FD_SENDMSG, pr);
 send(fd, &msg, sizeof(msg), 0);
 close(fd);
 wait_chat_ack(pr);
 if (pr->chat_rsq_stat == RSP_NO)
  m_printf ("Rejected\n");
 else
  m_printf ("Ok\n");
 return 0;
}

variable_types: struct message { int type; struct base_inf { char name[32]; unsigned int ip; } id; union { int m_answer; struct file_inf { char fname[64]; unsigned int fsize; } m_file; char m_news[64]; char m_chat[64]; } mdata; }

variable_types: fd int

user_defined_types: struct message { int type; struct base_inf id; union { int m_answer; struct file_inf m_file; char m_news[64]; char m_chat[64]; } mdata; }


decompiled_code:
__int64 cmd_printpr()
{
__int64 v0; // rax
struct in_addr **v1; // rbx
struct in_addr *v2; // rbp

v0 = *(_QWORD *)(peer_list + 8LL);
v1 = *(struct in_addr ***)(v0 + 16);
if ( (struct in_addr **)v0 != v1 )
{
do
{
v2 = *v1;
inet_ntoa((*v1)[9]);
m_printf("%d. %s : %s\n", v2->s_addr);
v1 = (struct in_addr **)v1[2];
}
while ( *(struct in_addr ***)(peer_list + 8LL) != v1 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
struct in_addr **v1; // rbx
struct in_addr *v2; // rbp

v0 = *(_QWORD *)(peer_list + 8LL);
v1 = *(struct in_addr ***)(v0 + 16);
if ( (struct in_addr **)v0 != v1 )
{
do
{
v2 = *v1;
inet_ntoa((*v1)[9]);
m_printf("%d. %s : %s\n", v2->s_addr);
v1 = (struct in_addr **)v1[2];
}
while ( *(struct in_addr ***)(peer_list + 8LL) != v1 );
}
return 0LL;
}

original_code:
int cmd_printpr(char **cmd)
{
 node_t *iter;
 for(iter = (peer_list)->head->next; iter != (peer_list)->head ; iter = iter->next) {
  struct peer *pr = (struct peer *)(iter->data);
  m_printf("%d. %s : %s\n", pr->idnum, pr->id.name, inet_ntoa(*((struct in_addr *)&(pr->id.ip))));
 }
 return 0;
}

canonical_original_code:
int cmd_printpr(char **cmd)
{
 struct list_node *iter;
 for(iter = (peer_list)->head->next; iter != (peer_list)->head ; iter = iter->next) {
  struct peer *pr = (struct peer *)(iter->data);
  m_printf("%d. %s : %s\n", pr->idnum, pr->id.name, inet_ntoa(*((struct in_addr *)&(pr->id.ip))));
 }
 return 0;
}

variable_types: struct list_node { void *data; struct list_node *prev; struct list_node *next; } *

user_defined_types: struct base_inf { char name[32]; unsigned int ip; }


decompiled_code:
__int64 __fastcall cmd_chat(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r12
const char *v4; // rbp
__int64 v5; // rbx
int v6; // ebx
__int64 result; // rax
int v8[34]; // [rsp+0h] [rbp-88h] BYREF

v2 = getpeerbyidnum(*(_QWORD *)(a1 + 8));
if ( v2 )
{
v3 = v2;
if ( *(_DWORD *)(v2 + 44) )
{
v4 = *(const char **)(a1 + 16);
if ( v4 )
{
memset(v8, 0, 0x68uLL);
v8[26] = 0;
v8[0] = 7;
*(__m128i *)&v8[1] = _mm_loadu_si128(self);
*(__m128i *)&v8[5] = _mm_loadu_si128((const __m128i *)(self + 16LL));
v8[9] = *(_DWORD *)(self + 32LL);
v5 = a1 + 24;
do
{
*(_WORD *)((char *)&v8[10] + strlen((const char *)&v8[10])) = 32;
strcat((char *)&v8[10], v4);
v5 += 8LL;
v4 = *(const char **)(v5 - 8);
}
while ( v4 );
v6 = getsockfd(4LL, v3);
send(v6, v8, 0x6CuLL, 0);
close(v6);
result = 0LL;
}
else
{
m_printf("No comment\n");
result = 0xFFFFFFFFLL;
}
}
else
{
m_printf("chat with %s is not allowed\n", (const char *)(v2 + 4));
result = 0xFFFFFFFFLL;
}
}
else
{
m_printf("No Such Peer\n", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r12
const char *v4; // rbp
__int64 v5; // rbx
int v6; // ebx
__int64 result; // rax
int v8[34]; // [rsp+0h] [rbp-88h] BYREF

v2 = getpeerbyidnum(*(_QWORD *)(a1 + 8));
if ( v2 )
{
v3 = v2;
if ( *(_DWORD *)(v2 + 44) )
{
v4 = *(const char **)(a1 + 16);
if ( v4 )
{
memset(v8, 0, 0x68uLL);
v8[26] = 0;
v8[0] = 7;
*(__m128i *)&v8[1] = _mm_loadu_si128(self);
*(__m128i *)&v8[5] = _mm_loadu_si128((const __m128i *)(self + 16LL));
v8[9] = *(_DWORD *)(self + 32LL);
v5 = a1 + 24;
do
{
*(_WORD *)((char *)&v8[10] + strlen((const char *)&v8[10])) = 32;
strcat((char *)&v8[10], v4);
v5 += 8LL;
v4 = *(const char **)(v5 - 8);
}
while ( v4 );
v6 = getsockfd(4LL, v3);
send(v6, v8, 0x6CuLL, 0);
close(v6);
result = 0LL;
}
else
{
m_printf("No comment\n");
result = 0xFFFFFFFFLL;
}
}
else
{
m_printf("chat with %s is not allowed\n", (const char *)(v2 + 4));
result = 0xFFFFFFFFLL;
}
}
else
{
m_printf("No Such Peer\n", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int cmd_chat(char **cmd)
{
 struct peer *pr = getpeerbyidnum(cmd[1]);
 if (pr == ((void *)0)) {
  m_printf ("No Such Peer\n");
  return -1;
 }
 if (pr->chat_rsq_stat == RSP_NO) {
  m_printf ("chat with %s is not allowed\n", pr->id.name);
  return -1;
 }
 if (cmd[2] == ((void *)0)) {
  m_printf ("No comment\n");
  return -1;
 }
 struct message msg;
 memset(&msg, 0, sizeof(struct message));
 msg.type = MSG_CHAT;
 memcpy(&msg.id, &self->id, sizeof(struct base_inf));
 int i;
 for (i = 2; cmd[i] != ((void *)0); i++) {
  strcat(msg.mdata.m_chat, " ");
  strcat(msg.mdata.m_chat, cmd[i]);
 }
 int fd = getsockfd(FD_SENDMSG, pr);
 send(fd, &msg, sizeof(msg), 0);
 close(fd);
 return 0;
}

user_defined_types: struct file_inf { char fname[64]; unsigned int fsize; }


decompiled_code:
void __fastcall free_cmd(void **a1)
{
void *v2; // rdi
void **v3; // rbx

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
v3 = a1 + 1;
do
{
free(v2);
v2 = *v3++;
}
while ( v2 );
}
}
}

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

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
v3 = a1 + 1;
do
{
free(v2);
v2 = *v3++;
}
while ( v2 );
}
}
}

original_code:
static void free_cmd(char **cmd)
{
 if (cmd == ((void *)0))
  return;
 int i;
 for (i = 0; cmd[i] != ((void *)0); i++)
  free(cmd[i]);
}