interpExp

decompiled_code:
__int64 __fastcall interpExp(char **a1, __int64 a2)
{
char **v2; // rbp
int v3; // eax
__int64 v4; // rax
int v6; // er12
int v7; // eax

v2 = a1;
v3 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 1 )
return *((unsigned int *)v2 + 2);
while ( 1 )
{
if ( !v3 )
return (unsigned int)lookup(v2[1], a2);
if ( v3 == 2 )
{
v6 = interpExp(v2[1]);
v7 = interpExp(v2[3]);
return (unsigned int)calculate(v6, v7, *((_DWORD *)v2 + 4));
}
if ( v3 != 3 )
break;
v4 = interpStm(v2[1]);
v2 = (char **)v2[2];
a2 = v4;
v3 = *(_DWORD *)v2;
if ( *(_DWORD *)v2 == 1 )
return *((unsigned int *)v2 + 2);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char **a1, __int64 a2)
{
char **v2; // rbp
int v3; // eax
__int64 v4; // rax
int v6; // er12
int v7; // eax

v2 = a1;
v3 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 1 )
return *((unsigned int *)v2 + 2);
while ( 1 )
{
if ( !v3 )
return (unsigned int)func1(v2[1], a2);
if ( v3 == 2 )
{
v6 = func4(v2[1]);
v7 = func4(v2[3]);
return (unsigned int)func3(v6, v7, *((_DWORD *)v2 + 4));
}
if ( v3 != 3 )
break;
v4 = func5(v2[1]);
v2 = (char **)v2[2];
a2 = v4;
v3 = *(_DWORD *)v2;
if ( *(_DWORD *)v2 == 1 )
return *((unsigned int *)v2 + 2);
}
return 0LL;
}

original_code:
struct IntAndTable interpExp( A_exp exp, A_table table){
 struct IntAndTable iat;
 if(exp->kind == A_numExp){
  iat.i = exp->u.num;
  iat.t = table;
  return iat;
 }else if(exp->kind == A_idExp){
  int val = lookup(exp->u.id, table);
  iat.i = val;
  iat.t = table;
  return iat;
 }else if(exp->kind == A_opExp){
  struct IntAndTable left_iat, right_iat, final_iat;
  left_iat = interpExp(exp->u.op.left, table);
  right_iat = interpExp(exp->u.op.right, left_iat.t);
  final_iat.i = calculate(left_iat.i, right_iat.i, exp->u.op.oper);
  final_iat.t = right_iat.t;
  return final_iat;
 }else if(exp->kind == A_eseqExp){
  iat.t = interpStm(exp->u.eseq.stm, table);
  iat = interpExp(exp->u.eseq.exp, iat.t);
  return iat;
 }
 return iat;
}

canonical_original_code:
struct IntAndTable interpExp(struct A_exp_ *exp, struct A_table_ *table){
 struct IntAndTable iat;
 if(exp->kind == A_numExp){
  iat.i = exp->u.num;
  iat.t = table;
  return iat;
 }else if(exp->kind == A_idExp){
  int val = lookup(exp->u.id, table);
  iat.i = val;
  iat.t = table;
  return iat;
 }else if(exp->kind == A_opExp){
  struct IntAndTable left_iat; struct IntAndTable right_iat; struct IntAndTable final_iat;
  left_iat = interpExp(exp->u.op.left, table);
  right_iat = interpExp(exp->u.op.right, left_iat.t);
  final_iat.i = calculate(left_iat.i, right_iat.i, exp->u.op.oper);
  final_iat.t = right_iat.t;
  return final_iat;
 }else if(exp->kind == A_eseqExp){
  iat.t = interpStm(exp->u.eseq.stm, table);
  iat = interpExp(exp->u.eseq.exp, iat.t);
  return iat;
 }
 return iat;
}

variable_types: struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ *exp; } assign; struct { struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *exps; } print; } u; } *stm; struct A_exp_ *exp; } eseq; } u; } *

variable_types:
table
struct A_table_ *

variable_types: struct IntAndTable { int i; struct A_table_ { char *id; int value; struct A_table_ *tail; } *t; }

variable_types: val int

user_defined_types: struct IntAndTable { int i; struct A_table_ *t; }

user_defined_types: struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ *exp; } assign; struct { struct A_expList_ *exps; } print; } u; }


interpStm

repo: wangxinalex/compiler

original_code:
A_table interpStm(A_stm prog, A_table table){
 if(prog->kind == A_compoundStm){
  table = interpStm(prog->u.compound.stm1, table);
  table = interpStm(prog->u.compound.stm2, table);
 }else if(prog->kind == A_assignStm){
  struct IntAndTable int_and_table =
   interpExp( prog->u.assign.exp, table);
  table = (A_table)Table(prog->u.assign.id, int_and_table.i, int_and_table.t);
 }else if(prog->kind == A_printStm){
  A_expList list = prog->u.print.exps;
  while(list->kind != A_lastExpList){
   if(list->u.pair.head->kind == A_eseqExp){
    A_stm ex_prog = list->u.pair.head->u.eseq.stm;
    interpStm(ex_prog, table);
   }
   list = list->u.pair.tail;
  }
  if(list->u.last->kind == A_eseqExp){
   interpStm(list->u.last->u.eseq.stm, table);
  }
 }
 return table;
}

canonical_original_code:
struct A_table_ *interpStm(struct A_stm_ *prog, struct A_table_ *table){
 if(prog->kind == A_compoundStm){
  table = interpStm(prog->u.compound.stm1, table);
  table = interpStm(prog->u.compound.stm2, table);
 }else if(prog->kind == A_assignStm){
  struct IntAndTable int_and_table = interpExp( prog->u.assign.exp, table);
  table = (struct A_table_ *)Table(prog->u.assign.id, int_and_table.i, int_and_table.t);
 }else if(prog->kind == A_printStm){
  struct A_expList_ *list = prog->u.print.exps;
  while(list->kind != A_lastExpList){
   if(list->u.pair.head->kind == A_eseqExp){
    struct A_stm_ *ex_prog = list->u.pair.head->u.eseq.stm;
    interpStm(ex_prog, table);
   }
   list = list->u.pair.tail;
  }
  if(list->u.last->kind == A_eseqExp){
   interpStm(list->u.last->u.eseq.stm, table);
  }
 }
 return table;
}

variable_types: struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ *stm; struct A_exp_ *exp; } eseq; } u; } *exp; } assign; struct { struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *exps; } print; } u; } *

variable_types: struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ *exp; } assign; struct { struct A_expList_ *exps; } print; } u; } *stm; struct A_exp_ *exp; } eseq; } u; } *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *

return_type: struct A_table_ { char *id; int value; struct A_table_ *tail; } *

user_defined_types: struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop oper; struct A_exp_ *right; } op; struct { struct A_stm_ *stm; struct A_exp_ *exp; } eseq; } u; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rbp
__int64 v4; // rdi
int *v5; // rbp
__int64 v6; // rax
int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

v8[0] = 0;
v3 = (int *)right_prog(argc, argv, envp);
maxargs(v3, v8);
puts(">> Right Prog Section:");
printf("the maximum number of arguments of any print statement is %d\n", (unsigned int)v8[0]);
v4 = interpStm(v3, 0LL);
print_table(v4);
v8[0] = 0;
v5 = (int *)error_prog();
maxargs(v5, v8);
puts(">> Error Prog Section:");
printf("the maximum number of arguments of any print statement is %d\n", (unsigned int)v8[0]);
v6 = interpStm(v5, 0LL);
print_table(v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rbp
__int64 v4; // rdi
int *v5; // rbp
__int64 v6; // rax
int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

v8[0] = 0;
v3 = (int *)right_prog(argc, argv, envp);
func0(v3, v8);
puts(">> Right Prog Section:");
printf("the maximum number of arguments of any print statement is %d\n", (unsigned int)v8[0]);
v4 = func5(v3, 0LL);
func2(v4);
v8[0] = 0;
v5 = (int *)error_prog();
func0(v5, v8);
puts(">> Error Prog Section:");
printf("the maximum number of arguments of any print statement is %d\n", (unsigned int)v8[0]);
v6 = func5(v5, 0LL);
func2(v6);
return 0;
}

original_code:
int main(){
 int max_args = 0;
 A_table global_table = ((void *)0);
 A_stm right_stm = right_prog();
 maxargs(right_stm, &max_args);
 printf(">> Right Prog Section:\n");
 printf("the maximum number of arguments of any print statement is %d\n",max_args);
 global_table = interpStm(right_stm, global_table);
 print_table(global_table);
 max_args = 0;
 global_table = ((void *)0);
 A_stm error_stm = error_prog();
 maxargs(error_stm, &max_args);
 printf(">> Error Prog Section:\n");
 printf("the maximum number of arguments of any print statement is %d\n",max_args);
 global_table = interpStm(error_stm, global_table);
 print_table(global_table);
   return 0;
}

canonical_original_code:
int main(){
 int max_args = 0;
 struct A_table_ *global_table = ((void *)0);
 struct A_stm_ *right_stm = right_prog();
 maxargs(right_stm, &max_args);
 printf(">> Right Prog Section:\n");
 printf("the maximum number of arguments of any print statement is %d\n",max_args);
 global_table = interpStm(right_stm, global_table);
 print_table(global_table);
 max_args = 0;
 global_table = ((void *)0);
 struct A_stm_ *error_stm = error_prog();
 maxargs(error_stm, &max_args);
 printf(">> Error Prog Section:\n");
 printf("the maximum number of arguments of any print statement is %d\n",max_args);
 global_table = interpStm(error_stm, global_table);
 print_table(global_table);
   return 0;
}

variable_types: struct A_table_ { char *id; int value; struct A_table_ *tail; } *

return_type: int

user_defined_types: struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; }

user_defined_types: enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 }


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

result = checked_malloc(24LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

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

result = checked_malloc(24LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

original_code:
A_stm A_CompoundStm(A_stm stm1, A_stm stm2) {
  A_stm s = checked_malloc(sizeof *s);
  s->kind=A_compoundStm; s->u.compound.stm1=stm1; s->u.compound.stm2=stm2;
  return s;
}

canonical_original_code:
struct A_stm_ *A_CompoundStm(struct A_stm_ *stm1, struct A_stm_ *stm2) {
  struct A_stm_ *s = checked_malloc(sizeof *s);
  s->kind=A_compoundStm; s->u.compound.stm1=stm1; s->u.compound.stm2=stm2;
  return s;
}

return_type: struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ *stm; struct A_exp_ *exp; } eseq; } u; } *exp; } assign; struct { struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *exps; } print; } u; } *


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

result = checked_malloc(24LL);
*(_DWORD *)result = 1;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

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

result = checked_malloc(24LL);
*(_DWORD *)result = 1;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

original_code:
A_stm A_AssignStm(string id, A_exp exp) {
  A_stm s = checked_malloc(sizeof *s);
  s->kind=A_assignStm; s->u.assign.id=id; s->u.assign.exp=exp;
  return s;
}

canonical_original_code:
struct A_stm_ *A_AssignStm(char *id, struct A_exp_ *exp) {
  struct A_stm_ *s = checked_malloc(sizeof *s);
  s->kind=A_assignStm; s->u.assign.id=id; s->u.assign.exp=exp;
  return s;
}

variable_types:
id
char *

variable_types:
exp
struct A_exp_ *


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

result = checked_malloc(24LL);
*(_DWORD *)result = 2;
*(_QWORD *)(result + 8) = a1;
return result;
}

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

result = checked_malloc(24LL);
*(_DWORD *)result = 2;
*(_QWORD *)(result + 8) = a1;
return result;
}

original_code:
A_stm A_PrintStm(A_expList exps) {
  A_stm s = checked_malloc(sizeof *s);
  s->kind=A_printStm; s->u.print.exps=exps;
  return s;
}

canonical_original_code:
struct A_stm_ *A_PrintStm(struct A_expList_ *exps) {
  struct A_stm_ *s = checked_malloc(sizeof *s);
  s->kind=A_printStm; s->u.print.exps=exps;
  return s;
}

variable_types:
exps
struct A_expList_ *


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

result = checked_malloc(32LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = a1;
return result;
}

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

result = checked_malloc(32LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = a1;
return result;
}

original_code:
A_exp A_IdExp(string id) {
  A_exp e = checked_malloc(sizeof *e);
  e->kind=A_idExp; e->u.id=id;
  return e;
}

canonical_original_code:
struct A_exp_ *A_IdExp(char *id) {
  struct A_exp_ *e = checked_malloc(sizeof *e);
  e->kind=A_idExp; e->u.id=id;
  return e;
}

return_type: struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ *exp; } assign; struct { struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *exps; } print; } u; } *stm; struct A_exp_ *exp; } eseq; } u; } *


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

result = checked_malloc(32LL);
*(_DWORD *)result = 2;
*(_QWORD *)(result + 8) = a1;
*(_DWORD *)(result + 16) = a2;
*(_QWORD *)(result + 24) = a3;
return result;
}

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

result = checked_malloc(32LL);
*(_DWORD *)result = 2;
*(_QWORD *)(result + 8) = a1;
*(_DWORD *)(result + 16) = a2;
*(_QWORD *)(result + 24) = a3;
return result;
}

original_code:
A_exp A_OpExp(A_exp left, A_binop oper, A_exp right) {
  A_exp e = checked_malloc(sizeof *e);
  e->kind=A_opExp; e->u.op.left=left; e->u.op.oper=oper; e->u.op.right=right;
  return e;
}

canonical_original_code:
struct A_exp_ *A_OpExp(struct A_exp_ *left, enum A_binop oper, struct A_exp_ *right) {
  struct A_exp_ *e = checked_malloc(sizeof *e);
  e->kind=A_opExp; e->u.op.left=left; e->u.op.oper=oper; e->u.op.right=right;
  return e;
}

variable_types:
left
struct A_exp_ *

variable_types: enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 }

variable_types:
right
struct A_exp_ *


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

result = checked_malloc(32LL);
*(_DWORD *)result = 3;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

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

result = checked_malloc(32LL);
*(_DWORD *)result = 3;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

original_code:
A_exp A_EseqExp(A_stm stm, A_exp exp) {
  A_exp e = checked_malloc(sizeof *e);
  e->kind=A_eseqExp; e->u.eseq.stm=stm; e->u.eseq.exp=exp;
  return e;
}

canonical_original_code:
struct A_exp_ *A_EseqExp(struct A_stm_ *stm, struct A_exp_ *exp) {
  struct A_exp_ *e = checked_malloc(sizeof *e);
  e->kind=A_eseqExp; e->u.eseq.stm=stm; e->u.eseq.exp=exp;
  return e;
}

variable_types:
stm
struct A_stm_ *


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

result = checked_malloc(24LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

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

result = checked_malloc(24LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = a2;
return result;
}

original_code:
A_expList A_PairExpList(A_exp head, A_expList tail) {
  A_expList e = checked_malloc(sizeof *e);
  e->kind=A_pairExpList; e->u.pair.head=head; e->u.pair.tail=tail;
  return e;
}

canonical_original_code:
struct A_expList_ *A_PairExpList(struct A_exp_ *head, struct A_expList_ *tail) {
  struct A_expList_ *e = checked_malloc(sizeof *e);
  e->kind=A_pairExpList; e->u.pair.head=head; e->u.pair.tail=tail;
  return e;
}

variable_types:
head
struct A_exp_ *

variable_types:
tail
struct A_expList_ *

return_type: struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ *exp; } assign; struct { struct A_expList_ *exps; } print; } u; } *stm; struct A_exp_ *exp; } eseq; } u; } *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *


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

result = checked_malloc(24LL);
*(_DWORD *)result = 1;
*(_QWORD *)(result + 8) = a1;
return result;
}

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

result = checked_malloc(24LL);
*(_DWORD *)result = 1;
*(_QWORD *)(result + 8) = a1;
return result;
}

original_code:
A_expList A_LastExpList(A_exp last) {
  A_expList e = checked_malloc(sizeof *e);
  e->kind=A_lastExpList; e->u.last=last;
  return e;
}

canonical_original_code:
struct A_expList_ *A_LastExpList(struct A_exp_ *last) {
  struct A_expList_ *e = checked_malloc(sizeof *e);
  e->kind=A_lastExpList; e->u.last=last;
  return e;
}

variable_types:
last
struct A_exp_ *


Table

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

result = checked_malloc(24LL);
*(_QWORD *)result = a1;
*(_DWORD *)(result + 8) = a2;
*(_QWORD *)(result + 16) = a3;
return result;
}

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

result = checked_malloc(24LL);
*(_QWORD *)result = a1;
*(_DWORD *)(result + 8) = a2;
*(_QWORD *)(result + 16) = a3;
return result;
}

original_code:
A_table Table(string id, int value, A_table tail){
 A_table t = checked_malloc(sizeof *t);
 t->id = id;
 t->value = value;
 t->tail = tail;
 return t;
}

canonical_original_code:
struct A_table_ *Table(char *id, int value, struct A_table_ *tail){
 struct A_table_ *t = checked_malloc(sizeof *t);
 t->id = id;
 t->value = value;
 t->tail = tail;
 return t;
}

variable_types: value int

variable_types:
tail
struct A_table_ *

user_defined_types: struct A_table_ { char *id; int value; struct A_table_ *tail; }


decompiled_code:
void *__fastcall checked_malloc(int a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("\nRan out of memory!\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
return result;
}

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

result = malloc(a1);
if ( !result )
{
fwrite("\nRan out of memory!\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
return result;
}

original_code:
void *checked_malloc(int len)
{void *p = malloc(len);
 if (!p) {
    fprintf(stderr,"\nRan out of memory!\n");
    exit(1);
 }
 return p;
}

variable_types: len int

variable_types:
p
void *

return_type: void *


String

decompiled_code:
char *__fastcall String(char *src)
{
int v1; // eax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)checked_malloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
int v1; // eax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)func0(v1 + 1);
return strcpy(v2, src);
}

original_code:
string String(char *s)
{string p = checked_malloc(strlen(s)+1);
 strcpy(p,s);
 return p;
}

canonical_original_code:
char *String(char *s)
{char *p = checked_malloc(strlen(s)+1);
 strcpy(p,s);
 return p;
}

variable_types:
s
char *

variable_types:
p
char *

return_type: char *


prog

original_code:
A_stm prog(void) {
return
 A_CompoundStm(A_AssignStm("a",
                 A_OpExp(A_NumExp(5), A_plus, A_NumExp(3))),
  A_CompoundStm(A_AssignStm("b",
      A_EseqExp(A_PrintStm(A_PairExpList(A_IdExp("a"),
                 A_LastExpList(A_OpExp(A_IdExp("a"), A_minus,
                                       A_NumExp(1))))),
              A_OpExp(A_NumExp(10), A_times, A_IdExp("a")))),
   A_PrintStm(A_LastExpList(A_IdExp("b")))));
}

canonical_original_code:
struct A_stm_ *prog() {
return
 A_CompoundStm(A_AssignStm("a",
                 A_OpExp(A_NumExp(5), A_plus, A_NumExp(3))),
  A_CompoundStm(A_AssignStm("b",
      A_EseqExp(A_PrintStm(A_PairExpList(A_IdExp("a"),
                 A_LastExpList(A_OpExp(A_IdExp("a"), A_minus,
                                       A_NumExp(1))))),
              A_OpExp(A_NumExp(10), A_times, A_IdExp("a")))),
   A_PrintStm(A_LastExpList(A_IdExp("b")))));
}


original_code:
A_stm prog_prog(void)
{
     A_stm stm1 = prog();
     return
   A_CompoundStm( stm1, A_CompoundStm(A_AssignStm("a",
                 A_OpExp(A_NumExp(5), A_plus, A_IdExp("b"))),
  A_CompoundStm(A_AssignStm("b",
      A_EseqExp(A_PrintStm(A_PairExpList(A_IdExp("a"),A_PairExpList(A_IdExp("a"),
                 A_LastExpList(A_OpExp(A_IdExp("a"), A_minus,
                                       A_NumExp(1)))))),
              A_OpExp(A_NumExp(10), A_times, A_IdExp("a")))),
   A_PrintStm(A_LastExpList(A_IdExp("b"))))));
}

canonical_original_code:
struct A_stm_ *prog_prog()
{
     struct A_stm_ *stm1 = prog();
     return
   A_CompoundStm( stm1, A_CompoundStm(A_AssignStm("a",
                 A_OpExp(A_NumExp(5), A_plus, A_IdExp("b"))),
  A_CompoundStm(A_AssignStm("b",
      A_EseqExp(A_PrintStm(A_PairExpList(A_IdExp("a"),A_PairExpList(A_IdExp("a"),
                 A_LastExpList(A_OpExp(A_IdExp("a"), A_minus,
                                       A_NumExp(1)))))),
              A_OpExp(A_NumExp(10), A_times, A_IdExp("a")))),
   A_PrintStm(A_LastExpList(A_IdExp("b"))))));
}

variable_types: struct A_stm_ { enum { A_compoundStm=0, A_assignStm=1, A_printStm=2 } kind; union { struct { struct A_stm_ *stm1; } compound; struct { char *id; struct A_exp_ { enum { A_idExp=0, A_numExp=1, A_opExp=2, A_eseqExp=3 } kind; union { char *id; int num; struct { struct A_exp_ *left; enum A_binop { A_plus=0, A_minus=1, A_times=2, A_div=3 } oper; struct A_exp_ *right; } op; struct { struct A_stm_ *stm; struct A_exp_ *exp; } eseq; } u; } *exp; } assign; struct { struct A_expList_ { enum { A_pairExpList=0, A_lastExpList=1 } kind; union { struct { struct A_exp_ *head; struct A_expList_ *tail; } pair; struct A_exp_ *last; } u; } *exps; } print; } u; } *


decompiled_code:
__int64 right_prog()
{
__int64 v0; // rbp
__int64 v1; // r12
__int64 v2; // r13
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v0 = prog_prog();
v1 = A_IdExp(&unk_481);
v2 = A_IdExp(&unk_47F);
v3 = A_IdExp(&unk_481);
v4 = A_OpExp(v3, 0LL, v2);
v5 = A_AssignStm(&unk_481, v4);
v6 = A_EseqExp(v5, v1);
v7 = A_AssignStm(&unk_481, v6);
return A_CompoundStm(v0, v7);
}

original_code:
A_stm right_prog(void)
{
     A_stm stm1 = prog_prog();
     return
   A_CompoundStm( stm1, A_AssignStm("a",
      A_EseqExp(A_AssignStm("a", A_OpExp(A_IdExp("a"), A_plus, A_IdExp("b"))),
              A_IdExp("a"))));
}

canonical_original_code:
struct A_stm_ *right_prog()
{
     struct A_stm_ *stm1 = prog_prog();
     return
   A_CompoundStm( stm1, A_AssignStm("a",
      A_EseqExp(A_AssignStm("a", A_OpExp(A_IdExp("a"), A_plus, A_IdExp("b"))),
              A_IdExp("a"))));
}


decompiled_code:
__int64 error_prog()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // rax

v0 = prog_prog();
v1 = A_IdExp(&unk_483);
v2 = A_AssignStm(&unk_481, v1);
return A_CompoundStm(v0, v2);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // rax

v0 = func1();
v1 = A_IdExp(&unk_483);
v2 = A_AssignStm(&unk_481, v1);
return A_CompoundStm(v0, v2);
}

original_code:
A_stm error_prog(void)
{
     A_stm stm1 = prog_prog();
     return
   A_CompoundStm( stm1, A_AssignStm("a", A_IdExp("c")));
}

canonical_original_code:
struct A_stm_ *error_prog()
{
     struct A_stm_ *stm1 = prog_prog();
     return
   A_CompoundStm( stm1, A_AssignStm("a", A_IdExp("c")));
}


decompiled_code:
__int64 complex_prog()
{
__int64 v0; // rbp
__int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax

v0 = prog_prog();
v1 = A_IdExp(&unk_47F);
v2 = A_IdExp(&unk_481);
v3 = A_OpExp(v2, 2LL, v1);
v4 = A_AssignStm(&unk_483, v3);
return A_CompoundStm(v0, v4);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbp
__int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax

v0 = func1();
v1 = A_IdExp(&unk_47F);
v2 = A_IdExp(&unk_481);
v3 = A_OpExp(v2, 2LL, v1);
v4 = A_AssignStm(&unk_483, v3);
return A_CompoundStm(v0, v4);
}

original_code:
A_stm complex_prog(void){
     A_stm stm1 = prog_prog();
 return A_CompoundStm(stm1, A_AssignStm("c", A_OpExp(A_IdExp("a"), A_times, A_IdExp("b"))));
}

canonical_original_code:
struct A_stm_ *complex_prog(){
     struct A_stm_ *stm1 = prog_prog();
 return A_CompoundStm(stm1, A_AssignStm("c", A_OpExp(A_IdExp("a"), A_times, A_IdExp("b"))));
}


decompiled_code:
__int64 simple_prog()
{
__int64 v0; // r12
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rbp
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rbp
__int64 v10; // rax
__int64 v11; // rax

v0 = A_NumExp(1LL);
v1 = A_IdExp(&unk_481);
v2 = A_OpExp(v1, 1LL, v0);
v3 = A_LastExpList(v2);
v4 = A_IdExp(&unk_481);
v5 = A_PairExpList(v4, v3);
v6 = A_NumExp(2LL);
v7 = A_IdExp(&unk_481);
v8 = A_OpExp(v7, 0LL, v6);
v9 = A_PairExpList(v8, v5);
v10 = A_IdExp(&unk_481);
v11 = A_PairExpList(v10, v9);
return A_PrintStm(v11);
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // r12
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rbp
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rbp
__int64 v10; // rax
__int64 v11; // rax

v0 = A_NumExp(1LL);
v1 = A_IdExp(&unk_481);
v2 = A_OpExp(v1, 1LL, v0);
v3 = A_LastExpList(v2);
v4 = A_IdExp(&unk_481);
v5 = A_PairExpList(v4, v3);
v6 = A_NumExp(2LL);
v7 = A_IdExp(&unk_481);
v8 = A_OpExp(v7, 0LL, v6);
v9 = A_PairExpList(v8, v5);
v10 = A_IdExp(&unk_481);
v11 = A_PairExpList(v10, v9);
return A_PrintStm(v11);
}

original_code:
A_stm simple_prog(void){
 return A_PrintStm(A_PairExpList(A_IdExp("a"),A_PairExpList(A_OpExp(A_IdExp("a"), A_plus, A_NumExp(2)),A_PairExpList(A_IdExp("a"),
                 A_LastExpList(A_OpExp(A_IdExp("a"), A_minus,
                                       A_NumExp(1)))))));
}

canonical_original_code:
struct A_stm_ *simple_prog(){
 return A_PrintStm(A_PairExpList(A_IdExp("a"),A_PairExpList(A_OpExp(A_IdExp("a"), A_plus, A_NumExp(2)),A_PairExpList(A_IdExp("a"),
                 A_LastExpList(A_OpExp(A_IdExp("a"), A_minus,
                                       A_NumExp(1)))))));
}


decompiled_code:
__int64 middle_prog()
{
__int64 v0; // rbp
__int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v0 = simple_prog();
v1 = A_NumExp(1LL);
v2 = A_IdExp(&unk_47F);
v3 = A_OpExp(v2, 0LL, v1);
v4 = A_LastExpList(v3);
v5 = A_IdExp(&unk_47F);
v6 = A_PairExpList(v5, v4);
v7 = A_PrintStm(v6);
return A_CompoundStm(v0, v7);
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbp
__int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v0 = func5();
v1 = A_NumExp(1LL);
v2 = A_IdExp(&unk_47F);
v3 = A_OpExp(v2, 0LL, v1);
v4 = A_LastExpList(v3);
v5 = A_IdExp(&unk_47F);
v6 = A_PairExpList(v5, v4);
v7 = A_PrintStm(v6);
return A_CompoundStm(v0, v7);
}

original_code:
A_stm middle_prog(void){
 A_stm stm1 = simple_prog();
 return A_CompoundStm(stm1, A_PrintStm(A_PairExpList(A_IdExp("b"),
       A_LastExpList(A_OpExp(A_IdExp("b"), A_plus, A_NumExp(1))))));
}

canonical_original_code:
struct A_stm_ *middle_prog(){
 struct A_stm_ *stm1 = simple_prog();
 return A_CompoundStm(stm1, A_PrintStm(A_PairExpList(A_IdExp("b"),
       A_LastExpList(A_OpExp(A_IdExp("b"), A_plus, A_NumExp(1))))));
}


repo: wangxunyu/sego

decompiled_code:
_BOOL8 __fastcall stk_empty(_DWORD *a1)
{
return *a1 <= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_DWORD *a1)
{
return *a1 <= 0;
}

original_code:
int stk_empty(stk_t *s) {
    return s->top > 0 ? 0 : 1;
}

canonical_original_code:
int stk_empty(struct stk *s) {
    return s->top > 0 ? 0 : 1;
}

variable_types:
s
struct stk { int top; int len[20]; } *


decompiled_code:
_BOOL8 __fastcall stk_full(_DWORD *a1)
{
return *a1 > 19;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_DWORD *a1)
{
return *a1 > 19;
}

original_code:
int stk_full(stk_t *s) {
    return s->top < 20 ? 0 : 1;
}

canonical_original_code:
int stk_full(struct stk *s) {
    return s->top < 20 ? 0 : 1;
}


decompiled_code:
__int64 __fastcall stk_push(_DWORD *a1, int a2)
{
_BOOL4 v2; // er8
__int64 result; // rax
__int64 v4; // rax

v2 = stk_full(a1);
result = 0LL;
if ( !v2 )
{
v4 = (int)*a1;
*a1 = v4 + 1;
a1[v4 + 1] = a2;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, int a2)
{
_BOOL4 v2; // er8
__int64 result; // rax
__int64 v4; // rax

v2 = func2(a1);
result = 0LL;
if ( !v2 )
{
v4 = (int)*a1;
*a1 = v4 + 1;
a1[v4 + 1] = a2;
result = 1LL;
}
return result;
}

original_code:
int stk_push(stk_t *s, int l) {
    if (stk_full(s)) return 0;
    s->len[s->top++] = l;
    return 1;
}

canonical_original_code:
int stk_push(struct stk *s, int l) {
    if (stk_full(s)) return 0;
    s->len[s->top++] = l;
    return 1;
}

variable_types: l int


decompiled_code:
__int64 __fastcall stk_pop(int *a1)
{
_BOOL4 v1; // er8
__int64 result; // rax
int v3; // eax

v1 = stk_empty(a1);
result = 0LL;
if ( !v1 )
{
v3 = *a1 - 1;
*a1 = v3;
result = (unsigned int)a1[v3 + 1];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1)
{
_BOOL4 v1; // er8
__int64 result; // rax
int v3; // eax

v1 = func1(a1);
result = 0LL;
if ( !v1 )
{
v3 = *a1 - 1;
*a1 = v3;
result = (unsigned int)a1[v3 + 1];
}
return result;
}

original_code:
int stk_pop(stk_t *s) {
    if (stk_empty(s)) return 0;
    return s->len[--s->top];
}

canonical_original_code:
int stk_pop(struct stk *s) {
    if (stk_empty(s)) return 0;
    return s->len[--s->top];
}


decompiled_code:
__int64 __fastcall mmseg_match_rec(_DWORD *a1, const char *a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5; // er9

result = strlen(a2);
if ( (int)result > 1 )
{
stk_clear(a1);
stk_push(a1, 2);
do
{
result = trie_match(a3, a2, v5);
if ( !(_DWORD)result )
break;
stk_push(a1, result);
result = stk_full(a1);
}
while ( !(_DWORD)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, const char *a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5; // er9

result = strlen(a2);
if ( (int)result > 1 )
{
func0(a1);
func3(a1, 2);
do
{
result = trie_match(a3, a2, v5);
if ( !(_DWORD)result )
break;
func3(a1, result);
result = func2(a1);
}
while ( !(_DWORD)result );
}
return result;
}

original_code:
void mmseg_match_rec(stk_t *stack, char *s, trie_t *dict) {
    int pos = charlen;
    int len = (int)strlen(s);
    if (!len) return;
    if (len < charlen) return;
    stk_clear(stack);
    stk_push(stack, pos);
    do {
        pos = trie_match(dict, (unsigned char *)s, pos);
        if (!pos) break;
        stk_push(stack, pos);
    } while (pos && !stk_full(stack));
    return;
}

canonical_original_code:
void mmseg_match_rec(struct stk *stack, char *s, struct trie *dict) {
    int pos = charlen;
    int len = (int)strlen(s);
    if (!len) return;
    if (len < charlen) return;
    stk_clear(stack);
    stk_push(stack, pos);
    do {
        pos = trie_match(dict, (unsigned char *)s, pos);
        if (!pos) break;
        stk_push(stack, pos);
    } while (pos && !stk_full(stack));
    return;
}

variable_types:
stack
struct stk { int top; int len[20]; } *

variable_types: struct trie { int count; struct trie *next[256]; } *

variable_types: pos int

return_type: void


decompiled_code:
__int64 __fastcall mmseg_first(const char *a1, __int64 a2)
{
__int64 v2; // r12
unsigned int v4; // ebx
__int64 v5; // rcx
int v6[24]; // [rsp+0h] [rbp-798h] BYREF
int v7[24]; // [rsp+60h] [rbp-738h] BYREF
int v8[24]; // [rsp+C0h] [rbp-6D8h] BYREF
char v9[1656]; // [rsp+120h] [rbp-678h] BYREF

LODWORD(v2) = strlen(a1);
if ( (_DWORD)v2 )
{
mmseg_match_rec(v6, a1, a2);
mmseg_attr_clear(v9);
if ( stk_empty(v6) )
{
LABEL_10:
LODWORD(v2) = mmseg_attr_choose(v9);
return (unsigned int)v2;
}
LABEL_4:
v2 = (int)stk_pop(v6);
mmseg_match_rec(v7, &a1[v2], a2);
if ( stk_empty(v7) )
return (unsigned int)v2;
while ( 1 )
{
v4 = stk_pop(v7);
mmseg_match_rec(v8, &a1[(int)(v2 + v4)], a2);
if ( stk_empty(v8) )
goto LABEL_7;
do
{
v5 = (unsigned int)stk_pop(v8);
LABEL_7:
mmseg_attr_rec(v9, (unsigned int)v2, v4, v5);
}
while ( !stk_empty(v8) );
if ( stk_empty(v7) )
{
if ( stk_empty(v6) )
goto LABEL_10;
goto LABEL_4;
}
}
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2)
{
__int64 v2; // r12
unsigned int v4; // ebx
__int64 v5; // rcx
int v6[24]; // [rsp+0h] [rbp-798h] BYREF
int v7[24]; // [rsp+60h] [rbp-738h] BYREF
int v8[24]; // [rsp+C0h] [rbp-6D8h] BYREF
char v9[1656]; // [rsp+120h] [rbp-678h] BYREF

LODWORD(v2) = strlen(a1);
if ( (_DWORD)v2 )
{
func5(v6, a1, a2);
mmseg_attr_clear(v9);
if ( func1(v6) )
{
LABEL_10:
LODWORD(v2) = mmseg_attr_choose(v9);
return (unsigned int)v2;
}
LABEL_4:
v2 = (int)func4(v6);
func5(v7, &a1[v2], a2);
if ( func1(v7) )
return (unsigned int)v2;
while ( 1 )
{
v4 = func4(v7);
func5(v8, &a1[(int)(v2 + v4)], a2);
if ( func1(v8) )
goto LABEL_7;
do
{
v5 = (unsigned int)func4(v8);
LABEL_7:
mmseg_attr_rec(v9, (unsigned int)v2, v4, v5);
}
while ( !func1(v8) );
if ( func1(v7) )
{
if ( func1(v6) )
goto LABEL_10;
goto LABEL_4;
}
}
}
return (unsigned int)v2;
}

original_code:
int mmseg_first(char *s, trie_t *dict) {
    gram_attr_t ga;
    stk_t w1, w2, w3;
    int l1, l2, l3;
    int len;
    int pos;
    len = strlen(s);
    if (!len) return 0;
    mmseg_match_rec(&w1, s, dict);
    mmseg_attr_clear(&ga);
    while (!stk_empty(&w1)) {
        l1 = stk_pop(&w1);
        mmseg_match_rec(&w2, &s[l1], dict);
        if (stk_empty(&w2)) return l1;
        while (!stk_empty(&w2)) {
            l2 = stk_pop(&w2);
            mmseg_match_rec(&w3, &s[l1+l2], dict);
            if (stk_empty(&w3)) mmseg_attr_rec(&ga, l1, l2, 0);
            while (!stk_empty(&w3)) {
                l3 = stk_pop(&w3);
                mmseg_attr_rec(&ga, l1, l2, l3);
            }
        }
    }
    pos = mmseg_attr_choose(&ga);
    return pos;
}

canonical_original_code:
int mmseg_first(char *s, struct trie *dict) {
    struct gram_attr ga;
    struct stk w1; struct stk w2; struct stk w3;
    int l1; int l2; int l3;
    int len;
    int pos;
    len = strlen(s);
    if (!len) return 0;
    mmseg_match_rec(&w1, s, dict);
    mmseg_attr_clear(&ga);
    while (!stk_empty(&w1)) {
        l1 = stk_pop(&w1);
        mmseg_match_rec(&w2, &s[l1], dict);
        if (stk_empty(&w2)) return l1;
        while (!stk_empty(&w2)) {
            l2 = stk_pop(&w2);
            mmseg_match_rec(&w3, &s[l1+l2], dict);
            if (stk_empty(&w3)) mmseg_attr_rec(&ga, l1, l2, 0);
            while (!stk_empty(&w3)) {
                l3 = stk_pop(&w3);
                mmseg_attr_rec(&ga, l1, l2, l3);
            }
        }
    }
    pos = mmseg_attr_choose(&ga);
    return pos;
}

variable_types: struct gram_attr { int n; int maxlen; int maxave; int minvar; int first[100]; int len[100]; int ave[100]; int var[100]; }

user_defined_types: struct trie { int count; struct trie *next[256]; }


original_code:
int mmseg_chunk(char *src, char *dst, trie_t *dict) {
    int i = 0;
    int j = 0;
    int k;
    int pos;
    int len;
    if (!src || !dst || !dict) return 1;
    len = (int)strlen(src);
    while (i < len) {
        pos = mmseg_first(&src[i], dict);
        if (!pos) break;
        for (k = i; k < i+pos; k++) dst[j++] = src[k];
        dst[j++] = ' ';
        i += pos;
    }
    dst[j] = '\0';
    return j;
}

canonical_original_code:
int mmseg_chunk(char *src, char *dst, struct trie *dict) {
    int i = 0;
    int j = 0;
    int k;
    int pos;
    int len;
    if (!src || !dst || !dict) return 1;
    len = (int)strlen(src);
    while (i < len) {
        pos = mmseg_first(&src[i], dict);
        if (!pos) break;
        for (k = i; k < i+pos; k++) dst[j++] = src[k];
        dst[j++] = ' ';
        i += pos;
    }
    dst[j] = '\0';
    return j;
}

variable_types:
src
char *

variable_types:
dst
char *

variable_types: i int

variable_types: j int

variable_types: k int


mmseg

original_code:
int mmseg(char *src, char *dst, trie_t *dict) {
    int curr, pos, where, here, len;
    char chunk[2048];
    if (!src || !dst || !dict) return 1;
    len = (int) strlen(src);
    if (!len) {
        dst[0] = '\0';
        return 0;
    }
    curr = 0;
    where = 0;
    here = 0;
    while (src[curr] && curr < len) {
        pos = 0;
        while (!(((src[curr]) & ~0x7f) == 0) && src[curr]
               && pos < 2048 && curr < len) {
            chunk[pos++] = src[curr++];
            chunk[pos++] = src[curr++];
        }
        chunk[pos] = '\0';
        where = mmseg_chunk(chunk, &dst[here], dict);
        here += where;
        while ((((src[curr]) & ~0x7f) == 0) && src[curr] && curr < len)
               dst[here++] = src[curr++];
        if (!((*__ctype_b_loc ())[(int) ((src[curr-1]))] & (unsigned short int) _ISblank)) dst[here++] = ' ';
    }
    dst[here] = '\0';
    return 0;
}

canonical_original_code:
int mmseg(char *src, char *dst, struct trie *dict) {
    int curr; int pos; int where; int here; int len;
    char chunk[2048];
    if (!src || !dst || !dict) return 1;
    len = (int) strlen(src);
    if (!len) {
        dst[0] = '\0';
        return 0;
    }
    curr = 0;
    where = 0;
    here = 0;
    while (src[curr] && curr < len) {
        pos = 0;
        while (!(((src[curr]) & ~0x7f) == 0) && src[curr]
               && pos < 2048 && curr < len) {
            chunk[pos++] = src[curr++];
            chunk[pos++] = src[curr++];
        }
        chunk[pos] = '\0';
        where = mmseg_chunk(chunk, &dst[here], dict);
        here += where;
        while ((((src[curr]) & ~0x7f) == 0) && src[curr] && curr < len)
               dst[here++] = src[curr++];
        if (!((*__ctype_b_loc ())[(int) ((src[curr-1]))] & (unsigned short) _ISblank)) dst[here++] = ' ';
    }
    dst[here] = '\0';
    return 0;
}

variable_types: curr int

variable_types: where int

variable_types: here int

variable_types:
chunk
char [2048]


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(stderr, "Usage: %s -v -d <dict>\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return fprintf(stderr, "Usage: %s -v -d <dict>\n", a1);
}

original_code:
void usage(char *s) {
    fprintf(stderr, "Usage: %s -v -d <dict>\n", s);
}

variable_types:
s
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int v4; // er12
char v5; // al
_BOOL4 v7; // ebx
struct timeval v8; // [rsp+0h] [rbp-D8h] BYREF
struct timeval tv; // [rsp+10h] [rbp-C8h] BYREF
struct timeval v10; // [rsp+20h] [rbp-B8h] BYREF
char v11[168]; // [rsp+30h] [rbp-A8h] BYREF

v3 = "/usr/local/lib/my.big5.dict";
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "vd:");
if ( v5 == -1 )
break;
if ( v5 == 100 )
{
v3 = v11;
_isoc99_sscanf(optarg, "%s", v11);
}
else
{
v4 = 1;
if ( v5 != 118 )
{
usage(*argv);
return v4;
}
}
}
if ( argc - optind > 0 )
{
v4 = 1;
usage(*argv);
}
else
{
gettimeofday(&v8, 0LL);
trie_init(&dict);
if ( (unsigned int)trie_load(v3, &dict) )
{
v4 = 1;
fprintf(stderr, "Load %s dict file failure!\n", v3);
}
else
{
gettimeofday(&tv, 0LL);
do
{
v7 = mygetline();
if ( v7 && !src[0] )
break;
if ( (unsigned int)mmseg(src, dst, &dict) )
fprintf(stderr, "%s seg failure!\n", src);
else
puts(dst);
}
while ( !v7 );
gettimeofday(&v10, 0LL);
trie_destroy(&dict, 0LL, 0LL);
if ( v4 )
{
v4 = 0;
fprintf(stderr, "load dict %ld us\n", tv.tv_usec + 1000000 * (tv.tv_sec - v8.tv_sec) - v8.tv_usec);
fprintf(stderr, "seg %ld us\n", v10.tv_usec + 1000000 * (v10.tv_sec - tv.tv_sec) - tv.tv_usec);
}
}
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int v4; // er12
char v5; // al
_BOOL4 v7; // ebx
struct timeval v8; // [rsp+0h] [rbp-D8h] BYREF
struct timeval tv; // [rsp+10h] [rbp-C8h] BYREF
struct timeval v10; // [rsp+20h] [rbp-B8h] BYREF
char v11[168]; // [rsp+30h] [rbp-A8h] BYREF

v3 = "/usr/local/lib/my.big5.dict";
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "vd:");
if ( v5 == -1 )
break;
if ( v5 == 100 )
{
v3 = v11;
_isoc99_sscanf(optarg, "%s", v11);
}
else
{
v4 = 1;
if ( v5 != 118 )
{
func1(*argv);
return v4;
}
}
}
if ( argc - optind > 0 )
{
v4 = 1;
func1(*argv);
}
else
{
gettimeofday(&v8, 0LL);
trie_init(&dict);
if ( (unsigned int)trie_load(v3, &dict) )
{
v4 = 1;
fprintf(stderr, "Load %s dict file failure!\n", v3);
}
else
{
gettimeofday(&tv, 0LL);
do
{
v7 = func0();
if ( v7 && !src[0] )
break;
if ( (unsigned int)mmseg(src, dst, &dict) )
fprintf(stderr, "%s seg failure!\n", src);
else
puts(dst);
}
while ( !v7 );
gettimeofday(&v10, 0LL);
trie_destroy(&dict, 0LL, 0LL);
if ( v4 )
{
v4 = 0;
fprintf(stderr, "load dict %ld us\n", tv.tv_usec + 1000000 * (tv.tv_sec - v8.tv_sec) - v8.tv_usec);
fprintf(stderr, "seg %ld us\n", v10.tv_usec + 1000000 * (v10.tv_sec - tv.tv_sec) - tv.tv_usec);
}
}
}
return v4;
}

original_code:
int main(int argc, char *argv[]) {
    char ch;
    int ret;
    int verbose = 0;
    char fn[128];
    char *dictfn = "/usr/local""/lib/my.""big5"".dict";
    struct timeval t1, t2, t3;
    while ((ch = getopt(argc, argv, "vd:")) != -1) {
        switch (ch) {
        case 'v':
            verbose = 1;
            break;
        case 'd':
            sscanf(optarg, "%s", fn);
            dictfn = fn;
            break;
        case '?':
        default:
            usage(argv[0]);
            return 1;
        }
    }
    argc -= optind;
    if (argc > 0) {
        usage(argv[0]);
        return 1;
    }
    gettimeofday(&t1, ((void *)0));
    trie_init(&dict);
    if (trie_load(dictfn, &dict)) {
        fprintf(stderr, "Load %s dict file failure!\n", dictfn);
        return 1;
    }
    gettimeofday(&t2, ((void *)0));
    do {
        ret = mygetline();
        if (ret && !strlen(src)) break;
        if (mmseg(src, dst, &dict)) {
            fprintf(stderr, "%s seg failure!\n", src);
        } else {
            printf("%s\n", dst);
        }
    } while (!ret);
    gettimeofday(&t3, ((void *)0));
    trie_destroy(&dict, ((void *)0), 0);
    if (verbose) {
        fprintf(stderr, "load dict %ld us\n", (((t2).tv_sec-(t1).tv_sec)*1000000 + ((t2).tv_usec-(t1).tv_usec)));
        fprintf(stderr, "seg %ld us\n", (((t3).tv_sec-(t2).tv_sec)*1000000 + ((t3).tv_usec-(t2).tv_usec)));
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    char ch;
    int ret;
    int verbose = 0;
    char fn[128];
    char *dictfn = "/usr/local""/lib/my.""big5"".dict";
    struct timeval t1; struct timeval t2; struct timeval t3;
    while ((ch = getopt(argc, argv, "vd:")) != -1) {
        switch (ch) {
        case 'v':
            verbose = 1;
            break;
        case 'd':
            sscanf(optarg, "%s", fn);
            dictfn = fn;
            break;
        case '?':
        default:
            usage(argv[0]);
            return 1;
        }
    }
    argc -= optind;
    if (argc > 0) {
        usage(argv[0]);
        return 1;
    }
    gettimeofday(&t1, ((void *)0));
    trie_init(&dict);
    if (trie_load(dictfn, &dict)) {
        fprintf(stderr, "Load %s dict file failure!\n", dictfn);
        return 1;
    }
    gettimeofday(&t2, ((void *)0));
    do {
        ret = mygetline();
        if (ret && !strlen(src)) break;
        if (mmseg(src, dst, &dict)) {
            fprintf(stderr, "%s seg failure!\n", src);
        } else {
            printf("%s\n", dst);
        }
    } while (!ret);
    gettimeofday(&t3, ((void *)0));
    trie_destroy(&dict, ((void *)0), 0);
    if (verbose) {
        fprintf(stderr, "load dict %ld us\n", (((t2).tv_sec-(t1).tv_sec)*1000000 + ((t2).tv_usec-(t1).tv_usec)));
        fprintf(stderr, "seg %ld us\n", (((t3).tv_sec-(t2).tv_sec)*1000000 + ((t3).tv_usec-(t2).tv_usec)));
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ch char

variable_types: ret int

variable_types: verbose int

variable_types:
fn
char [128]

variable_types:
dictfn
char *

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


decompiled_code:
__int64 __fastcall trie_match(_DWORD *a1, unsigned __int8 *a2, int a3)
{
__int64 v4; // rax
unsigned int v5; // er8
__int64 v6; // rdx

if ( !a1 || !a2 )
return 0;
v4 = *a2;
v5 = 0;
if ( (_BYTE)v4 )
{
v6 = 1LL;
while ( 1 )
{
a1 = *(_DWORD **)&a1[2 * v4 + 2];
v5 = v6;
if ( !a1 )
break;
if ( a3 < (int)v6 && *a1 )
return v5;
v4 = a2[v6++];
if ( !(_BYTE)v4 )
return 0;
}
return 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, unsigned __int8 *a2, int a3)
{
__int64 v4; // rax
unsigned int v5; // er8
__int64 v6; // rdx

if ( !a1 || !a2 )
return 0;
v4 = *a2;
v5 = 0;
if ( (_BYTE)v4 )
{
v6 = 1LL;
while ( 1 )
{
a1 = *(_DWORD **)&a1[2 * v4 + 2];
v5 = v6;
if ( !a1 )
break;
if ( a3 < (int)v6 && *a1 )
return v5;
v4 = a2[v6++];
if ( !(_BYTE)v4 )
return 0;
}
return 0;
}
return v5;
}

original_code:
int trie_match(trie_t *t, unsigned char *s, int bias) {
    int i = 0;
    trie_t *p = t;
    if (!t || !s) return 0;
    if (!s[0]) return 0;
    do {
        p = p->next[s[i++]];
        if (!p) return 0;
        if (i > bias && p->count) return i;
    } while (s[i]);
    return 0;
}

canonical_original_code:
int trie_match(struct trie *t, unsigned char *s, int bias) {
    int i = 0;
    struct trie *p = t;
    if (!t || !s) return 0;
    if (!s[0]) return 0;
    do {
        p = p->next[s[i++]];
        if (!p) return 0;
        if (i > bias && p->count) return i;
    } while (s[i]);
    return 0;
}

variable_types: struct trie { int count; struct trie *next[256]; } *

variable_types:
s
unsigned char *

variable_types: bias int


decompiled_code:
__int64 __fastcall trie_add(unsigned int *a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbp
unsigned __int8 v3; // al
unsigned int *v4; // r12
__int64 v6; // rbx
unsigned int *v7; // rax
unsigned int v8; // er8

if ( !a1 )
return 0LL;
v2 = a2;
if ( !a2 )
return 0LL;
v3 = *a2;
v4 = a1;
if ( !*a2 )
return 0LL;
do
{
while ( 1 )
{
v6 = v3;
v7 = *(unsigned int **)&v4[2 * v3 + 2];
if ( !v7 )
break;
++v2;
v4 = v7;
v3 = *v2;
if ( !*v2 )
goto LABEL_8;
}
++v2;
*(_QWORD *)&v4[2 * v6 + 2] = calloc(1uLL, 0x808uLL);
v4 = *(unsigned int **)&v4[2 * *(v2 - 1) + 2];
v3 = *v2;
}
while ( *v2 );
LABEL_8:
v8 = *v4 + 1;
*v4 = v8;
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbp
unsigned __int8 v3; // al
unsigned int *v4; // r12
__int64 v6; // rbx
unsigned int *v7; // rax
unsigned int v8; // er8

if ( !a1 )
return 0LL;
v2 = a2;
if ( !a2 )
return 0LL;
v3 = *a2;
v4 = a1;
if ( !*a2 )
return 0LL;
do
{
while ( 1 )
{
v6 = v3;
v7 = *(unsigned int **)&v4[2 * v3 + 2];
if ( !v7 )
break;
++v2;
v4 = v7;
v3 = *v2;
if ( !*v2 )
goto LABEL_8;
}
++v2;
*(_QWORD *)&v4[2 * v6 + 2] = calloc(1uLL, 0x808uLL);
v4 = *(unsigned int **)&v4[2 * *(v2 - 1) + 2];
v3 = *v2;
}
while ( *v2 );
LABEL_8:
v8 = *v4 + 1;
*v4 = v8;
return v8;
}

original_code:
int trie_add(trie_t *t, unsigned char *s) {
    int i = 0;
    trie_t *p = t;
    trie_t *node;
    if (!t || !s) return 0;
    if (!s[0]) return 0;
    do {
        if (!p->next[s[i]]) {
            node = (trie_t *) calloc(1, sizeof(trie_t));
            p->next[s[i]] = node;
        }
        p = p->next[s[i++]];
    } while (s[i]);
    p->count++;
    return p->count;
}

canonical_original_code:
int trie_add(struct trie *t, unsigned char *s) {
    int i = 0;
    struct trie *p = t;
    struct trie *node;
    if (!t || !s) return 0;
    if (!s[0]) return 0;
    do {
        if (!p->next[s[i]]) {
            node = (struct trie *) calloc(1, sizeof(trie_t));
            p->next[s[i]] = node;
        }
        p = p->next[s[i++]];
    } while (s[i]);
    p->count++;
    return p->count;
}

variable_types: i int


original_code:
void trie_destroy(trie_t *t, trie_t *parent, int idx) {
    int i;
    if (!t) return;
    for (i=0; i<256; i++)
        trie_destroy(t->next[i], t, i);
    if (!parent) return;
    free(parent->next[idx]);
    parent->next[idx] = ((void *)0);
}

canonical_original_code:
void trie_destroy(struct trie *t, struct trie *parent, int idx) {
    int i;
    if (!t) return;
    for (i=0; i<256; i++)
        trie_destroy(t->next[i], t, i);
    if (!parent) return;
    free(parent->next[idx]);
    parent->next[idx] = ((void *)0);
}

variable_types:
parent
struct trie *

variable_types: idx int


original_code:
void trie_traverse(trie_t *t) {
    static char w[128];
    static int pos = 0;
    int i;
    if (!t) return;
    if (t->count) {
        w[pos] = '\0';
        printf("%s\n", w);
    }
    for (i=0; i<256; i++) {
        w[pos++] = i;
        trie_traverse(t->next[i]);
        pos--;
    }
}

canonical_original_code:
void trie_traverse(struct trie *t) {
    static char w[128];
    static int pos = 0;
    int i;
    if (!t) return;
    if (t->count) {
        w[pos] = '\0';
        printf("%s\n", w);
    }
    for (i=0; i<256; i++) {
        w[pos++] = i;
        trie_traverse(t->next[i]);
        pos--;
    }
}

variable_types:
w
char [128]

variable_types: pos int


original_code:
int mmseg_attr_rec(gram_attr_t *ga, int l1, int l2, int l3) {
    int l, a, v;
    int maxl, maxa, minv;
    if (!ga) return 1;
    if (ga->n >= 100) return 1;
    maxl = ga->maxlen;
    maxa = ga->maxave;
    minv = ga->minvar;
    if (l3) {
        int tmp1, tmp2, tmp3;
        l = (l1+l2+l3)*6;
        a = l/3;
        tmp1 = l1*6-a;
        tmp2 = l2*6-a;
        tmp3 = l3*6-a;
        v = (tmp1*tmp1+tmp2*tmp2+tmp3*tmp3)/3;
    } else {
        int tmp1, tmp2;
        l = (l1+l2)*6;
        a = l/2;
        tmp1 = l1*6-a;
        tmp2 = l2*6-a;
        v = (tmp1*tmp1+tmp2*tmp2)/2;
    }
    maxl = l > maxl ? l : maxl;
    maxa = a > maxa ? a : maxa;
    minv = v < minv ? v : minv;
    if (l == maxl) {
        ga->first[ga->n] = l1;
        ga->len[ga->n] = l;
        ga->ave[ga->n] = a;
        ga->var[ga->n] = v;
        ga->maxlen = maxl;
        ga->maxave = maxa;
        ga->minvar = minv;
        ga->n++;
    }
    return 0;
}

canonical_original_code:
int mmseg_attr_rec(struct gram_attr *ga, int l1, int l2, int l3) {
    int l; int a; int v;
    int maxl; int maxa; int minv;
    if (!ga) return 1;
    if (ga->n >= 100) return 1;
    maxl = ga->maxlen;
    maxa = ga->maxave;
    minv = ga->minvar;
    if (l3) {
        int tmp1; int tmp2; int tmp3;
        l = (l1+l2+l3)*6;
        a = l/3;
        tmp1 = l1*6-a;
        tmp2 = l2*6-a;
        tmp3 = l3*6-a;
        v = (tmp1*tmp1+tmp2*tmp2+tmp3*tmp3)/3;
    } else {
        int tmp1; int tmp2;
        l = (l1+l2)*6;
        a = l/2;
        tmp1 = l1*6-a;
        tmp2 = l2*6-a;
        v = (tmp1*tmp1+tmp2*tmp2)/2;
    }
    maxl = l > maxl ? l : maxl;
    maxa = a > maxa ? a : maxa;
    minv = v < minv ? v : minv;
    if (l == maxl) {
        ga->first[ga->n] = l1;
        ga->len[ga->n] = l;
        ga->ave[ga->n] = a;
        ga->var[ga->n] = v;
        ga->maxlen = maxl;
        ga->maxave = maxa;
        ga->minvar = minv;
        ga->n++;
    }
    return 0;
}

variable_types: struct gram_attr { int n; int maxlen; int maxave; int minvar; int first[100]; int len[100]; int ave[100]; int var[100]; } *

variable_types: l int

variable_types: a int

variable_types: v int

variable_types: maxl int

variable_types: maxa int

variable_types: minv int


original_code:
int mmseg_attr_choose(gram_attr_t *ga) {
    int i, j, k;
    int idxmaxlen[100];
    int idxmaxave[100];
    int minv = 1000000;
    int ii, v;
    j = 0;
    for (i=0; i<ga->n; i++)
        if (ga->len[i] == ga->maxlen)
            idxmaxlen[j++] = i;
    if (j<=1) return ga->first[idxmaxlen[0]];
    k = 0;
    for (i=0; i<j; i++)
        if (ga->ave[idxmaxlen[i]] == ga->maxave)
            idxmaxave[k++] = idxmaxlen[i];
    if (k<=1) return ga->first[idxmaxave[0]];
    ii = 0;
    for (i=0; i<k; i++) {
        v = ga->var[idxmaxave[i]];
        if (v < minv) {
            ii = idxmaxave[i];
            minv = v;
        }
    }
    return ga->first[ii];
}

canonical_original_code:
int mmseg_attr_choose(struct gram_attr *ga) {
    int i; int j; int k;
    int idxmaxlen[100];
    int idxmaxave[100];
    int minv = 1000000;
    int ii; int v;
    j = 0;
    for (i=0; i<ga->n; i++)
        if (ga->len[i] == ga->maxlen)
            idxmaxlen[j++] = i;
    if (j<=1) return ga->first[idxmaxlen[0]];
    k = 0;
    for (i=0; i<j; i++)
        if (ga->ave[idxmaxlen[i]] == ga->maxave)
            idxmaxave[k++] = idxmaxlen[i];
    if (k<=1) return ga->first[idxmaxave[0]];
    ii = 0;
    for (i=0; i<k; i++) {
        v = ga->var[idxmaxave[i]];
        if (v < minv) {
            ii = idxmaxave[i];
            minv = v;
        }
    }
    return ga->first[ii];
}

variable_types: j int

variable_types: k int

variable_types:
idxmaxlen
int [100]

variable_types:
idxmaxave
int [100]

variable_types: ii int

user_defined_types: struct gram_attr { int n; int maxlen; int maxave; int minvar; int first[100]; int len[100]; int ave[100]; int var[100]; }


repo: wangyinfeng/system

decompiled_code:
void __fastcall __noreturn print_usage(int status)
{
bool v1; // zf
FILE *v3; // rdi

v1 = status == 0;
v3 = stderr;
if ( v1 )
v3 = stdout;
fprintf(
v3,
"Usage: %s [ options ]\n"
" -a, --address ADDR Bind to local address (by default, bind\n"
" to all local addresses).\n"
" -h, --help Print this information.\n"
" -m, --module-dir DIR Load modules from specified directory\n"
" (by default, use executable directory).\n"
" -p, --port PORT Bind to specified port.\n"
" -v, --verbose Print verbose messages.\n",
program_name);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int status)
{
bool v1; // zf
FILE *v3; // rdi

v1 = status == 0;
v3 = stderr;
if ( v1 )
v3 = stdout;
fprintf(
v3,
"Usage: %s [ options ]\n"
" -a, --address ADDR Bind to local address (by default, bind\n"
" to all local addresses).\n"
" -h, --help Print this information.\n"
" -m, --module-dir DIR Load modules from specified directory\n"
" (by default, use executable directory).\n"
" -p, --port PORT Bind to specified port.\n"
" -v, --verbose Print verbose messages.\n",
program_name);
exit(status);
}

original_code:
static void print_usage (int is_error)
{
  fprintf (is_error ? stderr : stdout, usage_template, program_name);
  exit (is_error ? 1 : 0);
}

canonical_original_code:
static void print_usage(int is_error)
{
  fprintf (is_error ? stderr : stdout, usage_template, program_name);
  exit (is_error ? 1 : 0);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
unsigned int v4; // er13
unsigned __int16 v5; // r12
int v6; // eax
__int16 v7; // ax
const char *v8; // rdx
const char *v9; // rdx
const char *v10; // rdx
struct hostent *v11; // rax
const char *v12; // rdx
struct stat v14; // [rsp+0h] [rbp-B8h] BYREF

v3 = *argv;
verbose = 0;
program_name = v3;
module_dir = get_self_executable_directory(argc, argv, envp);
if ( !module_dir )
_assert_fail("module_dir != NULL", "main.c", 0x47u, "main");
v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = getopt_long(argc, (char *const *)argv, "a:hm:p:v", &long_options, 0LL);
if ( v6 > 118 )
goto main_cold;
if ( v6 <= 96 )
break;
switch ( v6 )
{
case 'a':
v11 = gethostbyname(optarg);
if ( v11 && (v12 = (const char *)(unsigned int)v11->h_length, (_DWORD)v12) )
v4 = **(_DWORD **)v11->h_addr_list;
else
error((int)optarg, (int)"invalid host name", v12);
continue;
case 'h':
print_usage(0);
case 'm':
if ( access(optarg, 0) )
error((int)optarg, (int)"module directory does not exist", v8);
if ( access(optarg, 5) )
error((int)optarg, (int)"module directory is not accessible", v9);
if ( stat(optarg, &v14) || (v14.st_mode & 0xF000) != 0x4000 )
error((int)optarg, (int)"not a directory", v10);
module_dir = strdup(optarg);
continue;
case 'p':
v7 = strtol(optarg, (char **)&v14, 10);
if ( *(_BYTE *)v14.st_dev )
goto LABEL_26;
v5 = _bswap_16(v7);
break;
case 'v':
verbose = 1;
continue;
default:
goto main_cold;
}
}
if ( v6 != -1 )
{
if ( v6 != 63 )
main_cold:
abort();
LABEL_26:
print_usage(1);
}
if ( optind != argc )
goto LABEL_26;
if ( verbose )
printf("modules will be loaded from %s\n", module_dir);
server_run(v4, v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
unsigned int v4; // er13
unsigned __int16 v5; // r12
int v6; // eax
__int16 v7; // ax
const char *v8; // rdx
const char *v9; // rdx
const char *v10; // rdx
struct hostent *v11; // rax
const char *v12; // rdx
struct stat v14; // [rsp+0h] [rbp-B8h] BYREF

v3 = *argv;
verbose = 0;
program_name = v3;
module_dir = get_self_executable_directory(argc, argv, envp);
if ( !module_dir )
_assert_fail("module_dir != NULL", "main.c", 0x47u, "main");
v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = getopt_long(argc, (char *const *)argv, "a:hm:p:v", &long_options, 0LL);
if ( v6 > 118 )
goto main_cold;
if ( v6 <= 96 )
break;
switch ( v6 )
{
case 'a':
v11 = gethostbyname(optarg);
if ( v11 && (v12 = (const char *)(unsigned int)v11->h_length, (_DWORD)v12) )
v4 = **(_DWORD **)v11->h_addr_list;
else
error((int)optarg, (int)"invalid host name", v12);
continue;
case 'h':
func1(0);
case 'm':
if ( access(optarg, 0) )
error((int)optarg, (int)"module directory does not exist", v8);
if ( access(optarg, 5) )
error((int)optarg, (int)"module directory is not accessible", v9);
if ( stat(optarg, &v14) || (v14.st_mode & 0xF000) != 0x4000 )
error((int)optarg, (int)"not a directory", v10);
module_dir = strdup(optarg);
continue;
case 'p':
v7 = strtol(optarg, (char **)&v14, 10);
if ( *(_BYTE *)v14.st_dev )
goto LABEL_26;
v5 = func0(v7);
break;
case 'v':
verbose = 1;
continue;
default:
goto main_cold;
}
}
if ( v6 != -1 )
{
if ( v6 != 63 )
main_cold:
abort();
LABEL_26:
func1(1);
}
if ( optind != argc )
goto LABEL_26;
if ( verbose )
printf("modules will be loaded from %s\n", module_dir);
server_run(v4, v5);
return 0;
}

original_code:
int main (int argc, char* const argv[])
{
  struct in_addr local_address;
  uint16_t port;
  int next_option;
  program_name = argv[0];
  local_address.s_addr = ((in_addr_t) 0x00000000);
  port = 0;
  verbose = 0;
  module_dir = get_self_executable_directory ();
  ((void) sizeof ((module_dir != ((void *)0)) ? 1 : 0), __extension__ ({ if (module_dir != ((void *)0)) ; else __assert_fail ("module_dir != NULL", "main.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  do {
    next_option =
      getopt_long (argc, argv, short_options, long_options, ((void *)0));
    switch (next_option) {
    case 'a':
      {
 struct hostent* local_host_name;
 local_host_name = gethostbyname (optarg);
 if (local_host_name == ((void *)0) || local_host_name->h_length == 0)
   error (optarg, "invalid host name");
 else
   local_address.s_addr =
     *((int*) (local_host_name->h_addr_list[0]));
      }
      break;
    case 'h':
      print_usage (0);
    case 'm':
      {
 struct stat dir_info;
 if (access (optarg, 0) != 0)
   error (optarg, "module directory does not exist");
 if (access (optarg, 4 | 1) != 0)
   error (optarg, "module directory is not accessible");
 if (stat (optarg, &dir_info) != 0 || !((((dir_info.st_mode)) & 0170000) == (0040000)))
   error (optarg, "not a directory");
 module_dir = strdup (optarg);
      }
      break;
    case 'p':
      {
 long value;
 char* end;
 value = strtol (optarg, &end, 10);
 if (*end != '\0')
   print_usage (1);
 port = (uint16_t) htons (value);
      }
      break;
    case 'v':
      verbose = 1;
      break;
    case '?':
      print_usage (1);
    case -1:
      break;
    default:
      abort ();
    }
  } while (next_option != -1);
  if (optind != argc)
    print_usage (1);
  if (verbose)
    printf ("modules will be loaded from %s\n", module_dir);
  server_run (local_address, port);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  struct in_addr local_address;
  unsigned short port;
  int next_option;
  program_name = argv[0];
  local_address.s_addr = ((unsigned int) 0x00000000);
  port = 0;
  verbose = 0;
  module_dir = get_self_executable_directory ();
  ((void) sizeof ((module_dir != ((void *)0)) ? 1 : 0), __extension__ ({ if (module_dir != ((void *)0)) ; else __assert_fail ("module_dir != NULL", "main.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  do {
    next_option =
      getopt_long (argc, argv, short_options, long_options, ((void *)0));
    switch (next_option) {
    case 'a':
      {
 struct hostent *local_host_name;
 local_host_name = gethostbyname (optarg);
 if (local_host_name == ((void *)0) || local_host_name->h_length == 0)
   error (optarg, "invalid host name");
 else
   local_address.s_addr =
     *((int *) (local_host_name->h_addr_list[0]));
      }
      break;
    case 'h':
      print_usage (0);
    case 'm':
      {
 struct stat dir_info;
 if (access (optarg, 0) != 0)
   error (optarg, "module directory does not exist");
 if (access (optarg, 4 | 1) != 0)
   error (optarg, "module directory is not accessible");
 if (stat (optarg, &dir_info) != 0 || !((((dir_info.st_mode)) & 0170000) == (0040000)))
   error (optarg, "not a directory");
 module_dir = strdup (optarg);
      }
      break;
    case 'p':
      {
 long value;
 char *end;
 value = strtol (optarg, &end, 10);
 if (*end != '\0')
   print_usage (1);
 port = (unsigned short) htons (value);
      }
      break;
    case 'v':
      verbose = 1;
      break;
    case '?':
      print_usage (1);
    case -1:
      break;
    default:
      abort ();
    }
  } while (next_option != -1);
  if (optind != argc)
    print_usage (1);
  if (verbose)
    printf ("modules will be loaded from %s\n", module_dir);
  server_run (local_address, port);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
port
unsigned short

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

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: value long

variable_types:
end
char *

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]; }


decompiled_code:
__int64 __fastcall get_uid_gid(unsigned int a1, __uid_t *a2, __gid_t *a3)
{
__int64 result; // rax
char v5[64]; // [rsp+0h] [rbp-E8h] BYREF
struct stat v6; // [rsp+40h] [rbp-A8h] BYREF

snprintf(v5, 0x40uLL, "/proc/%d", a1);
result = stat(v5, &v6);
if ( (_DWORD)result )
return 1LL;
if ( (v6.st_mode & 0xF000) != 0x4000 )
__assert_fail("S_ISDIR (dir_info.st_mode)", "processes.c", 0x27u, "get_uid_gid");
*a2 = v6.st_uid;
*a3 = v6.st_gid;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, __uid_t *a2, __gid_t *a3)
{
__int64 result; // rax
char v5[64]; // [rsp+0h] [rbp-E8h] BYREF
struct stat v6; // [rsp+40h] [rbp-A8h] BYREF

snprintf(v5, 0x40uLL, "/proc/%d", a1);
result = func13(v5, &v6);
if ( (_DWORD)result )
return 1LL;
if ( (v6.st_mode & 0xF000) != 0x4000 )
__assert_fail("S_ISDIR (dir_info.st_mode)", "processes.c", 0x27u, "get_uid_gid");
*a2 = v6.st_uid;
*a3 = v6.st_gid;
return result;
}

original_code:
static int get_uid_gid (pid_t pid, uid_t* uid, gid_t* gid)
{
  char dir_name[64];
  struct stat dir_info;
  int rval;
  snprintf (dir_name, sizeof (dir_name), "/proc/%d", (int) pid);
  rval = stat (dir_name, &dir_info);
  if (rval != 0)
    return 1;
  ((void) sizeof ((((((dir_info.st_mode)) & 0170000) == (0040000))) ? 1 : 0), __extension__ ({ if (((((dir_info.st_mode)) & 0170000) == (0040000))) ; else __assert_fail ("S_ISDIR (dir_info.st_mode)", "processes.c", 39, __extension__ __PRETTY_FUNCTION__); }));
  *uid = dir_info.st_uid;
  *gid = dir_info.st_gid;
  return 0;
}

canonical_original_code:
static int get_uid_gid(int pid, unsigned int *uid, unsigned int *gid)
{
  char dir_name[64];
  struct stat dir_info;
  int rval;
  snprintf (dir_name, sizeof (dir_name), "/proc/%d", (int) pid);
  rval = stat (dir_name, &dir_info);
  if (rval != 0)
    return 1;
  ((void) sizeof ((((((dir_info.st_mode)) & 0170000) == (0040000))) ? 1 : 0), __extension__ ({ if (((((dir_info.st_mode)) & 0170000) == (0040000))) ; else __assert_fail ("S_ISDIR (dir_info.st_mode)", "processes.c", 39, __extension__ __PRETTY_FUNCTION__); }));
  *uid = dir_info.st_uid;
  *gid = dir_info.st_gid;
  return 0;
}

variable_types: pid int

variable_types:
uid
unsigned int *

variable_types:
gid
unsigned int *

variable_types: rval int

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


decompiled_code:
__int64 __fastcall get_rss(unsigned int a1)
{
int v1; // eax
int v2; // ebp
int v3; // ebx
__int64 result; // rax
int v5; // [rsp+Ch] [rbp-DCh]
char s[64]; // [rsp+10h] [rbp-D8h] BYREF
char buf[152]; // [rsp+50h] [rbp-98h] BYREF

snprintf(s, 0x40uLL, "/proc/%d/statm", a1);
v1 = open(s, 0);
if ( v1 == -1
|| (v2 = v1, v3 = read(v1, buf, 0x7FuLL), close(v2), v3 <= 0)
|| (buf[v3] = 0, (unsigned int)__isoc99_sscanf() != 1) )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)(v5 * getpagesize() / 1024);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
int v1; // eax
int v2; // ebp
int v3; // ebx
__int64 result; // rax
int v5; // [rsp+Ch] [rbp-DCh]
char s[64]; // [rsp+10h] [rbp-D8h] BYREF
char buf[152]; // [rsp+50h] [rbp-98h] BYREF

snprintf(s, 0x40uLL, "/proc/%d/statm", a1);
v1 = open(s, 0);
if ( v1 == -1
|| (v2 = v1, v3 = read(v1, buf, 0x7FuLL), close(v2), v3 <= 0)
|| (buf[v3] = 0, (unsigned int)__isoc99_sscanf() != 1) )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)(v5 * getpagesize() / 1024);
}
return result;
}

original_code:
static int get_rss (pid_t pid)
{
  char file_name[64];
  int fd;
  char mem_info[128];
  int rval;
  int rss;
  snprintf (file_name, sizeof (file_name), "/proc/%d/statm", (int) pid);
  fd = open (file_name, 00);
  if (fd == -1)
    return -1;
  rval = read (fd, mem_info, sizeof (mem_info) - 1);
  close (fd);
  if (rval <= 0)
    return -1;
  mem_info[rval] = '\0';
  rval = sscanf (mem_info, "%*d %d", &rss);
  if (rval != 1)
    return -1;
  return rss * getpagesize () / 1024;
}

canonical_original_code:
static int get_rss(int pid)
{
  char file_name[64];
  int fd;
  char mem_info[128];
  int rval;
  int rss;
  snprintf (file_name, sizeof (file_name), "/proc/%d/statm", (int) pid);
  fd = open (file_name, 00);
  if (fd == -1)
    return -1;
  rval = read (fd, mem_info, sizeof (mem_info) - 1);
  close (fd);
  if (rval <= 0)
    return -1;
  mem_info[rval] = '\0';
  rval = sscanf (mem_info, "%*d %d", &rss);
  if (rval != 1)
    return -1;
  return rss * getpagesize () / 1024;
}

variable_types: fd int

variable_types: rss int


decompiled_code:
// bad sp value at call has been detected, the output may be wrong!
char *__fastcall get_program_name(unsigned int a1)
{
int v1; // eax
int v2; // ebp
int v3; // ebx
char *v4; // rbx
char *v5; // rax
char *v6; // rax
char *result; // rax
size_t n[8]; // [rsp+1h] [rbp-1h] BYREF
char buf[280]; // [rsp+42h] [rbp+40h] BYREF

snprintf((char *)n + 1, 0x40uLL, "/proc/%d/stat", a1);
v1 = open((const char *)n + 1, 0);
if ( v1 == -1 )
return 0LL;
v2 = v1;
v3 = read(v1, buf, 0xFFuLL);
close(v2);
if ( v3 <= 0 )
return 0LL;
buf[v3] = 0;
v4 = strchr(buf, 40);
v5 = strchr(buf, 41);
if ( v5 == 0LL || v4 == 0LL || v4 > v5 )
return 0LL;
v6 = (char *)xmalloc();
result = strncpy(v6, v4 + 1, (size_t)n);
*((_BYTE *)n + (_QWORD)result) = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func8(unsigned int a1)
{
int v1; // eax
int v2; // ebp
int v3; // ebx
char *v4; // rbx
char *v5; // rax
char *v6; // rax
char *result; // rax
size_t n[8]; // [rsp+1h] [rbp-1h] BYREF
char buf[280]; // [rsp+42h] [rbp+40h] BYREF

snprintf((char *)n + 1, 0x40uLL, "/proc/%d/stat", a1);
v1 = open((const char *)n + 1, 0);
if ( v1 == -1 )
return 0LL;
v2 = v1;
v3 = read(v1, buf, 0xFFuLL);
close(v2);
if ( v3 <= 0 )
return 0LL;
buf[v3] = 0;
v4 = strchr(buf, 40);
v5 = strchr(buf, 41);
if ( v5 == 0LL || v4 == 0LL || v4 > v5 )
return 0LL;
v6 = (char *)xmalloc();
result = strncpy(v6, v4 + 1, (size_t)n);
*((_BYTE *)n + (_QWORD)result) = 0;
return result;
}

original_code:
static char* get_program_name (pid_t pid)
{
  char file_name[64];
  char status_info[256];
  int fd;
  int rval;
  char* open_paren;
  char* close_paren;
  char* result;
  snprintf (file_name, sizeof (file_name), "/proc/%d/stat", (int) pid);
  fd = open (file_name, 00);
  if (fd == -1)
    return ((void *)0);
  rval = read (fd, status_info, sizeof (status_info) - 1);
  close (fd);
  if (rval <= 0)
    return ((void *)0);
  status_info[rval] = '\0';
  open_paren = strchr (status_info, '(');
  close_paren = strchr (status_info, ')');
  if (open_paren == ((void *)0)
      || close_paren == ((void *)0)
      || close_paren < open_paren)
    return ((void *)0);
  result = (char*) xmalloc (close_paren - open_paren);
  strncpy (result, open_paren + 1, close_paren - open_paren - 1);
  result[close_paren - open_paren - 1] = '\0';
  return result;
}

canonical_original_code:
static char *get_program_name(int pid)
{
  char file_name[64];
  char status_info[256];
  int fd;
  int rval;
  char *open_paren;
  char *close_paren;
  char *result;
  snprintf (file_name, sizeof (file_name), "/proc/%d/stat", (int) pid);
  fd = open (file_name, 00);
  if (fd == -1)
    return ((void *)0);
  rval = read (fd, status_info, sizeof (status_info) - 1);
  close (fd);
  if (rval <= 0)
    return ((void *)0);
  status_info[rval] = '\0';
  open_paren = strchr (status_info, '(');
  close_paren = strchr (status_info, ')');
  if (open_paren == ((void *)0)
      || close_paren == ((void *)0)
      || close_paren < open_paren)
    return ((void *)0);
  result = (char *) xmalloc (close_paren - open_paren);
  strncpy (result, open_paren + 1, close_paren - open_paren - 1);
  result[close_paren - open_paren - 1] = '\0';
  return result;
}

variable_types:
result
char *


decompiled_code:
__int64 __fastcall get_user_name(__uid_t a1)
{
if ( !getpwuid(a1) )
system_error();
return xstrdup();
}

canonical_decompiled_code:
__int64 __fastcall func9(__uid_t a1)
{
if ( !getpwuid(a1) )
system_error();
return xstrdup();
}

original_code:
static char* get_user_name (uid_t uid)
{
  struct passwd* entry;
  entry = getpwuid (uid);
  if (entry == ((void *)0))
    system_error ("getpwuid");
  return xstrdup (entry->pw_name);
}

canonical_original_code:
static char *get_user_name(unsigned int uid)
{
  struct passwd *entry;
  entry = getpwuid (uid);
  if (entry == ((void *)0))
    system_error ("getpwuid");
  return xstrdup (entry->pw_name);
}

variable_types:
uid
unsigned int

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


decompiled_code:
__int64 __fastcall get_group_name(__gid_t a1)
{
if ( !getgrgid(a1) )
system_error();
return xstrdup();
}

canonical_decompiled_code:
__int64 __fastcall func10(__gid_t a1)
{
if ( !getgrgid(a1) )
system_error();
return xstrdup();
}

original_code:
static char* get_group_name (gid_t gid)
{
  struct group* entry;
  entry = getgrgid (gid);
  if (entry == ((void *)0))
    system_error ("getgrgid");
  return xstrdup (entry->gr_name);
}

canonical_original_code:
static char *get_group_name(unsigned int gid)
{
  struct group *entry;
  entry = getgrgid (gid);
  if (entry == ((void *)0))
    system_error ("getgrgid");
  return xstrdup (entry->gr_name);
}

variable_types:
gid
unsigned int

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


decompiled_code:
char *__fastcall format_process_info(unsigned int a1)
{
unsigned int v1; // eax
__int64 v2; // rbx
char *v3; // rbp
char *v4; // r15
char *v5; // r14
size_t v6; // r13
char *v7; // r13
size_t maxlen; // [rsp+8h] [rbp-50h]
size_t maxlena; // [rsp+8h] [rbp-50h]
__uid_t v11; // [rsp+18h] [rbp-40h] BYREF
__gid_t v12[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( (unsigned int)get_uid_gid(a1, &v11, v12) )
return 0LL;
v1 = get_rss(a1);
v2 = v1;
if ( v1 == -1 )
return 0LL;
v3 = get_program_name(a1);
if ( !v3 )
return 0LL;
v4 = (char *)get_user_name(v11);
v5 = (char *)get_group_name(v12[0]);
maxlen = strlen(v3);
v6 = strlen(v4);
maxlena = strlen(v5) + maxlen + v6 + 128;
v7 = (char *)xmalloc();
snprintf(
v7,
maxlena,
"
%d	<tt>%s</tt>	%s	%s	%d
\n",
a1,
v3,
v4,
v5,
v2);
free(v3);
free(v4);
free(v5);
return v7;
}

canonical_decompiled_code:
char *__fastcall func11(unsigned int a1)
{
unsigned int v1; // eax
__int64 v2; // rbx
char *v3; // rbp
char *v4; // r15
char *v5; // r14
size_t v6; // r13
char *v7; // r13
size_t maxlen; // [rsp+8h] [rbp-50h]
size_t maxlena; // [rsp+8h] [rbp-50h]
__uid_t v11; // [rsp+18h] [rbp-40h] BYREF
__gid_t v12[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( (unsigned int)func6(a1, &v11, v12) )
return 0LL;
v1 = func7(a1);
v2 = v1;
if ( v1 == -1 )
return 0LL;
v3 = func8(a1);
if ( !v3 )
return 0LL;
v4 = (char *)func9(v11);
v5 = (char *)func10(v12[0]);
maxlen = strlen(v3);
v6 = strlen(v4);
maxlena = strlen(v5) + maxlen + v6 + 128;
v7 = (char *)xmalloc();
snprintf(
v7,
maxlena,
"
%d	<tt>%s</tt>	%s	%s	%d
\n",
a1,
v3,
v4,
v5,
v2);
free(v3);
free(v4);
free(v5);
return v7;
}

original_code:
static char* format_process_info (pid_t pid)
{
  int rval;
  uid_t uid;
  gid_t gid;
  char* user_name;
  char* group_name;
  int rss;
  char* program_name;
  size_t result_length;
  char* result;
  rval = get_uid_gid (pid, &uid, &gid);
  if (rval != 0)
    return ((void *)0);
  rss = get_rss (pid);
  if (rss == -1)
    return ((void *)0);
  program_name = get_program_name (pid);
  if (program_name == ((void *)0))
    return ((void *)0);
  user_name = get_user_name (uid);
  group_name = get_group_name (gid);
  result_length = strlen (program_name)
    + strlen (user_name) + strlen (group_name) + 128;
  result = (char*) xmalloc (result_length);
  snprintf (result, result_length,
     "
%d	<tt>%s</tt>	%s	"
     "%s	%d
\n",
     (int) pid, program_name, user_name, group_name, rss);
  free (program_name);
  free (user_name);
  free (group_name);
  return result;
}

canonical_original_code:
static char *format_process_info(int pid)
{
  int rval;
  unsigned int uid;
  unsigned int gid;
  char *user_name;
  char *group_name;
  int rss;
  char *program_name;
  unsigned long result_length;
  char *result;
  rval = get_uid_gid (pid, &uid, &gid);
  if (rval != 0)
    return ((void *)0);
  rss = get_rss (pid);
  if (rss == -1)
    return ((void *)0);
  program_name = get_program_name (pid);
  if (program_name == ((void *)0))
    return ((void *)0);
  user_name = get_user_name (uid);
  group_name = get_group_name (gid);
  result_length = strlen (program_name)
    + strlen (user_name) + strlen (group_name) + 128;
  result = (char *) xmalloc (result_length);
  snprintf (result, result_length,
     "
%d	<tt>%s</tt>	%s	"
     "%s	%d
\n",
     (int) pid, program_name, user_name, group_name, rss);
  free (program_name);
  free (user_name);
  free (group_name);
  return result;
}


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

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

original_code:
void module_close (struct server_module* module)
{
  dlclose (module->handle);
  free ((char*) module->name);
  free (module);
}

canonical_original_code:
void module_close(struct server_module *module)
{
  dlclose (module->handle);
  free ((char *) module->name);
  free (module);
}

variable_types: struct server_module { void *handle; char *name; void (*generate_function)(int); } *


decompiled_code:
__pid_t clean_up_child_process()
{
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

return wait((__WAIT_STATUS)&stat_loc);
}

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

return wait((__WAIT_STATUS)&stat_loc);
}

original_code:
static void clean_up_child_process (int signal_number)
{
  int status;
  wait (&status);
}

canonical_original_code:
static void clean_up_child_process(int signal_number)
{
  int status;
  wait (&status);
}

variable_types: status int


decompiled_code:
ssize_t __fastcall handle_get(int fd, const char *a2)
{
size_t v2; // rax
ssize_t result; // rax
__int64 v4; // r14
char v5[1064]; // [rsp+0h] [rbp-428h] BYREF

if ( *a2 == 47 && !strchr(a2 + 1, 47) && (snprintf(v5, 0x40uLL, "%s.so", a2 + 1), (v4 = module_open(v5)) != 0) )
{
write(fd, "HTTP/1.0 200 OK\nContent-type: text/html\n\n", 0x29uLL);
(*(void (__fastcall **)(_QWORD))(v4 + 16))((unsigned int)fd);
result = module_close(v4);
}
else
{
snprintf(
v5,
0x400uLL,
"HTTP/1.0 404 Not Found\n"
"Content-type: text/html\n"
"\n"
"\n"
" \n"
"
Not Found
\n"
"
The requested URL %s was not found on this server.
\n"
" \n"
"\n",
a2);
v2 = strlen(v5);
result = write(fd, v5, v2);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(int fd, const char *a2)
{
size_t v2; // rax
ssize_t result; // rax
__int64 v4; // r14
char v5[1064]; // [rsp+0h] [rbp-428h] BYREF

if ( *a2 == 47 && !strchr(a2 + 1, 47) && (snprintf(v5, 0x40uLL, "%s.so", a2 + 1), (v4 = module_open(v5)) != 0) )
{
write(fd, "HTTP/1.0 200 OK\nContent-type: text/html\n\n", 0x29uLL);
(*(void (__fastcall **)(_QWORD))(v4 + 16))((unsigned int)fd);
result = module_close(v4);
}
else
{
snprintf(
v5,
0x400uLL,
"HTTP/1.0 404 Not Found\n"
"Content-type: text/html\n"
"\n"
"\n"
" \n"
"
Not Found
\n"
"
The requested URL %s was not found on this server.
\n"
" \n"
"\n",
a2);
v2 = strlen(v5);
result = write(fd, v5, v2);
}
return result;
}

original_code:
static void handle_get (int connection_fd, const char* page)
{
  struct server_module* module = ((void *)0);
  if (*page == '/' && strchr (page + 1, '/') == ((void *)0)) {
    char module_file_name[64];
    snprintf (module_file_name, sizeof (module_file_name),
       "%s.so", page + 1);
    module = module_open (module_file_name);
  }
  if (module == ((void *)0)) {
    char response[1024];
    snprintf (response, sizeof (response), not_found_response_template, page);
    write (connection_fd, response, strlen (response));
  }
  else {
    write (connection_fd, ok_response, strlen (ok_response));
    (*module->generate_function) (connection_fd);
    module_close (module);
  }
}

canonical_original_code:
static void handle_get(int connection_fd, char *page)
{
  struct server_module *module = ((void *)0);
  if (*page == '/' && strchr (page + 1, '/') == ((void *)0)) {
    char module_file_name[64];
    snprintf (module_file_name, sizeof (module_file_name),
       "%s.so", page + 1);
    module = module_open (module_file_name);
  }
  if (module == ((void *)0)) {
    char response[1024];
    snprintf (response, sizeof (response), not_found_response_template, page);
    write (connection_fd, response, strlen (response));
  }
  else {
    write (connection_fd, ok_response, strlen (ok_response));
    (*module->generate_function) (connection_fd);
    module_close (module);
  }
}

variable_types:
page
char *

variable_types:
response
char [1024]

user_defined_types: struct server_module { void *handle; char *name; void (*generate_function)(int); }


decompiled_code:
int __fastcall handle_connection(int fd)
{
ssize_t v1; // rax
ssize_t v2; // rbx
size_t v3; // rax
char v5[256]; // [rsp+0h] [rbp-818h] BYREF
char v6[256]; // [rsp+100h] [rbp-718h] BYREF
char v7[256]; // [rsp+200h] [rbp-618h] BYREF
char s1[256]; // [rsp+300h] [rbp-518h] BYREF
char s[1048]; // [rsp+400h] [rbp-418h] BYREF

v1 = read(fd, v5, 0xFFuLL);
if ( v1 > 0 )
{
v5[v1] = 0;
v2 = v1;
_isoc99_sscanf(v5, "%s %s %s", v6, v7, s1);
while ( !strstr(v5, "\r\n\r\n") )
v2 = read(fd, v5, 0x100uLL);
if ( v2 == -1 )
{
LODWORD(v1) = close(fd);
}
else if ( !strcmp(s1, "HTTP/1.0") || !strcmp(s1, "HTTP/1.1") )
{
if ( !strcmp(v6, "GET") )
{
LODWORD(v1) = handle_get(fd, v7);
}
else
{
snprintf(
s,
0x400uLL,
"HTTP/1.0 501 Method Not Implemented\n"
"Content-type: text/html\n"
"\n"
"\n"
" \n"
"
Method Not Implemented
\n"
"
The method %s is not implemented by this server.
\n"
" \n"
"\n",
v6);
v3 = strlen(s);
LODWORD(v1) = write(fd, s, v3);
}
}
else
{
LODWORD(v1) = write(
fd,
"HTTP/1.0 400 Bad Request\n"
"Content-type: text/html\n"
"\n"
"\n"
" \n"
"
Bad Request
\n"
"
This server did not understand your request.
\n"
" \n"
"\n",
8uLL);
}
}
else if ( v1 )
{
LODWORD(v1) = system_error("read");
}
return v1;
}

canonical_decompiled_code:
int __fastcall func3(int fd)
{
ssize_t v1; // rax
ssize_t v2; // rbx
size_t v3; // rax
char v5[256]; // [rsp+0h] [rbp-818h] BYREF
char v6[256]; // [rsp+100h] [rbp-718h] BYREF
char v7[256]; // [rsp+200h] [rbp-618h] BYREF
char s1[256]; // [rsp+300h] [rbp-518h] BYREF
char s[1048]; // [rsp+400h] [rbp-418h] BYREF

v1 = read(fd, v5, 0xFFuLL);
if ( v1 > 0 )
{
v5[v1] = 0;
v2 = v1;
_isoc99_sscanf(v5, "%s %s %s", v6, v7, s1);
while ( !strstr(v5, "\r\n\r\n") )
v2 = read(fd, v5, 0x100uLL);
if ( v2 == -1 )
{
LODWORD(v1) = close(fd);
}
else if ( !strcmp(s1, "HTTP/1.0") || !strcmp(s1, "HTTP/1.1") )
{
if ( !strcmp(v6, "GET") )
{
LODWORD(v1) = func2(fd, v7);
}
else
{
snprintf(
s,
0x400uLL,
"HTTP/1.0 501 Method Not Implemented\n"
"Content-type: text/html\n"
"\n"
"\n"
" \n"
"
Method Not Implemented
\n"
"
The method %s is not implemented by this server.
\n"
" \n"
"\n",
v6);
v3 = strlen(s);
LODWORD(v1) = write(fd, s, v3);
}
}
else
{
LODWORD(v1) = write(
fd,
"HTTP/1.0 400 Bad Request\n"
"Content-type: text/html\n"
"\n"
"\n"
" \n"
"
Bad Request
\n"
"
This server did not understand your request.
\n"
" \n"
"\n",
8uLL);
}
}
else if ( v1 )
{
LODWORD(v1) = system_error("read");
}
return v1;
}

original_code:
static void handle_connection (int connection_fd)
{
  char buffer[256];
  ssize_t bytes_read;
  bytes_read = read (connection_fd, buffer, sizeof (buffer) - 1);
  if (bytes_read > 0) {
    char method[sizeof (buffer)];
    char url[sizeof (buffer)];
    char protocol[sizeof (buffer)];
    buffer[bytes_read] = '\0';
    sscanf (buffer, "%s %s %s", method, url, protocol);
    while (strstr (buffer, "\r\n\r\n") == ((void *)0))
      bytes_read = read (connection_fd, buffer, sizeof (buffer));
    if (bytes_read == -1) {
      close (connection_fd);
      return;
    }
    if (strcmp (protocol, "HTTP/1.0") && strcmp (protocol, "HTTP/1.1")) {
      write (connection_fd, bad_request_response,
      sizeof (bad_request_response));
    }
    else if (strcmp (method, "GET")) {
      char response[1024];
      snprintf (response, sizeof (response),
  bad_method_response_template, method);
      write (connection_fd, response, strlen (response));
    }
    else
      handle_get (connection_fd, url);
  }
  else if (bytes_read == 0)
    ;
  else
    system_error ("read");
}

canonical_original_code:
static void handle_connection(int connection_fd)
{
  char buffer[256];
  long bytes_read;
  bytes_read = read (connection_fd, buffer, sizeof (buffer) - 1);
  if (bytes_read > 0) {
    char method[-1];
    char url[-1];
    char protocol[-1];
    buffer[bytes_read] = '\0';
    sscanf (buffer, "%s %s %s", method, url, protocol);
    while (strstr (buffer, "\r\n\r\n") == ((void *)0))
      bytes_read = read (connection_fd, buffer, sizeof (buffer));
    if (bytes_read == -1) {
      close (connection_fd);
      return;
    }
    if (strcmp (protocol, "HTTP/1.0") && strcmp (protocol, "HTTP/1.1")) {
      write (connection_fd, bad_request_response,
      sizeof (bad_request_response));
    }
    else if (strcmp (method, "GET")) {
      char response[1024];
      snprintf (response, sizeof (response),
  bad_method_response_template, method);
      write (connection_fd, response, strlen (response));
    }
    else
      handle_get (connection_fd, url);
  }
  else if (bytes_read == 0)
    ;
  else
    system_error ("read");
}

variable_types:
buffer
char [256]

variable_types:
method
char [-1]

variable_types:
url
char [-1]

variable_types:
protocol
char [-1]


decompiled_code:
void __fastcall __noreturn server_run(int a1, __int16 a2)
{
int v2; // er12
int v3; // ebp
char *v4; // rax
__pid_t v5; // eax
unsigned __int16 v6; // bx
char *v7; // rax
socklen_t addr_len; // [rsp+8h] [rbp-E0h] BYREF
socklen_t len; // [rsp+Ch] [rbp-DCh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-D8h] BYREF
struct sockaddr v11; // [rsp+20h] [rbp-C8h] BYREF
struct sigaction v12; // [rsp+30h] [rbp-B8h] BYREF

v12.sa_handler = (__sighandler_t)clean_up_child_process;
memset(&v12.sa_mask, 0, 0x90uLL);
sigaction(17, &v12, 0LL);
v2 = socket(2, 1, 0);
if ( v2 == -1 )
system_error("socket");
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = a2;
*(_DWORD *)&addr.sa_data[2] = a1;
if ( bind(v2, &addr, 0x10u) )
system_error("bind");
if ( listen(v2, 10) )
system_error("listen");
if ( verbose )
{
*(_DWORD *)&v11.sa_family = 16;
if ( getsockname(v2, &addr, (socklen_t *)&v11.sa_family) )
_assert_fail("rval == 0", "server.c", 0xE6u, "server_run");
v6 = _bswap_16(*(__int16 *)addr.sa_data);
v7 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("server listening on %s:%d\n", v7, v6);
}
while ( 1 )
{
addr_len = 16;
v3 = accept(v2, &v11, &addr_len);
if ( v3 != -1 )
goto LABEL_9;
if ( *_errno_location() != 4 )
{
system_error("accept");
LABEL_9:
if ( verbose )
{
len = 16;
if ( getpeername(v3, &addr, &len) )
_assert_fail("rval == 0", "server.c", 0x10Bu, "server_run");
v4 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("connection accepted from %s\n", v4);
}
v5 = fork();
if ( !v5 )
{
close(0);
close(1);
close(v2);
handle_connection(v3);
close(v3);
exit(0);
}
if ( v5 <= 0 )
system_error("fork");
else
close(v3);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func4(int a1, __int16 a2)
{
int v2; // er12
int v3; // ebp
char *v4; // rax
__pid_t v5; // eax
unsigned __int16 v6; // bx
char *v7; // rax
socklen_t addr_len; // [rsp+8h] [rbp-E0h] BYREF
socklen_t len; // [rsp+Ch] [rbp-DCh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-D8h] BYREF
struct sockaddr v11; // [rsp+20h] [rbp-C8h] BYREF
struct sigaction v12; // [rsp+30h] [rbp-B8h] BYREF

v12.sa_handler = (__sighandler_t)clean_up_child_process;
memset(&v12.sa_mask, 0, 0x90uLL);
sigaction(17, &v12, 0LL);
v2 = socket(2, 1, 0);
if ( v2 == -1 )
system_error("socket");
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = a2;
*(_DWORD *)&addr.sa_data[2] = a1;
if ( bind(v2, &addr, 0x10u) )
system_error("bind");
if ( listen(v2, 10) )
system_error("listen");
if ( verbose )
{
*(_DWORD *)&v11.sa_family = 16;
if ( getsockname(v2, &addr, (socklen_t *)&v11.sa_family) )
_assert_fail("rval == 0", "server.c", 0xE6u, "server_run");
v6 = func1(*(__int16 *)addr.sa_data);
v7 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("server listening on %s:%d\n", v7, v6);
}
while ( 1 )
{
addr_len = 16;
v3 = accept(v2, &v11, &addr_len);
if ( v3 != -1 )
goto LABEL_9;
if ( *_errno_location() != 4 )
{
system_error("accept");
LABEL_9:
if ( verbose )
{
len = 16;
if ( getpeername(v3, &addr, &len) )
_assert_fail("rval == 0", "server.c", 0x10Bu, "server_run");
v4 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("connection accepted from %s\n", v4);
}
v5 = fork();
if ( !v5 )
{
close(0);
close(1);
close(v2);
func3(v3);
close(v3);
exit(0);
}
if ( v5 <= 0 )
system_error("fork");
else
close(v3);
}
}
}

original_code:
void server_run (struct in_addr local_address, uint16_t port)
{
  struct sockaddr_in socket_address;
  int rval;
  struct sigaction sigchld_action;
  int server_socket;
  memset (&sigchld_action, 0, sizeof (sigchld_action));
  sigchld_action.__sigaction_handler.sa_handler = &clean_up_child_process;
  sigaction (17, &sigchld_action, ((void *)0));
  server_socket = socket (2, SOCK_STREAM, 0);
  if (server_socket == -1)
    system_error ("socket");
  memset (&socket_address, 0, sizeof (socket_address));
  socket_address.sin_family = 2;
  socket_address.sin_port = port;
  socket_address.sin_addr = local_address;
  rval = bind (server_socket, &socket_address, sizeof (socket_address));
  if (rval != 0)
    system_error ("bind");
  rval = listen (server_socket, 10);
  if (rval != 0)
    system_error ("listen");
  if (verbose) {
    socklen_t address_length;
    address_length = sizeof (socket_address);
    rval = getsockname (server_socket, &socket_address, &address_length);
    ((void) sizeof ((rval == 0) ? 1 : 0), __extension__ ({ if (rval == 0) ; else __assert_fail ("rval == 0", "server.c", 230, __extension__ __PRETTY_FUNCTION__); }));
    printf ("server listening on %s:%d\n",
     inet_ntoa (socket_address.sin_addr),
     (int) ntohs (socket_address.sin_port));
  }
  while (1) {
    struct sockaddr_in remote_address;
    socklen_t address_length;
    int connection;
    pid_t child_pid;
    address_length = sizeof (remote_address);
    connection = accept (server_socket, &remote_address, &address_length);
    if (connection == -1) {
      if ((*__errno_location ()) == 4)
 continue;
      else
 system_error ("accept");
    }
    if (verbose) {
      socklen_t address_length;
      address_length = sizeof (socket_address);
      rval = getpeername (connection, &socket_address, &address_length);
      ((void) sizeof ((rval == 0) ? 1 : 0), __extension__ ({ if (rval == 0) ; else __assert_fail ("rval == 0", "server.c", 267, __extension__ __PRETTY_FUNCTION__); }));
      printf ("connection accepted from %s\n",
       inet_ntoa (socket_address.sin_addr));
    }
    child_pid = fork ();
    if (child_pid == 0) {
      close (0);
      close (1);
      close (server_socket);
      handle_connection (connection);
      close (connection);
      exit (0);
    }
    else if (child_pid > 0) {
      close (connection);
    }
    else
      system_error ("fork");
  }
}

canonical_original_code:
void server_run(struct in_addr local_address, unsigned short port)
{
  struct sockaddr_in socket_address;
  int rval;
  struct sigaction sigchld_action;
  int server_socket;
  memset (&sigchld_action, 0, sizeof (sigchld_action));
  sigchld_action.__sigaction_handler.sa_handler = &clean_up_child_process;
  sigaction (17, &sigchld_action, ((void *)0));
  server_socket = socket (2, SOCK_STREAM, 0);
  if (server_socket == -1)
    system_error ("socket");
  memset (&socket_address, 0, sizeof (socket_address));
  socket_address.sin_family = 2;
  socket_address.sin_port = port;
  socket_address.sin_addr = local_address;
  rval = bind (server_socket, &socket_address, sizeof (socket_address));
  if (rval != 0)
    system_error ("bind");
  rval = listen (server_socket, 10);
  if (rval != 0)
    system_error ("listen");
  if (verbose) {
    unsigned int address_length;
    address_length = sizeof (socket_address);
    rval = getsockname (server_socket, &socket_address, &address_length);
    ((void) sizeof ((rval == 0) ? 1 : 0), __extension__ ({ if (rval == 0) ; else __assert_fail ("rval == 0", "server.c", 230, __extension__ __PRETTY_FUNCTION__); }));
    printf ("server listening on %s:%d\n",
     inet_ntoa (socket_address.sin_addr),
     (int) ntohs (socket_address.sin_port));
  }
  while (1) {
    struct sockaddr_in remote_address;
    unsigned int address_length;
    int connection;
    int child_pid;
    address_length = sizeof (remote_address);
    connection = accept (server_socket, &remote_address, &address_length);
    if (connection == -1) {
      if ((*__errno_location ()) == 4)
 continue;
      else
 system_error ("accept");
    }
    if (verbose) {
      unsigned int address_length;
      address_length = sizeof (socket_address);
      rval = getpeername (connection, &socket_address, &address_length);
      ((void) sizeof ((rval == 0) ? 1 : 0), __extension__ ({ if (rval == 0) ; else __assert_fail ("rval == 0", "server.c", 267, __extension__ __PRETTY_FUNCTION__); }));
      printf ("connection accepted from %s\n",
       inet_ntoa (socket_address.sin_addr));
    }
    child_pid = fork ();
    if (child_pid == 0) {
      close (0);
      close (1);
      close (server_socket);
      handle_connection (connection);
      close (connection);
      exit (0);
    }
    else if (child_pid > 0) {
      close (connection);
    }
    else
      system_error ("fork");
  }
}

variable_types:
port
unsigned short

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

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: connection int

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 sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


xmalloc

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

result = malloc(a1);
if ( !result )
xmalloc_cold();
return result;
}

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

result = malloc(a1);
if ( !result )
func6();
return result;
}

original_code:
void* xmalloc (size_t size)
{
  void* ptr = malloc (size);
  if (ptr == ((void *)0))
    abort ();
  else
    return ptr;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
  void *ptr = malloc (size);
  if (ptr == ((void *)0))
    abort ();
  else
    return ptr;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *


xrealloc

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

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

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

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

original_code:
void* xrealloc (void* ptr, size_t size)
{
  ptr = realloc (ptr, size);
  if (ptr == ((void *)0))
    abort ();
  else
    return ptr;
}

canonical_original_code:
void *xrealloc(void *ptr, unsigned long size)
{
  ptr = realloc (ptr, size);
  if (ptr == ((void *)0))
    abort ();
  else
    return ptr;
}


xstrdup

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

result = strdup(a1);
if ( !result )
xstrdup_cold();
return result;
}

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

result = strdup(a1);
if ( !result )
func8();
return result;
}

original_code:
char* xstrdup (const char* s)
{
  char* copy = strdup (s);
  if (copy == ((void *)0))
    abort ();
  else
    return copy;
}

canonical_original_code:
char *xstrdup(char *s)
{
  char *copy = strdup (s);
  if (copy == ((void *)0))
    abort ();
  else
    return copy;
}

variable_types:
s
char *

variable_types:
copy
char *