decompiled_code:
int show_shift_jis_char()
{
__int64 v1; // [rsp+6h] [rbp-12h] BYREF
__int16 v2; // [rsp+Eh] [rbp-Ah]

v1 = 0x81E38481E38281E3LL;
v2 = 134;
printf("c=%s\n", (const char *)&v1);
printf("c=%c\n", (unsigned int)(char)v1);
printf("c=%d\n", (unsigned __int8)v1);
return printf("c=%x\n", (unsigned __int8)v1);
}

canonical_decompiled_code:
int func11()
{
__int64 v1; // [rsp+6h] [rbp-12h] BYREF
__int16 v2; // [rsp+Eh] [rbp-Ah]

v1 = 0x81E38481E38281E3LL;
v2 = 134;
printf("c=%s\n", (const char *)&v1);
printf("c=%c\n", (unsigned int)(char)v1);
printf("c=%d\n", (unsigned __int8)v1);
return printf("c=%x\n", (unsigned __int8)v1);
}

original_code:
void show_shift_jis_char()
{
 int i, j;
 int num;
 char c[10] = "あいう";
 printf("c=%s\n", c);
 printf("c=%c\n", c[0]);
 printf("c=%d\n", (unsigned char)c[0]);
 printf("c=%x\n", (unsigned char)c[0]);
}

canonical_original_code:
void show_shift_jis_char()
{
 int i; int j;
 int num;
 char c[10] = "あいう";
 printf("c=%s\n", c);
 printf("c=%c\n", c[0]);
 printf("c=%d\n", (unsigned char)c[0]);
 printf("c=%x\n", (unsigned char)c[0]);
}

variable_types: num int

variable_types:
c
char [10]


repo: iwabuchiken/AI

decompiled_code:
int show_shift_jis_wchar()
{
char v1[40]; // [rsp+0h] [rbp-28h] BYREF

setlocale(0, "jpn");
v1[wctomb(v1, 12354)] = 0;
return printf("%s(%d, %%x=%x, (unsigned char)wc=%c wc(%%d)=%d wc(%%x)=%x\n", v1, v1, v1, 66LL, 12354LL, 12354LL);
}

original_code:
void show_shift_jis_wchar()
{
 int i, j;
 int num;
 num = 0;
 char mb[16 + 1];
  wchar_t wc = L'あ';
  int len;
  setlocale( 0, "jpn" );
  len = wctomb( mb, wc );
  mb[len] = '\0';
  printf( "%s(%d, %%x=%x, (unsigned char)wc=%c wc(%%d)=%d wc(%%x)=%x\n",
    mb, mb, mb, (unsigned char)wc, wc, wc);
}

canonical_original_code:
void show_shift_jis_wchar()
{
 int i; int j;
 int num;
 num = 0;
 char mb[-1];
  int wc = L'あ';
  int len;
  setlocale( 0, "jpn" );
  len = wctomb( mb, wc );
  mb[len] = '\0';
  printf( "%s(%d, %%x=%x, (unsigned char)wc=%c wc(%%d)=%d wc(%%x)=%x\n",
    mb, mb, mb, (unsigned char)wc, wc, wc);
}

variable_types: i int

variable_types: j int

variable_types:
mb
char [-1]

variable_types: wc int

variable_types: len int

return_type: void


decompiled_code:
int show_shift_jis()
{
return show_shift_jis_char();
}

canonical_decompiled_code:
int func13()
{
return func11();
}

original_code:
void show_shift_jis()
{
 show_shift_jis_char();
}


repo: ixonos/sensact-emulator

decompiled_code:
__int64 test_orientation_sweep()
{
int v0; // er12
int i; // ebx
_DWORD *v2; // rax
int v3; // er12
int j; // ebx
int v5; // er12
int k; // ebx

v0 = 10;
do
{
for ( i = 0; i != 1000; ++i )
{
v2 = senshub;
senshub[8] = i;
v2[16] = i;
*v2 = 0;
usleep(0x1F40u);
}
sleep(5u);
--v0;
}
while ( v0 );
v3 = 10;
do
{
for ( j = 0; j != 1000; ++j )
{
senshub[16] = j;
usleep(0x640u);
}
--v3;
}
while ( v3 );
v5 = 10;
sleep(5u);
do
{
for ( k = 0; k != 1000; ++k )
{
*senshub = k;
usleep(0x320u);
}
--v5;
}
while ( v5 );
return 0LL;
}

original_code:
static char * test_orientation_sweep() {
 int i, count = 0;
 for (count = 0; count < 10; count++) {
  for (i = 0; i < 1000; i++) {
   senshub->pitch = i;
   senshub->yaw = i;
   senshub->roll = 0;
   usleep(8000);
  }
  sleep(5);
 }
 for (count = 0; count < 10; count++) {
  for (i = 0; i < 1000; i++) {
   senshub->yaw = i;
   usleep(8000/5);
  }
 }
 sleep(5);
 for (count = 0; count < 10; count++) {
  for (i = 0; i < 1000; i++) {
   senshub->roll = i;
   usleep(8000/10);
  }
 }
 return 0;
}

canonical_original_code:
static char *test_orientation_sweep() {
 int i; int count = 0;
 for (count = 0; count < 10; count++) {
  for (i = 0; i < 1000; i++) {
   senshub->pitch = i;
   senshub->yaw = i;
   senshub->roll = 0;
   usleep(8000);
  }
  sleep(5);
 }
 for (count = 0; count < 10; count++) {
  for (i = 0; i < 1000; i++) {
   senshub->yaw = i;
   usleep(8000/5);
  }
 }
 sleep(5);
 for (count = 0; count < 10; count++) {
  for (i = 0; i < 1000; i++) {
   senshub->roll = i;
   usleep(8000/10);
  }
 }
 return 0;
}

variable_types: count int

return_type: char *


decompiled_code:
void *__fastcall runorientation_test(void *a1)
{
void *result; // rax

while ( 1 )
{
result = (void *)test_orientation_sweep(a1);
++tests_run;
if ( result )
break;
a1 = test_orientation_sweep + 1;
sleep(1u);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
void *result; // rax

while ( 1 )
{
result = (void *)func0(a1);
++tests_run;
if ( result )
break;
a1 = test_orientation_sweep + 1;
sleep(1u);
}
return result;
}

original_code:
void * runorientation_test()
{
        while(1)
        {
            do { char *message = test_orientation_sweep(); tests_run++; if (message) return message; } while (0);
            sleep(1);
        }
}

canonical_original_code:
void *runorientation_test()
{
        while(1)
        {
            do { char *message = test_orientation_sweep(); tests_run++; if (message) return message; } while (0);
            sleep(1);
        }
}

variable_types:
message
char *

return_type: void *


decompiled_code:
__int64 test_temperature_sweep()
{
int v0; // eax
float v1; // xmm0_4
__int64 result; // rax

v0 = rand();
v1 = (float)(5 * (v0 / 5) - v0 + 20);
result = 0LL;
*((float *)senshub + 40) = v1;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
float v1; // xmm0_4
__int64 result; // rax

v0 = rand();
v1 = (float)(5 * (v0 / 5) - v0 + 20);
result = 0LL;
*((float *)senshub + 40) = v1;
return result;
}

original_code:
static char * test_temperature_sweep() {
  senshub->objtemp = 20 - (rand() % 5);
 return 0;
}

canonical_original_code:
static char *test_temperature_sweep() {
  senshub->objtemp = 20 - (rand() % 5);
 return 0;
}


decompiled_code:
void *__fastcall runtemperature_test(void *a1)
{
void *result; // rax

while ( 1 )
{
result = (void *)test_temperature_sweep(a1);
++tests_run;
if ( result )
break;
a1 = test_orientation_sweep + 1;
sleep(1u);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1)
{
void *result; // rax

while ( 1 )
{
result = (void *)func2(a1);
++tests_run;
if ( result )
break;
a1 = test_orientation_sweep + 1;
sleep(1u);
}
return result;
}

original_code:
void * runtemperature_test()
{
        while(1)
        {
           do { char *message = test_temperature_sweep(); tests_run++; if (message) return message; } while (0);
           sleep(1);
        }
}

canonical_original_code:
void *runtemperature_test()
{
        while(1)
        {
           do { char *message = test_temperature_sweep(); tests_run++; if (message) return message; } while (0);
           sleep(1);
        }
}


decompiled_code:
__int64 test_ambient_temperature_sweep()
{
int v0; // eax
float v1; // xmm0_4
__int64 result; // rax

v0 = rand();
v1 = (float)(5 * (v0 / 5) - v0);
result = 0LL;
*((float *)senshub + 48) = v1;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
float v1; // xmm0_4
__int64 result; // rax

v0 = rand();
v1 = (float)(5 * (v0 / 5) - v0);
result = 0LL;
*((float *)senshub + 48) = v1;
return result;
}

original_code:
static char * test_ambient_temperature_sweep() {
  senshub->ambtemp = 0 - (rand() % 5);
 return 0;
}

canonical_original_code:
static char *test_ambient_temperature_sweep() {
  senshub->ambtemp = 0 - (rand() % 5);
 return 0;
}


decompiled_code:
void *__fastcall runambienttemperature_test(void *a1)
{
void *result; // rax

while ( 1 )
{
result = (void *)test_ambient_temperature_sweep(a1);
++tests_run;
if ( result )
break;
a1 = (void *)500000;
usleep(0x7A120u);
}
return result;
}

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

while ( 1 )
{
result = (void *)func4(a1);
++tests_run;
if ( result )
break;
a1 = (void *)500000;
usleep(0x7A120u);
}
return result;
}

original_code:
void * runambienttemperature_test()
{
        while(1)
        {
           do { char *message = test_ambient_temperature_sweep(); tests_run++; if (message) return message; } while (0);
           usleep(500000);
        }
}

canonical_original_code:
void *runambienttemperature_test()
{
        while(1)
        {
           do { char *message = test_ambient_temperature_sweep(); tests_run++; if (message) return message; } while (0);
           usleep(500000);
        }
}


decompiled_code:
__int64 test_humidity_sweep()
{
int v0; // eax
float v1; // xmm0_4
__int64 result; // rax

v0 = rand();
v1 = (float)(20 * (v0 / 20) - v0 + 80);
result = 0LL;
*((float *)senshub + 56) = v1;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax
float v1; // xmm0_4
__int64 result; // rax

v0 = rand();
v1 = (float)(20 * (v0 / 20) - v0 + 80);
result = 0LL;
*((float *)senshub + 56) = v1;
return result;
}

original_code:
static char * test_humidity_sweep() {
  senshub->humidity = 80 - (rand() % 20);
 return 0;
}

canonical_original_code:
static char *test_humidity_sweep() {
  senshub->humidity = 80 - (rand() % 20);
 return 0;
}


decompiled_code:
void *__fastcall runhumidity_test(void *a1)
{
void *result; // rax

while ( 1 )
{
result = (void *)test_humidity_sweep(a1);
++tests_run;
if ( result )
break;
a1 = (void *)1000000;
usleep(0xF4240u);
}
return result;
}

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

while ( 1 )
{
result = (void *)func6(a1);
++tests_run;
if ( result )
break;
a1 = (void *)1000000;
usleep(0xF4240u);
}
return result;
}

original_code:
void * runhumidity_test()
{
        while(1)
        {
           do { char *message = test_humidity_sweep(); tests_run++; if (message) return message; } while (0);
           usleep(1000000);
        }
}

canonical_original_code:
void *runhumidity_test()
{
        while(1)
        {
           do { char *message = test_humidity_sweep(); tests_run++; if (message) return message; } while (0);
           usleep(1000000);
        }
}


decompiled_code:
__int64 test_brightness_sweep()
{
int v0; // eax
float v1; // xmm0_4
__int64 result; // rax

v0 = rand();
v1 = (float)(10 * (v0 / 10) - v0 + 80);
result = 0LL;
*((float *)senshub + 24) = v1;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // eax
float v1; // xmm0_4
__int64 result; // rax

v0 = rand();
v1 = (float)(10 * (v0 / 10) - v0 + 80);
result = 0LL;
*((float *)senshub + 24) = v1;
return result;
}

original_code:
static char * test_brightness_sweep() {
  senshub->light = 80 - (rand() % 10);
 return 0;
}

canonical_original_code:
static char *test_brightness_sweep() {
  senshub->light = 80 - (rand() % 10);
 return 0;
}


decompiled_code:
void *__fastcall runbrightness_test(void *a1)
{
void *result; // rax

while ( 1 )
{
result = (void *)test_brightness_sweep(a1);
++tests_run;
if ( result )
break;
a1 = (void *)900000;
usleep(0xDBBA0u);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func9(void *a1)
{
void *result; // rax

while ( 1 )
{
result = (void *)func8(a1);
++tests_run;
if ( result )
break;
a1 = (void *)900000;
usleep(0xDBBA0u);
}
return result;
}

original_code:
void * runbrightness_test()
{
        while(1)
        {
           do { char *message = test_brightness_sweep(); tests_run++; if (message) return message; } while (0);
           usleep(900000);
        }
}

canonical_original_code:
void *runbrightness_test()
{
        while(1)
        {
           do { char *message = test_brightness_sweep(); tests_run++; if (message) return message; } while (0);
           usleep(900000);
        }
}


decompiled_code:
__int64 test_air_pressure()
{
int v0; // eax
float v1; // xmm0_4
__int64 result; // rax

v0 = rand();
v1 = (float)(50 * (v0 / 50) - v0 + 800);
result = 0LL;
*((float *)senshub + 32) = v1;
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // eax
float v1; // xmm0_4
__int64 result; // rax

v0 = rand();
v1 = (float)(50 * (v0 / 50) - v0 + 800);
result = 0LL;
*((float *)senshub + 32) = v1;
return result;
}

original_code:
static char * test_air_pressure() {
  senshub->presure = 800 - (rand() % 50);
 return 0;
}

canonical_original_code:
static char *test_air_pressure() {
  senshub->presure = 800 - (rand() % 50);
 return 0;
}


decompiled_code:
void *__fastcall runairpressure_test(void *a1)
{
void *result; // rax

while ( 1 )
{
result = (void *)test_air_pressure(a1);
++tests_run;
if ( result )
break;
a1 = (void *)900000;
usleep(0xDBBA0u);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func11(void *a1)
{
void *result; // rax

while ( 1 )
{
result = (void *)func10(a1);
++tests_run;
if ( result )
break;
a1 = (void *)900000;
usleep(0xDBBA0u);
}
return result;
}

original_code:
void * runairpressure_test()
{
        while(1)
        {
           do { char *message = test_air_pressure(); tests_run++; if (message) return message; } while (0);
           usleep(900000);
        }
}

canonical_original_code:
void *runairpressure_test()
{
        while(1)
        {
           do { char *message = test_air_pressure(); tests_run++; if (message) return message; } while (0);
           usleep(900000);
        }
}


decompiled_code:
void __fastcall __noreturn runbletemp_test(void *a1)
{
while ( 1 )
{
test_ble_sweep_isra_0(a1);
a1 = (void *)800000;
usleep(0xC3500u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func15(void *a1)
{
while ( 1 )
{
func14(a1);
a1 = (void *)800000;
usleep(0xC3500u);
}
}

original_code:
void * runbletemp_test() {
  while (1) {
    test_ble_sweep();
    usleep(800000);
  }
}

canonical_original_code:
void *runbletemp_test() {
  while (1) {
    test_ble_sweep();
    usleep(800000);
  }
}


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

result = engine;
*(_BYTE *)(engine + 64LL) = a1;
return result;
}

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

result = engine;
*(_BYTE *)(engine + 64LL) = a1;
return result;
}

original_code:
void emulator_set_direction(int direction) {
 engine->direction = direction;
}

variable_types: direction int


decompiled_code:
__int64 emulator_get_rpm()
{
return (unsigned int)*engine;
}

canonical_decompiled_code:
__int64 func17()
{
return (unsigned int)*engine;
}

original_code:
int emulator_get_rpm() {
 return engine->rpm;
}

return_type: int


decompiled_code:
__int64 emulator_get_rpm_max()
{
return (unsigned int)engine[8];
}

canonical_decompiled_code:
__int64 func18()
{
return (unsigned int)engine[8];
}

original_code:
int emulator_get_rpm_max(){
  return engine->rpm_max;
}


decompiled_code:
__int64 test_engine_setting_its_value()
{
int v0; // ebx
int v1; // ebp
int v2; // edi
__int64 result; // rax

emulator_set_rpm(0);
v0 = emulator_get_rpm();
v1 = emulator_get_rpm_max();
if ( rpm_max_last == v1 )
{
test_engine_rand_value_isra_0();
result = 0LL;
}
else
{
rpm_max_last = v1;
while ( v1 >= v0 )
{
v2 = v0++;
emulator_set_rpm(v2);
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func20()
{
int v0; // ebx
int v1; // ebp
int v2; // edi
__int64 result; // rax

emulator_set_rpm(0);
v0 = func17();
v1 = func18();
if ( rpm_max_last == v1 )
{
func19();
result = 0LL;
}
else
{
rpm_max_last = v1;
while ( v1 >= v0 )
{
v2 = v0++;
emulator_set_rpm(v2);
}
result = 0LL;
}
return result;
}

original_code:
static char * test_engine_setting_its_value() {
 emulator_set_rpm(0);
 int l_rpm = emulator_get_rpm();
 int l_rpm_max = emulator_get_rpm_max();
 if (rpm_max_last != l_rpm_max) {
   rpm_max_last = l_rpm_max;
   if (l_rpm <= l_rpm_max){
     for (; l_rpm <= l_rpm_max ; l_rpm++) {
       emulator_set_rpm(l_rpm);
   }
  }
  else {
    for (l_rpm = l_rpm_max; l_rpm > l_rpm_max ; l_rpm--) {
       emulator_set_rpm(l_rpm);
    }
  }
 }
 else {
   test_engine_rand_value();
 }
 return 0;
}

canonical_original_code:
static char *test_engine_setting_its_value() {
 emulator_set_rpm(0);
 int l_rpm = emulator_get_rpm();
 int l_rpm_max = emulator_get_rpm_max();
 if (rpm_max_last != l_rpm_max) {
   rpm_max_last = l_rpm_max;
   if (l_rpm <= l_rpm_max){
     for (; l_rpm <= l_rpm_max ; l_rpm++) {
       emulator_set_rpm(l_rpm);
   }
  }
  else {
    for (l_rpm = l_rpm_max; l_rpm > l_rpm_max ; l_rpm--) {
       emulator_set_rpm(l_rpm);
    }
  }
 }
 else {
   test_engine_rand_value();
 }
 return 0;
}


decompiled_code:
void *__fastcall runengine_tests(void *a1)
{
void *result; // rax

while ( 1 )
{
result = (void *)test_engine_setting_its_value(a1);
++tests_run;
if ( result )
break;
a1 = (void *)100000;
usleep(0x186A0u);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func21(void *a1)
{
void *result; // rax

while ( 1 )
{
result = (void *)func20(a1);
++tests_run;
if ( result )
break;
a1 = (void *)100000;
usleep(0x186A0u);
}
return result;
}

original_code:
void * runengine_tests() {
 while(1) {
   do { char *message = test_engine_setting_its_value(); tests_run++; if (message) return message; } while (0);
   usleep(100000);
 }
 return 0;
}

canonical_original_code:
void *runengine_tests() {
 while(1) {
   do { char *message = test_engine_setting_its_value(); tests_run++; if (message) return message; } while (0);
   usleep(100000);
 }
 return 0;
}


setup

decompiled_code:
__int64 setup()
{
__int64 v0; // rbp
unsigned int v1; // er12
__int64 v2; // rbp
__int64 v3; // rbp
__int64 result; // rax
int *v5; // rax
unsigned int v6; // eax
int *v7; // rax
unsigned int v8; // eax
int *v9; // rax
unsigned int v10; // eax

printf("setup() : shared_memory_senshub = %d\n", 1235LL);
v0 = (unsigned int)shmget(1235, 0x100uLL, 950);
printf("setup() : shmid = %d\n", v0);
if ( (_DWORD)v0 == -1 )
{
v5 = _errno_location();
v1 = 0;
v6 = (unsigned int)strerror(*v5);
printf("shmget failed %s \n", (const char *)v6);
}
else
{
v1 = 1;
shared_memory = shmat(v0, 0LL, 0);
senshub = (_DWORD *)shared_memory;
}
v2 = (unsigned int)shmget(1234, 0x60uLL, 950);
printf("setup() : shmid = %d\n", v2);
if ( (_DWORD)v2 == -1 )
{
v9 = _errno_location();
v10 = (unsigned int)strerror(*v9);
printf("shmget failed %s \n", (const char *)v10);
}
else
{
v1 = 1;
puts("setup:shmid");
shared_memory = shmat(v2, 0LL, 0);
printf("setup:shmid:shared_memory 0x%x\n", shared_memory);
engine = (_DWORD *)shared_memory;
printf("setup:shmid:engine 0x%x\n", shared_memory);
}
v3 = (unsigned int)shmget(1236, 0x20uLL, 950);
printf("setup() : shmid = %d\n", v3);
if ( (_DWORD)v3 == -1 )
{
v7 = _errno_location();
v8 = (unsigned int)strerror(*v7);
printf("shmget failed %s \n", (const char *)v8);
result = v1;
}
else
{
puts("setup:shmid");
shared_memory = shmat(v3, 0LL, 0);
printf("setup:shmid:shared_memory 0x%x\n", shared_memory);
ble = shared_memory;
printf("setup:shmid:ble 0x%x\n", shared_memory);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func22()
{
__int64 v0; // rbp
unsigned int v1; // er12
__int64 v2; // rbp
__int64 v3; // rbp
__int64 result; // rax
int *v5; // rax
unsigned int v6; // eax
int *v7; // rax
unsigned int v8; // eax
int *v9; // rax
unsigned int v10; // eax

printf("setup() : shared_memory_senshub = %d\n", 1235LL);
v0 = (unsigned int)shmget(1235, 0x100uLL, 950);
printf("setup() : shmid = %d\n", v0);
if ( (_DWORD)v0 == -1 )
{
v5 = _errno_location();
v1 = 0;
v6 = (unsigned int)strerror(*v5);
printf("shmget failed %s \n", (const char *)v6);
}
else
{
v1 = 1;
shared_memory = shmat(v0, 0LL, 0);
senshub = (_DWORD *)shared_memory;
}
v2 = (unsigned int)shmget(1234, 0x60uLL, 950);
printf("setup() : shmid = %d\n", v2);
if ( (_DWORD)v2 == -1 )
{
v9 = _errno_location();
v10 = (unsigned int)strerror(*v9);
printf("shmget failed %s \n", (const char *)v10);
}
else
{
v1 = 1;
puts("setup:shmid");
shared_memory = shmat(v2, 0LL, 0);
printf("setup:shmid:shared_memory 0x%x\n", shared_memory);
engine = (_DWORD *)shared_memory;
printf("setup:shmid:engine 0x%x\n", shared_memory);
}
v3 = (unsigned int)shmget(1236, 0x20uLL, 950);
printf("setup() : shmid = %d\n", v3);
if ( (_DWORD)v3 == -1 )
{
v7 = _errno_location();
v8 = (unsigned int)strerror(*v7);
printf("shmget failed %s \n", (const char *)v8);
result = v1;
}
else
{
puts("setup:shmid");
shared_memory = shmat(v3, 0LL, 0);
printf("setup:shmid:shared_memory 0x%x\n", shared_memory);
ble = shared_memory;
printf("setup:shmid:ble 0x%x\n", shared_memory);
result = 1LL;
}
return result;
}

original_code:
int setup() {
 int retval = 0;
 int shmid = 0;
  printf("setup() : shared_memory_senshub = %d\n",1235);
 shmid = shmget((key_t) 1235, sizeof(senshub_t),
   0666 | 01000);
  printf("setup() : shmid = %d\n",shmid);
 if (shmid == -1) {
  printf("shmget failed %s \n", strerror( (*__errno_location ())));
 } else {
  shared_memory = shmat(shmid, (void *) 0, 0);
  senshub = (senshub_t *) shared_memory;
  retval = 1;
  }
 shmid = shmget((key_t) 1234, sizeof(engine_t),0666 | 01000);
  printf("setup() : shmid = %d\n",shmid);
 if (shmid == -1) {
  printf("shmget failed %s \n", strerror( (*__errno_location ())));
 } else {
    printf("setup:shmid\n");
  shared_memory = shmat(shmid, (void *) 0, 0);
    printf("setup:shmid:shared_memory 0x%x\n",shared_memory);
  engine = (engine_t *) shared_memory;
    printf("setup:shmid:engine 0x%x\n",engine);
  retval = 1;
  }
 shmid = shmget((key_t) 1236, sizeof(ble_t),0666 | 01000);
  printf("setup() : shmid = %d\n",shmid);
 if (shmid == -1) {
  printf("shmget failed %s \n", strerror( (*__errno_location ())));
 } else {
    printf("setup:shmid\n");
  shared_memory = shmat(shmid, (void *) 0, 0);
    printf("setup:shmid:shared_memory 0x%x\n",shared_memory);
  ble = (ble_t *) shared_memory;
    printf("setup:shmid:ble 0x%x\n",ble);
  retval = 1;
  }
 return retval;
}

canonical_original_code:
int setup() {
 int retval = 0;
 int shmid = 0;
  printf("setup() : shared_memory_senshub = %d\n",1235);
 shmid = shmget((int) 1235, sizeof(senshub_t),
   0666 | 01000);
  printf("setup() : shmid = %d\n",shmid);
 if (shmid == -1) {
  printf("shmget failed %s \n", strerror( (*__errno_location ())));
 } else {
  shared_memory = shmat(shmid, (void *) 0, 0);
  senshub = (struct senshub_t *) shared_memory;
  retval = 1;
  }
 shmid = shmget((int) 1234, sizeof(engine_t),0666 | 01000);
  printf("setup() : shmid = %d\n",shmid);
 if (shmid == -1) {
  printf("shmget failed %s \n", strerror( (*__errno_location ())));
 } else {
    printf("setup:shmid\n");
  shared_memory = shmat(shmid, (void *) 0, 0);
    printf("setup:shmid:shared_memory 0x%x\n",shared_memory);
  engine = (struct engine_t *) shared_memory;
    printf("setup:shmid:engine 0x%x\n",engine);
  retval = 1;
  }
 shmid = shmget((int) 1236, sizeof(ble_t),0666 | 01000);
  printf("setup() : shmid = %d\n",shmid);
 if (shmid == -1) {
  printf("shmget failed %s \n", strerror( (*__errno_location ())));
 } else {
    printf("setup:shmid\n");
  shared_memory = shmat(shmid, (void *) 0, 0);
    printf("setup:shmid:shared_memory 0x%x\n",shared_memory);
  ble = (struct ble_t *) shared_memory;
    printf("setup:shmid:ble 0x%x\n",ble);
  retval = 1;
  }
 return retval;
}

variable_types: retval int

variable_types: shmid int

user_defined_types: struct senshub_t { int roll; char *roll_name; void (*setroll)(int roll); int (*getroll)(); int pitch; char *pitch_name; void (*setpitch)(int roll); int (*getpitch)(); int yaw; char *yaw_name; void (*setyaw)(int yaw); int (*getyaw)(); float light; char *light_name; void (*setlight)(float light); float (*getlight)(); float presure; char *presure_name; void (*setpresure)(float presure); float (*getpresure)(); float objtemp; char *objtemp_name; float (*getobjtemp)(); void (*setobjtemp)(float objtemp); float ambtemp; char *ambtemp_name; float (*getambtemp)(); void (*setambtemp)(float ambtemp); float humidity; char *humidity_name; void (*sethumidity)(float humidity); float (*gethumidity)(); }

user_defined_types: struct engine_t { int rpm; char *rpm_name; void (*setrpm)(int rpm); int (*getrpm)(); int rpm_max; char *rpm_max_name; void (*setrpm_max)(int rpm_max); int (*getrpm_max)(); unsigned char direction; char *direction_name; void (*setdirection)(unsigned char direction); unsigned char (*getdirection)(); }

user_defined_types: struct ble_t { float temp; char *temp_name; void (*settemp)(float rpm); float (*gettemp)(); }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // r12
time_t timer; // [rsp+8h] [rbp-20h] BYREF

v3 = time(&timer);
srand(v3);
puts("main()");
v4 = (unsigned int)setup("main()", argv);
printf("main() : retval = %d\n", v4);
if ( (_DWORD)v4 )
{
all_tests_isra_0();
while ( emulatorRunning )
sleep(1u);
}
else
{
printf("setup failed!");
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // r12
time_t timer; // [rsp+8h] [rbp-20h] BYREF

v3 = time(&timer);
srand(v3);
puts("main()");
v4 = (unsigned int)func22("main()", argv);
printf("main() : retval = %d\n", v4);
if ( (_DWORD)v4 )
{
func13();
while ( emulatorRunning )
sleep(1u);
}
else
{
printf("setup failed!");
}
return v4;
}

original_code:
int main(int argc, char **argv) {
  time_t t;
  srand((unsigned) time(&t));
  printf("main()\n");
 int retval = setup();
  printf("main() : retval = %d\n",retval);
 if (retval) {
    char *result = all_tests();
           while(emulatorRunning != 0)
           {
             sleep(1);
           }
 } else {
  printf("setup failed!");
 }
 return retval;
}

canonical_original_code:
int main(int argc, char **argv) {
  long t;
  srand((unsigned int) time(&t));
  printf("main()\n");
 int retval = setup();
  printf("main() : retval = %d\n",retval);
 if (retval) {
    char *result = all_tests();
           while(emulatorRunning != 0)
           {
             sleep(1);
           }
 } else {
  printf("setup failed!");
 }
 return retval;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: t long

variable_types:
result
char *


getroll

decompiled_code:
__int64 getroll()
{
return (unsigned int)*senshub;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)*senshub;
}

original_code:
int getroll() {
 return senshub->roll;
}

canonical_original_code:
int getroll() {
 return senshub->roll;
}


getpitch

decompiled_code:
__int64 getpitch()
{
return (unsigned int)senshub[8];
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)senshub[8];
}

original_code:
int getpitch() {
 return senshub->pitch;
}


getyaw

decompiled_code:
__int64 getyaw()
{
return (unsigned int)senshub[16];
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)senshub[16];
}

original_code:
int getyaw() {
 return senshub->yaw;
}

canonical_original_code:
int getyaw() {
 return senshub->yaw;
}


getlight

decompiled_code:
float getlight()
{
return *((float *)senshub + 24);
}

canonical_decompiled_code:
float func3()
{
return *((float *)senshub + 24);
}

original_code:
float getlight() {
 return senshub->light;
}

return_type: float


getpresure

decompiled_code:
float getpresure()
{
return *((float *)senshub + 32);
}

canonical_decompiled_code:
float func4()
{
return *((float *)senshub + 32);
}

original_code:
float getpresure() {
 return senshub->presure;
}


getobjtemp

decompiled_code:
float getobjtemp()
{
return *((float *)senshub + 40);
}

canonical_decompiled_code:
float func5()
{
return *((float *)senshub + 40);
}

original_code:
float getobjtemp() {
 return senshub->objtemp;
}


getambtemp

decompiled_code:
float getambtemp()
{
return *((float *)senshub + 48);
}

canonical_decompiled_code:
float func6()
{
return *((float *)senshub + 48);
}

original_code:
float getambtemp() {
 return senshub->ambtemp;
}


gethumidity

decompiled_code:
float gethumidity()
{
return *((float *)senshub + 56);
}

canonical_decompiled_code:
float func7()
{
return *((float *)senshub + 56);
}

original_code:
float gethumidity() {
 return senshub->humidity;
}


decompiled_code:
_DWORD *create_senshub_emulator()
{
int v0; // edi
_DWORD *result; // rax
int *v2; // rax
char *v3; // rax

v0 = shmget(1235, 0x100uLL, 950);
shmid = v0;
if ( v0 == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
printf("shmget failed %s \n", v3);
result = senshub;
}
else
{
result = shmat(v0, 0LL, 0);
shared_mem_senshub = result;
senshub = result;
}
if ( result )
{
*((_QWORD *)result + 1) = "roll";
*((_QWORD *)result + 2) = setroll;
*((_QWORD *)result + 5) = "pitch";
*((_QWORD *)result + 3) = getroll;
*((_QWORD *)result + 9) = "yaw";
*((_QWORD *)result + 6) = setpitch;
*((_QWORD *)result + 13) = "light";
*((_QWORD *)result + 7) = getpitch;
*((_QWORD *)result + 17) = "pressure";
*((_QWORD *)result + 11) = getyaw;
*result = 0;
*((_QWORD *)result + 10) = setyaw;
result[8] = 0;
*((_QWORD *)result + 14) = setlight;
result[16] = 0;
*((_QWORD *)result + 15) = getlight;
result[24] = 0;
*((_QWORD *)result + 18) = setpresure;
result[32] = 1202702336;
*((_QWORD *)result + 19) = getpresure;
result[40] = LC8;
*((_QWORD *)result + 21) = "objTemp";
*((_QWORD *)result + 25) = "ambTemp";
*((_QWORD *)result + 23) = setobjtemp;
result[56] = 0;
*((_QWORD *)result + 22) = getobjtemp;
*((_QWORD *)result + 29) = "humidity";
*((_QWORD *)result + 26) = getambtemp;
result[48] = LC8;
*((_QWORD *)result + 27) = setambtemp;
*((_QWORD *)result + 30) = sethumidity;
*((_QWORD *)result + 31) = gethumidity;
}
return result;
}

canonical_decompiled_code:
_DWORD *func8()
{
int v0; // edi
_DWORD *result; // rax
int *v2; // rax
char *v3; // rax

v0 = shmget(1235, 0x100uLL, 950);
shmid = v0;
if ( v0 == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
printf("shmget failed %s \n", v3);
result = senshub;
}
else
{
result = shmat(v0, 0LL, 0);
shared_mem_senshub = result;
senshub = result;
}
if ( result )
{
*((_QWORD *)result + 1) = "roll";
*((_QWORD *)result + 2) = setroll;
*((_QWORD *)result + 5) = "pitch";
*((_QWORD *)result + 3) = getroll;
*((_QWORD *)result + 9) = "yaw";
*((_QWORD *)result + 6) = setpitch;
*((_QWORD *)result + 13) = "light";
*((_QWORD *)result + 7) = getpitch;
*((_QWORD *)result + 17) = "pressure";
*((_QWORD *)result + 11) = getyaw;
*result = 0;
*((_QWORD *)result + 10) = setyaw;
result[8] = 0;
*((_QWORD *)result + 14) = setlight;
result[16] = 0;
*((_QWORD *)result + 15) = getlight;
result[24] = 0;
*((_QWORD *)result + 18) = setpresure;
result[32] = 1202702336;
*((_QWORD *)result + 19) = getpresure;
result[40] = LC8;
*((_QWORD *)result + 21) = "objTemp";
*((_QWORD *)result + 25) = "ambTemp";
*((_QWORD *)result + 23) = setobjtemp;
result[56] = 0;
*((_QWORD *)result + 22) = getobjtemp;
*((_QWORD *)result + 29) = "humidity";
*((_QWORD *)result + 26) = getambtemp;
result[48] = LC8;
*((_QWORD *)result + 27) = setambtemp;
*((_QWORD *)result + 30) = sethumidity;
*((_QWORD *)result + 31) = gethumidity;
}
return result;
}

original_code:
senshub_t * create_senshub_emulator() {
 shmid = shmget((key_t) 1235, sizeof(senshub_t),
   0666 | 01000);
 if (shmid == -1) {
  printf("shmget failed %s \n", strerror( (*__errno_location ())));
 } else {
  shared_mem_senshub = shmat(shmid, (void *) 0, 0);
  senshub = (senshub_t*) shared_mem_senshub;
 }
 if (senshub != ((void *)0)) {
  senshub->roll = 0;
  senshub->roll_name = "roll";
  senshub->setroll = setroll;
  senshub->getroll = getroll;
  senshub->pitch = 0;
  senshub->pitch_name = "pitch";
  senshub->setpitch = setpitch;
  senshub->getpitch = getpitch;
  senshub->yaw = 0;
  senshub->yaw_name = "yaw";
  senshub->getyaw = getyaw;
  senshub->setyaw = setyaw;
  senshub->light = 0;
  senshub->light_name = "light";
  senshub->setlight = setlight;
  senshub->getlight = getlight;
  senshub->presure = 90000;
  senshub->presure_name = "pressure";
  senshub->setpresure = setpresure;
  senshub->getpresure = getpresure;
  senshub->objtemp = -20;
  senshub->objtemp_name = "objTemp";
  senshub->setobjtemp = setobjtemp;
  senshub->getobjtemp = getobjtemp;
  senshub->ambtemp = -20;
  senshub->ambtemp_name = "ambTemp";
  senshub->getambtemp = getambtemp;
  senshub->setambtemp = setambtemp;
  senshub->humidity = 0;
  senshub->humidity_name = "humidity";
  senshub->sethumidity = sethumidity;
  senshub->gethumidity = gethumidity;
 }
 return senshub;
}

canonical_original_code:
struct senshub_t *create_senshub_emulator() {
 shmid = shmget((int) 1235, sizeof(senshub_t),
   0666 | 01000);
 if (shmid == -1) {
  printf("shmget failed %s \n", strerror( (*__errno_location ())));
 } else {
  shared_mem_senshub = shmat(shmid, (void *) 0, 0);
  senshub = (struct senshub_t *) shared_mem_senshub;
 }
 if (senshub != ((void *)0)) {
  senshub->roll = 0;
  senshub->roll_name = "roll";
  senshub->setroll = setroll;
  senshub->getroll = getroll;
  senshub->pitch = 0;
  senshub->pitch_name = "pitch";
  senshub->setpitch = setpitch;
  senshub->getpitch = getpitch;
  senshub->yaw = 0;
  senshub->yaw_name = "yaw";
  senshub->getyaw = getyaw;
  senshub->setyaw = setyaw;
  senshub->light = 0;
  senshub->light_name = "light";
  senshub->setlight = setlight;
  senshub->getlight = getlight;
  senshub->presure = 90000;
  senshub->presure_name = "pressure";
  senshub->setpresure = setpresure;
  senshub->getpresure = getpresure;
  senshub->objtemp = -20;
  senshub->objtemp_name = "objTemp";
  senshub->setobjtemp = setobjtemp;
  senshub->getobjtemp = getobjtemp;
  senshub->ambtemp = -20;
  senshub->ambtemp_name = "ambTemp";
  senshub->getambtemp = getambtemp;
  senshub->setambtemp = setambtemp;
  senshub->humidity = 0;
  senshub->humidity_name = "humidity";
  senshub->sethumidity = sethumidity;
  senshub->gethumidity = gethumidity;
 }
 return senshub;
}

return_type: struct senshub_t { int roll; char *roll_name; void (*setroll)(int roll); int (*getroll)(); int pitch; char *pitch_name; void (*setpitch)(int roll); int (*getpitch)(); int yaw; char *yaw_name; void (*setyaw)(int yaw); int (*getyaw)(); float light; char *light_name; void (*setlight)(float light); float (*getlight)(); float presure; char *presure_name; void (*setpresure)(float presure); float (*getpresure)(); float objtemp; char *objtemp_name; float (*getobjtemp)(); void (*setobjtemp)(float objtemp); float ambtemp; char *ambtemp_name; float (*getambtemp)(); void (*setambtemp)(float ambtemp); float humidity; char *humidity_name; void (*sethumidity)(float humidity); float (*gethumidity)(); } *


decompiled_code:
int destroy_senshub_emulator()
{
return shmdt(shared_mem_senshub);
}

canonical_decompiled_code:
int func9()
{
return shmdt(shared_mem_senshub);
}

original_code:
void destroy_senshub_emulator() {
 shmdt(shared_mem_senshub);
}


decompiled_code:
__int64 getrpm_max()
{
return *(unsigned int *)(engine + 32LL);
}

canonical_decompiled_code:
__int64 func1()
{
return *(unsigned int *)(engine + 32LL);
}

original_code:
int getrpm_max(void) {
 return engine->rpm_max;
}

canonical_original_code:
int getrpm_max() {
 return engine->rpm_max;
}


getrpm

decompiled_code:
__int64 getrpm()
{
return (unsigned int)*engine;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)*engine;
}

original_code:
int getrpm(void) {
 return engine->rpm;
}

canonical_original_code:
int getrpm() {
 return engine->rpm;
}


getdirection

decompiled_code:
__int64 getdirection()
{
return *((unsigned __int8 *)engine + 64);
}

canonical_decompiled_code:
__int64 func3()
{
return *((unsigned __int8 *)engine + 64);
}

original_code:
uint8_t getdirection() {
 return engine->direction;
}

canonical_original_code:
unsigned char getdirection() {
 return engine->direction;
}

return_type: unsigned char


decompiled_code:
_DWORD *create_emulator_engine()
{
int v0; // edi
_DWORD *result; // rax
int *v2; // rax
char *v3; // rax

v0 = shmget(1234, 0x60uLL, 950);
shmid = v0;
if ( v0 == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
printf("shmget failed %s \n", v3);
result = engine;
}
else
{
result = shmat(v0, 0LL, 0);
shared_mem_engine = result;
engine = result;
}
if ( result )
{
*((_BYTE *)result + 64) = 0;
*((_QWORD *)result + 9) = "direction";
*((_QWORD *)result + 10) = setdirection;
*result = 1000;
*((_QWORD *)result + 11) = getdirection;
*((_QWORD *)result + 1) = "rpm";
*((_QWORD *)result + 3) = getrpm;
result[8] = 1000;
*((_QWORD *)result + 2) = setrpm;
*((_QWORD *)result + 5) = "rpm_max";
*((_QWORD *)result + 7) = getrpm_max;
*((_QWORD *)result + 6) = setrpm_max;
}
return result;
}

canonical_decompiled_code:
_DWORD *func4()
{
int v0; // edi
_DWORD *result; // rax
int *v2; // rax
char *v3; // rax

v0 = shmget(1234, 0x60uLL, 950);
shmid = v0;
if ( v0 == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
printf("shmget failed %s \n", v3);
result = engine;
}
else
{
result = shmat(v0, 0LL, 0);
shared_mem_engine = result;
engine = result;
}
if ( result )
{
*((_BYTE *)result + 64) = 0;
*((_QWORD *)result + 9) = "direction";
*((_QWORD *)result + 10) = setdirection;
*result = 1000;
*((_QWORD *)result + 11) = getdirection;
*((_QWORD *)result + 1) = "rpm";
*((_QWORD *)result + 3) = getrpm;
result[8] = 1000;
*((_QWORD *)result + 2) = setrpm;
*((_QWORD *)result + 5) = "rpm_max";
*((_QWORD *)result + 7) = getrpm_max;
*((_QWORD *)result + 6) = setrpm_max;
}
return result;
}

original_code:
engine_t *create_emulator_engine() {
 shmid = shmget((key_t) 1234, sizeof(engine_t),
   0666 | 01000);
 if (shmid == -1) {
  printf("shmget failed %s \n", strerror( (*__errno_location ())));
 } else {
  shared_mem_engine = shmat(shmid, (void *) 0, 0);
  engine = (engine_t*) shared_mem_engine;
 }
 if (engine != ((void *)0)) {
  engine->setdirection = setdirection;
  engine->getdirection = getdirection;
  engine->direction = 0;
  engine->direction_name = "direction";
  engine->rpm = 1000;
  engine->rpm_name = "rpm";
  engine->getrpm = getrpm;
  engine->setrpm = setrpm;
  engine->rpm_max = 1000;
  engine->rpm_max_name = "rpm_max";
  engine->getrpm_max = getrpm_max;
  engine->setrpm_max = setrpm_max;
 }
 return engine;
}

canonical_original_code:
struct engine_t *create_emulator_engine() {
 shmid = shmget((int) 1234, sizeof(engine_t),
   0666 | 01000);
 if (shmid == -1) {
  printf("shmget failed %s \n", strerror( (*__errno_location ())));
 } else {
  shared_mem_engine = shmat(shmid, (void *) 0, 0);
  engine = (struct engine_t *) shared_mem_engine;
 }
 if (engine != ((void *)0)) {
  engine->setdirection = setdirection;
  engine->getdirection = getdirection;
  engine->direction = 0;
  engine->direction_name = "direction";
  engine->rpm = 1000;
  engine->rpm_name = "rpm";
  engine->getrpm = getrpm;
  engine->setrpm = setrpm;
  engine->rpm_max = 1000;
  engine->rpm_max_name = "rpm_max";
  engine->getrpm_max = getrpm_max;
  engine->setrpm_max = setrpm_max;
 }
 return engine;
}

return_type: struct engine_t { int rpm; char *rpm_name; void (*setrpm)(int rpm); int (*getrpm)(); int rpm_max; char *rpm_max_name; void (*setrpm_max)(int rpm_max); int (*getrpm_max)(); unsigned char direction; char *direction_name; void (*setdirection)(unsigned char direction); unsigned char (*getdirection)(); } *


decompiled_code:
int destroy_engine_emulator()
{
return shmdt(shared_mem_engine);
}

canonical_decompiled_code:
int func5()
{
return shmdt(shared_mem_engine);
}

original_code:
void destroy_engine_emulator() {
 shmdt(shared_mem_engine);
}


gettemp

decompiled_code:
float gettemp()
{
return *ble_device;
}

canonical_decompiled_code:
float func1()
{
return *ble_device;
}

original_code:
float gettemp(void) {
 return ble_device->temp;
}

canonical_original_code:
float gettemp() {
 return ble_device->temp;
}


decompiled_code:
float *create_emulator_ble()
{
int v0; // edi
float *result; // rax

v0 = shmget(1236, 0x20uLL, 950);
shmid = v0;
if ( v0 == -1 )
{
puts("shmget failed");
result = ble_device;
}
else
{
result = (float *)shmat(v0, 0LL, 0);
shared_mem = result;
ble_device = result;
}
if ( result )
{
*result = 10.0;
*((_QWORD *)result + 1) = "ble_temp";
*((_QWORD *)result + 3) = gettemp;
*((_QWORD *)result + 2) = settemp;
}
return result;
}

canonical_decompiled_code:
float *func2()
{
int v0; // edi
float *result; // rax

v0 = shmget(1236, 0x20uLL, 950);
shmid = v0;
if ( v0 == -1 )
{
puts("shmget failed");
result = ble_device;
}
else
{
result = (float *)shmat(v0, 0LL, 0);
shared_mem = result;
ble_device = result;
}
if ( result )
{
*result = 10.0;
*((_QWORD *)result + 1) = "ble_temp";
*((_QWORD *)result + 3) = gettemp;
*((_QWORD *)result + 2) = settemp;
}
return result;
}

original_code:
ble_t *create_emulator_ble() {
 shmid = shmget((key_t) 1236, sizeof(ble_t), 0666 | 01000);
 if (shmid == -1) {
  printf("shmget failed\n");
 } else {
  shared_mem = shmat(shmid, (void *) 0, 0);
  ble_device = (ble_t*) shared_mem;
 }
 if (ble_device != ((void *)0)) {
  ble_device->gettemp = gettemp;
  ble_device->settemp = settemp;
  ble_device->temp = 10;
  ble_device->temp_name = "ble_temp";
 }
 return ble_device;
}

canonical_original_code:
struct ble_t *create_emulator_ble() {
 shmid = shmget((int) 1236, sizeof(ble_t), 0666 | 01000);
 if (shmid == -1) {
  printf("shmget failed\n");
 } else {
  shared_mem = shmat(shmid, (void *) 0, 0);
  ble_device = (struct ble_t *) shared_mem;
 }
 if (ble_device != ((void *)0)) {
  ble_device->gettemp = gettemp;
  ble_device->settemp = settemp;
  ble_device->temp = 10;
  ble_device->temp_name = "ble_temp";
 }
 return ble_device;
}

return_type: struct ble_t { float temp; char *temp_name; void (*settemp)(float rpm); float (*gettemp)(); } *


decompiled_code:
int destroy_ble_emulator()
{
return shmdt(shared_mem);
}

canonical_decompiled_code:
int func3()
{
return shmdt(shared_mem);
}

original_code:
void destroy_ble_emulator() {
 shmdt(shared_mem);
}


readfile

repo: izak/monitortools

decompiled_code:
__int64 __fastcall readfile(char *file, void *s, size_t a3)
{
int v4; // eax
int v5; // er13
int i; // er12
int v7; // eax

memset(s, 0, a3);
v4 = open(file, 0);
if ( v4 == -1 )
{
i = -1;
}
else
{
v5 = v4;
for ( i = 0; ; i += v7 )
{
v7 = read(v5, (char *)s + i, a3 - i);
if ( v7 <= 0 )
break;
}
close(v5);
}
return (unsigned int)i;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *file, void *s, size_t a3)
{
int v4; // eax
int v5; // er13
int i; // er12
int v7; // eax

memset(s, 0, a3);
v4 = open(file, 0);
if ( v4 == -1 )
{
i = -1;
}
else
{
v5 = v4;
for ( i = 0; ; i += v7 )
{
v7 = read(v5, (char *)s + i, a3 - i);
if ( v7 <= 0 )
break;
}
close(v5);
}
return (unsigned int)i;
}

original_code:
int readfile(const char *filename, char *buf, size_t count){
    int i = 0;
    int j;
    int fd;
    bzero(buf, count);
    fd = open(filename, 00);
    if(fd!=-1){
        while((j = read(fd, buf+i, count-i))>0){
            i+=j;
        }
        close(fd);
        return i;
    }
    return -1;
}

canonical_original_code:
int readfile(char *filename, char *buf, unsigned long count){
    int i = 0;
    int j;
    int fd;
    bzero(buf, count);
    fd = open(filename, 00);
    if(fd!=-1){
        while((j = read(fd, buf+i, count-i))>0){
            i+=j;
        }
        close(fd);
        return i;
    }
    return -1;
}

variable_types:
filename
char *

variable_types:
buf
char *

variable_types:
count
unsigned long

variable_types: fd int


scanbuf

decompiled_code:
char *__fastcall scanbuf(char *s1, __int64 a2, const char *a3)
{
char *v3; // rbx
char *v4; // r12
size_t v6; // r13

v3 = &s1[a2];
if ( s1 >= &s1[a2] )
return 0LL;
v4 = s1;
v6 = strlen(a3);
while ( strncmp(v4, a3, v6) )
{
for ( ; *v4 && v4 < v3; ++v4 )
;
if ( ++v4 >= v3 )
return 0LL;
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(char *s1, __int64 a2, const char *a3)
{
char *v3; // rbx
char *v4; // r12
size_t v6; // r13

v3 = &s1[a2];
if ( s1 >= &s1[a2] )
return 0LL;
v4 = s1;
v6 = strlen(a3);
while ( strncmp(v4, a3, v6) )
{
for ( ; *v4 && v4 < v3; ++v4 )
;
if ( ++v4 >= v3 )
return 0LL;
}
return v4;
}

original_code:
const char* scanbuf(const char *buf, size_t count, const char *needle){
    int j;
    const char *ptr = buf;
    while(ptr < buf + count){
        if(strncmp(ptr, needle, strlen(needle))==0){
            return ptr;
        }
        while((*ptr!='\0') && (ptr < buf+count)) { ptr++; }
        ptr++;
    }
    return ((void *)0);
}

canonical_original_code:
char *scanbuf(char *buf, unsigned long count, char *needle){
    int j;
    char *ptr = buf;
    while(ptr < buf + count){
        if(strncmp(ptr, needle, strlen(needle))==0){
            return ptr;
        }
        while((*ptr!='\0') && (ptr < buf+count)) { ptr++; }
        ptr++;
    }
    return ((void *)0);
}

variable_types:
needle
char *

variable_types: j int

variable_types:
ptr
char *


getzopeuid

decompiled_code:
__int64 __fastcall getzopeuid(const char *a1)
{
struct passwd *v1; // rax
__int64 result; // rax

v1 = getpwnam(a1);
if ( v1 )
result = v1->pw_uid;
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
struct passwd *v1; // rax
__int64 result; // rax

v1 = getpwnam(a1);
if ( v1 )
result = v1->pw_uid;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int getzopeuid(const char *username){
    struct passwd *pw;
    pw = getpwnam(username);
    if(!pw) return -1;
    return pw->pw_uid;
}

canonical_original_code:
int getzopeuid(char *username){
    struct passwd *pw;
    pw = getpwnam(username);
    if(!pw) return -1;
    return pw->pw_uid;
}

variable_types:
username
char *

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


decompiled_code:
_BOOL8 __fastcall check_string(const char *a1, const char *a2)
{
_BOOL8 result; // rax

if ( *a2 == 33 )
result = strstr(a1, a2 + 1) == 0LL;
else
result = strstr(a1, a2) != 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1, const char *a2)
{
_BOOL8 result; // rax

if ( *a2 == 33 )
result = strstr(a1, a2 + 1) == 0LL;
else
result = strstr(a1, a2) != 0LL;
return result;
}

original_code:
int check_string(const char* haystack, const char* needle){
    if(needle[0]=='!'){
        return strstr(haystack, needle+1) == ((void *)0);
    }
    return strstr(haystack, needle) != ((void *)0);
}

canonical_original_code:
int check_string(char *haystack, char *needle){
    if(needle[0]=='!'){
        return strstr(haystack, needle+1) == ((void *)0);
    }
    return strstr(haystack, needle) != ((void *)0);
}

variable_types:
haystack
char *


decompiled_code:
_BOOL8 __fastcall check_cmdline(const char *a1, const char *a2)
{
_BOOL4 v2; // er13
const char *v3; // rbp
int v4; // edx
char *v5; // rax
char *v6; // rdx
char *v7; // rbx
char v9[1024]; // [rsp+0h] [rbp-C28h] BYREF
char s[1024]; // [rsp+400h] [rbp-828h] BYREF
char dest[1064]; // [rsp+800h] [rbp-428h] BYREF

v2 = 1;
if ( a2 )
{
v3 = a2;
snprintf(v9, 0x400uLL, "%s/cmdline", a1);
v4 = readfile(v9, s, 0x400uLL);
if ( v4 > 1 )
{
v5 = s;
v6 = &s[v4 - 2 + 1];
do
{
if ( !*v5 )
*v5 = 32;
++v5;
}
while ( v5 != v6 );
}
v7 = strchr(a2, 44);
if ( v7 )
{
v2 = 1;
do
{
strncpy(dest, v3, (int)v7 - (int)v3);
dest[(int)v7 - (int)v3] = 0;
if ( v2 )
v2 = check_string(s, dest);
v3 = v7 + 1;
v7 = strchr(v7 + 1, 44);
}
while ( v7 );
if ( v2 )
v2 = check_string(s, v3);
}
else
{
v2 = check_string(s, a2);
}
}
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1, const char *a2)
{
_BOOL4 v2; // er13
const char *v3; // rbp
int v4; // edx
char *v5; // rax
char *v6; // rdx
char *v7; // rbx
char v9[1024]; // [rsp+0h] [rbp-C28h] BYREF
char s[1024]; // [rsp+400h] [rbp-828h] BYREF
char dest[1064]; // [rsp+800h] [rbp-428h] BYREF

v2 = 1;
if ( a2 )
{
v3 = a2;
snprintf(v9, 0x400uLL, "%s/cmdline", a1);
v4 = func0(v9, s, 0x400uLL);
if ( v4 > 1 )
{
v5 = s;
v6 = &s[v4 - 2 + 1];
do
{
if ( !*v5 )
*v5 = 32;
++v5;
}
while ( v5 != v6 );
}
v7 = strchr(a2, 44);
if ( v7 )
{
v2 = 1;
do
{
strncpy(dest, v3, (int)v7 - (int)v3);
dest[(int)v7 - (int)v3] = 0;
if ( v2 )
v2 = func3(s, dest);
v3 = v7 + 1;
v7 = strchr(v7 + 1, 44);
}
while ( v7 );
if ( v2 )
v2 = func3(s, v3);
}
else
{
v2 = func3(s, a2);
}
}
return v2;
}

original_code:
int check_cmdline(const char* pidpath, const char* cmdline){
    if(cmdline != ((void *)0)){
        char procpidcmdline[1024];
        char buf[1024];
        int i, j;
        const char *ptr;
        const char *ptr2;
        snprintf(procpidcmdline, sizeof(procpidcmdline), "%s/cmdline", pidpath);
        i = readfile(procpidcmdline, buf, sizeof(buf));
        for (j=0; j<i-1; j++){
            if(buf[j]=='\0'){
                buf[j]=' ';
            }
        }
        ptr = cmdline;
        ptr2 = strchr(ptr, ',');
        if(ptr2){
            int ok = 1;
            char s[1024];
            int len = 0;
            while(ptr2){
                len = ptr2 - ptr;
                strncpy(s, ptr, len);
                s[len] = '\0';
                ok = ok && check_string(buf, s);
                ptr = ptr2+1;
                ptr2 = strchr(ptr, ',');
            }
            ok = ok && check_string(buf, ptr);
            return ok;
        } else {
            return check_string(buf, cmdline);
        }
    }
    return 1;
}

canonical_original_code:
int check_cmdline(char *pidpath, char *cmdline){
    if(cmdline != ((void *)0)){
        char procpidcmdline[1024];
        char buf[1024];
        int i; int j;
        char *ptr;
        char *ptr2;
        snprintf(procpidcmdline, sizeof(procpidcmdline), "%s/cmdline", pidpath);
        i = readfile(procpidcmdline, buf, sizeof(buf));
        for (j=0; j<i-1; j++){
            if(buf[j]=='\0'){
                buf[j]=' ';
            }
        }
        ptr = cmdline;
        ptr2 = strchr(ptr, ',');
        if(ptr2){
            int ok = 1;
            char s[1024];
            int len = 0;
            while(ptr2){
                len = ptr2 - ptr;
                strncpy(s, ptr, len);
                s[len] = '\0';
                ok = ok && check_string(buf, s);
                ptr = ptr2+1;
                ptr2 = strchr(ptr, ',');
            }
            ok = ok && check_string(buf, ptr);
            return ok;
        } else {
            return check_string(buf, cmdline);
        }
    }
    return 1;
}

variable_types:
pidpath
char *

variable_types:
cmdline
char *

variable_types:
procpidcmdline
char [1024]

variable_types:
buf
char [1024]

variable_types: i int

variable_types: ok int

variable_types: len int


monitored

decompiled_code:
_BOOL8 __fastcall monitored(char *file, const char *a2, const char *a3, const char *a4, char *a5, size_t a6)
{
_BOOL8 result; // rax
int v10; // ebp
int v11; // er8
int v12; // eax
char *v13; // rdi
char *v14; // rax
struct stat v15; // [rsp+0h] [rbp-104B8h] BYREF
char s[1024]; // [rsp+90h] [rbp-10428h] BYREF
char s1[65576]; // [rsp+490h] [rbp-10028h] BYREF

result = check_cmdline(file, a4);
if ( result )
{
v10 = getzopeuid(a2);
v11 = stat(file, &v15);
result = 0LL;
if ( v11 != -1 )
{
if ( v15.st_uid == v10
&& (snprintf(s, 0x400uLL, "%s/environ", file),
v12 = readfile(s, s1, 0xFFFFuLL),
(v13 = scanbuf(s1, v12, a3)) != 0LL)
&& (v14 = strchr(v13, 61)) != 0LL )
{
strncpy(a5, v14 + 1, a6);
result = 1LL;
}
else
{
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(char *file, const char *a2, const char *a3, const char *a4, char *a5, size_t a6)
{
_BOOL8 result; // rax
int v10; // ebp
int v11; // er8
int v12; // eax
char *v13; // rdi
char *v14; // rax
struct stat v15; // [rsp+0h] [rbp-104B8h] BYREF
char s[1024]; // [rsp+90h] [rbp-10428h] BYREF
char s1[65576]; // [rsp+490h] [rbp-10028h] BYREF

result = func4(file, a4);
if ( result )
{
v10 = func2(a2);
v11 = stat(file, &v15);
result = 0LL;
if ( v11 != -1 )
{
if ( v15.st_uid == v10
&& (snprintf(s, 0x400uLL, "%s/environ", file),
v12 = func0(s, s1, 0xFFFFuLL),
(v13 = func1(s1, v12, a3)) != 0LL)
&& (v14 = strchr(v13, 61)) != 0LL )
{
strncpy(a5, v14 + 1, a6);
result = 1LL;
}
else
{
result = 0LL;
}
}
}
return result;
}

original_code:
int monitored(const char *pidpath, const char *zopeuser, const char *tag, const char* cmdline, char *name, size_t nlen){
    if(check_cmdline(pidpath, cmdline)){
        struct stat s_procpid;
        uid_t zopeuid = getzopeuid(zopeuser);
        if(stat(pidpath, &s_procpid)==-1){
            return 0;
        }
        if(s_procpid.st_uid == zopeuid){
            char procpidenv[1024];
            char env[65535];
            const char *ptr;
            int i;
            snprintf(procpidenv, sizeof(procpidenv), "%s/environ", pidpath);
            i = readfile(procpidenv, env, sizeof(env));
            if(ptr=scanbuf(env, i, tag)){
                if(ptr = strchr(ptr, '=')){
                    ptr++;
                    strncpy(name, ptr, nlen);
                    return 1;
                }
            }
        }
    }
    return 0;
}

canonical_original_code:
int monitored(char *pidpath, char *zopeuser, char *tag, char *cmdline, char *name, unsigned long nlen){
    if(check_cmdline(pidpath, cmdline)){
        struct stat s_procpid;
        unsigned int zopeuid = getzopeuid(zopeuser);
        if(stat(pidpath, &s_procpid)==-1){
            return 0;
        }
        if(s_procpid.st_uid == zopeuid){
            char procpidenv[1024];
            char env[65535];
            char *ptr;
            int i;
            snprintf(procpidenv, sizeof(procpidenv), "%s/environ", pidpath);
            i = readfile(procpidenv, env, sizeof(env));
            if(ptr=scanbuf(env, i, tag)){
                if(ptr = strchr(ptr, '=')){
                    ptr++;
                    strncpy(name, ptr, nlen);
                    return 1;
                }
            }
        }
    }
    return 0;
}

variable_types:
zopeuser
char *

variable_types:
tag
char *

variable_types:
name
char *

variable_types:
nlen
unsigned long

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

variable_types:
zopeuid
unsigned int

variable_types:
procpidenv
char [1024]

variable_types:
env
char [65535]

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


splitbuf

decompiled_code:
void __fastcall splitbuf(char *s, __int64 a2, char a3)
{
int v3; // er12
char *v4; // rax

v3 = a3;
if ( s < &s[a2] )
{
do
{
v4 = strchr(s, v3);
if ( !v4 )
break;
*v4 = 0;
}
while ( &s[a2] > v4 + 1 );
}
}

canonical_decompiled_code:
void __fastcall func0(char *s, __int64 a2, char a3)
{
int v3; // er12
char *v4; // rax

v3 = a3;
if ( s < &s[a2] )
{
do
{
v4 = strchr(s, v3);
if ( !v4 )
break;
*v4 = 0;
}
while ( &s[a2] > v4 + 1 );
}
}

original_code:
void splitbuf(char *buf, size_t count, char separator){
    char *ptr = buf;
    while((ptr < buf + count) && (ptr = strchr(buf, separator))){
        *ptr = '\0';
        ptr++;
    }
}

canonical_original_code:
void splitbuf(char *buf, unsigned long count, char separator){
    char *ptr = buf;
    while((ptr < buf + count) && (ptr = strchr(buf, separator))){
        *ptr = '\0';
        ptr++;
    }
}

variable_types:
buf
char *

variable_types:
count
unsigned long

variable_types: separator char

variable_types:
ptr
char *


getuptime

decompiled_code:
__int64 getuptime()
{
__int64 v0; // r12
const char *v1; // rbp
char *v2; // rax
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

v0 = 0LL;
readfile("/proc/stat", v4, 1024LL);
splitbuf(v4, 1024LL, 10);
v1 = (const char *)scanbuf(v4, 1024LL, "cpu ");
while ( 1 )
{
v2 = strchr(v1, 32);
if ( !v2 )
break;
v1 = v2 + 1;
if ( (v2[1] & 0xDF) != 0 )
v0 += atoi(v2 + 1);
}
return v0;
}

original_code:
unsigned long int getuptime(){
    char buf[1024];
    const char *ptr;
    unsigned long int total;
    readfile("/proc/stat", buf, sizeof(buf));
    splitbuf(buf, sizeof(buf), '\n');
    ptr = scanbuf(buf, sizeof(buf), "cpu ");
    total = 0;
    while(ptr = strchr(ptr, ' ')){
        ptr++;
        if((*ptr != '\0') && (*ptr!=' ')){
            total+=atoi(ptr);
        }
    }
    return total;
}

canonical_original_code:
unsigned long getuptime(){
    char buf[1024];
    char *ptr;
    unsigned long total;
    readfile("/proc/stat", buf, sizeof(buf));
    splitbuf(buf, sizeof(buf), '\n');
    ptr = scanbuf(buf, sizeof(buf), "cpu ");
    total = 0;
    while(ptr = strchr(ptr, ' ')){
        ptr++;
        if((*ptr != '\0') && (*ptr!=' ')){
            total+=atoi(ptr);
        }
    }
    return total;
}

variable_types:
total
unsigned long

return_type: unsigned long


cpuusage

decompiled_code:
__int64 __fastcall cpuusage(unsigned int a1)
{
__int64 v2; // [rsp+0h] [rbp-1418h] BYREF
__int64 v3; // [rsp+8h] [rbp-1410h] BYREF
char s[1024]; // [rsp+10h] [rbp-1408h] BYREF
char v5[4104]; // [rsp+410h] [rbp-1008h] BYREF

snprintf(s, 0x400uLL, "/proc/%d/stat", a1);
readfile(s, v5, 4096LL);
_isoc99_sscanf(
v5,
"%*d %*s %*c %*d %*d %*d %*d %*d %*lu %*lu %*lu %*lu %*lu %lu %lu %*ld %*ld %*ld %*ld %*ld %*ld %*lu %*lu %*ld %*lu %"
"*lu %*lu %*lu %*lu %*lu %*u %*u %*u %*u %*lu %*lu %*lu",
&v2,
&v3);
return v2 + v3;
}

original_code:
unsigned long int cpuusage(pid_t pid){
    char procpidstat[1024];
    char buf[4096];
    unsigned long int utime, stime;
    snprintf(procpidstat, sizeof(procpidstat), "/proc/%d/stat", pid);
    readfile(procpidstat, buf, sizeof(buf));
    sscanf(buf,
            "%*d "
            "%*s "
            "%*c "
            "%*d %*d %*d %*d %*d "
            "%*lu %*lu %*lu %*lu %*lu %lu %lu "
            "%*ld %*ld %*ld %*ld %*ld %*ld "
            "%*lu %*lu "
            "%*ld "
            "%*lu %*lu %*lu %*lu %*lu %*lu "
            "%*u %*u %*u %*u "
            "%*lu %*lu %*lu",
            &utime, &stime);
    return utime+stime;
}

canonical_original_code:
unsigned long cpuusage(int pid){
    char procpidstat[1024];
    char buf[4096];
    unsigned long utime; unsigned long stime;
    snprintf(procpidstat, sizeof(procpidstat), "/proc/%d/stat", pid);
    readfile(procpidstat, buf, sizeof(buf));
    sscanf(buf,
            "%*d "
            "%*s "
            "%*c "
            "%*d %*d %*d %*d %*d "
            "%*lu %*lu %*lu %*lu %*lu %lu %lu "
            "%*ld %*ld %*ld %*ld %*ld %*ld "
            "%*lu %*lu "
            "%*ld "
            "%*lu %*lu %*lu %*lu %*lu %*lu "
            "%*u %*u %*u %*u "
            "%*lu %*lu %*lu",
            &utime, &stime);
    return utime+stime;
}

variable_types: pid int

variable_types:
procpidstat
char [1024]

variable_types:
buf
char [4096]

variable_types:
utime
unsigned long

variable_types:
stime
unsigned long


writecache

decompiled_code:
void __fastcall writecache(const char *a1, __int64 a2, __int64 a3)
{
int v4; // eax
int v5; // er12
int v6; // ebp
int v7; // eax
char v8[1064]; // [rsp+0h] [rbp-428h] BYREF

v4 = open(a1, 65, 384LL);
if ( v4 == -1 )
{
perror("open");
}
else
{
v5 = v4;
v6 = snprintf(v8, 0x400uLL, "%lu %lu\n", a2, a3);
do
{
while ( 1 )
{
v7 = write(v5, v8, v6);
if ( v7 == -1 )
break;
v6 -= v7;
if ( v6 <= 0 )
goto LABEL_6;
}
++v6;
perror("write");
}
while ( v6 > 0 );
LABEL_6:
close(v5);
}
}

canonical_decompiled_code:
void __fastcall func3(const char *a1, __int64 a2, __int64 a3)
{
int v4; // eax
int v5; // er12
int v6; // ebp
int v7; // eax
char v8[1064]; // [rsp+0h] [rbp-428h] BYREF

v4 = open(a1, 65, 384LL);
if ( v4 == -1 )
{
perror("open");
}
else
{
v5 = v4;
v6 = snprintf(v8, 0x400uLL, "%lu %lu\n", a2, a3);
do
{
while ( 1 )
{
v7 = write(v5, v8, v6);
if ( v7 == -1 )
break;
v6 -= v7;
if ( v6 <= 0 )
goto LABEL_6;
}
++v6;
perror("write");
}
while ( v6 > 0 );
LABEL_6:
close(v5);
}
}

original_code:
void writecache(const char *cachefile, unsigned long int uptime, unsigned long int usage){
    int fd = open(cachefile, 01 | 0100, 0400 | 0200);
    if(fd!=-1){
        char buf[1024];
        int n, i;
        n = snprintf(buf, sizeof(buf), "%lu %lu\n", uptime, usage);
        while(n>0){
            if((i = write(fd, buf, n))==-1){
                perror("write");
            }
            n -= i;
        }
        close(fd);
    } else {
        perror("open");
    }
}

canonical_original_code:
void writecache(char *cachefile, unsigned long uptime, unsigned long usage){
    int fd = open(cachefile, 01 | 0100, 0400 | 0200);
    if(fd!=-1){
        char buf[1024];
        int n; int i;
        n = snprintf(buf, sizeof(buf), "%lu %lu\n", uptime, usage);
        while(n>0){
            if((i = write(fd, buf, n))==-1){
                perror("write");
            }
            n -= i;
        }
        close(fd);
    } else {
        perror("open");
    }
}

variable_types:
cachefile
char *

variable_types:
uptime
unsigned long

variable_types:
usage
unsigned long

variable_types: fd int

variable_types:
buf
char [1024]

variable_types: n int

variable_types: i int


readcache

decompiled_code:
__int64 __fastcall readcache(__int64 a1, _QWORD *a2, _QWORD *a3)
{
__int64 result; // rax
_BYTE v5[1048]; // [rsp+0h] [rbp-418h] BYREF

*a3 = 0LL;
*a2 = 0LL;
result = readfile(a1, v5, 1024LL);
if ( (_DWORD)result != -1 )
result = _isoc99_sscanf(v5, "%lu %lu", a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _QWORD *a2, _QWORD *a3)
{
__int64 result; // rax
_BYTE v5[1048]; // [rsp+0h] [rbp-418h] BYREF

*a3 = 0LL;
*a2 = 0LL;
result = readfile(a1, v5, 1024LL);
if ( (_DWORD)result != -1 )
result = _isoc99_sscanf(v5, "%lu %lu", a2, a3);
return result;
}

original_code:
void readcache(const char *cachefile, unsigned long int *uptime, unsigned long int *usage){
    char buf[1024];
    *uptime = *usage = 0;
    if(readfile(cachefile, buf, sizeof(buf))!=-1){
        sscanf(buf, "%lu %lu", uptime, usage);
    }
}

canonical_original_code:
void readcache(char *cachefile, unsigned long *uptime, unsigned long *usage){
    char buf[1024];
    *uptime = *usage = 0;
    if(readfile(cachefile, buf, sizeof(buf))!=-1){
        sscanf(buf, "%lu %lu", uptime, usage);
    }
}

variable_types:
uptime
unsigned long *

variable_types:
usage
unsigned long *


memusage

decompiled_code:
__int64 __fastcall memusage(const char *a1)
{
__int64 v2; // [rsp+8h] [rbp-810h] BYREF
char s[1024]; // [rsp+10h] [rbp-808h] BYREF
char v4[1032]; // [rsp+410h] [rbp-408h] BYREF

snprintf(s, 0x400uLL, "%s/statm", a1);
memset(v4, 0, 0x400uLL);
readfile(s, v4, 1024LL);
_isoc99_sscanf(v4, "%ld %*ld %*ld %*ld %*ld %*ld %*ld", &v2);
return v2 * getpagesize();
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
__int64 v2; // [rsp+8h] [rbp-810h] BYREF
char s[1024]; // [rsp+10h] [rbp-808h] BYREF
char v4[1032]; // [rsp+410h] [rbp-408h] BYREF

snprintf(s, 0x400uLL, "%s/statm", a1);
memset(v4, 0, 0x400uLL);
readfile(s, v4, 1024LL);
_isoc99_sscanf(v4, "%ld %*ld %*ld %*ld %*ld %*ld %*ld", &v2);
return v2 * getpagesize();
}

original_code:
unsigned long int memusage(const char *pidpath){
    char procpidstatm[1024];
    char buf[1024];
    int i;
    unsigned long int vsz;
    snprintf(procpidstatm, sizeof(procpidstatm), "%s/statm", pidpath);
    bzero(buf, sizeof(buf));
    i = readfile(procpidstatm, buf, sizeof(buf));
    sscanf(buf, "%ld %*ld %*ld %*ld %*ld %*ld %*ld", &vsz);
    return getpagesize()*vsz;
}

canonical_original_code:
unsigned long memusage(char *pidpath){
    char procpidstatm[1024];
    char buf[1024];
    int i;
    unsigned long vsz;
    snprintf(procpidstatm, sizeof(procpidstatm), "%s/statm", pidpath);
    bzero(buf, sizeof(buf));
    i = readfile(procpidstatm, buf, sizeof(buf));
    sscanf(buf, "%ld %*ld %*ld %*ld %*ld %*ld %*ld", &vsz);
    return getpagesize()*vsz;
}

variable_types:
pidpath
char *

variable_types:
procpidstatm
char [1024]

variable_types:
vsz
unsigned long


usage

decompiled_code:
size_t __fastcall usage(const char *a1)
{
fprintf(stderr, "Usage: %s [-O | --owner=username] [-T | --tag=tag] [-V | --target=tagname]\n", a1);
fwrite(" [-W | --warning=integer] [-C | --critical=integer]\n", 1uLL, 0x3DuLL, stderr);
return fwrite(" [-P | --cmdline=path] [-H | --help]\n", 1uLL, 0x2EuLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
fprintf(stderr, "Usage: %s [-O | --owner=username] [-T | --tag=tag] [-V | --target=tagname]\n", a1);
fwrite(" [-W | --warning=integer] [-C | --critical=integer]\n", 1uLL, 0x3DuLL, stderr);
return fwrite(" [-P | --cmdline=path] [-H | --help]\n", 1uLL, 0x2EuLL, stderr);
}

original_code:
void usage(const char *name){
    fprintf(stderr, "Usage: %s [-O | --owner=username] [-T | --tag=tag] [-V | --target=tagname]\n", name);
    fprintf(stderr, "          [-W | --warning=integer] [-C | --critical=integer]\n");
    fprintf(stderr, "          [-P | --cmdline=path] [-H | --help]\n");
}

canonical_original_code:
void usage(char *name){
    fprintf(stderr, "Usage: %s [-O | --owner=username] [-T | --tag=tag] [-V | --target=tagname]\n", name);
    fprintf(stderr, "          [-W | --warning=integer] [-C | --critical=integer]\n");
    fprintf(stderr, "          [-P | --cmdline=path] [-H | --help]\n");
}

variable_types:
name
char *


printmessage

decompiled_code:
int __fastcall printmessage(const char *a1, const char *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rcx
const char *v4; // r8

v3 = a3;
v4 = "b";
if ( a3 > 0x400 )
{
if ( a3 <= 0x1003FF )
{
v3 = a3 >> 10;
v4 = "K";
}
else
{
v3 = a3 >> 20;
v4 = "M";
}
}
return printf("%s memory %s: %lu %s\n", a1, a2, v3, v4);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, const char *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rcx
const char *v4; // r8

v3 = a3;
v4 = "b";
if ( a3 > 0x400 )
{
if ( a3 <= 0x1003FF )
{
v3 = a3 >> 10;
v4 = "K";
}
else
{
v3 = a3 >> 20;
v4 = "M";
}
}
return printf("%s memory %s: %lu %s\n", a1, a2, v3, v4);
}

original_code:
void printmessage(const char *name, const char *stat, unsigned long int u){
    int i = 0;
    char *units[] = {"b", "K", "M"};
    while((i < 2) && (u > 1024)){
        u /= 1024;
        i++;
    }
    printf("%s memory %s: %lu %s\n", name, stat, u, units[i]);
}

canonical_original_code:
void printmessage(char *name, char *stat, unsigned long u){
    int i = 0;
    char *units[] = {"b", "K", "M"};
    while((i < 2) && (u > 1024)){
        u /= 1024;
        i++;
    }
    printf("%s memory %s: %lu %s\n", name, stat, u, units[i]);
}

variable_types:
stat
char *

variable_types:
u
unsigned long

variable_types:
units
char *[]


printusage

decompiled_code:
size_t __fastcall printusage(const char *a1)
{
fprintf(stderr, "Usage: %s [-O | --owner=username] [-T | --tag=tag] [-V | --target=tagname]\n", a1);
fwrite(" [-W | --warning=percentage] [-C | --critical=percentage]\n", 1uLL, 0x3AuLL, stderr);
return fwrite(" [-S | --cache=dir] [-P | --cmdline=path] [-H | --help]\n", 1uLL, 0x38uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
fprintf(stderr, "Usage: %s [-O | --owner=username] [-T | --tag=tag] [-V | --target=tagname]\n", a1);
fwrite(" [-W | --warning=percentage] [-C | --critical=percentage]\n", 1uLL, 0x3AuLL, stderr);
return fwrite(" [-S | --cache=dir] [-P | --cmdline=path] [-H | --help]\n", 1uLL, 0x38uLL, stderr);
}

original_code:
void printusage(const char *name){
    fprintf(stderr, "Usage: %s [-O | --owner=username] [-T | --tag=tag] [-V | --target=tagname]\n", name);
    fprintf(stderr, " [-W | --warning=percentage] [-C | --critical=percentage]\n");
    fprintf(stderr, " [-S | --cache=dir] [-P | --cmdline=path] [-H | --help]\n");
}

canonical_original_code:
void printusage(char *name){
    fprintf(stderr, "Usage: %s [-O | --owner=username] [-T | --tag=tag] [-V | --target=tagname]\n", name);
    fprintf(stderr, " [-W | --warning=percentage] [-C | --critical=percentage]\n");
    fprintf(stderr, " [-S | --cache=dir] [-P | --cmdline=path] [-H | --help]\n");
}


printmessage

decompiled_code:
int __fastcall printmessage(const char *a1, const char *a2, unsigned int a3)
{
return printf("%s cpu %s: %d\n", a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, const char *a2, unsigned int a3)
{
return printf("%s cpu %s: %d\n", a1, a2, a3);
}

original_code:
void printmessage(const char *name, const char *stat, int u){
    printf("%s cpu %s: %d\n", name, stat, u);
}

canonical_original_code:
void printmessage(char *name, char *stat, int u){
    printf("%s cpu %s: %d\n", name, stat, u);
}

variable_types: u int


repo: j-burrows/prime-number-library

decompiled_code:
int __fastcall print_list_llu(_QWORD *a1)
{
return fprint_list_llu(stdout, a1);
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1)
{
return func0(stdout, a1);
}

original_code:
void print_list_llu(list_llu* current){
 fprint_list_llu(stdout, current);
}

canonical_original_code:
void print_list_llu(struct list_llu *current){
 fprint_list_llu(stdout, current);
}

variable_types: struct list_llu { struct node_llu { unsigned long long value; struct node_llu *next; } *head; struct node_llu *tail; } *

user_defined_types: struct list_llu { struct node_llu *head; struct node_llu *tail; }


decompiled_code:
void __fastcall free_list_llu(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void free_list_llu(list_llu* list_deleting){
 node_llu* conductor, *prev;
 for( conductor = list_deleting->head; conductor != ((void *)0);){
  prev = conductor;
  conductor = conductor->next;
  free(prev);
  prev = ((void *)0);
 }
 free(list_deleting);
 list_deleting = ((void *)0);
}

canonical_original_code:
void free_list_llu(struct list_llu *list_deleting){
 struct node_llu *conductor; struct node_llu *prev;
 for( conductor = list_deleting->head; conductor != ((void *)0);){
  prev = conductor;
  conductor = conductor->next;
  free(prev);
  prev = ((void *)0);
 }
 free(list_deleting);
 list_deleting = ((void *)0);
}

variable_types: struct node_llu { unsigned long long value; struct node_llu *next; } *


decompiled_code:
__int64 __fastcall add_node_llu(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = init_node_llu(a2);
if ( !v2 )
return 0LL;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = v2;
*(_QWORD *)(a1 + 8) = v2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = init_node_llu(a2);
if ( !v2 )
return 0LL;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = v2;
*(_QWORD *)(a1 + 8) = v2;
return 1LL;
}

original_code:
int add_node_llu(list_llu* current, unsigned long long value_adding){
 node_llu* node_adding;
 if( (node_adding = init_node_llu(value_adding)) == ((void *)0)){
  return 0;
 }
 current->tail->next = node_adding;
 current->tail = node_adding;
 return 1;
}

canonical_original_code:
int add_node_llu(struct list_llu *current, unsigned long long value_adding){
 struct node_llu *node_adding;
 if( (node_adding = init_node_llu(value_adding)) == ((void *)0)){
  return 0;
 }
 current->tail->next = node_adding;
 current->tail = node_adding;
 return 1;
}

user_defined_types: struct node_llu { unsigned long long value; struct node_llu *next; }


decompiled_code:
__int64 __fastcall is_prime(_QWORD **a1, unsigned __int64 a2)
{
double v2; // xmm0_8
_QWORD *v3; // rdi
int v4; // er8
__int64 result; // rax
int v6; // er8
_QWORD *v7; // rdi

if ( (a2 & 0x8000000000000000LL) != 0LL )
v2 = (double)(int)(a2 & 1 | (a2 >> 1)) + (double)(int)(a2 & 1 | (a2 >> 1));
else
v2 = (double)(int)a2;
if ( v2 < 0.0 )
{
v6 = (int)sqrt(v2);
v7 = *a1;
if ( v7 )
{
while ( *v7 <= (unsigned __int64)v6 )
{
if ( !(a2 % *v7) )
return 0LL;
v7 = (_QWORD *)v7[1];
if ( !v7 )
break;
}
}
result = 1LL;
}
else
{
v3 = *a1;
v4 = (int)sqrt(v2);
if ( v3 )
{
while ( *v3 <= (unsigned __int64)v4 )
{
if ( !(a2 % *v3) )
return 0LL;
v3 = (_QWORD *)v3[1];
if ( !v3 )
break;
}
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD **a1, unsigned __int64 a2)
{
double v2; // xmm0_8
_QWORD *v3; // rdi
int v4; // er8
__int64 result; // rax
int v6; // er8
_QWORD *v7; // rdi

if ( (a2 & 0x8000000000000000LL) != 0LL )
v2 = (double)(int)(a2 & 1 | (a2 >> 1)) + (double)(int)(a2 & 1 | (a2 >> 1));
else
v2 = (double)(int)a2;
if ( v2 < 0.0 )
{
v6 = (int)sqrt(v2);
v7 = *a1;
if ( v7 )
{
while ( *v7 <= (unsigned __int64)v6 )
{
if ( !(a2 % *v7) )
return 0LL;
v7 = (_QWORD *)v7[1];
if ( !v7 )
break;
}
}
result = 1LL;
}
else
{
v3 = *a1;
v4 = (int)sqrt(v2);
if ( v3 )
{
while ( *v3 <= (unsigned __int64)v4 )
{
if ( !(a2 % *v3) )
return 0LL;
v3 = (_QWORD *)v3[1];
if ( !v3 )
break;
}
}
result = 1LL;
}
return result;
}

original_code:
int is_prime(list_llu* primes, unsigned long long number){
 node_llu* conductor;
 int number_is_prime;
 int seeve;
 seeve = sqrt(number);
 number_is_prime = 1;
 for(conductor=primes->head; conductor!=((void *)0) && conductor->value <= seeve;
  conductor=conductor->next){
  if((number%(conductor->value))!=0){
   continue;
  }
  else{
   number_is_prime = 0;
   break;
  }
 }
 return number_is_prime;
}

canonical_original_code:
int is_prime(struct list_llu *primes, unsigned long long number){
 struct node_llu *conductor;
 int number_is_prime;
 int seeve;
 seeve = sqrt(number);
 number_is_prime = 1;
 for(conductor=primes->head; conductor!=((void *)0) && conductor->value <= seeve;
  conductor=conductor->next){
  if((number%(conductor->value))!=0){
   continue;
  }
  else{
   number_is_prime = 0;
   break;
  }
 }
 return number_is_prime;
}

variable_types:
number
unsigned long long

variable_types: seeve int


decompiled_code:
_BOOL8 __fastcall add_if_prime(_QWORD **a1, unsigned __int64 a2)
{
int v2; // er8
_BOOL8 result; // rax

v2 = is_prime(a1, a2);
result = 1LL;
if ( v2 )
result = (unsigned int)add_node_llu(a1, a2) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_QWORD **a1, unsigned __int64 a2)
{
int v2; // er8
_BOOL8 result; // rax

v2 = func0(a1, a2);
result = 1LL;
if ( v2 )
result = (unsigned int)add_node_llu(a1, a2) != 0;
return result;
}

original_code:
int add_if_prime(list_llu* primes, unsigned long long number){
 if(is_prime(primes,number)){
  if(add_node_llu(primes,number) == 0){
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
int add_if_prime(struct list_llu *primes, unsigned long long number){
 if(is_prime(primes,number)){
  if(add_node_llu(primes,number) == 0){
   return 0;
  }
 }
 return 1;
}


repo: j-mcnally/girara-osx

decompiled_code:
struct passwd *__fastcall girara_get_home_directory(char *name)
{
__int64 v1; // rax
__int64 v2; // rax
struct passwd *v3; // rax
int v4; // eax
size_t v5; // r12
char *v6; // r13
struct passwd *v7; // r12
struct passwd *result; // [rsp+8h] [rbp-50h] BYREF
struct passwd resultbuf; // [rsp+10h] [rbp-48h] BYREF

if ( name && (v1 = g_get_user_name(), (unsigned int)g_strcmp0(name, v1)) )
{
v4 = sysconf(70);
if ( v4 < 0 )
v4 = 4096;
v5 = v4;
v6 = (char *)g_malloc0(v4);
getpwnam_r(name, &resultbuf, v6, v5, &result);
v7 = result;
if ( result )
v7 = (struct passwd *)g_strdup(resultbuf.pw_dir);
g_free(v6);
v3 = v7;
}
else
{
v2 = g_get_home_dir();
v3 = (struct passwd *)g_strdup(v2);
}
return v3;
}

canonical_decompiled_code:
struct passwd *__fastcall func1(char *name)
{
__int64 v1; // rax
__int64 v2; // rax
struct passwd *v3; // rax
int v4; // eax
size_t v5; // r12
char *v6; // r13
struct passwd *v7; // r12
struct passwd *result; // [rsp+8h] [rbp-50h] BYREF
struct passwd resultbuf; // [rsp+10h] [rbp-48h] BYREF

if ( name && (v1 = g_get_user_name(), (unsigned int)g_strcmp0(name, v1)) )
{
v4 = sysconf(70);
if ( v4 < 0 )
v4 = 4096;
v5 = v4;
v6 = (char *)g_malloc0(v4);
getpwnam_r(name, &resultbuf, v6, v5, &result);
v7 = result;
if ( result )
v7 = (struct passwd *)g_strdup(resultbuf.pw_dir);
g_free(v6);
v3 = v7;
}
else
{
v2 = g_get_home_dir();
v3 = (struct passwd *)g_strdup(v2);
}
return v3;
}

original_code:
char*
girara_get_home_directory(const char* user)
{
  if (user == ((void *)0) || g_strcmp0(user, g_get_user_name()) == 0) {
    return g_strdup(g_get_home_dir());
  }
  struct passwd pwd;
  struct passwd* result;
  int bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
  if (bufsize < 0) {
    bufsize = 4096;
  }
  char* buffer = g_malloc0(sizeof(char) * bufsize);
  getpwnam_r(user, &pwd, buffer, bufsize, &result);
  if (result == ((void *)0)) {
    g_free(buffer);
    return ((void *)0);
  }
  char* dir = g_strdup(pwd.pw_dir);
  g_free(buffer);
  return dir;
}

canonical_original_code:
char *girara_get_home_directory(char *user)
{
  if (user == ((void *)0) || g_strcmp0(user, g_get_user_name()) == 0) {
    return g_strdup(g_get_home_dir());
  }
  struct passwd pwd;
  struct passwd *result;
  int bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
  if (bufsize < 0) {
    bufsize = 4096;
  }
  char *buffer = g_malloc0(sizeof(char) * bufsize);
  getpwnam_r(user, &pwd, buffer, bufsize, &result);
  if (result == ((void *)0)) {
    g_free(buffer);
    return ((void *)0);
  }
  char *dir = g_strdup(pwd.pw_dir);
  g_free(buffer);
  return dir;
}

variable_types:
user
char *

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

variable_types: bufsize int

variable_types:
buffer
char *

variable_types:
dir
char *


decompiled_code:
__int64 __fastcall girara_fix_path(__int64 a1)
{
__int64 v1; // rbp
char v2; // al
__int64 v3; // rdi
__int64 v4; // rbx
__int64 v5; // rsi
char v6; // al
char *v7; // r13
struct passwd *v9; // r12
__int64 v10; // r13

if ( !a1 )
return 0LL;
v1 = a1;
if ( *(_BYTE *)a1 != 126 )
return g_strdup(a1);
if ( strlen((const char *)a1) <= 1 || (v2 = *(_BYTE *)(a1 + 1), v2 == 47) )
{
v4 = 1LL;
v7 = 0LL;
}
else
{
v3 = a1 + 1;
if ( v2 )
{
v4 = 1LL;
do
{
v5 = v4++;
v6 = *(_BYTE *)(v1 + v4);
}
while ( v6 && v6 != 47 );
}
else
{
v5 = 0LL;
v4 = 1LL;
}
v7 = (char *)g_strndup(v3, v5);
}
v9 = girara_get_home_directory(v7);
g_free(v7);
a1 = v1;
if ( !v9 )
return g_strdup(a1);
v10 = g_build_filename(v9, v1 + v4, 0LL);
g_free(v9);
return v10;
}

original_code:
char*
girara_fix_path(const char* path)
{
  if (path == ((void *)0)) {
    return ((void *)0);
  }
  char* rpath = ((void *)0);
  if (path[0] == '~') {
    const size_t len = strlen(path);
    char* user = ((void *)0);
    size_t idx = 1;
    if (len > 1 && path[1] != '/') {
      while (path[idx] && path[idx] != '/') {
        ++idx;
      }
      user = g_strndup(path + 1, idx - 1);
    }
    char* home_path = girara_get_home_directory(user);
    g_free(user);
    if (home_path == ((void *)0)) {
      return g_strdup(path);
    }
    rpath = g_build_filename(home_path, path + idx, ((void *)0));
    g_free(home_path);
  } else {
    rpath = g_strdup(path);
  }
  return rpath;
}

canonical_original_code:
char *girara_fix_path(char *path)
{
  if (path == ((void *)0)) {
    return ((void *)0);
  }
  char *rpath = ((void *)0);
  if (path[0] == '~') {
    unsigned long len = strlen(path);
    char *user = ((void *)0);
    unsigned long idx = 1;
    if (len > 1 && path[1] != '/') {
      while (path[idx] && path[idx] != '/') {
        ++idx;
      }
      user = g_strndup(path + 1, idx - 1);
    }
    char *home_path = girara_get_home_directory(user);
    g_free(user);
    if (home_path == ((void *)0)) {
      return g_strdup(path);
    }
    rpath = g_build_filename(home_path, path + idx, ((void *)0));
    g_free(home_path);
  } else {
    rpath = g_strdup(path);
  }
  return rpath;
}

variable_types:
path
char *

variable_types:
rpath
char *

variable_types:
len
unsigned long

variable_types:
idx
unsigned long


decompiled_code:
__int64 __fastcall girara_get_xdg_path(unsigned int a1)
{
__int64 v1; // rax
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rax

if ( a1 == 1 )
{
v5 = g_get_user_data_dir();
result = g_strdup(v5);
}
else if ( a1 > 1 )
{
if ( a1 - 2 > 1 )
{
result = 0LL;
}
else
{
v3 = g_getenv(VARS_3[a1]);
v4 = v3;
if ( v3 && (unsigned int)g_strcmp0(v3, &LC0) )
result = g_strdup(v4);
else
result = g_strdup(DEFAULTS_2[a1]);
}
}
else
{
v1 = g_get_user_config_dir();
result = g_strdup(v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 v1; // rax
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rax

if ( a1 == 1 )
{
v5 = g_get_user_data_dir();
result = g_strdup(v5);
}
else if ( a1 > 1 )
{
if ( a1 - 2 > 1 )
{
result = 0LL;
}
else
{
v3 = g_getenv(VARS_3[a1]);
v4 = v3;
if ( v3 && (unsigned int)g_strcmp0(v3, &LC0) )
result = g_strdup(v4);
else
result = g_strdup(DEFAULTS_2[a1]);
}
}
else
{
v1 = g_get_user_config_dir();
result = g_strdup(v1);
}
return result;
}

original_code:
char*
girara_get_xdg_path(girara_xdg_path_t path)
{
  static const char* VARS[] = {
    "XDG_CONFIG_HOME",
    "XDG_DATA_HOME",
    "XDG_CONFIG_DIRS",
    "XDG_DATA_DIRS"
  };
  static const char* DEFAULTS[] = {
    "NOTUSED",
    "NOTUSED",
    "/etc/xdg",
    "/usr/local/share/:/usr/share",
  };
  switch (path) {
    case XDG_DATA:
      return g_strdup(g_get_user_data_dir());
    case XDG_CONFIG:
      return g_strdup(g_get_user_config_dir());
    case XDG_CONFIG_DIRS:
    case XDG_DATA_DIRS:
    {
      const char* tmp = g_getenv(VARS[path]);
      if (tmp == ((void *)0) || !g_strcmp0(tmp, "")) {
        return g_strdup(DEFAULTS[path]);
      }
      return g_strdup(tmp);
    }
  }
  return ((void *)0);
}

canonical_original_code:
char *girara_get_xdg_path(enum girara_xdg_path_t path)
{
  static char *VARS[] = {
    "XDG_CONFIG_HOME",
    "XDG_DATA_HOME",
    "XDG_CONFIG_DIRS",
    "XDG_DATA_DIRS"
  };
  static char *DEFAULTS[] = {
    "NOTUSED",
    "NOTUSED",
    "/etc/xdg",
    "/usr/local/share/:/usr/share",
  };
  switch (path) {
    case XDG_DATA:
      return g_strdup(g_get_user_data_dir());
    case XDG_CONFIG:
      return g_strdup(g_get_user_config_dir());
    case XDG_CONFIG_DIRS:
    case XDG_DATA_DIRS:
    {
      char *tmp = g_getenv(VARS[path]);
      if (tmp == ((void *)0) || !g_strcmp0(tmp, "")) {
        return g_strdup(DEFAULTS[path]);
      }
      return g_strdup(tmp);
    }
  }
  return ((void *)0);
}

variable_types: enum girara_xdg_path_t { XDG_CONFIG=0, XDG_DATA=1, XDG_CONFIG_DIRS=2, XDG_DATA_DIRS=3 }

variable_types:
VARS
char *[]

variable_types:
DEFAULTS
char *[]

variable_types:
tmp
char *


decompiled_code:
void __fastcall girara_clean_line(char *s)
{
int v1; // er14
unsigned int v2; // er12
__int64 v4; // rbx
char *v5; // r15
const unsigned __int16 **v6; // rax
__int64 v7; // rdi
size_t v8; // [rsp+0h] [rbp-48h]
char v9; // [rsp+Fh] [rbp-39h]

if ( s )
{
v1 = 0;
v2 = 0;
v4 = 0LL;
v9 = 1;
v8 = strlen(s);
while ( 1 )
{
v5 = &s[v4];
if ( v2 >= v8 )
break;
v6 = _ctype_b_loc();
v7 = s[v2];
if ( ((*v6)[v7] & 0x2000) != 0 )
{
if ( !v9 )
{
*v5 = 32;
v4 = (unsigned int)++v1;
v9 = 1;
v8 = strlen(s);
}
}
else
{
*v5 = v7;
v4 = (unsigned int)++v1;
v9 = 0;
v8 = strlen(s);
}
++v2;
}
*v5 = 0;
}
}

original_code:
void
girara_clean_line(char* line)
{
  if (line == ((void *)0)) {
    return;
  }
  unsigned int i = 0;
  unsigned int j = 0;
  _Bool ws_mode = 1;
  for(i = 0; i < strlen(line); i++) {
    if (((*__ctype_b_loc ())[(int) ((line[i]))] & (unsigned short int) _ISspace) != 0) {
      if (ws_mode) {
        continue;
      }
      line[j++] = ' ';
      ws_mode = 1;
    } else {
      line[j++] = line[i];
      ws_mode = 0;
    }
  }
  line[j] = '\0';
}

canonical_original_code:
void girara_clean_line(char *line)
{
  if (line == ((void *)0)) {
    return;
  }
  unsigned int i = 0;
  unsigned int j = 0;
  _Bool ws_mode = 1;
  for(i = 0; i < strlen(line); i++) {
    if (((*__ctype_b_loc ())[(int) ((line[i]))] & (unsigned short) _ISspace) != 0) {
      if (ws_mode) {
        continue;
      }
      line[j++] = ' ';
      ws_mode = 1;
    } else {
      line[j++] = line[i];
      ws_mode = 0;
    }
  }
  line[j] = '\0';
}

variable_types:
line
char *

variable_types:
i
unsigned int

variable_types:
j
unsigned int


decompiled_code:
void *__fastcall girara_safe_realloc(void **a1, size_t a2)
{
void *result; // rax

if ( !a1 )
return 0LL;
if ( a2 && (result = realloc(*a1, a2)) != 0LL )
{
*a1 = result;
}
else
{
free(*a1);
*a1 = 0LL;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(void **a1, size_t a2)
{
void *result; // rax

if ( !a1 )
return 0LL;
if ( a2 && (result = realloc(*a1, a2)) != 0LL )
{
*a1 = result;
}
else
{
free(*a1);
*a1 = 0LL;
result = 0LL;
}
return result;
}

original_code:
void*
girara_safe_realloc(void** ptr, size_t size)
{
  if(ptr == ((void *)0)) {
    return ((void *)0);
  }
  if (size == 0) {
    goto error_free;
  }
  void* tmp = realloc(*ptr, size);
  if(tmp == ((void *)0)) {
    goto error_free;
  }
  *ptr = tmp;
  return *ptr;
error_free:
  free(*ptr);
  *ptr = ((void *)0);
  return ((void *)0);
}

canonical_original_code:
void *girara_safe_realloc(void **ptr, unsigned long size)
{
  if(ptr == ((void *)0)) {
    return ((void *)0);
  }
  if (size == 0) {
    goto error_free;
  }
  void *tmp = realloc(*ptr, size);
  if(tmp == ((void *)0)) {
    goto error_free;
  }
  *ptr = tmp;
  return *ptr;
error_free:
  free(*ptr);
  *ptr = ((void *)0);
  return ((void *)0);
}

variable_types:
ptr
void **

variable_types:
size
unsigned long

variable_types:
tmp
void *


decompiled_code:
__int64 __fastcall girara_xdg_open(_BYTE *a1)
{
unsigned int v1; // er13
__int64 *v3; // r12
__int64 v4; // rbp
__int64 v5; // rdi
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !a1 )
return 0LL;
v1 = 0;
if ( !*a1 )
return 0LL;
v3 = (__int64 *)g_string_new("xdg-open ");
v4 = g_shell_quote(a1);
g_string_append(v3, v4);
g_free(v4);
v5 = *v3;
v6[0] = 0LL;
LOBYTE(v1) = (unsigned int)g_spawn_command_line_async(v5, v6) != 0;
if ( v6[0] )
{
girara_debug("girara_xdg_open", 0x55u, 2u, "Failed to execute command: %s", *(const char **)(v6[0] + 8));
g_error_free(v6[0]);
}
g_string_free(v3, 1LL);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1)
{
unsigned int v1; // er13
__int64 *v3; // r12
__int64 v4; // rbp
__int64 v5; // rdi
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !a1 )
return 0LL;
v1 = 0;
if ( !*a1 )
return 0LL;
v3 = (__int64 *)g_string_new("xdg-open ");
v4 = g_shell_quote(a1);
g_string_append(v3, v4);
g_free(v4);
v5 = *v3;
v6[0] = 0LL;
LOBYTE(v1) = (unsigned int)g_spawn_command_line_async(v5, v6) != 0;
if ( v6[0] )
{
func8("girara_xdg_open", 0x55u, 2u, "Failed to execute command: %s", *(const char **)(v6[0] + 8));
g_error_free(v6[0]);
}
g_string_free(v3, 1LL);
return v1;
}

original_code:
_Bool
girara_xdg_open(const char* uri)
{
  if (uri == ((void *)0) || strlen(uri) == 0) {
    return 0;
  }
  GString* command = g_string_new("xdg-open ");
  char* tmp = g_shell_quote(uri);
  g_string_append(command, tmp);
  g_free(tmp);
  GError* error = ((void *)0);
  _Bool res = g_spawn_command_line_async(command->str, &error);
  if (error != ((void *)0)) {
    _girara_debug(__FUNCTION__, 85, GIRARA_WARNING, "Failed to execute command: %s", error->message);
    g_error_free(error);
  }
  g_string_free(command, (!(0)));
  return res;
}

canonical_original_code:
_Bool girara_xdg_open(char *uri)
{
  if (uri == ((void *)0) || strlen(uri) == 0) {
    return 0;
  }
  struct _GString *command = g_string_new("xdg-open ");
  char *tmp = g_shell_quote(uri);
  g_string_append(command, tmp);
  g_free(tmp);
  struct _GError *error = ((void *)0);
  _Bool res = g_spawn_command_line_async(command->str, &error);
  if (error != ((void *)0)) {
    _girara_debug(__FUNCTION__, 85, GIRARA_WARNING, "Failed to execute command: %s", error->message);
    g_error_free(error);
  }
  g_string_free(command, (!(0)));
  return res;
}

variable_types:
uri
char *

variable_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; } *

variable_types: struct _GError { unsigned int domain; int code; char *message; } *


decompiled_code:
__int64 girara_get_debug_level()
{
return (unsigned int)debug_level;
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned int)debug_level;
}

original_code:
girara_debug_level_t
girara_get_debug_level()
{
  return debug_level;
}

canonical_original_code:
enum girara_debug_level_e girara_get_debug_level()
{
  return debug_level;
}

return_type: enum girara_debug_level_e { GIRARA_DEBUG=0, GIRARA_INFO=1, GIRARA_WARNING=2, GIRARA_ERROR=3 }


decompiled_code:
void __fastcall girara_set_debug_level(int a1)
{
debug_level = a1;
}

canonical_decompiled_code:
void __fastcall func11(int a1)
{
debug_level = a1;
}

original_code:
void
girara_set_debug_level(girara_debug_level_t level)
{
  debug_level = level;
}

canonical_original_code:
void girara_set_debug_level(enum girara_debug_level_e level)
{
  debug_level = level;
}

variable_types: enum girara_debug_level_e { GIRARA_DEBUG=0, GIRARA_INFO=1, GIRARA_WARNING=2, GIRARA_ERROR=3 }


decompiled_code:
__int64 __fastcall girara_escape_string(char *a1)
{
char *v1; // rbx
__int64 *v2; // r12
char i; // al
char v4; // bp

if ( !a1 )
return 0LL;
v1 = a1;
v2 = (__int64 *)g_string_new(&LC0);
for ( i = *a1; *v1; i = *v1 )
{
v4 = i;
++v1;
if ( strchr("\\ \t\"'", i) )
g_string_append_c_inline_isra_0(v2, 92);
g_string_append_c_inline_isra_0(v2, v4);
}
return g_string_free(v2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1)
{
char *v1; // rbx
__int64 *v2; // r12
char i; // al
char v4; // bp

if ( !a1 )
return 0LL;
v1 = a1;
v2 = (__int64 *)g_string_new(&LC0);
for ( i = *a1; *v1; i = *v1 )
{
v4 = i;
++v1;
if ( strchr("\\ \t\"'", i) )
func0(v2, 92);
func0(v2, v4);
}
return g_string_free(v2, 0LL);
}

original_code:
char* girara_escape_string(const char* value)
{
  if (value == ((void *)0)) {
    return ((void *)0);
  }
  GString* str = g_string_new("");
  while (*value != '\0') {
    const char c = *value++;
    if (strchr("\\ \t\"\'", c) != ((void *)0)) {
      g_string_append_c_inline (str, '\\');
    }
    g_string_append_c_inline (str, c);
  }
  return g_string_free(str, (0));
}

canonical_original_code:
char *girara_escape_string(char *value)
{
  if (value == ((void *)0)) {
    return ((void *)0);
  }
  struct _GString *str = g_string_new("");
  while (*value != '\0') {
    char c = *value++;
    if (strchr("\\ \t\"\'", c) != ((void *)0)) {
      g_string_append_c_inline (str, '\\');
    }
    g_string_append_c_inline (str, c);
  }
  return g_string_free(str, (0));
}

variable_types:
value
char *

variable_types: c char

user_defined_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; }


decompiled_code:
__int64 girara_input_history_get_type_once()
{
__int64 v0; // rax

v0 = g_intern_static_string("GiraraInputHistory");
return g_type_register_static_simple(
80LL,
v0,
208LL,
girara_input_history_class_intern_init,
24LL,
girara_input_history_init,
0LL);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax

v0 = g_intern_static_string("GiraraInputHistory");
return g_type_register_static_simple(
80LL,
v0,
208LL,
girara_input_history_class_intern_init,
24LL,
girara_input_history_init,
0LL);
}

original_code: __attribute__((noinline)) static GType girara_input_history_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple (((GType) ((20) << (2))), g_intern_static_string ("GiraraInputHistory"), sizeof (GiraraInputHistoryClass), (GClassInitFunc)(void (*)(void)) girara_input_history_class_intern_init, sizeof (GiraraInputHistory), (GInstanceInitFunc)(void (*)(void)) girara_input_history_init, (GTypeFlags) 0); { {{};} } return g_define_type_id; }

canonical_original_code: static unsigned long girara_input_history_get_type_once() { unsigned long g_define_type_id = g_type_register_static_simple (((GType) ((20) << (2))), g_intern_static_string ("GiraraInputHistory"), sizeof (GiraraInputHistoryClass), (GClassInitFunc)(void (*)(void)) girara_input_history_class_intern_init, sizeof (GiraraInputHistory), (GInstanceInitFunc)(void (*)(void)) girara_input_history_init, (GTypeFlags) 0); { {{};} } return g_define_type_id; }


decompiled_code:
__int64 girara_input_history_get_type()
{
__int64 v1; // rax

if ( g_define_type_id__volatile_5 )
return g_define_type_id__volatile_5;
if ( (unsigned int)g_once_init_enter(&g_define_type_id__volatile_5) )
{
v1 = girara_input_history_get_type_once();
g_once_init_leave(&g_define_type_id__volatile_5, v1);
}
return g_define_type_id__volatile_5;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v1; // rax

if ( g_define_type_id__volatile_5 )
return g_define_type_id__volatile_5;
if ( (unsigned int)g_once_init_enter(&g_define_type_id__volatile_5) )
{
v1 = func0();
g_once_init_leave(&g_define_type_id__volatile_5, v1);
}
return g_define_type_id__volatile_5;
}

original_code: GType girara_input_history_get_type (void) { static volatile gsize g_define_type_id__volatile = 0; if ((__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_1[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? (gpointer) *(&g_define_type_id__volatile) : 0); (!(__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_2[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); guint64 gapg_temp = __atomic_load_8 ((&g_define_type_id__volatile), 5); (gpointer) gapg_temp; })) && g_once_init_enter (&g_define_type_id__volatile)); }))) { GType g_define_type_id = girara_input_history_get_type_once (); (__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_3[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? *(&g_define_type_id__volatile) = (g_define_type_id) : 0); g_once_init_leave ((&g_define_type_id__volatile), (gsize) (g_define_type_id)); })); } return g_define_type_id__volatile; }

canonical_original_code: unsigned long girara_input_history_get_type() { static unsigned long g_define_type_id__volatile = 0; if ((__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_1[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? (gpointer) *(&g_define_type_id__volatile) : 0); (!(__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_2[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); unsigned long gapg_temp = __atomic_load_8 ((&g_define_type_id__volatile), 5); (void *) gapg_temp; })) && g_once_init_enter (&g_define_type_id__volatile)); }))) { unsigned long g_define_type_id = girara_input_history_get_type_once (); (__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_3[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? *(&g_define_type_id__volatile) = (g_define_type_id) : 0); g_once_init_leave ((&g_define_type_id__volatile), (gsize) (g_define_type_id)); })); } return g_define_type_id__volatile; }


decompiled_code:
__int64 girara_input_history_io_get_type()
{
__int64 v1; // rax
__int64 v2; // rbp

if ( g_define_type_id__volatile_2 )
return g_define_type_id__volatile_2;
if ( (unsigned int)g_once_init_enter(&g_define_type_id__volatile_2) )
{
v1 = g_intern_static_string("GiraraInputHistoryIO");
v2 = g_type_register_static_simple(8LL, v1, 64LL, girara_input_history_io_default_init, 0LL, 0LL, 0LL);
g_type_interface_add_prerequisite(v2, 80LL);
g_once_init_leave(&g_define_type_id__volatile_2, v2);
}
return g_define_type_id__volatile_2;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v1; // rax
__int64 v2; // rbp

if ( g_define_type_id__volatile_2 )
return g_define_type_id__volatile_2;
if ( (unsigned int)g_once_init_enter(&g_define_type_id__volatile_2) )
{
v1 = g_intern_static_string("GiraraInputHistoryIO");
v2 = g_type_register_static_simple(8LL, v1, 64LL, girara_input_history_io_default_init, 0LL, 0LL, 0LL);
g_type_interface_add_prerequisite(v2, 80LL);
g_once_init_leave(&g_define_type_id__volatile_2, v2);
}
return g_define_type_id__volatile_2;
}

original_code: GType girara_input_history_io_get_type (void) { static volatile gsize g_define_type_id__volatile = 0; if ((__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_1[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? (gpointer) *(&g_define_type_id__volatile) : 0); (!(__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_2[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); guint64 gapg_temp = __atomic_load_8 ((&g_define_type_id__volatile), 5); (gpointer) gapg_temp; })) && g_once_init_enter (&g_define_type_id__volatile)); }))) { GType g_define_type_id = g_type_register_static_simple (((GType) ((2) << (2))), g_intern_static_string ("GiraraInputHistoryIO"), sizeof (GiraraInputHistoryIOInterface), (GClassInitFunc)(void (*)(void)) girara_input_history_io_default_init, 0, (GInstanceInitFunc)((void *)0), (GTypeFlags) 0); if (((GType) ((20) << (2))) != ((GType) ((0) << (2)))) g_type_interface_add_prerequisite (g_define_type_id, ((GType) ((20) << (2)))); { {;;} } (__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_3[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? *(&g_define_type_id__volatile) = (g_define_type_id) : 0); g_once_init_leave ((&g_define_type_id__volatile), (gsize) (g_define_type_id)); })); } return g_define_type_id__volatile; }

canonical_original_code: unsigned long girara_input_history_io_get_type() { static unsigned long g_define_type_id__volatile = 0; if ((__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_1[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? (gpointer) *(&g_define_type_id__volatile) : 0); (!(__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_2[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); unsigned long gapg_temp = __atomic_load_8 ((&g_define_type_id__volatile), 5); (void *) gapg_temp; })) && g_once_init_enter (&g_define_type_id__volatile)); }))) { unsigned long g_define_type_id = g_type_register_static_simple (((GType) ((2) << (2))), g_intern_static_string ("GiraraInputHistoryIO"), sizeof (GiraraInputHistoryIOInterface), (GClassInitFunc)(void (*)(void)) girara_input_history_io_default_init, 0, (GInstanceInitFunc)((void *)0), (GTypeFlags) 0); if (((GType) ((20) << (2))) != ((GType) ((0) << (2)))) g_type_interface_add_prerequisite (g_define_type_id, ((GType) ((20) << (2)))); { {;;} } (__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_3[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? *(&g_define_type_id__volatile) = (g_define_type_id) : 0); g_once_init_leave ((&g_define_type_id__volatile), (gsize) (g_define_type_id)); })); } return g_define_type_id__volatile; }


setup

decompiled_code:
__int64 setup()
{
return gtk_init(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func0()
{
return gtk_init(0LL, 0LL);
}

original_code:
void setup(void)
{
  gtk_init(((void *)0), ((void *)0));
}

canonical_original_code:
void setup()
{
  gtk_init(((void *)0), ((void *)0));
}