decompiled_code:
__int64 __fastcall snake_Move(int a1)
{
unsigned int *v1; // rax
unsigned int *v2; // rbx
__int64 v3; // rbx
unsigned int v4; // ebx
unsigned int v6; // er12
int v7; // ebp
unsigned int v8; // [rsp+8h] [rbp-20h] BYREF
unsigned int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = (unsigned int *)malloc(0x18uLL);
if ( !v1 )
return (unsigned int)-1;
v2 = v1;
Get_Next_xy(*(_DWORD *)(SnakeHead - 8), *(_DWORD *)(SnakeHead - 4), (int *)v9, (int *)&v8, a1);
*v2 = v9[0];
v2[1] = v8;
list_add((_QWORD *)v2 + 1, &SnakeHead);
DrawBody(*v2, v2[1]);
set_snakeMask(*v2, v2[1]);
if ( food == v9[0] && dword_40C == v8 )
{
do
{
GetFood_xy(&food);
v6 = dword_40C;
v7 = food;
v4 = is_OverSnakeBody(food, dword_40C);
}
while ( v4 );
DrawBody(v7, v6);
}
else
{
v3 = qword_418;
ClearBody(*(_DWORD *)(qword_418 - 8));
clear_snakeMask(*(_DWORD *)(v3 - 8), *(_DWORD *)(v3 - 4));
list_del(qword_418);
free((void *)(v3 - 8));
v4 = 0;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
unsigned int *v1; // rax
unsigned int *v2; // rbx
__int64 v3; // rbx
unsigned int v4; // ebx
unsigned int v6; // er12
int v7; // ebp
unsigned int v8; // [rsp+8h] [rbp-20h] BYREF
unsigned int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = (unsigned int *)malloc(0x18uLL);
if ( !v1 )
return (unsigned int)-1;
v2 = v1;
func5(*(_DWORD *)(SnakeHead - 8), *(_DWORD *)(SnakeHead - 4), (int *)v9, (int *)&v8, a1);
*v2 = v9[0];
v2[1] = v8;
func2((_QWORD *)v2 + 1, &SnakeHead);
func8(*v2, v2[1]);
func11(*v2, v2[1]);
if ( food == v9[0] && dword_40C == v8 )
{
do
{
func7(&food);
v6 = dword_40C;
v7 = food;
v4 = func14(food, dword_40C);
}
while ( v4 );
func8(v7, v6);
}
else
{
v3 = qword_418;
func9(*(_DWORD *)(qword_418 - 8));
func13(*(_DWORD *)(v3 - 8), *(_DWORD *)(v3 - 4));
func4(qword_418);
free((void *)(v3 - 8));
v4 = 0;
}
return v4;
}

original_code:
int snake_Move(int direction)
{
 int next_x, next_y;
 char *p;
 struct SnakeBody *pNew;
 struct SnakeBody *pHead;
 struct SnakeBody *pTail;
 int is_cover;
 p = malloc(sizeof(struct SnakeBody));
 if(p==((void *)0)){
  return -1;
 }
 pNew = (struct SnakeBody *)p;
 pHead = (struct SnakeBody *)((char *)SnakeHead.next -((size_t) &((struct SnakeBody *)0)->list));
 Get_Next_xy(pHead->x, pHead->y, &next_x, &next_y, direction);
 pNew->x = next_x;
 pNew->y = next_y;
 list_add(&(pNew->list), &SnakeHead);
 DrawBody(pNew->x, pNew->y);
 set_snakeMask(pNew->x, pNew->y);
 if((next_x == food.x)&&(next_y == food.y)){
  do{
   GetFood_xy(&food);
   is_cover = is_OverSnakeBody(food.x, food.y);
  }while(is_cover!=0);
  DrawBody(food.x, food.y);
  return 0;
 }
 pTail = (struct SnakeBody *)((char *)SnakeHead.prev -((size_t) &((struct SnakeBody *)0)->list));
 ClearBody(pTail->x, pTail->y);
 clear_snakeMask(pTail->x, pTail->y);
 list_del(SnakeHead.prev);
 free((char *)pTail);
 return 0;
}

canonical_original_code:
int snake_Move(int direction)
{
 int next_x; int next_y;
 char *p;
 struct SnakeBody *pNew;
 struct SnakeBody *pHead;
 struct SnakeBody *pTail;
 int is_cover;
 p = malloc(sizeof(struct SnakeBody));
 if(p==((void *)0)){
  return -1;
 }
 pNew = (struct SnakeBody *)p;
 pHead = (struct SnakeBody *)((char *)SnakeHead.next -((unsigned long) &((struct SnakeBody *)0)->list));
 Get_Next_xy(pHead->x, pHead->y, &next_x, &next_y, direction);
 pNew->x = next_x;
 pNew->y = next_y;
 list_add(&(pNew->list), &SnakeHead);
 DrawBody(pNew->x, pNew->y);
 set_snakeMask(pNew->x, pNew->y);
 if((next_x == food.x)&&(next_y == food.y)){
  do{
   GetFood_xy(&food);
   is_cover = is_OverSnakeBody(food.x, food.y);
  }while(is_cover!=0);
  DrawBody(food.x, food.y);
  return 0;
 }
 pTail = (struct SnakeBody *)((char *)SnakeHead.prev -((unsigned long) &((struct SnakeBody *)0)->list));
 ClearBody(pTail->x, pTail->y);
 clear_snakeMask(pTail->x, pTail->y);
 list_del(SnakeHead.prev);
 free((char *)pTail);
 return 0;
}

user_defined_types: struct list_head { struct list_head *next; }


repo: shmily/linux

decompiled_code:
_BOOL8 __fastcall ip_valid(int *a1)
{
int v1; // eax
int v2; // eax
int v3; // edx
int v4; // edx
int v5; // eax

v1 = *a1;
if ( v1 > 254 || v1 == 127 || !v1 )
return 0LL;
v2 = a1[1];
LOBYTE(v2) = 0;
v3 = a1[2];
LOBYTE(v3) = 0;
v4 = v2 + v3;
v5 = a1[3];
LOBYTE(v5) = 0;
return v4 + v5 <= 0;
}

variable_types:
ip
int *

variable_types: t int

return_type: int


decompiled_code:
_BOOL8 __fastcall mask_valid(_DWORD *a1)
{
_BOOL4 v1; // edx

v1 = 0;
if ( (unsigned int)(*a1 - 1) <= 0xFFFFFFFD )
v1 = (~*a1 & -*a1) == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_DWORD *a1)
{
_BOOL4 v1; // edx

v1 = 0;
if ( (unsigned int)(*a1 - 1) <= 0xFFFFFFFD )
v1 = (~*a1 & -*a1) == 0;
return v1;
}

original_code:
int mask_valid(int *mask)
{
 unsigned int b;
 b = (unsigned int)*mask;
 if((b==0xFFFFFFFF)||(b==0x00)) return 0;
 b = ~b + 1;
 b = b&(b-1);
 return (b==0)?1:0;
}

variable_types:
mask
int *

variable_types:
b
unsigned int


main

canonical_name: main

original_code:
int main(void)
{
 int ip[4];
 int mask[4];
 int i, count;
 int local, _mask, tmp;
 scanf("%d.%d.%d.%d", (ip), (ip+1), (ip+2), (ip+3));
 if(ip_valid(ip) == 0){
  printf("Invalid IP adress.\n");
  exit(0);
 }
 local = (ip[0]<<24) + (ip[1]<<16) + (ip[2]<<8) + ip[3];
 scanf("%d.%d.%d.%d", (mask), (mask+1), (mask+2), (mask+3));
 _mask = (mask[0]<<24) + (mask[1]<<16) + (mask[2]<<8) + mask[3];
 if(mask_valid(&_mask) == 0){
  printf("Invalid netmask adress.\n");
  exit(0);
 }
 local = local & _mask;
 scanf("%d", &count);
 for(i=0; i<count; i++){
  scanf("%d.%d.%d.%d", (ip), (ip+1), (ip+2), (ip+3));
  if(ip_valid(ip) == 0){
   printf("Invalid IP adress.\n");
   continue;
  }
  tmp = (ip[0]<<24) + (ip[1]<<16) + (ip[2]<<8) + ip[3];
  tmp = tmp & _mask;
  if(tmp == local){
   printf("let's rock\n");
  }else{
   printf("not you\n");
  }
 }
 exit(0);
}

canonical_original_code:
int main()
{
 int ip[4];
 int mask[4];
 int i; int count;
 int local; int _mask; int tmp;
 scanf("%d.%d.%d.%d", (ip), (ip+1), (ip+2), (ip+3));
 if(ip_valid(ip) == 0){
  printf("Invalid IP adress.\n");
  exit(0);
 }
 local = (ip[0]<<24) + (ip[1]<<16) + (ip[2]<<8) + ip[3];
 scanf("%d.%d.%d.%d", (mask), (mask+1), (mask+2), (mask+3));
 _mask = (mask[0]<<24) + (mask[1]<<16) + (mask[2]<<8) + mask[3];
 if(mask_valid(&_mask) == 0){
  printf("Invalid netmask adress.\n");
  exit(0);
 }
 local = local & _mask;
 scanf("%d", &count);
 for(i=0; i<count; i++){
  scanf("%d.%d.%d.%d", (ip), (ip+1), (ip+2), (ip+3));
  if(ip_valid(ip) == 0){
   printf("Invalid IP adress.\n");
   continue;
  }
  tmp = (ip[0]<<24) + (ip[1]<<16) + (ip[2]<<8) + ip[3];
  tmp = tmp & _mask;
  if(tmp == local){
   printf("let's rock\n");
  }else{
   printf("not you\n");
  }
 }
 exit(0);
}

variable_types:
ip
int [4]

variable_types:
mask
int [4]

variable_types: i int

variable_types: count int

variable_types: local int

variable_types: tmp int


original_code:
int infix_init(char *pstr, int *postfix, int *mask)
{
    int count;
    int sign = 1;
    int tmp;
    int *psave;
    while(*pstr==' '){
        pstr++;
    }
    if(*pstr=='-'){
        sign = -1;
        pstr++;
    }
    psave = postfix;
    count = 0;
    tmp = 0;
    while(*pstr!='\0'){
        if((*pstr>='0')&&(*pstr<='9')){
            tmp = tmp*10 + (*pstr - '0');
            pstr++;
        }else if((*pstr=='+')||(*pstr=='-')||(*pstr=='*')||(*pstr=='/')){
            *psave++ = tmp;
            *mask++ = 1;
            *psave++ = *pstr;
            *mask++ = 0;
            count += 2;
            tmp = 0;
            pstr++;
        }else{
            pstr++;
        }
    }
 *psave++ = tmp;
 *mask++ = 1;
 count += 1;
 pstr++;
    *postfix = *postfix * sign;
    return count;
}

variable_types:
pstr
char *

variable_types:
postfix
int *

variable_types: sign int

variable_types:
psave
int *


Init

decompiled_code:
__int64 __fastcall Init(__int64 a1, int a2)
{
void *v2; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 4) = a2 - 1;
*(_DWORD *)a1 = -1;
v2 = malloc(4LL * a2);
*(_QWORD *)(a1 + 8) = v2;
return (unsigned int)-(v2 == 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
void *v2; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 4) = a2 - 1;
*(_DWORD *)a1 = -1;
v2 = malloc(4LL * a2);
*(_QWORD *)(a1 + 8) = v2;
return (unsigned int)-(v2 == 0LL);
}

original_code:
int Init(STACK_STRU *pThis,int nMaxSize)
{
 if (((void *)0) == pThis){
  return -1;
 }
 pThis->nMaxStackTop = nMaxSize - 1;
 pThis->nStackTop = -1;
 pThis->pNStackBuf = (int *)malloc(sizeof(int) * nMaxSize);
 if (((void *)0) == pThis->pNStackBuf){
  return -1;
 }
 return 0;
}

canonical_original_code:
int Init(struct tag_STACK_STRU *pThis, int nMaxSize)
{
 if (((void *)0) == pThis){
  return -1;
 }
 pThis->nMaxStackTop = nMaxSize - 1;
 pThis->nStackTop = -1;
 pThis->pNStackBuf = (int *)malloc(sizeof(int) * nMaxSize);
 if (((void *)0) == pThis->pNStackBuf){
  return -1;
 }
 return 0;
}

variable_types: struct tag_STACK_STRU { int nStackTop; int nMaxStackTop; int *pNStackBuf; } *

variable_types: nMaxSize int


Push

original_code:
int Push(STACK_STRU *pThis,int nValue)
{
 pThis->pNStackBuf[++(pThis->nStackTop)] = nValue;
 return 0;
}

canonical_original_code:
int Push(struct tag_STACK_STRU *pThis, int nValue)
{
 pThis->pNStackBuf[++(pThis->nStackTop)] = nValue;
 return 0;
}

variable_types: nValue int

user_defined_types: struct tag_STACK_STRU { int nStackTop; int nMaxStackTop; int *pNStackBuf; }


Pop

decompiled_code:
__int64 __fastcall Pop(__int64 a1)
{
__int64 v1; // rdx
int v2; // eax

v1 = *(_QWORD *)(a1 + 8);
v2 = (*(_DWORD *)a1)--;
return *(unsigned int *)(v1 + 4LL * v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rdx
int v2; // eax

v1 = *(_QWORD *)(a1 + 8);
v2 = (*(_DWORD *)a1)--;
return *(unsigned int *)(v1 + 4LL * v2);
}

original_code:
int Pop(STACK_STRU *pThis)
{
 return pThis->pNStackBuf[pThis->nStackTop--];
}

canonical_original_code:
int Pop(struct tag_STACK_STRU *pThis)
{
 return pThis->pNStackBuf[pThis->nStackTop--];
}


original_code:
int postfix_calu(int *postfix, int *mask, int count)
{
    int a1, a2, tmp;
    int i;
    Init(&g_stOperand, 10);
    for(i=0; i<count; i++){
        if(*mask==1){
            Push(&g_stOperand, *postfix);
        }else{
            tmp = 0;
            a2 = Pop(&g_stOperand);
            a1 = Pop(&g_stOperand);
            switch(*postfix){
                case '+': tmp = a1 + a2;
                          break;
                case '-': tmp = a1 - a2;
                          break;
                case '*': tmp = a1 * a2;
                          break;
                case '/': tmp = a1 / a2;
                          break;
                default: break;
            }
            Push(&g_stOperand, tmp);
        }
        mask++;
        postfix++;
    }
    return Pop(&g_stOperand);
}

canonical_original_code:
int postfix_calu(int *postfix, int *mask, int count)
{
    int a1; int a2; int tmp;
    int i;
    Init(&g_stOperand, 10);
    for(i=0; i<count; i++){
        if(*mask==1){
            Push(&g_stOperand, *postfix);
        }else{
            tmp = 0;
            a2 = Pop(&g_stOperand);
            a1 = Pop(&g_stOperand);
            switch(*postfix){
                case '+': tmp = a1 + a2;
                          break;
                case '-': tmp = a1 - a2;
                          break;
                case '*': tmp = a1 * a2;
                          break;
                case '/': tmp = a1 / a2;
                          break;
                default: break;
            }
            Push(&g_stOperand, tmp);
        }
        mask++;
        postfix++;
    }
    return Pop(&g_stOperand);
}


IsFull

decompiled_code:
_BOOL8 __fastcall IsFull(_DWORD *a1)
{
return a1[1] == *a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_DWORD *a1)
{
return a1[1] == *a1;
}

original_code:
int IsFull(STACK_STRU *pThis)
{
 return (pThis->nMaxStackTop == pThis->nStackTop)?1:0;
}

canonical_original_code:
int IsFull(struct tag_STACK_STRU *pThis)
{
 return (pThis->nMaxStackTop == pThis->nStackTop)?1:0;
}


IsEmpty

decompiled_code:
_BOOL8 __fastcall IsEmpty(_DWORD *a1)
{
return *a1 == -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_DWORD *a1)
{
return *a1 == -1;
}

original_code:
int IsEmpty(STACK_STRU *pThis)
{
 return (pThis->nStackTop == -1)?1:0;
}

canonical_original_code:
int IsEmpty(struct tag_STACK_STRU *pThis)
{
 return (pThis->nStackTop == -1)?1:0;
}


original_code:
void infix2posfix(int *postfix, int *mask, int count)
{
    int buff[32];
    int flag[32];
    int i, tmp;
    int *psave, *psource, *pmask;
    memset(buff, 0, sizeof(int)*32);
    memset(flag, 0, sizeof(int)*32);
    Init(&g_stOperator, 10);
    psave = buff;
    pmask = flag;
    psource = postfix;
    for(i=0; i<count; i++){
        if(mask[i]==1){
            *psave++ = *psource;
            *pmask++ = 1;
        }else{
            if((*psource=='+')||(*psource=='-')){
                while(IsEmpty(&g_stOperator)!=1){
                    *psave++ = Pop(&g_stOperator);
                    *pmask++ = 0;
                }
                Push(&g_stOperator, *psource);
            }else{
                while(IsEmpty(&g_stOperator)!=1){
                    tmp = Pop(&g_stOperator);
                    if((tmp=='+')||(tmp=='-')){
                        Push(&g_stOperator, tmp);
                        Push(&g_stOperator, *psource);
                        break;
                    }else{
                        *psave++ = tmp;
                        *pmask++ = 0;
                    }
                }
                if(IsEmpty(&g_stOperator)==1){
     Push(&g_stOperator, *psource);
    }
            }
        }
        psource++;
    }
    while(IsEmpty(&g_stOperator)!=1){
        *psave++ = Pop(&g_stOperator);
        *pmask++ = 0;
    }
    memcpy(postfix, buff, sizeof(int)*32);
    memcpy(mask, flag, sizeof(int)*32);
}

canonical_original_code:
void infix2posfix(int *postfix, int *mask, int count)
{
    int buff[32];
    int flag[32];
    int i; int tmp;
    int *psave; int *psource; int *pmask;
    memset(buff, 0, sizeof(int)*32);
    memset(flag, 0, sizeof(int)*32);
    Init(&g_stOperator, 10);
    psave = buff;
    pmask = flag;
    psource = postfix;
    for(i=0; i<count; i++){
        if(mask[i]==1){
            *psave++ = *psource;
            *pmask++ = 1;
        }else{
            if((*psource=='+')||(*psource=='-')){
                while(IsEmpty(&g_stOperator)!=1){
                    *psave++ = Pop(&g_stOperator);
                    *pmask++ = 0;
                }
                Push(&g_stOperator, *psource);
            }else{
                while(IsEmpty(&g_stOperator)!=1){
                    tmp = Pop(&g_stOperator);
                    if((tmp=='+')||(tmp=='-')){
                        Push(&g_stOperator, tmp);
                        Push(&g_stOperator, *psource);
                        break;
                    }else{
                        *psave++ = tmp;
                        *pmask++ = 0;
                    }
                }
                if(IsEmpty(&g_stOperator)==1){
     Push(&g_stOperator, *psource);
    }
            }
        }
        psource++;
    }
    while(IsEmpty(&g_stOperator)!=1){
        *psave++ = Pop(&g_stOperator);
        *pmask++ = 0;
    }
    memcpy(postfix, buff, sizeof(int)*32);
    memcpy(mask, flag, sizeof(int)*32);
}

variable_types:
buff
int [32]

variable_types:
flag
int [32]

variable_types:
psource
int *

variable_types:
pmask
int *

return_type: void


Destory

decompiled_code:
__int64 __fastcall Destory(__int64 a1)
{
free(*(void **)(a1 + 8));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
free(*(void **)(a1 + 8));
return 0LL;
}

original_code:
int Destory(STACK_STRU *pThis)
{
 free(pThis->pNStackBuf);
 return 0;
}

canonical_original_code:
int Destory(struct tag_STACK_STRU *pThis)
{
 free(pThis->pNStackBuf);
 return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // eax
__m128i v6[8]; // [rsp+0h] [rbp-308h] BYREF
__m128i v7[8]; // [rsp+80h] [rbp-288h] BYREF
char v8[520]; // [rsp+100h] [rbp-208h] BYREF

gets(v8, argv, envp);
v3 = infix_init(v8, (int *)v7, v6);
infix2posfix(v7, v6, v3);
v4 = postfix_calu((int *)v7, v6, v3);
printf("%d\n", v4);
Destory((__int64)&g_stOperand);
Destory((__int64)g_stOperator);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // eax
__m128i v6[8]; // [rsp+0h] [rbp-308h] BYREF
__m128i v7[8]; // [rsp+80h] [rbp-288h] BYREF
char v8[520]; // [rsp+100h] [rbp-208h] BYREF

gets(v8, argv, envp);
v3 = func0(v8, (int *)v7, v6);
func7(v7, v6, v3);
v4 = func4((int *)v7, v6, v3);
printf("%d\n", v4);
func8((__int64)&g_stOperand);
func8((__int64)g_stOperator);
return 0;
}

original_code:
int main()
{
 char str[512];
    int postfix[32];
    int mask[32];
    int count, i;
 gets(str);
    count = infix_init(str, postfix, mask);
    infix2posfix(postfix, mask, count);
 i = postfix_calu(postfix, mask, count);
 printf("%d\n", i);
 Destory(&g_stOperand);
 Destory(&g_stOperator);
 return 0;
}

canonical_original_code:
int main()
{
 char str[512];
    int postfix[32];
    int mask[32];
    int count; int i;
 gets(str);
    count = infix_init(str, postfix, mask);
    infix2posfix(postfix, mask, count);
 i = postfix_calu(postfix, mask, count);
 printf("%d\n", i);
 Destory(&g_stOperand);
 Destory(&g_stOperator);
 return 0;
}

variable_types:
str
char [512]

variable_types:
postfix
int [32]

variable_types:
mask
int [32]


scale

original_code:
static inline signed int scale(mad_fixed_t sample)
{
    sample += (1L << (28 - 16));
    if (sample >= ((mad_fixed_t) (0x10000000L)))
    sample = ((mad_fixed_t) (0x10000000L)) - 1;
    else if (sample < -((mad_fixed_t) (0x10000000L)))
    sample = -((mad_fixed_t) (0x10000000L));
    return sample >> (28 + 1 - 16);
}

canonical_original_code:
static inline int scale(int sample)
{
    sample += (1L << (28 - 16));
    if (sample >= ((mad_fixed_t) (0x10000000L)))
    sample = ((mad_fixed_t) (0x10000000L)) - 1;
    else if (sample < -((mad_fixed_t) (0x10000000L)))
    sample = -((mad_fixed_t) (0x10000000L));
    return sample >> (28 + 1 - 16);
}

variable_types: sample int


error

decompiled_code:
__int64 error()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
static
enum mad_flow error(void *data,
            struct mad_stream *stream, struct mad_frame *frame)
{
    return MAD_FLOW_CONTINUE;
}

variable_types:
data
void *

variable_types: struct mad_stream { unsigned char *buffer; unsigned char *bufend; unsigned long skiplen; int sync; unsigned long freerate; unsigned char *this_frame; unsigned char *next_frame; struct mad_bitptr { unsigned char *byte; unsigned short cache; unsigned short left; } ptr; struct mad_bitptr anc_ptr; unsigned int anc_bitlen; unsigned char (*main_data)[-1]; unsigned int md_len; int options; enum mad_error { MAD_ERROR_NONE=0, MAD_ERROR_BUFLEN=1, MAD_ERROR_BUFPTR=2, MAD_ERROR_NOMEM=49, MAD_ERROR_LOSTSYNC=257, MAD_ERROR_BADLAYER=258, MAD_ERROR_BADBITRATE=259, MAD_ERROR_BADSAMPLERATE=260, MAD_ERROR_BADEMPHASIS=261, MAD_ERROR_BADCRC=513, MAD_ERROR_BADBITALLOC=529, MAD_ERROR_BADSCALEFACTOR=545, MAD_ERROR_BADMODE=546, MAD_ERROR_BADFRAMELEN=561, MAD_ERROR_BADBIGVALUES=562, MAD_ERROR_BADBLOCKTYPE=563, MAD_ERROR_BADSCFSI=564, MAD_ERROR_BADDATAPTR=565, MAD_ERROR_BADPART3LEN=566, MAD_ERROR_BADHUFFTABLE=567, MAD_ERROR_BADHUFFDATA=568, MAD_ERROR_BADSTEREO=569 } error; } *

variable_types: struct mad_frame { struct mad_header { enum mad_layer { MAD_LAYER_I=1, MAD_LAYER_II=2, MAD_LAYER_III=3 } layer; enum mad_mode { MAD_MODE_SINGLE_CHANNEL=0, MAD_MODE_DUAL_CHANNEL=1, MAD_MODE_JOINT_STEREO=2, MAD_MODE_STEREO=3 } mode; int mode_extension; enum mad_emphasis { MAD_EMPHASIS_NONE=0, MAD_EMPHASIS_50_15_US=1, MAD_EMPHASIS_CCITT_J_17=3, MAD_EMPHASIS_RESERVED=2 } emphasis; unsigned long bitrate; unsigned int samplerate; unsigned short crc_check; unsigned short crc_target; int flags; int private_bits; struct mad_timer_t { long seconds; unsigned long fraction; } duration; } header; int options; int sbsample[2][36][32]; int (*overlap)[2][32][18]; } *

return_type: enum mad_flow { MAD_FLOW_CONTINUE=0, MAD_FLOW_STOP=16, MAD_FLOW_BREAK=17, MAD_FLOW_IGNORE=32 }

user_defined_types: struct mad_stream { unsigned char *buffer; unsigned char *bufend; unsigned long skiplen; int sync; unsigned long freerate; unsigned char *this_frame; unsigned char *next_frame; struct mad_bitptr ptr; struct mad_bitptr anc_ptr; unsigned int anc_bitlen; unsigned char (*main_data)[-1]; unsigned int md_len; int options; enum mad_error error; }

user_defined_types: struct mad_frame { struct mad_header header; int options; int sbsample[2][36][32]; int (*overlap)[2][32][18]; }

user_defined_types: struct mad_header { enum mad_layer layer; enum mad_mode mode; int mode_extension; enum mad_emphasis emphasis; unsigned long bitrate; unsigned int samplerate; unsigned short crc_check; unsigned short crc_target; int flags; int private_bits; struct mad_timer_t duration; }


output

original_code:
static
enum mad_flow output(void *data,
             struct mad_header const *header, struct mad_pcm *pcm)
{
    unsigned int nchannels, nsamples, n;
    mad_fixed_t const *left_ch, *right_ch;
    unsigned char Output[6912], *OutputPtr;
    int fmt, wrote, speed;
    nchannels = pcm->channels;
    n = nsamples = pcm->length;
    left_ch = pcm->samples[0];
    right_ch = pcm->samples[1];
    fmt = 0x00000010;
    speed = pcm->samplerate * 2;
    ioctl(sfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((2)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &(speed));
    ioctl(sfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((5)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &fmt);
    ioctl(sfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((6)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &(pcm->channels));
    OutputPtr = Output;
    while (nsamples--) {
    signed int sample;
    sample = scale(*left_ch++);
    *(OutputPtr++) = sample >> 0;
    *(OutputPtr++) = sample >> 8;
    if (nchannels == 2) {
        sample = scale(*right_ch++);
        *(OutputPtr++) = sample >> 0;
        *(OutputPtr++) = sample >> 8;
    }
    }
    n *= 4;
    OutputPtr = Output;
    while (n) {
    wrote = write(sfd, OutputPtr, n);
    OutputPtr += wrote;
    n -= wrote;
    }
    OutputPtr = Output;
    return MAD_FLOW_CONTINUE;
}

canonical_original_code:
static enum mad_flow output(void *data, struct mad_header *header, struct mad_pcm *pcm)
{
    unsigned int nchannels; unsigned int nsamples; unsigned int n;
    int *left_ch; int *right_ch;
    unsigned char Output[6912]; unsigned char *OutputPtr;
    int fmt; int wrote; int speed;
    nchannels = pcm->channels;
    n = nsamples = pcm->length;
    left_ch = pcm->samples[0];
    right_ch = pcm->samples[1];
    fmt = 0x00000010;
    speed = pcm->samplerate * 2;
    ioctl(sfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((2)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &(speed));
    ioctl(sfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((5)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &fmt);
    ioctl(sfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((6)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &(pcm->channels));
    OutputPtr = Output;
    while (nsamples--) {
    int sample;
    sample = scale(*left_ch++);
    *(OutputPtr++) = sample >> 0;
    *(OutputPtr++) = sample >> 8;
    if (nchannels == 2) {
        sample = scale(*right_ch++);
        *(OutputPtr++) = sample >> 0;
        *(OutputPtr++) = sample >> 8;
    }
    }
    n *= 4;
    OutputPtr = Output;
    while (n) {
    wrote = write(sfd, OutputPtr, n);
    OutputPtr += wrote;
    n -= wrote;
    }
    OutputPtr = Output;
    return MAD_FLOW_CONTINUE;
}

variable_types: struct mad_header { enum mad_layer { MAD_LAYER_I=1, MAD_LAYER_II=2, MAD_LAYER_III=3 } layer; enum mad_mode { MAD_MODE_SINGLE_CHANNEL=0, MAD_MODE_DUAL_CHANNEL=1, MAD_MODE_JOINT_STEREO=2, MAD_MODE_STEREO=3 } mode; int mode_extension; enum mad_emphasis { MAD_EMPHASIS_NONE=0, MAD_EMPHASIS_50_15_US=1, MAD_EMPHASIS_CCITT_J_17=3, MAD_EMPHASIS_RESERVED=2 } emphasis; unsigned long bitrate; unsigned int samplerate; unsigned short crc_check; unsigned short crc_target; int flags; int private_bits; struct mad_timer_t { long seconds; unsigned long fraction; } duration; } *

variable_types: struct mad_pcm { unsigned int samplerate; unsigned short channels; unsigned short length; int samples[2][1152]; } *

variable_types:
nchannels
unsigned int

variable_types:
nsamples
unsigned int

variable_types:
n
unsigned int

variable_types:
Output
unsigned char [6912]

variable_types:
OutputPtr
unsigned char *

variable_types: fmt int

variable_types: wrote int

variable_types: speed int

user_defined_types: enum mad_flow { MAD_FLOW_CONTINUE=0, MAD_FLOW_STOP=16, MAD_FLOW_BREAK=17, MAD_FLOW_IGNORE=32 }


input

decompiled_code:
__int64 __fastcall input(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = 16LL;
if ( a1[1] )
{
mad_stream_buffer(a2, *a1);
a1[1] = 0LL;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = 16LL;
if ( a1[1] )
{
mad_stream_buffer(a2, *a1);
a1[1] = 0LL;
result = 0LL;
}
return result;
}

original_code:
static
enum mad_flow input(void *data, struct mad_stream *stream)
{
    struct buffer *buffer = data;
    if (!buffer->length)
    return MAD_FLOW_STOP;
    mad_stream_buffer(stream, buffer->start, buffer->length);
    buffer->length = 0;
    return MAD_FLOW_CONTINUE;
}

variable_types: struct buffer { unsigned char *start; unsigned long length; } *

user_defined_types: struct mad_bitptr { unsigned char *byte; unsigned short cache; unsigned short left; }

user_defined_types: enum mad_error { MAD_ERROR_NONE=0, MAD_ERROR_BUFLEN=1, MAD_ERROR_BUFPTR=2, MAD_ERROR_NOMEM=49, MAD_ERROR_LOSTSYNC=257, MAD_ERROR_BADLAYER=258, MAD_ERROR_BADBITRATE=259, MAD_ERROR_BADSAMPLERATE=260, MAD_ERROR_BADEMPHASIS=261, MAD_ERROR_BADCRC=513, MAD_ERROR_BADBITALLOC=529, MAD_ERROR_BADSCALEFACTOR=545, MAD_ERROR_BADMODE=546, MAD_ERROR_BADFRAMELEN=561, MAD_ERROR_BADBIGVALUES=562, MAD_ERROR_BADBLOCKTYPE=563, MAD_ERROR_BADSCFSI=564, MAD_ERROR_BADDATAPTR=565, MAD_ERROR_BADPART3LEN=566, MAD_ERROR_BADHUFFTABLE=567, MAD_ERROR_BADHUFFDATA=568, MAD_ERROR_BADSTEREO=569 }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
int result; // eax
void *v6; // rax
void *v7; // rbx
int v8; // ebx
struct stat v9; // [rsp+0h] [rbp-98h] BYREF

v3 = open(argv[1], 0, envp);
v4 = open("/dev/dsp", 1);
sfd = v4;
if ( v4 < 0 )
{
printf("can not open device!!!/n");
result = 5;
}
else
{
ioctl(v4, 0x5001uLL, 0LL);
if ( fstat(v3, &v9) == -1 )
{
result = 2;
}
else
{
result = 2;
if ( v9.st_size )
{
v6 = mmap(0LL, v9.st_size, 1, 1, v3, 0LL);
v7 = v6;
if ( v6 == (void *)-1LL )
{
result = 3;
}
else
{
decode((__int64)v6, v9.st_size);
if ( munmap(v7, v9.st_size) == -1 )
{
result = 4;
}
else
{
v8 = sfd;
ioctl(sfd, 0x5000uLL, 0LL);
close(v8);
result = 0;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
int result; // eax
void *v6; // rax
void *v7; // rbx
int v8; // ebx
struct stat v9; // [rsp+0h] [rbp-98h] BYREF

v3 = open(argv[1], 0, envp);
v4 = open("/dev/dsp", 1);
sfd = v4;
if ( v4 < 0 )
{
printf("can not open device!!!/n");
result = 5;
}
else
{
ioctl(v4, 0x5001uLL, 0LL);
if ( fstat(v3, &v9) == -1 )
{
result = 2;
}
else
{
result = 2;
if ( v9.st_size )
{
v6 = mmap(0LL, v9.st_size, 1, 1, v3, 0LL);
v7 = v6;
if ( v6 == (void *)-1LL )
{
result = 3;
}
else
{
func2((__int64)v6, v9.st_size);
if ( munmap(v7, v9.st_size) == -1 )
{
result = 4;
}
else
{
v8 = sfd;
ioctl(sfd, 0x5000uLL, 0LL);
close(v8);
result = 0;
}
}
}
}
}
return result;
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types:
fdm
void *

variable_types:
file
char *

variable_types: fd int

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


paserInput

decompiled_code:
__int64 __fastcall paserInput(unsigned __int8 *a1)
{
__int64 result; // rax
int v2; // eax
unsigned __int8 v3; // cl
int v4; // edx

for ( result = *a1; (_BYTE)result; result = *a1 )
{
v2 = (char)result - 48;
v3 = a1[1];
v4 = 0;
if ( v3 != 84 )
v4 = (v3 != 68) + 1;
++mahjong[10 * v4];
++mahjong[10 * v4 + v2];
a1 += 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
__int64 result; // rax
int v2; // eax
unsigned __int8 v3; // cl
int v4; // edx

for ( result = *a1; (_BYTE)result; result = *a1 )
{
v2 = (char)result - 48;
v3 = a1[1];
v4 = 0;
if ( v3 != 84 )
v4 = (v3 != 68) + 1;
++mahjong[10 * v4];
++mahjong[10 * v4 + v2];
a1 += 2;
}
return result;
}

original_code:
void paserInput(char *str)
{
 char *p;
 int num, type;
 p = str;
 while(*p!='\0'){
  num = (*p - '0');
  if(*(p+1)=='T') { type = 0; }
  else if(*(p+1)=='D') { type = 1; }
  else { type = 2; }
  mahjong[type][0]++;
  mahjong[type][num]++;
  p +=2;
 }
}

canonical_original_code:
void paserInput(char *str)
{
 char *p;
 int num; int type;
 p = str;
 while(*p!='\0'){
  num = (*p - '0');
  if(*(p+1)=='T') { type = 0; }
  else if(*(p+1)=='D') { type = 1; }
  else { type = 2; }
  mahjong[type][0]++;
  mahjong[type][num]++;
  p +=2;
 }
}

variable_types:
str
char *

variable_types:
p
char *

variable_types: num int

variable_types: type int


decompiled_code:
__int64 is7pair()
{
int *v0; // rdx
int *v2; // rax

v0 = mahjong;
while ( !*v0 )
{
LABEL_3:
v0 += 10;
if ( v0 == (int *)(unsigned int)((_DWORD)mahjong + 120) )
return 0LL;
}
v2 = v0;
while ( (v2[1] & 1) == 0 )
{
if ( ++v2 == v0 + 9 )
goto LABEL_3;
}
return 4294967294LL;
}

canonical_decompiled_code:
__int64 func1()
{
int *v0; // rdx
int *v2; // rax

v0 = mahjong;
while ( !*v0 )
{
LABEL_3:
v0 += 10;
if ( v0 == (int *)(unsigned int)((_DWORD)mahjong + 120) )
return 0LL;
}
v2 = v0;
while ( (v2[1] & 1) == 0 )
{
if ( ++v2 == v0 + 9 )
goto LABEL_3;
}
return 4294967294LL;
}

original_code:
int is7pair(void)
{
    int i,j;
    for(i=0; i<3; i++){
        if(mahjong[i][0]!=0){
            for(j=1; j<10; j++){
                if(mahjong[i][j]%2!=0){
                    return -2;
                }
            }
        }
    }
    return 0;
}

canonical_original_code:
int is7pair()
{
    int i; int j;
    for(i=0; i<3; i++){
        if(mahjong[i][0]!=0){
            for(j=1; j<10; j++){
                if(mahjong[i][j]%2!=0){
                    return -2;
                }
            }
        }
    }
    return 0;
}

variable_types: i int

variable_types: j int


analyze

decompiled_code:
__int64 __fastcall analyze(unsigned int *a1)
{
__int64 result; // rax
_DWORD *v2; // rdx
int v3; // eax
unsigned int *v4; // rbp
int v5; // edx
__int64 v6; // rcx
int *v7; // r12
int *v8; // r13

result = *a1;
if ( (_DWORD)result )
{
v2 = a1 + 1;
v3 = 1;
while ( !*v2 )
{
++v3;
++v2;
if ( v3 == 10 )
{
v4 = a1 + 10;
v5 = a1[10];
result = 0xFFFFFFFFLL;
if ( v5 <= 2 )
return result;
goto LABEL_6;
}
}
v6 = v3;
v4 = &a1[v6];
v5 = a1[v6];
if ( v5 > 2 )
{
LABEL_6:
*v4 = v5 - 3;
*a1 -= 3;
result = analyze(a1);
*v4 += 3;
*a1 += 3;
return result;
}
if ( v3 > 7 )
{
result = 0xFFFFFFFFLL;
}
else
{
v7 = (int *)&a1[v6 + 1];
if ( *v7 <= 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v8 = (int *)&a1[v6 + 2];
if ( *v8 <= 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
*v4 = v5 - 1;
--*v7;
--*v8;
*a1 -= 3;
result = analyze(a1);
++*v4;
++*v7;
++*v8;
*a1 += 3;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
__int64 result; // rax
_DWORD *v2; // rdx
int v3; // eax
unsigned int *v4; // rbp
int v5; // edx
__int64 v6; // rcx
int *v7; // r12
int *v8; // r13

result = *a1;
if ( (_DWORD)result )
{
v2 = a1 + 1;
v3 = 1;
while ( !*v2 )
{
++v3;
++v2;
if ( v3 == 10 )
{
v4 = a1 + 10;
v5 = a1[10];
result = 0xFFFFFFFFLL;
if ( v5 <= 2 )
return result;
goto LABEL_6;
}
}
v6 = v3;
v4 = &a1[v6];
v5 = a1[v6];
if ( v5 > 2 )
{
LABEL_6:
*v4 = v5 - 3;
*a1 -= 3;
result = func2(a1);
*v4 += 3;
*a1 += 3;
return result;
}
if ( v3 > 7 )
{
result = 0xFFFFFFFFLL;
}
else
{
v7 = (int *)&a1[v6 + 1];
if ( *v7 <= 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v8 = (int *)&a1[v6 + 2];
if ( *v8 <= 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
*v4 = v5 - 1;
--*v7;
--*v8;
*a1 -= 3;
result = func2(a1);
++*v4;
++*v7;
++*v8;
*a1 += 3;
}
}
}
}
return result;
}

original_code:
int analyze(int *arry)
{
 int i, ret;
 if(arry[0]==0){
  return 0;
 }
 for(i=1; i<10; i++){
  if(arry[i]!=0) break;
 }
 if(arry[i]>=3){
  arry[i] -= 3;
  arry[0] -= 3;
  ret = analyze(arry);
  arry[i] += 3;
  arry[0] += 3;
  return ret;
 }
 if((i<8)&&(arry[i+1]>0)&&(arry[i+2]>0)){
  arry[i] -= 1;
  arry[i+1] -= 1;
  arry[i+2] -= 1;
  arry[0] -= 3;
  ret = analyze(arry);
  arry[i] += 1;
  arry[i+1] += 1;
  arry[i+2] += 1;
  arry[0] += 3;
  return ret;
 }
 return -1;
}

canonical_original_code:
int analyze(int *arry)
{
 int i; int ret;
 if(arry[0]==0){
  return 0;
 }
 for(i=1; i<10; i++){
  if(arry[i]!=0) break;
 }
 if(arry[i]>=3){
  arry[i] -= 3;
  arry[0] -= 3;
  ret = analyze(arry);
  arry[i] += 3;
  arry[0] += 3;
  return ret;
 }
 if((i<8)&&(arry[i+1]>0)&&(arry[i+2]>0)){
  arry[i] -= 1;
  arry[i+1] -= 1;
  arry[i+2] -= 1;
  arry[0] -= 3;
  ret = analyze(arry);
  arry[i] += 1;
  arry[i+1] += 1;
  arry[i+2] += 1;
  arry[0] += 3;
  return ret;
 }
 return -1;
}

variable_types:
arry
int *

variable_types: ret int


isWin

decompiled_code:
__int64 isWin()
{
int v0; // ecx
int v1; // esi
int *v2; // rdx
int *v3; // rsi
int v4; // er8
int v5; // ebp
int i; // edx
int *v7; // rax
int v8; // eax
unsigned int v9; // edx
__int64 v10; // r12
unsigned int *v11; // r13
int *v12; // rbx
int *v13; // r12
__int64 v14; // rbp
int v15; // eax

v0 = mahjong[10];
v1 = mahjong[20];
if ( v1 + mahjong[0] + v0 == 14 && (mahjong[0] == 0 || v0 == 0 || !v1) )
{
v2 = mahjong;
while ( *v2 <= 4 )
{
LABEL_6:
v2 += 10;
if ( v2 == (int *)(unsigned int)((_DWORD)mahjong + 120) )
{
v3 = mahjong;
v4 = -1;
v5 = -1;
for ( i = 0; i != 3; ++i )
{
v8 = *v3 % 3;
if ( v8 == 1 )
return (unsigned int)-2;
if ( v8 == 2 )
{
if ( v5 != -1 )
return (unsigned int)-2;
v5 = i;
}
else
{
v4 = i;
}
v3 += 10;
}
if ( v4 != -1 && (unsigned int)analyze((unsigned int *)&mahjong[10 * v4]) )
return (unsigned int)-1;
v9 = 0;
if ( v5 != -1 )
{
v10 = 10LL * v5;
v11 = (unsigned int *)&mahjong[v10];
v12 = &mahjong[v10];
v13 = &mahjong[v10 + 9];
v14 = 10LL * v5;
do
{
v15 = v12[1];
if ( v15 > 1 )
{
v12[1] = v15 - 2;
mahjong[v14] -= 2;
v9 = analyze(v11);
v12[1] += 2;
mahjong[v14] += 2;
if ( !v9 )
break;
}
++v12;
}
while ( v12 != v13 );
}
return v9;
}
}
v7 = v2;
while ( v7[1] <= 4 )
{
if ( ++v7 == v2 + 9 )
goto LABEL_6;
}
}
return 4294967294LL;
}

original_code:
int isWin(void)
{
 int j, i, pair, nopair;
 int ret;
 if((mahjong[0][0]+mahjong[1][0]+mahjong[2][0])!=14) return -2;
 if((mahjong[0][0]!=0)&&(mahjong[1][0]!=0)&&(mahjong[2][0]!=0)){
        return -2;
 }
 for(j=0; j<3; j++){
  if(mahjong[j][0]>4){
   for(i=1; i<10; i++){
    if(mahjong[j][i]>4){
     return -2;
    }
   }
  }
 }
 pair = -1;
 nopair = -1;
 for(i=0; i<3; i++){
  if( mahjong[i][0]%3==1 ){
   return -2;
  }else if(mahjong[i][0]%3==2){
   if(pair==-1){
    pair = i;
   }else{
    return -2;
   }
  }else{
   nopair = i;
  }
 }
 if(nopair!=-1){
  ret = analyze(mahjong[nopair]);
  if(ret!=0) return -1;
 }
 if(pair!=-1){
  for(i=1; i<10; i++){
            if(mahjong[pair][i]>=2){
                mahjong[pair][i] -= 2;
                mahjong[pair][0] -= 2;
                ret = analyze(mahjong[pair]);
                mahjong[pair][i] += 2;
                mahjong[pair][0] += 2;
                if(ret==0) break;
            }
        }
 }
    return ret;
}

canonical_original_code:
int isWin()
{
 int j; int i; int pair; int nopair;
 int ret;
 if((mahjong[0][0]+mahjong[1][0]+mahjong[2][0])!=14) return -2;
 if((mahjong[0][0]!=0)&&(mahjong[1][0]!=0)&&(mahjong[2][0]!=0)){
        return -2;
 }
 for(j=0; j<3; j++){
  if(mahjong[j][0]>4){
   for(i=1; i<10; i++){
    if(mahjong[j][i]>4){
     return -2;
    }
   }
  }
 }
 pair = -1;
 nopair = -1;
 for(i=0; i<3; i++){
  if( mahjong[i][0]%3==1 ){
   return -2;
  }else if(mahjong[i][0]%3==2){
   if(pair==-1){
    pair = i;
   }else{
    return -2;
   }
  }else{
   nopair = i;
  }
 }
 if(nopair!=-1){
  ret = analyze(mahjong[nopair]);
  if(ret!=0) return -1;
 }
 if(pair!=-1){
  for(i=1; i<10; i++){
            if(mahjong[pair][i]>=2){
                mahjong[pair][i] -= 2;
                mahjong[pair][0] -= 2;
                ret = analyze(mahjong[pair]);
                mahjong[pair][i] += 2;
                mahjong[pair][0] += 2;
                if(ret==0) break;
            }
        }
 }
    return ret;
}

variable_types: pair int

variable_types: nopair int


main

original_code:
int main(void)
{
 char out[512];
 char str[64];
    int flag;
 char *p;
 memset(str, 0, 64);
 memset(mahjong, 0, sizeof(int)*3*10);
 p = out;
 while(gets(str)){
  paserInput(str);
  flag = isWin();
  if(flag==-1){
   flag = is7pair();
     }
  p += sprintf(p, "%s\n", (flag==0)?"true":"false");
  memset(mahjong, 0, sizeof(int)*3*10);
  memset(str, 0, 64);
 };
 printf("%s", out);
 return 0;
}

canonical_original_code:
int main()
{
 char out[512];
 char str[64];
    int flag;
 char *p;
 memset(str, 0, 64);
 memset(mahjong, 0, sizeof(int)*3*10);
 p = out;
 while(gets(str)){
  paserInput(str);
  flag = isWin();
  if(flag==-1){
   flag = is7pair();
     }
  p += sprintf(p, "%s\n", (flag==0)?"true":"false");
  memset(mahjong, 0, sizeof(int)*3*10);
  memset(str, 0, 64);
 };
 printf("%s", out);
 return 0;
}

variable_types:
out
char [512]

variable_types:
str
char [64]

variable_types: flag int


original_code:
int main( void )
{
 char str[1028];
 char out[1028];
 int new_word;
 char *pstr, *pout;
 memset(str, 0, 1028);
 memset(out, 0, 1028);
 scanf("%[^\n]", str);
 pstr = str;
 pout = out;
 new_word = 1;
 while(*pstr!='\0'){
  if( is_break(pstr) == 1){
   new_word = 1;
   *pout = *pstr;
  }else{
   if(new_word == 1){
    new_word = 0;
    if(((*pstr) == 'w')||((*pstr)=='W')){
     if( tolower(*(pstr+1))=='e' && is_break(pstr+2)==1 ){
      if(*pstr<'w') *pout++ = 'Y';
      else *pout++ = 'y';
      if(*(pstr+1)<'e'){
       *pout++= 'O';
       *pout= 'U';
      }else{
       *pout++= 'o';
       *pout= 'u';
      }
      pstr = pstr + 1;
     }else{
      *pout = *pstr;
     }
    } else if(((*pstr) == 'Y')||((*pstr)=='y')){
     if( tolower(*(pstr+1))=='o' && tolower(*(pstr+2))=='u' && is_break(pstr+3)==1 ){
      if(*pstr<'y') *pout++ = 'W';
      else *pout++ = 'w';
      if(*(pstr+1)<'o'){
       *pout= 'E';
      }else{
       *pout = 'e';
      }
      pstr = pstr + 2;
     }else{
      *pout = *pstr;
     }
    }else{
     *pout = *pstr;
    }
   } else {
    *pout = *pstr;
   }
  }
  pout++;
  pstr++;
 }
 printf("%s\n",out);
    return 0;
}

canonical_original_code:
int main()
{
 char str[1028];
 char out[1028];
 int new_word;
 char *pstr; char *pout;
 memset(str, 0, 1028);
 memset(out, 0, 1028);
 scanf("%[^\n]", str);
 pstr = str;
 pout = out;
 new_word = 1;
 while(*pstr!='\0'){
  if( is_break(pstr) == 1){
   new_word = 1;
   *pout = *pstr;
  }else{
   if(new_word == 1){
    new_word = 0;
    if(((*pstr) == 'w')||((*pstr)=='W')){
     if( tolower(*(pstr+1))=='e' && is_break(pstr+2)==1 ){
      if(*pstr<'w') *pout++ = 'Y';
      else *pout++ = 'y';
      if(*(pstr+1)<'e'){
       *pout++= 'O';
       *pout= 'U';
      }else{
       *pout++= 'o';
       *pout= 'u';
      }
      pstr = pstr + 1;
     }else{
      *pout = *pstr;
     }
    } else if(((*pstr) == 'Y')||((*pstr)=='y')){
     if( tolower(*(pstr+1))=='o' && tolower(*(pstr+2))=='u' && is_break(pstr+3)==1 ){
      if(*pstr<'y') *pout++ = 'W';
      else *pout++ = 'w';
      if(*(pstr+1)<'o'){
       *pout= 'E';
      }else{
       *pout = 'e';
      }
      pstr = pstr + 2;
     }else{
      *pout = *pstr;
     }
    }else{
     *pout = *pstr;
    }
   } else {
    *pout = *pstr;
   }
  }
  pout++;
  pstr++;
 }
 printf("%s\n",out);
    return 0;
}

variable_types:
str
char [1028]

variable_types:
out
char [1028]

variable_types:
pstr
char *

variable_types:
pout
char *


decompiled_code:
int __fastcall api_print_operation_result(int a1)
{
int result; // eax

switch ( a1 )
{
case 0:
result = libOutputStr(aE000);
break;
case 2:
result = libOutputStr(aE002);
break;
case 3:
result = libOutputStr(aE003);
break;
case 4:
result = libOutputStr(aE004);
break;
case 5:
result = libOutputStr(aE005);
break;
case 6:
result = libOutputStr(aE006);
break;
case 7:
result = libOutputStr(aE007);
break;
case 8:
result = libOutputStr(aE008);
break;
case 14:
result = libOutputStr(aE014);
break;
case 16:
result = libOutputStr(aE016);
break;
case 17:
result = libOutputStr(aE017);
break;
default:
return result;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = func0(aE000);
break;
case 2:
result = func0(aE002);
break;
case 3:
result = func0(aE003);
break;
case 4:
result = func0(aE004);
break;
case 5:
result = func0(aE005);
break;
case 6:
result = func0(aE006);
break;
case 7:
result = func0(aE007);
break;
case 8:
result = func0(aE008);
break;
case 14:
result = func0(aE014);
break;
case 16:
result = func0(aE016);
break;
case 17:
result = func0(aE017);
break;
default:
return result;
}
return result;
}

original_code:
void api_print_operation_result(OpRet opRet)
{
    switch (opRet)
    {
        case E000_INITITIAL_SUCC:
            libOutputStr("E000:初始化成功");
            break;
        case E002_DIAGNOSE_NOT_END:
            libOutputStr("E002:本次看病未结束");
            break;
        case E003_QUEUE_EXCEED_OF_PER_DOCTOR:
            libOutputStr("E003:医生排队人数达到上限");
            break;
        case E004_LACK_FEE_FOR_REGISTER:
            libOutputStr("E004:无足够挂号费用");
            break;
        case E005_DIAGNOSE_SUCC:
            libOutputStr("E005:诊治成功");
            break;
        case E006_NO_PATIENT_IN_QUEUE:
            libOutputStr("E006:无病人排队");
            break;
        case E007_PAY_SUCC:
            libOutputStr("E007:缴费成功");
            break;
        case E008_BALANCE_NOT_ENOUGH:
            libOutputStr("E008:余额不足");
            break;
        case E014_PATIENT_NOT_BE_PAY_STATUS:
            libOutputStr("E014:无该病人待缴费");
            break;
        case E016_NO_PATIENT_IN_HOSP:
            libOutputStr("E016:本院无该病人");
            break;
        case E017_DCT_DIAG_NOBODY:
            libOutputStr("E017:医生尚未诊断过任何病人");
            break;
        default:
            break;
    }
    return;
}

canonical_original_code:
void api_print_operation_result(enum _OpRet opRet)
{
    switch (opRet)
    {
        case E000_INITITIAL_SUCC:
            libOutputStr("E000:初始化成功");
            break;
        case E002_DIAGNOSE_NOT_END:
            libOutputStr("E002:本次看病未结束");
            break;
        case E003_QUEUE_EXCEED_OF_PER_DOCTOR:
            libOutputStr("E003:医生排队人数达到上限");
            break;
        case E004_LACK_FEE_FOR_REGISTER:
            libOutputStr("E004:无足够挂号费用");
            break;
        case E005_DIAGNOSE_SUCC:
            libOutputStr("E005:诊治成功");
            break;
        case E006_NO_PATIENT_IN_QUEUE:
            libOutputStr("E006:无病人排队");
            break;
        case E007_PAY_SUCC:
            libOutputStr("E007:缴费成功");
            break;
        case E008_BALANCE_NOT_ENOUGH:
            libOutputStr("E008:余额不足");
            break;
        case E014_PATIENT_NOT_BE_PAY_STATUS:
            libOutputStr("E014:无该病人待缴费");
            break;
        case E016_NO_PATIENT_IN_HOSP:
            libOutputStr("E016:本院无该病人");
            break;
        case E017_DCT_DIAG_NOBODY:
            libOutputStr("E017:医生尚未诊断过任何病人");
            break;
        default:
            break;
    }
    return;
}

variable_types: enum _OpRet { E000_INITITIAL_SUCC=0, E002_DIAGNOSE_NOT_END=2, E003_QUEUE_EXCEED_OF_PER_DOCTOR=3, E004_LACK_FEE_FOR_REGISTER=4, E005_DIAGNOSE_SUCC=5, E006_NO_PATIENT_IN_QUEUE=6, E007_PAY_SUCC=7, E008_BALANCE_NOT_ENOUGH=8, E014_PATIENT_NOT_BE_PAY_STATUS=14, E016_NO_PATIENT_IN_HOSP=16, E017_DCT_DIAG_NOBODY=17 }


OpPay

decompiled_code:
int __fastcall OpPay(__int64 a1)
{
int v1; // eax
int v2; // edi
int v4; // edx
int v5; // edx

v1 = *(char *)(a1 + 4) - 49;
v2 = 14;
if ( LODWORD(PatientInfo[5 * v1 + 4]) == 2 )
{
if ( LODWORD(PatientInfo[5 * v1 + 2]) == 1 && (v5 = PatientInfo[5 * v1 + 3], v5 > 49) )
{
LODWORD(PatientInfo[5 * v1 + 3]) = v5 - 50;
v2 = 7;
}
else
{
v4 = HIDWORD(PatientInfo[5 * v1 + 2]);
v2 = 8;
if ( v4 > 49 )
{
HIDWORD(PatientInfo[5 * v1 + 2]) = v4 - 50;
v2 = 7;
}
}
LODWORD(PatientInfo[5 * v1 + 4]) = 0;
}
return api_print_operation_result(v2);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
int v1; // eax
int v2; // edi
int v4; // edx
int v5; // edx

v1 = *(char *)(a1 + 4) - 49;
v2 = 14;
if ( LODWORD(PatientInfo[5 * v1 + 4]) == 2 )
{
if ( LODWORD(PatientInfo[5 * v1 + 2]) == 1 && (v5 = PatientInfo[5 * v1 + 3], v5 > 49) )
{
LODWORD(PatientInfo[5 * v1 + 3]) = v5 - 50;
v2 = 7;
}
else
{
v4 = HIDWORD(PatientInfo[5 * v1 + 2]);
v2 = 8;
if ( v4 > 49 )
{
HIDWORD(PatientInfo[5 * v1 + 2]) = v4 - 50;
v2 = 7;
}
}
LODWORD(PatientInfo[5 * v1 + 4]) = 0;
}
return func1(v2);
}

original_code:
void OpPay(unsigned int nMoney)
{
 if((nMoney==1)||(nMoney==2)||(nMoney==5)||(nMoney==10)){
  if((nMoney==5)||(nMoney==10)){
   if( nMoney>get_changeSum() ){
    apiPrintErrInfo(E003);
    return;
   }
  }
  if( (g_nPayBalance+nMoney)>10 ){
   apiPrintErrInfo(E004);
  }else if( get_goodsSum()==0 ){
   apiPrintErrInfo(E005);
  }else{
   g_nPayBalance += nMoney;
   add_money(nMoney);
   apiPrintBalance(S002, g_nPayBalance);
  }
 }else{
  apiPrintErrInfo(E002);
 }
}

variable_types:
nMoney
unsigned int


decompiled_code:
int api_print_register_succ()
{
return libOutputStr(aE001);
}

canonical_decompiled_code:
int func3()
{
return func0(aE001);
}

original_code:
void api_print_register_succ(void)
{
    libOutputStr("E001:挂号成功");
    return;
}

canonical_original_code:
void api_print_register_succ()
{
    libOutputStr("E001:挂号成功");
    return;
}


decompiled_code:
int __fastcall api_print_patient_query_info(__int64 a1, int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
int result; // eax
char v6[520]; // [rsp-208h] [rbp-208h] BYREF

if ( a1 )
{
result = 0;
memset(v6, 0, 0x200uLL);
switch ( a2 )
{
case 1:
sprintf(v6, format, a1, a3, a4, a5);
result = libOutputStr(v6);
break;
case 2:
sprintf(v6, aE012S_0, a1, a4);
result = libOutputStr(v6);
break;
case 0:
sprintf(v6, aE012S, a1, a4);
result = libOutputStr(v6);
break;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
int result; // eax
char v6[520]; // [rsp-208h] [rbp-208h] BYREF

if ( a1 )
{
result = 0;
memset(v6, 0, 0x200uLL);
switch ( a2 )
{
case 1:
sprintf(v6, format, a1, a3, a4, a5);
result = func0(v6);
break;
case 2:
sprintf(v6, aE012S_0, a1, a4);
result = func0(v6);
break;
case 0:
sprintf(v6, aE012S, a1, a4);
result = func0(v6);
break;
}
}
return result;
}

original_code:
void api_print_patient_query_info(const char *pPatientId, PatientStatus patientStatus, int sequence, int insureBalance, int creditBalance)
{
    char pBuff[512];
    if (((void *)0) == pPatientId)
    {
        return;
    }
    memset(pBuff, 0, sizeof(pBuff));
    switch (patientStatus)
    {
        case PS_IN_QUEUE:
            sprintf(pBuff, "E012:%s 待就诊 排在第%d位,社保帐户余额:%d,现金帐户余额:%d",
                    pPatientId, sequence, insureBalance, creditBalance);
            libOutputStr(pBuff);
            break;
        case PS_IDLE:
            sprintf(pBuff, "E012:%s 未挂号 社保帐户余额:%d,现金帐户余额:%d",
                    pPatientId, insureBalance, creditBalance);
            libOutputStr(pBuff);
            break;
        case PS_WAIT_PAY:
            sprintf(pBuff, "E012:%s 待缴费 社保帐户余额:%d,现金帐户余额:%d",
                    pPatientId, insureBalance, creditBalance);
            libOutputStr(pBuff);
            break;
        default:
            break;
    }
    return;
}

canonical_original_code:
void api_print_patient_query_info(char *pPatientId, enum PatientStatus patientStatus, int sequence, int insureBalance, int creditBalance)
{
    char pBuff[512];
    if (((void *)0) == pPatientId)
    {
        return;
    }
    memset(pBuff, 0, sizeof(pBuff));
    switch (patientStatus)
    {
        case PS_IN_QUEUE:
            sprintf(pBuff, "E012:%s 待就诊 排在第%d位,社保帐户余额:%d,现金帐户余额:%d",
                    pPatientId, sequence, insureBalance, creditBalance);
            libOutputStr(pBuff);
            break;
        case PS_IDLE:
            sprintf(pBuff, "E012:%s 未挂号 社保帐户余额:%d,现金帐户余额:%d",
                    pPatientId, insureBalance, creditBalance);
            libOutputStr(pBuff);
            break;
        case PS_WAIT_PAY:
            sprintf(pBuff, "E012:%s 待缴费 社保帐户余额:%d,现金帐户余额:%d",
                    pPatientId, insureBalance, creditBalance);
            libOutputStr(pBuff);
            break;
        default:
            break;
    }
    return;
}

variable_types:
pPatientId
char *

variable_types: enum PatientStatus { PS_IDLE=0, PS_IN_QUEUE=1, PS_WAIT_PAY=2 }

variable_types: sequence int

variable_types: insureBalance int

variable_types: creditBalance int

variable_types:
pBuff
char [512]


original_code:
void api_print_doctor_query_info(DoctorQueue *pDoctorQueue)
{
    char pBuff[512];
    if (((void *)0) == pDoctorQueue)
    {
        return;
    }
    memset(pBuff, 0, sizeof(pBuff));
    if (0 == pDoctorQueue->queueNum)
    {
        libOutputStr("E013:dct 无人排队");
    }
    else
    {
        int i;
        sprintf(pBuff, "E013:dct 等待队列");
        for (i = 0; i < pDoctorQueue->queueNum; i++)
        {
            strcat(pBuff, " ");
            strcat(pBuff, pDoctorQueue->pPatientIdInfo[i]);
        }
        libOutputStr(pBuff);
    }
    return;
}

canonical_original_code:
void api_print_doctor_query_info(struct DoctorQueue *pDoctorQueue)
{
    char pBuff[512];
    if (((void *)0) == pDoctorQueue)
    {
        return;
    }
    memset(pBuff, 0, sizeof(pBuff));
    if (0 == pDoctorQueue->queueNum)
    {
        libOutputStr("E013:dct 无人排队");
    }
    else
    {
        int i;
        sprintf(pBuff, "E013:dct 等待队列");
        for (i = 0; i < pDoctorQueue->queueNum; i++)
        {
            strcat(pBuff, " ");
            strcat(pBuff, pDoctorQueue->pPatientIdInfo[i]);
        }
        libOutputStr(pBuff);
    }
    return;
}

variable_types: struct DoctorQueue { int queueNum; char *pPatientIdInfo[4]; } *

variable_types: i int


original_code:
void queue_init(void)
{
 int i;
 _queue.nTail = 0;
 _queue.nHead = 0;
 _queue.count = 0;
 for(i=0; i<5; i++){
  _queue.pat_queue[i] = ((void *)0);
 }
}

canonical_original_code:
void queue_init()
{
 int i;
 _queue.nTail = 0;
 _queue.nHead = 0;
 _queue.count = 0;
 for(i=0; i<5; i++){
  _queue.pat_queue[i] = ((void *)0);
 }
}


OpInit

decompiled_code:
int OpInit()
{
unsigned __int64 v0; // rax
const __m128i *v1; // rcx
__int32 i; // edx

v0 = (unsigned int)((_DWORD)PatientInfo + 8);
v1 = (const __m128i *)&gPatientIniCfg;
for ( i = 0; i != 6; ++i )
{
*(_DWORD *)(v0 - 8) = i;
*(_DWORD *)(v0 + 24) = 0;
*(_DWORD *)(v0 + 28) = -1;
*(__m128i *)v0 = _mm_loadu_si128(v1);
*(_QWORD *)(v0 + 16) = v1[1].m128i_i64[0];
v0 += 40LL;
v1 = (const __m128i *)((char *)v1 + 24);
}
queue_init();
return api_print_operation_result(0);
}

original_code:
void OpInit(void)
{
 int i;
 for(i=0; i<6; i++){
  _PatientInfo[i].patid = i;
  _PatientInfo[i].status = PS_IDLE;
  _PatientInfo[i].index = -1;
  memcpy(&_PatientInfo[i].info, &gPatientIniCfg[i], sizeof(struct PatientIni));
 }
 queue_init();
 api_print_operation_result(E000_INITITIAL_SUCC);
}

canonical_original_code:
void OpInit()
{
 int i;
 for(i=0; i<6; i++){
  _PatientInfo[i].patid = i;
  _PatientInfo[i].status = PS_IDLE;
  _PatientInfo[i].index = -1;
  memcpy(&_PatientInfo[i].info, &gPatientIniCfg[i], sizeof(struct PatientIni));
 }
 queue_init();
 api_print_operation_result(E000_INITITIAL_SUCC);
}

user_defined_types: struct PatientIni { char *patientId; int patientLevel; int creditBalance; int insureBalance; }


decompiled_code:
_BOOL8 is_queue_empty()
{
return (_DWORD)queue == HIDWORD(queue);
}

canonical_decompiled_code:
_BOOL8 func8()
{
return (_DWORD)queue == HIDWORD(queue);
}

original_code:
int is_queue_empty(void)
{
 return (_queue.nTail == _queue.nHead)?1:0;
}

canonical_original_code:
int is_queue_empty()
{
 return (_queue.nTail == _queue.nHead)?1:0;
}


decompiled_code:
_BOOL8 is_queue_full()
{
return ((int)queue + 1) % 5 == HIDWORD(queue);
}

canonical_decompiled_code:
_BOOL8 func9()
{
return ((int)queue + 1) % 5 == HIDWORD(queue);
}

original_code:
int is_queue_full(void)
{
 return ((_queue.nTail+1)%5 == _queue.nHead)?1:0;
}

canonical_original_code:
int is_queue_full()
{
 return ((_queue.nTail+1)%5 == _queue.nHead)?1:0;
}


decompiled_code:
__int64 __fastcall en_queue(__int64 a1)
{
unsigned int v1; // ecx

++LODWORD(queue[1]);
v1 = queue[0];
queue[SLODWORD(queue[0]) + 2] = a1;
LODWORD(queue[0]) = (int)(v1 + 1) % 5;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
unsigned int v1; // ecx

++LODWORD(queue[1]);
v1 = queue[0];
queue[SLODWORD(queue[0]) + 2] = a1;
LODWORD(queue[0]) = (int)(v1 + 1) % 5;
return v1;
}

original_code:
int en_queue(void *p)
{
 int pos;
 _queue.count += 1;
 pos = _queue.nTail;
 _queue.pat_queue[_queue.nTail] = p;
 _queue.nTail = (_queue.nTail + 1)%5;
 return pos;
}

variable_types:
p
void *

variable_types: pos int


decompiled_code:
__int64 de_queue()
{
int v0; // eax
__int64 v1; // rdx
__int64 v2; // rcx

--LODWORD(queue[1]);
v0 = HIDWORD(queue[0]);
v1 = v0 + 2LL;
v2 = queue[v1];
queue[v1] = 0LL;
HIDWORD(queue[0]) = (v0 + 1) % 5;
return v2;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // eax
__int64 v1; // rdx
__int64 v2; // rcx

--LODWORD(queue[1]);
v0 = HIDWORD(queue[0]);
v1 = v0 + 2LL;
v2 = queue[v1];
queue[v1] = 0LL;
HIDWORD(queue[0]) = (v0 + 1) % 5;
return v2;
}

original_code:
void *de_queue(void)
{
 void *p;
 _queue.count -= 1;
 p = _queue.pat_queue[_queue.nHead];
 _queue.pat_queue[_queue.nHead] = ((void *)0);
 _queue.nHead = (_queue.nHead+1)%5;
 return p;
}

canonical_original_code:
void *de_queue()
{
 void *p;
 _queue.count -= 1;
 p = _queue.pat_queue[_queue.nHead];
 _queue.pat_queue[_queue.nHead] = ((void *)0);
 _queue.nHead = (_queue.nHead+1)%5;
 return p;
}

return_type: void *


decompiled_code:
__int64 queue_count()
{
return LODWORD(queue[1]);
}

canonical_decompiled_code:
__int64 func14()
{
return LODWORD(queue[1]);
}

original_code:
int queue_count(void)
{
 return _queue.count;
}

canonical_original_code:
int queue_count()
{
 return _queue.count;
}


decompiled_code:
__int64 __fastcall query_queue(int a1)
{
return queue[(HIDWORD(queue[0]) + a1) % 5 + 2];
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
return queue[(HIDWORD(queue[0]) + a1) % 5 + 2];
}

original_code:
void *query_queue(int offset)
{
 int i;
 i = (_queue.nHead + offset)%5;
 return _queue.pat_queue[i];
}

variable_types: offset int


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

if ( a1 == -1 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)((a1 + 5 - HIDWORD(queue[0])) % 5 + 1);
return result;
}

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

if ( a1 == -1 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)((a1 + 5 - HIDWORD(queue[0])) % 5 + 1);
return result;
}

original_code:
int get_queue_sequence(int index)
{
 if(index==-1) return -1;
 return ((index+5)-_queue.nHead)%5 + 1;
}

variable_types: index int


OpQuery

decompiled_code:
void __fastcall OpQuery(int a1, __int64 a2)
{
int v2; // ebp
__int64 v3; // rbx
int v4; // ebx
unsigned int v5; // eax
int v6[18]; // [rsp+0h] [rbp-48h] BYREF

if ( a1 )
{
if ( a1 == 1 )
{
v4 = *(char *)(a2 + 4) - 49;
v5 = get_queue_sequence(HIDWORD(PatientInfo[5 * v4 + 4]));
api_print_patient_query_info(
PatientInfo[5 * v4 + 1],
PatientInfo[5 * v4 + 4],
v5,
PatientInfo[5 * v4 + 3],
HIDWORD(PatientInfo[5 * v4 + 2]));
}
}
else
{
v2 = queue_count();
v6[0] = v2;
if ( v2 > 0 )
{
v3 = 0LL;
do
{
*(_QWORD *)&v6[2 * v3 + 2] = *(_QWORD *)(query_queue(v3) + 8);
++v3;
}
while ( v2 > (int)v3 );
}
api_print_doctor_query_info(v6);
}
}

canonical_decompiled_code:
void __fastcall func17(int a1, __int64 a2)
{
int v2; // ebp
__int64 v3; // rbx
int v4; // ebx
unsigned int v5; // eax
int v6[18]; // [rsp+0h] [rbp-48h] BYREF

if ( a1 )
{
if ( a1 == 1 )
{
v4 = *(char *)(a2 + 4) - 49;
v5 = func16(HIDWORD(PatientInfo[5 * v4 + 4]));
func4(
PatientInfo[5 * v4 + 1],
PatientInfo[5 * v4 + 4],
v5,
PatientInfo[5 * v4 + 3],
HIDWORD(PatientInfo[5 * v4 + 2]));
}
}
else
{
v2 = func14();
v6[0] = v2;
if ( v2 > 0 )
{
v3 = 0LL;
do
{
*(_QWORD *)&v6[2 * v3 + 2] = *(_QWORD *)(func15(v3) + 8);
++v3;
}
while ( v2 > (int)v3 );
}
func5(v6);
}
}

original_code:
void OpQuery(unsigned int nMethod)
{
 Goods_STRU *p[6];
 if(nMethod == 0){
  p[0] = &g_astGoods[0];
  p[1] = &g_astGoods[1];
  p[2] = &g_astGoods[2];
  p[3] = &g_astGoods[3];
  p[4] = &g_astGoods[4];
  p[5] = &g_astGoods[5];
  GoodsSort((Goods_STRU **)&p, 6);
  __PrintGoods((Goods_STRU **)&p, 6);
 }else if(nMethod == 1){
  apiPrintMoney(g_stSaveBox);
 }else{
  apiPrintErrInfo(E010);
 }
}

canonical_original_code:
void OpQuery(unsigned int nMethod)
{
 struct tagGoods *p[6];
 if(nMethod == 0){
  p[0] = &g_astGoods[0];
  p[1] = &g_astGoods[1];
  p[2] = &g_astGoods[2];
  p[3] = &g_astGoods[3];
  p[4] = &g_astGoods[4];
  p[5] = &g_astGoods[5];
  GoodsSort((struct tagGoods **)&p, 6);
  __PrintGoods((struct tagGoods **)&p, 6);
 }else if(nMethod == 1){
  apiPrintMoney(g_stSaveBox);
 }else{
  apiPrintErrInfo(E010);
 }
}

variable_types:
nMethod
unsigned int

variable_types: struct tagGoods { char szName[-1]; unsigned int nPrice; unsigned int nNumber; } *[6]


decompiled_code:
__int64 __fastcall cmd_parser(__int64 a1, __int64 a2)
{
char *v3; // rcx
const char *v4; // rbp
char v5; // al
char *v6; // rax
const void *v7; // rbp
char *v8; // rax
char *v9; // r12
char *v10; // rbp
char *v11; // rax
unsigned __int64 v12; // rcx
__int64 v13; // rdx
__int64 result; // rax
char *v15; // r12
size_t v16; // rdx
unsigned __int64 v17; // rsi
__int64 v18; // rdx
char *v19; // rbp
unsigned __int64 v20; // rdx
unsigned __int64 v21; // rdx
unsigned __int64 v22; // rcx
const char *v23; // rbp
char *v24; // rax

*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 24) = 0LL;
*(_QWORD *)(a2 + 32) = 0LL;
*(_QWORD *)(a2 + 40) = 0LL;
*(_QWORD *)(a2 + 48) = 0LL;
v3 = receive;
*(_QWORD *)receive = 0LL;
*((_QWORD *)v3 + 63) = 0LL;
memset(
(void *)((unsigned __int64)(v3 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 512) >> 3));
gets(receive);
v4 = receive;
v5 = *receive;
if ( *receive == 81 )
return strstr(receive, "QUIT") == 0LL ? -1 : 4;
if ( v5 > 81 )
{
if ( v5 == 83 )
{
v15 = strstr(receive, "SELECT");
if ( v15 )
{
v16 = strlen(v4);
result = 2LL;
if ( v16 > 6 )
{
strcpy((char *)a2, v15 + 7);
result = 2LL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else if ( v5 == 68 )
{
v24 = strstr(receive, "DELETE");
if ( v24 )
{
if ( v24[6] )
{
strcpy((char *)a2, v24 + 7);
result = 3LL;
}
else
{
puts("DELETE NO ID INPUT!");
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else if ( v5 == 73 )
{
v6 = strstr(receive, "INSERT");
if ( v6 )
{
v7 = v6 + 7;
v8 = strchr(v6 + 7, 44);
v9 = v8;
if ( v8 )
{
memcpy((void *)a2, v7, v8 - (_BYTE *)v7);
v10 = v9 + 1;
v11 = strchr(v9 + 1, 44);
if ( v11 )
{
v12 = v11 - v10;
if ( v11 - v10 > 16 )
{
puts("INSERT INVALID NAME LEN!");
result = 0xFFFFFFFFLL;
}
else
{
v13 = a2 + 8;
if ( v12 >= 8 )
{
*(_QWORD *)(a2 + 8) = *(_QWORD *)(v9 + 1);
*(_QWORD *)(a2 + v12) = *((_QWORD *)v11 - 1);
v17 = (a2 + 16) & 0xFFFFFFFFFFFFFFF8LL;
v18 = v13 - v17;
v19 = &v10[-v18];
v20 = (v12 + v18) & 0xFFFFFFFFFFFFFFF8LL;
if ( v20 >= 8 )
{
v21 = v20 & 0xFFFFFFFFFFFFFFF8LL;
v22 = 0LL;
do
{
*(_QWORD *)(v17 + v22) = *(_QWORD *)&v19[v22];
v22 += 8LL;
}
while ( v22 < v21 );
}
}
else if ( (v12 & 4) != 0 )
{
*(_DWORD *)(a2 + 8) = *(_DWORD *)(v9 + 1);
*(_DWORD *)(v13 + v12 - 4) = *((_DWORD *)v11 - 1);
}
else if ( v12 )
{
*(_BYTE *)(a2 + 8) = v9[1];
if ( (v12 & 2) != 0 )
*(_WORD *)(v13 + v12 - 2) = *((_WORD *)v11 - 1);
}
v23 = v11 + 1;
if ( strlen(v11 + 1) > 0x10 )
{
puts("INSERT INVALID TELNO LEN!");
result = 0xFFFFFFFFLL;
}
else
{
strcpy((char *)(a2 + 28), v23);
result = 1LL;
}
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
char *v3; // rcx
const char *v4; // rbp
char v5; // al
char *v6; // rax
const void *v7; // rbp
char *v8; // rax
char *v9; // r12
char *v10; // rbp
char *v11; // rax
unsigned __int64 v12; // rcx
__int64 v13; // rdx
__int64 result; // rax
char *v15; // r12
size_t v16; // rdx
unsigned __int64 v17; // rsi
__int64 v18; // rdx
char *v19; // rbp
unsigned __int64 v20; // rdx
unsigned __int64 v21; // rdx
unsigned __int64 v22; // rcx
const char *v23; // rbp
char *v24; // rax

*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 24) = 0LL;
*(_QWORD *)(a2 + 32) = 0LL;
*(_QWORD *)(a2 + 40) = 0LL;
*(_QWORD *)(a2 + 48) = 0LL;
v3 = receive;
*(_QWORD *)receive = 0LL;
*((_QWORD *)v3 + 63) = 0LL;
memset(
(void *)((unsigned __int64)(v3 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 512) >> 3));
gets(receive);
v4 = receive;
v5 = *receive;
if ( *receive == 81 )
return strstr(receive, "QUIT") == 0LL ? -1 : 4;
if ( v5 > 81 )
{
if ( v5 == 83 )
{
v15 = strstr(receive, "SELECT");
if ( v15 )
{
v16 = strlen(v4);
result = 2LL;
if ( v16 > 6 )
{
strcpy((char *)a2, v15 + 7);
result = 2LL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else if ( v5 == 68 )
{
v24 = strstr(receive, "DELETE");
if ( v24 )
{
if ( v24[6] )
{
strcpy((char *)a2, v24 + 7);
result = 3LL;
}
else
{
puts("DELETE NO ID INPUT!");
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else if ( v5 == 73 )
{
v6 = strstr(receive, "INSERT");
if ( v6 )
{
v7 = v6 + 7;
v8 = strchr(v6 + 7, 44);
v9 = v8;
if ( v8 )
{
memcpy((void *)a2, v7, v8 - (_BYTE *)v7);
v10 = v9 + 1;
v11 = strchr(v9 + 1, 44);
if ( v11 )
{
v12 = v11 - v10;
if ( v11 - v10 > 16 )
{
puts("INSERT INVALID NAME LEN!");
result = 0xFFFFFFFFLL;
}
else
{
v13 = a2 + 8;
if ( v12 >= 8 )
{
*(_QWORD *)(a2 + 8) = *(_QWORD *)(v9 + 1);
*(_QWORD *)(a2 + v12) = *((_QWORD *)v11 - 1);
v17 = (a2 + 16) & 0xFFFFFFFFFFFFFFF8LL;
v18 = v13 - v17;
v19 = &v10[-v18];
v20 = (v12 + v18) & 0xFFFFFFFFFFFFFFF8LL;
if ( v20 >= 8 )
{
v21 = v20 & 0xFFFFFFFFFFFFFFF8LL;
v22 = 0LL;
do
{
*(_QWORD *)(v17 + v22) = *(_QWORD *)&v19[v22];
v22 += 8LL;
}
while ( v22 < v21 );
}
}
else if ( (v12 & 4) != 0 )
{
*(_DWORD *)(a2 + 8) = *(_DWORD *)(v9 + 1);
*(_DWORD *)(v13 + v12 - 4) = *((_DWORD *)v11 - 1);
}
else if ( v12 )
{
*(_BYTE *)(a2 + 8) = v9[1];
if ( (v12 & 2) != 0 )
*(_WORD *)(v13 + v12 - 2) = *((_WORD *)v11 - 1);
}
v23 = v11 + 1;
if ( strlen(v11 + 1) > 0x10 )
{
puts("INSERT INVALID TELNO LEN!");
result = 0xFFFFFFFFLL;
}
else
{
strcpy((char *)(a2 + 28), v23);
result = 1LL;
}
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int cmd_parser(char *cmd, struct student_t *pin)
{
    int cmd_type;
    char *p, *pend;
    memset(pin, 0, sizeof(struct student_t));
    memset(receive, 0, 512);
    gets(receive);
    cmd_type = -1;
    switch(*receive){
        case 'I':
            p = strstr(receive, "INSERT");
            if(p!=((void *)0)){
                p = p + strlen("INSERT")+1;
                pend = strstr(p, ",");
                if(pend!=((void *)0)){
                    memcpy(pin->num, p, pend - p);
                }else{
                    break;
                }
                p = pend + 1;
                pend = strstr(p, ",");
                if(pend!=((void *)0)){
                    if((pend-p)>16){
                        printf("INSERT INVALID NAME LEN!\n");
                        break;
                    }
                    memcpy(pin->name, p, pend-p);
                }else{
                    break;
                }
                p = pend + 1;
                if(strlen(p)>16){
                    printf("INSERT INVALID TELNO LEN!\n");
                    break;
                }
                strcpy(pin->phone, p);
                cmd_type = 1;
            }
            break;
        case 'S':
            p = strstr(receive, "SELECT");
            if(p!=((void *)0)){
                if(strlen(receive)>strlen("SELECT")){
                    p = p + strlen("SELECT") + 1;
                    strcpy(pin->num, p);
                }
                cmd_type = 2;
            }
            break;
        case 'D':
            p = strstr(receive, "DELETE");
            if(p!=((void *)0)){
                p = p + strlen("DELETE");
                if(*p!='\0'){
                    strcpy(pin->num, p+1);
                    cmd_type = 3;
                }
                else{
                    printf("DELETE NO ID INPUT!\n");
                }
            }
            break;
        case 'Q':
            p = strstr(receive, "QUIT");
            if(p!=((void *)0)){
                cmd_type = 4;
            }
            break;
        default:
            break;
    }
    return cmd_type;
}

canonical_original_code:
int cmd_parser(char *cmd, struct student_t *pin)
{
    int cmd_type;
    char *p; char *pend;
    memset(pin, 0, sizeof(struct student_t));
    memset(receive, 0, 512);
    gets(receive);
    cmd_type = -1;
    switch(*receive){
        case 'I':
            p = strstr(receive, "INSERT");
            if(p!=((void *)0)){
                p = p + strlen("INSERT")+1;
                pend = strstr(p, ",");
                if(pend!=((void *)0)){
                    memcpy(pin->num, p, pend - p);
                }else{
                    break;
                }
                p = pend + 1;
                pend = strstr(p, ",");
                if(pend!=((void *)0)){
                    if((pend-p)>16){
                        printf("INSERT INVALID NAME LEN!\n");
                        break;
                    }
                    memcpy(pin->name, p, pend-p);
                }else{
                    break;
                }
                p = pend + 1;
                if(strlen(p)>16){
                    printf("INSERT INVALID TELNO LEN!\n");
                    break;
                }
                strcpy(pin->phone, p);
                cmd_type = 1;
            }
            break;
        case 'S':
            p = strstr(receive, "SELECT");
            if(p!=((void *)0)){
                if(strlen(receive)>strlen("SELECT")){
                    p = p + strlen("SELECT") + 1;
                    strcpy(pin->num, p);
                }
                cmd_type = 2;
            }
            break;
        case 'D':
            p = strstr(receive, "DELETE");
            if(p!=((void *)0)){
                p = p + strlen("DELETE");
                if(*p!='\0'){
                    strcpy(pin->num, p+1);
                    cmd_type = 3;
                }
                else{
                    printf("DELETE NO ID INPUT!\n");
                }
            }
            break;
        case 'Q':
            p = strstr(receive, "QUIT");
            if(p!=((void *)0)){
                cmd_type = 4;
            }
            break;
        default:
            break;
    }
    return cmd_type;
}

variable_types:
cmd
char *

variable_types: struct student_t { char num[8]; char name[20]; char phone[20]; struct student_t *next; } *

variable_types:
p
char *

variable_types:
pend
char *


insert

decompiled_code:
int __fastcall insert(char *src)
{
void *v2; // rbp

if ( list_search(src) )
return printf("INSERT %s,%s,%s ALREADY EXIST.\n", src, src + 8, src + 28);
v2 = malloc(0x38uLL);
*(_QWORD *)v2 = 0LL;
*((_QWORD *)v2 + 1) = 0LL;
*((_QWORD *)v2 + 2) = 0LL;
*((_QWORD *)v2 + 3) = 0LL;
*((_QWORD *)v2 + 4) = 0LL;
*((_QWORD *)v2 + 5) = 0LL;
*((_QWORD *)v2 + 6) = 0LL;
strcpy((char *)v2, src);
strcpy((char *)v2 + 8, src + 8);
strcpy((char *)v2 + 28, src + 28);
list_add((__int64)v2);
return printf("INSERT %s,%s,%s SUCCESS.\n", (const char *)v2, (const char *)v2 + 8, (const char *)v2 + 28);
}

canonical_decompiled_code:
int __fastcall func3(char *src)
{
void *v2; // rbp

if ( list_search(src) )
return printf("INSERT %s,%s,%s ALREADY EXIST.\n", src, src + 8, src + 28);
v2 = malloc(0x38uLL);
*(_QWORD *)v2 = 0LL;
*((_QWORD *)v2 + 1) = 0LL;
*((_QWORD *)v2 + 2) = 0LL;
*((_QWORD *)v2 + 3) = 0LL;
*((_QWORD *)v2 + 4) = 0LL;
*((_QWORD *)v2 + 5) = 0LL;
*((_QWORD *)v2 + 6) = 0LL;
strcpy((char *)v2, src);
strcpy((char *)v2 + 8, src + 8);
strcpy((char *)v2 + 28, src + 28);
func1((__int64)v2);
return printf("INSERT %s,%s,%s SUCCESS.\n", (const char *)v2, (const char *)v2 + 8, (const char *)v2 + 28);
}

original_code:
void insert(struct student_t *p)
{
    struct student_t *new;
    if(list_search(p->num)==((void *)0)){
        new = (struct student_t *)malloc(sizeof(struct student_t));
        memset(new, 0, sizeof(struct student_t));
        strcpy(new->num, p->num);
        strcpy(new->name, p->name);
        strcpy(new->phone, p->phone);
        list_add(new);
        printf("INSERT %s,%s,%s SUCCESS.\n", new->num, new->name, new->phone);
    }else{
        printf("INSERT %s,%s,%s ALREADY EXIST.\n", p->num, p->name, p->phone);
    }
}

user_defined_types: struct student_t { char num[8]; char name[20]; char phone[20]; struct student_t *next; }


delete

decompiled_code:
void __fastcall delete(char *a1)
{
_QWORD *v1; // rax
__int64 v2; // rbx
char *v3; // rbp

v1 = list_search(a1);
if ( v1 )
{
v2 = (__int64)v1;
v3 = (char *)v1[6];
printf("DELETE %s,%s,%s SUCCESS.\n", v3, v3 + 8, v3 + 28);
list_del(v2);
free(v3);
}
else
{
printf("DELETE %s FAILED BECAUSE NOT EXIST.\n", a1);
}
}

canonical_decompiled_code:
void __fastcall func4(char *a1)
{
_QWORD *v1; // rax
__int64 v2; // rbx
char *v3; // rbp

v1 = list_search(a1);
if ( v1 )
{
v2 = (__int64)v1;
v3 = (char *)v1[6];
printf("DELETE %s,%s,%s SUCCESS.\n", v3, v3 + 8, v3 + 28);
func2(v2);
free(v3);
}
else
{
printf("DELETE %s FAILED BECAUSE NOT EXIST.\n", a1);
}
}

original_code:
void delete(struct student_t *p)
{
    struct student_t *node;
    node = list_search(p->num);
    if(node!=((void *)0)){
        p = node->next;
        printf("DELETE %s,%s,%s SUCCESS.\n", p->num, p->name, p->phone);
        list_del(node);
        free(p);
    }else{
        printf("DELETE %s FAILED BECAUSE NOT EXIST.\n", p->num);
    }
}


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

v0 = *((_QWORD *)&List + 6);
if ( !v0 )
return puts("SELECT NULL.");
do
{
result = printf("%s,%s,%s\n", (const char *)v0, (const char *)(v0 + 8), (const char *)(v0 + 28));
v0 = *(_QWORD *)(v0 + 48);
}
while ( v0 );
return result;
}

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

v0 = *((_QWORD *)&List + 6);
if ( !v0 )
return puts("SELECT NULL.");
do
{
result = printf("%s,%s,%s\n", (const char *)v0, (const char *)(v0 + 8), (const char *)(v0 + 28));
v0 = *(_QWORD *)(v0 + 48);
}
while ( v0 );
return result;
}

original_code:
void print_list()
{
    struct student_t *p;
    p = List.next;
    if(p==((void *)0)) printf("SELECT NULL.\n");
    else
        while(p!=((void *)0)){
            printf("%s,%s,%s\n", p->num, p->name, p->phone);
            p = p->next;
        }
}


select

decompiled_code:
int __fastcall select(char *a1)
{
int result; // eax
_QWORD *v2; // rax

if ( !*a1 )
return print_list();
v2 = list_search(a1);
if ( v2 )
result = printf("%s,%s,%s\n", (const char *)v2[6], (const char *)(v2[6] + 8LL), (const char *)(v2[6] + 28LL));
else
result = printf("SELECT %s FAILED BECAUSE NOT EXIST.\n", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func6(char *a1)
{
int result; // eax
_QWORD *v2; // rax

if ( !*a1 )
return func5();
v2 = list_search(a1);
if ( v2 )
result = printf("%s,%s,%s\n", (const char *)v2[6], (const char *)(v2[6] + 8LL), (const char *)(v2[6] + 28LL));
else
result = printf("SELECT %s FAILED BECAUSE NOT EXIST.\n", a1);
return result;
}

original_code:
void select(struct student_t *p)
{
    struct student_t *node;
    if(strlen(p->num)==0){
        print_list();
    }else{
        node = list_search(p->num);
        if(node==((void *)0)){
            printf("SELECT %s FAILED BECAUSE NOT EXIST.\n", p->num);
        }else{
            node = node->next;
            printf("%s,%s,%s\n", node->num, node->name, node->phone);
        }
    }
}


quit

decompiled_code:
void quit()
{
_QWORD *i; // rdi

free(receive);
for ( i = (_QWORD *)*((_QWORD *)&List + 6); i; i = (_QWORD *)*((_QWORD *)&List + 6) )
{
*((_QWORD *)&List + 6) = i[6];
free(i);
}
}

canonical_decompiled_code:
void func7()
{
_QWORD *i; // rdi

free(receive);
for ( i = (_QWORD *)*((_QWORD *)&List + 6); i; i = (_QWORD *)*((_QWORD *)&List + 6) )
{
*((_QWORD *)&List + 6) = i[6];
free(i);
}
}

original_code:
void quit(void)
{
    struct student_t *p;
    free(receive);
    while(List.next!=((void *)0)){
        p = List.next;
        List.next = List.next->next;
        free(p);
    }
}

canonical_original_code:
void quit()
{
    struct student_t *p;
    free(receive);
    while(List.next!=((void *)0)){
        p = List.next;
        List.next = List.next->next;
        free(p);
    }
}


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

*(_QWORD *)(a1 + 48) = 0LL;
if ( *((_QWORD *)&List + 6) )
{
result = pTail;
*(_QWORD *)(pTail + 48) = a1;
}
else
{
*((_QWORD *)&List + 6) = a1;
}
pTail = a1;
return result;
}

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

*(_QWORD *)(a1 + 48) = 0LL;
if ( *((_QWORD *)&List + 6) )
{
result = pTail;
*(_QWORD *)(pTail + 48) = a1;
}
else
{
*((_QWORD *)&List + 6) = a1;
}
pTail = a1;
return result;
}

original_code:
void list_add(struct student_t *new)
{
    new->next = ((void *)0);
    if(List.next==((void *)0)){
        List.next= new;
        pTail = new;
    }else{
        pTail->next = new;
        pTail = new;
    }
}


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

result = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 48LL);
*(_QWORD *)(a1 + 48) = result;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 48LL);
*(_QWORD *)(a1 + 48) = result;
return result;
}

original_code:
void list_del(struct student_t *node)
{
    struct student_t *tmp;
    tmp = node->next->next;
    node->next = tmp;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

*((_QWORD *)&List + 6) = 0LL;
pTail = 0LL;
receive = (char *)malloc(0x200uLL);
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v3 = cmd_parser(0LL, (__int64)v5);
if ( v3 != 1 )
break;
insert(v5);
}
if ( v3 != 3 )
break;
delete(v5);
}
if ( v3 != 2 )
break;
select(v5);
}
}
while ( v3 != 4 );
quit();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

*((_QWORD *)&List + 6) = 0LL;
pTail = 0LL;
receive = (char *)malloc(0x200uLL);
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v3 = func0(0LL, (__int64)v5);
if ( v3 != 1 )
break;
func3(v5);
}
if ( v3 != 3 )
break;
func4(v5);
}
if ( v3 != 2 )
break;
func6(v5);
}
}
while ( v3 != 4 );
func7();
return 0;
}

original_code:
int main(void)
{
    struct student_t temp;
    int cmd_type;
    List.next= ((void *)0);
    pTail = ((void *)0);
    receive = malloc(512);
    while(1){
        cmd_type = cmd_parser(((void *)0),&temp);
        if(cmd_type==1){
            insert(&temp);
        }else if(cmd_type == 3){
            delete(&temp);
        }else if(cmd_type == 2){
            select(&temp);
        }else if(cmd_type == 4){
            break;
        }
    }
    quit();
    return 0;
}

canonical_original_code:
int main()
{
    struct student_t temp;
    int cmd_type;
    List.next= ((void *)0);
    pTail = ((void *)0);
    receive = malloc(512);
    while(1){
        cmd_type = cmd_parser(((void *)0),&temp);
        if(cmd_type==1){
            insert(&temp);
        }else if(cmd_type == 3){
            delete(&temp);
        }else if(cmd_type == 2){
            select(&temp);
        }else if(cmd_type == 4){
            break;
        }
    }
    quit();
    return 0;
}

variable_types: struct student_t { char num[8]; char name[20]; char phone[20]; struct student_t *next; }


original_code:
int param_parser(char *pstr, int len, char *param1, char *param2, int num)
{
 int i, cnt;
 int pos[2];
 pos[0] = 0;
 pos[1] = 0;
 cnt = 0;
 i = 0;
 while(i<len){
  while((pstr[i]==0)&&(i<len)) i++;
  if(i>=len) break;
  cnt++;
  if(cnt>num){
   break;
  }else if(cnt==2){
   pos[0] = i;
  }else if(cnt==3){
   pos[1] = i;
  }
  while(pstr[i]!=0) i++;
 }
 if(cnt<num){
  printf("error:参数过少\n");
  return -1;
 }else if(cnt>num){
  printf("error:参数过多\n");
  return -1;
 }else{
  strcpy(param1, pstr+pos[0]);
  strcpy(param2, pstr+pos[1]);
 }
 return 0;
}

canonical_original_code:
int param_parser(char *pstr, int len, char *param1, char *param2, int num)
{
 int i; int cnt;
 int pos[2];
 pos[0] = 0;
 pos[1] = 0;
 cnt = 0;
 i = 0;
 while(i<len){
  while((pstr[i]==0)&&(i<len)) i++;
  if(i>=len) break;
  cnt++;
  if(cnt>num){
   break;
  }else if(cnt==2){
   pos[0] = i;
  }else if(cnt==3){
   pos[1] = i;
  }
  while(pstr[i]!=0) i++;
 }
 if(cnt<num){
  printf("error:参数过少\n");
  return -1;
 }else if(cnt>num){
  printf("error:参数过多\n");
  return -1;
 }else{
  strcpy(param1, pstr+pos[0]);
  strcpy(param2, pstr+pos[1]);
 }
 return 0;
}

variable_types:
pstr
char *

variable_types: len int

variable_types: num int

variable_types: cnt int

variable_types:
pos
int [2]


decompiled_code:
__int64 __fastcall cmd_search(char *s2, char *a2)
{
int v2; // ebp

if ( !strcmp(s2, a2) )
return 0xFFFFFFFFLL;
v2 = list_search(s2);
return (unsigned int)-!((v2 != -1) & (v2 == (unsigned int)list_search(a2)));
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2, char *a2)
{
int v2; // ebp

if ( !strcmp(s2, a2) )
return 0xFFFFFFFFLL;
v2 = func2(s2);
return (unsigned int)-!((v2 != -1) & (v2 == (unsigned int)func2(a2)));
}

original_code:
int cmd_search(char *word1, char *word2)
{
 int id1, id2;
 if(strcmp(word1, word2)==0){
  return -1;
 }
 id1 = list_search(word1);
 id2 = list_search(word2);
 if((id1==id2)&&(id1!=-1)){
  return 0;
 }else{
  return -1;
 }
}

canonical_original_code:
int cmd_search(char *word1, char *word2)
{
 int id1; int id2;
 if(strcmp(word1, word2)==0){
  return -1;
 }
 id1 = list_search(word1);
 id2 = list_search(word2);
 if((id1==id2)&&(id1!=-1)){
  return 0;
 }else{
  return -1;
 }
}


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

for ( result = *((_QWORD *)&list_head + 9); result; result = *(_QWORD *)(result + 72) )
{
if ( *(_DWORD *)(result + 64) == a1 )
*(_DWORD *)(result + 64) = a2;
}
return result;
}

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

for ( result = *((_QWORD *)&list_head + 9); result; result = *(_QWORD *)(result + 72) )
{
if ( *(_DWORD *)(result + 64) == a1 )
*(_DWORD *)(result + 64) = a2;
}
return result;
}

original_code:
void list_update(int old_id, int new_id)
{
 struct list_t *curr;
 curr = list_head.next;
 while(curr!=((void *)0)){
  if(curr->id==old_id){
   curr->id = new_id;
  }
  curr = curr->next;
 }
}

variable_types: struct list_t { char word[64]; int id; struct list_t *next; } *


decompiled_code:
__int64 __fastcall cmd_set(char *s2, char *a2)
{
int v2; // ebx
int v3; // eax
int v4; // esi
__int64 result; // rax

if ( !strcmp(s2, a2) )
return 0xFFFFFFFFLL;
v2 = list_search(s2);
v3 = list_search(a2);
if ( v2 == v3 )
{
if ( v2 == -1 )
{
list_add(s2, ++gID);
list_add(a2, gID);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else if ( v2 == -1 )
{
list_add(s2, v3);
result = 0LL;
}
else if ( v3 == -1 )
{
list_add(a2, v2);
result = 0LL;
}
else
{
v4 = v3;
if ( v2 <= v3 )
v4 = v2;
if ( v2 >= v3 )
v3 = v2;
list_update(v3, v4);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2, char *a2)
{
int v2; // ebx
int v3; // eax
int v4; // esi
__int64 result; // rax

if ( !strcmp(s2, a2) )
return 0xFFFFFFFFLL;
v2 = func2(s2);
v3 = func2(a2);
if ( v2 == v3 )
{
if ( v2 == -1 )
{
func1(s2, ++gID);
func1(a2, gID);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else if ( v2 == -1 )
{
func1(s2, v3);
result = 0LL;
}
else if ( v3 == -1 )
{
func1(a2, v2);
result = 0LL;
}
else
{
v4 = v3;
if ( v2 <= v3 )
v4 = v2;
if ( v2 >= v3 )
v3 = v2;
func4(v3, v4);
result = 0LL;
}
return result;
}

original_code:
int cmd_set(char *world1, char *world2)
{
 int id1, id2;
 int old_id, new_id;
 if(strcmp(world1, world2)==0){
  return -1;
 }
 id1 = list_search(world1);
 id2 = list_search(world2);
 if(id1==id2){
  if(id1==-1){
   gID++;
   list_add(world1, gID);
   list_add(world2, gID);
  }else{
   return -1;
  }
 }else{
  if(id1==-1){
   list_add(world1, id2);
  }else if(id2==-1){
   list_add(world2, id1);
  }else{
   old_id = id1>id2?id1:id2;
   new_id = id1>id2?id2:id1;
   list_update(old_id, new_id);
  }
 }
 return 0;
}

canonical_original_code:
int cmd_set(char *world1, char *world2)
{
 int id1; int id2;
 int old_id; int new_id;
 if(strcmp(world1, world2)==0){
  return -1;
 }
 id1 = list_search(world1);
 id2 = list_search(world2);
 if(id1==id2){
  if(id1==-1){
   gID++;
   list_add(world1, gID);
   list_add(world2, gID);
  }else{
   return -1;
  }
 }else{
  if(id1==-1){
   list_add(world1, id2);
  }else if(id2==-1){
   list_add(world2, id1);
  }else{
   old_id = id1>id2?id1:id2;
   new_id = id1>id2?id2:id1;
   list_update(old_id, new_id);
  }
 }
 return 0;
}


decompiled_code:
void list_clear()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = (_QWORD *)*((_QWORD *)&list_head + 9);
*((_QWORD *)&list_head + 9) = 0LL;
while ( v0 )
{
v1 = v0;
v0 = (_QWORD *)v0[9];
free(v1);
}
}

canonical_decompiled_code:
void func6()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = (_QWORD *)*((_QWORD *)&list_head + 9);
*((_QWORD *)&list_head + 9) = 0LL;
while ( v0 )
{
v1 = v0;
v0 = (_QWORD *)v0[9];
free(v1);
}
}

original_code:
void list_clear(void)
{
 void *p;
 struct list_t *curr;
 curr = list_head.next;
 list_head.next = ((void *)0);
 while(curr!=((void *)0)){
  p = curr;
  curr = curr->next;
  free(p);
 }
}

canonical_original_code:
void list_clear()
{
 void *p;
 struct list_t *curr;
 curr = list_head.next;
 list_head.next = ((void *)0);
 while(curr!=((void *)0)){
  p = curr;
  curr = curr->next;
  free(p);
 }
}

variable_types:
p
void *

user_defined_types: struct list_t { char word[64]; int id; struct list_t *next; }


decompiled_code:
void cmd_clear()
{
gID = 0;
list_clear();
}

canonical_decompiled_code:
void func7()
{
gID = 0;
func6();
}

original_code:
void cmd_clear(void)
{
 gID = 0;
 list_clear();
}


decompiled_code:
__int64 __fastcall list_add(char *src, int a2)
{
char *v2; // rbx
__int64 result; // rax

v2 = (char *)malloc(0x50uLL);
strcpy(v2, src);
*((_DWORD *)v2 + 16) = a2;
result = *((_QWORD *)&list_head + 9);
*((_QWORD *)v2 + 9) = result;
*((_QWORD *)&list_head + 9) = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, int a2)
{
char *v2; // rbx
__int64 result; // rax

v2 = (char *)malloc(0x50uLL);
strcpy(v2, src);
*((_DWORD *)v2 + 16) = a2;
result = *((_QWORD *)&list_head + 9);
*((_QWORD *)v2 + 9) = result;
*((_QWORD *)&list_head + 9) = v2;
return result;
}

original_code:
void list_add(char *word, int id)
{
 struct list_t *p;
 p = (struct list_t *)malloc(sizeof(struct list_t));
 strcpy(p->word, word);
 p->id = id;
 p->next = list_head.next;
 list_head.next = p;
}

variable_types:
word
char *

variable_types: id int


decompiled_code:
__int64 __fastcall list_search(char *s2)
{
__int64 v1; // rbx

v1 = *((_QWORD *)&list_head + 9);
if ( !v1 )
return 0xFFFFFFFFLL;
while ( strcmp((const char *)v1, s2) )
{
v1 = *(_QWORD *)(v1 + 72);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v1 + 64);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
__int64 v1; // rbx

v1 = *((_QWORD *)&list_head + 9);
if ( !v1 )
return 0xFFFFFFFFLL;
while ( strcmp((const char *)v1, s2) )
{
v1 = *(_QWORD *)(v1 + 72);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v1 + 64);
}

original_code:
int list_search(char *word)
{
 int id;
 struct list_t *curr;
 id = -1;
 curr = list_head.next;
 while(curr!=((void *)0)){
  if(strcmp(curr->word, word)==0){
   id = curr->id;
   break;
  }
  curr = curr->next;
 }
 return id;
}


decompiled_code:
__int64 __fastcall cmd_process(const char *a1)
{
int v2; // ebp
const unsigned __int16 **v3; // rsi
__int64 v4; // rdi
const char *v5; // rax
const char *v6; // rax
bool v7; // zf
unsigned int v8; // er12
char v10[64]; // [rsp+0h] [rbp-98h] BYREF
char s2[88]; // [rsp+40h] [rbp-58h] BYREF

v2 = strlen(a1);
if ( v2 > 0 )
{
v3 = _ctype_b_loc();
v4 = (__int64)&a1[v2 - 1 + 1];
v5 = a1;
do
{
if ( ((*v3)[*v5] & 8) == 0 )
*v5 = 0;
++v5;
}
while ( v5 != (const char *)v4 );
}
if ( *a1 )
{
v6 = a1;
}
else
{
v6 = a1;
do
++v6;
while ( !*v6 );
}
v7 = strcmp(v6, "SetSynonyms") == 0;
v8 = !v7;
if ( v7 )
{
if ( (unsigned int)param_parser((__int64)a1, v2, s2, v10, 3) )
return v8;
v8 = cmd_set(s2, v10);
if ( !v8 )
return v8;
LABEL_18:
puts("false");
return 0;
}
v7 = strcmp(v6, "IsSynonyms") == 0;
v8 = !v7;
if ( v7 )
{
if ( (unsigned int)param_parser((__int64)a1, v2, s2, v10, 3) )
return v8;
v8 = cmd_search(s2, v10);
if ( !v8 )
{
puts("true");
return v8;
}
goto LABEL_18;
}
v7 = strcmp(v6, "ClearRelations") == 0;
v8 = !v7;
if ( v7 )
{
if ( !(unsigned int)param_parser((__int64)a1, v2, s2, v10, 1) )
{
cmd_clear();
v8 = 0;
}
}
else
{
puts(aError_0);
v8 = -1;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
int v2; // ebp
const unsigned __int16 **v3; // rsi
__int64 v4; // rdi
const char *v5; // rax
const char *v6; // rax
bool v7; // zf
unsigned int v8; // er12
char v10[64]; // [rsp+0h] [rbp-98h] BYREF
char s2[88]; // [rsp+40h] [rbp-58h] BYREF

v2 = strlen(a1);
if ( v2 > 0 )
{
v3 = _ctype_b_loc();
v4 = (__int64)&a1[v2 - 1 + 1];
v5 = a1;
do
{
if ( ((*v3)[*v5] & 8) == 0 )
*v5 = 0;
++v5;
}
while ( v5 != (const char *)v4 );
}
if ( *a1 )
{
v6 = a1;
}
else
{
v6 = a1;
do
++v6;
while ( !*v6 );
}
v7 = strcmp(v6, "SetSynonyms") == 0;
v8 = !v7;
if ( v7 )
{
if ( (unsigned int)func0((__int64)a1, v2, s2, v10, 3) )
return v8;
v8 = func5(s2, v10);
if ( !v8 )
return v8;
LABEL_18:
puts("false");
return 0;
}
v7 = strcmp(v6, "IsSynonyms") == 0;
v8 = !v7;
if ( v7 )
{
if ( (unsigned int)func0((__int64)a1, v2, s2, v10, 3) )
return v8;
v8 = func3(s2, v10);
if ( !v8 )
{
puts("true");
return v8;
}
goto LABEL_18;
}
v7 = strcmp(v6, "ClearRelations") == 0;
v8 = !v7;
if ( v7 )
{
if ( !(unsigned int)func0((__int64)a1, v2, s2, v10, 1) )
{
func7();
v8 = 0;
}
}
else
{
puts(aError_0);
v8 = -1;
}
return v8;
}

original_code:
int cmd_process(char *pstr)
{
 char *p;
 int i, len, ret;
 char param1[64];
 char param2[64];
 len = strlen(pstr);
 p = pstr;
 for(i=0; i<len; i++){
  if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalnum)==0) *p = 0;
  p++;
 }
 p = pstr;
 while(*p==0) p++;
 if(strcmp(p, "SetSynonyms")==0){
  ret = param_parser(pstr, len, param1, param2, 3);
  if(ret==0){
   if(cmd_set(param1, param2)!=0){
    printf("false\n");
   }
  }
 }else if(strcmp(p, "IsSynonyms")==0){
  ret = param_parser(pstr, len, param1, param2, 3);
  if(ret==0){
   if(cmd_search(param1, param2)==0){
    printf("true\n");
   }else{
    printf("false\n");
   }
  }
 }else if(strcmp(p, "ClearRelations")==0){
  ret = param_parser(pstr, len, param1, param2, 1);
  if(ret==0){
   cmd_clear();
  }
 }else{
  printf("error:系统不支持该命令\n");
  return -1;
 }
 return 0;
}

canonical_original_code:
int cmd_process(char *pstr)
{
 char *p;
 int i; int len; int ret;
 char param1[64];
 char param2[64];
 len = strlen(pstr);
 p = pstr;
 for(i=0; i<len; i++){
  if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalnum)==0) *p = 0;
  p++;
 }
 p = pstr;
 while(*p==0) p++;
 if(strcmp(p, "SetSynonyms")==0){
  ret = param_parser(pstr, len, param1, param2, 3);
  if(ret==0){
   if(cmd_set(param1, param2)!=0){
    printf("false\n");
   }
  }
 }else if(strcmp(p, "IsSynonyms")==0){
  ret = param_parser(pstr, len, param1, param2, 3);
  if(ret==0){
   if(cmd_search(param1, param2)==0){
    printf("true\n");
   }else{
    printf("false\n");
   }
  }
 }else if(strcmp(p, "ClearRelations")==0){
  ret = param_parser(pstr, len, param1, param2, 1);
  if(ret==0){
   cmd_clear();
  }
 }else{
  printf("error:系统不支持该命令\n");
  return -1;
 }
 return 0;
}

variable_types: i int

variable_types: ret int


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

while ( (unsigned int)_isoc99_scanf(" %[^\n]", v4) != -1 )
cmd_process(v4);
list_clear();
return 0;
}

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

while ( (unsigned int)_isoc99_scanf(" %[^\n]", v4) != -1 )
func8(v4);
func6();
return 0;
}

original_code:
int main(void)
{
 char input[1024];
 while(scanf(" %[^\n]", input)!=(-1)){
  cmd_process(input);
 }
 list_clear();
    return 0;
}

canonical_original_code:
int main()
{
 char input[1024];
 while(scanf(" %[^\n]", input)!=(-1)){
  cmd_process(input);
 }
 list_clear();
    return 0;
}

variable_types:
input
char [1024]


decompiled_code:
int Check_TermialSize()
{
int result; // eax

if ( LINES <= 25 || COLS <= 82 )
{
if ( wmove(stdscr, 4, 4) != -1 )
waddnstr(stdscr, "ERROR : Termial Size is too small!", -1);
result = wmove(stdscr, 5, 4);
if ( result != -1 )
{
waddnstr(stdscr, " Please resize it, and try again...", -1);
result = -1;
}
}
else
{
dword_780 = (LINES - 22) / 2;
dword_784 = (COLS - 79) / 2;
g_window = (COLS - 79) / 2;
dword_764 = (LINES - 22) / 2;
dword_768 = dword_784 + 78;
dword_76C = dword_780 + 21;
dword_770 = dword_784 + 27;
dword_774 = dword_780 + 2;
dword_778 = dword_784 + 76;
dword_77C = dword_780 + 19;
result = 0;
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

if ( LINES <= 25 || COLS <= 82 )
{
if ( wmove(stdscr, 4, 4) != -1 )
waddnstr(stdscr, "ERROR : Termial Size is too small!", -1);
result = wmove(stdscr, 5, 4);
if ( result != -1 )
{
waddnstr(stdscr, " Please resize it, and try again...", -1);
result = -1;
}
}
else
{
dword_780 = (LINES - 22) / 2;
dword_784 = (COLS - 79) / 2;
g_window = (COLS - 79) / 2;
dword_764 = (LINES - 22) / 2;
dword_768 = dword_784 + 78;
dword_76C = dword_780 + 21;
dword_770 = dword_784 + 27;
dword_774 = dword_780 + 2;
dword_778 = dword_784 + 76;
dword_77C = dword_780 + 19;
result = 0;
}
return result;
}

original_code:
static int Check_TermialSize(void)
{
 if((LINES<(16 + 6)+4)||(COLS<(48 + 31)+4)){
  (wmove((stdscr),((4)),((4))) == (-1) ? (-1) : waddnstr((stdscr),(("ERROR : Termial Size is too small!")),-1));
  (wmove((stdscr),((5)),((4))) == (-1) ? (-1) : waddnstr((stdscr),(("        Please resize it, and try again...")),-1));
  return -1;
 }
 g_window.Line_offset = (LINES - (16 + 6))/2;
 g_window.Col_offset = (COLS - (48 + 31))/2;
 g_window.TopLeft_x = g_window.Col_offset;
 g_window.TopLeft_y = g_window.Line_offset;
 g_window.BottomRight_x = (48 + 31) + g_window.Col_offset - 1;
 g_window.BottomRight_y = (16 + 6) + g_window.Line_offset - 1;
 g_window.G_TopLeft_x = g_window.TopLeft_x + 27;
 g_window.G_TopLeft_y = g_window.TopLeft_y + 2;
 g_window.G_BottomRight_x = g_window.G_TopLeft_x + 48 + 1;
 g_window.G_BottomRight_y = g_window.G_TopLeft_y + 16 + 1;
 return 0;
}

canonical_original_code:
static int Check_TermialSize()
{
 if((LINES<(16 + 6)+4)||(COLS<(48 + 31)+4)){
  (wmove((stdscr),((4)),((4))) == (-1) ? (-1) : waddnstr((stdscr),(("ERROR : Termial Size is too small!")),-1));
  (wmove((stdscr),((5)),((4))) == (-1) ? (-1) : waddnstr((stdscr),(("        Please resize it, and try again...")),-1));
  return -1;
 }
 g_window.Line_offset = (LINES - (16 + 6))/2;
 g_window.Col_offset = (COLS - (48 + 31))/2;
 g_window.TopLeft_x = g_window.Col_offset;
 g_window.TopLeft_y = g_window.Line_offset;
 g_window.BottomRight_x = (48 + 31) + g_window.Col_offset - 1;
 g_window.BottomRight_y = (16 + 6) + g_window.Line_offset - 1;
 g_window.G_TopLeft_x = g_window.TopLeft_x + 27;
 g_window.G_TopLeft_y = g_window.TopLeft_y + 2;
 g_window.G_BottomRight_x = g_window.G_TopLeft_x + 48 + 1;
 g_window.G_BottomRight_y = g_window.G_TopLeft_y + 16 + 1;
 return 0;
}


decompiled_code:
int Init_Disp()
{
int result; // eax
int v1; // ebp
int i; // ebx
int j; // ebx
int k; // ebx

initscr();
result = Check_TermialSize();
if ( !result )
{
v1 = 0;
cbreak();
noecho();
curs_set(0);
start_color();
init_pair(1, 1, 0);
init_pair(2, 3, 3);
init_pair(3, 0, 0);
init_pair(4, 0, 2);
wattrset(stdscr, 0);
wattr_on(stdscr, 0x40000uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
for ( i = 0; i != 22; ++i )
{
if ( wmove(stdscr, dword_764 + i, g_window) != -1 )
waddch(stdscr, 0x20uLL);
if ( wmove(stdscr, dword_764 + i, dword_768) != -1 )
waddch(stdscr, 0x20uLL);
}
for ( j = 0; j != 79; ++j )
{
if ( wmove(stdscr, dword_764, g_window + j) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, dword_76C, g_window + j) != -1 )
waddch(stdscr, 0x20uLL);
}
for ( k = 0; k != 18; ++k )
{
if ( wmove(stdscr, dword_774 + k, dword_770) != -1 )
waddch(stdscr, 0x20uLL);
if ( wmove(stdscr, dword_774 + k, dword_778) != -1 )
waddch(stdscr, 0x20uLL);
}
do
{
if ( wmove(stdscr, dword_774, dword_770 + v1) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, dword_77C, dword_770 + v1) != -1 )
waddch(stdscr, 0x20uLL);
++v1;
}
while ( v1 != 50 );
wattr_off(stdscr, 0x100uLL, 0LL);
curs_set(0);
wattr_on(stdscr, 0x400uLL, 0LL);
if ( wmove(stdscr, dword_764 + 2, g_window + 2) != -1 )
waddnstr(stdscr, " Game : snake", -1);
if ( wmove(stdscr, dword_764 + 3, g_window + 2) != -1 )
waddnstr(stdscr, "Version : 0.01", -1);
if ( wmove(stdscr, dword_764 + 4, g_window + 2) != -1 )
waddnstr(stdscr, " Author : shmily", -1);
if ( wmove(stdscr, dword_764 + 7, g_window + 2) != -1 )
waddnstr(stdscr, "Usage :", -1);
if ( wmove(stdscr, dword_764 + 9, g_window + 2) != -1 )
waddnstr(stdscr, "F for speed up", -1);
if ( wmove(stdscr, dword_764 + 10, g_window + 2) != -1 )
waddnstr(stdscr, "S for speed down", -1);
if ( wmove(stdscr, dword_764 + 11, g_window + 2) != -1 )
waddnstr(stdscr, "Q for quit", -1);
if ( wmove(stdscr, dword_764 + 13, g_window + 2) != -1 )
waddnstr(stdscr, "Nagivation key to moving.", -1);
wattr_off(stdscr, 0x400uLL, 0LL);
result = wrefresh(stdscr);
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
int v1; // ebp
int i; // ebx
int j; // ebx
int k; // ebx

initscr();
result = func0();
if ( !result )
{
v1 = 0;
cbreak();
noecho();
curs_set(0);
start_color();
init_pair(1, 1, 0);
init_pair(2, 3, 3);
init_pair(3, 0, 0);
init_pair(4, 0, 2);
wattrset(stdscr, 0);
wattr_on(stdscr, 0x40000uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
for ( i = 0; i != 22; ++i )
{
if ( wmove(stdscr, dword_764 + i, g_window) != -1 )
waddch(stdscr, 0x20uLL);
if ( wmove(stdscr, dword_764 + i, dword_768) != -1 )
waddch(stdscr, 0x20uLL);
}
for ( j = 0; j != 79; ++j )
{
if ( wmove(stdscr, dword_764, g_window + j) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, dword_76C, g_window + j) != -1 )
waddch(stdscr, 0x20uLL);
}
for ( k = 0; k != 18; ++k )
{
if ( wmove(stdscr, dword_774 + k, dword_770) != -1 )
waddch(stdscr, 0x20uLL);
if ( wmove(stdscr, dword_774 + k, dword_778) != -1 )
waddch(stdscr, 0x20uLL);
}
do
{
if ( wmove(stdscr, dword_774, dword_770 + v1) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, dword_77C, dword_770 + v1) != -1 )
waddch(stdscr, 0x20uLL);
++v1;
}
while ( v1 != 50 );
wattr_off(stdscr, 0x100uLL, 0LL);
curs_set(0);
wattr_on(stdscr, 0x400uLL, 0LL);
if ( wmove(stdscr, dword_764 + 2, g_window + 2) != -1 )
waddnstr(stdscr, " Game : snake", -1);
if ( wmove(stdscr, dword_764 + 3, g_window + 2) != -1 )
waddnstr(stdscr, "Version : 0.01", -1);
if ( wmove(stdscr, dword_764 + 4, g_window + 2) != -1 )
waddnstr(stdscr, " Author : shmily", -1);
if ( wmove(stdscr, dword_764 + 7, g_window + 2) != -1 )
waddnstr(stdscr, "Usage :", -1);
if ( wmove(stdscr, dword_764 + 9, g_window + 2) != -1 )
waddnstr(stdscr, "F for speed up", -1);
if ( wmove(stdscr, dword_764 + 10, g_window + 2) != -1 )
waddnstr(stdscr, "S for speed down", -1);
if ( wmove(stdscr, dword_764 + 11, g_window + 2) != -1 )
waddnstr(stdscr, "Q for quit", -1);
if ( wmove(stdscr, dword_764 + 13, g_window + 2) != -1 )
waddnstr(stdscr, "Nagivation key to moving.", -1);
wattr_off(stdscr, 0x400uLL, 0LL);
result = wrefresh(stdscr);
}
return result;
}

variable_types: j int


decompiled_code:
int Curs_Return()
{
int result; // eax

result = wmove(stdscr, 0, 0);
if ( result != -1 )
result = waddch(stdscr, 0x20uLL);
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax

result = wmove(stdscr, 0, 0);
if ( result != -1 )
result = waddch(stdscr, 0x20uLL);
return result;
}


DrawPoint

decompiled_code:
__int64 __fastcall DrawPoint(unsigned int a1, unsigned int a2, char a3)
{
int v4; // ebx
int v5; // ebp

if ( a1 > 0x2F )
return 0xFFFFFFFFLL;
if ( a2 > 0xF )
return 0xFFFFFFFFLL;
v4 = dword_770 + a1 + 1;
v5 = dword_774 + a2 + 1;
wattr_on(stdscr, 0x200uLL, 0LL);
if ( wmove(stdscr, v5, v4) != -1 )
waddch(stdscr, (unsigned int)a3);
wattr_on(stdscr, 0x200uLL, 0LL);
Curs_Return();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2, char a3)
{
int v4; // ebx
int v5; // ebp

if ( a1 > 0x2F )
return 0xFFFFFFFFLL;
if ( a2 > 0xF )
return 0xFFFFFFFFLL;
v4 = dword_770 + a1 + 1;
v5 = dword_774 + a2 + 1;
wattr_on(stdscr, 0x200uLL, 0LL);
if ( wmove(stdscr, v5, v4) != -1 )
waddch(stdscr, (unsigned int)a3);
wattr_on(stdscr, 0x200uLL, 0LL);
func2();
return 0LL;
}

variable_types: x int

variable_types: y int

variable_types: ascii char