OpPrintOpcode

decompiled_code:
int __fastcall OpPrintOpcode(unsigned __int16 a1)
{
__int16 v1; // ax
unsigned __int16 v2; // ax
int result; // eax
__int16 v4; // ax
__int16 v5; // ax
__int64 v6; // rsi
__int16 v7; // ax

if ( (a1 & 0xC000) != 0 )
return printf("Invalid high bits in opcode");
v1 = a1 & 0x3000;
if ( (a1 & 0x3000) != 0 )
{
if ( v1 == 4096 )
{
v7 = a1 & 0x3C00;
if ( (a1 & 0x3C00) == 6144 )
{
result = printf("BTFSC %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 7);
}
else
{
if ( (a1 & 0x3C00u) > 0x1800 )
{
if ( v7 == 7168 )
return printf("BTFSS %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 7);
}
else
{
if ( v7 == 4096 )
return printf("BCF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 7);
if ( v7 == 5120 )
return printf("BSF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 7);
}
result = printf("Invalid 01 opcode!");
}
}
else if ( v1 == 0x2000 )
{
v6 = a1 & 0x7FF;
if ( (a1 & 0x800) != 0 )
result = printf("GOTO %d", v6);
else
result = printf("CALL %d", v6);
}
else if ( (a1 & 0xE00) == 3584 )
{
result = printf("ADDLW %d", (unsigned __int8)a1);
}
else
{
v4 = a1 & 0xF00;
if ( (a1 & 0xF00) == 2304 )
{
result = printf("ANDLW %d", (unsigned __int8)a1);
}
else if ( v4 == 2048 )
{
result = printf("IORLW %d", (unsigned __int8)a1);
}
else if ( v4 == 2560 )
{
result = printf("XORLW %d", (unsigned __int8)a1);
}
else
{
v5 = a1 & 0xC00;
if ( (a1 & 0xC00) != 0 )
{
if ( v5 == 1024 )
{
result = printf("RETLW %d", (unsigned __int8)a1);
}
else if ( v5 == 3072 )
{
result = printf("SUBLW %d", (unsigned __int8)a1);
}
else
{
result = printf("Invalid 11 opcode!");
}
}
else
{
result = printf("MOVLW %d", (unsigned __int8)a1);
}
}
}
}
else
{
v2 = a1 & 0xF00;
if ( (a1 & 0xF00) == 2048 )
return printf("MOVF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
if ( (a1 & 0xF00u) > 0x800 )
{
if ( v2 == 3072 )
return printf("RRF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
if ( v2 <= 0xC00u )
{
switch ( v2 )
{
case 0xA00u:
return printf("INCF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
case 0xB00u:
return printf("DECFSZ %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
case 0x900u:
return printf("COMF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
}
}
else
{
switch ( v2 )
{
case 0xE00u:
return printf("SWAPF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
case 0xF00u:
return printf("INCFSZ %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
case 0xD00u:
return printf("RLF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
}
}
return printf("Invalid 00 opcode!");
}
if ( v2 == 1024 )
return printf("IORWF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
if ( v2 > 0x400u )
{
switch ( v2 )
{
case 0x600u:
return printf("XORWF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
case 0x700u:
return printf("ADDWF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
case 0x500u:
return printf("ANDWF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
}
return printf("Invalid 00 opcode!");
}
if ( v2 == 512 )
return printf("SUBWF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
if ( v2 > 0x200u )
{
if ( v2 == 768 )
return printf("DECF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
return printf("Invalid 00 opcode!");
}
if ( !v2 )
{
if ( (a1 & 0x80u) != 0 )
return printf("MOVWF %d", a1 & 0x7F);
if ( (a1 & 0xF) == 0 )
return printf("NOP");
if ( (unsigned __int8)a1 == 99 )
return printf("SLEEP");
if ( (unsigned __int8)a1 > 0x63u )
{
if ( (unsigned __int8)a1 == 100 )
return printf("CLRWDT");
}
else
{
if ( (unsigned __int8)a1 == 8 )
return printf("RETURN");
if ( (unsigned __int8)a1 == 9 )
return printf("RETFIE");
}
return printf("Invalid 00 0000 opcode!");
}
if ( v2 != 256 )
return printf("Invalid 00 opcode!");
if ( (a1 & 0x80u) == 0 )
result = printf("CLRW");
else
result = printf("CLRF %d", a1 & 0x7F);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int16 a1)
{
__int16 v1; // ax
unsigned __int16 v2; // ax
int result; // eax
__int16 v4; // ax
__int16 v5; // ax
__int64 v6; // rsi
__int16 v7; // ax

if ( (a1 & 0xC000) != 0 )
return printf("Invalid high bits in opcode");
v1 = a1 & 0x3000;
if ( (a1 & 0x3000) != 0 )
{
if ( v1 == 4096 )
{
v7 = a1 & 0x3C00;
if ( (a1 & 0x3C00) == 6144 )
{
result = printf("BTFSC %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 7);
}
else
{
if ( (a1 & 0x3C00u) > 0x1800 )
{
if ( v7 == 7168 )
return printf("BTFSS %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 7);
}
else
{
if ( v7 == 4096 )
return printf("BCF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 7);
if ( v7 == 5120 )
return printf("BSF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 7);
}
result = printf("Invalid 01 opcode!");
}
}
else if ( v1 == 0x2000 )
{
v6 = a1 & 0x7FF;
if ( (a1 & 0x800) != 0 )
result = printf("GOTO %d", v6);
else
result = printf("CALL %d", v6);
}
else if ( (a1 & 0xE00) == 3584 )
{
result = printf("ADDLW %d", (unsigned __int8)a1);
}
else
{
v4 = a1 & 0xF00;
if ( (a1 & 0xF00) == 2304 )
{
result = printf("ANDLW %d", (unsigned __int8)a1);
}
else if ( v4 == 2048 )
{
result = printf("IORLW %d", (unsigned __int8)a1);
}
else if ( v4 == 2560 )
{
result = printf("XORLW %d", (unsigned __int8)a1);
}
else
{
v5 = a1 & 0xC00;
if ( (a1 & 0xC00) != 0 )
{
if ( v5 == 1024 )
{
result = printf("RETLW %d", (unsigned __int8)a1);
}
else if ( v5 == 3072 )
{
result = printf("SUBLW %d", (unsigned __int8)a1);
}
else
{
result = printf("Invalid 11 opcode!");
}
}
else
{
result = printf("MOVLW %d", (unsigned __int8)a1);
}
}
}
}
else
{
v2 = a1 & 0xF00;
if ( (a1 & 0xF00) == 2048 )
return printf("MOVF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
if ( (a1 & 0xF00u) > 0x800 )
{
if ( v2 == 3072 )
return printf("RRF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
if ( v2 <= 0xC00u )
{
switch ( v2 )
{
case 0xA00u:
return printf("INCF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
case 0xB00u:
return printf("DECFSZ %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
case 0x900u:
return printf("COMF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
}
}
else
{
switch ( v2 )
{
case 0xE00u:
return printf("SWAPF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
case 0xF00u:
return printf("INCFSZ %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
case 0xD00u:
return printf("RLF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
}
}
return printf("Invalid 00 opcode!");
}
if ( v2 == 1024 )
return printf("IORWF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
if ( v2 > 0x400u )
{
switch ( v2 )
{
case 0x600u:
return printf("XORWF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
case 0x700u:
return printf("ADDWF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
case 0x500u:
return printf("ANDWF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
}
return printf("Invalid 00 opcode!");
}
if ( v2 == 512 )
return printf("SUBWF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
if ( v2 > 0x200u )
{
if ( v2 == 768 )
return printf("DECF %d, %d", a1 & 0x7F, ((int)a1 >> 7) & 1);
return printf("Invalid 00 opcode!");
}
if ( !v2 )
{
if ( (a1 & 0x80u) != 0 )
return printf("MOVWF %d", a1 & 0x7F);
if ( (a1 & 0xF) == 0 )
return printf("NOP");
if ( (unsigned __int8)a1 == 99 )
return printf("SLEEP");
if ( (unsigned __int8)a1 > 0x63u )
{
if ( (unsigned __int8)a1 == 100 )
return printf("CLRWDT");
}
else
{
if ( (unsigned __int8)a1 == 8 )
return printf("RETURN");
if ( (unsigned __int8)a1 == 9 )
return printf("RETFIE");
}
return printf("Invalid 00 0000 opcode!");
}
if ( v2 != 256 )
return printf("Invalid 00 opcode!");
if ( (a1 & 0x80u) == 0 )
result = printf("CLRW");
else
result = printf("CLRF %d", a1 & 0x7F);
}
return result;
}

original_code:
void OpPrintOpcode(unsigned short opcode)
{
    if ((opcode & 0xC000) != 0)
    {
        printf("Invalid high bits in opcode");
        return;
    }
    if ((opcode & 0x3000) == 0x0000)
    {
        switch (opcode & 0xF00)
        {
            case 0x700:
                printf("ADDWF %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0x500:
                printf("ANDWF %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0x100:
                if ((opcode & 0x80) != 0)
                {
                    printf("CLRF %d", (opcode & 0x7F));
                }
                else
                {
                    printf("CLRW");
                }
                break;
            case 0x900:
                printf("COMF %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0x300:
                printf("DECF %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0xB00:
                printf("DECFSZ %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0xA00:
                printf("INCF %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0xF00:
                printf("INCFSZ %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0x400:
                printf("IORWF %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0x800:
                printf("MOVF %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0x000:
                if ((opcode & 0x80) != 0)
                {
                    printf("MOVWF %d", (opcode & 0x7F));
                }
                else if ((opcode & 0xF) == 0)
                {
                    printf("NOP");
                }
                else
                {
                    switch (opcode & 0xFF)
                    {
                        case 0x64:
                            printf("CLRWDT");
                            break;
                        case 0x09:
                            printf("RETFIE");
                            break;
                        case 0x08:
                            printf("RETURN");
                            break;
                        case 0x63:
                            printf("SLEEP");
                            break;
                        default:
                            printf("Invalid 00 0000 opcode!");
                            break;
                    }
                }
                break;
            case 0xD00:
                printf("RLF %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0xC00:
                printf("RRF %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0x200:
                printf("SUBWF %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0xE00:
                printf("SWAPF %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            case 0x600:
                printf("XORWF %d, %d", (opcode & 0x7F), (opcode & 0x80) >> 7);
                break;
            default:
                printf("Invalid 00 opcode!");
                break;
        }
    }
    else if ((opcode & 0x3000) == 0x1000)
    {
        switch (opcode & 0x3C00)
        {
            case 0x1000:
                printf("BCF %d, %d", (opcode & 0x7F), (opcode & 0x380) >> 7);
                break;
            case 0x1400:
                printf("BSF %d, %d", (opcode & 0x7F), (opcode & 0x380) >> 7);
                break;
            case 0x1800:
                printf("BTFSC %d, %d", (opcode & 0x7F), (opcode & 0x380) >> 7);
                break;
            case 0x1C00:
                printf("BTFSS %d, %d", (opcode & 0x7F), (opcode & 0x380) >> 7);
                break;
            default:
                printf("Invalid 01 opcode!");
                break;
        }
    }
    else if ((opcode & 0x3000) == 0x2000)
    {
        if ((opcode & 0x800) != 0)
        {
            printf("GOTO %d", (opcode & 0x7FF));
        }
        else
        {
            printf("CALL %d", (opcode & 0x7FF));
        }
    }
    else
    {
        if ((opcode & 0xE00) == 0xE00)
        {
            printf("ADDLW %d", (opcode & 0xFF));
        }
        else if ((opcode & 0xF00) == 0x900)
        {
            printf("ANDLW %d", (opcode & 0xFF));
        }
        else if ((opcode & 0xF00) == 0x800)
        {
            printf("IORLW %d", (opcode & 0xFF));
        }
        else if ((opcode & 0xF00) == 0xA00)
        {
            printf("XORLW %d", (opcode & 0xFF));
        }
        else if ((opcode & 0xC00) == 0x000)
        {
            printf("MOVLW %d", (opcode & 0xFF));
        }
        else if ((opcode & 0xC00) == 0x400)
        {
            printf("RETLW %d", (opcode & 0xFF));
        }
        else if ((opcode & 0xC00) == 0xC00)
        {
            printf("SUBLW %d", (opcode & 0xFF));
        }
        else
        {
            printf("Invalid 11 opcode!");
        }
    }
}


GetNextPrimeP

repo: cgutman/mersy

decompiled_code:
__int64 GetNextPrimeP()
{
__int64 v0; // r12

pthread_mutex_lock(&NextPMutex);
v0 = _gmpz_get_ui(&NextPrimeP);
_gmpz_nextprime(&NextPrimeP);
pthread_mutex_unlock(&NextPMutex);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // r12

pthread_mutex_lock(&NextPMutex);
v0 = _gmpz_get_ui(&NextPrimeP);
_gmpz_nextprime(&NextPrimeP);
pthread_mutex_unlock(&NextPMutex);
return v0;
}

original_code:
static unsigned long GetNextPrimeP(void)
{
 unsigned long nextP;
 pthread_mutex_lock(&NextPMutex);
 nextP = __gmpz_get_ui(NextPrimeP);
 __gmpz_nextprime(NextPrimeP, NextPrimeP);
 pthread_mutex_unlock(&NextPMutex);
 return nextP;
}

canonical_original_code:
static unsigned long GetNextPrimeP()
{
 unsigned long nextP;
 pthread_mutex_lock(&NextPMutex);
 nextP = __gmpz_get_ui(NextPrimeP);
 __gmpz_nextprime(NextPrimeP, NextPrimeP);
 pthread_mutex_unlock(&NextPMutex);
 return nextP;
}

variable_types:
nextP
unsigned long

return_type: unsigned long


PrimeTest

decompiled_code:
__int64 __fastcall PrimeTest(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
_DWORD v4[10]; // [rsp+0h] [rbp-28h] BYREF

_gmpz_init_set_ui(v4, 4LL);
if ( a1 != 2 )
{
v2 = 0LL;
do
{
++v2;
_gmpz_mul(v4, v4, v4);
_gmpz_sub_ui(v4, v4, 2LL);
_gmpz_mod(v4, v4, a2);
}
while ( v2 != a1 - 2 );
}
return 2 * (unsigned int)(v4[1] == 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
_DWORD v4[10]; // [rsp+0h] [rbp-28h] BYREF

_gmpz_init_set_ui(v4, 4LL);
if ( a1 != 2 )
{
v2 = 0LL;
do
{
++v2;
_gmpz_mul(v4, v4, v4);
_gmpz_sub_ui(v4, v4, 2LL);
_gmpz_mod(v4, v4, a2);
}
while ( v2 != a1 - 2 );
}
return 2 * (unsigned int)(v4[1] == 0);
}

original_code:
static int PrimeTest(unsigned long p, mpz_t *potentialPrime)
{
 mpz_t s;
 unsigned long i;
 __gmpz_init_set_ui(s, 4);
 for (i = 0; i < p - 2; i++)
 {
  __gmpz_mul(s, s, s);
  __gmpz_sub_ui(s, s, 2);
  __gmpz_mod(s, s, *potentialPrime);
 }
 return ((__builtin_constant_p (0) && (0) == 0 ? ((s)->_mp_size < 0 ? -1 : (s)->_mp_size > 0) : __gmpz_cmp_ui (s,0)) == 0) ? (2) : (0);
}

canonical_original_code:
static int PrimeTest(unsigned long p, struct __mpz_struct (*potentialPrime)[1])
{
 struct __mpz_struct s[1];
 unsigned long i;
 __gmpz_init_set_ui(s, 4);
 for (i = 0; i < p - 2; i++)
 {
  __gmpz_mul(s, s, s);
  __gmpz_sub_ui(s, s, 2);
  __gmpz_mod(s, s, *potentialPrime);
 }
 return ((__builtin_constant_p (0) && (0) == 0 ? ((s)->_mp_size < 0 ? -1 : (s)->_mp_size > 0) : __gmpz_cmp_ui (s,0)) == 0) ? (2) : (0);
}

variable_types:
p
unsigned long

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*)[1]

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
i
unsigned long

return_type: int


PrintMsgHeader

decompiled_code:
int __fastcall PrintMsgHeader(int a1)
{
struct tm *v1; // rax
int result; // eax
time_t timer; // [rsp+8h] [rbp-80h] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
strftime(s, 0x64uLL, "%m/%d/%Y %H:%M:%S", v1);
result = printf("%s ", s);
if ( a1 == 3 )
return printf("WARNING: ");
if ( a1 == 4 )
result = printf("ERROR: ");
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
struct tm *v1; // rax
int result; // eax
time_t timer; // [rsp+8h] [rbp-80h] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
strftime(s, 0x64uLL, "%m/%d/%Y %H:%M:%S", v1);
result = printf("%s ", s);
if ( a1 == 3 )
return printf("WARNING: ");
if ( a1 == 4 )
result = printf("ERROR: ");
return result;
}

original_code:
void PrintMsgHeader(int tag)
{
 char buff[100];
 time_t now;
 now = time(((void *)0));
 strftime(buff, 100, "%m/%d/%Y %H:%M:%S", localtime(&now));
 printf("%s ", buff);
 switch (tag)
 {
  case 3:
   printf("WARNING: ");
   break;
  case 4:
   printf("ERROR: ");
   break;
  default:
   break;
 }
}

canonical_original_code:
void PrintMsgHeader(int tag)
{
 char buff[100];
 long now;
 now = time(((void *)0));
 strftime(buff, 100, "%m/%d/%Y %H:%M:%S", localtime(&now));
 printf("%s ", buff);
 switch (tag)
 {
  case 3:
   printf("WARNING: ");
   break;
  case 4:
   printf("ERROR: ");
   break;
  default:
   break;
 }
}

variable_types: tag int

variable_types:
buff
char [100]

variable_types: now long

return_type: void


Usage

decompiled_code:
int Usage()
{
return puts("mersy [<starting P value>]");
}

canonical_decompiled_code:
int func1()
{
return puts("mersy [<starting P value>]");
}

original_code:
void Usage(void)
{
 printf("mersy [<starting P value>]\n");
}

canonical_original_code:
void Usage()
{
 printf("mersy [<starting P value>]\n");
}


GetOptimalThreadCount

decompiled_code:
__int64 GetOptimalThreadCount()
{
return sysconf(83);
}

canonical_decompiled_code:
__int64 func2()
{
return sysconf(83);
}

original_code:
int GetOptimalThreadCount(void)
{
 return sysconf(_SC_NPROCESSORS_CONF);
}

canonical_original_code:
int GetOptimalThreadCount()
{
 return sysconf(_SC_NPROCESSORS_CONF);
}


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax

if ( argc > 2 )
{
Usage();
}
else
{
v3 = 2;
if ( argc == 2 )
{
*(_QWORD *)&argc = argv[1];
v3 = atoi(*(const char **)&argc);
}
v4 = GetOptimalThreadCount(*(_QWORD *)&argc, argv, envp);
FindPrimes(v4, v3);
}
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax

if ( argc > 2 )
{
func1();
}
else
{
v3 = 2;
if ( argc == 2 )
{
*(_QWORD *)&argc = argv[1];
v3 = atoi(*(const char **)&argc);
}
v4 = func2(*(_QWORD *)&argc, argv, envp);
FindPrimes(v4, v3);
}
return -1;
}

original_code:
int main(int argc, char *argv[])
{
 int threadCount, startP;
 if (argc > 2)
 {
  Usage();
  return -1;
 }
 if (argc >= 2)
 {
  startP = atoi(argv[1]);
 }
 else
 {
  startP = 2;
 }
 threadCount = GetOptimalThreadCount();
 FindPrimes(threadCount, startP);
 return -1;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int threadCount; int startP;
 if (argc > 2)
 {
  Usage();
  return -1;
 }
 if (argc >= 2)
 {
  startP = atoi(argv[1]);
 }
 else
 {
  startP = 2;
 }
 threadCount = GetOptimalThreadCount();
 FindPrimes(threadCount, startP);
 return -1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: threadCount int

variable_types: startP int


information

decompiled_code:
int information()
{
return puts(aXxxIp);
}

canonical_decompiled_code:
int func2()
{
return puts(aXxxIp);
}

original_code:
void information()
{
 printf("./XXX IP地址 \n\t./client 192.168.100.1 (例子)\n");
}


decompiled_code:
int my_help()
{
printf("\n\tcommand:");
printf("\n\t\tls: ls");
printf("\n\t\tget: 1.get xxx.mp3 aaa.txt\n\t\t 2.get *.pdf *.doc");
printf("\n\t\tput: put /home/chang/xxx.txt");
printf("\n\t\tcd: 1.cd first\n\t\t 2.cd ..");
printf("\n\t\tquit:quit");
return puts("\n\t\thelp:help");
}

canonical_decompiled_code:
int func4()
{
printf("\n\tcommand:");
printf("\n\t\tls: ls");
printf("\n\t\tget: 1.get xxx.mp3 aaa.txt\n\t\t 2.get *.pdf *.doc");
printf("\n\t\tput: put /home/chang/xxx.txt");
printf("\n\t\tcd: 1.cd first\n\t\t 2.cd ..");
printf("\n\t\tquit:quit");
return puts("\n\t\thelp:help");
}

original_code:
void my_help(void)
{
 printf("\n\tcommand:");
 printf("\n\t\tls:  ls");
 printf("\n\t\tget: 1.get  xxx.mp3  aaa.txt\n\t\t     2.get  *.pdf  *.doc");
 printf("\n\t\tput: put  /home/chang/xxx.txt");
 printf("\n\t\tcd:  1.cd  first\n\t\t     2.cd  ..");
 printf("\n\t\tquit:quit");
 printf("\n\t\thelp:help\n");
}

canonical_original_code:
void my_help()
{
 printf("\n\tcommand:");
 printf("\n\t\tls:  ls");
 printf("\n\t\tget: 1.get  xxx.mp3  aaa.txt\n\t\t     2.get  *.pdf  *.doc");
 printf("\n\t\tput: put  /home/chang/xxx.txt");
 printf("\n\t\tcd:  1.cd  first\n\t\t     2.cd  ..");
 printf("\n\t\tquit:quit");
 printf("\n\t\thelp:help\n");
}


original_code:
void show_ls(char filename[][256])
{
 int maxlen = 60;
 int nowlen = 0;
 int i = 0,linemax = 0,j;
 char *move;
 maxlen = strlen(filename[i]);
 while ( filename[i][0] != '\0')
 {
  if (maxlen < strlen(filename[i+1]))
        maxlen = strlen(filename[i+1]);
  i++;
 }
 i = 0;
 linemax = maxlen;
 while ( filename[i][0] != '\0')
 {
  nowlen = strlen(filename[i]);
  if ((linemax + 2 ) > 60)
  {
   printf("\n");
   move = filename[i];
   while (*move != '\0')
         move++;
   while (*move != '.' && move != filename[i])
         move--;
   if (strcmp(filename[i], move) != 0 && strcmp((move-1), "..") != 0)
    printf("%s",filename[i]);
   else
   {
    printf("\033[40;34m\033[5m");
    printf("%s", filename[i]);
    printf("\033[0m");
   }
   for ( j = 0; j < maxlen - nowlen + 2; j++)
        printf(" ");
   linemax = maxlen;
   i++;
  }
  else
  {
   move = filename[i];
   while (*move != '\0')
         move++;
   while (*move != '.' && move != filename[i])
         move--;
   if (strcmp(filename[i], move) != 0 && strcmp((move-1), "..") != 0)
    printf("%s",filename[i]);
   else
   {
    printf("\033[40;34m\033[5m");
    printf("%s", filename[i]);
    printf("\033[0m");
   }
   for ( j = 0; j < maxlen - nowlen + 2; j++)
       printf(" ");
   linemax += (maxlen + 2);
   i++;
  }
 }
 printf("\n");
}

canonical_original_code:
void show_ls(char filename[][256])
{
 int maxlen = 60;
 int nowlen = 0;
 int i = 0; int linemax = 0; int j;
 char *move;
 maxlen = strlen(filename[i]);
 while ( filename[i][0] != '\0')
 {
  if (maxlen < strlen(filename[i+1]))
        maxlen = strlen(filename[i+1]);
  i++;
 }
 i = 0;
 linemax = maxlen;
 while ( filename[i][0] != '\0')
 {
  nowlen = strlen(filename[i]);
  if ((linemax + 2 ) > 60)
  {
   printf("\n");
   move = filename[i];
   while (*move != '\0')
         move++;
   while (*move != '.' && move != filename[i])
         move--;
   if (strcmp(filename[i], move) != 0 && strcmp((move-1), "..") != 0)
    printf("%s",filename[i]);
   else
   {
    printf("\033[40;34m\033[5m");
    printf("%s", filename[i]);
    printf("\033[0m");
   }
   for ( j = 0; j < maxlen - nowlen + 2; j++)
        printf(" ");
   linemax = maxlen;
   i++;
  }
  else
  {
   move = filename[i];
   while (*move != '\0')
         move++;
   while (*move != '.' && move != filename[i])
         move--;
   if (strcmp(filename[i], move) != 0 && strcmp((move-1), "..") != 0)
    printf("%s",filename[i]);
   else
   {
    printf("\033[40;34m\033[5m");
    printf("%s", filename[i]);
    printf("\033[0m");
   }
   for ( j = 0; j < maxlen - nowlen + 2; j++)
       printf(" ");
   linemax += (maxlen + 2);
   i++;
  }
 }
 printf("\n");
}

variable_types:
filename
char [][256]

variable_types: maxlen int

variable_types: nowlen int

variable_types: i int

variable_types: linemax int

variable_types: j int

variable_types:
move
char *


decompiled_code:
int __fastcall client_ls(int fd, void *buf)
{
int v2; // ebx
char v4[65560]; // [rsp+0h] [rbp-10018h] BYREF

memset(v4, 0, 0x10000uLL);
v2 = recv(fd, buf, 0x400uLL, 0);
printf(&byte_10BA, (unsigned int)v2);
if ( v2 < 0 )
{
my_err("recv", 206LL);
}
else if ( !v2 )
{
puts(&s);
}
depart_file(buf, v4);
return show_ls(v4);
}

canonical_decompiled_code:
int __fastcall func6(int fd, void *buf)
{
int v2; // ebx
char v4[65560]; // [rsp+0h] [rbp-10018h] BYREF

memset(v4, 0, 0x10000uLL);
v2 = recv(fd, buf, 0x400uLL, 0);
printf(&byte_10BA, (unsigned int)v2);
if ( v2 < 0 )
{
my_err("recv", 206LL);
}
else if ( !v2 )
{
puts(&s);
}
depart_file(buf, v4);
return func5(v4);
}

original_code:
void client_ls(int sock_fd, char *buf, char file[][256])
{
 char filename[256][256] = {"\0"};
 int ret;
 ret = recv(sock_fd, (char*)buf, 1024, 0);
 printf("已经接收到%d字节\n", ret);
 if (ret < 0)
       my_err("recv",206);
 if (ret == 0)
  printf("异常断开连接...\n");
 depart_file(buf,filename);
 show_ls(filename);
}

canonical_original_code:
void client_ls(int sock_fd, char *buf, char file[][256])
{
 char filename[256][256] = {"\0"};
 int ret;
 ret = recv(sock_fd, (char *)buf, 1024, 0);
 printf("已经接收到%d字节\n", ret);
 if (ret < 0)
       my_err("recv",206);
 if (ret == 0)
  printf("异常断开连接...\n");
 depart_file(buf,filename);
 show_ls(filename);
}

variable_types:
buf
char *

variable_types:
file
char [][256]

variable_types:
filename
char [256][256]

variable_types: ret int


original_code:
int client_my_get(int sock_fd, char *buf, char *file)
{
 int file_fd;
 char path[256] = "/home/";
 char former_path[256];
 char *receive = former_path;
 long recv_ret = 1;
 long write_ret = 1;
 double sum = 0.0;
 double local_sum = 0.0;
 printf("进入my_get()...\n");
 recv_ret = recv(sock_fd, &sum, 8, 0);
 sleep(1);
 if (recv_ret == -1)
       return 0;
        receive = getcwd(receive, 256);
 if (receive == ((void *)0))
       my_err("getcwd", 349);
 receive = getlogin();
 strcat(path, receive);
 chdir(path);
 if ((file_exist(path, "receive_ftp")) == 0)
  mkdir("receive_ftp",0766);
 strcat(path, "/receive_ftp");
 printf("当前目录为%s\n", path);
 chdir(path);
 file_fd = open(file, 0100|0200|02, 0666);
 if (file_fd == -1)
 {
  printf("文件已存在，已跳过\n");
  return 0;
 }
 while (1)
 {
  memset(buf, 0, 1024);
  recv_ret = recv(sock_fd, buf, 1024, 0);
  if (recv_ret == -1)
        my_err("recv",377);
  if (strncmp(buf, "\t\t\t", 3) == 0)
        break;
  write_ret = write(file_fd, buf, recv_ret);
  if (write_ret == -1)
        my_err("write",382);
  local_sum += (double)write_ret;
  printf("下载进度 %s %.0lf%%\n", file, local_sum/sum*100);
 }
 close(file_fd);
 chdir(former_path);
 return 1;
}

variable_types:
file
char *

variable_types:
path
char [256]

variable_types:
receive
char *

variable_types: sum double


decompiled_code:
int __fastcall client_get(int fd, void *buf)
{
__int64 bufa; // [rsp+6h] [rbp-122h] BYREF
__int16 v4; // [rsp+Eh] [rbp-11Ah]
char file[280]; // [rsp+10h] [rbp-118h] BYREF

puts(&byte_1161);
while ( 1 )
{
puts(&byte_1178);
v4 = 0;
bufa = 0LL;
recv(fd, &bufa, 0xAuLL, 0);
sleep(1u);
if ( (_WORD)bufa == 2313 && BYTE2(bufa) == 9 )
break;
memset(file, 0, 0x100uLL);
if ( (_WORD)bufa == 28270 && BYTE2(bufa) == 110 )
{
puts(&byte_11B0);
recv(fd, file, 0x100uLL, 0);
sleep(1u);
client_my_get(fd, buf, file);
}
else if ( (_WORD)bufa == 25186 && BYTE2(bufa) == 98 )
{
while ( 1 )
{
puts(&byte_11C6);
recv(fd, file, 0x100uLL, 0);
sleep(1u);
if ( *(_WORD *)file == 2313 && file[2] == 9 )
break;
puts(&byte_11EF);
client_my_get(fd, buf, file);
}
puts(&byte_11D7);
}
}
return puts(&byte_1195);
}

canonical_decompiled_code:
int __fastcall func8(int fd, void *buf)
{
__int64 bufa; // [rsp+6h] [rbp-122h] BYREF
__int16 v4; // [rsp+Eh] [rbp-11Ah]
char file[280]; // [rsp+10h] [rbp-118h] BYREF

puts(&byte_1161);
while ( 1 )
{
puts(&byte_1178);
v4 = 0;
bufa = 0LL;
recv(fd, &bufa, 0xAuLL, 0);
sleep(1u);
if ( (_WORD)bufa == 2313 && BYTE2(bufa) == 9 )
break;
memset(file, 0, 0x100uLL);
if ( (_WORD)bufa == 28270 && BYTE2(bufa) == 110 )
{
puts(&byte_11B0);
recv(fd, file, 0x100uLL, 0);
sleep(1u);
func7(fd, buf, file);
}
else if ( (_WORD)bufa == 25186 && BYTE2(bufa) == 98 )
{
while ( 1 )
{
puts(&byte_11C6);
recv(fd, file, 0x100uLL, 0);
sleep(1u);
if ( *(_WORD *)file == 2313 && file[2] == 9 )
break;
puts(&byte_11EF);
func7(fd, buf, file);
}
puts(&byte_11D7);
}
}
return puts(&byte_1195);
}

original_code:
void client_get(int sock_fd, char *buf, char file[][256])
{
 char sign[10];
 char filename[256];
 printf("进入command_get()...\n");
 while (1)
 {
  printf("已回到循环开头...\n");
  memset(sign, 0, 10);
  recv(sock_fd, sign, 10, 0);
  sleep(1);
  if (strncmp(sign, "\t\t\t", 3) == 0)
  {
   printf("接收结束标志....\n");
   break;
  }
  memset(filename, 0, 256);
  if (strncmp(sign, "nnn", 3) == 0)
  {
   printf("匹配normal()...\n");
   recv(sock_fd, filename, 256, 0);
   sleep(1);
   client_my_get(sock_fd, buf, filename);
  }
  else if (strncmp(sign, "bbb", 3) == 0)
  {
   while (1)
   {
    printf("匹配batch()...\n");
    recv(sock_fd, filename, 256, 0);
    sleep(1);
    if (strncmp(filename, "\t\t\t", 3) == 0)
    {
     printf("已退出batch循环...\n");
     break;
    }
    printf("进入batch匹配的get()...\n");
    client_my_get(sock_fd, buf, filename);
   }
  }
 }
}

variable_types:
sign
char [10]

variable_types:
filename
char [256]


decompiled_code:
int __fastcall client_my_put(int fd, void *buf, char *file)
{
int v4; // er12
int v5; // eax
int v6; // er12
int v7; // eax
int v8; // ebp
double v10; // [rsp+0h] [rbp-A8h]
unsigned __int64 v11; // [rsp+8h] [rbp-A0h]
double bufa; // [rsp+18h] [rbp-90h] BYREF
char v13[136]; // [rsp+20h] [rbp-88h] BYREF

bufa = 0.0;
pick_name(file, v13);
v4 = open(file, 2, 420LL);
if ( v4 == -1 )
my_err("open", 426LL);
do
{
v5 = read(v4, buf, 0x400uLL);
bufa = (double)v5 + bufa;
}
while ( v5 > 0 );
close(v4);
send(fd, &bufa, 8uLL, 0);
v6 = open(file, 2, 420LL);
if ( v6 == -1 )
my_err("open", 438LL);
v11 = (unsigned __int64)buf + 8;
v10 = 0.0;
while ( 1 )
{
*(_QWORD *)buf = 0LL;
*((_QWORD *)buf + 127) = 0LL;
memset((void *)(v11 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)buf - (v11 & 0xFFFFFFF8) + 1024) >> 3));
v7 = read(v6, buf, 0x400uLL);
if ( v7 == -1 )
break;
if ( v7 <= 0 )
goto LABEL_12;
v8 = send(fd, buf, v7, 0);
v10 = (double)v8 + v10;
printf(&byte_1216, v13, v10 / bufa * 100.0);
if ( v8 == -1 )
my_err("send", 456LL);
}
my_err("read", 444LL);
LABEL_12:
*(_QWORD *)buf = 0x909090909090909LL;
*((_QWORD *)buf + 127) = 0x909090909090909LL;
memset((void *)(v11 & 0xFFFFFFFFFFFFFFF8LL), 9u, 8 * (((unsigned int)buf - (v11 & 0xFFFFFFF8) + 1024) >> 3));
send(fd, buf, 0x400uLL, 0);
return close(v6);
}

canonical_decompiled_code:
int __fastcall func9(int fd, void *buf, char *file)
{
int v4; // er12
int v5; // eax
int v6; // er12
int v7; // eax
int v8; // ebp
double v10; // [rsp+0h] [rbp-A8h]
unsigned __int64 v11; // [rsp+8h] [rbp-A0h]
double bufa; // [rsp+18h] [rbp-90h] BYREF
char v13[136]; // [rsp+20h] [rbp-88h] BYREF

bufa = 0.0;
pick_name(file, v13);
v4 = open(file, 2, 420LL);
if ( v4 == -1 )
my_err("open", 426LL);
do
{
v5 = read(v4, buf, 0x400uLL);
bufa = (double)v5 + bufa;
}
while ( v5 > 0 );
close(v4);
send(fd, &bufa, 8uLL, 0);
v6 = open(file, 2, 420LL);
if ( v6 == -1 )
my_err("open", 438LL);
v11 = (unsigned __int64)buf + 8;
v10 = 0.0;
while ( 1 )
{
*(_QWORD *)buf = 0LL;
*((_QWORD *)buf + 127) = 0LL;
memset((void *)(v11 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)buf - (v11 & 0xFFFFFFF8) + 1024) >> 3));
v7 = read(v6, buf, 0x400uLL);
if ( v7 == -1 )
break;
if ( v7 <= 0 )
goto LABEL_12;
v8 = send(fd, buf, v7, 0);
v10 = (double)v8 + v10;
printf(&byte_1216, v13, v10 / bufa * 100.0);
if ( v8 == -1 )
my_err("send", 456LL);
}
my_err("read", 444LL);
LABEL_12:
*(_QWORD *)buf = 0x909090909090909LL;
*((_QWORD *)buf + 127) = 0x909090909090909LL;
memset((void *)(v11 & 0xFFFFFFFFFFFFFFF8LL), 9u, 8 * (((unsigned int)buf - (v11 & 0xFFFFFFF8) + 1024) >> 3));
send(fd, buf, 0x400uLL, 0);
return close(v6);
}

original_code:
void client_my_put(int sock_fd, char *buf, char *file)
{
 int read_ret = 1;
 int send_ret = 1;
 int file_fd;
 double sum = 0;
 double local_sum = 0;
 char name[80];
 pick_name(file, name);
 file_fd = open(file, 02, 0644);
 if (file_fd == -1)
       my_err("open", 426);
 while (read_ret > 0)
 {
  read_ret = read(file_fd, buf, 1024);
  sum += read_ret;
 }
 close(file_fd);
 send(sock_fd, &sum, 8, 0);
 file_fd = open(file, 02, 0644);
 if (file_fd == -1)
       my_err("open", 438);
 while (1)
 {
  memset(buf, 0, 1024);
  read_ret = read(file_fd, buf, 1024);
  if (read_ret == -1)
        my_err("read", 444);
  if (read_ret <= 0)
  {
   memset(buf, '\t', 1024);
   send(sock_fd, buf, 1024, 0);
   break;
  }
  send_ret = send(sock_fd, buf, read_ret, 0);
  local_sum += send_ret;
  printf("上传进度%s %.lf%%\n", name, local_sum/sum*100);
  if (send_ret == -1)
        my_err("send", 456);
 }
 close(file_fd);
}

variable_types:
name
char [80]


decompiled_code:
int __fastcall client_put(int fd, void *buf, char *file)
{
char v5[256]; // [rsp+0h] [rbp-218h] BYREF
char path[280]; // [rsp+100h] [rbp-118h] BYREF

if ( !getcwd(v5, 0x100uLL) )
my_err("getcwd", 401LL);
find_path(file, path);
chdir(path);
printf(&byte_1232, path);
client_my_put(fd, buf, file);
return chdir(v5);
}

canonical_decompiled_code:
int __fastcall func10(int fd, void *buf, char *file)
{
char v5[256]; // [rsp+0h] [rbp-218h] BYREF
char path[280]; // [rsp+100h] [rbp-118h] BYREF

if ( !getcwd(v5, 0x100uLL) )
my_err("getcwd", 401LL);
find_path(file, path);
chdir(path);
printf(&byte_1232, path);
func9(fd, buf, file);
return chdir(v5);
}

original_code:
void client_put(int sock_fd, char *buf, char *file)
{
 char former_path[256];
 char *receive = former_path;
 char file_path[256];
 receive = getcwd(receive, 256);
 if (receive == ((void *)0))
       my_err("getcwd", 401);
 find_path(file, file_path);
 chdir(file_path);
 printf("已经转到%s目录\n",file_path);
 client_my_put(sock_fd, buf, file);
 chdir(former_path);
}


decompiled_code:
__int16 __fastcall client_cd(int fd, void *buf)
{
int v2; // eax
__int16 bufa[13]; // [rsp+Eh] [rbp-1Ah] BYREF

if ( (unsigned int)recv(fd, bufa, 2uLL, 0) <= 1 )
my_err("recv ", 468LL);
LOWORD(v2) = _bswap_16(bufa[0]);
bufa[0] = v2;
if ( (_WORD)v2 == 1 )
{
v2 = recv(fd, buf, 0x100uLL, 0);
if ( v2 == -1 )
LOWORD(v2) = my_err("cd recv", 474LL);
}
return v2;
}

canonical_decompiled_code:
__int16 __fastcall func11(int fd, void *buf)
{
int v2; // eax
__int16 bufa[13]; // [rsp+Eh] [rbp-1Ah] BYREF

if ( (unsigned int)recv(fd, bufa, 2uLL, 0) <= 1 )
my_err("recv ", 468LL);
LOWORD(v2) = func0(bufa[0]);
bufa[0] = v2;
if ( (_WORD)v2 == 1 )
{
v2 = recv(fd, buf, 0x100uLL, 0);
if ( v2 == -1 )
LOWORD(v2) = my_err("cd recv", 474LL);
}
return v2;
}

original_code:
void client_cd(int sock_fd, char *name)
{
 int ret;
 unsigned short flag;
 ret = recv(sock_fd, (char*)&flag, sizeof(unsigned short), 0);
 if (ret < sizeof(unsigned short))
       my_err("recv ",468);
 flag = ntohs(flag);
 if (flag == 1)
 {
  ret = recv(sock_fd, name, 256, 0);
  if (ret == -1)
        my_err("cd recv", 474);
 }
}

canonical_original_code:
void client_cd(int sock_fd, char *name)
{
 int ret;
 unsigned short flag;
 ret = recv(sock_fd, (char *)&flag, sizeof(unsigned short), 0);
 if (ret < sizeof(unsigned short))
       my_err("recv ",468);
 flag = ntohs(flag);
 if (flag == 1)
 {
  ret = recv(sock_fd, name, 256, 0);
  if (ret == -1)
        my_err("cd recv", 474);
 }
}

variable_types:
name
char *

variable_types:
flag
unsigned short


original_code:
int deal_server(int sock_fd)
{
 int ret;
 char file[80][256] = {"\0"};
 char buf[1024];
 char command[256] = "\0";
 unsigned int cmd_num;
 int i = 0;
 char name[256] = "changgong";
 while (1)
 {
  printf("\nftp:%s/>> ",name);
  for( i = 0; i < 80; i++)
        file[i][0] = '\0';
  i = 0;
  my_scanf(command);
  if (strncmp(command,"quit", 4) == 0 || strncmp(command, "exit", 4) == 0)
        cmd_num = 0;
  else if (strncmp(command,"ls", 2) == 0)
        cmd_num = 1;
  else if (strncmp(command,"get", 3) == 0)
        cmd_num = 2;
  else if (strncmp(command,"put", 3) == 0)
        cmd_num = 3;
  else if (strncmp(command,"cd", 2) == 0)
        cmd_num = 4;
  else if (strncmp(command, "help", 4) == 0)
        cmd_num = 9;
  else
  {
   printf("错误输入，重新输入");
   my_help();
   memset(command, '\0', 256);
   cmd_num = 111;
   continue;
  }
  printf("发送命令为%s,编号%u\n", command, cmd_num);
  if (cmd_num == 2 || cmd_num == 4 || cmd_num == 3)
  {
   depart_file(command, file);
   if (file[1][0] == '\0')
   {
    printf("command need least one argv\n");
    continue;
   }
  }
  if (command[0] != '\0' && cmd_num != 9)
  {
   cmd_num = htonl(cmd_num);
   ret = send(sock_fd, (char*)&cmd_num,sizeof(unsigned int), 0);
   if (ret < sizeof(unsigned int))
   {
    printf("发送时丢失数据包...错误...\n");
    return -1;
   }
  }
  else
  {
   my_help();
   continue;
  }
  cmd_num = ntohl(cmd_num);
  if (command[0] != '\0' && cmd_num != 9)
  {
   ret = send(sock_fd, command, 256, 0);
   if (ret < 256)
   {
    printf("发送时丢失数据包...错误...\n");
    return -1;
   }
  }
  else
  {
   my_help();
   continue;
  }
  switch (cmd_num)
  {
   case 0:
    return 0;
   case 1:
    client_ls(sock_fd, buf, file);
    break;
   case 2:
    client_get(sock_fd, buf, file);
    break;
   case 3:
    client_put(sock_fd, buf, file[1]);
    break;
   case 4:
    client_cd(sock_fd, name);
    break;
  }
 }
}

canonical_original_code:
int deal_server(int sock_fd)
{
 int ret;
 char file[80][256] = {"\0"};
 char buf[1024];
 char command[256] = "\0";
 unsigned int cmd_num;
 int i = 0;
 char name[256] = "changgong";
 while (1)
 {
  printf("\nftp:%s/>> ",name);
  for( i = 0; i < 80; i++)
        file[i][0] = '\0';
  i = 0;
  my_scanf(command);
  if (strncmp(command,"quit", 4) == 0 || strncmp(command, "exit", 4) == 0)
        cmd_num = 0;
  else if (strncmp(command,"ls", 2) == 0)
        cmd_num = 1;
  else if (strncmp(command,"get", 3) == 0)
        cmd_num = 2;
  else if (strncmp(command,"put", 3) == 0)
        cmd_num = 3;
  else if (strncmp(command,"cd", 2) == 0)
        cmd_num = 4;
  else if (strncmp(command, "help", 4) == 0)
        cmd_num = 9;
  else
  {
   printf("错误输入，重新输入");
   my_help();
   memset(command, '\0', 256);
   cmd_num = 111;
   continue;
  }
  printf("发送命令为%s,编号%u\n", command, cmd_num);
  if (cmd_num == 2 || cmd_num == 4 || cmd_num == 3)
  {
   depart_file(command, file);
   if (file[1][0] == '\0')
   {
    printf("command need least one argv\n");
    continue;
   }
  }
  if (command[0] != '\0' && cmd_num != 9)
  {
   cmd_num = htonl(cmd_num);
   ret = send(sock_fd, (char *)&cmd_num,sizeof(unsigned int), 0);
   if (ret < sizeof(unsigned int))
   {
    printf("发送时丢失数据包...错误...\n");
    return -1;
   }
  }
  else
  {
   my_help();
   continue;
  }
  cmd_num = ntohl(cmd_num);
  if (command[0] != '\0' && cmd_num != 9)
  {
   ret = send(sock_fd, command, 256, 0);
   if (ret < 256)
   {
    printf("发送时丢失数据包...错误...\n");
    return -1;
   }
  }
  else
  {
   my_help();
   continue;
  }
  switch (cmd_num)
  {
   case 0:
    return 0;
   case 1:
    client_ls(sock_fd, buf, file);
    break;
   case 2:
    client_get(sock_fd, buf, file);
    break;
   case 3:
    client_put(sock_fd, buf, file[1]);
    break;
   case 4:
    client_cd(sock_fd, name);
    break;
  }
 }
}

variable_types:
buf
char [1024]

variable_types:
command
char [256]

variable_types: i int

variable_types:
name
char [256]


client

decompiled_code:
__int64 __fastcall client(int fd)
{
my_help();
deal_server(fd);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(int fd)
{
func4();
func12(fd);
return 0LL;
}

original_code:
int client(int sock_fd)
{
 my_help();
 deal_server(sock_fd);
 return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edx
int v4; // ebp
struct in_addr inp[4]; // [rsp+0h] [rbp-28h] BYREF

if ( argc != 2 )
goto LABEL_9;
*(_OWORD *)&inp[0].s_addr = 0LL;
LOWORD(inp[0].s_addr) = 2;
HIWORD(inp[0].s_addr) = _bswap_16(4507);
v4 = socket(2, 1, v3);
if ( v4 < 0 )
my_err("socket", 63LL);
if ( inet_aton(argv[1], &inp[1]) <= 0 )
{
puts(aIp);
LABEL_9:
information();
return -1;
}
if ( connect(v4, (const struct sockaddr *)inp, 0x10u) < 0 )
my_err("connect", 73LL);
client(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edx
int v4; // ebp
struct in_addr inp[4]; // [rsp+0h] [rbp-28h] BYREF

if ( argc != 2 )
goto LABEL_9;
*(_OWORD *)&inp[0].s_addr = 0LL;
LOWORD(inp[0].s_addr) = 2;
HIWORD(inp[0].s_addr) = func0(4507);
v4 = socket(2, 1, v3);
if ( v4 < 0 )
my_err("socket", 63LL);
if ( inet_aton(argv[1], &inp[1]) <= 0 )
{
puts(aIp);
LABEL_9:
func2();
return -1;
}
if ( connect(v4, (const struct sockaddr *)inp, 0x10u) < 0 )
my_err("connect", 73LL);
func13(v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 struct sockaddr_in sock;
 int sock_fd;
 int ret;
 if ( argc != 2)
 {
  information();
  return -1;
 }
 memset(&sock, 0, sizeof(struct sockaddr_in));
 sock.sin_family = 2;
 sock.sin_port = htons(4507);
 sock_fd = socket(2, SOCK_STREAM, 0);
 if (sock_fd < 0)
       my_err("socket",63);
 ret = inet_aton(argv[1], &sock.sin_addr);
 if (ret <= 0)
 {
  printf("IP不可用\n");
  information();
  return -1;
 }
 if (connect(sock_fd, (struct sockaddr*)&sock, sizeof(struct sockaddr)) < 0)
       my_err("connect", 73);
 client(sock_fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct sockaddr_in sock;
 int sock_fd;
 int ret;
 if ( argc != 2)
 {
  information();
  return -1;
 }
 memset(&sock, 0, sizeof(struct sockaddr_in));
 sock.sin_family = 2;
 sock.sin_port = htons(4507);
 sock_fd = socket(2, SOCK_STREAM, 0);
 if (sock_fd < 0)
       my_err("socket",63);
 ret = inet_aton(argv[1], &sock.sin_addr);
 if (ret <= 0)
 {
  printf("IP不可用\n");
  information();
  return -1;
 }
 if (connect(sock_fd, (struct sockaddr *)&sock, sizeof(struct sockaddr)) < 0)
       my_err("connect", 73);
 client(sock_fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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

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

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
void __fastcall __noreturn my_err(char *s, unsigned int a2)
{
fprintf(stderr, "line: %d ", a2);
perror(s);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(char *s, unsigned int a2)
{
fprintf(stderr, "line: %d ", a2);
perror(s);
exit(1);
}

original_code:
void my_err(char *string,int line)
{
 fprintf(stderr,"line: %d ",line);
 perror(string);
 exit(1);
}

canonical_original_code:
void my_err(char *string, int line)
{
 fprintf(stderr,"line: %d ",line);
 perror(string);
 exit(1);
}

variable_types:
string
char *

variable_types: line int


decompiled_code:
char *__fastcall left_batch(const char *a1, char *a2)
{
const char *v3; // rsi

v3 = 0LL;
if ( !left_batch )
goto LABEL_5;
do
++v3;
while ( *v3 );
while ( a1 != v3 )
{
if ( *--v3 == 46 )
break;
LABEL_5:
;
}
return strcpy(a2, v3);
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1, char *a2)
{
const char *v3; // rsi

v3 = 0LL;
if ( !left_batch )
goto LABEL_5;
do
++v3;
while ( *v3 );
while ( a1 != v3 )
{
if ( *--v3 == 46 )
break;
LABEL_5:
;
}
return strcpy(a2, v3);
}

original_code:
void left_batch(char *string, char *batch)
{
 char *move;
 while (*move != '\0')
       move++;
 while (*move != '.' && move != string)
       move--;
 strcpy(batch, move);
}

variable_types:
batch
char *

variable_types:
move
char *


decompiled_code:
char *__fastcall find_path(char *src, char *dest)
{
char *result; // rax
char *i; // rdx

result = strcpy(dest, src);
for ( i = result; *i; ++i )
;
do
--i;
while ( *i != 47 );
*i = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *src, char *dest)
{
char *result; // rax
char *i; // rdx

result = strcpy(dest, src);
for ( i = result; *i; ++i )
;
do
--i;
while ( *i != 47 );
*i = 0;
return result;
}

original_code:
void find_path(char *file, char *path)
{
 char *move = path;
 strcpy(path ,file);
 while (*move != '\0')
       move++;
 while (*move != '/')
       move--;
 *move = '\0';
}

variable_types:
file
char *

variable_types:
path
char *


original_code:
void path_deal(char *path)
{
 char *move = path + 11;
 char temp[256];
 strcpy(temp, move);
 strcpy(path, "/home/chang/changgong");
 strcat(path, move);
 printf("此时路径为%s\n", path);
}

variable_types:
temp
char [256]


original_code:
void depart_file(char *buf, char filename[][256])
{
 char *move = buf;
 int i = 0, j = 0;
 while (*move != '\0')
 {
  if (*move == '\t' || *move == ' ')
  {
   filename[i][j] = '\0';
   i++;
   j = 0;
   move++;
  }
  filename[i][j] = *move;
  move++;
  j++;
 }
}

canonical_original_code:
void depart_file(char *buf, char filename[][256])
{
 char *move = buf;
 int i = 0; int j = 0;
 while (*move != '\0')
 {
  if (*move == '\t' || *move == ' ')
  {
   filename[i][j] = '\0';
   i++;
   j = 0;
   move++;
  }
  filename[i][j] = *move;
  move++;
  j++;
 }
}

variable_types:
buf
char *

variable_types:
filename
char [][256]

variable_types: j int


decompiled_code:
char *__fastcall pick_name(char *src, char *dest)
{
const char *v3; // rsi

for ( ; *src; ++src )
;
do
v3 = src--;
while ( *src != 47 );
return strcpy(dest, v3);
}

canonical_decompiled_code:
char *__fastcall func0(char *src, char *dest)
{
const char *v3; // rsi

for ( ; *src; ++src )
;
do
v3 = src--;
while ( *src != 47 );
return strcpy(dest, v3);
}

original_code:
void pick_name(char *file, char *name)
{
 char *move = file;
 while (*move != '\0')
       move++;
 while (*move != '/')
       move--;
 move++;
 strcpy(name, move);
}

variable_types:
name
char *


compare

repo: cgxryy/stack

original_code:
int compare(char top, char ch)
{
 int v_top, v_ch;
 v_top = judge_pri(top);
 v_ch = judge_pri(ch);
 if (v_ch == 4 && v_top != 3)
       return 4;
 else if (v_ch == 4 && v_top == 3)
       return 5;
 if (v_ch == 3)
       return 2;
 if (v_top == 3 && v_ch <= 2)
       return 2;
 if (v_top == -1 && v_ch == -1)
       return 1;
 if (v_top < v_ch)
       return 2;
 if (v_top >= v_ch)
       return 3;
 return 0;
}

canonical_original_code:
int compare(char top, char ch)
{
 int v_top; int v_ch;
 v_top = judge_pri(top);
 v_ch = judge_pri(ch);
 if (v_ch == 4 && v_top != 3)
       return 4;
 else if (v_ch == 4 && v_top == 3)
       return 5;
 if (v_ch == 3)
       return 2;
 if (v_top == 3 && v_ch <= 2)
       return 2;
 if (v_top == -1 && v_ch == -1)
       return 1;
 if (v_top < v_ch)
       return 2;
 if (v_top >= v_ch)
       return 3;
 return 0;
}

variable_types: top char

variable_types: ch char


decompiled_code:
__int64 __fastcall infix_to_postfix(char *a1, char *a2)
{
char *v3; // rbp
char v4; // bl
int v5; // er13
char v6; // r14
char v7; // bl
char *v8; // rsi
char *v9; // rsi
char v11; // [rsp+6h] [rbp-32h] BYREF
char v12; // [rsp+7h] [rbp-31h] BYREF
__int64 v13[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = a1;
v12 = 35;
stack_init(v13);
stack_push(v13[0], &v12, 1LL);
v4 = *a1;
if ( *a1 )
{
v5 = 0;
do
{
LABEL_5:
if ( v4 != 32 && v4 != 9 )
{
if ( (unsigned int)judge_num((unsigned int)v4) )
{
*a2++ = v4;
goto LABEL_4;
}
if ( (unsigned int)judge_opt((unsigned int)v4) )
{
while ( 1 )
{
while ( !(unsigned int)stack_gettop(v13[0], &v11, 1LL) )
stack_push(v13[0], v3, 1LL);
v6 = *v3;
v7 = v11;
switch ( (unsigned int)compare(v11, *v3) )
{
case 1u:
goto LABEL_4;
case 2u:
if ( v5 == 1 )
{
++a2;
v5 = 0;
stack_pop(v13[0], &v11, 1LL);
*(a2 - 1) = *v3;
goto LABEL_4;
}
v9 = v3++;
stack_push(v13[0], v9, 1LL);
v4 = *v3;
if ( !*v3 )
goto LABEL_18;
goto LABEL_5;
case 3u:
if ( v5 )
{
if ( v7 == 40 )
{
*a2 = v6;
v5 = 0;
++a2;
goto LABEL_4;
}
}
else if ( v7 == 40 )
{
stack_push(v13[0], v3, 1LL);
goto LABEL_4;
}
v8 = a2++;
stack_pop(v13[0], v8, 1LL);
stack_push(v13[0], v3, 1LL);
LABEL_12:
stack_pop(v13[0], v3, 1LL);
break;
case 4u:
v5 = 1;
goto LABEL_12;
case 5u:
stack_pop(v13[0], &v11, 1LL);
goto LABEL_4;
default:
puts("compare has a mistake!");
goto LABEL_12;
}
}
}
}
LABEL_4:
v4 = *++v3;
}
while ( v4 );
}
LABEL_18:
*a2 = 0;
return stack_dis(v13[0]);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, char *a2)
{
char *v3; // rbp
char v4; // bl
int v5; // er13
char v6; // r14
char v7; // bl
char *v8; // rsi
char *v9; // rsi
char v11; // [rsp+6h] [rbp-32h] BYREF
char v12; // [rsp+7h] [rbp-31h] BYREF
__int64 v13[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = a1;
v12 = 35;
stack_init(v13);
stack_push(v13[0], &v12, 1LL);
v4 = *a1;
if ( *a1 )
{
v5 = 0;
do
{
LABEL_5:
if ( v4 != 32 && v4 != 9 )
{
if ( (unsigned int)judge_num((unsigned int)v4) )
{
*a2++ = v4;
goto LABEL_4;
}
if ( (unsigned int)judge_opt((unsigned int)v4) )
{
while ( 1 )
{
while ( !(unsigned int)stack_gettop(v13[0], &v11, 1LL) )
stack_push(v13[0], v3, 1LL);
v6 = *v3;
v7 = v11;
switch ( (unsigned int)func1(v11, *v3) )
{
case 1u:
goto LABEL_4;
case 2u:
if ( v5 == 1 )
{
++a2;
v5 = 0;
stack_pop(v13[0], &v11, 1LL);
*(a2 - 1) = *v3;
goto LABEL_4;
}
v9 = v3++;
stack_push(v13[0], v9, 1LL);
v4 = *v3;
if ( !*v3 )
goto LABEL_18;
goto LABEL_5;
case 3u:
if ( v5 )
{
if ( v7 == 40 )
{
*a2 = v6;
v5 = 0;
++a2;
goto LABEL_4;
}
}
else if ( v7 == 40 )
{
stack_push(v13[0], v3, 1LL);
goto LABEL_4;
}
v8 = a2++;
stack_pop(v13[0], v8, 1LL);
stack_push(v13[0], v3, 1LL);
LABEL_12:
stack_pop(v13[0], v3, 1LL);
break;
case 4u:
v5 = 1;
goto LABEL_12;
case 5u:
stack_pop(v13[0], &v11, 1LL);
goto LABEL_4;
default:
puts("compare has a mistake!");
goto LABEL_12;
}
}
}
}
LABEL_4:
v4 = *++v3;
}
while ( v4 );
}
LABEL_18:
*a2 = 0;
return stack_dis(v13[0]);
}

original_code:
void infix_to_postfix(char *infix, char *postfix)
{
 Stack *opt;
 char *in, *out;
 char temp;
 int flag = 0;
 int flag_top = 0;
 char end = '#';
 stack_init(&opt);
 stack_push(opt, (void*)&end, 1);
 for ( in = infix, out = postfix; *in != '\0'; in++, flag = 0)
 {
  if (*in == ' ' || *in == '\t')
        continue;
  if (judge_num(*in))
  {
   *out = *in;
   out++;
  }
  else if (judge_opt(*in))
  {
   do
   {
    if (!stack_gettop(opt, (void*)&temp, 1))
    {
     stack_push(opt, (void*)in, 1);
    }
    else
    {
     switch (compare(temp, *in))
     {
      case 1:
       flag = 1;
       break;
      case 2:
       if (flag_top == 1)
       {
        flag_top = 0;
        flag = 1;
        stack_pop(opt, (void*)&temp, 1);
        *out = *in;
        out++;
       }
       else
       {
        stack_push(opt, (void*)in, 1);
        flag = 1;
       }
       break;
      case 3:
       if (flag_top == 0 && temp == '(')
       {
        stack_push(opt, (void*)in, 1);
        flag = 1;
        break;
       }
       if (temp == '(')
       {
        *out = *in;
        out++;
        flag = 1;
        flag_top = 0;
       }
       else
       {
        stack_pop(opt, (void*)out, 1);
        stack_push(opt, (void*)in, 1);
        out++;
        flag = 0;
       }
       break;
      case 4:
       flag_top = 1;
       flag = 0;
       break;
      case 5:
       stack_pop(opt, (void*)&temp, 1);
       flag = 1;
       break;
      default:
       printf("compare has a mistake!\n");
     }
     if (flag == 0)
     {
      stack_pop(opt, (void*)in, 1);
     }
    }
   }while (flag == 0);
  }
 }
 *out = '\0';
 stack_dis(opt);
}

canonical_original_code:
void infix_to_postfix(char *infix, char *postfix)
{
 struct stack *opt;
 char *in; char *out;
 char temp;
 int flag = 0;
 int flag_top = 0;
 char end = '#';
 stack_init(&opt);
 stack_push(opt, (void *)&end, 1);
 for ( in = infix, out = postfix; *in != '\0'; in++, flag = 0)
 {
  if (*in == ' ' || *in == '\t')
        continue;
  if (judge_num(*in))
  {
   *out = *in;
   out++;
  }
  else if (judge_opt(*in))
  {
   do
   {
    if (!stack_gettop(opt, (void *)&temp, 1))
    {
     stack_push(opt, (void *)in, 1);
    }
    else
    {
     switch (compare(temp, *in))
     {
      case 1:
       flag = 1;
       break;
      case 2:
       if (flag_top == 1)
       {
        flag_top = 0;
        flag = 1;
        stack_pop(opt, (void *)&temp, 1);
        *out = *in;
        out++;
       }
       else
       {
        stack_push(opt, (void *)in, 1);
        flag = 1;
       }
       break;
      case 3:
       if (flag_top == 0 && temp == '(')
       {
        stack_push(opt, (void *)in, 1);
        flag = 1;
        break;
       }
       if (temp == '(')
       {
        *out = *in;
        out++;
        flag = 1;
        flag_top = 0;
       }
       else
       {
        stack_pop(opt, (void *)out, 1);
        stack_push(opt, (void *)in, 1);
        out++;
        flag = 0;
       }
       break;
      case 4:
       flag_top = 1;
       flag = 0;
       break;
      case 5:
       stack_pop(opt, (void *)&temp, 1);
       flag = 1;
       break;
      default:
       printf("compare has a mistake!\n");
     }
     if (flag == 0)
     {
      stack_pop(opt, (void *)in, 1);
     }
    }
   }while (flag == 0);
  }
 }
 *out = '\0';
 stack_dis(opt);
}

variable_types:
infix
char *

variable_types:
postfix
char *

variable_types: struct stack { void *pointer; int elem_size; struct stack *next; } *

variable_types:
in
char *

variable_types:
out
char *

variable_types: temp char

variable_types: flag int

variable_types: end char


decompiled_code:
__int64 __fastcall stack_init(_QWORD *a1)
{
_QWORD *v1; // rax

v1 = malloc(0x18uLL);
*a1 = v1;
if ( !v1 )
return 0LL;
v1[2] = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
_QWORD *v1; // rax

v1 = malloc(0x18uLL);
*a1 = v1;
if ( !v1 )
return 0LL;
v1[2] = 0LL;
return 1LL;
}

original_code:
int stack_init(Stack **head)
{
 if ((*head = malloc(sizeof(Stack))) == ((void *)0))
       return 0;
 (*head)->next = ((void *)0);
 return 1;
}

canonical_original_code:
int stack_init(struct stack **head)
{
 if ((*head = malloc(sizeof(Stack))) == ((void *)0))
       return 0;
 (*head)->next = ((void *)0);
 return 1;
}

variable_types: struct stack { void *pointer; int elem_size; struct stack *next; } **


decompiled_code:
_BOOL8 __fastcall stack_empty(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

original_code:
int stack_empty(Stack *head)
{
 if (head->next == ((void *)0))
       return 1;
 else return 0;
}

canonical_original_code:
int stack_empty(struct stack *head)
{
 if (head->next == ((void *)0))
       return 1;
 else return 0;
}

user_defined_types: struct stack { void *pointer; int elem_size; struct stack *next; }


decompiled_code:
__int64 __fastcall stack_push(__int64 a1, const void *a2, int a3)
{
_DWORD *v4; // rax
_DWORD *v5; // rbx
void *v6; // rax
__int64 v7; // rax

v4 = malloc(0x18uLL);
if ( !v4 )
return 0LL;
v5 = v4;
v6 = malloc(a3);
*(_QWORD *)v5 = v6;
if ( !v6 )
return 0LL;
memcpy(v6, a2, a3);
v7 = *(_QWORD *)(a1 + 16);
v5[2] = a3;
*(_QWORD *)(a1 + 16) = v5;
*((_QWORD *)v5 + 2) = v7;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const void *a2, int a3)
{
_DWORD *v4; // rax
_DWORD *v5; // rbx
void *v6; // rax
__int64 v7; // rax

v4 = malloc(0x18uLL);
if ( !v4 )
return 0LL;
v5 = v4;
v6 = malloc(a3);
*(_QWORD *)v5 = v6;
if ( !v6 )
return 0LL;
memcpy(v6, a2, a3);
v7 = *(_QWORD *)(a1 + 16);
v5[2] = a3;
*(_QWORD *)(a1 + 16) = v5;
*((_QWORD *)v5 + 2) = v7;
return 1LL;
}

original_code:
int stack_push(Stack *head, void *temp, int size)
{
 Stack *push;
 if ((push = (Stack *)malloc(sizeof(Stack))) == ((void *)0))
       return 0;
 if ((push->pointer = malloc(size)) == ((void *)0))
       return 0;
 memcpy(push->pointer, temp, size);
 push->elem_size = size;
 push->next = head->next;
 head->next = push;
 return 1;
}

canonical_original_code:
int stack_push(struct stack *head, void *temp, int size)
{
 struct stack *push;
 if ((push = (struct stack *)malloc(sizeof(Stack))) == ((void *)0))
       return 0;
 if ((push->pointer = malloc(size)) == ((void *)0))
       return 0;
 memcpy(push->pointer, temp, size);
 push->elem_size = size;
 push->next = head->next;
 head->next = push;
 return 1;
}

variable_types:
temp
void *

variable_types: size int


decompiled_code:
__int64 __fastcall stack_pop(__int64 a1, void *a2)
{
int v3; // edx
_BOOL4 v4; // er9
__int64 result; // rax
_QWORD *v6; // rdi

v4 = stack_empty(a1);
result = 0LL;
if ( !v4 )
{
memcpy(a2, **(const void ***)(a1 + 16), v3);
v6 = *(_QWORD **)(a1 + 16);
*(_QWORD *)(a1 + 16) = v6[2];
free(v6);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, void *a2)
{
int v3; // edx
_BOOL4 v4; // er9
__int64 result; // rax
_QWORD *v6; // rdi

v4 = func1(a1);
result = 0LL;
if ( !v4 )
{
memcpy(a2, **(const void ***)(a1 + 16), v3);
v6 = *(_QWORD **)(a1 + 16);
*(_QWORD *)(a1 + 16) = v6[2];
free(v6);
result = 1LL;
}
return result;
}

original_code:
int stack_pop(Stack *head, void *temp, int size)
{
 Stack *del;
 if (stack_empty(head))
       return 0;
 memcpy(temp, head->next->pointer, size);
 del = head->next;
 head->next = head->next->next;
 free(del);
 return 1;
}

canonical_original_code:
int stack_pop(struct stack *head, void *temp, int size)
{
 struct stack *del;
 if (stack_empty(head))
       return 0;
 memcpy(temp, head->next->pointer, size);
 del = head->next;
 head->next = head->next->next;
 free(del);
 return 1;
}


decompiled_code:
__int64 __fastcall stack_gettop(__int64 a1, void *a2)
{
int v2; // edx
_BOOL4 v3; // er9
__int64 result; // rax

v3 = stack_empty(a1);
result = 0LL;
if ( !v3 )
{
memcpy(a2, **(const void ***)(a1 + 16), v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, void *a2)
{
int v2; // edx
_BOOL4 v3; // er9
__int64 result; // rax

v3 = func1(a1);
result = 0LL;
if ( !v3 )
{
memcpy(a2, **(const void ***)(a1 + 16), v2);
result = 1LL;
}
return result;
}

original_code:
int stack_gettop(Stack *head, void *temp, int size)
{
 if (stack_empty(head))
       return 0;
 memcpy(temp, head->next->pointer, size);
 return 1;
}

canonical_original_code:
int stack_gettop(struct stack *head, void *temp, int size)
{
 if (stack_empty(head))
       return 0;
 memcpy(temp, head->next->pointer, size);
 return 1;
}


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

if ( !ptr )
return 0LL;
v1 = *((_QWORD *)ptr + 2);
if ( v1 || (free(ptr), (v1 = *((_QWORD *)ptr + 2)) != 0) )
{
do
{
free(ptr);
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return 1LL;
}

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

if ( !ptr )
return 0LL;
v1 = *((_QWORD *)ptr + 2);
if ( v1 || (free(ptr), (v1 = *((_QWORD *)ptr + 2)) != 0) )
{
do
{
free(ptr);
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return 1LL;
}

original_code:
int stack_dis(Stack *head)
{
 Stack *del_next;
 if (head == ((void *)0))
       return 0;
 if (head->next == ((void *)0))
       free(head);
 for ( del_next = head->next; del_next != ((void *)0); del_next = del_next->next)
       free(head);
 return 1;
}

canonical_original_code:
int stack_dis(struct stack *head)
{
 struct stack *del_next;
 if (head == ((void *)0))
       return 0;
 if (head->next == ((void *)0))
       free(head);
 for ( del_next = head->next; del_next != ((void *)0); del_next = del_next->next)
       free(head);
 return 1;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int128 v4[3]; // [rsp+0h] [rbp-88h] BYREF
__int16 v5; // [rsp+30h] [rbp-58h]
char v6[72]; // [rsp+40h] [rbp-48h] BYREF

v5 = 0;
v4[0] = (__int128)_mm_load_si128((const __m128i *)&LC2);
v4[1] = 0LL;
v4[2] = 0LL;
printf("infix\t%s\n", (const char *)v4);
infix_to_postfix(v4, v6);
printf("postfix\t%s\n", v6);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char infix[50] = "9+(3-1)*3+10/2#";
 char postfix[50];
 printf("infix\t%s\n", infix);
 infix_to_postfix(infix, postfix);
 printf("postfix\t%s\n", postfix);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
infix
char [50]

variable_types:
postfix
char [50]


getField

repo: chaddcw/ContactManager-Example-C

decompiled_code:
__int64 getField()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

puts("\n0. First Name");
puts("1.Last Name");
puts("2. Email");
_isoc99_scanf("%d", v1);
return v1[0];
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

puts("\n0. First Name");
puts("1.Last Name");
puts("2. Email");
_isoc99_scanf("%d", v1);
return v1[0];
}

original_code:
Field getField()
{
 Field theField;
 printf("\n0. First Name\n");
 printf("1.Last Name\n");
 printf("2. Email\n");
 scanf("%d", &theField);
 return theField;
}

canonical_original_code:
enum Field getField()
{
 enum Field theField;
 printf("\n0. First Name\n");
 printf("1.Last Name\n");
 printf("2. Email\n");
 scanf("%d", &theField);
 return theField;
}

variable_types: enum Field { FName=0, LName=1, Email=2 }


getString

decompiled_code:
__int64 __fastcall getString(__int64 a1, int a2)
{
printf("What string in the field ");
switch ( a2 )
{
case 1:
printf("Last Name");
break;
case 2:
printf("Email");
break;
case 0:
printf("First Name");
break;
}
printf(" do you want to search for? ");
return _isoc99_scanf("%1024s", a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
printf("What string in the field ");
switch ( a2 )
{
case 1:
printf("Last Name");
break;
case 2:
printf("Email");
break;
case 0:
printf("First Name");
break;
}
printf(" do you want to search for? ");
return _isoc99_scanf("%1024s", a1);
}

original_code:
void getString(char* pBuf, Field theField)
{
 printf("What string in the field ");
 switch(theField)
 {
  case 0:
   printf("First Name");
   break;
  case 1:
   printf("Last Name");
   break;
  case 2:
   printf("Email");
   break;
 }
 printf(" do you want to search for? ");
 scanf("%1024s",pBuf);
}

canonical_original_code:
void getString(char *pBuf, enum Field theField)
{
 printf("What string in the field ");
 switch(theField)
 {
  case 0:
   printf("First Name");
   break;
  case 1:
   printf("Last Name");
   break;
  case 2:
   printf("Email");
   break;
 }
 printf(" do you want to search for? ");
 scanf("%1024s",pBuf);
}

variable_types:
pBuf
char *

user_defined_types: enum Field { FName=0, LName=1, Email=2 }


getNewContact

decompiled_code:
__int64 __fastcall getNewContact(__int64 a1, __int64 a2, __int64 a3)
{
printf("First Name: ");
_isoc99_scanf("%1024s", a1);
printf("Last Name: ");
_isoc99_scanf("%1024s", a2);
printf("Email: ");
return _isoc99_scanf("%1024s", a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
printf("First Name: ");
_isoc99_scanf("%1024s", a1);
printf("Last Name: ");
_isoc99_scanf("%1024s", a2);
printf("Email: ");
return _isoc99_scanf("%1024s", a3);
}

original_code:
void getNewContact(char* psFName, char* psLName, char* psEmail)
{
 printf("First Name: ");
 scanf("%1024s", psFName);
 printf("Last Name: ");
 scanf("%1024s", psLName);
 printf("Email: ");
 scanf("%1024s", psEmail);
}

canonical_original_code:
void getNewContact(char *psFName, char *psLName, char *psEmail)
{
 printf("First Name: ");
 scanf("%1024s", psFName);
 printf("Last Name: ");
 scanf("%1024s", psLName);
 printf("Email: ");
 scanf("%1024s", psEmail);
}

variable_types:
psFName
char *

variable_types:
psLName
char *

variable_types:
psEmail
char *


getFilename

decompiled_code:
__int64 __fastcall getFilename(__int64 a1)
{
printf("File Name: ");
return _isoc99_scanf("%1024s", a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
printf("File Name: ");
return _isoc99_scanf("%1024s", a1);
}

original_code:
void getFilename(char *psFilename)
{
 printf("File Name: ");
 scanf("%1024s", psFilename);
}

variable_types:
psFilename
char *


printMainMenu

decompiled_code:
int printMainMenu()
{
puts("\n");
puts("1. Print to screen");
puts("2. Search");
puts("3. Add Contact");
puts("4. Delete Contact");
puts("5. Write to file");
puts("6. Quit");
return putchar(10);
}

canonical_decompiled_code:
int func4()
{
puts("\n");
puts("1. Print to screen");
puts("2. Search");
puts("3. Add Contact");
puts("4. Delete Contact");
puts("5. Write to file");
puts("6. Quit");
return putchar(10);
}

original_code:
void printMainMenu()
{
 printf("\n\n");
 printf("1. Print to screen\n");
 printf("2. Search\n");
 printf("3. Add Contact\n");
 printf("4. Delete Contact\n");
 printf("5. Write to file\n");
 printf("6. Quit\n");
 printf("\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // er12
int v5; // eax
unsigned int v6; // er12
int v7; // eax
int v8; // [rsp+4h] [rbp-2414h] BYREF
char v9[8]; // [rsp+8h] [rbp-2410h] BYREF
char v10[1024]; // [rsp+10h] [rbp-2408h] BYREF
char v11[1024]; // [rsp+410h] [rbp-2008h] BYREF
char v12[1024]; // [rsp+810h] [rbp-1C08h] BYREF
char v13[1024]; // [rsp+C10h] [rbp-1808h] BYREF
char v14[1024]; // [rsp+1010h] [rbp-1408h] BYREF
char v15[4104]; // [rsp+1410h] [rbp-1008h] BYREF

edInitData(v9, argv, envp);
edReadData(v9, "data/contacts.txt");
while ( 1 )
{
do
{
LABEL_2:
printMainMenu();
_isoc99_scanf("%d", &v8);
}
while ( (unsigned int)(v8 - 1) > 5 );
switch ( v8 )
{
case 2:
v6 = getField();
getString((__int64)v10, v6);
v7 = edSearchData(v9, v10, v6, v15, 1024LL);
if ( v7 <= 0 )
goto LABEL_12;
edPrintContactToStdout(v9, (unsigned int)v7);
break;
case 3:
getNewContact((__int64)v11, (__int64)v12, (__int64)v13);
edAddContact(v9, v11, v12, v13);
goto LABEL_2;
case 4:
v4 = getField();
getString((__int64)v10, v4);
v5 = edSearchData(v9, v10, v4, v15, 1024LL);
if ( v5 <= 0 )
LABEL_12:
puts("Not Found.");
else
edDeleteContact(v9, (unsigned int)v5);
break;
case 5:
getFilename((__int64)v14);
edWriteData(v9, v14);
break;
case 6:
edDeleteData(v9);
return 0;
default:
edPrintEachContactToStdout(v9);
break;
}
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // er12
int v5; // eax
unsigned int v6; // er12
int v7; // eax
int v8; // [rsp+4h] [rbp-2414h] BYREF
char v9[8]; // [rsp+8h] [rbp-2410h] BYREF
char v10[1024]; // [rsp+10h] [rbp-2408h] BYREF
char v11[1024]; // [rsp+410h] [rbp-2008h] BYREF
char v12[1024]; // [rsp+810h] [rbp-1C08h] BYREF
char v13[1024]; // [rsp+C10h] [rbp-1808h] BYREF
char v14[1024]; // [rsp+1010h] [rbp-1408h] BYREF
char v15[4104]; // [rsp+1410h] [rbp-1008h] BYREF

edInitData(v9, argv, envp);
edReadData(v9, "data/contacts.txt");
while ( 1 )
{
do
{
LABEL_2:
func4();
_isoc99_scanf("%d", &v8);
}
while ( (unsigned int)(v8 - 1) > 5 );
switch ( v8 )
{
case 2:
v6 = func0();
func1((__int64)v10, v6);
v7 = edSearchData(v9, v10, v6, v15, 1024LL);
if ( v7 <= 0 )
goto LABEL_12;
edPrintContactToStdout(v9, (unsigned int)v7);
break;
case 3:
func2((__int64)v11, (__int64)v12, (__int64)v13);
edAddContact(v9, v11, v12, v13);
goto LABEL_2;
case 4:
v4 = func0();
func1((__int64)v10, v4);
v5 = edSearchData(v9, v10, v4, v15, 1024LL);
if ( v5 <= 0 )
LABEL_12:
puts("Not Found.");
else
edDeleteContact(v9, (unsigned int)v5);
break;
case 5:
func3((__int64)v14);
edWriteData(v9, v14);
break;
case 6:
edDeleteData(v9);
return 0;
default:
edPrintEachContactToStdout(v9);
break;
}
}
}

original_code:
int main()
{
 EntryData allData;
 int choice;
 Field theField;
 char buffer[1024];
 char psFName[1024], psLName[1024], psEmail[1024];
 char psFilename[1024];
 int index;
 int continueLooping = 1;
 int pResults[1024];
 edInitData(&allData);
 edReadData(&allData,"data/contacts.txt");
 while(continueLooping)
 {
  do
  {
   printMainMenu();
   scanf("%d", &choice);
  }while( choice < 1 || choice > 6);
  switch(choice)
  {
   case 1:
    edPrintEachContactToStdout(&allData);
    break;
   case 2:
    theField = getField();
    getString(buffer, theField);
    index = edSearchData(&allData, buffer, theField, pResults, 1024);
    if( index > 0)
    {
     edPrintContactToStdout(&allData, index);
    }
    else
    {
     printf("Not Found.\n");
    }
    break;
   case 3:
    getNewContact(psFName, psLName, psEmail);
    edAddContact(&allData, psFName, psLName, psEmail);
    break;
   case 4:
    theField = getField();
    getString(buffer, theField);
    index = edSearchData(&allData, buffer, theField, pResults, 1024);
    if( index > 0)
    {
     edDeleteContact(&allData, index);
    }
    else
    {
     printf("Not Found.\n");
    }
    break;
   case 5:
    getFilename(psFilename);
    edWriteData(&allData, psFilename);
    break;
   case 6:
    continueLooping = 0;
    break;
   default:
    break;
  }
 }
 edDeleteData(&allData);
 return 0;
}

canonical_original_code:
int main()
{
 struct EntryData allData;
 int choice;
 enum Field theField;
 char buffer[1024];
 char psFName[1024]; char psLName[1024]; char psEmail[1024];
 char psFilename[1024];
 int index;
 int continueLooping = 1;
 int pResults[1024];
 edInitData(&allData);
 edReadData(&allData,"data/contacts.txt");
 while(continueLooping)
 {
  do
  {
   printMainMenu();
   scanf("%d", &choice);
  }while( choice < 1 || choice > 6);
  switch(choice)
  {
   case 1:
    edPrintEachContactToStdout(&allData);
    break;
   case 2:
    theField = getField();
    getString(buffer, theField);
    index = edSearchData(&allData, buffer, theField, pResults, 1024);
    if( index > 0)
    {
     edPrintContactToStdout(&allData, index);
    }
    else
    {
     printf("Not Found.\n");
    }
    break;
   case 3:
    getNewContact(psFName, psLName, psEmail);
    edAddContact(&allData, psFName, psLName, psEmail);
    break;
   case 4:
    theField = getField();
    getString(buffer, theField);
    index = edSearchData(&allData, buffer, theField, pResults, 1024);
    if( index > 0)
    {
     edDeleteContact(&allData, index);
    }
    else
    {
     printf("Not Found.\n");
    }
    break;
   case 5:
    getFilename(psFilename);
    edWriteData(&allData, psFilename);
    break;
   case 6:
    continueLooping = 0;
    break;
   default:
    break;
  }
 }
 edDeleteData(&allData);
 return 0;
}

variable_types: struct EntryData { struct ContactDataStore { struct ContactEntry { char *psFName; char *psLName; char *psEmail; } *pArray; int numberOfUsedContacts; int numberOfContacts; int current; } *pDataStore; }

variable_types: choice int

variable_types:
buffer
char [1024]

variable_types:
psFName
char [1024]

variable_types:
psLName
char [1024]

variable_types:
psEmail
char [1024]

variable_types:
psFilename
char [1024]

variable_types: index int

variable_types: continueLooping int

variable_types:
pResults
int [1024]

user_defined_types: struct EntryData { struct ContactDataStore *pDataStore; }

user_defined_types: struct ContactDataStore { struct ContactEntry *pArray; int numberOfUsedContacts; int numberOfContacts; int current; }


printerVisitor

decompiled_code:
__int64 __fastcall printerVisitor(const char **a1)
{
if ( a1 )
printf("%25s %25s: %25s\n", *a1, a1[1], a1[2]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
if ( a1 )
printf("%25s %25s: %25s\n", *a1, a1[1], a1[2]);
return 0LL;
}

original_code:
static void* printerVisitor(ContactEntry *pContact)
{
 if(((void *)0) == pContact)
 {
  return ((void *)0);
 }
 printf("%25s %25s: %25s\n",
   pContact->psFName, pContact->psLName, pContact->psEmail);
 return ((void *)0);
}

canonical_original_code:
static void *printerVisitor(struct ContactEntry *pContact)
{
 if(((void *)0) == pContact)
 {
  return ((void *)0);
 }
 printf("%25s %25s: %25s\n",
   pContact->psFName, pContact->psLName, pContact->psEmail);
 return ((void *)0);
}

variable_types: struct ContactEntry { char *psFName; char *psLName; char *psEmail; } *

return_type: void *


edInitData

decompiled_code:
__int64 __fastcall edInitData(_QWORD *a1)
{
void *v1; // rax

v1 = calloc(1uLL, 0x18uLL);
*a1 = v1;
return dsInit(v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
void *v1; // rax

v1 = calloc(1uLL, 0x18uLL);
*a1 = v1;
return dsInit(v1);
}

original_code:
int edInitData(EntryData *pData)
{
 pData->pDataStore = calloc(1, sizeof(ContactDataStore));
 return dsInit(pData->pDataStore);
}

canonical_original_code:
int edInitData(struct EntryData *pData)
{
 pData->pDataStore = calloc(1, sizeof(ContactDataStore));
 return dsInit(pData->pDataStore);
}

variable_types: struct EntryData { struct ContactDataStore { struct ContactEntry { char *psFName; char *psLName; char *psEmail; } *pArray; int numberOfUsedContacts; int numberOfContacts; int current; } *pDataStore; } *


edDeleteData

decompiled_code:
__int64 __fastcall edDeleteData(void **a1)
{
unsigned int v1; // er12

v1 = 0;
if ( a1 )
{
v1 = dsDelete(*a1);
free(*a1);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(void **a1)
{
unsigned int v1; // er12

v1 = 0;
if ( a1 )
{
v1 = dsDelete(*a1);
free(*a1);
}
return v1;
}

original_code:
int edDeleteData(EntryData *pData)
{
 int i;
 if( ((void *)0) == pData )
 {
  return ED_ERROR;
 }
 i = dsDelete(pData->pDataStore);
 free(pData->pDataStore);
 return i;
}

canonical_original_code:
int edDeleteData(struct EntryData *pData)
{
 int i;
 if( ((void *)0) == pData )
 {
  return ED_ERROR;
 }
 i = dsDelete(pData->pDataStore);
 free(pData->pDataStore);
 return i;
}

variable_types: i int

user_defined_types: struct ContactEntry { char *psFName; char *psLName; char *psEmail; }


edSortData

decompiled_code:
__int64 edSortData()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 1LL;
}

original_code:
int edSortData(EntryData *pData, Field sortType)
{
 return 1;
}

canonical_original_code:
int edSortData(struct EntryData *pData, enum Field sortType)
{
 return 1;
}

variable_types: enum Field { FName=0, LName=1, Email=2 }


edAddContact

decompiled_code:
__int64 __fastcall edAddContact(_QWORD *a1, const char *a2, const char *a3, const char *a4)
{
char *v6; // rax
__int64 v7; // rdi
void *ptr; // [rsp+0h] [rbp-38h] BYREF
void *v10; // [rsp+8h] [rbp-30h]
void *v11; // [rsp+10h] [rbp-28h]

if ( !a1 )
return 0LL;
if ( !a2 || !a3 || !a4 )
return 0LL;
v11 = strdup(a4);
ptr = strdup(a2);
v6 = strdup(a3);
v7 = *a1;
v10 = v6;
dsAddEntry(v7, &ptr);
free(ptr);
free(v10);
free(v11);
return dsGetNumberOfContacts(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, const char *a2, const char *a3, const char *a4)
{
char *v6; // rax
__int64 v7; // rdi
void *ptr; // [rsp+0h] [rbp-38h] BYREF
void *v10; // [rsp+8h] [rbp-30h]
void *v11; // [rsp+10h] [rbp-28h]

if ( !a1 )
return 0LL;
if ( !a2 || !a3 || !a4 )
return 0LL;
v11 = strdup(a4);
ptr = strdup(a2);
v6 = strdup(a3);
v7 = *a1;
v10 = v6;
dsAddEntry(v7, &ptr);
free(ptr);
free(v10);
free(v11);
return dsGetNumberOfContacts(*a1);
}

original_code:
int edAddContact(EntryData *pData, char *psFName, char *psLName, char *psEmail)
{
 ContactEntry entry;
 if( ((void *)0) == pData || ((void *)0) == psFName || ((void *)0) == psLName || ((void *)0) == psEmail )
 {
  return ED_ERROR;
 }
 entry.psEmail = strdup(psEmail);
 entry.psFName = strdup(psFName);
 entry.psLName = strdup(psLName);
 dsAddEntry(pData->pDataStore, &entry);
 free(entry.psFName);
 free(entry.psLName);
 free(entry.psEmail);
 return dsGetNumberOfContacts(pData->pDataStore);
}

canonical_original_code:
int edAddContact(struct EntryData *pData, char *psFName, char *psLName, char *psEmail)
{
 struct ContactEntry entry;
 if( ((void *)0) == pData || ((void *)0) == psFName || ((void *)0) == psLName || ((void *)0) == psEmail )
 {
  return ED_ERROR;
 }
 entry.psEmail = strdup(psEmail);
 entry.psFName = strdup(psFName);
 entry.psLName = strdup(psLName);
 dsAddEntry(pData->pDataStore, &entry);
 free(entry.psFName);
 free(entry.psLName);
 free(entry.psEmail);
 return dsGetNumberOfContacts(pData->pDataStore);
}

variable_types:
psFName
char *

variable_types:
psLName
char *

variable_types: struct ContactEntry { char *psFName; char *psLName; char *psEmail; }


edDeleteContact

decompiled_code:
__int64 __fastcall edDeleteContact(_QWORD *a1, int a2)
{
int v3; // er12
int v4; // eax
__int64 v5; // [rsp-38h] [rbp-38h] BYREF

if ( !a1 )
return 0LL;
if ( (int)dsGetNumberOfContacts(*a1) <= a2 )
return 0LL;
dsFirst(*a1);
if ( a2 > 0 )
{
v3 = 0;
do
{
++v3;
dsCurrent(*a1, &v5);
v4 = dsNext(*a1);
}
while ( a2 > v3 && v4 == 1 );
}
dsDeleteEntry(*a1);
return (unsigned int)a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, int a2)
{
int v3; // er12
int v4; // eax
__int64 v5; // [rsp-38h] [rbp-38h] BYREF

if ( !a1 )
return 0LL;
if ( (int)dsGetNumberOfContacts(*a1) <= a2 )
return 0LL;
dsFirst(*a1);
if ( a2 > 0 )
{
v3 = 0;
do
{
++v3;
dsCurrent(*a1, &v5);
v4 = dsNext(*a1);
}
while ( a2 > v3 && v4 == 1 );
}
dsDeleteEntry(*a1);
return (unsigned int)a2;
}

original_code:
int edDeleteContact(EntryData *pData, int index)
{
 int i;
 ContactEntry entry;
 int result=1;
 if( ((void *)0) == pData || index >= dsGetNumberOfContacts(pData->pDataStore))
 {
  return ED_ERROR;
 }
 dsFirst(pData->pDataStore);
 for( i=0; i< index && result == 1; i++)
 {
  dsCurrent(pData->pDataStore, &entry);
  result = dsNext(pData->pDataStore);
 }
 dsDeleteEntry(pData->pDataStore);
 return index;
}

canonical_original_code:
int edDeleteContact(struct EntryData *pData, int index)
{
 int i;
 struct ContactEntry entry;
 int result = 1;
 if( ((void *)0) == pData || index >= dsGetNumberOfContacts(pData->pDataStore))
 {
  return ED_ERROR;
 }
 dsFirst(pData->pDataStore);
 for( i=0; i< index && result == 1; i++)
 {
  dsCurrent(pData->pDataStore, &entry);
  result = dsNext(pData->pDataStore);
 }
 dsDeleteEntry(pData->pDataStore);
 return index;
}

variable_types: result int


edSearchData

decompiled_code:
__int64 edSearchData()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func8()
{
return 1LL;
}

original_code:
int edSearchData(EntryData *pData, char *psPattern, Field field, int *pResults, int maxResults)
{
 return 1;
}

canonical_original_code:
int edSearchData(struct EntryData *pData, char *psPattern, enum Field field, int *pResults, int maxResults)
{
 return 1;
}

variable_types:
psPattern
char *

variable_types:
pResults
int *

variable_types: maxResults int


edVisitEachContact

decompiled_code:
__int64 __fastcall edVisitEachContact(_QWORD *a1, void (__fastcall *a2)(_BYTE *))
{
__int64 result; // rax
_BYTE v3[56]; // [rsp-38h] [rbp-38h] BYREF

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
dsFirst(*a1);
do
{
dsCurrent(*a1, v3);
a2(v3);
}
while ( (unsigned int)dsNext(*a1) == 1 );
result = dsGetNumberOfContacts(*a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, void (__fastcall *a2)(_BYTE *))
{
__int64 result; // rax
_BYTE v3[56]; // [rsp-38h] [rbp-38h] BYREF

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
dsFirst(*a1);
do
{
dsCurrent(*a1, v3);
a2(v3);
}
while ( (unsigned int)dsNext(*a1) == 1 );
result = dsGetNumberOfContacts(*a1);
}
return result;
}

original_code:
int edVisitEachContact(EntryData *pData, VisitFunction func)
{
 int result = 1;
 ContactEntry entry;
 if (((void *)0) == pData || ((void *)0) == func)
 {
  return ED_ERROR;
 }
 dsFirst(pData->pDataStore);
 while(1 == result)
 {
  dsCurrent(pData->pDataStore, &entry);
  func(&(entry));
  result = dsNext(pData->pDataStore);
 }
 return dsGetNumberOfContacts(pData->pDataStore);
}

canonical_original_code:
int edVisitEachContact(struct EntryData *pData, void *(*func)(struct ContactEntry *))
{
 int result = 1;
 struct ContactEntry entry;
 if (((void *)0) == pData || ((void *)0) == func)
 {
  return ED_ERROR;
 }
 dsFirst(pData->pDataStore);
 while(1 == result)
 {
  dsCurrent(pData->pDataStore, &entry);
  func(&(entry));
  result = dsNext(pData->pDataStore);
 }
 return dsGetNumberOfContacts(pData->pDataStore);
}

variable_types:
func
void *(*)(struct ContactEntry *)


edPrintContactToStdout

decompiled_code:
__int64 __fastcall edPrintContactToStdout(_QWORD *a1, unsigned int a2)
{
const char *v3[5]; // [rsp+0h] [rbp-28h] BYREF

dsGetEntry(*a1, v3, a2);
printerVisitor(v3);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, unsigned int a2)
{
const char *v3[5]; // [rsp+0h] [rbp-28h] BYREF

dsGetEntry(*a1, v3, a2);
func0(v3);
return a2;
}

original_code:
int edPrintContactToStdout(EntryData *pData, int index)
{
 ContactEntry entry;
 dsGetEntry(pData->pDataStore, &entry, index);
 printerVisitor(&(entry));
 return index;
}

canonical_original_code:
int edPrintContactToStdout(struct EntryData *pData, int index)
{
 struct ContactEntry entry;
 dsGetEntry(pData->pDataStore, &entry, index);
 printerVisitor(&(entry));
 return index;
}


edPrintEachContactToStdout

decompiled_code:
__int64 __fastcall edPrintEachContactToStdout(_QWORD *a1)
{
if ( !a1 )
return 0LL;
edVisitEachContact(a1, (void (__fastcall *)(_BYTE *))printerVisitor);
return dsGetNumberOfContacts(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1)
{
if ( !a1 )
return 0LL;
func9(a1, (void (__fastcall *)(_BYTE *))printerVisitor);
return dsGetNumberOfContacts(*a1);
}

original_code:
int edPrintEachContactToStdout(EntryData *pData)
{
 if (((void *)0) == pData )
 {
  return ED_ERROR;
 }
 edVisitEachContact(pData, printerVisitor);
 return dsGetNumberOfContacts(pData->pDataStore);
}

canonical_original_code:
int edPrintEachContactToStdout(struct EntryData *pData)
{
 if (((void *)0) == pData )
 {
  return ED_ERROR;
 }
 edVisitEachContact(pData, printerVisitor);
 return dsGetNumberOfContacts(pData->pDataStore);
}


main

repo: chalkos/ProjetoSO

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
int v4; // eax
const char *v5; // rdi

if ( argc != 3 )
printErrorAndExit(&unk_28, "main.c", 12LL);
MAXCOM = 50;
v3 = getenv("MAXCOM");
if ( !v3 )
printErrorAndExit(&unk_70, "main.c", 21LL);
v4 = atoi(v3);
MAXCOM = v4;
if ( v4 <= 0 )
{
printErrorAndExit("MAXCOM tem de ser superior a 0.", "main.c", 26LL);
v4 = MAXCOM;
}
gestor = myMalloc(28LL * v4);
signal(17, (__sighandler_t)&filhoMorreu);
v5 = argv[1];
zombieFound = 0;
map(v5);
reduce(argv[2]);
return 0;
}

original_code:
int main(int argc, char** argv) {
    if(argc != 3)
        printErrorAndExit("A aplicação deve receber exactamente dois argumentos: map e reduce", "main.c", 12);
    MAXCOM = 50;
    char* env;
    env = getenv("MAXCOM");
    if( env == ((void *)0) )
        printErrorAndExit("Variável de ambiente MAXCOM não está definida", "main.c", 21);
    MAXCOM = atoi(env);
    if( MAXCOM < 1 )
        printErrorAndExit("MAXCOM tem de ser superior a 0.", "main.c", 26);
    gestor = myMalloc(sizeof(Gestor) * MAXCOM);
    signal(17, filhoMorreu);
    zombieFound = 0;
    map(argv[1]);
    reduce(argv[2]);
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    if(argc != 3)
        printErrorAndExit("A aplicação deve receber exactamente dois argumentos: map e reduce", "main.c", 12);
    MAXCOM = 50;
    char *env;
    env = getenv("MAXCOM");
    if( env == ((void *)0) )
        printErrorAndExit("Variável de ambiente MAXCOM não está definida", "main.c", 21);
    MAXCOM = atoi(env);
    if( MAXCOM < 1 )
        printErrorAndExit("MAXCOM tem de ser superior a 0.", "main.c", 26);
    gestor = myMalloc(sizeof(Gestor) * MAXCOM);
    signal(17, filhoMorreu);
    zombieFound = 0;
    map(argv[1]);
    reduce(argv[2]);
    return (0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
env
char *


listaPush

decompiled_code:
char *__fastcall listaPush(int a1, const char *a2)
{
char **v2; // rbp
size_t v3; // rax
char *v4; // rax
__int64 v5; // rdi
char *result; // rax

v2 = (char **)myMalloc(16LL);
v3 = strlen(a2);
v4 = (char *)myMalloc(v3 + 1);
*v2 = v4;
strcpy(v4, a2);
v5 = listas + 32LL * a1;
result = *(char **)(v5 + 8);
v2[1] = result;
++*(_DWORD *)(v5 + 24);
*(_QWORD *)(v5 + 8) = v2;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(int a1, const char *a2)
{
char **v2; // rbp
size_t v3; // rax
char *v4; // rax
__int64 v5; // rdi
char *result; // rax

v2 = (char **)myMalloc(16LL);
v3 = strlen(a2);
v4 = (char *)myMalloc(v3 + 1);
*v2 = v4;
strcpy(v4, a2);
v5 = listas + 32LL * a1;
result = *(char **)(v5 + 8);
v2[1] = result;
++*(_DWORD *)(v5 + 24);
*(_QWORD *)(v5 + 8) = v2;
return result;
}

original_code:
void listaPush( int indice, char *valor ){
    Elem *elem = (Elem*)myMalloc(sizeof(Elem));
    elem->valor = (char*)myMalloc(sizeof(char) * (strlen(valor)+1));
    strcpy(elem->valor, valor);
    elem->proximo = listas[indice].valores;
    listas[indice].valores = elem;
    listas[indice].nElems++;
}

canonical_original_code:
void listaPush(int indice, char *valor){
    struct sElem *elem = (Elem*)myMalloc(sizeof(Elem));
    elem->valor = (char *)myMalloc(sizeof(char) * (strlen(valor)+1));
    strcpy(elem->valor, valor);
    elem->proximo = listas[indice].valores;
    listas[indice].valores = elem;
    listas[indice].nElems++;
}

variable_types: indice int

variable_types:
valor
char *

variable_types: struct sElem { char *valor; struct sElem *proximo; } *


listaPop

decompiled_code:
__int64 __fastcall listaPop(int a1)
{
__int64 v1; // rbx
__int64 *v2; // rdi
__int64 v3; // r12
__int64 result; // rax

v1 = 32LL * a1;
v2 = *(__int64 **)(v1 + listas + 8);
if ( !v2 )
return 0LL;
v3 = *v2;
*(_QWORD *)(v1 + listas + 8) = v2[1];
free(v2);
result = v3;
--*(_DWORD *)(listas + v1 + 24);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rbx
__int64 *v2; // rdi
__int64 v3; // r12
__int64 result; // rax

v1 = 32LL * a1;
v2 = *(__int64 **)(v1 + listas + 8);
if ( !v2 )
return 0LL;
v3 = *v2;
*(_QWORD *)(v1 + listas + 8) = v2[1];
free(v2);
result = v3;
--*(_DWORD *)(listas + v1 + 24);
return result;
}

original_code:
char *listaPop( int indice ){
    Elem *elem = listas[indice].valores;
    if(elem == ((void *)0))
        return ((void *)0);
    char *valor = elem->valor;
    listas[indice].valores = elem->proximo;
    free(elem);
    listas[indice].nElems--;
    return valor;
}

canonical_original_code:
char *listaPop(int indice){
    struct sElem *elem = listas[indice].valores;
    if(elem == ((void *)0))
        return ((void *)0);
    char *valor = elem->valor;
    listas[indice].valores = elem->proximo;
    free(elem);
    listas[indice].nElems--;
    return valor;
}

return_type: char *

user_defined_types: struct sElem { char *valor; struct sElem *proximo; }


listaAumenta

decompiled_code:
_QWORD *listaAumenta()
{
__int64 v0; // rdx
_QWORD *result; // rax
_QWORD *v2; // rdx

nListas += 20;
listas = myRealloc(listas, 32LL * nListas);
v0 = 32LL * nListas;
result = (_QWORD *)(listas + v0 - 640);
v2 = (_QWORD *)(listas + v0);
do
{
*result = 0LL;
result += 4;
*((_DWORD *)result - 2) = 0;
*(result - 3) = 0LL;
*(result - 2) = 0LL;
}
while ( result != v2 );
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
__int64 v0; // rdx
_QWORD *result; // rax
_QWORD *v2; // rdx

nListas += 20;
listas = myRealloc(listas, 32LL * nListas);
v0 = 32LL * nListas;
result = (_QWORD *)(listas + v0 - 640);
v2 = (_QWORD *)(listas + v0);
do
{
*result = 0LL;
result += 4;
*((_DWORD *)result - 2) = 0;
*(result - 3) = 0LL;
*(result - 2) = 0LL;
}
while ( result != v2 );
return result;
}

original_code:
void listaAumenta(){
    nListas += tamanhoIncremento;
    listas = (Lista*)myRealloc(listas, sizeof(Lista) * nListas);
    int i;
    for( i= nListas-tamanhoIncremento; i<nListas; i++){
        listas[i].chave = ((void *)0);
        listas[i].nElems = 0;
        listas[i].valores = ((void *)0);
        listas[i].reduced = ((void *)0);
    }
}

canonical_original_code:
void listaAumenta(){
    nListas += tamanhoIncremento;
    listas = (struct sLista *)myRealloc(listas, sizeof(Lista) * nListas);
    int i;
    for( i= nListas-tamanhoIncremento; i<nListas; i++){
        listas[i].chave = ((void *)0);
        listas[i].nElems = 0;
        listas[i].valores = ((void *)0);
        listas[i].reduced = ((void *)0);
    }
}

user_defined_types: struct sLista { char *chave; struct sElem *valores; char *reduced; int nElems; }


listaInsere

decompiled_code:
char *__fastcall listaInsere(char *s2, const char *a2)
{
__int64 v2; // r12
_QWORD *v3; // r14
int v4; // ebp
const char **v5; // rbx
__int64 v6; // rbx
size_t v7; // rax
size_t v9; // rax
__int64 v10; // r12

v2 = nListas;
if ( nListas <= 0 )
{
LABEL_10:
listaAumenta();
v4 = nListas - 20;
v9 = strlen(s2);
v10 = listas;
*(_QWORD *)(32LL * v4 + v10) = myMalloc(v9 + 1);
strcpy(*(char **)(listas + 32LL * v4), s2);
}
else
{
v3 = (_QWORD *)listas;
v4 = 0;
v5 = (const char **)listas;
while ( !*v5 || strcmp(*v5, s2) )
{
++v4;
v5 += 4;
if ( (_DWORD)v2 == v4 )
{
v6 = 0LL;
while ( *v3 )
{
++v6;
v3 += 4;
if ( v6 == v2 )
goto LABEL_10;
}
v7 = strlen(s2);
*v3 = myMalloc(v7 + 1);
strcpy(*(char **)(listas + 32 * v6), s2);
return listaPush(v6, a2);
}
}
}
return listaPush(v4, a2);
}

canonical_decompiled_code:
char *__fastcall func3(char *s2, const char *a2)
{
__int64 v2; // r12
_QWORD *v3; // r14
int v4; // ebp
const char **v5; // rbx
__int64 v6; // rbx
size_t v7; // rax
size_t v9; // rax
__int64 v10; // r12

v2 = nListas;
if ( nListas <= 0 )
{
LABEL_10:
func2();
v4 = nListas - 20;
v9 = strlen(s2);
v10 = listas;
*(_QWORD *)(32LL * v4 + v10) = myMalloc(v9 + 1);
strcpy(*(char **)(listas + 32LL * v4), s2);
}
else
{
v3 = (_QWORD *)listas;
v4 = 0;
v5 = (const char **)listas;
while ( !*v5 || strcmp(*v5, s2) )
{
++v4;
v5 += 4;
if ( (_DWORD)v2 == v4 )
{
v6 = 0LL;
while ( *v3 )
{
++v6;
v3 += 4;
if ( v6 == v2 )
goto LABEL_10;
}
v7 = strlen(s2);
*v3 = myMalloc(v7 + 1);
strcpy(*(char **)(listas + 32 * v6), s2);
return func0(v6, a2);
}
}
}
return func0(v4, a2);
}

original_code:
void listaInsere(char *chave, char *valor){
    int i;
    for( i=0; i<nListas; i++ ){
        if( listas[i].chave != ((void *)0) && strcmp(listas[i].chave, chave) == 0 ){
            listaPush(i, valor);
            return;
        }
    }
    for( i=0; i<nListas; i++ ){
        if( listas[i].chave == ((void *)0) ){
            listas[i].chave = (char*)myMalloc(sizeof(char) * (strlen(chave)+1));
            strcpy(listas[i].chave, chave);
            listaPush(i, valor);
            return;
        }
    }
    listaAumenta();
    i = nListas - tamanhoIncremento;
    listas[i].chave = (char*)myMalloc(sizeof(char) * (strlen(chave)+1));
    strcpy(listas[i].chave, chave);
    listaPush(i, valor);
    return;
}

canonical_original_code:
void listaInsere(char *chave, char *valor){
    int i;
    for( i=0; i<nListas; i++ ){
        if( listas[i].chave != ((void *)0) && strcmp(listas[i].chave, chave) == 0 ){
            listaPush(i, valor);
            return;
        }
    }
    for( i=0; i<nListas; i++ ){
        if( listas[i].chave == ((void *)0) ){
            listas[i].chave = (char *)myMalloc(sizeof(char) * (strlen(chave)+1));
            strcpy(listas[i].chave, chave);
            listaPush(i, valor);
            return;
        }
    }
    listaAumenta();
    i = nListas - tamanhoIncremento;
    listas[i].chave = (char *)myMalloc(sizeof(char) * (strlen(chave)+1));
    strcpy(listas[i].chave, chave);
    listaPush(i, valor);
    return;
}

variable_types:
chave
char *


listaInit

decompiled_code:
_QWORD *listaInit()
{
_QWORD *result; // rax
_QWORD *v1; // rdx

result = (_QWORD *)myMalloc(1600LL);
listas = (__int64)result;
v1 = result + 200;
do
{
*result = 0LL;
result += 4;
*((_DWORD *)result - 2) = 0;
*(result - 3) = 0LL;
*(result - 2) = 0LL;
}
while ( result != v1 );
nListas = 50;
return result;
}

canonical_decompiled_code:
_QWORD *func4()
{
_QWORD *result; // rax
_QWORD *v1; // rdx

result = (_QWORD *)myMalloc(1600LL);
listas = (__int64)result;
v1 = result + 200;
do
{
*result = 0LL;
result += 4;
*((_DWORD *)result - 2) = 0;
*(result - 3) = 0LL;
*(result - 2) = 0LL;
}
while ( result != v1 );
nListas = 50;
return result;
}

original_code:
void listaInit(){
    listas = (Lista*)myMalloc(sizeof(Lista) * tamanhoInicial);
    int i;
    for( i=0; i<tamanhoInicial; i++){
        listas[i].chave = ((void *)0);
        listas[i].nElems = 0;
        listas[i].valores = ((void *)0);
        listas[i].reduced = ((void *)0);
    }
    nListas = tamanhoInicial;
}

canonical_original_code:
void listaInit(){
    listas = (struct sLista *)myMalloc(sizeof(Lista) * tamanhoInicial);
    int i;
    for( i=0; i<tamanhoInicial; i++){
        listas[i].chave = ((void *)0);
        listas[i].nElems = 0;
        listas[i].valores = ((void *)0);
        listas[i].reduced = ((void *)0);
    }
    nListas = tamanhoInicial;
}

variable_types: i int


listaPrintKeyValues

decompiled_code:
int listaPrintKeyValues()
{
int result; // eax
__int64 v1; // rbp
__int64 i; // rbx

result = nListas;
if ( nListas > 0 )
{
v1 = 0LL;
do
{
printf(
"[%d] chave: %s (#elems: %d)\n",
(unsigned int)v1,
*(const char **)(32 * v1 + listas),
*(unsigned int *)(32 * v1 + listas + 24));
result = listas;
for ( i = *(_QWORD *)(listas + 32 * v1 + 8); i; i = *(_QWORD *)(i + 8) )
result = printf(" valor: %s\n", *(const char **)i);
++v1;
}
while ( nListas > (int)v1 );
}
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax
__int64 v1; // rbp
__int64 i; // rbx

result = nListas;
if ( nListas > 0 )
{
v1 = 0LL;
do
{
printf(
"[%d] chave: %s (#elems: %d)\n",
(unsigned int)v1,
*(const char **)(32 * v1 + listas),
*(unsigned int *)(32 * v1 + listas + 24));
result = listas;
for ( i = *(_QWORD *)(listas + 32 * v1 + 8); i; i = *(_QWORD *)(i + 8) )
result = printf(" valor: %s\n", *(const char **)i);
++v1;
}
while ( nListas > (int)v1 );
}
return result;
}

original_code:
void listaPrintKeyValues(){
    Elem *elem;
    int i;
    for(i=0; i<nListas; i++){
        printf("[%d] chave: %s (#elems: %d)\n", i, listas[i].chave, listas[i].nElems);
        elem = listas[i].valores;
        while( elem != ((void *)0) ){
            printf("    valor: %s\n", elem->valor);
            elem = elem->proximo;
        }
    }
}

canonical_original_code:
void listaPrintKeyValues(){
    struct sElem *elem;
    int i;
    for(i=0; i<nListas; i++){
        printf("[%d] chave: %s (#elems: %d)\n", i, listas[i].chave, listas[i].nElems);
        elem = listas[i].valores;
        while( elem != ((void *)0) ){
            printf("    valor: %s\n", elem->valor);
            elem = elem->proximo;
        }
    }
}


listaPrintKeyReduced

decompiled_code:
ssize_t listaPrintKeyReduced()
{
ssize_t result; // rax
__int64 v1; // rbx
const char *v2; // r12
size_t v3; // rax
const char *v4; // rbp
size_t v5; // rax
__int64 v6; // rbp

result = (unsigned int)nListas;
if ( nListas > 0 )
{
v1 = 0LL;
do
{
v6 = 32 * v1;
result = 32 * v1 + listas;
if ( !*(_QWORD *)(result + 16) )
break;
v2 = *(const char **)result;
++v1;
v3 = strlen(*(const char **)result);
write(1, v2, v3);
write(1, " ", 1uLL);
v4 = *(const char **)(listas + v6 + 16);
v5 = strlen(v4);
write(1, v4, v5);
result = write(1, "\n", 1uLL);
}
while ( nListas > (int)v1 );
}
return result;
}

canonical_decompiled_code:
ssize_t func6()
{
ssize_t result; // rax
__int64 v1; // rbx
const char *v2; // r12
size_t v3; // rax
const char *v4; // rbp
size_t v5; // rax
__int64 v6; // rbp

result = (unsigned int)nListas;
if ( nListas > 0 )
{
v1 = 0LL;
do
{
v6 = 32 * v1;
result = 32 * v1 + listas;
if ( !*(_QWORD *)(result + 16) )
break;
v2 = *(const char **)result;
++v1;
v3 = strlen(*(const char **)result);
write(1, v2, v3);
write(1, " ", 1uLL);
v4 = *(const char **)(listas + v6 + 16);
v5 = strlen(v4);
write(1, v4, v5);
result = write(1, "\n", 1uLL);
}
while ( nListas > (int)v1 );
}
return result;
}

original_code:
void listaPrintKeyReduced(){
    int i;
    for(i=0; i<nListas; i++){
        if( listas[i].reduced == ((void *)0) )
            break;
        write(1,listas[i].chave,strlen(listas[i].chave));
        write(1," ", 1);
        write(1,listas[i].reduced, strlen(listas[i].reduced));
        write(1,"\n",1);
    }
}


listaDumpValues

decompiled_code:
void __fastcall listaDumpValues(int a1, int a2)
{
__int64 i; // rbx
const char *v3; // rbp
size_t v4; // rax

for ( i = *(_QWORD *)(listas + 32LL * a1 + 8); i; i = *(_QWORD *)(i + 8) )
{
v3 = *(const char **)i;
v4 = strlen(*(const char **)i);
write(a2, v3, v4);
write(a2, "\n", 1uLL);
}
}

canonical_decompiled_code:
void __fastcall func7(int a1, int a2)
{
__int64 i; // rbx
const char *v3; // rbp
size_t v4; // rax

for ( i = *(_QWORD *)(listas + 32LL * a1 + 8); i; i = *(_QWORD *)(i + 8) )
{
v3 = *(const char **)i;
v4 = strlen(*(const char **)i);
write(a2, v3, v4);
write(a2, "\n", 1uLL);
}
}

original_code:
void listaDumpValues(int indice, int fd){
    Elem *elem;
    elem = listas[indice].valores;
    while( elem != ((void *)0) ){
        write(fd, elem->valor, strlen(elem->valor));
        write(fd, "\n", 1);
        elem = elem->proximo;
    }
}

canonical_original_code:
void listaDumpValues(int indice, int fd){
    struct sElem *elem;
    elem = listas[indice].valores;
    while( elem != ((void *)0) ){
        write(fd, elem->valor, strlen(elem->valor));
        write(fd, "\n", 1);
        elem = elem->proximo;
    }
}

variable_types: fd int


listaReduced

decompiled_code:
char *__fastcall listaReduced(int a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // r14
size_t v4; // rax
__int64 v5; // r14
int v6; // er13
__int64 v7; // r15
int v8; // ebp
char *v9; // rdi

v2 = 32LL * a1;
v3 = listas;
v4 = strlen(a2);
v5 = v2 + v3;
v6 = v4;
v7 = *(_QWORD *)(v5 + 16);
if ( v7 )
{
v8 = strlen(*(const char **)(v5 + 16));
*(_QWORD *)(v5 + 16) = myRealloc(v7, v6 + v8 + 1);
v9 = (char *)(*(_QWORD *)(listas + v2 + 16) + v8);
}
else
{
*(_QWORD *)(v5 + 16) = myMalloc(v4 + 1);
v9 = *(char **)(listas + v2 + 16);
}
return strcpy(v9, a2);
}

original_code:
void listaReduced(int indice, char *reducedValue){
    if( listas[indice].reduced == ((void *)0) ){
        listas[indice].reduced = (char*)myMalloc(sizeof(char) * (strlen(reducedValue)+1));
        strcpy(listas[indice].reduced, reducedValue);
    }else{
        int comprimento = strlen(listas[indice].reduced);
        int incremento = strlen(reducedValue)+1;
        listas[indice].reduced = myRealloc( listas[indice].reduced, comprimento + incremento );
        strcpy(listas[indice].reduced + comprimento, reducedValue);
    }
}

canonical_original_code:
void listaReduced(int indice, char *reducedValue){
    if( listas[indice].reduced == ((void *)0) ){
        listas[indice].reduced = (char *)myMalloc(sizeof(char) * (strlen(reducedValue)+1));
        strcpy(listas[indice].reduced, reducedValue);
    }else{
        int comprimento = strlen(listas[indice].reduced);
        int incremento = strlen(reducedValue)+1;
        listas[indice].reduced = myRealloc( listas[indice].reduced, comprimento + incremento );
        strcpy(listas[indice].reduced + comprimento, reducedValue);
    }
}

variable_types:
reducedValue
char *

variable_types: comprimento int

variable_types: incremento int


listaCount

decompiled_code:
__int64 listaCount()
{
unsigned int v0; // er8
int v1; // eax
__int64 v2; // rdx
__int64 v3; // rdx

v0 = nListas;
v1 = nListas - 1;
v2 = 32LL * (nListas - 1);
if ( !*(_QWORD *)(listas + v2) )
{
v3 = listas + v2 + 32;
do
{
v3 -= 32LL;
v0 = v1--;
}
while ( !*(_QWORD *)(v3 - 32) );
}
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // er8
int v1; // eax
__int64 v2; // rdx
__int64 v3; // rdx

v0 = nListas;
v1 = nListas - 1;
v2 = 32LL * (nListas - 1);
if ( !*(_QWORD *)(listas + v2) )
{
v3 = listas + v2 + 32;
do
{
v3 -= 32LL;
v0 = v1--;
}
while ( !*(_QWORD *)(v3 - 32) );
}
return v0;
}

original_code:
int listaCount(){
    int i = nListas-1;
    while( listas[i].chave == ((void *)0) )
        i--;
    return i+1;
}