repo: jorgefranconunes/mathstuff

decompiled_code:
__int64 __fastcall SysTickSource_init(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v5; // r12
__int64 v6; // rax
__int64 result; // rax

v3 = CounterTickSource_init(&tickSourceData, a1, a2, a3);
v4 = CounterTickSource_getClock(v3);
v5 = SysEventManager_get();
v6 = CounterTickSource_asEventSource(v3);
result = EventManager_addSource(v5, v6);
tickSource = v3;
*(_QWORD *)clock = v4;
needsInit = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v5; // r12
__int64 v6; // rax
__int64 result; // rax

v3 = CounterTickSource_init(&tickSourceData, a1, a2, a3);
v4 = CounterTickSource_getClock(v3);
v5 = SysEventManager_get();
v6 = CounterTickSource_asEventSource(v3);
result = EventManager_addSource(v5, v6);
tickSource = v3;
*(_QWORD *)clock = v4;
needsInit = 0;
return result;
}

original_code:
void SysTickSource_init(long (*tickCountGetter)(void),
                        int incrementFactorN,
                        int incrementFactorD) {
    CounterTickSource *tickSource =
        CounterTickSource_init(&_tickSourceData,
                               tickCountGetter,
                               incrementFactorN,
                               incrementFactorD);
    Clock *clock =
        CounterTickSource_getClock(tickSource);
    EventManager *eventManager =
        SysEventManager_get();
    EventManager_addSource(eventManager,
                           CounterTickSource_asEventSource(tickSource));
    _tickSource = tickSource;
    _clock = clock;
    _needsInit = 0;
}

canonical_original_code:
void SysTickSource_init(long (*tickCountGetter)(), int incrementFactorN, int incrementFactorD) {
    struct CounterTickSourceStruct *tickSource = CounterTickSource_init(&_tickSourceData,
                               tickCountGetter,
                               incrementFactorN,
                               incrementFactorD);
    struct ClockStruct *clock = CounterTickSource_getClock(tickSource);
    struct EventManagerStruct *eventManager = SysEventManager_get();
    EventManager_addSource(eventManager,
                           CounterTickSource_asEventSource(tickSource));
    _tickSource = tickSource;
    _clock = clock;
    _needsInit = 0;
}

variable_types:
tickCountGetter
long (*)()

variable_types: incrementFactorN int

variable_types: incrementFactorD int

variable_types: struct CounterTickSourceStruct { struct EventSourceStruct { struct EventSourceInterfaceStruct { struct EventStruct { struct EventTypeStruct { int id; } *eventType; } *(*poll)(struct EventSourceStruct *); } *vtable; struct EventSourceStruct *next; } base; long (*tickCountGetter)(); struct CounterClockStruct { struct ClockStruct { struct ClockInterfaceStruct { long (*currentTimeMillis)(struct ClockStruct *); } *vtable; } base; int incrFactorN; int incrFactorD; long ticks; long time; } clock; struct EventStruct tickEvent; long lastTickCount; } *

variable_types: struct ClockStruct { struct ClockInterfaceStruct { long (*currentTimeMillis)(struct ClockStruct *); } *vtable; } *

variable_types: struct EventManagerStruct { enum EventManagerStatus { STOPED=0, STARTED=1 } status; struct EventSourceStruct { struct EventSourceInterfaceStruct { struct EventStruct { struct EventTypeStruct { int id; } *eventType; } *(*poll)(struct EventSourceStruct *); } *vtable; struct EventSourceStruct *next; } *eventSourceListHead; struct EventListenerStruct { struct EventListenerInterfaceStruct { void (*notify)(struct EventListenerStruct *, struct EventStruct *); } *vtable; struct EventTypeStruct *eventType; struct EventListenerStruct *next; } *eventListenerListHead; } *

user_defined_types: struct CounterTickSourceStruct { struct EventSourceStruct base; long (*tickCountGetter)(); struct CounterClockStruct clock; struct EventStruct tickEvent; long lastTickCount; }

user_defined_types: struct ClockStruct { struct ClockInterfaceStruct *vtable; }

user_defined_types: struct EventManagerStruct { enum EventManagerStatus status; struct EventSourceStruct *eventSourceListHead; struct EventListenerStruct *eventListenerListHead; }

user_defined_types: struct EventSourceStruct { struct EventSourceInterfaceStruct *vtable; struct EventSourceStruct *next; }

user_defined_types: struct CounterClockStruct { struct ClockStruct base; int incrFactorN; int incrFactorD; long ticks; long time; }

user_defined_types: struct EventListenerStruct { struct EventListenerInterfaceStruct *vtable; struct EventTypeStruct *eventType; struct EventListenerStruct *next; }

user_defined_types: struct EventSourceInterfaceStruct { struct EventStruct *(*poll)(struct EventSourceStruct *); }

user_defined_types: struct EventStruct { struct EventTypeStruct *eventType; }


decompiled_code:
__int64 SysTickSource_get()
{
if ( needsInit )
_assert_fail(
"_needsInit == false",
"../ardev-core/src/main/c/ardev/sys/SysTickSource.c",
0x44u,
"SysTickSource_get");
return CounterTickSource_asEventSource(tickSource);
}

canonical_decompiled_code:
__int64 func1()
{
if ( needsInit )
_assert_fail(
"_needsInit == false",
"../ardev-core/src/main/c/ardev/sys/SysTickSource.c",
0x44u,
"SysTickSource_get");
return CounterTickSource_asEventSource(tickSource);
}

original_code:
EventSource *SysTickSource_get() {
    ((void) sizeof ((_needsInit == 0) ? 1 : 0), __extension__ ({ if (_needsInit == 0) ; else __assert_fail ("_needsInit == false", "../ardev-core/src/main/c/ardev/sys/SysTickSource.c", 68, __extension__ __PRETTY_FUNCTION__); }));
    EventSource *result = CounterTickSource_asEventSource(_tickSource);
    return result;
}

canonical_original_code:
struct EventSourceStruct *SysTickSource_get() {
    ((void) sizeof ((_needsInit == 0) ? 1 : 0), __extension__ ({ if (_needsInit == 0) ; else __assert_fail ("_needsInit == false", "../ardev-core/src/main/c/ardev/sys/SysTickSource.c", 68, __extension__ __PRETTY_FUNCTION__); }));
    struct EventSourceStruct *result = CounterTickSource_asEventSource(_tickSource);
    return result;
}

variable_types: struct EventSourceStruct { struct EventSourceInterfaceStruct { struct EventStruct { struct EventTypeStruct { int id; } *eventType; } *(*poll)(struct EventSourceStruct *); } *vtable; struct EventSourceStruct *next; } *


decompiled_code:
__int64 SysTickSource_getClock()
{
if ( needsInit )
_assert_fail(
"_needsInit == false",
"../ardev-core/src/main/c/ardev/sys/SysTickSource.c",
0x57u,
"SysTickSource_getClock");
return *(_QWORD *)clock;
}

canonical_decompiled_code:
__int64 func2()
{
if ( needsInit )
_assert_fail(
"_needsInit == false",
"../ardev-core/src/main/c/ardev/sys/SysTickSource.c",
0x57u,
"SysTickSource_getClock");
return *(_QWORD *)clock;
}

original_code:
Clock *SysTickSource_getClock() {
    ((void) sizeof ((_needsInit == 0) ? 1 : 0), __extension__ ({ if (_needsInit == 0) ; else __assert_fail ("_needsInit == false", "../ardev-core/src/main/c/ardev/sys/SysTickSource.c", 87, __extension__ __PRETTY_FUNCTION__); }));
    return _clock;
}

canonical_original_code:
struct ClockStruct *SysTickSource_getClock() {
    ((void) sizeof ((_needsInit == 0) ? 1 : 0), __extension__ ({ if (_needsInit == 0) ; else __assert_fail ("_needsInit == false", "../ardev-core/src/main/c/ardev/sys/SysTickSource.c", 87, __extension__ __PRETTY_FUNCTION__); }));
    return _clock;
}

return_type: struct ClockStruct { struct ClockInterfaceStruct { long (*currentTimeMillis)(struct ClockStruct *); } *vtable; } *


decompiled_code:
void SysTickSource_reset()
{
tickSource = 0LL;
*(_QWORD *)clock = 0LL;
needsInit = 1;
}

canonical_decompiled_code:
void func3()
{
tickSource = 0LL;
*(_QWORD *)clock = 0LL;
needsInit = 1;
}

original_code:
void SysTickSource_reset() {
    _tickSource = ((void *)0);
    _clock = ((void *)0);
    _needsInit = 1;
}

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
int v4; // er13
int v5; // er12
signed int v6; // er15
int v7; // er14
int v8; // ebx
double v10; // [rsp+0h] [rbp-68h]
int v11; // [rsp+Ch] [rbp-5Ch]
char v12; // [rsp+10h] [rbp-58h] BYREF
char v13; // [rsp+30h] [rbp-38h] BYREF

v3 = &v12;
v11 = 10;
v4 = 0;
v5 = 0;
v10 = 0.25;
v6 = 0;
v7 = 1;
do
{
v8 = (int)((double)v7 + v10 + (double)v5);
if ( v8 > 99 )
{
if ( v8 == 100 )
printf("Please enter the sum of %d Euro coin\n", 1LL);
else
printf("Please enter the sum of %d Euros coins\n", (unsigned int)(v8 / 100));
}
else if ( v8 == 1 )
{
printf("Please enter the sum of %d cent coin\n", 1LL);
}
else
{
printf("Please enter the sum of %d cent coins\n", (unsigned int)v8);
}
scanf("%d", v3);
v6 += *(_DWORD *)v3 * v8;
v7 *= 2;
v10 = v10 + v10;
++v4;
v5 *= 2;
if ( v4 == 5 )
{
v5 += v11;
v11 *= 10;
v4 = 2;
}
v3 += 4;
}
while ( &v13 != v3 );
puts("Thx you for entring the sum of coins!\n");
printf(
"The sum of all coins is: %d in Cents and %d,%d in Euros\n",
(unsigned int)v6,
(unsigned int)(v6 / 100),
(unsigned int)(v6 % 100));
return 0;
}

original_code:
int main ()
{
 int i;
 int Potenza = 1;
 int CurrentCoin = 0;
 int AmountCoins [8];
 int CashValue = 0;
 double offset_2 = 0.25;
 int offset_10 = 0;
 int n = 0;
 int offset = 10;
 for (i = 0; i < 8; i++)
 {
  CurrentCoin = Potenza + offset_2 + offset_10;
  if (CurrentCoin < 100)
  {
   if (CurrentCoin == 1)
    printf("Please enter the sum of %d cent coin\n", CurrentCoin);
   else
    printf("Please enter the sum of %d cent coins\n", CurrentCoin);
  }
  else
  {
   if (CurrentCoin == 100)
    printf("Please enter the sum of %d Euro coin\n", CurrentCoin/100);
   else
    printf("Please enter the sum of %d Euros coins\n", CurrentCoin/100);
  }
  scanf("%d", &AmountCoins[i]);
  CashValue += AmountCoins[i] * CurrentCoin;
  Potenza += Potenza;
  offset_2 += offset_2;
  n++;
  offset_10 += offset_10;
  if (n == 5)
  {
   offset_10 += offset;
   n = 2;
   offset *= 10;
  }
 }
 printf("Thx you for entring the sum of coins!\n\n");
 printf("The sum of all coins is: %d in Cents and %d,%d in Euros\n", CashValue, CashValue/100, CashValue - (CashValue/100)*100);
 return 0;
}

canonical_original_code:
int main()
{
 int i;
 int Potenza = 1;
 int CurrentCoin = 0;
 int AmountCoins[8];
 int CashValue = 0;
 double offset_2 = 0.25;
 int offset_10 = 0;
 int n = 0;
 int offset = 10;
 for (i = 0; i < 8; i++)
 {
  CurrentCoin = Potenza + offset_2 + offset_10;
  if (CurrentCoin < 100)
  {
   if (CurrentCoin == 1)
    printf("Please enter the sum of %d cent coin\n", CurrentCoin);
   else
    printf("Please enter the sum of %d cent coins\n", CurrentCoin);
  }
  else
  {
   if (CurrentCoin == 100)
    printf("Please enter the sum of %d Euro coin\n", CurrentCoin/100);
   else
    printf("Please enter the sum of %d Euros coins\n", CurrentCoin/100);
  }
  scanf("%d", &AmountCoins[i]);
  CashValue += AmountCoins[i] * CurrentCoin;
  Potenza += Potenza;
  offset_2 += offset_2;
  n++;
  offset_10 += offset_10;
  if (n == 5)
  {
   offset_10 += offset;
   n = 2;
   offset *= 10;
  }
 }
 printf("Thx you for entring the sum of coins!\n\n");
 printf("The sum of all coins is: %d in Cents and %d,%d in Euros\n", CashValue, CashValue/100, CashValue - (CashValue/100)*100);
 return 0;
}

variable_types: i int

variable_types: Potenza int

variable_types: CurrentCoin int

variable_types:
AmountCoins
int [8]

variable_types: CashValue int

variable_types: n int

variable_types: offset int

return_type: int


repo: kajnelissen/sereti-trafficlights

decompiled_code:
__int64 create_pedestrianlight()
{
return (create_pushbutton() << 32) | 2;
}

canonical_decompiled_code:
__int64 func0()
{
return (create_pushbutton() << 32) | 2;
}

original_code:
PedestrianLight create_pedestrianlight(){
    PedestrianLight pedestrianlight;
    pedestrianlight.light = 2;
    pedestrianlight.pushbutton = create_pushbutton();
    return pedestrianlight;
}

canonical_original_code:
struct PedestrianLight create_pedestrianlight(){
    struct PedestrianLight pedestrianlight;
    pedestrianlight.light = 2;
    pedestrianlight.pushbutton = create_pushbutton();
    return pedestrianlight;
}

variable_types: struct PedestrianLight { enum Light { GREEN=0, ORANGE=1, RED=2 } light; struct PushButton { int status; } pushbutton; }

user_defined_types: struct PedestrianLight { enum Light light; struct PushButton pushbutton; }


repo: khmacdonald/AES

decompiled_code:
__int64 __fastcall random_bytes(int *a1, int a2, unsigned int a3)
{
__int64 result; // rax
int *v4; // rbx
int v5; // eax
unsigned __int64 v6; // rax
int v7[11]; // [rsp+0h] [rbp-2Ch]

result = 0xFFFFFFFFLL;
if ( a2 >= 0 )
{
v4 = a1;
srand(a3);
if ( a2 <= 0 )
{
result = 0LL;
}
else
{
while ( 1 )
{
v5 = rand();
v7[0] = v5;
if ( v4 == &a1[(unsigned int)(a2 - 1) >> 2] )
break;
*v4++ = v5;
}
if ( a2 != 4 * ((unsigned int)(a2 - 1) >> 2) )
{
v6 = 0LL;
do
{
*((_BYTE *)v4 + v6) = *((_BYTE *)v7 + v6);
++v6;
}
while ( v6 < (int)(a2 - 4 * ((unsigned int)(a2 - 1) >> 2)) );
}
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1, int a2, unsigned int a3)
{
__int64 result; // rax
int *v4; // rbx
int v5; // eax
unsigned __int64 v6; // rax
int v7[11]; // [rsp+0h] [rbp-2Ch]

result = 0xFFFFFFFFLL;
if ( a2 >= 0 )
{
v4 = a1;
srand(a3);
if ( a2 <= 0 )
{
result = 0LL;
}
else
{
while ( 1 )
{
v5 = rand();
v7[0] = v5;
if ( v4 == &a1[(unsigned int)(a2 - 1) >> 2] )
break;
*v4++ = v5;
}
if ( a2 != 4 * ((unsigned int)(a2 - 1) >> 2) )
{
v6 = 0LL;
do
{
*((_BYTE *)v4 + v6) = *((_BYTE *)v7 + v6);
++v6;
}
while ( v6 < (int)(a2 - 4 * ((unsigned int)(a2 - 1) >> 2)) );
}
result = 0LL;
}
}
return result;
}

original_code:
uint32_t random_bytes(uint8_t * byte_arr, uint32_t m, uint32_t seed )
{
    uint32_t rndnum, k=0;
    int32_t n = (int32_t) m;
    void * dest = (void*) byte_arr;
    const void * src = &rndnum;
    if (n<0)
        return -1;
    srand(seed);
    while ( n>0 )
    {
        rndnum = (uint32_t) rand();
        if ( n > 4 )
            memcpy(dest,src,4);
        else
            memcpy(dest,src,n);
        k++;
        n -= 4;
        dest = (void*)(byte_arr+4*k);
    }
    return 0;
}

canonical_original_code:
unsigned int random_bytes(unsigned char *byte_arr, unsigned int m, unsigned int seed)
{
    unsigned int rndnum; unsigned int k = 0;
    int n = (int32_t) m;
    void *dest = (void*) byte_arr;
    void *src = &rndnum;
    if (n<0)
        return -1;
    srand(seed);
    while ( n>0 )
    {
        rndnum = (unsigned int) rand();
        if ( n > 4 )
            memcpy(dest,src,4);
        else
            memcpy(dest,src,n);
        k++;
        n -= 4;
        dest = (void *)(byte_arr+4*k);
    }
    return 0;
}

variable_types:
m
unsigned int

variable_types:
seed
unsigned int

variable_types:
rndnum
unsigned int

variable_types:
k
unsigned int

variable_types:
dest
void *

variable_types:
src
void *

return_type: unsigned int


decompiled_code:
__int64 inversion_test()
{
__int64 v0; // rbx
unsigned int v1; // er12
unsigned int v2; // ebp
unsigned __int8 v3; // al
__int64 v5; // [rsp+6h] [rbp-22h] BYREF
__int16 v6; // [rsp+Eh] [rbp-1Ah]

v5 = 0LL;
v6 = 0;
random_bytes((int *)&v5, 10, 1u);
puts(" Inversion Test");
v0 = 0LL;
v1 = 0;
do
{
v2 = *((unsigned __int8 *)&v5 + v0);
v3 = Rijndael_Inv(*((unsigned __int8 *)&v5 + v0));
if ( (unsigned __int8)Rijndael_Mul(v2, v3) == 1 )
{
printf("[%d]:\tSUCCESS\n", (unsigned int)v0);
}
else
{
printf("[%d]:\tERROR\n", (unsigned int)v0);
++v1;
}
++v0;
}
while ( v0 != 10 );
return v1;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rbx
unsigned int v1; // er12
unsigned int v2; // ebp
unsigned __int8 v3; // al
__int64 v5; // [rsp+6h] [rbp-22h] BYREF
__int16 v6; // [rsp+Eh] [rbp-1Ah]

v5 = 0LL;
v6 = 0;
func7((int *)&v5, 10, 1u);
puts(" Inversion Test");
v0 = 0LL;
v1 = 0;
do
{
v2 = *((unsigned __int8 *)&v5 + v0);
v3 = func26(*((unsigned __int8 *)&v5 + v0));
if ( (unsigned __int8)func29(v2, v3) == 1 )
{
printf("[%d]:\tSUCCESS\n", (unsigned int)v0);
}
else
{
printf("[%d]:\tERROR\n", (unsigned int)v0);
++v1;
}
++v0;
}
while ( v0 != 10 );
return v1;
}

original_code:
int inversion_test( void )
{
    uint8_t rnd[10] = {0};
    uint8_t a,b,c;
    int32_t k;
    int errors = 0;
    random_bytes(rnd,10,1);
    printf("  Inversion Test\n");
    for(k=0; k<10; k++)
    {
        a = rnd[k];
        b = Rijndael_Inv(a);
        c = Rijndael_Mul(a,b);
        if(1!=c)
        {
            printf("[%d]:\tERROR\n",k);
            errors++;
        }
        else
            printf("[%d]:\tSUCCESS\n",k);
    }
    return errors;
}

canonical_original_code:
int inversion_test()
{
    unsigned char rnd[10] = {0};
    unsigned char a; unsigned char b; unsigned char c;
    int k;
    int errors = 0;
    random_bytes(rnd,10,1);
    printf("  Inversion Test\n");
    for(k=0; k<10; k++)
    {
        a = rnd[k];
        b = Rijndael_Inv(a);
        c = Rijndael_Mul(a,b);
        if(1!=c)
        {
            printf("[%d]:\tERROR\n",k);
            errors++;
        }
        else
            printf("[%d]:\tSUCCESS\n",k);
    }
    return errors;
}

variable_types:
rnd
unsigned char [10]

variable_types:
a
unsigned char

variable_types:
b
unsigned char

variable_types:
c
unsigned char

variable_types: k int

variable_types: errors int


decompiled_code:
__int64 addition_test()
{
__int64 v0; // rbx
unsigned int v1; // ebp
__int64 v3; // [rsp+Ch] [rbp-2Ch] BYREF
__int16 v4; // [rsp+14h] [rbp-24h]
__int64 v5; // [rsp+16h] [rbp-22h] BYREF
__int16 v6; // [rsp+1Eh] [rbp-1Ah]

v5 = 0LL;
v6 = 0;
v3 = 0LL;
v4 = 0;
puts(" Additions Test");
random_bytes((int *)&v5, 10, 1u);
random_bytes((int *)&v3, 10, 1u);
v0 = 0LL;
v1 = 0;
do
{
if ( (unsigned __int8)Rijndael_Add(*((unsigned __int8 *)&v5 + v0), *((unsigned __int8 *)&v3 + v0)) == (*((_BYTE *)&v3 + v0) ^ *((_BYTE *)&v5 + v0)) )
{
printf("[%d]:\tSUCCESS\n", (unsigned int)v0);
}
else
{
printf("[%d]:\tERROR\n", (unsigned int)v0);
++v1;
}
++v0;
}
while ( v0 != 10 );
return v1;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rbx
unsigned int v1; // ebp
__int64 v3; // [rsp+Ch] [rbp-2Ch] BYREF
__int16 v4; // [rsp+14h] [rbp-24h]
__int64 v5; // [rsp+16h] [rbp-22h] BYREF
__int16 v6; // [rsp+1Eh] [rbp-1Ah]

v5 = 0LL;
v6 = 0;
v3 = 0LL;
v4 = 0;
puts(" Additions Test");
func7((int *)&v5, 10, 1u);
func7((int *)&v3, 10, 1u);
v0 = 0LL;
v1 = 0;
do
{
if ( (unsigned __int8)func27(*((unsigned __int8 *)&v5 + v0), *((unsigned __int8 *)&v3 + v0)) == (*((_BYTE *)&v3 + v0) ^ *((_BYTE *)&v5 + v0)) )
{
printf("[%d]:\tSUCCESS\n", (unsigned int)v0);
}
else
{
printf("[%d]:\tERROR\n", (unsigned int)v0);
++v1;
}
++v0;
}
while ( v0 != 10 );
return v1;
}

original_code:
int addition_test( void )
{
    uint8_t a[10]={0};
    uint8_t b[10]={0};
    uint8_t c,d;
    int32_t k=0;
    int errors=0;
    printf("  Additions Test\n");
    random_bytes(a,10,1);
    random_bytes(b,10,1);
    for(k=0;k<10;++k)
    {
        c=Rijndael_Add(a[k],b[k]);
        d=a[k]^b[k];
        if(d!=c)
        {
            printf("[%d]:\tERROR\n",k);
            errors++;
        }
        else
            printf("[%d]:\tSUCCESS\n",k);
    }
    return errors;
}

canonical_original_code:
int addition_test()
{
    unsigned char a[10] = {0};
    unsigned char b[10] = {0};
    unsigned char c; unsigned char d;
    int k = 0;
    int errors = 0;
    printf("  Additions Test\n");
    random_bytes(a,10,1);
    random_bytes(b,10,1);
    for(k=0;k<10;++k)
    {
        c=Rijndael_Add(a[k],b[k]);
        d=a[k]^b[k];
        if(d!=c)
        {
            printf("[%d]:\tERROR\n",k);
            errors++;
        }
        else
            printf("[%d]:\tSUCCESS\n",k);
    }
    return errors;
}

variable_types:
a
unsigned char [10]

variable_types:
b
unsigned char [10]

variable_types:
d
unsigned char


decompiled_code:
__int64 multiplication_test()
{
__int64 v0; // rbx
unsigned int v1; // er12
unsigned __int8 v2; // bp
unsigned __int8 v3; // al
__int64 v5; // [rsp+Ch] [rbp-2Ch] BYREF
__int16 v6; // [rsp+14h] [rbp-24h]
__int64 v7; // [rsp+16h] [rbp-22h] BYREF
__int16 v8; // [rsp+1Eh] [rbp-1Ah]

v7 = 0LL;
v8 = 0;
v5 = 0LL;
v6 = 0;
puts(" Multiplication Test");
random_bytes((int *)&v7, 10, 1u);
random_bytes((int *)&v5, 10, 2u);
v0 = 0LL;
v1 = 0;
do
{
v2 = Rijndael_Mul(*((unsigned __int8 *)&v7 + v0), *((unsigned __int8 *)&v5 + v0));
v3 = Long_Mul2(*((unsigned __int8 *)&v7 + v0), *((unsigned __int8 *)&v5 + v0));
if ( v2 == v3 )
{
printf("[%d]:\tSUCCESS\n", (unsigned int)v0);
}
else
{
printf(
"[%d]:\tERROR (a=%02x,b=%02x,c=%02x,e=%02x)\n",
(unsigned int)v0,
*((unsigned __int8 *)&v7 + v0),
*((unsigned __int8 *)&v5 + v0),
v2,
v3);
++v1;
}
++v0;
}
while ( v0 != 10 );
return v1;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v0; // rbx
unsigned int v1; // er12
unsigned __int8 v2; // bp
unsigned __int8 v3; // al
__int64 v5; // [rsp+Ch] [rbp-2Ch] BYREF
__int16 v6; // [rsp+14h] [rbp-24h]
__int64 v7; // [rsp+16h] [rbp-22h] BYREF
__int16 v8; // [rsp+1Eh] [rbp-1Ah]

v7 = 0LL;
v8 = 0;
v5 = 0LL;
v6 = 0;
puts(" Multiplication Test");
func7((int *)&v7, 10, 1u);
func7((int *)&v5, 10, 2u);
v0 = 0LL;
v1 = 0;
do
{
v2 = func29(*((unsigned __int8 *)&v7 + v0), *((unsigned __int8 *)&v5 + v0));
v3 = func31(*((unsigned __int8 *)&v7 + v0), *((unsigned __int8 *)&v5 + v0));
if ( v2 == v3 )
{
printf("[%d]:\tSUCCESS\n", (unsigned int)v0);
}
else
{
printf(
"[%d]:\tERROR (a=%02x,b=%02x,c=%02x,e=%02x)\n",
(unsigned int)v0,
*((unsigned __int8 *)&v7 + v0),
*((unsigned __int8 *)&v5 + v0),
v2,
v3);
++v1;
}
++v0;
}
while ( v0 != 10 );
return v1;
}

original_code:
int multiplication_test( void )
{
    uint8_t a[10]={0};
    uint8_t b[10]={0};
    uint8_t c,d,e;
    int32_t k=0;
    int errors=0;
    printf("  Multiplication Test\n");
    random_bytes(a,10,1);
    random_bytes(b,10,2);
    for(k=0;k<10;++k)
    {
        c=Rijndael_Mul(a[k],b[k]);
        e=Long_Mul2(a[k],b[k]);
        if(e!=c)
        {
            printf("[%d]:\tERROR (a=%02x,b=%02x,c=%02x,e=%02x)\n",k,a[k],b[k],c,e);
            errors++;
        }
        else
            printf("[%d]:\tSUCCESS\n",k);
    }
    return errors;
}

canonical_original_code:
int multiplication_test()
{
    unsigned char a[10] = {0};
    unsigned char b[10] = {0};
    unsigned char c; unsigned char d; unsigned char e;
    int k = 0;
    int errors = 0;
    printf("  Multiplication Test\n");
    random_bytes(a,10,1);
    random_bytes(b,10,2);
    for(k=0;k<10;++k)
    {
        c=Rijndael_Mul(a[k],b[k]);
        e=Long_Mul2(a[k],b[k]);
        if(e!=c)
        {
            printf("[%d]:\tERROR (a=%02x,b=%02x,c=%02x,e=%02x)\n",k,a[k],b[k],c,e);
            errors++;
        }
        else
            printf("[%d]:\tSUCCESS\n",k);
    }
    return errors;
}

variable_types:
e
unsigned char


TestField

decompiled_code:
int TestField()
{
int v0; // ebx
int v1; // ebx
int v2; // eax

puts("\t*** Starting first test ***");
puts("Testing field arithmetic\n");
v0 = inversion_test();
v1 = addition_test() + v0;
v2 = multiplication_test();
return printf("Number of test errors: %d\n", (unsigned int)(v1 + v2));
}

canonical_decompiled_code:
int func11()
{
int v0; // ebx
int v1; // ebx
int v2; // eax

puts("\t*** Starting first test ***");
puts("Testing field arithmetic\n");
v0 = func8();
v1 = func9() + v0;
v2 = func10();
return printf("Number of test errors: %d\n", (unsigned int)(v1 + v2));
}

original_code:
void TestField( void )
{
    int errors=0;
    printf("\t*** Starting first test ***\n");
    printf("Testing field arithmetic\n\n");
    errors += inversion_test();
    errors += addition_test();
    errors += multiplication_test();
    printf("Number of test errors: %d\n",errors);
}

canonical_original_code:
void TestField()
{
    int errors = 0;
    printf("\t*** Starting first test ***\n");
    printf("Testing field arithmetic\n\n");
    errors += inversion_test();
    errors += addition_test();
    errors += multiplication_test();
    printf("Number of test errors: %d\n",errors);
}


decompiled_code:
__int64 WritePowers_2()
{
int v0; // ebp
__int64 result; // rax
unsigned int v2; // ebx

v0 = 0;
LOBYTE(result) = 1;
do
{
v2 = (unsigned __int8)result;
printf("%02x, ", (unsigned __int8)result);
if ( (++v0 & 7) == 0 )
putchar(10);
result = Rijndael_Mul(v2, 2LL);
}
while ( (_BYTE)result != 1 && v0 != 256 );
return result;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // ebp
__int64 result; // rax
unsigned int v2; // ebx

v0 = 0;
LOBYTE(result) = 1;
do
{
v2 = (unsigned __int8)result;
printf("%02x, ", (unsigned __int8)result);
if ( (++v0 & 7) == 0 )
putchar(10);
result = func29(v2, 2LL);
}
while ( (_BYTE)result != 1 && v0 != 256 );
return result;
}

original_code:
void WritePowers_2( void )
{
    uint8_t el=1,g=2;
    int32_t k;
    for (k=0; k<256; ++k)
    {
        printf("%02x, ",el);
        if ( 0==((k+1)%8) )
            printf("\n");
        el = Rijndael_Mul(el,g);
        if (1==el)
            break;
    }
}

canonical_original_code:
void WritePowers_2()
{
    unsigned char el = 1; unsigned char g = 2;
    int k;
    for (k=0; k<256; ++k)
    {
        printf("%02x, ",el);
        if ( 0==((k+1)%8) )
            printf("\n");
        el = Rijndael_Mul(el,g);
        if (1==el)
            break;
    }
}

variable_types:
el
unsigned char

variable_types:
g
unsigned char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
WritePowers_2(argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func12(argc, argv, envp);
return 0;
}

original_code:
int main ( int argc, char ** argv )
{
    WritePowers_2();
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    WritePowers_2();
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 rijndael_encrypt()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
return 0LL;
}

original_code:
int32_t rijndael_encrypt( uint8_t * out, uint8_t * in, uint8_t * key, int32_t keylen )
{
    return 0;
}

canonical_original_code:
int rijndael_encrypt(unsigned char *out, unsigned char *in, unsigned char *key, int keylen)
{
    return 0;
}

variable_types:
out
unsigned char *

variable_types:
in
unsigned char *

variable_types:
key
unsigned char *

variable_types: keylen int


decompiled_code:
__int64 rijndael_decrypt()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
return 0LL;
}

original_code:
int32_t rijndael_decrypt( uint8_t * out, uint8_t * in, uint8_t * key, int32_t keylen )
{
    return 0;
}

canonical_original_code:
int rijndael_decrypt(unsigned char *out, unsigned char *in, unsigned char *key, int keylen)
{
    return 0;
}


AddRoundKey

decompiled_code:
void AddRoundKey()
{
;
}

canonical_decompiled_code:
void func15()
{
;
}

original_code:
void AddRoundKey( void )
{
    return;
}

canonical_original_code:
void AddRoundKey()
{
    return;
}


MixColumns

decompiled_code:
void MixColumns()
{
;
}

canonical_decompiled_code:
void func16()
{
;
}

original_code:
void MixColumns( void )
{
    return;
}

canonical_original_code:
void MixColumns()
{
    return;
}


RotWord

decompiled_code:
__int64 __fastcall RotWord(unsigned int a1)
{
return a1 & 0xFF000000 ^ (a1 >> 8);
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int a1)
{
return a1 & 0xFF000000 ^ (a1 >> 8);
}

original_code:
uint32_t RotWord( uint32_t w)
{
    uint32_t r, tmp;
    tmp = w & (0xff<<24);
    r = (w>>8) & 0xffffff;
    r ^= tmp;
    return r;
}

canonical_original_code:
unsigned int RotWord(unsigned int w)
{
    unsigned int r; unsigned int tmp;
    tmp = w & (0xff<<24);
    r = (w>>8) & 0xffffff;
    r ^= tmp;
    return r;
}

variable_types:
w
unsigned int

variable_types:
r
unsigned int

variable_types:
tmp
unsigned int


ShiftRows

decompiled_code:
void ShiftRows()
{
;
}

canonical_decompiled_code:
void func18()
{
;
}

original_code:
void ShiftRows( void )
{
    return;
}

canonical_original_code:
void ShiftRows()
{
    return;
}


SubBytes

decompiled_code:
void SubBytes()
{
;
}

canonical_decompiled_code:
void func19()
{
;
}

original_code:
void SubBytes( void )
{
    return;
}

canonical_original_code:
void SubBytes()
{
    return;
}


SubWord

decompiled_code:
__int64 __fastcall SubWord(int a1)
{
__int64 v1; // rax
unsigned int v2; // esi
int v4; // [rsp+0h] [rbp-4h]

v4 = a1;
v1 = 0LL;
v2 = 0;
do
{
v2 ^= (unsigned __int8)s_box[*((unsigned __int8 *)&v4 + v1)] << (8 * v1);
++v1;
}
while ( v1 != 4 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func20(int a1)
{
__int64 v1; // rax
unsigned int v2; // esi
int v4; // [rsp+0h] [rbp-4h]

v4 = a1;
v1 = 0LL;
v2 = 0;
do
{
v2 ^= (unsigned __int8)s_box[*((unsigned __int8 *)&v4 + v1)] << (8 * v1);
++v1;
}
while ( v1 != 4 );
return v2;
}

original_code:
uint32_t SubWord( uint32_t w )
{
    uint32_t r;
    uint8_t * arr;
    uint32_t tmp;
    int32_t shift, k;
    r=0;
    arr = (uint8_t*) &w;
    for ( k=0; k<4; ++k )
    {
        shift = 8*k;
        tmp = (uint32_t) s_box[arr[k]];
        r^= (tmp<<shift);
    }
    return r;
}

canonical_original_code:
unsigned int SubWord(unsigned int w)
{
    unsigned int r;
    unsigned char *arr;
    unsigned int tmp;
    int shift; int k;
    r=0;
    arr = (unsigned char *) &w;
    for ( k=0; k<4; ++k )
    {
        shift = 8*k;
        tmp = (unsigned int) s_box[arr[k]];
        r^= (tmp<<shift);
    }
    return r;
}

variable_types:
arr
unsigned char *

variable_types: shift int

variable_types: k int


InvMixColumns

decompiled_code:
void InvMixColumns()
{
;
}

canonical_decompiled_code:
void func21()
{
;
}

original_code:
void InvMixColumns( void )
{
    return;
}

canonical_original_code:
void InvMixColumns()
{
    return;
}


InvShiftRows

decompiled_code:
void InvShiftRows()
{
;
}

canonical_decompiled_code:
void func22()
{
;
}

original_code:
void InvShiftRows( void )
{
    return;
}

canonical_original_code:
void InvShiftRows()
{
    return;
}


InvSubBytes

decompiled_code:
void InvSubBytes()
{
;
}

canonical_decompiled_code:
void func23()
{
;
}

original_code:
void InvSubBytes( void )
{
    return;
}

canonical_original_code:
void InvSubBytes()
{
    return;
}


decompiled_code:
void create_word()
{
;
}

canonical_decompiled_code:
void func24()
{
;
}

original_code:
uint32_t create_word( uint8_t * key )
{
    uint32_t word = 0, tmp;
    int32_t k, shift;
    for (k=0; k<4; ++k)
    {
        shift = k*8;
        tmp = ((uint32_t) key[k]) & 0xff;
        word ^= (tmp<<shift);
    }
}

canonical_original_code:
unsigned int create_word(unsigned char *key)
{
    unsigned int word = 0; unsigned int tmp;
    int k; int shift;
    for (k=0; k<4; ++k)
    {
        shift = k*8;
        tmp = ((unsigned int) key[k]) & 0xff;
        word ^= (tmp<<shift);
    }
}

variable_types:
word
unsigned int


KeyExpansion

decompiled_code:
void KeyExpansion()
{
;
}

canonical_decompiled_code:
void func25()
{
;
}

original_code:
void KeyExpansion( uint8_t * key, uint32_t * w)
{
    uint32_t temp;
    int32_t i;
    for (i=0; i<Nk; ++i)
    {
        w[i] = create_word(&(key[i*4]));
    }
    for (i=Nk; i<Nb*(Nr+1); i++ )
    {
        temp=w[i-1];
        if (0==(i%Nk))
        {
            temp = SubWord(RotWord(temp)) ^ Rcon[i/Nk];
        }
        else if ( (6<Nk) && (4==(i%Nk)) )
        {
            temp = SubWord(temp);
        }
        w[i] = w[i-Nk]^temp;
    }
    return;
}

canonical_original_code:
void KeyExpansion(unsigned char *key, unsigned int *w)
{
    unsigned int temp;
    int i;
    for (i=0; i<Nk; ++i)
    {
        w[i] = create_word(&(key[i*4]));
    }
    for (i=Nk; i<Nb*(Nr+1); i++ )
    {
        temp=w[i-1];
        if (0==(i%Nk))
        {
            temp = SubWord(RotWord(temp)) ^ Rcon[i/Nk];
        }
        else if ( (6<Nk) && (4==(i%Nk)) )
        {
            temp = SubWord(temp);
        }
        w[i] = w[i-Nk]^temp;
    }
    return;
}

variable_types:
w
unsigned int *

variable_types:
temp
unsigned int

variable_types: i int


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

result = a1;
if ( (_BYTE)a1 )
{
if ( (_BYTE)a1 != 1 )
result = (unsigned __int8)RijndaelByPower[(unsigned __int8)~RijndaelByValue[(unsigned __int8)a1]];
}
return result;
}

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

result = a1;
if ( (_BYTE)a1 )
{
if ( (_BYTE)a1 != 1 )
result = (unsigned __int8)RijndaelByPower[(unsigned __int8)~RijndaelByValue[(unsigned __int8)a1]];
}
return result;
}

original_code:
uint8_t Rijndael_Inv( uint8_t a )
{
    uint8_t power = RijndaelByValue[a];
    if ( 0==a )
        return 0;
    if ( 1==a )
        return 1;
    power = 255 - power;
    return RijndaelByPower[power];
}

canonical_original_code:
unsigned char Rijndael_Inv(unsigned char a)
{
    unsigned char power = RijndaelByValue[a];
    if ( 0==a )
        return 0;
    if ( 1==a )
        return 1;
    power = 255 - power;
    return RijndaelByPower[power];
}

variable_types:
a
unsigned char

variable_types:
power
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall Rijndael_Add(int a1, unsigned int a2)
{
return a1 ^ a2;
}

canonical_decompiled_code:
__int64 __fastcall func27(int a1, unsigned int a2)
{
return a1 ^ a2;
}

original_code:
uint8_t Rijndael_Add( uint8_t a, uint8_t b )
{
    return (a^b);
}

canonical_original_code:
unsigned char Rijndael_Add(unsigned char a, unsigned char b)
{
    return (a^b);
}

variable_types:
b
unsigned char


decompiled_code:
__int64 __fastcall Rijndael_Sub(int a1, unsigned int a2)
{
return a1 ^ a2;
}

canonical_decompiled_code:
__int64 __fastcall func28(int a1, unsigned int a2)
{
return a1 ^ a2;
}

original_code:
uint8_t Rijndael_Sub( uint8_t a, uint8_t b )
{
    return (a^b);
}

canonical_original_code:
unsigned char Rijndael_Sub(unsigned char a, unsigned char b)
{
    return (a^b);
}


decompiled_code:
__int64 __fastcall Rijndael_Mul(unsigned __int8 a1, unsigned __int8 a2)
{
int v2; // edx

if ( !a1 || !a2 )
return 0LL;
v2 = (unsigned __int8)RijndaelByValue[a2] + (unsigned __int8)RijndaelByValue[a1];
return (unsigned __int8)RijndaelByPower[v2 - 255 * ((int)((unsigned __int64)(2155905153LL * v2) >> 32) >> 7)];
}

canonical_decompiled_code:
__int64 __fastcall func29(unsigned __int8 a1, unsigned __int8 a2)
{
int v2; // edx

if ( !a1 || !a2 )
return 0LL;
v2 = (unsigned __int8)RijndaelByValue[a2] + (unsigned __int8)RijndaelByValue[a1];
return (unsigned __int8)RijndaelByPower[v2 - 255 * ((int)((unsigned __int64)(2155905153LL * v2) >> 32) >> 7)];
}

original_code:
uint8_t Rijndael_Mul( uint8_t a, uint8_t b )
{
    uint8_t power = (RijndaelByValue[a] + RijndaelByValue[b]) % 0xff;
    if ( a && b )
        return RijndaelByPower[power];
    else
        return 0;
}

canonical_original_code:
unsigned char Rijndael_Mul(unsigned char a, unsigned char b)
{
    unsigned char power = (RijndaelByValue[a] + RijndaelByValue[b]) % 0xff;
    if ( a && b )
        return RijndaelByPower[power];
    else
        return 0;
}


decompiled_code:
__int64 __fastcall Rijndael_Div(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned __int8 v2; // al

v2 = Rijndael_Inv(a2);
return Rijndael_Mul(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func30(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned __int8 v2; // al

v2 = func26(a2);
return func29(a1, v2);
}

original_code:
uint8_t Rijndael_Div( uint8_t a, uint8_t b )
{
    return Rijndael_Mul(a,Rijndael_Inv(b));
}

canonical_original_code:
unsigned char Rijndael_Div(unsigned char a, unsigned char b)
{
    return Rijndael_Mul(a,Rijndael_Inv(b));
}


canonical_original_code:
unsigned char Long_Mul2(unsigned char a, unsigned char b)
{
    char rem[8] = {0};
    int k;
    unsigned int aa; unsigned int bb; unsigned int cc;
    unsigned char c;
    rem[0] = 0x1b;
    for (k=1; k<8; ++k)
    {
        rem[k] = (rem[k-1]<<1);
        if (rem[k-1]&0x80)
            rem[k] ^= 0x1b;
    }
    aa = (unsigned int)a;
    bb = (unsigned int)b;
    cc=0;
    for (k=0; k<8; ++k)
    {
        if (aa&1)
            cc= (cc^bb);
        aa = (aa>>1);
        bb = (bb<<1);
    }
    c = (unsigned char) (cc&0xff);
    cc = (cc>>8);
    for (k=0; k<8; ++k)
    {
        if(cc&1)
            c ^= rem[k];
        cc = (cc>>1);
    }
    return c;
}

variable_types:
rem
char [8]

variable_types:
aa
unsigned int

variable_types:
bb
unsigned int

variable_types:
cc
unsigned int

variable_types:
c
unsigned char


main

repo: koxuipang/RPILcd

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm1_8
int v4; // ebp
unsigned int v5; // ebx
unsigned int v6; // ebx
int v7; // ebp
unsigned int v8; // ebx
int v9; // ebp
unsigned int v10; // ebx
int v11; // ebp
int n; // ebx
int ii; // ebx
int jj; // ebx
int kk; // ebx
int v16; // eax
unsigned int i; // ebx
unsigned int j; // ebx
int k; // ebx
double v20; // xmm0_8
int l; // ebx
double v22; // xmm0_8
int m; // ebx
double v24; // xmm0_8
unsigned int v25; // ebx
unsigned int v26; // eax
int v28[330]; // [rsp+0h] [rbp-528h]

wiringPiSetup(argc, argv, envp);
SetPinNU(0LL, 1LL, 2LL, 3LL, 4LL, 5LL, 6LL, 7LL, 8LL, 10LL, 9LL, 11LL, 15LL, 16LL, 14LL, 12LL, 13LL);
SetLCDSize(28LL);
Touch_Init();
setFont(8LL, 12LL);
setColor(2016LL);
setBackColor(63488LL);
puts("Init is ok!");
LABEL_51:
clrScr();
setColorRGB(255LL, 0LL, 0LL);
fillRect(0LL, 0LL, 319LL, 13LL);
setColorRGB(64LL, 64LL, 64LL);
fillRect(0LL, 226LL, 319LL, 239LL);
setColorRGB(255LL, 255LL, 255LL);
setBackColorRGB(255LL, 0LL, 0LL);
print("* Universal Color TFT Display Library *", 9998LL, 1LL, 0LL);
setBackColorRGB(64LL, 64LL, 64LL);
setColorRGB(255LL, 255LL, 0LL);
print("<http://electronics.henningkarlsen.com>", 9998LL, 227LL, 0LL);
setColorRGB(0LL, 0LL, 255LL);
drawRect(0LL, 14LL, 319LL, 225LL);
setColorRGB(0LL, 0LL, 255LL);
setBackColorRGB(0LL, 0LL, 0LL);
drawLine(159LL, 15LL, 159LL, 224LL);
drawLine(1LL, 119LL, 318LL, 119LL);
for ( i = 9; i != 319; i += 10 )
drawLine(i, 117LL, i, 121LL);
for ( j = 19; j != 229; j += 10 )
drawLine(157LL, j, 161LL, j);
setColorRGB(0LL, 255LL, 255LL);
print("Sin", 5LL, 15LL, 0LL);
for ( k = 1; k != 318; ++k )
{
v20 = sin((double)k * 1.13 * 3.14 / 180.0);
drawPixel((unsigned int)k, (unsigned int)(int)(v20 * 95.0 + 119.0));
}
setColorRGB(255LL, 0LL, 0LL);
print("Cos", 5LL, 27LL, 0LL);
for ( l = 1; l != 318; ++l )
{
v22 = cos((double)l * 1.13 * 3.14 / 180.0);
drawPixel((unsigned int)l, (unsigned int)(int)(v22 * 95.0 + 119.0));
}
setColorRGB(255LL, 255LL, 0LL);
print("Tan", 5LL, 39LL, 0LL);
for ( m = 1; m != 318; ++m )
{
v24 = tan((double)m * 1.13 * 3.14 / 180.0);
drawPixel((unsigned int)m, (unsigned int)(int)(v24 + 119.0));
}
delay(2000LL);
setColorRGB(0LL, 0LL, 0LL);
fillRect(1LL, 15LL, 318LL, 224LL);
setColorRGB(0LL, 0LL, 255LL);
setBackColorRGB(0LL, 0LL, 0LL);
drawLine(159LL, 15LL, 159LL, 224LL);
drawLine(1LL, 119LL, 318LL, 119LL);
v4 = 1;
v5 = 1;
while ( 1 )
{
if ( ++v5 == 319 )
{
v5 = 1;
if ( v4 <= 319 )
goto LABEL_4;
}
else
{
if ( v4 <= 319 )
goto LABEL_4;
if ( v5 == 159 )
goto LABEL_2;
}
if ( v28[v5 - 1] != 119 )
{
setColorRGB(0LL, 0LL, 0LL);
goto LABEL_3;
}
LABEL_2:
setColorRGB(0LL, 0LL, 255LL);
LABEL_3:
drawPixel(v5, (unsigned int)v28[v5 - 1]);
LABEL_4:
setColorRGB(0LL, 255LL, 255LL);
v3 = sin((double)v4 * 1.1 * 3.14 / 180.0);
drawPixel(v5, (unsigned int)(int)((double)(v4 / -100 + 90) * v3 + 119.0));
v28[v5 - 1] = (int)((double)(v4 / -100 + 90) * v3 + 119.0);
if ( ++v4 == 6360 )
{
delay(2000LL);
setColorRGB(0LL, 0LL, 0LL);
fillRect(1LL, 15LL, 318LL, 224LL);
v6 = 90;
v7 = 2;
while ( 1 )
{
switch ( v7 )
{
case 2:
setColorRGB(255LL, 0LL, 255LL);
goto LABEL_12;
case 3:
setColorRGB(255LL, 0LL, 0LL);
goto LABEL_12;
case 4:
setColorRGB(0LL, 255LL, 0LL);
goto LABEL_12;
case 5:
setColorRGB(0LL, 0LL, 255LL);
LABEL_12:
fillRect(v6, v6 - 40, v6 + 60, v6 + 20);
goto LABEL_13;
case 6:
setColorRGB(255LL, 255LL, 0LL);
fillRect(170LL, 130LL, 230LL, 190LL);
goto LABEL_19;
default:
fillRect(v6, v6 - 40, v6 + 60, v6 + 20);
if ( v7 > 5 )
{
LABEL_19:
delay(2000LL);
setColorRGB(0LL, 0LL, 0LL);
fillRect(1LL, 15LL, 318LL, 224LL);
v8 = 170;
v9 = 2;
while ( 1 )
{
switch ( v9 )
{
case 2:
setColorRGB(255LL, 0LL, 255LL);
goto LABEL_23;
case 3:
setColorRGB(255LL, 0LL, 0LL);
goto LABEL_23;
case 4:
setColorRGB(0LL, 255LL, 0LL);
goto LABEL_23;
case 5:
setColorRGB(0LL, 0LL, 255LL);
LABEL_23:
fillRoundRect(v8, 220 - v8, v8 + 60, 280 - v8);
goto LABEL_24;
case 6:
setColorRGB(255LL, 255LL, 0LL);
fillRoundRect(90LL, 130LL, 150LL, 190LL);
goto LABEL_30;
default:
fillRoundRect(v8, 220 - v8, v8 + 60, 280 - v8);
if ( v9 > 5 )
{
LABEL_30:
delay(2000LL);
setColorRGB(0LL, 0LL, 0LL);
fillRect(1LL, 15LL, 318LL, 224LL);
v10 = 120;
v11 = 2;
while ( 1 )
{
switch ( v11 )
{
case 2:
setColorRGB(255LL, 0LL, 255LL);
goto LABEL_34;
case 3:
setColorRGB(255LL, 0LL, 0LL);
goto LABEL_34;
case 4:
setColorRGB(0LL, 255LL, 0LL);
goto LABEL_34;
case 5:
setColorRGB(0LL, 0LL, 255LL);
LABEL_34:
fillCircle(v10, v10 - 40, 30LL);
goto LABEL_35;
case 6:
setColorRGB(255LL, 255LL, 0LL);
fillCircle(200LL, 160LL, 30LL);
goto LABEL_41;
default:
fillCircle(v10, v10 - 40, 30LL);
if ( v11 > 5 )
{
LABEL_41:
delay(2000LL);
setColorRGB(0LL, 0LL, 0LL);
fillRect(1LL, 15LL, 318LL, 224LL);
setColorRGB(255LL, 0LL, 0LL);
for ( n = 15; n != 225; n += 5 )
drawLine(1LL, (unsigned int)n, (unsigned int)(int)((double)n * 1.44 - 10.0), 224LL);
setColorRGB(255LL, 0LL, 0LL);
for ( ii = 224; ii != 14; ii -= 5 )
drawLine(318LL, (unsigned int)ii, (unsigned int)(int)((double)ii * 1.44 - 11.0), 15LL);
setColorRGB(0LL, 255LL, 255LL);
for ( jj = 224; jj != 14; jj -= 5 )
drawLine(1LL, (unsigned int)jj, (unsigned int)(int)(331.0 - (double)jj * 1.44), 15LL);
setColorRGB(0LL, 255LL, 255LL);
for ( kk = 15; kk != 225; kk += 5 )
drawLine(318LL, (unsigned int)kk, (unsigned int)(int)(330.0 - (double)kk * 1.44), 224LL);
delay(2000LL);
setColorRGB(0LL, 0LL, 0LL);
fillRect(1LL, 15LL, 318LL, 224LL);
fillScrRGB(0LL, 0LL, 255LL);
setColorRGB(255LL, 0LL, 0LL);
fillRoundRect(80LL, 70LL, 239LL, 169LL);
setColorRGB(255LL, 255LL, 255LL);
setBackColorRGB(255LL, 0LL, 0LL);
print("That's it!", 9998LL, 93LL, 0LL);
print("Restarting in a", 9998LL, 119LL, 0LL);
print("few seconds...", 9998LL, 142LL, 0LL);
setColorRGB(0LL, 255LL, 0LL);
setBackColorRGB(0LL, 0LL, 255LL);
print("Runtime: (msecs)", 9998LL, 210LL, 0LL);
v16 = millis();
printNumI(v16, 9998LL, 225LL, 0LL, 0LL);
delay(2000LL);
if ( (unsigned __int8)Touch_DataAvailable() )
{
Touch_Read();
v25 = Touch_GetX();
v26 = Touch_GetY();
printf("%d,%d\n", v25, v26);
}
goto LABEL_51;
}
LABEL_35:
++v11;
v10 += 20;
break;
}
}
}
LABEL_24:
++v9;
v8 -= 20;
break;
}
}
}
LABEL_13:
++v7;
v6 += 20;
break;
}
}
}
}
}

variable_types:
buf
int [318]

variable_types: x int

variable_types: y int

variable_types: r int


usage

decompiled_code:
void __noreturn usage()
{
fprintf(stderr, "Usage: %s <FILE/DIRECTORY> [PARAMETER]\n", (const char *)progname);
fwrite(" PARAMETER may be any combination of the following:\n", 1uLL, 0x3AuLL, stderr);
fprintf(stderr, " %-8s <username/uid> match given user's files\n", "-user");
fprintf(stderr, " %-8s <expression> match filenames that match given expression\n", "-name");
fprintf(stderr, " %-8s <expression> match filenames that match given path and file name\n", "-path");
fprintf(stderr, " %-8s <b/c/d/p/f/l/s> match files of given type\n", "-type");
fprintf(stderr, " %-8s match files owned by a unknown uid according to /etc/passwd\n", "-nouser");
fprintf(stderr, " %-8s prints detailed information about matching files\n", "-ls");
fprintf(
stderr,
" %-8s prints filename explicitly (this is the default behaviour unless \"%s\" specified)\n",
"-print",
"-ls");
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fprintf(stderr, "Usage: %s <FILE/DIRECTORY> [PARAMETER]\n", (const char *)progname);
fwrite(" PARAMETER may be any combination of the following:\n", 1uLL, 0x3AuLL, stderr);
fprintf(stderr, " %-8s <username/uid> match given user's files\n", "-user");
fprintf(stderr, " %-8s <expression> match filenames that match given expression\n", "-name");
fprintf(stderr, " %-8s <expression> match filenames that match given path and file name\n", "-path");
fprintf(stderr, " %-8s <b/c/d/p/f/l/s> match files of given type\n", "-type");
fprintf(stderr, " %-8s match files owned by a unknown uid according to /etc/passwd\n", "-nouser");
fprintf(stderr, " %-8s prints detailed information about matching files\n", "-ls");
fprintf(
stderr,
" %-8s prints filename explicitly (this is the default behaviour unless \"%s\" specified)\n",
"-print",
"-ls");
exit(1);
}

original_code:
void usage(void) {
 fprintf(stderr, "Usage: %s <FILE/DIRECTORY> [PARAMETER]\n", progname);
 fprintf(stderr, "       PARAMETER may be any combination of the following:\n");
 fprintf(stderr, "       %-8s <username/uid> match given user's files\n", "-user");
 fprintf(stderr, "       %-8s <expression> match filenames that match given expression\n", "-name");
 fprintf(stderr, "       %-8s <expression> match filenames that match given path and file name\n", "-path");
 fprintf(stderr, "       %-8s <b/c/d/p/f/l/s> match files of given type\n", "-type");
 fprintf(stderr, "       %-8s match files owned by a unknown uid according to /etc/passwd\n", "-nouser");
 fprintf(stderr, "       %-8s prints detailed information about matching files\n", "-ls");
 fprintf(stderr, "       %-8s prints filename explicitly (this is the default behaviour unless \"%s\" specified)\n", "-print", "-ls");
 exit(1);
}

canonical_original_code:
void usage() {
 fprintf(stderr, "Usage: %s <FILE/DIRECTORY> [PARAMETER]\n", progname);
 fprintf(stderr, "       PARAMETER may be any combination of the following:\n");
 fprintf(stderr, "       %-8s <username/uid> match given user's files\n", "-user");
 fprintf(stderr, "       %-8s <expression> match filenames that match given expression\n", "-name");
 fprintf(stderr, "       %-8s <expression> match filenames that match given path and file name\n", "-path");
 fprintf(stderr, "       %-8s <b/c/d/p/f/l/s> match files of given type\n", "-type");
 fprintf(stderr, "       %-8s match files owned by a unknown uid according to /etc/passwd\n", "-nouser");
 fprintf(stderr, "       %-8s prints detailed information about matching files\n", "-ls");
 fprintf(stderr, "       %-8s prints filename explicitly (this is the default behaviour unless \"%s\" specified)\n", "-print", "-ls");
 exit(1);
}


variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *

variable_types: mode int

variable_types: retval char

return_type: char

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


ls

original_code:
void ls(const struct stat *file, const char *file_name) {
 char permissions[10] = {0};
 char timestring[20] = {0};
 char tmp[7] = {0};
 char *linkdestination = ((void *)0);
 int linkbytesread = 0;
 int linklength = 0;
 char filetype = 0;
 struct passwd *pwd = ((void *)0);
 struct group *grp = ((void *)0);
 struct tm *ptime = ((void *)0);
 filetype = get_file_type(file, 0);
 memset(permissions, '-', 9 );
 ptime = localtime(&file->st_mtim.tv_sec);
 strftime(timestring,9,"%b", ptime);
 strftime(tmp,4," %d", ptime);
 if(tmp[1] == '0') {
  tmp[1] = ' ';
 }
 strcat(timestring, tmp);
 strftime(tmp,7," %H:%M", ptime);
 strcat(timestring, tmp);
 if (file->st_mode & 0400) { permissions[0] = 'r'; };
 if (file->st_mode & 0200) { permissions[1] = 'w'; };
        if (file->st_mode & 04000) {
  permissions[2] = (file->st_mode & 0100) ? 's' : 'S';
 }
 else if (file->st_mode & 0100) { permissions[2] = 'x'; };
 if (file->st_mode & (0400 >> 3)) { permissions[3] = 'r'; };
 if (file->st_mode & (0200 >> 3)) { permissions[4] = 'w'; };
        if (file->st_mode & 02000) {
  permissions[5] = (file->st_mode & (0100 >> 3)) ? 's' : 'S';
 }
 else if (file->st_mode & (0100 >> 3)) { permissions[5] = 'x'; };
 if (file->st_mode & ((0400 >> 3) >> 3)) { permissions[6] = 'r'; };
 if (file->st_mode & ((0200 >> 3) >> 3)) { permissions[7] = 'w'; };
        if (file->st_mode & 01000) {
  permissions[8] = (file->st_mode & ((0100 >> 3) >> 3)) ? 't' : 'T';
 }
 else if (file->st_mode & ((0100 >> 3) >> 3)) { permissions[8] = 'x'; };
 if ( fprintf(stdout, "%6lu %4lu %c%s %3lu", file->st_ino, (file->st_blocks / 2), filetype, permissions, (long) file->st_nlink) < 0 ) {
  fprintf(stderr, "%s: writing to stdout failed!\n", progname);
 }
 if ((pwd = getpwuid(file->st_uid)) == ((void *)0)) {
  if ( fprintf(stdout, " %-8d", file->st_uid) < 0 ) {
   fprintf(stderr, "%s: writing to stdout failed!\n", progname);
  }
 }
 else {
  if ( fprintf(stdout, " %-8s", pwd->pw_name) < 0 ) {
   fprintf(stderr, "%s: writing to stdout failed!\n", progname);
  }
  pwd = ((void *)0);
 }
        if ((grp = getgrgid(file->st_gid)) == ((void *)0)) {
                if ( fprintf(stdout, " %-8d", file->st_gid) < 0 ) {
   fprintf(stderr, "%s: writing to stdout failed!\n", progname);
  }
        }
        else {
                if ( fprintf(stdout, " %-8s", grp->gr_name) < 0 ) {
   fprintf(stderr, "%s: writing to stdout failed!\n", progname);
  }
         grp = ((void *)0);
        }
        if ( fprintf(stdout, " %8lu %s %s", file->st_size, timestring, file_name) < 0 ) {
  fprintf(stderr, "%s: writing to stdout failed!\n", progname);
 }
 if (filetype == 'l') {
  linklength = (file->st_size + 1) * sizeof(char);
  linkdestination = malloc(linklength);
  if (linkdestination == ((void *)0)) {
   fprintf(stderr, "%s: Memory allocation for linkdestination in ls failed, exiting.\n", progname);
   exit(1);
  }
  memset(linkdestination, '\0', linklength);
  (*__errno_location ()) = 0;
  if ( (linkbytesread = readlink(file_name, linkdestination, linklength-1)) > 0 ) {
   if ( fprintf(stdout, " -> %s", linkdestination) < 0 ) {
    fprintf(stderr, "%s: writing to stdout failed!\n", progname);
   }
  }
  else {
   if ( fprintf(stdout, " -> ERROR READING LINK") < 0 ) {
    fprintf(stderr, "%s: writing to stdout failed!\n", progname);
   }
   fprintf(stderr, "%s: Error reading link %s - %s\n", progname, file_name, strerror((*__errno_location ())));
  }
  free(linkdestination);
  linkdestination = ((void *)0);
 }
 if ( fprintf(stdout, "\n") < 0 ) {
  fprintf(stderr, "%s: writing to stdout failed!\n", progname);
 }
}

canonical_original_code:
void ls(struct stat *file, char *file_name) {
 char permissions[10] = {0};
 char timestring[20] = {0};
 char tmp[7] = {0};
 char *linkdestination = ((void *)0);
 int linkbytesread = 0;
 int linklength = 0;
 char filetype = 0;
 struct passwd *pwd = ((void *)0);
 struct group *grp = ((void *)0);
 struct tm *ptime = ((void *)0);
 filetype = get_file_type(file, 0);
 memset(permissions, '-', 9 );
 ptime = localtime(&file->st_mtim.tv_sec);
 strftime(timestring,9,"%b", ptime);
 strftime(tmp,4," %d", ptime);
 if(tmp[1] == '0') {
  tmp[1] = ' ';
 }
 strcat(timestring, tmp);
 strftime(tmp,7," %H:%M", ptime);
 strcat(timestring, tmp);
 if (file->st_mode & 0400) { permissions[0] = 'r'; };
 if (file->st_mode & 0200) { permissions[1] = 'w'; };
        if (file->st_mode & 04000) {
  permissions[2] = (file->st_mode & 0100) ? 's' : 'S';
 }
 else if (file->st_mode & 0100) { permissions[2] = 'x'; };
 if (file->st_mode & (0400 >> 3)) { permissions[3] = 'r'; };
 if (file->st_mode & (0200 >> 3)) { permissions[4] = 'w'; };
        if (file->st_mode & 02000) {
  permissions[5] = (file->st_mode & (0100 >> 3)) ? 's' : 'S';
 }
 else if (file->st_mode & (0100 >> 3)) { permissions[5] = 'x'; };
 if (file->st_mode & ((0400 >> 3) >> 3)) { permissions[6] = 'r'; };
 if (file->st_mode & ((0200 >> 3) >> 3)) { permissions[7] = 'w'; };
        if (file->st_mode & 01000) {
  permissions[8] = (file->st_mode & ((0100 >> 3) >> 3)) ? 't' : 'T';
 }
 else if (file->st_mode & ((0100 >> 3) >> 3)) { permissions[8] = 'x'; };
 if ( fprintf(stdout, "%6lu %4lu %c%s %3lu", file->st_ino, (file->st_blocks / 2), filetype, permissions, (long) file->st_nlink) < 0 ) {
  fprintf(stderr, "%s: writing to stdout failed!\n", progname);
 }
 if ((pwd = getpwuid(file->st_uid)) == ((void *)0)) {
  if ( fprintf(stdout, " %-8d", file->st_uid) < 0 ) {
   fprintf(stderr, "%s: writing to stdout failed!\n", progname);
  }
 }
 else {
  if ( fprintf(stdout, " %-8s", pwd->pw_name) < 0 ) {
   fprintf(stderr, "%s: writing to stdout failed!\n", progname);
  }
  pwd = ((void *)0);
 }
        if ((grp = getgrgid(file->st_gid)) == ((void *)0)) {
                if ( fprintf(stdout, " %-8d", file->st_gid) < 0 ) {
   fprintf(stderr, "%s: writing to stdout failed!\n", progname);
  }
        }
        else {
                if ( fprintf(stdout, " %-8s", grp->gr_name) < 0 ) {
   fprintf(stderr, "%s: writing to stdout failed!\n", progname);
  }
         grp = ((void *)0);
        }
        if ( fprintf(stdout, " %8lu %s %s", file->st_size, timestring, file_name) < 0 ) {
  fprintf(stderr, "%s: writing to stdout failed!\n", progname);
 }
 if (filetype == 'l') {
  linklength = (file->st_size + 1) * sizeof(char);
  linkdestination = malloc(linklength);
  if (linkdestination == ((void *)0)) {
   fprintf(stderr, "%s: Memory allocation for linkdestination in ls failed, exiting.\n", progname);
   exit(1);
  }
  memset(linkdestination, '\0', linklength);
  (*__errno_location ()) = 0;
  if ( (linkbytesread = readlink(file_name, linkdestination, linklength-1)) > 0 ) {
   if ( fprintf(stdout, " -> %s", linkdestination) < 0 ) {
    fprintf(stderr, "%s: writing to stdout failed!\n", progname);
   }
  }
  else {
   if ( fprintf(stdout, " -> ERROR READING LINK") < 0 ) {
    fprintf(stderr, "%s: writing to stdout failed!\n", progname);
   }
   fprintf(stderr, "%s: Error reading link %s - %s\n", progname, file_name, strerror((*__errno_location ())));
  }
  free(linkdestination);
  linkdestination = ((void *)0);
 }
 if ( fprintf(stdout, "\n") < 0 ) {
  fprintf(stderr, "%s: writing to stdout failed!\n", progname);
 }
}

variable_types:
permissions
char [10]

variable_types:
timestring
char [20]

variable_types:
tmp
char [7]

variable_types:
linkdestination
char *

variable_types: linkbytesread int

variable_types: linklength int

variable_types: filetype char

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

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


nouser

decompiled_code:
bool __fastcall nouser(__int64 a1)
{
return getpwuid(*(_DWORD *)(a1 + 28)) == 0LL;
}

canonical_decompiled_code:
bool __fastcall func3(__int64 a1)
{
return getpwuid(*(_DWORD *)(a1 + 28)) == 0LL;
}

original_code:
_Bool nouser(const struct stat *file) {
 struct passwd *pwd = ((void *)0);
 if ( (pwd = getpwuid(file->st_uid)) == ((void *)0)) {
  return 1;
 }
 return 0;
}

canonical_original_code:
_Bool nouser(struct stat *file) {
 struct passwd *pwd = ((void *)0);
 if ( (pwd = getpwuid(file->st_uid)) == ((void *)0)) {
  return 1;
 }
 return 0;
}

user_defined_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; }


isnumeric

decompiled_code:
__int64 __fastcall isnumeric(char *a1)
{
char v1; // bl
const unsigned __int16 *v2; // rax
char *v3; // rdi

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1 + 1;
while ( (v2[v1] & 0x800) != 0 )
{
v1 = *v3++;
if ( !v1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
char v1; // bl
const unsigned __int16 *v2; // rax
char *v3; // rdi

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1 + 1;
while ( (v2[v1] & 0x800) != 0 )
{
v1 = *v3++;
if ( !v1 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool isnumeric(const char *arg) {
 int i = 0;
 while(arg[i] != '\0') {
  if(!((*__ctype_b_loc ())[(int) ((arg[i]))] & (unsigned short int) _ISdigit)) {
   return 0;
  }
  i++;
 }
 return 1;
}

canonical_original_code:
_Bool isnumeric(char *arg) {
 int i = 0;
 while(arg[i] != '\0') {
  if(!((*__ctype_b_loc ())[(int) ((arg[i]))] & (unsigned short) _ISdigit)) {
   return 0;
  }
  i++;
 }
 return 1;
}

variable_types:
arg
char *

variable_types: i int


usermatch

decompiled_code:
char __fastcall usermatch(__int64 a1, char *a2)
{
struct passwd *v2; // rax
char result; // al
__int64 v4; // rbp

getpwnam(a2);
v2 = getpwnam(a2);
if ( v2 )
return *(_DWORD *)(a1 + 28) == v2->pw_uid;
result = isnumeric(a2);
if ( result )
{
v4 = *(unsigned int *)(a1 + 28);
result = strtol(a2, 0LL, 10) == v4;
}
return result;
}

canonical_decompiled_code:
char __fastcall func5(__int64 a1, char *a2)
{
struct passwd *v2; // rax
char result; // al
__int64 v4; // rbp

getpwnam(a2);
v2 = getpwnam(a2);
if ( v2 )
return *(_DWORD *)(a1 + 28) == v2->pw_uid;
result = func4(a2);
if ( result )
{
v4 = *(unsigned int *)(a1 + 28);
result = strtol(a2, 0LL, 10) == v4;
}
return result;
}

original_code:
_Bool usermatch(const struct stat *file, const char *arg) {
 struct passwd *pwd = ((void *)0);
 pwd = getpwnam(arg);
 if ((pwd = getpwnam(arg)) != ((void *)0)) {
  return (file->st_uid == pwd->pw_uid ? 1 : 0);
 }
 else if (isnumeric(arg) == 1 && file->st_uid == (unsigned long) strtol(arg, ((void *)0), 10)) {
  return 1;
 }
 else {
  return 0;
 }
}

canonical_original_code:
_Bool usermatch(struct stat *file, char *arg) {
 struct passwd *pwd = ((void *)0);
 pwd = getpwnam(arg);
 if ((pwd = getpwnam(arg)) != ((void *)0)) {
  return (file->st_uid == pwd->pw_uid ? 1 : 0);
 }
 else if (isnumeric(arg) == 1 && file->st_uid == (unsigned long) strtol(arg, ((void *)0), 10)) {
  return 1;
 }
 else {
  return 0;
 }
}


decompiled_code:
void __fastcall do_file(char *name, int a2, __int64 a3, int a4)
{
size_t v6; // rax
int *v7; // rbx
char v8; // bp
int v9; // ebx
char *v10; // rax
__int64 v11; // r13
char *v12; // rax
char v13; // al
char *dest; // [rsp+0h] [rbp-D8h]
__int16 v15; // [rsp+Eh] [rbp-CAh]
struct stat buf; // [rsp+10h] [rbp-C8h] BYREF

v6 = strlen(name);
dest = (char *)malloc(v6 + 1);
if ( !dest )
{
fprintf(stderr, "%s: memory allocation for file_name_copy failed!\n", (const char *)progname);
exit(1);
}
strcpy(dest, name);
v7 = _errno_location();
*v7 = 0;
if ( lstat(name, &buf) == -1 )
{
v10 = strerror(*v7);
fprintf(stderr, "%s: Could not stat %s - %s\n", (const char *)progname, name, v10);
}
else
{
v8 = a4 <= 2;
if ( a4 > 2 )
{
v15 = 0;
v9 = 2;
while ( 1 )
{
v11 = 8LL * v9;
if ( !strcmp(*(const char **)(a3 + v11), "-nouser") )
{
v8 = nouser((__int64)&buf);
if ( !v8 )
goto LABEL_31;
}
else if ( !strcmp(*(const char **)(a3 + 8LL * v9), "-user") )
{
++v9;
v8 = usermatch((__int64)&buf, *(char **)(a3 + v11 + 8));
if ( !v8 )
goto LABEL_31;
}
else if ( !strcmp(*(const char **)(a3 + 8LL * v9), "-name") )
{
v12 = _xpg_basename(dest);
++v9;
if ( fnmatch(*(const char **)(a3 + v11 + 8), v12, 0) )
goto LABEL_31;
v8 = 1;
}
else if ( !strcmp(*(const char **)(a3 + 8LL * v9), "-path") )
{
++v9;
if ( fnmatch(*(const char **)(a3 + v11 + 8), name, 1) )
goto LABEL_31;
v8 = 1;
}
else if ( !strcmp(*(const char **)(a3 + 8LL * v9), "-type") )
{
++v9;
if ( **(_BYTE **)(a3 + v11 + 8) != (unsigned __int8)get_file_type((__int64)&buf, 1) )
goto LABEL_31;
v8 = 1;
}
else if ( !strcmp(*(const char **)(a3 + 8LL * v9), "-ls") )
{
ls((__int64)&buf, name);
HIBYTE(v15) = 1;
}
else
{
if ( strcmp(*(const char **)(a3 + 8LL * v9), "-print") )
_assert_fail("0", "myfind.c", 0x122u, "do_file");
LOBYTE(v15) = 1;
if ( fprintf(stdout, "%s\n", name) < 0 )
{
fprintf(stderr, "%s: writing to stdout failed!\n", (const char *)progname);
LOBYTE(v15) = 1;
}
}
if ( a4 <= ++v9 )
goto LABEL_29;
}
}
v15 = 0;
LABEL_29:
if ( v8 == 1 && !v15 && fprintf(stdout, "%s\n", name) < 0 )
fprintf(stderr, "%s: writing to stdout failed!\n", (const char *)progname);
LABEL_31:
v13 = get_file_type((__int64)&buf, 1);
if ( a2 == 1 && v13 == 100 )
do_dir(name);
}
free(dest);
}

canonical_decompiled_code:
void __fastcall func6(char *name, int a2, __int64 a3, int a4)
{
size_t v6; // rax
int *v7; // rbx
char v8; // bp
int v9; // ebx
char *v10; // rax
__int64 v11; // r13
char *v12; // rax
char v13; // al
char *dest; // [rsp+0h] [rbp-D8h]
__int16 v15; // [rsp+Eh] [rbp-CAh]
struct stat buf; // [rsp+10h] [rbp-C8h] BYREF

v6 = strlen(name);
dest = (char *)malloc(v6 + 1);
if ( !dest )
{
fprintf(stderr, "%s: memory allocation for file_name_copy failed!\n", (const char *)progname);
exit(1);
}
strcpy(dest, name);
v7 = _errno_location();
*v7 = 0;
if ( lstat(name, &buf) == -1 )
{
v10 = strerror(*v7);
fprintf(stderr, "%s: Could not stat %s - %s\n", (const char *)progname, name, v10);
}
else
{
v8 = a4 <= 2;
if ( a4 > 2 )
{
v15 = 0;
v9 = 2;
while ( 1 )
{
v11 = 8LL * v9;
if ( !strcmp(*(const char **)(a3 + v11), "-nouser") )
{
v8 = func3((__int64)&buf);
if ( !v8 )
goto LABEL_31;
}
else if ( !strcmp(*(const char **)(a3 + 8LL * v9), "-user") )
{
++v9;
v8 = func5((__int64)&buf, *(char **)(a3 + v11 + 8));
if ( !v8 )
goto LABEL_31;
}
else if ( !strcmp(*(const char **)(a3 + 8LL * v9), "-name") )
{
v12 = _xpg_basename(dest);
++v9;
if ( fnmatch(*(const char **)(a3 + v11 + 8), v12, 0) )
goto LABEL_31;
v8 = 1;
}
else if ( !strcmp(*(const char **)(a3 + 8LL * v9), "-path") )
{
++v9;
if ( fnmatch(*(const char **)(a3 + v11 + 8), name, 1) )
goto LABEL_31;
v8 = 1;
}
else if ( !strcmp(*(const char **)(a3 + 8LL * v9), "-type") )
{
++v9;
if ( **(_BYTE **)(a3 + v11 + 8) != (unsigned __int8)func1((__int64)&buf, 1) )
goto LABEL_31;
v8 = 1;
}
else if ( !strcmp(*(const char **)(a3 + 8LL * v9), "-ls") )
{
func2((__int64)&buf, name);
HIBYTE(v15) = 1;
}
else
{
if ( strcmp(*(const char **)(a3 + 8LL * v9), "-print") )
_assert_fail("0", "myfind.c", 0x122u, "do_file");
LOBYTE(v15) = 1;
if ( fprintf(stdout, "%s\n", name) < 0 )
{
fprintf(stderr, "%s: writing to stdout failed!\n", (const char *)progname);
LOBYTE(v15) = 1;
}
}
if ( a4 <= ++v9 )
goto LABEL_29;
}
}
v15 = 0;
LABEL_29:
if ( v8 == 1 && !v15 && fprintf(stdout, "%s\n", name) < 0 )
fprintf(stderr, "%s: writing to stdout failed!\n", (const char *)progname);
LABEL_31:
v13 = func1((__int64)&buf, 1);
if ( a2 == 1 && v13 == 100 )
func7(name);
}
free(dest);
}

original_code:
void do_file(const char *file_name, const int mode, const char * const *argv, int argc) {
 int i = 0;
 struct stat myfile;
 char *file_name_copy = ((void *)0);
 _Bool printed = 0;
 _Bool lsed = 0;
 _Bool match = 0;
 file_name_copy = malloc((strlen(file_name)+1)*sizeof(char));
 if (file_name_copy == ((void *)0)) {
  fprintf(stderr, "%s: memory allocation for file_name_copy failed!\n", progname);
  exit(1);
 }
 strcpy(file_name_copy, file_name);
 (*__errno_location ()) = 0;
 if ( lstat(file_name, &myfile) == -1 ) {
  fprintf(stderr, "%s: Could not stat %s - %s\n", progname, file_name, strerror((*__errno_location ())));
 }
 else {
  if(argc <= 2) {
   match = 1;
  }
  for(i=2; i<argc; i++) {
   if (strcmp(argv[i], "-nouser") == 0) {
    if (nouser(&myfile) == 0) {
     match = 0;
     break;
    }
    match = 1;
   }
   else if (strcmp(argv[i], "-user") == 0) {
    if (usermatch(&myfile, argv[++i]) == 0) {
     match = 0;
     break;
    }
    match = 1;
   }
   else if (strcmp(argv[i], "-name") == 0) {
    if (fnmatch(argv[++i], __xpg_basename((char*)file_name_copy), 0) != 0) {
     match = 0;
     break;
    }
    match = 1;
   }
   else if (strcmp(argv[i], "-path") == 0) {
    if (fnmatch(argv[++i], file_name, (1 << 0)) != 0) {
     match = 0;
     break;
    }
    match = 1;
   }
   else if (strcmp(argv[i], "-type") == 0) {
    if (argv[++i][0] != get_file_type(&myfile, 1)) {
     match = 0;
     break;
    }
    match = 1;
   }
   else if (strcmp(argv[i], "-ls") == 0) {
    ls(&myfile, file_name);
    lsed = 1;
   }
   else if (strcmp(argv[i], "-print") == 0) {
    if ( fprintf(stdout, "%s\n", file_name) < 0 ) {
     fprintf(stderr, "%s: writing to stdout failed!\n", progname);
    }
    printed = 1;
   }
   else {
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "myfind.c", 290, __extension__ __PRETTY_FUNCTION__); }));
   }
  }
  if (match == 1 && printed == 0 && lsed == 0) {
   if ( fprintf(stdout, "%s\n", file_name) < 0 ) {
    fprintf(stderr, "%s: writing to stdout failed!\n", progname);
   }
  }
  if ( get_file_type(&myfile, 1) == 'd' && mode == 1 ) {
   do_dir(file_name, argv, argc);
  }
 }
 free(file_name_copy);
 file_name_copy = ((void *)0);
}

canonical_original_code:
void do_file(char *file_name, int mode, char **argv, int argc) {
 int i = 0;
 struct stat myfile;
 char *file_name_copy = ((void *)0);
 _Bool printed = 0;
 _Bool lsed = 0;
 _Bool match = 0;
 file_name_copy = malloc((strlen(file_name)+1)*sizeof(char));
 if (file_name_copy == ((void *)0)) {
  fprintf(stderr, "%s: memory allocation for file_name_copy failed!\n", progname);
  exit(1);
 }
 strcpy(file_name_copy, file_name);
 (*__errno_location ()) = 0;
 if ( lstat(file_name, &myfile) == -1 ) {
  fprintf(stderr, "%s: Could not stat %s - %s\n", progname, file_name, strerror((*__errno_location ())));
 }
 else {
  if(argc <= 2) {
   match = 1;
  }
  for(i=2; i<argc; i++) {
   if (strcmp(argv[i], "-nouser") == 0) {
    if (nouser(&myfile) == 0) {
     match = 0;
     break;
    }
    match = 1;
   }
   else if (strcmp(argv[i], "-user") == 0) {
    if (usermatch(&myfile, argv[++i]) == 0) {
     match = 0;
     break;
    }
    match = 1;
   }
   else if (strcmp(argv[i], "-name") == 0) {
    if (fnmatch(argv[++i], __xpg_basename((char *)file_name_copy), 0) != 0) {
     match = 0;
     break;
    }
    match = 1;
   }
   else if (strcmp(argv[i], "-path") == 0) {
    if (fnmatch(argv[++i], file_name, (1 << 0)) != 0) {
     match = 0;
     break;
    }
    match = 1;
   }
   else if (strcmp(argv[i], "-type") == 0) {
    if (argv[++i][0] != get_file_type(&myfile, 1)) {
     match = 0;
     break;
    }
    match = 1;
   }
   else if (strcmp(argv[i], "-ls") == 0) {
    ls(&myfile, file_name);
    lsed = 1;
   }
   else if (strcmp(argv[i], "-print") == 0) {
    if ( fprintf(stdout, "%s\n", file_name) < 0 ) {
     fprintf(stderr, "%s: writing to stdout failed!\n", progname);
    }
    printed = 1;
   }
   else {
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "myfind.c", 290, __extension__ __PRETTY_FUNCTION__); }));
   }
  }
  if (match == 1 && printed == 0 && lsed == 0) {
   if ( fprintf(stdout, "%s\n", file_name) < 0 ) {
    fprintf(stderr, "%s: writing to stdout failed!\n", progname);
   }
  }
  if ( get_file_type(&myfile, 1) == 'd' && mode == 1 ) {
   do_dir(file_name, argv, argc);
  }
 }
 free(file_name_copy);
 file_name_copy = ((void *)0);
}

variable_types:
argv
char **

variable_types: argc int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebp
int *v5; // rbx
const char **v7; // r12
const char *v8; // rbx
__int64 v9; // r15
const char *v10; // r12
bool v11; // zf
_BOOL4 v12; // ebx
const char *v13; // rsi
char *v14; // rax
const char *v15; // rsi
char *s1; // [rsp+8h] [rbp-D0h]
struct stat buf; // [rsp+10h] [rbp-C8h] BYREF

setlocale(6, &locale);
progname = (__int64)*argv;
if ( argc <= 1 )
usage();
v4 = 2;
if ( argc > 2 )
{
while ( 1 )
{
v9 = v4;
v10 = argv[v9];
v11 = strcmp(v10, "-user") == 0;
v12 = !v11;
if ( v11 || !strcmp(argv[v4], "-name") || !strcmp(argv[v4], "-path") )
break;
if ( !strcmp(argv[v4], "-type") )
{
if ( ++v4 == argc )
{
LABEL_21:
fprintf(stderr, "%s: Option %s needs an argument.\n\n", (const char *)progname, v10);
usage();
}
v15 = argv[v9 + 1];
s1 = (char *)v15;
if ( !strcmp(v15, "b") )
goto LABEL_12;
LABEL_23:
if ( strcmp(s1, "c")
&& strcmp(s1, "d")
&& strcmp(s1, "p")
&& strcmp(s1, "f")
&& strcmp(s1, "l")
&& strcmp(s1, "s") )
{
fprintf(stderr, "%s: Option %s needs an argument of [bcdpfls].\n\n", (const char *)progname, v10);
usage();
}
LABEL_10:
if ( !v12 )
{
v7 = &argv[v9 + 1];
v8 = *v7;
if ( !(unsigned __int8)isnumeric((char *)*v7) && !getpwnam(v8) )
{
fprintf(stderr, "%s: User not found: %s\n", (const char *)progname, *v7);
exit(1);
}
}
goto LABEL_12;
}
if ( strcmp(argv[v4], "-ls") && strcmp(argv[v4], "-print") && strcmp(argv[v4], "-nouser") )
{
fprintf(stderr, "%s: Unknown parameter given: %s .\n\n", (const char *)progname, argv[v4]);
usage();
}
LABEL_12:
if ( argc <= ++v4 )
goto LABEL_3;
}
if ( ++v4 == argc )
goto LABEL_21;
if ( !strcmp(argv[v9], "-type") )
{
v13 = argv[v9 + 1];
s1 = (char *)v13;
if ( strcmp(v13, "b") )
goto LABEL_23;
}
goto LABEL_10;
}
LABEL_3:
v5 = _errno_location();
*v5 = 0;
if ( lstat(argv[1], &buf) == -1 )
{
v14 = strerror(*v5);
fprintf(stderr, "%s: Could not stat %s - %s\n", (const char *)progname, argv[1], v14);
exit(1);
}
if ( (unsigned __int8)get_file_type((__int64)&buf, 1) == 100 )
do_dir((char *)argv[1], (__int64)argv, argc);
else
do_file((char *)argv[1], 0, (__int64)argv, argc);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebp
int *v5; // rbx
const char **v7; // r12
const char *v8; // rbx
__int64 v9; // r15
const char *v10; // r12
bool v11; // zf
_BOOL4 v12; // ebx
const char *v13; // rsi
char *v14; // rax
const char *v15; // rsi
char *s1; // [rsp+8h] [rbp-D0h]
struct stat buf; // [rsp+10h] [rbp-C8h] BYREF

setlocale(6, &locale);
progname = (__int64)*argv;
if ( argc <= 1 )
func0();
v4 = 2;
if ( argc > 2 )
{
while ( 1 )
{
v9 = v4;
v10 = argv[v9];
v11 = strcmp(v10, "-user") == 0;
v12 = !v11;
if ( v11 || !strcmp(argv[v4], "-name") || !strcmp(argv[v4], "-path") )
break;
if ( !strcmp(argv[v4], "-type") )
{
if ( ++v4 == argc )
{
LABEL_21:
fprintf(stderr, "%s: Option %s needs an argument.\n\n", (const char *)progname, v10);
func0();
}
v15 = argv[v9 + 1];
s1 = (char *)v15;
if ( !strcmp(v15, "b") )
goto LABEL_12;
LABEL_23:
if ( strcmp(s1, "c")
&& strcmp(s1, "d")
&& strcmp(s1, "p")
&& strcmp(s1, "f")
&& strcmp(s1, "l")
&& strcmp(s1, "s") )
{
fprintf(stderr, "%s: Option %s needs an argument of [bcdpfls].\n\n", (const char *)progname, v10);
func0();
}
LABEL_10:
if ( !v12 )
{
v7 = &argv[v9 + 1];
v8 = *v7;
if ( !(unsigned __int8)func4((char *)*v7) && !getpwnam(v8) )
{
fprintf(stderr, "%s: User not found: %s\n", (const char *)progname, *v7);
exit(1);
}
}
goto LABEL_12;
}
if ( strcmp(argv[v4], "-ls") && strcmp(argv[v4], "-print") && strcmp(argv[v4], "-nouser") )
{
fprintf(stderr, "%s: Unknown parameter given: %s .\n\n", (const char *)progname, argv[v4]);
func0();
}
LABEL_12:
if ( argc <= ++v4 )
goto LABEL_3;
}
if ( ++v4 == argc )
goto LABEL_21;
if ( !strcmp(argv[v9], "-type") )
{
v13 = argv[v9 + 1];
s1 = (char *)v13;
if ( strcmp(v13, "b") )
goto LABEL_23;
}
goto LABEL_10;
}
LABEL_3:
v5 = _errno_location();
*v5 = 0;
if ( lstat(argv[1], &buf) == -1 )
{
v14 = strerror(*v5);
fprintf(stderr, "%s: Could not stat %s - %s\n", (const char *)progname, argv[1], v14);
exit(1);
}
if ( (unsigned __int8)func1((__int64)&buf, 1) == 100 )
func7((char *)argv[1], (__int64)argv, argc);
else
func6((char *)argv[1], 0, (__int64)argv, argc);
return 0;
}

original_code:
int main(int argc, const char * const *argv) {
 int i = 0;
 struct stat myfile;
 struct passwd *pwd = ((void *)0);
 setlocale(6, "");
 progname = argv[0];
 if (argc <2) {
  usage();
 }
 for(i=2; i<argc; i++) {
  if (strcmp(argv[i], "-user") == 0 || strcmp(argv[i], "-name") == 0 || strcmp(argv[i], "-path") == 0 || strcmp(argv[i], "-type") == 0) {
   if (i+1 == argc) {
    fprintf(stderr, "%s: Option %s needs an argument.\n\n", progname, argv[i]);
    usage();
                        }
   else {
    if (strcmp(argv[i], "-type") == 0 && strcmp(argv[i+1], "b") != 0 && strcmp(argv[i+1], "c") != 0
    && strcmp(argv[i+1], "d") != 0 && strcmp(argv[i+1], "p") != 0
    && strcmp(argv[i+1], "f") != 0 && strcmp(argv[i+1], "l") != 0 && strcmp(argv[i+1], "s") != 0)
    {
    fprintf(stderr, "%s: Option %s needs an argument of [bcdpfls].\n\n", progname, argv[i]);
    usage();
    }
    if (strcmp(argv[i], "-user") == 0 && isnumeric(argv[i+1]) == 0 && (pwd = getpwnam(argv[i+1])) == ((void *)0)) {
     fprintf(stderr, "%s: User not found: %s\n", progname, argv[i+1]);
     exit(1);
    }
   }
   i++;
  }
  else if (strcmp(argv[i], "-ls") != 0 && strcmp(argv[i], "-print") != 0 && strcmp(argv[i], "-nouser") != 0) {
   fprintf(stderr, "%s: Unknown parameter given: %s .\n\n", progname, argv[i]);
   usage();
  }
 }
 (*__errno_location ()) = 0;
 if ( lstat(argv[1], &myfile) == -1 ) {
  fprintf(stderr, "%s: Could not stat %s - %s\n", progname, argv[1], strerror((*__errno_location ())));
  exit(1);
 }
 else {
  if (get_file_type(&myfile, 1) == 'd') {
   do_dir(argv[1], argv, argc);
  }
  else {
   do_file(argv[1], 0, argv, argc);
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int i = 0;
 struct stat myfile;
 struct passwd *pwd = ((void *)0);
 setlocale(6, "");
 progname = argv[0];
 if (argc <2) {
  usage();
 }
 for(i=2; i<argc; i++) {
  if (strcmp(argv[i], "-user") == 0 || strcmp(argv[i], "-name") == 0 || strcmp(argv[i], "-path") == 0 || strcmp(argv[i], "-type") == 0) {
   if (i+1 == argc) {
    fprintf(stderr, "%s: Option %s needs an argument.\n\n", progname, argv[i]);
    usage();
                        }
   else {
    if (strcmp(argv[i], "-type") == 0 && strcmp(argv[i+1], "b") != 0 && strcmp(argv[i+1], "c") != 0
    && strcmp(argv[i+1], "d") != 0 && strcmp(argv[i+1], "p") != 0
    && strcmp(argv[i+1], "f") != 0 && strcmp(argv[i+1], "l") != 0 && strcmp(argv[i+1], "s") != 0)
    {
    fprintf(stderr, "%s: Option %s needs an argument of [bcdpfls].\n\n", progname, argv[i]);
    usage();
    }
    if (strcmp(argv[i], "-user") == 0 && isnumeric(argv[i+1]) == 0 && (pwd = getpwnam(argv[i+1])) == ((void *)0)) {
     fprintf(stderr, "%s: User not found: %s\n", progname, argv[i+1]);
     exit(1);
    }
   }
   i++;
  }
  else if (strcmp(argv[i], "-ls") != 0 && strcmp(argv[i], "-print") != 0 && strcmp(argv[i], "-nouser") != 0) {
   fprintf(stderr, "%s: Unknown parameter given: %s .\n\n", progname, argv[i]);
   usage();
  }
 }
 (*__errno_location ()) = 0;
 if ( lstat(argv[1], &myfile) == -1 ) {
  fprintf(stderr, "%s: Could not stat %s - %s\n", progname, argv[1], strerror((*__errno_location ())));
  exit(1);
 }
 else {
  if (get_file_type(&myfile, 1) == 'd') {
   do_dir(argv[1], argv, argc);
  }
  else {
   do_file(argv[1], 0, argv, argc);
  }
 }
 return 0;
}


decompiled_code:
int print_stats()
{
__int64 v0; // r14
unsigned int v1; // er13
unsigned int v2; // er12
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // eax

v0 = c3bt_stat_merges;
v1 = c3bt_stat_pushups;
v2 = c3bt_stat_splits;
v3 = c3bt_stat_pushdowns;
v4 = c3bt_stat_cells;
v5 = c3bt_nobjects();
return printf("%d uobjs in %d cells, %d pushdowns %d splits %d pushups %d merges.\n", v5, v4, v3, v2, v1, v0);
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // r14
unsigned int v1; // er13
unsigned int v2; // er12
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // eax

v0 = c3bt_stat_merges;
v1 = c3bt_stat_pushups;
v2 = c3bt_stat_splits;
v3 = c3bt_stat_pushdowns;
v4 = c3bt_stat_cells;
v5 = c3bt_nobjects();
return printf("%d uobjs in %d cells, %d pushdowns %d splits %d pushups %d merges.\n", v5, v4, v3, v2, v1, v0);
}

original_code:
void print_stats(c3bt_tree* tree)
{
    printf("%d uobjs in %d cells, %d pushdowns %d splits %d pushups "
        "%d merges.\n", c3bt_nobjects(tree), c3bt_stat_cells,
        c3bt_stat_pushdowns, c3bt_stat_splits, c3bt_stat_pushups,
        c3bt_stat_merges);
}

canonical_original_code:
void print_stats(struct c3bt_tree *tree)
{
    printf("%d uobjs in %d cells, %d pushdowns %d splits %d pushups "
        "%d merges.\n", c3bt_nobjects(tree), c3bt_stat_cells,
        c3bt_stat_pushdowns, c3bt_stat_splits, c3bt_stat_pushups,
        c3bt_stat_merges);
}

variable_types: struct c3bt_tree { void *opaque1[2]; int opaque2[3]; } *


decompiled_code:
void clear_stats()
{
c3bt_stat_pushdowns = 0;
c3bt_stat_splits = 0;
c3bt_stat_pushups = 0;
c3bt_stat_merges = 0;
}

canonical_decompiled_code:
void func1()
{
c3bt_stat_pushdowns = 0;
c3bt_stat_splits = 0;
c3bt_stat_pushups = 0;
c3bt_stat_merges = 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
char *v4; // rbx
char *v5; // rdx
int i; // eax
char *v7; // r12
char *v8; // rbp
char *v9; // rbp
__int64 j; // rbx
struct timespec v12; // [rsp+0h] [rbp-78h] BYREF
struct timespec tp; // [rsp+10h] [rbp-68h] BYREF
char v14[16]; // [rsp+20h] [rbp-58h] BYREF
char v15[72]; // [rsp+30h] [rbp-48h] BYREF

v3 = (char *)malloc(0x61A80uLL);
v4 = v3;
v5 = v3;
for ( i = 0; i != 700000; i += 7 )
{
*(_DWORD *)v5 = i;
v5 += 4;
}
c3bt_init(v15, 3LL, 0LL, 0LL);
clock_gettime(1, &tp);
v7 = v3 + 400000;
v8 = v3;
do
{
c3bt_add(v15, v8);
v8 += 4;
}
while ( v7 != v8 );
clock_gettime(1, &v12);
printf("Add %dk uobjs: %ldus\n", 100LL, 1000000 * (v12.tv_sec - tp.tv_sec) + (v12.tv_nsec - tp.tv_nsec) / 1000);
print_stats();
clear_stats();
clock_gettime(1, &tp);
v9 = v3;
do
{
c3bt_remove(v15, v9);
v9 += 8;
}
while ( v9 != v7 );
clock_gettime(1, &v12);
printf("Remove %dk uobjs: %ldus\n", 50LL, 1000000 * (v12.tv_sec - tp.tv_sec) + (v12.tv_nsec - tp.tv_nsec) / 1000);
print_stats();
clear_stats();
clock_gettime(1, &tp);
do
{
c3bt_add(v15, v4);
v4 += 8;
}
while ( v7 != v4 );
clock_gettime(1, &v12);
printf("Re-add %dk uobjs: %ldus\n", 50LL, 1000000 * (v12.tv_sec - tp.tv_sec) + (v12.tv_nsec - tp.tv_nsec) / 1000);
print_stats();
if ( c3bt_first(v15, v14) )
{
while ( c3bt_next(v15, v14) )
;
}
c3bt_destroy(v15);
puts("Population distribution:");
for ( j = 1LL; j != 9; ++j )
printf("cells with %d nodes: %d\n", (unsigned int)j, *((unsigned int *)&c3bt_stat_popdist + j - 1));
free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
char *v4; // rbx
char *v5; // rdx
int i; // eax
char *v7; // r12
char *v8; // rbp
char *v9; // rbp
__int64 j; // rbx
struct timespec v12; // [rsp+0h] [rbp-78h] BYREF
struct timespec tp; // [rsp+10h] [rbp-68h] BYREF
char v14[16]; // [rsp+20h] [rbp-58h] BYREF
char v15[72]; // [rsp+30h] [rbp-48h] BYREF

v3 = (char *)malloc(0x61A80uLL);
v4 = v3;
v5 = v3;
for ( i = 0; i != 700000; i += 7 )
{
*(_DWORD *)v5 = i;
v5 += 4;
}
c3bt_init(v15, 3LL, 0LL, 0LL);
clock_gettime(1, &tp);
v7 = v3 + 400000;
v8 = v3;
do
{
c3bt_add(v15, v8);
v8 += 4;
}
while ( v7 != v8 );
clock_gettime(1, &v12);
printf("Add %dk uobjs: %ldus\n", 100LL, 1000000 * (v12.tv_sec - tp.tv_sec) + (v12.tv_nsec - tp.tv_nsec) / 1000);
func0();
func1();
clock_gettime(1, &tp);
v9 = v3;
do
{
c3bt_remove(v15, v9);
v9 += 8;
}
while ( v9 != v7 );
clock_gettime(1, &v12);
printf("Remove %dk uobjs: %ldus\n", 50LL, 1000000 * (v12.tv_sec - tp.tv_sec) + (v12.tv_nsec - tp.tv_nsec) / 1000);
func0();
func1();
clock_gettime(1, &tp);
do
{
c3bt_add(v15, v4);
v4 += 8;
}
while ( v7 != v4 );
clock_gettime(1, &v12);
printf("Re-add %dk uobjs: %ldus\n", 50LL, 1000000 * (v12.tv_sec - tp.tv_sec) + (v12.tv_nsec - tp.tv_nsec) / 1000);
func0();
if ( c3bt_first(v15, v14) )
{
while ( c3bt_next(v15, v14) )
;
}
c3bt_destroy(v15);
puts("Population distribution:");
for ( j = 1LL; j != 9; ++j )
printf("cells with %d nodes: %d\n", (unsigned int)j, *((unsigned int *)&c3bt_stat_popdist + j - 1));
free(v3);
return 0;
}

original_code:
int main()
{
    c3bt_tree tree;
    c3bt_cursor cur;
    int i;
    int *array = malloc(100000 * sizeof(int));
    int *robj;
    struct timespec t_start, t_end;
    for (i = 0; i < 100000; i++)
        array[i] = i * 7;
    c3bt_init(&tree, C3BT_KDT_U32, 0, 0);
    clock_gettime(1, &t_start);
    for (i = 0; i < 100000; i++)
        c3bt_add(&tree, array + i);
    clock_gettime(1, &t_end);
    printf("Add %dk uobjs: %ldus\n", 100000 / 1000,
        (t_end.tv_sec - t_start.tv_sec) * 1000000
            + (t_end.tv_nsec - t_start.tv_nsec) / 1000);
    print_stats(&tree);
    clear_stats();
    clock_gettime(1, &t_start);
    for (i = 0; i < 100000; i += 2)
        c3bt_remove(&tree, array + i);
    clock_gettime(1, &t_end);
    printf("Remove %dk uobjs: %ldus\n", 100000 / 2000,
        (t_end.tv_sec - t_start.tv_sec) * 1000000
            + (t_end.tv_nsec - t_start.tv_nsec) / 1000);
    print_stats(&tree);
    clear_stats();
    clock_gettime(1, &t_start);
    for (i = 0; i < 100000; i += 2)
        c3bt_add(&tree, array + i);
    clock_gettime(1, &t_end);
    printf("Re-add %dk uobjs: %ldus\n", 100000 / 2000,
        (t_end.tv_sec - t_start.tv_sec) * 1000000
            + (t_end.tv_nsec - t_start.tv_nsec) / 1000);
    print_stats(&tree);
    robj = c3bt_first(&tree, &cur);
    while (robj) {
        robj = c3bt_next(&tree, &cur);
    }
    c3bt_destroy(&tree);
    printf("Population distribution:\n");
    for (i = 0; i < 8; i++)
        printf("cells with %d nodes: %d\n", i + 1, c3bt_stat_popdist[i]);
    free(array);
    return 0;
}

canonical_original_code:
int main()
{
    struct c3bt_tree tree;
    struct c3bt_cursor cur;
    int i;
    int *array = malloc(100000 * sizeof(int));
    int *robj;
    struct timespec t_start; struct timespec t_end;
    for (i = 0; i < 100000; i++)
        array[i] = i * 7;
    c3bt_init(&tree, C3BT_KDT_U32, 0, 0);
    clock_gettime(1, &t_start);
    for (i = 0; i < 100000; i++)
        c3bt_add(&tree, array + i);
    clock_gettime(1, &t_end);
    printf("Add %dk uobjs: %ldus\n", 100000 / 1000,
        (t_end.tv_sec - t_start.tv_sec) * 1000000
            + (t_end.tv_nsec - t_start.tv_nsec) / 1000);
    print_stats(&tree);
    clear_stats();
    clock_gettime(1, &t_start);
    for (i = 0; i < 100000; i += 2)
        c3bt_remove(&tree, array + i);
    clock_gettime(1, &t_end);
    printf("Remove %dk uobjs: %ldus\n", 100000 / 2000,
        (t_end.tv_sec - t_start.tv_sec) * 1000000
            + (t_end.tv_nsec - t_start.tv_nsec) / 1000);
    print_stats(&tree);
    clear_stats();
    clock_gettime(1, &t_start);
    for (i = 0; i < 100000; i += 2)
        c3bt_add(&tree, array + i);
    clock_gettime(1, &t_end);
    printf("Re-add %dk uobjs: %ldus\n", 100000 / 2000,
        (t_end.tv_sec - t_start.tv_sec) * 1000000
            + (t_end.tv_nsec - t_start.tv_nsec) / 1000);
    print_stats(&tree);
    robj = c3bt_first(&tree, &cur);
    while (robj) {
        robj = c3bt_next(&tree, &cur);
    }
    c3bt_destroy(&tree);
    printf("Population distribution:\n");
    for (i = 0; i < 8; i++)
        printf("cells with %d nodes: %d\n", i + 1, c3bt_stat_popdist[i]);
    free(array);
    return 0;
}

variable_types: struct c3bt_tree { void *opaque1[2]; int opaque2[3]; }

variable_types: struct c3bt_cursor { void *opaque1; short opaque2[2]; }

variable_types:
array
int *

variable_types:
robj
int *

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


repo: longluo/NanoShell

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
NanoShell_Init(argc, argv, envp);
return 0;
}

original_code:
int main(void)
{
 NanoShell_Init();
 return 0;
}

canonical_original_code:
int main()
{
 NanoShell_Init();
 return 0;
}


decompiled_code:
_BOOL8 __fastcall parse_single_header(char *s1, char *s, __int64 a3)
{
char *v6; // rbx
const unsigned __int16 *v7; // rdx
struct tm *v8; // rsi
char *v9; // rdi

if ( !strcasecmp(s1, "If-Modified-Since") )
{
v8 = (struct tm *)malloc(0x38uLL);
*(_QWORD *)(a3 + 40) = v8;
if ( v8 )
parse_time(s, v8);
else
fwrite("Out of memory.\n", 1uLL, 0xFuLL, stderr);
}
if ( !strcasecmp(s1, "User-Agent") )
{
v6 = &s[strlen(s) - 1];
v7 = *_ctype_b_loc();
while ( (v7[*v6] & 0x2000) != 0 )
--v6;
v6[1] = 0;
v9 = (char *)malloc(v6 - s + 1);
*(_QWORD *)(a3 + 24) = v9;
if ( v9 )
strcpy(v9, s);
else
fwrite("Out of memory\n", 1uLL, 0xEuLL, stderr);
}
if ( !strcasecmp(s1, "Host") )
*(_DWORD *)(a3 + 36) = 1;
if ( !strcasecmp(s1, "Connection") )
{
if ( !strcmp(s, "close") )
{
*(_DWORD *)(a3 + 32) = 0;
}
else if ( !strcmp(s, "Keep-Alive") )
{
*(_DWORD *)(a3 + 32) = 1;
}
}
return strcasecmp(s1, "Cookie") != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *s1, char *s, __int64 a3)
{
char *v6; // rbx
const unsigned __int16 *v7; // rdx
struct tm *v8; // rsi
char *v9; // rdi

if ( !strcasecmp(s1, "If-Modified-Since") )
{
v8 = (struct tm *)malloc(0x38uLL);
*(_QWORD *)(a3 + 40) = v8;
if ( v8 )
func0(s, v8);
else
fwrite("Out of memory.\n", 1uLL, 0xFuLL, stderr);
}
if ( !strcasecmp(s1, "User-Agent") )
{
v6 = &s[strlen(s) - 1];
v7 = *_ctype_b_loc();
while ( (v7[*v6] & 0x2000) != 0 )
--v6;
v6[1] = 0;
v9 = (char *)malloc(v6 - s + 1);
*(_QWORD *)(a3 + 24) = v9;
if ( v9 )
strcpy(v9, s);
else
fwrite("Out of memory\n", 1uLL, 0xEuLL, stderr);
}
if ( !strcasecmp(s1, "Host") )
*(_DWORD *)(a3 + 36) = 1;
if ( !strcasecmp(s1, "Connection") )
{
if ( !strcmp(s, "close") )
{
*(_DWORD *)(a3 + 32) = 0;
}
else if ( !strcmp(s, "Keep-Alive") )
{
*(_DWORD *)(a3 + 32) = 1;
}
}
return strcasecmp(s1, "Cookie") != 0;
}

original_code:
int parse_single_header(char *key, char *val, struct req_info *info) {
    if (strcasecmp(key, "If-Modified-Since") == 0) {
        info->if_modified_since = malloc(sizeof(*info->if_modified_since));
        if (!info->if_modified_since) {
            fprintf(stderr, "Out of memory.\n");
        } else {
            parse_time(val, info->if_modified_since);
        }
    }
    if (strcasecmp(key, "User-Agent") == 0) {
        char *ua_end = val + strlen(val) - 1;
        while (((*__ctype_b_loc ())[(int) ((*ua_end))] & (unsigned short int) _ISspace)) --ua_end;
        *(ua_end+1) = '\0';
        info->user_agent = malloc(ua_end-val + 1);
        if (info->user_agent) {
            strcpy(info->user_agent, val);
        } else {
            fputs("Out of memory\n", stderr);
        }
    }
    if (strcasecmp(key, "Host") == 0) {
        info->found_host = 1;
    }
    if (strcasecmp(key, "Connection") == 0) {
        if (strcmp(val, "close") == 0) {
            info->want_persistent = 0;
        }
        else if (strcmp(val, "Keep-Alive") == 0) {
            info->want_persistent = 1;
        }
    }
    if (strcasecmp(key, "Cookie") == 0) {
        return 0;
    }
    return 1;
}

canonical_original_code:
int parse_single_header(char *key, char *val, struct req_info *info) {
    if (strcasecmp(key, "If-Modified-Since") == 0) {
        info->if_modified_since = malloc(sizeof(*info->if_modified_since));
        if (!info->if_modified_since) {
            fprintf(stderr, "Out of memory.\n");
        } else {
            parse_time(val, info->if_modified_since);
        }
    }
    if (strcasecmp(key, "User-Agent") == 0) {
        char *ua_end = val + strlen(val) - 1;
        while (((*__ctype_b_loc ())[(int) ((*ua_end))] & (unsigned short) _ISspace)) --ua_end;
        *(ua_end+1) = '\0';
        info->user_agent = malloc(ua_end-val + 1);
        if (info->user_agent) {
            strcpy(info->user_agent, val);
        } else {
            fputs("Out of memory\n", stderr);
        }
    }
    if (strcasecmp(key, "Host") == 0) {
        info->found_host = 1;
    }
    if (strcasecmp(key, "Connection") == 0) {
        if (strcmp(val, "close") == 0) {
            info->want_persistent = 0;
        }
        else if (strcmp(val, "Keep-Alive") == 0) {
            info->want_persistent = 1;
        }
    }
    if (strcasecmp(key, "Cookie") == 0) {
        return 0;
    }
    return 1;
}

variable_types:
key
char *

variable_types:
val
char *

variable_types: struct req_info { enum req_method { INVALID=0, GET=1 } method; char *resource; char *http_ver; char *user_agent; int want_persistent; int found_host; struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; } *if_modified_since; } *

user_defined_types: struct req_info { enum req_method method; char *resource; char *http_ver; char *user_agent; int want_persistent; int found_host; struct tm *if_modified_since; }


decompiled_code:
__int64 __fastcall parse_headers(__int64 fd, __int64 a2)
{
unsigned int v2; // er12
int v4; // eax
char *v5; // rax
char *v6; // rbx
unsigned __int64 v7; // rcx
const char *v8; // rbx
char *v9; // rbp
char *v10; // rsi
char *i; // rbx
char *v12; // rcx
char *j; // rax
char *k; // rsi
int v15; // eax
const unsigned __int16 *v16; // rbp
char v18[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = fd;
v4 = recv_getline(fd, v18, 1024LL);
if ( v4 < 0 )
{
die_error((unsigned int)fd, 400LL, "Bad request");
}
else if ( !v4 )
{
close(fd);
exit(0);
}
v5 = strchr(v18, 32);
v6 = v5;
if ( !v5 )
goto LABEL_7;
v7 = v5 - v18;
if ( (unsigned __int64)(v5 - v18) > 4 )
v7 = 4LL;
if ( memcmp(v18, "GET", v7) )
LABEL_7:
die_error(v2, 405LL, "Method not allowed");
*(_DWORD *)a2 = 1;
v8 = v6 + 1;
v9 = strchr(v8, 32);
if ( !v9 )
die_error(v2, 400LL, "Bad request");
*v9 = 0;
*(_QWORD *)(a2 + 8) = strdup(v8);
v10 = strdup(v9 + 1);
*(_QWORD *)(a2 + 16) = v10;
if ( !strcmp(v10, "HTTP/1.1") )
*(_DWORD *)(a2 + 32) = 1;
while ( 1 )
{
v15 = recv_getline(v2, v18, 1024LL);
if ( v15 < 0 )
{
die_error(v2, 400LL, "Bad request");
}
else if ( !v15 )
{
close(v2);
exit(0);
}
if ( !v18[0] )
break;
v16 = *_ctype_b_loc();
for ( i = v18; (v16[*i] & 0x2000) != 0; ++i )
;
v12 = strchr(i, 58);
for ( j = v12 - 1; (v16[*j] & 0x2000) != 0; --j )
;
j[1] = 0;
for ( k = v12 + 1; (v16[*k] & 0x2000) != 0; ++k )
;
if ( !parse_single_header(i, k, a2) )
die_error(v2, 501LL, "Not implemented");
}
if ( !strcasecmp(*(const char **)(a2 + 16), "HTTP/1.1") && !*(_DWORD *)(a2 + 36) )
die_error(v2, 400LL, "Bad request");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 fd, __int64 a2)
{
unsigned int v2; // er12
int v4; // eax
char *v5; // rax
char *v6; // rbx
unsigned __int64 v7; // rcx
const char *v8; // rbx
char *v9; // rbp
char *v10; // rsi
char *i; // rbx
char *v12; // rcx
char *j; // rax
char *k; // rsi
int v15; // eax
const unsigned __int16 *v16; // rbp
char v18[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = fd;
v4 = recv_getline(fd, v18, 1024LL);
if ( v4 < 0 )
{
die_error((unsigned int)fd, 400LL, "Bad request");
}
else if ( !v4 )
{
close(fd);
exit(0);
}
v5 = strchr(v18, 32);
v6 = v5;
if ( !v5 )
goto LABEL_7;
v7 = v5 - v18;
if ( (unsigned __int64)(v5 - v18) > 4 )
v7 = 4LL;
if ( memcmp(v18, "GET", v7) )
LABEL_7:
die_error(v2, 405LL, "Method not allowed");
*(_DWORD *)a2 = 1;
v8 = v6 + 1;
v9 = strchr(v8, 32);
if ( !v9 )
die_error(v2, 400LL, "Bad request");
*v9 = 0;
*(_QWORD *)(a2 + 8) = strdup(v8);
v10 = strdup(v9 + 1);
*(_QWORD *)(a2 + 16) = v10;
if ( !strcmp(v10, "HTTP/1.1") )
*(_DWORD *)(a2 + 32) = 1;
while ( 1 )
{
v15 = recv_getline(v2, v18, 1024LL);
if ( v15 < 0 )
{
die_error(v2, 400LL, "Bad request");
}
else if ( !v15 )
{
close(v2);
exit(0);
}
if ( !v18[0] )
break;
v16 = *_ctype_b_loc();
for ( i = v18; (v16[*i] & 0x2000) != 0; ++i )
;
v12 = strchr(i, 58);
for ( j = v12 - 1; (v16[*j] & 0x2000) != 0; --j )
;
j[1] = 0;
for ( k = v12 + 1; (v16[*k] & 0x2000) != 0; ++k )
;
if ( !func1(i, k, a2) )
die_error(v2, 501LL, "Not implemented");
}
if ( !strcasecmp(*(const char **)(a2 + 16), "HTTP/1.1") && !*(_DWORD *)(a2 + 36) )
die_error(v2, 400LL, "Bad request");
return 1LL;
}

original_code:
int parse_headers(int sock, struct req_info *info) {
    char buf[1024];
    char *p1,
         *p2,
         *p3;
    int st;
    if ((st = recv_getline(sock, buf, 1024)) < 0) {
        die_error(sock, 400, "Bad request");
    } else if (st == 0) {
        close(sock);
        exit(0);
    }
    p1 = strstr(buf, " ");
    if (p1 == ((void *)0) || strncmp(buf, "GET", p1-buf) != 0) {
        die_error(sock, 405, "Method not allowed");
    }
    info->method = GET;
    ++p1;
    p2 = strstr(p1, " ");
    if (p2 == ((void *)0)) {
        die_error(sock, 400, "Bad request");
    }
    *p2 = '\0';
    info->resource = strdup(p1);
    info->http_ver = strdup(p2+1);
    if (strcmp(info->http_ver, "HTTP/1.1") == 0) {
        info->want_persistent = 1;
    }
    while (1) {
        if ((st = recv_getline(sock, buf, 1024)) < 0) {
            die_error(sock, 400, "Bad request");
        } else if (st == 0) {
            close(sock);
            exit(0);
        }
        if (buf[0] == 0) {
            break;
        }
        p1 = buf;
        while (((*__ctype_b_loc ())[(int) ((*p1))] & (unsigned short int) _ISspace)) ++p1;
        p2 = p3 = strstr(p1, ":");
        --p2;
        while (((*__ctype_b_loc ())[(int) ((*p2))] & (unsigned short int) _ISspace)) --p2;
        *(p2+1) = '\0';
        ++p3;
        while (((*__ctype_b_loc ())[(int) ((*p3))] & (unsigned short int) _ISspace)) ++p3;
        if (!parse_single_header(p1, p3, info)) {
            die_error(sock, 501, "Not implemented");
        }
    }
    if (strcasecmp(info->http_ver, "HTTP/1.1") == 0 && !info->found_host) {
        die_error(sock, 400, "Bad request");
    }
    return 1;
}

canonical_original_code:
int parse_headers(int sock, struct req_info *info) {
    char buf[1024];
    char *p1; char *p2; char *p3;
    int st;
    if ((st = recv_getline(sock, buf, 1024)) < 0) {
        die_error(sock, 400, "Bad request");
    } else if (st == 0) {
        close(sock);
        exit(0);
    }
    p1 = strstr(buf, " ");
    if (p1 == ((void *)0) || strncmp(buf, "GET", p1-buf) != 0) {
        die_error(sock, 405, "Method not allowed");
    }
    info->method = GET;
    ++p1;
    p2 = strstr(p1, " ");
    if (p2 == ((void *)0)) {
        die_error(sock, 400, "Bad request");
    }
    *p2 = '\0';
    info->resource = strdup(p1);
    info->http_ver = strdup(p2+1);
    if (strcmp(info->http_ver, "HTTP/1.1") == 0) {
        info->want_persistent = 1;
    }
    while (1) {
        if ((st = recv_getline(sock, buf, 1024)) < 0) {
            die_error(sock, 400, "Bad request");
        } else if (st == 0) {
            close(sock);
            exit(0);
        }
        if (buf[0] == 0) {
            break;
        }
        p1 = buf;
        while (((*__ctype_b_loc ())[(int) ((*p1))] & (unsigned short) _ISspace)) ++p1;
        p2 = p3 = strstr(p1, ":");
        --p2;
        while (((*__ctype_b_loc ())[(int) ((*p2))] & (unsigned short) _ISspace)) --p2;
        *(p2+1) = '\0';
        ++p3;
        while (((*__ctype_b_loc ())[(int) ((*p3))] & (unsigned short) _ISspace)) ++p3;
        if (!parse_single_header(p1, p3, info)) {
            die_error(sock, 501, "Not implemented");
        }
    }
    if (strcasecmp(info->http_ver, "HTTP/1.1") == 0 && !info->found_host) {
        die_error(sock, 400, "Bad request");
    }
    return 1;
}

variable_types: sock int

variable_types:
buf
char [1024]

variable_types: st int

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; }


original_code:
void setup_req_info(struct req_info *info) {
    info->method = INVALID;
    info->resource = ((void *)0);
    info->http_ver = ((void *)0);
    info->user_agent = ((void *)0);
    info->want_persistent = 0;
    info->found_host = 0;
    info->if_modified_since = ((void *)0);
}


decompiled_code:
void __fastcall clear_req_info(void **a1)
{
free(a1[1]);
free(a1[2]);
free(a1[3]);
free(a1[5]);
setup_req_info((__int64)a1);
}

canonical_decompiled_code:
void __fastcall func4(void **a1)
{
free(a1[1]);
free(a1[2]);
free(a1[3]);
free(a1[5]);
func3((__int64)a1);
}

original_code:
void clear_req_info(struct req_info *info) {
    free(info->resource);
    free(info->http_ver);
    free(info->user_agent);
    free(info->if_modified_since);
    setup_req_info(info);
}


decompiled_code:
char *__fastcall parse_time(char *s, struct tm *tp)
{
char *result; // rax

result = strptime(s, "%a, %d %b %Y %T GMT", tp);
if ( !result )
{
result = strptime(s, "%a, %d-%b-%y %T GMT", tp);
if ( !result )
result = strptime(s, "%a %b %d %T %Y", tp);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *s, struct tm *tp)
{
char *result; // rax

result = strptime(s, "%a, %d %b %Y %T GMT", tp);
if ( !result )
{
result = strptime(s, "%a, %d-%b-%y %T GMT", tp);
if ( !result )
result = strptime(s, "%a %b %d %T %Y", tp);
}
return result;
}

original_code:
char *parse_time(char *timestr, struct tm *out) {
    char *ret;
    ret = strptime(timestr, "%a, %d %b %Y %T GMT", out);
    if (ret) return ret;
    ret = strptime(timestr, "%a, %d-%b-%y %T GMT", out);
    if (ret) return ret;
    ret = strptime(timestr, "%a %b %d %T %Y", out);
    return ret;
}

variable_types:
timestr
char *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; } *

variable_types:
ret
char *

return_type: char *


match

repo: marcomorain/tcat

decompiled_code:
_BOOL8 __fastcall match(char *s1, const char *a2, const char *a3)
{
int v4; // edx
_BOOL8 result; // rax

v4 = strcmp(s1, a2);
result = 1LL;
if ( v4 )
result = strcmp(s1, a3) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(char *s1, const char *a2, const char *a3)
{
int v4; // edx
_BOOL8 result; // rax

v4 = strcmp(s1, a2);
result = 1LL;
if ( v4 )
result = strcmp(s1, a3) == 0;
return result;
}

original_code:
static int match(const char* x, const char* a, const char* b) {
  return (!strcmp(x, a)) || (!strcmp(x, b));
}

canonical_original_code:
static int match(char *x, char *a, char *b) {
  return (!strcmp(x, a)) || (!strcmp(x, b));
}

variable_types:
x
char *

variable_types:
a
char *

variable_types:
b
char *