decompiled_code:
unsigned __int16 rand8_8bit()
{
unsigned __int16 result; // ax
unsigned __int8 v1; // dl

result = word_360 + (unsigned __int8)word_365 * (unsigned __int8)rand8[(unsigned __int8)byte_362];
v1 = byte_362 + 1;
rand8[(unsigned __int8)byte_362] = result;
word_360 = HIBYTE(result);
if ( (unsigned __int8)byte_364 <= v1 )
v1 = 0;
byte_362 = v1;
return result;
}

canonical_decompiled_code:
unsigned __int16 func1()
{
unsigned __int16 result; // ax
unsigned __int8 v1; // dl

result = word_360 + (unsigned __int8)word_365 * (unsigned __int8)rand8[(unsigned __int8)byte_362];
v1 = byte_362 + 1;
rand8[(unsigned __int8)byte_362] = result;
word_360 = HIBYTE(result);
if ( (unsigned __int8)byte_364 <= v1 )
v1 = 0;
byte_362 = v1;
return result;
}

original_code:
uint8_t rand8_8bit(void)
{
    uint8_t i = rand8.i;
    uint8_t x = rand8.state[i];
    uint16_t c = rand8.c;
    uint16_t t;
    t = (uint16_t)((uint8_t)(x) * (uint8_t)(rand8.mul_lo)) + c;
    c = t >> 8;
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}

canonical_original_code:
unsigned char rand8_8bit()
{
    unsigned char i = rand8.i;
    unsigned char x = rand8.state[i];
    unsigned short c = rand8.c;
    unsigned short t;
    t = (unsigned short)((unsigned char)(x) * (unsigned char)(rand8.mul_lo)) + c;
    c = t >> 8;
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}

variable_types:
i
unsigned char


decompiled_code:
__int64 rand16_8bit()
{
int v0; // esi
int v1; // eax

v0 = (unsigned __int8)rand8_8bit();
LOWORD(v1) = rand8_8bit();
return (unsigned int)(v0 + (v1 << 8));
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // esi
int v1; // eax

v0 = (unsigned __int8)func1();
LOWORD(v1) = func1();
return (unsigned int)(v0 + (v1 << 8));
}

original_code:
uint16_t rand16_8bit(void)
{
    uint8_t x, y;
    x = rand8_8bit();
    y = rand8_8bit();
    return ((uint16_t)y << 8) + x;
}

canonical_original_code:
unsigned short rand16_8bit()
{
    unsigned char x; unsigned char y;
    x = rand8_8bit();
    y = rand8_8bit();
    return ((unsigned short)y << 8) + x;
}

variable_types:
x
unsigned char

variable_types:
y
unsigned char

return_type: unsigned short


decompiled_code:
__int64 rand32_8bit()
{
__int64 v0; // rdi

v0 = (unsigned __int16)((__int64 (*)(void))rand16_8bit)();
return (unsigned int)v0 + ((unsigned int)rand16_8bit(v0) << 16);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rdi

v0 = (unsigned __int16)((__int64 (*)(void))rand16_8bit)();
return (unsigned int)v0 + ((unsigned int)func2(v0) << 16);
}

original_code:
uint32_t rand32_8bit(void)
{
    uint16_t x, y;
    x = rand16_8bit();
    y = rand16_8bit();
    return ((uint32_t)y << 16) + x;
}

canonical_original_code:
unsigned int rand32_8bit()
{
    unsigned short x; unsigned short y;
    x = rand16_8bit();
    y = rand16_8bit();
    return ((unsigned int)y << 16) + x;
}

variable_types:
x
unsigned short

variable_types:
y
unsigned short

return_type: unsigned int


decompiled_code:
__int64 rand8_9bit()
{
int v0; // esi
__int16 v1; // cx
char v2; // dl
__int64 result; // rax
unsigned __int16 v4; // r8

v0 = (unsigned __int8)byte_362 + 1;
v1 = (unsigned __int8)rand8[(unsigned __int8)byte_362];
v2 = byte_362 + 1;
result = (unsigned __int16)(word_360 + (unsigned __int8)word_365 * v1);
v4 = word_360 + (unsigned __int8)word_365 * v1;
rand8[(unsigned __int8)byte_362] = word_360 + word_365 * rand8[(unsigned __int8)byte_362];
word_360 = HIBYTE(v4) + v1;
if ( (unsigned __int8)byte_364 <= v0 )
v2 = 0;
byte_362 = v2;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // esi
__int16 v1; // cx
char v2; // dl
__int64 result; // rax
unsigned __int16 v4; // r8

v0 = (unsigned __int8)byte_362 + 1;
v1 = (unsigned __int8)rand8[(unsigned __int8)byte_362];
v2 = byte_362 + 1;
result = (unsigned __int16)(word_360 + (unsigned __int8)word_365 * v1);
v4 = word_360 + (unsigned __int8)word_365 * v1;
rand8[(unsigned __int8)byte_362] = word_360 + word_365 * rand8[(unsigned __int8)byte_362];
word_360 = HIBYTE(v4) + v1;
if ( (unsigned __int8)byte_364 <= v0 )
v2 = 0;
byte_362 = v2;
return result;
}

original_code:
uint8_t rand8_9bit(void)
{
    int i = rand8.i;
    uint8_t x = rand8.state[i];
    uint16_t c = rand8.c;
    uint16_t t;
    t = (uint16_t)((uint8_t)(x) * (uint8_t)(rand8.mul_lo)) + c;
    c = t >> 8;
    c += x;
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}

canonical_original_code:
unsigned char rand8_9bit()
{
    int i = rand8.i;
    unsigned char x = rand8.state[i];
    unsigned short c = rand8.c;
    unsigned short t;
    t = (unsigned short)((unsigned char)(x) * (unsigned char)(rand8.mul_lo)) + c;
    c = t >> 8;
    c += x;
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}

variable_types: i int

variable_types:
c
unsigned short

variable_types:
t
unsigned short

return_type: unsigned char


decompiled_code:
__int64 __fastcall rand16_9bit(__int64 a1, __int64 a2)
{
unsigned __int8 v2; // al
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
int v6; // eax
int v7; // er9

v2 = ((__int64 (*)(void))rand8_9bit)();
v6 = rand8_9bit(a1, a2, v3, v4, v5, v2);
return (unsigned int)(v7 + (v6 << 8));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
unsigned __int8 v2; // al
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
int v6; // eax
int v7; // er9

v2 = ((__int64 (*)(void))rand8_9bit)();
v6 = func4(a1, a2, v3, v4, v5, v2);
return (unsigned int)(v7 + (v6 << 8));
}

original_code:
uint16_t rand16_9bit(void)
{
    uint8_t x, y;
    x = rand8_9bit();
    y = rand8_9bit();
    return ((uint16_t)y << 8) + x;
}

canonical_original_code:
unsigned short rand16_9bit()
{
    unsigned char x; unsigned char y;
    x = rand8_9bit();
    y = rand8_9bit();
    return ((unsigned short)y << 8) + x;
}


decompiled_code:
__int64 __fastcall rand32_9bit(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // er10

rand16_9bit(a1, a2);
v2 = rand16_9bit(a1, a2);
return (unsigned int)(v3 + (v2 << 16));
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // er10

func5(a1, a2);
v2 = func5(a1, a2);
return (unsigned int)(v3 + (v2 << 16));
}

original_code:
uint32_t rand32_9bit(void)
{
    uint16_t x, y;
    x = rand16_9bit();
    y = rand16_9bit();
    return ((uint32_t)y << 16) + x;
}

canonical_original_code:
unsigned int rand32_9bit()
{
    unsigned short x; unsigned short y;
    x = rand16_9bit();
    y = rand16_9bit();
    return ((unsigned int)y << 16) + x;
}


decompiled_code:
__int64 rand8_16bit()
{
int v0; // edi
char v1; // dl
unsigned int v2; // eax
unsigned int v3; // esi
unsigned __int16 v4; // r9
__int64 result; // rax

v0 = (unsigned __int8)byte_362 + 1;
v1 = byte_362 + 1;
v2 = (unsigned __int16)((unsigned __int8)word_365 * (unsigned __int8)rand8[(unsigned __int8)byte_362]);
LOWORD(v2) = word_360 + v2;
v3 = v2;
v4 = v2;
LOWORD(v2) = HIBYTE(word_365) * (unsigned __int8)rand8[(unsigned __int8)byte_362];
rand8[(unsigned __int8)byte_362] = v3;
word_360 = HIBYTE(v4) + v2;
if ( (unsigned __int8)byte_364 <= v0 )
v1 = 0;
result = v3;
byte_362 = v1;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // edi
char v1; // dl
unsigned int v2; // eax
unsigned int v3; // esi
unsigned __int16 v4; // r9
__int64 result; // rax

v0 = (unsigned __int8)byte_362 + 1;
v1 = byte_362 + 1;
v2 = (unsigned __int16)((unsigned __int8)word_365 * (unsigned __int8)rand8[(unsigned __int8)byte_362]);
LOWORD(v2) = word_360 + v2;
v3 = v2;
v4 = v2;
LOWORD(v2) = HIBYTE(word_365) * (unsigned __int8)rand8[(unsigned __int8)byte_362];
rand8[(unsigned __int8)byte_362] = v3;
word_360 = HIBYTE(v4) + v2;
if ( (unsigned __int8)byte_364 <= v0 )
v1 = 0;
result = v3;
byte_362 = v1;
return result;
}

original_code:
uint8_t rand8_16bit(void)
{
    int i = rand8.i;
    uint8_t x = rand8.state[i];
    uint16_t c = rand8.c;
    uint16_t t;
    t = (uint16_t)((uint8_t)(x) * (uint8_t)(rand8.mul_lo)) + c;
    c = t >> 8;
    c += (uint16_t)((uint8_t)(x) * (uint8_t)(rand8.mul_hi));
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}

canonical_original_code:
unsigned char rand8_16bit()
{
    int i = rand8.i;
    unsigned char x = rand8.state[i];
    unsigned short c = rand8.c;
    unsigned short t;
    t = (unsigned short)((unsigned char)(x) * (unsigned char)(rand8.mul_lo)) + c;
    c = t >> 8;
    c += (unsigned short)((unsigned char)(x) * (unsigned char)(rand8.mul_hi));
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}


decompiled_code:
__int64 rand16_16bit()
{
int v0; // eax
int v1; // er10

rand8_16bit();
v0 = rand8_16bit();
return (unsigned int)(v1 + (v0 << 8));
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // eax
int v1; // er10

func7();
v0 = func7();
return (unsigned int)(v1 + (v0 << 8));
}

original_code:
uint16_t rand16_16bit(void)
{
    uint8_t x, y;
    x = rand8_16bit();
    y = rand8_16bit();
    return ((uint16_t)y << 8) + x;
}

canonical_original_code:
unsigned short rand16_16bit()
{
    unsigned char x; unsigned char y;
    x = rand8_16bit();
    y = rand8_16bit();
    return ((unsigned short)y << 8) + x;
}


decompiled_code:
__int64 rand32_16bit()
{
int v0; // eax
int v1; // er11

rand16_16bit();
v0 = rand16_16bit();
return (unsigned int)(v1 + (v0 << 16));
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // eax
int v1; // er11

func8();
v0 = func8();
return (unsigned int)(v1 + (v0 << 16));
}

original_code:
uint32_t rand32_16bit(void)
{
    uint16_t x, y;
    x = rand16_16bit();
    y = rand16_16bit();
    return ((uint32_t)y << 16) + x;
}

canonical_original_code:
unsigned int rand32_16bit()
{
    unsigned short x; unsigned short y;
    x = rand16_16bit();
    y = rand16_16bit();
    return ((unsigned int)y << 16) + x;
}


decompiled_code:
__int64 rand8_8z8bit()
{
int v0; // edi
char v1; // dl
__int64 result; // rax

v0 = (unsigned __int8)byte_362 + 1;
v1 = byte_362 + 1;
result = (unsigned __int16)word_360
+ (unsigned __int16)((unsigned __int8)word_365 * (unsigned __int8)rand8[(unsigned __int8)byte_362])
+ (((unsigned __int8)byte_363
+ (unsigned int)(unsigned __int16)(HIBYTE(word_365) * (unsigned __int8)rand8[(unsigned __int8)byte_362])) << 16);
rand8[(unsigned __int8)byte_362] = word_360 + word_365 * rand8[(unsigned __int8)byte_362];
word_360 = (unsigned int)result >> 8;
byte_363 = BYTE3(result);
if ( (unsigned __int8)byte_364 <= v0 )
v1 = 0;
byte_362 = v1;
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // edi
char v1; // dl
__int64 result; // rax

v0 = (unsigned __int8)byte_362 + 1;
v1 = byte_362 + 1;
result = (unsigned __int16)word_360
+ (unsigned __int16)((unsigned __int8)word_365 * (unsigned __int8)rand8[(unsigned __int8)byte_362])
+ (((unsigned __int8)byte_363
+ (unsigned int)(unsigned __int16)(HIBYTE(word_365) * (unsigned __int8)rand8[(unsigned __int8)byte_362])) << 16);
rand8[(unsigned __int8)byte_362] = word_360 + word_365 * rand8[(unsigned __int8)byte_362];
word_360 = (unsigned int)result >> 8;
byte_363 = BYTE3(result);
if ( (unsigned __int8)byte_364 <= v0 )
v1 = 0;
byte_362 = v1;
return result;
}

original_code:
uint8_t rand8_8z8bit(void)
{
    int i = rand8.i;
    uint8_t x = rand8.state[i];
    uint16_t c0 = rand8.c;
    uint8_t c1 = rand8.c1;
    uint32_t t;
    t = (uint16_t)((uint8_t)(x) * (uint8_t)(rand8.mul_lo)) + (uint32_t)c0;
    t += (uint32_t)((uint16_t)((uint8_t)(x) * (uint8_t)(rand8.mul_hi)) + c1) << 16;
    c0 = t >> 8;
    c1 = t >> 24;
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c0;
    rand8.c1 = c1;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}

canonical_original_code:
unsigned char rand8_8z8bit()
{
    int i = rand8.i;
    unsigned char x = rand8.state[i];
    unsigned short c0 = rand8.c;
    unsigned char c1 = rand8.c1;
    unsigned int t;
    t = (unsigned short)((unsigned char)(x) * (unsigned char)(rand8.mul_lo)) + (unsigned int)c0;
    t += (unsigned int)((unsigned short)((unsigned char)(x) * (unsigned char)(rand8.mul_hi)) + c1) << 16;
    c0 = t >> 8;
    c1 = t >> 24;
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c0;
    rand8.c1 = c1;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}

variable_types:
t
unsigned int


decompiled_code:
__int64 __fastcall rand16_8z8bit(__int64 a1, __int64 a2)
{
unsigned __int8 v2; // al
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
int v6; // eax
int v7; // er9

v2 = ((__int64 (*)(void))rand8_8z8bit)();
v6 = rand8_8z8bit(a1, a2, v3, v4, v5, v2);
return (unsigned int)(v7 + (v6 << 8));
}

original_code:
uint16_t rand16_8z8bit(void)
{
    uint8_t x, y;
    x = rand8_8z8bit();
    y = rand8_8z8bit();
    return ((uint16_t)y << 8) + x;
}

canonical_original_code:
unsigned short rand16_8z8bit()
{
    unsigned char x; unsigned char y;
    x = rand8_8z8bit();
    y = rand8_8z8bit();
    return ((unsigned short)y << 8) + x;
}


decompiled_code:
__int64 __fastcall rand32_8z8bit(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // er10

rand16_8z8bit(a1, a2);
v2 = rand16_8z8bit(a1, a2);
return (unsigned int)(v3 + (v2 << 16));
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // er10

func11(a1, a2);
v2 = func11(a1, a2);
return (unsigned int)(v3 + (v2 << 16));
}

original_code:
uint32_t rand32_8z8bit(void)
{
    uint16_t x, y;
    x = rand16_8z8bit();
    y = rand16_8z8bit();
    return ((uint32_t)y << 16) + x;
}

canonical_original_code:
unsigned int rand32_8z8bit()
{
    unsigned short x; unsigned short y;
    x = rand16_8z8bit();
    y = rand16_8z8bit();
    return ((unsigned int)y << 16) + x;
}


decompiled_code:
__int64 __fastcall p32(unsigned __int16 a1, unsigned __int16 a2, unsigned int a3, __int64 a4, char a5)
{
unsigned __int16 v6; // di
int v7; // er9
__int64 v8; // rbx
__int64 v9; // r12
unsigned int v10; // er10
__int64 v11; // rax
unsigned __int64 v12; // rdx
unsigned __int64 v13; // rdx

v6 = a2;
v7 = ~(-2 << (a5 - 1));
v8 = a1;
v9 = 0LL;
v10 = v7 & a3;
v11 = v7 & a3;
while ( 1 )
{
++v9;
v12 = v8 * v11 + a2;
v11 = (unsigned int)v12 & v7;
v13 = v12 >> a5;
a2 = v13;
if ( v9 == a4 )
return v9;
if ( v6 > (unsigned __int16)v13 || v6 == (_WORD)v13 && v10 > (unsigned int)v11 )
break;
if ( v6 == (_WORD)v13 && v10 == (_DWORD)v11 )
return v9;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1, unsigned __int16 a2, unsigned int a3, __int64 a4, char a5)
{
unsigned __int16 v6; // di
int v7; // er9
__int64 v8; // rbx
__int64 v9; // r12
unsigned int v10; // er10
__int64 v11; // rax
unsigned __int64 v12; // rdx
unsigned __int64 v13; // rdx

v6 = a2;
v7 = ~(-2 << (a5 - 1));
v8 = a1;
v9 = 0LL;
v10 = v7 & a3;
v11 = v7 & a3;
while ( 1 )
{
++v9;
v12 = v8 * v11 + a2;
v11 = (unsigned int)v12 & v7;
v13 = v12 >> a5;
a2 = v13;
if ( v9 == a4 )
return v9;
if ( v6 > (unsigned __int16)v13 || v6 == (_WORD)v13 && v10 > (unsigned int)v11 )
break;
if ( v6 == (_WORD)v13 && v10 == (_DWORD)v11 )
return v9;
}
return 0LL;
}

original_code:
static uint64_t p32(uint16_t a, uint16_t c, uint32_t x, uint64_t b, int s)
{
    uint32_t m = ~(0xfffffffe << (s - 1));
    uint16_t cc = c;
    uint64_t xx;
    uint64_t p = 0;
    xx = x &= m;
    do
    {
        uint64_t t = (uint64_t)x * a + c;
        x = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && x < xx))
            return 0;
    } while (x != xx || c != cc);
    return p;
}

canonical_original_code:
static unsigned long p32(unsigned short a, unsigned short c, unsigned int x, unsigned long b, int s)
{
    unsigned int m = ~(0xfffffffe << (s - 1));
    unsigned short cc = c;
    unsigned long xx;
    unsigned long p = 0;
    xx = x &= m;
    do
    {
        unsigned long t = (uint64_t)x * a + c;
        x = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && x < xx))
            return 0;
    } while (x != xx || c != cc);
    return p;
}

variable_types:
a
unsigned short

variable_types:
x
unsigned int

variable_types:
b
unsigned long

variable_types: s int

variable_types:
m
unsigned int

variable_types:
cc
unsigned short

variable_types:
xx
unsigned long

variable_types:
p
unsigned long

variable_types:
t
unsigned long

return_type: unsigned long


original_code:
static uint64_t p56(uint16_t a, uint16_t c, uint64_t x, uint64_t b, int s)
{
    uint64_t m = ~(0xfffffffffffffffeull << (s - 1));
    uint16_t cc = c;
    uint64_t xx;
    uint64_t p = 0;
    xx = x &= m;
    do
    {
        uint64_t t = x * a + c;
        x = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && x < xx))
            return 0;
    } while (x != xx || c != cc);
    return p;
}

canonical_original_code:
static unsigned long p56(unsigned short a, unsigned short c, unsigned long x, unsigned long b, int s)
{
    unsigned long m = ~(0xfffffffffffffffeull << (s - 1));
    unsigned short cc = c;
    unsigned long xx;
    unsigned long p = 0;
    xx = x &= m;
    do
    {
        unsigned long t = x * a + c;
        x = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && x < xx))
            return 0;
    } while (x != xx || c != cc);
    return p;
}

variable_types:
x
unsigned long

variable_types:
m
unsigned long


decompiled_code:
__int64 __fastcall p64(unsigned __int16 a1, unsigned __int16 a2, unsigned __int64 a3, __int64 a4, char a5)
{
int v6; // er10
unsigned __int64 v7; // rbp
unsigned __int16 v8; // bx
unsigned int v9; // ebp
unsigned __int64 v10; // r12
char v11; // cl
__int64 v12; // r9
unsigned int v13; // er13
__int64 v14; // r8
unsigned __int64 v15; // rdi
unsigned __int64 v16; // rax
unsigned __int64 v17; // rax

v6 = ~(-2 << (a5 - 1));
v7 = HIDWORD(a3);
a3 = (unsigned int)a3;
v8 = a2;
v9 = v6 & v7;
v10 = (unsigned int)a3;
v11 = ((a5 - 1) & 0x1F) + 1;
v12 = a1;
v13 = v9;
v14 = 0LL;
while ( 1 )
{
while ( 1 )
{
++v14;
v15 = v12 * a3 + a2;
a3 = (unsigned int)v15;
v16 = HIDWORD(v15) + v12 * v13;
v13 = v16 & v6;
v17 = v16 >> v11;
a2 = v17;
if ( v14 == a4 )
return v14;
if ( v8 > (unsigned __int16)v17 )
return 0LL;
if ( v8 == (_WORD)v17 )
{
if ( v9 > v13 )
return 0LL;
if ( v9 == v13 )
break;
}
}
if ( v10 > (unsigned int)v15 )
break;
if ( v10 == (unsigned int)v15 )
return v14;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1, unsigned __int16 a2, unsigned __int64 a3, __int64 a4, char a5)
{
int v6; // er10
unsigned __int64 v7; // rbp
unsigned __int16 v8; // bx
unsigned int v9; // ebp
unsigned __int64 v10; // r12
char v11; // cl
__int64 v12; // r9
unsigned int v13; // er13
__int64 v14; // r8
unsigned __int64 v15; // rdi
unsigned __int64 v16; // rax
unsigned __int64 v17; // rax

v6 = ~(-2 << (a5 - 1));
v7 = HIDWORD(a3);
a3 = (unsigned int)a3;
v8 = a2;
v9 = v6 & v7;
v10 = (unsigned int)a3;
v11 = ((a5 - 1) & 0x1F) + 1;
v12 = a1;
v13 = v9;
v14 = 0LL;
while ( 1 )
{
while ( 1 )
{
++v14;
v15 = v12 * a3 + a2;
a3 = (unsigned int)v15;
v16 = HIDWORD(v15) + v12 * v13;
v13 = v16 & v6;
v17 = v16 >> v11;
a2 = v17;
if ( v14 == a4 )
return v14;
if ( v8 > (unsigned __int16)v17 )
return 0LL;
if ( v8 == (_WORD)v17 )
{
if ( v9 > v13 )
return 0LL;
if ( v9 == v13 )
break;
}
}
if ( v10 > (unsigned int)v15 )
break;
if ( v10 == (unsigned int)v15 )
return v14;
}
return 0LL;
}

canonical_original_code:
static unsigned long p64(unsigned short a, unsigned short c, unsigned long x, unsigned long b, int s)
{
    unsigned int m = ~(0xfffffffe << ((s - 1) & 31));
    unsigned int x0 = x & 0xffffffff; unsigned int x1 = (x >> 32) & m;
    unsigned short cc = c;
    unsigned long xx0 = x0;
    unsigned long xx1 = x1;
    unsigned long p = 0;
    s = ((s - 1) & 31) + 1;
    do
    {
        unsigned long t = (uint64_t)x0 * a + c;
        x0 = (unsigned int)t;
        c = t >> 32;
        t = (unsigned long)x1 * a + c;
        x1 = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && (x1 < xx1 || (x1 <= xx1 && x0 < xx0))))
            return 0;
    } while (x0 != xx0 || x1 != xx1 || c != cc);
    return p;
}


decompiled_code:
__int64 __fastcall p96(unsigned __int16 a1, unsigned __int16 a2, unsigned __int64 a3, __int64 a4, char a5)
{
char v6; // cl
__int64 v7; // r8
unsigned __int64 v8; // r14
unsigned __int64 v9; // rbp
int v10; // er12
char v11; // cl
int v12; // er12
unsigned __int64 v13; // rax
unsigned __int64 v14; // rdx
__int64 v15; // rdi
unsigned __int16 v16; // r15
__int64 v18; // r10
__int64 v19; // r11
__int64 v20; // r9
__int64 v21; // rdi
unsigned __int64 v22; // rsi
unsigned __int64 v23; // rsi

v6 = a5 - 1;
v7 = a1;
v8 = HIDWORD(a3);
v9 = (unsigned int)a3;
v10 = -2 << v6;
v11 = (v6 & 0x1F) + 1;
v12 = ~v10;
LODWORD(v13) = a1 * (_DWORD)a3 + a2;
v14 = a1 * HIDWORD(a3) + ((a1 * (unsigned __int64)(unsigned int)a3 + a2) >> 32);
v15 = HIDWORD(v14) & (unsigned int)v12;
if ( a4 == 1 )
return 1LL;
if ( a2 <= (unsigned __int16)(HIDWORD(v14) >> v11) )
{
v16 = HIDWORD(v14) >> v11;
v18 = (unsigned int)v13;
v19 = (unsigned int)v14;
v20 = 1LL;
do
{
if ( (_DWORD)v15 || a2 < v16 )
{
if ( v9 == (unsigned int)v13 && (unsigned int)v14 == v8 && !(_DWORD)v15 )
goto LABEL_12;
}
else
{
if ( v8 > (unsigned int)v14 )
return 0LL;
if ( v8 == (unsigned int)v14 )
{
if ( v9 > (unsigned int)v13 )
return 0LL;
if ( v9 == (unsigned int)v13 )
{
LABEL_12:
if ( a2 == v16 )
return v20;
v21 = 0LL;
goto LABEL_5;
}
}
}
v21 = v7 * v15;
LABEL_5:
++v20;
v13 = v7 * v18 + v16;
v18 = (_DWORD)v7 * (_DWORD)v18 + (unsigned int)v16;
v14 = v7 * v19 + HIDWORD(v13);
v19 = (unsigned int)(v7 * v19 + HIDWORD(v13));
v22 = v21 + HIDWORD(v14);
v15 = (unsigned int)v22 & v12;
v23 = v22 >> v11;
v16 = v23;
if ( v20 == a4 )
return v20;
}
while ( a2 <= (unsigned __int16)v23 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1, unsigned __int16 a2, unsigned __int64 a3, __int64 a4, char a5)
{
char v6; // cl
__int64 v7; // r8
unsigned __int64 v8; // r14
unsigned __int64 v9; // rbp
int v10; // er12
char v11; // cl
int v12; // er12
unsigned __int64 v13; // rax
unsigned __int64 v14; // rdx
__int64 v15; // rdi
unsigned __int16 v16; // r15
__int64 v18; // r10
__int64 v19; // r11
__int64 v20; // r9
__int64 v21; // rdi
unsigned __int64 v22; // rsi
unsigned __int64 v23; // rsi

v6 = a5 - 1;
v7 = a1;
v8 = HIDWORD(a3);
v9 = (unsigned int)a3;
v10 = -2 << v6;
v11 = (v6 & 0x1F) + 1;
v12 = ~v10;
LODWORD(v13) = a1 * (_DWORD)a3 + a2;
v14 = a1 * HIDWORD(a3) + ((a1 * (unsigned __int64)(unsigned int)a3 + a2) >> 32);
v15 = HIDWORD(v14) & (unsigned int)v12;
if ( a4 == 1 )
return 1LL;
if ( a2 <= (unsigned __int16)(HIDWORD(v14) >> v11) )
{
v16 = HIDWORD(v14) >> v11;
v18 = (unsigned int)v13;
v19 = (unsigned int)v14;
v20 = 1LL;
do
{
if ( (_DWORD)v15 || a2 < v16 )
{
if ( v9 == (unsigned int)v13 && (unsigned int)v14 == v8 && !(_DWORD)v15 )
goto LABEL_12;
}
else
{
if ( v8 > (unsigned int)v14 )
return 0LL;
if ( v8 == (unsigned int)v14 )
{
if ( v9 > (unsigned int)v13 )
return 0LL;
if ( v9 == (unsigned int)v13 )
{
LABEL_12:
if ( a2 == v16 )
return v20;
v21 = 0LL;
goto LABEL_5;
}
}
}
v21 = v7 * v15;
LABEL_5:
++v20;
v13 = v7 * v18 + v16;
v18 = (_DWORD)v7 * (_DWORD)v18 + (unsigned int)v16;
v14 = v7 * v19 + HIDWORD(v13);
v19 = (unsigned int)(v7 * v19 + HIDWORD(v13));
v22 = v21 + HIDWORD(v14);
v15 = (unsigned int)v22 & v12;
v23 = v22 >> v11;
v16 = v23;
if ( v20 == a4 )
return v20;
}
while ( a2 <= (unsigned __int16)v23 );
}
return 0LL;
}

canonical_original_code:
static unsigned long p96(unsigned short a, unsigned short c, unsigned long x, unsigned long b, int s)
{
    unsigned int m = ~(0xfffffffe << ((s - 1) & 31));
    unsigned int x0 = x & 0xffffffff; unsigned int x1 = x >> 32; unsigned int x2 = 0;
    unsigned short cc = c;
    unsigned long xx0 = x0;
    unsigned long xx1 = x1;
    unsigned long xx2 = x2;
    unsigned long p = 0;
    s = ((s - 1) & 31) + 1;
    do
    {
        unsigned long t = (uint64_t)x0 * a + c;
        x0 = (unsigned int)t;
        c = t >> 32;
        t = (unsigned long)x1 * a + c;
        x1 = (unsigned int)t;
        c = t >> 32;
        t = (unsigned long)x2 * a + c;
        x2 = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && (x2 < xx2 || (x2 <= xx2 && (x1 < xx1 || (x1 <= xx1 && x0 < xx0))))))
            return 0;
    } while (x0 != xx0 || x1 != xx1 || x2 != xx2 || c != cc);
    return p;
}


decompiled_code:
__int64 __fastcall p128(unsigned __int16 a1, unsigned __int16 a2, unsigned __int64 a3, __int64 a4, char a5)
{
unsigned __int64 v6; // rax
__int64 v7; // r9
unsigned __int64 v9; // r14
unsigned __int64 v10; // rdi
unsigned __int64 v11; // rbp
char v12; // cl
unsigned __int64 v13; // rdx
unsigned __int64 v14; // rsi
unsigned __int64 v15; // rdi
int v16; // er12
__int64 v17; // r11
__int64 v18; // rbx
__int64 v19; // r10
__int64 v20; // r8
__int64 v21; // r8
unsigned __int64 v22; // rax
unsigned __int64 v23; // rax
__int64 result; // rax

LOWORD(v6) = a2;
v7 = a1;
v9 = HIDWORD(a3);
v10 = HIDWORD(a3);
v11 = (unsigned int)a3;
v12 = ((a5 - 1) & 0x1F) + 1;
v13 = v7 * (unsigned int)a3 + a2;
v14 = v7 * v10 + HIDWORD(v13);
v15 = HIDWORD(v14);
if ( a4 == 1 )
{
v19 = 1LL;
LABEL_17:
result = v19;
}
else
{
if ( !a2 )
{
v16 = ~(-2 << (a5 - 1));
v17 = (unsigned int)v13;
v18 = (unsigned int)v14;
v19 = 1LL;
v20 = 0LL;
while ( (unsigned int)v20 | (unsigned int)v15 || (_WORD)v6 )
{
if ( v11 != (unsigned int)v13 || (unsigned int)v14 != v9 || (_DWORD)v15 )
goto LABEL_4;
if ( (_DWORD)v20 )
{
v21 = v7 * v20;
v15 = 0LL;
}
else
{
if ( !(_WORD)v6 )
goto LABEL_17;
v21 = 0LL;
v15 = 0LL;
}
LABEL_5:
++v19;
v13 = v7 * v17 + (unsigned __int16)v6;
v17 = (_DWORD)v7 * (_DWORD)v17 + (unsigned int)(unsigned __int16)v6;
v14 = v7 * v18 + HIDWORD(v13);
v18 = (unsigned int)(v7 * v18 + HIDWORD(v13));
v22 = v15 + HIDWORD(v14);
LODWORD(v15) = v15 + HIDWORD(v14);
v23 = v21 + HIDWORD(v22);
v20 = (unsigned int)v23 & v16;
v6 = v23 >> v12;
if ( v19 == a4 )
goto LABEL_17;
}
if ( v9 > (unsigned int)v14 )
goto LABEL_20;
if ( v9 == (unsigned int)v14 )
{
if ( v11 > (unsigned int)v13 )
goto LABEL_20;
if ( v11 == (unsigned int)v13 )
goto LABEL_17;
}
LABEL_4:
v21 = v7 * v20;
v15 = v7 * (unsigned int)v15;
goto LABEL_5;
}
LABEL_20:
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 a1, unsigned __int16 a2, unsigned __int64 a3, __int64 a4, char a5)
{
unsigned __int64 v6; // rax
__int64 v7; // r9
unsigned __int64 v9; // r14
unsigned __int64 v10; // rdi
unsigned __int64 v11; // rbp
char v12; // cl
unsigned __int64 v13; // rdx
unsigned __int64 v14; // rsi
unsigned __int64 v15; // rdi
int v16; // er12
__int64 v17; // r11
__int64 v18; // rbx
__int64 v19; // r10
__int64 v20; // r8
__int64 v21; // r8
unsigned __int64 v22; // rax
unsigned __int64 v23; // rax
__int64 result; // rax

LOWORD(v6) = a2;
v7 = a1;
v9 = HIDWORD(a3);
v10 = HIDWORD(a3);
v11 = (unsigned int)a3;
v12 = ((a5 - 1) & 0x1F) + 1;
v13 = v7 * (unsigned int)a3 + a2;
v14 = v7 * v10 + HIDWORD(v13);
v15 = HIDWORD(v14);
if ( a4 == 1 )
{
v19 = 1LL;
LABEL_17:
result = v19;
}
else
{
if ( !a2 )
{
v16 = ~(-2 << (a5 - 1));
v17 = (unsigned int)v13;
v18 = (unsigned int)v14;
v19 = 1LL;
v20 = 0LL;
while ( (unsigned int)v20 | (unsigned int)v15 || (_WORD)v6 )
{
if ( v11 != (unsigned int)v13 || (unsigned int)v14 != v9 || (_DWORD)v15 )
goto LABEL_4;
if ( (_DWORD)v20 )
{
v21 = v7 * v20;
v15 = 0LL;
}
else
{
if ( !(_WORD)v6 )
goto LABEL_17;
v21 = 0LL;
v15 = 0LL;
}
LABEL_5:
++v19;
v13 = v7 * v17 + (unsigned __int16)v6;
v17 = (_DWORD)v7 * (_DWORD)v17 + (unsigned int)(unsigned __int16)v6;
v14 = v7 * v18 + HIDWORD(v13);
v18 = (unsigned int)(v7 * v18 + HIDWORD(v13));
v22 = v15 + HIDWORD(v14);
LODWORD(v15) = v15 + HIDWORD(v14);
v23 = v21 + HIDWORD(v22);
v20 = (unsigned int)v23 & v16;
v6 = v23 >> v12;
if ( v19 == a4 )
goto LABEL_17;
}
if ( v9 > (unsigned int)v14 )
goto LABEL_20;
if ( v9 == (unsigned int)v14 )
{
if ( v11 > (unsigned int)v13 )
goto LABEL_20;
if ( v11 == (unsigned int)v13 )
goto LABEL_17;
}
LABEL_4:
v21 = v7 * v20;
v15 = v7 * (unsigned int)v15;
goto LABEL_5;
}
LABEL_20:
result = 0LL;
}
return result;
}

canonical_original_code:
static unsigned long p128(unsigned short a, unsigned short c, unsigned long x, unsigned long b, int s)
{
    unsigned int m = ~(0xfffffffe << ((s - 1) & 31));
    unsigned int x0 = x & 0xffffffff; unsigned int x1 = x >> 32; unsigned int x2 = 0; unsigned int x3 = 0;
    unsigned short cc = c;
    unsigned long xx0 = x0;
    unsigned long xx1 = x1;
    unsigned long xx2 = x2;
    unsigned long xx3 = x3;
    unsigned long p = 0;
    s = ((s - 1) & 31) + 1;
    do
    {
        unsigned long t = (uint64_t)x0 * a + c;
        x0 = (unsigned int)t;
        c = t >> 32;
        t = (unsigned long)x1 * a + c;
        x1 = (unsigned int)t;
        c = t >> 32;
        t = (unsigned long)x2 * a + c;
        x2 = (unsigned int)t;
        c = t >> 32;
        t = (unsigned long)x3 * a + c;
        x3 = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && (x3 < xx3 || (x3 <= xx3 && (x2 < xx2 || (x2 <= xx2 && (x1 < xx1 || (x1 <= xx1 && x0 < xx0))))))))
            return 0;
    } while (x0 != xx0 || x1 != xx1 || x2 != xx2 || x3 != xx3 || c != cc);
    return p;
}


period

decompiled_code:
__int64 __fastcall period(unsigned __int16 a1, unsigned __int16 a2, unsigned __int64 a3, unsigned __int8 a4, __int64 a5)
{
char v6; // r8
__int64 result; // rax

v6 = 8 * a4;
switch ( a4 )
{
case 1u:
case 2u:
case 3u:
case 4u:
result = p32(a1, a2, a3, a5, v6);
break;
case 5u:
case 6u:
result = p56(a1, a2, a3, a5, v6);
break;
case 7u:
case 8u:
result = p64(a1, a2, a3, a5, v6);
break;
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
result = p96(a1, a2, a3, a5, v6);
break;
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
result = p128(a1, a2, a3, a5, v6);
break;
default:
fprintf(stderr, "unsupported r=%d.\n", a4);
exit(-1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int16 a1, unsigned __int16 a2, unsigned __int64 a3, unsigned __int8 a4, __int64 a5)
{
char v6; // r8
__int64 result; // rax

v6 = 8 * a4;
switch ( a4 )
{
case 1u:
case 2u:
case 3u:
case 4u:
result = func0(a1, a2, a3, a5, v6);
break;
case 5u:
case 6u:
result = func1(a1, a2, a3, a5, v6);
break;
case 7u:
case 8u:
result = func2(a1, a2, a3, a5, v6);
break;
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
result = func3(a1, a2, a3, a5, v6);
break;
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
result = func4(a1, a2, a3, a5, v6);
break;
default:
fprintf(stderr, "unsupported r=%d.\n", a4);
exit(-1);
}
return result;
}

original_code:
static uint64_t period(uint16_t a, uint16_t c, uint64_t x, uint8_t r, uint64_t b)
{
    int s = r * 8;
    switch (r)
    {
    case 1: case 2: case 3: case 4:
        return p32(a, c, x, b, s);
    case 5: case 6:
        return p56(a, c, x, b, s);
    case 7: case 8:
        return p64(a, c, x, b, s);
    case 9: case 10: case 11: case 12:
        return p96(a, c, x, b, s);
    case 13: case 14: case 15: case 16:
        return p128(a, c, x, b, s);
    }
    fprintf(stderr, "unsupported r=%d.\n", r);
    exit(-1);
    return 0;
}

canonical_original_code:
static unsigned long period(unsigned short a, unsigned short c, unsigned long x, unsigned char r, unsigned long b)
{
    int s = r * 8;
    switch (r)
    {
    case 1: case 2: case 3: case 4:
        return p32(a, c, x, b, s);
    case 5: case 6:
        return p56(a, c, x, b, s);
    case 7: case 8:
        return p64(a, c, x, b, s);
    case 9: case 10: case 11: case 12:
        return p96(a, c, x, b, s);
    case 13: case 14: case 15: case 16:
        return p128(a, c, x, b, s);
    }
    fprintf(stderr, "unsupported r=%d.\n", r);
    exit(-1);
    return 0;
}

variable_types:
r
unsigned char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r15
unsigned int v4; // er14
unsigned __int16 v5; // r13
__int64 v6; // r12
int v7; // eax
unsigned int *v9; // r15
__int64 v10; // rdx
int v11; // [rsp+Ch] [rbp-3Ch]

v3 = 0LL;
v4 = 0;
v5 = 0;
v6 = 0LL;
v11 = 0;
while ( 2 )
{
v7 = getopt(argc, (char *const *)argv, "w:n:u:a:r:qh");
if ( v7 != -1 )
{
switch ( v7 )
{
case 'a':
v5 = strtoul(optarg, 0LL, 0);
continue;
case 'h':
usage();
return 0;
case 'n':
v3 = (unsigned int)((_DWORD)&multiplier_table + 1056);
v6 = strtol(optarg, 0LL, 0);
continue;
case 'q':
v11 = 1;
continue;
case 'r':
v4 = (unsigned __int8)strtoul(optarg, 0LL, 0);
continue;
case 'u':
v3 = (unsigned int)((_DWORD)&multiplier_table + 1584);
v6 = strtol(optarg, 0LL, 0);
continue;
case 'w':
v3 = (unsigned int)((_DWORD)&multiplier_table + 528);
v6 = strtol(optarg, 0LL, 0);
continue;
default:
fwrite("Invalid argument.\n", 1uLL, 0x12uLL, stderr);
usage();
exit(1);
}
}
break;
}
if ( (unsigned __int8)(v4 - 1) > 0x1Fu )
{
fwrite("Out-of-range lag value.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( !v5 )
{
if ( !v3 )
{
fwrite("Must choose multiplier.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
v9 = (unsigned int *)(16LL * (unsigned __int8)v4 + v3);
v10 = *v9;
if ( v6 < 0 )
v6 += (int)v10;
if ( (unsigned int)v10 <= (unsigned int)v6 )
{
if ( (int)v10 <= 0 )
fprintf(stderr, "No known lag-%d multipliers.\n", v4);
else
fprintf(stderr, "Only %d known lag-%d multipliers.\n", v10, v4);
LABEL_23:
exit(1);
}
v5 = *(_WORD *)(*((_QWORD *)v9 + 1) + 4 * v6);
}
printf("b=256 a=0x%04x r=%d\n", v5, v4);
if ( v5 + 255 * (unsigned __int8)v5 > 0x10000 )
{
fwrite("This multiplier could overflow internal arithmetic.\n", 1uLL, 0x34uLL, stderr);
goto LABEL_23;
}
test_loop(v5, v4, v11);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r15
unsigned int v4; // er14
unsigned __int16 v5; // r13
__int64 v6; // r12
int v7; // eax
unsigned int *v9; // r15
__int64 v10; // rdx
int v11; // [rsp+Ch] [rbp-3Ch]

v3 = 0LL;
v4 = 0;
v5 = 0;
v6 = 0LL;
v11 = 0;
while ( 2 )
{
v7 = getopt(argc, (char *const *)argv, "w:n:u:a:r:qh");
if ( v7 != -1 )
{
switch ( v7 )
{
case 'a':
v5 = strtoul(optarg, 0LL, 0);
continue;
case 'h':
func6();
return 0;
case 'n':
v3 = (unsigned int)((_DWORD)&multiplier_table + 1056);
v6 = strtol(optarg, 0LL, 0);
continue;
case 'q':
v11 = 1;
continue;
case 'r':
v4 = (unsigned __int8)strtoul(optarg, 0LL, 0);
continue;
case 'u':
v3 = (unsigned int)((_DWORD)&multiplier_table + 1584);
v6 = strtol(optarg, 0LL, 0);
continue;
case 'w':
v3 = (unsigned int)((_DWORD)&multiplier_table + 528);
v6 = strtol(optarg, 0LL, 0);
continue;
default:
fwrite("Invalid argument.\n", 1uLL, 0x12uLL, stderr);
func6();
exit(1);
}
}
break;
}
if ( (unsigned __int8)(v4 - 1) > 0x1Fu )
{
fwrite("Out-of-range lag value.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( !v5 )
{
if ( !v3 )
{
fwrite("Must choose multiplier.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
v9 = (unsigned int *)(16LL * (unsigned __int8)v4 + v3);
v10 = *v9;
if ( v6 < 0 )
v6 += (int)v10;
if ( (unsigned int)v10 <= (unsigned int)v6 )
{
if ( (int)v10 <= 0 )
fprintf(stderr, "No known lag-%d multipliers.\n", v4);
else
fprintf(stderr, "Only %d known lag-%d multipliers.\n", v10, v4);
LABEL_23:
exit(1);
}
v5 = *(_WORD *)(*((_QWORD *)v9 + 1) + 4 * v6);
}
printf("b=256 a=0x%04x r=%d\n", v5, v4);
if ( v5 + 255 * (unsigned __int8)v5 > 0x10000 )
{
fwrite("This multiplier could overflow internal arithmetic.\n", 1uLL, 0x34uLL, stderr);
goto LABEL_23;
}
func7(v5, v4, v11);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    uint16_t a = 0;
    uint8_t r = 0;
    int quick = 0;
    tabptr_t const *table = ((void *)0);
    long tab_index = 0;
    uint8_t a_lo;
    int optc;
    while ((optc = getopt(argc, argv, "w:n:u:a:r:qh")) != -1)
        switch (optc)
        {
        case 'w':
            table = multiplier_table[WIDE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'n':
            table = multiplier_table[NARROW_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'u':
            table = multiplier_table[UNSAFE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'a':
            a = strtoul(optarg, ((void *)0), 0);
            break;
        case 'r':
            r = strtoul(optarg, ((void *)0), 0);
            break;
        case 'q': quick = 1;
            break;
        case 'h':
            usage();
            return 0;
        default:
            fprintf(stderr, "Invalid argument.\n");
            usage();
            exit(1);
        }
    if (r < 1 || r > 32)
    {
        fprintf(stderr, "Out-of-range lag value.\n");
        exit(1);
    }
    if (a == 0)
    {
        if (table == ((void *)0))
        {
            fprintf(stderr, "Must choose multiplier.\n");
            exit(1);
        }
        if (tab_index < 0)
            tab_index += table[r].len;
        if ((unsigned)tab_index >= table[r].len)
        {
            if (table[r].len > 0)
                fprintf(stderr, "Only %d known lag-%d multipliers.\n", table[r].len, r);
            else
                fprintf(stderr, "No known lag-%d multipliers.\n", r);
            exit(1);
        }
        a = table[r].tab[tab_index];
    }
    a_lo = a & 0xff;
    printf("b=256 a=0x%04x r=%d\n", a, r);
    if (255 * a_lo + a - 1 > 0xffff)
    {
        fprintf(stderr, "This multiplier could overflow internal arithmetic.\n");
        exit(1);
    }
    argc -= optind;
    argv += optind;
    test_loop(a, r, quick);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned short a = 0;
    unsigned char r = 0;
    int quick = 0;
    struct tabptr_t *table = ((void *)0);
    long tab_index = 0;
    unsigned char a_lo;
    int optc;
    while ((optc = getopt(argc, argv, "w:n:u:a:r:qh")) != -1)
        switch (optc)
        {
        case 'w':
            table = multiplier_table[WIDE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'n':
            table = multiplier_table[NARROW_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'u':
            table = multiplier_table[UNSAFE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'a':
            a = strtoul(optarg, ((void *)0), 0);
            break;
        case 'r':
            r = strtoul(optarg, ((void *)0), 0);
            break;
        case 'q': quick = 1;
            break;
        case 'h':
            usage();
            return 0;
        default:
            fprintf(stderr, "Invalid argument.\n");
            usage();
            exit(1);
        }
    if (r < 1 || r > 32)
    {
        fprintf(stderr, "Out-of-range lag value.\n");
        exit(1);
    }
    if (a == 0)
    {
        if (table == ((void *)0))
        {
            fprintf(stderr, "Must choose multiplier.\n");
            exit(1);
        }
        if (tab_index < 0)
            tab_index += table[r].len;
        if ((unsigned int)tab_index >= table[r].len)
        {
            if (table[r].len > 0)
                fprintf(stderr, "Only %d known lag-%d multipliers.\n", table[r].len, r);
            else
                fprintf(stderr, "No known lag-%d multipliers.\n", r);
            exit(1);
        }
        a = table[r].tab[tab_index];
    }
    a_lo = a & 0xff;
    printf("b=256 a=0x%04x r=%d\n", a, r);
    if (255 * a_lo + a - 1 > 0xffff)
    {
        fprintf(stderr, "This multiplier could overflow internal arithmetic.\n");
        exit(1);
    }
    argc -= optind;
    argv += optind;
    test_loop(a, r, quick);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: quick int

variable_types: struct tabptr_t { int len; unsigned int *tab; } *

variable_types: optc int

return_type: int


usage

decompiled_code:
int usage()
{
return puts(
"8bitrand -w <i> -r <r> wide multiply\n"
"8bitrand -n <i> -r <r> narrow multiply\n"
"8bitrand -u <i> -r <r> narrow multiply (unsafe primes)\n"
"8bitrand -a <a> -r <r> user-specified multiply\n"
"\t-{w|n|u} <i> index of known-good multiplier to use\n"
"\t-a <a> multiplier to use\n"
"\t-r <r> generator lag");
}

canonical_decompiled_code:
int func6()
{
return puts(
"8bitrand -w <i> -r <r> wide multiply\n"
"8bitrand -n <i> -r <r> narrow multiply\n"
"8bitrand -u <i> -r <r> narrow multiply (unsafe primes)\n"
"8bitrand -a <a> -r <r> user-specified multiply\n"
"\t-{w|n|u} <i> index of known-good multiplier to use\n"
"\t-a <a> multiplier to use\n"
"\t-r <r> generator lag");
}

original_code:
static void usage(void)
{
    printf("8bitrand -w <i> -r <r>  wide multiply\n"
           "8bitrand -n <i> -r <r>  narrow multiply\n"
           "8bitrand -u <i> -r <r>  narrow multiply (unsafe primes)\n"
           "8bitrand -a <a> -r <r>  user-specified multiply\n"
           "\t-{w|n|u} <i> index of known-good multiplier to use\n"
           "\t-a <a> multiplier to use\n"
           "\t-r <r> generator lag\n");
}

canonical_original_code:
static void usage()
{
    printf("8bitrand -w <i> -r <r>  wide multiply\n"
           "8bitrand -n <i> -r <r>  narrow multiply\n"
           "8bitrand -u <i> -r <r>  narrow multiply (unsafe primes)\n"
           "8bitrand -a <a> -r <r>  user-specified multiply\n"
           "\t-{w|n|u} <i> index of known-good multiplier to use\n"
           "\t-a <a> multiplier to use\n"
           "\t-r <r> generator lag\n");
}

return_type: void


original_code:
static void test_loop(uint16_t a, uint8_t r, int quick)
{
    int s = 8 * (r <= 6 ? r : 6);
    uint64_t b = (uint64_t)1 << s;
    uint64_t goal = ((uint64_t)a << s);
    uint64_t bail = goal + 1;
    uint64_t crappy = b;
    uint64_t ptot = 0;
    uint64_t pmin = 0xffffffffffffffff;
    uint64_t pmax = 0;
    uint64_t npmin = 0;
    uint64_t npmax = 0;
    uint64_t dups = 0;
    uint64_t np1 = 0;
    uint64_t loops = 0;
    uint64_t p;
    uint64_t x = 0;
    int stop = 0, overrun = 0;
    uint16_t c = 0;
    if (b <= 0x10000000)
        quick = 0;
    if (quick)
    {
        b = 0x10000000;
        goal = a * b;
        bail = b + 1;
        crappy = b;
    }
    if (period(a, a - 1, -1LL, r, 2) == 1)
        np1++, ptot++;
    for (c = 0; c < a; c++)
    {
        putchar('.');
        fflush(stdout);
        for (x = 0; x < b; x++)
        {
            p = period(a, c, x, r, bail);
            switch (p)
            {
            case 0:
                dups++;
                if (loops == 0)
                    stop = 1;
                break;
            case 1:
                np1++;
                if (np1 > 2)
                    stop = 1;
                break;
            default:
                if (p == bail && !quick)
                {
                    overrun = 1;
                    p = 0;
                    stop = 1;
                }
                else
                {
                    printf("x=0x%llx, c=0x%x, p%s%llu (0x%llx)\n", x, c, p == bail ? ">=" : "=", p, p);
                    loops++;
                    if (pmin > p) pmin = p, npmin = 0;
                    if (pmax < p) pmax = p, npmax = 0;
                    if (pmin == p) npmin++;
                    if (pmax == p) npmax++;
                    if (p <= crappy)
                        stop = 1;
                }
            }
            ptot += p;
            if (ptot >= goal)
                stop = 1;
            if (stop)
                break;
        }
        if (stop)
            break;
    }
    printf("\nStopped at x=0x%llx, c=0x%x\n", x, c);
    if (ptot >= goal)
        printf("Met coverage requirement (0x%llx >= 0x%llx)\n", ptot, goal);
    printf("a=0x%x, r=%d, %llux p=1, "
            "%llux pmin=%llu (0x%llx), "
            "%llux pmax=%llu (0x%llx) "
            "goal %s\n",
            a, r, np1,
            npmin, pmin, pmin,
            npmax, pmax, pmax,
            ptot >= goal ? "met" : "missed");
    printf("loops=%llu, dups=%llu\n", loops, dups);
    if (overrun > 0)
        printf("!!! Bailed out because test overran\n");
    if (dups != 0 && loops == 0)
        printf("!!! Bailed out for collapsing to zero\n");
    if (np1 > 2)
        printf("!!! Bailed out with too many p=1\n");
    if (pmin <= crappy)
        printf("!!! Bailed out because pmin=0x%llx is crappy\n", pmin);
}

canonical_original_code:
static void test_loop(unsigned short a, unsigned char r, int quick)
{
    int s = 8 * (r <= 6 ? r : 6);
    unsigned long b = (uint64_t)1 << s;
    unsigned long goal = ((uint64_t)a << s);
    unsigned long bail = goal + 1;
    unsigned long crappy = b;
    unsigned long ptot = 0;
    unsigned long pmin = 0xffffffffffffffff;
    unsigned long pmax = 0;
    unsigned long npmin = 0;
    unsigned long npmax = 0;
    unsigned long dups = 0;
    unsigned long np1 = 0;
    unsigned long loops = 0;
    unsigned long p;
    unsigned long x = 0;
    int stop = 0; int overrun = 0;
    unsigned short c = 0;
    if (b <= 0x10000000)
        quick = 0;
    if (quick)
    {
        b = 0x10000000;
        goal = a * b;
        bail = b + 1;
        crappy = b;
    }
    if (period(a, a - 1, -1LL, r, 2) == 1)
        np1++, ptot++;
    for (c = 0; c < a; c++)
    {
        putchar('.');
        fflush(stdout);
        for (x = 0; x < b; x++)
        {
            p = period(a, c, x, r, bail);
            switch (p)
            {
            case 0:
                dups++;
                if (loops == 0)
                    stop = 1;
                break;
            case 1:
                np1++;
                if (np1 > 2)
                    stop = 1;
                break;
            default:
                if (p == bail && !quick)
                {
                    overrun = 1;
                    p = 0;
                    stop = 1;
                }
                else
                {
                    printf("x=0x%llx, c=0x%x, p%s%llu (0x%llx)\n", x, c, p == bail ? ">=" : "=", p, p);
                    loops++;
                    if (pmin > p) pmin = p, npmin = 0;
                    if (pmax < p) pmax = p, npmax = 0;
                    if (pmin == p) npmin++;
                    if (pmax == p) npmax++;
                    if (p <= crappy)
                        stop = 1;
                }
            }
            ptot += p;
            if (ptot >= goal)
                stop = 1;
            if (stop)
                break;
        }
        if (stop)
            break;
    }
    printf("\nStopped at x=0x%llx, c=0x%x\n", x, c);
    if (ptot >= goal)
        printf("Met coverage requirement (0x%llx >= 0x%llx)\n", ptot, goal);
    printf("a=0x%x, r=%d, %llux p=1, "
            "%llux pmin=%llu (0x%llx), "
            "%llux pmax=%llu (0x%llx) "
            "goal %s\n",
            a, r, np1,
            npmin, pmin, pmin,
            npmax, pmax, pmax,
            ptot >= goal ? "met" : "missed");
    printf("loops=%llu, dups=%llu\n", loops, dups);
    if (overrun > 0)
        printf("!!! Bailed out because test overran\n");
    if (dups != 0 && loops == 0)
        printf("!!! Bailed out for collapsing to zero\n");
    if (np1 > 2)
        printf("!!! Bailed out with too many p=1\n");
    if (pmin <= crappy)
        printf("!!! Bailed out because pmin=0x%llx is crappy\n", pmin);
}

variable_types:
a
unsigned short

variable_types:
goal
unsigned long

variable_types:
bail
unsigned long

variable_types:
crappy
unsigned long

variable_types:
ptot
unsigned long

variable_types:
pmin
unsigned long

variable_types:
pmax
unsigned long

variable_types:
npmin
unsigned long

variable_types:
npmax
unsigned long

variable_types:
dups
unsigned long

variable_types:
loops
unsigned long

variable_types: stop int

variable_types: overrun int

variable_types:
c
unsigned short


getpasswd

repo: shaardie/onetimepad

decompiled_code:
__int64 __fastcall getpasswd(__int64 a1, const char *a2)
{
__m128i v2; // xmm0
__m128i v3; // xmm1
__m128i v4; // xmm2
struct termios v6; // [rsp+0h] [rbp-98h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-58h] BYREF

tcgetattr(0, &v6);
v2 = _mm_loadu_si128((const __m128i *)&v6);
v3 = _mm_loadu_si128((const __m128i *)&v6.c_line);
*(_QWORD *)&termios_p.c_cc[31] = *(_QWORD *)&v6.c_cc[31];
v4 = _mm_loadu_si128((const __m128i *)&v6.c_cc[15]);
*(__m128i *)&termios_p.c_iflag = v2;
*(__m128i *)&termios_p.c_line = v3;
termios_p.c_lflag = v2.m128i_i32[3] & 0xFFFFF387;
termios_p.c_ospeed = v6.c_ospeed;
*(__m128i *)&termios_p.c_cc[15] = v4;
tcsetattr(0, 0, &termios_p);
if ( a2 )
{
printf(a2);
_isoc99_scanf("%1023s", a1);
tcsetattr(0, 0, &v6);
putchar(10);
}
else
{
_isoc99_scanf("%1023s", a1);
tcsetattr(0, 0, &v6);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
__m128i v2; // xmm0
__m128i v3; // xmm1
__m128i v4; // xmm2
struct termios v6; // [rsp+0h] [rbp-98h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-58h] BYREF

tcgetattr(0, &v6);
v2 = _mm_loadu_si128((const __m128i *)&v6);
v3 = _mm_loadu_si128((const __m128i *)&v6.c_line);
*(_QWORD *)&termios_p.c_cc[31] = *(_QWORD *)&v6.c_cc[31];
v4 = _mm_loadu_si128((const __m128i *)&v6.c_cc[15]);
*(__m128i *)&termios_p.c_iflag = v2;
*(__m128i *)&termios_p.c_line = v3;
termios_p.c_lflag = v2.m128i_i32[3] & 0xFFFFF387;
termios_p.c_ospeed = v6.c_ospeed;
*(__m128i *)&termios_p.c_cc[15] = v4;
tcsetattr(0, 0, &termios_p);
if ( a2 )
{
printf(a2);
_isoc99_scanf("%1023s", a1);
tcsetattr(0, 0, &v6);
putchar(10);
}
else
{
_isoc99_scanf("%1023s", a1);
tcsetattr(0, 0, &v6);
}
return a1;
}

original_code:
char * getpasswd( char * passwd, char * msg ) {
 struct termios old_opts, new_opts;
 tcgetattr( 0, &old_opts );
 memcpy( &new_opts, &old_opts, sizeof( struct termios ) );
 new_opts.c_lflag &= ~( 0000010 | 0000020 | 0000040 | 0000100 | 0002000 | 0004000 );
 tcsetattr( 0, 0, &new_opts );
 if (msg)
  printf( msg );
 scanf( "%1023s", passwd );
 tcsetattr( 0, 0, &old_opts );
 if (msg)
  printf( "\n" );
 return passwd;
}

canonical_original_code:
char *getpasswd(char *passwd, char *msg) {
 struct termios old_opts; struct termios new_opts;
 tcgetattr( 0, &old_opts );
 memcpy( &new_opts, &old_opts, sizeof( struct termios ) );
 new_opts.c_lflag &= ~( 0000010 | 0000020 | 0000040 | 0000100 | 0002000 | 0004000 );
 tcsetattr( 0, 0, &new_opts );
 if (msg)
  printf( msg );
 scanf( "%1023s", passwd );
 tcsetattr( 0, 0, &old_opts );
 if (msg)
  printf( "\n" );
 return passwd;
}

variable_types:
passwd
char *

variable_types:
msg
char *

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

return_type: char *


getkey

decompiled_code:
void *__fastcall getkey(void **a1, _QWORD *a2, const char *a3)
{
size_t v4; // rax
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( !*a2 )
{
puts("Generating salt");
*a2 = gcry_random_bytes(8LL, 1LL);
}
*a1 = malloc(0x20uLL);
getpasswd((__int64)v6, a3);
v4 = strlen(v6);
gcry_kdf_derive(v6, v4, 19LL, 10LL, *a2, 8LL, 10LL, 32LL, *a1);
return *a1;
}

canonical_decompiled_code:
void *__fastcall func1(void **a1, _QWORD *a2, const char *a3)
{
size_t v4; // rax
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( !*a2 )
{
puts("Generating salt");
*a2 = gcry_random_bytes(8LL, 1LL);
}
*a1 = malloc(0x20uLL);
func0((__int64)v6, a3);
v4 = strlen(v6);
gcry_kdf_derive(v6, v4, 19LL, 10LL, *a2, 8LL, 10LL, 32LL, *a1);
return *a1;
}

original_code:
char * getkey(char ** key, void ** salt, char * msg) {
 char passphrase[1024];
 if (!*salt) {
  printf("Generating salt\n");
  *salt = gcry_random_bytes( 8, GCRY_STRONG_RANDOM );
 }
 *key = (char *) malloc(32 * sizeof(char));
 getpasswd( passphrase, msg );
 gcry_kdf_derive( passphrase, strlen(passphrase), GCRY_KDF_ITERSALTED_S2K,
   GCRY_MD_SHA512, *salt, 8, 10, 32, *key );
 return *key;
}

canonical_original_code:
char *getkey(char **key, void **salt, char *msg) {
 char passphrase[1024];
 if (!*salt) {
  printf("Generating salt\n");
  *salt = gcry_random_bytes( 8, GCRY_STRONG_RANDOM );
 }
 *key = (char *) malloc(32 * sizeof(char));
 getpasswd( passphrase, msg );
 gcry_kdf_derive( passphrase, strlen(passphrase), GCRY_KDF_ITERSALTED_S2K,
   GCRY_MD_SHA512, *salt, 8, 10, 32, *key );
 return *key;
}

variable_types:
key
char **

variable_types:
salt
void **

variable_types:
passphrase
char [1024]


decompiled_code:
__int64 iolib_init()
{
void *v0; // rax
__int64 v1; // rbx
__off_t v2; // r9
void *v3; // rax

if ( memh )
return 0xFFFFFFFFLL;
PortSet_ptr = (__int64)&p8_PortSet;
*(&PortSet_ptr + 1) = (__int64)&p9_PortSet;
PortIDSet_ptr = (__int64)&p8_PortIDSet;
*(&PortIDSet_ptr + 1) = (__int64)&p9_PortIDSet;
memh = open("/dev/mem", 2);
v0 = mmap(0LL, 0x4000uLL, 3, 1, memh, 1155530752LL);
cm_per_addr = (__int64)v0;
if ( v0 != (void *)-1LL )
{
v1 = 0LL;
v2 = 1155559424LL;
cm_wkup_addr = (__int64)v0 + 1024;
while ( 1 )
{
v3 = mmap(0LL, 0x1000uLL, 3, 1, memh, v2);
gpio_addr[v1] = (__int64)v3;
if ( v3 == (void *)-1LL )
break;
if ( ++v1 == 4 )
{
ctrl_addr = (__int64)mmap(0LL, 0x2000uLL, 3, 1, memh, 1155596288LL);
return (unsigned int)-(ctrl_addr == -1);
}
v2 = (unsigned int)GPIO_AddressOffset[v1];
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
void *v0; // rax
__int64 v1; // rbx
__off_t v2; // r9
void *v3; // rax

if ( memh )
return 0xFFFFFFFFLL;
PortSet_ptr = (__int64)&p8_PortSet;
*(&PortSet_ptr + 1) = (__int64)&p9_PortSet;
PortIDSet_ptr = (__int64)&p8_PortIDSet;
*(&PortIDSet_ptr + 1) = (__int64)&p9_PortIDSet;
memh = open("/dev/mem", 2);
v0 = mmap(0LL, 0x4000uLL, 3, 1, memh, 1155530752LL);
cm_per_addr = (__int64)v0;
if ( v0 != (void *)-1LL )
{
v1 = 0LL;
v2 = 1155559424LL;
cm_wkup_addr = (__int64)v0 + 1024;
while ( 1 )
{
v3 = mmap(0LL, 0x1000uLL, 3, 1, memh, v2);
gpio_addr[v1] = (__int64)v3;
if ( v3 == (void *)-1LL )
break;
if ( ++v1 == 4 )
{
ctrl_addr = (__int64)mmap(0LL, 0x2000uLL, 3, 1, memh, 1155596288LL);
return (unsigned int)-(ctrl_addr == -1);
}
v2 = (unsigned int)GPIO_AddressOffset[v1];
}
}
return 0xFFFFFFFFLL;
}

original_code:
int
iolib_init(void)
{
 int i;
 if (memh)
 {
     if (0) printf("iolib_init: memory already mapped?\n");
     return -1;
 }
 PortSet_ptr[0]=(char*)p8_PortSet;
 PortSet_ptr[1]=(char*)p9_PortSet;
 PortIDSet_ptr[0]=(unsigned int*)p8_PortIDSet;
 PortIDSet_ptr[1]=(unsigned int*)p9_PortIDSet;
 memh=open("/dev/mem", 02);
 cm_per_addr = mmap(0, 0x4000, 0x1 | 0x2, 0x01, memh, 0x44e00000);
 if(cm_per_addr == ((void *) -1))
     {
            if (0) printf("iolib_init: CM_PER mmap failure! ,error :%s\n" ,strerror((*__errno_location ())));
            return -1;
 }
 cm_wkup_addr =(void *)cm_per_addr + 0x400 ;
 for (i=0; i<4; i++)
 {
     gpio_addr[i] = mmap(0 ,0x1000 ,0x1 | 0x2 ,0x01 ,memh ,GPIO_AddressOffset[i]);
     if(gpio_addr[i] == ((void *) -1))
     {
  if (0) printf("iolib_init: gpio mmap failure!\n");
      return -1;
     }
 }
 ctrl_addr = mmap(0, 0x2000, 0x1 | 0x2, 0x01, memh, 0x44e10000);
 if(ctrl_addr == ((void *) -1))
 {
     if (0) printf("iolib_init: control module mmap failure!\n");
  return -1;
 }
 return 0;
}

canonical_original_code:
int iolib_init()
{
 int i;
 if (memh)
 {
     if (0) printf("iolib_init: memory already mapped?\n");
     return -1;
 }
 PortSet_ptr[0]=(char *)p8_PortSet;
 PortSet_ptr[1]=(char *)p9_PortSet;
 PortIDSet_ptr[0]=(unsigned int *)p8_PortIDSet;
 PortIDSet_ptr[1]=(unsigned int *)p9_PortIDSet;
 memh=open("/dev/mem", 02);
 cm_per_addr = mmap(0, 0x4000, 0x1 | 0x2, 0x01, memh, 0x44e00000);
 if(cm_per_addr == ((void *) -1))
     {
            if (0) printf("iolib_init: CM_PER mmap failure! ,error :%s\n" ,strerror((*__errno_location ())));
            return -1;
 }
 cm_wkup_addr =(void *)cm_per_addr + 0x400 ;
 for (i=0; i<4; i++)
 {
     gpio_addr[i] = mmap(0 ,0x1000 ,0x1 | 0x2 ,0x01 ,memh ,GPIO_AddressOffset[i]);
     if(gpio_addr[i] == ((void *) -1))
     {
  if (0) printf("iolib_init: gpio mmap failure!\n");
      return -1;
     }
 }
 ctrl_addr = mmap(0, 0x2000, 0x1 | 0x2, 0x01, memh, 0x44e10000);
 if(ctrl_addr == ((void *) -1))
 {
     if (0) printf("iolib_init: control module mmap failure!\n");
  return -1;
 }
 return 0;
}

variable_types: i int


decompiled_code:
__int64 iolib_free()
{
if ( memh )
close(memh);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
if ( memh )
close(memh);
return 0LL;
}

original_code:
int
iolib_free(void)
{
 if (memh!=0)
 {
  close(memh);
 }
 return(0);
}

canonical_original_code:
int iolib_free()
{
 if (memh!=0)
 {
  close(memh);
 }
 return(0);
}


decompiled_code:
__int64 __fastcall iolib_setdir(char a1, char a2, char a3)
{
unsigned int v3; // er8
int v4; // eax
__int64 result; // rax
__int64 v6; // rcx
int v7; // edx

v3 = -1;
v4 = a1 - 8;
if ( (unsigned __int8)(a1 - 8) > 1u || (unsigned __int8)(a2 - 1) > 0x2Du )
return v3;
if ( *(char *)(PortSet_ptr[a1] + a2) < 0 || !memh )
return (unsigned int)-1;
v6 = gpio_addr[*(char *)(PortSet_ptr[v4] + a2 - 1)];
if ( a3 != 1 )
{
v3 = 0;
if ( !a3 )
{
v7 = *(_DWORD *)(PortIDSet_ptr[v4] + 4LL * a2 - 4) | *(_DWORD *)(v6 + 308);
result = 0LL;
*(_DWORD *)(v6 + 308) = v7;
return result;
}
return v3;
}
*(_DWORD *)(v6 + 308) &= ~*(_DWORD *)(PortIDSet_ptr[v4] + 4LL * a2 - 4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1, char a2, char a3)
{
unsigned int v3; // er8
int v4; // eax
__int64 result; // rax
__int64 v6; // rcx
int v7; // edx

v3 = -1;
v4 = a1 - 8;
if ( (unsigned __int8)(a1 - 8) > 1u || (unsigned __int8)(a2 - 1) > 0x2Du )
return v3;
if ( *(char *)(PortSet_ptr[a1] + a2) < 0 || !memh )
return (unsigned int)-1;
v6 = gpio_addr[*(char *)(PortSet_ptr[v4] + a2 - 1)];
if ( a3 != 1 )
{
v3 = 0;
if ( !a3 )
{
v7 = *(_DWORD *)(PortIDSet_ptr[v4] + 4LL * a2 - 4) | *(_DWORD *)(v6 + 308);
result = 0LL;
*(_DWORD *)(v6 + 308) = v7;
return result;
}
return v3;
}
*(_DWORD *)(v6 + 308) &= ~*(_DWORD *)(PortIDSet_ptr[v4] + 4LL * a2 - 4);
return 0LL;
}

original_code:
int
iolib_setdir(char port, char pin, char dir)
{
 int i;
 int param_error=0;
 volatile unsigned int* reg;
 int reg_port = port -8;
 int reg_pin = pin -1;
 if (memh==0)
  param_error=1;
 if ((port<8) || (port>9))
  param_error=1;
 if ((pin<1) || (pin>46))
  param_error=1;
 if (PortSet_ptr[port][pin]<0)
  param_error=1;
 if (param_error)
 {
  if (0) printf("iolib_setdir: parameter error!\n");
  return(-1);
 }
 if (0)
  printf("iolib_setdir: PortSet_ptr P%d.%d , %X\n",port ,pin , PortSet_ptr[port-8][pin-1]);
 reg=(void*)gpio_addr[PortSet_ptr[port-8][pin-1]] +0x134;
 if (dir ==1)
 {
  *reg &= ~(PortIDSet_ptr[port-8][pin-1]);
 }
 else if (dir ==0)
 {
  *reg |= PortIDSet_ptr[port-8][pin-1];
 }
 return(0);
}

canonical_original_code:
int iolib_setdir(char port, char pin, char dir)
{
 int i;
 int param_error = 0;
 unsigned int *reg;
 int reg_port = port -8;
 int reg_pin = pin -1;
 if (memh==0)
  param_error=1;
 if ((port<8) || (port>9))
  param_error=1;
 if ((pin<1) || (pin>46))
  param_error=1;
 if (PortSet_ptr[port][pin]<0)
  param_error=1;
 if (param_error)
 {
  if (0) printf("iolib_setdir: parameter error!\n");
  return(-1);
 }
 if (0)
  printf("iolib_setdir: PortSet_ptr P%d.%d , %X\n",port ,pin , PortSet_ptr[port-8][pin-1]);
 reg=(void *)gpio_addr[PortSet_ptr[port-8][pin-1]] +0x134;
 if (dir ==1)
 {
  *reg &= ~(PortIDSet_ptr[port-8][pin-1]);
 }
 else if (dir ==0)
 {
  *reg |= PortIDSet_ptr[port-8][pin-1];
 }
 return(0);
}

variable_types: port char

variable_types: pin char

variable_types: dir char

variable_types:
reg
unsigned int *


decompiled_code:
__int64 __fastcall iolib_delay_ms(int a1)
{
__syscall_slong_t v1; // rax
int *v3; // rax
unsigned int v4; // eax
struct timespec v5; // [rsp+0h] [rbp-18h] BYREF

if ( (unsigned int)a1 > 0x3E7 )
{
fwrite("delay_ms error: delay value needs to be less than 999\n", 1uLL, 0x36uLL, stderr);
v1 = 999000000LL;
}
else
{
v1 = (unsigned int)(int)((double)a1 * 1000000.0);
}
v5.tv_nsec = v1;
v5.tv_sec = 0LL;
if ( nanosleep(&v5, 0LL) )
{
v3 = _errno_location();
v4 = (unsigned int)strerror(*v3);
fprintf(stderr, "delay_ms error: %s\n", (const char *)v4);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__syscall_slong_t v1; // rax
int *v3; // rax
unsigned int v4; // eax
struct timespec v5; // [rsp+0h] [rbp-18h] BYREF

if ( (unsigned int)a1 > 0x3E7 )
{
fwrite("delay_ms error: delay value needs to be less than 999\n", 1uLL, 0x36uLL, stderr);
v1 = 999000000LL;
}
else
{
v1 = (unsigned int)(int)((double)a1 * 1000000.0);
}
v5.tv_nsec = v1;
v5.tv_sec = 0LL;
if ( nanosleep(&v5, 0LL) )
{
v3 = _errno_location();
v4 = (unsigned int)strerror(*v3);
fprintf(stderr, "delay_ms error: %s\n", (const char *)v4);
}
return 0LL;
}

original_code:
int
iolib_delay_ms(unsigned int msec)
{
 int ret;
 struct timespec a;
 if (msec>999)
 {
  fprintf(stderr, "delay_ms error: delay value needs to be less than 999\n");
  msec=999;
 }
 a.tv_nsec=((long)(msec))*1E6d;
 a.tv_sec=0;
 if ((ret = nanosleep(&a, ((void *)0))) != 0)
 {
  fprintf(stderr, "delay_ms error: %s\n", strerror((*__errno_location ())));
 }
 return(0);
}

variable_types:
msec
unsigned int

variable_types: ret int

variable_types: struct timespec { long tv_sec; long tv_nsec; }


original_code:
void
BBBIO_sys_GPIO_CLK_status()
{
 volatile unsigned int* reg ;
 unsigned int reg_value =0;
 const char s_GDBLCK[][9]={"FCLK_DIS" ,"FCLK_EN"};
 const char s_IDLEST[][8]={"Func" ,"Trans" ,"Idle" ,"Disable"};
 const char s_MODULEMODE[][8]={"Disable" ,"Reserve" ,"Enable" ,"Reserve"};
 int v_GDBLCK ;
 int v_IDLEST ;
 int v_MODULEMODE ;
 printf("\n******************************************************\n");
 printf("************ GPIO Clock module Information ***********\n");
 printf("******************************************************\n");
 reg =(void*)cm_per_addr + 0x0;
 reg_value = *reg ;
 printf("CM_PER CM_PER_L4LS_CLKSTCTRL : %X\n\n", reg_value );
 reg =(void*)cm_wkup_addr + 0x8 ;
        reg_value = *reg ;
 v_GDBLCK = (reg_value >>18) & 0x01 ;
 v_IDLEST = (reg_value >>16) & 0x02 ;
 v_MODULEMODE = reg_value & 0x02 ;
        printf("CM_WKUP CM_WKUP_GPIO0_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_0_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
 reg =(void*)cm_per_addr + 0xAC;
 reg_value = *reg ;
        v_GDBLCK = (reg_value >>18) & 0x01 ;
        v_IDLEST = (reg_value >>16) & 0x02 ;
        v_MODULEMODE = reg_value & 0x02 ;
 printf("CM_PER CM_PER_GPIO1_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_1_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
 reg =(void*)cm_per_addr + 0xB0;
 reg_value = *reg ;
        v_GDBLCK = (reg_value >>18) & 0x01 ;
        v_IDLEST = (reg_value >>16) & 0x02 ;
        v_MODULEMODE = reg_value & 0x02 ;
 printf("CM_PER CM_PER_GPIO2_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_2_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
 reg =(void*)cm_per_addr + 0xB4;
 reg_value = *reg ;
        v_GDBLCK = (reg_value >>18) & 0x01 ;
        v_IDLEST = (reg_value >>16) & 0x02 ;
        v_MODULEMODE = reg_value & 0x02 ;
 printf("CM_PER CM_PER_GPIO3_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_0_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
}

canonical_original_code:
void BBBIO_sys_GPIO_CLK_status()
{
 unsigned int *reg;
 unsigned int reg_value = 0;
 char s_GDBLCK[][9] = {"FCLK_DIS" ,"FCLK_EN"};
 char s_IDLEST[][8] = {"Func" ,"Trans" ,"Idle" ,"Disable"};
 char s_MODULEMODE[][8] = {"Disable" ,"Reserve" ,"Enable" ,"Reserve"};
 int v_GDBLCK;
 int v_IDLEST;
 int v_MODULEMODE;
 printf("\n******************************************************\n");
 printf("************ GPIO Clock module Information ***********\n");
 printf("******************************************************\n");
 reg =(void *)cm_per_addr + 0x0;
 reg_value = *reg ;
 printf("CM_PER CM_PER_L4LS_CLKSTCTRL : %X\n\n", reg_value );
 reg =(void *)cm_wkup_addr + 0x8 ;
        reg_value = *reg ;
 v_GDBLCK = (reg_value >>18) & 0x01 ;
 v_IDLEST = (reg_value >>16) & 0x02 ;
 v_MODULEMODE = reg_value & 0x02 ;
        printf("CM_WKUP CM_WKUP_GPIO0_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_0_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
 reg =(void *)cm_per_addr + 0xAC;
 reg_value = *reg ;
        v_GDBLCK = (reg_value >>18) & 0x01 ;
        v_IDLEST = (reg_value >>16) & 0x02 ;
        v_MODULEMODE = reg_value & 0x02 ;
 printf("CM_PER CM_PER_GPIO1_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_1_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
 reg =(void *)cm_per_addr + 0xB0;
 reg_value = *reg ;
        v_GDBLCK = (reg_value >>18) & 0x01 ;
        v_IDLEST = (reg_value >>16) & 0x02 ;
        v_MODULEMODE = reg_value & 0x02 ;
 printf("CM_PER CM_PER_GPIO2_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_2_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
 reg =(void *)cm_per_addr + 0xB4;
 reg_value = *reg ;
        v_GDBLCK = (reg_value >>18) & 0x01 ;
        v_IDLEST = (reg_value >>16) & 0x02 ;
        v_MODULEMODE = reg_value & 0x02 ;
 printf("CM_PER CM_PER_GPIO3_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_0_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
}


original_code:
void
BBBIO_sys_Expansion_Header_status(unsigned int port)
{
        volatile unsigned int* reg ;
        unsigned int reg_value =0;
 int i ;
 const char extra_status[][12]={ "GND" ,"DC_33V" ,"CDD_5V" ,"SYS_5V" ,"PWR_BUT" ,
            "SYS_RESET" ,"VADC" ,"AIN4" ,"AGND" ,"AIN6" ,"AIN5" ,
            "AIN2" ,"AIN3" ,"AIN0" ,"AIN1" ,"Unknow"};
 const char s_SLEWCTRL[2][5] ={"Fast" ,"Slow"} ;
 const char s_EXACTIVE[2][8] ={"Disable" ,"Enable"} ;
 const char s_PULLTYPESEL[2][9]={"Pulldown" ,"Pullup"};
 const char s_PULLUPEN[2][8] ={"Enable" ,"Disable"} ;
 int v_SLEWCTRL ;
 int v_EXACTIVE ;
 int v_PULLTYPESEL ;
 int v_PULLUPEN ;
 int v_MODE ;
 if ((port<8) || (port>9))
 {
     printf("Expansion_Header only have P8 and P9 ,please check your input port :%d\n",port);
            return ;
 }
 port -=8 ;
        printf("\n******************************************************\n");
        printf("************ Expansion Header Information ************\n");
        printf("******************************************************\n");
 for(i=0 ;i< 46 ; i++)
  {
     if(ExpHeader_MODE0[port][i] &0xF0000000)
     {
  printf("P%d_%2d : \t%s\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t| P%d_%2d\n" ,port+8 ,i+1 ,
       &extra_status[ExpHeader_MODE0[port][i] &0x0f][0] ,
       port+8 ,i+1);
     }
     else
     {
      reg =(void*)ctrl_addr + ExpHeader_MODE0[port][i] ;
             reg_value = *reg ;
  v_SLEWCTRL = reg_value>>6 ;
  v_EXACTIVE = reg_value >>5 &0x01;
  v_PULLTYPESEL = reg_value >>4 & 0x01;
  v_PULLUPEN = reg_value >>3 & 0x01;
  v_MODE =reg_value &0x07;
  printf("P%d_%2d : \tSLEWCTRL %d (%s) \t,RXACTIVE %d (%s)\t,PULLTYPESEL %d (%s) \t,PULLDEN %d (%s) \t,MUXMODE : %d \t| P%d_%2d \n" ,
    port+8 ,i+1 ,
    v_SLEWCTRL ,s_SLEWCTRL[v_SLEWCTRL] ,
    v_EXACTIVE ,s_EXACTIVE[v_EXACTIVE] ,
    v_PULLTYPESEL ,s_PULLTYPESEL[v_PULLTYPESEL] ,
    v_PULLUPEN ,s_PULLUPEN[v_PULLUPEN] ,
    v_MODE ,
    port+8 ,i+1);
     }
 }
}

canonical_original_code:
void BBBIO_sys_Expansion_Header_status(unsigned int port)
{
        unsigned int *reg;
        unsigned int reg_value = 0;
 int i;
 char extra_status[][12] = { "GND" ,"DC_33V" ,"CDD_5V" ,"SYS_5V" ,"PWR_BUT" ,
            "SYS_RESET" ,"VADC" ,"AIN4" ,"AGND" ,"AIN6" ,"AIN5" ,
            "AIN2" ,"AIN3" ,"AIN0" ,"AIN1" ,"Unknow"};
 char s_SLEWCTRL[2][5] = {"Fast" ,"Slow"};
 char s_EXACTIVE[2][8] = {"Disable" ,"Enable"};
 char s_PULLTYPESEL[2][9] = {"Pulldown" ,"Pullup"};
 char s_PULLUPEN[2][8] = {"Enable" ,"Disable"};
 int v_SLEWCTRL;
 int v_EXACTIVE;
 int v_PULLTYPESEL;
 int v_PULLUPEN;
 int v_MODE;
 if ((port<8) || (port>9))
 {
     printf("Expansion_Header only have P8 and P9 ,please check your input port :%d\n",port);
            return ;
 }
 port -=8 ;
        printf("\n******************************************************\n");
        printf("************ Expansion Header Information ************\n");
        printf("******************************************************\n");
 for(i=0 ;i< 46 ; i++)
  {
     if(ExpHeader_MODE0[port][i] &0xF0000000)
     {
  printf("P%d_%2d : \t%s\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t| P%d_%2d\n" ,port+8 ,i+1 ,
       &extra_status[ExpHeader_MODE0[port][i] &0x0f][0] ,
       port+8 ,i+1);
     }
     else
     {
      reg =(void *)ctrl_addr + ExpHeader_MODE0[port][i] ;
             reg_value = *reg ;
  v_SLEWCTRL = reg_value>>6 ;
  v_EXACTIVE = reg_value >>5 &0x01;
  v_PULLTYPESEL = reg_value >>4 & 0x01;
  v_PULLUPEN = reg_value >>3 & 0x01;
  v_MODE =reg_value &0x07;
  printf("P%d_%2d : \tSLEWCTRL %d (%s) \t,RXACTIVE %d (%s)\t,PULLTYPESEL %d (%s) \t,PULLDEN %d (%s) \t,MUXMODE : %d \t| P%d_%2d \n" ,
    port+8 ,i+1 ,
    v_SLEWCTRL ,s_SLEWCTRL[v_SLEWCTRL] ,
    v_EXACTIVE ,s_EXACTIVE[v_EXACTIVE] ,
    v_PULLTYPESEL ,s_PULLTYPESEL[v_PULLTYPESEL] ,
    v_PULLUPEN ,s_PULLUPEN[v_PULLUPEN] ,
    v_MODE ,
    port+8 ,i+1);
     }
 }
}

variable_types:
port
unsigned int


decompiled_code:
__int64 __fastcall BBBIO_sys_Enable_Debouncing(int a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rdx
__int64 result; // rax
__int64 v6; // rcx
_BYTE *v7; // rsi
__int64 v8; // rdi
_DWORD *v9; // rax
__int64 v10; // [rsp+0h] [rbp-Ch]
int v11; // [rsp+8h] [rbp-4h]

v4 = (unsigned int)(a1 - 8);
v11 = 180;
v10 = 0xB0000000ACLL;
result = 0xFFFFFFFFLL;
if ( (unsigned int)v4 <= 1 )
{
v6 = a2 - 1;
if ( (unsigned int)v6 <= 0x2D )
{
if ( a3 > 0xFF || memh == 0 || *(char *)(PortSet_ptr[a1] + a2) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v7 = (_BYTE *)(v6 + PortSet_ptr[v4]);
if ( *v7 )
{
v9 = (_DWORD *)(cm_per_addr + *((unsigned int *)&v10 + (char)*v7 - 1));
*v9 |= 0x40000u;
}
else
{
*(_DWORD *)(cm_wkup_addr + 8) |= 0x40000u;
}
v8 = gpio_addr[(char)*v7];
*(_DWORD *)(v8 + 336) |= *(_DWORD *)(PortIDSet_ptr[v4] + 4 * v6);
*(_DWORD *)(gpio_addr[(char)*v7] + 340) = a3;
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rdx
__int64 result; // rax
__int64 v6; // rcx
_BYTE *v7; // rsi
__int64 v8; // rdi
_DWORD *v9; // rax
__int64 v10; // [rsp+0h] [rbp-Ch]
int v11; // [rsp+8h] [rbp-4h]

v4 = (unsigned int)(a1 - 8);
v11 = 180;
v10 = 0xB0000000ACLL;
result = 0xFFFFFFFFLL;
if ( (unsigned int)v4 <= 1 )
{
v6 = a2 - 1;
if ( (unsigned int)v6 <= 0x2D )
{
if ( a3 > 0xFF || memh == 0 || *(char *)(PortSet_ptr[a1] + a2) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v7 = (_BYTE *)(v6 + PortSet_ptr[v4]);
if ( *v7 )
{
v9 = (_DWORD *)(cm_per_addr + *((unsigned int *)&v10 + (char)*v7 - 1));
*v9 |= 0x40000u;
}
else
{
*(_DWORD *)(cm_wkup_addr + 8) |= 0x40000u;
}
v8 = gpio_addr[(char)*v7];
*(_DWORD *)(v8 + 336) |= *(_DWORD *)(PortIDSet_ptr[v4] + 4 * v6);
*(_DWORD *)(gpio_addr[(char)*v7] + 340) = a3;
result = 0LL;
}
}
}
return result;
}

original_code:
int BBBIO_sys_Enable_Debouncing(unsigned int port ,unsigned int pin ,unsigned int GDB_time)
{
 volatile unsigned int* reg;
 int param_error=0;
 const unsigned int GPIO_CLKCTRL[] ={0xAC ,
         0xB0 ,
         0xB4};
        if (memh==0)
            param_error=1;
        if ((port<8) || (port>9))
            param_error=1;
        if ((pin<1) || (pin>46))
            param_error=1;
        if (PortSet_ptr[port][pin]<0)
            param_error=1;
 if(GDB_time <0 || GDB_time >255)
     param_error=1;
        if (param_error)
        {
            if (0) printf("BBBIO_sys_Enable_Debouncing : parameter error!\n");
            return -1 ;
 }
 port -=8 ;
 pin -=1 ;
 if(PortSet_ptr[port][pin]==0)
 {
     reg =(void*)cm_wkup_addr + 0x8;
            *reg |= 1 <<18;
 }
 else
 {
     reg =(void*)cm_per_addr + GPIO_CLKCTRL[PortSet_ptr[port][pin]-1] ;
     *reg |= 1 <<18;
 }
        reg = (void*)gpio_addr[PortSet_ptr[port][pin]] +0x150 ;
 *reg |= PortIDSet_ptr[port][pin] ;
 reg = (void*)gpio_addr[PortSet_ptr[port][pin]] +0x154 ;
 *reg = GDB_time ;
 return 0;
}

canonical_original_code:
int BBBIO_sys_Enable_Debouncing(unsigned int port, unsigned int pin, unsigned int GDB_time)
{
 unsigned int *reg;
 int param_error = 0;
 unsigned int GPIO_CLKCTRL[] = {0xAC ,
         0xB0 ,
         0xB4};
        if (memh==0)
            param_error=1;
        if ((port<8) || (port>9))
            param_error=1;
        if ((pin<1) || (pin>46))
            param_error=1;
        if (PortSet_ptr[port][pin]<0)
            param_error=1;
 if(GDB_time <0 || GDB_time >255)
     param_error=1;
        if (param_error)
        {
            if (0) printf("BBBIO_sys_Enable_Debouncing : parameter error!\n");
            return -1 ;
 }
 port -=8 ;
 pin -=1 ;
 if(PortSet_ptr[port][pin]==0)
 {
     reg =(void *)cm_wkup_addr + 0x8;
            *reg |= 1 <<18;
 }
 else
 {
     reg =(void *)cm_per_addr + GPIO_CLKCTRL[PortSet_ptr[port][pin]-1] ;
     *reg |= 1 <<18;
 }
        reg = (void *)gpio_addr[PortSet_ptr[port][pin]] +0x150 ;
 *reg |= PortIDSet_ptr[port][pin] ;
 reg = (void *)gpio_addr[PortSet_ptr[port][pin]] +0x154 ;
 *reg = GDB_time ;
 return 0;
}

variable_types:
pin
unsigned int


decompiled_code:
__int64 __fastcall BBBIO_sys_Disable_Debouncing(int a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // eax
__int64 result; // rax
__int64 v6; // rcx
__int64 v7; // rdx
_BYTE *v8; // rdi
__int64 v9; // rsi
_DWORD *v10; // rax
__int64 v11; // [rsp+0h] [rbp-Ch]
int v12; // [rsp+8h] [rbp-4h]

v12 = 180;
v11 = 0xB0000000ACLL;
v4 = a1 - 8;
if ( (unsigned int)(a1 - 8) > 1 )
return 0xFFFFFFFFLL;
v6 = a2 - 1;
if ( (unsigned int)v6 > 0x2D || a3 > 0xFF || memh == 0 || *(char *)(PortSet_ptr[a1] + a2) < 0 )
return 0xFFFFFFFFLL;
v7 = v4;
v8 = (_BYTE *)(v6 + PortSet_ptr[v4]);
if ( *v8 )
{
v10 = (_DWORD *)(cm_per_addr + *((unsigned int *)&v11 + (char)*v8 - 1));
*v10 &= 0xFFF80000;
}
else
{
*(_DWORD *)(cm_wkup_addr + 8) &= 0xFFF80000;
}
v9 = gpio_addr[(char)*v8];
*(_DWORD *)(v9 + 336) &= ~*(_DWORD *)(PortIDSet_ptr[v7] + 4 * v6);
result = gpio_addr[(char)*v8];
*(_DWORD *)(result + 340) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // eax
__int64 result; // rax
__int64 v6; // rcx
__int64 v7; // rdx
_BYTE *v8; // rdi
__int64 v9; // rsi
_DWORD *v10; // rax
__int64 v11; // [rsp+0h] [rbp-Ch]
int v12; // [rsp+8h] [rbp-4h]

v12 = 180;
v11 = 0xB0000000ACLL;
v4 = a1 - 8;
if ( (unsigned int)(a1 - 8) > 1 )
return 0xFFFFFFFFLL;
v6 = a2 - 1;
if ( (unsigned int)v6 > 0x2D || a3 > 0xFF || memh == 0 || *(char *)(PortSet_ptr[a1] + a2) < 0 )
return 0xFFFFFFFFLL;
v7 = v4;
v8 = (_BYTE *)(v6 + PortSet_ptr[v4]);
if ( *v8 )
{
v10 = (_DWORD *)(cm_per_addr + *((unsigned int *)&v11 + (char)*v8 - 1));
*v10 &= 0xFFF80000;
}
else
{
*(_DWORD *)(cm_wkup_addr + 8) &= 0xFFF80000;
}
v9 = gpio_addr[(char)*v8];
*(_DWORD *)(v9 + 336) &= ~*(_DWORD *)(PortIDSet_ptr[v7] + 4 * v6);
result = gpio_addr[(char)*v8];
*(_DWORD *)(result + 340) = a3;
return result;
}

original_code:
int BBBIO_sys_Disable_Debouncing(unsigned int port ,unsigned int pin ,unsigned int GDB_time)
{
        volatile unsigned int* reg;
        int param_error=0;
        const unsigned int GPIO_CLKCTRL[] ={0xAC ,
                                            0xB0 ,
                                            0xB4};
        if (memh==0)
            param_error=1;
        if ((port<8) || (port>9))
            param_error=1;
        if ((pin<1) || (pin>46))
            param_error=1;
        if (PortSet_ptr[port][pin]<0)
            param_error=1;
        if(GDB_time <0 || GDB_time >255)
            param_error=1;
        if (param_error)
        {
            if (0) printf("BBBIO_sys_Disable_Debouncing : parameter error!\n");
            return -1 ;
        }
        port -=8 ;
        pin -=1 ;
        if(PortSet_ptr[port][pin]==0)
        {
            reg =(void*)cm_wkup_addr + 0x8;
            *reg &= ~1 <<18;
        }
        else
        {
            reg =(void*)cm_per_addr + GPIO_CLKCTRL[PortSet_ptr[port][pin]-1] ;
            *reg &= ~1 <<18;
        }
        reg = (void*)gpio_addr[PortSet_ptr[port][pin]] +0x150 ;
        *reg &= ~PortIDSet_ptr[port][pin] ;
       reg = (void *)gpio_addr[PortSet_ptr[port][pin]] +0x154 ;
       *reg = GDB_time ;
}

canonical_original_code:
int BBBIO_sys_Disable_Debouncing(unsigned int port, unsigned int pin, unsigned int GDB_time)
{
        unsigned int *reg;
        int param_error = 0;
        unsigned int GPIO_CLKCTRL[] = {0xAC ,
                                            0xB0 ,
                                            0xB4};
        if (memh==0)
            param_error=1;
        if ((port<8) || (port>9))
            param_error=1;
        if ((pin<1) || (pin>46))
            param_error=1;
        if (PortSet_ptr[port][pin]<0)
            param_error=1;
        if(GDB_time <0 || GDB_time >255)
            param_error=1;
        if (param_error)
        {
            if (0) printf("BBBIO_sys_Disable_Debouncing : parameter error!\n");
            return -1 ;
        }
        port -=8 ;
        pin -=1 ;
        if(PortSet_ptr[port][pin]==0)
        {
            reg =(void *)cm_wkup_addr + 0x8;
            *reg &= ~1 <<18;
        }
        else
        {
            reg =(void *)cm_per_addr + GPIO_CLKCTRL[PortSet_ptr[port][pin]-1] ;
            *reg &= ~1 <<18;
        }
        reg = (void *)gpio_addr[PortSet_ptr[port][pin]] +0x150 ;
        *reg &= ~PortIDSet_ptr[port][pin] ;
       reg = (void *)gpio_addr[PortSet_ptr[port][pin]] +0x154 ;
       *reg = GDB_time ;
}


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

if ( !cm_per_addr || a1 > 3 )
return 0LL;
if ( a1 == 2 )
{
*(_DWORD *)(cm_per_addr + 176) |= 2u;
result = 1LL;
}
else if ( a1 == 3 )
{
*(_DWORD *)(cm_per_addr + 180) |= 2u;
result = 1LL;
}
else
{
if ( a1 == 1 )
*(_DWORD *)(cm_per_addr + 172) |= 2u;
else
*(_DWORD *)(cm_wkup_addr + 8) |= 2u;
result = 1LL;
}
return result;
}

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

if ( !cm_per_addr || a1 > 3 )
return 0LL;
if ( a1 == 2 )
{
*(_DWORD *)(cm_per_addr + 176) |= 2u;
result = 1LL;
}
else if ( a1 == 3 )
{
*(_DWORD *)(cm_per_addr + 180) |= 2u;
result = 1LL;
}
else
{
if ( a1 == 1 )
*(_DWORD *)(cm_per_addr + 172) |= 2u;
else
*(_DWORD *)(cm_wkup_addr + 8) |= 2u;
result = 1LL;
}
return result;
}

original_code:
int BBBIO_sys_Enable_GPIO(unsigned int gpio)
{
 int param_error=0;
 volatile unsigned int* reg;
 if (cm_per_addr==0)
  param_error=1;
 if (gpio <0 || gpio >3)
  param_error=1;
 if (param_error)
 {
  if (0) printf("BBBIO_sys_Enable_GPIO: parameter error!\n");
  return 0;
 }
 switch(gpio)
 {
  case 0 :
  {
   reg =(void*)cm_wkup_addr + 0x8;
   *reg |= 0x2 ;
  }
  break ;
  case 1 :
  {
   reg =(void*)cm_per_addr + 0xAC;
   *reg |= 0x2 ;
  }
  break ;
  case 2 :
  {
   reg =(void*)cm_per_addr + 0xB0;
   *reg |= 0x2 ;
  }
  break ;
  case 3 :
  {
   reg =(void*)cm_per_addr + 0xB4;
   *reg |= 0x2 ;
  }
  break ;
  default :
  {
   return 0 ;
  }
  break ;
 }
 return 1 ;
}

canonical_original_code:
int BBBIO_sys_Enable_GPIO(unsigned int gpio)
{
 int param_error = 0;
 unsigned int *reg;
 if (cm_per_addr==0)
  param_error=1;
 if (gpio <0 || gpio >3)
  param_error=1;
 if (param_error)
 {
  if (0) printf("BBBIO_sys_Enable_GPIO: parameter error!\n");
  return 0;
 }
 switch(gpio)
 {
  case 0 :
  {
   reg =(void *)cm_wkup_addr + 0x8;
   *reg |= 0x2 ;
  }
  break ;
  case 1 :
  {
   reg =(void *)cm_per_addr + 0xAC;
   *reg |= 0x2 ;
  }
  break ;
  case 2 :
  {
   reg =(void *)cm_per_addr + 0xB0;
   *reg |= 0x2 ;
  }
  break ;
  case 3 :
  {
   reg =(void *)cm_per_addr + 0xB4;
   *reg |= 0x2 ;
  }
  break ;
  default :
  {
   return 0 ;
  }
  break ;
 }
 return 1 ;
}

variable_types:
gpio
unsigned int


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

if ( !cm_per_addr || a1 > 3 )
return 0LL;
if ( a1 == 2 )
{
*(_DWORD *)(cm_per_addr + 176) &= 0xFFFFFFFD;
result = 1LL;
}
else if ( a1 == 3 )
{
*(_DWORD *)(cm_per_addr + 180) &= 0xFFFFFFFD;
result = 1LL;
}
else
{
if ( a1 == 1 )
*(_DWORD *)(cm_per_addr + 172) &= 0xFFFFFFFD;
else
*(_DWORD *)(cm_wkup_addr + 8) &= 2u;
result = 1LL;
}
return result;
}

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

if ( !cm_per_addr || a1 > 3 )
return 0LL;
if ( a1 == 2 )
{
*(_DWORD *)(cm_per_addr + 176) &= 0xFFFFFFFD;
result = 1LL;
}
else if ( a1 == 3 )
{
*(_DWORD *)(cm_per_addr + 180) &= 0xFFFFFFFD;
result = 1LL;
}
else
{
if ( a1 == 1 )
*(_DWORD *)(cm_per_addr + 172) &= 0xFFFFFFFD;
else
*(_DWORD *)(cm_wkup_addr + 8) &= 2u;
result = 1LL;
}
return result;
}

original_code:
int BBBIO_sys_Disable_GPIO(unsigned int gpio)
{
 int param_error=0;
 volatile unsigned int* reg;
 if (cm_per_addr==0)
  param_error=1;
 if (gpio <0 || gpio >3)
  param_error=1;
 if (param_error)
 {
  if (0) printf("BBBIO_sys_Disable_GPIO: parameter error!\n");
  return 0;
 }
 switch(gpio)
 {
  case 0 :
  {
   reg =(void*)cm_wkup_addr + 0x8;
                        *reg &= 0x2 ;
  }
  break ;
  case 1 :
  {
   reg =(void*)cm_per_addr + 0xAC;
   *reg &= ~0x2 ;
  }
  break ;
  case 2 :
  {
   reg =(void*)cm_per_addr + 0xB0;
   *reg &= ~0x2 ;
  }
  break ;
  case 3 :
  {
   reg =(void*)cm_per_addr + 0xB4;
   *reg &= ~0x2 ;
  }
  break ;
  default :
  {
   return 0 ;
  }
  break ;
 }
 return 1 ;
}

canonical_original_code:
int BBBIO_sys_Disable_GPIO(unsigned int gpio)
{
 int param_error = 0;
 unsigned int *reg;
 if (cm_per_addr==0)
  param_error=1;
 if (gpio <0 || gpio >3)
  param_error=1;
 if (param_error)
 {
  if (0) printf("BBBIO_sys_Disable_GPIO: parameter error!\n");
  return 0;
 }
 switch(gpio)
 {
  case 0 :
  {
   reg =(void *)cm_wkup_addr + 0x8;
                        *reg &= 0x2 ;
  }
  break ;
  case 1 :
  {
   reg =(void *)cm_per_addr + 0xAC;
   *reg &= ~0x2 ;
  }
  break ;
  case 2 :
  {
   reg =(void *)cm_per_addr + 0xB0;
   *reg &= ~0x2 ;
  }
  break ;
  case 3 :
  {
   reg =(void *)cm_per_addr + 0xB4;
   *reg &= ~0x2 ;
  }
  break ;
  default :
  {
   return 0 ;
  }
  break ;
 }
 return 1 ;
}


decompiled_code:
__int64 __fastcall BBBIO_GPIO_set_dir(unsigned int a1, int a2, int a3)
{
__int64 v4; // rax

if ( !memh || a1 > 3 || !(a3 | a2) )
return 0xFFFFFFFFLL;
v4 = gpio_addr[a1];
*(_DWORD *)(v4 + 308) &= ~a3;
*(_DWORD *)(v4 + 308) |= a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, int a2, int a3)
{
__int64 v4; // rax

if ( !memh || a1 > 3 || !(a3 | a2) )
return 0xFFFFFFFFLL;
v4 = gpio_addr[a1];
*(_DWORD *)(v4 + 308) &= ~a3;
*(_DWORD *)(v4 + 308) |= a2;
return 0LL;
}

original_code:
int
BBBIO_GPIO_set_dir(unsigned int gpio, unsigned int inset , unsigned int outset)
{
        int i;
        int param_error=0;
        volatile unsigned int* reg;
        if (memh==0)
                param_error=1;
        if (gpio <0 || gpio >3)
                param_error=1;
        if (inset==0 && outset==0)
                param_error=1;
        if (param_error)
        {
                if (0) printf("BBBIO_GPIO_set_dir: parameter error!\n");
                return(-1);
        }
        reg=(void*)gpio_addr[gpio] +0x134;
        *reg &= ~outset ;
        *reg |= inset ;
        return 0;
}

canonical_original_code:
int BBBIO_GPIO_set_dir(unsigned int gpio, unsigned int inset, unsigned int outset)
{
        int i;
        int param_error = 0;
        unsigned int *reg;
        if (memh==0)
                param_error=1;
        if (gpio <0 || gpio >3)
                param_error=1;
        if (inset==0 && outset==0)
                param_error=1;
        if (param_error)
        {
                if (0) printf("BBBIO_GPIO_set_dir: parameter error!\n");
                return(-1);
        }
        reg=(void *)gpio_addr[gpio] +0x134;
        *reg &= ~outset ;
        *reg |= inset ;
        return 0;
}

variable_types:
inset
unsigned int

variable_types:
outset
unsigned int


original_code:
unsigned int
col565(rgb_t* rgb)
{
 unsigned int r,g,b;
 r=(unsigned int) rgb->r;
 g=(unsigned int) rgb->g;
 b=(unsigned int) rgb->b;
  return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}

canonical_original_code:
unsigned int col565(struct rgb_s *rgb)
{
 unsigned int r; unsigned int g; unsigned int b;
 r=(unsigned int) rgb->r;
 g=(unsigned int) rgb->g;
 b=(unsigned int) rgb->b;
  return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}

variable_types: struct rgb_s { unsigned char r; unsigned char g; unsigned char b; } *

variable_types:
r
unsigned int

variable_types:
g
unsigned int

variable_types:
b
unsigned int


repo: shackspace/LOTUS

original_code:
int OTUS_dumpMessageToConsole(const OTUSMsg* msg)
{
    printf("\n\n\n");
    printf("MSG: %0.4x/%0.2x  TS:%0.8x\n",
            msg->magic,
            msg->msgCounter,
            msg->timestamp
            );
    printf("Jog0:%0.4x/%5d  Jog1:%0.2x Jog2:%0.2x Jog3:%0.2x Jog4:%0.2x\n",
            msg->jog0Rot,
            msg->jog0Speed,
            msg->jog1Rot,
            msg->jog2Rot,
            msg->jog3Rot,
            msg->jog4Rot
            );
    printf(" DeckA: G:%0.4x  H:%0.4x M:%0.4x L:%0.4x P:%0.4x  %s\n"
           " DeckB: G:%0.4x  H:%0.4x M:%0.4x L:%0.4x P:%0.4x  %s\n"
           "   XFader:%0.4x     Gain:%0.4x\n",
           msg->rotAGain,
           msg->rotAHigh,
           msg->rotAMid,
           msg->rotALow,
           msg->pitchA,
           msg->status == 0 ? "(active)" : "",
           msg->rotBGain,
           msg->rotBHigh,
           msg->rotBMid,
           msg->rotBLow,
           msg->pitchB,
           msg->status == 0 ? "" : "(active)",
           msg->rotXFader,
           msg->rotMaster
           );
    printf("PAD: X:%0.4x Y:%0.4x\n",
            msg->padX,
            msg->padY
            );
    printf("Buttons: %0.8x  Status: %0.4x\n",
            msg->buttons,
            msg->status
            );
    const int offset = strlen("OTUS_BUTTON_");
    for(OTUSButton* button = OTUSButtonMap; button->name != ((void *)0); ++button)
    {
        if(msg->buttons & button->id)
            printf("%s ",button->name+offset);
    }
    printf("\n");
    return OTUS_ERROR_OK;
}

canonical_original_code:
int OTUS_dumpMessageToConsole(struct OTUSMsg_ *msg)
{
    printf("\n\n\n");
    printf("MSG: %0.4x/%0.2x  TS:%0.8x\n",
            msg->magic,
            msg->msgCounter,
            msg->timestamp
            );
    printf("Jog0:%0.4x/%5d  Jog1:%0.2x Jog2:%0.2x Jog3:%0.2x Jog4:%0.2x\n",
            msg->jog0Rot,
            msg->jog0Speed,
            msg->jog1Rot,
            msg->jog2Rot,
            msg->jog3Rot,
            msg->jog4Rot
            );
    printf(" DeckA: G:%0.4x  H:%0.4x M:%0.4x L:%0.4x P:%0.4x  %s\n"
           " DeckB: G:%0.4x  H:%0.4x M:%0.4x L:%0.4x P:%0.4x  %s\n"
           "   XFader:%0.4x     Gain:%0.4x\n",
           msg->rotAGain,
           msg->rotAHigh,
           msg->rotAMid,
           msg->rotALow,
           msg->pitchA,
           msg->status == 0 ? "(active)" : "",
           msg->rotBGain,
           msg->rotBHigh,
           msg->rotBMid,
           msg->rotBLow,
           msg->pitchB,
           msg->status == 0 ? "" : "(active)",
           msg->rotXFader,
           msg->rotMaster
           );
    printf("PAD: X:%0.4x Y:%0.4x\n",
            msg->padX,
            msg->padY
            );
    printf("Buttons: %0.8x  Status: %0.4x\n",
            msg->buttons,
            msg->status
            );
    int offset = strlen("OTUS_BUTTON_");
    for(struct OTUSButton_ *button = OTUSButtonMap; button->name != ((void *)0); ++button)
    {
        if(msg->buttons & button->id)
            printf("%s ",button->name+offset);
    }
    printf("\n");
    return OTUS_ERROR_OK;
}

variable_types: struct OTUSMsg_ { unsigned short magic; unsigned short jog0Rot; short jog0Speed; unsigned int timestamp; unsigned int _0a_0d_reserved; unsigned char jog2Rot; unsigned char jog4Rot; unsigned char jog3Rot; unsigned char jog1Rot; unsigned short rotAGain; unsigned short rotBGain; unsigned short rotAHigh; unsigned short rotBHigh; unsigned short rotAMid; unsigned short rotBMid; unsigned short rotALow; unsigned short rotBLow; unsigned short rotXFader; unsigned short rotMaster; unsigned short padY; unsigned short padX; unsigned short pitchA; unsigned short pitchB; unsigned int buttons; unsigned char filler; unsigned char msgCounter; unsigned short status; unsigned char _36_reserved; unsigned char _37_reserved; unsigned int _38_3b_reserved; unsigned int _3c_3f_reserved; } *

variable_types: offset int

variable_types: struct OTUSButton_ { unsigned int id; char *name; } *


main

repo: shadowpho/Lisa

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // r12
const char *v5; // rax
__int64 v6; // r12
__int64 v7; // r12
__int64 v8; // r12
__int64 v9; // r12
__int64 v10; // r12

v3 = (unsigned int)load_lib(IPC_LIBRARY_PATH, argv, envp);
printf("%s = %d\n", "load library", v3);
if ( (_DWORD)v3 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 75LL);
perror("load library");
}
else
{
v4 = (unsigned int)resolve_syms();
printf("%s = %d\n", "resolve symbols", v4);
if ( (_DWORD)v4 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 78LL);
perror("resolve symbols");
}
else
{
v5 = (const char *)get_version();
printf("Library version tested: %s\n", v5);
v6 = (unsigned int)IPC_init(478LL, 479LL);
printf("%s = %d\n", "init ipc", v6);
if ( (_DWORD)v6 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 83LL);
perror("init ipc");
}
else
{
v7 = (unsigned int)IPC_send(0LL, 0LL, 0LL, 0LL);
printf("%s = %d\n", "send", v7);
if ( (_DWORD)v7 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 86LL);
perror("send");
}
else
{
v8 = (unsigned int)IPC_peek(0LL, 0LL);
printf("%s = %d\n", "peek", v8);
if ( (_DWORD)v8 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 89LL);
perror("peek");
}
else
{
v9 = (unsigned int)IPC_recv(0LL, 0LL);
printf("%s = %d\n", "recv", v9);
if ( (_DWORD)v9 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 92LL);
perror("recv");
}
else
{
v10 = (unsigned int)close_lib();
printf("%s = %d\n", "close lib", v10);
if ( (_DWORD)v10 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 95LL);
perror("close lib");
}
else
{
puts("ALL GOOD!!!");
}
}
}
}
}
}
}
return v10;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // r12
const char *v5; // rax
__int64 v6; // r12
__int64 v7; // r12
__int64 v8; // r12
__int64 v9; // r12
__int64 v10; // r12

v3 = (unsigned int)func7(IPC_LIBRARY_PATH, argv, envp);
printf("%s = %d\n", "load library", v3);
if ( (_DWORD)v3 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 75LL);
perror("load library");
}
else
{
v4 = (unsigned int)func8();
printf("%s = %d\n", "resolve symbols", v4);
if ( (_DWORD)v4 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 78LL);
perror("resolve symbols");
}
else
{
v5 = (const char *)get_version();
printf("Library version tested: %s\n", v5);
v6 = (unsigned int)IPC_init(478LL, 479LL);
printf("%s = %d\n", "init ipc", v6);
if ( (_DWORD)v6 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 83LL);
perror("init ipc");
}
else
{
v7 = (unsigned int)IPC_send(0LL, 0LL, 0LL, 0LL);
printf("%s = %d\n", "send", v7);
if ( (_DWORD)v7 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 86LL);
perror("send");
}
else
{
v8 = (unsigned int)IPC_peek(0LL, 0LL);
printf("%s = %d\n", "peek", v8);
if ( (_DWORD)v8 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 89LL);
perror("peek");
}
else
{
v9 = (unsigned int)IPC_recv(0LL, 0LL);
printf("%s = %d\n", "recv", v9);
if ( (_DWORD)v9 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 92LL);
perror("recv");
}
else
{
v10 = (unsigned int)func9();
printf("%s = %d\n", "close lib", v10);
if ( (_DWORD)v10 )
{
LODWORD(v10) = -1;
printf("Error at line: %d, error:\n", 95LL);
perror("close lib");
}
else
{
puts("ALL GOOD!!!");
}
}
}
}
}
}
}
return v10;
}

original_code:
int main(int argv, char* argc[])
{
    int status = load_lib(IPC_LIBRARY_PATH);
    do{ printf("%s = %d\n","load library",status); if((status)!=0){printf("Error at line: %d, error:\n",75);perror("load library");return -1;} }while(0);;
    status = resolve_syms();
    do{ printf("%s = %d\n","resolve symbols",status); if((status)!=0){printf("Error at line: %d, error:\n",78);perror("resolve symbols");return -1;} }while(0);;
    printf("Library version tested: %s\n", get_version());
    status = IPC_init(478,479);
    do{ printf("%s = %d\n","init ipc",status); if((status)!=0){printf("Error at line: %d, error:\n",83);perror("init ipc");return -1;} }while(0);;
    status = IPC_send(0, 0, ((void *)0), 0);
    do{ printf("%s = %d\n","send",status); if((status)!=0){printf("Error at line: %d, error:\n",86);perror("send");return -1;} }while(0);;
    status = IPC_peek(((void *)0), ((void *)0));
    do{ printf("%s = %d\n","peek",status); if((status)!=0){printf("Error at line: %d, error:\n",89);perror("peek");return -1;} }while(0);;
    status = IPC_recv(((void *)0), 0);
    do{ printf("%s = %d\n","recv",status); if((status)!=0){printf("Error at line: %d, error:\n",92);perror("recv");return -1;} }while(0);;
    status = close_lib();
    do{ printf("%s = %d\n","close lib",status); if((status)!=0){printf("Error at line: %d, error:\n",95);perror("close lib");return -1;} }while(0);;
    printf("%s","ALL GOOD!!!\n");
    return 0;
}

canonical_original_code:
int main(int argv, char *argc[])
{
    int status = load_lib(IPC_LIBRARY_PATH);
    do{ printf("%s = %d\n","load library",status); if((status)!=0){printf("Error at line: %d, error:\n",75);perror("load library");return -1;} }while(0);;
    status = resolve_syms();
    do{ printf("%s = %d\n","resolve symbols",status); if((status)!=0){printf("Error at line: %d, error:\n",78);perror("resolve symbols");return -1;} }while(0);;
    printf("Library version tested: %s\n", get_version());
    status = IPC_init(478,479);
    do{ printf("%s = %d\n","init ipc",status); if((status)!=0){printf("Error at line: %d, error:\n",83);perror("init ipc");return -1;} }while(0);;
    status = IPC_send(0, 0, ((void *)0), 0);
    do{ printf("%s = %d\n","send",status); if((status)!=0){printf("Error at line: %d, error:\n",86);perror("send");return -1;} }while(0);;
    status = IPC_peek(((void *)0), ((void *)0));
    do{ printf("%s = %d\n","peek",status); if((status)!=0){printf("Error at line: %d, error:\n",89);perror("peek");return -1;} }while(0);;
    status = IPC_recv(((void *)0), 0);
    do{ printf("%s = %d\n","recv",status); if((status)!=0){printf("Error at line: %d, error:\n",92);perror("recv");return -1;} }while(0);;
    status = close_lib();
    do{ printf("%s = %d\n","close lib",status); if((status)!=0){printf("Error at line: %d, error:\n",95);perror("close lib");return -1;} }while(0);;
    printf("%s","ALL GOOD!!!\n");
    return 0;
}

variable_types: argv int

variable_types:
argc
char *[]

variable_types: status int


decompiled_code:
__int64 load_lib()
{
char *v1; // rax

test_handle = dlopen(IPC_LIBRARY_PATH, 1);
if ( test_handle )
return 0LL;
v1 = dlerror();
puts(v1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func7()
{
char *v1; // rax

test_handle = dlopen(IPC_LIBRARY_PATH, 1);
if ( test_handle )
return 0LL;
v1 = dlerror();
puts(v1);
return 0xFFFFFFFFLL;
}

original_code:
int load_lib(char* path)
{
    test_handle = dlopen(IPC_LIBRARY_PATH,0x00001|0);
    if(!test_handle)
    {
        printf("%s\n",dlerror());
        return -1;
    }
    return 0;
}

canonical_original_code:
int load_lib(char *path)
{
    test_handle = dlopen(IPC_LIBRARY_PATH,0x00001|0);
    if(!test_handle)
    {
        printf("%s\n",dlerror());
        return -1;
    }
    return 0;
}

variable_types:
path
char *