decompiled_code:
__int64 __fastcall my_getopt(int a1, const char **a2, const char *a3)
{
__int64 v3; // r13
unsigned int v4; // ebx
char *v5; // rax
const char *v7; // rax
char v8; // al
int v9; // eax

optarg = 0LL;
if ( !rem_0 )
{
if ( optind >= a1 )
return (unsigned int)-1;
v7 = a2[optind];
if ( *v7 != 45 )
return (unsigned int)-1;
rem_0 = (__int64)(v7 + 1);
v8 = v7[1];
if ( !v8 )
return (unsigned int)-1;
if ( v8 == 45 )
{
++optind;
return (unsigned int)-1;
}
}
v3 = rem_0;
v4 = *(char *)rem_0;
v5 = strchr(a3, v4);
if ( !v5 || v4 == 58 )
{
fprintf(stderr, "%s: illegal option -- %c\n", *a2, v4);
++rem_0;
v4 = 63;
}
else
{
if ( v5[1] == 58 )
{
if ( *(_BYTE *)(v3 + 1) )
{
optarg = v3 + 1;
}
else
{
v9 = optind + 1;
optind = v9;
if ( v9 >= a1 )
{
fprintf(stderr, "Missing argument after -%c\n", v4);
exit(1);
}
optarg = (__int64)a2[v9];
}
goto LABEL_7;
}
rem_0 = v3 + 1;
}
if ( !*(_BYTE *)rem_0 )
{
LABEL_7:
rem_0 = 0LL;
++optind;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, const char **a2, const char *a3)
{
__int64 v3; // r13
unsigned int v4; // ebx
char *v5; // rax
const char *v7; // rax
char v8; // al
int v9; // eax

optarg = 0LL;
if ( !rem_0 )
{
if ( optind >= a1 )
return (unsigned int)-1;
v7 = a2[optind];
if ( *v7 != 45 )
return (unsigned int)-1;
rem_0 = (__int64)(v7 + 1);
v8 = v7[1];
if ( !v8 )
return (unsigned int)-1;
if ( v8 == 45 )
{
++optind;
return (unsigned int)-1;
}
}
v3 = rem_0;
v4 = *(char *)rem_0;
v5 = strchr(a3, v4);
if ( !v5 || v4 == 58 )
{
fprintf(stderr, "%s: illegal option -- %c\n", *a2, v4);
++rem_0;
v4 = 63;
}
else
{
if ( v5[1] == 58 )
{
if ( *(_BYTE *)(v3 + 1) )
{
optarg = v3 + 1;
}
else
{
v9 = optind + 1;
optind = v9;
if ( v9 >= a1 )
{
fprintf(stderr, "Missing argument after -%c\n", v4);
exit(1);
}
optarg = (__int64)a2[v9];
}
goto LABEL_7;
}
rem_0 = v3 + 1;
}
if ( !*(_BYTE *)rem_0 )
{
LABEL_7:
rem_0 = 0LL;
++optind;
}
return v4;
}

original_code:
int my_getopt(int argc, char **argv, char *optstring)
{
    char *q;
    static char *rem = ((void *)0);
    int c;
    int needarg = 0;
    optarg = ((void *)0);
    if (!rem) {
        if (optind < argc && argv[optind][0] == '-') {
            rem = argv[optind] + 1;
            if (*rem == 0)
                return (-1);
            if (*rem == '-') {
                optind++;
                return (-1);
            }
        } else
            return (-1);
    }
    c = *rem;
    q = strchr(optstring, c);
    if (q && c != ':') {
        needarg = (q[1] == ':');
        if (needarg) {
            if (rem[1] != 0)
                optarg = rem + 1;
            else {
                optind++;
                if (optind < argc)
                    optarg = argv[optind];
                else {
                    fprintf(stderr, "Missing argument after -%c\n", c);
                    exit(1);
                }
            }
        } else
            rem++;
    } else {
        fprintf(stderr, "%s: illegal option -- %c\n", argv[0], c);
        c = '?';
        rem++;
    }
    if (needarg || *rem == 0) {
        rem = ((void *)0);
        optind++;
    }
    return c;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
optstring
char *

variable_types:
q
char *

variable_types:
rem
char *

variable_types: c int

variable_types: needarg int


processOpts

repo: gmangal/MIPS-Disassembler

original_code:
int
processOpts(int argc, char *argv[], int *rFormat, int *iFormat, int *jFormat)
{
    struct option longopts[] =
    {
        {"usage", 0, ((void *)0), 'u'},
        {"Rformat", 0, ((void *)0), 'r'},
        {"Iformat", 0, ((void *)0), 'i'},
        {"Jformat", 0, ((void *)0), 'j'},
        {"all", 0, ((void *)0), 'a'},
        {((void *)0), 0, ((void *)0), 0 }
    };
    char *progName = argv[0];
    *rFormat = 0;
    *iFormat = 0;
    *jFormat = 0;
    int ch;
    while ((ch = getopt_long(argc, argv, "rija", longopts, ((void *)0))) != -1)
    {
        switch(ch)
        {
            case 'u':
                usage(argv[0], stdout);
            case 'r':
                *rFormat = 1;
                break;
            case 'i':
                *iFormat = 1;
                break;
            case 'j':
                *jFormat = 1;
                break;
            case 'a':
                *rFormat = 1;
                *iFormat = 1;
                *jFormat = 1;
                break;
            case '?':
            default:
                usage(progName, stderr);
                break;
        }
    }
    return optind;
}

variable_types:
argv
char *[]

variable_types:
rFormat
int *

variable_types:
iFormat
int *

variable_types:
jFormat
int *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types:
progName
char *

variable_types: ch int

return_type: int


rType

decompiled_code:
int __fastcall rType(unsigned int a1, unsigned int a2)
{
int result; // eax
char v3[6]; // [rsp+Eh] [rbp-2Ah] BYREF
char v4[6]; // [rsp+14h] [rbp-24h] BYREF
char v5[30]; // [rsp+1Ah] [rbp-1Eh] BYREF

printf("0x%08X ", a1);
getRegister((a2 >> 21) & 0x1F, v5);
getRegister(HIWORD(a2) & 0x1F, v4);
result = getRegister((unsigned __int16)a2 >> 11, v3);
switch ( a2 & 0x3F )
{
case 0u:
result = printf("%-8s %s, %s, %u\n", "sll", v3, v4, (a2 >> 6) & 0x1F);
break;
case 2u:
result = printf("%-8s %s, %s, %u\n", "srl", v3, v4, (a2 >> 6) & 0x1F);
break;
case 3u:
result = printf("%-8s %s, %s, %u\n", "sra", v3, v4, (a2 >> 6) & 0x1F);
break;
case 8u:
result = printf("%-8s %s\n", "jr", v5);
break;
case 0xCu:
result = printf("%-8s \n", "syscall");
break;
case 0x20u:
result = printf("%-8s %s, %s, %s\n", "add", v3, v5, v4);
break;
case 0x21u:
result = printf("%-8s %s, %s, %s\n", "addu", v3, v5, v4);
break;
case 0x22u:
result = printf("%-8s %s, %s, %s\n", "sub", v3, v5, v4);
break;
case 0x23u:
result = printf("%-8s %s, %s, %s\n", "subu", v3, v5, v4);
break;
case 0x24u:
result = printf("%-8s %s, %s, %s\n", "and", v3, v5, v4);
break;
case 0x25u:
result = printf("%-8s %s, %s, %s\n", "or", v3, v5, v4);
break;
case 0x26u:
result = printf("%-8s %s, %s, %s\n", "xor", v3, v5, v4);
break;
case 0x27u:
result = printf("%-8s %s, %s, %s\n", "nor", v3, v5, v4);
break;
case 0x2Au:
result = printf("%-8s %s, %s, %s\n", "slt", v3, v5, v4);
break;
case 0x2Bu:
result = printf("%-8s %s, %s, %s\n", "sltu", v3, v5, v4);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1, unsigned int a2)
{
int result; // eax
char v3[6]; // [rsp+Eh] [rbp-2Ah] BYREF
char v4[6]; // [rsp+14h] [rbp-24h] BYREF
char v5[30]; // [rsp+1Ah] [rbp-1Eh] BYREF

printf("0x%08X ", a1);
func12((a2 >> 21) & 0x1F, v5);
func12(HIWORD(a2) & 0x1F, v4);
result = func12((unsigned __int16)a2 >> 11, v3);
switch ( a2 & 0x3F )
{
case 0u:
result = printf("%-8s %s, %s, %u\n", "sll", v3, v4, (a2 >> 6) & 0x1F);
break;
case 2u:
result = printf("%-8s %s, %s, %u\n", "srl", v3, v4, (a2 >> 6) & 0x1F);
break;
case 3u:
result = printf("%-8s %s, %s, %u\n", "sra", v3, v4, (a2 >> 6) & 0x1F);
break;
case 8u:
result = printf("%-8s %s\n", "jr", v5);
break;
case 0xCu:
result = printf("%-8s \n", "syscall");
break;
case 0x20u:
result = printf("%-8s %s, %s, %s\n", "add", v3, v5, v4);
break;
case 0x21u:
result = printf("%-8s %s, %s, %s\n", "addu", v3, v5, v4);
break;
case 0x22u:
result = printf("%-8s %s, %s, %s\n", "sub", v3, v5, v4);
break;
case 0x23u:
result = printf("%-8s %s, %s, %s\n", "subu", v3, v5, v4);
break;
case 0x24u:
result = printf("%-8s %s, %s, %s\n", "and", v3, v5, v4);
break;
case 0x25u:
result = printf("%-8s %s, %s, %s\n", "or", v3, v5, v4);
break;
case 0x26u:
result = printf("%-8s %s, %s, %s\n", "xor", v3, v5, v4);
break;
case 0x27u:
result = printf("%-8s %s, %s, %s\n", "nor", v3, v5, v4);
break;
case 0x2Au:
result = printf("%-8s %s, %s, %s\n", "slt", v3, v5, v4);
break;
case 0x2Bu:
result = printf("%-8s %s, %s, %s\n", "sltu", v3, v5, v4);
break;
default:
return result;
}
return result;
}

original_code:
void
rType(int PC, struct RFormat rInstruct)
{
    printf("0x%08X ", PC);
    char rsReg[6];
    char rtReg[6];
    char rdReg[6];
    getRegister(rInstruct.rs, rsReg);
    getRegister(rInstruct.rt, rtReg);
    getRegister(rInstruct.rd, rdReg);
    switch(rInstruct.funct)
    {
        case 0:
            printf("%-8s %s, %s, %u\n", "sll", rdReg, rtReg, rInstruct.shamt);
            break;
        case 2:
            printf("%-8s %s, %s, %u\n", "srl", rdReg, rtReg, rInstruct.shamt);
            break;
        case 3:
            printf("%-8s %s, %s, %u\n", "sra", rdReg, rtReg, rInstruct.shamt);
            break;
        case 8:
            printf("%-8s %s\n", "jr", rsReg);
            break;
        case 12:
            printf("%-8s \n", "syscall");
            break;
        case 32:
            printf("%-8s %s, %s, %s\n", "add", rdReg, rsReg, rtReg);
            break;
        case 33:
            printf("%-8s %s, %s, %s\n", "addu", rdReg, rsReg, rtReg);
            break;
        case 34:
            printf("%-8s %s, %s, %s\n", "sub", rdReg, rsReg, rtReg);
            break;
        case 35:
            printf("%-8s %s, %s, %s\n", "subu", rdReg, rsReg, rtReg);
            break;
        case 36:
            printf("%-8s %s, %s, %s\n", "and", rdReg, rsReg, rtReg);
            break;
        case 37:
            printf("%-8s %s, %s, %s\n", "or", rdReg, rsReg, rtReg);
            break;
        case 38:
            printf("%-8s %s, %s, %s\n", "xor", rdReg, rsReg, rtReg);
            break;
        case 39:
            printf("%-8s %s, %s, %s\n", "nor", rdReg, rsReg, rtReg);
            break;
        case 42:
            printf("%-8s %s, %s, %s\n", "slt", rdReg, rsReg, rtReg);
            break;
        case 43:
            printf("%-8s %s, %s, %s\n", "sltu", rdReg, rsReg, rtReg);
            break;
        default:
            break;
    }
    return;
}

variable_types: PC int

variable_types: struct RFormat { unsigned int funct; unsigned int shamt; unsigned int rd; unsigned int rt; unsigned int rs; unsigned int opCode; }

variable_types:
rsReg
char [6]

variable_types:
rtReg
char [6]

variable_types:
rdReg
char [6]

return_type: void


iType

decompiled_code:
int __fastcall iType(unsigned int a1, unsigned __int16 *a2)
{
__int64 v2; // r8
unsigned int v3; // ebx
int result; // eax
char v5[6]; // [rsp+4h] [rbp-24h] BYREF
char v6[30]; // [rsp+Ah] [rbp-1Eh] BYREF

printf("0x%08X ", a1);
getRegister((a2[1] >> 5) & 0x1F, v6);
getRegister(a2[1] & 0x1F, v5);
v2 = *a2;
v3 = (__int16)*a2;
result = ((*((_BYTE *)a2 + 3) >> 2) + 60) & 0x3F;
switch ( (char)result )
{
case 0:
result = printf("%-8s %s, %s, 0x%08X\n", "beq", v6, v5, a1 + 4 * v3);
break;
case 1:
result = printf("%-8s %s, %s, 0x%08X\n", "bne", v6, v5, a1 + 4 * v3);
break;
case 4:
printf("%-8s %s, %s, ", "addi", v5, v6);
printf("%d", v3);
result = putchar(10);
break;
case 5:
result = printf("%-8s %s, %s, %u\n", "addiu", v5, v6, v2);
break;
case 6:
result = printf("%-8s %s, %s, %d\n", "slti", v5, v6, v3);
break;
case 8:
result = printf("%-8s %s, %s, %u\n", "andi", v5, v6, v2);
break;
case 9:
result = printf("%-8s %s, %s, %u\n", "ori", v5, v6, v2);
break;
case 10:
result = printf("%-8s %s, %s, %u\n", "xori", v5, v6, v2);
break;
case 11:
result = printf("%-8s %s, %u\n", "lui", v5, *a2);
break;
case 28:
result = printf("%-8s %s, %d(%s)\n", "lb", v5, v3, v6);
break;
case 29:
result = printf("%-8s %s, %d(%s)\n", "lh", v5, v3, v6);
break;
case 31:
result = printf("%-8s %s, %d(%s)\n", "lw", v5, v3, v6);
break;
case 36:
result = printf("%-8s %s, %d(%s)\n", "sb", v5, v3, v6);
break;
case 37:
result = printf("%-8s %s, %d(%s)\n", "sh", v5, v3, v6);
break;
case 39:
result = printf("%-8s %s, %d(%s)\n", "sw", v5, v3, v6);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, unsigned __int16 *a2)
{
__int64 v2; // r8
unsigned int v3; // ebx
int result; // eax
char v5[6]; // [rsp+4h] [rbp-24h] BYREF
char v6[30]; // [rsp+Ah] [rbp-1Eh] BYREF

printf("0x%08X ", a1);
func12((a2[1] >> 5) & 0x1F, v6);
func12(a2[1] & 0x1F, v5);
v2 = *a2;
v3 = (__int16)*a2;
result = ((*((_BYTE *)a2 + 3) >> 2) + 60) & 0x3F;
switch ( (char)result )
{
case 0:
result = printf("%-8s %s, %s, 0x%08X\n", "beq", v6, v5, a1 + 4 * v3);
break;
case 1:
result = printf("%-8s %s, %s, 0x%08X\n", "bne", v6, v5, a1 + 4 * v3);
break;
case 4:
printf("%-8s %s, %s, ", "addi", v5, v6);
printf("%d", v3);
result = putchar(10);
break;
case 5:
result = printf("%-8s %s, %s, %u\n", "addiu", v5, v6, v2);
break;
case 6:
result = printf("%-8s %s, %s, %d\n", "slti", v5, v6, v3);
break;
case 8:
result = printf("%-8s %s, %s, %u\n", "andi", v5, v6, v2);
break;
case 9:
result = printf("%-8s %s, %s, %u\n", "ori", v5, v6, v2);
break;
case 10:
result = printf("%-8s %s, %s, %u\n", "xori", v5, v6, v2);
break;
case 11:
result = printf("%-8s %s, %u\n", "lui", v5, *a2);
break;
case 28:
result = printf("%-8s %s, %d(%s)\n", "lb", v5, v3, v6);
break;
case 29:
result = printf("%-8s %s, %d(%s)\n", "lh", v5, v3, v6);
break;
case 31:
result = printf("%-8s %s, %d(%s)\n", "lw", v5, v3, v6);
break;
case 36:
result = printf("%-8s %s, %d(%s)\n", "sb", v5, v3, v6);
break;
case 37:
result = printf("%-8s %s, %d(%s)\n", "sh", v5, v3, v6);
break;
case 39:
result = printf("%-8s %s, %d(%s)\n", "sw", v5, v3, v6);
break;
default:
return result;
}
return result;
}

original_code:
void
iType(int PC, union Instruction *instruct)
{
    printf("0x%08X ", PC);
    char rsReg[6];
    char rtReg[6];
    getRegister(instruct->iInstruct.rs, rsReg);
    getRegister(instruct->iInstruct.rt, rtReg);
    int temp;
    unsigned int imm = instruct->iInstruct.immediate;
    signed int immSigned = instruct->iInstructSigned.immediate;
    switch (instruct->iInstruct.opCode)
    {
        case 4:
            temp = immSigned;
            temp = temp << 2;
            temp = temp + PC;
            printf("%-8s %s, %s, 0x%08X\n", "beq", rsReg, rtReg, temp);
            break;
        case 5:
            temp = immSigned;
            temp = temp << 2;
            temp = temp + PC;
            printf("%-8s %s, %s, 0x%08X\n", "bne", rsReg, rtReg, temp);
            break;
        case 8:
            printf("%-8s %s, %s, ", "addi", rtReg, rsReg);
            printf("%d", immSigned);
            printf("\n");
            break;
        case 9:
            printf("%-8s %s, %s, %u\n", "addiu", rtReg, rsReg, imm);
            break;
        case 10:
            printf("%-8s %s, %s, %d\n", "slti", rtReg, rsReg, immSigned);
            break;
        case 12:
            printf("%-8s %s, %s, %u\n", "andi", rtReg, rsReg, imm);
            break;
        case 13:
            printf("%-8s %s, %s, %u\n", "ori", rtReg, rsReg, imm);
            break;
        case 14:
            printf("%-8s %s, %s, %u\n", "xori", rtReg, rsReg, imm);
            break;
        case 15:
            printf("%-8s %s, %u\n", "lui", rtReg, imm);
            break;
        case 32:
            printf("%-8s %s, %d(%s)\n", "lb", rtReg, immSigned, rsReg);
            break;
        case 33:
            printf("%-8s %s, %d(%s)\n", "lh", rtReg, immSigned, rsReg);
            break;
        case 35:
            printf("%-8s %s, %d(%s)\n", "lw", rtReg, immSigned, rsReg);
            break;
        case 40:
            printf("%-8s %s, %d(%s)\n", "sb", rtReg, immSigned, rsReg);
            break;
        case 41:
            printf("%-8s %s, %d(%s)\n", "sh", rtReg, immSigned, rsReg);
            break;
        case 43:
            printf("%-8s %s, %d(%s)\n", "sw", rtReg, immSigned, rsReg);
            break;
        default:
            break;
    }
    return;
}

canonical_original_code:
void iType(int PC, union Instruction *instruct)
{
    printf("0x%08X ", PC);
    char rsReg[6];
    char rtReg[6];
    getRegister(instruct->iInstruct.rs, rsReg);
    getRegister(instruct->iInstruct.rt, rtReg);
    int temp;
    unsigned int imm = instruct->iInstruct.immediate;
    int immSigned = instruct->iInstructSigned.immediate;
    switch (instruct->iInstruct.opCode)
    {
        case 4:
            temp = immSigned;
            temp = temp << 2;
            temp = temp + PC;
            printf("%-8s %s, %s, 0x%08X\n", "beq", rsReg, rtReg, temp);
            break;
        case 5:
            temp = immSigned;
            temp = temp << 2;
            temp = temp + PC;
            printf("%-8s %s, %s, 0x%08X\n", "bne", rsReg, rtReg, temp);
            break;
        case 8:
            printf("%-8s %s, %s, ", "addi", rtReg, rsReg);
            printf("%d", immSigned);
            printf("\n");
            break;
        case 9:
            printf("%-8s %s, %s, %u\n", "addiu", rtReg, rsReg, imm);
            break;
        case 10:
            printf("%-8s %s, %s, %d\n", "slti", rtReg, rsReg, immSigned);
            break;
        case 12:
            printf("%-8s %s, %s, %u\n", "andi", rtReg, rsReg, imm);
            break;
        case 13:
            printf("%-8s %s, %s, %u\n", "ori", rtReg, rsReg, imm);
            break;
        case 14:
            printf("%-8s %s, %s, %u\n", "xori", rtReg, rsReg, imm);
            break;
        case 15:
            printf("%-8s %s, %u\n", "lui", rtReg, imm);
            break;
        case 32:
            printf("%-8s %s, %d(%s)\n", "lb", rtReg, immSigned, rsReg);
            break;
        case 33:
            printf("%-8s %s, %d(%s)\n", "lh", rtReg, immSigned, rsReg);
            break;
        case 35:
            printf("%-8s %s, %d(%s)\n", "lw", rtReg, immSigned, rsReg);
            break;
        case 40:
            printf("%-8s %s, %d(%s)\n", "sb", rtReg, immSigned, rsReg);
            break;
        case 41:
            printf("%-8s %s, %d(%s)\n", "sh", rtReg, immSigned, rsReg);
            break;
        case 43:
            printf("%-8s %s, %d(%s)\n", "sw", rtReg, immSigned, rsReg);
            break;
        default:
            break;
    }
    return;
}

variable_types: union Instruction { struct RFormat { unsigned int funct; unsigned int shamt; unsigned int rd; unsigned int rt; unsigned int rs; unsigned int opCode; } rInstruct; struct IFormat { unsigned int immediate; unsigned int rt; unsigned int rs; unsigned int opCode; } iInstruct; struct IFormatSigned { int immediate; unsigned int rt; unsigned int rs; unsigned int opCode; } iInstructSigned; struct JFormat { int target; unsigned int opCode; } jInstruct; } *

variable_types: temp int

variable_types:
imm
unsigned int

variable_types: immSigned int

user_defined_types: union Instruction { struct RFormat rInstruct; struct IFormat iInstruct; struct IFormatSigned iInstructSigned; struct JFormat jInstruct; }


jType

decompiled_code:
int __fastcall jType(unsigned int a1, int a2)
{
char v2; // ebx^3
unsigned int v3; // ebp
const char *v4; // rsi

v2 = HIBYTE(a2);
v3 = (4 * (a2 << 6 >> 6)) | a1 & 0x10000000;
printf("0x%08X ", a1);
v4 = (const char *)&unk_402610;
if ( (v2 & 0xFC) != 8 )
v4 = (const char *)&unk_402612;
printf("%-8s ", v4);
return printf("0x%08X\n", v3);
}

canonical_decompiled_code:
int __fastcall func11(unsigned int a1, int a2)
{
char v2; // ebx^3
unsigned int v3; // ebp
const char *v4; // rsi

v2 = HIBYTE(a2);
v3 = (4 * (a2 << 6 >> 6)) | a1 & 0x10000000;
printf("0x%08X ", a1);
v4 = (const char *)&unk_402610;
if ( (v2 & 0xFC) != 8 )
v4 = (const char *)&unk_402612;
printf("%-8s ", v4);
return printf("0x%08X\n", v3);
}

original_code:
void
jType(int PC, struct JFormat jInstruct)
{
    int fullTarget = jInstruct.target;
    fullTarget = fullTarget << 2;
    int mask = 0x10000000;
    mask = mask & PC;
    fullTarget = fullTarget | mask;
    printf("0x%08X ", PC);
    printf("%-8s ", jInstruct.opCode == 2 ? "j" : "jal");
    printf("0x%08X\n", fullTarget);
    return;
}

variable_types: struct JFormat { int target; unsigned int opCode; }

variable_types: fullTarget int

variable_types: mask int


getRegister

original_code:
void
getRegister(int reg, char regName[6])
{
    switch (reg)
    {
        case 0:
            sprintf(regName, "$zero");
            break;
        case 1:
            sprintf(regName, "$at");
            break;
        case 2:
            sprintf(regName, "$v0");
            break;
        case 3:
            sprintf(regName, "$v1");
            break;
        case 4:
            sprintf(regName, "$a0");
            break;
        case 5:
            sprintf(regName, "$a1");
            break;
        case 6:
            sprintf(regName, "$a2");
            break;
        case 7:
            sprintf(regName, "$a3");
            break;
        case 8:
            sprintf(regName, "$t0");
            break;
        case 9:
            sprintf(regName, "$t1");
            break;
        case 10:
            sprintf(regName, "$t2");
            break;
        case 11:
            sprintf(regName, "$t3");
            break;
        case 12:
            sprintf(regName, "$t4");
            break;
        case 13:
            sprintf(regName, "$t5");
            break;
        case 14:
            sprintf(regName, "$t6");
            break;
        case 15:
            sprintf(regName, "$t7");
            break;
        case 16:
            sprintf(regName, "$s0");
            break;
        case 17:
            sprintf(regName, "$s1");
            break;
        case 18:
            sprintf(regName, "$s2");
            break;
        case 19:
            sprintf(regName, "$s3");
            break;
        case 20:
            sprintf(regName, "$s4");
            break;
        case 21:
            sprintf(regName, "$s5");
            break;
        case 22:
            sprintf(regName, "$s6");
            break;
        case 23:
            sprintf(regName, "$s7");
            break;
        case 24:
            sprintf(regName, "$t8");
            break;
        case 25:
            sprintf(regName, "$t9");
            break;
        case 26:
            sprintf(regName, "$k0");
            break;
        case 27:
            sprintf(regName, "$k1");
            break;
        case 28:
            sprintf(regName, "$gp");
            break;
        case 29:
            sprintf(regName, "$sp");
            break;
        case 30:
            sprintf(regName, "$fp");
            break;
        case 31:
            sprintf(regName, "$ra");
            break;
    }
    return;
}

variable_types: reg int

variable_types:
regName
char [6]


ring

decompiled_code:
void *__fastcall ring(void *a1)
{
abre_sockets(a1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
abre_sockets(a1);
return 0LL;
}

original_code:
void *ring(void *p)
{
 abre_sockets();
 return (void *)0x0;
}

variable_types:
p
void *

return_type: void *


decompiled_code:
int abrir_chat()
{
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

pthread_create(newthread, 0LL, chat, 0LL);
pthread_create(&th, 0LL, ring, 0LL);
pthread_join(newthread[0], 0LL);
return pthread_join(th, 0LL);
}

canonical_decompiled_code:
int func1()
{
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

pthread_create(newthread, 0LL, chat, 0LL);
pthread_create(&th, 0LL, ring, 0LL);
pthread_join(newthread[0], 0LL);
return pthread_join(th, 0LL);
}

original_code:
void abrir_chat(void)
{
 pthread_t t_chat, t_ring;
 pthread_create(&t_chat, ((void *)0), chat, ((void *)0));
 pthread_create(&t_ring, ((void *)0), ring, ((void *)0));
 pthread_join(t_chat, ((void *)0));
 pthread_join(t_ring, ((void *)0));
}

canonical_original_code:
void abrir_chat()
{
 unsigned long t_chat; unsigned long t_ring;
 pthread_create(&t_chat, ((void *)0), chat, ((void *)0));
 pthread_create(&t_ring, ((void *)0), ring, ((void *)0));
 pthread_join(t_chat, ((void *)0));
 pthread_join(t_ring, ((void *)0));
}


decompiled_code:
int listar_contatos()
{
const char *v0; // rbx
int result; // eax

puts("contatos:");
v0 = (const char *)&contatos;
do
{
result = printf(">> %s\n", v0);
v0 += 15;
}
while ( v0 != (const char *)(unsigned int)((_DWORD)&contatos + 60) );
return result;
}

canonical_decompiled_code:
int func2()
{
const char *v0; // rbx
int result; // eax

puts("contatos:");
v0 = (const char *)&contatos;
do
{
result = printf(">> %s\n", v0);
v0 += 15;
}
while ( v0 != (const char *)(unsigned int)((_DWORD)&contatos + 60) );
return result;
}

original_code:
void listar_contatos(void)
{
 int i;
 printf("contatos:\n");
 for (i = 0; i < 4; i++) {
  printf(">> %s\n", contatos[i]);
 }
}

canonical_original_code:
void listar_contatos()
{
 int i;
 printf("contatos:\n");
 for (i = 0; i < 4; i++) {
  printf(">> %s\n", contatos[i]);
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall contato_id(char *s1)
{
unsigned int v1; // er12
__int64 v2; // rbx

v1 = 99;
if ( strcmp(s1, "todos") )
{
v2 = 0LL;
while ( 1 )
{
v1 = v2;
if ( !strcmp(s1, &contatos[15 * v2]) )
break;
if ( ++v2 == 4 )
return (unsigned int)-1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s1)
{
unsigned int v1; // er12
__int64 v2; // rbx

v1 = 99;
if ( strcmp(s1, "todos") )
{
v2 = 0LL;
while ( 1 )
{
v1 = v2;
if ( !strcmp(s1, &contatos[15 * v2]) )
break;
if ( ++v2 == 4 )
return (unsigned int)-1;
}
}
return v1;
}

original_code:
int contato_id(char *nome)
{
 int i;
 if (!strcmp(nome, "todos"))
  return 99;
 for (i = 0; i < 4; i++) {
  if (!strcmp(nome, contatos[i])) {
   return i;
  }
 }
 return -1;
}

variable_types:
nome
char *


chat

decompiled_code:
void __fastcall __noreturn chat(void *a1)
{
char *v1; // rbx
char *v2; // rbp
char *v3; // rax
char **v4; // rax
char *v5; // rdx
char v6; // al
char v7; // al
char v8[32]; // [rsp+0h] [rbp-138h] BYREF
char s; // [rsp+20h] [rbp-118h] BYREF
char s1[279]; // [rsp+21h] [rbp-117h] BYREF

v1 = 0LL;
while ( 1 )
{
while ( 1 )
{
LABEL_2:
if ( !v1 )
goto LABEL_8;
LABEL_3:
memset(v1, 0, 0x118uLL);
fgets(&s, 256, stdin);
if ( s != 47 )
{
*v1 = 99;
v2 = &s;
goto LABEL_5;
}
if ( strncmp(s1, "listar", 6uLL) )
break;
listar_contatos();
}
v5 = v8;
v2 = s1;
do
{
v6 = *v2;
if ( *v2 == 10 )
goto LABEL_2;
++v2;
*v5++ = v6;
}
while ( v6 != 32 );
if ( *v2 == 10 )
goto LABEL_2;
*(v5 - 1) = 0;
v7 = contato_id(v8);
*v1 = v7;
if ( v7 == ihost )
goto LABEL_2;
if ( v7 >= 0 )
{
LABEL_5:
v3 = strchr(v2, 10);
if ( v3 )
*v3 = 0;
strcpy(v1 + 1, v2);
pthread_mutex_lock(&mutex);
*((_QWORD *)v1 + 33) = 0LL;
v4 = (char **)my_tailq_head[1];
*((_QWORD *)v1 + 34) = v4;
*v4 = v1;
my_tailq_head[1] = v1 + 264;
pthread_mutex_unlock(&mutex);
LABEL_8:
v1 = (char *)malloc(0x118uLL);
if ( !v1 )
erro("erro no malloc");
goto LABEL_3;
}
puts("contato inexistente...");
}
}

canonical_decompiled_code:
void __fastcall __noreturn func4(void *a1)
{
char *v1; // rbx
char *v2; // rbp
char *v3; // rax
char **v4; // rax
char *v5; // rdx
char v6; // al
char v7; // al
char v8[32]; // [rsp+0h] [rbp-138h] BYREF
char s; // [rsp+20h] [rbp-118h] BYREF
char s1[279]; // [rsp+21h] [rbp-117h] BYREF

v1 = 0LL;
while ( 1 )
{
while ( 1 )
{
LABEL_2:
if ( !v1 )
goto LABEL_8;
LABEL_3:
memset(v1, 0, 0x118uLL);
fgets(&s, 256, stdin);
if ( s != 47 )
{
*v1 = 99;
v2 = &s;
goto LABEL_5;
}
if ( strncmp(s1, "listar", 6uLL) )
break;
func2();
}
v5 = v8;
v2 = s1;
do
{
v6 = *v2;
if ( *v2 == 10 )
goto LABEL_2;
++v2;
*v5++ = v6;
}
while ( v6 != 32 );
if ( *v2 == 10 )
goto LABEL_2;
*(v5 - 1) = 0;
v7 = func3(v8);
*v1 = v7;
if ( v7 == ihost )
goto LABEL_2;
if ( v7 >= 0 )
{
LABEL_5:
v3 = strchr(v2, 10);
if ( v3 )
*v3 = 0;
strcpy(v1 + 1, v2);
pthread_mutex_lock(&mutex);
*((_QWORD *)v1 + 33) = 0LL;
v4 = (char **)my_tailq_head[1];
*((_QWORD *)v1 + 34) = v4;
*v4 = v1;
my_tailq_head[1] = v1 + 264;
pthread_mutex_unlock(&mutex);
LABEL_8:
v1 = (char *)malloc(0x118uLL);
if ( !v1 )
erro("erro no malloc");
goto LABEL_3;
}
puts("contato inexistente...");
}
}

original_code:
void *chat(void *p)
{
 char buffer[256], destino[30], *ptr, *ptr2;
 struct tailq_entry *item;
 item = ((void *)0);
 while (1) {
  item = item ? item : malloc(sizeof(struct tailq_entry));
  if (!item)
   erro("erro no malloc");
  memset(item, 0, sizeof(struct tailq_entry));
  fgets(buffer, 256, stdin);
  ptr = buffer;
  ptr2 = destino;
  if (ptr[0] == '/') {
   ptr++;
   if (!strncmp(ptr, "listar", 6)) {
    listar_contatos();
    continue;
   }
   while (*ptr != '\n' && (*ptr2++ = *ptr++) != ' ') ;
   if (*ptr == '\n')
    continue;
   *--ptr2 = '\0';
   item->destino = (char)contato_id(destino);
   if (item->destino == ihost)
    continue;
   if (item->destino < 0) {
    printf("contato inexistente...\n");
    continue;
   }
  } else {
   item->destino = 99;
  }
  ptr2 = strchr(ptr, '\n');
  if (ptr2)
   *ptr2 = '\0';
  strcpy(item->mensagem, ptr);
  pthread_mutex_lock(&mutex);
  do { (item)->entries.tqe_next = ((void *)0); (item)->entries.tqe_prev = (&my_tailq_head)->tqh_last; *(&my_tailq_head)->tqh_last = (item); (&my_tailq_head)->tqh_last = &(item)->entries.tqe_next; } while ( 0);
  pthread_mutex_unlock(&mutex);
  item = ((void *)0);
 }
 return (void *)0x0;
}

canonical_original_code:
void *chat(void *p)
{
 char buffer[256]; char destino[30]; char *ptr; char *ptr2;
 struct tailq_entry *item;
 item = ((void *)0);
 while (1) {
  item = item ? item : malloc(sizeof(struct tailq_entry));
  if (!item)
   erro("erro no malloc");
  memset(item, 0, sizeof(struct tailq_entry));
  fgets(buffer, 256, stdin);
  ptr = buffer;
  ptr2 = destino;
  if (ptr[0] == '/') {
   ptr++;
   if (!strncmp(ptr, "listar", 6)) {
    listar_contatos();
    continue;
   }
   while (*ptr != '\n' && (*ptr2++ = *ptr++) != ' ') ;
   if (*ptr == '\n')
    continue;
   *--ptr2 = '\0';
   item->destino = (char)contato_id(destino);
   if (item->destino == ihost)
    continue;
   if (item->destino < 0) {
    printf("contato inexistente...\n");
    continue;
   }
  } else {
   item->destino = 99;
  }
  ptr2 = strchr(ptr, '\n');
  if (ptr2)
   *ptr2 = '\0';
  strcpy(item->mensagem, ptr);
  pthread_mutex_lock(&mutex);
  do { (item)->entries.tqe_next = ((void *)0); (item)->entries.tqe_prev = (&my_tailq_head)->tqh_last; *(&my_tailq_head)->tqh_last = (item); (&my_tailq_head)->tqh_last = &(item)->entries.tqe_next; } while ( 0);
  pthread_mutex_unlock(&mutex);
  item = ((void *)0);
 }
 return (void *)0x0;
}

variable_types:
buffer
char [256]

variable_types:
destino
char [30]

variable_types:
ptr
char *

variable_types: struct tailq_entry { char destino; struct { struct tailq_entry *tqe_next; struct tailq_entry **tqe_prev; } entries; } *


repo: gmcabrita/embed-python-c

decompiled_code:
__int64 __fastcall test_return_int(int a1)
{
return (unsigned int)(5 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
return (unsigned int)(5 * a1);
}

original_code:
int test_return_int(int n) {
    return n * 5;
}

variable_types: n int


canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return (unsigned int)(5 * a1);
}

canonical_original_code:
int test_return_int(int n) {
    return n * 5;
}


decompiled_code:
size_t __fastcall write_response(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v5; // rbp
size_t v6; // rsi
void *v7; // rax

v5 = a3 * a2;
v6 = *(_QWORD *)(a4 + 8) + a3 * a2;
if ( v6 <= 0x3FFFE )
{
LABEL_5:
memcpy((void *)(*(_QWORD *)a4 + *(_QWORD *)(a4 + 8)), src, v5);
*(_QWORD *)(a4 + 8) += v5;
return v5;
}
if ( v6 <= 0x9FFFFF )
{
v7 = realloc(*(void **)a4, v6);
*(_QWORD *)a4 = v7;
if ( !v7 )
return 0LL;
goto LABEL_5;
}
return 0LL;
}

canonical_decompiled_code:
size_t __fastcall func0(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v5; // rbp
size_t v6; // rsi
void *v7; // rax

v5 = a3 * a2;
v6 = *(_QWORD *)(a4 + 8) + a3 * a2;
if ( v6 <= 0x3FFFE )
{
LABEL_5:
memcpy((void *)(*(_QWORD *)a4 + *(_QWORD *)(a4 + 8)), src, v5);
*(_QWORD *)(a4 + 8) += v5;
return v5;
}
if ( v6 <= 0x9FFFFF )
{
v7 = realloc(*(void **)a4, v6);
*(_QWORD *)a4 = v7;
if ( !v7 )
return 0LL;
goto LABEL_5;
}
return 0LL;
}

original_code:
static size_t write_response(void *ptr, size_t size, size_t nmemb, void *stream)
{
    struct response *result = (struct response *)stream;
    size_t required_len = result->pos + size * nmemb;
    if(required_len >= (256 * 1024) - 1)
    {
        if (required_len < (10 * 1024 * 1024))
        {
            result->data = realloc(result->data, required_len);
            if (!result->data){
                return 0;
            }
        } else {
            return 0;
        }
    }
    memcpy(result->data + result->pos, ptr, size * nmemb);
    result->pos += size * nmemb;
    return size * nmemb;
}

canonical_original_code:
static unsigned long write_response(void *ptr, unsigned long size, unsigned long nmemb, void *stream)
{
    struct response *result = (struct response *)stream;
    unsigned long required_len = result->pos + size * nmemb;
    if(required_len >= (256 * 1024) - 1)
    {
        if (required_len < (10 * 1024 * 1024))
        {
            result->data = realloc(result->data, required_len);
            if (!result->data){
                return 0;
            }
        } else {
            return 0;
        }
    }
    memcpy(result->data + result->pos, ptr, size * nmemb);
    result->pos += size * nmemb;
    return size * nmemb;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
stream
void *

variable_types: struct response { char *data; unsigned long pos; } *

return_type: unsigned long


decompiled_code:
size_t j_strlen()
{
const char *v0; // rax

v0 = (const char *)json_string_value();
return strlen(v0);
}

canonical_decompiled_code:
size_t func1()
{
const char *v0; // rax

v0 = (const char *)json_string_value();
return strlen(v0);
}

original_code:
extern size_t
j_strlen(json_t *str)
{
    return strlen(json_string_value(str));
}

canonical_original_code:
extern unsigned long j_strlen(struct json_t *str)
{
    return strlen(json_string_value(str));
}

variable_types: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *

user_defined_types: struct json_t { enum json_type type; unsigned long refcount; }


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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

original_code:
static inline
void json_decref(json_t *json)
{
    if(json && json->refcount != (size_t)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

canonical_original_code:
static inline void json_decref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

user_defined_types: enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 }


printGraphCB

repo: gmodena/libgraph

decompiled_code:
int __fastcall printGraphCB(__int64 a1)
{
unsigned int *i; // rbx
double v2; // xmm1_8
int result; // eax

for ( i = *(unsigned int **)(a1 + 8); i; i = (unsigned int *)*((_QWORD *)i + 2) )
{
v2 = *(double *)(*((_QWORD *)i + 4) + 32LL) / ((double)(*(_DWORD *)a1 - 1) * (double)(*(_DWORD *)a1 - 2));
result = printf("%d\t\t\t%.16f\t\t\t%.16f\t\t\t%.16f\n", *i, *(double *)(*((_QWORD *)i + 4) + 32LL), v2 * 0.5, v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
unsigned int *i; // rbx
double v2; // xmm1_8
int result; // eax

for ( i = *(unsigned int **)(a1 + 8); i; i = (unsigned int *)*((_QWORD *)i + 2) )
{
v2 = *(double *)(*((_QWORD *)i + 4) + 32LL) / ((double)(*(_DWORD *)a1 - 1) * (double)(*(_DWORD *)a1 - 2));
result = printf("%d\t\t\t%.16f\t\t\t%.16f\t\t\t%.16f\n", *i, *(double *)(*((_QWORD *)i + 4) + 32LL), v2 * 0.5, v2);
}
return result;
}

original_code:
void printGraphCB(t_graph *graph)
{
  t_vertex *v;
  v = graph->vertices;
    while ( v != ((void *)0)) {
       printf("%d\t\t\t%.16f\t\t\t%.16f\t\t\t%.16f\n",
           v->id,
           v->data->rank,
           v->data->rank/((double)(graph->num_vertices-1)*(double)(graph->num_vertices-2))/2.0,
           v->data->rank/((double)(graph->num_vertices-1)*(double)(graph->num_vertices-2))
           );
       v = (v)->next;
    }
}

canonical_original_code:
void printGraphCB(struct tgraph *graph)
{
  struct tvertex *v;
  v = graph->vertices;
    while ( v != ((void *)0)) {
       printf("%d\t\t\t%.16f\t\t\t%.16f\t\t\t%.16f\n",
           v->id,
           v->data->rank,
           v->data->rank/((double)(graph->num_vertices-1)*(double)(graph->num_vertices-2))/2.0,
           v->data->rank/((double)(graph->num_vertices-1)*(double)(graph->num_vertices-2))
           );
       v = (v)->next;
    }
}

variable_types: struct tgraph { int num_vertices; int is_directed; struct tvertex { unsigned int id; struct tedge { int weight; struct tvertex *links; struct tedge *next; } *edges; struct tvertex *next; int visited; struct cbData { double sp_num; double distance; double dependency; struct tlParents { struct tvertex *vertex; struct tlParents *next; } *parents; double rank; } *data; } *vertices; } *

user_defined_types: struct tgraph { int num_vertices; int is_directed; struct tvertex *vertices; }

user_defined_types: struct tvertex { unsigned int id; struct tedge *edges; struct tvertex *next; int visited; struct cbData *data; }

user_defined_types: struct cbData { double sp_num; double distance; double dependency; struct tlParents *parents; double rank; }


destroyCBData

decompiled_code:
void __fastcall destroyCBData(__int64 a1)
{
__int64 i; // rbp
_QWORD *v2; // rdi
_QWORD *v3; // rbx
void *v4; // rdi

for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)(i + 16) )
{
v2 = *(_QWORD **)(i + 32);
if ( v2 )
{
v3 = (_QWORD *)v2[3];
if ( !v3 )
goto LABEL_4;
do
{
v4 = v3;
v3 = (_QWORD *)v3[1];
free(v4);
}
while ( v3 );
v2 = *(_QWORD **)(i + 32);
if ( v2 )
LABEL_4:
free(v2);
}
}
}

original_code:
void destroyCBData(t_graph *graph)
{
  t_vertex *w;
  t_parents *p, *tmp;
  w = graph->vertices;
  while (w != ((void *)0))
  {
    if (w->data != ((void *)0)) {
      p = w->data->parents;
      while (p != ((void *)0)) {
        p->vertex = ((void *)0);
        tmp = (p)->next;
        (p)->next = ((void *)0);
        free(p);
        p = tmp;
      }
    }
    if ((w)->data != ((void *)0))
      free(w->data);
    w = (w)->next;
  }
}

canonical_original_code:
void destroyCBData(struct tgraph *graph)
{
  struct tvertex *w;
  struct tlParents *p; struct tlParents *tmp;
  w = graph->vertices;
  while (w != ((void *)0))
  {
    if (w->data != ((void *)0)) {
      p = w->data->parents;
      while (p != ((void *)0)) {
        p->vertex = ((void *)0);
        tmp = (p)->next;
        (p)->next = ((void *)0);
        free(p);
        p = tmp;
      }
    }
    if ((w)->data != ((void *)0))
      free(w->data);
    w = (w)->next;
  }
}

variable_types: struct tvertex { unsigned int id; struct tedge { int weight; struct tvertex *links; struct tedge *next; } *edges; struct tvertex *next; int visited; struct cbData { double sp_num; double distance; double dependency; struct tlParents { struct tvertex *vertex; struct tlParents *next; } *parents; double rank; } *data; } *

variable_types: struct tlParents { struct tvertex { unsigned int id; struct tedge { int weight; struct tvertex *links; struct tedge *next; } *edges; struct tvertex *next; int visited; struct cbData { double sp_num; double distance; double dependency; struct tlParents *parents; double rank; } *data; } *vertex; struct tlParents *next; } *


help

decompiled_code:
int help()
{
puts("\nUsage: ");
puts("-b : compute betwenness centrality index and print results on screen ");
puts("-f : load a graph from a CSV file ");
puts("-o : oriented graph ");
puts("-d : dump the graph output in DOT format \n");
puts("Example: ");
return printf("bc -o -d -f net.csv\n ");
}

canonical_decompiled_code:
int func0()
{
puts("\nUsage: ");
puts("-b : compute betwenness centrality index and print results on screen ");
puts("-f : load a graph from a CSV file ");
puts("-o : oriented graph ");
puts("-d : dump the graph output in DOT format \n");
puts("Example: ");
return printf("bc -o -d -f net.csv\n ");
}

original_code:
void help(void)
{
  printf("\nUsage: \n");
  printf("-b : compute betwenness centrality index and print results on screen \n");
  printf("-f : load a graph from a CSV file \n");
  printf("-o : oriented graph \n");
  printf("-d : dump the graph output in DOT format \n\n");
  printf("Example: \n");
  printf("bc -o -d -f net.csv\n ");
}

canonical_original_code:
void help()
{
  printf("\nUsage: \n");
  printf("-b : compute betwenness centrality index and print results on screen \n");
  printf("-f : load a graph from a CSV file \n");
  printf("-o : oriented graph \n");
  printf("-d : dump the graph output in DOT format \n\n");
  printf("Example: \n");
  printf("bc -o -d -f net.csv\n ");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // r13
char *v5; // r14
int v6; // er15
const char **v7; // rsi
int v8; // eax
__int64 v9; // rdx
unsigned int v10; // ebx
const char **v12; // rbx
const char **v13; // rbp
__int64 v14; // rbp
int v15; // er12
int i; // ebx
unsigned int v17; // [rsp+8h] [rbp-40h]
int v18; // [rsp+Ch] [rbp-3Ch]

createGraph(0LL, argv, envp);
v4 = 0LL;
v5 = 0LL;
v17 = 1;
v18 = 0;
v6 = 0;
while ( 2 )
{
v7 = argv;
v8 = getopt(argc, (char *const *)argv, "odhbf:v:");
if ( v8 != -1 )
{
switch ( v8 )
{
case '?':
v10 = optopt;
if ( isprint(optopt) )
fprintf(stderr, "Unknown option: `-%c'.\n", v10);
else
fprintf(stderr, "Invalid option `\\x%x'.\n", v10);
help();
return 1;
case 'b':
v18 = 1;
continue;
case 'd':
v6 = 1;
continue;
case 'f':
v5 = optarg;
continue;
case 'h':
help();
continue;
case 'o':
v17 = 0;
continue;
case 'v':
v4 = optarg;
continue;
default:
abort();
}
}
break;
}
if ( argc > optind )
{
v12 = &argv[optind];
v13 = &(&argv[optind])[(unsigned __int64)(unsigned int)(argc + ~optind) + 1];
do
{
v7 = (const char **)*v12;
printf("Non-option argument %s\n", *v12++);
}
while ( v12 != v13 );
}
v14 = createGraph(v17, v7, v9);
if ( v4 )
{
v15 = atoi(v4);
if ( v15 > 0 )
{
for ( i = 1; i <= v15; ++i )
addVertex(v14, (unsigned int)i);
}
}
if ( v5 )
readFromCSV(v14, v5);
if ( v18 == 1 )
{
betweennessCentrality(v14);
printGraphCB(v14);
}
if ( v6 == 1 )
dumpDotGraph(v14);
destroyCBData(v14);
destroyGraph(v14);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // r13
char *v5; // r14
int v6; // er15
const char **v7; // rsi
int v8; // eax
__int64 v9; // rdx
unsigned int v10; // ebx
const char **v12; // rbx
const char **v13; // rbp
__int64 v14; // rbp
int v15; // er12
int i; // ebx
unsigned int v17; // [rsp+8h] [rbp-40h]
int v18; // [rsp+Ch] [rbp-3Ch]

createGraph(0LL, argv, envp);
v4 = 0LL;
v5 = 0LL;
v17 = 1;
v18 = 0;
v6 = 0;
while ( 2 )
{
v7 = argv;
v8 = getopt(argc, (char *const *)argv, "odhbf:v:");
if ( v8 != -1 )
{
switch ( v8 )
{
case '?':
v10 = optopt;
if ( isprint(optopt) )
fprintf(stderr, "Unknown option: `-%c'.\n", v10);
else
fprintf(stderr, "Invalid option `\\x%x'.\n", v10);
func0();
return 1;
case 'b':
v18 = 1;
continue;
case 'd':
v6 = 1;
continue;
case 'f':
v5 = optarg;
continue;
case 'h':
func0();
continue;
case 'o':
v17 = 0;
continue;
case 'v':
v4 = optarg;
continue;
default:
abort();
}
}
break;
}
if ( argc > optind )
{
v12 = &argv[optind];
v13 = &(&argv[optind])[(unsigned __int64)(unsigned int)(argc + ~optind) + 1];
do
{
v7 = (const char **)*v12;
printf("Non-option argument %s\n", *v12++);
}
while ( v12 != v13 );
}
v14 = createGraph(v17, v7, v9);
if ( v4 )
{
v15 = atoi(v4);
if ( v15 > 0 )
{
for ( i = 1; i <= v15; ++i )
addVertex(v14, (unsigned int)i);
}
}
if ( v5 )
readFromCSV(v14, v5);
if ( v18 == 1 )
{
betweennessCentrality(v14);
printGraphCB(v14);
}
if ( v6 == 1 )
dumpDotGraph(v14);
destroyCBData(v14);
destroyGraph(v14);
return 0;
}

original_code:
int main(int argc, char **argv)
{
  t_vertex *v1, *v2, *v3, *v4, *v5, *v6, *v7, *v8, *v9, *v10;
  t_vertex *w;
  t_edge *e;
  t_graph *graph;
  t_stack stack;
  t_queue queue;
  int V = 0;
  int i = 0;
  int dot = 0;
  int bc = 0;
  int is_directed = 1;
  int index;
  int f, v, c, o;
  char *file = ((void *)0);
  char *num_vertices = ((void *)0);
  graph = createGraph(0);
  while ((f = getopt (argc, argv, "odhbf:v:")) != -1)
    switch (f)
      {
      case 'd':
 dot = 1;
 break;
      case 'b':
 bc = 1;
 break;
      case 'o':
        is_directed = 0;
        break;
      case 'f':
 file = optarg;
 break;
      case 'h':
        help();
        break;
      case 'v':
        num_vertices = optarg;
        break;
      case '?':
 if (isprint (optopt)) {
   fprintf (stderr, "Unknown option: `-%c'.\n", optopt);
          help();
        }
 else {
   fprintf (stderr,
     "Invalid option `\\x%x'.\n",
     optopt);
          help();
        }
 return 1;
      default:
  abort();
      }
  for (index = optind; index < argc; index++)
    printf ("Non-option argument %s\n", argv[index]);
  graph = createGraph(is_directed);
  if (num_vertices != ((void *)0)){
    V = atoi(num_vertices) + 1;
    for (i = 1; i < V; i++)
      addVertex(graph, i);
  }
  if (file != ((void *)0))
    readFromCSV(graph, file);
  if (bc == 1) {
    betweennessCentrality(graph);
    printGraphCB(graph);
  }
  if (dot == 1)
    dumpDotGraph(graph);
  destroyCBData(graph);
  destroyGraph(graph);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct tvertex *v1; struct tvertex *v2; struct tvertex *v3; struct tvertex *v4; struct tvertex *v5; struct tvertex *v6; struct tvertex *v7; struct tvertex *v8; struct tvertex *v9; struct tvertex *v10;
  struct tvertex *w;
  struct tedge *e;
  struct tgraph *graph;
  struct tstack stack;
  struct tqueue queue;
  int V = 0;
  int i = 0;
  int dot = 0;
  int bc = 0;
  int is_directed = 1;
  int index;
  int f; int v; int c; int o;
  char *file = ((void *)0);
  char *num_vertices = ((void *)0);
  graph = createGraph(0);
  while ((f = getopt (argc, argv, "odhbf:v:")) != -1)
    switch (f)
      {
      case 'd':
 dot = 1;
 break;
      case 'b':
 bc = 1;
 break;
      case 'o':
        is_directed = 0;
        break;
      case 'f':
 file = optarg;
 break;
      case 'h':
        help();
        break;
      case 'v':
        num_vertices = optarg;
        break;
      case '?':
 if (isprint (optopt)) {
   fprintf (stderr, "Unknown option: `-%c'.\n", optopt);
          help();
        }
 else {
   fprintf (stderr,
     "Invalid option `\\x%x'.\n",
     optopt);
          help();
        }
 return 1;
      default:
  abort();
      }
  for (index = optind; index < argc; index++)
    printf ("Non-option argument %s\n", argv[index]);
  graph = createGraph(is_directed);
  if (num_vertices != ((void *)0)){
    V = atoi(num_vertices) + 1;
    for (i = 1; i < V; i++)
      addVertex(graph, i);
  }
  if (file != ((void *)0))
    readFromCSV(graph, file);
  if (bc == 1) {
    betweennessCentrality(graph);
    printGraphCB(graph);
  }
  if (dot == 1)
    dumpDotGraph(graph);
  destroyCBData(graph);
  destroyGraph(graph);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct tedge { int weight; struct tvertex { unsigned int id; struct tedge *edges; struct tvertex *next; int visited; struct cbData { double sp_num; double distance; double dependency; struct tlParents { struct tvertex *vertex; struct tlParents *next; } *parents; double rank; } *data; } *links; struct tedge *next; } *

variable_types: struct tstack { struct titem { struct tvertex { unsigned int id; struct tedge { int weight; struct tvertex *links; struct tedge *next; } *edges; struct tvertex *next; int visited; struct cbData { double sp_num; double distance; double dependency; struct tlParents { struct tvertex *vertex; struct tlParents *next; } *parents; double rank; } *data; } *item; struct titem *next; } *top; }

variable_types: struct tqueue { struct tqitem { struct tvertex { unsigned int id; struct tedge { int weight; struct tvertex *links; struct tedge *next; } *edges; struct tvertex *next; int visited; struct cbData { double sp_num; double distance; double dependency; struct tlParents { struct tvertex *vertex; struct tlParents *next; } *parents; double rank; } *data; } *item; struct tqitem *next; } *top; }

variable_types: V int

variable_types: dot int

variable_types: bc int

variable_types: index int

variable_types: f int

variable_types: v int

variable_types: c int

variable_types: o int

variable_types:
file
char *

user_defined_types: struct titem { struct tvertex *item; struct titem *next; }

user_defined_types: struct tqitem { struct tvertex *item; struct tqitem *next; }


decompiled_code:
const char *__fastcall cns_str_ereplace(char *string, char *s1, char *s)
{
char *v3; // rbp
int i; // er15
int v6; // er12
size_t v7; // rbx
size_t v8; // rax
char *v9; // rbx
int v10; // edx
const char *sa; // [rsp+0h] [rbp-58h]
__int64 v13; // [rsp+14h] [rbp-44h]

v3 = string;
sa = string;
if ( strcmp(s1, s) )
{
for ( i = 0; ; v3 = (char *)&sa[i] )
{
v13 = cns_reg(v3, s1);
if ( (_DWORD)v13 )
break;
v6 = v10;
v7 = strlen(sa);
v8 = strlen(s);
v9 = (char *)calloc(1uLL, 1LL - (v6 - HIDWORD(v13)) + v7 + v8);
strncpy(v9, sa, HIDWORD(v13) + i);
v9[HIDWORD(v13) + i] = 0;
strcat(v9, s);
strcat(v9, &v3[v6]);
sa = strdup(v9);
free(v9);
i += strlen(s) + HIDWORD(v13);
}
}
return sa;
}

canonical_decompiled_code:
const char *__fastcall func8(char *string, char *s1, char *s)
{
char *v3; // rbp
int i; // er15
int v6; // er12
size_t v7; // rbx
size_t v8; // rax
char *v9; // rbx
int v10; // edx
const char *sa; // [rsp+0h] [rbp-58h]
__int64 v13; // [rsp+14h] [rbp-44h]

v3 = string;
sa = string;
if ( strcmp(s1, s) )
{
for ( i = 0; ; v3 = (char *)&sa[i] )
{
v13 = func7(v3, s1);
if ( (_DWORD)v13 )
break;
v6 = v10;
v7 = strlen(sa);
v8 = strlen(s);
v9 = (char *)calloc(1uLL, 1LL - (v6 - HIDWORD(v13)) + v7 + v8);
strncpy(v9, sa, HIDWORD(v13) + i);
v9[HIDWORD(v13) + i] = 0;
strcat(v9, s);
strcat(v9, &v3[v6]);
sa = strdup(v9);
free(v9);
i += strlen(s) + HIDWORD(v13);
}
}
return sa;
}

original_code:
char *cns_str_ereplace(char *src, const char *pattern, const char *newsubstr)
{
    if(!strcmp(pattern, newsubstr))
       return src;
    reg_rtn_struct reg_rtn_struct_var;
    int rtn = 0;
    int pstart = 0;
    int pend = 0;
    char *dest=src;
    char *pstr=src;
    char *tmp;
    char *new_tmp_str=dest;
    int new_tmp_str_len=0;
    while(!rtn)
    {
        reg_rtn_struct_var=cns_reg(new_tmp_str, pattern);
        rtn = reg_rtn_struct_var.rtn;
        pstart = reg_rtn_struct_var.pstart;
        pend = reg_rtn_struct_var.pend;
        if(!rtn)
        {
            tmp=(char*)calloc(sizeof(char), strlen(dest)+strlen(newsubstr)-(pend-pstart)+1 );
            strncpy(tmp, dest, new_tmp_str_len+pstart);
            tmp[new_tmp_str_len+pstart]='\0';
            strcat(tmp, newsubstr);
            strcat(tmp, new_tmp_str+pend);
            dest = strdup(tmp);
            free(tmp);
            new_tmp_str_len = new_tmp_str_len + pstart + strlen(newsubstr);
            new_tmp_str=dest+new_tmp_str_len;
        }
    }
    return dest;
}

canonical_original_code:
char *cns_str_ereplace(char *src, char *pattern, char *newsubstr)
{
    if(!strcmp(pattern, newsubstr))
       return src;
    struct _reg_rtn_struct reg_rtn_struct_var;
    int rtn = 0;
    int pstart = 0;
    int pend = 0;
    char *dest = src;
    char *pstr = src;
    char *tmp;
    char *new_tmp_str = dest;
    int new_tmp_str_len = 0;
    while(!rtn)
    {
        reg_rtn_struct_var=cns_reg(new_tmp_str, pattern);
        rtn = reg_rtn_struct_var.rtn;
        pstart = reg_rtn_struct_var.pstart;
        pend = reg_rtn_struct_var.pend;
        if(!rtn)
        {
            tmp=(char *)calloc(sizeof(char), strlen(dest)+strlen(newsubstr)-(pend-pstart)+1 );
            strncpy(tmp, dest, new_tmp_str_len+pstart);
            tmp[new_tmp_str_len+pstart]='\0';
            strcat(tmp, newsubstr);
            strcat(tmp, new_tmp_str+pend);
            dest = strdup(tmp);
            free(tmp);
            new_tmp_str_len = new_tmp_str_len + pstart + strlen(newsubstr);
            new_tmp_str=dest+new_tmp_str_len;
        }
    }
    return dest;
}

variable_types:
src
char *

variable_types:
pattern
char *

variable_types:
newsubstr
char *

variable_types: struct _reg_rtn_struct { int rtn; int pstart; int pend; }

variable_types: rtn int

variable_types: pstart int

variable_types: pend int

variable_types:
dest
char *

variable_types:
pstr
char *

variable_types:
tmp
char *

return_type: char *


original_code:
int main()
{
  char str[]="唱的曲子是北宋大$natureOrder(0123)“蝶恋花”词，写的正\n怪客手掌一碰，只把她牙齿撞得隐隐生痛。$natureOrderDESC(8)开";
  reg_rtn_struct reg_rtn_struct_var;
  char *newstr=cns_str_ereplace(str,"\\$.{4,6}Order(DESC)?\\([0-9]{1,4}\\)","hello");
  puts(newstr);
  return 0;
}

canonical_original_code:
int main()
{
  char str[] = "唱的曲子是北宋大$natureOrder(0123)“蝶恋花”词，写的正\n怪客手掌一碰，只把她牙齿撞得隐隐生痛。$natureOrderDESC(8)开";
  struct _reg_rtn_struct reg_rtn_struct_var;
  char *newstr = cns_str_ereplace(str,"\\$.{4,6}Order(DESC)?\\([0-9]{1,4}\\)","hello");
  puts(newstr);
  return 0;
}

variable_types:
str
char []

variable_types:
newstr
char *

user_defined_types: struct _reg_rtn_struct { int rtn; int pstart; int pend; }


decompiled_code:
__int64 __fastcall string_comp(char *a1, char *a2)
{
char v2; // al
char v3; // dl

v2 = *a1;
if ( !*a1 )
return (unsigned int)-(*a2 != 0);
while ( 1 )
{
v3 = *a2;
if ( !*a2 )
break;
if ( v3 < v2 )
return 1LL;
if ( v3 > v2 )
return 0xFFFFFFFFLL;
++a1;
++a2;
v2 = *a1;
if ( !*a1 )
return (unsigned int)-(*a2 != 0);
}
if ( !v2 )
return (unsigned int)-(*a2 != 0);
return *a2 == 0;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, char *a2)
{
char v2; // al
char v3; // dl

v2 = *a1;
if ( !*a1 )
return (unsigned int)-(*a2 != 0);
while ( 1 )
{
v3 = *a2;
if ( !*a2 )
break;
if ( v3 < v2 )
return 1LL;
if ( v3 > v2 )
return 0xFFFFFFFFLL;
++a1;
++a2;
v2 = *a1;
if ( !*a1 )
return (unsigned int)-(*a2 != 0);
}
if ( !v2 )
return (unsigned int)-(*a2 != 0);
return *a2 == 0;
}


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

if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
{
++a1;
result = (unsigned int)(result + 1);
}
while ( *a1 );
return result;
}

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

if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
{
++a1;
result = (unsigned int)(result + 1);
}
while ( *a1 );
return result;
}

original_code:
int string_length(char* s)
{
    int len = 0;
    while(*s!='\0')
    {
        s++;
        len++;
    }
    return len;
}

canonical_original_code:
int string_length(char *s)
{
    int len = 0;
    while(*s!='\0')
    {
        s++;
        len++;
    }
    return len;
}

variable_types:
s
char *

variable_types: len int


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

v3 = string_comp("Liheyuanxx", "liheyuan");
printf("string_comp:%d\n", v3);
string_copy("Liheyuanxx", v6);
printf("copy result:%s\n", v6);
string_concat(v6, "liheyuan");
printf("concat result:%s\n", v6);
v4 = string_length(v6);
printf("length:%d\n", v4);
return 0;
}

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

v3 = func7("Liheyuanxx", "liheyuan");
printf("string_comp:%d\n", v3);
func8("Liheyuanxx", v6);
printf("copy result:%s\n", v6);
func9(v6, "liheyuan");
printf("concat result:%s\n", v6);
v4 = func10(v6);
printf("length:%d\n", v4);
return 0;
}

original_code:
int main()
{
    char* s1 = "Liheyuanxx";
    char* s2 = "liheyuan";
    char buf[1024];
    printf("string_comp:%d\n", string_comp(s1, s2));
    string_copy(s1, buf);
    printf("copy result:%s\n", buf);
    string_concat(buf, s2);
    printf("concat result:%s\n", buf);
    printf("length:%d\n", string_length(buf));
    return 0;
}

canonical_original_code:
int main()
{
    char *s1 = "Liheyuanxx";
    char *s2 = "liheyuan";
    char buf[1024];
    printf("string_comp:%d\n", string_comp(s1, s2));
    string_copy(s1, buf);
    printf("copy result:%s\n", buf);
    string_concat(buf, s2);
    printf("concat result:%s\n", buf);
    printf("length:%d\n", string_length(buf));
    return 0;
}

variable_types:
buf
char [1024]


decompiled_code:
__int64 __fastcall semaphore_p(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = -1;
sops.sem_flg = 4096;
return (unsigned int)-(semop(a1, &sops, 1uLL) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = -1;
sops.sem_flg = 4096;
return (unsigned int)-(semop(a1, &sops, 1uLL) == -1);
}

original_code:
static int semaphore_p(int sem_id)
{
 struct sembuf sem_b;
 sem_b.sem_num = 0;
 sem_b.sem_op = -1;
 sem_b.sem_flg = 0x1000;
 if (semop(sem_id, &sem_b, 1) == -1)
  return -1;
 return 0;
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


decompiled_code:
__int64 __fastcall semaphore_v(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = 1;
sops.sem_flg = 4096;
return (unsigned int)-(semop(a1, &sops, 1uLL) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 0;
sops.sem_op = 1;
sops.sem_flg = 4096;
return (unsigned int)-(semop(a1, &sops, 1uLL) == -1);
}

original_code:
static int semaphore_v(int sem_id)
{
 struct sembuf sem_b;
 sem_b.sem_num = 0;
 sem_b.sem_op = +1;
 sem_b.sem_flg = 0x1000;
 if (semop(sem_id, &sem_b, 1) == -1)
  return -1;
 return 0;
}

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


ProcessUpdate

decompiled_code:
void __fastcall ProcessUpdate(__int64 a1)
{
unsigned int v1; // er12
__suseconds_t v2; // rbp
char v3[264]; // [rsp+0h] [rbp-158h] BYREF
struct timezone tz; // [rsp+108h] [rbp-50h] BYREF
struct timeval v5; // [rsp+110h] [rbp-48h] BYREF
struct timeval tv; // [rsp+120h] [rbp-38h] BYREF

if ( (*(_BYTE *)a1 & 0xC) == 0 )
{
gettimeofday(&tv, &tz);
v1 = UpdateDomainName(a1 + 5, *(unsigned int *)(a1 + 1), *(_BYTE *)a1 & 3);
gettimeofday(&v5, &tz);
v2 = v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec;
if ( v1 )
{
SaveToFile(a1 + 5, *(unsigned int *)(a1 + 1));
if ( (*(_BYTE *)a1 & 3) == 1 )
{
gettimeofday(&tv, &tz);
AddListToBTree();
gettimeofday(&v5, &tz);
memset(v3, 0, 0x100uLL);
snprintf(
v3,
0x100uLL,
"Type: DOMAIN. Counts: %u. Update-Type: QUICK\n\t\t\t Time-Valid: %lu us Time-Total: %lu us\n",
v1,
v2,
v2 + v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec);
}
else
{
memset(v3, 0, 0x100uLL);
snprintf(
v3,
0x100uLL,
"Type: DOMAIN. Counts: %u. Update-Type: NORMAL\n \t\t\t Time-Valid: %lu us Time-Total: %lu us\n",
v1,
v2,
v2);
}
}
else
{
snprintf(
v3,
0x100uLL,
"Type: DOMAIN. <<FAILED>> Update-Type: QUICK\n\t\t\t Time-Valid: %lu us Time-Total: %lu us\n",
v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec,
v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec);
}
}
Logging("/home/shaw/Data/Logs/UpdateLog.txt", v3);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
unsigned int v1; // er12
__suseconds_t v2; // rbp
char v3[264]; // [rsp+0h] [rbp-158h] BYREF
struct timezone tz; // [rsp+108h] [rbp-50h] BYREF
struct timeval v5; // [rsp+110h] [rbp-48h] BYREF
struct timeval tv; // [rsp+120h] [rbp-38h] BYREF

if ( (*(_BYTE *)a1 & 0xC) == 0 )
{
gettimeofday(&tv, &tz);
v1 = UpdateDomainName(a1 + 5, *(unsigned int *)(a1 + 1), *(_BYTE *)a1 & 3);
gettimeofday(&v5, &tz);
v2 = v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec;
if ( v1 )
{
SaveToFile(a1 + 5, *(unsigned int *)(a1 + 1));
if ( (*(_BYTE *)a1 & 3) == 1 )
{
gettimeofday(&tv, &tz);
AddListToBTree();
gettimeofday(&v5, &tz);
memset(v3, 0, 0x100uLL);
snprintf(
v3,
0x100uLL,
"Type: DOMAIN. Counts: %u. Update-Type: QUICK\n\t\t\t Time-Valid: %lu us Time-Total: %lu us\n",
v1,
v2,
v2 + v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec);
}
else
{
memset(v3, 0, 0x100uLL);
snprintf(
v3,
0x100uLL,
"Type: DOMAIN. Counts: %u. Update-Type: NORMAL\n \t\t\t Time-Valid: %lu us Time-Total: %lu us\n",
v1,
v2,
v2);
}
}
else
{
snprintf(
v3,
0x100uLL,
"Type: DOMAIN. <<FAILED>> Update-Type: QUICK\n\t\t\t Time-Valid: %lu us Time-Total: %lu us\n",
v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec,
v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec);
}
}
func2("/home/shaw/Data/Logs/UpdateLog.txt", v3);
}

original_code:
static void ProcessUpdate(void *buffer)
{
 struct record_set_hdr *recdhdr;
 int sum=0;
        struct timeval t1,t2;
        struct timezone tz;
 unsigned long update_t, flush_t;
 char logString[256];
        recdhdr=(struct record_set_hdr *)buffer;
        if(recdhdr->data_type==0)
 {
  gettimeofday (&t1,&tz);
  sum=UpdateDomainName(buffer+sizeof(*recdhdr), recdhdr->recd_size,recdhdr->update_type);
  gettimeofday(&t2,&tz);
  update_t = (t2.tv_sec-t1.tv_sec)*1000000+(t2.tv_usec-t1.tv_usec);
  if(sum == 0)
  {
   snprintf(logString,256,"Type: DOMAIN.   <<FAILED>>   Update-Type: QUICK\n			    Time-Valid:  %lu us   Time-Total:  %lu us\n", update_t, update_t);
   goto out;
  }
         SaveToFile(buffer+sizeof(*recdhdr),recdhdr->recd_size);
  if(recdhdr->update_type==1)
  {
                 gettimeofday (&t1,&tz);
   AddListToBTree();
   gettimeofday (&t2,&tz);
   flush_t = (t2.tv_sec-t1.tv_sec)*1000000+(t2.tv_usec-t1.tv_usec);
   memset(logString, 0, 256);
   snprintf(logString,256,"Type: DOMAIN.  Counts: %u.  Update-Type: QUICK\n			    Time-Valid:  %lu us   Time-Total:  %lu us\n", sum, update_t, update_t+flush_t);
   goto out;
  }else{
   memset(logString, 0, 256);
   snprintf(logString,256,"Type: DOMAIN.  Counts: %u.  Update-Type: NORMAL\n 			    Time-Valid:  %lu us   Time-Total:  %lu us\n", sum, update_t, update_t);
   goto out;
  }
 }
out:
 Logging("/home/shaw/Data/Logs/UpdateLog.txt", logString);
}

canonical_original_code:
static void ProcessUpdate(void *buffer)
{
 struct record_set_hdr *recdhdr;
 int sum = 0;
        struct timeval t1; struct timeval t2;
        struct timezone tz;
 unsigned long update_t; unsigned long flush_t;
 char logString[256];
        recdhdr=(struct record_set_hdr *)buffer;
        if(recdhdr->data_type==0)
 {
  gettimeofday (&t1,&tz);
  sum=UpdateDomainName(buffer+sizeof(*recdhdr), recdhdr->recd_size,recdhdr->update_type);
  gettimeofday(&t2,&tz);
  update_t = (t2.tv_sec-t1.tv_sec)*1000000+(t2.tv_usec-t1.tv_usec);
  if(sum == 0)
  {
   snprintf(logString,256,"Type: DOMAIN.   <<FAILED>>   Update-Type: QUICK\n			    Time-Valid:  %lu us   Time-Total:  %lu us\n", update_t, update_t);
   goto out;
  }
         SaveToFile(buffer+sizeof(*recdhdr),recdhdr->recd_size);
  if(recdhdr->update_type==1)
  {
                 gettimeofday (&t1,&tz);
   AddListToBTree();
   gettimeofday (&t2,&tz);
   flush_t = (t2.tv_sec-t1.tv_sec)*1000000+(t2.tv_usec-t1.tv_usec);
   memset(logString, 0, 256);
   snprintf(logString,256,"Type: DOMAIN.  Counts: %u.  Update-Type: QUICK\n			    Time-Valid:  %lu us   Time-Total:  %lu us\n", sum, update_t, update_t+flush_t);
   goto out;
  }else{
   memset(logString, 0, 256);
   snprintf(logString,256,"Type: DOMAIN.  Counts: %u.  Update-Type: NORMAL\n 			    Time-Valid:  %lu us   Time-Total:  %lu us\n", sum, update_t, update_t);
   goto out;
  }
 }
out:
 Logging("/home/shaw/Data/Logs/UpdateLog.txt", logString);
}

variable_types:
buffer
void *

variable_types: struct record_set_hdr { unsigned char update_type; unsigned int recd_size; } *

variable_types: sum int

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }

variable_types:
logString
char [256]


InitSem

decompiled_code:
__int64 __fastcall InitSem()
{
__int64 v0; // rbp
key_t v1; // er12
key_t v2; // eax
key_t v3; // ebx
int v4; // eax
int v5; // eax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
char v15[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = ftok("/home/shaw/Data/", 11);
v2 = ftok("/home/shaw/Data/", 12);
if ( v1 == -1 || (v3 = v2, v2 == -1) )
{
memset(v15, 0, 0x100uLL);
v7 = _errno_location();
v8 = strerror(*v7);
snprintf(v15, 0x100uLL, "[ERROR] domainUpdate.c @ InitSem @ ftok --- %s", v8);
LABEL_9:
Logging("/home/shaw/Data/Logs/ErrorLog.txt", v15);
return 0xFFFFFFFFLL;
}
v4 = semget(v1, 1, 1968);
sem_send = v4;
if ( v4 == -1 )
{
sem_send = semget(v1, 1, 0);
if ( sem_send == -1 )
{
memset(v15, 0, 0x100uLL);
v11 = _errno_location();
v12 = strerror(*v11);
snprintf(v15, 0x100uLL, "[ERROR] domainUpdate.c @ InitSem @ semget --- %s", v12);
goto LABEL_9;
}
}
else
{
v0 = 1LL;
if ( semctl(v4, 0, 16) == -1 )
{
LABEL_10:
memset(v15, 0, 0x100uLL);
v9 = _errno_location();
v10 = strerror(*v9);
snprintf(v15, 0x100uLL, "[ERROR] domainUpdate.c @ InitSem @ semctl --- %s", v10);
goto LABEL_9;
}
}
v5 = semget(v3, 1, 1968);
sem_recv = v5;
if ( v5 != -1 )
{
if ( semctl(v5, 0, 16, v0 & 0xFFFFFFFF00000000LL) != -1 )
return 0LL;
goto LABEL_10;
}
sem_recv = semget(v3, 1, 0);
if ( sem_send == -1 )
{
memset(v15, 0, 0x100uLL);
v13 = _errno_location();
v14 = strerror(*v13);
snprintf(v15, 0x100uLL, "[ERROR] shareMem.c @ InitSem @ semget --- %s", v14);
goto LABEL_9;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4()
{
__int64 v0; // rbp
key_t v1; // er12
key_t v2; // eax
key_t v3; // ebx
int v4; // eax
int v5; // eax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
char v15[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = ftok("/home/shaw/Data/", 11);
v2 = ftok("/home/shaw/Data/", 12);
if ( v1 == -1 || (v3 = v2, v2 == -1) )
{
memset(v15, 0, 0x100uLL);
v7 = _errno_location();
v8 = strerror(*v7);
snprintf(v15, 0x100uLL, "[ERROR] domainUpdate.c @ InitSem @ ftok --- %s", v8);
LABEL_9:
func2("/home/shaw/Data/Logs/ErrorLog.txt", v15);
return 0xFFFFFFFFLL;
}
v4 = semget(v1, 1, 1968);
sem_send = v4;
if ( v4 == -1 )
{
sem_send = semget(v1, 1, 0);
if ( sem_send == -1 )
{
memset(v15, 0, 0x100uLL);
v11 = _errno_location();
v12 = strerror(*v11);
snprintf(v15, 0x100uLL, "[ERROR] domainUpdate.c @ InitSem @ semget --- %s", v12);
goto LABEL_9;
}
}
else
{
v0 = 1LL;
if ( semctl(v4, 0, 16) == -1 )
{
LABEL_10:
memset(v15, 0, 0x100uLL);
v9 = _errno_location();
v10 = strerror(*v9);
snprintf(v15, 0x100uLL, "[ERROR] domainUpdate.c @ InitSem @ semctl --- %s", v10);
goto LABEL_9;
}
}
v5 = semget(v3, 1, 1968);
sem_recv = v5;
if ( v5 != -1 )
{
if ( semctl(v5, 0, 16, v0 & 0xFFFFFFFF00000000LL) != -1 )
return 0LL;
goto LABEL_10;
}
sem_recv = semget(v3, 1, 0);
if ( sem_send == -1 )
{
memset(v15, 0, 0x100uLL);
v13 = _errno_location();
v14 = strerror(*v13);
snprintf(v15, 0x100uLL, "[ERROR] shareMem.c @ InitSem @ semget --- %s", v14);
goto LABEL_9;
}
return 0LL;
}

original_code:
static int InitSem(void)
{
 union semun sem_union;
 key_t sem_key1, sem_key2;
 char logString[256];
 sem_key1 = ftok("/home/shaw/Data/", 11);
 sem_key2 = ftok("/home/shaw/Data/", 12);
 if ((sem_key1 == -1)||(sem_key2 == -1))
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ ftok --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 sem_send = semget(sem_key1, num_sems, 01000|02000|0660);
 if(sem_send != -1)
 {
  sem_union.val = 1;
  if (semctl(sem_send, 0, 16, sem_union) == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ semctl --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }else{
  sem_send = semget(sem_key1, num_sems, 0);
  if(sem_send == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ semget --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }
 sem_recv = semget(sem_key2, num_sems, 01000|02000|0660);
 if (sem_recv != -1)
 {
  sem_union.val = 0;
  if (semctl(sem_recv, 0, 16, sem_union) == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ semctl --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }else{
  sem_recv = semget(sem_key2, num_sems, 0);
  if(sem_send == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] shareMem.c @ InitSem @ semget --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }
 return 0;
err_out:
 Logging("/home/shaw/Data/Logs/ErrorLog.txt", logString);
 return -1;
}

canonical_original_code:
static int InitSem()
{
 union semun sem_union;
 int sem_key1; int sem_key2;
 char logString[256];
 sem_key1 = ftok("/home/shaw/Data/", 11);
 sem_key2 = ftok("/home/shaw/Data/", 12);
 if ((sem_key1 == -1)||(sem_key2 == -1))
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ ftok --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 sem_send = semget(sem_key1, num_sems, 01000|02000|0660);
 if(sem_send != -1)
 {
  sem_union.val = 1;
  if (semctl(sem_send, 0, 16, sem_union) == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ semctl --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }else{
  sem_send = semget(sem_key1, num_sems, 0);
  if(sem_send == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ semget --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }
 sem_recv = semget(sem_key2, num_sems, 01000|02000|0660);
 if (sem_recv != -1)
 {
  sem_union.val = 0;
  if (semctl(sem_recv, 0, 16, sem_union) == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ semctl --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }else{
  sem_recv = semget(sem_key2, num_sems, 0);
  if(sem_send == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] shareMem.c @ InitSem @ semget --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }
 return 0;
err_out:
 Logging("/home/shaw/Data/Logs/ErrorLog.txt", logString);
 return -1;
}

variable_types: union semun { int val; struct semid_ds { struct ipc_perm { int __key; unsigned int uid; unsigned int gid; unsigned int cuid; unsigned int cgid; unsigned short mode; unsigned short __pad1; unsigned short __seq; unsigned short __pad2; unsigned long __glibc_reserved1; unsigned long __glibc_reserved2; } sem_perm; long sem_otime; unsigned long __glibc_reserved1; long sem_ctime; unsigned long __glibc_reserved2; unsigned long sem_nsems; unsigned long __glibc_reserved3; unsigned long __glibc_reserved4; } *buf; unsigned short *array; struct seminfo { int semmap; int semmni; int semmns; int semmnu; int semmsl; int semopm; int semume; int semusz; int semvmx; int semaem; } *__buf; }

user_defined_types: union semun { int val; struct semid_ds *buf; unsigned short *array; struct seminfo *__buf; }

user_defined_types: struct semid_ds { struct ipc_perm sem_perm; long sem_otime; unsigned long __glibc_reserved1; long sem_ctime; unsigned long __glibc_reserved2; unsigned long sem_nsems; unsigned long __glibc_reserved3; unsigned long __glibc_reserved4; }


InitShm

decompiled_code:
__int64 InitShm()
{
key_t v0; // eax
int v1; // edi
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
char v9[264]; // [rsp+0h] [rbp-108h] BYREF

v0 = ftok("/home/shaw/Data/", 10);
if ( v0 == -1 )
{
memset(v9, 0, 0x100uLL);
v3 = _errno_location();
v4 = strerror(*v3);
snprintf(v9, 0x100uLL, "[ERROR] domainUpdate.c @ InitShm @ ftok --- %s", v4);
}
else
{
v1 = shmget(v0, 0x100000uLL, 944);
if ( v1 == -1 )
{
memset(v9, 0, 0x100uLL);
v5 = _errno_location();
v6 = strerror(*v5);
snprintf(v9, 0x100uLL, "[ERROR] domainUpdate.c @ InitShm @ shmget --- %s", v6);
}
else
{
share_region = shmat(v1, 0LL, 0);
if ( share_region != (void *)-1LL )
return (unsigned int)-((unsigned int)InitSem() == -1);
memset(v9, 0, 0x100uLL);
v7 = _errno_location();
v8 = strerror(*v7);
snprintf(v9, 0x100uLL, "[ERROR] domainUpdate.c @ InitShm @ shmat --- %s", v8);
}
}
Logging("/home/shaw/Data/Logs/ErrorLog.txt", v9);
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
key_t v0; // eax
int v1; // edi
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
char v9[264]; // [rsp+0h] [rbp-108h] BYREF

v0 = ftok("/home/shaw/Data/", 10);
if ( v0 == -1 )
{
memset(v9, 0, 0x100uLL);
v3 = _errno_location();
v4 = strerror(*v3);
snprintf(v9, 0x100uLL, "[ERROR] domainUpdate.c @ InitShm @ ftok --- %s", v4);
}
else
{
v1 = shmget(v0, 0x100000uLL, 944);
if ( v1 == -1 )
{
memset(v9, 0, 0x100uLL);
v5 = _errno_location();
v6 = strerror(*v5);
snprintf(v9, 0x100uLL, "[ERROR] domainUpdate.c @ InitShm @ shmget --- %s", v6);
}
else
{
share_region = shmat(v1, 0LL, 0);
if ( share_region != (void *)-1LL )
return (unsigned int)-((unsigned int)func4() == -1);
memset(v9, 0, 0x100uLL);
v7 = _errno_location();
v8 = strerror(*v7);
snprintf(v9, 0x100uLL, "[ERROR] domainUpdate.c @ InitShm @ shmat --- %s", v8);
}
}
func2("/home/shaw/Data/Logs/ErrorLog.txt", v9);
return 1LL;
}

original_code:
result_t InitShm(void)
{
 key_t mem_key;
 char logString[256];
 mem_key = ftok("/home/shaw/Data/", 10);
    if(mem_key==-1)
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitShm @ ftok --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 share_id=shmget(mem_key,1024*1024,01000|0660);
        if(share_id==-1)
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitShm @ shmget --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 if((share_region=shmat(share_id, 0, 0))==(void *)(-1))
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitShm @ shmat --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 if(InitSem() == -1)
  return -1;
 return 0;
err_out:
 Logging("/home/shaw/Data/Logs/ErrorLog.txt", logString);
 return 1;
}

canonical_original_code:
int InitShm()
{
 int mem_key;
 char logString[256];
 mem_key = ftok("/home/shaw/Data/", 10);
    if(mem_key==-1)
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitShm @ ftok --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 share_id=shmget(mem_key,1024*1024,01000|0660);
        if(share_id==-1)
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitShm @ shmget --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 if((share_region=shmat(share_id, 0, 0))==(void *)(-1))
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitShm @ shmat --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 if(InitSem() == -1)
  return -1;
 return 0;
err_out:
 Logging("/home/shaw/Data/Logs/ErrorLog.txt", logString);
 return 1;
}


UpdateCreate

decompiled_code:
__int64 UpdateCreate()
{
int i; // ebx
int oldtype; // [rsp+Ch] [rbp-11Ch] BYREF
char v3[280]; // [rsp+10h] [rbp-118h] BYREF

pthread_setcanceltype(1, &oldtype);
for ( i = 0; ; ++i )
{
while ( (unsigned int)semaphore_p(sem_recv) != -1 )
{
ProcessUpdate((__int64)share_region);
i = 0;
if ( (unsigned int)semaphore_v(sem_send) == -1 )
{
InitShm();
i = 1;
}
}
memset(v3, 0, 0x100uLL);
if ( i > 2 )
break;
InitShm();
}
strcpy(v3, "[ERROR] domainUpdate.c @ UpdateCreate @ semaphore_p --- semaphore maybe destory, resume failed!");
Logging("/home/shaw/Data/Logs/ErrorLog.txt", v3);
return -1LL;
}

canonical_decompiled_code:
__int64 func6()
{
int i; // ebx
int oldtype; // [rsp+Ch] [rbp-11Ch] BYREF
char v3[280]; // [rsp+10h] [rbp-118h] BYREF

pthread_setcanceltype(1, &oldtype);
for ( i = 0; ; ++i )
{
while ( (unsigned int)func0(sem_recv) != -1 )
{
func3((__int64)share_region);
i = 0;
if ( (unsigned int)func1(sem_send) == -1 )
{
func5();
i = 1;
}
}
memset(v3, 0, 0x100uLL);
if ( i > 2 )
break;
func5();
}
strcpy(v3, "[ERROR] domainUpdate.c @ UpdateCreate @ semaphore_p --- semaphore maybe destory, resume failed!");
func2("/home/shaw/Data/Logs/ErrorLog.txt", v3);
return -1LL;
}

original_code:
void* UpdateCreate(void *arg)
{
 char logString[256];
        int oldtype, ret, retry=0;
 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,&oldtype);
 while(1)
 {
  ret = semaphore_p(sem_recv);
  if(ret == -1)
  {
   memset(logString, 0, 256);
   if(retry < 3)
   {
    InitShm();
    retry++;
    continue;
   }else{
    snprintf(logString,256,"[ERROR] domainUpdate.c @ UpdateCreate @ semaphore_p --- semaphore maybe destory, resume failed!");
    Logging("/home/shaw/Data/Logs/ErrorLog.txt", logString);
    return (void*)(-1);
   }
  }
  retry = 0;
  ProcessUpdate(share_region);
  ret = semaphore_v(sem_send);
  if(ret == -1)
  {
   InitShm();
   retry++;
  }
 }
 return arg;
}

canonical_original_code:
void *UpdateCreate(void *arg)
{
 char logString[256];
        int oldtype; int ret; int retry = 0;
 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,&oldtype);
 while(1)
 {
  ret = semaphore_p(sem_recv);
  if(ret == -1)
  {
   memset(logString, 0, 256);
   if(retry < 3)
   {
    InitShm();
    retry++;
    continue;
   }else{
    snprintf(logString,256,"[ERROR] domainUpdate.c @ UpdateCreate @ semaphore_p --- semaphore maybe destory, resume failed!");
    Logging("/home/shaw/Data/Logs/ErrorLog.txt", logString);
    return (void *)(-1);
   }
  }
  retry = 0;
  ProcessUpdate(share_region);
  ret = semaphore_v(sem_send);
  if(ret == -1)
  {
   InitShm();
   retry++;
  }
 }
 return arg;
}

variable_types:
arg
void *

variable_types: oldtype int

variable_types: ret int

variable_types: retry int


DetShm

decompiled_code:
__int64 DetShm()
{
if ( share_region )
shmdt(share_region);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
if ( share_region )
shmdt(share_region);
return 0LL;
}

original_code:
result_t DetShm(void)
{
 if(share_region!=((void *)0))
  shmdt(share_region);
 return 0;
}

canonical_original_code:
int DetShm()
{
 if(share_region!=((void *)0))
  shmdt(share_region);
 return 0;
}


hash

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

if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
result = 2 * (*(_DWORD *)a1++ ^ (unsigned int)result);
while ( *a1 );
return result;
}

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

if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
result = 2 * (*(_DWORD *)a1++ ^ (unsigned int)result);
while ( *a1 );
return result;
}

original_code:
static unsigned hash(char *string)
{
      unsigned ret_val = 0;
      int i;
      while (*string)
      {
            i = *( int *)string;
            ret_val ^= i;
            ret_val <<= 1;
            string ++;
      }
      return ret_val;
}

canonical_original_code:
static unsigned int hash(char *string)
{
      unsigned int ret_val = 0;
      int i;
      while (*string)
      {
            i = *( int *)string;
            ret_val ^= i;
            ret_val <<= 1;
            string ++;
      }
      return ret_val;
}

variable_types:
string
char *

variable_types: i int

return_type: unsigned int


printer

decompiled_code:
int __fastcall printer(const char *a1, const char *a2)
{
return printf("%s: %s\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, const char *a2)
{
return printf("%s: %s\n", a1, a2);
}

original_code:
void printer(char *string, void *data)
{
      printf("%s: %s\n", string, (char *)data);
}

variable_types:
data
void *


lookup

decompiled_code:
__int64 __fastcall lookup(char *s1, _QWORD *a2)
{
__int64 v2; // rbx

v2 = *(_QWORD *)(a2[1] + 8 * ((unsigned __int64)(unsigned int)hash(s1) % *a2));
if ( v2 )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return v2;
}
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *s1, _QWORD *a2)
{
__int64 v2; // rbx

v2 = *(_QWORD *)(a2[1] + 8 * ((unsigned __int64)(unsigned int)func7(s1) % *a2));
if ( v2 )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return v2;
}
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

original_code:
void *lookup(char *key, hash_table *table)
{
      unsigned val = hash(key) % table->size;
      bucket *ptr;
      if (((void *)0) == (table->table)[val])
            return ((void *)0);
      for ( ptr = (table->table)[val];((void *)0) != ptr; ptr = ptr->next )
      {
            if (0 == strcmp(key, ptr -> key ) )
                  return ptr->data;
      }
      return ((void *)0);
}

canonical_original_code:
void *lookup(char *key, struct hash_table *table)
{
      unsigned int val = hash(key) % table->size;
      struct bucket *ptr;
      if (((void *)0) == (table->table)[val])
            return ((void *)0);
      for ( ptr = (table->table)[val];((void *)0) != ptr; ptr = ptr->next )
      {
            if (0 == strcmp(key, ptr -> key ) )
                  return ptr->data;
      }
      return ((void *)0);
}

variable_types:
key
char *

variable_types: struct hash_table { unsigned long size; struct bucket { char *key; void *data; struct bucket *next; } **table; } *

variable_types:
val
unsigned int

user_defined_types: struct hash_table { unsigned long size; struct bucket **table; }


del

original_code:
void *del(char *key, hash_table *table)
{
      unsigned val = hash(key) % table->size;
      void *data;
      bucket *ptr, *last = ((void *)0);
      if (((void *)0) == (table->table)[val])
            return ((void *)0);
      for (last = ((void *)0), ptr = (table->table)[val];((void *)0) != ptr;last = ptr, ptr = ptr->next)
      {
            if (0 == strcmp(key, ptr -> key))
            {
                  if (last != ((void *)0) )
                  {
                        data = ptr -> data;
                        last -> next = ptr -> next;
                        free(ptr->key);
                        free(ptr);
                        return data;
                  }
                  else
                  {
                        data = ptr->data;
                        (table->table)[val] = ptr->next;
                        free(ptr->key);
                        free(ptr);
                        return data;
                  }
            }
      }
      return ((void *)0);
}

canonical_original_code:
void *del(char *key, struct hash_table *table)
{
      unsigned int val = hash(key) % table->size;
      void *data;
      struct bucket *ptr; struct bucket *last = ((void *)0);
      if (((void *)0) == (table->table)[val])
            return ((void *)0);
      for (last = ((void *)0), ptr = (table->table)[val];((void *)0) != ptr;last = ptr, ptr = ptr->next)
      {
            if (0 == strcmp(key, ptr -> key))
            {
                  if (last != ((void *)0) )
                  {
                        data = ptr -> data;
                        last -> next = ptr -> next;
                        free(ptr->key);
                        free(ptr);
                        return data;
                  }
                  else
                  {
                        data = ptr->data;
                        (table->table)[val] = ptr->next;
                        free(ptr->key);
                        free(ptr);
                        return data;
                  }
            }
      }
      return ((void *)0);
}

variable_types: struct bucket { char *key; void *data; struct bucket *next; } *


decompiled_code:
__int64 __fastcall free_node(char *a1)
{
__int64 (__fastcall *v1)(__int64); // rbx
__int64 v2; // rax

v1 = (__int64 (__fastcall *)(__int64))function;
if ( !function )
return del(a1, (_QWORD *)the_table);
v2 = del(a1, (_QWORD *)the_table);
return v1(v2);
}

canonical_decompiled_code:
__int64 __fastcall func12(char *a1)
{
__int64 (__fastcall *v1)(__int64); // rbx
__int64 v2; // rax

v1 = (__int64 (__fastcall *)(__int64))function;
if ( !function )
return func11(a1, (_QWORD *)the_table);
v2 = func11(a1, (_QWORD *)the_table);
return v1(v2);
}

original_code:
static void free_node(char *key, void *data)
{
    (void) data;
    if (function)
        function(del(key,the_table));
    else
        del(key,the_table);
}


enumerate

decompiled_code:
void __fastcall enumerate(_QWORD *a1, void (__fastcall *a2)(_QWORD, _QWORD))
{
unsigned int v2; // er12
__int64 v3; // rax
_QWORD *i; // rbx

if ( *a1 )
{
v2 = 0;
v3 = 0LL;
do
{
for ( i = *(_QWORD **)(a1[1] + 8 * v3); i; i = (_QWORD *)i[2] )
a2(*i, i[1]);
v3 = ++v2;
}
while ( (unsigned __int64)v2 < *a1 );
}
}

canonical_decompiled_code:
void __fastcall func13(_QWORD *a1, void (__fastcall *a2)(_QWORD, _QWORD))
{
unsigned int v2; // er12
__int64 v3; // rax
_QWORD *i; // rbx

if ( *a1 )
{
v2 = 0;
v3 = 0LL;
do
{
for ( i = *(_QWORD **)(a1[1] + 8 * v3); i; i = (_QWORD *)i[2] )
a2(*i, i[1]);
v3 = ++v2;
}
while ( (unsigned __int64)v2 < *a1 );
}
}

original_code:
void enumerate( hash_table *table, void (*func)(char *, void *))
{
      unsigned i;
      bucket *temp;
      for (i=0;i<table->size; i++)
      {
            if ((table->table)[i] != ((void *)0))
            {
                  for (temp = (table->table)[i];((void *)0) != temp;temp = temp -> next)
                  {
                        func(temp -> key, temp->data);
                  }
            }
      }
}

canonical_original_code:
void enumerate(struct hash_table *table, void (*func)(char *, void *))
{
      unsigned int i;
      struct bucket *temp;
      for (i=0;i<table->size; i++)
      {
            if ((table->table)[i] != ((void *)0))
            {
                  for (temp = (table->table)[i];((void *)0) != temp;temp = temp -> next)
                  {
                        func(temp -> key, temp->data);
                  }
            }
      }
}

variable_types:
func
void (*)(char *, void *)

variable_types:
i
unsigned int

user_defined_types: struct bucket { char *key; void *data; struct bucket *next; }


decompiled_code:
void __fastcall free_table(__int64 a1, __int64 a2)
{
function = a2;
the_table = a1;
enumerate((_QWORD *)a1, (void (__fastcall *)(_QWORD, _QWORD))free_node);
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
the_table = 0LL;
function = 0LL;
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, __int64 a2)
{
function = a2;
the_table = a1;
func13((_QWORD *)a1, (void (__fastcall *)(_QWORD, _QWORD))free_node);
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
the_table = 0LL;
function = 0LL;
}

original_code:
void free_table(hash_table *table, void (*func)(void *))
{
      function = func;
      the_table = table;
      enumerate( table, free_node);
      free(table->table);
      table->table = ((void *)0);
      table->size = 0;
      the_table = ((void *)0);
      function = (void (*)(void *))((void *)0);
}

canonical_original_code:
void free_table(struct hash_table *table, void (*func)(void *))
{
      function = func;
      the_table = table;
      enumerate( table, free_node);
      free(table->table);
      table->table = ((void *)0);
      table->size = 0;
      the_table = ((void *)0);
      function = (void (*)(void *))((void *)0);
}

variable_types:
func
void (*)(void *)


insert

original_code:
void *insert(char *key, void *data, hash_table *table)
{
      unsigned val = hash(key) % table->size;
      bucket *ptr;
      if (((void *)0) == (table->table)[val])
      {
            (table->table)[val] = (bucket *)malloc(sizeof(bucket));
            if (((void *)0)==(table->table)[val])
                  return ((void *)0);
            (table->table)[val] -> key = strdup(key);
            (table->table)[val] -> next = ((void *)0);
            (table->table)[val] -> data = data;
            return (table->table)[val] -> data;
      }
      for (ptr = (table->table)[val];((void *)0) != ptr; ptr = ptr -> next)
            if (0 == strcmp(key, ptr->key))
            {
                  void *old_data;
                  old_data = ptr->data;
                  ptr -> data = data;
                  return old_data;
            }
      ptr = (bucket *)malloc(sizeof(bucket));
      if (((void *)0)==ptr)
            return ((void *)0);
      ptr -> key = strdup(key);
      ptr -> data = data;
      ptr -> next = (table->table)[val];
      (table->table)[val] = ptr;
      return data;
}

canonical_original_code:
void *insert(char *key, void *data, struct hash_table *table)
{
      unsigned int val = hash(key) % table->size;
      struct bucket *ptr;
      if (((void *)0) == (table->table)[val])
      {
            (table->table)[val] = (struct bucket *)malloc(sizeof(bucket));
            if (((void *)0)==(table->table)[val])
                  return ((void *)0);
            (table->table)[val] -> key = strdup(key);
            (table->table)[val] -> next = ((void *)0);
            (table->table)[val] -> data = data;
            return (table->table)[val] -> data;
      }
      for (ptr = (table->table)[val];((void *)0) != ptr; ptr = ptr -> next)
            if (0 == strcmp(key, ptr->key))
            {
                  void *old_data;
                  old_data = ptr->data;
                  ptr -> data = data;
                  return old_data;
            }
      ptr = (struct bucket *)malloc(sizeof(bucket));
      if (((void *)0)==ptr)
            return ((void *)0);
      ptr -> key = strdup(key);
      ptr -> data = data;
      ptr -> next = (table->table)[val];
      (table->table)[val] = ptr;
      return data;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v4; // rdi
__int64 *v5; // rbp
__int64 *v6; // r12
char *v7; // rbx
char *v8; // rbx
__int64 v10[6]; // [rsp+0h] [rbp-98h]
const char *v11; // [rsp+30h] [rbp-68h]
__int64 v12[7]; // [rsp+38h] [rbp-60h] BYREF
_QWORD v13[5]; // [rsp+70h] [rbp-28h] BYREF

v11 = "The first string";
v12[0] = (__int64)"The second string";
v12[1] = (__int64)"The third string";
v12[2] = (__int64)"The fourth string";
v12[3] = (__int64)"A much longer string than the rest in this example.";
v12[4] = (__int64)"The last string";
v12[5] = 0LL;
v10[0] = (__int64)"The first data";
v10[1] = (__int64)"The second data";
v10[2] = (__int64)"The third data";
v10[3] = (__int64)"The fourth data";
v10[4] = (__int64)"The fifth datum";
v10[5] = (__int64)"The sixth piece of data";
construct_table(v13, 200LL);
v3 = 0LL;
v4 = "The first string";
do
{
insert(v4, (const char *)v10[v3++], v13);
v4 = (char *)(&v11)[v3];
}
while ( v4 );
v5 = v12;
v6 = v12;
v7 = "The first string";
do
{
putchar(10);
enumerate(v13, (void (__fastcall *)(_QWORD, _QWORD))printer);
del(v7, v13);
v7 = (char *)*v6++;
}
while ( v7 );
v8 = "The first string";
do
{
if ( lookup(v8, v13) )
printf("\nERROR: %s was deleted but is still in table.", v8);
else
printf("\n'%s' is not in table", v8);
v8 = (char *)*v5++;
}
while ( v8 );
putchar(10);
free_table((__int64)v13, 0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v4; // rdi
__int64 *v5; // rbp
__int64 *v6; // r12
char *v7; // rbx
char *v8; // rbx
__int64 v10[6]; // [rsp+0h] [rbp-98h]
const char *v11; // [rsp+30h] [rbp-68h]
__int64 v12[7]; // [rsp+38h] [rbp-60h] BYREF
_QWORD v13[5]; // [rsp+70h] [rbp-28h] BYREF

v11 = "The first string";
v12[0] = (__int64)"The second string";
v12[1] = (__int64)"The third string";
v12[2] = (__int64)"The fourth string";
v12[3] = (__int64)"A much longer string than the rest in this example.";
v12[4] = (__int64)"The last string";
v12[5] = 0LL;
v10[0] = (__int64)"The first data";
v10[1] = (__int64)"The second data";
v10[2] = (__int64)"The third data";
v10[3] = (__int64)"The fourth data";
v10[4] = (__int64)"The fifth datum";
v10[5] = (__int64)"The sixth piece of data";
construct_table(v13, 200LL);
v3 = 0LL;
v4 = "The first string";
do
{
func9(v4, (const char *)v10[v3++], v13);
v4 = (char *)(&v11)[v3];
}
while ( v4 );
v5 = v12;
v6 = v12;
v7 = "The first string";
do
{
putchar(10);
func13(v13, (void (__fastcall *)(_QWORD, _QWORD))printer);
func11(v7, v13);
v7 = (char *)*v6++;
}
while ( v7 );
v8 = "The first string";
do
{
if ( func10(v8, v13) )
printf("\nERROR: %s was deleted but is still in table.", v8);
else
printf("\n'%s' is not in table", v8);
v8 = (char *)*v5++;
}
while ( v8 );
putchar(10);
func14((__int64)v13, 0LL);
return 0;
}

original_code:
int main(void)
{
      hash_table table;
      char *strings[] = {
            "The first string",
            "The second string",
            "The third string",
            "The fourth string",
            "A much longer string than the rest in this example.",
            "The last string",
            ((void *)0)
            };
      char *junk[] = {
            "The first data",
            "The second data",
            "The third data",
            "The fourth data",
            "The fifth datum",
            "The sixth piece of data"
            };
      int i;
      void *j;
      construct_table(&table,200);
      for (i = 0; ((void *)0) != strings[i]; i++ )
            insert(strings[i], junk[i], &table);
      for (i=0;((void *)0) != strings[i];i++)
      {
            printf("\n");
            enumerate(&table, printer);
            del(strings[i],&table);
      }
      for (i=0;((void *)0) != strings[i];i++)
      {
            j = lookup(strings[i], &table);
            if (((void *)0) == j)
                  printf("\n'%s' is not in table",strings[i]);
            else
                printf("\nERROR: %s was deleted but is still in table.",strings[i]);
      }
      printf("\n");
      free_table(&table, ((void *)0));
      return 0;
}

canonical_original_code:
int main()
{
      struct hash_table table;
      char *strings[] = {
            "The first string",
            "The second string",
            "The third string",
            "The fourth string",
            "A much longer string than the rest in this example.",
            "The last string",
            ((void *)0)
            };
      char *junk[] = {
            "The first data",
            "The second data",
            "The third data",
            "The fourth data",
            "The fifth datum",
            "The sixth piece of data"
            };
      int i;
      void *j;
      construct_table(&table,200);
      for (i = 0; ((void *)0) != strings[i]; i++ )
            insert(strings[i], junk[i], &table);
      for (i=0;((void *)0) != strings[i];i++)
      {
            printf("\n");
            enumerate(&table, printer);
            del(strings[i],&table);
      }
      for (i=0;((void *)0) != strings[i];i++)
      {
            j = lookup(strings[i], &table);
            if (((void *)0) == j)
                  printf("\n'%s' is not in table",strings[i]);
            else
                printf("\nERROR: %s was deleted but is still in table.",strings[i]);
      }
      printf("\n");
      free_table(&table, ((void *)0));
      return 0;
}

variable_types: struct hash_table { unsigned long size; struct bucket { char *key; void *data; struct bucket *next; } **table; }

variable_types:
strings
char *[]

variable_types:
junk
char *[]

variable_types:
j
void *


decompiled_code:
__int64 rand_level()
{
int v0; // ebx
unsigned int v1; // ebp

v0 = 19;
v1 = 0;
do
{
v1 += rand() % 38 > 18;
--v0;
}
while ( v0 );
return v1;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // ebx
unsigned int v1; // ebp

v0 = 19;
v1 = 0;
do
{
v1 += rand() % 38 > 18;
--v0;
}
while ( v0 );
return v1;
}

variable_types: level int


decompiled_code:
__int64 __fastcall skip_list_write(__int64 a1, int a2, int a3)
{
__int64 v4; // rcx
int *v5; // rax
__int64 result; // rax
int v7; // er12
__int64 v8; // rsi
__int64 v9; // rcx
__int64 v10; // rdx
__int64 v11[23]; // [rsp+0h] [rbp-B8h]

LODWORD(v4) = *(_DWORD *)(a1 + 8);
if ( (int)v4 >= 0 )
{
v4 = (int)v4;
do
{
v5 = (int *)a1;
do
{
a1 = (__int64)v5;
v5 = *(int **)&v5[2 * (int)v4 + 4];
}
while ( v5 && *v5 < a2 );
v11[v4--] = a1;
}
while ( (int)v4 >= 0 );
}
result = *(_QWORD *)(a1 + 16);
if ( !result )
result = a1;
if ( *(_DWORD *)result == a2 )
{
*(_DWORD *)(result + 4) = a3;
}
else
{
v7 = rand_level();
result = (__int64)init_skip_list_node(v7, a2, a3);
v8 = result;
if ( v7 >= 0 )
{
result = 0LL;
do
{
v9 = v11[result];
v10 = (int)result + 2LL;
*(_QWORD *)(v8 + 8 * result + 16) = *(_QWORD *)(v9 + 8 * v10);
*(_QWORD *)(v9 + 8 * v10) = v8;
++result;
}
while ( result != v7 + 1 );
}
}
return result;
}

original_code:
int skip_list_write (skip_list_t *skip_list, int key, int value)
{
    skip_list_t *update_node[20];
    skip_list_t *node = skip_list;
    int i = skip_list->level;
    for(; i>=0; --i)
    {
        while (node->forward[i] != ((void *)0) && key > node->forward[i]->key)
        {
            node = node->forward[i];
        }
        update_node[i] = node;
    }
    node = node->forward[0] == ((void *)0) ? node : node->forward[0];
    if (key == node->key)
    {
        node->value = value;
    }
    else
    {
        int level = rand_level();
        node = init_skip_list_node(level, key, value);
        for (i = 0; i <= level; ++i)
        {
            node->forward[i] = update_node[i]->forward[i];
            update_node[i]->forward[i] = node;
        }
    }
}

canonical_original_code:
int skip_list_write(struct skip_list_struct *skip_list, int key, int value)
{
    struct skip_list_struct *update_node[20];
    struct skip_list_struct *node = skip_list;
    int i = skip_list->level;
    for(; i>=0; --i)
    {
        while (node->forward[i] != ((void *)0) && key > node->forward[i]->key)
        {
            node = node->forward[i];
        }
        update_node[i] = node;
    }
    node = node->forward[0] == ((void *)0) ? node : node->forward[0];
    if (key == node->key)
    {
        node->value = value;
    }
    else
    {
        int level = rand_level();
        node = init_skip_list_node(level, key, value);
        for (i = 0; i <= level; ++i)
        {
            node->forward[i] = update_node[i]->forward[i];
            update_node[i]->forward[i] = node;
        }
    }
}

variable_types: key int

variable_types: value int

variable_types: struct skip_list_struct { int key; int value; int level; struct skip_list_struct *forward[20]; } *[20]