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"))))));
}


repo: wangxinalex/compiler

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

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

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

v0 = func1();
v1 = A_IdExp(&unk_451);
v2 = A_IdExp(&unk_44F);
v3 = A_IdExp(&unk_451);
v4 = A_OpExp(v3, 0LL, v2);
v5 = A_AssignStm(&unk_451, v4);
v6 = A_EseqExp(v5, v1);
v7 = A_AssignStm(&unk_451, 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"))));
}

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

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

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


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

v0 = prog_prog();
v1 = A_IdExp(&unk_453);
v2 = A_AssignStm(&unk_451, v1);
return A_CompoundStm(v0, v2);
}

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

v0 = func1();
v1 = A_IdExp(&unk_453);
v2 = A_AssignStm(&unk_451, 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")));
}

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 complex_prog()
{
__int64 v0; // rbx
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax

v0 = prog_prog();
v1 = A_IdExp(&unk_44F);
v2 = A_IdExp(&unk_451);
v3 = A_OpExp(v2, 2LL, v1);
v4 = A_AssignStm(&unk_453, v3);
return A_CompoundStm(v0, v4);
}

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

v0 = func1();
v1 = A_IdExp(&unk_44F);
v2 = A_IdExp(&unk_451);
v3 = A_OpExp(v2, 2LL, v1);
v4 = A_AssignStm(&unk_453, 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"))));
}

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 simple_prog()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rbx
__int64 v10; // rax
__int64 v11; // rax

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

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

v0 = A_NumExp(1LL);
v1 = A_IdExp(&unk_451);
v2 = A_OpExp(v1, 1LL, v0);
v3 = A_LastExpList(v2);
v4 = A_IdExp(&unk_451);
v5 = A_PairExpList(v4, v3);
v6 = A_NumExp(2LL);
v7 = A_IdExp(&unk_451);
v8 = A_OpExp(v7, 0LL, v6);
v9 = A_PairExpList(v8, v5);
v10 = A_IdExp(&unk_451);
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; // rbx
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

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

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

v0 = func5();
v1 = A_NumExp(1LL);
v2 = A_IdExp(&unk_44F);
v3 = A_OpExp(v2, 0LL, v1);
v4 = A_LastExpList(v3);
v5 = A_IdExp(&unk_44F);
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]; } *

return_type: int


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; // edx
__int64 result; // rax
int v4; // eax

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

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

v2 = func2(a1);
result = 0LL;
if ( !v2 )
{
v4 = (*a1)++;
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; // edx
__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; // edx
__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; // ebx

result = strlen(a2);
if ( (int)result > 1 )
{
stk_clear(a1);
stk_push(a1, 2);
v5 = 2;
do
{
result = trie_match(a3, a2, v5);
v5 = result;
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; // ebx

result = strlen(a2);
if ( (int)result > 1 )
{
func0(a1);
func3(a1, 2);
v5 = 2;
do
{
result = trie_match(a3, a2, v5);
v5 = result;
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:
s
char *

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

variable_types: pos int

variable_types: len int

return_type: void


decompiled_code:
__int64 __fastcall mmseg_first(const char *a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v4; // eax
unsigned int v5; // ebx
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

v2 = strlen(a1);
if ( v2 )
{
mmseg_match_rec(v8, a1, a2);
mmseg_attr_clear(v9);
while ( !stk_empty(v8) )
{
v2 = stk_pop(v8);
mmseg_match_rec(v7, &a1[v2], a2);
if ( stk_empty(v7) )
return v2;
do
{
v5 = stk_pop(v7);
mmseg_match_rec(v6, &a1[v2 + v5], a2);
if ( stk_empty(v6) )
mmseg_attr_rec(v9, v2, v5, 0LL);
while ( !stk_empty(v6) )
{
v4 = stk_pop(v6);
mmseg_attr_rec(v9, v2, v5, v4);
}
}
while ( !stk_empty(v7) );
}
v2 = mmseg_attr_choose(v9);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v4; // eax
unsigned int v5; // ebx
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

v2 = strlen(a1);
if ( v2 )
{
func5(v8, a1, a2);
mmseg_attr_clear(v9);
while ( !func1(v8) )
{
v2 = func4(v8);
func5(v7, &a1[v2], a2);
if ( func1(v7) )
return v2;
do
{
v5 = func4(v7);
func5(v6, &a1[v2 + v5], a2);
if ( func1(v6) )
mmseg_attr_rec(v9, v2, v5, 0LL);
while ( !func1(v6) )
{
v4 = func4(v6);
mmseg_attr_rec(v9, v2, v5, v4);
}
}
while ( !func1(v7) );
}
v2 = mmseg_attr_choose(v9);
}
return 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);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int v4; // er12
char v5; // al
int v7; // ebp
_BOOL4 v8; // ebx
struct timeval v9; // [rsp+0h] [rbp-D8h] BYREF
struct timeval v10; // [rsp+10h] [rbp-C8h] BYREF
struct timeval tv; // [rsp+20h] [rbp-B8h] BYREF
char v12[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 )
{
_isoc99_sscanf(optarg, "%s", v12);
v3 = v12;
}
else
{
v4 = 1;
if ( v5 != 118 )
goto LABEL_5;
}
}
if ( argc - optind > 0 )
{
LABEL_5:
usage(*argv);
return 1;
}
gettimeofday(&tv, 0LL);
trie_init(&dict);
v7 = trie_load(v3, &dict);
if ( v7 )
{
fprintf(stderr, "Load %s dict file failure!\n", v3);
v4 = 1;
}
else
{
gettimeofday(&v10, 0LL);
do
{
v8 = mygetline();
if ( v8 && !src[0] )
break;
if ( (unsigned int)mmseg(src, dst, &dict) )
fprintf(stderr, "%s seg failure!\n", src);
else
puts(dst);
}
while ( !v8 );
gettimeofday(&v9, 0LL);
trie_destroy(&dict, 0LL, 0LL);
if ( v4 )
{
fprintf(stderr, "load dict %ld us\n", v10.tv_usec + 1000000 * (v10.tv_sec - tv.tv_sec) - tv.tv_usec);
fprintf(stderr, "seg %ld us\n", v9.tv_usec + 1000000 * (v9.tv_sec - v10.tv_sec) - v10.tv_usec);
v4 = v7;
}
}
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
int v7; // ebp
_BOOL4 v8; // ebx
struct timeval v9; // [rsp+0h] [rbp-D8h] BYREF
struct timeval v10; // [rsp+10h] [rbp-C8h] BYREF
struct timeval tv; // [rsp+20h] [rbp-B8h] BYREF
char v12[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 )
{
_isoc99_sscanf(optarg, "%s", v12);
v3 = v12;
}
else
{
v4 = 1;
if ( v5 != 118 )
goto LABEL_5;
}
}
if ( argc - optind > 0 )
{
LABEL_5:
func1(*argv);
return 1;
}
gettimeofday(&tv, 0LL);
trie_init(&dict);
v7 = trie_load(v3, &dict);
if ( v7 )
{
fprintf(stderr, "Load %s dict file failure!\n", v3);
v4 = 1;
}
else
{
gettimeofday(&v10, 0LL);
do
{
v8 = func0();
if ( v8 && !src[0] )
break;
if ( (unsigned int)mmseg(src, dst, &dict) )
fprintf(stderr, "%s seg failure!\n", src);
else
puts(dst);
}
while ( !v8 );
gettimeofday(&v9, 0LL);
trie_destroy(&dict, 0LL, 0LL);
if ( v4 )
{
fprintf(stderr, "load dict %ld us\n", v10.tv_usec + 1000000 * (v10.tv_sec - tv.tv_sec) - tv.tv_usec);
fprintf(stderr, "seg %ld us\n", v9.tv_usec + 1000000 * (v9.tv_sec - v10.tv_sec) - v10.tv_usec);
v4 = v7;
}
}
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, _BYTE *a2, int a3)
{
unsigned int v3; // er8
__int64 v4; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _BYTE *a2, int a3)
{
unsigned int v3; // er8
__int64 v4; // rax

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

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(_DWORD *a1, _BYTE *a2)
{
_DWORD *v2; // rbp
_BYTE *v3; // rbx
__int64 result; // rax
int v5; // er12

if ( !a1 )
return 0LL;
v2 = a1;
v3 = a2;
if ( !a2 )
return 0LL;
result = 0LL;
if ( *a2 )
{
do
{
if ( !*(_QWORD *)&v2[2 * (unsigned __int8)*v3 + 2] )
{
v5 = (unsigned __int8)*v3;
*(_QWORD *)&v2[2 * v5 + 2] = calloc(1uLL, 0x808uLL);
}
v2 = *(_DWORD **)&v2[2 * (unsigned __int8)*v3++ + 2];
}
while ( *v3 );
result = (unsigned int)(*v2 + 1);
*v2 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, _BYTE *a2)
{
_DWORD *v2; // rbp
_BYTE *v3; // rbx
__int64 result; // rax
int v5; // er12

if ( !a1 )
return 0LL;
v2 = a1;
v3 = a2;
if ( !a2 )
return 0LL;
result = 0LL;
if ( *a2 )
{
do
{
if ( !*(_QWORD *)&v2[2 * (unsigned __int8)*v3 + 2] )
{
v5 = (unsigned __int8)*v3;
*(_QWORD *)&v2[2 * v5 + 2] = calloc(1uLL, 0x808uLL);
}
v2 = *(_DWORD **)&v2[2 * (unsigned __int8)*v3++ + 2];
}
while ( *v3 );
result = (unsigned int)(*v2 + 1);
*v2 = result;
}
return result;
}

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


decompiled_code:
void __fastcall trie_destroy(__int64 a1, __int64 a2, int a3)
{
__int64 i; // rbx

if ( a1 )
{
for ( i = 0LL; i != 256; ++i )
trie_destroy(*(_QWORD *)(a1 + 8 * i + 8), a1, (unsigned int)i);
if ( a2 )
{
free(*(void **)(a2 + 8LL * a3 + 8));
*(_QWORD *)(a2 + 8LL * a3 + 8) = 0LL;
}
}
}

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


decompiled_code:
__int64 __fastcall trie_traverse(_DWORD *a1)
{
__int64 i; // rbx
int v2; // eax
__int64 result; // rax

if ( a1 )
{
if ( *a1 )
{
*(&w_0 + pos_1) = 0;
puts(&w_0);
}
for ( i = 0LL; i != 256; ++i )
{
v2 = pos_1++;
*(&w_0 + v2) = i;
result = trie_traverse(*(_QWORD *)&a1[2 * i + 2]);
--pos_1;
}
}
return result;
}

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 a1)
{
bool v2; // zf
FILE *v3; // rdi

v2 = a1 == 0;
v3 = stderr;
if ( v2 )
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(a1 != 0);
}

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

v2 = a1 == 0;
v3 = stderr;
if ( v2 )
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(a1 != 0);
}

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)
{
unsigned int v3; // er13
unsigned __int16 v4; // r12
struct hostent *v6; // rax
const char *v7; // rdx
const char *v8; // rdx
const char *v9; // rdx
const char *v10; // rdx
int v11; // eax
__int16 v12; // ax
struct stat v13; // [rsp+0h] [rbp-B8h] BYREF

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

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

program_name = *argv;
verbose = 0;
module_dir = get_self_executable_directory(argc, argv, envp);
if ( !module_dir )
_assert_fail("module_dir != NULL", "main.c", 0x47u, "main");
v3 = 0;
v4 = 0;
while ( 2 )
{
v11 = getopt_long(argc, (char *const *)argv, "a:hm:p:v", &long_options, 0LL);
if ( v11 > 118 )
LABEL_31:
abort();
if ( v11 > 96 )
{
switch ( v11 )
{
case 'a':
v6 = gethostbyname(optarg);
if ( v6 && v6->h_length )
v3 = **(_DWORD **)v6->h_addr_list;
else
error((int)optarg, (int)"invalid host name", v7);
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, &v13) || (v13.st_mode & 0xF000) != 0x4000 )
error((int)optarg, (int)"not a directory", v10);
module_dir = strdup(optarg);
continue;
case 'p':
v12 = strtol(optarg, (char **)&v13, 10);
if ( *(_BYTE *)v13.st_dev )
func1(1);
v4 = func0(v12);
continue;
case 'v':
verbose = 1;
continue;
default:
goto LABEL_31;
}
}
break;
}
if ( v11 != -1 )
{
if ( v11 == 63 )
func1(1);
goto LABEL_31;
}
if ( optind != argc )
func1(1);
if ( verbose )
printf("modules will be loaded from %s\n", module_dir);
server_run(v3, v4);
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
struct stat v5; // [rsp+0h] [rbp-E8h] BYREF
char s[88]; // [rsp+90h] [rbp-58h] BYREF

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

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

snprintf(s, 0x40uLL, "/proc/%d", a1);
result = func13(s, &v5);
if ( (_DWORD)result )
return 1LL;
if ( (v5.st_mode & 0xF000) != 0x4000 )
__assert_fail("S_ISDIR (dir_info.st_mode)", "processes.c", 0x27u, "get_uid_gid");
*a2 = v5.st_uid;
*a3 = v5.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
unsigned int v2; // ebx
int v3; // ebp
int v5; // [rsp+Ch] [rbp-DCh]
char buf[128]; // [rsp+10h] [rbp-D8h] BYREF
char s[88]; // [rsp+90h] [rbp-58h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
int v1; // eax
unsigned int v2; // ebx
int v3; // ebp
int v5; // [rsp+Ch] [rbp-DCh]
char buf[128]; // [rsp+10h] [rbp-D8h] BYREF
char s[88]; // [rsp+90h] [rbp-58h] BYREF

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

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:
char *__fastcall get_program_name(unsigned int a1)
{
int v1; // eax
int v2; // ebx
int v3; // ebp
char *v4; // rbp
char *v5; // rax
signed __int64 v6; // rbx
char *v7; // r12
char v9[256]; // [rsp+0h] [rbp-158h] BYREF
char s[88]; // [rsp+100h] [rbp-58h] BYREF

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

canonical_decompiled_code:
char *__fastcall func8(unsigned int a1)
{
int v1; // eax
int v2; // ebx
int v3; // ebp
char *v4; // rbp
char *v5; // rax
signed __int64 v6; // rbx
char *v7; // r12
char v9[256]; // [rsp+0h] [rbp-158h] BYREF
char s[88]; // [rsp+100h] [rbp-58h] BYREF

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

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 *

return_type: 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)
{
char *v1; // rbp
unsigned int v2; // eax
__int64 v3; // r13
char *v4; // r12
const char *v5; // rbp
char *v6; // r14
size_t v7; // r15
size_t v8; // rbp
size_t v9; // r15
char *ptr; // [rsp+8h] [rbp-50h]
__gid_t v12; // [rsp+18h] [rbp-40h] BYREF
__uid_t v13[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

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

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

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

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; // r12
char v5[1048]; // [rsp+0h] [rbp-418h] 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; // r12
char v5[1048]; // [rsp+0h] [rbp-418h] 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 s1[256]; // [rsp+200h] [rbp-618h] BYREF
char s[1024]; // [rsp+300h] [rbp-518h] BYREF
char buf[280]; // [rsp+700h] [rbp-118h] BYREF

v1 = read(fd, buf, 0xFFuLL);
if ( v1 > 0 )
{
v2 = v1;
buf[v1] = 0;
_isoc99_sscanf(buf, "%s %s %s", v5, v6, s1);
while ( !strstr(buf, "\r\n\r\n") )
v2 = read(fd, buf, 0x100uLL);
if ( v2 == -1 )
{
LODWORD(v1) = close(fd);
}
else if ( !strcmp(s1, "HTTP/1.0") || !strcmp(s1, "HTTP/1.1") )
{
if ( !strcmp(v5, "GET") )
{
LODWORD(v1) = handle_get(fd, v6);
}
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",
v5);
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 s1[256]; // [rsp+200h] [rbp-618h] BYREF
char s[1024]; // [rsp+300h] [rbp-518h] BYREF
char buf[280]; // [rsp+700h] [rbp-118h] BYREF

v1 = read(fd, buf, 0xFFuLL);
if ( v1 > 0 )
{
v2 = v1;
buf[v1] = 0;
_isoc99_sscanf(buf, "%s %s %s", v5, v6, s1);
while ( !strstr(buf, "\r\n\r\n") )
v2 = read(fd, buf, 0x100uLL);
if ( v2 == -1 )
{
LODWORD(v1) = close(fd);
}
else if ( !strcmp(s1, "HTTP/1.0") || !strcmp(s1, "HTTP/1.1") )
{
if ( !strcmp(v5, "GET") )
{
LODWORD(v1) = func2(fd, v6);
}
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",
v5);
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; // ebp
unsigned __int16 v3; // bx
char *v4; // rax
__pid_t v5; // eax
int v6; // ebx
char *v7; // rax
socklen_t addr_len; // [rsp+8h] [rbp-E0h] BYREF
socklen_t v9; // [rsp+Ch] [rbp-DCh] BYREF
struct sockaddr len; // [rsp+10h] [rbp-D8h] BYREF
struct sigaction v11; // [rsp+20h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+C0h] [rbp-28h] BYREF

memset(&v11.sa_mask, 0, 0x90uLL);
v11.sa_handler = (__sighandler_t)clean_up_child_process;
sigaction(17, &v11, 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 *)&len.sa_family = 16;
if ( getsockname(v2, &addr, (socklen_t *)&len.sa_family) )
_assert_fail("rval == 0", "server.c", 0xE6u, "server_run");
v3 = _bswap_16(*(__int16 *)addr.sa_data);
v4 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("server listening on %s:%d\n", v4, v3);
}
while ( 1 )
{
while ( 1 )
{
addr_len = 16;
v6 = accept(v2, &len, &addr_len);
if ( v6 == -1 )
break;
LABEL_18:
if ( verbose )
{
v9 = 16;
if ( getpeername(v6, &addr, &v9) )
_assert_fail("rval == 0", "server.c", 0x10Bu, "server_run");
v7 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("connection accepted from %s\n", v7);
}
v5 = fork();
if ( !v5 )
{
close(0);
close(1);
close(v2);
handle_connection(v6);
close(v6);
exit(0);
}
if ( v5 <= 0 )
system_error("fork");
else
close(v6);
}
if ( *_errno_location() != 4 )
{
system_error("accept");
goto LABEL_18;
}
}
}

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

memset(&v11.sa_mask, 0, 0x90uLL);
v11.sa_handler = (__sighandler_t)clean_up_child_process;
sigaction(17, &v11, 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 *)&len.sa_family = 16;
if ( getsockname(v2, &addr, (socklen_t *)&len.sa_family) )
_assert_fail("rval == 0", "server.c", 0xE6u, "server_run");
v3 = func1(*(__int16 *)addr.sa_data);
v4 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("server listening on %s:%d\n", v4, v3);
}
while ( 1 )
{
while ( 1 )
{
addr_len = 16;
v6 = accept(v2, &len, &addr_len);
if ( v6 == -1 )
break;
LABEL_18:
if ( verbose )
{
v9 = 16;
if ( getpeername(v6, &addr, &v9) )
_assert_fail("rval == 0", "server.c", 0x10Bu, "server_run");
v7 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("connection accepted from %s\n", v7);
}
v5 = fork();
if ( !v5 )
{
close(0);
close(1);
close(v2);
func3(v6);
close(v6);
exit(0);
}
if ( v5 <= 0 )
system_error("fork");
else
close(v6);
}
if ( *_errno_location() != 4 )
{
system_error("accept");
goto LABEL_18;
}
}
}

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 )
abort();
return result;
}

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

result = malloc(a1);
if ( !result )
abort();
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 *

return_type: void *


xrealloc

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

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

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

result = realloc(a1, a2);
if ( !result )
abort();
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 )
abort();
return result;
}

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

result = strdup(a1);
if ( !result )
abort();
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 *


error

decompiled_code:
void __fastcall __noreturn error(const char *a1, const char *a2)
{
fprintf(stderr, "%s: error: (%s) %s\n", (const char *)program_name, a1, a2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1, const char *a2)
{
fprintf(stderr, "%s: error: (%s) %s\n", (const char *)program_name, a1, a2);
exit(1);
}

original_code:
void error (const char* cause, const char* message)
{
  fprintf (stderr, "%s: error: (%s) %s\n", program_name, cause, message);
  exit (1);
}

canonical_original_code:
void error(char *cause, char *message)
{
  fprintf (stderr, "%s: error: (%s) %s\n", program_name, cause, message);
  exit (1);
}

variable_types:
cause
char *

variable_types:
message
char *


decompiled_code:
void __fastcall __noreturn system_error(const char *a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
error(a1, v2);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(const char *a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
func3(a1, v2);
}

original_code:
void system_error (const char* operation)
{
  error (operation, strerror ((*__errno_location ())));
}

canonical_original_code:
void system_error(char *operation)
{
  error (operation, strerror ((*__errno_location ())));
}

variable_types:
operation
char *


decompiled_code:
char *get_self_executable_directory()
{
int v0; // eax
char *v1; // rax
size_t v2; // rbx
char *v3; // rbp
char *result; // rax
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

v0 = readlink("/proc/self/exe", v5, 0x3FFuLL);
if ( v0 == -1 )
abort();
v5[v0] = 0;
v1 = strrchr(v5, 47);
if ( v1 == v5 || !v1 )
abort();
v2 = v1 - v5;
v3 = (char *)xmalloc(v1 - v5 + 1);
result = strncpy(v3, v5, v2);
v3[v2] = 0;
return result;
}

canonical_decompiled_code:
char *func5()
{
int v0; // eax
char *v1; // rax
size_t v2; // rbx
char *v3; // rbp
char *result; // rax
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

v0 = readlink("/proc/self/exe", v5, 0x3FFuLL);
if ( v0 == -1 )
abort();
v5[v0] = 0;
v1 = strrchr(v5, 47);
if ( v1 == v5 || !v1 )
abort();
v2 = v1 - v5;
v3 = (char *)func0(v1 - v5 + 1);
result = strncpy(v3, v5, v2);
v3[v2] = 0;
return result;
}

original_code:
char* get_self_executable_directory ()
{
  int rval;
  char link_target[1024];
  char* last_slash;
  size_t result_length;
  char* result;
  rval = readlink ("/proc/self/exe", link_target, sizeof (link_target) - 1);
  if (rval == -1)
    abort ();
  else
    link_target[rval] = '\0';
  last_slash = strrchr (link_target, '/');
  if (last_slash == ((void *)0) || last_slash == link_target)
    abort ();
  result_length = last_slash - link_target;
  result = (char*) xmalloc (result_length + 1);
  strncpy (result, link_target, result_length);
  result[result_length] = '\0';
  return result;
}

canonical_original_code:
char *get_self_executable_directory()
{
  int rval;
  char link_target[1024];
  char *last_slash;
  unsigned long result_length;
  char *result;
  rval = readlink ("/proc/self/exe", link_target, sizeof (link_target) - 1);
  if (rval == -1)
    abort ();
  else
    link_target[rval] = '\0';
  last_slash = strrchr (link_target, '/');
  if (last_slash == ((void *)0) || last_slash == link_target)
    abort ();
  result_length = last_slash - link_target;
  result = (char *) xmalloc (result_length + 1);
  strncpy (result, link_target, result_length);
  result[result_length] = '\0';
  return result;
}

variable_types: rval int

variable_types:
result
char *


runMonoAmplifier

repo: war-immo/ladspa

decompiled_code:
float *__fastcall runMonoAmplifier(__int64 a1, float *a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
float *result; // rax
float v5; // xmm1_4

v2 = *(_QWORD *)(a1 + 8);
v3 = *(_QWORD *)(a1 + 16);
result = *(float **)a1;
v5 = **(float **)a1;
if ( a2 )
{
for ( result = 0LL; result != a2; result = (float *)((char *)result + 1) )
*(float *)(v3 + 4LL * (_QWORD)result) = v5 * *(float *)(v2 + 4LL * (_QWORD)result);
}
return result;
}

canonical_decompiled_code:
float *__fastcall func1(__int64 a1, float *a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
float *result; // rax
float v5; // xmm1_4

v2 = *(_QWORD *)(a1 + 8);
v3 = *(_QWORD *)(a1 + 16);
result = *(float **)a1;
v5 = **(float **)a1;
if ( a2 )
{
for ( result = 0LL; result != a2; result = (float *)((char *)result + 1) )
*(float *)(v3 + 4LL * (_QWORD)result) = v5 * *(float *)(v2 + 4LL * (_QWORD)result);
}
return result;
}

original_code:
void
runMonoAmplifier(LADSPA_Handle Instance,
   unsigned long SampleCount) {
  LADSPA_Data * pfInput;
  LADSPA_Data * pfOutput;
  LADSPA_Data fGain;
  Amplifier * psAmplifier;
  unsigned long lSampleIndex;
  psAmplifier = (Amplifier *)Instance;
  pfInput = psAmplifier->m_pfInputBuffer1;
  pfOutput = psAmplifier->m_pfOutputBuffer1;
  fGain = *(psAmplifier->m_pfControlValue);
  for (lSampleIndex = 0; lSampleIndex < SampleCount; lSampleIndex++)
    *(pfOutput++) = *(pfInput++) * fGain;
}

canonical_original_code:
void runMonoAmplifier(void *Instance, unsigned long SampleCount) {
  float *pfInput;
  float *pfOutput;
  float fGain;
  struct Amplifier *psAmplifier;
  unsigned long lSampleIndex;
  psAmplifier = (struct Amplifier *)Instance;
  pfInput = psAmplifier->m_pfInputBuffer1;
  pfOutput = psAmplifier->m_pfOutputBuffer1;
  fGain = *(psAmplifier->m_pfControlValue);
  for (lSampleIndex = 0; lSampleIndex < SampleCount; lSampleIndex++)
    *(pfOutput++) = *(pfInput++) * fGain;
}

variable_types:
Instance
void *

variable_types:
SampleCount
unsigned long

variable_types:
pfInput
float *

variable_types:
pfOutput
float *

variable_types: fGain float

variable_types: struct Amplifier { float *m_pfControlValue; float *m_pfInputBuffer1; float *m_pfOutputBuffer1; float *m_pfInputBuffer2; float *m_pfOutputBuffer2; } *

variable_types:
lSampleIndex
unsigned long


runStereoAmplifier

decompiled_code:
float *__fastcall runStereoAmplifier(__int64 a1, float *a2)
{
float *result; // rax
float v4; // xmm0_4
__int64 v5; // rcx
__int64 v6; // rdi
float *i; // rax
float *v8; // rdx
__int64 v9; // rdi
__int64 v10; // rsi
float *v11; // rcx

result = *(float **)a1;
v4 = **(float **)a1;
v5 = *(_QWORD *)(a1 + 8);
v6 = *(_QWORD *)(a1 + 16);
if ( a2 )
{
for ( i = 0LL; i != a2; i = (float *)((char *)i + 1) )
{
*(float *)(v6 + 4LL * (_QWORD)i) = v4 * *(float *)(v5 + 4LL * (_QWORD)i);
v8 = i;
}
v9 = *(_QWORD *)(a1 + 24);
v10 = *(_QWORD *)(a1 + 32);
result = 0LL;
do
{
*(float *)(v10 + 4LL * (_QWORD)result) = v4 * *(float *)(v9 + 4LL * (_QWORD)result);
v11 = result;
result = (float *)((char *)result + 1);
}
while ( v8 != v11 );
}
return result;
}

canonical_decompiled_code:
float *__fastcall func2(__int64 a1, float *a2)
{
float *result; // rax
float v4; // xmm0_4
__int64 v5; // rcx
__int64 v6; // rdi
float *i; // rax
float *v8; // rdx
__int64 v9; // rdi
__int64 v10; // rsi
float *v11; // rcx

result = *(float **)a1;
v4 = **(float **)a1;
v5 = *(_QWORD *)(a1 + 8);
v6 = *(_QWORD *)(a1 + 16);
if ( a2 )
{
for ( i = 0LL; i != a2; i = (float *)((char *)i + 1) )
{
*(float *)(v6 + 4LL * (_QWORD)i) = v4 * *(float *)(v5 + 4LL * (_QWORD)i);
v8 = i;
}
v9 = *(_QWORD *)(a1 + 24);
v10 = *(_QWORD *)(a1 + 32);
result = 0LL;
do
{
*(float *)(v10 + 4LL * (_QWORD)result) = v4 * *(float *)(v9 + 4LL * (_QWORD)result);
v11 = result;
result = (float *)((char *)result + 1);
}
while ( v8 != v11 );
}
return result;
}

original_code:
void
runStereoAmplifier(LADSPA_Handle Instance,
     unsigned long SampleCount) {
  LADSPA_Data * pfInput;
  LADSPA_Data * pfOutput;
  LADSPA_Data fGain;
  Amplifier * psAmplifier;
  unsigned long lSampleIndex;
  psAmplifier = (Amplifier *)Instance;
  fGain = *(psAmplifier->m_pfControlValue);
  pfInput = psAmplifier->m_pfInputBuffer1;
  pfOutput = psAmplifier->m_pfOutputBuffer1;
  for (lSampleIndex = 0; lSampleIndex < SampleCount; lSampleIndex++)
    *(pfOutput++) = *(pfInput++) * fGain;
  pfInput = psAmplifier->m_pfInputBuffer2;
  pfOutput = psAmplifier->m_pfOutputBuffer2;
  for (lSampleIndex = 0; lSampleIndex < SampleCount; lSampleIndex++)
    *(pfOutput++) = *(pfInput++) * fGain;
}

canonical_original_code:
void runStereoAmplifier(void *Instance, unsigned long SampleCount) {
  float *pfInput;
  float *pfOutput;
  float fGain;
  struct Amplifier *psAmplifier;
  unsigned long lSampleIndex;
  psAmplifier = (struct Amplifier *)Instance;
  fGain = *(psAmplifier->m_pfControlValue);
  pfInput = psAmplifier->m_pfInputBuffer1;
  pfOutput = psAmplifier->m_pfOutputBuffer1;
  for (lSampleIndex = 0; lSampleIndex < SampleCount; lSampleIndex++)
    *(pfOutput++) = *(pfInput++) * fGain;
  pfInput = psAmplifier->m_pfInputBuffer2;
  pfOutput = psAmplifier->m_pfOutputBuffer2;
  for (lSampleIndex = 0; lSampleIndex < SampleCount; lSampleIndex++)
    *(pfOutput++) = *(pfInput++) * fGain;
}

user_defined_types: struct Amplifier { float *m_pfControlValue; float *m_pfInputBuffer1; float *m_pfOutputBuffer1; float *m_pfInputBuffer2; float *m_pfOutputBuffer2; }


instantiateAmplifier

decompiled_code:
void *instantiateAmplifier()
{
return malloc(0x28uLL);
}

canonical_decompiled_code:
void *func3()
{
return malloc(0x28uLL);
}

original_code:
LADSPA_Handle
instantiateAmplifier(const LADSPA_Descriptor * Descriptor,
       unsigned long SampleRate) {
  return malloc(sizeof(Amplifier));
}

canonical_original_code:
void *instantiateAmplifier(struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate) {
  return malloc(sizeof(Amplifier));
}

variable_types: struct _LADSPA_Descriptor { unsigned long UniqueID; char *Label; int Properties; char *Name; char *Maker; char *Copyright; unsigned long PortCount; int *PortDescriptors; char **PortNames; struct _LADSPA_PortRangeHint { int HintDescriptor; float LowerBound; float UpperBound; } *PortRangeHints; void *ImplementationData; void *(*instantiate)(struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate); void (*connect_port)(void *Instance, unsigned long Port, float *DataLocation); void (*activate)(void *Instance); void (*run)(void *Instance, unsigned long SampleCount); void (*run_adding)(void *Instance, unsigned long SampleCount); void (*set_run_adding_gain)(void *Instance, float Gain); void (*deactivate)(void *Instance); void (*cleanup)(void *Instance); } *

variable_types:
SampleRate
unsigned long

user_defined_types: struct _LADSPA_Descriptor { unsigned long UniqueID; char *Label; int Properties; char *Name; char *Maker; char *Copyright; unsigned long PortCount; int *PortDescriptors; char **PortNames; struct _LADSPA_PortRangeHint *PortRangeHints; void *ImplementationData; void *(*instantiate)(struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate); void (*connect_port)(void *Instance, unsigned long Port, float *DataLocation); void (*activate)(void *Instance); void (*run)(void *Instance, unsigned long SampleCount); void (*run_adding)(void *Instance, unsigned long SampleCount); void (*set_run_adding_gain)(void *Instance, float Gain); void (*deactivate)(void *Instance); void (*cleanup)(void *Instance); }


cleanupAmplifier

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

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

original_code:
void
cleanupAmplifier(LADSPA_Handle Instance) {
  free(Instance);
}

canonical_original_code:
void cleanupAmplifier(void *Instance) {
  free(Instance);
}


deleteDescriptor

decompiled_code:
void __fastcall deleteDescriptor(void *ptr)
{
unsigned __int64 v1; // rbx

if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(*((void **)ptr + 7));
if ( *((_QWORD *)ptr + 6) )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 8) + 8 * v1++));
while ( *((_QWORD *)ptr + 6) > v1 );
}
free(*((void **)ptr + 8));
free(*((void **)ptr + 9));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
unsigned __int64 v1; // rbx

if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(*((void **)ptr + 7));
if ( *((_QWORD *)ptr + 6) )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 8) + 8 * v1++));
while ( *((_QWORD *)ptr + 6) > v1 );
}
free(*((void **)ptr + 8));
free(*((void **)ptr + 9));
free(ptr);
}
}

original_code:
void
deleteDescriptor(LADSPA_Descriptor * psDescriptor) {
  unsigned long lIndex;
  if (psDescriptor) {
    free((char *)psDescriptor->Label);
    free((char *)psDescriptor->Name);
    free((char *)psDescriptor->Maker);
    free((char *)psDescriptor->Copyright);
    free((LADSPA_PortDescriptor *)psDescriptor->PortDescriptors);
    for (lIndex = 0; lIndex < psDescriptor->PortCount; lIndex++)
      free((char *)(psDescriptor->PortNames[lIndex]));
    free((char **)psDescriptor->PortNames);
    free((LADSPA_PortRangeHint *)psDescriptor->PortRangeHints);
    free(psDescriptor);
  }
}

canonical_original_code:
void deleteDescriptor(struct _LADSPA_Descriptor *psDescriptor) {
  unsigned long lIndex;
  if (psDescriptor) {
    free((char *)psDescriptor->Label);
    free((char *)psDescriptor->Name);
    free((char *)psDescriptor->Maker);
    free((char *)psDescriptor->Copyright);
    free((int *)psDescriptor->PortDescriptors);
    for (lIndex = 0; lIndex < psDescriptor->PortCount; lIndex++)
      free((char *)(psDescriptor->PortNames[lIndex]));
    free((char **)psDescriptor->PortNames);
    free((struct _LADSPA_PortRangeHint *)psDescriptor->PortRangeHints);
    free(psDescriptor);
  }
}

variable_types:
lIndex
unsigned long

user_defined_types: struct _LADSPA_PortRangeHint { int HintDescriptor; float LowerBound; float UpperBound; }


activateSimpleFilter

decompiled_code:
void __fastcall activateSimpleFilter(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
}

original_code:
void
activateSimpleFilter(LADSPA_Handle Instance) {
  SimpleFilter * psSimpleFilter;
  psSimpleFilter = (SimpleFilter *)Instance;
  psSimpleFilter->m_fLastOutput = 0;
}

canonical_original_code:
void activateSimpleFilter(void *Instance) {
  struct SimpleFilter *psSimpleFilter;
  psSimpleFilter = (struct SimpleFilter *)Instance;
  psSimpleFilter->m_fLastOutput = 0;
}

variable_types: struct SimpleFilter { float m_fSampleRate; float m_fTwoPiOverSampleRate; float m_fLastOutput; float m_fLastCutoff; float m_fAmountOfCurrent; float m_fAmountOfLast; float *m_pfCutoff; float *m_pfInput; float *m_pfOutput; } *


instantiateSimpleFilter

decompiled_code:
float *__fastcall instantiateSimpleFilter(__int64 a1, __int64 a2)
{
float *result; // rax
float v3; // xmm0_4
float v4; // xmm1_4

result = (float *)malloc(0x30uLL);
if ( result )
{
if ( a2 < 0 )
v3 = (float)(a2 & 1 | (unsigned int)((unsigned __int64)a2 >> 1))
+ (float)(a2 & 1 | (unsigned int)((unsigned __int64)a2 >> 1));
else
v3 = (float)(int)a2;
*result = v3;
v4 = 6.283185307179586 / v3;
result[1] = v4;
result[2] = 0.0;
result[3] = 0.0;
result[4] = 0.0;
result[5] = 0.0;
}
return result;
}

canonical_decompiled_code:
float *__fastcall func2(__int64 a1, __int64 a2)
{
float *result; // rax
float v3; // xmm0_4
float v4; // xmm1_4

result = (float *)malloc(0x30uLL);
if ( result )
{
if ( a2 < 0 )
v3 = (float)(a2 & 1 | (unsigned int)((unsigned __int64)a2 >> 1))
+ (float)(a2 & 1 | (unsigned int)((unsigned __int64)a2 >> 1));
else
v3 = (float)(int)a2;
*result = v3;
v4 = 6.283185307179586 / v3;
result[1] = v4;
result[2] = 0.0;
result[3] = 0.0;
result[4] = 0.0;
result[5] = 0.0;
}
return result;
}

original_code:
LADSPA_Handle
instantiateSimpleFilter(const LADSPA_Descriptor * Descriptor,
   unsigned long SampleRate) {
  SimpleFilter * psFilter;
  psFilter = (SimpleFilter *)malloc(sizeof(SimpleFilter));
  if (psFilter) {
    psFilter->m_fSampleRate = (LADSPA_Data)SampleRate;
    psFilter->m_fTwoPiOverSampleRate = (2 * 3.14159265358979323846) / (LADSPA_Data)SampleRate;
    psFilter->m_fLastOutput = 0;
    psFilter->m_fLastCutoff = 0;
    psFilter->m_fAmountOfCurrent = 0;
    psFilter->m_fAmountOfLast = 0;
  }
  return psFilter;
}

canonical_original_code:
void *instantiateSimpleFilter(struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate) {
  struct SimpleFilter *psFilter;
  psFilter = (struct SimpleFilter *)malloc(sizeof(SimpleFilter));
  if (psFilter) {
    psFilter->m_fSampleRate = (float)SampleRate;
    psFilter->m_fTwoPiOverSampleRate = (2 * 3.14159265358979323846) / (float)SampleRate;
    psFilter->m_fLastOutput = 0;
    psFilter->m_fLastCutoff = 0;
    psFilter->m_fAmountOfCurrent = 0;
    psFilter->m_fAmountOfLast = 0;
  }
  return psFilter;
}

user_defined_types: struct SimpleFilter { float m_fSampleRate; float m_fTwoPiOverSampleRate; float m_fLastOutput; float m_fLastCutoff; float m_fAmountOfCurrent; float m_fAmountOfLast; float *m_pfCutoff; float *m_pfInput; float *m_pfOutput; }


runSimpleLowPassFilter

original_code:
void
runSimpleLowPassFilter(LADSPA_Handle Instance,
         unsigned long SampleCount) {
  LADSPA_Data * pfInput;
  LADSPA_Data * pfOutput;
  LADSPA_Data fAmountOfCurrent;
  LADSPA_Data fAmountOfLast;
  LADSPA_Data fComp;
  LADSPA_Data fLastOutput;
  SimpleFilter * psFilter;
  unsigned long lSampleIndex;
  psFilter = (SimpleFilter *)Instance;
  pfInput = psFilter->m_pfInput;
  pfOutput = psFilter->m_pfOutput;
  if (*psFilter->m_pfCutoff !=
      psFilter->m_fLastCutoff) {
    psFilter->m_fLastCutoff = *psFilter->m_pfCutoff;
    if (psFilter->m_fLastCutoff <= 0) {
      psFilter->m_fAmountOfCurrent = psFilter->m_fAmountOfLast = 0;
    }
    else if (psFilter->m_fLastCutoff > psFilter->m_fSampleRate * 0.5) {
      psFilter->m_fAmountOfCurrent = 1;
      psFilter->m_fAmountOfLast = 0;
    }
    else {
      psFilter->m_fAmountOfLast = 0;
      fComp = 2 - cos(psFilter->m_fTwoPiOverSampleRate
        * psFilter->m_fLastCutoff);
      psFilter->m_fAmountOfLast = fComp - (LADSPA_Data)sqrt(fComp * fComp - 1);
      psFilter->m_fAmountOfCurrent = 1 - psFilter->m_fAmountOfLast;
    }
  }
  fAmountOfCurrent = psFilter->m_fAmountOfCurrent;
  fAmountOfLast = psFilter->m_fAmountOfLast;
  fLastOutput = psFilter->m_fLastOutput;
  for (lSampleIndex = 0;
       lSampleIndex < SampleCount;
       lSampleIndex++) {
    *(pfOutput++)
      = fLastOutput
      = (fAmountOfCurrent * *(pfInput++)
  + fAmountOfLast * fLastOutput);
  }
  psFilter->m_fLastOutput = fLastOutput;
}

canonical_original_code:
void runSimpleLowPassFilter(void *Instance, unsigned long SampleCount) {
  float *pfInput;
  float *pfOutput;
  float fAmountOfCurrent;
  float fAmountOfLast;
  float fComp;
  float fLastOutput;
  struct SimpleFilter *psFilter;
  unsigned long lSampleIndex;
  psFilter = (struct SimpleFilter *)Instance;
  pfInput = psFilter->m_pfInput;
  pfOutput = psFilter->m_pfOutput;
  if (*psFilter->m_pfCutoff !=
      psFilter->m_fLastCutoff) {
    psFilter->m_fLastCutoff = *psFilter->m_pfCutoff;
    if (psFilter->m_fLastCutoff <= 0) {
      psFilter->m_fAmountOfCurrent = psFilter->m_fAmountOfLast = 0;
    }
    else if (psFilter->m_fLastCutoff > psFilter->m_fSampleRate * 0.5) {
      psFilter->m_fAmountOfCurrent = 1;
      psFilter->m_fAmountOfLast = 0;
    }
    else {
      psFilter->m_fAmountOfLast = 0;
      fComp = 2 - cos(psFilter->m_fTwoPiOverSampleRate
        * psFilter->m_fLastCutoff);
      psFilter->m_fAmountOfLast = fComp - (float)sqrt(fComp * fComp - 1);
      psFilter->m_fAmountOfCurrent = 1 - psFilter->m_fAmountOfLast;
    }
  }
  fAmountOfCurrent = psFilter->m_fAmountOfCurrent;
  fAmountOfLast = psFilter->m_fAmountOfLast;
  fLastOutput = psFilter->m_fLastOutput;
  for (lSampleIndex = 0;
       lSampleIndex < SampleCount;
       lSampleIndex++) {
    *(pfOutput++)
      = fLastOutput
      = (fAmountOfCurrent * *(pfInput++)
  + fAmountOfLast * fLastOutput);
  }
  psFilter->m_fLastOutput = fLastOutput;
}

variable_types: fAmountOfCurrent float

variable_types: fAmountOfLast float

variable_types: fComp float

variable_types: fLastOutput float