main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
int v8; // eax
const char *v9; // rdx
int v10; // eax
__int128 v12; // [rsp+0h] [rbp-258h] BYREF
__int128 v13; // [rsp+10h] [rbp-248h]
__int128 v14; // [rsp+20h] [rbp-238h]
__int128 v15; // [rsp+30h] [rbp-228h]
char s[536]; // [rsp+40h] [rbp-218h] BYREF

v12 = 0LL;
v3 = s;
memset(mahjong, 0, sizeof(mahjong));
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
while ( gets(&v12, argv, envp) )
{
paserInput((char *)&v12);
v8 = isWin(&v12, argv, v4, v5, v6, v7, v12, *((_QWORD *)&v12 + 1));
if ( v8 == -1 )
v8 = is7pair();
v9 = "false";
argv = (const char **)"%s\n";
if ( !v8 )
v9 = "true";
v10 = sprintf(v3, "%s\n", v9);
v12 = 0LL;
v3 += v10;
v13 = 0LL;
memset(mahjong, 0, sizeof(mahjong));
v14 = 0LL;
v15 = 0LL;
}
printf("%s", s);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
int v8; // eax
const char *v9; // rdx
int v10; // eax
__int128 v12; // [rsp+0h] [rbp-258h] BYREF
__int128 v13; // [rsp+10h] [rbp-248h]
__int128 v14; // [rsp+20h] [rbp-238h]
__int128 v15; // [rsp+30h] [rbp-228h]
char s[536]; // [rsp+40h] [rbp-218h] BYREF

v12 = 0LL;
v3 = s;
memset(mahjong, 0, sizeof(mahjong));
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
while ( gets(&v12, argv, envp) )
{
func0((char *)&v12);
v8 = func3(&v12, argv, v4, v5, v6, v7, v12, *((_QWORD *)&v12 + 1));
if ( v8 == -1 )
v8 = func1();
v9 = "false";
argv = (const char **)"%s\n";
if ( !v8 )
v9 = "true";
v10 = sprintf(v3, "%s\n", v9);
v12 = 0LL;
v3 += v10;
v13 = 0LL;
memset(mahjong, 0, sizeof(mahjong));
v14 = 0LL;
v15 = 0LL;
}
printf("%s", s);
return 0;
}

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


repo: shmily/linux

decompiled_code:
unsigned __int64 __fastcall is_break(_BYTE *a1)
{
unsigned __int64 result; // rax

result = 0LL;
if ( *a1 <= 0x3Fu )
result = (0x8800500300000001LL >> *a1) & 1;
return result;
}

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

result = 0LL;
if ( *a1 <= 0x3Fu )
result = (0x8800500300000001LL >> *a1) & 1;
return result;
}

variable_types:
p
char *

return_type: int


canonical_name: main

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 }

return_type: void


OpPay

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);
if ( a2 == 1 )
{
sprintf(v6, aE012S, a1, a3, a4, a5);
return libOutputStr(v6);
}
if ( a2 == 2 )
{
sprintf(v6, aE012S_0, a1, a4);
}
else
{
if ( a2 )
return result;
sprintf(v6, format, a1, a4);
}
result = libOutputStr(v6);
}
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);
if ( a2 == 1 )
{
sprintf(v6, aE012S, a1, a3, a4, a5);
return func0(v6);
}
if ( a2 == 2 )
{
sprintf(v6, aE012S_0, a1, a4);
}
else
{
if ( a2 )
return result;
sprintf(v6, format, a1, a4);
}
result = func0(v6);
}
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]


decompiled_code:
void __fastcall api_print_doctor_query_info(int *a1)
{
int v1; // esi
int v2; // eax
_DWORD *v3; // rbx
__int64 v4; // r12
size_t v5; // rax
const char *v6; // rsi
__int128 v7[33]; // [rsp+0h] [rbp-218h] BYREF

if ( a1 )
{
v1 = *a1;
memset(v7, 0, 0x200uLL);
if ( v1 )
{
v2 = *a1;
LODWORD(v7[1]) = -1998217320;
WORD2(v7[1]) = 151;
v7[0] = (__int128)_mm_load_si128((const __m128i *)&LC16);
if ( v2 > 0 )
{
v3 = a1 + 2;
v4 = (__int64)&a1[2 * (v2 - 1) + 4];
do
{
v3 += 2;
v5 = strlen((const char *)v7);
v6 = (const char *)*((_QWORD *)v3 - 1);
*(_WORD *)((char *)v7 + v5) = 32;
strcpy((char *)v7 + v5 + 1, v6);
}
while ( v3 != (_DWORD *)v4 );
}
libOutputStr((const char *)v7);
}
else
{
libOutputStr(aE013Dct);
}
}
}

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

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)
{
__int64 result; // rax

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

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

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

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()
{
__int64 v0; // rdx
int v1; // eax
__int64 v2; // r8

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

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

v0 = SHIDWORD(queue[0]);
--LODWORD(queue[1]);
v1 = v0;
v0 += 2LL;
v2 = queue[v0];
queue[v0] = 0LL;
HIDWORD(queue[0]) = (v1 + 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; // eax
int *v3; // r8
int v4; // esi
int v5; // ecx
__int64 v6; // rax
__int64 v7; // rcx
unsigned int v8; // eax
__int64 v9; // r9
int v10; // [rsp+0h] [rbp-38h] BYREF

if ( a1 )
{
if ( a1 == 1 )
{
v8 = get_queue_sequence(PatientInfo[10 * *(char *)(a2 + 4) - 481]);
api_print_patient_query_info(
*(_QWORD *)(v9 + 8),
*(_DWORD *)(v9 + 32),
v8,
*(_DWORD *)(v9 + 24),
*(_DWORD *)(v9 + 20));
}
}
else
{
v2 = queue_count();
v3 = &v10;
v10 = v2;
v4 = v2;
if ( v2 > 0 )
{
v5 = 0;
do
{
v6 = query_queue(v5);
*(_QWORD *)&v3[2 * v7 + 2] = *(_QWORD *)(v6 + 8);
v5 = v7 + 1;
}
while ( v4 > v5 );
}
api_print_doctor_query_info(v3);
}
}

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 *v2; // rcx
char *v3; // r12
char v4; // al
char *v5; // rax
const void *v6; // r12
char *v7; // rax
char *v8; // rbx
char *v9; // r13
char *v10; // rax
char *v11; // r12
unsigned __int64 v12; // rdx
__int64 v13; // rax
char *v14; // rbx
size_t v15; // rax
unsigned int v16; // eax
__int64 v17; // rcx
char *v19; // rbx
const char *v20; // rdi
unsigned int v21; // er12
char *v22; // rax
unsigned __int64 v23; // rcx
__int64 v24; // rax
char *v25; // r13
unsigned __int64 v26; // rax
unsigned __int64 v27; // rax
unsigned __int64 v28; // rdx
unsigned __int64 v29; // rbp
__int64 v30; // rcx
char *v31; // rbx
unsigned int v32; // eax
unsigned int v33; // eax
unsigned int v34; // edx
__int64 v35; // rcx

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
char *v2; // rcx
char *v3; // r12
char v4; // al
char *v5; // rax
const void *v6; // r12
char *v7; // rax
char *v8; // rbx
char *v9; // r13
char *v10; // rax
char *v11; // r12
unsigned __int64 v12; // rdx
__int64 v13; // rax
char *v14; // rbx
size_t v15; // rax
unsigned int v16; // eax
__int64 v17; // rcx
char *v19; // rbx
const char *v20; // rdi
unsigned int v21; // er12
char *v22; // rax
unsigned __int64 v23; // rcx
__int64 v24; // rax
char *v25; // r13
unsigned __int64 v26; // rax
unsigned __int64 v27; // rax
unsigned __int64 v28; // rdx
unsigned __int64 v29; // rbp
__int64 v30; // rcx
char *v31; // rbx
unsigned int v32; // eax
unsigned int v33; // eax
unsigned int v34; // edx
__int64 v35; // rcx

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

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)
{
char *v2; // r12
const char *v3; // rdx
const char *v4; // rcx

if ( list_search(src) )
return printf("INSERT %s,%s,%s ALREADY EXIST.\n", src, src + 8, src + 28);
v2 = (char *)calloc(0x38uLL, 1uLL);
strcpy(v2, src);
strcpy(v2 + 8, src + 8);
strcpy(v2 + 28, src + 28);
list_add((__int64)v2);
return printf("INSERT %s,%s,%s SUCCESS.\n", v2, v3, v4);
}

canonical_decompiled_code:
int __fastcall func3(char *src)
{
char *v2; // r12
const char *v3; // rdx
const char *v4; // rcx

if ( list_search(src) )
return printf("INSERT %s,%s,%s ALREADY EXIST.\n", src, src + 8, src + 28);
v2 = (char *)calloc(0x38uLL, 1uLL);
strcpy(v2, src);
strcpy(v2 + 8, src + 8);
strcpy(v2 + 28, src + 28);
func1((__int64)v2);
return printf("INSERT %s,%s,%s SUCCESS.\n", v2, v3, v4);
}

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
char *v2; // r12
__int64 v3; // rbp

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

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

v1 = list_search(a1);
if ( v1 )
{
v2 = (char *)v1[6];
v3 = (__int64)v1;
printf("DELETE %s,%s,%s SUCCESS.\n", v2, v2 + 8, v2 + 28);
func2(v3);
free(v2);
}
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;
pTail = a1;
*(_QWORD *)(result + 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;
pTail = a1;
*(_QWORD *)(result + 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; // er12

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; // er12

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; // ebp
int v3; // eax
int v4; // er8
__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);
return 0LL;
}
return 0xFFFFFFFFLL;
}
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; // ebp
int v3; // eax
int v4; // er8
__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);
return 0LL;
}
return 0xFFFFFFFFLL;
}
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; // rax
char *v3; // rax
char *v4; // rdx
__int64 result; // rax

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

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

v2 = (char *)malloc(0x50uLL);
v3 = strcpy(v2, src);
*((_DWORD *)v3 + 16) = a2;
v4 = v3;
result = *((_QWORD *)&list_head + 9);
*((_QWORD *)&list_head + 9) = v4;
*((_QWORD *)v4 + 9) = result;
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; // ebx
const unsigned __int16 **v3; // rdi
const char *v4; // rax
const char *i; // rax
unsigned int v6; // er12
char v8[64]; // [rsp+0h] [rbp-98h] BYREF
char v9[88]; // [rsp+40h] [rbp-58h] BYREF

v2 = strlen(a1);
if ( v2 > 0 )
{
v3 = _ctype_b_loc();
v4 = a1;
do
{
if ( ((*v3)[*v4] & 8) == 0 )
*v4 = 0;
++v4;
}
while ( v4 != &a1[v2 - 1 + 1] );
}
for ( i = a1; !*i; ++i )
;
if ( !strcmp(i, "SetSynonyms") )
{
if ( (unsigned int)param_parser((__int64)a1, v2, v8, v9, 3) || !(unsigned int)cmd_set(v8, v9) )
return 0;
goto LABEL_19;
}
if ( !strcmp(i, "IsSynonyms") )
{
if ( (unsigned int)param_parser((__int64)a1, v2, v8, v9, 3) )
return 0;
v6 = cmd_search(v8, v9);
if ( !v6 )
{
puts("true");
return v6;
}
LABEL_19:
puts("false");
return 0;
}
if ( strcmp(i, "ClearRelations") )
{
v6 = -1;
puts(aError_0);
return v6;
}
if ( (unsigned int)param_parser((__int64)a1, v2, v8, v9, 1) )
return 0;
cmd_clear();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
int v2; // ebx
const unsigned __int16 **v3; // rdi
const char *v4; // rax
const char *i; // rax
unsigned int v6; // er12
char v8[64]; // [rsp+0h] [rbp-98h] BYREF
char v9[88]; // [rsp+40h] [rbp-58h] BYREF

v2 = strlen(a1);
if ( v2 > 0 )
{
v3 = _ctype_b_loc();
v4 = a1;
do
{
if ( ((*v3)[*v4] & 8) == 0 )
*v4 = 0;
++v4;
}
while ( v4 != &a1[v2 - 1 + 1] );
}
for ( i = a1; !*i; ++i )
;
if ( !strcmp(i, "SetSynonyms") )
{
if ( (unsigned int)func0((__int64)a1, v2, v8, v9, 3) || !(unsigned int)func5(v8, v9) )
return 0;
goto LABEL_19;
}
if ( !strcmp(i, "IsSynonyms") )
{
if ( (unsigned int)func0((__int64)a1, v2, v8, v9, 3) )
return 0;
v6 = func3(v8, v9);
if ( !v6 )
{
puts("true");
return v6;
}
LABEL_19:
puts("false");
return 0;
}
if ( strcmp(i, "ClearRelations") )
{
v6 = -1;
puts(aError_0);
return v6;
}
if ( (unsigned int)func0((__int64)a1, v2, v8, v9, 1) )
return 0;
func7();
return 0LL;
}

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 v0; // edx
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
{
v0 = (COLS - 79) >> 1;
dword_720 = (LINES - 22) >> 1;
dword_708 = v0 + 78;
dword_70C = dword_720 + 21;
dword_724 = v0;
g_window = v0;
dword_704 = (LINES - 22) >> 1;
dword_710 = v0 + 27;
dword_71C = dword_720 + 19;
result = 0;
dword_714 = dword_720 + 2;
dword_718 = v0 + 76;
}
return result;
}

canonical_decompiled_code:
int func0()
{
int v0; // edx
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
{
v0 = (COLS - 79) >> 1;
dword_720 = (LINES - 22) >> 1;
dword_708 = v0 + 78;
dword_70C = dword_720 + 21;
dword_724 = v0;
g_window = v0;
dword_704 = (LINES - 22) >> 1;
dword_710 = v0 + 27;
dword_71C = dword_720 + 19;
result = 0;
dword_714 = dword_720 + 2;
dword_718 = v0 + 76;
}
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 v2; // ebx
int i; // ebx
int j; // ebx

initscr();
result = Check_TermialSize();
if ( !result )
{
v1 = 0;
v2 = 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);
do
{
if ( wmove(stdscr, v2 + dword_704, g_window) != -1 )
waddch(stdscr, 0x20uLL);
if ( wmove(stdscr, v2 + dword_704, dword_708) != -1 )
waddch(stdscr, 0x20uLL);
++v2;
}
while ( v2 != 22 );
for ( i = 0; i != 79; ++i )
{
if ( wmove(stdscr, dword_704, i + g_window) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, dword_70C, i + g_window) != -1 )
waddch(stdscr, 0x20uLL);
}
for ( j = 0; j != 18; ++j )
{
if ( wmove(stdscr, j + dword_714, dword_710) != -1 )
waddch(stdscr, 0x20uLL);
if ( wmove(stdscr, j + dword_714, dword_718) != -1 )
waddch(stdscr, 0x20uLL);
}
do
{
if ( wmove(stdscr, dword_714, v1 + dword_710) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, dword_71C, v1 + dword_710) != -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_704 + 2, g_window + 2) != -1 )
waddnstr(stdscr, " Game : snake", -1);
if ( wmove(stdscr, dword_704 + 3, g_window + 2) != -1 )
waddnstr(stdscr, "Version : 0.01", -1);
if ( wmove(stdscr, dword_704 + 4, g_window + 2) != -1 )
waddnstr(stdscr, " Author : shmily", -1);
if ( wmove(stdscr, dword_704 + 7, g_window + 2) != -1 )
waddnstr(stdscr, "Usage :", -1);
if ( wmove(stdscr, dword_704 + 9, g_window + 2) != -1 )
waddnstr(stdscr, "F for speed up", -1);
if ( wmove(stdscr, dword_704 + 10, g_window + 2) != -1 )
waddnstr(stdscr, "S for speed down", -1);
if ( wmove(stdscr, dword_704 + 11, g_window + 2) != -1 )
waddnstr(stdscr, "Q for quit", -1);
if ( wmove(stdscr, dword_704 + 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 v2; // ebx
int i; // ebx
int j; // ebx

initscr();
result = func0();
if ( !result )
{
v1 = 0;
v2 = 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);
do
{
if ( wmove(stdscr, v2 + dword_704, g_window) != -1 )
waddch(stdscr, 0x20uLL);
if ( wmove(stdscr, v2 + dword_704, dword_708) != -1 )
waddch(stdscr, 0x20uLL);
++v2;
}
while ( v2 != 22 );
for ( i = 0; i != 79; ++i )
{
if ( wmove(stdscr, dword_704, i + g_window) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, dword_70C, i + g_window) != -1 )
waddch(stdscr, 0x20uLL);
}
for ( j = 0; j != 18; ++j )
{
if ( wmove(stdscr, j + dword_714, dword_710) != -1 )
waddch(stdscr, 0x20uLL);
if ( wmove(stdscr, j + dword_714, dword_718) != -1 )
waddch(stdscr, 0x20uLL);
}
do
{
if ( wmove(stdscr, dword_714, v1 + dword_710) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, dword_71C, v1 + dword_710) != -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_704 + 2, g_window + 2) != -1 )
waddnstr(stdscr, " Game : snake", -1);
if ( wmove(stdscr, dword_704 + 3, g_window + 2) != -1 )
waddnstr(stdscr, "Version : 0.01", -1);
if ( wmove(stdscr, dword_704 + 4, g_window + 2) != -1 )
waddnstr(stdscr, " Author : shmily", -1);
if ( wmove(stdscr, dword_704 + 7, g_window + 2) != -1 )
waddnstr(stdscr, "Usage :", -1);
if ( wmove(stdscr, dword_704 + 9, g_window + 2) != -1 )
waddnstr(stdscr, "F for speed up", -1);
if ( wmove(stdscr, dword_704 + 10, g_window + 2) != -1 )
waddnstr(stdscr, "S for speed down", -1);
if ( wmove(stdscr, dword_704 + 11, g_window + 2) != -1 )
waddnstr(stdscr, "Q for quit", -1);
if ( wmove(stdscr, dword_704 + 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 v3; // er12
int v4; // ebp

if ( a1 > 0x2F || a2 > 0xF )
return 0xFFFFFFFFLL;
v3 = dword_710 + a1 + 1;
v4 = dword_714 + a2 + 1;
wattr_on(stdscr, 0x200uLL, 0LL);
if ( wmove(stdscr, v4, v3) != -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 v3; // er12
int v4; // ebp

if ( a1 > 0x2F || a2 > 0xF )
return 0xFFFFFFFFLL;
v3 = dword_710 + a1 + 1;
v4 = dword_714 + a2 + 1;
wattr_on(stdscr, 0x200uLL, 0LL);
if ( wmove(stdscr, v4, v3) != -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


ClearPoint

decompiled_code:
__int64 __fastcall ClearPoint(unsigned int a1, unsigned int a2)
{
int v2; // er12
int v3; // ebp

if ( a1 > 0x2F || a2 > 0xF )
return 0xFFFFFFFFLL;
v2 = dword_710 + a1 + 1;
v3 = dword_714 + a2 + 1;
wattr_on(stdscr, 0x300uLL, 0LL);
if ( wmove(stdscr, v3, v2) != -1 )
waddch(stdscr, 0x20uLL);
wattr_off(stdscr, 0x300uLL, 0LL);
Curs_Return();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2)
{
int v2; // er12
int v3; // ebp

if ( a1 > 0x2F || a2 > 0xF )
return 0xFFFFFFFFLL;
v2 = dword_710 + a1 + 1;
v3 = dword_714 + a2 + 1;
wattr_on(stdscr, 0x300uLL, 0LL);
if ( wmove(stdscr, v3, v2) != -1 )
waddch(stdscr, 0x20uLL);
wattr_off(stdscr, 0x300uLL, 0LL);
func2();
return 0LL;
}


decompiled_code:
void Game_loop()
{
snake_Move((unsigned int)G_key);
wrefresh(stdscr);
}

canonical_decompiled_code:
void func0()
{
snake_Move((unsigned int)G_key);
wrefresh(stdscr);
}

original_code:
void Game_loop(int mod)
{
 snake_Move(G_key);
 wrefresh(stdscr);
}

variable_types: mod int


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

keypad(stdscr, 1);
result = wgetch(stdscr);
G_key = result;
return result;
}

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

keypad(stdscr, 1);
result = wgetch(stdscr);
G_key = result;
return result;
}

original_code:
void Key_loop(void)
{
 keypad(stdscr, 1);
 G_key = wgetch(stdscr);
}

canonical_original_code:
void Key_loop()
{
 keypad(stdscr, 1);
 G_key = wgetch(stdscr);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Init_Disp(argc, argv, envp);
CreatSnake();
signal(14, (__sighandler_t)Game_loop);
set_ticker(400LL);
while ( !Game_over )
Key_loop();
endwin();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Init_Disp(argc, argv, envp);
CreatSnake();
signal(14, (__sighandler_t)Game_loop);
set_ticker(400LL);
while ( !Game_over )
func1();
endwin();
return 0;
}

original_code:
int main(void)
{
 Init_Disp();
 CreatSnake();
 signal(14, Game_loop);
 set_ticker(400);
 while(Game_over==0){
  Key_loop();
 }
 endwin();
 return 0;
}

canonical_original_code:
int main()
{
 Init_Disp();
 CreatSnake();
 signal(14, Game_loop);
 set_ticker(400);
 while(Game_over==0){
  Key_loop();
 }
 endwin();
 return 0;
}


hanoi

decompiled_code:
int __fastcall hanoi(unsigned int a1, char a2, char a3, char a4)
{
unsigned int v4; // er13
char v5; // bp

while ( 1 )
{
v4 = a4;
if ( a1 == 1 )
break;
v5 = a3;
hanoi(a1 - 1, (unsigned int)a2, (unsigned int)a4, (unsigned int)a3);
printf("will move %d from %c to %c.\n", a1, (unsigned int)a2, v4);
a4 = v4;
a3 = a2;
a2 = v5;
--a1;
}
return printf("will move %d from %c to %c.\n", 1LL, (unsigned int)a2, (unsigned int)a4);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1, char a2, char a3, char a4)
{
unsigned int v4; // er13
char v5; // bp

while ( 1 )
{
v4 = a4;
if ( a1 == 1 )
break;
v5 = a3;
func7(a1 - 1, (unsigned int)a2, (unsigned int)a4, (unsigned int)a3);
printf("will move %d from %c to %c.\n", a1, (unsigned int)a2, v4);
a4 = v4;
a3 = a2;
a2 = v5;
--a1;
}
return printf("will move %d from %c to %c.\n", 1LL, (unsigned int)a2, (unsigned int)a4);
}

original_code:
void hanoi( int n, char start, char middle, char end )
{
    if( n == 1 )
    {
        printf( "will move %d from %c to %c.\n", n, start, end );
    }
    else
    {
        hanoi( n - 1, start, end, middle );
        printf( "will move %d from %c to %c.\n", n, start, end );
        hanoi( n - 1, middle, start, end );
    }
}

canonical_original_code:
void hanoi(int n, char start, char middle, char end)
{
    if( n == 1 )
    {
        printf( "will move %d from %c to %c.\n", n, start, end );
    }
    else
    {
        hanoi( n - 1, start, end, middle );
        printf( "will move %d from %c to %c.\n", n, start, end );
        hanoi( n - 1, middle, start, end );
    }
}

variable_types: n int

variable_types: start char

variable_types: middle char

variable_types: end char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("input the number of plates;");
__isoc99_scanf();
hanoi(0LL, 65LL, 66LL, 67LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("input the number of plates;");
__isoc99_scanf();
func7(0LL, 65LL, 66LL, 67LL);
return 0;
}

original_code:
int main()
{
    int n = 0;
    printf( "input the number of plates;\n" );
    scanf( "%d", &n );
    hanoi( n, 'A', 'B', 'C' );
    return 0;
}


variable_types:
str
char *

variable_types: year int

variable_types: mon int

variable_types: day int

variable_types:
p
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
_BYTE v5[40]; // [rsp+0h] [rbp-28h] BYREF

gets(v5, argv, envp);
v3 = (unsigned int)check_id((__int64)v5);
printf("%d\n", v3);
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
_BYTE v5[40]; // [rsp+0h] [rbp-28h] BYREF

gets(v5, argv, envp);
v3 = (unsigned int)func0((__int64)v5);
printf("%d\n", v3);
return v3;
}

original_code:
int main(void)
{
 char str[32];
 int err;
 gets(str);
 err = check_id(str);
 printf("%d\n", err);
    return err;
}

canonical_original_code:
int main()
{
 char str[32];
 int err;
 gets(str);
 err = check_id(str);
 printf("%d\n", err);
    return err;
}

variable_types:
str
char [32]

variable_types: err int


GetByondAvgNumber

decompiled_code:
__int64 __fastcall GetByondAvgNumber(int *a1, int a2)
{
int *v2; // rdx
int *v3; // rcx
int v4; // eax
unsigned int v5; // er8
int v6; // eax
int v7; // edx

if ( a2 <= 0 )
return 0LL;
v2 = a1;
v3 = &a1[a2];
v4 = 0;
do
v4 += *v2++;
while ( v3 != v2 );
v5 = 0;
v6 = (a2 - 1 + v4) / a2;
do
{
v7 = *a1++ >= v6;
v5 += v7;
}
while ( v3 != a1 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int a2)
{
int *v2; // rdx
int *v3; // rcx
int v4; // eax
unsigned int v5; // er8
int v6; // eax
int v7; // edx

if ( a2 <= 0 )
return 0LL;
v2 = a1;
v3 = &a1[a2];
v4 = 0;
do
v4 += *v2++;
while ( v3 != v2 );
v5 = 0;
v6 = (a2 - 1 + v4) / a2;
do
{
v7 = *a1++ >= v6;
v5 += v7;
}
while ( v3 != a1 );
return v5;
}

original_code:
int GetByondAvgNumber(int iArray[], int iLen)
{
 int sum = 0;
 int average = 0;
 int count = 0;
 int i;
 int *p;
 p = iArray;
 i = iLen;
 while( i-- > 0 ){
  sum += *p++;
 }
 average = (sum + (iLen-1)) / iLen;
 p = iArray;
 i = iLen;
 while( i-- > 0){
  if(*p >= average) count++;
  p++;
 }
 return count;
}

variable_types:
iArray
int []

variable_types: iLen int

variable_types: sum int

variable_types: average int

variable_types: count int

variable_types: i int

variable_types:
p
int *


isPrime

decompiled_code:
__int64 __fastcall isPrime(int a1)
{
double v2; // xmm0_8
double v3; // xmm0_8
int v4; // esi
int v5; // ecx

if ( (unsigned int)(a1 - 2) <= 1 )
return 1LL;
if ( (a1 & 1) == 0 )
return 0LL;
v2 = (double)a1;
if ( (double)a1 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
v4 = (int)(v3 + 1.0);
if ( v4 <= 3 )
return 1LL;
if ( (unsigned int)(-1431655765 * a1 + 715827882) > 0x55555554 )
{
v5 = 3;
while ( 1 )
{
v5 += 2;
if ( v4 <= v5 )
break;
if ( !(a1 % v5) )
return 0LL;
}
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
double v2; // xmm0_8
double v3; // xmm0_8
int v4; // esi
int v5; // ecx

if ( (unsigned int)(a1 - 2) <= 1 )
return 1LL;
if ( (a1 & 1) == 0 )
return 0LL;
v2 = (double)a1;
if ( (double)a1 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
v4 = (int)(v3 + 1.0);
if ( v4 <= 3 )
return 1LL;
if ( (unsigned int)(-1431655765 * a1 + 715827882) > 0x55555554 )
{
v5 = 3;
while ( 1 )
{
v5 += 2;
if ( v4 <= v5 )
break;
if ( !(a1 % v5) )
return 0LL;
}
return 1LL;
}
return 0LL;
}

original_code:
int isPrime(int n)
{
 int i;
 int upper;
 if(n == 2|| n == 3)
  return 1;
 if(n % 2 ==0)
  return 0;
 upper = sqrt(n) + 1;
 for(i = 3;i < upper; i += 2){
  if(n %i == 0)
  return 0;
 }
 return 1;
}

variable_types: n int

variable_types: upper int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_scanf(&unk_A7, v5, envp);
v3 = isPrime(v5[0]);
printf("%d\n", v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_scanf(&unk_A7, v5, envp);
v3 = func0(v5[0]);
printf("%d\n", v3);
return 0;
}

original_code:
int main(void)
{
    int num;
    scanf("%d", &num);
    printf("%d\n", isPrime(num));
    return 0;
}

canonical_original_code:
int main()
{
    int num;
    scanf("%d", &num);
    printf("%d\n", isPrime(num));
    return 0;
}

variable_types: num int


decompiled_code:
__int64 __fastcall init_mask(_QWORD *a1)
{
_QWORD *v1; // rsi
unsigned __int64 v2; // rdi
char **v3; // rcx
char *v4; // rdx
__int64 result; // rax

*a1 = 0LL;
v1 = a1;
v2 = (unsigned __int64)(a1 + 1);
*(_QWORD *)(v2 + 244) = 0LL;
memset((void *)(v2 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)v1 - (v2 & 0xFFFFFFF8) + 260) >> 3));
v3 = &mis;
do
{
v4 = *v3;
for ( result = **v3; (_BYTE)result; ++v4 )
{
if ( (_BYTE)result != 32 )
*((_BYTE *)v1 + result - 97) = 1;
result = v4[1];
}
++v3;
v1 = (_QWORD *)((char *)v1 + 26);
}
while ( v3 != &mis + 10 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
_QWORD *v1; // rsi
unsigned __int64 v2; // rdi
char **v3; // rcx
char *v4; // rdx
__int64 result; // rax

*a1 = 0LL;
v1 = a1;
v2 = (unsigned __int64)(a1 + 1);
*(_QWORD *)(v2 + 244) = 0LL;
memset((void *)(v2 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)v1 - (v2 & 0xFFFFFFF8) + 260) >> 3));
v3 = &mis;
do
{
v4 = *v3;
for ( result = **v3; (_BYTE)result; ++v4 )
{
if ( (_BYTE)result != 32 )
*((_BYTE *)v1 + result - 97) = 1;
result = v4[1];
}
++v3;
v1 = (_QWORD *)((char *)v1 + 26);
}
while ( v3 != &mis + 10 );
return result;
}

original_code:
void init_mask(char *p)
{
 int i;
 char *pname;
 memset(p, 0, 26*10);
 for(i=0; i<10; i++){
  pname = mis[i];
  while(*pname!='\0'){
   if(*pname!=' ')
    *(p+(*pname - 'a')) = 1;
   pname++;
  }
  p = p + 26;
 }
}

variable_types:
pname
char *


original_code:
int main(void)
{
 int i;
    char mr[32];
 char mask[10][26];
 int index;
 char *p;
 int rap[10];
 int max;
 init_mask((char *)mask);
    scanf("%[^\n]", mr);
 memset(rap, 0, sizeof(rap));
 p = mr;
 while(*p!='\0'){
  if(*p!=' '){
   index = *p - 'a';
   for(i=0; i<10; i++){
    rap[i] = rap[i] + mask[i][index];
    mask[i][index] = 0;
   }
  }
  p++;
 }
 max = 0;
 index = 0;
 for(i=0; i<10; i++){
  if(rap[i]>max){
   max = rap[i];
   index = i;
  }
 }
 printf("%s\n", mis[index]);
    return 0;
}

canonical_original_code:
int main()
{
 int i;
    char mr[32];
 char mask[10][26];
 int index;
 char *p;
 int rap[10];
 int max;
 init_mask((char *)mask);
    scanf("%[^\n]", mr);
 memset(rap, 0, sizeof(rap));
 p = mr;
 while(*p!='\0'){
  if(*p!=' '){
   index = *p - 'a';
   for(i=0; i<10; i++){
    rap[i] = rap[i] + mask[i][index];
    mask[i][index] = 0;
   }
  }
  p++;
 }
 max = 0;
 index = 0;
 for(i=0; i<10; i++){
  if(rap[i]>max){
   max = rap[i];
   index = i;
  }
 }
 printf("%s\n", mis[index]);
    return 0;
}

variable_types:
mr
char [32]

variable_types:
mask
char [10][26]

variable_types: index int

variable_types:
rap
int [10]

variable_types: max int


inside

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

while ( 1 )
{
v1 = a1 / 10;
if ( a1 % 10 == 7 )
break;
a1 /= 10;
if ( !v1 )
return 0LL;
}
return 1LL;
}

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

while ( 1 )
{
v1 = a1 / 10;
if ( a1 % 10 == 7 )
break;
a1 /= 10;
if ( !v1 )
return 0LL;
}
return 1LL;
}

original_code:
int inside(int num)
{
    do{
        if( num%10 == 7 ) return 1;
        else num = num / 10;
    }while(num!=0);
    return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er8
__int64 v4; // rsi
int v5; // ecx
int v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_scanf(&unk_38, v7, envp);
v3 = v7[0];
v4 = 0LL;
if ( v7[0] > 6 )
{
v5 = 7;
do
{
while ( (unsigned int)(-1227133513 * v5) <= 0x24924924 || (unsigned int)inside(v5) == 1 )
{
++v5;
v4 = (unsigned int)(v4 + 1);
if ( v5 > v3 )
goto LABEL_7;
}
++v5;
}
while ( v5 <= v3 );
}
LABEL_7:
printf("%d\n", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er8
__int64 v4; // rsi
int v5; // ecx
int v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_scanf(&unk_38, v7, envp);
v3 = v7[0];
v4 = 0LL;
if ( v7[0] > 6 )
{
v5 = 7;
do
{
while ( (unsigned int)(-1227133513 * v5) <= 0x24924924 || (unsigned int)func0(v5) == 1 )
{
++v5;
v4 = (unsigned int)(v4 + 1);
if ( v5 > v3 )
goto LABEL_7;
}
++v5;
}
while ( v5 <= v3 );
}
LABEL_7:
printf("%d\n", v4);
return 0;
}

original_code:
int main(void)
{
    int limit;
    int i;
    int count = 0;
    scanf("%d", &limit);
    for(i=7; i<=limit; i++){
        if( ((i%7)==0) || (inside(i)==1) ){
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}

canonical_original_code:
int main()
{
    int limit;
    int i;
    int count = 0;
    scanf("%d", &limit);
    for(i=7; i<=limit; i++){
        if( ((i%7)==0) || (inside(i)==1) ){
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}

variable_types: limit int


search

original_code:
int search(int *p, int len, int target)
{
    int low = -1;
    int high = len;
    int probe;
    while(high-low > 1){
        probe = (low + high)>>1;
        if(*(p+probe)>target){
            high = probe;
        }else{
            low = probe;
        }
    }
    if((low==-1)||(*(p+low)!=target))
        return -1;
    else
        return low;
}

variable_types: len int

variable_types: target int

variable_types: low int

variable_types: high int

variable_types: probe int


main

original_code:
int main(void)
{
    int i;
    int count;
    int *p, *pboy, *pgirl;
    int *_p, *_pboy, *_pgirl;
    int position_b, _count;
 int *pos_b, *pos_g, *_pos_b;
 int result;
 while(1){
     scanf("%d", &count);
     if(count<=0) break;
     count = count*2;
     p = (int *)malloc(sizeof(int)*count);
     pboy = (int *)malloc(sizeof(int)*count);
     pgirl = (int *)malloc(sizeof(int)*count);
  pos_b = (int *)malloc(sizeof(int)*count);
     _p = p;
     _pboy = pboy;
     _pgirl = pgirl;
  _pos_b = pos_b;
     i = 0;
     while(i<count){
         scanf("%d", p+i);
         i++;
     }
     *pboy++ = *p;
     pgirl = pgirl+count-1;
     *pgirl-- = *(p+count-1);
     for(i=1; i<count; i++){
         *pboy = *(pboy-1) + *(p+i);
         *pgirl = *(pgirl+1) + *(p+count-1-i);
         pboy++;
         pgirl--;
     }
  pos_g = _p;
  memset(pos_g, 0, count);
  memset(pos_b, 0, count);
  result = 1;
  *pos_g++ = 1;
  *pos_b++ = count;
     _count = count;
     count = count-1;
     for(i=1; i<_count; i++){
         position_b = search(_pboy, count, *(_pgirl+i));
         if(position_b!=-1){
    *pos_g++ = i+1;
    *pos_b++ = position_b+1;
    result++;
             count = position_b;
         }
     }
  pos_g = _p;
  pos_b = _pos_b;
  printf("共有%d种站法\n", result);
  for(i=0; i<result; i++){
   printf("第%d种站法:女方站位置%d,男方站位置%d\n", i+1, *pos_g++, *pos_b++);
  }
     free(_p);
     free(_pboy);
     free(_pgirl);
  free(_pos_b);
 }
    return 0;
}

canonical_original_code:
int main()
{
    int i;
    int count;
    int *p; int *pboy; int *pgirl;
    int *_p; int *_pboy; int *_pgirl;
    int position_b; int _count;
 int *pos_b; int *pos_g; int *_pos_b;
 int result;
 while(1){
     scanf("%d", &count);
     if(count<=0) break;
     count = count*2;
     p = (int *)malloc(sizeof(int)*count);
     pboy = (int *)malloc(sizeof(int)*count);
     pgirl = (int *)malloc(sizeof(int)*count);
  pos_b = (int *)malloc(sizeof(int)*count);
     _p = p;
     _pboy = pboy;
     _pgirl = pgirl;
  _pos_b = pos_b;
     i = 0;
     while(i<count){
         scanf("%d", p+i);
         i++;
     }
     *pboy++ = *p;
     pgirl = pgirl+count-1;
     *pgirl-- = *(p+count-1);
     for(i=1; i<count; i++){
         *pboy = *(pboy-1) + *(p+i);
         *pgirl = *(pgirl+1) + *(p+count-1-i);
         pboy++;
         pgirl--;
     }
  pos_g = _p;
  memset(pos_g, 0, count);
  memset(pos_b, 0, count);
  result = 1;
  *pos_g++ = 1;
  *pos_b++ = count;
     _count = count;
     count = count-1;
     for(i=1; i<_count; i++){
         position_b = search(_pboy, count, *(_pgirl+i));
         if(position_b!=-1){
    *pos_g++ = i+1;
    *pos_b++ = position_b+1;
    result++;
             count = position_b;
         }
     }
  pos_g = _p;
  pos_b = _pos_b;
  printf("共有%d种站法\n", result);
  for(i=0; i<result; i++){
   printf("第%d种站法:女方站位置%d,男方站位置%d\n", i+1, *pos_g++, *pos_b++);
  }
     free(_p);
     free(_pboy);
     free(_pgirl);
  free(_pos_b);
 }
    return 0;
}

variable_types: i int

variable_types: count int

variable_types:
pboy
int *

variable_types:
pgirl
int *

variable_types: result int


Parser

decompiled_code:
__int64 __fastcall Parser(_BYTE *a1)
{
_BYTE *v1; // rdx
int v2; // eax
int *v3; // rcx
int *v4; // rdi
int v5; // edx
__int64 result; // rax
int *v7; // rcx
int *v8; // rdi
int v9; // esi
int v10[32]; // [rsp+0h] [rbp-100h] BYREF
int v11[32]; // [rsp+80h] [rbp-80h] BYREF

v1 = a1;
memset(v10, 0, 0x78uLL);
memset(v11, 0, 0x78uLL);
v2 = (char)*a1;
if ( !*a1 )
{
v5 = 0;
result = 0LL;
goto LABEL_7;
}
v3 = v11;
v4 = v10;
do
{
while ( (char)v2 <= 47 )
{
++v1;
*v3 = v2;
++v4;
++v3;
v2 = (char)*v1;
if ( !*v1 )
goto LABEL_6;
}
++v1;
*v4 = (char)(v2 - 48) + 10 * *v4;
v2 = (char)*v1;
}
while ( *v1 );
LABEL_6:
v5 = v11[0];
result = (unsigned int)v10[0];
if ( v11[0] != 48 )
{
LABEL_7:
v7 = &v10[2];
v8 = v11;
do
{
if ( v5 == 45 )
{
result = (unsigned int)(result - *(v7 - 1));
}
else if ( v5 > 45 )
{
if ( v5 != 47 )
return result;
v9 = *(v7 - 1);
if ( !v9 )
return result;
result = (unsigned int)((int)result / v9);
}
else if ( v5 == 42 )
{
result = (unsigned int)(*(v7 - 1) * result);
}
else
{
if ( v5 != 43 )
return result;
result = (unsigned int)(*(v7 - 1) + result);
}
v5 = v8[1];
++v8;
++v7;
}
while ( v5 != 48 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
_BYTE *v1; // rdx
int v2; // eax
int *v3; // rcx
int *v4; // rdi
int v5; // edx
__int64 result; // rax
int *v7; // rcx
int *v8; // rdi
int v9; // esi
int v10[32]; // [rsp+0h] [rbp-100h] BYREF
int v11[32]; // [rsp+80h] [rbp-80h] BYREF

v1 = a1;
memset(v10, 0, 0x78uLL);
memset(v11, 0, 0x78uLL);
v2 = (char)*a1;
if ( !*a1 )
{
v5 = 0;
result = 0LL;
goto LABEL_7;
}
v3 = v11;
v4 = v10;
do
{
while ( (char)v2 <= 47 )
{
++v1;
*v3 = v2;
++v4;
++v3;
v2 = (char)*v1;
if ( !*v1 )
goto LABEL_6;
}
++v1;
*v4 = (char)(v2 - 48) + 10 * *v4;
v2 = (char)*v1;
}
while ( *v1 );
LABEL_6:
v5 = v11[0];
result = (unsigned int)v10[0];
if ( v11[0] != 48 )
{
LABEL_7:
v7 = &v10[2];
v8 = v11;
do
{
if ( v5 == 45 )
{
result = (unsigned int)(result - *(v7 - 1));
}
else if ( v5 > 45 )
{
if ( v5 != 47 )
return result;
v9 = *(v7 - 1);
if ( !v9 )
return result;
result = (unsigned int)((int)result / v9);
}
else if ( v5 == 42 )
{
result = (unsigned int)(*(v7 - 1) * result);
}
else
{
if ( v5 != 43 )
return result;
result = (unsigned int)(*(v7 - 1) + result);
}
v5 = v8[1];
++v8;
++v7;
}
while ( v5 != 48 );
}
return result;
}

original_code:
int Parser(const char *pstr)
{
 int num[30];
 int op[30];
 int sum;
 int *p_num;
 int *p_op;
 memset(num, 0, sizeof(num));
 memset(op, 0, sizeof(op));
 p_num = num;
 p_op = op;
 while(*pstr!='\0'){
  if(*pstr<'0'){
   *p_op = *pstr;
   p_op++;
   p_num++;
  }else{
   *p_num = (*p_num * 10) + (*pstr - '0');
  }
  pstr++;
 }
 p_num = num;
 p_op = op;
 sum = *p_num++;
 while(*p_op != '0'){
  switch(*p_op){
   case '+':
    sum = sum + (*p_num++);
    break;
   case '-':
    sum = sum - (*p_num++);
    break;
   case '*':
    sum = sum * (*p_num++);
    break;
   case '/':
    if(*p_num!=0){
     sum = sum / (*p_num++);
    }else{
     goto _return;
    }
    break;
   default:
    goto _return;
    break;
  }
  p_op++;
 }
_return:
 return sum;
}

canonical_original_code:
int Parser(char *pstr)
{
 int num[30];
 int op[30];
 int sum;
 int *p_num;
 int *p_op;
 memset(num, 0, sizeof(num));
 memset(op, 0, sizeof(op));
 p_num = num;
 p_op = op;
 while(*pstr!='\0'){
  if(*pstr<'0'){
   *p_op = *pstr;
   p_op++;
   p_num++;
  }else{
   *p_num = (*p_num * 10) + (*pstr - '0');
  }
  pstr++;
 }
 p_num = num;
 p_op = op;
 sum = *p_num++;
 while(*p_op != '0'){
  switch(*p_op){
   case '+':
    sum = sum + (*p_num++);
    break;
   case '-':
    sum = sum - (*p_num++);
    break;
   case '*':
    sum = sum * (*p_num++);
    break;
   case '/':
    if(*p_num!=0){
     sum = sum / (*p_num++);
    }else{
     goto _return;
    }
    break;
   default:
    goto _return;
    break;
  }
  p_op++;
 }
_return:
 return sum;
}

variable_types:
pstr
char *

variable_types:
num
int [30]

variable_types:
op
int [30]

variable_types: sum int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
_BYTE savedregs[264]; // [rsp+0h] [rbp+0h] BYREF

memset(savedregs, 0, 0x100uLL);
_isoc99_scanf(&unk_F0, savedregs, envp);
v3 = Parser(savedregs);
printf("%d", v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
_BYTE savedregs[264]; // [rsp+0h] [rbp+0h] BYREF

memset(savedregs, 0, 0x100uLL);
_isoc99_scanf(&unk_F0, savedregs, envp);
v3 = func0(savedregs);
printf("%d", v3);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char str[256];
 int res;
 memset(str, 0, sizeof(str));
 scanf("%s", str);
 res = Parser(str);
 printf("%d", res);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
str
char [256]

variable_types: res int


decompiled_code:
int __fastcall set_ticker(int a1)
{
struct itimerval v2; // [rsp+0h] [rbp-28h] BYREF

v2.it_interval.tv_sec = a1 / 1000;
v2.it_interval.tv_usec = 1000LL * (a1 % 1000);
v2.it_value = v2.it_interval;
return setitimer(ITIMER_REAL, &v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
struct itimerval v2; // [rsp+0h] [rbp-28h] BYREF

v2.it_interval.tv_sec = a1 / 1000;
v2.it_interval.tv_usec = 1000LL * (a1 % 1000);
v2.it_value = v2.it_interval;
return setitimer(ITIMER_REAL, &v2, 0LL);
}

original_code:
int set_ticker(int n_msecs)
{
 struct itimerval timer;
 long n_sec, n_usec;
 n_sec = n_msecs / 1000;
 n_usec = (n_msecs % 1000)*1000L;
 timer.it_interval.tv_sec = n_sec;
 timer.it_interval.tv_usec = n_usec;
 timer.it_value.tv_sec = n_sec;
 timer.it_value.tv_usec = n_usec;
 return setitimer(ITIMER_REAL, &timer, ((void *)0));
}

canonical_original_code:
int set_ticker(int n_msecs)
{
 struct itimerval timer;
 long n_sec; long n_usec;
 n_sec = n_msecs / 1000;
 n_usec = (n_msecs % 1000)*1000L;
 timer.it_interval.tv_sec = n_sec;
 timer.it_interval.tv_usec = n_usec;
 timer.it_value.tv_sec = n_sec;
 timer.it_value.tv_usec = n_usec;
 return setitimer(ITIMER_REAL, &timer, ((void *)0));
}

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


isValidPassword

decompiled_code:
__int64 __fastcall isValidPassword(const char *a1)
{
const char *v1; // rbx
__int64 v2; // rax
int v3; // ecx
__int64 *v4; // rax
int v5; // edx

v1 = a1;
if ( (unsigned int)strlen(a1) - 8 > 0xC )
return 0xFFFFFFFFLL;
count = 0LL;
*(&count + 1) = 0LL;
*((_DWORD *)&count + 4) = 0;
v2 = *a1;
if ( (_BYTE)v2 )
{
do
{
++v1;
*((_DWORD *)&count + mask[v2]) = 1;
v2 = *v1;
}
while ( (_BYTE)v2 );
if ( (int)count <= 0 )
{
v3 = HIDWORD(count);
goto LABEL_6;
}
return 0xFFFFFFFFLL;
}
v3 = 0;
LABEL_6:
v4 = &count;
v5 = 0;
while ( 1 )
{
v4 = (__int64 *)((char *)v4 + 4);
v5 += v3 > 0;
if ( v4 == &count + 2 )
break;
v3 = *((_DWORD *)v4 + 1);
}
return (unsigned int)-(v5 <= 2);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
const char *v1; // rbx
__int64 v2; // rax
int v3; // ecx
__int64 *v4; // rax
int v5; // edx

v1 = a1;
if ( (unsigned int)strlen(a1) - 8 > 0xC )
return 0xFFFFFFFFLL;
count = 0LL;
*(&count + 1) = 0LL;
*((_DWORD *)&count + 4) = 0;
v2 = *a1;
if ( (_BYTE)v2 )
{
do
{
++v1;
*((_DWORD *)&count + mask[v2]) = 1;
v2 = *v1;
}
while ( (_BYTE)v2 );
if ( (int)count <= 0 )
{
v3 = HIDWORD(count);
goto LABEL_6;
}
return 0xFFFFFFFFLL;
}
v3 = 0;
LABEL_6:
v4 = &count;
v5 = 0;
while ( 1 )
{
v4 = (__int64 *)((char *)v4 + 4);
v5 += v3 > 0;
if ( v4 == &count + 2 )
break;
v3 = *((_DWORD *)v4 + 1);
}
return (unsigned int)-(v5 <= 2);
}

original_code:
int isValidPassword(char *p)
{
 int i, len, typeCount;
 len = strlen(p);
 if( len<8||len>20 ) return -1;
 _count[0] = 0;
 _count[1] = 0;
 _count[2] = 0;
 _count[3] = 0;
 _count[4] = 0;
 while(*p!='\0'){
  i = (int)*p;
  _count[_mask[i]] = 1;
  p++;
 }
 if(_count[0]>0) return -1;
 typeCount = 0;
 for(i=1; i<5; i++){
  if(_count[i]>0) typeCount++;
 }
 if(typeCount<3) return -1;
 return 0;
}

canonical_original_code:
int isValidPassword(char *p)
{
 int i; int len; int typeCount;
 len = strlen(p);
 if( len<8||len>20 ) return -1;
 _count[0] = 0;
 _count[1] = 0;
 _count[2] = 0;
 _count[3] = 0;
 _count[4] = 0;
 while(*p!='\0'){
  i = (int)*p;
  _count[_mask[i]] = 1;
  p++;
 }
 if(_count[0]>0) return -1;
 typeCount = 0;
 for(i=1; i<5; i++){
  if(_count[i]>0) typeCount++;
 }
 if(typeCount<3) return -1;
 return 0;
}

variable_types:
p
char *

variable_types: len int

variable_types: typeCount int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rdx
char v6[1016]; // [rsp+0h] [rbp-3F8h] BYREF

while ( 1 )
{
v3 = gets(v6, argv, envp);
if ( !v3 )
break;
while ( !(unsigned int)isValidPassword(v6) )
{
puts("true");
v3 = gets(v6, argv, v4);
if ( !v3 )
return v3;
}
puts("false");
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rdx
char v6[1016]; // [rsp+0h] [rbp-3F8h] BYREF

while ( 1 )
{
v3 = gets(v6, argv, envp);
if ( !v3 )
break;
while ( !(unsigned int)func0(v6) )
{
puts("true");
v3 = gets(v6, argv, v4);
if ( !v3 )
return v3;
}
puts("false");
}
return v3;
}

original_code:
int main(void)
{
 char str[1000];
 int ret;
 while(gets(str)){
  ret = isValidPassword(str);
  if(ret==0) printf("true\n");
  else printf("false\n");
 }
    return 0;
}

canonical_original_code:
int main()
{
 char str[1000];
 int ret;
 while(gets(str)){
  ret = isValidPassword(str);
  if(ret==0) printf("true\n");
  else printf("false\n");
 }
    return 0;
}

variable_types:
str
char [1000]

variable_types: ret int


repo: shmmy/OS

decompiled_code:
void __noreturn sigint_handler()
{
reset_xterm_color(1LL);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
reset_xterm_color(1LL);
exit(1);
}

original_code:
static void
sigint_handler(int signum)
{
    reset_xterm_color(1);
    exit(1);
}

variable_types: signum int


original_code:
static void
install_signal_handler(void)
{
    sigset_t sigset;
    struct sigaction sa;
    sa.__sigaction_handler.sa_handler = sigint_handler;
    sa.sa_flags = 0x10000000 ;
    sigemptyset(&sigset);
    sigaddset(&sigset, 2);
    sa.sa_mask = sigset;
    if (sigaction(2, &sa, ((void *)0)) < 0) {
        perror("sigaction: sigint");
        exit(1);
    }
}

canonical_original_code:
static void install_signal_handler()
{
    struct __sigset_t sigset;
    struct sigaction sa;
    sa.__sigaction_handler.sa_handler = sigint_handler;
    sa.sa_flags = 0x10000000 ;
    sigemptyset(&sigset);
    sigaddset(&sigset, 2);
    sa.sa_mask = sigset;
    if (sigaction(2, &sa, ((void *)0)) < 0) {
        perror("sigaction: sigint");
        exit(1);
    }
}

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

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

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


decompiled_code:
void __fastcall compute_mandel_line(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
int v4; // eax
unsigned __int8 v5; // al
double v6; // xmm2_8

v2 = *(double *)&xmin;
if ( *(double *)&xmax >= *(double *)&xmin )
{
do
{
v4 = mandel_iterations_at_point(100000LL);
if ( v4 > 255 )
v4 = 255;
a2 += 4LL;
v5 = xterm_color((unsigned int)v4);
v2 = v2 + *(double *)&xstep;
v6 = *(double *)&xmax;
*(_DWORD *)(a2 - 4) = v5;
}
while ( v6 >= v2 );
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
int v4; // eax
unsigned __int8 v5; // al
double v6; // xmm2_8

v2 = *(double *)&xmin;
if ( *(double *)&xmax >= *(double *)&xmin )
{
do
{
v4 = mandel_iterations_at_point(100000LL);
if ( v4 > 255 )
v4 = 255;
a2 += 4LL;
v5 = xterm_color((unsigned int)v4);
v2 = v2 + *(double *)&xstep;
v6 = *(double *)&xmax;
*(_DWORD *)(a2 - 4) = v5;
}
while ( v6 >= v2 );
}
}

original_code:
void compute_mandel_line(int line, int color_val[])
{
    double x, y;
    int n;
    int val;
    y = ymax - ystep * line;
    for (x = xmin, n = 0; x <= xmax; x+= xstep, n++) {
        val = mandel_iterations_at_point(x, y, 100000);
        if (val > 255)
            val = 255;
        val = xterm_color(val);
        color_val[n] = val;
    }
}

canonical_original_code:
void compute_mandel_line(int line, int color_val[])
{
    double x; double y;
    int n;
    int val;
    y = ymax - ystep * line;
    for (x = xmin, n = 0; x <= xmax; x+= xstep, n++) {
        val = mandel_iterations_at_point(x, y, 100000);
        if (val > 255)
            val = 255;
        val = xterm_color(val);
        color_val[n] = val;
    }
}

variable_types: line int

variable_types: x double

variable_types: y double

variable_types: n int

variable_types: val int


decompiled_code:
ssize_t __fastcall output_mandel_line(int fd, __int64 a2)
{
__int64 v2; // rbx
ssize_t result; // rax
char buf; // [rsp+Eh] [rbp-1Ah] BYREF
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

buf = 64;
v5[0] = 10;
if ( x_chars > 0 )
{
v2 = 0LL;
do
{
set_xterm_color((unsigned int)fd, *(unsigned __int8 *)(a2 + 4 * v2));
if ( write(fd, &buf, 1uLL) != 1 )
{
perror("compute_and_output_mandel_line: write point");
exit(1);
}
++v2;
}
while ( x_chars > (int)v2 );
}
result = write(fd, v5, 1uLL);
if ( result != 1 )
{
perror("compute_and_output_mandel_line: write newline");
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(int fd, __int64 a2)
{
__int64 v2; // rbx
ssize_t result; // rax
char buf; // [rsp+Eh] [rbp-1Ah] BYREF
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

buf = 64;
v5[0] = 10;
if ( x_chars > 0 )
{
v2 = 0LL;
do
{
set_xterm_color((unsigned int)fd, *(unsigned __int8 *)(a2 + 4 * v2));
if ( write(fd, &buf, 1uLL) != 1 )
{
perror("compute_and_output_mandel_line: write point");
exit(1);
}
++v2;
}
while ( x_chars > (int)v2 );
}
result = write(fd, v5, 1uLL);
if ( result != 1 )
{
perror("compute_and_output_mandel_line: write newline");
exit(1);
}
return result;
}

original_code:
void output_mandel_line(int fd, int color_val[])
{
    int i;
    char point ='@';
    char newline='\n';
    for (i = 0; i < x_chars; i++) {
        set_xterm_color(fd, color_val[i]);
        if (write(fd, &point, 1) != 1) {
            perror("compute_and_output_mandel_line: write point");
            exit(1);
        }
    }
    if (write(fd, &newline, 1) != 1) {
        perror("compute_and_output_mandel_line: write newline");
        exit(1);
    }
}

canonical_original_code:
void output_mandel_line(int fd, int color_val[])
{
    int i;
    char point = '@';
    char newline = '\n';
    for (i = 0; i < x_chars; i++) {
        set_xterm_color(fd, color_val[i]);
        if (write(fd, &point, 1) != 1) {
            perror("compute_and_output_mandel_line: write point");
            exit(1);
        }
    }
    if (write(fd, &newline, 1) != 1) {
        perror("compute_and_output_mandel_line: write newline");
        exit(1);
    }
}

variable_types: fd int

variable_types: i int

variable_types: point char

variable_types: newline char


decompiled_code:
ssize_t __fastcall compute_and_output_mandel_line(int fd, unsigned int a2)
{
void *v2; // rsp
_BYTE v4[16]; // [rsp+0h] [rbp-10h] BYREF

v2 = alloca(4LL * x_chars);
compute_mandel_line(a2, (__int64)v4);
return output_mandel_line(fd, (__int64)v4);
}

canonical_decompiled_code:
ssize_t __fastcall func4(int fd, unsigned int a2)
{
void *v2; // rsp
_BYTE v4[16]; // [rsp+0h] [rbp-10h] BYREF

v2 = alloca(4LL * x_chars);
func2(a2, (__int64)v4);
return func3(fd, (__int64)v4);
}

original_code:
void compute_and_output_mandel_line(int fd, int line)
{
    int color_val[x_chars];
    compute_mandel_line(line, color_val);
    output_mandel_line(fd, color_val);
}

canonical_original_code:
void compute_and_output_mandel_line(int fd, int line)
{
    int color_val[-1];
    compute_mandel_line(line, color_val);
    output_mandel_line(fd, color_val);
}


child

decompiled_code:
__int64 __fastcall child(int a1, __int64 a2, __int64 a3)
{
void *v3; // rsp
int v4; // ebx
__int64 v6; // rdi
_BYTE v8[32]; // [rsp+0h] [rbp-20h] BYREF

v3 = alloca(4LL * x_chars);
if ( a1 < y_chars )
{
v4 = a1;
do
{
v6 = (unsigned int)v4;
v4 += 30;
compute_mandel_line(v6, (__int64)v8);
pipesem_wait(a2);
output_mandel_line(1, (__int64)v8);
pipesem_signal(a3);
}
while ( y_chars > v4 );
}
return pipesem_destroy(a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, __int64 a2, __int64 a3)
{
void *v3; // rsp
int v4; // ebx
__int64 v6; // rdi
_BYTE v8[32]; // [rsp+0h] [rbp-20h] BYREF

v3 = alloca(4LL * x_chars);
if ( a1 < y_chars )
{
v4 = a1;
do
{
v6 = (unsigned int)v4;
v4 += 30;
func2(v6, (__int64)v8);
pipesem_wait(a2);
func3(1, (__int64)v8);
pipesem_signal(a3);
}
while ( y_chars > v4 );
}
return pipesem_destroy(a2);
}

original_code:
void child(int ch_id,struct pipesem *mysem,struct pipesem *othersem)
{
    int line;
    int color_val[x_chars];
    for (line = ch_id; line < y_chars; line+=30) {
        compute_mandel_line(line, color_val);
        pipesem_wait(mysem);
        output_mandel_line(1, color_val);
        pipesem_signal(othersem);
    }
    pipesem_destroy(mysem);
}

canonical_original_code:
void child(int ch_id, struct pipesem *mysem, struct pipesem *othersem)
{
    int line;
    int color_val[-1];
    for (line = ch_id; line < y_chars; line+=30) {
        compute_mandel_line(line, color_val);
        pipesem_wait(mysem);
        output_mandel_line(1, color_val);
        pipesem_signal(othersem);
    }
    pipesem_destroy(mysem);
}

variable_types:
mysem
struct pipesem { int rfd; int wfd; } *

variable_types:
othersem
struct pipesem *