decompiled_code:
__int64 __fastcall crc16_update(int a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3; // ecx
unsigned int v4; // edx
unsigned int v5; // esi
bool v6; // zf

LODWORD(result) = a1 ^ a2;
v3 = 8;
do
{
HIWORD(v4) = WORD1(result);
LOWORD(v4) = ((unsigned __int16)result >> 1) ^ 0xA001;
HIWORD(v5) = WORD1(result);
LOWORD(v5) = (unsigned __int16)result >> 1;
v6 = (result & 1) == 0;
result = v4;
if ( v6 )
result = v5;
--v3;
}
while ( v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3; // ecx
unsigned int v4; // edx
unsigned int v5; // esi
bool v6; // zf

LODWORD(result) = a1 ^ a2;
v3 = 8;
do
{
HIWORD(v4) = WORD1(result);
LOWORD(v4) = ((unsigned __int16)result >> 1) ^ 0xA001;
HIWORD(v5) = WORD1(result);
LOWORD(v5) = (unsigned __int16)result >> 1;
v6 = (result & 1) == 0;
result = v4;
if ( v6 )
result = v5;
--v3;
}
while ( v3 );
return result;
}

original_code:
uint16_t crc16_update(uint16_t crc, uint8_t a)
{
    int i;
    crc ^= a;
    for (i = 0; i < 8; ++i)
    {
        if (crc & 1)
            crc = (crc >> 1) ^ 0xA001;
        else
            crc = (crc >> 1);
    }
    return crc;
}

canonical_original_code:
unsigned short crc16_update(unsigned short crc, unsigned char a)
{
    int i;
    crc ^= a;
    for (i = 0; i < 8; ++i)
    {
        if (crc & 1)
            crc = (crc >> 1) ^ 0xA001;
        else
            crc = (crc >> 1);
    }
    return crc;
}

variable_types:
crc
unsigned short

variable_types:
a
unsigned char


main

canonical_name: main

repo: phatio/phatio

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx
int v4; // ebp
__int16 v5; // ax
unsigned __int16 v6; // bx
char v7; // r13
int v8; // er12
unsigned __int8 v9; // al

for ( i = 0LL; ; ++i )
{
v4 = i;
v5 = getchar();
if ( v5 == -1 )
break;
buffer[i] = v5;
}
offset = 0;
v6 = 0;
while ( offset < v4 )
{
if ( (unsigned __int8)next_char(*(_QWORD *)&argc, argv) == 58 )
{
v7 = next_byte();
next_word();
next_byte();
if ( v7 )
{
v8 = 0;
do
{
v9 = next_byte();
*(_QWORD *)&argc = v6;
argv = (const char **)v9;
v6 = crc16_update(v6, v9);
++v8;
}
while ( v7 != (_BYTE)v8 );
}
next_byte();
}
}
printf("%04X", v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx
int v4; // ebp
__int16 v5; // ax
unsigned __int16 v6; // bx
char v7; // r13
int v8; // er12
unsigned __int8 v9; // al

for ( i = 0LL; ; ++i )
{
v4 = i;
v5 = getchar();
if ( v5 == -1 )
break;
buffer[i] = v5;
}
offset = 0;
v6 = 0;
while ( offset < v4 )
{
if ( (unsigned __int8)func7(*(_QWORD *)&argc, argv) == 58 )
{
v7 = func9();
func10();
func9();
if ( v7 )
{
v8 = 0;
do
{
v9 = func9();
*(_QWORD *)&argc = v6;
argv = (const char **)v9;
v6 = func11(v6, v9);
++v8;
}
while ( v7 != (_BYTE)v8 );
}
func9();
}
}
printf("%04X", v6);
return 0;
}

original_code:
int main(void)
{
    int32_t size = 0;
    uint16_t prog_crc = 0;
    for (int16_t c = 0; (c = getchar()) != (-1); size++) {
        buffer[size] = c;
    }
    int lines=0;
    int bytes=0;
    for (offset = 0; offset < size;) {
        if (next_char() == ':') {
            uint8_t byte_count = next_byte();
            uint16_t address = next_word();
            uint8_t type = next_byte();
            for (uint8_t i = 0; i < byte_count; i++) {
                uint8_t byte = next_byte();
                prog_crc = crc16_update(prog_crc, byte);
            }
            bytes += byte_count;
            uint8_t checksum = next_byte();
            lines++;
        }
    }
    printf("%04X", prog_crc);
}

canonical_original_code:
int main()
{
    int size = 0;
    unsigned short prog_crc = 0;
    for (short c = 0; (c = getchar()) != (-1); size++) {
        buffer[size] = c;
    }
    int lines = 0;
    int bytes = 0;
    for (offset = 0; offset < size;) {
        if (next_char() == ':') {
            unsigned char byte_count = next_byte();
            unsigned short address = next_word();
            unsigned char type = next_byte();
            for (unsigned char i = 0; i < byte_count; i++) {
                unsigned char byte = next_byte();
                prog_crc = crc16_update(prog_crc, byte);
            }
            bytes += byte_count;
            unsigned char checksum = next_byte();
            lines++;
        }
    }
    printf("%04X", prog_crc);
}

variable_types: size int

variable_types: c short

variable_types: lines int

variable_types: bytes int

variable_types:
address
unsigned short

variable_types:
type
unsigned char

variable_types:
i
unsigned char

variable_types:
byte
unsigned char

variable_types:
checksum
unsigned char

return_type: int


decompiled_code:
__int16 __fastcall cluster_to_block(__int64 a1, __int16 a2)
{
__int16 result; // ax

if ( a2 < 0 )
result = *(_WORD *)(a1 + 528) + ~a2;
else
result = *(_WORD *)(a1 + 526) + a2 - 2;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func0(__int64 a1, __int16 a2)
{
__int16 result; // ax

if ( a2 < 0 )
result = *(_WORD *)(a1 + 528) + ~a2;
else
result = *(_WORD *)(a1 + 526) + a2 - 2;
return result;
}

original_code:
uint16_t cluster_to_block(sd_disk *sd, int16_t cluster)
{
    return (cluster < 0) ? (sd->root_dir - cluster - 1) : (sd->data_start+cluster-2);
}

canonical_original_code:
unsigned short cluster_to_block(struct sd_disk *sd, short cluster)
{
    return (cluster < 0) ? (sd->root_dir - cluster - 1) : (sd->data_start+cluster-2);
}

variable_types: struct sd_disk { unsigned char sd_type; unsigned int sd_size; unsigned char buf[512]; unsigned int p_size; unsigned short fat_start; unsigned short data_start; unsigned short root_dir; } *

variable_types: cluster short

return_type: unsigned short


decompiled_code:
char __fastcall sfn_checksum(_BYTE *a1)
{
_BYTE *v1; // rdx
char result; // al

v1 = a1 + 11;
result = 0;
do
result = *a1++ + __ROR1__(result, 1);
while ( a1 != v1 );
return result;
}

canonical_decompiled_code:
char __fastcall func1(_BYTE *a1)
{
_BYTE *v1; // rdx
char result; // al

v1 = a1 + 11;
result = 0;
do
result = *a1++ + __ROR1__(result, 1);
while ( a1 != v1 );
return result;
}

original_code:
uint8_t sfn_checksum(uint8_t sfn[])
{
     uint8_t checksum = 0;
     for (uint8_t i=0; i<11; i++) {
          checksum = (((checksum & 1) << 7) | ((checksum & 0xfe) >> 1)) + sfn[i];
     }
     return checksum;
}

canonical_original_code:
unsigned char sfn_checksum(unsigned char sfn[])
{
     unsigned char checksum = 0;
     for (unsigned char i = 0; i<11; i++) {
          checksum = (((checksum & 1) << 7) | ((checksum & 0xfe) >> 1)) + sfn[i];
     }
     return checksum;
}

variable_types:
sfn
unsigned char []

return_type: unsigned char


decompiled_code:
__int64 __fastcall fat_sfn_safe_char(unsigned int a1)
{
int v1; // edx
char v2; // al

if ( (_BYTE)a1 == 32 || (_BYTE)a1 == 46 )
return 0LL;
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
return a1 - 32;
if ( (unsigned __int8)(a1 - 65) <= 0x19u || (unsigned __int8)(a1 - 48) <= 9u )
return a1;
v1 = 0;
v2 = 36;
while ( (unsigned __int8)a1 != v2 )
{
v2 = byte_20C[(unsigned __int8)++v1];
if ( !v2 )
return 95LL;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
int v1; // edx
char v2; // al

if ( (_BYTE)a1 == 32 || (_BYTE)a1 == 46 )
return 0LL;
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
return a1 - 32;
if ( (unsigned __int8)(a1 - 65) <= 0x19u || (unsigned __int8)(a1 - 48) <= 9u )
return a1;
v1 = 0;
v2 = 36;
while ( (unsigned __int8)a1 != v2 )
{
v2 = byte_20C[(unsigned __int8)++v1];
if ( !v2 )
return 95LL;
}
return a1;
}

original_code:
uint8_t fat_sfn_safe_char(uint8_t c)
{
     if (c == ' ' || c =='.') {
          return 0;
     } else if (c >= 'a' && c<= 'z') {
          return c-('a'-'A');
     } else if ((c >= 'A' && c<= 'Z') || (c >= '0' && c<= '9')) {
          return c;
     } else {
          static char *valid = "$%'-_@~'!()";
          for (uint8_t i=0; valid[i]; i++) {
               if (c == valid[i]) {
                    return c;
               }
          }
     }
     return '_';
}

canonical_original_code:
unsigned char fat_sfn_safe_char(unsigned char c)
{
     if (c == ' ' || c =='.') {
          return 0;
     } else if (c >= 'a' && c<= 'z') {
          return c-('a'-'A');
     } else if ((c >= 'A' && c<= 'Z') || (c >= '0' && c<= '9')) {
          return c;
     } else {
          static char *valid = "$%'-_@~'!()";
          for (unsigned char i = 0; valid[i]; i++) {
               if (c == valid[i]) {
                    return c;
               }
          }
     }
     return '_';
}

variable_types:
c
unsigned char

variable_types:
valid
char *


decompiled_code:
int test_map_keys()
{
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_keys(&report, "Aasdf", 1LL) != 1 )
_assert_fail("map_keys(report, \"Aasdf\", 1) == 1", "test_keyboard.c", 0xBu, "test_map_keys");
putchar(46);
if ( report != 2 )
_assert_fail("report[0] == (1 << 1)", "test_keyboard.c", 0xCu, "test_map_keys");
putchar(46);
if ( byte_A8A != 4 )
_assert_fail("report[2] == 0x04", "test_keyboard.c", 0xDu, "test_map_keys");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_keys(&report, "zasdf", 1LL) != 1 )
_assert_fail("map_keys(report, \"zasdf\", 1) == 1", "test_keyboard.c", 0x10u, "test_map_keys");
putchar(46);
if ( report )
_assert_fail("report[0] == 0", "test_keyboard.c", 0x11u, "test_map_keys");
putchar(46);
if ( byte_A8A != 29 )
_assert_fail("report[2] == 0x1D", "test_keyboard.c", 0x12u, "test_map_keys");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_keys(&report, "^asdf", 1LL) != 1 )
_assert_fail("map_keys(report, \"^asdf\", 1) == 1", "test_keyboard.c", 0x15u, "test_map_keys");
putchar(46);
if ( report != 2 )
_assert_fail("report[0] == (1 << 1)", "test_keyboard.c", 0x16u, "test_map_keys");
putchar(46);
if ( byte_A8A != 35 )
_assert_fail("report[2] == 0x23", "test_keyboard.c", 0x17u, "test_map_keys");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_keys(&report, "%{bad+B+2}", 1LL) != 1 )
_assert_fail("map_keys(report, \"%{bad+B+2}\", 1) == 1", "test_keyboard.c", 0x1Au, "test_map_keys");
putchar(46);
if ( report != 2 )
_assert_fail("report[0] == (1 << 1)", "test_keyboard.c", 0x1Bu, "test_map_keys");
putchar(46);
if ( byte_A8A != 34 )
_assert_fail("report[2] == 0x22", "test_keyboard.c", 0x1Cu, "test_map_keys");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_keys(&report, "%{LeftGUI+ }rocketnumbernine.com", 1LL) != 12 )
_assert_fail(
"map_keys(report, \"%{LeftGUI+ }rocketnumbernine.com\", 1) == 12",
"test_keyboard.c",
0x1Fu,
"test_map_keys");
putchar(46);
if ( report != 8 )
_assert_fail("report[0] == (1 << 3)", "test_keyboard.c", 0x20u, "test_map_keys");
putchar(46);
if ( byte_A8A != 44 )
_assert_fail("report[2] == 0x2C", "test_keyboard.c", 0x21u, "test_map_keys");
return putchar(46);
}

canonical_decompiled_code:
int func0()
{
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_keys(&report, "Aasdf", 1LL) != 1 )
_assert_fail("map_keys(report, \"Aasdf\", 1) == 1", "test_keyboard.c", 0xBu, "test_map_keys");
putchar(46);
if ( report != 2 )
_assert_fail("report[0] == (1 << 1)", "test_keyboard.c", 0xCu, "test_map_keys");
putchar(46);
if ( byte_A8A != 4 )
_assert_fail("report[2] == 0x04", "test_keyboard.c", 0xDu, "test_map_keys");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_keys(&report, "zasdf", 1LL) != 1 )
_assert_fail("map_keys(report, \"zasdf\", 1) == 1", "test_keyboard.c", 0x10u, "test_map_keys");
putchar(46);
if ( report )
_assert_fail("report[0] == 0", "test_keyboard.c", 0x11u, "test_map_keys");
putchar(46);
if ( byte_A8A != 29 )
_assert_fail("report[2] == 0x1D", "test_keyboard.c", 0x12u, "test_map_keys");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_keys(&report, "^asdf", 1LL) != 1 )
_assert_fail("map_keys(report, \"^asdf\", 1) == 1", "test_keyboard.c", 0x15u, "test_map_keys");
putchar(46);
if ( report != 2 )
_assert_fail("report[0] == (1 << 1)", "test_keyboard.c", 0x16u, "test_map_keys");
putchar(46);
if ( byte_A8A != 35 )
_assert_fail("report[2] == 0x23", "test_keyboard.c", 0x17u, "test_map_keys");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_keys(&report, "%{bad+B+2}", 1LL) != 1 )
_assert_fail("map_keys(report, \"%{bad+B+2}\", 1) == 1", "test_keyboard.c", 0x1Au, "test_map_keys");
putchar(46);
if ( report != 2 )
_assert_fail("report[0] == (1 << 1)", "test_keyboard.c", 0x1Bu, "test_map_keys");
putchar(46);
if ( byte_A8A != 34 )
_assert_fail("report[2] == 0x22", "test_keyboard.c", 0x1Cu, "test_map_keys");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_keys(&report, "%{LeftGUI+ }rocketnumbernine.com", 1LL) != 12 )
_assert_fail(
"map_keys(report, \"%{LeftGUI+ }rocketnumbernine.com\", 1) == 12",
"test_keyboard.c",
0x1Fu,
"test_map_keys");
putchar(46);
if ( report != 8 )
_assert_fail("report[0] == (1 << 3)", "test_keyboard.c", 0x20u, "test_map_keys");
putchar(46);
if ( byte_A8A != 44 )
_assert_fail("report[2] == 0x2C", "test_keyboard.c", 0x21u, "test_map_keys");
return putchar(46);
}

original_code:
void test_map_keys()
{
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_keys(report, "Aasdf", 1) == 1) ? (void) (0) : __assert_fail ("map_keys(report, \"Aasdf\", 1) == 1", "test_keyboard.c", 11, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 1)", "test_keyboard.c", 12, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x04) ? (void) (0) : __assert_fail ("report[2] == 0x04", "test_keyboard.c", 13, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_keys(report, "zasdf", 1) == 1) ? (void) (0) : __assert_fail ("map_keys(report, \"zasdf\", 1) == 1", "test_keyboard.c", 16, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == 0) ? (void) (0) : __assert_fail ("report[0] == 0", "test_keyboard.c", 17, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x1D) ? (void) (0) : __assert_fail ("report[2] == 0x1D", "test_keyboard.c", 18, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_keys(report, "^asdf", 1) == 1) ? (void) (0) : __assert_fail ("map_keys(report, \"^asdf\", 1) == 1", "test_keyboard.c", 21, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 1)", "test_keyboard.c", 22, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x23) ? (void) (0) : __assert_fail ("report[2] == 0x23", "test_keyboard.c", 23, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_keys(report, "%{bad+B+2}", 1) == 1) ? (void) (0) : __assert_fail ("map_keys(report, \"%{bad+B+2}\", 1) == 1", "test_keyboard.c", 26, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 1)", "test_keyboard.c", 27, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x22) ? (void) (0) : __assert_fail ("report[2] == 0x22", "test_keyboard.c", 28, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_keys(report, "%{LeftGUI+ }rocketnumbernine.com", 1) == 12) ? (void) (0) : __assert_fail ("map_keys(report, \"%{LeftGUI+ }rocketnumbernine.com\", 1) == 12", "test_keyboard.c", 31, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 3)) ? (void) (0) : __assert_fail ("report[0] == (1 << 3)", "test_keyboard.c", 32, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x2C) ? (void) (0) : __assert_fail ("report[2] == 0x2C", "test_keyboard.c", 33, __extension__ __PRETTY_FUNCTION__)); printf(".");};
}

canonical_original_code:
void test_map_keys()
{
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_keys(report, "Aasdf", 1) == 1) ? (void) (0) : __assert_fail ("map_keys(report, \"Aasdf\", 1) == 1", "test_keyboard.c", 11, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 1)", "test_keyboard.c", 12, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x04) ? (void) (0) : __assert_fail ("report[2] == 0x04", "test_keyboard.c", 13, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_keys(report, "zasdf", 1) == 1) ? (void) (0) : __assert_fail ("map_keys(report, \"zasdf\", 1) == 1", "test_keyboard.c", 16, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == 0) ? (void) (0) : __assert_fail ("report[0] == 0", "test_keyboard.c", 17, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x1D) ? (void) (0) : __assert_fail ("report[2] == 0x1D", "test_keyboard.c", 18, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_keys(report, "^asdf", 1) == 1) ? (void) (0) : __assert_fail ("map_keys(report, \"^asdf\", 1) == 1", "test_keyboard.c", 21, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 1)", "test_keyboard.c", 22, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x23) ? (void) (0) : __assert_fail ("report[2] == 0x23", "test_keyboard.c", 23, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_keys(report, "%{bad+B+2}", 1) == 1) ? (void) (0) : __assert_fail ("map_keys(report, \"%{bad+B+2}\", 1) == 1", "test_keyboard.c", 26, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 1)", "test_keyboard.c", 27, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x22) ? (void) (0) : __assert_fail ("report[2] == 0x22", "test_keyboard.c", 28, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_keys(report, "%{LeftGUI+ }rocketnumbernine.com", 1) == 12) ? (void) (0) : __assert_fail ("map_keys(report, \"%{LeftGUI+ }rocketnumbernine.com\", 1) == 12", "test_keyboard.c", 31, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 3)) ? (void) (0) : __assert_fail ("report[0] == (1 << 3)", "test_keyboard.c", 32, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x2C) ? (void) (0) : __assert_fail ("report[2] == 0x2C", "test_keyboard.c", 33, __extension__ __PRETTY_FUNCTION__)); printf(".");};
}

variable_types: i int

return_type: void


decompiled_code:
int test_map_extension_block()
{
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{LeftControl}") != 14 )
_assert_fail(
"map_extension_block(report, \"%{LeftControl}\") == 14",
"test_keyboard.c",
0x29u,
"test_map_extension_block");
putchar(46);
if ( report != 1 )
_assert_fail("report[0] == (1 << 0)", "test_keyboard.c", 0x2Au, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{RightGUI}") != 11 )
_assert_fail(
"map_extension_block(report, \"%{RightGUI}\") == 11",
"test_keyboard.c",
0x2Du,
"test_map_extension_block");
putchar(46);
if ( report != (char)0x80 )
_assert_fail("report[0] == (1 << 7)", "test_keyboard.c", 0x2Eu, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{LeftGUI+a}") != 12 )
_assert_fail(
"map_extension_block(report, \"%{LeftGUI+a}\") == 12",
"test_keyboard.c",
0x33u,
"test_map_extension_block");
putchar(46);
if ( report != 8 )
_assert_fail("report[0] == (1 << 3)", "test_keyboard.c", 0x34u, "test_map_extension_block");
putchar(46);
if ( byte_A8A != 4 )
_assert_fail("report[2] == 0x04", "test_keyboard.c", 0x35u, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{LeftGUI+B}") != 12 )
_assert_fail(
"map_extension_block(report, \"%{LeftGUI+B}\") == 12",
"test_keyboard.c",
0x39u,
"test_map_extension_block");
putchar(46);
putchar(46);
if ( byte_A8A != 5 )
_assert_fail("report[2] == 0x05", "test_keyboard.c", 0x3Bu, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{LeftShift+LeftControl+LeftAlt+LeftGUI+B}") != 42 )
_assert_fail(
"map_extension_block(report, \"%{LeftShift+LeftControl+LeftAlt+LeftGUI+B}\") == 42",
"test_keyboard.c",
0x3Fu,
"test_map_extension_block");
putchar(46);
putchar(46);
if ( byte_A8A != 5 )
_assert_fail("report[2] == 0x05", "test_keyboard.c", 0x41u, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{.+LeftGUI+B+2}") != 16 )
_assert_fail(
"map_extension_block(report, \"%{.+LeftGUI+B+2}\") == 16",
"test_keyboard.c",
0x45u,
"test_map_extension_block");
putchar(46);
putchar(46);
if ( byte_A8A != 55 )
_assert_fail("report[2] == 0x37", "test_keyboard.c", 0x47u, "test_map_extension_block");
putchar(46);
if ( byte_A8B != 5 )
_assert_fail("report[3] == 0x05", "test_keyboard.c", 0x48u, "test_map_extension_block");
putchar(46);
if ( byte_A8C != 31 )
_assert_fail("report[4] == 0x1F", "test_keyboard.c", 0x49u, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{bad+B+2}") != 1 )
_assert_fail(
"map_extension_block(report, \"%{bad+B+2}\") == 1",
"test_keyboard.c",
0x4Eu,
"test_map_extension_block");
putchar(46);
if ( report != 2 )
_assert_fail("report[0] == (1 << 1)", "test_keyboard.c", 0x4Fu, "test_map_extension_block");
putchar(46);
if ( byte_A8A != 34 )
_assert_fail("report[2] == 0x22", "test_keyboard.c", 0x50u, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{LeftShift+0x31}") != 17 )
_assert_fail(
"map_extension_block(report, \"%{LeftShift+0x31}\") == 17",
"test_keyboard.c",
0x54u,
"test_map_extension_block");
putchar(46);
if ( report != 2 )
_assert_fail("report[0] == (1 << 1)", "test_keyboard.c", 0x55u, "test_map_extension_block");
putchar(46);
if ( byte_A8A != 49 )
_assert_fail("report[2] == 0x31", "test_keyboard.c", 0x56u, "test_map_extension_block");
return putchar(46);
}

canonical_decompiled_code:
int func1()
{
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{LeftControl}") != 14 )
_assert_fail(
"map_extension_block(report, \"%{LeftControl}\") == 14",
"test_keyboard.c",
0x29u,
"test_map_extension_block");
putchar(46);
if ( report != 1 )
_assert_fail("report[0] == (1 << 0)", "test_keyboard.c", 0x2Au, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{RightGUI}") != 11 )
_assert_fail(
"map_extension_block(report, \"%{RightGUI}\") == 11",
"test_keyboard.c",
0x2Du,
"test_map_extension_block");
putchar(46);
if ( report != (char)0x80 )
_assert_fail("report[0] == (1 << 7)", "test_keyboard.c", 0x2Eu, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{LeftGUI+a}") != 12 )
_assert_fail(
"map_extension_block(report, \"%{LeftGUI+a}\") == 12",
"test_keyboard.c",
0x33u,
"test_map_extension_block");
putchar(46);
if ( report != 8 )
_assert_fail("report[0] == (1 << 3)", "test_keyboard.c", 0x34u, "test_map_extension_block");
putchar(46);
if ( byte_A8A != 4 )
_assert_fail("report[2] == 0x04", "test_keyboard.c", 0x35u, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{LeftGUI+B}") != 12 )
_assert_fail(
"map_extension_block(report, \"%{LeftGUI+B}\") == 12",
"test_keyboard.c",
0x39u,
"test_map_extension_block");
putchar(46);
putchar(46);
if ( byte_A8A != 5 )
_assert_fail("report[2] == 0x05", "test_keyboard.c", 0x3Bu, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{LeftShift+LeftControl+LeftAlt+LeftGUI+B}") != 42 )
_assert_fail(
"map_extension_block(report, \"%{LeftShift+LeftControl+LeftAlt+LeftGUI+B}\") == 42",
"test_keyboard.c",
0x3Fu,
"test_map_extension_block");
putchar(46);
putchar(46);
if ( byte_A8A != 5 )
_assert_fail("report[2] == 0x05", "test_keyboard.c", 0x41u, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{.+LeftGUI+B+2}") != 16 )
_assert_fail(
"map_extension_block(report, \"%{.+LeftGUI+B+2}\") == 16",
"test_keyboard.c",
0x45u,
"test_map_extension_block");
putchar(46);
putchar(46);
if ( byte_A8A != 55 )
_assert_fail("report[2] == 0x37", "test_keyboard.c", 0x47u, "test_map_extension_block");
putchar(46);
if ( byte_A8B != 5 )
_assert_fail("report[3] == 0x05", "test_keyboard.c", 0x48u, "test_map_extension_block");
putchar(46);
if ( byte_A8C != 31 )
_assert_fail("report[4] == 0x1F", "test_keyboard.c", 0x49u, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{bad+B+2}") != 1 )
_assert_fail(
"map_extension_block(report, \"%{bad+B+2}\") == 1",
"test_keyboard.c",
0x4Eu,
"test_map_extension_block");
putchar(46);
if ( report != 2 )
_assert_fail("report[0] == (1 << 1)", "test_keyboard.c", 0x4Fu, "test_map_extension_block");
putchar(46);
if ( byte_A8A != 34 )
_assert_fail("report[2] == 0x22", "test_keyboard.c", 0x50u, "test_map_extension_block");
putchar(46);
report = 0;
byte_A89 = 0;
byte_A8A = 0;
byte_A8B = 0;
byte_A8C = 0;
byte_A8D = 0;
byte_A8E = 0;
byte_A8F = 0;
if ( (unsigned __int8)map_extension_block(&report, "%{LeftShift+0x31}") != 17 )
_assert_fail(
"map_extension_block(report, \"%{LeftShift+0x31}\") == 17",
"test_keyboard.c",
0x54u,
"test_map_extension_block");
putchar(46);
if ( report != 2 )
_assert_fail("report[0] == (1 << 1)", "test_keyboard.c", 0x55u, "test_map_extension_block");
putchar(46);
if ( byte_A8A != 49 )
_assert_fail("report[2] == 0x31", "test_keyboard.c", 0x56u, "test_map_extension_block");
return putchar(46);
}

original_code:
void test_map_extension_block()
{
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{LeftControl}") == 14) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{LeftControl}\") == 14", "test_keyboard.c", 41, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 0)) ? (void) (0) : __assert_fail ("report[0] == (1 << 0)", "test_keyboard.c", 42, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{RightGUI}") == 11) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{RightGUI}\") == 11", "test_keyboard.c", 45, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 7)) ? (void) (0) : __assert_fail ("report[0] == (1 << 7)", "test_keyboard.c", 46, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{LeftGUI+a}") == 12) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{LeftGUI+a}\") == 12", "test_keyboard.c", 51, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 3)) ? (void) (0) : __assert_fail ("report[0] == (1 << 3)", "test_keyboard.c", 52, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x04) ? (void) (0) : __assert_fail ("report[2] == 0x04", "test_keyboard.c", 53, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{LeftGUI+B}") == 12) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{LeftGUI+B}\") == 12", "test_keyboard.c", 57, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 3) | (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 3) | (1 << 1)", "test_keyboard.c", 58, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x05) ? (void) (0) : __assert_fail ("report[2] == 0x05", "test_keyboard.c", 59, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{LeftShift+LeftControl+LeftAlt+LeftGUI+B}") == 42) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{LeftShift+LeftControl+LeftAlt+LeftGUI+B}\") == 42", "test_keyboard.c", 63, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 1) | (1 << 0) | (1 << 2) | (1 << 3)) ? (void) (0) : __assert_fail ("report[0] == (1 << 1) | (1 << 0) | (1 << 2) | (1 << 3)", "test_keyboard.c", 64, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x05) ? (void) (0) : __assert_fail ("report[2] == 0x05", "test_keyboard.c", 65, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{.+LeftGUI+B+2}") == 16) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{.+LeftGUI+B+2}\") == 16", "test_keyboard.c", 69, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 3) | (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 3) | (1 << 1)", "test_keyboard.c", 70, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x37) ? (void) (0) : __assert_fail ("report[2] == 0x37", "test_keyboard.c", 71, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[3] == 0x05) ? (void) (0) : __assert_fail ("report[3] == 0x05", "test_keyboard.c", 72, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[4] == 0x1F) ? (void) (0) : __assert_fail ("report[4] == 0x1F", "test_keyboard.c", 73, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{bad+B+2}") == 1) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{bad+B+2}\") == 1", "test_keyboard.c", 78, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 1)", "test_keyboard.c", 79, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x22) ? (void) (0) : __assert_fail ("report[2] == 0x22", "test_keyboard.c", 80, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i=0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{LeftShift+0x31}") == 17) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{LeftShift+0x31}\") == 17", "test_keyboard.c", 84, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 1)", "test_keyboard.c", 85, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x31) ? (void) (0) : __assert_fail ("report[2] == 0x31", "test_keyboard.c", 86, __extension__ __PRETTY_FUNCTION__)); printf(".");};
}

canonical_original_code:
void test_map_extension_block()
{
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{LeftControl}") == 14) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{LeftControl}\") == 14", "test_keyboard.c", 41, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 0)) ? (void) (0) : __assert_fail ("report[0] == (1 << 0)", "test_keyboard.c", 42, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{RightGUI}") == 11) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{RightGUI}\") == 11", "test_keyboard.c", 45, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 7)) ? (void) (0) : __assert_fail ("report[0] == (1 << 7)", "test_keyboard.c", 46, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{LeftGUI+a}") == 12) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{LeftGUI+a}\") == 12", "test_keyboard.c", 51, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 3)) ? (void) (0) : __assert_fail ("report[0] == (1 << 3)", "test_keyboard.c", 52, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x04) ? (void) (0) : __assert_fail ("report[2] == 0x04", "test_keyboard.c", 53, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{LeftGUI+B}") == 12) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{LeftGUI+B}\") == 12", "test_keyboard.c", 57, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 3) | (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 3) | (1 << 1)", "test_keyboard.c", 58, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x05) ? (void) (0) : __assert_fail ("report[2] == 0x05", "test_keyboard.c", 59, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{LeftShift+LeftControl+LeftAlt+LeftGUI+B}") == 42) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{LeftShift+LeftControl+LeftAlt+LeftGUI+B}\") == 42", "test_keyboard.c", 63, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 1) | (1 << 0) | (1 << 2) | (1 << 3)) ? (void) (0) : __assert_fail ("report[0] == (1 << 1) | (1 << 0) | (1 << 2) | (1 << 3)", "test_keyboard.c", 64, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x05) ? (void) (0) : __assert_fail ("report[2] == 0x05", "test_keyboard.c", 65, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{.+LeftGUI+B+2}") == 16) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{.+LeftGUI+B+2}\") == 16", "test_keyboard.c", 69, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 3) | (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 3) | (1 << 1)", "test_keyboard.c", 70, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x37) ? (void) (0) : __assert_fail ("report[2] == 0x37", "test_keyboard.c", 71, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[3] == 0x05) ? (void) (0) : __assert_fail ("report[3] == 0x05", "test_keyboard.c", 72, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[4] == 0x1F) ? (void) (0) : __assert_fail ("report[4] == 0x1F", "test_keyboard.c", 73, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{bad+B+2}") == 1) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{bad+B+2}\") == 1", "test_keyboard.c", 78, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 1)", "test_keyboard.c", 79, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x22) ? (void) (0) : __assert_fail ("report[2] == 0x22", "test_keyboard.c", 80, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { for (int i = 0; i<8; i++) report[i] = 0;};
 { ((map_extension_block(report, "%{LeftShift+0x31}") == 17) ? (void) (0) : __assert_fail ("map_extension_block(report, \"%{LeftShift+0x31}\") == 17", "test_keyboard.c", 84, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[0] == (1 << 1)) ? (void) (0) : __assert_fail ("report[0] == (1 << 1)", "test_keyboard.c", 85, __extension__ __PRETTY_FUNCTION__)); printf(".");};
 { ((report[2] == 0x31) ? (void) (0) : __assert_fail ("report[2] == 0x31", "test_keyboard.c", 86, __extension__ __PRETTY_FUNCTION__)); printf(".");};
}


decompiled_code:
int test_keyboard()
{
test_map_keys();
return test_map_extension_block();
}

canonical_decompiled_code:
int func2()
{
func0();
return func1();
}

original_code:
void test_keyboard(void)
{
 test_map_keys();
 test_map_extension_block();
}

canonical_original_code:
void test_keyboard()
{
 test_map_keys();
 test_map_extension_block();
}


decompiled_code:
char *__fastcall data_alloc(unsigned __int16 a1)
{
unsigned __int8 v2; // di
char *result; // rax

v2 = free_data;
if ( a1 + (unsigned __int8)free_data > 300 )
{
lio_stop("out of memory");
result = 0LL;
}
else
{
free_data += a1;
result = (char *)&data + v2;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int16 a1)
{
unsigned __int8 v2; // di
char *result; // rax

v2 = free_data;
if ( a1 + (unsigned __int8)free_data > 300 )
{
lio_stop("out of memory");
result = 0LL;
}
else
{
free_data += a1;
result = (char *)&data + v2;
}
return result;
}

original_code:
void *data_alloc(uint16_t size)
{
    if (free_data+size > 300) {
        lio_stop("out of memory");
        return 0;
    }
    void *allocated = data+free_data;
    free_data += size;
    return allocated;
}

canonical_original_code:
void *data_alloc(unsigned short size)
{
    if (free_data+size > 300) {
        lio_stop("out of memory");
        return 0;
    }
    void *allocated = data+free_data;
    free_data += size;
    return allocated;
}

variable_types:
size
unsigned short

variable_types:
allocated
void *

return_type: void *


decompiled_code:
void __fastcall data_free(char a1)
{
free_data -= a1;
}

canonical_decompiled_code:
void __fastcall func1(char a1)
{
free_data -= a1;
}

original_code:
void data_free(uint16_t size)
{
    free_data -= size;
}

canonical_original_code:
void data_free(unsigned short size)
{
    free_data -= size;
}


original_code:
int16_t find_index(const char *name, const char map[])
{
    int16_t len = strlen(name);
    int8_t j=0;
    int16_t index = 0;
    for (int16_t i=0; ; i++) {
        char c = *(map+i);
        if (j >= 0 && c==name[j]) {
            if (c==0) {
                return index;
            }
            j++;
        } else if (c==0) {
            index++;
            if (*(map+i+1) == 0) {
                return -1;
            }
            j=0;
        } else {
            j = -1;
        }
    }
    return -1;
}

canonical_original_code:
short find_index(char *name, char map[])
{
    short len = strlen(name);
    char j = 0;
    short index = 0;
    for (short i = 0; ; i++) {
        char c = *(map+i);
        if (j >= 0 && c==name[j]) {
            if (c==0) {
                return index;
            }
            j++;
        } else if (c==0) {
            index++;
            if (*(map+i+1) == 0) {
                return -1;
            }
            j=0;
        } else {
            j = -1;
        }
    }
    return -1;
}

variable_types:
name
char *

variable_types:
map
char []

variable_types: len short

variable_types: j char

variable_types: index short

variable_types: i short

variable_types: c char

return_type: short


decompiled_code:
bool __fastcall parse_number(__int64 a1, __int64 a2)
{
return (unsigned int)_isoc99_sscanf(a1, "%i", a2) == 1;
}

canonical_decompiled_code:
bool __fastcall func3(__int64 a1, __int64 a2)
{
return (unsigned int)_isoc99_sscanf(a1, "%i", a2) == 1;
}

original_code:
_Bool parse_number(const uint8_t *buf, uint16_t *value)
{
    return (sscanf(buf,"%i",value) == 1);
}

canonical_original_code:
_Bool parse_number(unsigned char *buf, unsigned short *value)
{
    return (sscanf(buf,"%i",value) == 1);
}

variable_types:
buf
unsigned char *

variable_types:
value
unsigned short *


decompiled_code:
int __fastcall print_number(char *a1, unsigned __int16 a2)
{
return sprintf(a1, "%d", a2);
}

canonical_decompiled_code:
int __fastcall func4(char *a1, unsigned __int16 a2)
{
return sprintf(a1, "%d", a2);
}

original_code:
uint16_t print_number(uint8_t *buf, const uint16_t value)
{
    return sprintf(buf,"%d",value);
}

canonical_original_code:
unsigned short print_number(unsigned char *buf, unsigned short value)
{
    return sprintf(buf,"%d",value);
}

variable_types:
value
unsigned short


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

result = a1;
do
{
if ( !(_WORD)result )
break;
result = (unsigned int)(result - 1);
}
while ( timeSinceStart < (unsigned int)(unsigned __int16)a1 + timeSinceStart );
return result;
}

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

result = a1;
do
{
if ( !(_WORD)result )
break;
result = (unsigned int)(result - 1);
}
while ( timeSinceStart < (unsigned int)(unsigned __int16)a1 + timeSinceStart );
return result;
}

original_code:
void delay_ms(uint16_t duration)
{
     uint32_t end = _timeSinceStart+duration;
     while(duration-- > 0 && _timeSinceStart < end) {
          ;
     }
}

canonical_original_code:
void delay_ms(unsigned short duration)
{
     unsigned int end = _timeSinceStart+duration;
     while(duration-- > 0 && _timeSinceStart < end) {
          ;
     }
}

variable_types:
duration
unsigned short

variable_types:
end
unsigned int


original_code:
uint8_t map_extension_block(uint8_t* report, uint8_t *input)
{
     int consumed = 2;
     while ((input[consumed] != 0) && (input[consumed] != '}')) {
          uint8_t found = 0;
          for (int modifier=0; !found && modifier<8; modifier++) {
               char *m = (char *)*(&(modifiers[modifier]));
               uint8_t l = strlen(m);
               if (strncmp(input+consumed,m,l) == 0) {
                    report[0] |= (1<<modifier);
                    found = 1;
                    consumed += l;
                    break;
               }
          }
          if (!found && input[consumed] == '0' && input[consumed+1] == 'x') {
               uint16_t hex = 0;
               found = parse_number(&input[consumed], &hex);
               if (found) {
                    consumed += 4;
                    { for (int k=0; k<6; k++) { if (report[2+k] == 0) {report[2+k] = hex; break; }}};
               }
          }
          if ((!found && input[consumed+1] == '+') || input[consumed+1] == '}') {
               found = map_keys(report, input+consumed, 0);
               consumed += found;
          }
          if (!found) {
               return map_keys(report, input, 0);
          }
          if (input[consumed] == '+') {
               consumed++;
               continue;
          }
     }
     return consumed+1;
}

canonical_original_code:
unsigned char map_extension_block(unsigned char *report, unsigned char *input)
{
     int consumed = 2;
     while ((input[consumed] != 0) && (input[consumed] != '}')) {
          unsigned char found = 0;
          for (int modifier = 0; !found && modifier<8; modifier++) {
               char *m = (char *)*(&(modifiers[modifier]));
               unsigned char l = strlen(m);
               if (strncmp(input+consumed,m,l) == 0) {
                    report[0] |= (1<<modifier);
                    found = 1;
                    consumed += l;
                    break;
               }
          }
          if (!found && input[consumed] == '0' && input[consumed+1] == 'x') {
               unsigned short hex = 0;
               found = parse_number(&input[consumed], &hex);
               if (found) {
                    consumed += 4;
                    { for (int k = 0; k<6; k++) { if (report[2+k] == 0) {report[2+k] = hex; break; }}};
               }
          }
          if ((!found && input[consumed+1] == '+') || input[consumed+1] == '}') {
               found = map_keys(report, input+consumed, 0);
               consumed += found;
          }
          if (!found) {
               return map_keys(report, input, 0);
          }
          if (input[consumed] == '+') {
               consumed++;
               continue;
          }
     }
     return consumed+1;
}

variable_types:
report
unsigned char *

variable_types:
input
unsigned char *

variable_types: consumed int

variable_types:
found
unsigned char

variable_types: modifier int

variable_types:
m
char *

variable_types:
l
unsigned char

variable_types:
hex
unsigned short

variable_types: k int


original_code:
uint8_t map_keys(uint8_t* report, uint8_t *input, uint8_t extensions)
{
     uint8_t current_key = *input;
     uint8_t charsRead = 1;
     if (current_key < 128) {
          if ((input[0] == '%') && (input[1] == '{') && extensions) {
               return map_extension_block(report, input);
          }
          if (current_key == '\\') {
              for (uint16_t i=0; i<3; i++) {
                  if (input[1] == escaped_chars[i]) {
                      { for (int k=0; k<6; k++) { if (report[2+k] == 0) {report[2+k] = *(&escaped_values[i]); break; }}};
                      charsRead++;
                      break;
                  }
              }
          } else if (current_key > 31) {
               if (current_key < 65) {
                    map_ascii_key(report, *(&ascii_from32[current_key-32]));
               } else if (current_key < 91) {
                    { for (int k=0; k<6; k++) { if (report[2+k] == 0) {report[2+k] = current_key-(65-4); break; }}};
                    report[0] |= (1 << 1);
               } else if (current_key < 97) {
                    map_ascii_key(report, *(&ascii_from91[current_key-91]));
               } else if (current_key<123) {
                    { for (int k=0; k<6; k++) { if (report[2+k] == 0) {report[2+k] = current_key-(97-4); break; }}};
               } else {
                    map_ascii_key(report, *(&ascii_from123[current_key-123]));
               }
          } else {
              if (current_key == '\t') {
                  { for (int k=0; k<6; k++) { if (report[2+k] == 0) {report[2+k] = 0x2B; break; }}};
               }
          }
     }
     return charsRead;
}

canonical_original_code:
unsigned char map_keys(unsigned char *report, unsigned char *input, unsigned char extensions)
{
     unsigned char current_key = *input;
     unsigned char charsRead = 1;
     if (current_key < 128) {
          if ((input[0] == '%') && (input[1] == '{') && extensions) {
               return map_extension_block(report, input);
          }
          if (current_key == '\\') {
              for (unsigned short i = 0; i<3; i++) {
                  if (input[1] == escaped_chars[i]) {
                      { for (int k = 0; k<6; k++) { if (report[2+k] == 0) {report[2+k] = *(&escaped_values[i]); break; }}};
                      charsRead++;
                      break;
                  }
              }
          } else if (current_key > 31) {
               if (current_key < 65) {
                    map_ascii_key(report, *(&ascii_from32[current_key-32]));
               } else if (current_key < 91) {
                    { for (int k = 0; k<6; k++) { if (report[2+k] == 0) {report[2+k] = current_key-(65-4); break; }}};
                    report[0] |= (1 << 1);
               } else if (current_key < 97) {
                    map_ascii_key(report, *(&ascii_from91[current_key-91]));
               } else if (current_key<123) {
                    { for (int k = 0; k<6; k++) { if (report[2+k] == 0) {report[2+k] = current_key-(97-4); break; }}};
               } else {
                    map_ascii_key(report, *(&ascii_from123[current_key-123]));
               }
          } else {
              if (current_key == '\t') {
                  { for (int k = 0; k<6; k++) { if (report[2+k] == 0) {report[2+k] = 0x2B; break; }}};
               }
          }
     }
     return charsRead;
}

variable_types:
extensions
unsigned char

variable_types:
charsRead
unsigned char

variable_types:
i
unsigned short


findIndex

repo: philcowans/speedy-goat

decompiled_code:
size_t __fastcall findIndex(char *s, __int64 a2)
{
unsigned __int64 i; // rbx
size_t result; // rax
unsigned __int8 v4; // al
_BYTE *v5; // rax

for ( i = 0LL; ; ++i )
{
result = strlen(s);
if ( result <= i )
break;
v4 = s[i];
if ( (unsigned __int8)(v4 - 97) > 0x19u )
{
fprintf(stderr, "Invlid entry %s: contains characters other than lower case a-z\n", s);
}
else
{
v5 = (_BYTE *)(a2 + v4 - 97);
if ( *v5 == 0xFF )
fprintf(stderr, "Invalid entry %s: too many repeated characters\n", s);
else
*v5 = 2 * *v5 + 1;
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(char *s, __int64 a2)
{
unsigned __int64 i; // rbx
size_t result; // rax
unsigned __int8 v4; // al
_BYTE *v5; // rax

for ( i = 0LL; ; ++i )
{
result = strlen(s);
if ( result <= i )
break;
v4 = s[i];
if ( (unsigned __int8)(v4 - 97) > 0x19u )
{
fprintf(stderr, "Invlid entry %s: contains characters other than lower case a-z\n", s);
}
else
{
v5 = (_BYTE *)(a2 + v4 - 97);
if ( *v5 == 0xFF )
fprintf(stderr, "Invalid entry %s: too many repeated characters\n", s);
else
*v5 = 2 * *v5 + 1;
}
}
return result;
}

original_code:
void findIndex(const unsigned char *word, unsigned char *indexEntry) {
  for(int i = 0; i < strlen(word); ++i) {
    unsigned char c = word[i];
    if((c >= 'a') && (c <= 'z')) {
      int offset = c - 'a';
      if(indexEntry[offset] < 255) {
 indexEntry[offset] <<= 1;
 indexEntry[offset] += 1;
      }
      else {
 fprintf(stderr, "Invalid entry %s: too many repeated characters\n", word);
      }
    }
    else {
      fprintf(stderr, "Invlid entry %s: contains characters other than lower case a-z\n", word);
    }
  }
}

canonical_original_code:
void findIndex(unsigned char *word, unsigned char *indexEntry) {
  for(int i = 0; i < strlen(word); ++i) {
    unsigned char c = word[i];
    if((c >= 'a') && (c <= 'z')) {
      int offset = c - 'a';
      if(indexEntry[offset] < 255) {
 indexEntry[offset] <<= 1;
 indexEntry[offset] += 1;
      }
      else {
 fprintf(stderr, "Invalid entry %s: too many repeated characters\n", word);
      }
    }
    else {
      fprintf(stderr, "Invlid entry %s: contains characters other than lower case a-z\n", word);
    }
  }
}

variable_types:
word
unsigned char *

variable_types:
indexEntry
unsigned char *

variable_types: i int

variable_types:
c
unsigned char

variable_types: offset int


check

original_code:
int check(const unsigned char *wordPattern, const unsigned char *boardPattern) {
  for(int i = 0; i < 26; ++i) {
    if((wordPattern[i] & boardPattern[i]) != wordPattern[i]) {
      return 0;
    }
  }
  return 1;
}

canonical_original_code:
int check(unsigned char *wordPattern, unsigned char *boardPattern) {
  for(int i = 0; i < 26; ++i) {
    if((wordPattern[i] & boardPattern[i]) != wordPattern[i]) {
      return 0;
    }
  }
  return 1;
}

variable_types:
wordPattern
unsigned char *

variable_types:
boardPattern
unsigned char *


score

decompiled_code:
__int64 __fastcall score(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp
unsigned int v5; // er12
char v6; // bl
int v7; // er12

v4 = 0LL;
v5 = 0;
do
{
v6 = *(_BYTE *)(a1 + v4);
v7 = countBits(*(_BYTE *)(a2 + v4) & v6) + v5;
v5 = countBits(*(_BYTE *)(a3 + v4++) & v6) + v7;
}
while ( v4 != 26 );
return v5;
}

original_code:
int score(const unsigned char *wordPattern, const unsigned char *onePointPattern, const unsigned char *twoPointPattern) {
  int s = 0;
  for(int i = 0; i < 26; ++i) {
    s += countBits(wordPattern[i] & onePointPattern[i]);
    s += countBits(wordPattern[i] & twoPointPattern[i]);
  }
  return s;
}

canonical_original_code:
int score(unsigned char *wordPattern, unsigned char *onePointPattern, unsigned char *twoPointPattern) {
  int s = 0;
  for(int i = 0; i < 26; ++i) {
    s += countBits(wordPattern[i] & onePointPattern[i]);
    s += countBits(wordPattern[i] & twoPointPattern[i]);
  }
  return s;
}

variable_types:
onePointPattern
unsigned char *

variable_types:
twoPointPattern
unsigned char *

variable_types: s int


entrenched

original_code:
int entrenched(const int i, const unsigned char *ownerships) {
  int row = i / 5;
  int col = i % 5;
  if((row > 0) && (ownerships[i - 5] != ownerships[i])) {
    return 0;
  }
  if((row < 4) && (ownerships[i + 5] != ownerships[i])) {
    return 0;
  }
  if((col > 0) && (ownerships[i - 1] != ownerships[i])) {
    return 0;
  }
  if((col < 4) && (ownerships[i + 1] != ownerships[i])) {
    return 0;
  }
  return 1;
}

canonical_original_code:
int entrenched(int i, unsigned char *ownerships) {
  int row = i / 5;
  int col = i % 5;
  if((row > 0) && (ownerships[i - 5] != ownerships[i])) {
    return 0;
  }
  if((row < 4) && (ownerships[i + 5] != ownerships[i])) {
    return 0;
  }
  if((col > 0) && (ownerships[i - 1] != ownerships[i])) {
    return 0;
  }
  if((col < 4) && (ownerships[i + 1] != ownerships[i])) {
    return 0;
  }
  return 1;
}

variable_types:
ownerships
unsigned char *

variable_types: row int

variable_types: col int


pickMove

decompiled_code:
__int64 __fastcall pickMove(__int64 a1, int a2, char *a3, char *a4, char *a5, __int64 a6)
{
void *v9; // r14
void *v10; // r15
__int64 v11; // rbx
int v12; // eax
void *ptr; // [rsp+10h] [rbp-48h]
int v16; // [rsp+18h] [rbp-40h]
unsigned int v17; // [rsp+1Ch] [rbp-3Ch]

v9 = calloc(0x1AuLL, 1uLL);
findIndex(a3, (__int64)v9);
v10 = calloc(0x1AuLL, 1uLL);
findIndex(a4, (__int64)v10);
ptr = calloc(0x1AuLL, 1uLL);
findIndex(a5, (__int64)ptr);
if ( a2 <= 0 )
{
v17 = -1;
}
else
{
v11 = 0LL;
v17 = -1;
v16 = -1;
do
{
if ( !*(_DWORD *)(a6 + 4 * v11) )
{
if ( (unsigned int)check(a1 + 26 * (int)v11, (__int64)v9) )
{
v12 = score(a1 + 26 * (int)v11, (__int64)v10, (__int64)ptr);
if ( v12 > v16 )
{
v17 = v11;
v16 = v12;
}
}
}
++v11;
}
while ( v11 != a2 );
}
free(v9);
free(v10);
free(ptr);
return v17;
}

original_code:
int pickMove(const unsigned char *index, const int dictionarySize, const unsigned char *board, const unsigned char *onePoint, const unsigned char *twoPoint, int *played) {
  unsigned char *boardPattern = calloc(26, 1);
  findIndex(board, boardPattern);
  unsigned char *onePointPattern = calloc(26, 1);
  findIndex(onePoint, onePointPattern);
  unsigned char *twoPointPattern = calloc(26, 1);
  findIndex(twoPoint, twoPointPattern);
  int maxScore = -1;
  int maxIndex = -1;
  for(int i = 0; i < dictionarySize; ++i) {
    if(!played[i] && check(index + 26 * i, boardPattern)) {
      int s = score(index + 26 * i, onePointPattern, twoPointPattern);
      if(s > maxScore) {
 maxScore = s;
 maxIndex = i;
      }
    }
  }
  free(boardPattern);
  free(onePointPattern);
  free(twoPointPattern);
  return maxIndex;
}

canonical_original_code:
int pickMove(unsigned char *index, int dictionarySize, unsigned char *board, unsigned char *onePoint, unsigned char *twoPoint, int *played) {
  unsigned char *boardPattern = calloc(26, 1);
  findIndex(board, boardPattern);
  unsigned char *onePointPattern = calloc(26, 1);
  findIndex(onePoint, onePointPattern);
  unsigned char *twoPointPattern = calloc(26, 1);
  findIndex(twoPoint, twoPointPattern);
  int maxScore = -1;
  int maxIndex = -1;
  for(int i = 0; i < dictionarySize; ++i) {
    if(!played[i] && check(index + 26 * i, boardPattern)) {
      int s = score(index + 26 * i, onePointPattern, twoPointPattern);
      if(s > maxScore) {
 maxScore = s;
 maxIndex = i;
      }
    }
  }
  free(boardPattern);
  free(onePointPattern);
  free(twoPointPattern);
  return maxIndex;
}

variable_types:
index
unsigned char *

variable_types: dictionarySize int

variable_types:
board
unsigned char *

variable_types:
onePoint
unsigned char *

variable_types:
twoPoint
unsigned char *

variable_types:
played
int *

variable_types: maxScore int

variable_types: maxIndex int


strhextonum

original_code:
long long
strhextonum(const char *numstr, long long minval, long long maxval,
    const char **errstrp)
{
 long long ll = 0;
 char *ep;
 int error = 0;
 struct errval {
  const char *errstr;
  int err;
 } ev[4] = {
  { ((void *)0), 0 },
  { "invalid", 22 },
  { "too small", 34 },
  { "too large", 34 },
 };
 ev[0].err = (*__errno_location ());
 (*__errno_location ()) = 0;
 if (minval > maxval)
  error = 1;
 else {
  ll = strtoll(numstr, &ep, 16);
  if (numstr == ep || *ep != '\0')
   error = 1;
  else if ((ll == (-0x7fffffffffffffffLL - 1LL) && (*__errno_location ()) == 34) || ll < minval)
   error = 2;
  else if ((ll == 0x7fffffffffffffffLL && (*__errno_location ()) == 34) || ll > maxval)
   error = 3;
 }
 if (errstrp != ((void *)0))
  *errstrp = ev[error].errstr;
 (*__errno_location ()) = ev[error].err;
 if (error)
  ll = 0;
 return (ll);
}

canonical_original_code:
long long strhextonum(char *numstr, long long minval, long long maxval, char **errstrp)
{
 long long ll = 0;
 char *ep;
 int error = 0;
 struct errval ev[4] = {
  { ((void *)0), 0 },
  { "invalid", 22 },
  { "too small", 34 },
  { "too large", 34 },
 };
 ev[0].err = (*__errno_location ());
 (*__errno_location ()) = 0;
 if (minval > maxval)
  error = 1;
 else {
  ll = strtoll(numstr, &ep, 16);
  if (numstr == ep || *ep != '\0')
   error = 1;
  else if ((ll == (-0x7fffffffffffffffLL - 1LL) && (*__errno_location ()) == 34) || ll < minval)
   error = 2;
  else if ((ll == 0x7fffffffffffffffLL && (*__errno_location ()) == 34) || ll > maxval)
   error = 3;
 }
 if (errstrp != ((void *)0))
  *errstrp = ev[error].errstr;
 (*__errno_location ()) = ev[error].err;
 if (error)
  ll = 0;
 return (ll);
}

variable_types:
numstr
char *

variable_types:
minval
long long

variable_types:
maxval
long long

variable_types:
errstrp
char **

variable_types:
ll
long long

variable_types:
ep
char *

variable_types: error int

variable_types: struct errval { char *errstr; int err; } [4]

return_type: long long


dispatch

repo: philipaconrad/mini-vm

decompiled_code:
__int64 __fastcall dispatch(__int64 a1, unsigned __int8 a2)
{
return (*(__int64 (**)(void))(*(_QWORD *)(a1 + 16) + 8LL * a2))();
}

original_code:
void dispatch(struct VMContext* ctx, const uint32_t instr) {
    const uint8_t i = (instr & 0xFF);
    (*ctx->funtable[i])(ctx, instr);
}

canonical_original_code:
void dispatch(struct VMContext *ctx, unsigned int instr) {
    unsigned char i = (instr & 0xFF);
    (*ctx->funtable[i])(ctx, instr);
}

variable_types: struct VMContext { unsigned int numRegs; unsigned int numFuns; struct Reg { unsigned int type; unsigned int value; } *r; void (**funtable)(struct VMContext *ctx, unsigned int); } *

variable_types:
instr
unsigned int

variable_types:
i
unsigned char

user_defined_types: struct VMContext { unsigned int numRegs; unsigned int numFuns; struct Reg *r; void (**funtable)(struct VMContext *ctx, unsigned int); }


initVMContext

original_code:
void initVMContext(struct VMContext* ctx, const uint32_t numRegs, const uint32_t numFuns, Reg* registers, FunPtr* funtable) {
    ctx->numRegs = numRegs;
    ctx->numFuns = numFuns;
    ctx->r = registers;
    ctx->funtable = funtable;
}

canonical_original_code:
void initVMContext(struct VMContext *ctx, unsigned int numRegs, unsigned int numFuns, struct Reg *registers, void (**funtable)(struct VMContext *ctx, unsigned int)) {
    ctx->numRegs = numRegs;
    ctx->numFuns = numFuns;
    ctx->r = registers;
    ctx->funtable = funtable;
}

variable_types:
numRegs
unsigned int

variable_types:
numFuns
unsigned int

variable_types:
registers
struct Reg *

variable_types: void (**)(struct VMContext *ctx, unsigned int)

user_defined_types: struct Reg { unsigned int type; unsigned int value; }


stepVMContext

decompiled_code:
__int64 __fastcall stepVMContext(__int64 a1, _DWORD **a2)
{
__int64 result; // rax

result = dispatch(a1, **a2);
++*a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, _DWORD **a2)
{
__int64 result; // rax

result = func16(a1, **a2);
++*a2;
return result;
}

original_code:
void stepVMContext(struct VMContext* ctx, uint32_t** pc) {
    uint32_t instr = **pc;
    dispatch(ctx, instr);
    (*pc)++;
}

canonical_original_code:
void stepVMContext(struct VMContext *ctx, unsigned int **pc) {
    unsigned int instr = **pc;
    dispatch(ctx, instr);
    (*pc)++;
}

variable_types:
pc
unsigned int **


canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, _DWORD **a2)
{
__int64 result; // rax

result = func12(a1, **a2);
++*a2;
return result;
}


initArray

repo: philipaconrad/theta

decompiled_code:
__int64 __fastcall initArray(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx
__int64 v5; // r12
__int64 result; // rax

if ( a3 )
{
v3 = a2;
v5 = a2 + 8LL * (unsigned int)(a3 - 1) + 8;
do
{
result = __gmpf_init_set_d();
v3 += 8LL;
a1 += 24LL;
}
while ( v3 != v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx
__int64 v5; // r12
__int64 result; // rax

if ( a3 )
{
v3 = a2;
v5 = a2 + 8LL * (unsigned int)(a3 - 1) + 8;
do
{
result = __gmpf_init_set_d();
v3 += 8LL;
a1 += 24LL;
}
while ( v3 != v5 );
}
return result;
}

original_code:
void initArray(bigFloat* dest, double* inputs, uint32 numVars) {
    uint32 i;
    for(i = 0; i < numVars; i++) {
        __gmpf_init_set_d(dest[i], inputs[i]);
    }
}

canonical_original_code:
void initArray(struct __mpf_struct (*dest)[1], double *inputs, unsigned int numVars) {
    unsigned int i;
    for(i = 0; i < numVars; i++) {
        __gmpf_init_set_d(dest[i], inputs[i]);
    }
}

variable_types: struct __mpf_struct { int _mp_prec; int _mp_size; long _mp_exp; unsigned long *_mp_d; } (*)[1]

variable_types:
inputs
double *

variable_types:
numVars
unsigned int

variable_types:
i
unsigned int


initNLSystemContext

original_code:
void initNLSystemContext(NLSystemContext* ctx, bigFloat* initialState, bigFloat* minBounds, bigFloat* maxBounds, uint32 listSize) {
    ctx->state = initialState;
    ctx->minBounds = minBounds;
    ctx->maxBounds = maxBounds;
    ctx->listSize = listSize;
}

canonical_original_code:
void initNLSystemContext(struct NLSystemContext *ctx, struct __mpf_struct (*initialState)[1], struct __mpf_struct (*minBounds)[1], struct __mpf_struct (*maxBounds)[1], unsigned int listSize) {
    ctx->state = initialState;
    ctx->minBounds = minBounds;
    ctx->maxBounds = maxBounds;
    ctx->listSize = listSize;
}

variable_types: struct NLSystemContext { struct __mpf_struct { int _mp_prec; int _mp_size; long _mp_exp; unsigned long *_mp_d; } (*state)[1]; struct __mpf_struct (*minBounds)[1]; struct __mpf_struct (*maxBounds)[1]; unsigned int listSize; } *

variable_types:
initialState
struct __mpf_struct (*)[1]

variable_types:
minBounds
struct __mpf_struct (*)[1]

variable_types:
maxBounds
struct __mpf_struct (*)[1]

variable_types:
listSize
unsigned int

user_defined_types: struct NLSystemContext { struct __mpf_struct (*state)[1]; struct __mpf_struct (*minBounds)[1]; struct __mpf_struct (*maxBounds)[1]; unsigned int listSize; }


checkBounds

decompiled_code:
__int64 __fastcall checkBounds(_QWORD *a1, int a2)
{
int i; // ecx

if ( !a2 )
return 0LL;
for ( i = 0; i != a2; ++i )
{
if ( *a1 != a1[1] )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, int a2)
{
int i; // ecx

if ( !a2 )
return 0LL;
for ( i = 0; i != a2; ++i )
{
if ( *a1 != a1[1] )
return 0LL;
}
return 1LL;
}

original_code:
bool checkBounds(NLSystemContext* ctx, uint32 boundsSize) {
    bool out = 0;
    int i;
    for(i = 0; i < boundsSize; i++) {
        if((ctx->state[i] >= ctx->minBounds[i]) && (ctx->state[i] <= ctx->minBounds[i])) {
            out = 1;
            continue;
        }
        out = 0;
        break;
    }
    return out;
}

canonical_original_code:
int checkBounds(struct NLSystemContext *ctx, unsigned int boundsSize) {
    int out = 0;
    int i;
    for(i = 0; i < boundsSize; i++) {
        if((ctx->state[i] >= ctx->minBounds[i]) && (ctx->state[i] <= ctx->minBounds[i])) {
            out = 1;
            continue;
        }
        out = 0;
        break;
    }
    return out;
}

variable_types:
boundsSize
unsigned int

variable_types: out int

variable_types: i int

user_defined_types: struct __mpf_struct { int _mp_prec; int _mp_size; long _mp_exp; unsigned long *_mp_d; }


clearArray

decompiled_code:
__int64 __fastcall clearArray(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( a2 )
{
v2 = a1;
do
{
result = __gmpf_clear();
v2 += 24LL;
}
while ( v2 != a1 + 24LL * (unsigned int)(a2 - 1) + 24 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( a2 )
{
v2 = a1;
do
{
result = __gmpf_clear();
v2 += 24LL;
}
while ( v2 != a1 + 24LL * (unsigned int)(a2 - 1) + 24 );
}
return result;
}

original_code:
void clearArray(bigFloat* source, uint32 numVars) {
    uint32 i;
    for(i = 0; i < numVars; i++) {
        __gmpf_clear(source[i]);
    }
}

canonical_original_code:
void clearArray(struct __mpf_struct (*source)[1], unsigned int numVars) {
    unsigned int i;
    for(i = 0; i < numVars; i++) {
        __gmpf_clear(source[i]);
    }
}