original_code:
void sbt_dumpln( const unsigned char* buf, int start_index, int end_index ){
 int i = 0;
    int dump_size = 0;
 unsigned char* dump_buf = ((void *)0);
 dump_size = end_index - start_index + 1;
 if( 0!=dump_size%16 ){
  dump_size+= 16 - dump_size%16;
 }
 dump_buf = (unsigned char*)malloc( dump_size );
 memset( dump_buf, 0x00, dump_size );
 memcpy( dump_buf, buf+start_index, end_index - start_index + 1 );
 fprintf(stderr, "        |+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F\n");
 for(i=0; i+16<=dump_size; i+=16){
  fprintf(stderr, "%08x|%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
    i,
    dump_buf[i+ 0],
    dump_buf[i+ 1],
    dump_buf[i+ 2],
    dump_buf[i+ 3],
    dump_buf[i+ 4],
    dump_buf[i+ 5],
    dump_buf[i+ 6],
    dump_buf[i+ 7],
    dump_buf[i+ 8],
    dump_buf[i+ 9],
    dump_buf[i+10],
    dump_buf[i+11],
    dump_buf[i+12],
    dump_buf[i+13],
    dump_buf[i+14],
    dump_buf[i+15]
  );
 }
 free(dump_buf);
}

canonical_original_code:
void sbt_dumpln(unsigned char *buf, int start_index, int end_index){
 int i = 0;
    int dump_size = 0;
 unsigned char *dump_buf = ((void *)0);
 dump_size = end_index - start_index + 1;
 if( 0!=dump_size%16 ){
  dump_size+= 16 - dump_size%16;
 }
 dump_buf = (unsigned char *)malloc( dump_size );
 memset( dump_buf, 0x00, dump_size );
 memcpy( dump_buf, buf+start_index, end_index - start_index + 1 );
 fprintf(stderr, "        |+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F\n");
 for(i=0; i+16<=dump_size; i+=16){
  fprintf(stderr, "%08x|%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
    i,
    dump_buf[i+ 0],
    dump_buf[i+ 1],
    dump_buf[i+ 2],
    dump_buf[i+ 3],
    dump_buf[i+ 4],
    dump_buf[i+ 5],
    dump_buf[i+ 6],
    dump_buf[i+ 7],
    dump_buf[i+ 8],
    dump_buf[i+ 9],
    dump_buf[i+10],
    dump_buf[i+11],
    dump_buf[i+12],
    dump_buf[i+13],
    dump_buf[i+14],
    dump_buf[i+15]
  );
 }
 free(dump_buf);
}

variable_types:
buf
unsigned char *

variable_types: i int


repo: seabat/TohriSDK

decompiled_code:
int __fastcall sbt_dump(__int64 a1, unsigned int a2, int a3)
{
unsigned int v3; // er13
int v4; // er14
__int64 v5; // rbx
int v6; // ebp
int v7; // er12
__int64 v8; // r15
__int64 v9; // rdx
int result; // eax

v3 = a2;
v4 = a3 + 1 - a2;
fwrite(" |+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F\n", 1uLL, 0x39uLL, stderr);
v5 = (int)a2 + a1;
do
{
if ( (int)(v3 + 15) >= a3 )
{
v7 = v4;
v6 = a3 - v3;
fprintf(stderr, "%08x|", v3);
if ( v4 <= 0 )
goto LABEL_8;
}
else
{
v6 = 15;
fprintf(stderr, "%08x|", v3);
v7 = 16;
}
v8 = 0LL;
do
{
while ( 1 )
{
v9 = *(unsigned __int8 *)(v5 + v8);
if ( v6 == (_DWORD)v8 )
break;
++v8;
fprintf(stderr, "%02x ", v9);
if ( v7 <= (int)v8 )
goto LABEL_8;
}
++v8;
fprintf(stderr, "%02x", v9);
}
while ( v7 > (int)v8 );
LABEL_8:
v3 += 16;
v5 += 16LL;
v4 -= 16;
result = fputc(10, stderr);
}
while ( a3 >= (int)v3 );
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, unsigned int a2, int a3)
{
unsigned int v3; // er13
int v4; // er14
__int64 v5; // rbx
int v6; // ebp
int v7; // er12
__int64 v8; // r15
__int64 v9; // rdx
int result; // eax

v3 = a2;
v4 = a3 + 1 - a2;
fwrite(" |+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F\n", 1uLL, 0x39uLL, stderr);
v5 = (int)a2 + a1;
do
{
if ( (int)(v3 + 15) >= a3 )
{
v7 = v4;
v6 = a3 - v3;
fprintf(stderr, "%08x|", v3);
if ( v4 <= 0 )
goto LABEL_8;
}
else
{
v6 = 15;
fprintf(stderr, "%08x|", v3);
v7 = 16;
}
v8 = 0LL;
do
{
while ( 1 )
{
v9 = *(unsigned __int8 *)(v5 + v8);
if ( v6 == (_DWORD)v8 )
break;
++v8;
fprintf(stderr, "%02x ", v9);
if ( v7 <= (int)v8 )
goto LABEL_8;
}
++v8;
fprintf(stderr, "%02x", v9);
}
while ( v7 > (int)v8 );
LABEL_8:
v3 += 16;
v5 += 16LL;
v4 -= 16;
result = fputc(10, stderr);
}
while ( a3 >= (int)v3 );
return result;
}

original_code:
void sbt_dump( const unsigned char* buf, int start_index, int end_index ){
 int cur_index = start_index;
 int dump_num = 0;
 int i = 0;
 fprintf(stderr, "        |+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F\n");
 do{
  if( (end_index+1)<=cur_index+16 ){
   dump_num = end_index-cur_index+1;
  }else{
   dump_num = 16;
  }
  fprintf(stderr,"%08x|", cur_index);
  for(i=0; i<dump_num; i++){
   if(i==dump_num-1){
    fprintf(stderr, "%02x", buf[cur_index+i]);
   }else{
    fprintf(stderr, "%02x ", buf[cur_index+i]);
   }
  }
  fprintf(stderr, "\n");
  cur_index += 16;
 }while( cur_index<=end_index );
}

canonical_original_code:
void sbt_dump(unsigned char *buf, int start_index, int end_index){
 int cur_index = start_index;
 int dump_num = 0;
 int i = 0;
 fprintf(stderr, "        |+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F\n");
 do{
  if( (end_index+1)<=cur_index+16 ){
   dump_num = end_index-cur_index+1;
  }else{
   dump_num = 16;
  }
  fprintf(stderr,"%08x|", cur_index);
  for(i=0; i<dump_num; i++){
   if(i==dump_num-1){
    fprintf(stderr, "%02x", buf[cur_index+i]);
   }else{
    fprintf(stderr, "%02x ", buf[cur_index+i]);
   }
  }
  fprintf(stderr, "\n");
  cur_index += 16;
 }while( cur_index<=end_index );
}

return_type: void


decompiled_code:
void sbt_test_log()
{
unsigned int v0; // eax
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
__int64 v10; // [rsp+0h] [rbp-58h]
__int64 v11; // [rsp+0h] [rbp-58h]
__int64 v12; // [rsp+0h] [rbp-58h]
char v13[5]; // [rsp+1Bh] [rbp-3Dh] BYREF
_OWORD v14[2]; // [rsp+20h] [rbp-38h] BYREF
int v15[6]; // [rsp+40h] [rbp-18h] BYREF

strcpy(v13, "test");
v14[0] = _mm_load_si128((const __m128i *)&LC21);
v14[1] = _mm_load_si128((const __m128i *)&LC22);
qmemcpy(v15, " !\"#$%", 6);
v0 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_log.c", "sbt_test_log", 0xABu, v0, "DEBUG %d", 3LL);
v1 = getpid();
sbt_logln_tofd(stderr, "I", "src/sbt_log.c", "sbt_test_log", 0xAEu, v1, "INFO %d", 3LL);
v2 = getpid();
sbt_logln_tofd(stderr, "W", "src/sbt_log.c", "sbt_test_log", 0xB1u, v2, "WARNING %d", 3LL);
v3 = getpid();
sbt_logln_tofd(stderr, "E", "src/sbt_log.c", "sbt_test_log", 0xB4u, v3, "ERROR %d", 3LL);
v4 = getpid();
sbt_flogln("D", (__int64)"src/sbt_log.c", "sbt_test_log", 0xB7u, v4, "DEBUG %d", 3LL);
v5 = getpid();
LODWORD(v10) = 3;
sbt_flogln("I", (__int64)"src/sbt_log.c", "sbt_test_log", 0xBAu, v5, "INFO %d", v10);
v6 = getpid();
LODWORD(v11) = 3;
sbt_flogln("W", (__int64)"src/sbt_log.c", "sbt_test_log", 0xBDu, v6, "WARNING %d", v11);
v7 = getpid();
LODWORD(v12) = 3;
sbt_flogln("E", (__int64)"src/sbt_log.c", "sbt_test_log", 0xC0u, v7, "ERROR %d", v12);
sbt_flog_init(0LL);
v8 = getpid();
sbt_flogln("I", (__int64)"src/sbt_log.c", "sbt_test_log", 0xC4u, v8, "%d", v13);
sbt_flog_init("./log2.txt");
v9 = getpid();
sbt_flogln("W", (__int64)"src/sbt_log.c", "sbt_test_log", 0xC8u, v9, "%d", v13);
sbt_dump((__int64)v14, 0, 37);
sbt_dump((__int64)v14, 0x10u, 37);
sbt_dumpln((__int64)v14, 0, 37);
sbt_dumpln((__int64)v14, 16, 37);
}

canonical_decompiled_code:
void func5()
{
unsigned int v0; // eax
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
__int64 v10; // [rsp+0h] [rbp-58h]
__int64 v11; // [rsp+0h] [rbp-58h]
__int64 v12; // [rsp+0h] [rbp-58h]
char v13[5]; // [rsp+1Bh] [rbp-3Dh] BYREF
_OWORD v14[2]; // [rsp+20h] [rbp-38h] BYREF
int v15[6]; // [rsp+40h] [rbp-18h] BYREF

strcpy(v13, "test");
v14[0] = _mm_load_si128((const __m128i *)&LC21);
v14[1] = _mm_load_si128((const __m128i *)&LC22);
qmemcpy(v15, " !\"#$%", 6);
v0 = getpid();
func0(stderr, "D", "src/sbt_log.c", "sbt_test_log", 0xABu, v0, "DEBUG %d", 3LL);
v1 = getpid();
func0(stderr, "I", "src/sbt_log.c", "sbt_test_log", 0xAEu, v1, "INFO %d", 3LL);
v2 = getpid();
func0(stderr, "W", "src/sbt_log.c", "sbt_test_log", 0xB1u, v2, "WARNING %d", 3LL);
v3 = getpid();
func0(stderr, "E", "src/sbt_log.c", "sbt_test_log", 0xB4u, v3, "ERROR %d", 3LL);
v4 = getpid();
func1("D", (__int64)"src/sbt_log.c", "sbt_test_log", 0xB7u, v4, "DEBUG %d", 3LL);
v5 = getpid();
LODWORD(v10) = 3;
func1("I", (__int64)"src/sbt_log.c", "sbt_test_log", 0xBAu, v5, "INFO %d", v10);
v6 = getpid();
LODWORD(v11) = 3;
func1("W", (__int64)"src/sbt_log.c", "sbt_test_log", 0xBDu, v6, "WARNING %d", v11);
v7 = getpid();
LODWORD(v12) = 3;
func1("E", (__int64)"src/sbt_log.c", "sbt_test_log", 0xC0u, v7, "ERROR %d", v12);
func2(0LL);
v8 = getpid();
func1("I", (__int64)"src/sbt_log.c", "sbt_test_log", 0xC4u, v8, "%d", v13);
func2("./log2.txt");
v9 = getpid();
func1("W", (__int64)"src/sbt_log.c", "sbt_test_log", 0xC8u, v9, "%d", v13);
func4((__int64)v14, 0, 37);
func4((__int64)v14, 0x10u, 37);
func3((__int64)v14, 0, 37);
func3((__int64)v14, 16, 37);
}

original_code:
void sbt_test_log(){
 int int_arg = 3;
 unsigned char char_arg[5]={"test"};
 unsigned char dump_arg[38]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
        ,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f
        ,0x20,0x21,0x22,0x23,0x24,0x25};
 sbt_logln_tofd(stderr, "D", "src/sbt_log.c", __func__, 171, getpid(), "DEBUG %d", int_arg);
 sbt_logln_tofd(stderr, "I", "src/sbt_log.c", __func__, 174, getpid(), "INFO %d", int_arg);
 sbt_logln_tofd(stderr, "W", "src/sbt_log.c", __func__, 177, getpid(), "WARNING %d", int_arg);
 sbt_logln_tofd(stderr, "E", "src/sbt_log.c", __func__, 180, getpid(), "ERROR %d", int_arg);
 sbt_flogln("D", "src/sbt_log.c", __func__, 183, getpid(), "DEBUG %d",int_arg);
 sbt_flogln("I", "src/sbt_log.c", __func__, 186, getpid(), "INFO %d",int_arg);
 sbt_flogln("W", "src/sbt_log.c", __func__, 189, getpid(), "WARNING %d",int_arg);
 sbt_flogln("E", "src/sbt_log.c", __func__, 192, getpid(), "ERROR %d",int_arg);
 sbt_flog_init(((void *)0));
 sbt_flogln("I", "src/sbt_log.c", __func__, 196, getpid(), "%d",char_arg);
 sbt_flog_init("./log2.txt");
 sbt_flogln("W", "src/sbt_log.c", __func__, 200, getpid(), "%d",char_arg);
 sbt_dump( (const unsigned char*)dump_arg, 0, 38-1 );
 sbt_dump( (const unsigned char*)dump_arg, 16, 38-1 );
 sbt_dumpln( (const unsigned char*)dump_arg, 0, 38-1 );
 sbt_dumpln( (const unsigned char*)dump_arg, 16, 38-1 );
}

canonical_original_code:
void sbt_test_log(){
 int int_arg = 3;
 unsigned char char_arg[5] = {"test"};
 unsigned char dump_arg[38] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
        ,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f
        ,0x20,0x21,0x22,0x23,0x24,0x25};
 sbt_logln_tofd(stderr, "D", "src/sbt_log.c", __func__, 171, getpid(), "DEBUG %d", int_arg);
 sbt_logln_tofd(stderr, "I", "src/sbt_log.c", __func__, 174, getpid(), "INFO %d", int_arg);
 sbt_logln_tofd(stderr, "W", "src/sbt_log.c", __func__, 177, getpid(), "WARNING %d", int_arg);
 sbt_logln_tofd(stderr, "E", "src/sbt_log.c", __func__, 180, getpid(), "ERROR %d", int_arg);
 sbt_flogln("D", "src/sbt_log.c", __func__, 183, getpid(), "DEBUG %d",int_arg);
 sbt_flogln("I", "src/sbt_log.c", __func__, 186, getpid(), "INFO %d",int_arg);
 sbt_flogln("W", "src/sbt_log.c", __func__, 189, getpid(), "WARNING %d",int_arg);
 sbt_flogln("E", "src/sbt_log.c", __func__, 192, getpid(), "ERROR %d",int_arg);
 sbt_flog_init(((void *)0));
 sbt_flogln("I", "src/sbt_log.c", __func__, 196, getpid(), "%d",char_arg);
 sbt_flog_init("./log2.txt");
 sbt_flogln("W", "src/sbt_log.c", __func__, 200, getpid(), "%d",char_arg);
 sbt_dump( (unsigned char *)dump_arg, 0, 38-1 );
 sbt_dump( (unsigned char *)dump_arg, 16, 38-1 );
 sbt_dumpln( (unsigned char *)dump_arg, 0, 38-1 );
 sbt_dumpln( (unsigned char *)dump_arg, 16, 38-1 );
}


decompiled_code:
int __fastcall sbt_mem_dump(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbx
int result; // eax
__int64 v4; // rcx
unsigned __int8 *v5; // rdx

v2 = a1;
result = fwrite("ADDRESS |VALUE\n", 1uLL, 0x19uLL, stderr);
if ( a2 )
{
do
{
v4 = *v2;
v5 = v2++;
result = fprintf(stderr, "%p|%02x\n", v5, v4);
}
while ( v2 != &a1[a2] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbx
int result; // eax
__int64 v4; // rcx
unsigned __int8 *v5; // rdx

v2 = a1;
result = fwrite("ADDRESS |VALUE\n", 1uLL, 0x19uLL, stderr);
if ( a2 )
{
do
{
v4 = *v2;
v5 = v2++;
result = fprintf(stderr, "%p|%02x\n", v5, v4);
}
while ( v2 != &a1[a2] );
}
return result;
}

original_code:
void sbt_mem_dump( void* buf, unsigned long long num){
 int i = 0;
 unsigned char* c_buf = buf;
 if(4==sizeof(buf)){
  fprintf(stderr, "ADDRESS   |VALUE\n");
 }else if(8==sizeof(buf)){
  fprintf(stderr, "ADDRESS           |VALUE\n");
 }else{
 }
 for(i=0; i<num; i++){
   fprintf(stderr, "%p|%02x\n",
     (unsigned char*)&c_buf[i],
     (unsigned char)c_buf[i]);
 }
}

canonical_original_code:
void sbt_mem_dump(void *buf, unsigned long long num){
 int i = 0;
 unsigned char *c_buf = buf;
 if(4==sizeof(buf)){
  fprintf(stderr, "ADDRESS   |VALUE\n");
 }else if(8==sizeof(buf)){
  fprintf(stderr, "ADDRESS           |VALUE\n");
 }else{
 }
 for(i=0; i<num; i++){
   fprintf(stderr, "%p|%02x\n",
     (unsigned char *)&c_buf[i],
     (unsigned char)c_buf[i]);
 }
}

variable_types:
buf
void *

variable_types:
num
unsigned long long


decompiled_code:
int sbt_test_mem_dump()
{
__int64 v1; // [rsp+0h] [rbp-28h] BYREF
__int64 *v2; // [rsp+8h] [rbp-20h] BYREF
__m128i v3; // [rsp+10h] [rbp-18h] BYREF

v2 = &v1;
v3 = _mm_load_si128((const __m128i *)&LC31);
v1 = 287454020LL;
fwrite("Dump array memory =>\n", 1uLL, 0x15uLL, stderr);
fprintf(stderr, "Start address is %p\n", &v3);
sbt_mem_dump((unsigned __int8 *)&v3, 16LL);
fwrite("Dump int memory =>\n", 1uLL, 0x13uLL, stderr);
fprintf(stderr, "Start address is %p\n", &v1);
sbt_mem_dump((unsigned __int8 *)&v1, 8LL);
fwrite("Dump int pointer memory =>\n", 1uLL, 0x1BuLL, stderr);
fprintf(stderr, "Start address is %p\n", &v2);
sbt_mem_dump((unsigned __int8 *)&v2, 8LL);
fwrite("Dump all local memory =>\n", 1uLL, 0x19uLL, stderr);
sbt_mem_dump((unsigned __int8 *)&v2, 32LL);
fwrite("Dump stack memory(with \"ebp\" and \"return address\") =>\n", 1uLL, 0x36uLL, stderr);
return sbt_mem_dump((unsigned __int8 *)&v2, 48LL);
}

canonical_decompiled_code:
int func7()
{
__int64 v1; // [rsp+0h] [rbp-28h] BYREF
__int64 *v2; // [rsp+8h] [rbp-20h] BYREF
__m128i v3; // [rsp+10h] [rbp-18h] BYREF

v2 = &v1;
v3 = _mm_load_si128((const __m128i *)&LC31);
v1 = 287454020LL;
fwrite("Dump array memory =>\n", 1uLL, 0x15uLL, stderr);
fprintf(stderr, "Start address is %p\n", &v3);
func6((unsigned __int8 *)&v3, 16LL);
fwrite("Dump int memory =>\n", 1uLL, 0x13uLL, stderr);
fprintf(stderr, "Start address is %p\n", &v1);
func6((unsigned __int8 *)&v1, 8LL);
fwrite("Dump int pointer memory =>\n", 1uLL, 0x1BuLL, stderr);
fprintf(stderr, "Start address is %p\n", &v2);
func6((unsigned __int8 *)&v2, 8LL);
fwrite("Dump all local memory =>\n", 1uLL, 0x19uLL, stderr);
func6((unsigned __int8 *)&v2, 32LL);
fwrite("Dump stack memory(with \"ebp\" and \"return address\") =>\n", 1uLL, 0x36uLL, stderr);
return func6((unsigned __int8 *)&v2, 48LL);
}

original_code:
void sbt_test_mem_dump(){
 unsigned char test_ar[]={ 0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18
           ,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28 };
 long long test_int = 0x11223344;
 long long* p_test_int = &test_int;
 fprintf(stderr, "Dump array memory =>\n");
 fprintf(stderr, "Start address is %p\n",&test_ar[0]);
 sbt_mem_dump( (void*)test_ar ,sizeof(test_ar));
 fprintf(stderr, "Dump int memory =>\n");
 fprintf(stderr, "Start address is %p\n",&test_int);
 sbt_mem_dump( (void*)&test_int ,sizeof(long long));
 fprintf(stderr, "Dump int pointer memory =>\n");
 fprintf(stderr, "Start address is %p\n",&p_test_int);
 sbt_mem_dump( (void*)&p_test_int ,sizeof(long long*));
 fprintf(stderr, "Dump all local memory =>\n");
 sbt_mem_dump( (void*)&p_test_int, sizeof(long long*) + sizeof(long long) + sizeof(test_ar));
 fprintf(stderr, "Dump stack memory(with \"ebp\" and \"return address\") =>\n");
 sbt_mem_dump( (void*)&p_test_int, sizeof(long long*) + sizeof(long long) + sizeof(test_ar) + sizeof(void*) + sizeof(void*) );
}

canonical_original_code:
void sbt_test_mem_dump(){
 unsigned char test_ar[] = { 0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18
           ,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28 };
 long long test_int = 0x11223344;
 long long *p_test_int = &test_int;
 fprintf(stderr, "Dump array memory =>\n");
 fprintf(stderr, "Start address is %p\n",&test_ar[0]);
 sbt_mem_dump( (void *)test_ar ,sizeof(test_ar));
 fprintf(stderr, "Dump int memory =>\n");
 fprintf(stderr, "Start address is %p\n",&test_int);
 sbt_mem_dump( (void *)&test_int ,sizeof(long long));
 fprintf(stderr, "Dump int pointer memory =>\n");
 fprintf(stderr, "Start address is %p\n",&p_test_int);
 sbt_mem_dump( (void *)&p_test_int ,sizeof(long long *));
 fprintf(stderr, "Dump all local memory =>\n");
 sbt_mem_dump( (void *)&p_test_int, sizeof(long long *) + sizeof(long long) + sizeof(test_ar));
 fprintf(stderr, "Dump stack memory(with \"ebp\" and \"return address\") =>\n");
 sbt_mem_dump( (void *)&p_test_int, sizeof(long long *) + sizeof(long long) + sizeof(test_ar) + sizeof(void *) + sizeof(void *) );
}


decompiled_code:
__int64 matsu_d()
{
printf("%s -- start\n", "matsu_d");
printf("%s -- exit\n", "matsu_d");
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
printf("%s -- start\n", "matsu_d");
printf("%s -- exit\n", "matsu_d");
return 0LL;
}

original_code:
static int matsu_d(arg_set_st* st){
 printf("%s -- start\n",__func__);
 printf("%s -- exit\n",__func__);
 return 0;
}

canonical_original_code:
static int matsu_d(struct arg_set *st){
 printf("%s -- start\n",__func__);
 printf("%s -- exit\n",__func__);
 return 0;
}

variable_types:
st
struct arg_set { int aa; char bb; } *

return_type: int


decompiled_code:
__int64 matsu_c()
{
printf("%s -- start\n", "matsu_c");
printf("%s -- exit\n", "matsu_c");
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
printf("%s -- start\n", "matsu_c");
printf("%s -- exit\n", "matsu_c");
return 0LL;
}

original_code:
static int matsu_c(int ii, char cc){
 printf("%s -- start\n",__func__);
 printf("%s -- exit\n",__func__);
 return 0;
}

variable_types: ii int

variable_types: cc char


decompiled_code:
__int64 matsu_b()
{
printf("%s -- start\n", "matsu_b");
printf("%s -- exit\n", "matsu_b");
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
printf("%s -- start\n", "matsu_b");
printf("%s -- exit\n", "matsu_b");
return 0LL;
}

original_code:
static int matsu_b(char cc){
 printf("%s -- start\n",__func__);
 printf("%s -- exit\n",__func__);
 return 0;
}


decompiled_code:
int matsu_a()
{
printf("%s -- start\n", "matsu_a");
return printf("%s -- exit\n", "matsu_a");
}

canonical_decompiled_code:
int func3()
{
printf("%s -- start\n", "matsu_a");
return printf("%s -- exit\n", "matsu_a");
}

original_code:
static void matsu_a(int ii){
 printf("%s -- start\n",__func__);
 printf("%s -- exit\n",__func__);
 return;
}


decompiled_code:
__int64 *plugin_init()
{
__int64 *result; // rax

printf("%s %s -- start\n", "plugin_matsu.c", "plugin_init");
printf("%s %s -- exit\n", "plugin_matsu.c", "plugin_init");
result = &info;
info = (__int64)"plugin-matsu";
xmmword_188 = (__int128)_mm_load_si128((const __m128i *)fp);
xmmword_198 = (__int128)_mm_load_si128((const __m128i *)off_250);
return result;
}

canonical_decompiled_code:
__int64 *func4()
{
__int64 *result; // rax

printf("%s %s -- start\n", "plugin_matsu.c", "plugin_init");
printf("%s %s -- exit\n", "plugin_matsu.c", "plugin_init");
result = &info;
info = (__int64)"plugin-matsu";
xmmword_188 = (__int128)_mm_load_si128((const __m128i *)fp);
xmmword_198 = (__int128)_mm_load_si128((const __m128i *)off_250);
return result;
}

original_code:
plugin_info_st* plugin_init(){
 printf("%s %s -- start\n","plugin_matsu.c",__func__);
 printf("%s %s -- exit\n","plugin_matsu.c",__func__);
 info.name = "plugin-matsu";
 info.fp = fp;
 return &info;
}

canonical_original_code:
struct plugin_info *plugin_init(){
 printf("%s %s -- start\n","plugin_matsu.c",__func__);
 printf("%s %s -- exit\n","plugin_matsu.c",__func__);
 info.name = "plugin-matsu";
 info.fp = fp;
 return &info;
}

return_type: struct plugin_info { char *name; struct func_pointer { void (*func_a)(int); int (*func_b)(char); int (*func_c)(int, char); int (*func_d)(struct arg_set { int aa; char bb; } *); } fp; } *

user_defined_types: struct plugin_info { char *name; struct func_pointer fp; }

user_defined_types: struct func_pointer { void (*func_a)(int); int (*func_b)(char); int (*func_c)(int, char); int (*func_d)(struct arg_set *); }


decompiled_code:
int plugin_desc()
{
printf("%s %s -- start\n", "plugin_matsu.c", "plugin_desc");
return printf("%s %s -- exit\n", "plugin_matsu.c", "plugin_desc");
}

canonical_decompiled_code:
int func5()
{
printf("%s %s -- start\n", "plugin_matsu.c", "plugin_desc");
return printf("%s %s -- exit\n", "plugin_matsu.c", "plugin_desc");
}

original_code:
void plugin_desc(){
 printf("%s %s -- start\n","plugin_matsu.c",__func__);
 printf("%s %s -- exit\n","plugin_matsu.c",__func__);
}


decompiled_code:
char *__fastcall sbt_web_html_parse(char **a1, const char *a2)
{
int v4; // edi
int v5; // esi
char *result; // rax
int v7; // er8
const char *v8; // rdx
int v9; // ecx
__int64 v10; // rdx
unsigned __int64 v11; // r10
char v12; // cl
int v13; // er9
__int64 v14; // rax
__int64 v15; // rcx
__int64 v16; // rdx
__int64 v17; // r10
char v18; // r9
__int64 v19; // r10
char *v20; // rcx
char *v21; // rax
__int128 v22; // [rsp+0h] [rbp-418h] BYREF
char v23[1008]; // [rsp+10h] [rbp-408h] BYREF

v22 = 0LL;
memset(v23, 0, sizeof(v23));
v4 = 0;
v5 = strlen(a2);
result = 0LL;
v7 = v5 - 1;
if ( v5 <= 0 )
{
LABEL_6:
*a1 = 0LL;
return result;
}
LABEL_2:
while ( 2 )
{
v8 = &a2[(int)result];
while ( 1 )
{
v9 = (int)result;
result = (char *)(unsigned int)((_DWORD)result + 1);
if ( *v8 == 62 )
break;
++v8;
if ( v5 <= (int)result )
goto LABEL_5;
}
if ( v5 > (int)result )
{
v10 = v9 + 2;
v11 = (int)result + (unsigned __int64)(unsigned int)(v7 - (_DWORD)result) + 2;
while ( 1 )
{
v12 = a2[v10 - 1];
v13 = v10;
result = (char *)(unsigned int)v10;
if ( v12 == 60 )
break;
if ( v12 != 32 )
{
v14 = v4++;
*((_BYTE *)&v22 + v14) = v12;
if ( v5 <= (int)v10 )
goto LABEL_16;
v15 = (int)v10;
v16 = (int)v10 + 1;
v17 = (unsigned int)(v7 - v13);
result = (char *)(v14 - v13);
v18 = a2[v16 - 1];
v19 = v15 + v17 + 2;
v20 = (char *)&v22 + (_QWORD)result;
LODWORD(result) = v16;
if ( v18 == 60 )
{
LABEL_15:
if ( v5 > (int)v16 )
goto LABEL_2;
}
else
{
while ( 1 )
{
v20[v16++] = v18;
++v4;
if ( v19 == v16 )
break;
v18 = a2[v16 - 1];
LODWORD(result) = v16;
if ( v18 == 60 )
goto LABEL_15;
}
}
goto LABEL_16;
}
if ( ++v10 == v11 )
goto LABEL_5;
}
if ( v5 > (int)v10 )
continue;
}
break;
}
LABEL_5:
if ( !v4 )
goto LABEL_6;
LABEL_16:
v21 = (char *)calloc(v4, 1uLL);
*a1 = v21;
return strcpy(v21, (const char *)&v22);
}

canonical_decompiled_code:
char *__fastcall func0(char **a1, const char *a2)
{
int v4; // edi
int v5; // esi
char *result; // rax
int v7; // er8
const char *v8; // rdx
int v9; // ecx
__int64 v10; // rdx
unsigned __int64 v11; // r10
char v12; // cl
int v13; // er9
__int64 v14; // rax
__int64 v15; // rcx
__int64 v16; // rdx
__int64 v17; // r10
char v18; // r9
__int64 v19; // r10
char *v20; // rcx
char *v21; // rax
__int128 v22; // [rsp+0h] [rbp-418h] BYREF
char v23[1008]; // [rsp+10h] [rbp-408h] BYREF

v22 = 0LL;
memset(v23, 0, sizeof(v23));
v4 = 0;
v5 = strlen(a2);
result = 0LL;
v7 = v5 - 1;
if ( v5 <= 0 )
{
LABEL_6:
*a1 = 0LL;
return result;
}
LABEL_2:
while ( 2 )
{
v8 = &a2[(int)result];
while ( 1 )
{
v9 = (int)result;
result = (char *)(unsigned int)((_DWORD)result + 1);
if ( *v8 == 62 )
break;
++v8;
if ( v5 <= (int)result )
goto LABEL_5;
}
if ( v5 > (int)result )
{
v10 = v9 + 2;
v11 = (int)result + (unsigned __int64)(unsigned int)(v7 - (_DWORD)result) + 2;
while ( 1 )
{
v12 = a2[v10 - 1];
v13 = v10;
result = (char *)(unsigned int)v10;
if ( v12 == 60 )
break;
if ( v12 != 32 )
{
v14 = v4++;
*((_BYTE *)&v22 + v14) = v12;
if ( v5 <= (int)v10 )
goto LABEL_16;
v15 = (int)v10;
v16 = (int)v10 + 1;
v17 = (unsigned int)(v7 - v13);
result = (char *)(v14 - v13);
v18 = a2[v16 - 1];
v19 = v15 + v17 + 2;
v20 = (char *)&v22 + (_QWORD)result;
LODWORD(result) = v16;
if ( v18 == 60 )
{
LABEL_15:
if ( v5 > (int)v16 )
goto LABEL_2;
}
else
{
while ( 1 )
{
v20[v16++] = v18;
++v4;
if ( v19 == v16 )
break;
v18 = a2[v16 - 1];
LODWORD(result) = v16;
if ( v18 == 60 )
goto LABEL_15;
}
}
goto LABEL_16;
}
if ( ++v10 == v11 )
goto LABEL_5;
}
if ( v5 > (int)v10 )
continue;
}
break;
}
LABEL_5:
if ( !v4 )
goto LABEL_6;
LABEL_16:
v21 = (char *)calloc(v4, 1uLL);
*a1 = v21;
return strcpy(v21, (const char *)&v22);
}

original_code:
void sbt_web_html_parse(char** outBuf,const char* inBuf){
 char textBuf[1024] = {'\0'};
 int in_len;
 int i;
 int tagStatus = 0;
 int outLen = 0;
 in_len = strlen( inBuf );
 for(i=0; i<in_len; i++){
  if( 0 == tagStatus ){
   if('>' == inBuf[i]){
    tagStatus = 1;
   }
  }else if(1 == tagStatus){
   if('<' == inBuf[i]){
    tagStatus = 0;
   }else if(' ' == inBuf[i]){
   }else{
    tagStatus = 2;
    textBuf[outLen] = inBuf[i];
    outLen++;
   }
  }else if(2 == tagStatus){
   if('<' == inBuf[i]){
    tagStatus = 0;
    continue;
   }else{
    textBuf[outLen] = inBuf[i];
    outLen++;
   }
  }
 }
 if(0==outLen){
  *outBuf = ((void *)0);
 }else{
  *outBuf = malloc(outLen);
  memset( *outBuf, '\0', outLen );
  strcpy( *outBuf, textBuf );
 }
 return;
}

canonical_original_code:
void sbt_web_html_parse(char **outBuf, char *inBuf){
 char textBuf[1024] = {'\0'};
 int in_len;
 int i;
 int tagStatus = 0;
 int outLen = 0;
 in_len = strlen( inBuf );
 for(i=0; i<in_len; i++){
  if( 0 == tagStatus ){
   if('>' == inBuf[i]){
    tagStatus = 1;
   }
  }else if(1 == tagStatus){
   if('<' == inBuf[i]){
    tagStatus = 0;
   }else if(' ' == inBuf[i]){
   }else{
    tagStatus = 2;
    textBuf[outLen] = inBuf[i];
    outLen++;
   }
  }else if(2 == tagStatus){
   if('<' == inBuf[i]){
    tagStatus = 0;
    continue;
   }else{
    textBuf[outLen] = inBuf[i];
    outLen++;
   }
  }
 }
 if(0==outLen){
  *outBuf = ((void *)0);
 }else{
  *outBuf = malloc(outLen);
  memset( *outBuf, '\0', outLen );
  strcpy( *outBuf, textBuf );
 }
 return;
}

variable_types:
outBuf
char **

variable_types:
inBuf
char *

variable_types:
textBuf
char [1024]

variable_types: tagStatus int

variable_types: outLen int


decompiled_code:
__int64 sbt_web_html_parse_test()
{
bool v0; // cf
bool v1; // zf
_BYTE *v2; // rdi
__int64 v3; // rcx
char *v4; // rsi
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
char *v9; // rsi
char *v11; // [rsp+8h] [rbp-60h] BYREF
__m128i v12; // [rsp+10h] [rbp-58h] BYREF
char v13[16]; // [rsp+20h] [rbp-48h] BYREF
__int128 v14[2]; // [rsp+30h] [rbp-38h] BYREF
char v15[8]; // [rsp+50h] [rbp-18h] BYREF

strcpy(v13, "/body></html>");
v12 = _mm_load_si128((const __m128i *)&LC5);
v14[0] = (__int128)_mm_load_si128((const __m128i *)&LC6);
v11 = 0LL;
strcpy(v15, "l>");
v14[1] = (__int128)_mm_load_si128((const __m128i *)&LC7);
sbt_web_html_parse(&v11, v12.m128i_i8);
v2 = &unk_275;
v3 = 4LL;
v4 = v11;
do
{
if ( !v3 )
break;
v0 = (unsigned __int8)*v4 < *v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
if ( (!v0 && !v1) != v0 )
_assert_fail("0 == strcmp(p_buf,\"aaa\")", "src/sbt_web.c", 0x46u, "sbt_web_html_parse_test");
sbt_free(v11, v4);
sbt_web_html_parse(&v11, (const char *)v14);
v7 = "bbb ";
v8 = 6LL;
v9 = v11;
do
{
if ( !v8 )
break;
v5 = (unsigned __int8)*v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) != v5 )
_assert_fail("0 == strcmp(p_buf,\"bbb \")", "src/sbt_web.c", 0x4Au, "sbt_web_html_parse_test");
return sbt_free(v11, v9);
}

original_code:
void sbt_web_html_parse_test(){
 char *p_buf = ((void *)0);
 char html_test1[]={"aaa"};
 char html_test2[]={"  bbb   "};
 sbt_web_html_parse( (char**)&p_buf,(const char*)html_test1 );
 ((void) sizeof ((0 == strcmp(p_buf,"aaa")) ? 1 : 0), __extension__ ({ if (0 == strcmp(p_buf,"aaa")) ; else __assert_fail ("0 == strcmp(p_buf,\"aaa\")", "src/sbt_web.c", 70, __extension__ __PRETTY_FUNCTION__); }));
 if(((void *)0)!=p_buf) sbt_free(p_buf);
 sbt_web_html_parse( (char**)&p_buf,(const char*)html_test2 );
 ((void) sizeof ((0 == strcmp(p_buf,"bbb  ")) ? 1 : 0), __extension__ ({ if (0 == strcmp(p_buf,"bbb  ")) ; else __assert_fail ("0 == strcmp(p_buf,\"bbb  \")", "src/sbt_web.c", 74, __extension__ __PRETTY_FUNCTION__); }));
 if(((void *)0)!=p_buf) sbt_free(p_buf);
}

canonical_original_code:
void sbt_web_html_parse_test(){
 char *p_buf = ((void *)0);
 char html_test1[] = {"aaa"};
 char html_test2[] = {"  bbb   "};
 sbt_web_html_parse( (char **)&p_buf,(char *)html_test1 );
 ((void) sizeof ((0 == strcmp(p_buf,"aaa")) ? 1 : 0), __extension__ ({ if (0 == strcmp(p_buf,"aaa")) ; else __assert_fail ("0 == strcmp(p_buf,\"aaa\")", "src/sbt_web.c", 70, __extension__ __PRETTY_FUNCTION__); }));
 if(((void *)0)!=p_buf) sbt_free(p_buf);
 sbt_web_html_parse( (char **)&p_buf,(char *)html_test2 );
 ((void) sizeof ((0 == strcmp(p_buf,"bbb  ")) ? 1 : 0), __extension__ ({ if (0 == strcmp(p_buf,"bbb  ")) ; else __assert_fail ("0 == strcmp(p_buf,\"bbb  \")", "src/sbt_web.c", 74, __extension__ __PRETTY_FUNCTION__); }));
 if(((void *)0)!=p_buf) sbt_free(p_buf);
}


decompiled_code:
void __fastcall progress_print(_DWORD *a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // r14
char *v5; // rbp

if ( a1 )
{
v4 = a2 / (a3 / 0x28);
v5 = (char *)calloc(0x29uLL, 1uLL);
memset(v5, 42, (unsigned int)v4);
memset(&v5[(unsigned int)v4], 45, (unsigned int)(40 - v4));
fputs(v5, stderr);
fprintf(stderr, "(%lld/%lld)", a2, a3);
fputc(13, stderr);
fflush(stderr);
if ( (_DWORD)v4 == 40 )
fputc(10, stderr);
*a1 = v4;
}
}

canonical_decompiled_code:
void __fastcall func1(_DWORD *a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // r14
char *v5; // rbp

if ( a1 )
{
v4 = a2 / (a3 / 0x28);
v5 = (char *)calloc(0x29uLL, 1uLL);
memset(v5, 42, (unsigned int)v4);
memset(&v5[(unsigned int)v4], 45, (unsigned int)(40 - v4));
fputs(v5, stderr);
fprintf(stderr, "(%lld/%lld)", a2, a3);
fputc(13, stderr);
fflush(stderr);
if ( (_DWORD)v4 == 40 )
fputc(10, stderr);
*a1 = v4;
}
}

original_code:
void progress_print(unsigned int* prog_num, unsigned long long progress, unsigned long long max){
 unsigned int MAX_WIDTH = 40;
 unsigned long long rate = 0;
 unsigned int new_prog_num = 0;
 unsigned char* prog_bar = ((void *)0);
 if( ((void *)0)==prog_num ){
  return;
 }
 rate = max / (unsigned long long)MAX_WIDTH;
 new_prog_num = (unsigned int)(progress / rate);
 ;
 prog_bar = (unsigned char*)malloc(MAX_WIDTH+1);
 memset( prog_bar, 0x00, MAX_WIDTH+1 );
 memset( prog_bar, '*', new_prog_num );
 memset( prog_bar+new_prog_num, '-', MAX_WIDTH-new_prog_num );
 fprintf( stderr, "%s",prog_bar );
 fprintf( stderr, "(%lld/%lld)", progress, max );
    fprintf( stderr,"\r");
 fflush( stderr );
 if( MAX_WIDTH==new_prog_num ){
       fprintf( stderr, "\n" );
 }
 *prog_num = new_prog_num;
 if( ((void *)0)==prog_bar ){
  free(prog_bar);
 }
 return;
}

canonical_original_code:
void progress_print(unsigned int *prog_num, unsigned long long progress, unsigned long long max){
 unsigned int MAX_WIDTH = 40;
 unsigned long long rate = 0;
 unsigned int new_prog_num = 0;
 unsigned char *prog_bar = ((void *)0);
 if( ((void *)0)==prog_num ){
  return;
 }
 rate = max / (unsigned long long)MAX_WIDTH;
 new_prog_num = (unsigned int)(progress / rate);
 ;
 prog_bar = (unsigned char *)malloc(MAX_WIDTH+1);
 memset( prog_bar, 0x00, MAX_WIDTH+1 );
 memset( prog_bar, '*', new_prog_num );
 memset( prog_bar+new_prog_num, '-', MAX_WIDTH-new_prog_num );
 fprintf( stderr, "%s",prog_bar );
 fprintf( stderr, "(%lld/%lld)", progress, max );
    fprintf( stderr,"\r");
 fflush( stderr );
 if( MAX_WIDTH==new_prog_num ){
       fprintf( stderr, "\n" );
 }
 *prog_num = new_prog_num;
 if( ((void *)0)==prog_bar ){
  free(prog_bar);
 }
 return;
}

variable_types:
progress
unsigned long long

variable_types:
max
unsigned long long

variable_types:
rate
unsigned long long


decompiled_code:
void __fastcall append_file_thread(void *src, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // rbp
void *v4; // rax
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-68h] BYREF

v2 = malloc(0x10uLL);
v2[3] = 0;
v3 = v2;
v4 = malloc(a2);
*(_QWORD *)v3 = v4;
memcpy(v4, src, a2);
v3[2] = a2;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 0x10000uLL);
pthread_create(&newthread, 0LL, (void *(*)(void *))append_file, v3);
pthread_join(newthread, 0LL);
pthread_attr_destroy(&attr);
if ( *(_QWORD *)v3 )
free(*(void **)v3);
free(v3);
}

canonical_decompiled_code:
void __fastcall func2(void *src, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // rbp
void *v4; // rax
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-68h] BYREF

v2 = malloc(0x10uLL);
v2[3] = 0;
v3 = v2;
v4 = malloc(a2);
*(_QWORD *)v3 = v4;
memcpy(v4, src, a2);
v3[2] = a2;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 0x10000uLL);
pthread_create(&newthread, 0LL, (void *(*)(void *))append_file, v3);
pthread_join(newthread, 0LL);
pthread_attr_destroy(&attr);
if ( *(_QWORD *)v3 )
free(*(void **)v3);
free(v3);
}

original_code:
void append_file_thread( char* buf, int size ){
    pthread_t thread;
 pthread_attr_t attr;
 append_file_st* apd;
 apd = (append_file_st*)malloc( sizeof(append_file_st) );
 memset( apd, 0x00, sizeof(append_file_st) );
 apd->buf = (char*)malloc(size);
 memcpy(apd->buf, buf, size);
 apd->size = size;
 pthread_attr_init(&attr);
 pthread_attr_setstacksize(&attr, 64 * 1024);
 pthread_create( &thread, ((void *)0), (void*)append_file, (append_file_st*)apd );
 ;
 pthread_join( thread, ((void *)0) );
 ;
 pthread_attr_destroy(&attr);
 if(((void *)0)!=apd->buf){
  free(apd->buf);
 }
 if(((void *)0)!=apd){
  free(apd);
 }
}

canonical_original_code:
void append_file_thread(char *buf, int size){
    unsigned long thread;
 union pthread_attr_t attr;
 struct _append_file_st *apd;
 apd = (struct _append_file_st *)malloc( sizeof(append_file_st) );
 memset( apd, 0x00, sizeof(append_file_st) );
 apd->buf = (char *)malloc(size);
 memcpy(apd->buf, buf, size);
 apd->size = size;
 pthread_attr_init(&attr);
 pthread_attr_setstacksize(&attr, 64 * 1024);
 pthread_create( &thread, ((void *)0), (void *)append_file, (struct _append_file_st *)apd );
 ;
 pthread_join( thread, ((void *)0) );
 ;
 pthread_attr_destroy(&attr);
 if(((void *)0)!=apd->buf){
  free(apd->buf);
 }
 if(((void *)0)!=apd){
  free(apd);
 }
}

variable_types:
buf
char *

variable_types: size int

variable_types:
thread
unsigned long

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types: struct _append_file_st { char *buf; int size; } *


decompiled_code:
void *__fastcall sub_thread_join(void *a1)
{
pthread_t v1; // r12
unsigned int v2; // eax
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
__int64 v7; // [rsp-8h] [rbp-20h]

v1 = pthread_self();
v2 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sub_thread_join", 50LL, v2, "Start(threadID=0x%x)", v1);
if ( *(int *)a1 > 0 )
{
v3 = 0LL;
do
{
sleep(1u);
v4 = getpid();
v7 = v3;
v3 = (unsigned int)(v3 + 1);
sbt_logln_tofd(stderr, "I", "src/sbt_thread.c", "sub_thread_join", 54LL, v4, "count = %d", v7);
}
while ( *(_DWORD *)a1 > (int)v3 );
}
v5 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sub_thread_join", 57LL, v5, "End(threadID=0x%x)", v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
pthread_t v1; // r12
unsigned int v2; // eax
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
__int64 v7; // [rsp-8h] [rbp-20h]

v1 = pthread_self();
v2 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sub_thread_join", 50LL, v2, "Start(threadID=0x%x)", v1);
if ( *(int *)a1 > 0 )
{
v3 = 0LL;
do
{
sleep(1u);
v4 = getpid();
v7 = v3;
v3 = (unsigned int)(v3 + 1);
sbt_logln_tofd(stderr, "I", "src/sbt_thread.c", "sub_thread_join", 54LL, v4, "count = %d", v7);
}
while ( *(_DWORD *)a1 > (int)v3 );
}
v5 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sub_thread_join", 57LL, v5, "End(threadID=0x%x)", v1);
return 0LL;
}

original_code:
static void *sub_thread_join(int* param){
 int i;
 pthread_t tid = pthread_self();
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 50, getpid(), "Start(threadID=0x%x)", tid);
 for( i=0; i<*param; i++ ){
        sleep(1);
        sbt_logln_tofd(stderr, "I", "src/sbt_thread.c", __func__, 54, getpid(), "count = %d" , i);
 }
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 57, getpid(), "End(threadID=0x%x)", tid);
 return ((void *)0);
}

canonical_original_code:
static void *sub_thread_join(int *param){
 int i;
 unsigned long tid = pthread_self();
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 50, getpid(), "Start(threadID=0x%x)", tid);
 for( i=0; i<*param; i++ ){
        sleep(1);
        sbt_logln_tofd(stderr, "I", "src/sbt_thread.c", __func__, 54, getpid(), "count = %d" , i);
 }
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 57, getpid(), "End(threadID=0x%x)", tid);
 return ((void *)0);
}

variable_types:
param
int *

variable_types: i int

variable_types:
tid
unsigned long

return_type: void *


decompiled_code:
void *__fastcall sub_thread_exclusive(void *a1)
{
pthread_t v1; // rax
__int64 v2; // rbp
pthread_t v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax

v1 = pthread_self();
v2 = *(unsigned int *)a1;
v3 = v1;
v4 = getpid();
sbt_logln_tofd(
stderr,
"D",
"src/sbt_thread.c",
"sub_thread_exclusive",
77LL,
v4,
"Start(param=0x%x threadID=0x%x)",
v2,
v3);
pthread_mutex_lock(&test_mutex);
test_sleep_func_isra_0();
pthread_mutex_unlock(&test_mutex);
v5 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sub_thread_exclusive", 83LL, v5, "End(threadID=0x%x)", v3);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1)
{
pthread_t v1; // rax
__int64 v2; // rbp
pthread_t v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax

v1 = pthread_self();
v2 = *(unsigned int *)a1;
v3 = v1;
v4 = getpid();
sbt_logln_tofd(
stderr,
"D",
"src/sbt_thread.c",
"sub_thread_exclusive",
77LL,
v4,
"Start(param=0x%x threadID=0x%x)",
v2,
v3);
pthread_mutex_lock(&test_mutex);
func1();
pthread_mutex_unlock(&test_mutex);
v5 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sub_thread_exclusive", 83LL, v5, "End(threadID=0x%x)", v3);
return 0LL;
}

original_code:
static void *sub_thread_exclusive(int* param){
 pthread_t tid = pthread_self();
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 77, getpid(), "Start(param=0x%x threadID=0x%x)", *param, tid);
    pthread_mutex_lock(&test_mutex);
    test_sleep_func();
    pthread_mutex_unlock(&test_mutex);
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 83, getpid(), "End(threadID=0x%x)", tid);
 return ((void *)0);
}

canonical_original_code:
static void *sub_thread_exclusive(int *param){
 unsigned long tid = pthread_self();
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 77, getpid(), "Start(param=0x%x threadID=0x%x)", *param, tid);
    pthread_mutex_lock(&test_mutex);
    test_sleep_func();
    pthread_mutex_unlock(&test_mutex);
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 83, getpid(), "End(threadID=0x%x)", tid);
 return ((void *)0);
}


decompiled_code:
int sbt_thread_detatch()
{
pthread_t v0; // rax

v0 = pthread_self();
return pthread_detach(v0);
}

canonical_decompiled_code:
int func3()
{
pthread_t v0; // rax

v0 = pthread_self();
return pthread_detach(v0);
}

original_code:
void sbt_thread_detatch( ){
 pthread_detach(pthread_self());
}

canonical_original_code:
void sbt_thread_detatch(){
 pthread_detach(pthread_self());
}


decompiled_code:
void *__fastcall sub_thread_detach(void *a1)
{
pthread_t v1; // r13
unsigned int v2; // eax
__int64 v3; // rbx
unsigned int v4; // eax
__int64 v5; // rbx
__int64 v6; // r12
unsigned int v7; // eax
unsigned int v8; // eax
__int64 v10; // [rsp-18h] [rbp-40h]

v1 = pthread_self();
v2 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sub_thread_detach", 34LL, v2, "Start(threadID=0x%x)", v1);
v3 = *(unsigned int *)a1;
v4 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sub_thread_detach", 35LL, v4, "param->size=%d", v3);
if ( *(int *)a1 > 0 )
{
v5 = 0LL;
do
{
sleep(1u);
v6 = (unsigned int)*((char *)a1 + v5 + 4);
v7 = getpid();
v10 = v5++;
sbt_logln_tofd(stderr, "I", "src/sbt_thread.c", "sub_thread_detach", 38LL, v7, "param->buf[%d]=%d", v10, v6);
}
while ( *(_DWORD *)a1 > (int)v5 );
}
v8 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sub_thread_detach", 41LL, v8, "End(threadID=0x%x)", v1);
sbt_thread_detatch();
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func4(void *a1)
{
pthread_t v1; // r13
unsigned int v2; // eax
__int64 v3; // rbx
unsigned int v4; // eax
__int64 v5; // rbx
__int64 v6; // r12
unsigned int v7; // eax
unsigned int v8; // eax
__int64 v10; // [rsp-18h] [rbp-40h]

v1 = pthread_self();
v2 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sub_thread_detach", 34LL, v2, "Start(threadID=0x%x)", v1);
v3 = *(unsigned int *)a1;
v4 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sub_thread_detach", 35LL, v4, "param->size=%d", v3);
if ( *(int *)a1 > 0 )
{
v5 = 0LL;
do
{
sleep(1u);
v6 = (unsigned int)*((char *)a1 + v5 + 4);
v7 = getpid();
v10 = v5++;
sbt_logln_tofd(stderr, "I", "src/sbt_thread.c", "sub_thread_detach", 38LL, v7, "param->buf[%d]=%d", v10, v6);
}
while ( *(_DWORD *)a1 > (int)v5 );
}
v8 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sub_thread_detach", 41LL, v8, "End(threadID=0x%x)", v1);
func3();
return 0LL;
}

original_code:
static void *sub_thread_detach(test_thread_func_st* param){
 int i;
 pthread_t tid = pthread_self();
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 34, getpid(), "Start(threadID=0x%x)", tid);
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 35, getpid(), "param->size=%d", param->size);
 for( i=0; i<param->size; i++ ){
        sleep(1);
        sbt_logln_tofd(stderr, "I", "src/sbt_thread.c", __func__, 38, getpid(), "param->buf[%d]=%d", i, param->buf[i]);
 }
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 41, getpid(), "End(threadID=0x%x)", tid);
 sbt_thread_detatch();
 return ((void *)0);
}

canonical_original_code:
static void *sub_thread_detach(struct _test_thread_func_st *param){
 int i;
 unsigned long tid = pthread_self();
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 34, getpid(), "Start(threadID=0x%x)", tid);
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 35, getpid(), "param->size=%d", param->size);
 for( i=0; i<param->size; i++ ){
        sleep(1);
        sbt_logln_tofd(stderr, "I", "src/sbt_thread.c", __func__, 38, getpid(), "param->buf[%d]=%d", i, param->buf[i]);
 }
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 41, getpid(), "End(threadID=0x%x)", tid);
 sbt_thread_detatch();
 return ((void *)0);
}

variable_types: struct _test_thread_func_st { int size; char buf[4]; } *


decompiled_code:
void __noreturn sbt_thread_exit()
{
pthread_exit(0LL);
}

canonical_decompiled_code:
void __noreturn func5()
{
pthread_exit(0LL);
}

original_code:
void sbt_thread_exit( ){
 pthread_exit(((void *)0));
}

canonical_original_code:
void sbt_thread_exit(){
 pthread_exit(((void *)0));
}


decompiled_code:
int __fastcall sbt_thread_run(void *(*start_routine)(void *), void *arg, __int16 a3, size_t a4)
{
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-68h] BYREF

pthread_attr_init(&attr);
if ( a4 )
{
pthread_attr_setstacksize(&attr, a4);
if ( a3 != 1 )
goto LABEL_3;
LABEL_6:
pthread_attr_setdetachstate(&attr, 0);
pthread_create(&newthread, &attr, start_routine, arg);
pthread_join(newthread, 0LL);
return pthread_attr_destroy(&attr);
}
pthread_attr_setstacksize(&attr, 0x10000uLL);
if ( a3 == 1 )
goto LABEL_6;
LABEL_3:
pthread_attr_setdetachstate(&attr, 1);
pthread_create(&newthread, &attr, start_routine, arg);
return pthread_attr_destroy(&attr);
}

canonical_decompiled_code:
int __fastcall func6(void *(*start_routine)(void *), void *arg, __int16 a3, size_t a4)
{
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-68h] BYREF

pthread_attr_init(&attr);
if ( a4 )
{
pthread_attr_setstacksize(&attr, a4);
if ( a3 != 1 )
goto LABEL_3;
LABEL_6:
pthread_attr_setdetachstate(&attr, 0);
pthread_create(&newthread, &attr, start_routine, arg);
pthread_join(newthread, 0LL);
return pthread_attr_destroy(&attr);
}
pthread_attr_setstacksize(&attr, 0x10000uLL);
if ( a3 == 1 )
goto LABEL_6;
LABEL_3:
pthread_attr_setdetachstate(&attr, 1);
pthread_create(&newthread, &attr, start_routine, arg);
return pthread_attr_destroy(&attr);
}

original_code:
void sbt_thread_run( const void* func, const void* f_arg, short int join_flg, long int stk_size){
    pthread_t thread;
 pthread_attr_t attr;
 pthread_attr_init(&attr);
 if(0==stk_size){
  pthread_attr_setstacksize( &attr, 64 * 1024 );
 }else{
  pthread_attr_setstacksize( &attr, stk_size );
 }
 if(1==join_flg){
  pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE );
 }else{
  pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
 }
 pthread_create( &thread, &attr, (void*)func, (void*)f_arg );
 if(1==join_flg){
  pthread_join( thread, ((void *)0) );
 }
 pthread_attr_destroy(&attr);
 return;
}

canonical_original_code:
void sbt_thread_run(void *func, void *f_arg, short join_flg, long stk_size){
    unsigned long thread;
 union pthread_attr_t attr;
 pthread_attr_init(&attr);
 if(0==stk_size){
  pthread_attr_setstacksize( &attr, 64 * 1024 );
 }else{
  pthread_attr_setstacksize( &attr, stk_size );
 }
 if(1==join_flg){
  pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE );
 }else{
  pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
 }
 pthread_create( &thread, &attr, (void *)func, (void *)f_arg );
 if(1==join_flg){
  pthread_join( thread, ((void *)0) );
 }
 pthread_attr_destroy(&attr);
 return;
}

variable_types:
func
void *

user_defined_types: union pthread_attr_t { char __size[56]; long __align; }


decompiled_code:
__int64 sbt_thread_test_join()
{
pthread_t v0; // rbx
unsigned int v1; // eax
unsigned int v2; // eax
int arg[3]; // [rsp+Ch] [rbp-Ch] BYREF

arg[0] = 6;
v0 = pthread_self();
v1 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sbt_thread_test_join", 136LL, v1, "Start (main threadID=0x%x)", v0);
sbt_thread_run(sub_thread_join, arg, 1, 0LL);
v2 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sbt_thread_test_join", 142LL, v2, "End (main threadID=0x%x)", v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
pthread_t v0; // rbx
unsigned int v1; // eax
unsigned int v2; // eax
int arg[3]; // [rsp+Ch] [rbp-Ch] BYREF

arg[0] = 6;
v0 = pthread_self();
v1 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sbt_thread_test_join", 136LL, v1, "Start (main threadID=0x%x)", v0);
func6(sub_thread_join, arg, 1, 0LL);
v2 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sbt_thread_test_join", 142LL, v2, "End (main threadID=0x%x)", v0);
return 0LL;
}

original_code:
int sbt_thread_test_join(){
 int loop_cnt = 6;
 pthread_t tid = pthread_self();
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 136, getpid(), "Start (main threadID=0x%x)", tid);
 sbt_thread_run( (const void*)sub_thread_join,
     (const void*)&loop_cnt ,
     1,
     0);
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 142, getpid(), "End (main threadID=0x%x)", tid);
 return 0;
}

canonical_original_code:
int sbt_thread_test_join(){
 int loop_cnt = 6;
 unsigned long tid = pthread_self();
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 136, getpid(), "Start (main threadID=0x%x)", tid);
 sbt_thread_run( (void *)sub_thread_join,
     (void *)&loop_cnt ,
     1,
     0);
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 142, getpid(), "End (main threadID=0x%x)", tid);
 return 0;
}


decompiled_code:
void __noreturn sbt_thread_test_detatch()
{
pthread_t v0; // rbx
unsigned int v1; // eax
_QWORD *v2; // rbp
unsigned int v3; // eax

v0 = pthread_self();
v1 = getpid();
sbt_logln_tofd(
stderr,
"D",
"src/sbt_thread.c",
"sbt_thread_test_detatch",
152LL,
v1,
"Start (main threadID=0x%x)",
v0);
v2 = malloc(8uLL);
*v2 = 0x403020100000004LL;
sbt_thread_run(sub_thread_detach, v2, 0, 0LL);
free(v2);
v3 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sbt_thread_test_detatch", 165LL, v3, "End (main threadID=0x%x)", v0);
sbt_thread_exit();
}

canonical_decompiled_code:
void __noreturn func8()
{
pthread_t v0; // rbx
unsigned int v1; // eax
_QWORD *v2; // rbp
unsigned int v3; // eax

v0 = pthread_self();
v1 = getpid();
sbt_logln_tofd(
stderr,
"D",
"src/sbt_thread.c",
"sbt_thread_test_detatch",
152LL,
v1,
"Start (main threadID=0x%x)",
v0);
v2 = malloc(8uLL);
*v2 = 0x403020100000004LL;
func6(sub_thread_detach, v2, 0, 0LL);
free(v2);
v3 = getpid();
sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", "sbt_thread_test_detatch", 165LL, v3, "End (main threadID=0x%x)", v0);
func5();
}

original_code:
int sbt_thread_test_detatch(){
 test_thread_func_st* st_thread_func = ((void *)0);
 pthread_t tid = pthread_self();
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 152, getpid(), "Start (main threadID=0x%x)", tid);
    st_thread_func = (test_thread_func_st*)malloc( sizeof(test_thread_func_st) );
 st_thread_func->size = 4;
 st_thread_func->buf[0] = 1;
 st_thread_func->buf[1] = 2;
 st_thread_func->buf[2] = 3;
 st_thread_func->buf[3] = 4;
 sbt_thread_run( (const void*)sub_thread_detach,
     (const void*)st_thread_func,
     0,
     0);
 free(st_thread_func);
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 165, getpid(), "End (main threadID=0x%x)", tid);
 sbt_thread_exit();
 return 0;
}

canonical_original_code:
int sbt_thread_test_detatch(){
 struct _test_thread_func_st *st_thread_func = ((void *)0);
 unsigned long tid = pthread_self();
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 152, getpid(), "Start (main threadID=0x%x)", tid);
    st_thread_func = (struct _test_thread_func_st *)malloc( sizeof(test_thread_func_st) );
 st_thread_func->size = 4;
 st_thread_func->buf[0] = 1;
 st_thread_func->buf[1] = 2;
 st_thread_func->buf[2] = 3;
 st_thread_func->buf[3] = 4;
 sbt_thread_run( (void *)sub_thread_detach,
     (void *)st_thread_func,
     0,
     0);
 free(st_thread_func);
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 165, getpid(), "End (main threadID=0x%x)", tid);
 sbt_thread_exit();
 return 0;
}

user_defined_types: struct _test_thread_func_st { int size; char buf[4]; }


decompiled_code:
__int64 sbt_thread_test_exclusive()
{
pthread_t v0; // rbx
unsigned int v1; // eax
unsigned int v2; // eax
int arg[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = pthread_self();
v1 = getpid();
sbt_logln_tofd(
stderr,
"D",
"src/sbt_thread.c",
"sbt_thread_test_exclusive",
177LL,
v1,
"Start (main threadID=0x%x)",
v0);
arg[0] = 0;
do
{
sbt_thread_run(sub_thread_exclusive, arg, 1, 0LL);
++arg[0];
}
while ( arg[0] <= 2 );
v2 = getpid();
sbt_logln_tofd(
stderr,
"D",
"src/sbt_thread.c",
"sbt_thread_test_exclusive",
185LL,
v2,
"End (main threadID=0x%x)",
v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
pthread_t v0; // rbx
unsigned int v1; // eax
unsigned int v2; // eax
int arg[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = pthread_self();
v1 = getpid();
sbt_logln_tofd(
stderr,
"D",
"src/sbt_thread.c",
"sbt_thread_test_exclusive",
177LL,
v1,
"Start (main threadID=0x%x)",
v0);
arg[0] = 0;
do
{
func6(sub_thread_exclusive, arg, 1, 0LL);
++arg[0];
}
while ( arg[0] <= 2 );
v2 = getpid();
sbt_logln_tofd(
stderr,
"D",
"src/sbt_thread.c",
"sbt_thread_test_exclusive",
185LL,
v2,
"End (main threadID=0x%x)",
v0);
return 0LL;
}

original_code:
int sbt_thread_test_exclusive(){
 int i = 0;
 pthread_t tid = pthread_self();
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 177, getpid(), "Start (main threadID=0x%x)", tid);
    for(i=0; i<3; i++){
     sbt_thread_run( (const void*)sub_thread_exclusive,
         (const void*)&i ,
         1,
         0);
    }
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 185, getpid(), "End (main threadID=0x%x)", tid);
 return 0;
}

canonical_original_code:
int sbt_thread_test_exclusive(){
 int i = 0;
 unsigned long tid = pthread_self();
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 177, getpid(), "Start (main threadID=0x%x)", tid);
    for(i=0; i<3; i++){
     sbt_thread_run( (void *)sub_thread_exclusive,
         (void *)&i ,
         1,
         0);
    }
 sbt_logln_tofd(stderr, "D", "src/sbt_thread.c", __func__, 185, getpid(), "End (main threadID=0x%x)", tid);
 return 0;
}


decompiled_code:
__int64 __fastcall load_plugin(char *file, int mode)
{
void *v2; // rax
__int64 (__fastcall *v3)(_QWORD); // rax
__int64 v4; // rbp
__int64 result; // rax
char *v6; // rax

printf("%s %s -- start\n", "plugin_manager.c", "load_plugin");
v2 = dlopen(file, mode);
if ( v2 && (v3 = (__int64 (__fastcall *)(_QWORD))dlsym(v2, "plugin_init")) != 0LL )
{
v4 = v3(0LL);
printf("%s %s -- end\n", "plugin_manager.c", "load_plugin");
result = v4;
}
else
{
v6 = dlerror();
fprintf(stderr, "%s\n", v6);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *file, int mode)
{
void *v2; // rax
__int64 (__fastcall *v3)(_QWORD); // rax
__int64 v4; // rbp
__int64 result; // rax
char *v6; // rax

printf("%s %s -- start\n", "plugin_manager.c", "load_plugin");
v2 = dlopen(file, mode);
if ( v2 && (v3 = (__int64 (__fastcall *)(_QWORD))dlsym(v2, "plugin_init")) != 0LL )
{
v4 = v3(0LL);
printf("%s %s -- end\n", "plugin_manager.c", "load_plugin");
result = v4;
}
else
{
v6 = dlerror();
fprintf(stderr, "%s\n", v6);
result = 0LL;
}
return result;
}

original_code:
plugin_manage_st load_plugin(char* name, int mode){
 void* handle = ((void *)0);
 plugin_info_st* (*function)(char*);
 plugin_manage_st plugin = {0x00};
 printf("%s %s -- start\n","plugin_manager.c",__func__);
 handle = (void*)dlopen( name, mode );
 if(!handle){
  fprintf(stderr, "%s\n",dlerror());
  return plugin;
 }
 function = dlsym(handle, "plugin_init");
 if( ((void *)0)==function ){
  fprintf(stderr, "%s\n", dlerror());
  return plugin;
 }
 plugin.p_plugin_info = (*function)(((void *)0));
 plugin.p_plugin_handle = handle;
 printf("%s %s -- end\n","plugin_manager.c",__func__);
 return plugin;
}

canonical_original_code:
struct plugin_manage load_plugin(char *name, int mode){
 void *handle = ((void *)0);
 struct plugin_info *(*function)(char *);
 struct plugin_manage plugin = {0x00};
 printf("%s %s -- start\n","plugin_manager.c",__func__);
 handle = (void *)dlopen( name, mode );
 if(!handle){
  fprintf(stderr, "%s\n",dlerror());
  return plugin;
 }
 function = dlsym(handle, "plugin_init");
 if( ((void *)0)==function ){
  fprintf(stderr, "%s\n", dlerror());
  return plugin;
 }
 plugin.p_plugin_info = (*function)(((void *)0));
 plugin.p_plugin_handle = handle;
 printf("%s %s -- end\n","plugin_manager.c",__func__);
 return plugin;
}

variable_types:
name
char *

variable_types: mode int

variable_types:
handle
void *

variable_types: struct plugin_info { char *name; struct func_pointer { void (*func_a)(int); int (*func_b)(char); int (*func_c)(int, char); int (*func_d)(struct arg_set { int aa; char bb; } *); } fp; } *(*)(char *)

variable_types: struct plugin_manage { struct plugin_info { char *name; struct func_pointer { void (*func_a)(int); int (*func_b)(char); int (*func_c)(int, char); int (*func_d)(struct arg_set { int aa; char bb; } *); } fp; } *p_plugin_info; void *p_plugin_handle; }

user_defined_types: struct plugin_manage { struct plugin_info *p_plugin_info; void *p_plugin_handle; }


decompiled_code:
__int64 __fastcall unload_plugin(void *handle)
{
void (__fastcall *v1)(_QWORD); // rax
__int64 result; // rax
char *v3; // rax

printf("%s %s -- start\n", "plugin_manager.c", "unload_plugin");
v1 = (void (__fastcall *)(_QWORD))dlsym(handle, "plugin_desc");
if ( v1 )
{
v1(0LL);
dlclose(handle);
printf("%s %s -- end\n", "plugin_manager.c", "unload_plugin");
result = 0LL;
}
else
{
v3 = dlerror();
fprintf(stderr, "%s\n", v3);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *handle)
{
void (__fastcall *v1)(_QWORD); // rax
__int64 result; // rax
char *v3; // rax

printf("%s %s -- start\n", "plugin_manager.c", "unload_plugin");
v1 = (void (__fastcall *)(_QWORD))dlsym(handle, "plugin_desc");
if ( v1 )
{
v1(0LL);
dlclose(handle);
printf("%s %s -- end\n", "plugin_manager.c", "unload_plugin");
result = 0LL;
}
else
{
v3 = dlerror();
fprintf(stderr, "%s\n", v3);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int unload_plugin(void* handle){
 int (*function)(char*);
 printf("%s %s -- start\n","plugin_manager.c",__func__);
 function = dlsym(handle, "plugin_desc");
 if( ((void *)0)==function ){
  fprintf(stderr, "%s\n", dlerror());
  return -1;
 }
 (*function)(((void *)0));
 dlclose(handle);
 printf("%s %s -- end\n","plugin_manager.c",__func__);
 return 0;
}

canonical_original_code:
int unload_plugin(void *handle){
 int (*function)(char *);
 printf("%s %s -- start\n","plugin_manager.c",__func__);
 function = dlsym(handle, "plugin_desc");
 if( ((void *)0)==function ){
  fprintf(stderr, "%s\n", dlerror());
  return -1;
 }
 (*function)(((void *)0));
 dlclose(handle);
 printf("%s %s -- end\n","plugin_manager.c",__func__);
 return 0;
}

variable_types:
function
int (*)(char *)


decompiled_code:
__int64 plugin_manager_main()
{
__int64 v0; // rdx
__int64 v1; // rax
__int64 v2; // rdx

printf("%s %s -- start\n", "plugin_manager.c", "plugin_manager_main");
g_plugin_manage = load_plugin("./plugin_dynamic_matsu.so", 1);
*(&g_plugin_manage + 1) = v0;
*(&g_plugin_manage + 2) = load_plugin("./plugin_dynamic_take.so", 1);
v1 = g_plugin_manage;
*(&g_plugin_manage + 3) = v2;
(*(void (__fastcall **)(__int64))(v1 + 8))(1LL);
(*(void (__fastcall **)(__int64))(*(&g_plugin_manage + 2) + 8))(1LL);
unload_plugin((void *)*(&g_plugin_manage + 1));
unload_plugin((void *)*(&g_plugin_manage + 3));
printf("%s %s -- end\n", "plugin_manager.c", "plugin_manager_main");
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rdx
__int64 v1; // rax
__int64 v2; // rdx

printf("%s %s -- start\n", "plugin_manager.c", "plugin_manager_main");
g_plugin_manage = func0("./plugin_dynamic_matsu.so", 1);
*(&g_plugin_manage + 1) = v0;
*(&g_plugin_manage + 2) = func0("./plugin_dynamic_take.so", 1);
v1 = g_plugin_manage;
*(&g_plugin_manage + 3) = v2;
(*(void (__fastcall **)(__int64))(v1 + 8))(1LL);
(*(void (__fastcall **)(__int64))(*(&g_plugin_manage + 2) + 8))(1LL);
func1((void *)*(&g_plugin_manage + 1));
func1((void *)*(&g_plugin_manage + 3));
printf("%s %s -- end\n", "plugin_manager.c", "plugin_manager_main");
return 0LL;
}

original_code:
int plugin_manager_main(){
 printf("%s %s -- start\n","plugin_manager.c",__func__);
 g_plugin_manage[0] = load_plugin("./plugin_dynamic_matsu.so", 0x00001);
 g_plugin_manage[1] = load_plugin("./plugin_dynamic_take.so", 0x00001);
 g_plugin_manage[0].p_plugin_info->fp.func_a(1);
 g_plugin_manage[1].p_plugin_info->fp.func_a(1);
 unload_plugin(g_plugin_manage[0].p_plugin_handle);
 unload_plugin(g_plugin_manage[1].p_plugin_handle);
 printf("%s %s -- end\n","plugin_manager.c",__func__);
 return 0;
}


decompiled_code:
__int64 sbt_file_test()
{
int v0; // ebp
const char *v1; // rbx
__int64 result; // rax
__int64 v3; // rbp
unsigned int v4; // eax
__int64 v5; // [rsp-10h] [rbp-28h]
const char *v6; // [rsp-8h] [rbp-20h]

v0 = get_file_num("src/");
v1 = (const char *)malloc(100LL * v0);
result = get_file_name_list("src/", (__int64)v1);
if ( v0 > 0 )
{
v3 = (__int64)&v1[100 * (v0 - 1) + 100];
do
{
v4 = getpid();
v6 = v1;
v1 += 100;
sbt_logln_tofd(stderr, "D", "src/sbt_file.c", "sbt_file_test", 77LL, v4, "file name=%s", v6);
result = v5;
}
while ( v1 != (const char *)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // ebp
const char *v1; // rbx
__int64 result; // rax
__int64 v3; // rbp
unsigned int v4; // eax
__int64 v5; // [rsp-10h] [rbp-28h]
const char *v6; // [rsp-8h] [rbp-20h]

v0 = func0("src/");
v1 = (const char *)malloc(100LL * v0);
result = func1("src/", (__int64)v1);
if ( v0 > 0 )
{
v3 = (__int64)&v1[100 * (v0 - 1) + 100];
do
{
v4 = getpid();
v6 = v1;
v1 += 100;
sbt_logln_tofd(stderr, "D", "src/sbt_file.c", "sbt_file_test", 77LL, v4, "file name=%s", v6);
result = v5;
}
while ( v1 != (const char *)v3 );
}
return result;
}

original_code:
void sbt_file_test(){
 int file_num = 0;
 files_st* p_file_list;
 int i;
 file_num = get_file_num("src/");
 p_file_list = (files_st*)malloc( sizeof(files_st)*file_num );
 get_file_name_list( "src/", p_file_list );
 for( i=0;i<file_num;i++ ){
  sbt_logln_tofd(stderr, "D", "src/sbt_file.c", __func__, 77, getpid(), "file name=%s", p_file_list[i].name);
 }
}

canonical_original_code:
void sbt_file_test(){
 int file_num = 0;
 struct files *p_file_list;
 int i;
 file_num = get_file_num("src/");
 p_file_list = (struct files *)malloc( sizeof(files_st)*file_num );
 get_file_name_list( "src/", p_file_list );
 for( i=0;i<file_num;i++ ){
  sbt_logln_tofd(stderr, "D", "src/sbt_file.c", __func__, 77, getpid(), "file name=%s", p_file_list[i].name);
 }
}


decompiled_code:
int log_debug(const char *a1, __int64 a2, const char *a3, unsigned int a4, unsigned int a5, const char *a6, ...)
{
__int64 v6; // r14
__int64 v7; // r13
struct tm *v10; // rax
time_t v12; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a6);
v6 = a5;
v7 = a4;
time(&v12);
v10 = localtime(&v12);
fprintf(
_bss_start,
"%02d-%02d %02d:%02d:%02d %s/%s(%d)[%d]: ",
(unsigned int)(v10->tm_mon + 1),
(unsigned int)v10->tm_mday,
(unsigned int)v10->tm_hour,
(unsigned int)v10->tm_min,
(unsigned int)v10->tm_sec,
a1,
a3,
v7,
v6);
vfprintf(_bss_start, a6, arg);
return fputc(10, _bss_start);
}

canonical_decompiled_code:
int func9(const char *a1, __int64 a2, const char *a3, unsigned int a4, unsigned int a5, const char *a6, ...)
{
__int64 v6; // r14
__int64 v7; // r13
struct tm *v10; // rax
time_t v12; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a6);
v6 = a5;
v7 = a4;
time(&v12);
v10 = localtime(&v12);
fprintf(
_bss_start,
"%02d-%02d %02d:%02d:%02d %s/%s(%d)[%d]: ",
(unsigned int)(v10->tm_mon + 1),
(unsigned int)v10->tm_mday,
(unsigned int)v10->tm_hour,
(unsigned int)v10->tm_min,
(unsigned int)v10->tm_sec,
a1,
a3,
v7,
v6);
vfprintf(_bss_start, a6, arg);
return fputc(10, _bss_start);
}

original_code:
void log_debug(const char* level, const char* file_name, const char* func_name, int line_no, int pid, const char* format, ...){
 va_list va_args;
 time_t timer;
 struct tm *t_st;
 time(&timer);
 t_st = localtime(&timer);
 fprintf( stderr, "%02d-%02d %02d:%02d:%02d %s/%s(%d)[%d]: ",
    t_st->tm_mon+1,
    t_st->tm_mday,
    t_st->tm_hour,
    t_st->tm_min,
    t_st->tm_sec,
    level,
    func_name,
    line_no,
    pid );
 __builtin_va_start(va_args,format);
 vfprintf(stderr, format, va_args);
 __builtin_va_end(va_args);
 fprintf( stderr, "\n");
}

canonical_original_code:
void log_debug(char *level, char *file_name, char *func_name, int line_no, int pid, char *format, ...){
 __builtin_va_list va_args;
 long timer;
 struct tm *t_st;
 time(&timer);
 t_st = localtime(&timer);
 fprintf( stderr, "%02d-%02d %02d:%02d:%02d %s/%s(%d)[%d]: ",
    t_st->tm_mon+1,
    t_st->tm_mday,
    t_st->tm_hour,
    t_st->tm_min,
    t_st->tm_sec,
    level,
    func_name,
    line_no,
    pid );
 __builtin_va_start(va_args,format);
 vfprintf(stderr, format, va_args);
 __builtin_va_end(va_args);
 fprintf( stderr, "\n");
}

variable_types:
level
char *

variable_types: pid int

variable_types:
format
char *

variable_types: timer long

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


decompiled_code:
int __fastcall log_dump(__int64 a1, int a2, __int64 a3)
{
int v3; // er15
int v4; // er13
int v5; // er14
__int64 v6; // rbp
int v7; // er12
__int64 v8; // rbx
__int64 v9; // rdx
int result; // eax

v3 = a3;
v4 = a2;
v5 = a3 + 1 - a2;
fprintf(_bss_start, "end_index=%d\n", a3);
v6 = a2 + a1;
do
{
if ( v3 > v4 + 15 )
{
v7 = 16;
}
else
{
v7 = v5;
if ( v5 <= 0 )
goto LABEL_6;
}
v8 = 0LL;
do
{
v9 = (unsigned int)*(char *)(v6 + v8++);
fprintf(_bss_start, "%02x", v9);
}
while ( v7 > (int)v8 );
LABEL_6:
v4 += 16;
v5 -= 16;
v6 += 16LL;
result = fputc(10, _bss_start);
}
while ( v3 >= v4 );
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, int a2, __int64 a3)
{
int v3; // er15
int v4; // er13
int v5; // er14
__int64 v6; // rbp
int v7; // er12
__int64 v8; // rbx
__int64 v9; // rdx
int result; // eax

v3 = a3;
v4 = a2;
v5 = a3 + 1 - a2;
fprintf(_bss_start, "end_index=%d\n", a3);
v6 = a2 + a1;
do
{
if ( v3 > v4 + 15 )
{
v7 = 16;
}
else
{
v7 = v5;
if ( v5 <= 0 )
goto LABEL_6;
}
v8 = 0LL;
do
{
v9 = (unsigned int)*(char *)(v6 + v8++);
fprintf(_bss_start, "%02x", v9);
}
while ( v7 > (int)v8 );
LABEL_6:
v4 += 16;
v5 -= 16;
v6 += 16LL;
result = fputc(10, _bss_start);
}
while ( v3 >= v4 );
return result;
}

original_code:
void log_dump( char* buf, int start_index, int end_index ){
 int dump_index = start_index;
 int dump_num = 0;
 int i = 0;
 fprintf(stderr, "end_index=%d\n", end_index);
 do{
  if( (end_index+1)<=dump_index+16 ){
   dump_num = end_index-dump_index+1;
  }else{
   dump_num = 16;
  }
  for(i=0; i<dump_num; i++){
   fprintf(stderr, "%02x", buf[dump_index+i]);
  }
  fprintf(stderr, "\n");
  dump_index += 16;
 }while( dump_index<=end_index );
}

canonical_original_code:
void log_dump(char *buf, int start_index, int end_index){
 int dump_index = start_index;
 int dump_num = 0;
 int i = 0;
 fprintf(stderr, "end_index=%d\n", end_index);
 do{
  if( (end_index+1)<=dump_index+16 ){
   dump_num = end_index-dump_index+1;
  }else{
   dump_num = 16;
  }
  for(i=0; i<dump_num; i++){
   fprintf(stderr, "%02x", buf[dump_index+i]);
  }
  fprintf(stderr, "\n");
  dump_index += 16;
 }while( dump_index<=end_index );
}

variable_types:
buf
char *


decompiled_code:
int log_debug(const char *a1, __int64 a2, const char *a3, unsigned int a4, unsigned int a5, const char *a6, ...)
{
__int64 v6; // r14
__int64 v7; // r13
struct tm *v10; // rax
time_t v12; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a6);
v6 = a5;
v7 = a4;
time(&v12);
v10 = localtime(&v12);
fprintf(
stderr,
"%02d-%02d %02d:%02d:%02d %s/%s(%d)[%d]: ",
(unsigned int)(v10->tm_mon + 1),
(unsigned int)v10->tm_mday,
(unsigned int)v10->tm_hour,
(unsigned int)v10->tm_min,
(unsigned int)v10->tm_sec,
a1,
a3,
v7,
v6);
vfprintf(stderr, a6, arg);
return fputc(10, stderr);
}

canonical_decompiled_code:
int func8(const char *a1, __int64 a2, const char *a3, unsigned int a4, unsigned int a5, const char *a6, ...)
{
__int64 v6; // r14
__int64 v7; // r13
struct tm *v10; // rax
time_t v12; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a6);
v6 = a5;
v7 = a4;
time(&v12);
v10 = localtime(&v12);
fprintf(
stderr,
"%02d-%02d %02d:%02d:%02d %s/%s(%d)[%d]: ",
(unsigned int)(v10->tm_mon + 1),
(unsigned int)v10->tm_mday,
(unsigned int)v10->tm_hour,
(unsigned int)v10->tm_min,
(unsigned int)v10->tm_sec,
a1,
a3,
v7,
v6);
vfprintf(stderr, a6, arg);
return fputc(10, stderr);
}

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


decompiled_code:
int __fastcall log_dump(__int64 a1, int a2, __int64 a3)
{
int v3; // er15
int v4; // er13
int v5; // er14
__int64 v6; // rbp
int v7; // er12
__int64 v8; // rbx
__int64 v9; // rdx
int result; // eax

v3 = a3;
v4 = a2;
v5 = a3 + 1 - a2;
fprintf(stderr, "end_index=%d\n", a3);
v6 = a2 + a1;
do
{
if ( v3 > v4 + 15 )
{
v7 = 16;
}
else
{
v7 = v5;
if ( v5 <= 0 )
goto LABEL_6;
}
v8 = 0LL;
do
{
v9 = (unsigned int)*(char *)(v6 + v8++);
fprintf(stderr, "%02x", v9);
}
while ( v7 > (int)v8 );
LABEL_6:
v4 += 16;
v5 -= 16;
v6 += 16LL;
result = fputc(10, stderr);
}
while ( v3 >= v4 );
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, int a2, __int64 a3)
{
int v3; // er15
int v4; // er13
int v5; // er14
__int64 v6; // rbp
int v7; // er12
__int64 v8; // rbx
__int64 v9; // rdx
int result; // eax

v3 = a3;
v4 = a2;
v5 = a3 + 1 - a2;
fprintf(stderr, "end_index=%d\n", a3);
v6 = a2 + a1;
do
{
if ( v3 > v4 + 15 )
{
v7 = 16;
}
else
{
v7 = v5;
if ( v5 <= 0 )
goto LABEL_6;
}
v8 = 0LL;
do
{
v9 = (unsigned int)*(char *)(v6 + v8++);
fprintf(stderr, "%02x", v9);
}
while ( v7 > (int)v8 );
LABEL_6:
v4 += 16;
v5 -= 16;
v6 += 16LL;
result = fputc(10, stderr);
}
while ( v3 >= v4 );
return result;
}


decompiled_code:
float __fastcall lp_filter(float a1, float a2, float a3)
{
return (float)((float)(1.0 - a3) * a2) + (float)(a3 * a1);
}

canonical_decompiled_code:
float __fastcall func0(float a1, float a2, float a3)
{
return (float)((float)(1.0 - a3) * a2) + (float)(a3 * a1);
}

original_code:
static inline float lp_filter(float a, float b, float d)
{
    return d*a + (1-d)*b;
}

variable_types: a float

variable_types: b float

variable_types: d float

return_type: float


decompiled_code:
__int64 compute_initial_orientation()
{
int v0; // xmm0_4
__int64 v1; // rax
int v2; // xmm0_4
double v3; // xmm0_8
__int64 result; // rax
__int64 v5; // [rsp+Ch] [rbp-4Ch] BYREF
int v6; // [rsp+14h] [rbp-44h]
__int64 v7; // [rsp+18h] [rbp-40h] BYREF
int v8; // [rsp+20h] [rbp-38h]
__int64 v9; // [rsp+24h] [rbp-34h] BYREF
int v10; // [rsp+2Ch] [rbp-2Ch]
int v11[4]; // [rsp+30h] [rbp-28h] BYREF
char v12[24]; // [rsp+40h] [rbp-18h] BYREF

v0 = DWORD2(xmmword_FC0);
v10 = 1065353216;
v5 = xmmword_FC0;
v1 = *((_QWORD *)&xmmword_FC0 + 3);
v6 = v0;
v2 = *((_DWORD *)&xmmword_FC0 + 8);
v7 = v1;
v8 = v2;
v9 = 0LL;
normalize(&v5);
normalize(&v7);
vec2vec2quat(v11, &v5, &v9);
rotvecquat(&v7, v11);
v8 = 0;
normalize(&v7);
v3 = atan2(*((float *)&v7 + 1), *(float *)&v7);
*(float *)&v3 = v3;
angvec2quat(v12, &v9, COERCE_DOUBLE(*(_QWORD *)&v3 ^ LC2));
result = quatmult2(v12, v11);
q0 = v11[0];
q1 = v11[1];
q2 = v11[2];
q3 = v11[3];
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // xmm0_4
__int64 v1; // rax
int v2; // xmm0_4
double v3; // xmm0_8
__int64 result; // rax
__int64 v5; // [rsp+Ch] [rbp-4Ch] BYREF
int v6; // [rsp+14h] [rbp-44h]
__int64 v7; // [rsp+18h] [rbp-40h] BYREF
int v8; // [rsp+20h] [rbp-38h]
__int64 v9; // [rsp+24h] [rbp-34h] BYREF
int v10; // [rsp+2Ch] [rbp-2Ch]
int v11[4]; // [rsp+30h] [rbp-28h] BYREF
char v12[24]; // [rsp+40h] [rbp-18h] BYREF

v0 = DWORD2(xmmword_FC0);
v10 = 1065353216;
v5 = xmmword_FC0;
v1 = *((_QWORD *)&xmmword_FC0 + 3);
v6 = v0;
v2 = *((_DWORD *)&xmmword_FC0 + 8);
v7 = v1;
v8 = v2;
v9 = 0LL;
normalize(&v5);
normalize(&v7);
vec2vec2quat(v11, &v5, &v9);
rotvecquat(&v7, v11);
v8 = 0;
normalize(&v7);
v3 = atan2(*((float *)&v7 + 1), *(float *)&v7);
*(float *)&v3 = v3;
angvec2quat(v12, &v9, COERCE_DOUBLE(*(_QWORD *)&v3 ^ LC2));
result = quatmult2(v12, v11);
q0 = v11[0];
q1 = v11[1];
q2 = v11[2];
q3 = v11[3];
return result;
}

original_code:
static void compute_initial_orientation()
{
    float q[4], a[3] = {of[0], of[1], of[2]}, m[3] = {of[6], of[7], of[8]};
    float g[3] = {0, 0, 1};
    normalize(a);
    normalize(m);
    vec2vec2quat(q, a, g);
    rotvecquat(m, q);
    m[2] = 0;
    normalize(m);
    float r[4];
    angvec2quat(r, -atan2(m[1], m[0]), g);
    quatmult2(r, q);
    q0 = q[0], q1 = q[1], q2 = q[2], q3 = q[3];
}

canonical_original_code:
static void compute_initial_orientation()
{
    float q[4]; float a[3] = {of[0], of[1], of[2]}; float m[3] = {of[6], of[7], of[8]};
    float g[3] = {0, 0, 1};
    normalize(a);
    normalize(m);
    vec2vec2quat(q, a, g);
    rotvecquat(m, q);
    m[2] = 0;
    normalize(m);
    float r[4];
    angvec2quat(r, -atan2(m[1], m[0]), g);
    quatmult2(r, q);
    q0 = q[0], q1 = q[1], q2 = q[2], q3 = q[3];
}

variable_types:
q
float [4]

variable_types:
a
float [3]

variable_types:
m
float [3]

variable_types:
g
float [3]

variable_types:
r
float [4]


decompiled_code:
ssize_t __fastcall i2c_read(char a1, int a2)
{
buf = a1;
write(file, &buf, 1uLL);
return read(file, &buf, a2);
}

canonical_decompiled_code:
ssize_t __fastcall func2(char a1, int a2)
{
buf = a1;
write(file, &buf, 1uLL);
return read(file, &buf, a2);
}

original_code:
void i2c_read(uint8_t addr, int len)
{
    buf[0] = addr;
    write(file, buf, 1);
    read(file, buf, len);
}

canonical_original_code:
void i2c_read(unsigned char addr, int len)
{
    buf[0] = addr;
    write(file, buf, 1);
    read(file, buf, len);
}

variable_types:
addr
unsigned char

variable_types: len int


decompiled_code:
ssize_t __fastcall i2c_write_byte(char a1, char a2)
{
int v2; // edi

buf[0] = a1;
v2 = file;
buf[1] = a2;
return write(v2, buf, 2uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func3(char a1, char a2)
{
int v2; // edi

buf[0] = a1;
v2 = file;
buf[1] = a2;
return write(v2, buf, 2uLL);
}

original_code:
void i2c_write_byte(uint8_t addr, uint8_t value)
{
    buf[0] = addr;
    buf[1] = value;
    write(file, buf, 2);
}

canonical_original_code:
void i2c_write_byte(unsigned char addr, unsigned char value)
{
    buf[0] = addr;
    buf[1] = value;
    write(file, buf, 2);
}

variable_types:
value
unsigned char


decompiled_code:
void read_sensors()
{
int v0; // edx
__int64 i; // rax
unsigned __int64 k; // rax
__int64 v3; // rcx
float v4; // xmm2_4
__int64 j; // rax
int v6[6]; // [rsp+0h] [rbp-2Ch]
__int64 v7; // [rsp+18h] [rbp-14h]
int v8; // [rsp+20h] [rbp-Ch]

if ( file != -1 )
{
if ( ioctl(file, 0x703uLL, 64LL) < 0 )
{
fwrite("Failed to aquire bus address\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
i2c_read(2, 6);
v0 = (unsigned __int8)buf[0];
if ( (buf[0] & 1) != 0 && (buf[2] & 1) != 0 && (buf[4] & 1) != 0 )
{
for ( i = 0LL; ; v0 = (unsigned __int8)buf[2 * i] )
{
*((float *)&dof + i) = (float)((float)((buf[2 * i + 1] << 8) + v0) * 0.000061035156) + *((float *)&dof + i);
*((float *)&cof + i) = *((float *)&cof + i) + 1.0;
if ( ++i == 3 )
break;
}
}
else
{
fwrite("accel miss\n", 1uLL, 0xBuLL, stderr);
}
if ( ioctl(file, 0x703uLL, 104LL) < 0 )
{
fwrite("Failed to aquire bus address\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
i2c_read(26, 1);
if ( (buf[0] & 1) != 0 )
{
i2c_read(29, 6);
v4 = *(float *)&gyro_scale;
for ( j = 0LL; j != 3; ++j )
{
*((float *)&dof + j + 3) = (float)((float)((unsigned __int8)buf[2 * j + 1] + (buf[2 * j] << 8)) / v4)
+ *((float *)&dof + j + 3);
*((float *)&cof + j + 3) = *((float *)&cof + j + 3) + 1.0;
}
}
else
{
fwrite("gyro miss\n", 1uLL, 0xAuLL, stderr);
}
if ( ioctl(file, 0x703uLL, 30LL) < 0 )
{
fwrite("Failed to aquire bus address\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
i2c_read(9, 1);
if ( (buf[0] & 1) != 0 )
{
i2c_read(3, 6);
for ( k = 24LL; k != 36; *(float *)((char *)&cof + k - 4) = *(float *)((char *)&cof + k - 4) + 1.0 )
{
v7 = 0x400000000LL;
v8 = 2;
v3 = v6[k / 4];
k += 4LL;
*(float *)((char *)&dof + k - 4) = (float)((float)((buf[v3] << 8) + (unsigned __int8)buf[(int)v3 + 1])
* 0.001953125)
+ *(float *)((char *)&dof + k - 4);
}
}
else
{
fwrite("mag miss\n", 1uLL, 9uLL, stderr);
}
i2c_write_byte(2, 1);
if ( ioctl(file, 0x703uLL, 119LL) != -1 )
{
i2c_read(246, 3);
*((float *)&dof + 9) = (float)((float)(buf[2] + (buf[0] << 24) + (buf[1] << 16)) * 0.000000059604645)
+ *((float *)&dof + 9);
*((float *)&cof + 9) = *((float *)&cof + 9) + 1.0;
i2c_write_byte(244, 244);
}
}
}

original_code:
static void read_sensors()
{
    if(file == -1)
        return;
    if(ioctl(file, 0x0703, 0x40) < 0) {
        fprintf(stderr, "Failed to aquire bus address\n");
        exit(1);
    }
    int i;
    i2c_read(0x02, 6);
    if(buf[0] & 1 && buf[2] & 1 && buf[4] & 1) {
        for(i=0; i<3; i++) {
            dof[i] += (float)(((int16_t)buf[2*i+1]<<8) + (uint8_t)buf[2*i]) / 16384;
            cof[i]++;
        }
    } else
        fprintf(stderr, "accel miss\n");
    if(ioctl(file, 0x0703, 0x68) < 0) {
        fprintf(stderr, "Failed to aquire bus address\n");
        exit(1);
    }
    i2c_read(0x1a, 1);
    if(buf[0] & 1) {
        i2c_read(0x1d, 6);
        for(i=0; i<3; i++) {
            dof[3+i] += (float)(((int16_t)buf[2*i+0]<<8) + (uint8_t)buf[2*i+1]) / gyro_scale;
            cof[3+i]++;
        }
    } else
        fprintf(stderr, "gyro miss\n");
    if(ioctl(file, 0x0703, 0x1e) < 0) {
        fprintf(stderr, "Failed to aquire bus address\n");
        exit(1);
    }
    i2c_read(0x09, 1);
    if(buf[0] & 1) {
        i2c_read(0x03, 6);
        for(i=0; i<3; i++) {
            int ind[3] = {0, 4, 2};
            dof[6+i] += (float)((int)((int16_t)buf[ind[i]]<<8) + (uint8_t)buf[ind[i]+1]) / 512;
            cof[6+i]++;
        }
    } else
        fprintf(stderr, "mag miss\n");
    i2c_write_byte(0x02, 0x01);
    if(ioctl(file, 0x0703, 0x77) != -1) {
        i2c_read(0xf6, 3);
        dof[9] += (float)(((int32_t)buf[0]<<24) +
                          ((int32_t)buf[1]<<16) +
                          ((int32_t)buf[2])) / (1<<24); cof[9]++;
        i2c_write_byte(0xf4, 0xf4);
    }
}

canonical_original_code:
static void read_sensors()
{
    if(file == -1)
        return;
    if(ioctl(file, 0x0703, 0x40) < 0) {
        fprintf(stderr, "Failed to aquire bus address\n");
        exit(1);
    }
    int i;
    i2c_read(0x02, 6);
    if(buf[0] & 1 && buf[2] & 1 && buf[4] & 1) {
        for(i=0; i<3; i++) {
            dof[i] += (float)(((short)buf[2*i+1]<<8) + (unsigned char)buf[2*i]) / 16384;
            cof[i]++;
        }
    } else
        fprintf(stderr, "accel miss\n");
    if(ioctl(file, 0x0703, 0x68) < 0) {
        fprintf(stderr, "Failed to aquire bus address\n");
        exit(1);
    }
    i2c_read(0x1a, 1);
    if(buf[0] & 1) {
        i2c_read(0x1d, 6);
        for(i=0; i<3; i++) {
            dof[3+i] += (float)(((short)buf[2*i+0]<<8) + (unsigned char)buf[2*i+1]) / gyro_scale;
            cof[3+i]++;
        }
    } else
        fprintf(stderr, "gyro miss\n");
    if(ioctl(file, 0x0703, 0x1e) < 0) {
        fprintf(stderr, "Failed to aquire bus address\n");
        exit(1);
    }
    i2c_read(0x09, 1);
    if(buf[0] & 1) {
        i2c_read(0x03, 6);
        for(i=0; i<3; i++) {
            int ind[3] = {0, 4, 2};
            dof[6+i] += (float)((int)((short)buf[ind[i]]<<8) + (unsigned char)buf[ind[i]+1]) / 512;
            cof[6+i]++;
        }
    } else
        fprintf(stderr, "mag miss\n");
    i2c_write_byte(0x02, 0x01);
    if(ioctl(file, 0x0703, 0x77) != -1) {
        i2c_read(0xf6, 3);
        dof[9] += (float)(((int)buf[0]<<24) +
                          ((int)buf[1]<<16) +
                          ((int)buf[2])) / (1<<24); cof[9]++;
        i2c_write_byte(0xf4, 0xf4);
    }
}

variable_types: i int

variable_types:
ind
int [3]


decompiled_code:
int probe_i2c_devices()
{
int result; // eax

if ( !ioctl(file, 0x703uLL, 64LL) )
{
i2c_read(0, 2);
if ( buf[0] == 3 && buf[1] == 20 )
puts("found bma180");
}
if ( !ioctl(file, 0x703uLL, 104LL) )
{
i2c_read(0, 1);
if ( buf[0] == 104 )
{
puts("found itg3200");
i2c_write_byte(21, 7);
i2c_write_byte(22, 29);
i2c_write_byte(62, 1);
}
}
if ( !ioctl(file, 0x703uLL, 30LL) )
{
i2c_read(10, 3);
if ( buf[0] == 72 && buf[1] == 52 && buf[2] == 51 )
puts("found hmc5883");
}
result = ioctl(file, 0x703uLL, 119LL);
if ( !result )
result = puts("found bmp085");
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax

if ( !ioctl(file, 0x703uLL, 64LL) )
{
func2(0, 2);
if ( buf[0] == 3 && buf[1] == 20 )
puts("found bma180");
}
if ( !ioctl(file, 0x703uLL, 104LL) )
{
func2(0, 1);
if ( buf[0] == 104 )
{
puts("found itg3200");
func3(21, 7);
func3(22, 29);
func3(62, 1);
}
}
if ( !ioctl(file, 0x703uLL, 30LL) )
{
func2(10, 3);
if ( buf[0] == 72 && buf[1] == 52 && buf[2] == 51 )
puts("found hmc5883");
}
result = ioctl(file, 0x703uLL, 119LL);
if ( !result )
result = puts("found bmp085");
return result;
}


decompiled_code:
void write_config(void)
{
config(1LL);
}

canonical_decompiled_code:
void func7(void)
{
func6(1LL);
}

original_code:
static void write_config()
{
    config(WRITE);
}


decompiled_code:
int read_config()
{
return config(0LL);
}

canonical_decompiled_code:
int func8()
{
return func6(0LL);
}

original_code:
static void read_config()
{
    config(READ);
}


decompiled_code:
float imu_runtime()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)(LODWORD(v1.tv_usec) - LODWORD(start.tv_usec)) / 1000000.0
+ (double)(LODWORD(v1.tv_sec) - LODWORD(start.tv_sec));
}

canonical_decompiled_code:
float func9()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)(LODWORD(v1.tv_usec) - LODWORD(start.tv_usec)) / 1000000.0
+ (double)(LODWORD(v1.tv_sec) - LODWORD(start.tv_sec));
}

original_code:
float imu_runtime()
{
    struct timeval current;
    gettimeofday(&current, ((void *)0));
    return current.tv_sec - start.tv_sec + (current.tv_usec - start.tv_usec)/1e6;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
int imu_init()
{
int result; // eax
pthread_t newthread; // [rsp+8h] [rbp-50h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-48h] BYREF

read_config();
atexit(write_config);
file = open(i2c_device, 2);
if ( file < 0 )
{
fprintf(stderr, "failed to open: '%s'\n", i2c_device);
result = 1;
}
else
{
init_mag_calibration();
probe_i2c_devices();
*((_QWORD *)&cof + 4) = 0LL;
*((_QWORD *)&dof + 4) = 0LL;
*((_QWORD *)&xmmword_FC0 + 4) = 0LL;
cof = 0LL;
*(&cof + 1) = 0LL;
dof = 0LL;
*(&dof + 1) = 0LL;
xmmword_FC0 = 0LL;
*(&xmmword_FC0 + 1) = 0LL;
if ( pthread_attr_init(&attr) || (result = pthread_create(&newthread, &attr, sensors_loop, 0LL)) != 0 )
exit(1);
}
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax
pthread_t newthread; // [rsp+8h] [rbp-50h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-48h] BYREF

func8();
atexit(write_config);
file = open(i2c_device, 2);
if ( file < 0 )
{
fprintf(stderr, "failed to open: '%s'\n", i2c_device);
result = 1;
}
else
{
init_mag_calibration();
func5();
*((_QWORD *)&cof + 4) = 0LL;
*((_QWORD *)&dof + 4) = 0LL;
*((_QWORD *)&xmmword_FC0 + 4) = 0LL;
cof = 0LL;
*(&cof + 1) = 0LL;
dof = 0LL;
*(&dof + 1) = 0LL;
xmmword_FC0 = 0LL;
*(&xmmword_FC0 + 1) = 0LL;
if ( pthread_attr_init(&attr) || (result = pthread_create(&newthread, &attr, sensors_loop, 0LL)) != 0 )
exit(1);
}
return result;
}

original_code:
int imu_init()
{
    read_config();
    atexit(write_config);
    if((file = open(i2c_device, 02)) < 0) {
        fprintf(stderr, "failed to open: '%s'\n", i2c_device);
        return 1;
    }
    init_mag_calibration();
    probe_i2c_devices();
    int i;
    for(i=0; i<SENSOR_COUNT; i++)
        of[i] = dof[i] = cof[i] = 0;
    pthread_attr_t attr;
    if(pthread_attr_init(&attr) != 0)
        exit(1);
    pthread_t thread;
    if(pthread_create(&thread, &attr, sensors_loop, ((void *)0)) != 0)
        exit(1);
    return 0;
}

canonical_original_code:
int imu_init()
{
    read_config();
    atexit(write_config);
    if((file = open(i2c_device, 02)) < 0) {
        fprintf(stderr, "failed to open: '%s'\n", i2c_device);
        return 1;
    }
    init_mag_calibration();
    probe_i2c_devices();
    int i;
    for(i=0; i<SENSOR_COUNT; i++)
        of[i] = dof[i] = cof[i] = 0;
    union pthread_attr_t attr;
    if(pthread_attr_init(&attr) != 0)
        exit(1);
    unsigned long thread;
    if(pthread_create(&thread, &attr, sensors_loop, ((void *)0)) != 0)
        exit(1);
    return 0;
}

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types:
thread
unsigned long


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

for ( result = 0LL; result != 36; result += 4LL )
*(_DWORD *)(a1 + result) = *(_DWORD *)((char *)&xmmword_FC0 + result);
return result;
}

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

for ( result = 0LL; result != 36; result += 4LL )
*(_DWORD *)(a1 + result) = *(_DWORD *)((char *)&xmmword_FC0 + result);
return result;
}

original_code:
void imu_read(float s[9])
{
    int i;
    for(i=0; i<9; i++)
        s[i] = of[i];
}

variable_types:
s
float [9]


decompiled_code:
__int64 __fastcall imu_yaw_offset(float a1)
{
double v1; // xmm0_8
__int64 v3; // [rsp+4h] [rbp-24h] BYREF
int v4; // [rsp+Ch] [rbp-1Ch]
char v5[24]; // [rsp+10h] [rbp-18h] BYREF

v1 = (float)(a1 / 180.0) * 3.141592653589793;
v3 = 0LL;
v4 = 1065353216;
*(float *)&v1 = v1;
angvec2quat(v5, &v3, v1);
return quatmult1(&alignment, v5);
}

original_code:
void imu_yaw_offset(float angle)
{
    float q[4], g[3] = {0, 0, 1};
    angvec2quat(q, ((angle)/180*3.14159265358979323846), g);
    quatmult1(alignment, q);
}

canonical_original_code:
void imu_yaw_offset(float angle)
{
    float q[4]; float g[3] = {0, 0, 1};
    angvec2quat(q, ((angle)/180*3.14159265358979323846), g);
    quatmult1(alignment, q);
}

variable_types: angle float


decompiled_code:
__int64 __fastcall imu_quaternion(_DWORD *a1)
{
*a1 = q0;
a1[1] = q1;
a1[2] = q2;
a1[3] = q3;
return quatmult1(a1, &alignment);
}

canonical_decompiled_code:
__int64 __fastcall func13(_DWORD *a1)
{
*a1 = q0;
a1[1] = q1;
a1[2] = q2;
a1[3] = q3;
return quatmult1(a1, &alignment);
}

original_code:
void imu_quaternion(float q[4])
{
    q[0] = q0, q[1] = q1, q[2] = q2, q[3] = q3;
    quatmult1(q, alignment);
 }


decompiled_code:
__int64 __fastcall imu_orientation(__int64 a1)
{
_DWORD v2[6]; // [rsp+0h] [rbp-18h] BYREF

imu_quaternion(v2);
return quaternion_pitch_roll_yaw(v2, a1, a1 + 4, a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
_DWORD v2[6]; // [rsp+0h] [rbp-18h] BYREF

func13(v2);
return quaternion_pitch_roll_yaw(v2, a1, a1 + 4, a1 + 8);
}

original_code:
void imu_orientation(float a[3])
{
    float q[4];
    imu_quaternion(q);
    quaternion_pitch_roll_yaw(q, a+0, a+1, a+2);
}


decompiled_code:
void __fastcall __noreturn sensors_loop(void *a1)
{
float v1; // ebx
float v2; // xmm0_4
float v3; // xmm4_4
__m128i v4; // xmm0
struct timespec *v5; // rdi
__int128 *v6; // rax
__int64 i; // rax
float v8; // xmm0_4
float v9; // xmm0_4
float v10; // xmm2_4
__int64 j; // rax
double v12; // xmm1_8
float v13; // xmm0_4
__int64 k; // rax
float v15; // xmm0_4
float v16; // [rsp+18h] [rbp-30h]
float v17; // [rsp+18h] [rbp-30h]
float v18; // [rsp+1Ch] [rbp-2Ch]
char v19[8]; // [rsp+24h] [rbp-24h] BYREF
float v20; // [rsp+2Ch] [rbp-1Ch]
struct timespec requested_time; // [rsp+30h] [rbp-18h] BYREF

v1 = 0.0;
gettimeofday(&start, 0LL);
v18 = 0.0;
while ( 1 )
{
v2 = imu_runtime();
v3 = v1 - v2;
v16 = v2;
v4 = 0LL;
*(double *)v4.m128i_i64 = v3 + 0.02;
*(float *)v4.m128i_i32 = *(double *)v4.m128i_i64;
if ( *(float *)v4.m128i_i32 < 0.0 )
{
v5 = (struct timespec *)"system too slow to maintain inertial sensors filter\n";
fwrite("system too slow to maintain inertial sensors filter\n", 1uLL, 0x34uLL, stderr);
}
else
{
v5 = &requested_time;
requested_time.tv_sec = 0LL;
*(double *)v4.m128i_i64 = *(float *)v4.m128i_i32 * 1000000000.0;
requested_time.tv_nsec = (unsigned int)(int)*(double *)v4.m128i_i64;
nanosleep(&requested_time, 0LL);
}
*(float *)v4.m128i_i32 = imu_runtime();
v1 = COERCE_FLOAT(_mm_cvtsi128_si32(v4));
if ( (float)(v16 - v18) >= 0.2 )
{
v6 = &cof;
v18 = v18 + 0.2;
do
{
if ( *(float *)v6 == 0.0 )
goto LABEL_18;
v6 = (__int128 *)((char *)v6 + 4);
}
while ( v6 != (__int128 *)((char *)&cof + 40) );
for ( i = 0LL; i != 40; *(_DWORD *)((char *)&cof + i - 4) = 0 )
{
v8 = *(float *)((char *)&dof + i);
i += 4LL;
v9 = v8 / *(float *)((char *)&cof + i - 4);
*(_DWORD *)((char *)&dof + i - 4) = 0;
*(float *)((char *)&xmmword_FC0 + i - 4) = v9;
}
v10 = *(float *)&gyro_bias_lowpass;
for ( j = 3LL; j != 6; *(float *)&dword_F3C[j] = v13 )
{
*(_QWORD *)&v12 = *(unsigned int *)((char *)&xmmword_FC0 + j * 4);
v13 = lp_filter(*(float *)&of_bias[j], *(float *)&v12, v10);
}
for ( k = 0LL; k != 10; *(float *)((char *)&xmmword_FC0 + k * 4 - 4) = v15 )
{
v15 = *(float *)((char *)&xmmword_FC0 + k * 4) - *(float *)&of_bias[k];
++k;
}
if ( initial_values_0 )
{
initial_values_0 = 0;
compute_initial_orientation(v15, v12, COERCE_DOUBLE((unsigned __int64)LODWORD(v10)));
}
MadgwickAHRSupdate(
*((float *)&xmmword_FC0 + 3),
*((float *)&xmmword_FC0 + 4),
*((float *)&xmmword_FC0 + 5),
*(float *)&xmmword_FC0,
*((float *)&xmmword_FC0 + 1),
*((float *)&xmmword_FC0 + 2),
*((float *)&xmmword_FC0 + 6),
*((float *)&xmmword_FC0 + 7),
v5);
if ( (unsigned int)calibrate_mag((unsigned int)((_DWORD)&xmmword_FC0 + 24), &requested_time) )
{
imu_orientation((__int64)v19);
v17 = v20;
*(float *)&dword_F58 = *(float *)&dword_F58 + *(float *)&requested_time.tv_sec;
*(float *)&dword_F5C = *(float *)&dword_F5C + *((float *)&requested_time.tv_sec + 1);
*(float *)&dword_F60 = *(float *)&dword_F60 + *(float *)&requested_time.tv_nsec;
imu_orientation((__int64)v19);
imu_yaw_offset(v17 - v20);
}
}
LABEL_18:
read_sensors();
}
}

canonical_decompiled_code:
void __fastcall __noreturn func15(void *a1)
{
float v1; // ebx
float v2; // xmm0_4
float v3; // xmm4_4
__m128i v4; // xmm0
struct timespec *v5; // rdi
__int128 *v6; // rax
__int64 i; // rax
float v8; // xmm0_4
float v9; // xmm0_4
float v10; // xmm2_4
__int64 j; // rax
double v12; // xmm1_8
float v13; // xmm0_4
__int64 k; // rax
float v15; // xmm0_4
float v16; // [rsp+18h] [rbp-30h]
float v17; // [rsp+18h] [rbp-30h]
float v18; // [rsp+1Ch] [rbp-2Ch]
char v19[8]; // [rsp+24h] [rbp-24h] BYREF
float v20; // [rsp+2Ch] [rbp-1Ch]
struct timespec requested_time; // [rsp+30h] [rbp-18h] BYREF

v1 = 0.0;
gettimeofday(&start, 0LL);
v18 = 0.0;
while ( 1 )
{
v2 = func9();
v3 = v1 - v2;
v16 = v2;
v4 = 0LL;
*(double *)v4.m128i_i64 = v3 + 0.02;
*(float *)v4.m128i_i32 = *(double *)v4.m128i_i64;
if ( *(float *)v4.m128i_i32 < 0.0 )
{
v5 = (struct timespec *)"system too slow to maintain inertial sensors filter\n";
fwrite("system too slow to maintain inertial sensors filter\n", 1uLL, 0x34uLL, stderr);
}
else
{
v5 = &requested_time;
requested_time.tv_sec = 0LL;
*(double *)v4.m128i_i64 = *(float *)v4.m128i_i32 * 1000000000.0;
requested_time.tv_nsec = (unsigned int)(int)*(double *)v4.m128i_i64;
nanosleep(&requested_time, 0LL);
}
*(float *)v4.m128i_i32 = func9();
v1 = COERCE_FLOAT(_mm_cvtsi128_si32(v4));
if ( (float)(v16 - v18) >= 0.2 )
{
v6 = &cof;
v18 = v18 + 0.2;
do
{
if ( *(float *)v6 == 0.0 )
goto LABEL_18;
v6 = (__int128 *)((char *)v6 + 4);
}
while ( v6 != (__int128 *)((char *)&cof + 40) );
for ( i = 0LL; i != 40; *(_DWORD *)((char *)&cof + i - 4) = 0 )
{
v8 = *(float *)((char *)&dof + i);
i += 4LL;
v9 = v8 / *(float *)((char *)&cof + i - 4);
*(_DWORD *)((char *)&dof + i - 4) = 0;
*(float *)((char *)&xmmword_FC0 + i - 4) = v9;
}
v10 = *(float *)&gyro_bias_lowpass;
for ( j = 3LL; j != 6; *(float *)&dword_F3C[j] = v13 )
{
*(_QWORD *)&v12 = *(unsigned int *)((char *)&xmmword_FC0 + j * 4);
v13 = func0(*(float *)&of_bias[j], *(float *)&v12, v10);
}
for ( k = 0LL; k != 10; *(float *)((char *)&xmmword_FC0 + k * 4 - 4) = v15 )
{
v15 = *(float *)((char *)&xmmword_FC0 + k * 4) - *(float *)&of_bias[k];
++k;
}
if ( initial_values_0 )
{
initial_values_0 = 0;
func1(v15, v12, COERCE_DOUBLE((unsigned __int64)LODWORD(v10)));
}
MadgwickAHRSupdate(
*((float *)&xmmword_FC0 + 3),
*((float *)&xmmword_FC0 + 4),
*((float *)&xmmword_FC0 + 5),
*(float *)&xmmword_FC0,
*((float *)&xmmword_FC0 + 1),
*((float *)&xmmword_FC0 + 2),
*((float *)&xmmword_FC0 + 6),
*((float *)&xmmword_FC0 + 7),
v5);
if ( (unsigned int)calibrate_mag((unsigned int)((_DWORD)&xmmword_FC0 + 24), &requested_time) )
{
func14((__int64)v19);
v17 = v20;
*(float *)&dword_F58 = *(float *)&dword_F58 + *(float *)&requested_time.tv_sec;
*(float *)&dword_F5C = *(float *)&dword_F5C + *((float *)&requested_time.tv_sec + 1);
*(float *)&dword_F60 = *(float *)&dword_F60 + *(float *)&requested_time.tv_nsec;
func14((__int64)v19);
func12(v17 - v20);
}
}
LABEL_18:
func4();
}
}

original_code:
static void *sensors_loop(void *v)
{
    float freq = 50;
    float l = 0, l2 = 0;
    gettimeofday(&start, ((void *)0));
    for(;;) {
        float n = imu_runtime();
        float s = l - n + 1.0/freq;
        if(s<0) {
            fprintf(stderr, "system too slow to maintain inertial sensors filter\n");
        } else {
            struct timespec ts = {0, (s)*1e9};
            nanosleep(&ts, ((void *)0));
        }
        l = imu_runtime();
        float p = 1.0f/filter_sample_count;
        if(n - l2 >= p) {
            l2 += p;
            int i;
            for(i=0; i<SENSOR_COUNT; i++)
                if(cof[i] == 0)
                    goto skip;
            for(i=0; i<SENSOR_COUNT; i++) {
                of[i] = dof[i] / cof[i];
                dof[i] = cof[i] = 0;
            }
            for(i=3; i<6; i++)
                of_bias[i] = lp_filter(of_bias[i], of[i], gyro_bias_lowpass);
            for(i=0; i<SENSOR_COUNT; i++)
                of[i] -= of_bias[i];
            static int initial_values = 1;
            if(initial_values) {
                initial_values = 0;
                compute_initial_orientation();
            }
            MadgwickAHRSupdate(of[3], of[4], of[5], of[0], of[1], of[2], of[6], of[7], of[8]);
            float magstate[4];
            if(calibrate_mag(of + 6, magstate)) {
                float a[3];
                imu_orientation(a);
                float yaw = a[2];
                for(i=0; i<3; i++)
                    of_bias[MAGX+i] += magstate[i];
                imu_orientation(a);
                imu_yaw_offset(yaw - a[2]);
            }
        }
    skip:
        read_sensors();
    }
}

canonical_original_code:
static void *sensors_loop(void *v)
{
    float freq = 50;
    float l = 0; float l2 = 0;
    gettimeofday(&start, ((void *)0));
    for(;;) {
        float n = imu_runtime();
        float s = l - n + 1.0/freq;
        if(s<0) {
            fprintf(stderr, "system too slow to maintain inertial sensors filter\n");
        } else {
            struct timespec ts = {0, (s)*1e9};
            nanosleep(&ts, ((void *)0));
        }
        l = imu_runtime();
        float p = 1.0f/filter_sample_count;
        if(n - l2 >= p) {
            l2 += p;
            int i;
            for(i=0; i<SENSOR_COUNT; i++)
                if(cof[i] == 0)
                    goto skip;
            for(i=0; i<SENSOR_COUNT; i++) {
                of[i] = dof[i] / cof[i];
                dof[i] = cof[i] = 0;
            }
            for(i=3; i<6; i++)
                of_bias[i] = lp_filter(of_bias[i], of[i], gyro_bias_lowpass);
            for(i=0; i<SENSOR_COUNT; i++)
                of[i] -= of_bias[i];
            static int initial_values = 1;
            if(initial_values) {
                initial_values = 0;
                compute_initial_orientation();
            }
            MadgwickAHRSupdate(of[3], of[4], of[5], of[0], of[1], of[2], of[6], of[7], of[8]);
            float magstate[4];
            if(calibrate_mag(of + 6, magstate)) {
                float a[3];
                imu_orientation(a);
                float yaw = a[2];
                for(i=0; i<3; i++)
                    of_bias[MAGX+i] += magstate[i];
                imu_orientation(a);
                imu_yaw_offset(yaw - a[2]);
            }
        }
    skip:
        read_sensors();
    }
}

variable_types:
v
void *

variable_types: freq float

variable_types: l float

variable_types: n float

variable_types: s float

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

variable_types: p float

variable_types:
magstate
float [4]

variable_types: yaw float


decompiled_code:
__int64 imu_level()
{
float v1; // [rsp+Ch] [rbp-2Ch]
char v2[8]; // [rsp+10h] [rbp-28h] BYREF
float v3; // [rsp+18h] [rbp-20h]

imu_orientation((__int64)v2);
alignment = q0;
v1 = v3;
*(&alignment + 1) = q1 ^ LC2;
*(&alignment + 2) = q2 ^ LC2;
*(&alignment + 3) = q3 ^ LC2;
imu_orientation((__int64)v2);
return imu_yaw_offset(v1 - v3);
}

canonical_decompiled_code:
__int64 func16()
{
float v1; // [rsp+Ch] [rbp-2Ch]
char v2[8]; // [rsp+10h] [rbp-28h] BYREF
float v3; // [rsp+18h] [rbp-20h]

func14((__int64)v2);
alignment = q0;
v1 = v3;
*(&alignment + 1) = q1 ^ LC2;
*(&alignment + 2) = q2 ^ LC2;
*(&alignment + 3) = q3 ^ LC2;
func14((__int64)v2);
return func12(v1 - v3);
}

original_code:
void imu_level()
{
    float a[6];
    imu_orientation(a);
    float yaw = a[2];
    alignment[0] = q0;
    alignment[1] = -q1;
    alignment[2] = -q2;
    alignment[3] = -q3;
    imu_orientation(a);
    imu_yaw_offset(yaw - a[2]);
}

variable_types:
a
float [6]


decompiled_code:
__int64 __fastcall imu_rate(__int64 a1)
{
float v1; // xmm0_4
__int64 v3; // [rsp+4h] [rbp-34h] BYREF
float v4; // [rsp+Ch] [rbp-2Ch]
float v5; // [rsp+10h] [rbp-28h] BYREF
float v6; // [rsp+14h] [rbp-24h]
float v7; // [rsp+18h] [rbp-20h]
float v8; // [rsp+1Ch] [rbp-1Ch]
int v9[6]; // [rsp+20h] [rbp-18h] BYREF

imu_quaternion(&v5);
v1 = *((float *)&xmmword_FC0 + 5);
v3 = *(_QWORD *)((char *)&xmmword_FC0 + 12);
v4 = v1;
rotvecquat(&v3, &alignment);
*(float *)v9 = (float)((float)((float)((float)(COERCE_FLOAT(LODWORD(v6) ^ LC2) * *(float *)&v3)
- (float)(v7 * *((float *)&v3 + 1)))
- (float)(v8 * v4))
* 0.5)
+ 1.0;
*(float *)&v9[1] = (float)((float)((float)(*(float *)&v3 * v5) + (float)(v7 * v4)) - (float)(*((float *)&v3 + 1) * v8))
* 0.5;
*(float *)&v9[2] = (float)((float)((float)(*((float *)&v3 + 1) * v5) - (float)(v6 * v4)) + (float)(v8 * *(float *)&v3))
* 0.5;
*(float *)&v9[3] = (float)((float)((float)(v4 * v5) + (float)(v6 * *((float *)&v3 + 1))) - (float)(*(float *)&v3 * v7))
* 0.5;
quatnormalize(v9);
return quaternion_pitch_roll_yaw(v9, a1, a1 + 4, a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
float v1; // xmm0_4
__int64 v3; // [rsp+4h] [rbp-34h] BYREF
float v4; // [rsp+Ch] [rbp-2Ch]
float v5; // [rsp+10h] [rbp-28h] BYREF
float v6; // [rsp+14h] [rbp-24h]
float v7; // [rsp+18h] [rbp-20h]
float v8; // [rsp+1Ch] [rbp-1Ch]
int v9[6]; // [rsp+20h] [rbp-18h] BYREF

func13(&v5);
v1 = *((float *)&xmmword_FC0 + 5);
v3 = *(_QWORD *)((char *)&xmmword_FC0 + 12);
v4 = v1;
rotvecquat(&v3, &alignment);
*(float *)v9 = (float)((float)((float)((float)(COERCE_FLOAT(LODWORD(v6) ^ LC2) * *(float *)&v3)
- (float)(v7 * *((float *)&v3 + 1)))
- (float)(v8 * v4))
* 0.5)
+ 1.0;
*(float *)&v9[1] = (float)((float)((float)(*(float *)&v3 * v5) + (float)(v7 * v4)) - (float)(*((float *)&v3 + 1) * v8))
* 0.5;
*(float *)&v9[2] = (float)((float)((float)(*((float *)&v3 + 1) * v5) - (float)(v6 * v4)) + (float)(v8 * *(float *)&v3))
* 0.5;
*(float *)&v9[3] = (float)((float)((float)(v4 * v5) + (float)(v6 * *((float *)&v3 + 1))) - (float)(*(float *)&v3 * v7))
* 0.5;
quatnormalize(v9);
return quaternion_pitch_roll_yaw(v9, a1, a1 + 4, a1 + 8);
}

variable_types:
a
float [3]

variable_types:
q
float [4]

variable_types:
r
float [4]

variable_types:
g
float [3]


cleanup

decompiled_code:
void cleanup(void)
{
servo_close(servo);
werase(stdscr);
if ( !isendwin() )
endwin();
}

canonical_decompiled_code:
void func0(void)
{
servo_close(servo);
werase(stdscr);
if ( !isendwin() )
endwin();
}

original_code:
void cleanup()
{
    servo_close(servo);
    werase(stdscr);
    if(isendwin() == 0)
        endwin();
}