LoadDisplayPointer

decompiled_code:
__int64 LoadDisplayPointer()
{
__int64 v0; // rbx
int v1; // ebp
__int64 result; // rax

v0 = (int)DataAddr(Pmem[2 * PC + 1]);
v1 = Dmem[v0];
Dmem[(int)DataAddr(FP)] = v1;
result = (unsigned int)FP;
Dmem[v0] = FP;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rbx
int v1; // ebp
__int64 result; // rax

v0 = (int)func5(Pmem[2 * PC + 1]);
v1 = Dmem[v0];
Dmem[(int)func5(FP)] = v1;
result = (unsigned int)FP;
Dmem[v0] = FP;
return result;
}

original_code:
static void LoadDisplayPointer( void )
{
    int addr, temp;
    addr = DataAddr( Pmem[PC].offset );
    temp = Dmem[ addr ];
    Dmem[ DataAddr( FP ) ] = temp;
    Dmem[ addr ] = FP;
}

canonical_original_code:
static void LoadDisplayPointer()
{
    int addr; int temp;
    addr = DataAddr( Pmem[PC].offset );
    temp = Dmem[ addr ];
    Dmem[ DataAddr( FP ) ] = temp;
    Dmem[ addr ] = FP;
}


RestoreDisplayPointer

repo: Ethanjfobrien/LanguageProcessorsProject

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

v0 = DataAddr(Pmem[2 * PC + 1]);
result = (unsigned int)Dmem[(int)DataAddr(FP)];
Dmem[v0] = result;
return result;
}

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

v0 = func5(Pmem[2 * PC + 1]);
result = (unsigned int)Dmem[(int)func5(FP)];
Dmem[v0] = result;
return result;
}

original_code:
static void RestoreDisplayPointer( void )
{
    int addr;
    addr = DataAddr( Pmem[PC].offset );
    Dmem[ addr ] = Dmem[ DataAddr( FP ) ];
}

canonical_original_code:
static void RestoreDisplayPointer()
{
    int addr;
    addr = DataAddr( Pmem[PC].offset );
    Dmem[ addr ] = Dmem[ DataAddr( FP ) ];
}

variable_types: addr int

return_type: void


Pop

decompiled_code:
__int64 Pop()
{
if ( dword_6B4 < 0 )
{
AddressError("Stack Underflow");
exit(1);
}
return (unsigned int)Dmem[dword_6B4--];
}

canonical_decompiled_code:
__int64 func9()
{
if ( dword_6B4 < 0 )
{
func0("Stack Underflow");
exit(1);
}
return (unsigned int)Dmem[dword_6B4--];
}

original_code:
static int Pop( void )
{
    int temp;
    if ( SP < 0 ) {
        AddressError( "Stack Underflow" );
        exit( 1 );
    }
    else {
        temp = Dmem[SP];
        SP--;
    }
    return temp;
}

canonical_original_code:
static int Pop()
{
    int temp;
    if ( SP < 0 ) {
        AddressError( "Stack Underflow" );
        exit( 1 );
    }
    else {
        temp = Dmem[SP];
        SP--;
    }
    return temp;
}

variable_types: temp int

return_type: int


BinaryOp

decompiled_code:
__int64 __fastcall BinaryOp(int a1)
{
int v1; // er12
int v2; // eax
int v3; // ebp

v1 = Pop();
v2 = Pop();
v3 = v2;
if ( a1 == 3 )
{
v3 = v1 * v2;
return Push(v3);
}
if ( a1 > 3 )
{
if ( a1 == 4 )
{
v3 = v2 / v1;
return Push(v3);
}
LABEL_11:
DisplayError(0LL, "Error, illegal opcode in BinaryOp, %d\n", (unsigned int)a1);
return Push(v3);
}
if ( a1 == 1 )
{
v3 = v1 + v2;
return Push(v3);
}
if ( a1 != 2 )
goto LABEL_11;
v3 = v2 - v1;
return Push(v3);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
int v1; // er12
int v2; // eax
int v3; // ebp

v1 = func9();
v2 = func9();
v3 = v2;
if ( a1 == 3 )
{
v3 = v1 * v2;
return func3(v3);
}
if ( a1 > 3 )
{
if ( a1 == 4 )
{
v3 = v2 / v1;
return func3(v3);
}
LABEL_11:
DisplayError(0LL, "Error, illegal opcode in BinaryOp, %d\n", (unsigned int)a1);
return func3(v3);
}
if ( a1 == 1 )
{
v3 = v1 + v2;
return func3(v3);
}
if ( a1 != 2 )
goto LABEL_11;
v3 = v2 - v1;
return func3(v3);
}

original_code:
static void BinaryOp( int opcode )
{
    int tos, tos_m1;
    tos = Pop(); tos_m1 = Pop();
    switch ( opcode ) {
        case 1 : tos_m1 += tos; break;
        case 2 : tos_m1 -= tos; break;
        case 3 : tos_m1 *= tos; break;
        case 4 : tos_m1 /= tos; break;
        default:
            DisplayError( !1, "Error, illegal opcode in BinaryOp, %d\n",
                          opcode );
            break;
    }
    Push( tos_m1 );
}

canonical_original_code:
static void BinaryOp(int opcode)
{
    int tos; int tos_m1;
    tos = Pop(); tos_m1 = Pop();
    switch ( opcode ) {
        case 1 : tos_m1 += tos; break;
        case 2 : tos_m1 -= tos; break;
        case 3 : tos_m1 *= tos; break;
        case 4 : tos_m1 /= tos; break;
        default:
            DisplayError( !1, "Error, illegal opcode in BinaryOp, %d\n",
                          opcode );
            break;
    }
    Push( tos_m1 );
}

variable_types: opcode int

variable_types: tos int


Branch

decompiled_code:
__int64 __fastcall Branch(unsigned int a1)
{
unsigned int v1; // ebp
int v3; // edx

v1 = Pmem[2 * PC + 1];
if ( a1 != 6 )
{
v3 = Pop();
switch ( a1 )
{
case 6u:
return v1;
case 7u:
if ( v3 < 0 )
v1 = PC + 1;
break;
case 8u:
if ( v3 <= 0 )
v1 = PC + 1;
break;
case 9u:
if ( v3 > 0 )
v1 = PC + 1;
break;
case 0xAu:
if ( v3 >= 0 )
v1 = PC + 1;
break;
case 0xBu:
if ( v3 )
v1 = PC + 1;
break;
case 0xCu:
if ( !v3 )
v1 = PC + 1;
break;
default:
DisplayError(0LL, "Error, illegal opcode in Branch, %d\n", a1);
break;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
unsigned int v1; // ebp
int v3; // edx

v1 = Pmem[2 * PC + 1];
if ( a1 != 6 )
{
v3 = func9();
switch ( a1 )
{
case 6u:
return v1;
case 7u:
if ( v3 < 0 )
v1 = PC + 1;
break;
case 8u:
if ( v3 <= 0 )
v1 = PC + 1;
break;
case 9u:
if ( v3 > 0 )
v1 = PC + 1;
break;
case 0xAu:
if ( v3 >= 0 )
v1 = PC + 1;
break;
case 0xBu:
if ( v3 )
v1 = PC + 1;
break;
case 0xCu:
if ( !v3 )
v1 = PC + 1;
break;
default:
DisplayError(0LL, "Error, illegal opcode in Branch, %d\n", a1);
break;
}
}
return v1;
}

original_code:
static int Branch( int opcode )
{
    int flag = 0,
        nextaddr;
    nextaddr = Pmem[PC].offset;
    if ( opcode != 6 ) flag = Pop();
    switch ( opcode ) {
        case 6 : break;
        case 7 : if ( flag < 0 ) nextaddr = PC+1; break;
        case 8 : if ( flag <= 0 ) nextaddr = PC+1; break;
        case 9 : if ( flag > 0 ) nextaddr = PC+1; break;
        case 10 : if ( flag >= 0 ) nextaddr = PC+1; break;
        case 11 : if ( flag != 0 ) nextaddr = PC+1; break;
        case 12 : if ( flag == 0 ) nextaddr = PC+1; break;
        default:
            DisplayError( !1, "Error, illegal opcode in Branch, %d\n",
                          opcode );
            break;
    }
    return nextaddr;
}

canonical_original_code:
static int Branch(int opcode)
{
    int flag = 0; int nextaddr;
    nextaddr = Pmem[PC].offset;
    if ( opcode != 6 ) flag = Pop();
    switch ( opcode ) {
        case 6 : break;
        case 7 : if ( flag < 0 ) nextaddr = PC+1; break;
        case 8 : if ( flag <= 0 ) nextaddr = PC+1; break;
        case 9 : if ( flag > 0 ) nextaddr = PC+1; break;
        case 10 : if ( flag >= 0 ) nextaddr = PC+1; break;
        case 11 : if ( flag != 0 ) nextaddr = PC+1; break;
        case 12 : if ( flag == 0 ) nextaddr = PC+1; break;
        default:
            DisplayError( !1, "Error, illegal opcode in Branch, %d\n",
                          opcode );
            break;
    }
    return nextaddr;
}

variable_types: flag int

variable_types: nextaddr int


WriteInteger

decompiled_code:
__int64 WriteInteger()
{
unsigned int v0; // eax

v0 = Pop();
return WriteOut("\n!! Write instruction, Top of Stack --> \"%d\"\n\n", v0);
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int v0; // eax

v0 = func9();
return WriteOut("\n!! Write instruction, Top of Stack --> \"%d\"\n\n", v0);
}

original_code:
static void WriteInteger( void )
{
    WriteOut( "\n!! Write instruction, Top of Stack --> \"%d\"\n\n", Pop() );
}

canonical_original_code:
static void WriteInteger()
{
    WriteOut( "\n!! Write instruction, Top of Stack --> \"%d\"\n\n", Pop() );
}


ReadInteger

decompiled_code:
__int64 ReadInteger()
{
const char *i; // rdi
int v2; // [rsp+Ch] [rbp-Ch] BYREF

WriteOut("\n!! Read instruction, Enter integer --> ");
for ( i = (const char *)ReadString(); sscanf(i, " %d", &v2) != 1; i = (const char *)ReadString() )
WriteOut(" Invalid integer, try again --> ");
return Push(v2);
}

canonical_decompiled_code:
__int64 func13()
{
const char *i; // rdi
int v2; // [rsp+Ch] [rbp-Ch] BYREF

WriteOut("\n!! Read instruction, Enter integer --> ");
for ( i = (const char *)ReadString(); sscanf(i, " %d", &v2) != 1; i = (const char *)ReadString() )
WriteOut(" Invalid integer, try again --> ");
return func3(v2);
}

original_code:
static void ReadInteger( void )
{
    char *buffer;
    int value;
    WriteOut( "\n!! Read instruction, Enter integer --> " );
    buffer = ReadString();
    while ( 1 != sscanf( buffer, " %d", &value ) ) {
        WriteOut( "   Invalid integer, try again --> " );
        buffer = ReadString();
    }
    Push( value );
}

canonical_original_code:
static void ReadInteger()
{
    char *buffer;
    int value;
    WriteOut( "\n!! Read instruction, Enter integer --> " );
    buffer = ReadString();
    while ( 1 != sscanf( buffer, " %d", &value ) ) {
        WriteOut( "   Invalid integer, try again --> " );
        buffer = ReadString();
    }
    Push( value );
}

variable_types:
buffer
char *

variable_types: value int


Interpret

decompiled_code:
__int64 Interpret()
{
int v0; // er12
int v1; // ebp
unsigned int v2; // ebx
__int64 result; // rax
unsigned int v4; // eax
int v5; // eax
int v6; // eax
int v7; // edx
int v8; // ebx
int v9; // ebx
unsigned int v10; // eax
int v11; // eax
int v12; // ebx

v0 = Pmem[2 * PC + 1];
v1 = PC + 1;
v2 = Pmem[2 * PC];
switch ( v2 )
{
case 0u:
result = WriteOut("!! HALT encountered\n\n");
Running = 0;
break;
case 1u:
result = BinaryOp(1);
break;
case 2u:
result = BinaryOp(2);
break;
case 3u:
result = BinaryOp(3);
break;
case 4u:
result = BinaryOp(4);
break;
case 5u:
result = dword_6B4;
Dmem[dword_6B4] = -Dmem[dword_6B4];
break;
case 6u:
result = Branch(6u);
v1 = result;
break;
case 7u:
result = Branch(7u);
v1 = result;
break;
case 8u:
result = Branch(8u);
v1 = result;
break;
case 9u:
result = Branch(9u);
v1 = result;
break;
case 0xAu:
result = Branch(0xAu);
v1 = result;
break;
case 0xBu:
result = Branch(0xBu);
v1 = result;
break;
case 0xCu:
result = Branch(0xCu);
v1 = result;
break;
case 0xDu:
Push(v1);
result = CodeAddr(v0);
v1 = result;
break;
case 0xEu:
v4 = Pop();
result = CodeAddr(v4);
v1 = result;
break;
case 0xFu:
result = BuildStackFrame();
break;
case 0x10u:
result = RemoveStackFrame();
break;
case 0x11u:
result = LoadDisplayPointer();
break;
case 0x12u:
result = RestoreDisplayPointer();
break;
case 0x13u:
result = DataAddr(dword_6B4 + v0);
dword_6B4 = result;
break;
case 0x14u:
result = Decrement(dword_6B4, v0);
dword_6B4 = result;
break;
case 0x15u:
result = Push(FP);
break;
case 0x16u:
result = Push(v0);
break;
case 0x17u:
v5 = DataAddr(v0);
result = Push(Dmem[v5]);
break;
case 0x18u:
v6 = DataAddr(FP + v0);
result = Push(Dmem[v6]);
break;
case 0x19u:
v7 = Dmem[(int)DataAddr(Dmem[dword_6B4] + v0)];
result = dword_6B4;
Dmem[dword_6B4] = v7;
break;
case 0x1Au:
v8 = DataAddr(v0);
result = Pop();
Dmem[v8] = result;
break;
case 0x1Bu:
v9 = DataAddr(FP + v0);
result = Pop();
Dmem[v9] = result;
break;
case 0x1Cu:
v10 = Pop();
v11 = DataAddr(v10);
v12 = DataAddr(v11 + v0);
result = Pop();
Dmem[v12] = result;
break;
case 0x1Du:
result = ReadInteger();
break;
case 0x1Eu:
result = WriteInteger();
break;
default:
DisplayError(0LL, "Error, unknown opcode encountered\n");
result = DisplayError(
1LL,
"PC = %d, SP = %d, FP = %d, opcode = %d\n",
(unsigned int)PC,
(unsigned int)dword_6B4,
(unsigned int)FP,
v2);
break;
}
PC = v1;
return result;
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // er12
int v1; // ebp
unsigned int v2; // ebx
__int64 result; // rax
unsigned int v4; // eax
int v5; // eax
int v6; // eax
int v7; // edx
int v8; // ebx
int v9; // ebx
unsigned int v10; // eax
int v11; // eax
int v12; // ebx

v0 = Pmem[2 * PC + 1];
v1 = PC + 1;
v2 = Pmem[2 * PC];
switch ( v2 )
{
case 0u:
result = WriteOut("!! HALT encountered\n\n");
Running = 0;
break;
case 1u:
result = func10(1);
break;
case 2u:
result = func10(2);
break;
case 3u:
result = func10(3);
break;
case 4u:
result = func10(4);
break;
case 5u:
result = dword_6B4;
Dmem[dword_6B4] = -Dmem[dword_6B4];
break;
case 6u:
result = func11(6u);
v1 = result;
break;
case 7u:
result = func11(7u);
v1 = result;
break;
case 8u:
result = func11(8u);
v1 = result;
break;
case 9u:
result = func11(9u);
v1 = result;
break;
case 0xAu:
result = func11(0xAu);
v1 = result;
break;
case 0xBu:
result = func11(0xBu);
v1 = result;
break;
case 0xCu:
result = func11(0xCu);
v1 = result;
break;
case 0xDu:
func3(v1);
result = func1(v0);
v1 = result;
break;
case 0xEu:
v4 = func9();
result = func1(v4);
v1 = result;
break;
case 0xFu:
result = func4();
break;
case 0x10u:
result = func6();
break;
case 0x11u:
result = func7();
break;
case 0x12u:
result = func8();
break;
case 0x13u:
result = func5(dword_6B4 + v0);
dword_6B4 = result;
break;
case 0x14u:
result = func2(dword_6B4, v0);
dword_6B4 = result;
break;
case 0x15u:
result = func3(FP);
break;
case 0x16u:
result = func3(v0);
break;
case 0x17u:
v5 = func5(v0);
result = func3(Dmem[v5]);
break;
case 0x18u:
v6 = func5(FP + v0);
result = func3(Dmem[v6]);
break;
case 0x19u:
v7 = Dmem[(int)func5(Dmem[dword_6B4] + v0)];
result = dword_6B4;
Dmem[dword_6B4] = v7;
break;
case 0x1Au:
v8 = func5(v0);
result = func9();
Dmem[v8] = result;
break;
case 0x1Bu:
v9 = func5(FP + v0);
result = func9();
Dmem[v9] = result;
break;
case 0x1Cu:
v10 = func9();
v11 = func5(v10);
v12 = func5(v11 + v0);
result = func9();
Dmem[v12] = result;
break;
case 0x1Du:
result = func13();
break;
case 0x1Eu:
result = func12();
break;
default:
DisplayError(0LL, "Error, unknown opcode encountered\n");
result = DisplayError(
1LL,
"PC = %d, SP = %d, FP = %d, opcode = %d\n",
(unsigned int)PC,
(unsigned int)dword_6B4,
(unsigned int)FP,
v2);
break;
}
PC = v1;
return result;
}

original_code:
void Interpret( void )
{
    INSTRUCTION current;
    int addr, nextaddr;
    current = Pmem[PC];
    nextaddr = PC+1;
    switch ( current.opcode ) {
        case 0: WriteOut( "!! HALT encountered\n\n" );
                       Running = 0; break;
        case 1: BinaryOp( 1 ); break;
        case 2: BinaryOp( 2 ); break;
        case 3: BinaryOp( 3 ); break;
        case 4: BinaryOp( 4 ); break;
        case 5: Dmem[SP] = -Dmem[SP]; break;
        case 6: nextaddr = Branch( 6 ); break;
        case 7: nextaddr = Branch( 7 ); break;
        case 8: nextaddr = Branch( 8 ); break;
        case 9: nextaddr = Branch( 9 ); break;
        case 10: nextaddr = Branch( 10 ); break;
        case 11: nextaddr = Branch( 11 ); break;
        case 12: nextaddr = Branch( 12 ); break;
        case 13: Push( nextaddr );
                       nextaddr = CodeAddr( current.offset ); break;
        case 14: nextaddr = CodeAddr( Pop() ); break;
        case 15: BuildStackFrame(); break;
        case 16: RemoveStackFrame(); break;
        case 17: LoadDisplayPointer(); break;
        case 18: RestoreDisplayPointer(); break;
        case 19: SP = DataAddr( SP + current.offset ); break;
        case 20: SP = Decrement( SP, current.offset ); break;
        case 21: Push( FP ); break;
        case 22: Push( current.offset ); break;
        case 23: addr = DataAddr( current.offset );
                       Push( Dmem[addr] ); break;
        case 24: addr = DataAddr( FP + current.offset );
                       Push( Dmem[addr] ); break;
        case 25: addr = DataAddr( Dmem[SP] + current.offset );
                       Dmem[SP] = Dmem[addr]; break;
        case 26: addr = DataAddr( current.offset );
                       Dmem[addr] = Pop(); break;
        case 27: addr = DataAddr( FP + current.offset );
                       Dmem[addr] = Pop(); break;
        case 28: addr = DataAddr( Pop() );
                       addr = DataAddr( addr + current.offset );
                       Dmem[addr] = Pop(); break;
        case 29: ReadInteger(); break;
        case 30: WriteInteger(); break;
        default:
            DisplayError( !1, "Error, unknown opcode encountered\n" );
            DisplayError( 1, "PC = %d, SP = %d, FP = %d, opcode = %d\n",
                          PC, SP, FP, current.opcode );
            break;
    }
    PC = nextaddr;
}

canonical_original_code:
void Interpret()
{
    struct INSTRUCTION current;
    int addr; int nextaddr;
    current = Pmem[PC];
    nextaddr = PC+1;
    switch ( current.opcode ) {
        case 0: WriteOut( "!! HALT encountered\n\n" );
                       Running = 0; break;
        case 1: BinaryOp( 1 ); break;
        case 2: BinaryOp( 2 ); break;
        case 3: BinaryOp( 3 ); break;
        case 4: BinaryOp( 4 ); break;
        case 5: Dmem[SP] = -Dmem[SP]; break;
        case 6: nextaddr = Branch( 6 ); break;
        case 7: nextaddr = Branch( 7 ); break;
        case 8: nextaddr = Branch( 8 ); break;
        case 9: nextaddr = Branch( 9 ); break;
        case 10: nextaddr = Branch( 10 ); break;
        case 11: nextaddr = Branch( 11 ); break;
        case 12: nextaddr = Branch( 12 ); break;
        case 13: Push( nextaddr );
                       nextaddr = CodeAddr( current.offset ); break;
        case 14: nextaddr = CodeAddr( Pop() ); break;
        case 15: BuildStackFrame(); break;
        case 16: RemoveStackFrame(); break;
        case 17: LoadDisplayPointer(); break;
        case 18: RestoreDisplayPointer(); break;
        case 19: SP = DataAddr( SP + current.offset ); break;
        case 20: SP = Decrement( SP, current.offset ); break;
        case 21: Push( FP ); break;
        case 22: Push( current.offset ); break;
        case 23: addr = DataAddr( current.offset );
                       Push( Dmem[addr] ); break;
        case 24: addr = DataAddr( FP + current.offset );
                       Push( Dmem[addr] ); break;
        case 25: addr = DataAddr( Dmem[SP] + current.offset );
                       Dmem[SP] = Dmem[addr]; break;
        case 26: addr = DataAddr( current.offset );
                       Dmem[addr] = Pop(); break;
        case 27: addr = DataAddr( FP + current.offset );
                       Dmem[addr] = Pop(); break;
        case 28: addr = DataAddr( Pop() );
                       addr = DataAddr( addr + current.offset );
                       Dmem[addr] = Pop(); break;
        case 29: ReadInteger(); break;
        case 30: WriteInteger(); break;
        default:
            DisplayError( !1, "Error, unknown opcode encountered\n" );
            DisplayError( 1, "PC = %d, SP = %d, FP = %d, opcode = %d\n",
                          PC, SP, FP, current.opcode );
            break;
    }
    PC = nextaddr;
}

variable_types: struct INSTRUCTION { int opcode; int offset; }


UnGetToken

decompiled_code:
void __fastcall UnGetToken(int a1, int a2)
{
pbtoken = a1;
pboffset = a2;
pushback = 1;
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2)
{
pbtoken = a1;
pboffset = a2;
pushback = 1;
}

original_code:
static void UnGetToken( int token, int offset )
{
    pbtoken = token;
    pboffset = offset;
    pushback = 1;
}

canonical_original_code:
static void UnGetToken(int token, int offset)
{
    pbtoken = token;
    pboffset = offset;
    pushback = 1;
}

variable_types: token int

variable_types: offset int


GetToken

decompiled_code:
__int64 __fastcall GetToken(int *a1)
{
int v1; // er12
unsigned int v2; // ebp
int v3; // er14
int v4; // ebx
__int64 result; // rax
unsigned __int16 v6; // ax
bool v7; // zf
int v8; // edx
int v9; // edx
int v10; // edx
int v11; // edx
int v12; // edx
int v13; // edx
int v14; // edx
int v15; // edx
int v16; // edx
int v17; // edx
int v18; // edx
int v19; // edx
int v20; // edx
int v21; // edx
int v22; // edx
int v23; // edx
int v24; // edx
int v25; // edx
int v26; // edx
char v27[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = pushback;
v2 = pushback;
v3 = pushback;
if ( pushback )
{
*a1 = pboffset;
pushback = 0;
return (unsigned int)pbtoken;
}
while ( 2 )
{
v4 = fgetc(InputFile);
switch ( v2 )
{
case 0u:
if ( v4 == 10 )
{
result = 4294967293LL;
goto LABEL_62;
}
if ( v4 == 59 )
{
v2 = 7;
}
else
{
v6 = (*_ctype_b_loc())[v4];
if ( (v6 & 0x2000) == 0 )
{
if ( (v6 & 0x400) != 0 )
{
v27[v3++] = toupper(v4);
v2 = 1;
}
else if ( (v6 & 0x800) != 0 )
{
v1 = v4 + 10 * v1 - 48;
v2 = 2;
}
else
{
switch ( v4 )
{
case '+':
result = 4294967289LL;
goto LABEL_62;
case '-':
result = 4294967288LL;
goto LABEL_62;
case '#':
result = 4294967287LL;
goto LABEL_62;
}
if ( v4 != 91 )
{
result = 2 * (unsigned int)(v4 != -1) - 4;
goto LABEL_62;
}
v2 = 3;
}
}
}
continue;
case 1u:
if ( ((*_ctype_b_loc())[v4] & 0x400) != 0 )
{
if ( v3 <= 28 )
v27[v3++] = toupper(v4);
continue;
}
ungetc(v4, InputFile);
v27[v3] = 0;
v7 = strcmp(v27, "HALT") == 0;
result = !v7;
if ( !v7 )
{
result = v2;
if ( strcmp(v27, "ADD") )
{
result = 2LL;
if ( strcmp(v27, "SUB") )
{
result = 3LL;
if ( strcmp(v27, "MULT") )
{
result = 4LL;
if ( strcmp(v27, "DIV") )
{
result = 5LL;
if ( strcmp(v27, "NEG") )
{
result = 6LL;
if ( strcmp(v27, "BR") )
{
result = 7LL;
if ( strcmp(v27, "BGZ") )
{
v8 = strcmp(v27, "BG");
result = 8LL;
if ( v8 )
{
v9 = strcmp(v27, "BLZ");
result = 9LL;
if ( v9 )
{
v10 = strcmp(v27, "BL");
result = 10LL;
if ( v10 )
{
v11 = strcmp(v27, "BZ");
result = 11LL;
if ( v11 )
{
v12 = strcmp(v27, "BNZ");
result = 12LL;
if ( v12 )
{
v13 = strcmp(v27, "CALL");
result = 13LL;
if ( v13 )
{
v14 = strcmp(v27, "RET");
result = 14LL;
if ( v14 )
{
v15 = strcmp(v27, "BSF");
result = 15LL;
if ( v15 )
{
v16 = strcmp(v27, "RSF");
result = 16LL;
if ( v16 )
{
v17 = strcmp(v27, "LDP");
result = 17LL;
if ( v17 )
{
v18 = strcmp(v27, "RDP");
result = 18LL;
if ( v18 )
{
v19 = strcmp(v27, "INC");
result = 19LL;
if ( v19 )
{
v20 = strcmp(v27, "DEC");
result = 20LL;
if ( v20 )
{
v21 = strcmp(v27, "PUSH");
result = 21LL;
if ( v21 )
{
v22 = strcmp(v27, "LOAD");
result = 4294967291LL;
if ( v22 )
{
v23 = strcmp(v27, "STORE");
result = 4294967290LL;
if ( v23 )
{
v24 = strcmp(v27, "READ");
result = 29LL;
if ( v24 )
{
v25 = strcmp(v27, "WRITE");
result = 30LL;
if ( v25 )
{
v26 = strcmp(v27, "FP");
result = 4294967285LL;
if ( v26 )
{
DisplayError(1LL, "Unknown string \"%s\"\n", v27);
result = 4294967286LL;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
LABEL_62:
*a1 = v1;
return result;
case 2u:
if ( ((*_ctype_b_loc())[v4] & 0x800) == 0 )
{
ungetc(v4, InputFile);
result = 0xFFFFFFFFLL;
goto LABEL_62;
}
v1 = v4 + 10 * v1 - 48;
continue;
case 3u:
v2 = 2 * (toupper(v4) != 83) + 4;
continue;
case 4u:
v2 = (toupper(v4) != 80) + 5;
continue;
case 5u:
if ( v4 == 93 )
{
result = 4294967284LL;
goto LABEL_62;
}
v2 = 6;
continue;
case 6u:
DisplayError(1LL, "Error, illegal token scanned\n");
continue;
case 7u:
if ( v4 == 10 )
{
result = 4294967293LL;
goto LABEL_62;
}
if ( v4 == -1 )
{
result = 4294967292LL;
goto LABEL_62;
}
continue;
default:
DisplayError(1LL, "Error, illegal scanner state\n");
continue;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
int v1; // er12
unsigned int v2; // ebp
int v3; // er14
int v4; // ebx
__int64 result; // rax
unsigned __int16 v6; // ax
bool v7; // zf
int v8; // edx
int v9; // edx
int v10; // edx
int v11; // edx
int v12; // edx
int v13; // edx
int v14; // edx
int v15; // edx
int v16; // edx
int v17; // edx
int v18; // edx
int v19; // edx
int v20; // edx
int v21; // edx
int v22; // edx
int v23; // edx
int v24; // edx
int v25; // edx
int v26; // edx
char v27[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = pushback;
v2 = pushback;
v3 = pushback;
if ( pushback )
{
*a1 = pboffset;
pushback = 0;
return (unsigned int)pbtoken;
}
while ( 2 )
{
v4 = fgetc(InputFile);
switch ( v2 )
{
case 0u:
if ( v4 == 10 )
{
result = 4294967293LL;
goto LABEL_62;
}
if ( v4 == 59 )
{
v2 = 7;
}
else
{
v6 = (*_ctype_b_loc())[v4];
if ( (v6 & 0x2000) == 0 )
{
if ( (v6 & 0x400) != 0 )
{
v27[v3++] = toupper(v4);
v2 = 1;
}
else if ( (v6 & 0x800) != 0 )
{
v1 = v4 + 10 * v1 - 48;
v2 = 2;
}
else
{
switch ( v4 )
{
case '+':
result = 4294967289LL;
goto LABEL_62;
case '-':
result = 4294967288LL;
goto LABEL_62;
case '#':
result = 4294967287LL;
goto LABEL_62;
}
if ( v4 != 91 )
{
result = 2 * (unsigned int)(v4 != -1) - 4;
goto LABEL_62;
}
v2 = 3;
}
}
}
continue;
case 1u:
if ( ((*_ctype_b_loc())[v4] & 0x400) != 0 )
{
if ( v3 <= 28 )
v27[v3++] = toupper(v4);
continue;
}
ungetc(v4, InputFile);
v27[v3] = 0;
v7 = strcmp(v27, "HALT") == 0;
result = !v7;
if ( !v7 )
{
result = v2;
if ( strcmp(v27, "ADD") )
{
result = 2LL;
if ( strcmp(v27, "SUB") )
{
result = 3LL;
if ( strcmp(v27, "MULT") )
{
result = 4LL;
if ( strcmp(v27, "DIV") )
{
result = 5LL;
if ( strcmp(v27, "NEG") )
{
result = 6LL;
if ( strcmp(v27, "BR") )
{
result = 7LL;
if ( strcmp(v27, "BGZ") )
{
v8 = strcmp(v27, "BG");
result = 8LL;
if ( v8 )
{
v9 = strcmp(v27, "BLZ");
result = 9LL;
if ( v9 )
{
v10 = strcmp(v27, "BL");
result = 10LL;
if ( v10 )
{
v11 = strcmp(v27, "BZ");
result = 11LL;
if ( v11 )
{
v12 = strcmp(v27, "BNZ");
result = 12LL;
if ( v12 )
{
v13 = strcmp(v27, "CALL");
result = 13LL;
if ( v13 )
{
v14 = strcmp(v27, "RET");
result = 14LL;
if ( v14 )
{
v15 = strcmp(v27, "BSF");
result = 15LL;
if ( v15 )
{
v16 = strcmp(v27, "RSF");
result = 16LL;
if ( v16 )
{
v17 = strcmp(v27, "LDP");
result = 17LL;
if ( v17 )
{
v18 = strcmp(v27, "RDP");
result = 18LL;
if ( v18 )
{
v19 = strcmp(v27, "INC");
result = 19LL;
if ( v19 )
{
v20 = strcmp(v27, "DEC");
result = 20LL;
if ( v20 )
{
v21 = strcmp(v27, "PUSH");
result = 21LL;
if ( v21 )
{
v22 = strcmp(v27, "LOAD");
result = 4294967291LL;
if ( v22 )
{
v23 = strcmp(v27, "STORE");
result = 4294967290LL;
if ( v23 )
{
v24 = strcmp(v27, "READ");
result = 29LL;
if ( v24 )
{
v25 = strcmp(v27, "WRITE");
result = 30LL;
if ( v25 )
{
v26 = strcmp(v27, "FP");
result = 4294967285LL;
if ( v26 )
{
DisplayError(1LL, "Unknown string \"%s\"\n", v27);
result = 4294967286LL;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
LABEL_62:
*a1 = v1;
return result;
case 2u:
if ( ((*_ctype_b_loc())[v4] & 0x800) == 0 )
{
ungetc(v4, InputFile);
result = 0xFFFFFFFFLL;
goto LABEL_62;
}
v1 = v4 + 10 * v1 - 48;
continue;
case 3u:
v2 = 2 * (toupper(v4) != 83) + 4;
continue;
case 4u:
v2 = (toupper(v4) != 80) + 5;
continue;
case 5u:
if ( v4 == 93 )
{
result = 4294967284LL;
goto LABEL_62;
}
v2 = 6;
continue;
case 6u:
DisplayError(1LL, "Error, illegal token scanned\n");
continue;
case 7u:
if ( v4 == 10 )
{
result = 4294967293LL;
goto LABEL_62;
}
if ( v4 == -1 )
{
result = 4294967292LL;
goto LABEL_62;
}
continue;
default:
DisplayError(1LL, "Error, illegal scanner state\n");
continue;
}
}
}

original_code:
static int GetToken( int *offset )
{
    int ch, token = 0, i = 0, state = 0, quit = 0, intvalue = 0;
    char buffer[30];
    if ( pushback ) {
        *offset = pboffset; pushback = 0; return pbtoken;
    }
    while ( !quit ) {
        ch = fgetc( InputFile );
        switch ( state ) {
            case 0 :
                if ( ch == '\n' ) {
                    quit = 1; token = -3;
                }
                else if ( ch == ';' ) state = 7;
                else if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISspace) ) state = 0;
                else if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISalpha) ) {
                    *(buffer+i) = (char)toupper( ch ); i++;
                    state = 1;
                }
                else if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISdigit) ) {
                    intvalue *= 10; intvalue += ( ch - '0' );
                    state = 2;
                }
                else if ( ch == '+' ) {
                    quit = 1; token = -7;
                }
                else if ( ch == '-' ) {
                    quit = 1; token = -8;
                }
                else if ( ch == '#' ) {
                    quit = 1; token = -9;
                }
                else if ( ch == '[' ) {
                    state = 3;
                }
                else if ( ch == (-1) ) {
                    quit = 1; token = -4;
                }
                else {
                    quit = 1; token = -2;
                }
                break;
            case 1 :
                if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISalpha) ) {
                    if ( i < 29 ) {
                        *(buffer+i) = (char)toupper( ch ); i++;
                    }
                }
                else {
                    ungetc( ch, InputFile );
                    *(buffer+i) = '\0';
                    token = -10;
                    quit = 1;
                }
                break;
            case 2 :
                if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISdigit) ) {
                    intvalue *= 10; intvalue += ( ch - '0' );
                }
                else {
                    ungetc( ch, InputFile );
                    token = -1;
                    quit = 1;
                }
                break;
            case 3 :
                ch = toupper( ch );
                if ( ch == 'S' ) state = 4; else state = 6;
                break;
            case 4 :
                ch = toupper( ch );
                if ( ch == 'P' ) state = 5; else state = 6;
                break;
            case 5 :
                if ( ch == ']' ) {
                    token = -12;
                    quit = 1;
                }
                else state = 6;
                break;
            case 6 :
                DisplayError( 1, "Error, illegal token scanned\n" );
                break;
            case 7 :
                if ( ch == '\n' ) {
                    token = -3;
                    quit = 1;
                }
                else if ( ch == (-1) ) {
                    token = -4;
                    quit = 1;
                }
                else state = 7;
                break;
            default :
                DisplayError( 1, "Error, illegal scanner state\n" );
                break;
        }
    }
    if ( token == -10 ) {
        if ( 0 == strcmp( buffer, "HALT" ) ) token = 0;
        else if ( 0 == strcmp( buffer, "ADD" ) ) token = 1;
        else if ( 0 == strcmp( buffer, "SUB" ) ) token = 2;
        else if ( 0 == strcmp( buffer, "MULT" ) ) token = 3;
        else if ( 0 == strcmp( buffer, "DIV" ) ) token = 4;
        else if ( 0 == strcmp( buffer, "NEG" ) ) token = 5;
        else if ( 0 == strcmp( buffer, "BR" ) ) token = 6;
        else if ( 0 == strcmp( buffer, "BGZ" ) ) token = 7;
        else if ( 0 == strcmp( buffer, "BG" ) ) token = 8;
        else if ( 0 == strcmp( buffer, "BLZ" ) ) token = 9;
        else if ( 0 == strcmp( buffer, "BL" ) ) token = 10;
        else if ( 0 == strcmp( buffer, "BZ" ) ) token = 11;
        else if ( 0 == strcmp( buffer, "BNZ" ) ) token = 12;
        else if ( 0 == strcmp( buffer, "CALL" ) ) token = 13;
        else if ( 0 == strcmp( buffer, "RET" ) ) token = 14;
        else if ( 0 == strcmp( buffer, "BSF" ) ) token = 15;
        else if ( 0 == strcmp( buffer, "RSF" ) ) token = 16;
        else if ( 0 == strcmp( buffer, "LDP" ) ) token = 17;
        else if ( 0 == strcmp( buffer, "RDP" ) ) token = 18;
        else if ( 0 == strcmp( buffer, "INC" ) ) token = 19;
        else if ( 0 == strcmp( buffer, "DEC" ) ) token = 20;
        else if ( 0 == strcmp( buffer, "PUSH" ) ) token = 21;
        else if ( 0 == strcmp( buffer, "LOAD" ) ) token = -5;
        else if ( 0 == strcmp( buffer, "STORE" ) ) token = -6;
        else if ( 0 == strcmp( buffer, "READ" ) ) token = 29;
        else if ( 0 == strcmp( buffer, "WRITE" ) ) token = 30;
        else if ( 0 == strcmp( buffer, "FP" ) ) token = -11;
        else DisplayError( 1, "Unknown string \"%s\"\n", buffer );
    }
    *offset = intvalue;
    return token;
}

canonical_original_code:
static int GetToken(int *offset)
{
    int ch; int token = 0; int i = 0; int state = 0; int quit = 0; int intvalue = 0;
    char buffer[30];
    if ( pushback ) {
        *offset = pboffset; pushback = 0; return pbtoken;
    }
    while ( !quit ) {
        ch = fgetc( InputFile );
        switch ( state ) {
            case 0 :
                if ( ch == '\n' ) {
                    quit = 1; token = -3;
                }
                else if ( ch == ';' ) state = 7;
                else if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISspace) ) state = 0;
                else if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISalpha) ) {
                    *(buffer+i) = (char)toupper( ch ); i++;
                    state = 1;
                }
                else if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISdigit) ) {
                    intvalue *= 10; intvalue += ( ch - '0' );
                    state = 2;
                }
                else if ( ch == '+' ) {
                    quit = 1; token = -7;
                }
                else if ( ch == '-' ) {
                    quit = 1; token = -8;
                }
                else if ( ch == '#' ) {
                    quit = 1; token = -9;
                }
                else if ( ch == '[' ) {
                    state = 3;
                }
                else if ( ch == (-1) ) {
                    quit = 1; token = -4;
                }
                else {
                    quit = 1; token = -2;
                }
                break;
            case 1 :
                if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISalpha) ) {
                    if ( i < 29 ) {
                        *(buffer+i) = (char)toupper( ch ); i++;
                    }
                }
                else {
                    ungetc( ch, InputFile );
                    *(buffer+i) = '\0';
                    token = -10;
                    quit = 1;
                }
                break;
            case 2 :
                if ( ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISdigit) ) {
                    intvalue *= 10; intvalue += ( ch - '0' );
                }
                else {
                    ungetc( ch, InputFile );
                    token = -1;
                    quit = 1;
                }
                break;
            case 3 :
                ch = toupper( ch );
                if ( ch == 'S' ) state = 4; else state = 6;
                break;
            case 4 :
                ch = toupper( ch );
                if ( ch == 'P' ) state = 5; else state = 6;
                break;
            case 5 :
                if ( ch == ']' ) {
                    token = -12;
                    quit = 1;
                }
                else state = 6;
                break;
            case 6 :
                DisplayError( 1, "Error, illegal token scanned\n" );
                break;
            case 7 :
                if ( ch == '\n' ) {
                    token = -3;
                    quit = 1;
                }
                else if ( ch == (-1) ) {
                    token = -4;
                    quit = 1;
                }
                else state = 7;
                break;
            default :
                DisplayError( 1, "Error, illegal scanner state\n" );
                break;
        }
    }
    if ( token == -10 ) {
        if ( 0 == strcmp( buffer, "HALT" ) ) token = 0;
        else if ( 0 == strcmp( buffer, "ADD" ) ) token = 1;
        else if ( 0 == strcmp( buffer, "SUB" ) ) token = 2;
        else if ( 0 == strcmp( buffer, "MULT" ) ) token = 3;
        else if ( 0 == strcmp( buffer, "DIV" ) ) token = 4;
        else if ( 0 == strcmp( buffer, "NEG" ) ) token = 5;
        else if ( 0 == strcmp( buffer, "BR" ) ) token = 6;
        else if ( 0 == strcmp( buffer, "BGZ" ) ) token = 7;
        else if ( 0 == strcmp( buffer, "BG" ) ) token = 8;
        else if ( 0 == strcmp( buffer, "BLZ" ) ) token = 9;
        else if ( 0 == strcmp( buffer, "BL" ) ) token = 10;
        else if ( 0 == strcmp( buffer, "BZ" ) ) token = 11;
        else if ( 0 == strcmp( buffer, "BNZ" ) ) token = 12;
        else if ( 0 == strcmp( buffer, "CALL" ) ) token = 13;
        else if ( 0 == strcmp( buffer, "RET" ) ) token = 14;
        else if ( 0 == strcmp( buffer, "BSF" ) ) token = 15;
        else if ( 0 == strcmp( buffer, "RSF" ) ) token = 16;
        else if ( 0 == strcmp( buffer, "LDP" ) ) token = 17;
        else if ( 0 == strcmp( buffer, "RDP" ) ) token = 18;
        else if ( 0 == strcmp( buffer, "INC" ) ) token = 19;
        else if ( 0 == strcmp( buffer, "DEC" ) ) token = 20;
        else if ( 0 == strcmp( buffer, "PUSH" ) ) token = 21;
        else if ( 0 == strcmp( buffer, "LOAD" ) ) token = -5;
        else if ( 0 == strcmp( buffer, "STORE" ) ) token = -6;
        else if ( 0 == strcmp( buffer, "READ" ) ) token = 29;
        else if ( 0 == strcmp( buffer, "WRITE" ) ) token = 30;
        else if ( 0 == strcmp( buffer, "FP" ) ) token = -11;
        else DisplayError( 1, "Unknown string \"%s\"\n", buffer );
    }
    *offset = intvalue;
    return token;
}

variable_types:
offset
int *

variable_types: ch int

variable_types: i int

variable_types: state int

variable_types: quit int

variable_types: intvalue int

variable_types:
buffer
char [30]


ReadAddress

decompiled_code:
__int64 __fastcall ReadAddress(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)GetToken((int *)v2) != -1 )
return DisplayError(1LL, "Positve integer expected as address\n");
result = v2[0];
if ( v2[0] > 0x3FF )
return DisplayError(1LL, "Target address out of range in branch or call\n");
*(_DWORD *)(a1 + 4) = v2[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)func1((int *)v2) != -1 )
return DisplayError(1LL, "Positve integer expected as address\n");
result = v2[0];
if ( v2[0] > 0x3FF )
return DisplayError(1LL, "Target address out of range in branch or call\n");
*(_DWORD *)(a1 + 4) = v2[0];
return result;
}

original_code:
static void ReadAddress( INSTRUCTION *instruction )
{
    int token, address;
    token = GetToken( &address );
    if ( token != -1 ) {
        DisplayError( 1, "Positve integer expected as address\n" );
    }
    else if ( address < 0 || address >= 1024 ) {
        DisplayError( 1, "Target address out of range in branch or call\n" );
    }
    else instruction->offset = address;
}

canonical_original_code:
static void ReadAddress(struct INSTRUCTION *instruction)
{
    int token; int address;
    token = GetToken( &address );
    if ( token != -1 ) {
        DisplayError( 1, "Positve integer expected as address\n" );
    }
    else if ( address < 0 || address >= 1024 ) {
        DisplayError( 1, "Target address out of range in branch or call\n" );
    }
    else instruction->offset = address;
}

variable_types: struct INSTRUCTION { int opcode; int offset; } *

variable_types: address int


ReadNatural

decompiled_code:
__int64 __fastcall ReadNatural(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)GetToken((int *)v2) != -1 )
return DisplayError(1LL, "Positve integer expected as argument of INC or DEC\n");
result = v2[0];
if ( v2[0] > 0x3FF )
return DisplayError(1LL, "Argument of INC or DEC out of range\n");
*(_DWORD *)(a1 + 4) = v2[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)func1((int *)v2) != -1 )
return DisplayError(1LL, "Positve integer expected as argument of INC or DEC\n");
result = v2[0];
if ( v2[0] > 0x3FF )
return DisplayError(1LL, "Argument of INC or DEC out of range\n");
*(_DWORD *)(a1 + 4) = v2[0];
return result;
}

original_code:
static void ReadNatural( INSTRUCTION *instruction )
{
    int token, natural;
    token = GetToken( &natural );
    if ( token != -1 ) {
        DisplayError( 1, "Positve integer expected as argument of INC or DEC\n" );
    }
    else if ( natural < 0 || natural >= 1024 ) {
        DisplayError( 1, "Argument of INC or DEC out of range\n" );
    }
    else instruction->offset = natural;
}

canonical_original_code:
static void ReadNatural(struct INSTRUCTION *instruction)
{
    int token; int natural;
    token = GetToken( &natural );
    if ( token != -1 ) {
        DisplayError( 1, "Positve integer expected as argument of INC or DEC\n" );
    }
    else if ( natural < 0 || natural >= 1024 ) {
        DisplayError( 1, "Argument of INC or DEC out of range\n" );
    }
    else instruction->offset = natural;
}

variable_types: natural int

user_defined_types: struct INSTRUCTION { int opcode; int offset; }


ReadOffset

decompiled_code:
void __fastcall ReadOffset(__int64 a1)
{
int v1; // ebx
int v2[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = GetToken(v2);
if ( (unsigned int)(v1 + 8) <= 1 )
{
if ( (unsigned int)GetToken(v2) == -1 )
{
if ( v1 == -8 )
*(_DWORD *)(a1 + 4) = -v2[0];
else
*(_DWORD *)(a1 + 4) = v2[0];
}
else
{
DisplayError(1LL, "Reading offset value, integer expected\n");
}
}
else if ( (unsigned int)(v1 + 4) <= 1 )
{
UnGetToken(v1, v2[0]);
*(_DWORD *)(a1 + 4) = 0;
}
else
{
DisplayError(1LL, "Reading offset value, + or - expected\n");
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
int v1; // ebx
int v2[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = func1(v2);
if ( (unsigned int)(v1 + 8) <= 1 )
{
if ( (unsigned int)func1(v2) == -1 )
{
if ( v1 == -8 )
*(_DWORD *)(a1 + 4) = -v2[0];
else
*(_DWORD *)(a1 + 4) = v2[0];
}
else
{
DisplayError(1LL, "Reading offset value, integer expected\n");
}
}
else if ( (unsigned int)(v1 + 4) <= 1 )
{
func0(v1, v2[0]);
*(_DWORD *)(a1 + 4) = 0;
}
else
{
DisplayError(1LL, "Reading offset value, + or - expected\n");
}
}

original_code:
static void ReadOffset( INSTRUCTION *instruction )
{
    int token, negative, branch;
    token = GetToken( &branch );
    if ( token == -7 || token == -8 ) {
        if ( token == -8 ) negative = 1; else negative = 0;
        token = GetToken( &branch );
        if ( token == -1 ) {
            if ( negative ) instruction->offset = -branch;
            else instruction->offset = branch;
        }
        else {
            DisplayError( 1, "Reading offset value, integer expected\n" );
        }
    }
    else if ( token == -3 || token == -4 ) {
        UnGetToken( token, branch );
        instruction->offset = 0;
    }
    else {
        DisplayError( 1, "Reading offset value, + or - expected\n" );
    }
}

canonical_original_code:
static void ReadOffset(struct INSTRUCTION *instruction)
{
    int token; int negative; int branch;
    token = GetToken( &branch );
    if ( token == -7 || token == -8 ) {
        if ( token == -8 ) negative = 1; else negative = 0;
        token = GetToken( &branch );
        if ( token == -1 ) {
            if ( negative ) instruction->offset = -branch;
            else instruction->offset = branch;
        }
        else {
            DisplayError( 1, "Reading offset value, integer expected\n" );
        }
    }
    else if ( token == -3 || token == -4 ) {
        UnGetToken( token, branch );
        instruction->offset = 0;
    }
    else {
        DisplayError( 1, "Reading offset value, + or - expected\n" );
    }
}

variable_types: negative int

variable_types: branch int


ReadLoadStore

decompiled_code:
void __fastcall ReadLoadStore(_DWORD *a1, int a2)
{
int v2; // eax
int v3; // ebp
unsigned int v4; // eax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = GetToken(v5);
switch ( v2 )
{
case -11:
*a1 = 3 * (a2 != -5) + 24;
ReadOffset((__int64)a1);
break;
case -9:
if ( a2 == -5 )
{
*a1 = 22;
v3 = GetToken(v5);
v4 = v3 + 8;
if ( v3 == -1 || v4 <= 1 )
{
if ( v4 <= 1 )
{
if ( (unsigned int)GetToken(v5) != -1 )
DisplayError(1LL, "Reading LOAD #<datum>, integer expected\n");
if ( v3 == -8 )
v5[0] = -v5[0];
}
a1[1] = v5[0];
}
else
{
DisplayError(1LL, "Reading LOAD #<datum>, integer expected\n");
}
}
else
{
DisplayError(1LL, "Immediate mode illgal with STORE\n");
}
break;
case -1:
*a1 = 3 * (a2 != -5) + 23;
if ( v5[0] > 0x3FFu )
DisplayError(1LL, "Data address out of range\n");
else
a1[1] = v5[0];
break;
case -12:
*a1 = 3 * (a2 != -5) + 25;
ReadOffset((__int64)a1);
break;
default:
DisplayError(1LL, "Unknown form of LOAD or STORE encountered\n");
break;
}
}

canonical_decompiled_code:
void __fastcall func5(_DWORD *a1, int a2)
{
int v2; // eax
int v3; // ebp
unsigned int v4; // eax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = func1(v5);
switch ( v2 )
{
case -11:
*a1 = 3 * (a2 != -5) + 24;
func4((__int64)a1);
break;
case -9:
if ( a2 == -5 )
{
*a1 = 22;
v3 = func1(v5);
v4 = v3 + 8;
if ( v3 == -1 || v4 <= 1 )
{
if ( v4 <= 1 )
{
if ( (unsigned int)func1(v5) != -1 )
DisplayError(1LL, "Reading LOAD #<datum>, integer expected\n");
if ( v3 == -8 )
v5[0] = -v5[0];
}
a1[1] = v5[0];
}
else
{
DisplayError(1LL, "Reading LOAD #<datum>, integer expected\n");
}
}
else
{
DisplayError(1LL, "Immediate mode illgal with STORE\n");
}
break;
case -1:
*a1 = 3 * (a2 != -5) + 23;
if ( v5[0] > 0x3FFu )
DisplayError(1LL, "Data address out of range\n");
else
a1[1] = v5[0];
break;
case -12:
*a1 = 3 * (a2 != -5) + 25;
func4((__int64)a1);
break;
default:
DisplayError(1LL, "Unknown form of LOAD or STORE encountered\n");
break;
}
}

original_code:
static void ReadLoadStore( INSTRUCTION *instruction, int class )
{
    int token, branch, negative;
    token = GetToken( &branch );
    if ( token == -11 ) {
        if ( class == -5 ) instruction->opcode = 24;
        else instruction->opcode = 27;
        ReadOffset( instruction );
    }
    else if ( token == -9 ) {
        if ( class == -5 ) {
            instruction->opcode = 22;
            token = GetToken( &branch );
            if ( token != -1 && token != -7 && token != -8 ) {
                DisplayError( 1, "Reading LOAD #<datum>, integer expected\n" );
            }
            else {
                if ( token == -7 || token == -8 ) {
      if ( token == -8 ) negative = 1; else negative = 0;
                    token = GetToken( &branch );
                    if ( token != -1 ) {
                        DisplayError( 1,
                                 "Reading LOAD #<datum>, integer expected\n" );
                    }
                    if ( negative ) branch = -branch;
                }
                instruction->offset = branch;
            }
        }
        else DisplayError( 1, "Immediate mode illgal with STORE\n" );
    }
    else if ( token == -1 ) {
        if ( class == -5 ) instruction->opcode = 23;
        else instruction->opcode = 26;
        if ( branch < 0 || branch >= 1024 ) {
            DisplayError( 1, "Data address out of range\n" );
        }
        else instruction->offset = branch;
    }
    else if ( token == -12 ) {
        if ( class == -5 ) instruction->opcode = 25;
        else instruction->opcode = 28;
        ReadOffset( instruction );
    }
    else {
        DisplayError( 1, "Unknown form of LOAD or STORE encountered\n" );
    }
}

canonical_original_code:
static void ReadLoadStore(struct INSTRUCTION *instruction, int class)
{
    int token; int branch; int negative;
    token = GetToken( &branch );
    if ( token == -11 ) {
        if ( class == -5 ) instruction->opcode = 24;
        else instruction->opcode = 27;
        ReadOffset( instruction );
    }
    else if ( token == -9 ) {
        if ( class == -5 ) {
            instruction->opcode = 22;
            token = GetToken( &branch );
            if ( token != -1 && token != -7 && token != -8 ) {
                DisplayError( 1, "Reading LOAD #<datum>, integer expected\n" );
            }
            else {
                if ( token == -7 || token == -8 ) {
      if ( token == -8 ) negative = 1; else negative = 0;
                    token = GetToken( &branch );
                    if ( token != -1 ) {
                        DisplayError( 1,
                                 "Reading LOAD #<datum>, integer expected\n" );
                    }
                    if ( negative ) branch = -branch;
                }
                instruction->offset = branch;
            }
        }
        else DisplayError( 1, "Immediate mode illgal with STORE\n" );
    }
    else if ( token == -1 ) {
        if ( class == -5 ) instruction->opcode = 23;
        else instruction->opcode = 26;
        if ( branch < 0 || branch >= 1024 ) {
            DisplayError( 1, "Data address out of range\n" );
        }
        else instruction->offset = branch;
    }
    else if ( token == -12 ) {
        if ( class == -5 ) instruction->opcode = 25;
        else instruction->opcode = 28;
        ReadOffset( instruction );
    }
    else {
        DisplayError( 1, "Unknown form of LOAD or STORE encountered\n" );
    }
}

variable_types: class int


ReadInstruction

decompiled_code:
__int64 __fastcall ReadInstruction(unsigned int *a1)
{
unsigned int i; // ebx
unsigned int v2; // ebp
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = GetToken(v4); i == -3; i = GetToken(v4) )
;
if ( i == -1 )
i = GetToken(v4);
switch ( i )
{
case 0xFFFFFFFA:
ReadLoadStore(a1, -6);
v2 = 1;
goto LABEL_8;
case 0xFFFFFFFB:
ReadLoadStore(a1, -5);
v2 = 1;
goto LABEL_8;
case 0xFFFFFFFC:
return 0;
case 0xFFFFFFFE:
DisplayError(1LL, "Error, invalid token\n");
v2 = 0;
goto LABEL_8;
case 0u:
case 1u:
case 2u:
case 3u:
case 4u:
case 5u:
case 0xEu:
case 0xFu:
case 0x10u:
case 0x15u:
case 0x1Du:
case 0x1Eu:
*a1 = i;
a1[1] = 0;
v2 = 1;
goto LABEL_7;
case 6u:
case 7u:
case 8u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0x11u:
case 0x12u:
*a1 = i;
ReadAddress((__int64)a1);
v2 = 1;
goto LABEL_7;
case 0x13u:
case 0x14u:
*a1 = i;
ReadNatural((__int64)a1);
v2 = 1;
goto LABEL_7;
default:
DisplayError(0LL, "Error, unknown token read ");
DisplayError(1LL, "%d\n", i);
v2 = 0;
LABEL_7:
if ( i + 4 > 1 )
{
LABEL_8:
while ( (unsigned int)GetToken(v4) + 4 > 1 )
;
}
return v2;
}
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
unsigned int i; // ebx
unsigned int v2; // ebp
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = func1(v4); i == -3; i = func1(v4) )
;
if ( i == -1 )
i = func1(v4);
switch ( i )
{
case 0xFFFFFFFA:
func5(a1, -6);
v2 = 1;
goto LABEL_8;
case 0xFFFFFFFB:
func5(a1, -5);
v2 = 1;
goto LABEL_8;
case 0xFFFFFFFC:
return 0;
case 0xFFFFFFFE:
DisplayError(1LL, "Error, invalid token\n");
v2 = 0;
goto LABEL_8;
case 0u:
case 1u:
case 2u:
case 3u:
case 4u:
case 5u:
case 0xEu:
case 0xFu:
case 0x10u:
case 0x15u:
case 0x1Du:
case 0x1Eu:
*a1 = i;
a1[1] = 0;
v2 = 1;
goto LABEL_7;
case 6u:
case 7u:
case 8u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0x11u:
case 0x12u:
*a1 = i;
func2((__int64)a1);
v2 = 1;
goto LABEL_7;
case 0x13u:
case 0x14u:
*a1 = i;
func3((__int64)a1);
v2 = 1;
goto LABEL_7;
default:
DisplayError(0LL, "Error, unknown token read ");
DisplayError(1LL, "%d\n", i);
v2 = 0;
LABEL_7:
if ( i + 4 > 1 )
{
LABEL_8:
while ( (unsigned int)func1(v4) + 4 > 1 )
;
}
return v2;
}
}

original_code:
int ReadInstruction( INSTRUCTION *Instruction )
{
    int token, offset, status = 0;
    token = GetToken( &offset );
    while ( token == -3 )
        token = GetToken( &offset );
    if ( token == -1 )
        token = GetToken( &offset );
    switch ( token ) {
        case -4: status = 0; break;
        case 0:
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 14:
        case 15:
        case 16:
        case 21:
        case 29:
        case 30: Instruction->opcode = token;
                        Instruction->offset = 0;
                        status = 1; break;
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
        case 11:
        case 12:
        case 17:
        case 18:
        case 13: Instruction->opcode = token;
                        ReadAddress( Instruction );
                        status = 1; break;
        case 19:
        case 20: Instruction->opcode = token;
                        ReadNatural( Instruction );
                        status = 1; break;
        case -5: ReadLoadStore( Instruction, -5 );
                        status = 1; break;
        case -6: ReadLoadStore( Instruction, -6 );
                        status = 1; break;
        case -2: DisplayError( 1, "Error, invalid token\n" );
                        break;
        default: DisplayError( !1, "Error, unknown token read  " );
                        DisplayError( 1, "%d\n", token );
                        break;
    }
    while ( token != -3 && token != -4 )
        token = GetToken( &offset );
    return status;
}

canonical_original_code:
int ReadInstruction(struct INSTRUCTION *Instruction)
{
    int token; int offset; int status = 0;
    token = GetToken( &offset );
    while ( token == -3 )
        token = GetToken( &offset );
    if ( token == -1 )
        token = GetToken( &offset );
    switch ( token ) {
        case -4: status = 0; break;
        case 0:
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 14:
        case 15:
        case 16:
        case 21:
        case 29:
        case 30: Instruction->opcode = token;
                        Instruction->offset = 0;
                        status = 1; break;
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
        case 11:
        case 12:
        case 17:
        case 18:
        case 13: Instruction->opcode = token;
                        ReadAddress( Instruction );
                        status = 1; break;
        case 19:
        case 20: Instruction->opcode = token;
                        ReadNatural( Instruction );
                        status = 1; break;
        case -5: ReadLoadStore( Instruction, -5 );
                        status = 1; break;
        case -6: ReadLoadStore( Instruction, -6 );
                        status = 1; break;
        case -2: DisplayError( 1, "Error, invalid token\n" );
                        break;
        default: DisplayError( !1, "Error, unknown token read  " );
                        DisplayError( 1, "%d\n", token );
                        break;
    }
    while ( token != -3 && token != -4 )
        token = GetToken( &offset );
    return status;
}

variable_types: status int


Disassemble

decompiled_code:
unsigned int __fastcall Disassemble(unsigned int *a1, char *a2)
{
unsigned int v2; // ebx
unsigned int result; // eax
char dest[34]; // [rsp+6h] [rbp-22h] BYREF

v2 = *a1;
if ( *a1 > 0x1E )
return sprintf(a2, "Unknown opcode %d\n", v2);
strcpy(dest, (&mnemonics)[v2]);
switch ( v2 )
{
case 0u:
case 1u:
case 2u:
case 3u:
case 4u:
case 5u:
case 0xEu:
case 0xFu:
case 0x10u:
case 0x1Du:
case 0x1Eu:
result = (unsigned int)strcpy(a2, dest);
break;
case 6u:
case 7u:
case 8u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0x11u:
case 0x12u:
case 0x13u:
case 0x14u:
case 0x17u:
case 0x1Au:
result = sprintf(a2, "%-8s%-4d", dest, a1[1]);
break;
case 0x15u:
goto LABEL_8;
case 0x16u:
result = sprintf(a2, "%-8s#%-4d", dest, a1[1]);
break;
case 0x18u:
case 0x1Bu:
if ( a1[1] )
result = sprintf(a2, "%-8sFP%-+4d", dest);
else
LABEL_8:
result = sprintf(a2, "%-8sFP", dest);
break;
case 0x19u:
case 0x1Cu:
if ( a1[1] )
result = sprintf(a2, "%-8s[SP]%-+4d", dest);
else
result = sprintf(a2, "%-8s[SP]", dest);
break;
default:
result = fprintf(stderr, "Error - shouldn't be here, %d %d\n", v2, a1[1]);
break;
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func0(unsigned int *a1, char *a2)
{
unsigned int v2; // ebx
unsigned int result; // eax
char dest[34]; // [rsp+6h] [rbp-22h] BYREF

v2 = *a1;
if ( *a1 > 0x1E )
return sprintf(a2, "Unknown opcode %d\n", v2);
strcpy(dest, (&mnemonics)[v2]);
switch ( v2 )
{
case 0u:
case 1u:
case 2u:
case 3u:
case 4u:
case 5u:
case 0xEu:
case 0xFu:
case 0x10u:
case 0x1Du:
case 0x1Eu:
result = (unsigned int)strcpy(a2, dest);
break;
case 6u:
case 7u:
case 8u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0x11u:
case 0x12u:
case 0x13u:
case 0x14u:
case 0x17u:
case 0x1Au:
result = sprintf(a2, "%-8s%-4d", dest, a1[1]);
break;
case 0x15u:
goto LABEL_8;
case 0x16u:
result = sprintf(a2, "%-8s#%-4d", dest, a1[1]);
break;
case 0x18u:
case 0x1Bu:
if ( a1[1] )
result = sprintf(a2, "%-8sFP%-+4d", dest);
else
LABEL_8:
result = sprintf(a2, "%-8sFP", dest);
break;
case 0x19u:
case 0x1Cu:
if ( a1[1] )
result = sprintf(a2, "%-8s[SP]%-+4d", dest);
else
result = sprintf(a2, "%-8s[SP]", dest);
break;
default:
result = fprintf(stderr, "Error - shouldn't be here, %d %d\n", v2, a1[1]);
break;
}
return result;
}

original_code:
void Disassemble( INSTRUCTION *inst, char *buffer )
{
    char temp[10];
    if ( inst->opcode < 0 || inst->opcode > 30 ) {
        sprintf( buffer, "Unknown opcode %d\n", inst->opcode );
    }
    else {
        strcpy( temp, mnemonics[inst->opcode] );
        switch ( inst->opcode ) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 14:
            case 15:
            case 16:
            case 29:
            case 30: strcpy( buffer, temp );
                            break;
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 17:
            case 18:
            case 19:
            case 20:
            case 23:
            case 26: sprintf( buffer, "%-8s%-4d", temp, inst->offset );
                            break;
            case 21: sprintf( buffer, "%-8sFP", temp );
                            break;
            case 22: sprintf( buffer, "%-8s#%-4d", temp, inst->offset );
                            break;
            case 24:
            case 27:
                if ( inst->offset == 0 ) sprintf( buffer, "%-8sFP", temp );
                else sprintf( buffer, "%-8sFP%-+4d", temp, inst->offset );
                break;
            case 25:
            case 28:
                if ( inst->offset == 0 ) sprintf( buffer, "%-8s[SP]", temp );
                else sprintf( buffer, "%-8s[SP]%-+4d", temp, inst->offset );
                break;
            default:
                fprintf( stderr, "Error - shouldn't be here, %d %d\n",
                         inst->opcode, inst->offset );
                break;
        }
    }
}

canonical_original_code:
void Disassemble(struct INSTRUCTION *inst, char *buffer)
{
    char temp[10];
    if ( inst->opcode < 0 || inst->opcode > 30 ) {
        sprintf( buffer, "Unknown opcode %d\n", inst->opcode );
    }
    else {
        strcpy( temp, mnemonics[inst->opcode] );
        switch ( inst->opcode ) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 14:
            case 15:
            case 16:
            case 29:
            case 30: strcpy( buffer, temp );
                            break;
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 17:
            case 18:
            case 19:
            case 20:
            case 23:
            case 26: sprintf( buffer, "%-8s%-4d", temp, inst->offset );
                            break;
            case 21: sprintf( buffer, "%-8sFP", temp );
                            break;
            case 22: sprintf( buffer, "%-8s#%-4d", temp, inst->offset );
                            break;
            case 24:
            case 27:
                if ( inst->offset == 0 ) sprintf( buffer, "%-8sFP", temp );
                else sprintf( buffer, "%-8sFP%-+4d", temp, inst->offset );
                break;
            case 25:
            case 28:
                if ( inst->offset == 0 ) sprintf( buffer, "%-8s[SP]", temp );
                else sprintf( buffer, "%-8s[SP]%-+4d", temp, inst->offset );
                break;
            default:
                fprintf( stderr, "Error - shouldn't be here, %d %d\n",
                         inst->opcode, inst->offset );
                break;
        }
    }
}

variable_types:
buffer
char *

variable_types:
temp
char [10]


textcolor

repo: Ethilanie/C-Project

decompiled_code:
int __fastcall textcolor(unsigned int a1, int a2, int a3)
{
char s[21]; // [rsp+3h] [rbp-15h] BYREF

sprintf(s, "%c[%d;%d;%dm", 27LL, a1, (unsigned int)(a2 + 30), (unsigned int)(a3 + 40));
return printf("%s", s);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, int a2, int a3)
{
char s[21]; // [rsp+3h] [rbp-15h] BYREF

sprintf(s, "%c[%d;%d;%dm", 27LL, a1, (unsigned int)(a2 + 30), (unsigned int)(a3 + 40));
return printf("%s", s);
}

original_code:
void textcolor(int attr, int fg, int bg){
 char command[13];
 sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
 printf("%s", command);
}

variable_types: attr int

variable_types: fg int

variable_types: bg int

variable_types:
command
char [13]


nbPiles

decompiled_code:
__int64 __fastcall nbPiles(int a1, double a2)
{
unsigned int v2; // ebx
_BOOL4 i; // ebp
unsigned int v4; // eax

if ( init_0 )
{
v4 = time(0LL);
srand(v4);
init_0 = 0;
}
v2 = 0;
for ( i = 0; (float)((float)rand() * 4.6566129e-10) > a2 && !i; i = (int)v2 > a1 )
++v2;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, double a2)
{
unsigned int v2; // ebx
_BOOL4 i; // ebp
unsigned int v4; // eax

if ( init_0 )
{
v4 = time(0LL);
srand(v4);
init_0 = 0;
}
v2 = 0;
for ( i = 0; (float)((float)rand() * 4.6566129e-10) > a2 && !i; i = (int)v2 > a1 )
++v2;
return v2;
}

original_code:
int nbPiles(double proba, int hauteur) {
     static int init = 1;
     int stop = 0;
     if(init) {
         srand((unsigned)time(((void *)0)));
         init = 0;
     }
 int etages = 0;
    while(((float) rand() / 2147483647)> proba && stop ==0){
   etages++;
   if(etages>=hauteur+1){stop=1;}
    }
 return etages;
}

canonical_original_code:
int nbPiles(double proba, int hauteur) {
     static int init = 1;
     int stop = 0;
     if(init) {
         srand((unsigned int)time(((void *)0)));
         init = 0;
     }
 int etages = 0;
    while(((float) rand() / 2147483647)> proba && stop ==0){
   etages++;
   if(etages>=hauteur+1){stop=1;}
    }
 return etages;
}

variable_types: proba double

variable_types: hauteur int

variable_types: init int

variable_types: stop int

variable_types: etages int


hauteur

decompiled_code:
__int64 __fastcall hauteur(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !a1 )
return 0;
v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 1;
v2 = 1;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !a1 )
return 0;
v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 1;
v2 = 1;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

original_code:
int hauteur(L* skipList){
 int ht = 1;
 if(skipList==((void *)0)) return 0;
 while(skipList->suite!=((void *)0)){
  ht=ht +1;
  skipList= skipList->suite;
 }
 return ht;
}

canonical_original_code:
int hauteur(struct _L *skipList){
 int ht = 1;
 if(skipList==((void *)0)) return 0;
 while(skipList->suite!=((void *)0)){
  ht=ht +1;
  skipList= skipList->suite;
 }
 return ht;
}

variable_types: struct _L { struct _CL { int val; struct _CL *suiv; struct _CL *bas; } *tete; struct _L *suite; } *

variable_types: ht int

user_defined_types: struct _L { struct _CL *tete; struct _L *suite; }


recherche

original_code:
int recherche(int valeur, L* skipList){
    CL* temp;
    int trouve = 0;
    int pas = 1;
    temp = skipList->tete;
    if(skipList != ((void *)0))
    {
        while(trouve == 0)
        {
            while (skipList !=((void *)0) && temp!=((void *)0) && temp->val > valeur && skipList->suite !=((void *)0) )
            {
                skipList = skipList->suite;
                temp = skipList->tete;
                pas = pas +1;
            }
            while(temp!=((void *)0) && temp->suiv != ((void *)0) && temp->suiv->val<=valeur)
            {
                temp= temp->suiv;
                pas = pas+1;
            }
            if(temp!=((void *)0) && temp->val == valeur)
            {
                trouve = 1;
                return pas;
            }
            else
            {
                if(temp!=((void *)0) && temp->bas != ((void *)0))
                {
                    temp = temp->bas;
                    pas = pas + 1;
                }
                else
                {
                    trouve=1;
                    return 0;
                }
            }
        }
    }
}

canonical_original_code:
int recherche(int valeur, struct _L *skipList){
    struct _CL *temp;
    int trouve = 0;
    int pas = 1;
    temp = skipList->tete;
    if(skipList != ((void *)0))
    {
        while(trouve == 0)
        {
            while (skipList !=((void *)0) && temp!=((void *)0) && temp->val > valeur && skipList->suite !=((void *)0) )
            {
                skipList = skipList->suite;
                temp = skipList->tete;
                pas = pas +1;
            }
            while(temp!=((void *)0) && temp->suiv != ((void *)0) && temp->suiv->val<=valeur)
            {
                temp= temp->suiv;
                pas = pas+1;
            }
            if(temp!=((void *)0) && temp->val == valeur)
            {
                trouve = 1;
                return pas;
            }
            else
            {
                if(temp!=((void *)0) && temp->bas != ((void *)0))
                {
                    temp = temp->bas;
                    pas = pas + 1;
                }
                else
                {
                    trouve=1;
                    return 0;
                }
            }
        }
    }
}

variable_types: valeur int

variable_types: struct _CL { int val; struct _CL *suiv; struct _CL *bas; } *

variable_types: trouve int

variable_types: pas int


boucleRecherche

original_code:
void boucleRecherche(L* skipList, int nbElements){
    int pas = 0;
    int i = 0;
    int tabPas[nbElements];
    for (i = 0; i<nbElements; i++)
    {
        tabPas[i] = recherche(i, skipList);
    }
    printf("  ==========================\n");
    printf("||  Cases || Nombre de pas ||\n");
    for (i = 0; i < nbElements; i++)
    {
        printf("||%7d ||%15d||\n",i, tabPas[i]);
    }
    printf("  =========================");
    for(i = 0; i<nbElements; i++)
    {
        pas = pas + tabPas[i];
    }
 printf("\n 0 : la valeur n'existe pas");
    printf("\n \n Somme des pas : %d\n", pas);
}

canonical_original_code:
void boucleRecherche(struct _L *skipList, int nbElements){
    int pas = 0;
    int i = 0;
    int tabPas[-1];
    for (i = 0; i<nbElements; i++)
    {
        tabPas[i] = recherche(i, skipList);
    }
    printf("  ==========================\n");
    printf("||  Cases || Nombre de pas ||\n");
    for (i = 0; i < nbElements; i++)
    {
        printf("||%7d ||%15d||\n",i, tabPas[i]);
    }
    printf("  =========================");
    for(i = 0; i<nbElements; i++)
    {
        pas = pas + tabPas[i];
    }
 printf("\n 0 : la valeur n'existe pas");
    printf("\n \n Somme des pas : %d\n", pas);
}

variable_types: nbElements int

variable_types: i int

variable_types:
tabPas
int [-1]

user_defined_types: struct _CL { int val; struct _CL *suiv; struct _CL *bas; }


place

decompiled_code:
__int64 __fastcall place(__int64 *a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = *a1;
if ( !*a1 )
return 0LL;
v3 = 0;
while ( *(_DWORD *)result != a2 )
{
++v3;
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return (unsigned int)(v3 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = *a1;
if ( !*a1 )
return 0LL;
v3 = 0;
while ( *(_DWORD *)result != a2 )
{
++v3;
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return (unsigned int)(v3 + 1);
}

original_code:
int place(L*SkipList, int valeur){
    int i=0;
    CL*temp;
    int trouve=0;
    temp=SkipList->tete;
    while(temp!=((void *)0) && trouve ==0){
        if(valeur == temp->val){
            trouve=1;
        }
            i++;
        temp=temp->suiv;
    }
 if(trouve==0){
  return 0;
 }else{
  return i;
 }
}

canonical_original_code:
int place(struct _L *SkipList, int valeur){
    int i = 0;
    struct _CL *temp;
    int trouve = 0;
    temp=SkipList->tete;
    while(temp!=((void *)0) && trouve ==0){
        if(valeur == temp->val){
            trouve=1;
        }
            i++;
        temp=temp->suiv;
    }
 if(trouve==0){
  return 0;
 }else{
  return i;
 }
}


afficheListe

decompiled_code:
int __fastcall afficheListe(__int64 a1)
{
unsigned int **v1; // rbp
int v2; // eax
int v3; // er12
unsigned int *i; // rbx

v1 = (unsigned int **)a1;
v2 = hauteur(a1);
if ( v2 > 0 )
{
v3 = v2;
if ( a1 )
{
do
{
for ( i = *v1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf("valeur :%d -", *i);
putchar(10);
v1 = (unsigned int **)v1[1];
--v3;
}
while ( v3 > 0 && v1 );
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
unsigned int **v1; // rbp
int v2; // eax
int v3; // er12
unsigned int *i; // rbx

v1 = (unsigned int **)a1;
v2 = func4(a1);
if ( v2 > 0 )
{
v3 = v2;
if ( a1 )
{
do
{
for ( i = *v1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf("valeur :%d -", *i);
putchar(10);
v1 = (unsigned int **)v1[1];
--v3;
}
while ( v3 > 0 && v1 );
}
}
return putchar(10);
}

original_code:
void afficheListe(L* skipList){
    CL* temp;
    int ht = hauteur(skipList);
    while(ht >= 1 && skipList!=((void *)0))
    {
        temp = skipList->tete;
        while(temp!=((void *)0))
        {
            printf("valeur :%d -",temp->val);
            temp = temp->suiv;
        }
        printf("\n");
        skipList= skipList->suite;
        ht = ht - 1;
    }
    printf("\n");
}

canonical_original_code:
void afficheListe(struct _L *skipList){
    struct _CL *temp;
    int ht = hauteur(skipList);
    while(ht >= 1 && skipList!=((void *)0))
    {
        temp = skipList->tete;
        while(temp!=((void *)0))
        {
            printf("valeur :%d -",temp->val);
            temp = temp->suiv;
        }
        printf("\n");
        skipList= skipList->suite;
        ht = ht - 1;
    }
    printf("\n");
}


AfficherAide

decompiled_code:
int AfficherAide()
{
textcolor(3u, 2, 0);
puts("\n\t NAME");
textcolor(3u, 3, 0);
puts("\t\t Le programme prog.exe permet de creer des skip-list avec les options choisies");
textcolor(3u, 2, 0);
puts("\t SYNOPSIS");
textcolor(3u, 3, 0);
puts("\t\t ./prog [-h]");
puts("\t\t [-p var-double]");
puts("\t\t [-n var-int | -f @file]");
puts("\t\t [-o] [h][l][t][r][i]");
textcolor(3u, 2, 0);
puts("\t DESCRIPTION");
textcolor(3u, 3, 0);
puts(
"\t\t Le programme prog permet de creer des skiplistes.\n"
"\t\t Developpe en C.\n"
"\t\t Il est possible d'utiliser plusieurs options mais certaines ne doivent pas etre groupees : -f et -n\n"
"\t\t L'ordre des options n'importe pas");
textcolor(3u, 2, 0);
puts("\t OPTIONS");
textcolor(3u, 3, 0);
puts("\t\t Sommaire\n\t\t Voici le sommaire des options, par type.\n");
puts("\t\t Option Probabilite\n\t\t -p\n");
puts("\t\t Option Elements\n\t\t -n -f\n");
puts("\t\t Option Affichage\n\t\t -o\n");
puts("\t\t -p Modifie la probabilite par defaut \n");
puts("\t\t -n Modifie le nombre d'elements a ajouter dans la skip-list \n");
puts("\t\t -f Ajoute les elements du fichier a la skip-list \n");
puts("\t\t -o Precise les affichages \n");
puts("\t\t\t -oh : affiche la hauteur \n");
puts("\t\t\t -ol : affiche la longueur de chaque liste \n");
puts("\t\t\t -ot : affiche la skip-list en mode texte \n");
puts("\t\t\t -or : recherche chaque element et affiche le nombre de pas \n");
puts("\t\t\t -oi : affiche graphiquement la skip-list \n");
return textcolor(3u, 7, 0);
}

canonical_decompiled_code:
int func10()
{
func0(3u, 2, 0);
puts("\n\t NAME");
func0(3u, 3, 0);
puts("\t\t Le programme prog.exe permet de creer des skip-list avec les options choisies");
func0(3u, 2, 0);
puts("\t SYNOPSIS");
func0(3u, 3, 0);
puts("\t\t ./prog [-h]");
puts("\t\t [-p var-double]");
puts("\t\t [-n var-int | -f @file]");
puts("\t\t [-o] [h][l][t][r][i]");
func0(3u, 2, 0);
puts("\t DESCRIPTION");
func0(3u, 3, 0);
puts(
"\t\t Le programme prog permet de creer des skiplistes.\n"
"\t\t Developpe en C.\n"
"\t\t Il est possible d'utiliser plusieurs options mais certaines ne doivent pas etre groupees : -f et -n\n"
"\t\t L'ordre des options n'importe pas");
func0(3u, 2, 0);
puts("\t OPTIONS");
func0(3u, 3, 0);
puts("\t\t Sommaire\n\t\t Voici le sommaire des options, par type.\n");
puts("\t\t Option Probabilite\n\t\t -p\n");
puts("\t\t Option Elements\n\t\t -n -f\n");
puts("\t\t Option Affichage\n\t\t -o\n");
puts("\t\t -p Modifie la probabilite par defaut \n");
puts("\t\t -n Modifie le nombre d'elements a ajouter dans la skip-list \n");
puts("\t\t -f Ajoute les elements du fichier a la skip-list \n");
puts("\t\t -o Precise les affichages \n");
puts("\t\t\t -oh : affiche la hauteur \n");
puts("\t\t\t -ol : affiche la longueur de chaque liste \n");
puts("\t\t\t -ot : affiche la skip-list en mode texte \n");
puts("\t\t\t -or : recherche chaque element et affiche le nombre de pas \n");
puts("\t\t\t -oi : affiche graphiquement la skip-list \n");
return func0(3u, 7, 0);
}

original_code:
void AfficherAide(){
 textcolor(3,2, 0 );
 printf("\n\t NAME\n");
 textcolor(3,3, 0 );
 printf("\t\t Le programme prog.exe permet de creer des skip-list avec les options choisies\n");
 textcolor(3,2, 0 );
 printf("\t SYNOPSIS\n");
 textcolor(3,3, 0 );
 printf("\t\t ./prog [-h]\n");
 printf("\t\t        [-p var-double]\n");
 printf("\t\t        [-n var-int | -f @file]\n");
 printf("\t\t        [-o] [h][l][t][r][i]\n");
 textcolor(3,2, 0 );
 printf("\t DESCRIPTION\n");
 textcolor(3,3, 0 );
 printf("\t\t Le programme prog permet de creer des skiplistes.\n	\t Developpe en C.\n	\t Il est possible d'utiliser plusieurs options mais certaines ne doivent pas etre groupees : -f et -n\n	\t L'ordre des options n'importe pas\n");
 textcolor(3,2, 0 );
 printf("\t OPTIONS\n");
 textcolor(3,3, 0 );
 printf("\t\t Sommaire\n\t\t Voici le sommaire des options, par type.\n\n");
 printf("\t\t Option Probabilite\n\t\t -p\n\n");
 printf("\t\t Option Elements\n\t\t -n -f\n\n");
 printf("\t\t Option Affichage\n\t\t -o\n\n");
 printf("\t\t -p Modifie la probabilite par defaut \n\n");
 printf("\t\t -n Modifie le nombre d'elements a ajouter dans la skip-list \n\n");
 printf("\t\t -f Ajoute les elements du fichier a la skip-list \n\n");
 printf("\t\t -o Precise les affichages \n\n");
 printf("\t\t\t -oh : affiche la hauteur \n\n");
 printf("\t\t\t -ol : affiche la longueur de chaque liste \n\n");
 printf("\t\t\t -ot : affiche la skip-list en mode texte \n\n");
 printf("\t\t\t -or : recherche chaque element et affiche le nombre de pas \n\n");
 printf("\t\t\t -oi : affiche graphiquement la skip-list \n\n");
 textcolor(3,7, 0 );
}


nbElemHauteur

original_code:
int nbElemHauteur(int ht,L* SkipList){
    if (hauteur(SkipList)==0) return 0;
    while(hauteur(SkipList)!=ht && SkipList!=((void *)0)){
        SkipList=SkipList->suite;
    }
    int i=0;
    CL*temp;
    temp = SkipList->tete;
    while(temp!=((void *)0)){
        i++;
        temp=temp->suiv;
    }
    return i;
}

canonical_original_code:
int nbElemHauteur(int ht, struct _L *SkipList){
    if (hauteur(SkipList)==0) return 0;
    while(hauteur(SkipList)!=ht && SkipList!=((void *)0)){
        SkipList=SkipList->suite;
    }
    int i = 0;
    struct _CL *temp;
    temp = SkipList->tete;
    while(temp!=((void *)0)){
        i++;
        temp=temp->suiv;
    }
    return i;
}


afficheLongueur

decompiled_code:
int __fastcall afficheLongueur(__int64 a1)
{
__int64 v1; // rbp
int v2; // ebx
unsigned int v3; // eax

v1 = a1;
v2 = hauteur(a1);
puts("\n---Longueur de chaque hauteur---\n");
if ( v2 > 0 )
{
do
{
v3 = nbElemHauteur(v2, v1);
printf("Hauteur %d : %d element(s) \n", (unsigned int)v2, v3);
v1 = *(_QWORD *)(v1 + 8);
--v2;
}
while ( v2 );
}
return puts("\n");
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
__int64 v1; // rbp
int v2; // ebx
unsigned int v3; // eax

v1 = a1;
v2 = func4(a1);
puts("\n---Longueur de chaque hauteur---\n");
if ( v2 > 0 )
{
do
{
v3 = func11(v2, v1);
printf("Hauteur %d : %d element(s) \n", (unsigned int)v2, v3);
v1 = *(_QWORD *)(v1 + 8);
--v2;
}
while ( v2 );
}
return puts("\n");
}

original_code:
void afficheLongueur(L*SkipList){
 int ht = hauteur(SkipList);
 printf("\n---Longueur de chaque hauteur---\n\n");
 while(ht>0){
  printf("Hauteur %d : %d element(s) \n", ht, nbElemHauteur(ht,SkipList));
  ht--;
  SkipList=SkipList->suite;
 }
 printf("\n\n");
}

canonical_original_code:
void afficheLongueur(struct _L *SkipList){
 int ht = hauteur(SkipList);
 printf("\n---Longueur de chaque hauteur---\n\n");
 while(ht>0){
  printf("Hauteur %d : %d element(s) \n", ht, nbElemHauteur(ht,SkipList));
  ht--;
  SkipList=SkipList->suite;
 }
 printf("\n\n");
}


isNumeric

decompiled_code:
_BOOL8 __fastcall isNumeric(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

original_code:
int isNumeric(char caractere){
    if(caractere=='0'){
        return 1;
    }
    if(caractere=='1'){
        return 1;
    }
     if(caractere=='2'){
        return 1;
    }
     if(caractere=='3'){
        return 1;
    }
     if(caractere=='4'){
        return 1;
    }
     if(caractere=='5'){
        return 1;
    }
     if(caractere=='6'){
        return 1;
    }
     if(caractere=='7'){
        return 1;
    }
     if(caractere=='8'){
        return 1;
    }
     if(caractere=='9'){
        return 1;
    }
    return 0;
}

variable_types: caractere char


min

repo: EvanPurkhiser/CS-Matrix-Multiplication

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

original_code:
int min(int a, int b)
{
 return a < b ? a : b;
}

variable_types: a int

variable_types: b int


main

canonical_name: main

original_code:
int main(int argc, char* argv[])
{
 for (int i = 0; i < 2048; ++i)
  for (int k = 0; k < 2048; ++k)
   A[i][k] = B[i][k] = 1;
 int k, j, i, jj, kk;
 for (int trial = 0; trial < 8; ++trial)
 {
  printf("Trial %d: ", trial);
  for (int block_size = 256; block_size <= 2048; block_size *= 2)
  {
   memset(C, 0, sizeof(C[0][0] * 2048 * 2048));
   struct timeval time_start;
   struct timeval time_end;
   gettimeofday(&time_start, ((void *)0));
   for (k = 0; k < 2048; k += block_size)
    for (j = 0; j < 2048; j += block_size)
     for (i = 0; i < 2048; ++i)
      for (jj = j; jj < min(j + block_size, 2048); ++jj)
       for (kk = k; kk < min(k + block_size, 2048); ++kk)
        C[i][jj] += A[i][kk] * B[kk][jj];
   gettimeofday(&time_end, ((void *)0));
   long long execution_time = 1000000LL
    * (time_end.tv_sec - time_start.tv_sec)
    + (time_end.tv_usec - time_start.tv_usec);
   printf("%lld,", execution_time);
   fflush(stdout);
  }
  puts("");
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 for (int i = 0; i < 2048; ++i)
  for (int k = 0; k < 2048; ++k)
   A[i][k] = B[i][k] = 1;
 int k; int j; int i; int jj; int kk;
 for (int trial = 0; trial < 8; ++trial)
 {
  printf("Trial %d: ", trial);
  for (int block_size = 256; block_size <= 2048; block_size *= 2)
  {
   memset(C, 0, sizeof(C[0][0] * 2048 * 2048));
   struct timeval time_start;
   struct timeval time_end;
   gettimeofday(&time_start, ((void *)0));
   for (k = 0; k < 2048; k += block_size)
    for (j = 0; j < 2048; j += block_size)
     for (i = 0; i < 2048; ++i)
      for (jj = j; jj < min(j + block_size, 2048); ++jj)
       for (kk = k; kk < min(k + block_size, 2048); ++kk)
        C[i][jj] += A[i][kk] * B[kk][jj];
   gettimeofday(&time_end, ((void *)0));
   long long execution_time = 1000000LL
    * (time_end.tv_sec - time_start.tv_sec)
    + (time_end.tv_usec - time_start.tv_usec);
   printf("%lld,", execution_time);
   fflush(stdout);
  }
  puts("");
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: k int

variable_types: j int

variable_types: jj int

variable_types: kk int

variable_types: trial int

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


repo: Exanis/hh

decompiled_code:
__int64 __fastcall hh_find_parent_of_type(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r12
unsigned __int64 v4; // r13
__int64 v5; // rbx
unsigned __int64 v6; // r14
__int64 v7; // rdx

if ( !a2 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)a2 == -904811746 )
{
v3 = *(_QWORD *)(a1 + 8);
if ( v3 == *(_QWORD *)(a2 + 8) )
{
result = a2;
}
else
{
v4 = *(_QWORD *)(a2 + 48);
v5 = a2 + 56;
if ( v4 <= 0x38 )
{
result = 0LL;
}
else
{
v6 = 56LL;
while ( *(_DWORD *)v5 == -904811746 )
{
result = hh_find_parent_of_type(a1, v5);
if ( result )
return result;
v7 = *(_QWORD *)(v5 + 48);
if ( *(_QWORD *)(v5 + 8) == v3 )
return v5;
v5 += v7;
v6 += v7;
if ( v4 <= v6 )
return result;
}
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r12
unsigned __int64 v4; // r13
__int64 v5; // rbx
unsigned __int64 v6; // r14
__int64 v7; // rdx

if ( !a2 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)a2 == -904811746 )
{
v3 = *(_QWORD *)(a1 + 8);
if ( v3 == *(_QWORD *)(a2 + 8) )
{
result = a2;
}
else
{
v4 = *(_QWORD *)(a2 + 48);
v5 = a2 + 56;
if ( v4 <= 0x38 )
{
result = 0LL;
}
else
{
v6 = 56LL;
while ( *(_DWORD *)v5 == -904811746 )
{
result = func0(a1, v5);
if ( result )
return result;
v7 = *(_QWORD *)(v5 + 48);
if ( *(_QWORD *)(v5 + 8) == v3 )
return v5;
v5 += v7;
v6 += v7;
if ( v4 <= v6 )
return result;
}
result = 0LL;
}
}
}
return result;
}

original_code:
void *hh_find_parent_of_type(hh_object_struct *object, hh_object_struct *this)
{
  if (this == ((void *)0))
    return ((void *)0);
  size_t jump = sizeof(hh_object_struct);
  size_t jumped = 0;
  size_t max_jump = this->size;
  if (this->magic_number != 0xCA11AB1E)
    return (((void *)0));
  while (object->__this_identifier != this->__this_identifier)
    {
      void *tmp;
      this = (hh_object_struct *) (((char *) this) + jump);
      jumped += jump;
      if (jumped >= max_jump || this->magic_number != 0xCA11AB1E)
 return (((void *)0));
      if ((tmp = hh_find_parent_of_type(object, this)) != ((void *)0))
 return (tmp);
      jump = this->size;
    }
  return (this);
}

canonical_original_code:
void *hh_find_parent_of_type(struct hh_object_struct *object, struct hh_object_struct *this)
{
  if (this == ((void *)0))
    return ((void *)0);
  unsigned long jump = sizeof(hh_object_struct);
  unsigned long jumped = 0;
  unsigned long max_jump = this->size;
  if (this->magic_number != 0xCA11AB1E)
    return (((void *)0));
  while (object->__this_identifier != this->__this_identifier)
    {
      void *tmp;
      this = (struct hh_object_struct *) (((char *) this) + jump);
      jumped += jump;
      if (jumped >= max_jump || this->magic_number != 0xCA11AB1E)
 return (((void *)0));
      if ((tmp = hh_find_parent_of_type(object, this)) != ((void *)0))
 return (tmp);
      jump = this->size;
    }
  return (this);
}

variable_types: struct hh_object_struct { unsigned int magic_number; void *__this_identifier; unsigned long next_parent; void (*__init)(); void (*__construct)(); void (*__delete)(void *); unsigned long size; } *

variable_types:
this
struct hh_object_struct *

variable_types:
jump
unsigned long

variable_types:
jumped
unsigned long

variable_types:
tmp
void *

return_type: void *


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

result = a2;
if ( a2 )
{
result = a2 - 1;
do
{
while ( *(_DWORD *)result != -904811746 )
--result;
}
while ( *(_QWORD *)(result + 8) != *(_QWORD *)(a1 + 8) );
}
return result;
}

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

result = a2;
if ( a2 )
{
result = a2 - 1;
do
{
while ( *(_DWORD *)result != -904811746 )
--result;
}
while ( *(_QWORD *)(result + 8) != *(_QWORD *)(a1 + 8) );
}
return result;
}

original_code:
void *hh_find_child_of_type(hh_object_struct *type, hh_object_struct *this)
{
  char *position = (char *) this;
  if (this == ((void *)0))
    return ((void *)0);
  position--;
  do {
    while (((hh_object_struct *) position)->magic_number != 0xCA11AB1E)
      position--;
    if (((hh_object_struct *) position)->__this_identifier == type->__this_identifier)
      return position;
  } while (1);
}

canonical_original_code:
void *hh_find_child_of_type(struct hh_object_struct *type, struct hh_object_struct *this)
{
  char *position = (char *) this;
  if (this == ((void *)0))
    return ((void *)0);
  position--;
  do {
    while (((struct hh_object_struct *) position)->magic_number != 0xCA11AB1E)
      position--;
    if (((struct hh_object_struct *) position)->__this_identifier == type->__this_identifier)
      return position;
  } while (1);
}

variable_types:
position
char *

user_defined_types: struct hh_object_struct { unsigned int magic_number; void *__this_identifier; unsigned long next_parent; void (*__init)(); void (*__construct)(); void (*__delete)(void *); unsigned long size; }


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

if ( !a2 )
return 0LL;
result = hh_find_parent_of_type(a1, a2);
if ( !result )
result = hh_find_child_of_type(a1, a2);
return result;
}

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

if ( !a2 )
return 0LL;
result = func0(a1, a2);
if ( !result )
result = func1(a1, a2);
return result;
}

original_code:
void *hh_find_of_type(hh_object_struct *type, hh_object_struct *this)
{
  void *result;
  if (this == ((void *)0))
    return ((void *)0);
  result = hh_find_parent_of_type(type, this);
  if (!result)
    result = hh_find_child_of_type(type,this);
  return (result);
}

canonical_original_code:
void *hh_find_of_type(struct hh_object_struct *type, struct hh_object_struct *this)
{
  void *result;
  if (this == ((void *)0))
    return ((void *)0);
  result = hh_find_parent_of_type(type, this);
  if (!result)
    result = hh_find_child_of_type(type,this);
  return (result);
}

variable_types:
result
void *


decompiled_code:
_QWORD *hh_add_try_context()
{
_QWORD *result; // rax

result = malloc(0xD0uLL);
result[25] = buffers;
buffers = result;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0xD0uLL);
result[25] = buffers;
buffers = result;
return result;
}

original_code:
jmp_buf *hh_add_try_context()
{
  hh_jmp_buffer_t *buffer = malloc(sizeof(hh_jmp_buffer_t));
  buffer->next = buffers;
  buffers = buffer;
  return (&(buffer->buffer));
}

canonical_original_code:
struct __jmp_buf_tag (*hh_add_try_context())[1]
{
  struct hh_jmp_buffer *buffer = malloc(sizeof(hh_jmp_buffer_t));
  buffer->next = buffers;
  buffers = buffer;
  return (&(buffer->buffer));
}

variable_types: struct hh_jmp_buffer { struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } buffer[1]; struct hh_jmp_buffer *next; } *

return_type: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } (*)[1]

user_defined_types: struct hh_jmp_buffer { struct __jmp_buf_tag buffer[1]; struct hh_jmp_buffer *next; }

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


decompiled_code:
void hh_remove_try_context()
{
void *v0; // rdi

v0 = buffers;
buffers = (void *)*((_QWORD *)buffers + 25);
free(v0);
}

canonical_decompiled_code:
void func1()
{
void *v0; // rdi

v0 = buffers;
buffers = (void *)*((_QWORD *)buffers + 25);
free(v0);
}

original_code:
void hh_remove_try_context(__attribute__((unused)) void *_)
{
  hh_jmp_buffer_t *tmp = buffers;
  buffers = tmp->next;
  free(tmp);
}

canonical_original_code:
void hh_remove_try_context(void *_)
{
  struct hh_jmp_buffer *tmp = buffers;
  buffers = tmp->next;
  free(tmp);
}

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


decompiled_code:
void *hh_get_last_try_context()
{
return buffers;
}

canonical_decompiled_code:
void *func2()
{
return buffers;
}

original_code:
jmp_buf *hh_get_last_try_context()
{
  return (&(buffers->buffer));
}

canonical_original_code:
struct __jmp_buf_tag (*hh_get_last_try_context())[1]
{
  return (&(buffers->buffer));
}


decompiled_code:
__int64 __fastcall run_delete(__int64 a1)
{
unsigned __int64 v2; // rbp
__int64 result; // rax
unsigned __int64 v4; // rdi
unsigned __int64 v5; // rbx

v2 = *(_QWORD *)(a1 + 48) + a1;
result = (*(__int64 (**)(void))(a1 + 40))();
v4 = a1 + 56;
if ( v2 > a1 + 56 )
{
while ( *(_DWORD *)v4 == -904811746 )
{
v5 = *(_QWORD *)(v4 + 48) + v4;
result = run_delete();
if ( v2 <= v5 )
break;
v4 = v5;
}
}
return result;
}

original_code:
static void run_delete(void *object)
{
  hh_object_struct *obj = object;
  char *struct_ptr = object;
  char *max_position;
  max_position = struct_ptr + obj->size;
  obj->__delete(object);
  struct_ptr = struct_ptr + sizeof(hh_object_struct);
  while (struct_ptr < max_position)
    {
      hh_object_struct *obj_struct = (hh_object_struct *) struct_ptr;
      if (obj_struct->magic_number != 0xCA11AB1E)
 return ;
      char *next_struct_ptr = struct_ptr + obj_struct->size;
      run_delete((void *) obj_struct);
      struct_ptr = next_struct_ptr;
    }
}

canonical_original_code:
static void run_delete(void *object)
{
  struct hh_object_struct *obj = object;
  char *struct_ptr = object;
  char *max_position;
  max_position = struct_ptr + obj->size;
  obj->__delete(object);
  struct_ptr = struct_ptr + sizeof(hh_object_struct);
  while (struct_ptr < max_position)
    {
      struct hh_object_struct *obj_struct = (hh_object_struct *) struct_ptr;
      if (obj_struct->magic_number != 0xCA11AB1E)
 return ;
      char *next_struct_ptr = struct_ptr + obj_struct->size;
      run_delete((void *) obj_struct);
      struct_ptr = next_struct_ptr;
    }
}

variable_types:
object
void *


original_code:
void *hh_init_memory()
{
  void *args = __builtin_apply_args();
  hh_object_struct *object = hh_tmp_this_reference;
  object->__construct();
  __builtin_apply(object->__init, args, 100);
  return (object);
}

canonical_original_code:
void *hh_init_memory()
{
  void *args = __builtin_apply_args();
  struct hh_object_struct *object = hh_tmp_this_reference;
  object->__construct();
  __builtin_apply(object->__init, args, 100);
  return (object);
}

variable_types:
args
void *


delete

decompiled_code:
void __fastcall delete(void *ptr)
{
run_delete((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
func0((__int64)ptr);
free(ptr);
}

original_code:
void delete(void *object)
{
  run_delete(object);
  free(object);
}


decompiled_code:
void __fastcall hh_cleanup_local(void **a1)
{
delete(*a1);
}

canonical_decompiled_code:
void __fastcall func3(void **a1)
{
func2(*a1);
}

original_code:
void hh_cleanup_local(void *obj)
{
  hh_object_struct **object = (hh_object_struct **) obj;
  delete(*object);
}

canonical_original_code:
void hh_cleanup_local(void *obj)
{
  struct hh_object_struct **object = (hh_object_struct **) obj;
  delete(*object);
}

variable_types:
obj
void *

variable_types: struct hh_object_struct { unsigned int magic_number; void *__this_identifier; unsigned long next_parent; void (*__init)(); void (*__construct)(); void (*__delete)(void *); unsigned long size; } **


decompiled_code:
ssize_t __fastcall protocole_acc(int fd)
{
float v1; // xmm2_4
int v2; // ebx
float v4; // [rsp+8h] [rbp-120h]
float v5; // [rsp+Ch] [rbp-11Ch]
char s[280]; // [rsp+10h] [rbp-118h] BYREF

acc_power_on();
v4 = acc_read_acceleration(0LL);
v5 = acc_read_acceleration(1LL);
v1 = acc_read_acceleration(2LL);
v2 = sprintf(s, "Ax = %f, Ay = %f, Az = %f", v4, v5, v1);
printf("%s", s);
s[v2] = 0;
return send(fd, s, v2, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func9(int fd)
{
float v1; // xmm2_4
int v2; // ebx
float v4; // [rsp+8h] [rbp-120h]
float v5; // [rsp+Ch] [rbp-11Ch]
char s[280]; // [rsp+10h] [rbp-118h] BYREF

func11();
v4 = func15(0LL);
v5 = func15(1LL);
v1 = func15(2LL);
v2 = sprintf(s, "Ax = %f, Ay = %f, Az = %f", v4, v5, v1);
printf("%s", s);
s[v2] = 0;
return send(fd, s, v2, 0);
}

original_code:
void protocole_acc(int socket_s)
{
 float a[3];
 int dim;
 char message [256];
 acc_power_on();
 a[0] = acc_read_acceleration(0);
 a[1] = acc_read_acceleration(1);
 a[2] = acc_read_acceleration(2);
 dim = sprintf(message,"Ax = %f, Ay = %f, Az = %f",a[0],a[1],a[2]);
 printf("%s",message);
 message[dim] = 0;
 send(socket_s , message, dim, 0);
}

canonical_original_code:
void protocole_acc(int socket_s)
{
 float a[3];
 int dim;
 char message[256];
 acc_power_on();
 a[0] = acc_read_acceleration(0);
 a[1] = acc_read_acceleration(1);
 a[2] = acc_read_acceleration(2);
 dim = sprintf(message,"Ax = %f, Ay = %f, Az = %f",a[0],a[1],a[2]);
 printf("%s",message);
 message[dim] = 0;
 send(socket_s , message, dim, 0);
}

variable_types:
a
float [3]

variable_types: dim int

variable_types:
message
char [256]


decompiled_code:
ssize_t __fastcall protocole_temp(int fd)
{
float v1; // xmm0_4
int v2; // ebx
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = readTemp();
v2 = sprintf(v4, "T = %f degrees\n", v1);
printf("%s", v4);
v4[v2] = 0;
return send(fd, v4, v2, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func10(int fd)
{
float v1; // xmm0_4
int v2; // ebx
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = func16();
v2 = sprintf(v4, "T = %f degrees\n", v1);
printf("%s", v4);
v4[v2] = 0;
return send(fd, v4, v2, 0);
}

original_code:
void protocole_temp(int socket_s)
{
 float temperature;
 char message[256];
 int dim;
 temperature = readTemp();
 dim = sprintf(message,"T = %f degrees\n",temperature);
 printf("%s",message);
 message[dim] = 0;
 send(socket_s , message, dim, 0);
}

variable_types: temperature float


decompiled_code:
float __fastcall acc_read_acceleration(char a1)
{
char v2; // [rsp+Eh] [rbp-Ah] BYREF
char v3[9]; // [rsp+Fh] [rbp-9h] BYREF

switch ( a1 )
{
case 1:
acc_read_register(43, v3);
acc_read_register(42, &v2);
break;
case 2:
acc_read_register(45, v3);
acc_read_register(44, &v2);
break;
case 0:
acc_read_register(41, v3);
acc_read_register(40, &v2);
break;
}
return (double)(v2 + (v3[0] << 8)) * 0.001796;
}

canonical_decompiled_code:
float __fastcall func15(char a1)
{
char v2; // [rsp+Eh] [rbp-Ah] BYREF
char v3[9]; // [rsp+Fh] [rbp-9h] BYREF

switch ( a1 )
{
case 1:
func13(43, v3);
func13(42, &v2);
break;
case 2:
func13(45, v3);
func13(44, &v2);
break;
case 0:
func13(41, v3);
func13(40, &v2);
break;
}
return (double)(v2 + (v3[0] << 8)) * 0.001796;
}

original_code:
float acc_read_acceleration(char axis)
{
 char buffh, buffl;
 int acc_integer;
 float acc_float;
 switch (axis) {
  case 0:
   acc_read_register(0x29, &buffh);
   acc_read_register(0x28, &buffl);
   break;
  case 1:
   acc_read_register(0x2B, &buffh);
   acc_read_register(0x2A, &buffl);
   break;
  case 2:
   acc_read_register(0x2D, &buffh);
   acc_read_register(0x2C, &buffl);
   break;
  default:
   break;
 }
 acc_integer=(buffh<<8)+buffl;
 if(acc_integer>32768)
 {
  acc_integer-=65536;
 }
 acc_float = 0.001796 * acc_integer;
 return acc_float;
}

canonical_original_code:
float acc_read_acceleration(char axis)
{
 char buffh; char buffl;
 int acc_integer;
 float acc_float;
 switch (axis) {
  case 0:
   acc_read_register(0x29, &buffh);
   acc_read_register(0x28, &buffl);
   break;
  case 1:
   acc_read_register(0x2B, &buffh);
   acc_read_register(0x2A, &buffl);
   break;
  case 2:
   acc_read_register(0x2D, &buffh);
   acc_read_register(0x2C, &buffl);
   break;
  default:
   break;
 }
 acc_integer=(buffh<<8)+buffl;
 if(acc_integer>32768)
 {
  acc_integer-=65536;
 }
 acc_float = 0.001796 * acc_integer;
 return acc_float;
}

variable_types: axis char

variable_types: buffh char

variable_types: buffl char

return_type: float


OnGetACC

decompiled_code:
int __fastcall OnGetACC(__int64 a1, _BYTE *a2, _BYTE *a3, char *a4)
{
float v6; // xmm0_4
int result; // eax

v6 = acc_read_acceleration((unsigned int)(char)(*a2 - 48));
result = sprintf(a4, "%f", v6);
*a3 = result;
if ( !(_BYTE)result )
{
result = sprintf(a4, "%c", 202LL);
*a3 = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, _BYTE *a2, _BYTE *a3, char *a4)
{
float v6; // xmm0_4
int result; // eax

v6 = acc_read_acceleration((unsigned int)(char)(*a2 - 48));
result = sprintf(a4, "%f", v6);
*a3 = result;
if ( !(_BYTE)result )
{
result = sprintf(a4, "%c", 202LL);
*a3 = 1;
}
return result;
}

original_code:
void OnGetACC(u_char param_len, const char * parametres, u_char * rep_len, char * reponse)
{
 char axe = (*parametres)-48;
 float acc = acc_read_acceleration(axe);
 *rep_len = sprintf(reponse,"%f",acc);
 if ((*rep_len) <= 0)
 {
  *rep_len = sprintf(reponse,"%c",202);
 }
}

canonical_original_code:
void OnGetACC(unsigned char param_len, char *parametres, unsigned char *rep_len, char *reponse)
{
 char axe = (*parametres)-48;
 float acc = acc_read_acceleration(axe);
 *rep_len = sprintf(reponse,"%f",acc);
 if ((*rep_len) <= 0)
 {
  *rep_len = sprintf(reponse,"%c",202);
 }
}

variable_types:
parametres
char *

variable_types:
reponse
char *

variable_types: axe char

variable_types: acc float


canonical_decompiled_code:
ssize_t __fastcall func6(int fd)
{
float v1; // xmm2_4
int v2; // ebx
float v4; // [rsp+8h] [rbp-120h]
float v5; // [rsp+Ch] [rbp-11Ch]
char s[280]; // [rsp+10h] [rbp-118h] BYREF

acc_power_on();
v4 = acc_read_acceleration(0LL);
v5 = acc_read_acceleration(1LL);
v1 = acc_read_acceleration(2LL);
v2 = sprintf(s, "Ax = %f, Ay = %f, Az = %f", v4, v5, v1);
printf("%s", s);
s[v2] = 0;
return send(fd, s, v2, 0);
}


canonical_decompiled_code:
ssize_t __fastcall func7(int fd)
{
float v1; // xmm0_4
int v2; // ebx
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = readTemp();
v2 = sprintf(v4, "T = %f degrees\n", v1);
printf("%s", v4);
v4[v2] = 0;
return send(fd, v4, v2, 0);
}

canonical_original_code:
void protocole_temp(int socket_s)
{
 float temperature;
 char message[256];
 int dim;
 temperature = readTemp();
 dim = sprintf(message,"T = %f degrees\n",temperature);
 printf("%s",message);
 message[dim] = 0;
 send(socket_s , message, dim, 0);
}


repo: ExperimentMonty/tutoring

decompiled_code:
unsigned __int64 print_list()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
puts("Printing list");
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func8()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
puts("Printing list");
return v1 - __readfsqword(0x28u);
}

original_code:
void print_list()
{
  printf("Printing list\n");
  return;
}