decompiled_code:
__int64 find_free_pos_arc()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = 99LL;
while ( 1 )
{
v1 = v0;
if ( !*((_DWORD *)&arc_pool + v0 + 1400) )
break;
if ( !--v0 )
return (unsigned int)-1;
}
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = 99LL;
while ( 1 )
{
v1 = v0;
if ( !*((_DWORD *)&arc_pool + v0 + 1400) )
break;
if ( !--v0 )
return (unsigned int)-1;
}
return v1;
}

original_code:
int find_free_pos_arc(){
    int i=100 -1;
    while(i>0){
        if(arc_pool.iarc[i] == 0){
            return i;
        }
        --i;
    }
    return -1;
}

canonical_original_code:
int find_free_pos_arc(){
    int i = 100 -1;
    while(i>0){
        if(arc_pool.iarc[i] == 0){
            return i;
        }
        --i;
    }
    return -1;
}


decompiled_code:
__int64 *dispatch_arc()
{
int v0; // ebx
int v1; // eax
__int64 v2; // rsi
__int64 *result; // rax

v0 = arc_pool[750];
if ( v0 > 99 )
{
v_error("arc pool is full!");
result = 0LL;
}
else
{
v1 = find_free_pos_arc();
if ( v1 == -1 )
{
v_error("no space for arc");
result = 0LL;
}
else
{
v2 = 7LL * v1;
LODWORD(arc_pool[v2 + 6]) = v1;
arc_pool[v2 + 3] = 0LL;
arc_pool[v2 + 4] = 0LL;
arc_pool[v2 + 5] = 0LL;
arc_pool[v2 + 2] = 0LL;
arc_pool[v2 + 1] = 0LL;
LODWORD(arc_pool[750]) = v0 + 1;
*((_DWORD *)&arc_pool[700] + v1) = 1;
result = &arc_pool[7 * v1];
}
}
return result;
}

canonical_decompiled_code:
__int64 *func2()
{
int v0; // ebx
int v1; // eax
__int64 v2; // rsi
__int64 *result; // rax

v0 = arc_pool[750];
if ( v0 > 99 )
{
v_error("arc pool is full!");
result = 0LL;
}
else
{
v1 = func1();
if ( v1 == -1 )
{
v_error("no space for arc");
result = 0LL;
}
else
{
v2 = 7LL * v1;
LODWORD(arc_pool[v2 + 6]) = v1;
arc_pool[v2 + 3] = 0LL;
arc_pool[v2 + 4] = 0LL;
arc_pool[v2 + 5] = 0LL;
arc_pool[v2 + 2] = 0LL;
arc_pool[v2 + 1] = 0LL;
LODWORD(arc_pool[750]) = v0 + 1;
*((_DWORD *)&arc_pool[700] + v1) = 1;
result = &arc_pool[7 * v1];
}
}
return result;
}

original_code:
struct arc* dispatch_arc(){
    if(arc_pool.count >= 100){
        v_error("arc pool is full!");
        return ((void *)0);
    }
    int free_pos = find_free_pos_arc();
    if(free_pos == -1){
        v_error("no space for arc");
        return ((void *)0);
    }
    arc_pool.arcs[free_pos].pos = free_pos;
    arc_pool.arcs[free_pos].e = ((void *)0);
    arc_pool.arcs[free_pos].s0 = ((void *)0);
    arc_pool.arcs[free_pos].s1 = ((void *)0);
    arc_pool.arcs[free_pos].next = ((void *)0);
    arc_pool.arcs[free_pos].prev = ((void *)0);
    arc_pool.count++;
    arc_pool.iarc[free_pos] = 1;
    arc_t *free_arc = &arc_pool.arcs[free_pos];
    return free_arc;
}

canonical_original_code:
struct arc *dispatch_arc(){
    if(arc_pool.count >= 100){
        v_error("arc pool is full!");
        return ((void *)0);
    }
    int free_pos = find_free_pos_arc();
    if(free_pos == -1){
        v_error("no space for arc");
        return ((void *)0);
    }
    arc_pool.arcs[free_pos].pos = free_pos;
    arc_pool.arcs[free_pos].e = ((void *)0);
    arc_pool.arcs[free_pos].s0 = ((void *)0);
    arc_pool.arcs[free_pos].s1 = ((void *)0);
    arc_pool.arcs[free_pos].next = ((void *)0);
    arc_pool.arcs[free_pos].prev = ((void *)0);
    arc_pool.count++;
    arc_pool.iarc[free_pos] = 1;
    struct arc *free_arc = &arc_pool.arcs[free_pos];
    return free_arc;
}

variable_types: struct arc { struct point { int x; int y; } p; struct arc *prev; struct event { struct point p; double x; struct arc *a; int valid; } *e; struct seg { struct point start; int done; } *s0; struct seg *s1; int pos; } *

user_defined_types: struct arc { struct point p; struct arc *prev; struct event *e; struct seg *s0; struct seg *s1; int pos; }


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

result = *(int *)(a1 + 48);
*((_DWORD *)&arc_pool[700] + result) = 0;
--LODWORD(arc_pool[750]);
return result;
}

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

result = *(int *)(a1 + 48);
*((_DWORD *)&arc_pool[700] + result) = 0;
--LODWORD(arc_pool[750]);
return result;
}

original_code:
void destory_arc(arc_t *arc){
    int pos = arc->pos;
    arc_pool.iarc[pos] = 0;
    arc_pool.count--;
    return;
}

canonical_original_code:
void destory_arc(struct arc *arc){
    int pos = arc->pos;
    arc_pool.iarc[pos] = 0;
    arc_pool.count--;
    return;
}

variable_types: pos int

return_type: void

user_defined_types: struct event { struct point p; double x; struct arc *a; int valid; }

user_defined_types: struct seg { struct point start; int done; }


decompiled_code:
int init_event_list()
{
unsigned __int64 v0; // rax

*((_QWORD *)&event_list + 451) = 0LL;
*(&event_list + 900) = 0;
v0 = (unsigned int)((_DWORD)&event_list + 3200);
do
{
*(_DWORD *)v0 = 0;
v0 += 4LL;
}
while ( v0 != (_DWORD)&event_list + 3600 );
return puts("init event list successed");
}

canonical_decompiled_code:
int func4()
{
unsigned __int64 v0; // rax

*((_QWORD *)&event_list + 451) = 0LL;
*(&event_list + 900) = 0;
v0 = (unsigned int)((_DWORD)&event_list + 3200);
do
{
*(_DWORD *)v0 = 0;
v0 += 4LL;
}
while ( v0 != (_DWORD)&event_list + 3600 );
return puts("init event list successed");
}

original_code:
void init_event_list(){
    event_list.head = ((void *)0);
    event_list.count = 0;
    int i;
    for(i=0; i<100; i++){
        event_list.i[i] = 0;
    }
    printf("init event list successed\n");
}

variable_types: i int


decompiled_code:
__int64 find_free_pos_e_list()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = 99LL;
while ( 1 )
{
v1 = v0;
if ( !event_list[v0 + 800] )
break;
if ( !--v0 )
return (unsigned int)-1;
}
return v1;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = 99LL;
while ( 1 )
{
v1 = v0;
if ( !event_list[v0 + 800] )
break;
if ( !--v0 )
return (unsigned int)-1;
}
return v1;
}

original_code:
int find_free_pos_e_list(){
    int i=100 -1;
    while(i>0){
        if(event_list.i[i] == 0){
            return i;
        }
        --i;
    }
    return -1;
}

canonical_original_code:
int find_free_pos_e_list(){
    int i = 100 -1;
    while(i>0){
        if(event_list.i[i] == 0){
            return i;
        }
        --i;
    }
    return -1;
}

return_type: int


decompiled_code:
int *dispatch_event()
{
int v0; // ebx
int v1; // eax
int *result; // rax

v0 = event_list[900];
if ( v0 > 99 )
{
v_error("arc pool is full!");
result = 0LL;
}
else
{
v1 = find_free_pos_e_list();
if ( v1 == -1 )
{
v_error("no space for event");
result = 0LL;
}
else
{
event_list[v1 + 800] = 1;
event_list[900] = v0 + 1;
result = &event_list[8 * v1];
}
}
return result;
}

canonical_decompiled_code:
int *func6()
{
int v0; // ebx
int v1; // eax
int *result; // rax

v0 = event_list[900];
if ( v0 > 99 )
{
v_error("arc pool is full!");
result = 0LL;
}
else
{
v1 = func5();
if ( v1 == -1 )
{
v_error("no space for event");
result = 0LL;
}
else
{
event_list[v1 + 800] = 1;
event_list[900] = v0 + 1;
result = &event_list[8 * v1];
}
}
return result;
}

original_code:
struct event* dispatch_event(){
    if(event_list.count >= 100){
        v_error("arc pool is full!");
        return ((void *)0);
    }
    int free_pos = find_free_pos_e_list();
    if(free_pos == -1){
        v_error("no space for event");
        return ((void *)0);
    }
    event_list.i[free_pos] = 1;
    event_list.count++;
    event_t *free_event = &event_list.events[free_pos];
    return free_event;
}

canonical_original_code:
struct event *dispatch_event(){
    if(event_list.count >= 100){
        v_error("arc pool is full!");
        return ((void *)0);
    }
    int free_pos = find_free_pos_e_list();
    if(free_pos == -1){
        v_error("no space for event");
        return ((void *)0);
    }
    event_list.i[free_pos] = 1;
    event_list.count++;
    struct event *free_event = &event_list.events[free_pos];
    return free_event;
}

variable_types: struct event { struct point { int x; int y; } p; double x; struct arc { struct point p; struct arc *prev; struct event *e; struct seg { struct point start; int done; } *s0; struct seg *s1; int pos; } *a; int valid; } *


decompiled_code:
int init_seg_pool()
{
unsigned __int64 v0; // rbx
int result; // eax

seg_pool[600] = 1;
v0 = (unsigned int)((_DWORD)seg_pool + 2000);
do
{
*(_DWORD *)v0 = 0;
result = puts("init seg_pool successed");
v0 += 4LL;
}
while ( v0 != (_DWORD)seg_pool + 2400 );
return result;
}

canonical_decompiled_code:
int func0()
{
unsigned __int64 v0; // rbx
int result; // eax

seg_pool[600] = 1;
v0 = (unsigned int)((_DWORD)seg_pool + 2000);
do
{
*(_DWORD *)v0 = 0;
result = puts("init seg_pool successed");
v0 += 4LL;
}
while ( v0 != (_DWORD)seg_pool + 2400 );
return result;
}

original_code:
void init_seg_pool(){
    seg_pool.segs_count = 1;
    int i=0;
    for(;i<100;++i){
        seg_pool.i[i] = 0;
        printf("init seg_pool successed\n");
    }
}

canonical_original_code:
void init_seg_pool(){
    seg_pool.segs_count = 1;
    int i = 0;
    for(;i<100;++i){
        seg_pool.i[i] = 0;
        printf("init seg_pool successed\n");
    }
}


decompiled_code:
__int64 find_free_segs()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = 99LL;
while ( 1 )
{
v1 = v0;
if ( !seg_pool[v0 + 500] )
break;
if ( --v0 == -1 )
return (unsigned int)-1;
}
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = 99LL;
while ( 1 )
{
v1 = v0;
if ( !seg_pool[v0 + 500] )
break;
if ( --v0 == -1 )
return (unsigned int)-1;
}
return v1;
}

original_code:
int find_free_segs(){
    int i=100 -1;
    while(i>=0){
        if(seg_pool.i[i] == 0){
            return i;
        }
        --i;
    }
    return -1;
}

canonical_original_code:
int find_free_segs(){
    int i = 100 -1;
    while(i>=0){
        if(seg_pool.i[i] == 0){
            return i;
        }
        --i;
    }
    return -1;
}


decompiled_code:
int *dispatch_seg()
{
int v0; // ebx
int v1; // eax
__int64 v2; // rcx
int *v3; // rbx

v0 = seg_pool[600];
if ( v0 > 99 )
{
v_error("seg pool is full!");
v3 = 0LL;
}
else
{
v1 = find_free_segs();
if ( v1 == -1 )
{
v_error("no space for segs");
v3 = 0LL;
}
else
{
seg_pool[v1 + 500] = 1;
seg_pool[600] = v0 + 1;
v2 = 5LL * v1;
seg_pool[v2] = 0;
seg_pool[v2 + 1] = 0;
seg_pool[v2 + 2] = 0;
seg_pool[v2 + 3] = 0;
seg_pool[v2 + 4] = 0;
v3 = &seg_pool[5 * v1];
push_back_seg(v3);
}
}
return v3;
}

canonical_decompiled_code:
int *func2()
{
int v0; // ebx
int v1; // eax
__int64 v2; // rcx
int *v3; // rbx

v0 = seg_pool[600];
if ( v0 > 99 )
{
v_error("seg pool is full!");
v3 = 0LL;
}
else
{
v1 = func1();
if ( v1 == -1 )
{
v_error("no space for segs");
v3 = 0LL;
}
else
{
seg_pool[v1 + 500] = 1;
seg_pool[600] = v0 + 1;
v2 = 5LL * v1;
seg_pool[v2] = 0;
seg_pool[v2 + 1] = 0;
seg_pool[v2 + 2] = 0;
seg_pool[v2 + 3] = 0;
seg_pool[v2 + 4] = 0;
v3 = &seg_pool[5 * v1];
push_back_seg(v3);
}
}
return v3;
}

original_code:
seg_t * dispatch_seg(){
    if(seg_pool.segs_count >= 100){
        v_error("seg pool is full!");
        return ((void *)0);
    }
    int free_pos = find_free_segs();
    if(free_pos == -1){
        v_error("no space for segs");
        return ((void *)0);
    }
    seg_pool.i[free_pos] = 1;
    seg_pool.segs_count++;
    seg_pool.segs[free_pos].start.x = 0;
    seg_pool.segs[free_pos].start.y = 0;
    seg_pool.segs[free_pos].end.x = 0;
    seg_pool.segs[free_pos].end.y = 0;
    seg_pool.segs[free_pos].done = 0;
    seg_t *free_seg = &seg_pool.segs[free_pos];
    push_back_seg(free_seg);
    return free_seg;
}

canonical_original_code:
struct seg *dispatch_seg(){
    if(seg_pool.segs_count >= 100){
        v_error("seg pool is full!");
        return ((void *)0);
    }
    int free_pos = find_free_segs();
    if(free_pos == -1){
        v_error("no space for segs");
        return ((void *)0);
    }
    seg_pool.i[free_pos] = 1;
    seg_pool.segs_count++;
    seg_pool.segs[free_pos].start.x = 0;
    seg_pool.segs[free_pos].start.y = 0;
    seg_pool.segs[free_pos].end.x = 0;
    seg_pool.segs[free_pos].end.y = 0;
    seg_pool.segs[free_pos].done = 0;
    struct seg *free_seg = &seg_pool.segs[free_pos];
    push_back_seg(free_seg);
    return free_seg;
}

variable_types: struct seg { struct point { int x; int y; } start; int done; } *


decompiled_code:
_BOOL8 __fastcall is_point_within_area(_DWORD *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 <= 0x7D0u )
result = a1[1] <= 0x7D0u;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_DWORD *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 <= 0x7D0u )
result = a1[1] <= 0x7D0u;
return result;
}

original_code:
BOOL is_point_within_area(point_t *p){
    if(p->x >= 0 && p->x <= 2000 && p->y >= 0 && p->y <= 2000){
        return 1;
    }else{
        return 0;
    }
}

canonical_original_code:
int is_point_within_area(struct point *p){
    if(p->x >= 0 && p->x <= 2000 && p->y >= 0 && p->y <= 2000){
        return 1;
    }else{
        return 0;
    }
}

variable_types:
p
struct point { int x; int y; } *


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

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = HIDWORD(a1) == HIDWORD(a2);
return result;
}

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

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = HIDWORD(a1) == HIDWORD(a2);
return result;
}

original_code:
BOOL is_points_equal(point_t a, point_t b){
    if(a.x == b.x && a.y == b.y){
        return 1;
    }else{
        return 0;
    }
}

canonical_original_code:
int is_points_equal(struct point a, struct point b){
    if(a.x == b.x && a.y == b.y){
        return 1;
    }else{
        return 0;
    }
}

variable_types:
a
struct point { int x; int y; }

variable_types:
b
struct point


decompiled_code:
void __fastcall add_intersections(__int64 *a1, int *a2, __int64 a3)
{
int v4; // er13
__int64 *v5; // rbp
int i; // ebx

v4 = *a2;
if ( *a2 )
{
v5 = a1;
for ( i = 0; v4 > i; ++i )
{
if ( is_points_equal(*v5++, a3) )
return;
}
a1[v4] = a3;
++*a2;
}
else
{
*a1 = a3;
++*a2;
}
}

original_code:
void add_intersections(point_t * intersections, int *count, point_t p){
    if(*count == 0){
        intersections[*count] = p;
        (*count)++;
        return;
    }
    int i = 0;
    while(i < *count){
        if(is_points_equal( intersections[i++], p)) return;
    }
    intersections[*count] = p;
    (*count)++;
}

canonical_original_code:
void add_intersections(struct point *intersections, int *count, struct point p){
    if(*count == 0){
        intersections[*count] = p;
        (*count)++;
        return;
    }
    int i = 0;
    while(i < *count){
        if(is_points_equal( intersections[i++], p)) return;
    }
    intersections[*count] = p;
    (*count)++;
}

variable_types:
intersections
struct point { int x; int y; } *

variable_types:
count
int *

variable_types:
p
struct point


decompiled_code:
__int64 __fastcall rebuild_seg(_QWORD *a1)
{
__int64 result; // rax
__int64 v2; // r13
__int64 v3; // rbp
__int64 v4; // r12
__int64 v5; // r14
unsigned int v6; // [rsp+4h] [rbp-54h] BYREF
__int64 v7; // [rsp+8h] [rbp-50h] BYREF
__int64 v8; // [rsp+10h] [rbp-48h] BYREF
__int64 v9; // [rsp+18h] [rbp-40h]

if ( !is_point_within_area(a1) || (result = is_point_within_area((_DWORD *)a1 + 2), (_DWORD)result != 1) )
{
v2 = build_point(0LL, 0LL);
v3 = build_point(2000LL, 0LL);
v4 = build_point(2000LL, 2000LL);
v5 = build_point(0LL, 2000LL);
v6 = 0;
if ( (unsigned int)get_seg_intersection(v2, v3, *a1, a1[1], &v7) == 1 )
add_intersections(&v8, (int *)&v6, v7);
if ( (unsigned int)get_seg_intersection(v5, v4, *a1, a1[1], &v7) == 1 )
add_intersections(&v8, (int *)&v6, v7);
if ( (unsigned int)get_seg_intersection(v2, v5, *a1, a1[1], &v7) == 1 )
add_intersections(&v8, (int *)&v6, v7);
if ( (unsigned int)get_seg_intersection(v3, v4, *a1, a1[1], &v7) == 1 )
add_intersections(&v8, (int *)&v6, v7);
result = v6;
if ( v6 )
{
if ( v6 == 2 )
{
*a1 = v8;
result = v9;
a1[1] = v9;
}
else if ( v6 == 1 )
{
if ( !is_point_within_area(a1) )
*a1 = v8;
result = is_point_within_area((_DWORD *)a1 + 2);
if ( !(_DWORD)result )
{
result = v8;
a1[1] = v8;
}
}
}
else
{
*(_DWORD *)a1 = 0;
*((_DWORD *)a1 + 1) = 0;
*((_DWORD *)a1 + 2) = 0;
*((_DWORD *)a1 + 3) = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 result; // rax
__int64 v2; // r13
__int64 v3; // rbp
__int64 v4; // r12
__int64 v5; // r14
unsigned int v6; // [rsp+4h] [rbp-54h] BYREF
__int64 v7; // [rsp+8h] [rbp-50h] BYREF
__int64 v8; // [rsp+10h] [rbp-48h] BYREF
__int64 v9; // [rsp+18h] [rbp-40h]

if ( !func0(a1) || (result = func0((_DWORD *)a1 + 2), (_DWORD)result != 1) )
{
v2 = build_point(0LL, 0LL);
v3 = build_point(2000LL, 0LL);
v4 = build_point(2000LL, 2000LL);
v5 = build_point(0LL, 2000LL);
v6 = 0;
if ( (unsigned int)get_seg_intersection(v2, v3, *a1, a1[1], &v7) == 1 )
func2(&v8, (int *)&v6, v7);
if ( (unsigned int)get_seg_intersection(v5, v4, *a1, a1[1], &v7) == 1 )
func2(&v8, (int *)&v6, v7);
if ( (unsigned int)get_seg_intersection(v2, v5, *a1, a1[1], &v7) == 1 )
func2(&v8, (int *)&v6, v7);
if ( (unsigned int)get_seg_intersection(v3, v4, *a1, a1[1], &v7) == 1 )
func2(&v8, (int *)&v6, v7);
result = v6;
if ( v6 )
{
if ( v6 == 2 )
{
*a1 = v8;
result = v9;
a1[1] = v9;
}
else if ( v6 == 1 )
{
if ( !func0(a1) )
*a1 = v8;
result = func0((_DWORD *)a1 + 2);
if ( !(_DWORD)result )
{
result = v8;
a1[1] = v8;
}
}
}
else
{
*(_DWORD *)a1 = 0;
*((_DWORD *)a1 + 1) = 0;
*((_DWORD *)a1 + 2) = 0;
*((_DWORD *)a1 + 3) = 0;
}
}
return result;
}

original_code:
void rebuild_seg(seg_t *seg){
    if(is_point_within_area(&(seg->start)) == 1 && is_point_within_area(&(seg->end)) == 1){
        return;
    }else{
        point_t x0_y0 = build_point(0, 0);
        point_t x1_y0 = build_point(2000, 0);
        point_t x1_y1 = build_point(2000, 2000);
        point_t x0_y1 = build_point(0, 2000);
        point_t intersections[4];
        int count = 0;
        point_t its;
        BOOL is_its = get_seg_intersection(x0_y0, x1_y0, seg->start, seg->end, &its);
        if(is_its == 1){
            add_intersections(intersections, &count, its);
        }
        is_its = get_seg_intersection(x0_y1, x1_y1, seg->start, seg->end, &its);
        if(is_its == 1){
            add_intersections(intersections, &count, its);
        }
        is_its = get_seg_intersection(x0_y0, x0_y1, seg->start, seg->end, &its);
        if(is_its == 1){
            add_intersections(intersections, &count, its);
        }
        is_its = get_seg_intersection(x1_y0, x1_y1, seg->start, seg->end, &its);
        if(is_its == 1){
            add_intersections(intersections, &count, its);
        }
        if(count == 0){
            seg->start.x = 0;
            seg->start.y = 0;
            seg->end.x = 0;
            seg->end.y = 0;
            return;
        }
        if(count == 2){
            seg->start = intersections[0];
            seg->end = intersections[1];
        }
        if(count == 1){
            if(is_point_within_area(&(seg->start)) == 0){
                seg->start = intersections[0];
            }
            if(is_point_within_area(&(seg->end)) == 0){
                seg->end = intersections[0];
            }
        }
    }
}

canonical_original_code:
void rebuild_seg(struct seg *seg){
    if(is_point_within_area(&(seg->start)) == 1 && is_point_within_area(&(seg->end)) == 1){
        return;
    }else{
        struct point x0_y0 = build_point(0, 0);
        struct point x1_y0 = build_point(2000, 0);
        struct point x1_y1 = build_point(2000, 2000);
        struct point x0_y1 = build_point(0, 2000);
        struct point intersections[4];
        int count = 0;
        struct point its;
        int is_its = get_seg_intersection(x0_y0, x1_y0, seg->start, seg->end, &its);
        if(is_its == 1){
            add_intersections(intersections, &count, its);
        }
        is_its = get_seg_intersection(x0_y1, x1_y1, seg->start, seg->end, &its);
        if(is_its == 1){
            add_intersections(intersections, &count, its);
        }
        is_its = get_seg_intersection(x0_y0, x0_y1, seg->start, seg->end, &its);
        if(is_its == 1){
            add_intersections(intersections, &count, its);
        }
        is_its = get_seg_intersection(x1_y0, x1_y1, seg->start, seg->end, &its);
        if(is_its == 1){
            add_intersections(intersections, &count, its);
        }
        if(count == 0){
            seg->start.x = 0;
            seg->start.y = 0;
            seg->end.x = 0;
            seg->end.y = 0;
            return;
        }
        if(count == 2){
            seg->start = intersections[0];
            seg->end = intersections[1];
        }
        if(count == 1){
            if(is_point_within_area(&(seg->start)) == 0){
                seg->start = intersections[0];
            }
            if(is_point_within_area(&(seg->end)) == 0){
                seg->end = intersections[0];
            }
        }
    }
}

variable_types:
intersections
struct point { int x; int y; } [4]

variable_types: count int

variable_types:
its
struct point { int x; int y; }


decompiled_code:
__int64 __fastcall rebuild_seg_list(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 800) > 0 )
{
v1 = 0LL;
do
result = rebuild_seg(*(_QWORD **)(a1 + 8 * v1++));
while ( *(_DWORD *)(a1 + 800) > (int)v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 800) > 0 )
{
v1 = 0LL;
do
result = func3(*(_QWORD **)(a1 + 8 * v1++));
while ( *(_DWORD *)(a1 + 800) > (int)v1 );
}
return result;
}

original_code:
void rebuild_seg_list(seg_list_t * sl){
    int i = 0;
    for(;i<sl->segs_count; i++){
        rebuild_seg(sl->segs[i]);
    }
}

canonical_original_code:
void rebuild_seg_list(struct seg_list *sl){
    int i = 0;
    for(;i<sl->segs_count; i++){
        rebuild_seg(sl->segs[i]);
    }
}

variable_types: struct seg_list { struct seg { struct point { int x; int y; } start; int done; } *segs[100]; int segs_count; } *

user_defined_types: struct seg_list { struct seg *segs[100]; int segs_count; }


decompiled_code:
void init_seg_list()
{
*((_DWORD *)&seg_list + 200) = 0;
}

original_code:
void init_seg_list(void){
    seg_list.segs_count = 0;
}

canonical_original_code:
void init_seg_list(){
    seg_list.segs_count = 0;
}


decompiled_code:
_BOOL8 is_seg_list_full()
{
return *((_DWORD *)&seg_list + 200) > 99;
}

canonical_decompiled_code:
_BOOL8 func1()
{
return *((_DWORD *)&seg_list + 200) > 99;
}

original_code:
int is_seg_list_full(){
    if(seg_list.segs_count >= 100){
        return 1;
    }else{
        return 0;
    }
}


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

if ( is_seg_list_full() )
return v_error("seg list is full");
result = LODWORD(seg_list[100]);
if ( (_DWORD)result )
{
seg_list[(int)result] = a1;
result = (unsigned int)(result + 1);
LODWORD(seg_list[100]) = result;
}
else
{
seg_list[0] = a1;
LODWORD(seg_list[100]) = 1;
}
return result;
}

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

if ( func1() )
return v_error("seg list is full");
result = LODWORD(seg_list[100]);
if ( (_DWORD)result )
{
seg_list[(int)result] = a1;
result = (unsigned int)(result + 1);
LODWORD(seg_list[100]) = result;
}
else
{
seg_list[0] = a1;
LODWORD(seg_list[100]) = 1;
}
return result;
}

original_code:
void push_back_seg(seg_t* s){
    if(is_seg_list_full()){
        v_error("seg list is full");
        return;
    }
    if(seg_list.segs_count == 0){
        seg_list.segs[0] = s;
        seg_list.segs_count++;
    }else{
        seg_list.segs[seg_list.segs_count] = s;
        seg_list.segs_count++;
    }
}

canonical_original_code:
void push_back_seg(struct seg *s){
    if(is_seg_list_full()){
        v_error("seg list is full");
        return;
    }
    if(seg_list.segs_count == 0){
        seg_list.segs[0] = s;
        seg_list.segs_count++;
    }else{
        seg_list.segs[seg_list.segs_count] = s;
        seg_list.segs_count++;
    }
}


decompiled_code:
unsigned __int64 init_event_pool()
{
unsigned __int64 result; // rax

*((_DWORD *)&e_queue + 600) = 0;
result = (unsigned int)((_DWORD)&e_queue + 2404);
do
{
*(_DWORD *)result = 0;
result += 4LL;
}
while ( result != (_DWORD)&e_queue + 2804 );
*(&e_queue + 351) = 0LL;
*(&e_queue + 352) = 0LL;
return result;
}

canonical_decompiled_code:
unsigned __int64 func0()
{
unsigned __int64 result; // rax

*((_DWORD *)&e_queue + 600) = 0;
result = (unsigned int)((_DWORD)&e_queue + 2404);
do
{
*(_DWORD *)result = 0;
result += 4LL;
}
while ( result != (_DWORD)&e_queue + 2804 );
*(&e_queue + 351) = 0LL;
*(&e_queue + 352) = 0LL;
return result;
}

original_code:
void init_event_pool(){
    e_queue.events_count = 0;
    int i=0;
    for(; i<100; i++){
        e_queue.ievents[i] = 0;
    }
    e_queue.head = ((void *)0);
    e_queue.tail = ((void *)0);
}

canonical_original_code:
void init_event_pool(){
    e_queue.events_count = 0;
    int i = 0;
    for(; i<100; i++){
        e_queue.ievents[i] = 0;
    }
    e_queue.head = ((void *)0);
    e_queue.tail = ((void *)0);
}


decompiled_code:
_BOOL8 is_ep_empty()
{
return *((_DWORD *)&e_queue + 600) == 0;
}

canonical_decompiled_code:
_BOOL8 func1()
{
return *((_DWORD *)&e_queue + 600) == 0;
}

original_code:
int is_ep_empty(){
    if(e_queue.events_count == 0){
        return 1;
    }else{
        return 0;
    }
}


decompiled_code:
__int64 find_free_pos_e()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = 99LL;
while ( 1 )
{
v1 = v0;
if ( !*((_DWORD *)&e_queue + v0 + 601) )
break;
if ( --v0 == -1 )
return (unsigned int)-1;
}
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = 99LL;
while ( 1 )
{
v1 = v0;
if ( !*((_DWORD *)&e_queue + v0 + 601) )
break;
if ( --v0 == -1 )
return (unsigned int)-1;
}
return v1;
}

original_code:
int find_free_pos_e(){
    int i = 100 -1;
    while(i>=0){
        if(e_queue.ievents[i] == 0){
            return i;
        }
        --i;
    }
    return -1;
}


decompiled_code:
__int64 top_event()
{
return *(_QWORD *)e_queue[351];
}

canonical_decompiled_code:
__int64 func3()
{
return *(_QWORD *)e_queue[351];
}

original_code:
struct event* top_event(){
    return e_queue.head->e;
}

canonical_original_code:
struct event *top_event(){
    return e_queue.head->e;
}

return_type: struct event { struct point { int x; int y; } p; double x; struct arc { struct point p; struct arc *prev; struct event *e; struct seg { struct point start; int done; } *s0; struct seg *s1; int pos; } *a; int valid; } *


decompiled_code:
void __fastcall e_quicksort(__int64 *a1, __int64 *a2)
{
__int64 *v2; // r12

if ( a1 != a2 )
{
v2 = get_partion_e(a1, a2);
e_quicksort(a1, v2);
e_quicksort(v2[2], a2);
}
}

original_code:
void e_quicksort(event_node_t * e_begin, event_node_t *e_end){
    if(e_begin != e_end){
        event_node_t *partion = get_partion_e(e_begin, e_end);
        e_quicksort(e_begin, partion);
        e_quicksort(partion->next, e_end);
    }
}

canonical_original_code:
void e_quicksort(struct event_node *e_begin, struct event_node *e_end){
    if(e_begin != e_end){
        struct event_node *partion = get_partion_e(e_begin, e_end);
        e_quicksort(e_begin, partion);
        e_quicksort(partion->next, e_end);
    }
}

variable_types: struct event_node { struct event { struct point { int x; int y; } p; double x; struct arc { struct point p; struct arc *prev; struct event *e; struct seg { struct point start; int done; } *s0; struct seg *s1; int pos; } *a; int valid; } *e; int pos; struct event_node *next; } *

user_defined_types: struct event_node { struct event *e; int pos; struct event_node *next; }


decompiled_code:
void events_quicksort()
{
e_quicksort((__int64 *)e_queue[351], *(__int64 **)(e_queue[352] + 16));
}

original_code:
void events_quicksort(){
    e_quicksort(e_queue.head, e_queue.tail->next);
}


decompiled_code:
void __fastcall push_event(__int64 a1)
{
int v1; // eax
__int64 v2; // rsi
__int64 *v3; // rcx
__int64 *v4; // rdx

v1 = find_free_pos_e();
if ( v1 == -1 )
{
v_error("can not find free node for the new event!");
}
else
{
v2 = 3LL * v1;
e_queue[v2] = a1;
LODWORD(e_queue[v2 + 1]) = v1;
e_queue[v2 + 2] = 0LL;
if ( e_queue[351] )
{
v3 = &e_queue[3 * v1];
*(_QWORD *)(e_queue[352] + 16) = v3;
e_queue[352] = (__int64)v3;
e_queue[3 * v1 + 2] = 0LL;
}
else
{
v4 = &e_queue[3 * v1];
e_queue[351] = (__int64)v4;
e_queue[352] = (__int64)v4;
}
++LODWORD(e_queue[300]);
*((_DWORD *)&e_queue[300] + v1 + 1) = 1;
events_quicksort();
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
int v1; // eax
__int64 v2; // rsi
__int64 *v3; // rcx
__int64 *v4; // rdx

v1 = func2();
if ( v1 == -1 )
{
v_error("can not find free node for the new event!");
}
else
{
v2 = 3LL * v1;
e_queue[v2] = a1;
LODWORD(e_queue[v2 + 1]) = v1;
e_queue[v2 + 2] = 0LL;
if ( e_queue[351] )
{
v3 = &e_queue[3 * v1];
*(_QWORD *)(e_queue[352] + 16) = v3;
e_queue[352] = (__int64)v3;
e_queue[3 * v1 + 2] = 0LL;
}
else
{
v4 = &e_queue[3 * v1];
e_queue[351] = (__int64)v4;
e_queue[352] = (__int64)v4;
}
++LODWORD(e_queue[300]);
*((_DWORD *)&e_queue[300] + v1 + 1) = 1;
func5();
}
}

original_code:
void push_event(struct event *e){
    int free_node = find_free_pos_e();
    if(free_node == -1){
        v_error("can not find free node for the new event!");
        return;
    }
    e_queue.events[free_node].e = e;
    e_queue.events[free_node].pos = free_node;
    e_queue.events[free_node].next = ((void *)0);
    if(e_queue.head == ((void *)0)){
        e_queue.head = &(e_queue.events[free_node]);
        e_queue.tail = &(e_queue.events[free_node]);
        e_queue.events_count++;
        e_queue.ievents[free_node] = 1;
    }else{
        e_queue.tail->next = &(e_queue.events[free_node]);
        e_queue.tail = &(e_queue.events[free_node]);
        e_queue.tail->next = ((void *)0);
        e_queue.events_count++;
        e_queue.ievents[free_node] = 1;
    }
    events_quicksort();
}


KeyExpansion

repo: haiphan/haitech

decompiled_code:
__int64 KeyExpansion()
{
__int64 result; // rax
unsigned int v1; // edx
int v2; // er8
__int64 v3; // r9
__int64 v4; // rcx
char v5; // r11
unsigned __int8 v6; // dl
unsigned __int8 v7; // si
unsigned __int8 v8; // di
unsigned __int8 v9; // r10
__int64 v10; // rcx
unsigned __int8 v11; // dl
unsigned __int8 v12; // di
unsigned __int8 v13; // r10
unsigned __int8 v14; // si
char v15; // r11

result = (unsigned int)Nkb;
if ( Nkb > 0 )
{
RoundKey[0] = Key;
if ( Nkb > 1 )
{
RoundKey[1] = *(&Key + 1);
if ( (int)result > 2 )
{
RoundKey[2] = *(&Key + 2);
if ( (int)result > 3 )
{
RoundKey[3] = *(&Key + 3);
if ( (int)result > 4 )
{
RoundKey[4] = *(&Key + 4);
if ( (int)result > 5 )
{
RoundKey[5] = *(&Key + 5);
if ( (int)result > 6 )
{
RoundKey[6] = *(&Key + 6);
if ( (int)result > 7 )
{
RoundKey[7] = *(&Key + 7);
if ( (int)result > 8 )
{
RoundKey[8] = *(&Key + 8);
if ( (int)result > 9 )
{
RoundKey[9] = *(&Key + 9);
if ( (int)result > 10 )
{
RoundKey[10] = *(&Key + 10);
if ( (int)result > 11 )
{
RoundKey[11] = *(&Key + 11);
if ( (int)result > 12 )
{
RoundKey[12] = *(&Key + 12);
if ( (int)result > 13 )
{
RoundKey[13] = *(&Key + 13);
if ( (int)result > 14 )
{
RoundKey[14] = *(&Key + 14);
if ( (int)result > 15 )
{
result = (unsigned __int8)*(&Key + 15);
RoundKey[15] = result;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
v1 = 4 * Nr + 4;
if ( !(((Nr & 0x20000000) != 0) ^ __OFSUB__(v1, 4) | (v1 == 4)) )
{
v2 = Nk;
v3 = v1;
v4 = 4LL;
do
{
v6 = RoundKey[4 * v4 - 4];
v7 = RoundKey[4 * v4 - 3];
v8 = RoundKey[4 * v4 - 2];
v9 = RoundKey[4 * v4 - 1];
if ( (v4 & 3) == 0 )
{
v5 = sbox[v7];
v7 = sbox[v8];
v8 = sbox[v9];
v9 = sbox[v6];
v6 = rcon[(int)v4 / v2 - 1] ^ v5;
}
RoundKey[4 * v4] = RoundKey[4 * v4 - 16] ^ v6;
RoundKey[4 * v4 + 1] = RoundKey[4 * v4 - 15] ^ v7;
RoundKey[4 * v4 + 2] = RoundKey[4 * v4 - 14] ^ v8;
RoundKey[4 * v4 + 3] = RoundKey[4 * v4 - 13] ^ v9;
v10 = v4 + 1;
result = (unsigned int)v10;
v11 = RoundKey[4 * v10 - 4];
v12 = RoundKey[4 * v10 - 3];
v13 = RoundKey[4 * v10 - 2];
v14 = RoundKey[4 * v10 - 1];
if ( (v10 & 3) == 0 )
{
v15 = sbox[v12];
v12 = sbox[v13];
v13 = sbox[v14];
v14 = sbox[v11];
result = (int)v10 / v2 - 1;
v11 = rcon[result] ^ v15;
}
RoundKey[4 * v10] = RoundKey[4 * v10 - 16] ^ v11;
RoundKey[4 * v10 + 1] = RoundKey[4 * v10 - 15] ^ v12;
RoundKey[4 * v10 + 2] = RoundKey[4 * v10 - 14] ^ v13;
RoundKey[4 * v10 + 3] = RoundKey[4 * v10 - 13] ^ v14;
v4 = v10 + 1;
}
while ( v3 != v4 );
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
unsigned int v1; // edx
int v2; // er8
__int64 v3; // r9
__int64 v4; // rcx
char v5; // r11
unsigned __int8 v6; // dl
unsigned __int8 v7; // si
unsigned __int8 v8; // di
unsigned __int8 v9; // r10
__int64 v10; // rcx
unsigned __int8 v11; // dl
unsigned __int8 v12; // di
unsigned __int8 v13; // r10
unsigned __int8 v14; // si
char v15; // r11

result = (unsigned int)Nkb;
if ( Nkb > 0 )
{
RoundKey[0] = Key;
if ( Nkb > 1 )
{
RoundKey[1] = *(&Key + 1);
if ( (int)result > 2 )
{
RoundKey[2] = *(&Key + 2);
if ( (int)result > 3 )
{
RoundKey[3] = *(&Key + 3);
if ( (int)result > 4 )
{
RoundKey[4] = *(&Key + 4);
if ( (int)result > 5 )
{
RoundKey[5] = *(&Key + 5);
if ( (int)result > 6 )
{
RoundKey[6] = *(&Key + 6);
if ( (int)result > 7 )
{
RoundKey[7] = *(&Key + 7);
if ( (int)result > 8 )
{
RoundKey[8] = *(&Key + 8);
if ( (int)result > 9 )
{
RoundKey[9] = *(&Key + 9);
if ( (int)result > 10 )
{
RoundKey[10] = *(&Key + 10);
if ( (int)result > 11 )
{
RoundKey[11] = *(&Key + 11);
if ( (int)result > 12 )
{
RoundKey[12] = *(&Key + 12);
if ( (int)result > 13 )
{
RoundKey[13] = *(&Key + 13);
if ( (int)result > 14 )
{
RoundKey[14] = *(&Key + 14);
if ( (int)result > 15 )
{
result = (unsigned __int8)*(&Key + 15);
RoundKey[15] = result;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
v1 = 4 * Nr + 4;
if ( !(((Nr & 0x20000000) != 0) ^ __OFSUB__(v1, 4) | (v1 == 4)) )
{
v2 = Nk;
v3 = v1;
v4 = 4LL;
do
{
v6 = RoundKey[4 * v4 - 4];
v7 = RoundKey[4 * v4 - 3];
v8 = RoundKey[4 * v4 - 2];
v9 = RoundKey[4 * v4 - 1];
if ( (v4 & 3) == 0 )
{
v5 = sbox[v7];
v7 = sbox[v8];
v8 = sbox[v9];
v9 = sbox[v6];
v6 = rcon[(int)v4 / v2 - 1] ^ v5;
}
RoundKey[4 * v4] = RoundKey[4 * v4 - 16] ^ v6;
RoundKey[4 * v4 + 1] = RoundKey[4 * v4 - 15] ^ v7;
RoundKey[4 * v4 + 2] = RoundKey[4 * v4 - 14] ^ v8;
RoundKey[4 * v4 + 3] = RoundKey[4 * v4 - 13] ^ v9;
v10 = v4 + 1;
result = (unsigned int)v10;
v11 = RoundKey[4 * v10 - 4];
v12 = RoundKey[4 * v10 - 3];
v13 = RoundKey[4 * v10 - 2];
v14 = RoundKey[4 * v10 - 1];
if ( (v10 & 3) == 0 )
{
v15 = sbox[v12];
v12 = sbox[v13];
v13 = sbox[v14];
v14 = sbox[v11];
result = (int)v10 / v2 - 1;
v11 = rcon[result] ^ v15;
}
RoundKey[4 * v10] = RoundKey[4 * v10 - 16] ^ v11;
RoundKey[4 * v10 + 1] = RoundKey[4 * v10 - 15] ^ v12;
RoundKey[4 * v10 + 2] = RoundKey[4 * v10 - 14] ^ v13;
RoundKey[4 * v10 + 3] = RoundKey[4 * v10 - 13] ^ v14;
v4 = v10 + 1;
}
while ( v3 != v4 );
}
return result;
}

original_code:
void KeyExpansion()
{
 int i,j;
 unsigned char temp[4],k;
 for(i=0;i<Nkb;i++)
 {
  RoundKey[i]=Key[i];
 }
 i=4;
 while (i < (4 * (Nr+1)))
 {
     for(j=0;j<4;j++)
     {
      temp[j]=RoundKey[(i-1) * 4 + j];
     }
     if (i % 4 == 0)
     {
      {
       k = temp[0];
       temp[0] = temp[1];
       temp[1] = temp[2];
       temp[2] = temp[3];
       temp[3] = k;
      }
      {
       temp[0]=sbox[temp[0]];
       temp[1]=sbox[temp[1]];;
       temp[2]=sbox[temp[2]];;
       temp[3]=sbox[temp[3]];;
      }
      temp[0] = temp[0] ^ rcon[i/Nk - 1];
     }
     RoundKey[i*4+0] = RoundKey[(i-4)*4+0] ^ temp[0];
     RoundKey[i*4+1] = RoundKey[(i-4)*4+1] ^ temp[1];
     RoundKey[i*4+2] = RoundKey[(i-4)*4+2] ^ temp[2];
     RoundKey[i*4+3] = RoundKey[(i-4)*4+3] ^ temp[3];
     i++;
 }
}

canonical_original_code:
void KeyExpansion()
{
 int i; int j;
 unsigned char temp[4]; unsigned char k;
 for(i=0;i<Nkb;i++)
 {
  RoundKey[i]=Key[i];
 }
 i=4;
 while (i < (4 * (Nr+1)))
 {
     for(j=0;j<4;j++)
     {
      temp[j]=RoundKey[(i-1) * 4 + j];
     }
     if (i % 4 == 0)
     {
      {
       k = temp[0];
       temp[0] = temp[1];
       temp[1] = temp[2];
       temp[2] = temp[3];
       temp[3] = k;
      }
      {
       temp[0]=sbox[temp[0]];
       temp[1]=sbox[temp[1]];;
       temp[2]=sbox[temp[2]];;
       temp[3]=sbox[temp[3]];;
      }
      temp[0] = temp[0] ^ rcon[i/Nk - 1];
     }
     RoundKey[i*4+0] = RoundKey[(i-4)*4+0] ^ temp[0];
     RoundKey[i*4+1] = RoundKey[(i-4)*4+1] ^ temp[1];
     RoundKey[i*4+2] = RoundKey[(i-4)*4+2] ^ temp[2];
     RoundKey[i*4+3] = RoundKey[(i-4)*4+3] ^ temp[3];
     i++;
 }
}

variable_types: j int

variable_types:
temp
unsigned char [4]

variable_types:
k
unsigned char


AddRoundKey

decompiled_code:
__int64 __fastcall AddRoundKey(int a1)
{
int v1; // edx
int v2; // edi
__int64 result; // rax

v1 = 4 * a1;
v2 = 16 * a1;
state ^= RoundKey[v2];
*(&state + 4) ^= RoundKey[v2 + 1];
*(&state + 8) ^= RoundKey[v2 + 2];
*(&state + 12) ^= RoundKey[v2 + 3];
*(&state + 1) ^= RoundKey[4 * v1 + 4];
*(&state + 5) ^= RoundKey[4 * v1 + 5];
*(&state + 9) ^= RoundKey[4 * v1 + 6];
*(&state + 13) ^= RoundKey[4 * v1 + 7];
*(&state + 2) ^= RoundKey[4 * v1 + 8];
*(&state + 6) ^= RoundKey[4 * v1 + 9];
*(&state + 10) ^= RoundKey[4 * v1 + 10];
*(&state + 14) ^= RoundKey[4 * v1 + 11];
*(&state + 3) ^= RoundKey[4 * v1 + 12];
*(&state + 7) ^= RoundKey[4 * v1 + 13];
*(&state + 11) ^= RoundKey[4 * v1 + 14];
result = (unsigned __int8)RoundKey[4 * v1 + 15];
*(&state + 15) ^= result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // edx
int v2; // edi
__int64 result; // rax

v1 = 4 * a1;
v2 = 16 * a1;
state ^= RoundKey[v2];
*(&state + 4) ^= RoundKey[v2 + 1];
*(&state + 8) ^= RoundKey[v2 + 2];
*(&state + 12) ^= RoundKey[v2 + 3];
*(&state + 1) ^= RoundKey[4 * v1 + 4];
*(&state + 5) ^= RoundKey[4 * v1 + 5];
*(&state + 9) ^= RoundKey[4 * v1 + 6];
*(&state + 13) ^= RoundKey[4 * v1 + 7];
*(&state + 2) ^= RoundKey[4 * v1 + 8];
*(&state + 6) ^= RoundKey[4 * v1 + 9];
*(&state + 10) ^= RoundKey[4 * v1 + 10];
*(&state + 14) ^= RoundKey[4 * v1 + 11];
*(&state + 3) ^= RoundKey[4 * v1 + 12];
*(&state + 7) ^= RoundKey[4 * v1 + 13];
*(&state + 11) ^= RoundKey[4 * v1 + 14];
result = (unsigned __int8)RoundKey[4 * v1 + 15];
*(&state + 15) ^= result;
return result;
}

original_code:
void AddRoundKey(int round)
{
 int i,j;
 for(i=0;i<4;i++)
 {
  for(j=0;j<4;j++)
  {
   state[j][i] ^= RoundKey[round * 4 * 4 + i * 4 + j];
  }
 }
}

canonical_original_code:
void AddRoundKey(int round)
{
 int i; int j;
 for(i=0;i<4;i++)
 {
  for(j=0;j<4;j++)
  {
   state[j][i] ^= RoundKey[round * 4 * 4 + i * 4 + j];
  }
 }
}

variable_types: round int

variable_types: i int


SubBytes

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

state = sbox[(unsigned __int8)state];
*(&state + 1) = sbox[(unsigned __int8)*(&state + 1)];
*(&state + 2) = sbox[(unsigned __int8)*(&state + 2)];
*(&state + 3) = sbox[(unsigned __int8)*(&state + 3)];
*(&state + 4) = sbox[(unsigned __int8)*(&state + 4)];
*(&state + 5) = sbox[(unsigned __int8)*(&state + 5)];
*(&state + 6) = sbox[(unsigned __int8)*(&state + 6)];
*(&state + 7) = sbox[(unsigned __int8)*(&state + 7)];
*(&state + 8) = sbox[(unsigned __int8)*(&state + 8)];
*(&state + 9) = sbox[(unsigned __int8)*(&state + 9)];
*(&state + 10) = sbox[(unsigned __int8)*(&state + 10)];
*(&state + 11) = sbox[(unsigned __int8)*(&state + 11)];
*(&state + 12) = sbox[(unsigned __int8)*(&state + 12)];
result = (unsigned __int8)sbox[(unsigned __int8)*(&state + 13)];
*(&state + 13) = result;
*(&state + 14) = sbox[(unsigned __int8)*(&state + 14)];
*(&state + 15) = sbox[(unsigned __int8)*(&state + 15)];
return result;
}

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

state = sbox[(unsigned __int8)state];
*(&state + 1) = sbox[(unsigned __int8)*(&state + 1)];
*(&state + 2) = sbox[(unsigned __int8)*(&state + 2)];
*(&state + 3) = sbox[(unsigned __int8)*(&state + 3)];
*(&state + 4) = sbox[(unsigned __int8)*(&state + 4)];
*(&state + 5) = sbox[(unsigned __int8)*(&state + 5)];
*(&state + 6) = sbox[(unsigned __int8)*(&state + 6)];
*(&state + 7) = sbox[(unsigned __int8)*(&state + 7)];
*(&state + 8) = sbox[(unsigned __int8)*(&state + 8)];
*(&state + 9) = sbox[(unsigned __int8)*(&state + 9)];
*(&state + 10) = sbox[(unsigned __int8)*(&state + 10)];
*(&state + 11) = sbox[(unsigned __int8)*(&state + 11)];
*(&state + 12) = sbox[(unsigned __int8)*(&state + 12)];
result = (unsigned __int8)sbox[(unsigned __int8)*(&state + 13)];
*(&state + 13) = result;
*(&state + 14) = sbox[(unsigned __int8)*(&state + 14)];
*(&state + 15) = sbox[(unsigned __int8)*(&state + 15)];
return result;
}

original_code:
void SubBytes()
{
 int i,j;
 for(i=0;i<4;i++)
 {
  for(j=0;j<4;j++)
  {
   state[i][j] = sbox[state[i][j]];
  }
 }
}

canonical_original_code:
void SubBytes()
{
 int i; int j;
 for(i=0;i<4;i++)
 {
  for(j=0;j<4;j++)
  {
   state[i][j] = sbox[state[i][j]];
  }
 }
}


ShiftRows

original_code:
void ShiftRows()
{
 unsigned char temp;
 temp=state[1][0];
 state[1][0]=state[1][1];
 state[1][1]=state[1][2];
 state[1][2]=state[1][3];
 state[1][3]=temp;
 temp=state[2][0];
 state[2][0]=state[2][2];
 state[2][2]=temp;
 temp=state[2][1];
 state[2][1]=state[2][3];
 state[2][3]=temp;
 temp=state[3][0];
 state[3][0]=state[3][3];
 state[3][3]=state[3][2];
 state[3][2]=state[3][1];
 state[3][1]=temp;
}

variable_types:
temp
unsigned char


original_code:
void aes128e(unsigned char *c, const unsigned char *p, const unsigned char *k) {
 int i,j,round=0;
 for(i=0;i<Nkb;i++)
 {
  Key[i]=k[i];
 }
 for(i=0;i<4;i++)
 {
  for(j=0;j<4;j++)
  {
   state[j][i] = p[i*4 + j];
  }
 }
 KeyExpansion();
 AddRoundKey(0);
 for(round=1;round<Nr;round++)
 {
  SubBytes();
  ShiftRows();
  MixColumns();
  AddRoundKey(round);
 }
 SubBytes();
 ShiftRows();
 AddRoundKey(Nr);
 for(i=0;i<4;i++)
 {
  for(j=0;j<4;j++)
  {
   c[i*4+j]=state[j][i];
  }
 }
}

canonical_original_code:
void aes128e(unsigned char *c, unsigned char *p, unsigned char *k) {
 int i; int j; int round = 0;
 for(i=0;i<Nkb;i++)
 {
  Key[i]=k[i];
 }
 for(i=0;i<4;i++)
 {
  for(j=0;j<4;j++)
  {
   state[j][i] = p[i*4 + j];
  }
 }
 KeyExpansion();
 AddRoundKey(0);
 for(round=1;round<Nr;round++)
 {
  SubBytes();
  ShiftRows();
  MixColumns();
  AddRoundKey(round);
 }
 SubBytes();
 ShiftRows();
 AddRoundKey(Nr);
 for(i=0;i<4;i++)
 {
  for(j=0;j<4;j++)
  {
   c[i*4+j]=state[j][i];
  }
 }
}

variable_types:
c
unsigned char *

variable_types:
p
unsigned char *

variable_types:
k
unsigned char *


repo: haipome/fls

decompiled_code:
int __fastcall get_head(char *s, const char *a2)
{
char *v2; // rax

v2 = getenv("HOME");
return sprintf(s, "%s%s", v2, a2);
}

canonical_decompiled_code:
int __fastcall func0(char *s, const char *a2)
{
char *v2; // rax

v2 = getenv("HOME");
return sprintf(s, "%s%s", v2, a2);
}

original_code:
static void get_head(char *head, char *name)
{
 sprintf(head, "%s%s", getenv("HOME"), name);
}

variable_types:
head
char *

variable_types:
name
char *


decompiled_code:
char *__fastcall add_id_tag(char *s)
{
sprintf(s, "%3u ", localaddr);
return &s[strlen(s)];
}

canonical_decompiled_code:
char *__fastcall func1(char *s)
{
sprintf(s, "%3u ", localaddr);
return &s[strlen(s)];
}

original_code:
static char * add_id_tag(char * buf)
{
 sprintf(buf, "%3u  ", localaddr.id);
 return (buf + strlen(buf));
}

canonical_original_code:
static char *add_id_tag(char *buf)
{
 sprintf(buf, "%3u  ", localaddr.id);
 return (buf + strlen(buf));
}

variable_types:
buf
char *

return_type: char *


decompiled_code:
__int64 __fastcall name_in_date(char *src, char *dest, char *a3)
{
struct tm *v4; // r13
size_t v5; // rax
size_t v6; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

time(&timer);
v4 = localtime(&timer);
strncpy(dest, src, 0x63uLL);
v5 = strlen(src);
strftime(&dest[v5], 0x14uLL, "%Y%m%d", v4);
v6 = strlen(dest);
strncat(dest, a3, 99 - v6);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, char *dest, char *a3)
{
struct tm *v4; // r13
size_t v5; // rax
size_t v6; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

time(&timer);
v4 = localtime(&timer);
strncpy(dest, src, 0x63uLL);
v5 = strlen(src);
strftime(&dest[v5], 0x14uLL, "%Y%m%d", v4);
v6 = strlen(dest);
strncat(dest, a3, 99 - v6);
return 1LL;
}

original_code:
static int name_in_date(const char * head, char * name, const char * tail)
{
 time_t now;
 struct tm * today;
 time(&now);
 today = localtime(&now);
 strncpy(name, head, 100 - 1);
 strftime((name + strlen(head)), 20, "%Y%m%d", today);
 strncat(name, tail, 100 - strlen(name) - 1);
 return 1;
}

canonical_original_code:
static int name_in_date(char *head, char *name, char *tail)
{
 long now;
 struct tm *today;
 time(&now);
 today = localtime(&now);
 strncpy(name, head, 100 - 1);
 strftime((name + strlen(head)), 20, "%Y%m%d", today);
 strncat(name, tail, 100 - strlen(name) - 1);
 return 1;
}

variable_types:
tail
char *

variable_types: now long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
void log_init()
{
if ( logs_status != 1 )
{
get_head(src, "/wb/fls/log/gene/flsd");
name_in_date(src, dest, ".log");
logs = fopen(dest, "a+");
if ( !logs )
{
fwrite("In log_init: cannot open general log file\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
get_head(s, "/wb/fls/log/freq/freq");
name_in_date(s, byte_A78, ".log");
stream = fopen(byte_A78, "a+");
if ( !stream )
{
fwrite("In log_init: cannot open freqence log file\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
get_head(byte_BAC, "/wb/fls/log/over/over");
name_in_date(byte_BAC, byte_B48, ".log");
qword_B40 = fopen(byte_B48, "a+");
if ( !qword_B40 )
{
fwrite("In log_init: cannot open over limit log file\n", 1uLL, 0x2DuLL, stderr);
exit(1);
}
get_head(byte_C7C, "/wb/fls/log/warn/warn");
name_in_date(byte_C7C, byte_C18, ".log");
qword_C10 = fopen(byte_C18, "a+");
if ( !qword_C10 )
{
fwrite("In log_init: cannot open warning log file\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
logs_status = 1;
}
}

canonical_decompiled_code:
void func5()
{
if ( logs_status != 1 )
{
func0(src, "/wb/fls/log/gene/flsd");
func3(src, dest, ".log");
logs = fopen(dest, "a+");
if ( !logs )
{
fwrite("In log_init: cannot open general log file\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
func0(s, "/wb/fls/log/freq/freq");
func3(s, byte_A78, ".log");
stream = fopen(byte_A78, "a+");
if ( !stream )
{
fwrite("In log_init: cannot open freqence log file\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
func0(byte_BAC, "/wb/fls/log/over/over");
func3(byte_BAC, byte_B48, ".log");
qword_B40 = fopen(byte_B48, "a+");
if ( !qword_B40 )
{
fwrite("In log_init: cannot open over limit log file\n", 1uLL, 0x2DuLL, stderr);
exit(1);
}
func0(byte_C7C, "/wb/fls/log/warn/warn");
func3(byte_C7C, byte_C18, ".log");
qword_C10 = fopen(byte_C18, "a+");
if ( !qword_C10 )
{
fwrite("In log_init: cannot open warning log file\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
logs_status = 1;
}
}

original_code:
void log_init(void)
{
 if (logs_status == 1)
  return;
 get_head(logs.gene_log.head, genehead);
 name_in_date(logs.gene_log.head, logs.gene_log.name, commtail);
 if ((logs.gene_log.fp = fopen(logs.gene_log.name, "a+")) == ((void *)0))
 {
  fputs("In log_init: cannot open general log file\n", stderr);
  exit(1);
 }
 get_head(logs.freq_log.head, freqhead);
 name_in_date(logs.freq_log.head, logs.freq_log.name, commtail);
 if ((logs.freq_log.fp = fopen(logs.freq_log.name, "a+")) == ((void *)0))
 {
  fputs("In log_init: cannot open freqence log file\n", stderr);
  exit(1);
 }
 get_head(logs.over_log.head, overhead);
 name_in_date(logs.over_log.head, logs.over_log.name, commtail);
 if ((logs.over_log.fp = fopen(logs.over_log.name, "a+")) == ((void *)0))
 {
  fputs("In log_init: cannot open over limit log file\n", stderr);
  exit(1);
 }
 get_head(logs.warn_log.head, warnhead);
 name_in_date(logs.warn_log.head, logs.warn_log.name, commtail);
 if ((logs.warn_log.fp = fopen(logs.warn_log.name, "a+")) == ((void *)0))
 {
  fputs("In log_init: cannot open warning log file\n", stderr);
  exit(1);
 }
 logs_status = 1;
 return;
}

canonical_original_code:
void log_init()
{
 if (logs_status == 1)
  return;
 get_head(logs.gene_log.head, genehead);
 name_in_date(logs.gene_log.head, logs.gene_log.name, commtail);
 if ((logs.gene_log.fp = fopen(logs.gene_log.name, "a+")) == ((void *)0))
 {
  fputs("In log_init: cannot open general log file\n", stderr);
  exit(1);
 }
 get_head(logs.freq_log.head, freqhead);
 name_in_date(logs.freq_log.head, logs.freq_log.name, commtail);
 if ((logs.freq_log.fp = fopen(logs.freq_log.name, "a+")) == ((void *)0))
 {
  fputs("In log_init: cannot open freqence log file\n", stderr);
  exit(1);
 }
 get_head(logs.over_log.head, overhead);
 name_in_date(logs.over_log.head, logs.over_log.name, commtail);
 if ((logs.over_log.fp = fopen(logs.over_log.name, "a+")) == ((void *)0))
 {
  fputs("In log_init: cannot open over limit log file\n", stderr);
  exit(1);
 }
 get_head(logs.warn_log.head, warnhead);
 name_in_date(logs.warn_log.head, logs.warn_log.name, commtail);
 if ((logs.warn_log.fp = fopen(logs.warn_log.name, "a+")) == ((void *)0))
 {
  fputs("In log_init: cannot open warning log file\n", stderr);
  exit(1);
 }
 logs_status = 1;
 return;
}


decompiled_code:
_BOOL8 log_close()
{
_BOOL4 v0; // ebx
int v2; // ebp

v0 = 1;
if ( logs_status )
{
v2 = fclose(logs);
v0 = 0;
if ( fclose(stream) != -1 )
v0 = v2 != -1;
if ( fclose(qword_B40) == -1 )
v0 = 0;
if ( fclose(qword_C10) == -1 )
v0 = 0;
}
return v0;
}

canonical_decompiled_code:
_BOOL8 func7()
{
_BOOL4 v0; // ebx
int v2; // ebp

v0 = 1;
if ( logs_status )
{
v2 = fclose(logs);
v0 = 0;
if ( fclose(stream) != -1 )
v0 = v2 != -1;
if ( fclose(qword_B40) == -1 )
v0 = 0;
if ( fclose(qword_C10) == -1 )
v0 = 0;
}
return v0;
}

original_code:
int log_close(void)
{
 int stat = 1;
 if (logs_status != 0)
 {
  if (fclose(logs.gene_log.fp) == (-1))
   stat = 0;
  if (fclose(logs.freq_log.fp) == (-1))
   stat = 0;
  if (fclose(logs.over_log.fp) == (-1))
   stat = 0;
  if (fclose(logs.warn_log.fp) == (-1))
   stat = 0;
 }
 return stat;
}

canonical_original_code:
int log_close()
{
 int stat = 1;
 if (logs_status != 0)
 {
  if (fclose(logs.gene_log.fp) == (-1))
   stat = 0;
  if (fclose(logs.freq_log.fp) == (-1))
   stat = 0;
  if (fclose(logs.over_log.fp) == (-1))
   stat = 0;
  if (fclose(logs.warn_log.fp) == (-1))
   stat = 0;
 }
 return stat;
}

variable_types: stat int


decompiled_code:
__int64 fls_init()
{
signal_init();
log_init();
if ( !(unsigned int)readconf() )
err_exit("read config file error");
net_init();
shamem_init();
limit_init();
manage_fls_init();
if ( manage_switch )
read_rflsl();
if ( !(unsigned int)inform_start() )
err_exit("In fls_init: cannot connect to manage server");
pid_conf();
return run_msg("started.");
}

canonical_decompiled_code:
__int64 func0()
{
signal_init();
log_init();
if ( !(unsigned int)readconf() )
err_exit("read config file error");
net_init();
shamem_init();
limit_init();
manage_fls_init();
if ( manage_switch )
read_rflsl();
if ( !(unsigned int)inform_start() )
err_exit("In fls_init: cannot connect to manage server");
pid_conf();
return run_msg("started.");
}

original_code:
void fls_init(void)
{
 signal_init();
 log_init();
 if (!readconf())
  err_exit("read config file error");
 net_init();
 shamem_init();
 limit_init();
 manage_fls_init();
 if (manage_switch)
  read_rflsl();
 if (!inform_start())
  err_exit("In fls_init: cannot connect to manage server");
 pid_conf();
 run_msg("started.");
 return;
}

canonical_original_code:
void fls_init()
{
 signal_init();
 log_init();
 if (!readconf())
  err_exit("read config file error");
 net_init();
 shamem_init();
 limit_init();
 manage_fls_init();
 if (manage_switch)
  read_rflsl();
 if (!inform_start())
  err_exit("In fls_init: cannot connect to manage server");
 pid_conf();
 run_msg("started.");
 return;
}


decompiled_code:
void fls_close()
{
fls_switch = 0;
}

canonical_decompiled_code:
void func1()
{
fls_switch = 0;
}

original_code:
void fls_close(int sig)
{
 extern int fls_switch;
 fls_switch = 0;
}

variable_types: sig int


decompiled_code:
void __noreturn fls_exit()
{
run_msg("closed.");
if ( !(unsigned int)inform_close() )
run_msg("In fls_exit: cannot connect to manage fls");
log_close();
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
run_msg("closed.");
if ( !(unsigned int)inform_close() )
run_msg("In fls_exit: cannot connect to manage fls");
log_close();
exit(0);
}

original_code:
void fls_exit(void)
{
 run_msg("closed.");
 if (!inform_close())
  run_msg("In fls_exit: cannot connect to manage fls")
  ;
 log_close();
 exit(0);
}

canonical_original_code:
void fls_exit()
{
 run_msg("closed.");
 if (!inform_close())
  run_msg("In fls_exit: cannot connect to manage fls")
  ;
 log_close();
 exit(0);
}


decompiled_code:
void __noreturn send_exit_signal()
{
__pid_t v0; // edi

v0 = getconf2("processid", _id_offset);
if ( (unsigned int)(v0 + 1) > 1 )
{
kill(v0, 10);
exit(0);
}
fwrite("In send_exit_signal: get pid error\n", 1uLL, 0x23uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
__pid_t v0; // edi

v0 = getconf2("processid", _id_offset);
if ( (unsigned int)(v0 + 1) > 1 )
{
kill(v0, 10);
exit(0);
}
fwrite("In send_exit_signal: get pid error\n", 1uLL, 0x23uLL, stderr);
exit(1);
}

original_code:
void send_exit_signal()
{
 pid_t pid;
 pid = (pid_t)getconf2("processid", __id_offset);
 if (pid == 0 || pid == -1)
 {
  fputs("In send_exit_signal: get pid error\n", stderr);
  exit(1);
 }
 kill(pid, 10);
 exit(0);
}

canonical_original_code:
void send_exit_signal()
{
 int pid;
 pid = (int)getconf2("processid", __id_offset);
 if (pid == 0 || pid == -1)
 {
  fputs("In send_exit_signal: get pid error\n", stderr);
  exit(1);
 }
 kill(pid, 10);
 exit(0);
}

variable_types: pid int


decompiled_code:
__sighandler_t signal_init()
{
__sighandler_t result; // rax

if ( signal(10, (__sighandler_t)&fls_close) == (__sighandler_t)-1LL )
{
fwrite("In signal_init: cannot catch SIGUSR1\n", 1uLL, 0x25uLL, stderr);
exit(1);
}
if ( signal(2, (__sighandler_t)&fls_close) == (__sighandler_t)-1LL )
{
fwrite("In signal_init: cannot catch SIGINT\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
result = signal(3, (__sighandler_t)&fls_close);
if ( result == (__sighandler_t)-1LL )
{
fwrite("In signal_init: cannot catch SIGINT\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
return result;
}

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

if ( signal(10, (__sighandler_t)&fls_close) == (__sighandler_t)-1LL )
{
fwrite("In signal_init: cannot catch SIGUSR1\n", 1uLL, 0x25uLL, stderr);
exit(1);
}
if ( signal(2, (__sighandler_t)&fls_close) == (__sighandler_t)-1LL )
{
fwrite("In signal_init: cannot catch SIGINT\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
result = signal(3, (__sighandler_t)&fls_close);
if ( result == (__sighandler_t)-1LL )
{
fwrite("In signal_init: cannot catch SIGINT\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
return result;
}

original_code:
void signal_init(void)
{
 if (signal(10, fls_close) == ((__sighandler_t) -1))
 {
  fputs("In signal_init: cannot catch SIGUSR1\n", stderr);
  exit(1);
 }
 if (signal(2, fls_close) == ((__sighandler_t) -1))
 {
  fputs("In signal_init: cannot catch SIGINT\n", stderr);
  exit(1);
 }
 if (signal(3, fls_close) == ((__sighandler_t) -1))
 {
  fputs("In signal_init: cannot catch SIGINT\n", stderr);
  exit(1);
 }
}

canonical_original_code:
void signal_init()
{
 if (signal(10, fls_close) == ((__sighandler_t) -1))
 {
  fputs("In signal_init: cannot catch SIGUSR1\n", stderr);
  exit(1);
 }
 if (signal(2, fls_close) == ((__sighandler_t) -1))
 {
  fputs("In signal_init: cannot catch SIGINT\n", stderr);
  exit(1);
 }
 if (signal(3, fls_close) == ((__sighandler_t) -1))
 {
  fputs("In signal_init: cannot catch SIGINT\n", stderr);
  exit(1);
 }
}


decompiled_code:
__int64 pid_conf()
{
__pid_t v0; // eax
__int64 result; // rax

readconf();
v0 = getpid();
result = setconf2("processid", _id_offset, v0);
if ( !(_DWORD)result )
result = run_msg("In pid_conf: write pid error");
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__pid_t v0; // eax
__int64 result; // rax

readconf();
v0 = getpid();
result = setconf2("processid", _id_offset, v0);
if ( !(_DWORD)result )
result = run_msg("In pid_conf: write pid error");
return result;
}

original_code:
void pid_conf(void)
{
 readconf();
 pid_t pid = getpid();
 if (setconf2("processid", __id_offset, pid) == 0)
  run_msg("In pid_conf: write pid error");
}

canonical_original_code:
void pid_conf()
{
 readconf();
 int pid = getpid();
 if (setconf2("processid", __id_offset, pid) == 0)
  run_msg("In pid_conf: write pid error");
}


decompiled_code:
int pid_print()
{
__int64 v0; // rax

readconf();
v0 = getconf2("processid", _id_offset);
return printf("%d\n", v0);
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // rax

readconf();
v0 = getconf2("processid", _id_offset);
return printf("%d\n", v0);
}

original_code:
void pid_print(void)
{
 readconf();
 printf("%d\n", (int)getconf2("processid", __id_offset));
}

canonical_original_code:
void pid_print()
{
 readconf();
 printf("%d\n", (int)getconf2("processid", __id_offset));
}


getconfs

decompiled_code:
const char *__fastcall getconfs(char *s2)
{
const char *v1; // rbx
const char *v2; // rsi
unsigned __int64 v3; // rax
__int64 v4; // rdx
char *v5; // rax

if ( !s2 )
return 0LL;
if ( !conf_status )
readconf();
v1 = first_match(s2);
if ( v1 )
{
v2 = &v1[strlen(s2)];
v3 = *(unsigned __int8 *)v2;
if ( (unsigned __int8)v3 <= 0x3Du )
{
v4 = 0x2000000100000200LL;
if ( _bittest64(&v4, v3) )
{
do
v3 = *(unsigned __int8 *)++v2;
while ( (unsigned __int8)v3 <= 0x3Du && _bittest64(&v4, v3) );
}
}
v1 = 0LL;
if ( (_BYTE)v3 )
{
strncpy(&buf_line, v2, 0x3FFuLL);
if ( buf_line == 10 || !buf_line )
{
v5 = &buf_line;
}
else
{
v5 = &buf_line;
do
++v5;
while ( *v5 != 10 && *v5 );
}
*v5 = 0;
v1 = &buf_line;
}
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func5(char *s2)
{
const char *v1; // rbx
const char *v2; // rsi
unsigned __int64 v3; // rax
__int64 v4; // rdx
char *v5; // rax

if ( !s2 )
return 0LL;
if ( !conf_status )
func1();
v1 = func0(s2);
if ( v1 )
{
v2 = &v1[strlen(s2)];
v3 = *(unsigned __int8 *)v2;
if ( (unsigned __int8)v3 <= 0x3Du )
{
v4 = 0x2000000100000200LL;
if ( _bittest64(&v4, v3) )
{
do
v3 = *(unsigned __int8 *)++v2;
while ( (unsigned __int8)v3 <= 0x3Du && _bittest64(&v4, v3) );
}
}
v1 = 0LL;
if ( (_BYTE)v3 )
{
strncpy(&buf_line, v2, 0x3FFuLL);
if ( buf_line == 10 || !buf_line )
{
v5 = &buf_line;
}
else
{
v5 = &buf_line;
do
++v5;
while ( *v5 != 10 && *v5 );
}
*v5 = 0;
v1 = &buf_line;
}
}
return v1;
}

original_code:
char * getconfs(const char *name)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 if ((line = first_match(name)) == ((void *)0))
  return ((void *)0);
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 if (strlen(line) == 0)
  return ((void *)0);
 strncpy(buf_line, line, 1024 - 1);
 char *temp = buf_line;
 while (*temp != '\n' && *temp != '\0') ++temp;
 *temp = '\0';
 return buf_line;
}

canonical_original_code:
char *getconfs(char *name)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 if ((line = first_match(name)) == ((void *)0))
  return ((void *)0);
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 if (strlen(line) == 0)
  return ((void *)0);
 strncpy(buf_line, line, 1024 - 1);
 char *temp = buf_line;
 while (*temp != '\n' && *temp != '\0') ++temp;
 *temp = '\0';
 return buf_line;
}

variable_types:
line
char *

variable_types:
temp
char *


decompiled_code:
_BOOL8 __fastcall setconf1(char *s2, __int64 a2)
{
const char *v2; // rbx
char *v3; // rdi
unsigned __int64 v4; // rax
__int64 v5; // rdx
unsigned __int64 v6; // rax

if ( !s2 )
return 0LL;
if ( !conf_status )
readconf();
v2 = first_match(s2);
if ( !v2 )
return 0LL;
v3 = (char *)&v2[strlen(s2)];
v4 = (unsigned __int8)*v3;
if ( (unsigned __int8)v4 <= 0x3Du )
{
v5 = 0x2000000100000200LL;
if ( _bittest64(&v5, v4) )
{
do
v6 = (unsigned __int8)*++v3;
while ( (unsigned __int8)v6 <= 0x3Du && _bittest64(&v5, v6) );
}
}
sprintf(v3, "%ld\n", a2);
return (unsigned int)writeconf() != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(char *s2, __int64 a2)
{
const char *v2; // rbx
char *v3; // rdi
unsigned __int64 v4; // rax
__int64 v5; // rdx
unsigned __int64 v6; // rax

if ( !s2 )
return 0LL;
if ( !conf_status )
func1();
v2 = func0(s2);
if ( !v2 )
return 0LL;
v3 = (char *)&v2[strlen(s2)];
v4 = (unsigned __int8)*v3;
if ( (unsigned __int8)v4 <= 0x3Du )
{
v5 = 0x2000000100000200LL;
if ( _bittest64(&v5, v4) )
{
do
v6 = (unsigned __int8)*++v3;
while ( (unsigned __int8)v6 <= 0x3Du && _bittest64(&v5, v6) );
}
}
sprintf(v3, "%ld\n", a2);
return (unsigned int)func2() != 0;
}

original_code:
int setconf1(const char *name, long value)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 if ((line = first_match(name)) == ((void *)0))
  return 0;
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 sprintf(line, "%ld\n", value);
 if (!writeconf())
  return 0;
 return 1;
}

canonical_original_code:
int setconf1(char *name, long value)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 if ((line = first_match(name)) == ((void *)0))
  return 0;
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 sprintf(line, "%ld\n", value);
 if (!writeconf())
  return 0;
 return 1;
}

variable_types: value long


decompiled_code:
_BOOL8 __fastcall setconf2(char *s2, int a2, __int64 a3)
{
const char *v4; // r12
const char *v5; // r14
__int64 v6; // rbp
char *v7; // rbx
unsigned __int64 v8; // rax
size_t v9; // rbx
const unsigned __int16 *v10; // rdi
__int64 i; // rax
unsigned __int64 v12; // rdx
char nptr[1080]; // [rsp+10h] [rbp-438h] BYREF

if ( !s2 )
return 0LL;
if ( !conf_status )
readconf();
if ( dword_100C60 <= 0 )
return 0LL;
v4 = config;
v5 = (char *)&unk_1060 + 1024 * (unsigned __int64)(unsigned int)(dword_100C60 - 1);
v6 = 0x2000000100000200LL;
do
{
v9 = strlen(s2);
if ( !strncmp(v4, s2, v9) )
{
v7 = (char *)&v4[v9];
if ( *v7 == 32 || *v7 == 9 )
{
do
{
do
++v7;
while ( *v7 == 32 );
}
while ( *v7 == 9 );
}
v10 = *_ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v12 = (unsigned __int8)*v7;
if ( (v10[(char)v12] & 0x800) == 0 )
break;
nptr[i] = v12;
++v7;
}
nptr[(int)i] = 0;
if ( (unsigned __int8)v12 <= 0x3Du && _bittest64(&v6, v12) )
{
do
v8 = (unsigned __int8)*++v7;
while ( (unsigned __int8)v8 <= 0x3Du && _bittest64(&v6, v8) );
}
if ( atoi(nptr) == a2 )
{
sprintf(v7, "%ld\n", a3);
return (unsigned int)writeconf() != 0;
}
}
v4 += 1024;
}
while ( v4 != v5 );
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(char *s2, int a2, __int64 a3)
{
const char *v4; // r12
const char *v5; // r14
__int64 v6; // rbp
char *v7; // rbx
unsigned __int64 v8; // rax
size_t v9; // rbx
const unsigned __int16 *v10; // rdi
__int64 i; // rax
unsigned __int64 v12; // rdx
char nptr[1080]; // [rsp+10h] [rbp-438h] BYREF

if ( !s2 )
return 0LL;
if ( !conf_status )
func1();
if ( dword_100C60 <= 0 )
return 0LL;
v4 = config;
v5 = (char *)&unk_1060 + 1024 * (unsigned __int64)(unsigned int)(dword_100C60 - 1);
v6 = 0x2000000100000200LL;
do
{
v9 = strlen(s2);
if ( !strncmp(v4, s2, v9) )
{
v7 = (char *)&v4[v9];
if ( *v7 == 32 || *v7 == 9 )
{
do
{
do
++v7;
while ( *v7 == 32 );
}
while ( *v7 == 9 );
}
v10 = *_ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v12 = (unsigned __int8)*v7;
if ( (v10[(char)v12] & 0x800) == 0 )
break;
nptr[i] = v12;
++v7;
}
nptr[(int)i] = 0;
if ( (unsigned __int8)v12 <= 0x3Du && _bittest64(&v6, v12) )
{
do
v8 = (unsigned __int8)*++v7;
while ( (unsigned __int8)v8 <= 0x3Du && _bittest64(&v6, v8) );
}
if ( atoi(nptr) == a2 )
{
sprintf(v7, "%ld\n", a3);
return (unsigned int)func2() != 0;
}
}
v4 += 1024;
}
while ( v4 != v5 );
return 0LL;
}

original_code:
int setconf2(const char *name, int key, long value)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 int i, j;
 char num[1024];
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], name, strlen(name)))
  {
   line = config.buf[i];
   line += strlen(name);
   while ( *line == ' ' || *line == '\t') ++line;
   j = 0;
   while (((*__ctype_b_loc ())[(int) ((*line))] & (unsigned short int) _ISdigit))
   {
    num[j++] = *line;
    ++line;
   }
   num[j] = '\0';
   while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
   if (atoi(num) == key)
   {
    sprintf(line, "%ld\n", value);
    if (!writeconf())
     return 0;
    return 1;
   }
  }
 }
 return 0;
}

canonical_original_code:
int setconf2(char *name, int key, long value)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 int i; int j;
 char num[1024];
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], name, strlen(name)))
  {
   line = config.buf[i];
   line += strlen(name);
   while ( *line == ' ' || *line == '\t') ++line;
   j = 0;
   while (((*__ctype_b_loc ())[(int) ((*line))] & (unsigned short) _ISdigit))
   {
    num[j++] = *line;
    ++line;
   }
   num[j] = '\0';
   while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
   if (atoi(num) == key)
   {
    sprintf(line, "%ld\n", value);
    if (!writeconf())
     return 0;
    return 1;
   }
  }
 }
 return 0;
}

variable_types: key int

variable_types: i int

variable_types: j int

variable_types:
num
char [1024]


decompiled_code:
void limit_init()
{
_BYTE *v0; // rbx
int v1; // er12
int v2; // ebp
_BYTE *v3; // rdi
const char *v4; // rbx
const char *v5; // rdi
unsigned __int64 v6; // rax
__int64 v7; // rdx
unsigned __int64 v8; // rax
unsigned int v9; // [rsp+0h] [rbp-24h] BYREF
unsigned int v10; // [rsp+4h] [rbp-20h] BYREF
unsigned __int16 v11; // [rsp+8h] [rbp-1Ch] BYREF

if ( limit_stat != 1 )
{
if ( !conf_status )
readconf();
if ( dword_100C60 <= 0 )
goto LABEL_20;
v0 = &unk_C6B;
v1 = 0;
v2 = 0;
do
{
if ( !memcmp(v0 - 11, "serverlimit", 0xBuLL) )
{
v3 = v0;
if ( *v0 == 32 || *v0 == 9 )
{
do
{
do
++v3;
while ( *v3 == 32 );
}
while ( *v3 == 9 );
}
_isoc99_sscanf(v3, "%d = %d %d", &v11, &v9, &v10);
addto_limd(v11, v9, v10);
++v1;
}
++v2;
v0 += 1024;
}
while ( dword_100C60 > v2 );
if ( !v1 )
LABEL_20:
err_exit("In limit_init: No limit data in config");
v4 = first_match("timelevel");
if ( !v4 )
err_exit("In limit_init: can not find %s in config file", "timelevel");
v5 = v4 + 9;
v6 = *((unsigned __int8 *)v4 + 9);
if ( (unsigned __int8)v6 <= 0x3Du )
{
v7 = 0x2000000100000200LL;
if ( _bittest64(&v7, v6) )
{
do
v8 = *(unsigned __int8 *)++v5;
while ( (unsigned __int8)v8 <= 0x3Du && _bittest64(&v7, v8) );
}
}
_isoc99_sscanf(v5, "%d %d", &timel1, &timel2);
if ( !timel1 || !timel2 )
err_exit("In limit_init: illegal timelevel");
warning_rate = getconf1("warningrate");
if ( !warning_rate )
err_exit("In limit_init: warningrate is illegal");
limit_stat = 1;
}
}

canonical_decompiled_code:
void func8()
{
_BYTE *v0; // rbx
int v1; // er12
int v2; // ebp
_BYTE *v3; // rdi
const char *v4; // rbx
const char *v5; // rdi
unsigned __int64 v6; // rax
__int64 v7; // rdx
unsigned __int64 v8; // rax
unsigned int v9; // [rsp+0h] [rbp-24h] BYREF
unsigned int v10; // [rsp+4h] [rbp-20h] BYREF
unsigned __int16 v11; // [rsp+8h] [rbp-1Ch] BYREF

if ( limit_stat != 1 )
{
if ( !conf_status )
func1();
if ( dword_100C60 <= 0 )
goto LABEL_20;
v0 = &unk_C6B;
v1 = 0;
v2 = 0;
do
{
if ( !memcmp(v0 - 11, "serverlimit", 0xBuLL) )
{
v3 = v0;
if ( *v0 == 32 || *v0 == 9 )
{
do
{
do
++v3;
while ( *v3 == 32 );
}
while ( *v3 == 9 );
}
_isoc99_sscanf(v3, "%d = %d %d", &v11, &v9, &v10);
addto_limd(v11, v9, v10);
++v1;
}
++v2;
v0 += 1024;
}
while ( dword_100C60 > v2 );
if ( !v1 )
LABEL_20:
err_exit("In limit_init: No limit data in config");
v4 = func0("timelevel");
if ( !v4 )
err_exit("In limit_init: can not find %s in config file", "timelevel");
v5 = v4 + 9;
v6 = *((unsigned __int8 *)v4 + 9);
if ( (unsigned __int8)v6 <= 0x3Du )
{
v7 = 0x2000000100000200LL;
if ( _bittest64(&v7, v6) )
{
do
v8 = *(unsigned __int8 *)++v5;
while ( (unsigned __int8)v8 <= 0x3Du && _bittest64(&v7, v8) );
}
}
_isoc99_sscanf(v5, "%d %d", &timel1, &timel2);
if ( !timel1 || !timel2 )
err_exit("In limit_init: illegal timelevel");
warning_rate = func3("warningrate");
if ( !warning_rate )
err_exit("In limit_init: warningrate is illegal");
limit_stat = 1;
}
}

original_code:
void limit_init(void)
{
 if (limit_stat == 1)
  return;
 if (conf_status == 0)
 {
  readconf();
 }
 char *name = "serverlimit";
 char *line;
 int sid, temp[2];
 int i, j = 0;
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], name, strlen(name)))
  {
   line = config.buf[i];
   line += strlen(name);
   while ( *line == ' '|| *line == '\t') ++line;
   sscanf(line, "%d = %d %d", &sid, temp, temp + 1);
   addto_limd(sid, temp[0], temp[1]);
   ++j;
  }
 }
 if (j == 0)
  err_exit("In limit_init: No limit data in config");
 name = "timelevel";
 if ((line = first_match(name)) == ((void *)0))
  err_exit("In limit_init: can not find %s in config file",name);
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 sscanf(line, "%d %d", &timel1, &timel2);
 if (timel1 == 0 || timel2 == 0)
  err_exit("In limit_init: illegal timelevel");
 if ((warning_rate = getconf1("warningrate")) == 0)
  err_exit("In limit_init: warningrate is illegal");
 limit_stat = 1;
 return;
}

canonical_original_code:
void limit_init()
{
 if (limit_stat == 1)
  return;
 if (conf_status == 0)
 {
  readconf();
 }
 char *name = "serverlimit";
 char *line;
 int sid; int temp[2];
 int i; int j = 0;
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], name, strlen(name)))
  {
   line = config.buf[i];
   line += strlen(name);
   while ( *line == ' '|| *line == '\t') ++line;
   sscanf(line, "%d = %d %d", &sid, temp, temp + 1);
   addto_limd(sid, temp[0], temp[1]);
   ++j;
  }
 }
 if (j == 0)
  err_exit("In limit_init: No limit data in config");
 name = "timelevel";
 if ((line = first_match(name)) == ((void *)0))
  err_exit("In limit_init: can not find %s in config file",name);
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 sscanf(line, "%d %d", &timel1, &timel2);
 if (timel1 == 0 || timel2 == 0)
  err_exit("In limit_init: illegal timelevel");
 if ((warning_rate = getconf1("warningrate")) == 0)
  err_exit("In limit_init: warningrate is illegal");
 limit_stat = 1;
 return;
}

variable_types: sid int

variable_types:
temp
int [2]


decompiled_code:
const char *__fastcall first_match(char *s2)
{
int v1; // er12
size_t v2; // r13
const char *v3; // rbx
const char *v4; // r12
const char *v5; // r14

if ( !s2 )
return 0LL;
v1 = dword_100C60;
if ( dword_100C60 <= 0 )
return 0LL;
v2 = strlen(s2);
v3 = config;
v4 = (char *)&unk_1060 + 1024 * (unsigned __int64)(unsigned int)(v1 - 1);
while ( 1 )
{
v5 = v3;
if ( !strncmp(v3, s2, v2) )
break;
v3 += 1024;
if ( v3 == v4 )
return 0LL;
}
return v5;
}

canonical_decompiled_code:
const char *__fastcall func0(char *s2)
{
int v1; // er12
size_t v2; // r13
const char *v3; // rbx
const char *v4; // r12
const char *v5; // r14

if ( !s2 )
return 0LL;
v1 = dword_100C60;
if ( dword_100C60 <= 0 )
return 0LL;
v2 = strlen(s2);
v3 = config;
v4 = (char *)&unk_1060 + 1024 * (unsigned __int64)(unsigned int)(v1 - 1);
while ( 1 )
{
v5 = v3;
if ( !strncmp(v3, s2, v2) )
break;
v3 += 1024;
if ( v3 == v4 )
return 0LL;
}
return v5;
}

original_code:
static char * first_match(const char *head)
{
 if (((void *)0) == head)
  return ((void *)0);
 int i;
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], head, strlen(head)))
   return config.buf[i];
 }
 return ((void *)0);
}

canonical_original_code:
static char *first_match(char *head)
{
 if (((void *)0) == head)
  return ((void *)0);
 int i;
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], head, strlen(head)))
   return config.buf[i];
 }
 return ((void *)0);
}

variable_types:
head
char *


decompiled_code:
__int64 __fastcall getconf1(char *s2)
{
const char *v1; // rbx
const char *v2; // rdi
unsigned __int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rdx

if ( !s2 )
return 0LL;
if ( !conf_status )
readconf();
v1 = first_match(s2);
if ( !v1 )
return 0LL;
v2 = &v1[strlen(s2)];
v3 = *(unsigned __int8 *)v2;
if ( (unsigned __int8)v3 <= 0x3Du )
{
v4 = 0x2000000100000200LL;
if ( _bittest64(&v4, v3) )
{
do
v3 = *(unsigned __int8 *)++v2;
while ( (unsigned __int8)v3 <= 0x3Du && _bittest64(&v4, v3) );
}
}
v5 = 0LL;
if ( (_BYTE)v3 )
v5 = atol(v2);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2)
{
const char *v1; // rbx
const char *v2; // rdi
unsigned __int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rdx

if ( !s2 )
return 0LL;
if ( !conf_status )
func1();
v1 = func0(s2);
if ( !v1 )
return 0LL;
v2 = &v1[strlen(s2)];
v3 = *(unsigned __int8 *)v2;
if ( (unsigned __int8)v3 <= 0x3Du )
{
v4 = 0x2000000100000200LL;
if ( _bittest64(&v4, v3) )
{
do
v3 = *(unsigned __int8 *)++v2;
while ( (unsigned __int8)v3 <= 0x3Du && _bittest64(&v4, v3) );
}
}
v5 = 0LL;
if ( (_BYTE)v3 )
v5 = atol(v2);
return v5;
}

original_code:
long getconf1(const char *name)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 if ((line = first_match(name)) == ((void *)0))
  return 0;
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 if (strlen(line) == 0)
  return 0;
 return (atol(line));
}

canonical_original_code:
long getconf1(char *name)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 if ((line = first_match(name)) == ((void *)0))
  return 0;
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 if (strlen(line) == 0)
  return 0;
 return (atol(line));
}

variable_types:
name
char *

return_type: long


decompiled_code:
__int64 __fastcall getconf2(char *s2, int a2)
{
const char *v3; // r12
const char *v4; // r14
__int64 v5; // rbp
const char *v6; // rbx
unsigned __int64 v7; // rax
size_t v8; // rbx
const unsigned __int16 *v9; // rdi
__int64 i; // rax
unsigned __int64 v11; // rdx
char v13[1080]; // [rsp+0h] [rbp-438h] BYREF

if ( !s2 )
return 0LL;
if ( !conf_status )
readconf();
if ( dword_100C60 <= 0 )
return 0LL;
v3 = config;
v4 = (char *)&unk_1060 + 1024 * (unsigned __int64)(unsigned int)(dword_100C60 - 1);
v5 = 0x2000000100000200LL;
do
{
v8 = strlen(s2);
if ( !strncmp(v3, s2, v8) )
{
v6 = &v3[v8];
if ( *v6 == 32 || *v6 == 9 )
{
do
{
do
++v6;
while ( *v6 == 32 );
}
while ( *v6 == 9 );
}
v9 = *_ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v11 = *(unsigned __int8 *)v6;
if ( (v9[(char)v11] & 0x800) == 0 )
break;
v13[i] = v11;
++v6;
}
v13[(int)i] = 0;
if ( (unsigned __int8)v11 <= 0x3Du && _bittest64(&v5, v11) )
{
do
v7 = *(unsigned __int8 *)++v6;
while ( (unsigned __int8)v7 <= 0x3Du && _bittest64(&v5, v7) );
}
if ( atoi(v13) == a2 )
return atol(v6);
}
v3 += 1024;
}
while ( v3 != v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2, int a2)
{
const char *v3; // r12
const char *v4; // r14
__int64 v5; // rbp
const char *v6; // rbx
unsigned __int64 v7; // rax
size_t v8; // rbx
const unsigned __int16 *v9; // rdi
__int64 i; // rax
unsigned __int64 v11; // rdx
char v13[1080]; // [rsp+0h] [rbp-438h] BYREF

if ( !s2 )
return 0LL;
if ( !conf_status )
func1();
if ( dword_100C60 <= 0 )
return 0LL;
v3 = config;
v4 = (char *)&unk_1060 + 1024 * (unsigned __int64)(unsigned int)(dword_100C60 - 1);
v5 = 0x2000000100000200LL;
do
{
v8 = strlen(s2);
if ( !strncmp(v3, s2, v8) )
{
v6 = &v3[v8];
if ( *v6 == 32 || *v6 == 9 )
{
do
{
do
++v6;
while ( *v6 == 32 );
}
while ( *v6 == 9 );
}
v9 = *_ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v11 = *(unsigned __int8 *)v6;
if ( (v9[(char)v11] & 0x800) == 0 )
break;
v13[i] = v11;
++v6;
}
v13[(int)i] = 0;
if ( (unsigned __int8)v11 <= 0x3Du && _bittest64(&v5, v11) )
{
do
v7 = *(unsigned __int8 *)++v6;
while ( (unsigned __int8)v7 <= 0x3Du && _bittest64(&v5, v7) );
}
if ( atoi(v13) == a2 )
return atol(v6);
}
v3 += 1024;
}
while ( v3 != v4 );
return 0LL;
}

original_code:
long getconf2(const char *name, int key)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 int i, j;
 char num[1024];
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], name, strlen(name)))
  {
   line = config.buf[i];
   line += strlen(name);
   while ( *line == ' ' || *line == '\t') ++line;
   j = 0;
   while (((*__ctype_b_loc ())[(int) ((*line))] & (unsigned short int) _ISdigit))
   {
    num[j++] = *line;
    ++line;
   }
   num[j] = '\0';
   while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
   if (atoi(num) == key)
    return (atol(line));
  }
 }
 return 0;
}

canonical_original_code:
long getconf2(char *name, int key)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 int i; int j;
 char num[1024];
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], name, strlen(name)))
  {
   line = config.buf[i];
   line += strlen(name);
   while ( *line == ' ' || *line == '\t') ++line;
   j = 0;
   while (((*__ctype_b_loc ())[(int) ((*line))] & (unsigned short) _ISdigit))
   {
    num[j++] = *line;
    ++line;
   }
   num[j] = '\0';
   while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
   if (atoi(num) == key)
    return (atol(line));
  }
 }
 return 0;
}


rflsucom

decompiled_code:
__int64 __fastcall rflsucom(const void *a1, const void *a2)
{
return *(unsigned __int8 *)a1 - (unsigned int)*(unsigned __int8 *)a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return *(unsigned __int8 *)a1 - (unsigned int)*(unsigned __int8 *)a2;
}

original_code:
static int rflsucom(const void * p1, const void * p2)
{
 return (((flsunit *)p1)->server.id - ((flsunit *)p2)->server.id);
}

canonical_original_code:
static int rflsucom(void *p1, void *p2)
{
 return (((struct flsunit *)p1)->server.id - ((struct flsunit *)p2)->server.id);
}

user_defined_types: struct flsunit { struct addr server; int delaycount; int delaytime; long delaystart; }

user_defined_types: struct addr { unsigned char id; unsigned char zero; unsigned short port; unsigned int ip; }


decompiled_code:
__int64 __fastcall addto_rflsl(__int64 a1)
{
__int64 result; // rax
int v2; // edx

result = 0xFFFFFFFFLL;
if ( a1 )
{
result = add_item(a1);
if ( (_DWORD)result )
{
qsort(rflsl, SLODWORD(rflsl[384]), 0x18uLL, (__compar_fn_t)rflsucom);
v2 = write_rflsl();
result = 1LL;
if ( !v2 )
{
run_msg("In addto_rflsl: write_rflsl error");
result = 1LL;
}
}
}
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a1 )
{
result = func1(a1);
if ( (_DWORD)result )
{
qsort(rflsl, SLODWORD(rflsl[384]), 0x18uLL, (__compar_fn_t)rflsucom);
v2 = func2();
result = 1LL;
if ( !v2 )
{
run_msg("In addto_rflsl: write_rflsl error");
result = 1LL;
}
}
}
return result;
}

original_code:
int addto_rflsl(addr *ptr)
{
 if (((void *)0) == ptr)
  return -1;
 if (!add_item(ptr))
  return 0;
 qsort(rflsl.list, rflsl.len, sizeof(flsunit), rflsucom);
 if (!write_rflsl())
  run_msg("In addto_rflsl: write_rflsl error");
 return 1;
}

canonical_original_code:
int addto_rflsl(struct addr *ptr)
{
 if (((void *)0) == ptr)
  return -1;
 if (!add_item(ptr))
  return 0;
 qsort(rflsl.list, rflsl.len, sizeof(flsunit), rflsucom);
 if (!write_rflsl())
  run_msg("In addto_rflsl: write_rflsl error");
 return 1;
}

variable_types: struct addr { unsigned char id; unsigned char zero; unsigned short port; unsigned int ip; } *


decompiled_code:
__int64 __fastcall remove_rflsl(char *a1)
{
char v1; // cl
__int64 result; // rax
__int64 v3; // rdx
int v4; // edx
const __m128i *v5; // rdx
__m128i *v6; // rcx
__int64 v7; // rax
int v8; // edx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
result = 0LL;
if ( *a1 != localaddr )
{
if ( v1 == LOBYTE(rflsl[0]) )
{
LODWORD(result) = 0;
LABEL_7:
v4 = rflsl[384];
if ( v4 <= (int)result )
{
result = 1LL;
}
else
{
if ( v4 - 1 > (int)result )
{
v5 = (const __m128i *)&rflsl[3 * (int)result];
do
{
v6 = (__m128i *)v5;
v5 = (const __m128i *)((char *)v5 + 24);
*v6 = _mm_loadu_si128(v5);
v6[1].m128i_i64[0] = v5[1].m128i_i64[0];
LODWORD(result) = result + 1;
}
while ( LODWORD(rflsl[384]) - 1 > (int)result );
}
v7 = 3LL * (int)result;
rflsl[v7] = 0LL;
rflsl[v7 + 1] = 0LL;
rflsl[v7 + 2] = 0LL;
--LODWORD(rflsl[384]);
v8 = write_rflsl();
result = 1LL;
if ( !v8 )
{
run_msg("In remove_rflsl: write_rflsl error");
result = 1LL;
}
}
}
else
{
v3 = (unsigned int)((_DWORD)rflsl + 24);
while ( SLODWORD(rflsl[384]) > (int)result )
{
LODWORD(result) = result + 1;
v3 += 24LL;
if ( v1 == *(_BYTE *)(v3 - 24) )
goto LABEL_7;
}
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
char v1; // cl
__int64 result; // rax
__int64 v3; // rdx
int v4; // edx
const __m128i *v5; // rdx
__m128i *v6; // rcx
__int64 v7; // rax
int v8; // edx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
result = 0LL;
if ( *a1 != localaddr )
{
if ( v1 == LOBYTE(rflsl[0]) )
{
LODWORD(result) = 0;
LABEL_7:
v4 = rflsl[384];
if ( v4 <= (int)result )
{
result = 1LL;
}
else
{
if ( v4 - 1 > (int)result )
{
v5 = (const __m128i *)&rflsl[3 * (int)result];
do
{
v6 = (__m128i *)v5;
v5 = (const __m128i *)((char *)v5 + 24);
*v6 = _mm_loadu_si128(v5);
v6[1].m128i_i64[0] = v5[1].m128i_i64[0];
LODWORD(result) = result + 1;
}
while ( LODWORD(rflsl[384]) - 1 > (int)result );
}
v7 = 3LL * (int)result;
rflsl[v7] = 0LL;
rflsl[v7 + 1] = 0LL;
rflsl[v7 + 2] = 0LL;
--LODWORD(rflsl[384]);
v8 = func2();
result = 1LL;
if ( !v8 )
{
run_msg("In remove_rflsl: write_rflsl error");
result = 1LL;
}
}
}
else
{
v3 = (unsigned int)((_DWORD)rflsl + 24);
while ( SLODWORD(rflsl[384]) > (int)result )
{
LODWORD(result) = result + 1;
v3 += 24LL;
if ( v1 == *(_BYTE *)(v3 - 24) )
goto LABEL_7;
}
result = 1LL;
}
}
return result;
}

original_code:
int remove_rflsl(addr *ptr)
{
 if (((void *)0) == ptr)
  return -1;
 int i = 0;
 if (ptr->id == localaddr.id)
  return 0;
 while (ptr->id != rflsl.list[i].server.id && i < rflsl.len)
  ++i;
 if (i >= rflsl.len)
  return 1;
 for ( ; i < (rflsl.len - 1); ++i)
  memcpy(rflsl.list + i, rflsl.list + i + 1, sizeof(flsunit));
 memset(rflsl.list + i, '\0', sizeof(flsunit));
 --rflsl.len;
 if (!write_rflsl())
  run_msg("In remove_rflsl: write_rflsl error");
 return 1;
}

canonical_original_code:
int remove_rflsl(struct addr *ptr)
{
 if (((void *)0) == ptr)
  return -1;
 int i = 0;
 if (ptr->id == localaddr.id)
  return 0;
 while (ptr->id != rflsl.list[i].server.id && i < rflsl.len)
  ++i;
 if (i >= rflsl.len)
  return 1;
 for ( ; i < (rflsl.len - 1); ++i)
  memcpy(rflsl.list + i, rflsl.list + i + 1, sizeof(flsunit));
 memset(rflsl.list + i, '\0', sizeof(flsunit));
 --rflsl.len;
 if (!write_rflsl())
  run_msg("In remove_rflsl: write_rflsl error");
 return 1;
}


decompiled_code:
__int16 manage_fls_init()
{
int v0; // ebx
const char *v1; // rsi
__int16 v2; // ax
__int16 result; // ax
struct in_addr inp; // [rsp+Ch] [rbp-40Ch] BYREF
char dest[1032]; // [rsp+10h] [rbp-408h] BYREF

v0 = getconf1("manageflsid");
if ( (unsigned int)(v0 - 1) > 0xFE )
err_exit("In manage_fls_init: manageflsid is illegal");
manage_fls_addr = v0;
if ( !localaddr )
err_exit("In manage_fls_init: localaddr id is illegal");
manage_switch = manage_fls_addr == localaddr;
v1 = (const char *)getconfs("manageflsip");
if ( !strncpy(dest, v1, 0x3FFuLL) )
err_exit("In manage_fls_init: get manageflsip error");
inet_aton(dest, &inp);
*((struct in_addr *)&manage_fls_addr + 1) = inp;
v2 = getconf1("manageflsport");
*((_WORD *)&manage_fls_addr + 1) = v2;
if ( !v2 )
err_exit("In manage_fls_init: manageflsport is illegal");
result = _bswap_16(*((_WORD *)&manage_fls_addr + 1));
*((_WORD *)&manage_fls_addr + 1) = result;
return result;
}

canonical_decompiled_code:
__int16 func9()
{
int v0; // ebx
const char *v1; // rsi
__int16 v2; // ax
__int16 result; // ax
struct in_addr inp; // [rsp+Ch] [rbp-40Ch] BYREF
char dest[1032]; // [rsp+10h] [rbp-408h] BYREF

v0 = getconf1("manageflsid");
if ( (unsigned int)(v0 - 1) > 0xFE )
err_exit("In manage_fls_init: manageflsid is illegal");
manage_fls_addr = v0;
if ( !localaddr )
err_exit("In manage_fls_init: localaddr id is illegal");
manage_switch = manage_fls_addr == localaddr;
v1 = (const char *)getconfs("manageflsip");
if ( !strncpy(dest, v1, 0x3FFuLL) )
err_exit("In manage_fls_init: get manageflsip error");
inet_aton(dest, &inp);
*((struct in_addr *)&manage_fls_addr + 1) = inp;
v2 = getconf1("manageflsport");
*((_WORD *)&manage_fls_addr + 1) = v2;
if ( !v2 )
err_exit("In manage_fls_init: manageflsport is illegal");
result = func3(*((_WORD *)&manage_fls_addr + 1));
*((_WORD *)&manage_fls_addr + 1) = result;
return result;
}

original_code:
void manage_fls_init(void)
{
 int id_temp = getconf1("manageflsid");
 if (id_temp <= 0 || id_temp > 255)
  err_exit("In manage_fls_init: manageflsid is illegal");
 manage_fls_addr.id = id_temp;
 if (localaddr.id == 0)
  err_exit("In manage_fls_init: localaddr id is illegal");
 if (manage_fls_addr.id == localaddr.id)
 {
  manage_switch = 1;
 }
 else
 {
  manage_switch = 0;
 }
 char ip_string[1024];
 struct in_addr inaddr;
 if (strncpy(ip_string, getconfs("manageflsip"), 1024 - 1) == 0)
  err_exit("In manage_fls_init: get manageflsip error");
 inet_aton(ip_string, &(inaddr));
 manage_fls_addr.ip = inaddr.s_addr;
 if ((manage_fls_addr.port = (uint16_t)getconf1("manageflsport")) == 0)
  err_exit("In manage_fls_init: manageflsport is illegal");
 manage_fls_addr.port = htons(manage_fls_addr.port);
}

canonical_original_code:
void manage_fls_init()
{
 int id_temp = getconf1("manageflsid");
 if (id_temp <= 0 || id_temp > 255)
  err_exit("In manage_fls_init: manageflsid is illegal");
 manage_fls_addr.id = id_temp;
 if (localaddr.id == 0)
  err_exit("In manage_fls_init: localaddr id is illegal");
 if (manage_fls_addr.id == localaddr.id)
 {
  manage_switch = 1;
 }
 else
 {
  manage_switch = 0;
 }
 char ip_string[1024];
 struct in_addr inaddr;
 if (strncpy(ip_string, getconfs("manageflsip"), 1024 - 1) == 0)
  err_exit("In manage_fls_init: get manageflsip error");
 inet_aton(ip_string, &(inaddr));
 manage_fls_addr.ip = inaddr.s_addr;
 if ((manage_fls_addr.port = (unsigned short)getconf1("manageflsport")) == 0)
  err_exit("In manage_fls_init: manageflsport is illegal");
 manage_fls_addr.port = htons(manage_fls_addr.port);
}

variable_types:
inaddr
struct in_addr { unsigned int s_addr; }


decompiled_code:
__int64 inform_start()
{
int v0; // ebx
__int64 result; // rax

if ( !manage_fls_addr )
manage_fls_init();
v0 = 3;
if ( localaddr == manage_fls_addr )
{
addto_rflsl((__int64)&localaddr);
result = 1LL;
}
else
{
while ( 1 )
{
send_net7(&manage_fls_addr, 1LL);
result = recv_netpt(1);
if ( (_DWORD)result == 1 )
break;
if ( !--v0 )
return 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // ebx
__int64 result; // rax

if ( !manage_fls_addr )
func9();
v0 = 3;
if ( localaddr == manage_fls_addr )
{
func7((__int64)&localaddr);
result = 1LL;
}
else
{
while ( 1 )
{
send_net7(&manage_fls_addr, 1LL);
result = func5(1);
if ( (_DWORD)result == 1 )
break;
if ( !--v0 )
return 0LL;
}
}
return result;
}

original_code:
int inform_start(void)
{
 if (manage_fls_addr.id == 0)
 {
  manage_fls_init();
 }
 if (localaddr.id == manage_fls_addr.id)
 {
  addto_rflsl(&(localaddr));
  return 1;
 }
 int i, stat = 0;
 for (i = 0; i < 3; ++i)
 {
  send_net7(&(manage_fls_addr), 1);
  stat = recv_netpt(1);
  if (stat == 1)
  {
   return 1;
  }
  else
  {
   continue;
  }
 }
 return 0;
}

canonical_original_code:
int inform_start()
{
 if (manage_fls_addr.id == 0)
 {
  manage_fls_init();
 }
 if (localaddr.id == manage_fls_addr.id)
 {
  addto_rflsl(&(localaddr));
  return 1;
 }
 int i; int stat = 0;
 for (i = 0; i < 3; ++i)
 {
  send_net7(&(manage_fls_addr), 1);
  stat = recv_netpt(1);
  if (stat == 1)
  {
   return 1;
  }
  else
  {
   continue;
  }
 }
 return 0;
}


decompiled_code:
__int64 inform_close()
{
int v0; // ebx
__int64 result; // rax

if ( !manage_fls_addr )
manage_fls_init();
v0 = 3;
if ( localaddr == manage_fls_addr )
{
remove_rflsl((char *)&localaddr);
result = 1LL;
}
else
{
while ( 1 )
{
send_net7(&manage_fls_addr, 2LL);
result = recv_netpt(1);
if ( (_DWORD)result == 1 )
break;
if ( !--v0 )
return 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // ebx
__int64 result; // rax

if ( !manage_fls_addr )
func9();
v0 = 3;
if ( localaddr == manage_fls_addr )
{
func8((char *)&localaddr);
result = 1LL;
}
else
{
while ( 1 )
{
send_net7(&manage_fls_addr, 2LL);
result = func5(1);
if ( (_DWORD)result == 1 )
break;
if ( !--v0 )
return 0LL;
}
}
return result;
}

original_code:
int inform_close(void)
{
 if (manage_fls_addr.id == 0)
 {
  manage_fls_init();
 }
 if (localaddr.id == manage_fls_addr.id)
 {
  remove_rflsl(&(localaddr));
  return 1;
 }
 int i, stat = 0;
 for (i = 0; i < 3; ++i)
 {
  send_net7(&(manage_fls_addr), 2);
  stat = recv_netpt(1);
  if (stat == 1)
  {
   return 1;
  }
  else
  {
   continue;
  }
 }
 return 0;
}

canonical_original_code:
int inform_close()
{
 if (manage_fls_addr.id == 0)
 {
  manage_fls_init();
 }
 if (localaddr.id == manage_fls_addr.id)
 {
  remove_rflsl(&(localaddr));
  return 1;
 }
 int i; int stat = 0;
 for (i = 0; i < 3; ++i)
 {
  send_net7(&(manage_fls_addr), 2);
  stat = recv_netpt(1);
  if (stat == 1)
  {
   return 1;
  }
  else
  {
   continue;
  }
 }
 return 0;
}


decompiled_code:
__int64 __fastcall add_item(__int64 a1)
{
int v1; // ecx
__int64 result; // rax
__int64 *v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rsi

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = rflsl[384];
result = 0LL;
if ( v1 <= 127 )
{
if ( v1 <= 0 )
{
LABEL_7:
v4 = 3LL * v1;
rflsl[v4] = 0LL;
rflsl[v4 + 1] = 0LL;
rflsl[v4 + 2] = 0LL;
v5 = 3LL * v1;
LOBYTE(rflsl[v5]) = *(_BYTE *)a1;
WORD1(rflsl[v5]) = *(_WORD *)(a1 + 2);
HIDWORD(rflsl[3 * v1]) = *(_DWORD *)(a1 + 4);
++LODWORD(rflsl[384]);
result = 1LL;
}
else
{
v3 = rflsl;
while ( *(_BYTE *)a1 != *(_BYTE *)v3 )
{
LODWORD(result) = result + 1;
v3 += 3;
if ( v1 == (_DWORD)result )
goto LABEL_7;
}
v6 = 3LL * (int)result;
v7 = HIDWORD(rflsl[3 * (int)result]);
if ( *(_DWORD *)(a1 + 4) != (_DWORD)v7 || (result = 1LL, v7 = WORD1(rflsl[v6]), *(_WORD *)(a1 + 2) != (_WORD)v7) )
{
run_msg("fls id:%d confused!", v7);
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // ecx
__int64 result; // rax
__int64 *v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rsi

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = rflsl[384];
result = 0LL;
if ( v1 <= 127 )
{
if ( v1 <= 0 )
{
LABEL_7:
v4 = 3LL * v1;
rflsl[v4] = 0LL;
rflsl[v4 + 1] = 0LL;
rflsl[v4 + 2] = 0LL;
v5 = 3LL * v1;
LOBYTE(rflsl[v5]) = *(_BYTE *)a1;
WORD1(rflsl[v5]) = *(_WORD *)(a1 + 2);
HIDWORD(rflsl[3 * v1]) = *(_DWORD *)(a1 + 4);
++LODWORD(rflsl[384]);
result = 1LL;
}
else
{
v3 = rflsl;
while ( *(_BYTE *)a1 != *(_BYTE *)v3 )
{
LODWORD(result) = result + 1;
v3 += 3;
if ( v1 == (_DWORD)result )
goto LABEL_7;
}
v6 = 3LL * (int)result;
v7 = HIDWORD(rflsl[3 * (int)result]);
if ( *(_DWORD *)(a1 + 4) != (_DWORD)v7 || (result = 1LL, v7 = WORD1(rflsl[v6]), *(_WORD *)(a1 + 2) != (_WORD)v7) )
{
run_msg("fls id:%d confused!", v7);
result = 1LL;
}
}
}
return result;
}

original_code:
static int add_item(addr *ptr)
{
 if (((void *)0) == ptr)
  return -1;
 if (rflsl.len >= 128)
  return 0;
 int i;
 for (i = 0; i < rflsl.len; ++i)
  if (ptr->id == rflsl.list[i].server.id)
  {
   if (ptr->ip != rflsl.list[i].server.ip || ptr->port != rflsl.list[i].server.port)
   {
    run_msg("fls id:%d confused!");
   }
   return 1;
  }
 i = rflsl.len;
 memset(rflsl.list + i, '\0', sizeof(flsunit));
 rflsl.list[i].server.id = ptr->id;
 rflsl.list[i].server.port = ptr->port;
 rflsl.list[i].server.ip = ptr->ip;
 ++rflsl.len;
 return 1;
}

canonical_original_code:
static int add_item(struct addr *ptr)
{
 if (((void *)0) == ptr)
  return -1;
 if (rflsl.len >= 128)
  return 0;
 int i;
 for (i = 0; i < rflsl.len; ++i)
  if (ptr->id == rflsl.list[i].server.id)
  {
   if (ptr->ip != rflsl.list[i].server.ip || ptr->port != rflsl.list[i].server.port)
   {
    run_msg("fls id:%d confused!");
   }
   return 1;
  }
 i = rflsl.len;
 memset(rflsl.list + i, '\0', sizeof(flsunit));
 rflsl.list[i].server.id = ptr->id;
 rflsl.list[i].server.port = ptr->port;
 rflsl.list[i].server.ip = ptr->ip;
 ++rflsl.len;
 return 1;
}


original_code:
static void netpt7_init(netpt7 *send, addr *fls, uint8_t stat, uint16_t sid)
{
 bzero(send, sizeof(netpt7));
 pth_init(&(send->head),7, sizeof(netpt7), 1);
 send->body.stat = stat;
 send->body.sid = sid;
 if (fls != ((void *)0))
  send->body.fls = *fls;
 send->pef = 0X10;
}

canonical_original_code:
static void netpt7_init(struct netpt7 *send, struct addr *fls, unsigned char stat, unsigned short sid)
{
 bzero(send, sizeof(netpt7));
 pth_init(&(send->head),7, sizeof(netpt7), 1);
 send->body.stat = stat;
 send->body.sid = sid;
 if (fls != ((void *)0))
  send->body.fls = *fls;
 send->pef = 0X10;
}

variable_types: struct netpt7 { struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } head; struct pbody7 { unsigned char stat; char zero; unsigned short sid; struct addr { unsigned char id; unsigned char stat; unsigned short port; unsigned int ip; } fls; } body; char zero[3]; char pef; } *

variable_types:
fls
struct addr *

variable_types:
stat
unsigned char

variable_types:
sid
unsigned short

user_defined_types: struct netpt7 { struct phead head; struct pbody7 body; char zero[3]; char pef; }

user_defined_types: struct pbody7 { unsigned char stat; char zero; unsigned short sid; struct addr fls; }


original_code:
static void netpt1_init(netpt1 *send, uint16_t sid, uint32_t uid, uint16_t num)
{
 bzero(send, sizeof(netpt1));
 pth_init(&(send->head),1, sizeof(netpt1), uid);
 send->body.sid = sid;
 send->body.uid = uid;
 send->body.num = num;
 send->pef = 0X10;
}

canonical_original_code:
static void netpt1_init(struct netpt1 *send, unsigned short sid, unsigned int uid, unsigned short num)
{
 bzero(send, sizeof(netpt1));
 pth_init(&(send->head),1, sizeof(netpt1), uid);
 send->body.sid = sid;
 send->body.uid = uid;
 send->body.num = num;
 send->pef = 0X10;
}

variable_types: struct netpt1 { struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } head; struct pbody1 { unsigned int uid; unsigned short sid; unsigned short num; } body; char zero[3]; char pef; } *

variable_types:
uid
unsigned int

variable_types:
num
unsigned short

user_defined_types: struct netpt1 { struct phead head; struct pbody1 body; char zero[3]; char pef; }


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

*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 68) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 76) >> 3));
result = pth_init(a1, 3, 76, a3);
*(_WORD *)(a1 + 68) = a2;
*(_DWORD *)(a1 + 64) = a3;
*(_BYTE *)(a1 + 75) = 16;
return result;
}

original_code:
static void netpt3_init(netpt3 *send, uint16_t sid, uint32_t uid)
{
 bzero(send, sizeof(netpt3));
 pth_init(&(send->head),3, sizeof(netpt3), uid);
 send->body.sid = sid;
 send->body.uid = uid;
 send->pef = 0X10;
}

canonical_original_code:
static void netpt3_init(struct netpt3 *send, unsigned short sid, unsigned int uid)
{
 bzero(send, sizeof(netpt3));
 pth_init(&(send->head),3, sizeof(netpt3), uid);
 send->body.sid = sid;
 send->body.uid = uid;
 send->pef = 0X10;
}

variable_types: struct netpt3 { struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } head; struct pbody3 { unsigned int uid; unsigned short sid; char zero[2]; } body; char zero[3]; char pef; } *

user_defined_types: struct netpt3 { struct phead head; struct pbody3 body; char zero[3]; char pef; }


ntohpch

original_code:
static void ntohpch(phead *ptr)
{
 ptr->len = ntohs(ptr->len);
 ptr->subcmd = ntohs(ptr->subcmd);
 ptr->version = ntohs(ptr->version);
 ptr->uid = ntohl(ptr->uid);
 ptr->fls_id = ntohs(ptr->fls_id);
 ptr->fls_num = ntohs(ptr->fls_num);
}

canonical_original_code:
static void ntohpch(struct phead *ptr)
{
 ptr->len = ntohs(ptr->len);
 ptr->subcmd = ntohs(ptr->subcmd);
 ptr->version = ntohs(ptr->version);
 ptr->uid = ntohl(ptr->uid);
 ptr->fls_id = ntohs(ptr->fls_id);
 ptr->fls_num = ntohs(ptr->fls_num);
}

variable_types: struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } *