decompiled_code:
__int64 __fastcall read_timestamp(char *s, char *haystack)
{
char *v2; // rax
char *v3; // rbp
size_t v4; // rax
int v6; // [rsp+8h] [rbp-30h] BYREF
int v7; // [rsp+Ch] [rbp-2Ch] BYREF
int v8; // [rsp+10h] [rbp-28h] BYREF
char v9; // [rsp+14h] [rbp-24h] BYREF
char v10; // [rsp+18h] [rbp-20h] BYREF
char v11; // [rsp+1Ch] [rbp-1Ch] BYREF

v2 = strstr(haystack, s);
if ( v2 )
{
v3 = v2;
v4 = strlen(s);
_isoc99_sscanf(&v3[v4 + 1], "%04d-%02d-%02d-%02d:%02d:%02d", &v11, &v10, &v9, &v8, &v7, &v6);
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
}
return (unsigned int)(v6 + 60 * v7 + 3600 * v8);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, char *haystack)
{
char *v2; // rax
char *v3; // rbp
size_t v4; // rax
int v6; // [rsp+8h] [rbp-30h] BYREF
int v7; // [rsp+Ch] [rbp-2Ch] BYREF
int v8; // [rsp+10h] [rbp-28h] BYREF
char v9; // [rsp+14h] [rbp-24h] BYREF
char v10; // [rsp+18h] [rbp-20h] BYREF
char v11; // [rsp+1Ch] [rbp-1Ch] BYREF

v2 = strstr(haystack, s);
if ( v2 )
{
v3 = v2;
v4 = strlen(s);
_isoc99_sscanf(&v3[v4 + 1], "%04d-%02d-%02d-%02d:%02d:%02d", &v11, &v10, &v9, &v8, &v7, &v6);
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
}
return (unsigned int)(v6 + 60 * v7 + 3600 * v8);
}

original_code:
int read_timestamp(char *keyword,char *buffer)
{
  int result;
  int iyear,imonth,iday,ihour,imin,isec;
  char *pch;
  if ((pch=strstr(buffer,keyword))!=((void *)0)) {
    sscanf(pch+strlen(keyword)+1,"%04d-%02d-%02d-%02d:%02d:%02d",&iyear,&imonth,&iday,&ihour,&imin,&isec);
  } else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  result=3600*ihour+60*imin+isec;
  return result;
}

canonical_original_code:
int read_timestamp(char *keyword, char *buffer)
{
  int result;
  int iyear; int imonth; int iday; int ihour; int imin; int isec;
  char *pch;
  if ((pch=strstr(buffer,keyword))!=((void *)0)) {
    sscanf(pch+strlen(keyword)+1,"%04d-%02d-%02d-%02d:%02d:%02d",&iyear,&imonth,&iday,&ihour,&imin,&isec);
  } else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  result=3600*ihour+60*imin+isec;
  return result;
}

variable_types: iyear int

variable_types: imonth int

variable_types: iday int

variable_types: ihour int

variable_types: imin int

variable_types: isec int


RotateVec

repo: cbassa/lmt

decompiled_code:
void __fastcall RotateVec(float *a1, float *a2, float a3)
{
float v3; // ebx
float v4; // er12
float v5; // xmm1_4
float v6; // xmm0_4
double v7; // [rsp+0h] [rbp-38h] BYREF
double sinx[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = *a1;
v4 = *a2;
sincos(a3, sinx, &v7);
v5 = v7;
v6 = sinx[0];
*a1 = (float)(v3 * v5) - (float)(v4 * v6);
*a2 = (float)(v3 * v6) + (float)(v4 * v5);
}

canonical_decompiled_code:
void __fastcall func2(float *a1, float *a2, float a3)
{
float v3; // ebx
float v4; // er12
float v5; // xmm1_4
float v6; // xmm0_4
double v7; // [rsp+0h] [rbp-38h] BYREF
double sinx[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = *a1;
v4 = *a2;
sincos(a3, sinx, &v7);
v5 = v7;
v6 = sinx[0];
*a1 = (float)(v3 * v5) - (float)(v4 * v6);
*a2 = (float)(v3 * v6) + (float)(v4 * v5);
}

original_code:
void RotateVec(float *re, float *im, float angle)
{
  float x, y, cosangle, sinangle;
  x = *re;
  y = *im;
  cosangle = cos(angle);
  sinangle = sin(angle);
  *re = x*cosangle - y*sinangle;
  *im = x*sinangle + y*cosangle;
}

canonical_original_code:
void RotateVec(float *re, float *im, float angle)
{
  float x; float y; float cosangle; float sinangle;
  x = *re;
  y = *im;
  cosangle = cos(angle);
  sinangle = sin(angle);
  *re = x*cosangle - y*sinangle;
  *im = x*sinangle + y*cosangle;
}

variable_types:
re
float *

variable_types:
im
float *

variable_types: angle float

variable_types: x float

variable_types: y float

variable_types: cosangle float

variable_types: sinangle float

return_type: void


GetTimedelay

decompiled_code:
double __fastcall GetTimedelay(__int64 a1, _QWORD *a2, int a3, double a4)
{
double v4; // r14
__int64 v5; // rbx
double v7; // [rsp+0h] [rbp-38h]

v4 = (double)a3 * a4;
v5 = 0LL;
v7 = 0.0;
do
{
v7 = pow(v4, (double)(int)v5) * *(double *)(*a2 + 8 * v5) + v7;
++v5;
}
while ( v5 != 6 );
return (double)(int)*(_QWORD *)(a1 + 16) * a4 + v7;
}

canonical_decompiled_code:
double __fastcall func3(__int64 a1, _QWORD *a2, int a3, double a4)
{
double v4; // r14
__int64 v5; // rbx
double v7; // [rsp+0h] [rbp-38h]

v4 = (double)a3 * a4;
v5 = 0LL;
v7 = 0.0;
do
{
v7 = pow(v4, (double)(int)v5) * *(double *)(*a2 + 8 * v5) + v7;
++v5;
}
while ( v5 != 6 );
return (double)(int)*(_QWORD *)(a1 + 16) * a4 + v7;
}

original_code:
double GetTimedelay(delays_type *delays, calc_type *Calc, double samptime, long reducedbinnumber)
{
  int i;
  double timedelay = 0;
  for (i=0; i<6; i++) {
    timedelay += pow(reducedbinnumber*samptime, i) * Calc->Poly[i];
  }
  timedelay += delays->geoshifted*samptime;
  return timedelay;
}

canonical_original_code:
double GetTimedelay(struct delays_type *delays, struct calc_type *Calc, double samptime, long reducedbinnumber)
{
  int i;
  double timedelay = 0;
  for (i=0; i<6; i++) {
    timedelay += pow(reducedbinnumber*samptime, i) * Calc->Poly[i];
  }
  timedelay += delays->geoshifted*samptime;
  return timedelay;
}

variable_types: struct delays_type { long skipsamples; long samplesshifted; long geoshifted; float frac_delay_pol1; float frac_delay_pol2; float phase_offset_pol1; float phase_offset_pol2; float fringe_drift; } *

variable_types: struct calc_type { double *Poly; char *filename; double Offset; int CountCalcSteps; double CalcMJD; } *

variable_types: samptime double

variable_types: reducedbinnumber long

variable_types: i int

variable_types: timedelay double

return_type: double


Usage

decompiled_code:
int Usage()
{
return puts(
"Usage: reader -i <input file> -o <output file> [-b <blocksize> (64000)] -c <calcfile> -g <gpsfile> -r <refgps"
"file> -s <samples to skip>");
}

canonical_decompiled_code:
int func0()
{
return puts(
"Usage: reader -i <input file> -o <output file> [-b <blocksize> (64000)] -c <calcfile> -g <gpsfile> -r <refgps"
"file> -s <samples to skip>");
}

original_code:
void Usage()
{
  printf("Usage: reader -i <input file> -o <output file> [-b <blocksize> (64000)] -c <calcfile> -g <gpsfile> -r <refgpsfile> -s <samples to skip>\n");
}


digitize

original_code:
char digitize(float f,float scale,float offset)
{
  char c;
  f=f*scale+offset;
  if (f>127.0)
    f=127.0;
  else if (f<-128.0)
    f=-128.0;
  c=(char) floor(f);
  return c;
}

canonical_original_code:
char digitize(float f, float scale, float offset)
{
  char c;
  f=f*scale+offset;
  if (f>127.0)
    f=127.0;
  else if (f<-128.0)
    f=-128.0;
  c=(char) floor(f);
  return c;
}

variable_types: f float

variable_types: scale float

variable_types: offset float

variable_types: c char

return_type: char


decompiled_code:
__int64 __fastcall shm_close_server(void *shmaddr)
{
int v1; // ebp

sem_wait((sem_t *)shmaddr + 2);
*((_DWORD *)shmaddr + 28) = 0;
*((_DWORD *)shmaddr + 29) = 1;
sem_destroy((sem_t *)shmaddr);
sem_destroy((sem_t *)shmaddr + 1);
sem_destroy((sem_t *)shmaddr + 2);
v1 = *((_DWORD *)shmaddr + 25);
shmdt(shmaddr);
shmctl(v1, 0, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *shmaddr)
{
int v1; // ebp

sem_wait((sem_t *)shmaddr + 2);
*((_DWORD *)shmaddr + 28) = 0;
*((_DWORD *)shmaddr + 29) = 1;
sem_destroy((sem_t *)shmaddr);
sem_destroy((sem_t *)shmaddr + 1);
sem_destroy((sem_t *)shmaddr + 2);
v1 = *((_DWORD *)shmaddr + 25);
shmdt(shmaddr);
shmctl(v1, 0, 0LL);
return 0LL;
}

original_code:
int shm_close_server(shm_socket_t* sock){
 sem_wait(&(sock->mutex));
 sock->connected = 0;
 sock->sigclose = 1;
 sem_destroy(&(sock->empty));
 sem_destroy(&(sock->full));
 sem_destroy(&(sock->mutex));
 int shmID = sock->shmID;
 shmdt(&(sock->empty));
 shmctl(shmID, 0, 0);
 return 0;
}

canonical_original_code:
int shm_close_server(struct shm_socket_t *sock){
 sem_wait(&(sock->mutex));
 sock->connected = 0;
 sock->sigclose = 1;
 sem_destroy(&(sock->empty));
 sem_destroy(&(sock->full));
 sem_destroy(&(sock->mutex));
 int shmID = sock->shmID;
 shmdt(&(sock->empty));
 shmctl(shmID, 0, 0);
 return 0;
}

variable_types: struct shm_socket_t { union sem_t { char __size[32]; long __align; } empty; union sem_t full; union sem_t mutex; int buflen; int shmID; int bufhead; int buftail; int connected; int sigclose; char buffer[5]; } *

variable_types: shmID int

return_type: int

user_defined_types: struct shm_socket_t { union sem_t empty; union sem_t full; union sem_t mutex; int buflen; int shmID; int bufhead; int buftail; int connected; int sigclose; char buffer[5]; }


decompiled_code:
__int64 __fastcall shm_close_client(void *shmaddr)
{
sem_wait((sem_t *)shmaddr + 2);
*((_DWORD *)shmaddr + 28) = 0;
*((_DWORD *)shmaddr + 29) = 1;
sem_post((sem_t *)shmaddr + 2);
sem_post((sem_t *)shmaddr);
sem_post((sem_t *)shmaddr + 1);
shmdt(shmaddr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *shmaddr)
{
sem_wait((sem_t *)shmaddr + 2);
*((_DWORD *)shmaddr + 28) = 0;
*((_DWORD *)shmaddr + 29) = 1;
sem_post((sem_t *)shmaddr + 2);
sem_post((sem_t *)shmaddr);
sem_post((sem_t *)shmaddr + 1);
shmdt(shmaddr);
return 0LL;
}

original_code:
int shm_close_client(shm_socket_t* sock){
 sem_wait(&(sock->mutex));
 sock->connected = 0;
 sock->sigclose = 1;
 sem_post(&(sock->mutex));
 sem_post(&(sock->empty));
 sem_post(&(sock->full));
 shmdt(sock);
 return 0;
}

canonical_original_code:
int shm_close_client(struct shm_socket_t *sock){
 sem_wait(&(sock->mutex));
 sock->connected = 0;
 sock->sigclose = 1;
 sem_post(&(sock->mutex));
 sem_post(&(sock->empty));
 sem_post(&(sock->full));
 shmdt(sock);
 return 0;
}

user_defined_types: union sem_t { char __size[32]; long __align; }


original_code:
int shm_socket_write_byte(shm_socket_t* sock, char* byte){
 if(!sock->connected || sock->sigclose){
  return 0;
 }
 sem_wait(&(sock->empty));
 sem_wait(&(sock->mutex));
 *(char*)(sock->buffer+sock->bufhead) = *byte;
 sock->bufhead++;
 if(sock->bufhead>=(sock->buflen)){
  sock->bufhead=0;
 }
 sem_post(&(sock->mutex));
 sem_post(&(sock->full));
 return 1;
}

canonical_original_code:
int shm_socket_write_byte(struct shm_socket_t *sock, char *byte){
 if(!sock->connected || sock->sigclose){
  return 0;
 }
 sem_wait(&(sock->empty));
 sem_wait(&(sock->mutex));
 *(char *)(sock->buffer+sock->bufhead) = *byte;
 sock->bufhead++;
 if(sock->bufhead>=(sock->buflen)){
  sock->bufhead=0;
 }
 sem_post(&(sock->mutex));
 sem_post(&(sock->full));
 return 1;
}

variable_types:
byte
char *


decompiled_code:
__int64 __fastcall shm_socket_write(__int64 a1, _BYTE *a2, int a3)
{
_BYTE *v3; // rbx
_BYTE *v4; // rbp
_BYTE *v5; // rax

if ( a3 <= 0 )
return 0LL;
v3 = a2;
v4 = &a2[a3 - 1];
do
{
shm_socket_write_byte(a1, v3);
v5 = v3++;
}
while ( v5 != v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _BYTE *a2, int a3)
{
_BYTE *v3; // rbx
_BYTE *v4; // rbp
_BYTE *v5; // rax

if ( a3 <= 0 )
return 0LL;
v3 = a2;
v4 = &a2[a3 - 1];
do
{
func2(a1, v3);
v5 = v3++;
}
while ( v5 != v4 );
return 0LL;
}

original_code:
int shm_socket_write(shm_socket_t* sock, void *buf, int size){
 char* chbuf = (char*)buf;
 int i;
 for(i = 0; i < size; i++){
  shm_socket_write_byte(sock,&chbuf[i]);
 }
 return 0;
}

canonical_original_code:
int shm_socket_write(struct shm_socket_t *sock, void *buf, int size){
 char *chbuf = (char*)buf;
 int i;
 for(i = 0; i < size; i++){
  shm_socket_write_byte(sock,&chbuf[i]);
 }
 return 0;
}

variable_types:
buf
void *

variable_types: size int

variable_types:
chbuf
char *


decompiled_code:
__int64 __fastcall shm_socket_write_str(__int64 a1, _BYTE *a2)
{
unsigned int v3; // ebp

v3 = 0;
while ( 1 )
{
shm_socket_write_byte(a1, a2);
if ( !*a2 )
break;
++v3;
++a2;
if ( v3 == 1024 )
return v3;
}
++v3;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _BYTE *a2)
{
unsigned int v3; // ebp

v3 = 0;
while ( 1 )
{
func2(a1, a2);
if ( !*a2 )
break;
++v3;
++a2;
if ( v3 == 1024 )
return v3;
}
++v3;
return v3;
}

original_code:
int shm_socket_write_str(shm_socket_t* sock, char* buf){
 int reading = 1;
 int i = 0;
 while(reading && i < 1024){
  shm_socket_write_byte(sock,&buf[i]);
  if(buf[i]=='\0'){
   reading=0;
  }
  i++;
 }
 return i;
}

canonical_original_code:
int shm_socket_write_str(struct shm_socket_t *sock, char *buf){
 int reading = 1;
 int i = 0;
 while(reading && i < 1024){
  shm_socket_write_byte(sock,&buf[i]);
  if(buf[i]=='\0'){
   reading=0;
  }
  i++;
 }
 return i;
}

variable_types:
buf
char *

variable_types: reading int


decompiled_code:
__int64 __fastcall shm_socket_read_byte(sem_t *sem, _BYTE *a2)
{
int v2; // eax
__int64 result; // rax

sem_wait(sem + 1);
sem_wait(sem + 2);
*a2 = sem[3].__size[*((int *)&sem[3].__align + 3) + 24];
v2 = *((_DWORD *)&sem[3].__align + 3) + 1;
*((_DWORD *)&sem[3].__align + 3) = v2;
if ( v2 >= *(_DWORD *)sem[3].__size )
*((_DWORD *)&sem[3].__align + 3) = 0;
sem_post(sem + 2);
sem_post(sem);
result = *((unsigned int *)&sem[3].__align + 4);
if ( (_DWORD)result )
result = *((_DWORD *)&sem[3].__align + 5) == 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(sem_t *sem, _BYTE *a2)
{
int v2; // eax
__int64 result; // rax

sem_wait(sem + 1);
sem_wait(sem + 2);
*a2 = sem[3].__size[*((int *)&sem[3].__align + 3) + 24];
v2 = *((_DWORD *)&sem[3].__align + 3) + 1;
*((_DWORD *)&sem[3].__align + 3) = v2;
if ( v2 >= *(_DWORD *)sem[3].__size )
*((_DWORD *)&sem[3].__align + 3) = 0;
sem_post(sem + 2);
sem_post(sem);
result = *((unsigned int *)&sem[3].__align + 4);
if ( (_DWORD)result )
result = *((_DWORD *)&sem[3].__align + 5) == 0;
return result;
}

original_code:
int shm_socket_read_byte(shm_socket_t* sock, char* buf){
 sem_wait(&(sock->full));
 sem_wait(&(sock->mutex));
 *buf = *(char*)(sock->buffer+sock->buftail);
 sock->buftail++;
 if(sock->buftail>=(sock->buflen)){
  sock->buftail=0;
 }
 sem_post(&(sock->mutex));
 sem_post(&(sock->empty));
 if(!sock->connected || sock->sigclose){
  return 0;
 }
 return 1;
}

canonical_original_code:
int shm_socket_read_byte(struct shm_socket_t *sock, char *buf){
 sem_wait(&(sock->full));
 sem_wait(&(sock->mutex));
 *buf = *(char *)(sock->buffer+sock->buftail);
 sock->buftail++;
 if(sock->buftail>=(sock->buflen)){
  sock->buftail=0;
 }
 sem_post(&(sock->mutex));
 sem_post(&(sock->empty));
 if(!sock->connected || sock->sigclose){
  return 0;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall shm_socket_read(sem_t *sem, _BYTE *a2, int a3)
{
_BYTE *v3; // rbx
_BYTE *v4; // rbp
_BYTE *v5; // rax

if ( a3 <= 0 )
return 0LL;
v3 = a2;
v4 = &a2[a3 - 1];
do
{
shm_socket_read_byte(sem, v3);
v5 = v3++;
}
while ( v5 != v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(sem_t *sem, _BYTE *a2, int a3)
{
_BYTE *v3; // rbx
_BYTE *v4; // rbp
_BYTE *v5; // rax

if ( a3 <= 0 )
return 0LL;
v3 = a2;
v4 = &a2[a3 - 1];
do
{
func5(sem, v3);
v5 = v3++;
}
while ( v5 != v4 );
return 0LL;
}

original_code:
int shm_socket_read(shm_socket_t* sock, void* buf, int size){
 char* chbuf = (char*)buf;
 int i;
 for(i = 0; i < size; i++){
  shm_socket_read_byte(sock,&chbuf[i]);
 }
 return 0;
}

canonical_original_code:
int shm_socket_read(struct shm_socket_t *sock, void *buf, int size){
 char *chbuf = (char*)buf;
 int i;
 for(i = 0; i < size; i++){
  shm_socket_read_byte(sock,&chbuf[i]);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall shm_socket_read_str(sem_t *sem, _QWORD *a2)
{
_BYTE *v2; // r13
_BYTE *v3; // rbx
unsigned int v4; // ebp

v2 = calloc(0LL, 0x400uLL);
v3 = v2;
v4 = 0;
while ( 1 )
{
shm_socket_read_byte(sem, v3);
if ( !*v3 )
break;
++v4;
++v3;
if ( v4 == 1024 )
goto LABEL_5;
}
++v4;
LABEL_5:
*a2 = v2;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(sem_t *sem, _QWORD *a2)
{
_BYTE *v2; // r13
_BYTE *v3; // rbx
unsigned int v4; // ebp

v2 = calloc(0LL, 0x400uLL);
v3 = v2;
v4 = 0;
while ( 1 )
{
func5(sem, v3);
if ( !*v3 )
break;
++v4;
++v3;
if ( v4 == 1024 )
goto LABEL_5;
}
++v4;
LABEL_5:
*a2 = v2;
return v4;
}

original_code:
int shm_socket_read_str(shm_socket_t* sock, char** buf){
 char* chbuf = calloc(0,1024);
 int reading = 1;
 int i =0;
 while(reading && i < 1024){
  shm_socket_read_byte(sock,&chbuf[i]);
  if(chbuf[i]=='\0'){
   reading=0;
  }
  i++;
 }
 *buf = chbuf;
 return i;
}

canonical_original_code:
int shm_socket_read_str(struct shm_socket_t *sock, char **buf){
 char *chbuf = calloc(0,1024);
 int reading = 1;
 int i = 0;
 while(reading && i < 1024){
  shm_socket_read_byte(sock,&chbuf[i]);
  if(chbuf[i]=='\0'){
   reading=0;
  }
  i++;
 }
 *buf = chbuf;
 return i;
}

variable_types:
buf
char **


decompiled_code:
__int64 __fastcall shm_listen(__int64 a1)
{
do
sem_wait((sem_t *)(a1 + 32));
while ( *(_DWORD *)(a1 + 112) != 1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
do
sem_wait((sem_t *)(a1 + 32));
while ( *(_DWORD *)(a1 + 112) != 1 );
return 0LL;
}

original_code:
int shm_listen(shm_socket_t* sock){
 int listening = 1;
 int state = 0;
 while(listening){
  sem_wait(&(sock->full));
  if(sock->connected != 1){
   if(sock->sigclose == 1){
    state = 0;
   }
   else{
    state= 1;
   }
  }
  else{
   state =0;
   listening = 0;
  }
 }
 return state;
}

canonical_original_code:
int shm_listen(struct shm_socket_t *sock){
 int listening = 1;
 int state = 0;
 while(listening){
  sem_wait(&(sock->full));
  if(sock->connected != 1){
   if(sock->sigclose == 1){
    state = 0;
   }
   else{
    state= 1;
   }
  }
  else{
   state =0;
   listening = 0;
  }
 }
 return state;
}

variable_types: listening int

variable_types: state int


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

result = 0LL;
if ( *(_DWORD *)(a1 + 112) == 1 )
result = *(_DWORD *)(a1 + 116) != 1;
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 112) == 1 )
result = *(_DWORD *)(a1 + 116) != 1;
return result;
}

original_code:
int shm_is_connected(shm_socket_t* sock){
  int state = 0;
  if(sock->connected == 1){
   if(sock->sigclose == 1){
    state = 0;
   }
   else{
    state = 1;
   }
  }
  else{
   state = 0;
  }
  return state;
}

canonical_original_code:
int shm_is_connected(struct shm_socket_t *sock){
  int state = 0;
  if(sock->connected == 1){
   if(sock->sigclose == 1){
    state = 0;
   }
   else{
    state = 1;
   }
  }
  else{
   state = 0;
  }
  return state;
}


repo: cbeny/wavy

decompiled_code:
void __fastcall mouse_hook(__int64 a1, int a2)
{
if ( a2 )
{
if ( a2 == 1 && observe == 1 )
{
observe = 0;
hist_size = 0;
hist_ptr = 0;
}
}
else
{
observe = 1;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
if ( a2 )
{
if ( a2 == 1 && observe == 1 )
{
observe = 0;
hist_size = 0;
hist_ptr = 0;
}
}
else
{
observe = 1;
}
}

original_code:
void mouse_hook( int button, int state, int x, int y )
{
  if( state == 0x0000 ) observe = 1;
  if( state == 0x0001 && observe == 1 ) {
    observe = 0;
    hist_size = 0;
    hist_ptr = 0;
  }
}

canonical_original_code:
void mouse_hook(int button, int state, int x, int y)
{
  if( state == 0x0000 ) observe = 1;
  if( state == 0x0001 && observe == 1 ) {
    observe = 0;
    hist_size = 0;
    hist_ptr = 0;
  }
}

variable_types: button int

variable_types: x int

variable_types: y int


decompiled_code:
__int64 display_hook()
{
particle_represent(wave, pixmap, (unsigned int)disp_pot);
glTexImage2D(3553LL, 0LL, 6407LL, (unsigned int)wave[0], (unsigned int)wave[1], 0LL, 6407LL, 5121LL, pixmap);
glBegin(7LL);
glTexCoord2f(0.0);
glVertex2f(-1.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC2));
glVertex2f(1.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC2));
glVertex2f(1.0);
glTexCoord2f(0.0);
glVertex2f(-1.0);
glEnd(-1.0, 1.0);
glFlush();
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func1()
{
particle_represent(wave, pixmap, (unsigned int)disp_pot);
glTexImage2D(3553LL, 0LL, 6407LL, (unsigned int)wave[0], (unsigned int)wave[1], 0LL, 6407LL, 5121LL, pixmap);
glBegin(7LL);
glTexCoord2f(0.0);
glVertex2f(-1.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC2));
glVertex2f(1.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC2));
glVertex2f(1.0);
glTexCoord2f(0.0);
glVertex2f(-1.0);
glEnd(-1.0, 1.0);
glFlush();
return glutSwapBuffers();
}

original_code:
void display_hook() {
  particle_represent( &wave, pixmap, disp_pot );
  glTexImage2D( 0x0DE1, 0, 0x1907, wave.nx, wave.ny, 0, 0x1907, 0x1401, pixmap );
  glBegin( 0x0007 );
  glTexCoord2f( 0.0, 0.0 );
  glVertex2f( -1.0, -1.0 );
  glTexCoord2f( 1.0, 0.0 );
  glVertex2f( 1.0, -1.0 );
  glTexCoord2f( 1.0, 1.0 );
  glVertex2f( 1.0, 1.0 );
  glTexCoord2f( 0.0, 1.0 );
  glVertex2f( -1.0, 1.0 );
  glEnd();
  if( observe && disp_history ) {
    int i;
    double rx = 2.0 / wave.nx;
    double ry = 2.0 / wave.ny;
    glDisable( 0x0DE1 );
    glColor3f( 1.0, 1.0, 1.0);
    glBegin( 0x0003 );
    for( i = hist_ptr - hist_size; i < hist_ptr; i ++ ) {
      glVertex2f( history[ i % hist_max].x * rx - 1.0, history[ i % hist_max].y * ry- 1.0 );
    }
    glEnd();
    glEnable( 0x0DE1 );
  }
  glFlush();
  glutSwapBuffers();
}

variable_types: i int

variable_types: rx double

variable_types: ry double


decompiled_code:
__int64 update_time_step()
{
__int64 result; // rax
double v1; // xmm0_8
double v2; // xmm1_8
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v3, 0LL);
result = v3.tv_sec - realtime.tv_sec;
v1 = ((double)(LODWORD(v3.tv_usec) - LODWORD(realtime.tv_usec)) * 0.000001
+ (double)(LODWORD(v3.tv_sec) - LODWORD(realtime.tv_sec)))
* wave[18];
realtime = (struct timeval)_mm_loadu_si128((const __m128i *)&v3);
v2 = 0.0;
if ( v1 >= 0.0 )
v2 = fmin(wave[19], v1);
wave[8] = v2;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
double v1; // xmm0_8
double v2; // xmm1_8
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v3, 0LL);
result = v3.tv_sec - realtime.tv_sec;
v1 = ((double)(LODWORD(v3.tv_usec) - LODWORD(realtime.tv_usec)) * 0.000001
+ (double)(LODWORD(v3.tv_sec) - LODWORD(realtime.tv_sec)))
* wave[18];
realtime = (struct timeval)_mm_loadu_si128((const __m128i *)&v3);
v2 = 0.0;
if ( v1 >= 0.0 )
v2 = fmin(wave[19], v1);
wave[8] = v2;
return result;
}

original_code:
void update_time_step() {
  struct timeval now;
  gettimeofday( &now, 0 );
  wave.dt = (( now.tv_sec - realtime.tv_sec ) + ( now.tv_usec - realtime.tv_usec ) * 1e-6 ) * wave.time_unit;
  realtime = now;
  wave.dt = ( (wave.dt) < (0.0) ? (0.0) : (wave.dt) > (wave.max_dt) ? (wave.max_dt) : (wave.dt) );
}

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


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

if ( disp_pot )
{
gettimeofday(&v1, 0LL);
if ( (double)(LODWORD(v1.tv_usec) - LODWORD(disp_pot_time.tv_usec)) * 0.000001
+ (double)(LODWORD(v1.tv_sec) - LODWORD(disp_pot_time.tv_sec)) > 1.02 )
disp_pot = 0;
}
update_time_step();
if ( observe )
{
*(_QWORD *)(history + 8LL * (hist_ptr % hist_max)) = measure_position(wave, meas_fft, *(double *)&meas_sigma);
++hist_ptr;
if ( hist_size < hist_max )
++hist_size;
}
move_potential(wave);
particle_fourierize(wave);
move_kinetic(wave);
particle_unfourierize(wave);
return glutPostRedisplay();
}

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

if ( disp_pot )
{
gettimeofday(&v1, 0LL);
if ( (double)(LODWORD(v1.tv_usec) - LODWORD(disp_pot_time.tv_usec)) * 0.000001
+ (double)(LODWORD(v1.tv_sec) - LODWORD(disp_pot_time.tv_sec)) > 1.02 )
disp_pot = 0;
}
func3();
if ( observe )
{
*(_QWORD *)(history + 8LL * (hist_ptr % hist_max)) = measure_position(wave, meas_fft, *(double *)&meas_sigma);
++hist_ptr;
if ( hist_size < hist_max )
++hist_size;
}
move_potential(wave);
particle_fourierize(wave);
move_kinetic(wave);
particle_unfourierize(wave);
return glutPostRedisplay();
}

original_code:
void idle_hook() {
  if( disp_pot ) {
    struct timeval now;
    gettimeofday( &now, 0 );
    if(( now.tv_sec - disp_pot_time.tv_sec ) + ( now.tv_usec - disp_pot_time.tv_usec ) * 1e-6 > 1.02 ) {
      disp_pot = 0;
    }
  }
  update_time_step();
  if( observe ) {
    icoo pos = measure_position( &wave, meas_sigma, meas_fft );
    history[hist_ptr % hist_max] = pos;
    hist_ptr ++;
    if( hist_size < hist_max ) hist_size ++;
  }
  move_potential( &wave );
  particle_fourierize( &wave );
  move_kinetic( &wave );
  particle_unfourierize( &wave );
  glutPostRedisplay();
}

canonical_original_code:
void idle_hook() {
  if( disp_pot ) {
    struct timeval now;
    gettimeofday( &now, 0 );
    if(( now.tv_sec - disp_pot_time.tv_sec ) + ( now.tv_usec - disp_pot_time.tv_usec ) * 1e-6 > 1.02 ) {
      disp_pot = 0;
    }
  }
  update_time_step();
  if( observe ) {
    struct icoo pos = measure_position( &wave, meas_sigma, meas_fft );
    history[hist_ptr % hist_max] = pos;
    hist_ptr ++;
    if( hist_size < hist_max ) hist_size ++;
  }
  move_potential( &wave );
  particle_fourierize( &wave );
  move_kinetic( &wave );
  particle_unfourierize( &wave );
  glutPostRedisplay();
}

variable_types:
pos
struct icoo { int x; }

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


decompiled_code:
char *__fastcall get_device(const char *a1)
{
int *v1; // rbp
int v2; // eax
char *v3; // rbx
char *v4; // rbp
char v6[8192]; // [rsp+0h] [rbp-4018h] BYREF
char s[8216]; // [rsp+2000h] [rbp-2018h] BYREF

v1 = _errno_location();
*v1 = 0;
snprintf(s, 0x2000uLL, "/sys/class/video4linux/%s", a1);
v2 = readlink(s, v6, 0x2000uLL);
if ( v2 < 0 || v2 == 0x2000 )
return 0LL;
v3 = 0LL;
if ( !*v1 )
{
v6[v2] = 0;
v4 = basename(v6);
v3 = (char *)malloc(0x400uLL);
if ( snprintf(v3, 0x400uLL, "/dev/%s", v4) > 1023 )
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
int *v1; // rbp
int v2; // eax
char *v3; // rbx
char *v4; // rbp
char v6[8192]; // [rsp+0h] [rbp-4018h] BYREF
char s[8216]; // [rsp+2000h] [rbp-2018h] BYREF

v1 = _errno_location();
*v1 = 0;
snprintf(s, 0x2000uLL, "/sys/class/video4linux/%s", a1);
v2 = readlink(s, v6, 0x2000uLL);
if ( v2 < 0 || v2 == 0x2000 )
return 0LL;
v3 = 0LL;
if ( !*v1 )
{
v6[v2] = 0;
v4 = basename(v6);
v3 = (char *)malloc(0x400uLL);
if ( snprintf(v3, 0x400uLL, "/dev/%s", v4) > 1023 )
v3 = 0LL;
}
return v3;
}

original_code:
static char *
get_device (const char *fname)
{
 char path[8192], target[8192];
 int s, ret;
 char *bname, *device;
 (*__errno_location ()) = 0;
 snprintf (path, 8192, "/sys/class/video4linux/%s", fname);
 ret = readlink (path, target, 8192);
 if (ret < 0 || ret == 8192 || (*__errno_location ()))
  return ((void *)0);
 target[ret] = '\0';
 bname = basename (target);
 device = (char *) malloc (1024 * sizeof (char));
 s = snprintf (device, 1024, "/dev/%s", bname);
 if (s >= 1024)
  return ((void *)0);
 return device;
}

canonical_original_code:
static char *get_device(char *fname)
{
 char path[8192]; char target[8192];
 int s; int ret;
 char *bname; char *device;
 (*__errno_location ()) = 0;
 snprintf (path, 8192, "/sys/class/video4linux/%s", fname);
 ret = readlink (path, target, 8192);
 if (ret < 0 || ret == 8192 || (*__errno_location ()))
  return ((void *)0);
 target[ret] = '\0';
 bname = basename (target);
 device = (char *) malloc (1024 * sizeof (char));
 s = snprintf (device, 1024, "/dev/%s", bname);
 if (s >= 1024)
  return ((void *)0);
 return device;
}

variable_types:
fname
char *

variable_types:
path
char [8192]

variable_types:
target
char [8192]

variable_types: s int

variable_types: ret int

variable_types:
bname
char *

variable_types:
device
char *

return_type: char *


decompiled_code:
__int64 __fastcall v4l2_mfc_querycap(int a1)
{
unsigned int v1; // ebx
__int64 v3; // [rsp+0h] [rbp-78h] BYREF
int v4; // [rsp+54h] [rbp-24h]

v1 = ioctl(a1, 0x80685600uLL, &v3);
if ( v1 )
{
perror("VIDIOC_QUERYCAP failed: ");
}
else if ( (v4 & 0x1000) != 0 )
{
if ( (v4 & 0x2000) != 0 )
{
if ( (v4 & 0x4000000) == 0 )
{
fwrite("Device does not support streaming\n", 1uLL, 0x22uLL, stderr);
v1 = -1;
}
}
else
{
fwrite("Device does not support output\n", 1uLL, 0x1FuLL, stderr);
v1 = -1;
}
}
else
{
fwrite("Device does not support capture\n", 1uLL, 0x20uLL, stderr);
v1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // ebx
__int64 v3; // [rsp+0h] [rbp-78h] BYREF
int v4; // [rsp+54h] [rbp-24h]

v1 = ioctl(a1, 0x80685600uLL, &v3);
if ( v1 )
{
perror("VIDIOC_QUERYCAP failed: ");
}
else if ( (v4 & 0x1000) != 0 )
{
if ( (v4 & 0x2000) != 0 )
{
if ( (v4 & 0x4000000) == 0 )
{
fwrite("Device does not support streaming\n", 1uLL, 0x22uLL, stderr);
v1 = -1;
}
}
else
{
fwrite("Device does not support output\n", 1uLL, 0x1FuLL, stderr);
v1 = -1;
}
}
else
{
fwrite("Device does not support capture\n", 1uLL, 0x20uLL, stderr);
v1 = -1;
}
return v1;
}

original_code:
int
v4l2_mfc_querycap (int fd)
{
 int ret;
 struct v4l2_capability cap;
 ret = ioctl (fd, (((2U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((0)) << 0) | ((((sizeof(struct v4l2_capability)))) << ((0 +8)+8))), &cap);
 if (ret != 0) {
  perror ("VIDIOC_QUERYCAP failed: ");
  return ret;
 }
 if (!(cap.capabilities & 0x00001000)) {
  fprintf (stderr, "Device does not support capture\n");
  return -1;
 }
 if (!(cap.capabilities & 0x00002000)) {
  fprintf (stderr, "Device does not support output\n");
  return -1;
 }
 if (!(cap.capabilities & 0x04000000)) {
  fprintf (stderr, "Device does not support streaming\n");
  return -1;
 }
 return 0;
}

canonical_original_code:
int v4l2_mfc_querycap(int fd)
{
 int ret;
 struct v4l2_capability cap;
 ret = ioctl (fd, (((2U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((0)) << 0) | ((((sizeof(struct v4l2_capability)))) << ((0 +8)+8))), &cap);
 if (ret != 0) {
  perror ("VIDIOC_QUERYCAP failed: ");
  return ret;
 }
 if (!(cap.capabilities & 0x00001000)) {
  fprintf (stderr, "Device does not support capture\n");
  return -1;
 }
 if (!(cap.capabilities & 0x00002000)) {
  fprintf (stderr, "Device does not support output\n");
  return -1;
 }
 if (!(cap.capabilities & 0x04000000)) {
  fprintf (stderr, "Device does not support streaming\n");
  return -1;
 }
 return 0;
}

variable_types: fd int

variable_types: struct v4l2_capability { unsigned char driver[16]; unsigned char card[32]; unsigned char bus_info[32]; unsigned int version; unsigned int capabilities; unsigned int device_caps; unsigned int reserved[3]; }


decompiled_code:
int __fastcall v4l2_mfc_reqbufs(int a1, int a2, int a3, int *a4)
{
int result; // eax
int v6[3]; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+Ch] [rbp-1Ch]

v7 = 0LL;
v6[0] = *a4;
v6[1] = a2;
v6[2] = a3;
result = ioctl(a1, 0xC0145608uLL, v6);
*a4 = v6[0];
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, int a2, int a3, int *a4)
{
int result; // eax
int v6[3]; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+Ch] [rbp-1Ch]

v7 = 0LL;
v6[0] = *a4;
v6[1] = a2;
v6[2] = a3;
result = ioctl(a1, 0xC0145608uLL, v6);
*a4 = v6[0];
return result;
}

original_code:
int
v4l2_mfc_reqbufs (int fd,
    enum v4l2_buf_type type,
    enum v4l2_memory memory,
    uint32_t *buf_cnt)
{
 int ret;
 struct v4l2_requestbuffers reqbuf = {
  .type = type,
  .memory = memory,
  .count = *buf_cnt,
 };
 ret = ioctl (fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((8)) << 0) | ((((sizeof(struct v4l2_requestbuffers)))) << ((0 +8)+8))), &reqbuf);
 *buf_cnt = reqbuf.count;
 return ret;
}

canonical_original_code:
int v4l2_mfc_reqbufs(int fd, enum v4l2_buf_type type, enum v4l2_memory memory, unsigned int *buf_cnt)
{
 int ret;
 struct v4l2_requestbuffers reqbuf = {
  .type = type,
  .memory = memory,
  .count = *buf_cnt,
 };
 ret = ioctl (fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((8)) << 0) | ((((sizeof(struct v4l2_requestbuffers)))) << ((0 +8)+8))), &reqbuf);
 *buf_cnt = reqbuf.count;
 return ret;
}

variable_types: enum v4l2_buf_type { V4L2_BUF_TYPE_VIDEO_CAPTURE=1, V4L2_BUF_TYPE_VIDEO_OUTPUT=2, V4L2_BUF_TYPE_VIDEO_OVERLAY=3, V4L2_BUF_TYPE_VBI_CAPTURE=4, V4L2_BUF_TYPE_VBI_OUTPUT=5, V4L2_BUF_TYPE_SLICED_VBI_CAPTURE=6, V4L2_BUF_TYPE_SLICED_VBI_OUTPUT=7, V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY=8, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE=9, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE=10, V4L2_BUF_TYPE_SDR_CAPTURE=11, V4L2_BUF_TYPE_SDR_OUTPUT=12, V4L2_BUF_TYPE_META_CAPTURE=13, V4L2_BUF_TYPE_PRIVATE=128 }

variable_types: enum v4l2_memory { V4L2_MEMORY_MMAP=1, V4L2_MEMORY_USERPTR=2, V4L2_MEMORY_OVERLAY=3, V4L2_MEMORY_DMABUF=4 }

variable_types: struct v4l2_requestbuffers { unsigned int count; unsigned int type; unsigned int memory; unsigned int reserved[2]; }


decompiled_code:
int __fastcall v4l2_mfc_streamon(int a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return ioctl(a1, 0x40045612uLL, v3);
}

canonical_decompiled_code:
int __fastcall func4(int a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return ioctl(a1, 0x40045612uLL, v3);
}

user_defined_types: enum v4l2_buf_type { V4L2_BUF_TYPE_VIDEO_CAPTURE=1, V4L2_BUF_TYPE_VIDEO_OUTPUT=2, V4L2_BUF_TYPE_VIDEO_OVERLAY=3, V4L2_BUF_TYPE_VBI_CAPTURE=4, V4L2_BUF_TYPE_VBI_OUTPUT=5, V4L2_BUF_TYPE_SLICED_VBI_CAPTURE=6, V4L2_BUF_TYPE_SLICED_VBI_OUTPUT=7, V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY=8, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE=9, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE=10, V4L2_BUF_TYPE_SDR_CAPTURE=11, V4L2_BUF_TYPE_SDR_OUTPUT=12, V4L2_BUF_TYPE_META_CAPTURE=13, V4L2_BUF_TYPE_PRIVATE=128 }


decompiled_code:
int __fastcall v4l2_mfc_streamoff(int a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return ioctl(a1, 0x40045613uLL, v3);
}

canonical_decompiled_code:
int __fastcall func5(int a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return ioctl(a1, 0x40045613uLL, v3);
}


decompiled_code:
int __fastcall v4l2_mfc_poll(int a1, _DWORD *a2, int a3)
{
int result; // eax
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

fds.fd = a1;
fds.events = 12;
fds.revents = 0;
result = poll(&fds, 1uLL, a3);
*a2 = fds.revents;
return result;
}

canonical_decompiled_code:
int __fastcall func12(int a1, _DWORD *a2, int a3)
{
int result; // eax
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

fds.fd = a1;
fds.events = 12;
fds.revents = 0;
result = poll(&fds, 1uLL, a3);
*a2 = fds.revents;
return result;
}

original_code:
int
v4l2_mfc_poll (int fd,
        int *revents,
        int timeout)
{
    int ret;
    struct pollfd poll_events = {
     .fd = fd,
     .events = 0x004 | 0x008,
     .revents = 0,
    };
    ret = poll ((struct pollfd*) &poll_events, 1, timeout);
    *revents = poll_events.revents;
    return ret;
}

canonical_original_code:
int v4l2_mfc_poll(int fd, int *revents, int timeout)
{
    int ret;
    struct pollfd poll_events = {
     .fd = fd,
     .events = 0x004 | 0x008,
     .revents = 0,
    };
    ret = poll ((struct pollfd *) &poll_events, 1, timeout);
    *revents = poll_events.revents;
    return ret;
}

variable_types:
revents
int *

variable_types: timeout int

variable_types: struct pollfd { int fd; short events; short revents; }


decompiled_code:
__int64 __fastcall waveform_db_open(const char *a1)
{
__int64 result; // rax
const char *v2; // rax
__int64 v3[2]; // [rsp+0h] [rbp-418h] BYREF
char v4[1008]; // [rsp+10h] [rbp-408h] BYREF

sqlite3_close(db);
v3[0] = 0LL;
v3[1] = 0LL;
memset(v4, 0, sizeof(v4));
snprintf((char *)v3, 0x400uLL, "%s/%s", a1, "wavecache.db");
result = sqlite3_open(v3, &db);
if ( (_DWORD)result )
{
v2 = (const char *)sqlite3_errmsg(db);
fprintf(stderr, "Can't open database: %s\n", v2);
result = sqlite3_close(db);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
__int64 result; // rax
const char *v2; // rax
__int64 v3[2]; // [rsp+0h] [rbp-418h] BYREF
char v4[1008]; // [rsp+10h] [rbp-408h] BYREF

sqlite3_close(db);
v3[0] = 0LL;
v3[1] = 0LL;
memset(v4, 0, sizeof(v4));
snprintf((char *)v3, 0x400uLL, "%s/%s", a1, "wavecache.db");
result = sqlite3_open(v3, &db);
if ( (_DWORD)result )
{
v2 = (const char *)sqlite3_errmsg(db);
fprintf(stderr, "Can't open database: %s\n", v2);
result = sqlite3_close(db);
}
return result;
}

original_code:
void
waveform_db_open (const char* path)
{
    sqlite3_close(db);
    char db_path[1024] = "";
    snprintf (db_path, sizeof(db_path)/sizeof (char), "%s/%s", path, "wavecache.db");
    int rc = sqlite3_open(db_path, &db);
    if (rc) {
        fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
        return;
    }
}

canonical_original_code:
void waveform_db_open(char *path)
{
    sqlite3_close(db);
    char db_path[1024] = "";
    snprintf (db_path, sizeof(db_path)/sizeof (char), "%s/%s", path, "wavecache.db");
    int rc = sqlite3_open(db_path, &db);
    if (rc) {
        fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
        return;
    }
}

variable_types:
path
char *

variable_types: rc int


decompiled_code:
__int64 waveform_db_close()
{
return sqlite3_close(db);
}

canonical_decompiled_code:
__int64 func1()
{
return sqlite3_close(db);
}

original_code:
void
waveform_db_close ()
{
    sqlite3_close(db);
}

canonical_original_code:
void waveform_db_close()
{
    sqlite3_close(db);
}


decompiled_code:
__int64 waveform_db_init()
{
const char *v1; // [rsp+8h] [rbp-10h] BYREF

v1 = 0LL;
if ( (unsigned int)sqlite3_exec(
db,
"CREATE TABLE IF NOT EXISTS wave ( path TEXT PRIMARY KEY NOT NULL, channels INTEGER NOT NULL, comp"
"ression INTEGER, data BLOB)",
0LL,
0LL,
&v1) )
fprintf(stderr, "SQL error: %s\n", v1);
return sqlite3_free(v1);
}

canonical_decompiled_code:
__int64 func2()
{
const char *v1; // [rsp+8h] [rbp-10h] BYREF

v1 = 0LL;
if ( (unsigned int)sqlite3_exec(
db,
"CREATE TABLE IF NOT EXISTS wave ( path TEXT PRIMARY KEY NOT NULL, channels INTEGER NOT NULL, comp"
"ression INTEGER, data BLOB)",
0LL,
0LL,
&v1) )
fprintf(stderr, "SQL error: %s\n", v1);
return sqlite3_free(v1);
}

original_code:
void
waveform_db_init (char const *fname)
{
    char *zErrMsg = 0;
    int rc;
    char *query = "CREATE TABLE IF NOT EXISTS wave ( path TEXT PRIMARY KEY NOT NULL, channels INTEGER NOT NULL, compression INTEGER, data BLOB)";
    rc = sqlite3_exec(db, query, ((void *)0), 0, &zErrMsg);
    if (rc != 0) {
        fprintf(stderr, "SQL error: %s\n", zErrMsg);
    }
    sqlite3_free(zErrMsg);
}

canonical_original_code:
void waveform_db_init(char *fname)
{
    char *zErrMsg = 0;
    int rc;
    char *query = "CREATE TABLE IF NOT EXISTS wave ( path TEXT PRIMARY KEY NOT NULL, channels INTEGER NOT NULL, compression INTEGER, data BLOB)";
    rc = sqlite3_exec(db, query, ((void *)0), 0, &zErrMsg);
    if (rc != 0) {
        fprintf(stderr, "SQL error: %s\n", zErrMsg);
    }
    sqlite3_free(zErrMsg);
}

variable_types:
fname
char *

variable_types:
zErrMsg
char *

variable_types:
query
char *


repo: cbrake/snippets

decompiled_code:
int timer_handler()
{
return puts("timer_handler");
}

canonical_decompiled_code:
int func7()
{
return puts("timer_handler");
}

original_code:
void timer_handler(int sig)
{
 printf("timer_handler\n");
}

variable_types: sig int


matches

decompiled_code:
__int64 __fastcall matches(char *s2, char *s)
{
int v2; // edx
__int64 result; // rax
char *i; // rbp
char *v5; // rbx

v2 = strcmp(s2, s);
result = 1LL;
if ( v2 )
{
for ( i = s; ; i = v5 + 1 )
{
v5 = strchr(i, 124);
if ( !v5 )
{
if ( i == s )
return 0LL;
v5 = &i[strlen(s)];
}
if ( !strncmp(i, s2, v5 - i) )
return 1LL;
if ( !*v5 )
break;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s2, char *s)
{
int v2; // edx
__int64 result; // rax
char *i; // rbp
char *v5; // rbx

v2 = strcmp(s2, s);
result = 1LL;
if ( v2 )
{
for ( i = s; ; i = v5 + 1 )
{
v5 = strchr(i, 124);
if ( !v5 )
{
if ( i == s )
return 0LL;
v5 = &i[strlen(s)];
}
if ( !strncmp(i, s2, v5 - i) )
return 1LL;
if ( !*v5 )
break;
}
result = 0LL;
}
return result;
}

original_code:
static int matches( const char *actualType, const char *expectedTypes) {
    const char *p = expectedTypes;
    if( ! strcmp( actualType, expectedTypes)) return 1;
    while( 1) {
        const char *q = strchr( p, '|');
        if( ! q) {
            if( p == expectedTypes) return 0;
            else q = p+strlen( expectedTypes);
        }
        if( ! strncmp( p, actualType, q-p)) return 1;
        if( ! *q) return 0; else p = q+1;
    };
}

canonical_original_code:
static int matches(char *actualType, char *expectedTypes) {
    char *p = expectedTypes;
    if( ! strcmp( actualType, expectedTypes)) return 1;
    while( 1) {
        char *q = strchr( p, '|');
        if( ! q) {
            if( p == expectedTypes) return 0;
            else q = p+strlen( expectedTypes);
        }
        if( ! strncmp( p, actualType, q-p)) return 1;
        if( ! *q) return 0; else p = q+1;
    };
}

variable_types:
actualType
char *

variable_types:
expectedTypes
char *

variable_types:
p
char *

variable_types:
q
char *


drawingBloc

repo: cchampet/Arkanopong

decompiled_code:
__int64 drawingBloc()
{
glBegin(7LL);
glTexCoord2f(1.0, 0.0);
glVertex2f(1.0, 0.0);
glTexCoord2f(1.0, COERCE_DOUBLE((unsigned __int64)LC1));
glVertex2f(1.0, COERCE_DOUBLE((unsigned __int64)LC2));
glTexCoord2f(0.0, COERCE_DOUBLE((unsigned __int64)LC1));
glVertex2f(0.0, COERCE_DOUBLE((unsigned __int64)LC2));
glTexCoord2f(0.0, 0.0);
glVertex2f(0.0, 0.0);
return glEnd();
}

canonical_decompiled_code:
__int64 func0()
{
glBegin(7LL);
glTexCoord2f(1.0, 0.0);
glVertex2f(1.0, 0.0);
glTexCoord2f(1.0, COERCE_DOUBLE((unsigned __int64)LC1));
glVertex2f(1.0, COERCE_DOUBLE((unsigned __int64)LC2));
glTexCoord2f(0.0, COERCE_DOUBLE((unsigned __int64)LC1));
glVertex2f(0.0, COERCE_DOUBLE((unsigned __int64)LC2));
glTexCoord2f(0.0, 0.0);
glVertex2f(0.0, 0.0);
return glEnd();
}

original_code:
void drawingBloc() {
 glBegin(0x0007);
 glTexCoord2f(1., 0.);
 glVertex2f(1., 0.);
 glTexCoord2f(1., 1.);
 glVertex2f(1., -1.);
 glTexCoord2f(0., 1.);
 glVertex2f(0., -1.);
 glTexCoord2f(0., 0.);
 glVertex2f(0., 0.);
 glEnd();
}


drawingBall

decompiled_code:
__int64 drawingBall()
{
int i; // ebx
__m128i v1; // xmm0
__m128i v2; // xmm2
double v4; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

glBegin(9LL);
for ( i = 0; i != 200; i += 2 )
{
sincos((double)i * 3.14 / 100.0, sinx, &v4);
v1 = 0LL;
*(float *)v1.m128i_i32 = v4;
v2 = 0LL;
*(float *)v2.m128i_i32 = sinx[0];
glTexCoord2f(*(float *)v1.m128i_i32, *(double *)v2.m128i_i64);
glVertex2f(
*(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v1)).m128i_i64,
*(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v2)).m128i_i64);
}
return glEnd();
}

original_code:
void drawingBall() {
 glBegin(0x0009);
 int nbDivisionCircle = 100;
 int i;
 float x, y;
 for(i=0; i < nbDivisionCircle; i++) {
  x = cos(i * 2 * 3.14/nbDivisionCircle);
  y = sin(i * 2 * 3.14/nbDivisionCircle);
  glTexCoord2f(x, y);
  glVertex2f(x, y);
 }
 glEnd();
}

canonical_original_code:
void drawingBall() {
 glBegin(0x0009);
 int nbDivisionCircle = 100;
 int i;
 float x; float y;
 for(i=0; i < nbDivisionCircle; i++) {
  x = cos(i * 2 * 3.14/nbDivisionCircle);
  y = sin(i * 2 * 3.14/nbDivisionCircle);
  glTexCoord2f(x, y);
  glVertex2f(x, y);
 }
 glEnd();
}

variable_types: nbDivisionCircle int

variable_types: i int

variable_types: x float

variable_types: y float


ProjectionSurSegment

decompiled_code:
_BOOL8 __fastcall ProjectionSurSegment(float a1, float a2, float a3, float a4, float a5, float a6)
{
return (int)(float)((float)((float)(a2 - a6) * (float)(a6 - a4))
+ (float)(int)(float)((float)(a1 - a5) * (float)(a5 - a3)))
* (int)(float)((float)((float)(a2 - a4) * (float)(a6 - a4))
+ (float)(int)(float)((float)(a1 - a3) * (float)(a5 - a3))) <= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(float a1, float a2, float a3, float a4, float a5, float a6)
{
return (int)(float)((float)((float)(a2 - a6) * (float)(a6 - a4))
+ (float)(int)(float)((float)(a1 - a5) * (float)(a5 - a3)))
* (int)(float)((float)((float)(a2 - a4) * (float)(a6 - a4))
+ (float)(int)(float)((float)(a1 - a3) * (float)(a5 - a3))) <= 0;
}

original_code:
int ProjectionSurSegment(float Cx, float Cy, float Ax, float Ay, float Bx, float By) {
   float ACx = Cx-Ax;
   float ACy = Cy-Ay;
   float ABx = Bx-Ax;
   float ABy = By-Ay;
   float BCx = Cx-Bx;
   float BCy = Cy-By;
   int s1 = (int)(ACx*ABx) + (ACy*ABy);
   int s2 = (int)(BCx*ABx) + (BCy*ABy);
   if (s1*s2>0)
     return 0;
   return 1;
}

variable_types: Cx float

variable_types: Cy float

variable_types: Ax float

variable_types: Ay float

variable_types: Bx float

variable_types: By float

variable_types: ACx float

variable_types: ACy float

variable_types: ABx float

variable_types: ABy float

variable_types: BCx float

variable_types: BCy float


repo: cclinus/Ethernet-Switch-Simulator

decompiled_code:
_QWORD *switch_table_create()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
result[1] = 0LL;
return result;
}

original_code:
switch_table switch_table_create(void) {
    switch_table new = (switch_table) malloc(sizeof(struct switch_table));
    new->next = ((void *)0);
    return new;
}

canonical_original_code:
struct switch_table *switch_table_create() {
    struct switch_table *new = (switch_table) malloc(sizeof(struct switch_table));
    new->next = ((void *)0);
    return new;
}

variable_types: struct switch_table { unsigned int port; unsigned int addr; struct switch_table *next; } *


decompiled_code:
_QWORD *forwarding_status_create()
{
_QWORD *result; // rax

result = malloc(0x30uLL);
result[5] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *result; // rax

result = malloc(0x30uLL);
result[5] = 0LL;
return result;
}

original_code:
forwarding_status forwarding_status_create(void) {
    forwarding_status new = (forwarding_status) malloc(sizeof(struct forwarding_status));
    new->next = ((void *)0);
    return new;
}

canonical_original_code:
struct forwarding_status *forwarding_status_create() {
    struct forwarding_status *new = (forwarding_status) malloc(sizeof(struct forwarding_status));
    new->next = ((void *)0);
    return new;
}

variable_types: struct forwarding_status { int port_decs[8]; unsigned int frame_id; struct forwarding_status *next; } *


original_code:
void forwarding_status_insert(switch_state *state, unsigned int dport, unsigned int sport, unsigned int frame_id) {
    forwarding_status head = state->p1.status;
    forwarding_status new = forwarding_status_create();
    new->frame_id = frame_id;
    new->next = ((void *)0);
    if(dport >= 0 && dport < 8){
 if(dport == sport){
     for(int i=0; i< 8; i++){
  new->port_decs[i] = 0;
     }
 }else{
     for(int i=0; i < 8; i++){
  if( i == dport ){
      new->port_decs[i] = 1;
      *(state->p1.port_status + i) += 1;
  }else{
      new->port_decs[i] = 0;
  }
     }
 }
    }else if(dport == 8){
 for(int i=0; i < 8; i++){
     if(i == sport){
  new->port_decs[i] = 0;
     }else{
  new->port_decs[i] = 1;
  *(state->p1.port_status + i) += 1;
     }
 }
    }
    forwarding_status temp = head;
    if(head==((void *)0)){ state->p1.status = new;}
    else{
 while(head->next!=((void *)0)){
     head = head->next;
 }
 head->next = new;
 state->p1.status = temp;
    }
}

canonical_original_code:
void forwarding_status_insert(union switch_state *state, unsigned int dport, unsigned int sport, unsigned int frame_id) {
    struct forwarding_status *head = state->p1.status;
    struct forwarding_status *new = forwarding_status_create();
    new->frame_id = frame_id;
    new->next = ((void *)0);
    if(dport >= 0 && dport < 8){
 if(dport == sport){
     for(int i = 0; i< 8; i++){
  new->port_decs[i] = 0;
     }
 }else{
     for(int i = 0; i < 8; i++){
  if( i == dport ){
      new->port_decs[i] = 1;
      *(state->p1.port_status + i) += 1;
  }else{
      new->port_decs[i] = 0;
  }
     }
 }
    }else if(dport == 8){
 for(int i = 0; i < 8; i++){
     if(i == sport){
  new->port_decs[i] = 0;
     }else{
  new->port_decs[i] = 1;
  *(state->p1.port_status + i) += 1;
     }
 }
    }
    struct forwarding_status *temp = head;
    if(head==((void *)0)){ state->p1.status = new;}
    else{
 while(head->next!=((void *)0)){
     head = head->next;
 }
 head->next = new;
 state->p1.status = temp;
    }
}

variable_types: union switch_state { struct switch_state_p1 { struct switch_table { unsigned int port; unsigned int addr; struct switch_table *next; } *table; struct forwarding_status { int port_decs[8]; unsigned int frame_id; struct forwarding_status *next; } *status; int *port_status; } p1; struct switch_state_p2 { int current_size; struct buffer { unsigned int frame_id; struct buffer *next; } *buffer; } p2; struct switch_state_p3 { struct buffer *buffers[8]; int ports_size[8]; struct switch_table *table; } p3; } *

variable_types:
dport
unsigned int

variable_types:
sport
unsigned int

variable_types: i int

user_defined_types: union switch_state { struct switch_state_p1 p1; struct switch_state_p2 p2; struct switch_state_p3 p3; }

user_defined_types: struct switch_state_p1 { struct switch_table *table; struct forwarding_status *status; int *port_status; }

user_defined_types: struct switch_state_p2 { int current_size; struct buffer *buffer; }


decompiled_code:
void *initialize_ports_status()
{
return malloc(0x20uLL);
}

canonical_decompiled_code:
void *func4()
{
return malloc(0x20uLL);
}

original_code:
int * initialize_ports_status(void) {
    int *ports_status = (int *) malloc(8*sizeof(int));
    return ports_status;
}

canonical_original_code:
int *initialize_ports_status() {
    int *ports_status = (int *) malloc(8*sizeof(int));
    return ports_status;
}

return_type: int *


decompiled_code:
__int64 __fastcall update_output_ports(unsigned int **a1, int a2, int a3, int a4)
{
unsigned int v5; // eax

v5 = is_dest_addr_in_table(a1, a3);
return forwarding_status_insert((__int64)a1, v5, a2, a4);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int **a1, int a2, int a3, int a4)
{
unsigned int v5; // eax

v5 = func6(a1, a3);
return func3((__int64)a1, v5, a2, a4);
}

original_code:
void update_output_ports(switch_state *state, unsigned int port, unsigned int dest_addr, unsigned int frame_id) {
    unsigned int dport = is_dest_addr_in_table(state,dest_addr);
    forwarding_status_insert(state, dport, port, frame_id);
}

canonical_original_code:
void update_output_ports(union switch_state *state, unsigned int port, unsigned int dest_addr, unsigned int frame_id) {
    unsigned int dport = is_dest_addr_in_table(state,dest_addr);
    forwarding_status_insert(state, dport, port, frame_id);
}

variable_types:
port
unsigned int

user_defined_types: struct switch_state_p3 { struct buffer *buffers[8]; int ports_size[8]; struct switch_table *table; }

user_defined_types: struct switch_table { unsigned int port; unsigned int addr; struct switch_table *next; }

user_defined_types: struct forwarding_status { int port_decs[8]; unsigned int frame_id; struct forwarding_status *next; }

user_defined_types: struct buffer { unsigned int frame_id; struct buffer *next; }


decompiled_code:
int print_ports_status_title()
{
unsigned int i; // ebx

for ( i = 0; i != 8; ++i )
printf("P%d ", i);
printf("FRAME_ID");
return putchar(10);
}

canonical_decompiled_code:
int func11()
{
unsigned int i; // ebx

for ( i = 0; i != 8; ++i )
printf("P%d ", i);
printf("FRAME_ID");
return putchar(10);
}

original_code:
void print_ports_status_title() {
    for (int i=0; i<8; i++) {
 printf("P%d  ", i);
    }
    printf("FRAME_ID");
    printf("\n");
}

canonical_original_code:
void print_ports_status_title() {
    for (int i = 0; i<8; i++) {
 printf("P%d  ", i);
    }
    printf("FRAME_ID");
    printf("\n");
}


decompiled_code:
int __fastcall print_forwarding_status(__int64 a1)
{
__int64 i; // r12
_DWORD *v2; // rbx
int result; // eax

for ( i = a1; i; i = *(_QWORD *)(i + 40) )
{
v2 = (_DWORD *)i;
do
{
if ( *v2 )
printf(" + ");
else
printf(" ^ ");
++v2;
}
while ( v2 != (_DWORD *)(i + 32) );
printf("%03u", *(unsigned int *)(i + 32));
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
__int64 i; // r12
_DWORD *v2; // rbx
int result; // eax

for ( i = a1; i; i = *(_QWORD *)(i + 40) )
{
v2 = (_DWORD *)i;
do
{
if ( *v2 )
printf(" + ");
else
printf(" ^ ");
++v2;
}
while ( v2 != (_DWORD *)(i + 32) );
printf("%03u", *(unsigned int *)(i + 32));
result = putchar(10);
}
return result;
}

original_code:
void print_forwarding_status(forwarding_status head) {
    if(head==((void *)0)) return;
    while (head!=((void *)0)) {
 for (int i=0; i<8; i++) {
     if(head->port_decs[i] == 0) printf(" ^  ");
     else printf(" +  ");
 }
 printf("%03u", head->frame_id);
 printf("\n");
 head = head->next;
    }
}

canonical_original_code:
void print_forwarding_status(struct forwarding_status *head) {
    if(head==((void *)0)) return;
    while (head!=((void *)0)) {
 for (int i = 0; i<8; i++) {
     if(head->port_decs[i] == 0) printf(" ^  ");
     else printf(" +  ");
 }
 printf("%03u", head->frame_id);
 printf("\n");
 head = head->next;
    }
}


decompiled_code:
int __fastcall print_ports_status(__int64 a1)
{
unsigned int *v1; // rbx
unsigned int *v2; // rbp

v1 = *(unsigned int **)(a1 + 16);
v2 = v1 + 8;
do
printf(" %d ", *v1++);
while ( v1 != v2 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
unsigned int *v1; // rbx
unsigned int *v2; // rbp

v1 = *(unsigned int **)(a1 + 16);
v2 = v1 + 8;
do
printf(" %d ", *v1++);
while ( v1 != v2 );
return putchar(10);
}

original_code:
void print_ports_status(switch_state *state) {
    int *ports_status = state->p1.port_status;
    for (int i=0; i<8; i++) {
 printf(" %d  ", *(ports_status+i));
    }
    printf("\n");
}

canonical_original_code:
void print_ports_status(union switch_state *state) {
    int *ports_status = state->p1.port_status;
    for (int i = 0; i<8; i++) {
 printf(" %d  ", *(ports_status+i));
    }
    printf("\n");
}


decompiled_code:
void __fastcall destroy_forwarding_status(void *ptr)
{
_QWORD *v1; // rbx

if ( ptr )
{
v1 = (_QWORD *)*((_QWORD *)ptr + 5);
if ( v1 )
{
while ( 1 )
{
free(ptr);
ptr = v1;
if ( !v1[5] )
break;
v1 = (_QWORD *)v1[5];
}
}
else
{
v1 = ptr;
}
free(v1);
}
}

canonical_decompiled_code:
void __fastcall func18(void *ptr)
{
_QWORD *v1; // rbx

if ( ptr )
{
v1 = (_QWORD *)*((_QWORD *)ptr + 5);
if ( v1 )
{
while ( 1 )
{
free(ptr);
ptr = v1;
if ( !v1[5] )
break;
v1 = (_QWORD *)v1[5];
}
}
else
{
v1 = ptr;
}
free(v1);
}
}

original_code:
void destroy_forwarding_status(forwarding_status status) {
    if(status==((void *)0)) return;
    forwarding_status temp = status;
    while (status->next!=((void *)0)) {
 temp = status->next;
 free(status);
 status = temp;
    }
    free(status);
}

canonical_original_code:
void destroy_forwarding_status(struct forwarding_status *status) {
    if(status==((void *)0)) return;
    struct forwarding_status *temp = status;
    while (status->next!=((void *)0)) {
 temp = status->next;
 free(status);
 status = temp;
    }
    free(status);
}


decompiled_code:
_QWORD *buffer_create()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
result[1] = 0LL;
return result;
}

original_code:
buffer buffer_create(void) {
 buffer new = (buffer) malloc(sizeof(struct buffer));
 new->next = ((void *)0);
 return new;
}

canonical_original_code:
struct buffer *buffer_create() {
 struct buffer *new = (buffer) malloc(sizeof(struct buffer));
 new->next = ((void *)0);
 return new;
}

variable_types: struct buffer { unsigned int frame_id; struct buffer *next; } *


canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
result[1] = 0LL;
return result;
}

return_type: struct switch_table { unsigned int port; unsigned int addr; struct switch_table *next; } *


decompiled_code:
int __fastcall print_bufferstatue(__int64 a1)
{
__int64 i; // rax
int v2; // er12
__int64 j; // rbx
unsigned int *v4; // rbp
int result; // eax
__int64 v6[11]; // [rsp+0h] [rbp-58h]

for ( i = 0LL; i != 8; ++i )
v6[i] = *(_QWORD *)(a1 + i * 8);
v2 = 6;
do
{
for ( j = 0LL; j != 8; ++j )
{
v4 = (unsigned int *)v6[j];
if ( v4 )
{
if ( (_DWORD)j )
putchar(32);
putchar(32);
printf("%03u", *v4);
v6[j] = *((_QWORD *)v4 + 1);
}
else
{
if ( (_DWORD)j )
putchar(32);
putchar(32);
printf("---");
}
}
result = putchar(10);
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
__int64 i; // rax
int v2; // er12
__int64 j; // rbx
unsigned int *v4; // rbp
int result; // eax
__int64 v6[11]; // [rsp+0h] [rbp-58h]

for ( i = 0LL; i != 8; ++i )
v6[i] = *(_QWORD *)(a1 + i * 8);
v2 = 6;
do
{
for ( j = 0LL; j != 8; ++j )
{
v4 = (unsigned int *)v6[j];
if ( v4 )
{
if ( (_DWORD)j )
putchar(32);
putchar(32);
printf("%03u", *v4);
v6[j] = *((_QWORD *)v4 + 1);
}
else
{
if ( (_DWORD)j )
putchar(32);
putchar(32);
printf("---");
}
}
result = putchar(10);
--v2;
}
while ( v2 );
return result;
}

original_code:
void print_bufferstatue(switch_state *state) {
 buffer cbuffers[8];
 for(int k=0; k<8; k++) {
  cbuffers[k] = state->p3.buffers[k];
 }
 for(int i=0; i<6; i++) {
  for(int j=0; j<8; j++) {
   buffer cbuffer = cbuffers[j];
   if(cbuffer == ((void *)0)) {
    if(j!=0) {
     printf(" ");
    }
    printf(" ");
    printf("---");
   }
   else {
    if(j!=0) {
     printf(" ");
    }
    printf(" ");
    printf("%03u", cbuffer->frame_id);
    cbuffer = cbuffer->next;
    cbuffers[j] = cbuffer;
   }
  }
  printf("\n");
 }
}

canonical_original_code:
void print_bufferstatue(union switch_state *state) {
 struct buffer *cbuffers[8];
 for(int k = 0; k<8; k++) {
  cbuffers[k] = state->p3.buffers[k];
 }
 for(int i = 0; i<6; i++) {
  for(int j = 0; j<8; j++) {
   struct buffer *cbuffer = cbuffers[j];
   if(cbuffer == ((void *)0)) {
    if(j!=0) {
     printf(" ");
    }
    printf(" ");
    printf("---");
   }
   else {
    if(j!=0) {
     printf(" ");
    }
    printf(" ");
    printf("%03u", cbuffer->frame_id);
    cbuffer = cbuffer->next;
    cbuffers[j] = cbuffer;
   }
  }
  printf("\n");
 }
}

variable_types: struct buffer { unsigned int frame_id; struct buffer *next; } *[8]

variable_types: k int

variable_types: j int


decompiled_code:
void __fastcall destroy_buffer(void *ptr)
{
_QWORD *v1; // rbx

if ( ptr )
{
v1 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v1 )
{
while ( 1 )
{
free(ptr);
ptr = v1;
if ( !v1[1] )
break;
v1 = (_QWORD *)v1[1];
}
}
else
{
v1 = ptr;
}
free(v1);
}
}

canonical_decompiled_code:
void __fastcall func13(void *ptr)
{
_QWORD *v1; // rbx

if ( ptr )
{
v1 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v1 )
{
while ( 1 )
{
free(ptr);
ptr = v1;
if ( !v1[1] )
break;
v1 = (_QWORD *)v1[1];
}
}
else
{
v1 = ptr;
}
free(v1);
}
}

original_code:
void destroy_buffer(buffer cbuffer) {
 if(cbuffer==((void *)0)) return;
 buffer temp = cbuffer;
 while(cbuffer->next!=((void *)0)) {
  temp = cbuffer->next;
  free(cbuffer);
  cbuffer = temp;
 }
 free(cbuffer);
}

canonical_original_code:
void destroy_buffer(struct buffer *cbuffer) {
 if(cbuffer==((void *)0)) return;
 struct buffer *temp = cbuffer;
 while(cbuffer->next!=((void *)0)) {
  temp = cbuffer->next;
  free(cbuffer);
  cbuffer = temp;
 }
 free(cbuffer);
}


canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
result[1] = 0LL;
return result;
}

return_type: struct buffer { unsigned int frame_id; struct buffer *next; } *


repo: ccoff/lsupnp

decompiled_code:
__int64 __fastcall send_ssdp_request(int fd)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr buf; // [rsp+0h] [rbp-18h] BYREF

*(_QWORD *)&buf.sa_family = 2LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
*(_WORD *)buf.sa_data = _bswap_16(1900);
inet_pton(2, "239.255.255.250", &buf.sa_data[2]);
v1 = sendto(
fd,
"M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 3\r\nST: ssdp:all\r\n\r\n",
0x5EuLL,
0,
&buf,
0x10u);
if ( v1 < 0 )
{
v2 = *_errno_location();
perror("sendto()");
}
else if ( v1 == 94 )
{
v2 = 0;
if ( opt_verbose == 1 )
puts("M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 3\r\nST: ssdp:all\r\n\r\n");
}
else
{
fprintf(stderr, "sendto(): only sent %d of %d bytes\n", (unsigned int)v1, 94LL);
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr buf; // [rsp+0h] [rbp-18h] BYREF

*(_QWORD *)&buf.sa_family = 2LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
*(_WORD *)buf.sa_data = func1(1900);
inet_pton(2, "239.255.255.250", &buf.sa_data[2]);
v1 = sendto(
fd,
"M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 3\r\nST: ssdp:all\r\n\r\n",
0x5EuLL,
0,
&buf,
0x10u);
if ( v1 < 0 )
{
v2 = *_errno_location();
perror("sendto()");
}
else if ( v1 == 94 )
{
v2 = 0;
if ( opt_verbose == 1 )
puts("M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 3\r\nST: ssdp:all\r\n\r\n");
}
else
{
fprintf(stderr, "sendto(): only sent %d of %d bytes\n", (unsigned int)v1, 94LL);
v2 = -1;
}
return v2;
}

original_code:
int send_ssdp_request(int sock)
{
    int ret = 0, len, bytes_out;
    struct sockaddr_in dest_sock;
    memset(&dest_sock, 0, sizeof(dest_sock));
    dest_sock.sin_family = 2;
    dest_sock.sin_port = htons(1900);
    inet_pton(2, "239.255.255.250", &dest_sock.sin_addr);
    len = strlen(ssdp_discover_string);
    if ((bytes_out = sendto(sock, ssdp_discover_string,
                             len, 0,
                             (struct sockaddr*) &dest_sock,
                             sizeof(dest_sock))) < 0)
    {
        ret = (*__errno_location ());
        perror("sendto()");
        return(ret);
    }
    else if (bytes_out != len)
    {
        fprintf(stderr, "sendto(): only sent %d of %d bytes\n", bytes_out, len);
        return(-1);
    }
    else if ( opt_verbose == 1 )
        printf("%s\n", ssdp_discover_string);
    return ret;
}

canonical_original_code:
int send_ssdp_request(int sock)
{
    int ret = 0; int len; int bytes_out;
    struct sockaddr_in dest_sock;
    memset(&dest_sock, 0, sizeof(dest_sock));
    dest_sock.sin_family = 2;
    dest_sock.sin_port = htons(1900);
    inet_pton(2, "239.255.255.250", &dest_sock.sin_addr);
    len = strlen(ssdp_discover_string);
    if ((bytes_out = sendto(sock, ssdp_discover_string,
                             len, 0,
                             (struct sockaddr *) &dest_sock,
                             sizeof(dest_sock))) < 0)
    {
        ret = (*__errno_location ());
        perror("sendto()");
        return(ret);
    }
    else if (bytes_out != len)
    {
        fprintf(stderr, "sendto(): only sent %d of %d bytes\n", bytes_out, len);
        return(-1);
    }
    else if ( opt_verbose == 1 )
        printf("%s\n", ssdp_discover_string);
    return ret;
}

variable_types: sock int

variable_types: ret int

variable_types: len int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall rdns_lookup(char *cp, char *host, socklen_t hostlen)
{
int v4; // eax
unsigned int v5; // ebx
const char *v7; // rax
struct sockaddr buf[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&buf[0].sa_family = 2LL;
*(_QWORD *)&buf[0].sa_data[6] = 0LL;
inet_pton(2, cp, &buf[0].sa_data[2]);
v4 = getnameinfo(buf, 0x10u, host, hostlen, 0LL, 0, 0);
v5 = v4;
if ( v4 )
{
v7 = gai_strerror(v4);
fprintf(stderr, "getnameinfo(): %s\n", v7);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *cp, char *host, socklen_t hostlen)
{
int v4; // eax
unsigned int v5; // ebx
const char *v7; // rax
struct sockaddr buf[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&buf[0].sa_family = 2LL;
*(_QWORD *)&buf[0].sa_data[6] = 0LL;
inet_pton(2, cp, &buf[0].sa_data[2]);
v4 = getnameinfo(buf, 0x10u, host, hostlen, 0LL, 0, 0);
v5 = v4;
if ( v4 )
{
v7 = gai_strerror(v4);
fprintf(stderr, "getnameinfo(): %s\n", v7);
}
return v5;
}

original_code:
int rdns_lookup(char *ip_addr, char *hostname, int hostname_size)
{
    int ret;
    struct sockaddr_in sa;
    memset(&sa, 0, sizeof(sa));
    sa.sin_family = 2;
    inet_pton(2, ip_addr, &sa.sin_addr);
    if ( (ret = getnameinfo((struct sockaddr *)&sa, sizeof(sa),
                             hostname, hostname_size, ((void *)0), 0, 0)) != 0 )
    {
        fprintf(stderr, "getnameinfo(): %s\n", gai_strerror(ret));
    }
    return(ret);
}

variable_types:
hostname
char *


decompiled_code:
__int64 __fastcall get_ssdp_responses(int fd, __int64 a2)
{
int v4; // ebp
__int64 v5; // r12
unsigned int v6; // er14
int v8; // eax
char *v9; // rdi
char *v10; // rax
const char *v11; // r14
char *v12; // rax
signed __int64 v13; // r15
char v14[1040]; // [rsp+0h] [rbp-2908h] BYREF
struct timeval timeout; // [rsp+410h] [rbp-24F8h] BYREF
fd_set readfds; // [rsp+420h] [rbp-24E8h] BYREF
char dest[1040]; // [rsp+4A0h] [rbp-2468h] BYREF
char buf[8192]; // [rsp+8B0h] [rbp-2058h] BYREF
struct sockaddr addr; // [rsp+28B0h] [rbp-58h] BYREF
socklen_t addr_len[15]; // [rsp+28CCh] [rbp-3Ch] BYREF

memset(&readfds, 0, sizeof(readfds));
v4 = fd / 64;
v5 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v5;
timeout.tv_sec = opt_timeout;
timeout.tv_usec = 0LL;
while ( 1 )
{
v6 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( (v6 & 0x80000000) != 0 )
{
v6 = *_errno_location();
perror("select()");
return v6;
}
if ( (readfds.fds_bits[v4] & v5) == 0 )
return v6;
addr_len[0] = 16;
v8 = recvfrom(fd, buf, 0x2000uLL, 0, &addr, addr_len);
if ( v8 < 0 )
break;
buf[v8] = 0;
if ( !memcmp(buf, "HTTP/1.1 200 OK", 0xCuLL) )
{
if ( opt_verbose == 1 )
printf("\n%s", buf);
v9 = strcasestr(buf, "LOCATION:");
if ( v9 )
{
v10 = strstr(v9, "http://");
if ( v10 )
{
v11 = v10 + 7;
v12 = strchr(v10 + 7, 58);
if ( v12 )
{
v13 = v12 - v11;
strncpy(dest, v11, v12 - v11);
dest[v13] = 0;
if ( !(unsigned int)str_vector_search(a2, dest) )
{
str_vector_add(a2, dest);
printf("%s", dest);
if ( opt_rdns_lookup == 1 )
{
v14[0] = 0;
if ( !(unsigned int)rdns_lookup(dest, v14, 0x401u) )
printf("\t%s", v14);
}
putchar(10);
}
}
}
}
}
else
{
fwrite("[Unexpected SSDP response]\n", 1uLL, 0x1BuLL, stderr);
if ( opt_verbose == 1 )
printf("%s\n\n", buf);
}
}
v6 = *_errno_location();
perror("recvfrom()");
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int64 a2)
{
int v4; // ebp
__int64 v5; // r12
unsigned int v6; // er14
int v8; // eax
char *v9; // rdi
char *v10; // rax
const char *v11; // r14
char *v12; // rax
signed __int64 v13; // r15
char v14[1040]; // [rsp+0h] [rbp-2908h] BYREF
struct timeval timeout; // [rsp+410h] [rbp-24F8h] BYREF
fd_set readfds; // [rsp+420h] [rbp-24E8h] BYREF
char dest[1040]; // [rsp+4A0h] [rbp-2468h] BYREF
char buf[8192]; // [rsp+8B0h] [rbp-2058h] BYREF
struct sockaddr addr; // [rsp+28B0h] [rbp-58h] BYREF
socklen_t addr_len[15]; // [rsp+28CCh] [rbp-3Ch] BYREF

memset(&readfds, 0, sizeof(readfds));
v4 = fd / 64;
v5 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v5;
timeout.tv_sec = opt_timeout;
timeout.tv_usec = 0LL;
while ( 1 )
{
v6 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( (v6 & 0x80000000) != 0 )
{
v6 = *_errno_location();
perror("select()");
return v6;
}
if ( (readfds.fds_bits[v4] & v5) == 0 )
return v6;
addr_len[0] = 16;
v8 = recvfrom(fd, buf, 0x2000uLL, 0, &addr, addr_len);
if ( v8 < 0 )
break;
buf[v8] = 0;
if ( !memcmp(buf, "HTTP/1.1 200 OK", 0xCuLL) )
{
if ( opt_verbose == 1 )
printf("\n%s", buf);
v9 = strcasestr(buf, "LOCATION:");
if ( v9 )
{
v10 = strstr(v9, "http://");
if ( v10 )
{
v11 = v10 + 7;
v12 = strchr(v10 + 7, 58);
if ( v12 )
{
v13 = v12 - v11;
strncpy(dest, v11, v12 - v11);
dest[v13] = 0;
if ( !(unsigned int)str_vector_search(a2, dest) )
{
str_vector_add(a2, dest);
printf("%s", dest);
if ( opt_rdns_lookup == 1 )
{
v14[0] = 0;
if ( !(unsigned int)func3(dest, v14, 0x401u) )
printf("\t%s", v14);
}
putchar(10);
}
}
}
}
}
else
{
fwrite("[Unexpected SSDP response]\n", 1uLL, 0x1BuLL, stderr);
if ( opt_verbose == 1 )
printf("%s\n\n", buf);
}
}
v6 = *_errno_location();
perror("recvfrom()");
return v6;
}

original_code:
int get_ssdp_responses(int sock, struct str_vector *vector)
{
    int ret = 0, bytes_in, done = 0;
    unsigned int host_sock_len;
    struct sockaddr_in host_sock;
    char buffer[8192];
    char host[1025];
    char *url_start, *host_start, *host_end;
    fd_set read_fds;
    struct timeval timeout;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&read_fds)->fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = opt_timeout;
    timeout.tv_usec = 0;
    do
    {
        if ((ret = select(sock+1, &read_fds, ((void *)0), ((void *)0), &timeout)) < 0)
        {
            ret = (*__errno_location ());
            perror("select()");
            return(ret);
        }
        if (((((&read_fds)->fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        {
            host_sock_len = sizeof(host_sock);
            if ((bytes_in = recvfrom(sock, buffer, sizeof(buffer), 0,
                                    &host_sock, &host_sock_len)) < 0)
            {
                ret = (*__errno_location ());
                perror("recvfrom()");
                return(ret);
            }
            buffer[bytes_in] = '\0';
            if (strncmp(buffer, "HTTP/1.1 200 OK", 12) == 0)
            {
                if ( opt_verbose == 1 )
                {
                    printf("\n%s", buffer);
                }
                if ( (url_start = strcasestr(buffer, "LOCATION:")) != ((void *)0) )
                {
                    if ( (host_start = strstr(url_start, "http://")) != ((void *)0) )
                    {
                        host_start += 7;
                        if ( (host_end = strstr(host_start, ":")) != ((void *)0) )
                        {
                            strncpy(host, host_start, host_end - host_start);
                            host[host_end - host_start] = '\0';
                            if ( str_vector_search(vector, host) == 0 )
                            {
                                str_vector_add(vector, host);
                                printf("%s", host);
                                if ( opt_rdns_lookup == 1 )
                                {
                                    char name[1025];
                                    name[0] = '\0';
                                    if ( (rdns_lookup(host, name, 1025)) == 0 )
                                    {
                                        printf("\t%s", name);
                                    }
                                }
                                printf("\n");
                            }
                        }
                    }
                }
            }
            else
            {
                fprintf(stderr, "[Unexpected SSDP response]\n");
                if ( opt_verbose == 1 )
                {
                    printf("%s\n\n", buffer);
                }
            }
        }
        else
        {
            done = 1;
        }
    } while ( done == 0 );
    return ret;
}

canonical_original_code:
int get_ssdp_responses(int sock, struct str_vector *vector)
{
    int ret = 0; int bytes_in; int done = 0;
    unsigned int host_sock_len;
    struct sockaddr_in host_sock;
    char buffer[8192];
    char host[1025];
    char *url_start; char *host_start; char *host_end;
    struct fd_set read_fds;
    struct timeval timeout;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&read_fds)->fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = opt_timeout;
    timeout.tv_usec = 0;
    do
    {
        if ((ret = select(sock+1, &read_fds, ((void *)0), ((void *)0), &timeout)) < 0)
        {
            ret = (*__errno_location ());
            perror("select()");
            return(ret);
        }
        if (((((&read_fds)->fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        {
            host_sock_len = sizeof(host_sock);
            if ((bytes_in = recvfrom(sock, buffer, sizeof(buffer), 0,
                                    &host_sock, &host_sock_len)) < 0)
            {
                ret = (*__errno_location ());
                perror("recvfrom()");
                return(ret);
            }
            buffer[bytes_in] = '\0';
            if (strncmp(buffer, "HTTP/1.1 200 OK", 12) == 0)
            {
                if ( opt_verbose == 1 )
                {
                    printf("\n%s", buffer);
                }
                if ( (url_start = strcasestr(buffer, "LOCATION:")) != ((void *)0) )
                {
                    if ( (host_start = strstr(url_start, "http://")) != ((void *)0) )
                    {
                        host_start += 7;
                        if ( (host_end = strstr(host_start, ":")) != ((void *)0) )
                        {
                            strncpy(host, host_start, host_end - host_start);
                            host[host_end - host_start] = '\0';
                            if ( str_vector_search(vector, host) == 0 )
                            {
                                str_vector_add(vector, host);
                                printf("%s", host);
                                if ( opt_rdns_lookup == 1 )
                                {
                                    char name[1025];
                                    name[0] = '\0';
                                    if ( (rdns_lookup(host, name, 1025)) == 0 )
                                    {
                                        printf("\t%s", name);
                                    }
                                }
                                printf("\n");
                            }
                        }
                    }
                }
            }
            else
            {
                fprintf(stderr, "[Unexpected SSDP response]\n");
                if ( opt_verbose == 1 )
                {
                    printf("%s\n\n", buffer);
                }
            }
        }
        else
        {
            done = 1;
        }
    } while ( done == 0 );
    return ret;
}

variable_types: struct str_vector { char **str_array; int str_count; } *

variable_types: done int

variable_types:
buffer
char [8192]

variable_types:
host
char [1025]

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

variable_types:
name
char [1025]


decompiled_code:
__int64 __fastcall discover_hosts(__int64 a1)
{
int v1; // eax
int v2; // ebx
unsigned int v3; // ebp
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 2, 0);
if ( v1 < 0 )
{
v3 = *_errno_location();
perror("socket()");
}
else
{
v2 = v1;
*(_DWORD *)&v5.sa_data[10] = 0;
v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)v5.sa_data = _bswap_16(opt_source_port);
if ( bind(v2, &v5, 0x10u) )
{
v3 = *_errno_location();
perror("bind()");
}
else
{
if ( opt_verbose == 1 && opt_source_port )
printf("[Client bound to port %d]\n\n", (unsigned int)opt_source_port);
v3 = send_ssdp_request(v2);
if ( !v3 )
v3 = get_ssdp_responses(v2, a1);
}
if ( close(v2) )
{
v3 = *_errno_location();
perror("close()");
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // eax
int v2; // ebx
unsigned int v3; // ebp
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 2, 0);
if ( v1 < 0 )
{
v3 = *_errno_location();
perror("socket()");
}
else
{
v2 = v1;
*(_DWORD *)&v5.sa_data[10] = 0;
v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[2] = (unsigned int)func0(0);
*(_WORD *)v5.sa_data = func1(opt_source_port);
if ( bind(v2, &v5, 0x10u) )
{
v3 = *_errno_location();
perror("bind()");
}
else
{
if ( opt_verbose == 1 && opt_source_port )
printf("[Client bound to port %d]\n\n", (unsigned int)opt_source_port);
v3 = func2(v2);
if ( !v3 )
v3 = func4(v2, a1);
}
if ( close(v2) )
{
v3 = *_errno_location();
perror("close()");
}
}
return v3;
}

original_code:
int discover_hosts(struct str_vector *vector)
{
    int ret = 0, sock;
    struct sockaddr_in src_sock;
    if ((sock = socket(2, SOCK_DGRAM, 0)) < 0)
    {
        ret = (*__errno_location ());
        perror("socket()");
        return(ret);
    }
    memset(&src_sock, 0, sizeof(src_sock));
    src_sock.sin_family = 2;
    src_sock.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    src_sock.sin_port = htons(opt_source_port);
    if ((ret = bind(sock, (struct sockaddr *)&src_sock,
                            sizeof(src_sock))) != 0 )
    {
        ret = (*__errno_location ());
        perror("bind()");
        goto close_socket;
    }
    else if ( (opt_verbose == 1) && (opt_source_port != 0) )
        printf("[Client bound to port %d]\n\n", opt_source_port);
    if ((ret = send_ssdp_request(sock)) != 0)
    {
        goto close_socket;
    }
    if ((ret = get_ssdp_responses(sock, vector)) != 0)
    {
        goto close_socket;
    }
close_socket:
    if ( close(sock) != 0 )
    {
        ret = (*__errno_location ());
        perror("close()");
    }
    return(ret);
}

canonical_original_code:
int discover_hosts(struct str_vector *vector)
{
    int ret = 0; int sock;
    struct sockaddr_in src_sock;
    if ((sock = socket(2, SOCK_DGRAM, 0)) < 0)
    {
        ret = (*__errno_location ());
        perror("socket()");
        return(ret);
    }
    memset(&src_sock, 0, sizeof(src_sock));
    src_sock.sin_family = 2;
    src_sock.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    src_sock.sin_port = htons(opt_source_port);
    if ((ret = bind(sock, (struct sockaddr *)&src_sock,
                            sizeof(src_sock))) != 0 )
    {
        ret = (*__errno_location ());
        perror("bind()");
        goto close_socket;
    }
    else if ( (opt_verbose == 1) && (opt_source_port != 0) )
        printf("[Client bound to port %d]\n\n", opt_source_port);
    if ((ret = send_ssdp_request(sock)) != 0)
    {
        goto close_socket;
    }
    if ((ret = get_ssdp_responses(sock, vector)) != 0)
    {
        goto close_socket;
    }
close_socket:
    if ( close(sock) != 0 )
    {
        ret = (*__errno_location ());
        perror("close()");
    }
    return(ret);
}

user_defined_types: struct str_vector { char **str_array; int str_count; }


decompiled_code:
__int64 __fastcall parse_cmd_opts(int argc, char **argv)
{
int v2; // eax

while ( 1 )
{
v2 = getopt(argc, argv, "p:rt:v");
if ( v2 == -1 )
return 0LL;
if ( v2 == 116 )
{
opt_timeout = abs32(atoi(optarg));
}
else if ( v2 > 116 )
{
if ( v2 != 118 )
{
LABEL_11:
printf("\nUsage: %s [OPTION]...", *argv);
puts("\nDiscover and list UPnP devices on the network.\n");
puts("Available options:\n");
puts(" -p [port]\tSpecify client-side (source) UDP port to bind to");
puts(" -r\t\tDo reverse DNS lookups");
printf(" -t [interval]\tSpecify timeout interval in seconds (default is %d)\n", (unsigned int)opt_timeout);
puts(" -v\t\tProvide verbose information");
putchar(10);
exit(0);
}
opt_verbose = 1;
}
else if ( v2 == 112 )
{
opt_source_port = atoi(optarg);
}
else
{
if ( v2 != 114 )
goto LABEL_11;
opt_rdns_lookup = 1;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func6(int argc, char **argv)
{
int v2; // eax

while ( 1 )
{
v2 = getopt(argc, argv, "p:rt:v");
if ( v2 == -1 )
return 0LL;
if ( v2 == 116 )
{
opt_timeout = abs32(atoi(optarg));
}
else if ( v2 > 116 )
{
if ( v2 != 118 )
{
LABEL_11:
printf("\nUsage: %s [OPTION]...", *argv);
puts("\nDiscover and list UPnP devices on the network.\n");
puts("Available options:\n");
puts(" -p [port]\tSpecify client-side (source) UDP port to bind to");
puts(" -r\t\tDo reverse DNS lookups");
printf(" -t [interval]\tSpecify timeout interval in seconds (default is %d)\n", (unsigned int)opt_timeout);
puts(" -v\t\tProvide verbose information");
putchar(10);
exit(0);
}
opt_verbose = 1;
}
else if ( v2 == 112 )
{
opt_source_port = atoi(optarg);
}
else
{
if ( v2 != 114 )
goto LABEL_11;
opt_rdns_lookup = 1;
}
}
}

original_code:
int parse_cmd_opts(int argc, char *argv[])
{
    int cmdopt;
    while ( (cmdopt = getopt(argc, argv, "p:rt:v")) != -1 )
    {
        switch (cmdopt)
        {
            case 'p':
                opt_source_port = atoi(optarg);
                break;
            case 'r':
                opt_rdns_lookup = 1;
                break;
            case 't':
                opt_timeout = abs(atoi(optarg));
                break;
            case 'v':
                opt_verbose = 1;
                break;
            default:
                printf("\nUsage: %s [OPTION]...", argv[0]);
                printf("\nDiscover and list UPnP devices on the network.\n\n");
                printf("Available options:\n\n");
                printf("  -p [port]\tSpecify client-side (source) UDP port to bind to\n");
                printf("  -r\t\tDo reverse DNS lookups\n");
                printf("  -t [interval]\tSpecify timeout interval in seconds (default is %d)\n", opt_timeout);
                printf("  -v\t\tProvide verbose information\n");
                printf("\n");
                exit(0);
        }
    }
    return(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: cmdopt int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
_BYTE v5[24]; // [rsp+0h] [rbp-18h] BYREF

parse_cmd_opts(argc, (char **)argv);
str_vector_init(v5);
v3 = discover_hosts((__int64)v5);
str_vector_free(v5);
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
_BYTE v5[24]; // [rsp+0h] [rbp-18h] BYREF

func6(argc, (char **)argv);
str_vector_init(v5);
v3 = func5((__int64)v5);
str_vector_free(v5);
return v3;
}

original_code:
int main(int argc, char *argv[])
{
    int ret = 0;
    struct str_vector my_vector;
    parse_cmd_opts(argc, argv);
    str_vector_init(&my_vector);
    ret = discover_hosts(&my_vector);
    str_vector_free(&my_vector);
    return(ret);
}

variable_types: struct str_vector { char **str_array; int str_count; }


decompiled_code:
__int64 __fastcall str_vector_init(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
return 0LL;
}

original_code:
int str_vector_init(struct str_vector *vector)
{
    vector->str_array = ((void *)0);
    vector->str_count = 0;
    return(0);
}


decompiled_code:
__int64 __fastcall str_vector_add(__int64 a1, const char *a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbp
int v4; // er13
char *v5; // rax

v2 = realloc(*(void **)a1, 8LL * (*(_DWORD *)(a1 + 8) + 1));
*(_QWORD *)a1 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = v4 + 1;
v5 = strdup(a2);
v3[v4] = v5;
return (unsigned int)-(v5 == 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbp
int v4; // er13
char *v5; // rax

v2 = realloc(*(void **)a1, 8LL * (*(_DWORD *)(a1 + 8) + 1));
*(_QWORD *)a1 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = v4 + 1;
v5 = strdup(a2);
v3[v4] = v5;
return (unsigned int)-(v5 == 0LL);
}

original_code:
int str_vector_add(struct str_vector *vector, char *str)
{
    if ( (vector->str_array = (char **)realloc(vector->str_array,
                            (vector->str_count + 1) * sizeof(char *))) == ((void *)0) )
    {
        return(-1);
    }
    if ( (vector->str_array[vector->str_count++] = strdup(str)) == ((void *)0) )
    {
        return(-1);
    }
    return(0);
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall str_vector_search(__int64 a1, const char *a2)
{
int v2; // eax
const char **v3; // rbx
__int64 v4; // r12

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= 0 )
return 0LL;
v3 = *(const char ***)a1;
v4 = *(_QWORD *)a1 + 8LL * (unsigned int)(v2 - 1) + 8;
while ( strcmp(*v3, a2) )
{
if ( ++v3 == (const char **)v4 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
int v2; // eax
const char **v3; // rbx
__int64 v4; // r12

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= 0 )
return 0LL;
v3 = *(const char ***)a1;
v4 = *(_QWORD *)a1 + 8LL * (unsigned int)(v2 - 1) + 8;
while ( strcmp(*v3, a2) )
{
if ( ++v3 == (const char **)v4 )
return 0LL;
}
return 1LL;
}

original_code:
int str_vector_search(struct str_vector *vector, char *search_str)
{
    int i;
    for (i = 0; i < vector->str_count; i++)
    {
        if ( strcmp(vector->str_array[i], search_str) == 0 )
            return(1);
    }
    return(0);
}

variable_types: i int


original_code:
int str_vector_free(struct str_vector *vector)
{
    int i;
    for ( i = 0; i < vector->str_count; i++ )
    {
        free(vector->str_array[i]);
    }
    free(vector->str_array);
    vector->str_count = 0;
    return(0);
}


repo: ccontavalli/grub-shusher

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // rsi
int v5; // er8
int v6; // er10
char v7; // bl
const char *v8; // rcx
unsigned int v9; // ebp
char v10; // al
const char *v12; // r15
int v13; // ebp
int v14; // er12
int v15; // er13
const char **v16; // r12
unsigned int v17; // er14
const char *v18; // rax
signed __int64 v19; // r13
int v20; // eax
int v21; // ebx
int *v22; // rax
char *v23; // rax
int *v24; // rax
char *v25; // rax
int *v26; // rax
char *v27; // rax
int *v28; // rax
char *v29; // rax
int *v30; // rax
char *v31; // rax
size_t haystacklen; // [rsp+8h] [rbp-870h]
const char *v33; // [rsp+10h] [rbp-868h] BYREF
int v34; // [rsp+18h] [rbp-860h]
const char *v35; // [rsp+20h] [rbp-858h]
int v36; // [rsp+28h] [rbp-850h]
const char *v37; // [rsp+30h] [rbp-848h]
int v38; // [rsp+38h] [rbp-840h]
char buf[2104]; // [rsp+40h] [rbp-838h] BYREF

if ( argc <= 1 )
{
v5 = 1;
v7 = 0;
goto LABEL_24;
}
v4 = argv + 1;
v5 = 1;
v6 = 0;
v7 = 0;
while ( 1 )
{
v8 = *v4;
if ( **v4 == 45 )
break;
if ( v6 )
{
fprintf(
_bss_start,
"ERROR: A single partition can be specified.\n%s",
"Usage: ./mbr [-gh] <device/partition file>\n"
"\tRequires rw permissions of target file (root, most likely).\n"
"\n"
"\t-g: GPT partition - keep going even if not all patches can be found.\n"
"\t-h (or -v): Print this message\n");
return 1;
}
v6 = v5;
LABEL_6:
++v5;
++v4;
if ( argc == v5 )
{
if ( v6 )
goto LABEL_25;
goto LABEL_8;
}
}
envp = (const char **)(v8 + 1);
v10 = v8[1];
if ( v10 != 45 )
{
if ( v10 )
{
LABEL_19:
while ( v10 != 104 && v10 != 118 )
{
if ( v10 == 103 )
v7 = 1;
envp = (const char **)((char *)envp + 1);
v10 = *(_BYTE *)envp;
if ( !*(_BYTE *)envp )
goto LABEL_6;
}
puts(
"Usage: ./mbr [-gh] <device/partition file>\n"
"\tRequires rw permissions of target file (root, most likely).\n"
"\n"
"\t-g: GPT partition - keep going even if not all patches can be found.\n"
"\t-h (or -v): Print this message");
return 0;
}
goto LABEL_6;
}
if ( v8[2] )
goto LABEL_19;
if ( v6 )
goto LABEL_25;
LABEL_24:
v6 = argc - 1;
if ( argc - v5 == 2 )
{
LABEL_25:
v12 = argv[v6];
v13 = open(v12, 0, envp);
if ( v13 < 0 )
{
v22 = __errno_location();
v23 = strerror(*v22);
fprintf(_bss_start, "Could not open for read %s: %s\n", v12, v23);
v9 = 1;
}
else
{
printf("opened: %s\n", v12);
v14 = read(v13, buf, 0x800uLL);
v15 = v14;
if ( v14 < 0 )
{
v24 = __errno_location();
v25 = strerror(*v24);
fprintf(_bss_start, "Could not read %s: %s\n", v12, v25);
v9 = 2;
}
else
{
close(v13);
printf("read: %d bytes from %s\n", (unsigned int)v14, v12);
v33 = "loading";
v34 = 22;
v35 = ".";
v36 = 14;
v37 = "GRUB ";
v38 = 21;
v16 = &v33;
v9 = 0;
v17 = 0;
haystacklen = v15;
do
{
v18 = (const char *)memmem(buf, haystacklen, *v16, *((int *)v16 + 2));
if ( v18 )
{
v19 = v18 - buf;
printf("match[%d]: found at %ld, \"%s\", '%c'\n", v9, v18 - buf, v18, (unsigned int)*v18);
++v17;
buf[v19] = 0;
}
else
{
printf("match[%d]: NOT FOUND\n", v9);
}
++v9;
v16 += 2;
}
while ( v9 != 3 );
if ( v17 > 2 || v7 == 1 )
{
if ( v7 )
{
if ( v17 == 1 )
{
puts("Found mbr header of gpt disk.\nMake sure to also run this on the ef02 partition of this drive.");
}
else if ( v17 == 2 )
{
puts("Found ef02 header of gpt grub partition.\nMake sure to also run this on full drive.");
}
}
v20 = open(v12, 2);
v21 = v20;
if ( v20 < 0 )
{
v26 = __errno_location();
v27 = strerror(*v26);
fprintf(_bss_start, "Could not open for write %s: %s\n", v12, v27);
}
else if ( (int)write(v20, buf, 0x800uLL) < 0 )
{
v28 = __errno_location();
v29 = strerror(*v28);
fprintf(_bss_start, "Could not write %s, good luck: %s\n", v12, v29);
v9 = 4;
}
else if ( close(v21) < 0 )
{
v30 = __errno_location();
v31 = strerror(*v30);
fprintf(_bss_start, "Close failed! Good luck: %s - %s\n", v12, v31);
v9 = 5;
}
else
{
puts("PATCHED SUCCESSFULLY!");
puts("(the message should be gone next time you reboot, good luck!)");
v9 = 0;
}
}
else
{
fwrite("Not enough matches were found, giving up.\n", 1uLL, 0x2AuLL, _bss_start);
fwrite("If you have a gpt disk, run this with the -g flag.\n", 1uLL, 0x33uLL, _bss_start);
fwrite("(if you run this command more than once, it's good!\n", 1uLL, 0x34uLL, _bss_start);
fwrite("it means the first run succeeded)\n", 1uLL, 0x22uLL, _bss_start);
v9 = 10;
}
}
}
}
else
{
LABEL_8:
fprintf(
_bss_start,
"ERROR: You must specify a single file/partition.\n%s",
"Usage: ./mbr [-gh] <device/partition file>\n"
"\tRequires rw permissions of target file (root, most likely).\n"
"\n"
"\t-g: GPT partition - keep going even if not all patches can be found.\n"
"\t-h (or -v): Print this message\n");
v9 = 1;
}
return v9;
}

original_code:
int main(int argc, char** argv) {
  if (argc != 2) {
    fprintf(stderr, "Usage: grub-kernel /path/to/grub/kernel.img\n");
    fprintf(stderr, "\nYou need to provide one path to kernel.img, generally\n");
    fprintf(stderr, "/boot/grub/kernel.img\n");
    return 1;
  }
  int fd = open(argv[1], 00);
  if (fd < 0) {
    fprintf(stderr, "Could not open for read %s: %s\n", argv[1], strerror((*__errno_location ())));
    return 1;
  }
  printf("opened: %s\n", argv[1]);
  char buffer[1024 * 1024];
  int data = read(fd, buffer, sizeof(buffer));
  if (data < 0) {
    fprintf(stderr, "Could not read %s: %s\n", argv[1], strerror((*__errno_location ())));
    return 2;
  }
  close(fd);
  printf("read: %d bytes from %s\n", data, argv[1]);
  struct {
    const char* match;
    const int length;
  } matches[] = {
    { "Welcome to GRUB!\n\n\0", sizeof("Welcome to GRUB!\n\n\0") - 1 },
  };
  int found = 0;
  for (int i = 0; i < sizeof(matches) / sizeof(matches[0]); ++i) {
    const char* match = matches[i].match;
    const int length = matches[i].length;
    void* ptr = memmem(buffer, data, match, length);
    if (!ptr) {
      printf("match[%d]: NOT FOUND\n", i);
      continue;
    }
    size_t offset = (char*)ptr - buffer;
    printf("match[%d]: found at %ld, \"%s\", '%c'\n",
           i, offset, buffer + offset, buffer[offset]);
    ++found;
    buffer[offset] = '\0';
  }
  if (found != sizeof(matches) / sizeof(matches[0])) {
    fprintf(stderr, "Not all required matches were found, giving up.\n");
    fprintf(stderr, "(if you run this command more than once, it's good!\n");
    fprintf(stderr, "it means the first run succeeded)\n");
    return 10;
  }
  fd = open(argv[1], 02);
  if (fd < 0) {
    fprintf(stderr, "Could not open for write %s: %s\n", argv[1], strerror((*__errno_location ())));
    return 3;
  }
  data = write(fd, buffer, sizeof(buffer));
  if (data < 0) {
    fprintf(stderr, "Could not write %s, good luck: %s\n", argv[1], strerror((*__errno_location ())));
    return 4;
  }
  if (close(fd) < 0) {
    fprintf(stderr, "Close failed! Good luck: %s - %s\n", argv[1], strerror((*__errno_location ())));
    return 5;
  }
  printf("SUCCESS! (maybe! you won't know until you reboot!)\n");
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "Usage: grub-kernel /path/to/grub/kernel.img\n");
    fprintf(stderr, "\nYou need to provide one path to kernel.img, generally\n");
    fprintf(stderr, "/boot/grub/kernel.img\n");
    return 1;
  }
  int fd = open(argv[1], 00);
  if (fd < 0) {
    fprintf(stderr, "Could not open for read %s: %s\n", argv[1], strerror((*__errno_location ())));
    return 1;
  }
  printf("opened: %s\n", argv[1]);
  char buffer[-1];
  int data = read(fd, buffer, sizeof(buffer));
  if (data < 0) {
    fprintf(stderr, "Could not read %s: %s\n", argv[1], strerror((*__errno_location ())));
    return 2;
  }
  close(fd);
  printf("read: %d bytes from %s\n", data, argv[1]);
  struct { char *match; int length; } matches[] = {
    { "Welcome to GRUB!\n\n\0", sizeof("Welcome to GRUB!\n\n\0") - 1 },
  };
  int found = 0;
  for (int i = 0; i < sizeof(matches) / sizeof(matches[0]); ++i) {
    char *match = matches[i].match;
    int length = matches[i].length;
    void *ptr = memmem(buffer, data, match, length);
    if (!ptr) {
      printf("match[%d]: NOT FOUND\n", i);
      continue;
    }
    unsigned long offset = (char*)ptr - buffer;
    printf("match[%d]: found at %ld, \"%s\", '%c'\n",
           i, offset, buffer + offset, buffer[offset]);
    ++found;
    buffer[offset] = '\0';
  }
  if (found != sizeof(matches) / sizeof(matches[0])) {
    fprintf(stderr, "Not all required matches were found, giving up.\n");
    fprintf(stderr, "(if you run this command more than once, it's good!\n");
    fprintf(stderr, "it means the first run succeeded)\n");
    return 10;
  }
  fd = open(argv[1], 02);
  if (fd < 0) {
    fprintf(stderr, "Could not open for write %s: %s\n", argv[1], strerror((*__errno_location ())));
    return 3;
  }
  data = write(fd, buffer, sizeof(buffer));
  if (data < 0) {
    fprintf(stderr, "Could not write %s, good luck: %s\n", argv[1], strerror((*__errno_location ())));
    return 4;
  }
  if (close(fd) < 0) {
    fprintf(stderr, "Close failed! Good luck: %s - %s\n", argv[1], strerror((*__errno_location ())));
    return 5;
  }
  printf("SUCCESS! (maybe! you won't know until you reboot!)\n");
  return 0;
}

variable_types:
argv
char **

variable_types: fd int

variable_types:
buffer
char [-1]

variable_types: data int

variable_types:
matches
struct { char *match; int length; } []

variable_types: found int

variable_types:
match
char *

variable_types: length int

variable_types:
ptr
void *

variable_types:
offset
unsigned long


repo: cdoenges/misclib

decompiled_code:
int __fastcall pt_start(__int64 a1)
{
if ( !a1 )
_assert_fail("NULL != pt", "src/portable_timer.c", 0x43u, "pt_start");
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
*(_BYTE *)a1 = 1;
return gettimeofday((struct timeval *)(a1 + 8), 0LL);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
if ( !a1 )
_assert_fail("NULL != pt", "src/portable_timer.c", 0x43u, "pt_start");
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
*(_BYTE *)a1 = 1;
return gettimeofday((struct timeval *)(a1 + 8), 0LL);
}

original_code:
void pt_start(portable_timer_t *pt) {
    ((void) sizeof ((((void *)0) != pt) ? 1 : 0), __extension__ ({ if (((void *)0) != pt) ; else __assert_fail ("NULL != pt", "src/portable_timer.c", 67, __extension__ __PRETTY_FUNCTION__); }));
    memset(pt, 0, sizeof(portable_timer_t));
    pt->running = 1;
    (void) gettimeofday(&pt->startTime, ((void *)0));
}

canonical_original_code:
void pt_start(struct portable_timer_t *pt) {
    ((void) sizeof ((((void *)0) != pt) ? 1 : 0), __extension__ ({ if (((void *)0) != pt) ; else __assert_fail ("NULL != pt", "src/portable_timer.c", 67, __extension__ __PRETTY_FUNCTION__); }));
    memset(pt, 0, sizeof(portable_timer_t));
    pt->running = 1;
    (void) gettimeofday(&pt->startTime, ((void *)0));
}

variable_types: struct portable_timer_t { _Bool running; struct timeval { long tv_sec; long tv_usec; } startTime; struct timeval endTime; } *

user_defined_types: struct portable_timer_t { _Bool running; struct timeval startTime; struct timeval endTime; }


decompiled_code:
int __fastcall pt_stop(__int64 a1)
{
int result; // eax

if ( !a1 )
_assert_fail("NULL != pt", "src/portable_timer.c", 0x56u, "pt_stop");
if ( !*(_BYTE *)a1 )
_assert_fail("pt->running", "src/portable_timer.c", 0x57u, "pt_stop");
result = gettimeofday((struct timeval *)(a1 + 24), 0LL);
*(_BYTE *)a1 = 0;
return result;
}

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

if ( !a1 )
_assert_fail("NULL != pt", "src/portable_timer.c", 0x56u, "pt_stop");
if ( !*(_BYTE *)a1 )
_assert_fail("pt->running", "src/portable_timer.c", 0x57u, "pt_stop");
result = gettimeofday((struct timeval *)(a1 + 24), 0LL);
*(_BYTE *)a1 = 0;
return result;
}

original_code:
void pt_stop(portable_timer_t *pt) {
    ((void) sizeof ((((void *)0) != pt) ? 1 : 0), __extension__ ({ if (((void *)0) != pt) ; else __assert_fail ("NULL != pt", "src/portable_timer.c", 86, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((pt->running) ? 1 : 0), __extension__ ({ if (pt->running) ; else __assert_fail ("pt->running", "src/portable_timer.c", 87, __extension__ __PRETTY_FUNCTION__); }));
    (void) gettimeofday(&pt->endTime, ((void *)0));
    pt->running = 0;
}

canonical_original_code:
void pt_stop(struct portable_timer_t *pt) {
    ((void) sizeof ((((void *)0) != pt) ? 1 : 0), __extension__ ({ if (((void *)0) != pt) ; else __assert_fail ("NULL != pt", "src/portable_timer.c", 86, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((pt->running) ? 1 : 0), __extension__ ({ if (pt->running) ; else __assert_fail ("pt->running", "src/portable_timer.c", 87, __extension__ __PRETTY_FUNCTION__); }));
    (void) gettimeofday(&pt->endTime, ((void *)0));
    pt->running = 0;
}


decompiled_code:
__int64 __fastcall pt_is_running(unsigned __int8 *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1)
{
return *a1;
}

original_code:
_Bool pt_is_running(const portable_timer_t *pt) {
    return pt->running;
}

canonical_original_code:
_Bool pt_is_running(struct portable_timer_t *pt) {
    return pt->running;
}