decompiled_code:
void __fastcall __noreturn app_thread(void *a1)
{
pthread_t v2; // rax
char v3; // al
void (**v4)(void); // rdi

v2 = pthread_self();
pthread_detach(v2);
v3 = *((_BYTE *)a1 + 48);
if ( v3 == 5 )
{
LABEL_2:
*((_BYTE *)a1 + 48) = 6;
pthread_exit(0LL);
}
while ( 1 )
{
while ( v3 == 1 )
{
LABEL_3:
usleep(0xAu);
LABEL_4:
v3 = *((_BYTE *)a1 + 48);
if ( v3 == 5 )
goto LABEL_2;
}
switch ( v3 )
{
case 2:
*((_BYTE *)a1 + 48) = 3;
break;
case 3:
v4 = (void (**)(void))*((_QWORD *)a1 + 7);
if ( v4 )
{
if ( *v4 )
(*v4)();
else
printf("error paramter (func,data) for thread %u\n", *((unsigned int *)a1 + 13));
}
else
{
printf("error parameter for thread %u\n", *((unsigned int *)a1 + 13));
}
*((_BYTE *)a1 + 48) = 4;
break;
case 4:
goto LABEL_3;
default:
goto LABEL_4;
}
v3 = *((_BYTE *)a1 + 48);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
pthread_t v2; // rax
char v3; // al
void (**v4)(void); // rdi

v2 = pthread_self();
pthread_detach(v2);
v3 = *((_BYTE *)a1 + 48);
if ( v3 == 5 )
{
LABEL_2:
*((_BYTE *)a1 + 48) = 6;
pthread_exit(0LL);
}
while ( 1 )
{
while ( v3 == 1 )
{
LABEL_3:
usleep(0xAu);
LABEL_4:
v3 = *((_BYTE *)a1 + 48);
if ( v3 == 5 )
goto LABEL_2;
}
switch ( v3 )
{
case 2:
*((_BYTE *)a1 + 48) = 3;
break;
case 3:
v4 = (void (**)(void))*((_QWORD *)a1 + 7);
if ( v4 )
{
if ( *v4 )
(*v4)();
else
printf("error paramter (func,data) for thread %u\n", *((unsigned int *)a1 + 13));
}
else
{
printf("error parameter for thread %u\n", *((unsigned int *)a1 + 13));
}
*((_BYTE *)a1 + 48) = 4;
break;
case 4:
goto LABEL_3;
default:
goto LABEL_4;
}
v3 = *((_BYTE *)a1 + 48);
}
}

original_code:
void * app_thread(void*data)
{
 thread_t * pt = (thread_t*)data;
 pthread_detach (pthread_self());
 while (pt->status != status_dead)
 {
  if (pt->status == status_free)
  {
   usleep (10);
   continue;
  }
  if (pt->status == status_ready)
  {
   pt->status = status_running;
   continue;
  }
  if (pt->status == status_running)
  {
   if (!pt->param)
   {
    printf ("error parameter for thread %u\n", pt->index);
    goto OVER;
   }
   if (pt->param->func && pt->param)
   {
    pt->param->func (pt->param);
   }else
   {
    printf ("error paramter (func,data) for thread %u\n",pt->index);
   }
   OVER:
   pt->status = status_over;
   continue;
  }
  if (pt->status == status_over)
  {
   usleep(10);
   continue;
  }
  if (pt->status == status_dead)
  {
   printf ("good luck, i'm now exiting..bye\n");
   break;
  }
 }
 pt->status = status_already_dead;
 pthread_exit (0);
}

canonical_original_code:
void *app_thread(void *data)
{
 struct thread_t *pt = (thread_t*)data;
 pthread_detach (pthread_self());
 while (pt->status != status_dead)
 {
  if (pt->status == status_free)
  {
   usleep (10);
   continue;
  }
  if (pt->status == status_ready)
  {
   pt->status = status_running;
   continue;
  }
  if (pt->status == status_running)
  {
   if (!pt->param)
   {
    printf ("error parameter for thread %u\n", pt->index);
    goto OVER;
   }
   if (pt->param->func && pt->param)
   {
    pt->param->func (pt->param);
   }else
   {
    printf ("error paramter (func,data) for thread %u\n",pt->index);
   }
   OVER:
   pt->status = status_over;
   continue;
  }
  if (pt->status == status_over)
  {
   usleep(10);
   continue;
  }
  if (pt->status == status_dead)
  {
   printf ("good luck, i'm now exiting..bye\n");
   break;
  }
 }
 pt->status = status_already_dead;
 pthread_exit (0);
}

variable_types:
data
void *

variable_types: struct thread_t { unsigned long thread; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned char status; unsigned int index; struct param_t { int (*func)(void *data); void *data; int index; void *conf; } *param; } *

return_type: void *


decompiled_code:
__int64 __fastcall init_thread_slot(void *arg, __int64 a2)
{
char *v2; // rbx
unsigned int v3; // ebp

if ( !arg )
{
printf("error thread_pool pointer, program bug!!!");
exit(0);
}
if ( (unsigned int)(*((_DWORD *)arg + 1600) - 1) > 0x63 )
{
puts("error thread number, default value is used");
*((_DWORD *)arg + 1600) = 99;
}
v2 = (char *)arg;
v3 = 0;
do
{
v2[48] = 1;
*((_DWORD *)v2 + 13) = v3;
*((_QWORD *)v2 + 7) = 0LL;
if ( pthread_mutex_init((pthread_mutex_t *)(v2 + 8), 0LL) )
{
printf("pthread_mutex_init for thread_%u failed\n", v3);
return 0xFFFFFFFFLL;
}
if ( pthread_create((pthread_t *)v2, 0LL, (void *(*)(void *))app_thread, v2) )
{
printf("create thread for thread %u failed\n", v3);
return 0xFFFFFFFFLL;
}
if ( *(_BYTE *)(a2 + 3) )
printf("create thread \x1B[0;32;32m%03d\x1B[m success\n", v3 + 1);
++v3;
v2 += 64;
}
while ( *((_DWORD *)arg + 1600) > v3 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *arg, __int64 a2)
{
char *v2; // rbx
unsigned int v3; // ebp

if ( !arg )
{
printf("error thread_pool pointer, program bug!!!");
exit(0);
}
if ( (unsigned int)(*((_DWORD *)arg + 1600) - 1) > 0x63 )
{
puts("error thread number, default value is used");
*((_DWORD *)arg + 1600) = 99;
}
v2 = (char *)arg;
v3 = 0;
do
{
v2[48] = 1;
*((_DWORD *)v2 + 13) = v3;
*((_QWORD *)v2 + 7) = 0LL;
if ( pthread_mutex_init((pthread_mutex_t *)(v2 + 8), 0LL) )
{
printf("pthread_mutex_init for thread_%u failed\n", v3);
return 0xFFFFFFFFLL;
}
if ( pthread_create((pthread_t *)v2, 0LL, (void *(*)(void *))app_thread, v2) )
{
printf("create thread for thread %u failed\n", v3);
return 0xFFFFFFFFLL;
}
if ( *(_BYTE *)(a2 + 3) )
printf("create thread \x1B[0;32;32m%03d\x1B[m success\n", v3 + 1);
++v3;
v2 += 64;
}
while ( *((_DWORD *)arg + 1600) > v3 );
return 1LL;
}

original_code:
int init_thread_slot(thread_pool_t * pp, const config_t * conf)
{
 unsigned int index = 0;
 if (!pp)
 {
  printf ("error thread_pool pointer, program bug!!!");
  exit (0);
 }
 if ((pp->thread_num <=0) || (pp->thread_num > 100))
 {
  printf ("error thread number, default value is used\n");
  pp->thread_num = 100 - 1;
 }
 for ( index = 0; index < pp->thread_num; index++)
 {
  pp->thread_list[index].status = status_free;
  pp->thread_list[index].index = index;
  pp->thread_list[index].param = 0;
  if(pthread_mutex_init (&(pp->thread_list[index].mutex), 0))
  {
   printf ("pthread_mutex_init for thread_%u failed\n", index);
   return -1;
  }
  if (pthread_create (
   &(pp->thread_list[index].thread),
   0,
   app_thread,
   pp->thread_list + index))
  {
   printf ("create thread for thread %u failed\n", index);
   return -1;
  }else
  {
   if (conf->verb)
   printf ("create thread ""\033[0;32;32m""%03d""\033[m"" success\n", index + 1);
  }
 }
 return 1;
}

canonical_original_code:
int init_thread_slot(struct thread_pool_t *pp, struct config_t *conf)
{
 unsigned int index = 0;
 if (!pp)
 {
  printf ("error thread_pool pointer, program bug!!!");
  exit (0);
 }
 if ((pp->thread_num <=0) || (pp->thread_num > 100))
 {
  printf ("error thread number, default value is used\n");
  pp->thread_num = 100 - 1;
 }
 for ( index = 0; index < pp->thread_num; index++)
 {
  pp->thread_list[index].status = status_free;
  pp->thread_list[index].index = index;
  pp->thread_list[index].param = 0;
  if(pthread_mutex_init (&(pp->thread_list[index].mutex), 0))
  {
   printf ("pthread_mutex_init for thread_%u failed\n", index);
   return -1;
  }
  if (pthread_create (
   &(pp->thread_list[index].thread),
   0,
   app_thread,
   pp->thread_list + index))
  {
   printf ("create thread for thread %u failed\n", index);
   return -1;
  }else
  {
   if (conf->verb)
   printf ("create thread ""\033[0;32;32m""%03d""\033[m"" success\n", index + 1);
  }
 }
 return 1;
}

variable_types: struct thread_pool_t { struct thread_t { unsigned long thread; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned char status; unsigned int index; struct param_t { int (*func)(void *data); void *data; int index; void *conf; } *param; } thread_list[100]; unsigned int thread_num; } *

variable_types: struct config_t { unsigned short nthread; unsigned char daemon; unsigned char verb; char conf[256]; char user[64]; char basedir[256]; char sigfile[64]; int interval; struct _repo { char path[256]; char sigfile[256]; int intv; void *next; long last_update; } repo_list[100]; int repo_num; int loop; } *

variable_types:
index
unsigned int

return_type: int

user_defined_types: struct thread_pool_t { struct thread_t thread_list[100]; unsigned int thread_num; }

user_defined_types: struct config_t { unsigned short nthread; unsigned char daemon; unsigned char verb; char conf[256]; char user[64]; char basedir[256]; char sigfile[64]; int interval; struct _repo repo_list[100]; int repo_num; int loop; }

user_defined_types: struct thread_t { unsigned long thread; union pthread_mutex_t mutex; unsigned char status; unsigned int index; struct param_t *param; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall run_over(__int64 a1)
{
int v1; // edx
_BYTE *v2; // rax
unsigned __int64 v3; // rdx

v1 = *(_DWORD *)(a1 + 6400);
if ( !v1 )
return 1LL;
v2 = (_BYTE *)(a1 + 48);
v3 = a1 + ((unsigned __int64)(unsigned int)(v1 - 1) << 6) + 112;
while ( *v2 == 4 )
{
v2 += 64;
if ( v2 == (_BYTE *)v3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // edx
_BYTE *v2; // rax
unsigned __int64 v3; // rdx

v1 = *(_DWORD *)(a1 + 6400);
if ( !v1 )
return 1LL;
v2 = (_BYTE *)(a1 + 48);
v3 = a1 + ((unsigned __int64)(unsigned int)(v1 - 1) << 6) + 112;
while ( *v2 == 4 )
{
v2 += 64;
if ( v2 == (_BYTE *)v3 )
return 1LL;
}
return 0LL;
}

original_code:
unsigned char run_over(thread_pool_t * pool)
{
 unsigned char bRet = 1;
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  if (pool->thread_list[index].status != status_over)
  {
   bRet = 0;
   break;
  }
 }
 return bRet;
}

canonical_original_code:
unsigned char run_over(struct thread_pool_t *pool)
{
 unsigned char bRet = 1;
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  if (pool->thread_list[index].status != status_over)
  {
   bRet = 0;
   break;
  }
 }
 return bRet;
}

variable_types:
bRet
unsigned char

return_type: unsigned char

user_defined_types: struct param_t { int (*func)(void *data); void *data; int index; void *conf; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


original_code:
int reset_thread (thread_pool_t * pool)
{
 int nRet = 0;
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  if (pool->thread_list[index].status == status_over)
  {
   pool->thread_list[index].status = status_free;
   pool->thread_list[index].param = 0;
   nRet++;
  }
 }
 return nRet;
}

canonical_original_code:
int reset_thread(struct thread_pool_t *pool)
{
 int nRet = 0;
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  if (pool->thread_list[index].status == status_over)
  {
   pool->thread_list[index].status = status_free;
   pool->thread_list[index].param = 0;
   nRet++;
  }
 }
 return nRet;
}

variable_types: nRet int


decompiled_code:
__int64 __fastcall terminate_thread(__int64 a1)
{
__int64 v1; // r12
unsigned int v2; // er13
time_t v3; // rbx

if ( !*(_DWORD *)(a1 + 6400) )
return 0;
v1 = a1 + 48;
v2 = 0;
do
{
v3 = time(0LL);
*(_BYTE *)v1 = 5;
while ( 1 )
{
usleep(0xAu);
if ( time(0LL) - v3 > 4 )
break;
if ( *(_BYTE *)v1 == 6 )
goto LABEL_4;
}
printf("waitting for thread_%u to exit timeout\n", *(unsigned int *)(v1 + 4));
LABEL_4:
++v2;
v1 += 64LL;
}
while ( *(_DWORD *)(a1 + 6400) > v2 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // r12
unsigned int v2; // er13
time_t v3; // rbx

if ( !*(_DWORD *)(a1 + 6400) )
return 0;
v1 = a1 + 48;
v2 = 0;
do
{
v3 = time(0LL);
*(_BYTE *)v1 = 5;
while ( 1 )
{
usleep(0xAu);
if ( time(0LL) - v3 > 4 )
break;
if ( *(_BYTE *)v1 == 6 )
goto LABEL_4;
}
printf("waitting for thread_%u to exit timeout\n", *(unsigned int *)(v1 + 4));
LABEL_4:
++v2;
v1 += 64LL;
}
while ( *(_DWORD *)(a1 + 6400) > v2 );
return v2;
}

original_code:
int terminate_thread (thread_pool_t * pool)
{
 int nRet = 0;
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  time_t start = time (0);
  pool->thread_list[index].status = status_dead;
  while (pool->thread_list[index].status != status_already_dead)
  {
   usleep (10);
   if (time(0) - start >= 5)
   {
    printf ("waitting for thread_%u to exit timeout\n",
    pool->thread_list[index].index);
    break;
   }
  }
  nRet++;
 }
 return nRet;
}

canonical_original_code:
int terminate_thread(struct thread_pool_t *pool)
{
 int nRet = 0;
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  long start = time (0);
  pool->thread_list[index].status = status_dead;
  while (pool->thread_list[index].status != status_already_dead)
  {
   usleep (10);
   if (time(0) - start >= 5)
   {
    printf ("waitting for thread_%u to exit timeout\n",
    pool->thread_list[index].index);
    break;
   }
  }
  nRet++;
 }
 return nRet;
}

variable_types: start long


daemon

decompiled_code:
__int64 __fastcall daemon(int a1, int a2)
{
__pid_t v2; // eax
unsigned int v3; // er12
int v5; // eax
int v6; // ebx

v2 = fork();
if ( v2 < 0 )
{
perror("fork");
v3 = -1;
}
else
{
v3 = v2;
if ( v2 )
exit(0);
if ( setsid() < -1 )
{
perror("setsid");
v3 = -1;
}
else
{
if ( !a1 )
chdir("/");
if ( !a2 )
{
v5 = open("/dev/null", 2, 0LL);
v6 = v5;
if ( v5 != -1 )
{
dup2(v5, 0);
dup2(v6, 1);
dup2(v6, 2);
close(v6);
}
}
umask(0x17u);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__pid_t v2; // eax
unsigned int v3; // er12
int v5; // eax
int v6; // ebx

v2 = fork();
if ( v2 < 0 )
{
perror("fork");
v3 = -1;
}
else
{
v3 = v2;
if ( v2 )
exit(0);
if ( setsid() < -1 )
{
perror("setsid");
v3 = -1;
}
else
{
if ( !a1 )
chdir("/");
if ( !a2 )
{
v5 = open("/dev/null", 2, 0LL);
v6 = v5;
if ( v5 != -1 )
{
dup2(v5, 0);
dup2(v6, 1);
dup2(v6, 2);
close(v6);
}
}
umask(0x17u);
}
}
return v3;
}

original_code:
int daemon (int nochdir, int noclose)
{
  pid_t pid;
  pid = fork ();
  if (pid < 0)
    {
      perror ("fork");
      return -1;
    }
  if (pid != 0)
    exit (0);
  pid = setsid();
  if (pid < -1)
    {
      perror ("setsid");
      return -1;
    }
  if (! nochdir)
    chdir ("/");
  if (! noclose)
    {
      int fd;
      fd = open ("/dev/null", 02, 0);
      if (fd != -1)
    {
      dup2 (fd, 0);
      dup2 (fd, 1);
      dup2 (fd, 2);
      close(fd);
    }
    }
  umask (0027);
  return 0;
}

canonical_original_code:
int daemon(int nochdir, int noclose)
{
  int pid;
  pid = fork ();
  if (pid < 0)
    {
      perror ("fork");
      return -1;
    }
  if (pid != 0)
    exit (0);
  pid = setsid();
  if (pid < -1)
    {
      perror ("setsid");
      return -1;
    }
  if (! nochdir)
    chdir ("/");
  if (! noclose)
    {
      int fd;
      fd = open ("/dev/null", 02, 0);
      if (fd != -1)
    {
      dup2 (fd, 0);
      dup2 (fd, 1);
      dup2 (fd, 2);
      close(fd);
    }
    }
  umask (0027);
  return 0;
}

variable_types: nochdir int

variable_types: noclose int

variable_types: pid int

variable_types: fd int


decompiled_code:
int __fastcall act_listpkg_init(int argc, char **argv, __int64 a3)
{
char *v4; // r13
int v5; // eax
int result; // eax
const char *v7; // r12
struct stat v8; // [rsp+0h] [rbp-B8h] BYREF

optind = 1;
v4 = (char *)(a3 + 260);
while ( 1 )
{
v5 = getopt(argc, argv, "hc:k:u:r:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'r':
sprintf(v4, optarg);
break;
case 'u':
if ( strcmp(optarg, "me") && strcmp(optarg, "any") )
{
my_usage((unsigned int)argc, (const char **)argv);
return 1;
}
sprintf((char *)(a3 + 772), optarg);
break;
case 'h':
my_usage((unsigned int)argc, (const char **)argv);
return 1;
}
}
if ( !*(_BYTE *)(a3 + 772) )
*(_DWORD *)(a3 + 772) = 7958113;
if ( !*(_BYTE *)(a3 + 260) )
*(_DWORD *)(a3 + 260) = 7958113;
v7 = (const char *)(a3 + 4);
result = stat(v7, &v8);
if ( result )
{
printf("can not access file: '%s'\n", v7);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int argc, char **argv, __int64 a3)
{
char *v4; // r13
int v5; // eax
int result; // eax
const char *v7; // r12
struct stat v8; // [rsp+0h] [rbp-B8h] BYREF

optind = 1;
v4 = (char *)(a3 + 260);
while ( 1 )
{
v5 = getopt(argc, argv, "hc:k:u:r:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'r':
sprintf(v4, optarg);
break;
case 'u':
if ( strcmp(optarg, "me") && strcmp(optarg, "any") )
{
func0((unsigned int)argc, (const char **)argv);
return 1;
}
sprintf((char *)(a3 + 772), optarg);
break;
case 'h':
func0((unsigned int)argc, (const char **)argv);
return 1;
}
}
if ( !*(_BYTE *)(a3 + 772) )
*(_DWORD *)(a3 + 772) = 7958113;
if ( !*(_BYTE *)(a3 + 260) )
*(_DWORD *)(a3 + 260) = 7958113;
v7 = (const char *)(a3 + 4);
result = stat(v7, &v8);
if ( result )
{
printf("can not access file: '%s'\n", v7);
result = 1;
}
return result;
}

original_code:
int act_listpkg_init(int argc, char* argv[], gk_conf_t * gc)
{
 int opt;
 struct stat st;
     char *string = "hc:k:u:r:";
 optind = 1;
    while ((opt = getopt(argc, argv, string))!= -1)
    {
  switch(opt)
  {
   case 'u':
     if((strcmp(optarg,"me"))&&(strcmp(optarg, "any")))
     {
      my_usage(argc, argv);
      return 1;
     }
     sprintf(gc->user, optarg);
     break;
   case 'r':
     sprintf(gc->repo, optarg);
     break;
   case 'h':
    my_usage(argc, argv);
    return 1;
  }
    }
 if(strlen(gc->user) == 0)
 {
  sprintf(gc->user, "%s", "any");
 }
 if(strlen(gc->repo) == 0)
 {
  sprintf(gc->repo, "%s", "any");
 }
 if(stat(gc->conf, &st)) {printf("can not access file: '%s'\n",gc->conf);return 1;}
 return 0;
}

canonical_original_code:
int act_listpkg_init(int argc, char *argv[], struct _gk_conf_t *gc)
{
 int opt;
 struct stat st;
     char *string = "hc:k:u:r:";
 optind = 1;
    while ((opt = getopt(argc, argv, string))!= -1)
    {
  switch(opt)
  {
   case 'u':
     if((strcmp(optarg,"me"))&&(strcmp(optarg, "any")))
     {
      my_usage(argc, argv);
      return 1;
     }
     sprintf(gc->user, optarg);
     break;
   case 'r':
     sprintf(gc->repo, optarg);
     break;
   case 'h':
    my_usage(argc, argv);
    return 1;
  }
    }
 if(strlen(gc->user) == 0)
 {
  sprintf(gc->user, "%s", "any");
 }
 if(strlen(gc->repo) == 0)
 {
  sprintf(gc->repo, "%s", "any");
 }
 if(stat(gc->conf, &st)) {printf("can not access file: '%s'\n",gc->conf);return 1;}
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct _gk_conf_t { enum GK_ACTION { ACT_MIN_ACTION=0, ACT_UPLOAD_PKG=1, ACT_LIST_REPO=2, ACT_LIST_PKG=3, ACT_MAX_ACTION=4 } action; char conf[128]; char file[128]; char repo[64]; char osv[64]; char app[64]; char ak[64]; char as[64]; char uid[64]; char url[128]; char user[64]; char output[64]; char upload_method[64]; char endpoint[64]; char info[512]; } *

variable_types: opt int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

variable_types:
string
char *

user_defined_types: struct _gk_conf_t { enum GK_ACTION action; char conf[128]; char file[128]; char repo[64]; char osv[64]; char app[64]; char ak[64]; char as[64]; char uid[64]; char url[128]; char user[64]; char output[64]; char upload_method[64]; char endpoint[64]; char info[512]; }


randstr

original_code:
char * randstr(int len)
{
 static char ret[128]= {0};
 memset(ret, 0, 128);
 int i = 0;
 int nlen = len;
 if(nlen > 128) nlen = 128;
 for(i=0; i < nlen; i++)
 {
  char ch;
  int a = rand()%26;
  if(i%3==0) ch = 'A';
  else ch = 'a';
  ch = ch + a;
  ret[i] = ch;
 }
 return ret;
}

canonical_original_code:
char *randstr(int len)
{
 static char ret[128] = {0};
 memset(ret, 0, 128);
 int i = 0;
 int nlen = len;
 if(nlen > 128) nlen = 128;
 for(i=0; i < nlen; i++)
 {
  char ch;
  int a = rand()%26;
  if(i%3==0) ch = 'A';
  else ch = 'a';
  ch = ch + a;
  ret[i] = ch;
 }
 return ret;
}

variable_types: len int

variable_types:
ret
char [128]

variable_types: i int

variable_types: nlen int

variable_types: ch char

variable_types: a int

return_type: char *


decompiled_code:
int __fastcall act_listrepo_init(int argc, char **argv, __int64 a3)
{
char *v4; // r13
int v5; // eax
int result; // eax
const char *v7; // r12
struct stat v8; // [rsp+0h] [rbp-B8h] BYREF

optind = 1;
v4 = (char *)(a3 + 772);
while ( 1 )
{
v5 = getopt(argc, argv, "hc:k:u:");
if ( v5 == -1 )
break;
if ( v5 == 104 )
{
my_usage((unsigned int)argc, (const char **)argv);
return 1;
}
if ( v5 == 117 )
{
if ( strcmp(optarg, "me") && strcmp(optarg, "any") )
{
my_usage((unsigned int)argc, (const char **)argv);
return 1;
}
sprintf(v4, optarg);
}
}
if ( !*(_BYTE *)(a3 + 772) )
*(_DWORD *)(a3 + 772) = 7958113;
v7 = (const char *)(a3 + 4);
result = stat(v7, &v8);
if ( result )
{
printf("can not access file: '%s'\n", v7);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int argc, char **argv, __int64 a3)
{
char *v4; // r13
int v5; // eax
int result; // eax
const char *v7; // r12
struct stat v8; // [rsp+0h] [rbp-B8h] BYREF

optind = 1;
v4 = (char *)(a3 + 772);
while ( 1 )
{
v5 = getopt(argc, argv, "hc:k:u:");
if ( v5 == -1 )
break;
if ( v5 == 104 )
{
func0((unsigned int)argc, (const char **)argv);
return 1;
}
if ( v5 == 117 )
{
if ( strcmp(optarg, "me") && strcmp(optarg, "any") )
{
func0((unsigned int)argc, (const char **)argv);
return 1;
}
sprintf(v4, optarg);
}
}
if ( !*(_BYTE *)(a3 + 772) )
*(_DWORD *)(a3 + 772) = 7958113;
v7 = (const char *)(a3 + 4);
result = stat(v7, &v8);
if ( result )
{
printf("can not access file: '%s'\n", v7);
result = 1;
}
return result;
}

original_code:
int act_listrepo_init(int argc, char* argv[], gk_conf_t * gc)
{
 int opt;
 struct stat st;
    char *string = "hc:k:u:";
 optind = 1;
    while ((opt = getopt(argc, argv, string))!= -1)
    {
  switch(opt)
  {
   case 'u':
     if((strcmp(optarg,"me"))&&(strcmp(optarg, "any")))
     {
      my_usage(argc, argv);
      return 1;
     }
     sprintf(gc->user, optarg);
     break;
   case 'h':
    my_usage(argc, argv);
    return 1;
  }
    }
 if(strlen(gc->user) == 0)
 {
  sprintf(gc->user, "%s", "any");
 }
 if(stat(gc->conf, &st)) {printf("can not access file: '%s'\n",gc->conf);return 1;}
 return 0;
}

canonical_original_code:
int act_listrepo_init(int argc, char *argv[], struct _gk_conf_t *gc)
{
 int opt;
 struct stat st;
    char *string = "hc:k:u:";
 optind = 1;
    while ((opt = getopt(argc, argv, string))!= -1)
    {
  switch(opt)
  {
   case 'u':
     if((strcmp(optarg,"me"))&&(strcmp(optarg, "any")))
     {
      my_usage(argc, argv);
      return 1;
     }
     sprintf(gc->user, optarg);
     break;
   case 'h':
    my_usage(argc, argv);
    return 1;
  }
    }
 if(strlen(gc->user) == 0)
 {
  sprintf(gc->user, "%s", "any");
 }
 if(stat(gc->conf, &st)) {printf("can not access file: '%s'\n",gc->conf);return 1;}
 return 0;
}

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

user_defined_types: enum GK_ACTION { ACT_MIN_ACTION=0, ACT_UPLOAD_PKG=1, ACT_LIST_REPO=2, ACT_LIST_PKG=3, ACT_MAX_ACTION=4 }


main

canonical_name: main

repo: duckythescientist/obfuscatedLife

variable_types: O int


repo: duffrohde/RaadhusLED

decompiled_code:
__int64 __fastcall setup_shader(const char *a1)
{
unsigned int v1; // ebp
__int64 v2; // rbx
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = load_shader(a1, 0x8B30u);
if ( v1 )
{
v2 = (unsigned int)glCreateProgramObjectARB();
glAttachObjectARB(v2, v1);
glLinkProgramARB((unsigned int)v2);
glGetObjectParameterivARB((unsigned int)v2, 35714LL, v4);
if ( !v4[0] )
{
fwrite("shader linking failed\n", 1uLL, 0x16uLL, stderr);
LODWORD(v2) = 0;
}
}
else
{
fwrite("shader loading failed\n", 1uLL, 0x16uLL, stderr);
LODWORD(v2) = 0;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
unsigned int v1; // ebp
__int64 v2; // rbx
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = func0(a1, 0x8B30u);
if ( v1 )
{
v2 = (unsigned int)glCreateProgramObjectARB();
glAttachObjectARB(v2, v1);
glLinkProgramARB((unsigned int)v2);
glGetObjectParameterivARB((unsigned int)v2, 35714LL, v4);
if ( !v4[0] )
{
fwrite("shader linking failed\n", 1uLL, 0x16uLL, stderr);
LODWORD(v2) = 0;
}
}
else
{
fwrite("shader loading failed\n", 1uLL, 0x16uLL, stderr);
LODWORD(v2) = 0;
}
return (unsigned int)v2;
}

original_code:
unsigned int setup_shader(const char *fname) {
 unsigned int prog, sdr;
 int linked;
 sdr = load_shader(fname, 0x8B30);
 if(!sdr) {
  fprintf(stderr, "shader loading failed\n");
  return 0;
 }
 prog = glCreateProgramObjectARB();
 glAttachObjectARB(prog, sdr);
 glLinkProgramARB(prog);
 glGetObjectParameterivARB(prog, 0x8B82, &linked);
 if(!linked) {
  fprintf(stderr, "shader linking failed\n");
  return 0;
 }
 return prog;
}

canonical_original_code:
unsigned int setup_shader(char *fname) {
 unsigned int prog; unsigned int sdr;
 int linked;
 sdr = load_shader(fname, 0x8B30);
 if(!sdr) {
  fprintf(stderr, "shader loading failed\n");
  return 0;
 }
 prog = glCreateProgramObjectARB();
 glAttachObjectARB(prog, sdr);
 glLinkProgramARB(prog);
 glGetObjectParameterivARB(prog, 0x8B82, &linked);
 if(!linked) {
  fprintf(stderr, "shader linking failed\n");
  return 0;
 }
 return prog;
}

variable_types:
fname
char *

variable_types:
prog
unsigned int

variable_types:
sdr
unsigned int

variable_types: linked int

return_type: unsigned int


decompiled_code:
__int64 __fastcall setup_shader_vertex(const char *a1, const char *a2)
{
unsigned int v2; // ebx
unsigned int v3; // er12
unsigned int v4; // ebp
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = load_shader(a1, 0x8B30u);
if ( v2 && (v3 = load_shader(a2, 0x8B31u)) != 0 )
{
v4 = glCreateProgramObjectARB();
glAttachObjectARB(v4, v2);
glAttachObjectARB(v4, v3);
glLinkProgramARB(v4);
glGetObjectParameterivARB(v4, 35714LL, v6);
if ( !v6[0] )
{
fwrite("shader linking failed\n", 1uLL, 0x16uLL, stderr);
v4 = 0;
}
}
else
{
fwrite("shader loading failed\n", 1uLL, 0x16uLL, stderr);
v4 = 0;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
unsigned int v2; // ebx
unsigned int v3; // er12
unsigned int v4; // ebp
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = func0(a1, 0x8B30u);
if ( v2 && (v3 = func0(a2, 0x8B31u)) != 0 )
{
v4 = glCreateProgramObjectARB();
glAttachObjectARB(v4, v2);
glAttachObjectARB(v4, v3);
glLinkProgramARB(v4);
glGetObjectParameterivARB(v4, 35714LL, v6);
if ( !v6[0] )
{
fwrite("shader linking failed\n", 1uLL, 0x16uLL, stderr);
v4 = 0;
}
}
else
{
fwrite("shader loading failed\n", 1uLL, 0x16uLL, stderr);
v4 = 0;
}
return v4;
}

original_code:
unsigned int setup_shader_vertex(const char *fname_frag, const char *fname_vertex) {
 unsigned int prog, sdr_frag, sdr_vertex;
 int linked;
 sdr_frag = load_shader(fname_frag, 0x8B30);
 if(!sdr_frag) {
  fprintf(stderr, "shader loading failed\n");
  return 0;
 }
 sdr_vertex = load_shader(fname_vertex, 0x8B31);
 if(!sdr_vertex) {
  fprintf(stderr, "shader loading failed\n");
  return 0;
 }
 prog = glCreateProgramObjectARB();
 glAttachObjectARB(prog, sdr_frag);
 glAttachObjectARB(prog, sdr_vertex);
 glLinkProgramARB(prog);
 glGetObjectParameterivARB(prog, 0x8B82, &linked);
 if(!linked) {
  fprintf(stderr, "shader linking failed\n");
  return 0;
 }
 return prog;
}

canonical_original_code:
unsigned int setup_shader_vertex(char *fname_frag, char *fname_vertex) {
 unsigned int prog; unsigned int sdr_frag; unsigned int sdr_vertex;
 int linked;
 sdr_frag = load_shader(fname_frag, 0x8B30);
 if(!sdr_frag) {
  fprintf(stderr, "shader loading failed\n");
  return 0;
 }
 sdr_vertex = load_shader(fname_vertex, 0x8B31);
 if(!sdr_vertex) {
  fprintf(stderr, "shader loading failed\n");
  return 0;
 }
 prog = glCreateProgramObjectARB();
 glAttachObjectARB(prog, sdr_frag);
 glAttachObjectARB(prog, sdr_vertex);
 glLinkProgramARB(prog);
 glGetObjectParameterivARB(prog, 0x8B82, &linked);
 if(!linked) {
  fprintf(stderr, "shader linking failed\n");
  return 0;
 }
 return prog;
}


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

result = glGetUniformLocationARB();
if ( (_DWORD)result != -1 )
result = glUniform1f((unsigned int)result, a1);
return result;
}

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

result = glGetUniformLocationARB();
if ( (_DWORD)result != -1 )
result = glUniform1f((unsigned int)result, a1);
return result;
}

original_code:
void set_uniform1f(unsigned int prog, const char *name, float val) {
 int loc = glGetUniformLocationARB(prog, name);
 if(loc != -1) {
  glUniform1f(loc, val);
 }
}

canonical_original_code:
void set_uniform1f(unsigned int prog, char *name, float val) {
 int loc = glGetUniformLocationARB(prog, name);
 if(loc != -1) {
  glUniform1f(loc, val);
 }
}

variable_types:
name
char *

variable_types: val float

variable_types: loc int

return_type: void


decompiled_code:
__int64 __fastcall set_uniform2f(float a1, float a2)
{
__int64 result; // rax

result = glGetUniformLocationARB();
if ( (_DWORD)result != -1 )
result = glUniform2f((unsigned int)result, a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(float a1, float a2)
{
__int64 result; // rax

result = glGetUniformLocationARB();
if ( (_DWORD)result != -1 )
result = glUniform2f((unsigned int)result, a1, a2);
return result;
}

original_code:
void set_uniform2f(unsigned int prog, const char *name, float v1, float v2) {
 int loc = glGetUniformLocationARB(prog, name);
 if(loc != -1) {
  glUniform2f(loc, v1, v2);
 }
}

canonical_original_code:
void set_uniform2f(unsigned int prog, char *name, float v1, float v2) {
 int loc = glGetUniformLocationARB(prog, name);
 if(loc != -1) {
  glUniform2f(loc, v1, v2);
 }
}


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

result = glGetUniformLocationARB();
if ( (_DWORD)result != -1 )
result = glUniform1i((unsigned int)result, a3);
return result;
}

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

result = glGetUniformLocationARB();
if ( (_DWORD)result != -1 )
result = glUniform1i((unsigned int)result, a3);
return result;
}

original_code:
void set_uniform1i(unsigned int prog, const char *name, int val) {
 int loc = glGetUniformLocationARB(prog, name);
 if(loc != -1) {
  glUniform1i(loc, val);
 }
}

canonical_original_code:
void set_uniform1i(unsigned int prog, char *name, int val) {
 int loc = glGetUniformLocationARB(prog, name);
 if(loc != -1) {
  glUniform1i(loc, val);
 }
}

variable_types: val int


decompiled_code:
__int64 set_shader()
{
return glUseProgramObjectARB();
}

canonical_decompiled_code:
__int64 func6()
{
return glUseProgramObjectARB();
}

original_code:
void set_shader(unsigned int prog) {
 glUseProgramObjectARB(prog);
}


decompiled_code:
__int64 get_msec()
{
gettimeofday(&timeval_1, 0LL);
if ( (_QWORD)first_timeval_0 )
return (timeval_1.tv_usec - *((_QWORD *)&first_timeval_0 + 1)) / 1000 + 1000 * (timeval_1.tv_sec - first_timeval_0);
first_timeval_0 = (__int128)_mm_load_si128((const __m128i *)&timeval_1);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
gettimeofday(&timeval_1, 0LL);
if ( (_QWORD)first_timeval_0 )
return (timeval_1.tv_usec - *((_QWORD *)&first_timeval_0 + 1)) / 1000 + 1000 * (timeval_1.tv_sec - first_timeval_0);
first_timeval_0 = (__int128)_mm_load_si128((const __m128i *)&timeval_1);
return 0LL;
}

original_code:
unsigned long get_msec(void) {
 static struct timeval timeval, first_timeval;
 gettimeofday(&timeval, 0);
 if(first_timeval.tv_sec == 0) {
  first_timeval = timeval;
  return 0;
 }
 return (timeval.tv_sec - first_timeval.tv_sec) * 1000 + (timeval.tv_usec - first_timeval.tv_usec) / 1000;
}

canonical_original_code:
unsigned long get_msec() {
 static struct timeval timeval; static struct timeval first_timeval;
 gettimeofday(&timeval, 0);
 if(first_timeval.tv_sec == 0) {
  first_timeval = timeval;
  return 0;
 }
 return (timeval.tv_sec - first_timeval.tv_sec) * 1000 + (timeval.tv_usec - first_timeval.tv_usec) / 1000;
}

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

return_type: unsigned long


repo: duskwuff/lmgdbserver

decompiled_code:
__int64 pump_gdb2icdi()
{
__int64 v0; // rbx
int v1; // ebp
char v2; // al
int v3; // er13
__int64 result; // rax
const char *v5; // rax

v0 = 1LL;
while ( 1 )
{
v1 = v0;
v2 = fgetc(stdin);
v3 = v0;
byte_4040FF[v0] = v2;
if ( v2 == -1 )
{
libusb_close();
exit(0);
}
if ( v2 == 3 && (int)v0 <= 2 )
break;
if ( v0 == 4092 )
{
fwrite("ICDI ERROR: Line too long!!\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
++v0;
if ( v2 == 35 )
{
buf[v3] = fgetc(stdin);
v3 = v1 + 2;
buf[v1 + 1] = fgetc(stdin);
buf[v1 + 2] = 0;
if ( trace )
fprintf(stderr, "ICDI <<- %s\n", buf);
break;
}
}
result = libusb_bulk_transfer();
if ( (_DWORD)result || v3 )
{
v5 = (const char *)libusb_error_name();
fprintf(stderr, "ICDI send error: %s\n", v5);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rbx
int v1; // ebp
char v2; // al
int v3; // er13
__int64 result; // rax
const char *v5; // rax

v0 = 1LL;
while ( 1 )
{
v1 = v0;
v2 = fgetc(stdin);
v3 = v0;
byte_4040FF[v0] = v2;
if ( v2 == -1 )
{
libusb_close();
exit(0);
}
if ( v2 == 3 && (int)v0 <= 2 )
break;
if ( v0 == 4092 )
{
fwrite("ICDI ERROR: Line too long!!\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
++v0;
if ( v2 == 35 )
{
buf[v3] = fgetc(stdin);
v3 = v1 + 2;
buf[v1 + 1] = fgetc(stdin);
buf[v1 + 2] = 0;
if ( trace )
fprintf(stderr, "ICDI <<- %s\n", buf);
break;
}
}
result = libusb_bulk_transfer();
if ( (_DWORD)result || v3 )
{
v5 = (const char *)libusb_error_name();
fprintf(stderr, "ICDI send error: %s\n", v5);
exit(1);
}
return result;
}

original_code:
void pump_gdb2icdi(int endpoint)
{
    int p = 0;
    int ch;
    do {
        ch = buf[p++] = fgetc(stdin);
        if (ch == -1) {
            libusb_close(lph);
            exit(0);
        }
        if (ch == 0x03 && p < 3)
            goto sendnow;
        if (p >= sizeof(buf) - 4) {
            fprintf(stderr, "ICDI ERROR: Line too long!!\n");
            exit(1);
        }
    } while (ch != '#');
    buf[p++] = fgetc(stdin);
    buf[p++] = fgetc(stdin);
    buf[p] = 0;
    if (trace) fprintf(stderr, "ICDI <<- %s\n", buf);
sendnow: ;
    int count = 0;
    int rc = libusb_bulk_transfer(lph, endpoint, (uint8_t *) buf, p, &count, 0);
    if (rc != 0 || count != p) {
        fprintf(stderr, "ICDI send error: %s\n", libusb_error_name(rc));
        exit(1);
    }
}

variable_types: endpoint int

variable_types: p int

variable_types: ch int

variable_types: count int

variable_types: rc int


decompiled_code:
int pump_icdi2gdb()
{
const char *v0; // rax
int result; // eax

if ( (unsigned int)libusb_bulk_transfer() )
{
v0 = (const char *)libusb_error_name();
result = fprintf(stderr, "ICDI recv error: %s\n", v0);
}
else
{
buf[0] = 0;
if ( trace )
fprintf(stderr, "ICDI ->> %s\n", buf);
fwrite(buf, 0LL, 1uLL, _bss_start);
result = fflush(_bss_start);
}
return result;
}

canonical_decompiled_code:
int func8()
{
const char *v0; // rax
int result; // eax

if ( (unsigned int)libusb_bulk_transfer() )
{
v0 = (const char *)libusb_error_name();
result = fprintf(stderr, "ICDI recv error: %s\n", v0);
}
else
{
buf[0] = 0;
if ( trace )
fprintf(stderr, "ICDI ->> %s\n", buf);
fwrite(buf, 0LL, 1uLL, _bss_start);
result = fflush(_bss_start);
}
return result;
}

original_code:
void pump_icdi2gdb(int endpoint)
{
    int count = 0;
again: ;
    int rc = libusb_bulk_transfer(lph, endpoint, (uint8_t *) buf, sizeof(buf), &count, 100);
    if (rc != 0) {
        fprintf(stderr, "ICDI recv error: %s\n", libusb_error_name(rc));
        return;
    }
    buf[count] = 0;
    if (trace) fprintf(stderr, "ICDI ->> %s\n", buf);
    fwrite(buf, count, 1, stdout);
    fflush(stdout);
    if(count == 1 && buf[0] == '+') goto again;
}


usage

decompiled_code:
int usage()
{
return fprintf(
stderr,
"USAGE: (gdb) target remote | %s [opts]\n"
" -h : this message\n"
" -t : enable ICDI command tracing\n"
" -v : increase libusb verbosity\n"
" -q : decrease libusb verbosity\n"
" -D : specify alternate VID:PID\n"
" default: -D %04x:%04x\n"
" -P : specify alternate interface & in/out endpoints\n"
" default: -P %02x:%02x:%02x\n",
(const char *)appname,
7358LL,
253LL,
2LL,
131LL,
2LL);
}

canonical_decompiled_code:
int func9()
{
return fprintf(
stderr,
"USAGE: (gdb) target remote | %s [opts]\n"
" -h : this message\n"
" -t : enable ICDI command tracing\n"
" -v : increase libusb verbosity\n"
" -q : decrease libusb verbosity\n"
" -D : specify alternate VID:PID\n"
" default: -D %04x:%04x\n"
" -P : specify alternate interface & in/out endpoints\n"
" default: -P %02x:%02x:%02x\n",
(const char *)appname,
7358LL,
253LL,
2LL,
131LL,
2LL);
}

original_code:
void usage()
{
    fprintf(stderr,
            "USAGE: (gdb) target remote | %s [opts]\n"
            "    -h : this message\n"
            "    -t : enable ICDI command tracing\n"
            "    -v : increase libusb verbosity\n"
            "    -q : decrease libusb verbosity\n"
            "    -D : specify alternate VID:PID\n"
            "         default: -D %04x:%04x\n"
            "    -P : specify alternate interface & in/out endpoints\n"
            "         default: -P %02x:%02x:%02x\n",
            appname,
            0x1cbe, 0x00fd,
            0x02, 0x83, 0x02
            );
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int result; // eax
const char *v5; // rax

appname = (__int64)*argv;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "htvqD:P:");
if ( v3 == -1 )
break;
if ( v3 != 68 )
{
usage();
return 1;
}
if ( (unsigned int)__isoc99_sscanf() != 2 )
usage();
}
if ( (unsigned int)libusb_init() )
{
v5 = (const char *)libusb_error_name();
fprintf(stderr, "ICDI: libusb init failed: %s\n", v5);
result = 1;
}
else
{
libusb_set_debug();
lph = libusb_open_device_with_vid_pid();
if ( lph )
{
if ( !(unsigned int)libusb_claim_interface() )
{
fwrite("ICDI connected\n", 1uLL, 0xFuLL, stderr);
if ( isatty(0) )
fwrite("(Good luck using this thing interactively. You'll need it.)\n", 1uLL, 0x3CuLL, stderr);
while ( 1 )
{
pump_gdb2icdi(2LL);
pump_icdi2gdb();
}
}
fwrite("ICDI: Couldn't claim interface!\n", 1uLL, 0x20uLL, stderr);
result = 1;
}
else
{
fwrite("ICDI: No LaunchPad found!\n", 1uLL, 0x1AuLL, stderr);
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int result; // eax
const char *v5; // rax

appname = (__int64)*argv;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "htvqD:P:");
if ( v3 == -1 )
break;
if ( v3 != 68 )
{
func9();
return 1;
}
if ( (unsigned int)__isoc99_sscanf() != 2 )
func9();
}
if ( (unsigned int)libusb_init() )
{
v5 = (const char *)libusb_error_name();
fprintf(stderr, "ICDI: libusb init failed: %s\n", v5);
result = 1;
}
else
{
libusb_set_debug();
lph = libusb_open_device_with_vid_pid();
if ( lph )
{
if ( !(unsigned int)libusb_claim_interface() )
{
fwrite("ICDI connected\n", 1uLL, 0xFuLL, stderr);
if ( isatty(0) )
fwrite("(Good luck using this thing interactively. You'll need it.)\n", 1uLL, 0x3CuLL, stderr);
while ( 1 )
{
func7(2LL);
func8();
}
}
fwrite("ICDI: Couldn't claim interface!\n", 1uLL, 0x20uLL, stderr);
result = 1;
}
else
{
fwrite("ICDI: No LaunchPad found!\n", 1uLL, 0x1AuLL, stderr);
result = 1;
}
}
return result;
}

original_code:
int main(int argc, char **argv)
{
    int lu_verbosity = 0;
    int icdi_vid = 0x1cbe;
    int icdi_pid = 0x00fd;
    int icdi_interface = 0x02;
    int icdi_ep_in = 0x83;
    int icdi_ep_out = 0x02;
    appname = argv[0];
    int ch;
    while ((ch = getopt(argc, argv, "htvqD:P:")) != -1) {
        switch (ch) {
            case 't':
                trace++;
                break;
            case 'h':
                usage();
                return 0;
            case 'v':
                lu_verbosity++;
                break;
            case 'q':
                lu_verbosity--;
                break;
            case 'D':
                if (sscanf(optarg, "%x:%x", &icdi_vid, &icdi_pid) != 2)
                    usage();
                break;
            case 'P':
                if (sscanf(optarg, "%x:%x:%x", &icdi_interface, &icdi_ep_in, &icdi_ep_out) != 3)
                    usage();
                break;
            default:
                usage();
                return 1;
        }
    }
    int rc;
    rc = libusb_init(((void *)0));
    if (rc != 0) {
        fprintf(stderr, "ICDI: libusb init failed: %s\n", libusb_error_name(rc));
        return 1;
    }
    libusb_set_debug(((void *)0), lu_verbosity);
    lph = libusb_open_device_with_vid_pid(((void *)0), icdi_vid, icdi_pid);
    if (lph == ((void *)0)) {
        fprintf(stderr, "ICDI: No LaunchPad found!\n");
        return 1;
    }
    rc = libusb_claim_interface(lph, icdi_interface);
    if (rc) {
        fprintf(stderr, "ICDI: Couldn't claim interface!\n");
        return 1;
    }
    fprintf(stderr, "ICDI connected\n");
    if (isatty(0))
        fprintf(stderr, "(Good luck using this thing interactively. You'll need it.)\n");
    for (;;) {
        pump_gdb2icdi(icdi_ep_out);
        pump_icdi2gdb(icdi_ep_in);
    }
}

variable_types: argc int

variable_types:
argv
char **


hola

repo: dvdalilue/sistemas

decompiled_code:
int hola()
{
return puts("Hola Mundo!");
}

canonical_decompiled_code:
int func8()
{
return puts("Hola Mundo!");
}

original_code:
void hola(){
    printf("Hola Mundo!\n");
}

canonical_original_code:
void hola(){
    printf("Hola Mundo!\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("%d\n", 1LL);
v4[0] = 1;
hola();
cambiar_cont(v4);
printf("%d\n", v4[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("%d\n", 1LL);
v4[0] = 1;
func8();
func7(v4);
printf("%d\n", v4[0]);
return 0;
}

original_code:
int main(){
    NUEVA_ESTRUCTURA nuevo;
    ESTRUCTURA_NUEVA2 nuevo2;
    printf("%d\n",1);
    nuevo.cont = 1;
    hola();
    cambiar_cont(&nuevo);
    printf("%d\n", nuevo.cont);
}

canonical_original_code:
int main(){
    struct nuevo nuevo;
    struct nuevo2 nuevo2;
    printf("%d\n",1);
    nuevo.cont = 1;
    hola();
    cambiar_cont(&nuevo);
    printf("%d\n", nuevo.cont);
}

variable_types:
nuevo
struct nuevo { int cont; }

user_defined_types:
struct nuevo { int cont; }
struct nuevo2 { char a; }


repo: dweinstein/vmxos-osx

decompiled_code:
void __noreturn guest_entry()
{
puts("VM_ENTER: inside guest\n");
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("VM_ENTER: inside guest\n");
while ( 1 )
;
}

original_code:
void guest_entry()
{
 puts("VM_ENTER: inside guest\n");
 while(1);
}


decompiled_code:
void __noreturn host_entry()
{
unsigned int v0; // ebx
const char *v1; // rax
const char *v2; // rax
const char *v3; // rax

v0 = vmx_vmread(17410LL);
puts("VM_EXIT: back to the host.. finally!\n");
puts("Exit reason:\n");
puts("- Basic exit reason: ");
puts((const char *)vmx_exit_reasons[(unsigned __int16)v0]);
puts("\n");
puts("- Pending MTF VM exit: ");
v1 = (const char *)dec2string((v0 >> 28) & 1);
puts(v1);
puts("\n");
puts("- VM exit from VMX root operation: ");
v2 = (const char *)dec2string((v0 >> 29) & 1);
puts(v2);
puts("\n");
puts("- VM-entry failure: ");
v3 = (const char *)dec2string(v0 >> 31);
puts(v3);
puts("\n");
sti();
vmx_vmresume();
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func1()
{
unsigned int v0; // ebx
const char *v1; // rax
const char *v2; // rax
const char *v3; // rax

v0 = vmx_vmread(17410LL);
puts("VM_EXIT: back to the host.. finally!\n");
puts("Exit reason:\n");
puts("- Basic exit reason: ");
puts((const char *)vmx_exit_reasons[(unsigned __int16)v0]);
puts("\n");
puts("- Pending MTF VM exit: ");
v1 = (const char *)dec2string((v0 >> 28) & 1);
puts(v1);
puts("\n");
puts("- VM exit from VMX root operation: ");
v2 = (const char *)dec2string((v0 >> 29) & 1);
puts(v2);
puts("\n");
puts("- VM-entry failure: ");
v3 = (const char *)dec2string(v0 >> 31);
puts(v3);
puts("\n");
sti();
vmx_vmresume();
while ( 1 )
;
}

original_code:
void host_entry()
{
 VM_EXIT_REASON_t er;
 *(unsigned int *) &er = vmx_vmread(0x00004402);
 puts("VM_EXIT: back to the host.. finally!\n");
 puts("Exit reason:\n");
 puts("- Basic exit reason: "); puts(vmx_exit_reasons[er.b0015_Basic_exit_reason]); puts("\n");
 puts("- Pending MTF VM exit: "); puts(dec2string(er.b28_Pending_MTF_VM_exit)); puts("\n");
 puts("- VM exit from VMX root operation: "); puts(dec2string(er.b29_VM_exit_from_VMX_root_operation)); puts("\n");
 puts("- VM-entry failure: "); puts(dec2string(er.b31_VM_entry_failure)); puts("\n");
 sti();
 vmx_vmresume();
 while(1);
}

canonical_original_code:
void host_entry()
{
 struct VM_EXIT_REASON_t er;
 *(unsigned int *) &er = vmx_vmread(0x00004402);
 puts("VM_EXIT: back to the host.. finally!\n");
 puts("Exit reason:\n");
 puts("- Basic exit reason: "); puts(vmx_exit_reasons[er.b0015_Basic_exit_reason]); puts("\n");
 puts("- Pending MTF VM exit: "); puts(dec2string(er.b28_Pending_MTF_VM_exit)); puts("\n");
 puts("- VM exit from VMX root operation: "); puts(dec2string(er.b29_VM_exit_from_VMX_root_operation)); puts("\n");
 puts("- VM-entry failure: "); puts(dec2string(er.b31_VM_entry_failure)); puts("\n");
 sti();
 vmx_vmresume();
 while(1);
}

variable_types: struct VM_EXIT_REASON_t { unsigned int b0015_Basic_exit_reason; unsigned int b2716_Reserved_zeros; unsigned int b28_Pending_MTF_VM_exit; unsigned int b29_VM_exit_from_VMX_root_operation; unsigned int b30_Reserved_zeros; unsigned int b31_VM_entry_failure; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
int v4; // ebx
int result; // eax
unsigned int v6; // ebx
const char *v7; // rax
const char *v8; // rax
const char *v9; // rdi
unsigned int v10; // eax
unsigned int v11; // ebx
int v12; // ebx
unsigned int v13; // eax
const char *v14; // rax
unsigned int v15; // eax
const char *v16; // rax
unsigned int v17; // eax
const char *v18; // rax
unsigned int v19; // eax
const char *v20; // rax
unsigned int v21; // eax
const char *v22; // rax
unsigned int v23; // eax
const char *v24; // rax
unsigned int v25; // eax
const char *v26; // rax
unsigned int v27; // eax
const char *v28; // rax
const char *v29; // rax
const char *v30; // rax
__int64 i; // rax
_DWORD *v32; // rax
_DWORD *v33; // rbx
__int64 v34; // rdx
const char *v35; // rax
const char *v36; // rax
const char *v37; // rax
const char *v38; // rdi
const char *v39; // rdi
const char *v40; // rdi
const char *v41; // rax
const char *v42; // rax
const char *v43; // rax
const char *v44; // rax
const char *v45; // rax
const char *v46; // rax
unsigned int v47; // eax
unsigned int v48; // eax
unsigned int v49; // eax
unsigned int v50; // eax
unsigned int v51; // eax
unsigned int v52; // eax
unsigned int v53; // eax
const char *v54; // rdi
int v55; // eax
const char *v56; // rax
const char *v57; // rax
const char *v58; // rax
const char *v59; // rax
const char *v60; // rax
const char *v61; // rax
const char *v62; // rax
const char *v63; // rax
const char *v64; // rdi
const char *v65; // rdi
__int64 v66; // [rsp+18h] [rbp-40h] BYREF
unsigned __int16 v67; // [rsp+26h] [rbp-32h]
__int64 v68; // [rsp+28h] [rbp-30h] BYREF
unsigned int v69; // [rsp+30h] [rbp-28h] BYREF
unsigned int v70; // [rsp+34h] [rbp-24h]
unsigned int v71; // [rsp+38h] [rbp-20h]
unsigned int v72; // [rsp+3Ch] [rbp-1Ch]

cls(argc, argv, envp);
puts("Welcome to VMXOS ");
puts(vmxos_version);
puts(" build ");
v3 = (const char *)dec2string((unsigned int)vmxos_build);
puts(v3);
puts("\n");
puts("Inizialising the kernel modules\n\n");
disable_A20();
v4 = check_A20();
puts("A20 : ");
if ( v4 )
{
puts("enabled\n");
}
else
{
puts("not enabled -> ");
puts("enabling A20 gate... ");
enable_A20();
if ( !(unsigned int)check_A20() )
return puts("failed\n");
puts("successed\n");
}
cpuid(&v69);
puts("CPUID : EAX -> ");
v56 = (const char *)hex2string(v69);
puts(v56);
puts(" = ");
v57 = (const char *)bin2string(v69);
puts(v57);
puts("\n");
puts(" : EBX -> ");
v58 = (const char *)hex2string(v70);
puts(v58);
puts(" = ");
v59 = (const char *)bin2string(v70);
puts(v59);
puts("\n");
puts(" : ECX -> ");
v60 = (const char *)hex2string(v71);
puts(v60);
puts(" = ");
v61 = (const char *)bin2string(v71);
puts(v61);
puts("\n");
puts(" : EDX -> ");
v62 = (const char *)hex2string(v72);
puts(v62);
puts(" = ");
v63 = (const char *)bin2string(v72);
puts(v63);
puts("\n");
puts("VMX : ");
v64 = "supported\n";
if ( (v71 & 0x20) == 0 )
v64 = "not supported\n";
puts(v64);
puts("MSR RW: ");
v65 = "supported\n";
if ( (v72 & 0x20) == 0 )
v65 = "not supported\n";
result = puts(v65);
if ( (v71 & 0x20) != 0 && (v72 & 0x20) != 0 )
{
v6 = vmx_read_eflags();
puts("EFLAGS: ");
v7 = (const char *)hex2string(v6);
puts(v7);
puts(" = ");
v8 = (const char *)bin2string(v6);
puts(v8);
puts("\n");
puts("VM86 Mode is ");
v9 = "on\n";
if ( (v6 & 0x20000) == 0 )
v9 = "off\n";
puts(v9);
v10 = vmx_read_cr4();
BYTE1(v10) |= 0x20u;
v11 = v10;
puts("Enabling CR4.VME ");
vmx_write_cr4(v11);
puts("[done]\n");
v12 = vmx_read_cr0();
puts("Enabling CR0.PE ");
vmx_write_cr0(v12 | 1u);
puts("[done]\n");
puts("Enabling CR0.NE ");
vmx_write_cr0(v12 | 0x21u);
puts("[done]\n");
puts("Enabling paging ");
enable_paging();
puts("[done]\n");
puts("CR0 : ");
v13 = vmx_read_cr0();
v14 = (const char *)hex2string(v13);
puts(v14);
puts(" = ");
v15 = vmx_read_cr0();
v16 = (const char *)bin2string(v15);
puts(v16);
puts("\n");
puts("CR2 : ");
v17 = vmx_read_cr2();
v18 = (const char *)hex2string(v17);
puts(v18);
puts(" = ");
v19 = vmx_read_cr2();
v20 = (const char *)bin2string(v19);
puts(v20);
puts("\n");
puts("CR3 : ");
v21 = vmx_read_cr3();
v22 = (const char *)hex2string(v21);
puts(v22);
puts(" = ");
v23 = vmx_read_cr3();
v24 = (const char *)bin2string(v23);
puts(v24);
puts("\n");
puts("CR4 : ");
v25 = vmx_read_cr4();
v26 = (const char *)hex2string(v25);
puts(v26);
puts(" = ");
v27 = vmx_read_cr4();
v28 = (const char *)bin2string(v27);
puts(v28);
puts("\n");
remap_pic(32LL, 40LL);
mask_irq(0LL);
puts("Inizializing interrupt handlers ");
init_exceptions();
puts("[done]\n");
sti();
v68 = 0LL;
puts("Reading MSR 0xA3");
vmx_read_msr(58LL, &v68);
puts(" -> ");
v29 = (const char *)bin2string((unsigned int)v68);
puts(v29);
puts("\n");
if ( (v68 & 1) != 0 )
{
puts("MSR 0x3A already locked\n");
}
else
{
puts("Locking MSR...\n");
v68 |= 1uLL;
vmx_write_msr(58LL, &v68);
puts("MSR 0x3A locked -> ");
v30 = (const char *)bin2string((unsigned int)v68);
puts(v30);
puts("\n");
}
vmx_read_msr(1152LL, &v68);
vmxon_ptr = 647168LL;
vmcs_ptr = 651264LL;
for ( i = 647168LL; i != 651264; i += 4LL )
*(_DWORD *)i = 0;
MEMORY[0x9E000] = v68;
v32 = (_DWORD *)vmcs_ptr;
v33 = (_DWORD *)vmcs_ptr;
v34 = vmcs_ptr + 4096LL;
do
*v32++ = 0;
while ( (_DWORD *)v34 != v32 );
*v33 = v68;
puts("VMX revID: ");
v35 = (const char *)hex2string((unsigned int)*v33);
puts(v35);
puts(" - ");
puts("vmx region at: ");
v36 = (const char *)hex2string(vmxon_ptr);
puts(v36);
puts(" - ");
puts("vmcs region at: ");
v37 = (const char *)hex2string(vmcs_ptr);
puts(v37);
puts("\n");
puts("Entering VMX mode ");
v38 = "success\n";
if ( !(unsigned int)vmx_vmxon() )
v38 = "failed\n";
puts(v38);
puts("Clearing VMCS region ");
v39 = "success\n";
if ( !(unsigned int)vmx_vmclear() )
v39 = "failed\n";
puts(v39);
puts("Loading VMCS pointer ");
v40 = "success\n";
if ( !(unsigned int)vmx_vmptrld() )
v40 = "failed\n";
puts(v40);
break_point();
sgdt();
puts("GDTR base : ");
v41 = (const char *)hex2string(*(unsigned int *)((char *)&gdtr + 2));
puts(v41);
puts("\n");
puts("GDTR limit: ");
v42 = (const char *)hex2string(gdtr);
puts(v42);
puts("\n");
puts("IDTR base : ");
v43 = (const char *)hex2string(*(unsigned int *)((char *)&idtr + 2));
puts(v43);
puts("\n");
puts("IDTR limit: ");
v44 = (const char *)hex2string(idtr);
puts(v44);
puts("\n");
v66 = 0LL;
vmx_vmwrite(3072LL, (unsigned __int16)__ES__);
vmx_vmwrite(3074LL, (unsigned __int16)__CS__);
vmx_vmwrite(3076LL, (unsigned __int16)__SS__);
vmx_vmwrite(3078LL, (unsigned __int16)__DS__);
vmx_vmwrite(3080LL, (unsigned __int16)__FS__);
v67 = __GS__;
vmx_vmwrite(3082LL, (unsigned __int16)__GS__);
vmx_vmwrite(3084LL, 24LL);
vmx_vmwrite(10240LL, 0xFFFFFFFFLL);
vmx_vmwrite(10241LL, 0xFFFFFFFFLL);
vmx_read_msr(473LL, &v66);
vmx_vmwrite(10242LL, (unsigned int)v66);
vmx_vmwrite(10243LL, HIDWORD(v66));
puts("Guest_IA32_DEBUGCTL_full: ");
v45 = (const char *)hex2string((unsigned int)v66);
puts(v45);
puts("\n");
puts("Guest_IA32_DEBUGCTL_high: ");
v46 = (const char *)hex2string(HIDWORD(v66));
puts(v46);
puts("\n");
vmx_vmwrite(0x4000LL, 31LL);
vmx_vmwrite(16386LL, 67234290LL);
vmx_vmwrite(16396LL, 224767LL);
vmx_vmwrite(16402LL, 4607LL);
vmx_vmwrite(16398LL, 0LL);
vmx_vmwrite(16400LL, 0LL);
vmx_vmwrite(16404LL, 0LL);
vmx_vmwrite(16406LL, 0LL);
vmx_vmwrite(8208LL, 0LL);
vmx_vmwrite(8209LL, 0LL);
vmx_vmwrite(16390LL, 0LL);
vmx_vmwrite(16392LL, 0LL);
vmx_vmwrite(16394LL, 0LL);
vmx_vmwrite(24584LL, 0LL);
vmx_vmwrite(24586LL, 0LL);
vmx_vmwrite(24588LL, 0LL);
vmx_vmwrite(24590LL, 0LL);
v67 = __ES__;
vmx_vmwrite(2048LL, (unsigned __int16)__ES__);
v67 = __CS__;
vmx_vmwrite(2050LL, (unsigned __int16)__CS__);
v67 = __SS__;
vmx_vmwrite(2052LL, (unsigned __int16)__SS__);
v67 = __DS__;
vmx_vmwrite(2054LL, (unsigned __int16)__DS__);
v67 = __FS__;
vmx_vmwrite(2056LL, (unsigned __int16)__FS__);
v67 = __GS__;
vmx_vmwrite(2058LL, (unsigned __int16)__GS__);
__asm { sldt [rsp+58h+var_32] }
vmx_vmwrite(2060LL, v67);
vmx_vmwrite(2062LL, 24LL);
vmx_vmwrite(18434LL, 0xFFFFFFFFLL);
vmx_vmwrite(18432LL, 0xFFFFFFFFLL);
vmx_vmwrite(18436LL, 0xFFFFFFFFLL);
vmx_vmwrite(18438LL, 0xFFFFFFFFLL);
vmx_vmwrite(18440LL, 0xFFFFFFFFLL);
vmx_vmwrite(18442LL, 0xFFFFFFFFLL);
vmx_vmwrite(18444LL, 0xFFFFLL);
vmx_vmwrite(18446LL, 255LL);
vmx_vmwrite(18448LL, gdtr);
vmx_vmwrite(18450LL, idtr);
vmx_vmwrite(26650LL, 1024LL);
vmx_vmwrite(18468LL, 0LL);
vmx_vmwrite(18470LL, 0LL);
vmx_vmwrite(18454LL, 49307LL);
vmx_vmwrite(18452LL, 49299LL);
vmx_vmwrite(18456LL, 49299LL);
vmx_vmwrite(18458LL, 49299LL);
vmx_vmwrite(18460LL, 49299LL);
vmx_vmwrite(18462LL, 49299LL);
vmx_vmwrite(18464LL, 0x10000LL);
vmx_vmwrite(18466LL, 139LL);
vmx_read_msr(372LL, &v66);
vmx_vmwrite(18474LL, (unsigned int)v66);
v47 = vmx_read_cr0();
vmx_vmwrite(26624LL, v47);
v48 = vmx_read_cr3();
vmx_vmwrite(26626LL, v48);
v49 = vmx_read_cr4();
vmx_vmwrite(26628LL, v49);
vmx_vmwrite(26630LL, 0LL);
vmx_vmwrite(26632LL, 0LL);
vmx_vmwrite(26634LL, 0LL);
vmx_vmwrite(26636LL, 0LL);
vmx_vmwrite(26638LL, 0LL);
vmx_vmwrite(26640LL, 0LL);
vmx_vmwrite(26642LL, 0LL);
vmx_vmwrite(26644LL, 0LL);
vmx_vmwrite(26646LL, *(unsigned int *)((char *)&gdtr + 2));
vmx_vmwrite(26648LL, *(unsigned int *)((char *)&idtr + 2));
v50 = vmx_read_eflags();
vmx_vmwrite(26656LL, v50);
vmx_read_msr(373LL, &v66);
vmx_vmwrite(26660LL, (unsigned int)v66);
vmx_read_msr(374LL, &v66);
vmx_vmwrite(26662LL, (unsigned int)v66);
v51 = vmx_read_cr0();
vmx_vmwrite(27648LL, v51);
v52 = vmx_read_cr3();
vmx_vmwrite(27650LL, v52);
v53 = vmx_read_cr4();
vmx_vmwrite(27652LL, v53);
vmx_vmwrite(27654LL, 0LL);
vmx_vmwrite(27656LL, 0LL);
vmx_vmwrite(27658LL, 0LL);
vmx_vmwrite(27660LL, *(unsigned int *)((char *)&gdtr + 2));
vmx_vmwrite(27662LL, *(unsigned int *)((char *)&idtr + 2));
vmx_vmwrite(26652LL, 589824LL);
vmx_vmwrite(26654LL, (unsigned int)guest_entry);
vmx_vmwrite(27668LL, 589824LL);
vmx_vmwrite(27670LL, (unsigned int)host_entry);
if ( !(unsigned int)vmx_vmlaunch() )
{
puts("IMPOSSIBILE LANCIARE LA VM\nError #");
v55 = vmx_vmread(17408LL);
puts((const char *)vmx_instruction_errors[v55]);
puts("\n");
}
puts("Leaving VMX mode ");
v54 = "success\n";
if ( !(unsigned int)vmx_vmxoff() )
v54 = "failed\n";
puts(v54);
puts("Type something: ");
while ( 1 )
;
}
return result;
}

original_code:
void main()
{
 CPUID_t cpu;
 CR4_t cr4;
 CR0_t cr0;
 EFLAGS_t eflags;
 unsigned int a20;
 cls();
 puts("Welcome to VMXOS "); puts(vmxos_version); puts(" build "); puts(dec2string(vmxos_build)); puts("\n");
 puts("Inizialising the kernel modules\n\n");
 disable_A20();
 a20 = check_A20();
 puts("A20   : "); puts(a20 ? "enabled\n" : "not enabled -> ");
 if (!a20)
 {
  puts("enabling A20 gate... ");
  enable_A20();
  if (check_A20())
  {
   puts("successed\n");
  }
  else
  {
   puts("failed\n");
   return;
  }
 }
 cpuid(&cpu);
 puts("CPUID : EAX -> "); puts(hex2string(cpu.eax)); puts(" = "); puts(bin2string(cpu.eax)); puts("\n");
 puts("      : EBX -> "); puts(hex2string(cpu.ebx)); puts(" = "); puts(bin2string(cpu.ebx)); puts("\n");
 puts("      : ECX -> "); puts(hex2string(*(unsigned int *) &cpu.ecx)); puts(" = "); puts(bin2string(*(unsigned int *) &cpu.ecx)); puts("\n");
 puts("      : EDX -> "); puts(hex2string(*(unsigned int *) &cpu.edx)); puts(" = "); puts(bin2string(*(unsigned int *) &cpu.edx)); puts("\n");
 puts("VMX   : "); puts(cpu.ecx.b05_VMX ? "supported\n" : "not supported\n");
 puts("MSR RW: "); puts(cpu.edx.b05_MSR ? "supported\n" : "not supported\n");
 if (!cpu.ecx.b05_VMX || !cpu.edx.b05_MSR) return;
 *(unsigned int *) &eflags = vmx_read_eflags();
 puts("EFLAGS: "); puts(hex2string(*(unsigned int *) &eflags)); puts(" = "); puts(bin2string(*(unsigned int *) &eflags)); puts("\n");
 puts("VM86 Mode is "); puts(eflags.b17_VM ? "on\n" : "off\n");
 *(unsigned int *) &cr4 = vmx_read_cr4();
 cr4.b13_VMXE = 1;
 puts("Enabling CR4.VME "); vmx_write_cr4(*(unsigned int *) &cr4); puts("[done]\n");
 *(unsigned int *) &cr0 = vmx_read_cr0();
 cr0.b00_PE = 1; puts("Enabling CR0.PE "); vmx_write_cr0(*(unsigned int *) &cr0); puts("[done]\n");
 cr0.b05_NE = 1; puts("Enabling CR0.NE "); vmx_write_cr0(*(unsigned int *) &cr0); puts("[done]\n");
 puts("Enabling paging "); enable_paging(); puts("[done]\n");
 puts("CR0   : "); puts(hex2string(vmx_read_cr0())); puts(" = "); puts(bin2string(vmx_read_cr0())); puts("\n");
 puts("CR2   : "); puts(hex2string(vmx_read_cr2())); puts(" = "); puts(bin2string(vmx_read_cr2())); puts("\n");
 puts("CR3   : "); puts(hex2string(vmx_read_cr3())); puts(" = "); puts(bin2string(vmx_read_cr3())); puts("\n");
 puts("CR4   : "); puts(hex2string(vmx_read_cr4())); puts(" = "); puts(bin2string(vmx_read_cr4())); puts("\n");
 remap_pic(0x20, 0x28);
 mask_irq(0);
 puts("Inizializing interrupt handlers "); init_exceptions(); puts("[done]\n");
 sti();
 unsigned long long nl = 0;
 puts("Reading MSR 0xA3");
 vmx_read_msr(0x3A, &nl);
 puts(" -> "); puts(bin2string(nl)); puts("\n");
 if (!(nl & 1))
 {
  puts("Locking MSR...\n");
  nl |= 1;
  vmx_write_msr(0x3A, &nl);
  puts("MSR 0x3A locked -> "); puts(bin2string(nl)); puts("\n");
 }
 else
 {
  puts("MSR 0x3A already locked\n");
 }
 vmx_read_msr(0x480, &nl);
 vmxon_ptr = 0x9E000;
 vmcs_ptr = 0x9F000;
 int i;
 unsigned int* reg;
 reg = (unsigned int*)vmxon_ptr;
 for(i = 0; i < 1024; i++) reg[i] = 0;
 reg[0] = nl;
 reg = (unsigned int*)vmcs_ptr;
 for(i = 0; i < 1024; i++) reg[i] = 0;
 reg[0] = nl;
 puts("VMX revID: "); puts(hex2string(*reg));
 puts(" - "); puts("vmx region at: "); puts(hex2string(vmxon_ptr));
 puts(" - "); puts("vmcs region at: "); puts(hex2string(vmcs_ptr)); puts("\n");
 puts("Entering VMX mode "); puts(vmx_vmxon() ? "success\n" : "failed\n");
 puts("Clearing VMCS region "); puts(vmx_vmclear() ? "success\n" : "failed\n");
 puts("Loading VMCS pointer "); puts(vmx_vmptrld() ? "success\n" : "failed\n");
 break_point();
 sgdt();
 puts("GDTR base : "); puts(hex2string(gdtr.base)); puts("\n");
 puts("GDTR limit: "); puts(hex2string(gdtr.limit)); puts("\n");
 puts("IDTR base : "); puts(hex2string(idtr.base)); puts("\n");
 puts("IDTR limit: "); puts(hex2string(idtr.limit)); puts("\n");
 unsigned char u8 = 0;
 unsigned short u16 = 0;
 unsigned int u32 = 0;
 unsigned long long u64 = 0;
 asm("mov %%es, %0" : "=m" (u16)); vmx_vmwrite(0x00000C00, u16);
 asm("mov %%cs, %0" : "=m" (u16)); vmx_vmwrite(0x00000C02, u16);
 asm("mov %%ss, %0" : "=m" (u16)); vmx_vmwrite(0x00000C04, u16);
 asm("mov %%ds, %0" : "=m" (u16)); vmx_vmwrite(0x00000C06, u16);
 asm("mov %%fs, %0" : "=m" (u16)); vmx_vmwrite(0x00000C08, u16);
 asm("mov %%gs, %0" : "=m" (u16)); vmx_vmwrite(0x00000C0A, u16);
                                  vmx_vmwrite(0x00000C0C, 0x18);
 vmx_vmwrite(0x00002800, 0xFFFFFFFF);
 vmx_vmwrite(0x00002801, 0xFFFFFFFF);
 vmx_read_msr(0x000001D9, &u64);
 vmx_vmwrite(0x00002802, u64);
 vmx_vmwrite(0x00002803, u64>>32);
 puts("Guest_IA32_DEBUGCTL_full: "); puts(hex2string(u64)); puts("\n");
 puts("Guest_IA32_DEBUGCTL_high: "); puts(hex2string(u64>>32)); puts("\n");
 vmx_vmwrite(0x00004000, 0x1f);
 vmx_vmwrite(0x00004002, 0x0401E9F2);
 vmx_vmwrite(0x0000400C, 0x36dff);
 vmx_vmwrite(0x00004012, 0x11ff);
 vmx_vmwrite(0x0000400E, 0);
 vmx_vmwrite(0x00004010, 0);
 vmx_vmwrite(0x00004014, 0);
 vmx_vmwrite(0x00004016, 0);
 vmx_vmwrite(0x00002010, 0);
 vmx_vmwrite(0x00002011, 0);
 vmx_vmwrite(0x00004006, 0);
 vmx_vmwrite(0x00004008, 0);
 vmx_vmwrite(0x0000400A, 0);
 vmx_vmwrite(0x00006008, 0);
 vmx_vmwrite(0x0000600A, 0);
 vmx_vmwrite(0x0000600C, 0);
 vmx_vmwrite(0x0000600E, 0);
 asm("mov %%es, %0" : "=m" (u16)); vmx_vmwrite(0x00000800, u16);
 asm("mov %%cs, %0" : "=m" (u16)); vmx_vmwrite(0x00000802, u16);
 asm("mov %%ss, %0" : "=m" (u16)); vmx_vmwrite(0x00000804, u16);
 asm("mov %%ds, %0" : "=m" (u16)); vmx_vmwrite(0x00000806, u16);
 asm("mov %%fs, %0" : "=m" (u16)); vmx_vmwrite(0x00000808, u16);
 asm("mov %%gs, %0" : "=m" (u16)); vmx_vmwrite(0x0000080A, u16);
 asm("sldt %0" : "=m" (u16)); vmx_vmwrite(0x0000080C, u16);
                                  vmx_vmwrite(0x0000080E, 0x18);
 vmx_vmwrite(0x00004802, 0XFFFFFFFF);
 vmx_vmwrite(0x00004800, 0XFFFFFFFF);
 vmx_vmwrite(0x00004804, 0XFFFFFFFF);
 vmx_vmwrite(0x00004806, 0XFFFFFFFF);
 vmx_vmwrite(0x00004808, 0XFFFFFFFF);
 vmx_vmwrite(0x0000480A, 0XFFFFFFFF);
 vmx_vmwrite(0x0000480C, 0xFFFF);
 vmx_vmwrite(0x0000480E, 0xFF);
 vmx_vmwrite(0x00004810, gdtr.limit);
 vmx_vmwrite(0x00004812, idtr.limit);
 vmx_vmwrite(0x0000681A, 0x400);
 vmx_vmwrite(0x00004824, 0);
 vmx_vmwrite(0x00004826, 0);
 vmx_vmwrite(0x00004816, 0xC09B);
 vmx_vmwrite(0x00004814, 0xC093);
 vmx_vmwrite(0x00004818, 0xC093);
 vmx_vmwrite(0x0000481A, 0xC093);
 vmx_vmwrite(0x0000481C, 0xC093);
 vmx_vmwrite(0x0000481E, 0xC093);
 vmx_vmwrite(0x00004820, 0x00010000);
 vmx_vmwrite(0x00004822, 0x8b);
 vmx_read_msr(0x00000174, &u64);
 vmx_vmwrite(0x0000482A, u64);
 vmx_vmwrite(0x00006800, vmx_read_cr0());
 vmx_vmwrite(0x00006802, vmx_read_cr3());
 vmx_vmwrite(0x00006804, vmx_read_cr4());
 vmx_vmwrite(0x00006806, 0);
 vmx_vmwrite(0x00006808, 0);
 vmx_vmwrite(0x0000680A, 0);
 vmx_vmwrite(0x0000680C, 0);
 vmx_vmwrite(0x0000680E, 0);
 vmx_vmwrite(0x00006810, 0);
 vmx_vmwrite(0x00006812, 0);
 vmx_vmwrite(0x00006814, 0);
 vmx_vmwrite(0x00006816, gdtr.base);
 vmx_vmwrite(0x00006818, idtr.base);
 *(unsigned int *) &eflags = vmx_read_eflags();
 vmx_vmwrite(0x00006820, *(unsigned int *) &eflags);
 vmx_read_msr(0x00000175, &u64);
 vmx_vmwrite(0x00006824, u64);
 vmx_read_msr(0x00000176, &u64);
 vmx_vmwrite(0x00006826, u64);
 vmx_vmwrite(0x00006C00, vmx_read_cr0());
 vmx_vmwrite(0x00006C02, vmx_read_cr3());
 vmx_vmwrite(0x00006C04, vmx_read_cr4());
 vmx_vmwrite(0x00006C06, 0);
 vmx_vmwrite(0x00006C08, 0);
 vmx_vmwrite(0x00006C0A, 0);
 vmx_vmwrite(0x00006C0C, gdtr.base);
 vmx_vmwrite(0x00006C0E, idtr.base);
 vmx_vmwrite(0x0000681C, 0x90000);
 vmx_vmwrite(0x0000681E, guest_entry);
 vmx_vmwrite(0x00006C14, 0x90000);
 vmx_vmwrite(0x00006C16, host_entry);
 if (!vmx_vmlaunch())
 {
  puts("IMPOSSIBILE LANCIARE LA VM\nError #");
  puts(vmx_instruction_errors[vmx_vmread(0x00004400)]);
  puts("\n");
 }
 puts("Leaving VMX mode "); puts(vmx_vmxoff() ? "success\n" : "failed\n");
 puts("Type something: ");
 while(1);
}

canonical_original_code:
void main()
{
 struct CPUID_t cpu;
 struct CR4_t cr4;
 struct CR0_t cr0;
 struct EFLAGS_t eflags;
 unsigned int a20;
 cls();
 puts("Welcome to VMXOS "); puts(vmxos_version); puts(" build "); puts(dec2string(vmxos_build)); puts("\n");
 puts("Inizialising the kernel modules\n\n");
 disable_A20();
 a20 = check_A20();
 puts("A20   : "); puts(a20 ? "enabled\n" : "not enabled -> ");
 if (!a20)
 {
  puts("enabling A20 gate... ");
  enable_A20();
  if (check_A20())
  {
   puts("successed\n");
  }
  else
  {
   puts("failed\n");
   return;
  }
 }
 cpuid(&cpu);
 puts("CPUID : EAX -> "); puts(hex2string(cpu.eax)); puts(" = "); puts(bin2string(cpu.eax)); puts("\n");
 puts("      : EBX -> "); puts(hex2string(cpu.ebx)); puts(" = "); puts(bin2string(cpu.ebx)); puts("\n");
 puts("      : ECX -> "); puts(hex2string(*(unsigned int *) &cpu.ecx)); puts(" = "); puts(bin2string(*(unsigned int *) &cpu.ecx)); puts("\n");
 puts("      : EDX -> "); puts(hex2string(*(unsigned int *) &cpu.edx)); puts(" = "); puts(bin2string(*(unsigned int *) &cpu.edx)); puts("\n");
 puts("VMX   : "); puts(cpu.ecx.b05_VMX ? "supported\n" : "not supported\n");
 puts("MSR RW: "); puts(cpu.edx.b05_MSR ? "supported\n" : "not supported\n");
 if (!cpu.ecx.b05_VMX || !cpu.edx.b05_MSR) return;
 *(unsigned int *) &eflags = vmx_read_eflags();
 puts("EFLAGS: "); puts(hex2string(*(unsigned int *) &eflags)); puts(" = "); puts(bin2string(*(unsigned int *) &eflags)); puts("\n");
 puts("VM86 Mode is "); puts(eflags.b17_VM ? "on\n" : "off\n");
 *(unsigned int *) &cr4 = vmx_read_cr4();
 cr4.b13_VMXE = 1;
 puts("Enabling CR4.VME "); vmx_write_cr4(*(unsigned int *) &cr4); puts("[done]\n");
 *(unsigned int *) &cr0 = vmx_read_cr0();
 cr0.b00_PE = 1; puts("Enabling CR0.PE "); vmx_write_cr0(*(unsigned int *) &cr0); puts("[done]\n");
 cr0.b05_NE = 1; puts("Enabling CR0.NE "); vmx_write_cr0(*(unsigned int *) &cr0); puts("[done]\n");
 puts("Enabling paging "); enable_paging(); puts("[done]\n");
 puts("CR0   : "); puts(hex2string(vmx_read_cr0())); puts(" = "); puts(bin2string(vmx_read_cr0())); puts("\n");
 puts("CR2   : "); puts(hex2string(vmx_read_cr2())); puts(" = "); puts(bin2string(vmx_read_cr2())); puts("\n");
 puts("CR3   : "); puts(hex2string(vmx_read_cr3())); puts(" = "); puts(bin2string(vmx_read_cr3())); puts("\n");
 puts("CR4   : "); puts(hex2string(vmx_read_cr4())); puts(" = "); puts(bin2string(vmx_read_cr4())); puts("\n");
 remap_pic(0x20, 0x28);
 mask_irq(0);
 puts("Inizializing interrupt handlers "); init_exceptions(); puts("[done]\n");
 sti();
 unsigned long long nl = 0;
 puts("Reading MSR 0xA3");
 vmx_read_msr(0x3A, &nl);
 puts(" -> "); puts(bin2string(nl)); puts("\n");
 if (!(nl & 1))
 {
  puts("Locking MSR...\n");
  nl |= 1;
  vmx_write_msr(0x3A, &nl);
  puts("MSR 0x3A locked -> "); puts(bin2string(nl)); puts("\n");
 }
 else
 {
  puts("MSR 0x3A already locked\n");
 }
 vmx_read_msr(0x480, &nl);
 vmxon_ptr = 0x9E000;
 vmcs_ptr = 0x9F000;
 int i;
 unsigned int *reg;
 reg = (unsigned int *)vmxon_ptr;
 for(i = 0; i < 1024; i++) reg[i] = 0;
 reg[0] = nl;
 reg = (unsigned int *)vmcs_ptr;
 for(i = 0; i < 1024; i++) reg[i] = 0;
 reg[0] = nl;
 puts("VMX revID: "); puts(hex2string(*reg));
 puts(" - "); puts("vmx region at: "); puts(hex2string(vmxon_ptr));
 puts(" - "); puts("vmcs region at: "); puts(hex2string(vmcs_ptr)); puts("\n");
 puts("Entering VMX mode "); puts(vmx_vmxon() ? "success\n" : "failed\n");
 puts("Clearing VMCS region "); puts(vmx_vmclear() ? "success\n" : "failed\n");
 puts("Loading VMCS pointer "); puts(vmx_vmptrld() ? "success\n" : "failed\n");
 break_point();
 sgdt();
 puts("GDTR base : "); puts(hex2string(gdtr.base)); puts("\n");
 puts("GDTR limit: "); puts(hex2string(gdtr.limit)); puts("\n");
 puts("IDTR base : "); puts(hex2string(idtr.base)); puts("\n");
 puts("IDTR limit: "); puts(hex2string(idtr.limit)); puts("\n");
 unsigned char u8 = 0;
 unsigned short u16 = 0;
 unsigned int u32 = 0;
 unsigned long long u64 = 0;
 asm("mov %%es, %0" : "=m" (u16)); vmx_vmwrite(0x00000C00, u16);
 asm("mov %%cs, %0" : "=m" (u16)); vmx_vmwrite(0x00000C02, u16);
 asm("mov %%ss, %0" : "=m" (u16)); vmx_vmwrite(0x00000C04, u16);
 asm("mov %%ds, %0" : "=m" (u16)); vmx_vmwrite(0x00000C06, u16);
 asm("mov %%fs, %0" : "=m" (u16)); vmx_vmwrite(0x00000C08, u16);
 asm("mov %%gs, %0" : "=m" (u16)); vmx_vmwrite(0x00000C0A, u16);
                                  vmx_vmwrite(0x00000C0C, 0x18);
 vmx_vmwrite(0x00002800, 0xFFFFFFFF);
 vmx_vmwrite(0x00002801, 0xFFFFFFFF);
 vmx_read_msr(0x000001D9, &u64);
 vmx_vmwrite(0x00002802, u64);
 vmx_vmwrite(0x00002803, u64>>32);
 puts("Guest_IA32_DEBUGCTL_full: "); puts(hex2string(u64)); puts("\n");
 puts("Guest_IA32_DEBUGCTL_high: "); puts(hex2string(u64>>32)); puts("\n");
 vmx_vmwrite(0x00004000, 0x1f);
 vmx_vmwrite(0x00004002, 0x0401E9F2);
 vmx_vmwrite(0x0000400C, 0x36dff);
 vmx_vmwrite(0x00004012, 0x11ff);
 vmx_vmwrite(0x0000400E, 0);
 vmx_vmwrite(0x00004010, 0);
 vmx_vmwrite(0x00004014, 0);
 vmx_vmwrite(0x00004016, 0);
 vmx_vmwrite(0x00002010, 0);
 vmx_vmwrite(0x00002011, 0);
 vmx_vmwrite(0x00004006, 0);
 vmx_vmwrite(0x00004008, 0);
 vmx_vmwrite(0x0000400A, 0);
 vmx_vmwrite(0x00006008, 0);
 vmx_vmwrite(0x0000600A, 0);
 vmx_vmwrite(0x0000600C, 0);
 vmx_vmwrite(0x0000600E, 0);
 asm("mov %%es, %0" : "=m" (u16)); vmx_vmwrite(0x00000800, u16);
 asm("mov %%cs, %0" : "=m" (u16)); vmx_vmwrite(0x00000802, u16);
 asm("mov %%ss, %0" : "=m" (u16)); vmx_vmwrite(0x00000804, u16);
 asm("mov %%ds, %0" : "=m" (u16)); vmx_vmwrite(0x00000806, u16);
 asm("mov %%fs, %0" : "=m" (u16)); vmx_vmwrite(0x00000808, u16);
 asm("mov %%gs, %0" : "=m" (u16)); vmx_vmwrite(0x0000080A, u16);
 asm("sldt %0" : "=m" (u16)); vmx_vmwrite(0x0000080C, u16);
                                  vmx_vmwrite(0x0000080E, 0x18);
 vmx_vmwrite(0x00004802, 0XFFFFFFFF);
 vmx_vmwrite(0x00004800, 0XFFFFFFFF);
 vmx_vmwrite(0x00004804, 0XFFFFFFFF);
 vmx_vmwrite(0x00004806, 0XFFFFFFFF);
 vmx_vmwrite(0x00004808, 0XFFFFFFFF);
 vmx_vmwrite(0x0000480A, 0XFFFFFFFF);
 vmx_vmwrite(0x0000480C, 0xFFFF);
 vmx_vmwrite(0x0000480E, 0xFF);
 vmx_vmwrite(0x00004810, gdtr.limit);
 vmx_vmwrite(0x00004812, idtr.limit);
 vmx_vmwrite(0x0000681A, 0x400);
 vmx_vmwrite(0x00004824, 0);
 vmx_vmwrite(0x00004826, 0);
 vmx_vmwrite(0x00004816, 0xC09B);
 vmx_vmwrite(0x00004814, 0xC093);
 vmx_vmwrite(0x00004818, 0xC093);
 vmx_vmwrite(0x0000481A, 0xC093);
 vmx_vmwrite(0x0000481C, 0xC093);
 vmx_vmwrite(0x0000481E, 0xC093);
 vmx_vmwrite(0x00004820, 0x00010000);
 vmx_vmwrite(0x00004822, 0x8b);
 vmx_read_msr(0x00000174, &u64);
 vmx_vmwrite(0x0000482A, u64);
 vmx_vmwrite(0x00006800, vmx_read_cr0());
 vmx_vmwrite(0x00006802, vmx_read_cr3());
 vmx_vmwrite(0x00006804, vmx_read_cr4());
 vmx_vmwrite(0x00006806, 0);
 vmx_vmwrite(0x00006808, 0);
 vmx_vmwrite(0x0000680A, 0);
 vmx_vmwrite(0x0000680C, 0);
 vmx_vmwrite(0x0000680E, 0);
 vmx_vmwrite(0x00006810, 0);
 vmx_vmwrite(0x00006812, 0);
 vmx_vmwrite(0x00006814, 0);
 vmx_vmwrite(0x00006816, gdtr.base);
 vmx_vmwrite(0x00006818, idtr.base);
 *(unsigned int *) &eflags = vmx_read_eflags();
 vmx_vmwrite(0x00006820, *(unsigned int *) &eflags);
 vmx_read_msr(0x00000175, &u64);
 vmx_vmwrite(0x00006824, u64);
 vmx_read_msr(0x00000176, &u64);
 vmx_vmwrite(0x00006826, u64);
 vmx_vmwrite(0x00006C00, vmx_read_cr0());
 vmx_vmwrite(0x00006C02, vmx_read_cr3());
 vmx_vmwrite(0x00006C04, vmx_read_cr4());
 vmx_vmwrite(0x00006C06, 0);
 vmx_vmwrite(0x00006C08, 0);
 vmx_vmwrite(0x00006C0A, 0);
 vmx_vmwrite(0x00006C0C, gdtr.base);
 vmx_vmwrite(0x00006C0E, idtr.base);
 vmx_vmwrite(0x0000681C, 0x90000);
 vmx_vmwrite(0x0000681E, guest_entry);
 vmx_vmwrite(0x00006C14, 0x90000);
 vmx_vmwrite(0x00006C16, host_entry);
 if (!vmx_vmlaunch())
 {
  puts("IMPOSSIBILE LANCIARE LA VM\nError #");
  puts(vmx_instruction_errors[vmx_vmread(0x00004400)]);
  puts("\n");
 }
 puts("Leaving VMX mode "); puts(vmx_vmxoff() ? "success\n" : "failed\n");
 puts("Type something: ");
 while(1);
}

variable_types: struct CPUID_t { unsigned int eax; unsigned int ebx; struct CPUID_ECX_t { unsigned int b00_SSE3; unsigned int b01_PCLMUL; unsigned int b02_DTES64; unsigned int b03_MON; unsigned int b04_DSCPL; unsigned int b05_VMX; unsigned int b06_SMX; unsigned int b07_EST; unsigned int b08_TM2; unsigned int b09_SSSE3; unsigned int b10_CID; unsigned int b11_res; unsigned int b12_FMA; unsigned int b13_CX16; unsigned int b14_ETPRD; unsigned int b15_PDCM; unsigned int b16_res; unsigned int b17_res; unsigned int b18_DCA; unsigned int b19_SSE4_1; unsigned int b20_SSE4_2; unsigned int b21_x2APIC; unsigned int b22_MOVBE; unsigned int b23_POPCNT; unsigned int b24_res; unsigned int b25_AES; unsigned int b26_XSAVE; unsigned int b27_OSXSAVE; unsigned int b28_AVX; unsigned int b29_res; unsigned int b30_res; unsigned int b31_res; } ecx; struct CPUID_EDX_t { unsigned int b00_FPU; unsigned int b01_VME; unsigned int b02_DE; unsigned int b03_PSE; unsigned int b04_TSC; unsigned int b05_MSR; unsigned int b06_PAE; unsigned int b07_MCE; unsigned int b08_CX8; unsigned int b09_APIC; unsigned int b10_res; unsigned int b11_SEP; unsigned int b12_MTRR; unsigned int b13_PGE; unsigned int b14_MCA; unsigned int b15_CMOV; unsigned int b16_PAT; unsigned int b17_PSE36; unsigned int b18_PSN; unsigned int b19_CLFL; unsigned int b20_res; unsigned int b21_DTES; unsigned int b22_ACPI; unsigned int b23_MMX; unsigned int b24_FXSR; unsigned int b25_SSE; unsigned int b26_SSE2; unsigned int b27_SS; unsigned int b28_HTT; unsigned int b29_TM1; unsigned int b30_IA_64; unsigned int b31_PBE; } edx; }

variable_types: struct CR4_t { unsigned int b00_VME; unsigned int b01_PVI; unsigned int b02_TSD; unsigned int b03_DE; unsigned int b04_PSE; unsigned int b05_PAE; unsigned int b06_MCE; unsigned int b07_PGE; unsigned int b08_PCE; unsigned int b09_OSFXSR; unsigned int b10_OSXMMEXCPT; unsigned int b11_res; unsigned int b12_res; unsigned int b13_VMXE; unsigned int b14_SMXE; unsigned int b1531_res; }

variable_types: struct CR0_t { unsigned int b00_PE; unsigned int b01_MP; unsigned int b02_EM; unsigned int b03_TS; unsigned int b04_ET; unsigned int b05_NE; unsigned int b0615_res; unsigned int b16_WP; unsigned int b17_res; unsigned int b18_AM; unsigned int b1928_res; unsigned int b29_NW; unsigned int b30_CD; unsigned int b31_PG; }

variable_types: struct EFLAGS_t { unsigned int b00_CF; unsigned int b01_one; unsigned int b02_PF; unsigned int b03_zero; unsigned int b04_AF; unsigned int b05_zero; unsigned int b06_ZF; unsigned int b07_SF; unsigned int b08_TF; unsigned int b09_IF; unsigned int b10_DF; unsigned int b11_OF; unsigned int b12_OPPL; unsigned int b14_NT; unsigned int b15_zero; unsigned int b16_RF; unsigned int b17_VM; unsigned int b18_AC; unsigned int b19_VIF; unsigned int b20_VIP; unsigned int b21_ID; unsigned int b22_zero; }

variable_types:
nl
unsigned long long

variable_types: i int

variable_types:
reg
unsigned int *

user_defined_types: struct CPUID_t { unsigned int eax; unsigned int ebx; struct CPUID_ECX_t ecx; struct CPUID_EDX_t edx; }


decompiled_code:
__int64 __fastcall DS18X20_raw_to_decicelsius(char a1, unsigned __int16 *a2)
{
unsigned int v2; // eax
int v3; // edx
int v4; // edx
int v5; // eax
__int64 result; // rax
int v7; // edx
char v8; // cl
char v9; // dl
int v10; // edx

v2 = *a2;
if ( a1 == 16 )
v2 = ((8 * v2) & 0xFFFFFFF0) - *((unsigned __int8 *)a2 + 6) + 12;
if ( (v2 & 0x8000u) != 0 )
{
v2 = -v2;
if ( a1 != 40 && a1 != 34 )
{
HIWORD(v7) = HIWORD(v2);
LOWORD(v7) = (unsigned __int16)v2 >> 4;
v4 = 10 * v7;
v5 = 640 * (v2 & 0xF);
goto LABEL_21;
}
v8 = 1;
}
else
{
if ( a1 != 40 && a1 != 34 )
{
HIWORD(v3) = HIWORD(v2);
LOWORD(v3) = (unsigned __int16)v2 >> 4;
v4 = 10 * v3;
v5 = 640 * (v2 & 0xF);
LABEL_7:
LOWORD(v5) = (unsigned __int16)(v5 + 512) >> 10;
result = (unsigned int)(v4 + v5);
goto LABEL_8;
}
v8 = 0;
}
v9 = a2[2] & 0x60;
switch ( v9 )
{
case 32:
v2 &= 0xFFFFFFFC;
break;
case 64:
v2 &= 0xFFFFFFFE;
break;
case 0:
v2 &= 0xFFFFFFF8;
break;
}
HIWORD(v10) = HIWORD(v2);
LOWORD(v10) = (unsigned __int16)v2 >> 4;
v4 = 10 * v10;
v5 = 640 * (v2 & 0xF);
if ( !v8 )
goto LABEL_7;
LABEL_21:
LOWORD(v5) = (unsigned __int16)v5 >> 10;
result = (unsigned int)-(v4 + v5);
LABEL_8:
if ( (unsigned __int16)(result + 550) >= 0x709u )
result = 2000LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, unsigned __int16 *a2)
{
unsigned int v2; // eax
int v3; // edx
int v4; // edx
int v5; // eax
__int64 result; // rax
int v7; // edx
char v8; // cl
char v9; // dl
int v10; // edx

v2 = *a2;
if ( a1 == 16 )
v2 = ((8 * v2) & 0xFFFFFFF0) - *((unsigned __int8 *)a2 + 6) + 12;
if ( (v2 & 0x8000u) != 0 )
{
v2 = -v2;
if ( a1 != 40 && a1 != 34 )
{
HIWORD(v7) = HIWORD(v2);
LOWORD(v7) = (unsigned __int16)v2 >> 4;
v4 = 10 * v7;
v5 = 640 * (v2 & 0xF);
goto LABEL_21;
}
v8 = 1;
}
else
{
if ( a1 != 40 && a1 != 34 )
{
HIWORD(v3) = HIWORD(v2);
LOWORD(v3) = (unsigned __int16)v2 >> 4;
v4 = 10 * v3;
v5 = 640 * (v2 & 0xF);
LABEL_7:
LOWORD(v5) = (unsigned __int16)(v5 + 512) >> 10;
result = (unsigned int)(v4 + v5);
goto LABEL_8;
}
v8 = 0;
}
v9 = a2[2] & 0x60;
switch ( v9 )
{
case 32:
v2 &= 0xFFFFFFFC;
break;
case 64:
v2 &= 0xFFFFFFFE;
break;
case 0:
v2 &= 0xFFFFFFF8;
break;
}
HIWORD(v10) = HIWORD(v2);
LOWORD(v10) = (unsigned __int16)v2 >> 4;
v4 = 10 * v10;
v5 = 640 * (v2 & 0xF);
if ( !v8 )
goto LABEL_7;
LABEL_21:
LOWORD(v5) = (unsigned __int16)v5 >> 10;
result = (unsigned int)-(v4 + v5);
LABEL_8:
if ( (unsigned __int16)(result + 550) >= 0x709u )
result = 2000LL;
return result;
}

original_code:
static int16_t DS18X20_raw_to_decicelsius(uint8_t familycode, uint8_t sp[]) {
  uint16_t measure;
  uint8_t negative;
  int16_t decicelsius;
  uint16_t fract;
  measure = sp[0] | (sp[1] << 8);
  if(familycode == 0x10) {
    measure &= (uint16_t)0xfffe;
    measure <<= 3;
    measure += (16 - sp[6]) - 4;
  }
  if(measure & 0x8000) {
    negative = 1;
    measure ^= 0xffff;
    measure++;
  }
  else negative = 0;
  if(familycode == 0x28 || familycode == 0x22) {
    switch(sp[4] & ((1<<6)|(1<<5))) {
      case 0:
        measure &= ~(((1<<0)|(1<<1)|(1<<2)));
        break;
      case (1<<5):
        measure &= ~(((1<<0)|(1<<1)));
        break;
      case (1<<6):
        measure &= ~(((1<<0)));
        break;
      default: break;
    }
  }
  decicelsius = (measure >> 4);
  decicelsius *= 10;
  fract = (measure & 0x000F) * 640;
  if(!negative) fract += 512;
  fract /= 1024;
  decicelsius += fract;
  if (negative) decicelsius = -decicelsius;
  if ( decicelsius < -550 || decicelsius > 1250) return 2000;
  else return decicelsius;
}

canonical_original_code:
static short DS18X20_raw_to_decicelsius(unsigned char familycode, unsigned char sp[]) {
  unsigned short measure;
  unsigned char negative;
  short decicelsius;
  unsigned short fract;
  measure = sp[0] | (sp[1] << 8);
  if(familycode == 0x10) {
    measure &= (unsigned short)0xfffe;
    measure <<= 3;
    measure += (16 - sp[6]) - 4;
  }
  if(measure & 0x8000) {
    negative = 1;
    measure ^= 0xffff;
    measure++;
  }
  else negative = 0;
  if(familycode == 0x28 || familycode == 0x22) {
    switch(sp[4] & ((1<<6)|(1<<5))) {
      case 0:
        measure &= ~(((1<<0)|(1<<1)|(1<<2)));
        break;
      case (1<<5):
        measure &= ~(((1<<0)|(1<<1)));
        break;
      case (1<<6):
        measure &= ~(((1<<0)));
        break;
      default: break;
    }
  }
  decicelsius = (measure >> 4);
  decicelsius *= 10;
  fract = (measure & 0x000F) * 640;
  if(!negative) fract += 512;
  fract /= 1024;
  decicelsius += fract;
  if (negative) decicelsius = -decicelsius;
  if ( decicelsius < -550 || decicelsius > 1250) return 2000;
  else return decicelsius;
}

variable_types:
familycode
unsigned char

variable_types:
sp
unsigned char []

variable_types:
measure
unsigned short

variable_types:
negative
unsigned char

variable_types: decicelsius short

variable_types:
fract
unsigned short

return_type: short


decompiled_code:
__int64 __fastcall DS18X20_raw_to_maxres(char a1, unsigned __int16 *a2)
{
unsigned int v2; // edx
unsigned int v3; // eax
char v4; // cl
char v5; // dl
__int64 result; // rax

v2 = *a2;
v3 = v2;
if ( a1 == 16 )
{
v3 = ((8 * v2) & 0xFFFFFFF0) - *((unsigned __int8 *)a2 + 6);
LOWORD(v3) = ((8 * v2) & 0xFFF0) - *((unsigned __int8 *)a2 + 6) + 12;
if ( (v3 & 0x8000u) == 0 )
return 10000 * ((unsigned __int16)v3 >> 4) + 625 * (v3 & 0xF);
}
else
{
v4 = 0;
if ( (v2 & 0x8000u) == 0 )
goto LABEL_4;
}
v3 = -v3;
v4 = 1;
LABEL_4:
if ( a1 == 40 || a1 == 34 )
{
v5 = a2[2] & 0x60;
switch ( v5 )
{
case 32:
LOWORD(v3) = v3 & 0xFFFC;
break;
case 64:
LOWORD(v3) = v3 & 0xFFFE;
break;
case 0:
LOWORD(v3) = v3 & 0xFFF8;
break;
}
}
result = 10000 * ((unsigned __int16)v3 >> 4) + 625 * (v3 & 0xF);
if ( v4 )
result = (unsigned int)-(int)result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, unsigned __int16 *a2)
{
unsigned int v2; // edx
unsigned int v3; // eax
char v4; // cl
char v5; // dl
__int64 result; // rax

v2 = *a2;
v3 = v2;
if ( a1 == 16 )
{
v3 = ((8 * v2) & 0xFFFFFFF0) - *((unsigned __int8 *)a2 + 6);
LOWORD(v3) = ((8 * v2) & 0xFFF0) - *((unsigned __int8 *)a2 + 6) + 12;
if ( (v3 & 0x8000u) == 0 )
return 10000 * ((unsigned __int16)v3 >> 4) + 625 * (v3 & 0xF);
}
else
{
v4 = 0;
if ( (v2 & 0x8000u) == 0 )
goto LABEL_4;
}
v3 = -v3;
v4 = 1;
LABEL_4:
if ( a1 == 40 || a1 == 34 )
{
v5 = a2[2] & 0x60;
switch ( v5 )
{
case 32:
LOWORD(v3) = v3 & 0xFFFC;
break;
case 64:
LOWORD(v3) = v3 & 0xFFFE;
break;
case 0:
LOWORD(v3) = v3 & 0xFFF8;
break;
}
}
result = 10000 * ((unsigned __int16)v3 >> 4) + 625 * (v3 & 0xF);
if ( v4 )
result = (unsigned int)-(int)result;
return result;
}

original_code:
static int32_t DS18X20_raw_to_maxres( uint8_t familycode, uint8_t sp[]) {
  uint16_t measure;
  uint8_t negative;
  int32_t temperaturevalue;
  measure = sp[0] | (sp[1] << 8);
  if(familycode == 0x10) {
    measure &= (uint16_t)0xfffe;
    measure <<= 3;
    measure += ( 16 - sp[6] ) - 4;
  }
  if(measure & 0x8000) {
    negative = 1;
    measure ^= 0xffff;
    measure++;
  }
  else negative = 0;
  if(familycode == 0x28 || familycode == 0x22) {
    switch(sp[4] & ((1<<6)|(1<<5))) {
      case 0:
        measure &= ~(((1<<0)|(1<<1)|(1<<2)));
        break;
      case (1<<5):
        measure &= ~(((1<<0)|(1<<1)));
        break;
      case (1<<6):
        measure &= ~(((1<<0)));
        break;
      default: break;
    }
  }
  temperaturevalue = (measure >> 4);
  temperaturevalue *= 10000;
  temperaturevalue +=( measure & 0x000F ) * 625;
  if(negative) temperaturevalue = -temperaturevalue;
  return temperaturevalue;
}

canonical_original_code:
static int DS18X20_raw_to_maxres(unsigned char familycode, unsigned char sp[]) {
  unsigned short measure;
  unsigned char negative;
  int temperaturevalue;
  measure = sp[0] | (sp[1] << 8);
  if(familycode == 0x10) {
    measure &= (unsigned short)0xfffe;
    measure <<= 3;
    measure += ( 16 - sp[6] ) - 4;
  }
  if(measure & 0x8000) {
    negative = 1;
    measure ^= 0xffff;
    measure++;
  }
  else negative = 0;
  if(familycode == 0x28 || familycode == 0x22) {
    switch(sp[4] & ((1<<6)|(1<<5))) {
      case 0:
        measure &= ~(((1<<0)|(1<<1)|(1<<2)));
        break;
      case (1<<5):
        measure &= ~(((1<<0)|(1<<1)));
        break;
      case (1<<6):
        measure &= ~(((1<<0)));
        break;
      default: break;
    }
  }
  temperaturevalue = (measure >> 4);
  temperaturevalue *= 10000;
  temperaturevalue +=( measure & 0x000F ) * 625;
  if(negative) temperaturevalue = -temperaturevalue;
  return temperaturevalue;
}

variable_types: temperaturevalue int


decompiled_code:
__int64 __fastcall read_scratchpad(__int64 a1, _BYTE *a2, char a3)
{
_BYTE *v4; // rbx
__int64 v5; // rbp
__int64 result; // rax

ow_command(190LL, a1);
if ( a3 )
{
v4 = a2;
v5 = (__int64)&a2[(unsigned __int8)(a3 - 1) + 1];
do
*v4++ = ow_byte_rd();
while ( v4 != (_BYTE *)v5 );
}
result = crc8(a2, 9LL);
if ( (_BYTE)result )
result = 3LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _BYTE *a2, char a3)
{
_BYTE *v4; // rbx
__int64 v5; // rbp
__int64 result; // rax

ow_command(190LL, a1);
if ( a3 )
{
v4 = a2;
v5 = (__int64)&a2[(unsigned __int8)(a3 - 1) + 1];
do
*v4++ = ow_byte_rd();
while ( v4 != (_BYTE *)v5 );
}
result = crc8(a2, 9LL);
if ( (_BYTE)result )
result = 3LL;
return result;
}

original_code:
static uint8_t read_scratchpad(uint8_t id[], uint8_t sp[], uint8_t n) {
  uint8_t i;
  uint8_t ret;
  ow_command( 0xBE, id );
  for(i = 0; i < n; i++) sp[i] = ow_byte_rd();
  if (crc8(&sp[0], 9)) ret = 0x03;
  else ret = 0x00;
  return ret;
}

canonical_original_code:
static unsigned char read_scratchpad(unsigned char id[], unsigned char sp[], unsigned char n) {
  unsigned char i;
  unsigned char ret;
  ow_command( 0xBE, id );
  for(i = 0; i < n; i++) sp[i] = ow_byte_rd();
  if (crc8(&sp[0], 9)) ret = 0x03;
  else ret = 0x00;
  return ret;
}

variable_types:
id
unsigned char []

variable_types:
n
unsigned char

variable_types:
i
unsigned char

variable_types:
ret
unsigned char


decompiled_code:
__int64 __fastcall DS18X20_find_sensor(_BYTE *a1, unsigned __int8 *a2)
{
__int64 v2; // r12
char v3; // al
unsigned __int64 v4; // rax

v2 = 0x10400010000LL;
while ( 1 )
{
v3 = ow_rom_search((unsigned __int8)*a1, a2);
*a1 = v3;
if ( (unsigned __int8)(v3 - 1) > 0xFCu )
break;
v4 = *a2;
if ( (unsigned __int8)v4 <= 0x28u && _bittest64(&v2, v4) )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, unsigned __int8 *a2)
{
__int64 v2; // r12
char v3; // al
unsigned __int64 v4; // rax

v2 = 0x10400010000LL;
while ( 1 )
{
v3 = ow_rom_search((unsigned __int8)*a1, a2);
*a1 = v3;
if ( (unsigned __int8)(v3 - 1) > 0xFCu )
break;
v4 = *a2;
if ( (unsigned __int8)v4 <= 0x28u && _bittest64(&v2, v4) )
return 0LL;
}
return 1LL;
}

original_code:
uint8_t DS18X20_find_sensor(uint8_t *diff, uint8_t id[]) {
  uint8_t go;
  uint8_t ret;
  ret = 0x00;
  go = 1;
  do {
    *diff = ow_rom_search(*diff, &id[0]);
    if(*diff == 0xFF || *diff == 0xFE || *diff == 0x00) {
      go = 0;
      ret = 0x01;
    }
    else if(id[0] == 0x28 || id[0] == 0x10 || id[0] == 0x22) go = 0;
  } while(go);
  return ret;
}

canonical_original_code:
unsigned char DS18X20_find_sensor(unsigned char *diff, unsigned char id[]) {
  unsigned char go;
  unsigned char ret;
  ret = 0x00;
  go = 1;
  do {
    *diff = ow_rom_search(*diff, &id[0]);
    if(*diff == 0xFF || *diff == 0xFE || *diff == 0x00) {
      go = 0;
      ret = 0x01;
    }
    else if(id[0] == 0x28 || id[0] == 0x10 || id[0] == 0x22) go = 0;
  } while(go);
  return ret;
}

variable_types:
diff
unsigned char *

variable_types:
go
unsigned char


decompiled_code:
bool __fastcall DS18X20_get_power_status(__int64 a1)
{
char v1; // bl

ow_reset();
ow_command(180LL, a1);
v1 = ow_bit(1LL);
ow_reset();
return v1 != 0;
}

canonical_decompiled_code:
bool __fastcall func4(__int64 a1)
{
char v1; // bl

ow_reset();
ow_command(180LL, a1);
v1 = ow_bit(1LL);
ow_reset();
return v1 != 0;
}

original_code:
uint8_t DS18X20_get_power_status(uint8_t id[]) {
  uint8_t pstat;
  ow_reset();
  ow_command(0xB4, id);
  pstat = ow_bit(1);
  ow_reset();
  return (pstat) ? 0x01 : 0x00;
}

canonical_original_code:
unsigned char DS18X20_get_power_status(unsigned char id[]) {
  unsigned char pstat;
  ow_reset();
  ow_command(0xB4, id);
  pstat = ow_bit(1);
  ow_reset();
  return (pstat) ? 0x01 : 0x00;
}

variable_types:
pstat
unsigned char


decompiled_code:
__int64 __fastcall DS18X20_start_meas(__int64 a1, __int64 a2)
{
ow_reset();
ow_command(68LL, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
ow_reset();
ow_command(68LL, a2);
return 0LL;
}

original_code:
uint8_t DS18X20_start_meas(uint8_t with_power_extern, uint8_t id[]) {
  ow_reset();
  ow_command(0x44, id);
  return 0x00;
}

canonical_original_code:
unsigned char DS18X20_start_meas(unsigned char with_power_extern, unsigned char id[]) {
  ow_reset();
  ow_command(0x44, id);
  return 0x00;
}


decompiled_code:
bool DS18X20_conversion_in_progress()
{
return (unsigned __int8)ow_bit(1LL) == 0;
}

canonical_decompiled_code:
bool func6()
{
return (unsigned __int8)ow_bit(1LL) == 0;
}

original_code:
uint8_t DS18X20_conversion_in_progress(void) {
  return ow_bit(1) ? 0x00 : 0x01;
}

canonical_original_code:
unsigned char DS18X20_conversion_in_progress() {
  return ow_bit(1) ? 0x00 : 0x01;
}


decompiled_code:
__int64 __fastcall DS18X20_read_decicelsius(char *a1, _WORD *a2)
{
unsigned int v2; // ebx
unsigned __int16 v4[16]; // [rsp+7h] [rbp-21h] BYREF

ow_reset();
v2 = read_scratchpad((__int64)a1, v4, 9);
if ( !(_BYTE)v2 )
*a2 = DS18X20_raw_to_decicelsius(*a1, v4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, _WORD *a2)
{
unsigned int v2; // ebx
unsigned __int16 v4[16]; // [rsp+7h] [rbp-21h] BYREF

ow_reset();
v2 = func2((__int64)a1, v4, 9);
if ( !(_BYTE)v2 )
*a2 = func0(*a1, v4);
return v2;
}

original_code:
uint8_t DS18X20_read_decicelsius(uint8_t id[], int16_t *decicelsius) {
  uint8_t sp[9];
  uint8_t ret;
  ow_reset();
  ret = read_scratchpad(id, sp, 9);
  if(ret == 0x00) *decicelsius = DS18X20_raw_to_decicelsius(id[0], sp);
  return ret;
}

canonical_original_code:
unsigned char DS18X20_read_decicelsius(unsigned char id[], short *decicelsius) {
  unsigned char sp[9];
  unsigned char ret;
  ow_reset();
  ret = read_scratchpad(id, sp, 9);
  if(ret == 0x00) *decicelsius = DS18X20_raw_to_decicelsius(id[0], sp);
  return ret;
}

variable_types:
decicelsius
short *

variable_types:
sp
unsigned char [9]


decompiled_code:
__int64 __fastcall DS18X20_read_decicelsius_single(char a1, _WORD *a2)
{
unsigned int v2; // ebx
unsigned __int16 v4[16]; // [rsp+7h] [rbp-21h] BYREF

v2 = read_scratchpad(0LL, v4, 9);
if ( !(_BYTE)v2 )
*a2 = DS18X20_raw_to_decicelsius(a1, v4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1, _WORD *a2)
{
unsigned int v2; // ebx
unsigned __int16 v4[16]; // [rsp+7h] [rbp-21h] BYREF

v2 = func2(0LL, v4, 9);
if ( !(_BYTE)v2 )
*a2 = func0(a1, v4);
return v2;
}

original_code:
uint8_t DS18X20_read_decicelsius_single(uint8_t familycode, int16_t *decicelsius) {
  uint8_t sp[9];
  uint8_t ret;
  ret = read_scratchpad(((void *)0), sp, 9);
  if(ret == 0x00) *decicelsius = DS18X20_raw_to_decicelsius(familycode, sp);
  return ret;
}

canonical_original_code:
unsigned char DS18X20_read_decicelsius_single(unsigned char familycode, short *decicelsius) {
  unsigned char sp[9];
  unsigned char ret;
  ret = read_scratchpad(((void *)0), sp, 9);
  if(ret == 0x00) *decicelsius = DS18X20_raw_to_decicelsius(familycode, sp);
  return ret;
}


decompiled_code:
__int64 __fastcall DS18X20_read_maxres(char *a1, _DWORD *a2)
{
unsigned int v2; // ebx
unsigned __int16 v4[16]; // [rsp+7h] [rbp-21h] BYREF

ow_reset();
v2 = read_scratchpad((__int64)a1, v4, 9);
if ( !(_BYTE)v2 )
*a2 = DS18X20_raw_to_maxres(*a1, v4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, _DWORD *a2)
{
unsigned int v2; // ebx
unsigned __int16 v4[16]; // [rsp+7h] [rbp-21h] BYREF

ow_reset();
v2 = func2((__int64)a1, v4, 9);
if ( !(_BYTE)v2 )
*a2 = func1(*a1, v4);
return v2;
}

original_code:
uint8_t DS18X20_read_maxres(uint8_t id[], int32_t *temperaturevalue) {
  uint8_t sp[9];
  uint8_t ret;
  ow_reset();
  ret = read_scratchpad(id, sp, 9);
  if(ret == 0x00) *temperaturevalue = DS18X20_raw_to_maxres(id[0], sp);
  return ret;
}

canonical_original_code:
unsigned char DS18X20_read_maxres(unsigned char id[], int *temperaturevalue) {
  unsigned char sp[9];
  unsigned char ret;
  ow_reset();
  ret = read_scratchpad(id, sp, 9);
  if(ret == 0x00) *temperaturevalue = DS18X20_raw_to_maxres(id[0], sp);
  return ret;
}

variable_types:
temperaturevalue
int *


decompiled_code:
__int64 __fastcall DS18X20_read_maxres_single(char a1, _DWORD *a2)
{
unsigned int v2; // ebx
unsigned __int16 v4[16]; // [rsp+7h] [rbp-21h] BYREF

v2 = read_scratchpad(0LL, v4, 9);
if ( !(_BYTE)v2 )
*a2 = DS18X20_raw_to_maxres(a1, v4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(char a1, _DWORD *a2)
{
unsigned int v2; // ebx
unsigned __int16 v4[16]; // [rsp+7h] [rbp-21h] BYREF

v2 = func2(0LL, v4, 9);
if ( !(_BYTE)v2 )
*a2 = func1(a1, v4);
return v2;
}

original_code:
uint8_t DS18X20_read_maxres_single(uint8_t familycode, int32_t *temperaturevalue) {
  uint8_t sp[9];
  uint8_t ret;
  ret = read_scratchpad( ((void *)0), sp, 9 );
  if(ret == 0x00) *temperaturevalue = DS18X20_raw_to_maxres(familycode, sp);
  return ret;
}

canonical_original_code:
unsigned char DS18X20_read_maxres_single(unsigned char familycode, int *temperaturevalue) {
  unsigned char sp[9];
  unsigned char ret;
  ret = read_scratchpad( ((void *)0), sp, 9 );
  if(ret == 0x00) *temperaturevalue = DS18X20_raw_to_maxres(familycode, sp);
  return ret;
}

variable_types:
familycode
unsigned char


decompiled_code:
__int64 __fastcall DS18X20_format_from_maxres(int a1, __int64 a2, unsigned __int8 a3)
{
__int64 result; // rax
char v4; // r12
char v5; // bl
ldiv_t v6; // rax
char v7; // cl
int v8; // ecx
int v9; // edx
unsigned __int8 v10; // al
char v11[34]; // [rsp+0h] [rbp-22h]

if ( (unsigned int)(a1 + 999999) > 0xA7D8BE )
return 1LL;
result = 1LL;
if ( a3 > 9u )
{
v4 = 0;
if ( a1 < 0 )
{
a1 = -a1;
v4 = 1;
}
v5 = 0;
do
{
v6 = ldiv(a1, 10LL);
v7 = v6.rem;
LOBYTE(v6.rem) = v5++;
v11[SLOBYTE(v6.rem)] = v7 + 48;
a1 = v6.quot;
}
while ( SLODWORD(v6.quot) > 0 );
if ( v4 )
v11[v5] = 45;
else
v11[v5] = 43;
v8 = 0;
LOBYTE(v9) = 0;
if ( v5 >= 0 )
{
while ( 1 )
{
v10 = v5--;
v9 = v8 + 1;
*(_BYTE *)(a2 + (unsigned __int8)v8) = v11[v10];
if ( v5 == 3 )
{
*(_BYTE *)(a2 + (unsigned __int8)v9) = 46;
v9 = v8 + 2;
}
else if ( v5 < 0 )
{
break;
}
v8 = v9;
}
}
*(_BYTE *)(a2 + (unsigned __int8)v9) = 0;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, __int64 a2, unsigned __int8 a3)
{
__int64 result; // rax
char v4; // r12
char v5; // bl
ldiv_t v6; // rax
char v7; // cl
int v8; // ecx
int v9; // edx
unsigned __int8 v10; // al
char v11[34]; // [rsp+0h] [rbp-22h]

if ( (unsigned int)(a1 + 999999) > 0xA7D8BE )
return 1LL;
result = 1LL;
if ( a3 > 9u )
{
v4 = 0;
if ( a1 < 0 )
{
a1 = -a1;
v4 = 1;
}
v5 = 0;
do
{
v6 = ldiv(a1, 10LL);
v7 = v6.rem;
LOBYTE(v6.rem) = v5++;
v11[SLOBYTE(v6.rem)] = v7 + 48;
a1 = v6.quot;
}
while ( SLODWORD(v6.quot) > 0 );
if ( v4 )
v11[v5] = 45;
else
v11[v5] = 43;
v8 = 0;
LOBYTE(v9) = 0;
if ( v5 >= 0 )
{
while ( 1 )
{
v10 = v5--;
v9 = v8 + 1;
*(_BYTE *)(a2 + (unsigned __int8)v8) = v11[v10];
if ( v5 == 3 )
{
*(_BYTE *)(a2 + (unsigned __int8)v9) = 46;
v9 = v8 + 2;
}
else if ( v5 < 0 )
{
break;
}
v8 = v9;
}
}
*(_BYTE *)(a2 + (unsigned __int8)v9) = 0;
result = 0LL;
}
return result;
}

original_code:
uint8_t DS18X20_format_from_maxres(int32_t temperaturevalue, char str[], uint8_t n) {
  uint8_t sign = 0;
  char temp[10];
  int8_t temp_loc = 0;
  uint8_t str_loc = 0;
  ldiv_t ldt;
  uint8_t ret;
  if(n >= (9 + 1) && temperaturevalue > -1000000L && temperaturevalue < 10000000L) {
    if(temperaturevalue < 0) {
      sign = 1;
      temperaturevalue = -temperaturevalue;
    }
    do {
      ldt = ldiv(temperaturevalue, 10);
      temp[temp_loc++] = ldt.rem + '0';
      temperaturevalue = ldt.quot;
    } while(temperaturevalue > 0);
    if(sign) temp[temp_loc] = '-';
    else temp[temp_loc] = '+';
    while(temp_loc >= 0) {
      str[str_loc++] = temp[(uint8_t)temp_loc--];
      if(temp_loc == 3) str[str_loc++] = '.';
    }
    str[str_loc] = '\0';
    ret = 0x00;
  }
  else ret = 0x01;
  return ret;
}

canonical_original_code:
unsigned char DS18X20_format_from_maxres(int temperaturevalue, char str[], unsigned char n) {
  unsigned char sign = 0;
  char temp[10];
  char temp_loc = 0;
  unsigned char str_loc = 0;
  struct ldiv_t ldt;
  unsigned char ret;
  if(n >= (9 + 1) && temperaturevalue > -1000000L && temperaturevalue < 10000000L) {
    if(temperaturevalue < 0) {
      sign = 1;
      temperaturevalue = -temperaturevalue;
    }
    do {
      ldt = ldiv(temperaturevalue, 10);
      temp[temp_loc++] = ldt.rem + '0';
      temperaturevalue = ldt.quot;
    } while(temperaturevalue > 0);
    if(sign) temp[temp_loc] = '-';
    else temp[temp_loc] = '+';
    while(temp_loc >= 0) {
      str[str_loc++] = temp[(unsigned char)temp_loc--];
      if(temp_loc == 3) str[str_loc++] = '.';
    }
    str[str_loc] = '\0';
    ret = 0x00;
  }
  else ret = 0x01;
  return ret;
}

variable_types:
str
char []

variable_types:
sign
unsigned char

variable_types:
temp
char [10]

variable_types:
ldt
struct ldiv_t { long quot; long rem; }


decompiled_code:
__int64 __fastcall DS18X20_write_scratchpad(_BYTE *a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
ow_reset();
ow_command(78LL, a1);
ow_byte_wr(a2);
ow_byte_wr(a3);
if ( *a1 == 40 || *a1 == 34 )
ow_byte_wr(a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(_BYTE *a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
ow_reset();
ow_command(78LL, a1);
ow_byte_wr(a2);
ow_byte_wr(a3);
if ( *a1 == 40 || *a1 == 34 )
ow_byte_wr(a4);
return 0LL;
}

original_code:
uint8_t DS18X20_write_scratchpad(uint8_t id[], uint8_t th, uint8_t tl, uint8_t conf) {
  ow_reset();
  ow_command(0x4E, id);
  ow_byte_wr(th);
  ow_byte_wr(tl);
  if(id[0] == 0x28 || id[0] == 0x22) ow_byte_wr(conf);
  return 0x00;
}

canonical_original_code:
unsigned char DS18X20_write_scratchpad(unsigned char id[], unsigned char th, unsigned char tl, unsigned char conf) {
  ow_reset();
  ow_command(0x4E, id);
  ow_byte_wr(th);
  ow_byte_wr(tl);
  if(id[0] == 0x28 || id[0] == 0x22) ow_byte_wr(conf);
  return 0x00;
}

variable_types:
th
unsigned char

variable_types:
tl
unsigned char

variable_types:
conf
unsigned char


decompiled_code:
__int64 __fastcall DS18X20_read_scratchpad(__int64 a1, _BYTE *a2, char a3)
{
ow_reset();
return read_scratchpad(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, _BYTE *a2, char a3)
{
ow_reset();
return func2(a1, a2, a3);
}

original_code:
uint8_t DS18X20_read_scratchpad(uint8_t id[], uint8_t sp[], uint8_t n) {
  ow_reset();
  return read_scratchpad(id, sp, n);
}

canonical_original_code:
unsigned char DS18X20_read_scratchpad(unsigned char id[], unsigned char sp[], unsigned char n) {
  ow_reset();
  return read_scratchpad(id, sp, n);
}

variable_types:
id
unsigned char []

variable_types:
sp
unsigned char []

variable_types:
n
unsigned char