decompiled_code:
void send_txt()
{
size_t v0; // rax
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

sprintf(v1, "%d %f %s..", 6LL, pj_ang, (const char *)&pj_txtbuf);
printf("msg:%s\n", v1);
v0 = strlen(v1);
if ( send(sockfd, v1, v0, 0) == -1 )
perror("send");
}

canonical_decompiled_code:
void func3()
{
size_t v0; // rax
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

sprintf(v1, "%d %f %s..", 6LL, pj_ang, (const char *)&pj_txtbuf);
printf("msg:%s\n", v1);
v0 = strlen(v1);
if ( send(sockfd, v1, v0, 0) == -1 )
perror("send");
}

original_code:
void send_txt()
{
 char msg[256];
 sprintf(msg,"%d %f %s..",6,pj_ang,pj_txtbuf);
 printf("msg:%s\n",msg);
 if (send(sockfd, msg, strlen(msg), 0) == -1) perror("send");
}

variable_types:
msg
char [256]


repo: joseprous/kianagy

decompiled_code:
void send_name()
{
size_t v0; // rax
char v1[216]; // [rsp+0h] [rbp-D8h] BYREF

sprintf(v1, "%d 0 %s..", 7LL, (const char *)&myname);
v0 = strlen(v1);
if ( send(sockfd, v1, v0, 0) == -1 )
perror("send");
}

canonical_decompiled_code:
void func4()
{
size_t v0; // rax
char v1[216]; // [rsp+0h] [rbp-D8h] BYREF

sprintf(v1, "%d 0 %s..", 7LL, (const char *)&myname);
v0 = strlen(v1);
if ( send(sockfd, v1, v0, 0) == -1 )
perror("send");
}

original_code:
void send_name()
{
 char msg[200];
 sprintf(msg,"%d 0 %s..",7,myname);
 if (send(sockfd, msg, strlen(msg), 0) == -1) perror("send");
}

variable_types:
msg
char [200]

return_type: void


count

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

result = 0LL;
if ( a1 )
result = (unsigned int)count(*(_QWORD *)(a1 + 336)) + 1;
return result;
}

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

result = 0LL;
if ( a1 )
result = (unsigned int)func5(*(_QWORD *)(a1 + 336)) + 1;
return result;
}

original_code:
int count(struct player *p)
{
 if(p==0)return 0;
 return 1+count(p->next);
}

variable_types: struct player { int tipo; int id; int model; int weapon; int hp; float x; float dir; float vel; int acc; char txt[-1]; char name[-1]; int txt_ini_time; int alive; int n; float interp; struct player *next; } *

return_type: int


original_code:
int buscar_player(int tipo,int id,char *name,int hp,float x,float y,float z,int acc,float ang,char *txt)
{
 struct player *aux;
 aux=players;
 while(aux!=((void *)0)){
  if(aux->id==id){
   SDL_mutexP (mutex);
    aux->tipo=tipo;
    strcpy(aux->name,name);
    aux->hp=hp;
    aux->x=x;
    aux->y=y;
    aux->z=z;
    aux->acc=acc;
    if(acc==8){
     aux->model=1;
    }else{
     aux->model=2;
    }
    aux->dir=ang;
    aux->vel=0;
    if(txt[0]){
     strcpy(aux->txt,txt);
     aux->txt_ini_time=SDL_GetTicks();
    }
    aux->alive=1;
   SDL_mutexV (mutex);
   return 1;
  }
  aux=aux->next;
 }
 return 0;
}

canonical_original_code:
int buscar_player(int tipo, int id, char *name, int hp, float x, float y, float z, int acc, float ang, char *txt)
{
 struct player *aux;
 aux=players;
 while(aux!=((void *)0)){
  if(aux->id==id){
   SDL_mutexP (mutex);
    aux->tipo=tipo;
    strcpy(aux->name,name);
    aux->hp=hp;
    aux->x=x;
    aux->y=y;
    aux->z=z;
    aux->acc=acc;
    if(acc==8){
     aux->model=1;
    }else{
     aux->model=2;
    }
    aux->dir=ang;
    aux->vel=0;
    if(txt[0]){
     strcpy(aux->txt,txt);
     aux->txt_ini_time=SDL_GetTicks();
    }
    aux->alive=1;
   SDL_mutexV (mutex);
   return 1;
  }
  aux=aux->next;
 }
 return 0;
}

variable_types: tipo int

variable_types: id int

variable_types:
name
char *

variable_types: hp int

variable_types: x float

variable_types: y float

variable_types: z float

variable_types: acc int

variable_types: ang float

variable_types:
txt
char *

user_defined_types: struct player { int tipo; int id; int model; int weapon; int hp; float x; float dir; float vel; int acc; char txt[-1]; char name[-1]; int txt_ini_time; int alive; int n; float interp; struct player *next; }


network

original_code:
int network(void *data)
{
 char buf[1024],buf2[1024],txt[256],gname[16];
 char curbuf[1024]="";
 struct player *aux,*aux2;
 char *pbuf;
 int i,j,k,c,i2;
 static int c1=0;
 int numbytes;
 int gid,gacc,gtipo=3;
 float gx,gy,gz,gang;
 int ghp;
 while(1){
  if ((numbytes=recv(sockfd, buf, 1024-1, 0)) == -1) {
   perror("recv");
   exit(1);
  }
  buf[numbytes] = '\0';
  if(!numbytes)continue;
  for(i2=0;i2<numbytes;i2++){
   if(buf[i2]!='\n'){
    curbuf[c1]=buf[i2];
    c1++;
   }else{
    curbuf[c1]=0;
    if(curbuf[0]=='<' && curbuf[1]=='0' && curbuf[2]=='>' ){
     j=0;
     for(i=3;i<c1;i++){
      if(curbuf[i]!=';'){
       buf2[j]=curbuf[i];
       j++;
      }else{
       buf2[j]=0;
       pbuf=buf2;
       sscanf(pbuf,"%d,",&gtipo);
       while(pbuf[0]!=',')pbuf++;
       pbuf++;
       sscanf(pbuf,"%d,",&gid);
       while(pbuf[0]!=',')pbuf++;
       pbuf++;
       k=0;
       while(pbuf[0]!=','){
        gname[k]=pbuf[0];
        pbuf++;
        k++;
       }
       gname[k]=0;
       pbuf++;
       sscanf(pbuf,"%d,%f,%f,%f,%d,%f",&ghp,&gx,&gy,&gz,&gacc,&gang);
       c=0;
       for(k=0;k<6;k++){
        while(pbuf[c]!=',')c++;
        c++;
       }
       strcpy(txt,pbuf+c);
       if(!buscar_player(gtipo,gid,gname,ghp,gx,gy,gz,gacc,gang,txt)){
        aux=players;
        while(aux->next!=((void *)0)){
         aux=aux->next;
        }
        SDL_mutexP (mutex);
         aux->next=malloc(sizeof(struct player));
         aux->next->tipo=gtipo;
         aux->next->id=gid;
         aux->next->hp=ghp;
         aux->next->x=gx;
         aux->next->y=gy;
         aux->next->z=gz;
         aux->next->acc=gacc;
         if(gacc==8){
          aux->next->model=1;
         }else{
          aux->next->model=2;
         }
         aux->next->weapon=rand()%12;
         if(txt[0]){
          strcpy(aux->txt,txt);
          aux->txt_ini_time=SDL_GetTicks();
         }else{
          aux->next->txt[0]=0;
          aux->next->txt_ini_time=0;
         }
         strcpy(aux->name,gname);
         aux->next->dir=gang;
         aux->next->vel=0;
         aux->next->next=0;
         aux->next->alive=1;
         aux->interp=0;
        SDL_mutexV (mutex);
       }
       j=0;
      }
     }
     aux=players;
     while(aux->next!=((void *)0)){
      if(!aux->next->alive){
       aux2=aux->next->next;
       free(aux->next);
       aux->next=aux2;
      }else{
       aux->next->alive=0;
       aux=aux->next;
      }
     }
    }else{
     printf("Error %s\n",curbuf);
    }
    c1=0;
   }
  }
 }
}

canonical_original_code:
int network(void *data)
{
 char buf[1024]; char buf2[1024]; char txt[256]; char gname[16];
 char curbuf[1024] = "";
 struct player *aux; struct player *aux2;
 char *pbuf;
 int i; int j; int k; int c; int i2;
 static int c1 = 0;
 int numbytes;
 int gid; int gacc; int gtipo = 3;
 float gx; float gy; float gz; float gang;
 int ghp;
 while(1){
  if ((numbytes=recv(sockfd, buf, 1024-1, 0)) == -1) {
   perror("recv");
   exit(1);
  }
  buf[numbytes] = '\0';
  if(!numbytes)continue;
  for(i2=0;i2<numbytes;i2++){
   if(buf[i2]!='\n'){
    curbuf[c1]=buf[i2];
    c1++;
   }else{
    curbuf[c1]=0;
    if(curbuf[0]=='<' && curbuf[1]=='0' && curbuf[2]=='>' ){
     j=0;
     for(i=3;i<c1;i++){
      if(curbuf[i]!=';'){
       buf2[j]=curbuf[i];
       j++;
      }else{
       buf2[j]=0;
       pbuf=buf2;
       sscanf(pbuf,"%d,",&gtipo);
       while(pbuf[0]!=',')pbuf++;
       pbuf++;
       sscanf(pbuf,"%d,",&gid);
       while(pbuf[0]!=',')pbuf++;
       pbuf++;
       k=0;
       while(pbuf[0]!=','){
        gname[k]=pbuf[0];
        pbuf++;
        k++;
       }
       gname[k]=0;
       pbuf++;
       sscanf(pbuf,"%d,%f,%f,%f,%d,%f",&ghp,&gx,&gy,&gz,&gacc,&gang);
       c=0;
       for(k=0;k<6;k++){
        while(pbuf[c]!=',')c++;
        c++;
       }
       strcpy(txt,pbuf+c);
       if(!buscar_player(gtipo,gid,gname,ghp,gx,gy,gz,gacc,gang,txt)){
        aux=players;
        while(aux->next!=((void *)0)){
         aux=aux->next;
        }
        SDL_mutexP (mutex);
         aux->next=malloc(sizeof(struct player));
         aux->next->tipo=gtipo;
         aux->next->id=gid;
         aux->next->hp=ghp;
         aux->next->x=gx;
         aux->next->y=gy;
         aux->next->z=gz;
         aux->next->acc=gacc;
         if(gacc==8){
          aux->next->model=1;
         }else{
          aux->next->model=2;
         }
         aux->next->weapon=rand()%12;
         if(txt[0]){
          strcpy(aux->txt,txt);
          aux->txt_ini_time=SDL_GetTicks();
         }else{
          aux->next->txt[0]=0;
          aux->next->txt_ini_time=0;
         }
         strcpy(aux->name,gname);
         aux->next->dir=gang;
         aux->next->vel=0;
         aux->next->next=0;
         aux->next->alive=1;
         aux->interp=0;
        SDL_mutexV (mutex);
       }
       j=0;
      }
     }
     aux=players;
     while(aux->next!=((void *)0)){
      if(!aux->next->alive){
       aux2=aux->next->next;
       free(aux->next);
       aux->next=aux2;
      }else{
       aux->next->alive=0;
       aux=aux->next;
      }
     }
    }else{
     printf("Error %s\n",curbuf);
    }
    c1=0;
   }
  }
 }
}

variable_types:
data
void *

variable_types:
buf
char [1024]

variable_types:
txt
char [256]

variable_types:
gname
char [16]

variable_types:
curbuf
char [1024]

variable_types:
pbuf
char *

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: c int

variable_types: numbytes int

variable_types: gid int

variable_types: gacc int

variable_types: gtipo int

variable_types: gx float

variable_types: gy float

variable_types: gz float

variable_types: gang float

variable_types: ghp int


decompiled_code:
int end_network()
{
return close(sockfd);
}

canonical_decompiled_code:
int func9()
{
return close(sockfd);
}

original_code:
void end_network()
{
 close(sockfd);
}

canonical_original_code:
void end_network()
{
 close(sockfd);
}


comb

decompiled_code:
__int64 __fastcall comb(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // ecx
unsigned int v4; // edi

result = 0LL;
if ( a2 <= a1 )
{
if ( a2 )
{
v3 = 1;
LODWORD(result) = 1;
v4 = a1 + 1;
do
{
result = (v4 - v3) * (unsigned int)result / v3;
++v3;
}
while ( a2 >= v3 );
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // ecx
unsigned int v4; // edi

result = 0LL;
if ( a2 <= a1 )
{
if ( a2 )
{
v3 = 1;
LODWORD(result) = 1;
v4 = a1 + 1;
do
{
result = (v4 - v3) * (unsigned int)result / v3;
++v3;
}
while ( a2 >= v3 );
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
unsigned int comb(unsigned int m, unsigned int n) {
  unsigned r = 1;
  unsigned d;
  if (n > m) return 0;
  for (d=1; d <= n; d++) {
    r *= m--;
    r /= d;
  }
  return r;
}

canonical_original_code:
unsigned int comb(unsigned int m, unsigned int n) {
  unsigned int r = 1;
  unsigned int d;
  if (n > m) return 0;
  for (d=1; d <= n; d++) {
    r *= m--;
    r /= d;
  }
  return r;
}

variable_types:
m
unsigned int

variable_types:
n
unsigned int

variable_types:
r
unsigned int

variable_types:
d
unsigned int

return_type: unsigned int


printvector

decompiled_code:
int __fastcall printvector(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
return printf("<%lf %lf %lf> ", a9, a10, a11);
}

canonical_decompiled_code:
int __fastcall func1(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
return printf("<%lf %lf %lf> ", a9, a10, a11);
}

original_code:
void printvector(struct vector v)
{
 printf("<%lf %lf %lf> ",v.x,v.y,v.z);
}

variable_types:
v
struct vector { double x; }


pointinpoly

decompiled_code:
__int64 __fastcall pointinpoly(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9, int a10)
{
__int64 v10; // rbx
__int64 result; // rax

if ( a10 <= 0 )
return 0LL;
v10 = 0LL;
while ( 1 )
{
result = comppoints(a1, a2, a3, a4, a5, a6);
if ( (_DWORD)result )
break;
v10 += 24LL;
if ( v10 == 24LL * (unsigned int)a10 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9, int a10)
{
__int64 v10; // rbx
__int64 result; // rax

if ( a10 <= 0 )
return 0LL;
v10 = 0LL;
while ( 1 )
{
result = comppoints(a1, a2, a3, a4, a5, a6);
if ( (_DWORD)result )
break;
v10 += 24LL;
if ( v10 == 24LL * (unsigned int)a10 )
return result;
}
return 1LL;
}

original_code:
int pointinpoly(struct vector point,struct poly p)
{
 int i;
 for(i=0;i<p.num;i++){
  if(comppoints(point,p.vertexes[i]))return 1;
 }
 return 0;
}

canonical_original_code:
int pointinpoly(struct vector point, struct poly p)
{
 int i;
 for(i=0;i<p.num;i++){
  if(comppoints(point,p.vertexes[i]))return 1;
 }
 return 0;
}

variable_types:
point
struct vector { double x; }

variable_types: struct poly { int num; struct vector *vertexes; struct vector center; struct vector normal; struct texture { char *name; } tex; }

variable_types: i int

user_defined_types: struct poly { int num; struct vector *vertexes; struct vector center; struct vector normal; struct texture tex; }


glPrint

decompiled_code:
void glPrint(char *format, ...)
{
size_t v1; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1D0h] BYREF
char s[256]; // [rsp+20h] [rbp-1B8h] BYREF

if ( format )
{
va_start(arg, format);
vsprintf(s, format, arg);
glPushAttrib(0x20000LL);
glListBase((unsigned int)(base - 32));
v1 = strlen(s);
glCallLists(v1, 5121LL, s);
glPopAttrib();
}
}

canonical_decompiled_code:
void func1(char *format, ...)
{
size_t v1; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1D0h] BYREF
char s[256]; // [rsp+20h] [rbp-1B8h] BYREF

if ( format )
{
va_start(arg, format);
vsprintf(s, format, arg);
glPushAttrib(0x20000LL);
glListBase((unsigned int)(base - 32));
v1 = strlen(s);
glCallLists(v1, 5121LL, s);
glPopAttrib();
}
}

original_code:
GLvoid glPrint( const char *fmt, ... )
{
    char text[256];
    va_list ap;
    if ( fmt == ((void *)0) )
 return;
    __builtin_va_start(ap,fmt);
      vsprintf( text, fmt, ap );
    __builtin_va_end(ap);
    glPushAttrib( 0x00020000 );
    glListBase( base - 32 );
    glCallLists( strlen( text ), 0x1401, text );
    glPopAttrib( );
}

canonical_original_code:
void glPrint(char *fmt, ...)
{
    char text[256];
    __builtin_va_list ap;
    if ( fmt == ((void *)0) )
 return;
    __builtin_va_start(ap,fmt);
      vsprintf( text, fmt, ap );
    __builtin_va_end(ap);
    glPushAttrib( 0x00020000 );
    glListBase( base - 32 );
    glCallLists( strlen( text ), 0x1401, text );
    glPopAttrib( );
}

variable_types:
fmt
char *

variable_types:
text
char [256]


validate

repo: joshi-prahlad/CPrograms

original_code:
void validate(int* output, int num_elements) {
    int i = 0;
    ((void) sizeof ((output != ((void *)0)) ? 1 : 0), __extension__ ({ if (output != ((void *)0)) ; else __assert_fail ("output != NULL", "validate.c", 8, __extension__ __PRETTY_FUNCTION__); }));
    for(i = 0; i < num_elements - 1; i++) {
        if (output[i] > output[i+1]) {
            printf("************* NOT sorted *************\n");
            return;
        }
    }
    printf("============= SORTED ===========\n");
}

canonical_original_code:
void validate(int *output, int num_elements) {
    int i = 0;
    ((void) sizeof ((output != ((void *)0)) ? 1 : 0), __extension__ ({ if (output != ((void *)0)) ; else __assert_fail ("output != NULL", "validate.c", 8, __extension__ __PRETTY_FUNCTION__); }));
    for(i = 0; i < num_elements - 1; i++) {
        if (output[i] > output[i+1]) {
            printf("************* NOT sorted *************\n");
            return;
        }
    }
    printf("============= SORTED ===========\n");
}

variable_types:
output
int *


repo: joshsh/archive

decompiled_code:
void __fastcall array__delete(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void array__delete(struct JS_array *a)
{
  free(a->buffer);
  free(a);
}

variable_types: struct JS_array { int head; double expansion; void **buffer; } *


original_code:
void array__minimize(struct JS_array *a)
{
  int i;
  void **buffer0;
  if (a->size < a->buffer_size) {
    if (!a->size) {
      buffer0 = (void **) malloc(sizeof(void *));
      a->buffer_size = 1;
    } else {
      buffer0 = (void **) malloc(a->size * sizeof(void *));
      for (i=0; i<a->size; i++)
        buffer0[i] = a->buffer[(a->head+i)%a->buffer_size];
      a->buffer_size = a->size;
    }
    free(a->buffer);
    a->buffer = buffer0;
    a->head = 0;
  }
}

user_defined_types: struct JS_array { int head; double expansion; void **buffer; }


original_code:
void *array__get(struct JS_array *a, int index)
{
  if ((index >=0)&&(index < a->size))
    return a->buffer[(index+a->head)%a->buffer_size];
  else
    return ((void *)0);
}

variable_types: index int

return_type: void *


decompiled_code:
__int64 __fastcall array__peek(int *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1[1] )
result = *(_QWORD *)(*((_QWORD *)a1 + 3) + 8LL * *a1);
return result;
}

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

result = 0LL;
if ( a1[1] )
result = *(_QWORD *)(*((_QWORD *)a1 + 3) + 8LL * *a1);
return result;
}

original_code:
void *array__peek(struct JS_array *a)
{
  if (a->size)
    return a->buffer[a->head];
  else
    return ((void *)0);
}


original_code:
void array__push(struct JS_array *a, void *p)
{
  if (a->size >= a->buffer_size)
    array__expand(a);
  a->head = ((a->head-1)+a->buffer_size)%a->buffer_size;
  a->buffer[a->head] = p;
  a->size++;
}

variable_types:
p
void *


original_code:
void *array__pop(struct JS_array *a)
{
  void *p;
  if (a->size) {
    p = a->buffer[a->head];
    a->head = (a->head+1)%a->buffer_size;
    a->size--;
    return p;
  } else
    return ((void *)0);
}


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

if ( *(_DWORD *)(a1 + 4) >= *(_DWORD *)(a1 + 8) )
array__expand((int *)a1);
result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(result + 8LL * ((*(_DWORD *)a1 + (*(_DWORD *)(a1 + 4))++) % *(_DWORD *)(a1 + 8))) = a2;
return result;
}

original_code:
void array__enqueue(struct JS_array *a, void *p)
{
  if (a->size >= a->buffer_size)
    array__expand(a);
  a->buffer[(a->head+a->size)%a->buffer_size] = p;
  a->size++;
}


original_code:
void *array__dequeue(struct JS_array *a)
{
  if (a->size) {
    a->size--;
    return a->buffer[(a->head+a->size)%a->buffer_size];
  } else
    return ((void *)0);
}


original_code:
void array__insert_before(struct JS_array *a, int index, void *p)
{
  int i;
  if ((index >= 0)&&(index < a->size)) {
    if (a->size >= a->buffer_size)
      array__expand(a);
    for (i=a->size; i>index; i--)
      a->buffer[(a->head+i)%a->buffer_size]
        = a->buffer[(a->head+i-1)%a->buffer_size];
    a->buffer[(a->head+index)%a->buffer_size] = p;
    a->size++;
  }
}


original_code:
void array__insert_after(struct JS_array *a, int index, void *p)
{
  int i;
  if ((index >= 0)&&(index < a->size)) {
    if (a->size >= a->buffer_size)
      array__expand(a);
    for (i=a->size; i>(index+1); i--)
      a->buffer[(a->head+i)%a->buffer_size]
        = a->buffer[(a->head+i-1)%a->buffer_size];
    a->buffer[(a->head+index+1)%a->buffer_size] = p;
    a->size++;
  }
}


original_code:
void array__remove(struct JS_array *a, int index)
{
  int i;
  if ((index >= 0)&&(index < a->size)) {
    for (i=index; i<(a->size-1); i++)
      a->buffer[(a->head+i)%a->buffer_size]
        = a->buffer[(a->head+i+1)%a->buffer_size];
    a->size--;
  }
}


original_code:
void array__simple_remove(struct JS_array *a, int index)
{
  if ((index >= 0)&&(index < a->size)) {
    a->buffer[(a->head+index)%a->buffer_size]
      = a->buffer[(a->head+a->size-1)%a->buffer_size];
    a->size--;
  }
}


original_code:
void array__merge_(int lo, int m, int hi)
{
 int i, j, k;
    i=0; j=lo;
    while (j<=m)
        aux_[i++]=buffer_[j++];
    i=0; k=lo;
    while (k<j && j<=hi)
        if (compare_(aux_[i],buffer_[j]) <= 0)
            buffer_[k++]=aux_[i++];
        else
            buffer_[k++]=buffer_[j++];
    while (k<j)
        buffer_[k++]=aux_[i++];
}

canonical_original_code:
void array__merge_(int lo, int m, int hi)
{
 int i; int j; int k;
    i=0; j=lo;
    while (j<=m)
        aux_[i++]=buffer_[j++];
    i=0; k=lo;
    while (k<j && j<=hi)
        if (compare_(aux_[i],buffer_[j]) <= 0)
            buffer_[k++]=aux_[i++];
        else
            buffer_[k++]=buffer_[j++];
    while (k<j)
        buffer_[k++]=aux_[i++];
}

variable_types: lo int

variable_types: m int

variable_types: hi int

variable_types: j int

variable_types: k int


decompiled_code:
void __fastcall array__mergesort_(__int64 a1, int a2)
{
unsigned int v2; // er12

if ( (int)a1 < a2 )
{
v2 = ((int)a1 + a2) / 2;
array__mergesort_(a1, v2);
array__mergesort_(v2 + 1, (unsigned int)a2);
array__merge_(a1, v2, a2);
}
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, int a2)
{
unsigned int v2; // er12

if ( (int)a1 < a2 )
{
v2 = ((int)a1 + a2) / 2;
func15(a1, v2);
func15(v2 + 1, (unsigned int)a2);
func14(a1, v2, a2);
}
}

original_code:
void array__mergesort_(int lo, int hi)
{
 int m;
    if (lo<hi)
    {
        m=(lo+hi)/2;
        array__mergesort_(lo, m);
        array__mergesort_(m+1, hi);
        array__merge_(lo, m, hi);
    }
}


decompiled_code:
void __fastcall array__mergesort(int *a1, __int64 (__fastcall *a2)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD))
{
int v3; // er14
int v4; // ebx
int v5; // ebp
_QWORD *v6; // r12
int v7; // ecx
int v8; // ebp
__int64 v9; // rsi

v3 = a1[1];
v4 = a1[2];
v5 = *a1;
v6 = (_QWORD *)*((_QWORD *)a1 + 3);
buffer_ = (__int64)malloc(8LL * v3);
if ( v3 > 0 )
{
v7 = v5;
v8 = v3 + v5;
v9 = 0LL;
do
{
*(_QWORD *)(buffer_ + v9) = v6[v7 % v4];
++v7;
v9 += 8LL;
}
while ( v7 != v8 );
}
*a1 = 0;
*((_QWORD *)a1 + 3) = buffer_;
free(v6);
aux_ = malloc(8LL * a1[1]);
compare_ = a2;
array__mergesort_(0LL, v3 - 1);
free(aux_);
}

canonical_decompiled_code:
void __fastcall func16(int *a1, __int64 (__fastcall *a2)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD))
{
int v3; // er14
int v4; // ebx
int v5; // ebp
_QWORD *v6; // r12
int v7; // ecx
int v8; // ebp
__int64 v9; // rsi

v3 = a1[1];
v4 = a1[2];
v5 = *a1;
v6 = (_QWORD *)*((_QWORD *)a1 + 3);
buffer_ = (__int64)malloc(8LL * v3);
if ( v3 > 0 )
{
v7 = v5;
v8 = v3 + v5;
v9 = 0LL;
do
{
*(_QWORD *)(buffer_ + v9) = v6[v7 % v4];
++v7;
v9 += 8LL;
}
while ( v7 != v8 );
}
*a1 = 0;
*((_QWORD *)a1 + 3) = buffer_;
free(v6);
aux_ = malloc(8LL * a1[1]);
compare_ = a2;
func15(0LL, v3 - 1);
free(aux_);
}

original_code:
void array__mergesort(struct JS_array *a, int (*compare) (void *, void *))
{
 int i;
 int size = a->size, buffer_size = a->buffer_size, head = a->head;
 void **buffer = a->buffer;
 buffer_ = (void **) malloc(sizeof(void*)*a->size);
    for (i=0; i<size; i++)
  buffer_[i] = buffer[(head+i)%buffer_size];
    a->head = 0;
    a->buffer = buffer_;
    free(buffer);
 aux_ = (void **) malloc(sizeof(void*)*a->size);
 compare_ = compare;
 array__mergesort_(0, size - 1);
 free(aux_);
}

canonical_original_code:
void array__mergesort(struct JS_array *a, int (*compare)(void *, void *))
{
 int i;
 int size = a->size; int buffer_size = a->buffer_size; int head = a->head;
 void **buffer = a->buffer;
 buffer_ = (void **) malloc(sizeof(void *)*a->size);
    for (i=0; i<size; i++)
  buffer_[i] = buffer[(head+i)%buffer_size];
    a->head = 0;
    a->buffer = buffer_;
    free(buffer);
 aux_ = (void **) malloc(sizeof(void *)*a->size);
 compare_ = compare;
 array__mergesort_(0, size - 1);
 free(aux_);
}

variable_types:
compare
int (*)(void *, void *)

variable_types: size int

variable_types: head int

variable_types:
buffer
void **


decompiled_code:
__int64 __fastcall array__forall(__int64 a1, __int64 (__fastcall *a2)(_QWORD))
{
int v2; // ebp
__int64 result; // rax

if ( *(int *)(a1 + 4) > 0 )
{
v2 = 0;
do
result = a2(*(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL * ((*(_DWORD *)a1 + v2++) % *(_DWORD *)(a1 + 8))));
while ( *(_DWORD *)(a1 + 4) > v2 );
}
return result;
}

original_code:
void array__forall(struct JS_array *a, void (*func) (void *))
{
  int i;
  for (i=0; i<a->size; i++)
    func(a->buffer[(a->head+i)%a->buffer_size]);
}

canonical_original_code:
void array__forall(struct JS_array *a, void (*func)(void *))
{
  int i;
  for (i=0; i<a->size; i++)
    func(a->buffer[(a->head+i)%a->buffer_size]);
}

variable_types:
func
void (*)(void *)


decompiled_code:
int __fastcall view_bytes(char *a1, __int64 a2)
{
char *v2; // rbx

v2 = a1;
printf("%d bytes beginning at %d:", a2, (unsigned int)a1);
if ( (int)a2 > 0 )
{
do
printf(" %d", (unsigned int)*v2++);
while ( v2 != &a1[(unsigned int)a2] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(char *a1, __int64 a2)
{
char *v2; // rbx

v2 = a1;
printf("%d bytes beginning at %d:", a2, (unsigned int)a1);
if ( (int)a2 > 0 )
{
do
printf(" %d", (unsigned int)*v2++);
while ( v2 != &a1[(unsigned int)a2] );
}
return putchar(10);
}

original_code:
void view_bytes(void *start_address, int n)
{
  int i;
  char *s = (char *) start_address;
  printf("%d bytes beginning at %d:", n, (int) start_address);
  for (i=0; i<n; i++) {
    printf(" %d", (int) *s);
    s++;
  }
  printf("\n");
}

variable_types: n int

variable_types: i int

variable_types:
s
char *


decompiled_code:
void __fastcall jstring_destructor(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void jstring_destructor(struct jstring *j)
{
  free(j->s);
  free(j);
}

variable_types: struct jstring { char *s; int length; } *


decompiled_code:
int __fastcall jstring_view(__int64 a1)
{
printf("jstring of length %d: ", *(unsigned int *)(a1 + 8));
return view_bytes(*(char **)a1, *(unsigned int *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
printf("jstring of length %d: ", *(unsigned int *)(a1 + 8));
return func0(*(char **)a1, *(unsigned int *)(a1 + 8));
}

original_code:
void jstring_view(struct jstring *j)
{
 printf("jstring of length %d: ", j->length);
 view_bytes(j->s, j->length);
}


decompiled_code:
void __fastcall expression_destructor(void *ptr)
{
jstring_destructor(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
func1(*(void **)ptr);
free(ptr);
}

original_code:
void expression_destructor(struct expression *e)
{
  jstring_destructor(e->jval);
  free(e);
}

variable_types: struct expression { struct jstring { char *s; int length; } *jval; int topvar; } *

user_defined_types: struct expression { struct jstring *jval; int topvar; }


decompiled_code:
__int64 __fastcall evaluate_term(__int64 a1)
{
_DWORD *v1; // rbx
__int64 v2; // rbp

v1 = parenthesize(*(_QWORD *)a1);
v2 = SParse_interpret_expression(*(_QWORD *)v1, (unsigned int)v1[2], (unsigned int)(*(_DWORD *)(a1 + 8) + 1));
jstring_destructor(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
_DWORD *v1; // rbx
__int64 v2; // rbp

v1 = parenthesize(*(_QWORD *)a1);
v2 = SParse_interpret_expression(*(_QWORD *)v1, (unsigned int)v1[2], (unsigned int)(*(_DWORD *)(a1 + 8) + 1));
func1(v1);
return v2;
}

original_code:
void *evaluate_term(struct expression *e)
{
  void *p;
  struct jstring *j = parenthesize(e->jval);
  p = SParse_interpret_expression(
    j->s, j->length, e->topvar+1);
  jstring_destructor(j);
  return p;
}


output

decompiled_code:
int __fastcall output(__int64 a1)
{
printf("\n\t>> ");
SParse_print(a1);
return puts(" <<\n");
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
printf("\n\t>> ");
SParse_print(a1);
return puts(" <<\n");
}

original_code:
void output(void *p)
{
    printf("\n\t>> ");
    SParse_print(p);
    printf(" <<\n\n");
}


original_code:
int find_next_prime(int i)
{
  int j;
  if (i<3)
    i=3;
  else if (!(i%2))
    i++;
  while (1) {
    for (j=3; j<i; j+=2)
      if (!(i%j))
        j=i+1;
    if (j>i)
      i+=2;
    else
      return i;
  }
}


decompiled_code:
void __fastcall hash_table__delete(void *ptr)
{
free(*((void **)ptr + 4));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
free(*((void **)ptr + 4));
free(ptr);
}

original_code:
void hash_table__delete(struct JS_hash_table *h)
{
  free(h->buffer);
  free(h);
}

variable_types: struct JS_hash_table { int size; double expansion; void **buffer; int (*hashing_function)(void *key); int (*compare_to)(void *key1, void *key2); } *


original_code:
void *hash_table__lookup(struct JS_hash_table *h, void *key)
{
  int int_key, actual_size;
  void **p;
  if (key == ((void *)0))
    return ((void *)0);
  int_key = h->hashing_function(key);
  if (int_key < 0)
    int_key *= -1;
  p = h->buffer + (2*(int_key%h->buffer_size));
  actual_size = 2*h->buffer_size;
  while (1) {
    if ((*p == ((void *)0))||(!h->compare_to(*p, key)))
      break;
    p = h->buffer + ((p + 2 - h->buffer)%actual_size);
  }
  p++;
  return *p;
}

canonical_original_code:
void *hash_table__lookup(struct JS_hash_table *h, void *key)
{
  int int_key; int actual_size;
  void **p;
  if (key == ((void *)0))
    return ((void *)0);
  int_key = h->hashing_function(key);
  if (int_key < 0)
    int_key *= -1;
  p = h->buffer + (2*(int_key%h->buffer_size));
  actual_size = 2*h->buffer_size;
  while (1) {
    if ((*p == ((void *)0))||(!h->compare_to(*p, key)))
      break;
    p = h->buffer + ((p + 2 - h->buffer)%actual_size);
  }
  p++;
  return *p;
}

variable_types:
key
void *

variable_types:
p
void **

user_defined_types: struct JS_hash_table { int size; double expansion; void **buffer; int (*hashing_function)(void *key); int (*compare_to)(void *key1, void *key2); }


repo: joshthecoder/libhttp

decompiled_code:
void __fastcall http_session_close(void *ptr)
{
close(*(_DWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
close(*(_DWORD *)ptr);
free(ptr);
}

original_code:
void http_session_close(http_session* session) {
  close(session->sockfd);
  free(session);
}

canonical_original_code:
void http_session_close(struct http_session_s *session) {
  close(session->sockfd);
  free(session);
}

variable_types:
session
struct http_session_s { int sockfd; } *


main

canonical_name: main

repo: joshuaday/rook

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-28h] BYREF

Rng(&v4, 0LL, envp);
if ( (unsigned int)Term() )
Game();
return 0;
}

original_code:
int main (int argc, char *argv[]) {
 rng state = Rng.seed(0);
 if (Term.init()) {
  Game.loop();
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 struct rng state = Rng.seed(0);
 if (Term.init()) {
  Game.loop();
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct rng { unsigned int seed; unsigned int a; }


getkey

decompiled_code:
int getkey()
{
int v0; // eax
int result; // eax
WINDOW *v2; // rax

while ( 1 )
{
result = wgetch(stdscr);
if ( result != 410 )
break;
v2 = stdscr;
if ( stdscr )
{
*((_DWORD *)&Term + 13) = stdscr->_maxy + 1;
v0 = v2->_maxx + 1;
}
else
{
*((_DWORD *)&Term + 13) = -1;
v0 = -1;
}
*((_DWORD *)&Term + 12) = v0;
}
return result;
}

canonical_decompiled_code:
int func0()
{
int v0; // eax
int result; // eax
WINDOW *v2; // rax

while ( 1 )
{
result = wgetch(stdscr);
if ( result != 410 )
break;
v2 = stdscr;
if ( stdscr )
{
*((_DWORD *)&Term + 13) = stdscr->_maxy + 1;
v0 = v2->_maxx + 1;
}
else
{
*((_DWORD *)&Term + 13) = -1;
v0 = -1;
}
*((_DWORD *)&Term + 12) = v0;
}
return result;
}

original_code:
static int getkey( ) {
 while (1) {
  int got = wgetch(stdscr);
  if (got == 0632) {
   (Term.height = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), Term.width = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
  } else {
   return got;
  }
 }
}

canonical_original_code:
static int getkey() {
 while (1) {
  int got = wgetch(stdscr);
  if (got == 0632) {
   (Term.height = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), Term.width = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
  } else {
   return got;
  }
 }
}

variable_types: got int


decompiled_code:
int term_clear()
{
return wclear(stdscr);
}

canonical_decompiled_code:
int func1()
{
return wclear(stdscr);
}

original_code:
static void term_clear( ) {
 wclear(stdscr);
}

canonical_original_code:
static void term_clear() {
 wclear(stdscr);
}


plot

decompiled_code:
int __fastcall plot(int a1, int a2, int a3, unsigned int a4)
{
int result; // eax

wattrset(stdscr, (a3 << 18) & 0x200000 | (((a3 & 7) + ((a3 >> 1) & 0x38) + 1) << 8));
result = wmove(stdscr, a2, a1);
if ( result != -1 )
result = waddch(stdscr, a4);
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, int a2, int a3, unsigned int a4)
{
int result; // eax

wattrset(stdscr, (a3 << 18) & 0x200000 | (((a3 & 7) + ((a3 >> 1) & 0x38) + 1) << 8));
result = wmove(stdscr, a2, a1);
if ( result != -1 )
result = waddch(stdscr, a4);
return result;
}

variable_types: x int

variable_types: y int

variable_types: color int

variable_types: ch int


print

decompiled_code:
int __fastcall print(int a1, int a2, int a3, char *a4)
{
char *v4; // rax
char v5; // cl
char *v7; // rbx
int v8; // ebp

v4 = a4;
v5 = *a4;
if ( v5 )
{
v7 = v4;
v8 = a1 - (_DWORD)v4;
do
{
LODWORD(v4) = plot(v8 + (_DWORD)v7++, a2, a3, v5);
v5 = *v7;
}
while ( *v7 );
}
return (int)v4;
}

canonical_decompiled_code:
int __fastcall func3(int a1, int a2, int a3, char *a4)
{
char *v4; // rax
char v5; // cl
char *v7; // rbx
int v8; // ebp

v4 = a4;
v5 = *a4;
if ( v5 )
{
v7 = v4;
v8 = a1 - (_DWORD)v4;
do
{
LODWORD(v4) = func2(v8 + (_DWORD)v7++, a2, a3, v5);
v5 = *v7;
}
while ( *v7 );
}
return (int)v4;
}

original_code:
static void print(int x, int y, int color, const char *ch) {
 while (*ch) {
  plot(x, y, color, *ch);
  x++;
  ch++;
 }
}

canonical_original_code:
static void print(int x, int y, int color, char *ch) {
 while (*ch) {
  plot(x, y, color, *ch);
  x++;
  ch++;
 }
}

variable_types:
ch
char *


cleanup

decompiled_code:
void cleanup(void)
{
if ( videomode )
{
wclear(stdscr);
wrefresh(stdscr);
endwin();
}
}

canonical_decompiled_code:
void func4(void)
{
if ( videomode )
{
wclear(stdscr);
wrefresh(stdscr);
endwin();
}
}

original_code:
static void cleanup( ) {
 if (videomode.curses) {
  wclear(stdscr);
  wrefresh(stdscr);
  endwin();
 }
}

canonical_original_code:
static void cleanup() {
 if (videomode.curses) {
  wclear(stdscr);
  wrefresh(stdscr);
  endwin();
 }
}


preparecolor

decompiled_code:
int preparecolor()
{
__int16 *v0; // rbp
int i; // er13
__int64 j; // rbx
int result; // eax

v0 = pairParts_0;
for ( i = 0; i != 128; i += 16 )
{
for ( j = 0LL; j != 8; ++j )
result = init_pair((j & 7 | ((int)(j | i & 0x70) >> 1) & 0x38) + 1, pairParts_0[2 * j], *v0);
v0 += 2;
}
return result;
}

canonical_decompiled_code:
int func5()
{
__int16 *v0; // rbp
int i; // er13
__int64 j; // rbx
int result; // eax

v0 = pairParts_0;
for ( i = 0; i != 128; i += 16 )
{
for ( j = 0LL; j != 8; ++j )
result = init_pair((j & 7 | ((int)(j | i & 0x70) >> 1) & 0x38) + 1, pairParts_0[2 * j], *v0);
v0 += 2;
}
return result;
}

variable_types:
pairParts
int [8]

variable_types: fg int

variable_types: bg int


decompiled_code:
__int64 curses_init()
{
__int64 result; // rax
WINDOW *v1; // rax
int v2; // eax

result = 0LL;
if ( !videomode )
{
initscr();
if ( has_colors() )
{
start_color();
wclear(stdscr);
curs_set(0);
wrefresh(stdscr);
leaveok(stdscr, 1);
preparecolor();
cbreak();
noecho();
meta(stdscr, 1);
keypad(stdscr, 1);
mousemask(0x10000003uLL, 0LL);
mouseinterval(0);
videomode = 1;
v1 = stdscr;
if ( stdscr )
{
*((_DWORD *)&Term + 13) = stdscr->_maxy + 1;
v2 = v1->_maxx + 1;
}
else
{
*((_DWORD *)&Term + 13) = -1;
v2 = -1;
}
*((_DWORD *)&Term + 12) = v2;
atexit(cleanup);
result = 1LL;
}
else
{
endwin();
fwrite("Your terminal has no color support.\n", 1uLL, 0x24uLL, stderr);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
WINDOW *v1; // rax
int v2; // eax

result = 0LL;
if ( !videomode )
{
initscr();
if ( has_colors() )
{
start_color();
wclear(stdscr);
curs_set(0);
wrefresh(stdscr);
leaveok(stdscr, 1);
func5();
cbreak();
noecho();
meta(stdscr, 1);
keypad(stdscr, 1);
mousemask(0x10000003uLL, 0LL);
mouseinterval(0);
videomode = 1;
v1 = stdscr;
if ( stdscr )
{
*((_DWORD *)&Term + 13) = stdscr->_maxy + 1;
v2 = v1->_maxx + 1;
}
else
{
*((_DWORD *)&Term + 13) = -1;
v2 = -1;
}
*((_DWORD *)&Term + 12) = v2;
atexit(cleanup);
result = 1LL;
}
else
{
endwin();
fwrite("Your terminal has no color support.\n", 1uLL, 0x24uLL, stderr);
result = 1LL;
}
}
return result;
}

original_code:
static int curses_init( ) {
 if (videomode.curses) return 0;
 initscr( );
 if (!has_colors( )) {
  endwin( );
  fprintf (stderr, "Your terminal has no color support.\n");
  return 1;
 }
 start_color( );
 wclear(stdscr);
 curs_set( 0 );
 wrefresh(stdscr);
 leaveok(stdscr, 1);
 preparecolor( );
 cbreak( );
 noecho( );
 meta(stdscr, 1);
 keypad(stdscr, 1);
 mousemask(((002L) << (((1) - 1) * 5)) | ((001L) << (((1) - 1) * 5)) | ((0010L) << (((6) - 1) * 5)), ((void *)0));
 mouseinterval(0);
 videomode.curses = 1;
 (Term.height = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), Term.width = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 atexit(cleanup);
 return 1;
}

canonical_original_code:
static int curses_init() {
 if (videomode.curses) return 0;
 initscr( );
 if (!has_colors( )) {
  endwin( );
  fprintf (stderr, "Your terminal has no color support.\n");
  return 1;
 }
 start_color( );
 wclear(stdscr);
 curs_set( 0 );
 wrefresh(stdscr);
 leaveok(stdscr, 1);
 preparecolor( );
 cbreak( );
 noecho( );
 meta(stdscr, 1);
 keypad(stdscr, 1);
 mousemask(((002L) << (((1) - 1) * 5)) | ((001L) << (((1) - 1) * 5)) | ((0010L) << (((6) - 1) * 5)), ((void *)0));
 mouseinterval(0);
 videomode.curses = 1;
 (Term.height = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), Term.width = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 atexit(cleanup);
 return 1;
}


read

decompiled_code:
void *read()
{
*(_BYTE *)writer = 0;
return &buffer;
}

canonical_decompiled_code:
void *func0()
{
*(_BYTE *)writer = 0;
return &buffer;
}

original_code:
static char *read( ) {
 if ((1)) {
  *writer = '\0';
  return buffer;
 } else {
  return "Error in string builder.";
 }
}

canonical_original_code:
static char *read() {
 if ((1)) {
  *writer = '\0';
  return buffer;
 } else {
  return "Error in string builder.";
 }
}

return_type: char *


publish

decompiled_code:
void __fastcall publish(__int64 a1)
{
void (__fastcall *v1)(__int64, void *); // rbp
void *v2; // rax

if ( enabled )
{
v1 = (void (__fastcall *)(__int64, void *))Chronicle[1];
v2 = read();
v1(a1, v2);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
void (__fastcall *v1)(__int64, void *); // rbp
void *v2; // rax

if ( enabled )
{
v1 = (void (__fastcall *)(__int64, void *))Chronicle[1];
v2 = func0();
v1(a1, v2);
}
}

original_code:
static void publish(chronicle *chron) {
 if (enabled) {
  Chronicle.post(chron, read( ));
 }
}

canonical_original_code:
static void publish(struct chronicle *chron) {
 if (enabled) {
  Chronicle.post(chron, read( ));
 }
}

variable_types: struct chronicle { struct message { int turn_number; char *text; int length; struct message *prev; int fork_count; } *last; int turn_number; } *

user_defined_types: struct chronicle { struct message *last; int turn_number; }


enable

decompiled_code:
void __fastcall enable(int a1)
{
enabled = a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
enabled = a1;
}

original_code:
static void enable (int on) {
 enabled = on;
}

canonical_original_code:
static void enable(int on) {
 enabled = on;
}

variable_types: on int


original_code:
void layer_fill(layer *layer, int value) {
 int i, length = layer->width * layer->height;
 for (i = 0; i < length; i++) {
  layer->buffer[i] = value;
 }
}

canonical_original_code:
void layer_fill(struct layer *layer, int value) {
 int i; int length = layer->width * layer->height;
 for (i = 0; i < length; i++) {
  layer->buffer[i] = value;
 }
}

variable_types: struct layer { int width; int x1; int oob; int buffer[]; } *

variable_types: value int

variable_types: i int

variable_types: length int


decompiled_code:
__int64 __fastcall layer_set(_DWORD *a1, int a2, int a3, int a4)
{
__int64 result; // rax
int v5; // er8

result = (unsigned int)a1[2];
if ( (int)result <= a2 )
{
v5 = a1[3];
if ( v5 <= a3 && a1[4] >= a2 && a1[5] >= a3 )
{
result = *a1 * (a3 - v5) + a2 - (int)result;
a1[result + 7] = a4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, int a2, int a3, int a4)
{
__int64 result; // rax
int v5; // er8

result = (unsigned int)a1[2];
if ( (int)result <= a2 )
{
v5 = a1[3];
if ( v5 <= a3 && a1[4] >= a2 && a1[5] >= a3 )
{
result = *a1 * (a3 - v5) + a2 - (int)result;
a1[result + 7] = a4;
}
}
return result;
}

original_code:
void layer_set(layer *layer, int x, int y, int value) {
 if (x < layer->x1 || y < layer->y1 || x > layer->x2 || y > layer->y2) {
  return;
 } else {
  int index = (x - layer->x1) + (y - layer->y1) * layer->width;
  layer->buffer[index] = value;
 }
}

canonical_original_code:
void layer_set(struct layer *layer, int x, int y, int value) {
 if (x < layer->x1 || y < layer->y1 || x > layer->x2 || y > layer->y2) {
  return;
 } else {
  int index = (x - layer->x1) + (y - layer->y1) * layer->width;
  layer->buffer[index] = value;
 }
}

variable_types: index int

user_defined_types: struct layer { int width; int x1; int oob; int buffer[]; }


decompiled_code:
__int64 __fastcall layer_get(_DWORD *a1, int a2, int a3)
{
int v3; // eax
int v4; // ecx
__int64 result; // rax

v3 = a1[2];
if ( v3 <= a2 && (v4 = a1[3], v4 <= a3) && a1[4] >= a2 && a1[5] >= a3 )
result = (unsigned int)a1[*a1 * (a3 - v4) + 7 + a2 - v3];
else
result = (unsigned int)a1[6];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, int a2, int a3)
{
int v3; // eax
int v4; // ecx
__int64 result; // rax

v3 = a1[2];
if ( v3 <= a2 && (v4 = a1[3], v4 <= a3) && a1[4] >= a2 && a1[5] >= a3 )
result = (unsigned int)a1[*a1 * (a3 - v4) + 7 + a2 - v3];
else
result = (unsigned int)a1[6];
return result;
}

original_code:
int layer_get(layer *layer, int x, int y) {
 if (x < layer->x1 || y < layer->y1 || x > layer->x2 || y > layer->y2) {
  return layer->oob;
 } else {
  int index = (x - layer->x1) + (y - layer->y1) * layer->width;
  return layer->buffer[index];
 }
}

canonical_original_code:
int layer_get(struct layer *layer, int x, int y) {
 if (x < layer->x1 || y < layer->y1 || x > layer->x2 || y > layer->y2) {
  return layer->oob;
 } else {
  int index = (x - layer->x1) + (y - layer->y1) * layer->width;
  return layer->buffer[index];
 }
}


original_code:
void chronicle_post (chronicle *chron, const char *text) {
 if (chron == ((void *)0) || text == ((void *)0)) return;
 message *msg = malloc(sizeof(message));
 int length = strlen(text);
 msg->length = length;
 msg->text = malloc(length + 1);
 msg->turn_number = chron->turn_number;
 msg->fork_count = 0;
 msg->prev = chron->last;
 chron->last = msg;
 chron->count++;
 memcpy(msg->text, text, length + 1);
}

canonical_original_code:
void chronicle_post(struct chronicle *chron, char *text) {
 if (chron == ((void *)0) || text == ((void *)0)) return;
 struct message *msg = malloc(sizeof(message));
 int length = strlen(text);
 msg->length = length;
 msg->text = malloc(length + 1);
 msg->turn_number = chron->turn_number;
 msg->fork_count = 0;
 msg->prev = chron->last;
 chron->last = msg;
 chron->count++;
 memcpy(msg->text, text, length + 1);
}

variable_types:
text
char *

variable_types: struct message { int turn_number; char *text; int length; struct message *prev; int fork_count; } *


original_code:
void chronicle_free (chronicle *chron) {
 message *msg = chron->last;
 free(chron);
 while (msg != ((void *)0) && !msg->fork_count) {
  message *prev = msg->prev;
  free(msg);
  msg = prev;
 }
 if (msg != ((void *)0)) {
  msg->fork_count--;
 }
}

canonical_original_code:
void chronicle_free(struct chronicle *chron) {
 struct message *msg = chron->last;
 free(chron);
 while (msg != ((void *)0) && !msg->fork_count) {
  struct message *prev = msg->prev;
  free(msg);
  msg = prev;
 }
 if (msg != ((void *)0)) {
  msg->fork_count--;
 }
}

user_defined_types: struct message { int turn_number; char *text; int length; struct message *prev; int fork_count; }


original_code:
static enum effects check_apply_effect(worldstate *state, agent *item, int itemnumber) {
 int magictype = item->def->asitem.magic[0];
 if (magictype == 'w') {
  char hacktype = item->def->asitem.magic[1];
  if (hacktype == '-') return outcome_like_waiting;
  if (hacktype == 'q') return outcome_like_waiting;
  else return outcome_needs_forking;
 } else {
  return outcome_needs_forking;
 }
}

canonical_original_code:
static enum effects check_apply_effect(struct worldstate *state, struct agent *item, int itemnumber) {
 int magictype = item->def->asitem.magic[0];
 if (magictype == 'w') {
  char hacktype = item->def->asitem.magic[1];
  if (hacktype == '-') return outcome_like_waiting;
  if (hacktype == 'q') return outcome_like_waiting;
  else return outcome_needs_forking;
 } else {
  return outcome_needs_forking;
 }
}

variable_types: struct worldstate { int locked; int donotfree; int isvalid; int turk_active; int totaltime; struct rng { unsigned int seed; unsigned int a; } randomness; struct agentlist { struct agent { struct mondef { struct forms_t { char *tag; char *name; char *desc; } forms; struct asabout_t { int glyph; } about; struct ascell_t { int flags; char *promotion; } ascell; struct asmob_t { int hp; char *stab; char *stumble; char *speed; } asmob; struct asitem_t { char *magic; char *stab; } asitem; } *def; int x; int hp; int time; } *buffer; int max; } agents; struct agent *player; struct layout { int left; int shiftx; int lastItem; } *layout; struct gameboard { int width; struct mondef **cells; int fork_count; } *board; struct chronicle { struct message { int turn_number; char *text; int length; struct message *prev; int fork_count; } *last; int turn_number; } *chron; struct layer { int width; int x1; int oob; int buffer[]; } *player_fov; struct agent inventory[-1]; } *

variable_types:
item
struct agent *

variable_types: itemnumber int

variable_types: magictype int

variable_types: hacktype char

return_type: enum effects { outcome_invalid=0, outcome_like_waiting=1, outcome_needs_forking=2 }

user_defined_types: struct worldstate { int locked; int donotfree; int isvalid; int turk_active; int totaltime; struct rng randomness; struct agentlist agents; struct agent *player; struct layout *layout; struct gameboard *board; struct chronicle *chron; struct layer *player_fov; struct agent inventory[-1]; }

user_defined_types: struct agentlist { struct agent *buffer; int max; }

user_defined_types: struct agent { struct mondef *def; int x; int hp; int time; }

user_defined_types: struct mondef { struct forms_t forms; struct asabout_t about; struct ascell_t ascell; struct asmob_t asmob; struct asitem_t asitem; }


original_code:
static enum effects do_fire_effect(worldstate *state, agent *item, int dx, int dy) {
 agent *player = state->player;
 int stafftype = item->def->asitem.magic[2];
 if (stafftype == 'b') {
  int x = -1, y = -1;
  trace_shot(state, player, dx, dy, 8, ' ', &x, &y, ((void *)0));
  if (x == -1) return outcome_invalid;
  else {
   Chronicle.post(state->chron, "You blink!");
   player->x = x;
   player->y = y;
  }
 }
 if (stafftype == 'd') {
  agent *mob = ((void *)0);
  int x = -1, y = -1;
  trace_shot(state, player, dx, dy, 8, '@', &x, &y, &mob);
  if (x == -1) return outcome_invalid;
  else {
   mob->hp = 0;
   Chronicle.post(state->chron, "Bam!  Dead.");
   return outcome_needs_forking;
  }
 }
 return outcome_like_waiting;
}

canonical_original_code:
static enum effects do_fire_effect(struct worldstate *state, struct agent *item, int dx, int dy) {
 struct agent *player = state->player;
 int stafftype = item->def->asitem.magic[2];
 if (stafftype == 'b') {
  int x = -1; int y = -1;
  trace_shot(state, player, dx, dy, 8, ' ', &x, &y, ((void *)0));
  if (x == -1) return outcome_invalid;
  else {
   Chronicle.post(state->chron, "You blink!");
   player->x = x;
   player->y = y;
  }
 }
 if (stafftype == 'd') {
  struct agent *mob = ((void *)0);
  int x = -1; int y = -1;
  trace_shot(state, player, dx, dy, 8, '@', &x, &y, &mob);
  if (x == -1) return outcome_invalid;
  else {
   mob->hp = 0;
   Chronicle.post(state->chron, "Bam!  Dead.");
   return outcome_needs_forking;
  }
 }
 return outcome_like_waiting;
}

variable_types: dx int

variable_types: dy int

variable_types: struct agent { struct mondef { struct forms_t { char *tag; char *name; char *desc; } forms; struct asabout_t { int glyph; } about; struct ascell_t { int flags; char *promotion; } ascell; struct asmob_t { int hp; char *stab; char *stumble; char *speed; } asmob; struct asitem_t { char *magic; char *stab; } asitem; } *def; int x; int hp; int time; } *

variable_types: stafftype int

variable_types: x int

variable_types: y int

user_defined_types: enum effects { outcome_invalid=0, outcome_like_waiting=1, outcome_needs_forking=2 }

user_defined_types: struct rng { unsigned int seed; unsigned int a; }

user_defined_types: struct layout { int left; int shiftx; int lastItem; }

user_defined_types: struct gameboard { int width; struct mondef **cells; int fork_count; }


original_code:
static enum effects check_fire_effect(worldstate *state, agent *item, int dx, int dy) {
 agent *player = state->player;
 int stafftype = item->def->asitem.magic[2];
 if (stafftype == 'b') {
  int x = -1, y = -1;
  trace_shot(state, player, dx, dy, 8, ' ', &x, &y, ((void *)0));
  if (x == -1) return outcome_invalid;
  else return outcome_needs_forking;
 }
 if (stafftype == 'd') {
  agent *mob = ((void *)0);
  int x = -1, y = -1;
  trace_shot(state, player, dx, dy, 8, '@', &x, &y, &mob);
  if (x == -1) return outcome_invalid;
  else return outcome_needs_forking;
 }
 return outcome_like_waiting;
}

canonical_original_code:
static enum effects check_fire_effect(struct worldstate *state, struct agent *item, int dx, int dy) {
 struct agent *player = state->player;
 int stafftype = item->def->asitem.magic[2];
 if (stafftype == 'b') {
  int x = -1; int y = -1;
  trace_shot(state, player, dx, dy, 8, ' ', &x, &y, ((void *)0));
  if (x == -1) return outcome_invalid;
  else return outcome_needs_forking;
 }
 if (stafftype == 'd') {
  struct agent *mob = ((void *)0);
  int x = -1; int y = -1;
  trace_shot(state, player, dx, dy, 8, '@', &x, &y, &mob);
  if (x == -1) return outcome_invalid;
  else return outcome_needs_forking;
 }
 return outcome_like_waiting;
}

user_defined_types: struct forms_t { char *tag; char *name; char *desc; }

user_defined_types: struct ascell_t { int flags; char *promotion; }

user_defined_types: struct asmob_t { int hp; char *stab; char *stumble; char *speed; }

user_defined_types: struct asitem_t { char *magic; char *stab; }


lookup

decompiled_code:
char **__fastcall lookup(int a1, const char *a2)
{
char **v2; // rbp
char **v3; // rbx

v2 = itemdefs;
if ( a1 != 1 )
{
v2 = &mondefs;
if ( a1 == 2 )
v2 = &celldefs;
}
v3 = v2 + 15;
while ( strcmp(*v2, a2) )
{
v2 = v3;
v3 += 15;
if ( !*((_DWORD *)v3 - 22) )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
char **__fastcall func0(int a1, const char *a2)
{
char **v2; // rbp
char **v3; // rbx

v2 = itemdefs;
if ( a1 != 1 )
{
v2 = &mondefs;
if ( a1 == 2 )
v2 = &celldefs;
}
v3 = v2 + 15;
while ( strcmp(*v2, a2) )
{
v2 = v3;
v3 += 15;
if ( !*((_DWORD *)v3 - 22) )
return 0LL;
}
return v2;
}

original_code:
static const mondef *lookup(int whichlist, const char *tag) {
 int i;
 const mondef *list = mondefs;
 if (whichlist == 1) list = itemdefs;
 if (whichlist == 2) list = celldefs;
 for (i = 0; list[i].about.glyph != '\0'; i++) {
  if (strcmp(list[i].forms.tag, tag) == 0) {
   return list + i;
  }
 }
 return 0;
}

canonical_original_code:
static struct mondef *lookup(int whichlist, char *tag) {
 int i;
 struct mondef *list = mondefs;
 if (whichlist == 1) list = itemdefs;
 if (whichlist == 2) list = celldefs;
 for (i = 0; list[i].about.glyph != '\0'; i++) {
  if (strcmp(list[i].forms.tag, tag) == 0) {
   return list + i;
  }
 }
 return 0;
}

variable_types: whichlist int

variable_types:
tag
char *

variable_types: struct mondef { struct forms_t { char *tag; char *name; char *desc; } forms; struct asabout_t { int glyph; } about; struct ascell_t { int flags; char *promotion; } ascell; struct asmob_t { int hp; char *stab; char *stumble; char *speed; } asmob; struct asitem_t { char *magic; char *stab; } asitem; } *


main

repo: josmardias/linkedlist

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rbx

v3 = Person_newlist(argc, argv, envp);
v4 = Person_new(10LL);
List_add(v3, v4);
v5 = Person_new(1LL);
List_add(v3, v5);
v6 = Person_new(9LL);
List_add(v3, v6);
v7 = Person_new(8LL);
List_add(v3, v7);
puts("All people:");
List_print(v3);
puts("Inverse:");
List_print_inverse(v3);
v8 = List_findOne(v3, 3LL);
printf("\nPerson with id %llu:\n", 3LL);
Person_print(v8);
return 0;
}

original_code:
int main() {
    List *l = Person_newlist();
    List_add(l, Person_new(10));
    List_add(l, Person_new(1));
    List_add(l, Person_new(9));
    List_add(l, Person_new(8));
    puts("All people:");
    List_print(l);
    puts("Inverse:");
    List_print_inverse(l);
    unsigned long long id = 3;
    Person * p = List_findOne(l, (void *)id);
    printf("\nPerson with id %llu:\n", id);
    Person_print(p);
    return 0;
}

canonical_original_code:
int main() {
    struct List *l = Person_newlist();
    List_add(l, Person_new(10));
    List_add(l, Person_new(1));
    List_add(l, Person_new(9));
    List_add(l, Person_new(8));
    puts("All people:");
    List_print(l);
    puts("Inverse:");
    List_print_inverse(l);
    unsigned long long id = 3;
    struct Person *p = List_findOne(l, (void *)id);
    printf("\nPerson with id %llu:\n", id);
    Person_print(p);
    return 0;
}

variable_types: struct List { int length; struct node { void *info; struct node *next; } *head; int (*cmp)(void *, void *); void (*print)(void *); _Bool (*query)(void *, void *); } *

variable_types:
id
unsigned long long

variable_types:
p
struct Person { int id; int age; } *

user_defined_types: struct List { int length; struct node *head; int (*cmp)(void *, void *); void (*print)(void *); _Bool (*query)(void *, void *); }


decompiled_code:
__int64 __fastcall Person_cmp(__int64 a1, __int64 a2)
{
int v2; // ecx
int v3; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 4);
v3 = *(_DWORD *)(a2 + 4);
result = 1LL;
if ( v2 <= v3 )
result = (unsigned int)-(v2 != v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
int v2; // ecx
int v3; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 4);
v3 = *(_DWORD *)(a2 + 4);
result = 1LL;
if ( v2 <= v3 )
result = (unsigned int)-(v2 != v3);
return result;
}

original_code:
int Person_cmp(Person *p1, Person *p2) {
    if (p1->age > p2->age) {
        return 1;
    }
    if (p1->age == p2->age) {
        return 0;
    }
    return -1;
}

canonical_original_code:
int Person_cmp(struct Person *p1, struct Person *p2) {
    if (p1->age > p2->age) {
        return 1;
    }
    if (p1->age == p2->age) {
        return 0;
    }
    return -1;
}


decompiled_code:
bool __fastcall Person_query(_DWORD *a1, int a2)
{
return *a1 == a2;
}

canonical_decompiled_code:
bool __fastcall func1(_DWORD *a1, int a2)
{
return *a1 == a2;
}

original_code:
_Bool Person_query(Person *p, int id) {
    return p->id == id;
}

canonical_original_code:
_Bool Person_query(struct Person *p, int id) {
    return p->id == id;
}

variable_types: id int


decompiled_code:
int __fastcall Person_print(unsigned int *a1)
{
if ( !a1 )
puts("nil\n");
return printf("id: %d, age: %d\n", *a1, a1[1]);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int *a1)
{
if ( !a1 )
puts("nil\n");
return printf("id: %d, age: %d\n", *a1, a1[1]);
}

original_code:
void Person_print(Person *p) {
    if(!p)
        puts("nil\n");
    printf("id: %d, age: %d\n", p->id, p->age);
}

canonical_original_code:
void Person_print(struct Person *p) {
    if(!p)
        puts("nil\n");
    printf("id: %d, age: %d\n", p->id, p->age);
}


decompiled_code:
__int64 Person_newlist()
{
return List_new(Person_cmp, Person_print, Person_query);
}

canonical_decompiled_code:
__int64 func3()
{
return List_new(Person_cmp, Person_print, Person_query);
}

original_code:
List * Person_newlist() {
    List *l = List_new(
        (int (*)(void *, void *))Person_cmp,
        (void (*)(void *))Person_print,
        (_Bool (*)(void *, void *))Person_query
        );
    return l;
}

canonical_original_code:
struct List *Person_newlist() {
    struct List *l = List_new(
        (int (*)(void *, void *))Person_cmp,
        (void (*)(void *))Person_print,
        (_Bool (*)(void *, void *))Person_query
        );
    return l;
}

return_type: struct List { int length; struct node { void *info; struct node *next; } *head; int (*cmp)(void *, void *); void (*print)(void *); _Bool (*query)(void *, void *); } *


die

repo: jossk/fmio-dos

decompiled_code:
void __fastcall __noreturn die(int a1)
{
radio_drv_free();
radio_cleanup();
exit(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1)
{
radio_drv_free();
radio_cleanup();
exit(a1);
}

original_code:
void
die(int sig) {
 radio_drv_free();
 radio_cleanup();
 exit(sig);
}

variable_types: sig int


usage

decompiled_code:
void __noreturn usage()
{
unsigned int v0; // ebx
__int64 v1; // rax
char v2[392]; // [rsp+0h] [rbp-188h] BYREF

strcpy(
v2,
"Usage: %s [-d driver] [-f frequency] [-i] [-m] [-s] [-v volume]\n"
"\t%s [-d driver] -S [-l begin] [-h end] [-c count]\n"
"\t%s [-d driver] -W frequency\n"
"\t%s -D - detect driver\n"
"\n"
"\t-f frequency in Mhz, -f 98.0 for example\n"
"\t-i information\n"
"\t-m mono\n"
"\t-s stat\n"
"\t-v volume, -v 0 set tuner off\n"
"\t-S scan -l start frequency, -h end frequency\n"
"\t-c number of probes for each scanned frequency\n"
"\t-W search\n");
printf("%s version %s\n", (const char *)pn, "2.0.8");
printf("Default driver: ");
v0 = radio_info_port();
v1 = radio_info_name();
radio_info_show(stdout, v1, v0);
printf(v2, pn, pn, pn, pn);
die(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
unsigned int v0; // ebx
__int64 v1; // rax
char v2[392]; // [rsp+0h] [rbp-188h] BYREF

strcpy(
v2,
"Usage: %s [-d driver] [-f frequency] [-i] [-m] [-s] [-v volume]\n"
"\t%s [-d driver] -S [-l begin] [-h end] [-c count]\n"
"\t%s [-d driver] -W frequency\n"
"\t%s -D - detect driver\n"
"\n"
"\t-f frequency in Mhz, -f 98.0 for example\n"
"\t-i information\n"
"\t-m mono\n"
"\t-s stat\n"
"\t-v volume, -v 0 set tuner off\n"
"\t-S scan -l start frequency, -h end frequency\n"
"\t-c number of probes for each scanned frequency\n"
"\t-W search\n");
printf("%s version %s\n", (const char *)pn, "2.0.8");
printf("Default driver: ");
v0 = radio_info_port();
v1 = radio_info_name();
radio_info_show(stdout, v1, v0);
printf(v2, pn, pn, pn, pn);
func0(0);
}

original_code:
void
usage(void) {
 const char usage_string[] =
  "Usage:  %s [-d driver] [-f frequency] [-i] [-m] [-s] [-v volume]\n"
  "\t%s [-d driver] -S [-l begin] [-h end] [-c count]\n"
  "\t%s [-d driver] -W frequency\n"
  "\t%s -D - detect driver\n\n"
  "\t-f frequency in Mhz, -f 98.0 for example\n"
  "\t-i information\n"
  "\t-m mono\n"
  "\t-s stat\n"
  "\t-v volume, -v 0 set tuner off\n"
  "\t-S scan -l start frequency, -h end frequency\n"
  "\t-c number of probes for each scanned frequency\n"
  "\t-W search\n"
 ;
 printf("%s version %s\n", pn, "2.0.8");
 printf("Default driver: ");
 radio_info_show(stdout, radio_info_name(), radio_info_port());
 printf(usage_string, pn, pn, pn, pn);
 die(0);
}

canonical_original_code:
void usage() {
 char usage_string[] = "Usage:  %s [-d driver] [-f frequency] [-i] [-m] [-s] [-v volume]\n"
  "\t%s [-d driver] -S [-l begin] [-h end] [-c count]\n"
  "\t%s [-d driver] -W frequency\n"
  "\t%s -D - detect driver\n\n"
  "\t-f frequency in Mhz, -f 98.0 for example\n"
  "\t-i information\n"
  "\t-m mono\n"
  "\t-s stat\n"
  "\t-v volume, -v 0 set tuner off\n"
  "\t-S scan -l start frequency, -h end frequency\n"
  "\t-c number of probes for each scanned frequency\n"
  "\t-W search\n";
 printf("%s version %s\n", pn, "2.0.8");
 printf("Default driver: ");
 radio_info_show(stdout, radio_info_name(), radio_info_port());
 printf(usage_string, pn, pn, pn, pn);
 die(0);
}


decompiled_code:
__int64 __fastcall invalid_driver_error(const char *a1)
{
warnx("Invalid driver `%s', using default `%s'", a1, "sf4r");
radio_drv_free();
return radio_drv_init("sf4r");
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
warnx("Invalid driver `%s', using default `%s'", a1, "sf4r");
radio_drv_free();
return radio_drv_init("sf4r");
}

original_code:
void
invalid_driver_error(char *invl_drv) {
 warnx("Invalid driver `%s', using default `%s'", invl_drv, "sf4r");
 radio_drv_free();
 radio_drv_init("sf4r");
}


gouser

decompiled_code:
__int64 gouser()
{
__uid_t v0; // eax
__uid_t v2; // eax

v0 = getuid();
if ( seteuid(v0) >= 0 )
return 0LL;
v2 = getuid();
warn("set effective user %d privs error", v2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func3()
{
__uid_t v0; // eax
__uid_t v2; // eax

v0 = getuid();
if ( seteuid(v0) >= 0 )
return 0LL;
v2 = getuid();
warn("set effective user %d privs error", v2);
return 0xFFFFFFFFLL;
}

original_code:
int
gouser(void) {
 if (seteuid(getuid()) < 0) {
  warn("set effective user %d privs error", getuid());
  return -1;
 }
 return 0;
}

canonical_original_code:
int gouser() {
 if (seteuid(getuid()) < 0) {
  warn("set effective user %d privs error", getuid());
  return -1;
 }
 return 0;
}


goroot

decompiled_code:
__int64 goroot()
{
if ( seteuid(0) >= 0 )
return 0LL;
warn("set effective root privs error");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func4()
{
if ( seteuid(0) >= 0 )
return 0LL;
warn("set effective root privs error");
return 0xFFFFFFFFLL;
}

original_code:
int
goroot(void) {
 if (seteuid(0) < 0) {
  warn("set effective root privs error");
  return -1;
 }
 return 0;
}

canonical_original_code:
int goroot() {
 if (seteuid(0) < 0) {
  warn("set effective root privs error");
  return -1;
 }
 return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rdx
char *v5; // rax
const char *v6; // rbx
int v7; // er15
int v8; // er14
int v9; // ebx
int v10; // er13
int v11; // eax
int v12; // edx
const char **v13; // rsi
int v14; // eax
int v15; // eax
__int16 v16; // dx
unsigned int v17; // ebp
__int64 v18; // rdx
const char *v19; // rsi
unsigned __int64 v20; // rdi
int v21; // eax
__int64 v22; // rdx
unsigned int v23; // ebx
__int64 v24; // rsi
unsigned __int16 v25; // bx
__int64 v26; // rdx
int v27; // eax
__int64 v28; // rdx
__int64 v29; // rdi
int v30; // er12
int v31; // eax
int v32; // ebp
unsigned __int16 v33; // bx
unsigned int v34; // ebp
unsigned int v35; // er12
int v36; // eax
int v37; // eax
__int64 v38; // rdx
__int64 v39; // rdx
int result; // eax
unsigned int v41; // [rsp+4h] [rbp-44h]
unsigned int v42; // [rsp+8h] [rbp-40h]
unsigned __int16 v43; // [rsp+Eh] [rbp-3Ah]

if ( (int)gouser(argc, argv, envp) < 0 )
return -1;
pn = (__int64)strrchr(*argv, 47);
v4 = (const char *)(pn + 1);
if ( !pn )
v4 = *argv;
pn = (__int64)v4;
radio_init();
v5 = getenv("FMTUNER");
v6 = v5;
if ( v5 )
{
if ( !*v5 )
v6 = "sf4r";
}
else
{
v6 = "sf4r";
}
if ( (unsigned int)radio_drv_init(v6) == -1 )
invalid_driver_error(v6);
if ( argc <= 1 )
usage();
v41 = 1;
LOWORD(v7) = 0;
LOWORD(v8) = 0;
v9 = 0;
v42 = 0;
v43 = 10630;
v10 = 0;
while ( 1 )
{
v13 = argv;
v14 = getopt(argc, (char *const *)argv, "c:Dd:f:h:il:mSsv:W:X:x:");
if ( v14 == -1 )
break;
switch ( v14 )
{
case 'D':
v9 = 512;
break;
case 'S':
v9 = 256;
break;
case 'W':
v10 = (int)(atof(optarg) * 100.0);
v9 = 1024;
break;
case 'c':
v11 = strtol(optarg, 0LL, 10);
v12 = 1;
if ( v11 )
v12 = v11;
v41 = v12;
break;
case 'd':
radio_drv_free();
if ( (unsigned int)radio_drv_init(optarg) == -1 )
invalid_driver_error(optarg);
break;
case 'f':
v15 = (int)(strtod(optarg, 0LL) * 100.0);
v16 = 10630;
if ( (_WORD)v15 )
v16 = v15;
v43 = v16;
v9 |= 2u;
break;
case 'h':
v7 = (int)(atof(optarg) * 100.0);
break;
case 'i':
v9 |= 0x10u;
break;
case 'l':
v8 = (int)(atof(optarg) * 100.0);
break;
case 'm':
v9 |= 8u;
break;
case 's':
v9 |= 1u;
break;
case 'v':
v42 = strtoul(optarg, 0LL, 10);
v9 |= 4u;
break;
default:
usage();
return result;
}
}
if ( (_BYTE)v9 )
LOWORD(v9) = (unsigned __int8)v9;
if ( (unsigned int)radio_info_root() && (int)goroot() < 0 )
die(1);
if ( (int)radio_get_port() < 0 )
die(1);
v17 = radio_test_port();
if ( v17 != 1 )
{
fprintf(stderr, "%s: card not found: ", (const char *)pn);
v23 = radio_info_port();
v24 = radio_info_name();
radio_info_show(stderr, v24, v23);
radio_free_port();
die(1);
}
if ( (unsigned int)radio_info_root() && (int)gouser((unsigned int)argc, v13, v18) < 0 )
die(1);
signal(2, (__sighandler_t)die);
signal(1, (__sighandler_t)die);
v19 = (const char *)die;
v20 = 15LL;
signal(15, (__sighandler_t)die);
v21 = v9 & 0xFF00;
if ( v21 == 512 )
{
if ( (int)goroot() < 0 )
die(1);
radio_detect();
if ( (int)gouser(15LL, die, v38) < 0 )
die(1);
goto LABEL_108;
}
if ( (v9 & 0xFF00u) > 0x200 )
{
if ( v21 == 1024 )
{
if ( (unsigned int)radio_info_root() && (int)goroot() < 0 )
die(1);
if ( v10 < 0 )
{
v19 = (const char *)(unsigned __int16)-(__int16)v10;
v20 = 0LL;
v25 = radio_search(0LL, v19);
}
else
{
v19 = (const char *)(unsigned __int16)v10;
v20 = 1LL;
v25 = radio_search(1LL, (unsigned __int16)v10);
}
if ( (unsigned int)radio_info_root() && (int)gouser(v20, v19, v26) < 0 )
die(1);
if ( v25 )
{
v19 = (const char *)pn;
v20 = (unsigned __int64)"%s: %.2f MHz\n";
printf("%s: %.2f MHz\n", (const char *)pn, (float)((float)v25 / 100.0));
}
}
goto LABEL_108;
}
if ( (v9 & 0xFF00) == 0 )
{
if ( (unsigned int)radio_info_root() && (int)goroot() < 0 )
die(1);
if ( (v9 & 8) != 0 )
radio_set_mono();
v27 = radio_info_policy();
if ( v27 )
{
if ( v27 == 1 )
{
if ( (v9 & 2) == 0 )
{
LABEL_67:
if ( (v9 & 4) != 0 )
{
v20 = v42;
radio_set_volume(v42);
}
if ( (v9 & 1) == 0 )
goto LABEL_70;
v30 = radio_info_stereo();
v31 = radio_info_signal();
v32 = v31;
if ( v30 == -1 )
{
if ( v31 == -1 )
{
LABEL_92:
if ( (v30 & v32) != -1 )
{
v20 = 10LL;
putchar(10);
}
LABEL_70:
if ( (v9 & 0x10) != 0 )
{
v33 = radio_info_freq();
v34 = radio_info_volume();
printf("Driver: ");
v35 = radio_info_port();
v19 = (const char *)radio_info_name();
v20 = (unsigned __int64)stdout;
radio_info_show(stdout, v19, v35);
if ( v33 )
{
v20 = (unsigned __int64)"Frequency: %.2f MHz\n";
printf("Frequency: %.2f MHz\n", (float)((float)v33 / 100.0));
}
if ( v34 )
{
v19 = (const char *)v34;
v20 = (unsigned __int64)"Volume: %u\n";
printf("Volume: %u\n", v34);
}
v36 = radio_info_signal();
if ( v36 != -1 )
{
v19 = "on";
if ( !v36 )
v19 = "off";
v20 = (unsigned __int64)"Signal: %s\n";
printf("Signal: %s\n", v19);
}
v37 = radio_info_stereo();
if ( v37 != -1 )
{
v19 = "on";
if ( !v37 )
v19 = "off";
v20 = (unsigned __int64)"Stereo: %s\n";
printf("Stereo: %s\n", v19);
}
}
if ( (unsigned int)radio_info_root() )
gouser(v20, v19, v28);
goto LABEL_108;
}
}
else
{
v19 = "stereo";
if ( !v30 )
v19 = "mono";
v20 = (unsigned __int64)"%s";
printf("%s", v19);
if ( v32 == -1 )
goto LABEL_92;
printf(" : ");
}
v19 = "signal";
if ( !v32 )
v19 = "noise";
v20 = (unsigned __int64)"%s";
printf("%s", v19);
goto LABEL_92;
}
v29 = v42;
if ( (v9 & 4) == 0 )
v29 = (unsigned __int8)radio_info_maxvol(v42);
radio_set_volume(v29);
}
else if ( (v9 & 2) == 0 )
{
goto LABEL_67;
}
}
else
{
if ( (v9 & 2) == 0 )
goto LABEL_67;
if ( (v9 & 4) != 0 )
v17 = v42;
radio_set_volume(v17);
}
v20 = v43;
radio_set_freq(v43);
goto LABEL_67;
}
if ( v21 == 256 )
{
if ( (unsigned int)radio_info_root() && (int)goroot() < 0 )
die(1);
v19 = (const char *)(unsigned __int16)v7;
v20 = (unsigned __int16)v8;
radio_scan((unsigned __int16)v8, (unsigned __int16)v7, v41);
if ( (unsigned int)radio_info_root() && (int)gouser((unsigned __int16)v8, (unsigned __int16)v7, v22) < 0 )
die(1);
}
LABEL_108:
if ( (unsigned int)radio_info_root() && (int)goroot() < 0 )
die(1);
radio_free_port();
if ( (unsigned int)radio_info_root() )
gouser(v20, v19, v39);
radio_drv_free();
radio_cleanup();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rdx
char *v5; // rax
const char *v6; // rbx
int v7; // er15
int v8; // er14
int v9; // ebx
int v10; // er13
int v11; // eax
int v12; // edx
const char **v13; // rsi
int v14; // eax
int v15; // eax
__int16 v16; // dx
unsigned int v17; // ebp
__int64 v18; // rdx
const char *v19; // rsi
unsigned __int64 v20; // rdi
int v21; // eax
__int64 v22; // rdx
unsigned int v23; // ebx
__int64 v24; // rsi
unsigned __int16 v25; // bx
__int64 v26; // rdx
int v27; // eax
__int64 v28; // rdx
__int64 v29; // rdi
int v30; // er12
int v31; // eax
int v32; // ebp
unsigned __int16 v33; // bx
unsigned int v34; // ebp
unsigned int v35; // er12
int v36; // eax
int v37; // eax
__int64 v38; // rdx
__int64 v39; // rdx
int result; // eax
unsigned int v41; // [rsp+4h] [rbp-44h]
unsigned int v42; // [rsp+8h] [rbp-40h]
unsigned __int16 v43; // [rsp+Eh] [rbp-3Ah]

if ( (int)func3(argc, argv, envp) < 0 )
return -1;
pn = (__int64)strrchr(*argv, 47);
v4 = (const char *)(pn + 1);
if ( !pn )
v4 = *argv;
pn = (__int64)v4;
radio_init();
v5 = getenv("FMTUNER");
v6 = v5;
if ( v5 )
{
if ( !*v5 )
v6 = "sf4r";
}
else
{
v6 = "sf4r";
}
if ( (unsigned int)radio_drv_init(v6) == -1 )
func2(v6);
if ( argc <= 1 )
func1();
v41 = 1;
LOWORD(v7) = 0;
LOWORD(v8) = 0;
v9 = 0;
v42 = 0;
v43 = 10630;
v10 = 0;
while ( 1 )
{
v13 = argv;
v14 = getopt(argc, (char *const *)argv, "c:Dd:f:h:il:mSsv:W:X:x:");
if ( v14 == -1 )
break;
switch ( v14 )
{
case 'D':
v9 = 512;
break;
case 'S':
v9 = 256;
break;
case 'W':
v10 = (int)(atof(optarg) * 100.0);
v9 = 1024;
break;
case 'c':
v11 = strtol(optarg, 0LL, 10);
v12 = 1;
if ( v11 )
v12 = v11;
v41 = v12;
break;
case 'd':
radio_drv_free();
if ( (unsigned int)radio_drv_init(optarg) == -1 )
func2(optarg);
break;
case 'f':
v15 = (int)(strtod(optarg, 0LL) * 100.0);
v16 = 10630;
if ( (_WORD)v15 )
v16 = v15;
v43 = v16;
v9 |= 2u;
break;
case 'h':
v7 = (int)(atof(optarg) * 100.0);
break;
case 'i':
v9 |= 0x10u;
break;
case 'l':
v8 = (int)(atof(optarg) * 100.0);
break;
case 'm':
v9 |= 8u;
break;
case 's':
v9 |= 1u;
break;
case 'v':
v42 = strtoul(optarg, 0LL, 10);
v9 |= 4u;
break;
default:
func1();
return result;
}
}
if ( (_BYTE)v9 )
LOWORD(v9) = (unsigned __int8)v9;
if ( (unsigned int)radio_info_root() && (int)func4() < 0 )
func0(1);
if ( (int)radio_get_port() < 0 )
func0(1);
v17 = radio_test_port();
if ( v17 != 1 )
{
fprintf(stderr, "%s: card not found: ", (const char *)pn);
v23 = radio_info_port();
v24 = radio_info_name();
radio_info_show(stderr, v24, v23);
radio_free_port();
func0(1);
}
if ( (unsigned int)radio_info_root() && (int)func3((unsigned int)argc, v13, v18) < 0 )
func0(1);
signal(2, (__sighandler_t)die);
signal(1, (__sighandler_t)die);
v19 = (const char *)die;
v20 = 15LL;
signal(15, (__sighandler_t)die);
v21 = v9 & 0xFF00;
if ( v21 == 512 )
{
if ( (int)func4() < 0 )
func0(1);
radio_detect();
if ( (int)func3(15LL, die, v38) < 0 )
func0(1);
goto LABEL_108;
}
if ( (v9 & 0xFF00u) > 0x200 )
{
if ( v21 == 1024 )
{
if ( (unsigned int)radio_info_root() && (int)func4() < 0 )
func0(1);
if ( v10 < 0 )
{
v19 = (const char *)(unsigned __int16)-(__int16)v10;
v20 = 0LL;
v25 = radio_search(0LL, v19);
}
else
{
v19 = (const char *)(unsigned __int16)v10;
v20 = 1LL;
v25 = radio_search(1LL, (unsigned __int16)v10);
}
if ( (unsigned int)radio_info_root() && (int)func3(v20, v19, v26) < 0 )
func0(1);
if ( v25 )
{
v19 = (const char *)pn;
v20 = (unsigned __int64)"%s: %.2f MHz\n";
printf("%s: %.2f MHz\n", (const char *)pn, (float)((float)v25 / 100.0));
}
}
goto LABEL_108;
}
if ( (v9 & 0xFF00) == 0 )
{
if ( (unsigned int)radio_info_root() && (int)func4() < 0 )
func0(1);
if ( (v9 & 8) != 0 )
radio_set_mono();
v27 = radio_info_policy();
if ( v27 )
{
if ( v27 == 1 )
{
if ( (v9 & 2) == 0 )
{
LABEL_67:
if ( (v9 & 4) != 0 )
{
v20 = v42;
radio_set_volume(v42);
}
if ( (v9 & 1) == 0 )
goto LABEL_70;
v30 = radio_info_stereo();
v31 = radio_info_signal();
v32 = v31;
if ( v30 == -1 )
{
if ( v31 == -1 )
{
LABEL_92:
if ( (v30 & v32) != -1 )
{
v20 = 10LL;
putchar(10);
}
LABEL_70:
if ( (v9 & 0x10) != 0 )
{
v33 = radio_info_freq();
v34 = radio_info_volume();
printf("Driver: ");
v35 = radio_info_port();
v19 = (const char *)radio_info_name();
v20 = (unsigned __int64)stdout;
radio_info_show(stdout, v19, v35);
if ( v33 )
{
v20 = (unsigned __int64)"Frequency: %.2f MHz\n";
printf("Frequency: %.2f MHz\n", (float)((float)v33 / 100.0));
}
if ( v34 )
{
v19 = (const char *)v34;
v20 = (unsigned __int64)"Volume: %u\n";
printf("Volume: %u\n", v34);
}
v36 = radio_info_signal();
if ( v36 != -1 )
{
v19 = "on";
if ( !v36 )
v19 = "off";
v20 = (unsigned __int64)"Signal: %s\n";
printf("Signal: %s\n", v19);
}
v37 = radio_info_stereo();
if ( v37 != -1 )
{
v19 = "on";
if ( !v37 )
v19 = "off";
v20 = (unsigned __int64)"Stereo: %s\n";
printf("Stereo: %s\n", v19);
}
}
if ( (unsigned int)radio_info_root() )
func3(v20, v19, v28);
goto LABEL_108;
}
}
else
{
v19 = "stereo";
if ( !v30 )
v19 = "mono";
v20 = (unsigned __int64)"%s";
printf("%s", v19);
if ( v32 == -1 )
goto LABEL_92;
printf(" : ");
}
v19 = "signal";
if ( !v32 )
v19 = "noise";
v20 = (unsigned __int64)"%s";
printf("%s", v19);
goto LABEL_92;
}
v29 = v42;
if ( (v9 & 4) == 0 )
v29 = (unsigned __int8)radio_info_maxvol(v42);
radio_set_volume(v29);
}
else if ( (v9 & 2) == 0 )
{
goto LABEL_67;
}
}
else
{
if ( (v9 & 2) == 0 )
goto LABEL_67;
if ( (v9 & 4) != 0 )
v17 = v42;
radio_set_volume(v17);
}
v20 = v43;
radio_set_freq(v43);
goto LABEL_67;
}
if ( v21 == 256 )
{
if ( (unsigned int)radio_info_root() && (int)func4() < 0 )
func0(1);
v19 = (const char *)(unsigned __int16)v7;
v20 = (unsigned __int16)v8;
radio_scan((unsigned __int16)v8, (unsigned __int16)v7, v41);
if ( (unsigned int)radio_info_root() && (int)func3((unsigned __int16)v8, (unsigned __int16)v7, v22) < 0 )
func0(1);
}
LABEL_108:
if ( (unsigned int)radio_info_root() && (int)func4() < 0 )
func0(1);
radio_free_port();
if ( (unsigned int)radio_info_root() )
func3(v20, v19, v39);
radio_drv_free();
radio_cleanup();
return 0;
}

original_code:
int
main(int argc, char **argv) {
 int optchar;
 int search = 0;
 char *drv = ((void *)0);
 u_int16_t freq = 10630;
 int volu = 0;
 u_int16_t action = 0x0000;
 u_int16_t lower = 0, higher = 0;
 u_int32_t cycle = 1;
 if (gouser() < 0)
  return -1;
 pn = strrchr(argv[0], '/');
 if (pn == ((void *)0))
  pn = argv[0];
 else
  pn++;
 radio_init();
 drv = getenv("FMTUNER");
 if (drv == ((void *)0) || *drv == '\0')
  drv = "sf4r";
 if (radio_drv_init(drv) == -1)
  invalid_driver_error(drv);
 if (argc < 2)
  usage();
 while ((optchar = getopt(argc, argv, "c:Dd:f:h:il:mSsv:W:X:x:")) != -1) {
  switch (optchar) {
  case 'c':
   if ((cycle = strtol(optarg, (char **)((void *)0), 10)) == 0)
    cycle = 1;
   break;
  case 'D':
   action = 0x0200;
   break;
  case 'd':
   radio_drv_free();
   if (radio_drv_init(optarg) == -1)
    invalid_driver_error(optarg);
   break;
  case 'f':
   freq = 100.0 * strtod(optarg, (char **)((void *)0));
   if (freq == 0)
    freq = 10630;
   action |= 0x0002;
   break;
  case 'h':
   higher = atof(optarg) * 100;
   break;
  case 'i':
   action |= 0x0010;
   break;
  case 'l':
   lower = atof(optarg) * 100;
   break;
  case 'm':
   action |= 0x0008;
   break;
  case 'S':
   action = 0x0100;
   break;
  case 's':
   action |= 0x0001;
   break;
  case 'v':
   volu = strtoul(optarg, (char **)((void *)0), 10);
   action |= 0x0004;
   break;
  case 'W':
   action = 0x0400;
   search = atof(optarg) * 100;
   break;
  default:
   usage();
  }
 }
 if (action & 0x00FF) action &= 0x00FF;
 if (radio_info_root())
  if (goroot() < 0)
   die(1);
 if (radio_get_port() < 0)
  die(1);
 if (radio_test_port() != 1) {
  fprintf(stderr, "%s: card not found: ", pn);
  radio_info_show(stderr, radio_info_name(), radio_info_port());
  radio_free_port();
  die(1);
 }
 if (radio_info_root())
  if (gouser() < 0)
   die(1);
 signal(2 , die);
 signal(1 , die);
 signal(15, die);
 switch (action & ~0x00FF) {
 case 0x0000:
  if (radio_info_root())
   if (goroot() < 0)
    die(1);
  if (action & 0x0008)
   radio_set_mono();
  switch (radio_info_policy()) {
  case 0:
   if (action & 0x0002)
    radio_set_volume(action & 0x0004 ? volu : 1);
   break;
  case 1:
   if (action & 0x0002)
    radio_set_volume(action & 0x0004 ?
      volu : radio_info_maxvol());
   break;
  }
  if (action & 0x0002)
   radio_set_freq(freq);
  if (action & 0x0004)
   radio_set_volume(volu);
  if (action & 0x0001) {
   int st = radio_info_stereo();
   int si = radio_info_signal();
   if (st != -1)
    printf("%s", st ? "stereo" : "mono");
   if (st != -1 && si != -1)
    printf(" : ");
   if (si != -1)
    printf("%s", si ? "signal" : "noise");
   if (st != -1 || si != -1)
    printf("\n");
  }
  if (action & 0x0010) {
   u_int16_t f = radio_info_freq();
   int v = radio_info_volume();
   printf("Driver: ");
   radio_info_show(stdout, radio_info_name(), radio_info_port());
   if (f)
    printf("Frequency: %.2f MHz\n", (float) f / 100);
   if (v)
    printf("Volume: %u\n", v);
   v = radio_info_signal();
   if (v != -1)
    printf("Signal: %s\n", v ? "on" : "off");
   v = radio_info_stereo();
   if (v != -1)
    printf("Stereo: %s\n", v ? "on" : "off");
  }
  if (radio_info_root())
   gouser();
  break;
 case 0x0200:
  if (goroot() < 0)
   die(1);
  radio_detect();
  if (gouser() < 0)
   die(1);
  break;
 case 0x0100:
  if (radio_info_root())
   if (goroot() < 0)
    die(1);
  radio_scan(lower, higher, cycle);
  if (radio_info_root())
   if (gouser() < 0)
    die(1);
  break;
 case 0x0400:
  if (radio_info_root())
   if (goroot() < 0)
    die(1);
  if (search < 0)
   freq = radio_search(0, -1 * search);
  else
   freq = radio_search(1, search);
  if (radio_info_root())
   if (gouser() < 0)
    die(1);
  if (freq)
   printf("%s: %.2f MHz\n", pn, (float)freq / 100);
  break;
 default:
  break;
 }
 if (radio_info_root())
  if (goroot() < 0)
   die(1);
 radio_free_port();
 if (radio_info_root())
  gouser();
 radio_drv_free();
 radio_cleanup();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int optchar;
 int search = 0;
 char *drv = ((void *)0);
 unsigned int freq = 10630;
 int volu = 0;
 unsigned int action = 0x0000;
 unsigned int lower = 0; unsigned int higher = 0;
 unsigned int cycle = 1;
 if (gouser() < 0)
  return -1;
 pn = strrchr(argv[0], '/');
 if (pn == ((void *)0))
  pn = argv[0];
 else
  pn++;
 radio_init();
 drv = getenv("FMTUNER");
 if (drv == ((void *)0) || *drv == '\0')
  drv = "sf4r";
 if (radio_drv_init(drv) == -1)
  invalid_driver_error(drv);
 if (argc < 2)
  usage();
 while ((optchar = getopt(argc, argv, "c:Dd:f:h:il:mSsv:W:X:x:")) != -1) {
  switch (optchar) {
  case 'c':
   if ((cycle = strtol(optarg, (char **)((void *)0), 10)) == 0)
    cycle = 1;
   break;
  case 'D':
   action = 0x0200;
   break;
  case 'd':
   radio_drv_free();
   if (radio_drv_init(optarg) == -1)
    invalid_driver_error(optarg);
   break;
  case 'f':
   freq = 100.0 * strtod(optarg, (char **)((void *)0));
   if (freq == 0)
    freq = 10630;
   action |= 0x0002;
   break;
  case 'h':
   higher = atof(optarg) * 100;
   break;
  case 'i':
   action |= 0x0010;
   break;
  case 'l':
   lower = atof(optarg) * 100;
   break;
  case 'm':
   action |= 0x0008;
   break;
  case 'S':
   action = 0x0100;
   break;
  case 's':
   action |= 0x0001;
   break;
  case 'v':
   volu = strtoul(optarg, (char **)((void *)0), 10);
   action |= 0x0004;
   break;
  case 'W':
   action = 0x0400;
   search = atof(optarg) * 100;
   break;
  default:
   usage();
  }
 }
 if (action & 0x00FF) action &= 0x00FF;
 if (radio_info_root())
  if (goroot() < 0)
   die(1);
 if (radio_get_port() < 0)
  die(1);
 if (radio_test_port() != 1) {
  fprintf(stderr, "%s: card not found: ", pn);
  radio_info_show(stderr, radio_info_name(), radio_info_port());
  radio_free_port();
  die(1);
 }
 if (radio_info_root())
  if (gouser() < 0)
   die(1);
 signal(2 , die);
 signal(1 , die);
 signal(15, die);
 switch (action & ~0x00FF) {
 case 0x0000:
  if (radio_info_root())
   if (goroot() < 0)
    die(1);
  if (action & 0x0008)
   radio_set_mono();
  switch (radio_info_policy()) {
  case 0:
   if (action & 0x0002)
    radio_set_volume(action & 0x0004 ? volu : 1);
   break;
  case 1:
   if (action & 0x0002)
    radio_set_volume(action & 0x0004 ?
      volu : radio_info_maxvol());
   break;
  }
  if (action & 0x0002)
   radio_set_freq(freq);
  if (action & 0x0004)
   radio_set_volume(volu);
  if (action & 0x0001) {
   int st = radio_info_stereo();
   int si = radio_info_signal();
   if (st != -1)
    printf("%s", st ? "stereo" : "mono");
   if (st != -1 && si != -1)
    printf(" : ");
   if (si != -1)
    printf("%s", si ? "signal" : "noise");
   if (st != -1 || si != -1)
    printf("\n");
  }
  if (action & 0x0010) {
   unsigned int f = radio_info_freq();
   int v = radio_info_volume();
   printf("Driver: ");
   radio_info_show(stdout, radio_info_name(), radio_info_port());
   if (f)
    printf("Frequency: %.2f MHz\n", (float) f / 100);
   if (v)
    printf("Volume: %u\n", v);
   v = radio_info_signal();
   if (v != -1)
    printf("Signal: %s\n", v ? "on" : "off");
   v = radio_info_stereo();
   if (v != -1)
    printf("Stereo: %s\n", v ? "on" : "off");
  }
  if (radio_info_root())
   gouser();
  break;
 case 0x0200:
  if (goroot() < 0)
   die(1);
  radio_detect();
  if (gouser() < 0)
   die(1);
  break;
 case 0x0100:
  if (radio_info_root())
   if (goroot() < 0)
    die(1);
  radio_scan(lower, higher, cycle);
  if (radio_info_root())
   if (gouser() < 0)
    die(1);
  break;
 case 0x0400:
  if (radio_info_root())
   if (goroot() < 0)
    die(1);
  if (search < 0)
   freq = radio_search(0, -1 * search);
  else
   freq = radio_search(1, search);
  if (radio_info_root())
   if (gouser() < 0)
    die(1);
  if (freq)
   printf("%s: %.2f MHz\n", pn, (float)freq / 100);
  break;
 default:
  break;
 }
 if (radio_info_root())
  if (goroot() < 0)
   die(1);
 radio_free_port();
 if (radio_info_root())
  gouser();
 radio_drv_free();
 radio_cleanup();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: optchar int

variable_types: search int

variable_types:
drv
char *

variable_types:
freq
unsigned int

variable_types: volu int

variable_types:
action
unsigned int

variable_types:
lower
unsigned int

variable_types:
higher
unsigned int

variable_types:
cycle
unsigned int

variable_types: st int

variable_types: si int

variable_types:
f
unsigned int

variable_types: v int


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

result = 0x200000LL;
if ( a1 > 0x23u )
result = (unsigned __int8)((unsigned __int16)(a1 - 36) < 0x27u) << 22;
return result;
}

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

result = 0x200000LL;
if ( a1 > 0x23u )
result = (unsigned __int8)((unsigned __int16)(a1 - 36) < 0x27u) << 22;
return result;
}

original_code:
u_int32_t
lm700x_encode_ref(u_int16_t rf) {
 u_int32_t ret;
 if (rf < 36)
  ret = (2 << 20);
 else if (rf > 35 && rf < 75)
  ret = (4 << 20);
 else
  ret = (0 << 20);
 return ret;
}

canonical_original_code:
unsigned int lm700x_encode_ref(unsigned int rf) {
 unsigned int ret;
 if (rf < 36)
  ret = (2 << 20);
 else if (rf > 35 && rf < 75)
  ret = (4 << 20);
 else
  ret = (0 << 20);
 return ret;
}

variable_types:
rf
unsigned int

variable_types:
ret
unsigned int


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

result = 100LL;
if ( a1 )
{
result = 50LL;
if ( a1 == 0x200000 )
result = 25LL;
}
return result;
}

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

result = 100LL;
if ( a1 )
{
result = 50LL;
if ( a1 == 0x200000 )
result = 25LL;
}
return result;
}

original_code:
u_int16_t
lm700x_decode_ref(u_int32_t rf) {
 switch (rf) {
 case (2 << 20):
  return 25;
 case (4 << 20):
  return 50;
 case (0 << 20):
  return 100;
 }
 return 50;
}

canonical_original_code:
unsigned int lm700x_decode_ref(unsigned int rf) {
 switch (rf) {
 case (2 << 20):
  return 25;
 case (4 << 20):
  return 50;
 case (0 << 20):
  return 100;
 }
 return 50;
}


decompiled_code:
__int64 __fastcall lm700x_encode_freq(unsigned __int16 a1, int a2)
{
return 2 * (5 * (unsigned int)a1 + 5350) / (unsigned __int16)lm700x_decode_ref(a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1, int a2)
{
return 2 * (5 * (unsigned int)a1 + 5350) / (unsigned __int16)func1(a2);
}

original_code:
u_int32_t
lm700x_encode_freq(u_int16_t f, u_int32_t rf) {
 u_int32_t reg;
 reg = f + 1070;
 reg *= 10;
 reg /= lm700x_decode_ref(rf);
 return reg;
}

canonical_original_code:
unsigned int lm700x_encode_freq(unsigned int f, unsigned int rf) {
 unsigned int reg;
 reg = f + 1070;
 reg *= 10;
 reg /= lm700x_decode_ref(rf);
 return reg;
}

variable_types:
reg
unsigned int


decompiled_code:
__int64 __fastcall pt2254a_encode_volume(unsigned int a1, unsigned int a2)
{
signed int v2; // edx
__int64 result; // rax

v2 = 68;
if ( a1 )
{
if ( a2 / 3 < a1 )
{
if ( 2 * a2 / 3 >= a1 )
v2 = 34 - 42 * a1 / a2;
else
v2 = 18 - 18 * a1 / a2;
}
else
{
v2 = 68 - 144 * a1 / a2;
}
}
LODWORD(result) = 1 << (v2 / 10);
_bittestandset((int *)&result, v2 % 10 / 2 + 7);
return (int)result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
signed int v2; // edx
__int64 result; // rax

v2 = 68;
if ( a1 )
{
if ( a2 / 3 < a1 )
{
if ( 2 * a2 / 3 >= a1 )
v2 = 34 - 42 * a1 / a2;
else
v2 = 18 - 18 * a1 / a2;
}
else
{
v2 = 68 - 144 * a1 / a2;
}
}
LODWORD(result) = 1 << (v2 / 10);
_bittestandset((int *)&result, v2 % 10 / 2 + 7);
return (int)result;
}

original_code:
unsigned long
pt2254a_encode_volume(unsigned int current, unsigned int max) {
 unsigned long ret = 0ul;
 int vol, tens, ones;
 if (current > 0 && current <= max / 3) {
  vol = 68 - (48 * 3 * current / max);
 } else if (current > max / 3 && current <= 2 * max / 3) {
  vol = 34 - (42 * current / max);
 } else if (current > 2 * max / 3) {
  vol = 18 - (18 * current / max);
 } else vol = 68;
 tens = vol / 10;
 ones = vol - tens * 10;
 ret = (1 << tens) | (1 << (7 + ones / 2));
 return ret;
}

canonical_original_code:
unsigned long pt2254a_encode_volume(unsigned int current, unsigned int max) {
 unsigned long ret = 0ul;
 int vol; int tens; int ones;
 if (current > 0 && current <= max / 3) {
  vol = 68 - (48 * 3 * current / max);
 } else if (current > max / 3 && current <= 2 * max / 3) {
  vol = 34 - (42 * current / max);
 } else if (current > 2 * max / 3) {
  vol = 18 - (18 * current / max);
 } else vol = 68;
 tens = vol / 10;
 ones = vol - tens * 10;
 ret = (1 << tens) | (1 << (7 + ones / 2));
 return ret;
}

variable_types:
current
unsigned int

variable_types:
max
unsigned int

variable_types:
ret
unsigned long

variable_types: vol int

variable_types: tens int

variable_types: ones int

return_type: unsigned long


decompiled_code:
__int64 __fastcall pt2254a_compose_register(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 v4; // rdi
__int64 result; // rax
__int64 v6; // rsi

v4 = a1 | 0x2000;
result = 0LL;
if ( a3 == 1 )
result = v4;
v6 = result | a2 | 0x4000;
if ( a4 == 1 )
result = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 v4; // rdi
__int64 result; // rax
__int64 v6; // rsi

v4 = a1 | 0x2000;
result = 0LL;
if ( a3 == 1 )
result = v4;
v6 = result | a2 | 0x4000;
if ( a4 == 1 )
result = v6;
return result;
}

original_code:
unsigned long
pt2254a_compose_register(unsigned long lvol, unsigned long rvol, int left, int right) {
 unsigned long ret = 0ul;
 if (left == 1) {
  ret |= (1 << 13);
  ret |= lvol;
 }
 if (right == 1) {
  ret |= (1 << 14);
  ret |= rvol;
 }
 ret |= (0 << 15);
 ret |= (0 << 12);
 return ret;
}

variable_types:
lvol
unsigned long

variable_types:
rvol
unsigned long

variable_types: left int

variable_types: right int


chartoint

repo: jouyouyun/serial

decompiled_code:
__int64 __fastcall chartoint(char a1)
{
unsigned __int8 v1; // dl
int v2; // eax
unsigned int v3; // edi
__int64 result; // rax

v1 = a1 - 48;
v2 = a1;
v3 = a1 - 48;
result = (unsigned int)(v2 - 55);
if ( v1 <= 9u )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
unsigned __int8 v1; // dl
int v2; // eax
unsigned int v3; // edi
__int64 result; // rax

v1 = a1 - 48;
v2 = a1;
v3 = a1 - 48;
result = (unsigned int)(v2 - 55);
if ( v1 <= 9u )
result = v3;
return result;
}

original_code:
int chartoint( char c )
{
 if ( c >= '0' && c <= '9' ) {
  return ( c - '0' );
 }
 return ( c - 'A' + 10 );
}

canonical_original_code:
int chartoint(char c)
{
 if ( c >= '0' && c <= '9' ) {
  return ( c - '0' );
 }
 return ( c - 'A' + 10 );
}

variable_types: c char


decompiled_code:
__int16 __fastcall modbus_crc(unsigned __int8 *a1, int a2)
{
__int64 v2; // r8
int v3; // eax
int v4; // ecx
int v5; // edx
int v6; // esi
bool v7; // zf

if ( a2 <= 0 )
{
LOWORD(v3) = -1;
}
else
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = -1;
do
{
v3 ^= *a1;
v4 = 8;
do
{
HIWORD(v5) = HIWORD(v3);
LOWORD(v5) = ((unsigned __int16)v3 >> 1) ^ 0xA001;
HIWORD(v6) = HIWORD(v3);
LOWORD(v6) = (unsigned __int16)v3 >> 1;
v7 = (v3 & 1) == 0;
v3 = v5;
if ( v7 )
v3 = v6;
--v4;
}
while ( v4 );
++a1;
}
while ( a1 != (unsigned __int8 *)v2 );
}
return __ROL2__(v3, 8);
}

canonical_decompiled_code:
__int16 __fastcall func8(unsigned __int8 *a1, int a2)
{
__int64 v2; // r8
int v3; // eax
int v4; // ecx
int v5; // edx
int v6; // esi
bool v7; // zf

if ( a2 <= 0 )
{
LOWORD(v3) = -1;
}
else
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = -1;
do
{
v3 ^= *a1;
v4 = 8;
do
{
HIWORD(v5) = HIWORD(v3);
LOWORD(v5) = ((unsigned __int16)v3 >> 1) ^ 0xA001;
HIWORD(v6) = HIWORD(v3);
LOWORD(v6) = (unsigned __int16)v3 >> 1;
v7 = (v3 & 1) == 0;
v3 = v5;
if ( v7 )
v3 = v6;
--v4;
}
while ( v4 );
++a1;
}
while ( a1 != (unsigned __int8 *)v2 );
}
return __ROL2__(v3, 8);
}

original_code:
unsigned short modbus_crc( unsigned char *p, int len )
{
 unsigned short ret = 0xFFFF;
 int i = 0;
 int k = 0;
 for ( i = 0; i < len; ++i ) {
  ret ^= p[i];
  for ( k = 0; k < 8; ++k ) {
   ret = ( ret & 0x01) ? ( (ret >> 1) ^ 0xA001 ) : ( ret >> 1 );
  }
 }
 ret = ((ret & 0x00FF) << 8) | ((ret & 0xFF00) >> 8);
 return ret;
}

canonical_original_code:
unsigned short modbus_crc(unsigned char *p, int len)
{
 unsigned short ret = 0xFFFF;
 int i = 0;
 int k = 0;
 for ( i = 0; i < len; ++i ) {
  ret ^= p[i];
  for ( k = 0; k < 8; ++k ) {
   ret = ( ret & 0x01) ? ( (ret >> 1) ^ 0xA001 ) : ( ret >> 1 );
  }
 }
 ret = ((ret & 0x00FF) << 8) | ((ret & 0xFF00) >> 8);
 return ret;
}

variable_types:
p
unsigned char *

variable_types: len int

variable_types:
ret
unsigned short

variable_types: i int

variable_types: k int

return_type: unsigned short


main

original_code:
int main( int argc, char *argv[] )
{
 int saveadd = 0, func = 0, startadd = 0, num = 0, i = 0, len = 0, k = 0;
 unsigned short val = 0;
 unsigned char recv[65];
 unsigned char recvtmp[65];
 unsigned char str[65];
 unsigned char fstr[4];
 float *pf = ((void *)0);
 while ( scanf( "%d, %d, %d, %d", &saveadd, &func, &startadd, &num )
   != (-1) ) {
  str[0] = saveadd;
  str[1] = func;
  str[3] = startadd & 0xFF;
  startadd >>= 8;
  str[2] = startadd & 0xFF;
  str[5] = num & 0xFF;
  num >>= 8;
  str[4] = num & 0xFF;
  val = modbus_crc( str, 6 );
  str[7] = val & 0xFF;
  val >>= 8;
  str[6] = val & 0xFF;
  for ( i = 0; i < 8; ++i ) {
   printf( "%02X", str[i] );
  }
  printf( "\n" );
  scanf( "%s", recvtmp );
  len = strlen( (char*)recvtmp ) / 2;
  for( i = 0; i < len; ++i ) {
   recv[i] = (unsigned char) ( chartoint( recvtmp[i * 2] ) * 16 +
     chartoint( recvtmp[i * 2 + 1] ) );
  }
  for ( i = 0; i < len; ++i ) {
   printf( "%d ", recv[i] );
  }
  val = modbus_crc( recv, len - 2 );
  printf( "\n%02X\n", val );
  if ( ( (val & 0xFF) != recv[len - 1] ) || ( ( (val >> 8) & 0xFF )
    != recv[len - 2] ) ) {
   printf( "CRC ERROR\n" );
   continue;
  }
  k = 2;
  num = recv[k] / 4;
  printf( "num: %d\n", num );
  ++k;
  for ( i = 0; i < num; ++i ) {
   fstr[0] = recv[k + 3];
   fstr[1] = recv[k + 2];
   fstr[2] = recv[k + 1];
   fstr[3] = recv[k];
   pf = (float*)(fstr);
   printf( "%.lf", *pf );
   if ( num - 1 != i ) {
    printf( ", " );
   }
   k += 4;
  }
  if ( num != 0 ) {
   printf( "\n" );
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int saveadd = 0; int func = 0; int startadd = 0; int num = 0; int i = 0; int len = 0; int k = 0;
 unsigned short val = 0;
 unsigned char recv[65];
 unsigned char recvtmp[65];
 unsigned char str[65];
 unsigned char fstr[4];
 float *pf = ((void *)0);
 while ( scanf( "%d, %d, %d, %d", &saveadd, &func, &startadd, &num )
   != (-1) ) {
  str[0] = saveadd;
  str[1] = func;
  str[3] = startadd & 0xFF;
  startadd >>= 8;
  str[2] = startadd & 0xFF;
  str[5] = num & 0xFF;
  num >>= 8;
  str[4] = num & 0xFF;
  val = modbus_crc( str, 6 );
  str[7] = val & 0xFF;
  val >>= 8;
  str[6] = val & 0xFF;
  for ( i = 0; i < 8; ++i ) {
   printf( "%02X", str[i] );
  }
  printf( "\n" );
  scanf( "%s", recvtmp );
  len = strlen( (char *)recvtmp ) / 2;
  for( i = 0; i < len; ++i ) {
   recv[i] = (unsigned char) ( chartoint( recvtmp[i * 2] ) * 16 +
     chartoint( recvtmp[i * 2 + 1] ) );
  }
  for ( i = 0; i < len; ++i ) {
   printf( "%d ", recv[i] );
  }
  val = modbus_crc( recv, len - 2 );
  printf( "\n%02X\n", val );
  if ( ( (val & 0xFF) != recv[len - 1] ) || ( ( (val >> 8) & 0xFF )
    != recv[len - 2] ) ) {
   printf( "CRC ERROR\n" );
   continue;
  }
  k = 2;
  num = recv[k] / 4;
  printf( "num: %d\n", num );
  ++k;
  for ( i = 0; i < num; ++i ) {
   fstr[0] = recv[k + 3];
   fstr[1] = recv[k + 2];
   fstr[2] = recv[k + 1];
   fstr[3] = recv[k];
   pf = (float *)(fstr);
   printf( "%.lf", *pf );
   if ( num - 1 != i ) {
    printf( ", " );
   }
   k += 4;
  }
  if ( num != 0 ) {
   printf( "\n" );
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: saveadd int

variable_types: func int

variable_types: startadd int

variable_types: num int

variable_types:
val
unsigned short

variable_types:
recv
unsigned char [65]

variable_types:
recvtmp
unsigned char [65]

variable_types:
str
unsigned char [65]

variable_types:
fstr
unsigned char [4]

variable_types:
pf
float *


decompiled_code:
__int64 __fastcall open_port(const char *a1)
{
unsigned int v1; // ebx
int *v3; // rax
char *v4; // rax

v1 = open(a1, 2306);
if ( v1 == -1 )
{
v3 = __errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Cannot open the port: %s\n", v4);
}
return v1;
}

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

v1 = open(a1, 2306);
if ( v1 == -1 )
{
v3 = __errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Cannot open the port: %s\n", v4);
}
return v1;
}

original_code:
int open_port( char *port )
{
 int fd;
 if ( (fd = open( port, 02 | 0400 | 04000 )) == -1 ) {
  fprintf( stderr, "Cannot open the port: %s\n", strerror((*__errno_location ())) );
  return -1;
 }
 return fd;
}

canonical_original_code:
int open_port(char *port)
{
 int fd;
 if ( (fd = open( port, 02 | 0400 | 04000 )) == -1 ) {
  fprintf( stderr, "Cannot open the port: %s\n", strerror((*__errno_location ())) );
  return -1;
 }
 return fd;
}

variable_types:
port
char *

variable_types: fd int


decompiled_code:
int __fastcall close_port(int a1)
{
return close(a1);
}

canonical_decompiled_code:
int __fastcall func8(int a1)
{
return close(a1);
}

original_code:
void close_port( int fd )
{
 close(fd);
}

canonical_original_code:
void close_port(int fd)
{
 close(fd);
}


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

if ( a1 == 1200 )
return 9LL;
if ( a1 > 0x4B0 )
{
if ( a1 == 19200 )
{
result = 14LL;
}
else if ( a1 <= 0x4B00 )
{
result = 12LL;
if ( a1 != 4800 )
{
if ( a1 <= 0x12C0 )
{
result = 10LL;
if ( a1 != 1800 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 2400 )
result = 11LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( a1 == 9600 )
result = 13LL;
}
}
}
else
{
result = 4098LL;
if ( a1 != 115200 )
{
if ( a1 <= 0x1C200 )
{
result = 15LL;
if ( a1 != 38400 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 57600 )
result = 4097LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( a1 == 230400 )
result = 4099LL;
}
}
}
}
else if ( a1 == 134 )
{
result = 4LL;
}
else if ( a1 <= 0x86 )
{
result = 2LL;
if ( a1 != 75 )
{
if ( a1 <= 0x4B )
{
result = 0LL;
if ( a1 )
result = 2 * (unsigned int)(a1 == 50) - 1;
}
else
{
result = 4 * (unsigned int)(a1 == 110) - 1;
}
}
}
else
{
result = 7LL;
if ( a1 != 300 )
{
if ( a1 <= 0x12C )
{
result = 5LL;
if ( a1 != 150 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 200 )
result = 6LL;
}
}
else
{
result = 9 * (unsigned int)(a1 == 600) - 1;
}
}
}
return result;
}

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

if ( a1 == 1200 )
return 9LL;
if ( a1 > 0x4B0 )
{
if ( a1 == 19200 )
{
result = 14LL;
}
else if ( a1 <= 0x4B00 )
{
result = 12LL;
if ( a1 != 4800 )
{
if ( a1 <= 0x12C0 )
{
result = 10LL;
if ( a1 != 1800 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 2400 )
result = 11LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( a1 == 9600 )
result = 13LL;
}
}
}
else
{
result = 4098LL;
if ( a1 != 115200 )
{
if ( a1 <= 0x1C200 )
{
result = 15LL;
if ( a1 != 38400 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 57600 )
result = 4097LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( a1 == 230400 )
result = 4099LL;
}
}
}
}
else if ( a1 == 134 )
{
result = 4LL;
}
else if ( a1 <= 0x86 )
{
result = 2LL;
if ( a1 != 75 )
{
if ( a1 <= 0x4B )
{
result = 0LL;
if ( a1 )
result = 2 * (unsigned int)(a1 == 50) - 1;
}
else
{
result = 4 * (unsigned int)(a1 == 110) - 1;
}
}
}
else
{
result = 7LL;
if ( a1 != 300 )
{
if ( a1 <= 0x12C )
{
result = 5LL;
if ( a1 != 150 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 200 )
result = 6LL;
}
}
else
{
result = 9 * (unsigned int)(a1 == 600) - 1;
}
}
}
return result;
}