decompiled_code:
size_t __fastcall fw_read(FILE *stream, void *ptr, __int16 a3)
{
return fread(ptr, 1uLL, a3, stream);
}

canonical_decompiled_code:
size_t __fastcall func1(FILE *stream, void *ptr, __int16 a3)
{
return fread(ptr, 1uLL, a3, stream);
}

original_code:
int fw_read(void *context, void *buffer, int16_t bytes)
{
    return fread(buffer, 1, bytes, context);
}

canonical_original_code:
int fw_read(void *context, void *buffer, short bytes)
{
    return fread(buffer, 1, bytes, context);
}

variable_types:
context
void *

variable_types:
buffer
void *

variable_types: bytes short


decompiled_code:
__int64 __fastcall jsll_rand(unsigned __int64 *a1)
{
__int64 v1; // r12
unsigned int v2; // ebx
__int64 result; // rax

v1 = (unsigned int)rand();
v2 = rand();
result = (unsigned int)rand();
*a1 = (v1 << 33) ^ ((unsigned int)result + ((unsigned __int64)v2 << 16));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int64 *a1)
{
__int64 v1; // r12
unsigned int v2; // ebx
__int64 result; // rax

v1 = (unsigned int)rand();
v2 = rand();
result = (unsigned int)rand();
*a1 = (v1 << 33) ^ ((unsigned int)result + ((unsigned __int64)v2 << 16));
return result;
}

canonical_original_code:
void jsll_rand(unsigned long *n)
{
 *n = ((unsigned long)(unsigned int) rand() << 33)
  ^ ((unsigned long)(unsigned int) rand() << 16)
  + (unsigned int) rand();
}

variable_types:
n
unsigned long *

return_type: void


decompiled_code:
int jsll_gen()
{
unsigned int i; // ebx
const char *v1; // rcx
const char *v2; // rsi
unsigned int v3; // ebp
const char *v4; // rcx
const char *v5; // rsi
__int64 v7; // [rsp+0h] [rbp-38h] BYREF
unsigned __int64 v8[6]; // [rsp+8h] [rbp-30h] BYREF

puts("// file generated by jsll_gen.c on a system with 64-bit integers");
puts("");
printf("#define SHIFT_BITS %u\n", 13LL);
puts("typedef struct testrec_t {");
puts(" JSInt64 a, b, add, sub, mul, and, or, xor, not, neg;");
puts(" JSInt64 shl, shr, ushr;");
puts(" int32_t l2i;");
puts(" uint32_t l2ui;");
puts(" JSInt64 i2l;");
puts(" JSUint64 ui2l;");
puts(" const char *hexstr, *decstr, *udecstr;");
puts(" bool_t gtu, ltu, gt, lt;");
puts("} testrec_t;");
puts("");
puts("const testrec_t tests[] = {");
for ( i = 0; i != 20; ++i )
{
if ( i )
jsll_rand(v8);
else
v8[0] = 0LL;
jsll_rand((unsigned __int64 *)&v7);
printf("{ // record %u\n\t", i);
printf("JSLL_INIT( 0x%08x, 0x%08x )", HIDWORD(v8[0]), v8[0]);
printf(",\t// a\n\t");
printf("JSLL_INIT( 0x%08x, 0x%08x )", HIDWORD(v7), v7);
printf(",\t// b\n\t");
printf("JSLL_INIT( 0x%08x, 0x%08x )", (v8[0] + v7) >> 32, v8[0] + v7);
printf(",\t// a %s b\n\t", "+");
printf("JSLL_INIT( 0x%08x, 0x%08x )", (v8[0] - v7) >> 32, v8[0] - v7);
printf(",\t// a %s b\n\t", (const char *)asc_402134);
printf("JSLL_INIT( 0x%08x, 0x%08x )", (v7 * v8[0]) >> 32, v7 * v8[0]);
printf(",\t// a %s b\n\t", &asc_402134[1]);
printf("JSLL_INIT( 0x%08x, 0x%08x )", (v7 & v8[0]) >> 32, v7 & v8[0]);
printf(",\t// a %s b\n\t", &asc_402134[2]);
printf("JSLL_INIT( 0x%08x, 0x%08x )", (v7 | v8[0]) >> 32, v7 | v8[0]);
printf(",\t// a %s b\n\t", &asc_402134[3]);
printf("JSLL_INIT( 0x%08x, 0x%08x )", (v7 ^ v8[0]) >> 32, v7 ^ v8[0]);
printf(",\t// a %s b\n\t", &asc_402134[4]);
printf("JSLL_INIT( 0x%08x, 0x%08x )", ~v8[0] >> 32, ~v8[0]);
printf(",\t// %sa\n\t", &asc_402134[5]);
printf("JSLL_INIT( 0x%08x, 0x%08x )", -v8[0] >> 32, -v8[0]);
printf(",\t// %sa\n\t", (const char *)asc_402134);
printf("JSLL_INIT( 0x%08x, 0x%08x )", v8[0] << 13 >> 32, v8[0] << 13);
printf(",\t// a << %u\n\t", 13LL);
printf("JSLL_INIT( 0x%08x, 0x%08x )", (unsigned __int64)((__int64)v8[0] >> 13) >> 32, (__int64)v8[0] >> 13);
printf(",\t// a >> %u (signed)\n\t", 13LL);
printf("JSLL_INIT( 0x%08x, 0x%08x )", v8[0] >> 45, v8[0] >> 13);
printf(",\t// a >> %u (unsigned)\n\t", 13LL);
v3 = v8[0];
printf("%d, UINT32_C(%u),\t// (int32_t) a, (uint32_t) a\n\t", LODWORD(v8[0]), LODWORD(v8[0]));
printf("JSLL_INIT( 0x%08x, 0x%08x )", (unsigned __int64)(int)v3 >> 32, (int)v3);
printf(",\t// (int64_t)(int32_t)a\n\t");
printf("JSLL_INIT( 0x%08x, 0x%08x )", 0LL, v3);
printf(",\t// (uint64_t)(uint32_t)a\n\t");
printf("\"%016lx\",\t// a (hexadecimal)\n\t", v8[0]);
printf("\"%ld\",\t// a (signed decimal)\n\t", v8[0]);
printf("\"%lu\",\t// a (unsigned decimal)\n\t", v8[0]);
v4 = "FALSE";
if ( v8[0] < v7 )
v4 = "TRUE";
v5 = "FALSE";
if ( v8[0] > v7 )
v5 = "TRUE";
printf("%s, %s,\t// a > b, a < b (unsigned)\n", v5, v4);
if ( (__int64)v8[0] < v7 )
{
v1 = "TRUE";
v2 = "FALSE";
}
else
{
v1 = "FALSE";
v2 = "FALSE";
if ( (__int64)v8[0] > v7 )
v2 = "TRUE";
}
printf("\t%s, %s,\t// a > b, a < b (signed)\n", v2, v1);
puts("},");
}
return puts("};");
}

canonical_decompiled_code:
int func8()
{
unsigned int i; // ebx
const char *v1; // rcx
const char *v2; // rsi
unsigned int v3; // ebp
const char *v4; // rcx
const char *v5; // rsi
__int64 v7; // [rsp+0h] [rbp-38h] BYREF
unsigned __int64 v8[6]; // [rsp+8h] [rbp-30h] BYREF

puts("// file generated by jsll_gen.c on a system with 64-bit integers");
puts("");
printf("#define SHIFT_BITS %u\n", 13LL);
puts("typedef struct testrec_t {");
puts(" JSInt64 a, b, add, sub, mul, and, or, xor, not, neg;");
puts(" JSInt64 shl, shr, ushr;");
puts(" int32_t l2i;");
puts(" uint32_t l2ui;");
puts(" JSInt64 i2l;");
puts(" JSUint64 ui2l;");
puts(" const char *hexstr, *decstr, *udecstr;");
puts(" bool_t gtu, ltu, gt, lt;");
puts("} testrec_t;");
puts("");
puts("const testrec_t tests[] = {");
for ( i = 0; i != 20; ++i )
{
if ( i )
func7(v8);
else
v8[0] = 0LL;
func7((unsigned __int64 *)&v7);
printf("{ // record %u\n\t", i);
printf("JSLL_INIT( 0x%08x, 0x%08x )", HIDWORD(v8[0]), v8[0]);
printf(",\t// a\n\t");
printf("JSLL_INIT( 0x%08x, 0x%08x )", HIDWORD(v7), v7);
printf(",\t// b\n\t");
printf("JSLL_INIT( 0x%08x, 0x%08x )", (v8[0] + v7) >> 32, v8[0] + v7);
printf(",\t// a %s b\n\t", "+");
printf("JSLL_INIT( 0x%08x, 0x%08x )", (v8[0] - v7) >> 32, v8[0] - v7);
printf(",\t// a %s b\n\t", (const char *)asc_402134);
printf("JSLL_INIT( 0x%08x, 0x%08x )", (v7 * v8[0]) >> 32, v7 * v8[0]);
printf(",\t// a %s b\n\t", &asc_402134[1]);
printf("JSLL_INIT( 0x%08x, 0x%08x )", (v7 & v8[0]) >> 32, v7 & v8[0]);
printf(",\t// a %s b\n\t", &asc_402134[2]);
printf("JSLL_INIT( 0x%08x, 0x%08x )", (v7 | v8[0]) >> 32, v7 | v8[0]);
printf(",\t// a %s b\n\t", &asc_402134[3]);
printf("JSLL_INIT( 0x%08x, 0x%08x )", (v7 ^ v8[0]) >> 32, v7 ^ v8[0]);
printf(",\t// a %s b\n\t", &asc_402134[4]);
printf("JSLL_INIT( 0x%08x, 0x%08x )", ~v8[0] >> 32, ~v8[0]);
printf(",\t// %sa\n\t", &asc_402134[5]);
printf("JSLL_INIT( 0x%08x, 0x%08x )", -v8[0] >> 32, -v8[0]);
printf(",\t// %sa\n\t", (const char *)asc_402134);
printf("JSLL_INIT( 0x%08x, 0x%08x )", v8[0] << 13 >> 32, v8[0] << 13);
printf(",\t// a << %u\n\t", 13LL);
printf("JSLL_INIT( 0x%08x, 0x%08x )", (unsigned __int64)((__int64)v8[0] >> 13) >> 32, (__int64)v8[0] >> 13);
printf(",\t// a >> %u (signed)\n\t", 13LL);
printf("JSLL_INIT( 0x%08x, 0x%08x )", v8[0] >> 45, v8[0] >> 13);
printf(",\t// a >> %u (unsigned)\n\t", 13LL);
v3 = v8[0];
printf("%d, UINT32_C(%u),\t// (int32_t) a, (uint32_t) a\n\t", LODWORD(v8[0]), LODWORD(v8[0]));
printf("JSLL_INIT( 0x%08x, 0x%08x )", (unsigned __int64)(int)v3 >> 32, (int)v3);
printf(",\t// (int64_t)(int32_t)a\n\t");
printf("JSLL_INIT( 0x%08x, 0x%08x )", 0LL, v3);
printf(",\t// (uint64_t)(uint32_t)a\n\t");
printf("\"%016lx\",\t// a (hexadecimal)\n\t", v8[0]);
printf("\"%ld\",\t// a (signed decimal)\n\t", v8[0]);
printf("\"%lu\",\t// a (unsigned decimal)\n\t", v8[0]);
v4 = "FALSE";
if ( v8[0] < v7 )
v4 = "TRUE";
v5 = "FALSE";
if ( v8[0] > v7 )
v5 = "TRUE";
printf("%s, %s,\t// a > b, a < b (unsigned)\n", v5, v4);
if ( (__int64)v8[0] < v7 )
{
v1 = "TRUE";
v2 = "FALSE";
}
else
{
v1 = "FALSE";
v2 = "FALSE";
if ( (__int64)v8[0] > v7 )
v2 = "TRUE";
}
printf("\t%s, %s,\t// a > b, a < b (signed)\n", v2, v1);
puts("},");
}
return puts("};");
}

canonical_original_code:
void jsll_gen()
{
 int i;
 unsigned long a; unsigned long b; unsigned long c;
 int i32;
 unsigned int ui32;
 puts( "// file generated by jsll_gen.c on a system with 64-bit integers");
 puts( "");
 printf( "#define SHIFT_BITS %u\n", 13);
 puts( "typedef struct testrec_t {");
 puts( "   JSInt64 a, b, add, sub, mul, and, or, xor, not, neg;");
 puts( "   JSInt64 shl, shr, ushr;");
 puts( "   int32_t l2i;");
 puts( "   uint32_t l2ui;");
 puts( "   JSInt64 i2l;");
 puts( "   JSUint64 ui2l;");
 puts( "   const char *hexstr, *decstr, *udecstr;");
 puts( "   bool_t gtu, ltu, gt, lt;");
 puts( "} testrec_t;");
 puts( "");
 puts( "const testrec_t tests[] = {");
 for (i = 0; i < 20; ++i)
 {
  if (i)
  {
   jsll_rand( &a);
  }
  else
  {
   a = 0;
  }
  jsll_rand( &b);
  printf( "{ // record %u\n\t", i);
  printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(a >> 32), (unsigned int)(a));
  printf( ",\t// a\n\t");
  printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(b >> 32), (unsigned int)(b));
  printf( ",\t// b\n\t");
  { c = a + b; printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c)); printf( ",\t// a %s b\n\t", "+"); };
  { c = a - b; printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c)); printf( ",\t// a %s b\n\t", "-"); };
  { c = a * b; printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c)); printf( ",\t// a %s b\n\t", "*"); };
  { c = a & b; printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c)); printf( ",\t// a %s b\n\t", "&"); };
  { c = a | b; printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c)); printf( ",\t// a %s b\n\t", "|"); };
  { c = a ^ b; printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c)); printf( ",\t// a %s b\n\t", "^"); };
  { c = ~ a; printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c)); printf( ",\t// %sa\n\t", "~"); };
  { c = - a; printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c)); printf( ",\t// %sa\n\t", "-"); };
  c = a << 13;
  printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c));
  printf( ",\t// a << %u\n\t", 13);
  c = (long) a >> 13;
  printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c));
  printf( ",\t// a >> %u (signed)\n\t", 13);
  c = a >> 13;
  printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c));
  printf( ",\t// a >> %u (unsigned)\n\t", 13);
  i32 = (int) a;
  ui32 = (unsigned int) a;
  printf( "%" "d" ", UINT32_C(%" "u"
   "),\t// (int32_t) a, (uint32_t) a\n\t", i32, ui32);
  c = (long) i32;
  printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c));
  printf( ",\t// (int64_t)(int32_t)a\n\t");
  c = (unsigned long) ui32;
  printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(c >> 32), (unsigned int)(c));
  printf( ",\t// (uint64_t)(uint32_t)a\n\t");
  printf( "\"%016" "l" "x" "\",\t// a (hexadecimal)\n\t", a);
  printf( "\"%" "l" "d" "\",\t// a (signed decimal)\n\t", a);
  printf( "\"%" "l" "u" "\",\t// a (unsigned decimal)\n\t", a);
  printf ("%s, %s,\t// a > b, a < b (unsigned)\n",
   (a > b) ? "TRUE" : "FALSE", (a < b) ? "TRUE" : "FALSE");
  printf ("\t%s, %s,\t// a > b, a < b (signed)\n",
   ((long)a > (long)b) ? "TRUE" : "FALSE", ((long)a < (long)b) ? "TRUE" : "FALSE");
  puts( "},");
 }
 puts( "};");
}

variable_types: i int

variable_types:
a
unsigned long

variable_types:
b
unsigned long

variable_types:
c
unsigned long


decompiled_code:
int jsll_gen_shift()
{
unsigned int i; // er14
unsigned __int64 v1; // rax
unsigned int j; // ebx
unsigned __int64 v3; // r13
unsigned __int64 v4; // r12
__int64 v5; // rbp
unsigned __int64 v7[8]; // [rsp+8h] [rbp-40h] BYREF

puts("typedef struct shiftrec_t {");
puts(" JSUint64 shl, ushr;");
puts(" JSInt64 shr;");
puts("} shiftrec_t;");
puts("typedef struct shifttest_t {");
puts(" JSUint64 base;");
puts(" shiftrec_t shift[63];");
puts("} shifttest_t;");
puts("const shifttest_t shift_tests[] = {");
for ( i = 0; i != 4; ++i )
{
jsll_rand(v7);
if ( (i & 1) != 0 )
v1 = v7[0] | 0x8000000000000000LL;
else
v1 = v7[0] & 0x7FFFFFFFFFFFFFFFLL;
v7[0] = v1;
printf("\t{ ");
printf("JSLL_INIT( 0x%08x, 0x%08x )", HIDWORD(v7[0]), v7[0]);
printf(",\t// record %u\n", i);
puts("\t {");
for ( j = 1; j != 64; ++j )
{
v3 = v7[0] << j;
v4 = v7[0] >> j;
v5 = (__int64)v7[0] >> j;
printf("\t\t{ ");
printf("JSLL_INIT( 0x%08x, 0x%08x )", HIDWORD(v3), (unsigned int)v3);
printf(",\t// shift left %u\n\t\t ", j);
printf("JSLL_INIT( 0x%08x, 0x%08x )", HIDWORD(v4), (unsigned int)v4);
printf(",\t// shift right (logical/unsigned)\n\t\t ");
printf("JSLL_INIT( 0x%08x, 0x%08x )", v5 >> 32, (unsigned int)v5);
puts("\t// shift right (arithmetic/signed)\n\t\t},");
}
puts("\t },\n\t},");
}
return puts("};");
}

canonical_decompiled_code:
int func9()
{
unsigned int i; // er14
unsigned __int64 v1; // rax
unsigned int j; // ebx
unsigned __int64 v3; // r13
unsigned __int64 v4; // r12
__int64 v5; // rbp
unsigned __int64 v7[8]; // [rsp+8h] [rbp-40h] BYREF

puts("typedef struct shiftrec_t {");
puts(" JSUint64 shl, ushr;");
puts(" JSInt64 shr;");
puts("} shiftrec_t;");
puts("typedef struct shifttest_t {");
puts(" JSUint64 base;");
puts(" shiftrec_t shift[63];");
puts("} shifttest_t;");
puts("const shifttest_t shift_tests[] = {");
for ( i = 0; i != 4; ++i )
{
func7(v7);
if ( (i & 1) != 0 )
v1 = v7[0] | 0x8000000000000000LL;
else
v1 = v7[0] & 0x7FFFFFFFFFFFFFFFLL;
v7[0] = v1;
printf("\t{ ");
printf("JSLL_INIT( 0x%08x, 0x%08x )", HIDWORD(v7[0]), v7[0]);
printf(",\t// record %u\n", i);
puts("\t {");
for ( j = 1; j != 64; ++j )
{
v3 = v7[0] << j;
v4 = v7[0] >> j;
v5 = (__int64)v7[0] >> j;
printf("\t\t{ ");
printf("JSLL_INIT( 0x%08x, 0x%08x )", HIDWORD(v3), (unsigned int)v3);
printf(",\t// shift left %u\n\t\t ", j);
printf("JSLL_INIT( 0x%08x, 0x%08x )", HIDWORD(v4), (unsigned int)v4);
printf(",\t// shift right (logical/unsigned)\n\t\t ");
printf("JSLL_INIT( 0x%08x, 0x%08x )", v5 >> 32, (unsigned int)v5);
puts("\t// shift right (arithmetic/signed)\n\t\t},");
}
puts("\t },\n\t},");
}
return puts("};");
}

original_code:
void jsll_gen_shift( void)
{
 uint64_t base, shl, ushr;
 int64_t shr;
 int i;
 unsigned char shift;
 puts( "typedef struct shiftrec_t {");
 puts( "   JSUint64 shl, ushr;");
 puts( "   JSInt64 shr;");
 puts( "} shiftrec_t;");
 puts( "typedef struct shifttest_t {");
 puts( "   JSUint64 base;");
 puts( "   shiftrec_t shift[63];");
 puts( "} shifttest_t;");
 puts( "const shifttest_t shift_tests[] = {");
 for (i = 0; i < 4; ++i)
 {
  jsll_rand( &base);
  if (i & 1)
  {
   base |= (1UL << 63);
  }
  else
  {
   base &= ~(1UL << 63);
  }
  printf( "\t{ ");
  printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (uint32_t)(base >> 32), (uint32_t)(base));
  printf( ",\t// record %u\n", i);
  puts( "\t {");
  for (shift = 1; shift < 64; ++shift)
  {
   shl = base << shift;
   ushr = base >> shift;
   shr = (int64_t)base >> shift;
   printf( "\t\t{ ");
   printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (uint32_t)(shl >> 32), (uint32_t)(shl));
   printf( ",\t// shift left %u\n\t\t  ", shift);
   printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (uint32_t)(ushr >> 32), (uint32_t)(ushr));
   printf( ",\t// shift right (logical/unsigned)\n\t\t  ");
   printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (uint32_t)(shr >> 32), (uint32_t)(shr));
   printf( "\t// shift right (arithmetic/signed)\n\t\t},\n");
  }
  puts( "\t },\n\t},");
 }
 puts( "};");
}

canonical_original_code:
void jsll_gen_shift()
{
 unsigned long base; unsigned long shl; unsigned long ushr;
 long shr;
 int i;
 unsigned char shift;
 puts( "typedef struct shiftrec_t {");
 puts( "   JSUint64 shl, ushr;");
 puts( "   JSInt64 shr;");
 puts( "} shiftrec_t;");
 puts( "typedef struct shifttest_t {");
 puts( "   JSUint64 base;");
 puts( "   shiftrec_t shift[63];");
 puts( "} shifttest_t;");
 puts( "const shifttest_t shift_tests[] = {");
 for (i = 0; i < 4; ++i)
 {
  jsll_rand( &base);
  if (i & 1)
  {
   base |= (1UL << 63);
  }
  else
  {
   base &= ~(1UL << 63);
  }
  printf( "\t{ ");
  printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(base >> 32), (unsigned int)(base));
  printf( ",\t// record %u\n", i);
  puts( "\t {");
  for (shift = 1; shift < 64; ++shift)
  {
   shl = base << shift;
   ushr = base >> shift;
   shr = (long)base >> shift;
   printf( "\t\t{ ");
   printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(shl >> 32), (unsigned int)(shl));
   printf( ",\t// shift left %u\n\t\t  ", shift);
   printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(ushr >> 32), (unsigned int)(ushr));
   printf( ",\t// shift right (logical/unsigned)\n\t\t  ");
   printf( "JSLL_INIT( 0x%08" "x" ", 0x%08" "x" " )", (unsigned int)(shr >> 32), (unsigned int)(shr));
   printf( "\t// shift right (arithmetic/signed)\n\t\t},\n");
  }
  puts( "\t },\n\t},");
 }
 puts( "};");
}

variable_types:
base
unsigned long

variable_types:
shl
unsigned long

variable_types:
ushr
unsigned long

variable_types: shr long

variable_types:
shift
unsigned char


main

canonical_name: main

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

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

original_code:
int main()
{
 jsll_gen();
 jsll_gen_shift();
 return 0;
}

return_type: int


decompiled_code:
int xbee_term_console_init()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

if ( init_0 )
{
init_0 = 0;
tcgetattr(0, &ttystate_orig);
atexit(xbee_term_console_restore);
}
tcgetattr(0, &v1);
v1.c_lflag &= 0xFFFF7FB5;
v1.c_cc[6] = 0;
return tcsetattr(0, 0, &v1);
}

canonical_decompiled_code:
int func0()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

if ( init_0 )
{
init_0 = 0;
tcgetattr(0, &ttystate_orig);
atexit(xbee_term_console_restore);
}
tcgetattr(0, &v1);
v1.c_lflag &= 0xFFFF7FB5;
v1.c_cc[6] = 0;
return tcsetattr(0, 0, &v1);
}

original_code:
void xbee_term_console_init( void)
{
    static int init = 1;
    struct termios ttystate;
    if (init)
    {
        init = 0;
        tcgetattr( 0, &_ttystate_orig);
        atexit( xbee_term_console_restore);
    }
    tcgetattr(0, &ttystate);
    ttystate.c_lflag &= ~(0000010 | 0000100 | 0000002 | 0100000);
    ttystate.c_cc[6] = 0;
    tcsetattr(0, 0, &ttystate);
}

canonical_original_code:
void xbee_term_console_init()
{
    static int init = 1;
    struct termios ttystate;
    if (init)
    {
        init = 0;
        tcgetattr( 0, &_ttystate_orig);
        atexit( xbee_term_console_restore);
    }
    tcgetattr(0, &ttystate);
    ttystate.c_lflag &= ~(0000010 | 0000100 | 0000002 | 0100000);
    ttystate.c_cc[6] = 0;
    tcsetattr(0, 0, &ttystate);
}

variable_types: init int

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


decompiled_code:
int __fastcall xbee_term_set_color(int a1)
{
const char *v2; // rdi

v2 = "\x1B[31;1m";
if ( a1 != 2 )
{
v2 = "\x1B[32;1m";
if ( a1 != 3 )
{
v2 = "\x1B[0m";
if ( a1 == 1 )
v2 = "\x1B[36;1m";
}
}
fputs(v2, stdout);
return fflush(stdout);
}

original_code:
void xbee_term_set_color( enum char_source source)
{
   const char *color;
   switch (source)
   {
      case SOURCE_KEYBOARD:
         color = "\x1B[36;1m";
         break;
      case SOURCE_STATUS:
         color = "\x1B[32;1m";
         break;
      case SOURCE_SERIAL:
         color = "\x1B[31;1m";
         break;
      default:
         color = "\x1B[0m";
         break;
   }
   fputs( color, stdout);
   fflush( stdout);
}

canonical_original_code:
void xbee_term_set_color(enum char_source source)
{
   char *color;
   switch (source)
   {
      case SOURCE_KEYBOARD:
         color = "\x1B[36;1m";
         break;
      case SOURCE_STATUS:
         color = "\x1B[32;1m";
         break;
      case SOURCE_SERIAL:
         color = "\x1B[31;1m";
         break;
      default:
         color = "\x1B[0m";
         break;
   }
   fputs( color, stdout);
   fflush( stdout);
}

variable_types: enum char_source { SOURCE_UNKNOWN=0, SOURCE_KEYBOARD=1, SOURCE_SERIAL=2, SOURCE_STATUS=3 }

variable_types:
color
char *


decompiled_code:
void xbee_term_console_restore(void)
{
xbee_term_set_color(0);
tcsetattr(0, 0, &ttystate_orig);
}

canonical_decompiled_code:
void func2(void)
{
func1(0);
tcsetattr(0, 0, &ttystate_orig);
}

original_code:
void xbee_term_console_restore( void)
{
   xbee_term_set_color(SOURCE_UNKNOWN);
   tcsetattr(0, 0, &_ttystate_orig);
}

canonical_original_code:
void xbee_term_console_restore()
{
   xbee_term_set_color(SOURCE_UNKNOWN);
   tcsetattr(0, 0, &_ttystate_orig);
}


decompiled_code:
__int64 xbee_term_getchar()
{
unsigned int v0; // ebx

v0 = getc(stdin);
if ( v0 == -1 )
{
if ( feof(stdin) )
{
clearerr(stdin);
usleep(0x1F4u);
v0 = -11;
}
else if ( ferror(stdin) )
{
v0 = -5;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebx

v0 = getc(stdin);
if ( v0 == -1 )
{
if ( feof(stdin) )
{
clearerr(stdin);
usleep(0x1F4u);
v0 = -11;
}
else if ( ferror(stdin) )
{
v0 = -5;
}
}
return v0;
}

original_code:
int xbee_term_getchar(void)
{
   int c = getc(stdin);
   if (c == (-1) && feof(stdin)) {
      clearerr(stdin);
      usleep(500);
      return -11;
   }
   if (c == (-1) && ferror(stdin)) {
      return -5;
   }
   return c;
}

canonical_original_code:
int xbee_term_getchar()
{
   int c = getc(stdin);
   if (c == (-1) && feof(stdin)) {
      clearerr(stdin);
      usleep(500);
      return -11;
   }
   if (c == (-1) && ferror(stdin)) {
      return -5;
   }
   return c;
}

variable_types: c int


original_code:
void parse_serial_arguments( int argc, char *argv[], xbee_serial_t *serial)
{
    int i;
    uint32_t baud;
    memset( serial, 0, sizeof *serial);
    serial->baudrate = 115200;
    for (i = 1; i < argc; ++i)
    {
        if (strncmp( argv[i], "/dev", 4) == 0)
        {
            strncpy( serial->device, argv[i], (sizeof serial->device) - 1);
            serial->device[(sizeof serial->device) - 1] = '\0';
        }
        if ( (baud = (uint32_t) strtoul( argv[i], ((void *)0), 0)) > 0)
        {
            serial->baudrate = baud;
        }
    }
    while (*serial->device == '\0')
    {
        printf( "Connect to which device? ");
        fgets( serial->device, sizeof serial->device, stdin);
        serial->device[strcspn(serial->device, "\r\n")] = '\0';
    }
}

canonical_original_code:
void parse_serial_arguments(int argc, char *argv[], struct xbee_serial_t *serial)
{
    int i;
    unsigned int baud;
    memset( serial, 0, sizeof *serial);
    serial->baudrate = 115200;
    for (i = 1; i < argc; ++i)
    {
        if (strncmp( argv[i], "/dev", 4) == 0)
        {
            strncpy( serial->device, argv[i], (sizeof serial->device) - 1);
            serial->device[(sizeof serial->device) - 1] = '\0';
        }
        if ( (baud = (unsigned int) strtoul( argv[i], ((void *)0), 0)) > 0)
        {
            serial->baudrate = baud;
        }
    }
    while (*serial->device == '\0')
    {
        printf( "Connect to which device? ");
        fgets( serial->device, sizeof serial->device, stdin);
        serial->device[strcspn(serial->device, "\r\n")] = '\0';
    }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct xbee_serial_t { unsigned int baudrate; int fd; char device[40]; } *

variable_types:
baud
unsigned int


repo: digsig-ng/dsngctl

decompiled_code:
__int64 __fastcall dsng_start(const char *a1)
{
int v1; // eax
int v2; // ebx
int v3; // ebp
unsigned int v4; // er12

v1 = open(a1, 0);
if ( v1 < 0 )
{
fprintf(stderr, "dsngctl: %s: unable to open public key\n", "dsng_start");
v4 = -1;
}
else
{
v2 = v1;
v3 = open("/sys/digsig/key", 1);
if ( (unsigned int)check_pubkey(v2) )
{
fprintf(stderr, "dsngctl: %s: public key invalid\n", "dsng_start");
v4 = -1;
}
else if ( (unsigned int)get_mpi(v2, v3) )
{
fprintf(stderr, "dsngctl: %s: get_mpi(..., ..., 'n') failed\n", "dsng_start");
v4 = -1;
}
else
{
v4 = get_mpi(v2, v3);
if ( v4 )
{
fprintf(stderr, "dsngctl: %s: get_mpi(..., ..., 'e') failed\n", "dsng_start");
v4 = -1;
}
}
close(v3);
close(v2);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
int v1; // eax
int v2; // ebx
int v3; // ebp
unsigned int v4; // er12

v1 = open(a1, 0);
if ( v1 < 0 )
{
fprintf(stderr, "dsngctl: %s: unable to open public key\n", "dsng_start");
v4 = -1;
}
else
{
v2 = v1;
v3 = open("/sys/digsig/key", 1);
if ( (unsigned int)func10(v2) )
{
fprintf(stderr, "dsngctl: %s: public key invalid\n", "dsng_start");
v4 = -1;
}
else if ( (unsigned int)func11(v2, v3) )
{
fprintf(stderr, "dsngctl: %s: get_mpi(..., ..., 'n') failed\n", "dsng_start");
v4 = -1;
}
else
{
v4 = func11(v2, v3);
if ( v4 )
{
fprintf(stderr, "dsngctl: %s: get_mpi(..., ..., 'e') failed\n", "dsng_start");
v4 = -1;
}
}
close(v3);
close(v2);
}
return v4;
}

original_code:
int dsng_start(char *pkey_path)
{
 int ret = -1;
 int pkey_file, mod_file;
 pkey_file = open(pkey_path, 00);
 if (pkey_file < 0) {
  fprintf(stderr, "dsngctl: %s: unable to open public key\n", __func__);
  goto cleanup_done;
 }
 mod_file = open("/sys/digsig/key", 01);
 if (pkey_file < 0) {
  fprintf(stderr, "dsngctl: %s: unable to open module char device\n",
   __func__);
  goto cleanup_pkey;
 }
 if (check_pubkey(pkey_file) != 0) {
  fprintf(stderr, "dsngctl: %s: public key invalid\n", __func__);
  goto cleanup_mod;
 }
 if (get_mpi(pkey_file, mod_file, 'n') != 0) {
  fprintf(stderr, "dsngctl: %s: get_mpi(..., ..., 'n') failed\n",
   __func__);
  goto cleanup_mod;
 }
 if (get_mpi(pkey_file, mod_file, 'e') != 0) {
  fprintf(stderr, "dsngctl: %s: get_mpi(..., ..., 'e') failed\n",
   __func__);
  goto cleanup_mod;
 }
 ret = 0;
cleanup_mod:
 close(mod_file);
cleanup_pkey:
 close(pkey_file);
cleanup_done:
 return ret;
}

canonical_original_code:
int dsng_start(char *pkey_path)
{
 int ret = -1;
 int pkey_file; int mod_file;
 pkey_file = open(pkey_path, 00);
 if (pkey_file < 0) {
  fprintf(stderr, "dsngctl: %s: unable to open public key\n", __func__);
  goto cleanup_done;
 }
 mod_file = open("/sys/digsig/key", 01);
 if (pkey_file < 0) {
  fprintf(stderr, "dsngctl: %s: unable to open module char device\n",
   __func__);
  goto cleanup_pkey;
 }
 if (check_pubkey(pkey_file) != 0) {
  fprintf(stderr, "dsngctl: %s: public key invalid\n", __func__);
  goto cleanup_mod;
 }
 if (get_mpi(pkey_file, mod_file, 'n') != 0) {
  fprintf(stderr, "dsngctl: %s: get_mpi(..., ..., 'n') failed\n",
   __func__);
  goto cleanup_mod;
 }
 if (get_mpi(pkey_file, mod_file, 'e') != 0) {
  fprintf(stderr, "dsngctl: %s: get_mpi(..., ..., 'e') failed\n",
   __func__);
  goto cleanup_mod;
 }
 ret = 0;
cleanup_mod:
 close(mod_file);
cleanup_pkey:
 close(pkey_file);
cleanup_done:
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 digsig_is_loaded()
{
unsigned int v0; // ebx
struct stat v2; // [rsp+0h] [rbp-128h] BYREF
struct stat v3; // [rsp+90h] [rbp-98h] BYREF

if ( (unsigned int)stat("/sys/digsig/key", &v3) )
{
fprintf(stderr, "dsngctl: %s: could not stat /sys/digsig/key\n", "digsig_is_loaded");
v0 = 0;
}
else
{
v0 = 0;
if ( (unsigned int)stat("/sys/digsig/revoke", &v2) )
fprintf(stderr, "dsngctl: %s: could not stat /sys/digsig/revoke\n", "digsig_is_loaded");
else
v0 = 1;
}
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // ebx
struct stat v2; // [rsp+0h] [rbp-128h] BYREF
struct stat v3; // [rsp+90h] [rbp-98h] BYREF

if ( (unsigned int)func17("/sys/digsig/key", &v3) )
{
fprintf(stderr, "dsngctl: %s: could not stat /sys/digsig/key\n", "digsig_is_loaded");
v0 = 0;
}
else
{
v0 = 0;
if ( (unsigned int)func17("/sys/digsig/revoke", &v2) )
fprintf(stderr, "dsngctl: %s: could not stat /sys/digsig/revoke\n", "digsig_is_loaded");
else
v0 = 1;
}
return v0;
}

original_code:
int digsig_is_loaded()
{
 struct stat key_stat, revoke_stat;
 if (stat("/sys/digsig/key", &key_stat) != 0) {
  fprintf(stderr, "dsngctl: %s: could not stat /sys/digsig/key\n", __func__);
  return 0;
 }
 if (stat("/sys/digsig/revoke", &revoke_stat) != 0) {
  fprintf(stderr, "dsngctl: %s: could not stat /sys/digsig/revoke\n", __func__);
  return 0;
 }
 return 1;
}

canonical_original_code:
int digsig_is_loaded()
{
 struct stat key_stat; struct stat revoke_stat;
 if (stat("/sys/digsig/key", &key_stat) != 0) {
  fprintf(stderr, "dsngctl: %s: could not stat /sys/digsig/key\n", __func__);
  return 0;
 }
 if (stat("/sys/digsig/revoke", &revoke_stat) != 0) {
  fprintf(stderr, "dsngctl: %s: could not stat /sys/digsig/revoke\n", __func__);
  return 0;
 }
 return 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]; }

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]; }


decompiled_code:
__int64 digsig_is_initialized()
{
__int64 result; // rax
int v1; // eax
int v2; // ebx
char buf[16]; // [rsp+8h] [rbp-10h] BYREF

result = digsig_is_loaded();
if ( (_DWORD)result )
{
v1 = open("/sys/digsig/status", 0);
v2 = v1;
if ( v1 < 0 )
{
fprintf(stderr, "dsngctl: %s: could not open /sys/digsig/status\n", "digsig_is_initialized");
result = 0LL;
}
else if ( (int)read(v1, buf, 8uLL) < 0 )
{
fprintf(stderr, "dsngctl: %s: could not read /sys/digsig/status\n", "digsig_is_initialized");
close(v2);
result = 0LL;
}
else if ( !memcmp(buf, "1", 1uLL) )
{
close(v2);
result = 1LL;
}
else
{
result = 0LL;
if ( v2 > 0 )
{
close(v2);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax
int v1; // eax
int v2; // ebx
char buf[16]; // [rsp+8h] [rbp-10h] BYREF

result = func8();
if ( (_DWORD)result )
{
v1 = open("/sys/digsig/status", 0);
v2 = v1;
if ( v1 < 0 )
{
fprintf(stderr, "dsngctl: %s: could not open /sys/digsig/status\n", "digsig_is_initialized");
result = 0LL;
}
else if ( (int)read(v1, buf, 8uLL) < 0 )
{
fprintf(stderr, "dsngctl: %s: could not read /sys/digsig/status\n", "digsig_is_initialized");
close(v2);
result = 0LL;
}
else if ( !memcmp(buf, "1", 1uLL) )
{
close(v2);
result = 1LL;
}
else
{
result = 0LL;
if ( v2 > 0 )
{
close(v2);
result = 0LL;
}
}
}
return result;
}

original_code:
int digsig_is_initialized()
{
 int status_fd;
 int rcount;
 char status[8];
 if (!digsig_is_loaded())
  return 0;
 status_fd = open("/sys/digsig/status", 00);
 if (status_fd < 0) {
  fprintf(stderr, "dsngctl: %s: could not open /sys/digsig/status\n", __func__);
  return 0;
 }
 rcount = read(status_fd, status, 8);
 if (rcount < 0) {
  fprintf(stderr, "dsngctl: %s: could not read /sys/digsig/status\n", __func__);
  close(status_fd);
  return 0;
 }
 if (strncmp(status, "1", 1) == 0) {
  close(status_fd);
  return 1;
 }
 if (status_fd > 0)
  close(status_fd);
 return 0;
}

variable_types: rcount int

variable_types:
status
char [8]


decompiled_code:
__int64 __fastcall check_pubkey(int fd)
{
char v1; // al
__int64 result; // rax
int v3; // eax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

read(fd, buf, 1uLL);
if ( buf[0] >= 0 )
{
fprintf(stderr, "dsngctl: %s: bad packet tag byte: this is not an OpenPGP message\n", "check_pubkey");
result = 0xFFFFFFFFLL;
}
else if ( (buf[0] & 0x40) != 0 )
{
fprintf(stderr, "dsngctl: %s: packet tag: new packet headers are not supported\n", "check_pubkey");
result = 0xFFFFFFFFLL;
}
else if ( (buf[0] & 0x18) != 0 )
{
v1 = buf[0] & 3;
if ( (buf[0] & 3) == 1 )
{
v3 = 3;
}
else if ( v1 == 2 )
{
v3 = 5;
}
else
{
if ( v1 )
{
fprintf(stderr, "dsngctl: %s: packet tag: indefinite length headers are not supported\n", "check_pubkey");
return 0xFFFFFFFFLL;
}
v3 = 2;
}
lseek(fd, (unsigned int)(v3 - 1), 1);
read(fd, buf, 1uLL);
if ( buf[0] == 4 )
{
lseek(fd, 4LL, 1);
read(fd, buf, 1uLL);
if ( (buf[0] & 0xFD) == 1 )
{
result = 0LL;
}
else
{
fprintf(stderr, "dsngctl: %s: this is not an RSA key, or signatures not allowed\n", "check_pubkey");
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "dsngctl: %s: unsupported pkey version\n", "check_pubkey");
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "dsngctl: %s: packet tag: this is not a public key\n", "check_pubkey");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd)
{
char v1; // al
__int64 result; // rax
int v3; // eax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

read(fd, buf, 1uLL);
if ( buf[0] >= 0 )
{
fprintf(stderr, "dsngctl: %s: bad packet tag byte: this is not an OpenPGP message\n", "check_pubkey");
result = 0xFFFFFFFFLL;
}
else if ( (buf[0] & 0x40) != 0 )
{
fprintf(stderr, "dsngctl: %s: packet tag: new packet headers are not supported\n", "check_pubkey");
result = 0xFFFFFFFFLL;
}
else if ( (buf[0] & 0x18) != 0 )
{
v1 = buf[0] & 3;
if ( (buf[0] & 3) == 1 )
{
v3 = 3;
}
else if ( v1 == 2 )
{
v3 = 5;
}
else
{
if ( v1 )
{
fprintf(stderr, "dsngctl: %s: packet tag: indefinite length headers are not supported\n", "check_pubkey");
return 0xFFFFFFFFLL;
}
v3 = 2;
}
lseek(fd, (unsigned int)(v3 - 1), 1);
read(fd, buf, 1uLL);
if ( buf[0] == 4 )
{
lseek(fd, 4LL, 1);
read(fd, buf, 1uLL);
if ( (buf[0] & 0xFD) == 1 )
{
result = 0LL;
}
else
{
fprintf(stderr, "dsngctl: %s: this is not an RSA key, or signatures not allowed\n", "check_pubkey");
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "dsngctl: %s: unsupported pkey version\n", "check_pubkey");
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "dsngctl: %s: packet tag: this is not a public key\n", "check_pubkey");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int check_pubkey(int pkey_file)
{
 unsigned char c;
 unsigned int header_len;
 const int RSA_ENCRYPT_OR_SIGN = 1;
 const int RSA_SIGN = 3;
 const int CREATION_TIME_LENGTH = 4;
 read(pkey_file, &c, 1);
 if (!(c & 0x80)) {
  fprintf(stderr, "dsngctl: %s: bad packet tag byte: this is not an OpenPGP message\n", __func__);
  return -1;
 }
 if (c & 0x40) {
  fprintf(stderr, "dsngctl: %s: packet tag: new packet headers are not supported\n", __func__);
  return -1;
 }
 if (!(c & 0x18)) {
  fprintf(stderr, "dsngctl: %s: packet tag: this is not a public key\n", __func__);
  return -1;
 }
 switch (c & 0x03) {
 case 0:
  header_len = 2;
  break;
 case 1:
  header_len = 3;
  break;
 case 2:
  header_len = 5;
  break;
 case 3:
 default:
  fprintf(stderr, "dsngctl: %s: packet tag: indefinite length headers are not supported\n", __func__);
  return -1;
 }
 header_len--;
 lseek(pkey_file, header_len, 1);
 read(pkey_file, &c, 1);
 if (c != 4) {
  fprintf(stderr, "dsngctl: %s: unsupported pkey version\n",
   __func__);
  return -1;
 }
 lseek(pkey_file, CREATION_TIME_LENGTH, 1);
 read(pkey_file, &c, 1);
 if (c != RSA_ENCRYPT_OR_SIGN && c != RSA_SIGN) {
  fprintf(stderr, "dsngctl: %s: this is not an RSA key, or signatures not allowed\n", __func__);
  return -1;
 }
 return 0;
}

canonical_original_code:
int check_pubkey(int pkey_file)
{
 unsigned char c;
 unsigned int header_len;
 int RSA_ENCRYPT_OR_SIGN = 1;
 int RSA_SIGN = 3;
 int CREATION_TIME_LENGTH = 4;
 read(pkey_file, &c, 1);
 if (!(c & 0x80)) {
  fprintf(stderr, "dsngctl: %s: bad packet tag byte: this is not an OpenPGP message\n", __func__);
  return -1;
 }
 if (c & 0x40) {
  fprintf(stderr, "dsngctl: %s: packet tag: new packet headers are not supported\n", __func__);
  return -1;
 }
 if (!(c & 0x18)) {
  fprintf(stderr, "dsngctl: %s: packet tag: this is not a public key\n", __func__);
  return -1;
 }
 switch (c & 0x03) {
 case 0:
  header_len = 2;
  break;
 case 1:
  header_len = 3;
  break;
 case 2:
  header_len = 5;
  break;
 case 3:
 default:
  fprintf(stderr, "dsngctl: %s: packet tag: indefinite length headers are not supported\n", __func__);
  return -1;
 }
 header_len--;
 lseek(pkey_file, header_len, 1);
 read(pkey_file, &c, 1);
 if (c != 4) {
  fprintf(stderr, "dsngctl: %s: unsupported pkey version\n",
   __func__);
  return -1;
 }
 lseek(pkey_file, CREATION_TIME_LENGTH, 1);
 read(pkey_file, &c, 1);
 if (c != RSA_ENCRYPT_OR_SIGN && c != RSA_SIGN) {
  fprintf(stderr, "dsngctl: %s: this is not an RSA key, or signatures not allowed\n", __func__);
  return -1;
 }
 return 0;
}

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall get_mpi(int fd, int a2, char a3)
{
_BYTE *v4; // rax
_BYTE *v5; // rbp
unsigned __int8 v6; // bl
unsigned __int8 v7; // al
unsigned int v8; // ebx
int v9; // er12
__int64 v10; // rbx
__int64 result; // rax
int *v12; // rbx
char *v13; // rax
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

v4 = malloc(0x201uLL);
if ( v4 )
{
v5 = v4;
*v4 = a3;
read(fd, buf, 1uLL);
v6 = buf[0];
v5[1] = buf[0];
read(fd, buf, 1uLL);
v7 = buf[0];
v5[2] = buf[0];
v8 = (unsigned int)((v7 | (v6 << 8)) + 7) >> 3;
read(fd, v5 + 3, v8);
v9 = v8 + 3;
if ( write(a2, v5, (int)(v8 + 3)) < 0 )
{
v12 = __errno_location();
v13 = strerror(*v12);
fprintf(stderr, "dsngctl: %s: write problem %i: %s\n", "get_mpi", (unsigned int)*v12, v13);
result = 0xFFFFFFFFLL;
}
else
{
printf("MPI: %c (len=%d)\n{ ", (unsigned int)a3, v8);
v10 = 0LL;
do
printf("0x%02X, ", (unsigned __int8)v5[v10++]);
while ( v9 > (int)v10 );
puts("}");
result = 0LL;
}
}
else
{
fprintf(stderr, "dsngctl: %s: cannot allocate key buffer\n", "get_mpi");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd, int a2, char a3)
{
_BYTE *v4; // rax
_BYTE *v5; // rbp
unsigned __int8 v6; // bl
unsigned __int8 v7; // al
unsigned int v8; // ebx
int v9; // er12
__int64 v10; // rbx
__int64 result; // rax
int *v12; // rbx
char *v13; // rax
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

v4 = malloc(0x201uLL);
if ( v4 )
{
v5 = v4;
*v4 = a3;
read(fd, buf, 1uLL);
v6 = buf[0];
v5[1] = buf[0];
read(fd, buf, 1uLL);
v7 = buf[0];
v5[2] = buf[0];
v8 = (unsigned int)((v7 | (v6 << 8)) + 7) >> 3;
read(fd, v5 + 3, v8);
v9 = v8 + 3;
if ( write(a2, v5, (int)(v8 + 3)) < 0 )
{
v12 = __errno_location();
v13 = strerror(*v12);
fprintf(stderr, "dsngctl: %s: write problem %i: %s\n", "get_mpi", (unsigned int)*v12, v13);
result = 0xFFFFFFFFLL;
}
else
{
printf("MPI: %c (len=%d)\n{ ", (unsigned int)a3, v8);
v10 = 0LL;
do
printf("0x%02X, ", (unsigned __int8)v5[v10++]);
while ( v9 > (int)v10 );
puts("}");
result = 0LL;
}
}
else
{
fprintf(stderr, "dsngctl: %s: cannot allocate key buffer\n", "get_mpi");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int get_mpi(int pkey_file, int module_file, char tag)
{
 unsigned char c;
 unsigned int len;
 unsigned char *key;
 int i;
 int key_offset = 0;
 key = (unsigned char *) malloc(512 + 1);
 if (key == ((void *)0)) {
  fprintf(stderr, "dsngctl: %s: cannot allocate key buffer\n",
   __func__);
  return -1;
 }
 key[key_offset++] = tag;
 read(pkey_file, &c, 1);
 key[key_offset++] = c;
 len = c << 8;
 read(pkey_file, &c, 1);
 key[key_offset++] = c;
 len |= c;
 len = (len + 7) / 8;
 read(pkey_file, &key[key_offset], len);
 key_offset += len;
 if (write(module_file, key, key_offset) < 0) {
  fprintf(stderr, "dsngctl: %s: write problem %i: %s\n", __func__,
   (*__errno_location ()), strerror((*__errno_location ())));
  return -1;
 }
 printf("MPI: %c (len=%d)\n{ ", tag, len);
 for (i = 0; i < key_offset; i++) {
  printf("0x%02X, ", key[i] & 0xff);
 }
 printf("}\n");
 return 0;
}

variable_types: tag char

variable_types:
len
unsigned int

variable_types:
key
unsigned char *

variable_types: i int


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return printf("usage: %s [start|status|help]\n", a1);
}

canonical_decompiled_code:
int __fastcall func12(const char *a1)
{
return printf("usage: %s [start|status|help]\n", a1);
}

original_code:
static void print_usage(char *name)
{
 printf("usage: %s [start|status|help]\n", name);
}

variable_types:
name
char *


decompiled_code:
int __fastcall print_help(const char *a1)
{
print_usage(a1);
putchar(10);
printf(" %s start [pkey]\n", a1);
puts(" Loads a private key to the kernel module.");
puts(" You can export a key with `gpg --export > pkey`");
putchar(10);
printf(" %s status\n", a1);
puts(" Determines the current status of the module, whether it is loaded and running.");
putchar(10);
printf(" %s help\n", a1);
return puts(" Prints this message to standard output.");
}

canonical_decompiled_code:
int __fastcall func13(const char *a1)
{
func12(a1);
putchar(10);
printf(" %s start [pkey]\n", a1);
puts(" Loads a private key to the kernel module.");
puts(" You can export a key with `gpg --export > pkey`");
putchar(10);
printf(" %s status\n", a1);
puts(" Determines the current status of the module, whether it is loaded and running.");
putchar(10);
printf(" %s help\n", a1);
return puts(" Prints this message to standard output.");
}

original_code:
static void print_help(char *name)
{
 print_usage(name);
 printf("\n");
 printf("    %s start [pkey]\n", name);
 printf("        Loads a private key to the kernel module.\n");
 printf("        You can export a key with `gpg --export > pkey`\n");
 printf("\n");
 printf("    %s status\n", name);
 printf("        Determines the current status of the module, whether it is loaded and running.\n");
 printf("\n");
 printf("    %s help\n", name);
 printf("        Prints this message to standard output.\n");
}


decompiled_code:
_BOOL8 check_root()
{
return getuid() == 0;
}

canonical_decompiled_code:
_BOOL8 func14()
{
return getuid() == 0;
}

original_code:
static int check_root()
{
 return getuid() == 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r8
bool v4; // zf
int v5; // ebx
const char *v7; // rbp
const char *v8; // rsi

if ( argc <= 1 )
{
print_usage(*argv);
v5 = 1;
}
else
{
v3 = argv[1];
v4 = strcmp(v3, "help") == 0;
v5 = !v4;
if ( v4 )
{
print_help(*argv);
}
else if ( !strcmp(v3, "start") )
{
if ( argc <= 2 )
{
fwrite("dsngctl: invalid number of parameters for start command\n", 1uLL, 0x38uLL, stderr);
v5 = 1;
}
else if ( check_root() )
{
v5 = dsng_start(argv[2]);
}
else
{
fwrite("dsngctl: start command must be run as root\n", 1uLL, 0x2BuLL, stderr);
v5 = 1;
}
}
else
{
v5 = strcmp(v3, "status");
if ( v5 )
{
fwrite("dsngctl: unrecognized argument\n", 1uLL, 0x1FuLL, stderr);
v5 = 0;
}
else if ( check_root() )
{
v7 = "initialized";
if ( !(unsigned int)digsig_is_initialized() )
v7 = (const char *)&unk_402649;
v8 = "loaded";
if ( !(unsigned int)digsig_is_loaded() )
v8 = (const char *)&unk_402659;
printf("dsngctl: digsig-ng status\n\tmodule loaded:\t\t%s\n\tmodule initialized:\t%s\n", v8, v7);
}
else
{
fwrite("dsngctl: status command must be run as root\n", 1uLL, 0x2CuLL, stderr);
v5 = 1;
}
}
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r8
bool v4; // zf
int v5; // ebx
const char *v7; // rbp
const char *v8; // rsi

if ( argc <= 1 )
{
func12(*argv);
v5 = 1;
}
else
{
v3 = argv[1];
v4 = strcmp(v3, "help") == 0;
v5 = !v4;
if ( v4 )
{
func13(*argv);
}
else if ( !strcmp(v3, "start") )
{
if ( argc <= 2 )
{
fwrite("dsngctl: invalid number of parameters for start command\n", 1uLL, 0x38uLL, stderr);
v5 = 1;
}
else if ( func14() )
{
v5 = func7(argv[2]);
}
else
{
fwrite("dsngctl: start command must be run as root\n", 1uLL, 0x2BuLL, stderr);
v5 = 1;
}
}
else
{
v5 = strcmp(v3, "status");
if ( v5 )
{
fwrite("dsngctl: unrecognized argument\n", 1uLL, 0x1FuLL, stderr);
v5 = 0;
}
else if ( func14() )
{
v7 = "initialized";
if ( !(unsigned int)func9() )
v7 = (const char *)&unk_402649;
v8 = "loaded";
if ( !(unsigned int)func8() )
v8 = (const char *)&unk_402659;
printf("dsngctl: digsig-ng status\n\tmodule loaded:\t\t%s\n\tmodule initialized:\t%s\n", v8, v7);
}
else
{
fwrite("dsngctl: status command must be run as root\n", 1uLL, 0x2CuLL, stderr);
v5 = 1;
}
}
}
return v5;
}

original_code:
int main(int argc, char *argv[])
{
 int ret = 0;
 if (argc < 2) {
  print_usage(argv[0]);
  return 1;
 }
 else if (argc >= 2 && (strcmp(argv[1], "help") == 0)) {
  print_help(argv[0]);
  return 0;
 }
 else if (argc >= 2 && (strcmp(argv[1], "start") == 0)) {
  if (argc < 3) {
   fprintf(stderr, "dsngctl: invalid number of parameters for start command\n");
   return 1;
  }
  if (!check_root()) {
   fprintf(stderr, "dsngctl: start command must be run as root\n");
   return 1;
  }
  ret = dsng_start(argv[2]);
 }
 else if (argc >= 2 && (strcmp(argv[1], "status") == 0)) {
  if (!check_root()) {
   fprintf(stderr, "dsngctl: status command must be run as root\n");
   return 1;
  }
  printf("dsngctl: digsig-ng status\n\t"
   "module loaded:\t\t%s\n\t"
   "module initialized:\t%s\n",
   digsig_is_loaded() ? "loaded" : "not loaded",
   digsig_is_initialized() ? "initialized" : "not initialized");
  return 0;
 }
 else {
  fprintf(stderr, "dsngctl: unrecognized argument\n");
 }
 return ret;
}


repo: dimitarpeikov/eclib

decompiled_code:
__int64 eclib_set_version()
{
return 256LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 256LL;
}

original_code:
uint32_t eclib_set_version() {
 return 0x0100;
}

canonical_original_code:
unsigned int eclib_set_version() {
 return 0x0100;
}

return_type: unsigned int


original_code:
eclib_status_t eclib_set_init( eclib_set_ptr_t pSet, uint16_t nInitUnitSize, uint16_t nInitCount )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pSet )
 {
  pSet->nCount = nInitCount;
  pSet->nUnitSize = nInitUnitSize;
  pSet->nUsageCount = 0;
  pSet->nSignature = ECLIB_SIGNATURE_SET;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_set_init(struct eclib_set_struct *pSet, unsigned short nInitUnitSize, unsigned short nInitCount)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pSet )
 {
  pSet->nCount = nInitCount;
  pSet->nUnitSize = nInitUnitSize;
  pSet->nUsageCount = 0;
  pSet->nSignature = ECLIB_SIGNATURE_SET;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}

variable_types: struct eclib_set_struct { unsigned short nSignature; unsigned short nUnitSize; unsigned short nCount; unsigned short nUsageCount; unsigned char pBuffer[]; } *

variable_types:
nInitUnitSize
unsigned short

variable_types:
nInitCount
unsigned short

variable_types: enum eclib_status_enum { ECLIB_OK=0, ECLIB_INITIALIZED=1, ECLIB_ERROR=2, ECLIB_NULL_POINTER=3, ECLIB_NOT_FULL=4, ECLIB_FULL=5, ECLIB_EMPTY=6, ECLIB_FOUND=7, ECLIB_NOT_FOUND=8, ECLIB_OUT_OF_BOUNDS=9, ECLIB_NOT_IMPLEMENTED=10 }


decompiled_code:
__int64 __fastcall eclib_set_clear(__int64 a1)
{
if ( !a1 )
return 3LL;
*(_WORD *)(a1 + 6) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( !a1 )
return 3LL;
*(_WORD *)(a1 + 6) = 0;
return 0LL;
}

original_code:
eclib_status_t eclib_set_clear( eclib_set_ptr_t pSet) {
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if (pSet != ((void *)0)) {
  pSet->nUsageCount = 0;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_set_clear(struct eclib_set_struct *pSet) {
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if (pSet != ((void *)0)) {
  pSet->nUsageCount = 0;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}

return_type: enum eclib_status_enum { ECLIB_OK=0, ECLIB_INITIALIZED=1, ECLIB_ERROR=2, ECLIB_NULL_POINTER=3, ECLIB_NOT_FULL=4, ECLIB_FULL=5, ECLIB_EMPTY=6, ECLIB_FOUND=7, ECLIB_NOT_FOUND=8, ECLIB_OUT_OF_BOUNDS=9, ECLIB_NOT_IMPLEMENTED=10 }

user_defined_types: struct eclib_set_struct { unsigned short nSignature; unsigned short nUnitSize; unsigned short nCount; unsigned short nUsageCount; unsigned char pBuffer[]; }


decompiled_code:
__int64 __fastcall eclib_set_find(__int64 a1, const void *a2, _WORD *a3)
{
unsigned __int16 v3; // bx
int v4; // ebp
size_t v5; // r15
int v6; // er14
unsigned __int16 v7; // r12
int v8; // eax
int v9; // eax
__int64 result; // rax

if ( !a1 || !a2 )
return 3LL;
v3 = *(_WORD *)(a1 + 6);
v4 = (int)v3 >> 1;
if ( v3 > (unsigned __int16)v4 )
{
v5 = *(unsigned __int16 *)(a1 + 2);
v6 = *(unsigned __int16 *)(a1 + 2);
v7 = 0;
while ( 1 )
{
v9 = memcmp((const void *)(a1 + 8 + v6 * (unsigned __int16)v4), a2, v5);
if ( !v9 )
{
result = 7LL;
goto LABEL_15;
}
if ( v9 < 0 )
{
v7 = v4 + 1;
}
else
{
if ( !(_WORD)v4 )
{
result = 8LL;
goto LABEL_15;
}
v3 = v4;
}
v8 = (v7 + v3) >> 1;
LOWORD(v4) = v8;
if ( v3 < v7 || v3 <= (unsigned __int16)v8 )
{
result = 8LL;
goto LABEL_15;
}
}
}
result = 8LL;
LABEL_15:
if ( a3 )
*a3 = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const void *a2, _WORD *a3)
{
unsigned __int16 v3; // bx
int v4; // ebp
size_t v5; // r15
int v6; // er14
unsigned __int16 v7; // r12
int v8; // eax
int v9; // eax
__int64 result; // rax

if ( !a1 || !a2 )
return 3LL;
v3 = *(_WORD *)(a1 + 6);
v4 = (int)v3 >> 1;
if ( v3 > (unsigned __int16)v4 )
{
v5 = *(unsigned __int16 *)(a1 + 2);
v6 = *(unsigned __int16 *)(a1 + 2);
v7 = 0;
while ( 1 )
{
v9 = memcmp((const void *)(a1 + 8 + v6 * (unsigned __int16)v4), a2, v5);
if ( !v9 )
{
result = 7LL;
goto LABEL_15;
}
if ( v9 < 0 )
{
v7 = v4 + 1;
}
else
{
if ( !(_WORD)v4 )
{
result = 8LL;
goto LABEL_15;
}
v3 = v4;
}
v8 = (v7 + v3) >> 1;
LOWORD(v4) = v8;
if ( v3 < v7 || v3 <= (unsigned __int16)v8 )
{
result = 8LL;
goto LABEL_15;
}
}
}
result = 8LL;
LABEL_15:
if ( a3 )
*a3 = v4;
return result;
}

original_code:
eclib_status_t eclib_set_find( eclib_set_ptr_t pSet, void * pData, uint16_t * pIndex) {
 eclib_status_t eStatus = ECLIB_NOT_FOUND;
 uint16_t nIndex = 0;
 uint16_t nMaxIndex;
 uint16_t nLowIndex = 0;
 int nCmpResult;
 if (( ((void *)0) != pSet ) && (((void *)0) != pData))
 {
  nMaxIndex = pSet->nUsageCount;
  nIndex = (nMaxIndex + nLowIndex) / 2;
  while ((nMaxIndex >= nLowIndex) && (nIndex < nMaxIndex)){
   nCmpResult = memcmp( ((uint8_t *) pSet->pBuffer) + (pSet->nUnitSize * nIndex),
         pData,
         pSet->nUnitSize );
   if (nCmpResult == 0) {
    eStatus = ECLIB_FOUND;
    break;
   }
   if (nCmpResult < 0) {
    nLowIndex = ++nIndex;
   } else {
    if (nIndex == 0) {
     break;
    }
    nMaxIndex = nIndex;
   }
   nIndex = (nMaxIndex + nLowIndex) / 2;
  }
  if (pIndex != 0) {
   *pIndex = nIndex;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_set_find(struct eclib_set_struct *pSet, void *pData, unsigned short *pIndex) {
 enum eclib_status_enum eStatus = ECLIB_NOT_FOUND;
 unsigned short nIndex = 0;
 unsigned short nMaxIndex;
 unsigned short nLowIndex = 0;
 int nCmpResult;
 if (( ((void *)0) != pSet ) && (((void *)0) != pData))
 {
  nMaxIndex = pSet->nUsageCount;
  nIndex = (nMaxIndex + nLowIndex) / 2;
  while ((nMaxIndex >= nLowIndex) && (nIndex < nMaxIndex)){
   nCmpResult = memcmp( ((unsigned char *) pSet->pBuffer) + (pSet->nUnitSize * nIndex),
         pData,
         pSet->nUnitSize );
   if (nCmpResult == 0) {
    eStatus = ECLIB_FOUND;
    break;
   }
   if (nCmpResult < 0) {
    nLowIndex = ++nIndex;
   } else {
    if (nIndex == 0) {
     break;
    }
    nMaxIndex = nIndex;
   }
   nIndex = (nMaxIndex + nLowIndex) / 2;
  }
  if (pIndex != 0) {
   *pIndex = nIndex;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

variable_types:
pData
void *

variable_types:
pIndex
unsigned short *

variable_types:
nIndex
unsigned short

variable_types:
nMaxIndex
unsigned short

variable_types:
nLowIndex
unsigned short

variable_types: nCmpResult int

user_defined_types: enum eclib_status_enum { ECLIB_OK=0, ECLIB_INITIALIZED=1, ECLIB_ERROR=2, ECLIB_NULL_POINTER=3, ECLIB_NOT_FULL=4, ECLIB_FULL=5, ECLIB_EMPTY=6, ECLIB_FOUND=7, ECLIB_NOT_FOUND=8, ECLIB_OUT_OF_BOUNDS=9, ECLIB_NOT_IMPLEMENTED=10 }


decompiled_code:
__int64 __fastcall eclib_set_add(unsigned __int16 *a1, const void *a2)
{
__int64 result; // rax
int v3; // eax
unsigned __int16 v4; // dx
unsigned __int16 v5; // r12
int v6; // eax
unsigned __int16 v7[13]; // [rsp+0h] [rbp-1Ah] BYREF

if ( !a1 )
return 3LL;
result = 3LL;
if ( a2 )
{
v3 = eclib_set_find((__int64)a1, a2, v7);
if ( v3 == 8 )
{
v4 = a1[3];
result = 5LL;
if ( v4 < a1[2] )
{
v5 = v7[0];
if ( v4 > v7[0] )
{
v6 = v7[0] * a1[1];
memcpy((char *)a1 + a1[1] + v6 + 8, (char *)a1 + v6 + 8, a1[1] * (v4 - v7[0]));
}
memcpy((char *)a1 + a1[1] * v5 + 8, a2, a1[1]);
++a1[3];
result = 0LL;
}
}
else
{
result = 5 * (unsigned int)(v3 != 7);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 *a1, const void *a2)
{
__int64 result; // rax
int v3; // eax
unsigned __int16 v4; // dx
unsigned __int16 v5; // r12
int v6; // eax
unsigned __int16 v7[13]; // [rsp+0h] [rbp-1Ah] BYREF

if ( !a1 )
return 3LL;
result = 3LL;
if ( a2 )
{
v3 = func3((__int64)a1, a2, v7);
if ( v3 == 8 )
{
v4 = a1[3];
result = 5LL;
if ( v4 < a1[2] )
{
v5 = v7[0];
if ( v4 > v7[0] )
{
v6 = v7[0] * a1[1];
memcpy((char *)a1 + a1[1] + v6 + 8, (char *)a1 + v6 + 8, a1[1] * (v4 - v7[0]));
}
memcpy((char *)a1 + a1[1] * v5 + 8, a2, a1[1]);
++a1[3];
result = 0LL;
}
}
else
{
result = 5 * (unsigned int)(v3 != 7);
}
}
return result;
}

original_code:
eclib_status_t eclib_set_add( eclib_set_ptr_t pSet, void * pData )
{
 eclib_status_t eStatus = ECLIB_ERROR;
 uint16_t nIndex;
 eclib_status_t setContainStatus;
 if (( ((void *)0) != pSet ) && (((void *)0) != pData))
 {
  setContainStatus = eclib_set_find(pSet, pData, &nIndex);
  if ((setContainStatus == ECLIB_NOT_FOUND) && (pSet->nUsageCount < pSet->nCount)) {
   if (nIndex < pSet->nUsageCount) {
    memcpy( ((uint8_t *) pSet->pBuffer) + (pSet->nUnitSize * (nIndex + 1)),
      ((uint8_t *) pSet->pBuffer) + (pSet->nUnitSize * nIndex),
      pSet->nUnitSize * (pSet->nUsageCount - nIndex) );
   }
   memcpy( ((uint8_t *) pSet->pBuffer) + (pSet->nUnitSize * nIndex), pData, pSet->nUnitSize );
   pSet->nUsageCount ++;
   eStatus = ECLIB_OK;
  } else {
   if (setContainStatus == ECLIB_FOUND) {
    eStatus = ECLIB_OK;
   } else {
    eStatus = ECLIB_FULL;
   }
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_set_add(struct eclib_set_struct *pSet, void *pData)
{
 enum eclib_status_enum eStatus = ECLIB_ERROR;
 unsigned short nIndex;
 enum eclib_status_enum setContainStatus;
 if (( ((void *)0) != pSet ) && (((void *)0) != pData))
 {
  setContainStatus = eclib_set_find(pSet, pData, &nIndex);
  if ((setContainStatus == ECLIB_NOT_FOUND) && (pSet->nUsageCount < pSet->nCount)) {
   if (nIndex < pSet->nUsageCount) {
    memcpy( ((unsigned char *) pSet->pBuffer) + (pSet->nUnitSize * (nIndex + 1)),
      ((unsigned char *) pSet->pBuffer) + (pSet->nUnitSize * nIndex),
      pSet->nUnitSize * (pSet->nUsageCount - nIndex) );
   }
   memcpy( ((unsigned char *) pSet->pBuffer) + (pSet->nUnitSize * nIndex), pData, pSet->nUnitSize );
   pSet->nUsageCount ++;
   eStatus = ECLIB_OK;
  } else {
   if (setContainStatus == ECLIB_FOUND) {
    eStatus = ECLIB_OK;
   } else {
    eStatus = ECLIB_FULL;
   }
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_set_add_set(unsigned __int16 *a1, __int64 a2)
{
__int64 result; // rax
unsigned __int16 v3; // r13
int v4; // ebx

if ( !a1 )
return 3LL;
result = 3LL;
if ( a2 )
{
v3 = *(_WORD *)(a2 + 6);
result = 9LL;
if ( a1[2] > v3 + a1[3] )
{
if ( v3 )
{
v4 = 0;
do
result = eclib_set_add(a1, (const void *)(a2 + 8 + (unsigned __int16)v4++ * a1[1]));
while ( v3 > (unsigned __int16)v4 && !(_DWORD)result );
}
else
{
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int16 *a1, __int64 a2)
{
__int64 result; // rax
unsigned __int16 v3; // r13
int v4; // ebx

if ( !a1 )
return 3LL;
result = 3LL;
if ( a2 )
{
v3 = *(_WORD *)(a2 + 6);
result = 9LL;
if ( a1[2] > v3 + a1[3] )
{
if ( v3 )
{
v4 = 0;
do
result = func4(a1, (const void *)(a2 + 8 + (unsigned __int16)v4++ * a1[1]));
while ( v3 > (unsigned __int16)v4 && !(_DWORD)result );
}
else
{
result = 0LL;
}
}
}
return result;
}

original_code:
eclib_status_t eclib_set_add_set( eclib_set_ptr_t pSet, eclib_set_ptr_t pAddSet ) {
 eclib_status_t eStatus = ECLIB_ERROR;
 uint16_t nIndex;
 uint16_t nMaxIndex;
 if ((((void *)0) != pSet) && (((void *)0) != pAddSet)) {
  if (pSet->nCount > (pSet->nUsageCount + pAddSet->nUsageCount)) {
   nMaxIndex = pAddSet->nUsageCount;
   eStatus = ECLIB_OK;
   for (nIndex = 0; (nIndex < nMaxIndex) && (eStatus == ECLIB_OK); nIndex ++) {
    eStatus = eclib_set_add(pSet, ((uint8_t *) pAddSet->pBuffer) + (pSet->nUnitSize * nIndex));
   }
  } else {
   eStatus = ECLIB_OUT_OF_BOUNDS;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_set_add_set(struct eclib_set_struct *pSet, struct eclib_set_struct *pAddSet) {
 enum eclib_status_enum eStatus = ECLIB_ERROR;
 unsigned short nIndex;
 unsigned short nMaxIndex;
 if ((((void *)0) != pSet) && (((void *)0) != pAddSet)) {
  if (pSet->nCount > (pSet->nUsageCount + pAddSet->nUsageCount)) {
   nMaxIndex = pAddSet->nUsageCount;
   eStatus = ECLIB_OK;
   for (nIndex = 0; (nIndex < nMaxIndex) && (eStatus == ECLIB_OK); nIndex ++) {
    eStatus = eclib_set_add(pSet, ((unsigned char *) pAddSet->pBuffer) + (pSet->nUnitSize * nIndex));
   }
  } else {
   eStatus = ECLIB_OUT_OF_BOUNDS;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

variable_types:
pAddSet
struct eclib_set_struct *


decompiled_code:
__int64 __fastcall eclib_set_copy(unsigned __int16 *a1, const void *a2)
{
if ( !a1 || !a2 )
return 3LL;
memcpy(a1, a2, a1[3] * a1[1] + 8LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int16 *a1, const void *a2)
{
if ( !a1 || !a2 )
return 3LL;
memcpy(a1, a2, a1[3] * a1[1] + 8LL);
return 0LL;
}

original_code:
eclib_status_t eclib_set_copy( eclib_set_ptr_t pSet, eclib_set_ptr_t pSrcSet ) {
 eclib_status_t eStatus = ECLIB_ERROR;
 if ((((void *)0) != pSet) && (((void *)0) != pSrcSet)) {
  if ((pSet->nCount * pSet->nUnitSize) == (pSet->nCount * pSet->nUnitSize)) {
   memcpy( pSet,
     pSrcSet,
     sizeof(eclib_set_t) + (pSet->nUnitSize * pSet->nUsageCount));
   eStatus = ECLIB_OK;
  } else {
   eStatus = ECLIB_OUT_OF_BOUNDS;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_set_copy(struct eclib_set_struct *pSet, struct eclib_set_struct *pSrcSet) {
 enum eclib_status_enum eStatus = ECLIB_ERROR;
 if ((((void *)0) != pSet) && (((void *)0) != pSrcSet)) {
  if ((pSet->nCount * pSet->nUnitSize) == (pSet->nCount * pSet->nUnitSize)) {
   memcpy( pSet,
     pSrcSet,
     sizeof(eclib_set_t) + (pSet->nUnitSize * pSet->nUsageCount));
   eStatus = ECLIB_OK;
  } else {
   eStatus = ECLIB_OUT_OF_BOUNDS;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

variable_types:
pSrcSet
struct eclib_set_struct *


decompiled_code:
__int64 __fastcall eclib_set_get(__int64 a1, unsigned __int16 a2, void *a3)
{
unsigned int v4; // edx

if ( !a1 || !a3 )
return 3;
v4 = 9;
if ( *(_WORD *)(a1 + 6) > a2 )
{
memcpy(a3, (const void *)(a1 + *(unsigned __int16 *)(a1 + 2) * a2 + 8), *(unsigned __int16 *)(a1 + 2));
return 0LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int16 a2, void *a3)
{
unsigned int v4; // edx

if ( !a1 || !a3 )
return 3;
v4 = 9;
if ( *(_WORD *)(a1 + 6) > a2 )
{
memcpy(a3, (const void *)(a1 + *(unsigned __int16 *)(a1 + 2) * a2 + 8), *(unsigned __int16 *)(a1 + 2));
return 0LL;
}
return v4;
}

original_code:
eclib_status_t eclib_set_get( eclib_set_ptr_t pSet, uint16_t nIndex, void * pData )
{
 eclib_status_t eStatus = ECLIB_ERROR;
 if (( ((void *)0) != pSet ) && (((void *)0) != pData))
 {
  if ( nIndex < pSet->nUsageCount )
  {
   memcpy( pData,
     ((uint8_t *)pSet->pBuffer) + pSet->nUnitSize * nIndex,
     pSet->nUnitSize );
   eStatus = ECLIB_OK;
  } else {
   eStatus = ECLIB_OUT_OF_BOUNDS;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_set_get(struct eclib_set_struct *pSet, unsigned short nIndex, void *pData)
{
 enum eclib_status_enum eStatus = ECLIB_ERROR;
 if (( ((void *)0) != pSet ) && (((void *)0) != pData))
 {
  if ( nIndex < pSet->nUsageCount )
  {
   memcpy( pData,
     ((unsigned char *)pSet->pBuffer) + pSet->nUnitSize * nIndex,
     pSet->nUnitSize );
   eStatus = ECLIB_OK;
  } else {
   eStatus = ECLIB_OUT_OF_BOUNDS;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_set_get_usage(__int64 a1, _WORD *a2)
{
if ( !a1 || !a2 )
return 3LL;
*a2 = *(_WORD *)(a1 + 6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _WORD *a2)
{
if ( !a1 || !a2 )
return 3LL;
*a2 = *(_WORD *)(a1 + 6);
return 0LL;
}

original_code:
eclib_status_t eclib_set_get_usage(eclib_set_ptr_t pSet, uint16_t * pIndex) {
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ((pSet != ((void *)0)) && (pIndex != ((void *)0))) {
  *pIndex = pSet->nUsageCount;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_set_get_usage(struct eclib_set_struct *pSet, unsigned short *pIndex) {
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ((pSet != ((void *)0)) && (pIndex != ((void *)0))) {
  *pIndex = pSet->nUsageCount;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}


original_code:
eclib_status_t eclib_set_remove( eclib_set_ptr_t pSet, uint16_t nIndex )
{
 eclib_status_t eStatus = ECLIB_ERROR;
 if ( ((void *)0) != pSet )
 {
  if ( nIndex < pSet->nUsageCount )
  {
   memcpy( ((uint8_t *)pSet->pBuffer) + pSet->nUnitSize * nIndex,
     ((uint8_t *)pSet->pBuffer) + pSet->nUnitSize * (nIndex + 1),
     pSet->nUnitSize * (pSet->nUsageCount - nIndex - 1));
   pSet->nUsageCount --;
   eStatus = ECLIB_OK;
  } else {
   eStatus = ECLIB_OUT_OF_BOUNDS;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_set_remove(struct eclib_set_struct *pSet, unsigned short nIndex)
{
 enum eclib_status_enum eStatus = ECLIB_ERROR;
 if ( ((void *)0) != pSet )
 {
  if ( nIndex < pSet->nUsageCount )
  {
   memcpy( ((unsigned char *)pSet->pBuffer) + pSet->nUnitSize * nIndex,
     ((unsigned char *)pSet->pBuffer) + pSet->nUnitSize * (nIndex + 1),
     pSet->nUnitSize * (pSet->nUsageCount - nIndex - 1));
   pSet->nUsageCount --;
   eStatus = ECLIB_OK;
  } else {
   eStatus = ECLIB_OUT_OF_BOUNDS;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}


decompiled_code:
int __fastcall eclib_set_dump(unsigned __int16 *a1)
{
return printf("eclib_set:%x, %6d, %6d, %6d\n", *a1, a1[1], a1[2], a1[3]);
}

canonical_decompiled_code:
int __fastcall func10(unsigned __int16 *a1)
{
return printf("eclib_set:%x, %6d, %6d, %6d\n", *a1, a1[1], a1[2], a1[3]);
}

original_code:
void eclib_set_dump(eclib_set_ptr_t pSet) {
 printf("eclib_set:%x, %6d, %6d, %6d\n", pSet->nSignature, pSet->nUnitSize, pSet->nCount, pSet->nUsageCount);
}

canonical_original_code:
void eclib_set_dump(struct eclib_set_struct *pSet) {
 printf("eclib_set:%x, %6d, %6d, %6d\n", pSet->nSignature, pSet->nUnitSize, pSet->nCount, pSet->nUsageCount);
}


decompiled_code:
int action_one()
{
return puts("action_one");
}

canonical_decompiled_code:
int func0()
{
return puts("action_one");
}

original_code:
void action_one() {
 printf("%s\n", __PRETTY_FUNCTION__);
}


decompiled_code:
int action_two()
{
return puts("action_two");
}

canonical_decompiled_code:
int func1()
{
return puts("action_two");
}

original_code:
void action_two() {
 printf("%s\n", __PRETTY_FUNCTION__);
}


decompiled_code:
int action_three()
{
return puts("action_three");
}

canonical_decompiled_code:
int func2()
{
return puts("action_three");
}

original_code:
void action_three() {
 printf("%s\n", __PRETTY_FUNCTION__);
}


decompiled_code:
int action_four()
{
return puts("action_four");
}

canonical_decompiled_code:
int func3()
{
return puts("action_four");
}

original_code:
void action_four() {
 printf("%s\n", __PRETTY_FUNCTION__);
}


decompiled_code:
int action_onEnter()
{
return puts("action_onEnter");
}

canonical_decompiled_code:
int func4()
{
return puts("action_onEnter");
}

original_code:
void action_onEnter() {
 printf("%s\n", __PRETTY_FUNCTION__);
}


decompiled_code:
int action_onExit()
{
return puts("action_onExit");
}

canonical_decompiled_code:
int func5()
{
return puts("action_onExit");
}

original_code:
void action_onExit() {
 printf("%s\n", __PRETTY_FUNCTION__);
}


decompiled_code:
int action_doStart()
{
return puts("action_doStart");
}

canonical_decompiled_code:
int func6()
{
return puts("action_doStart");
}

original_code:
void action_doStart() {
 printf("%s\n", __PRETTY_FUNCTION__);
}


decompiled_code:
int action_doEnd()
{
return puts("action_doEnd");
}

canonical_decompiled_code:
int func7()
{
return puts("action_doEnd");
}

original_code:
void action_doEnd() {
 printf("%s\n", __PRETTY_FUNCTION__);
}


decompiled_code:
__int64 __fastcall stm_transition_compare(const void *a1, const void *a2)
{
__int64 result; // rax

if ( !a1 || (result = 0LL, *(_WORD *)a1 != *(_WORD *)a2) )
result = *(_WORD *)a2 < *(_WORD *)a1 ? -1 : 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
__int64 result; // rax

if ( !a1 || (result = 0LL, *(_WORD *)a1 != *(_WORD *)a2) )
result = *(_WORD *)a2 < *(_WORD *)a1 ? -1 : 1;
return result;
}

original_code:
int stm_transition_compare(const void * a, const void * b) {
 stm_transition_ptr_t transPtr = (stm_transition_ptr_t) b;
 stm_event_ptr_t event = (stm_event_ptr_t) a;
 if ((0 != event) && (event->event == transPtr->event.event)) {
  return 0;
 }
    if(event->event > transPtr->event.event) {
     return -1;
 }
    return 1;
}

canonical_original_code:
int stm_transition_compare(void *a, void *b) {
 struct stm_transition *transPtr = (stm_transition_ptr_t) b;
 struct stm_event *event = (stm_event_ptr_t) a;
 if ((0 != event) && (event->event == transPtr->event.event)) {
  return 0;
 }
    if(event->event > transPtr->event.event) {
     return -1;
 }
    return 1;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct stm_transition { struct stm_event { unsigned short event; void *ptr; } event; unsigned short toStateIndex; unsigned short actionIndex; } *

variable_types: struct stm_event { unsigned short event; void *ptr; } *

user_defined_types: struct stm_transition { struct stm_event event; unsigned short toStateIndex; unsigned short actionIndex; }


decompiled_code:
void __fastcall stm_set_fsmContext(__int64 a1)
{
fsmContext = a1;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
fsmContext = a1;
}

original_code:
void stm_set_fsmContext(stm_fsm_context_ptr_t fsmContextList) {
 fsmContext = fsmContextList;
}

canonical_original_code:
void stm_set_fsmContext(struct stm_fsm_context *fsmContextList) {
 fsmContext = fsmContextList;
}

variable_types: struct stm_fsm_context { struct stm_transition { struct stm_event { unsigned short event; void *ptr; } event; unsigned short toStateIndex; unsigned short actionIndex; } *transitionListPtr; struct stm_state { enum stm_state_type { STM_INITIAL=0, STM_STATE=1, STM_FORK=2, STM_JOIN=3, STM_CONDITION=4, STM_HISTORY=5, STM_TERMINATION=6, STM_JUNCTION=7, STM_PSEUDO=8, STM_NODE_COUNT=9 } stateType; unsigned short transitionStartIndex; unsigned short transitionCount; unsigned short enterActionIndex; unsigned short exitActionIndex; unsigned short doStartActionIndex; unsigned short doEndActionIndex; } *stateListPtr; void (**actionListPtr)(); struct eclib_set_struct { unsigned short nSignature; unsigned short nUnitSize; unsigned short nCount; unsigned short nUsageCount; unsigned char pBuffer[]; } *activeStateIndexListPtr; struct eclib_set_struct *workStateListPtr; void (*errorCallback)(); } *

user_defined_types: struct stm_fsm_context { struct stm_transition *transitionListPtr; struct stm_state *stateListPtr; void (**actionListPtr)(); struct eclib_set_struct *activeStateIndexListPtr; struct eclib_set_struct *workStateListPtr; void (*errorCallback)(); }

user_defined_types: struct stm_state { enum stm_state_type stateType; unsigned short transitionStartIndex; unsigned short transitionCount; unsigned short enterActionIndex; unsigned short exitActionIndex; unsigned short doStartActionIndex; unsigned short doEndActionIndex; }


decompiled_code:
void stm_traversal_start()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void stm_traversal_start() {
}

canonical_original_code:
void stm_traversal_start() {
}


decompiled_code:
void stm_traversal_start_from_state()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void stm_traversal_start_from_state(stm_index_t startStateIndex) {
}

canonical_original_code:
void stm_traversal_start_from_state(unsigned short startStateIndex) {
}

variable_types:
startStateIndex
unsigned short


decompiled_code:
__int64 __fastcall stm_find_state(unsigned __int16 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = fsmContext;
if ( fsmContext )
{
v2 = *(_QWORD *)(fsmContext + 8);
if ( a1 == 0xFFFF || !v2 )
result = 0LL;
else
result = v2 + 16LL * a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = fsmContext;
if ( fsmContext )
{
v2 = *(_QWORD *)(fsmContext + 8);
if ( a1 == 0xFFFF || !v2 )
result = 0LL;
else
result = v2 + 16LL * a1;
}
return result;
}

original_code:
stm_state_ptr_t stm_find_state(stm_index_t nodeIndex) {
 stm_state_ptr_t result = (stm_state_ptr_t) 0;
 if ((0 != fsmContext) && (0 != fsmContext->stateListPtr) && ((0xFFFF) != nodeIndex)) {
   return &fsmContext->stateListPtr[nodeIndex];
 }
 return result;
}

canonical_original_code:
struct stm_state *stm_find_state(unsigned short nodeIndex) {
 struct stm_state *result = (stm_state_ptr_t) 0;
 if ((0 != fsmContext) && (0 != fsmContext->stateListPtr) && ((0xFFFF) != nodeIndex)) {
   return &fsmContext->stateListPtr[nodeIndex];
 }
 return result;
}

variable_types:
nodeIndex
unsigned short

variable_types: struct stm_state { enum stm_state_type { STM_INITIAL=0, STM_STATE=1, STM_FORK=2, STM_JOIN=3, STM_CONDITION=4, STM_HISTORY=5, STM_TERMINATION=6, STM_JUNCTION=7, STM_PSEUDO=8, STM_NODE_COUNT=9 } stateType; unsigned short transitionStartIndex; unsigned short transitionCount; unsigned short enterActionIndex; unsigned short exitActionIndex; unsigned short doStartActionIndex; unsigned short doEndActionIndex; } *


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

result = fsmContext;
if ( fsmContext )
*(_QWORD *)(fsmContext + 8) = a1;
return result;
}

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

result = fsmContext;
if ( fsmContext )
*(_QWORD *)(fsmContext + 8) = a1;
return result;
}

original_code:
void stm_set_state_list(stm_state_ptr_t rootNode) {
 if (0 != fsmContext) {
  fsmContext->stateListPtr = rootNode;
 }
}

canonical_original_code:
void stm_set_state_list(struct stm_state *rootNode) {
 if (0 != fsmContext) {
  fsmContext->stateListPtr = rootNode;
 }
}

user_defined_types: enum stm_state_type { STM_INITIAL=0, STM_STATE=1, STM_FORK=2, STM_JOIN=3, STM_CONDITION=4, STM_HISTORY=5, STM_TERMINATION=6, STM_JUNCTION=7, STM_PSEUDO=8, STM_NODE_COUNT=9 }


decompiled_code:
__int64 __fastcall stm_find_transition(unsigned __int16 a1)
{
__int64 result; // rax
__int64 v2; // rax

result = fsmContext;
if ( fsmContext )
{
v2 = *(_QWORD *)fsmContext;
if ( a1 == 0xFFFF || !v2 )
result = 0LL;
else
result = v2 + 24LL * a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int16 a1)
{
__int64 result; // rax
__int64 v2; // rax

result = fsmContext;
if ( fsmContext )
{
v2 = *(_QWORD *)fsmContext;
if ( a1 == 0xFFFF || !v2 )
result = 0LL;
else
result = v2 + 24LL * a1;
}
return result;
}

original_code:
stm_transition_ptr_t stm_find_transition(stm_index_t transitionIndex) {
 stm_transition_ptr_t result = (stm_transition_ptr_t) 0;
 if ((0 != fsmContext) && (0 != fsmContext->transitionListPtr) && ((0xFFFF) != transitionIndex)) {
  return &fsmContext->transitionListPtr[transitionIndex];
 }
 return result;
}

canonical_original_code:
struct stm_transition *stm_find_transition(unsigned short transitionIndex) {
 struct stm_transition *result = (stm_transition_ptr_t) 0;
 if ((0 != fsmContext) && (0 != fsmContext->transitionListPtr) && ((0xFFFF) != transitionIndex)) {
  return &fsmContext->transitionListPtr[transitionIndex];
 }
 return result;
}

variable_types:
transitionIndex
unsigned short

return_type: struct stm_transition { struct stm_event { unsigned short event; void *ptr; } event; unsigned short toStateIndex; unsigned short actionIndex; } *


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

result = fsmContext;
if ( fsmContext )
*(_QWORD *)fsmContext = a1;
return result;
}

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

result = fsmContext;
if ( fsmContext )
*(_QWORD *)fsmContext = a1;
return result;
}

original_code:
void stm_set_transition_list(stm_transition_ptr_t rootTransition) {
 if (0 != fsmContext) {
  fsmContext->transitionListPtr = rootTransition;
 }
}

canonical_original_code:
void stm_set_transition_list(struct stm_transition *rootTransition) {
 if (0 != fsmContext) {
  fsmContext->transitionListPtr = rootTransition;
 }
}

user_defined_types: struct stm_event { unsigned short event; void *ptr; }


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

result = fsmContext;
if ( fsmContext )
*(_QWORD *)(fsmContext + 16) = a1;
return result;
}

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

result = fsmContext;
if ( fsmContext )
*(_QWORD *)(fsmContext + 16) = a1;
return result;
}

original_code:
void stm_set_action_list(stm_action_fn_ptr_t rootActionList) {
 if (0 != fsmContext) {
  fsmContext->actionListPtr = rootActionList;
 }
}

canonical_original_code:
void stm_set_action_list(void (**rootActionList)()) {
 if (0 != fsmContext) {
  fsmContext->actionListPtr = rootActionList;
 }
}

variable_types:
rootActionList
void (**)()


decompiled_code:
__int64 __fastcall stm_find_action(__int64 a1, unsigned __int16 a2)
{
__int64 v2; // rax
__int64 result; // rax

if ( !fsmContext )
return 0LL;
v2 = *(_QWORD *)(fsmContext + 16);
if ( a2 == 0xFFFF || !v2 )
result = 0LL;
else
result = *(_QWORD *)(v2 + 8LL * a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned __int16 a2)
{
__int64 v2; // rax
__int64 result; // rax

if ( !fsmContext )
return 0LL;
v2 = *(_QWORD *)(fsmContext + 16);
if ( a2 == 0xFFFF || !v2 )
result = 0LL;
else
result = *(_QWORD *)(v2 + 8LL * a2);
return result;
}

original_code:
stm_action_fn_t stm_find_action(stm_index_t stateIndex, stm_index_t actionIndex) {
 stm_action_fn_t result = (stm_action_fn_t) 0;
 if ((0 != fsmContext) && (0 != fsmContext->actionListPtr) && ((0xFFFF) != actionIndex)) {
  result = fsmContext->actionListPtr[actionIndex];
 }
 return result;
}

canonical_original_code:
void (*stm_find_action(unsigned short stateIndex, unsigned short actionIndex))() {
 void (*result)() = (stm_action_fn_t) 0;
 if ((0 != fsmContext) && (0 != fsmContext->actionListPtr) && ((0xFFFF) != actionIndex)) {
  result = fsmContext->actionListPtr[actionIndex];
 }
 return result;
}

variable_types:
stateIndex
unsigned short

variable_types:
actionIndex
unsigned short

variable_types:
result
void (*)()


decompiled_code:
__int64 __fastcall stm_process_event(void *key)
{
void (__fastcall *v1)(__int64); // rdx
__int64 v2; // r15
void (__fastcall *v3)(__int64); // rdx
unsigned __int16 v4; // r13
_WORD *v5; // rbx
unsigned __int16 *v6; // rbp
const void *v7; // r12
void (*v8)(void); // rdx
void (*v9)(void); // rdx
void (*v10)(void); // rdx
__int64 v11; // rbp
void (*v12)(void); // rdx
void (*v13)(void); // rdx
int v15; // [rsp+4h] [rbp-54h]
__int64 v16; // [rsp+8h] [rbp-50h]
unsigned __int16 v17; // [rsp+1Ch] [rbp-3Ch] BYREF
unsigned __int16 v18[29]; // [rsp+1Eh] [rbp-3Ah] BYREF

v16 = *(_QWORD *)(fsmContext + 32);
if ( (unsigned int)eclib_set_clear(v16) )
{
v1 = *(void (__fastcall **)(__int64))(fsmContext + 40);
if ( v1 )
v1(6LL);
}
v2 = *(_QWORD *)(fsmContext + 24);
if ( (unsigned int)eclib_set_get_usage(v2, v18) )
{
v3 = *(void (__fastcall **)(__int64))(fsmContext + 40);
if ( v3 )
v3(2LL);
}
if ( v18[0] )
{
v15 = 0;
v4 = 0;
do
{
if ( (unsigned int)eclib_set_get(v2, v4, &v17) )
break;
v6 = (unsigned __int16 *)stm_find_state(v17);
v7 = (const void *)stm_find_transition(v6[2]);
v5 = bsearch(key, v7, v6[3], 0x18uLL, (__compar_fn_t)stm_transition_compare);
if ( !v5 )
{
v5 = bsearch(&_stm_null_event, v7, v6[3], 0x18uLL, (__compar_fn_t)stm_transition_compare);
if ( !v5 )
continue;
}
v8 = (void (*)(void))stm_find_action(v17, v6[7]);
if ( v8 )
v8();
v9 = (void (*)(void))stm_find_action(v17, v6[5]);
if ( v9 )
v9();
v10 = (void (*)(void))stm_find_action(v17, v5[9]);
if ( v10 )
v10();
v11 = stm_find_state(v5[8]);
if ( v11 )
{
if ( (unsigned int)eclib_set_add(v16, v5 + 8) )
goto LABEL_29;
v12 = (void (*)(void))stm_find_action(v17, *(_WORD *)(v11 + 8));
if ( v12 )
v12();
v13 = (void (*)(void))stm_find_action(v17, *(_WORD *)(v11 + 12));
v15 = 1;
if ( v13 )
{
v13();
v15 = 1;
}
}
else
{
v15 = 1;
}
++v4;
}
while ( v18[0] > v4 );
if ( !v15 )
return 0xFFFFFFFFLL;
LABEL_29:
eclib_set_copy(v2, v16);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(void *key)
{
void (__fastcall *v1)(__int64); // rdx
__int64 v2; // r15
void (__fastcall *v3)(__int64); // rdx
unsigned __int16 v4; // r13
_WORD *v5; // rbx
unsigned __int16 *v6; // rbp
const void *v7; // r12
void (*v8)(void); // rdx
void (*v9)(void); // rdx
void (*v10)(void); // rdx
__int64 v11; // rbp
void (*v12)(void); // rdx
void (*v13)(void); // rdx
int v15; // [rsp+4h] [rbp-54h]
__int64 v16; // [rsp+8h] [rbp-50h]
unsigned __int16 v17; // [rsp+1Ch] [rbp-3Ch] BYREF
unsigned __int16 v18[29]; // [rsp+1Eh] [rbp-3Ah] BYREF

v16 = *(_QWORD *)(fsmContext + 32);
if ( (unsigned int)eclib_set_clear(v16) )
{
v1 = *(void (__fastcall **)(__int64))(fsmContext + 40);
if ( v1 )
v1(6LL);
}
v2 = *(_QWORD *)(fsmContext + 24);
if ( (unsigned int)eclib_set_get_usage(v2, v18) )
{
v3 = *(void (__fastcall **)(__int64))(fsmContext + 40);
if ( v3 )
v3(2LL);
}
if ( v18[0] )
{
v15 = 0;
v4 = 0;
do
{
if ( (unsigned int)eclib_set_get(v2, v4, &v17) )
break;
v6 = (unsigned __int16 *)func4(v17);
v7 = (const void *)func6(v6[2]);
v5 = bsearch(key, v7, v6[3], 0x18uLL, (__compar_fn_t)stm_transition_compare);
if ( !v5 )
{
v5 = bsearch(&_stm_null_event, v7, v6[3], 0x18uLL, (__compar_fn_t)stm_transition_compare);
if ( !v5 )
continue;
}
v8 = (void (*)(void))func9(v17, v6[7]);
if ( v8 )
v8();
v9 = (void (*)(void))func9(v17, v6[5]);
if ( v9 )
v9();
v10 = (void (*)(void))func9(v17, v5[9]);
if ( v10 )
v10();
v11 = func4(v5[8]);
if ( v11 )
{
if ( (unsigned int)eclib_set_add(v16, v5 + 8) )
goto LABEL_29;
v12 = (void (*)(void))func9(v17, *(_WORD *)(v11 + 8));
if ( v12 )
v12();
v13 = (void (*)(void))func9(v17, *(_WORD *)(v11 + 12));
v15 = 1;
if ( v13 )
{
v13();
v15 = 1;
}
}
else
{
v15 = 1;
}
++v4;
}
while ( v18[0] > v4 );
if ( !v15 )
return 0xFFFFFFFFLL;
LABEL_29:
eclib_set_copy(v2, v16);
}
return 0xFFFFFFFFLL;
}

original_code:
stm_index_t stm_process_event(stm_event_ptr_t eventPtr) {
 stm_index_t result = -1;
 stm_transition_ptr_t transitionPtr;
 stm_state_ptr_t statePtr;
 stm_state_ptr_t newStatePtr;
 stm_transition_ptr_t lookupTransitionPtr;
 stm_action_fn_t action;
 eclib_status_t eStatus = ECLIB_ERROR;
 stm_index_t activeStateCount, activeStateIndex;
 stm_index_t index;
 eclib_set_ptr_t activeStateSetPtr;
 eclib_set_ptr_t workingStateSetPtr;
 int transitionDetectionFlag = 0;
 workingStateSetPtr = fsmContext->workStateListPtr;
 eStatus = eclib_set_clear(workingStateSetPtr);
 if (eStatus != ECLIB_OK) {
  if (fsmContext->errorCallback != ((void *)0)) {
   fsmContext->errorCallback(ECLIB_EMPTY);
  }
 }
 activeStateSetPtr = fsmContext->activeStateIndexListPtr;
 eStatus = eclib_set_get_usage(activeStateSetPtr, &activeStateCount);
 if (ECLIB_OK != eStatus) {
  if (fsmContext->errorCallback != ((void *)0)) {
   fsmContext->errorCallback(ECLIB_ERROR);
  }
 }
 for (index = 0; index < activeStateCount; index ++) {
  eStatus = eclib_set_get(activeStateSetPtr, index, &activeStateIndex);
  if (ECLIB_OK != eStatus) {
   break;
  }
  statePtr = stm_find_state(activeStateIndex);
  transitionPtr = stm_find_transition(statePtr->transitionStartIndex);
  lookupTransitionPtr = bsearch( eventPtr,
          transitionPtr,
          statePtr->transitionCount,
          sizeof(stm_transition_t),
          stm_transition_compare);
  if (0 == lookupTransitionPtr) {
   lookupTransitionPtr = bsearch( &__stm_null_event,
          transitionPtr,
          statePtr->transitionCount,
          sizeof(stm_transition_t),
          stm_transition_compare);
  }
  if (0 != lookupTransitionPtr) {
   transitionDetectionFlag = 1;
   action = stm_find_action(activeStateIndex, statePtr->doEndActionIndex);
   if (0 != action) {
    action();
   }
   action = stm_find_action(activeStateIndex, statePtr->exitActionIndex);
   if (0 != action) {
    action();
   }
   action = stm_find_action(activeStateIndex, lookupTransitionPtr->actionIndex);
   if (0 != action) {
    action();
   }
   newStatePtr = stm_find_state(lookupTransitionPtr->toStateIndex);
   if (0 != newStatePtr) {
    eStatus = eclib_set_add(workingStateSetPtr, &lookupTransitionPtr->toStateIndex);
    if (ECLIB_OK != eStatus) {
     break;
    }
    action = stm_find_action(activeStateIndex, newStatePtr->enterActionIndex);
    if (0 != action) {
     action();
    }
    action = stm_find_action(activeStateIndex, newStatePtr->doStartActionIndex);
    if (0 != action) {
     action();
    }
   }
  }
 }
 if (0 != transitionDetectionFlag) {
  eclib_set_copy(activeStateSetPtr, workingStateSetPtr);
 }
 return result;
}

canonical_original_code:
unsigned short stm_process_event(struct stm_event *eventPtr) {
 unsigned short result = -1;
 struct stm_transition *transitionPtr;
 struct stm_state *statePtr;
 struct stm_state *newStatePtr;
 struct stm_transition *lookupTransitionPtr;
 void (*action)();
 enum eclib_status_enum eStatus = ECLIB_ERROR;
 unsigned short activeStateCount; unsigned short activeStateIndex;
 unsigned short index;
 struct eclib_set_struct *activeStateSetPtr;
 struct eclib_set_struct *workingStateSetPtr;
 int transitionDetectionFlag = 0;
 workingStateSetPtr = fsmContext->workStateListPtr;
 eStatus = eclib_set_clear(workingStateSetPtr);
 if (eStatus != ECLIB_OK) {
  if (fsmContext->errorCallback != ((void *)0)) {
   fsmContext->errorCallback(ECLIB_EMPTY);
  }
 }
 activeStateSetPtr = fsmContext->activeStateIndexListPtr;
 eStatus = eclib_set_get_usage(activeStateSetPtr, &activeStateCount);
 if (ECLIB_OK != eStatus) {
  if (fsmContext->errorCallback != ((void *)0)) {
   fsmContext->errorCallback(ECLIB_ERROR);
  }
 }
 for (index = 0; index < activeStateCount; index ++) {
  eStatus = eclib_set_get(activeStateSetPtr, index, &activeStateIndex);
  if (ECLIB_OK != eStatus) {
   break;
  }
  statePtr = stm_find_state(activeStateIndex);
  transitionPtr = stm_find_transition(statePtr->transitionStartIndex);
  lookupTransitionPtr = bsearch( eventPtr,
          transitionPtr,
          statePtr->transitionCount,
          sizeof(stm_transition_t),
          stm_transition_compare);
  if (0 == lookupTransitionPtr) {
   lookupTransitionPtr = bsearch( &__stm_null_event,
          transitionPtr,
          statePtr->transitionCount,
          sizeof(stm_transition_t),
          stm_transition_compare);
  }
  if (0 != lookupTransitionPtr) {
   transitionDetectionFlag = 1;
   action = stm_find_action(activeStateIndex, statePtr->doEndActionIndex);
   if (0 != action) {
    action();
   }
   action = stm_find_action(activeStateIndex, statePtr->exitActionIndex);
   if (0 != action) {
    action();
   }
   action = stm_find_action(activeStateIndex, lookupTransitionPtr->actionIndex);
   if (0 != action) {
    action();
   }
   newStatePtr = stm_find_state(lookupTransitionPtr->toStateIndex);
   if (0 != newStatePtr) {
    eStatus = eclib_set_add(workingStateSetPtr, &lookupTransitionPtr->toStateIndex);
    if (ECLIB_OK != eStatus) {
     break;
    }
    action = stm_find_action(activeStateIndex, newStatePtr->enterActionIndex);
    if (0 != action) {
     action();
    }
    action = stm_find_action(activeStateIndex, newStatePtr->doStartActionIndex);
    if (0 != action) {
     action();
    }
   }
  }
 }
 if (0 != transitionDetectionFlag) {
  eclib_set_copy(activeStateSetPtr, workingStateSetPtr);
 }
 return result;
}

variable_types:
result
unsigned short

variable_types:
action
void (*)()

variable_types: enum eclib_status_enum { ECLIB_OK=0, ECLIB_INITIALIZED=1, ECLIB_ERROR=2, ECLIB_NULL_POINTER=3, ECLIB_NOT_FULL=4, ECLIB_FULL=5, ECLIB_EMPTY=6, ECLIB_FOUND=7, ECLIB_NOT_FOUND=8, ECLIB_OUT_OF_BOUNDS=9, ECLIB_NOT_IMPLEMENTED=10 }

variable_types:
activeStateCount
unsigned short

variable_types:
activeStateIndex
unsigned short

variable_types:
index
unsigned short

variable_types: struct eclib_set_struct { unsigned short nSignature; unsigned short nUnitSize; unsigned short nCount; unsigned short nUsageCount; unsigned char pBuffer[]; } *

variable_types: transitionDetectionFlag int

return_type: unsigned short


decompiled_code:
__int16 __fastcall eclib_queue_head_inc(__int64 a1)
{
__int16 result; // ax

result = (unsigned __int16)(*(_WORD *)(a1 + 4) + 1) / *(_WORD *)(a1 + 10);
*(_WORD *)(a1 + 4) = (unsigned __int16)(*(_WORD *)(a1 + 4) + 1) % *(_WORD *)(a1 + 10);
return result;
}

original_code:
static void eclib_queue_head_inc( eclib_queue_t * pQueue )
{
 pQueue->nHeadIndex ++;
 pQueue->nHeadIndex %= pQueue->nUnits;
}

canonical_original_code:
static void eclib_queue_head_inc(struct eclib_queue_struct *pQueue)
{
 pQueue->nHeadIndex ++;
 pQueue->nHeadIndex %= pQueue->nUnits;
}

variable_types: struct eclib_queue_struct { enum eclib_signature_enum { ECLIB_SIGNATURE_EMPTY=0, ECLIB_SIGNATURE_QUEUE=4660, ECLIB_SIGNATURE_ARRAY=9029, ECLIB_SIGNATURE_SET=13398, ECLIB_SIGNATURE_BUTTON=17767 } eSignature; unsigned short nHeadIndex; unsigned short nTailIndex; unsigned short nSize; unsigned short nUnits; void *pBuffer; unsigned char nIsFull; } *

user_defined_types: struct eclib_queue_struct { enum eclib_signature_enum eSignature; unsigned short nHeadIndex; unsigned short nTailIndex; unsigned short nSize; unsigned short nUnits; void *pBuffer; unsigned char nIsFull; }


decompiled_code:
__int16 __fastcall eclib_queue_tail_inc(__int64 a1)
{
__int16 result; // ax

result = (unsigned __int16)(*(_WORD *)(a1 + 6) + 1) / *(_WORD *)(a1 + 10);
*(_WORD *)(a1 + 6) = (unsigned __int16)(*(_WORD *)(a1 + 6) + 1) % *(_WORD *)(a1 + 10);
return result;
}

original_code:
static void eclib_queue_tail_inc( eclib_queue_t * pQueue )
{
 pQueue->nTailIndex ++;
 pQueue->nTailIndex %= pQueue->nUnits;
}

canonical_original_code:
static void eclib_queue_tail_inc(struct eclib_queue_struct *pQueue)
{
 pQueue->nTailIndex ++;
 pQueue->nTailIndex %= pQueue->nUnits;
}

user_defined_types: enum eclib_signature_enum { ECLIB_SIGNATURE_EMPTY=0, ECLIB_SIGNATURE_QUEUE=4660, ECLIB_SIGNATURE_ARRAY=9029, ECLIB_SIGNATURE_SET=13398, ECLIB_SIGNATURE_BUTTON=17767 }


decompiled_code:
__int64 eclib_queue_version()
{
return 256LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 256LL;
}

original_code:
uint32_t eclib_queue_version() {
 return 0x0100;
}

canonical_original_code:
unsigned int eclib_queue_version() {
 return 0x0100;
}


original_code:
eclib_status_t eclib_queue_init( eclib_queue_t * pQueue, void * pBuffer, uint16_t nSize, uint16_t nUnits )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  if ( ((void *)0) != pBuffer )
  {
   pQueue->nHeadIndex = 0;
   pQueue->nTailIndex = 0;
   pQueue->nUnits = nUnits;
   pQueue->nSize = nSize;
   pQueue->pBuffer = pBuffer;
   pQueue->nIsFull = 0;
   pQueue->eSignature = ECLIB_SIGNATURE_QUEUE;
   eStatus = ECLIB_OK;
  } else {
   pQueue->eSignature = ECLIB_SIGNATURE_EMPTY;
  }
 } else {
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_init(struct eclib_queue_struct *pQueue, void *pBuffer, unsigned short nSize, unsigned short nUnits)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  if ( ((void *)0) != pBuffer )
  {
   pQueue->nHeadIndex = 0;
   pQueue->nTailIndex = 0;
   pQueue->nUnits = nUnits;
   pQueue->nSize = nSize;
   pQueue->pBuffer = pBuffer;
   pQueue->nIsFull = 0;
   pQueue->eSignature = ECLIB_SIGNATURE_QUEUE;
   eStatus = ECLIB_OK;
  } else {
   pQueue->eSignature = ECLIB_SIGNATURE_EMPTY;
  }
 } else {
 }
 return eStatus;
}

variable_types:
pBuffer
void *

variable_types:
nSize
unsigned short

variable_types:
nUnits
unsigned short


original_code:
eclib_status_t eclib_queue_clear( eclib_queue_t * pQueue )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  pQueue->nHeadIndex = 0;
  pQueue->nTailIndex = 0;
  pQueue->nIsFull = 0;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_clear(struct eclib_queue_struct *pQueue)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  pQueue->nHeadIndex = 0;
  pQueue->nTailIndex = 0;
  pQueue->nIsFull = 0;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}


original_code:
eclib_status_t eclib_queue_full( eclib_queue_t * pQueue )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  pQueue->nHeadIndex = 0;
  pQueue->nTailIndex = 0;
  pQueue->nIsFull = ECLIB_FULL;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_full(struct eclib_queue_struct *pQueue)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  pQueue->nHeadIndex = 0;
  pQueue->nTailIndex = 0;
  pQueue->nIsFull = ECLIB_FULL;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}


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

if ( !a1 )
return 3LL;
result = 0LL;
if ( !*(_BYTE *)(a1 + 24) )
{
result = 6LL;
if ( *(_WORD *)(a1 + 4) != *(_WORD *)(a1 + 6) )
result = 0LL;
}
return result;
}

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

if ( !a1 )
return 3LL;
result = 0LL;
if ( !*(_BYTE *)(a1 + 24) )
{
result = 6LL;
if ( *(_WORD *)(a1 + 4) != *(_WORD *)(a1 + 6) )
result = 0LL;
}
return result;
}

original_code:
eclib_status_t eclib_queue_is_empty( eclib_queue_t * pQueue )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  if ( 0 == pQueue->nIsFull )
  {
   eStatus = (pQueue->nHeadIndex == pQueue->nTailIndex) ? ECLIB_EMPTY : ECLIB_OK ;
  } else {
   eStatus = ECLIB_OK;
  }
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_is_empty(struct eclib_queue_struct *pQueue)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  if ( 0 == pQueue->nIsFull )
  {
   eStatus = (pQueue->nHeadIndex == pQueue->nTailIndex) ? ECLIB_EMPTY : ECLIB_OK ;
  } else {
   eStatus = ECLIB_OK;
  }
 }
 return eStatus;
}


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

if ( a1 )
result = *(_BYTE *)(a1 + 24) != 0 ? 5 : 0;
else
result = 3LL;
return result;
}

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

if ( a1 )
result = *(_BYTE *)(a1 + 24) != 0 ? 5 : 0;
else
result = 3LL;
return result;
}

original_code:
eclib_status_t eclib_queue_is_full( eclib_queue_t * pQueue )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  eStatus = ( 0 == pQueue->nIsFull ) ? ECLIB_OK : ECLIB_FULL;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_is_full(struct eclib_queue_struct *pQueue)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  eStatus = ( 0 == pQueue->nIsFull ) ? ECLIB_OK : ECLIB_FULL;
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_queue_push(__int64 a1, const void *a2)
{
__int64 result; // rax

result = eclib_queue_is_full(a1);
if ( (_DWORD)result != 5 )
{
result = 3LL;
if ( a2 )
{
memcpy(
(void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 8) * *(unsigned __int16 *)(a1 + 4)),
a2,
*(unsigned __int16 *)(a1 + 8));
eclib_queue_head_inc(a1);
result = 0LL;
if ( *(_WORD *)(a1 + 4) == *(_WORD *)(a1 + 6) )
*(_BYTE *)(a1 + 24) = 5;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const void *a2)
{
__int64 result; // rax

result = func7(a1);
if ( (_DWORD)result != 5 )
{
result = 3LL;
if ( a2 )
{
memcpy(
(void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 8) * *(unsigned __int16 *)(a1 + 4)),
a2,
*(unsigned __int16 *)(a1 + 8));
func0(a1);
result = 0LL;
if ( *(_WORD *)(a1 + 4) == *(_WORD *)(a1 + 6) )
*(_BYTE *)(a1 + 24) = 5;
}
}
return result;
}

original_code:
eclib_status_t eclib_queue_push( eclib_queue_t * pQueue, void * pData )
{
 eclib_status_t eStatus;
 eStatus = eclib_queue_is_full( pQueue );
 if ( ECLIB_FULL != eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( ((uint8_t *)pQueue->pBuffer) + pQueue->nSize * pQueue->nHeadIndex, pData, pQueue->nSize );
   eclib_queue_head_inc( pQueue );
   if ( pQueue->nHeadIndex == pQueue->nTailIndex )
   {
    pQueue->nIsFull = ECLIB_FULL;
   }
   eStatus = ECLIB_OK;
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_push(struct eclib_queue_struct *pQueue, void *pData)
{
 enum eclib_status_enum eStatus;
 eStatus = eclib_queue_is_full( pQueue );
 if ( ECLIB_FULL != eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( ((unsigned char *)pQueue->pBuffer) + pQueue->nSize * pQueue->nHeadIndex, pData, pQueue->nSize );
   eclib_queue_head_inc( pQueue );
   if ( pQueue->nHeadIndex == pQueue->nTailIndex )
   {
    pQueue->nIsFull = ECLIB_FULL;
   }
   eStatus = ECLIB_OK;
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}

variable_types:
pData
void *


decompiled_code:
__int64 __fastcall eclib_queue_pop(__int64 a1, void *a2)
{
unsigned int v2; // ebp

v2 = eclib_queue_is_empty(a1);
if ( v2 != 6 )
{
if ( a2 )
{
memcpy(
a2,
(const void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 8) * *(unsigned __int16 *)(a1 + 6)),
*(unsigned __int16 *)(a1 + 8));
eclib_queue_tail_inc(a1);
if ( *(_BYTE *)(a1 + 24) )
*(_BYTE *)(a1 + 24) = 0;
}
else
{
v2 = 3;
}
}
return v2;
}

original_code:
eclib_status_t eclib_queue_pop( eclib_queue_t * pQueue, void * pData )
{
 eclib_status_t eStatus;
 eStatus = eclib_queue_is_empty( pQueue );
 if ( ECLIB_EMPTY != eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( pData, ((uint8_t *)pQueue->pBuffer) + pQueue->nSize * pQueue->nTailIndex, pQueue->nSize );
   eclib_queue_tail_inc( pQueue );
   if ( 0 != pQueue->nIsFull )
   {
    pQueue->nIsFull = 0;
   }
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_pop(struct eclib_queue_struct *pQueue, void *pData)
{
 enum eclib_status_enum eStatus;
 eStatus = eclib_queue_is_empty( pQueue );
 if ( ECLIB_EMPTY != eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( pData, ((unsigned char *)pQueue->pBuffer) + pQueue->nSize * pQueue->nTailIndex, pQueue->nSize );
   eclib_queue_tail_inc( pQueue );
   if ( 0 != pQueue->nIsFull )
   {
    pQueue->nIsFull = 0;
   }
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_queue_peek(__int64 a1, void *a2)
{
unsigned int v2; // ebp

v2 = eclib_queue_is_empty(a1);
if ( v2 != 6 )
{
if ( a2 )
{
memcpy(
a2,
(const void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 8) * *(unsigned __int16 *)(a1 + 6)),
*(unsigned __int16 *)(a1 + 8));
if ( *(_BYTE *)(a1 + 24) )
*(_BYTE *)(a1 + 24) = 0;
}
else
{
v2 = 3;
}
}
return v2;
}

original_code:
eclib_status_t eclib_queue_peek( eclib_queue_t * pQueue, void * pData )
{
 eclib_status_t eStatus;
 eStatus = eclib_queue_is_empty( pQueue );
 if ( ECLIB_EMPTY != eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( pData, ((uint8_t *)pQueue->pBuffer) + pQueue->nSize * pQueue->nTailIndex, pQueue->nSize );
   if ( 0 != pQueue->nIsFull )
   {
    pQueue->nIsFull = 0;
   }
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_peek(struct eclib_queue_struct *pQueue, void *pData)
{
 enum eclib_status_enum eStatus;
 eStatus = eclib_queue_is_empty( pQueue );
 if ( ECLIB_EMPTY != eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( pData, ((unsigned char *)pQueue->pBuffer) + pQueue->nSize * pQueue->nTailIndex, pQueue->nSize );
   if ( 0 != pQueue->nIsFull )
   {
    pQueue->nIsFull = 0;
   }
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_queue_get_queue_size(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 10);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 10);
}

original_code:
uint16_t eclib_queue_get_queue_size(eclib_queue_ptr_t pQueue) {
  return pQueue->nUnits;
}

canonical_original_code:
unsigned short eclib_queue_get_queue_size(struct eclib_queue_struct *pQueue) {
  return pQueue->nUnits;
}


decompiled_code:
__int64 __fastcall eclib_queue_get_usage(_WORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // edx

v1 = (unsigned __int16)(a1[2] - a1[3]);
v2 = v1;
if ( (__int16)(a1[2] - a1[3]) < 0 )
{
LOWORD(v1) = a1[5] + v1;
v2 = v1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(_WORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // edx

v1 = (unsigned __int16)(a1[2] - a1[3]);
v2 = v1;
if ( (__int16)(a1[2] - a1[3]) < 0 )
{
LOWORD(v1) = a1[5] + v1;
v2 = v1;
}
return v2;
}

original_code:
uint16_t eclib_queue_get_usage(eclib_queue_ptr_t pQueue) {
  int16_t size = pQueue->nHeadIndex - pQueue->nTailIndex;
  if (size < 0) {
    size += pQueue->nUnits;
  }
  return size;
}

canonical_original_code:
unsigned short eclib_queue_get_usage(struct eclib_queue_struct *pQueue) {
  short size = pQueue->nHeadIndex - pQueue->nTailIndex;
  if (size < 0) {
    size += pQueue->nUnits;
  }
  return size;
}

variable_types: size short


decompiled_code:
__int64 __fastcall eclib_queue_get_head_index(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 4);
}

original_code:
uint16_t eclib_queue_get_head_index(eclib_queue_ptr_t pQueue) {
  return pQueue->nHeadIndex;
}

canonical_original_code:
unsigned short eclib_queue_get_head_index(struct eclib_queue_struct *pQueue) {
  return pQueue->nHeadIndex;
}