myRm

decompiled_code:
__int64 __fastcall myRm(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rcx
__int64 v4; // rax
int *v5; // r12
unsigned int v6; // er8
int v7; // edx
int *v8; // rax
__int64 v9; // rsi
__int64 v10; // rdx
__int64 result; // rax

v2 = buscaPosDirectorio(a1, a2);
if ( v2 == -1 )
{
fwrite("El archivo a borrar no existe\n", 1uLL, 0x1EuLL, stderr);
result = 1LL;
}
else
{
v3 = v2;
v4 = *(int *)(a1 + 24LL * v2 + 4136);
v5 = *(int **)(a1 + 8 * v4 + 6536);
v6 = v4;
v5[104] = 1;
v7 = *v5;
*(_DWORD *)(a1 + 20) += *v5;
if ( v7 > 0 )
{
v8 = v5 + 4;
v9 = (__int64)&v5[v7 - 1 + 5];
do
{
v10 = *v8++;
*(_DWORD *)(a1 + 4 * v10 + 36) = 0;
}
while ( v8 != (int *)v9 );
}
*(_DWORD *)(a1 + 24 * v3 + 4156) = 1;
escribeNodoI(a1, v6, v5);
escribeMapaDeBits(a1);
escribeSuperBloque(a1);
free(v5);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rcx
__int64 v4; // rax
int *v5; // r12
unsigned int v6; // er8
int v7; // edx
int *v8; // rax
__int64 v9; // rsi
__int64 v10; // rdx
__int64 result; // rax

v2 = buscaPosDirectorio(a1, a2);
if ( v2 == -1 )
{
fwrite("El archivo a borrar no existe\n", 1uLL, 0x1EuLL, stderr);
result = 1LL;
}
else
{
v3 = v2;
v4 = *(int *)(a1 + 24LL * v2 + 4136);
v5 = *(int **)(a1 + 8 * v4 + 6536);
v6 = v4;
v5[104] = 1;
v7 = *v5;
*(_DWORD *)(a1 + 20) += *v5;
if ( v7 > 0 )
{
v8 = v5 + 4;
v9 = (__int64)&v5[v7 - 1 + 5];
do
{
v10 = *v8++;
*(_DWORD *)(a1 + 4 * v10 + 36) = 0;
}
while ( v8 != (int *)v9 );
}
*(_DWORD *)(a1 + 24 * v3 + 4156) = 1;
escribeNodoI(a1, v6, v5);
escribeMapaDeBits(a1);
escribeSuperBloque(a1);
free(v5);
result = 0LL;
}
return result;
}

original_code:
int myRm(MiSistemaDeFicheros* miSistemaDeFicheros, char* nombreArchivo) {
 int posDirectorio = buscaPosDirectorio(miSistemaDeFicheros, nombreArchivo);
 if (posDirectorio == -1) {
  fprintf(stderr, "El archivo a borrar no existe\n");
  return 1;
 }
 int posNodoI =
   miSistemaDeFicheros->directorio.archivos[posDirectorio].idxNodoI;
 EstructuraNodoI *nodoI = miSistemaDeFicheros->nodosI[posNodoI];
 nodoI->libre = 1;
 miSistemaDeFicheros->superBloque.numBloquesLibres += nodoI->numBloques;
 int i;
 for (i = 0; i < nodoI->numBloques; i++) {
  miSistemaDeFicheros->mapaDeBits[nodoI->idxBloques[i]] = 0;
 }
 miSistemaDeFicheros->directorio.archivos[posDirectorio].libre = 1;
 escribeNodoI(miSistemaDeFicheros, posNodoI, nodoI);
 escribeMapaDeBits(miSistemaDeFicheros);
 escribeSuperBloque(miSistemaDeFicheros);
 free(nodoI);
 return 0;
}

canonical_original_code:
int myRm(struct MiSistemaDeFicheros *miSistemaDeFicheros, char *nombreArchivo) {
 int posDirectorio = buscaPosDirectorio(miSistemaDeFicheros, nombreArchivo);
 if (posDirectorio == -1) {
  fprintf(stderr, "El archivo a borrar no existe\n");
  return 1;
 }
 int posNodoI = miSistemaDeFicheros->directorio.archivos[posDirectorio].idxNodoI;
 struct EstructuraNodoI *nodoI = miSistemaDeFicheros->nodosI[posNodoI];
 nodoI->libre = 1;
 miSistemaDeFicheros->superBloque.numBloquesLibres += nodoI->numBloques;
 int i;
 for (i = 0; i < nodoI->numBloques; i++) {
  miSistemaDeFicheros->mapaDeBits[nodoI->idxBloques[i]] = 0;
 }
 miSistemaDeFicheros->directorio.archivos[posDirectorio].libre = 1;
 escribeNodoI(miSistemaDeFicheros, posNodoI, nodoI);
 escribeMapaDeBits(miSistemaDeFicheros);
 escribeSuperBloque(miSistemaDeFicheros);
 free(nodoI);
 return 0;
}

variable_types: posNodoI int

variable_types: i int


myLs

repo: elreplicante/simple-file-system

decompiled_code:
int __fastcall myLs(__int64 a1)
{
__int64 v1; // r14
int v2; // er12
__int64 *v3; // rbp
__int64 v4; // rbx
const char *v5; // rsi
__int64 v6; // rax
struct tm *v7; // rax
int result; // eax
char v9[168]; // [rsp+0h] [rbp-A8h] BYREF

v1 = a1 + 6540;
v2 = 0;
v3 = (__int64 *)(a1 + 6536);
v4 = a1 + 4140;
puts("Lista de archivos");
do
{
while ( *(_DWORD *)(v4 + 16) )
{
v4 += 24LL;
++v3;
if ( v4 == v1 )
goto LABEL_5;
}
v5 = (const char *)v4;
v4 += 24LL;
printf("%s\t", v5);
v6 = *v3;
++v2;
++v3;
printf("%d\t", *(unsigned int *)(v6 + 4));
v7 = localtime((const time_t *)(*(v3 - 1) + 8));
strftime(v9, 0x80uLL, "%d/%m/%y %H:%M:%S", v7);
puts(v9);
}
while ( v4 != v1 );
LABEL_5:
if ( v2 )
result = printf(aN, *(unsigned int *)(a1 + 4132));
else
result = puts(aDirectorioVac);
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
__int64 v1; // r14
int v2; // er12
__int64 *v3; // rbp
__int64 v4; // rbx
const char *v5; // rsi
__int64 v6; // rax
struct tm *v7; // rax
int result; // eax
char v9[168]; // [rsp+0h] [rbp-A8h] BYREF

v1 = a1 + 6540;
v2 = 0;
v3 = (__int64 *)(a1 + 6536);
v4 = a1 + 4140;
puts("Lista de archivos");
do
{
while ( *(_DWORD *)(v4 + 16) )
{
v4 += 24LL;
++v3;
if ( v4 == v1 )
goto LABEL_5;
}
v5 = (const char *)v4;
v4 += 24LL;
printf("%s\t", v5);
v6 = *v3;
++v2;
++v3;
printf("%d\t", *(unsigned int *)(v6 + 4));
v7 = localtime((const time_t *)(*(v3 - 1) + 8));
strftime(v9, 0x80uLL, "%d/%m/%y %H:%M:%S", v7);
puts(v9);
}
while ( v4 != v1 );
LABEL_5:
if ( v2 )
result = printf(aN, *(unsigned int *)(a1 + 4132));
else
result = puts(aDirectorioVac);
return result;
}

original_code:
void myLs(MiSistemaDeFicheros* miSistemaDeFicheros) {
 int numArchivosEncontrados = 0;
 int i;
 printf("%s\n", "Lista de archivos");
 for (i = 0; i < 100; i++) {
  if (miSistemaDeFicheros->directorio.archivos[i].libre == 0) {
   printf("%s\t",
     miSistemaDeFicheros->directorio.archivos[i].nombreArchivo);
   printf("%d\t", miSistemaDeFicheros->nodosI[i]->tamArchivo);
   struct tm *tlocal = localtime(
     &miSistemaDeFicheros->nodosI[i]->tiempoModificado);
   char output[128];
   strftime(output, 128, "%d/%m/%y %H:%M:%S", tlocal);
   printf("%s\n", output);
   numArchivosEncontrados++;
  }
 }
 if (numArchivosEncontrados == 0) {
  printf("Directorio vacío\n");
 } else {
  printf("Número total de archivos:%d\n",
    miSistemaDeFicheros->directorio.numArchivos);
 }
}

canonical_original_code:
void myLs(struct MiSistemaDeFicheros *miSistemaDeFicheros) {
 int numArchivosEncontrados = 0;
 int i;
 printf("%s\n", "Lista de archivos");
 for (i = 0; i < 100; i++) {
  if (miSistemaDeFicheros->directorio.archivos[i].libre == 0) {
   printf("%s\t",
     miSistemaDeFicheros->directorio.archivos[i].nombreArchivo);
   printf("%d\t", miSistemaDeFicheros->nodosI[i]->tamArchivo);
   struct tm *tlocal = localtime(
     &miSistemaDeFicheros->nodosI[i]->tiempoModificado);
   char output[128];
   strftime(output, 128, "%d/%m/%y %H:%M:%S", tlocal);
   printf("%s\n", output);
   numArchivosEncontrados++;
  }
 }
 if (numArchivosEncontrados == 0) {
  printf("Directorio vacío\n");
 } else {
  printf("Número total de archivos:%d\n",
    miSistemaDeFicheros->directorio.numArchivos);
 }
}

variable_types: struct MiSistemaDeFicheros { int discoVirtual; struct EstructuraSuperBloque { int tamSuperBloque; int tamDirectorio; int tamNodoI; int tamDiscoEnBloques; int numBloquesLibres; int tamBloque; int maxTamNombreArchivo; int maxBloquesPorArchivo; } superBloque; unsigned int mapaDeBits[-1]; struct EstructuraDirectorio { int numArchivos; struct EstructuraArchivo { int idxNodoI; char nombreArchivo[-1]; int libre; } archivos[100]; } directorio; struct EstructuraNodoI { int numBloques; int tamArchivo; long tiempoModificado; int idxBloques[100]; int libre; } *nodosI[-1]; int numNodosLibres; } *

variable_types: numArchivosEncontrados int

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

variable_types:
output
char [128]

return_type: void

user_defined_types: struct MiSistemaDeFicheros { int discoVirtual; struct EstructuraSuperBloque superBloque; unsigned int mapaDeBits[-1]; struct EstructuraDirectorio directorio; struct EstructuraNodoI *nodosI[-1]; int numNodosLibres; }

user_defined_types: struct EstructuraDirectorio { int numArchivos; struct EstructuraArchivo archivos[100]; }


myExit

decompiled_code:
void __fastcall __noreturn myExit(int *a1)
{
void **v1; // rbx
void **v2; // rbp
void *v3; // rdi

v1 = (void **)(a1 + 1634);
v2 = (void **)(a1 + 1724);
close(*a1);
do
{
v3 = *v1++;
free(v3);
*(v1 - 1) = 0LL;
}
while ( v1 != v2 );
exit(1);
}

original_code:
void myExit(MiSistemaDeFicheros* miSistemaDeFicheros) {
 int i;
 close(miSistemaDeFicheros->discoVirtual);
 for (i = 0; i < ((4096/sizeof(EstructuraNodoI)) * 5); i++) {
  free(miSistemaDeFicheros->nodosI[i]);
  miSistemaDeFicheros->nodosI[i] = ((void *)0);
 }
 exit(1);
}

canonical_original_code:
void myExit(struct MiSistemaDeFicheros *miSistemaDeFicheros) {
 int i;
 close(miSistemaDeFicheros->discoVirtual);
 for (i = 0; i < ((4096/sizeof(EstructuraNodoI)) * 5); i++) {
  free(miSistemaDeFicheros->nodosI[i]);
  miSistemaDeFicheros->nodosI[i] = ((void *)0);
 }
 exit(1);
}

user_defined_types: struct EstructuraSuperBloque { int tamSuperBloque; int tamDirectorio; int tamNodoI; int tamDiscoEnBloques; int numBloquesLibres; int tamBloque; int maxTamNombreArchivo; int maxBloquesPorArchivo; }

user_defined_types: struct EstructuraArchivo { int idxNodoI; char nombreArchivo[-1]; int libre; }

user_defined_types: struct EstructuraNodoI { int numBloques; int tamArchivo; long tiempoModificado; int idxBloques[100]; int libre; }


Lector

repo: elreplicante/unix-programming

decompiled_code:
void __fastcall __noreturn Lector(void *a1)
{
int v1; // eax
int v2; // ebx
pthread_t v3; // rbp
int v4; // eax

v1 = rand() % 10;
if ( v1 > 0 )
{
v2 = v1;
v3 = pthread_self();
do
{
sem_wait(&sem_lec);
if ( ++n_lectores == 1 )
sem_wait(&cerrojo);
sem_post(&sem_lec);
printf("El lector\t%ld lee dato:\t%d\n", v3, (unsigned int)dato);
sem_wait(&sem_lec);
if ( !--n_lectores )
sem_post(&cerrojo);
sem_post(&sem_lec);
v4 = rand();
sleep(v4 % 10);
--v2;
}
while ( v2 );
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // eax
int v2; // ebx
pthread_t v3; // rbp
int v4; // eax

v1 = rand() % 10;
if ( v1 > 0 )
{
v2 = v1;
v3 = pthread_self();
do
{
sem_wait(&sem_lec);
if ( ++n_lectores == 1 )
sem_wait(&cerrojo);
sem_post(&sem_lec);
printf("El lector\t%ld lee dato:\t%d\n", v3, (unsigned int)dato);
sem_wait(&sem_lec);
if ( !--n_lectores )
sem_post(&cerrojo);
sem_post(&sem_lec);
v4 = rand();
sleep(v4 % 10);
--v2;
}
while ( v2 );
}
pthread_exit(0LL);
}

original_code:
void * Lector(void * arg) {
  int i;
  for (i=rand()%10;i>0;i--) {
    sem_wait(&sem_lec);
    n_lectores = n_lectores + 1;
    if (n_lectores == 1)
      sem_wait(&cerrojo);
    sem_post(&sem_lec);
    printf("El lector\t%ld lee dato:\t%d\n", pthread_self(), dato);
    sem_wait(&sem_lec);
    n_lectores = n_lectores - 1;
    if (n_lectores == 0)
      sem_post(&cerrojo);
    sem_post(&sem_lec);
    sleep(rand()%10);
  }
  pthread_exit(0);
}

canonical_original_code:
void *Lector(void *arg) {
  int i;
  for (i=rand()%10;i>0;i--) {
    sem_wait(&sem_lec);
    n_lectores = n_lectores + 1;
    if (n_lectores == 1)
      sem_wait(&cerrojo);
    sem_post(&sem_lec);
    printf("El lector\t%ld lee dato:\t%d\n", pthread_self(), dato);
    sem_wait(&sem_lec);
    n_lectores = n_lectores - 1;
    if (n_lectores == 0)
      sem_post(&cerrojo);
    sem_post(&sem_lec);
    sleep(rand()%10);
  }
  pthread_exit(0);
}

variable_types:
arg
void *

return_type: void *


Escritor

decompiled_code:
void __fastcall __noreturn Escritor(void *a1)
{
int v1; // eax
int v2; // ebp
pthread_t v3; // rbx
int v4; // eax

v1 = rand() % 10;
if ( v1 > 0 )
{
v2 = v1;
v3 = pthread_self();
do
{
sem_wait(&cerrojo);
dato += 2;
printf("El consumidor\t%ld modifica dato:\t%d\n", v3, (unsigned int)dato);
sem_post(&cerrojo);
v4 = rand();
sleep(v4 % 5);
--v2;
}
while ( v2 );
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
int v1; // eax
int v2; // ebp
pthread_t v3; // rbx
int v4; // eax

v1 = rand() % 10;
if ( v1 > 0 )
{
v2 = v1;
v3 = pthread_self();
do
{
sem_wait(&cerrojo);
dato += 2;
printf("El consumidor\t%ld modifica dato:\t%d\n", v3, (unsigned int)dato);
sem_post(&cerrojo);
v4 = rand();
sleep(v4 % 5);
--v2;
}
while ( v2 );
}
pthread_exit(0LL);
}

original_code:
void * Escritor(void * arg) {
  int i;
  for (i=rand()%10;i>0;i--) {
    sem_wait(&cerrojo);
    dato = dato + 2;
    printf("El consumidor\t%ld modifica dato:\t%d\n", pthread_self(), dato);
    sem_post(&cerrojo);
    sleep(rand()%5);
  }
  pthread_exit(0);
}

canonical_original_code:
void *Escritor(void *arg) {
  int i;
  for (i=rand()%10;i>0;i--) {
    sem_wait(&cerrojo);
    dato = dato + 2;
    printf("El consumidor\t%ld modifica dato:\t%d\n", pthread_self(), dato);
    sem_post(&cerrojo);
    sleep(rand()%5);
  }
  pthread_exit(0);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_t th; // [rsp+0h] [rbp-28h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-20h] BYREF
pthread_t v5; // [rsp+10h] [rbp-18h] BYREF
pthread_t v6[2]; // [rsp+18h] [rbp-10h] BYREF

printf("Iniciamos lectores/escritores con dato:\t\t%d\n", (unsigned int)dato);
sem_init(&cerrojo, 0, 1u);
sem_init(&sem_lec, 0, 1u);
pthread_create(&th, 0LL, Lector, 0LL);
pthread_create(&newthread, 0LL, Escritor, 0LL);
pthread_create(&v5, 0LL, Lector, 0LL);
pthread_create(v6, 0LL, Escritor, 0LL);
pthread_join(th, 0LL);
pthread_join(newthread, 0LL);
pthread_join(v5, 0LL);
pthread_join(v6[0], 0LL);
sem_destroy(&cerrojo);
sem_destroy(&sem_lec);
printf("Proceso finalizado, dato:\t%d\n", (unsigned int)dato);
exit(0);
}

original_code:
int main(void) {
  pthread_t th1, th2, th3, th4;
  printf("Iniciamos lectores/escritores con dato:\t\t%d\n", dato);
  sem_init(&cerrojo, 0, 1); sem_init(&sem_lec, 0, 1);
  pthread_create(&th1, ((void *)0), Lector, ((void *)0));
  pthread_create(&th2, ((void *)0), Escritor, ((void *)0));
  pthread_create(&th3, ((void *)0), Lector, ((void *)0));
  pthread_create(&th4, ((void *)0), Escritor, ((void *)0));
  pthread_join(th1, ((void *)0)); pthread_join(th2, ((void *)0));
  pthread_join(th3, ((void *)0)); pthread_join(th4, ((void *)0));
  sem_destroy(&cerrojo); sem_destroy(&sem_lec);
  printf("Proceso finalizado, dato:\t%d\n", dato);
  exit(0);
}

canonical_original_code:
int main() {
  unsigned long th1; unsigned long th2; unsigned long th3; unsigned long th4;
  printf("Iniciamos lectores/escritores con dato:\t\t%d\n", dato);
  sem_init(&cerrojo, 0, 1); sem_init(&sem_lec, 0, 1);
  pthread_create(&th1, ((void *)0), Lector, ((void *)0));
  pthread_create(&th2, ((void *)0), Escritor, ((void *)0));
  pthread_create(&th3, ((void *)0), Lector, ((void *)0));
  pthread_create(&th4, ((void *)0), Escritor, ((void *)0));
  pthread_join(th1, ((void *)0)); pthread_join(th2, ((void *)0));
  pthread_join(th3, ((void *)0)); pthread_join(th4, ((void *)0));
  sem_destroy(&cerrojo); sem_destroy(&sem_lec);
  printf("Proceso finalizado, dato:\t%d\n", dato);
  exit(0);
}

return_type: int


repo: emagii/cpufrequtils

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

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

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

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
long long int get_time()
{
 struct timeval now;
 gettimeofday(&now, ((void *)0));
 return (long long int)(now.tv_sec * 1000000LL + now.tv_usec);
}

canonical_original_code:
long long get_time()
{
 struct timeval now;
 gettimeofday(&now, ((void *)0));
 return (long long)(now.tv_sec * 1000000LL + now.tv_usec);
}

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

return_type: long long


decompiled_code:
int __fastcall set_cpufreq_governor(char *governor, unsigned int cpu)
{
int result; // eax

if ( cpufreq_cpu_exists(cpu) )
{
perror("cpufreq_cpu_exists");
fprintf(stderr, "error: cpu %u does not exist\n", cpu);
result = -1;
}
else
{
result = cpufreq_modify_policy_governor(cpu, governor);
if ( result )
{
perror("cpufreq_modify_policy_governor");
fprintf(stderr, "error: unable to set %s governor\n", governor);
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *governor, unsigned int cpu)
{
int result; // eax

if ( cpufreq_cpu_exists(cpu) )
{
perror("cpufreq_cpu_exists");
fprintf(stderr, "error: cpu %u does not exist\n", cpu);
result = -1;
}
else
{
result = cpufreq_modify_policy_governor(cpu, governor);
if ( result )
{
perror("cpufreq_modify_policy_governor");
fprintf(stderr, "error: unable to set %s governor\n", governor);
result = -1;
}
}
return result;
}

original_code:
int set_cpufreq_governor(char *governor, unsigned int cpu)
{
 while(0) { };
 if (cpufreq_cpu_exists(cpu) != 0) {
  perror("cpufreq_cpu_exists");
  fprintf(stderr, "error: cpu %u does not exist\n", cpu);
  return -1;
 }
 if (cpufreq_modify_policy_governor(cpu, governor) != 0) {
  perror("cpufreq_modify_policy_governor");
  fprintf(stderr, "error: unable to set %s governor\n", governor);
  return -1;
 }
 return 0;
}

variable_types:
governor
char *

variable_types:
cpu
unsigned int


decompiled_code:
__int64 __fastcall set_cpu_affinity(unsigned int a1)
{
__pid_t v1; // eax
cpu_set_t v3; // [rsp+0h] [rbp-88h] BYREF

memset(&v3, 0, sizeof(v3));
if ( a1 <= 0x3FF )
v3.__bits[(unsigned __int64)a1 >> 6] |= 1LL << a1;
v1 = getpid();
if ( sched_setaffinity(v1, 0x80uLL, &v3) >= 0 )
return 0LL;
perror("sched_setaffinity");
fwrite("warning: unable to set cpu affinity\n", 1uLL, 0x24uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__pid_t v1; // eax
cpu_set_t v3; // [rsp+0h] [rbp-88h] BYREF

memset(&v3, 0, sizeof(v3));
if ( a1 <= 0x3FF )
v3.__bits[(unsigned __int64)a1 >> 6] |= 1LL << a1;
v1 = getpid();
if ( sched_setaffinity(v1, 0x80uLL, &v3) >= 0 )
return 0LL;
perror("sched_setaffinity");
fwrite("warning: unable to set cpu affinity\n", 1uLL, 0x24uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int set_cpu_affinity(unsigned int cpu)
{
 cpu_set_t cpuset;
 do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = (cpu); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 while(0) { };
 if (sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset) < 0) {
  perror("sched_setaffinity");
  fprintf(stderr, "warning: unable to set cpu affinity\n");
  return -1;
 }
 return 0;
}

canonical_original_code:
int set_cpu_affinity(unsigned int cpu)
{
 struct cpu_set_t cpuset;
 do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = (cpu); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 while(0) { };
 if (sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset) < 0) {
  perror("sched_setaffinity");
  fprintf(stderr, "warning: unable to set cpu affinity\n");
  return -1;
 }
 return 0;
}

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }


decompiled_code:
__int64 __fastcall set_process_priority(int a1)
{
struct sched_param param; // [rsp+Ch] [rbp-Ch] BYREF

param.__sched_priority = a1;
if ( sched_setscheduler(0, 0, &param) >= 0 )
return 0LL;
perror("sched_setscheduler");
fwrite("warning: unable to set scheduler priority\n", 1uLL, 0x2AuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
struct sched_param param; // [rsp+Ch] [rbp-Ch] BYREF

param.__sched_priority = a1;
if ( sched_setscheduler(0, 0, &param) >= 0 )
return 0LL;
perror("sched_setscheduler");
fwrite("warning: unable to set scheduler priority\n", 1uLL, 0x2AuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int set_process_priority(int priority)
{
 struct sched_param param;
 while(0) { };
 param.sched_priority = priority;
 if (sched_setscheduler(0, 0, &param) < 0) {
  perror("sched_setscheduler");
  fprintf(stderr, "warning: unable to set scheduler priority\n");
  return -1;
 }
 return 0;
}

variable_types: priority int

variable_types: struct sched_param { int sched_priority; }


decompiled_code:
int __fastcall string_to_prio(char *s2)
{
size_t v1; // r12
int result; // eax
int v3; // er8

v1 = strlen(s2);
result = strncasecmp("high", s2, v1);
if ( result )
{
v3 = strncasecmp("default", s2, v1);
result = 1;
if ( v3 )
result = strncasecmp("low", s2, v1) == 0 ? 2 : -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s2)
{
size_t v1; // r12
int result; // eax
int v3; // er8

v1 = strlen(s2);
result = strncasecmp("high", s2, v1);
if ( result )
{
v3 = strncasecmp("default", s2, v1);
result = 1;
if ( v3 )
result = strncasecmp("low", s2, v1) == 0 ? 2 : -1;
}
return result;
}

original_code:
enum sched_prio string_to_prio(const char *str)
{
 if (strncasecmp("high", str, strlen(str)) == 0)
  return SCHED_HIGH;
 else if (strncasecmp("default", str, strlen(str)) == 0)
  return SCHED_DEFAULT;
 else if (strncasecmp("low", str, strlen(str)) == 0)
  return SCHED_LOW;
 else
  return SCHED_ERR;
}

canonical_original_code:
enum sched_prio string_to_prio(char *str)
{
 if (strncasecmp("high", str, strlen(str)) == 0)
  return SCHED_HIGH;
 else if (strncasecmp("default", str, strlen(str)) == 0)
  return SCHED_DEFAULT;
 else if (strncasecmp("low", str, strlen(str)) == 0)
  return SCHED_LOW;
 else
  return SCHED_ERR;
}

variable_types:
str
char *

return_type: enum sched_prio { SCHED_ERR=-1, SCHED_HIGH=0, SCHED_DEFAULT=1, SCHED_LOW=2 }


decode

decompiled_code:
int __fastcall decode(unsigned int a1)
{
return printf("0x%x means multiplier %d @ %d mV\n", a1, BYTE1(a1), 16 * (unsigned int)(unsigned __int8)a1 + 700);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
return printf("0x%x means multiplier %d @ %d mV\n", a1, BYTE1(a1), 16 * (unsigned int)(unsigned __int8)a1 + 700);
}

original_code:
static void decode (unsigned int msr)
{
 unsigned int multiplier;
 unsigned int mv;
 multiplier = ((msr >> 8) & 0xFF);
 mv = (((msr & 0xFF) * 16) + 700);
 printf("0x%x means multiplier %d @ %d mV\n", msr, multiplier, mv);
}

canonical_original_code:
static void decode(unsigned int msr)
{
 unsigned int multiplier;
 unsigned int mv;
 multiplier = ((msr >> 8) & 0xFF);
 mv = (((msr & 0xFF) * 16) + 700);
 printf("0x%x means multiplier %d @ %d mV\n", msr, multiplier, mv);
}

variable_types:
msr
unsigned int

variable_types:
multiplier
unsigned int

variable_types:
mv
unsigned int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rdx
__int64 v5; // rcx
unsigned int v6; // er8

if ( argc <= 1 )
{
v6 = 0;
}
else
{
v3 = strtoul(argv[1], 0LL, 0);
v6 = v3;
if ( v3 > 0x1F )
{
decode(v3, 0LL, v4, v5, v3);
return 0;
}
}
decode_live_isra_0(v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rdx
__int64 v5; // rcx
unsigned int v6; // er8

if ( argc <= 1 )
{
v6 = 0;
}
else
{
v3 = strtoul(argv[1], 0LL, 0);
v6 = v3;
if ( v3 > 0x1F )
{
func7(v3, 0LL, v4, v5, v3);
return 0;
}
}
func9(v6);
return 0;
}

original_code:
int main (int argc, char **argv)
{
 unsigned int cpu, mode = 0;
 if (argc < 2)
  cpu = 0;
 else {
  cpu = strtoul(argv[1], ((void *)0), 0);
  if (cpu >= 32)
   mode = 1;
 }
 if (mode)
  decode(cpu);
 else
  decode_live(cpu);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned int cpu; unsigned int mode = 0;
 if (argc < 2)
  cpu = 0;
 else {
  cpu = strtoul(argv[1], ((void *)0), 0);
  if (cpu >= 32)
   mode = 1;
 }
 if (mode)
  decode(cpu);
 else
  decode_live(cpu);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
mode
unsigned int


decompiled_code:
__int64 __fastcall find_freq_from_fid(int a1)
{
return (unsigned int)(100 * a1 + 800);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return (unsigned int)(100 * a1 + 800);
}

original_code:
static uint32_t find_freq_from_fid(uint32_t fid)
{
 return 800 + (fid * 100);
}

canonical_original_code:
static unsigned int find_freq_from_fid(unsigned int fid)
{
 return 800 + (fid * 100);
}

variable_types:
fid
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall find_millivolts_from_vid(int a1)
{
return (unsigned int)(1550 - 25 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return (unsigned int)(1550 - 25 * a1);
}

original_code:
static uint32_t find_millivolts_from_vid(uint32_t vid)
{
 return 1550-vid*25;
}

canonical_original_code:
static unsigned int find_millivolts_from_vid(unsigned int vid)
{
 return 1550-vid*25;
}

variable_types:
vid
unsigned int


decompiled_code:
__int64 __fastcall get_fidvid(unsigned int a1, _DWORD *a2, int *a3)
{
unsigned int v3; // er12
int v6; // eax
int v7; // ebp
int v8; // eax
__int64 buf; // [rsp+8h] [rbp-50h] BYREF
char s[72]; // [rsp+10h] [rbp-48h] BYREF

buf = 0LL;
if ( a1 > 0x20 )
return 1;
sprintf(s, "/dev/cpu/%d/msr", a1);
v6 = open(s, 0);
v7 = v6;
if ( v6 < 0 )
return 1;
v3 = 1;
lseek(v6, 3221291074LL, 1);
if ( read(v7, &buf, 8uLL) == 8 )
{
v3 = 0;
v8 = BYTE4(buf) & 0x1F;
*a2 = buf & 0x3F;
*a3 = v8;
}
close(v7);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, _DWORD *a2, int *a3)
{
unsigned int v3; // er12
int v6; // eax
int v7; // ebp
int v8; // eax
__int64 buf; // [rsp+8h] [rbp-50h] BYREF
char s[72]; // [rsp+10h] [rbp-48h] BYREF

buf = 0LL;
if ( a1 > 0x20 )
return 1;
sprintf(s, "/dev/cpu/%d/msr", a1);
v6 = open(s, 0);
v7 = v6;
if ( v6 < 0 )
return 1;
v3 = 1;
lseek(v6, 3221291074LL, 1);
if ( read(v7, &buf, 8uLL) == 8 )
{
v3 = 0;
v8 = BYTE4(buf) & 0x1F;
*a2 = buf & 0x3F;
*a3 = v8;
}
close(v7);
return v3;
}

original_code:
static int get_fidvid(uint32_t cpu, uint32_t *fid, uint32_t *vid)
{
 int err = 1;
 uint64_t msr = 0;
 int fd;
 char file[20];
 if (cpu > 32)
  goto out;
 sprintf(file, "/dev/cpu/%d/msr", cpu);
 fd = open(file, 00);
 if (fd < 0)
  goto out;
 lseek(fd, 0xc0010042, 1);
 if (read(fd, &msr, 8) != 8)
  goto err1;
 *fid = ((uint32_t )(msr & 0xffffffffull)) & 0x0000003f;
 *vid = ((uint32_t )(msr>>32 & 0xffffffffull)) & 0x0000001f;
 err = 0;
err1:
 close(fd);
out:
 return err;
}

canonical_original_code:
static int get_fidvid(unsigned int cpu, unsigned int *fid, unsigned int *vid)
{
 int err = 1;
 unsigned long msr = 0;
 int fd;
 char file[20];
 if (cpu > 32)
  goto out;
 sprintf(file, "/dev/cpu/%d/msr", cpu);
 fd = open(file, 00);
 if (fd < 0)
  goto out;
 lseek(fd, 0xc0010042, 1);
 if (read(fd, &msr, 8) != 8)
  goto err1;
 *fid = ((unsigned int )(msr & 0xffffffffull)) & 0x0000003f;
 *vid = ((unsigned int )(msr>>32 & 0xffffffffull)) & 0x0000001f;
 err = 0;
err1:
 close(fd);
out:
 return err;
}

variable_types:
fid
unsigned int *

variable_types:
vid
unsigned int *

variable_types: err int

variable_types:
msr
unsigned long

variable_types: fd int

variable_types:
file
char [20]


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax
__int64 v5; // rdx
unsigned int v6; // eax
__int64 v7; // rcx
unsigned int v9; // [rsp+8h] [rbp-10h] BYREF
unsigned int v10[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = 0;
if ( argc > 1 )
v3 = strtoul(argv[1], 0LL, 0);
if ( (unsigned int)get_fidvid(v3, &v9, v10) )
{
puts("can't get fid, vid from MSR");
puts("Possible trouble: you don't run a powernow-k8 capable cpu");
puts("or you are not root, or the msr driver is not present");
exit(1);
}
v4 = find_millivolts_from_vid(v10[0], v3);
v6 = find_freq_from_fid(v9, v3, v5, v4);
printf("cpu %d currently at %d MHz and %d mV\n", v3, v6, v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax
__int64 v5; // rdx
unsigned int v6; // eax
__int64 v7; // rcx
unsigned int v9; // [rsp+8h] [rbp-10h] BYREF
unsigned int v10[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = 0;
if ( argc > 1 )
v3 = strtoul(argv[1], 0LL, 0);
if ( (unsigned int)func9(v3, &v9, v10) )
{
puts("can't get fid, vid from MSR");
puts("Possible trouble: you don't run a powernow-k8 capable cpu");
puts("or you are not root, or the msr driver is not present");
exit(1);
}
v4 = func8(v10[0], v3);
v6 = func7(v9, v3, v5, v4);
printf("cpu %d currently at %d MHz and %d mV\n", v3, v6, v7);
return 0;
}

original_code:
int main (int argc, char *argv[])
{
 int err;
 int cpu;
 uint32_t fid, vid;
 if (argc < 2)
  cpu = 0;
 else
  cpu = strtoul(argv[1], ((void *)0), 0);
 err = get_fidvid(cpu, &fid, &vid);
 if (err) {
  printf("can't get fid, vid from MSR\n");
  printf("Possible trouble: you don't run a powernow-k8 capable cpu\n");
  printf("or you are not root, or the msr driver is not present\n");
  exit(1);
 }
 printf("cpu %d currently at %d MHz and %d mV\n",
   cpu,
   find_freq_from_fid(fid),
   find_millivolts_from_vid(vid));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int err;
 int cpu;
 unsigned int fid; unsigned int vid;
 if (argc < 2)
  cpu = 0;
 else
  cpu = strtoul(argv[1], ((void *)0), 0);
 err = get_fidvid(cpu, &fid, &vid);
 if (err) {
  printf("can't get fid, vid from MSR\n");
  printf("Possible trouble: you don't run a powernow-k8 capable cpu\n");
  printf("or you are not root, or the msr driver is not present\n");
  exit(1);
 }
 printf("cpu %d currently at %d MHz and %d mV\n",
   cpu,
   find_freq_from_fid(fid),
   find_millivolts_from_vid(vid));
 return 0;
}

variable_types:
argv
char *[]

variable_types: cpu int


decompiled_code:
int __fastcall decode_psb(__int64 a1, int a2)
{
int v2; // er12
unsigned __int8 *v3; // rbx
__int64 v4; // rax
unsigned int v5; // ebp
__int64 v6; // rdx
int v7; // esi

if ( *(_BYTE *)(a1 + 10) == 18 )
{
v2 = a2;
v3 = (unsigned __int8 *)(a1 + 16);
LODWORD(v4) = printf(
"PSB version: %hhx flags: %hhx settling time %hhuus res1 %hhx num pst %hhu\n",
18LL,
*(unsigned __int8 *)(a1 + 11),
*(unsigned __int16 *)(a1 + 12),
*(unsigned __int8 *)(a1 + 14),
*(unsigned __int8 *)(a1 + 15));
if ( a2 >= 0 )
LODWORD(v4) = printf("Overriding number of pst :%d\n", (unsigned int)a2);
else
v2 = *(unsigned __int8 *)(a1 + 15);
if ( v2 )
{
v5 = 0;
do
{
v6 = *(unsigned int *)v3;
++v5;
if ( !relevant || relevant == (unsigned int)v6 )
{
printf(
" PST %d cpuid %.3x fsb %hhu mfid %hhx svid %hhx numberstates %hhu\n",
v5,
v6,
v3[4],
v3[5],
v3[6],
v3[7]);
v7 = v3[7];
fsb = v3[4];
decode_pst_isra_0((__int64)(v3 + 8), v7);
}
v4 = v3[7];
v3 += 2 * v4 + 8;
}
while ( v2 != v5 );
}
}
return v4;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, int a2)
{
int v2; // er12
unsigned __int8 *v3; // rbx
__int64 v4; // rax
unsigned int v5; // ebp
__int64 v6; // rdx
int v7; // esi

if ( *(_BYTE *)(a1 + 10) == 18 )
{
v2 = a2;
v3 = (unsigned __int8 *)(a1 + 16);
LODWORD(v4) = printf(
"PSB version: %hhx flags: %hhx settling time %hhuus res1 %hhx num pst %hhu\n",
18LL,
*(unsigned __int8 *)(a1 + 11),
*(unsigned __int16 *)(a1 + 12),
*(unsigned __int8 *)(a1 + 14),
*(unsigned __int8 *)(a1 + 15));
if ( a2 >= 0 )
LODWORD(v4) = printf("Overriding number of pst :%d\n", (unsigned int)a2);
else
v2 = *(unsigned __int8 *)(a1 + 15);
if ( v2 )
{
v5 = 0;
do
{
v6 = *(unsigned int *)v3;
++v5;
if ( !relevant || relevant == (unsigned int)v6 )
{
printf(
" PST %d cpuid %.3x fsb %hhu mfid %hhx svid %hhx numberstates %hhu\n",
v5,
v6,
v3[4],
v3[5],
v3[6],
v3[7]);
v7 = v3[7];
fsb = v3[4];
func7((__int64)(v3 + 8), v7);
}
v4 = v3[7];
v3 += 2 * v4 + 8;
}
while ( v2 != v5 );
}
}
return v4;
}

original_code:
static
void decode_psb(char *p, int numpst)
{
 int i;
 struct psb_header *psb;
 struct pst_header *pst;
 psb = (struct psb_header*) p;
 if (psb->version != 0x12)
  return;
 printf("PSB version: %hhx flags: %hhx settling time %hhuus res1 %hhx num pst %hhu\n",
   psb->version,
   psb->flags,
   psb->settlingtime,
   psb->res1,
   psb->numpst);
 sgtc = psb->settlingtime * 100;
 if (sgtc < 10000)
  sgtc = 10000;
 p = ((char *) psb) + sizeof(struct psb_header);
 if (numpst < 0)
  numpst = psb->numpst;
 else
  printf("Overriding number of pst :%d\n", numpst);
 for (i = 0; i < numpst; i++) {
  pst = (struct pst_header*) p;
  if (relevant != 0) {
   if (relevant!= pst->cpuid)
    goto next_one;
  }
  printf("  PST %d  cpuid %.3x fsb %hhu mfid %hhx svid %hhx numberstates %hhu\n",
    i+1,
    pst->cpuid,
    pst->fsb,
    pst->maxfid,
    pst->startvid,
    pst->numpstates);
  fsb = pst->fsb;
  decode_pst(p + sizeof(struct pst_header), pst->numpstates);
next_one:
  p += sizeof(struct pst_header) + 2*pst->numpstates;
 }
}

canonical_original_code:
static void decode_psb(char *p, int numpst)
{
 int i;
 struct psb_header *psb;
 struct pst_header *pst;
 psb = (struct psb_header *) p;
 if (psb->version != 0x12)
  return;
 printf("PSB version: %hhx flags: %hhx settling time %hhuus res1 %hhx num pst %hhu\n",
   psb->version,
   psb->flags,
   psb->settlingtime,
   psb->res1,
   psb->numpst);
 sgtc = psb->settlingtime * 100;
 if (sgtc < 10000)
  sgtc = 10000;
 p = ((char *) psb) + sizeof(struct psb_header);
 if (numpst < 0)
  numpst = psb->numpst;
 else
  printf("Overriding number of pst :%d\n", numpst);
 for (i = 0; i < numpst; i++) {
  pst = (struct pst_header *) p;
  if (relevant != 0) {
   if (relevant!= pst->cpuid)
    goto next_one;
  }
  printf("  PST %d  cpuid %.3x fsb %hhu mfid %hhx svid %hhx numberstates %hhu\n",
    i+1,
    pst->cpuid,
    pst->fsb,
    pst->maxfid,
    pst->startvid,
    pst->numpstates);
  fsb = pst->fsb;
  decode_pst(p + sizeof(struct pst_header), pst->numpstates);
next_one:
  p += sizeof(struct pst_header) + 2*pst->numpstates;
 }
}

variable_types:
p
char *

variable_types: numpst int

variable_types: i int

variable_types: struct psb_header { char signature[10]; unsigned char version; unsigned char flags; unsigned short settlingtime; unsigned char res1; unsigned char numpst; } *

variable_types: struct pst_header { unsigned int cpuid; unsigned char fsb; unsigned char maxfid; unsigned char startvid; unsigned char numpstates; } *


decompiled_code:
int print_help()
{
puts("Usage: dump_psb [options]");
puts("Options:");
puts(" -n, --numpst Set number of PST tables to scan");
return puts(" -r, --relevant Only display PSTs relevant to cpuid N");
}

canonical_decompiled_code:
int func9()
{
puts("Usage: dump_psb [options]");
puts("Options:");
puts(" -n, --numpst Set number of PST tables to scan");
return puts(" -r, --relevant Only display PSTs relevant to cpuid N");
}

original_code:
void print_help(void)
{
 printf ("Usage: dump_psb [options]\n");
 printf ("Options:\n");
 printf ("  -n, --numpst     Set number of PST tables to scan\n");
 printf ("  -r, --relevant   Only display PSTs relevant to cpuid N\n");
}

canonical_original_code:
void print_help()
{
 printf ("Usage: dump_psb [options]\n");
 printf ("Options:\n");
 printf ("  -n, --numpst     Set number of PST tables to scan\n");
 printf ("  -r, --relevant   Only display PSTs relevant to cpuid N\n");
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // eax
int v5; // eax
int v6; // er13
char *v7; // rbp
char *v8; // rdi

v3 = -1;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v4 = getopt_long(argc, (char *const *)argv, "hr:n:", &info_opts, 0LL);
if ( v4 != 110 )
break;
v3 = strtol(_bss_start, 0LL, 10);
}
if ( v4 <= 110 )
break;
if ( v4 == 114 )
relevant = strtol(_bss_start, 0LL, 16);
}
if ( v4 == 63 || v4 == 104 )
break;
if ( v4 == -1 )
goto LABEL_7;
}
print_help();
LABEL_7:
v5 = open("/dev/mem", 0);
v6 = v5;
if ( v5 < 0 )
{
puts("Couldn't open /dev/mem. Are you root?");
exit(1);
}
v7 = (char *)mmap(0LL, 0x40000uLL, 1, 1, v5, 786432LL);
close(v6);
v8 = v7;
while ( *(_QWORD *)v8 != 0x4F4E50374B444D41LL || *((_WORD *)v8 + 4) != 8535 )
{
v8 += 16;
if ( v8 - v7 > 0x3FFFF )
goto LABEL_13;
}
decode_psb(v8, v3, 0x4F4E50374B444D41LL);
LABEL_13:
munmap(v7, 0x40000uLL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // eax
int v5; // eax
int v6; // er13
char *v7; // rbp
char *v8; // rdi

v3 = -1;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v4 = getopt_long(argc, (char *const *)argv, "hr:n:", &info_opts, 0LL);
if ( v4 != 110 )
break;
v3 = strtol(_bss_start, 0LL, 10);
}
if ( v4 <= 110 )
break;
if ( v4 == 114 )
relevant = strtol(_bss_start, 0LL, 16);
}
if ( v4 == 63 || v4 == 104 )
break;
if ( v4 == -1 )
goto LABEL_7;
}
func9();
LABEL_7:
v5 = open("/dev/mem", 0);
v6 = v5;
if ( v5 < 0 )
{
puts("Couldn't open /dev/mem. Are you root?");
exit(1);
}
v7 = (char *)mmap(0LL, 0x40000uLL, 1, 1, v5, 786432LL);
close(v6);
v8 = v7;
while ( *(_QWORD *)v8 != 0x4F4E50374B444D41LL || *((_WORD *)v8 + 4) != 8535 )
{
v8 += 16;
if ( v8 - v7 > 0x3FFFF )
goto LABEL_13;
}
func8(v8, v3, 0x4F4E50374B444D41LL);
LABEL_13:
munmap(v7, 0x40000uLL);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
 int fd;
 int numpst=-1;
 int ret=0, cont=1;
 char *mem = ((void *)0);
 char *p;
 do {
  ret = getopt_long(argc, argv, "hr:n:", info_opts, ((void *)0));
  switch (ret){
  case '?':
  case 'h':
   print_help();
   cont = 0;
   break;
  case 'r':
   relevant = strtol(optarg, ((void *)0), 16);
   break;
  case 'n':
   numpst = strtol(optarg, ((void *)0), 10);
   break;
  case -1:
   cont = 0;
   break;
  }
 } while(cont);
 fd = open("/dev/mem", 00);
 if (fd < 0) {
  printf ("Couldn't open /dev/mem. Are you root?\n");
  exit(1);
 }
 mem = mmap(mem, 0x100000 - 0xc0000, 0x1, 0x01, fd, 0xc0000);
 close(fd);
 for (p = mem; p - mem < (0x100000 - 0xc0000); p+=16) {
  if (memcmp(p, "AMDK7PNOW!", 10) == 0) {
   decode_psb(p, numpst);
   break;
  }
 }
 munmap(mem, (0x100000 - 0xc0000));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd;
 int numpst = -1;
 int ret = 0; int cont = 1;
 char *mem = ((void *)0);
 char *p;
 do {
  ret = getopt_long(argc, argv, "hr:n:", info_opts, ((void *)0));
  switch (ret){
  case '?':
  case 'h':
   print_help();
   cont = 0;
   break;
  case 'r':
   relevant = strtol(optarg, ((void *)0), 16);
   break;
  case 'n':
   numpst = strtol(optarg, ((void *)0), 10);
   break;
  case -1:
   cont = 0;
   break;
  }
 } while(cont);
 fd = open("/dev/mem", 00);
 if (fd < 0) {
  printf ("Couldn't open /dev/mem. Are you root?\n");
  exit(1);
 }
 mem = mmap(mem, 0x100000 - 0xc0000, 0x1, 0x01, fd, 0xc0000);
 close(fd);
 for (p = mem; p - mem < (0x100000 - 0xc0000); p+=16) {
  if (memcmp(p, "AMDK7PNOW!", 10) == 0) {
   decode_psb(p, numpst);
   break;
  }
 }
 munmap(mem, (0x100000 - 0xc0000));
 return 0;
}

variable_types: argc int

variable_types: ret int

variable_types: cont int

variable_types:
mem
char *


usage

decompiled_code:
int usage()
{
return puts(
"cpufreq-aperf [OPTIONS]\n"
"\n"
"-c [ --cpu ] CPU The CPU core to measure - default all cores\n"
"-i [ --intervall ] seconds Refresh rate - default 1 second\n"
"-o [ --once ] Exit after one intervall\n"
"-h [ --help ] This help text\n"
"The msr driver must be loaded for this command to work");
}

canonical_decompiled_code:
int func3()
{
return puts(
"cpufreq-aperf [OPTIONS]\n"
"\n"
"-c [ --cpu ] CPU The CPU core to measure - default all cores\n"
"-i [ --intervall ] seconds Refresh rate - default 1 second\n"
"-o [ --once ] Exit after one intervall\n"
"-h [ --help ] This help text\n"
"The msr driver must be loaded for this command to work");
}

original_code:
void usage()
{
 printf("usage: ./bench\n");
 printf("Options:\n");
 printf(" -l, --load=<long int>\t\tinitial load time in us\n");
 printf(" -s, --sleep=<long int>\t\tinitial sleep time in us\n");
 printf(" -x, --load-step=<long int>\ttime to be added to load time, in us\n");
 printf(" -y, --sleep-step=<long int>\ttime to be added to sleep time, in us\n");
 printf(" -c, --cpu=<cpu #>\t\t\tCPU Nr. to use, starting at 0\n");
 printf(" -p, --prio=<priority>\t\t\tscheduler priority, HIGH, LOW or DEFAULT\n");
 printf(" -g, --governor=<governor>\t\tcpufreq governor to test\n");
 printf(" -n, --cycles=<int>\t\t\tload/sleep cycles\n");
 printf(" -r, --rounds<int>\t\t\tload/sleep rounds\n");
 printf(" -f, --file=<configfile>\t\tconfig file to use\n");
 printf(" -o, --output=<dir>\t\t\toutput path. Filename will be OUTPUTPATH/benchmark_TIMESTAMP.log\n");
 printf(" -v, --verbose\t\t\t\tverbose output on/off\n");
 printf(" -h, --help\t\t\t\tPrint this help screen\n");
 exit (1);
}


decompiled_code:
int print_help()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax
char *v9; // rax

v0 = dcgettext(0LL, "Usage: cpufreq-set [options]\n", 5);
printf(v0);
v1 = dcgettext(0LL, "Options:\n", 5);
printf(v1);
v2 = dcgettext(0LL, " -c CPU, --cpu CPU number of CPU where cpufreq settings shall be modified\n", 5);
printf(v2);
v3 = dcgettext(0LL, " -d FREQ, --min FREQ new minimum CPU frequency the governor may select\n", 5);
printf(v3);
v4 = dcgettext(0LL, " -u FREQ, --max FREQ new maximum CPU frequency the governor may select\n", 5);
printf(v4);
v5 = dcgettext(0LL, " -g GOV, --governor GOV new cpufreq governor\n", 5);
printf(v5);
v6 = dcgettext(
0LL,
" -f FREQ, --freq FREQ specific frequency to be set. Requires userspace\n"
" governor to be available and loaded\n",
5);
printf(v6);
v7 = dcgettext(0LL, " -r, --related Switches all hardware-related CPUs\n", 5);
printf(v7);
v8 = dcgettext(0LL, " -h, --help Prints out this screen\n", 5);
printf(v8);
putchar(10);
v9 = dcgettext(
0LL,
"Notes:\n"
"1. Omitting the -c or --cpu argument is equivalent to setting it to zero\n"
"2. The -f FREQ, --freq FREQ parameter cannot be combined with any other parameter\n"
" except the -c CPU, --cpu CPU parameter\n"
"3. FREQuencies can be passed in Hz, kHz (default), MHz, GHz, or THz\n"
" by postfixing the value with the wanted unit name, without any space\n"
" (FREQuency in kHz =^ Hz * 0.001 =^ MHz * 1000 =^ GHz * 1000000).\n",
5);
return printf(v9);
}

canonical_decompiled_code:
int func2()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax
char *v9; // rax

v0 = dcgettext(0LL, "Usage: cpufreq-set [options]\n", 5);
printf(v0);
v1 = dcgettext(0LL, "Options:\n", 5);
printf(v1);
v2 = dcgettext(0LL, " -c CPU, --cpu CPU number of CPU where cpufreq settings shall be modified\n", 5);
printf(v2);
v3 = dcgettext(0LL, " -d FREQ, --min FREQ new minimum CPU frequency the governor may select\n", 5);
printf(v3);
v4 = dcgettext(0LL, " -u FREQ, --max FREQ new maximum CPU frequency the governor may select\n", 5);
printf(v4);
v5 = dcgettext(0LL, " -g GOV, --governor GOV new cpufreq governor\n", 5);
printf(v5);
v6 = dcgettext(
0LL,
" -f FREQ, --freq FREQ specific frequency to be set. Requires userspace\n"
" governor to be available and loaded\n",
5);
printf(v6);
v7 = dcgettext(0LL, " -r, --related Switches all hardware-related CPUs\n", 5);
printf(v7);
v8 = dcgettext(0LL, " -h, --help Prints out this screen\n", 5);
printf(v8);
putchar(10);
v9 = dcgettext(
0LL,
"Notes:\n"
"1. Omitting the -c or --cpu argument is equivalent to setting it to zero\n"
"2. The -f FREQ, --freq FREQ parameter cannot be combined with any other parameter\n"
" except the -c CPU, --cpu CPU parameter\n"
"3. FREQuencies can be passed in Hz, kHz (default), MHz, GHz, or THz\n"
" by postfixing the value with the wanted unit name, without any space\n"
" (FREQuency in kHz =^ Hz * 0.001 =^ MHz * 1000 =^ GHz * 1000000).\n",
5);
return printf(v9);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // r15
struct cpufreq_affected_cpus *v4; // r14
int v5; // er13
int v6; // er12
int v7; // eax
int result; // eax
const char *v9; // rsi
struct cpufreq_affected_cpus *v10; // rdi
char *v11; // rax
struct cpufreq_affected_cpus *v12; // rdi
int v13; // [rsp+4h] [rbp-A4h]
int v14; // [rsp+4h] [rbp-A4h]
int v15; // [rsp+4h] [rbp-A4h]
const char *s; // [rsp+8h] [rbp-A0h]
char v17; // [rsp+10h] [rbp-98h] BYREF
struct cpufreq_policy v18; // [rsp+30h] [rbp-78h] BYREF
int v19; // [rsp+50h] [rbp-58h] BYREF
__int64 v20; // [rsp+58h] [rbp-50h]
int *v21; // [rsp+60h] [rbp-48h]

v3 = 0LL;
v4 = 0LL;
v5 = 0;
v6 = 0;
v18.min = 0LL;
v18.max = 0LL;
v18.governor = 0LL;
v19 = 0;
v20 = 0LL;
v21 = &v19;
setlocale(6, &locale);
textdomain("cpufrequtils");
v13 = 0;
while ( 2 )
{
v7 = getopt_long(argc, (char *const *)argv, "c:d:u:g:f:hr", &set_opts, 0LL);
if ( v7 != -1 )
{
switch ( v7 )
{
case '?':
goto LABEL_7;
case 'c':
v6 -= (v4 == 0LL) - 1;
if ( sscanf(optarg, "%d ", &v19) != 1 )
goto LABEL_7;
v4 = (struct cpufreq_affected_cpus *)&v19;
continue;
case 'd':
if ( v18.min )
++v6;
++v5;
v18.min = string_to_frequency(optarg);
if ( v18.min )
continue;
goto LABEL_7;
case 'f':
v6 -= (v3 == 0) - 1;
v3 = string_to_frequency(optarg);
if ( v3 )
continue;
goto LABEL_7;
case 'g':
if ( v18.governor )
++v6;
++v5;
s = optarg;
if ( strlen(optarg) - 3 > 0xF || sscanf(s, "%s", &v17) != 1 )
goto LABEL_7;
v18.governor = &v17;
continue;
case 'h':
print_header();
print_help();
return 0;
case 'r':
v6 -= (v13++ == 0) - 1;
continue;
case 'u':
if ( v18.max )
++v6;
++v5;
v18.max = string_to_frequency(optarg);
if ( v18.max )
continue;
LABEL_7:
print_unknown_arg();
return -22;
default:
continue;
}
}
break;
}
if ( v6 )
{
print_header();
puts("the same parameter was passed more than once");
return -22;
}
if ( v3 )
{
v9 = "the -f/--freq parameter cannot be combined with -d/--min, -u/--max or\n-g/--governor parameters\n";
if ( !v5 )
goto LABEL_27;
LABEL_39:
v11 = dcgettext(0LL, v9, 5);
printf(v11);
return -22;
}
if ( !v5 )
{
v9 = "At least one parameter out of -f/--freq, -d/--min, -u/--max, and\n-g/--governor must be passed\n";
goto LABEL_39;
}
LABEL_27:
if ( !v4 )
v4 = (struct cpufreq_affected_cpus *)&v19;
if ( v13 )
v4 = cpufreq_get_related_cpus(v4->cpu);
while ( 1 )
{
result = do_one_cpu(v4->cpu, &v18, v3, v5);
if ( result )
{
v10 = v4->first;
if ( v10 != (struct cpufreq_affected_cpus *)&v19 )
{
v14 = result;
cpufreq_put_related_cpus(v10);
result = v14;
}
v15 = result;
print_error();
return v15;
}
if ( !v4->next )
break;
v4 = v4->next;
}
v12 = v4->first;
if ( v12 != (struct cpufreq_affected_cpus *)&v19 )
{
cpufreq_put_related_cpus(v12);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // r15
struct cpufreq_affected_cpus *v4; // r14
int v5; // er13
int v6; // er12
int v7; // eax
int result; // eax
const char *v9; // rsi
struct cpufreq_affected_cpus *v10; // rdi
char *v11; // rax
struct cpufreq_affected_cpus *v12; // rdi
int v13; // [rsp+4h] [rbp-A4h]
int v14; // [rsp+4h] [rbp-A4h]
int v15; // [rsp+4h] [rbp-A4h]
const char *s; // [rsp+8h] [rbp-A0h]
char v17; // [rsp+10h] [rbp-98h] BYREF
struct cpufreq_policy v18; // [rsp+30h] [rbp-78h] BYREF
int v19; // [rsp+50h] [rbp-58h] BYREF
__int64 v20; // [rsp+58h] [rbp-50h]
int *v21; // [rsp+60h] [rbp-48h]

v3 = 0LL;
v4 = 0LL;
v5 = 0;
v6 = 0;
v18.min = 0LL;
v18.max = 0LL;
v18.governor = 0LL;
v19 = 0;
v20 = 0LL;
v21 = &v19;
setlocale(6, &locale);
textdomain("cpufrequtils");
v13 = 0;
while ( 2 )
{
v7 = getopt_long(argc, (char *const *)argv, "c:d:u:g:f:hr", &set_opts, 0LL);
if ( v7 != -1 )
{
switch ( v7 )
{
case '?':
goto LABEL_7;
case 'c':
v6 -= (v4 == 0LL) - 1;
if ( sscanf(optarg, "%d ", &v19) != 1 )
goto LABEL_7;
v4 = (struct cpufreq_affected_cpus *)&v19;
continue;
case 'd':
if ( v18.min )
++v6;
++v5;
v18.min = func4(optarg);
if ( v18.min )
continue;
goto LABEL_7;
case 'f':
v6 -= (v3 == 0) - 1;
v3 = func4(optarg);
if ( v3 )
continue;
goto LABEL_7;
case 'g':
if ( v18.governor )
++v6;
++v5;
s = optarg;
if ( strlen(optarg) - 3 > 0xF || sscanf(s, "%s", &v17) != 1 )
goto LABEL_7;
v18.governor = &v17;
continue;
case 'h':
func0();
func2();
return 0;
case 'r':
v6 -= (v13++ == 0) - 1;
continue;
case 'u':
if ( v18.max )
++v6;
++v5;
v18.max = func4(optarg);
if ( v18.max )
continue;
LABEL_7:
func3();
return -22;
default:
continue;
}
}
break;
}
if ( v6 )
{
func0();
puts("the same parameter was passed more than once");
return -22;
}
if ( v3 )
{
v9 = "the -f/--freq parameter cannot be combined with -d/--min, -u/--max or\n-g/--governor parameters\n";
if ( !v5 )
goto LABEL_27;
LABEL_39:
v11 = dcgettext(0LL, v9, 5);
printf(v11);
return -22;
}
if ( !v5 )
{
v9 = "At least one parameter out of -f/--freq, -d/--min, -u/--max, and\n-g/--governor must be passed\n";
goto LABEL_39;
}
LABEL_27:
if ( !v4 )
v4 = (struct cpufreq_affected_cpus *)&v19;
if ( v13 )
v4 = cpufreq_get_related_cpus(v4->cpu);
while ( 1 )
{
result = func6(v4->cpu, &v18, v3, v5);
if ( result )
{
v10 = v4->first;
if ( v10 != (struct cpufreq_affected_cpus *)&v19 )
{
v14 = result;
cpufreq_put_related_cpus(v10);
result = v14;
}
v15 = result;
func1();
return v15;
}
if ( !v4->next )
break;
v4 = v4->next;
}
v12 = v4->first;
if ( v12 != (struct cpufreq_affected_cpus *)&v19 )
{
cpufreq_put_related_cpus(v12);
result = 0;
}
return result;
}


repo: emaniacs/primeNumber

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
const char *v5; // rbp
int v6; // ebx
int v7; // eax
const char *v9; // rdi
__int64 v10; // rdi
unsigned int v11; // eax
char *endptr; // [rsp+8h] [rbp-40h] BYREF

v3 = 0;
v4 = 0;
v5 = "\n";
v6 = 0;
while ( 2 )
{
v7 = getopt(argc, (char *const *)argv, "qhngs:");
if ( v7 == -1 )
{
if ( optind >= argc )
goto LABEL_13;
v9 = argv[optind];
endptr = 0LL;
v10 = strtol(v9, &endptr, 10);
if ( *endptr )
goto LABEL_13;
if ( v3 && (int)v10 > 0 )
{
v11 = find_prime();
v4 = 0;
fprintf(_bss_start, "%d\n", v11);
return v4;
}
if ( v6 && (int)v10 > 0 )
{
v4 = 0;
generate_prime(v10, v5);
return v4;
}
if ( (int)v10 <= 1 )
{
LABEL_13:
v4 = -1;
fwrite("Please enter valid integer, above than 1\n", 1uLL, 0x29uLL, _bss_start);
}
else if ( (unsigned int)its_prime() )
{
if ( !v4 )
fwrite("true\n", 1uLL, 5uLL, _bss_start);
}
else if ( !v4 )
{
v4 = 1;
fwrite("false\n", 1uLL, 6uLL, _bss_start);
}
}
else
{
if ( v7 != 63 )
{
switch ( v7 )
{
case 'g':
v6 = 1;
continue;
case 'h':
return usage(*argv);
case 'n':
v3 = 1;
continue;
case 'q':
v4 = 1;
continue;
case 's':
v5 = (const char *)optarg;
continue;
default:
abort();
}
}
v4 = -1;
}
return v4;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
const char *v5; // rbp
int v6; // ebx
int v7; // eax
const char *v9; // rdi
__int64 v10; // rdi
unsigned int v11; // eax
char *endptr; // [rsp+8h] [rbp-40h] BYREF

v3 = 0;
v4 = 0;
v5 = "\n";
v6 = 0;
while ( 2 )
{
v7 = getopt(argc, (char *const *)argv, "qhngs:");
if ( v7 == -1 )
{
if ( optind >= argc )
goto LABEL_13;
v9 = argv[optind];
endptr = 0LL;
v10 = strtol(v9, &endptr, 10);
if ( *endptr )
goto LABEL_13;
if ( v3 && (int)v10 > 0 )
{
v11 = func9();
v4 = 0;
fprintf(_bss_start, "%d\n", v11);
return v4;
}
if ( v6 && (int)v10 > 0 )
{
v4 = 0;
func10(v10, v5);
return v4;
}
if ( (int)v10 <= 1 )
{
LABEL_13:
v4 = -1;
fwrite("Please enter valid integer, above than 1\n", 1uLL, 0x29uLL, _bss_start);
}
else if ( (unsigned int)func8() )
{
if ( !v4 )
fwrite("true\n", 1uLL, 5uLL, _bss_start);
}
else if ( !v4 )
{
v4 = 1;
fwrite("false\n", 1uLL, 6uLL, _bss_start);
}
}
else
{
if ( v7 != 63 )
{
switch ( v7 )
{
case 'g':
v6 = 1;
continue;
case 'h':
return func7(*argv);
case 'n':
v3 = 1;
continue;
case 'q':
v4 = 1;
continue;
case 's':
v5 = (const char *)optarg;
continue;
default:
abort();
}
}
v4 = -1;
}
return v4;
}
}

original_code:
int main(int argc, char *argv[]) {
    int ret = 0;
    char *sep = "\n";
    int number = 0;
    int quiet = 0;
    int generate = 0;
    int nth = 0;
    int c;
    while ((c=getopt(argc, argv, "qhngs:")) != -1) {
        switch(c) {
            case 'q':
                quiet = 1; break;
            case 'h':
                return usage(argv[0]); break;
            case 'n':
                nth = 1; break;
            case 'g':
                generate = 1; break;
            case 's':
                sep = optarg; break;
            case '?':
                return -1;
            default:
                abort();
        }
    }
    if (optind < argc) {
        char *garbage = ((void *)0);
        number = strtol(argv[optind], &garbage, 10);
        if (*garbage != 0)
            number = 0;
    }
    if (nth && number >= 1) {
        fprintf(stdout, "%d\n", find_prime(number));
    }
    else if (generate && number >= 1) {
        generate_prime(number, sep);
    }
    else if (number > 1) {
        if (its_prime(number) && !quiet){
            fprintf(stdout, "true\n");
        }
        else {
            ret = 1;
            if (! quiet)
                fprintf(stdout, "false\n");
        }
    }
    else {
        fprintf(stdout, "Please enter valid integer, above than 1\n");
        return -1;
    }
    return ret;
}

variable_types:
sep
char *

variable_types: number int

variable_types: quiet int

variable_types: generate int

variable_types: nth int

variable_types: c int

variable_types:
garbage
char *


usage

decompiled_code:
__int64 __fastcall usage(const char *a1)
{
fprintf(
_bss_start,
"%s\n"
"Usage:\n"
" %s <options> number\n"
"Options:\n"
" -h show this help.\n"
" -q quiet mode.\n"
" -g <number> generate prime number\n"
" -n <number> find prime number\n"
" -s <char> use 'char' as separator. (default is newline).\n"
"Return:\n"
" 0 if number is prime.\n"
" 1 if number is not a prime.\n"
" -1 error\n",
a1,
a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
fprintf(
_bss_start,
"%s\n"
"Usage:\n"
" %s <options> number\n"
"Options:\n"
" -h show this help.\n"
" -q quiet mode.\n"
" -g <number> generate prime number\n"
" -n <number> find prime number\n"
" -s <char> use 'char' as separator. (default is newline).\n"
"Return:\n"
" 0 if number is prime.\n"
" 1 if number is not a prime.\n"
" -1 error\n",
a1,
a1);
return 0xFFFFFFFFLL;
}

original_code:
int usage(char *self) {
    fprintf(stdout, "%s\nUsage:\n    %s <options> number\nOptions:\n    -h           show this help.\n    -q           quiet mode.\n    -g <number>  generate prime number\n    -n <number>  find prime number\n    -s <char>    use 'char' as separator. (default is newline).\nReturn:\n    0       if number is prime.\n    1       if number is not a prime.\n    -1      error\n",
self, self);
    return -1;
}

variable_types:
self
char *


decompiled_code:
__int64 __fastcall its_prime(int a1)
{
unsigned int v1; // er8
int v2; // ecx

v1 = 1;
if ( a1 == 2 )
return v1;
v1 = a1 & 1;
if ( (a1 & 1) == 0 || a1 <= 7 )
return v1;
if ( a1 != 3 * (a1 / 3) )
{
v2 = 3;
while ( 1 )
{
v2 += 2;
if ( a1 / 2 <= v2 )
break;
if ( !(a1 % v2) )
return 0LL;
}
return v1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned int v1; // er8
int v2; // ecx

v1 = 1;
if ( a1 == 2 )
return v1;
v1 = a1 & 1;
if ( (a1 & 1) == 0 || a1 <= 7 )
return v1;
if ( a1 != 3 * (a1 / 3) )
{
v2 = 3;
while ( 1 )
{
v2 += 2;
if ( a1 / 2 <= v2 )
break;
if ( !(a1 % v2) )
return 0LL;
}
return v1;
}
return 0LL;
}

original_code:
int its_prime (int number) {
    if (number == 2)
        return 1;
    if ((number & 1) == 0)
        return 0;
    int start = 3;
    int to = number / 2;
    for (; start < to; start+=2) {
        if (number % start == 0) {
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int its_prime(int number) {
    if (number == 2)
        return 1;
    if ((number & 1) == 0)
        return 0;
    int start = 3;
    int to = number / 2;
    for (; start < to; start+=2) {
        if (number % start == 0) {
            return 0;
        }
    }
    return 1;
}

variable_types: start int

variable_types: to int


decompiled_code:
__int64 __fastcall find_prime(int a1)
{
unsigned int v1; // er9
int v2; // eax
int v3; // er10
int v4; // er11

v1 = 1;
if ( a1 > 0 )
{
do
v2 = its_prime(v1 + 1);
while ( v3 - ((v2 == 0) - 1) < v4 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
unsigned int v1; // er9
int v2; // eax
int v3; // er10
int v4; // er11

v1 = 1;
if ( a1 > 0 )
{
do
v2 = func8(v1 + 1);
while ( v3 - ((v2 == 0) - 1) < v4 );
}
return v1;
}

original_code:
int find_prime(int number) {
    int x = 0, prime = 1;
    while(x<number) {
        prime++;
        if (its_prime(prime))
            x++;
    }
    return prime;
}

canonical_original_code:
int find_prime(int number) {
    int x = 0; int prime = 1;
    while(x<number) {
        prime++;
        if (its_prime(prime))
            x++;
    }
    return prime;
}

variable_types: x int

variable_types: prime int


decompiled_code:
int __fastcall generate_prime(int a1, const char *a2)
{
int v2; // ebp
unsigned int v3; // ebx

v2 = 0;
v3 = 2;
if ( a1 > 0 )
{
while ( (unsigned int)its_prime(v3) )
{
LABEL_5:
++v2;
fprintf(_bss_start, "%d", v3);
if ( a1 <= v2 )
return fputc(10, _bss_start);
++v3;
fputs(a2, _bss_start);
}
while ( 1 )
{
++v3;
if ( a1 <= v2 )
break;
if ( (unsigned int)its_prime(v3) )
goto LABEL_5;
}
}
return fputc(10, _bss_start);
}

canonical_decompiled_code:
int __fastcall func10(int a1, const char *a2)
{
int v2; // ebp
unsigned int v3; // ebx

v2 = 0;
v3 = 2;
if ( a1 > 0 )
{
while ( (unsigned int)func8(v3) )
{
LABEL_5:
++v2;
fprintf(_bss_start, "%d", v3);
if ( a1 <= v2 )
return fputc(10, _bss_start);
++v3;
fputs(a2, _bss_start);
}
while ( 1 )
{
++v3;
if ( a1 <= v2 )
break;
if ( (unsigned int)func8(v3) )
goto LABEL_5;
}
}
return fputc(10, _bss_start);
}

original_code:
void generate_prime(int number, char *separator) {
    int loop = 0, prime = 2;
    for (; loop < number; prime++) {
        if (its_prime(prime)) {
            fprintf(stdout, "%d", prime);
            loop++;
            if (loop < number)
                fprintf(stdout, "%s", separator);
        }
    }
    fprintf(stdout, "\n");
}

canonical_original_code:
void generate_prime(int number, char *separator) {
    int loop = 0; int prime = 2;
    for (; loop < number; prime++) {
        if (its_prime(prime)) {
            fprintf(stdout, "%d", prime);
            loop++;
            if (loop < number)
                fprintf(stdout, "%s", separator);
        }
    }
    fprintf(stdout, "\n");
}

variable_types:
separator
char *

variable_types: loop int


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
const char **v4; // rbx
const char **v5; // r12
unsigned int v6; // edx
int v7; // ebx
int v8; // rdx^4
__int64 v9; // rdx
const char **v10; // rdi
unsigned __int8 v11; // bp
unsigned __int8 v12; // bl
__int64 v14; // rdx

LABEL_1:
while ( 1 )
{
v3 = prng(*(_QWORD *)&argc, argv, envp) & 0x7FF;
printf("%s %d: ", "tryit.c", 68LL);
printf("try to allocate %d bytes\n", (unsigned int)v3);
v4 = (const char **)pvPortMalloc((int)v3);
printf("%s %d: ", "tryit.c", 70LL);
argv = v4;
*(_QWORD *)&argc = "malloc returned %p\n";
printf("malloc returned %p\n", v4);
if ( !v4 )
break;
printf("allocate a block, size %d\n", (unsigned int)v3);
*(_QWORD *)&argc = v4;
argv = (const char **)(((unsigned __int64)(unsigned int)lfsr << 32) | v3 & 0x7FF);
write_cb(v4, argv);
if ( (_DWORD)v3 )
{
*(_QWORD *)&argc = (char *)v4 + (unsigned int)(v3 - 1) + 1;
do
{
v4 = (const char **)((char *)v4 + 1);
*((_BYTE *)v4 - 1) = prng(*(_QWORD *)&argc, argv, envp);
}
while ( v4 != *(const char ***)&argc );
}
}
while ( 1 )
{
if ( !(unsigned int)circbuf_size() )
goto LABEL_1;
v5 = (const char **)read_cb();
v7 = v6;
argv = (const char **)v6;
lfsr = v8;
printf("free a block, size %d\n", v6);
if ( v7 > 0 )
break;
LABEL_8:
*(_QWORD *)&argc = v5;
vPortFree(v5);
if ( (prng(v5, argv, v14) & 1) == 0 )
goto LABEL_1;
}
argv = v5;
v10 = (const char **)((char *)v5 + (unsigned int)(v7 - 1) + 1);
while ( 1 )
{
v11 = *(_BYTE *)argv;
v12 = prng(v10, argv, v9);
if ( v11 != v12 )
break;
argv = (const char **)((char *)argv + 1);
if ( argv == v10 )
goto LABEL_8;
}
printf("%s %d: ", "tryit.c", 84LL);
printf("OUCH: u=%02X, v=%02X\n", v11, v12);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
const char **v4; // rbx
const char **v5; // r12
unsigned int v6; // edx
int v7; // ebx
int v8; // rdx^4
__int64 v9; // rdx
const char **v10; // rdi
unsigned __int8 v11; // bp
unsigned __int8 v12; // bl
__int64 v14; // rdx

LABEL_1:
while ( 1 )
{
v3 = func9(*(_QWORD *)&argc, argv, envp) & 0x7FF;
printf("%s %d: ", "tryit.c", 68LL);
printf("try to allocate %d bytes\n", (unsigned int)v3);
v4 = (const char **)func11((int)v3);
printf("%s %d: ", "tryit.c", 70LL);
argv = v4;
*(_QWORD *)&argc = "malloc returned %p\n";
printf("malloc returned %p\n", v4);
if ( !v4 )
break;
printf("allocate a block, size %d\n", (unsigned int)v3);
*(_QWORD *)&argc = v4;
argv = (const char **)(((unsigned __int64)(unsigned int)lfsr << 32) | v3 & 0x7FF);
func10(v4, argv);
if ( (_DWORD)v3 )
{
*(_QWORD *)&argc = (char *)v4 + (unsigned int)(v3 - 1) + 1;
do
{
v4 = (const char **)((char *)v4 + 1);
*((_BYTE *)v4 - 1) = func9(*(_QWORD *)&argc, argv, envp);
}
while ( v4 != *(const char ***)&argc );
}
}
while ( 1 )
{
if ( !(unsigned int)func7() )
goto LABEL_1;
v5 = (const char **)func8();
v7 = v6;
argv = (const char **)v6;
lfsr = v8;
printf("free a block, size %d\n", v6);
if ( v7 > 0 )
break;
LABEL_8:
*(_QWORD *)&argc = v5;
func12(v5);
if ( (func9(v5, argv, v14) & 1) == 0 )
goto LABEL_1;
}
argv = v5;
v10 = (const char **)((char *)v5 + (unsigned int)(v7 - 1) + 1);
while ( 1 )
{
v11 = *(_BYTE *)argv;
v12 = func9(v10, argv, v9);
if ( v11 != v12 )
break;
argv = (const char **)((char *)argv + 1);
if ( argv == v10 )
goto LABEL_8;
}
printf("%s %d: ", "tryit.c", 84LL);
printf("OUCH: u=%02X, v=%02X\n", v11, v12);
return 1;
}

original_code:
int main(void)
{
    int i, size;
    char *p;
    while (1) {
        size = prng() & 0x7FF;
        printf("%s %d: ", "tryit.c", 68); printf("try to allocate %d bytes\n", size);
        p = (char *) pvPortMalloc(size);
        printf("%s %d: ", "tryit.c", 70); printf("malloc returned %p\n", p);
        if (p == ((void *)0)) {
            while (circbuf_size() > 0) {
                struct slot foo = read_cb();
                p = foo.pointer;
                lfsr = foo.lfsr;
                size = foo.size;
                printf("free a block, size %d\n", size);
                for (i = 0; i < size; i++) {
                    unsigned char u = p[i];
                    unsigned char v = (unsigned char) prng();
                    if (u != v) {
                        printf("%s %d: ", "tryit.c", 84); printf("OUCH: u=%02X, v=%02X\n", u, v);
                        return 1;
                    }
                }
                vPortFree(p);
                if ((prng() & 1) == 0) break;
            }
        } else {
            printf("allocate a block, size %d\n", size);
            write_cb((struct slot){.pointer=p, .size=size, .lfsr=lfsr});
            for (i = 0; i < size; i++) {
                p[i] = (unsigned char) prng();
            }
        }
    }
    return 0;
}

canonical_original_code:
int main()
{
    int i; int size;
    char *p;
    while (1) {
        size = prng() & 0x7FF;
        printf("%s %d: ", "tryit.c", 68); printf("try to allocate %d bytes\n", size);
        p = (char *) pvPortMalloc(size);
        printf("%s %d: ", "tryit.c", 70); printf("malloc returned %p\n", p);
        if (p == ((void *)0)) {
            while (circbuf_size() > 0) {
                struct slot foo = read_cb();
                p = foo.pointer;
                lfsr = foo.lfsr;
                size = foo.size;
                printf("free a block, size %d\n", size);
                for (i = 0; i < size; i++) {
                    unsigned char u = p[i];
                    unsigned char v = (unsigned char) prng();
                    if (u != v) {
                        printf("%s %d: ", "tryit.c", 84); printf("OUCH: u=%02X, v=%02X\n", u, v);
                        return 1;
                    }
                }
                vPortFree(p);
                if ((prng() & 1) == 0) break;
            }
        } else {
            printf("allocate a block, size %d\n", size);
            write_cb((struct slot){.pointer=p, .size=size, .lfsr=lfsr});
            for (i = 0; i < size; i++) {
                p[i] = (unsigned char) prng();
            }
        }
    }
    return 0;
}

variable_types: i int

variable_types: size int

variable_types:
p
char *

variable_types: struct slot { void *pointer; unsigned int size; unsigned int lfsr; }

variable_types:
u
unsigned char

variable_types:
v
unsigned char


decompiled_code:
__int64 circbuf_size()
{
return (write_pointer + 5000 - read_pointer) % 0x1388u;
}

canonical_decompiled_code:
__int64 func7()
{
return (write_pointer + 5000 - read_pointer) % 0x1388u;
}

original_code:
static unsigned int circbuf_size(void)
{
    return (write_pointer + 5000 - read_pointer) % 5000;
}

canonical_original_code:
static unsigned int circbuf_size()
{
    return (write_pointer + 5000 - read_pointer) % 5000;
}


decompiled_code:
__int64 read_cb()
{
unsigned int v0; // eax

v0 = read_pointer;
if ( write_pointer == read_pointer )
return 0LL;
read_pointer = (read_pointer + 1) % 0x1388u;
return slots[2 * v0];
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // eax

v0 = read_pointer;
if ( write_pointer == read_pointer )
return 0LL;
read_pointer = (read_pointer + 1) % 0x1388u;
return slots[2 * v0];
}

original_code:
static struct slot read_cb(void)
{
    struct slot foo;
    if (write_pointer == read_pointer) {
        return (struct slot){ .pointer=((void *)0), .size=0, .lfsr=0 };
    }
    foo = slots[read_pointer++];
    read_pointer %= 5000;
    return foo;
}

canonical_original_code:
static struct slot read_cb()
{
    struct slot foo;
    if (write_pointer == read_pointer) {
        return (struct slot){ .pointer=((void *)0), .size=0, .lfsr=0 };
    }
    foo = slots[read_pointer++];
    read_pointer %= 5000;
    return foo;
}

return_type: struct slot { void *pointer; unsigned int size; unsigned int lfsr; }


prng

decompiled_code:
__int64 prng()
{
lfsr = ((unsigned int)lfsr >> 1) | (unsigned __int16)(((unsigned __int16)((unsigned int)lfsr >> 5) ^ (unsigned __int16)(lfsr ^ ((unsigned int)lfsr >> 3) ^ ((unsigned int)lfsr >> 2))) << 15);
return (unsigned __int16)lfsr;
}

canonical_decompiled_code:
__int64 func9()
{
lfsr = ((unsigned int)lfsr >> 1) | (unsigned __int16)(((unsigned __int16)((unsigned int)lfsr >> 5) ^ (unsigned __int16)(lfsr ^ ((unsigned int)lfsr >> 3) ^ ((unsigned int)lfsr >> 2))) << 15);
return (unsigned __int16)lfsr;
}

original_code:
static int prng(void)
{
    static unsigned int bit;
    bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1;
    lfsr = (lfsr >> 1) | (bit << 15);
    return lfsr & 0xffff;
}

canonical_original_code:
static int prng()
{
    static unsigned int bit;
    bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1;
    lfsr = (lfsr >> 1) | (bit << 15);
    return lfsr & 0xffff;
}

variable_types:
bit
unsigned int


decompiled_code:
__int64 __fastcall write_cb(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 result; // rax

if ( (unsigned int)circbuf_size() == 4999 )
{
fwrite("circular buffer overflow\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v2 = write_pointer;
v3 = 2LL * (unsigned int)write_pointer;
slots[v3] = a1;
qword_4040A8[v3] = a2;
result = (v2 + 1) % 0x1388u;
write_pointer = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 result; // rax

if ( (unsigned int)func7() == 4999 )
{
fwrite("circular buffer overflow\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v2 = write_pointer;
v3 = 2LL * (unsigned int)write_pointer;
slots[v3] = a1;
qword_4040A8[v3] = a2;
result = (v2 + 1) % 0x1388u;
write_pointer = result;
return result;
}

original_code:
static void write_cb(struct slot foo)
{
    if (circbuf_size() == 5000 - 1) {
        fprintf(stderr, "circular buffer overflow\n");
        exit(1);
    }
    slots[write_pointer++] = foo;
    write_pointer %= 5000;
}

user_defined_types: struct slot { void *pointer; unsigned int size; unsigned int lfsr; }


pvPortMalloc

original_code:
void *pvPortMalloc( size_t xWantedSize )
{
    xBlockLink *pxBlock, *pxPreviousSizeBlock, *pxNewBlockLink;
    static portBASE_TYPE xHeapHasBeenInitialised = 0;
    void *pvReturn = ((void *)0);
    ;
    {
        if ( xHeapHasBeenInitialised == 0 )
        {
            { xBlockLink *pxFirstFreeBlock; xStartSize.pxNextSizeBlock = ( void * ) xHeap.ucHeap; xStartSize.xBlockSize = ( size_t ) 0; xStartAddr.pxNextAddrBlock = ( void * ) xHeap.ucHeap; xEnd.xBlockSize = 4096; xEnd.pxNextSizeBlock = ((void *)0); xEnd.pxNextAddrBlock = ((void *)0); pxFirstFreeBlock = ( void * ) xHeap.ucHeap; pxFirstFreeBlock->xBlockSize = 4096; pxFirstFreeBlock->pxNextSizeBlock = &xEnd; pxFirstFreeBlock->pxNextAddrBlock = &xEnd; };
            xHeapHasBeenInitialised = 1;
        }
        if ( xWantedSize > 0 )
        {
            xWantedSize += heapSTRUCT_SIZE;
            if( xWantedSize & ((1 << 2) - 1) )
            {
                xWantedSize += ( (1 << 2) - ( xWantedSize & ((1 << 2) - 1) ) );
            }
        }
        if ( ( xWantedSize > 0 ) && ( xWantedSize < 4096 ) )
        {
            pxPreviousSizeBlock = &xStartSize;
            pxBlock = xStartSize.pxNextSizeBlock;
            while ( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextSizeBlock ) )
            {
                pxPreviousSizeBlock = pxBlock;
                pxBlock = pxBlock->pxNextSizeBlock;
            }
            if ( pxBlock != &xEnd )
            {
                xBlockLink *pxPreviousAddrBlock = &xStartAddr;
                pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousSizeBlock->pxNextSizeBlock ) +
                                        heapSTRUCT_SIZE );
                while ((int) pxPreviousAddrBlock->pxNextAddrBlock < (int) pxBlock)
                    pxPreviousAddrBlock = pxPreviousAddrBlock->pxNextAddrBlock;
                ;
                pxPreviousSizeBlock->pxNextSizeBlock = pxBlock->pxNextSizeBlock;
                pxPreviousAddrBlock->pxNextAddrBlock = pxBlock->pxNextAddrBlock;
                if ( ( pxBlock->xBlockSize - xWantedSize ) > ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) ) )
                {
                    pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize );
                    pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
                    ;
                    pxBlock->xBlockSize = xWantedSize;
                    ;
                    { xBlockLink *pxIterator; size_t xBlockSize; xBlockSize = pxNewBlockLink->xBlockSize; for( pxIterator = &xStartSize; pxIterator->pxNextSizeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextSizeBlock ) { } pxNewBlockLink->pxNextSizeBlock = pxIterator->pxNextSizeBlock; pxIterator->pxNextSizeBlock = pxNewBlockLink; for ( pxIterator = &xStartAddr; pxIterator->pxNextAddrBlock != &xEnd && (int) pxIterator->pxNextAddrBlock < (int) pxNewBlockLink; pxIterator = pxIterator->pxNextAddrBlock ) { } pxNewBlockLink->pxNextAddrBlock = pxIterator->pxNextAddrBlock; pxIterator->pxNextAddrBlock = pxNewBlockLink; };
                }
                ;
                xFreeBytesRemaining -= pxBlock->xBlockSize;
            }
        }
    }
    ;
    return pvReturn;
}

canonical_original_code:
void *pvPortMalloc(unsigned long xWantedSize)
{
    struct A_BLOCK_LINK *pxBlock; struct A_BLOCK_LINK *pxPreviousSizeBlock; struct A_BLOCK_LINK *pxNewBlockLink;
    static int xHeapHasBeenInitialised = 0;
    void *pvReturn = ((void *)0);
    ;
    {
        if ( xHeapHasBeenInitialised == 0 )
        {
            { struct A_BLOCK_LINK *pxFirstFreeBlock; xStartSize.pxNextSizeBlock = ( void * ) xHeap.ucHeap; xStartSize.xBlockSize = ( unsigned long ) 0; xStartAddr.pxNextAddrBlock = ( void * ) xHeap.ucHeap; xEnd.xBlockSize = 4096; xEnd.pxNextSizeBlock = ((void *)0); xEnd.pxNextAddrBlock = ((void *)0); pxFirstFreeBlock = ( void * ) xHeap.ucHeap; pxFirstFreeBlock->xBlockSize = 4096; pxFirstFreeBlock->pxNextSizeBlock = &xEnd; pxFirstFreeBlock->pxNextAddrBlock = &xEnd; };
            xHeapHasBeenInitialised = 1;
        }
        if ( xWantedSize > 0 )
        {
            xWantedSize += heapSTRUCT_SIZE;
            if( xWantedSize & ((1 << 2) - 1) )
            {
                xWantedSize += ( (1 << 2) - ( xWantedSize & ((1 << 2) - 1) ) );
            }
        }
        if ( ( xWantedSize > 0 ) && ( xWantedSize < 4096 ) )
        {
            pxPreviousSizeBlock = &xStartSize;
            pxBlock = xStartSize.pxNextSizeBlock;
            while ( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextSizeBlock ) )
            {
                pxPreviousSizeBlock = pxBlock;
                pxBlock = pxBlock->pxNextSizeBlock;
            }
            if ( pxBlock != &xEnd )
            {
                struct A_BLOCK_LINK *pxPreviousAddrBlock = &xStartAddr;
                pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousSizeBlock->pxNextSizeBlock ) +
                                        heapSTRUCT_SIZE );
                while ((int) pxPreviousAddrBlock->pxNextAddrBlock < (int) pxBlock)
                    pxPreviousAddrBlock = pxPreviousAddrBlock->pxNextAddrBlock;
                ;
                pxPreviousSizeBlock->pxNextSizeBlock = pxBlock->pxNextSizeBlock;
                pxPreviousAddrBlock->pxNextAddrBlock = pxBlock->pxNextAddrBlock;
                if ( ( pxBlock->xBlockSize - xWantedSize ) > ( ( unsigned long ) ( heapSTRUCT_SIZE * 2 ) ) )
                {
                    pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize );
                    pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
                    ;
                    pxBlock->xBlockSize = xWantedSize;
                    ;
                    { struct A_BLOCK_LINK *pxIterator; unsigned long xBlockSize; xBlockSize = pxNewBlockLink->xBlockSize; for( pxIterator = &xStartSize; pxIterator->pxNextSizeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextSizeBlock ) { } pxNewBlockLink->pxNextSizeBlock = pxIterator->pxNextSizeBlock; pxIterator->pxNextSizeBlock = pxNewBlockLink; for ( pxIterator = &xStartAddr; pxIterator->pxNextAddrBlock != &xEnd && (int) pxIterator->pxNextAddrBlock < (int) pxNewBlockLink; pxIterator = pxIterator->pxNextAddrBlock ) { } pxNewBlockLink->pxNextAddrBlock = pxIterator->pxNextAddrBlock; pxIterator->pxNextAddrBlock = pxNewBlockLink; };
                }
                ;
                xFreeBytesRemaining -= pxBlock->xBlockSize;
            }
        }
    }
    ;
    return pvReturn;
}

variable_types:
xWantedSize
unsigned long

variable_types: struct A_BLOCK_LINK { struct A_BLOCK_LINK *pxNextSizeBlock; struct A_BLOCK_LINK *pxNextAddrBlock; unsigned long xBlockSize; } *

variable_types: xHeapHasBeenInitialised int

variable_types:
pvReturn
void *

variable_types:
xBlockSize
unsigned long


vPortFree

original_code:
void vPortFree( void *pv )
{
    unsigned char *puc = ( unsigned char * ) pv;
    xBlockLink *pxLink;
    if( pv )
    {
        puc -= heapSTRUCT_SIZE;
        pxLink = ( void * ) puc;
        ;
        {
            xBlockLink *previousPrevious, *previous, *successor;
            previousPrevious = ((void *)0);
            previous = &xStartAddr;
            while (previous->pxNextAddrBlock != &xEnd) {
                successor = previous->pxNextAddrBlock;
                if ((unsigned int) successor >= (unsigned int) pxLink)
                    break;
                previousPrevious = previous;
                previous = successor;
            }
            if (successor != &xEnd && ((xBlockLink*) (((char*)pxLink) + pxLink->xBlockSize)) == successor) {
                { xBlockLink *previousBySize, *successorBySize; previous->pxNextAddrBlock = successor->pxNextAddrBlock; previousBySize = &xStartSize; while (previousBySize->pxNextSizeBlock != ((void *)0)) { successorBySize = previousBySize->pxNextSizeBlock; if (successorBySize->xBlockSize >= successor->xBlockSize) break; previousBySize = successorBySize; } previousBySize->pxNextSizeBlock = successor->pxNextSizeBlock; };
                pxLink->xBlockSize += successor->xBlockSize;
            }
            if (previous != &xStartAddr && ((xBlockLink*) (((char*)previous) + previous->xBlockSize)) == pxLink) {
                { xBlockLink *previousBySize, *successorBySize; previousPrevious->pxNextAddrBlock = previous->pxNextAddrBlock; previousBySize = &xStartSize; while (previousBySize->pxNextSizeBlock != ((void *)0)) { successorBySize = previousBySize->pxNextSizeBlock; if (successorBySize->xBlockSize >= previous->xBlockSize) break; previousBySize = successorBySize; } previousBySize->pxNextSizeBlock = previous->pxNextSizeBlock; };
                previous->xBlockSize += pxLink->xBlockSize;
                pxLink = previous;
            }
            { xBlockLink *pxIterator; size_t xBlockSize; xBlockSize = ( ( xBlockLink * ) pxLink )->xBlockSize; for( pxIterator = &xStartSize; pxIterator->pxNextSizeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextSizeBlock ) { } ( ( xBlockLink * ) pxLink )->pxNextSizeBlock = pxIterator->pxNextSizeBlock; pxIterator->pxNextSizeBlock = ( ( xBlockLink * ) pxLink ); for ( pxIterator = &xStartAddr; pxIterator->pxNextAddrBlock != &xEnd && (int) pxIterator->pxNextAddrBlock < (int) ( ( xBlockLink * ) pxLink ); pxIterator = pxIterator->pxNextAddrBlock ) { } ( ( xBlockLink * ) pxLink )->pxNextAddrBlock = pxIterator->pxNextAddrBlock; pxIterator->pxNextAddrBlock = ( ( xBlockLink * ) pxLink ); };
            xFreeBytesRemaining += pxLink->xBlockSize;
        }
        ;
    }
}

canonical_original_code:
void vPortFree(void *pv)
{
    unsigned char *puc = ( unsigned char * ) pv;
    struct A_BLOCK_LINK *pxLink;
    if( pv )
    {
        puc -= heapSTRUCT_SIZE;
        pxLink = ( void * ) puc;
        ;
        {
            struct A_BLOCK_LINK *previousPrevious; struct A_BLOCK_LINK *previous; struct A_BLOCK_LINK *successor;
            previousPrevious = ((void *)0);
            previous = &xStartAddr;
            while (previous->pxNextAddrBlock != &xEnd) {
                successor = previous->pxNextAddrBlock;
                if ((unsigned int) successor >= (unsigned int) pxLink)
                    break;
                previousPrevious = previous;
                previous = successor;
            }
            if (successor != &xEnd && ((struct A_BLOCK_LINK *) (((char *)pxLink) + pxLink->xBlockSize)) == successor) {
                { struct A_BLOCK_LINK *previousBySize; struct A_BLOCK_LINK *successorBySize; previous->pxNextAddrBlock = successor->pxNextAddrBlock; previousBySize = &xStartSize; while (previousBySize->pxNextSizeBlock != ((void *)0)) { successorBySize = previousBySize->pxNextSizeBlock; if (successorBySize->xBlockSize >= successor->xBlockSize) break; previousBySize = successorBySize; } previousBySize->pxNextSizeBlock = successor->pxNextSizeBlock; };
                pxLink->xBlockSize += successor->xBlockSize;
            }
            if (previous != &xStartAddr && ((struct A_BLOCK_LINK *) (((char *)previous) + previous->xBlockSize)) == pxLink) {
                { struct A_BLOCK_LINK *previousBySize; struct A_BLOCK_LINK *successorBySize; previousPrevious->pxNextAddrBlock = previous->pxNextAddrBlock; previousBySize = &xStartSize; while (previousBySize->pxNextSizeBlock != ((void *)0)) { successorBySize = previousBySize->pxNextSizeBlock; if (successorBySize->xBlockSize >= previous->xBlockSize) break; previousBySize = successorBySize; } previousBySize->pxNextSizeBlock = previous->pxNextSizeBlock; };
                previous->xBlockSize += pxLink->xBlockSize;
                pxLink = previous;
            }
            { struct A_BLOCK_LINK *pxIterator; unsigned long xBlockSize; xBlockSize = ( ( struct A_BLOCK_LINK * ) pxLink )->xBlockSize; for( pxIterator = &xStartSize; pxIterator->pxNextSizeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextSizeBlock ) { } ( ( struct A_BLOCK_LINK * ) pxLink )->pxNextSizeBlock = pxIterator->pxNextSizeBlock; pxIterator->pxNextSizeBlock = ( ( struct A_BLOCK_LINK * ) pxLink ); for ( pxIterator = &xStartAddr; pxIterator->pxNextAddrBlock != &xEnd && (int) pxIterator->pxNextAddrBlock < (int) ( ( struct A_BLOCK_LINK * ) pxLink ); pxIterator = pxIterator->pxNextAddrBlock ) { } ( ( struct A_BLOCK_LINK * ) pxLink )->pxNextAddrBlock = pxIterator->pxNextAddrBlock; pxIterator->pxNextAddrBlock = ( ( struct A_BLOCK_LINK * ) pxLink ); };
            xFreeBytesRemaining += pxLink->xBlockSize;
        }
        ;
    }
}

variable_types:
pv
void *

variable_types:
puc
unsigned char *

user_defined_types: struct A_BLOCK_LINK { struct A_BLOCK_LINK *pxNextSizeBlock; struct A_BLOCK_LINK *pxNextAddrBlock; unsigned long xBlockSize; }


xPortGetFreeHeapSize

decompiled_code:
__int64 xPortGetFreeHeapSize()
{
return xFreeBytesRemaining;
}

canonical_decompiled_code:
__int64 func13()
{
return xFreeBytesRemaining;
}

original_code:
size_t xPortGetFreeHeapSize( void )
{
    return xFreeBytesRemaining;
}

canonical_original_code:
unsigned long xPortGetFreeHeapSize()
{
    return xFreeBytesRemaining;
}

return_type: unsigned long


vPortInitialiseBlocks

decompiled_code:
void vPortInitialiseBlocks()
{
;
}

canonical_decompiled_code:
void func14()
{
;
}

original_code:
void vPortInitialiseBlocks( void )
{
}

canonical_original_code:
void vPortInitialiseBlocks()
{
}


repo: emboss/openssl-prng

decompiled_code:
__int64 __fastcall RAND_set_rand_method(__int64 a1)
{
if ( funct_ref )
{
ENGINE_finish();
funct_ref = 0LL;
}
default_RAND_meth = a1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( funct_ref )
{
ENGINE_finish();
funct_ref = 0LL;
}
default_RAND_meth = a1;
return 1LL;
}

original_code:
int RAND_set_rand_method(const RAND_METHOD *meth)
 {
 if(funct_ref)
  {
  ENGINE_finish(funct_ref);
  funct_ref = ((void *)0);
  }
 default_RAND_meth = meth;
 return 1;
 }

canonical_original_code:
int RAND_set_rand_method(struct rand_meth_st *meth)
 {
 if(funct_ref)
  {
  ENGINE_finish(funct_ref);
  funct_ref = ((void *)0);
  }
 default_RAND_meth = meth;
 return 1;
 }

variable_types: struct rand_meth_st { void (*seed)(void *buf, int num); int (*bytes)(unsigned char *buf, int num); void (*cleanup)(); void (*add)(void *buf, int num, double entropy); int (*pseudorand)(unsigned char *buf, int num); int (*status)(); } *


decompiled_code:
__int64 RAND_cleanup()
{
__int64 v0; // rax
void (*v1)(void); // rax

v0 = RAND_get_rand_method();
if ( v0 )
{
v1 = *(void (**)(void))(v0 + 16);
if ( v1 )
v1();
}
return RAND_set_rand_method(0LL);
}

original_code:
void RAND_cleanup(void)
 {
 const RAND_METHOD *meth = RAND_get_rand_method();
 if (meth && meth->cleanup)
  meth->cleanup();
 RAND_set_rand_method(((void *)0));
 }

canonical_original_code:
void RAND_cleanup()
 {
 struct rand_meth_st *meth = RAND_get_rand_method();
 if (meth && meth->cleanup)
  meth->cleanup();
 RAND_set_rand_method(((void *)0));
 }

user_defined_types: struct rand_meth_st { void (*seed)(void *buf, int num); int (*bytes)(unsigned char *buf, int num); void (*cleanup)(); void (*add)(void *buf, int num, double entropy); int (*pseudorand)(unsigned char *buf, int num); int (*status)(); }


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

result = RAND_get_rand_method();
if ( result )
{
result = *(_QWORD *)(result + 24);
if ( result )
result = ((__int64 (__fastcall *)(__int64, _QWORD, double))result)(a1, a2, a3);
}
return result;
}

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

result = func1();
if ( result )
{
result = *(_QWORD *)(result + 24);
if ( result )
result = ((__int64 (__fastcall *)(__int64, _QWORD, double))result)(a1, a2, a3);
}
return result;
}

original_code:
void RAND_add(const void *buf, int num, double entropy)
 {
 const RAND_METHOD *meth = RAND_get_rand_method();
 if (meth && meth->add)
  meth->add(buf,num,entropy);
 }

canonical_original_code:
void RAND_add(void *buf, int num, double entropy)
 {
 struct rand_meth_st *meth = RAND_get_rand_method();
 if (meth && meth->add)
  meth->add(buf,num,entropy);
 }

variable_types:
buf
void *

variable_types: num int

variable_types: entropy double


decompiled_code:
__int64 __fastcall RAND_bytes(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 (__fastcall *v3)(__int64, _QWORD); // rax
__int64 result; // rax

v2 = RAND_get_rand_method();
if ( v2 && (v3 = *(__int64 (__fastcall **)(__int64, _QWORD))(v2 + 8)) != 0LL )
result = v3(a1, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 (__fastcall *v3)(__int64, _QWORD); // rax
__int64 result; // rax

v2 = func1();
if ( v2 && (v3 = *(__int64 (__fastcall **)(__int64, _QWORD))(v2 + 8)) != 0LL )
result = v3(a1, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int RAND_bytes(unsigned char *buf, int num)
 {
 const RAND_METHOD *meth = RAND_get_rand_method();
 if (meth && meth->bytes)
  return meth->bytes(buf,num);
 return(-1);
 }

canonical_original_code:
int RAND_bytes(unsigned char *buf, int num)
 {
 struct rand_meth_st *meth = RAND_get_rand_method();
 if (meth && meth->bytes)
  return meth->bytes(buf,num);
 return(-1);
 }

variable_types:
buf
unsigned char *


decompiled_code:
__int64 __fastcall RAND_pseudo_bytes(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 (__fastcall *v3)(__int64, _QWORD); // rax
__int64 result; // rax

v2 = RAND_get_rand_method();
if ( v2 && (v3 = *(__int64 (__fastcall **)(__int64, _QWORD))(v2 + 32)) != 0LL )
result = v3(a1, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 (__fastcall *v3)(__int64, _QWORD); // rax
__int64 result; // rax

v2 = func1();
if ( v2 && (v3 = *(__int64 (__fastcall **)(__int64, _QWORD))(v2 + 32)) != 0LL )
result = v3(a1, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int RAND_pseudo_bytes(unsigned char *buf, int num)
 {
 const RAND_METHOD *meth = RAND_get_rand_method();
 if (meth && meth->pseudorand)
  return meth->pseudorand(buf,num);
 return(-1);
 }

canonical_original_code:
int RAND_pseudo_bytes(unsigned char *buf, int num)
 {
 struct rand_meth_st *meth = RAND_get_rand_method();
 if (meth && meth->pseudorand)
  return meth->pseudorand(buf,num);
 return(-1);
 }


decompiled_code:
__int64 RAND_status()
{
__int64 v0; // rax
__int64 (*v1)(void); // rax
__int64 result; // rax

v0 = RAND_get_rand_method();
if ( v0 && (v1 = *(__int64 (**)(void))(v0 + 40)) != 0LL )
result = v1();
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rax
__int64 (*v1)(void); // rax
__int64 result; // rax

v0 = func1();
if ( v0 && (v1 = *(__int64 (**)(void))(v0 + 40)) != 0LL )
result = v1();
else
result = 0LL;
return result;
}

original_code:
int RAND_status(void)
 {
 const RAND_METHOD *meth = RAND_get_rand_method();
 if (meth && meth->status)
  return meth->status();
 return 0;
 }

canonical_original_code:
int RAND_status()
 {
 struct rand_meth_st *meth = RAND_get_rand_method();
 if (meth && meth->status)
  return meth->status();
 return 0;
 }


decompiled_code:
int dump_random()
{
char *v0; // rbx
unsigned int v1; // eax
__int64 v2; // rsi
int v4; // [rsp+Ch] [rbp-1Ch] BYREF
char v5; // [rsp+10h] [rbp-18h] BYREF

v4 = 0;
v0 = (char *)&v4;
RAND_bytes(&v4, 4LL);
v1 = getpid();
printf("pid=%d ", v1);
do
{
v2 = (unsigned __int8)*v0++;
printf("\\x%02x", v2);
}
while ( v0 != &v5 );
return puts(&s);
}

canonical_decompiled_code:
int func0()
{
char *v0; // rbx
unsigned int v1; // eax
__int64 v2; // rsi
int v4; // [rsp+Ch] [rbp-1Ch] BYREF
char v5; // [rsp+10h] [rbp-18h] BYREF

v4 = 0;
v0 = (char *)&v4;
RAND_bytes(&v4, 4LL);
v1 = getpid();
printf("pid=%d ", v1);
do
{
v2 = (unsigned __int8)*v0++;
printf("\\x%02x", v2);
}
while ( v0 != &v5 );
return puts(&s);
}

original_code:
static void dump_random(void)
{
    int i;
    unsigned char buf[4];
    memset(buf, 0, sizeof(buf));
    RAND_bytes(buf, sizeof(buf));
    printf("pid=%d ", getpid());
    for (i = 0; i < sizeof(buf); i++)
 printf("\\x%02x", buf[i]);
    puts("");
}

canonical_original_code:
static void dump_random()
{
    int i;
    unsigned char buf[4];
    memset(buf, 0, sizeof(buf));
    RAND_bytes(buf, sizeof(buf));
    printf("pid=%d ", getpid());
    for (i = 0; i < sizeof(buf); i++)
 printf("\\x%02x", buf[i]);
    puts("");
}

variable_types: i int

variable_types:
buf
unsigned char [4]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
__pid_t v4; // eax
__pid_t v5; // ebx
__pid_t v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

RAND_bytes(v7, 4LL);
v3 = fork();
v7[0] = v3;
if ( !v3 )
{
LABEL_10:
dump_random();
return 0;
}
if ( v3 > 0 )
{
wait(0LL);
while ( 1 )
{
v4 = fork();
v5 = v4;
if ( !v4 )
break;
if ( v4 > 0 )
{
wait(0LL);
if ( v7[0] == v5 )
return 0;
}
else
{
perror("fork");
if ( v7[0] == v5 )
return 0;
}
}
if ( getpid() != v7[0] )
return 0;
goto LABEL_10;
}
perror("fork");
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
__pid_t v4; // eax
__pid_t v5; // ebx
__pid_t v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

RAND_bytes(v7, 4LL);
v3 = fork();
v7[0] = v3;
if ( !v3 )
{
LABEL_10:
func0();
return 0;
}
if ( v3 > 0 )
{
wait(0LL);
while ( 1 )
{
v4 = fork();
v5 = v4;
if ( !v4 )
break;
if ( v4 > 0 )
{
wait(0LL);
if ( v7[0] == v5 )
return 0;
}
else
{
perror("fork");
if ( v7[0] == v5 )
return 0;
}
}
if ( getpid() != v7[0] )
return 0;
goto LABEL_10;
}
perror("fork");
return 1;
}

original_code:
int main(void)
{
    pid_t pid, xpid;
    RAND_bytes((unsigned char *)&pid, sizeof(pid));
    pid = fork();
    if (pid == 0) {
 dump_random();
 return 0;
    } else if (pid > 0) {
 wait(((void *)0));
 do {
     xpid = fork();
     if (xpid == 0) {
  if (getpid() == pid) {
      dump_random();
  }
  return 0;
     } else if (xpid > 0) {
  wait(((void *)0));
     } else {
  perror("fork");
     }
 } while (pid != xpid);
    } else {
 perror("fork");
 return 1;
    }
    return 0;
}

canonical_original_code:
int main()
{
    int pid; int xpid;
    RAND_bytes((unsigned char *)&pid, sizeof(pid));
    pid = fork();
    if (pid == 0) {
 dump_random();
 return 0;
    } else if (pid > 0) {
 wait(((void *)0));
 do {
     xpid = fork();
     if (xpid == 0) {
  if (getpid() == pid) {
      dump_random();
  }
  return 0;
     } else if (xpid > 0) {
  wait(((void *)0));
     } else {
  perror("fork");
     }
 } while (pid != xpid);
    } else {
 perror("fork");
 return 1;
    }
    return 0;
}

variable_types: pid int

variable_types: xpid int


original_code:
int RAND_poll(void)
{
 unsigned long l;
 pid_t curr_pid = getpid();
 l=curr_pid;
 RAND_add(&l,sizeof(l),0.0);
 l=getuid();
 RAND_add(&l,sizeof(l),0.0);
 l=time(((void *)0));
 RAND_add(&l,sizeof(l),0.0);
 return 0;
}

canonical_original_code:
int RAND_poll()
{
 unsigned long l;
 int curr_pid = getpid();
 l=curr_pid;
 RAND_add(&l,sizeof(l),0.0);
 l=getuid();
 RAND_add(&l,sizeof(l),0.0);
 l=time(((void *)0));
 RAND_add(&l,sizeof(l),0.0);
 return 0;
}

variable_types:
l
unsigned long


decompiled_code:
__int64 __fastcall my_putnbr(unsigned int a1)
{
if ( a1 > 9 )
my_putnbr(a1 / 0xAuLL);
return my_putchar((unsigned __int8)(a1 % 0xA + 48));
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
if ( a1 > 9 )
func0(a1 / 0xAuLL);
return my_putchar((unsigned __int8)(a1 % 0xA + 48));
}

original_code:
void my_putnbr(unsigned int nb)
{
  if (nb > 9)
    my_putnbr(nb / 10);
  my_putchar(nb % 10 + '0');
}

variable_types:
nb
unsigned int


decompiled_code:
__int64 refresh_win()
{
print_list();
wrefresh(g_ctrl);
wrefresh(*(WINDOW **)&g_ctrl->_regtop);
wrefresh(stdscr);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
print_list();
wrefresh(g_ctrl);
wrefresh(*(WINDOW **)&g_ctrl->_regtop);
wrefresh(stdscr);
return 1LL;
}

original_code:
t_bool refresh_win(int focus)
{
  print_list(focus);
  wrefresh(g_ctrl.menu[0].win);
  wrefresh(g_ctrl.menu[1].win);
  wrefresh(stdscr);
  return (1);
}

canonical_original_code:
unsigned char refresh_win(int focus)
{
  print_list(focus);
  wrefresh(g_ctrl.menu[0].win);
  wrefresh(g_ctrl.menu[1].win);
  wrefresh(stdscr);
  return (1);
}

variable_types: focus int

return_type: unsigned char


decompiled_code:
__int64 __fastcall catch_key()
{
int v0; // ebx
_DWORD *v1; // rax
int v2; // edx
int v3; // ecx
__int64 v4; // rdi
char *v5; // rdx
void (__fastcall *v6)(WINDOW **); // rcx
int v8; // eax

keypad(stdscr, 1);
do
{
if ( v0 == 9 )
{
v8 = (g_ctrl->_bkgrnd.chars[2] + 1) % 2;
g_ctrl->_bkgrnd.chars[2] = v8;
wbkgd(*(&g_ctrl + 7 * v8), 0x100uLL);
wbkgd(*(&g_ctrl + 7 * ((g_ctrl->_bkgrnd.chars[2] + 1) % 2)), 0x400uLL);
}
else if ( v0 == 259 )
{
((void (__fastcall *)(WINDOW **))arrow_up)(&g_ctrl + 7 * g_ctrl->_bkgrnd.chars[2]);
goto LABEL_10;
}
v1 = &g_movetab;
v2 = 258;
v3 = 0;
while ( 1 )
{
++v3;
v1 += 6;
if ( v0 == v2 || !v2 )
break;
v2 = v1[6];
}
v4 = g_ctrl->_bkgrnd.chars[2];
v5 = (char *)&g_movetab + 24 * v3;
v6 = (void (__fastcall *)(WINDOW **))*((_QWORD *)v5 + 1);
if ( v6 )
{
v6(&g_ctrl + 7 * (int)v4);
LABEL_10:
v4 = (unsigned int)g_ctrl->_bkgrnd.chars[2];
goto LABEL_11;
}
if ( *((_QWORD *)v5 + 2) )
{
exec_sh(*((_QWORD *)v5 + 2), &g_ctrl + 7 * v4);
v4 = (unsigned int)g_ctrl->_bkgrnd.chars[2];
}
LABEL_11:
refresh_win(v4);
v0 = wgetch(stdscr);
}
while ( v0 != 113 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1()
{
int v0; // ebx
_DWORD *v1; // rax
int v2; // edx
int v3; // ecx
__int64 v4; // rdi
char *v5; // rdx
void (__fastcall *v6)(WINDOW **); // rcx
int v8; // eax

keypad(stdscr, 1);
do
{
if ( v0 == 9 )
{
v8 = (g_ctrl->_bkgrnd.chars[2] + 1) % 2;
g_ctrl->_bkgrnd.chars[2] = v8;
wbkgd(*(&g_ctrl + 7 * v8), 0x100uLL);
wbkgd(*(&g_ctrl + 7 * ((g_ctrl->_bkgrnd.chars[2] + 1) % 2)), 0x400uLL);
}
else if ( v0 == 259 )
{
((void (__fastcall *)(WINDOW **))arrow_up)(&g_ctrl + 7 * g_ctrl->_bkgrnd.chars[2]);
goto LABEL_10;
}
v1 = &g_movetab;
v2 = 258;
v3 = 0;
while ( 1 )
{
++v3;
v1 += 6;
if ( v0 == v2 || !v2 )
break;
v2 = v1[6];
}
v4 = g_ctrl->_bkgrnd.chars[2];
v5 = (char *)&g_movetab + 24 * v3;
v6 = (void (__fastcall *)(WINDOW **))*((_QWORD *)v5 + 1);
if ( v6 )
{
v6(&g_ctrl + 7 * (int)v4);
LABEL_10:
v4 = (unsigned int)g_ctrl->_bkgrnd.chars[2];
goto LABEL_11;
}
if ( *((_QWORD *)v5 + 2) )
{
exec_sh(*((_QWORD *)v5 + 2), &g_ctrl + 7 * v4);
v4 = (unsigned int)g_ctrl->_bkgrnd.chars[2];
}
LABEL_11:
func0(v4);
v0 = wgetch(stdscr);
}
while ( v0 != 113 );
return 1LL;
}

original_code:
t_bool catch_key()
{
  int i;
  int key;
  keypad(stdscr, 1);
  i = -1;
  while (i == -1 || (key = wgetch(stdscr)) != 'q')
    {
      i = 0;
      if (key == '\t')
 {
   g_ctrl.focus = (g_ctrl.focus + 1) % 2;
   wbkgd(g_ctrl.menu[g_ctrl.focus].win, (((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
   wbkgd(g_ctrl.menu[(g_ctrl.focus + 1) % 2].win, (((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
 }
      while (g_movetab[i].c != 0 && g_movetab[i].c != key)
 i++;
      if (g_movetab[i].fct != ((void *)0))
 g_movetab[i].fct(&(g_ctrl.menu[g_ctrl.focus]));
      else if (g_movetab[i].sh != ((void *)0))
 exec_sh(g_movetab[i].sh, &(g_ctrl.menu[g_ctrl.focus]));
      refresh_win(g_ctrl.focus);
    }
  return (1);
}

canonical_original_code:
unsigned char catch_key()
{
  int i;
  int key;
  keypad(stdscr, 1);
  i = -1;
  while (i == -1 || (key = wgetch(stdscr)) != 'q')
    {
      i = 0;
      if (key == '\t')
 {
   g_ctrl.focus = (g_ctrl.focus + 1) % 2;
   wbkgd(g_ctrl.menu[g_ctrl.focus].win, (((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
   wbkgd(g_ctrl.menu[(g_ctrl.focus + 1) % 2].win, (((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
 }
      while (g_movetab[i].c != 0 && g_movetab[i].c != key)
 i++;
      if (g_movetab[i].fct != ((void *)0))
 g_movetab[i].fct(&(g_ctrl.menu[g_ctrl.focus]));
      else if (g_movetab[i].sh != ((void *)0))
 exec_sh(g_movetab[i].sh, &(g_ctrl.menu[g_ctrl.focus]));
      refresh_win(g_ctrl.focus);
    }
  return (1);
}

variable_types: key int


decompiled_code:
__int64 __fastcall my_strndup(char *a1, int a2)
{
int v2; // eax
__int64 v3; // r8
char v4; // dl
__int64 v5; // rax

if ( !a1 )
return 0LL;
v2 = my_strlen();
v3 = my_malloc((unsigned int)(v2 + 1));
if ( !v3 )
return 0LL;
v4 = *a1;
if ( a2 > 0 && v4 )
{
v5 = 0LL;
do
{
*(_BYTE *)(v3 + v5++) = v4;
v4 = a1[v5];
}
while ( a2 > (int)v5 && v4 );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, int a2)
{
int v2; // eax
__int64 v3; // r8
char v4; // dl
__int64 v5; // rax

if ( !a1 )
return 0LL;
v2 = my_strlen();
v3 = my_malloc((unsigned int)(v2 + 1));
if ( !v3 )
return 0LL;
v4 = *a1;
if ( a2 > 0 && v4 )
{
v5 = 0LL;
do
{
*(_BYTE *)(v3 + v5++) = v4;
v4 = a1[v5];
}
while ( a2 > (int)v5 && v4 );
}
return v3;
}

original_code:
char *my_strndup(char *str, int len)
{
  char *ret;
  int i;
  if (!str)
    return (str);
  i = 0;
  if ((ret = my_malloc(sizeof(*ret) * (my_strlen(str) + 1))) == ((void *)0))
    return (((void *)0));
  while (str[i] != '\0' && i < len)
    {
      ret[i] = str[i];
      i++;
    }
  return (ret);
}

variable_types:
str
char *

variable_types: len int

variable_types:
ret
char *

return_type: char *


decompiled_code:
__int64 __fastcall my_read(int a1, void *a2, int a3)
{
unsigned int v3; // er12

v3 = 0;
if ( a3 > 0 )
{
if ( a2 )
{
v3 = read(a1, a2, a3);
if ( v3 == -1 )
print_errno(2LL);
}
else
{
v3 = -1;
print_errno(1LL);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, void *a2, int a3)
{
unsigned int v3; // er12

v3 = 0;
if ( a3 > 0 )
{
if ( a2 )
{
v3 = read(a1, a2, a3);
if ( v3 == -1 )
print_errno(2LL);
}
else
{
v3 = -1;
print_errno(1LL);
}
}
return v3;
}

original_code:
int my_read(const int fd, void *buf, const int count)
{
  int ret;
  if (count <= 0)
    return (0);
  if (!buf)
    {
      print_errno(1);
      return (-1);
    }
  if ((ret = read(fd, buf, count)) == -1)
    {
      print_errno(2);
      return (-1);
    }
  if (ret == 0)
    return (0);
  return (ret);
}

canonical_original_code:
int my_read(int fd, void *buf, int count)
{
  int ret;
  if (count <= 0)
    return (0);
  if (!buf)
    {
      print_errno(1);
      return (-1);
    }
  if ((ret = read(fd, buf, count)) == -1)
    {
      print_errno(2);
      return (-1);
    }
  if (ret == 0)
    return (0);
  return (ret);
}

variable_types: fd int

variable_types: count int

variable_types: ret int